@tdacorp/hyle-sdk 0.17.0 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +261 -42
  2. package/dist/check-routes-bin.js +190 -53
  3. package/dist/{chunk-6VOHFFA5.js → chunk-7T5EEJHK.js} +2 -2
  4. package/dist/chunk-DUPT6XLB.js +57 -0
  5. package/dist/chunk-IW3TUD4G.js +841 -0
  6. package/dist/{chunk-MGSUQBDW.js → chunk-KU7LWK4E.js} +249 -24
  7. package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
  8. package/dist/chunk-SFFBZFEN.js +178 -0
  9. package/dist/chunk-U74B7AUG.js +398 -0
  10. package/dist/chunk-ZIW6FDU2.js +1126 -0
  11. package/dist/client-BGjmEWhN.d.cts +207 -0
  12. package/dist/client-D0LTpr3Y.d.ts +207 -0
  13. package/dist/code-copy.cjs +74 -0
  14. package/dist/code-copy.d.cts +18 -0
  15. package/dist/code-copy.d.ts +18 -0
  16. package/dist/code-copy.js +50 -0
  17. package/dist/comments.cjs +738 -280
  18. package/dist/comments.d.cts +66 -3
  19. package/dist/comments.d.ts +66 -3
  20. package/dist/comments.js +419 -331
  21. package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
  22. package/dist/docs-enhance.cjs +7 -4
  23. package/dist/docs-enhance.d.cts +5 -3
  24. package/dist/docs-enhance.d.ts +5 -3
  25. package/dist/docs-enhance.js +8 -5
  26. package/dist/{embed-DNTZ2UXv.d.ts → embed-CbtsbZs3.d.cts} +5 -3
  27. package/dist/{embed-BmdwA2G9.d.cts → embed-Cf_2ZR5x.d.ts} +5 -3
  28. package/dist/fragment-alias.cjs +51 -0
  29. package/dist/fragment-alias.d.cts +7 -0
  30. package/dist/fragment-alias.d.ts +7 -0
  31. package/dist/fragment-alias.js +27 -0
  32. package/dist/html.cjs +886 -0
  33. package/dist/html.d.cts +20 -0
  34. package/dist/html.d.ts +20 -0
  35. package/dist/html.js +45 -0
  36. package/dist/index.cjs +244 -24
  37. package/dist/index.d.cts +22 -68
  38. package/dist/index.d.ts +22 -68
  39. package/dist/index.js +12 -2
  40. package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.cts} +9 -0
  41. package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.ts} +9 -0
  42. package/dist/mermaid-diagram.cjs +441 -125
  43. package/dist/mermaid-diagram.d.cts +23 -7
  44. package/dist/mermaid-diagram.d.ts +23 -7
  45. package/dist/mermaid-diagram.js +213 -51
  46. package/dist/mermaid-image.cjs +137 -60
  47. package/dist/mermaid-image.d.cts +4 -3
  48. package/dist/mermaid-image.d.ts +4 -3
  49. package/dist/mermaid-image.js +27 -28
  50. package/dist/next.cjs +836 -304
  51. package/dist/next.d.cts +45 -20
  52. package/dist/next.d.ts +45 -20
  53. package/dist/next.js +151 -40
  54. package/dist/print-coordinator.cjs +157 -0
  55. package/dist/print-coordinator.d.cts +27 -0
  56. package/dist/print-coordinator.d.ts +27 -0
  57. package/dist/print-coordinator.js +83 -0
  58. package/dist/react.cjs +603 -240
  59. package/dist/react.d.cts +148 -30
  60. package/dist/react.d.ts +148 -30
  61. package/dist/react.js +26 -4
  62. package/dist/reactions.cjs +653 -0
  63. package/dist/reactions.d.cts +27 -0
  64. package/dist/reactions.d.ts +27 -0
  65. package/dist/reactions.js +364 -0
  66. package/dist/{resolve-euZ4-aC9.d.cts → resolve-BnIv7aB7.d.cts} +2 -2
  67. package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BysHtZ_i.d.ts} +2 -2
  68. package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
  69. package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
  70. package/dist/sanitize-BpY_AdZh.d.cts +23 -0
  71. package/dist/sanitize-BpY_AdZh.d.ts +23 -0
  72. package/dist/styles.css +100 -29
  73. package/dist/toc-spy.cjs +60 -0
  74. package/dist/toc-spy.d.cts +15 -0
  75. package/dist/toc-spy.d.ts +15 -0
  76. package/dist/toc-spy.js +36 -0
  77. package/dist/{types-Czt887Iv.d.cts → types-D09Z072G.d.cts} +57 -2
  78. package/dist/{types-Czt887Iv.d.ts → types-D09Z072G.d.ts} +57 -2
  79. package/dist/use-cache.cjs +89 -13
  80. package/dist/use-cache.d.cts +12 -5
  81. package/dist/use-cache.d.ts +12 -5
  82. package/dist/use-cache.js +8 -8
  83. package/dist/youtube-facade.cjs +50 -0
  84. package/dist/youtube-facade.d.cts +17 -0
  85. package/dist/youtube-facade.d.ts +17 -0
  86. package/dist/youtube-facade.js +26 -0
  87. package/package.json +16 -3
  88. package/dist/chunk-67IOIAVW.js +0 -35
  89. package/dist/chunk-DMK4XQLU.js +0 -1556
  90. package/dist/chunk-PJMJMP66.js +0 -63
  91. package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
  92. package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
