@standarx/graph 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.fr.md +436 -0
- package/README.md +435 -2
- package/THIRD_PARTY_NOTICES.md +22 -0
- package/assets/fonts/Inter-Regular.ttf +0 -0
- package/assets/fonts/Inter-SemiBold.ttf +0 -0
- package/assets/fonts/OFL.txt +92 -0
- package/dist/adapter-0bggwh8x.js +393 -0
- package/dist/cli-4m00785g.js +20 -0
- package/dist/cli-5v9761s9.js +330 -0
- package/dist/cli-9f1pdw5q.js +462 -0
- package/dist/cli-a4ax1vkc.js +172 -0
- package/dist/cli-b4n941t8.js +1439 -0
- package/dist/cli-eqq7a3wz.js +1144 -0
- package/dist/cli-gh5166k6.js +1565 -0
- package/dist/cli-kzp16pt5.js +207 -0
- package/dist/cli-mzmjkk5v.js +11 -0
- package/dist/cli-njgyf690.js +1060 -0
- package/dist/cli-nkm2j980.js +141 -0
- package/dist/cli-nyckgf1t.js +4 -0
- package/dist/cli-sfdqkbd1.js +433 -0
- package/dist/cli-txrzzr2q.js +0 -0
- package/dist/cli-vecew2na.js +709 -0
- package/dist/cli-wt9dmbhm.js +560 -0
- package/dist/cli-xhdxp3cj.js +387 -0
- package/dist/cli-ywgtv1cg.js +39 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +415 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +93 -0
- package/dist/core/spatial.d.ts +16 -0
- package/dist/core/threshold.d.ts +1 -0
- package/dist/core/view.d.ts +80 -0
- package/dist/export/index.d.ts +18 -0
- package/dist/export/index.js +172 -0
- package/dist/export/pdf.d.ts +5 -0
- package/dist/export/png.d.ts +4 -0
- package/dist/format/index.d.ts +4 -0
- package/dist/format/index.js +71 -0
- package/dist/format/json-schema.d.ts +2 -0
- package/dist/format/schema.d.ts +787 -0
- package/dist/format/semantic/er.d.ts +3 -0
- package/dist/format/semantic/graph.d.ts +3 -0
- package/dist/format/semantic/sequence.d.ts +3 -0
- package/dist/format/semantic/shared.d.ts +14 -0
- package/dist/format/semantic/state.d.ts +3 -0
- package/dist/format/semantic/tree.d.ts +3 -0
- package/dist/format/transition-label.d.ts +2 -0
- package/dist/format/validate.d.ts +11 -0
- package/dist/html/index.d.ts +3 -0
- package/dist/html/index.js +127 -0
- package/dist/html/layout-worker.d.ts +1 -0
- package/dist/html/layout-worker.generated.d.ts +1 -0
- package/dist/html/mount.d.ts +12 -0
- package/dist/html/page.d.ts +14 -0
- package/dist/html/render.d.ts +7 -0
- package/dist/html/runtime.d.ts +1 -0
- package/dist/html/runtime.generated.d.ts +1 -0
- package/dist/html/shell.d.ts +10 -0
- package/dist/html/svg-adapter.d.ts +8 -0
- package/dist/html/ui.d.ts +34 -0
- package/dist/language/analysis.d.ts +38 -0
- package/dist/language/complete.d.ts +3 -0
- package/dist/language/docs.d.ts +11 -0
- package/dist/language/format.d.ts +17 -0
- package/dist/language/hover.d.ts +3 -0
- package/dist/language/index.d.ts +6 -0
- package/dist/language/index.js +1385 -0
- package/dist/language/navigation.d.ts +9 -0
- package/dist/language/positions.d.ts +7 -0
- package/dist/language/symbols.d.ts +3 -0
- package/dist/language/types.d.ts +34 -0
- package/dist/layout/elk.d.ts +35 -0
- package/dist/layout/er.d.ts +3 -0
- package/dist/layout/font-metrics.d.ts +9 -0
- package/dist/layout/graph.d.ts +3 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +17 -0
- package/dist/layout/measure.d.ts +10 -0
- package/dist/layout/sequence.d.ts +3 -0
- package/dist/layout/shapes.d.ts +16 -0
- package/dist/layout/shared.d.ts +31 -0
- package/dist/layout/state.d.ts +3 -0
- package/dist/layout/tree.d.ts +3 -0
- package/dist/layout/types.d.ts +198 -0
- package/dist/layout-worker.generated-emmvgfb1.js +34 -0
- package/dist/mermaid/common.d.ts +36 -0
- package/dist/mermaid/er.d.ts +3 -0
- package/dist/mermaid/graph.d.ts +4 -0
- package/dist/mermaid/index.d.ts +6 -0
- package/dist/mermaid/index.js +6 -0
- package/dist/mermaid/mindmap.d.ts +3 -0
- package/dist/mermaid/sequence.d.ts +3 -0
- package/dist/mermaid/state.d.ts +3 -0
- package/dist/remark/index.d.ts +9 -0
- package/dist/remark/index.js +104 -0
- package/dist/shared/errors.d.ts +6 -0
- package/dist/shared/package-root.d.ts +5 -0
- package/dist/svg/escape.d.ts +1 -0
- package/dist/svg/index.d.ts +3 -0
- package/dist/svg/index.js +25 -0
- package/dist/svg/render.d.ts +9 -0
- package/dist/svg/theme.d.ts +62 -0
- package/dist/svg-adapter-gq5vmp6q.js +227 -0
- package/dist/text/build.d.ts +10 -0
- package/dist/text/canonical.d.ts +10 -0
- package/dist/text/errors.d.ts +33 -0
- package/dist/text/highlight.d.ts +13 -0
- package/dist/text/index.d.ts +33 -0
- package/dist/text/index.js +27 -0
- package/dist/text/lexer.d.ts +29 -0
- package/dist/text/parser.d.ts +160 -0
- package/dist/text/print.d.ts +6 -0
- package/dist/text/slug.d.ts +1 -0
- package/dist/text/syntax.d.ts +8 -0
- package/dist/version.d.ts +1 -0
- package/dist/webgl/adapter.d.ts +4 -0
- package/dist/webgl/index.d.ts +7 -0
- package/dist/webgl/index.js +15 -0
- package/dist/webgl/runtime.d.ts +1 -0
- package/dist/webgl/runtime.generated.d.ts +1 -0
- package/grammars/standargraph.tmLanguage.json +599 -0
- package/language-configuration.json +35 -0
- package/licenses/EPL-2.0.txt +277 -0
- package/licenses/MPL-2.0.txt +373 -0
- package/package.json +133 -4
- package/schema/graph-document.v1.json +1737 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var package_default = {
|
|
3
|
+
name: "@standarx/graph",
|
|
4
|
+
version: "1.0.0",
|
|
5
|
+
type: "module",
|
|
6
|
+
license: "MIT",
|
|
7
|
+
description: "Declarative graph and diagram rendering",
|
|
8
|
+
keywords: [
|
|
9
|
+
"graph",
|
|
10
|
+
"diagram",
|
|
11
|
+
"svg",
|
|
12
|
+
"webgl",
|
|
13
|
+
"elk",
|
|
14
|
+
"sequence-diagram",
|
|
15
|
+
"visualization",
|
|
16
|
+
"cli",
|
|
17
|
+
"remark"
|
|
18
|
+
],
|
|
19
|
+
homepage: "https://github.com/miralabs-tech/standargraph#readme",
|
|
20
|
+
bugs: {
|
|
21
|
+
url: "https://github.com/miralabs-tech/standargraph/issues"
|
|
22
|
+
},
|
|
23
|
+
repository: {
|
|
24
|
+
type: "git",
|
|
25
|
+
url: "git+https://github.com/miralabs-tech/standargraph.git"
|
|
26
|
+
},
|
|
27
|
+
bin: {
|
|
28
|
+
standargraph: "dist/cli.js"
|
|
29
|
+
},
|
|
30
|
+
exports: {
|
|
31
|
+
"./core": {
|
|
32
|
+
types: "./dist/core/index.d.ts",
|
|
33
|
+
import: "./dist/core/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./format": {
|
|
36
|
+
types: "./dist/format/index.d.ts",
|
|
37
|
+
import: "./dist/format/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./layout": {
|
|
40
|
+
types: "./dist/layout/index.d.ts",
|
|
41
|
+
import: "./dist/layout/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./svg": {
|
|
44
|
+
types: "./dist/svg/index.d.ts",
|
|
45
|
+
import: "./dist/svg/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./html": {
|
|
48
|
+
types: "./dist/html/index.d.ts",
|
|
49
|
+
import: "./dist/html/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./export": {
|
|
52
|
+
types: "./dist/export/index.d.ts",
|
|
53
|
+
import: "./dist/export/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./webgl": {
|
|
56
|
+
types: "./dist/webgl/index.d.ts",
|
|
57
|
+
import: "./dist/webgl/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./remark": {
|
|
60
|
+
types: "./dist/remark/index.d.ts",
|
|
61
|
+
import: "./dist/remark/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./mermaid": {
|
|
64
|
+
types: "./dist/mermaid/index.d.ts",
|
|
65
|
+
import: "./dist/mermaid/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./text": {
|
|
68
|
+
types: "./dist/text/index.d.ts",
|
|
69
|
+
import: "./dist/text/index.js"
|
|
70
|
+
},
|
|
71
|
+
"./language": {
|
|
72
|
+
types: "./dist/language/index.d.ts",
|
|
73
|
+
import: "./dist/language/index.js"
|
|
74
|
+
},
|
|
75
|
+
"./schema/graph-document.v1.json": "./schema/graph-document.v1.json",
|
|
76
|
+
"./grammars/standargraph.tmLanguage.json": "./grammars/standargraph.tmLanguage.json",
|
|
77
|
+
"./language-configuration.json": "./language-configuration.json",
|
|
78
|
+
"./package.json": "./package.json"
|
|
79
|
+
},
|
|
80
|
+
files: [
|
|
81
|
+
"dist",
|
|
82
|
+
"schema",
|
|
83
|
+
"grammars",
|
|
84
|
+
"language-configuration.json",
|
|
85
|
+
"assets",
|
|
86
|
+
"licenses",
|
|
87
|
+
"THIRD_PARTY_NOTICES.md"
|
|
88
|
+
],
|
|
89
|
+
engines: {
|
|
90
|
+
node: ">=20"
|
|
91
|
+
},
|
|
92
|
+
scripts: {
|
|
93
|
+
build: "bun scripts/clean.ts && bun build src/cli.ts src/core/index.ts src/format/index.ts src/layout/index.ts src/svg/index.ts src/webgl/index.ts src/remark/index.ts src/html/index.ts src/export/index.ts src/text/index.ts src/language/index.ts src/mermaid/index.ts --root src --outdir dist --splitting --target node --format esm --packages external && tsc -p tsconfig.build.json",
|
|
94
|
+
typecheck: "tsc --noEmit",
|
|
95
|
+
schema: "bun scripts/schema.ts",
|
|
96
|
+
metrics: "bun scripts/font-metrics.ts",
|
|
97
|
+
runtime: "bun scripts/build-runtime.ts",
|
|
98
|
+
generate: "bun scripts/generate.ts",
|
|
99
|
+
bench: "bun bench/run.ts",
|
|
100
|
+
test: "bun test",
|
|
101
|
+
prepublishOnly: "bun run typecheck && bun test && bun run build",
|
|
102
|
+
smoke: "bun tools/smoke.ts",
|
|
103
|
+
site: "bun scripts/site.ts",
|
|
104
|
+
"test:browser": "bun test --config=bunfig.browser.toml tests/browser"
|
|
105
|
+
},
|
|
106
|
+
devDependencies: {
|
|
107
|
+
"@types/bun": "^1.4.4",
|
|
108
|
+
"@types/mdast": "^4.0.4",
|
|
109
|
+
"@types/node": "^26.6.6",
|
|
110
|
+
"@types/opentype.js": "^1.3.10",
|
|
111
|
+
"@types/pdfkit": "^0.17.7",
|
|
112
|
+
"opentype.js": "^2.0.0",
|
|
113
|
+
"playwright-core": "^1.65.1",
|
|
114
|
+
"rehype-raw": "^7.0.0",
|
|
115
|
+
"rehype-stringify": "^10.0.1",
|
|
116
|
+
"remark-parse": "^11.0.0",
|
|
117
|
+
"remark-rehype": "^11.1.2",
|
|
118
|
+
typescript: "^7.0.2",
|
|
119
|
+
unified: "^11.0.5",
|
|
120
|
+
"vscode-oniguruma": "^2.0.1",
|
|
121
|
+
"vscode-textmate": "^9.3.2"
|
|
122
|
+
},
|
|
123
|
+
dependencies: {
|
|
124
|
+
"@resvg/resvg-wasm": "^2.6.2",
|
|
125
|
+
"@sinclair/typebox": "^0.34.52",
|
|
126
|
+
elkjs: "^0.12.1",
|
|
127
|
+
graphology: "^0.26.0",
|
|
128
|
+
pdfkit: "^0.20.2",
|
|
129
|
+
sigma: "^4.0.6",
|
|
130
|
+
"svg-to-pdfkit": "^0.1.8"
|
|
131
|
+
},
|
|
132
|
+
publishConfig: {
|
|
133
|
+
access: "public",
|
|
134
|
+
provenance: true
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/version.ts
|
|
139
|
+
var VERSION2 = package_default.version;
|
|
140
|
+
|
|
141
|
+
export { VERSION2 };
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import {
|
|
2
|
+
transitionLabel2
|
|
3
|
+
} from "./cli-mzmjkk5v.js";
|
|
4
|
+
|
|
5
|
+
// src/mermaid/common.ts
|
|
6
|
+
var RESERVED = new Set([
|
|
7
|
+
"end",
|
|
8
|
+
"graph",
|
|
9
|
+
"flowchart",
|
|
10
|
+
"subgraph",
|
|
11
|
+
"style",
|
|
12
|
+
"classdef",
|
|
13
|
+
"class",
|
|
14
|
+
"click",
|
|
15
|
+
"linkstyle",
|
|
16
|
+
"direction",
|
|
17
|
+
"state",
|
|
18
|
+
"note",
|
|
19
|
+
"default",
|
|
20
|
+
"call",
|
|
21
|
+
"href"
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
class Ids {
|
|
25
|
+
table = new Map;
|
|
26
|
+
used = new Set;
|
|
27
|
+
add(key, id) {
|
|
28
|
+
let base = id.replace(/[^A-Za-z0-9_]/gu, "_");
|
|
29
|
+
if (/^[0-9]/.test(base) || RESERVED.has(base.toLowerCase()))
|
|
30
|
+
base = `n_${base}`;
|
|
31
|
+
let candidate = base;
|
|
32
|
+
for (let count = 2;this.used.has(candidate); count++)
|
|
33
|
+
candidate = `${base}_${count}`;
|
|
34
|
+
this.used.add(candidate);
|
|
35
|
+
this.table.set(key, candidate);
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
get(key) {
|
|
39
|
+
return this.table.get(key) ?? key;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class Warnings {
|
|
44
|
+
seen = new Set;
|
|
45
|
+
list = [];
|
|
46
|
+
add(message) {
|
|
47
|
+
if (this.seen.has(message))
|
|
48
|
+
return;
|
|
49
|
+
this.seen.add(message);
|
|
50
|
+
this.list.push(message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var FLOW_DIRECTIONS = { down: "TD", right: "LR", up: "BT", left: "RL" };
|
|
54
|
+
var BLOCK_DIRECTIONS = { down: "TB", right: "LR", up: "BT", left: "RL" };
|
|
55
|
+
function mlabel(text) {
|
|
56
|
+
return `"${text.replace(/"/g, "#quot;").replace(/\r?\n/g, "<br>")}"`;
|
|
57
|
+
}
|
|
58
|
+
function plainText(text) {
|
|
59
|
+
return text.replace(/[#;]/g, (character) => character === "#" ? "#35;" : "#59;").replace(/\r?\n/g, "<br>");
|
|
60
|
+
}
|
|
61
|
+
function noteLosses(warnings, item) {
|
|
62
|
+
if (item.type !== undefined)
|
|
63
|
+
warnings.add("type dropped");
|
|
64
|
+
if (item.description !== undefined)
|
|
65
|
+
warnings.add("description dropped");
|
|
66
|
+
if (item.link !== undefined)
|
|
67
|
+
warnings.add("link dropped");
|
|
68
|
+
if (item.position !== undefined)
|
|
69
|
+
warnings.add("position dropped");
|
|
70
|
+
if (item.meta !== undefined)
|
|
71
|
+
warnings.add("metadata dropped");
|
|
72
|
+
}
|
|
73
|
+
function frontMatter(title) {
|
|
74
|
+
if (title === undefined || title === "")
|
|
75
|
+
return [];
|
|
76
|
+
const value = title.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\r?\n/g, " ");
|
|
77
|
+
return ["---", `title: "${value}"`, "---"];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/mermaid/er.ts
|
|
81
|
+
var LEFT = {
|
|
82
|
+
one: "||",
|
|
83
|
+
"zero-or-one": "|o",
|
|
84
|
+
"one-or-more": "}|",
|
|
85
|
+
"zero-or-more": "}o"
|
|
86
|
+
};
|
|
87
|
+
var RIGHT = {
|
|
88
|
+
one: "||",
|
|
89
|
+
"zero-or-one": "o|",
|
|
90
|
+
"one-or-more": "|{",
|
|
91
|
+
"zero-or-more": "o{"
|
|
92
|
+
};
|
|
93
|
+
function safe(text) {
|
|
94
|
+
return text.replace(/[^A-Za-z0-9_()[\]-]/g, "_");
|
|
95
|
+
}
|
|
96
|
+
function attributeType(type) {
|
|
97
|
+
if (type === undefined || type === "")
|
|
98
|
+
return "any";
|
|
99
|
+
const name = safe(type);
|
|
100
|
+
return /^[A-Za-z]/.test(name) ? name : `t_${name}`;
|
|
101
|
+
}
|
|
102
|
+
function erLines(doc, warnings) {
|
|
103
|
+
const ids = new Ids;
|
|
104
|
+
const lines = ["erDiagram", ` direction ${BLOCK_DIRECTIONS[doc.direction ?? "down"]}`];
|
|
105
|
+
for (const entity of doc.entities) {
|
|
106
|
+
noteLosses(warnings, entity);
|
|
107
|
+
const id = ids.add(entity.id, entity.id);
|
|
108
|
+
const label = entity.label ?? entity.id;
|
|
109
|
+
lines.push(` ${id}${label === id ? "" : `[${mlabel(label)}]`} {`);
|
|
110
|
+
for (const attribute of entity.attributes ?? []) {
|
|
111
|
+
if (attribute.nullable !== undefined)
|
|
112
|
+
warnings.add("nullable dropped");
|
|
113
|
+
const keys = (attribute.keys ?? []).map((key) => key.toUpperCase());
|
|
114
|
+
const note = attribute.note === undefined || attribute.note === "" ? "" : ` "${attribute.note.replace(/"/g, "").replace(/\r?\n/g, " ")}"`;
|
|
115
|
+
const suffix = keys.length === 0 ? "" : ` ${keys.join(", ")}`;
|
|
116
|
+
lines.push(` ${attributeType(attribute.type)} ${safe(attribute.name)}${suffix}${note}`);
|
|
117
|
+
}
|
|
118
|
+
lines.push(" }");
|
|
119
|
+
}
|
|
120
|
+
for (const relation of doc.relations ?? []) {
|
|
121
|
+
noteLosses(warnings, relation);
|
|
122
|
+
if (relation.fromCardinality === undefined || relation.toCardinality === undefined) {
|
|
123
|
+
warnings.add('relation cardinality missing, written as "one"');
|
|
124
|
+
}
|
|
125
|
+
const left = LEFT[relation.fromCardinality ?? "one"];
|
|
126
|
+
const right = RIGHT[relation.toCardinality ?? "one"];
|
|
127
|
+
const operator = relation.identifying ?? true ? "--" : "..";
|
|
128
|
+
lines.push(` ${ids.get(relation.from)} ${left}${operator}${right} ${ids.get(relation.to)} : ${mlabel(relation.label ?? "")}`);
|
|
129
|
+
}
|
|
130
|
+
return lines;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/mermaid/graph.ts
|
|
134
|
+
var DELIMITERS = {
|
|
135
|
+
box: ["(", ")"],
|
|
136
|
+
rect: ["[", "]"],
|
|
137
|
+
pill: ["([", "])"],
|
|
138
|
+
diamond: ["{", "}"],
|
|
139
|
+
circle: ["((", "))"],
|
|
140
|
+
ellipse: ["((", "))"],
|
|
141
|
+
hexagon: ["{{", "}}"],
|
|
142
|
+
parallelogram: ["[/", "/]"],
|
|
143
|
+
cylinder: ["[(", ")]"],
|
|
144
|
+
subroutine: ["[[", "]]"],
|
|
145
|
+
document: ["[", "]"]
|
|
146
|
+
};
|
|
147
|
+
function shapeNode(id, label, shape, warnings) {
|
|
148
|
+
if (shape === "ellipse")
|
|
149
|
+
warnings.add('shape "ellipse" written as a circle');
|
|
150
|
+
if (shape === "document")
|
|
151
|
+
warnings.add('shape "document" written as a rectangle');
|
|
152
|
+
const [open, close] = DELIMITERS[shape ?? "box"];
|
|
153
|
+
return `${id}${open}${mlabel(label)}${close}`;
|
|
154
|
+
}
|
|
155
|
+
function push(map, key, item) {
|
|
156
|
+
const list = map.get(key);
|
|
157
|
+
if (list === undefined)
|
|
158
|
+
map.set(key, [item]);
|
|
159
|
+
else
|
|
160
|
+
list.push(item);
|
|
161
|
+
}
|
|
162
|
+
function graphLines(doc, warnings) {
|
|
163
|
+
const ids = new Ids;
|
|
164
|
+
for (const node of doc.nodes)
|
|
165
|
+
ids.add(`node:${node.id}`, node.id);
|
|
166
|
+
const groups = doc.groups ?? [];
|
|
167
|
+
for (const group of groups)
|
|
168
|
+
ids.add(`group:${group.id}`, group.id);
|
|
169
|
+
const nodesByGroup = new Map;
|
|
170
|
+
for (const node of doc.nodes) {
|
|
171
|
+
noteLosses(warnings, node);
|
|
172
|
+
push(nodesByGroup, node.group ?? "", node);
|
|
173
|
+
}
|
|
174
|
+
const groupsByParent = new Map;
|
|
175
|
+
for (const group of groups) {
|
|
176
|
+
noteLosses(warnings, group);
|
|
177
|
+
push(groupsByParent, group.parent ?? "", group);
|
|
178
|
+
}
|
|
179
|
+
const lines = [`flowchart ${FLOW_DIRECTIONS[doc.direction ?? "down"]}`];
|
|
180
|
+
const emit = (container, depth) => {
|
|
181
|
+
const indent = " ".repeat(depth);
|
|
182
|
+
for (const node of nodesByGroup.get(container) ?? []) {
|
|
183
|
+
const id = ids.get(`node:${node.id}`);
|
|
184
|
+
lines.push(`${indent}${shapeNode(id, node.label ?? node.id, node.shape, warnings)}`);
|
|
185
|
+
}
|
|
186
|
+
for (const group of groupsByParent.get(container) ?? []) {
|
|
187
|
+
const id = ids.get(`group:${group.id}`);
|
|
188
|
+
lines.push(`${indent}subgraph ${id} [${mlabel(group.label ?? group.id)}]`);
|
|
189
|
+
emit(group.id, depth + 1);
|
|
190
|
+
lines.push(`${indent}end`);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
emit("", 1);
|
|
194
|
+
for (const edge of doc.edges ?? []) {
|
|
195
|
+
noteLosses(warnings, edge);
|
|
196
|
+
const confidence = edge.meta?.provenance?.confidence;
|
|
197
|
+
const dotted = confidence === "inferred" || confidence === "unknown";
|
|
198
|
+
const directed = edge.directed ?? true;
|
|
199
|
+
const arrow = directed ? dotted ? "-.->" : "-->" : dotted ? "-.-" : "---";
|
|
200
|
+
const label = edge.label === undefined || edge.label === "" ? "" : `|${mlabel(edge.label)}|`;
|
|
201
|
+
lines.push(` ${ids.get(`node:${edge.from}`)} ${arrow}${label} ${ids.get(`node:${edge.to}`)}`);
|
|
202
|
+
}
|
|
203
|
+
return lines;
|
|
204
|
+
}
|
|
205
|
+
function treeFlowLines(doc, warnings) {
|
|
206
|
+
const ids = new Ids;
|
|
207
|
+
for (const node of doc.nodes)
|
|
208
|
+
ids.add(node.id, node.id);
|
|
209
|
+
const lines = [`flowchart ${FLOW_DIRECTIONS[doc.direction ?? "down"]}`];
|
|
210
|
+
for (const node of doc.nodes) {
|
|
211
|
+
noteLosses(warnings, node);
|
|
212
|
+
lines.push(` ${shapeNode(ids.get(node.id), node.label, node.shape, warnings)}`);
|
|
213
|
+
}
|
|
214
|
+
for (const node of doc.nodes) {
|
|
215
|
+
if (node.parent !== undefined)
|
|
216
|
+
lines.push(` ${ids.get(node.parent)} --- ${ids.get(node.id)}`);
|
|
217
|
+
}
|
|
218
|
+
return lines;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/mermaid/mindmap.ts
|
|
222
|
+
var DELIMITERS2 = {
|
|
223
|
+
box: ["(", ")"],
|
|
224
|
+
pill: ["(", ")"],
|
|
225
|
+
rect: ["[", "]"],
|
|
226
|
+
circle: ["((", "))"],
|
|
227
|
+
hexagon: ["{{", "}}"]
|
|
228
|
+
};
|
|
229
|
+
function nodeText(label) {
|
|
230
|
+
const flat = label.replace(/\r?\n/g, " ");
|
|
231
|
+
if (/[()[\]{}]/.test(flat) || flat.startsWith('"')) {
|
|
232
|
+
return `"\`${flat.replace(/`/g, "")}\`"`;
|
|
233
|
+
}
|
|
234
|
+
return flat;
|
|
235
|
+
}
|
|
236
|
+
function mindmapLines(doc, warnings) {
|
|
237
|
+
const ids = new Ids;
|
|
238
|
+
const children = new Map;
|
|
239
|
+
let root;
|
|
240
|
+
for (const node of doc.nodes) {
|
|
241
|
+
ids.add(node.id, node.id);
|
|
242
|
+
noteLosses(warnings, node);
|
|
243
|
+
if (node.parent === undefined) {
|
|
244
|
+
root ??= node;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const list = children.get(node.parent);
|
|
248
|
+
if (list === undefined)
|
|
249
|
+
children.set(node.parent, [node]);
|
|
250
|
+
else
|
|
251
|
+
list.push(node);
|
|
252
|
+
}
|
|
253
|
+
const lines = ["mindmap"];
|
|
254
|
+
const stack = root === undefined ? [] : [{ node: root, depth: 1 }];
|
|
255
|
+
while (stack.length > 0) {
|
|
256
|
+
const { node, depth } = stack.pop();
|
|
257
|
+
const shape = node.shape ?? "box";
|
|
258
|
+
let delimiters = DELIMITERS2[shape];
|
|
259
|
+
if (delimiters === undefined) {
|
|
260
|
+
warnings.add(`shape "${shape}" written as a rectangle`);
|
|
261
|
+
delimiters = ["[", "]"];
|
|
262
|
+
}
|
|
263
|
+
lines.push(`${" ".repeat(depth)}${ids.get(node.id)}${delimiters[0]}${nodeText(node.label)}${delimiters[1]}`);
|
|
264
|
+
const own = children.get(node.id) ?? [];
|
|
265
|
+
for (let index = own.length - 1;index >= 0; index--) {
|
|
266
|
+
stack.push({ node: own[index], depth: depth + 1 });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return lines;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/mermaid/sequence.ts
|
|
273
|
+
var ARROWS = { sync: "->>", async: "-)", reply: "-->>" };
|
|
274
|
+
function sequenceLines(doc, warnings) {
|
|
275
|
+
const ids = new Ids;
|
|
276
|
+
const lines = ["sequenceDiagram"];
|
|
277
|
+
for (const participant of doc.participants) {
|
|
278
|
+
noteLosses(warnings, participant);
|
|
279
|
+
const id = ids.add(participant.id, participant.id);
|
|
280
|
+
const label = plainText(participant.label ?? participant.id);
|
|
281
|
+
lines.push(label === id ? ` participant ${id}` : ` participant ${id} as ${label}`);
|
|
282
|
+
}
|
|
283
|
+
for (const message of doc.messages) {
|
|
284
|
+
noteLosses(warnings, message);
|
|
285
|
+
const arrow = ARROWS[message.style ?? "sync"];
|
|
286
|
+
const text = message.label === undefined || message.label === "" ? "" : ` ${plainText(message.label)}`;
|
|
287
|
+
lines.push(` ${ids.get(message.from)}${arrow}${ids.get(message.to)}:${text}`);
|
|
288
|
+
}
|
|
289
|
+
return lines;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/mermaid/state.ts
|
|
293
|
+
var MARKER = "[*]";
|
|
294
|
+
function isTerminal(state) {
|
|
295
|
+
return state.pseudo === "initial" || state.pseudo === "final";
|
|
296
|
+
}
|
|
297
|
+
function stateLines(doc, warnings) {
|
|
298
|
+
const ids = new Ids;
|
|
299
|
+
const byId = new Map;
|
|
300
|
+
const children = new Map;
|
|
301
|
+
for (const state of doc.states) {
|
|
302
|
+
byId.set(state.id, state);
|
|
303
|
+
noteLosses(warnings, state);
|
|
304
|
+
if (!isTerminal(state))
|
|
305
|
+
ids.add(state.id, state.id);
|
|
306
|
+
const key = state.parent ?? "";
|
|
307
|
+
const list = children.get(key);
|
|
308
|
+
if (list === undefined)
|
|
309
|
+
children.set(key, [state]);
|
|
310
|
+
else
|
|
311
|
+
list.push(state);
|
|
312
|
+
}
|
|
313
|
+
const chain = (region) => {
|
|
314
|
+
const result = [region];
|
|
315
|
+
let current = region;
|
|
316
|
+
while (current !== "") {
|
|
317
|
+
current = byId.get(current)?.parent ?? "";
|
|
318
|
+
result.push(current);
|
|
319
|
+
}
|
|
320
|
+
return result;
|
|
321
|
+
};
|
|
322
|
+
const lowestCommon = (first, second) => {
|
|
323
|
+
const above = new Set(chain(first));
|
|
324
|
+
return chain(second).find((region) => above.has(region)) ?? "";
|
|
325
|
+
};
|
|
326
|
+
const transitionsByRegion = new Map;
|
|
327
|
+
for (const transition of doc.transitions ?? []) {
|
|
328
|
+
noteLosses(warnings, transition);
|
|
329
|
+
const from = byId.get(transition.from);
|
|
330
|
+
const to = byId.get(transition.to);
|
|
331
|
+
const fromTerminal = isTerminal(from);
|
|
332
|
+
const toTerminal = isTerminal(to);
|
|
333
|
+
let region;
|
|
334
|
+
if (fromTerminal)
|
|
335
|
+
region = from.parent ?? "";
|
|
336
|
+
else if (toTerminal)
|
|
337
|
+
region = to.parent ?? "";
|
|
338
|
+
else
|
|
339
|
+
region = lowestCommon(from.parent ?? "", to.parent ?? "");
|
|
340
|
+
if (!fromTerminal && !toTerminal && from.parent !== undefined && to.parent !== undefined && from.parent !== to.parent) {
|
|
341
|
+
warnings.add("a transition between internal states of different composites may be refused by Mermaid");
|
|
342
|
+
}
|
|
343
|
+
const label = transitionLabel2(transition);
|
|
344
|
+
const left = fromTerminal ? MARKER : ids.get(from.id);
|
|
345
|
+
const right = toTerminal ? MARKER : ids.get(to.id);
|
|
346
|
+
const line = `${left} --> ${right}${label === "" ? "" : ` : ${plainText(label)}`}`;
|
|
347
|
+
const list = transitionsByRegion.get(region);
|
|
348
|
+
if (list === undefined)
|
|
349
|
+
transitionsByRegion.set(region, [line]);
|
|
350
|
+
else
|
|
351
|
+
list.push(line);
|
|
352
|
+
}
|
|
353
|
+
const lines = ["stateDiagram-v2", ` direction ${BLOCK_DIRECTIONS[doc.direction ?? "down"]}`];
|
|
354
|
+
const emit = (region, depth) => {
|
|
355
|
+
const indent = " ".repeat(depth);
|
|
356
|
+
for (const state of children.get(region) ?? []) {
|
|
357
|
+
if (isTerminal(state))
|
|
358
|
+
continue;
|
|
359
|
+
const id = ids.get(state.id);
|
|
360
|
+
if (state.pseudo === "choice" || state.pseudo === "fork" || state.pseudo === "join") {
|
|
361
|
+
lines.push(`${indent}state ${id} <<${state.pseudo}>>`);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (state.pseudo === "history") {
|
|
365
|
+
warnings.add('pseudo-state "history" written as a plain state');
|
|
366
|
+
lines.push(`${indent}state "H" as ${id}`);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
lines.push(`${indent}state ${mlabel(state.label ?? state.id)} as ${id}`);
|
|
370
|
+
for (const action of state.actions ?? []) {
|
|
371
|
+
lines.push(`${indent}${id} : ${plainText(action)}`);
|
|
372
|
+
}
|
|
373
|
+
if (children.has(state.id)) {
|
|
374
|
+
lines.push(`${indent}state ${id} {`);
|
|
375
|
+
emit(state.id, depth + 1);
|
|
376
|
+
lines.push(`${indent}}`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
for (const line of transitionsByRegion.get(region) ?? [])
|
|
380
|
+
lines.push(`${indent}${line}`);
|
|
381
|
+
};
|
|
382
|
+
emit("", 1);
|
|
383
|
+
return lines;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/mermaid/index.ts
|
|
387
|
+
var MAX_EDGES = 500;
|
|
388
|
+
var MAX_TEXT_SIZE = 50000;
|
|
389
|
+
function body(doc, warnings) {
|
|
390
|
+
switch (doc.kind) {
|
|
391
|
+
case "graph":
|
|
392
|
+
return graphLines(doc, warnings);
|
|
393
|
+
case "sequence":
|
|
394
|
+
return sequenceLines(doc, warnings);
|
|
395
|
+
case "state":
|
|
396
|
+
return stateLines(doc, warnings);
|
|
397
|
+
case "er":
|
|
398
|
+
return erLines(doc, warnings);
|
|
399
|
+
case "tree":
|
|
400
|
+
return doc.layout === "mindmap" ? mindmapLines(doc, warnings) : treeFlowLines(doc, warnings);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function edgeCount(doc) {
|
|
404
|
+
switch (doc.kind) {
|
|
405
|
+
case "graph":
|
|
406
|
+
return doc.edges?.length ?? 0;
|
|
407
|
+
case "sequence":
|
|
408
|
+
return doc.messages.length;
|
|
409
|
+
case "state":
|
|
410
|
+
return doc.transitions?.length ?? 0;
|
|
411
|
+
case "er":
|
|
412
|
+
return doc.relations?.length ?? 0;
|
|
413
|
+
case "tree":
|
|
414
|
+
return Math.max(doc.nodes.length - 1, 0);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function toMermaid2(doc) {
|
|
418
|
+
const warnings = new Warnings;
|
|
419
|
+
noteLosses(warnings, doc);
|
|
420
|
+
const lines = [...frontMatter(doc.title), ...body(doc, warnings)];
|
|
421
|
+
const text = `${lines.join(`
|
|
422
|
+
`)}
|
|
423
|
+
`;
|
|
424
|
+
if (edgeCount(doc) > MAX_EDGES) {
|
|
425
|
+
warnings.add("More than 500 edges: Mermaid's default maxEdges may refuse to render");
|
|
426
|
+
}
|
|
427
|
+
if (text.length > MAX_TEXT_SIZE) {
|
|
428
|
+
warnings.add("Mermaid's default maxTextSize (50000) is exceeded");
|
|
429
|
+
}
|
|
430
|
+
return { text, warnings: warnings.list };
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export { toMermaid2 };
|
|
File without changes
|