You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: Add Examples, Themes & Layouts section to CLAUDE.md
Document the templates system, FFTheme schema, available layouts,
Cytoscape CSS pipeline, utility classes, screenshot generation, and
how templates integrate with the AI pipeline and chart creation UI.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CLAUDE.md
+155Lines changed: 155 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -180,6 +180,161 @@ Pro access is determined by Stripe subscription status (`active` or `trialing`)
180
180
181
181
The sandbox warning modal (`SandboxWarning.tsx`) appears after 3 minutes of editing to encourage upgrade.
182
182
183
+
## Examples, Themes & Layouts
184
+
185
+
### Templates Overview
186
+
187
+
13 templates defined in `shared/src/templates.ts` (single source of truth, `as const` array). Each template is a file at `app/src/lib/templates/{name}-template.ts` exporting three things:
188
+
189
+
-`content: string` — starter DSL text for the editor
10 layout algorithms (from `LayoutName` type in `FFTheme.ts`):
211
+
212
+
| Layout | Engine | Best For |
213
+
|--------|--------|----------|
214
+
| dagre | dagre | Hierarchical flowcharts |
215
+
| klay | klayjs | Hierarchical (alternative) |
216
+
| layered | ELK | Hierarchical with balanced alignment |
217
+
| mrtree | ELK | Tree structures |
218
+
| stress | ELK | Force-directed, interactive |
219
+
| radial | ELK | Radial/spoke layouts |
220
+
| cose | fcose | Force-directed with animation |
221
+
| breadthfirst | cytoscape | Breadth-first tree |
222
+
| concentric | cytoscape | Concentric circles |
223
+
| circle | cytoscape | Simple circle |
224
+
225
+
Direction property maps to layout-specific direction configs (dagre: rankDir TB/LR/RL/BT; klay: klay.direction; ELK: elk.direction). Reference: https://js.cytoscape.org/ for Cytoscape layout/CSS docs.
226
+
227
+
### Cytoscape CSS (Not Browser CSS)
228
+
229
+
All CSS in `cytoscapeStyle` is **Cytoscape CSS** — different property names, selectors, and values from browser CSS. Reference: https://js.cytoscape.org/#style
230
+
231
+
Key features:
232
+
-**Variables:**`$varname: value;` — preprocessed by `app/src/lib/preprocessStyle.ts`, substituted throughout
233
+
-**Font imports:**`@import url(...)` — extracted and loaded via FontFace API
234
+
-**Dynamic class detection:** classes matching `type_name` pattern (e.g., `color_blue`, `shape_diamond`) auto-detected and made available in the right-click context menu on nodes/edges (`GraphContextMenu.tsx`)
-**Three-stage pipeline:** themeStyle (generated from FFTheme) → customCss (user's cytoscapeStyle) → postStyle (utility classes). All concatenated unless `customCssOnly: true` in metadata.
237
+
238
+
Example from flowchart-template.ts cytoscapeStyle:
239
+
```css
240
+
$blue: #e3f2fd;
241
+
:childless.color_blue {
242
+
background-color: $blue;
243
+
color: $color;
244
+
}
245
+
:childless[in_degree > 0][out_degree > 1] {
246
+
shape: diamond;
247
+
height: $width;
248
+
}
249
+
```
250
+
251
+
### Built-in Utility Classes
252
+
253
+
From `app/src/lib/graphUtilityClasses.ts` (generated as postStyle, always available):
254
+
255
+
-**Shape classes** (`.shape_*`): All Cytoscape shapes (rectangle, roundrectangle, ellipse, triangle, diamond, star, hexagon, etc.) + "smart shapes" (circle, square, roundsquare) that enforce 1:1 aspect ratio
256
+
-**Border classes** (`.border_*`): none, solid, dashed, dotted, double — works on both nodes and edges
257
+
-**Color classes** (`.color_*`): **Defined per-template** in cytoscapeStyle, NOT global. Common set across most templates: red, orange, yellow, green, blue, pink, grey, white, black. Each template defines its own color values.
-**Filter:** Pass a string to only screenshot matching templates (e.g., `pnpm -F app screenshot-templates mindmap` screenshots all mindmap variants)
304
+
-**Window globals** set up by `app/src/lib/loadTemplate.ts` (`useEnsureLoadTemplate` hook) and `app/src/lib/useEnsureGetScreenshotLink.ts`
305
+
306
+
### Templates in the AI Pipeline
307
+
308
+
- When user runs AI "prompt" or "convert", `runAi()` (`app/src/lib/runAi.ts`) first calls `/api/prompt/choose-template` to auto-select the best template for the user's prompt
309
+
- The choose-template endpoint uses a short system prompt to pick from the 13 template names (avoids "default"); the specific model is documented in the AI Integration table
310
+
- Selected template's `theme` and `cytoscapeStyle` are applied to the document **before** the AI streams generated text — so the graph looks right as text arrives
311
+
- Edit mode does NOT use template selection (it edits existing text in-place, preserving the current theme)
312
+
313
+
### Templates in Chart Creation UI
314
+
315
+
-**LoadTemplateDialog** (`app/src/components/LoadTemplateDialog.tsx`): "Examples" button in toolbar; shows grid of 13 thumbnails; user can independently toggle "Load layout and styles" and "Load default content" checkboxes
316
+
-**New hosted chart** (`app/src/pages/New.tsx`): template selector during creation; template content+theme baked into the chart at insert time
317
+
-**loadTemplate()** (`app/src/lib/loadTemplate.ts`): dynamically imports template module, merges theme into doc metadata, unfreezes nodePositions, unmounts/remounts graph for clean re-layout
318
+
319
+
### Key File Reference
320
+
321
+
| Component | File |
322
+
|-----------|------|
323
+
| Template names (source of truth) |`shared/src/templates.ts`|
324
+
| Template data files |`app/src/lib/templates/{name}-template.ts`|
325
+
| FFTheme type definition |`app/src/lib/FFTheme.ts`|
0 commit comments