@tdacorp/hyle-sdk 0.14.1 → 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 +171 -32
  2. package/dist/check-routes-bin.js +48 -21
  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 +733 -278
  17. package/dist/comments.d.cts +66 -3
  18. package/dist/comments.d.ts +66 -3
  19. package/dist/comments.js +414 -330
  20. package/dist/{diagram-viewer-DYX6R63Y.js → diagram-viewer-XY3CG75U.js} +107 -46
  21. package/dist/{embed-B76zRRPa.d.cts → embed-BUFRQboD.d.ts} +10 -5
  22. package/dist/{embed-SqOBGI-E.d.ts → embed-CYt-q13P.d.cts} +10 -5
  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-CrA-iqTN.d.cts +46 -0
  36. package/dist/labels-CrA-iqTN.d.ts +46 -0
  37. package/dist/mermaid-diagram.cjs +453 -148
  38. package/dist/mermaid-diagram.d.cts +25 -42
  39. package/dist/mermaid-diagram.d.ts +25 -42
  40. package/dist/mermaid-diagram.js +205 -50
  41. package/dist/mermaid-image.cjs +1456 -0
  42. package/dist/mermaid-image.d.cts +30 -0
  43. package/dist/mermaid-image.d.ts +30 -0
  44. package/dist/mermaid-image.js +93 -0
  45. package/dist/next.cjs +1709 -1134
  46. package/dist/next.d.cts +67 -14
  47. package/dist/next.d.ts +67 -14
  48. package/dist/next.js +950 -794
  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 +677 -264
  54. package/dist/react.d.cts +161 -31
  55. package/dist/react.d.ts +161 -31
  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-DC2ccfwA.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
  62. package/dist/{resolve-DKLVftk_.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 +107 -47
  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-ByodIyEv.d.cts → types-3F0wqD-o.d.cts} +44 -4
  73. package/dist/{types-ByodIyEv.d.ts → types-3F0wqD-o.d.ts} +44 -4
  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-4V4VKB3O.js +0 -1471
  84. package/dist/chunk-R5EMI4HQ.js +0 -61
  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) {
@@ -342,6 +373,37 @@ var init_scope_svg = __esm({
342
373
  }
343
374
  });
344
375
 
376
+ // src/react/viewer/svg-css.ts
377
+ var SVG_CSS;
378
+ var init_svg_css = __esm({
379
+ "src/react/viewer/svg-css.ts"() {
380
+ "use strict";
381
+ SVG_CSS = `
382
+ svg{display:block;position:static!important;width:100%;height:100%;max-width:none!important}
383
+ .hv-n{cursor:pointer;outline:none}
384
+ .hv-n,.hv-e{transition:opacity .15s}
385
+ @media (prefers-reduced-motion:reduce){.hv-n,.hv-e{transition:none}}
386
+ :host(.hv-plain) .hv-n,:host(.hv-plain) .hv-e{transition:none}
387
+ :host(.hv-active) .hv-n:not(.hv-on),:host(.hv-active) .hv-e:not(.hv-on){opacity:var(--hv-dim)}
388
+ .hv-n:focus-visible :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-focus)!important;stroke-width:calc(3px / var(--hv-k,1))!important}
389
+ .hv-n.hv-nb :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(2px / var(--hv-k,1))!important}
390
+ .hv-n.hv-up :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-up)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
391
+ .hv-n.hv-down :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-down)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
392
+ .hv-n.hv-sel :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(3.5px / var(--hv-k,1))!important}
393
+ .hv-n.hv-hit :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(3px / var(--hv-k,1))!important}
394
+ .hv-n.hv-cur :is(rect,polygon,circle,ellipse,path){stroke-width:calc(5px / var(--hv-k,1))!important}
395
+ text.hv-hit,text.hv-hit tspan{fill:var(--hv-accent)!important;font-weight:700}
396
+ text.hv-cur{text-decoration:underline}
397
+ path.hv-nb{stroke:var(--hv-accent)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
398
+ path.hv-up{stroke:var(--hv-up)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
399
+ path.hv-down{stroke:var(--hv-down)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
400
+ path.hv-flow{stroke-dasharray:calc(7px / var(--hv-k,1)) calc(6px / var(--hv-k,1))!important;animation:hv-dash .9s linear infinite}
401
+ @keyframes hv-dash{to{stroke-dashoffset:calc(-26px / var(--hv-k,1))}}
402
+ @media (prefers-reduced-motion:reduce){path.hv-flow{animation:none}}
403
+ `;
404
+ }
405
+ });
406
+
345
407
  // src/react/viewer/view-math.ts
