@grethel-labs/excaliplant 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +302 -0
- package/index.mjs +89 -0
- package/package.json +53 -0
- package/src/layout/elk_layout.mjs +517 -0
- package/src/layout/sequence_layout.mjs +90 -0
- package/src/layout/sizing.mjs +160 -0
- package/src/model/diagram.mjs +207 -0
- package/src/parser/component_context.mjs +129 -0
- package/src/parser/engine.mjs +87 -0
- package/src/parser/plantuml.mjs +126 -0
- package/src/parser/plugins/component/connections.mjs +26 -0
- package/src/parser/plugins/component/containers.mjs +36 -0
- package/src/parser/plugins/component/notes.mjs +65 -0
- package/src/parser/plugins/component/preamble.mjs +25 -0
- package/src/parser/plugins/component/shapes.mjs +111 -0
- package/src/parser/plugins/sequence/messages.mjs +37 -0
- package/src/parser/plugins/sequence/notes.mjs +84 -0
- package/src/parser/plugins/sequence/participants.mjs +18 -0
- package/src/parser/plugins/sequence/preamble.mjs +11 -0
- package/src/parser/sequence_context.mjs +39 -0
- package/src/parser/utils.mjs +150 -0
- package/src/render/excalidraw.mjs +736 -0
- package/src/render/sequence_render.mjs +201 -0
- package/src/render/svg.mjs +167 -0
- package/src/style/colors.mjs +75 -0
- package/src/style/text.mjs +42 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Shared helpers used by the parser engine and all plugins.
|
|
2
|
+
//
|
|
3
|
+
// Keeping these here lets each plugin file stay tiny and self-contained;
|
|
4
|
+
// adding a new plugin never forces a change to the engine.
|
|
5
|
+
|
|
6
|
+
export const STEREOTYPE = /<<\s*([^>]+?)\s*>>/;
|
|
7
|
+
export const TITLE_LINE = /^title\s+(.+)$/;
|
|
8
|
+
|
|
9
|
+
// Lines we always silently skip. Plugins can extend this via the engine's
|
|
10
|
+
// `skip` array if needed.
|
|
11
|
+
export const ALWAYS_SKIP = [
|
|
12
|
+
/^@startuml/, /^@enduml/, /^skinparam/, /^!/,
|
|
13
|
+
/^hide\s/, /^show\s/, /^scale\s/,
|
|
14
|
+
/^autonumber\b/, /^activate\s/, /^deactivate\s/,
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export function stripComment(line) {
|
|
18
|
+
// PlantUML: ' starts a line comment except inside a string.
|
|
19
|
+
const idx = line.indexOf("'");
|
|
20
|
+
if (idx === 0) return "";
|
|
21
|
+
if (idx > 0 && /\s/.test(line[idx - 1])) return line.slice(0, idx);
|
|
22
|
+
return line;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function stripQuotes(s) {
|
|
26
|
+
if (s.length >= 2 && s.startsWith('"') && s.endsWith('"')) return s.slice(1, -1);
|
|
27
|
+
return s;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function slug(s) {
|
|
31
|
+
return String(s).toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Replace literal "\n" sequences with real newlines.
|
|
35
|
+
export function unescapeLabel(s) {
|
|
36
|
+
return String(s ?? "").replace(/\\n/g, "\n");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Normalise inline `{ … }` so that `frame "F" as f { [a] [b] }` parses
|
|
40
|
+
// cleanly. We split each line on `{` and `}` boundaries OUTSIDE quoted
|
|
41
|
+
// strings, then re-attach lone `{` to the preceding header line.
|
|
42
|
+
export function explodeBraces(lines) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const raw of lines) {
|
|
45
|
+
let buf = "";
|
|
46
|
+
let inStr = false;
|
|
47
|
+
for (let i = 0; i < raw.length; i++) {
|
|
48
|
+
const c = raw[i];
|
|
49
|
+
if (c === '"') { inStr = !inStr; buf += c; continue; }
|
|
50
|
+
if (!inStr && (c === "{" || c === "}")) {
|
|
51
|
+
if (buf.trim()) out.push(buf);
|
|
52
|
+
out.push(c);
|
|
53
|
+
buf = "";
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
buf += c;
|
|
57
|
+
}
|
|
58
|
+
if (buf.trim() || (!buf && raw === "")) out.push(buf);
|
|
59
|
+
}
|
|
60
|
+
const stitched = [];
|
|
61
|
+
for (const ln of out) {
|
|
62
|
+
if (ln === "{" && stitched.length) {
|
|
63
|
+
const prevIdx = stitched.length - 1;
|
|
64
|
+
const prev = stitched[prevIdx];
|
|
65
|
+
if (prev && !prev.endsWith("{") && prev.trim() && prev.trim() !== "}") {
|
|
66
|
+
stitched[prevIdx] = `${prev.trimEnd()} {`;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
stitched.push(ln);
|
|
71
|
+
}
|
|
72
|
+
return stitched;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Map a shape keyword to the canonical model shape name.
|
|
76
|
+
export function normaliseShape(kw) {
|
|
77
|
+
switch (kw) {
|
|
78
|
+
case "component": return "component";
|
|
79
|
+
case "actor": return "actor";
|
|
80
|
+
case "usecase": return "usecase";
|
|
81
|
+
case "database": return "database";
|
|
82
|
+
case "node": return "node";
|
|
83
|
+
case "cloud": return "cloud";
|
|
84
|
+
case "interface": return "interface";
|
|
85
|
+
case "entity": return "entity";
|
|
86
|
+
case "class": return "class";
|
|
87
|
+
case "rectangle": return "rectangle";
|
|
88
|
+
case "boundary": return "interface";
|
|
89
|
+
case "control": return "interface";
|
|
90
|
+
default: return "rectangle";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Decode a PlantUML connection operator into structural fields.
|
|
95
|
+
// Returns null if the op is not a recognised arrow.
|
|
96
|
+
export function classifyArrow(op) {
|
|
97
|
+
let directionHint = null;
|
|
98
|
+
const dirMatch = op.match(/-(up|down|left|right)-/i);
|
|
99
|
+
if (dirMatch) {
|
|
100
|
+
directionHint = dirMatch[1].toLowerCase();
|
|
101
|
+
op = op.replace(/-(?:up|down|left|right)-/i, "--");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const bidir = /<.*>/.test(op);
|
|
105
|
+
const startsWithLeft = op.startsWith("<");
|
|
106
|
+
const endsWithRight = op.endsWith(">");
|
|
107
|
+
const reversed = startsWithLeft && !endsWithRight;
|
|
108
|
+
const dashed = op.includes(".");
|
|
109
|
+
|
|
110
|
+
if (op.includes("|>") || op.includes("<|")) {
|
|
111
|
+
return {
|
|
112
|
+
kind: dashed ? "realization" : "inheritance",
|
|
113
|
+
dashed,
|
|
114
|
+
reversed: op.includes("<|") && !op.includes("|>"),
|
|
115
|
+
startArrowhead: null,
|
|
116
|
+
endArrowhead: "triangle_outline",
|
|
117
|
+
directionHint,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (op.startsWith("*") || op.endsWith("*")) {
|
|
121
|
+
return {
|
|
122
|
+
kind: "composition",
|
|
123
|
+
dashed,
|
|
124
|
+
reversed: op.endsWith("*"),
|
|
125
|
+
startArrowhead: "diamond",
|
|
126
|
+
endArrowhead: null,
|
|
127
|
+
directionHint,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (op.startsWith("o") || op.endsWith("o")) {
|
|
131
|
+
return {
|
|
132
|
+
kind: "aggregation",
|
|
133
|
+
dashed,
|
|
134
|
+
reversed: op.endsWith("o"),
|
|
135
|
+
startArrowhead: "diamond_outline",
|
|
136
|
+
endArrowhead: null,
|
|
137
|
+
directionHint,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (!/[-.]/.test(op)) return null;
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
kind: dashed ? "dependency" : "default",
|
|
144
|
+
dashed,
|
|
145
|
+
reversed,
|
|
146
|
+
startArrowhead: bidir ? "arrow" : null,
|
|
147
|
+
endArrowhead: (endsWithRight || bidir) ? "arrow" : (reversed ? null : "arrow"),
|
|
148
|
+
directionHint,
|
|
149
|
+
};
|
|
150
|
+
}
|