@standarx/graph 0.0.0-stage → 1.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.fr.md +438 -0
- package/README.md +437 -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-abzdy8pn.js +1144 -0
- package/dist/cli-gh5166k6.js +1565 -0
- package/dist/cli-m29a3wgx.js +579 -0
- package/dist/cli-mzmjkk5v.js +11 -0
- package/dist/cli-nhmh6yxk.js +2485 -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-ywgtv1cg.js +39 -0
- package/dist/cli-z3ccx2y4.js +141 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +413 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +91 -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 +170 -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 +69 -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 +125 -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/actions.d.ts +3 -0
- package/dist/language/analysis.d.ts +38 -0
- package/dist/language/complete.d.ts +3 -0
- package/dist/language/diagnostics.d.ts +14 -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 +8 -0
- package/dist/language/index.js +1560 -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 +46 -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 +16 -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-xsmtzrfj.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 +102 -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 +25 -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,560 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FONT_METRICS,
|
|
3
|
+
LINE_HEIGHT,
|
|
4
|
+
measureText2,
|
|
5
|
+
LABEL_FONT,
|
|
6
|
+
CAPTION_FONT,
|
|
7
|
+
EDGE_LABEL_FONT,
|
|
8
|
+
GROUP_FONT,
|
|
9
|
+
PAD_X,
|
|
10
|
+
SELF_LOOP_WIDTH,
|
|
11
|
+
SELF_LOOP_HEIGHT,
|
|
12
|
+
round,
|
|
13
|
+
boxSize,
|
|
14
|
+
ACTIONS_GAP,
|
|
15
|
+
keysText,
|
|
16
|
+
attributeTypeText,
|
|
17
|
+
CYLINDER_RY,
|
|
18
|
+
DOCUMENT_WAVE,
|
|
19
|
+
SUBROUTINE_BAR,
|
|
20
|
+
textOffsetY,
|
|
21
|
+
outline
|
|
22
|
+
} from "./cli-gh5166k6.js";
|
|
23
|
+
import {
|
|
24
|
+
esc,
|
|
25
|
+
resolveTheme2,
|
|
26
|
+
withPalette,
|
|
27
|
+
typesPresent,
|
|
28
|
+
escapedTheme,
|
|
29
|
+
themeVariables2,
|
|
30
|
+
typeRules
|
|
31
|
+
} from "./cli-5v9761s9.js";
|
|
32
|
+
|
|
33
|
+
// src/svg/render.ts
|
|
34
|
+
function typeStyleOf(types, type) {
|
|
35
|
+
return type !== undefined && Object.hasOwn(types, type) ? types[type] : {};
|
|
36
|
+
}
|
|
37
|
+
var DASH = { inferred: "6 4", unknown: "2 3", reply: "5 3" };
|
|
38
|
+
var UNSAFE_HREF = /^[\s\u0000-\u001f]*(javascript|data|vbscript):/i;
|
|
39
|
+
function n(value) {
|
|
40
|
+
return String(round(value));
|
|
41
|
+
}
|
|
42
|
+
function baseline(top, size, weight) {
|
|
43
|
+
const metrics = FONT_METRICS[weight];
|
|
44
|
+
const ascent = metrics.ascender / metrics.unitsPerEm * size;
|
|
45
|
+
const descent = -metrics.descender / metrics.unitsPerEm * size;
|
|
46
|
+
return top + (LINE_HEIGHT * size - (ascent + descent)) / 2 + ascent;
|
|
47
|
+
}
|
|
48
|
+
function textLines(text, x, top, style, cls, fill, anchor = "middle") {
|
|
49
|
+
return text.split(`
|
|
50
|
+
`).map((line, index) => {
|
|
51
|
+
const y = baseline(top + index * LINE_HEIGHT * style.size, style.size, style.weight);
|
|
52
|
+
const weight = style.weight === "semibold" ? ' font-weight="600"' : "";
|
|
53
|
+
return `<text class="${cls}" x="${n(x)}" y="${n(y)}" text-anchor="${anchor}" font-size="${style.size}"${weight} fill="${fill}">${esc(line)}</text>`;
|
|
54
|
+
}).join("");
|
|
55
|
+
}
|
|
56
|
+
function metaTitle(meta) {
|
|
57
|
+
if (meta === undefined)
|
|
58
|
+
return "";
|
|
59
|
+
const lines = [];
|
|
60
|
+
const provenance = meta.provenance;
|
|
61
|
+
if (provenance !== undefined) {
|
|
62
|
+
const confidence = provenance.confidence === undefined ? "" : ` (${provenance.confidence})`;
|
|
63
|
+
lines.push(`Source: ${provenance.source}${confidence}`);
|
|
64
|
+
if (provenance.tool !== undefined)
|
|
65
|
+
lines.push(`Tool: ${provenance.tool}`);
|
|
66
|
+
}
|
|
67
|
+
if (meta.coverage !== undefined) {
|
|
68
|
+
lines.push(`Coverage: ${round(meta.coverage * 100)}%`);
|
|
69
|
+
}
|
|
70
|
+
if (meta.freshness !== undefined)
|
|
71
|
+
lines.push(`Freshness: ${meta.freshness}`);
|
|
72
|
+
if (lines.length === 0)
|
|
73
|
+
return "";
|
|
74
|
+
return `<title>${esc(lines.join(`
|
|
75
|
+
`))}</title>`;
|
|
76
|
+
}
|
|
77
|
+
function confidenceOf(meta) {
|
|
78
|
+
return meta?.provenance?.confidence;
|
|
79
|
+
}
|
|
80
|
+
function dashAttr(dash) {
|
|
81
|
+
return dash === undefined ? "" : ` stroke-dasharray="${dash}"`;
|
|
82
|
+
}
|
|
83
|
+
function confidenceDash(meta) {
|
|
84
|
+
const confidence = confidenceOf(meta);
|
|
85
|
+
if (confidence === "inferred")
|
|
86
|
+
return DASH.inferred;
|
|
87
|
+
if (confidence === "unknown")
|
|
88
|
+
return DASH.unknown;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
function css(tokens, types) {
|
|
92
|
+
return [
|
|
93
|
+
`.sg-root{${themeVariables2({ tokens })}}`,
|
|
94
|
+
".sg-bg{fill:var(--sg-bg)}",
|
|
95
|
+
".sg-text{fill:var(--sg-fg)}",
|
|
96
|
+
".sg-muted{fill:var(--sg-muted)}",
|
|
97
|
+
".sg-node{fill:var(--sg-node-fill);stroke:var(--sg-node-stroke)}",
|
|
98
|
+
".sg-node.sg-unknown{fill:var(--sg-unknown-fill)}",
|
|
99
|
+
".sg-node-detail{fill:none;stroke:var(--sg-node-stroke)}",
|
|
100
|
+
".sg-divider{stroke:var(--sg-node-stroke)}",
|
|
101
|
+
".sg-header{fill:var(--sg-header-fill)}",
|
|
102
|
+
".sg-pseudo{fill:var(--sg-fg)}",
|
|
103
|
+
".sg-group{fill:var(--sg-group-fill);stroke:var(--sg-group-stroke)}",
|
|
104
|
+
".sg-edge{stroke:var(--sg-edge)}",
|
|
105
|
+
".sg-arrow-filled{fill:var(--sg-edge);stroke:var(--sg-edge)}",
|
|
106
|
+
".sg-arrow-open{stroke:var(--sg-edge)}",
|
|
107
|
+
".sg-label-bg{fill:var(--sg-label-bg)}",
|
|
108
|
+
".sg-accent{fill:var(--sg-accent)}",
|
|
109
|
+
".sg-lifeline{stroke:var(--sg-lifeline)}",
|
|
110
|
+
typeRules(types, ".sg-root")
|
|
111
|
+
].join("");
|
|
112
|
+
}
|
|
113
|
+
function defs(theme, resolved, styles) {
|
|
114
|
+
return [
|
|
115
|
+
"<defs>",
|
|
116
|
+
styles ? `<style>${css(resolved.tokens, resolved.types)}</style>` : "",
|
|
117
|
+
`<marker id="sg-arrow-filled" viewBox="0 0 10 10" refX="10" refY="5" markerUnits="userSpaceOnUse" markerWidth="10" markerHeight="10" orient="auto"><path class="sg-arrow-filled" d="M0,0 L10,5 L0,10 z" fill="${theme.edge}" stroke="${theme.edge}" stroke-width="1" stroke-linejoin="round"/></marker>`,
|
|
118
|
+
`<marker id="sg-arrow-open" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="userSpaceOnUse" markerWidth="10" markerHeight="10" orient="auto"><path class="sg-arrow-open" d="M1,1 L9,5 L1,9" fill="none" stroke="${theme.edge}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></marker>`,
|
|
119
|
+
"</defs>"
|
|
120
|
+
].join("");
|
|
121
|
+
}
|
|
122
|
+
function wrapLink(content, link) {
|
|
123
|
+
if (link === undefined || link === "" || UNSAFE_HREF.test(link)) {
|
|
124
|
+
return content;
|
|
125
|
+
}
|
|
126
|
+
return `<a href="${esc(link)}">${content}</a>`;
|
|
127
|
+
}
|
|
128
|
+
function data(entries) {
|
|
129
|
+
return entries.filter((entry) => entry[1] !== undefined).map(([name, value]) => ` data-${name}="${esc(String(value))}"`).join("");
|
|
130
|
+
}
|
|
131
|
+
function group(kind, id, meta, body, attributes = "") {
|
|
132
|
+
return `<g data-kind="${kind}" data-id="${esc(id)}"${attributes}>${metaTitle(meta)}${body}</g>`;
|
|
133
|
+
}
|
|
134
|
+
function labelBoxSvg(box, text, theme, withBackground) {
|
|
135
|
+
const lines = text.split(`
|
|
136
|
+
`).length;
|
|
137
|
+
const textHeight = lines * LINE_HEIGHT * EDGE_LABEL_FONT.size;
|
|
138
|
+
const top = box.y + (box.height - textHeight) / 2;
|
|
139
|
+
const background = withBackground ? `<rect class="sg-label-bg sg-edge-label" x="${n(box.x)}" y="${n(box.y)}" width="${n(box.width)}" height="${n(box.height)}" rx="3" fill="${theme.labelBg}"/>` : "";
|
|
140
|
+
return background + textLines(text, box.x + box.width / 2, top, EDGE_LABEL_FONT, "sg-text sg-edge-label", theme.fg);
|
|
141
|
+
}
|
|
142
|
+
function renderGroup(item, theme) {
|
|
143
|
+
const dash = confidenceDash(item.meta);
|
|
144
|
+
const rect = `<rect class="sg-group" x="${n(item.x)}" y="${n(item.y)}" width="${n(item.width)}" height="${n(item.height)}" rx="10" fill="${theme.groupFill}" stroke="${theme.groupStroke}" stroke-width="1"${dashAttr(dash)}/>`;
|
|
145
|
+
const label = item.label === undefined || item.label === "" ? "" : textLines(item.label, item.x + PAD_X, item.y + 8, GROUP_FONT, "sg-muted sg-label", theme.muted, "start");
|
|
146
|
+
return group("group", item.id, item.meta, rect + label, data([
|
|
147
|
+
["confidence", confidenceOf(item.meta)],
|
|
148
|
+
["depth", item.depth]
|
|
149
|
+
]));
|
|
150
|
+
}
|
|
151
|
+
function pathOf(points) {
|
|
152
|
+
return points.map((point, index) => `${index === 0 ? "M" : "L"}${n(point.x)},${n(point.y)}`).join(" ");
|
|
153
|
+
}
|
|
154
|
+
function renderEdge(item, theme) {
|
|
155
|
+
const dash = confidenceDash(item.meta);
|
|
156
|
+
const marker = item.directed ? ' marker-end="url(#sg-arrow-filled)"' : "";
|
|
157
|
+
const path = `<path class="sg-edge" d="${pathOf(item.points)}" fill="none" stroke="${theme.edge}" stroke-width="1.5" stroke-linejoin="round"${dashAttr(dash)}${marker}/>`;
|
|
158
|
+
const label = item.labelBox === undefined || item.label === undefined ? "" : labelBoxSvg(item.labelBox, item.label, theme, true);
|
|
159
|
+
return group("edge", item.id, item.meta, path + label, data([
|
|
160
|
+
["type", item.type],
|
|
161
|
+
["confidence", confidenceOf(item.meta)],
|
|
162
|
+
["from", item.from],
|
|
163
|
+
["to", item.to],
|
|
164
|
+
["directed", item.directed ? undefined : "false"]
|
|
165
|
+
]));
|
|
166
|
+
}
|
|
167
|
+
function shapeGeometry(shape, box) {
|
|
168
|
+
const { x, y, width: w, height: h } = box;
|
|
169
|
+
const rect = (rx) => ({
|
|
170
|
+
tag: "rect",
|
|
171
|
+
attrs: ` x="${n(x)}" y="${n(y)}" width="${n(w)}" height="${n(h)}" rx="${n(rx)}"`
|
|
172
|
+
});
|
|
173
|
+
const polygon = () => ({
|
|
174
|
+
tag: "polygon",
|
|
175
|
+
attrs: ` points="${outline(shape, box).map((point) => `${n(point.x)},${n(point.y)}`).join(" ")}"`
|
|
176
|
+
});
|
|
177
|
+
switch (shape) {
|
|
178
|
+
case "box":
|
|
179
|
+
return rect(8);
|
|
180
|
+
case "rect":
|
|
181
|
+
case "subroutine":
|
|
182
|
+
return rect(0);
|
|
183
|
+
case "pill":
|
|
184
|
+
return rect(h / 2);
|
|
185
|
+
case "diamond":
|
|
186
|
+
case "hexagon":
|
|
187
|
+
case "parallelogram":
|
|
188
|
+
return polygon();
|
|
189
|
+
case "circle":
|
|
190
|
+
return {
|
|
191
|
+
tag: "circle",
|
|
192
|
+
attrs: ` cx="${n(x + w / 2)}" cy="${n(y + h / 2)}" r="${n(w / 2)}"`
|
|
193
|
+
};
|
|
194
|
+
case "ellipse":
|
|
195
|
+
return {
|
|
196
|
+
tag: "ellipse",
|
|
197
|
+
attrs: ` cx="${n(x + w / 2)}" cy="${n(y + h / 2)}" rx="${n(w / 2)}" ry="${n(h / 2)}"`
|
|
198
|
+
};
|
|
199
|
+
case "cylinder": {
|
|
200
|
+
const arc = `A${n(w / 2)},${CYLINDER_RY} 0 0 1`;
|
|
201
|
+
return {
|
|
202
|
+
tag: "path",
|
|
203
|
+
attrs: ` d="M${n(x)},${n(y + CYLINDER_RY)} ${arc} ${n(x + w)},${n(y + CYLINDER_RY)} V${n(y + h - CYLINDER_RY)} ${arc} ${n(x)},${n(y + h - CYLINDER_RY)} Z"`
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
case "document": {
|
|
207
|
+
const a = DOCUMENT_WAVE;
|
|
208
|
+
return {
|
|
209
|
+
tag: "path",
|
|
210
|
+
attrs: ` d="M${n(x)},${n(y)} H${n(x + w)} V${n(y + h - a)} C${n(x + 0.75 * w)},${n(y + h - 3 * a)} ${n(x + 0.25 * w)},${n(y + h + a)} ${n(x)},${n(y + h - a)} Z"`
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function shapeDetails(shape, box, theme) {
|
|
216
|
+
const { x, y, width: w, height: h } = box;
|
|
217
|
+
const style = `fill="none" stroke="${theme.nodeStroke}" stroke-width="1.5"`;
|
|
218
|
+
if (shape === "cylinder") {
|
|
219
|
+
return `<path class="sg-node-detail" d="M${n(x)},${n(y + CYLINDER_RY)} A${n(w / 2)},${CYLINDER_RY} 0 0 0 ${n(x + w)},${n(y + CYLINDER_RY)}" ${style}/>`;
|
|
220
|
+
}
|
|
221
|
+
if (shape === "subroutine") {
|
|
222
|
+
return [x + SUBROUTINE_BAR, x + w - SUBROUTINE_BAR].map((lineX) => `<line class="sg-node-detail" x1="${n(lineX)}" y1="${n(y)}" x2="${n(lineX)}" y2="${n(y + h)}" ${style}/>`).join("");
|
|
223
|
+
}
|
|
224
|
+
return "";
|
|
225
|
+
}
|
|
226
|
+
function renderNode(item, index, theme, types, extra = []) {
|
|
227
|
+
const confidence = confidenceOf(item.meta);
|
|
228
|
+
const dash = confidenceDash(item.meta);
|
|
229
|
+
const unknown = confidence === "unknown";
|
|
230
|
+
const typed = typeStyleOf(types, item.type);
|
|
231
|
+
const fill = unknown ? theme.unknownFill : typed.fill ?? theme.nodeFill;
|
|
232
|
+
const stroke = typed.stroke ?? theme.nodeStroke;
|
|
233
|
+
const cls = unknown ? "sg-node sg-unknown" : "sg-node";
|
|
234
|
+
const shape = item.shape ?? "box";
|
|
235
|
+
const geometry = shapeGeometry(shape, item);
|
|
236
|
+
let body = `<${geometry.tag} class="${cls}"${geometry.attrs} fill="${fill}" stroke="${stroke}" stroke-width="1.5"${dashAttr(dash)}/>${shapeDetails(shape, item, theme)}`;
|
|
237
|
+
const label = measureText2(item.label, LABEL_FONT);
|
|
238
|
+
const caption = item.type === undefined ? undefined : measureText2(item.type, CAPTION_FONT);
|
|
239
|
+
const block = label.height + (caption?.height ?? 0);
|
|
240
|
+
const top = item.y + (item.height - block) / 2 + textOffsetY(shape);
|
|
241
|
+
const cx = item.x + item.width / 2;
|
|
242
|
+
body += textLines(item.label, cx, top, LABEL_FONT, "sg-text sg-label", typed.text ?? theme.fg);
|
|
243
|
+
if (item.type !== undefined) {
|
|
244
|
+
body += textLines(item.type, cx, top + label.height, CAPTION_FONT, "sg-muted sg-caption", theme.muted);
|
|
245
|
+
}
|
|
246
|
+
const coverage = item.meta?.coverage;
|
|
247
|
+
if (coverage !== undefined) {
|
|
248
|
+
const clip = `sg-clip-${index}`;
|
|
249
|
+
body = `<clipPath id="${clip}"><${geometry.tag}${geometry.attrs}/></clipPath>` + body + `<rect class="sg-accent" x="${n(item.x)}" y="${n(item.y + item.height - 4)}" width="${n(coverage * item.width)}" height="4" fill="${theme.accent}" clip-path="url(#${clip})"/>`;
|
|
250
|
+
}
|
|
251
|
+
return wrapLink(group("node", item.id, item.meta, body, data([
|
|
252
|
+
["type", item.type],
|
|
253
|
+
["confidence", confidence],
|
|
254
|
+
["shape", shape],
|
|
255
|
+
...extra
|
|
256
|
+
])), item.link);
|
|
257
|
+
}
|
|
258
|
+
function renderGraph(laid, theme, types) {
|
|
259
|
+
return [
|
|
260
|
+
...laid.groups.map((item) => renderGroup(item, theme)),
|
|
261
|
+
...laid.edges.map((item) => renderEdge(item, theme)),
|
|
262
|
+
...laid.nodes.map((item, index) => renderNode(item, index, theme, types))
|
|
263
|
+
].join("");
|
|
264
|
+
}
|
|
265
|
+
function renderParticipant(item, lifelineBottom, theme, types) {
|
|
266
|
+
const lifeline = `<line class="sg-lifeline" x1="${n(item.lifelineX)}" y1="${n(item.y + item.height)}" x2="${n(item.lifelineX)}" y2="${n(lifelineBottom)}" stroke="${theme.lifeline}" stroke-width="1" stroke-dasharray="4 4"/>`;
|
|
267
|
+
const confidence = confidenceOf(item.meta);
|
|
268
|
+
const unknown = confidence === "unknown";
|
|
269
|
+
const typed = typeStyleOf(types, item.type);
|
|
270
|
+
const fill = unknown ? theme.unknownFill : typed.fill ?? theme.nodeFill;
|
|
271
|
+
const cls = unknown ? "sg-node sg-unknown" : "sg-node";
|
|
272
|
+
let body = `<rect class="${cls}" x="${n(item.x)}" y="${n(item.y)}" width="${n(item.width)}" height="${n(item.height)}" rx="8" fill="${fill}" stroke="${typed.stroke ?? theme.nodeStroke}" stroke-width="1.5"${dashAttr(confidenceDash(item.meta))}/>`;
|
|
273
|
+
const label = measureText2(item.label, LABEL_FONT);
|
|
274
|
+
const caption = item.type === undefined ? undefined : measureText2(item.type, CAPTION_FONT);
|
|
275
|
+
const top = item.y + (item.height - label.height - (caption?.height ?? 0)) / 2;
|
|
276
|
+
const cx = item.x + item.width / 2;
|
|
277
|
+
body += textLines(item.label, cx, top, LABEL_FONT, "sg-text sg-label", typed.text ?? theme.fg);
|
|
278
|
+
if (item.type !== undefined) {
|
|
279
|
+
body += textLines(item.type, cx, top + label.height, CAPTION_FONT, "sg-muted sg-caption", theme.muted);
|
|
280
|
+
}
|
|
281
|
+
return group("participant", item.id, item.meta, lifeline + body, data([
|
|
282
|
+
["type", item.type],
|
|
283
|
+
["confidence", confidence]
|
|
284
|
+
]));
|
|
285
|
+
}
|
|
286
|
+
function renderMessage(item, theme) {
|
|
287
|
+
const dash = confidenceDash(item.meta) ?? (item.style === "reply" ? DASH.reply : undefined);
|
|
288
|
+
const marker = item.style === "sync" ? "url(#sg-arrow-filled)" : "url(#sg-arrow-open)";
|
|
289
|
+
const d = item.self ? `M${n(item.x1)},${n(item.y)} H${n(item.x1 + SELF_LOOP_WIDTH)} V${n(item.y + SELF_LOOP_HEIGHT)} H${n(item.x1)}` : `M${n(item.x1)},${n(item.y)} L${n(item.x2)},${n(item.y)}`;
|
|
290
|
+
const path = `<path class="sg-edge" d="${d}" fill="none" stroke="${theme.edge}" stroke-width="1.5" stroke-linejoin="round"${dashAttr(dash)} marker-end="${marker}"/>`;
|
|
291
|
+
const label = item.labelBox === undefined || item.label === undefined ? "" : labelBoxSvg(item.labelBox, item.label, theme, false);
|
|
292
|
+
return group("message", String(item.index), item.meta, path + label, data([
|
|
293
|
+
["confidence", confidenceOf(item.meta)],
|
|
294
|
+
["from", item.from],
|
|
295
|
+
["to", item.to],
|
|
296
|
+
["style", item.style]
|
|
297
|
+
]));
|
|
298
|
+
}
|
|
299
|
+
function renderSequence(laid, theme, types) {
|
|
300
|
+
return [
|
|
301
|
+
...laid.participants.map((item) => renderParticipant(item, laid.lifelineBottom, theme, types)),
|
|
302
|
+
...laid.messages.map((item) => renderMessage(item, theme))
|
|
303
|
+
].join("");
|
|
304
|
+
}
|
|
305
|
+
function nodeLook(meta, type, theme, types) {
|
|
306
|
+
const unknown = confidenceOf(meta) === "unknown";
|
|
307
|
+
const typed = typeStyleOf(types, type);
|
|
308
|
+
const fill = unknown ? theme.unknownFill : typed.fill ?? theme.nodeFill;
|
|
309
|
+
const stroke = typed.stroke ?? theme.nodeStroke;
|
|
310
|
+
return {
|
|
311
|
+
cls: unknown ? "sg-node sg-unknown" : "sg-node",
|
|
312
|
+
paint: `fill="${fill}" stroke="${stroke}" stroke-width="1.5"${dashAttr(confidenceDash(meta))}`,
|
|
313
|
+
typed
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function actionLines(actions, x, top, theme) {
|
|
317
|
+
return actions.map((action, index) => textLines(action, x, top + index * LINE_HEIGHT * CAPTION_FONT.size, CAPTION_FONT, "sg-muted sg-caption", theme.muted, "start")).join("");
|
|
318
|
+
}
|
|
319
|
+
function pseudoBody(item, theme, types) {
|
|
320
|
+
const cx = item.x + item.width / 2;
|
|
321
|
+
const cy = item.y + item.height / 2;
|
|
322
|
+
const look = nodeLook(item.meta, item.type, theme, types);
|
|
323
|
+
const circle = (r, cls, paint) => `<circle class="${cls}" cx="${n(cx)}" cy="${n(cy)}" r="${r}" ${paint}/>`;
|
|
324
|
+
const solid = `fill="${theme.fg}"`;
|
|
325
|
+
switch (item.pseudo) {
|
|
326
|
+
case "initial":
|
|
327
|
+
return circle(10, "sg-pseudo", solid);
|
|
328
|
+
case "final":
|
|
329
|
+
return circle(12, look.cls, look.paint) + circle(7, "sg-pseudo", solid);
|
|
330
|
+
case "history": {
|
|
331
|
+
const glyph = measureText2("H", LABEL_FONT);
|
|
332
|
+
return circle(12, look.cls, look.paint) + textLines("H", cx, cy - glyph.height / 2, LABEL_FONT, "sg-text", theme.fg);
|
|
333
|
+
}
|
|
334
|
+
case "choice": {
|
|
335
|
+
const points = outline("diamond", item).map((point) => `${n(point.x)},${n(point.y)}`).join(" ");
|
|
336
|
+
return `<polygon class="${look.cls}" points="${points}" ${look.paint}/>`;
|
|
337
|
+
}
|
|
338
|
+
default:
|
|
339
|
+
return `<rect class="sg-pseudo" x="${n(item.x)}" y="${n(item.y)}" width="${n(item.width)}" height="${n(item.height)}" ${solid}/>`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function compositeBody(item, theme) {
|
|
343
|
+
const rect = `<rect class="sg-group" x="${n(item.x)}" y="${n(item.y)}" width="${n(item.width)}" height="${n(item.height)}" rx="10" fill="${theme.groupFill}" stroke="${theme.groupStroke}" stroke-width="1"${dashAttr(confidenceDash(item.meta))}/>`;
|
|
344
|
+
const title = measureText2(item.label, GROUP_FONT);
|
|
345
|
+
const label = item.label === "" ? "" : textLines(item.label, item.x + PAD_X, item.y + 8, GROUP_FONT, "sg-muted sg-label", theme.muted, "start");
|
|
346
|
+
const actions = item.actions ?? [];
|
|
347
|
+
return rect + label + actionLines(actions, item.x + PAD_X, item.y + 8 + title.height + ACTIONS_GAP / 2, theme);
|
|
348
|
+
}
|
|
349
|
+
function simpleBody(item, index, theme, types) {
|
|
350
|
+
const look = nodeLook(item.meta, item.type, theme, types);
|
|
351
|
+
const actions = item.actions ?? [];
|
|
352
|
+
const geometry = {
|
|
353
|
+
tag: "rect",
|
|
354
|
+
attrs: ` x="${n(item.x)}" y="${n(item.y)}" width="${n(item.width)}" height="${n(item.height)}" rx="10"`
|
|
355
|
+
};
|
|
356
|
+
let body = `<rect class="${look.cls}"${geometry.attrs} ${look.paint}/>`;
|
|
357
|
+
const header = actions.length === 0 ? item.height : boxSize(item.label, item.type, 80).height;
|
|
358
|
+
const label = measureText2(item.label, LABEL_FONT);
|
|
359
|
+
const caption = item.type === undefined ? undefined : measureText2(item.type, CAPTION_FONT);
|
|
360
|
+
const top = item.y + (header - label.height - (caption?.height ?? 0)) / 2;
|
|
361
|
+
const cx = item.x + item.width / 2;
|
|
362
|
+
body += textLines(item.label, cx, top, LABEL_FONT, "sg-text sg-label", look.typed.text ?? theme.fg);
|
|
363
|
+
if (item.type !== undefined) {
|
|
364
|
+
body += textLines(item.type, cx, top + label.height, CAPTION_FONT, "sg-muted sg-caption", theme.muted);
|
|
365
|
+
}
|
|
366
|
+
if (actions.length > 0) {
|
|
367
|
+
body += `<line class="sg-divider" x1="${n(item.x)}" y1="${n(item.y + header)}" x2="${n(item.x + item.width)}" y2="${n(item.y + header)}" stroke="${theme.nodeStroke}" stroke-width="1"/>`;
|
|
368
|
+
body += actionLines(actions, item.x + PAD_X, item.y + header + ACTIONS_GAP, theme);
|
|
369
|
+
}
|
|
370
|
+
const coverage = item.meta?.coverage;
|
|
371
|
+
if (coverage !== undefined) {
|
|
372
|
+
const clip = `sg-clip-${index}`;
|
|
373
|
+
body = `<clipPath id="${clip}"><rect${geometry.attrs}/></clipPath>` + body + `<rect class="sg-accent" x="${n(item.x)}" y="${n(item.y + item.height - 4)}" width="${n(coverage * item.width)}" height="4" fill="${theme.accent}" clip-path="url(#${clip})"/>`;
|
|
374
|
+
}
|
|
375
|
+
return body;
|
|
376
|
+
}
|
|
377
|
+
function renderStateItem(item, index, theme, types) {
|
|
378
|
+
const body = item.composite ? compositeBody(item, theme) : item.pseudo !== undefined ? pseudoBody(item, theme, types) : simpleBody(item, index, theme, types);
|
|
379
|
+
return wrapLink(group("state", item.id, item.meta, body, data([
|
|
380
|
+
["type", item.type],
|
|
381
|
+
["confidence", confidenceOf(item.meta)],
|
|
382
|
+
["pseudo", item.pseudo],
|
|
383
|
+
["composite", item.composite ? "true" : undefined]
|
|
384
|
+
])), item.link);
|
|
385
|
+
}
|
|
386
|
+
function renderTransition(item, theme) {
|
|
387
|
+
const path = `<path class="sg-edge" d="${pathOf(item.points)}" fill="none" stroke="${theme.edge}" stroke-width="1.5" stroke-linejoin="round"${dashAttr(confidenceDash(item.meta))} marker-end="url(#sg-arrow-filled)"/>`;
|
|
388
|
+
const label = item.labelBox === undefined || item.label === undefined ? "" : labelBoxSvg(item.labelBox, item.label, theme, true);
|
|
389
|
+
return group("transition", item.id, item.meta, path + label, data([
|
|
390
|
+
["type", item.type],
|
|
391
|
+
["confidence", confidenceOf(item.meta)],
|
|
392
|
+
["from", item.from],
|
|
393
|
+
["to", item.to]
|
|
394
|
+
]));
|
|
395
|
+
}
|
|
396
|
+
function renderState(laid, theme, types) {
|
|
397
|
+
const composites = laid.states.map((item, index) => ({ item, index })).filter(({ item }) => item.composite).sort((a, b) => a.item.depth - b.item.depth);
|
|
398
|
+
const simple = laid.states.map((item, index) => ({ item, index })).filter(({ item }) => !item.composite);
|
|
399
|
+
return [
|
|
400
|
+
...composites.map(({ item, index }) => renderStateItem(item, index, theme, types)),
|
|
401
|
+
...laid.transitions.map((item) => renderTransition(item, theme)),
|
|
402
|
+
...simple.map(({ item, index }) => renderStateItem(item, index, theme, types))
|
|
403
|
+
].join("");
|
|
404
|
+
}
|
|
405
|
+
function attributeRow(attribute, entity, theme) {
|
|
406
|
+
const keys = keysText(attribute.keys);
|
|
407
|
+
const typeText = attributeTypeText(attribute);
|
|
408
|
+
const top = attribute.y + (attribute.height - LINE_HEIGHT * EDGE_LABEL_FONT.size) / 2;
|
|
409
|
+
const keyTop = attribute.y + (attribute.height - LINE_HEIGHT * CAPTION_FONT.size) / 2;
|
|
410
|
+
let body = attribute.note === undefined ? "" : `<title>${esc(attribute.note)}</title>`;
|
|
411
|
+
if (keys !== "") {
|
|
412
|
+
body += textLines(keys, entity.x + entity.columns.key, keyTop, CAPTION_FONT, "sg-muted sg-attr-key", theme.muted, "start");
|
|
413
|
+
}
|
|
414
|
+
body += textLines(attribute.name, entity.x + entity.columns.name, top, EDGE_LABEL_FONT, "sg-text", theme.fg, "start");
|
|
415
|
+
if (typeText !== "") {
|
|
416
|
+
body += textLines(typeText, entity.x + entity.columns.type, top, EDGE_LABEL_FONT, "sg-muted sg-attr-type", theme.muted, "start");
|
|
417
|
+
}
|
|
418
|
+
return `<g class="sg-attr"${data([
|
|
419
|
+
["attr", attribute.name],
|
|
420
|
+
["keys", attribute.keys === undefined ? undefined : attribute.keys.join(" ")]
|
|
421
|
+
])}>${body}</g>`;
|
|
422
|
+
}
|
|
423
|
+
function renderEntity(item, index, theme, types) {
|
|
424
|
+
const look = nodeLook(item.meta, item.type, theme, types);
|
|
425
|
+
const frame = ` x="${n(item.x)}" y="${n(item.y)}" width="${n(item.width)}" height="${n(item.height)}" rx="4"`;
|
|
426
|
+
const clip = `sg-clip-${index}`;
|
|
427
|
+
let body = `<clipPath id="${clip}"><rect${frame}/></clipPath>` + `<rect class="${look.cls}"${frame} ${look.paint}/>` + `<rect class="sg-header" x="${n(item.x)}" y="${n(item.y)}" width="${n(item.width)}" height="${n(item.headerHeight)}" fill="${theme.headerFill}" clip-path="url(#${clip})"/>`;
|
|
428
|
+
const label = measureText2(item.label, LABEL_FONT);
|
|
429
|
+
const caption = item.type === undefined ? undefined : measureText2(item.type, CAPTION_FONT);
|
|
430
|
+
const top = item.y + (item.headerHeight - label.height - (caption?.height ?? 0)) / 2;
|
|
431
|
+
const cx = item.x + item.width / 2;
|
|
432
|
+
body += textLines(item.label, cx, top, LABEL_FONT, "sg-text sg-label", look.typed.text ?? theme.fg);
|
|
433
|
+
if (item.type !== undefined) {
|
|
434
|
+
body += textLines(item.type, cx, top + label.height, CAPTION_FONT, "sg-muted sg-caption", theme.muted);
|
|
435
|
+
}
|
|
436
|
+
body += item.attributes.map((attribute) => attributeRow(attribute, item, theme)).join("");
|
|
437
|
+
const coverage = item.meta?.coverage;
|
|
438
|
+
if (coverage !== undefined) {
|
|
439
|
+
body += `<rect class="sg-accent" x="${n(item.x)}" y="${n(item.y + item.height - 4)}" width="${n(coverage * item.width)}" height="4" fill="${theme.accent}" clip-path="url(#${clip})"/>`;
|
|
440
|
+
}
|
|
441
|
+
return wrapLink(group("entity", item.id, item.meta, body, data([
|
|
442
|
+
["type", item.type],
|
|
443
|
+
["confidence", confidenceOf(item.meta)]
|
|
444
|
+
])), item.link);
|
|
445
|
+
}
|
|
446
|
+
function cardinalityMarks(cardinality, from, next, theme) {
|
|
447
|
+
if (cardinality === undefined || from === undefined || next === undefined)
|
|
448
|
+
return "";
|
|
449
|
+
const length = Math.hypot(next.x - from.x, next.y - from.y);
|
|
450
|
+
if (length === 0)
|
|
451
|
+
return "";
|
|
452
|
+
const ux = (next.x - from.x) / length;
|
|
453
|
+
const uy = (next.y - from.y) / length;
|
|
454
|
+
const vx = -uy;
|
|
455
|
+
const vy = ux;
|
|
456
|
+
const at = (distance, side = 0) => `${n(from.x + distance * ux + side * vx)},${n(from.y + distance * uy + side * vy)}`;
|
|
457
|
+
const stroke = `fill="none" stroke="${theme.edge}" stroke-width="1.5" stroke-linecap="round"`;
|
|
458
|
+
const line = (d) => `<path class="sg-edge" d="${d}" ${stroke}/>`;
|
|
459
|
+
const bar = (distance) => line(`M${at(distance, 6)} L${at(distance, -6)}`);
|
|
460
|
+
const circle = (distance) => `<circle class="sg-bg sg-edge" cx="${n(from.x + distance * ux)}" cy="${n(from.y + distance * uy)}" r="4" fill="${theme.bg}" stroke="${theme.edge}" stroke-width="1.5"/>`;
|
|
461
|
+
const foot = () => line(`M${at(12)} L${at(0, 7)} M${at(12)} L${at(0)} M${at(12)} L${at(0, -7)}`);
|
|
462
|
+
switch (cardinality) {
|
|
463
|
+
case "one":
|
|
464
|
+
return bar(6) + bar(11);
|
|
465
|
+
case "zero-or-one":
|
|
466
|
+
return bar(6) + circle(15);
|
|
467
|
+
case "one-or-more":
|
|
468
|
+
return foot() + bar(15);
|
|
469
|
+
case "zero-or-more":
|
|
470
|
+
return foot() + circle(17);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function renderRelation(item, theme) {
|
|
474
|
+
const dash = confidenceDash(item.meta) ?? (item.identifying ? undefined : "4 3");
|
|
475
|
+
const path = `<path class="sg-edge" d="${pathOf(item.points)}" fill="none" stroke="${theme.edge}" stroke-width="1.5" stroke-linejoin="round"${dashAttr(dash)}/>`;
|
|
476
|
+
const points = item.points;
|
|
477
|
+
const marks = cardinalityMarks(item.fromCardinality, points[0], points[1], theme) + cardinalityMarks(item.toCardinality, points[points.length - 1], points[points.length - 2], theme);
|
|
478
|
+
const label = item.labelBox === undefined || item.label === undefined ? "" : labelBoxSvg(item.labelBox, item.label, theme, true);
|
|
479
|
+
return group("relation", item.id, item.meta, path + marks + label, data([
|
|
480
|
+
["type", item.type],
|
|
481
|
+
["confidence", confidenceOf(item.meta)],
|
|
482
|
+
["from", item.from],
|
|
483
|
+
["to", item.to],
|
|
484
|
+
["from-cardinality", item.fromCardinality],
|
|
485
|
+
["to-cardinality", item.toCardinality],
|
|
486
|
+
["identifying", String(item.identifying)]
|
|
487
|
+
]));
|
|
488
|
+
}
|
|
489
|
+
function renderEr(laid, theme, types) {
|
|
490
|
+
return [
|
|
491
|
+
...laid.relations.map((item) => renderRelation(item, theme)),
|
|
492
|
+
...laid.entities.map((item, index) => renderEntity(item, index, theme, types))
|
|
493
|
+
].join("");
|
|
494
|
+
}
|
|
495
|
+
function renderTreeEdge(item, theme) {
|
|
496
|
+
const [first, ...rest] = item.points;
|
|
497
|
+
const d = first === undefined ? "" : item.curve === "bezier" ? `M${n(first.x)},${n(first.y)} C${rest.map((point) => `${n(point.x)},${n(point.y)}`).join(" ")}` : pathOf(item.points);
|
|
498
|
+
return group("edge", item.id, undefined, `<path class="sg-edge" d="${d}" fill="none" stroke="${theme.edge}" stroke-width="1.5" stroke-linejoin="round"/>`, data([
|
|
499
|
+
["from", item.from],
|
|
500
|
+
["to", item.to]
|
|
501
|
+
]));
|
|
502
|
+
}
|
|
503
|
+
function renderTreeNode(item, index, theme, types) {
|
|
504
|
+
return renderNode(item, index, theme, types, [
|
|
505
|
+
["depth", item.depth],
|
|
506
|
+
["side", item.side]
|
|
507
|
+
]);
|
|
508
|
+
}
|
|
509
|
+
function renderTree(laid, theme, types) {
|
|
510
|
+
return [
|
|
511
|
+
...laid.edges.map((item) => renderTreeEdge(item, theme)),
|
|
512
|
+
...laid.nodes.map((item, index) => renderTreeNode(item, index, theme, types))
|
|
513
|
+
].join("");
|
|
514
|
+
}
|
|
515
|
+
function renderScene(laidOut, theme, types) {
|
|
516
|
+
switch (laidOut.kind) {
|
|
517
|
+
case "graph":
|
|
518
|
+
return renderGraph(laidOut, theme, types);
|
|
519
|
+
case "sequence":
|
|
520
|
+
return renderSequence(laidOut, theme, types);
|
|
521
|
+
case "state":
|
|
522
|
+
return renderState(laidOut, theme, types);
|
|
523
|
+
case "er":
|
|
524
|
+
return renderEr(laidOut, theme, types);
|
|
525
|
+
case "tree":
|
|
526
|
+
return renderTree(laidOut, theme, types);
|
|
527
|
+
default:
|
|
528
|
+
return unreachable(laidOut);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
function unreachable(value) {
|
|
532
|
+
throw new Error(`Unsupported scene: ${JSON.stringify(value)}`);
|
|
533
|
+
}
|
|
534
|
+
function renderSvg2(laidOut, options = {}) {
|
|
535
|
+
const resolved = withPalette(resolveTheme2(options.theme), typesPresent(laidOut));
|
|
536
|
+
const { tokens: theme, types } = escapedTheme(resolved);
|
|
537
|
+
const standalone = options.standalone ?? true;
|
|
538
|
+
const width = n(laidOut.width);
|
|
539
|
+
const height = n(laidOut.height);
|
|
540
|
+
const head = standalone ? `<?xml version="1.0" encoding="UTF-8"?>
|
|
541
|
+
<svg xmlns="http://www.w3.org/2000/svg"` : "<svg";
|
|
542
|
+
const title = laidOut.title === undefined ? "" : `<title>${esc(laidOut.title)}</title>`;
|
|
543
|
+
const body = renderScene(laidOut, theme, types);
|
|
544
|
+
const svg = [
|
|
545
|
+
`${head} class="sg-root" data-diagram="${laidOut.kind}"${laidOut.kind === "tree" ? ` data-layout="${laidOut.layout}"` : ""} version="1.1" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" font-family="Inter, system-ui, sans-serif">`,
|
|
546
|
+
title,
|
|
547
|
+
defs(theme, resolved, options.styles ?? true),
|
|
548
|
+
`<rect class="sg-bg" x="0" y="0" width="${width}" height="${height}" fill="${theme.bg}"/>`,
|
|
549
|
+
body,
|
|
550
|
+
"</svg>",
|
|
551
|
+
""
|
|
552
|
+
].filter((part, index, all) => part !== "" || index === all.length - 1).join(`
|
|
553
|
+
`);
|
|
554
|
+
const prefix = options.idPrefix;
|
|
555
|
+
if (prefix === undefined || prefix === "sg")
|
|
556
|
+
return svg;
|
|
557
|
+
return svg.replaceAll('id="sg-', `id="${esc(prefix)}-`).replaceAll("url(#sg-", `url(#${esc(prefix)}-`);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export { renderSvg2 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lightTheme
|
|
3
|
+
} from "./cli-5v9761s9.js";
|
|
4
|
+
import {
|
|
5
|
+
svgViewport,
|
|
6
|
+
renderPage,
|
|
7
|
+
renderWebglHtml2
|
|
8
|
+
} from "./cli-a4ax1vkc.js";
|
|
9
|
+
import {
|
|
10
|
+
renderSvg2
|
|
11
|
+
} from "./cli-wt9dmbhm.js";
|
|
12
|
+
import {
|
|
13
|
+
WEBGL_THRESHOLD2
|
|
14
|
+
} from "./cli-nyckgf1t.js";
|
|
15
|
+
|
|
16
|
+
// src/html/runtime.generated.ts
|
|
17
|
+
var RUNTIME_JS = '(()=>{var pe=1.25;var He={size:12,weight:"regular"};var ge=30,ye=20;var ut=Math.ceil(pe*He.size+6);function Pe(n,r){return n.x<=r.x+r.width&&r.x<=n.x+n.width&&n.y<=r.y+r.height&&r.y<=n.y+n.height}function be(n,r){let c=n.length,L=1/0,v=1/0,l=-1/0,T=-1/0;for(let{box:s}of n)L=Math.min(L,s.x),v=Math.min(v,s.y),l=Math.max(l,s.x+s.width),T=Math.max(T,s.y+s.height);if(c===0)L=v=0,l=T=1;let I=Math.max(1,l-L),g=Math.max(1,T-v),y=r??Math.max(32,Math.sqrt(I*g/Math.max(1,c))*2);while((Math.floor(I/y)+1)*(Math.floor(g/y)+1)>262144)y*=1.5;let D=Math.floor(I/y)+1,H=Math.floor(g/y)+1,O=new Map,A=[],_=(s)=>Math.min(D-1,Math.max(0,Math.floor((s-L)/y))),P=(s)=>Math.min(H-1,Math.max(0,Math.floor((s-v)/y)));n.forEach(({box:s},E)=>{let k=_(s.x),m=_(s.x+s.width),i=P(s.y),f=P(s.y+s.height);if((m-k+1)*(f-i+1)>64){A.push(E);return}for(let S=i;S<=f;S++)for(let C=k;C<=m;C++){let R=S*D+C,F=O.get(R);if(F===void 0)O.set(R,[E]);else F.push(E)}});let h=new Int32Array(c),a=0;function b(s){a+=1;let E=[],k=(m)=>{if(h[m]===a)return;h[m]=a;let i=n[m];if(Pe(i.box,s))E.push(i.value)};if(s.x<=l&&s.x+s.width>=L&&s.y<=T&&s.y+s.height>=v){let m=_(s.x),i=_(s.x+s.width),f=P(s.y),S=P(s.y+s.height);for(let C=f;C<=S;C++)for(let R=m;R<=i;R++){let F=O.get(C*D+R);if(F===void 0)continue;for(let G of F)k(G)}}for(let m of A)k(m);return E}return{size:c,query:b,at:(s,E)=>b({x:s,y:E,width:0,height:0})}}var Ee=new Set(["node","participant","state","entity"]);function ve(n){switch(n.kind){case"graph":return n.groups.length+n.nodes.length+n.edges.length;case"sequence":return n.participants.length+n.messages.length;case"state":return n.states.length+n.transitions.length;case"er":return n.entities.length+n.relations.length;case"tree":return n.nodes.length+n.edges.length;default:return Me(n)}}function Me(n){throw Error(`Unsupported scene: ${JSON.stringify(n)}`)}var De=0.05,$e=8,Be=7,ze=14,Ke=11,Fe=12,Ve=4,Xe=100,xe=16,se=new Set,we=0,ce=1,Q=2,Ge=3;function X(n,r){return`${n}:${r}`}function Ye(n,r,c,L,v,l){let T=v-c,I=l-L,g=T*T+I*I,y=g===0?0:Math.max(0,Math.min(1,((n-c)*T+(r-L)*I)/g));return Math.hypot(n-(c+y*T),r-(L+y*I))}function qe(n){let[r,c,L,v]=n;if(r===void 0||c===void 0||L===void 0||v===void 0)return[...n];let l=[];for(let T=0;T<xe;T++){let I=T/(xe-1),g=1-I,y=g*g*g,D=3*g*g*I,H=3*g*I*I,O=I*I*I;l.push({x:y*r.x+D*c.x+H*L.x+O*v.x,y:y*r.y+D*c.y+H*L.y+O*v.y})}return l}function Le(n,r,c){return r>=n.x&&r<=n.x+n.width&&c>=n.y&&c<=n.y+n.height}function We(n,r){if(n.length!==r.length)return!1;for(let c=0;c<n.length;c++)if(n[c]!==r[c])return!1;return!0}function Te(n,r={}){let c=r.minScale??De,L=r.maxScale??$e,v=r.padding??0,l=r.labelMinPx??Be,T=Math.max(1,n.width),I=Math.max(1,n.height),g=[],y=new Map,D=[],H=new Map,O=[];function A(t,e,o,d=0,p=!1){let w=g.length,x=X(t,e);return g.push({ref:{kind:t,id:e},key:x,depth:d,container:p,item:o}),y.set(x,w),w}function _(t,e,o,d,p,w){let x={x:Math.min(o,p),y:Math.min(d,w),width:Math.abs(p-o),height:Math.abs(w-d)};D.push({box:x,value:{entry:t,role:e,box:x,x1:o,y1:d,x2:p,y2:w}})}function P(t,e,o,d,p){_(t,we,e,o,e+d,o+p)}function h(t,e){let o=e[0];if(o===void 0)return;if(e.length===1)_(t,ce,o.x,o.y,o.x,o.y);for(let d=1;d<e.length;d++){let p=e[d-1],w=e[d];_(t,ce,p.x,p.y,w.x,w.y)}}function a(t,e){let o=H.get(t);if(o===void 0)H.set(t,o=new Set);o.add(e)}switch(n.kind){case"graph":{for(let e of n.groups){let o=A("group",e.id,e,e.depth,!0);P(o,e.x,e.y,e.width,e.height)}let t=[];for(let e of n.edges){let o=A("edge",e.id,e);if(t.push(o),h(o,e.points),e.labelBox!==void 0){let d=e.labelBox;_(o,Q,d.x,d.y,d.x+d.width,d.y+d.height)}}for(let e of n.nodes){let o=A("node",e.id,e);P(o,e.x,e.y,e.width,e.height),O.push({index:o,label:e.label.toLowerCase(),id:e.id.toLowerCase()})}n.edges.forEach((e,o)=>{let d=g[t[o]].key,p=X("node",e.from),w=X("node",e.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)});break}case"sequence":{for(let t of n.participants){let e=A("participant",t.id,t);P(e,t.x,t.y,t.width,t.height),_(e,Ge,t.lifelineX,t.y+t.height,t.lifelineX,n.lifelineBottom),O.push({index:e,label:t.label.toLowerCase(),id:t.id.toLowerCase()})}for(let t of n.messages){let e=String(t.index),o=A("message",e,t);if(t.self){let x=t.x1+ge,N=t.y+ye;h(o,[{x:t.x1,y:t.y},{x,y:t.y},{x,y:N},{x:t.x1,y:N}])}else h(o,[{x:t.x1,y:t.y},{x:t.x2,y:t.y}]);if(t.labelBox!==void 0){let x=t.labelBox;_(o,Q,x.x,x.y,x.x+x.width,x.y+x.height)}let d=g[o].key,p=X("participant",t.from),w=X("participant",t.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)}break}case"state":{let t=(o)=>{let d=A("state",o.id,o,o.depth,o.composite);P(d,o.x,o.y,o.width,o.height),O.push({index:d,label:o.label.toLowerCase(),id:o.id.toLowerCase()})};n.states.filter((o)=>o.composite).sort((o,d)=>o.depth-d.depth).forEach(t);let e=[];for(let o of n.transitions){let d=A("transition",o.id,o);if(e.push(d),h(d,o.points),o.labelBox!==void 0){let p=o.labelBox;_(d,Q,p.x,p.y,p.x+p.width,p.y+p.height)}}n.states.filter((o)=>!o.composite).forEach(t),n.transitions.forEach((o,d)=>{let p=g[e[d]].key,w=X("state",o.from),x=X("state",o.to);for(let[N,J]of[[w,x],[x,w]]){if(!y.has(N))continue;if(a(N,p),y.has(J))a(N,J)}if(y.has(w))a(p,w);if(y.has(x))a(p,x)});break}case"er":{let t=[];for(let e of n.relations){let o=A("relation",e.id,e);if(t.push(o),h(o,e.points),e.labelBox!==void 0){let d=e.labelBox;_(o,Q,d.x,d.y,d.x+d.width,d.y+d.height)}}for(let e of n.entities){let o=A("entity",e.id,e);P(o,e.x,e.y,e.width,e.height),O.push({index:o,label:[e.label,...e.attributes.map((d)=>d.name)].join(" ").toLowerCase(),id:e.id.toLowerCase()})}n.relations.forEach((e,o)=>{let d=g[t[o]].key,p=X("entity",e.from),w=X("entity",e.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)});break}case"tree":{let t=[];for(let e of n.edges){let o=A("edge",e.id,e);t.push(o),h(o,e.curve==="bezier"?qe(e.points):e.points)}for(let e of n.nodes){let o=A("node",e.id,e);P(o,e.x,e.y,e.width,e.height),O.push({index:o,label:e.label.toLowerCase(),id:e.id.toLowerCase()})}n.edges.forEach((e,o)=>{let d=g[t[o]].key,p=X("node",e.from),w=X("node",e.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)});break}default:Me(n)}let b=be(D),s=g.length,E=new Int32Array(s),k=0,m={x:0,y:0,scale:1},i={width:0,height:0},f=-1,S=-1,C="",R=se,F={focused:!1,active:se},G=z(),Z=null,j=ne(1),ee=0,V=new Set,W=!1,te=new Set;function ne(t){return{labels:ze*t>=l,captions:Ke*t>=l,edgeLabels:Fe*t>=l}}function U(){let{width:t,height:e}=i;if(t<=0||e<=0)return c;let o=Math.min(Math.max(1,t-2*v)/T,Math.max(1,e-2*v)/I);return Math.min(c,o)}function u(t){return Math.min(L,Math.max(U(),t))}function M(t){if(t.x===m.x&&t.y===m.y&&t.scale===m.scale)return;m=t,V.add("camera"),W=!0}function z(){let{width:t,height:e}=i;if(t<=0||e<=0){let w=new Int32Array(s);for(let x=0;x<s;x++)w[x]=x;return w}let o=Xe/m.scale,d=b.query({x:-m.x/m.scale-o,y:-m.y/m.scale-o,width:t/m.scale+2*o,height:e/m.scale+2*o});k+=1;let p=[];for(let w of d){if(E[w.entry]===k)continue;E[w.entry]=k,p.push(w.entry)}return Int32Array.from(p).sort()}function ie(){if(!W)return;W=!1;let t=ne(m.scale);if(t.labels!==j.labels||t.captions!==j.captions||t.edgeLabels!==j.edgeLabels)j=t,V.add("lod");let e=z();if(!We(e,G))G=e,Z=null,V.add("visible")}function Ne(){if(ie(),V.size===0)return;let t=V;V=new Set;for(let e of[...te])e(t)}function q(t){ee+=1;try{t()}finally{if(ee-=1,ee===0)Ne()}}function me(){if(f>=0){let t=g[f],e=new Set([t.key]);for(let o of H.get(t.key)??[])e.add(o);F={focused:!0,active:e}}else if(C!=="")F={focused:!0,active:R};else F={focused:!1,active:se}}function ae(t){if(t===null)return-1;return y.get(X(t.kind,t.id))??-1}return{scene:n,camera:()=>({...m}),viewport:()=>({...i}),setViewport(t,e){if(t===i.width&&e===i.height)return;q(()=>{i={width:t,height:e},V.add("viewport"),W=!0})},setCamera(t){if(![t.x,t.y,t.scale].every(Number.isFinite)||t.scale<=0)return;q(()=>M({x:t.x,y:t.y,scale:u(t.scale)}))},fit(){let{width:t,height:e}=i;if(t<=0||e<=0)return;q(()=>{let o=Math.min(Math.max(1,t-2*v)/T,Math.max(1,e-2*v)/I),d=u(Math.min(o,1));M({scale:d,x:(t-n.width*d)/2,y:(e-n.height*d)/2})})},panBy(t,e){if(t===0&&e===0)return;q(()=>M({x:m.x+t,y:m.y+e,scale:m.scale}))},zoomAt(t,e,o){if(!Number.isFinite(t)||t<=0)return;q(()=>{let d=u(m.scale*t),p=d/m.scale;M({scale:d,x:e-(e-m.x)*p,y:o-(o-m.y)*p})})},screenToWorld:(t,e)=>({x:(t-m.x)/m.scale,y:(e-m.y)/m.scale}),worldToScreen:(t,e)=>({x:t*m.scale+m.x,y:e*m.scale+m.y}),hitTest(t,e){let o=(t-m.x)/m.scale,d=(e-m.y)/m.scale,p=Ve/m.scale,w=b.query({x:o-p,y:d-p,width:2*p,height:2*p}),x=-1,N=-1,J=1/0,de=-1,le=-1;for(let K of w){let oe=g[K.entry];if(K.role===we){if(!Le(K.box,o,d))continue;if(oe.container){if(oe.depth>le||oe.depth===le&&K.entry>de)de=K.entry,le=oe.depth}else if(K.entry>x)x=K.entry}else if(K.role===ce||K.role===Q){let re=K.role===Q?Le(K.box,o,d)?0:1/0:Ye(o,d,K.x1,K.y1,K.x2,K.y2);if(re<=p&&(re<J||re===J&&K.entry>N))N=K.entry,J=re}}let he=x>=0?x:N>=0?N:de;return he>=0?g[he].ref:null},visible(){if(Z===null)Z=Array.from(G,(t)=>g[t].ref);return{items:Z,count:G.length}},lod:()=>j,hover(t){let e=ae(t);if(e===f)return;q(()=>{f=e,me(),V.add("hover")})},select(t){let e=ae(t);if(e===S)return;q(()=>{S=e,V.add("selection")})},search(t){let e=t.trim().toLowerCase();if(e===C)return;q(()=>{if(C=e,e==="")R=se;else{let o=new Set;for(let d of O)if(d.label.includes(e)||d.id.includes(e))o.add(g[d.index].key);R=o}me(),V.add("search")})},hovered:()=>f>=0?g[f].ref:null,selected:()=>S>=0?g[S].ref:null,highlight:()=>F,item(t){let e=ae(t);return e>=0?g[e].item:void 0},subscribe(t){return te.add(t),()=>{te.delete(t)}},batch:q}}function Se(n){let{event:r,guard:c,action:L}=n;return[r,c===void 0?void 0:`[${c}]`,L===void 0?void 0:`/ ${L}`].filter((v)=>v!==void 0).join(" ")}var Ue=4,je=/^[\\s\\u0000-\\u001f]*(javascript|data|vbscript):/i,Ze;function Y(n){let r=(Ze??document).querySelector(`.${n}`);if(r===null)throw Error(`Missing element .${n}`);return r}function B(n,r,c){let L=document.createElement(n);if(r!==void 0)L.textContent=r;if(c!==void 0)L.className=c;return L}var Je={initial:"Initial",final:"Final",choice:"Choice",fork:"Fork",join:"Join",history:"History"},Qe={one:"1","zero-or-one":"0..1","one-or-more":"1..*","zero-or-more":"0..*"},ke="standargraph-scheme",ue=["auto","light","dark"];function et(){try{let n=localStorage.getItem(ke);return n==="light"||n==="dark"?n:"auto"}catch{return"auto"}}function tt(n){try{localStorage.setItem(ke,n)}catch{return}}function nt(n){let r=n.getAttribute("data-sg-scheme");return r==="light"||r==="dark"?r:"auto"}function Ie(n,r,c=!0){if(r==="auto")n.removeAttribute("data-sg-scheme");else n.setAttribute("data-sg-scheme",r);let L=n.querySelector(".sg-scheme");if(L!==null){let v=`Color scheme: ${r}`;L.textContent=r[0].toUpperCase()+r.slice(1),L.setAttribute("aria-label",v),L.title=v}if(c)tt(r);n.dispatchEvent(new CustomEvent("sg-scheme",{bubbles:!0,detail:r}))}function Ce(n){let r=n.querySelector(".sg-scheme");if(r===null)return;Ie(n,et(),!1),r.addEventListener("click",()=>{let c=ue[(ue.indexOf(nt(n))+1)%ue.length];Ie(n,c)})}function Oe(n,r,c){let L=r.kind==="graph"?r.edges??[]:[];function v(a){return L[a]?.id??`e${a}`}function l(a,b,s){let E=B("dt",b),k=B("dd");if(typeof s==="string")k.textContent=s;else k.appendChild(s);a.append(E,k)}function T(a){if(je.test(a))return document.createTextNode(a);let b=B("a",a);return b.href=a,b.target="_blank",b.rel="noopener noreferrer",b}function I(a,b){if(b===void 0)return;let s=b.provenance;if(s!==void 0){if(l(a,"Source",s.source),s.confidence!==void 0)l(a,"Confidence",s.confidence);if(s.tool!==void 0)l(a,"Tool",s.tool)}if(b.coverage!==void 0)l(a,"Coverage",`${Math.round(b.coverage*1000)/10}%`);if(b.freshness!==void 0){let E=new Date(b.freshness);l(a,"Freshness",Number.isNaN(E.getTime())?b.freshness:E.toLocaleString())}if(b.data!==void 0){let E=B("table",void 0,"sg-data");for(let[k,m]of Object.entries(b.data)){let i=B("tr");i.append(B("th",k),B("td",String(m))),E.appendChild(i)}l(a,"Data",E)}}let g=new Map;if(r.kind==="graph")r.nodes.forEach((a,b)=>g.set(a.id,b));let y=new Map;if(r.kind==="state")r.states.forEach((a,b)=>y.set(a.id,b));let D=new Map;if(r.kind==="er")r.entities.forEach((a,b)=>D.set(a.id,b));let H=new Map;if(r.kind==="tree")r.nodes.forEach((a,b)=>H.set(a.id,b));let O,A,_;function P(a,b){let s=B("dl"),E=b,k;if(a==="node"&&r.kind==="graph"){let i=r.nodes[g.get(b)??-1];if(i===void 0)return;if(E=i.label??i.id,k=i.meta,l(s,"Kind","Node"),i.type!==void 0)l(s,"Type",i.type);if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link))}else if(a==="node"&&r.kind==="tree"){let i=r.nodes[H.get(b)??-1];if(i===void 0)return;if(E=i.label,k=i.meta,l(s,"Kind","Node"),i.parent!==void 0){let S=r.nodes[H.get(i.parent)??-1];l(s,"Parent",S?.label??i.parent)}let f=n.item({kind:"node",id:b});if(f!==void 0&&"depth"in f)l(s,"Depth",String(f.depth));if(i.type!==void 0)l(s,"Type",i.type);if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link))}else if(a==="edge"&&r.kind==="graph"){if(O===void 0)O=new Map,L.forEach((f,S)=>{let C=v(S);if(!O.has(C))O.set(C,S)});let i=L[O.get(b)??-1];if(i===void 0)return;if(E=i.label??`${i.from} → ${i.to}`,k=i.meta,l(s,"Kind","Edge"),l(s,"Connection",`${i.from} → ${i.to}`),i.type!==void 0)l(s,"Type",i.type)}else if(a==="participant"&&r.kind==="sequence"){let i=r.participants.find((f)=>f.id===b);if(i===void 0)return;if(E=i.label??i.id,k=i.meta,l(s,"Kind","Participant"),i.type!==void 0)l(s,"Type",i.type)}else if(a==="message"&&r.kind==="sequence"){let i=r.messages[Number(b)];if(i===void 0)return;E=i.label??`${i.from} → ${i.to}`,k=i.meta,l(s,"Kind","Message"),l(s,"Connection",`${i.from} → ${i.to}`),l(s,"Style",i.style??"sync")}else if(a==="state"&&r.kind==="state"){let i=r.states[y.get(b)??-1];if(i===void 0)return;if(E=i.label??i.id,k=i.meta,l(s,"Kind",i.pseudo===void 0?"State":Je[i.pseudo]),i.type!==void 0)l(s,"Type",i.type);if(i.actions!==void 0&&i.actions.length>0){let f=B("div");for(let S of i.actions)f.appendChild(B("div",S));l(s,"Actions",f)}if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link))}else if(a==="transition"&&r.kind==="state"){let i=r.transitions??[];if(A===void 0)A=new Map,i.forEach((S,C)=>{let R=S.id??`t${C}`;if(!A.has(R))A.set(R,C)});let f=i[A.get(b)??-1];if(f===void 0)return;if(E=Se(f)||`${f.from} → ${f.to}`,k=f.meta,l(s,"Connection",`${f.from} → ${f.to}`),f.event!==void 0)l(s,"Event",f.event);if(f.guard!==void 0)l(s,"Guard",f.guard);if(f.action!==void 0)l(s,"Action",f.action);if(f.type!==void 0)l(s,"Type",f.type)}else if(a==="entity"&&r.kind==="er"){let i=r.entities[D.get(b)??-1];if(i===void 0)return;if(E=i.label??i.id,k=i.meta,i.type!==void 0)l(s,"Type",i.type);if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link));let f=i.attributes??[];if(f.length>0){let S=B("table",void 0,"sg-data"),C=B("tr");for(let R of["Name","Type","Keys","Null","Note"])C.appendChild(B("th",R));S.appendChild(C);for(let R of f){let F=B("tr");F.append(B("td",R.name),B("td",R.type??""),B("td",(R.keys??[]).join(", ")),B("td",R.nullable===!0?"yes":""),B("td",R.note??"")),S.appendChild(F)}l(s,"Attributes",S)}}else if(a==="relation"&&r.kind==="er"){let i=r.relations??[];if(_===void 0)_=new Map,i.forEach((S,C)=>{let R=S.id??`r${C}`;if(!_.has(R))_.set(R,C)});let f=i[_.get(b)??-1];if(f===void 0)return;if(E=f.label??`${f.from} → ${f.to}`,k=f.meta,l(s,"Connection",`${f.from} → ${f.to}`),f.fromCardinality!==void 0||f.toCardinality!==void 0){let S=(C)=>C===void 0?"-":Qe[C];l(s,"Cardinality",`${S(f.fromCardinality)} → ${S(f.toCardinality)}`)}if(l(s,"Identifying",f.identifying===!1?"no":"yes"),f.type!==void 0)l(s,"Type",f.type)}else return;I(s,k);let m=B("button","×","sg-close");m.type="button",m.setAttribute("aria-label","Close"),m.addEventListener("click",()=>n.select(null)),c.replaceChildren(m,B("h2",E),s),c.hidden=!1}let h=(a)=>{if(a.key==="Escape"&&!c.hidden)n.select(null)};return document.addEventListener("keydown",h),{update(){let a=n.selected();if(a===null){c.hidden=!0,c.replaceChildren();return}P(a.kind,a.id)},destroy(){document.removeEventListener("keydown",h)}}}function Re(n){let{view:r,viewport:c,search:L}=n,v=c.getBoundingClientRect(),l={pointer:null,dragging:!1,lastWheel:-1/0,rect:()=>v,resize:_,destroy(){P.disconnect()}},T=null,I=0,g=0,y=0,D=0,H=!1;c.addEventListener("pointerdown",(h)=>{if(h.button!==0)return;T=h.pointerId,I=h.clientX,g=h.clientY,y=h.clientX,D=h.clientY,H=!1}),c.addEventListener("pointermove",(h)=>{if(T===h.pointerId){let a=Math.hypot(h.clientX-I,h.clientY-g);if(!H&&a<Ue)return;if(!H)H=!0,l.dragging=!0,c.setPointerCapture(h.pointerId),c.classList.add("sg-dragging");r.panBy(h.clientX-y,h.clientY-D),y=h.clientX,D=h.clientY;return}if(T!==null)return;l.pointer={x:h.clientX-v.left,y:h.clientY-v.top},n.onPointer()});function O(h){if(T!==h.pointerId)return;T=null,l.dragging=!1,c.classList.remove("sg-dragging")}c.addEventListener("pointerup",O),c.addEventListener("pointercancel",O),c.addEventListener("click",(h)=>{if(H){H=!1,h.preventDefault();return}let a=n.pick(h,h.clientX-v.left,h.clientY-v.top);if(a!==null)h.preventDefault(),r.select(a);else if(h.target instanceof Element&&h.target.closest("a")!==null)h.preventDefault()}),c.addEventListener("wheel",(h)=>{h.preventDefault(),l.lastWheel=performance.now(),r.zoomAt(Math.exp(-h.deltaY*0.0015),h.clientX-v.left,h.clientY-v.top)},{passive:!1}),c.addEventListener("mouseleave",()=>{l.pointer=null,r.hover(null)});function A(h){let a=r.viewport();r.zoomAt(h,a.width/2,a.height/2)}Y("sg-zoom-in").addEventListener("click",()=>A(1.25)),Y("sg-zoom-out").addEventListener("click",()=>A(0.8)),Y("sg-fit").addEventListener("click",()=>r.fit()),L.addEventListener("input",()=>r.search(L.value));function _(){v=c.getBoundingClientRect(),r.batch(()=>{r.setViewport(c.clientWidth,c.clientHeight),r.fit()}),n.onResize?.()}let P=new ResizeObserver(_);return P.observe(c),r.batch(()=>{r.setViewport(c.clientWidth,c.clientHeight),r.fit()}),l}var fe=150,it=400;function Ae(n,r){let c=Y("sg-viewport"),L=Y("sg-stage"),v=Y("sg-panel"),l=Y("sg-search"),T=L.querySelector("svg");if(T===null)return;let I=T;Ce(Y("sg-app"));let g=Te(r),y=Oe(g,n,v),D=new Map;for(let u of I.querySelectorAll("[data-kind]"))D.set(`${u.getAttribute("data-kind")}:${u.getAttribute("data-id")}`,u);let H=new Map;function O(u){let M=H.get(u);if(M===void 0){if(M=D.get(`${u.kind}:${u.id}`),M!==void 0)H.set(u,M)}return M}let A=ve(r)>it,_=0,P=0,h=!1,a=!1,b=!1,s=new Set,E=new Set(g.visible().items),k=new Set,m=!1,i=null;function f(){if(_=performance.now(),!h)h=!0,L.style.willChange="transform";if(P===0)P=window.setTimeout(S,fe)}function S(){let u=fe-(performance.now()-_);if(u>1){P=window.setTimeout(S,u);return}if(P=0,h=!1,L.style.willChange="",b)G();if(U.pointer!==null)W()}function C(){let u=g.camera();L.style.transform=`translate(${u.x}px, ${u.y}px) scale(${u.scale})`}function R(){let u=g.lod();I.classList.toggle("sg-lod-nolabels",!u.labels),I.classList.toggle("sg-lod-nocaptions",!u.captions),I.classList.toggle("sg-lod-noedgelabels",!u.edgeLabels)}function F(){let{focused:u,active:M}=g.highlight();if(u!==m)I.classList.toggle("sg-focus",u),m=u;for(let z of k)if(!M.has(z))D.get(z)?.classList.remove("sg-hl");for(let z of M)if(!k.has(z))D.get(z)?.classList.add("sg-hl");k=M}function G(){b=!1;let u=new Set(g.visible().items);for(let M of E){if(u.has(M))continue;let z=O(M);if(z instanceof SVGElement)z.style.display="none"}for(let M of u){if(E.has(M))continue;let z=O(M);if(z instanceof SVGElement)z.style.display=""}E=u}function Z(){b=!0;let u=g.visible().items,M=new Set(E);for(let z of u){if(M.has(z))continue;let ie=O(z);if(ie instanceof SVGElement)ie.style.display="";M.add(z)}E=M}function j(){let u=U.pointer;if(u===null||U.dragging)return;if(performance.now()-U.lastWheel<fe)return;let M=g.hitTest(u.x,u.y);U.pointer=null,g.hover(M!==null&&ee(M)?M:null)}function ee(u){if(!Ee.has(u.kind))return!1;return u.kind!=="state"||g.item({kind:"state",id:u.id})?.composite!==!0}function V(){j(),a=!1;let u=s;if(s=new Set,u.has("camera"))C();if(u.has("lod"))R();if(u.has("hover")||u.has("search"))F();if(A&&u.has("visible"))if(h)Z();else G()}function W(){if(a)return;a=!0,requestAnimationFrame(V)}g.subscribe((u)=>{if(u.has("selection"))te();if(u.has("camera"))f();for(let M of u)s.add(M);W()});function te(){i?.classList.remove("sg-selected"),i=null;let u=g.selected();if(u!==null)i=O(u)??null,i?.classList.add("sg-selected");y.update()}function ne(u){if(!(u instanceof Element))return null;let M=u.closest("[data-kind]");if(M===null||M.getAttribute("data-kind")==="group")return null;return{kind:M.getAttribute("data-kind")??"",id:M.getAttribute("data-id")??""}}let U=Re({view:g,viewport:c,search:l,pick:(u)=>ne(u.target),onPointer:W});if(C(),R(),A)G();return Y("sg-app").dataset.sgReady="1",{view:g,destroy(){U.destroy(),y.destroy(),clearTimeout(P)}}}function _e(n){return JSON.parse(document.getElementById(n).textContent??"{}")}Ae(_e("standargraph-document"),_e("standargraph-scene"));})();';
|
|
18
|
+
|
|
19
|
+
// src/html/render.ts
|
|
20
|
+
function renderHtml2(document, laidOut, options = {}) {
|
|
21
|
+
const renderer = options.renderer ?? "auto";
|
|
22
|
+
const useWebgl = laidOut.kind === "graph" && (renderer === "webgl" || renderer === "auto" && laidOut.nodes.length > WEBGL_THRESHOLD2);
|
|
23
|
+
if (useWebgl)
|
|
24
|
+
return renderWebglHtml2(document, laidOut, options);
|
|
25
|
+
const theme = options.theme ?? "auto";
|
|
26
|
+
const svg = renderSvg2(laidOut, {
|
|
27
|
+
theme: lightTheme(theme),
|
|
28
|
+
standalone: false
|
|
29
|
+
}).trim();
|
|
30
|
+
return renderPage({
|
|
31
|
+
document,
|
|
32
|
+
laidOut,
|
|
33
|
+
options,
|
|
34
|
+
viewport: svgViewport(svg),
|
|
35
|
+
runtime: RUNTIME_JS
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { renderHtml2 };
|