@tldraw/mermaid 5.7.0 → 5.8.0-canary.15ae3e10cc28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +12 -10
  2. package/dist-cjs/blueprint.js.map +1 -1
  3. package/dist-cjs/classDiagram.js +272 -0
  4. package/dist-cjs/classDiagram.js.map +7 -0
  5. package/dist-cjs/classShape.js +241 -0
  6. package/dist-cjs/classShape.js.map +7 -0
  7. package/dist-cjs/colors.js.map +1 -1
  8. package/dist-cjs/createMermaidDiagram.js +107 -105
  9. package/dist-cjs/createMermaidDiagram.js.map +2 -2
  10. package/dist-cjs/defaultMermaidNodeRenderSpec.js +5 -1
  11. package/dist-cjs/defaultMermaidNodeRenderSpec.js.map +2 -2
  12. package/dist-cjs/endLabelBinding.js +120 -0
  13. package/dist-cjs/endLabelBinding.js.map +7 -0
  14. package/dist-cjs/flowchartDiagram.js +55 -44
  15. package/dist-cjs/flowchartDiagram.js.map +3 -3
  16. package/dist-cjs/index.d.ts +140 -10
  17. package/dist-cjs/index.js +7 -1
  18. package/dist-cjs/index.js.map +2 -2
  19. package/dist-cjs/mermaidNodeCreateShape.js +141 -3
  20. package/dist-cjs/mermaidNodeCreateShape.js.map +2 -2
  21. package/dist-cjs/mindmapDiagram.js +85 -27
  22. package/dist-cjs/mindmapDiagram.js.map +2 -2
  23. package/dist-cjs/peleDiagram.js +231 -0
  24. package/dist-cjs/peleDiagram.js.map +7 -0
  25. package/dist-cjs/renderBlueprint.js +57 -6
  26. package/dist-cjs/renderBlueprint.js.map +3 -3
  27. package/dist-cjs/sequenceDiagram.js +237 -211
  28. package/dist-cjs/sequenceDiagram.js.map +3 -3
  29. package/dist-cjs/stateDiagram.js +38 -22
  30. package/dist-cjs/stateDiagram.js.map +2 -2
  31. package/dist-cjs/svgParsing.js +66 -156
  32. package/dist-cjs/svgParsing.js.map +2 -2
  33. package/dist-cjs/utils.js +43 -8
  34. package/dist-cjs/utils.js.map +2 -2
  35. package/dist-esm/classDiagram.mjs +264 -0
  36. package/dist-esm/classDiagram.mjs.map +7 -0
  37. package/dist-esm/classShape.mjs +235 -0
  38. package/dist-esm/classShape.mjs.map +7 -0
  39. package/dist-esm/colors.mjs.map +1 -1
  40. package/dist-esm/createMermaidDiagram.mjs +115 -97
  41. package/dist-esm/createMermaidDiagram.mjs.map +2 -2
  42. package/dist-esm/defaultMermaidNodeRenderSpec.mjs +5 -1
  43. package/dist-esm/defaultMermaidNodeRenderSpec.mjs.map +2 -2
  44. package/dist-esm/endLabelBinding.mjs +106 -0
  45. package/dist-esm/endLabelBinding.mjs.map +7 -0
  46. package/dist-esm/flowchartDiagram.mjs +58 -52
  47. package/dist-esm/flowchartDiagram.mjs.map +3 -3
  48. package/dist-esm/index.d.mts +140 -10
  49. package/dist-esm/index.mjs +13 -1
  50. package/dist-esm/index.mjs.map +2 -2
  51. package/dist-esm/mermaidNodeCreateShape.mjs +145 -4
  52. package/dist-esm/mermaidNodeCreateShape.mjs.map +2 -2
  53. package/dist-esm/mindmapDiagram.mjs +86 -28
  54. package/dist-esm/mindmapDiagram.mjs.map +2 -2
  55. package/dist-esm/peleDiagram.mjs +205 -0
  56. package/dist-esm/peleDiagram.mjs.map +7 -0
  57. package/dist-esm/renderBlueprint.mjs +59 -4
  58. package/dist-esm/renderBlueprint.mjs.map +2 -2
  59. package/dist-esm/sequenceDiagram.mjs +237 -211
  60. package/dist-esm/sequenceDiagram.mjs.map +3 -3
  61. package/dist-esm/stateDiagram.mjs +44 -31
  62. package/dist-esm/stateDiagram.mjs.map +2 -2
  63. package/dist-esm/svgParsing.mjs +66 -156
  64. package/dist-esm/svgParsing.mjs.map +2 -2
  65. package/dist-esm/utils.mjs +43 -8
  66. package/dist-esm/utils.mjs.map +2 -2
  67. package/package.json +8 -6
  68. package/src/blueprint.ts +43 -2
  69. package/src/classDiagram.test.ts +339 -0
  70. package/src/classDiagram.ts +329 -0
  71. package/src/classShape.tsx +348 -0
  72. package/src/colors.ts +1 -1
  73. package/src/createMermaidDiagram.test.ts +41 -44
  74. package/src/createMermaidDiagram.ts +138 -128
  75. package/src/defaultMermaidNodeRenderSpec.ts +13 -1
  76. package/src/endLabelBinding.ts +167 -0
  77. package/src/flowchartDiagram.ts +108 -74
  78. package/src/index.ts +14 -0
  79. package/src/mermaidDiagrams.test.ts +398 -94
  80. package/src/mermaidNodeCreateShape.ts +197 -5
  81. package/src/mindmapDiagram.ts +133 -36
  82. package/src/peleDiagram.test.ts +323 -0
  83. package/src/peleDiagram.ts +264 -0
  84. package/src/peleSequence.test.ts +399 -0
  85. package/src/renderBlueprint.test.ts +2 -0
  86. package/src/renderBlueprint.ts +77 -4
  87. package/src/sequenceDiagram.ts +377 -303
  88. package/src/stateDiagram.ts +76 -39
  89. package/src/svgParsing.ts +109 -207
  90. package/src/test/createEditor.ts +46 -0
  91. package/src/utils.ts +82 -16
  92. package/src/svgParsing.test.ts +0 -348
