@tdacorp/hyle-sdk 0.3.0 → 0.8.1

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 (38) hide show
  1. package/README.md +135 -5
  2. package/bin/hyle-sdk-check-routes.mjs +3 -0
  3. package/dist/check-routes-bin.js +537 -0
  4. package/dist/chunk-67IOIAVW.js +35 -0
  5. package/dist/chunk-BUJFMR3M.js +38 -0
  6. package/dist/chunk-EBNIKRQH.js +536 -0
  7. package/dist/{chunk-EARQBSMF.js → chunk-LGW2KP4X.js} +109 -5
  8. package/dist/{chunk-7VCMJUPC.js → chunk-N4QYPO7S.js} +1 -1
  9. package/dist/diagram-viewer-DYX6R63Y.js +1132 -0
  10. package/dist/index.cjs +279 -23
  11. package/dist/index.d.cts +147 -3
  12. package/dist/index.d.ts +147 -3
  13. package/dist/index.js +18 -1
  14. package/dist/mermaid-diagram.cjs +1267 -16
  15. package/dist/mermaid-diagram.d.cts +39 -1
  16. package/dist/mermaid-diagram.d.ts +39 -1
  17. package/dist/mermaid-diagram.js +35 -5
  18. package/dist/next.cjs +385 -30
  19. package/dist/next.d.cts +93 -5
  20. package/dist/next.d.ts +93 -5
  21. package/dist/next.js +210 -5
  22. package/dist/react.cjs +118 -5
  23. package/dist/react.d.cts +44 -4
  24. package/dist/react.d.ts +44 -4
  25. package/dist/react.js +2 -1
  26. package/dist/{resolve-fMx2W8RR.d.ts → resolve-1rQntRBh.d.ts} +1 -1
  27. package/dist/{resolve-B_p0p4Zn.d.cts → resolve-36-Ng1H0.d.cts} +1 -1
  28. package/dist/styles.css +76 -0
  29. package/dist/{types-CBvLhUPr.d.ts → types-BoyBWF2F.d.ts} +1 -1
  30. package/dist/{types-DjXf6iPo.d.cts → types-CwBCPh6K.d.cts} +20 -1
  31. package/dist/{types-DjXf6iPo.d.ts → types-CwBCPh6K.d.ts} +20 -1
  32. package/dist/{types-D0qoLh4E.d.cts → types-DnPzhrFx.d.cts} +1 -1
  33. package/dist/use-cache.cjs +55 -23
  34. package/dist/use-cache.d.cts +2 -2
  35. package/dist/use-cache.d.ts +2 -2
  36. package/dist/use-cache.js +3 -2
  37. package/package.json +5 -1
  38. package/dist/chunk-HFUJRNFP.js +0 -290
@@ -1,5 +1,41 @@
1
1
  import * as react from 'react';
2
2
 
3
+ /**
4
+ * Every string the diagram viewer shows. Pure data, so the client component can carry the English defaults without importing
5
+ * the viewer chunk, and the server passes the host's locale in (strings.ts holds fr and es, unreviewed drafts like the rest).
6
+ */
7
+ interface ViewerLabels {
8
+ expand: string;
9
+ expandHint: string;
10
+ viewer: string;
11
+ close: string;
12
+ zoomIn: string;
13
+ zoomOut: string;
14
+ fit: string;
15
+ actual: string;
16
+ search: string;
17
+ searchPlaceholder: string;
18
+ noMatch: string;
19
+ matchOf: string;
20
+ copySource: string;
21
+ downloadSvg: string;
22
+ downloadPng: string;
23
+ copyImage: string;
24
+ pngScale: string;
25
+ fullscreen: string;
26
+ exitFullscreen: string;
27
+ copied: string;
28
+ saved: string;
29
+ unavailable: string;
30
+ hint: string;
31
+ legendSelected: string;
32
+ legendUpstream: string;
33
+ legendDownstream: string;
34
+ outgoing: string;
35
+ tracing: string;
36
+ map: string;
37
+ }
38
+
3
39
  /**
4
40
  * The SDK's only client component. It receives the diagram text and presentational strings and nothing else: never a token,
5
41
  * base URL or client (a test pins this). Mermaid is a dynamic import, so the chunk loads only on pages that have a diagram,
@@ -11,7 +47,9 @@ interface MermaidDiagramProps {
11
47
  title: string;
12
48
  /** Shown when Mermaid cannot render the source. */
13
49
  errorText: string;
50
+ /** Strings of the diagram viewer (English when omitted). */
51
+ labels?: ViewerLabels;
14
52
  }
15
- declare function MermaidDiagram({ source, title, errorText }: MermaidDiagramProps): react.JSX.Element;
53
+ declare function MermaidDiagram({ source, title, errorText, labels }: MermaidDiagramProps): react.JSX.Element;
16
54
 
17
55
  export { MermaidDiagram, type MermaidDiagramProps };
@@ -1,5 +1,41 @@
1
1
  import * as react from 'react';
2
2
 