@@ -1,10 +1,11 @@
1
1
  import * as react from 'react';
2
- import { V as ViewerLabels } from './labels-nmukKYgL.cjs';
2
+ import { Component, ReactNode } from 'react';
3
+ import { V as ViewerLabels } from './labels-CrA-iqTN.cjs';
3
4
 
4
5
  /**
5
- * The SDK's only client component. It receives the diagram text and presentational strings and nothing else: never a token,
6
- * base URL or client (a test pins this). Mermaid is a dynamic import, so the chunk loads only on pages that have a diagram,
7
- * from the host's own origin.
6
+ * Draws one diagram and opens it in the viewer on click. It receives the diagram text and presentational strings and nothing else:
7
+ * never a token, base URL or client (a test pins this). Mermaid is a dynamic import, so the chunk loads only on pages that draw a
8
+ * diagram, from the host's own origin; the viewer is another, fetched by the first click.
8
9
  */
9
10
  interface MermaidDiagramProps {
10
11
  source: string;
@@ -14,9 +15,24 @@ interface MermaidDiagramProps {
14
15
  errorText: string;
15
16
  /** Accessible name of the loader shown while the diagram renders (English when omitted). */
16
17
  loadingText?: string;
17
- /** Strings of the diagram viewer (English when omitted). */
18
+ /** Strings of the large-diagram notice, the print note and the diagram viewer (English when omitted). */
18
19
  labels?: ViewerLabels;
19
20
  }
20
- declare function MermaidDiagram({ source, title, errorText, loadingText, labels }: MermaidDiagramProps): react.JSX.Element;
21
+ /** A throw anywhere in a diagram (the viewer included) must not blank the page: fall back to the source, as without JavaScript. */
22
+ declare class DiagramBoundary extends Component<{
23
+ source: string;
24
+ children: ReactNode;
25
+ }, {
26
+ failed: boolean;
27
+ }> {
28
+ state: {
29
+ failed: boolean;
30
+ };
31
+ static getDerivedStateFromError(): {
32
+ failed: boolean;
33
+ };
34
+ render(): ReactNode;
35
+ }
36
+ declare function MermaidDiagram(props: MermaidDiagramProps): react.JSX.Element;
21
37
 
22
- export { MermaidDiagram, type MermaidDiagramProps };
38
+ export { DiagramBoundary, MermaidDiagram, type MermaidDiagramProps };
@@ -1,10 +1,11 @@
1
1
  import * as react from 'react';
2
- import { V as ViewerLabels } from './labels-nmukKYgL.js';
2
+ import { Component, ReactNode } from 'react';
3
+ import { V as ViewerLabels } from './labels-CrA-iqTN.js';
3
4
 
4
5
  /**
5
- * The SDK's only client component. It receives the diagram text and presentational strings and nothing else: never a token,
6
- * base URL or client (a test pins this). Mermaid is a dynamic import, so the chunk loads only on pages that have a diagram,
7
- * from the host's own origin.
6
+ * Draws one diagram and opens it in the viewer on click. It receives the diagram text and presentational strings and nothing else:
7
+ * never a token, base URL or client (a test pins this). Mermaid is a dynamic import, so the chunk loads only on pages that draw a
8
+ * diagram, from the host's own origin; the viewer is another, fetched by the first click.
8
9
  */
9
10
  interface MermaidDiagramProps {
10
11
  source: string;
@@ -14,9 +15,24 @@ interface MermaidDiagramProps {
14
15
  errorText: string;
15
16
  /** Accessible name of the loader shown while the diagram renders (English when omitted). */
16
17
  loadingText?: string;
17
- /** Strings of the diagram viewer (English when omitted). */
18
+ /** Strings of the large-diagram notice, the print note and the diagram viewer (English when omitted). */
18
19
  labels?: ViewerLabels;
19
20
  }
20
- declare function MermaidDiagram({ source, title, errorText, loadingText, labels }: MermaidDiagramProps): react.JSX.Element;
21
+ /** A throw anywhere in a diagram (the viewer included) must not blank the page: fall back to the source, as without JavaScript. */
22
+ declare class DiagramBoundary extends Component<{
23
+ source: string;
24
+ children: ReactNode;
25
+ }, {
26
+ failed: boolean;
27
+ }> {
28
+ state: {
29
+ failed: boolean;
30
+ };
31
+ static getDerivedStateFromError(): {
32
+ failed: boolean;
33
+ };
34
+ render(): ReactNode;
35
+ }
36
+ declare function MermaidDiagram(props: MermaidDiagramProps): react.JSX.Element;
21
37
 
22
- export { MermaidDiagram, type MermaidDiagramProps };
38
+ export { DiagramBoundary, MermaidDiagram, type MermaidDiagramProps };
@@ -1,97 +1,259 @@
1
1
  "use client";
2
2
  import {
3
+ DARK_VARIABLES,
3
4
  MAX_MERMAID_EDGES,
4
5
  MAX_MERMAID_SOURCE,
5
6
  RENDER_TIMEOUT_MS,
7
+ afterFullscreen,
8
+ diagramThemeVariables,
9
+ isClampedSource,
10
+ isLargeDiagram,
6
11
  nextMermaidId,
7
- pickMermaidTheme,
8
12
  stripMermaidConfig,
13
+ watchPageTheme,
9
14
  whenNearViewport,
10
15
  withTimeout
11
- } from "./chunk-PJMJMP66.js";
16
+ } from "./chunk-SFFBZFEN.js";
12
17
  import {
13
18
  VIEWER_LABELS_EN
14
- } from "./chunk-BUJFMR3M.js";
19
+ } from "./chunk-QVYQM5R2.js";
15
20
 