package/README.md CHANGED
@@ -4,6 +4,8 @@ Convert [Mermaid](https://mermaid.js.org/) diagram syntax into native, editable
4
4
 
5
5
  Instead of rendering a static SVG, `@tldraw/mermaid` parses Mermaid text and creates real geo shapes, arrows, frames, and groups on the tldraw canvas — so users can move, resize, restyle, and connect them like any other shape.
6
6
 
7
+ Diagrams are parsed and laid out by [pele](https://pele.run), a small Mermaid renderer, rather than the `mermaid` library. Pele reads the same syntax with its own layout, so a diagram can look different from Mermaid's rendering of it.
8
+
7
9
  ## Installation
8
10
 
9
11
  ```bash
@@ -62,9 +64,9 @@ When `centerOnPosition` is `true` (the default), the diagram's center aligns wit
62
64
  | Flowchart | `flowchart`, `graph` | Geo shapes, arrows, subgraph frames |
63
65
  | Sequence diagram | `sequenceDiagram` | Actor shapes, lifelines, signal arrows, fragment frames, participant boxes |
64
66
  | State diagram | `stateDiagram-v2` | State shapes, transitions, compound state frames, fork/join, choice |
65
- | Mindmap | `mindmap` | Colored geo shapes, parent-child edges, tree hierarchy |
67
+ | Mindmap | `mindmap` | Colored geo shapes and text, parent-child edges, tree hierarchy |
66
68
 
67
- Unsupported diagram types (pie, gantt, class, ER, etc.) can be handled with the `onUnsupportedDiagram` callback — for example, to fall back to SVG import:
69
+ Unsupported diagram types (pie, gantt, class, ER, etc.) can be handled with the `onUnsupportedDiagram` callback, which receives the diagram rendered as SVG — for example, to import it as an image:
68
70
 
69
71
  ```tsx
70
72
  await createMermaidDiagram(editor, text, {
@@ -78,12 +80,12 @@ await createMermaidDiagram(editor, text, {
78
80
 
79
81
  ### `createMermaidDiagram(editor, text, options?)`
80
82
 
81
- Parses Mermaid text, extracts layout from the rendered SVG, builds a blueprint, and creates tldraw shapes.
83
+ Parses Mermaid text, lays it out with pele, builds a blueprint from the layout, and creates tldraw shapes.
82
84
 
83
85
  - **`editor`** — a tldraw `Editor` instance.
84
86
  - **`text`** — Mermaid diagram source text.
85
87
  - **`options`** — optional `MermaidDiagramOptions`:
86
- - `mermaidConfig` — Mermaid configuration overrides (theme, spacing, etc.).
88
+ - `mermaidConfig` — layout settings keyed by diagram type, as in Mermaid's config (for example `flowchart.nodeSpacing`, `state.rankSpacing`). A diagram's own frontmatter config takes precedence.
87
89
  - `blueprintRender` — positioning (`position`, `centerOnPosition`) and optional `mapNodeToRenderSpec` (see below).
88
90
  - `onUnsupportedDiagram(svg)` — callback when the diagram type isn't natively supported.
89
91
 
@@ -99,7 +101,7 @@ Error class with `type: 'parse' | 'unsupported'` and `diagramType` properties.
99
101
 
100
102
  ### Customizing node shapes
101
103
 
102
- Blueprint nodes carry layout and semantic `kind` only. At **`renderBlueprint`** time, each node is mapped to a **`MermaidBlueprintNodeRenderSpec`**: either `{ variant: 'geo', geo }` (defaults use the same built-in tables as before) or `{ variant: 'shape', type, props }` for any shape type registered on your editor.
104
+ Blueprint nodes carry layout and semantic `kind` only. At **`renderBlueprint`** time, each node is mapped to a **`MermaidBlueprintNodeRenderSpec`**: `{ variant: 'geo', geo }` (the built-in defaults), `{ variant: 'text' }` for a bare label (the default for mindmap nodes written without brackets), or `{ variant: 'shape', type, props }` for any shape type registered on your editor.
103
105
 
104
106
  Pass **`mapNodeToRenderSpec`** on **`blueprintRender`** (or to `renderBlueprint` directly) with a callback `(input) => spec | undefined`. **`input`** includes `diagramKind`, `nodeId`, `kind`, and the full **`node`**. Return `undefined` to keep the package default for that node. **`defaultCreateMermaidNodeFromBlueprint`** then merges the spec with layout (size, colors, label text) and calls **`editor.createShape`** once per node.
105
107
 
@@ -111,7 +113,7 @@ Helpers: **`defaultMermaidNodeRenderSpec`**, **`resolveMermaidNodeRender`**, **`
111
113
 
112
114
  - **`DiagramMermaidBlueprint`** — `{ diagramKind, nodes, edges, lines?, groups? }`.
113
115
  - **`MermaidBlueprintNode`** — layout, semantic `kind`, and style fields (materialization is chosen at render time).
114
- - **`MermaidBlueprintNodeRenderSpec`** — `variant: 'geo'` + `geo`, or `variant: 'shape'` + `type` + `props`.
116
+ - **`MermaidBlueprintNodeRenderSpec`** — `variant: 'geo'` + `geo`, `variant: 'text'`, or `variant: 'shape'` + `type` + `props`.
115
117
  - **`MermaidDiagramKind`** — `'flowchart' | 'state' | 'sequence' | 'mindmap'`.
116
118
  - **`MermaidBlueprintEdge`** — an arrow with start/end node IDs, bend, arrowheads, dash style, and anchor positions.
117
119
  - **`MermaidBlueprintLineNode`** — a vertical or horizontal line (used for sequence diagram lifelines).
@@ -124,13 +126,13 @@ The conversion happens in three stages:
124
126
 
125
127
  ```mermaid
126
128
  flowchart LR
127
- MermaidText["Mermaid text"] --> ParseRender["Parse and render SVG"]
129
+ MermaidText["Mermaid text"] --> ParseRender["Parse and lay out"]
128
130
  ParseRender --> ExtractBlueprint["Extract blueprint"]
129
131
  ExtractBlueprint --> CreateShapes["Create tldraw shapes"]
130
132
  ```
131
133
 
132
- 1. **Parse and render** — Mermaid parses the text and renders an SVG into an offscreen DOM element, giving us accurate layout positions via `getBBox()`.
133
- 2. **Extract blueprint** — a diagram-specific converter reads positions from the SVG and semantic data from Mermaid's internal database, producing a `DiagramMermaidBlueprint`.
134
+ 1. **Parse and lay out** — pele parses the text into a typed model and renders it to an SVG, measuring text in tldraw's own font so boxes fit their labels. The SVG is mounted offscreen so `getBBox()` works.
135
+ 2. **Extract blueprint** — a diagram-specific converter reads positions from the SVG, where every node, edge and label carries its model id, and combines them with the parsed model, producing a `DiagramMermaidBlueprint`. Each edge's bend is taken from the route pele drew for it.
134
136
  3. **Create shapes** — `renderBlueprint` resolves each node’s materialization spec (mapper or default), then creates tldraw shapes (geo or custom), plus arrows, lines, frames, and groups.
135
137
 
136
138
  ## Example: paste handler
@@ -177,7 +179,7 @@ The regex above is a simplified check. On tldraw.com the detection is handled by
177
179
 
178
180
  ## Lazy loading
179
181
 
180
- The `mermaid` dependency is roughly 2 MB. The paste handler above already lazy-loads with `await import('@tldraw/mermaid')` — the package is only fetched when the pasted text matches a Mermaid keyword. For your own integration, the same pattern applies: pre-screen with a lightweight regex, then dynamic-import the package only when needed.
182
+ `createMermaidDiagram` loads pele on first call, and only the parser and layout for the diagram type being converted. The paste handler above also lazy-loads the package itself with `await import('@tldraw/mermaid')`, so it is only fetched when the pasted text matches a Mermaid keyword. For your own integration, the same pattern applies: pre-screen with a lightweight regex, then dynamic-import the package only when needed.
181
183
 
182
184
  ## Examples
183
185
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/blueprint.ts"],
4
- "sourcesContent": ["import type {\n\tTLArrowShapeArrowheadStyle,\n\tTLDefaultColorStyle,\n\tTLDefaultDashStyle,\n\tTLDefaultFillStyle,\n\tTLDefaultHorizontalAlignStyle,\n\tTLDefaultSizeStyle,\n\tTLDefaultVerticalAlignStyle,\n\tTLGeoShapeGeoStyle,\n} from 'tldraw'\n\n/**\n * Which Mermaid diagram family produced this blueprint (used by default geo tables and mapper dispatch).\n * @public\n */\nexport type MermaidDiagramKind = 'flowchart' | 'state' | 'sequence' | 'mindmap'\n\n/**\n * Optional hook: return a custom render spec for this node, or `undefined` to use the package default mapper.\n * Invoked from {@link renderBlueprint}.\n * @public\n */\nexport type MermaidNodeRenderMapper = (input: {\n\t/** Same as {@link DiagramMermaidBlueprint.diagramKind} for this blueprint. */\n\tdiagramKind: MermaidDiagramKind\n\t/** Blueprint node id (stable binding key). */\n\tnodeId: string\n\t/** Semantic kind for this node in its diagram family. */\n\tkind: string\n\t/** Layout and style fields for this node (no materialization spec \u2014 that is what you return). */\n\tnode: MermaidBlueprintNode\n}) => MermaidBlueprintNodeRenderSpec | undefined\n\n/**\n * Instructions for creating one blueprint node on the canvas: geo variant or custom shape type + props.\n * Merged with layout-derived props in {@link defaultCreateMermaidNodeFromBlueprint}.\n * @public\n */\nexport type MermaidBlueprintNodeRenderSpec =\n\t| {\n\t\t\t/** Use tldraw\u2019s built-in geo shape; `geo` selects the variant (rectangle, diamond, \u2026). */\n\t\t\tvariant: 'geo'\n\t\t\tgeo: TLGeoShapeGeoStyle\n\t }\n\t| {\n\t\t\t/** Use any shape type registered on the editor (including custom ShapeUtils). */\n\t\t\tvariant: 'shape'\n\t\t\t/** Must match `editor.createShape({ type })` \u2014 same string as in the app\u2019s shape schema. */\n\t\t\ttype: string\n\t\t\t/** Partial props merged with layout-derived props (size, colors, label text, \u2026) in {@link defaultCreateMermaidNodeFromBlueprint}. */\n\t\t\tprops: Record<string, unknown>\n\t }\n\n/**\n * Intermediate representation of a parsed Mermaid diagram: nodes, edges, optional lifelines and groups.\n * Produced by diagram-specific `*ToBlueprint` functions and consumed by {@link renderBlueprint}.\n * @public\n */\nexport interface DiagramMermaidBlueprint {\n\tdiagramKind: MermaidDiagramKind\n\tnodes: MermaidBlueprintNode[]\n\tedges: MermaidBlueprintEdge[]\n\tlines?: MermaidBlueprintLineNode[]\n\tgroups?: string[][]\n}\n\n/**\n * One node in the blueprint: layout and semantic kind from Mermaid (materialization is resolved at {@link renderBlueprint} via `mapNodeToRenderSpec` or defaults).\n * @public\n */\nexport interface MermaidBlueprintNode {\n\tid: string\n\tx: number\n\ty: number\n\tw: number\n\th: number\n\t/**\n\t * Stable semantic key from Mermaid (flowchart vertex type, `subgraph`, state kind, actor type,\n\t * internal sequence kinds such as `sequence_note`, mindmap type as decimal string, \u2026).\n\t */\n\tkind: string\n\tparentId?: string\n\tlabel?: string\n\tfill?: TLDefaultFillStyle\n\tcolor?: TLDefaultColorStyle\n\tdash?: TLDefaultDashStyle\n\tsize?: TLDefaultSizeStyle\n\talign?: TLDefaultHorizontalAlignStyle\n\tverticalAlign?: TLDefaultVerticalAlignStyle\n\t/**\n\t * Draw this node beneath the blueprint's lines as well as its other nodes. Lines are otherwise\n\t * drawn beneath every node, so a filled node that spans them, such as a sequence diagram's\n\t * participant box, would hide them.\n\t */\n\tbackground?: boolean\n}\n\n/** @public */\nexport interface MermaidBlueprintEdge {\n\tstartNodeId: string\n\tendNodeId: string\n\tlabel?: string\n\tbend: number\n\tarrowheadEnd?: TLArrowShapeArrowheadStyle\n\tarrowheadStart?: TLArrowShapeArrowheadStyle\n\tdash?: TLDefaultDashStyle\n\tsize?: TLDefaultSizeStyle\n\tcolor?: TLDefaultColorStyle\n\t/** Where the arrow meets its start shape, as a 0\u20131 fraction of that shape's width. Defaults to the center. */\n\tanchorStartX?: number\n\tanchorStartY?: number\n\t/** Where the arrow meets its end shape, as a 0\u20131 fraction of that shape's width. Defaults to the center. */\n\tanchorEndX?: number\n\tanchorEndY?: number\n\tisExact?: boolean\n\tisPrecise?: boolean\n\tisExactEnd?: boolean\n\tisPreciseEnd?: boolean\n\tdecoration?: { type: 'autonumber'; value: string }\n}\n\n/** @public */\nexport interface MermaidBlueprintLineNode {\n\tid: string\n\tx: number\n\ty: number\n\tendX?: number\n\tendY: number\n\tdash?: TLDefaultDashStyle\n\tsize?: TLDefaultSizeStyle\n\tcolor?: TLDefaultColorStyle\n}\n"],
4
+ "sourcesContent": ["import type {\n\tTLArrowShapeArrowheadStyle,\n\tTLDefaultColorStyle,\n\tTLDefaultDashStyle,\n\tTLDefaultFillStyle,\n\tTLDefaultHorizontalAlignStyle,\n\tTLDefaultSizeStyle,\n\tTLDefaultVerticalAlignStyle,\n\tTLGeoShapeGeoStyle,\n} from 'tldraw'\n\n/**\n * Which Mermaid diagram family produced this blueprint (used by default geo tables and mapper dispatch).\n * @public\n */\nexport type MermaidDiagramKind = 'flowchart' | 'state' | 'sequence' | 'mindmap' | 'class'\n\n/**\n * Optional hook: return a custom render spec for this node, or `undefined` to use the package default mapper.\n * Invoked from {@link renderBlueprint}.\n * @public\n */\nexport type MermaidNodeRenderMapper = (input: {\n\t/** Same as {@link DiagramMermaidBlueprint.diagramKind} for this blueprint. */\n\tdiagramKind: MermaidDiagramKind\n\t/** Blueprint node id (stable binding key). */\n\tnodeId: string\n\t/** Semantic kind for this node in its diagram family. */\n\tkind: string\n\t/** Layout and style fields for this node (no materialization spec \u2014 that is what you return). */\n\tnode: MermaidBlueprintNode\n}) => MermaidBlueprintNodeRenderSpec | undefined\n\n/**\n * Instructions for creating one blueprint node on the canvas: geo variant, bare text, or custom shape type + props.\n * Merged with layout-derived props in {@link defaultCreateMermaidNodeFromBlueprint}.\n * @public\n */\nexport type MermaidBlueprintNodeRenderSpec =\n\t| {\n\t\t\t/** Use tldraw\u2019s built-in geo shape; `geo` selects the variant (rectangle, diamond, \u2026). */\n\t\t\tvariant: 'geo'\n\t\t\tgeo: TLGeoShapeGeoStyle\n\t }\n\t| {\n\t\t\t/** Use tldraw's text shape: the label alone, with no outline, centred on the node's box. */\n\t\t\tvariant: 'text'\n\t }\n\t| {\n\t\t\t/** Use any shape type registered on the editor (including custom ShapeUtils). */\n\t\t\tvariant: 'shape'\n\t\t\t/** Must match `editor.createShape({ type })` \u2014 same string as in the app\u2019s shape schema. */\n\t\t\ttype: string\n\t\t\t/** Partial props merged with layout-derived props (size, colors, label text, \u2026) in {@link defaultCreateMermaidNodeFromBlueprint}. */\n\t\t\tprops: Record<string, unknown>\n\t }\n\n/**\n * Intermediate representation of a parsed Mermaid diagram: nodes, edges, optional lifelines and groups.\n * Produced by diagram-specific `*ToBlueprint` functions and consumed by {@link renderBlueprint}.\n * @public\n */\nexport interface DiagramMermaidBlueprint {\n\tdiagramKind: MermaidDiagramKind\n\tnodes: MermaidBlueprintNode[]\n\tedges: MermaidBlueprintEdge[]\n\tlines?: MermaidBlueprintLineNode[]\n\tgroups?: string[][]\n}\n\n/**\n * One attribute or method line in a class box. Mermaid marks static members with `$` (drawn\n * underlined) and abstract ones with `*` (drawn in italics).\n * @public\n */\nexport interface MermaidClassMember {\n\ttext: string\n\tclassifier?: 'static' | 'abstract'\n}\n\n/**\n * The contents of a UML class box: a header (annotations and name), then attributes, then methods.\n * @public\n */\nexport interface MermaidClassBox {\n\tannotations: string[]\n\tname: string\n\tattributes: MermaidClassMember[]\n\tmethods: MermaidClassMember[]\n}\n\n/**\n * One node in the blueprint: layout and semantic kind from Mermaid (materialization is resolved at {@link renderBlueprint} via `mapNodeToRenderSpec` or defaults).\n * @public\n */\nexport interface MermaidBlueprintNode {\n\tid: string\n\tx: number\n\ty: number\n\tw: number\n\th: number\n\t/**\n\t * Stable semantic key from Mermaid (flowchart vertex type, `subgraph`, state kind, actor type,\n\t * internal sequence kinds such as `sequence_note`, mindmap type as decimal string, \u2026).\n\t */\n\tkind: string\n\tparentId?: string\n\tlabel?: string\n\tfill?: TLDefaultFillStyle\n\tcolor?: TLDefaultColorStyle\n\tdash?: TLDefaultDashStyle\n\tsize?: TLDefaultSizeStyle\n\talign?: TLDefaultHorizontalAlignStyle\n\tverticalAlign?: TLDefaultVerticalAlignStyle\n\t/**\n\t * Draw this node beneath the blueprint's lines as well as its other nodes. Lines are otherwise\n\t * drawn beneath every node, so a filled node that spans them, such as a sequence diagram's\n\t * participant box, would hide them.\n\t */\n\tbackground?: boolean\n\t/** A class diagram's class: the sections {@link MermaidClassShapeUtil} draws. */\n\tclassBox?: MermaidClassBox\n}\n\n/** @public */\nexport interface MermaidBlueprintEdge {\n\tstartNodeId: string\n\tendNodeId: string\n\tlabel?: string\n\t/**\n\t * Text beside the arrow's start, such as a class diagram's multiplicity. Kept there when\n\t * {@link MermaidEndLabelBindingUtil} is registered, folded into `label` otherwise.\n\t */\n\tstartLabel?: string\n\t/** Like `startLabel`, beside the arrow's end. */\n\tendLabel?: string\n\tbend: number\n\t/**\n\t * Where the label sits along the arrow, from 0 to 1. Defaults to the middle.\n\t * @internal\n\t */\n\tlabelPosition?: number\n\tarrowheadEnd?: TLArrowShapeArrowheadStyle\n\tarrowheadStart?: TLArrowShapeArrowheadStyle\n\t/** Fills closed arrowheads (triangles, diamonds). `none`, the default, leaves them hollow. */\n\tfill?: TLDefaultFillStyle\n\tdash?: TLDefaultDashStyle\n\tsize?: TLDefaultSizeStyle\n\tcolor?: TLDefaultColorStyle\n\t/** Where the arrow meets its start shape, as a 0\u20131 fraction of that shape's width. Defaults to the center. */\n\tanchorStartX?: number\n\tanchorStartY?: number\n\t/** Where the arrow meets its end shape, as a 0\u20131 fraction of that shape's width. Defaults to the center. */\n\tanchorEndX?: number\n\tanchorEndY?: number\n\tisExact?: boolean\n\tisPrecise?: boolean\n\tisExactEnd?: boolean\n\tisPreciseEnd?: boolean\n\tdecoration?: { type: 'autonumber'; value: string }\n}\n\n/** @public */\nexport interface MermaidBlueprintLineNode {\n\tid: string\n\tx: number\n\ty: number\n\tendX?: number\n\tendY: number\n\tdash?: TLDefaultDashStyle\n\tsize?: TLDefaultSizeStyle\n\tcolor?: TLDefaultColorStyle\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var classDiagram_exports = {};
20
+ __export(classDiagram_exports, {
21
+ classToBlueprint: () => classToBlueprint,
22
+ parseClassDiagramLayout: () => parseClassDiagramLayout
23
+ });
24
+ module.exports = __toCommonJS(classDiagram_exports);
25
+ var import_colors = require("./colors");
26
+ var import_peleDiagram = require("./peleDiagram");
27
+ var import_svgParsing = require("./svgParsing");
28
+ var import_utils = require("./utils");
29
+ const AGGREGATION = 0;
30
+ const EXTENSION = 1;
31
+ const COMPOSITION = 2;
32
+ const DEPENDENCY = 3;
33
+ const LOLLIPOP = 4;
34
+ const DOTTED_LINE = 1;
35
+ function mapRelationTypeToArrowhead(type) {
36
+ switch (type) {
37
+ case AGGREGATION:
38
+ case COMPOSITION:
39
+ return "diamond";
40
+ case EXTENSION:
41
+ return "triangle";
42
+ case DEPENDENCY:
43
+ return "arrow";
44
+ case LOLLIPOP:
45
+ return "dot";
46
+ default:
47
+ return "none";
48
+ }
49
+ }
50
+ function parseClassDiagramLayout(root, model) {
51
+ const ends = /* @__PURE__ */ new Map();
52
+ model.relations.forEach((relation, i) => {
53
+ ends.set(`id_${relation.id1}_${relation.id2}_${i + 1}`, {
54
+ start: relation.id1,
55
+ end: relation.id2
56
+ });
57
+ });
58
+ for (const note of model.notes.values()) {
59
+ if (note.class) ends.set(`edgeNote${note.index}`, { start: note.id, end: note.class });
60
+ }
61
+ return (0, import_peleDiagram.parsePeleLayout)(root, { edgeEnds: (id) => ends.get(id) });
62
+ }
63
+ function toClassMember(member) {
64
+ const { displayText } = member.getDisplayDetails();
65
+ if (member.classifier === "$") return { text: displayText, classifier: "static" };
66
+ if (member.classifier === "*") return { text: displayText, classifier: "abstract" };
67
+ return { text: displayText };
68
+ }
69
+ function getClassBox(classNode) {
70
+ const name = classNode.label || classNode.id;
71
+ return {
72
+ annotations: classNode.annotations,
73
+ // pele keeps a generic apart from the name: `class Box~T~` is `Box` of type `T`.
74
+ name: classNode.type ? `${name}<${classNode.type}>` : name,
75
+ attributes: classNode.members.map(toClassMember),
76
+ methods: classNode.methods.map(toClassMember)
77
+ };
78
+ }
79
+ function getClassLabel({ annotations, name, attributes, methods }) {
80
+ const header = [...annotations.map((annotation) => `\xAB${annotation}\xBB`), name];
81
+ const sections = [attributes, methods].filter((members) => members.length > 0).map((members) => members.map((member) => member.text));
82
+ return [header, ...sections].map((lines) => lines.map(import_utils.escapeHtml).join("<br>")).join("<br><br>");
83
+ }
84
+ function getMultiplicity(title) {
85
+ return title && title !== "none" ? title : void 0;
86
+ }
87
+ const NAMESPACE_LABEL_ROOM = 50;
88
+ function makeRoomForNamespaceLabels(nodes) {
89
+ const frames = nodes.filter((node) => node.kind === "namespace");
90
+ const byId = new Map(frames.map((frame) => [frame.id, frame]));
91
+ const depth = (frame) => {
92
+ let count = 0;
93
+ for (let id = frame.parentId; id && byId.has(id); id = byId.get(id).parentId) count++;
94
+ return count;
95
+ };
96
+ for (const frame of [...frames].sort((a, b) => depth(b) - depth(a))) {
97
+ const children = frames.filter((child) => child.parentId === frame.id);
98
+ if (children.length === 0) continue;
99
+ const top = Math.min(...children.map((child) => child.y)) - NAMESPACE_LABEL_ROOM;
100
+ if (top >= frame.y) continue;
101
+ frame.h += frame.y - top;
102
+ frame.y = top;
103
+ }
104
+ }
105
+ function classToBlueprint(layout, model) {
106
+ const { nodes: svgNodes, clusters, edges: svgEdges } = layout;
107
+ const nodes = [];
108
+ const blueprintEdges = [];
109
+ const drawn = (id) => id && clusters.has(id) ? id : void 0;
110
+ const namespaces = [...model.namespaces.values()].filter(
111
+ (namespace) => clusters.has(namespace.id)
112
+ );
113
+ for (const namespace of (0, import_utils.orderTopDown)(
114
+ namespaces,
115
+ (node) => node.id,
116
+ (node) => drawn(node.parent)
117
+ )) {
118
+ const cluster = clusters.get(namespace.id);
119
+ const parentId = drawn(namespace.parent);
120
+ nodes.push({
121
+ id: namespace.id,
122
+ kind: "namespace",
123
+ x: cluster.topLeft.x,
124
+ y: cluster.topLeft.y - import_utils.FRAME_TOP_PAD,
125
+ w: cluster.width,
126
+ h: cluster.height + import_utils.FRAME_TOP_PAD,
127
+ parentId,
128
+ label: parentId ? namespace.label : namespace.id,
129
+ fill: "semi",
130
+ color: "black",
131
+ dash: "draw",
132
+ size: "s",
133
+ // Top left, as pele draws it: centred, it sits where relations into the namespace come
134
+ // down its middle.
135
+ align: "start",
136
+ verticalAlign: "start"
137
+ });
138
+ }
139
+ const classDefs = new Map(
140
+ [...model.styleClasses].map(([id, { styles }]) => [
141
+ id,
142
+ { styles: styles.flatMap((style) => style.split(/,(?![^(]*\))/)) }
143
+ ])
144
+ );
145
+ const colorsByClass = (0, import_colors.buildClassDefColorMap)(
146
+ classDefs,
147
+ [...model.classes].map(([id, classNode]) => [id, { classes: classNode.cssClasses.split(" ") }])
148
+ );
149
+ for (const [id, classNode] of model.classes) {
150
+ const svgNode = svgNodes.get(id);
151
+ if (!svgNode) continue;
152
+ const classBox = getClassBox(classNode);
153
+ const hasMembers = classBox.attributes.length > 0 || classBox.methods.length > 0;
154
+ nodes.push({
155
+ id,
156
+ kind: "class",
157
+ x: svgNode.center.x - svgNode.width / 2,
158
+ y: svgNode.center.y - svgNode.height / 2,
159
+ w: svgNode.width,
160
+ h: svgNode.height,
161
+ parentId: drawn(classNode.parent),
162
+ label: getClassLabel(classBox),
163
+ classBox,
164
+ ...(0, import_colors.toNodeColorProps)(colorsByClass.get(id) ?? (0, import_colors.parseNodeInlineColor)(classNode.styles)),
165
+ align: hasMembers ? "start" : "middle",
166
+ verticalAlign: hasMembers ? "start" : "middle",
167
+ size: "m"
168
+ });
169
+ }
170
+ for (const note of model.notes.values()) {
171
+ const svgNode = svgNodes.get(note.id);
172
+ if (!svgNode) continue;
173
+ nodes.push({
174
+ id: note.id,
175
+ kind: "note",
176
+ x: svgNode.center.x - svgNode.width / 2,
177
+ y: svgNode.center.y - svgNode.height / 2,
178
+ w: svgNode.width,
179
+ h: svgNode.height,
180
+ parentId: drawn(note.parent),
181
+ // The layout's lines, which keep the note's `<br>` breaks.
182
+ label: svgNode.lines?.join("\n") ?? note.text,
183
+ fill: "solid",
184
+ color: "yellow",
185
+ size: "s",
186
+ align: "middle",
187
+ verticalAlign: "middle"
188
+ });
189
+ }
190
+ for (const { id, label } of model.interfaces) {
191
+ const svgNode = svgNodes.get(id);
192
+ if (!svgNode) continue;
193
+ nodes.push({
194
+ id,
195
+ kind: "interface",
196
+ x: svgNode.center.x - svgNode.width / 2,
197
+ y: svgNode.center.y - svgNode.height / 2,
198
+ w: svgNode.width,
199
+ h: svgNode.height,
200
+ label,
201
+ size: "m",
202
+ align: "middle",
203
+ verticalAlign: "middle"
204
+ });
205
+ }
206
+ const nodeById = new Map(nodes.map((node) => [node.id, node]));
207
+ const claimed = /* @__PURE__ */ new Set();
208
+ for (const relation of model.relations) {
209
+ const startBox = (0, import_svgParsing.getLayoutBox)(layout, relation.id1);
210
+ const endBox = (0, import_svgParsing.getLayoutBox)(layout, relation.id2);
211
+ const svgEdge = (0, import_svgParsing.claimEdge)(svgEdges, claimed, {
212
+ startId: relation.id1,
213
+ endId: relation.id2,
214
+ startBox,
215
+ endBox
216
+ });
217
+ const svgNode = svgNodes.get(relation.id1);
218
+ const selfLoop = relation.id1 === relation.id2 && svgEdge && svgNode ? (0, import_svgParsing.getSelfLoopEdgeLayout)(svgEdge, svgNode, layout.edgeLabels) : void 0;
219
+ const label = svgEdge && layout.edgeLabels.get(svgEdge.id);
220
+ const labelPosition = label && svgEdge && !selfLoop ? (0, import_svgParsing.getPositionAlongRoute)(svgEdge.points, {
221
+ x: label.x + label.w / 2,
222
+ y: label.y + label.h / 2
223
+ }) : void 0;
224
+ const anchors = svgEdge && !selfLoop && startBox && endBox ? (0, import_svgParsing.getRouteEndAnchors)(svgEdge, startBox, endBox) : void 0;
225
+ const bend = svgEdge && anchors ? (0, import_utils.getRouteArcBend)(
226
+ svgEdge.points,
227
+ nodeById.get(relation.id1),
228
+ nodeById.get(relation.id2),
229
+ anchors,
230
+ { hasLabel: !!label }
231
+ ) : 0;
232
+ const { type1, type2, lineType } = relation.relation;
233
+ blueprintEdges.push({
234
+ startNodeId: relation.id1,
235
+ endNodeId: relation.id2,
236
+ label: label?.lines?.join("\n") ?? (relation.title || void 0),
237
+ startLabel: getMultiplicity(relation.relationTitle1),
238
+ endLabel: getMultiplicity(relation.relationTitle2),
239
+ bend,
240
+ ...anchors,
241
+ labelPosition,
242
+ ...selfLoop,
243
+ arrowheadStart: mapRelationTypeToArrowhead(type1),
244
+ arrowheadEnd: mapRelationTypeToArrowhead(type2),
245
+ // An arrow has one fill for both ends, so a composition's filled diamond also fills a
246
+ // triangle or aggregation diamond at the other end. Relations rarely mix the two.
247
+ fill: type1 === COMPOSITION || type2 === COMPOSITION ? "fill" : "none",
248
+ dash: lineType === DOTTED_LINE ? "dashed" : "solid",
249
+ size: "m"
250
+ });
251
+ }
252
+ for (const note of model.notes.values()) {
253
+ if (!note.class) continue;
254
+ const svgEdge = (0, import_svgParsing.claimEdge)(svgEdges, claimed, { startId: note.id, endId: note.class });
255
+ const startBox = (0, import_svgParsing.getLayoutBox)(layout, note.id);
256
+ const endBox = (0, import_svgParsing.getLayoutBox)(layout, note.class);
257
+ const anchors = svgEdge && startBox && endBox ? (0, import_svgParsing.getRouteEndAnchors)(svgEdge, startBox, endBox) : void 0;
258
+ blueprintEdges.push({
259
+ startNodeId: note.id,
260
+ endNodeId: note.class,
261
+ bend: 0,
262
+ ...anchors,
263
+ arrowheadStart: "none",
264
+ arrowheadEnd: "none",
265
+ dash: "dotted",
266
+ size: "m"
267
+ });
268
+ }
269
+ makeRoomForNamespaceLabels(nodes);
270
+ return { diagramKind: "class", nodes, edges: (0, import_utils.dropDanglingEdges)(nodes, blueprintEdges) };
271
+ }
272
+ //# sourceMappingURL=classDiagram.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/classDiagram.ts"],
4
+ "sourcesContent": ["import type { ClassModel } from 'pele'\nimport type { TLArrowShapeArrowheadStyle } from 'tldraw'\nimport type {\n\tDiagramMermaidBlueprint,\n\tMermaidBlueprintEdge,\n\tMermaidBlueprintNode,\n\tMermaidClassBox,\n\tMermaidClassMember,\n} from './blueprint'\nimport { buildClassDefColorMap, parseNodeInlineColor, toNodeColorProps } from './colors'\nimport { parsePeleLayout } from './peleDiagram'\nimport {\n\tclaimEdge,\n\tgetLayoutBox,\n\tgetPositionAlongRoute,\n\tgetRouteEndAnchors,\n\tgetSelfLoopEdgeLayout,\n\ttype ParsedDiagramLayout,\n} from './svgParsing'\nimport {\n\tdropDanglingEdges,\n\tescapeHtml,\n\tFRAME_TOP_PAD,\n\tgetRouteArcBend,\n\torderTopDown,\n} from './utils'\n\ntype ClassNode = ClassModel['classes'] extends Map<string, infer T> ? T : never\ntype ClassMember = ClassNode['members'][number]\n\n// The model's `relationType` values. A relation end with no marker is the string `'none'`.\nconst AGGREGATION = 0\nconst EXTENSION = 1\nconst COMPOSITION = 2\nconst DEPENDENCY = 3\n// `Swimmable ()-- Duck`: a lollipop interface, the end at the interface's name.\nconst LOLLIPOP = 4\n\nconst DOTTED_LINE = 1\n\nfunction mapRelationTypeToArrowhead(type: number | string): TLArrowShapeArrowheadStyle {\n\tswitch (type) {\n\t\tcase AGGREGATION:\n\t\tcase COMPOSITION:\n\t\t\treturn 'diamond'\n\t\tcase EXTENSION:\n\t\t\treturn 'triangle'\n\t\tcase DEPENDENCY:\n\t\t\treturn 'arrow'\n\t\tcase LOLLIPOP:\n\t\t\treturn 'dot'\n\t\tdefault:\n\t\t\treturn 'none'\n\t}\n}\n\n/** Parse pele's class diagram SVG for use by {@link classToBlueprint}. */\nexport function parseClassDiagramLayout(root: Element, model: ClassModel): ParsedDiagramLayout {\n\t// pele names the nth relation's path `id_<id1>_<id2>_<n>`, counting from 1, and the line from a\n\t// note to its class `edgeNote<n>` after the note's index.\n\tconst ends = new Map<string, { start: string; end: string }>()\n\tmodel.relations.forEach((relation, i) => {\n\t\tends.set(`id_${relation.id1}_${relation.id2}_${i + 1}`, {\n\t\t\tstart: relation.id1,\n\t\t\tend: relation.id2,\n\t\t})\n\t})\n\tfor (const note of model.notes.values()) {\n\t\tif (note.class) ends.set(`edgeNote${note.index}`, { start: note.id, end: note.class })\n\t}\n\treturn parsePeleLayout(root, { edgeEnds: (id) => ends.get(id) })\n}\n\nfunction toClassMember(member: ClassMember): MermaidClassMember {\n\tconst { displayText } = member.getDisplayDetails()\n\tif (member.classifier === '$') return { text: displayText, classifier: 'static' }\n\tif (member.classifier === '*') return { text: displayText, classifier: 'abstract' }\n\treturn { text: displayText }\n}\n\nfunction getClassBox(classNode: ClassNode): MermaidClassBox {\n\tconst name = classNode.label || classNode.id\n\treturn {\n\t\tannotations: classNode.annotations,\n\t\t// pele keeps a generic apart from the name: `class Box~T~` is `Box` of type `T`.\n\t\tname: classNode.type ? `${name}<${classNode.type}>` : name,\n\t\tattributes: classNode.members.map(toClassMember),\n\t\tmethods: classNode.methods.map(toClassMember),\n\t}\n}\n\n// Read as HTML, where member text such as `List<int> items` would lose its generic.\nfunction getClassLabel({ annotations, name, attributes, methods }: MermaidClassBox): string {\n\tconst header = [...annotations.map((annotation) => `\u00AB${annotation}\u00BB`), name]\n\tconst sections = [attributes, methods]\n\t\t.filter((members) => members.length > 0)\n\t\t.map((members) => members.map((member) => member.text))\n\treturn [header, ...sections].map((lines) => lines.map(escapeHtml).join('<br>')).join('<br><br>')\n}\n\nfunction getMultiplicity(title: string) {\n\treturn title && title !== 'none' ? title : undefined\n}\n\n// The layout leaves less room above a nested namespace than tldraw's frame label takes, so the\n// child frame would hide its parent's name.\nconst NAMESPACE_LABEL_ROOM = 50\n\n/** Grow each namespace upward until its child namespaces clear its label, innermost first. */\nfunction makeRoomForNamespaceLabels(nodes: MermaidBlueprintNode[]) {\n\tconst frames = nodes.filter((node) => node.kind === 'namespace')\n\tconst byId = new Map(frames.map((frame) => [frame.id, frame]))\n\tconst depth = (frame: MermaidBlueprintNode) => {\n\t\tlet count = 0\n\t\tfor (let id = frame.parentId; id && byId.has(id); id = byId.get(id)!.parentId) count++\n\t\treturn count\n\t}\n\tfor (const frame of [...frames].sort((a, b) => depth(b) - depth(a))) {\n\t\tconst children = frames.filter((child) => child.parentId === frame.id)\n\t\tif (children.length === 0) continue\n\t\tconst top = Math.min(...children.map((child) => child.y)) - NAMESPACE_LABEL_ROOM\n\t\tif (top >= frame.y) continue\n\t\tframe.h += frame.y - top\n\t\tframe.y = top\n\t}\n}\n\n/** Convert a parsed class diagram into a tldraw blueprint of nodes and edges. */\nexport function classToBlueprint(\n\tlayout: ParsedDiagramLayout,\n\tmodel: Pick<\n\t\tClassModel,\n\t\t'classes' | 'relations' | 'namespaces' | 'notes' | 'interfaces' | 'styleClasses'\n\t>\n): DiagramMermaidBlueprint {\n\tconst { nodes: svgNodes, clusters, edges: svgEdges } = layout\n\tconst nodes: MermaidBlueprintNode[] = []\n\tconst blueprintEdges: MermaidBlueprintEdge[] = []\n\n\t// The model nests every dotted namespace, but with `hierarchicalNamespaces: false` pele draws\n\t// only the declared ones, side by side and named in full. Frames follow what was drawn.\n\tconst drawn = (id: string | undefined) => (id && clusters.has(id) ? id : undefined)\n\tconst namespaces = [...model.namespaces.values()].filter((namespace) =>\n\t\tclusters.has(namespace.id)\n\t)\n\tfor (const namespace of orderTopDown(\n\t\tnamespaces,\n\t\t(node) => node.id,\n\t\t(node) => drawn(node.parent)\n\t)) {\n\t\tconst cluster = clusters.get(namespace.id)!\n\t\tconst parentId = drawn(namespace.parent)\n\t\tnodes.push({\n\t\t\tid: namespace.id,\n\t\t\tkind: 'namespace',\n\t\t\tx: cluster.topLeft.x,\n\t\t\ty: cluster.topLeft.y - FRAME_TOP_PAD,\n\t\t\tw: cluster.width,\n\t\t\th: cluster.height + FRAME_TOP_PAD,\n\t\t\tparentId,\n\t\t\tlabel: parentId ? namespace.label : namespace.id,\n\t\t\tfill: 'semi',\n\t\t\tcolor: 'black',\n\t\t\tdash: 'draw',\n\t\t\tsize: 's',\n\t\t\t// Top left, as pele draws it: centred, it sits where relations into the namespace come\n\t\t\t// down its middle.\n\t\t\talign: 'start',\n\t\t\tverticalAlign: 'start',\n\t\t})\n\t}\n\n\t// pele keeps a class diagram's `classDef` as one comma-joined declaration, where a flowchart's\n\t// is split into one per property. Commas inside `rgb(\u2026)` stay put.\n\tconst classDefs = new Map(\n\t\t[...model.styleClasses].map(([id, { styles }]) => [\n\t\t\tid,\n\t\t\t{ styles: styles.flatMap((style) => style.split(/,(?![^(]*\\))/)) },\n\t\t])\n\t)\n\tconst colorsByClass = buildClassDefColorMap(\n\t\tclassDefs,\n\t\t[...model.classes].map(([id, classNode]) => [id, { classes: classNode.cssClasses.split(' ') }])\n\t)\n\tfor (const [id, classNode] of model.classes) {\n\t\tconst svgNode = svgNodes.get(id)\n\t\tif (!svgNode) continue\n\n\t\tconst classBox = getClassBox(classNode)\n\t\tconst hasMembers = classBox.attributes.length > 0 || classBox.methods.length > 0\n\t\tnodes.push({\n\t\t\tid,\n\t\t\tkind: 'class',\n\t\t\tx: svgNode.center.x - svgNode.width / 2,\n\t\t\ty: svgNode.center.y - svgNode.height / 2,\n\t\t\tw: svgNode.width,\n\t\t\th: svgNode.height,\n\t\t\tparentId: drawn(classNode.parent),\n\t\t\tlabel: getClassLabel(classBox),\n\t\t\tclassBox,\n\t\t\t...toNodeColorProps(colorsByClass.get(id) ?? parseNodeInlineColor(classNode.styles)),\n\t\t\talign: hasMembers ? 'start' : 'middle',\n\t\t\tverticalAlign: hasMembers ? 'start' : 'middle',\n\t\t\tsize: 'm',\n\t\t})\n\t}\n\n\tfor (const note of model.notes.values()) {\n\t\tconst svgNode = svgNodes.get(note.id)\n\t\tif (!svgNode) continue\n\t\tnodes.push({\n\t\t\tid: note.id,\n\t\t\tkind: 'note',\n\t\t\tx: svgNode.center.x - svgNode.width / 2,\n\t\t\ty: svgNode.center.y - svgNode.height / 2,\n\t\t\tw: svgNode.width,\n\t\t\th: svgNode.height,\n\t\t\tparentId: drawn(note.parent),\n\t\t\t// The layout's lines, which keep the note's `<br>` breaks.\n\t\t\tlabel: svgNode.lines?.join('\\n') ?? note.text,\n\t\t\tfill: 'solid',\n\t\t\tcolor: 'yellow',\n\t\t\tsize: 's',\n\t\t\talign: 'middle',\n\t\t\tverticalAlign: 'middle',\n\t\t})\n\t}\n\n\t// pele draws a lollipop interface as its name, and the circle as a marker on the relation's end.\n\tfor (const { id, label } of model.interfaces) {\n\t\tconst svgNode = svgNodes.get(id)\n\t\tif (!svgNode) continue\n\t\tnodes.push({\n\t\t\tid,\n\t\t\tkind: 'interface',\n\t\t\tx: svgNode.center.x - svgNode.width / 2,\n\t\t\ty: svgNode.center.y - svgNode.height / 2,\n\t\t\tw: svgNode.width,\n\t\t\th: svgNode.height,\n\t\t\tlabel,\n\t\t\tsize: 'm',\n\t\t\talign: 'middle',\n\t\t\tverticalAlign: 'middle',\n\t\t})\n\t}\n\n\tconst nodeById = new Map(nodes.map((node) => [node.id, node]))\n\tconst claimed = new Set<number>()\n\tfor (const relation of model.relations) {\n\t\tconst startBox = getLayoutBox(layout, relation.id1)\n\t\tconst endBox = getLayoutBox(layout, relation.id2)\n\t\tconst svgEdge = claimEdge(svgEdges, claimed, {\n\t\t\tstartId: relation.id1,\n\t\t\tendId: relation.id2,\n\t\t\tstartBox,\n\t\t\tendBox,\n\t\t})\n\t\tconst svgNode = svgNodes.get(relation.id1)\n\t\tconst selfLoop =\n\t\t\trelation.id1 === relation.id2 && svgEdge && svgNode\n\t\t\t\t? getSelfLoopEdgeLayout(svgEdge, svgNode, layout.edgeLabels)\n\t\t\t\t: undefined\n\t\tconst label = svgEdge && layout.edgeLabels.get(svgEdge.id)\n\t\t// Where the layout drew the label along the route; a loop places its label with its bend.\n\t\tconst labelPosition =\n\t\t\tlabel && svgEdge && !selfLoop\n\t\t\t\t? getPositionAlongRoute(svgEdge.points, {\n\t\t\t\t\t\tx: label.x + label.w / 2,\n\t\t\t\t\t\ty: label.y + label.h / 2,\n\t\t\t\t\t})\n\t\t\t\t: undefined\n\t\tconst anchors =\n\t\t\tsvgEdge && !selfLoop && startBox && endBox\n\t\t\t\t? getRouteEndAnchors(svgEdge, startBox, endBox)\n\t\t\t\t: undefined\n\t\tconst bend =\n\t\t\tsvgEdge && anchors\n\t\t\t\t? getRouteArcBend(\n\t\t\t\t\t\tsvgEdge.points,\n\t\t\t\t\t\tnodeById.get(relation.id1),\n\t\t\t\t\t\tnodeById.get(relation.id2),\n\t\t\t\t\t\tanchors,\n\t\t\t\t\t\t{ hasLabel: !!label }\n\t\t\t\t\t)\n\t\t\t\t: 0\n\t\tconst { type1, type2, lineType } = relation.relation\n\n\t\tblueprintEdges.push({\n\t\t\tstartNodeId: relation.id1,\n\t\t\tendNodeId: relation.id2,\n\t\t\tlabel: label?.lines?.join('\\n') ?? (relation.title || undefined),\n\t\t\tstartLabel: getMultiplicity(relation.relationTitle1),\n\t\t\tendLabel: getMultiplicity(relation.relationTitle2),\n\t\t\tbend,\n\t\t\t...anchors,\n\t\t\tlabelPosition,\n\t\t\t...selfLoop,\n\t\t\tarrowheadStart: mapRelationTypeToArrowhead(type1),\n\t\t\tarrowheadEnd: mapRelationTypeToArrowhead(type2),\n\t\t\t// An arrow has one fill for both ends, so a composition's filled diamond also fills a\n\t\t\t// triangle or aggregation diamond at the other end. Relations rarely mix the two.\n\t\t\tfill: type1 === COMPOSITION || type2 === COMPOSITION ? 'fill' : 'none',\n\t\t\tdash: lineType === DOTTED_LINE ? 'dashed' : 'solid',\n\t\t\tsize: 'm',\n\t\t})\n\t}\n\n\tfor (const note of model.notes.values()) {\n\t\tif (!note.class) continue\n\t\tconst svgEdge = claimEdge(svgEdges, claimed, { startId: note.id, endId: note.class })\n\t\tconst startBox = getLayoutBox(layout, note.id)\n\t\tconst endBox = getLayoutBox(layout, note.class)\n\t\tconst anchors =\n\t\t\tsvgEdge && startBox && endBox ? getRouteEndAnchors(svgEdge, startBox, endBox) : undefined\n\t\tblueprintEdges.push({\n\t\t\tstartNodeId: note.id,\n\t\t\tendNodeId: note.class,\n\t\t\tbend: 0,\n\t\t\t...anchors,\n\t\t\tarrowheadStart: 'none',\n\t\t\tarrowheadEnd: 'none',\n\t\t\tdash: 'dotted',\n\t\t\tsize: 'm',\n\t\t})\n\t}\n\n\tmakeRoomForNamespaceLabels(nodes)\n\treturn { diagramKind: 'class', nodes, edges: dropDanglingEdges(nodes, blueprintEdges) }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,oBAA8E;AAC9E,yBAAgC;AAChC,wBAOO;AACP,mBAMO;AAMP,MAAM,cAAc;AACpB,MAAM,YAAY;AAClB,MAAM,cAAc;AACpB,MAAM,aAAa;AAEnB,MAAM,WAAW;AAEjB,MAAM,cAAc;AAEpB,SAAS,2BAA2B,MAAmD;AACtF,UAAQ,MAAM;AAAA,IACb,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAGO,SAAS,wBAAwB,MAAe,OAAwC;AAG9F,QAAM,OAAO,oBAAI,IAA4C;AAC7D,QAAM,UAAU,QAAQ,CAAC,UAAU,MAAM;AACxC,SAAK,IAAI,MAAM,SAAS,GAAG,IAAI,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI;AAAA,MACvD,OAAO,SAAS;AAAA,MAChB,KAAK,SAAS;AAAA,IACf,CAAC;AAAA,EACF,CAAC;AACD,aAAW,QAAQ,MAAM,MAAM,OA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