3
+ /**
4
+ * Every string the diagram viewer shows. Pure data, so the client component can carry the English defaults without importing
5
+ * the viewer chunk, and the server passes the host's locale in (strings.ts holds fr and es, unreviewed drafts like the rest).
6
+ */
7
+ interface ViewerLabels {
8
+ expand: string;
9
+ expandHint: string;
10
+ viewer: string;
11
+ close: string;
12
+ zoomIn: string;
13
+ zoomOut: string;
14
+ fit: string;
15
+ actual: string;
16
+ search: string;
17
+ searchPlaceholder: string;
18
+ noMatch: string;
19
+ matchOf: string;
20
+ copySource: string;
21
+ downloadSvg: string;
22
+ downloadPng: string;
23
+ copyImage: string;
24
+ pngScale: string;
25
+ fullscreen: string;
26
+ exitFullscreen: string;
27
+ copied: string;
28
+ saved: string;
29
+ unavailable: string;
30
+ hint: string;
31
+ legendSelected: string;
32
+ legendUpstream: string;
33
+ legendDownstream: string;
34
+ outgoing: string;
35
+ tracing: string;
36
+ map: string;
37
+ }
38
+
3
39
  /**
4
40
  * The SDK's only client component. It receives the diagram text and presentational strings and nothing else: never a token,
5
41
  * base URL or client (a test pins this). Mermaid is a dynamic import, so the chunk loads only on pages that have a diagram,
@@ -11,7 +47,9 @@ interface MermaidDiagramProps {
11
47
  title: string;
12
48
  /** Shown when Mermaid cannot render the source. */
13
49
  errorText: string;
50
+ /** Strings of the diagram viewer (English when omitted). */
51
+ labels?: ViewerLabels;
14
52
  }
15
- declare function MermaidDiagram({ source, title, errorText }: MermaidDiagramProps): react.JSX.Element;
53
+ declare function MermaidDiagram({ source, title, errorText, labels }: MermaidDiagramProps): react.JSX.Element;
16
54
 
17
55
  export { MermaidDiagram, type MermaidDiagramProps };
@@ -1,7 +1,10 @@
1
1
  "use client";
2
+ import {
3
+ VIEWER_LABELS_EN
4
+ } from "./chunk-BUJFMR3M.js";
2
5
 
3
6
  // src/react/mermaid-diagram.tsx
4
- import { useEffect, useRef, useState } from "react";
7
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
5
8
 
6
9
  // src/react/mermaid-config.ts
7
10
  var MAX_MERMAID_SOURCE = 2e4;
@@ -62,14 +65,18 @@ async function renderSvg(id, source, theme) {
62
65
  const { default: mermaid } = await import("mermaid");
63
66
  mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme, maxTextSize: MAX_MERMAID_SOURCE, suppressErrorRendering: true });
64
67
  try {
65
- return (await mermaid.render(id, stripMermaidConfig(source))).svg;
68
+ return { markup: (await mermaid.render(id, stripMermaidConfig(source))).svg, id };
66
69
  } finally {
67
70
  document.getElementById(`d${id}`)?.remove();
68
71
  }
69
72
  }
70
73
  var THEME_ATTRS = ["data-act", "data-theme", "class"];
71
- function MermaidDiagram({ source, title, errorText }) {
74
+ function MermaidDiagram({ source, title, errorText, labels = VIEWER_LABELS_EN }) {
72
75
  const figure = useRef(null);
76
+ const trigger = useRef(null);
77
+ const captionId = useId();
78
+ const [open, setOpen] = useState(false);
79
+ const [Viewer, setViewer] = useState(null);
73
80
  const [theme, setTheme] = useState(null);
74
81
  const [near, setNear] = useState(false);
75
82
  const [svg, setSvg] = useState(null);
@@ -99,10 +106,33 @@ function MermaidDiagram({ source, title, errorText }) {
99
106
  current = false;
100
107
  };
101
108
  }, [source, theme, near]);
109
+ const html = useMemo(() => svg ? { __html: svg.markup } : void 0, [svg]);
110
+ const expand = (e) => {
111
+ if (e.target.closest("a")) return;
112
+ setOpen(true);
113
+ if (!Viewer) void import("./diagram-viewer-DYX6R63Y.js").then((m) => setViewer(() => m.DiagramViewer), () => setOpen(false));
114
+ };
102
115
  return /* @__PURE__ */ jsxs("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", children: [
103
- svg === null ? /* @__PURE__ */ jsx("pre", { tabIndex: 0, children: /* @__PURE__ */ jsx("code", { className: "language-mermaid", children: source }) }) : /* @__PURE__ */ jsx("div", { className: "hyle-mermaid-svg", role: "img", "aria-label": title, dangerouslySetInnerHTML: { __html: svg } }),
116
+ 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: [
117
+ /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-svg", dangerouslySetInnerHTML: html }),
118
+ /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-hint", "aria-hidden": "true", children: labels.expandHint })
119
+ ] }),
120
+ open && Viewer && svg ? /* @__PURE__ */ jsx(
121
+ Viewer,
122
+ {
123
+ svg: svg.markup,
124
+ svgId: svg.id,
125
+ source,
126
+ title,
127
+ labels,
128
+ onClose: () => {
129
+ setOpen(false);
130
+ trigger.current?.focus({ preventScroll: true });
131
+ }
132
+ }
133
+ ) : null,
104
134
  failed ? /* @__PURE__ */ jsx("p", { className: "hyle-mermaid-note", role: "status", children: errorText }) : null,
105
- /* @__PURE__ */ jsx("figcaption", { className: "sr-only", children: title })
135
+ /* @__PURE__ */ jsx("figcaption", { id: svg ? captionId : void 0, className: "sr-only", children: title })
106
136
  ] });
107
137
  }
108
138
  export {