16
21
  // src/react/mermaid-diagram.tsx
17
- import { useEffect, useId, useMemo, useRef, useState } from "react";
18
- import { jsx, jsxs } from "react/jsx-runtime";
22
+ import { Component, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
23
+
24
+ // src/react/diagram-frame.tsx
25
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
26
+ function LargeDiagram({ source, sourceId, labels, errorText, live, drawing, busy, failed, clamped, showAll, onDraw, onToggle }) {
27
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
28
+ /* @__PURE__ */ jsxs("div", { className: "hyle-mermaid-gate", inert: !live, children: [
29
+ /* @__PURE__ */ jsxs("div", { className: "hyle-mermaid-gate-text", children: [
30
+ /* @__PURE__ */ jsx("p", { className: "hyle-mermaid-gate-title", children: labels.largeTitle }),
31
+ /* @__PURE__ */ jsx("p", { className: "hyle-mermaid-gate-body", children: labels.largeBody })
32
+ ] }),
33
+ /* @__PURE__ */ 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 }),
34
+ /* @__PURE__ */ jsx("span", { className: "sr-only", role: "status", children: drawing ? labels.drawingBody : failed ? errorText : "" }),
35
+ failed ? /* @__PURE__ */ jsx("p", { className: "hyle-mermaid-note", "aria-hidden": "true", children: errorText }) : null
36
+ ] }),
37
+ drawing ? (
38
+ // The status above speaks for it; this is what a sighted reader watches while the page is blocked.
39
+ /* @__PURE__ */ jsxs("div", { className: "hyle-mermaid-drawing", "aria-hidden": "true", children: [
40
+ /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-spinner" }),
41
+ /* @__PURE__ */ jsx("span", { children: labels.drawingBody })
42
+ ] })
43
+ ) : null,
44
+ /* @__PURE__ */ jsxs("div", { className: "hyle-mermaid-source", "data-drawing": drawing ? "" : void 0, "data-clamped": live && clamped && !showAll ? "" : void 0, children: [
45
+ /* @__PURE__ */ jsx("pre", { id: sourceId, tabIndex: 0, children: /* @__PURE__ */ jsx("code", { className: "language-mermaid", children: source }) }),
46
+ clamped ? /* @__PURE__ */ 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
47
+ ] })
48
+ ] });
49
+ }
50
+
51
+ // src/react/mermaid-diagram.tsx
52
+ import { installPrintShortcut, registerPrintTarget } from "./print-coordinator.js";
53
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
54
+ var DiagramBoundary = class extends Component {
55
+ state = { failed: false };
56
+ static getDerivedStateFromError() {
57
+ return { failed: true };
58
+ }
59
+ render() {
60
+ if (!this.state.failed) return this.props.children;
61
+ return /* @__PURE__ */ jsx2("figure", { className: "hyle-mermaid", children: /* @__PURE__ */ jsx2("pre", { tabIndex: 0, children: /* @__PURE__ */ jsx2("code", { className: "language-mermaid", children: this.props.source }) }) });
62
+ }
63
+ };
19
64
  var queue = Promise.resolve();
