@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.
Files changed (92) hide show
  1. package/README.md +261 -42
  2. package/dist/check-routes-bin.js +190 -53
  3. package/dist/{chunk-6VOHFFA5.js → chunk-7T5EEJHK.js} +2 -2
  4. package/dist/chunk-DUPT6XLB.js +57 -0
  5. package/dist/chunk-IW3TUD4G.js +841 -0
  6. package/dist/{chunk-MGSUQBDW.js → chunk-KU7LWK4E.js} +249 -24
  7. package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
  8. package/dist/chunk-SFFBZFEN.js +178 -0
  9. package/dist/chunk-U74B7AUG.js +398 -0
  10. package/dist/chunk-ZIW6FDU2.js +1126 -0
  11. package/dist/client-BGjmEWhN.d.cts +207 -0
  12. package/dist/client-D0LTpr3Y.d.ts +207 -0
  13. package/dist/code-copy.cjs +74 -0
  14. package/dist/code-copy.d.cts +18 -0
  15. package/dist/code-copy.d.ts +18 -0
  16. package/dist/code-copy.js +50 -0
  17. package/dist/comments.cjs +738 -280
  18. package/dist/comments.d.cts +66 -3
  19. package/dist/comments.d.ts +66 -3
  20. package/dist/comments.js +419 -331
  21. package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
  22. package/dist/docs-enhance.cjs +7 -4
  23. package/dist/docs-enhance.d.cts +5 -3
  24. package/dist/docs-enhance.d.ts +5 -3
  25. package/dist/docs-enhance.js +8 -5
  26. package/dist/{embed-DNTZ2UXv.d.ts → embed-CbtsbZs3.d.cts} +5 -3
  27. package/dist/{embed-BmdwA2G9.d.cts → embed-Cf_2ZR5x.d.ts} +5 -3
  28. package/dist/fragment-alias.cjs +51 -0
  29. package/dist/fragment-alias.d.cts +7 -0
  30. package/dist/fragment-alias.d.ts +7 -0
  31. package/dist/fragment-alias.js +27 -0
  32. package/dist/html.cjs +886 -0
  33. package/dist/html.d.cts +20 -0
  34. package/dist/html.d.ts +20 -0
  35. package/dist/html.js +45 -0
  36. package/dist/index.cjs +244 -24
  37. package/dist/index.d.cts +22 -68
  38. package/dist/index.d.ts +22 -68
  39. package/dist/index.js +12 -2
  40. package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.cts} +9 -0
  41. package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.ts} +9 -0
  42. package/dist/mermaid-diagram.cjs +441 -125
  43. package/dist/mermaid-diagram.d.cts +23 -7
  44. package/dist/mermaid-diagram.d.ts +23 -7
  45. package/dist/mermaid-diagram.js +213 -51
  46. package/dist/mermaid-image.cjs +137 -60
  47. package/dist/mermaid-image.d.cts +4 -3
  48. package/dist/mermaid-image.d.ts +4 -3
  49. package/dist/mermaid-image.js +27 -28
  50. package/dist/next.cjs +836 -304
  51. package/dist/next.d.cts +45 -20
  52. package/dist/next.d.ts +45 -20
  53. package/dist/next.js +151 -40
  54. package/dist/print-coordinator.cjs +157 -0
  55. package/dist/print-coordinator.d.cts +27 -0
  56. package/dist/print-coordinator.d.ts +27 -0
  57. package/dist/print-coordinator.js +83 -0
  58. package/dist/react.cjs +603 -240
  59. package/dist/react.d.cts +148 -30
  60. package/dist/react.d.ts +148 -30
  61. package/dist/react.js +26 -4
  62. package/dist/reactions.cjs +653 -0
  63. package/dist/reactions.d.cts +27 -0
  64. package/dist/reactions.d.ts +27 -0
  65. package/dist/reactions.js +364 -0
  66. package/dist/{resolve-euZ4-aC9.d.cts → resolve-BnIv7aB7.d.cts} +2 -2
  67. package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BysHtZ_i.d.ts} +2 -2
  68. package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
  69. package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
  70. package/dist/sanitize-BpY_AdZh.d.cts +23 -0
  71. package/dist/sanitize-BpY_AdZh.d.ts +23 -0
  72. package/dist/styles.css +100 -29
  73. package/dist/toc-spy.cjs +60 -0
  74. package/dist/toc-spy.d.cts +15 -0
  75. package/dist/toc-spy.d.ts +15 -0
  76. package/dist/toc-spy.js +36 -0
  77. package/dist/{types-Czt887Iv.d.cts → types-D09Z072G.d.cts} +57 -2
  78. package/dist/{types-Czt887Iv.d.ts → types-D09Z072G.d.ts} +57 -2
  79. package/dist/use-cache.cjs +89 -13
  80. package/dist/use-cache.d.cts +12 -5
  81. package/dist/use-cache.d.ts +12 -5
  82. package/dist/use-cache.js +8 -8
  83. package/dist/youtube-facade.cjs +50 -0
  84. package/dist/youtube-facade.d.cts +17 -0
  85. package/dist/youtube-facade.d.ts +17 -0
  86. package/dist/youtube-facade.js +26 -0
  87. package/package.json +16 -3
  88. package/dist/chunk-67IOIAVW.js +0 -35
  89. package/dist/chunk-DMK4XQLU.js +0 -1556
  90. package/dist/chunk-PJMJMP66.js +0 -63
  91. package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
  92. package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
