@tldraw/mermaid 4.6.0-next.1f489710ee41 → 4.6.0-next.4dde09fa17ab
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.
- package/README.md +19 -6
- package/dist-cjs/blueprint.js.map +1 -1
- package/dist-cjs/defaultMermaidNodeRenderSpec.js +129 -0
- package/dist-cjs/defaultMermaidNodeRenderSpec.js.map +7 -0
- package/dist-cjs/flowchartDiagram.js +7 -33
- package/dist-cjs/flowchartDiagram.js.map +2 -2
- package/dist-cjs/index.d.ts +118 -19
- package/dist-cjs/index.js +9 -2
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/mermaidNodeCreateShape.js +66 -0
- package/dist-cjs/mermaidNodeCreateShape.js.map +7 -0
- package/dist-cjs/mindmapDiagram.js +8 -23
- package/dist-cjs/mindmapDiagram.js.map +2 -2
- package/dist-cjs/renderBlueprint.js +12 -17
- package/dist-cjs/renderBlueprint.js.map +2 -2
- package/dist-cjs/sequenceDiagram.js +41 -24
- package/dist-cjs/sequenceDiagram.js.map +2 -2
- package/dist-cjs/stateDiagram.js +23 -37
- package/dist-cjs/stateDiagram.js.map +2 -2
- package/dist-esm/defaultMermaidNodeRenderSpec.mjs +109 -0
- package/dist-esm/defaultMermaidNodeRenderSpec.mjs.map +7 -0
- package/dist-esm/flowchartDiagram.mjs +7 -33
- package/dist-esm/flowchartDiagram.mjs.map +2 -2
- package/dist-esm/index.d.mts +118 -19
- package/dist-esm/index.mjs +14 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/mermaidNodeCreateShape.mjs +46 -0
- package/dist-esm/mermaidNodeCreateShape.mjs.map +7 -0
- package/dist-esm/mindmapDiagram.mjs +8 -23
- package/dist-esm/mindmapDiagram.mjs.map +2 -2
- package/dist-esm/renderBlueprint.mjs +13 -22
- package/dist-esm/renderBlueprint.mjs.map +2 -2
- package/dist-esm/sequenceDiagram.mjs +41 -24
- package/dist-esm/sequenceDiagram.mjs.map +2 -2
- package/dist-esm/stateDiagram.mjs +23 -37
- package/dist-esm/stateDiagram.mjs.map +2 -2
- package/package.json +5 -5
- package/src/blueprint.ts +56 -9
- package/src/defaultMermaidNodeRenderSpec.ts +135 -0
- package/src/flowchartDiagram.ts +11 -38
- package/src/index.ts +13 -1
- package/src/mermaidDiagrams.test.ts +79 -21
- package/src/mermaidNodeCreateShape.test.ts +79 -0
- package/src/mermaidNodeCreateShape.ts +73 -0
- package/src/mindmapDiagram.ts +11 -27
- package/src/renderBlueprint.ts +21 -29
- package/src/sequenceDiagram.ts +44 -28
- package/src/stateDiagram.ts +32 -42
package/README.md
CHANGED
|
@@ -84,26 +84,39 @@ Parses Mermaid text, extracts layout from the rendered SVG, builds a blueprint,
|
|
|
84
84
|
- **`text`** — Mermaid diagram source text.
|
|
85
85
|
- **`options`** — optional `MermaidDiagramOptions`:
|
|
86
86
|
- `mermaidConfig` — Mermaid configuration overrides (theme, spacing, etc.).
|
|
87
|
-
- `blueprintRender` — positioning
|
|
87
|
+
- `blueprintRender` — positioning (`position`, `centerOnPosition`) and optional `mapNodeToRenderSpec` (see below).
|
|
88
88
|
- `onUnsupportedDiagram(svg)` — callback when the diagram type isn't natively supported.
|
|
89
89
|
|
|
90
90
|
Throws `MermaidDiagramError` on parse failure or unsupported diagram type (if no callback is provided).
|
|
91
91
|
|
|
92
92
|
### `renderBlueprint(editor, blueprint, opts?)`
|
|
93
93
|
|
|
94
|
-
Renders a pre-built `DiagramMermaidBlueprint` into the editor. Useful if you want to construct or modify a blueprint programmatically before rendering.
|
|
94
|
+
Renders a pre-built `DiagramMermaidBlueprint` into the editor. Useful if you want to construct or modify a blueprint programmatically before rendering. Options include `mapNodeToRenderSpec` to customize how each node is materialized (see below).
|
|
95
95
|
|
|
96
96
|
### `MermaidDiagramError`
|
|
97
97
|
|
|
98
98
|
Error class with `type: 'parse' | 'unsupported'` and `diagramType` properties.
|
|
99
99
|
|
|
100
|
+
### Customizing node shapes
|
|
101
|
+
|
|
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.
|
|
103
|
+
|
|
104
|
+
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
|
+
|
|
106
|
+
Custom `type` values must exist on the editor before import. Exotic shapes may need compatible geometry for arrow bindings to feel like built-in geo nodes.
|
|
107
|
+
|
|
108
|
+
Helpers: **`defaultMermaidNodeRenderSpec`**, **`resolveMermaidNodeRender`**, **`MERMAID_MINDMAP_NODE_TYPE`** (mindmap `kind` strings match `String` of these integers).
|
|
109
|
+
|
|
100
110
|
### Types
|
|
101
111
|
|
|
102
|
-
- **`DiagramMermaidBlueprint`** —
|
|
103
|
-
- **`
|
|
112
|
+
- **`DiagramMermaidBlueprint`** — `{ diagramKind, nodes, edges, lines?, groups? }`.
|
|
113
|
+
- **`MermaidBlueprintNode`** — layout, semantic `kind`, and style fields (materialization is chosen at render time).
|
|
114
|
+
- **`MermaidBlueprintNodeRenderSpec`** — `variant: 'geo'` + `geo`, or `variant: 'shape'` + `type` + `props`.
|
|
115
|
+
- **`MermaidDiagramKind`** — `'flowchart' | 'state' | 'sequence' | 'mindmap'`.
|
|
104
116
|
- **`MermaidBlueprintEdge`** — an arrow with start/end node IDs, bend, arrowheads, dash style, and anchor positions.
|
|
105
117
|
- **`MermaidBlueprintLineNode`** — a vertical or horizontal line (used for sequence diagram lifelines).
|
|
106
|
-
- **`BlueprintRenderingOptions`** — position and
|
|
118
|
+
- **`BlueprintRenderingOptions`** — position, centering, and optional `mapNodeToRenderSpec` for `renderBlueprint` / `createMermaidDiagram`.
|
|
119
|
+
- **`MermaidNodeCreateFunctionArgs`** — argument object for **`defaultCreateMermaidNodeFromBlueprint`** (includes resolved **`render`** spec).
|
|
107
120
|
|
|
108
121
|
## How it works
|
|
109
122
|
|
|
@@ -118,7 +131,7 @@ flowchart LR
|
|
|
118
131
|
|
|
119
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()`.
|
|
120
133
|
2. **Extract blueprint** — a diagram-specific converter reads positions from the SVG and semantic data from Mermaid's internal database, producing a `DiagramMermaidBlueprint`.
|
|
121
|
-
3. **Create shapes** — `renderBlueprint`
|
|
134
|
+
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.
|
|
122
135
|
|
|
123
136
|
## Example: paste handler
|
|
124
137
|
|
|
@@ -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 *
|
|
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"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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 defaultMermaidNodeRenderSpec_exports = {};
|
|
20
|
+
__export(defaultMermaidNodeRenderSpec_exports, {
|
|
21
|
+
defaultMermaidNodeRenderSpec: () => defaultMermaidNodeRenderSpec,
|
|
22
|
+
resolveMermaidNodeRender: () => resolveMermaidNodeRender
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(defaultMermaidNodeRenderSpec_exports);
|
|
25
|
+
function flowchartKindToGeo(kind) {
|
|
26
|
+
switch (kind) {
|
|
27
|
+
case "diamond":
|
|
28
|
+
return "diamond";
|
|
29
|
+
case "ellipse":
|
|
30
|
+
case "circle":
|
|
31
|
+
case "doublecircle":
|
|
32
|
+
case "stadium":
|
|
33
|
+
case "cylinder":
|
|
34
|
+
return "ellipse";
|
|
35
|
+
case "hexagon":
|
|
36
|
+
return "hexagon";
|
|
37
|
+
case "trapezoid":
|
|
38
|
+
case "inv_trapezoid":
|
|
39
|
+
return "trapezoid";
|
|
40
|
+
case "lean_right":
|
|
41
|
+
return "rhombus";
|
|
42
|
+
case "lean_left":
|
|
43
|
+
return "rhombus-2";
|
|
44
|
+
case "subgraph":
|
|
45
|
+
case "square":
|
|
46
|
+
case "rect":
|
|
47
|
+
case "round":
|
|
48
|
+
case "subroutine":
|
|
49
|
+
default:
|
|
50
|
+
return "rectangle";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function stateKindToGeo(kind) {
|
|
54
|
+
switch (kind) {
|
|
55
|
+
case "choice":
|
|
56
|
+
return "diamond";
|
|
57
|
+
case "start":
|
|
58
|
+
case "end":
|
|
59
|
+
case "end_inner":
|
|
60
|
+
return "ellipse";
|
|
61
|
+
case "compound":
|
|
62
|
+
case "note":
|
|
63
|
+
case "fork":
|
|
64
|
+
case "join":
|
|
65
|
+
default:
|
|
66
|
+
return "rectangle";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function sequenceKindToGeo(kind) {
|
|
70
|
+
switch (kind) {
|
|
71
|
+
case "actor":
|
|
72
|
+
return "ellipse";
|
|
73
|
+
case "database":
|
|
74
|
+
return "oval";
|
|
75
|
+
case "sequence_activation":
|
|
76
|
+
case "sequence_fragment":
|
|
77
|
+
case "sequence_fragment_section":
|
|
78
|
+
case "sequence_note":
|
|
79
|
+
default:
|
|
80
|
+
return "rectangle";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function mindmapKindToGeo(kind) {
|
|
84
|
+
const type = Number(kind);
|
|
85
|
+
switch (type) {
|
|
86
|
+
case 3:
|
|
87
|
+
return "ellipse";
|
|
88
|
+
case 4:
|
|
89
|
+
return "cloud";
|
|
90
|
+
case 6:
|
|
91
|
+
return "hexagon";
|
|
92
|
+
case 5:
|
|
93
|
+
return "star";
|
|
94
|
+
case 2:
|
|
95
|
+
case 1:
|
|
96
|
+
case 0:
|
|
97
|
+
default:
|
|
98
|
+
return "rectangle";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
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 };
|
|
120
|
+
}
|
|
121
|
+
function resolveMermaidNodeRender(diagramKind, node, mapper) {
|
|
122
|
+
return mapper?.({
|
|
123
|
+
diagramKind,
|
|
124
|
+
nodeId: node.id,
|
|
125
|
+
kind: node.kind,
|
|
126
|
+
node
|
|
127
|
+
}) ?? defaultMermaidNodeRenderSpec(diagramKind, node.kind);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=defaultMermaidNodeRenderSpec.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,eAAe,MAAkC;AACzD,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,kBAAkB,MAAkC;AAC5D,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,iBAAiB,MAAkC;AAC3D,QAAM,OAAO,OAAO,IAAI;AACxB,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL;AACC,aAAO;AAAA,EACT;AACD;AAOO,SAAS,6BACf,aACA,MACiC;AACjC,MAAI;AACJ,UAAQ,aAAa;AAAA,IACpB,KAAK;AACJ,YAAM,mBAAmB,IAAI;AAC7B;AAAA,IACD,KAAK;AACJ,YAAM,eAAe,IAAI;AACzB;AAAA,IACD,KAAK;AACJ,YAAM,kBAAkB,IAAI;AAC5B;AAAA,IACD,KAAK;AACJ,YAAM,iBAAiB,IAAI;AAC3B;AAAA,IACD;AACC,YAAM;AAAA,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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -33,34 +33,6 @@ function mapEdgeTypeToArrowhead(type) {
|
|
|
33
33
|
if (type.includes("open")) return "none";
|
|
34
34
|
return "arrow";
|
|
35
35
|
}
|
|
36
|
-
function mapFlowShapeTypeToGeo(type) {
|
|
37
|
-
switch (type) {
|
|
38
|
-
case "diamond":
|
|
39
|
-
return "diamond";
|
|
40
|
-
case "ellipse":
|
|
41
|
-
case "circle":
|
|
42
|
-
case "doublecircle":
|
|
43
|
-
case "stadium":
|
|
44
|
-
case "cylinder":
|
|
45
|
-
return "ellipse";
|
|
46
|
-
case "hexagon":
|
|
47
|
-
return "hexagon";
|
|
48
|
-
case "trapezoid":
|
|
49
|
-
// TODO: implement inv_trapezoid in SDK
|
|
50
|
-
case "inv_trapezoid":
|
|
51
|
-
return "trapezoid";
|
|
52
|
-
case "lean_right":
|
|
53
|
-
return "rhombus";
|
|
54
|
-
case "lean_left":
|
|
55
|
-
return "rhombus-2";
|
|
56
|
-
case "square":
|
|
57
|
-
case "rect":
|
|
58
|
-
case "round":
|
|
59
|
-
case "subroutine":
|
|
60
|
-
default:
|
|
61
|
-
return "rectangle";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
36
|
function mapEdgeStrokeToDash(stroke) {
|
|
65
37
|
if (!stroke) return "solid";
|
|
66
38
|
if (stroke === "dotted") return "dotted";
|
|
@@ -110,13 +82,15 @@ function flowchartToBlueprint(layout, vertices, edges, subGraphs, classDefs) {
|
|
|
110
82
|
)) {
|
|
111
83
|
const cluster = svgClusters.get(subGraph.id);
|
|
112
84
|
if (!cluster) continue;
|
|
85
|
+
const id = subGraph.id;
|
|
86
|
+
const kind = "subgraph";
|
|
113
87
|
nodes.push({
|
|
114
|
-
id
|
|
88
|
+
id,
|
|
89
|
+
kind,
|
|
115
90
|
x: cluster.topLeft.x,
|
|
116
91
|
y: cluster.topLeft.y - FRAME_TOP_PAD,
|
|
117
92
|
w: cluster.width,
|
|
118
93
|
h: cluster.height + FRAME_TOP_PAD,
|
|
119
|
-
geo: "rectangle",
|
|
120
94
|
parentId: subGraphParent.get(subGraph.id),
|
|
121
95
|
label: subGraph.title || subGraph.id,
|
|
122
96
|
fill: "semi",
|
|
@@ -130,7 +104,7 @@ function flowchartToBlueprint(layout, vertices, edges, subGraphs, classDefs) {
|
|
|
130
104
|
for (const [id, vertex] of vertices) {
|
|
131
105
|
const svgNode = svgNodes.get(id);
|
|
132
106
|
if (!svgNode) continue;
|
|
133
|
-
const
|
|
107
|
+
const kind = vertex.type ?? "rect";
|
|
134
108
|
const colors = nodeColorMap.get(id) ?? (0, import_colors.parseNodeInlineColor)(vertex.styles);
|
|
135
109
|
let { width: w, height: h } = svgNode;
|
|
136
110
|
if (vertex.type === "circle" || vertex.type === "doublecircle") {
|
|
@@ -138,11 +112,11 @@ function flowchartToBlueprint(layout, vertices, edges, subGraphs, classDefs) {
|
|
|
138
112
|
}
|
|
139
113
|
nodes.push({
|
|
140
114
|
id,
|
|
115
|
+
kind,
|
|
141
116
|
x: svgNode.center.x - w / 2,
|
|
142
117
|
y: svgNode.center.y - h / 2,
|
|
143
118
|
w,
|
|
144
119
|
h,
|
|
145
|
-
geo,
|
|
146
120
|
parentId: nodeToSubGraph.get(id),
|
|
147
121
|
label: vertex.text || void 0,
|
|
148
122
|
...colors?.fillColor && { fill: "solid" },
|
|
@@ -197,6 +171,6 @@ function flowchartToBlueprint(layout, vertices, edges, subGraphs, classDefs) {
|
|
|
197
171
|
const validEdges = blueprintEdges.filter(
|
|
198
172
|
(e) => nodeIds.has(e.startNodeId) && nodeIds.has(e.endNodeId)
|
|
199
173
|
);
|
|
200
|
-
return { nodes, edges: validEdges };
|
|
174
|
+
return { diagramKind: "flowchart", nodes, edges: validEdges };
|
|
201
175
|
}
|
|
202
176
|
//# sourceMappingURL=flowchartDiagram.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/flowchartDiagram.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n\tFlowClass,\n\tFlowEdge,\n\tFlowSubGraph,\n\tFlowVertex,\n} from 'mermaid/dist/diagrams/flowchart/types.js'\nimport { TLArrowShapeArrowheadStyle, TLDefaultDashStyle
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,oBAA4E;AAC5E,wBAOO;AACP,mBAAyD;AAEzD,SAAS,uBAAuB,MAAsD;AACrF,MAAI,CAAC,KAAM,QAAO;AAElB,MAAI,KAAK,SAAS,OAAO,EAAG,QAAO;AACnC,MAAI,KAAK,SAAS,QAAQ,EAAG,QAAO;AACpC,MAAI,KAAK,SAAS,OAAO,EAAG,QAAO;AACnC,MAAI,KAAK,SAAS,MAAM,EAAG,QAAO;AAElC,SAAO;AACR;AAEA,SAAS,
|
|
4
|
+
"sourcesContent": ["import type {\n\tFlowClass,\n\tFlowEdge,\n\tFlowSubGraph,\n\tFlowVertex,\n} from 'mermaid/dist/diagrams/flowchart/types.js'\nimport { TLArrowShapeArrowheadStyle, TLDefaultDashStyle } from 'tldraw'\nimport type {\n\tDiagramMermaidBlueprint,\n\tMermaidBlueprintEdge,\n\tMermaidBlueprintNode,\n} from './blueprint'\nimport { buildClassDefColorMap, parseCssStyles, parseNodeInlineColor } from './colors'\nimport {\n\tbuildNodeCentersFromSvg,\n\tparseAllEdgePointsFromSvg,\n\tparseClustersFromSvg,\n\ttype ParsedDiagramLayout,\n\tparseNodesFromSvg,\n\tscaleLayout,\n} from './svgParsing'\nimport { getArrowBend, LAYOUT_SCALE, orderTopDown } from './utils'\n\nfunction mapEdgeTypeToArrowhead(type: string | undefined): TLArrowShapeArrowheadStyle {\n\tif (!type) return 'arrow'\n\n\tif (type.includes('point')) return 'arrow'\n\tif (type.includes('circle')) return 'dot'\n\tif (type.includes('cross')) return 'bar'\n\tif (type.includes('open')) return 'none'\n\n\treturn 'arrow'\n}\n\nfunction mapEdgeStrokeToDash(stroke: string | undefined): TLDefaultDashStyle {\n\tif (!stroke) return 'solid'\n\tif (stroke === 'dotted') return 'dotted'\n\treturn 'solid'\n}\n\nconst FRAME_TOP_PAD = 14\n\nfunction buildHierarchy(subGraphs: FlowSubGraph[]) {\n\tconst subGraphIds = new Set(subGraphs.map((subGraph) => subGraph.id))\n\tconst nodeToSubGraph = new Map<string, string>()\n\tconst subGraphParent = new Map<string, string>()\n\tfor (const subGraph of subGraphs) {\n\t\tfor (const nodeId of subGraph.nodes) {\n\t\t\tif (subGraphIds.has(nodeId)) {\n\t\t\t\tsubGraphParent.set(nodeId, subGraph.id)\n\t\t\t} else if (!nodeToSubGraph.has(nodeId)) {\n\t\t\t\tnodeToSubGraph.set(nodeId, subGraph.id)\n\t\t\t}\n\t\t}\n\t}\n\treturn { nodeToSubGraph, subGraphParent }\n}\n\n/** Parse flowchart-specific SVG layout data for use by {@link flowchartToBlueprint}. */\nexport function parseFlowchartLayout(root: Element): ParsedDiagramLayout {\n\tconst nodes = parseNodesFromSvg(root, '.node', (domId) => {\n\t\tconst match = domId.match(/^flowchart-(.+)-\\d+$/)\n\t\treturn match ? match[1] : domId\n\t})\n\tconst clusters = parseClustersFromSvg(root, '.cluster')\n\tconst edges = parseAllEdgePointsFromSvg(root, (dataId) => {\n\t\tconst match = dataId.match(/^L_(.+)_([^_]+)_\\d+$/)\n\t\treturn match ? { start: match[1], end: match[2] } : null\n\t})\n\tscaleLayout(nodes, clusters, edges, LAYOUT_SCALE)\n\treturn { nodes, clusters, edges }\n}\n\n/** Convert a parsed Mermaid flowchart into a tldraw blueprint of nodes and edges. */\nexport function flowchartToBlueprint(\n\tlayout: ParsedDiagramLayout,\n\tvertices: Map<string, FlowVertex>,\n\tedges: FlowEdge[],\n\tsubGraphs?: FlowSubGraph[],\n\tclassDefs?: Map<string, FlowClass>\n): DiagramMermaidBlueprint {\n\tconst nodeColorMap = classDefs ? buildClassDefColorMap(classDefs, vertices) : new Map()\n\tconst { nodes: svgNodes, clusters: svgClusters, edges: svgEdges } = layout\n\tconst nodeCenters = buildNodeCentersFromSvg(svgNodes, svgClusters)\n\n\tconst allSubGraphs = subGraphs || []\n\tconst { nodeToSubGraph, subGraphParent } = buildHierarchy(allSubGraphs)\n\n\tconst nodes: MermaidBlueprintNode[] = []\n\tconst blueprintEdges: MermaidBlueprintEdge[] = []\n\n\t// Frames for subgraphs\n\tfor (const subGraph of orderTopDown(\n\t\tallSubGraphs,\n\t\t(subGraph) => subGraph.id,\n\t\t(subGraph) => subGraphParent.get(subGraph.id)\n\t)) {\n\t\tconst cluster = svgClusters.get(subGraph.id)\n\t\tif (!cluster) continue\n\n\t\tconst id = subGraph.id\n\t\tconst kind = 'subgraph'\n\t\tnodes.push({\n\t\t\tid,\n\t\t\tkind,\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: subGraphParent.get(subGraph.id),\n\t\t\tlabel: subGraph.title || subGraph.id,\n\t\t\tfill: 'semi',\n\t\t\tcolor: 'black',\n\t\t\tdash: 'draw',\n\t\t\tsize: 's',\n\t\t\talign: 'middle',\n\t\t\tverticalAlign: 'start',\n\t\t})\n\t}\n\n\t// Node shapes\n\tfor (const [id, vertex] of vertices) {\n\t\tconst svgNode = svgNodes.get(id)\n\t\tif (!svgNode) continue\n\n\t\tconst kind = vertex.type ?? 'rect'\n\t\tconst colors = nodeColorMap.get(id) ?? parseNodeInlineColor(vertex.styles)\n\n\t\tlet { width: w, height: h } = svgNode\n\t\tif (vertex.type === 'circle' || vertex.type === 'doublecircle') {\n\t\t\tw = h = Math.max(w, h)\n\t\t}\n\n\t\tnodes.push({\n\t\t\tid,\n\t\t\tkind,\n\t\t\tx: svgNode.center.x - w / 2,\n\t\t\ty: svgNode.center.y - h / 2,\n\t\t\tw,\n\t\t\th,\n\t\t\tparentId: nodeToSubGraph.get(id),\n\t\t\tlabel: vertex.text || undefined,\n\t\t\t...(colors?.fillColor && { fill: 'solid' as const }),\n\t\t\t...(colors && { color: colors.strokeColor ?? colors.fillColor }),\n\t\t\talign: 'middle',\n\t\t\tverticalAlign: 'middle',\n\t\t\tsize: 'm',\n\t\t})\n\t}\n\n\t// Edges: match DB edges to SVG edges by proximity, compute bends\n\tconst claimed = new Set<number>()\n\tfor (const edge of edges) {\n\t\tconst startCenter = nodeCenters.get(edge.start)\n\t\tconst endCenter = nodeCenters.get(edge.end)\n\n\t\tlet bend = 0\n\t\tif (startCenter && endCenter) {\n\t\t\tlet bestIndex = -1\n\t\t\tlet bestDist = Infinity\n\t\t\tfor (let i = 0; i < svgEdges.length; i++) {\n\t\t\t\tif (claimed.has(i) || svgEdges[i].points.length < 2) continue\n\n\t\t\t\tconst points = svgEdges[i].points\n\t\t\t\tconst distance =\n\t\t\t\t\tMath.hypot(points[0].x - startCenter.x, points[0].y - startCenter.y) +\n\t\t\t\t\tMath.hypot(\n\t\t\t\t\t\tpoints[points.length - 1].x - endCenter.x,\n\t\t\t\t\t\tpoints[points.length - 1].y - endCenter.y\n\t\t\t\t\t)\n\t\t\t\tif (distance < bestDist) {\n\t\t\t\t\tbestDist = distance\n\t\t\t\t\tbestIndex = i\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (bestIndex >= 0) {\n\t\t\t\tclaimed.add(bestIndex)\n\t\t\t\tbend = getArrowBend(svgEdges[bestIndex])\n\t\t\t}\n\t\t}\n\n\t\tconst cssOverrides = edge.style ? parseCssStyles(edge.style) : undefined\n\t\tconst arrowheadEnd = mapEdgeTypeToArrowhead(edge.type)\n\t\tconst dash = cssOverrides?.dashOverride ?? mapEdgeStrokeToDash(edge.stroke)\n\t\tconst size = cssOverrides?.sizeOverride ?? (edge.stroke === 'thick' ? 'l' : 's')\n\n\t\tblueprintEdges.push({\n\t\t\tstartNodeId: edge.start,\n\t\t\tendNodeId: edge.end,\n\t\t\tlabel: edge.text,\n\t\t\tbend,\n\t\t\tarrowheadEnd,\n\t\t\tarrowheadStart: edge.type?.includes('double_arrow') ? arrowheadEnd : undefined,\n\t\t\tdash,\n\t\t\tsize,\n\t\t\tcolor: cssOverrides?.color,\n\t\t})\n\t}\n\n\tconst nodeIds = new Set(nodes.map((n) => n.id))\n\tconst validEdges = blueprintEdges.filter(\n\t\t(e) => nodeIds.has(e.startNodeId) && nodeIds.has(e.endNodeId)\n\t)\n\treturn { diagramKind: 'flowchart', nodes, edges: validEdges }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,oBAA4E;AAC5E,wBAOO;AACP,mBAAyD;AAEzD,SAAS,uBAAuB,MAAsD;AACrF,MAAI,CAAC,KAAM,QAAO;AAElB,MAAI,KAAK,SAAS,OAAO,EAAG,QAAO;AACnC,MAAI,KAAK,SAAS,QAAQ,EAAG,QAAO;AACpC,MAAI,KAAK,SAAS,OAAO,EAAG,QAAO;AACnC,MAAI,KAAK,SAAS,MAAM,EAAG,QAAO;AAElC,SAAO;AACR;AAEA,SAAS,oBAAoB,QAAgD;AAC5E,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,WAAW,SAAU,QAAO;AAChC,SAAO;AACR;AAEA,MAAM,gBAAgB;AAEtB,SAAS,eAAe,WAA2B;AAClD,QAAM,cAAc,IAAI,IAAI,UAAU,IAAI,CAAC,aAAa,SAAS,EAAE,CAAC;AACpE,QAAM,iBAAiB,oBAAI,IAAoB;AAC/C,QAAM,iBAAiB,oBAAI,IAAoB;AAC/C,aAAW,YAAY,WAAW;AACjC,eAAW,UAAU,SAAS,OAAO;AACpC,UAAI,YAAY,IAAI,MAAM,GAAG;AAC5B,uBAAe,IAAI,QAAQ,SAAS,EAAE;AAAA,MACvC,WAAW,CAAC,eAAe,IAAI,MAAM,GAAG;AACvC,uBAAe,IAAI,QAAQ,SAAS,EAAE;AAAA,MACvC;AAAA,IACD;AAAA,EACD;AACA,SAAO,EAAE,gBAAgB,eAAe;AACzC;AAGO,SAAS,qBAAqB,MAAoC;AACxE,QAAM,YAAQ,qCAAkB,MAAM,SAAS,CAAC,UAAU;AACzD,UAAM,QAAQ,MAAM,MAAM,sBAAsB;AAChD,WAAO,QAAQ,MAAM,CAA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aultSizeStyle } from 'tldraw';
|
|
8
8
|
import type { TLDefaultVerticalAlignStyle } from 'tldraw';
|
|
9
9
|
import type { TLGeoShapeGeoStyle } from 'tldraw';
|
|
10
|
+
import type { TLShape } from 'tldraw';
|
|
11
|
+
import type { TLShapeId } from 'tldraw';
|
|
10
12
|
|
|
11
13
|
/** @public */
|
|
12
14
|
export declare interface BlueprintRenderingOptions {
|
|
@@ -15,6 +17,11 @@ export declare interface BlueprintRenderingOptions {
|
|
|
15
17
|
x: number;
|
|
16
18
|
y: number;
|
|
17
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Return a custom {@link MermaidBlueprintNodeRenderSpec} per node, or `undefined` for package defaults.
|
|
22
|
+
* Called from {@link renderBlueprint} for each node (after layout offsets are known).
|
|
23
|
+
*/
|
|
24
|
+
mapNodeToRenderSpec?: MermaidNodeRenderMapper;
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
/**
|
|
@@ -27,20 +34,42 @@ export declare interface BlueprintRenderingOptions {
|
|
|
27
34
|
export declare function createMermaidDiagram(editor: Editor, text: string, options?: MermaidDiagramOptions): Promise<void>;
|
|
28
35
|
|
|
29
36
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
* Creates the tldraw shape for one Mermaid blueprint node using `render` and layout-derived props.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare function defaultCreateMermaidNodeFromBlueprint(args: MermaidNodeCreateFunctionArgs): TLShape;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Default built-in mapping from {@link MermaidDiagramKind} + semantic `kind` to a geo {@link MermaidBlueprintNodeRenderSpec}.
|
|
44
|
+
* Used when `mapNodeToRenderSpec` is omitted from `renderBlueprint` options, or when the mapper returns `undefined`.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare function defaultMermaidNodeRenderSpec(diagramKind: MermaidDiagramKind, kind: string): MermaidBlueprintNodeRenderSpec;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Intermediate representation of a parsed Mermaid diagram: nodes, edges, optional lifelines and groups.
|
|
51
|
+
* Produced by diagram-specific `*ToBlueprint` functions and consumed by {@link renderBlueprint}.
|
|
35
52
|
* @public
|
|
36
53
|
*/
|
|
37
54
|
export declare interface DiagramMermaidBlueprint {
|
|
38
|
-
|
|
55
|
+
diagramKind: MermaidDiagramKind;
|
|
56
|
+
nodes: MermaidBlueprintNode[];
|
|
39
57
|
edges: MermaidBlueprintEdge[];
|
|
40
58
|
lines?: MermaidBlueprintLineNode[];
|
|
41
59
|
groups?: string[][];
|
|
42
60
|
}
|
|
43
61
|
|
|
62
|
+
/** Mermaid mindmap node `type` integers (`kind` on blueprint nodes is `String(type)`). @public */
|
|
63
|
+
export declare const MERMAID_MINDMAP_NODE_TYPE: {
|
|
64
|
+
readonly BANG: 5;
|
|
65
|
+
readonly CIRCLE: 3;
|
|
66
|
+
readonly CLOUD: 4;
|
|
67
|
+
readonly DEFAULT: 0;
|
|
68
|
+
readonly HEXAGON: 6;
|
|
69
|
+
readonly RECT: 2;
|
|
70
|
+
readonly ROUNDED_RECT: 1;
|
|
71
|
+
};
|
|
72
|
+
|
|
44
73
|
/** @public */
|
|
45
74
|
export declare interface MermaidBlueprintEdge {
|
|
46
75
|
startNodeId: string;
|
|
@@ -65,13 +94,32 @@ export declare interface MermaidBlueprintEdge {
|
|
|
65
94
|
}
|
|
66
95
|
|
|
67
96
|
/** @public */
|
|
68
|
-
export declare interface
|
|
97
|
+
export declare interface MermaidBlueprintLineNode {
|
|
98
|
+
id: string;
|
|
99
|
+
x: number;
|
|
100
|
+
y: number;
|
|
101
|
+
endX?: number;
|
|
102
|
+
endY: number;
|
|
103
|
+
dash?: TLDefaultDashStyle;
|
|
104
|
+
size?: TLDefaultSizeStyle;
|
|
105
|
+
color?: TLDefaultColorStyle;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One node in the blueprint: layout and semantic kind from Mermaid (materialization is resolved at {@link renderBlueprint} via `mapNodeToRenderSpec` or defaults).
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export declare interface MermaidBlueprintNode {
|
|
69
113
|
id: string;
|
|
70
114
|
x: number;
|
|
71
115
|
y: number;
|
|
72
116
|
w: number;
|
|
73
117
|
h: number;
|
|
74
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Stable semantic key from Mermaid (flowchart vertex type, `subgraph`, state kind, actor type,
|
|
120
|
+
* internal sequence kinds such as `sequence_note`, mindmap type as decimal string, …).
|
|
121
|
+
*/
|
|
122
|
+
kind: string;
|
|
75
123
|
parentId?: string;
|
|
76
124
|
label?: string;
|
|
77
125
|
fill?: TLDefaultFillStyle;
|
|
@@ -82,17 +130,23 @@ export declare interface MermaidBlueprintGeoNode {
|
|
|
82
130
|
verticalAlign?: TLDefaultVerticalAlignStyle;
|
|
83
131
|
}
|
|
84
132
|
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
size
|
|
94
|
-
|
|
95
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Instructions for creating one blueprint node on the canvas: geo variant or custom shape type + props.
|
|
135
|
+
* Merged with layout-derived props in {@link defaultCreateMermaidNodeFromBlueprint}.
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export declare type MermaidBlueprintNodeRenderSpec = {
|
|
139
|
+
/** Must match `editor.createShape({ type })` — same string as in the app’s shape schema. */
|
|
140
|
+
type: string;
|
|
141
|
+
/** Partial props merged with layout-derived props (size, colors, label text, …) in {@link defaultCreateMermaidNodeFromBlueprint}. */
|
|
142
|
+
props: Record<string, unknown>;
|
|
143
|
+
/** Use any shape type registered on the editor (including custom ShapeUtils). */
|
|
144
|
+
variant: 'shape';
|
|
145
|
+
} | {
|
|
146
|
+
/** Use tldraw’s built-in geo shape; `geo` selects the variant (rectangle, diamond, …). */
|
|
147
|
+
variant: 'geo';
|
|
148
|
+
geo: TLGeoShapeGeoStyle;
|
|
149
|
+
};
|
|
96
150
|
|
|
97
151
|
/** @public */
|
|
98
152
|
export declare class MermaidDiagramError extends Error {
|
|
@@ -101,6 +155,12 @@ export declare class MermaidDiagramError extends Error {
|
|
|
101
155
|
constructor(diagramType: string, type: 'parse' | 'unsupported');
|
|
102
156
|
}
|
|
103
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Which Mermaid diagram family produced this blueprint (used by default geo tables and mapper dispatch).
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
export declare type MermaidDiagramKind = 'flowchart' | 'mindmap' | 'sequence' | 'state';
|
|
163
|
+
|
|
104
164
|
/** @public */
|
|
105
165
|
export declare interface MermaidDiagramOptions {
|
|
106
166
|
mermaidConfig?: Record<string, any>;
|
|
@@ -108,7 +168,46 @@ export declare interface MermaidDiagramOptions {
|
|
|
108
168
|
onUnsupportedDiagram?(svg: string): Promise<void>;
|
|
109
169
|
}
|
|
110
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Arguments for {@link defaultCreateMermaidNodeFromBlueprint}. `x` / `y` are in shape space (parent-relative when
|
|
173
|
+
* `parentShapeId` is set), matching {@link renderBlueprint}.
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
export declare interface MermaidNodeCreateFunctionArgs {
|
|
177
|
+
editor: Editor;
|
|
178
|
+
node: MermaidBlueprintNode;
|
|
179
|
+
shapeId: TLShapeId;
|
|
180
|
+
x: number;
|
|
181
|
+
y: number;
|
|
182
|
+
parentShapeId?: TLShapeId;
|
|
183
|
+
diagramKind: MermaidDiagramKind;
|
|
184
|
+
/** Materialization spec (from {@link resolveMermaidNodeRender} or your mapper). */
|
|
185
|
+
render: MermaidBlueprintNodeRenderSpec;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Optional hook: return a custom render spec for this node, or `undefined` to use the package default mapper.
|
|
190
|
+
* Invoked from {@link renderBlueprint}.
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
export declare type MermaidNodeRenderMapper = (input: {
|
|
194
|
+
/** Blueprint node id (stable binding key). */
|
|
195
|
+
nodeId: string;
|
|
196
|
+
/** Layout and style fields for this node (no materialization spec — that is what you return). */
|
|
197
|
+
node: MermaidBlueprintNode;
|
|
198
|
+
/** Same as {@link DiagramMermaidBlueprint.diagramKind} for this blueprint. */
|
|
199
|
+
diagramKind: MermaidDiagramKind;
|
|
200
|
+
/** Semantic kind for this node in its diagram family. */
|
|
201
|
+
kind: string;
|
|
202
|
+
}) => MermaidBlueprintNodeRenderSpec | undefined;
|
|
203
|
+
|
|
111
204
|
/** @public */
|
|
112
205
|
export declare function renderBlueprint(editor: Editor, blueprint: DiagramMermaidBlueprint, opts?: BlueprintRenderingOptions): void;
|
|
113
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Uses the optional mapper when it returns a value; otherwise {@link defaultMermaidNodeRenderSpec}.
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
export declare function resolveMermaidNodeRender(diagramKind: MermaidDiagramKind, node: MermaidBlueprintNode, mapper?: MermaidNodeRenderMapper | undefined): MermaidBlueprintNodeRenderSpec;
|
|
212
|
+
|
|
114
213
|
export { }
|
package/dist-cjs/index.js
CHANGED
|
@@ -18,17 +18,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var index_exports = {};
|
|
20
20
|
__export(index_exports, {
|
|
21
|
+
MERMAID_MINDMAP_NODE_TYPE: () => import_mindmapDiagram.MERMAID_MINDMAP_NODE_TYPE,
|
|
21
22
|
MermaidDiagramError: () => import_createMermaidDiagram.MermaidDiagramError,
|
|
22
23
|
createMermaidDiagram: () => import_createMermaidDiagram.createMermaidDiagram,
|
|
23
|
-
|
|
24
|
+
defaultCreateMermaidNodeFromBlueprint: () => import_mermaidNodeCreateShape.defaultCreateMermaidNodeFromBlueprint,
|
|
25
|
+
defaultMermaidNodeRenderSpec: () => import_defaultMermaidNodeRenderSpec.defaultMermaidNodeRenderSpec,
|
|
26
|
+
renderBlueprint: () => import_renderBlueprint.renderBlueprint,
|
|
27
|
+
resolveMermaidNodeRender: () => import_defaultMermaidNodeRenderSpec.resolveMermaidNodeRender
|
|
24
28
|
});
|
|
25
29
|
module.exports = __toCommonJS(index_exports);
|
|
26
30
|
var import_utils = require("@tldraw/utils");
|
|
27
31
|
var import_createMermaidDiagram = require("./createMermaidDiagram");
|
|
32
|
+
var import_defaultMermaidNodeRenderSpec = require("./defaultMermaidNodeRenderSpec");
|
|
33
|
+
var import_mindmapDiagram = require("./mindmapDiagram");
|
|
34
|
+
var import_mermaidNodeCreateShape = require("./mermaidNodeCreateShape");
|
|
28
35
|
var import_renderBlueprint = require("./renderBlueprint");
|
|
29
36
|
(0, import_utils.registerTldrawLibraryVersion)(
|
|
30
37
|
"@tldraw/mermaid",
|
|
31
|
-
"4.6.0-next.
|
|
38
|
+
"4.6.0-next.4dde09fa17ab",
|
|
32
39
|
"cjs"
|
|
33
40
|
);
|
|
34
41
|
//# sourceMappingURL=index.js.map
|
package/dist-cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { registerTldrawLibraryVersion } from '@tldraw/utils'\n\nexport type {\n\tDiagramMermaidBlueprint,\n\tMermaidBlueprintEdge,\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;
|
|
4
|
+
"sourcesContent": ["import { registerTldrawLibraryVersion } from '@tldraw/utils'\n\nexport type {\n\tDiagramMermaidBlueprint,\n\tMermaidBlueprintEdge,\n\tMermaidBlueprintLineNode,\n\tMermaidBlueprintNode,\n\tMermaidBlueprintNodeRenderSpec,\n\tMermaidDiagramKind,\n\tMermaidNodeRenderMapper,\n} from './blueprint'\nexport { createMermaidDiagram, MermaidDiagramError } from './createMermaidDiagram'\nexport type { MermaidDiagramOptions } from './createMermaidDiagram'\nexport {\n\tdefaultMermaidNodeRenderSpec,\n\tresolveMermaidNodeRender,\n} from './defaultMermaidNodeRenderSpec'\nexport { MERMAID_MINDMAP_NODE_TYPE } from './mindmapDiagram'\nexport {\n\tdefaultCreateMermaidNodeFromBlueprint,\n\ttype MermaidNodeCreateFunctionArgs,\n} from './mermaidNodeCreateShape'\nexport { renderBlueprint } from './renderBlueprint'\nexport type { BlueprintRenderingOptions } from './renderBlueprint'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;AAW7C,kCAA0D;AAE1D,0CAGO;AACP,4BAA0C;AAC1C,oCAGO;AACP,6BAAgC;AAAA,IAGhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|