@tldraw/mermaid 5.5.0-next.4d6473b0bda1 → 5.5.0-next.8a3d5202c15f

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 (68) hide show
  1. package/README.md +6 -6
  2. package/dist-cjs/blueprint.js.map +1 -1
  3. package/dist-cjs/colors.js +173 -16
  4. package/dist-cjs/colors.js.map +2 -2
  5. package/dist-cjs/createMermaidDiagram.js +15 -6
  6. package/dist-cjs/createMermaidDiagram.js.map +2 -2
  7. package/dist-cjs/defaultMermaidNodeRenderSpec.js +13 -40
  8. package/dist-cjs/defaultMermaidNodeRenderSpec.js.map +2 -2
  9. package/dist-cjs/flowchartDiagram.js +55 -68
  10. package/dist-cjs/flowchartDiagram.js.map +3 -3
  11. package/dist-cjs/index.d.ts +10 -0
  12. package/dist-cjs/index.js +1 -1
  13. package/dist-cjs/mermaidNodeCreateShape.js +32 -25
  14. package/dist-cjs/mermaidNodeCreateShape.js.map +2 -2
  15. package/dist-cjs/mindmapDiagram.js +43 -67
  16. package/dist-cjs/mindmapDiagram.js.map +2 -2
  17. package/dist-cjs/renderBlueprint.js +122 -172
  18. package/dist-cjs/renderBlueprint.js.map +2 -2
  19. package/dist-cjs/sequenceDiagram.js +349 -233
  20. package/dist-cjs/sequenceDiagram.js.map +3 -3
  21. package/dist-cjs/stateDiagram.js +87 -160
  22. package/dist-cjs/stateDiagram.js.map +3 -3
  23. package/dist-cjs/svgParsing.js +125 -30
  24. package/dist-cjs/svgParsing.js.map +2 -2
  25. package/dist-cjs/utils.js +23 -7
  26. package/dist-cjs/utils.js.map +2 -2
  27. package/dist-esm/colors.mjs +173 -16
  28. package/dist-esm/colors.mjs.map +2 -2
  29. package/dist-esm/createMermaidDiagram.mjs +16 -7
  30. package/dist-esm/createMermaidDiagram.mjs.map +2 -2
  31. package/dist-esm/defaultMermaidNodeRenderSpec.mjs +13 -40
  32. package/dist-esm/defaultMermaidNodeRenderSpec.mjs.map +2 -2
  33. package/dist-esm/flowchartDiagram.mjs +68 -71
  34. package/dist-esm/flowchartDiagram.mjs.map +3 -3
  35. package/dist-esm/index.d.mts +10 -0
  36. package/dist-esm/index.mjs +1 -1
  37. package/dist-esm/mermaidNodeCreateShape.mjs +37 -26
  38. package/dist-esm/mermaidNodeCreateShape.mjs.map +2 -2
  39. package/dist-esm/mindmapDiagram.mjs +45 -69
  40. package/dist-esm/mindmapDiagram.mjs.map +2 -2
  41. package/dist-esm/renderBlueprint.mjs +122 -172
  42. package/dist-esm/renderBlueprint.mjs.map +2 -2
  43. package/dist-esm/sequenceDiagram.mjs +349 -233
  44. package/dist-esm/sequenceDiagram.mjs.map +3 -3
  45. package/dist-esm/stateDiagram.mjs +93 -162
  46. package/dist-esm/stateDiagram.mjs.map +3 -3
  47. package/dist-esm/svgParsing.mjs +125 -30
  48. package/dist-esm/svgParsing.mjs.map +2 -2
  49. package/dist-esm/utils.mjs +23 -7
  50. package/dist-esm/utils.mjs.map +2 -2
  51. package/package.json +6 -5
  52. package/src/blueprint.ts +10 -0
  53. package/src/colors.ts +181 -19
  54. package/src/createMermaidDiagram.test.ts +56 -18
  55. package/src/createMermaidDiagram.ts +16 -7
  56. package/src/defaultMermaidNodeRenderSpec.ts +14 -40
  57. package/src/flowchartDiagram.ts +90 -83
  58. package/src/mermaidDiagrams.test.ts +796 -115
  59. package/src/mermaidNodeCreateShape.ts +50 -27
  60. package/src/mindmapDiagram.ts +49 -90
  61. package/src/renderBlueprint.test.ts +101 -0
  62. package/src/renderBlueprint.ts +148 -191
  63. package/src/sequenceDiagram.ts +511 -268
  64. package/src/stateDiagram.ts +118 -201
  65. package/src/svgParsing.test.ts +303 -13
  66. package/src/svgParsing.ts +205 -57
  67. package/src/utils.ts +40 -10
  68. package/src/layoutParsing.test.ts +0 -71
package/README.md CHANGED
@@ -57,12 +57,12 @@ When `centerOnPosition` is `true` (the default), the diagram's center aligns wit
57
57
 
58
58
  ## Supported diagram types
59
59
 
60
- | Diagram type | Mermaid keyword | What you get |
61
- | ---------------- | -------------------- | ------------------------------------------------------------------- |
62
- | Flowchart | `flowchart`, `graph` | Geo shapes, arrows, subgraph frames |
63
- | Sequence diagram | `sequenceDiagram` | Actor shapes, lifelines, signal arrows, fragment frames |
64
- | State diagram | `stateDiagram-v2` | State shapes, transitions, compound state frames, fork/join, choice |
65
- | Mindmap | `mindmap` | Colored geo shapes, parent-child edges, tree hierarchy |
60
+ | Diagram type | Mermaid keyword | What you get |
61
+ | ---------------- | -------------------- | -------------------------------------------------------------------------- |
62
+ | Flowchart | `flowchart`, `graph` | Geo shapes, arrows, subgraph frames |
63
+ | Sequence diagram | `sequenceDiagram` | Actor shapes, lifelines, signal arrows, fragment frames, participant boxes |
64
+ | State diagram | `stateDiagram-v2` | State shapes, transitions, compound state frames, fork/join, choice |
65
+ | Mindmap | `mindmap` | Colored geo shapes, parent-child edges, tree hierarchy |
66
66
 
67
67
  Unsupported diagram types (pie, gantt, class, ER, etc.) can be handled with the `onUnsupportedDiagram` callback — for example, to fall back to SVG import:
68
68
 
@@ -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}\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\tanchorStartY?: 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'\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"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -21,31 +21,33 @@ __export(colors_exports, {
21
21
  buildClassDefColorMap: () => buildClassDefColorMap,
22
22
  parseCssStyles: () => parseCssStyles,
23
23
  parseNodeInlineColor: () => parseNodeInlineColor,
24
- parseRgbToTldrawColor: () => parseRgbToTldrawColor
24
+ parseRgbToTldrawColor: () => parseRgbToTldrawColor,
25
+ toNodeColorProps: () => toNodeColorProps
25
26
  });
26
27
  module.exports = __toCommonJS(colors_exports);
28
+ var import_utils = require("@tldraw/utils");
27
29
  var import_tldraw = require("tldraw");