20
- async function renderSvg(id, source, theme) {
65
+ var afterPaint = () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
66
+ async function renderSvg(id, source, theme, colours, onSvg, stillWanted) {
21
67
  const { default: mermaid } = await import("mermaid");
22
- mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme, maxTextSize: MAX_MERMAID_SOURCE, maxEdges: MAX_MERMAID_EDGES, suppressErrorRendering: true });
23
- try {
24
- return { markup: (await mermaid.render(id, stripMermaidConfig(source))).svg, id };
25
- } finally {
26
- document.getElementById(`d${id}`)?.remove();
68
+ if (stillWanted) {
69
+ await afterPaint();
70
+ if (!stillWanted()) return;
27
71
  }
72
+ const look = colours ? { theme: "base", themeVariables: diagramThemeVariables(colours.split(" "), theme === "dark") } : { theme, ...theme === "dark" ? { themeVariables: DARK_VARIABLES } : {} };
73
+ mermaid.initialize({ startOnLoad: false, securityLevel: "strict", ...look, maxTextSize: MAX_MERMAID_SOURCE, maxEdges: MAX_MERMAID_EDGES, suppressErrorRendering: true });
74
+ const drawing = mermaid.render(id, stripMermaidConfig(source)).then((out) => onSvg({ markup: out.svg, id, theme })).finally(() => document.getElementById(`d${id}`)?.remove());
75
+ await withTimeout(drawing, RENDER_TIMEOUT_MS);
28
76
  }
