merslim 0.1.0
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/LICENSE +21 -0
- package/README.md +266 -0
- package/dist/index.cjs +4349 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +654 -0
- package/dist/index.d.ts +654 -0
- package/dist/index.js +4292 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4349 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dagre2 = require('dagre');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var dagre2__default = /*#__PURE__*/_interopDefault(dagre2);
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __esm = (fn, res) => function __init() {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
};
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
function layoutFlowchart(ir, options = {}) {
|
|
21
|
+
const defaultSize = options.defaultNodeSize ?? { width: 180, height: 60 };
|
|
22
|
+
const nodeSizes = options.nodeSizes ?? /* @__PURE__ */ new Map();
|
|
23
|
+
const nodeSep = options.nodeSeparation ?? 60;
|
|
24
|
+
const rankSep = options.rankSeparation ?? 80;
|
|
25
|
+
const margin = options.margin ?? 24;
|
|
26
|
+
const g = new dagre2__default.default.graphlib.Graph({ multigraph: true, compound: true });
|
|
27
|
+
g.setGraph({
|
|
28
|
+
rankdir: DAGRE_RANK_DIR[ir.direction],
|
|
29
|
+
nodesep: nodeSep,
|
|
30
|
+
ranksep: rankSep,
|
|
31
|
+
marginx: margin,
|
|
32
|
+
marginy: margin
|
|
33
|
+
});
|
|
34
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
35
|
+
const subgraphIds = /* @__PURE__ */ new Set();
|
|
36
|
+
if (ir.subgraphs) {
|
|
37
|
+
for (const sg of ir.subgraphs) {
|
|
38
|
+
g.setNode(sg.id, { label: sg.label, clusterLabelPos: "top" });
|
|
39
|
+
subgraphIds.add(sg.id);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const representativeChild = /* @__PURE__ */ new Map();
|
|
43
|
+
for (const node of ir.nodes) {
|
|
44
|
+
const size = nodeSizes.get(node.id) ?? defaultSize;
|
|
45
|
+
g.setNode(node.id, { ...size, label: node.label });
|
|
46
|
+
if (node.subgraph) {
|
|
47
|
+
g.setParent(node.id, node.subgraph);
|
|
48
|
+
if (!representativeChild.has(node.subgraph)) {
|
|
49
|
+
representativeChild.set(node.subgraph, node.id);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const resolveEndpoint = (id) => {
|
|
54
|
+
if (!subgraphIds.has(id)) return id;
|
|
55
|
+
return representativeChild.get(id) ?? null;
|
|
56
|
+
};
|
|
57
|
+
for (const edge of ir.edges) {
|
|
58
|
+
const source = resolveEndpoint(edge.source);
|
|
59
|
+
const target = resolveEndpoint(edge.target);
|
|
60
|
+
if (!source || !target) continue;
|
|
61
|
+
if (!g.hasNode(source) || !g.hasNode(target)) continue;
|
|
62
|
+
g.setEdge(source, target, edge.label ? { label: edge.label } : {});
|
|
63
|
+
}
|
|
64
|
+
dagre2__default.default.layout(g);
|
|
65
|
+
const nodePositions = /* @__PURE__ */ new Map();
|
|
66
|
+
let maxX = 0;
|
|
67
|
+
let maxY = 0;
|
|
68
|
+
for (const node of ir.nodes) {
|
|
69
|
+
const { x, y } = g.node(node.id);
|
|
70
|
+
const size = nodeSizes.get(node.id) ?? defaultSize;
|
|
71
|
+
const topLeft = { x: x - size.width / 2, y: y - size.height / 2 };
|
|
72
|
+
nodePositions.set(node.id, topLeft);
|
|
73
|
+
maxX = Math.max(maxX, topLeft.x + size.width);
|
|
74
|
+
maxY = Math.max(maxY, topLeft.y + size.height);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
nodePositions,
|
|
78
|
+
width: maxX + margin,
|
|
79
|
+
height: maxY + margin
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
var DAGRE_RANK_DIR;
|
|
83
|
+
var init_dagreLayout = __esm({
|
|
84
|
+
"src/utils/diagrams/layout/dagreLayout.ts"() {
|
|
85
|
+
DAGRE_RANK_DIR = {
|
|
86
|
+
TB: "TB",
|
|
87
|
+
BT: "BT",
|
|
88
|
+
LR: "LR",
|
|
89
|
+
RL: "RL"
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// src/components/diagrams/shared/theme.ts
|
|
95
|
+
function getDiagramTheme(dark) {
|
|
96
|
+
return dark ? DARK : LIGHT;
|
|
97
|
+
}
|
|
98
|
+
var LIGHT, DARK;
|
|
99
|
+
var init_theme = __esm({
|
|
100
|
+
"src/components/diagrams/shared/theme.ts"() {
|
|
101
|
+
LIGHT = {
|
|
102
|
+
canvasBg: "#f8fafc",
|
|
103
|
+
// slate-50
|
|
104
|
+
edgeColor: "#94a3b8",
|
|
105
|
+
// slate-400
|
|
106
|
+
edgeLabel: "#475569",
|
|
107
|
+
// slate-600
|
|
108
|
+
edgeLabelBg: "#ffffff",
|
|
109
|
+
subgraphBg: "rgba(241, 245, 249, 0.5)",
|
|
110
|
+
// slate-100/50
|
|
111
|
+
subgraphBorder: "#cbd5e1",
|
|
112
|
+
// slate-300
|
|
113
|
+
subgraphLabel: "#475569",
|
|
114
|
+
nodeShadow: "rgba(15, 23, 42, 0.08)",
|
|
115
|
+
byKind: {
|
|
116
|
+
service: {
|
|
117
|
+
border: "#86efac",
|
|
118
|
+
headerBg: "#ecfdf5",
|
|
119
|
+
accent: "#10b981",
|
|
120
|
+
bodyBg: "#ffffff",
|
|
121
|
+
text: "#064e3b",
|
|
122
|
+
iconColor: "#10b981"
|
|
123
|
+
},
|
|
124
|
+
database: {
|
|
125
|
+
border: "#fcd34d",
|
|
126
|
+
headerBg: "#fffbeb",
|
|
127
|
+
accent: "#f59e0b",
|
|
128
|
+
bodyBg: "#ffffff",
|
|
129
|
+
text: "#78350f",
|
|
130
|
+
iconColor: "#f59e0b"
|
|
131
|
+
},
|
|
132
|
+
queue: {
|
|
133
|
+
border: "#fda4af",
|
|
134
|
+
headerBg: "#fff1f2",
|
|
135
|
+
accent: "#f43f5e",
|
|
136
|
+
bodyBg: "#ffffff",
|
|
137
|
+
text: "#881337",
|
|
138
|
+
iconColor: "#f43f5e"
|
|
139
|
+
},
|
|
140
|
+
storage: {
|
|
141
|
+
border: "#67e8f9",
|
|
142
|
+
headerBg: "#ecfeff",
|
|
143
|
+
accent: "#06b6d4",
|
|
144
|
+
bodyBg: "#ffffff",
|
|
145
|
+
text: "#164e63",
|
|
146
|
+
iconColor: "#06b6d4"
|
|
147
|
+
},
|
|
148
|
+
user: {
|
|
149
|
+
border: "#93c5fd",
|
|
150
|
+
headerBg: "#eff6ff",
|
|
151
|
+
accent: "#3b82f6",
|
|
152
|
+
bodyBg: "#ffffff",
|
|
153
|
+
text: "#1e3a8a",
|
|
154
|
+
iconColor: "#3b82f6"
|
|
155
|
+
},
|
|
156
|
+
client: {
|
|
157
|
+
border: "#c4b5fd",
|
|
158
|
+
headerBg: "#f5f3ff",
|
|
159
|
+
accent: "#8b5cf6",
|
|
160
|
+
bodyBg: "#ffffff",
|
|
161
|
+
text: "#4c1d95",
|
|
162
|
+
iconColor: "#8b5cf6"
|
|
163
|
+
},
|
|
164
|
+
external: {
|
|
165
|
+
border: "#cbd5e1",
|
|
166
|
+
headerBg: "#f1f5f9",
|
|
167
|
+
accent: "#64748b",
|
|
168
|
+
bodyBg: "#ffffff",
|
|
169
|
+
text: "#334155",
|
|
170
|
+
iconColor: "#64748b"
|
|
171
|
+
},
|
|
172
|
+
process: {
|
|
173
|
+
border: "#bfdbfe",
|
|
174
|
+
headerBg: "#eff6ff",
|
|
175
|
+
accent: "#60a5fa",
|
|
176
|
+
bodyBg: "#ffffff",
|
|
177
|
+
text: "#1e3a8a",
|
|
178
|
+
iconColor: "#60a5fa"
|
|
179
|
+
},
|
|
180
|
+
decision: {
|
|
181
|
+
border: "#c4b5fd",
|
|
182
|
+
headerBg: "#f5f3ff",
|
|
183
|
+
accent: "#8b5cf6",
|
|
184
|
+
bodyBg: "#faf5ff",
|
|
185
|
+
text: "#4c1d95",
|
|
186
|
+
iconColor: "#8b5cf6"
|
|
187
|
+
},
|
|
188
|
+
start: {
|
|
189
|
+
border: "#86efac",
|
|
190
|
+
headerBg: "#ecfdf5",
|
|
191
|
+
accent: "#10b981",
|
|
192
|
+
bodyBg: "#ffffff",
|
|
193
|
+
text: "#064e3b",
|
|
194
|
+
iconColor: "#10b981"
|
|
195
|
+
},
|
|
196
|
+
end: {
|
|
197
|
+
border: "#fda4af",
|
|
198
|
+
headerBg: "#fff1f2",
|
|
199
|
+
accent: "#f43f5e",
|
|
200
|
+
bodyBg: "#ffffff",
|
|
201
|
+
text: "#881337",
|
|
202
|
+
iconColor: "#f43f5e"
|
|
203
|
+
},
|
|
204
|
+
icon: {
|
|
205
|
+
border: "#cbd5e1",
|
|
206
|
+
headerBg: "#ffffff",
|
|
207
|
+
accent: "#64748b",
|
|
208
|
+
bodyBg: "#ffffff",
|
|
209
|
+
text: "#1e293b",
|
|
210
|
+
iconColor: "#64748b"
|
|
211
|
+
},
|
|
212
|
+
plain: {
|
|
213
|
+
border: "#cbd5e1",
|
|
214
|
+
headerBg: "#f8fafc",
|
|
215
|
+
accent: "#64748b",
|
|
216
|
+
bodyBg: "#ffffff",
|
|
217
|
+
text: "#1e293b",
|
|
218
|
+
iconColor: "#64748b"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
DARK = {
|
|
223
|
+
canvasBg: "#0f172a",
|
|
224
|
+
edgeColor: "#64748b",
|
|
225
|
+
edgeLabel: "#cbd5e1",
|
|
226
|
+
edgeLabelBg: "#1e293b",
|
|
227
|
+
subgraphBg: "rgba(30, 41, 59, 0.5)",
|
|
228
|
+
subgraphBorder: "#475569",
|
|
229
|
+
subgraphLabel: "#94a3b8",
|
|
230
|
+
nodeShadow: "rgba(0, 0, 0, 0.30)",
|
|
231
|
+
byKind: {
|
|
232
|
+
service: {
|
|
233
|
+
border: "#10b981",
|
|
234
|
+
headerBg: "rgba(16, 185, 129, 0.12)",
|
|
235
|
+
accent: "#34d399",
|
|
236
|
+
bodyBg: "#1e293b",
|
|
237
|
+
text: "#a7f3d0",
|
|
238
|
+
iconColor: "#34d399"
|
|
239
|
+
},
|
|
240
|
+
database: {
|
|
241
|
+
border: "#f59e0b",
|
|
242
|
+
headerBg: "rgba(245, 158, 11, 0.12)",
|
|
243
|
+
accent: "#fbbf24",
|
|
244
|
+
bodyBg: "#1e293b",
|
|
245
|
+
text: "#fde68a",
|
|
246
|
+
iconColor: "#fbbf24"
|
|
247
|
+
},
|
|
248
|
+
queue: {
|
|
249
|
+
border: "#f43f5e",
|
|
250
|
+
headerBg: "rgba(244, 63, 94, 0.12)",
|
|
251
|
+
accent: "#fb7185",
|
|
252
|
+
bodyBg: "#1e293b",
|
|
253
|
+
text: "#fecdd3",
|
|
254
|
+
iconColor: "#fb7185"
|
|
255
|
+
},
|
|
256
|
+
storage: {
|
|
257
|
+
border: "#06b6d4",
|
|
258
|
+
headerBg: "rgba(6, 182, 212, 0.12)",
|
|
259
|
+
accent: "#22d3ee",
|
|
260
|
+
bodyBg: "#1e293b",
|
|
261
|
+
text: "#a5f3fc",
|
|
262
|
+
iconColor: "#22d3ee"
|
|
263
|
+
},
|
|
264
|
+
user: {
|
|
265
|
+
border: "#3b82f6",
|
|
266
|
+
headerBg: "rgba(59, 130, 246, 0.12)",
|
|
267
|
+
accent: "#60a5fa",
|
|
268
|
+
bodyBg: "#1e293b",
|
|
269
|
+
text: "#bfdbfe",
|
|
270
|
+
iconColor: "#60a5fa"
|
|
271
|
+
},
|
|
272
|
+
client: {
|
|
273
|
+
border: "#8b5cf6",
|
|
274
|
+
headerBg: "rgba(139, 92, 246, 0.12)",
|
|
275
|
+
accent: "#a78bfa",
|
|
276
|
+
bodyBg: "#1e293b",
|
|
277
|
+
text: "#ddd6fe",
|
|
278
|
+
iconColor: "#a78bfa"
|
|
279
|
+
},
|
|
280
|
+
external: {
|
|
281
|
+
border: "#64748b",
|
|
282
|
+
headerBg: "rgba(100, 116, 139, 0.12)",
|
|
283
|
+
accent: "#94a3b8",
|
|
284
|
+
bodyBg: "#1e293b",
|
|
285
|
+
text: "#cbd5e1",
|
|
286
|
+
iconColor: "#94a3b8"
|
|
287
|
+
},
|
|
288
|
+
process: {
|
|
289
|
+
border: "#60a5fa",
|
|
290
|
+
headerBg: "rgba(96, 165, 250, 0.12)",
|
|
291
|
+
accent: "#93c5fd",
|
|
292
|
+
bodyBg: "#1e293b",
|
|
293
|
+
text: "#bfdbfe",
|
|
294
|
+
iconColor: "#93c5fd"
|
|
295
|
+
},
|
|
296
|
+
decision: {
|
|
297
|
+
border: "#8b5cf6",
|
|
298
|
+
headerBg: "rgba(139, 92, 246, 0.12)",
|
|
299
|
+
accent: "#a78bfa",
|
|
300
|
+
bodyBg: "#1e293b",
|
|
301
|
+
text: "#ddd6fe",
|
|
302
|
+
iconColor: "#a78bfa"
|
|
303
|
+
},
|
|
304
|
+
start: {
|
|
305
|
+
border: "#10b981",
|
|
306
|
+
headerBg: "rgba(16, 185, 129, 0.12)",
|
|
307
|
+
accent: "#34d399",
|
|
308
|
+
bodyBg: "#1e293b",
|
|
309
|
+
text: "#a7f3d0",
|
|
310
|
+
iconColor: "#34d399"
|
|
311
|
+
},
|
|
312
|
+
end: {
|
|
313
|
+
border: "#f43f5e",
|
|
314
|
+
headerBg: "rgba(244, 63, 94, 0.12)",
|
|
315
|
+
accent: "#fb7185",
|
|
316
|
+
bodyBg: "#1e293b",
|
|
317
|
+
text: "#fecdd3",
|
|
318
|
+
iconColor: "#fb7185"
|
|
319
|
+
},
|
|
320
|
+
icon: {
|
|
321
|
+
border: "#475569",
|
|
322
|
+
headerBg: "#1e293b",
|
|
323
|
+
accent: "#94a3b8",
|
|
324
|
+
bodyBg: "#1e293b",
|
|
325
|
+
text: "#e2e8f0",
|
|
326
|
+
iconColor: "#94a3b8"
|
|
327
|
+
},
|
|
328
|
+
plain: {
|
|
329
|
+
border: "#475569",
|
|
330
|
+
headerBg: "#1e293b",
|
|
331
|
+
accent: "#94a3b8",
|
|
332
|
+
bodyBg: "#1e293b",
|
|
333
|
+
text: "#e2e8f0",
|
|
334
|
+
iconColor: "#94a3b8"
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
function escXml(s) {
|
|
341
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
342
|
+
}
|
|
343
|
+
function palette(dark) {
|
|
344
|
+
return {
|
|
345
|
+
common: dark ? DARK_COMMON : LIGHT_COMMON,
|
|
346
|
+
byKind: dark ? DARK_KIND : LIGHT_KIND
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function flowchartNodeSize(node) {
|
|
350
|
+
if (node.kind === "user" || node.kind === "start" || node.kind === "end") {
|
|
351
|
+
return { width: 84, height: 84 };
|
|
352
|
+
}
|
|
353
|
+
if (node.kind === "icon") return { width: 100, height: 96 };
|
|
354
|
+
if (node.kind === "decision") {
|
|
355
|
+
const len2 = node.label.length;
|
|
356
|
+
return {
|
|
357
|
+
width: Math.max(140, Math.min(280, len2 * 11 + 60)),
|
|
358
|
+
height: Math.max(96, Math.min(160, Math.ceil(len2 / 16) * 32 + 64))
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
if (node.kind === "queue") return { width: 220, height: 64 };
|
|
362
|
+
const len = node.label.length;
|
|
363
|
+
const lines = Math.max(1, Math.ceil(len / 24));
|
|
364
|
+
return {
|
|
365
|
+
width: Math.max(160, Math.min(320, len * 8 + 40)),
|
|
366
|
+
height: 48 + (lines - 1) * 18
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function wrapText(text, maxChars) {
|
|
370
|
+
if (text.length <= maxChars) return [text];
|
|
371
|
+
const words = text.split(/\s+/);
|
|
372
|
+
const lines = [];
|
|
373
|
+
let line = "";
|
|
374
|
+
for (const w of words) {
|
|
375
|
+
if ((line + " " + w).trim().length > maxChars && line) {
|
|
376
|
+
lines.push(line);
|
|
377
|
+
line = w;
|
|
378
|
+
} else {
|
|
379
|
+
line = (line + " " + w).trim();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (line) lines.push(line);
|
|
383
|
+
return lines;
|
|
384
|
+
}
|
|
385
|
+
function tspans(lines, x, lineHeight) {
|
|
386
|
+
return lines.map((l, i) => `<tspan x="${x}" dy="${i === 0 ? 0 : lineHeight}">${escXml(l)}</tspan>`).join("");
|
|
387
|
+
}
|
|
388
|
+
function attachPoint(box, towards) {
|
|
389
|
+
const cx = box.x + box.width / 2;
|
|
390
|
+
const cy = box.y + box.height / 2;
|
|
391
|
+
const dx = towards.x - cx;
|
|
392
|
+
const dy = towards.y - cy;
|
|
393
|
+
if (dx === 0 && dy === 0) return { x: cx, y: cy };
|
|
394
|
+
const halfW = box.width / 2;
|
|
395
|
+
const halfH = box.height / 2;
|
|
396
|
+
const tx = Math.abs(dx) > 0 ? halfW / Math.abs(dx) : Infinity;
|
|
397
|
+
const ty = Math.abs(dy) > 0 ? halfH / Math.abs(dy) : Infinity;
|
|
398
|
+
const t = Math.min(tx, ty);
|
|
399
|
+
return { x: cx + dx * t, y: cy + dy * t };
|
|
400
|
+
}
|
|
401
|
+
function arrowDef(id, color) {
|
|
402
|
+
return `<marker id="${id}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M 0 0 L 10 5 L 0 10 z" fill="${color}"/></marker>`;
|
|
403
|
+
}
|
|
404
|
+
function svgOpen(viewX, viewY, w, h, bg, title) {
|
|
405
|
+
const label = (title ?? "Diagram").trim() || "Diagram";
|
|
406
|
+
const titleEl = `<title>${escXml(label)}</title>`;
|
|
407
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="${viewX} ${viewY} ${w} ${h}" width="${w}" height="${h}" font-family='${FONT_FAMILY}' role="img" aria-label="${escXml(label)}">${titleEl}<rect x="${viewX}" y="${viewY}" width="${w}" height="${h}" fill="${bg}"/>`;
|
|
408
|
+
}
|
|
409
|
+
function buildFlowchartSvg(ir, positions, options = {}) {
|
|
410
|
+
const { common, byKind } = palette(options.dark ?? false);
|
|
411
|
+
const padding = options.padding ?? 40;
|
|
412
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
413
|
+
for (const node of ir.nodes) {
|
|
414
|
+
const pos = positions.get(node.id);
|
|
415
|
+
if (!pos) continue;
|
|
416
|
+
const size = flowchartNodeSize(node);
|
|
417
|
+
boxes.set(node.id, { x: pos.x, y: pos.y, width: size.width, height: size.height });
|
|
418
|
+
}
|
|
419
|
+
if (boxes.size === 0) return svgOpen(0, 0, 100, 100, common.canvasBg) + "</svg>";
|
|
420
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
421
|
+
for (const b of boxes.values()) {
|
|
422
|
+
minX = Math.min(minX, b.x);
|
|
423
|
+
minY = Math.min(minY, b.y);
|
|
424
|
+
maxX = Math.max(maxX, b.x + b.width);
|
|
425
|
+
maxY = Math.max(maxY, b.y + b.height);
|
|
426
|
+
}
|
|
427
|
+
minX -= padding;
|
|
428
|
+
minY -= padding;
|
|
429
|
+
maxX += padding;
|
|
430
|
+
maxY += padding;
|
|
431
|
+
const width = Math.round(maxX - minX);
|
|
432
|
+
const height = Math.round(maxY - minY);
|
|
433
|
+
const parts = [];
|
|
434
|
+
parts.push(svgOpen(minX, minY, width, height, common.canvasBg, "Flowchart diagram"));
|
|
435
|
+
parts.push(`<defs>${arrowDef("arr", common.edgeColor)}</defs>`);
|
|
436
|
+
for (const e of ir.edges) {
|
|
437
|
+
const a = boxes.get(e.source);
|
|
438
|
+
const b = boxes.get(e.target);
|
|
439
|
+
if (!a || !b) continue;
|
|
440
|
+
parts.push(buildEdgePath(a, b, e, common));
|
|
441
|
+
}
|
|
442
|
+
for (const node of ir.nodes) {
|
|
443
|
+
const box = boxes.get(node.id);
|
|
444
|
+
if (!box) continue;
|
|
445
|
+
parts.push(buildFlowNode(node, box, byKind[node.kind]));
|
|
446
|
+
}
|
|
447
|
+
parts.push("</svg>");
|
|
448
|
+
return parts.join("");
|
|
449
|
+
}
|
|
450
|
+
function buildEdgePath(a, b, edge, common) {
|
|
451
|
+
const ac = { x: a.x + a.width / 2, y: a.y + a.height / 2 };
|
|
452
|
+
const bc = { x: b.x + b.width / 2, y: b.y + b.height / 2 };
|
|
453
|
+
const p1 = attachPoint(a, bc);
|
|
454
|
+
const p2 = attachPoint(b, ac);
|
|
455
|
+
const dx = Math.abs(p2.x - p1.x);
|
|
456
|
+
const dy = Math.abs(p2.y - p1.y);
|
|
457
|
+
const horizontal = dx > dy;
|
|
458
|
+
const cp = Math.max(30, (horizontal ? dx : dy) * 0.45);
|
|
459
|
+
const c1 = horizontal ? { x: p1.x + Math.sign(p2.x - p1.x) * cp, y: p1.y } : { x: p1.x, y: p1.y + Math.sign(p2.y - p1.y) * cp };
|
|
460
|
+
const c2 = horizontal ? { x: p2.x - Math.sign(p2.x - p1.x) * cp, y: p2.y } : { x: p2.x, y: p2.y - Math.sign(p2.y - p1.y) * cp };
|
|
461
|
+
const dash = edge.kind === "dashed" ? ' stroke-dasharray="6 4"' : edge.kind === "dotted" ? ' stroke-dasharray="2 3"' : "";
|
|
462
|
+
const sw = edge.kind === "thick" ? 2.5 : 1.5;
|
|
463
|
+
const path = `<path d="M ${p1.x} ${p1.y} C ${c1.x} ${c1.y}, ${c2.x} ${c2.y}, ${p2.x} ${p2.y}" stroke="${common.edgeColor}" stroke-width="${sw}" fill="none"${dash} marker-end="url(#arr)"/>`;
|
|
464
|
+
if (!edge.label) return path;
|
|
465
|
+
const lx = 0.125 * p1.x + 0.375 * c1.x + 0.375 * c2.x + 0.125 * p2.x;
|
|
466
|
+
const ly = 0.125 * p1.y + 0.375 * c1.y + 0.375 * c2.y + 0.125 * p2.y;
|
|
467
|
+
const text = escXml(edge.label);
|
|
468
|
+
const w = text.length * 6.5 + 12;
|
|
469
|
+
return path + `<rect x="${lx - w / 2}" y="${ly - 9}" width="${w}" height="16" fill="${common.edgeLabelBg}" rx="3"/><text x="${lx}" y="${ly + 3}" text-anchor="middle" font-size="11" font-weight="500" fill="${common.edgeLabel}">${text}</text>`;
|
|
470
|
+
}
|
|
471
|
+
function buildFlowNode(node, box, c) {
|
|
472
|
+
const cx = box.x + box.width / 2;
|
|
473
|
+
const cy = box.y + box.height / 2;
|
|
474
|
+
if (node.kind === "decision") {
|
|
475
|
+
const left = box.x, right = box.x + box.width, top = box.y, bottom = box.y + box.height;
|
|
476
|
+
const points = `${cx},${top} ${right},${cy} ${cx},${bottom} ${left},${cy}`;
|
|
477
|
+
const lines2 = wrapText(node.label, 18);
|
|
478
|
+
return `<polygon points="${points}" fill="${c.bodyBg}" stroke="${c.accent}" stroke-width="1.5"/><text x="${cx}" y="${cy - (lines2.length - 1) * 7}" text-anchor="middle" font-size="12" font-weight="600" fill="${c.text}">${tspans(lines2, cx, 14)}</text>`;
|
|
479
|
+
}
|
|
480
|
+
if (node.kind === "database") {
|
|
481
|
+
const rx = box.width / 2;
|
|
482
|
+
const ry = 8;
|
|
483
|
+
const top = box.y;
|
|
484
|
+
const bottom = box.y + box.height;
|
|
485
|
+
const path = `M ${box.x} ${top + ry} A ${rx} ${ry} 0 0 0 ${box.x + box.width} ${top + ry} L ${box.x + box.width} ${bottom - ry} A ${rx} ${ry} 0 0 1 ${box.x} ${bottom - ry} Z`;
|
|
486
|
+
const ellipse = `<ellipse cx="${cx}" cy="${top + ry}" rx="${rx}" ry="${ry}" fill="none" stroke="${c.accent}" stroke-width="2"/>`;
|
|
487
|
+
return `<path d="${path}" fill="${c.bodyBg}" stroke="${c.border}" stroke-width="1"/>` + ellipse + `<text x="${cx}" y="${cy + 6}" text-anchor="middle" font-size="13" font-weight="500" fill="${c.text}">${escXml(node.label)}</text>`;
|
|
488
|
+
}
|
|
489
|
+
if (node.kind === "user" || node.kind === "start" || node.kind === "end") {
|
|
490
|
+
const r = Math.min(box.width, box.height) / 2;
|
|
491
|
+
const lines2 = wrapText(node.label, 12);
|
|
492
|
+
return `<circle cx="${cx}" cy="${cy}" r="${r}" fill="${c.bodyBg}" stroke="${c.accent}" stroke-width="2"/><text x="${cx}" y="${cy + 4 - (lines2.length - 1) * 7}" text-anchor="middle" font-size="12" font-weight="600" fill="${c.text}">${tspans(lines2, cx, 14)}</text>`;
|
|
493
|
+
}
|
|
494
|
+
if (node.kind === "queue") {
|
|
495
|
+
return `<rect x="${box.x}" y="${box.y}" width="${box.width}" height="${box.height}" rx="8" fill="${c.bodyBg}" stroke="${c.accent}" stroke-width="1"/><rect x="${box.x + 4}" y="${box.y + 4}" width="${box.width - 8}" height="${box.height - 8}" rx="5" fill="none" stroke="${c.border}" stroke-width="1"/><text x="${cx}" y="${cy + 5}" text-anchor="middle" font-size="13" font-weight="500" fill="${c.text}">${escXml(node.label)}</text>`;
|
|
496
|
+
}
|
|
497
|
+
const lines = wrapText(node.label, 24);
|
|
498
|
+
return `<rect x="${box.x}" y="${box.y}" width="${box.width}" height="${box.height}" rx="10" fill="${c.bodyBg}" stroke="${c.border}" stroke-width="1"/><rect x="${box.x}" y="${box.y}" width="4" height="${box.height}" fill="${c.accent}"/><text x="${cx}" y="${cy + 4 - (lines.length - 1) * 8}" text-anchor="middle" font-size="13" font-weight="500" fill="${c.text}">${tspans(lines, cx, 16)}</text>`;
|
|
499
|
+
}
|
|
500
|
+
function buildStateSvg(ir, positions, options = {}) {
|
|
501
|
+
const { common } = palette(options.dark ?? false);
|
|
502
|
+
const dark = options.dark ?? false;
|
|
503
|
+
const padding = options.padding ?? 40;
|
|
504
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
505
|
+
for (const [id, p] of positions.topLevel) {
|
|
506
|
+
boxes.set(id, p);
|
|
507
|
+
}
|
|
508
|
+
for (const [id, p] of positions.children) {
|
|
509
|
+
const parent = boxes.get(p.parent);
|
|
510
|
+
if (!parent) continue;
|
|
511
|
+
boxes.set(id, { x: parent.x + p.x, y: parent.y + p.y, width: p.width, height: p.height });
|
|
512
|
+
}
|
|
513
|
+
if (boxes.size === 0) return svgOpen(0, 0, 100, 100, common.canvasBg) + "</svg>";
|
|
514
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
515
|
+
for (const b of boxes.values()) {
|
|
516
|
+
minX = Math.min(minX, b.x);
|
|
517
|
+
minY = Math.min(minY, b.y);
|
|
518
|
+
maxX = Math.max(maxX, b.x + b.width);
|
|
519
|
+
maxY = Math.max(maxY, b.y + b.height);
|
|
520
|
+
}
|
|
521
|
+
minX -= padding;
|
|
522
|
+
minY -= padding;
|
|
523
|
+
maxX += padding;
|
|
524
|
+
maxY += padding;
|
|
525
|
+
const width = Math.round(maxX - minX);
|
|
526
|
+
const height = Math.round(maxY - minY);
|
|
527
|
+
const parts = [];
|
|
528
|
+
parts.push(svgOpen(minX, minY, width, height, common.canvasBg, "State diagram"));
|
|
529
|
+
parts.push(`<defs>${arrowDef("arr", common.edgeColor)}</defs>`);
|
|
530
|
+
for (const s of ir.states) {
|
|
531
|
+
if (s.kind !== "composite") continue;
|
|
532
|
+
const box = boxes.get(s.id);
|
|
533
|
+
if (!box) continue;
|
|
534
|
+
parts.push(
|
|
535
|
+
`<rect x="${box.x}" y="${box.y}" width="${box.width}" height="${box.height}" rx="14" fill="${dark ? "rgba(15,23,42,0.5)" : "#ffffff"}" stroke="${common.border}" stroke-width="1.5"/><rect x="${box.x}" y="${box.y}" width="${box.width}" height="32" rx="14" fill="${dark ? "#1e293b" : "#f1f5f9"}"/><rect x="${box.x}" y="${box.y + 18}" width="${box.width}" height="14" fill="${dark ? "#1e293b" : "#f1f5f9"}"/><line x1="${box.x}" y1="${box.y + 32}" x2="${box.x + box.width}" y2="${box.y + 32}" stroke="${common.border}" stroke-width="1"/><text x="${box.x + box.width / 2}" y="${box.y + 21}" text-anchor="middle" font-size="13" font-weight="600" fill="${common.text}">${escXml(s.label || s.id)}</text>`
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
for (const t of ir.transitions) {
|
|
539
|
+
const a = boxes.get(t.source);
|
|
540
|
+
const b = boxes.get(t.target);
|
|
541
|
+
if (!a || !b) continue;
|
|
542
|
+
parts.push(buildEdgePath(a, b, { source: t.source, target: t.target, label: t.label, kind: "solid" }, common));
|
|
543
|
+
}
|
|
544
|
+
for (const s of ir.states) {
|
|
545
|
+
if (s.kind === "composite") continue;
|
|
546
|
+
const box = boxes.get(s.id);
|
|
547
|
+
if (!box) continue;
|
|
548
|
+
parts.push(buildStateBox(s, box, common, dark));
|
|
549
|
+
}
|
|
550
|
+
parts.push("</svg>");
|
|
551
|
+
return parts.join("");
|
|
552
|
+
}
|
|
553
|
+
function buildStateBox(s, box, common, dark) {
|
|
554
|
+
if (s.kind === "start" || s.kind === "end") {
|
|
555
|
+
const cx2 = box.x + box.width / 2;
|
|
556
|
+
const cy2 = box.y + box.height / 2;
|
|
557
|
+
const r = 12;
|
|
558
|
+
const fill = s.kind === "start" ? dark ? "#e2e8f0" : "#0f172a" : dark ? "#0f172a" : "#ffffff";
|
|
559
|
+
const stroke = dark ? "#e2e8f0" : "#0f172a";
|
|
560
|
+
const inner = s.kind === "end" ? `<circle cx="${cx2}" cy="${cy2}" r="${r - 4}" fill="${dark ? "#e2e8f0" : "#0f172a"}"/>` : "";
|
|
561
|
+
return `<circle cx="${cx2}" cy="${cy2}" r="${r}" fill="${fill}" stroke="${stroke}" stroke-width="2"/>${inner}`;
|
|
562
|
+
}
|
|
563
|
+
const cx = box.x + box.width / 2;
|
|
564
|
+
const cy = box.y + box.height / 2;
|
|
565
|
+
return `<rect x="${box.x}" y="${box.y}" width="${box.width}" height="${box.height}" rx="14" fill="${dark ? "#1e293b" : "#ffffff"}" stroke="${common.border}" stroke-width="1.5"/><text x="${cx}" y="${cy + 5}" text-anchor="middle" font-size="13" font-weight="500" fill="${common.text}">${escXml(s.label || s.id)}</text>`;
|
|
566
|
+
}
|
|
567
|
+
function buildClassSvg(ir, positions, options = {}) {
|
|
568
|
+
const { common } = palette(options.dark ?? false);
|
|
569
|
+
const dark = options.dark ?? false;
|
|
570
|
+
const padding = options.padding ?? 40;
|
|
571
|
+
if (positions.size === 0) return svgOpen(0, 0, 100, 100, common.canvasBg) + "</svg>";
|
|
572
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
573
|
+
for (const p of positions.values()) {
|
|
574
|
+
minX = Math.min(minX, p.x);
|
|
575
|
+
minY = Math.min(minY, p.y);
|
|
576
|
+
maxX = Math.max(maxX, p.x + p.width);
|
|
577
|
+
maxY = Math.max(maxY, p.y + p.height);
|
|
578
|
+
}
|
|
579
|
+
minX -= padding;
|
|
580
|
+
minY -= padding;
|
|
581
|
+
maxX += padding;
|
|
582
|
+
maxY += padding;
|
|
583
|
+
const width = Math.round(maxX - minX);
|
|
584
|
+
const height = Math.round(maxY - minY);
|
|
585
|
+
const parts = [];
|
|
586
|
+
parts.push(svgOpen(minX, minY, width, height, common.canvasBg, "Class diagram"));
|
|
587
|
+
parts.push(`<defs>${arrowDef("arr", common.edgeColor)}</defs>`);
|
|
588
|
+
for (const rel of ir.relations) {
|
|
589
|
+
const a = positions.get(rel.source);
|
|
590
|
+
const b = positions.get(rel.target);
|
|
591
|
+
if (!a || !b) continue;
|
|
592
|
+
const aBox = { x: a.x, y: a.y, width: a.width, height: a.height };
|
|
593
|
+
const bBox = { x: b.x, y: b.y, width: b.width, height: b.height };
|
|
594
|
+
const dashed = rel.kind === "dependency" || rel.kind === "realization";
|
|
595
|
+
parts.push(buildEdgePath(aBox, bBox, { source: rel.source, target: rel.target, label: rel.label, kind: dashed ? "dashed" : "solid" }, common));
|
|
596
|
+
}
|
|
597
|
+
for (const cls of ir.classes) {
|
|
598
|
+
const p = positions.get(cls.id);
|
|
599
|
+
if (!p) continue;
|
|
600
|
+
parts.push(buildClassNode(cls, p, common, dark));
|
|
601
|
+
}
|
|
602
|
+
parts.push("</svg>");
|
|
603
|
+
return parts.join("");
|
|
604
|
+
}
|
|
605
|
+
function buildClassNode(cls, p, common, dark) {
|
|
606
|
+
const headerH = 30;
|
|
607
|
+
const rowH = 18;
|
|
608
|
+
const attrs = cls.members.filter((m) => m.kind === "attribute");
|
|
609
|
+
const methods = cls.members.filter((m) => m.kind === "method");
|
|
610
|
+
const parts = [];
|
|
611
|
+
parts.push(`<g transform="translate(${p.x},${p.y})">`);
|
|
612
|
+
parts.push(`<rect width="${p.width}" height="${p.height}" rx="8" fill="${dark ? "#0f172a" : "#ffffff"}" stroke="${common.border}" stroke-width="1"/>`);
|
|
613
|
+
parts.push(`<rect width="${p.width}" height="${headerH}" rx="8" fill="${dark ? "#1e293b" : "#f1f5f9"}"/>`);
|
|
614
|
+
parts.push(`<rect y="${headerH - 8}" width="${p.width}" height="8" fill="${dark ? "#1e293b" : "#f1f5f9"}"/>`);
|
|
615
|
+
parts.push(`<line x1="0" y1="${headerH}" x2="${p.width}" y2="${headerH}" stroke="${common.border}"/>`);
|
|
616
|
+
parts.push(`<text x="${p.width / 2}" y="${headerH / 2 + 5}" text-anchor="middle" font-size="13" font-weight="600" fill="${common.text}">${escXml(cls.label)}</text>`);
|
|
617
|
+
let y = headerH + 14;
|
|
618
|
+
for (const m of attrs) {
|
|
619
|
+
parts.push(buildClassMember(m, y, p.width, common));
|
|
620
|
+
y += rowH;
|
|
621
|
+
}
|
|
622
|
+
if (attrs.length > 0 && methods.length > 0) {
|
|
623
|
+
parts.push(`<line x1="6" y1="${y - 6}" x2="${p.width - 6}" y2="${y - 6}" stroke="${common.border}" stroke-dasharray="3 2"/>`);
|
|
624
|
+
y += 4;
|
|
625
|
+
}
|
|
626
|
+
for (const m of methods) {
|
|
627
|
+
parts.push(buildClassMember(m, y, p.width, common));
|
|
628
|
+
y += rowH;
|
|
629
|
+
}
|
|
630
|
+
parts.push("</g>");
|
|
631
|
+
return parts.join("");
|
|
632
|
+
}
|
|
633
|
+
function buildClassMember(m, y, width, common) {
|
|
634
|
+
const sym = m.visibility ? VIS_SYMBOL[m.visibility] ?? "" : "";
|
|
635
|
+
const sig = m.kind === "method" ? `${m.name}(${m.parameters ?? ""})${m.returnType ? `: ${m.returnType}` : ""}` : `${m.name}${m.returnType ? `: ${m.returnType}` : ""}`;
|
|
636
|
+
return `<text x="10" y="${y}" font-family='${MONO_FAMILY}' font-size="11" fill="${common.subtle}">${escXml(sym)}</text><text x="22" y="${y}" font-family='${MONO_FAMILY}' font-size="11" fill="${common.text}">${escXml(sig.length > 32 ? sig.slice(0, 31) + "\u2026" : sig)}</text>`;
|
|
637
|
+
}
|
|
638
|
+
function buildErSvg(ir, positions, options = {}) {
|
|
639
|
+
const { common } = palette(options.dark ?? false);
|
|
640
|
+
const dark = options.dark ?? false;
|
|
641
|
+
const padding = options.padding ?? 40;
|
|
642
|
+
const HEADER_H = 34;
|
|
643
|
+
const ROW_H = 26;
|
|
644
|
+
if (positions.size === 0) return svgOpen(0, 0, 100, 100, common.canvasBg) + "</svg>";
|
|
645
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
646
|
+
for (const p of positions.values()) {
|
|
647
|
+
minX = Math.min(minX, p.x);
|
|
648
|
+
minY = Math.min(minY, p.y);
|
|
649
|
+
maxX = Math.max(maxX, p.x + p.width);
|
|
650
|
+
maxY = Math.max(maxY, p.y + p.height);
|
|
651
|
+
}
|
|
652
|
+
minX -= padding;
|
|
653
|
+
minY -= padding;
|
|
654
|
+
maxX += padding;
|
|
655
|
+
maxY += padding;
|
|
656
|
+
const width = Math.round(maxX - minX);
|
|
657
|
+
const height = Math.round(maxY - minY);
|
|
658
|
+
const parts = [];
|
|
659
|
+
parts.push(svgOpen(minX, minY, width, height, common.canvasBg, "Entity-relationship diagram"));
|
|
660
|
+
parts.push(`<defs>${arrowDef("arr", common.edgeColor)}</defs>`);
|
|
661
|
+
for (const rel of ir.schema.relations) {
|
|
662
|
+
const fromTable = ir.schema.tables.find((t) => t.name === rel.fromTable);
|
|
663
|
+
const toTable = ir.schema.tables.find((t) => t.name === rel.toTable);
|
|
664
|
+
if (!fromTable || !toTable) continue;
|
|
665
|
+
const fromPos = positions.get(rel.fromTable);
|
|
666
|
+
const toPos = positions.get(rel.toTable);
|
|
667
|
+
if (!fromPos || !toPos) continue;
|
|
668
|
+
const fromColIdx = fromTable.columns.findIndex((c) => c.name === rel.fromCol);
|
|
669
|
+
const toColIdx = toTable.columns.findIndex((c) => c.name === rel.toCol);
|
|
670
|
+
const fy = fromColIdx >= 0 ? fromPos.y + HEADER_H + fromColIdx * ROW_H + ROW_H / 2 : fromPos.y + fromPos.height / 2;
|
|
671
|
+
const ty = toColIdx >= 0 ? toPos.y + HEADER_H + toColIdx * ROW_H + ROW_H / 2 : toPos.y + toPos.height / 2;
|
|
672
|
+
const goRight = toPos.x + toPos.width / 2 > fromPos.x + fromPos.width / 2;
|
|
673
|
+
const fx = goRight ? fromPos.x + fromPos.width : fromPos.x;
|
|
674
|
+
const tx = goRight ? toPos.x : toPos.x + toPos.width;
|
|
675
|
+
const cp = Math.max(40, Math.abs(tx - fx) * 0.55);
|
|
676
|
+
const c1x = goRight ? fx + cp : fx - cp;
|
|
677
|
+
const c2x = goRight ? tx - cp : tx + cp;
|
|
678
|
+
parts.push(`<path d="M ${fx} ${fy} C ${c1x} ${fy}, ${c2x} ${ty}, ${tx} ${ty}" stroke="${common.edgeColor}" stroke-width="1.4" fill="none" stroke-dasharray="5 4" marker-end="url(#arr)"/>`);
|
|
679
|
+
const lx = (fx + tx) / 2;
|
|
680
|
+
const ly = (fy + ty) / 2 - 5;
|
|
681
|
+
parts.push(`<text x="${lx}" y="${ly}" font-size="9" font-style="italic" fill="${common.subtle}" text-anchor="middle">${escXml(fromColIdx >= 0 ? "FK" : rel.fromCol)}</text>`);
|
|
682
|
+
}
|
|
683
|
+
for (const table of ir.schema.tables) {
|
|
684
|
+
const p = positions.get(table.name);
|
|
685
|
+
if (!p) continue;
|
|
686
|
+
parts.push(`<g transform="translate(${p.x},${p.y})">`);
|
|
687
|
+
parts.push(`<rect width="${p.width}" height="${p.height}" rx="8" fill="${dark ? "#0f172a" : "#ffffff"}" stroke="${common.border}" stroke-width="1"/>`);
|
|
688
|
+
parts.push(`<rect width="${p.width}" height="${HEADER_H}" rx="8" fill="${dark ? "#1e293b" : "#f8fafc"}"/>`);
|
|
689
|
+
parts.push(`<rect y="${HEADER_H - 8}" width="${p.width}" height="8" fill="${dark ? "#1e293b" : "#f8fafc"}"/>`);
|
|
690
|
+
parts.push(`<line x1="0" y1="${HEADER_H}" x2="${p.width}" y2="${HEADER_H}" stroke="${common.border}"/>`);
|
|
691
|
+
parts.push(`<text x="12" y="${HEADER_H / 2 + 5}" font-family='${MONO_FAMILY}' font-size="12" font-weight="600" fill="${common.text}">${escXml(table.name)}</text>`);
|
|
692
|
+
for (let i = 0; i < table.columns.length; i++) {
|
|
693
|
+
const col = table.columns[i];
|
|
694
|
+
const rowY = HEADER_H + i * ROW_H;
|
|
695
|
+
const textY = rowY + ROW_H / 2 + 3;
|
|
696
|
+
if (i > 0) {
|
|
697
|
+
parts.push(`<line x1="8" y1="${rowY}" x2="${p.width - 8}" y2="${rowY}" stroke="${dark ? "#1e293b" : "#f1f5f9"}"/>`);
|
|
698
|
+
}
|
|
699
|
+
const nameColor = col.isPK ? "#d97706" : col.isFK ? "#0284c7" : dark ? "#cbd5e1" : "#475569";
|
|
700
|
+
const marker = col.isPK ? "\u{1F511}" : col.isFK ? "\u2197" : "\xB7";
|
|
701
|
+
parts.push(`<text x="14" y="${textY}" font-size="10" fill="${nameColor}">${marker}</text>`);
|
|
702
|
+
parts.push(`<text x="28" y="${textY}" font-family='${MONO_FAMILY}' font-size="11" font-weight="${col.isPK ? "600" : "400"}" fill="${nameColor}">${escXml(col.name)}</text>`);
|
|
703
|
+
parts.push(`<text x="${p.width - 12}" y="${textY}" text-anchor="end" font-family='${MONO_FAMILY}' font-size="10" fill="${common.subtle}">${escXml(col.type)}</text>`);
|
|
704
|
+
}
|
|
705
|
+
parts.push("</g>");
|
|
706
|
+
}
|
|
707
|
+
parts.push("</svg>");
|
|
708
|
+
return parts.join("");
|
|
709
|
+
}
|
|
710
|
+
function buildMindmapSvg(ir, positions, options = {}) {
|
|
711
|
+
const { common } = palette(options.dark ?? false);
|
|
712
|
+
const dark = options.dark ?? false;
|
|
713
|
+
const padding = options.padding ?? 60;
|
|
714
|
+
if (positions.size === 0) return svgOpen(0, 0, 100, 100, common.canvasBg) + "</svg>";
|
|
715
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
716
|
+
for (const p of positions.values()) {
|
|
717
|
+
minX = Math.min(minX, p.x);
|
|
718
|
+
minY = Math.min(minY, p.y);
|
|
719
|
+
maxX = Math.max(maxX, p.x + p.width);
|
|
720
|
+
maxY = Math.max(maxY, p.y + p.height);
|
|
721
|
+
}
|
|
722
|
+
minX -= padding;
|
|
723
|
+
minY -= padding;
|
|
724
|
+
maxX += padding;
|
|
725
|
+
maxY += padding;
|
|
726
|
+
const width = Math.round(maxX - minX);
|
|
727
|
+
const height = Math.round(maxY - minY);
|
|
728
|
+
const parts = [];
|
|
729
|
+
parts.push(svgOpen(minX, minY, width, height, common.canvasBg, ir.root.label || "Mindmap"));
|
|
730
|
+
const collect = (node) => {
|
|
731
|
+
const p = positions.get(node.id);
|
|
732
|
+
if (!p) return;
|
|
733
|
+
for (const c of node.children) {
|
|
734
|
+
const cp = positions.get(c.id);
|
|
735
|
+
if (!cp) continue;
|
|
736
|
+
const fx = p.x + p.width / 2;
|
|
737
|
+
const fy = p.y + p.height / 2;
|
|
738
|
+
const tx = cp.x + cp.width / 2;
|
|
739
|
+
const ty = cp.y + cp.height / 2;
|
|
740
|
+
const c1x = fx + (tx - fx) * 0.4;
|
|
741
|
+
const c2x = fx + (tx - fx) * 0.6;
|
|
742
|
+
parts.push(`<path d="M ${fx} ${fy} C ${c1x} ${fy}, ${c2x} ${ty}, ${tx} ${ty}" stroke="${common.edgeColor}" stroke-width="1.5" fill="none"/>`);
|
|
743
|
+
collect(c);
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
collect(ir.root);
|
|
747
|
+
const palettes = [
|
|
748
|
+
dark ? { bg: "#e2e8f0", border: "#f8fafc", text: "#0f172a" } : { bg: "#1e293b", border: "#0f172a", text: "#f8fafc" },
|
|
749
|
+
dark ? { bg: "rgba(59,130,246,0.20)", border: "#60a5fa", text: "#bfdbfe" } : { bg: "#dbeafe", border: "#3b82f6", text: "#1e3a8a" },
|
|
750
|
+
dark ? { bg: "rgba(16,185,129,0.20)", border: "#34d399", text: "#a7f3d0" } : { bg: "#dcfce7", border: "#10b981", text: "#064e3b" },
|
|
751
|
+
dark ? { bg: "rgba(245,158,11,0.20)", border: "#fbbf24", text: "#fde68a" } : { bg: "#fef3c7", border: "#f59e0b", text: "#78350f" },
|
|
752
|
+
dark ? { bg: "rgba(244,63,94,0.20)", border: "#fb7185", text: "#fecdd3" } : { bg: "#fee2e2", border: "#f43f5e", text: "#881337" },
|
|
753
|
+
dark ? { bg: "rgba(139,92,246,0.20)", border: "#a78bfa", text: "#ddd6fe" } : { bg: "#ede9fe", border: "#8b5cf6", text: "#4c1d95" }
|
|
754
|
+
];
|
|
755
|
+
const renderNode = (node) => {
|
|
756
|
+
const p = positions.get(node.id);
|
|
757
|
+
if (!p) return;
|
|
758
|
+
const c = palettes[Math.min(p.depth, palettes.length - 1)];
|
|
759
|
+
const isRoot = p.depth === 0;
|
|
760
|
+
const radius = node.shape === "circle" ? Math.min(p.width, p.height) / 2 : node.shape === "rounded" ? 999 : node.shape === "square" ? 4 : 12;
|
|
761
|
+
parts.push(
|
|
762
|
+
`<rect x="${p.x}" y="${p.y}" width="${p.width}" height="${p.height}" rx="${radius}" ry="${radius}" fill="${c.bg}" stroke="${c.border}" stroke-width="2"/>`
|
|
763
|
+
);
|
|
764
|
+
parts.push(
|
|
765
|
+
`<text x="${p.x + p.width / 2}" y="${p.y + p.height / 2 + 4}" text-anchor="middle" font-size="${isRoot ? 14 : 12}" font-weight="${isRoot ? 700 : 500}" fill="${c.text}">${escXml(node.label)}</text>`
|
|
766
|
+
);
|
|
767
|
+
for (const child of node.children) renderNode(child);
|
|
768
|
+
};
|
|
769
|
+
renderNode(ir.root);
|
|
770
|
+
parts.push("</svg>");
|
|
771
|
+
return parts.join("");
|
|
772
|
+
}
|
|
773
|
+
function buildGanttSvg(ir, options = {}) {
|
|
774
|
+
const { common } = palette(options.dark ?? false);
|
|
775
|
+
const dark = options.dark ?? false;
|
|
776
|
+
const padding = options.padding ?? 24;
|
|
777
|
+
if (ir.tasks.length === 0) return svgOpen(0, 0, 200, 60, common.canvasBg) + "</svg>";
|
|
778
|
+
const sections = /* @__PURE__ */ new Map();
|
|
779
|
+
for (const t of ir.tasks) {
|
|
780
|
+
const s = t.section ?? "Tasks";
|
|
781
|
+
if (!sections.has(s)) sections.set(s, []);
|
|
782
|
+
sections.get(s).push(t);
|
|
783
|
+
}
|
|
784
|
+
const rowH = 30;
|
|
785
|
+
const sectionHeaderH = 24;
|
|
786
|
+
const labelW = 160;
|
|
787
|
+
const chartW = 760;
|
|
788
|
+
const headerH = 36;
|
|
789
|
+
const totalRows = ir.tasks.length;
|
|
790
|
+
const totalSections = sections.size;
|
|
791
|
+
const titleH = ir.title ? 32 : 0;
|
|
792
|
+
const bodyH = headerH + totalSections * sectionHeaderH + totalRows * rowH;
|
|
793
|
+
const width = padding * 2 + labelW + chartW;
|
|
794
|
+
const height = padding * 2 + titleH + bodyH;
|
|
795
|
+
let minTime = Infinity, maxTime = -Infinity;
|
|
796
|
+
for (const t of ir.tasks) {
|
|
797
|
+
minTime = Math.min(minTime, new Date(t.start).getTime());
|
|
798
|
+
maxTime = Math.max(maxTime, new Date(t.end).getTime());
|
|
799
|
+
}
|
|
800
|
+
if (!isFinite(minTime) || !isFinite(maxTime) || maxTime === minTime) maxTime = minTime + 864e5;
|
|
801
|
+
const timeToX = (t) => padding + labelW + (t - minTime) / (maxTime - minTime) * chartW;
|
|
802
|
+
const colors = dark ? {
|
|
803
|
+
default: { fill: "rgba(59,130,246,0.30)", stroke: "#60a5fa", text: "#bfdbfe" },
|
|
804
|
+
active: { fill: "rgba(245,158,11,0.30)", stroke: "#fbbf24", text: "#fde68a" },
|
|
805
|
+
done: { fill: "rgba(16,185,129,0.30)", stroke: "#34d399", text: "#a7f3d0" },
|
|
806
|
+
crit: { fill: "rgba(244,63,94,0.30)", stroke: "#fb7185", text: "#fecdd3" },
|
|
807
|
+
milestone: { fill: "rgba(139,92,246,0.40)", stroke: "#a78bfa", text: "#ddd6fe" }
|
|
808
|
+
} : {
|
|
809
|
+
default: { fill: "#bfdbfe", stroke: "#3b82f6", text: "#1e3a8a" },
|
|
810
|
+
active: { fill: "#fde68a", stroke: "#f59e0b", text: "#78350f" },
|
|
811
|
+
done: { fill: "#a7f3d0", stroke: "#10b981", text: "#064e3b" },
|
|
812
|
+
crit: { fill: "#fecaca", stroke: "#f43f5e", text: "#881337" },
|
|
813
|
+
milestone: { fill: "#ddd6fe", stroke: "#8b5cf6", text: "#4c1d95" }
|
|
814
|
+
};
|
|
815
|
+
const parts = [];
|
|
816
|
+
parts.push(svgOpen(0, 0, width, height, common.canvasBg, ir.title || "Gantt chart"));
|
|
817
|
+
if (ir.title) {
|
|
818
|
+
parts.push(`<text x="${width / 2}" y="22" text-anchor="middle" font-size="15" font-weight="600" fill="${common.text}">${escXml(ir.title)}</text>`);
|
|
819
|
+
}
|
|
820
|
+
const axisY = padding + titleH + headerH - 4;
|
|
821
|
+
for (const ratio of [0, 0.5, 1]) {
|
|
822
|
+
const x = padding + labelW + ratio * chartW;
|
|
823
|
+
const time = minTime + (maxTime - minTime) * ratio;
|
|
824
|
+
const date = new Date(time);
|
|
825
|
+
const label = `${date.getMonth() + 1}/${date.getDate()}/${String(date.getFullYear()).slice(2)}`;
|
|
826
|
+
parts.push(`<text x="${x}" y="${axisY}" text-anchor="middle" font-size="10" fill="${common.subtle}">${escXml(label)}</text>`);
|
|
827
|
+
parts.push(`<line x1="${x}" y1="${axisY + 4}" x2="${x}" y2="${padding + titleH + bodyH}" stroke="${common.border}" stroke-dasharray="2 3"/>`);
|
|
828
|
+
}
|
|
829
|
+
let cy = padding + titleH + headerH;
|
|
830
|
+
for (const [section, tasks] of sections) {
|
|
831
|
+
parts.push(`<rect x="${padding}" y="${cy}" width="${labelW + chartW}" height="${sectionHeaderH}" fill="${dark ? "#1e293b" : "#f8fafc"}"/>`);
|
|
832
|
+
parts.push(`<text x="${padding + 8}" y="${cy + 16}" font-size="11" font-weight="600" fill="${common.text}">${escXml(section)}</text>`);
|
|
833
|
+
cy += sectionHeaderH;
|
|
834
|
+
for (const t of tasks) {
|
|
835
|
+
const x1 = timeToX(new Date(t.start).getTime());
|
|
836
|
+
const x2 = timeToX(new Date(t.end).getTime());
|
|
837
|
+
const c = colors[t.status] ?? colors.default;
|
|
838
|
+
parts.push(`<text x="${padding + 8}" y="${cy + rowH / 2 + 4}" font-size="11" fill="${common.text}">${escXml(t.label)}</text>`);
|
|
839
|
+
if (t.status === "milestone") {
|
|
840
|
+
const cx = x1;
|
|
841
|
+
const my = cy + rowH / 2;
|
|
842
|
+
parts.push(`<polygon points="${cx},${my - 7} ${cx + 7},${my} ${cx},${my + 7} ${cx - 7},${my}" fill="${c.fill}" stroke="${c.stroke}" stroke-width="1.5"/>`);
|
|
843
|
+
} else {
|
|
844
|
+
const w = Math.max(4, x2 - x1);
|
|
845
|
+
parts.push(`<rect x="${x1}" y="${cy + 6}" width="${w}" height="${rowH - 12}" rx="4" fill="${c.fill}" stroke="${c.stroke}" stroke-width="1"/>`);
|
|
846
|
+
}
|
|
847
|
+
cy += rowH;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
parts.push("</svg>");
|
|
851
|
+
return parts.join("");
|
|
852
|
+
}
|
|
853
|
+
function buildTimelineSvg(ir, options = {}) {
|
|
854
|
+
const { common } = palette(options.dark ?? false);
|
|
855
|
+
const dark = options.dark ?? false;
|
|
856
|
+
const padding = options.padding ?? 24;
|
|
857
|
+
if (ir.events.length === 0) return svgOpen(0, 0, 200, 60, common.canvasBg) + "</svg>";
|
|
858
|
+
const sectionsMap = /* @__PURE__ */ new Map();
|
|
859
|
+
for (const e of ir.events) {
|
|
860
|
+
const s = e.section ?? "";
|
|
861
|
+
if (!sectionsMap.has(s)) sectionsMap.set(s, []);
|
|
862
|
+
sectionsMap.get(s).push(e);
|
|
863
|
+
}
|
|
864
|
+
const titleH = ir.title ? 32 : 0;
|
|
865
|
+
const sectionHeaderH = 28;
|
|
866
|
+
const eventH = 56;
|
|
867
|
+
const rows = [];
|
|
868
|
+
for (const [section, events] of sectionsMap) {
|
|
869
|
+
if (section) rows.push({ type: "section", data: section });
|
|
870
|
+
for (const e of events) rows.push({ type: "event", data: e });
|
|
871
|
+
}
|
|
872
|
+
const lineX = padding + 80;
|
|
873
|
+
const eventBoxX = lineX + 24;
|
|
874
|
+
const eventBoxW = 480;
|
|
875
|
+
const width = padding * 2 + 80 + 24 + eventBoxW;
|
|
876
|
+
let height = padding * 2 + titleH;
|
|
877
|
+
for (const r of rows) height += r.type === "section" ? sectionHeaderH : eventH;
|
|
878
|
+
height += 20;
|
|
879
|
+
const sectionColors = ["#3b82f6", "#10b981", "#f59e0b", "#f43f5e", "#8b5cf6", "#06b6d4"];
|
|
880
|
+
const parts = [];
|
|
881
|
+
parts.push(svgOpen(0, 0, width, height, common.canvasBg, ir.title || "Timeline"));
|
|
882
|
+
if (ir.title) {
|
|
883
|
+
parts.push(`<text x="${width / 2}" y="22" text-anchor="middle" font-size="15" font-weight="600" fill="${common.text}">${escXml(ir.title)}</text>`);
|
|
884
|
+
}
|
|
885
|
+
parts.push(`<line x1="${lineX}" y1="${padding + titleH}" x2="${lineX}" y2="${height - padding}" stroke="${common.border}" stroke-width="2"/>`);
|
|
886
|
+
let cy = padding + titleH + 8;
|
|
887
|
+
let sectionIndex = -1;
|
|
888
|
+
for (const r of rows) {
|
|
889
|
+
if (r.type === "section") {
|
|
890
|
+
sectionIndex++;
|
|
891
|
+
parts.push(`<text x="${padding}" y="${cy + 16}" font-size="11" font-weight="700" fill="${common.subtle}">${escXml(r.data)}</text>`);
|
|
892
|
+
cy += sectionHeaderH;
|
|
893
|
+
} else {
|
|
894
|
+
const e = r.data;
|
|
895
|
+
const color = sectionColors[Math.max(0, sectionIndex) % sectionColors.length];
|
|
896
|
+
parts.push(`<circle cx="${lineX}" cy="${cy + eventH / 2}" r="6" fill="${color}" stroke="${common.canvasBg}" stroke-width="2"/>`);
|
|
897
|
+
parts.push(`<text x="${lineX - 12}" y="${cy + eventH / 2 + 4}" text-anchor="end" font-size="11" font-weight="600" fill="${common.text}">${escXml(e.period)}</text>`);
|
|
898
|
+
parts.push(`<rect x="${eventBoxX}" y="${cy + 4}" width="${eventBoxW}" height="${eventH - 12}" rx="8" fill="${dark ? "rgba(30,41,59,0.6)" : "#f8fafc"}" stroke="${color}" stroke-width="1"/>`);
|
|
899
|
+
const lines = wrapText(e.text, 60);
|
|
900
|
+
for (let i = 0; i < Math.min(lines.length, 3); i++) {
|
|
901
|
+
parts.push(`<text x="${eventBoxX + 12}" y="${cy + 22 + i * 14}" font-size="11" fill="${common.text}">${escXml(lines[i])}</text>`);
|
|
902
|
+
}
|
|
903
|
+
cy += eventH;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
parts.push("</svg>");
|
|
907
|
+
return parts.join("");
|
|
908
|
+
}
|
|
909
|
+
function buildPieSvg(ir, options = {}) {
|
|
910
|
+
const { common } = palette(options.dark ?? false);
|
|
911
|
+
const padding = options.padding ?? 20;
|
|
912
|
+
const titleH = ir.title ? 32 : 0;
|
|
913
|
+
const legendW = 200;
|
|
914
|
+
const radius = 160;
|
|
915
|
+
const cx = padding + radius + 16;
|
|
916
|
+
const cy = padding + titleH + radius + 16;
|
|
917
|
+
const width = padding * 2 + radius * 2 + 32 + legendW;
|
|
918
|
+
const height = padding * 2 + titleH + radius * 2 + 32;
|
|
919
|
+
const total = ir.slices.reduce((s, sl) => s + sl.value, 0);
|
|
920
|
+
const parts = [];
|
|
921
|
+
parts.push(svgOpen(0, 0, width, height, common.canvasBg, ir.title || "Pie chart"));
|
|
922
|
+
if (ir.title) {
|
|
923
|
+
parts.push(`<text x="${width / 2}" y="22" text-anchor="middle" font-size="16" font-weight="600" fill="${common.text}">${escXml(ir.title)}</text>`);
|
|
924
|
+
}
|
|
925
|
+
if (total === 0 || ir.slices.length === 0) {
|
|
926
|
+
parts.push(`<circle cx="${cx}" cy="${cy}" r="${radius}" fill="${common.border}"/>`);
|
|
927
|
+
parts.push("</svg>");
|
|
928
|
+
return parts.join("");
|
|
929
|
+
}
|
|
930
|
+
let startAngle = -Math.PI / 2;
|
|
931
|
+
ir.slices.forEach((slice, i) => {
|
|
932
|
+
const fraction = slice.value / total;
|
|
933
|
+
const endAngle = startAngle + fraction * Math.PI * 2;
|
|
934
|
+
const fill = PIE_PALETTE[i % PIE_PALETTE.length];
|
|
935
|
+
if (fraction >= 0.999) {
|
|
936
|
+
parts.push(`<circle cx="${cx}" cy="${cy}" r="${radius}" fill="${fill}" stroke="${common.canvasBg}" stroke-width="2"/>`);
|
|
937
|
+
} else {
|
|
938
|
+
const x1 = cx + Math.cos(startAngle) * radius;
|
|
939
|
+
const y1 = cy + Math.sin(startAngle) * radius;
|
|
940
|
+
const x2 = cx + Math.cos(endAngle) * radius;
|
|
941
|
+
const y2 = cy + Math.sin(endAngle) * radius;
|
|
942
|
+
const largeArc = fraction > 0.5 ? 1 : 0;
|
|
943
|
+
parts.push(
|
|
944
|
+
`<path d="M ${cx} ${cy} L ${x1} ${y1} A ${radius} ${radius} 0 ${largeArc} 1 ${x2} ${y2} Z" fill="${fill}" stroke="${common.canvasBg}" stroke-width="2"/>`
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
if (ir.showData && fraction >= 0.04) {
|
|
948
|
+
const mid = (startAngle + endAngle) / 2;
|
|
949
|
+
const lx = cx + Math.cos(mid) * radius * 0.65;
|
|
950
|
+
const ly = cy + Math.sin(mid) * radius * 0.65;
|
|
951
|
+
parts.push(
|
|
952
|
+
`<text x="${lx}" y="${ly + 4}" text-anchor="middle" font-size="12" font-weight="600" fill="#ffffff">${(fraction * 100).toFixed(1)}%</text>`
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
startAngle = endAngle;
|
|
956
|
+
});
|
|
957
|
+
const legendX = cx + radius + 24;
|
|
958
|
+
let legendY = padding + titleH + 16;
|
|
959
|
+
ir.slices.forEach((slice, i) => {
|
|
960
|
+
const fill = PIE_PALETTE[i % PIE_PALETTE.length];
|
|
961
|
+
const pct = (slice.value / total * 100).toFixed(1);
|
|
962
|
+
parts.push(`<rect x="${legendX}" y="${legendY - 10}" width="14" height="14" rx="2" fill="${fill}"/>`);
|
|
963
|
+
parts.push(`<text x="${legendX + 22}" y="${legendY + 1}" font-size="12" fill="${common.text}">${escXml(slice.label)}</text>`);
|
|
964
|
+
parts.push(`<text x="${legendX + 22}" y="${legendY + 16}" font-size="10" fill="${common.subtle}">${slice.value} \xB7 ${pct}%</text>`);
|
|
965
|
+
legendY += 32;
|
|
966
|
+
});
|
|
967
|
+
parts.push("</svg>");
|
|
968
|
+
return parts.join("");
|
|
969
|
+
}
|
|
970
|
+
function buildQuadrantSvg(ir, options = {}) {
|
|
971
|
+
const { common } = palette(options.dark ?? false);
|
|
972
|
+
const dark = options.dark ?? false;
|
|
973
|
+
const padding = options.padding ?? 60;
|
|
974
|
+
const titleH = ir.title ? 32 : 0;
|
|
975
|
+
const chartW = 700;
|
|
976
|
+
const chartH = 500;
|
|
977
|
+
const yAxis = ir.yAxisLabel ?? { low: "Low", high: "High" };
|
|
978
|
+
const xAxis = ir.xAxisLabel ?? { low: "Low", high: "High" };
|
|
979
|
+
const longestYLabel = Math.max(yAxis.low.length, yAxis.high.length);
|
|
980
|
+
const leftPadding = Math.max(padding, longestYLabel * 7 + 24);
|
|
981
|
+
const width = leftPadding + chartW + padding;
|
|
982
|
+
const height = padding * 2 + titleH + chartH;
|
|
983
|
+
const x0 = leftPadding;
|
|
984
|
+
const y0 = padding + titleH;
|
|
985
|
+
const tints = dark ? { q1: "rgba(16,185,129,0.18)", q2: "rgba(245,158,11,0.18)", q3: "rgba(244,63,94,0.18)", q4: "rgba(59,130,246,0.18)" } : { q1: "#10b98120", q2: "#f59e0b20", q3: "#ef444420", q4: "#3b82f620" };
|
|
986
|
+
const parts = [];
|
|
987
|
+
parts.push(svgOpen(0, 0, width, height, common.canvasBg, ir.title || "Quadrant chart"));
|
|
988
|
+
if (ir.title) {
|
|
989
|
+
parts.push(`<text x="${width / 2}" y="22" text-anchor="middle" font-size="16" font-weight="600" fill="${common.text}">${escXml(ir.title)}</text>`);
|
|
990
|
+
}
|
|
991
|
+
const halfW = chartW / 2;
|
|
992
|
+
const halfH = chartH / 2;
|
|
993
|
+
parts.push(`<rect x="${x0}" y="${y0 + halfH}" width="${halfW}" height="${halfH}" fill="${tints.q3}"/>`);
|
|
994
|
+
parts.push(`<rect x="${x0 + halfW}" y="${y0 + halfH}" width="${halfW}" height="${halfH}" fill="${tints.q4}"/>`);
|
|
995
|
+
parts.push(`<rect x="${x0}" y="${y0}" width="${halfW}" height="${halfH}" fill="${tints.q2}"/>`);
|
|
996
|
+
parts.push(`<rect x="${x0 + halfW}" y="${y0}" width="${halfW}" height="${halfH}" fill="${tints.q1}"/>`);
|
|
997
|
+
parts.push(`<line x1="${x0}" y1="${y0 + halfH}" x2="${x0 + chartW}" y2="${y0 + halfH}" stroke="${common.border}" stroke-width="1"/>`);
|
|
998
|
+
parts.push(`<line x1="${x0 + halfW}" y1="${y0}" x2="${x0 + halfW}" y2="${y0 + chartH}" stroke="${common.border}" stroke-width="1"/>`);
|
|
999
|
+
const labels = ir.quadrantLabels ?? {};
|
|
1000
|
+
if (labels.q1) parts.push(`<text x="${x0 + halfW + halfW / 2}" y="${y0 + halfH / 2}" text-anchor="middle" font-size="13" font-weight="500" fill="${common.text}">${escXml(labels.q1)}</text>`);
|
|
1001
|
+
if (labels.q2) parts.push(`<text x="${x0 + halfW / 2}" y="${y0 + halfH / 2}" text-anchor="middle" font-size="13" font-weight="500" fill="${common.text}">${escXml(labels.q2)}</text>`);
|
|
1002
|
+
if (labels.q3) parts.push(`<text x="${x0 + halfW / 2}" y="${y0 + halfH + halfH / 2}" text-anchor="middle" font-size="13" font-weight="500" fill="${common.text}">${escXml(labels.q3)}</text>`);
|
|
1003
|
+
if (labels.q4) parts.push(`<text x="${x0 + halfW + halfW / 2}" y="${y0 + halfH + halfH / 2}" text-anchor="middle" font-size="13" font-weight="500" fill="${common.text}">${escXml(labels.q4)}</text>`);
|
|
1004
|
+
parts.push(`<text x="${x0}" y="${y0 + chartH + 24}" text-anchor="start" font-size="12" fill="${common.text}">${escXml(xAxis.low)}</text>`);
|
|
1005
|
+
parts.push(`<text x="${x0 + chartW}" y="${y0 + chartH + 24}" text-anchor="end" font-size="12" fill="${common.text}">${escXml(xAxis.high)}</text>`);
|
|
1006
|
+
parts.push(`<text x="${x0 - 12}" y="${y0 + chartH}" text-anchor="end" font-size="12" fill="${common.text}">${escXml(yAxis.low)}</text>`);
|
|
1007
|
+
parts.push(`<text x="${x0 - 12}" y="${y0 + 12}" text-anchor="end" font-size="12" fill="${common.text}">${escXml(yAxis.high)}</text>`);
|
|
1008
|
+
for (const p of ir.points) {
|
|
1009
|
+
const px = x0 + p.x * chartW;
|
|
1010
|
+
const py = y0 + (1 - p.y) * chartH;
|
|
1011
|
+
parts.push(`<circle cx="${px}" cy="${py}" r="6" fill="#3b82f6" stroke="${common.canvasBg}" stroke-width="2"/>`);
|
|
1012
|
+
parts.push(`<text x="${px}" y="${py - 12}" text-anchor="middle" font-size="11" font-weight="500" fill="${common.text}">${escXml(p.label)}</text>`);
|
|
1013
|
+
}
|
|
1014
|
+
parts.push("</svg>");
|
|
1015
|
+
return parts.join("");
|
|
1016
|
+
}
|
|
1017
|
+
function buildJourneySvg(ir, options = {}) {
|
|
1018
|
+
const { common } = palette(options.dark ?? false);
|
|
1019
|
+
const padding = options.padding ?? 40;
|
|
1020
|
+
const titleH = ir.title ? 32 : 0;
|
|
1021
|
+
const SECTION_HEADER_H = 32;
|
|
1022
|
+
const TASK_H = 36;
|
|
1023
|
+
const labelW = 200;
|
|
1024
|
+
const chartW = 600;
|
|
1025
|
+
const SCORE_MAX = 7;
|
|
1026
|
+
const allTasks = [];
|
|
1027
|
+
ir.sections.forEach((s, idx) => {
|
|
1028
|
+
s.tasks.forEach((t) => allTasks.push({ sectionTitle: s.title, sectionIdx: idx, label: t.label, score: t.score, actors: t.actors }));
|
|
1029
|
+
});
|
|
1030
|
+
const totalH = padding * 2 + titleH + ir.sections.length * SECTION_HEADER_H + allTasks.length * TASK_H + 40;
|
|
1031
|
+
const width = padding * 2 + labelW + chartW;
|
|
1032
|
+
const height = totalH;
|
|
1033
|
+
const sectionColors = ["#3b82f6", "#10b981", "#f59e0b", "#f43f5e", "#8b5cf6", "#06b6d4"];
|
|
1034
|
+
const parts = [];
|
|
1035
|
+
parts.push(svgOpen(0, 0, width, height, common.canvasBg, ir.title || "User journey"));
|
|
1036
|
+
if (ir.title) {
|
|
1037
|
+
parts.push(`<text x="${width / 2}" y="22" text-anchor="middle" font-size="16" font-weight="600" fill="${common.text}">${escXml(ir.title)}</text>`);
|
|
1038
|
+
}
|
|
1039
|
+
const chartX = padding + labelW;
|
|
1040
|
+
const axisY = padding + titleH + 14;
|
|
1041
|
+
for (let s = 1; s <= SCORE_MAX; s++) {
|
|
1042
|
+
const x = chartX + (s - 1) / (SCORE_MAX - 1) * chartW;
|
|
1043
|
+
parts.push(`<text x="${x}" y="${axisY}" text-anchor="middle" font-size="10" fill="${common.subtle}">${s}</text>`);
|
|
1044
|
+
}
|
|
1045
|
+
let cy = padding + titleH + SECTION_HEADER_H;
|
|
1046
|
+
ir.sections.forEach((section, idx) => {
|
|
1047
|
+
const color = sectionColors[idx % sectionColors.length];
|
|
1048
|
+
parts.push(`<rect x="${padding}" y="${cy - SECTION_HEADER_H + 4}" width="${labelW + chartW}" height="${SECTION_HEADER_H - 4}" fill="${color}20" rx="6"/>`);
|
|
1049
|
+
parts.push(`<text x="${padding + 10}" y="${cy - 12}" font-size="12" font-weight="600" fill="${common.text}">${escXml(section.title)}</text>`);
|
|
1050
|
+
section.tasks.forEach((task) => {
|
|
1051
|
+
parts.push(`<text x="${padding + 10}" y="${cy + TASK_H / 2 + 4}" font-size="12" fill="${common.text}">${escXml(task.label)}</text>`);
|
|
1052
|
+
const scoreClamped = Math.max(1, Math.min(SCORE_MAX, task.score));
|
|
1053
|
+
const dotX = chartX + (scoreClamped - 1) / (SCORE_MAX - 1) * chartW;
|
|
1054
|
+
const dotY = cy + TASK_H / 2;
|
|
1055
|
+
parts.push(`<line x1="${chartX}" y1="${dotY}" x2="${chartX + chartW}" y2="${dotY}" stroke="${common.border}" stroke-dasharray="2 3"/>`);
|
|
1056
|
+
parts.push(`<circle cx="${dotX}" cy="${dotY}" r="8" fill="${color}" stroke="${common.canvasBg}" stroke-width="2"/>`);
|
|
1057
|
+
parts.push(`<text x="${dotX}" y="${dotY + 3}" text-anchor="middle" font-size="10" font-weight="700" fill="#ffffff">${task.score}</text>`);
|
|
1058
|
+
if (task.actors.length > 0) {
|
|
1059
|
+
const actorsText = task.actors.join(", ");
|
|
1060
|
+
parts.push(`<text x="${dotX + 14}" y="${dotY + 4}" font-size="10" fill="${common.subtle}">${escXml(actorsText)}</text>`);
|
|
1061
|
+
}
|
|
1062
|
+
cy += TASK_H;
|
|
1063
|
+
});
|
|
1064
|
+
cy += SECTION_HEADER_H;
|
|
1065
|
+
});
|
|
1066
|
+
parts.push("</svg>");
|
|
1067
|
+
return parts.join("");
|
|
1068
|
+
}
|
|
1069
|
+
function archTint(icon, dark) {
|
|
1070
|
+
if (!icon) return dark ? { fill: "#1e293b", border: "#475569" } : { fill: "#ffffff", border: "#cbd5e1" };
|
|
1071
|
+
const key = Object.keys(ARCH_ICON_TINT).find((k) => icon.toLowerCase().includes(k));
|
|
1072
|
+
const base = key ? ARCH_ICON_TINT[key] : { fill: "#ffffff", border: "#cbd5e1" };
|
|
1073
|
+
if (!dark) return base;
|
|
1074
|
+
return { fill: `${base.border}25`, border: base.border };
|
|
1075
|
+
}
|
|
1076
|
+
function buildArchitectureSvg(ir, options = {}) {
|
|
1077
|
+
const { common } = palette(options.dark ?? false);
|
|
1078
|
+
const dark = options.dark ?? false;
|
|
1079
|
+
const padding = options.padding ?? 40;
|
|
1080
|
+
const SERVICE_W = 130;
|
|
1081
|
+
const SERVICE_H = 80;
|
|
1082
|
+
const byParent = /* @__PURE__ */ new Map();
|
|
1083
|
+
for (const n of ir.nodes) {
|
|
1084
|
+
const k = n.parent;
|
|
1085
|
+
if (!byParent.has(k)) byParent.set(k, []);
|
|
1086
|
+
byParent.get(k).push(n);
|
|
1087
|
+
}
|
|
1088
|
+
const groupBounds = /* @__PURE__ */ new Map();
|
|
1089
|
+
for (const node of ir.nodes) {
|
|
1090
|
+
if (node.kind !== "group") continue;
|
|
1091
|
+
const children = byParent.get(node.id) ?? [];
|
|
1092
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
1093
|
+
g.setGraph({ rankdir: "LR", nodesep: 30, ranksep: 50, marginx: 16, marginy: 16 });
|
|
1094
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
1095
|
+
for (const c of children) {
|
|
1096
|
+
g.setNode(c.id, { width: SERVICE_W, height: SERVICE_H });
|
|
1097
|
+
}
|
|
1098
|
+
const childIds = new Set(children.map((c) => c.id));
|
|
1099
|
+
for (const e of ir.edges) {
|
|
1100
|
+
if (childIds.has(e.source) && childIds.has(e.target) && g.hasNode(e.source) && g.hasNode(e.target)) {
|
|
1101
|
+
g.setEdge(e.source, e.target);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
if (children.length > 0) dagre2__default.default.layout(g);
|
|
1105
|
+
const positions = /* @__PURE__ */ new Map();
|
|
1106
|
+
let minLeft = Infinity, minTop = Infinity, maxRight = 0, maxBottom = 0;
|
|
1107
|
+
for (const c of children) {
|
|
1108
|
+
const { x, y } = g.node(c.id);
|
|
1109
|
+
const left = x - SERVICE_W / 2;
|
|
1110
|
+
const top = y - SERVICE_H / 2;
|
|
1111
|
+
positions.set(c.id, { x: left, y: top });
|
|
1112
|
+
minLeft = Math.min(minLeft, left);
|
|
1113
|
+
minTop = Math.min(minTop, top);
|
|
1114
|
+
maxRight = Math.max(maxRight, left + SERVICE_W);
|
|
1115
|
+
maxBottom = Math.max(maxBottom, top + SERVICE_H);
|
|
1116
|
+
}
|
|
1117
|
+
const HEADER = 28;
|
|
1118
|
+
const PAD = 16;
|
|
1119
|
+
const dx = PAD - (isFinite(minLeft) ? minLeft : 0);
|
|
1120
|
+
const dy = HEADER + PAD - (isFinite(minTop) ? minTop : 0);
|
|
1121
|
+
const offset = /* @__PURE__ */ new Map();
|
|
1122
|
+
for (const [id, p] of positions) offset.set(id, { x: p.x + dx, y: p.y + dy });
|
|
1123
|
+
groupBounds.set(node.id, {
|
|
1124
|
+
width: Math.max(220, (isFinite(maxRight - minLeft) ? maxRight - minLeft : 0) + PAD * 2),
|
|
1125
|
+
height: Math.max(120, (isFinite(maxBottom - minTop) ? maxBottom - minTop : 0) + HEADER + PAD * 2),
|
|
1126
|
+
positions: offset
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
const topLevel = ir.nodes.filter((n) => !n.parent);
|
|
1130
|
+
const outer = new dagre2__default.default.graphlib.Graph();
|
|
1131
|
+
outer.setGraph({ rankdir: "LR", nodesep: 50, ranksep: 80, marginx: 32, marginy: 32 });
|
|
1132
|
+
outer.setDefaultEdgeLabel(() => ({}));
|
|
1133
|
+
for (const n of topLevel) {
|
|
1134
|
+
if (n.kind === "group") {
|
|
1135
|
+
const b = groupBounds.get(n.id);
|
|
1136
|
+
outer.setNode(n.id, { width: b.width, height: b.height });
|
|
1137
|
+
} else {
|
|
1138
|
+
outer.setNode(n.id, { width: SERVICE_W, height: SERVICE_H });
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
for (const e of ir.edges) {
|
|
1142
|
+
if (outer.hasNode(e.source) && outer.hasNode(e.target)) outer.setEdge(e.source, e.target);
|
|
1143
|
+
}
|
|
1144
|
+
dagre2__default.default.layout(outer);
|
|
1145
|
+
const abs = /* @__PURE__ */ new Map();
|
|
1146
|
+
for (const n of topLevel) {
|
|
1147
|
+
const { x, y } = outer.node(n.id);
|
|
1148
|
+
const w = n.kind === "group" ? groupBounds.get(n.id).width : SERVICE_W;
|
|
1149
|
+
const h = n.kind === "group" ? groupBounds.get(n.id).height : SERVICE_H;
|
|
1150
|
+
abs.set(n.id, { x: x - w / 2, y: y - h / 2, width: w, height: h, kind: n.kind, node: n });
|
|
1151
|
+
}
|
|
1152
|
+
for (const n of ir.nodes) {
|
|
1153
|
+
if (!n.parent) continue;
|
|
1154
|
+
const parentBox = abs.get(n.parent);
|
|
1155
|
+
if (!parentBox) continue;
|
|
1156
|
+
const pos = groupBounds.get(n.parent)?.positions.get(n.id);
|
|
1157
|
+
if (!pos) continue;
|
|
1158
|
+
abs.set(n.id, { x: parentBox.x + pos.x, y: parentBox.y + pos.y, width: SERVICE_W, height: SERVICE_H, kind: n.kind, node: n });
|
|
1159
|
+
}
|
|
1160
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
1161
|
+
for (const b of abs.values()) {
|
|
1162
|
+
minX = Math.min(minX, b.x);
|
|
1163
|
+
minY = Math.min(minY, b.y);
|
|
1164
|
+
maxX = Math.max(maxX, b.x + b.width);
|
|
1165
|
+
maxY = Math.max(maxY, b.y + b.height);
|
|
1166
|
+
}
|
|
1167
|
+
minX -= padding;
|
|
1168
|
+
minY -= padding;
|
|
1169
|
+
maxX += padding;
|
|
1170
|
+
maxY += padding;
|
|
1171
|
+
const width = Math.round(maxX - minX);
|
|
1172
|
+
const height = Math.round(maxY - minY);
|
|
1173
|
+
const parts = [];
|
|
1174
|
+
parts.push(svgOpen(minX, minY, width, height, common.canvasBg, "Architecture diagram"));
|
|
1175
|
+
parts.push(`<defs>${arrowDef("arr", common.edgeColor)}</defs>`);
|
|
1176
|
+
for (const n of ir.nodes) {
|
|
1177
|
+
if (n.kind !== "group") continue;
|
|
1178
|
+
const b = abs.get(n.id);
|
|
1179
|
+
if (!b) continue;
|
|
1180
|
+
const tint = archTint(n.icon, dark);
|
|
1181
|
+
parts.push(
|
|
1182
|
+
`<rect x="${b.x}" y="${b.y}" width="${b.width}" height="${b.height}" rx="12" fill="${tint.fill}" stroke="${tint.border}" stroke-width="1.5" stroke-dasharray="6 4"/>`
|
|
1183
|
+
);
|
|
1184
|
+
parts.push(`<text x="${b.x + 14}" y="${b.y + 18}" font-size="12" font-weight="700" fill="${common.text}">${escXml(n.label)}</text>`);
|
|
1185
|
+
if (n.icon) {
|
|
1186
|
+
parts.push(`<text x="${b.x + b.width - 14}" y="${b.y + 18}" text-anchor="end" font-size="9" fill="${common.subtle}">${escXml(n.icon)}</text>`);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
for (const e of ir.edges) {
|
|
1190
|
+
const a = abs.get(e.source);
|
|
1191
|
+
const b = abs.get(e.target);
|
|
1192
|
+
if (!a || !b) continue;
|
|
1193
|
+
parts.push(buildEdgePath(a, b, { source: e.source, target: e.target, label: e.label, kind: "solid" }, common));
|
|
1194
|
+
}
|
|
1195
|
+
for (const n of ir.nodes) {
|
|
1196
|
+
if (n.kind !== "service") continue;
|
|
1197
|
+
const b = abs.get(n.id);
|
|
1198
|
+
if (!b) continue;
|
|
1199
|
+
const tint = archTint(n.icon, dark);
|
|
1200
|
+
parts.push(
|
|
1201
|
+
`<rect x="${b.x}" y="${b.y}" width="${b.width}" height="${b.height}" rx="10" fill="${tint.fill}" stroke="${tint.border}" stroke-width="1.5"/>`
|
|
1202
|
+
);
|
|
1203
|
+
parts.push(`<circle cx="${b.x + b.width / 2}" cy="${b.y + 22}" r="14" fill="${tint.border}" opacity="0.85"/>`);
|
|
1204
|
+
if (n.icon) {
|
|
1205
|
+
const short = n.icon.split(":").pop().slice(0, 3).toUpperCase();
|
|
1206
|
+
parts.push(`<text x="${b.x + b.width / 2}" y="${b.y + 26}" text-anchor="middle" font-size="9" font-weight="700" fill="#ffffff">${escXml(short)}</text>`);
|
|
1207
|
+
}
|
|
1208
|
+
parts.push(`<text x="${b.x + b.width / 2}" y="${b.y + 56}" text-anchor="middle" font-size="12" font-weight="600" fill="${common.text}">${escXml(n.label)}</text>`);
|
|
1209
|
+
}
|
|
1210
|
+
parts.push("</svg>");
|
|
1211
|
+
return parts.join("");
|
|
1212
|
+
}
|
|
1213
|
+
function c4StyleFor(kind, dark) {
|
|
1214
|
+
const isExternal = kind.endsWith("-external");
|
|
1215
|
+
const base = kind.startsWith("person") ? { fill: dark ? "rgba(8, 80, 134, 0.4)" : "#08427b", text: "#ffffff" } : kind.startsWith("system") ? { fill: dark ? "rgba(17, 102, 187, 0.4)" : "#1168bd", text: "#ffffff" } : kind.startsWith("container") ? { fill: dark ? "rgba(67, 130, 245, 0.4)" : "#438dd5", text: "#ffffff" } : kind.startsWith("component") ? { fill: dark ? "rgba(133, 187, 245, 0.4)" : "#85bbf0", text: "#0f172a" } : { fill: dark ? "rgba(148, 163, 184, 0.3)" : "#9ca3af", text: "#0f172a" };
|
|
1216
|
+
let shape = "rect";
|
|
1217
|
+
if (kind.startsWith("person")) shape = "person";
|
|
1218
|
+
else if (kind.endsWith("-db")) shape = "cylinder";
|
|
1219
|
+
else if (kind.endsWith("-queue")) shape = "queue";
|
|
1220
|
+
else if (kind.endsWith("boundary")) shape = "boundary";
|
|
1221
|
+
else if (kind === "node") shape = "node";
|
|
1222
|
+
return {
|
|
1223
|
+
fill: isExternal ? dark ? "rgba(100, 116, 139, 0.4)" : "#999999" : base.fill,
|
|
1224
|
+
border: isExternal ? "#64748b" : "#073b6f",
|
|
1225
|
+
text: base.text,
|
|
1226
|
+
badge: "#0f172a40",
|
|
1227
|
+
badgeText: "#ffffff",
|
|
1228
|
+
shape,
|
|
1229
|
+
dashed: shape === "boundary" || shape === "node"
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
function c4BadgeLabel(kind) {
|
|
1233
|
+
if (kind.startsWith("person")) return "Person";
|
|
1234
|
+
if (kind.endsWith("-external")) {
|
|
1235
|
+
if (kind.startsWith("system")) return "External System";
|
|
1236
|
+
if (kind.startsWith("container")) return "External Container";
|
|
1237
|
+
if (kind.startsWith("component")) return "External Component";
|
|
1238
|
+
}
|
|
1239
|
+
if (kind.endsWith("-db")) return kind.startsWith("system") ? "System" : kind.startsWith("container") ? "Container" : "Component";
|
|
1240
|
+
if (kind.endsWith("-queue")) return kind.startsWith("system") ? "System" : kind.startsWith("container") ? "Container" : "Component";
|
|
1241
|
+
if (kind === "system") return "System";
|
|
1242
|
+
if (kind === "container") return "Container";
|
|
1243
|
+
if (kind === "component") return "Component";
|
|
1244
|
+
if (kind === "node") return "Deployment Node";
|
|
1245
|
+
return "Boundary";
|
|
1246
|
+
}
|
|
1247
|
+
function buildC4Svg(ir, options = {}) {
|
|
1248
|
+
const { common } = palette(options.dark ?? false);
|
|
1249
|
+
const dark = options.dark ?? false;
|
|
1250
|
+
const padding = options.padding ?? 40;
|
|
1251
|
+
const titleH = ir.title ? 32 : 0;
|
|
1252
|
+
const ELEM_W = 200;
|
|
1253
|
+
const ELEM_H = 110;
|
|
1254
|
+
const nonBoundary = ir.elements.filter((e) => !c4StyleFor(e.kind, dark).shape.includes("boundary") && c4StyleFor(e.kind, dark).shape !== "node");
|
|
1255
|
+
const boundaries = ir.elements.filter((e) => {
|
|
1256
|
+
const s = c4StyleFor(e.kind, dark);
|
|
1257
|
+
return s.shape === "boundary" || s.shape === "node";
|
|
1258
|
+
});
|
|
1259
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
1260
|
+
g.setGraph({ rankdir: "TB", nodesep: 60, ranksep: 80, marginx: 32, marginy: 32 });
|
|
1261
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
1262
|
+
for (const el of nonBoundary) g.setNode(el.id, { width: ELEM_W, height: ELEM_H });
|
|
1263
|
+
for (const rel of ir.relations) {
|
|
1264
|
+
if (g.hasNode(rel.source) && g.hasNode(rel.target)) g.setEdge(rel.source, rel.target);
|
|
1265
|
+
}
|
|
1266
|
+
dagre2__default.default.layout(g);
|
|
1267
|
+
const positions = /* @__PURE__ */ new Map();
|
|
1268
|
+
for (const el of nonBoundary) {
|
|
1269
|
+
const { x, y } = g.node(el.id);
|
|
1270
|
+
positions.set(el.id, { x: x - ELEM_W / 2, y: y - ELEM_H / 2, width: ELEM_W, height: ELEM_H });
|
|
1271
|
+
}
|
|
1272
|
+
for (const b of boundaries) {
|
|
1273
|
+
const children = ir.elements.filter((e) => e.parent === b.id);
|
|
1274
|
+
const childPositions = children.map((c) => positions.get(c.id)).filter((p) => !!p);
|
|
1275
|
+
if (childPositions.length === 0) continue;
|
|
1276
|
+
let minX2 = Infinity, minY2 = Infinity, maxX2 = -Infinity, maxY2 = -Infinity;
|
|
1277
|
+
for (const p of childPositions) {
|
|
1278
|
+
minX2 = Math.min(minX2, p.x);
|
|
1279
|
+
minY2 = Math.min(minY2, p.y);
|
|
1280
|
+
maxX2 = Math.max(maxX2, p.x + p.width);
|
|
1281
|
+
maxY2 = Math.max(maxY2, p.y + p.height);
|
|
1282
|
+
}
|
|
1283
|
+
positions.set(b.id, { x: minX2 - 20, y: minY2 - 28, width: maxX2 - minX2 + 40, height: maxY2 - minY2 + 48 });
|
|
1284
|
+
}
|
|
1285
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
1286
|
+
for (const p of positions.values()) {
|
|
1287
|
+
minX = Math.min(minX, p.x);
|
|
1288
|
+
minY = Math.min(minY, p.y);
|
|
1289
|
+
maxX = Math.max(maxX, p.x + p.width);
|
|
1290
|
+
maxY = Math.max(maxY, p.y + p.height);
|
|
1291
|
+
}
|
|
1292
|
+
minX -= padding;
|
|
1293
|
+
minY -= padding - titleH;
|
|
1294
|
+
maxX += padding;
|
|
1295
|
+
maxY += padding;
|
|
1296
|
+
const width = Math.round(maxX - minX);
|
|
1297
|
+
const height = Math.round(maxY - minY) + titleH;
|
|
1298
|
+
const viewMinY = minY - titleH;
|
|
1299
|
+
const parts = [];
|
|
1300
|
+
parts.push(svgOpen(minX, viewMinY, width, height, common.canvasBg, ir.title || `C4 ${ir.variant} diagram`));
|
|
1301
|
+
parts.push(`<defs>${arrowDef("arr", common.edgeColor)}</defs>`);
|
|
1302
|
+
if (ir.title) {
|
|
1303
|
+
parts.push(`<text x="${minX + width / 2}" y="${viewMinY + 22}" text-anchor="middle" font-size="16" font-weight="700" fill="${common.text}">${escXml(ir.title)}</text>`);
|
|
1304
|
+
}
|
|
1305
|
+
for (const b of boundaries) {
|
|
1306
|
+
const p = positions.get(b.id);
|
|
1307
|
+
if (!p) continue;
|
|
1308
|
+
const style = c4StyleFor(b.kind, dark);
|
|
1309
|
+
parts.push(
|
|
1310
|
+
`<rect x="${p.x}" y="${p.y}" width="${p.width}" height="${p.height}" rx="8" fill="none" stroke="${style.border}" stroke-width="2" stroke-dasharray="8 4"/>`
|
|
1311
|
+
);
|
|
1312
|
+
parts.push(`<text x="${p.x + 12}" y="${p.y + 18}" font-size="11" font-weight="700" fill="${common.text}">${escXml(b.label)}</text>`);
|
|
1313
|
+
parts.push(`<text x="${p.x + 12}" y="${p.y + 32}" font-size="9" fill="${common.subtle}" font-style="italic">[${escXml(c4BadgeLabel(b.kind))}]</text>`);
|
|
1314
|
+
}
|
|
1315
|
+
for (const rel of ir.relations) {
|
|
1316
|
+
const a = positions.get(rel.source);
|
|
1317
|
+
const b = positions.get(rel.target);
|
|
1318
|
+
if (!a || !b) continue;
|
|
1319
|
+
const labelLine = rel.label ?? "";
|
|
1320
|
+
const techLine = rel.technology ? `[${rel.technology}]` : "";
|
|
1321
|
+
parts.push(
|
|
1322
|
+
buildEdgePath(a, b, { source: rel.source, target: rel.target, label: [labelLine, techLine].filter(Boolean).join(" "), kind: "solid" }, common)
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
for (const el of nonBoundary) {
|
|
1326
|
+
const p = positions.get(el.id);
|
|
1327
|
+
if (!p) continue;
|
|
1328
|
+
parts.push(buildC4Element(el, p, dark));
|
|
1329
|
+
}
|
|
1330
|
+
parts.push("</svg>");
|
|
1331
|
+
return parts.join("");
|
|
1332
|
+
}
|
|
1333
|
+
function buildC4Element(el, p, dark) {
|
|
1334
|
+
const style = c4StyleFor(el.kind, dark);
|
|
1335
|
+
const cx = p.x + p.width / 2;
|
|
1336
|
+
const parts = [];
|
|
1337
|
+
if (style.shape === "person") {
|
|
1338
|
+
const headR = 14;
|
|
1339
|
+
parts.push(
|
|
1340
|
+
`<rect x="${p.x}" y="${p.y + headR + 8}" width="${p.width}" height="${p.height - headR - 8}" rx="10" fill="${style.fill}" stroke="${style.border}" stroke-width="1.5"/>`
|
|
1341
|
+
);
|
|
1342
|
+
parts.push(`<circle cx="${cx}" cy="${p.y + headR + 4}" r="${headR}" fill="${style.fill}" stroke="${style.border}" stroke-width="1.5"/>`);
|
|
1343
|
+
} else if (style.shape === "cylinder") {
|
|
1344
|
+
const ry = 8;
|
|
1345
|
+
parts.push(
|
|
1346
|
+
`<path d="M ${p.x} ${p.y + ry} A ${p.width / 2} ${ry} 0 0 0 ${p.x + p.width} ${p.y + ry} L ${p.x + p.width} ${p.y + p.height - ry} A ${p.width / 2} ${ry} 0 0 1 ${p.x} ${p.y + p.height - ry} Z" fill="${style.fill}" stroke="${style.border}" stroke-width="1.5"/>`
|
|
1347
|
+
);
|
|
1348
|
+
parts.push(`<ellipse cx="${cx}" cy="${p.y + ry}" rx="${p.width / 2}" ry="${ry}" fill="none" stroke="${style.border}" stroke-width="1.5"/>`);
|
|
1349
|
+
} else if (style.shape === "queue") {
|
|
1350
|
+
parts.push(
|
|
1351
|
+
`<rect x="${p.x}" y="${p.y}" width="${p.width}" height="${p.height}" rx="${p.height / 2}" fill="${style.fill}" stroke="${style.border}" stroke-width="1.5"/>`
|
|
1352
|
+
);
|
|
1353
|
+
} else {
|
|
1354
|
+
parts.push(
|
|
1355
|
+
`<rect x="${p.x}" y="${p.y}" width="${p.width}" height="${p.height}" rx="8" fill="${style.fill}" stroke="${style.border}" stroke-width="1.5"/>`
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
const badgeY = p.y + (style.shape === "person" ? 36 : 18);
|
|
1359
|
+
parts.push(`<text x="${cx}" y="${badgeY}" text-anchor="middle" font-size="9" font-style="italic" font-weight="600" fill="${style.text}" opacity="0.85">[${escXml(c4BadgeLabel(el.kind))}]</text>`);
|
|
1360
|
+
parts.push(`<text x="${cx}" y="${badgeY + 18}" text-anchor="middle" font-size="13" font-weight="700" fill="${style.text}">${escXml(el.label)}</text>`);
|
|
1361
|
+
if (el.technology) {
|
|
1362
|
+
parts.push(`<text x="${cx}" y="${badgeY + 32}" text-anchor="middle" font-size="10" font-style="italic" fill="${style.text}" opacity="0.85">[${escXml(el.technology)}]</text>`);
|
|
1363
|
+
}
|
|
1364
|
+
if (el.description) {
|
|
1365
|
+
const lines = wrapText(el.description, 28);
|
|
1366
|
+
const startY = badgeY + (el.technology ? 48 : 36);
|
|
1367
|
+
for (let i = 0; i < Math.min(lines.length, 2); i++) {
|
|
1368
|
+
parts.push(`<text x="${cx}" y="${startY + i * 12}" text-anchor="middle" font-size="10" fill="${style.text}" opacity="0.92">${escXml(lines[i])}</text>`);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return parts.join("");
|
|
1372
|
+
}
|
|
1373
|
+
function buildGitGraphSvg(ir, options = {}) {
|
|
1374
|
+
const { common } = palette(options.dark ?? false);
|
|
1375
|
+
const dark = options.dark ?? false;
|
|
1376
|
+
const padding = options.padding ?? 40;
|
|
1377
|
+
const titleH = ir.title ? 32 : 0;
|
|
1378
|
+
const commits = [];
|
|
1379
|
+
const branchOrder = ["main"];
|
|
1380
|
+
const branchHead = /* @__PURE__ */ new Map();
|
|
1381
|
+
branchHead.set("main", null);
|
|
1382
|
+
let currentBranch = "main";
|
|
1383
|
+
let counter = 0;
|
|
1384
|
+
for (const op of ir.ops) {
|
|
1385
|
+
if (op.kind === "branch") {
|
|
1386
|
+
if (!branchOrder.includes(op.name)) branchOrder.push(op.name);
|
|
1387
|
+
branchHead.set(op.name, branchHead.get(currentBranch) ?? null);
|
|
1388
|
+
currentBranch = op.name;
|
|
1389
|
+
} else if (op.kind === "checkout") {
|
|
1390
|
+
currentBranch = op.name;
|
|
1391
|
+
if (!branchOrder.includes(op.name)) branchOrder.push(op.name);
|
|
1392
|
+
if (!branchHead.has(op.name)) branchHead.set(op.name, null);
|
|
1393
|
+
} else if (op.kind === "commit") {
|
|
1394
|
+
const id = op.id ?? `c${++counter}`;
|
|
1395
|
+
const parent = branchHead.get(currentBranch);
|
|
1396
|
+
const commit = {
|
|
1397
|
+
id,
|
|
1398
|
+
branch: currentBranch,
|
|
1399
|
+
parents: parent ? [parent] : [],
|
|
1400
|
+
tag: op.tag,
|
|
1401
|
+
type: op.type ?? "NORMAL"
|
|
1402
|
+
};
|
|
1403
|
+
commits.push(commit);
|
|
1404
|
+
branchHead.set(currentBranch, id);
|
|
1405
|
+
} else if (op.kind === "merge") {
|
|
1406
|
+
const id = `merge-${++counter}`;
|
|
1407
|
+
const a = branchHead.get(currentBranch);
|
|
1408
|
+
const b = branchHead.get(op.from);
|
|
1409
|
+
const commit = {
|
|
1410
|
+
id,
|
|
1411
|
+
branch: currentBranch,
|
|
1412
|
+
parents: [a, b].filter((p) => !!p),
|
|
1413
|
+
tag: op.tag,
|
|
1414
|
+
type: "NORMAL",
|
|
1415
|
+
isMerge: true
|
|
1416
|
+
};
|
|
1417
|
+
commits.push(commit);
|
|
1418
|
+
branchHead.set(currentBranch, id);
|
|
1419
|
+
} else if (op.kind === "cherry-pick") {
|
|
1420
|
+
const id = `cherry-${++counter}`;
|
|
1421
|
+
const parent = branchHead.get(currentBranch);
|
|
1422
|
+
commits.push({
|
|
1423
|
+
id,
|
|
1424
|
+
branch: currentBranch,
|
|
1425
|
+
parents: parent ? [parent] : [],
|
|
1426
|
+
type: "HIGHLIGHT"
|
|
1427
|
+
});
|
|
1428
|
+
branchHead.set(currentBranch, id);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const BRANCH_GAP = 60;
|
|
1432
|
+
const COMMIT_GAP = 70;
|
|
1433
|
+
const branchIdx = new Map(branchOrder.map((b, i) => [b, i]));
|
|
1434
|
+
const branchX = (b) => padding + 90 + (branchIdx.get(b) ?? 0) * BRANCH_GAP;
|
|
1435
|
+
const commitPositions = /* @__PURE__ */ new Map();
|
|
1436
|
+
commits.forEach((c, i) => {
|
|
1437
|
+
commitPositions.set(c.id, { x: branchX(c.branch), y: padding + titleH + 40 + i * COMMIT_GAP });
|
|
1438
|
+
});
|
|
1439
|
+
const width = padding * 2 + 90 + branchOrder.length * BRANCH_GAP + 200;
|
|
1440
|
+
const height = padding * 2 + titleH + 60 + commits.length * COMMIT_GAP;
|
|
1441
|
+
const branchColors = ["#3b82f6", "#10b981", "#f59e0b", "#f43f5e", "#8b5cf6", "#06b6d4", "#ec4899"];
|
|
1442
|
+
const branchColor = (b) => branchColors[(branchIdx.get(b) ?? 0) % branchColors.length];
|
|
1443
|
+
const parts = [];
|
|
1444
|
+
parts.push(svgOpen(0, 0, width, height, common.canvasBg, ir.title || "Git graph"));
|
|
1445
|
+
if (ir.title) {
|
|
1446
|
+
parts.push(`<text x="${width / 2}" y="22" text-anchor="middle" font-size="15" font-weight="600" fill="${common.text}">${escXml(ir.title)}</text>`);
|
|
1447
|
+
}
|
|
1448
|
+
for (const b of branchOrder) {
|
|
1449
|
+
const x = branchX(b);
|
|
1450
|
+
const y = padding + titleH + 16;
|
|
1451
|
+
parts.push(`<text x="${x}" y="${y}" text-anchor="middle" font-size="11" font-weight="700" fill="${branchColor(b)}">${escXml(b)}</text>`);
|
|
1452
|
+
parts.push(`<line x1="${x}" y1="${y + 8}" x2="${x}" y2="${height - padding}" stroke="${branchColor(b)}" stroke-width="2" opacity="0.3"/>`);
|
|
1453
|
+
}
|
|
1454
|
+
for (const c of commits) {
|
|
1455
|
+
const cp = commitPositions.get(c.id);
|
|
1456
|
+
if (!cp) continue;
|
|
1457
|
+
for (const pid of c.parents) {
|
|
1458
|
+
const pp = commitPositions.get(pid);
|
|
1459
|
+
if (!pp) continue;
|
|
1460
|
+
const sameLane = pp.x === cp.x;
|
|
1461
|
+
const stroke = branchColor(c.branch);
|
|
1462
|
+
if (sameLane) {
|
|
1463
|
+
parts.push(`<line x1="${pp.x}" y1="${pp.y}" x2="${cp.x}" y2="${cp.y}" stroke="${stroke}" stroke-width="2"/>`);
|
|
1464
|
+
} else {
|
|
1465
|
+
const midY = (pp.y + cp.y) / 2;
|
|
1466
|
+
parts.push(`<path d="M ${pp.x} ${pp.y} C ${pp.x} ${midY}, ${cp.x} ${midY}, ${cp.x} ${cp.y}" stroke="${stroke}" stroke-width="2" fill="none"/>`);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
for (const c of commits) {
|
|
1471
|
+
const cp = commitPositions.get(c.id);
|
|
1472
|
+
if (!cp) continue;
|
|
1473
|
+
const color = branchColor(c.branch);
|
|
1474
|
+
const r = 9;
|
|
1475
|
+
if (c.type === "REVERSE") {
|
|
1476
|
+
parts.push(`<rect x="${cp.x - r}" y="${cp.y - r}" width="${r * 2}" height="${r * 2}" fill="${dark ? "#0f172a" : "#ffffff"}" stroke="${color}" stroke-width="2"/>`);
|
|
1477
|
+
} else if (c.type === "HIGHLIGHT") {
|
|
1478
|
+
parts.push(`<rect x="${cp.x - r}" y="${cp.y - r}" width="${r * 2}" height="${r * 2}" rx="3" fill="${color}" stroke="${color}" stroke-width="2"/>`);
|
|
1479
|
+
} else if (c.isMerge) {
|
|
1480
|
+
parts.push(`<circle cx="${cp.x}" cy="${cp.y}" r="${r}" fill="${dark ? "#0f172a" : "#ffffff"}" stroke="${color}" stroke-width="2.5"/>`);
|
|
1481
|
+
parts.push(`<circle cx="${cp.x}" cy="${cp.y}" r="${r - 4}" fill="${color}"/>`);
|
|
1482
|
+
} else {
|
|
1483
|
+
parts.push(`<circle cx="${cp.x}" cy="${cp.y}" r="${r}" fill="${color}" stroke="${dark ? "#0f172a" : "#ffffff"}" stroke-width="2"/>`);
|
|
1484
|
+
}
|
|
1485
|
+
const labelX = padding + 90 + branchOrder.length * BRANCH_GAP + 24;
|
|
1486
|
+
parts.push(`<text x="${labelX}" y="${cp.y + 4}" font-family='${MONO_FAMILY}' font-size="11" fill="${common.text}">${escXml(c.id)}</text>`);
|
|
1487
|
+
if (c.tag) {
|
|
1488
|
+
const tagX = labelX + c.id.length * 7 + 12;
|
|
1489
|
+
parts.push(`<rect x="${tagX}" y="${cp.y - 8}" width="${c.tag.length * 6.5 + 12}" height="16" rx="3" fill="${color}" opacity="0.85"/>`);
|
|
1490
|
+
parts.push(`<text x="${tagX + 6}" y="${cp.y + 4}" font-size="10" font-weight="700" fill="#ffffff">${escXml(c.tag)}</text>`);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
parts.push("</svg>");
|
|
1494
|
+
return parts.join("");
|
|
1495
|
+
}
|
|
1496
|
+
function svgStringToElement(svg) {
|
|
1497
|
+
if (typeof window === "undefined" || !window.DOMParser) return null;
|
|
1498
|
+
const doc = new DOMParser().parseFromString(svg, "image/svg+xml");
|
|
1499
|
+
const root = doc.documentElement;
|
|
1500
|
+
if (root.tagName !== "svg") return null;
|
|
1501
|
+
const imported = document.importNode(root, true);
|
|
1502
|
+
return imported;
|
|
1503
|
+
}
|
|
1504
|
+
var LIGHT_KIND, DARK_KIND, LIGHT_COMMON, DARK_COMMON, FONT_FAMILY, MONO_FAMILY, VIS_SYMBOL, PIE_PALETTE, ARCH_ICON_TINT;
|
|
1505
|
+
var init_svgBuilders = __esm({
|
|
1506
|
+
"src/utils/diagrams/svgBuilders.ts"() {
|
|
1507
|
+
LIGHT_KIND = {
|
|
1508
|
+
service: { border: "#86efac", headerBg: "#ecfdf5", accent: "#10b981", bodyBg: "#ffffff", text: "#064e3b" },
|
|
1509
|
+
database: { border: "#fcd34d", headerBg: "#fffbeb", accent: "#f59e0b", bodyBg: "#ffffff", text: "#78350f" },
|
|
1510
|
+
queue: { border: "#fda4af", headerBg: "#fff1f2", accent: "#f43f5e", bodyBg: "#ffffff", text: "#881337" },
|
|
1511
|
+
storage: { border: "#67e8f9", headerBg: "#ecfeff", accent: "#06b6d4", bodyBg: "#ffffff", text: "#164e63" },
|
|
1512
|
+
user: { border: "#93c5fd", headerBg: "#eff6ff", accent: "#3b82f6", bodyBg: "#ffffff", text: "#1e3a8a" },
|
|
1513
|
+
client: { border: "#c4b5fd", headerBg: "#f5f3ff", accent: "#8b5cf6", bodyBg: "#ffffff", text: "#4c1d95" },
|
|
1514
|
+
external: { border: "#cbd5e1", headerBg: "#f1f5f9", accent: "#64748b", bodyBg: "#ffffff", text: "#334155" },
|
|
1515
|
+
process: { border: "#bfdbfe", headerBg: "#eff6ff", accent: "#60a5fa", bodyBg: "#ffffff", text: "#1e3a8a" },
|
|
1516
|
+
decision: { border: "#c4b5fd", headerBg: "#f5f3ff", accent: "#8b5cf6", bodyBg: "#faf5ff", text: "#4c1d95" },
|
|
1517
|
+
start: { border: "#86efac", headerBg: "#ecfdf5", accent: "#10b981", bodyBg: "#ffffff", text: "#064e3b" },
|
|
1518
|
+
end: { border: "#fda4af", headerBg: "#fff1f2", accent: "#f43f5e", bodyBg: "#ffffff", text: "#881337" },
|
|
1519
|
+
icon: { border: "#cbd5e1", headerBg: "#ffffff", accent: "#64748b", bodyBg: "#ffffff", text: "#1e293b" },
|
|
1520
|
+
plain: { border: "#cbd5e1", headerBg: "#f8fafc", accent: "#64748b", bodyBg: "#ffffff", text: "#1e293b" }
|
|
1521
|
+
};
|
|
1522
|
+
DARK_KIND = {
|
|
1523
|
+
service: { border: "#10b981", headerBg: "rgba(16,185,129,0.12)", accent: "#34d399", bodyBg: "#1e293b", text: "#a7f3d0" },
|
|
1524
|
+
database: { border: "#f59e0b", headerBg: "rgba(245,158,11,0.12)", accent: "#fbbf24", bodyBg: "#1e293b", text: "#fde68a" },
|
|
1525
|
+
queue: { border: "#f43f5e", headerBg: "rgba(244,63,94,0.12)", accent: "#fb7185", bodyBg: "#1e293b", text: "#fecdd3" },
|
|
1526
|
+
storage: { border: "#06b6d4", headerBg: "rgba(6,182,212,0.12)", accent: "#22d3ee", bodyBg: "#1e293b", text: "#a5f3fc" },
|
|
1527
|
+
user: { border: "#3b82f6", headerBg: "rgba(59,130,246,0.12)", accent: "#60a5fa", bodyBg: "#1e293b", text: "#bfdbfe" },
|
|
1528
|
+
client: { border: "#8b5cf6", headerBg: "rgba(139,92,246,0.12)", accent: "#a78bfa", bodyBg: "#1e293b", text: "#ddd6fe" },
|
|
1529
|
+
external: { border: "#64748b", headerBg: "rgba(100,116,139,0.12)", accent: "#94a3b8", bodyBg: "#1e293b", text: "#cbd5e1" },
|
|
1530
|
+
process: { border: "#60a5fa", headerBg: "rgba(96,165,250,0.12)", accent: "#93c5fd", bodyBg: "#1e293b", text: "#bfdbfe" },
|
|
1531
|
+
decision: { border: "#8b5cf6", headerBg: "rgba(139,92,246,0.12)", accent: "#a78bfa", bodyBg: "#1e293b", text: "#ddd6fe" },
|
|
1532
|
+
start: { border: "#10b981", headerBg: "rgba(16,185,129,0.12)", accent: "#34d399", bodyBg: "#1e293b", text: "#a7f3d0" },
|
|
1533
|
+
end: { border: "#f43f5e", headerBg: "rgba(244,63,94,0.12)", accent: "#fb7185", bodyBg: "#1e293b", text: "#fecdd3" },
|
|
1534
|
+
icon: { border: "#475569", headerBg: "#1e293b", accent: "#94a3b8", bodyBg: "#1e293b", text: "#e2e8f0" },
|
|
1535
|
+
plain: { border: "#475569", headerBg: "#1e293b", accent: "#94a3b8", bodyBg: "#1e293b", text: "#e2e8f0" }
|
|
1536
|
+
};
|
|
1537
|
+
LIGHT_COMMON = {
|
|
1538
|
+
canvasBg: "#ffffff",
|
|
1539
|
+
edgeColor: "#94a3b8",
|
|
1540
|
+
edgeLabel: "#475569",
|
|
1541
|
+
edgeLabelBg: "#ffffff",
|
|
1542
|
+
text: "#1e293b",
|
|
1543
|
+
subtle: "#64748b",
|
|
1544
|
+
border: "#cbd5e1"
|
|
1545
|
+
};
|
|
1546
|
+
DARK_COMMON = {
|
|
1547
|
+
canvasBg: "#0f172a",
|
|
1548
|
+
edgeColor: "#64748b",
|
|
1549
|
+
edgeLabel: "#cbd5e1",
|
|
1550
|
+
edgeLabelBg: "#1e293b",
|
|
1551
|
+
text: "#e2e8f0",
|
|
1552
|
+
subtle: "#94a3b8",
|
|
1553
|
+
border: "#475569"
|
|
1554
|
+
};
|
|
1555
|
+
FONT_FAMILY = '"Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif';
|
|
1556
|
+
MONO_FAMILY = '"Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace';
|
|
1557
|
+
VIS_SYMBOL = { public: "+", private: "-", protected: "#", package: "~" };
|
|
1558
|
+
PIE_PALETTE = [
|
|
1559
|
+
"#3b82f6",
|
|
1560
|
+
"#10b981",
|
|
1561
|
+
"#f59e0b",
|
|
1562
|
+
"#ef4444",
|
|
1563
|
+
"#8b5cf6",
|
|
1564
|
+
"#06b6d4",
|
|
1565
|
+
"#ec4899",
|
|
1566
|
+
"#84cc16",
|
|
1567
|
+
"#f97316",
|
|
1568
|
+
"#6366f1",
|
|
1569
|
+
"#14b8a6",
|
|
1570
|
+
"#d946ef"
|
|
1571
|
+
];
|
|
1572
|
+
ARCH_ICON_TINT = {
|
|
1573
|
+
aws: { fill: "#fff5e6", border: "#ff9900" },
|
|
1574
|
+
google: { fill: "#e8f0fe", border: "#4285f4" },
|
|
1575
|
+
azure: { fill: "#e3f2fd", border: "#0078d4" },
|
|
1576
|
+
cloudflare: { fill: "#fff4e0", border: "#f48120" },
|
|
1577
|
+
docker: { fill: "#e7f3ff", border: "#2496ed" },
|
|
1578
|
+
kubernetes: { fill: "#eaf1ff", border: "#326ce5" },
|
|
1579
|
+
redis: { fill: "#fde7e3", border: "#dc382d" },
|
|
1580
|
+
postgresql: { fill: "#e3f2fa", border: "#336791" },
|
|
1581
|
+
mongodb: { fill: "#e8f5e9", border: "#47a248" },
|
|
1582
|
+
cloud: { fill: "#f0f4ff", border: "#6366f1" },
|
|
1583
|
+
database: { fill: "#fff7ed", border: "#f59e0b" },
|
|
1584
|
+
disk: { fill: "#ecfeff", border: "#06b6d4" },
|
|
1585
|
+
server: { fill: "#ecfdf5", border: "#10b981" },
|
|
1586
|
+
internet: { fill: "#eff6ff", border: "#3b82f6" }
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1591
|
+
// src/components/diagrams/FlowchartRenderer.tsx
|
|
1592
|
+
var FlowchartRenderer_exports = {};
|
|
1593
|
+
__export(FlowchartRenderer_exports, {
|
|
1594
|
+
default: () => FlowchartRenderer
|
|
1595
|
+
});
|
|
1596
|
+
function rectSize(label) {
|
|
1597
|
+
const width = Math.max(160, Math.min(320, label.length * 8 + 40));
|
|
1598
|
+
const lines = Math.max(1, Math.ceil(label.length / 24));
|
|
1599
|
+
return { width, height: 48 + (lines - 1) * 18 };
|
|
1600
|
+
}
|
|
1601
|
+
function diamondSize(label) {
|
|
1602
|
+
return {
|
|
1603
|
+
width: Math.max(140, Math.min(280, label.length * 11 + 60)),
|
|
1604
|
+
height: Math.max(96, Math.min(160, Math.ceil(label.length / 16) * 32 + 64))
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
function FlowchartRenderer({ ir, dark = false, handleRef }) {
|
|
1608
|
+
const theme = getDiagramTheme(dark);
|
|
1609
|
+
const containerRef = react.useRef(null);
|
|
1610
|
+
const svg = react.useMemo(() => {
|
|
1611
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
1612
|
+
for (const n of ir.nodes) {
|
|
1613
|
+
if (n.kind === "user" || n.kind === "start" || n.kind === "end") sizes.set(n.id, NODE_SIZE.circle);
|
|
1614
|
+
else if (n.kind === "icon") sizes.set(n.id, NODE_SIZE.icon);
|
|
1615
|
+
else if (n.kind === "decision") sizes.set(n.id, diamondSize(n.label));
|
|
1616
|
+
else if (n.kind === "queue") sizes.set(n.id, NODE_SIZE.subroutine);
|
|
1617
|
+
else sizes.set(n.id, rectSize(n.label));
|
|
1618
|
+
}
|
|
1619
|
+
const layout = layoutFlowchart(ir, { nodeSizes: sizes });
|
|
1620
|
+
return buildFlowchartSvg(ir, layout.nodePositions, { dark });
|
|
1621
|
+
}, [ir, dark]);
|
|
1622
|
+
react.useEffect(() => {
|
|
1623
|
+
if (!handleRef) return;
|
|
1624
|
+
const handle = {
|
|
1625
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
1626
|
+
};
|
|
1627
|
+
handleRef.current = handle;
|
|
1628
|
+
return () => {
|
|
1629
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
1630
|
+
};
|
|
1631
|
+
}, [handleRef, svg]);
|
|
1632
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1633
|
+
"div",
|
|
1634
|
+
{
|
|
1635
|
+
ref: containerRef,
|
|
1636
|
+
className: "flowchart-renderer",
|
|
1637
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
1638
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
1639
|
+
}
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
var NODE_SIZE;
|
|
1643
|
+
var init_FlowchartRenderer = __esm({
|
|
1644
|
+
"src/components/diagrams/FlowchartRenderer.tsx"() {
|
|
1645
|
+
init_dagreLayout();
|
|
1646
|
+
init_theme();
|
|
1647
|
+
init_svgBuilders();
|
|
1648
|
+
NODE_SIZE = {
|
|
1649
|
+
circle: { width: 84, height: 84 },
|
|
1650
|
+
icon: { width: 100, height: 96 },
|
|
1651
|
+
subroutine: { width: 220, height: 64 }
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
|
|
1656
|
+
// src/components/diagrams/ERRenderer.tsx
|
|
1657
|
+
var ERRenderer_exports = {};
|
|
1658
|
+
__export(ERRenderer_exports, {
|
|
1659
|
+
default: () => ERRenderer
|
|
1660
|
+
});
|
|
1661
|
+
function ERRenderer({ ir, dark = false, handleRef }) {
|
|
1662
|
+
const theme = getDiagramTheme(dark);
|
|
1663
|
+
const containerRef = react.useRef(null);
|
|
1664
|
+
const svg = react.useMemo(() => {
|
|
1665
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
1666
|
+
g.setGraph({ rankdir: "LR", nodesep: 60, ranksep: 100, marginx: 24, marginy: 24 });
|
|
1667
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
1668
|
+
const tableHeight = (cols) => TABLE_HEADER_HEIGHT + cols * TABLE_ROW_HEIGHT;
|
|
1669
|
+
for (const table of ir.schema.tables) {
|
|
1670
|
+
g.setNode(table.name, { width: TABLE_NODE_WIDTH, height: tableHeight(table.columns.length) });
|
|
1671
|
+
}
|
|
1672
|
+
for (const rel of ir.schema.relations) {
|
|
1673
|
+
if (g.hasNode(rel.fromTable) && g.hasNode(rel.toTable)) g.setEdge(rel.fromTable, rel.toTable);
|
|
1674
|
+
}
|
|
1675
|
+
dagre2__default.default.layout(g);
|
|
1676
|
+
const positions = /* @__PURE__ */ new Map();
|
|
1677
|
+
for (const table of ir.schema.tables) {
|
|
1678
|
+
const { x, y } = g.node(table.name);
|
|
1679
|
+
const h = tableHeight(table.columns.length);
|
|
1680
|
+
positions.set(table.name, { x: x - TABLE_NODE_WIDTH / 2, y: y - h / 2, width: TABLE_NODE_WIDTH, height: h });
|
|
1681
|
+
}
|
|
1682
|
+
return buildErSvg(ir, positions, { dark });
|
|
1683
|
+
}, [ir, dark]);
|
|
1684
|
+
react.useEffect(() => {
|
|
1685
|
+
if (!handleRef) return;
|
|
1686
|
+
const handle = {
|
|
1687
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
1688
|
+
};
|
|
1689
|
+
handleRef.current = handle;
|
|
1690
|
+
return () => {
|
|
1691
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
1692
|
+
};
|
|
1693
|
+
}, [handleRef, svg]);
|
|
1694
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1695
|
+
"div",
|
|
1696
|
+
{
|
|
1697
|
+
ref: containerRef,
|
|
1698
|
+
className: "er-renderer",
|
|
1699
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
1700
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
1701
|
+
}
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
var TABLE_NODE_WIDTH, TABLE_HEADER_HEIGHT, TABLE_ROW_HEIGHT;
|
|
1705
|
+
var init_ERRenderer = __esm({
|
|
1706
|
+
"src/components/diagrams/ERRenderer.tsx"() {
|
|
1707
|
+
init_theme();
|
|
1708
|
+
init_svgBuilders();
|
|
1709
|
+
TABLE_NODE_WIDTH = 240;
|
|
1710
|
+
TABLE_HEADER_HEIGHT = 34;
|
|
1711
|
+
TABLE_ROW_HEIGHT = 26;
|
|
1712
|
+
}
|
|
1713
|
+
});
|
|
1714
|
+
|
|
1715
|
+
// src/components/diagrams/PieRenderer.tsx
|
|
1716
|
+
var PieRenderer_exports = {};
|
|
1717
|
+
__export(PieRenderer_exports, {
|
|
1718
|
+
default: () => PieRenderer
|
|
1719
|
+
});
|
|
1720
|
+
function PieRenderer({ ir, dark = false, handleRef }) {
|
|
1721
|
+
const theme = getDiagramTheme(dark);
|
|
1722
|
+
const containerRef = react.useRef(null);
|
|
1723
|
+
const svg = react.useMemo(() => buildPieSvg(ir, { dark }), [ir, dark]);
|
|
1724
|
+
react.useEffect(() => {
|
|
1725
|
+
if (!handleRef) return;
|
|
1726
|
+
const handle = {
|
|
1727
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
1728
|
+
};
|
|
1729
|
+
handleRef.current = handle;
|
|
1730
|
+
return () => {
|
|
1731
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
1732
|
+
};
|
|
1733
|
+
}, [handleRef, svg]);
|
|
1734
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1735
|
+
"div",
|
|
1736
|
+
{
|
|
1737
|
+
ref: containerRef,
|
|
1738
|
+
className: "pie-renderer",
|
|
1739
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
1740
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
1741
|
+
}
|
|
1742
|
+
);
|
|
1743
|
+
}
|
|
1744
|
+
var init_PieRenderer = __esm({
|
|
1745
|
+
"src/components/diagrams/PieRenderer.tsx"() {
|
|
1746
|
+
init_theme();
|
|
1747
|
+
init_svgBuilders();
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
|
|
1751
|
+
// src/components/diagrams/QuadrantRenderer.tsx
|
|
1752
|
+
var QuadrantRenderer_exports = {};
|
|
1753
|
+
__export(QuadrantRenderer_exports, {
|
|
1754
|
+
default: () => QuadrantRenderer
|
|
1755
|
+
});
|
|
1756
|
+
function QuadrantRenderer({ ir, dark = false, handleRef }) {
|
|
1757
|
+
const theme = getDiagramTheme(dark);
|
|
1758
|
+
const containerRef = react.useRef(null);
|
|
1759
|
+
const svg = react.useMemo(() => buildQuadrantSvg(ir, { dark }), [ir, dark]);
|
|
1760
|
+
react.useEffect(() => {
|
|
1761
|
+
if (!handleRef) return;
|
|
1762
|
+
const handle = {
|
|
1763
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
1764
|
+
};
|
|
1765
|
+
handleRef.current = handle;
|
|
1766
|
+
return () => {
|
|
1767
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
1768
|
+
};
|
|
1769
|
+
}, [handleRef, svg]);
|
|
1770
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1771
|
+
"div",
|
|
1772
|
+
{
|
|
1773
|
+
ref: containerRef,
|
|
1774
|
+
className: "quadrant-renderer",
|
|
1775
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
1776
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
1777
|
+
}
|
|
1778
|
+
);
|
|
1779
|
+
}
|
|
1780
|
+
var init_QuadrantRenderer = __esm({
|
|
1781
|
+
"src/components/diagrams/QuadrantRenderer.tsx"() {
|
|
1782
|
+
init_theme();
|
|
1783
|
+
init_svgBuilders();
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1786
|
+
|
|
1787
|
+
// src/components/diagrams/JourneyRenderer.tsx
|
|
1788
|
+
var JourneyRenderer_exports = {};
|
|
1789
|
+
__export(JourneyRenderer_exports, {
|
|
1790
|
+
default: () => JourneyRenderer
|
|
1791
|
+
});
|
|
1792
|
+
function JourneyRenderer({ ir, dark = false, handleRef }) {
|
|
1793
|
+
const theme = getDiagramTheme(dark);
|
|
1794
|
+
const containerRef = react.useRef(null);
|
|
1795
|
+
const svg = react.useMemo(() => buildJourneySvg(ir, { dark }), [ir, dark]);
|
|
1796
|
+
react.useEffect(() => {
|
|
1797
|
+
if (!handleRef) return;
|
|
1798
|
+
const handle = {
|
|
1799
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
1800
|
+
};
|
|
1801
|
+
handleRef.current = handle;
|
|
1802
|
+
return () => {
|
|
1803
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
1804
|
+
};
|
|
1805
|
+
}, [handleRef, svg]);
|
|
1806
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1807
|
+
"div",
|
|
1808
|
+
{
|
|
1809
|
+
ref: containerRef,
|
|
1810
|
+
className: "journey-renderer",
|
|
1811
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
1812
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
1813
|
+
}
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
var init_JourneyRenderer = __esm({
|
|
1817
|
+
"src/components/diagrams/JourneyRenderer.tsx"() {
|
|
1818
|
+
init_theme();
|
|
1819
|
+
init_svgBuilders();
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
|
|
1823
|
+
// src/components/diagrams/SequenceRenderer.tsx
|
|
1824
|
+
var SequenceRenderer_exports = {};
|
|
1825
|
+
__export(SequenceRenderer_exports, {
|
|
1826
|
+
default: () => SequenceRenderer
|
|
1827
|
+
});
|
|
1828
|
+
function SequenceRenderer({ ir, dark = false, handleRef }) {
|
|
1829
|
+
const theme = getDiagramTheme(dark);
|
|
1830
|
+
const containerRef = react.useRef(null);
|
|
1831
|
+
const layout = react.useMemo(() => computeLayout(ir.participants, ir.steps), [ir.participants, ir.steps]);
|
|
1832
|
+
react.useEffect(() => {
|
|
1833
|
+
if (!handleRef) return;
|
|
1834
|
+
const handle = {
|
|
1835
|
+
getSvgElement: () => containerRef.current?.querySelector("svg.sequence-svg") ?? null
|
|
1836
|
+
};
|
|
1837
|
+
handleRef.current = handle;
|
|
1838
|
+
return () => {
|
|
1839
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
1840
|
+
};
|
|
1841
|
+
}, [handleRef, layout]);
|
|
1842
|
+
const lifelineColor = dark ? "#475569" : "#cbd5e1";
|
|
1843
|
+
const headFill = dark ? "#1e293b" : "#f1f5f9";
|
|
1844
|
+
const headBorder = dark ? "#475569" : "#cbd5e1";
|
|
1845
|
+
const headText = dark ? "#e2e8f0" : "#1e293b";
|
|
1846
|
+
const arrowColor = dark ? "#94a3b8" : "#64748b";
|
|
1847
|
+
const labelColor = dark ? "#cbd5e1" : "#334155";
|
|
1848
|
+
const noteFill = dark ? "#451a03" : "#fef3c7";
|
|
1849
|
+
const noteBorder = dark ? "#92400e" : "#fcd34d";
|
|
1850
|
+
const noteText = dark ? "#fde68a" : "#78350f";
|
|
1851
|
+
const titleY = ir.title ? TITLE_H : 0;
|
|
1852
|
+
const headTopY = titleY + HEAD_PAD_Y;
|
|
1853
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1854
|
+
"div",
|
|
1855
|
+
{
|
|
1856
|
+
ref: containerRef,
|
|
1857
|
+
className: "sequence-renderer",
|
|
1858
|
+
style: {
|
|
1859
|
+
width: "100%",
|
|
1860
|
+
background: theme.canvasBg,
|
|
1861
|
+
borderRadius: 12,
|
|
1862
|
+
padding: 16,
|
|
1863
|
+
overflow: "auto"
|
|
1864
|
+
},
|
|
1865
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1866
|
+
"svg",
|
|
1867
|
+
{
|
|
1868
|
+
className: "sequence-svg",
|
|
1869
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1870
|
+
width: layout.width,
|
|
1871
|
+
height: layout.height + titleY,
|
|
1872
|
+
viewBox: `0 0 ${layout.width} ${layout.height + titleY}`,
|
|
1873
|
+
style: { display: "block", minWidth: "100%", fontFamily: '"Inter", ui-sans-serif, system-ui, sans-serif' },
|
|
1874
|
+
children: [
|
|
1875
|
+
ir.title && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1876
|
+
"text",
|
|
1877
|
+
{
|
|
1878
|
+
x: layout.width / 2,
|
|
1879
|
+
y: 20,
|
|
1880
|
+
textAnchor: "middle",
|
|
1881
|
+
fontSize: 15,
|
|
1882
|
+
fontWeight: 600,
|
|
1883
|
+
fill: headText,
|
|
1884
|
+
children: ir.title
|
|
1885
|
+
}
|
|
1886
|
+
),
|
|
1887
|
+
ir.participants.map((p) => {
|
|
1888
|
+
const x = layout.participantX.get(p.id);
|
|
1889
|
+
if (x === void 0) return null;
|
|
1890
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1891
|
+
"line",
|
|
1892
|
+
{
|
|
1893
|
+
x1: x,
|
|
1894
|
+
x2: x,
|
|
1895
|
+
y1: headTopY + PART_BOX_H,
|
|
1896
|
+
y2: headTopY + PART_BOX_H + layout.contentH + STEP_GAP,
|
|
1897
|
+
stroke: lifelineColor,
|
|
1898
|
+
strokeWidth: 1,
|
|
1899
|
+
strokeDasharray: "4 4"
|
|
1900
|
+
},
|
|
1901
|
+
`life-${p.id}`
|
|
1902
|
+
);
|
|
1903
|
+
}),
|
|
1904
|
+
ir.participants.map((p) => {
|
|
1905
|
+
const x = layout.participantX.get(p.id);
|
|
1906
|
+
if (x === void 0) return null;
|
|
1907
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
1908
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1909
|
+
"rect",
|
|
1910
|
+
{
|
|
1911
|
+
x: x - PART_BOX_W / 2,
|
|
1912
|
+
y: headTopY,
|
|
1913
|
+
width: PART_BOX_W,
|
|
1914
|
+
height: PART_BOX_H,
|
|
1915
|
+
rx: 6,
|
|
1916
|
+
fill: headFill,
|
|
1917
|
+
stroke: headBorder,
|
|
1918
|
+
strokeWidth: 1
|
|
1919
|
+
}
|
|
1920
|
+
),
|
|
1921
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1922
|
+
"text",
|
|
1923
|
+
{
|
|
1924
|
+
x,
|
|
1925
|
+
y: headTopY + PART_BOX_H / 2 + 4,
|
|
1926
|
+
textAnchor: "middle",
|
|
1927
|
+
fontSize: 12,
|
|
1928
|
+
fontWeight: 600,
|
|
1929
|
+
fill: headText,
|
|
1930
|
+
children: truncate(p.label, 18)
|
|
1931
|
+
}
|
|
1932
|
+
)
|
|
1933
|
+
] }, `head-${p.id}`);
|
|
1934
|
+
}),
|
|
1935
|
+
layout.placedSteps.map((ps, i) => {
|
|
1936
|
+
if (ps.step.kind === "message") {
|
|
1937
|
+
const fromX = layout.participantX.get(ps.step.from);
|
|
1938
|
+
const isSelf = ps.step.from === ps.step.to;
|
|
1939
|
+
const isRightmost = isSelf && fromX === Math.max(...layout.participantX.values());
|
|
1940
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1941
|
+
MessageStep,
|
|
1942
|
+
{
|
|
1943
|
+
msg: ps.step,
|
|
1944
|
+
fromX,
|
|
1945
|
+
toX: layout.participantX.get(ps.step.to),
|
|
1946
|
+
y: headTopY + PART_BOX_H + ps.y,
|
|
1947
|
+
arrowColor,
|
|
1948
|
+
labelColor,
|
|
1949
|
+
selfDirection: isRightmost ? "left" : "right",
|
|
1950
|
+
canvasWidth: layout.width
|
|
1951
|
+
}
|
|
1952
|
+
) }, i);
|
|
1953
|
+
}
|
|
1954
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1955
|
+
NoteStep,
|
|
1956
|
+
{
|
|
1957
|
+
note: ps.step,
|
|
1958
|
+
participantXs: ps.step.participants.map((id) => layout.participantX.get(id)).filter((x) => x !== void 0),
|
|
1959
|
+
y: headTopY + PART_BOX_H + ps.y,
|
|
1960
|
+
fill: noteFill,
|
|
1961
|
+
border: noteBorder,
|
|
1962
|
+
textColor: noteText
|
|
1963
|
+
}
|
|
1964
|
+
) }, i);
|
|
1965
|
+
}),
|
|
1966
|
+
ir.participants.map((p) => {
|
|
1967
|
+
const x = layout.participantX.get(p.id);
|
|
1968
|
+
if (x === void 0) return null;
|
|
1969
|
+
const footY = headTopY + PART_BOX_H + layout.contentH + STEP_GAP - PART_BOX_H / 2;
|
|
1970
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
1971
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1972
|
+
"rect",
|
|
1973
|
+
{
|
|
1974
|
+
x: x - PART_BOX_W / 2,
|
|
1975
|
+
y: footY,
|
|
1976
|
+
width: PART_BOX_W,
|
|
1977
|
+
height: PART_BOX_H,
|
|
1978
|
+
rx: 6,
|
|
1979
|
+
fill: headFill,
|
|
1980
|
+
stroke: headBorder,
|
|
1981
|
+
strokeWidth: 1
|
|
1982
|
+
}
|
|
1983
|
+
),
|
|
1984
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1985
|
+
"text",
|
|
1986
|
+
{
|
|
1987
|
+
x,
|
|
1988
|
+
y: footY + PART_BOX_H / 2 + 4,
|
|
1989
|
+
textAnchor: "middle",
|
|
1990
|
+
fontSize: 12,
|
|
1991
|
+
fontWeight: 600,
|
|
1992
|
+
fill: headText,
|
|
1993
|
+
children: truncate(p.label, 18)
|
|
1994
|
+
}
|
|
1995
|
+
)
|
|
1996
|
+
] }, `foot-${p.id}`);
|
|
1997
|
+
}),
|
|
1998
|
+
/* @__PURE__ */ jsxRuntime.jsx(ArrowDefs, { arrowColor })
|
|
1999
|
+
]
|
|
2000
|
+
}
|
|
2001
|
+
)
|
|
2002
|
+
}
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
function MessageStep({
|
|
2006
|
+
msg,
|
|
2007
|
+
fromX,
|
|
2008
|
+
toX,
|
|
2009
|
+
y,
|
|
2010
|
+
arrowColor,
|
|
2011
|
+
labelColor,
|
|
2012
|
+
selfDirection = "right",
|
|
2013
|
+
canvasWidth
|
|
2014
|
+
}) {
|
|
2015
|
+
const isReply = msg.arrow === "reply";
|
|
2016
|
+
const isAsync = msg.arrow === "async";
|
|
2017
|
+
const isCross = msg.arrow === "cross";
|
|
2018
|
+
const dasharray = isReply ? "5 4" : isAsync ? "8 3" : void 0;
|
|
2019
|
+
const markerEnd = isCross ? "url(#arr-cross)" : isAsync ? "url(#arr-open)" : "url(#arr-solid)";
|
|
2020
|
+
const labelX = (fromX + toX) / 2;
|
|
2021
|
+
const labelY = y - 8;
|
|
2022
|
+
const showSelf = fromX === toX;
|
|
2023
|
+
if (showSelf) {
|
|
2024
|
+
const dir = selfDirection === "left" ? -1 : 1;
|
|
2025
|
+
const loopEndX = fromX + dir * SELF_LOOP_W;
|
|
2026
|
+
const labelText = truncate(msg.label, 28);
|
|
2027
|
+
const charW = 6.2;
|
|
2028
|
+
const approxLabelW = labelText.length * charW;
|
|
2029
|
+
const labelXPos = dir === 1 ? (
|
|
2030
|
+
// loop opens right; label sits to the right of the loop's edge
|
|
2031
|
+
Math.min(loopEndX + 8, (canvasWidth ?? Infinity) - approxLabelW - 4)
|
|
2032
|
+
) : (
|
|
2033
|
+
// loop opens left; label sits to the left of the loop's edge
|
|
2034
|
+
Math.max(loopEndX - approxLabelW - 8, 4)
|
|
2035
|
+
);
|
|
2036
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
2037
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2038
|
+
"path",
|
|
2039
|
+
{
|
|
2040
|
+
d: `M ${fromX} ${y} h ${dir * SELF_LOOP_W} v 22 h ${-dir * SELF_LOOP_W}`,
|
|
2041
|
+
fill: "none",
|
|
2042
|
+
stroke: arrowColor,
|
|
2043
|
+
strokeWidth: 1.4,
|
|
2044
|
+
strokeDasharray: dasharray,
|
|
2045
|
+
markerEnd
|
|
2046
|
+
}
|
|
2047
|
+
),
|
|
2048
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2049
|
+
"text",
|
|
2050
|
+
{
|
|
2051
|
+
x: labelXPos,
|
|
2052
|
+
y: y + 14,
|
|
2053
|
+
fontSize: 11,
|
|
2054
|
+
fill: labelColor,
|
|
2055
|
+
textAnchor: dir === 1 ? "start" : "start",
|
|
2056
|
+
children: labelText
|
|
2057
|
+
}
|
|
2058
|
+
)
|
|
2059
|
+
] });
|
|
2060
|
+
}
|
|
2061
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
2062
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2063
|
+
"text",
|
|
2064
|
+
{
|
|
2065
|
+
x: labelX,
|
|
2066
|
+
y: labelY,
|
|
2067
|
+
textAnchor: "middle",
|
|
2068
|
+
fontSize: 11,
|
|
2069
|
+
fill: labelColor,
|
|
2070
|
+
fontWeight: 500,
|
|
2071
|
+
children: truncate(msg.label, 60)
|
|
2072
|
+
}
|
|
2073
|
+
),
|
|
2074
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2075
|
+
"line",
|
|
2076
|
+
{
|
|
2077
|
+
x1: fromX,
|
|
2078
|
+
x2: toX,
|
|
2079
|
+
y1: y,
|
|
2080
|
+
y2: y,
|
|
2081
|
+
stroke: arrowColor,
|
|
2082
|
+
strokeWidth: 1.4,
|
|
2083
|
+
strokeDasharray: dasharray,
|
|
2084
|
+
markerEnd
|
|
2085
|
+
}
|
|
2086
|
+
)
|
|
2087
|
+
] });
|
|
2088
|
+
}
|
|
2089
|
+
function NoteStep({
|
|
2090
|
+
note,
|
|
2091
|
+
participantXs,
|
|
2092
|
+
y,
|
|
2093
|
+
fill,
|
|
2094
|
+
border,
|
|
2095
|
+
textColor
|
|
2096
|
+
}) {
|
|
2097
|
+
if (participantXs.length === 0) return null;
|
|
2098
|
+
let x = 0;
|
|
2099
|
+
let w = 160;
|
|
2100
|
+
if (note.side === "over") {
|
|
2101
|
+
const min = Math.min(...participantXs);
|
|
2102
|
+
const max = Math.max(...participantXs);
|
|
2103
|
+
w = Math.max(160, max - min + 80);
|
|
2104
|
+
x = min - (w - (max - min)) / 2;
|
|
2105
|
+
} else if (note.side === "left") {
|
|
2106
|
+
x = participantXs[0] - 90 - 60;
|
|
2107
|
+
w = 140;
|
|
2108
|
+
} else {
|
|
2109
|
+
x = participantXs[0] + 60;
|
|
2110
|
+
w = 140;
|
|
2111
|
+
}
|
|
2112
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
2113
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2114
|
+
"rect",
|
|
2115
|
+
{
|
|
2116
|
+
x,
|
|
2117
|
+
y: y - 6,
|
|
2118
|
+
width: w,
|
|
2119
|
+
height: NOTE_H,
|
|
2120
|
+
rx: 4,
|
|
2121
|
+
fill,
|
|
2122
|
+
stroke: border,
|
|
2123
|
+
strokeWidth: 1
|
|
2124
|
+
}
|
|
2125
|
+
),
|
|
2126
|
+
/* @__PURE__ */ jsxRuntime.jsx("text", { x: x + w / 2, y: y + NOTE_H / 2 - 1, textAnchor: "middle", fontSize: 11, fill: textColor, children: truncate(note.text, 50) })
|
|
2127
|
+
] });
|
|
2128
|
+
}
|
|
2129
|
+
function ArrowDefs({ arrowColor }) {
|
|
2130
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
2131
|
+
/* @__PURE__ */ jsxRuntime.jsx("marker", { id: "arr-solid", viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto-start-reverse", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M 0 0 L 10 5 L 0 10 z", fill: arrowColor }) }),
|
|
2132
|
+
/* @__PURE__ */ jsxRuntime.jsx("marker", { id: "arr-open", viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "9", markerHeight: "9", orient: "auto-start-reverse", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M 0 0 L 10 5 L 0 10", fill: "none", stroke: arrowColor, strokeWidth: "1.5" }) }),
|
|
2133
|
+
/* @__PURE__ */ jsxRuntime.jsx("marker", { id: "arr-cross", viewBox: "0 0 10 10", refX: "5", refY: "5", markerWidth: "9", markerHeight: "9", orient: "auto", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M 0 0 L 10 10 M 10 0 L 0 10", stroke: arrowColor, strokeWidth: "1.5" }) })
|
|
2134
|
+
] });
|
|
2135
|
+
}
|
|
2136
|
+
function computeLayout(participants, steps) {
|
|
2137
|
+
const participantX = /* @__PURE__ */ new Map();
|
|
2138
|
+
participants.forEach((p, i) => {
|
|
2139
|
+
participantX.set(p.id, SIDE_PAD + PART_BOX_W / 2 + i * PARTICIPANT_GAP);
|
|
2140
|
+
});
|
|
2141
|
+
const lastX = (participants.length - 1) * PARTICIPANT_GAP + SIDE_PAD * 2 + PART_BOX_W;
|
|
2142
|
+
const placedSteps = [];
|
|
2143
|
+
let y = 36;
|
|
2144
|
+
for (const step of steps) {
|
|
2145
|
+
placedSteps.push({ step, y });
|
|
2146
|
+
y += step.kind === "note" ? NOTE_H + 16 : STEP_GAP;
|
|
2147
|
+
}
|
|
2148
|
+
return {
|
|
2149
|
+
width: lastX,
|
|
2150
|
+
height: HEAD_PAD_Y + PART_BOX_H + y + STEP_GAP + PART_BOX_H + FOOT_HEIGHT,
|
|
2151
|
+
contentH: y,
|
|
2152
|
+
participantX,
|
|
2153
|
+
placedSteps
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
function truncate(s, max) {
|
|
2157
|
+
return s.length <= max ? s : s.slice(0, max - 1) + "\u2026";
|
|
2158
|
+
}
|
|
2159
|
+
var PARTICIPANT_GAP, STEP_GAP, HEAD_PAD_Y, FOOT_HEIGHT, SIDE_PAD, PART_BOX_W, PART_BOX_H, NOTE_H, TITLE_H, SELF_LOOP_W;
|
|
2160
|
+
var init_SequenceRenderer = __esm({
|
|
2161
|
+
"src/components/diagrams/SequenceRenderer.tsx"() {
|
|
2162
|
+
init_theme();
|
|
2163
|
+
PARTICIPANT_GAP = 200;
|
|
2164
|
+
STEP_GAP = 56;
|
|
2165
|
+
HEAD_PAD_Y = 20;
|
|
2166
|
+
FOOT_HEIGHT = 36;
|
|
2167
|
+
SIDE_PAD = 40;
|
|
2168
|
+
PART_BOX_W = 150;
|
|
2169
|
+
PART_BOX_H = 36;
|
|
2170
|
+
NOTE_H = 38;
|
|
2171
|
+
TITLE_H = 28;
|
|
2172
|
+
SELF_LOOP_W = 60;
|
|
2173
|
+
}
|
|
2174
|
+
});
|
|
2175
|
+
|
|
2176
|
+
// src/components/diagrams/ClassRenderer.tsx
|
|
2177
|
+
var ClassRenderer_exports = {};
|
|
2178
|
+
__export(ClassRenderer_exports, {
|
|
2179
|
+
default: () => ClassRenderer
|
|
2180
|
+
});
|
|
2181
|
+
function classBoxSize(memberCount) {
|
|
2182
|
+
return { width: 220, height: Math.max(64, 40 + memberCount * 18) };
|
|
2183
|
+
}
|
|
2184
|
+
function ClassRenderer({ ir, dark = false, handleRef }) {
|
|
2185
|
+
const theme = getDiagramTheme(dark);
|
|
2186
|
+
const containerRef = react.useRef(null);
|
|
2187
|
+
const svg = react.useMemo(() => {
|
|
2188
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
2189
|
+
g.setGraph({ rankdir: "TB", nodesep: 50, ranksep: 80, marginx: 24, marginy: 24 });
|
|
2190
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
2191
|
+
for (const cls of ir.classes) g.setNode(cls.id, classBoxSize(cls.members.length));
|
|
2192
|
+
for (const rel of ir.relations) {
|
|
2193
|
+
if (g.hasNode(rel.source) && g.hasNode(rel.target)) g.setEdge(rel.source, rel.target);
|
|
2194
|
+
}
|
|
2195
|
+
dagre2__default.default.layout(g);
|
|
2196
|
+
const positions = /* @__PURE__ */ new Map();
|
|
2197
|
+
for (const cls of ir.classes) {
|
|
2198
|
+
const { x, y } = g.node(cls.id);
|
|
2199
|
+
const size = classBoxSize(cls.members.length);
|
|
2200
|
+
positions.set(cls.id, { x: x - size.width / 2, y: y - size.height / 2, width: size.width, height: size.height });
|
|
2201
|
+
}
|
|
2202
|
+
return buildClassSvg(ir, positions, { dark });
|
|
2203
|
+
}, [ir, dark]);
|
|
2204
|
+
react.useEffect(() => {
|
|
2205
|
+
if (!handleRef) return;
|
|
2206
|
+
const handle = {
|
|
2207
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2208
|
+
};
|
|
2209
|
+
handleRef.current = handle;
|
|
2210
|
+
return () => {
|
|
2211
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2212
|
+
};
|
|
2213
|
+
}, [handleRef, svg]);
|
|
2214
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2215
|
+
"div",
|
|
2216
|
+
{
|
|
2217
|
+
ref: containerRef,
|
|
2218
|
+
className: "class-renderer",
|
|
2219
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
2220
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2221
|
+
}
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
var init_ClassRenderer = __esm({
|
|
2225
|
+
"src/components/diagrams/ClassRenderer.tsx"() {
|
|
2226
|
+
init_theme();
|
|
2227
|
+
init_svgBuilders();
|
|
2228
|
+
}
|
|
2229
|
+
});
|
|
2230
|
+
|
|
2231
|
+
// src/components/diagrams/StateRenderer.tsx
|
|
2232
|
+
var StateRenderer_exports = {};
|
|
2233
|
+
__export(StateRenderer_exports, {
|
|
2234
|
+
default: () => StateRenderer
|
|
2235
|
+
});
|
|
2236
|
+
function stateNodeSize(s) {
|
|
2237
|
+
if (s.kind === "start" || s.kind === "end") return { width: 80, height: 32 };
|
|
2238
|
+
const len = (s.label || s.id).length;
|
|
2239
|
+
return { width: Math.max(96, len * 9 + 40), height: 44 };
|
|
2240
|
+
}
|
|
2241
|
+
function layoutComposite(parentId, ir) {
|
|
2242
|
+
const children = ir.states.filter((s) => s.parent === parentId);
|
|
2243
|
+
if (children.length === 0) {
|
|
2244
|
+
return { width: 200, height: COMPOSITE_HEADER_HEIGHT + 60, positions: /* @__PURE__ */ new Map() };
|
|
2245
|
+
}
|
|
2246
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
2247
|
+
g.setGraph({ rankdir: "TB", nodesep: 60, ranksep: 70, marginx: 16, marginy: 16 });
|
|
2248
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
2249
|
+
for (const c of children) g.setNode(c.id, stateNodeSize(c));
|
|
2250
|
+
for (const t of ir.transitions) {
|
|
2251
|
+
if (t.parent !== parentId) continue;
|
|
2252
|
+
if (g.hasNode(t.source) && g.hasNode(t.target)) g.setEdge(t.source, t.target);
|
|
2253
|
+
}
|
|
2254
|
+
dagre2__default.default.layout(g);
|
|
2255
|
+
let minLeft = Infinity, minTop = Infinity, maxRight = 0, maxBottom = 0;
|
|
2256
|
+
const tmp = /* @__PURE__ */ new Map();
|
|
2257
|
+
for (const c of children) {
|
|
2258
|
+
const { x, y } = g.node(c.id);
|
|
2259
|
+
const sz = stateNodeSize(c);
|
|
2260
|
+
const left = x - sz.width / 2;
|
|
2261
|
+
const top = y - sz.height / 2;
|
|
2262
|
+
tmp.set(c.id, { x: left, y: top });
|
|
2263
|
+
minLeft = Math.min(minLeft, left);
|
|
2264
|
+
minTop = Math.min(minTop, top);
|
|
2265
|
+
maxRight = Math.max(maxRight, left + sz.width);
|
|
2266
|
+
maxBottom = Math.max(maxBottom, top + sz.height);
|
|
2267
|
+
}
|
|
2268
|
+
const dx = COMPOSITE_PAD - minLeft;
|
|
2269
|
+
const dy = COMPOSITE_HEADER_HEIGHT + COMPOSITE_PAD - minTop;
|
|
2270
|
+
const positions = /* @__PURE__ */ new Map();
|
|
2271
|
+
for (const [id, p] of tmp) positions.set(id, { x: p.x + dx, y: p.y + dy });
|
|
2272
|
+
return {
|
|
2273
|
+
width: maxRight - minLeft + COMPOSITE_PAD * 2,
|
|
2274
|
+
height: maxBottom - minTop + COMPOSITE_HEADER_HEIGHT + COMPOSITE_PAD * 2,
|
|
2275
|
+
positions
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
function StateRenderer({ ir, dark = false, handleRef }) {
|
|
2279
|
+
const theme = getDiagramTheme(dark);
|
|
2280
|
+
const containerRef = react.useRef(null);
|
|
2281
|
+
const svg = react.useMemo(() => {
|
|
2282
|
+
const compositeIds = ir.states.filter((s) => s.kind === "composite").map((s) => s.id);
|
|
2283
|
+
const innerLayouts = /* @__PURE__ */ new Map();
|
|
2284
|
+
for (const id of compositeIds) innerLayouts.set(id, layoutComposite(id, ir));
|
|
2285
|
+
const buildPositions = { topLevel: /* @__PURE__ */ new Map(), children: /* @__PURE__ */ new Map() };
|
|
2286
|
+
const topLevel = ir.states.filter((s) => !s.parent);
|
|
2287
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
2288
|
+
g.setGraph({ rankdir: "TB", nodesep: 80, ranksep: 90, marginx: 32, marginy: 32 });
|
|
2289
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
2290
|
+
for (const s of topLevel) {
|
|
2291
|
+
if (s.kind === "composite") {
|
|
2292
|
+
const inner = innerLayouts.get(s.id);
|
|
2293
|
+
g.setNode(s.id, { width: inner.width, height: inner.height });
|
|
2294
|
+
} else {
|
|
2295
|
+
g.setNode(s.id, stateNodeSize(s));
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
for (const t of ir.transitions) {
|
|
2299
|
+
if (t.parent) continue;
|
|
2300
|
+
if (g.hasNode(t.source) && g.hasNode(t.target)) g.setEdge(t.source, t.target);
|
|
2301
|
+
}
|
|
2302
|
+
dagre2__default.default.layout(g);
|
|
2303
|
+
for (const s of topLevel) {
|
|
2304
|
+
const { x, y } = g.node(s.id);
|
|
2305
|
+
if (s.kind === "composite") {
|
|
2306
|
+
const inner = innerLayouts.get(s.id);
|
|
2307
|
+
buildPositions.topLevel.set(s.id, {
|
|
2308
|
+
x: x - inner.width / 2,
|
|
2309
|
+
y: y - inner.height / 2,
|
|
2310
|
+
width: inner.width,
|
|
2311
|
+
height: inner.height
|
|
2312
|
+
});
|
|
2313
|
+
} else {
|
|
2314
|
+
const size = stateNodeSize(s);
|
|
2315
|
+
buildPositions.topLevel.set(s.id, {
|
|
2316
|
+
x: x - size.width / 2,
|
|
2317
|
+
y: y - size.height / 2,
|
|
2318
|
+
width: size.width,
|
|
2319
|
+
height: size.height
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
for (const compId of compositeIds) {
|
|
2324
|
+
const inner = innerLayouts.get(compId);
|
|
2325
|
+
const children = ir.states.filter((s) => s.parent === compId);
|
|
2326
|
+
for (const c of children) {
|
|
2327
|
+
const pos = inner.positions.get(c.id);
|
|
2328
|
+
if (!pos) continue;
|
|
2329
|
+
const size = stateNodeSize(c);
|
|
2330
|
+
buildPositions.children.set(c.id, {
|
|
2331
|
+
x: pos.x,
|
|
2332
|
+
y: pos.y,
|
|
2333
|
+
width: size.width,
|
|
2334
|
+
height: size.height,
|
|
2335
|
+
parent: compId
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
return buildStateSvg(ir, buildPositions, { dark });
|
|
2340
|
+
}, [ir, dark]);
|
|
2341
|
+
react.useEffect(() => {
|
|
2342
|
+
if (!handleRef) return;
|
|
2343
|
+
const handle = {
|
|
2344
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2345
|
+
};
|
|
2346
|
+
handleRef.current = handle;
|
|
2347
|
+
return () => {
|
|
2348
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2349
|
+
};
|
|
2350
|
+
}, [handleRef, svg]);
|
|
2351
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2352
|
+
"div",
|
|
2353
|
+
{
|
|
2354
|
+
ref: containerRef,
|
|
2355
|
+
className: "state-renderer",
|
|
2356
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
2357
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2358
|
+
}
|
|
2359
|
+
);
|
|
2360
|
+
}
|
|
2361
|
+
var COMPOSITE_HEADER_HEIGHT, COMPOSITE_PAD;
|
|
2362
|
+
var init_StateRenderer = __esm({
|
|
2363
|
+
"src/components/diagrams/StateRenderer.tsx"() {
|
|
2364
|
+
init_theme();
|
|
2365
|
+
init_svgBuilders();
|
|
2366
|
+
COMPOSITE_HEADER_HEIGHT = 32;
|
|
2367
|
+
COMPOSITE_PAD = 18;
|
|
2368
|
+
}
|
|
2369
|
+
});
|
|
2370
|
+
|
|
2371
|
+
// src/components/diagrams/GanttRenderer.tsx
|
|
2372
|
+
var GanttRenderer_exports = {};
|
|
2373
|
+
__export(GanttRenderer_exports, {
|
|
2374
|
+
default: () => GanttRenderer
|
|
2375
|
+
});
|
|
2376
|
+
function GanttRenderer({ ir, dark = false, handleRef }) {
|
|
2377
|
+
const theme = getDiagramTheme(dark);
|
|
2378
|
+
const containerRef = react.useRef(null);
|
|
2379
|
+
const svg = react.useMemo(() => buildGanttSvg(ir, { dark }), [ir, dark]);
|
|
2380
|
+
react.useEffect(() => {
|
|
2381
|
+
if (!handleRef) return;
|
|
2382
|
+
const handle = {
|
|
2383
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2384
|
+
};
|
|
2385
|
+
handleRef.current = handle;
|
|
2386
|
+
return () => {
|
|
2387
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2388
|
+
};
|
|
2389
|
+
}, [handleRef, svg]);
|
|
2390
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2391
|
+
"div",
|
|
2392
|
+
{
|
|
2393
|
+
ref: containerRef,
|
|
2394
|
+
className: "gantt-renderer",
|
|
2395
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflowX: "auto" },
|
|
2396
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2397
|
+
}
|
|
2398
|
+
);
|
|
2399
|
+
}
|
|
2400
|
+
var init_GanttRenderer = __esm({
|
|
2401
|
+
"src/components/diagrams/GanttRenderer.tsx"() {
|
|
2402
|
+
init_theme();
|
|
2403
|
+
init_svgBuilders();
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
2406
|
+
|
|
2407
|
+
// src/components/diagrams/TimelineRenderer.tsx
|
|
2408
|
+
var TimelineRenderer_exports = {};
|
|
2409
|
+
__export(TimelineRenderer_exports, {
|
|
2410
|
+
default: () => TimelineRenderer
|
|
2411
|
+
});
|
|
2412
|
+
function TimelineRenderer({ ir, dark = false, handleRef }) {
|
|
2413
|
+
const theme = getDiagramTheme(dark);
|
|
2414
|
+
const containerRef = react.useRef(null);
|
|
2415
|
+
const svg = react.useMemo(() => buildTimelineSvg(ir, { dark }), [ir, dark]);
|
|
2416
|
+
react.useEffect(() => {
|
|
2417
|
+
if (!handleRef) return;
|
|
2418
|
+
const handle = {
|
|
2419
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2420
|
+
};
|
|
2421
|
+
handleRef.current = handle;
|
|
2422
|
+
return () => {
|
|
2423
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2424
|
+
};
|
|
2425
|
+
}, [handleRef, svg]);
|
|
2426
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2427
|
+
"div",
|
|
2428
|
+
{
|
|
2429
|
+
ref: containerRef,
|
|
2430
|
+
className: "timeline-renderer",
|
|
2431
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflowX: "auto" },
|
|
2432
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2433
|
+
}
|
|
2434
|
+
);
|
|
2435
|
+
}
|
|
2436
|
+
var init_TimelineRenderer = __esm({
|
|
2437
|
+
"src/components/diagrams/TimelineRenderer.tsx"() {
|
|
2438
|
+
init_theme();
|
|
2439
|
+
init_svgBuilders();
|
|
2440
|
+
}
|
|
2441
|
+
});
|
|
2442
|
+
|
|
2443
|
+
// src/components/diagrams/MindmapRenderer.tsx
|
|
2444
|
+
var MindmapRenderer_exports = {};
|
|
2445
|
+
__export(MindmapRenderer_exports, {
|
|
2446
|
+
default: () => MindmapRenderer
|
|
2447
|
+
});
|
|
2448
|
+
function radialLayout(root) {
|
|
2449
|
+
const positioned = [];
|
|
2450
|
+
const RING_DISTANCE = 180;
|
|
2451
|
+
const place = (node, depth, startAngle, endAngle) => {
|
|
2452
|
+
const angle = (startAngle + endAngle) / 2;
|
|
2453
|
+
const x = depth === 0 ? 0 : Math.cos(angle) * RING_DISTANCE * depth;
|
|
2454
|
+
const y = depth === 0 ? 0 : Math.sin(angle) * RING_DISTANCE * depth;
|
|
2455
|
+
positioned.push({ id: node.id, node, x, y, depth });
|
|
2456
|
+
if (node.children.length === 0) return;
|
|
2457
|
+
const span = endAngle - startAngle;
|
|
2458
|
+
const slice = span / node.children.length;
|
|
2459
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
2460
|
+
place(node.children[i], depth + 1, startAngle + i * slice, startAngle + (i + 1) * slice);
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
place(root, 0, 0, Math.PI * 2);
|
|
2464
|
+
let minX = 0, minY = 0, maxX = 0, maxY = 0;
|
|
2465
|
+
for (const p of positioned) {
|
|
2466
|
+
if (p.x < minX) minX = p.x;
|
|
2467
|
+
if (p.y < minY) minY = p.y;
|
|
2468
|
+
if (p.x > maxX) maxX = p.x;
|
|
2469
|
+
if (p.y > maxY) maxY = p.y;
|
|
2470
|
+
}
|
|
2471
|
+
for (const p of positioned) {
|
|
2472
|
+
p.x = p.x - minX + 200;
|
|
2473
|
+
p.y = p.y - minY + 100;
|
|
2474
|
+
}
|
|
2475
|
+
return { positioned, bounds: { w: maxX - minX + 400, h: maxY - minY + 200 } };
|
|
2476
|
+
}
|
|
2477
|
+
function MindmapRenderer({ ir, dark = false, handleRef }) {
|
|
2478
|
+
const theme = getDiagramTheme(dark);
|
|
2479
|
+
const containerRef = react.useRef(null);
|
|
2480
|
+
const svg = react.useMemo(() => {
|
|
2481
|
+
const { positioned } = radialLayout(ir.root);
|
|
2482
|
+
const positions = /* @__PURE__ */ new Map();
|
|
2483
|
+
for (const p of positioned) {
|
|
2484
|
+
const isRoot = p.depth === 0;
|
|
2485
|
+
const labelLen = p.node.label.length;
|
|
2486
|
+
const w = Math.max(isRoot ? 100 : 70, labelLen * (isRoot ? 9 : 7) + 40);
|
|
2487
|
+
const h = isRoot ? 44 : 32;
|
|
2488
|
+
positions.set(p.id, { x: p.x, y: p.y, width: w, height: h, depth: p.depth });
|
|
2489
|
+
}
|
|
2490
|
+
return buildMindmapSvg(ir, positions, { dark });
|
|
2491
|
+
}, [ir, dark]);
|
|
2492
|
+
react.useEffect(() => {
|
|
2493
|
+
if (!handleRef) return;
|
|
2494
|
+
const handle = {
|
|
2495
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2496
|
+
};
|
|
2497
|
+
handleRef.current = handle;
|
|
2498
|
+
return () => {
|
|
2499
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2500
|
+
};
|
|
2501
|
+
}, [handleRef, svg]);
|
|
2502
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2503
|
+
"div",
|
|
2504
|
+
{
|
|
2505
|
+
ref: containerRef,
|
|
2506
|
+
className: "mindmap-renderer",
|
|
2507
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
2508
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2509
|
+
}
|
|
2510
|
+
);
|
|
2511
|
+
}
|
|
2512
|
+
var init_MindmapRenderer = __esm({
|
|
2513
|
+
"src/components/diagrams/MindmapRenderer.tsx"() {
|
|
2514
|
+
init_theme();
|
|
2515
|
+
init_svgBuilders();
|
|
2516
|
+
}
|
|
2517
|
+
});
|
|
2518
|
+
|
|
2519
|
+
// src/components/diagrams/ArchitectureRenderer.tsx
|
|
2520
|
+
var ArchitectureRenderer_exports = {};
|
|
2521
|
+
__export(ArchitectureRenderer_exports, {
|
|
2522
|
+
default: () => ArchitectureRenderer
|
|
2523
|
+
});
|
|
2524
|
+
function ArchitectureRenderer({ ir, dark = false, handleRef }) {
|
|
2525
|
+
const theme = getDiagramTheme(dark);
|
|
2526
|
+
const containerRef = react.useRef(null);
|
|
2527
|
+
const svg = react.useMemo(() => buildArchitectureSvg(ir, { dark }), [ir, dark]);
|
|
2528
|
+
react.useEffect(() => {
|
|
2529
|
+
if (!handleRef) return;
|
|
2530
|
+
const handle = {
|
|
2531
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2532
|
+
};
|
|
2533
|
+
handleRef.current = handle;
|
|
2534
|
+
return () => {
|
|
2535
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2536
|
+
};
|
|
2537
|
+
}, [handleRef, svg]);
|
|
2538
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2539
|
+
"div",
|
|
2540
|
+
{
|
|
2541
|
+
ref: containerRef,
|
|
2542
|
+
className: "architecture-renderer",
|
|
2543
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
2544
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2545
|
+
}
|
|
2546
|
+
);
|
|
2547
|
+
}
|
|
2548
|
+
var init_ArchitectureRenderer = __esm({
|
|
2549
|
+
"src/components/diagrams/ArchitectureRenderer.tsx"() {
|
|
2550
|
+
init_theme();
|
|
2551
|
+
init_svgBuilders();
|
|
2552
|
+
}
|
|
2553
|
+
});
|
|
2554
|
+
|
|
2555
|
+
// src/components/diagrams/C4Renderer.tsx
|
|
2556
|
+
var C4Renderer_exports = {};
|
|
2557
|
+
__export(C4Renderer_exports, {
|
|
2558
|
+
default: () => C4Renderer
|
|
2559
|
+
});
|
|
2560
|
+
function C4Renderer({ ir, dark = false, handleRef }) {
|
|
2561
|
+
const theme = getDiagramTheme(dark);
|
|
2562
|
+
const containerRef = react.useRef(null);
|
|
2563
|
+
const svg = react.useMemo(() => buildC4Svg(ir, { dark }), [ir, dark]);
|
|
2564
|
+
react.useEffect(() => {
|
|
2565
|
+
if (!handleRef) return;
|
|
2566
|
+
const handle = {
|
|
2567
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2568
|
+
};
|
|
2569
|
+
handleRef.current = handle;
|
|
2570
|
+
return () => {
|
|
2571
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2572
|
+
};
|
|
2573
|
+
}, [handleRef, svg]);
|
|
2574
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2575
|
+
"div",
|
|
2576
|
+
{
|
|
2577
|
+
ref: containerRef,
|
|
2578
|
+
className: "c4-renderer",
|
|
2579
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
2580
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2581
|
+
}
|
|
2582
|
+
);
|
|
2583
|
+
}
|
|
2584
|
+
var init_C4Renderer = __esm({
|
|
2585
|
+
"src/components/diagrams/C4Renderer.tsx"() {
|
|
2586
|
+
init_theme();
|
|
2587
|
+
init_svgBuilders();
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
|
|
2591
|
+
// src/components/diagrams/GitGraphRenderer.tsx
|
|
2592
|
+
var GitGraphRenderer_exports = {};
|
|
2593
|
+
__export(GitGraphRenderer_exports, {
|
|
2594
|
+
default: () => GitGraphRenderer
|
|
2595
|
+
});
|
|
2596
|
+
function GitGraphRenderer({ ir, dark = false, handleRef }) {
|
|
2597
|
+
const theme = getDiagramTheme(dark);
|
|
2598
|
+
const containerRef = react.useRef(null);
|
|
2599
|
+
const svg = react.useMemo(() => buildGitGraphSvg(ir, { dark }), [ir, dark]);
|
|
2600
|
+
react.useEffect(() => {
|
|
2601
|
+
if (!handleRef) return;
|
|
2602
|
+
const handle = {
|
|
2603
|
+
getSvgElement: () => svgStringToElement(svg)
|
|
2604
|
+
};
|
|
2605
|
+
handleRef.current = handle;
|
|
2606
|
+
return () => {
|
|
2607
|
+
if (handleRef.current === handle) handleRef.current = null;
|
|
2608
|
+
};
|
|
2609
|
+
}, [handleRef, svg]);
|
|
2610
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2611
|
+
"div",
|
|
2612
|
+
{
|
|
2613
|
+
ref: containerRef,
|
|
2614
|
+
className: "gitgraph-renderer",
|
|
2615
|
+
style: { width: "100%", background: theme.canvasBg, borderRadius: 12, padding: 12, overflow: "auto" },
|
|
2616
|
+
dangerouslySetInnerHTML: { __html: svg }
|
|
2617
|
+
}
|
|
2618
|
+
);
|
|
2619
|
+
}
|
|
2620
|
+
var init_GitGraphRenderer = __esm({
|
|
2621
|
+
"src/components/diagrams/GitGraphRenderer.tsx"() {
|
|
2622
|
+
init_theme();
|
|
2623
|
+
init_svgBuilders();
|
|
2624
|
+
}
|
|
2625
|
+
});
|
|
2626
|
+
|
|
2627
|
+
// src/utils/diagrams/parser.ts
|
|
2628
|
+
var HEADER_KEYWORDS = [
|
|
2629
|
+
{ re: /^(flowchart|graph)\b/i, type: "flowchart" },
|
|
2630
|
+
{ re: /^erdiagram\b/i, type: "er" },
|
|
2631
|
+
{ re: /^sequencediagram\b/i, type: "sequence" },
|
|
2632
|
+
{ re: /^classdiagram\b/i, type: "class" },
|
|
2633
|
+
{ re: /^statediagram(-v2)?\b/i, type: "state" },
|
|
2634
|
+
{ re: /^gantt\b/i, type: "gantt" },
|
|
2635
|
+
{ re: /^pie\b/i, type: "pie" },
|
|
2636
|
+
{ re: /^quadrantchart\b/i, type: "quadrant" },
|
|
2637
|
+
{ re: /^mindmap\b/i, type: "mindmap" },
|
|
2638
|
+
{ re: /^gitgraph\b/i, type: "gitgraph" },
|
|
2639
|
+
{ re: /^timeline\b/i, type: "timeline" },
|
|
2640
|
+
{ re: /^journey\b/i, type: "journey" },
|
|
2641
|
+
{ re: /^c4(context|container|component|deployment)/i, type: "c4" },
|
|
2642
|
+
{ re: /^architecture(-beta)?\b/i, type: "architecture" }
|
|
2643
|
+
];
|
|
2644
|
+
async function detectDiagramType(source) {
|
|
2645
|
+
const clean = source.replace(/^/, "");
|
|
2646
|
+
const firstLine = clean.split("\n").map((l) => l.trim()).find((l) => l.length > 0 && !l.startsWith("%%"));
|
|
2647
|
+
if (!firstLine) return null;
|
|
2648
|
+
for (const { re, type } of HEADER_KEYWORDS) {
|
|
2649
|
+
if (re.test(firstLine)) return type;
|
|
2650
|
+
}
|
|
2651
|
+
return "unsupported";
|
|
2652
|
+
}
|
|
2653
|
+
async function parseToIR(source) {
|
|
2654
|
+
const type = await detectDiagramType(source);
|
|
2655
|
+
if (type === null) {
|
|
2656
|
+
return { ok: false, source, error: "Empty or whitespace-only source" };
|
|
2657
|
+
}
|
|
2658
|
+
if (type === "unsupported") {
|
|
2659
|
+
return { ok: false, source, error: "Unrecognized diagram type" };
|
|
2660
|
+
}
|
|
2661
|
+
try {
|
|
2662
|
+
switch (type) {
|
|
2663
|
+
case "flowchart":
|
|
2664
|
+
return { ok: true, type, ir: parseFlowchart(source) };
|
|
2665
|
+
case "pie":
|
|
2666
|
+
return { ok: true, type, ir: parsePieChart(source) };
|
|
2667
|
+
case "quadrant":
|
|
2668
|
+
return { ok: true, type, ir: parseQuadrantChart(source) };
|
|
2669
|
+
case "journey":
|
|
2670
|
+
return { ok: true, type, ir: parseJourney(source) };
|
|
2671
|
+
case "sequence":
|
|
2672
|
+
return { ok: true, type, ir: parseSequence(source) };
|
|
2673
|
+
case "class":
|
|
2674
|
+
return { ok: true, type, ir: parseClassDiagram(source) };
|
|
2675
|
+
case "state":
|
|
2676
|
+
return { ok: true, type, ir: parseStateDiagram(source) };
|
|
2677
|
+
case "er":
|
|
2678
|
+
return { ok: true, type, ir: parseMermaidERDiagram(source) };
|
|
2679
|
+
case "gantt":
|
|
2680
|
+
return { ok: true, type, ir: parseGantt(source) };
|
|
2681
|
+
case "timeline":
|
|
2682
|
+
return { ok: true, type, ir: parseTimeline(source) };
|
|
2683
|
+
case "mindmap":
|
|
2684
|
+
return { ok: true, type, ir: parseMindmap(source) };
|
|
2685
|
+
case "architecture":
|
|
2686
|
+
return { ok: true, type, ir: parseArchitecture(source) };
|
|
2687
|
+
case "c4":
|
|
2688
|
+
return { ok: true, type, ir: parseC4(source) };
|
|
2689
|
+
case "gitgraph":
|
|
2690
|
+
return { ok: true, type, ir: parseGitGraph(source) };
|
|
2691
|
+
}
|
|
2692
|
+
return { ok: false, source, error: `Unhandled diagram type: ${String(type)}` };
|
|
2693
|
+
} catch (err) {
|
|
2694
|
+
return {
|
|
2695
|
+
ok: false,
|
|
2696
|
+
source,
|
|
2697
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
var HEADER_RE = /^(?:flowchart|graph)\s+(TB|TD|BT|LR|RL)\b/i;
|
|
2702
|
+
var SUBGRAPH_OPEN_RE = /^subgraph\s+([\w-]+)(?:\s*\[(.+?)\])?/i;
|
|
2703
|
+
var EDGE_LINE_REGEX = /-{2,}>|-{2,}|-\.-+>|\.-+>|={2,}>|-{2,}-|=={2,}|~~~/;
|
|
2704
|
+
function parseFlowchart(source) {
|
|
2705
|
+
const rawLines = source.split("\n");
|
|
2706
|
+
if (rawLines.length === 0) throw new Error("Empty flowchart source");
|
|
2707
|
+
let direction = "TB";
|
|
2708
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
2709
|
+
const edges = [];
|
|
2710
|
+
const subgraphs = [];
|
|
2711
|
+
const subgraphStack = [];
|
|
2712
|
+
const ensureNode = (decl) => {
|
|
2713
|
+
const existing = nodes.get(decl.id);
|
|
2714
|
+
if (existing) {
|
|
2715
|
+
if (decl.label && (decl.label !== decl.id || !existing.label)) existing.label = decl.label;
|
|
2716
|
+
if (decl.kind !== "plain" && existing.kind === "plain") existing.kind = decl.kind;
|
|
2717
|
+
if (decl.icon) {
|
|
2718
|
+
existing.icon = decl.icon;
|
|
2719
|
+
existing.kind = "icon";
|
|
2720
|
+
}
|
|
2721
|
+
return existing;
|
|
2722
|
+
}
|
|
2723
|
+
const node = {
|
|
2724
|
+
id: decl.id,
|
|
2725
|
+
label: decl.label,
|
|
2726
|
+
kind: decl.icon ? "icon" : decl.kind
|
|
2727
|
+
};
|
|
2728
|
+
if (decl.icon) node.icon = decl.icon;
|
|
2729
|
+
if (subgraphStack.length > 0) node.subgraph = subgraphStack[subgraphStack.length - 1];
|
|
2730
|
+
nodes.set(decl.id, node);
|
|
2731
|
+
return node;
|
|
2732
|
+
};
|
|
2733
|
+
for (let i = 0; i < rawLines.length; i++) {
|
|
2734
|
+
const line = rawLines[i].trim();
|
|
2735
|
+
if (!line || line.startsWith("%%")) continue;
|
|
2736
|
+
if (i === 0 || nodes.size === 0 && edges.length === 0 && subgraphs.length === 0) {
|
|
2737
|
+
const m = line.match(HEADER_RE);
|
|
2738
|
+
if (m) {
|
|
2739
|
+
const dir = m[1].toUpperCase();
|
|
2740
|
+
direction = dir === "TD" ? "TB" : dir;
|
|
2741
|
+
continue;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
const subOpen = line.match(SUBGRAPH_OPEN_RE);
|
|
2745
|
+
if (subOpen) {
|
|
2746
|
+
const id = subOpen[1];
|
|
2747
|
+
const label = subOpen[2] ?? id;
|
|
2748
|
+
subgraphs.push({ id, label });
|
|
2749
|
+
subgraphStack.push(id);
|
|
2750
|
+
continue;
|
|
2751
|
+
}
|
|
2752
|
+
if (/^end\b/i.test(line)) {
|
|
2753
|
+
subgraphStack.pop();
|
|
2754
|
+
continue;
|
|
2755
|
+
}
|
|
2756
|
+
if (/^(direction|class|classDef|style|linkStyle|click)\b/i.test(line)) continue;
|
|
2757
|
+
if (EDGE_LINE_REGEX.test(line)) {
|
|
2758
|
+
const edge = parseEdge(line);
|
|
2759
|
+
if (edge) {
|
|
2760
|
+
const fromTokens = edge.from.split(/\s*&\s*/).filter(Boolean);
|
|
2761
|
+
const toTokens = edge.to.split(/\s*&\s*/).filter(Boolean);
|
|
2762
|
+
for (const f of fromTokens) {
|
|
2763
|
+
const fromDecl = parseNodeDecl(f);
|
|
2764
|
+
if (!fromDecl.id) continue;
|
|
2765
|
+
ensureNode(fromDecl);
|
|
2766
|
+
for (const t of toTokens) {
|
|
2767
|
+
const toDecl = parseNodeDecl(t);
|
|
2768
|
+
if (!toDecl.id) continue;
|
|
2769
|
+
ensureNode(toDecl);
|
|
2770
|
+
const e = { source: fromDecl.id, target: toDecl.id, kind: edge.kind };
|
|
2771
|
+
if (edge.label) e.label = edge.label;
|
|
2772
|
+
edges.push(e);
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
continue;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
const decl = parseNodeDecl(line);
|
|
2779
|
+
if (decl.id) ensureNode(decl);
|
|
2780
|
+
}
|
|
2781
|
+
for (const sg of subgraphs) nodes.delete(sg.id);
|
|
2782
|
+
return {
|
|
2783
|
+
type: "flowchart",
|
|
2784
|
+
direction,
|
|
2785
|
+
nodes: [...nodes.values()],
|
|
2786
|
+
edges,
|
|
2787
|
+
subgraphs
|
|
2788
|
+
};
|
|
2789
|
+
}
|
|
2790
|
+
function splitClassDirective(text) {
|
|
2791
|
+
const idx = text.indexOf(":::");
|
|
2792
|
+
if (idx === -1) return { core: text };
|
|
2793
|
+
const core = text.slice(0, idx).trim();
|
|
2794
|
+
const rest = text.slice(idx + 3).trim();
|
|
2795
|
+
const iconMatch = rest.match(/(?:^|[\s,])icon\s*=\s*([\w:_-]+)/);
|
|
2796
|
+
return { core, icon: iconMatch?.[1] };
|
|
2797
|
+
}
|
|
2798
|
+
function parseNodeDecl(text) {
|
|
2799
|
+
const trimmed = text.trim();
|
|
2800
|
+
const { core, icon } = splitClassDirective(trimmed);
|
|
2801
|
+
const shapes = [
|
|
2802
|
+
{ re: /^([\w-]+)\(\(([^)]*)\)\)$/, kind: "user" },
|
|
2803
|
+
// ((circle))
|
|
2804
|
+
{ re: /^([\w-]+)\[\(([^)]*)\)\]$/, kind: "database" },
|
|
2805
|
+
// [(cylinder)]
|
|
2806
|
+
{ re: /^([\w-]+)\[\[([^\]]*)\]\]$/, kind: "queue" },
|
|
2807
|
+
// [[subroutine]]
|
|
2808
|
+
{ re: /^([\w-]+)\[\/([^/]*)\/\]$/, kind: "process" },
|
|
2809
|
+
// [/parallelogram/]
|
|
2810
|
+
{ re: /^([\w-]+)\[\\([^\\]*)\\\]$/, kind: "process" },
|
|
2811
|
+
// [\..\]
|
|
2812
|
+
{ re: /^([\w-]+)\{([^}]*)\}$/, kind: "decision" },
|
|
2813
|
+
// {decision}
|
|
2814
|
+
{ re: /^([\w-]+)>([^\]]*)\]$/, kind: "plain" },
|
|
2815
|
+
// >tag]
|
|
2816
|
+
{ re: /^([\w-]+)\(([^)]*)\)$/, kind: "service" },
|
|
2817
|
+
// (rounded)
|
|
2818
|
+
{ re: /^([\w-]+)\[([^\]]*)\]$/, kind: "process" }
|
|
2819
|
+
// [rect]
|
|
2820
|
+
];
|
|
2821
|
+
for (const { re, kind } of shapes) {
|
|
2822
|
+
const m = core.match(re);
|
|
2823
|
+
if (m) {
|
|
2824
|
+
return {
|
|
2825
|
+
id: m[1],
|
|
2826
|
+
label: stripQuotes(m[2]) || m[1],
|
|
2827
|
+
kind,
|
|
2828
|
+
icon
|
|
2829
|
+
};
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
const bare = core.match(/^([\w-]+)$/);
|
|
2833
|
+
if (bare) {
|
|
2834
|
+
return { id: bare[1], label: bare[1], kind: "plain", icon };
|
|
2835
|
+
}
|
|
2836
|
+
return { id: "", label: "", kind: "plain" };
|
|
2837
|
+
}
|
|
2838
|
+
function stripQuotes(s) {
|
|
2839
|
+
if (s.startsWith('"') && s.endsWith('"') || s.startsWith("'") && s.endsWith("'")) {
|
|
2840
|
+
return s.slice(1, -1);
|
|
2841
|
+
}
|
|
2842
|
+
return s;
|
|
2843
|
+
}
|
|
2844
|
+
function parseEdge(line) {
|
|
2845
|
+
const labeled = [
|
|
2846
|
+
{ re: /^(.+?)\s*--\s*([^-][^|]*?)\s*-{1,2}>\s*(.+)$/, kind: "solid" },
|
|
2847
|
+
{ re: /^(.+?)\s*-\.\s*([^.][^|]*?)\s*\.-+>\s*(.+)$/, kind: "dashed" },
|
|
2848
|
+
{ re: /^(.+?)\s*==\s*([^=][^|]*?)\s*={1,2}>\s*(.+)$/, kind: "thick" }
|
|
2849
|
+
];
|
|
2850
|
+
for (const { re, kind } of labeled) {
|
|
2851
|
+
const m = line.match(re);
|
|
2852
|
+
if (m) return { from: m[1].trim(), to: m[3].trim(), label: m[2].trim(), kind };
|
|
2853
|
+
}
|
|
2854
|
+
const unlabeled = [
|
|
2855
|
+
{ re: /^(.+?)\s*~~~\s*(?:\|([^|]+)\|\s*)?(.+)$/, kind: "invisible" },
|
|
2856
|
+
{ re: /^(.+?)\s*-\.-+>\s*(?:\|([^|]+)\|\s*)?(.+)$/, kind: "dashed" },
|
|
2857
|
+
{ re: /^(.+?)\s*={2,}>\s*(?:\|([^|]+)\|\s*)?(.+)$/, kind: "thick" },
|
|
2858
|
+
{ re: /^(.+?)\s*-{2,}>\s*(?:\|([^|]+)\|\s*)?(.+)$/, kind: "solid" },
|
|
2859
|
+
{ re: /^(.+?)\s*-{2,}\s*(?:\|([^|]+)\|\s*)?(.+)$/, kind: "solid" }
|
|
2860
|
+
];
|
|
2861
|
+
for (const { re, kind } of unlabeled) {
|
|
2862
|
+
const m = line.match(re);
|
|
2863
|
+
if (m) {
|
|
2864
|
+
const label = m[2]?.trim();
|
|
2865
|
+
return { from: m[1].trim(), to: m[3].trim(), label: label || void 0, kind };
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
return null;
|
|
2869
|
+
}
|
|
2870
|
+
var PIE_SLICE_RE = /^"([^"]+)"\s*:\s*([\d.]+)/;
|
|
2871
|
+
function parsePieChart(source) {
|
|
2872
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
2873
|
+
const ir = { type: "pie", slices: [] };
|
|
2874
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2875
|
+
const line = lines[i];
|
|
2876
|
+
if (!line || line.startsWith("%%")) continue;
|
|
2877
|
+
if (/^pie\b/i.test(line)) {
|
|
2878
|
+
if (/\bshowData\b/i.test(line)) ir.showData = true;
|
|
2879
|
+
continue;
|
|
2880
|
+
}
|
|
2881
|
+
const titleMatch = line.match(/^title\s+(.+)$/i);
|
|
2882
|
+
if (titleMatch) {
|
|
2883
|
+
ir.title = titleMatch[1].trim();
|
|
2884
|
+
continue;
|
|
2885
|
+
}
|
|
2886
|
+
const sliceMatch = line.match(PIE_SLICE_RE);
|
|
2887
|
+
if (sliceMatch) {
|
|
2888
|
+
const value = parseFloat(sliceMatch[2]);
|
|
2889
|
+
if (!isNaN(value)) ir.slices.push({ label: sliceMatch[1], value });
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
return ir;
|
|
2893
|
+
}
|
|
2894
|
+
var QUADRANT_POINT_RE = /^([^:]+):\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]/;
|
|
2895
|
+
function parseQuadrantChart(source) {
|
|
2896
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
2897
|
+
const ir = { type: "quadrant", points: [] };
|
|
2898
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2899
|
+
const line = lines[i];
|
|
2900
|
+
if (!line || line.startsWith("%%")) continue;
|
|
2901
|
+
if (/^quadrantchart\b/i.test(line)) continue;
|
|
2902
|
+
const titleMatch = line.match(/^title\s+(.+)$/i);
|
|
2903
|
+
if (titleMatch) {
|
|
2904
|
+
ir.title = titleMatch[1].trim();
|
|
2905
|
+
continue;
|
|
2906
|
+
}
|
|
2907
|
+
const xAxisMatch = line.match(/^x-axis\s+(.+?)\s*-->\s*(.+)$/i);
|
|
2908
|
+
if (xAxisMatch) {
|
|
2909
|
+
ir.xAxisLabel = { low: xAxisMatch[1].trim(), high: xAxisMatch[2].trim() };
|
|
2910
|
+
continue;
|
|
2911
|
+
}
|
|
2912
|
+
const yAxisMatch = line.match(/^y-axis\s+(.+?)\s*-->\s*(.+)$/i);
|
|
2913
|
+
if (yAxisMatch) {
|
|
2914
|
+
ir.yAxisLabel = { low: yAxisMatch[1].trim(), high: yAxisMatch[2].trim() };
|
|
2915
|
+
continue;
|
|
2916
|
+
}
|
|
2917
|
+
const qMatch = line.match(/^quadrant-([1-4])\s+(.+)$/i);
|
|
2918
|
+
if (qMatch) {
|
|
2919
|
+
ir.quadrantLabels = ir.quadrantLabels ?? {};
|
|
2920
|
+
ir.quadrantLabels[`q${qMatch[1]}`] = qMatch[2].trim();
|
|
2921
|
+
continue;
|
|
2922
|
+
}
|
|
2923
|
+
const pt = line.match(QUADRANT_POINT_RE);
|
|
2924
|
+
if (pt) {
|
|
2925
|
+
const x = parseFloat(pt[2]);
|
|
2926
|
+
const y = parseFloat(pt[3]);
|
|
2927
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
2928
|
+
ir.points.push({ label: pt[1].trim(), x, y });
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
return ir;
|
|
2933
|
+
}
|
|
2934
|
+
var JOURNEY_TASK_RE = /^([^:]+?)\s*:\s*([\d.]+)\s*:\s*(.+)$/;
|
|
2935
|
+
function parseJourney(source) {
|
|
2936
|
+
const lines = source.split("\n").map((l) => l.replace(/^\s+/, ""));
|
|
2937
|
+
const ir = { type: "journey", sections: [] };
|
|
2938
|
+
let currentSection = null;
|
|
2939
|
+
for (const rawLine of lines) {
|
|
2940
|
+
const line = rawLine.trimEnd();
|
|
2941
|
+
if (!line || line.startsWith("%%")) continue;
|
|
2942
|
+
if (/^journey\b/i.test(line)) continue;
|
|
2943
|
+
const titleMatch = line.match(/^title\s+(.+)$/i);
|
|
2944
|
+
if (titleMatch) {
|
|
2945
|
+
ir.title = titleMatch[1].trim();
|
|
2946
|
+
continue;
|
|
2947
|
+
}
|
|
2948
|
+
const sectionMatch = line.match(/^section\s+(.+)$/i);
|
|
2949
|
+
if (sectionMatch) {
|
|
2950
|
+
currentSection = { title: sectionMatch[1].trim(), tasks: [] };
|
|
2951
|
+
ir.sections.push(currentSection);
|
|
2952
|
+
continue;
|
|
2953
|
+
}
|
|
2954
|
+
const taskMatch = line.match(JOURNEY_TASK_RE);
|
|
2955
|
+
if (taskMatch && currentSection) {
|
|
2956
|
+
const score = parseFloat(taskMatch[2]);
|
|
2957
|
+
const actors = taskMatch[3].split(",").map((a) => a.trim()).filter(Boolean);
|
|
2958
|
+
currentSection.tasks.push({ label: taskMatch[1].trim(), score, actors });
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
return ir;
|
|
2962
|
+
}
|
|
2963
|
+
var SEQ_ARROW_TOKENS = [
|
|
2964
|
+
{ token: "-->>", arrow: "reply" },
|
|
2965
|
+
{ token: "->>", arrow: "sync" },
|
|
2966
|
+
{ token: "-->", arrow: "reply" },
|
|
2967
|
+
{ token: "->", arrow: "sync" },
|
|
2968
|
+
{ token: "-x", arrow: "cross" },
|
|
2969
|
+
{ token: "-)", arrow: "async" }
|
|
2970
|
+
];
|
|
2971
|
+
function matchSequenceArrow(line) {
|
|
2972
|
+
let bestIdx = -1;
|
|
2973
|
+
let bestToken = null;
|
|
2974
|
+
for (const t of SEQ_ARROW_TOKENS) {
|
|
2975
|
+
const idx = line.indexOf(t.token);
|
|
2976
|
+
if (idx === -1) continue;
|
|
2977
|
+
if (bestIdx === -1 || idx < bestIdx || idx === bestIdx && t.token.length > (bestToken?.token.length ?? 0)) {
|
|
2978
|
+
bestIdx = idx;
|
|
2979
|
+
bestToken = t;
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
if (bestIdx === -1 || !bestToken) return null;
|
|
2983
|
+
const from = line.slice(0, bestIdx).trim();
|
|
2984
|
+
const rest = line.slice(bestIdx + bestToken.token.length);
|
|
2985
|
+
const colonIdx = rest.indexOf(":");
|
|
2986
|
+
if (colonIdx === -1) return null;
|
|
2987
|
+
let to = rest.slice(0, colonIdx).trim();
|
|
2988
|
+
const label = rest.slice(colonIdx + 1).trim();
|
|
2989
|
+
if (!from || !to || !label) return null;
|
|
2990
|
+
if (to.startsWith("+") || to.startsWith("-")) to = to.slice(1).trim();
|
|
2991
|
+
return { from, to, arrow: bestToken.arrow, label };
|
|
2992
|
+
}
|
|
2993
|
+
function parseSequence(source) {
|
|
2994
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
2995
|
+
const ir = { type: "sequence", participants: [], steps: [] };
|
|
2996
|
+
const ensureParticipant = (id, label) => {
|
|
2997
|
+
const existing = ir.participants.find((p) => p.id === id);
|
|
2998
|
+
if (existing) {
|
|
2999
|
+
if (label && existing.label === existing.id) existing.label = label;
|
|
3000
|
+
return;
|
|
3001
|
+
}
|
|
3002
|
+
ir.participants.push({ id, label: label ?? id });
|
|
3003
|
+
};
|
|
3004
|
+
for (const line of lines) {
|
|
3005
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3006
|
+
if (/^sequencediagram\b/i.test(line)) continue;
|
|
3007
|
+
if (/^(loop|alt|opt|par|else|critical|break|rect|end|activate|deactivate|autonumber|box)\b/i.test(line)) continue;
|
|
3008
|
+
const titleMatch = line.match(/^title\s+(.+)$/i);
|
|
3009
|
+
if (titleMatch) {
|
|
3010
|
+
ir.title = titleMatch[1].trim();
|
|
3011
|
+
continue;
|
|
3012
|
+
}
|
|
3013
|
+
const partMatch = line.match(/^(?:participant|actor)\s+(.+)$/i);
|
|
3014
|
+
if (partMatch) {
|
|
3015
|
+
const rest = partMatch[1].trim();
|
|
3016
|
+
const asMatch = rest.match(/^(.+?)\s+as\s+(.+)$/i);
|
|
3017
|
+
if (asMatch) {
|
|
3018
|
+
ensureParticipant(stripQuotes(asMatch[1].trim()), stripQuotes(asMatch[2].trim()));
|
|
3019
|
+
} else {
|
|
3020
|
+
ensureParticipant(stripQuotes(rest));
|
|
3021
|
+
}
|
|
3022
|
+
continue;
|
|
3023
|
+
}
|
|
3024
|
+
const noteMatch = line.match(/^note\s+(left of|right of|over)\s+([^:]+)\s*:\s*(.+)$/i);
|
|
3025
|
+
if (noteMatch) {
|
|
3026
|
+
const sideRaw = noteMatch[1].toLowerCase();
|
|
3027
|
+
const side = sideRaw.startsWith("left") ? "left" : sideRaw.startsWith("right") ? "right" : "over";
|
|
3028
|
+
const participants = noteMatch[2].split(",").map((p) => p.trim()).filter(Boolean);
|
|
3029
|
+
participants.forEach((p) => ensureParticipant(p));
|
|
3030
|
+
const note = { kind: "note", side, participants, text: noteMatch[3].trim() };
|
|
3031
|
+
ir.steps.push(note);
|
|
3032
|
+
continue;
|
|
3033
|
+
}
|
|
3034
|
+
const arrowMatch = matchSequenceArrow(line);
|
|
3035
|
+
if (arrowMatch) {
|
|
3036
|
+
ensureParticipant(arrowMatch.from);
|
|
3037
|
+
ensureParticipant(arrowMatch.to);
|
|
3038
|
+
const msg = {
|
|
3039
|
+
kind: "message",
|
|
3040
|
+
from: arrowMatch.from,
|
|
3041
|
+
to: arrowMatch.to,
|
|
3042
|
+
arrow: arrowMatch.arrow,
|
|
3043
|
+
label: arrowMatch.label
|
|
3044
|
+
};
|
|
3045
|
+
ir.steps.push(msg);
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
return ir;
|
|
3049
|
+
}
|
|
3050
|
+
var CLASS_VISIBILITY = {
|
|
3051
|
+
"+": "public",
|
|
3052
|
+
"-": "private",
|
|
3053
|
+
"#": "protected",
|
|
3054
|
+
"~": "package"
|
|
3055
|
+
};
|
|
3056
|
+
var CLASS_REL_PATTERNS = [
|
|
3057
|
+
{ re: /^([\w-]+)\s*<\|--\s*([\w-]+)$/, kind: "inheritance", reversed: true },
|
|
3058
|
+
{ re: /^([\w-]+)\s*--\|>\s*([\w-]+)$/, kind: "inheritance" },
|
|
3059
|
+
{ re: /^([\w-]+)\s*<\|\.\.\s*([\w-]+)$/, kind: "realization", reversed: true },
|
|
3060
|
+
{ re: /^([\w-]+)\s*\.\.\|>\s*([\w-]+)$/, kind: "realization" },
|
|
3061
|
+
{ re: /^([\w-]+)\s*\*--\s*([\w-]+)$/, kind: "composition" },
|
|
3062
|
+
{ re: /^([\w-]+)\s*o--\s*([\w-]+)$/, kind: "aggregation" },
|
|
3063
|
+
{ re: /^([\w-]+)\s*<\.\.\s*([\w-]+)$/, kind: "dependency", reversed: true },
|
|
3064
|
+
{ re: /^([\w-]+)\s*\.\.>\s*([\w-]+)$/, kind: "dependency" },
|
|
3065
|
+
{ re: /^([\w-]+)\s*--\s*([\w-]+)$/, kind: "association" }
|
|
3066
|
+
];
|
|
3067
|
+
function parseClassDiagram(source) {
|
|
3068
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
3069
|
+
const classes = /* @__PURE__ */ new Map();
|
|
3070
|
+
const relations = [];
|
|
3071
|
+
const ensureClass = (id) => {
|
|
3072
|
+
let cls = classes.get(id);
|
|
3073
|
+
if (!cls) {
|
|
3074
|
+
cls = { id, label: id, members: [] };
|
|
3075
|
+
classes.set(id, cls);
|
|
3076
|
+
}
|
|
3077
|
+
return cls;
|
|
3078
|
+
};
|
|
3079
|
+
let currentClassBody = null;
|
|
3080
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3081
|
+
const line = lines[i];
|
|
3082
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3083
|
+
if (/^classdiagram\b/i.test(line)) continue;
|
|
3084
|
+
if (currentClassBody) {
|
|
3085
|
+
if (/^\}\s*$/.test(line)) {
|
|
3086
|
+
currentClassBody = null;
|
|
3087
|
+
continue;
|
|
3088
|
+
}
|
|
3089
|
+
const stereotype = matchStereotype(line);
|
|
3090
|
+
if (stereotype) {
|
|
3091
|
+
ensureClass(currentClassBody).stereotype = stereotype;
|
|
3092
|
+
continue;
|
|
3093
|
+
}
|
|
3094
|
+
const member = parseClassMember(line);
|
|
3095
|
+
if (member) ensureClass(currentClassBody).members.push(member);
|
|
3096
|
+
continue;
|
|
3097
|
+
}
|
|
3098
|
+
const sameLine = line.match(/^class\s+([\w-]+)\s*\{(.*)\}\s*$/);
|
|
3099
|
+
if (sameLine) {
|
|
3100
|
+
const cls = ensureClass(sameLine[1]);
|
|
3101
|
+
const inner = sameLine[2].split(/[;\n]/).map((s) => s.trim()).filter(Boolean);
|
|
3102
|
+
for (const part of inner) {
|
|
3103
|
+
const stereotype = matchStereotype(part);
|
|
3104
|
+
if (stereotype) {
|
|
3105
|
+
cls.stereotype = stereotype;
|
|
3106
|
+
continue;
|
|
3107
|
+
}
|
|
3108
|
+
const m = parseClassMember(part);
|
|
3109
|
+
if (m) cls.members.push(m);
|
|
3110
|
+
}
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
const open = line.match(/^class\s+([\w-]+)\s*\{$/);
|
|
3114
|
+
if (open) {
|
|
3115
|
+
ensureClass(open[1]);
|
|
3116
|
+
currentClassBody = open[1];
|
|
3117
|
+
continue;
|
|
3118
|
+
}
|
|
3119
|
+
const decl = line.match(/^class\s+([\w-]+)$/);
|
|
3120
|
+
if (decl) {
|
|
3121
|
+
ensureClass(decl[1]);
|
|
3122
|
+
continue;
|
|
3123
|
+
}
|
|
3124
|
+
const memberDecl = line.match(/^([\w-]+)\s*:\s*(.+)$/);
|
|
3125
|
+
if (memberDecl && !line.includes("-->") && !line.includes("--")) {
|
|
3126
|
+
const stereotype = matchStereotype(memberDecl[2]);
|
|
3127
|
+
if (stereotype) {
|
|
3128
|
+
ensureClass(memberDecl[1]).stereotype = stereotype;
|
|
3129
|
+
continue;
|
|
3130
|
+
}
|
|
3131
|
+
const m = parseClassMember(memberDecl[2]);
|
|
3132
|
+
if (m) ensureClass(memberDecl[1]).members.push(m);
|
|
3133
|
+
continue;
|
|
3134
|
+
}
|
|
3135
|
+
let labelPart;
|
|
3136
|
+
let relLine = line;
|
|
3137
|
+
const labelMatch = line.match(/^(.+?)\s*:\s*(.+)$/);
|
|
3138
|
+
if (labelMatch && /(<\|--|--\|>|<\|\.\.|\.\.\|>|\*--|o--|<\.\.|\.\.>|--)/.test(labelMatch[1])) {
|
|
3139
|
+
relLine = labelMatch[1];
|
|
3140
|
+
labelPart = labelMatch[2].trim();
|
|
3141
|
+
}
|
|
3142
|
+
for (const { re, kind, reversed } of CLASS_REL_PATTERNS) {
|
|
3143
|
+
const m = relLine.match(re);
|
|
3144
|
+
if (m) {
|
|
3145
|
+
const a = m[1];
|
|
3146
|
+
const b = m[2];
|
|
3147
|
+
ensureClass(a);
|
|
3148
|
+
ensureClass(b);
|
|
3149
|
+
relations.push({
|
|
3150
|
+
source: reversed ? b : a,
|
|
3151
|
+
target: reversed ? a : b,
|
|
3152
|
+
kind,
|
|
3153
|
+
label: labelPart
|
|
3154
|
+
});
|
|
3155
|
+
break;
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
return { type: "class", classes: [...classes.values()], relations };
|
|
3160
|
+
}
|
|
3161
|
+
function matchStereotype(text) {
|
|
3162
|
+
const m = text.trim().match(/^<<\s*([^>]+?)\s*>>$/);
|
|
3163
|
+
return m ? m[1] : void 0;
|
|
3164
|
+
}
|
|
3165
|
+
function parseClassMember(text) {
|
|
3166
|
+
const t = text.trim();
|
|
3167
|
+
if (!t) return null;
|
|
3168
|
+
let visibility;
|
|
3169
|
+
let body = t;
|
|
3170
|
+
const first = body[0];
|
|
3171
|
+
if (first in CLASS_VISIBILITY) {
|
|
3172
|
+
visibility = CLASS_VISIBILITY[first];
|
|
3173
|
+
body = body.slice(1).trim();
|
|
3174
|
+
}
|
|
3175
|
+
const methodMatch = body.match(/^([\w-]+)\(([^)]*)\)(?:\s*([\w<>[\]]+))?$/);
|
|
3176
|
+
if (methodMatch) {
|
|
3177
|
+
return {
|
|
3178
|
+
kind: "method",
|
|
3179
|
+
visibility,
|
|
3180
|
+
name: methodMatch[1],
|
|
3181
|
+
parameters: methodMatch[2] || void 0,
|
|
3182
|
+
returnType: methodMatch[3] || void 0
|
|
3183
|
+
};
|
|
3184
|
+
}
|
|
3185
|
+
const colonMatch = body.match(/^([\w-]+)\s*:\s*([\w<>[\]]+)$/);
|
|
3186
|
+
if (colonMatch) {
|
|
3187
|
+
return { kind: "attribute", visibility, name: colonMatch[1], returnType: colonMatch[2] };
|
|
3188
|
+
}
|
|
3189
|
+
const typeNameMatch = body.match(/^([\w<>[\]]+)\s+([\w-]+)$/);
|
|
3190
|
+
if (typeNameMatch) {
|
|
3191
|
+
return { kind: "attribute", visibility, name: typeNameMatch[2], returnType: typeNameMatch[1] };
|
|
3192
|
+
}
|
|
3193
|
+
return { kind: "attribute", visibility, name: body };
|
|
3194
|
+
}
|
|
3195
|
+
function parseStateDiagram(source) {
|
|
3196
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
3197
|
+
const states = /* @__PURE__ */ new Map();
|
|
3198
|
+
const transitions = [];
|
|
3199
|
+
const parentStack = [];
|
|
3200
|
+
const currentParent = () => parentStack.length > 0 ? parentStack[parentStack.length - 1] : void 0;
|
|
3201
|
+
const markerId = (kind, parent) => parent ? `__${kind}_${parent}` : `__${kind}`;
|
|
3202
|
+
const ensureMarker = (kind) => {
|
|
3203
|
+
const parent = currentParent();
|
|
3204
|
+
const id = markerId(kind, parent);
|
|
3205
|
+
let s = states.get(id);
|
|
3206
|
+
if (!s) {
|
|
3207
|
+
s = { id, label: "", kind, parent };
|
|
3208
|
+
states.set(id, s);
|
|
3209
|
+
}
|
|
3210
|
+
return s;
|
|
3211
|
+
};
|
|
3212
|
+
const ensureState = (id) => {
|
|
3213
|
+
let s = states.get(id);
|
|
3214
|
+
if (s) return s;
|
|
3215
|
+
s = { id, label: id, kind: "state", parent: currentParent() };
|
|
3216
|
+
states.set(id, s);
|
|
3217
|
+
return s;
|
|
3218
|
+
};
|
|
3219
|
+
for (const line of lines) {
|
|
3220
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3221
|
+
if (/^statediagram(-v2)?\b/i.test(line)) continue;
|
|
3222
|
+
const compositeOpen = line.match(/^state\s+([\w-]+)\s*\{$/);
|
|
3223
|
+
if (compositeOpen) {
|
|
3224
|
+
const id = compositeOpen[1];
|
|
3225
|
+
const existing = states.get(id);
|
|
3226
|
+
if (existing) {
|
|
3227
|
+
existing.kind = "composite";
|
|
3228
|
+
} else {
|
|
3229
|
+
states.set(id, { id, label: id, kind: "composite", parent: currentParent() });
|
|
3230
|
+
}
|
|
3231
|
+
parentStack.push(id);
|
|
3232
|
+
continue;
|
|
3233
|
+
}
|
|
3234
|
+
if (line === "}") {
|
|
3235
|
+
parentStack.pop();
|
|
3236
|
+
continue;
|
|
3237
|
+
}
|
|
3238
|
+
const arrow = line.match(/^(\[\*\]|[\w-]+)\s*-->\s*(\[\*\]|[\w-]+)(?:\s*:\s*(.+))?$/);
|
|
3239
|
+
if (arrow) {
|
|
3240
|
+
const src = arrow[1] === "[*]" ? ensureMarker("start") : ensureState(arrow[1]);
|
|
3241
|
+
const tgt = arrow[2] === "[*]" ? ensureMarker("end") : ensureState(arrow[2]);
|
|
3242
|
+
transitions.push({
|
|
3243
|
+
source: src.id,
|
|
3244
|
+
target: tgt.id,
|
|
3245
|
+
label: arrow[3]?.trim(),
|
|
3246
|
+
parent: currentParent()
|
|
3247
|
+
});
|
|
3248
|
+
continue;
|
|
3249
|
+
}
|
|
3250
|
+
const stateLabel = line.match(/^([\w-]+)\s*:\s*(.+)$/);
|
|
3251
|
+
if (stateLabel) {
|
|
3252
|
+
const s = ensureState(stateLabel[1]);
|
|
3253
|
+
s.label = stateLabel[2].trim();
|
|
3254
|
+
continue;
|
|
3255
|
+
}
|
|
3256
|
+
if (/^[\w-]+$/.test(line)) ensureState(line);
|
|
3257
|
+
}
|
|
3258
|
+
return { type: "state", states: [...states.values()], transitions };
|
|
3259
|
+
}
|
|
3260
|
+
function parseMermaidERDiagram(source) {
|
|
3261
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
3262
|
+
const tables = /* @__PURE__ */ new Map();
|
|
3263
|
+
const relations = [];
|
|
3264
|
+
const ensureTable = (name) => {
|
|
3265
|
+
let t = tables.get(name);
|
|
3266
|
+
if (!t) {
|
|
3267
|
+
t = { name, columns: [] };
|
|
3268
|
+
tables.set(name, t);
|
|
3269
|
+
}
|
|
3270
|
+
return t;
|
|
3271
|
+
};
|
|
3272
|
+
let currentTableBody = null;
|
|
3273
|
+
for (const line of lines) {
|
|
3274
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3275
|
+
if (/^erdiagram\b/i.test(line)) continue;
|
|
3276
|
+
if (currentTableBody) {
|
|
3277
|
+
if (/^\}\s*$/.test(line)) {
|
|
3278
|
+
currentTableBody = null;
|
|
3279
|
+
continue;
|
|
3280
|
+
}
|
|
3281
|
+
const col = line.match(/^([\w-]+)\s+([\w-]+)(?:\s+(.+))?$/);
|
|
3282
|
+
if (col) {
|
|
3283
|
+
const flags = (col[3] ?? "").toUpperCase();
|
|
3284
|
+
const column = {
|
|
3285
|
+
name: col[2],
|
|
3286
|
+
type: col[1],
|
|
3287
|
+
isPK: /\bPK\b/.test(flags),
|
|
3288
|
+
isFK: /\bFK\b/.test(flags),
|
|
3289
|
+
isNullable: !/\bNOT NULL\b/.test(flags),
|
|
3290
|
+
isUnique: /\bUK\b/.test(flags) || /\bUNIQUE\b/.test(flags)
|
|
3291
|
+
};
|
|
3292
|
+
ensureTable(currentTableBody).columns.push(column);
|
|
3293
|
+
}
|
|
3294
|
+
continue;
|
|
3295
|
+
}
|
|
3296
|
+
const blockOpen = line.match(/^([A-Z][\w-]*)\s*\{$/);
|
|
3297
|
+
if (blockOpen) {
|
|
3298
|
+
ensureTable(blockOpen[1]);
|
|
3299
|
+
currentTableBody = blockOpen[1];
|
|
3300
|
+
continue;
|
|
3301
|
+
}
|
|
3302
|
+
const rel = line.match(/^([A-Z][\w-]*)\s+([|}{o\-.]+)\s+([A-Z][\w-]*)\s*:\s*(.+)$/);
|
|
3303
|
+
if (rel) {
|
|
3304
|
+
const fromTable = rel[1];
|
|
3305
|
+
const toTable = rel[3];
|
|
3306
|
+
const cardinality = rel[2];
|
|
3307
|
+
ensureTable(fromTable);
|
|
3308
|
+
ensureTable(toTable);
|
|
3309
|
+
relations.push({
|
|
3310
|
+
fromTable,
|
|
3311
|
+
fromCol: rel[4].trim(),
|
|
3312
|
+
toTable,
|
|
3313
|
+
toCol: rel[4].trim(),
|
|
3314
|
+
nullable: cardinality.includes("o")
|
|
3315
|
+
});
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
const schema = {
|
|
3319
|
+
tables: [...tables.values()],
|
|
3320
|
+
relations,
|
|
3321
|
+
inputFormat: "unknown"
|
|
3322
|
+
};
|
|
3323
|
+
return { type: "er", schema };
|
|
3324
|
+
}
|
|
3325
|
+
var GANTT_TASK_LINE_RE = /^([^:]+?)\s*:\s*(.+)$/;
|
|
3326
|
+
var STATUS_TOKENS = {
|
|
3327
|
+
done: "done",
|
|
3328
|
+
active: "active",
|
|
3329
|
+
crit: "crit",
|
|
3330
|
+
milestone: "milestone"
|
|
3331
|
+
};
|
|
3332
|
+
function parseGantt(source) {
|
|
3333
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
3334
|
+
const ir = { type: "gantt", tasks: [] };
|
|
3335
|
+
const intermediates = [];
|
|
3336
|
+
let currentSection;
|
|
3337
|
+
let anonCounter = 0;
|
|
3338
|
+
for (const line of lines) {
|
|
3339
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3340
|
+
if (/^gantt\b/i.test(line)) continue;
|
|
3341
|
+
const titleMatch = line.match(/^title\s+(.+)$/i);
|
|
3342
|
+
if (titleMatch) {
|
|
3343
|
+
ir.title = titleMatch[1].trim();
|
|
3344
|
+
continue;
|
|
3345
|
+
}
|
|
3346
|
+
const dateMatch = line.match(/^dateFormat\s+(.+)$/i);
|
|
3347
|
+
if (dateMatch) {
|
|
3348
|
+
ir.dateFormat = dateMatch[1].trim();
|
|
3349
|
+
continue;
|
|
3350
|
+
}
|
|
3351
|
+
const axisMatch = line.match(/^axisFormat\s+(.+)$/i);
|
|
3352
|
+
if (axisMatch) {
|
|
3353
|
+
ir.axisFormat = axisMatch[1].trim();
|
|
3354
|
+
continue;
|
|
3355
|
+
}
|
|
3356
|
+
const sectionMatch = line.match(/^section\s+(.+)$/i);
|
|
3357
|
+
if (sectionMatch) {
|
|
3358
|
+
currentSection = sectionMatch[1].trim();
|
|
3359
|
+
continue;
|
|
3360
|
+
}
|
|
3361
|
+
if (/^(excludes|includes|todayMarker|click|tickInterval|weekday)\b/i.test(line)) continue;
|
|
3362
|
+
const taskMatch = line.match(GANTT_TASK_LINE_RE);
|
|
3363
|
+
if (!taskMatch) continue;
|
|
3364
|
+
const label = taskMatch[1].trim();
|
|
3365
|
+
const parts = taskMatch[2].split(",").map((p) => p.trim()).filter(Boolean);
|
|
3366
|
+
if (parts.length === 0) continue;
|
|
3367
|
+
let status = "default";
|
|
3368
|
+
let id;
|
|
3369
|
+
let startSpec;
|
|
3370
|
+
let durationOrEnd;
|
|
3371
|
+
for (const part of parts) {
|
|
3372
|
+
const lower = part.toLowerCase();
|
|
3373
|
+
if (lower in STATUS_TOKENS) {
|
|
3374
|
+
status = STATUS_TOKENS[lower];
|
|
3375
|
+
continue;
|
|
3376
|
+
}
|
|
3377
|
+
if (id === void 0 && /^[\w-]+$/.test(part) && !isDateLike(part) && !/^\d/.test(part)) {
|
|
3378
|
+
id = part;
|
|
3379
|
+
continue;
|
|
3380
|
+
}
|
|
3381
|
+
if (startSpec === void 0) {
|
|
3382
|
+
startSpec = part;
|
|
3383
|
+
continue;
|
|
3384
|
+
}
|
|
3385
|
+
if (durationOrEnd === void 0) {
|
|
3386
|
+
durationOrEnd = part;
|
|
3387
|
+
continue;
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
if (!startSpec || !durationOrEnd) continue;
|
|
3391
|
+
intermediates.push({
|
|
3392
|
+
id: id ?? `__gantt_${anonCounter++}`,
|
|
3393
|
+
label,
|
|
3394
|
+
status,
|
|
3395
|
+
startSpec,
|
|
3396
|
+
durationOrEnd,
|
|
3397
|
+
section: currentSection
|
|
3398
|
+
});
|
|
3399
|
+
}
|
|
3400
|
+
const byId = /* @__PURE__ */ new Map();
|
|
3401
|
+
for (const it of intermediates) {
|
|
3402
|
+
const start = resolveGanttDate(it.startSpec, byId);
|
|
3403
|
+
if (!start) continue;
|
|
3404
|
+
let end = resolveGanttDate(it.durationOrEnd, byId);
|
|
3405
|
+
if (!end) {
|
|
3406
|
+
end = applyGanttDuration(start, it.durationOrEnd);
|
|
3407
|
+
}
|
|
3408
|
+
if (!end) continue;
|
|
3409
|
+
if (it.status === "milestone") end = start;
|
|
3410
|
+
const task = {
|
|
3411
|
+
id: it.id,
|
|
3412
|
+
label: it.label,
|
|
3413
|
+
start: toIsoDay(start),
|
|
3414
|
+
end: toIsoDay(end),
|
|
3415
|
+
status: it.status,
|
|
3416
|
+
section: it.section
|
|
3417
|
+
};
|
|
3418
|
+
ir.tasks.push(task);
|
|
3419
|
+
byId.set(it.id, task);
|
|
3420
|
+
}
|
|
3421
|
+
return ir;
|
|
3422
|
+
}
|
|
3423
|
+
function isDateLike(s) {
|
|
3424
|
+
return /^\d{4}-\d{2}-\d{2}/.test(s);
|
|
3425
|
+
}
|
|
3426
|
+
function resolveGanttDate(spec, byId) {
|
|
3427
|
+
if (isDateLike(spec)) {
|
|
3428
|
+
const d = new Date(spec);
|
|
3429
|
+
return isNaN(d.getTime()) ? null : d;
|
|
3430
|
+
}
|
|
3431
|
+
const after = spec.match(/^after\s+(.+)$/i);
|
|
3432
|
+
if (after) {
|
|
3433
|
+
const refIds = after[1].split(/\s+/);
|
|
3434
|
+
let max = null;
|
|
3435
|
+
for (const refId of refIds) {
|
|
3436
|
+
const ref = byId.get(refId);
|
|
3437
|
+
if (!ref) continue;
|
|
3438
|
+
const d = new Date(ref.end);
|
|
3439
|
+
if (!max || d.getTime() > max.getTime()) max = d;
|
|
3440
|
+
}
|
|
3441
|
+
return max;
|
|
3442
|
+
}
|
|
3443
|
+
return null;
|
|
3444
|
+
}
|
|
3445
|
+
function applyGanttDuration(start, dur) {
|
|
3446
|
+
const m = dur.match(/^(\d+(?:\.\d+)?)\s*(d|h|w|m|y)$/i);
|
|
3447
|
+
if (!m) return null;
|
|
3448
|
+
const n = parseFloat(m[1]);
|
|
3449
|
+
const unit = m[2].toLowerCase();
|
|
3450
|
+
const result = new Date(start);
|
|
3451
|
+
switch (unit) {
|
|
3452
|
+
case "h":
|
|
3453
|
+
result.setHours(result.getHours() + n);
|
|
3454
|
+
break;
|
|
3455
|
+
case "d":
|
|
3456
|
+
result.setDate(result.getDate() + n);
|
|
3457
|
+
break;
|
|
3458
|
+
case "w":
|
|
3459
|
+
result.setDate(result.getDate() + n * 7);
|
|
3460
|
+
break;
|
|
3461
|
+
case "m":
|
|
3462
|
+
result.setMonth(result.getMonth() + n);
|
|
3463
|
+
break;
|
|
3464
|
+
case "y":
|
|
3465
|
+
result.setFullYear(result.getFullYear() + n);
|
|
3466
|
+
break;
|
|
3467
|
+
default:
|
|
3468
|
+
return null;
|
|
3469
|
+
}
|
|
3470
|
+
return result;
|
|
3471
|
+
}
|
|
3472
|
+
function toIsoDay(d) {
|
|
3473
|
+
return d.toISOString();
|
|
3474
|
+
}
|
|
3475
|
+
function parseTimeline(source) {
|
|
3476
|
+
const lines = source.split("\n");
|
|
3477
|
+
const ir = { type: "timeline", events: [] };
|
|
3478
|
+
let currentSection;
|
|
3479
|
+
let counter = 0;
|
|
3480
|
+
for (const rawLine of lines) {
|
|
3481
|
+
const line = rawLine.trim();
|
|
3482
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3483
|
+
if (/^timeline\b/i.test(line)) continue;
|
|
3484
|
+
const titleMatch = line.match(/^title\s+(.+)$/i);
|
|
3485
|
+
if (titleMatch) {
|
|
3486
|
+
ir.title = titleMatch[1].trim();
|
|
3487
|
+
continue;
|
|
3488
|
+
}
|
|
3489
|
+
const sectionMatch = line.match(/^section\s+(.+)$/i);
|
|
3490
|
+
if (sectionMatch) {
|
|
3491
|
+
currentSection = sectionMatch[1].trim();
|
|
3492
|
+
continue;
|
|
3493
|
+
}
|
|
3494
|
+
const parts = line.split(":").map((p) => p.trim()).filter(Boolean);
|
|
3495
|
+
if (parts.length < 2) continue;
|
|
3496
|
+
const period = parts[0];
|
|
3497
|
+
for (let i = 1; i < parts.length; i++) {
|
|
3498
|
+
const event = {
|
|
3499
|
+
id: `__tl_${counter++}`,
|
|
3500
|
+
period,
|
|
3501
|
+
text: parts[i],
|
|
3502
|
+
section: currentSection
|
|
3503
|
+
};
|
|
3504
|
+
ir.events.push(event);
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
return ir;
|
|
3508
|
+
}
|
|
3509
|
+
var MINDMAP_SHAPE_PATTERNS = [
|
|
3510
|
+
{ re: /^([\w-]*)\(\(([^)]*)\)\)$/, shape: "circle" },
|
|
3511
|
+
// ((text))
|
|
3512
|
+
{ re: /^([\w-]*)\)\)([^(]*)\(\($/, shape: "bang" },
|
|
3513
|
+
// ))text(( bang
|
|
3514
|
+
{ re: /^([\w-]*)\)([^(]*)\($/, shape: "cloud" },
|
|
3515
|
+
// )text( cloud
|
|
3516
|
+
{ re: /^([\w-]*)\{\{([^}]*)\}\}$/, shape: "hexagon" },
|
|
3517
|
+
// {{text}}
|
|
3518
|
+
{ re: /^([\w-]*)\(([^)]*)\)$/, shape: "rounded" },
|
|
3519
|
+
// (text)
|
|
3520
|
+
{ re: /^([\w-]*)\[([^\]]*)\]$/, shape: "square" }
|
|
3521
|
+
// [text]
|
|
3522
|
+
];
|
|
3523
|
+
function parseMindmap(source) {
|
|
3524
|
+
const rawLines = source.split("\n");
|
|
3525
|
+
const stripped = [];
|
|
3526
|
+
let inHeader = true;
|
|
3527
|
+
for (const line of rawLines) {
|
|
3528
|
+
if (line.trim().length === 0) continue;
|
|
3529
|
+
if (inHeader && /^\s*mindmap\b/i.test(line)) {
|
|
3530
|
+
inHeader = false;
|
|
3531
|
+
continue;
|
|
3532
|
+
}
|
|
3533
|
+
inHeader = false;
|
|
3534
|
+
if (line.trim().startsWith("%%")) continue;
|
|
3535
|
+
const indent = line.match(/^\s*/)?.[0]?.length ?? 0;
|
|
3536
|
+
stripped.push({ indent, raw: line.trim() });
|
|
3537
|
+
}
|
|
3538
|
+
if (stripped.length === 0) {
|
|
3539
|
+
return {
|
|
3540
|
+
type: "mindmap",
|
|
3541
|
+
root: { id: "__mm_0", label: "Mindmap", shape: "default", children: [] }
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3544
|
+
let counter = 0;
|
|
3545
|
+
const makeNode = (raw) => {
|
|
3546
|
+
let label = raw;
|
|
3547
|
+
let shape = "default";
|
|
3548
|
+
let icon;
|
|
3549
|
+
const iconMatch = label.match(/^(.*?)\s*::icon\(([^)]+)\)\s*$/);
|
|
3550
|
+
if (iconMatch) {
|
|
3551
|
+
label = iconMatch[1].trim();
|
|
3552
|
+
icon = iconMatch[2].trim();
|
|
3553
|
+
}
|
|
3554
|
+
for (const { re, shape: s } of MINDMAP_SHAPE_PATTERNS) {
|
|
3555
|
+
const m = label.match(re);
|
|
3556
|
+
if (m) {
|
|
3557
|
+
label = m[2].trim() || m[1].trim();
|
|
3558
|
+
shape = s;
|
|
3559
|
+
break;
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
const node = {
|
|
3563
|
+
id: `__mm_${counter++}`,
|
|
3564
|
+
label,
|
|
3565
|
+
shape,
|
|
3566
|
+
children: []
|
|
3567
|
+
};
|
|
3568
|
+
if (icon) node.icon = icon;
|
|
3569
|
+
return node;
|
|
3570
|
+
};
|
|
3571
|
+
const rootEntry = stripped[0];
|
|
3572
|
+
const root = makeNode(rootEntry.raw);
|
|
3573
|
+
const stack = [{ indent: rootEntry.indent, node: root }];
|
|
3574
|
+
for (let i = 1; i < stripped.length; i++) {
|
|
3575
|
+
const { indent, raw } = stripped[i];
|
|
3576
|
+
while (stack.length > 0 && stack[stack.length - 1].indent >= indent) stack.pop();
|
|
3577
|
+
const parent = stack.length > 0 ? stack[stack.length - 1].node : root;
|
|
3578
|
+
const node = makeNode(raw);
|
|
3579
|
+
parent.children.push(node);
|
|
3580
|
+
stack.push({ indent, node });
|
|
3581
|
+
}
|
|
3582
|
+
return { type: "mindmap", root };
|
|
3583
|
+
}
|
|
3584
|
+
var ARCH_DECL_RE = /^(group|service)\s+([\w-]+)\s*(?:\(([^)]+)\))?\s*(?:\[([^\]]+)\])?\s*(?:in\s+([\w-]+))?\s*$/i;
|
|
3585
|
+
var ARCH_EDGE_RE = /^([\w-]+)(?::([LRTB]))?\s*(?:--|<-->|<--|-->|<-|->)\s*(?:([LRTB]):)?([\w-]+)(?:\s*\[([^\]]+)\])?$/i;
|
|
3586
|
+
function parseArchitecture(source) {
|
|
3587
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
3588
|
+
const nodes = [];
|
|
3589
|
+
const edges = [];
|
|
3590
|
+
for (const line of lines) {
|
|
3591
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3592
|
+
if (/^architecture(-beta)?\b/i.test(line)) continue;
|
|
3593
|
+
if (/^title\b/i.test(line)) continue;
|
|
3594
|
+
const decl = line.match(ARCH_DECL_RE);
|
|
3595
|
+
if (decl) {
|
|
3596
|
+
const [, kind, id, icon, label, parent] = decl;
|
|
3597
|
+
nodes.push({
|
|
3598
|
+
id,
|
|
3599
|
+
kind: kind.toLowerCase() === "group" ? "group" : "service",
|
|
3600
|
+
label: label?.trim() || id,
|
|
3601
|
+
icon: icon?.trim() || void 0,
|
|
3602
|
+
parent: parent?.trim() || void 0
|
|
3603
|
+
});
|
|
3604
|
+
continue;
|
|
3605
|
+
}
|
|
3606
|
+
const edge = line.match(ARCH_EDGE_RE);
|
|
3607
|
+
if (edge) {
|
|
3608
|
+
const [, source2, sourceSide, targetSide, target, label] = edge;
|
|
3609
|
+
edges.push({
|
|
3610
|
+
source: source2,
|
|
3611
|
+
target,
|
|
3612
|
+
sourceSide: sourceSide?.toUpperCase() ?? void 0,
|
|
3613
|
+
targetSide: targetSide?.toUpperCase() ?? void 0,
|
|
3614
|
+
label: label?.trim() || void 0
|
|
3615
|
+
});
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
return { type: "architecture", nodes, edges };
|
|
3619
|
+
}
|
|
3620
|
+
var C4_VARIANT_RE = /^C4(Context|Container|Component|Deployment)\b/i;
|
|
3621
|
+
var C4_ELEMENT_RE = /^([A-Z][\w_]*)\s*\(\s*([^,)]+)(?:\s*,\s*"([^"]*)")?(?:\s*,\s*"([^"]*)")?(?:\s*,\s*"([^"]*)")?(?:\s*,\s*"([^"]*)")?\s*\)\s*\{?\s*$/;
|
|
3622
|
+
var C4_REL_RE = /^(Rel|BiRel|Rel_Back|Rel_Up|Rel_Down|Rel_Left|Rel_Right)\s*\(\s*([\w_]+)\s*,\s*([\w_]+)\s*(?:,\s*"([^"]*)")?(?:\s*,\s*"([^"]*)")?\s*\)\s*$/i;
|
|
3623
|
+
var C4_KIND_MAP = {
|
|
3624
|
+
Person: "person",
|
|
3625
|
+
Person_Ext: "person-external",
|
|
3626
|
+
System: "system",
|
|
3627
|
+
System_Ext: "system-external",
|
|
3628
|
+
SystemDb: "system-db",
|
|
3629
|
+
SystemDb_Ext: "system-db",
|
|
3630
|
+
SystemQueue: "system-queue",
|
|
3631
|
+
SystemQueue_Ext: "system-queue",
|
|
3632
|
+
Container: "container",
|
|
3633
|
+
Container_Ext: "container-external",
|
|
3634
|
+
ContainerDb: "container-db",
|
|
3635
|
+
ContainerDb_Ext: "container-db",
|
|
3636
|
+
ContainerQueue: "container-queue",
|
|
3637
|
+
Component: "component",
|
|
3638
|
+
Component_Ext: "component-external",
|
|
3639
|
+
ComponentDb: "component-db",
|
|
3640
|
+
ComponentQueue: "component-queue",
|
|
3641
|
+
Boundary: "boundary",
|
|
3642
|
+
System_Boundary: "system-boundary",
|
|
3643
|
+
Container_Boundary: "container-boundary",
|
|
3644
|
+
Enterprise_Boundary: "enterprise-boundary",
|
|
3645
|
+
Node: "node",
|
|
3646
|
+
Deployment_Node: "node"
|
|
3647
|
+
};
|
|
3648
|
+
function parseC4(source) {
|
|
3649
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
3650
|
+
const elements = [];
|
|
3651
|
+
const relations = [];
|
|
3652
|
+
let variant = "context";
|
|
3653
|
+
let title;
|
|
3654
|
+
const boundaryStack = [];
|
|
3655
|
+
for (const rawLine of lines) {
|
|
3656
|
+
let line = rawLine;
|
|
3657
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3658
|
+
const v = line.match(C4_VARIANT_RE);
|
|
3659
|
+
if (v) {
|
|
3660
|
+
const t = v[1].toLowerCase();
|
|
3661
|
+
variant = t === "context" ? "context" : t === "container" ? "container" : t === "component" ? "component" : "deployment";
|
|
3662
|
+
continue;
|
|
3663
|
+
}
|
|
3664
|
+
const titleMatch = line.match(/^title\s+(.+)$/i);
|
|
3665
|
+
if (titleMatch) {
|
|
3666
|
+
title = titleMatch[1].trim();
|
|
3667
|
+
continue;
|
|
3668
|
+
}
|
|
3669
|
+
if (line === "}") {
|
|
3670
|
+
boundaryStack.pop();
|
|
3671
|
+
continue;
|
|
3672
|
+
}
|
|
3673
|
+
const rel = line.match(C4_REL_RE);
|
|
3674
|
+
if (rel) {
|
|
3675
|
+
const [, , src, tgt, label, technology] = rel;
|
|
3676
|
+
relations.push({ source: src, target: tgt, label, technology });
|
|
3677
|
+
continue;
|
|
3678
|
+
}
|
|
3679
|
+
const el = line.match(C4_ELEMENT_RE);
|
|
3680
|
+
if (el) {
|
|
3681
|
+
const [, type, id, ...rest] = el;
|
|
3682
|
+
const kind = C4_KIND_MAP[type] ?? "system";
|
|
3683
|
+
const label = rest[0] ?? id;
|
|
3684
|
+
const isBoundary = kind.endsWith("boundary") || kind === "node";
|
|
3685
|
+
const technology = !isBoundary ? rest[1] : void 0;
|
|
3686
|
+
const description = !isBoundary ? rest[2] : rest[1];
|
|
3687
|
+
elements.push({
|
|
3688
|
+
id,
|
|
3689
|
+
kind,
|
|
3690
|
+
label: label.trim(),
|
|
3691
|
+
technology: technology?.trim(),
|
|
3692
|
+
description: description?.trim(),
|
|
3693
|
+
parent: boundaryStack.length > 0 ? boundaryStack[boundaryStack.length - 1] : void 0
|
|
3694
|
+
});
|
|
3695
|
+
if (line.endsWith("{") && isBoundary) {
|
|
3696
|
+
boundaryStack.push(id);
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
return { type: "c4", variant, title, elements, relations };
|
|
3701
|
+
}
|
|
3702
|
+
function parseGitGraph(source) {
|
|
3703
|
+
const lines = source.split("\n").map((l) => l.trim());
|
|
3704
|
+
const ops = [];
|
|
3705
|
+
let title;
|
|
3706
|
+
for (const line of lines) {
|
|
3707
|
+
if (!line || line.startsWith("%%")) continue;
|
|
3708
|
+
if (/^gitgraph\b/i.test(line) || /^---/.test(line)) continue;
|
|
3709
|
+
const titleMatch = line.match(/^title:\s*(.+)$/i) || line.match(/^title\s+(.+)$/i);
|
|
3710
|
+
if (titleMatch) {
|
|
3711
|
+
title = titleMatch[1].trim();
|
|
3712
|
+
continue;
|
|
3713
|
+
}
|
|
3714
|
+
const commit = line.match(/^commit\b(.*)$/i);
|
|
3715
|
+
if (commit) {
|
|
3716
|
+
const rest = commit[1];
|
|
3717
|
+
const idMatch = rest.match(/id:\s*"([^"]+)"/);
|
|
3718
|
+
const tagMatch = rest.match(/tag:\s*"([^"]+)"/);
|
|
3719
|
+
const typeMatch = rest.match(/type:\s*(HIGHLIGHT|REVERSE|NORMAL)/);
|
|
3720
|
+
ops.push({
|
|
3721
|
+
kind: "commit",
|
|
3722
|
+
id: idMatch?.[1],
|
|
3723
|
+
tag: tagMatch?.[1],
|
|
3724
|
+
type: typeMatch ? typeMatch[1] : "NORMAL"
|
|
3725
|
+
});
|
|
3726
|
+
continue;
|
|
3727
|
+
}
|
|
3728
|
+
const branch = line.match(/^branch\s+([\w/-]+)/i);
|
|
3729
|
+
if (branch) {
|
|
3730
|
+
ops.push({ kind: "branch", name: branch[1] });
|
|
3731
|
+
continue;
|
|
3732
|
+
}
|
|
3733
|
+
const checkout = line.match(/^(?:checkout|switch)\s+([\w/-]+)/i);
|
|
3734
|
+
if (checkout) {
|
|
3735
|
+
ops.push({ kind: "checkout", name: checkout[1] });
|
|
3736
|
+
continue;
|
|
3737
|
+
}
|
|
3738
|
+
const merge = line.match(/^merge\s+([\w/-]+)(?:\s+tag:\s*"([^"]+)")?/i);
|
|
3739
|
+
if (merge) {
|
|
3740
|
+
ops.push({ kind: "merge", from: merge[1], tag: merge[2] });
|
|
3741
|
+
continue;
|
|
3742
|
+
}
|
|
3743
|
+
const cherry = line.match(/^cherry-pick\s+id:\s*"([^"]+)"/i);
|
|
3744
|
+
if (cherry) {
|
|
3745
|
+
ops.push({ kind: "cherry-pick", commitId: cherry[1] });
|
|
3746
|
+
}
|
|
3747
|
+
}
|
|
3748
|
+
return { type: "gitgraph", title, ops };
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
// src/utils/diagrams/registry.ts
|
|
3752
|
+
var REGISTRY = /* @__PURE__ */ new Map();
|
|
3753
|
+
function register(entry) {
|
|
3754
|
+
REGISTRY.set(entry.type, entry);
|
|
3755
|
+
}
|
|
3756
|
+
function getRenderer(type) {
|
|
3757
|
+
return REGISTRY.get(type) ?? null;
|
|
3758
|
+
}
|
|
3759
|
+
function hasRenderer(type) {
|
|
3760
|
+
return REGISTRY.has(type);
|
|
3761
|
+
}
|
|
3762
|
+
function _resetRegistry() {
|
|
3763
|
+
REGISTRY.clear();
|
|
3764
|
+
}
|
|
3765
|
+
var LAZY_RENDERERS = /* @__PURE__ */ new Map();
|
|
3766
|
+
function getLazyRenderer(type) {
|
|
3767
|
+
let lazyComp = LAZY_RENDERERS.get(type);
|
|
3768
|
+
if (lazyComp) return lazyComp;
|
|
3769
|
+
const entry = getRenderer(type);
|
|
3770
|
+
if (!entry) return null;
|
|
3771
|
+
lazyComp = react.lazy(entry.loader);
|
|
3772
|
+
LAZY_RENDERERS.set(type, lazyComp);
|
|
3773
|
+
return lazyComp;
|
|
3774
|
+
}
|
|
3775
|
+
function DiagramRenderer({ source, dark, handleRef, onError }) {
|
|
3776
|
+
const [parsed, setParsed] = react.useState(null);
|
|
3777
|
+
react.useEffect(() => {
|
|
3778
|
+
let cancelled = false;
|
|
3779
|
+
setParsed(null);
|
|
3780
|
+
parseToIR(source).then((result) => {
|
|
3781
|
+
if (cancelled) return;
|
|
3782
|
+
if (!result.ok && onError) onError(result.error);
|
|
3783
|
+
setParsed(result);
|
|
3784
|
+
});
|
|
3785
|
+
return () => {
|
|
3786
|
+
cancelled = true;
|
|
3787
|
+
};
|
|
3788
|
+
}, [source, onError]);
|
|
3789
|
+
if (!parsed) {
|
|
3790
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "my-4 text-slate-400 text-xs italic", children: "Parsing diagram\u2026" });
|
|
3791
|
+
}
|
|
3792
|
+
if (!parsed.ok) {
|
|
3793
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "my-4 p-3 bg-red-50 border border-red-200 rounded-lg text-red-600 text-xs font-mono", children: [
|
|
3794
|
+
"Diagram parse error: ",
|
|
3795
|
+
parsed.error
|
|
3796
|
+
] });
|
|
3797
|
+
}
|
|
3798
|
+
const ir = parsed.ir;
|
|
3799
|
+
const lazyRenderer = getLazyRenderer(ir.type);
|
|
3800
|
+
if (!lazyRenderer) {
|
|
3801
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "my-4 p-3 bg-amber-50 border border-amber-200 rounded-lg text-amber-700 text-xs font-mono", children: [
|
|
3802
|
+
'No renderer registered for "',
|
|
3803
|
+
ir.type,
|
|
3804
|
+
'".'
|
|
3805
|
+
] });
|
|
3806
|
+
}
|
|
3807
|
+
const Component = lazyRenderer;
|
|
3808
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "my-4 text-slate-400 text-xs italic", children: "Loading renderer\u2026" }), children: /* @__PURE__ */ jsxRuntime.jsx(Component, { ir, dark, handleRef }) });
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
// src/utils/diagrams/export.ts
|
|
3812
|
+
var INLINEABLE_STYLE_PROPS = [
|
|
3813
|
+
"fill",
|
|
3814
|
+
"fill-opacity",
|
|
3815
|
+
"stroke",
|
|
3816
|
+
"stroke-width",
|
|
3817
|
+
"stroke-opacity",
|
|
3818
|
+
"stroke-dasharray",
|
|
3819
|
+
"stroke-linecap",
|
|
3820
|
+
"stroke-linejoin",
|
|
3821
|
+
"stroke-miterlimit",
|
|
3822
|
+
"opacity",
|
|
3823
|
+
"visibility",
|
|
3824
|
+
"display",
|
|
3825
|
+
"font-family",
|
|
3826
|
+
"font-size",
|
|
3827
|
+
"font-weight",
|
|
3828
|
+
"font-style",
|
|
3829
|
+
"text-anchor",
|
|
3830
|
+
"dominant-baseline",
|
|
3831
|
+
"alignment-baseline",
|
|
3832
|
+
"letter-spacing",
|
|
3833
|
+
"color",
|
|
3834
|
+
"cursor"
|
|
3835
|
+
];
|
|
3836
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
3837
|
+
var XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
3838
|
+
function resolveSource(source) {
|
|
3839
|
+
if (typeof source === "string") return source;
|
|
3840
|
+
if (typeof source === "function") {
|
|
3841
|
+
const el = source();
|
|
3842
|
+
if (!el) throw new Error("SVG source resolver returned null");
|
|
3843
|
+
return el;
|
|
3844
|
+
}
|
|
3845
|
+
return source;
|
|
3846
|
+
}
|
|
3847
|
+
function inlineStylesOnClone(live, clone) {
|
|
3848
|
+
if (typeof window === "undefined" || !window.getComputedStyle) return;
|
|
3849
|
+
const visit = (l, c) => {
|
|
3850
|
+
const computed = window.getComputedStyle(l);
|
|
3851
|
+
const decls = [];
|
|
3852
|
+
for (const prop of INLINEABLE_STYLE_PROPS) {
|
|
3853
|
+
const value = computed.getPropertyValue(prop);
|
|
3854
|
+
if (value && value !== "" && value !== "none" && value !== "normal") {
|
|
3855
|
+
decls.push(`${prop}: ${value}`);
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
if (decls.length > 0) {
|
|
3859
|
+
const existing = c.getAttribute("style") ?? "";
|
|
3860
|
+
const merged = existing ? `${existing}; ${decls.join("; ")}` : decls.join("; ");
|
|
3861
|
+
c.setAttribute("style", merged);
|
|
3862
|
+
}
|
|
3863
|
+
const liveChildren = l.children;
|
|
3864
|
+
const cloneChildren = c.children;
|
|
3865
|
+
const n = Math.min(liveChildren.length, cloneChildren.length);
|
|
3866
|
+
for (let i = 0; i < n; i++) visit(liveChildren[i], cloneChildren[i]);
|
|
3867
|
+
};
|
|
3868
|
+
visit(live, clone);
|
|
3869
|
+
}
|
|
3870
|
+
function toSvgString(source, options = {}) {
|
|
3871
|
+
const inlineStyles = options.inlineStyles !== false;
|
|
3872
|
+
const stripForeignObject = options.stripForeignObject !== false;
|
|
3873
|
+
const resolved = resolveSource(source);
|
|
3874
|
+
if (typeof resolved === "string") return resolved;
|
|
3875
|
+
const clone = resolved.cloneNode(true);
|
|
3876
|
+
if (!clone.getAttribute("xmlns")) clone.setAttribute("xmlns", SVG_NS);
|
|
3877
|
+
if (!clone.getAttribute("xmlns:xlink")) clone.setAttribute("xmlns:xlink", XLINK_NS);
|
|
3878
|
+
if (inlineStyles) inlineStylesOnClone(resolved, clone);
|
|
3879
|
+
if (stripForeignObject) clone.querySelectorAll("foreignObject").forEach((el) => el.remove());
|
|
3880
|
+
return new XMLSerializer().serializeToString(clone);
|
|
3881
|
+
}
|
|
3882
|
+
function getSvgDimensions(svg) {
|
|
3883
|
+
const fallback = { width: 800, height: 600 };
|
|
3884
|
+
const vbMatch = svg.match(/viewBox\s*=\s*["']([^"']+)["']/);
|
|
3885
|
+
if (vbMatch) {
|
|
3886
|
+
const parts = vbMatch[1].split(/[\s,]+/).map((p) => parseFloat(p)).filter((n) => !isNaN(n));
|
|
3887
|
+
if (parts.length === 4 && parts[2] > 0 && parts[3] > 0) {
|
|
3888
|
+
return { width: parts[2], height: parts[3] };
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
const rootMatch = svg.match(/<svg\b[^>]*>/);
|
|
3892
|
+
if (rootMatch) {
|
|
3893
|
+
const root = rootMatch[0];
|
|
3894
|
+
const wMatch = root.match(/\swidth\s*=\s*["']([^"']+)["']/);
|
|
3895
|
+
const hMatch = root.match(/\sheight\s*=\s*["']([^"']+)["']/);
|
|
3896
|
+
const w = wMatch ? parseFloat(wMatch[1]) : NaN;
|
|
3897
|
+
const h = hMatch ? parseFloat(hMatch[1]) : NaN;
|
|
3898
|
+
return {
|
|
3899
|
+
width: !isNaN(w) && w > 0 ? w : fallback.width,
|
|
3900
|
+
height: !isNaN(h) && h > 0 ? h : fallback.height
|
|
3901
|
+
};
|
|
3902
|
+
}
|
|
3903
|
+
return fallback;
|
|
3904
|
+
}
|
|
3905
|
+
async function svgToPngBlob(svg, options = {}) {
|
|
3906
|
+
const scale = options.scale ?? 2;
|
|
3907
|
+
const background = options.background === void 0 ? "#ffffff" : options.background;
|
|
3908
|
+
const { width, height } = getSvgDimensions(svg);
|
|
3909
|
+
const blob = new Blob([svg], { type: "image/svg+xml;charset=utf-8" });
|
|
3910
|
+
const url = URL.createObjectURL(blob);
|
|
3911
|
+
try {
|
|
3912
|
+
const img = new Image();
|
|
3913
|
+
img.crossOrigin = "anonymous";
|
|
3914
|
+
await new Promise((resolve, reject) => {
|
|
3915
|
+
img.onload = () => resolve();
|
|
3916
|
+
img.onerror = () => reject(new Error("Failed to load SVG image for PNG conversion"));
|
|
3917
|
+
img.src = url;
|
|
3918
|
+
});
|
|
3919
|
+
const canvas = document.createElement("canvas");
|
|
3920
|
+
canvas.width = Math.round(width * scale);
|
|
3921
|
+
canvas.height = Math.round(height * scale);
|
|
3922
|
+
const ctx = canvas.getContext("2d");
|
|
3923
|
+
if (!ctx) throw new Error("Canvas 2D context unavailable");
|
|
3924
|
+
if (background !== null) {
|
|
3925
|
+
ctx.fillStyle = background;
|
|
3926
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
3927
|
+
}
|
|
3928
|
+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
3929
|
+
return await new Promise(
|
|
3930
|
+
(resolve, reject) => canvas.toBlob(
|
|
3931
|
+
(b) => b ? resolve(b) : reject(new Error("canvas.toBlob() returned null")),
|
|
3932
|
+
"image/png"
|
|
3933
|
+
)
|
|
3934
|
+
);
|
|
3935
|
+
} finally {
|
|
3936
|
+
URL.revokeObjectURL(url);
|
|
3937
|
+
}
|
|
3938
|
+
}
|
|
3939
|
+
function triggerDownload(blob, filename) {
|
|
3940
|
+
const url = URL.createObjectURL(blob);
|
|
3941
|
+
const a = document.createElement("a");
|
|
3942
|
+
a.href = url;
|
|
3943
|
+
a.download = filename;
|
|
3944
|
+
a.rel = "noopener";
|
|
3945
|
+
document.body.appendChild(a);
|
|
3946
|
+
a.click();
|
|
3947
|
+
setTimeout(() => {
|
|
3948
|
+
document.body.removeChild(a);
|
|
3949
|
+
URL.revokeObjectURL(url);
|
|
3950
|
+
}, 1500);
|
|
3951
|
+
}
|
|
3952
|
+
async function downloadSvg(source, filename) {
|
|
3953
|
+
const svg = toSvgString(source, { stripForeignObject: false });
|
|
3954
|
+
const blob = new Blob([svg], { type: "image/svg+xml;charset=utf-8" });
|
|
3955
|
+
triggerDownload(blob, filename);
|
|
3956
|
+
}
|
|
3957
|
+
async function downloadPng(source, filename, options = {}) {
|
|
3958
|
+
const svg = toSvgString(source);
|
|
3959
|
+
const blob = await svgToPngBlob(svg, options);
|
|
3960
|
+
triggerDownload(blob, filename);
|
|
3961
|
+
}
|
|
3962
|
+
async function copySvgToClipboard(source) {
|
|
3963
|
+
const svg = toSvgString(source, { stripForeignObject: false });
|
|
3964
|
+
await navigator.clipboard.writeText(svg);
|
|
3965
|
+
}
|
|
3966
|
+
async function copyPngToClipboard(source, options = {}) {
|
|
3967
|
+
const svg = toSvgString(source);
|
|
3968
|
+
const blob = await svgToPngBlob(svg, options);
|
|
3969
|
+
if (typeof ClipboardItem === "undefined" || !navigator.clipboard?.write) {
|
|
3970
|
+
throw new Error("Clipboard image write not supported in this environment");
|
|
3971
|
+
}
|
|
3972
|
+
await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]);
|
|
3973
|
+
}
|
|
3974
|
+
var ICON_PROPS = {
|
|
3975
|
+
width: 11,
|
|
3976
|
+
height: 11,
|
|
3977
|
+
viewBox: "0 0 24 24",
|
|
3978
|
+
fill: "none",
|
|
3979
|
+
stroke: "currentColor",
|
|
3980
|
+
strokeWidth: 2,
|
|
3981
|
+
strokeLinecap: "round",
|
|
3982
|
+
strokeLinejoin: "round",
|
|
3983
|
+
"aria-hidden": true
|
|
3984
|
+
};
|
|
3985
|
+
var IconCopy = () => /* @__PURE__ */ jsxRuntime.jsxs("svg", { ...ICON_PROPS, children: [
|
|
3986
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
3987
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
3988
|
+
] });
|
|
3989
|
+
var IconCheck = (props) => /* @__PURE__ */ jsxRuntime.jsx("svg", { ...ICON_PROPS, stroke: props.color ?? "currentColor", children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "20 6 9 17 4 12" }) });
|
|
3990
|
+
var IconDownload = () => /* @__PURE__ */ jsxRuntime.jsxs("svg", { ...ICON_PROPS, children: [
|
|
3991
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
|
|
3992
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "7 10 12 15 17 10" }),
|
|
3993
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "15", x2: "12", y2: "3" })
|
|
3994
|
+
] });
|
|
3995
|
+
var IconFileImage = () => /* @__PURE__ */ jsxRuntime.jsxs("svg", { ...ICON_PROPS, children: [
|
|
3996
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
|
|
3997
|
+
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "14 2 14 8 20 8" }),
|
|
3998
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "10", cy: "13", r: "2" }),
|
|
3999
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m20 17-1.09-1.09a2 2 0 0 0-2.82 0L10 22" })
|
|
4000
|
+
] });
|
|
4001
|
+
var IconImageDown = () => /* @__PURE__ */ jsxRuntime.jsxs("svg", { ...ICON_PROPS, children: [
|
|
4002
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M10.3 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5.3" }),
|
|
4003
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m14 19 3 3 3-3" }),
|
|
4004
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17 22V13" }),
|
|
4005
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "9", cy: "9", r: "2" })
|
|
4006
|
+
] });
|
|
4007
|
+
function DiagramExportToolbar({
|
|
4008
|
+
source,
|
|
4009
|
+
filenameBase = "diagram",
|
|
4010
|
+
pngScale = 2,
|
|
4011
|
+
pngBackground,
|
|
4012
|
+
className = "",
|
|
4013
|
+
onError
|
|
4014
|
+
}) {
|
|
4015
|
+
const [flash, setFlash] = react.useState("idle");
|
|
4016
|
+
const flashAndReset = (state) => {
|
|
4017
|
+
setFlash(state);
|
|
4018
|
+
setTimeout(() => setFlash("idle"), 2e3);
|
|
4019
|
+
};
|
|
4020
|
+
const safe = async (fn, e) => {
|
|
4021
|
+
e.stopPropagation();
|
|
4022
|
+
try {
|
|
4023
|
+
await fn();
|
|
4024
|
+
} catch (err) {
|
|
4025
|
+
onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
4026
|
+
}
|
|
4027
|
+
};
|
|
4028
|
+
const handleCopySvg = (e) => safe(async () => {
|
|
4029
|
+
await copySvgToClipboard(source);
|
|
4030
|
+
flashAndReset("svg-copied");
|
|
4031
|
+
}, e);
|
|
4032
|
+
const handleCopyPng = (e) => safe(async () => {
|
|
4033
|
+
await copyPngToClipboard(source, { scale: pngScale, background: pngBackground });
|
|
4034
|
+
flashAndReset("png-copied");
|
|
4035
|
+
}, e);
|
|
4036
|
+
const handleDownloadSvg = (e) => safe(() => downloadSvg(source, `${filenameBase}.svg`), e);
|
|
4037
|
+
const handleDownloadPng = (e) => safe(
|
|
4038
|
+
() => downloadPng(source, `${filenameBase}.png`, { scale: pngScale, background: pngBackground }),
|
|
4039
|
+
e
|
|
4040
|
+
);
|
|
4041
|
+
const buttonClass = "flex items-center gap-1 px-2 py-1 rounded-md bg-white border border-slate-200 text-slate-500 hover:text-blue-600 hover:border-blue-300 text-[10px] font-bold shadow-sm transition-colors";
|
|
4042
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-1 ${className}`, role: "toolbar", "aria-label": "Diagram export", children: [
|
|
4043
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4044
|
+
"button",
|
|
4045
|
+
{
|
|
4046
|
+
type: "button",
|
|
4047
|
+
onClick: handleCopySvg,
|
|
4048
|
+
className: buttonClass,
|
|
4049
|
+
"aria-label": "Copy SVG markup to clipboard",
|
|
4050
|
+
title: "Copy SVG markup",
|
|
4051
|
+
children: [
|
|
4052
|
+
flash === "svg-copied" ? /* @__PURE__ */ jsxRuntime.jsx(IconCheck, { color: "#22c55e" }) : /* @__PURE__ */ jsxRuntime.jsx(IconCopy, {}),
|
|
4053
|
+
flash === "svg-copied" ? "Copied!" : "SVG"
|
|
4054
|
+
]
|
|
4055
|
+
}
|
|
4056
|
+
),
|
|
4057
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4058
|
+
"button",
|
|
4059
|
+
{
|
|
4060
|
+
type: "button",
|
|
4061
|
+
onClick: handleCopyPng,
|
|
4062
|
+
className: buttonClass,
|
|
4063
|
+
"aria-label": "Copy diagram as PNG to clipboard",
|
|
4064
|
+
title: "Copy as PNG image",
|
|
4065
|
+
children: [
|
|
4066
|
+
flash === "png-copied" ? /* @__PURE__ */ jsxRuntime.jsx(IconCheck, { color: "#22c55e" }) : /* @__PURE__ */ jsxRuntime.jsx(IconFileImage, {}),
|
|
4067
|
+
flash === "png-copied" ? "Copied!" : "PNG"
|
|
4068
|
+
]
|
|
4069
|
+
}
|
|
4070
|
+
),
|
|
4071
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4072
|
+
"button",
|
|
4073
|
+
{
|
|
4074
|
+
type: "button",
|
|
4075
|
+
onClick: handleDownloadSvg,
|
|
4076
|
+
className: buttonClass,
|
|
4077
|
+
"aria-label": "Download diagram as SVG file",
|
|
4078
|
+
title: "Download SVG",
|
|
4079
|
+
children: [
|
|
4080
|
+
/* @__PURE__ */ jsxRuntime.jsx(IconDownload, {}),
|
|
4081
|
+
" SVG"
|
|
4082
|
+
]
|
|
4083
|
+
}
|
|
4084
|
+
),
|
|
4085
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4086
|
+
"button",
|
|
4087
|
+
{
|
|
4088
|
+
type: "button",
|
|
4089
|
+
onClick: handleDownloadPng,
|
|
4090
|
+
className: buttonClass,
|
|
4091
|
+
"aria-label": "Download diagram as PNG file",
|
|
4092
|
+
title: "Download PNG",
|
|
4093
|
+
children: [
|
|
4094
|
+
/* @__PURE__ */ jsxRuntime.jsx(IconImageDown, {}),
|
|
4095
|
+
" PNG"
|
|
4096
|
+
]
|
|
4097
|
+
}
|
|
4098
|
+
)
|
|
4099
|
+
] });
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
// src/index.ts
|
|
4103
|
+
init_FlowchartRenderer();
|
|
4104
|
+
init_ERRenderer();
|
|
4105
|
+
init_PieRenderer();
|
|
4106
|
+
init_QuadrantRenderer();
|
|
4107
|
+
init_JourneyRenderer();
|
|
4108
|
+
init_SequenceRenderer();
|
|
4109
|
+
init_ClassRenderer();
|
|
4110
|
+
init_StateRenderer();
|
|
4111
|
+
init_GanttRenderer();
|
|
4112
|
+
init_TimelineRenderer();
|
|
4113
|
+
init_MindmapRenderer();
|
|
4114
|
+
init_ArchitectureRenderer();
|
|
4115
|
+
init_C4Renderer();
|
|
4116
|
+
init_GitGraphRenderer();
|
|
4117
|
+
|
|
4118
|
+
// src/components/diagrams/bootstrap.ts
|
|
4119
|
+
var bootstrapped = false;
|
|
4120
|
+
function bootstrapDiagramRenderers() {
|
|
4121
|
+
if (bootstrapped) return;
|
|
4122
|
+
bootstrapped = true;
|
|
4123
|
+
register({
|
|
4124
|
+
type: "flowchart",
|
|
4125
|
+
loader: () => Promise.resolve().then(() => (init_FlowchartRenderer(), FlowchartRenderer_exports))
|
|
4126
|
+
});
|
|
4127
|
+
register({
|
|
4128
|
+
type: "er",
|
|
4129
|
+
loader: () => Promise.resolve().then(() => (init_ERRenderer(), ERRenderer_exports))
|
|
4130
|
+
});
|
|
4131
|
+
register({
|
|
4132
|
+
type: "pie",
|
|
4133
|
+
loader: () => Promise.resolve().then(() => (init_PieRenderer(), PieRenderer_exports))
|
|
4134
|
+
});
|
|
4135
|
+
register({
|
|
4136
|
+
type: "quadrant",
|
|
4137
|
+
loader: () => Promise.resolve().then(() => (init_QuadrantRenderer(), QuadrantRenderer_exports))
|
|
4138
|
+
});
|
|
4139
|
+
register({
|
|
4140
|
+
type: "journey",
|
|
4141
|
+
loader: () => Promise.resolve().then(() => (init_JourneyRenderer(), JourneyRenderer_exports))
|
|
4142
|
+
});
|
|
4143
|
+
register({
|
|
4144
|
+
type: "sequence",
|
|
4145
|
+
loader: () => Promise.resolve().then(() => (init_SequenceRenderer(), SequenceRenderer_exports))
|
|
4146
|
+
});
|
|
4147
|
+
register({
|
|
4148
|
+
type: "class",
|
|
4149
|
+
loader: () => Promise.resolve().then(() => (init_ClassRenderer(), ClassRenderer_exports))
|
|
4150
|
+
});
|
|
4151
|
+
register({
|
|
4152
|
+
type: "state",
|
|
4153
|
+
loader: () => Promise.resolve().then(() => (init_StateRenderer(), StateRenderer_exports))
|
|
4154
|
+
});
|
|
4155
|
+
register({
|
|
4156
|
+
type: "gantt",
|
|
4157
|
+
loader: () => Promise.resolve().then(() => (init_GanttRenderer(), GanttRenderer_exports))
|
|
4158
|
+
});
|
|
4159
|
+
register({
|
|
4160
|
+
type: "timeline",
|
|
4161
|
+
loader: () => Promise.resolve().then(() => (init_TimelineRenderer(), TimelineRenderer_exports))
|
|
4162
|
+
});
|
|
4163
|
+
register({
|
|
4164
|
+
type: "mindmap",
|
|
4165
|
+
loader: () => Promise.resolve().then(() => (init_MindmapRenderer(), MindmapRenderer_exports))
|
|
4166
|
+
});
|
|
4167
|
+
register({
|
|
4168
|
+
type: "architecture",
|
|
4169
|
+
loader: () => Promise.resolve().then(() => (init_ArchitectureRenderer(), ArchitectureRenderer_exports))
|
|
4170
|
+
});
|
|
4171
|
+
register({
|
|
4172
|
+
type: "c4",
|
|
4173
|
+
loader: () => Promise.resolve().then(() => (init_C4Renderer(), C4Renderer_exports))
|
|
4174
|
+
});
|
|
4175
|
+
register({
|
|
4176
|
+
type: "gitgraph",
|
|
4177
|
+
loader: () => Promise.resolve().then(() => (init_GitGraphRenderer(), GitGraphRenderer_exports))
|
|
4178
|
+
});
|
|
4179
|
+
}
|
|
4180
|
+
|
|
4181
|
+
// src/utils/diagrams/convenience.ts
|
|
4182
|
+
init_dagreLayout();
|
|
4183
|
+
init_svgBuilders();
|
|
4184
|
+
var FLOW_DEFAULT_SIZE = { width: 180, height: 60 };
|
|
4185
|
+
var CLASS_NODE_WIDTH = 220;
|
|
4186
|
+
var ER_NODE_WIDTH = 240;
|
|
4187
|
+
var ER_HEADER_H = 34;
|
|
4188
|
+
var ER_ROW_H = 26;
|
|
4189
|
+
function flowchartNodeSize2(label) {
|
|
4190
|
+
const len = label.length;
|
|
4191
|
+
return {
|
|
4192
|
+
width: Math.max(160, Math.min(320, len * 8 + 40)),
|
|
4193
|
+
height: 48
|
|
4194
|
+
};
|
|
4195
|
+
}
|
|
4196
|
+
function flowchartToSvg(ir, options = {}) {
|
|
4197
|
+
const nodeSizes = /* @__PURE__ */ new Map();
|
|
4198
|
+
for (const node of ir.nodes) {
|
|
4199
|
+
nodeSizes.set(node.id, flowchartNodeSize2(node.label || node.id));
|
|
4200
|
+
}
|
|
4201
|
+
const { nodePositions } = layoutFlowchart(ir, {
|
|
4202
|
+
defaultNodeSize: FLOW_DEFAULT_SIZE,
|
|
4203
|
+
nodeSizes
|
|
4204
|
+
});
|
|
4205
|
+
return buildFlowchartSvg(ir, nodePositions, options);
|
|
4206
|
+
}
|
|
4207
|
+
function classToSvg(ir, options = {}) {
|
|
4208
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
4209
|
+
g.setGraph({ rankdir: "TB", nodesep: 50, ranksep: 80, marginx: 24, marginy: 24 });
|
|
4210
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
4211
|
+
const sizeFor = (memberCount) => ({
|
|
4212
|
+
width: CLASS_NODE_WIDTH,
|
|
4213
|
+
height: Math.max(64, 40 + memberCount * 18)
|
|
4214
|
+
});
|
|
4215
|
+
for (const cls of ir.classes) g.setNode(cls.id, sizeFor(cls.members.length));
|
|
4216
|
+
for (const rel of ir.relations) {
|
|
4217
|
+
if (g.hasNode(rel.source) && g.hasNode(rel.target)) g.setEdge(rel.source, rel.target);
|
|
4218
|
+
}
|
|
4219
|
+
dagre2__default.default.layout(g);
|
|
4220
|
+
const positions = /* @__PURE__ */ new Map();
|
|
4221
|
+
for (const cls of ir.classes) {
|
|
4222
|
+
const { x, y } = g.node(cls.id);
|
|
4223
|
+
const size = sizeFor(cls.members.length);
|
|
4224
|
+
positions.set(cls.id, {
|
|
4225
|
+
x: x - size.width / 2,
|
|
4226
|
+
y: y - size.height / 2,
|
|
4227
|
+
width: size.width,
|
|
4228
|
+
height: size.height
|
|
4229
|
+
});
|
|
4230
|
+
}
|
|
4231
|
+
return buildClassSvg(ir, positions, options);
|
|
4232
|
+
}
|
|
4233
|
+
function erToSvg(ir, options = {}) {
|
|
4234
|
+
const g = new dagre2__default.default.graphlib.Graph();
|
|
4235
|
+
g.setGraph({ rankdir: "LR", nodesep: 60, ranksep: 100, marginx: 24, marginy: 24 });
|
|
4236
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
4237
|
+
const tableHeight = (cols) => ER_HEADER_H + cols * ER_ROW_H;
|
|
4238
|
+
for (const table of ir.schema.tables) {
|
|
4239
|
+
g.setNode(table.name, {
|
|
4240
|
+
width: ER_NODE_WIDTH,
|
|
4241
|
+
height: tableHeight(table.columns.length)
|
|
4242
|
+
});
|
|
4243
|
+
}
|
|
4244
|
+
for (const rel of ir.schema.relations) {
|
|
4245
|
+
if (g.hasNode(rel.fromTable) && g.hasNode(rel.toTable)) {
|
|
4246
|
+
g.setEdge(rel.fromTable, rel.toTable);
|
|
4247
|
+
}
|
|
4248
|
+
}
|
|
4249
|
+
dagre2__default.default.layout(g);
|
|
4250
|
+
const positions = /* @__PURE__ */ new Map();
|
|
4251
|
+
for (const table of ir.schema.tables) {
|
|
4252
|
+
const { x, y } = g.node(table.name);
|
|
4253
|
+
const h = tableHeight(table.columns.length);
|
|
4254
|
+
positions.set(table.name, {
|
|
4255
|
+
x: x - ER_NODE_WIDTH / 2,
|
|
4256
|
+
y: y - h / 2,
|
|
4257
|
+
width: ER_NODE_WIDTH,
|
|
4258
|
+
height: h
|
|
4259
|
+
});
|
|
4260
|
+
}
|
|
4261
|
+
return buildErSvg(ir, positions, options);
|
|
4262
|
+
}
|
|
4263
|
+
|
|
4264
|
+
// src/index.ts
|
|
4265
|
+
init_svgBuilders();
|
|
4266
|
+
init_dagreLayout();
|
|
4267
|
+
|
|
4268
|
+
// src/components/diagrams/darkMode.ts
|
|
4269
|
+
function isDarkMode() {
|
|
4270
|
+
if (typeof document === "undefined") return false;
|
|
4271
|
+
return document.documentElement.classList.contains("dark");
|
|
4272
|
+
}
|
|
4273
|
+
function watchDarkMode(callback) {
|
|
4274
|
+
if (typeof MutationObserver === "undefined" || typeof document === "undefined") {
|
|
4275
|
+
return () => {
|
|
4276
|
+
};
|
|
4277
|
+
}
|
|
4278
|
+
let last = isDarkMode();
|
|
4279
|
+
const observer = new MutationObserver(() => {
|
|
4280
|
+
const next = isDarkMode();
|
|
4281
|
+
if (next !== last) {
|
|
4282
|
+
last = next;
|
|
4283
|
+
callback(next);
|
|
4284
|
+
}
|
|
4285
|
+
});
|
|
4286
|
+
observer.observe(document.documentElement, {
|
|
4287
|
+
attributes: true,
|
|
4288
|
+
attributeFilter: ["class"]
|
|
4289
|
+
});
|
|
4290
|
+
return () => observer.disconnect();
|
|
4291
|
+
}
|
|
4292
|
+
|
|
4293
|
+
// src/index.ts
|
|
4294
|
+
init_theme();
|
|
4295
|
+
|
|
4296
|
+
exports.ArchitectureRenderer = ArchitectureRenderer;
|
|
4297
|
+
exports.C4Renderer = C4Renderer;
|
|
4298
|
+
exports.ClassRenderer = ClassRenderer;
|
|
4299
|
+
exports.DiagramExportToolbar = DiagramExportToolbar;
|
|
4300
|
+
exports.DiagramRenderer = DiagramRenderer;
|
|
4301
|
+
exports.ERRenderer = ERRenderer;
|
|
4302
|
+
exports.FlowchartRenderer = FlowchartRenderer;
|
|
4303
|
+
exports.GanttRenderer = GanttRenderer;
|
|
4304
|
+
exports.GitGraphRenderer = GitGraphRenderer;
|
|
4305
|
+
exports.INLINEABLE_STYLE_PROPS = INLINEABLE_STYLE_PROPS;
|
|
4306
|
+
exports.JourneyRenderer = JourneyRenderer;
|
|
4307
|
+
exports.MindmapRenderer = MindmapRenderer;
|
|
4308
|
+
exports.PieRenderer = PieRenderer;
|
|
4309
|
+
exports.QuadrantRenderer = QuadrantRenderer;
|
|
4310
|
+
exports.SequenceRenderer = SequenceRenderer;
|
|
4311
|
+
exports.StateRenderer = StateRenderer;
|
|
4312
|
+
exports.TimelineRenderer = TimelineRenderer;
|
|
4313
|
+
exports._resetRegistry = _resetRegistry;
|
|
4314
|
+
exports.bootstrapDiagramRenderers = bootstrapDiagramRenderers;
|
|
4315
|
+
exports.buildArchitectureSvg = buildArchitectureSvg;
|
|
4316
|
+
exports.buildC4Svg = buildC4Svg;
|
|
4317
|
+
exports.buildClassSvg = buildClassSvg;
|
|
4318
|
+
exports.buildErSvg = buildErSvg;
|
|
4319
|
+
exports.buildFlowchartSvg = buildFlowchartSvg;
|
|
4320
|
+
exports.buildGanttSvg = buildGanttSvg;
|
|
4321
|
+
exports.buildGitGraphSvg = buildGitGraphSvg;
|
|
4322
|
+
exports.buildJourneySvg = buildJourneySvg;
|
|
4323
|
+
exports.buildMindmapSvg = buildMindmapSvg;
|
|
4324
|
+
exports.buildPieSvg = buildPieSvg;
|
|
4325
|
+
exports.buildQuadrantSvg = buildQuadrantSvg;
|
|
4326
|
+
exports.buildStateSvg = buildStateSvg;
|
|
4327
|
+
exports.buildTimelineSvg = buildTimelineSvg;
|
|
4328
|
+
exports.classToSvg = classToSvg;
|
|
4329
|
+
exports.copyPngToClipboard = copyPngToClipboard;
|
|
4330
|
+
exports.copySvgToClipboard = copySvgToClipboard;
|
|
4331
|
+
exports.detectDiagramType = detectDiagramType;
|
|
4332
|
+
exports.downloadPng = downloadPng;
|
|
4333
|
+
exports.downloadSvg = downloadSvg;
|
|
4334
|
+
exports.erToSvg = erToSvg;
|
|
4335
|
+
exports.flowchartToSvg = flowchartToSvg;
|
|
4336
|
+
exports.getDiagramTheme = getDiagramTheme;
|
|
4337
|
+
exports.getRenderer = getRenderer;
|
|
4338
|
+
exports.getSvgDimensions = getSvgDimensions;
|
|
4339
|
+
exports.hasRenderer = hasRenderer;
|
|
4340
|
+
exports.isDarkMode = isDarkMode;
|
|
4341
|
+
exports.layoutFlowchart = layoutFlowchart;
|
|
4342
|
+
exports.parseToIR = parseToIR;
|
|
4343
|
+
exports.register = register;
|
|
4344
|
+
exports.svgStringToElement = svgStringToElement;
|
|
4345
|
+
exports.svgToPngBlob = svgToPngBlob;
|
|
4346
|
+
exports.toSvgString = toSvgString;
|
|
4347
|
+
exports.watchDarkMode = watchDarkMode;
|
|
4348
|
+
//# sourceMappingURL=index.cjs.map
|
|
4349
|
+
//# sourceMappingURL=index.cjs.map
|