@tdacorp/hyle-sdk 0.17.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -28
- package/dist/check-routes-bin.js +38 -13
- package/dist/chunk-56Y24XBV.js +840 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-75JFLML4.js} +176 -14
- package/dist/chunk-HJX57NLI.js +1105 -0
- package/dist/chunk-K5VDLROQ.js +145 -0
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/{chunk-6VOHFFA5.js → chunk-X2TLYM7Y.js} +2 -2
- package/dist/client-41fU6OY2.d.cts +201 -0
- package/dist/client-LwzHwqpM.d.ts +201 -0
- package/dist/code-copy.cjs +72 -0
- package/dist/code-copy.d.cts +15 -0
- package/dist/code-copy.d.ts +15 -0
- package/dist/code-copy.js +48 -0
- package/dist/comments.cjs +728 -275
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +409 -326
- package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
- package/dist/{embed-BmdwA2G9.d.cts → embed-BUFRQboD.d.ts} +2 -2
- package/dist/{embed-DNTZ2UXv.d.ts → embed-CYt-q13P.d.cts} +2 -2
- 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 +881 -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 +181 -14
- package/dist/index.d.cts +14 -62
- package/dist/index.d.ts +14 -62
- package/dist/index.js +11 -1
- package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.cts} +9 -0
- package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.ts} +9 -0
- package/dist/mermaid-diagram.cjs +401 -125
- package/dist/mermaid-diagram.d.cts +23 -7
- package/dist/mermaid-diagram.d.ts +23 -7
- package/dist/mermaid-diagram.js +204 -51
- package/dist/mermaid-image.cjs +134 -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 +627 -264
- package/dist/next.d.cts +11 -8
- package/dist/next.d.ts +11 -8
- package/dist/next.js +39 -12
- 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 +556 -226
- package/dist/react.d.cts +136 -29
- package/dist/react.d.ts +136 -29
- package/dist/react.js +23 -3
- 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-Ae7UFjsQ.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
- package/dist/{resolve-euZ4-aC9.d.cts → resolve-eI1muCKL.d.cts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-ijiWjEm9.d.cts +23 -0
- package/dist/sanitize-ijiWjEm9.d.ts +23 -0
- package/dist/styles.css +96 -25
- package/dist/toc-spy.cjs +59 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +35 -0
- package/dist/{types-Czt887Iv.d.cts → types-3F0wqD-o.d.cts} +26 -2
- package/dist/{types-Czt887Iv.d.ts → types-3F0wqD-o.d.ts} +26 -2
- package/dist/use-cache.cjs +37 -11
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +7 -7
- 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-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-image.cjs
CHANGED
|
@@ -34,15 +34,15 @@ var init_labels = __esm({
|
|
|
34
34
|
zoomIn: "Zoom in",
|
|
35
35
|
zoomOut: "Zoom out",
|
|
36
36
|
fit: "Fit to window",
|
|
37
|
-
actual: "
|
|
37
|
+
actual: "100%: actual size",
|
|
38
38
|
search: "Find in diagram",
|
|
39
39
|
searchPlaceholder: "Find",
|
|
40
40
|
noMatch: "No match",
|
|
41
41
|
matchOf: "{n} of {total}",
|
|
42
|
-
copySource: "
|
|
43
|
-
downloadSvg: "
|
|
44
|
-
downloadPng: "
|
|
45
|
-
copyImage: "
|
|
42
|
+
copySource: "MMD: copy diagram source",
|
|
43
|
+
downloadSvg: "SVG: download",
|
|
44
|
+
downloadPng: "PNG: download",
|
|
45
|
+
copyImage: "IMG: copy as image",
|
|
46
46
|
pngScale: "PNG scale",
|
|
47
47
|
fullscreen: "Fullscreen",
|
|
48
48
|
exitFullscreen: "Exit fullscreen",
|
|
@@ -55,7 +55,16 @@ var init_labels = __esm({
|
|
|
55
55
|
legendDownstream: "Downstream",
|
|
56
56
|
outgoing: "outgoing",
|
|
57
57
|
tracing: "{label}: {up} upstream, {down} downstream",
|
|
58
|
-
map: "Overview map"
|
|
58
|
+
map: "Overview map",
|
|
59
|
+
largeTitle: "Large diagram, not drawn automatically",
|
|
60
|
+
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.",
|
|
61
|
+
drawLarge: "Draw diagram",
|
|
62
|
+
drawing: "Drawing\u2026",
|
|
63
|
+
drawingBody: "Drawing the diagram\u2026 this takes a couple of seconds.",
|
|
64
|
+
drawAgain: "Draw again",
|
|
65
|
+
showSource: "Show full source",
|
|
66
|
+
hideSource: "Show less",
|
|
67
|
+
printPreparing: "Preparing diagrams for print\u2026 Esc cancels between steps."
|
|
59
68
|
};
|
|
60
69
|
fill = (template, values) => template.replace(/\{(\w+)\}/g, (m, k) => k in values ? String(values[k]) : m);
|
|
61
70
|
}
|
|
@@ -116,7 +125,10 @@ function nearest(nodes, x, y) {
|
|
|
116
125
|
let d = GEOMETRY_SLACK;
|
|
117
126
|
for (const n of nodes) {
|
|
118
127
|
const nd = dist(n.box, x, y);
|
|
119
|
-
if (nd < d)
|
|
128
|
+
if (nd < d) {
|
|
129
|
+
d = nd;
|
|
130
|
+
best = n.key;
|
|
131
|
+
}
|
|
120
132
|
}
|
|
121
133
|
return best;
|
|
122
134
|
}
|
|
@@ -219,7 +231,10 @@ function walk(g, start, next, far) {
|
|
|
219
231
|
edges.add(i);
|
|
220
232
|
const other = far(g.edges[i]);
|
|
221
233
|
nodes.add(other);
|
|
222
|
-
if (!seen.has(other))
|
|
234
|
+
if (!seen.has(other)) {
|
|
235
|
+
seen.add(other);
|
|
236
|
+
queue.push(other);
|
|
237
|
+
}
|
|
223
238
|
}
|
|
224
239
|
}
|
|
225
240
|
return { nodes, edges };
|
|
@@ -232,7 +247,10 @@ function trace(g, key) {
|
|
|
232
247
|
function neighbourhood(g, key) {
|
|
233
248
|
const edges = /* @__PURE__ */ new Set([...g.out.get(key) ?? [], ...g.inn.get(key) ?? []]);
|
|
234
249
|
const nodes = /* @__PURE__ */ new Set([key]);
|
|
235
|
-
for (const i of edges)
|
|
250
|
+
for (const i of edges) {
|
|
251
|
+
nodes.add(g.edges[i].from);
|
|
252
|
+
nodes.add(g.edges[i].to);
|
|
253
|
+
}
|
|
236
254
|
return { nodes, edges };
|
|
237
255
|
}
|
|
238
256
|
function pickNeighbour(g, key, dir) {
|
|
@@ -251,12 +269,18 @@ function pickNeighbour(g, key, dir) {
|
|
|
251
269
|
const across = Math.abs((x - cx) * vy - (y - cy) * vx);
|
|
252
270
|
if (along <= 0 || across > along * cone) continue;
|
|
253
271
|
const c = along + across * 2;
|
|
254
|
-
if (c < cost)
|
|
272
|
+
if (c < cost) {
|
|
273
|
+
cost = c;
|
|
274
|
+
pick = k;
|
|
275
|
+
}
|
|
255
276
|
}
|
|
256
277
|
return pick;
|
|
257
278
|
};
|
|
258
279
|
const adjacent = /* @__PURE__ */ new Set();
|
|
259
|
-
for (const i of [...g.out.get(key) ?? [], ...g.inn.get(key) ?? []])
|
|
280
|
+
for (const i of [...g.out.get(key) ?? [], ...g.inn.get(key) ?? []]) {
|
|
281
|
+
adjacent.add(g.edges[i].from);
|
|
282
|
+
adjacent.add(g.edges[i].to);
|
|
283
|
+
}
|
|
260
284
|
return best(adjacent, CONE) ?? best(adjacent, Infinity) ?? best(g.byKey.keys(), CONE);
|
|
261
285
|
}
|
|
262
286
|
function searchNodes(nodes, query) {
|
|
@@ -292,18 +316,25 @@ var init_graph = __esm({
|
|
|
292
316
|
// src/react/viewer/scope-svg.ts
|
|
293
317
|
function scopeSvg(svg, oldId, newId) {
|
|
294
318
|
if (!/^[\w-]+$/.test(oldId) || !/^[\w-]+$/.test(newId)) throw new Error("unsafe svg id");
|
|
319
|
+
const own = `${oldId}-`;
|
|
295
320
|
const token = new RegExp(`(?<![\\w-])${escapeRe(oldId)}(?![A-Za-z0-9-])`, "g");
|
|
296
321
|
const rooted = svg.replace(SEGMENT, (segment) => segment.replace(token, newId));
|
|
297
|
-
const
|
|
322
|
+
const ids = /* @__PURE__ */ new Set();
|
|
298
323
|
for (const segment of rooted.match(SEGMENT) ?? []) {
|
|
299
324
|
if (!isTag(segment)) continue;
|
|
300
|
-
for (const m of segment.matchAll(/\sid="([^"]*)"/g))
|
|
325
|
+
for (const m of segment.matchAll(/\sid="([^"]*)"/g)) ids.add(m[1]);
|
|
301
326
|
}
|
|
327
|
+
const stripped = (id) => id.startsWith(own) ? id.slice(own.length) : id;
|
|
328
|
+
const target = (id) => `${newId}_${stripped(id)}`;
|
|
329
|
+
const plain = [...ids].filter((id) => !id.startsWith(`${newId}_`) && id !== newId);
|
|
330
|
+
const claims = /* @__PURE__ */ new Map();
|
|
331
|
+
for (const id of plain) claims.set(target(id), (claims.get(target(id)) ?? 0) + 1);
|
|
332
|
+
const fresh = new Map(plain.map((id) => [id, ids.has(target(id)) || claims.get(target(id)) > 1 ? `${newId}_${id}` : target(id)]));
|
|
302
333
|
if (!fresh.size) return rooted;
|
|
303
334
|
const to = (id) => fresh.get(id) ?? id;
|
|
304
335
|
return rooted.replace(
|
|
305
336
|
SEGMENT,
|
|
306
|
-
(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,
|
|
337
|
+
(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(" ")}"`)
|
|
307
338
|
);
|
|
308
339
|
}
|
|
309
340
|
function svgSize(svg) {
|
|
@@ -593,7 +624,10 @@ var init_controller = __esm({
|
|
|
593
624
|
n.el.setAttribute("aria-pressed", "false");
|
|
594
625
|
});
|
|
595
626
|
if (this.nodes[0]) this.roving = this.nodes[0].el;
|
|
596
|
-
for (const e of this.edges)
|
|
627
|
+
for (const e of this.edges) {
|
|
628
|
+
e.el.classList.add("hv-e");
|
|
629
|
+
e.labelEl?.classList.add("hv-e");
|
|
630
|
+
}
|
|
597
631
|
this.o.stage.classList.toggle("hv-plain", this.nodes.length > FADE_MAX_NODES);
|
|
598
632
|
}
|
|
599
633
|
// ---- view ---------------------------------------------------------------------------------------------------------------------------
|
|
@@ -852,13 +886,22 @@ var init_controller = __esm({
|
|
|
852
886
|
for (const k of t.down) mark(at(k)?.el, "hv-down");
|
|
853
887
|
mark(at(this.pinned)?.el, "hv-sel");
|
|
854
888
|
const flow = t.upEdges.size + t.downEdges.size <= FLOW_MAX_EDGES ? ["hv-flow"] : [];
|
|
855
|
-
for (const i of t.upEdges)
|
|
856
|
-
|
|
889
|
+
for (const i of t.upEdges) {
|
|
890
|
+
mark(this.edges[i]?.el, "hv-up", ...flow);
|
|
891
|
+
mark(this.edges[i]?.labelEl, "hv-up");
|
|
892
|
+
}
|
|
893
|
+
for (const i of t.downEdges) {
|
|
894
|
+
mark(this.edges[i]?.el, "hv-down", ...flow);
|
|
895
|
+
mark(this.edges[i]?.labelEl, "hv-down");
|
|
896
|
+
}
|
|
857
897
|
} else if (g && this.hot) {
|
|
858
898
|
active = true;
|
|
859
899
|
const n = neighbourhood(g, this.hot);
|
|
860
900
|
for (const k of n.nodes) mark(at(k)?.el, k === this.hot ? "hv-sel" : "hv-nb");
|
|
861
|
-
for (const i of n.edges)
|
|
901
|
+
for (const i of n.edges) {
|
|
902
|
+
mark(this.edges[i]?.el, "hv-nb");
|
|
903
|
+
mark(this.edges[i]?.labelEl, "hv-nb");
|
|
904
|
+
}
|
|
862
905
|
} else if (this.query && this.hitEls.length) {
|
|
863
906
|
active = true;
|
|
864
907
|
for (const el of this.hitEls) mark(el);
|
|
@@ -1085,8 +1128,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1085
1128
|
const finder = (0, import_react.useRef)(null);
|
|
1086
1129
|
const ctl = (0, import_react.useRef)(null);
|
|
1087
1130
|
const labelsRef = (0, import_react.useRef)(labels);
|
|
1088
|
-
|
|
1089
|
-
const ownId = (0, import_react.useRef)(`hyle-viewer-${++sequence}`);
|
|
1131
|
+
const [ownId] = (0, import_react.useState)(() => `hyleViewer-${++sequence}`);
|
|
1090
1132
|
const helpId = (0, import_react.useId)();
|
|
1091
1133
|
const toastTimer = (0, import_react.useRef)(void 0);
|
|
1092
1134
|
const downOnBackdrop = (0, import_react.useRef)(false);
|
|
@@ -1096,12 +1138,15 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1096
1138
|
const [query, setQuery] = (0, import_react.useState)("");
|
|
1097
1139
|
const [scale, setScale] = (0, import_react.useState)("2");
|
|
1098
1140
|
const [fullscreen, setFullscreen] = (0, import_react.useState)(false);
|
|
1099
|
-
const scoped = (0, import_react.useMemo)(() => scopeSvg(svg, svgId, ownId
|
|
1141
|
+
const scoped = (0, import_react.useMemo)(() => scopeSvg(svg, svgId, ownId), [svg, svgId, ownId]);
|
|
1100
1142
|
const say = (message) => {
|
|
1101
1143
|
clearTimeout(toastTimer.current);
|
|
1102
1144
|
setToast(message);
|
|
1103
1145
|
toastTimer.current = setTimeout(() => setToast(""), TOAST_MS);
|
|
1104
1146
|
};
|
|
1147
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
1148
|
+
labelsRef.current = labels;
|
|
1149
|
+
}, [labels]);
|
|
1105
1150
|
(0, import_react.useLayoutEffect)(() => {
|
|
1106
1151
|
const c = new DiagramController({
|
|
1107
1152
|
viewport: viewport.current,
|
|
@@ -1118,18 +1163,22 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1118
1163
|
ctl.current = null;
|
|
1119
1164
|
};
|
|
1120
1165
|
}, []);
|
|
1121
|
-
(0, import_react.useLayoutEffect)(() => ctl.current?.show(scoped, `${ownId
|
|
1166
|
+
(0, import_react.useLayoutEffect)(() => ctl.current?.show(scoped, `${ownId}_`), [scoped, ownId]);
|
|
1122
1167
|
(0, import_react.useEffect)(() => {
|
|
1123
1168
|
const d = dialog.current;
|
|
1124
1169
|
if (!d.open) d.showModal();
|
|
1125
1170
|
if (locks++ === 0) document.documentElement.classList.add(LOCK_CLASS);
|
|
1126
1171
|
viewport.current?.focus({ preventScroll: true });
|
|
1127
|
-
const sync = () =>
|
|
1172
|
+
const sync = () => {
|
|
1173
|
+
const full = document.fullscreenElement === shell.current;
|
|
1174
|
+
setFullscreen(full);
|
|
1175
|
+
document.documentElement.classList.toggle(FULLSCREEN_CLASS, full);
|
|
1176
|
+
};
|
|
1128
1177
|
document.addEventListener("fullscreenchange", sync);
|
|
1129
1178
|
return () => {
|
|
1130
1179
|
document.removeEventListener("fullscreenchange", sync);
|
|
1131
1180
|
clearTimeout(toastTimer.current);
|
|
1132
|
-
if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS);
|
|
1181
|
+
if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS, FULLSCREEN_CLASS);
|
|
1133
1182
|
if (document.fullscreenElement && d.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
|
|
1134
1183
|
});
|
|
1135
1184
|
};
|
|
@@ -1236,13 +1285,13 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
|
|
|
1236
1285
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "hv-down", children: labels.legendDownstream })
|
|
1237
1286
|
] }) : null,
|
|
1238
1287
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "hv-hint", id: helpId, children: labels.hint }),
|
|
1239
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("output", { className: "hv-toast",
|
|
1288
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("output", { className: "hv-toast", children: toast })
|
|
1240
1289
|
] })
|
|
1241
1290
|
] })
|
|
1242
1291
|
}
|
|
1243
1292
|
);
|
|
1244
1293
|
}
|
|
1245
|
-
var import_react, import_jsx_runtime, sequence, locks, LOCK_CLASS, SCALES, TOAST_MS, Glyph, ICONS;
|
|
1294
|
+
var import_react, import_jsx_runtime, sequence, locks, LOCK_CLASS, FULLSCREEN_CLASS, SCALES, TOAST_MS, Glyph, ICONS;
|
|
1246
1295
|
var init_diagram_viewer = __esm({
|
|
1247
1296
|
"src/react/viewer/diagram-viewer.tsx"() {
|
|
1248
1297
|
"use strict";
|
|
@@ -1255,6 +1304,7 @@ var init_diagram_viewer = __esm({
|
|
|
1255
1304
|
sequence = 0;
|
|
1256
1305
|
locks = 0;
|
|
1257
1306
|
LOCK_CLASS = "hyle-viewer-lock";
|
|
1307
|
+
FULLSCREEN_CLASS = "hyle-viewer-fs";
|
|
1258
1308
|
SCALES = ["1", "2", "4"];
|
|
1259
1309
|
TOAST_MS = 4e3;
|
|
1260
1310
|
Glyph = ({ d }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "hv-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d }) });
|
|
@@ -1262,7 +1312,7 @@ var init_diagram_viewer = __esm({
|
|
|
1262
1312
|
close: "m4 4 8 8M12 4l-8 8",
|
|
1263
1313
|
fit: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",
|
|
1264
1314
|
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",
|
|
1265
|
-
full: "
|
|
1315
|
+
full: "M9.5 2.5h4v4M13.5 2.5 9 7M6.5 13.5h-4v-4M2.5 13.5 7 9",
|
|
1266
1316
|
exit: "M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"
|
|
1267
1317
|
};
|
|
1268
1318
|
}
|
|
@@ -1279,18 +1329,44 @@ var import_react2 = require("react");
|
|
|
1279
1329
|
|
|
1280
1330
|
// src/react/mermaid-config.ts
|
|
1281
1331
|
var MAX_MERMAID_SOURCE = 1024 * 1024;
|
|
1282
|
-
|
|
1283
|
-
|
|
1332
|
+
var COLOR = /^(rgba?|oklab|oklch|lab|lch)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/;
|
|
1333
|
+
function isDark(css) {
|
|
1334
|
+
const m = COLOR.exec(css.trim());
|
|
1284
1335
|
if (!m) return void 0;
|
|
1285
|
-
const
|
|
1286
|
-
const
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
|
|
1336
|
+
const kind = m[1] ?? "color";
|
|
1337
|
+
const parts = (m[2] ?? m[3] ?? "").split(/[\s,/]+/).filter(Boolean);
|
|
1338
|
+
const [a, b, c] = parts.map((v) => v === "none" ? 0 : Number.parseFloat(v));
|
|
1339
|
+
const alpha = parts[3] === void 0 ? 1 : Number.parseFloat(parts[3]) / (parts[3].endsWith("%") ? 100 : 1);
|
|
1340
|
+
if (a === void 0 || b === void 0 || c === void 0 || [a, b, c, alpha].some(Number.isNaN) || alpha < 0.5) return void 0;
|
|
1341
|
+
if (kind.startsWith("ok")) return (parts[0]?.endsWith("%") ? a / 100 : a) < 0.6;
|
|
1342
|
+
if (kind.startsWith("l")) return a < 53;
|
|
1343
|
+
const scale = kind === "color" ? 1 : 255;
|
|
1344
|
+
return (0.2126 * a + 0.7152 * b + 0.0722 * c) / scale < 0.5;
|
|
1345
|
+
}
|
|
1346
|
+
function pickMermaidTheme(background, prefersDark, colorScheme = "") {
|
|
1347
|
+
const declared = /\bdark\b/.test(colorScheme) === /\blight\b/.test(colorScheme) ? void 0 : /\bdark\b/.test(colorScheme);
|
|
1348
|
+
return isDark(background) ?? declared ?? prefersDark ? "dark" : "default";
|
|
1349
|
+
}
|
|
1350
|
+
function watchPageTheme(el, onTheme) {
|
|
1351
|
+
const scheme = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1352
|
+
const update = () => {
|
|
1353
|
+
const style = getComputedStyle(el);
|
|
1354
|
+
onTheme(pickMermaidTheme(style.backgroundColor, scheme.matches, style.colorScheme));
|
|
1355
|
+
};
|
|
1356
|
+
update();
|
|
1357
|
+
const observer = new MutationObserver(update);
|
|
1358
|
+
observer.observe(document.documentElement, { attributes: true });
|
|
1359
|
+
observer.observe(document.body, { attributes: true });
|
|
1360
|
+
scheme.addEventListener("change", update);
|
|
1361
|
+
return () => {
|
|
1362
|
+
observer.disconnect();
|
|
1363
|
+
scheme.removeEventListener("change", update);
|
|
1364
|
+
};
|
|
1290
1365
|
}
|
|
1291
|
-
function
|
|
1292
|
-
|
|
1293
|
-
|
|
1366
|
+
function afterFullscreen(within, then) {
|
|
1367
|
+
if (document.fullscreenElement && within?.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
|
|
1368
|
+
}).then(then);
|
|
1369
|
+
else then();
|
|
1294
1370
|
}
|
|
1295
1371
|
|
|
1296
1372
|
// src/react/mermaid-image.tsx
|
|
@@ -1304,7 +1380,7 @@ function isSafeStoredSvg(svg) {
|
|
|
1304
1380
|
for (const m of svg.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>|\s[\w:-]+="([^"]*)"/g)) if (BAD_CSS.test(m[1] ?? m[2] ?? "")) return false;
|
|
1305
1381
|
return true;
|
|
1306
1382
|
}
|
|
1307
|
-
function
|
|
1383
|
+
function StoredDiagram({ source, title, errorText, loadingText, sourceLabel, light, dark, labels = VIEWER_LABELS_EN }) {
|
|
1308
1384
|
const figure = (0, import_react2.useRef)(null);
|
|
1309
1385
|
const img = (0, import_react2.useRef)(null);
|
|
1310
1386
|
const trigger = (0, import_react2.useRef)(null);
|
|
@@ -1312,19 +1388,9 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
|
|
|
1312
1388
|
const [pending, setPending] = (0, import_react2.useState)(false);
|
|
1313
1389
|
const [failed, setFailed] = (0, import_react2.useState)(false);
|
|
1314
1390
|
const [view, setView] = (0, import_react2.useState)(null);
|
|
1391
|
+
const [viewerFailed, setViewerFailed] = (0, import_react2.useState)(false);
|
|
1315
1392
|
const [Viewer, setViewer] = (0, import_react2.useState)(null);
|
|
1316
|
-
(0, import_react2.useEffect)(() =>
|
|
1317
|
-
const scheme = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1318
|
-
const update = () => figure.current && setTheme(pickMermaidTheme(getComputedStyle(figure.current).backgroundColor, scheme.matches));
|
|
1319
|
-
update();
|
|
1320
|
-
const observer = new MutationObserver(update);
|
|
1321
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-act", "data-theme", "class"] });
|
|
1322
|
-
scheme.addEventListener("change", update);
|
|
1323
|
-
return () => {
|
|
1324
|
-
observer.disconnect();
|
|
1325
|
-
scheme.removeEventListener("change", update);
|
|
1326
|
-
};
|
|
1327
|
-
}, []);
|
|
1393
|
+
(0, import_react2.useEffect)(() => figure.current ? watchPageTheme(figure.current, setTheme) : void 0, []);
|
|
1328
1394
|
(0, import_react2.useEffect)(() => {
|
|
1329
1395
|
const el = img.current;
|
|
1330
1396
|
if (!el?.complete) setPending(true);
|
|
@@ -1334,26 +1400,30 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
|
|
|
1334
1400
|
const active = theme === "dark" ? dark : light;
|
|
1335
1401
|
const expand = async (e) => {
|
|
1336
1402
|
if (e.target.closest("a")) return;
|
|
1403
|
+
setViewerFailed(false);
|
|
1337
1404
|
try {
|
|
1338
1405
|
const response = await fetch(active.src);
|
|
1339
1406
|
const svg = response.ok ? await response.text() : "";
|
|
1340
1407
|
const id = /^\s*<svg\b[^>]*?\sid="([\w-]+)"/.exec(svg)?.[1];
|
|
1341
|
-
if (!id || !isSafeStoredSvg(svg)) return;
|
|
1408
|
+
if (!id || !isSafeStoredSvg(svg)) return setViewerFailed(true);
|
|
1342
1409
|
const { DiagramViewer: DiagramViewer2 } = await Promise.resolve().then(() => (init_diagram_viewer(), diagram_viewer_exports));
|
|
1343
1410
|
setViewer(() => DiagramViewer2);
|
|
1344
1411
|
setView({ svg, id });
|
|
1345
1412
|
} catch {
|
|
1413
|
+
setViewerFailed(true);
|
|
1346
1414
|
}
|
|
1347
1415
|
};
|
|
1348
1416
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", children: [
|
|
1349
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.
|
|
1353
|
-
|
|
1417
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "hyle-mermaid-open", role: "presentation", onClick: expand, children: [
|
|
1418
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hyle-mermaid-frame", style: { aspectRatio: `${active.width} / ${active.height}`, maxWidth: active.width }, children: [
|
|
1419
|
+
pending ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-mermaid-loader", role: "status", "aria-busy": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "sr-only", children: loadingText }) }) : null,
|
|
1420
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("picture", { children: [
|
|
1421
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("source", { srcSet: dark.src, media: theme === null ? "(prefers-color-scheme: dark)" : theme === "dark" ? "all" : "not all" }),
|
|
1422
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { ref: img, src: light.src, alt: title, width: light.width, height: light.height, decoding: "async", loading: "lazy", onLoad: () => setPending(false), onError: () => setFailed(true) })
|
|
1423
|
+
] })
|
|
1354
1424
|
] }),
|
|
1355
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("
|
|
1356
|
-
] })
|
|
1425
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { ref: trigger, type: "button", className: "hyle-mermaid-hint", "aria-label": labels.expand, "aria-haspopup": "dialog", children: labels.expandHint })
|
|
1426
|
+
] }),
|
|
1357
1427
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("details", { className: "hyle-mermaid-source", children: [
|
|
1358
1428
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("summary", { children: sourceLabel }),
|
|
1359
1429
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { className: "language-mermaid", children: source }) })
|
|
@@ -1366,15 +1436,19 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
|
|
|
1366
1436
|
source,
|
|
1367
1437
|
title,
|
|
1368
1438
|
labels,
|
|
1369
|
-
onClose: () => {
|
|
1439
|
+
onClose: () => afterFullscreen(figure.current, () => {
|
|
1370
1440
|
setView(null);
|
|
1371
1441
|
trigger.current?.focus({ preventScroll: true });
|
|
1372
|
-
}
|
|
1442
|
+
})
|
|
1373
1443
|
}
|
|
1374
1444
|
) : null,
|
|
1445
|
+
viewerFailed ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: labels.unavailable }) : null,
|
|
1375
1446
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("figcaption", { className: "sr-only", children: title })
|
|
1376
1447
|
] });
|
|
1377
1448
|
}
|
|
1449
|
+
function MermaidImage(props) {
|
|
1450
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mermaid_diagram.DiagramBoundary, { source: props.source, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StoredDiagram, { ...props }) });
|
|
1451
|
+
}
|
|
1378
1452
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1379
1453
|
0 && (module.exports = {
|
|
1380
1454
|
MermaidImage,
|
package/dist/mermaid-image.d.cts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { V as ViewerLabels } from './labels-
|
|
2
|
+
import { V as ViewerLabels } from './labels-CrA-iqTN.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A diagram hyle already rendered (in the author's browser, sanitized and stored, ADR 0024): the reader gets a sized `<img>` and
|
|
6
6
|
* no layout runs in any browser. The source stays in the markup inside `<details>`, so crawlers and no-JS readers have it. Like
|
|
7
7
|
* MermaidDiagram it receives presentational values only, never a token or client; the SVG it fetches on click comes from the
|
|
8
|
-
* host's own same-origin asset route. If the image fails to load it falls back to MermaidDiagram
|
|
8
|
+
* host's own same-origin asset route. If the image fails to load it falls back to MermaidDiagram, which asks before drawing a large
|
|
9
|
+
* diagram; the stored image itself needs no such gate, since showing it runs no layout.
|
|
9
10
|
*/
|
|
10
11
|
interface StoredRender {
|
|
11
12
|
src: string;
|
|
@@ -24,6 +25,6 @@ interface MermaidImageProps {
|
|
|
24
25
|
}
|
|
25
26
|
/** True when a fetched stored SVG still looks like what the server stores; the viewer inlines only those. */
|
|
26
27
|
declare function isSafeStoredSvg(svg: string): boolean;
|
|
27
|
-
declare function MermaidImage(
|
|
28
|
+
declare function MermaidImage(props: MermaidImageProps): react.JSX.Element;
|
|
28
29
|
|
|
29
30
|
export { MermaidImage, type MermaidImageProps, type StoredRender, isSafeStoredSvg };
|
package/dist/mermaid-image.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { V as ViewerLabels } from './labels-
|
|
2
|
+
import { V as ViewerLabels } from './labels-CrA-iqTN.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A diagram hyle already rendered (in the author's browser, sanitized and stored, ADR 0024): the reader gets a sized `<img>` and
|
|
6
6
|
* no layout runs in any browser. The source stays in the markup inside `<details>`, so crawlers and no-JS readers have it. Like
|
|
7
7
|
* MermaidDiagram it receives presentational values only, never a token or client; the SVG it fetches on click comes from the
|
|
8
|
-
* host's own same-origin asset route. If the image fails to load it falls back to MermaidDiagram
|
|
8
|
+
* host's own same-origin asset route. If the image fails to load it falls back to MermaidDiagram, which asks before drawing a large
|
|
9
|
+
* diagram; the stored image itself needs no such gate, since showing it runs no layout.
|
|
9
10
|
*/
|
|
10
11
|
interface StoredRender {
|
|
11
12
|
src: string;
|
|
@@ -24,6 +25,6 @@ interface MermaidImageProps {
|
|
|
24
25
|
}
|
|
25
26
|
/** True when a fetched stored SVG still looks like what the server stores; the viewer inlines only those. */
|
|
26
27
|
declare function isSafeStoredSvg(svg: string): boolean;
|
|
27
|
-
declare function MermaidImage(
|
|
28
|
+
declare function MermaidImage(props: MermaidImageProps): react.JSX.Element;
|
|
28
29
|
|
|
29
30
|
export { MermaidImage, type MermaidImageProps, type StoredRender, isSafeStoredSvg };
|
package/dist/mermaid-image.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
afterFullscreen,
|
|
4
|
+
watchPageTheme
|
|
5
|
+
} from "./chunk-K5VDLROQ.js";
|
|
5
6
|
import {
|
|
6
7
|
VIEWER_LABELS_EN
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-QVYQM5R2.js";
|
|
8
9
|
|
|
9
10
|
// src/react/mermaid-image.tsx
|
|
10
11
|
import { useEffect, useRef, useState } from "react";
|
|
11
|
-
import { MermaidDiagram } from "./mermaid-diagram.js";
|
|
12
|
+
import { DiagramBoundary, MermaidDiagram } from "./mermaid-diagram.js";
|
|
12
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
14
|
var FORBIDDEN_IN_SVG = /<script|<foreignObject|\son\w+\s*=|javascript:/i;
|
|
14
15
|
var BAD_CSS = /\\|@(?!keyframes\b)|expression|-moz-binding|behavior|-webkit-image-set|(?:src|image|image-set|cross-fade|element|paint)\(|url\((?!\s*['"]?\s*#)/i;
|
|
@@ -17,7 +18,7 @@ function isSafeStoredSvg(svg) {
|
|
|
17
18
|
for (const m of svg.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>|\s[\w:-]+="([^"]*)"/g)) if (BAD_CSS.test(m[1] ?? m[2] ?? "")) return false;
|
|
18
19
|
return true;
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
+
function StoredDiagram({ source, title, errorText, loadingText, sourceLabel, light, dark, labels = VIEWER_LABELS_EN }) {
|
|
21
22
|
const figure = useRef(null);
|
|
22
23
|
const img = useRef(null);
|
|
23
24
|
const trigger = useRef(null);
|
|
@@ -25,19 +26,9 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
|
|
|
25
26
|
const [pending, setPending] = useState(false);
|
|
26
27
|
const [failed, setFailed] = useState(false);
|
|
27
28
|
const [view, setView] = useState(null);
|
|
29
|
+
const [viewerFailed, setViewerFailed] = useState(false);
|
|
28
30
|
const [Viewer, setViewer] = useState(null);
|
|
29
|
-
useEffect(() =>
|
|
30
|
-
const scheme = window.matchMedia("(prefers-color-scheme: dark)");
|
|
31
|
-
const update = () => figure.current && setTheme(pickMermaidTheme(getComputedStyle(figure.current).backgroundColor, scheme.matches));
|
|
32
|
-
update();
|
|
33
|
-
const observer = new MutationObserver(update);
|
|
34
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-act", "data-theme", "class"] });
|
|
35
|
-
scheme.addEventListener("change", update);
|
|
36
|
-
return () => {
|
|
37
|
-
observer.disconnect();
|
|
38
|
-
scheme.removeEventListener("change", update);
|
|
39
|
-
};
|
|
40
|
-
}, []);
|
|
31
|
+
useEffect(() => figure.current ? watchPageTheme(figure.current, setTheme) : void 0, []);
|
|
41
32
|
useEffect(() => {
|
|
42
33
|
const el = img.current;
|
|
43
34
|
if (!el?.complete) setPending(true);
|
|
@@ -47,26 +38,30 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
|
|
|
47
38
|
const active = theme === "dark" ? dark : light;
|
|
48
39
|
const expand = async (e) => {
|
|
49
40
|
if (e.target.closest("a")) return;
|
|
41
|
+
setViewerFailed(false);
|
|
50
42
|
try {
|
|
51
43
|
const response = await fetch(active.src);
|
|
52
44
|
const svg = response.ok ? await response.text() : "";
|
|
53
45
|
const id = /^\s*<svg\b[^>]*?\sid="([\w-]+)"/.exec(svg)?.[1];
|
|
54
|
-
if (!id || !isSafeStoredSvg(svg)) return;
|
|
55
|
-
const { DiagramViewer } = await import("./diagram-viewer-
|
|
46
|
+
if (!id || !isSafeStoredSvg(svg)) return setViewerFailed(true);
|
|
47
|
+
const { DiagramViewer } = await import("./diagram-viewer-XY3CG75U.js");
|
|
56
48
|
setViewer(() => DiagramViewer);
|
|
57
49
|
setView({ svg, id });
|
|
58
50
|
} catch {
|
|
51
|
+
setViewerFailed(true);
|
|
59
52
|
}
|
|
60
53
|
};
|
|
61
54
|
return /* @__PURE__ */ jsxs("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", children: [
|
|
62
|
-
/* @__PURE__ */
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/* @__PURE__ */
|
|
66
|
-
|
|
55
|
+
/* @__PURE__ */ jsxs("div", { className: "hyle-mermaid-open", role: "presentation", onClick: expand, children: [
|
|
56
|
+
/* @__PURE__ */ jsxs("span", { className: "hyle-mermaid-frame", style: { aspectRatio: `${active.width} / ${active.height}`, maxWidth: active.width }, children: [
|
|
57
|
+
pending ? /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-loader", role: "status", "aria-busy": "true", children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: loadingText }) }) : null,
|
|
58
|
+
/* @__PURE__ */ jsxs("picture", { children: [
|
|
59
|
+
/* @__PURE__ */ jsx("source", { srcSet: dark.src, media: theme === null ? "(prefers-color-scheme: dark)" : theme === "dark" ? "all" : "not all" }),
|
|
60
|
+
/* @__PURE__ */ jsx("img", { ref: img, src: light.src, alt: title, width: light.width, height: light.height, decoding: "async", loading: "lazy", onLoad: () => setPending(false), onError: () => setFailed(true) })
|
|
61
|
+
] })
|
|
67
62
|
] }),
|
|
68
|
-
/* @__PURE__ */ jsx("
|
|
69
|
-
] })
|
|
63
|
+
/* @__PURE__ */ jsx("button", { ref: trigger, type: "button", className: "hyle-mermaid-hint", "aria-label": labels.expand, "aria-haspopup": "dialog", children: labels.expandHint })
|
|
64
|
+
] }),
|
|
70
65
|
/* @__PURE__ */ jsxs("details", { className: "hyle-mermaid-source", children: [
|
|
71
66
|
/* @__PURE__ */ jsx("summary", { children: sourceLabel }),
|
|
72
67
|
/* @__PURE__ */ jsx("pre", { tabIndex: 0, children: /* @__PURE__ */ jsx("code", { className: "language-mermaid", children: source }) })
|
|
@@ -79,15 +74,19 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
|
|
|
79
74
|
source,
|
|
80
75
|
title,
|
|
81
76
|
labels,
|
|
82
|
-
onClose: () => {
|
|
77
|
+
onClose: () => afterFullscreen(figure.current, () => {
|
|
83
78
|
setView(null);
|
|
84
79
|
trigger.current?.focus({ preventScroll: true });
|
|
85
|
-
}
|
|
80
|
+
})
|
|
86
81
|
}
|
|
87
82
|
) : null,
|
|
83
|
+
viewerFailed ? /* @__PURE__ */ jsx("p", { className: "hyle-mermaid-note", role: "status", children: labels.unavailable }) : null,
|
|
88
84
|
/* @__PURE__ */ jsx("figcaption", { className: "sr-only", children: title })
|
|
89
85
|
] });
|
|
90
86
|
}
|
|
87
|
+
function MermaidImage(props) {
|
|
88
|
+
return /* @__PURE__ */ jsx(DiagramBoundary, { source: props.source, children: /* @__PURE__ */ jsx(StoredDiagram, { ...props }) });
|
|
89
|
+
}
|
|
91
90
|
export {
|
|
92
91
|
MermaidImage,
|
|
93
92
|
isSafeStoredSvg
|