29
- var THEME_ATTRS = ["data-act", "data-theme", "class"];
30
- function MermaidDiagram({ source, title, errorText, loadingText = "Rendering the diagram", labels = VIEWER_LABELS_EN }) {
77
+ var noSubscription = () => () => {
78
+ };
79
+ function Diagram({ source, title, errorText, loadingText = "Rendering the diagram", labels = VIEWER_LABELS_EN }) {
31
80
  const figure = useRef(null);
32
81
  const trigger = useRef(null);
33
82
  const captionId = useId();
83
+ const sourceId = useId();
84
+ const live = useSyncExternalStore(noSubscription, () => true, () => false);
34
85
  const [open, setOpen] = useState(false);
35
86
  const [Viewer, setViewer] = useState(null);
87
+ const [viewerFailed, setViewerFailed] = useState(false);
36
88
  const [theme, setTheme] = useState(null);
89
+ const [colours, setColours] = useState("");
37
90
  const [near, setNear] = useState(false);
38
91
  const [svg, setSvg] = useState(null);
39
92
  const [failed, setFailed] = useState(false);
93
+ const large = useMemo(() => isLargeDiagram(source), [source]);
94
+ const [asked, setAsked] = useState(false);
95
+ const [attempt, setAttempt] = useState(0);
96
+ const [showAll, setShowAll] = useState(false);
97
+ const refocus = useRef(false);
98
+ const allowed = !large || asked;
99
+ const clamped = large && isClampedSource(source);
40
100
  useEffect(() => {
41
- const scheme = window.matchMedia("(prefers-color-scheme: dark)");
42
- const update = () => figure.current && setTheme(pickMermaidTheme(getComputedStyle(figure.current).backgroundColor, scheme.matches));
43
- update();
44
- const observer = new MutationObserver(update);
45
- observer.observe(document.documentElement, { attributes: true, attributeFilter: THEME_ATTRS });
46
- scheme.addEventListener("change", update);
101
+ if (!figure.current) return void 0;
102
+ return watchPageTheme(figure.current, (next, themed) => {
103
+ setTheme(next);
104
+ setColours(themed);
105
+ });
106
+ }, []);
107
+ useEffect(() => figure.current ? whenNearViewport(figure.current, () => setNear(true)) : void 0, []);
108
+ useEffect(() => {
109
+ const toPrint = window.matchMedia("print");
110
+ const draw2 = () => setNear(true);
111
+ if (toPrint.matches) draw2();
112
+ const onChange = (e) => {
113
+ if (e.matches) draw2();
114
+ };
115
+ window.addEventListener("beforeprint", draw2);
116
+ toPrint.addEventListener("change", onChange);
47
117
  return () => {
48
- observer.disconnect();
49
- scheme.removeEventListener("change", update);
118
+ window.removeEventListener("beforeprint", draw2);
119
+ toPrint.removeEventListener("change", onChange);
50
120
  };
51
121
  }, []);
52
- useEffect(() => figure.current ? whenNearViewport(figure.current, () => setNear(true)) : void 0, []);
122
+ const settled = useRef(false);
123
+ const shown = useRef(false);
124
+ const allowedNow = useRef(allowed);
125
+ const waiters = useRef([]);
126
+ useEffect(() => {
127
+ allowedNow.current = allowed;
128
+ settled.current = svg !== null || failed || !allowed;
129
+ shown.current = svg !== null;
130
+ if (settled.current) waiters.current.splice(0).forEach((resolve) => resolve());
131
+ }, [svg, failed, allowed]);
132
+ useEffect(() => {
133
+ const pending = waiters.current;
134
+ const uninstall = installPrintShortcut();
135
+ const unregister = registerPrintTarget({
136
+ status: labels.printPreparing,
137
+ settled: () => settled.current,
138
+ prepare: () => allowedNow.current ? import("mermaid") : Promise.resolve(),
139
+ ensureDrawn: () => settled.current ? Promise.resolve() : new Promise((resolve) => {
140
+ pending.push(resolve);
141
+ setNear(true);
142
+ })
143
+ });
144
+ return () => {
145
+ unregister();
146
+ uninstall();
147
+ pending.splice(0).forEach((resolve) => resolve());
148
+ };
149
+ }, [labels.printPreparing]);
150
+ const wanted = near && allowed;
53
151
  useEffect(() => {
54
- if (theme === null || !near) return;
152
+ if (theme === null || !wanted) return;
55
153
  let current = true;
56
154
  const id = nextMermaidId();
57
- queue = queue.then(() => current ? withTimeout(renderSvg(id, source, theme), RENDER_TIMEOUT_MS) : void 0).then(
58
- (out) => current && out !== void 0 && (setSvg(out), setFailed(false)),
59
- () => current && setFailed(true)
60
- );
155
+ const show = (out) => {
156
+ if (!current) return;
157
+ setSvg(out);
158
+ setFailed(false);
159
+ };
160
+ queue = queue.then(() => current ? renderSvg(id, source, theme, colours, show, large && !shown.current ? () => current : void 0) : void 0).catch(() => {
161
+ if (current) setFailed(true);
162
+ });
61
163
  return () => {
62
164
  current = false;
63
165
  };
64
- }, [source, theme, near]);
166
+ }, [source, theme, colours, wanted, attempt, large]);
167
+ useEffect(() => {
168
+ if (!refocus.current || svg === null && !failed) return;
169
+ refocus.current = false;
170
+ const active = document.activeElement;
171
+ if (svg && (!active || active === document.body)) trigger.current?.focus({ preventScroll: true });
172
+ }, [svg, failed]);
173
+ const collapsed = useRef(null);
174
+ useLayoutEffect(() => {
175
+ collapsed.current?.scrollIntoView({ block: "nearest" });
176
+ collapsed.current = null;
177
+ }, [showAll]);
178
+ const toggleSource = (button) => {
179
+ collapsed.current = showAll ? button : null;
180
+ setShowAll(!showAll);
181
+ };
65
182
  const html = useMemo(() => svg ? { __html: svg.markup } : void 0, [svg]);
