@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.
Files changed (86) hide show
  1. package/README.md +155 -28
  2. package/dist/check-routes-bin.js +38 -13
  3. package/dist/chunk-56Y24XBV.js +840 -0
  4. package/dist/{chunk-MGSUQBDW.js → chunk-75JFLML4.js} +176 -14
  5. package/dist/chunk-HJX57NLI.js +1105 -0
  6. package/dist/chunk-K5VDLROQ.js +145 -0
  7. package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
  8. package/dist/chunk-U74B7AUG.js +398 -0
  9. package/dist/{chunk-6VOHFFA5.js → chunk-X2TLYM7Y.js} +2 -2
  10. package/dist/client-41fU6OY2.d.cts +201 -0
  11. package/dist/client-LwzHwqpM.d.ts +201 -0
  12. package/dist/code-copy.cjs +72 -0
  13. package/dist/code-copy.d.cts +15 -0
  14. package/dist/code-copy.d.ts +15 -0
  15. package/dist/code-copy.js +48 -0
  16. package/dist/comments.cjs +728 -275
  17. package/dist/comments.d.cts +66 -3
  18. package/dist/comments.d.ts +66 -3
  19. package/dist/comments.js +409 -326
  20. package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
  21. package/dist/{embed-BmdwA2G9.d.cts → embed-BUFRQboD.d.ts} +2 -2
  22. package/dist/{embed-DNTZ2UXv.d.ts → embed-CYt-q13P.d.cts} +2 -2
  23. package/dist/fragment-alias.cjs +51 -0
  24. package/dist/fragment-alias.d.cts +7 -0
  25. package/dist/fragment-alias.d.ts +7 -0
  26. package/dist/fragment-alias.js +27 -0
  27. package/dist/html.cjs +881 -0
  28. package/dist/html.d.cts +20 -0
  29. package/dist/html.d.ts +20 -0
  30. package/dist/html.js +45 -0
  31. package/dist/index.cjs +181 -14
  32. package/dist/index.d.cts +14 -62
  33. package/dist/index.d.ts +14 -62
  34. package/dist/index.js +11 -1
  35. package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.cts} +9 -0
  36. package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.ts} +9 -0
  37. package/dist/mermaid-diagram.cjs +401 -125
  38. package/dist/mermaid-diagram.d.cts +23 -7
  39. package/dist/mermaid-diagram.d.ts +23 -7
  40. package/dist/mermaid-diagram.js +204 -51
  41. package/dist/mermaid-image.cjs +134 -60
  42. package/dist/mermaid-image.d.cts +4 -3
  43. package/dist/mermaid-image.d.ts +4 -3
  44. package/dist/mermaid-image.js +27 -28
  45. package/dist/next.cjs +627 -264
  46. package/dist/next.d.cts +11 -8
  47. package/dist/next.d.ts +11 -8
  48. package/dist/next.js +39 -12
  49. package/dist/print-coordinator.cjs +157 -0
  50. package/dist/print-coordinator.d.cts +27 -0
  51. package/dist/print-coordinator.d.ts +27 -0
  52. package/dist/print-coordinator.js +83 -0
  53. package/dist/react.cjs +556 -226
  54. package/dist/react.d.cts +136 -29
  55. package/dist/react.d.ts +136 -29
  56. package/dist/react.js +23 -3
  57. package/dist/reactions.cjs +653 -0
  58. package/dist/reactions.d.cts +27 -0
  59. package/dist/reactions.d.ts +27 -0
  60. package/dist/reactions.js +364 -0
  61. package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
  62. package/dist/{resolve-euZ4-aC9.d.cts → resolve-eI1muCKL.d.cts} +2 -2
  63. package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
  64. package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
  65. package/dist/sanitize-ijiWjEm9.d.cts +23 -0
  66. package/dist/sanitize-ijiWjEm9.d.ts +23 -0
  67. package/dist/styles.css +96 -25
  68. package/dist/toc-spy.cjs +59 -0
  69. package/dist/toc-spy.d.cts +15 -0
  70. package/dist/toc-spy.d.ts +15 -0
  71. package/dist/toc-spy.js +35 -0
  72. package/dist/{types-Czt887Iv.d.cts → types-3F0wqD-o.d.cts} +26 -2
  73. package/dist/{types-Czt887Iv.d.ts → types-3F0wqD-o.d.ts} +26 -2
  74. package/dist/use-cache.cjs +37 -11
  75. package/dist/use-cache.d.cts +12 -5
  76. package/dist/use-cache.d.ts +12 -5
  77. package/dist/use-cache.js +7 -7
  78. package/dist/youtube-facade.cjs +50 -0
  79. package/dist/youtube-facade.d.cts +17 -0
  80. package/dist/youtube-facade.d.ts +17 -0
  81. package/dist/youtube-facade.js +26 -0
  82. package/package.json +16 -3
  83. package/dist/chunk-DMK4XQLU.js +0 -1556
  84. package/dist/chunk-PJMJMP66.js +0 -63
  85. package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
  86. package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