346
408
  function zoomAt(v, px, py, k, min = MIN_K) {
347
409
  const next = clamp(k, min, MAX_K);
@@ -437,6 +499,7 @@ var init_controller = __esm({
437
499
  init_extract();
438
500
  init_graph();
439
501
  init_scope_svg();
502
+ init_svg_css();
440
503
  init_view_math();
441
504
  TAP_SLOP = 5;
442
505
  DOUBLE_TAP_MS = 350;
@@ -454,6 +517,7 @@ var init_controller = __esm({
454
517
  constructor(o) {
455
518
  this.o = o;
456
519
  const { viewport: vp, stage, minimap } = o;
520
+ const root = this.root = stage.shadowRoot ?? stage.attachShadow({ mode: "open" });
457
521
  const on = (el, type, fn, opts) => {
458
522
  el.addEventListener(type, fn, opts);
459
523
  this.off.push(() => el.removeEventListener(type, fn, opts));
@@ -463,21 +527,16 @@ var init_controller = __esm({
463
527
  on(vp, "pointermove", (e) => this.onMove(e));
464
528
  on(vp, "pointerup", (e) => this.onUp(e));
465
529
  on(vp, "pointercancel", (e) => this.onUp(e, true));
466
- on(stage, "pointerover", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.target)));
467
- on(stage, "pointerout", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.relatedTarget)));
468
- on(stage, "focusin", (e) => this.onFocusIn(e));
469
- on(stage, "focusout", () => this.focusLeft());
530
+ on(root, "pointerover", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.target)));
531
+ on(root, "pointerout", (e) => e.pointerType === "mouse" && !this.pointers.size && this.mouseOver(this.keyAt(e.relatedTarget)));
532
+ on(root, "focusin", (e) => this.onFocusIn(e));
533
+ on(root, "focusout", () => this.focusLeft());
470
534
  on(minimap, "pointerdown", (e) => this.onMiniDown(e));
471
535
  on(minimap, "pointermove", (e) => this.miniDrag && this.miniTo(e));
472
536
  on(minimap, "pointerup", () => this.miniDrag = false);
473
537
  on(minimap, "pointercancel", () => this.miniDrag = false);
474
538
  this.ro = new ResizeObserver(() => this.measure());
475
539
  this.ro.observe(vp);
476
- this.watcher = new MutationObserver(() => {
477
- const now = stage.querySelector("svg");
478
- if (now && now !== this.svg && this.source) this.mount(now, this.source.markup, this.source.idPrefix);
479
- });
480
- this.watcher.observe(stage, { childList: true });
481
540
  this.measure();
482
541
  }
483
542
  o;
@@ -515,8 +574,7 @@ var init_controller = __esm({
515
574
  dragging = false;
516
575
  samples = [];
517
576
  ro;
518
- watcher;
519
- source;
577
+ root;
520
578
  miniDrag = false;
521
579
  miniColors = { node: "#888", edge: "#555", view: "#0af", bg: "transparent" };
522
580
  off = [];
@@ -524,16 +582,19 @@ var init_controller = __esm({
524
582
  this.anim?.stop();
525
583
  cancelAnimationFrame(this.frame);
526
584
  this.ro?.disconnect();
527
- this.watcher?.disconnect();
528
585
  for (const f of this.off) f();
529
586
  }
530
587
  // ---- mounting -----------------------------------------------------------------------------------------------------------------------
531
- /** (Re)attaches to the SVG now in the stage. A re-mount (theme change) keeps the view and a still-valid pin. */
588
+ /** Shows `markup` in the stage's shadow root and attaches to its SVG. A new SVG (theme change) keeps the view and a still-valid pin. */
589
+ show(markup, idPrefix) {
590
+ this.root.innerHTML = `<style>${SVG_CSS}</style>${markup}`;
591
+ const svg = this.root.querySelector("svg");
592
+ if (svg) this.mount(svg, markup, idPrefix);
593
+ }
532
594
  mount(svg, markup, idPrefix) {
533
595
  const size = svgSize(markup) ?? { w: svg.getBoundingClientRect().width || 600, h: svg.getBoundingClientRect().height || 400 };
534
596
  const first = this.svg === void 0;
535
597
  this.svg = svg;
536
- this.source = { markup, idPrefix };
537
598
  this.content = { x: 0, y: 0, w: size.w, h: size.h };
538
599
  this.o.stage.style.width = `${size.w}px`;
539
600
  this.o.stage.style.height = `${size.h}px`;
@@ -573,7 +634,10 @@ var init_controller = __esm({
573
634
  n.el.setAttribute("aria-pressed", "false");
574
635
  });
575
636
  if (this.nodes[0]) this.roving = this.nodes[0].el;
576
- 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
+ }
577
641
  this.o.stage.classList.toggle("hv-plain", this.nodes.length > FADE_MAX_NODES);
578
642
  }
579
643
  // ---- view ---------------------------------------------------------------------------------------------------------------------------
@@ -667,8 +731,9 @@ var init_controller = __esm({
667
731
  const at = this.local(e);
668
732
  this.pointers.set(e.pointerId, at);
669
733
  if (this.pointers.size === 1) {
670
- const key = this.keyAt(e.target);
671
- this.tap = { at, key, moved: false, link: Boolean(e.target.closest?.("a")), id: e.pointerId };
734
+ const target = e.composedPath()[0];
735
+ const key = this.keyAt(target);
736
+ this.tap = { at, key, moved: false, link: Boolean(target.closest?.("a")), id: e.pointerId };
672
737
  this.start = { view: this.view, at };
673
738
  this.dragging = false;
674
739
  this.samples = [{ t: e.timeStamp, ...at }];
@@ -800,7 +865,7 @@ var init_controller = __esm({
800
865
  }
801
866
  focusLeft() {
802
867
  queueMicrotask(() => {
803
- if (this.o.stage.contains(document.activeElement)) return;
868
+ if (this.root.activeElement) return;
804
869
  this.focusKey = null;
805
870
  this.refreshHot();
806
871
  });
@@ -831,13 +896,22 @@ var init_controller = __esm({
831
896
  for (const k of t.down) mark(at(k)?.el, "hv-down");
832
897
  mark(at(this.pinned)?.el, "hv-sel");
833
898
  const flow = t.upEdges.size + t.downEdges.size <= FLOW_MAX_EDGES ? ["hv-flow"] : [];
834
- for (const i of t.upEdges) mark(this.edges[i]?.el, "hv-up", ...flow), mark(this.edges[i]?.labelEl, "hv-up");
835
- 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
+ }
836
907
  } else if (g && this.hot) {
837
908
  active = true;
838
909
  const n = neighbourhood(g, this.hot);
839
910
  for (const k of n.nodes) mark(at(k)?.el, k === this.hot ? "hv-sel" : "hv-nb");
840
- 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
+ }
841
915
  } else if (this.query && this.hitEls.length) {
842
916
  active = true;
843
917
  for (const el of this.hitEls) mark(el);
@@ -856,7 +930,7 @@ var init_controller = __esm({
856
930
  }
857
931
  /** Arrow-key traversal from the focused node. Returns false when the key was not used. */
858
932
  traverse(dir) {
859
- const el = document.activeElement?.closest?.(".hv-n") ?? null;
933
+ const el = this.root.activeElement?.closest?.(".hv-n") ?? null;
860
934
  const key = el && this.stageHas(el) ? this.keyAt(el) : null;
861
935
  if (key === null || !this.graph) return false;
862
936
  const next = pickNeighbour(this.graph, key, dir);
@@ -868,7 +942,7 @@ var init_controller = __esm({
868
942
  return true;
869
943
  }
870
944
  stageHas(el) {
871
- return this.o.stage.contains(el);
945
+ return this.root.contains(el);
872
946
  }
873
947
  /** Keyboard commands of the viewer. Returns true when the key was handled (the caller then prevents the default). */
874
948
  key(e) {
@@ -882,7 +956,7 @@ var init_controller = __esm({
882
956
  this.set({ ...this.view, x: this.view.x + (dir === "left" ? step : dir === "right" ? -step : 0), y: this.view.y + (dir === "up" ? step : dir === "down" ? -step : 0) });
883
957
  return true;
884
958
  }
885
- const onNode = this.keyAt(document.activeElement);
959
+ const onNode = this.keyAt(this.root.activeElement);
886
960
  switch (e.key) {
887
961
  case "+":
888
962
  case "=":
@@ -1064,8 +1138,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1064
1138
  const finder = (0, import_react.useRef)(null);
1065
1139
  const ctl = (0, import_react.useRef)(null);
1066
1140
  const labelsRef = (0, import_react.useRef)(labels);
1067
- labelsRef.current = labels;
1068
- const ownId = (0, import_react.useRef)(`hyle-viewer-${++sequence}`);
1141
+ const [ownId] = (0, import_react.useState)(() => `hyleViewer-${++sequence}`);
1069
1142
  const helpId = (0, import_react.useId)();
1070
1143
  const toastTimer = (0, import_react.useRef)(void 0);
1071
1144
  const downOnBackdrop = (0, import_react.useRef)(false);
@@ -1075,13 +1148,15 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1075
1148
  const [query, setQuery] = (0, import_react.useState)("");
1076
1149
  const [scale, setScale] = (0, import_react.useState)("2");
1077
1150
  const [fullscreen, setFullscreen] = (0, import_react.useState)(false);
1078
- const scoped = (0, import_react.useMemo)(() => scopeSvg(svg, svgId, ownId.current), [svg, svgId]);
1079
- const html = (0, import_react.useMemo)(() => ({ __html: scoped }), [scoped]);
1151
+ const scoped = (0, import_react.useMemo)(() => scopeSvg(svg, svgId, ownId), [svg, svgId, ownId]);
1080
1152
  const say = (message) => {
1081
1153
  clearTimeout(toastTimer.current);
1082
1154
  setToast(message);
1083
1155
  toastTimer.current = setTimeout(() => setToast(""), TOAST_MS);
1084
1156
  };
1157
+ (0, import_react.useLayoutEffect)(() => {
1158
+ labelsRef.current = labels;
1159
+ }, [labels]);
1085
1160
  (0, import_react.useLayoutEffect)(() => {
1086
1161
  const c = new DiagramController({
1087
1162
  viewport: viewport.current,
@@ -1098,21 +1173,22 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1098
1173
  ctl.current = null;
1099
1174
  };
1100
1175
  }, []);
1101
- (0, import_react.useLayoutEffect)(() => {
1102
- const el = stage.current?.querySelector("svg");
1103
- if (el) ctl.current?.mount(el, scoped, `${ownId.current}_`);
1104
- }, [scoped]);
1176
+ (0, import_react.useLayoutEffect)(() => ctl.current?.show(scoped, `${ownId}_`), [scoped, ownId]);
1105
1177
  (0, import_react.useEffect)(() => {
1106
1178
  const d = dialog.current;
1107
1179
  if (!d.open) d.showModal();
1108
1180
  if (locks++ === 0) document.documentElement.classList.add(LOCK_CLASS);
1109
1181
  viewport.current?.focus({ preventScroll: true });
1110
- 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
+ };
1111
1187
  document.addEventListener("fullscreenchange", sync);
1112
1188
  return () => {
1113
1189
  document.removeEventListener("fullscreenchange", sync);
1114
1190
  clearTimeout(toastTimer.current);
1115
- if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS);
1191
+ if (--locks === 0) document.documentElement.classList.remove(LOCK_CLASS, FULLSCREEN_CLASS);
1116
1192
  if (document.fullscreenElement && d.contains(document.fullscreenElement)) void document.exitFullscreen().catch(() => {
1117
1193
  });
1118
1194
  };
@@ -1156,7 +1232,7 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1156
1232
  const canCopyImage = typeof ClipboardItem !== "undefined" && Boolean(navigator.clipboard?.write);
1157
1233
  const canFullscreen = typeof document !== "undefined" && document.fullscreenEnabled;
1158
1234
  const status = !query.trim() ? "" : ui.matches === 0 ? labels.noMatch : fill(labels.matchOf, { n: Math.max(ui.current, 0) + 1, total: ui.matches });
1159
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1235
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1160
1236
  "dialog",
1161
1237
  {
1162
1238
  ref: dialog,
@@ -1166,20 +1242,20 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1166
1242
  onPointerDown: (e) => downOnBackdrop.current = e.target === dialog.current,
1167
1243
  onClick: (e) => e.target === dialog.current && downOnBackdrop.current && dialog.current?.close(),
1168
1244
  onKeyDown,
1169
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hv-shell", ref: shell, children: [
1170
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hv-bar", role: "toolbar", "aria-label": labels.viewer, children: [
1171
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "hv-title", children: title }),
1172
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("output", { className: "hv-zoom", ref: zoom, "aria-label": "zoom", children: "100%" }),
1173
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "hv-group", children: [
1174
- /* @__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" }),
1175
- /* @__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: "+" }),
1176
- /* @__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 }) }),
1177
- /* @__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%" })
1178
1254
  ] }),
1179
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "hv-group hv-find", children: [
1180
- /* @__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 }) }),
1181
- finding ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1182
- /* @__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)(
1183
1259
  "input",
1184
1260
  {
1185
1261
  ref: finder,
@@ -1195,37 +1271,37 @@ function DiagramViewer({ svg, svgId, source, title, labels, onClose }) {
1195
1271
  onKeyDown: onFindKey
1196
1272
  }
1197
1273
  ),
1198
- /* @__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 })
1199
1275
  ] }) : null
1200
1276
  ] }),
1201
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "hv-group hv-export", children: [
1202
- /* @__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" }),
1203
- /* @__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" }),
1204
- /* @__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" }),
1205
- /* @__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)) }),
1206
- 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
1207
1283
  ] }),
1208
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "hv-group hv-end", children: [
1209
- 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,
1210
- /* @__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 }) })
1211
1287
  ] })
1212
1288
  ] }),
1213
- /* @__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, dangerouslySetInnerHTML: html }) }),
1214
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("canvas", { className: "hv-mini", ref: minimap, width: 176, height: 120, hidden: !ui.minimap, "aria-hidden": "true" }),
1215
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hv-foot", children: [
1216
- ui.pinned ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", { className: "hv-legend", "aria-hidden": "true", children: [
1217
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "hv-sel", children: labels.legendSelected }),
1218
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: "hv-up", children: labels.legendUpstream }),
1219
- /* @__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 })
1220
1296
  ] }) : null,
1221
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "hv-hint", id: helpId, children: labels.hint }),
1222
- /* @__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 })
1223
1299
  ] })
1224
1300
  ] })
1225
1301
  }
1226
1302
  );
1227
1303
  }
1228
- 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;
1229
1305
  var init_diagram_viewer = __esm({
1230
1306
  "src/react/viewer/diagram-viewer.tsx"() {
1231
1307
  "use strict";
@@ -1234,18 +1310,19 @@ var init_diagram_viewer = __esm({
1234
1310
  init_export();
1235
1311
  init_labels();
1236
1312
  init_scope_svg();
1237
- import_jsx_runtime = require("react/jsx-runtime");
1313
+ import_jsx_runtime2 = require("react/jsx-runtime");
1238
1314
  sequence = 0;
1239
1315
  locks = 0;
1240
1316
  LOCK_CLASS = "hyle-viewer-lock";
1317
+ FULLSCREEN_CLASS = "hyle-viewer-fs";
1241
1318
  SCALES = ["1", "2", "4"];
1242
1319
  TOAST_MS = 4e3;
1243
- 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 }) });
1244
1321
  ICONS = {
1245
1322
  close: "m4 4 8 8M12 4l-8 8",
1246
1323
  fit: "M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10",
1247
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",
1248
- 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",
1249
1326
  exit: "M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"
1250
1327
  };
1251
1328
  }
@@ -1254,40 +1331,142 @@ var init_diagram_viewer = __esm({
1254
1331
  // src/react/mermaid-diagram.tsx
1255
1332
  var mermaid_diagram_exports = {};
1256
1333
  __export(mermaid_diagram_exports, {
1334
+ DiagramBoundary: () => DiagramBoundary,
1257
1335
  MermaidDiagram: () => MermaidDiagram
1258
1336
  });
1259
1337
  module.exports = __toCommonJS(mermaid_diagram_exports);
1260
1338
  var import_react2 = require("react");
1261
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
+
1262
1367
  // src/react/mermaid-config.ts
1263
- var MAX_MERMAID_SOURCE = 2e4;
1264
- function luminance(css) {
1265
- const m = /^(rgba?)\(([^)]*)\)$|^color\(srgb ([^)]*)\)$/.exec(css.trim());
1368
+ var MAX_MERMAID_SOURCE = 1024 * 1024;
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());
1266
1381
  if (!m) return void 0;
1267
- const parts = (m[2] ?? m[3] ?? "").split(/[\s,/]+/).filter(Boolean).map(Number);
1268
- const [r, g, b] = parts.map((v) => m[3] ? v : v / 255);
1269
- const alpha = parts[3] ?? 1;
1270
- if (r === void 0 || g === void 0 || b === void 0 || [r, g, b, alpha].some(Number.isNaN) || alpha < 0.5) return void 0;
1271
- 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;
1391
+ }
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";
1272
1395
  }
1273
- function pickMermaidTheme(background, prefersDark) {
1274
- const l = luminance(background);
1275
- return (l === void 0 ? prefersDark : l < 0.5) ? "dark" : "default";
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
+ };
1276
1411
  }
1277
1412
  var RENDER_TIMEOUT_MS = 1e4;
1278
1413
  var NEAR_VIEWPORT_MARGIN = "200px";
1279
- 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;
1280
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
+ }
1281
1426
  function stripMermaidConfig(source) {
1282
1427
  let text = source.replace(/\r\n?/g, "\n");
1283
- for (let previous = ""; previous !== text; ) {
1284
- previous = text;
1285
- 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;
1286
1432
  }
1287
- 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;
1288
1467
  }
1289
1468
  var counter = 0;
1290
- var nextMermaidId = () => `hyle-mermaid-${++counter}`;
1469
+ var nextMermaidId = () => `hyleMermaid-${++counter}`;
1291
1470
  function withTimeout(promise, ms) {
1292
1471
  let timer;
1293
1472
  const timeout = new Promise((_, reject) => {
@@ -1310,86 +1489,212 @@ function whenNearViewport(el, onNear, Observer = globalThis.IntersectionObserver
1310
1489
  observer.observe(el);
1311
1490
  return () => observer.disconnect();
1312
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
+ }
1313
1497
 
1314
1498
  // src/react/mermaid-diagram.tsx
1499
+ var import_print_coordinator = require("./print-coordinator.cjs");
1315
1500
  init_labels();
1316
- 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
+ };
1317
1512
  var queue = Promise.resolve();
1318
- async function renderSvg(id, source, theme) {
1513
+ var afterPaint = () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
1514
+ async function renderSvg(id, source, theme, onSvg, stillWanted) {
1319
1515
  const { default: mermaid } = await import("mermaid");
1320
- mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme, maxTextSize: MAX_MERMAID_SOURCE, suppressErrorRendering: true });
1321
- try {
1322
- return { markup: (await mermaid.render(id, stripMermaidConfig(source))).svg, id };
1323
- } finally {
1324
- document.getElementById(`d${id}`)?.remove();
1516
+ if (stillWanted) {
1517
+ await afterPaint();
1518
+ if (!stillWanted()) return;
1325
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);
1326
1523
  }
1327
- var THEME_ATTRS = ["data-act", "data-theme", "class"];
1328
- function MermaidDiagram({ source, title, errorText, labels = VIEWER_LABELS_EN }) {
1524
+ var noSubscription = () => () => {
1525
+ };
1526
+ function Diagram({ source, title, errorText, loadingText = "Rendering the diagram", labels = VIEWER_LABELS_EN }) {
1329
1527
  const figure = (0, import_react2.useRef)(null);
1330
1528
  const trigger = (0, import_react2.useRef)(null);
1331
1529
  const captionId = (0, import_react2.useId)();
1530
+ const sourceId = (0, import_react2.useId)();
1531
+ const live = (0, import_react2.useSyncExternalStore)(noSubscription, () => true, () => false);
1332
1532
  const [open, setOpen] = (0, import_react2.useState)(false);
1333
1533
  const [Viewer, setViewer] = (0, import_react2.useState)(null);
1534
+ const [viewerFailed, setViewerFailed] = (0, import_react2.useState)(false);
1334
1535
  const [theme, setTheme] = (0, import_react2.useState)(null);
1335
1536
  const [near, setNear] = (0, import_react2.useState)(false);
1336
1537
  const [svg, setSvg] = (0, import_react2.useState)(null);
1337
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, []);
1338
1548
  (0, import_react2.useEffect)(() => {
1339
- const scheme = window.matchMedia("(prefers-color-scheme: dark)");
1340
- const update = () => figure.current && setTheme(pickMermaidTheme(getComputedStyle(figure.current).backgroundColor, scheme.matches));
1341
- update();
1342
- const observer = new MutationObserver(update);
1343
- observer.observe(document.documentElement, { attributes: true, attributeFilter: THEME_ATTRS });
1344
- 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);
1345
1557
  return () => {
1346
- observer.disconnect();
1347
- scheme.removeEventListener("change", update);
1558
+ window.removeEventListener("beforeprint", draw2);
1559
+ toPrint.removeEventListener("change", onChange);
1348
1560
  };
1349
1561
  }, []);
1350
- (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]);
1351
1572
  (0, import_react2.useEffect)(() => {
1352
- if (theme === null || !near) return;
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;
1591
+ (0, import_react2.useEffect)(() => {
1592
+ if (theme === null || !wanted) return;
1353
1593
  let current = true;
1354
1594
  const id = nextMermaidId();
1355
- queue = queue.then(() => current ? withTimeout(renderSvg(id, source, theme), RENDER_TIMEOUT_MS) : void 0).then(
1356
- (out) => current && out !== void 0 && (setSvg(out), setFailed(false)),
1357
- () => current && setFailed(true)
1358
- );
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
+ });
1359
1603
  return () => {
1360
1604
  current = false;
1361
1605
  };
1362
- }, [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
+ };
1363
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
+ };
1364
1635
  const expand = (e) => {
1365
1636
  if (e.target.closest("a")) return;
1637
+ const selection = window.getSelection();
1638
+ if (selection && !selection.isCollapsed && figure.current?.contains(selection.anchorNode)) return;
1366
1639
  setOpen(true);
1367
- if (!Viewer) void Promise.resolve().then(() => (init_diagram_viewer(), diagram_viewer_exports)).then((m) => setViewer(() => m.DiagramViewer), () => setOpen(false));
1368
- };
1369
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", children: [
1370
- 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: [
1371
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-mermaid-svg", dangerouslySetInnerHTML: html }),
1372
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "hyle-mermaid-hint", "aria-hidden": "true", children: labels.expandHint })
1373
- ] }),
1374
- open && Viewer && svg ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1375
- Viewer,
1376
- {
1377
- svg: svg.markup,
1378
- svgId: svg.id,
1379
- source,
1380
- title,
1381
- labels,
1382
- 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
+ () => {
1383
1645
  setOpen(false);
1384
- trigger.current?.focus({ preventScroll: true });
1646
+ setViewerFailed(true);
1385
1647
  }
1386
- }
1387
- ) : null,
1388
- failed ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "hyle-mermaid-note", role: "status", children: errorText }) : null,
1389
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("figcaption", { id: svg ? captionId : void 0, className: "sr-only", children: title })
1390
- ] });
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 }) });
1391
1695
  }
1392
1696
  // Annotate the CommonJS export names for ESM import in node:
1393
1697
  0 && (module.exports = {
1698
+ DiagramBoundary,
1394
1699
  MermaidDiagram
1395
1700
  });