183
+ const drawing = wanted && svg === null && !failed;
184
+ const busy = asked && !failed;
185
+ const draw = () => {
186
+ if (busy) return;
187
+ refocus.current = true;
188
+ setAsked(true);
189
+ setNear(true);
190
+ if (failed) {
191
+ setFailed(false);
192
+ setAttempt((n) => n + 1);
193
+ }
194
+ };
66
195
  const expand = (e) => {
67
196
  if (e.target.closest("a")) return;
197
+ const selection = window.getSelection();
198
+ if (selection && !selection.isCollapsed && figure.current?.contains(selection.anchorNode)) return;
68
199
  setOpen(true);
69
- if (!Viewer) void import("./diagram-viewer-FJPED4SN.js").then((m) => setViewer(() => m.DiagramViewer), () => setOpen(false));
70
- };
71
- return /* @__PURE__ */ jsxs("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", ...svg === null && !failed ? { "data-state": "pending" } : {}, children: [
72
- near && svg === null && !failed ? /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-loader", role: "status", "aria-busy": "true", children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: loadingText }) }) : null,
73
- svg === null ? /* @__PURE__ */ jsx("pre", { tabIndex: 0, children: /* @__PURE__ */ jsx("code", { className: "language-mermaid", children: source }) }) : /* @__PURE__ */ jsxs("button", { ref: trigger, type: "button", className: "hyle-mermaid-open", "aria-label": labels.expand, "aria-describedby": captionId, "aria-haspopup": "dialog", onClick: expand, children: [
74
- /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-svg", dangerouslySetInnerHTML: html }),
75
- /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-hint", "aria-hidden": "true", children: labels.expandHint })
76
- ] }),
77
- open && Viewer && svg ? /* @__PURE__ */ jsx(
78
- Viewer,
79
- {
80
- svg: svg.markup,
81
- svgId: svg.id,
82
- source,
83
- title,
84
- labels,
85
- onClose: () => {
200
+ setViewerFailed(false);
201
+ if (!Viewer) {
202
+ void import("./diagram-viewer-XY3CG75U.js").then(
203
+ (m) => setViewer(() => m.DiagramViewer),
204
+ () => {
86
205
  setOpen(false);
87
- trigger.current?.focus({ preventScroll: true });
206
+ setViewerFailed(true);
88
207
  }
89
- }
90
- ) : null,
91
- failed ? /* @__PURE__ */ jsx("p", { className: "hyle-mermaid-note", role: "status", children: errorText }) : null,
92
- /* @__PURE__ */ jsx("figcaption", { id: svg ? captionId : void 0, className: "sr-only", children: title })
93
- ] });
208
+ );
209
+ }
210
+ };
211
+ return /* @__PURE__ */ jsxs2(
212
+ "figure",
213
+ {
214
+ ref: figure,
215
+ className: "hyle-mermaid",
216
+ "data-slot-component": "Mermaid",
217
+ "data-mermaid-theme": svg?.theme,
218
+ ...allowed && svg === null && !failed ? { "data-state": "pending" } : {},
219
+ ...!live && clamped ? { "data-clamp": "" } : {},
220
+ children: [
221
+ svg !== null ? (
222
+ // The whole diagram is a click target for the mouse; the button is the one control for keyboard and assistive technology, and its
223
+ // text ("Expand") is the start of its name. A diagram's own text must not be inside a button (axe label-content-name-mismatch).
224
+ /* @__PURE__ */ jsxs2("div", { className: "hyle-mermaid-open", role: "presentation", onClick: expand, children: [
225
+ /* @__PURE__ */ jsx2("span", { className: "hyle-mermaid-svg", dangerouslySetInnerHTML: html }),
226
+ /* @__PURE__ */ jsx2("button", { ref: trigger, type: "button", className: "hyle-mermaid-hint", "aria-label": labels.expand, "aria-describedby": captionId, "aria-haspopup": "dialog", children: labels.expandHint })
227
+ ] })
228
+ ) : large ? /* @__PURE__ */ jsx2(LargeDiagram, { source, sourceId, labels, errorText, live, drawing, busy, failed, clamped, showAll, onDraw: draw, onToggle: toggleSource }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
229
+ drawing ? /* @__PURE__ */ jsx2("span", { className: "hyle-mermaid-loader", role: "status", "aria-busy": "true", children: /* @__PURE__ */ jsx2("span", { className: "sr-only", children: loadingText }) }) : null,
230
+ /* @__PURE__ */ jsx2("pre", { tabIndex: 0, children: /* @__PURE__ */ jsx2("code", { className: "language-mermaid", children: source }) })
231
+ ] }),
232
+ open && Viewer && svg ? /* @__PURE__ */ jsx2(
233
+ Viewer,
234
+ {
235
+ svg: svg.markup,
236
+ svgId: svg.id,
237
+ source,
238
+ title,
239
+ labels,
240
+ onClose: () => afterFullscreen(figure.current, () => {
241
+ setOpen(false);
242
+ trigger.current?.focus({ preventScroll: true });
243
+ })
244
+ }
245
+ ) : null,
246
+ failed && (svg !== null || !large) ? /* @__PURE__ */ jsx2("p", { className: "hyle-mermaid-note", role: "status", children: errorText }) : null,
247
+ viewerFailed ? /* @__PURE__ */ jsx2("p", { className: "hyle-mermaid-note", role: "status", children: labels.unavailable }) : null,
248
+ /* @__PURE__ */ jsx2("figcaption", { id: svg ? captionId : void 0, className: "sr-only", children: title })
249
+ ]
250
+ }
251
+ );
252
+ }
253
+ function MermaidDiagram(props) {
254
+ return /* @__PURE__ */ jsx2(DiagramBoundary, { source: props.source, children: /* @__PURE__ */ jsx2(Diagram, { ...props }) });
94
255
  }
95
256
  export {
257
+ DiagramBoundary,
96
258
  MermaidDiagram
97
259
  };