@@ -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: "Actual size",
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: "Copy diagram source",
53
- downloadSvg: "Download SVG",
54
- downloadPng: "Download PNG",
55
- copyImage: "Copy as image",
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) d = nd, best = n.key;
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)) seen.add(other), queue2.push(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) nodes.add(g.edges[i].from), nodes.add(g.edges[i].to);
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) cost = c, pick = k;
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) ?? []]) adjacent.add(g.edges[i].from), adjacent.add(g.edges[i].to);
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 fresh = /* @__PURE__ */ new Map();
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)) if (!m[1].startsWith(`${newId}_`) && m[1] !== newId) fresh.set(m[1], `${newId}_${m[1]}`);
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, ids) => `${a}${ids.split(/\s+/).map(to).join(" ")}"`)
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) e.el.classList.add("hv-e"), e.labelEl?.classList.add("hv-e");
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) mark(this.edges[i]?.el, "hv-up", ...flow), mark(this.edges[i]?.labelEl, "hv-up");
866
- for (const i of t.downEdges) mark(this.edges[i]?.el, "hv-down", ...flow), mark(this.edges[i]?.labelEl, "hv-down");
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) mark(this.edges[i]?.el, "hv-nb"), mark(this.edges[i]?.labelEl, "hv-nb");
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
- labelsRef.current = labels;
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.current), [svg, svgId]);
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.current}_`), [scoped]);
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 = () => setFullscreen(document.fullscreenElement === shell.current);
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, import_jsx_runtime.jsx)(
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, import_jsx_runtime.jsxs)("div", { className: "hv-shell", ref: shell, children: [
1197
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hv-bar", role: "toolbar", "aria-label": labels.viewer, children: [
1198
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "hv-title", children: title }),
1199
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("output", { className: "hv-zoom", ref: zoom, "aria-label": "zoom", children: "100%" }),
1200
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "hv-group", children: [
1201
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.zoomOut, title: labels.zoomOut, onClick: () => ctl.current?.zoomBy(0.8), children: "\u2212" }),
1202
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.zoomIn, title: labels.zoomIn, onClick: () => ctl.current?.zoomBy(1.25), children: "+" }),
1203
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.fit, title: labels.fit, onClick: () => ctl.current?.fit(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Glyph, { d: ICONS.fit }) }),
1204
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "hv-btn hv-txt", "aria-label": labels.actual, title: labels.actual, onClick: () => ctl.current?.actual(), children: "100%" })
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, import_jsx_runtime.jsxs)("span", { className: "hv-group hv-find", children: [
1207
- /* @__PURE__ */ (0, import_jsx_runtime.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_runtime.jsx)(Glyph, { d: ICONS.search }) }),
1208
- finding ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1209
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
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, import_jsx_runtime.jsx)("output", { className: "hv-count", "aria-live": "polite", children: status })
1274
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("output", { className: "hv-count", "aria-live": "polite", children: status })
1226
1275
  ] }) : null
1227
1276
  ] }),
1228
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "hv-group hv-export", children: [
1229
- /* @__PURE__ */ (0, import_jsx_runtime.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" }),
1230
- /* @__PURE__ */ (0, import_jsx_runtime.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" }),
1231
- /* @__PURE__ */ (0, import_jsx_runtime.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" }),
1232
- /* @__PURE__ */ (0, import_jsx_runtime.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_runtime.jsx)("option", { value: s, children: `${s}\xD7` }, s)) }),
1233
- canCopyImage ? /* @__PURE__ */ (0, import_jsx_runtime.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
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, import_jsx_runtime.jsxs)("span", { className: "hv-group hv-end", children: [
1236
- canFullscreen ? /* @__PURE__ */ (0, import_jsx_runtime.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_runtime.jsx)(Glyph, { d: fullscreen ? ICONS.exit : ICONS.full }) }) : null,
1237
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "hv-btn", "aria-label": labels.close, title: `${labels.close} (Esc)`, onClick: () => dialog.current?.close(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Glyph, { d: ICONS.close }) })
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, import_jsx_runtime.jsx)("div", { className: "hv-view", ref: viewport, tabIndex: -1, role: "group", "aria-label": title, "aria-describedby": helpId, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "hv-stage", ref: stage }) }),
1241
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("canvas", { className: "hv-mini", ref: minimap, width: 176, height: 120, hidden: !ui.minimap, "aria-hidden": "true" }),
1242
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hv-foot", children: [
1243
- ui.pinned ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", { className: "hv-legend", "aria-hidden": "true", children: [
1244
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "hv-sel", children: labels.legendSelected }),
1245
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "hv-up", children: labels.legendUpstream }),
1246
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "hv-down", children: labels.legendDownstream })
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, import_jsx_runtime.jsx)("p", { className: "hv-hint", id: helpId, children: labels.hint }),
1249
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("output", { className: "hv-toast", role: "status", children: toast })
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, import_jsx_runtime, sequence, locks, LOCK_CLASS, SCALES, TOAST_MS, Glyph, ICONS;
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
- import_jsx_runtime = require("react/jsx-runtime");
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, 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 }) });
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: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",
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,142 @@ 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 = 5e3;
1292
- function luminance(css) {
1293
- const m = /^(rgba?)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/.exec(css.trim());
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 COLOR = /^(rgba?|oklab|oklch|lab|lch)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/;
1379
+ function isDark(css) {
1380
+ const m = COLOR.exec(css.trim());
1294
1381
  if (!m) return void 0;
1295
- const parts = (m[2] ?? m[3] ?? "").split(/[\s,/]+/).filter(Boolean).map(Number);
1296
- const [r, g, b] = parts.map((v) => m[3] ? v : v / 255);
1297
- const alpha = parts[3] ?? 1;
1298
- if (r === void 0 || g === void 0 || b === void 0 || [r, g, b, alpha].some(Number.isNaN) || alpha < 0.5) return void 0;
1299
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
1382
+ const kind = m[1] ?? "color";
1383
+ const parts = (m[2] ?? m[3] ?? "").split(/[\s,/]+/).filter(Boolean);
1384
+ const [a, b, c] = parts.map((v) => v === "none" ? 0 : Number.parseFloat(v));
1385
+ const alpha = parts[3] === void 0 ? 1 : Number.parseFloat(parts[3]) / (parts[3].endsWith("%") ? 100 : 1);
1386
+ if (a === void 0 || b === void 0 || c === void 0 || [a, b, c, alpha].some(Number.isNaN) || alpha < 0.5) return void 0;
1387
+ if (kind.startsWith("ok")) return (parts[0]?.endsWith("%") ? a / 100 : a) < 0.6;
1388
+ if (kind.startsWith("l")) return a < 53;
1389
+ const scale = kind === "color" ? 1 : 255;
1390
+ return (0.2126 * a + 0.7152 * b + 0.0722 * c) / scale < 0.5;
1300
1391
  }
1301
- function pickMermaidTheme(background, prefersDark) {
1302
- const l = luminance(background);
1303
- return (l === void 0 ? prefersDark : l < 0.5) ? "dark" : "default";
1392
+ function pickMermaidTheme(background, prefersDark, colorScheme = "") {
1393
+ const declared = /\bdark\b/.test(colorScheme) === /\blight\b/.test(colorScheme) ? void 0 : /\bdark\b/.test(colorScheme);
1394
+ return isDark(background) ?? declared ?? prefersDark ? "dark" : "default";
1395
+ }
1396
+ function watchPageTheme(el, onTheme) {
1397
+ const scheme = window.matchMedia("(prefers-color-scheme: dark)");
1398
+ const update = () => {
1399
+ const style = getComputedStyle(el);
1400
+ onTheme(pickMermaidTheme(style.backgroundColor, scheme.matches, style.colorScheme));
1401
+ };
1402
+ update();
1403
+ const observer = new MutationObserver(update);
1404
+ observer.observe(document.documentElement, { attributes: true });
1405
+ observer.observe(document.body, { attributes: true });
1406
+ scheme.addEventListener("change", update);
1407
+ return () => {
1408
+ observer.disconnect();
1409
+ scheme.removeEventListener("change", update);
1410
+ };
1304
1411
  }
1305
1412
  var RENDER_TIMEOUT_MS = 1e4;
1306
1413
  var NEAR_VIEWPORT_MARGIN = "200px";
1307
- var FRONTMATTER = /^\s*-{3}[^\S\n]*\n[\s\S]*?\n-{3}[^\S\n]*(?:\n|$)/;
1414
+ var FRONTMATTER = /\s*-{3}[^\S\n]*\n[\s\S]*?\n[^\S\n]*-{3}[^\S\n]*(?:\n|$)/y;
1308
1415
  var DIRECTIVE = /%%\{(?:(?!\}%%)[\s\S])*(?:\}%%)?/g;
1416
+ var MAX_STRIP_ROUNDS = 16;
1417
+ function dropFrontmatter(text) {
1418
+ let end = 0;
1419
+ for (; ; ) {
1420
+ FRONTMATTER.lastIndex = end;
1421
+ const block = FRONTMATTER.exec(text);
1422
+ if (!block) return text.slice(end);
1423
+ end += block[0].length;
1424
+ }
1425
+ }
1309
1426
  function stripMermaidConfig(source) {
1310
1427
  let text = source.replace(/\r\n?/g, "\n");
1311
- for (let previous = ""; previous !== text; ) {
1312
- previous = text;
1313
- text = text.replace(FRONTMATTER, "").replace(DIRECTIVE, "");
1428
+ for (let round = 0; round < MAX_STRIP_ROUNDS; round++) {
1429
+ const next = dropFrontmatter(text).replace(DIRECTIVE, "");
1430
+ if (next === text) return text;
1431
+ text = next;
1314
1432
  }
1315
- return text;
1433
+ return "";
1434
+ }
1435
+ var EDGE_TOKEN = /-{2,}|={2,}|~{3}|\.{2,}|\.-|-[>x)]/;
1436
+ var ER_TOKEN = /-{2,}|={2,}|~{3}|\.{2,}|\.-|-[>x)]|-\.|to\b/i;
1437
+ var AMPERSAND = /\s&(?=\s)/g;
1438
+ var GROUP_OPENER = /^(?:subgraph\b|state\b.*\{)/;
1439
+ var BLOCK_OPENER = /\bblock\b(?!-)/g;
1440
+ var DEFAULT_LIMITS = { statements: AUTO_RENDER_STATEMENTS, words: AUTO_RENDER_WORDS, groups: AUTO_RENDER_GROUPS, edges: AUTO_RENDER_EDGES, blocks: Infinity, token: EDGE_TOKEN };
1441
+ var TYPE_LIMITS = {
1442
+ mindmap: { statements: 40 },
1443
+ kanban: { statements: 100 },
1444
+ block: { words: 100, blocks: 8 },
1445
+ erDiagram: { statements: 120, edges: 50, token: ER_TOKEN },
1446
+ "venn-beta": { statements: 180 },
1447
+ classDiagram: { statements: 70, edges: 30 },
1448
+ stateDiagram: { statements: 80 }
1449
+ };
1450
+ var COMMENT_LINE = /^[^\S\n\u2028\u2029]*%%[^\n]+\n?/gm;
1451
+ var statementsOf = (code) => code.split(/[\n;]/).map((s) => s.trim()).filter((s) => s && s !== "end");
1452
+ var edgeBound = (code, token) => {
1453
+ const amps = code.match(AMPERSAND)?.length ?? 0;
1454
+ return code.split(token).length - 1 + 2 * amps + Math.floor(amps ** 2 / 4);
1455
+ };
1456
+ function isLargeDiagram(source) {
1457
+ if (source.length > AUTO_RENDER_CHARS) return true;
1458
+ const code = stripMermaidConfig(source).replace(COMMENT_LINE, "");
1459
+ const statements = statementsOf(code);
1460
+ const first = statements.find((line) => !line.startsWith("%%")) ?? "";
1461
+ const type = Object.keys(TYPE_LIMITS).find((keyword) => first.startsWith(keyword));
1462
+ const limit = { ...DEFAULT_LIMITS, ...type ? TYPE_LIMITS[type] : void 0 };
1463
+ const words = statements.reduce((n, line) => n + line.split(/\s+/).length, 0);
1464
+ const groups = statements.filter((line) => GROUP_OPENER.test(line)).length;
1465
+ const blocks = code.match(BLOCK_OPENER)?.length ?? 0;
1466
+ return statements.length > limit.statements || words > limit.words || groups > limit.groups || blocks > limit.blocks || edgeBound(code, limit.token) > limit.edges;
1316
1467
  }
1317
1468
  var counter = 0;
1318
- var nextMermaidId = () => `hyle-mermaid-${++counter}`;
1469
+ var nextMermaidId = () => `hyleMermaid-${++counter}`;
1319
1470
  function withTimeout(promise, ms) {
1320
1471
  let timer;
1321
1472
  const timeout = new Promise((_, reject) => {
@@ -1338,87 +1489,212 @@ function whenNearViewport(el, onNear, Observer = globalThis.IntersectionObserver
1338
1489
  observer.observe(el);
1339
1490
  return () => observer.disconnect();
1340
1491
  }
1492
+ function afterFullscreen(within, then) {
1493
+ if (document.fullscreenElement && within?.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
1494
+ }).then(then);
1495
+ else then();
1496
+ }
1341
1497
 
1342
1498
  // src/react/mermaid-diagram.tsx
1499
+ var import_print_coordinator = require("./print-coordinator.cjs");
1343
1500
  init_labels();
1344
- var import_jsx_runtime2 = require("react/jsx-runtime");
1501
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1502
+ var DiagramBoundary = class extends import_react2.Component {
1503
+ state = { failed: false };
1504
+ static getDerivedStateFromError() {
1505
+ return { failed: true };
1506
+ }
1507
+ render() {
1508
+ if (!this.state.failed) return this.props.children;
1509
+ 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 }) }) });
1510
+ }
1511
+ };
1345
1512
  var queue = Promise.resolve();
1346
- async function renderSvg(id, source, theme) {
1513
+ var afterPaint = () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
1514
+ async function renderSvg(id, source, theme, onSvg, stillWanted) {
1347
1515
  const { default: mermaid } = await import("mermaid");
1348
- mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme, maxTextSize: MAX_MERMAID_SOURCE, maxEdges: MAX_MERMAID_EDGES, suppressErrorRendering: true });
1349
- try {
1350
- return { markup: (await mermaid.render(id, stripMermaidConfig(source))).svg, id };
1351
- } finally {
1352
- document.getElementById(`d${id}`)?.remove();
1516
+ if (stillWanted) {
1517
+ await afterPaint();
1518
+ if (!stillWanted()) return;
1353
1519
  }
1520
+ mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme, ...theme === "dark" ? { themeVariables: DARK_VARIABLES } : {}, maxTextSize: MAX_MERMAID_SOURCE, maxEdges: MAX_MERMAID_EDGES, suppressErrorRendering: true });
1521
+ const drawing = mermaid.render(id, stripMermaidConfig(source)).then((out) => onSvg({ markup: out.svg, id, theme })).finally(() => document.getElementById(`d${id}`)?.remove());
1522
+ await withTimeout(drawing, RENDER_TIMEOUT_MS);
1354
1523
  }
1355
- var THEME_ATTRS = ["data-act", "data-theme", "class"];
1356
- function MermaidDiagram({ source, title, errorText, loadingText = "Rendering the diagram", labels = VIEWER_LABELS_EN }) {
1524
+ var noSubscription = () => () => {
1525
+ };
1526
+ function Diagram({ source, title, errorText, loadingText = "Rendering the diagram", labels = VIEWER_LABELS_EN }) {
1357
1527
  const figure = (0, import_react2.useRef)(null);
1358
1528
  const trigger = (0, import_react2.useRef)(null);
1359
1529
  const captionId = (0, import_react2.useId)();
1530
+ const sourceId = (0, import_react2.useId)();
1531
+ const live = (0, import_react2.useSyncExternalStore)(noSubscription, () => true, () => false);
1360
1532
  const [open, setOpen] = (0, import_react2.useState)(false);
1361
1533
  const [Viewer, setViewer] = (0, import_react2.useState)(null);
1534
+ const [viewerFailed, setViewerFailed] = (0, import_react2.useState)(false);
1362
1535
  const [theme, setTheme] = (0, import_react2.useState)(null);
1363
1536
  const [near, setNear] = (0, import_react2.useState)(false);
1364
1537
  const [svg, setSvg] = (0, import_react2.useState)(null);
1365
1538
  const [failed, setFailed] = (0, import_react2.useState)(false);
1539
+ const large = (0, import_react2.useMemo)(() => isLargeDiagram(source), [source]);
1540
+ const [asked, setAsked] = (0, import_react2.useState)(false);
1541
+ const [attempt, setAttempt] = (0, import_react2.useState)(0);
1542
+ const [showAll, setShowAll] = (0, import_react2.useState)(false);
1543
+ const refocus = (0, import_react2.useRef)(false);
1544
+ const allowed = !large || asked;
1545
+ const clamped = large && isClampedSource(source);
1546
+ (0, import_react2.useEffect)(() => figure.current ? watchPageTheme(figure.current, setTheme) : void 0, []);
1547
+ (0, import_react2.useEffect)(() => figure.current ? whenNearViewport(figure.current, () => setNear(true)) : void 0, []);
1366
1548
  (0, import_react2.useEffect)(() => {
1367
- const scheme = window.matchMedia("(prefers-color-scheme: dark)");
1368
- const update = () => figure.current && setTheme(pickMermaidTheme(getComputedStyle(figure.current).backgroundColor, scheme.matches));
1369
- update();
1370
- const observer = new MutationObserver(update);
1371
- observer.observe(document.documentElement, { attributes: true, attributeFilter: THEME_ATTRS });
1372
- scheme.addEventListener("change", update);
1549
+ const toPrint = window.matchMedia("print");
1550
+ const draw2 = () => setNear(true);
1551
+ if (toPrint.matches) draw2();
1552
+ const onChange = (e) => {
1553
+ if (e.matches) draw2();
1554
+ };
1555
+ window.addEventListener("beforeprint", draw2);
1556
+ toPrint.addEventListener("change", onChange);
1373
1557
  return () => {
1374
- observer.disconnect();
1375
- scheme.removeEventListener("change", update);
1558
+ window.removeEventListener("beforeprint", draw2);
1559
+ toPrint.removeEventListener("change", onChange);
1376
1560
  };
1377
1561
  }, []);
1378
- (0, import_react2.useEffect)(() => figure.current ? whenNearViewport(figure.current, () => setNear(true)) : void 0, []);
1562
+ const settled = (0, import_react2.useRef)(false);
1563
+ const shown = (0, import_react2.useRef)(false);
1564
+ const allowedNow = (0, import_react2.useRef)(allowed);
1565
+ const waiters = (0, import_react2.useRef)([]);
1566
+ (0, import_react2.useEffect)(() => {
1567
+ allowedNow.current = allowed;
1568
+ settled.current = svg !== null || failed || !allowed;
1569
+ shown.current = svg !== null;
1570
+ if (settled.current) waiters.current.splice(0).forEach((resolve) => resolve());
1571
+ }, [svg, failed, allowed]);
1572
+ (0, import_react2.useEffect)(() => {
1573
+ const pending = waiters.current;
1574
+ const uninstall = (0, import_print_coordinator.installPrintShortcut)();
1575
+ const unregister = (0, import_print_coordinator.registerPrintTarget)({
1576
+ status: labels.printPreparing,
1577
+ settled: () => settled.current,
1578
+ prepare: () => allowedNow.current ? import("mermaid") : Promise.resolve(),
1579
+ ensureDrawn: () => settled.current ? Promise.resolve() : new Promise((resolve) => {
1580
+ pending.push(resolve);
1581
+ setNear(true);
1582
+ })
1583
+ });
1584
+ return () => {
1585
+ unregister();
1586
+ uninstall();
1587
+ pending.splice(0).forEach((resolve) => resolve());
1588
+ };
1589
+ }, [labels.printPreparing]);
1590
+ const wanted = near && allowed;
1379
1591
  (0, import_react2.useEffect)(() => {
1380
- if (theme === null || !near) return;
1592
+ if (theme === null || !wanted) return;
1381
1593
  let current = true;
1382
1594
  const id = nextMermaidId();
1383
- queue = queue.then(() => current ? withTimeout(renderSvg(id, source, theme), RENDER_TIMEOUT_MS) : void 0).then(
1384
- (out) => current && out !== void 0 && (setSvg(out), setFailed(false)),
1385
- () => current && setFailed(true)
1386
- );
1595
+ const show = (out) => {
1596
+ if (!current) return;
1597
+ setSvg(out);
1598
+ setFailed(false);
1599
+ };
1600
+ queue = queue.then(() => current ? renderSvg(id, source, theme, show, large && !shown.current ? () => current : void 0) : void 0).catch(() => {
1601
+ if (current) setFailed(true);
1602
+ });
1387
1603
  return () => {
1388
1604
  current = false;
1389
1605
  };
1390
- }, [source, theme, near]);
1606
+ }, [source, theme, wanted, attempt, large]);
1607
+ (0, import_react2.useEffect)(() => {
1608
+ if (!refocus.current || svg === null && !failed) return;
1609
+ refocus.current = false;
1610
+ const active = document.activeElement;
1611
+ if (svg && (!active || active === document.body)) trigger.current?.focus({ preventScroll: true });
1612
+ }, [svg, failed]);
1613
+ const collapsed = (0, import_react2.useRef)(null);
1614
+ (0, import_react2.useLayoutEffect)(() => {
1615
+ collapsed.current?.scrollIntoView({ block: "nearest" });
1616
+ collapsed.current = null;
1617
+ }, [showAll]);
1618
+ const toggleSource = (button) => {
1619
+ collapsed.current = showAll ? button : null;
1620
+ setShowAll(!showAll);
1621
+ };
1391
1622
  const html = (0, import_react2.useMemo)(() => svg ? { __html: svg.markup } : void 0, [svg]);
1623
+ const drawing = wanted && svg === null && !failed;
1624
+ const busy = asked && !failed;
1625
+ const draw = () => {
1626
+ if (busy) return;
1627
+ refocus.current = true;
1628
+ setAsked(true);
1629
+ setNear(true);
1630
+ if (failed) {
1631
+ setFailed(false);
1632
+ setAttempt((n) => n + 1);
1633
+ }
1634
+ };
1392
1635
  const expand = (e) => {
1393
1636
  if (e.target.closest("a")) return;
1637
+ const selection = window.getSelection();
1638
+ if (selection && !selection.isCollapsed && figure.current?.contains(selection.anchorNode)) return;
1394
1639
  setOpen(true);
1395
- if (!Viewer) void Promise.resolve().then(() => (init_diagram_viewer(), diagram_viewer_exports)).then((m) => setViewer(() => m.DiagramViewer), () => setOpen(false));
1396
- };
1397
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", ...svg === null && !failed ? { "data-state": "pending" } : {}, children: [
1398
- near && svg === null && !failed ? /* @__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,
1399
- svg === null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { className: "language-mermaid", children: source }) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { ref: trigger, type: "button", className: "hyle-mermaid-open", "aria-label": labels.expand, "aria-describedby": captionId, "aria-haspopup": "dialog", onClick: expand, children: [
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: () => {
1640
+ setViewerFailed(false);
1641
+ if (!Viewer) {
1642
+ void Promise.resolve().then(() => (init_diagram_viewer(), diagram_viewer_exports)).then(
1643
+ (m) => setViewer(() => m.DiagramViewer),
1644
+ () => {
1412
1645
  setOpen(false);
1413
- trigger.current?.focus({ preventScroll: true });
1646
+ setViewerFailed(true);
1414
1647
  }
1415
- }
1416
- ) : null,
1417
- failed ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: errorText }) : null,
1418
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("figcaption", { id: svg ? captionId : void 0, className: "sr-only", children: title })
1419
- ] });
1648
+ );
1649
+ }
1650
+ };
1651
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1652
+ "figure",
1653
+ {
1654
+ ref: figure,
1655
+ className: "hyle-mermaid",
1656
+ "data-slot-component": "Mermaid",
1657
+ "data-mermaid-theme": svg?.theme,
1658
+ ...allowed && svg === null && !failed ? { "data-state": "pending" } : {},
1659
+ ...!live && clamped ? { "data-clamp": "" } : {},
1660
+ children: [
1661
+ svg !== null ? (
1662
+ // The whole diagram is a click target for the mouse; the button is the one control for keyboard and assistive technology, and its
1663
+ // text ("Expand") is the start of its name. A diagram's own text must not be inside a button (axe label-content-name-mismatch).
1664
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "hyle-mermaid-open", role: "presentation", onClick: expand, children: [
1665
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "hyle-mermaid-svg", dangerouslySetInnerHTML: html }),
1666
+ /* @__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 })
1667
+ ] })
1668
+ ) : 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: [
1669
+ 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,
1670
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("code", { className: "language-mermaid", children: source }) })
1671
+ ] }),
1672
+ open && Viewer && svg ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1673
+ Viewer,
1674
+ {
1675
+ svg: svg.markup,
1676
+ svgId: svg.id,
1677
+ source,
1678
+ title,
1679
+ labels,
1680
+ onClose: () => afterFullscreen(figure.current, () => {
1681
+ setOpen(false);
1682
+ trigger.current?.focus({ preventScroll: true });
1683
+ })
1684
+ }
1685
+ ) : null,
1686
+ failed && (svg !== null || !large) ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: errorText }) : null,
1687
+ viewerFailed ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: labels.unavailable }) : null,
1688
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("figcaption", { id: svg ? captionId : void 0, className: "sr-only", children: title })
1689
+ ]
1690
+ }
1691
+ );
1692
+ }
1693
+ function MermaidDiagram(props) {
1694
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DiagramBoundary, { source: props.source, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Diagram, { ...props }) });
1420
1695
  }
1421
1696
  // Annotate the CommonJS export names for ESM import in node:
1422
1697
  0 && (module.exports = {
1698
+ DiagramBoundary,
1423
1699
  MermaidDiagram
1424
1700
  });