@openpresentation/opf 0.32.1 → 0.34.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/README.md +9 -0
- package/dist/browser.js +22 -21
- package/dist/catalog-refs-CoIrOdAw.d.ts +937 -0
- package/dist/{catalog-schemas-LdqOPebq.d.ts → catalog-schemas-FjLRPtjB.d.ts} +10 -4
- package/dist/{chart-data-oIZQlFGi.d.ts → chart-data-B_k-WTex.d.ts} +7 -4
- package/dist/{chunk-PB7ME64J.js → chunk-244OPLAV.js} +1 -1
- package/dist/{chunk-IT7FQKED.js → chunk-2HX4BGAS.js} +6 -6
- package/dist/{chunk-2E6CDYL2.js → chunk-36DLVJGW.js} +19 -16
- package/dist/{chunk-XQO2CT6Q.js → chunk-3THGTDL2.js} +2 -2
- package/dist/{chunk-CLRYHWQN.js → chunk-42JBXJKW.js} +187 -25
- package/dist/chunk-BLCDUM7B.js +7 -0
- package/dist/{chunk-NVAJASOD.js → chunk-CJVKOJ6B.js} +10195 -2036
- package/dist/{chunk-XFHXQCXL.js → chunk-DQ7QYOUV.js} +99 -13
- package/dist/{chunk-NEJ32O7X.js → chunk-F6BXO4AI.js} +1 -1
- package/dist/{chunk-OXLA4HXQ.js → chunk-FAXO3SUE.js} +1196 -313
- package/dist/{chunk-J63CIRIV.js → chunk-FIQMAIZV.js} +4 -4
- package/dist/{chunk-PJSPHHRK.js → chunk-FK5XG742.js} +3 -16
- package/dist/{chunk-HKUV7NEN.js → chunk-HHVQ2SDT.js} +1 -1
- package/dist/{chunk-SZFO3MAJ.js → chunk-HUGVYHZ2.js} +4 -4
- package/dist/{chunk-LEF4X4KI.js → chunk-LCT5ZV3Q.js} +2400 -222
- package/dist/chunk-NLJFNCZ4.js +1560 -0
- package/dist/{chunk-GM7WFPGG.js → chunk-PRXZD2II.js} +6 -1
- package/dist/{chunk-YFJIIIOL.js → chunk-QGJVOPLG.js} +3 -3
- package/dist/{chunk-F7DN33UL.js → chunk-QGTJF7HV.js} +16 -14
- package/dist/{chunk-ONVFUVQ5.js → chunk-RUV7CCE6.js} +136 -31
- package/dist/{chunk-SW676APJ.js → chunk-U7TYSPYM.js} +2 -2
- package/dist/chunk-UJZN2ZH6.js +1 -0
- package/dist/chunk-VDZXNNZF.js +221 -0
- package/dist/{chunk-UJSAR6GF.js → chunk-W4DYDRV2.js} +21 -0
- package/dist/chunk-WCPDN7AY.js +642 -0
- package/dist/{chunk-BBVW5ZC2.js → chunk-WMFT5R7I.js} +2 -2
- package/dist/{chunk-AQEAZDL2.js → chunk-XJUMFH33.js} +2 -1
- package/dist/{composition-Ds6WHyO7.d.ts → composition-CvtvgBDE.d.ts} +2783 -873
- package/dist/composition.d.ts +4 -3
- package/dist/composition.js +3 -2
- package/dist/{conversion-CdzrTxib.d.ts → conversion-B_5AKTYQ.d.ts} +39 -10
- package/dist/conversion-CMBGOTAC.js +25 -0
- package/dist/convert.d.ts +5 -4
- package/dist/convert.js +17 -13
- package/dist/data.d.ts +2 -2
- package/dist/data.js +4 -3
- package/dist/{deck-report-CKDNQ2t4.d.ts → deck-report-BVlQZ42f.d.ts} +3 -3
- package/dist/deck.d.ts +7 -6
- package/dist/deck.js +13 -12
- package/dist/diagram-engine-eager.js +6 -2
- package/dist/diagram-engine-lazy.js +14 -1
- package/dist/diagram-plantuml-XRZ6VAOL.js +3 -0
- package/dist/diff.js +6 -5
- package/dist/docs.js +88 -52
- package/dist/examples.js +28745 -18393
- package/dist/font-policy.js +2 -2
- package/dist/format.js +3 -3
- package/dist/ids.js +6 -5
- package/dist/index.d.ts +19 -16
- package/dist/index.js +37 -26
- package/dist/markdown.d.ts +3 -2
- package/dist/markdown.js +10 -9
- package/dist/node-engine.d.ts +44 -11
- package/dist/node-engine.js +47 -28
- package/dist/{pagination-DRZ_JNFY.d.ts → pagination-CZQQYk7L.d.ts} +22 -4
- package/dist/pagination.d.ts +5 -4
- package/dist/pagination.js +6 -5
- package/dist/patch.js +5 -4
- package/dist/precompiled.js +3 -3
- package/dist/{presentation-DnD7mfmf.d.ts → presentation-s9262acV.d.ts} +1172 -208
- package/dist/repo-readme.js +2 -2
- package/dist/schema-engine-ajv.js +2 -2
- package/dist/schema-engine-precompiled.js +3 -3
- package/dist/schema.d.ts +3 -3
- package/dist/schema.js +5 -4
- package/dist/schemas.d.ts +56 -4
- package/dist/schemas.js +2 -2
- package/dist/shape-catalog.d.ts +98 -0
- package/dist/shape-catalog.js +302 -0
- package/dist/shape-engine-eager.js +9 -0
- package/dist/shape-engine-lazy.js +12 -0
- package/dist/shape-engine-module-N74FCHGY.js +3 -0
- package/dist/shape-geometry.d.ts +126 -0
- package/dist/shape-geometry.js +2 -0
- package/dist/source.d.ts +10 -5
- package/dist/source.js +12 -11
- package/dist/spec/README.md +1 -1
- package/dist/spec/reference/engine-vocabularies.json +135 -0
- package/dist/spec/reference/font-policy.json +3 -16
- package/dist/spec/reference/preset-geometry.json +10699 -0
- package/dist/spec/reference/preset-geometry.schema.json +126 -0
- package/dist/spec/schemas/catalog-index.schema.json +1 -0
- package/dist/spec/schemas/chart-type.schema.json +4 -4
- package/dist/spec/schemas/icon-set.schema.json +75 -0
- package/dist/spec/schemas/layout.schema.json +82 -23
- package/dist/spec/schemas/opf.schema.json +1616 -296
- package/dist/spec/schemas/theme.schema.json +11 -5
- package/dist/spec-files.d.ts +1 -1
- package/dist/spec-files.js +2 -2
- package/dist/symbol-font-encodings.js +1 -1
- package/dist/types.d.ts +83 -71
- package/dist/{validation-types-DxyYPebs.d.ts → validation-types-CYbsUuZ9.d.ts} +8 -5
- package/dist/validator.d.ts +35 -7
- package/dist/validator.js +5 -4
- package/dist/yaml.d.ts +3 -2
- package/dist/yaml.js +9 -8
- package/package.json +22 -6
- package/dist/catalog-refs-kAefsZWT.d.ts +0 -129
- package/dist/chunk-DGS47ONG.js +0 -1
- package/dist/conversion-5FUDQPED.js +0 -24
|
@@ -0,0 +1,1560 @@
|
|
|
1
|
+
import { DIAGRAM_SOURCE_LIMIT, DIAGRAM_TRANSLATED_LIMIT, DIAGRAM_MAX_NESTING } from './chunk-BLCDUM7B.js';
|
|
2
|
+
|
|
3
|
+
// src/diagram-plantuml.ts
|
|
4
|
+
var PlantumlError = class extends Error {
|
|
5
|
+
constructor(issue) {
|
|
6
|
+
super(issue.message);
|
|
7
|
+
this.issue = issue;
|
|
8
|
+
}
|
|
9
|
+
issue;
|
|
10
|
+
};
|
|
11
|
+
var MAX_LINE = 2e3;
|
|
12
|
+
var fail = (code, message, line, column) => {
|
|
13
|
+
throw new PlantumlError({ code, message, ...line !== void 0 ? { line, column: column ?? 1 } : {} });
|
|
14
|
+
};
|
|
15
|
+
var OTHER_KINDS = {
|
|
16
|
+
wbs: "work breakdown structure",
|
|
17
|
+
json: "JSON",
|
|
18
|
+
yaml: "YAML",
|
|
19
|
+
salt: "Salt wireframe",
|
|
20
|
+
ditaa: "ditaa",
|
|
21
|
+
dot: 'Graphviz DOT (write it with syntax "dot")',
|
|
22
|
+
math: "math",
|
|
23
|
+
latex: "LaTeX",
|
|
24
|
+
creole: "Creole",
|
|
25
|
+
board: "board",
|
|
26
|
+
chen: "Chen entity relationship",
|
|
27
|
+
ebnf: "EBNF",
|
|
28
|
+
regex: "regular expression",
|
|
29
|
+
files: "files",
|
|
30
|
+
chronology: "chronology",
|
|
31
|
+
nwdiag: "network",
|
|
32
|
+
archimate: "ArchiMate",
|
|
33
|
+
jcckit: "JCCKit",
|
|
34
|
+
flow: "flow",
|
|
35
|
+
git: "git",
|
|
36
|
+
project: "project"
|
|
37
|
+
};
|
|
38
|
+
function readLines(source) {
|
|
39
|
+
const raw = source.split(/\r?\n/);
|
|
40
|
+
let kind = "", start = -1, end = raw.length;
|
|
41
|
+
for (let index = 0; index < raw.length; index++) {
|
|
42
|
+
const match = /^\s*@start(\w+)/i.exec(raw[index]);
|
|
43
|
+
if (match) {
|
|
44
|
+
kind = match[1].toLowerCase();
|
|
45
|
+
start = index;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
if (raw[index].trim() && !/^\s*'/.test(raw[index])) break;
|
|
49
|
+
}
|
|
50
|
+
if (start < 0) fail("diagram-syntax", "A PlantUML source starts with @startuml (or @startmindmap, @startgantt).", 1, 1);
|
|
51
|
+
for (let index = start + 1; index < raw.length; index++) {
|
|
52
|
+
if (/^\s*@end\w*/i.test(raw[index])) {
|
|
53
|
+
end = index;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
if (/^\s*@start\w*/i.test(raw[index])) fail("diagram-unsupported", "A PlantUML source holds one diagram: draw each @start ... @end block as its own diagram.", index + 1, 1);
|
|
57
|
+
}
|
|
58
|
+
if (end === raw.length) fail("diagram-syntax", `The diagram is not closed with @end${kind}.`, raw.length, 1);
|
|
59
|
+
for (let index = end + 1; index < raw.length; index++) {
|
|
60
|
+
if (raw[index].trim() && !/^\s*'/.test(raw[index])) fail("diagram-unsupported", "A PlantUML source holds one diagram: draw each @start ... @end block as its own diagram.", index + 1, 1);
|
|
61
|
+
}
|
|
62
|
+
const lines = [];
|
|
63
|
+
let comment = false;
|
|
64
|
+
for (let index = start + 1; index < end; index++) {
|
|
65
|
+
let text = raw[index];
|
|
66
|
+
if (comment) {
|
|
67
|
+
const close = text.indexOf("'/");
|
|
68
|
+
if (close < 0) continue;
|
|
69
|
+
text = text.slice(close + 2);
|
|
70
|
+
comment = false;
|
|
71
|
+
}
|
|
72
|
+
for (; ; ) {
|
|
73
|
+
const open = text.indexOf("/'");
|
|
74
|
+
if (open < 0) break;
|
|
75
|
+
const close = text.indexOf("'/", open + 2);
|
|
76
|
+
if (close < 0) {
|
|
77
|
+
text = text.slice(0, open);
|
|
78
|
+
comment = true;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
text = text.slice(0, open) + text.slice(close + 2);
|
|
82
|
+
}
|
|
83
|
+
if (/^\s*'/.test(text)) continue;
|
|
84
|
+
if (text.length > MAX_LINE) fail("diagram-limit", `A line is longer than ${MAX_LINE} characters; split it.`, index + 1, 1);
|
|
85
|
+
lines.push({ text: text.trim().replace(/\s{2,}/g, " "), line: index + 1, indent: /^[ \t]*/.exec(text)[0].replace(/\t/g, " ").length });
|
|
86
|
+
}
|
|
87
|
+
return { kind, lines };
|
|
88
|
+
}
|
|
89
|
+
var RELATION_AFTER = /^(?:(?:[<xo*#+^{}()]{1,3}[-.=~]+|[-.=~]+)(?:[>\\/xo|*#+^{}()[\]]|\s|$)|:)/;
|
|
90
|
+
function statement(text, keyword) {
|
|
91
|
+
const match = keyword.exec(text);
|
|
92
|
+
if (!match) return void 0;
|
|
93
|
+
const rest = text.slice(match[0].length).trim();
|
|
94
|
+
return RELATION_AFTER.test(rest) ? void 0 : rest;
|
|
95
|
+
}
|
|
96
|
+
var STYLED = [/^(?:skinparam|mainframe|hide|show|caption)\s+(?=\S)/i, /^scale\s+(?=(?:max\s+)?\d)/i, /^autoactivate\s+(?=(?:on|off)$)/i, /^(?:(?:left|right|center)\s+)?(?:header|footer)\s+(?=\S)/i];
|
|
97
|
+
var isStyling = (text) => /^(?:(?:top\s+to\s+bottom|left\s+to\s+right)\s+direction|allow_?mixing|(?:!pragma|!theme|set\s+namespaceseparator)\s+\S.*)$/i.test(text) || STYLED.some((pattern) => statement(text, pattern) !== void 0);
|
|
98
|
+
function strip(lines) {
|
|
99
|
+
const kept = [];
|
|
100
|
+
let title, direction;
|
|
101
|
+
const closer = (from, closing) => {
|
|
102
|
+
for (let at = from + 1; at < lines.length; at++) if (closing.test(lines[at].text)) return at;
|
|
103
|
+
return -1;
|
|
104
|
+
};
|
|
105
|
+
for (let index = 0; index < lines.length; index++) {
|
|
106
|
+
const { text, line } = lines[index];
|
|
107
|
+
if (!text) continue;
|
|
108
|
+
if (/^!(include|includeurl|includesub|import|define|definelong|undef|function|procedure|unquoted|if|ifdef|ifndef|else|endif|while|foreach|log|dump|assert|startsub|endsub|\$)/i.test(text) || /^\$\w+\s*=/.test(text)) {
|
|
109
|
+
fail("diagram-unsupported", `OPF does not run PlantUML's preprocessor (${text.split(/\s/)[0]}); write the diagram out in full.`, line, 1);
|
|
110
|
+
}
|
|
111
|
+
if (/^left\s+to\s+right\s+direction$/i.test(text)) {
|
|
112
|
+
direction = "LR";
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (/^top\s+to\s+bottom\s+direction$/i.test(text)) {
|
|
116
|
+
direction = "TB";
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (/^<style>/i.test(text)) {
|
|
120
|
+
if (!/<\/style>/i.test(text)) {
|
|
121
|
+
const end = closer(index, /<\/style>/i);
|
|
122
|
+
if (end < 0) fail("diagram-syntax", "A <style> block is not closed with </style>.", line, 1);
|
|
123
|
+
index = end;
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (/^skinparam\s+\S/i.test(text) && statement(text, /^skinparam\s+/i) !== void 0) {
|
|
128
|
+
if (/\{$/.test(text)) {
|
|
129
|
+
const end = closer(index, /^\}$/);
|
|
130
|
+
if (end < 0) fail("diagram-syntax", "A skinparam block is not closed with }.", line, 1);
|
|
131
|
+
index = end;
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (/^(hide|show)\s+(@|<<)/i.test(text)) fail("diagram-unsupported", "hide of unlinked elements or of a stereotype is not drawn; leave those elements out.", line, 1);
|
|
136
|
+
if (/^title\s*$/i.test(text)) {
|
|
137
|
+
const end = closer(index, /^end\s*title$/i);
|
|
138
|
+
if (end >= 0) {
|
|
139
|
+
title = lines.slice(index + 1, end).map((entry) => entry.text).join(" ").trim();
|
|
140
|
+
index = end;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const titled2 = statement(text, /^title\s+(?=\S)/i);
|
|
145
|
+
if (titled2 !== void 0) {
|
|
146
|
+
title = plainText(titled2);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (/^legend(?:\s+(?:left|right|center|top|bottom))*$/i.test(text)) {
|
|
150
|
+
const end = closer(index, /^end\s*legend$/i);
|
|
151
|
+
if (end >= 0) {
|
|
152
|
+
index = end;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const block = /^(?:(?:left|right|center)\s+)?(header|footer|caption)$/i.exec(text);
|
|
157
|
+
if (block) {
|
|
158
|
+
const end = closer(index, new RegExp(String.raw`^end\s*${block[1].toLowerCase()}$`, "i"));
|
|
159
|
+
if (end >= 0) {
|
|
160
|
+
index = end;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (isStyling(text)) continue;
|
|
165
|
+
kept.push(lines[index]);
|
|
166
|
+
}
|
|
167
|
+
return { lines: kept, ...title ? { title } : {}, ...direction ? { direction } : {} };
|
|
168
|
+
}
|
|
169
|
+
function plainText(text) {
|
|
170
|
+
return text.replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/<\/?(b|i|u|s|font|color|size|back|strike|del|sup|sub|w|plain)\b[^<>]*>/gi, "").replace(/\*\*(.+?)\*\*/g, "$1").replace(/\/\/(.+?)\/\//g, "$1").replace(/""(.+?)""/g, "$1").replace(/__(.+?)__/g, "$1").replace(/~~(.+?)~~/g, "$1").trim();
|
|
171
|
+
}
|
|
172
|
+
var unquote = (text) => /^".*"$/.test(text.trim()) ? text.trim().slice(1, -1) : text.trim();
|
|
173
|
+
function quoted(text) {
|
|
174
|
+
return text.replace(/[#"<>&\\`]/g, (char) => ({ "#": "#35;", '"': "#quot;", "<": "#lt;", ">": "#gt;", "&": "#amp;", "\\": "#92;", "`": "#96;" })[char]).split("\n").join("<br>");
|
|
175
|
+
}
|
|
176
|
+
function bare(text) {
|
|
177
|
+
return text.replace(/[#;<>&{}\\"`]/g, (char) => ({ "#": "#35;", ";": "#59;", "<": "#lt;", ">": "#gt;", "&": "#amp;", "{": "#123;", "}": "#125;", "\\": "#92;", '"': "#quot;", "`": "#96;" })[char]).split("\n").join("<br>");
|
|
178
|
+
}
|
|
179
|
+
var labelled = (text) => bare(text).replace(/:/g, "#58;");
|
|
180
|
+
var betweenDashes = (text) => bare(text).replace(/['()[\]:-]/g, (char) => `#${char.charCodeAt(0)};`);
|
|
181
|
+
function ganttName(text) {
|
|
182
|
+
const name = bare(text).replace(/[:%]/g, (char) => `#${char.charCodeAt(0)};`);
|
|
183
|
+
return /^(?:title|section|dateformat|axisformat|excludes|includes|todaymarker|tickinterval|weekday|weekend|click|acctitle|accdescr|inclusiveenddates|topaxis)(?![\w])/i.test(name) ? `#${name.charCodeAt(0)};${name.slice(1)}` : name;
|
|
184
|
+
}
|
|
185
|
+
var yamlQuoted = (text) => `'${text.replace(/\s*\n\s*/g, " ").replace(/'/g, "''")}'`;
|
|
186
|
+
var titled = (title, header) => title ? `---
|
|
187
|
+
title: ${yamlQuoted(title)}
|
|
188
|
+
---
|
|
189
|
+
${header}` : header;
|
|
190
|
+
var Ids = class {
|
|
191
|
+
constructor(prefix = "n") {
|
|
192
|
+
this.prefix = prefix;
|
|
193
|
+
}
|
|
194
|
+
prefix;
|
|
195
|
+
ids = /* @__PURE__ */ new Map();
|
|
196
|
+
used = /* @__PURE__ */ new Set();
|
|
197
|
+
of(name) {
|
|
198
|
+
let id = this.ids.get(name);
|
|
199
|
+
if (id) return id;
|
|
200
|
+
if (/^[A-Za-z][A-Za-z0-9_]{0,40}$/.test(name) && !RESERVED.has(name.toLowerCase()) && !this.used.has(name)) id = name;
|
|
201
|
+
else {
|
|
202
|
+
let index = this.ids.size;
|
|
203
|
+
while (this.used.has(`${this.prefix}${index}`)) index++;
|
|
204
|
+
id = `${this.prefix}${index}`;
|
|
205
|
+
}
|
|
206
|
+
this.used.add(id);
|
|
207
|
+
this.ids.set(name, id);
|
|
208
|
+
return id;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var RESERVED = /* @__PURE__ */ new Set(["end", "graph", "flowchart", "subgraph", "style", "classdef", "class", "click", "linkstyle", "direction", "call", "href", "default", "interpolate", "acctitle", "accdescr", "callback", "td", "tb", "bt", "rl", "lr", "note", "state", "participant", "actor", "as", "loop", "alt", "else", "opt", "par", "and", "rect", "critical", "break", "box", "activate", "deactivate", "create", "destroy", "autonumber", "title", "section", "namespace", "over", "left", "right", "of", "for", "systemboundary", "usecase", "root", "option"]);
|
|
212
|
+
var DECLARED_NAME = String.raw`(?:"[^"]+"|\[[^\]]+\]|\([^)]+\)|:[^:]+:|[\w$\u0080-\uFFFF][\w.$\u0080-\uFFFF]*)`;
|
|
213
|
+
var COMPONENT_DECLARATION = new RegExp(String.raw`^(component|interface|database|node|cloud|artifact|file|folder|frame|package|queue|storage|actor|person|card|agent|collections|stack|hexagon|label|boundary|control|entity|rectangle|usecase|port|portin|portout)\s+(${DECLARED_NAME})(?:\s+as\s+("[^"]+"|[\w.]+))?\s*(\{)?$`, "iu");
|
|
214
|
+
var COMPONENT_KEYWORDS = /* @__PURE__ */ new Set(["component", "node", "cloud", "artifact", "folder", "frame", "storage", "card", "file", "agent", "stack", "port", "portin", "portout", "hexagon"]);
|
|
215
|
+
var FALLBACK_COMPONENT_KEYWORDS = /* @__PURE__ */ new Set(["interface", "database", "queue", "package", "rectangle"]);
|
|
216
|
+
var STATE_DECLARATION = /^state\s+("[^"]+"|[\w.]+)(?:\s+as\s+("[^"]+"|[\w.]+))?\s*(<<\s*(\w+)\s*>>)?\s*(\{)?\s*(?::\s*(.*))?$/i;
|
|
217
|
+
var USECASE_DECLARATION = /^usecase\s+(?:\(([^)]+)\)|"([^"]+)"|([\w.]+))(?:\s+as\s+(?:\(([^)]+)\)|"([^"]+)"|([\w.]+)))?$/i;
|
|
218
|
+
var PARTICIPANT_KEYWORDS = /^(participant|actor|boundary|control|entity|database|collections|queue)\s+(?=\S)/i;
|
|
219
|
+
var plainDeclaration = (text) => text.replace(/\s+#\S+(\s*\{)?$/, "$1").replace(/\s*<<[^<>]*>>/g, "").trim();
|
|
220
|
+
function detect(kind, lines) {
|
|
221
|
+
if (kind === "mindmap") return "mindmap";
|
|
222
|
+
if (kind === "gantt") return "gantt";
|
|
223
|
+
if (kind !== "uml") fail("diagram-unsupported", `OPF does not draw PlantUML ${OTHER_KINDS[kind] ?? `@start${kind}`} diagrams; it draws sequence, class, state, activity, use case, component and deployment diagrams, mind maps and gantt charts.`, 1, 1);
|
|
224
|
+
const outside = [];
|
|
225
|
+
for (let at = 0, inBody = false; at < lines.length; at++) {
|
|
226
|
+
const text = lines[at].text;
|
|
227
|
+
if (inBody) {
|
|
228
|
+
inBody = text !== "}";
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
outside.push(lines[at]);
|
|
232
|
+
const declaration = CLASS_DECLARATION.exec(text);
|
|
233
|
+
if (declaration?.[9] && !declaration[9].includes("}")) inBody = true;
|
|
234
|
+
}
|
|
235
|
+
const texts = outside.map((line) => line.text);
|
|
236
|
+
const any = (pattern) => texts.some((text) => pattern.test(text));
|
|
237
|
+
const refuse = (what, pattern) => {
|
|
238
|
+
const at = lines.find((line) => pattern.test(line.text));
|
|
239
|
+
if (at) fail("diagram-unsupported", `OPF does not draw PlantUML ${what}; it draws sequence, class, state, activity, use case, component and deployment diagrams, mind maps and gantt charts.`, at.line, 1);
|
|
240
|
+
};
|
|
241
|
+
refuse("timing diagrams", /^(?:robust|concise|clock|binary|analog)\s+(?:"[^"]*"|[\w.]+)(?:\s+(?:as|with|is)\b.*)?$/i);
|
|
242
|
+
refuse("object diagrams", /^(object|map)\s+("[^"]*"|\w+)(\s+as\s+\w+)?\s*(\{|$)/i);
|
|
243
|
+
refuse("network diagrams", /^nwdiag\s*\{/i);
|
|
244
|
+
refuse("ArchiMate diagrams", /^archimate\s+(?:#\S+\s+)?"/i);
|
|
245
|
+
refuse("entity relationship diagrams (write them in Mermaid)", /^entity\s+("[^"]*"|\w+)(\s+as\s+\w+)?\s*\{/i);
|
|
246
|
+
if (any(/^\(\*\)/) || any(/-->\s*\(\*\)/)) refuse("legacy activity diagrams (write the activity with start, :action; and stop)", /\(\*\)/);
|
|
247
|
+
if (any(/^(start|stop|kill|detach)$/i) || any(/^:[^:]*$/) || any(/^:[\s\S]*;$/) || any(/^(if\s*\(.*\)\s*(is\s*\(.*\)\s*)?then\b|while\s*\(|repeat\s*$|fork\s*$)/i) || any(/^partition\s+(?:"[^"]+"|[^\s{]+)(?:\s+#\S+)?\s*\{?$/i) || any(/^\|[^|]+\|$/)) return "activity";
|
|
248
|
+
const declared = outside.map((line) => COMPONENT_DECLARATION.exec(plainDeclaration(line.text))).filter((match) => match !== null);
|
|
249
|
+
const component2 = any(/^\[[\w$\u0080-\uFFFF][^\]\[]*\]/) || declared.some((match) => COMPONENT_KEYWORDS.has(match[1].toLowerCase())) || any(/^\(\)\s/);
|
|
250
|
+
const classes = outside.some((line) => {
|
|
251
|
+
const match = CLASS_DECLARATION.exec(line.text);
|
|
252
|
+
const word = match?.[1]?.toLowerCase();
|
|
253
|
+
return !!match && !["entity", "circle", "diamond"].includes(word) && (word !== "interface" || !!match[9]);
|
|
254
|
+
});
|
|
255
|
+
const usecaseName = (name) => /^\([^()*]+\)$/.test(name);
|
|
256
|
+
const cases = any(USECASE_DECLARATION) || any(/^\([^()*]+\)(\s|$)/) || any(/^(actor\s+)?:[^:]+:/) || outside.some((line) => {
|
|
257
|
+
const link = readLink(line.text);
|
|
258
|
+
return !!link && (usecaseName(link.from) || usecaseName(link.to));
|
|
259
|
+
});
|
|
260
|
+
if (classes && !component2) return "class";
|
|
261
|
+
if (cases && !component2) return "usecase";
|
|
262
|
+
if (any(/\[\*\]/) || any(STATE_DECLARATION)) return "state";
|
|
263
|
+
if (component2) return "component";
|
|
264
|
+
const classArrow = (text) => /(<\|--|--\|>|\*--|--\*|o--|--o|<\|\.\.|\.\.\|>)/.test(text.replace(/\s*:.*$/, ""));
|
|
265
|
+
if (outside.some((line) => classArrow(line.text)) && !any(PARTICIPANT_KEYWORDS)) return "class";
|
|
266
|
+
if (any(PARTICIPANT_KEYWORDS) || any(/^("[^"]+"|[\w.]+)\s*(?:<{1,2}|[xo]<{0,2})?-{1,2}(?:\[[^\]]*\])?(?:[>\\/]{1,2})?[xo]?\s*("[^"]+"|[\w.]+)\s*(?:\+\+|--|\*\*|!!)?\s*(?::|$)/) || any(/^(activate|deactivate|autonumber|alt|loop|opt|par|group)(\s|$)/i)) {
|
|
267
|
+
if (any(/^actor\b/i) && any(/^(rectangle|package)\b[^{]*\{/i) && !any(/^(participant|boundary|control|collections|queue)\b/i)) return "usecase";
|
|
268
|
+
return "sequence";
|
|
269
|
+
}
|
|
270
|
+
if (declared.some((match) => FALLBACK_COMPONENT_KEYWORDS.has(match[1].toLowerCase()))) return "component";
|
|
271
|
+
return fail("diagram-unsupported", "OPF could not tell which PlantUML diagram this is; it draws sequence, class, state, activity, use case, component and deployment diagrams, mind maps and gantt charts.", lines[0]?.line ?? 1, 1);
|
|
272
|
+
}
|
|
273
|
+
var NAME = String.raw`(?:"[^"]{1,200}"|\[[^\]]{1,200}\]|\(\)\s?"?[^"\s]{1,120}"?|\([^)]{1,200}\)|:[^:]{1,200}:|[\w$\u0080-\uFFFF][\w.$\u0080-\uFFFF]{0,119}|\[\*\])`;
|
|
274
|
+
var ARROW = String.raw`(<\|?|<<|\*|o|#|x|\}|\{|\+|\^|\(0?|0?\))?([-.=~]{1,40})(?:\[([^\]]{0,100})\](up|down|left|right|u|d|l|r)?([-.=~]{0,40})|(up|down|left|right|u|d|l|r)([-.=~]{0,40}))?(\|>|>>|>|\*|o|#|x|\{|\}|\+|\^|\)0?|0?\()?`;
|
|
275
|
+
var LINK = new RegExp(String.raw`^(${NAME})\s*(?:"([^"]{0,200})"\s*)?${ARROW}\s*(?:"([^"]{0,200})"\s*)?(${NAME})\s*(?::\s*(.*))?$`, "u");
|
|
276
|
+
function readLink(text) {
|
|
277
|
+
const match = LINK.exec(text);
|
|
278
|
+
if (!match) return void 0;
|
|
279
|
+
const from = match[1], leftLabel = match[2], left = match[3] ?? "", style = match[5] ?? "", right = match[10] ?? "", rightLabel = match[11], to = match[12], label = match[13];
|
|
280
|
+
const body = (match[4] ?? "") + (match[7] ?? match[9] ?? "");
|
|
281
|
+
if (!/[-.=~]/.test(body)) return void 0;
|
|
282
|
+
const line = /hidden/i.test(style) ? "hidden" : body.includes(".") || /dashed|dotted/i.test(style) ? "dotted" : body.includes("=") || /bold|thickness=[2-9]/i.test(style) ? "bold" : "solid";
|
|
283
|
+
return {
|
|
284
|
+
from,
|
|
285
|
+
to,
|
|
286
|
+
left,
|
|
287
|
+
right,
|
|
288
|
+
line,
|
|
289
|
+
length: Math.max(1, body.replace(/[^-.=~]/g, "").length - 1),
|
|
290
|
+
...label?.trim() ? { label: plainText(label.replace(/\s+[<>]$|^[<>]\s+/g, "")) } : {},
|
|
291
|
+
...leftLabel ? { leftLabel: plainText(leftLabel) } : {},
|
|
292
|
+
...rightLabel ? { rightLabel: plainText(rightLabel) } : {}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
var nest = (depth, line) => {
|
|
296
|
+
if (depth > DIAGRAM_MAX_NESTING) fail("diagram-limit", `Blocks are nested more than ${DIAGRAM_MAX_NESTING} deep; flatten the diagram or split it.`, line.line, 1);
|
|
297
|
+
};
|
|
298
|
+
var noNote = (line, to) => fail("diagram-unsupported", `A note on a link or a floating note is not drawn; attach it to ${to} with note left of or right of.`, line.line, 1);
|
|
299
|
+
var unknown = (line, what) => fail("diagram-syntax", `OPF cannot read this line of a PlantUML ${what} diagram: ${JSON.stringify(line.text.length > 60 ? `${line.text.slice(0, 57)}...` : line.text)}.`, line.line, 1);
|
|
300
|
+
function noteBlock(lines, index, first) {
|
|
301
|
+
const body = [];
|
|
302
|
+
let at = index;
|
|
303
|
+
while (++at < lines.length && !/^end\s*(note|hnote|rnote)\b/i.test(lines[at].text)) body.push(lines[at].text);
|
|
304
|
+
if (at >= lines.length) fail("diagram-syntax", "A note is not closed with end note.", lines[index].line, 1);
|
|
305
|
+
return { text: plainText(body.join("\n")), end: at };
|
|
306
|
+
}
|
|
307
|
+
var PARTICIPANT = /^(participant|actor|boundary|control|entity|database|collections|queue)\s+(?:"([^"]+)"\s+as\s+([\w.]+)|([\w.]+)\s+as\s+"([^"]+)"|([\w.]+)\s+as\s+([\w.]+)|"([^"]+)"|([\w.\u0080-\uFFFF]+))\s*(<<[^<>]*>>)?\s*(#\S+)?\s*(order\s+-?\d+)?\s*$/iu;
|
|
308
|
+
var MESSAGE = /^(\[|"[^"]+"|[\w.\u0080-\uFFFF]+)?\s*(\[?)([xo]?<{1,2}|x|o)?(-{1,2})(\[[^\]]*\])?((?:>{1,2}|\\{1,2}|\/{1,2})[xo]?|x|o)?(\]?)\s*(\]|"[^"]+"|[\w.\u0080-\uFFFF]+)?\s*(\+\+|--|\*\*|!!)?\s*(?::\s*(.*))?$/u;
|
|
309
|
+
function sequence(lines, title, maxEdges) {
|
|
310
|
+
const out = [];
|
|
311
|
+
const ids = new Ids("p");
|
|
312
|
+
const declared = /* @__PURE__ */ new Set();
|
|
313
|
+
const order = [];
|
|
314
|
+
const declare = (name, kind = "participant", alias) => {
|
|
315
|
+
const id = ids.of(name);
|
|
316
|
+
if (declared.has(id)) return id;
|
|
317
|
+
declared.add(id);
|
|
318
|
+
order.push(id);
|
|
319
|
+
const label = alias ?? name;
|
|
320
|
+
const meta = [];
|
|
321
|
+
if (kind !== "participant" && kind !== "actor") meta.push(`"type": "${kind}"`);
|
|
322
|
+
if (label !== id) meta.push(`"alias": ${JSON.stringify(bare(label))}`);
|
|
323
|
+
out.push(` ${kind === "actor" ? "actor" : "participant"} ${id}${meta.length ? `@{ ${meta.join(", ")} }` : ""}`);
|
|
324
|
+
return id;
|
|
325
|
+
};
|
|
326
|
+
const frames = [];
|
|
327
|
+
const open = (kind, current) => {
|
|
328
|
+
nest(frames.push(kind), current);
|
|
329
|
+
};
|
|
330
|
+
let messages = 0, last, groupLabel;
|
|
331
|
+
const calls = [];
|
|
332
|
+
const lastCall = (accept) => {
|
|
333
|
+
for (let at = calls.length - 1; at >= 0; at--) if (accept(calls[at])) return at;
|
|
334
|
+
return -1;
|
|
335
|
+
};
|
|
336
|
+
const pendingNotes = [];
|
|
337
|
+
const flushNotes = () => {
|
|
338
|
+
if (!pendingNotes.length || !order.length) return;
|
|
339
|
+
for (const note of pendingNotes) out.push(` Note over ${order.length > 1 ? `${order[0]},${order.at(-1)}` : order[0]}: ${note}`);
|
|
340
|
+
pendingNotes.length = 0;
|
|
341
|
+
};
|
|
342
|
+
const sent = [];
|
|
343
|
+
let created;
|
|
344
|
+
const destroying = [];
|
|
345
|
+
const emit = (message, from, to, current) => {
|
|
346
|
+
flushNotes();
|
|
347
|
+
settleDestroys(from, to, current);
|
|
348
|
+
const involved = created !== void 0 && (from === created || to === created);
|
|
349
|
+
sent.push({ at: out.length, from, to, ...involved ? { creates: created } : {} });
|
|
350
|
+
if (involved) created = void 0;
|
|
351
|
+
out.push(message);
|
|
352
|
+
};
|
|
353
|
+
const settleDestroys = (from, to, current) => {
|
|
354
|
+
for (const { id, at } of destroying.splice(0)) {
|
|
355
|
+
if (from === id || to === id) continue;
|
|
356
|
+
let k = sent.length - 1;
|
|
357
|
+
while (k >= 0 && sent[k].from !== id && sent[k].to !== id) k--;
|
|
358
|
+
if (k < 0 || sent[k].creates === id) fail("diagram-unsupported", `destroy ${id} needs a message to or from it after the one that creates it.`, current.line, 1);
|
|
359
|
+
const target = sent[k].at;
|
|
360
|
+
const [line] = out.splice(at, 1);
|
|
361
|
+
out.splice(target, 0, line);
|
|
362
|
+
for (let j = k; j < sent.length; j++) sent[j].at++;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
for (let index = 0; index < lines.length; index++) {
|
|
366
|
+
const current = lines[index];
|
|
367
|
+
const { text } = current;
|
|
368
|
+
let match;
|
|
369
|
+
let rest;
|
|
370
|
+
match = PARTICIPANT.exec(text);
|
|
371
|
+
if (match) {
|
|
372
|
+
const kind = match[1].toLowerCase();
|
|
373
|
+
const name = match[3] ?? match[4] ?? match[7] ?? match[8] ?? match[9];
|
|
374
|
+
const label = match[2] ?? match[5] ?? match[6] ?? void 0;
|
|
375
|
+
declare(name, kind, label && label !== name ? plainText(label) : void 0);
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (/^autonumber$/i.test(text)) {
|
|
379
|
+
out.push(" autonumber");
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (statement(text, /^autonumber\s+(?=\S)/i) !== void 0) fail("diagram-unsupported", "autonumber takes no start, step or format here; write plain autonumber.", current.line, 1);
|
|
383
|
+
match = /^(activate|deactivate|destroy)\s+("[^"]+"|[\w.]+)/i.exec(text);
|
|
384
|
+
if (match) {
|
|
385
|
+
const verb = match[1].toLowerCase(), id = declare(unquote(match[2]));
|
|
386
|
+
if (verb === "activate") {
|
|
387
|
+
const at = lastCall((call) => call.to === id && !call.activated);
|
|
388
|
+
if (at >= 0) calls[at].activated = true;
|
|
389
|
+
} else if (verb === "deactivate") {
|
|
390
|
+
const at = lastCall((call) => call.to === id && call.activated);
|
|
391
|
+
if (at >= 0) calls[at].activated = false;
|
|
392
|
+
}
|
|
393
|
+
if (verb === "destroy") destroying.push({ id, at: out.length });
|
|
394
|
+
out.push(` ${verb} ${id}`);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
match = /^create\s+(?:(participant|actor|boundary|control|entity|database|collections|queue)\s+)?("[^"]+"|[\w.]+)/i.exec(text);
|
|
398
|
+
if (match) {
|
|
399
|
+
const name = unquote(match[2]);
|
|
400
|
+
out.push(` create ${match[1]?.toLowerCase() === "actor" ? "actor" : "participant"} ${ids.of(name)}`);
|
|
401
|
+
declared.add(ids.of(name));
|
|
402
|
+
order.push(ids.of(name));
|
|
403
|
+
created = ids.of(name);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
rest = statement(text, /^box\b/i);
|
|
407
|
+
if (rest !== void 0) {
|
|
408
|
+
out.push(` box ${bare(plainText(unquote(/^("[^"]*"|[^#]*)/.exec(rest)[1])) || " ")}`);
|
|
409
|
+
open("box", current);
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (/^end\s*box$/i.test(text)) {
|
|
413
|
+
out.push(" end");
|
|
414
|
+
frames.pop();
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
match = /^(alt|opt|loop|par|break|critical|group)\b/i.exec(text);
|
|
418
|
+
rest = match ? statement(text, /^(?:alt|opt|loop|par|break|critical|group)\b/i) : void 0;
|
|
419
|
+
if (match && rest !== void 0) {
|
|
420
|
+
const kind = match[1].toLowerCase(), label = plainText(rest.replace(/^#\S+\s*/, "").replace(/\[([^\]]*)\]/, "$1"));
|
|
421
|
+
if (kind === "group") {
|
|
422
|
+
out.push(" rect");
|
|
423
|
+
groupLabel = label || void 0;
|
|
424
|
+
} else out.push(` ${kind}${label ? ` ${bare(label)}` : ""}`);
|
|
425
|
+
open(kind, current);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
rest = statement(text, /^else\b/i);
|
|
429
|
+
if (rest !== void 0) {
|
|
430
|
+
const frame = frames.at(-1);
|
|
431
|
+
if (!frame || !["alt", "par", "critical"].includes(frame)) unknown(current, "sequence");
|
|
432
|
+
out.push(` ${frame === "par" ? "and" : frame === "critical" ? "option" : "else"}${rest ? ` ${bare(plainText(rest.replace(/^#\S+\s*/, "")))}` : ""}`);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (/^end$/i.test(text)) {
|
|
436
|
+
if (!frames.length) unknown(current, "sequence");
|
|
437
|
+
frames.pop();
|
|
438
|
+
out.push(" end");
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
match = /^(note|hnote|rnote)\s+(left|right|over)(?:\s+of)?\s*([^:]*?)\s*(#\S+)?\s*(?::\s*(.*))?$/i.exec(text);
|
|
442
|
+
if (match) {
|
|
443
|
+
const side = match[2].toLowerCase();
|
|
444
|
+
let body = match[5];
|
|
445
|
+
if (body === void 0) {
|
|
446
|
+
const block = noteBlock(lines, index);
|
|
447
|
+
body = block.text;
|
|
448
|
+
index = block.end;
|
|
449
|
+
}
|
|
450
|
+
const names = match[3].split(",").map((name) => unquote(name)).filter(Boolean);
|
|
451
|
+
const targets = names.length ? names.map((name) => declare(name)) : last ? [last.to] : order.slice(0, 1);
|
|
452
|
+
if (!targets.length) unknown(current, "sequence");
|
|
453
|
+
out.push(` Note ${side === "over" ? "over" : `${side} of`} ${(side === "over" ? targets.slice(0, 2) : targets.slice(0, 1)).join(",")}: ${bare(plainText(body)) || " "}`);
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
match = /^ref\s+over\s+([^:]+?)\s*(?::\s*(.*))?$/i.exec(text);
|
|
457
|
+
if (match) {
|
|
458
|
+
let body = match[2];
|
|
459
|
+
if (body === void 0) {
|
|
460
|
+
const block = noteBlock(lines.map((line) => ({ ...line, text: line.text.replace(/^end\s*ref\b/i, "end note") })), index);
|
|
461
|
+
body = block.text;
|
|
462
|
+
index = block.end;
|
|
463
|
+
}
|
|
464
|
+
const targets = match[1].split(",").map((name) => declare(unquote(name)));
|
|
465
|
+
out.push(` Note over ${targets.slice(0, 2).join(",")}: ref ${bare(plainText(body))}`);
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
match = /^={2,}\s*(.*?)\s*={2,}$/.exec(text) ?? /^\.{3}\s*(.+?)\s*\.{3}$/.exec(text);
|
|
469
|
+
if (match) {
|
|
470
|
+
pendingNotes.push(bare(plainText(match[1])) || " ");
|
|
471
|
+
flushNotes();
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (/^(\.{3,}|\|{3}|\|\|\d+\|\|)$/.test(text)) continue;
|
|
475
|
+
rest = statement(text, /^return\b/i);
|
|
476
|
+
if (rest !== void 0) {
|
|
477
|
+
let at = lastCall((call2) => call2.activated);
|
|
478
|
+
if (at < 0) at = calls.length - 1;
|
|
479
|
+
if (at < 0) fail("diagram-syntax", "return has no message to answer.", current.line, 1);
|
|
480
|
+
const call = calls[at];
|
|
481
|
+
calls.length = at;
|
|
482
|
+
emit(` ${call.to}-->>${call.activated ? "-" : ""}${call.from}: ${bare(plainText(rest)) || " "}`, call.to, call.from, current);
|
|
483
|
+
last = { from: call.to, to: call.from };
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
match = MESSAGE.exec(text);
|
|
487
|
+
if (match && match[4] && (match[1] || match[8])) {
|
|
488
|
+
const [, rawFrom, openLeft, leftHead = "", dashes = "", , rightHead = "", openRight, rawTo, activation, label] = match;
|
|
489
|
+
if (rawFrom === "[" || rawTo === "]" || openLeft || openRight) fail("diagram-unsupported", "A message from or to outside the diagram ([-> or ->]) is not drawn; name the participant it comes from or goes to.", current.line, 1);
|
|
490
|
+
if (!rawFrom || !rawTo) unknown(current, "sequence");
|
|
491
|
+
const heads = `${leftHead}${rightHead}`;
|
|
492
|
+
if (heads.includes("o")) fail("diagram-unsupported", "A circle end on a message (->o, o->) is not drawn; use -> or ->x.", current.line, 1);
|
|
493
|
+
if (leftHead && rightHead && /[x\\/]/.test(heads)) fail("diagram-unsupported", "A double-headed message with a cross or a half head is not drawn; write two.", current.line, 1);
|
|
494
|
+
if (activation === "**") fail("diagram-unsupported", "A ** after a message is not drawn; write create before it.", current.line, 1);
|
|
495
|
+
let from = declare(unquote(rawFrom)), to = declare(unquote(rawTo));
|
|
496
|
+
let head = rightHead;
|
|
497
|
+
const dashed = dashes.length > 1 || /dashed|dotted/i.test(match[5] ?? "");
|
|
498
|
+
if (leftHead && !rightHead) {
|
|
499
|
+
[from, to] = [to, from];
|
|
500
|
+
head = leftHead.includes("x") ? "x" : leftHead.length > 1 ? ">>" : ">";
|
|
501
|
+
}
|
|
502
|
+
const both = !!leftHead && !!rightHead;
|
|
503
|
+
const arrow = both ? dashed ? "<<-->>" : "<<->>" : head.includes("x") ? dashed ? "--x" : "-x" : head === ">>" || head.startsWith("\\") || head.startsWith("/") ? dashed ? "--)" : "-)" : dashed ? "-->>" : "->>";
|
|
504
|
+
const act = activation === "++" ? "+" : activation === "--" ? "-" : "";
|
|
505
|
+
flushNotes();
|
|
506
|
+
if (groupLabel !== void 0) {
|
|
507
|
+
out.push(` Note over ${from === to ? from : `${from},${to}`}: ${bare(groupLabel)}`);
|
|
508
|
+
groupLabel = void 0;
|
|
509
|
+
}
|
|
510
|
+
if (activation === "!!") out.push(` destroy ${to}`);
|
|
511
|
+
emit(` ${from}${arrow}${act}${to}: ${bare(plainText(label ?? "")) || " "}`, from, to, current);
|
|
512
|
+
if (activation === "--") {
|
|
513
|
+
const at = lastCall((call) => call.to === from && call.activated);
|
|
514
|
+
if (at >= 0) calls[at].activated = false;
|
|
515
|
+
}
|
|
516
|
+
if (!dashed && !both && !head.includes("x") && activation !== "--" && activation !== "!!") calls.push({ from, to, activated: activation === "++" });
|
|
517
|
+
last = { from, to };
|
|
518
|
+
if (++messages > maxEdges) fail("diagram-limit", `The diagram has more than ${maxEdges} messages.`);
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
unknown(current, "sequence");
|
|
522
|
+
}
|
|
523
|
+
if (frames.length) fail("diagram-syntax", `A ${frames.at(-1)} block is not closed with end.`);
|
|
524
|
+
if (!order.length) fail("diagram-syntax", "The sequence diagram has no participants.");
|
|
525
|
+
flushNotes();
|
|
526
|
+
return `${titled(void 0, "sequenceDiagram")}
|
|
527
|
+
${title ? ` title ${bare(title)}
|
|
528
|
+
` : ""}${out.join("\n")}`;
|
|
529
|
+
}
|
|
530
|
+
var CLASS_DECLARATION = /^(abstract\s+class|abstract|class|interface|enum|annotation|struct|exception|protocol|record|metaclass|stereotype|dataclass|entity|circle|diamond)\s+("[^"]+"|[\w.$\u0080-\uFFFF]+)(?:\s+as\s+("[^"]+"|[\w.$]+))?\s*(<(?!<)[^<>]*(?:<[^<>]*>[^<>]*)*>)?\s*(<<[^<>]*>>)?\s*(#\S+)?\s*(?:extends\s+([\w.,\s]+?))?\s*(?:implements\s+([\w.,\s]+?))?\s*(\{.*)?$/iu;
|
|
531
|
+
var SEPARATOR = /^(?:-{2,}|\.{2,}|={2,}|_{2,})(?: .+ (?:-{2,}|\.{2,}|={2,}|_{2,}))?$/;
|
|
532
|
+
function classDiagram(lines, title, maxEdges) {
|
|
533
|
+
const out = [];
|
|
534
|
+
const ids = new Ids("c");
|
|
535
|
+
const declared = /* @__PURE__ */ new Set();
|
|
536
|
+
let relations = 0;
|
|
537
|
+
const floatingNotes = /* @__PURE__ */ new Set();
|
|
538
|
+
const name = (raw) => ids.of(unquote(raw).replace(/^\[|\]$/g, ""));
|
|
539
|
+
const declare = (raw, label, indent = " ") => {
|
|
540
|
+
const id = name(raw);
|
|
541
|
+
if (!declared.has(id)) {
|
|
542
|
+
declared.add(id);
|
|
543
|
+
const shown = unquote(raw);
|
|
544
|
+
out.push(`${indent}class ${id}${shown !== id ? `["${quoted(shown)}"]` : ""}`);
|
|
545
|
+
}
|
|
546
|
+
return id;
|
|
547
|
+
};
|
|
548
|
+
const member = (text) => {
|
|
549
|
+
let line = text.replace(/\{(static|classifier)\}\s*/i, "").replace(/\{abstract\}\s*/i, "");
|
|
550
|
+
const isStatic = /\{(static|classifier)\}/i.test(text), isAbstract = /\{abstract\}/i.test(text);
|
|
551
|
+
line = line.replace(/^([+\-#~]?\s*[^():]+\([^)]*\))\s*:\s*(.+)$/, "$1 $2");
|
|
552
|
+
return plainText(line).replace(/[<>]/g, "~").replace(/[&"{}`]/g, (char) => ({ "&": "#amp;", '"': "#quot;", "{": "#123;", "}": "#125;", "`": "#96;" })[char]).replace(/\n/g, " ") + (isStatic ? "$" : isAbstract ? "*" : "");
|
|
553
|
+
};
|
|
554
|
+
const stack = [];
|
|
555
|
+
for (let index = 0; index < lines.length; index++) {
|
|
556
|
+
const current = lines[index];
|
|
557
|
+
const { text } = current;
|
|
558
|
+
let match;
|
|
559
|
+
nest(stack.length, current);
|
|
560
|
+
const inClass = stack.at(-1)?.kind === "class" ? stack.at(-1).id : void 0;
|
|
561
|
+
if (inClass) {
|
|
562
|
+
if (/^\}$/.test(text)) {
|
|
563
|
+
stack.pop();
|
|
564
|
+
out.push(`${" ".repeat(stack.length + 1)}}`);
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
if (SEPARATOR.test(text)) continue;
|
|
568
|
+
out.push(`${" ".repeat(stack.length + 1)}${member(text)}`);
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
match = /^(package|namespace|together)\b\s*("[^"]+"|[\w.$]+)?[^{]*\{\s*$/i.exec(text);
|
|
572
|
+
if (match) {
|
|
573
|
+
if (match[1].toLowerCase() === "together" || stack.some((entry) => entry.kind === "namespace")) {
|
|
574
|
+
stack.push({ kind: "namespace" });
|
|
575
|
+
out.push("");
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
stack.push({ kind: "namespace", id: "ns", start: out.length });
|
|
579
|
+
out.push(` namespace ${unquote(match[2] ?? "Package").replace(/[^\w]/g, "_") || "Package"} {`);
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
if (/^\}$/.test(text)) {
|
|
583
|
+
const top = stack.pop();
|
|
584
|
+
if (!top) unknown(current, "class");
|
|
585
|
+
if (top.id === "ns") {
|
|
586
|
+
if (out.length - 1 === top.start) out.pop();
|
|
587
|
+
else out.push(" }");
|
|
588
|
+
}
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
match = CLASS_DECLARATION.exec(text);
|
|
592
|
+
if (match) {
|
|
593
|
+
const kind = match[1].toLowerCase().replace(/\s+/g, " ");
|
|
594
|
+
let raw = match[2], label;
|
|
595
|
+
if (match[3]) {
|
|
596
|
+
if (match[3].startsWith('"')) label = unquote(match[3]);
|
|
597
|
+
else {
|
|
598
|
+
label = unquote(raw);
|
|
599
|
+
raw = match[3];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const generic = match[4] ? `~${match[4].slice(1, -1).replace(/[<>]/g, "~")}~` : "";
|
|
603
|
+
const indent = stack.length ? " " : " ";
|
|
604
|
+
const id = name(raw);
|
|
605
|
+
if (!declared.has(id)) {
|
|
606
|
+
declared.add(id);
|
|
607
|
+
const shown = label ?? unquote(raw);
|
|
608
|
+
out.push(`${indent}class ${id}${generic}${shown !== id ? `["${quoted(shown)}"]` : ""}${match[9] ? " {" : ""}`);
|
|
609
|
+
} else if (match[9]) out.push(`${indent}class ${id} {`);
|
|
610
|
+
const stereotype = match[5] ? match[5].slice(2, -2).trim() : kind === "interface" ? "interface" : kind === "enum" ? "enumeration" : kind.startsWith("abstract") ? "abstract" : kind === "annotation" ? "annotation" : void 0;
|
|
611
|
+
if (stereotype) {
|
|
612
|
+
if (match[9]) out.push(`${indent} <<${bare(stereotype)}>>`);
|
|
613
|
+
else out.push(`${indent}<<${bare(stereotype)}>> ${id}`);
|
|
614
|
+
}
|
|
615
|
+
for (const parent of (match[7] ?? "").split(",").map((entry) => entry.trim()).filter(Boolean)) {
|
|
616
|
+
out.push(` ${declare(parent)} <|-- ${id}`);
|
|
617
|
+
relations++;
|
|
618
|
+
}
|
|
619
|
+
for (const parent of (match[8] ?? "").split(",").map((entry) => entry.trim()).filter(Boolean)) {
|
|
620
|
+
out.push(` ${declare(parent)} <|.. ${id}`);
|
|
621
|
+
relations++;
|
|
622
|
+
}
|
|
623
|
+
if (match[9]) {
|
|
624
|
+
const rest = match[9].slice(1).trim();
|
|
625
|
+
if (rest.endsWith("}")) {
|
|
626
|
+
for (const entry of rest.slice(0, -1).split(";").map((part) => part.trim()).filter(Boolean)) out.push(`${indent} ${member(entry)}`);
|
|
627
|
+
out.push(`${indent}}`);
|
|
628
|
+
} else {
|
|
629
|
+
stack.push({ kind: "class", id });
|
|
630
|
+
if (rest) out.push(`${indent} ${member(rest)}`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
match = /^note\s+(?:(left|right|top|bottom)\s+of\s+("[^"]+"|[\w.$]+)|"([^"]+)"\s+as\s+(\w+)|as\s+(\w+))\s*(#\S+)?\s*(?::\s*(.*))?$/i.exec(text);
|
|
636
|
+
if (match) {
|
|
637
|
+
let body = match[7] ?? match[3];
|
|
638
|
+
if (match[4] ?? match[5]) floatingNotes.add(match[4] ?? match[5]);
|
|
639
|
+
if (body === void 0) {
|
|
640
|
+
const block = noteBlock(lines, index);
|
|
641
|
+
body = block.text;
|
|
642
|
+
index = block.end;
|
|
643
|
+
}
|
|
644
|
+
out.push(match[2] ? ` note for ${declare(match[2])} "${quoted(plainText(body))}"` : ` note "${quoted(plainText(body))}"`);
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (/^note\s+(?:on\s+)?link\b/i.test(text)) noNote(current, "a class");
|
|
648
|
+
match = /^("[^"]+"|[\w.$]+)\s*:\s*(.+)$/u.exec(text);
|
|
649
|
+
if (match && !readLink(text)) {
|
|
650
|
+
out.push(` ${declare(match[1])} : ${member(match[2])}`);
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
const link = readLink(text);
|
|
654
|
+
if (link) {
|
|
655
|
+
if (floatingNotes.has(link.from) || floatingNotes.has(link.to)) noNote(current, "a class");
|
|
656
|
+
const from = declare(link.from), to = declare(link.to);
|
|
657
|
+
const head = (end, side) => {
|
|
658
|
+
if (end === "<|" || end === "|>" || end === "^") return side === "left" ? "<|" : "|>";
|
|
659
|
+
if (end === "*") return "*";
|
|
660
|
+
if (end === "o") return "o";
|
|
661
|
+
if (end === "<" || end === ">" || end === "<<" || end === ">>") return side === "left" ? "<" : ">";
|
|
662
|
+
return "";
|
|
663
|
+
};
|
|
664
|
+
const line = link.line === "dotted" ? ".." : "--";
|
|
665
|
+
const arrow = `${head(link.left, "left")}${line}${head(link.right, "right")}`;
|
|
666
|
+
out.push(` ${from}${link.leftLabel ? ` "${quoted(link.leftLabel)}"` : ""} ${arrow}${link.rightLabel ? ` "${quoted(link.rightLabel)}"` : ""} ${to}${link.label ? ` : ${labelled(link.label)}` : ""}`);
|
|
667
|
+
if (++relations > maxEdges) fail("diagram-limit", `The diagram has more than ${maxEdges} relations.`);
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
unknown(current, "class");
|
|
671
|
+
}
|
|
672
|
+
if (stack.length) fail("diagram-syntax", "A { block is not closed with }.");
|
|
673
|
+
if (!declared.size) fail("diagram-syntax", "The class diagram has no classes.");
|
|
674
|
+
return `${titled(title, "classDiagram")}
|
|
675
|
+
${out.filter((line) => line !== "").join("\n")}`;
|
|
676
|
+
}
|
|
677
|
+
function stateDiagram(lines, title, direction, maxEdges) {
|
|
678
|
+
const out = [];
|
|
679
|
+
const ids = new Ids("s");
|
|
680
|
+
let depth = 1, transitions = 0;
|
|
681
|
+
const state = (raw) => {
|
|
682
|
+
const name = unquote(raw);
|
|
683
|
+
if (name === "[*]") return "[*]";
|
|
684
|
+
if (/^\[H\*?\]$/.test(name) || /\[H\*?\]$/.test(name)) fail("diagram-unsupported", "History states ([H] and [H*]) are not drawn; point the transition at the state it resumes.");
|
|
685
|
+
return ids.of(name);
|
|
686
|
+
};
|
|
687
|
+
for (let index = 0; index < lines.length; index++) {
|
|
688
|
+
const current = lines[index];
|
|
689
|
+
const text = current.text.replace(/\s+#\S+(\s|$)/g, " ").replace(/\s+##\S*/g, "").trim();
|
|
690
|
+
nest(depth, current);
|
|
691
|
+
const indent = " ".repeat(depth);
|
|
692
|
+
let match;
|
|
693
|
+
match = STATE_DECLARATION.exec(text);
|
|
694
|
+
if (match) {
|
|
695
|
+
let raw = match[1], label;
|
|
696
|
+
if (match[2]) {
|
|
697
|
+
if (match[2].startsWith('"')) label = unquote(match[2]);
|
|
698
|
+
else {
|
|
699
|
+
label = unquote(raw);
|
|
700
|
+
raw = match[2];
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const id = state(raw);
|
|
704
|
+
const stereotype = match[4]?.toLowerCase();
|
|
705
|
+
if (stereotype && ["choice", "fork", "join"].includes(stereotype)) out.push(`${indent}state ${id} <<${stereotype}>>`);
|
|
706
|
+
else if (stereotype === "end") out.push(`${indent}state ${id}`);
|
|
707
|
+
else if (label && label !== id) out.push(`${indent}state "${bare(plainText(label))}" as ${id}`);
|
|
708
|
+
if (match[6]) out.push(`${indent}${id} : ${labelled(plainText(match[6]))}`);
|
|
709
|
+
if (match[5]) {
|
|
710
|
+
out.push(`${indent}state ${id} {`);
|
|
711
|
+
depth++;
|
|
712
|
+
} else if (!stereotype && !label && !match[6]) out.push(`${indent}${id}`);
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
if (/^\}$/.test(text)) {
|
|
716
|
+
if (depth <= 1) unknown(current, "state");
|
|
717
|
+
depth--;
|
|
718
|
+
out.push(`${" ".repeat(depth)}}`);
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
if (/^(--+|\|\|+)$/.test(text)) {
|
|
722
|
+
out.push(`${indent}--`);
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
match = /^note\s+(left|right|top|bottom)\s+of\s+("[^"]+"|[\w.]+)\s*(?::\s*(.*))?$/i.exec(text);
|
|
726
|
+
if (match) {
|
|
727
|
+
let body = match[3];
|
|
728
|
+
if (body === void 0) {
|
|
729
|
+
const block = noteBlock(lines, index);
|
|
730
|
+
body = block.text;
|
|
731
|
+
index = block.end;
|
|
732
|
+
}
|
|
733
|
+
const side = match[1].toLowerCase();
|
|
734
|
+
if (side !== "left" && side !== "right") noNote(current, "a state");
|
|
735
|
+
out.push(`${indent}note ${side} of ${state(match[2])} : ${labelled(plainText(body))}`);
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
if (statement(text, /^note\b/i)) noNote(current, "a state");
|
|
739
|
+
const link = readLink(text);
|
|
740
|
+
if (link) {
|
|
741
|
+
if (link.left && link.right) fail("diagram-syntax", "A state transition has one arrowhead; write two transitions for both directions.", current.line);
|
|
742
|
+
const [from, to] = link.left && !link.right ? [link.to, link.from] : [link.from, link.to];
|
|
743
|
+
out.push(`${indent}${state(from)} --> ${state(to)}${link.label ? ` : ${labelled(link.label)}` : ""}`);
|
|
744
|
+
if (++transitions > maxEdges) fail("diagram-limit", `The diagram has more than ${maxEdges} transitions.`);
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
match = /^("[^"]+"|[\w.]+)\s*:\s*(.*)$/.exec(text);
|
|
748
|
+
if (match) {
|
|
749
|
+
out.push(`${indent}${state(match[1])} : ${labelled(plainText(match[2]))}`);
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
match = /^("[^"]+"|[\w.]+)$/.exec(text);
|
|
753
|
+
if (match) {
|
|
754
|
+
out.push(`${indent}${state(match[1])}`);
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
unknown(current, "state");
|
|
758
|
+
}
|
|
759
|
+
if (depth > 1) fail("diagram-syntax", "A state block is not closed with }.");
|
|
760
|
+
return `${titled(title, "stateDiagram-v2")}
|
|
761
|
+
${direction ? ` direction ${direction}
|
|
762
|
+
` : ""}${out.join("\n")}`;
|
|
763
|
+
}
|
|
764
|
+
function activity(lines, title, maxEdges) {
|
|
765
|
+
const nodes = [], edges = [];
|
|
766
|
+
const groups = [];
|
|
767
|
+
let count = 0, tails = [], pending, group, lane;
|
|
768
|
+
const lanes = /* @__PURE__ */ new Map();
|
|
769
|
+
const node = (shape, label2) => {
|
|
770
|
+
const id = `a${count++}`;
|
|
771
|
+
nodes.push(`${id}@{ shape: ${shape}, label: "${label2 ? quoted(label2) : " "}" }`);
|
|
772
|
+
const owner = group ?? lane;
|
|
773
|
+
if (owner !== void 0) groups[owner].nodes.push(id);
|
|
774
|
+
return id;
|
|
775
|
+
};
|
|
776
|
+
const link = (from, to, label2, dotted = false) => {
|
|
777
|
+
edges.push(` ${from} ${dotted ? "-.->" : "-->"}${label2 ? `|"${quoted(label2)}"|` : ""} ${to}`);
|
|
778
|
+
if (edges.length > maxEdges) fail("diagram-limit", `The diagram has more than ${maxEdges} arrows.`);
|
|
779
|
+
};
|
|
780
|
+
const enter = (id) => {
|
|
781
|
+
for (const tail of tails) link(tail.id, id, tail.label ?? pending);
|
|
782
|
+
pending = void 0;
|
|
783
|
+
tails = [{ id }];
|
|
784
|
+
for (const frame of frames) if (frame.kind === "repeat" && frame.first === void 0) frame.first = id;
|
|
785
|
+
};
|
|
786
|
+
const frames = [];
|
|
787
|
+
const top = (kinds, current) => {
|
|
788
|
+
const frame = frames.at(-1);
|
|
789
|
+
if (!frame || !kinds.includes(frame.kind)) unknown(current, "activity");
|
|
790
|
+
return frame;
|
|
791
|
+
};
|
|
792
|
+
const label = (text) => (text ?? "").trim() ? plainText(text.trim()) : void 0;
|
|
793
|
+
for (let index = 0; index < lines.length; index++) {
|
|
794
|
+
const current = lines[index];
|
|
795
|
+
const { text } = current;
|
|
796
|
+
let match;
|
|
797
|
+
nest(frames.length, current);
|
|
798
|
+
if (/^start$/i.test(text)) {
|
|
799
|
+
enter(node("sm-circ", ""));
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
if (/^(stop|end)$/i.test(text)) {
|
|
803
|
+
enter(node("fr-circ", ""));
|
|
804
|
+
tails = [];
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
if (/^(kill|detach)$/i.test(text)) {
|
|
808
|
+
tails = [];
|
|
809
|
+
continue;
|
|
810
|
+
}
|
|
811
|
+
match = /^(#\S+)?:([\s\S]*)$/.exec(text);
|
|
812
|
+
if (match) {
|
|
813
|
+
let body = match[2];
|
|
814
|
+
while (!/[;|<>/\]}]$/.test(body) && index + 1 < lines.length) body += `
|
|
815
|
+
${lines[++index].text}`;
|
|
816
|
+
if (!/[;|<>/\]}]$/.test(body)) fail("diagram-syntax", "An action (:...) is not ended with ;.", current.line, 1);
|
|
817
|
+
const ending = body.at(-1);
|
|
818
|
+
const shape = ending === "|" ? "fr-rect" : ending === "<" || ending === ">" ? "flag" : ending === "/" ? "lean-r" : ending === "]" ? "rect" : ending === "}" ? "st-rect" : "rounded";
|
|
819
|
+
enter(node(shape, plainText(body.slice(0, -1))));
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
match = /^-+(\[[^\]]*\])?>\s*(.*?);?$/.exec(text);
|
|
823
|
+
if (match) {
|
|
824
|
+
pending = label(match[2]);
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
match = /^if\s*\((.*?)\)\s*(?:is\s*\((.*?)\)\s*)?then\s*(?:\((.*)\))?$/i.exec(text);
|
|
828
|
+
if (match) {
|
|
829
|
+
const diamond = node("diam", plainText(match[1] + (match[2] ? ` ${match[2]}` : "")));
|
|
830
|
+
enter(diamond);
|
|
831
|
+
tails = [{ id: diamond, ...label(match[3]) ? { label: label(match[3]) } : {} }];
|
|
832
|
+
frames.push({ kind: "if", diamond, ends: [], hasElse: false, line: current.line });
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
match = /^(?:elseif|else\s+if)\s*\((.*?)\)\s*(?:is\s*\((.*?)\)\s*)?then\s*(?:\((.*)\))?$/i.exec(text);
|
|
836
|
+
if (match) {
|
|
837
|
+
const frame = top(["if"], current);
|
|
838
|
+
frame.ends.push(...tails);
|
|
839
|
+
const diamond = node("diam", plainText(match[1] + (match[2] ? ` ${match[2]}` : "")));
|
|
840
|
+
link(frame.diamond, diamond);
|
|
841
|
+
frame.diamond = diamond;
|
|
842
|
+
tails = [{ id: diamond, ...label(match[3]) ? { label: label(match[3]) } : {} }];
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
match = /^else\s*(?:\((.*)\))?$/i.exec(text);
|
|
846
|
+
if (match) {
|
|
847
|
+
const frame = top(["if"], current);
|
|
848
|
+
frame.ends.push(...tails);
|
|
849
|
+
frame.hasElse = true;
|
|
850
|
+
tails = [{ id: frame.diamond, ...label(match[1]) ? { label: label(match[1]) } : {} }];
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if (/^end\s*if$/i.test(text)) {
|
|
854
|
+
const frame = top(["if"], current);
|
|
855
|
+
frames.pop();
|
|
856
|
+
tails = [...frame.ends, ...tails, ...frame.hasElse ? [] : [{ id: frame.diamond }]];
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
match = /^switch\s*\((.*)\)$/i.exec(text);
|
|
860
|
+
if (match) {
|
|
861
|
+
const diamond = node("diam", plainText(match[1]));
|
|
862
|
+
enter(diamond);
|
|
863
|
+
tails = [];
|
|
864
|
+
frames.push({ kind: "switch", diamond, ends: [], line: current.line, started: false });
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
match = /^case\s*\((.*)\)$/i.exec(text);
|
|
868
|
+
if (match) {
|
|
869
|
+
const frame = top(["switch"], current);
|
|
870
|
+
if (frame.started) frame.ends.push(...tails);
|
|
871
|
+
frame.started = true;
|
|
872
|
+
tails = [{ id: frame.diamond, ...label(match[1]) ? { label: label(match[1]) } : {} }];
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
if (/^end\s*switch$/i.test(text)) {
|
|
876
|
+
const frame = top(["switch"], current);
|
|
877
|
+
frames.pop();
|
|
878
|
+
tails = [...frame.ends, ...tails];
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
match = /^while\s*\((.*?)\)\s*(?:is\s*\((.*)\))?$/i.exec(text);
|
|
882
|
+
if (match) {
|
|
883
|
+
const diamond = node("diam", plainText(match[1]));
|
|
884
|
+
enter(diamond);
|
|
885
|
+
tails = [{ id: diamond, ...label(match[2]) ? { label: label(match[2]) } : {} }];
|
|
886
|
+
frames.push({ kind: "while", diamond, line: current.line });
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
match = /^end\s*while\s*(?:\((.*)\))?$/i.exec(text);
|
|
890
|
+
if (match) {
|
|
891
|
+
const frame = top(["while"], current);
|
|
892
|
+
frames.pop();
|
|
893
|
+
for (const tail of tails) link(tail.id, frame.diamond, tail.label ?? pending);
|
|
894
|
+
pending = void 0;
|
|
895
|
+
tails = [{ id: frame.diamond, ...label(match[1]) ? { label: label(match[1]) } : {} }];
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
if (/^repeat$/i.test(text) || /^repeat\s*:/.test(text)) {
|
|
899
|
+
frames.push({ kind: "repeat", line: current.line });
|
|
900
|
+
if (/^repeat\s*:/.test(text)) {
|
|
901
|
+
lines[index] = { ...current, text: text.replace(/^repeat\s*/, "") };
|
|
902
|
+
index--;
|
|
903
|
+
}
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
match = /^repeat\s*while\s*\((.*?)\)\s*(?:is\s*\((.*?)\))?\s*(?:not\s*\((.*?)\))?$/i.exec(text);
|
|
907
|
+
if (match) {
|
|
908
|
+
const frame = top(["repeat"], current);
|
|
909
|
+
frames.pop();
|
|
910
|
+
const diamond = node("diam", plainText(match[1]));
|
|
911
|
+
enter(diamond);
|
|
912
|
+
link(diamond, frame.first ?? diamond, label(match[2]));
|
|
913
|
+
tails = [{ id: diamond, ...label(match[3]) ? { label: label(match[3]) } : {} }];
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
916
|
+
match = /^backward\s*:([\s\S]*);$/.exec(text);
|
|
917
|
+
if (match) continue;
|
|
918
|
+
if (/^fork$/i.test(text)) {
|
|
919
|
+
const bar = node("fork", "");
|
|
920
|
+
enter(bar);
|
|
921
|
+
frames.push({ kind: "fork", bar, ends: [], line: current.line });
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
if (/^fork\s+again$/i.test(text)) {
|
|
925
|
+
const frame = top(["fork"], current);
|
|
926
|
+
frame.ends.push(...tails);
|
|
927
|
+
tails = [{ id: frame.bar }];
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
if (/^end\s*(fork|merge)\b.*$/i.test(text)) {
|
|
931
|
+
const frame = top(["fork"], current);
|
|
932
|
+
frames.pop();
|
|
933
|
+
const ends = [...frame.ends, ...tails];
|
|
934
|
+
tails = ends;
|
|
935
|
+
enter(node(/merge/i.test(text) ? "diam" : "fork", ""));
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
if (/^split$/i.test(text)) {
|
|
939
|
+
frames.push({ kind: "split", start: tails, ends: [], line: current.line });
|
|
940
|
+
continue;
|
|
941
|
+
}
|
|
942
|
+
if (/^split\s+again$/i.test(text)) {
|
|
943
|
+
const frame = top(["split"], current);
|
|
944
|
+
frame.ends.push(...tails);
|
|
945
|
+
tails = [...frame.start];
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
if (/^end\s*split$/i.test(text)) {
|
|
949
|
+
const frame = top(["split"], current);
|
|
950
|
+
frames.pop();
|
|
951
|
+
tails = [...frame.ends, ...tails];
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
match = /^(partition|group|package|rectangle|card)\s+("[^"]+"|[^{]+?)\s*(#\S+)?\s*\{?$/i.exec(text);
|
|
955
|
+
if (match) {
|
|
956
|
+
groups.push({ id: `g${groups.length}`, label: plainText(unquote(match[2])), nodes: [], ...group !== void 0 ? { parent: group } : lane !== void 0 ? { parent: lane } : {} });
|
|
957
|
+
frames.push({ kind: "group", previous: group, line: current.line });
|
|
958
|
+
group = groups.length - 1;
|
|
959
|
+
continue;
|
|
960
|
+
}
|
|
961
|
+
if (/^\}$/.test(text) || /^end\s*(group|partition)$/i.test(text)) {
|
|
962
|
+
const frame = top(["group"], current);
|
|
963
|
+
frames.pop();
|
|
964
|
+
group = frame.previous;
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
match = /^\|(?:#[^|]*\|)?([^|]+)\|$/.exec(text);
|
|
968
|
+
if (match) {
|
|
969
|
+
const name = match[1].trim();
|
|
970
|
+
let at = lanes.get(name);
|
|
971
|
+
if (at === void 0) {
|
|
972
|
+
groups.push({ id: `g${groups.length}`, label: plainText(name), nodes: [] });
|
|
973
|
+
at = groups.length - 1;
|
|
974
|
+
lanes.set(name, at);
|
|
975
|
+
}
|
|
976
|
+
lane = at;
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
match = /^(floating\s+)?note\s+(left|right)?\s*(?::\s*(.*))?$/i.exec(text);
|
|
980
|
+
if (match) {
|
|
981
|
+
let body = match[3];
|
|
982
|
+
if (body === void 0) {
|
|
983
|
+
const block = noteBlock(lines, index);
|
|
984
|
+
body = block.text;
|
|
985
|
+
index = block.end;
|
|
986
|
+
}
|
|
987
|
+
const anchor = tails[0]?.id;
|
|
988
|
+
const note = node("notch-rect", plainText(body));
|
|
989
|
+
if (anchor) edges.push(` ${anchor} -.- ${note}`);
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
match = /^\((\w)\)$/.exec(text);
|
|
993
|
+
if (match) {
|
|
994
|
+
enter(node("circle", match[1]));
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
if (/^(label|goto)\s/i.test(text)) fail("diagram-unsupported", "label and goto are not drawn; write the flow with if, while or repeat.", current.line, 1);
|
|
998
|
+
unknown(current, "activity");
|
|
999
|
+
}
|
|
1000
|
+
if (frames.length) fail("diagram-syntax", `A ${frames.at(-1).kind} block opened here is not closed.`, frames.at(-1).line, 1);
|
|
1001
|
+
if (!count) fail("diagram-syntax", "The activity diagram has no actions.");
|
|
1002
|
+
const out = [titled(title, "flowchart TB")];
|
|
1003
|
+
const inGroup = new Set(groups.flatMap((entry) => entry.nodes));
|
|
1004
|
+
for (const line of nodes) if (!inGroup.has(line.slice(0, line.indexOf("@")))) out.push(` ${line}`);
|
|
1005
|
+
const write = (at, indent) => {
|
|
1006
|
+
const entry = groups[at];
|
|
1007
|
+
out.push(`${indent}subgraph ${entry.id}["${quoted(entry.label)}"]`);
|
|
1008
|
+
for (const id of entry.nodes) out.push(`${indent} ${nodes.find((line) => line.startsWith(`${id}@`))}`);
|
|
1009
|
+
groups.forEach((child, index) => {
|
|
1010
|
+
if (child.parent === at) write(index, `${indent} `);
|
|
1011
|
+
});
|
|
1012
|
+
out.push(`${indent}end`);
|
|
1013
|
+
};
|
|
1014
|
+
groups.forEach((entry, index) => {
|
|
1015
|
+
if (entry.parent === void 0) write(index, " ");
|
|
1016
|
+
});
|
|
1017
|
+
out.push(...edges);
|
|
1018
|
+
return out.join("\n");
|
|
1019
|
+
}
|
|
1020
|
+
function usecase(lines, title, direction, maxEdges) {
|
|
1021
|
+
const ids = new Ids("u");
|
|
1022
|
+
const actors = /* @__PURE__ */ new Map(), cases = /* @__PURE__ */ new Map();
|
|
1023
|
+
const actorLines = [], caseLines = [], relationLines = [];
|
|
1024
|
+
const boundaries = [];
|
|
1025
|
+
const stack = [];
|
|
1026
|
+
const element = (raw, forced, alias) => {
|
|
1027
|
+
let name = raw.trim(), kind = forced;
|
|
1028
|
+
if (/^:.*:$/.test(name)) {
|
|
1029
|
+
name = name.slice(1, -1);
|
|
1030
|
+
kind = "actor";
|
|
1031
|
+
} else if (/^\(.*\)$/.test(name)) {
|
|
1032
|
+
name = name.slice(1, -1);
|
|
1033
|
+
kind = "usecase";
|
|
1034
|
+
} else name = unquote(name);
|
|
1035
|
+
const label = name;
|
|
1036
|
+
if (alias) name = alias;
|
|
1037
|
+
const known = actors.get(name) ?? cases.get(name);
|
|
1038
|
+
if (known) return known;
|
|
1039
|
+
const id = ids.of(name);
|
|
1040
|
+
if ((kind ?? "actor") === "actor") {
|
|
1041
|
+
actors.set(name, id);
|
|
1042
|
+
actorLines.push(` actor ${id}${label !== id ? `("${quoted(plainText(label))}")` : ""}`);
|
|
1043
|
+
} else {
|
|
1044
|
+
cases.set(name, id);
|
|
1045
|
+
caseLines.push({ line: `${id}("${quoted(plainText(label))}")`, ...stack.length ? { boundary: stack.at(-1) } : {} });
|
|
1046
|
+
}
|
|
1047
|
+
return id;
|
|
1048
|
+
};
|
|
1049
|
+
const declared = (first, second, kind) => element(first, kind, second);
|
|
1050
|
+
for (let index = 0; index < lines.length; index++) {
|
|
1051
|
+
const current = lines[index];
|
|
1052
|
+
nest(stack.length, current);
|
|
1053
|
+
const plain = current.text.replace(/\s+#\S+$/, "");
|
|
1054
|
+
const text = readLink(plain) ? plain : plain.replace(/\s*<<[^<>]*>>\s*$/, "");
|
|
1055
|
+
let match;
|
|
1056
|
+
match = /^actor\s+(?::([^:]+):|"([^"]+)"|([\w.\u0080-\uFFFF]+))(?:\s+as\s+(?::([^:]+):|"([^"]+)"|([\w.]+)))?$/iu.exec(text);
|
|
1057
|
+
if (match) {
|
|
1058
|
+
const second = match[4] ?? match[5] ?? match[6];
|
|
1059
|
+
if (second !== void 0 && (match[4] !== void 0 || match[5] !== void 0)) element(match[4] ?? match[5], "actor", match[1] ?? match[2] ?? match[3]);
|
|
1060
|
+
else declared(match[1] ?? match[2] ?? match[3], second, "actor");
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
match = /^:([^:]+):(?:\s+as\s+([\w.]+))?$/.exec(text);
|
|
1064
|
+
if (match) {
|
|
1065
|
+
element(match[1], "actor", match[2]);
|
|
1066
|
+
continue;
|
|
1067
|
+
}
|
|
1068
|
+
match = /^usecase\s+(?:\(([^)]+)\)|"([^"]+)"|([\w.]+))(?:\s+as\s+(?:\(([^)]+)\)|"([^"]+)"|([\w.]+)))?$/i.exec(text);
|
|
1069
|
+
if (match) {
|
|
1070
|
+
const second = match[4] ?? match[5] ?? match[6];
|
|
1071
|
+
if (second !== void 0 && (match[4] !== void 0 || match[5] !== void 0)) element(match[4] ?? match[5], "usecase", match[1] ?? match[2] ?? match[3]);
|
|
1072
|
+
else declared(match[1] ?? match[2] ?? match[3], second, "usecase");
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
match = /^\(([^)]+)\)(?:\s+as\s+(?:\(([\w.]+)\)|([\w.]+)))?$/.exec(text);
|
|
1076
|
+
if (match) {
|
|
1077
|
+
element(match[1], "usecase", match[2] ?? match[3]);
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
match = /^(rectangle|package|frame|node|folder|cloud)\s+("[^"]+"|[\w.]+)(?:\s+as\s+[\w.]+)?\s*\{$/i.exec(text);
|
|
1081
|
+
if (match) {
|
|
1082
|
+
boundaries.push({ label: plainText(unquote(match[2])), package: match[1].toLowerCase() !== "rectangle" });
|
|
1083
|
+
stack.push(boundaries.length - 1);
|
|
1084
|
+
continue;
|
|
1085
|
+
}
|
|
1086
|
+
if (/^\}$/.test(text)) {
|
|
1087
|
+
if (!stack.length) unknown(current, "use case");
|
|
1088
|
+
stack.pop();
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
match = /^note\s+(?:left|right|top|bottom)\s+of\s+("[^"]+"|\([^)]+\)|:[^:]+:|[\w.]+)\s*(?::\s*(.*))?$/i.exec(text);
|
|
1092
|
+
if (match) {
|
|
1093
|
+
let body = match[2];
|
|
1094
|
+
if (body === void 0) {
|
|
1095
|
+
const block = noteBlock(lines, index);
|
|
1096
|
+
body = block.text;
|
|
1097
|
+
index = block.end;
|
|
1098
|
+
}
|
|
1099
|
+
relationLines.push(` note for ${element(match[1])} "${quoted(plainText(body))}"`);
|
|
1100
|
+
continue;
|
|
1101
|
+
}
|
|
1102
|
+
if (statement(text, /^note\b/i)) noNote(current, "an actor or use case");
|
|
1103
|
+
const link = readLink(text);
|
|
1104
|
+
if (link) {
|
|
1105
|
+
const from = element(link.from), to = element(link.to);
|
|
1106
|
+
const label = link.label?.replace(/^<+\s*|\s*>+$/g, "").trim();
|
|
1107
|
+
if (link.line === "dotted" && /^(include|extend)s?$/i.test(label ?? "")) relationLines.push(` ${from} ..> : ${/^include/i.test(label) ? "include" : "extend"} ${to}`);
|
|
1108
|
+
else if (link.left === "<|") relationLines.push(` ${to} --|> ${from}`);
|
|
1109
|
+
else if (link.right === "|>") relationLines.push(` ${from} --|> ${to}`);
|
|
1110
|
+
else if (label) relationLines.push(link.left && !link.right ? ` ${to} -- ${betweenDashes(label)} --> ${from}` : ` ${from} -- ${betweenDashes(label)} --> ${to}`);
|
|
1111
|
+
else relationLines.push(` ${from} ${link.right ? "-->" : link.left ? "<--" : "---"} ${to}`);
|
|
1112
|
+
if (relationLines.length > maxEdges) fail("diagram-limit", `The diagram has more than ${maxEdges} relations.`);
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
unknown(current, "use case");
|
|
1116
|
+
}
|
|
1117
|
+
if (stack.length) fail("diagram-syntax", "A rectangle or package block is not closed with }.");
|
|
1118
|
+
if (!actors.size && !cases.size) fail("diagram-syntax", "The use case diagram has no actors or use cases.");
|
|
1119
|
+
const out = [titled(title, "usecase-beta")];
|
|
1120
|
+
if (direction) out.push(` direction ${direction}`);
|
|
1121
|
+
out.push(...actorLines, ...caseLines.filter((entry) => entry.boundary === void 0).map((entry) => ` ${entry.line}`));
|
|
1122
|
+
boundaries.forEach((boundary, at) => {
|
|
1123
|
+
const members = caseLines.filter((entry) => entry.boundary === at);
|
|
1124
|
+
if (!members.length) return;
|
|
1125
|
+
out.push(` systemBoundary "${quoted(boundary.label)}"${boundary.package ? "@{ type: package }" : ""}`, ...members.map((entry) => ` ${entry.line}`), " end");
|
|
1126
|
+
});
|
|
1127
|
+
out.push(...relationLines);
|
|
1128
|
+
return out.join("\n");
|
|
1129
|
+
}
|
|
1130
|
+
var ELEMENT_SHAPES = {
|
|
1131
|
+
component: "rect",
|
|
1132
|
+
interface: "circle",
|
|
1133
|
+
database: "cyl",
|
|
1134
|
+
node: "st-rect",
|
|
1135
|
+
cloud: "cloud",
|
|
1136
|
+
artifact: "doc",
|
|
1137
|
+
file: "doc",
|
|
1138
|
+
folder: "folder",
|
|
1139
|
+
frame: "rect",
|
|
1140
|
+
package: "folder",
|
|
1141
|
+
queue: "h-cyl",
|
|
1142
|
+
storage: "stadium",
|
|
1143
|
+
actor: "person",
|
|
1144
|
+
person: "person",
|
|
1145
|
+
card: "rect",
|
|
1146
|
+
agent: "rect",
|
|
1147
|
+
collections: "st-rect",
|
|
1148
|
+
stack: "st-rect",
|
|
1149
|
+
hexagon: "hex",
|
|
1150
|
+
label: "text",
|
|
1151
|
+
boundary: "circle",
|
|
1152
|
+
control: "circle",
|
|
1153
|
+
entity: "circle",
|
|
1154
|
+
rectangle: "rect",
|
|
1155
|
+
usecase: "stadium",
|
|
1156
|
+
port: "sm-circ",
|
|
1157
|
+
portin: "sm-circ",
|
|
1158
|
+
portout: "sm-circ"
|
|
1159
|
+
};
|
|
1160
|
+
function component(lines, title, direction, maxEdges) {
|
|
1161
|
+
const ids = new Ids("k");
|
|
1162
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
1163
|
+
const groups = [];
|
|
1164
|
+
const groupByCode = /* @__PURE__ */ new Map();
|
|
1165
|
+
const edges = [];
|
|
1166
|
+
const stack = [];
|
|
1167
|
+
const element = (raw, kind, alias) => {
|
|
1168
|
+
let name = raw.trim(), label, shape = kind ? ELEMENT_SHAPES[kind] ?? "rect" : "rect";
|
|
1169
|
+
if (/^\[.*\]$/.test(name)) {
|
|
1170
|
+
name = name.slice(1, -1);
|
|
1171
|
+
shape = kind ? shape : "rect";
|
|
1172
|
+
} else if (/^\(\)\s*/.test(name)) {
|
|
1173
|
+
name = unquote(name.replace(/^\(\)\s*/, ""));
|
|
1174
|
+
shape = "circle";
|
|
1175
|
+
} else if (/^\(.*\)$/.test(name)) {
|
|
1176
|
+
name = name.slice(1, -1);
|
|
1177
|
+
shape = "stadium";
|
|
1178
|
+
} else if (/^:.*:$/.test(name)) {
|
|
1179
|
+
name = name.slice(1, -1);
|
|
1180
|
+
shape = "person";
|
|
1181
|
+
} else {
|
|
1182
|
+
name = unquote(name);
|
|
1183
|
+
const group = kind === void 0 && alias === void 0 ? groupByCode.get(name) : void 0;
|
|
1184
|
+
if (group !== void 0) return `#${group}#`;
|
|
1185
|
+
}
|
|
1186
|
+
label = name;
|
|
1187
|
+
if (alias) name = alias;
|
|
1188
|
+
const id = ids.of(name);
|
|
1189
|
+
if (!nodes.has(id)) nodes.set(id, { line: `${id}@{ shape: ${shape}, label: "${quoted(plainText(label))}" }`, ...stack.length ? { group: stack.at(-1) } : {} });
|
|
1190
|
+
return id;
|
|
1191
|
+
};
|
|
1192
|
+
for (let index = 0; index < lines.length; index++) {
|
|
1193
|
+
const current = lines[index];
|
|
1194
|
+
nest(stack.length, current);
|
|
1195
|
+
const text = plainDeclaration(current.text);
|
|
1196
|
+
let match;
|
|
1197
|
+
match = /^(\w+)\s*\{$/.exec(text);
|
|
1198
|
+
if (match && Object.hasOwn(ELEMENT_SHAPES, match[1].toLowerCase())) {
|
|
1199
|
+
groups.push({ id: `g${groups.length}`, label: "", ...stack.length ? { parent: stack.at(-1) } : {} });
|
|
1200
|
+
stack.push(groups.length - 1);
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
match = COMPONENT_DECLARATION.exec(text);
|
|
1204
|
+
if (match) {
|
|
1205
|
+
const kind = match[1].toLowerCase();
|
|
1206
|
+
let raw = match[2], alias = match[3] ? unquote(match[3]) : void 0;
|
|
1207
|
+
if (alias && /^"/.test(match[3])) {
|
|
1208
|
+
[raw, alias] = [match[3], unquote(match[2])];
|
|
1209
|
+
}
|
|
1210
|
+
if (match[4]) {
|
|
1211
|
+
const label = plainText(unquote(raw).replace(/^\[|\]$/g, ""));
|
|
1212
|
+
const code = alias ?? unquote(raw).replace(/^\[|\]$/g, "");
|
|
1213
|
+
if (!groupByCode.has(code)) groupByCode.set(code, groups.length);
|
|
1214
|
+
groups.push({ id: `g${groups.length}`, label, ...stack.length ? { parent: stack.at(-1) } : {} });
|
|
1215
|
+
stack.push(groups.length - 1);
|
|
1216
|
+
continue;
|
|
1217
|
+
}
|
|
1218
|
+
element(raw, kind, alias);
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
match = /^(\[[^\]]+\]|\(\)\s*("[^"]+"|[\w.]+))(?:\s+as\s+([\w.]+))?$/.exec(text);
|
|
1222
|
+
if (match) {
|
|
1223
|
+
element(match[1], void 0, match[3]);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
if (/^\}$/.test(text)) {
|
|
1227
|
+
if (!stack.length) unknown(current, "component");
|
|
1228
|
+
stack.pop();
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
match = /^note\s+(?:left|right|top|bottom)\s+of\s+("[^"]+"|\[[^\]]+\]|[\w.]+)\s*(?::\s*(.*))?$/i.exec(text);
|
|
1232
|
+
if (match) {
|
|
1233
|
+
let body = match[2];
|
|
1234
|
+
if (body === void 0) {
|
|
1235
|
+
const block = noteBlock(lines, index);
|
|
1236
|
+
body = block.text;
|
|
1237
|
+
index = block.end;
|
|
1238
|
+
}
|
|
1239
|
+
const target = element(match[1]);
|
|
1240
|
+
const note = ids.of(`note ${index}`);
|
|
1241
|
+
nodes.set(note, { line: `${note}@{ shape: notch-rect, label: "${quoted(plainText(body))}" }` });
|
|
1242
|
+
edges.push(` ${target} -.- ${note}`);
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
if (statement(text, /^note\b/i)) noNote(current, "an element");
|
|
1246
|
+
const link = readLink(text);
|
|
1247
|
+
if (link) {
|
|
1248
|
+
const from = element(link.from), to = element(link.to);
|
|
1249
|
+
const tip = (end) => /^(>|>>|\|>|\^)$/.test(end) ? ">" : /^(\*|#|x)$/.test(end) ? "x" : end === "o" || /^[()]0?$|^0?[()]$/.test(end) ? "o" : end === "<" || end === "<<" || end === "<|" ? "<" : "";
|
|
1250
|
+
let left = tip(link.left), right = tip(link.right);
|
|
1251
|
+
if (left === ">") left = "<";
|
|
1252
|
+
if (right === "<") right = ">";
|
|
1253
|
+
if (left && !right) {
|
|
1254
|
+
right = left === "<" ? ">" : left;
|
|
1255
|
+
left = "";
|
|
1256
|
+
edges.push(` ${edgeLine(to, from, link, "", right)}`);
|
|
1257
|
+
} else edges.push(` ${edgeLine(from, to, link, left && right ? right === ">" ? "<" : right : "", right)}`);
|
|
1258
|
+
if (edges.length > maxEdges) fail("diagram-limit", `The diagram has more than ${maxEdges} links.`);
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
unknown(current, "component");
|
|
1262
|
+
}
|
|
1263
|
+
if (stack.length) fail("diagram-syntax", "A { block is not closed with }.");
|
|
1264
|
+
if (!nodes.size) fail("diagram-syntax", "The component diagram has no elements.");
|
|
1265
|
+
const usedIds = new Set(nodes.keys());
|
|
1266
|
+
let groupId = 0;
|
|
1267
|
+
for (const group of groups) {
|
|
1268
|
+
while (usedIds.has(`g${groupId}`)) groupId++;
|
|
1269
|
+
group.id = `g${groupId++}`;
|
|
1270
|
+
usedIds.add(group.id);
|
|
1271
|
+
}
|
|
1272
|
+
const out = [titled(title, `flowchart ${direction ?? "TB"}`)];
|
|
1273
|
+
for (const [, entry] of nodes) if (entry.group === void 0) out.push(` ${entry.line}`);
|
|
1274
|
+
const write = (at, indent) => {
|
|
1275
|
+
out.push(`${indent}subgraph ${groups[at].id}["${quoted(groups[at].label) || " "}"]`);
|
|
1276
|
+
for (const [, entry] of nodes) if (entry.group === at) out.push(`${indent} ${entry.line}`);
|
|
1277
|
+
groups.forEach((child, index) => {
|
|
1278
|
+
if (child.parent === at) write(index, `${indent} `);
|
|
1279
|
+
});
|
|
1280
|
+
out.push(`${indent}end`);
|
|
1281
|
+
};
|
|
1282
|
+
groups.forEach((entry, index) => {
|
|
1283
|
+
if (entry.parent === void 0) write(index, " ");
|
|
1284
|
+
});
|
|
1285
|
+
out.push(...edges.map((edge) => edge.replace(/#(\d+)#/g, (_, at) => groups[Number(at)].id)));
|
|
1286
|
+
return out.join("\n");
|
|
1287
|
+
}
|
|
1288
|
+
function edgeLine(from, to, link, start, tip) {
|
|
1289
|
+
if (link.line === "hidden") return `${from} ~~~ ${to}`;
|
|
1290
|
+
const extra = Math.min(7, link.length - 1);
|
|
1291
|
+
const body = link.line === "dotted" ? `-${".".repeat(1 + Math.max(0, extra))}-` : link.line === "bold" ? tip ? "=".repeat(2 + Math.max(0, extra)) : "=".repeat(3 + Math.max(0, extra)) : tip ? "-".repeat(2 + Math.max(0, extra)) : "-".repeat(3 + Math.max(0, extra));
|
|
1292
|
+
const label = link.label ? `|"${quoted(link.label)}"|` : "";
|
|
1293
|
+
return `${from} ${start}${body}${tip}${label} ${to}`;
|
|
1294
|
+
}
|
|
1295
|
+
function mindmap(lines) {
|
|
1296
|
+
const out = ["mindmap"];
|
|
1297
|
+
let roots = 0, count = 0;
|
|
1298
|
+
const indented = lines.some((line) => line.indent > 0 && /^[*+-][\s[_:]/.test(line.text));
|
|
1299
|
+
const levels = [...new Set(lines.filter((line) => /^[*+-][\s[_:]/.test(line.text)).map((line) => line.indent))].sort((a, b) => a - b);
|
|
1300
|
+
for (let index = 0; index < lines.length; index++) {
|
|
1301
|
+
const current = lines[index];
|
|
1302
|
+
const match = /^([*+-]+)(\[#[^\]]*\])?(_)?\s*(.*)$/.exec(current.text);
|
|
1303
|
+
if (!match) unknown(current, "mind map");
|
|
1304
|
+
const depth = indented && match[1].length === 1 ? levels.indexOf(current.indent) + 1 : match[1].length;
|
|
1305
|
+
let text = match[4];
|
|
1306
|
+
if (/^:/.test(text)) {
|
|
1307
|
+
text = text.slice(1);
|
|
1308
|
+
while (!/;$/.test(text) && index + 1 < lines.length) text += `
|
|
1309
|
+
${lines[++index].text}`;
|
|
1310
|
+
if (!/;$/.test(text)) fail("diagram-syntax", "A multi-line node is not ended with ;.", current.line, 1);
|
|
1311
|
+
text = text.replace(/;$/, "");
|
|
1312
|
+
}
|
|
1313
|
+
nest(depth, current);
|
|
1314
|
+
if (depth === 1 && ++roots > 1) fail("diagram-unsupported", "A mind map has one root; draw the second tree as its own diagram.", current.line, 1);
|
|
1315
|
+
if (depth > 1 && !count) fail("diagram-syntax", "A mind map starts with its root (*).", current.line, 1);
|
|
1316
|
+
const label = plainText(text);
|
|
1317
|
+
const shown = quoted(label).replace(/:/g, "#58;") || " ";
|
|
1318
|
+
out.push(`${" ".repeat(depth)}m${count++}${match[3] ? `["${shown}"]` : `("${shown}")`}`);
|
|
1319
|
+
}
|
|
1320
|
+
if (!count) fail("diagram-syntax", "The mind map has no nodes.");
|
|
1321
|
+
return out.join("\n");
|
|
1322
|
+
}
|
|
1323
|
+
var DAY = 864e5;
|
|
1324
|
+
var GANTT_MAX_DAYS = 36600;
|
|
1325
|
+
var GANTT_MAX_STEPS = GANTT_MAX_DAYS * 10;
|
|
1326
|
+
var WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
1327
|
+
function gantt(lines, title) {
|
|
1328
|
+
let projectStart;
|
|
1329
|
+
const closed = /* @__PURE__ */ new Set(), closedDates = /* @__PURE__ */ new Set();
|
|
1330
|
+
const tasks = /* @__PURE__ */ new Map(), aliases = /* @__PURE__ */ new Map(), order = [];
|
|
1331
|
+
let section, previous;
|
|
1332
|
+
const date = (text, line) => {
|
|
1333
|
+
const match = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(text.trim());
|
|
1334
|
+
if (!match) fail("diagram-syntax", `A date is written YYYY-MM-DD: ${text}.`, line, 1);
|
|
1335
|
+
const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
|
|
1336
|
+
const parsed = /* @__PURE__ */ new Date(0);
|
|
1337
|
+
parsed.setUTCFullYear(year, month - 1, day);
|
|
1338
|
+
if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) fail("diagram-syntax", `The date is not a calendar date: ${text}.`, line, 1);
|
|
1339
|
+
return parsed.getTime();
|
|
1340
|
+
};
|
|
1341
|
+
const task = (raw, line) => {
|
|
1342
|
+
const name = aliases.get(raw) ?? raw;
|
|
1343
|
+
let entry = tasks.get(name);
|
|
1344
|
+
if (!entry) {
|
|
1345
|
+
entry = { name, id: `t${tasks.size}`, milestone: false, ...section ? { section } : {}, line };
|
|
1346
|
+
tasks.set(name, entry);
|
|
1347
|
+
order.push(entry);
|
|
1348
|
+
}
|
|
1349
|
+
return entry;
|
|
1350
|
+
};
|
|
1351
|
+
const amount = (count, unit) => {
|
|
1352
|
+
const days = Number(count) * (/^week/i.test(unit) ? 7 : 1);
|
|
1353
|
+
if (!Number.isSafeInteger(days) || days > GANTT_MAX_DAYS) fail("diagram-limit", `A gantt duration or offset exceeds ${GANTT_MAX_DAYS} days; shorten the schedule or split the diagram.`);
|
|
1354
|
+
return days;
|
|
1355
|
+
};
|
|
1356
|
+
for (const current of lines) {
|
|
1357
|
+
const text = current.text.replace(/\s+and\s+(is\s+colored|is\s+displayed|on\s+\{).*$/i, "");
|
|
1358
|
+
let match;
|
|
1359
|
+
match = /^project\s+starts?\s+(?:the\s+|on\s+)?(\d{4}[-/]\d{1,2}[-/]\d{1,2})$/i.exec(text);
|
|
1360
|
+
if (match) {
|
|
1361
|
+
projectStart = date(match[1], current.line);
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
match = /^(saturday|sunday|monday|tuesday|wednesday|thursday|friday)s?\s+(?:are|is)\s+closed$/i.exec(text);
|
|
1365
|
+
if (match) {
|
|
1366
|
+
closed.add(WEEKDAYS.indexOf(match[1].toLowerCase()));
|
|
1367
|
+
continue;
|
|
1368
|
+
}
|
|
1369
|
+
match = /^(\d{4}[-/]\d{1,2}[-/]\d{1,2})\s+(?:is|are)\s+closed$/i.exec(text);
|
|
1370
|
+
if (match) {
|
|
1371
|
+
closedDates.add(date(match[1], current.line));
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
match = /^--\s*(.*?)\s*--$/.exec(text);
|
|
1375
|
+
if (match) {
|
|
1376
|
+
section = plainText(match[1]);
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
if (/^(printscale|projectscale|language|today|hide\s+ressources|hide\s+footbox|<style>|\d{4}[-/]\d{1,2}[-/]\d{1,2}\s+is\s+(colored|named)|\[[^\]]+\]\s+is\s+colored|\[[^\]]+\]\s+is\s+displayed|separator\b|\{[^}]*\}\s+is\s+off)/i.test(text)) continue;
|
|
1380
|
+
let rest = text;
|
|
1381
|
+
let subject;
|
|
1382
|
+
match = /^then\s+(\[[^\]]+\].*)$/i.exec(rest);
|
|
1383
|
+
if (match) {
|
|
1384
|
+
rest = match[1];
|
|
1385
|
+
const name = /^\[([^\]]+)\]/.exec(rest)[1];
|
|
1386
|
+
subject = task(name, current.line);
|
|
1387
|
+
if (previous) subject.startRef = { task: previous.name, at: "end", offset: 0 };
|
|
1388
|
+
}
|
|
1389
|
+
match = /^\[([^\]]+)\]\s+as\s+\[([^\]]+)\]\s*(.*)$/i.exec(rest);
|
|
1390
|
+
if (match) {
|
|
1391
|
+
aliases.set(match[2], match[1]);
|
|
1392
|
+
task(match[1], current.line);
|
|
1393
|
+
rest = `[${match[1]}] ${match[3]}`.trim();
|
|
1394
|
+
if (!match[3]) {
|
|
1395
|
+
previous = task(match[1], current.line);
|
|
1396
|
+
continue;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
match = /^\[([^\]]+)\]\s*(.*)$/.exec(rest);
|
|
1400
|
+
if (!match) unknown(current, "gantt");
|
|
1401
|
+
subject = task(match[1], current.line);
|
|
1402
|
+
previous = subject;
|
|
1403
|
+
for (const clause of match[2].split(/\s+and\s+/i).map((part) => part.trim()).filter(Boolean)) {
|
|
1404
|
+
let part;
|
|
1405
|
+
part = /^(?:lasts|requires)\s+(\d+)\s+(days?|weeks?)(?:\s+and\s+(\d+)\s+days?)?$/i.exec(clause);
|
|
1406
|
+
if (part) {
|
|
1407
|
+
subject.duration = amount(part[1], part[2]) + Number(part[3] ?? 0);
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
part = /^starts?\s+(?:on\s+|the\s+)?(\d{4}[-/]\d{1,2}[-/]\d{1,2})$/i.exec(clause);
|
|
1411
|
+
if (part) {
|
|
1412
|
+
subject.start = date(part[1], current.line);
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
part = /^ends?\s+(?:on\s+|the\s+)?(\d{4}[-/]\d{1,2}[-/]\d{1,2})$/i.exec(clause);
|
|
1416
|
+
if (part) {
|
|
1417
|
+
subject.end = date(part[1], current.line);
|
|
1418
|
+
continue;
|
|
1419
|
+
}
|
|
1420
|
+
part = /^(starts?|ends?)\s+(?:(\d+)\s+(days?|weeks?)\s+(after|before)\s+)?(?:at\s+)?\[([^\]]+)\]'s\s+(start|end)$/i.exec(clause);
|
|
1421
|
+
if (part) {
|
|
1422
|
+
const offset = part[2] ? amount(part[2], part[3]) * (part[4].toLowerCase() === "before" ? -1 : 1) : 0;
|
|
1423
|
+
const ref = { task: aliases.get(part[5]) ?? part[5], at: part[6].toLowerCase(), offset };
|
|
1424
|
+
if (/^start/i.test(part[1])) subject.startRef = ref;
|
|
1425
|
+
else subject.endRef = ref;
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
part = /^happens\s+(?:at\s+)?\[([^\]]+)\]'s\s+(start|end)$/i.exec(clause);
|
|
1429
|
+
if (part) {
|
|
1430
|
+
subject.milestone = true;
|
|
1431
|
+
subject.startRef = { task: aliases.get(part[1]) ?? part[1], at: part[2].toLowerCase(), offset: 0 };
|
|
1432
|
+
subject.duration = 0;
|
|
1433
|
+
continue;
|
|
1434
|
+
}
|
|
1435
|
+
part = /^happens\s+(?:on\s+|the\s+)?(\d{4}[-/]\d{1,2}[-/]\d{1,2})$/i.exec(clause);
|
|
1436
|
+
if (part) {
|
|
1437
|
+
subject.milestone = true;
|
|
1438
|
+
subject.start = date(part[1], current.line);
|
|
1439
|
+
subject.duration = 0;
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
part = /^is\s+(\d+)%\s+complete(?:d)?$/i.exec(clause);
|
|
1443
|
+
if (part) {
|
|
1444
|
+
subject.complete = Number(part[1]);
|
|
1445
|
+
continue;
|
|
1446
|
+
}
|
|
1447
|
+
if (/^(?:pauses\b|is\s+deleted$)/i.test(clause)) fail("diagram-unsupported", `"${clause}" is not drawn.`, current.line, 1);
|
|
1448
|
+
if (/^(is\s+colored\b|is\s+displayed\b|on\s+\{|links\s+to\b)/i.test(clause)) continue;
|
|
1449
|
+
fail("diagram-syntax", `OPF cannot read this part of a PlantUML gantt chart: ${JSON.stringify(clause)}.`, current.line, 1);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
if (!order.length) fail("diagram-syntax", "The gantt chart has no tasks.");
|
|
1453
|
+
if (closed.size === 7) fail("diagram-syntax", "The gantt chart closes every weekday; leave at least one working day open.");
|
|
1454
|
+
let steps = 0;
|
|
1455
|
+
const tick = () => {
|
|
1456
|
+
if (++steps > GANTT_MAX_STEPS) fail("diagram-limit", `The gantt schedule needs more than ${GANTT_MAX_STEPS} calendar-day checks; shorten the schedule or split the diagram.`);
|
|
1457
|
+
};
|
|
1458
|
+
const relative = projectStart === void 0;
|
|
1459
|
+
const origin = projectStart ?? Date.UTC(2001, 0, 1);
|
|
1460
|
+
const open = (day) => !closed.has(new Date(day).getUTCDay()) && !closedDates.has(day);
|
|
1461
|
+
const forward = (day, count) => {
|
|
1462
|
+
let at = day;
|
|
1463
|
+
for (let step = 0; step < count; at += DAY) {
|
|
1464
|
+
tick();
|
|
1465
|
+
if (open(at)) step++;
|
|
1466
|
+
}
|
|
1467
|
+
return at;
|
|
1468
|
+
};
|
|
1469
|
+
const firstOpen = (day) => {
|
|
1470
|
+
let at = day;
|
|
1471
|
+
while (!open(at)) {
|
|
1472
|
+
tick();
|
|
1473
|
+
at += DAY;
|
|
1474
|
+
}
|
|
1475
|
+
return at;
|
|
1476
|
+
};
|
|
1477
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
1478
|
+
const resolve = (entry, depth = 0) => {
|
|
1479
|
+
const done = resolved.get(entry.name);
|
|
1480
|
+
if (done) return done;
|
|
1481
|
+
if (depth > 200) fail("diagram-syntax", `The tasks refer to each other in a circle (${entry.name}).`, entry.line, 1);
|
|
1482
|
+
const point = (ref) => {
|
|
1483
|
+
const other = tasks.get(ref.task);
|
|
1484
|
+
if (!other) fail("diagram-syntax", `No task is named [${ref.task}].`, entry.line, 1);
|
|
1485
|
+
const span2 = resolve(other, depth + 1);
|
|
1486
|
+
return (ref.at === "end" ? span2.end : span2.start) + ref.offset * DAY;
|
|
1487
|
+
};
|
|
1488
|
+
const duration = entry.duration ?? (entry.milestone ? 0 : void 0);
|
|
1489
|
+
let start = entry.start ?? (entry.startRef ? point(entry.startRef) : void 0);
|
|
1490
|
+
let end = entry.end !== void 0 ? entry.end + DAY : entry.endRef ? point(entry.endRef) : void 0;
|
|
1491
|
+
if (start === void 0 && end !== void 0 && duration !== void 0) {
|
|
1492
|
+
start = end;
|
|
1493
|
+
for (let step = 0; step < duration; ) {
|
|
1494
|
+
tick();
|
|
1495
|
+
start -= DAY;
|
|
1496
|
+
if (open(start)) step++;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
if (start === void 0) start = origin;
|
|
1500
|
+
start = duration === 0 ? start : firstOpen(start);
|
|
1501
|
+
if (end === void 0) end = duration === void 0 ? forward(start, 1) : forward(start, duration);
|
|
1502
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end - start > GANTT_MAX_DAYS * DAY) fail("diagram-limit", `A gantt task spans more than ${GANTT_MAX_DAYS} calendar days; shorten the schedule or split the diagram.`, entry.line, 1);
|
|
1503
|
+
if (end < start) fail("diagram-syntax", `The gantt task [${entry.name}] ends before it starts.`, entry.line, 1);
|
|
1504
|
+
const span = { start, end };
|
|
1505
|
+
resolved.set(entry.name, span);
|
|
1506
|
+
return span;
|
|
1507
|
+
};
|
|
1508
|
+
const iso = (day) => new Date(day).toISOString().slice(0, 10);
|
|
1509
|
+
const out = [titled(void 0, "gantt"), " dateFormat YYYY-MM-DD"];
|
|
1510
|
+
if (title) out.push(` title ${bare(title)}`);
|
|
1511
|
+
if (relative) out.push(" axisFormat %-j");
|
|
1512
|
+
const excluded = [...closed].sort().map((day) => WEEKDAYS[day]);
|
|
1513
|
+
if (excluded.length || closedDates.size) out.push(` excludes ${[...excluded, ...[...closedDates].sort().map(iso)].join(", ")}`);
|
|
1514
|
+
let currentSection = "\0";
|
|
1515
|
+
for (const entry of order) {
|
|
1516
|
+
const span = resolve(entry);
|
|
1517
|
+
if (entry.section !== currentSection) {
|
|
1518
|
+
currentSection = entry.section;
|
|
1519
|
+
if (entry.section !== void 0) out.push(` section ${bare(entry.section)}`);
|
|
1520
|
+
}
|
|
1521
|
+
const tags = [entry.milestone ? "milestone" : "", entry.complete === 100 ? "done" : entry.complete ? "active" : ""].filter(Boolean);
|
|
1522
|
+
let days = 0;
|
|
1523
|
+
if (!entry.milestone) {
|
|
1524
|
+
for (let at = span.start; at < span.end; at += DAY) {
|
|
1525
|
+
tick();
|
|
1526
|
+
if (open(at)) days++;
|
|
1527
|
+
}
|
|
1528
|
+
days = Math.max(1, days);
|
|
1529
|
+
}
|
|
1530
|
+
out.push(` ${ganttName(plainText(entry.name))} :${[...tags, entry.id, iso(span.start), `${days}d`].join(", ")}`);
|
|
1531
|
+
}
|
|
1532
|
+
return out.join("\n");
|
|
1533
|
+
}
|
|
1534
|
+
function translate(source, maxEdges) {
|
|
1535
|
+
const { kind, lines: all } = readLines(source);
|
|
1536
|
+
const { lines, title, direction } = strip(all);
|
|
1537
|
+
if (!lines.length) fail("diagram-syntax", "The diagram is empty.");
|
|
1538
|
+
const diagram = detect(kind, lines);
|
|
1539
|
+
const mermaid = diagram === "sequence" ? sequence(lines, title, maxEdges) : diagram === "class" ? classDiagram(lines, title, maxEdges) : diagram === "state" ? stateDiagram(lines, title, direction, maxEdges) : diagram === "activity" ? activity(lines, title, maxEdges) : diagram === "usecase" ? usecase(lines, title, direction, maxEdges) : diagram === "component" ? component(lines, title, direction, maxEdges) : diagram === "mindmap" ? mindmap(lines) : gantt(lines, title);
|
|
1540
|
+
return { diagram, mermaid };
|
|
1541
|
+
}
|
|
1542
|
+
var translations = /* @__PURE__ */ new Map();
|
|
1543
|
+
function plantumlToMermaid(source, options) {
|
|
1544
|
+
const key = `${options.maxEdges}\0${source}`;
|
|
1545
|
+
let result = translations.get(key);
|
|
1546
|
+
if (!result) {
|
|
1547
|
+
try {
|
|
1548
|
+
if (source.length > DIAGRAM_SOURCE_LIMIT) fail("diagram-limit", `The diagram source is longer than ${DIAGRAM_SOURCE_LIMIT} characters.`);
|
|
1549
|
+
result = translate(source, options.maxEdges);
|
|
1550
|
+
if (result.mermaid.length > DIAGRAM_TRANSLATED_LIMIT) fail("diagram-limit", "The diagram has too many elements, labels or nested blocks for one slide; split it.");
|
|
1551
|
+
} catch (error) {
|
|
1552
|
+
result = error instanceof PlantumlError ? error.issue : { code: "diagram-syntax", message: `OPF could not read this PlantUML source (${error instanceof Error ? error.message : String(error)}).` };
|
|
1553
|
+
}
|
|
1554
|
+
if (translations.size >= 500) translations.clear();
|
|
1555
|
+
translations.set(key, result);
|
|
1556
|
+
}
|
|
1557
|
+
return "mermaid" in result ? { ok: true, translation: result } : { ok: false, issue: result };
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
export { plantumlToMermaid };
|