@tdacorp/hyle-sdk 0.17.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -42
- package/dist/check-routes-bin.js +190 -53
- package/dist/{chunk-6VOHFFA5.js → chunk-7T5EEJHK.js} +2 -2
- package/dist/chunk-DUPT6XLB.js +57 -0
- package/dist/chunk-IW3TUD4G.js +841 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-KU7LWK4E.js} +249 -24
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-SFFBZFEN.js +178 -0
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/chunk-ZIW6FDU2.js +1126 -0
- package/dist/client-BGjmEWhN.d.cts +207 -0
- package/dist/client-D0LTpr3Y.d.ts +207 -0
- package/dist/code-copy.cjs +74 -0
- package/dist/code-copy.d.cts +18 -0
- package/dist/code-copy.d.ts +18 -0
- package/dist/code-copy.js +50 -0
- package/dist/comments.cjs +738 -280
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +419 -331
- package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
- package/dist/docs-enhance.cjs +7 -4
- package/dist/docs-enhance.d.cts +5 -3
- package/dist/docs-enhance.d.ts +5 -3
- package/dist/docs-enhance.js +8 -5
- package/dist/{embed-DNTZ2UXv.d.ts → embed-CbtsbZs3.d.cts} +5 -3
- package/dist/{embed-BmdwA2G9.d.cts → embed-Cf_2ZR5x.d.ts} +5 -3
- package/dist/fragment-alias.cjs +51 -0
- package/dist/fragment-alias.d.cts +7 -0
- package/dist/fragment-alias.d.ts +7 -0
- package/dist/fragment-alias.js +27 -0
- package/dist/html.cjs +886 -0
- package/dist/html.d.cts +20 -0
- package/dist/html.d.ts +20 -0
- package/dist/html.js +45 -0
- package/dist/index.cjs +244 -24
- package/dist/index.d.cts +22 -68
- package/dist/index.d.ts +22 -68
- package/dist/index.js +12 -2
- package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.cts} +9 -0
- package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.ts} +9 -0
- package/dist/mermaid-diagram.cjs +441 -125
- package/dist/mermaid-diagram.d.cts +23 -7
- package/dist/mermaid-diagram.d.ts +23 -7
- package/dist/mermaid-diagram.js +213 -51
- package/dist/mermaid-image.cjs +137 -60
- package/dist/mermaid-image.d.cts +4 -3
- package/dist/mermaid-image.d.ts +4 -3
- package/dist/mermaid-image.js +27 -28
- package/dist/next.cjs +836 -304
- package/dist/next.d.cts +45 -20
- package/dist/next.d.ts +45 -20
- package/dist/next.js +151 -40
- package/dist/print-coordinator.cjs +157 -0
- package/dist/print-coordinator.d.cts +27 -0
- package/dist/print-coordinator.d.ts +27 -0
- package/dist/print-coordinator.js +83 -0
- package/dist/react.cjs +603 -240
- package/dist/react.d.cts +148 -30
- package/dist/react.d.ts +148 -30
- package/dist/react.js +26 -4
- package/dist/reactions.cjs +653 -0
- package/dist/reactions.d.cts +27 -0
- package/dist/reactions.d.ts +27 -0
- package/dist/reactions.js +364 -0
- package/dist/{resolve-euZ4-aC9.d.cts → resolve-BnIv7aB7.d.cts} +2 -2
- package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BysHtZ_i.d.ts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-BpY_AdZh.d.cts +23 -0
- package/dist/sanitize-BpY_AdZh.d.ts +23 -0
- package/dist/styles.css +100 -29
- package/dist/toc-spy.cjs +60 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +36 -0
- package/dist/{types-Czt887Iv.d.cts → types-D09Z072G.d.cts} +57 -2
- package/dist/{types-Czt887Iv.d.ts → types-D09Z072G.d.ts} +57 -2
- package/dist/use-cache.cjs +89 -13
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +8 -8
- package/dist/youtube-facade.cjs +50 -0
- package/dist/youtube-facade.d.cts +17 -0
- package/dist/youtube-facade.d.ts +17 -0
- package/dist/youtube-facade.js +26 -0
- package/package.json +16 -3
- package/dist/chunk-67IOIAVW.js +0 -35
- package/dist/chunk-DMK4XQLU.js +0 -1556
- package/dist/chunk-PJMJMP66.js +0 -63
- package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
- package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
package/dist/mermaid-diagram.cjs
CHANGED
|
@@ -44,15 +44,15 @@ var init_labels = __esm({
|
|
|
44
44
|
zoomIn: "Zoom in",
|
|
45
45
|
zoomOut: "Zoom out",
|
|
46
46
|
fit: "Fit to window",
|
|
47
|
-
actual: "
|
|
47
|
+
actual: "100%: actual size",
|
|
48
48
|
search: "Find in diagram",
|
|
49
49
|
searchPlaceholder: "Find",
|
|
50
50
|
noMatch: "No match",
|
|
51
51
|
matchOf: "{n} of {total}",
|
|
52
|
-
copySource: "
|
|
53
|
-
downloadSvg: "
|
|
54
|
-
downloadPng: "
|
|
55
|
-
copyImage: "
|
|
52
|
+
copySource: "MMD: copy diagram source",
|
|
53
|
+
downloadSvg: "SVG: download",
|
|
54
|
+
downloadPng: "PNG: download",
|
|
55
|
+
copyImage: "IMG: copy as image",
|
|
56
56
|
pngScale: "PNG scale",
|
|
57
57
|
fullscreen: "Fullscreen",
|
|
58
58
|
exitFullscreen: "Exit fullscreen",
|
|
@@ -65,7 +65,16 @@ var init_labels = __esm({
|
|
|
65
65
|
legendDownstream: "Downstream",
|
|
66
66
|
outgoing: "outgoing",
|
|
67
67
|
tracing: "{label}: {up} upstream, {down} downstream",
|
|
68
|
-
map: "Overview map"
|
|
68
|
+
map: "Overview map",
|
|
69
|
+
largeTitle: "Large diagram, not drawn automatically",
|
|
70
|
+
largeBody: "Drawing a diagram this size can freeze this page for a few seconds, so it waits until you ask. Press Draw diagram: it takes a couple of seconds (a few more on a phone) and the page may pause while it works.",
|
|
71
|
+
drawLarge: "Draw diagram",
|
|
72
|
+
drawing: "Drawing\u2026",
|
|
73
|
+
drawingBody: "Drawing the diagram\u2026 this takes a couple of seconds.",
|
|
74
|
+
drawAgain: "Draw again",
|
|
75
|
+
showSource: "Show full source",
|
|
76
|
+
hideSource: "Show less",
|
|
77
|
+
printPreparing: "Preparing diagrams for print\u2026 Esc cancels between steps."
|
|
69
78
|
};
|
|
70
79
|
fill = (template, values) => template.replace(/\{(\w+)\}/g, (m, k) => k in values ? String(values[k]) : m);
|
|
71
80
|
}
|
|
@@ -126,7 +135,10 @@ function nearest(nodes, x, y) {
|
|
|
126
135
|
let d = GEOMETRY_SLACK;
|
|
127
136
|
for (const n of nodes) {
|
|
128
137
|
const nd = dist(n.box, x, y);
|
|
129
|
-
if (nd < d)
|
|
138
|
+
if (nd < d) {
|
|
139
|
+
d = nd;
|
|
140
|
+
best = n.key;
|
|
141
|
+
}
|
|
130
142
|
}
|
|
131
143
|
return best;
|
|
132
144
|
}
|
|
@@ -229,7 +241,10 @@ function walk(g, start, next, far) {
|
|
|
229
241
|
edges.add(i);
|
|
230
242
|
const other = far(g.edges[i]);
|
|
231
243
|
nodes.add(other);
|
|
232
|
-
if (!seen.has(other))
|
|
244
|
+
if (!seen.has(other)) {
|
|
245
|
+
seen.add(other);
|
|
246
|
+
queue2.push(other);
|
|
247
|
+
}
|
|
233
248
|
}
|
|
234
249
|
}
|
|
235
250
|
return { nodes, edges };
|
|
@@ -242,7 +257,10 @@ function trace(g, key) {
|
|
|
242
257
|
function neighbourhood(g, key) {
|
|
243
258
|
const edges = /* @__PURE__ */ new Set([...g.out.get(key) ?? [], ...g.inn.get(key) ?? []]);
|
|
244
259
|
const nodes = /* @__PURE__ */ new Set([key]);
|
|
245
|
-
for (const i of edges)
|
|
260
|
+
for (const i of edges) {
|
|
261
|
+
nodes.add(g.edges[i].from);
|
|
262
|
+
nodes.add(g.edges[i].to);
|
|
263
|
+
}
|
|
246
264
|
return { nodes, edges };
|
|
247
265
|
}
|
|
248
266
|
function pickNeighbour(g, key, dir) {
|
|
@@ -261,12 +279,18 @@ function pickNeighbour(g, key, dir) {
|
|
|
261
279
|
const across = Math.abs((x - cx) * vy - (y - cy) * vx);
|
|
262
280
|
if (along <= 0 || across > along * cone) continue;
|
|
263
281
|
const c = along + across * 2;
|
|
264
|
-
if (c < cost)
|
|
282
|
+
if (c < cost) {
|
|
283
|
+
cost = c;
|
|
284
|
+
pick = k;
|
|
285
|
+
}
|
|
265
286
|
}
|
|
266
287
|
return pick;
|
|
267
288
|
};
|
|
268
289
|
const adjacent = /* @__PURE__ */ new Set();
|
|
269
|
-
for (const i of [...g.out.get(key) ?? [], ...g.inn.get(key) ?? []])
|
|
290
|
+
for (const i of [...g.out.get(key) ?? [], ...g.inn.get(key) ?? []]) {
|
|
291
|
+
adjacent.add(g.edges[i].from);
|
|
292
|
+
adjacent.add(g.edges[i].to);
|
|
293
|
+
}
|
|
270
294
|
return best(adjacent, CONE) ?? best(adjacent, Infinity) ?? best(g.byKey.keys(), CONE);
|
|
271
295
|
}
|
|
272
296
|
function searchNodes(nodes, query) {
|
|
@@ -302,18 +326,25 @@ var init_graph = __esm({
|
|
|
302
326
|
// src/react/viewer/scope-svg.ts
|
|
303
327
|
function scopeSvg(svg, oldId, newId) {
|
|
304
328
|
if (!/^[\w-]+$/.test(oldId) || !/^[\w-]+$/.test(newId)) throw new Error("unsafe svg id");
|
|
329
|
+
const own = `${oldId}-`;
|
|
305
330
|
const token = new RegExp(`(?<![\\w-])${escapeRe(oldId)}(?![A-Za-z0-9-])`, "g");
|
|
306
331
|
const rooted = svg.replace(SEGMENT, (segment) => segment.replace(token, newId));
|
|
307
|
-
const
|
|
332
|
+
const ids = /* @__PURE__ */ new Set();
|
|
308
333
|
for (const segment of rooted.match(SEGMENT) ?? []) {
|
|
309
334
|
if (!isTag(segment)) continue;
|
|
310
|
-
for (const m of segment.matchAll(/\sid="([^"]*)"/g))
|
|
335
|
+
for (const m of segment.matchAll(/\sid="([^"]*)"/g)) ids.add(m[1]);
|
|
311
336
|
}
|
|
337
|
+
const stripped = (id) => id.startsWith(own) ? id.slice(own.length) : id;
|
|
338
|
+
const target = (id) => `${newId}_${stripped(id)}`;
|
|
339
|
+
const plain = [...ids].filter((id) => !id.startsWith(`${newId}_`) && id !== newId);
|
|
340
|
+
const claims = /* @__PURE__ */ new Map();
|
|
341
|
+
for (const id of plain) claims.set(target(id), (claims.get(target(id)) ?? 0) + 1);
|
|
342
|
+
const fresh = new Map(plain.map((id) => [id, ids.has(target(id)) || claims.get(target(id)) > 1 ? `${newId}_${id}` : target(id)]));
|
|
312
343
|
if (!fresh.size) return rooted;
|
|
313
344
|
const to = (id) => fresh.get(id) ?? id;
|
|
314
345
|
return rooted.replace(
|
|
315
346
|
SEGMENT,
|
|
316
|
-
(segment) => !isTag(segment) ? segment : segment.replace(/(\sid=")([^"]*)"/g, (_, a, id) => `${a}${to(id)}"`).replace(/url\(#([^)"'\s]+)\)/g, (_, id) => `url(#${to(id)})`).replace(/(\s(?:xlink:)?href=")#([^"]*)"/g, (_, a, id) => `${a}#${to(id)}"`).replace(/(\saria-(?:labelledby|describedby)=")([^"]*)"/g, (_, a,
|
|
347
|
+
(segment) => !isTag(segment) ? segment : segment.replace(/(\sid=")([^"]*)"/g, (_, a, id) => `${a}${to(id)}"`).replace(/url\(#([^)"'\s]+)\)/g, (_, id) => `url(#${to(id)})`).replace(/(\s(?:xlink:)?href=")#([^"]*)"/g, (_, a, id) => `${a}#${to(id)}"`).replace(/(\saria-(?:labelledby|describedby)=")([^"]*)"/g, (_, a, ids2) => `${a}${ids2.split(/\s+/).map(to).join(" ")}"`)
|
|
317
348
|
);
|
|
318
349
|
}
|
|
319
350
|
function svgSize(svg) {
|
|
@@ -603,7 +634,10 @@ var init_controller = __esm({
|
|
|
603
634
|
n.el.setAttribute("aria-pressed", "false");
|
|
604
635
|
});
|
|
605
636
|
if (this.nodes[0]) this.roving = this.nodes[0].el;
|
|
606
|
-
for (const e of this.edges)
|
|
637
|
+
for (const e of this.edges) {
|
|
638
|
+
e.el.classList.add("hv-e");
|
|
639
|
+
e.labelEl?.classList.add("hv-e");
|
|
640
|
+
}
|
|
607
641
|
this.o.stage.classList.toggle("hv-plain", this.nodes.length > FADE_MAX_NODES);
|
|
608
642
|
}
|
|
609
643
|
// ---- view ---------------------------------------------------------------------------------------------------------------------------
|
|
@@ -862,13 +896,22 @@ var init_controller = __esm({
|
|
|
862
896
|
for (const k of t.down) mark(at(k)?.el, "hv-down");
|
|
863
897
|
mark(at(this.pinned)?.el, "hv-sel");
|
|
864
898
|
const flow = t.upEdges.size + t.downEdges.size <= FLOW_MAX_EDGES ? ["hv-flow"] : [];
|
|
865
|
-
for (const i of t.upEdges)
|
|
866
|
-
|
|
899
|
+
for (const i of t.upEdges) {
|
|
900
|
+
mark(this.edges[i]?.el, "hv-up", ...flow);
|
|
901
|
+
mark(this.edges[i]?.labelEl, "hv-up");
|
|
902
|
+
}
|
|
903
|
+
for (const i of t.downEdges) {
|
|
904
|
+
mark(this.edges[i]?.el, "hv-down", ...flow);
|
|
905
|
+
mark(this.edges[i]?.labelEl, "hv-down");
|
|
906
|
+
}
|
|
867
907
|
} else if (g && this.hot) {
|
|
868
908
|
active = true;
|
|
869
909
|
const n = neighbourhood(g, this.hot);
|
|
870
910
|
for (const k of n.nodes) mark(at(k)?.el, k === this.hot ? "hv-sel" : "hv-nb");
|
|
871
|
-
for (const i of n.edges)
|
|
911
|
+
for (const i of n.edges) {
|
|
912
|
+
mark(this.edges[i]?.el, "hv-nb");
|
|
913
|
+
mark(this.edges[i]?.labelEl, "hv-nb");
|
|
914
|
+
}
|
|
872
915
|
} else if (this.query && this.hitEls.length) {
|
|
873
916
|
active = true;
|
|
874
917
|
for (const el of this.hitEls) mark(el);
|
|
@@ -1095,8 +1138,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1095
1138
|
const finder = (0, import_react.useRef)(null);
|
|
1096
1139
|
const ctl = (0, import_react.useRef)(null);
|
|
1097
1140
|
const labelsRef = (0, import_react.useRef)(labels);
|
|
1098
|
-
|
|
1099
|
-
const ownId = (0, import_react.useRef)(`hyle-viewer-${++sequence}`);
|
|
1141
|
+
const [ownId] = (0, import_react.useState)(() => `hyleViewer-${++sequence}`);
|
|
1100
1142
|
const helpId = (0, import_react.useId)();
|
|
1101
1143
|
const toastTimer = (0, import_react.useRef)(void 0);
|
|
1102
1144
|
const downOnBackdrop = (0, import_react.useRef)(false);
|
|
@@ -1106,12 +1148,15 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1106
1148
|
const [query, setQuery] = (0, import_react.useState)("");
|
|
1107
1149
|
const [scale, setScale] = (0, import_react.useState)("2");
|
|
1108
1150
|
const [fullscreen, setFullscreen] = (0, import_react.useState)(false);
|
|
1109
|
-
const scoped = (0, import_react.useMemo)(() => scopeSvg(svg, svgId, ownId
|
|
1151
|
+
const scoped = (0, import_react.useMemo)(() => scopeSvg(svg, svgId, ownId), [svg, svgId, ownId]);
|
|
1110
1152
|
const say = (message) => {
|
|
1111
1153
|
clearTimeout(toastTimer.current);
|
|
1112
1154
|
setToast(message);
|
|
1113
1155
|
toastTimer.current = setTimeout(() => setToast(""), TOAST_MS);
|
|
1114
1156
|
};
|
|
1157
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
1158
|
+
labelsRef.current = labels;
|
|
1159
|
+
}, [labels]);
|
|
1115
1160
|
(0, import_react.useLayoutEffect)(() => {
|
|
1116
1161
|
const c = new DiagramController({
|
|
1117
1162
|
viewport: viewport.current,
|
|
@@ -1128,18 +1173,22 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1128
1173
|
ctl.current = null;
|
|
1129
1174
|
};
|
|
1130
1175
|
}, []);
|
|
1131
|
-
(0, import_react.useLayoutEffect)(() => ctl.current?.show(scoped, `${ownId
|
|
1176
|
+
(0, import_react.useLayoutEffect)(() => ctl.current?.show(scoped, `${ownId}_`), [scoped, ownId]);
|
|
1132
1177
|
(0, import_react.useEffect)(() => {
|
|
1133
1178
|
const d = dialog.current;
|
|
1134
1179
|
if (!d.open) d.showModal();
|
|
1135
1180
|
if (locks++ === 0) document.documentElement.classList.add(LOCK_CLASS);
|
|
1136
1181
|
viewport.current?.focus({ preventScroll: true });
|
|
1137
|
-
const sync = () =>
|
|
1182
|
+
const sync = () => {
|
|
1183
|
+
const full = document.fullscreenElement === shell.current;
|
|
1184
|
+
setFullscreen(full);
|
|
1185
|
+
document.documentElement.classList.toggle(FULLSCREEN_CLASS, full);
|
|
1186
|
+
};
|
|
1138
1187
|
document.addEventListener("fullscreenchange", sync);
|
|
1139
1188
|
return () => {
|
|
1140
1189
|
document.removeEventListener("fullscreenchange", sync);
|
|
1141
1190
|
clearTimeout(toastTimer.current);
|
|
1142
|
-
if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS);
|
|
1191
|
+
if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS, FULLSCREEN_CLASS);
|
|
1143
1192
|
if (document.fullscreenElement && d.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
|
|
1144
1193
|
});
|
|
1145
1194
|
};
|
|
@@ -1183,7 +1232,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1183
1232
|
const canCopyImage = typeof ClipboardItem !== "undefined" && Boolean(navigator.clipboard?.write);
|
|
1184
1233
|
const canFullscreen = typeof document !== "undefined" && document.fullscreenEnabled;
|
|
1185
1234
|
const status = !query.trim() ? "" : ui.matches === 0 ? labels.noMatch : fill(labels.matchOf, { n: Math.max(ui.current, 0) + 1, total: ui.matches });
|
|
1186
|
-
return /* @__PURE__ */ (0,
|
|
1235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1187
1236
|
"dialog",
|
|
1188
1237
|
{
|
|
1189
1238
|
ref: dialog,
|
|
@@ -1193,20 +1242,20 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1193
1242
|
onPointerDown: (e) => downOnBackdrop.current = e.target === dialog.current,
|
|
1194
1243
|
onClick: (e) => e.target === dialog.current && downOnBackdrop.current && dialog.current?.close(),
|
|
1195
1244
|
onKeyDown,
|
|
1196
|
-
children: /* @__PURE__ */ (0,
|
|
1197
|
-
/* @__PURE__ */ (0,
|
|
1198
|
-
/* @__PURE__ */ (0,
|
|
1199
|
-
/* @__PURE__ */ (0,
|
|
1200
|
-
/* @__PURE__ */ (0,
|
|
1201
|
-
/* @__PURE__ */ (0,
|
|
1202
|
-
/* @__PURE__ */ (0,
|
|
1203
|
-
/* @__PURE__ */ (0,
|
|
1204
|
-
/* @__PURE__ */ (0,
|
|
1245
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "hv-shell", ref: shell, children: [
|
|
1246
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "hv-bar", role: "toolbar", "aria-label": labels.viewer, children: [
|
|
1247
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hv-title", children: title }),
|
|
1248
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("output", { className: "hv-zoom", ref: zoom, "aria-label": "zoom", children: "100%" }),
|
|
1249
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hv-group", children: [
|
|
1250
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.zoomOut, title: labels.zoomOut, onClick: () => ctl.current?.zoomBy(0.8), children: "\u2212" }),
|
|
1251
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.zoomIn, title: labels.zoomIn, onClick: () => ctl.current?.zoomBy(1.25), children: "+" }),
|
|
1252
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.fit, title: labels.fit, onClick: () => ctl.current?.fit(), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Glyph, { d: ICONS.fit }) }),
|
|
1253
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn hv-txt", "aria-label": labels.actual, title: labels.actual, onClick: () => ctl.current?.actual(), children: "100%" })
|
|
1205
1254
|
] }),
|
|
1206
|
-
/* @__PURE__ */ (0,
|
|
1207
|
-
/* @__PURE__ */ (0,
|
|
1208
|
-
finding ? /* @__PURE__ */ (0,
|
|
1209
|
-
/* @__PURE__ */ (0,
|
|
1255
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hv-group hv-find", children: [
|
|
1256
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.search, title: `${labels.search} (/)`, "aria-pressed": finding, onClick: () => finding ? closeFind() : setFinding(true), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Glyph, { d: ICONS.search }) }),
|
|
1257
|
+
finding ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1258
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1210
1259
|
"input",
|
|
1211
1260
|
{
|
|
1212
1261
|
ref: finder,
|
|
@@ -1222,37 +1271,37 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1222
1271
|
onKeyDown: onFindKey
|
|
1223
1272
|
}
|
|
1224
1273
|
),
|
|
1225
|
-
/* @__PURE__ */ (0,
|
|
1274
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("output", { className: "hv-count", "aria-live": "polite", children: status })
|
|
1226
1275
|
] }) : null
|
|
1227
1276
|
] }),
|
|
1228
|
-
/* @__PURE__ */ (0,
|
|
1229
|
-
/* @__PURE__ */ (0,
|
|
1230
|
-
/* @__PURE__ */ (0,
|
|
1231
|
-
/* @__PURE__ */ (0,
|
|
1232
|
-
/* @__PURE__ */ (0,
|
|
1233
|
-
canCopyImage ? /* @__PURE__ */ (0,
|
|
1277
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hv-group hv-export", children: [
|
|
1278
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn hv-txt", "aria-label": labels.copySource, title: labels.copySource, onClick: () => run(() => navigator.clipboard.writeText(source).then(() => labels.copied)), children: "MMD" }),
|
|
1279
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn hv-txt", "aria-label": labels.downloadSvg, title: labels.downloadSvg, onClick: () => run(async () => downloadBlob(svgBlob(svg), fileName(title, "svg"))), children: "SVG" }),
|
|
1280
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn hv-txt", "aria-label": labels.downloadPng, title: labels.downloadPng, onClick: () => run(async () => downloadBlob(await png(), fileName(title, "png"))), children: "PNG" }),
|
|
1281
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("select", { className: "hv-select", "aria-label": labels.pngScale, title: labels.pngScale, value: scale, onChange: (e) => setScale(e.target.value), children: SCALES.map((s) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: s, children: `${s}\xD7` }, s)) }),
|
|
1282
|
+
canCopyImage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn hv-txt", "aria-label": labels.copyImage, title: labels.copyImage, onClick: () => run(() => navigator.clipboard.write([new ClipboardItem({ "image/png": png() })]).then(() => labels.copied)), children: "IMG" }) : null
|
|
1234
1283
|
] }),
|
|
1235
|
-
/* @__PURE__ */ (0,
|
|
1236
|
-
canFullscreen ? /* @__PURE__ */ (0,
|
|
1237
|
-
/* @__PURE__ */ (0,
|
|
1284
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hv-group hv-end", children: [
|
|
1285
|
+
canFullscreen ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn", "aria-label": fullscreen ? labels.exitFullscreen : labels.fullscreen, title: fullscreen ? labels.exitFullscreen : labels.fullscreen, "aria-pressed": fullscreen, onClick: () => fullscreen ? void document.exitFullscreen() : void shell.current?.requestFullscreen().catch(() => say(labels.unavailable)), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Glyph, { d: fullscreen ? ICONS.exit : ICONS.full }) }) : null,
|
|
1286
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.close, title: `${labels.close} (Esc)`, onClick: () => dialog.current?.close(), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Glyph, { d: ICONS.close }) })
|
|
1238
1287
|
] })
|
|
1239
1288
|
] }),
|
|
1240
|
-
/* @__PURE__ */ (0,
|
|
1241
|
-
/* @__PURE__ */ (0,
|
|
1242
|
-
/* @__PURE__ */ (0,
|
|
1243
|
-
ui.pinned ? /* @__PURE__ */ (0,
|
|
1244
|
-
/* @__PURE__ */ (0,
|
|
1245
|
-
/* @__PURE__ */ (0,
|
|
1246
|
-
/* @__PURE__ */ (0,
|
|
1289
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "hv-view", ref: viewport, tabIndex: -1, role: "group", "aria-label": title, "aria-describedby": helpId, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "hv-stage", ref: stage }) }),
|
|
1290
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("canvas", { className: "hv-mini", ref: minimap, width: 176, height: 120, hidden: !ui.minimap, "aria-hidden": "true" }),
|
|
1291
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "hv-foot", children: [
|
|
1292
|
+
ui.pinned ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("ul", { className: "hv-legend", "aria-hidden": "true", children: [
|
|
1293
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { className: "hv-sel", children: labels.legendSelected }),
|
|
1294
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { className: "hv-up", children: labels.legendUpstream }),
|
|
1295
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { className: "hv-down", children: labels.legendDownstream })
|
|
1247
1296
|
] }) : null,
|
|
1248
|
-
/* @__PURE__ */ (0,
|
|
1249
|
-
/* @__PURE__ */ (0,
|
|
1297
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "hv-hint", id: helpId, children: labels.hint }),
|
|
1298
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("output", { className: "hv-toast", children: toast })
|
|
1250
1299
|
] })
|
|
1251
1300
|
] })
|
|
1252
1301
|
}
|
|
1253
1302
|
);
|
|
1254
1303
|
}
|
|
1255
|
-
var import_react,
|
|
1304
|
+
var import_react, import_jsx_runtime2, sequence, locks, LOCK_CLASS, FULLSCREEN_CLASS, SCALES, TOAST_MS, Glyph, ICONS;
|
|
1256
1305
|
var init_diagram_viewer = __esm({
|
|
1257
1306
|
"src/react/viewer/diagram-viewer.tsx"() {
|
|
1258
1307
|
"use strict";
|
|
@@ -1261,18 +1310,19 @@ var init_diagram_viewer = __esm({
|
|
|
1261
1310
|
init_export();
|
|
1262
1311
|
init_labels();
|
|
1263
1312
|
init_scope_svg();
|
|
1264
|
-
|
|
1313
|
+
import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1265
1314
|
sequence = 0;
|
|
1266
1315
|
locks = 0;
|
|
1267
1316
|
LOCK_CLASS = "hyle-viewer-lock";
|
|
1317
|
+
FULLSCREEN_CLASS = "hyle-viewer-fs";
|
|
1268
1318
|
SCALES = ["1", "2", "4"];
|
|
1269
1319
|
TOAST_MS = 4e3;
|
|
1270
|
-
Glyph = ({ d }) => /* @__PURE__ */ (0,
|
|
1320
|
+
Glyph = ({ d }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "hv-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d }) });
|
|
1271
1321
|
ICONS = {
|
|
1272
1322
|
close: "m4 4 8 8M12 4l-8 8",
|
|
1273
1323
|
fit: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",
|
|
1274
1324
|
search: "M7 12.2A5.2 5.2 0 1 0 7 1.8a5.2 5.2 0 0 0 0 10.4zM11 11l3.2 3.2",
|
|
1275
|
-
full: "
|
|
1325
|
+
full: "M9.5 2.5h4v4M13.5 2.5 9 7M6.5 13.5h-4v-4M2.5 13.5 7 9",
|
|
1276
1326
|
exit: "M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"
|
|
1277
1327
|
};
|
|
1278
1328
|
}
|
|
@@ -1281,41 +1331,174 @@ var init_diagram_viewer = __esm({
|
|
|
1281
1331
|
// src/react/mermaid-diagram.tsx
|
|
1282
1332
|
var mermaid_diagram_exports = {};
|
|
1283
1333
|
__export(mermaid_diagram_exports, {
|
|
1334
|
+
DiagramBoundary: () => DiagramBoundary,
|
|
1284
1335
|
MermaidDiagram: () => MermaidDiagram
|
|
1285
1336
|
});
|
|
1286
1337
|
module.exports = __toCommonJS(mermaid_diagram_exports);
|
|
1287
1338
|
var import_react2 = require("react");
|
|
1288
1339
|
|
|
1340
|
+
// src/react/diagram-frame.tsx
|
|
1341
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1342
|
+
function LargeDiagram({ source, sourceId, labels, errorText, live, drawing, busy, failed, clamped, showAll, onDraw, onToggle }) {
|
|
1343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1344
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hyle-mermaid-gate", inert: !live, children: [
|
|
1345
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hyle-mermaid-gate-text", children: [
|
|
1346
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "hyle-mermaid-gate-title", children: labels.largeTitle }),
|
|
1347
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "hyle-mermaid-gate-body", children: labels.largeBody })
|
|
1348
|
+
] }),
|
|
1349
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "hyle-mermaid-draw", "aria-disabled": busy ? true : void 0, onClick: onDraw, children: busy ? labels.drawing : failed ? labels.drawAgain : labels.drawLarge }),
|
|
1350
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "sr-only", role: "status", children: drawing ? labels.drawingBody : failed ? errorText : "" }),
|
|
1351
|
+
failed ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "hyle-mermaid-note", "aria-hidden": "true", children: errorText }) : null
|
|
1352
|
+
] }),
|
|
1353
|
+
drawing ? (
|
|
1354
|
+
// The status above speaks for it; this is what a sighted reader watches while the page is blocked.
|
|
1355
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hyle-mermaid-drawing", "aria-hidden": "true", children: [
|
|
1356
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "hyle-mermaid-spinner" }),
|
|
1357
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: labels.drawingBody })
|
|
1358
|
+
] })
|
|
1359
|
+
) : null,
|
|
1360
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hyle-mermaid-source", "data-drawing": drawing ? "" : void 0, "data-clamped": live && clamped && !showAll ? "" : void 0, children: [
|
|
1361
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { id: sourceId, tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { className: "language-mermaid", children: source }) }),
|
|
1362
|
+
clamped ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "hyle-mermaid-more", inert: !live, "aria-expanded": showAll, "aria-controls": sourceId, onClick: (e) => onToggle(e.currentTarget), children: showAll ? labels.hideSource : labels.showSource }) : null
|
|
1363
|
+
] })
|
|
1364
|
+
] });
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1289
1367
|
// src/react/mermaid-config.ts
|
|
1290
1368
|
var MAX_MERMAID_SOURCE = 1024 * 1024;
|
|
1291
|
-
var MAX_MERMAID_EDGES =
|
|
1292
|
-
|
|
1293
|
-
|
|
1369
|
+
var MAX_MERMAID_EDGES = 500;
|
|
1370
|
+
var AUTO_RENDER_EDGES = 100;
|
|
1371
|
+
var AUTO_RENDER_CHARS = 6e3;
|
|
1372
|
+
var AUTO_RENDER_STATEMENTS = 250;
|
|
1373
|
+
var AUTO_RENDER_WORDS = 800;
|
|
1374
|
+
var AUTO_RENDER_GROUPS = 25;
|
|
1375
|
+
var CLAMP_LINES = 12;
|
|
1376
|
+
var isClampedSource = (source) => source.trimEnd().split("\n").length > CLAMP_LINES;
|
|
1377
|
+
var DARK_VARIABLES = { edgeLabelBackground: "#333333" };
|
|
1378
|
+
var DIAGRAM_COLOUR_ROLES = ["bg", "node", "node-text", "node-border", "line", "accent", "muted"];
|
|
1379
|
+
var THEME_COLOUR = /^(?:#[0-9a-f]{6}(?:[0-9a-f]{2})?|transparent)$/;
|
|
1380
|
+
function diagramThemeVariables(colours, dark) {
|
|
1381
|
+
const [bg, node, text, border, line, accent, muted] = colours;
|
|
1382
|
+
return {
|
|
1383
|
+
darkMode: dark,
|
|
1384
|
+
background: bg,
|
|
1385
|
+
primaryColor: node,
|
|
1386
|
+
primaryTextColor: text,
|
|
1387
|
+
primaryBorderColor: border,
|
|
1388
|
+
secondaryColor: bg,
|
|
1389
|
+
secondaryTextColor: text,
|
|
1390
|
+
secondaryBorderColor: muted,
|
|
1391
|
+
tertiaryColor: bg,
|
|
1392
|
+
tertiaryTextColor: text,
|
|
1393
|
+
tertiaryBorderColor: muted,
|
|
1394
|
+
lineColor: line,
|
|
1395
|
+
textColor: text,
|
|
1396
|
+
titleColor: text,
|
|
1397
|
+
edgeLabelBackground: bg,
|
|
1398
|
+
clusterBkg: bg,
|
|
1399
|
+
clusterBorder: muted,
|
|
1400
|
+
noteBkgColor: bg,
|
|
1401
|
+
noteTextColor: text,
|
|
1402
|
+
noteBorderColor: accent,
|
|
1403
|
+
activationBorderColor: accent,
|
|
1404
|
+
actorLineColor: muted,
|
|
1405
|
+
signalColor: line,
|
|
1406
|
+
signalTextColor: text
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
var COLOR = /^(rgba?|oklab|oklch|lab|lch)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/;
|
|
1410
|
+
function isDark(css) {
|
|
1411
|
+
const m = COLOR.exec(css.trim());
|
|
1294
1412
|
if (!m) return void 0;
|
|
1295
|
-
const
|
|
1296
|
-
const
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
|
|
1413
|
+
const kind = m[1] ?? "color";
|
|
1414
|
+
const parts = (m[2] ?? m[3] ?? "").split(/[\s,/]+/).filter(Boolean);
|
|
1415
|
+
const [a, b, c] = parts.map((v) => v === "none" ? 0 : Number.parseFloat(v));
|
|
1416
|
+
const alpha = parts[3] === void 0 ? 1 : Number.parseFloat(parts[3]) / (parts[3].endsWith("%") ? 100 : 1);
|
|
1417
|
+
if (a === void 0 || b === void 0 || c === void 0 || [a, b, c, alpha].some(Number.isNaN) || alpha < 0.5) return void 0;
|
|
1418
|
+
if (kind.startsWith("ok")) return (parts[0]?.endsWith("%") ? a / 100 : a) < 0.6;
|
|
1419
|
+
if (kind.startsWith("l")) return a < 53;
|
|
1420
|
+
const scale = kind === "color" ? 1 : 255;
|
|
1421
|
+
return (0.2126 * a + 0.7152 * b + 0.0722 * c) / scale < 0.5;
|
|
1422
|
+
}
|
|
1423
|
+
function pickMermaidTheme(background, prefersDark, colorScheme = "") {
|
|
1424
|
+
const declared = /\bdark\b/.test(colorScheme) === /\blight\b/.test(colorScheme) ? void 0 : /\bdark\b/.test(colorScheme);
|
|
1425
|
+
return isDark(background) ?? declared ?? prefersDark ? "dark" : "default";
|
|
1300
1426
|
}
|
|
1301
|
-
function
|
|
1302
|
-
const
|
|
1303
|
-
|
|
1427
|
+
function watchPageTheme(el, onTheme) {
|
|
1428
|
+
const scheme = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1429
|
+
const update = () => {
|
|
1430
|
+
const style = getComputedStyle(el);
|
|
1431
|
+
const colours = DIAGRAM_COLOUR_ROLES.map((role) => style.getPropertyValue(`--hyle-diagram-${role}`).trim());
|
|
1432
|
+
onTheme(pickMermaidTheme(style.backgroundColor, scheme.matches, style.colorScheme), colours.every((c) => THEME_COLOUR.test(c)) ? colours.join(" ") : "");
|
|
1433
|
+
};
|
|
1434
|
+
update();
|
|
1435
|
+
const observer = new MutationObserver(update);
|
|
1436
|
+
observer.observe(document.documentElement, { attributes: true });
|
|
1437
|
+
observer.observe(document.body, { attributes: true });
|
|
1438
|
+
scheme.addEventListener("change", update);
|
|
1439
|
+
return () => {
|
|
1440
|
+
observer.disconnect();
|
|
1441
|
+
scheme.removeEventListener("change", update);
|
|
1442
|
+
};
|
|
1304
1443
|
}
|
|
1305
1444
|
var RENDER_TIMEOUT_MS = 1e4;
|
|
1306
1445
|
var NEAR_VIEWPORT_MARGIN = "200px";
|
|
1307
|
-
var FRONTMATTER =
|
|
1446
|
+
var FRONTMATTER = /\s*-{3}[^\S\n]*\n[\s\S]*?\n[^\S\n]*-{3}[^\S\n]*(?:\n|$)/y;
|
|
1308
1447
|
var DIRECTIVE = /%%\{(?:(?!\}%%)[\s\S])*(?:\}%%)?/g;
|
|
1448
|
+
var MAX_STRIP_ROUNDS = 16;
|
|
1449
|
+
function dropFrontmatter(text) {
|
|
1450
|
+
let end = 0;
|
|
1451
|
+
for (; ; ) {
|
|
1452
|
+
FRONTMATTER.lastIndex = end;
|
|
1453
|
+
const block = FRONTMATTER.exec(text);
|
|
1454
|
+
if (!block) return text.slice(end);
|
|
1455
|
+
end += block[0].length;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1309
1458
|
function stripMermaidConfig(source) {
|
|
1310
1459
|
let text = source.replace(/\r\n?/g, "\n");
|
|
1311
|
-
for (let
|
|
1312
|
-
|
|
1313
|
-
|
|
1460
|
+
for (let round = 0; round < MAX_STRIP_ROUNDS; round++) {
|
|
1461
|
+
const next = dropFrontmatter(text).replace(DIRECTIVE, "");
|
|
1462
|
+
if (next === text) return text;
|
|
1463
|
+
text = next;
|
|
1314
1464
|
}
|
|
1315
|
-
return
|
|
1465
|
+
return "";
|
|
1466
|
+
}
|
|
1467
|
+
var EDGE_TOKEN = /-{2,}|={2,}|~{3}|\.{2,}|\.-|-[>x)]/;
|
|
1468
|
+
var ER_TOKEN = /-{2,}|={2,}|~{3}|\.{2,}|\.-|-[>x)]|-\.|to\b/i;
|
|
1469
|
+
var AMPERSAND = /\s&(?=\s)/g;
|
|
1470
|
+
var GROUP_OPENER = /^(?:subgraph\b|state\b.*\{)/;
|
|
1471
|
+
var BLOCK_OPENER = /\bblock\b(?!-)/g;
|
|
1472
|
+
var DEFAULT_LIMITS = { statements: AUTO_RENDER_STATEMENTS, words: AUTO_RENDER_WORDS, groups: AUTO_RENDER_GROUPS, edges: AUTO_RENDER_EDGES, blocks: Infinity, token: EDGE_TOKEN };
|
|
1473
|
+
var TYPE_LIMITS = {
|
|
1474
|
+
mindmap: { statements: 40 },
|
|
1475
|
+
kanban: { statements: 100 },
|
|
1476
|
+
block: { words: 100, blocks: 8 },
|
|
1477
|
+
erDiagram: { statements: 120, edges: 50, token: ER_TOKEN },
|
|
1478
|
+
"venn-beta": { statements: 180 },
|
|
1479
|
+
classDiagram: { statements: 70, edges: 30 },
|
|
1480
|
+
stateDiagram: { statements: 80 }
|
|
1481
|
+
};
|
|
1482
|
+
var COMMENT_LINE = /^[^\S\n\u2028\u2029]*%%[^\n]+\n?/gm;
|
|
1483
|
+
var statementsOf = (code) => code.split(/[\n;]/).map((s) => s.trim()).filter((s) => s && s !== "end");
|
|
1484
|
+
var edgeBound = (code, token) => {
|
|
1485
|
+
const amps = code.match(AMPERSAND)?.length ?? 0;
|
|
1486
|
+
return code.split(token).length - 1 + 2 * amps + Math.floor(amps ** 2 / 4);
|
|
1487
|
+
};
|
|
1488
|
+
function isLargeDiagram(source) {
|
|
1489
|
+
if (source.length > AUTO_RENDER_CHARS) return true;
|
|
1490
|
+
const code = stripMermaidConfig(source).replace(COMMENT_LINE, "");
|
|
1491
|
+
const statements = statementsOf(code);
|
|
1492
|
+
const first = statements.find((line) => !line.startsWith("%%")) ?? "";
|
|
1493
|
+
const type = Object.keys(TYPE_LIMITS).find((keyword) => first.startsWith(keyword));
|
|
1494
|
+
const limit = { ...DEFAULT_LIMITS, ...type ? TYPE_LIMITS[type] : void 0 };
|
|
1495
|
+
const words = statements.reduce((n, line) => n + line.split(/\s+/).length, 0);
|
|
1496
|
+
const groups = statements.filter((line) => GROUP_OPENER.test(line)).length;
|
|
1497
|
+
const blocks = code.match(BLOCK_OPENER)?.length ?? 0;
|
|
1498
|
+
return statements.length > limit.statements || words > limit.words || groups > limit.groups || blocks > limit.blocks || edgeBound(code, limit.token) > limit.edges;
|
|
1316
1499
|
}
|
|
1317
1500
|
var counter = 0;
|
|
1318
|
-
var nextMermaidId = () => `
|
|
1501
|
+
var nextMermaidId = () => `hyleMermaid-${++counter}`;
|
|
1319
1502
|
function withTimeout(promise, ms) {
|
|
1320
1503
|
let timer;
|
|
1321
1504
|
const timeout = new Promise((_, reject) => {
|
|
@@ -1338,87 +1521,220 @@ function whenNearViewport(el, onNear, Observer = globalThis.IntersectionObserver
|
|
|
1338
1521
|
observer.observe(el);
|
|
1339
1522
|
return () => observer.disconnect();
|
|
1340
1523
|
}
|
|
1524
|
+
function afterFullscreen(within, then) {
|
|
1525
|
+
if (document.fullscreenElement && within?.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
|
|
1526
|
+
}).then(then);
|
|
1527
|
+
else then();
|
|
1528
|
+
}
|
|
1341
1529
|
|
|
1342
1530
|
// src/react/mermaid-diagram.tsx
|
|
1531
|
+
var import_print_coordinator = require("./print-coordinator.cjs");
|
|
1343
1532
|
init_labels();
|
|
1344
|
-
var
|
|
1533
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1534
|
+
var DiagramBoundary = class extends import_react2.Component {
|
|
1535
|
+
state = { failed: false };
|
|
1536
|
+
static getDerivedStateFromError() {
|
|
1537
|
+
return { failed: true };
|
|
1538
|
+
}
|
|
1539
|
+
render() {
|
|
1540
|
+
if (!this.state.failed) return this.props.children;
|
|
1541
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("figure", { className: "hyle-mermaid", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("code", { className: "language-mermaid", children: this.props.source }) }) });
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1345
1544
|
var queue = Promise.resolve();
|
|
1346
|
-
|
|
1545
|
+
var afterPaint = () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
1546
|
+
async function renderSvg(id, source, theme, colours, onSvg, stillWanted) {
|
|
1347
1547
|
const { default: mermaid } = await import("mermaid");
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
} finally {
|
|
1352
|
-
document.getElementById(`d${id}`)?.remove();
|
|
1548
|
+
if (stillWanted) {
|
|
1549
|
+
await afterPaint();
|
|
1550
|
+
if (!stillWanted()) return;
|
|
1353
1551
|
}
|
|
1552
|
+
const look = colours ? { theme: "base", themeVariables: diagramThemeVariables(colours.split(" "), theme === "dark") } : { theme, ...theme === "dark" ? { themeVariables: DARK_VARIABLES } : {} };
|
|
1553
|
+
mermaid.initialize({ startOnLoad: false, securityLevel: "strict", ...look, maxTextSize: MAX_MERMAID_SOURCE, maxEdges: MAX_MERMAID_EDGES, suppressErrorRendering: true });
|
|
1554
|
+
const drawing = mermaid.render(id, stripMermaidConfig(source)).then((out) => onSvg({ markup: out.svg, id, theme })).finally(() => document.getElementById(`d${id}`)?.remove());
|
|
1555
|
+
await withTimeout(drawing, RENDER_TIMEOUT_MS);
|
|
1354
1556
|
}
|
|
1355
|
-
var
|
|
1356
|
-
|
|
1557
|
+
var noSubscription = () => () => {
|
|
1558
|
+
};
|
|
1559
|
+
function Diagram({ source, title, errorText, loadingText = "Rendering the diagram", labels = VIEWER_LABELS_EN }) {
|
|
1357
1560
|
const figure = (0, import_react2.useRef)(null);
|
|
1358
1561
|
const trigger = (0, import_react2.useRef)(null);
|
|
1359
1562
|
const captionId = (0, import_react2.useId)();
|
|
1563
|
+
const sourceId = (0, import_react2.useId)();
|
|
1564
|
+
const live = (0, import_react2.useSyncExternalStore)(noSubscription, () => true, () => false);
|
|
1360
1565
|
const [open, setOpen] = (0, import_react2.useState)(false);
|
|
1361
1566
|
const [Viewer, setViewer] = (0, import_react2.useState)(null);
|
|
1567
|
+
const [viewerFailed, setViewerFailed] = (0, import_react2.useState)(false);
|
|
1362
1568
|
const [theme, setTheme] = (0, import_react2.useState)(null);
|
|
1569
|
+
const [colours, setColours] = (0, import_react2.useState)("");
|
|
1363
1570
|
const [near, setNear] = (0, import_react2.useState)(false);
|
|
1364
1571
|
const [svg, setSvg] = (0, import_react2.useState)(null);
|
|
1365
1572
|
const [failed, setFailed] = (0, import_react2.useState)(false);
|
|
1573
|
+
const large = (0, import_react2.useMemo)(() => isLargeDiagram(source), [source]);
|
|
1574
|
+
const [asked, setAsked] = (0, import_react2.useState)(false);
|
|
1575
|
+
const [attempt, setAttempt] = (0, import_react2.useState)(0);
|
|
1576
|
+
const [showAll, setShowAll] = (0, import_react2.useState)(false);
|
|
1577
|
+
const refocus = (0, import_react2.useRef)(false);
|
|
1578
|
+
const allowed = !large || asked;
|
|
1579
|
+
const clamped = large && isClampedSource(source);
|
|
1580
|
+
(0, import_react2.useEffect)(() => {
|
|
1581
|
+
if (!figure.current) return void 0;
|
|
1582
|
+
return watchPageTheme(figure.current, (next, themed) => {
|
|
1583
|
+
setTheme(next);
|
|
1584
|
+
setColours(themed);
|
|
1585
|
+
});
|
|
1586
|
+
}, []);
|
|
1587
|
+
(0, import_react2.useEffect)(() => figure.current ? whenNearViewport(figure.current, () => setNear(true)) : void 0, []);
|
|
1366
1588
|
(0, import_react2.useEffect)(() => {
|
|
1367
|
-
const
|
|
1368
|
-
const
|
|
1369
|
-
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
|
|
1589
|
+
const toPrint = window.matchMedia("print");
|
|
1590
|
+
const draw2 = () => setNear(true);
|
|
1591
|
+
if (toPrint.matches) draw2();
|
|
1592
|
+
const onChange = (e) => {
|
|
1593
|
+
if (e.matches) draw2();
|
|
1594
|
+
};
|
|
1595
|
+
window.addEventListener("beforeprint", draw2);
|
|
1596
|
+
toPrint.addEventListener("change", onChange);
|
|
1373
1597
|
return () => {
|
|
1374
|
-
|
|
1375
|
-
|
|
1598
|
+
window.removeEventListener("beforeprint", draw2);
|
|
1599
|
+
toPrint.removeEventListener("change", onChange);
|
|
1376
1600
|
};
|
|
1377
1601
|
}, []);
|
|
1378
|
-
(0, import_react2.
|
|
1602
|
+
const settled = (0, import_react2.useRef)(false);
|
|
1603
|
+
const shown = (0, import_react2.useRef)(false);
|
|
1604
|
+
const allowedNow = (0, import_react2.useRef)(allowed);
|
|
1605
|
+
const waiters = (0, import_react2.useRef)([]);
|
|
1379
1606
|
(0, import_react2.useEffect)(() => {
|
|
1380
|
-
|
|
1607
|
+
allowedNow.current = allowed;
|
|
1608
|
+
settled.current = svg !== null || failed || !allowed;
|
|
1609
|
+
shown.current = svg !== null;
|
|
1610
|
+
if (settled.current) waiters.current.splice(0).forEach((resolve) => resolve());
|
|
1611
|
+
}, [svg, failed, allowed]);
|
|
1612
|
+
(0, import_react2.useEffect)(() => {
|
|
1613
|
+
const pending = waiters.current;
|
|
1614
|
+
const uninstall = (0, import_print_coordinator.installPrintShortcut)();
|
|
1615
|
+
const unregister = (0, import_print_coordinator.registerPrintTarget)({
|
|
1616
|
+
status: labels.printPreparing,
|
|
1617
|
+
settled: () => settled.current,
|
|
1618
|
+
prepare: () => allowedNow.current ? import("mermaid") : Promise.resolve(),
|
|
1619
|
+
ensureDrawn: () => settled.current ? Promise.resolve() : new Promise((resolve) => {
|
|
1620
|
+
pending.push(resolve);
|
|
1621
|
+
setNear(true);
|
|
1622
|
+
})
|
|
1623
|
+
});
|
|
1624
|
+
return () => {
|
|
1625
|
+
unregister();
|
|
1626
|
+
uninstall();
|
|
1627
|
+
pending.splice(0).forEach((resolve) => resolve());
|
|
1628
|
+
};
|
|
1629
|
+
}, [labels.printPreparing]);
|
|
1630
|
+
const wanted = near && allowed;
|
|
1631
|
+
(0, import_react2.useEffect)(() => {
|
|
1632
|
+
if (theme === null || !wanted) return;
|
|
1381
1633
|
let current = true;
|
|
1382
1634
|
const id = nextMermaidId();
|
|
1383
|
-
|
|
1384
|
-
(
|
|
1385
|
-
()
|
|
1386
|
-
|
|
1635
|
+
const show = (out) => {
|
|
1636
|
+
if (!current) return;
|
|
1637
|
+
setSvg(out);
|
|
1638
|
+
setFailed(false);
|
|
1639
|
+
};
|
|
1640
|
+
queue = queue.then(() => current ? renderSvg(id, source, theme, colours, show, large && !shown.current ? () => current : void 0) : void 0).catch(() => {
|
|
1641
|
+
if (current) setFailed(true);
|
|
1642
|
+
});
|
|
1387
1643
|
return () => {
|
|
1388
1644
|
current = false;
|
|
1389
1645
|
};
|
|
1390
|
-
}, [source, theme,
|
|
1646
|
+
}, [source, theme, colours, wanted, attempt, large]);
|
|
1647
|
+
(0, import_react2.useEffect)(() => {
|
|
1648
|
+
if (!refocus.current || svg === null && !failed) return;
|
|
1649
|
+
refocus.current = false;
|
|
1650
|
+
const active = document.activeElement;
|
|
1651
|
+
if (svg && (!active || active === document.body)) trigger.current?.focus({ preventScroll: true });
|
|
1652
|
+
}, [svg, failed]);
|
|
1653
|
+
const collapsed = (0, import_react2.useRef)(null);
|
|
1654
|
+
(0, import_react2.useLayoutEffect)(() => {
|
|
1655
|
+
collapsed.current?.scrollIntoView({ block: "nearest" });
|
|
1656
|
+
collapsed.current = null;
|
|
1657
|
+
}, [showAll]);
|
|
1658
|
+
const toggleSource = (button) => {
|
|
1659
|
+
collapsed.current = showAll ? button : null;
|
|
1660
|
+
setShowAll(!showAll);
|
|
1661
|
+
};
|
|
1391
1662
|
const html = (0, import_react2.useMemo)(() => svg ? { __html: svg.markup } : void 0, [svg]);
|
|
1663
|
+
const drawing = wanted && svg === null && !failed;
|
|
1664
|
+
const busy = asked && !failed;
|
|
1665
|
+
const draw = () => {
|
|
1666
|
+
if (busy) return;
|
|
1667
|
+
refocus.current = true;
|
|
1668
|
+
setAsked(true);
|
|
1669
|
+
setNear(true);
|
|
1670
|
+
if (failed) {
|
|
1671
|
+
setFailed(false);
|
|
1672
|
+
setAttempt((n) => n + 1);
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1392
1675
|
const expand = (e) => {
|
|
1393
1676
|
if (e.target.closest("a")) return;
|
|
1677
|
+
const selection = window.getSelection();
|
|
1678
|
+
if (selection && !selection.isCollapsed && figure.current?.contains(selection.anchorNode)) return;
|
|
1394
1679
|
setOpen(true);
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-mermaid-svg", dangerouslySetInnerHTML: html }),
|
|
1401
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-mermaid-hint", "aria-hidden": "true", children: labels.expandHint })
|
|
1402
|
-
] }),
|
|
1403
|
-
open && Viewer && svg ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1404
|
-
Viewer,
|
|
1405
|
-
{
|
|
1406
|
-
svg: svg.markup,
|
|
1407
|
-
svgId: svg.id,
|
|
1408
|
-
source,
|
|
1409
|
-
title,
|
|
1410
|
-
labels,
|
|
1411
|
-
onClose: () => {
|
|
1680
|
+
setViewerFailed(false);
|
|
1681
|
+
if (!Viewer) {
|
|
1682
|
+
void Promise.resolve().then(() => (init_diagram_viewer(), diagram_viewer_exports)).then(
|
|
1683
|
+
(m) => setViewer(() => m.DiagramViewer),
|
|
1684
|
+
() => {
|
|
1412
1685
|
setOpen(false);
|
|
1413
|
-
|
|
1686
|
+
setViewerFailed(true);
|
|
1414
1687
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1688
|
+
);
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1692
|
+
"figure",
|
|
1693
|
+
{
|
|
1694
|
+
ref: figure,
|
|
1695
|
+
className: "hyle-mermaid",
|
|
1696
|
+
"data-slot-component": "Mermaid",
|
|
1697
|
+
"data-mermaid-theme": svg?.theme,
|
|
1698
|
+
...allowed && svg === null && !failed ? { "data-state": "pending" } : {},
|
|
1699
|
+
...!live && clamped ? { "data-clamp": "" } : {},
|
|
1700
|
+
children: [
|
|
1701
|
+
svg !== null ? (
|
|
1702
|
+
// The whole diagram is a click target for the mouse; the button is the one control for keyboard and assistive technology, and its
|
|
1703
|
+
// text ("Expand") is the start of its name. A diagram's own text must not be inside a button (axe label-content-name-mismatch).
|
|
1704
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "hyle-mermaid-open", role: "presentation", onClick: expand, children: [
|
|
1705
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "hyle-mermaid-svg", dangerouslySetInnerHTML: html }),
|
|
1706
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { ref: trigger, type: "button", className: "hyle-mermaid-hint", "aria-label": labels.expand, "aria-describedby": captionId, "aria-haspopup": "dialog", children: labels.expandHint })
|
|
1707
|
+
] })
|
|
1708
|
+
) : large ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LargeDiagram, { source, sourceId, labels, errorText, live, drawing, busy, failed, clamped, showAll, onDraw: draw, onToggle: toggleSource }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1709
|
+
drawing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "hyle-mermaid-loader", role: "status", "aria-busy": "true", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "sr-only", children: loadingText }) }) : null,
|
|
1710
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("code", { className: "language-mermaid", children: source }) })
|
|
1711
|
+
] }),
|
|
1712
|
+
open && Viewer && svg ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1713
|
+
Viewer,
|
|
1714
|
+
{
|
|
1715
|
+
svg: svg.markup,
|
|
1716
|
+
svgId: svg.id,
|
|
1717
|
+
source,
|
|
1718
|
+
title,
|
|
1719
|
+
labels,
|
|
1720
|
+
onClose: () => afterFullscreen(figure.current, () => {
|
|
1721
|
+
setOpen(false);
|
|
1722
|
+
trigger.current?.focus({ preventScroll: true });
|
|
1723
|
+
})
|
|
1724
|
+
}
|
|
1725
|
+
) : null,
|
|
1726
|
+
failed && (svg !== null || !large) ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: errorText }) : null,
|
|
1727
|
+
viewerFailed ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: labels.unavailable }) : null,
|
|
1728
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("figcaption", { id: svg ? captionId : void 0, className: "sr-only", children: title })
|
|
1729
|
+
]
|
|
1730
|
+
}
|
|
1731
|
+
);
|
|
1732
|
+
}
|
|
1733
|
+
function MermaidDiagram(props) {
|
|
1734
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DiagramBoundary, { source: props.source, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Diagram, { ...props }) });
|
|
1420
1735
|
}
|
|
1421
1736
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1422
1737
|
0 && (module.exports = {
|
|
1738
|
+
DiagramBoundary,
|
|
1423
1739
|
MermaidDiagram
|
|
1424
1740
|
});
|