@node-projects/web-component-designer-mermaid 0.1.0 → 0.3.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/{src/index.ts → dist/index.d.ts} +0 -3
- package/dist/index.js +17 -0
- package/dist/monaco/MermaidLanguage.d.ts +1 -0
- package/{src/monaco/MermaidLanguage.ts → dist/monaco/MermaidLanguage.js} +1 -4
- package/dist/services/MermaidConnectionRouting.d.ts +2 -0
- package/{src/services/MermaidConnectionRouting.ts → dist/services/MermaidConnectionRouting.js} +25 -46
- package/dist/services/MermaidDocumentPropertiesService.d.ts +24 -0
- package/{src/services/MermaidDocumentPropertiesService.ts → dist/services/MermaidDocumentPropertiesService.js} +25 -54
- package/dist/services/MermaidElementsService.d.ts +23 -0
- package/{src/services/MermaidElementsService.ts → dist/services/MermaidElementsService.js} +35 -36
- package/dist/services/MermaidLayoutCopyPasteService.d.ts +5 -0
- package/{src/services/MermaidLayoutCopyPasteService.ts → dist/services/MermaidLayoutCopyPasteService.js} +4 -6
- package/dist/services/MermaidLayoutPlacementService.d.ts +8 -0
- package/{src/services/MermaidLayoutPlacementService.ts → dist/services/MermaidLayoutPlacementService.js} +6 -11
- package/dist/services/MermaidParserService.d.ts +7 -0
- package/{src/services/MermaidParserService.ts → dist/services/MermaidParserService.js} +441 -707
- package/dist/services/MermaidPropertyGroupsService.d.ts +8 -0
- package/{src/services/MermaidPropertyGroupsService.ts → dist/services/MermaidPropertyGroupsService.js} +2 -7
- package/dist/services/mermaidGeometry.d.ts +31 -0
- package/{src/services/mermaidGeometry.ts → dist/services/mermaidGeometry.js} +13 -43
- package/dist/setupMermaidServiceContainer.d.ts +2 -0
- package/{src/setupMermaidServiceContainer.ts → dist/setupMermaidServiceContainer.js} +27 -36
- package/dist/toolbar/ConnectMermaidNodesTool.d.ts +20 -0
- package/{src/toolbar/ConnectMermaidNodesTool.ts → dist/toolbar/ConnectMermaidNodesTool.js} +26 -58
- package/dist/widgets/mermaid-edge.d.ts +46 -0
- package/{src/widgets/mermaid-edge.ts → dist/widgets/mermaid-edge.js} +63 -61
- package/dist/widgets/mermaid-flowchart-directive.d.ts +16 -0
- package/{src/widgets/mermaid-flowchart-directive.ts → dist/widgets/mermaid-flowchart-directive.js} +11 -23
- package/dist/widgets/mermaid-mindmap-node.d.ts +37 -0
- package/{src/widgets/mermaid-mindmap-node.ts → dist/widgets/mermaid-mindmap-node.js} +36 -55
- package/dist/widgets/mermaid-node.d.ts +75 -0
- package/{src/widgets/mermaid-node.ts → dist/widgets/mermaid-node.js} +78 -105
- package/dist/widgets/mermaid-requirement-node.d.ts +37 -0
- package/{src/widgets/mermaid-requirement-node.ts → dist/widgets/mermaid-requirement-node.js} +30 -49
- package/dist/widgets/mermaid-requirement-relationship.d.ts +28 -0
- package/{src/widgets/mermaid-requirement-relationship.ts → dist/widgets/mermaid-requirement-relationship.js} +21 -38
- package/dist/widgets/mermaid-sequence-message.d.ts +34 -0
- package/{src/widgets/mermaid-sequence-message.ts → dist/widgets/mermaid-sequence-message.js} +30 -44
- package/dist/widgets/mermaid-sequence-participant.d.ts +24 -0
- package/{src/widgets/mermaid-sequence-participant.ts → dist/widgets/mermaid-sequence-participant.js} +17 -28
- package/dist/widgets/mermaid-subgraph.d.ts +20 -0
- package/{src/widgets/mermaid-subgraph.ts → dist/widgets/mermaid-subgraph.js} +13 -25
- package/dist/widgets/views/mermaid-demo-view.d.ts +11 -0
- package/{src/widgets/views/mermaid-demo-view.ts → dist/widgets/views/mermaid-demo-view.js} +8 -18
- package/package.json +7 -2
- package/tsconfig.json +0 -20
- /package/{src → dist}/widgets/elements.json +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DesignItem
|
|
1
|
+
import { DesignItem } from "@node-projects/web-component-designer";
|
|
2
2
|
import { MermaidEdge } from "../widgets/mermaid-edge.js";
|
|
3
3
|
import { MermaidNode, normalizeLabelLineBreaks } from "../widgets/mermaid-node.js";
|
|
4
4
|
import { MermaidSequenceMessage } from "../widgets/mermaid-sequence-message.js";
|
|
@@ -8,111 +8,12 @@ import { MermaidRequirementNode } from "../widgets/mermaid-requirement-node.js";
|
|
|
8
8
|
import { MermaidRequirementRelationship } from "../widgets/mermaid-requirement-relationship.js";
|
|
9
9
|
import { MermaidSubgraph } from "../widgets/mermaid-subgraph.js";
|
|
10
10
|
import { MermaidFlowchartDirective } from "../widgets/mermaid-flowchart-directive.js";
|
|
11
|
-
import { getMermaidDocumentDiagramType, getMermaidDocumentFrontmatter, getMermaidDocumentTitle, mermaidDiagramTypeAttribute, mermaidFlowchartDirectionAttribute, mermaidFrontmatterAttribute, mermaidTitleAttribute
|
|
12
|
-
import { encodeWaypoints,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
id: string;
|
|
16
|
-
label: string;
|
|
17
|
-
shape: string;
|
|
18
|
-
parentId?: string;
|
|
19
|
-
classes?: string;
|
|
20
|
-
style?: string;
|
|
21
|
-
sourceRange?: { start: number; length: number };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type ParsedEdge = {
|
|
25
|
-
from: string;
|
|
26
|
-
to: string;
|
|
27
|
-
fromNode?: ParsedNode;
|
|
28
|
-
toNode?: ParsedNode;
|
|
29
|
-
label: string;
|
|
30
|
-
edgeType: string;
|
|
31
|
-
connector?: string;
|
|
32
|
-
edgeId?: string;
|
|
33
|
-
animation?: string;
|
|
34
|
-
connectorRange?: { start: number; length: number };
|
|
35
|
-
sourceRange?: { start: number; length: number };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type ParsedSubgraph = {
|
|
39
|
-
id: string;
|
|
40
|
-
title: string;
|
|
41
|
-
parentId?: string;
|
|
42
|
-
direction?: FlowchartDirection;
|
|
43
|
-
sourceRange?: { start: number; length: number };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
type ParsedFlowchartDirective = {
|
|
47
|
-
line: string;
|
|
48
|
-
sourceRange?: { start: number; length: number };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
type ParsedSequenceParticipant = {
|
|
52
|
-
id: string;
|
|
53
|
-
label: string;
|
|
54
|
-
participantType: string;
|
|
55
|
-
implicit?: boolean;
|
|
56
|
-
sourceRange?: { start: number; length: number };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
type ParsedSequenceMessage = {
|
|
60
|
-
from: string;
|
|
61
|
-
to: string;
|
|
62
|
-
label: string;
|
|
63
|
-
messageType: string;
|
|
64
|
-
connector: string;
|
|
65
|
-
sourceRange?: { start: number; length: number };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type ParsedMindmapNode = {
|
|
69
|
-
id: string;
|
|
70
|
-
parentId: string;
|
|
71
|
-
label: string;
|
|
72
|
-
shape: string;
|
|
73
|
-
indent: number;
|
|
74
|
-
sourceRange?: { start: number; length: number };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
type ParsedRequirementNode = {
|
|
78
|
-
id: string;
|
|
79
|
-
kind: "requirement" | "element";
|
|
80
|
-
requirementType?: string;
|
|
81
|
-
requirementId?: string;
|
|
82
|
-
text?: string;
|
|
83
|
-
risk?: string;
|
|
84
|
-
verifyMethod?: string;
|
|
85
|
-
elementType?: string;
|
|
86
|
-
docRef?: string;
|
|
87
|
-
sourceRange?: { start: number; length: number };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
type ParsedRequirementRelationship = {
|
|
91
|
-
from: string;
|
|
92
|
-
to: string;
|
|
93
|
-
relationshipType: string;
|
|
94
|
-
syntaxDirection: "forward" | "reverse";
|
|
95
|
-
sourceRange?: { start: number; length: number };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
type LineRecord = {
|
|
99
|
-
text: string;
|
|
100
|
-
trimmed: string;
|
|
101
|
-
indent: number;
|
|
102
|
-
start: number;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
type ParsedMermaidDocument = {
|
|
106
|
-
lines: LineRecord[];
|
|
107
|
-
title: string;
|
|
108
|
-
frontmatter: string;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export class MermaidParserService implements IHtmlParserService, IHtmlWriterService {
|
|
112
|
-
options: IHtmlWriterOptions = {};
|
|
11
|
+
import { getMermaidDocumentDiagramType, getMermaidDocumentFrontmatter, getMermaidDocumentTitle, mermaidDiagramTypeAttribute, mermaidFlowchartDirectionAttribute, mermaidFrontmatterAttribute, mermaidTitleAttribute } from "./MermaidDocumentPropertiesService.js";
|
|
12
|
+
import { encodeWaypoints, routeBetweenBounds } from "./mermaidGeometry.js";
|
|
13
|
+
export class MermaidParserService {
|
|
14
|
+
options = {};
|
|
113
15
|
supportsRootItemWrite = true;
|
|
114
|
-
|
|
115
|
-
async parse(html: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer, parseSnippet: boolean): Promise<IDesignItem[]> {
|
|
16
|
+
async parse(html, serviceContainer, instanceServiceContainer, parseSnippet) {
|
|
116
17
|
const diagramKind = getDiagramKind(readMermaidDocument(html));
|
|
117
18
|
if (diagramKind === "sequence")
|
|
118
19
|
return parseSequenceDiagram(html, serviceContainer, instanceServiceContainer);
|
|
@@ -122,8 +23,7 @@ export class MermaidParserService implements IHtmlParserService, IHtmlWriterServ
|
|
|
122
23
|
return parseRequirementDiagram(html, serviceContainer, instanceServiceContainer);
|
|
123
24
|
return parseFlowchart(html, serviceContainer, instanceServiceContainer);
|
|
124
25
|
}
|
|
125
|
-
|
|
126
|
-
write(textWriter: ITextWriter, designItems: IDesignItem[], rootContainerKeepInline: boolean, updatePositions?: boolean) {
|
|
26
|
+
write(textWriter, designItems, rootContainerKeepInline, updatePositions) {
|
|
127
27
|
const rootDesignItem = getRootDesignItem(designItems);
|
|
128
28
|
const mermaidDesignItems = getMermaidDesignItems(designItems);
|
|
129
29
|
const documentType = getWritableDocumentDiagramType(mermaidDesignItems.length ? mermaidDesignItems : designItems);
|
|
@@ -139,12 +39,10 @@ export class MermaidParserService implements IHtmlParserService, IHtmlWriterServ
|
|
|
139
39
|
writeRequirementDiagram(textWriter, mermaidDesignItems, updatePositions, rootDesignItem);
|
|
140
40
|
return;
|
|
141
41
|
}
|
|
142
|
-
|
|
143
42
|
writeFlowchart(textWriter, mermaidDesignItems, updatePositions, rootDesignItem);
|
|
144
43
|
}
|
|
145
44
|
}
|
|
146
|
-
|
|
147
|
-
function getDiagramKind(document: ParsedMermaidDocument) {
|
|
45
|
+
function getDiagramKind(document) {
|
|
148
46
|
const firstMeaningfulLine = document.lines.find(line => line.trimmed && !line.trimmed.startsWith("%%"))?.trimmed ?? "";
|
|
149
47
|
if (equalsIgnoreCase(firstMeaningfulLine, "sequenceDiagram"))
|
|
150
48
|
return "sequence";
|
|
@@ -154,272 +52,266 @@ function getDiagramKind(document: ParsedMermaidDocument) {
|
|
|
154
52
|
return "requirementDiagram";
|
|
155
53
|
return "flowchart";
|
|
156
54
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
subgraphStack.push(subgraph);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (equalsIgnoreCase(line.trimmed, "end")) {
|
|
184
|
-
subgraphStack.pop();
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const directive = parseFlowchartDirective(line.trimmed, line.start);
|
|
189
|
-
if (directive) {
|
|
190
|
-
directives.push(directive);
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const parsedDirection = parseFlowchartDirection(line.trimmed);
|
|
195
|
-
if (parsedDirection) {
|
|
196
|
-
if (subgraphStack.length)
|
|
197
|
-
subgraphStack[subgraphStack.length - 1].direction = parsedDirection;
|
|
198
|
-
else
|
|
199
|
-
direction = parsedDirection;
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
const parsedSubgraphDirection = parseDirectionStatement(line.trimmed);
|
|
203
|
-
if (parsedSubgraphDirection && subgraphStack.length) {
|
|
204
|
-
subgraphStack[subgraphStack.length - 1].direction = parsedSubgraphDirection;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const edge = parseEdge(line.trimmed, line.start);
|
|
209
|
-
if (edge) {
|
|
210
|
-
scannedEdges.push(edge);
|
|
211
|
-
mergeNode(scannedNodes, edge.fromNode);
|
|
212
|
-
mergeNode(scannedNodes, edge.toNode);
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const node = parseNode(line.trimmed, line.start);
|
|
217
|
-
if (node) {
|
|
218
|
-
node.parentId = subgraphStack[subgraphStack.length - 1]?.id;
|
|
219
|
-
mergeNode(scannedNodes, node);
|
|
220
|
-
}
|
|
55
|
+
async function parseFlowchart(html, serviceContainer, instanceServiceContainer) {
|
|
56
|
+
const document = readMermaidDocument(html);
|
|
57
|
+
const lines = document.lines;
|
|
58
|
+
const designItems = [];
|
|
59
|
+
const nodes = new Map();
|
|
60
|
+
const nodeBounds = new Map();
|
|
61
|
+
const edges = [];
|
|
62
|
+
const subgraphs = new Map();
|
|
63
|
+
const directives = [];
|
|
64
|
+
const edgeDirectives = new Map();
|
|
65
|
+
const subgraphStack = [];
|
|
66
|
+
let direction = "TD";
|
|
67
|
+
const scannedNodes = new Map();
|
|
68
|
+
const scannedEdges = [];
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
if (!line.trimmed || line.trimmed.startsWith("%%"))
|
|
71
|
+
continue;
|
|
72
|
+
const subgraph = parseSubgraphStart(line.trimmed, line.start, subgraphStack[subgraphStack.length - 1]?.id);
|
|
73
|
+
if (subgraph) {
|
|
74
|
+
subgraphs.set(subgraph.id, subgraph);
|
|
75
|
+
subgraphStack.push(subgraph);
|
|
76
|
+
continue;
|
|
221
77
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (parsed) {
|
|
226
|
-
for (const node of parsed.nodes) {
|
|
227
|
-
const scanned = scannedNodes.get(node.id);
|
|
228
|
-
mergeNode(nodes, { ...node, parentId: scanned?.parentId, classes: scanned?.classes, style: scanned?.style, sourceRange: scanned?.sourceRange });
|
|
229
|
-
}
|
|
230
|
-
for (const edge of parsed.edges) {
|
|
231
|
-
const scanned = getScannedEdge(scannedEdges, edge);
|
|
232
|
-
edges.push({ ...edge, ...scanned });
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
235
|
-
for (const node of scannedNodes.values())
|
|
236
|
-
mergeNode(nodes, node);
|
|
237
|
-
edges.push(...scannedEdges);
|
|
78
|
+
if (equalsIgnoreCase(line.trimmed, "end")) {
|
|
79
|
+
subgraphStack.pop();
|
|
80
|
+
continue;
|
|
238
81
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
for (const subgraph of subgraphs.values()) {
|
|
244
|
-
const layout = mermaidLayout?.subgraphs?.get(subgraph.id);
|
|
245
|
-
const element = new MermaidSubgraph();
|
|
246
|
-
element.style.position = "absolute";
|
|
247
|
-
element.style.left = (layout?.x ?? (30 + subgraphIndex * 40)) + "px";
|
|
248
|
-
element.style.top = (layout?.y ?? (30 + subgraphIndex * 40)) + "px";
|
|
249
|
-
element.style.width = (layout?.width ?? 360) + "px";
|
|
250
|
-
element.style.height = (layout?.height ?? 240) + "px";
|
|
251
|
-
element.setAttribute("subgraph-id", subgraph.id);
|
|
252
|
-
element.setAttribute("title", subgraph.title);
|
|
253
|
-
if (subgraph.direction)
|
|
254
|
-
element.setAttribute("direction", subgraph.direction);
|
|
255
|
-
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
256
|
-
designItemsById.set(subgraph.id, designItem);
|
|
257
|
-
const parentItem = designItemsById.get(subgraph.parentId);
|
|
258
|
-
if (parentItem)
|
|
259
|
-
parentItem._insertChildInternal(designItem);
|
|
260
|
-
else
|
|
261
|
-
designItems.push(designItem);
|
|
262
|
-
if (subgraph.sourceRange)
|
|
263
|
-
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, subgraph.sourceRange);
|
|
264
|
-
subgraphIndex++;
|
|
82
|
+
const directive = parseFlowchartDirective(line.trimmed, line.start);
|
|
83
|
+
if (directive) {
|
|
84
|
+
directives.push(directive);
|
|
85
|
+
continue;
|
|
265
86
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const parentLayout = node.parentId ? mermaidLayout?.subgraphs?.get(node.parentId) : null;
|
|
271
|
-
const fallbackPosition = getFallbackFlowchartNodePosition(index, nodes.size, direction);
|
|
272
|
-
const left = layout ? layout.x - (parentLayout?.x ?? 0) : fallbackPosition.left;
|
|
273
|
-
const top = layout ? layout.y - (parentLayout?.y ?? 0) : fallbackPosition.top;
|
|
274
|
-
const width = layout?.width ?? getDefaultNodeSize(node.shape).width;
|
|
275
|
-
const height = layout?.height ?? getDefaultNodeSize(node.shape).height;
|
|
276
|
-
const element = new MermaidNode();
|
|
277
|
-
element.style.position = "absolute";
|
|
278
|
-
element.style.left = left + "px";
|
|
279
|
-
element.style.top = top + "px";
|
|
280
|
-
element.style.width = width + "px";
|
|
281
|
-
element.style.height = height + "px";
|
|
282
|
-
element.setAttribute("node-id", node.id);
|
|
283
|
-
element.setAttribute("label", node.label);
|
|
284
|
-
element.setAttribute("shape", node.shape);
|
|
285
|
-
element.setAttribute("diagram-direction", direction);
|
|
286
|
-
if (node.classes)
|
|
287
|
-
element.setAttribute("classes", node.classes);
|
|
288
|
-
if (node.style)
|
|
289
|
-
element.setAttribute("style-directive", node.style);
|
|
290
|
-
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
291
|
-
const parentItem = designItemsById.get(node.parentId);
|
|
292
|
-
if (parentItem)
|
|
293
|
-
parentItem._insertChildInternal(designItem);
|
|
87
|
+
const parsedDirection = parseFlowchartDirection(line.trimmed);
|
|
88
|
+
if (parsedDirection) {
|
|
89
|
+
if (subgraphStack.length)
|
|
90
|
+
subgraphStack[subgraphStack.length - 1].direction = parsedDirection;
|
|
294
91
|
else
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (node.sourceRange)
|
|
298
|
-
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, node.sourceRange);
|
|
299
|
-
nodeBounds.set(node.id, { x: layout?.x ?? left, y: layout?.y ?? top, width, height });
|
|
300
|
-
index++;
|
|
92
|
+
direction = parsedDirection;
|
|
93
|
+
continue;
|
|
301
94
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
element.style.position = "absolute";
|
|
307
|
-
element.style.left = "40px";
|
|
308
|
-
element.style.top = 60 + index * 110 + edgeIndex * 44 + "px";
|
|
309
|
-
element.style.width = "220px";
|
|
310
|
-
element.style.height = "28px";
|
|
311
|
-
element.setAttribute("from", edge.from);
|
|
312
|
-
element.setAttribute("to", edge.to);
|
|
313
|
-
element.setAttribute("label", edge.label);
|
|
314
|
-
element.setAttribute("edge-type", edge.edgeType);
|
|
315
|
-
if (edge.connector)
|
|
316
|
-
element.setAttribute("connector", edge.connector);
|
|
317
|
-
if (edge.edgeId)
|
|
318
|
-
element.setAttribute("edge-id", edge.edgeId);
|
|
319
|
-
if (edge.animation)
|
|
320
|
-
element.setAttribute("animation", edge.animation);
|
|
321
|
-
element.setAttribute("diagram-direction", direction);
|
|
322
|
-
const sourceBounds = nodeBounds.get(edge.from);
|
|
323
|
-
const targetBounds = nodeBounds.get(edge.to);
|
|
324
|
-
if (sourceBounds && targetBounds)
|
|
325
|
-
element.setAttribute("waypoints", encodeWaypoints(routeBetweenBounds(sourceBounds, targetBounds, direction)));
|
|
326
|
-
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
327
|
-
designItems.push(designItem);
|
|
328
|
-
if (edge.sourceRange)
|
|
329
|
-
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, edge.connectorRange ?? edge.sourceRange);
|
|
330
|
-
edgeIndex++;
|
|
95
|
+
const parsedSubgraphDirection = parseDirectionStatement(line.trimmed);
|
|
96
|
+
if (parsedSubgraphDirection && subgraphStack.length) {
|
|
97
|
+
subgraphStack[subgraphStack.length - 1].direction = parsedSubgraphDirection;
|
|
98
|
+
continue;
|
|
331
99
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
element.style.position = "absolute";
|
|
337
|
-
element.style.left = "40px";
|
|
338
|
-
element.style.top = 60 + index * 110 + edgeIndex * 44 + directiveIndex * 28 + "px";
|
|
339
|
-
element.style.width = "320px";
|
|
340
|
-
element.style.height = "24px";
|
|
341
|
-
element.setAttribute("line", directive.line);
|
|
342
|
-
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
343
|
-
designItems.push(designItem);
|
|
344
|
-
if (directive.sourceRange)
|
|
345
|
-
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, directive.sourceRange);
|
|
346
|
-
directiveIndex++;
|
|
100
|
+
const edgeDirective = parseFlowchartEdgeDirective(line.trimmed, line.start);
|
|
101
|
+
if (edgeDirective) {
|
|
102
|
+
edgeDirectives.set(edgeDirective.edgeId, edgeDirective);
|
|
103
|
+
continue;
|
|
347
104
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const direction = isFlowchartDirection(rootDirection) ? rootDirection : getDiagramDirection(designItems);
|
|
355
|
-
writeMermaidFrontmatter(textWriter, designItems, rootDesignItem);
|
|
356
|
-
textWriter.writeLine("flowchart " + direction);
|
|
357
|
-
const allFlowchartItems = getAllFlowchartItems(designItems);
|
|
358
|
-
const nodeIdsUsedByEdges = getFlowchartNodeIdsUsedByEdges(allFlowchartItems);
|
|
359
|
-
const nodeItemsById = getFlowchartNodeItemsById(allFlowchartItems);
|
|
360
|
-
const explicitlyWrittenNodeIds = new Set<string>();
|
|
361
|
-
|
|
362
|
-
const writeNodeOrSubgraph = (designItem: IDesignItem, depth: number) => {
|
|
363
|
-
const element = designItem.element as HTMLElement & { createMermaid?: () => string };
|
|
364
|
-
if (element.nodeName === "MERMAID-SUBGRAPH") {
|
|
365
|
-
const subgraphElement = element as HTMLElement & { createMermaidStart?: () => string };
|
|
366
|
-
writeDesignItemLine(textWriter, designItem, repeatText(" ", depth) + subgraphElement.createMermaidStart(), updatePositions);
|
|
367
|
-
const subgraphDirection = element.getAttribute("direction");
|
|
368
|
-
if (isFlowchartDirection(subgraphDirection))
|
|
369
|
-
textWriter.writeLine(repeatText(" ", depth + 1) + "direction " + subgraphDirection);
|
|
370
|
-
for (const child of designItem.children())
|
|
371
|
-
writeNodeOrSubgraph(child, depth + 1);
|
|
372
|
-
textWriter.writeLine(repeatText(" ", depth) + "end");
|
|
373
|
-
} else if (element.nodeName === "MERMAID-NODE" && element.createMermaid && shouldWriteFlowchartNode(element, nodeIdsUsedByEdges)) {
|
|
374
|
-
writeDesignItemLine(textWriter, designItem, repeatText(" ", depth) + element.createMermaid(), updatePositions);
|
|
375
|
-
explicitlyWrittenNodeIds.add(element.getAttribute("node-id"));
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
for (const designItem of designItems) {
|
|
380
|
-
writeNodeOrSubgraph(designItem, 1);
|
|
105
|
+
const edge = parseEdge(line.trimmed, line.start);
|
|
106
|
+
if (edge) {
|
|
107
|
+
scannedEdges.push(edge);
|
|
108
|
+
mergeNode(scannedNodes, edge.fromNode);
|
|
109
|
+
mergeNode(scannedNodes, edge.toNode);
|
|
110
|
+
continue;
|
|
381
111
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
112
|
+
const node = parseNode(line.trimmed, line.start);
|
|
113
|
+
if (node) {
|
|
114
|
+
node.parentId = subgraphStack[subgraphStack.length - 1]?.id;
|
|
115
|
+
mergeNode(scannedNodes, node);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
setMermaidDocumentAttributes(instanceServiceContainer, "flowchart", direction, document.title, document.frontmatter);
|
|
119
|
+
const parsed = await getMermaidFlowchartData(html);
|
|
120
|
+
if (parsed) {
|
|
121
|
+
for (const node of parsed.nodes) {
|
|
122
|
+
const scanned = scannedNodes.get(node.id);
|
|
123
|
+
mergeNode(nodes, { ...node, parentId: scanned?.parentId, classes: scanned?.classes, style: scanned?.style, sourceRange: scanned?.sourceRange });
|
|
124
|
+
}
|
|
125
|
+
for (const edge of parsed.edges) {
|
|
126
|
+
const scanned = getScannedEdge(scannedEdges, edge);
|
|
127
|
+
const edgeDirective = scanned.edgeId ? edgeDirectives.get(scanned.edgeId) : null;
|
|
128
|
+
edges.push({ ...edge, ...scanned, animation: edgeDirective?.animation ?? scanned.animation });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
for (const node of scannedNodes.values())
|
|
133
|
+
mergeNode(nodes, node);
|
|
134
|
+
edges.push(...scannedEdges.map(edge => {
|
|
135
|
+
const edgeDirective = edge.edgeId ? edgeDirectives.get(edge.edgeId) : null;
|
|
136
|
+
return { ...edge, animation: edgeDirective?.animation ?? edge.animation };
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
const mermaidLayout = await getMermaidLayout(html, nodes);
|
|
140
|
+
const designItemsById = new Map();
|
|
141
|
+
let subgraphIndex = 0;
|
|
142
|
+
for (const subgraph of subgraphs.values()) {
|
|
143
|
+
const layout = mermaidLayout?.subgraphs?.get(subgraph.id);
|
|
144
|
+
const element = new MermaidSubgraph();
|
|
145
|
+
element.style.position = "absolute";
|
|
146
|
+
element.style.left = (layout?.x ?? (30 + subgraphIndex * 40)) + "px";
|
|
147
|
+
element.style.top = (layout?.y ?? (30 + subgraphIndex * 40)) + "px";
|
|
148
|
+
element.style.width = (layout?.width ?? 360) + "px";
|
|
149
|
+
element.style.height = (layout?.height ?? 240) + "px";
|
|
150
|
+
element.setAttribute("subgraph-id", subgraph.id);
|
|
151
|
+
element.setAttribute("title", subgraph.title);
|
|
152
|
+
if (subgraph.direction)
|
|
153
|
+
element.setAttribute("direction", subgraph.direction);
|
|
154
|
+
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
155
|
+
designItemsById.set(subgraph.id, designItem);
|
|
156
|
+
const parentItem = designItemsById.get(subgraph.parentId);
|
|
157
|
+
if (parentItem)
|
|
158
|
+
parentItem._insertChildInternal(designItem);
|
|
159
|
+
else
|
|
160
|
+
designItems.push(designItem);
|
|
161
|
+
if (subgraph.sourceRange)
|
|
162
|
+
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, subgraph.sourceRange);
|
|
163
|
+
subgraphIndex++;
|
|
164
|
+
}
|
|
165
|
+
let index = 0;
|
|
166
|
+
for (const node of nodes.values()) {
|
|
167
|
+
const layout = mermaidLayout?.nodes.get(node.id);
|
|
168
|
+
const parentLayout = node.parentId ? mermaidLayout?.subgraphs?.get(node.parentId) : null;
|
|
169
|
+
const fallbackPosition = getFallbackFlowchartNodePosition(index, nodes.size, direction);
|
|
170
|
+
const left = layout ? layout.x - (parentLayout?.x ?? 0) : fallbackPosition.left;
|
|
171
|
+
const top = layout ? layout.y - (parentLayout?.y ?? 0) : fallbackPosition.top;
|
|
172
|
+
const width = layout?.width ?? getDefaultNodeSize(node.shape).width;
|
|
173
|
+
const height = layout?.height ?? getDefaultNodeSize(node.shape).height;
|
|
174
|
+
const element = new MermaidNode();
|
|
175
|
+
element.style.position = "absolute";
|
|
176
|
+
element.style.left = left + "px";
|
|
177
|
+
element.style.top = top + "px";
|
|
178
|
+
element.style.width = width + "px";
|
|
179
|
+
element.style.height = height + "px";
|
|
180
|
+
element.setAttribute("node-id", node.id);
|
|
181
|
+
element.setAttribute("label", node.label);
|
|
182
|
+
element.setAttribute("shape", node.shape);
|
|
183
|
+
element.setAttribute("diagram-direction", direction);
|
|
184
|
+
if (node.classes)
|
|
185
|
+
element.setAttribute("classes", node.classes);
|
|
186
|
+
if (node.style)
|
|
187
|
+
element.setAttribute("style-directive", node.style);
|
|
188
|
+
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
189
|
+
const parentItem = designItemsById.get(node.parentId);
|
|
190
|
+
if (parentItem)
|
|
191
|
+
parentItem._insertChildInternal(designItem);
|
|
192
|
+
else
|
|
193
|
+
designItems.push(designItem);
|
|
194
|
+
designItemsById.set(node.id, designItem);
|
|
195
|
+
if (node.sourceRange)
|
|
196
|
+
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, node.sourceRange);
|
|
197
|
+
nodeBounds.set(node.id, { x: layout?.x ?? left, y: layout?.y ?? top, width, height });
|
|
198
|
+
index++;
|
|
199
|
+
}
|
|
200
|
+
let edgeIndex = 0;
|
|
201
|
+
for (const edge of edges) {
|
|
202
|
+
const element = new MermaidEdge();
|
|
203
|
+
element.style.position = "absolute";
|
|
204
|
+
element.style.left = "40px";
|
|
205
|
+
element.style.top = 60 + index * 110 + edgeIndex * 44 + "px";
|
|
206
|
+
element.style.width = "220px";
|
|
207
|
+
element.style.height = "28px";
|
|
208
|
+
element.setAttribute("from", edge.from);
|
|
209
|
+
element.setAttribute("to", edge.to);
|
|
210
|
+
element.setAttribute("label", edge.label);
|
|
211
|
+
element.setAttribute("edge-type", edge.edgeType);
|
|
212
|
+
if (edge.connector)
|
|
213
|
+
element.setAttribute("connector", edge.connector);
|
|
214
|
+
if (edge.edgeId)
|
|
215
|
+
element.setAttribute("edge-id", edge.edgeId);
|
|
216
|
+
if (edge.animation)
|
|
217
|
+
element.setAttribute("animation", edge.animation);
|
|
218
|
+
element.setAttribute("diagram-direction", direction);
|
|
219
|
+
const sourceBounds = nodeBounds.get(edge.from);
|
|
220
|
+
const targetBounds = nodeBounds.get(edge.to);
|
|
221
|
+
if (sourceBounds && targetBounds)
|
|
222
|
+
element.setAttribute("waypoints", encodeWaypoints(routeBetweenBounds(sourceBounds, targetBounds, direction)));
|
|
223
|
+
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
224
|
+
designItems.push(designItem);
|
|
225
|
+
if (edge.sourceRange)
|
|
226
|
+
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, edge.connectorRange ?? edge.sourceRange);
|
|
227
|
+
edgeIndex++;
|
|
228
|
+
}
|
|
229
|
+
let directiveIndex = 0;
|
|
230
|
+
for (const directive of directives) {
|
|
231
|
+
const element = new MermaidFlowchartDirective();
|
|
232
|
+
element.style.position = "absolute";
|
|
233
|
+
element.style.left = "40px";
|
|
234
|
+
element.style.top = 60 + index * 110 + edgeIndex * 44 + directiveIndex * 28 + "px";
|
|
235
|
+
element.style.width = "320px";
|
|
236
|
+
element.style.height = "24px";
|
|
237
|
+
element.setAttribute("line", directive.line);
|
|
238
|
+
const designItem = DesignItem.createDesignItemFromInstance(element, serviceContainer, instanceServiceContainer);
|
|
239
|
+
designItems.push(designItem);
|
|
240
|
+
if (directive.sourceRange)
|
|
241
|
+
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, directive.sourceRange);
|
|
242
|
+
directiveIndex++;
|
|
243
|
+
}
|
|
244
|
+
return designItems;
|
|
245
|
+
}
|
|
246
|
+
function writeFlowchart(textWriter, designItems, updatePositions, rootDesignItem) {
|
|
247
|
+
const rootDirection = rootDesignItem?.getAttribute(mermaidFlowchartDirectionAttribute);
|
|
248
|
+
const direction = isFlowchartDirection(rootDirection) ? rootDirection : getDiagramDirection(designItems);
|
|
249
|
+
writeMermaidFrontmatter(textWriter, designItems, rootDesignItem);
|
|
250
|
+
textWriter.writeLine("flowchart " + direction);
|
|
251
|
+
const allFlowchartItems = getAllFlowchartItems(designItems);
|
|
252
|
+
const nodeIdsUsedByEdges = getFlowchartNodeIdsUsedByEdges(allFlowchartItems);
|
|
253
|
+
const nodeItemsById = getFlowchartNodeItemsById(allFlowchartItems);
|
|
254
|
+
const explicitlyWrittenNodeIds = new Set();
|
|
255
|
+
const writeNodeOrSubgraph = (designItem, depth) => {
|
|
256
|
+
const element = designItem.element;
|
|
257
|
+
if (element.nodeName === "MERMAID-SUBGRAPH") {
|
|
258
|
+
const subgraphElement = element;
|
|
259
|
+
writeDesignItemLine(textWriter, designItem, repeatText(" ", depth) + subgraphElement.createMermaidStart(), updatePositions);
|
|
260
|
+
const subgraphDirection = element.getAttribute("direction");
|
|
261
|
+
if (isFlowchartDirection(subgraphDirection))
|
|
262
|
+
textWriter.writeLine(repeatText(" ", depth + 1) + "direction " + subgraphDirection);
|
|
263
|
+
for (const child of designItem.children())
|
|
264
|
+
writeNodeOrSubgraph(child, depth + 1);
|
|
265
|
+
textWriter.writeLine(repeatText(" ", depth) + "end");
|
|
386
266
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
writeDesignItemLine(textWriter, designItem, " " + element.createMermaid(), updatePositions);
|
|
267
|
+
else if (element.nodeName === "MERMAID-NODE" && element.createMermaid && shouldWriteFlowchartNode(element, nodeIdsUsedByEdges)) {
|
|
268
|
+
writeDesignItemLine(textWriter, designItem, repeatText(" ", depth) + element.createMermaid(), updatePositions);
|
|
269
|
+
explicitlyWrittenNodeIds.add(element.getAttribute("node-id"));
|
|
391
270
|
}
|
|
271
|
+
};
|
|
272
|
+
for (const designItem of designItems) {
|
|
273
|
+
writeNodeOrSubgraph(designItem, 1);
|
|
274
|
+
}
|
|
275
|
+
for (const designItem of allFlowchartItems) {
|
|
276
|
+
const element = designItem.element;
|
|
277
|
+
if (element.nodeName === "MERMAID-EDGE" && element.createMermaid)
|
|
278
|
+
writeFlowchartEdgeLine(textWriter, designItem, element, nodeItemsById, explicitlyWrittenNodeIds, updatePositions);
|
|
279
|
+
}
|
|
280
|
+
for (const designItem of allFlowchartItems) {
|
|
281
|
+
const element = designItem.element;
|
|
282
|
+
if (element.nodeName === "MERMAID-FLOWCHART-DIRECTIVE" && element.createMermaid)
|
|
283
|
+
writeDesignItemLine(textWriter, designItem, " " + element.createMermaid(), updatePositions);
|
|
284
|
+
}
|
|
392
285
|
}
|
|
393
|
-
|
|
394
|
-
function writeFlowchartEdgeLine(textWriter: ITextWriter, designItem: IDesignItem, element: HTMLElement & { createMermaid?: () => string }, nodeItemsById: Map<string, IDesignItem>, explicitlyWrittenNodeIds: Set<string>, updatePositions?: boolean) {
|
|
286
|
+
function writeFlowchartEdgeLine(textWriter, designItem, element, nodeItemsById, explicitlyWrittenNodeIds, updatePositions) {
|
|
395
287
|
const start = textWriter.position;
|
|
396
288
|
const line = indentEmbeddedNewlines(" " + element.createMermaid());
|
|
397
289
|
textWriter.writeLine(line);
|
|
290
|
+
const directive = element.createMermaidDirective?.();
|
|
291
|
+
if (directive)
|
|
292
|
+
textWriter.writeLine(" " + directive);
|
|
398
293
|
if (!updatePositions)
|
|
399
294
|
return;
|
|
400
|
-
|
|
401
295
|
const from = element.getAttribute("from");
|
|
402
296
|
const to = element.getAttribute("to");
|
|
403
297
|
const fromIndex = from ? line.indexOf(from) : -1;
|
|
404
298
|
const toIndex = to ? line.lastIndexOf(to) : -1;
|
|
405
|
-
|
|
406
299
|
if (from && fromIndex >= 0 && !explicitlyWrittenNodeIds.has(from))
|
|
407
300
|
nodeItemsById.get(from)?.instanceServiceContainer.designItemDocumentPositionService?.setPosition(nodeItemsById.get(from), { start: start + fromIndex, length: from.length });
|
|
408
301
|
if (to && toIndex >= 0 && !explicitlyWrittenNodeIds.has(to))
|
|
409
302
|
nodeItemsById.get(to)?.instanceServiceContainer.designItemDocumentPositionService?.setPosition(nodeItemsById.get(to), { start: start + toIndex, length: to.length });
|
|
410
|
-
|
|
411
303
|
if (fromIndex >= 0 && toIndex > fromIndex) {
|
|
412
304
|
const connectorStart = fromIndex + from.length;
|
|
413
305
|
designItem.instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, { start: start + connectorStart, length: toIndex - connectorStart });
|
|
414
|
-
}
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
415
308
|
designItem.instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, { start, length: line.length });
|
|
416
309
|
}
|
|
417
310
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const ids = new Set<string>();
|
|
311
|
+
function getFlowchartNodeIdsUsedByEdges(designItems) {
|
|
312
|
+
const ids = new Set();
|
|
421
313
|
for (const designItem of designItems) {
|
|
422
|
-
const element = designItem.element
|
|
314
|
+
const element = designItem.element;
|
|
423
315
|
if (element.nodeName === "MERMAID-EDGE") {
|
|
424
316
|
const from = element.getAttribute("from");
|
|
425
317
|
const to = element.getAttribute("to");
|
|
@@ -431,11 +323,10 @@ function getFlowchartNodeIdsUsedByEdges(designItems: IDesignItem[]) {
|
|
|
431
323
|
}
|
|
432
324
|
return ids;
|
|
433
325
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const nodeItemsById = new Map<string, IDesignItem>();
|
|
326
|
+
function getFlowchartNodeItemsById(designItems) {
|
|
327
|
+
const nodeItemsById = new Map();
|
|
437
328
|
for (const designItem of designItems) {
|
|
438
|
-
const element = designItem.element
|
|
329
|
+
const element = designItem.element;
|
|
439
330
|
if (element.nodeName === "MERMAID-NODE") {
|
|
440
331
|
const id = element.getAttribute("node-id");
|
|
441
332
|
if (id)
|
|
@@ -444,10 +335,9 @@ function getFlowchartNodeItemsById(designItems: IDesignItem[]) {
|
|
|
444
335
|
}
|
|
445
336
|
return nodeItemsById;
|
|
446
337
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
const
|
|
450
|
-
const append = (item: IDesignItem) => {
|
|
338
|
+
function getAllFlowchartItems(designItems) {
|
|
339
|
+
const result = [];
|
|
340
|
+
const append = (item) => {
|
|
451
341
|
result.push(item);
|
|
452
342
|
for (const child of item.children())
|
|
453
343
|
append(child);
|
|
@@ -456,8 +346,7 @@ function getAllFlowchartItems(designItems: IDesignItem[]) {
|
|
|
456
346
|
append(designItem);
|
|
457
347
|
return result;
|
|
458
348
|
}
|
|
459
|
-
|
|
460
|
-
function shouldWriteFlowchartNode(element: HTMLElement, nodeIdsUsedByEdges: Set<string>) {
|
|
349
|
+
function shouldWriteFlowchartNode(element, nodeIdsUsedByEdges) {
|
|
461
350
|
const id = element.getAttribute("node-id");
|
|
462
351
|
const label = element.getAttribute("label");
|
|
463
352
|
const shape = element.getAttribute("shape") ?? "rectangle";
|
|
@@ -465,32 +354,27 @@ function shouldWriteFlowchartNode(element: HTMLElement, nodeIdsUsedByEdges: Set<
|
|
|
465
354
|
return true;
|
|
466
355
|
return shape !== "rectangle" || (label && label !== id);
|
|
467
356
|
}
|
|
468
|
-
|
|
469
|
-
async function parseSequenceDiagram(html: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer): Promise<IDesignItem[]> {
|
|
357
|
+
async function parseSequenceDiagram(html, serviceContainer, instanceServiceContainer) {
|
|
470
358
|
const document = readMermaidDocument(html);
|
|
471
359
|
setMermaidDocumentAttributes(instanceServiceContainer, "sequenceDiagram", undefined, document.title, document.frontmatter);
|
|
472
360
|
const lines = document.lines;
|
|
473
|
-
const participants = new Map
|
|
474
|
-
const messages
|
|
475
|
-
const scannedParticipants = new Map
|
|
476
|
-
const scannedMessages
|
|
477
|
-
|
|
361
|
+
const participants = new Map();
|
|
362
|
+
const messages = [];
|
|
363
|
+
const scannedParticipants = new Map();
|
|
364
|
+
const scannedMessages = [];
|
|
478
365
|
for (const line of lines) {
|
|
479
366
|
if (!line.trimmed || line.trimmed.startsWith("%%") || equalsIgnoreCase(line.trimmed, "sequenceDiagram"))
|
|
480
367
|
continue;
|
|
481
|
-
|
|
482
368
|
const participant = parseSequenceParticipant(line.trimmed, line.start);
|
|
483
369
|
if (participant) {
|
|
484
370
|
scannedParticipants.set(participant.id, participant);
|
|
485
371
|
continue;
|
|
486
372
|
}
|
|
487
|
-
|
|
488
373
|
const message = parseSequenceMessage(line.trimmed, line.start);
|
|
489
374
|
if (message) {
|
|
490
375
|
scannedMessages.push(message);
|
|
491
376
|
}
|
|
492
377
|
}
|
|
493
|
-
|
|
494
378
|
const parsed = await getMermaidSequenceData(html);
|
|
495
379
|
if (parsed) {
|
|
496
380
|
for (const participant of parsed.participants) {
|
|
@@ -507,19 +391,18 @@ async function parseSequenceDiagram(html: string, serviceContainer: ServiceConta
|
|
|
507
391
|
sourceRange: scannedMessages[i]?.sourceRange,
|
|
508
392
|
});
|
|
509
393
|
}
|
|
510
|
-
}
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
511
396
|
for (const participant of scannedParticipants.values())
|
|
512
397
|
participants.set(participant.id, participant);
|
|
513
398
|
messages.push(...scannedMessages);
|
|
514
399
|
}
|
|
515
|
-
|
|
516
400
|
for (const message of messages) {
|
|
517
401
|
ensureSequenceParticipant(participants, message.from);
|
|
518
402
|
ensureSequenceParticipant(participants, message.to);
|
|
519
403
|
}
|
|
520
|
-
|
|
521
|
-
const
|
|
522
|
-
const participantBounds = new Map<string, { x: number; y: number; width: number; height: number }>();
|
|
404
|
+
const designItems = [];
|
|
405
|
+
const participantBounds = new Map();
|
|
523
406
|
let index = 0;
|
|
524
407
|
for (const participant of participants.values()) {
|
|
525
408
|
const width = 140;
|
|
@@ -544,7 +427,6 @@ async function parseSequenceDiagram(html: string, serviceContainer: ServiceConta
|
|
|
544
427
|
participantBounds.set(participant.id, { x: left, y: top, width, height });
|
|
545
428
|
index++;
|
|
546
429
|
}
|
|
547
|
-
|
|
548
430
|
let messageIndex = 0;
|
|
549
431
|
for (const message of messages) {
|
|
550
432
|
const fromBounds = participantBounds.get(message.from);
|
|
@@ -571,50 +453,42 @@ async function parseSequenceDiagram(html: string, serviceContainer: ServiceConta
|
|
|
571
453
|
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, message.sourceRange);
|
|
572
454
|
messageIndex++;
|
|
573
455
|
}
|
|
574
|
-
|
|
575
456
|
return designItems;
|
|
576
457
|
}
|
|
577
|
-
|
|
578
|
-
function writeSequenceDiagram(textWriter: ITextWriter, designItems: IDesignItem[], updatePositions?: boolean, rootDesignItem?: IDesignItem) {
|
|
458
|
+
function writeSequenceDiagram(textWriter, designItems, updatePositions, rootDesignItem) {
|
|
579
459
|
writeMermaidFrontmatter(textWriter, designItems, rootDesignItem);
|
|
580
460
|
textWriter.writeLine("sequenceDiagram");
|
|
581
461
|
for (const designItem of designItems) {
|
|
582
|
-
const element = designItem.element
|
|
462
|
+
const element = designItem.element;
|
|
583
463
|
if (element.nodeName === "MERMAID-SEQUENCE-PARTICIPANT" && element.getAttribute("implicit") !== "true" && element.createMermaid)
|
|
584
464
|
writeDesignItemLine(textWriter, designItem, " " + element.createMermaid(), updatePositions);
|
|
585
465
|
}
|
|
586
466
|
for (const designItem of designItems) {
|
|
587
|
-
const element = designItem.element
|
|
467
|
+
const element = designItem.element;
|
|
588
468
|
if (element.nodeName === "MERMAID-SEQUENCE-MESSAGE" && element.createMermaid)
|
|
589
469
|
writeDesignItemLine(textWriter, designItem, " " + element.createMermaid(), updatePositions);
|
|
590
470
|
}
|
|
591
471
|
}
|
|
592
|
-
|
|
593
|
-
async function parseMindmapDiagram(html: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer): Promise<IDesignItem[]> {
|
|
472
|
+
async function parseMindmapDiagram(html, serviceContainer, instanceServiceContainer) {
|
|
594
473
|
const document = readMermaidDocument(html);
|
|
595
474
|
setMermaidDocumentAttributes(instanceServiceContainer, "mindmap", undefined, document.title, document.frontmatter);
|
|
596
|
-
|
|
597
|
-
const
|
|
598
|
-
const parentStack: ParsedMindmapNode[] = [];
|
|
475
|
+
const parsedNodes = [];
|
|
476
|
+
const parentStack = [];
|
|
599
477
|
let index = 0;
|
|
600
|
-
|
|
601
478
|
for (const line of document.lines) {
|
|
602
479
|
if (!line.trimmed || line.trimmed.startsWith("%%") || equalsIgnoreCase(line.trimmed, "mindmap"))
|
|
603
480
|
continue;
|
|
604
|
-
|
|
605
481
|
while (parentStack.length && parentStack[parentStack.length - 1].indent >= line.indent)
|
|
606
482
|
parentStack.pop();
|
|
607
|
-
|
|
608
483
|
const parent = parentStack[parentStack.length - 1];
|
|
609
484
|
const parsed = parseMindmapNode(line.trimmed, index, parent?.id ?? "", line.start, line.text.length, line.indent);
|
|
610
485
|
parsedNodes.push(parsed);
|
|
611
486
|
parentStack.push(parsed);
|
|
612
487
|
index++;
|
|
613
488
|
}
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
const
|
|
617
|
-
const rootDesignItems: IDesignItem[] = [];
|
|
489
|
+
const siblingsByParent = new Map();
|
|
490
|
+
const designItemsById = new Map();
|
|
491
|
+
const rootDesignItems = [];
|
|
618
492
|
const mermaidLayout = await getMermaidMindmapLayout(html, parsedNodes);
|
|
619
493
|
for (const node of parsedNodes) {
|
|
620
494
|
const siblingIndex = siblingsByParent.get(node.parentId) ?? 0;
|
|
@@ -637,22 +511,21 @@ async function parseMindmapDiagram(html: string, serviceContainer: ServiceContai
|
|
|
637
511
|
const parentItem = designItemsById.get(node.parentId);
|
|
638
512
|
if (parentItem) {
|
|
639
513
|
parentItem._insertChildInternal(designItem);
|
|
640
|
-
}
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
641
516
|
rootDesignItems.push(designItem);
|
|
642
517
|
}
|
|
643
518
|
if (node.sourceRange)
|
|
644
519
|
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, node.sourceRange);
|
|
645
520
|
}
|
|
646
|
-
|
|
647
521
|
return rootDesignItems;
|
|
648
522
|
}
|
|
649
|
-
|
|
650
|
-
function writeMindmapDiagram(textWriter: ITextWriter, designItems: IDesignItem[], updatePositions?: boolean, rootDesignItem?: IDesignItem) {
|
|
523
|
+
function writeMindmapDiagram(textWriter, designItems, updatePositions, rootDesignItem) {
|
|
651
524
|
writeMermaidFrontmatter(textWriter, designItems, rootDesignItem);
|
|
652
525
|
textWriter.writeLine("mindmap");
|
|
653
|
-
const writeItems = (items
|
|
526
|
+
const writeItems = (items, depth) => {
|
|
654
527
|
for (const item of sortMindmapItems(items)) {
|
|
655
|
-
const element = item.element
|
|
528
|
+
const element = item.element;
|
|
656
529
|
if (!element.createMermaid)
|
|
657
530
|
continue;
|
|
658
531
|
writeDesignItemLine(textWriter, item, repeatText(" ", depth + 1) + element.createMermaid(), updatePositions);
|
|
@@ -661,28 +534,24 @@ function writeMindmapDiagram(textWriter: ITextWriter, designItems: IDesignItem[]
|
|
|
661
534
|
};
|
|
662
535
|
writeItems(designItems.filter(designItem => designItem.element.localName === MermaidMindmapNode.is), 0);
|
|
663
536
|
}
|
|
664
|
-
|
|
665
|
-
async function parseRequirementDiagram(html: string, serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer): Promise<IDesignItem[]> {
|
|
537
|
+
async function parseRequirementDiagram(html, serviceContainer, instanceServiceContainer) {
|
|
666
538
|
const document = readMermaidDocument(html);
|
|
667
539
|
const lines = document.lines;
|
|
668
|
-
const nodes = new Map
|
|
669
|
-
const relationships
|
|
670
|
-
let direction
|
|
671
|
-
|
|
540
|
+
const nodes = new Map();
|
|
541
|
+
const relationships = [];
|
|
542
|
+
let direction = "TB";
|
|
672
543
|
for (let i = 0; i < lines.length; i++) {
|
|
673
544
|
const line = lines[i];
|
|
674
545
|
if (!line.trimmed || line.trimmed.startsWith("%%") || equalsIgnoreCase(line.trimmed, "requirementDiagram"))
|
|
675
546
|
continue;
|
|
676
|
-
|
|
677
547
|
const parsedDirection = parseDirectionStatement(line.trimmed);
|
|
678
548
|
if (parsedDirection) {
|
|
679
549
|
direction = parsedDirection;
|
|
680
550
|
continue;
|
|
681
551
|
}
|
|
682
|
-
|
|
683
552
|
const blockStart = parseRequirementBlockStart(line.trimmed);
|
|
684
553
|
if (blockStart) {
|
|
685
|
-
const blockLines
|
|
554
|
+
const blockLines = [];
|
|
686
555
|
const start = line.start;
|
|
687
556
|
while (++i < lines.length) {
|
|
688
557
|
if (lines[i].trimmed === "}")
|
|
@@ -694,16 +563,13 @@ async function parseRequirementDiagram(html: string, serviceContainer: ServiceCo
|
|
|
694
563
|
nodes.set(node.id, node);
|
|
695
564
|
continue;
|
|
696
565
|
}
|
|
697
|
-
|
|
698
566
|
const relationship = parseRequirementRelationship(line.trimmed, line.start);
|
|
699
567
|
if (relationship)
|
|
700
568
|
relationships.push(relationship);
|
|
701
569
|
}
|
|
702
|
-
|
|
703
570
|
setMermaidDocumentAttributes(instanceServiceContainer, "requirementDiagram", direction, document.title, document.frontmatter);
|
|
704
|
-
|
|
705
|
-
const
|
|
706
|
-
const nodeBounds = new Map<string, { x: number; y: number; width: number; height: number }>();
|
|
571
|
+
const designItems = [];
|
|
572
|
+
const nodeBounds = new Map();
|
|
707
573
|
const mermaidLayout = await getMermaidRequirementLayout(html, nodes);
|
|
708
574
|
let index = 0;
|
|
709
575
|
for (const node of nodes.values()) {
|
|
@@ -728,7 +594,8 @@ async function parseRequirementDiagram(html: string, serviceContainer: ServiceCo
|
|
|
728
594
|
element.setAttribute("text", node.text ?? "");
|
|
729
595
|
element.setAttribute("risk", node.risk ?? "");
|
|
730
596
|
element.setAttribute("verify-method", node.verifyMethod ?? "");
|
|
731
|
-
}
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
732
599
|
element.setAttribute("element-type", node.elementType ?? "");
|
|
733
600
|
element.setAttribute("doc-ref", node.docRef ?? "");
|
|
734
601
|
}
|
|
@@ -739,7 +606,6 @@ async function parseRequirementDiagram(html: string, serviceContainer: ServiceCo
|
|
|
739
606
|
nodeBounds.set(node.id, { x: left, y: top, width, height });
|
|
740
607
|
index++;
|
|
741
608
|
}
|
|
742
|
-
|
|
743
609
|
let relationshipIndex = 0;
|
|
744
610
|
for (const relationship of relationships) {
|
|
745
611
|
const element = new MermaidRequirementRelationship();
|
|
@@ -752,7 +618,8 @@ async function parseRequirementDiagram(html: string, serviceContainer: ServiceCo
|
|
|
752
618
|
const targetBounds = nodeBounds.get(relationship.to);
|
|
753
619
|
if (sourceBounds && targetBounds) {
|
|
754
620
|
element.setAttribute("waypoints", encodeWaypoints(routeBetweenBounds(sourceBounds, targetBounds, direction)));
|
|
755
|
-
}
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
756
623
|
element.style.left = "40px";
|
|
757
624
|
element.style.top = 80 + index * 120 + relationshipIndex * 40 + "px";
|
|
758
625
|
element.style.width = "220px";
|
|
@@ -764,11 +631,9 @@ async function parseRequirementDiagram(html: string, serviceContainer: ServiceCo
|
|
|
764
631
|
instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, relationship.sourceRange);
|
|
765
632
|
relationshipIndex++;
|
|
766
633
|
}
|
|
767
|
-
|
|
768
634
|
return designItems;
|
|
769
635
|
}
|
|
770
|
-
|
|
771
|
-
function writeRequirementDiagram(textWriter: ITextWriter, designItems: IDesignItem[], updatePositions?: boolean, rootDesignItem?: IDesignItem) {
|
|
636
|
+
function writeRequirementDiagram(textWriter, designItems, updatePositions, rootDesignItem) {
|
|
772
637
|
const rootDirection = rootDesignItem?.getAttribute(mermaidFlowchartDirectionAttribute);
|
|
773
638
|
const direction = isRequirementDirection(rootDirection) ? rootDirection : "TB";
|
|
774
639
|
writeMermaidFrontmatter(textWriter, designItems, rootDesignItem);
|
|
@@ -776,18 +641,17 @@ function writeRequirementDiagram(textWriter: ITextWriter, designItems: IDesignIt
|
|
|
776
641
|
if (direction !== "TB")
|
|
777
642
|
textWriter.writeLine(" direction " + direction);
|
|
778
643
|
for (const designItem of designItems) {
|
|
779
|
-
const element = designItem.element
|
|
644
|
+
const element = designItem.element;
|
|
780
645
|
if (element.nodeName === "MERMAID-REQUIREMENT-NODE" && element.createMermaid)
|
|
781
646
|
writeDesignItemLine(textWriter, designItem, " " + element.createMermaid(), updatePositions);
|
|
782
647
|
}
|
|
783
648
|
for (const designItem of designItems) {
|
|
784
|
-
const element = designItem.element
|
|
649
|
+
const element = designItem.element;
|
|
785
650
|
if (element.nodeName === "MERMAID-REQUIREMENT-RELATIONSHIP" && element.createMermaid)
|
|
786
651
|
writeDesignItemLine(textWriter, designItem, " " + element.createMermaid(), updatePositions);
|
|
787
652
|
}
|
|
788
653
|
}
|
|
789
|
-
|
|
790
|
-
function parseSequenceParticipant(line: string, sourceStart: number): ParsedSequenceParticipant {
|
|
654
|
+
function parseSequenceParticipant(line, sourceStart) {
|
|
791
655
|
const cursor = new SourceCursor(line);
|
|
792
656
|
const keyword = cursor.readIdentifier();
|
|
793
657
|
if (!equalsIgnoreCase(keyword, "participant") && !equalsIgnoreCase(keyword, "actor"))
|
|
@@ -797,7 +661,6 @@ function parseSequenceParticipant(line: string, sourceStart: number): ParsedSequ
|
|
|
797
661
|
const id = cursor.readIdentifier();
|
|
798
662
|
if (!id)
|
|
799
663
|
return null;
|
|
800
|
-
|
|
801
664
|
let label = id;
|
|
802
665
|
cursor.skipWhitespace();
|
|
803
666
|
if (!cursor.atEnd()) {
|
|
@@ -808,7 +671,6 @@ function parseSequenceParticipant(line: string, sourceStart: number): ParsedSequ
|
|
|
808
671
|
return null;
|
|
809
672
|
label = cursor.readRest().trim();
|
|
810
673
|
}
|
|
811
|
-
|
|
812
674
|
return {
|
|
813
675
|
id,
|
|
814
676
|
label: unquoteLabel(label),
|
|
@@ -816,8 +678,7 @@ function parseSequenceParticipant(line: string, sourceStart: number): ParsedSequ
|
|
|
816
678
|
sourceRange: { start: sourceStart, length: line.length },
|
|
817
679
|
};
|
|
818
680
|
}
|
|
819
|
-
|
|
820
|
-
function parseSequenceMessage(line: string, sourceStart: number): ParsedSequenceMessage {
|
|
681
|
+
function parseSequenceMessage(line, sourceStart) {
|
|
821
682
|
const parsed = parseBinaryStatement(line, ["-->>", "->>", "-->", "->", "--x", "-x", "--)", "-)"]);
|
|
822
683
|
if (!parsed)
|
|
823
684
|
return null;
|
|
@@ -828,7 +689,6 @@ function parseSequenceMessage(line: string, sourceStart: number): ParsedSequence
|
|
|
828
689
|
const label = parsed.right.substring(separatorIndex + 1).trim();
|
|
829
690
|
if (!to || !isIdentifier(to))
|
|
830
691
|
return null;
|
|
831
|
-
|
|
832
692
|
return {
|
|
833
693
|
from: parsed.left,
|
|
834
694
|
to,
|
|
@@ -838,13 +698,11 @@ function parseSequenceMessage(line: string, sourceStart: number): ParsedSequence
|
|
|
838
698
|
sourceRange: { start: sourceStart, length: line.length },
|
|
839
699
|
};
|
|
840
700
|
}
|
|
841
|
-
|
|
842
|
-
function ensureSequenceParticipant(participants: Map<string, ParsedSequenceParticipant>, id: string) {
|
|
701
|
+
function ensureSequenceParticipant(participants, id) {
|
|
843
702
|
if (!participants.has(id))
|
|
844
703
|
participants.set(id, { id, label: id, participantType: "participant", implicit: true });
|
|
845
704
|
}
|
|
846
|
-
|
|
847
|
-
function getSequenceMessageType(connector: string) {
|
|
705
|
+
function getSequenceMessageType(connector) {
|
|
848
706
|
if (connector.includes(")"))
|
|
849
707
|
return "async";
|
|
850
708
|
if (connector.includes("--"))
|
|
@@ -855,28 +713,24 @@ function getSequenceMessageType(connector: string) {
|
|
|
855
713
|
return "open";
|
|
856
714
|
return "solid";
|
|
857
715
|
}
|
|
858
|
-
|
|
859
716
|
class SourceCursor {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
constructor(
|
|
717
|
+
text;
|
|
718
|
+
position = 0;
|
|
719
|
+
constructor(text) {
|
|
720
|
+
this.text = text;
|
|
863
721
|
}
|
|
864
|
-
|
|
865
722
|
atEnd() {
|
|
866
723
|
return this.position >= this.text.length;
|
|
867
724
|
}
|
|
868
|
-
|
|
869
725
|
skipWhitespace() {
|
|
870
726
|
while (!this.atEnd() && isWhitespace(this.text[this.position]))
|
|
871
727
|
this.position++;
|
|
872
728
|
}
|
|
873
|
-
|
|
874
729
|
skipRequiredWhitespace() {
|
|
875
730
|
const start = this.position;
|
|
876
731
|
this.skipWhitespace();
|
|
877
732
|
return this.position > start;
|
|
878
733
|
}
|
|
879
|
-
|
|
880
734
|
readIdentifier() {
|
|
881
735
|
if (this.atEnd() || !isIdentifierStart(this.text[this.position]))
|
|
882
736
|
return "";
|
|
@@ -886,22 +740,19 @@ class SourceCursor {
|
|
|
886
740
|
this.position++;
|
|
887
741
|
return this.text.substring(start, this.position);
|
|
888
742
|
}
|
|
889
|
-
|
|
890
743
|
readRest() {
|
|
891
744
|
const rest = this.text.substring(this.position);
|
|
892
745
|
this.position = this.text.length;
|
|
893
746
|
return rest;
|
|
894
747
|
}
|
|
895
|
-
|
|
896
|
-
consume(value: string) {
|
|
748
|
+
consume(value) {
|
|
897
749
|
if (!this.text.startsWith(value, this.position))
|
|
898
750
|
return false;
|
|
899
751
|
this.position += value.length;
|
|
900
752
|
return true;
|
|
901
753
|
}
|
|
902
754
|
}
|
|
903
|
-
|
|
904
|
-
function parseFlowchartDirection(line: string): FlowchartDirection | null {
|
|
755
|
+
function parseFlowchartDirection(line) {
|
|
905
756
|
const cursor = new SourceCursor(line);
|
|
906
757
|
const keyword = cursor.readIdentifier();
|
|
907
758
|
if (!equalsIgnoreCase(keyword, "graph") && !equalsIgnoreCase(keyword, "flowchart"))
|
|
@@ -911,8 +762,7 @@ function parseFlowchartDirection(line: string): FlowchartDirection | null {
|
|
|
911
762
|
const direction = cursor.readIdentifier().toUpperCase();
|
|
912
763
|
return isFlowchartDirection(direction) ? direction : null;
|
|
913
764
|
}
|
|
914
|
-
|
|
915
|
-
function parseDirectionStatement(line: string): FlowchartDirection | null {
|
|
765
|
+
function parseDirectionStatement(line) {
|
|
916
766
|
const cursor = new SourceCursor(line);
|
|
917
767
|
const keyword = cursor.readIdentifier();
|
|
918
768
|
if (!equalsIgnoreCase(keyword, "direction"))
|
|
@@ -922,8 +772,7 @@ function parseDirectionStatement(line: string): FlowchartDirection | null {
|
|
|
922
772
|
const direction = cursor.readIdentifier().toUpperCase();
|
|
923
773
|
return isRequirementDirection(direction) ? direction : null;
|
|
924
774
|
}
|
|
925
|
-
|
|
926
|
-
function parseSubgraphStart(line: string, sourceStart: number, parentId?: string): ParsedSubgraph | null {
|
|
775
|
+
function parseSubgraphStart(line, sourceStart, parentId) {
|
|
927
776
|
const cursor = new SourceCursor(line);
|
|
928
777
|
const keyword = cursor.readIdentifier();
|
|
929
778
|
if (!equalsIgnoreCase(keyword, "subgraph"))
|
|
@@ -943,8 +792,7 @@ function parseSubgraphStart(line: string, sourceStart: number, parentId?: string
|
|
|
943
792
|
const title = unquoteLabel(rest);
|
|
944
793
|
return { id: sanitizeDirectiveId(title), title, parentId, sourceRange: { start: sourceStart, length: line.length } };
|
|
945
794
|
}
|
|
946
|
-
|
|
947
|
-
function parseFlowchartDirective(line: string, sourceStart: number): ParsedFlowchartDirective | null {
|
|
795
|
+
function parseFlowchartDirective(line, sourceStart) {
|
|
948
796
|
const cursor = new SourceCursor(line);
|
|
949
797
|
const keyword = cursor.readIdentifier();
|
|
950
798
|
if (!keyword)
|
|
@@ -955,17 +803,30 @@ function parseFlowchartDirective(line: string, sourceStart: number): ParsedFlowc
|
|
|
955
803
|
return null;
|
|
956
804
|
return null;
|
|
957
805
|
}
|
|
958
|
-
|
|
959
|
-
|
|
806
|
+
function parseFlowchartEdgeDirective(line, sourceStart) {
|
|
807
|
+
const cursor = new SourceCursor(line);
|
|
808
|
+
const edgeId = cursor.readIdentifier();
|
|
809
|
+
if (!edgeId)
|
|
810
|
+
return null;
|
|
811
|
+
cursor.skipWhitespace();
|
|
812
|
+
if (!cursor.consume("@{"))
|
|
813
|
+
return null;
|
|
814
|
+
const contentEnd = line.lastIndexOf("}");
|
|
815
|
+
const content = contentEnd >= 0 ? line.substring(cursor.position, contentEnd) : line.substring(cursor.position);
|
|
816
|
+
const properties = parseObjectLiteralProperties(content);
|
|
817
|
+
const animation = properties.get("animation") ?? (properties.get("animate") === "true" ? "fast" : "");
|
|
818
|
+
if (!animation)
|
|
819
|
+
return null;
|
|
820
|
+
return { edgeId, animation, sourceRange: { start: sourceStart, length: line.length } };
|
|
821
|
+
}
|
|
822
|
+
function parseBinaryStatement(line, operators) {
|
|
960
823
|
const parsed = findOperator(line, operators);
|
|
961
824
|
if (!parsed)
|
|
962
825
|
return null;
|
|
963
|
-
|
|
964
826
|
const leftRange = trimRange(line, 0, parsed.index);
|
|
965
827
|
const rightRange = trimRange(line, parsed.index + parsed.operator.length, line.length);
|
|
966
828
|
if (leftRange.start >= leftRange.end || rightRange.start >= rightRange.end)
|
|
967
829
|
return null;
|
|
968
|
-
|
|
969
830
|
return {
|
|
970
831
|
left: line.substring(leftRange.start, leftRange.end),
|
|
971
832
|
leftStart: leftRange.start,
|
|
@@ -975,8 +836,7 @@ function parseBinaryStatement(line: string, operators: string[]) {
|
|
|
975
836
|
rightStart: rightRange.start,
|
|
976
837
|
};
|
|
977
838
|
}
|
|
978
|
-
|
|
979
|
-
function parseRequirementBlockStart(line: string): { kind: "requirement" | "element"; type: string; id: string } | null {
|
|
839
|
+
function parseRequirementBlockStart(line) {
|
|
980
840
|
const cursor = new SourceCursor(line);
|
|
981
841
|
const type = cursor.readIdentifier();
|
|
982
842
|
if (!type)
|
|
@@ -998,9 +858,8 @@ function parseRequirementBlockStart(line: string): { kind: "requirement" | "elem
|
|
|
998
858
|
return null;
|
|
999
859
|
return { kind, type, id };
|
|
1000
860
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
const values = new Map<string, string>();
|
|
861
|
+
function parseRequirementBlock(blockStart, lines, sourceStart, sourceLength) {
|
|
862
|
+
const values = new Map();
|
|
1004
863
|
for (const line of lines) {
|
|
1005
864
|
const separator = findTopLevelColon(line.trimmed);
|
|
1006
865
|
if (separator < 0)
|
|
@@ -1009,7 +868,6 @@ function parseRequirementBlock(blockStart: { kind: "requirement" | "element"; ty
|
|
|
1009
868
|
const value = unquoteLabel(line.trimmed.substring(separator + 1).trim());
|
|
1010
869
|
values.set(key, value);
|
|
1011
870
|
}
|
|
1012
|
-
|
|
1013
871
|
if (blockStart.kind === "element") {
|
|
1014
872
|
return {
|
|
1015
873
|
id: blockStart.id,
|
|
@@ -1019,7 +877,6 @@ function parseRequirementBlock(blockStart: { kind: "requirement" | "element"; ty
|
|
|
1019
877
|
sourceRange: { start: sourceStart, length: sourceLength },
|
|
1020
878
|
};
|
|
1021
879
|
}
|
|
1022
|
-
|
|
1023
880
|
return {
|
|
1024
881
|
id: blockStart.id,
|
|
1025
882
|
kind: "requirement",
|
|
@@ -1031,15 +888,13 @@ function parseRequirementBlock(blockStart: { kind: "requirement" | "element"; ty
|
|
|
1031
888
|
sourceRange: { start: sourceStart, length: sourceLength },
|
|
1032
889
|
};
|
|
1033
890
|
}
|
|
1034
|
-
|
|
1035
|
-
function parseRequirementRelationship(line: string, sourceStart: number): ParsedRequirementRelationship | null {
|
|
891
|
+
function parseRequirementRelationship(line, sourceStart) {
|
|
1036
892
|
const forward = parseRequirementRelationshipForward(line, sourceStart);
|
|
1037
893
|
if (forward)
|
|
1038
894
|
return forward;
|
|
1039
895
|
return parseRequirementRelationshipReverse(line, sourceStart);
|
|
1040
896
|
}
|
|
1041
|
-
|
|
1042
|
-
function parseRequirementRelationshipForward(line: string, sourceStart: number): ParsedRequirementRelationship | null {
|
|
897
|
+
function parseRequirementRelationshipForward(line, sourceStart) {
|
|
1043
898
|
const cursor = new SourceCursor(line);
|
|
1044
899
|
const from = cursor.readIdentifier();
|
|
1045
900
|
if (!from)
|
|
@@ -1060,8 +915,7 @@ function parseRequirementRelationshipForward(line: string, sourceStart: number):
|
|
|
1060
915
|
return null;
|
|
1061
916
|
return { from, to, relationshipType, syntaxDirection: "forward", sourceRange: { start: sourceStart, length: line.length } };
|
|
1062
917
|
}
|
|
1063
|
-
|
|
1064
|
-
function parseRequirementRelationshipReverse(line: string, sourceStart: number): ParsedRequirementRelationship | null {
|
|
918
|
+
function parseRequirementRelationshipReverse(line, sourceStart) {
|
|
1065
919
|
const cursor = new SourceCursor(line);
|
|
1066
920
|
const to = cursor.readIdentifier();
|
|
1067
921
|
if (!to)
|
|
@@ -1082,12 +936,10 @@ function parseRequirementRelationshipReverse(line: string, sourceStart: number):
|
|
|
1082
936
|
return null;
|
|
1083
937
|
return { from, to, relationshipType, syntaxDirection: "reverse", sourceRange: { start: sourceStart, length: line.length } };
|
|
1084
938
|
}
|
|
1085
|
-
|
|
1086
|
-
function parseFlowchartEdgeStatement(line: string) {
|
|
939
|
+
function parseFlowchartEdgeStatement(line) {
|
|
1087
940
|
const parsed = parseBinaryStatement(line, getFlowchartOperators());
|
|
1088
941
|
if (!parsed)
|
|
1089
942
|
return null;
|
|
1090
|
-
|
|
1091
943
|
let left = parsed.left;
|
|
1092
944
|
let leftStart = parsed.leftStart;
|
|
1093
945
|
let edgeId = "";
|
|
@@ -1104,7 +956,6 @@ function parseFlowchartEdgeStatement(line: string) {
|
|
|
1104
956
|
}
|
|
1105
957
|
}
|
|
1106
958
|
}
|
|
1107
|
-
|
|
1108
959
|
let label = "";
|
|
1109
960
|
let labelPartLength = 0;
|
|
1110
961
|
const right = parsed.right;
|
|
@@ -1128,10 +979,8 @@ function parseFlowchartEdgeStatement(line: string) {
|
|
|
1128
979
|
};
|
|
1129
980
|
}
|
|
1130
981
|
}
|
|
1131
|
-
|
|
1132
982
|
return { ...parsed, left, leftStart, label, labelPartLength, edgeId };
|
|
1133
983
|
}
|
|
1134
|
-
|
|
1135
984
|
function getFlowchartOperators() {
|
|
1136
985
|
return [
|
|
1137
986
|
"<-->", "<==>", "<-.->",
|
|
@@ -1142,8 +991,7 @@ function getFlowchartOperators() {
|
|
|
1142
991
|
"---->", "--->", "-->", "-----", "----", "---",
|
|
1143
992
|
];
|
|
1144
993
|
}
|
|
1145
|
-
|
|
1146
|
-
function parseExpandedShape(value: string): { shape: string; label?: string } | null {
|
|
994
|
+
function parseExpandedShape(value) {
|
|
1147
995
|
const cursor = new SourceCursor(value);
|
|
1148
996
|
if (!cursor.consume("@{"))
|
|
1149
997
|
return null;
|
|
@@ -1155,9 +1003,8 @@ function parseExpandedShape(value: string): { shape: string; label?: string } |
|
|
|
1155
1003
|
return null;
|
|
1156
1004
|
return { shape, label: properties.get("label") };
|
|
1157
1005
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
const candidates: Array<{ start: string; end: string; shape: string }> = [
|
|
1006
|
+
function parseDelimitedShapeValue(value) {
|
|
1007
|
+
const candidates = [
|
|
1161
1008
|
{ start: "(((", end: ")))", shape: "doubleCircle" },
|
|
1162
1009
|
{ start: "((", end: "))", shape: "circle" },
|
|
1163
1010
|
{ start: "([", end: "])", shape: "stadium" },
|
|
@@ -1173,7 +1020,6 @@ function parseDelimitedShapeValue(value: string): { label: string; shape: string
|
|
|
1173
1020
|
{ start: "[\\", end: "/]", shape: "trapezoidAlt" },
|
|
1174
1021
|
{ start: "[", end: "]", shape: "rectangle" },
|
|
1175
1022
|
];
|
|
1176
|
-
|
|
1177
1023
|
for (const candidate of candidates) {
|
|
1178
1024
|
if (value.startsWith(candidate.start) && value.endsWith(candidate.end)) {
|
|
1179
1025
|
return {
|
|
@@ -1182,12 +1028,10 @@ function parseDelimitedShapeValue(value: string): { label: string; shape: string
|
|
|
1182
1028
|
};
|
|
1183
1029
|
}
|
|
1184
1030
|
}
|
|
1185
|
-
|
|
1186
1031
|
return null;
|
|
1187
1032
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
const properties = new Map<string, string>();
|
|
1033
|
+
function parseObjectLiteralProperties(content) {
|
|
1034
|
+
const properties = new Map();
|
|
1191
1035
|
let start = 0;
|
|
1192
1036
|
let quote = "";
|
|
1193
1037
|
for (let i = 0; i <= content.length; i++) {
|
|
@@ -1214,8 +1058,7 @@ function parseObjectLiteralProperties(content: string) {
|
|
|
1214
1058
|
}
|
|
1215
1059
|
return properties;
|
|
1216
1060
|
}
|
|
1217
|
-
|
|
1218
|
-
function findOperator(line: string, operators: string[]) {
|
|
1061
|
+
function findOperator(line, operators) {
|
|
1219
1062
|
let depth = 0;
|
|
1220
1063
|
let quote = "";
|
|
1221
1064
|
for (let i = 0; i < line.length; i++) {
|
|
@@ -1242,128 +1085,113 @@ function findOperator(line: string, operators: string[]) {
|
|
|
1242
1085
|
}
|
|
1243
1086
|
return null;
|
|
1244
1087
|
}
|
|
1245
|
-
|
|
1246
|
-
function trimRange(text: string, start: number, end: number) {
|
|
1088
|
+
function trimRange(text, start, end) {
|
|
1247
1089
|
while (start < end && isWhitespace(text[start]))
|
|
1248
1090
|
start++;
|
|
1249
1091
|
while (end > start && isWhitespace(text[end - 1]))
|
|
1250
1092
|
end--;
|
|
1251
1093
|
return { start, end };
|
|
1252
1094
|
}
|
|
1253
|
-
|
|
1254
|
-
function countLeadingWhitespace(text: string) {
|
|
1095
|
+
function countLeadingWhitespace(text) {
|
|
1255
1096
|
let count = 0;
|
|
1256
1097
|
while (count < text.length && isWhitespace(text[count]))
|
|
1257
1098
|
count++;
|
|
1258
1099
|
return count;
|
|
1259
1100
|
}
|
|
1260
|
-
|
|
1261
|
-
function equalsIgnoreCase(a: string, b: string) {
|
|
1101
|
+
function equalsIgnoreCase(a, b) {
|
|
1262
1102
|
return a.toLowerCase() === b.toLowerCase();
|
|
1263
1103
|
}
|
|
1264
|
-
|
|
1265
|
-
function isIdentifier(value: string) {
|
|
1104
|
+
function isIdentifier(value) {
|
|
1266
1105
|
const cursor = new SourceCursor(value);
|
|
1267
1106
|
const id = cursor.readIdentifier();
|
|
1268
1107
|
cursor.skipWhitespace();
|
|
1269
1108
|
return id.length === value.length || (id.length > 0 && cursor.atEnd());
|
|
1270
1109
|
}
|
|
1271
|
-
|
|
1272
|
-
function isIdentifierStart(char: string) {
|
|
1110
|
+
function isIdentifierStart(char) {
|
|
1273
1111
|
return isAsciiLetter(char) || char === "_";
|
|
1274
1112
|
}
|
|
1275
|
-
|
|
1276
|
-
function isIdentifierPart(char: string) {
|
|
1113
|
+
function isIdentifierPart(char) {
|
|
1277
1114
|
return isIdentifierStart(char) || isAsciiDigit(char) || char === "-";
|
|
1278
1115
|
}
|
|
1279
|
-
|
|
1280
|
-
function isAsciiLetter(char: string) {
|
|
1116
|
+
function isAsciiLetter(char) {
|
|
1281
1117
|
if (!char)
|
|
1282
1118
|
return false;
|
|
1283
1119
|
const code = char.charCodeAt(0);
|
|
1284
1120
|
return (code >= 65 && code <= 90) || (code >= 97 && code <= 122);
|
|
1285
1121
|
}
|
|
1286
|
-
|
|
1287
|
-
function isAsciiDigit(char: string) {
|
|
1122
|
+
function isAsciiDigit(char) {
|
|
1288
1123
|
if (!char)
|
|
1289
1124
|
return false;
|
|
1290
1125
|
const code = char.charCodeAt(0);
|
|
1291
1126
|
return code >= 48 && code <= 57;
|
|
1292
1127
|
}
|
|
1293
|
-
|
|
1294
|
-
function isWhitespace(char: string) {
|
|
1128
|
+
function isWhitespace(char) {
|
|
1295
1129
|
return char === " " || char === "\t" || char === "\r" || char === "\n";
|
|
1296
1130
|
}
|
|
1297
|
-
|
|
1298
|
-
async function getMermaidFlowchartData(code: string): Promise<{ nodes: ParsedNode[]; edges: ParsedEdge[] } | null> {
|
|
1131
|
+
async function getMermaidFlowchartData(code) {
|
|
1299
1132
|
try {
|
|
1300
1133
|
const mermaid = await import("mermaid");
|
|
1301
1134
|
mermaid.default.initialize({ startOnLoad: false, securityLevel: "loose" });
|
|
1302
1135
|
const diagram = await mermaid.default.mermaidAPI.getDiagramFromText(code);
|
|
1303
|
-
const db = diagram.db
|
|
1136
|
+
const db = diagram.db;
|
|
1304
1137
|
const vertices = db?.getVertices?.();
|
|
1305
1138
|
const mermaidEdges = db?.getEdges?.();
|
|
1306
1139
|
if (!vertices || !mermaidEdges)
|
|
1307
1140
|
return null;
|
|
1308
|
-
|
|
1309
|
-
const nodes: ParsedNode[] = Array.from(vertices.values()).map((vertex: any) => ({
|
|
1141
|
+
const nodes = Array.from(vertices.values()).map((vertex) => ({
|
|
1310
1142
|
id: vertex.id,
|
|
1311
1143
|
label: normalizeMermaidText(vertex.text ?? vertex.label ?? vertex.id),
|
|
1312
1144
|
shape: mapMermaidVertexType(vertex.type),
|
|
1313
1145
|
}));
|
|
1314
|
-
const edges
|
|
1146
|
+
const edges = mermaidEdges.map((edge) => ({
|
|
1315
1147
|
from: edge.start,
|
|
1316
1148
|
to: edge.end,
|
|
1317
1149
|
label: normalizeMermaidText(edge.text ?? ""),
|
|
1318
1150
|
edgeType: mapMermaidEdgeType(edge),
|
|
1319
1151
|
}));
|
|
1320
|
-
|
|
1321
1152
|
return { nodes, edges };
|
|
1322
|
-
}
|
|
1153
|
+
}
|
|
1154
|
+
catch {
|
|
1323
1155
|
return null;
|
|
1324
1156
|
}
|
|
1325
1157
|
}
|
|
1326
|
-
|
|
1327
|
-
async function getMermaidSequenceData(code: string): Promise<{ participants: ParsedSequenceParticipant[]; messages: ParsedSequenceMessage[] } | null> {
|
|
1158
|
+
async function getMermaidSequenceData(code) {
|
|
1328
1159
|
try {
|
|
1329
1160
|
const mermaid = await import("mermaid");
|
|
1330
1161
|
mermaid.default.initialize({ startOnLoad: false, securityLevel: "loose" });
|
|
1331
1162
|
const diagram = await mermaid.default.mermaidAPI.getDiagramFromText(code);
|
|
1332
|
-
const db = diagram.db
|
|
1163
|
+
const db = diagram.db;
|
|
1333
1164
|
const actors = db?.getActors?.();
|
|
1334
1165
|
const mermaidMessages = db?.getMessages?.();
|
|
1335
1166
|
if (!actors || !mermaidMessages)
|
|
1336
1167
|
return null;
|
|
1337
|
-
|
|
1338
|
-
const participants: ParsedSequenceParticipant[] = Array.from(actors.entries()).map(([id, actor]: [string, any]) => ({
|
|
1168
|
+
const participants = Array.from(actors.entries()).map(([id, actor]) => ({
|
|
1339
1169
|
id,
|
|
1340
1170
|
label: actor.description ?? actor.name ?? id,
|
|
1341
1171
|
participantType: actor.type ?? "participant",
|
|
1342
1172
|
}));
|
|
1343
|
-
const messages
|
|
1344
|
-
.filter((message
|
|
1345
|
-
.map((message
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1173
|
+
const messages = mermaidMessages
|
|
1174
|
+
.filter((message) => typeof message.from === "string" && typeof message.to === "string")
|
|
1175
|
+
.map((message) => {
|
|
1176
|
+
const connector = mapMermaidSequenceConnector(message.type);
|
|
1177
|
+
return {
|
|
1178
|
+
from: message.from,
|
|
1179
|
+
to: message.to,
|
|
1180
|
+
label: message.message ?? "",
|
|
1181
|
+
messageType: getSequenceMessageType(connector),
|
|
1182
|
+
connector,
|
|
1183
|
+
};
|
|
1184
|
+
});
|
|
1356
1185
|
return { participants, messages };
|
|
1357
|
-
}
|
|
1186
|
+
}
|
|
1187
|
+
catch {
|
|
1358
1188
|
return null;
|
|
1359
1189
|
}
|
|
1360
1190
|
}
|
|
1361
|
-
|
|
1362
|
-
function getScannedEdge(scannedEdges: ParsedEdge[], edge: ParsedEdge): Partial<ParsedEdge> {
|
|
1191
|
+
function getScannedEdge(scannedEdges, edge) {
|
|
1363
1192
|
return scannedEdges.find(scannedEdge => scannedEdge.from === edge.from && scannedEdge.to === edge.to && scannedEdge.label === edge.label) ?? {};
|
|
1364
1193
|
}
|
|
1365
|
-
|
|
1366
|
-
function mapMermaidVertexType(type: string) {
|
|
1194
|
+
function mapMermaidVertexType(type) {
|
|
1367
1195
|
const expanded = mapExpandedShape(type);
|
|
1368
1196
|
if (expanded !== "rectangle")
|
|
1369
1197
|
return expanded;
|
|
@@ -1398,8 +1226,7 @@ function mapMermaidVertexType(type: string) {
|
|
|
1398
1226
|
return "rectangle";
|
|
1399
1227
|
}
|
|
1400
1228
|
}
|
|
1401
|
-
|
|
1402
|
-
function mapMermaidEdgeType(edge: any) {
|
|
1229
|
+
function mapMermaidEdgeType(edge) {
|
|
1403
1230
|
if (edge.stroke === "dotted")
|
|
1404
1231
|
return "dotted";
|
|
1405
1232
|
if (edge.stroke === "thick")
|
|
@@ -1408,8 +1235,7 @@ function mapMermaidEdgeType(edge: any) {
|
|
|
1408
1235
|
return "open";
|
|
1409
1236
|
return "arrow";
|
|
1410
1237
|
}
|
|
1411
|
-
|
|
1412
|
-
function mapMermaidSequenceConnector(type: number) {
|
|
1238
|
+
function mapMermaidSequenceConnector(type) {
|
|
1413
1239
|
switch (type) {
|
|
1414
1240
|
case 1:
|
|
1415
1241
|
return "-->>";
|
|
@@ -1429,8 +1255,7 @@ function mapMermaidSequenceConnector(type: number) {
|
|
|
1429
1255
|
return "->>";
|
|
1430
1256
|
}
|
|
1431
1257
|
}
|
|
1432
|
-
|
|
1433
|
-
function normalizeMermaidText(value: any) {
|
|
1258
|
+
function normalizeMermaidText(value) {
|
|
1434
1259
|
if (value == null)
|
|
1435
1260
|
return "";
|
|
1436
1261
|
if (typeof value === "string")
|
|
@@ -1447,39 +1272,33 @@ function normalizeMermaidText(value: any) {
|
|
|
1447
1272
|
}
|
|
1448
1273
|
return stripMarkdownString(value.toString());
|
|
1449
1274
|
}
|
|
1450
|
-
|
|
1451
|
-
function stripMarkdownString(value: string) {
|
|
1275
|
+
function stripMarkdownString(value) {
|
|
1452
1276
|
let result = value;
|
|
1453
1277
|
if (result.startsWith("`") && result.endsWith("`") && result.length >= 2)
|
|
1454
1278
|
result = result.substring(1, result.length - 1);
|
|
1455
1279
|
return normalizeLabelLineBreaks(result);
|
|
1456
1280
|
}
|
|
1457
|
-
|
|
1458
|
-
function mergeNode(nodes: Map<string, ParsedNode>, node: ParsedNode) {
|
|
1281
|
+
function mergeNode(nodes, node) {
|
|
1459
1282
|
const existing = nodes.get(node.id);
|
|
1460
1283
|
if (!existing || existing.label === existing.id || node.label !== node.id)
|
|
1461
1284
|
nodes.set(node.id, node);
|
|
1462
1285
|
}
|
|
1463
|
-
|
|
1464
|
-
function parseNode(line: string, sourceStart?: number): ParsedNode {
|
|
1286
|
+
function parseNode(line, sourceStart) {
|
|
1465
1287
|
const cursor = new SourceCursor(line);
|
|
1466
1288
|
const id = cursor.readIdentifier();
|
|
1467
1289
|
if (!id)
|
|
1468
1290
|
return null;
|
|
1469
|
-
|
|
1470
1291
|
cursor.skipWhitespace();
|
|
1471
1292
|
const value = cursor.readRest().trim();
|
|
1472
1293
|
const parsedShape = parseShapeValue(id, value);
|
|
1473
1294
|
if (!parsedShape)
|
|
1474
1295
|
return null;
|
|
1475
|
-
|
|
1476
1296
|
return {
|
|
1477
1297
|
...parsedShape,
|
|
1478
1298
|
sourceRange: sourceStart == null ? undefined : { start: sourceStart, length: line.length },
|
|
1479
1299
|
};
|
|
1480
1300
|
}
|
|
1481
|
-
|
|
1482
|
-
function parseMindmapNode(line: string, index: number, parentId: string, sourceStart: number, sourceLength: number, indent: number): ParsedMindmapNode {
|
|
1301
|
+
function parseMindmapNode(line, index, parentId, sourceStart, sourceLength, indent) {
|
|
1483
1302
|
const parsedNode = parseNode(line);
|
|
1484
1303
|
if (parsedNode) {
|
|
1485
1304
|
return {
|
|
@@ -1491,7 +1310,6 @@ function parseMindmapNode(line: string, index: number, parentId: string, sourceS
|
|
|
1491
1310
|
sourceRange: { start: sourceStart, length: sourceLength },
|
|
1492
1311
|
};
|
|
1493
1312
|
}
|
|
1494
|
-
|
|
1495
1313
|
const id = sanitizeMindmapId(line, index);
|
|
1496
1314
|
return {
|
|
1497
1315
|
id,
|
|
@@ -1502,20 +1320,16 @@ function parseMindmapNode(line: string, index: number, parentId: string, sourceS
|
|
|
1502
1320
|
sourceRange: { start: sourceStart, length: sourceLength },
|
|
1503
1321
|
};
|
|
1504
1322
|
}
|
|
1505
|
-
|
|
1506
|
-
function parseEdge(line: string, sourceStart: number): ParsedEdge & { fromNode: ParsedNode; toNode: ParsedNode } {
|
|
1323
|
+
function parseEdge(line, sourceStart) {
|
|
1507
1324
|
const parsed = parseFlowchartEdgeStatement(line);
|
|
1508
1325
|
if (!parsed)
|
|
1509
1326
|
return null;
|
|
1510
|
-
|
|
1511
1327
|
const fromNode = parseNodeToken(parsed.left);
|
|
1512
1328
|
const toNode = parseNodeToken(parsed.right);
|
|
1513
1329
|
if (!fromNode || !toNode)
|
|
1514
1330
|
return null;
|
|
1515
|
-
|
|
1516
1331
|
fromNode.sourceRange = { start: sourceStart + parsed.leftStart + parsed.left.indexOf(fromNode.id), length: fromNode.id.length };
|
|
1517
1332
|
toNode.sourceRange = { start: sourceStart + parsed.rightStart + parsed.right.indexOf(toNode.id), length: toNode.id.length };
|
|
1518
|
-
|
|
1519
1333
|
return {
|
|
1520
1334
|
from: fromNode.id,
|
|
1521
1335
|
to: toNode.id,
|
|
@@ -1529,32 +1343,25 @@ function parseEdge(line: string, sourceStart: number): ParsedEdge & { fromNode:
|
|
|
1529
1343
|
sourceRange: { start: sourceStart, length: line.length },
|
|
1530
1344
|
};
|
|
1531
1345
|
}
|
|
1532
|
-
|
|
1533
|
-
function parseNodeToken(token: string): ParsedNode {
|
|
1346
|
+
function parseNodeToken(token) {
|
|
1534
1347
|
const node = parseNode(token);
|
|
1535
1348
|
if (node)
|
|
1536
1349
|
return node;
|
|
1537
|
-
|
|
1538
1350
|
const id = new SourceCursor(token).readIdentifier();
|
|
1539
1351
|
return id ? { id, label: id, shape: "rectangle" } : null;
|
|
1540
1352
|
}
|
|
1541
|
-
|
|
1542
|
-
function parseShapeValue(id: string, value: string): ParsedNode {
|
|
1353
|
+
function parseShapeValue(id, value) {
|
|
1543
1354
|
if (!value)
|
|
1544
1355
|
return { id, label: id, shape: "rectangle" };
|
|
1545
|
-
|
|
1546
1356
|
const expandedShape = parseExpandedShape(value);
|
|
1547
1357
|
if (expandedShape)
|
|
1548
1358
|
return { id, label: expandedShape.label ?? id, shape: mapExpandedShape(expandedShape.shape) };
|
|
1549
|
-
|
|
1550
1359
|
const shapeValue = parseDelimitedShapeValue(value);
|
|
1551
1360
|
if (shapeValue)
|
|
1552
1361
|
return { id, label: unquoteLabel(shapeValue.label), shape: shapeValue.shape };
|
|
1553
|
-
|
|
1554
1362
|
return null;
|
|
1555
1363
|
}
|
|
1556
|
-
|
|
1557
|
-
function getEdgeType(connector: string) {
|
|
1364
|
+
function getEdgeType(connector) {
|
|
1558
1365
|
if (connector.includes("~"))
|
|
1559
1366
|
return "invisible";
|
|
1560
1367
|
if (connector.includes("o"))
|
|
@@ -1571,8 +1378,7 @@ function getEdgeType(connector: string) {
|
|
|
1571
1378
|
return "open";
|
|
1572
1379
|
return "arrow";
|
|
1573
1380
|
}
|
|
1574
|
-
|
|
1575
|
-
function unquoteLabel(label: string) {
|
|
1381
|
+
function unquoteLabel(label) {
|
|
1576
1382
|
let result = label.trim();
|
|
1577
1383
|
if (result.length >= 2) {
|
|
1578
1384
|
const first = result[0];
|
|
@@ -1582,8 +1388,7 @@ function unquoteLabel(label: string) {
|
|
|
1582
1388
|
}
|
|
1583
1389
|
return normalizeLabelLineBreaks(result);
|
|
1584
1390
|
}
|
|
1585
|
-
|
|
1586
|
-
function mapExpandedShape(shape: string) {
|
|
1391
|
+
function mapExpandedShape(shape) {
|
|
1587
1392
|
switch (shape) {
|
|
1588
1393
|
case "rect":
|
|
1589
1394
|
case "proc":
|
|
@@ -1763,8 +1568,7 @@ function mapExpandedShape(shape: string) {
|
|
|
1763
1568
|
return "rectangle";
|
|
1764
1569
|
}
|
|
1765
1570
|
}
|
|
1766
|
-
|
|
1767
|
-
function mapMindmapShape(shape: string) {
|
|
1571
|
+
function mapMindmapShape(shape) {
|
|
1768
1572
|
switch (shape) {
|
|
1769
1573
|
case "rectangle":
|
|
1770
1574
|
return "square";
|
|
@@ -1776,8 +1580,7 @@ function mapMindmapShape(shape: string) {
|
|
|
1776
1580
|
return "default";
|
|
1777
1581
|
}
|
|
1778
1582
|
}
|
|
1779
|
-
|
|
1780
|
-
function sanitizeMindmapId(label: string, index: number) {
|
|
1583
|
+
function sanitizeMindmapId(label, index) {
|
|
1781
1584
|
let result = "";
|
|
1782
1585
|
for (const char of label) {
|
|
1783
1586
|
if (isIdentifierPart(char))
|
|
@@ -1788,8 +1591,7 @@ function sanitizeMindmapId(label: string, index: number) {
|
|
|
1788
1591
|
result = result.trim();
|
|
1789
1592
|
return result || "mindmap_" + index;
|
|
1790
1593
|
}
|
|
1791
|
-
|
|
1792
|
-
function sanitizeDirectiveId(label: string) {
|
|
1594
|
+
function sanitizeDirectiveId(label) {
|
|
1793
1595
|
let result = "";
|
|
1794
1596
|
for (const char of label) {
|
|
1795
1597
|
if (isIdentifierPart(char))
|
|
@@ -1799,8 +1601,7 @@ function sanitizeDirectiveId(label: string) {
|
|
|
1799
1601
|
}
|
|
1800
1602
|
return result || "subgraph";
|
|
1801
1603
|
}
|
|
1802
|
-
|
|
1803
|
-
function getDefaultMindmapNodeSize(shape: string) {
|
|
1604
|
+
function getDefaultMindmapNodeSize(shape) {
|
|
1804
1605
|
switch (shape) {
|
|
1805
1606
|
case "circle":
|
|
1806
1607
|
case "bang":
|
|
@@ -1811,14 +1612,12 @@ function getDefaultMindmapNodeSize(shape: string) {
|
|
|
1811
1612
|
return { width: 150, height: 44 };
|
|
1812
1613
|
}
|
|
1813
1614
|
}
|
|
1814
|
-
|
|
1815
|
-
function getDefaultRequirementNodeSize(node: ParsedRequirementNode) {
|
|
1615
|
+
function getDefaultRequirementNodeSize(node) {
|
|
1816
1616
|
if (node.kind === "element")
|
|
1817
1617
|
return { width: 170, height: node.docRef ? 108 : 84 };
|
|
1818
1618
|
return { width: 220, height: 160 };
|
|
1819
1619
|
}
|
|
1820
|
-
|
|
1821
|
-
function getDefaultNodeSize(shape: string) {
|
|
1620
|
+
function getDefaultNodeSize(shape) {
|
|
1822
1621
|
switch (shape) {
|
|
1823
1622
|
case "decision":
|
|
1824
1623
|
return { width: 120, height: 80 };
|
|
@@ -1844,8 +1643,7 @@ function getDefaultNodeSize(shape: string) {
|
|
|
1844
1643
|
return { width: 120, height: 54 };
|
|
1845
1644
|
}
|
|
1846
1645
|
}
|
|
1847
|
-
|
|
1848
|
-
function getFallbackRequirementNodePosition(index: number, total: number, direction: FlowchartDirection) {
|
|
1646
|
+
function getFallbackRequirementNodePosition(index, total, direction) {
|
|
1849
1647
|
const columns = direction === "LR" || direction === "RL" ? Math.max(1, Math.ceil(total / 3)) : 3;
|
|
1850
1648
|
const column = index % columns;
|
|
1851
1649
|
const row = Math.floor(index / columns);
|
|
@@ -1857,8 +1655,7 @@ function getFallbackRequirementNodePosition(index: number, total: number, direct
|
|
|
1857
1655
|
return { left, top: 40 + (Math.ceil(total / columns) - row - 1) * 230 };
|
|
1858
1656
|
return { left, top };
|
|
1859
1657
|
}
|
|
1860
|
-
|
|
1861
|
-
function getFallbackFlowchartNodePosition(index: number, count: number, direction: FlowchartDirection) {
|
|
1658
|
+
function getFallbackFlowchartNodePosition(index, count, direction) {
|
|
1862
1659
|
const xStep = 180;
|
|
1863
1660
|
const yStep = 110;
|
|
1864
1661
|
switch (direction) {
|
|
@@ -1874,12 +1671,10 @@ function getFallbackFlowchartNodePosition(index: number, count: number, directio
|
|
|
1874
1671
|
return { left: 40, top: 40 + index * yStep };
|
|
1875
1672
|
}
|
|
1876
1673
|
}
|
|
1877
|
-
|
|
1878
|
-
function readMermaidDocument(text: string): ParsedMermaidDocument {
|
|
1674
|
+
function readMermaidDocument(text) {
|
|
1879
1675
|
const lines = getLineRecords(text);
|
|
1880
1676
|
if (lines[0]?.trimmed !== "---")
|
|
1881
1677
|
return { lines, title: "", frontmatter: "" };
|
|
1882
|
-
|
|
1883
1678
|
let frontmatterEnd = -1;
|
|
1884
1679
|
for (let i = 1; i < lines.length; i++) {
|
|
1885
1680
|
if (lines[i].trimmed === "---") {
|
|
@@ -1887,20 +1682,16 @@ function readMermaidDocument(text: string): ParsedMermaidDocument {
|
|
|
1887
1682
|
break;
|
|
1888
1683
|
}
|
|
1889
1684
|
}
|
|
1890
|
-
|
|
1891
1685
|
if (frontmatterEnd < 0)
|
|
1892
1686
|
return { lines, title: "", frontmatter: "" };
|
|
1893
|
-
|
|
1894
1687
|
const frontmatterLines = lines.slice(1, frontmatterEnd);
|
|
1895
|
-
|
|
1896
1688
|
return {
|
|
1897
1689
|
lines: lines.filter((_, index) => index > frontmatterEnd),
|
|
1898
1690
|
title: readFrontmatterTitle(frontmatterLines),
|
|
1899
1691
|
frontmatter: readFrontmatterWithoutTitle(frontmatterLines),
|
|
1900
1692
|
};
|
|
1901
1693
|
}
|
|
1902
|
-
|
|
1903
|
-
function readFrontmatterTitle(lines: LineRecord[]) {
|
|
1694
|
+
function readFrontmatterTitle(lines) {
|
|
1904
1695
|
for (const line of lines) {
|
|
1905
1696
|
const separator = line.trimmed.indexOf(":");
|
|
1906
1697
|
if (separator < 0)
|
|
@@ -1911,9 +1702,8 @@ function readFrontmatterTitle(lines: LineRecord[]) {
|
|
|
1911
1702
|
}
|
|
1912
1703
|
return "";
|
|
1913
1704
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
const remainingLines: string[] = [];
|
|
1705
|
+
function readFrontmatterWithoutTitle(lines) {
|
|
1706
|
+
const remainingLines = [];
|
|
1917
1707
|
for (let i = 0; i < lines.length; i++) {
|
|
1918
1708
|
const line = lines[i];
|
|
1919
1709
|
const separator = line.trimmed.indexOf(":");
|
|
@@ -1924,8 +1714,7 @@ function readFrontmatterWithoutTitle(lines: LineRecord[]) {
|
|
|
1924
1714
|
}
|
|
1925
1715
|
return trimBlankLines(remainingLines).join("\n");
|
|
1926
1716
|
}
|
|
1927
|
-
|
|
1928
|
-
function trimBlankLines(lines: string[]) {
|
|
1717
|
+
function trimBlankLines(lines) {
|
|
1929
1718
|
let start = 0;
|
|
1930
1719
|
let end = lines.length;
|
|
1931
1720
|
while (start < end && !lines[start].trim())
|
|
@@ -1934,9 +1723,8 @@ function trimBlankLines(lines: string[]) {
|
|
|
1934
1723
|
end--;
|
|
1935
1724
|
return lines.slice(start, end);
|
|
1936
1725
|
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
const records: LineRecord[] = [];
|
|
1726
|
+
function getLineRecords(text) {
|
|
1727
|
+
const records = [];
|
|
1940
1728
|
let offset = 0;
|
|
1941
1729
|
for (const line of splitLines(text)) {
|
|
1942
1730
|
const leadingWhitespaceLength = countLeadingWhitespace(line);
|
|
@@ -1945,9 +1733,8 @@ function getLineRecords(text: string) {
|
|
|
1945
1733
|
}
|
|
1946
1734
|
return records;
|
|
1947
1735
|
}
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
const lines: string[] = [];
|
|
1736
|
+
function splitLines(text) {
|
|
1737
|
+
const lines = [];
|
|
1951
1738
|
let start = 0;
|
|
1952
1739
|
for (let i = 0; i < text.length; i++) {
|
|
1953
1740
|
if (text[i] === "\n") {
|
|
@@ -1961,13 +1748,11 @@ function splitLines(text: string) {
|
|
|
1961
1748
|
lines.push(text.substring(start));
|
|
1962
1749
|
return lines;
|
|
1963
1750
|
}
|
|
1964
|
-
|
|
1965
|
-
function getDiagramDirection(designItems: IDesignItem[]) {
|
|
1751
|
+
function getDiagramDirection(designItems) {
|
|
1966
1752
|
const rootDesignItem = getRootDesignItem(designItems);
|
|
1967
1753
|
const rootDirection = rootDesignItem?.getAttribute(mermaidFlowchartDirectionAttribute);
|
|
1968
1754
|
if (isFlowchartDirection(rootDirection))
|
|
1969
1755
|
return rootDirection;
|
|
1970
|
-
|
|
1971
1756
|
for (const designItem of designItems) {
|
|
1972
1757
|
const direction = designItem.element.getAttribute("diagram-direction");
|
|
1973
1758
|
if (isFlowchartDirection(direction))
|
|
@@ -1975,42 +1760,34 @@ function getDiagramDirection(designItems: IDesignItem[]) {
|
|
|
1975
1760
|
}
|
|
1976
1761
|
return inferDiagramDirection(designItems);
|
|
1977
1762
|
}
|
|
1978
|
-
|
|
1979
|
-
function inferDiagramDirection(designItems: IDesignItem[]): FlowchartDirection {
|
|
1763
|
+
function inferDiagramDirection(designItems) {
|
|
1980
1764
|
const nodes = designItems
|
|
1981
1765
|
.filter(designItem => designItem.element.localName === "mermaid-node")
|
|
1982
1766
|
.map(designItem => {
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1767
|
+
const element = designItem.element;
|
|
1768
|
+
return {
|
|
1769
|
+
left: Number.parseFloat(element.style.left || "0"),
|
|
1770
|
+
top: Number.parseFloat(element.style.top || "0"),
|
|
1771
|
+
};
|
|
1772
|
+
});
|
|
1990
1773
|
if (nodes.length < 2)
|
|
1991
1774
|
return "TD";
|
|
1992
|
-
|
|
1993
1775
|
const first = nodes[0];
|
|
1994
1776
|
const last = nodes[nodes.length - 1];
|
|
1995
1777
|
const dx = last.left - first.left;
|
|
1996
1778
|
const dy = last.top - first.top;
|
|
1997
|
-
|
|
1998
1779
|
if (Math.abs(dx) > Math.abs(dy))
|
|
1999
1780
|
return dx >= 0 ? "LR" : "RL";
|
|
2000
|
-
|
|
2001
1781
|
return dy >= 0 ? "TD" : "BT";
|
|
2002
1782
|
}
|
|
2003
|
-
|
|
2004
|
-
function isFlowchartDirection(value: string): value is FlowchartDirection {
|
|
1783
|
+
function isFlowchartDirection(value) {
|
|
2005
1784
|
return value === "TB" || value === "TD" || value === "BT" || value === "RL" || value === "LR";
|
|
2006
1785
|
}
|
|
2007
|
-
|
|
2008
|
-
function isRequirementDirection(value: string): value is FlowchartDirection {
|
|
1786
|
+
function isRequirementDirection(value) {
|
|
2009
1787
|
return value === "TB" || value === "BT" || value === "RL" || value === "LR";
|
|
2010
1788
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
const rootDesignItem = instanceServiceContainer?.designerCanvas?.rootDesignItem;
|
|
1789
|
+
function setMermaidDocumentAttributes(instanceServiceContainer, diagramType, direction, title, frontmatter) {
|
|
1790
|
+
const rootDesignItem = instanceServiceContainer?.rootDesignItem;
|
|
2014
1791
|
rootDesignItem?._withoutUndoSetAttribute(mermaidDiagramTypeAttribute, diagramType);
|
|
2015
1792
|
if (direction)
|
|
2016
1793
|
rootDesignItem?._withoutUndoSetAttribute(mermaidFlowchartDirectionAttribute, direction);
|
|
@@ -2025,8 +1802,7 @@ function setMermaidDocumentAttributes(instanceServiceContainer: InstanceServiceC
|
|
|
2025
1802
|
else
|
|
2026
1803
|
rootDesignItem?._withoutUndoRemoveAttribute(mermaidFrontmatterAttribute);
|
|
2027
1804
|
}
|
|
2028
|
-
|
|
2029
|
-
function writeMermaidFrontmatter(textWriter: ITextWriter, designItems: IDesignItem[], rootDesignItem?: IDesignItem) {
|
|
1805
|
+
function writeMermaidFrontmatter(textWriter, designItems, rootDesignItem) {
|
|
2030
1806
|
const root = rootDesignItem ?? getRootDesignItem(designItems);
|
|
2031
1807
|
const title = getMermaidDocumentTitle(root);
|
|
2032
1808
|
const frontmatter = getMermaidDocumentFrontmatter(root);
|
|
@@ -2041,15 +1817,13 @@ function writeMermaidFrontmatter(textWriter: ITextWriter, designItems: IDesignIt
|
|
|
2041
1817
|
}
|
|
2042
1818
|
textWriter.writeLine("---");
|
|
2043
1819
|
}
|
|
2044
|
-
|
|
2045
|
-
function getWritableDocumentDiagramType(designItems: IDesignItem[]): MermaidDocumentDiagramType {
|
|
1820
|
+
function getWritableDocumentDiagramType(designItems) {
|
|
2046
1821
|
const hasSequenceItems = designItems.some(designItem => designItem.element.localName === MermaidSequenceParticipant.is || designItem.element.localName === MermaidSequenceMessage.is);
|
|
2047
1822
|
const hasFlowchartItems = designItems.some(designItem => designItem.element.localName === MermaidNode.is || designItem.element.localName === MermaidEdge.is);
|
|
2048
1823
|
const hasMindmapItems = designItems.some(designItem => designItem.element.localName === MermaidMindmapNode.is);
|
|
2049
1824
|
const hasRequirementItems = designItems.some(designItem => designItem.element.localName === MermaidRequirementNode.is || designItem.element.localName === MermaidRequirementRelationship.is);
|
|
2050
1825
|
const rootDesignItem = getRootDesignItem(designItems);
|
|
2051
1826
|
const documentType = rootDesignItem ? getMermaidDocumentDiagramType(rootDesignItem) : null;
|
|
2052
|
-
|
|
2053
1827
|
if (documentType === "requirementDiagram" && !hasFlowchartItems && !hasSequenceItems && !hasMindmapItems)
|
|
2054
1828
|
return "requirementDiagram";
|
|
2055
1829
|
if (documentType === "mindmap" && !hasFlowchartItems && !hasSequenceItems && !hasRequirementItems)
|
|
@@ -2066,71 +1840,60 @@ function getWritableDocumentDiagramType(designItems: IDesignItem[]): MermaidDocu
|
|
|
2066
1840
|
return "sequenceDiagram";
|
|
2067
1841
|
return "flowchart";
|
|
2068
1842
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
return designItems[0]?.isRootItem ? designItems[0] : designItems[0]?.instanceServiceContainer?.designerCanvas?.rootDesignItem;
|
|
1843
|
+
function getRootDesignItem(designItems) {
|
|
1844
|
+
return designItems[0]?.isRootItem ? designItems[0] : designItems[0]?.instanceServiceContainer?.rootDesignItem;
|
|
2072
1845
|
}
|
|
2073
|
-
|
|
2074
|
-
function getMermaidDesignItems(designItems: IDesignItem[]) {
|
|
1846
|
+
function getMermaidDesignItems(designItems) {
|
|
2075
1847
|
if (designItems[0]?.isRootItem)
|
|
2076
1848
|
return Array.from(designItems[0].children());
|
|
2077
1849
|
return designItems;
|
|
2078
1850
|
}
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
const element = designItem.element as HTMLElement;
|
|
1851
|
+
function getMindmapSortValue(designItem) {
|
|
1852
|
+
const element = designItem.element;
|
|
2082
1853
|
const top = Number.parseFloat(element.style.top || "0");
|
|
2083
1854
|
const left = Number.parseFloat(element.style.left || "0");
|
|
2084
1855
|
return top * 10000 + left;
|
|
2085
1856
|
}
|
|
2086
|
-
|
|
2087
|
-
function sortMindmapItems(items: IDesignItem[]) {
|
|
1857
|
+
function sortMindmapItems(items) {
|
|
2088
1858
|
return [...items].sort((a, b) => getMindmapSortValue(a) - getMindmapSortValue(b));
|
|
2089
1859
|
}
|
|
2090
|
-
|
|
2091
|
-
function repeatText(value: string, count: number) {
|
|
1860
|
+
function repeatText(value, count) {
|
|
2092
1861
|
let result = "";
|
|
2093
1862
|
for (let i = 0; i < count; i++)
|
|
2094
1863
|
result += value;
|
|
2095
1864
|
return result;
|
|
2096
1865
|
}
|
|
2097
|
-
|
|
2098
|
-
function writeDesignItemLine(textWriter: ITextWriter, designItem: IDesignItem, line: string, updatePositions?: boolean) {
|
|
1866
|
+
function writeDesignItemLine(textWriter, designItem, line, updatePositions) {
|
|
2099
1867
|
const start = textWriter.position;
|
|
2100
1868
|
line = indentEmbeddedNewlines(line);
|
|
2101
1869
|
textWriter.writeLine(line);
|
|
2102
1870
|
if (updatePositions)
|
|
2103
1871
|
designItem.instanceServiceContainer.designItemDocumentPositionService?.setPosition(designItem, { start, length: line.length });
|
|
2104
1872
|
}
|
|
2105
|
-
|
|
2106
|
-
function indentEmbeddedNewlines(line: string) {
|
|
1873
|
+
function indentEmbeddedNewlines(line) {
|
|
2107
1874
|
const newlineIndex = line.indexOf("\n");
|
|
2108
1875
|
if (newlineIndex < 0)
|
|
2109
1876
|
return line;
|
|
2110
1877
|
const indent = line.substring(0, countLeadingWhitespace(line));
|
|
2111
1878
|
return line.replaceAll("\n", "\n" + indent);
|
|
2112
1879
|
}
|
|
2113
|
-
|
|
2114
|
-
async function getMermaidLayout(code: string, nodes: Map<string, ParsedNode>) {
|
|
1880
|
+
async function getMermaidLayout(code, nodes) {
|
|
2115
1881
|
if (typeof document === "undefined" || typeof DOMParser === "undefined")
|
|
2116
1882
|
return null;
|
|
2117
|
-
|
|
2118
1883
|
try {
|
|
2119
1884
|
const mermaid = await import("mermaid");
|
|
2120
1885
|
const id = "mermaid-layout-" + Math.random().toString(36).slice(2);
|
|
2121
1886
|
mermaid.default.initialize({ startOnLoad: false, securityLevel: "strict" });
|
|
2122
1887
|
const result = await mermaid.default.render(id, code);
|
|
2123
1888
|
const doc = new DOMParser().parseFromString(result.svg, "image/svg+xml");
|
|
2124
|
-
const layoutNodes = new Map
|
|
2125
|
-
const layoutSubgraphs = new Map
|
|
1889
|
+
const layoutNodes = new Map();
|
|
1890
|
+
const layoutSubgraphs = new Map();
|
|
2126
1891
|
let minX = Number.POSITIVE_INFINITY;
|
|
2127
1892
|
let minY = Number.POSITIVE_INFINITY;
|
|
2128
|
-
|
|
2129
1893
|
for (const nodeElement of Array.from(doc.querySelectorAll("g.node"))) {
|
|
2130
1894
|
const nodeId = nodeElement.getAttribute("data-id") ?? getFlowchartNodeIdFromDomId(nodeElement.id);
|
|
2131
1895
|
if (!nodeId || !nodes.has(nodeId))
|
|
2132
1896
|
continue;
|
|
2133
|
-
|
|
2134
1897
|
const center = parseTranslate(nodeElement.getAttribute("transform"));
|
|
2135
1898
|
const size = getSvgNodeSize(nodeElement);
|
|
2136
1899
|
const layout = {
|
|
@@ -2143,7 +1906,6 @@ async function getMermaidLayout(code: string, nodes: Map<string, ParsedNode>) {
|
|
|
2143
1906
|
minX = Math.min(minX, layout.x);
|
|
2144
1907
|
minY = Math.min(minY, layout.y);
|
|
2145
1908
|
}
|
|
2146
|
-
|
|
2147
1909
|
for (const clusterElement of Array.from(doc.querySelectorAll("g.cluster"))) {
|
|
2148
1910
|
const clusterId = getClusterIdFromDomId(clusterElement.id, id);
|
|
2149
1911
|
if (!clusterId)
|
|
@@ -2163,10 +1925,8 @@ async function getMermaidLayout(code: string, nodes: Map<string, ParsedNode>) {
|
|
|
2163
1925
|
minX = Math.min(minX, layout.x);
|
|
2164
1926
|
minY = Math.min(minY, layout.y);
|
|
2165
1927
|
}
|
|
2166
|
-
|
|
2167
1928
|
if (!layoutNodes.size && !layoutSubgraphs.size)
|
|
2168
1929
|
return null;
|
|
2169
|
-
|
|
2170
1930
|
const offsetX = 40 - minX;
|
|
2171
1931
|
const offsetY = 40 - minY;
|
|
2172
1932
|
for (const layout of layoutNodes.values()) {
|
|
@@ -2177,27 +1937,24 @@ async function getMermaidLayout(code: string, nodes: Map<string, ParsedNode>) {
|
|
|
2177
1937
|
layout.x += offsetX;
|
|
2178
1938
|
layout.y += offsetY;
|
|
2179
1939
|
}
|
|
2180
|
-
|
|
2181
1940
|
return { nodes: layoutNodes, subgraphs: layoutSubgraphs };
|
|
2182
|
-
}
|
|
1941
|
+
}
|
|
1942
|
+
catch {
|
|
2183
1943
|
return null;
|
|
2184
1944
|
}
|
|
2185
1945
|
}
|
|
2186
|
-
|
|
2187
|
-
async function getMermaidRequirementLayout(code: string, nodes: Map<string, ParsedRequirementNode>) {
|
|
1946
|
+
async function getMermaidRequirementLayout(code, nodes) {
|
|
2188
1947
|
if (typeof document === "undefined" || typeof DOMParser === "undefined")
|
|
2189
1948
|
return null;
|
|
2190
|
-
|
|
2191
1949
|
try {
|
|
2192
1950
|
const mermaid = await import("mermaid");
|
|
2193
1951
|
const id = "mermaid-requirement-layout-" + Math.random().toString(36).slice(2);
|
|
2194
1952
|
mermaid.default.initialize({ startOnLoad: false, securityLevel: "strict" });
|
|
2195
1953
|
const result = await mermaid.default.render(id, code);
|
|
2196
1954
|
const doc = new DOMParser().parseFromString(result.svg, "image/svg+xml");
|
|
2197
|
-
const layoutNodes = new Map
|
|
1955
|
+
const layoutNodes = new Map();
|
|
2198
1956
|
let minX = Number.POSITIVE_INFINITY;
|
|
2199
1957
|
let minY = Number.POSITIVE_INFINITY;
|
|
2200
|
-
|
|
2201
1958
|
for (const nodeElement of Array.from(doc.querySelectorAll("g.node"))) {
|
|
2202
1959
|
const nodeId = getRequirementNodeIdFromSvgId(nodeElement.id, id, nodes);
|
|
2203
1960
|
const node = nodeId ? nodes.get(nodeId) : null;
|
|
@@ -2215,45 +1972,39 @@ async function getMermaidRequirementLayout(code: string, nodes: Map<string, Pars
|
|
|
2215
1972
|
minX = Math.min(minX, layout.x);
|
|
2216
1973
|
minY = Math.min(minY, layout.y);
|
|
2217
1974
|
}
|
|
2218
|
-
|
|
2219
1975
|
if (!layoutNodes.size)
|
|
2220
1976
|
return null;
|
|
2221
|
-
|
|
2222
1977
|
const offsetX = 40 - minX;
|
|
2223
1978
|
const offsetY = 40 - minY;
|
|
2224
1979
|
for (const layout of layoutNodes.values()) {
|
|
2225
1980
|
layout.x += offsetX;
|
|
2226
1981
|
layout.y += offsetY;
|
|
2227
1982
|
}
|
|
2228
|
-
|
|
2229
1983
|
return { nodes: layoutNodes };
|
|
2230
|
-
}
|
|
1984
|
+
}
|
|
1985
|
+
catch {
|
|
2231
1986
|
return null;
|
|
2232
1987
|
}
|
|
2233
1988
|
}
|
|
2234
|
-
|
|
2235
|
-
async function getMermaidMindmapLayout(code: string, nodes: ParsedMindmapNode[]) {
|
|
1989
|
+
async function getMermaidMindmapLayout(code, nodes) {
|
|
2236
1990
|
if (typeof document === "undefined" || typeof DOMParser === "undefined")
|
|
2237
1991
|
return null;
|
|
2238
|
-
|
|
2239
1992
|
try {
|
|
2240
1993
|
const mermaid = await import("mermaid");
|
|
2241
1994
|
const id = "mermaid-mindmap-layout-" + Math.random().toString(36).slice(2);
|
|
2242
1995
|
mermaid.default.initialize({ startOnLoad: false, securityLevel: "strict" });
|
|
2243
1996
|
const result = await mermaid.default.render(id, code);
|
|
2244
1997
|
const doc = new DOMParser().parseFromString(result.svg, "image/svg+xml");
|
|
2245
|
-
const layoutNodes = new Map
|
|
1998
|
+
const layoutNodes = new Map();
|
|
2246
1999
|
const candidateElements = Array.from(doc.querySelectorAll("g.node.mindmap-node"));
|
|
2247
2000
|
let minX = Number.POSITIVE_INFINITY;
|
|
2248
2001
|
let minY = Number.POSITIVE_INFINITY;
|
|
2249
2002
|
let nextNodeIndex = 0;
|
|
2250
|
-
|
|
2251
2003
|
for (const nodeElement of candidateElements) {
|
|
2252
2004
|
if (nextNodeIndex >= nodes.length)
|
|
2253
2005
|
break;
|
|
2254
2006
|
if (!nodeElement.querySelector("text, foreignObject"))
|
|
2255
2007
|
continue;
|
|
2256
|
-
|
|
2257
2008
|
const node = nodes[nextNodeIndex++];
|
|
2258
2009
|
const center = parseTranslateFromElementTree(nodeElement);
|
|
2259
2010
|
const size = getMindmapWidgetSize(getSvgNodeSize(nodeElement), node.shape);
|
|
@@ -2267,27 +2018,24 @@ async function getMermaidMindmapLayout(code: string, nodes: ParsedMindmapNode[])
|
|
|
2267
2018
|
minX = Math.min(minX, layout.x);
|
|
2268
2019
|
minY = Math.min(minY, layout.y);
|
|
2269
2020
|
}
|
|
2270
|
-
|
|
2271
2021
|
if (!layoutNodes.size)
|
|
2272
2022
|
return null;
|
|
2273
|
-
|
|
2274
2023
|
const offsetX = 40 - minX;
|
|
2275
2024
|
const offsetY = 40 - minY;
|
|
2276
2025
|
for (const layout of layoutNodes.values()) {
|
|
2277
2026
|
layout.x += offsetX;
|
|
2278
2027
|
layout.y += offsetY;
|
|
2279
2028
|
}
|
|
2280
|
-
|
|
2281
2029
|
return { nodes: layoutNodes };
|
|
2282
|
-
}
|
|
2030
|
+
}
|
|
2031
|
+
catch {
|
|
2283
2032
|
return null;
|
|
2284
2033
|
}
|
|
2285
2034
|
}
|
|
2286
|
-
|
|
2287
|
-
function parseTranslateFromElementTree(element: Element) {
|
|
2035
|
+
function parseTranslateFromElementTree(element) {
|
|
2288
2036
|
let x = 0;
|
|
2289
2037
|
let y = 0;
|
|
2290
|
-
let current
|
|
2038
|
+
let current = element;
|
|
2291
2039
|
while (current) {
|
|
2292
2040
|
const translate = parseTranslate(current.getAttribute("transform"));
|
|
2293
2041
|
x += translate.x;
|
|
@@ -2296,16 +2044,14 @@ function parseTranslateFromElementTree(element: Element) {
|
|
|
2296
2044
|
}
|
|
2297
2045
|
return { x, y };
|
|
2298
2046
|
}
|
|
2299
|
-
|
|
2300
|
-
function parseTranslate(transform: string) {
|
|
2047
|
+
function parseTranslate(transform) {
|
|
2301
2048
|
const values = parseTranslateValues(transform);
|
|
2302
2049
|
return {
|
|
2303
2050
|
x: values.x,
|
|
2304
2051
|
y: values.y,
|
|
2305
2052
|
};
|
|
2306
2053
|
}
|
|
2307
|
-
|
|
2308
|
-
function getFlowchartNodeIdFromDomId(domId: string) {
|
|
2054
|
+
function getFlowchartNodeIdFromDomId(domId) {
|
|
2309
2055
|
const prefix = "flowchart-";
|
|
2310
2056
|
if (!domId?.startsWith(prefix))
|
|
2311
2057
|
return "";
|
|
@@ -2316,8 +2062,7 @@ function getFlowchartNodeIdFromDomId(domId: string) {
|
|
|
2316
2062
|
const suffix = withoutPrefix.substring(lastDash + 1);
|
|
2317
2063
|
return isAllDigits(suffix) ? withoutPrefix.substring(0, lastDash) : withoutPrefix;
|
|
2318
2064
|
}
|
|
2319
|
-
|
|
2320
|
-
function getRequirementNodeIdFromSvgId(svgId: string, renderId: string, nodes: Map<string, ParsedRequirementNode>) {
|
|
2065
|
+
function getRequirementNodeIdFromSvgId(svgId, renderId, nodes) {
|
|
2321
2066
|
if (!svgId)
|
|
2322
2067
|
return "";
|
|
2323
2068
|
const prefix = renderId + "-";
|
|
@@ -2333,8 +2078,7 @@ function getRequirementNodeIdFromSvgId(svgId: string, renderId: string, nodes: M
|
|
|
2333
2078
|
}
|
|
2334
2079
|
return match;
|
|
2335
2080
|
}
|
|
2336
|
-
|
|
2337
|
-
function getClusterIdFromDomId(domId: string, renderId: string) {
|
|
2081
|
+
function getClusterIdFromDomId(domId, renderId) {
|
|
2338
2082
|
if (!domId)
|
|
2339
2083
|
return "";
|
|
2340
2084
|
const prefixes = [renderId + "_flowchart-", "flowchart-", renderId + "-", "cluster-"];
|
|
@@ -2344,8 +2088,7 @@ function getClusterIdFromDomId(domId: string, renderId: string) {
|
|
|
2344
2088
|
}
|
|
2345
2089
|
return domId;
|
|
2346
2090
|
}
|
|
2347
|
-
|
|
2348
|
-
function parseTranslateValues(transform: string) {
|
|
2091
|
+
function parseTranslateValues(transform) {
|
|
2349
2092
|
const result = { x: 0, y: 0 };
|
|
2350
2093
|
if (!transform)
|
|
2351
2094
|
return result;
|
|
@@ -2364,8 +2107,7 @@ function parseTranslateValues(transform: string) {
|
|
|
2364
2107
|
result.y = Number.parseFloat(content.substring(separator + 1).trim()) || 0;
|
|
2365
2108
|
return result;
|
|
2366
2109
|
}
|
|
2367
|
-
|
|
2368
|
-
function findTopLevelColon(text: string) {
|
|
2110
|
+
function findTopLevelColon(text) {
|
|
2369
2111
|
let quote = "";
|
|
2370
2112
|
for (let i = 0; i < text.length; i++) {
|
|
2371
2113
|
const char = text[i];
|
|
@@ -2383,8 +2125,7 @@ function findTopLevelColon(text: string) {
|
|
|
2383
2125
|
}
|
|
2384
2126
|
return -1;
|
|
2385
2127
|
}
|
|
2386
|
-
|
|
2387
|
-
function isRequirementType(value: string) {
|
|
2128
|
+
function isRequirementType(value) {
|
|
2388
2129
|
return equalsIgnoreCase(value, "requirement")
|
|
2389
2130
|
|| equalsIgnoreCase(value, "functionalRequirement")
|
|
2390
2131
|
|| equalsIgnoreCase(value, "interfaceRequirement")
|
|
@@ -2392,8 +2133,7 @@ function isRequirementType(value: string) {
|
|
|
2392
2133
|
|| equalsIgnoreCase(value, "physicalRequirement")
|
|
2393
2134
|
|| equalsIgnoreCase(value, "designConstraint");
|
|
2394
2135
|
}
|
|
2395
|
-
|
|
2396
|
-
function isRequirementRelationshipType(value: string) {
|
|
2136
|
+
function isRequirementRelationshipType(value) {
|
|
2397
2137
|
return equalsIgnoreCase(value, "contains")
|
|
2398
2138
|
|| equalsIgnoreCase(value, "copies")
|
|
2399
2139
|
|| equalsIgnoreCase(value, "derives")
|
|
@@ -2402,8 +2142,7 @@ function isRequirementRelationshipType(value: string) {
|
|
|
2402
2142
|
|| equalsIgnoreCase(value, "refines")
|
|
2403
2143
|
|| equalsIgnoreCase(value, "traces");
|
|
2404
2144
|
}
|
|
2405
|
-
|
|
2406
|
-
function isAllDigits(value: string) {
|
|
2145
|
+
function isAllDigits(value) {
|
|
2407
2146
|
if (!value)
|
|
2408
2147
|
return false;
|
|
2409
2148
|
for (const char of value) {
|
|
@@ -2412,8 +2151,7 @@ function isAllDigits(value: string) {
|
|
|
2412
2151
|
}
|
|
2413
2152
|
return true;
|
|
2414
2153
|
}
|
|
2415
|
-
|
|
2416
|
-
function getSvgNodeSize(nodeElement: Element) {
|
|
2154
|
+
function getSvgNodeSize(nodeElement) {
|
|
2417
2155
|
const foreignObject = nodeElement.querySelector("foreignObject");
|
|
2418
2156
|
if (foreignObject) {
|
|
2419
2157
|
const width = Number.parseFloat(foreignObject.getAttribute("width") ?? "");
|
|
@@ -2421,7 +2159,6 @@ function getSvgNodeSize(nodeElement: Element) {
|
|
|
2421
2159
|
if (Number.isFinite(width) && Number.isFinite(height))
|
|
2422
2160
|
return { width, height };
|
|
2423
2161
|
}
|
|
2424
|
-
|
|
2425
2162
|
const rect = nodeElement.querySelector("rect");
|
|
2426
2163
|
if (rect) {
|
|
2427
2164
|
const width = Number.parseFloat(rect.getAttribute("width") ?? "");
|
|
@@ -2429,7 +2166,6 @@ function getSvgNodeSize(nodeElement: Element) {
|
|
|
2429
2166
|
if (Number.isFinite(width) && Number.isFinite(height))
|
|
2430
2167
|
return { width, height };
|
|
2431
2168
|
}
|
|
2432
|
-
|
|
2433
2169
|
const polygon = nodeElement.querySelector("polygon");
|
|
2434
2170
|
if (polygon) {
|
|
2435
2171
|
const points = splitWhitespace(polygon.getAttribute("points") ?? "").map(point => {
|
|
@@ -2442,20 +2178,17 @@ function getSvgNodeSize(nodeElement: Element) {
|
|
|
2442
2178
|
return { width: Math.max(...xs) - Math.min(...xs), height: Math.max(...ys) - Math.min(...ys) };
|
|
2443
2179
|
}
|
|
2444
2180
|
}
|
|
2445
|
-
|
|
2446
2181
|
return { width: 120, height: 54 };
|
|
2447
2182
|
}
|
|
2448
|
-
|
|
2449
|
-
function getMindmapWidgetSize(svgSize: { width: number; height: number }, shape: string) {
|
|
2183
|
+
function getMindmapWidgetSize(svgSize, shape) {
|
|
2450
2184
|
const defaultSize = getDefaultMindmapNodeSize(shape);
|
|
2451
2185
|
return {
|
|
2452
2186
|
width: Math.max(svgSize.width, defaultSize.width),
|
|
2453
2187
|
height: Math.max(svgSize.height, defaultSize.height),
|
|
2454
2188
|
};
|
|
2455
2189
|
}
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
const parts: string[] = [];
|
|
2190
|
+
function splitWhitespace(text) {
|
|
2191
|
+
const parts = [];
|
|
2459
2192
|
let start = -1;
|
|
2460
2193
|
for (let i = 0; i < text.length; i++) {
|
|
2461
2194
|
if (isWhitespace(text[i])) {
|
|
@@ -2463,7 +2196,8 @@ function splitWhitespace(text: string) {
|
|
|
2463
2196
|
parts.push(text.substring(start, i));
|
|
2464
2197
|
start = -1;
|
|
2465
2198
|
}
|
|
2466
|
-
}
|
|
2199
|
+
}
|
|
2200
|
+
else if (start < 0) {
|
|
2467
2201
|
start = i;
|
|
2468
2202
|
}
|
|
2469
2203
|
}
|