@@ -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: "Actual size",
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: "Copy diagram source",
43
- downloadSvg: "Download SVG",
44
- downloadPng: "Download PNG",
45
- copyImage: "Copy as image",
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) d = nd, best = n.key;
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)) seen.add(other), queue.push(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) nodes.add(g.edges[i].from), nodes.add(g.edges[i].to);
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) cost = c, pick = k;
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) ?? []]) adjacent.add(g.edges[i].from), adjacent.add(g.edges[i].to);
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 fresh = /* @__PURE__ */ new Map();
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)) if (!m[1].startsWith(`${newId}_`) && m[1] !== newId) fresh.set(m[1], `${newId}_${m[1]}`);
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, ids) => `${a}${ids.split(/\s+/).map(to).join(" ")}"`)
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) e.el.classList.add("hv-e"), e.labelEl?.classList.add("hv-e");
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) mark(this.edges[i]?.el, "hv-up", ...flow), mark(this.edges[i]?.labelEl, "hv-up");
856
- for (const i of t.downEdges) mark(this.edges[i]?.el, "hv-down", ...flow), mark(this.edges[i]?.labelEl, "hv-down");
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) mark(this.edges[i]?.el, "hv-nb"), mark(this.edges[i]?.labelEl, "hv-nb");
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
- labelsRef.current = labels;
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.current), [svg, svgId]);
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.current}_`), [scoped]);
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 = () => setFullscreen(document.fullscreenElement === shell.current);
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", role: "status", children: 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: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",
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,47 @@ var import_react2 = require("react");
1279
1329
 
1280
1330
  // src/react/mermaid-config.ts
1281
1331
  var MAX_MERMAID_SOURCE = 1024 * 1024;
1282
- function luminance(css) {
1283
- const m = /^(rgba?)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/.exec(css.trim());
1332
+ var DIAGRAM_COLOUR_ROLES = ["bg", "node", "node-text", "node-border", "line", "accent", "muted"];
1333
+ var THEME_COLOUR = /^(?:#[0-9a-f]{6}(?:[0-9a-f]{2})?|transparent)$/;
1334
+ var COLOR = /^(rgba?|oklab|oklch|lab|lch)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/;
1335
+ function isDark(css) {
1336
+ const m = COLOR.exec(css.trim());
1284
1337
  if (!m) return void 0;
1285
- const parts = (m[2] ?? m[3] ?? "").split(/[\s,/]+/).filter(Boolean).map(Number);
1286
- const [r, g, b] = parts.map((v) => m[3] ? v : v / 255);
1287
- const alpha = parts[3] ?? 1;
1288
- if (r === void 0 || g === void 0 || b === void 0 || [r, g, b, alpha].some(Number.isNaN) || alpha < 0.5) return void 0;
1289
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
1338
+ const kind = m[1] ?? "color";
1339
+ const parts = (m[2] ?? m[3] ?? "").split(/[\s,/]+/).filter(Boolean);
1340
+ const [a, b, c] = parts.map((v) => v === "none" ? 0 : Number.parseFloat(v));
1341
+ const alpha = parts[3] === void 0 ? 1 : Number.parseFloat(parts[3]) / (parts[3].endsWith("%") ? 100 : 1);
1342
+ if (a === void 0 || b === void 0 || c === void 0 || [a, b, c, alpha].some(Number.isNaN) || alpha < 0.5) return void 0;
1343
+ if (kind.startsWith("ok")) return (parts[0]?.endsWith("%") ? a / 100 : a) < 0.6;
1344
+ if (kind.startsWith("l")) return a < 53;
1345
+ const scale = kind === "color" ? 1 : 255;
1346
+ return (0.2126 * a + 0.7152 * b + 0.0722 * c) / scale < 0.5;
1347
+ }
1348
+ function pickMermaidTheme(background, prefersDark, colorScheme = "") {
1349
+ const declared = /\bdark\b/.test(colorScheme) === /\blight\b/.test(colorScheme) ? void 0 : /\bdark\b/.test(colorScheme);
1350
+ return isDark(background) ?? declared ?? prefersDark ? "dark" : "default";
1351
+ }
1352
+ function watchPageTheme(el, onTheme) {
1353
+ const scheme = window.matchMedia("(prefers-color-scheme: dark)");
1354
+ const update = () => {
1355
+ const style = getComputedStyle(el);
1356
+ const colours = DIAGRAM_COLOUR_ROLES.map((role) => style.getPropertyValue(`--hyle-diagram-${role}`).trim());
1357
+ onTheme(pickMermaidTheme(style.backgroundColor, scheme.matches, style.colorScheme), colours.every((c) => THEME_COLOUR.test(c)) ? colours.join(" ") : "");
1358
+ };
1359
+ update();
1360
+ const observer = new MutationObserver(update);
1361
+ observer.observe(document.documentElement, { attributes: true });
1362
+ observer.observe(document.body, { attributes: true });
1363
+ scheme.addEventListener("change", update);
1364
+ return () => {
1365
+ observer.disconnect();
1366
+ scheme.removeEventListener("change", update);
1367
+ };
1290
1368
  }
1291
- function pickMermaidTheme(background, prefersDark) {
1292
- const l = luminance(background);
1293
- return (l === void 0 ? prefersDark : l < 0.5) ? "dark" : "default";
1369
+ function afterFullscreen(within, then) {
1370
+ if (document.fullscreenElement && within?.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
1371
+ }).then(then);
1372
+ else then();
1294
1373
  }
1295
1374
 
1296
1375
  // src/react/mermaid-image.tsx
@@ -1304,7 +1383,7 @@ function isSafeStoredSvg(svg) {
1304
1383
  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
1384
  return true;
1306
1385
  }
1307
- function MermaidImage({ source, title, errorText, loadingText, sourceLabel, light, dark, labels = VIEWER_LABELS_EN }) {
1386
+ function StoredDiagram({ source, title, errorText, loadingText, sourceLabel, light, dark, labels = VIEWER_LABELS_EN }) {
1308
1387
  const figure = (0, import_react2.useRef)(null);
1309
1388
  const img = (0, import_react2.useRef)(null);
1310
1389
  const trigger = (0, import_react2.useRef)(null);
@@ -1312,19 +1391,9 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
1312
1391
  const [pending, setPending] = (0, import_react2.useState)(false);
1313
1392
  const [failed, setFailed] = (0, import_react2.useState)(false);
1314
1393
  const [view, setView] = (0, import_react2.useState)(null);
1394
+ const [viewerFailed, setViewerFailed] = (0, import_react2.useState)(false);
1315
1395
  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
- }, []);
1396
+ (0, import_react2.useEffect)(() => figure.current ? watchPageTheme(figure.current, setTheme) : void 0, []);
1328
1397
  (0, import_react2.useEffect)(() => {
1329
1398
  const el = img.current;
1330
1399
  if (!el?.complete) setPending(true);
@@ -1334,26 +1403,30 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
1334
1403
  const active = theme === "dark" ? dark : light;
1335
1404
  const expand = async (e) => {
1336
1405
  if (e.target.closest("a")) return;
1406
+ setViewerFailed(false);
1337
1407
  try {
1338
1408
  const response = await fetch(active.src);
1339
1409
  const svg = response.ok ? await response.text() : "";
1340
1410
  const id = /^\s*<svg\b[^>]*?\sid="([\w-]+)"/.exec(svg)?.[1];
1341
- if (!id || !isSafeStoredSvg(svg)) return;
1411
+ if (!id || !isSafeStoredSvg(svg)) return setViewerFailed(true);
1342
1412
  const { DiagramViewer: DiagramViewer2 } = await Promise.resolve().then(() => (init_diagram_viewer(), diagram_viewer_exports));
1343
1413
  setViewer(() => DiagramViewer2);
1344
1414
  setView({ svg, id });
1345
1415
  } catch {
1416
+ setViewerFailed(true);
1346
1417
  }
1347
1418
  };
1348
1419
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", children: [
1349
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { ref: trigger, type: "button", className: "hyle-mermaid-open", "aria-label": labels.expand, "aria-haspopup": "dialog", onClick: expand, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hyle-mermaid-frame", style: { aspectRatio: `${active.width} / ${active.height}`, maxWidth: active.width }, children: [
1350
- 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,
1351
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("picture", { children: [
1352
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("source", { srcSet: dark.src, media: theme === null ? "(prefers-color-scheme: dark)" : theme === "dark" ? "all" : "not all" }),
1353
- /* @__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) })
1420
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "hyle-mermaid-open", role: "presentation", onClick: expand, children: [
1421
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "hyle-mermaid-frame", style: { aspectRatio: `${active.width} / ${active.height}`, maxWidth: active.width }, children: [
1422
+ 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,
1423
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("picture", { children: [
1424
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("source", { srcSet: dark.src, media: theme === null ? "(prefers-color-scheme: dark)" : theme === "dark" ? "all" : "not all" }),
1425
+ /* @__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) })
1426
+ ] })
1354
1427
  ] }),
1355
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-mermaid-hint", "aria-hidden": "true", children: labels.expandHint })
1356
- ] }) }),
1428
+ /* @__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 })
1429
+ ] }),
1357
1430
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("details", { className: "hyle-mermaid-source", children: [
1358
1431
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("summary", { children: sourceLabel }),
1359
1432
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { className: "language-mermaid", children: source }) })
@@ -1366,15 +1439,19 @@ function MermaidImage({ source, title, errorText, loadingText, sourceLabel, ligh
1366
1439
  source,
1367
1440
  title,
1368
1441
  labels,
1369
- onClose: () => {
1442
+ onClose: () => afterFullscreen(figure.current, () => {
1370
1443
  setView(null);
1371
1444
  trigger.current?.focus({ preventScroll: true });
1372
- }
1445
+ })
1373
1446
  }
1374
1447
  ) : null,
1448
+ viewerFailed ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: labels.unavailable }) : null,
1375
1449
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("figcaption", { className: "sr-only", children: title })
1376
1450
  ] });
1377
1451
  }
1452
+ function MermaidImage(props) {
1453
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mermaid_diagram.DiagramBoundary, { source: props.source, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StoredDiagram, { ...props }) });
1454
+ }
1378
1455
  // Annotate the CommonJS export names for ESM import in node:
1379
1456
  0 && (module.exports = {
1380
1457
  MermaidImage,
@@ -1,11 +1,12 @@
1
1
  import * as react from 'react';
2
- import { V as ViewerLabels } from './labels-nmukKYgL.cjs';
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({ source, title, errorText, loadingText, sourceLabel, light, dark, labels }: MermaidImageProps): react.JSX.Element;
28
+ declare function MermaidImage(props: MermaidImageProps): react.JSX.Element;
28
29
 
29
30
  export { MermaidImage, type MermaidImageProps, type StoredRender, isSafeStoredSvg };
@@ -1,11 +1,12 @@
1
1
  import * as react from 'react';
2
- import { V as ViewerLabels } from './labels-nmukKYgL.js';
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({ source, title, errorText, loadingText, sourceLabel, light, dark, labels }: MermaidImageProps): react.JSX.Element;
28
+ declare function MermaidImage(props: MermaidImageProps): react.JSX.Element;
28
29
 
29
30
  export { MermaidImage, type MermaidImageProps, type StoredRender, isSafeStoredSvg };
@@ -1,14 +1,15 @@
1
1
  "use client";
2
2
  import {
3
- pickMermaidTheme
4
- } from "./chunk-PJMJMP66.js";
3
+ afterFullscreen,
4
+ watchPageTheme
5
+ } from "./chunk-SFFBZFEN.js";
5
6
  import {
6
7
  VIEWER_LABELS_EN
7
- } from "./chunk-BUJFMR3M.js";
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 MermaidImage({ source, title, errorText, loadingText, sourceLabel, light, dark, labels = VIEWER_LABELS_EN }) {
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-FJPED4SN.js");
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__ */ jsx("button", { ref: trigger, type: "button", className: "hyle-mermaid-open", "aria-label": labels.expand, "aria-haspopup": "dialog", onClick: expand, children: /* @__PURE__ */ jsxs("span", { className: "hyle-mermaid-frame", style: { aspectRatio: `${active.width} / ${active.height}`, maxWidth: active.width }, children: [
63
- pending ? /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-loader", role: "status", "aria-busy": "true", children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: loadingText }) }) : null,
64
- /* @__PURE__ */ jsxs("picture", { children: [
65
- /* @__PURE__ */ jsx("source", { srcSet: dark.src, media: theme === null ? "(prefers-color-scheme: dark)" : theme === "dark" ? "all" : "not all" }),
66
- /* @__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) })
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("span", { className: "hyle-mermaid-hint", "aria-hidden": "true", children: labels.expandHint })
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