28
30
  function buildClassDefColorMap(classDefs, items) {
29
31
  const result = /* @__PURE__ */ new Map();
30
32
  if (classDefs.size === 0) return result;
31
33
  for (const [nodeId, item] of items) {
32
- if (!item.classes || item.classes.length === 0) continue;
33
- for (const className of item.classes) {
34
- const classDef = classDefs.get(className);
35
- if (!classDef || classDef.styles.length === 0) continue;
36
- const props = parseCssProps(classDef.styles);
37
- const fill = toColor(props.get("fill"));
38
- const stroke = toColor(props.get("stroke"));
39
- if (!fill && !stroke) continue;
40
- const colors = {};
41
- if (fill) colors.fillColor = nearestTldrawColor(fill);
42
- if (stroke) colors.strokeColor = nearestTldrawColor(stroke);
43
- result.set(nodeId, colors);
44
- break;
34
+ for (const className of item.classes ?? []) {
35
+ const colors = parseNodeInlineColor(classDefs.get(className)?.styles);
36
+ if (colors) {
37
+ result.set(nodeId, colors);
38
+ break;
39
+ }
45
40
  }
46
41
  }
47
42
  return result;
48
43
  }
44
+ function toNodeColorProps(colors) {
45
+ if (!colors) return {};
46
+ return {
47
+ ...colors.fillColor && { fill: "solid" },
48
+ color: colors.strokeColor ?? colors.fillColor
49
+ };
50
+ }
49
51
  function parseRgbToTldrawColor(text) {
50
52
  const color = toColor(text);
51
53
  if (!color) return null;
@@ -79,8 +81,8 @@ function parseCssStyles(styles) {
79
81
  if (strokeWidth) {
80
82
  const pixels = parseFloat(strokeWidth);
81
83
  if (Number.isFinite(pixels)) {
82
- if (pixels <= 1) result.sizeOverride = "s";
83
- else if (pixels <= 2) result.sizeOverride = "m";
84
+ if (pixels < 1) result.sizeOverride = "s";
85
+ else if (pixels < 2) result.sizeOverride = "m";
84
86
  else result.sizeOverride = "l";
85
87
  }
86
88
  }
@@ -183,6 +185,161 @@ function toColor(value) {
183
185
  if (!rgb) return void 0;
184
186
  return [rgb[0], rgb[1], rgb[2], 255];
185
187
  }
188
+ const keyword = trimmed.toLowerCase();
189
+ if ((0, import_utils.hasOwnProperty)(CSS_NAMED_COLORS, keyword)) {
190
+ const rgb = parseHexToRgb(CSS_NAMED_COLORS[keyword]);
191
+ return [rgb[0], rgb[1], rgb[2], 255];
192
+ }
186
193
  return void 0;
187
194
  }
195
+ const CSS_NAMED_COLORS = {
196
+ aliceblue: "f0f8ff",
197
+ antiquewhite: "faebd7",
198
+ aqua: "00ffff",
199
+ aquamarine: "7fffd4",
200
+ azure: "f0ffff",
201
+ beige: "f5f5dc",
202
+ bisque: "ffe4c4",
203
+ black: "000000",
204
+ blanchedalmond: "ffebcd",
205
+ blue: "0000ff",
206
+ blueviolet: "8a2be2",
207
+ brown: "a52a2a",
208
+ burlywood: "deb887",
209
+ cadetblue: "5f9ea0",
210
+ chartreuse: "7fff00",
211
+ chocolate: "d2691e",
212
+ coral: "ff7f50",
213
+ cornflowerblue: "6495ed",
214
+ cornsilk: "fff8dc",
215
+ crimson: "dc143c",
216
+ cyan: "00ffff",
217
+ darkblue: "00008b",
218
+ darkcyan: "008b8b",
219
+ darkgoldenrod: "b8860b",
220
+ darkgray: "a9a9a9",
221
+ darkgreen: "006400",
222
+ darkgrey: "a9a9a9",
223
+ darkkhaki: "bdb76b",
224
+ darkmagenta: "8b008b",
225
+ darkolivegreen: "556b2f",
226
+ darkorange: "ff8c00",
227
+ darkorchid: "9932cc",
228
+ darkred: "8b0000",
229
+ darksalmon: "e9967a",
230
+ darkseagreen: "8fbc8f",
231
+ darkslateblue: "483d8b",
232
+ darkslategray: "2f4f4f",
233
+ darkslategrey: "2f4f4f",
234
+ darkturquoise: "00ced1",
235
+ darkviolet: "9400d3",
236
+ deeppink: "ff1493",
237
+ deepskyblue: "00bfff",
238
+ dimgray: "696969",
239
+ dimgrey: "696969",
240
+ dodgerblue: "1e90ff",
241
+ firebrick: "b22222",
242
+ floralwhite: "fffaf0",
243
+ forestgreen: "228b22",
244
+ fuchsia: "ff00ff",
245
+ gainsboro: "dcdcdc",
246
+ ghostwhite: "f8f8ff",
247
+ gold: "ffd700",
248
+ goldenrod: "daa520",
249
+ gray: "808080",
250
+ green: "008000",
251
+ greenyellow: "adff2f",
252
+ grey: "808080",
253
+ honeydew: "f0fff0",
254
+ hotpink: "ff69b4",
255
+ indianred: "cd5c5c",
256
+ indigo: "4b0082",
257
+ ivory: "fffff0",
258
+ khaki: "f0e68c",
259
+ lavender: "e6e6fa",
260
+ lavenderblush: "fff0f5",
261
+ lawngreen: "7cfc00",
262
+ lemonchiffon: "fffacd",
263
+ lightblue: "add8e6",
264
+ lightcoral: "f08080",
265
+ lightcyan: "e0ffff",
266
+ lightgoldenrodyellow: "fafad2",
267
+ lightgray: "d3d3d3",
268
+ lightgreen: "90ee90",
269
+ lightgrey: "d3d3d3",
270
+ lightpink: "ffb6c1",
271
+ lightsalmon: "ffa07a",
272
+ lightseagreen: "20b2aa",
273
+ lightskyblue: "87cefa",
274
+ lightslategray: "778899",
275
+ lightslategrey: "778899",
276
+ lightsteelblue: "b0c4de",
277
+ lightyellow: "ffffe0",
278
+ lime: "00ff00",
279
+ limegreen: "32cd32",
280
+ linen: "faf0e6",
281
+ magenta: "ff00ff",
282
+ maroon: "800000",
283
+ mediumaquamarine: "66cdaa",
284
+ mediumblue: "0000cd",
285
+ mediumorchid: "ba55d3",
286
+ mediumpurple: "9370db",
287
+ mediumseagreen: "3cb371",
288
+ mediumslateblue: "7b68ee",
289
+ mediumspringgreen: "00fa9a",
290
+ mediumturquoise: "48d1cc",
291
+ mediumvioletred: "c71585",
292
+ midnightblue: "191970",
293
+ mintcream: "f5fffa",
294
+ mistyrose: "ffe4e1",
295
+ moccasin: "ffe4b5",
296
+ navajowhite: "ffdead",
297
+ navy: "000080",
298
+ oldlace: "fdf5e6",
299
+ olive: "808000",
300
+ olivedrab: "6b8e23",
301
+ orange: "ffa500",
302
+ orangered: "ff4500",
303
+ orchid: "da70d6",
304
+ palegoldenrod: "eee8aa",
305
+ palegreen: "98fb98",
306
+ paleturquoise: "afeeee",
307
+ palevioletred: "db7093",
308
+ papayawhip: "ffefd5",
309
+ peachpuff: "ffdab9",
310
+ peru: "cd853f",
311
+ pink: "ffc0cb",
312
+ plum: "dda0dd",
313
+ powderblue: "b0e0e6",
314
+ purple: "800080",
315
+ rebeccapurple: "663399",
316
+ red: "ff0000",
317
+ rosybrown: "bc8f8f",
318
+ royalblue: "4169e1",
319
+ saddlebrown: "8b4513",
320
+ salmon: "fa8072",
321
+ sandybrown: "f4a460",
322
+ seagreen: "2e8b57",
323
+ seashell: "fff5ee",
324
+ sienna: "a0522d",
325
+ silver: "c0c0c0",
326
+ skyblue: "87ceeb",
327
+ slateblue: "6a5acd",
328
+ slategray: "708090",
329
+ slategrey: "708090",
330
+ snow: "fffafa",
331
+ springgreen: "00ff7f",
332
+ steelblue: "4682b4",
333
+ tan: "d2b48c",
334
+ teal: "008080",
335
+ thistle: "d8bfd8",
336
+ tomato: "ff6347",
337
+ turquoise: "40e0d0",
338
+ violet: "ee82ee",
339
+ wheat: "f5deb3",
340
+ white: "ffffff",
341
+ whitesmoke: "f5f5f5",
342
+ yellow: "ffff00",
343
+ yellowgreen: "9acd32"
344
+ };
188
345
  //# sourceMappingURL=colors.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/colors.ts"],
4
- "sourcesContent": ["import { DEFAULT_THEME, TLDefaultColorStyle, TLDefaultDashStyle, TLDefaultSizeStyle } from 'tldraw'\n\ntype Color = [number, number, number, number]\n\nexport interface ParsedNodeColors {\n\tfillColor?: TLDefaultColorStyle\n\tstrokeColor?: TLDefaultColorStyle\n}\n\n/**\n * Build a map of node id \u2192 parsed fill/stroke colors from Mermaid's classDef definitions.\n *\n * Uses the structured data from `db.getClasses()` and each node's `classes`\n * array. For each node, looks up its applied classDef styles and maps fill and\n * stroke independently to the nearest tldraw palette color.\n */\nexport function buildClassDefColorMap(\n\tclassDefs: Map<string, { styles: string[] }>,\n\titems: Iterable<[string, { classes?: string[] }]>\n): Map<string, ParsedNodeColors> {\n\tconst result = new Map<string, ParsedNodeColors>()\n\tif (classDefs.size === 0) return result\n\n\tfor (const [nodeId, item] of items) {\n\t\tif (!item.classes || item.classes.length === 0) continue\n\n\t\tfor (const className of item.classes) {\n\t\t\tconst classDef = classDefs.get(className)\n\t\t\tif (!classDef || classDef.styles.length === 0) continue\n\n\t\t\tconst props = parseCssProps(classDef.styles)\n\t\t\tconst fill = toColor(props.get('fill'))\n\t\t\tconst stroke = toColor(props.get('stroke'))\n\n\t\t\tif (!fill && !stroke) continue\n\n\t\t\tconst colors: ParsedNodeColors = {}\n\t\t\tif (fill) colors.fillColor = nearestTldrawColor(fill)\n\t\t\tif (stroke) colors.strokeColor = nearestTldrawColor(stroke)\n\t\t\tresult.set(nodeId, colors)\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn result\n}\n\nexport function parseRgbToTldrawColor(\n\ttext: string\n): { color: TLDefaultColorStyle; hasAlpha: boolean } | null {\n\tconst color = toColor(text)\n\tif (!color) return null\n\treturn { color: nearestTldrawColor(color), hasAlpha: color[3] < 255 }\n}\n\ninterface ParsedCssOverrides {\n\tcolor?: TLDefaultColorStyle\n\tdashOverride?: TLDefaultDashStyle\n\tsizeOverride?: TLDefaultSizeStyle\n}\n\nfunction parseCssProps(styles: string[]): Map<string, string> {\n\tconst props = new Map<string, string>()\n\tfor (const entry of styles) {\n\t\tfor (const part of entry.split(';')) {\n\t\t\tconst colon = part.indexOf(':')\n\t\t\tif (colon < 0) continue\n\t\t\tconst key = part.slice(0, colon).trim().toLowerCase()\n\t\t\tconst value = part.slice(colon + 1).trim()\n\t\t\tif (key && value) props.set(key, value)\n\t\t}\n\t}\n\treturn props\n}\n\n/**\n * Parse a Mermaid CSS style array from an edge (FlowEdge.style / linkStyle)\n * and return tldraw-compatible overrides.\n */\nexport function parseCssStyles(styles: string[] | undefined): ParsedCssOverrides {\n\tif (!styles || styles.length === 0) return {}\n\n\tconst props = parseCssProps(styles)\n\tconst result: ParsedCssOverrides = {}\n\n\tconst stroke = toColor(props.get('stroke'))\n\tif (stroke) {\n\t\tresult.color = nearestTldrawColor(stroke)\n\t}\n\n\tif (props.has('stroke-dasharray')) {\n\t\tresult.dashOverride = 'dashed'\n\t}\n\n\tconst strokeWidth = props.get('stroke-width')\n\tif (strokeWidth) {\n\t\tconst pixels = parseFloat(strokeWidth)\n\t\tif (Number.isFinite(pixels)) {\n\t\t\tif (pixels <= 1) result.sizeOverride = 's'\n\t\t\telse if (pixels <= 2) result.sizeOverride = 'm'\n\t\t\telse result.sizeOverride = 'l'\n\t\t}\n\t}\n\n\treturn result\n}\n\n/**\n * Parse inline `style nodeId fill:\u2026,stroke:\u2026` directives from a FlowVertex.styles\n * array and return fill and stroke as independent tldraw colors.\n */\nexport function parseNodeInlineColor(styles: string[] | undefined): ParsedNodeColors | undefined {\n\tif (!styles || styles.length === 0) return undefined\n\n\tconst props = parseCssProps(styles)\n\tconst fill = toColor(props.get('fill'))\n\tconst stroke = toColor(props.get('stroke'))\n\n\tif (!fill && !stroke) return undefined\n\n\tconst colors: ParsedNodeColors = {}\n\tif (fill) colors.fillColor = nearestTldrawColor(fill)\n\tif (stroke) colors.strokeColor = nearestTldrawColor(stroke)\n\treturn colors\n}\n\nfunction parseHexToRgb(hex: string): [number, number, number] | null {\n\tconst stripped = hex.replace(/^#/, '')\n\tif (stripped.length === 3 || stripped.length === 4) {\n\t\treturn [\n\t\t\tparseInt(stripped[0] + stripped[0], 16),\n\t\t\tparseInt(stripped[1] + stripped[1], 16),\n\t\t\tparseInt(stripped[2] + stripped[2], 16),\n\t\t]\n\t}\n\tif (stripped.length === 6 || stripped.length === 8) {\n\t\treturn [\n\t\t\tparseInt(stripped.slice(0, 2), 16),\n\t\t\tparseInt(stripped.slice(2, 4), 16),\n\t\t\tparseInt(stripped.slice(4, 6), 16),\n\t\t]\n\t}\n\treturn null\n}\n\nconst defaultColorNames: TLDefaultColorStyle[] = [\n\t'black',\n\t'grey',\n\t'light-violet',\n\t'violet',\n\t'blue',\n\t'light-blue',\n\t'yellow',\n\t'orange',\n\t'green',\n\t'light-green',\n\t'light-red',\n\t'red',\n\t'white',\n]\n\nconst TLDRAW_PALETTE: [TLDefaultColorStyle, number, number, number][] = defaultColorNames.map(\n\t(name) => {\n\t\tconst { solid } = DEFAULT_THEME.colors.light[name]!\n\t\tconst rgb = parseHexToRgb(solid)!\n\t\treturn [name, rgb[0], rgb[1], rgb[2]]\n\t}\n)\n\n/** Map an arbitrary Color tuple to the nearest tldraw named color (best-effort). */\nfunction nearestTldrawColor(rgb: Color): TLDefaultColorStyle {\n\tlet [r, g, b] = rgb\n\n\tconst max = Math.max(r, g, b)\n\tconst min = Math.min(r, g, b)\n\tconst lightness = (max + min) / 2 / 255\n\tconst chroma = max - min\n\n\t// For very light pastels, strip the white base and amplify the\n\t// chromatic signal so the distance metric can see the hue.\n\tif (lightness > 0.75 && chroma > 5) {\n\t\tconst target = 200\n\t\tr = Math.round(((r - min) / chroma) * target)\n\t\tg = Math.round(((g - min) / chroma) * target)\n\t\tb = Math.round(((b - min) / chroma) * target)\n\t}\n\n\tlet best: TLDefaultColorStyle = 'black'\n\tlet bestDistance = Infinity\n\tfor (const [name, red, green, blue] of TLDRAW_PALETTE) {\n\t\t// \"Redmean\" weighted Euclidean distance (Compuphase approximation).\n\t\t// Weights RGB channels by the average red value of the two colors to\n\t\t// approximate human perception, which is more sensitive to green and\n\t\t// varies in red/blue sensitivity depending on the color's warmth.\n\t\tconst rMean = (r + red) / 2\n\t\tconst dR = r - red\n\t\tconst dG = g - green\n\t\tconst dB = b - blue\n\t\tconst distance = (2 + rMean / 256) * dR * dR + 4 * dG * dG + (2 + (255 - rMean) / 256) * dB * dB\n\t\tif (distance < bestDistance) {\n\t\t\tbestDistance = distance\n\t\t\tbest = name\n\t\t}\n\t}\n\treturn best\n}\n\nfunction toColor(value: string | undefined): Color | undefined {\n\tif (!value) return undefined\n\n\tconst trimmed = value.trim()\n\tif (!trimmed || trimmed === 'none' || trimmed === 'transparent') return undefined\n\n\tif (trimmed.startsWith('rgb')) {\n\t\tconst match = trimmed.match(/rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*([\\d.]+)\\s*)?\\)/)\n\t\tif (!match) return undefined\n\t\treturn [\n\t\t\tparseInt(match[1], 10),\n\t\t\tparseInt(match[2], 10),\n\t\t\tparseInt(match[3], 10),\n\t\t\tmatch[4] !== undefined ? Math.round(parseFloat(match[4]) * 255) : 255,\n\t\t]\n\t}\n\tif (trimmed.startsWith('#')) {\n\t\tconst rgb = parseHexToRgb(trimmed)\n\t\tif (!rgb) return undefined\n\t\treturn [rgb[0], rgb[1], rgb[2], 255]\n\t}\n\treturn undefined\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2F;AAgBpF,SAAS,sBACf,WACA,OACgC;AAChC,QAAM,SAAS,oBAAI,IAA8B;AACjD,MAAI,UAAU,SAAS,EAAG,QAAO;AAEjC,aAAW,CAAC,QAAQ,IAAI,KAAK,OAAO;AACnC,QAAI,CAAC,KAAK,WAAW,KAAK,QAAQ,WAAW,EAAG;AAEhD,eAAW,aAAa,KAAK,SAAS;AACrC,YAAM,WAAW,UAAU,IAAI,SAAS;AACxC,UAAI,CAAC,YAAY,SAAS,OAAO,WAAW,EAAG;AAE/C,YAAM,QAAQ,cAAc,SAAS,MAAM;AAC3C,YAAM,OAAO,QAAQ,MAAM,IAAI,MAAM,CAAC;AACtC,YAAM,SAAS,QAAQ,MAAM,IAAI,QAAQ,CAAC;AAE1C,UAAI,CAAC,QAAQ,CAAC,OAAQ;AAEtB,YAAM,SAA2B,CAAC;AAClC,UAAI,KAAM,QAAO,YAAY,mBAAmB,IAAI;AACpD,UAAI,OAAQ,QAAO,cAAc,mBAAmB,MAAM;AAC1D,aAAO,IAAI,Q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MACN,SAAS,MAAM,CAAC,GAAG,EAAE;AAAA,MACrB,SAAS,MAAM,CAAC,GAAG,EAAE;AAAA,MACrB,SAAS,MAAM,CAAC,GAAG,EAAE;AAAA,MACrB,MAAM,CAAC,MAAM,SAAY,KAAK,MAAM,WAAW,MAAM,CAAC,CAAC,IAAI,GAAG,IAAI;AAAA,IACnE;AAAA,EACD;AACA,MAAI,QAAQ,WAAW,GAAG,GAAG;AAC5B,UAAM,MAAM,cAAc,OAAO;AACjC,QAAI,CAAC,IAAK,QAAO;AACjB,WAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG;AAAA,EACpC;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["import { hasOwnProperty } from '@tldraw/utils'\nimport { DEFAULT_THEME, TLDefaultColorStyle, TLDefaultDashStyle, TLDefaultSizeStyle } from 'tldraw'\nimport type { MermaidBlueprintNode } from './blueprint'\n\ntype Color = [number, number, number, number]\n\nexport interface ParsedNodeColors {\n\tfillColor?: TLDefaultColorStyle\n\tstrokeColor?: TLDefaultColorStyle\n}\n\n/**\n * Build a map of node id \u2192 parsed fill/stroke colors from Mermaid's classDef definitions.\n *\n * Uses the structured data from `db.getClasses()` and each node's `classes`\n * array. For each node, looks up its applied classDef styles and maps fill and\n * stroke independently to the nearest tldraw palette color.\n */\nexport function buildClassDefColorMap(\n\tclassDefs: Map<string, { styles: string[] }>,\n\titems: Iterable<[string, { classes?: string[] }]>\n): Map<string, ParsedNodeColors> {\n\tconst result = new Map<string, ParsedNodeColors>()\n\tif (classDefs.size === 0) return result\n\n\tfor (const [nodeId, item] of items) {\n\t\tfor (const className of item.classes ?? []) {\n\t\t\tconst colors = parseNodeInlineColor(classDefs.get(className)?.styles)\n\t\t\tif (colors) {\n\t\t\t\tresult.set(nodeId, colors)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result\n}\n\n/** Blueprint node style props for parsed fill/stroke colors: solid fill when a fill was set, stroke color preferred. */\nexport function toNodeColorProps(\n\tcolors: ParsedNodeColors | undefined\n): Pick<MermaidBlueprintNode, 'fill' | 'color'> {\n\tif (!colors) return {}\n\treturn {\n\t\t...(colors.fillColor && { fill: 'solid' as const }),\n\t\tcolor: colors.strokeColor ?? colors.fillColor,\n\t}\n}\n\nexport function parseRgbToTldrawColor(\n\ttext: string\n): { color: TLDefaultColorStyle; hasAlpha: boolean } | null {\n\tconst color = toColor(text)\n\tif (!color) return null\n\treturn { color: nearestTldrawColor(color), hasAlpha: color[3] < 255 }\n}\n\ninterface ParsedCssOverrides {\n\tcolor?: TLDefaultColorStyle\n\tdashOverride?: TLDefaultDashStyle\n\tsizeOverride?: TLDefaultSizeStyle\n}\n\nfunction parseCssProps(styles: string[]): Map<string, string> {\n\tconst props = new Map<string, string>()\n\tfor (const entry of styles) {\n\t\tfor (const part of entry.split(';')) {\n\t\t\tconst colon = part.indexOf(':')\n\t\t\tif (colon < 0) continue\n\t\t\tconst key = part.slice(0, colon).trim().toLowerCase()\n\t\t\tconst value = part.slice(colon + 1).trim()\n\t\t\tif (key && value) props.set(key, value)\n\t\t}\n\t}\n\treturn props\n}\n\n/**\n * Parse a Mermaid CSS style array from an edge (FlowEdge.style / linkStyle)\n * and return tldraw-compatible overrides.\n */\nexport function parseCssStyles(styles: string[] | undefined): ParsedCssOverrides {\n\tif (!styles || styles.length === 0) return {}\n\n\tconst props = parseCssProps(styles)\n\tconst result: ParsedCssOverrides = {}\n\n\tconst stroke = toColor(props.get('stroke'))\n\tif (stroke) {\n\t\tresult.color = nearestTldrawColor(stroke)\n\t}\n\n\tif (props.has('stroke-dasharray')) {\n\t\tresult.dashOverride = 'dashed'\n\t}\n\n\tconst strokeWidth = props.get('stroke-width')\n\tif (strokeWidth) {\n\t\tconst pixels = parseFloat(strokeWidth)\n\t\tif (Number.isFinite(pixels)) {\n\t\t\t// Mermaid's unstyled edge is 1px, drawn at 'm'. A lower cut-off would draw\n\t\t\t// `stroke-width:1px` thinner than no style at all.\n\t\t\tif (pixels < 1) result.sizeOverride = 's'\n\t\t\telse if (pixels < 2) result.sizeOverride = 'm'\n\t\t\telse result.sizeOverride = 'l'\n\t\t}\n\t}\n\n\treturn result\n}\n\n/**\n * Parse inline `style nodeId fill:\u2026,stroke:\u2026` directives from a FlowVertex.styles\n * array and return fill and stroke as independent tldraw colors.\n */\nexport function parseNodeInlineColor(styles: string[] | undefined): ParsedNodeColors | undefined {\n\tif (!styles || styles.length === 0) return undefined\n\n\tconst props = parseCssProps(styles)\n\tconst fill = toColor(props.get('fill'))\n\tconst stroke = toColor(props.get('stroke'))\n\n\tif (!fill && !stroke) return undefined\n\n\tconst colors: ParsedNodeColors = {}\n\tif (fill) colors.fillColor = nearestTldrawColor(fill)\n\tif (stroke) colors.strokeColor = nearestTldrawColor(stroke)\n\treturn colors\n}\n\nfunction parseHexToRgb(hex: string): [number, number, number] | null {\n\tconst stripped = hex.replace(/^#/, '')\n\tif (stripped.length === 3 || stripped.length === 4) {\n\t\treturn [\n\t\t\tparseInt(stripped[0] + stripped[0], 16),\n\t\t\tparseInt(stripped[1] + stripped[1], 16),\n\t\t\tparseInt(stripped[2] + stripped[2], 16),\n\t\t]\n\t}\n\tif (stripped.length === 6 || stripped.length === 8) {\n\t\treturn [\n\t\t\tparseInt(stripped.slice(0, 2), 16),\n\t\t\tparseInt(stripped.slice(2, 4), 16),\n\t\t\tparseInt(stripped.slice(4, 6), 16),\n\t\t]\n\t}\n\treturn null\n}\n\nconst defaultColorNames: TLDefaultColorStyle[] = [\n\t'black',\n\t'grey',\n\t'light-violet',\n\t'violet',\n\t'blue',\n\t'light-blue',\n\t'yellow',\n\t'orange',\n\t'green',\n\t'light-green',\n\t'light-red',\n\t'red',\n\t'white',\n]\n\nconst TLDRAW_PALETTE: [TLDefaultColorStyle, number, number, number][] = defaultColorNames.map(\n\t(name) => {\n\t\tconst { solid } = DEFAULT_THEME.colors.light[name]!\n\t\tconst rgb = parseHexToRgb(solid)!\n\t\treturn [name, rgb[0], rgb[1], rgb[2]]\n\t}\n)\n\n/** Map an arbitrary Color tuple to the nearest tldraw named color (best-effort). */\nfunction nearestTldrawColor(rgb: Color): TLDefaultColorStyle {\n\tlet [r, g, b] = rgb\n\n\tconst max = Math.max(r, g, b)\n\tconst min = Math.min(r, g, b)\n\tconst lightness = (max + min) / 2 / 255\n\tconst chroma = max - min\n\n\t// For very light pastels, strip the white base and amplify the\n\t// chromatic signal so the distance metric can see the hue.\n\tif (lightness > 0.75 && chroma > 5) {\n\t\tconst target = 200\n\t\tr = Math.round(((r - min) / chroma) * target)\n\t\tg = Math.round(((g - min) / chroma) * target)\n\t\tb = Math.round(((b - min) / chroma) * target)\n\t}\n\n\tlet best: TLDefaultColorStyle = 'black'\n\tlet bestDistance = Infinity\n\tfor (const [name, red, green, blue] of TLDRAW_PALETTE) {\n\t\t// \"Redmean\" weighted Euclidean distance (Compuphase approximation).\n\t\t// Weights RGB channels by the average red value of the two colors to\n\t\t// approximate human perception, which is more sensitive to green and\n\t\t// varies in red/blue sensitivity depending on the color's warmth.\n\t\tconst rMean = (r + red) / 2\n\t\tconst dR = r - red\n\t\tconst dG = g - green\n\t\tconst dB = b - blue\n\t\tconst distance = (2 + rMean / 256) * dR * dR + 4 * dG * dG + (2 + (255 - rMean) / 256) * dB * dB\n\t\tif (distance < bestDistance) {\n\t\t\tbestDistance = distance\n\t\t\tbest = name\n\t\t}\n\t}\n\treturn best\n}\n\nfunction toColor(value: string | undefined): Color | undefined {\n\tif (!value) return undefined\n\n\tconst trimmed = value.trim()\n\tif (!trimmed || trimmed === 'none' || trimmed === 'transparent') return undefined\n\n\tif (trimmed.startsWith('rgb')) {\n\t\tconst match = trimmed.match(/rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*([\\d.]+)\\s*)?\\)/)\n\t\tif (!match) return undefined\n\t\treturn [\n\t\t\tparseInt(match[1], 10),\n\t\t\tparseInt(match[2], 10),\n\t\t\tparseInt(match[3], 10),\n\t\t\tmatch[4] !== undefined ? Math.round(parseFloat(match[4]) * 255) : 255,\n\t\t]\n\t}\n\tif (trimmed.startsWith('#')) {\n\t\tconst rgb = parseHexToRgb(trimmed)\n\t\tif (!rgb) return undefined\n\t\treturn [rgb[0], rgb[1], rgb[2], 255]\n\t}\n\tconst keyword = trimmed.toLowerCase()\n\tif (hasOwnProperty(CSS_NAMED_COLORS, keyword)) {\n\t\tconst rgb = parseHexToRgb(CSS_NAMED_COLORS[keyword])!\n\t\treturn [rgb[0], rgb[1], rgb[2], 255]\n\t}\n\treturn undefined\n}\n\n// Mermaid accepts CSS color keywords wherever it takes a color, and sequence `box` statements\n// can't take a hex color at all, so without these a box's color is usually lost.\nconst CSS_NAMED_COLORS: Record<string, string> = {\n\taliceblue: 'f0f8ff',\n\tantiquewhite: 'faebd7',\n\taqua: '00ffff',\n\taquamarine: '7fffd4',\n\tazure: 'f0ffff',\n\tbeige: 'f5f5dc',\n\tbisque: 'ffe4c4',\n\tblack: '000000',\n\tblanchedalmond: 'ffebcd',\n\tblue: '0000ff',\n\tblueviolet: '8a2be2',\n\tbrown: 'a52a2a',\n\tburlywood: 'deb887',\n\tcadetblue: '5f9ea0',\n\tchartreuse: '7fff00',\n\tchocolate: 'd2691e',\n\tcoral: 'ff7f50',\n\tcornflowerblue: '6495ed',\n\tcornsilk: 'fff8dc',\n\tcrimson: 'dc143c',\n\tcyan: '00ffff',\n\tdarkblue: '00008b',\n\tdarkcyan: '008b8b',\n\tdarkgoldenrod: 'b8860b',\n\tdarkgray: 'a9a9a9',\n\tdarkgreen: '006400',\n\tdarkgrey: 'a9a9a9',\n\tdarkkhaki: 'bdb76b',\n\tdarkmagenta: '8b008b',\n\tdarkolivegreen: '556b2f',\n\tdarkorange: 'ff8c00',\n\tdarkorchid: '9932cc',\n\tdarkred: '8b0000',\n\tdarksalmon: 'e9967a',\n\tdarkseagreen: '8fbc8f',\n\tdarkslateblue: '483d8b',\n\tdarkslategray: '2f4f4f',\n\tdarkslategrey: '2f4f4f',\n\tdarkturquoise: '00ced1',\n\tdarkviolet: '9400d3',\n\tdeeppink: 'ff1493',\n\tdeepskyblue: '00bfff',\n\tdimgray: '696969',\n\tdimgrey: '696969',\n\tdodgerblue: '1e90ff',\n\tfirebrick: 'b22222',\n\tfloralwhite: 'fffaf0',\n\tforestgreen: '228b22',\n\tfuchsia: 'ff00ff',\n\tgainsboro: 'dcdcdc',\n\tghostwhite: 'f8f8ff',\n\tgold: 'ffd700',\n\tgoldenrod: 'daa520',\n\tgray: '808080',\n\tgreen: '008000',\n\tgreenyellow: 'adff2f',\n\tgrey: '808080',\n\thoneydew: 'f0fff0',\n\thotpink: 'ff69b4',\n\tindianred: 'cd5c5c',\n\tindigo: '4b0082',\n\tivory: 'fffff0',\n\tkhaki: 'f0e68c',\n\tlavender: 'e6e6fa',\n\tlavenderblush: 'fff0f5',\n\tlawngreen: '7cfc00',\n\tlemonchiffon: 'fffacd',\n\tlightblue: 'add8e6',\n\tlightcoral: 'f08080',\n\tlightcyan: 'e0ffff',\n\tlightgoldenrodyellow: 'fafad2',\n\tlightgray: 'd3d3d3',\n\tlightgreen: '90ee90',\n\tlightgrey: 'd3d3d3',\n\tlightpink: 'ffb6c1',\n\tlightsalmon: 'ffa07a',\n\tlightseagreen: '20b2aa',\n\tlightskyblue: '87cefa',\n\tlightslategray: '778899',\n\tlightslategrey: '778899',\n\tlightsteelblue: 'b0c4de',\n\tlightyellow: 'ffffe0',\n\tlime: '00ff00',\n\tlimegreen: '32cd32',\n\tlinen: 'faf0e6',\n\tmagenta: 'ff00ff',\n\tmaroon: '800000',\n\tmediumaquamarine: '66cdaa',\n\tmediumblue: '0000cd',\n\tmediumorchid: 'ba55d3',\n\tmediumpurple: '9370db',\n\tmediumseagreen: '3cb371',\n\tmediumslateblue: '7b68ee',\n\tmediumspringgreen: '00fa9a',\n\tmediumturquoise: '48d1cc',\n\tmediumvioletred: 'c71585',\n\tmidnightblue: '191970',\n\tmintcream: 'f5fffa',\n\tmistyrose: 'ffe4e1',\n\tmoccasin: 'ffe4b5',\n\tnavajowhite: 'ffdead',\n\tnavy: '000080',\n\toldlace: 'fdf5e6',\n\tolive: '808000',\n\tolivedrab: '6b8e23',\n\torange: 'ffa500',\n\torangered: 'ff4500',\n\torchid: 'da70d6',\n\tpalegoldenrod: 'eee8aa',\n\tpalegreen: '98fb98',\n\tpaleturquoise: 'afeeee',\n\tpalevioletred: 'db7093',\n\tpapayawhip: 'ffefd5',\n\tpeachpuff: 'ffdab9',\n\tperu: 'cd853f',\n\tpink: 'ffc0cb',\n\tplum: 'dda0dd',\n\tpowderblue: 'b0e0e6',\n\tpurple: '800080',\n\trebeccapurple: '663399',\n\tred: 'ff0000',\n\trosybrown: 'bc8f8f',\n\troyalblue: '4169e1',\n\tsaddlebrown: '8b4513',\n\tsalmon: 'fa8072',\n\tsandybrown: 'f4a460',\n\tseagreen: '2e8b57',\n\tseashell: 'fff5ee',\n\tsienna: 'a0522d',\n\tsilver: 'c0c0c0',\n\tskyblue: '87ceeb',\n\tslateblue: '6a5acd',\n\tslategray: '708090',\n\tslategrey: '708090',\n\tsnow: 'fffafa',\n\tspringgreen: '00ff7f',\n\tsteelblue: '4682b4',\n\ttan: 'd2b48c',\n\tteal: '008080',\n\tthistle: 'd8bfd8',\n\ttomato: 'ff6347',\n\tturquoise: '40e0d0',\n\tviolet: 'ee82ee',\n\twheat: 'f5deb3',\n\twhite: 'ffffff',\n\twhitesmoke: 'f5f5f5',\n\tyellow: 'ffff00',\n\tyellowgreen: '9acd32',\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,oBAA2F;AAiBpF,SAAS,sBACf,WACA,OACgC;AAChC,QAAM,SAAS,oBAAI,IAA8B;AACjD,MAAI,UAAU,SAAS,EAAG,QAAO;AAEjC,aAAW,CAAC,QAAQ,IAAI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ACX,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,aAAa;AAAA,EACb,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,WAAW;AAAA,EACX,eAAe;AAAA,EACf,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,KAAK;AAAA,EACL,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,MAAM;AAAA,EACN,aAAa;AAAA,EACb,WAAW;AAAA,EACX,KAAK;AAAA,EACL,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AACd;",
6
6
  "names": []
7
7
  }
@@ -33,6 +33,7 @@ __export(createMermaidDiagram_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(createMermaidDiagram_exports);
35
35
  var import_flowchartDiagram = require("./flowchartDiagram");
36
+ var import_mermaidNodeCreateShape = require("./mermaidNodeCreateShape");
36
37
  var import_mindmapDiagram = require("./mindmapDiagram");
37
38
  var import_renderBlueprint = require("./renderBlueprint");
38
39
  var import_sequenceDiagram = require("./sequenceDiagram");
@@ -66,17 +67,24 @@ async function createMermaidDiagram(editor, text, options = {}) {
66
67
  state: { ...MERMAID_CONFIG.state, ...options.mermaidConfig?.state },
67
68
  mindmap: { ...MERMAID_CONFIG.mindmap, ...options.mermaidConfig?.mindmap },
68
69
  sequence: { ...MERMAID_CONFIG.sequence, ...options.mermaidConfig?.sequence },
69
- themeVariables: { ...MERMAID_CONFIG.themeVariables, ...options.mermaidConfig?.themeVariables }
70
+ themeVariables: { ...MERMAID_CONFIG.themeVariables, ...options.mermaidConfig?.themeVariables },
71
+ // A diagram's own `%%{init}%%` or frontmatter config outranks `initialize`, so one that sets
72
+ // `fontSize` undoes FONT_INFLATE: every box is measured small while tldraw still draws its
73
+ // wider face, and labels break mid-word. Mermaid strips `secure` keys from in-diagram config
74
+ // at any depth, and keeps its own defaults alongside the ones listed here.
75
+ secure: [...options.mermaidConfig?.secure ?? [], "fontSize"]
70
76
  });
71
77
  const parsedResult = await mermaid.parse(text, { suppressErrors: true });
72
78
  if (!parsedResult) {
73
79
  throw new MermaidDiagramError("not a mermaid diagram", "parse");
74
80
  }
75
81
  const offscreen = document.createElement("div");
76
- offscreen.style.position = "absolute";
77
- offscreen.style.left = "-9999px";
78
- offscreen.style.top = "-9999px";
79
- offscreen.style.overflow = "hidden";
82
+ Object.assign(offscreen.style, {
83
+ position: "absolute",
84
+ left: "-9999px",
85
+ top: "-9999px",
86
+ overflow: "hidden"
87
+ });
80
88
  document.body.appendChild(offscreen);
81
89
  try {
82
90
  const parsedSvg = (await mermaid.render(`mermaid-${nextMermaidId++}`, text, offscreen)).svg;
@@ -113,7 +121,8 @@ async function createMermaidDiagram(editor, text, options = {}) {
113
121
  actorKeys,
114
122
  messages,
115
123
  db.getCreatedActors(),
116
- db.getDestroyedActors()
124
+ db.getDestroyedActors(),
125
+ (0, import_mermaidNodeCreateShape.createLabelWidthMeasurer)(editor)
117
126
  );
118
127
  break;
119
128
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/createMermaidDiagram.ts"],
4
- "sourcesContent": ["let nextMermaidId = 0\n\nimport type { FlowDB } from 'mermaid/dist/diagrams/flowchart/flowDb.d.ts'\nimport type { FlowEdge, FlowSubGraph, FlowVertex } from 'mermaid/dist/diagrams/flowchart/types.js'\nimport type { MindmapDB } from 'mermaid/dist/diagrams/mindmap/mindmapDb.d.ts'\nimport type { SequenceDB } from 'mermaid/dist/diagrams/sequence/sequenceDb.d.ts'\nimport type { StateDB } from 'mermaid/dist/diagrams/state/stateDb.d.ts'\nimport { Editor } from 'tldraw'\nimport { flowchartToBlueprint, parseFlowchartLayout } from './flowchartDiagram'\nimport { mindmapToBlueprint, parseMindmapLayout } from './mindmapDiagram'\nimport { BlueprintRenderingOptions, renderBlueprint } from './renderBlueprint'\nimport { countSequenceEvents, parseSequenceLayout, sequenceToBlueprint } from './sequenceDiagram'\nimport { parseStateDiagramLayout, stateToBlueprint } from './stateDiagram'\n\n/** @public */\nexport class MermaidDiagramError extends Error {\n\tconstructor(\n\t\tpublic diagramType: string,\n\t\tpublic type: 'parse' | 'unsupported'\n\t) {\n\t\tsuper(`mermaid diagram error: ${diagramType}`)\n\t\tthis.name = 'MermaidDiagramError'\n\t}\n}\n\n// Inflate the font size so Mermaid's layout engine allocates larger nodes,\n// compensating for tldraw's hand-drawn font being wider than Mermaid's default.\nconst FONT_INFLATE = 1.4\n\nconst MERMAID_CONFIG = {\n\tstartOnLoad: false,\n\tflowchart: { nodeSpacing: 80, rankSpacing: 80, padding: 20 },\n\tstate: { nodeSpacing: 80, rankSpacing: 80, padding: 20 },\n\tmindmap: { padding: 20 },\n\tsequence: { actorMargin: 50, noteMargin: 20 },\n\tthemeVariables: { fontSize: `${18 * FONT_INFLATE}px` },\n}\n\n/** @public */\nexport interface MermaidDiagramOptions {\n\tmermaidConfig?: Record<string, any>\n\tblueprintRender?: BlueprintRenderingOptions\n\tonUnsupportedDiagram?(svg: string): Promise<void>\n}\n\n/**\n * Parse mermaid text and create tldraw shapes for supported diagram types.\n * Returns the SVG string for supported diagrams, or `null` when the diagram type\n * is unsupported (after calling `onUnsupportedDiagram` if provided).\n * Throws {@link MermaidDiagramError} if parsing fails.\n * @public\n */\nexport async function createMermaidDiagram(\n\teditor: Editor,\n\ttext: string,\n\toptions: MermaidDiagramOptions = {}\n): Promise<void> {\n\t// load mermaid lazily: it's a large, ESM-only dependency only needed when a\n\t// diagram is actually created. a dynamic import() works from CommonJS (unlike\n\t// a static import, which compiles to require(<esm>) and throws\n\t// ERR_REQUIRE_ESM on Node <20.19, Jest, and ts-node) and avoids pulling\n\t// mermaid in when @tldraw/mermaid is merely imported.\n\tconst mermaid = (await import('mermaid')).default\n\n\tmermaid.initialize({\n\t\t...MERMAID_CONFIG,\n\t\t...(options.mermaidConfig ?? {}),\n\t\tflowchart: { ...MERMAID_CONFIG.flowchart, ...options.mermaidConfig?.flowchart },\n\t\tstate: { ...MERMAID_CONFIG.state, ...options.mermaidConfig?.state },\n\t\tmindmap: { ...MERMAID_CONFIG.mindmap, ...options.mermaidConfig?.mindmap },\n\t\tsequence: { ...MERMAID_CONFIG.sequence, ...options.mermaidConfig?.sequence },\n\t\tthemeVariables: { ...MERMAID_CONFIG.themeVariables, ...options.mermaidConfig?.themeVariables },\n\t})\n\n\tconst parsedResult = await mermaid.parse(text, { suppressErrors: true })\n\n\tif (!parsedResult) {\n\t\tthrow new MermaidDiagramError('not a mermaid diagram', 'parse')\n\t}\n\n\tconst offscreen = document.createElement('div')\n\toffscreen.style.position = 'absolute'\n\toffscreen.style.left = '-9999px'\n\toffscreen.style.top = '-9999px'\n\toffscreen.style.overflow = 'hidden'\n\tdocument.body.appendChild(offscreen)\n\n\ttry {\n\t\tconst parsedSvg = (await mermaid.render(`mermaid-${nextMermaidId++}`, text, offscreen)).svg\n\n\t\t// Reuse the live SVG that mermaid.render() already mounted into the\n\t\t// offscreen container. This avoids a second DOM mount and ensures\n\t\t// getBBox() works for every diagram type (state diagrams in particular\n\t\t// lack explicit dimension attributes and rely on live layout).\n\t\tlet liveSvg = offscreen.querySelector('svg')\n\n\t\tif (!liveSvg) {\n\t\t\toffscreen.innerHTML = parsedSvg\n\t\t\tliveSvg = offscreen.querySelector('svg')\n\t\t\tif (!liveSvg) {\n\t\t\t\tthrow new MermaidDiagramError(parsedResult.diagramType, 'parse')\n\t\t\t}\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\tconst diagramResult = await mermaid.mermaidAPI.getDiagramFromText(text)\n\n\t\tlet blueprint\n\t\tswitch (parsedResult.diagramType) {\n\t\t\tcase 'flowchart-v2': {\n\t\t\t\tconst db = diagramResult.db as FlowDB\n\t\t\t\tconst vertices = db.getVertices() as Map<string, FlowVertex>\n\t\t\t\tconst edges = db.getEdges() as FlowEdge[]\n\t\t\t\tconst subGraphs = db.getSubGraphs() as FlowSubGraph[]\n\t\t\t\tconst classes = db.getClasses()\n\t\t\t\tconst layout = parseFlowchartLayout(liveSvg)\n\t\t\t\tblueprint = flowchartToBlueprint(layout, vertices, edges, subGraphs, classes)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'sequence': {\n\t\t\t\tconst db = diagramResult.db as SequenceDB\n\t\t\t\tconst actors = db.getActors()\n\t\t\t\tconst actorKeys = db.getActorKeys()\n\t\t\t\tconst messages = db.getMessages()\n\t\t\t\tconst layout = parseSequenceLayout(liveSvg, actorKeys.length, countSequenceEvents(messages))\n\t\t\t\tblueprint = sequenceToBlueprint(\n\t\t\t\t\tlayout,\n\t\t\t\t\tactors,\n\t\t\t\t\tactorKeys,\n\t\t\t\t\tmessages,\n\t\t\t\t\tdb.getCreatedActors(),\n\t\t\t\t\tdb.getDestroyedActors()\n\t\t\t\t)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'state':\n\t\t\tcase 'stateDiagram': {\n\t\t\t\tconst db = diagramResult.db as StateDB\n\t\t\t\tconst states = db.getStates()\n\t\t\t\tconst relations = db.getRelations()\n\t\t\t\tconst classes = db.getClasses()\n\t\t\t\tconst layout = parseStateDiagramLayout(liveSvg)\n\t\t\t\tblueprint = stateToBlueprint(layout, states, relations, classes)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'mindmap': {\n\t\t\t\tconst db = diagramResult.db as MindmapDB\n\t\t\t\tconst tree = db.getMindmap()\n\t\t\t\tif (tree) {\n\t\t\t\t\tdb.assignSections(tree)\n\t\t\t\t\tconst layout = parseMindmapLayout(liveSvg)\n\t\t\t\t\tblueprint = mindmapToBlueprint(layout, tree, liveSvg)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tif (options.onUnsupportedDiagram) {\n\t\t\t\t\tawait options.onUnsupportedDiagram(parsedSvg)\n\t\t\t\t} else {\n\t\t\t\t\tthrow new MermaidDiagramError(parsedResult.diagramType, 'unsupported')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (blueprint) {\n\t\t\trenderBlueprint(editor, blueprint, options.blueprintRender)\n\t\t}\n\t} catch (e) {\n\t\tif (e instanceof MermaidDiagramError) throw e\n\t\tconsole.error(e)\n\t\tthrow new MermaidDiagramError(parsedResult.diagramType, 'parse')\n\t} finally {\n\t\toffscreen.remove()\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,8BAA2D;AAC3D,4BAAuD;AACvD,6BAA2D;AAC3D,6BAA8E;AAC9E,0BAA0D;AAZ1D,IAAI,gBAAgB;AAeb,MAAM,4BAA4B,MAAM;AAAA,EAC9C,YACQ,aACA,MACN;AACD,UAAM,0BAA0B,WAAW,EAAE;AAHt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QAAQ,WAAW,OAAO;AAC/D;AAAA,MACD;AAAA,MACA,KAAK,WAAW;AACf,cAAM,KAAK,cAAc;AACzB,cAAM,OAAO,GAAG,WAAW;AAC3B,YAAI,MAAM;AACT,aAAG,eAAe,IAAI;AACtB,gBAAM,aAAS,0CAAmB,OAAO;AACzC,0BAAY,0CAAmB,QAAQ,MAAM,OAAO;AAAA,QACrD;AACA;AAAA,MACD;AAAA,MACA;AACC,YAAI,QAAQ,sBAAsB;AACjC,gBAAM,QAAQ,qBAAqB,SAAS;AAAA,QAC7C,OAAO;AACN,gBAAM,IAAI,oBAAoB,aAAa,aAAa,aAAa;AAAA,QACtE;AACA;AAAA,IACF;AAEA,QAAI,WAAW;AACd,kDAAgB,QAAQ,WAAW,QAAQ,eAAe;AAAA,IAC3D;AAAA,EACD,SAAS,GAAG;AACX,QAAI,aAAa,oBAAqB,OAAM;AAC5C,YAAQ,MAAM,CAAC;AACf,UAAM,IAAI,oBAAoB,aAAa,aAAa,OAAO;AAAA,EAChE,UAAE;AACD,cAAU,OAAO;AAAA,EAClB;AACD;",
4
+ "sourcesContent": ["import type { FlowDB } from 'mermaid/dist/diagrams/flowchart/flowDb.d.ts'\nimport type { FlowEdge, FlowSubGraph, FlowVertex } from 'mermaid/dist/diagrams/flowchart/types.js'\nimport type { MindmapDB } from 'mermaid/dist/diagrams/mindmap/mindmapDb.d.ts'\nimport type { SequenceDB } from 'mermaid/dist/diagrams/sequence/sequenceDb.d.ts'\nimport type { StateDB } from 'mermaid/dist/diagrams/state/stateDb.d.ts'\nimport { Editor } from 'tldraw'\nimport { flowchartToBlueprint, parseFlowchartLayout } from './flowchartDiagram'\nimport { createLabelWidthMeasurer } from './mermaidNodeCreateShape'\nimport { mindmapToBlueprint, parseMindmapLayout } from './mindmapDiagram'\nimport { BlueprintRenderingOptions, renderBlueprint } from './renderBlueprint'\nimport { countSequenceEvents, parseSequenceLayout, sequenceToBlueprint } from './sequenceDiagram'\nimport { parseStateDiagramLayout, stateToBlueprint } from './stateDiagram'\n\nlet nextMermaidId = 0\n\n/** @public */\nexport class MermaidDiagramError extends Error {\n\tconstructor(\n\t\tpublic diagramType: string,\n\t\tpublic type: 'parse' | 'unsupported'\n\t) {\n\t\tsuper(`mermaid diagram error: ${diagramType}`)\n\t\tthis.name = 'MermaidDiagramError'\n\t}\n}\n\n// Inflate the font size so Mermaid's layout engine allocates larger nodes,\n// compensating for tldraw's hand-drawn font being wider than Mermaid's default.\nconst FONT_INFLATE = 1.4\n\nconst MERMAID_CONFIG = {\n\tstartOnLoad: false,\n\tflowchart: { nodeSpacing: 80, rankSpacing: 80, padding: 20 },\n\tstate: { nodeSpacing: 80, rankSpacing: 80, padding: 20 },\n\tmindmap: { padding: 20 },\n\tsequence: { actorMargin: 50, noteMargin: 20 },\n\tthemeVariables: { fontSize: `${18 * FONT_INFLATE}px` },\n}\n\n/** @public */\nexport interface MermaidDiagramOptions {\n\tmermaidConfig?: Record<string, any>\n\tblueprintRender?: BlueprintRenderingOptions\n\tonUnsupportedDiagram?(svg: string): Promise<void>\n}\n\n/**\n * Parse mermaid text and create tldraw shapes for supported diagram types.\n * Returns the SVG string for supported diagrams, or `null` when the diagram type\n * is unsupported (after calling `onUnsupportedDiagram` if provided).\n * Throws {@link MermaidDiagramError} if parsing fails.\n * @public\n */\nexport async function createMermaidDiagram(\n\teditor: Editor,\n\ttext: string,\n\toptions: MermaidDiagramOptions = {}\n): Promise<void> {\n\t// load mermaid lazily: it's a large, ESM-only dependency only needed when a\n\t// diagram is actually created. a dynamic import() works from CommonJS (unlike\n\t// a static import, which compiles to require(<esm>) and throws\n\t// ERR_REQUIRE_ESM on Node <20.19, Jest, and ts-node) and avoids pulling\n\t// mermaid in when @tldraw/mermaid is merely imported.\n\tconst mermaid = (await import('mermaid')).default\n\n\tmermaid.initialize({\n\t\t...MERMAID_CONFIG,\n\t\t...(options.mermaidConfig ?? {}),\n\t\tflowchart: { ...MERMAID_CONFIG.flowchart, ...options.mermaidConfig?.flowchart },\n\t\tstate: { ...MERMAID_CONFIG.state, ...options.mermaidConfig?.state },\n\t\tmindmap: { ...MERMAID_CONFIG.mindmap, ...options.mermaidConfig?.mindmap },\n\t\tsequence: { ...MERMAID_CONFIG.sequence, ...options.mermaidConfig?.sequence },\n\t\tthemeVariables: { ...MERMAID_CONFIG.themeVariables, ...options.mermaidConfig?.themeVariables },\n\t\t// A diagram's own `%%{init}%%` or frontmatter config outranks `initialize`, so one that sets\n\t\t// `fontSize` undoes FONT_INFLATE: every box is measured small while tldraw still draws its\n\t\t// wider face, and labels break mid-word. Mermaid strips `secure` keys from in-diagram config\n\t\t// at any depth, and keeps its own defaults alongside the ones listed here.\n\t\tsecure: [...(options.mermaidConfig?.secure ?? []), 'fontSize'],\n\t})\n\n\tconst parsedResult = await mermaid.parse(text, { suppressErrors: true })\n\n\tif (!parsedResult) {\n\t\tthrow new MermaidDiagramError('not a mermaid diagram', 'parse')\n\t}\n\n\tconst offscreen = document.createElement('div')\n\tObject.assign(offscreen.style, {\n\t\tposition: 'absolute',\n\t\tleft: '-9999px',\n\t\ttop: '-9999px',\n\t\toverflow: 'hidden',\n\t})\n\tdocument.body.appendChild(offscreen)\n\n\ttry {\n\t\tconst parsedSvg = (await mermaid.render(`mermaid-${nextMermaidId++}`, text, offscreen)).svg\n\n\t\t// Reuse the live SVG that mermaid.render() already mounted into the\n\t\t// offscreen container. This avoids a second DOM mount and ensures\n\t\t// getBBox() works for every diagram type (state diagrams in particular\n\t\t// lack explicit dimension attributes and rely on live layout).\n\t\tlet liveSvg = offscreen.querySelector('svg')\n\n\t\tif (!liveSvg) {\n\t\t\toffscreen.innerHTML = parsedSvg\n\t\t\tliveSvg = offscreen.querySelector('svg')\n\t\t\tif (!liveSvg) {\n\t\t\t\tthrow new MermaidDiagramError(parsedResult.diagramType, 'parse')\n\t\t\t}\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\tconst diagramResult = await mermaid.mermaidAPI.getDiagramFromText(text)\n\n\t\tlet blueprint\n\t\tswitch (parsedResult.diagramType) {\n\t\t\tcase 'flowchart-v2': {\n\t\t\t\tconst db = diagramResult.db as FlowDB\n\t\t\t\tconst vertices = db.getVertices() as Map<string, FlowVertex>\n\t\t\t\tconst edges = db.getEdges() as FlowEdge[]\n\t\t\t\tconst subGraphs = db.getSubGraphs() as FlowSubGraph[]\n\t\t\t\tconst classes = db.getClasses()\n\t\t\t\tconst layout = parseFlowchartLayout(liveSvg)\n\t\t\t\tblueprint = flowchartToBlueprint(layout, vertices, edges, subGraphs, classes)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'sequence': {\n\t\t\t\tconst db = diagramResult.db as SequenceDB\n\t\t\t\tconst actors = db.getActors()\n\t\t\t\tconst actorKeys = db.getActorKeys()\n\t\t\t\tconst messages = db.getMessages()\n\t\t\t\tconst layout = parseSequenceLayout(liveSvg, actorKeys.length, countSequenceEvents(messages))\n\t\t\t\tblueprint = sequenceToBlueprint(\n\t\t\t\t\tlayout,\n\t\t\t\t\tactors,\n\t\t\t\t\tactorKeys,\n\t\t\t\t\tmessages,\n\t\t\t\t\tdb.getCreatedActors(),\n\t\t\t\t\tdb.getDestroyedActors(),\n\t\t\t\t\tcreateLabelWidthMeasurer(editor)\n\t\t\t\t)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'state':\n\t\t\tcase 'stateDiagram': {\n\t\t\t\tconst db = diagramResult.db as StateDB\n\t\t\t\tconst states = db.getStates()\n\t\t\t\tconst relations = db.getRelations()\n\t\t\t\tconst classes = db.getClasses()\n\t\t\t\tconst layout = parseStateDiagramLayout(liveSvg)\n\t\t\t\tblueprint = stateToBlueprint(layout, states, relations, classes)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'mindmap': {\n\t\t\t\tconst db = diagramResult.db as MindmapDB\n\t\t\t\tconst tree = db.getMindmap()\n\t\t\t\tif (tree) {\n\t\t\t\t\tdb.assignSections(tree)\n\t\t\t\t\tconst layout = parseMindmapLayout(liveSvg)\n\t\t\t\t\tblueprint = mindmapToBlueprint(layout, tree, liveSvg)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tif (options.onUnsupportedDiagram) {\n\t\t\t\t\tawait options.onUnsupportedDiagram(parsedSvg)\n\t\t\t\t} else {\n\t\t\t\t\tthrow new MermaidDiagramError(parsedResult.diagramType, 'unsupported')\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\tif (blueprint) {\n\t\t\trenderBlueprint(editor, blueprint, options.blueprintRender)\n\t\t}\n\t} catch (e) {\n\t\tif (e instanceof MermaidDiagramError) throw e\n\t\tconsole.error(e)\n\t\tthrow new MermaidDiagramError(parsedResult.diagramType, 'parse')\n\t} finally {\n\t\toffscreen.remove()\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,8BAA2D;AAC3D,oCAAyC;AACzC,4BAAuD;AACvD,6BAA2D;AAC3D,6BAA8E;AAC9E,0BAA0D;AAE1D,IAAI,gBAAgB;AAGb,MAAM,4BAA4B,MAAM;AAAA,EAC9C,YACQ,aACA,MACN;AACD,UAAM,0BAA0B,WAAW,EAAE;AAHtC;AACA;AAGP,SAAK,OAAO;AAAA,EACb;AAAA,EALQ;AAAA,EACA;AAKT;AAIA,MAAM,eAAe;AAErB,MAAM,iBAAiB;AAAA,EACtB,aAAa;AAAA,EACb,WAAW,EAAE,aAAa,IAAI,aAAa,IAAI,SAAS,GAAG;AAAA,EAC3D,OAAO,EAAE,aAAa,IAAI,aAAa,IAAI,SAAS,GAAG;AAAA,EACvD,SAAS,EAAE,SAAS,GAAG;AAAA,EACvB,UAAU,EAAE,aAAa,IAAI,YAAY,GAAG;AAAA,EAC5C,gBAAgB,EAAE,UAAU,GAAG,KAAK,YAAY,KAAK;AACtD;AAgBA,eAAsB,qBACrB,QACA,MACA,UAAiC,CAAC,GACl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gBAAM,QAAQ,qBAAqB,SAAS;AAAA,QAC7C,OAAO;AACN,gBAAM,IAAI,oBAAoB,aAAa,aAAa,aAAa;AAAA,QACtE;AACA;AAAA,IACF;AAEA,QAAI,WAAW;AACd,kDAAgB,QAAQ,WAAW,QAAQ,eAAe;AAAA,IAC3D;AAAA,EACD,SAAS,GAAG;AACX,QAAI,aAAa,oBAAqB,OAAM;AAC5C,YAAQ,MAAM,CAAC;AACf,UAAM,IAAI,oBAAoB,aAAa,aAAa,OAAO;AAAA,EAChE,UAAE;AACD,cAAU,OAAO;AAAA,EAClB;AACD;",
6
6
  "names": []
7
7
  }
@@ -22,6 +22,7 @@ __export(defaultMermaidNodeRenderSpec_exports, {
22
22
  resolveMermaidNodeRender: () => resolveMermaidNodeRender
23
23
  });
24
24
  module.exports = __toCommonJS(defaultMermaidNodeRenderSpec_exports);
25
+ var import_mindmapDiagram = require("./mindmapDiagram");
25
26
  function flowchartKindToGeo(kind) {
26
27
  switch (kind) {
27
28
  case "diamond":
@@ -41,11 +42,6 @@ function flowchartKindToGeo(kind) {
41
42
  return "rhombus";
42
43
  case "lean_left":
43
44
  return "rhombus-2";
44
- case "subgraph":
45
- case "square":
46
- case "rect":
47
- case "round":
48
- case "subroutine":
49
45
  default:
50
46
  return "rectangle";
51
47
  }
@@ -58,10 +54,6 @@ function stateKindToGeo(kind) {
58
54
  case "end":
59
55
  case "end_inner":
60
56
  return "ellipse";
61
- case "compound":
62
- case "note":
63
- case "fork":
64
- case "join":
65
57
  default:
66
58
  return "rectangle";
67
59
  }
@@ -72,51 +64,32 @@ function sequenceKindToGeo(kind) {
72
64
  return "ellipse";
73
65
  case "database":
74
66
  return "oval";
75
- case "sequence_activation":
76
- case "sequence_fragment":
77
- case "sequence_fragment_section":
78
- case "sequence_note":
79
67
  default:
80
68
  return "rectangle";
81
69
  }
82
70
  }
83
71
  function mindmapKindToGeo(kind) {
84
- const type = Number(kind);
85
- switch (type) {
86
- case 3:
72
+ switch (Number(kind)) {
73
+ case import_mindmapDiagram.MERMAID_MINDMAP_NODE_TYPE.CIRCLE:
87
74
  return "ellipse";
88
- case 4:
75
+ case import_mindmapDiagram.MERMAID_MINDMAP_NODE_TYPE.CLOUD:
89
76
  return "cloud";
90
- case 6:
77
+ case import_mindmapDiagram.MERMAID_MINDMAP_NODE_TYPE.HEXAGON:
91
78
  return "hexagon";
92
- case 5:
79
+ case import_mindmapDiagram.MERMAID_MINDMAP_NODE_TYPE.BANG:
93
80
  return "star";
94
- case 2:
95
- case 1:
96
- case 0:
97
81
  default:
98
82
  return "rectangle";
99
83
  }
100
84
  }
85
+ const KIND_TO_GEO = {
86
+ flowchart: flowchartKindToGeo,
87
+ state: stateKindToGeo,
88
+ sequence: sequenceKindToGeo,
89
+ mindmap: mindmapKindToGeo
90
+ };
101
91
  function defaultMermaidNodeRenderSpec(diagramKind, kind) {
102
- let geo;
103
- switch (diagramKind) {
104
- case "flowchart":
105
- geo = flowchartKindToGeo(kind);
106
- break;
107
- case "state":
108
- geo = stateKindToGeo(kind);
109
- break;
110
- case "sequence":
111
- geo = sequenceKindToGeo(kind);
112
- break;
113
- case "mindmap":
114
- geo = mindmapKindToGeo(kind);
115
- break;
116
- default:
117
- geo = "rectangle";
118
- }
119
- return { variant: "geo", geo };
92
+ return { variant: "geo", geo: KIND_TO_GEO[diagramKind]?.(kind) ?? "rectangle" };
120
93
  }
121
94
  function resolveMermaidNodeRender(diagramKind, node, mapper) {
122
95
  return mapper?.({
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/defaultMermaidNodeRenderSpec.ts"],
4
- "sourcesContent": ["import type { TLGeoShapeGeoStyle } from 'tldraw'\nimport type {\n\tMermaidBlueprintNode,\n\tMermaidBlueprintNodeRenderSpec,\n\tMermaidDiagramKind,\n\tMermaidNodeRenderMapper,\n} from './blueprint'\n\nfunction flowchartKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tswitch (kind) {\n\t\tcase 'diamond':\n\t\t\treturn 'diamond'\n\t\tcase 'ellipse':\n\t\tcase 'circle':\n\t\tcase 'doublecircle':\n\t\tcase 'stadium':\n\t\tcase 'cylinder':\n\t\t\treturn 'ellipse'\n\t\tcase 'hexagon':\n\t\t\treturn 'hexagon'\n\t\tcase 'trapezoid':\n\t\tcase 'inv_trapezoid':\n\t\t\treturn 'trapezoid'\n\t\tcase 'lean_right':\n\t\t\treturn 'rhombus'\n\t\tcase 'lean_left':\n\t\t\treturn 'rhombus-2'\n\t\tcase 'subgraph':\n\t\tcase 'square':\n\t\tcase 'rect':\n\t\tcase 'round':\n\t\tcase 'subroutine':\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\nfunction stateKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tswitch (kind) {\n\t\tcase 'choice':\n\t\t\treturn 'diamond'\n\t\tcase 'start':\n\t\tcase 'end':\n\t\tcase 'end_inner':\n\t\t\treturn 'ellipse'\n\t\tcase 'compound':\n\t\tcase 'note':\n\t\tcase 'fork':\n\t\tcase 'join':\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\nfunction sequenceKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tswitch (kind) {\n\t\tcase 'actor':\n\t\t\treturn 'ellipse'\n\t\tcase 'database':\n\t\t\treturn 'oval'\n\t\tcase 'sequence_activation':\n\t\tcase 'sequence_fragment':\n\t\tcase 'sequence_fragment_section':\n\t\tcase 'sequence_note':\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\nfunction mindmapKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tconst type = Number(kind)\n\tswitch (type) {\n\t\tcase 3:\n\t\t\treturn 'ellipse'\n\t\tcase 4:\n\t\t\treturn 'cloud'\n\t\tcase 6:\n\t\t\treturn 'hexagon'\n\t\tcase 5:\n\t\t\treturn 'star'\n\t\tcase 2:\n\t\tcase 1:\n\t\tcase 0:\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\n/**\n * Default built-in mapping from {@link MermaidDiagramKind} + semantic `kind` to a geo {@link MermaidBlueprintNodeRenderSpec}.\n * Used when `mapNodeToRenderSpec` is omitted from `renderBlueprint` options, or when the mapper returns `undefined`.\n * @public\n */\nexport function defaultMermaidNodeRenderSpec(\n\tdiagramKind: MermaidDiagramKind,\n\tkind: string\n): MermaidBlueprintNodeRenderSpec {\n\tlet geo: TLGeoShapeGeoStyle\n\tswitch (diagramKind) {\n\t\tcase 'flowchart':\n\t\t\tgeo = flowchartKindToGeo(kind)\n\t\t\tbreak\n\t\tcase 'state':\n\t\t\tgeo = stateKindToGeo(kind)\n\t\t\tbreak\n\t\tcase 'sequence':\n\t\t\tgeo = sequenceKindToGeo(kind)\n\t\t\tbreak\n\t\tcase 'mindmap':\n\t\t\tgeo = mindmapKindToGeo(kind)\n\t\t\tbreak\n\t\tdefault:\n\t\t\tgeo = 'rectangle'\n\t}\n\treturn { variant: 'geo', geo }\n}\n\n/**\n * Uses the optional mapper when it returns a value; otherwise {@link defaultMermaidNodeRenderSpec}.\n * @public\n */\nexport function resolveMermaidNodeRender(\n\tdiagramKind: MermaidDiagramKind,\n\tnode: MermaidBlueprintNode,\n\tmapper?: MermaidNodeRenderMapper | undefined\n): MermaidBlueprintNodeRenderSpec {\n\treturn (\n\t\tmapper?.({\n\t\t\tdiagramKind,\n\t\t\tnodeId: node.id,\n\t\t\tkind: node.kind,\n\t\t\tnode,\n\t\t}) ?? defaultMermaidNodeRenderSpec(diagramKind, node.kind)\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAS,mBAAmB,MAAkC;AAC7D,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,K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,EACR;AACA,SAAO,EAAE,SAAS,OAAO,IAAI;AAC9B;AAMO,SAAS,yBACf,aACA,MACA,QACiC;AACjC,SACC,SAAS;AAAA,IACR;AAAA,IACA,QAAQ,KAAK;AAAA,IACb,MAAM,KAAK;AAAA,IACX;AAAA,EACD,CAAC,KAAK,6BAA6B,aAAa,KAAK,IAAI;AAE3D;",
4
+ "sourcesContent": ["import type { TLGeoShapeGeoStyle } from 'tldraw'\nimport type {\n\tMermaidBlueprintNode,\n\tMermaidBlueprintNodeRenderSpec,\n\tMermaidDiagramKind,\n\tMermaidNodeRenderMapper,\n} from './blueprint'\nimport { MERMAID_MINDMAP_NODE_TYPE } from './mindmapDiagram'\n\nfunction flowchartKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tswitch (kind) {\n\t\tcase 'diamond':\n\t\t\treturn 'diamond'\n\t\tcase 'ellipse':\n\t\tcase 'circle':\n\t\tcase 'doublecircle':\n\t\tcase 'stadium':\n\t\tcase 'cylinder':\n\t\t\treturn 'ellipse'\n\t\tcase 'hexagon':\n\t\t\treturn 'hexagon'\n\t\tcase 'trapezoid':\n\t\tcase 'inv_trapezoid':\n\t\t\treturn 'trapezoid'\n\t\tcase 'lean_right':\n\t\t\treturn 'rhombus'\n\t\tcase 'lean_left':\n\t\t\treturn 'rhombus-2'\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\nfunction stateKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tswitch (kind) {\n\t\tcase 'choice':\n\t\t\treturn 'diamond'\n\t\tcase 'start':\n\t\tcase 'end':\n\t\tcase 'end_inner':\n\t\t\treturn 'ellipse'\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\nfunction sequenceKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tswitch (kind) {\n\t\tcase 'actor':\n\t\t\treturn 'ellipse'\n\t\tcase 'database':\n\t\t\treturn 'oval'\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\nfunction mindmapKindToGeo(kind: string): TLGeoShapeGeoStyle {\n\tswitch (Number(kind)) {\n\t\tcase MERMAID_MINDMAP_NODE_TYPE.CIRCLE:\n\t\t\treturn 'ellipse'\n\t\tcase MERMAID_MINDMAP_NODE_TYPE.CLOUD:\n\t\t\treturn 'cloud'\n\t\tcase MERMAID_MINDMAP_NODE_TYPE.HEXAGON:\n\t\t\treturn 'hexagon'\n\t\tcase MERMAID_MINDMAP_NODE_TYPE.BANG:\n\t\t\treturn 'star'\n\t\tdefault:\n\t\t\treturn 'rectangle'\n\t}\n}\n\nconst KIND_TO_GEO: Record<MermaidDiagramKind, (kind: string) => TLGeoShapeGeoStyle> = {\n\tflowchart: flowchartKindToGeo,\n\tstate: stateKindToGeo,\n\tsequence: sequenceKindToGeo,\n\tmindmap: mindmapKindToGeo,\n}\n\n/**\n * Default built-in mapping from {@link MermaidDiagramKind} + semantic `kind` to a geo {@link MermaidBlueprintNodeRenderSpec}.\n * Used when `mapNodeToRenderSpec` is omitted from `renderBlueprint` options, or when the mapper returns `undefined`.\n * @public\n */\nexport function defaultMermaidNodeRenderSpec(\n\tdiagramKind: MermaidDiagramKind,\n\tkind: string\n): MermaidBlueprintNodeRenderSpec {\n\treturn { variant: 'geo', geo: KIND_TO_GEO[diagramKind]?.(kind) ?? 'rectangle' }\n}\n\n/**\n * Uses the optional mapper when it returns a value; otherwise {@link defaultMermaidNodeRenderSpec}.\n * @public\n */\nexport function resolveMermaidNodeRender(\n\tdiagramKind: MermaidDiagramKind,\n\tnode: MermaidBlueprintNode,\n\tmapper?: MermaidNodeRenderMapper | undefined\n): MermaidBlueprintNodeRenderSpec {\n\treturn (\n\t\tmapper?.({\n\t\t\tdiagramKind,\n\t\t\tnodeId: node.id,\n\t\t\tkind: node.kind,\n\t\t\tnode,\n\t\t}) ?? defaultMermaidNodeRenderSpec(diagramKind, node.kind)\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;A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