@tdacorp/hyle-sdk 0.14.1 → 0.17.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.
- package/README.md +20 -8
- package/dist/check-routes-bin.js +10 -8
- package/dist/{chunk-4V4VKB3O.js → chunk-DMK4XQLU.js} +470 -385
- package/dist/{chunk-R5EMI4HQ.js → chunk-PJMJMP66.js} +3 -1
- package/dist/comments.cjs +6 -4
- package/dist/comments.js +6 -5
- package/dist/{diagram-viewer-DYX6R63Y.js → diagram-viewer-FJPED4SN.js} +46 -26
- package/dist/{embed-B76zRRPa.d.cts → embed-BmdwA2G9.d.cts} +9 -4
- package/dist/{embed-SqOBGI-E.d.ts → embed-DNTZ2UXv.d.ts} +9 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/labels-nmukKYgL.d.cts +37 -0
- package/dist/labels-nmukKYgL.d.ts +37 -0
- package/dist/mermaid-diagram.cjs +59 -30
- package/dist/mermaid-diagram.d.cts +4 -37
- package/dist/mermaid-diagram.d.ts +4 -37
- package/dist/mermaid-diagram.js +7 -5
- package/dist/mermaid-image.cjs +1382 -0
- package/dist/mermaid-image.d.cts +29 -0
- package/dist/mermaid-image.d.ts +29 -0
- package/dist/mermaid-image.js +94 -0
- package/dist/next.cjs +1330 -1118
- package/dist/next.d.cts +61 -11
- package/dist/next.d.ts +61 -11
- package/dist/next.js +922 -793
- package/dist/react.cjs +267 -184
- package/dist/react.d.cts +29 -6
- package/dist/react.d.ts +29 -6
- package/dist/react.js +1 -1
- package/dist/{resolve-DC2ccfwA.d.ts → resolve-Ae7UFjsQ.d.ts} +1 -1
- package/dist/{resolve-DKLVftk_.d.cts → resolve-euZ4-aC9.d.cts} +1 -1
- package/dist/styles.css +11 -22
- package/dist/{types-ByodIyEv.d.cts → types-Czt887Iv.d.cts} +19 -3
- package/dist/{types-ByodIyEv.d.ts → types-Czt887Iv.d.ts} +19 -3
- package/dist/use-cache.d.cts +2 -2
- package/dist/use-cache.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { V as ViewerLabels } from './labels-nmukKYgL.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A diagram hyle already rendered (in the author's browser, sanitized and stored, ADR 0024): the reader gets a sized `<img>` and
|
|
6
|
+
* no layout runs in any browser. The source stays in the markup inside `<details>`, so crawlers and no-JS readers have it. Like
|
|
7
|
+
* MermaidDiagram it receives presentational values only, never a token or client; the SVG it fetches on click comes from the
|
|
8
|
+
* host's own same-origin asset route. If the image fails to load it falls back to MermaidDiagram.
|
|
9
|
+
*/
|
|
10
|
+
interface StoredRender {
|
|
11
|
+
src: string;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
interface MermaidImageProps {
|
|
16
|
+
source: string;
|
|
17
|
+
title: string;
|
|
18
|
+
errorText: string;
|
|
19
|
+
loadingText: string;
|
|
20
|
+
sourceLabel: string;
|
|
21
|
+
light: StoredRender;
|
|
22
|
+
dark: StoredRender;
|
|
23
|
+
labels?: ViewerLabels;
|
|
24
|
+
}
|
|
25
|
+
/** True when a fetched stored SVG still looks like what the server stores; the viewer inlines only those. */
|
|
26
|
+
declare function isSafeStoredSvg(svg: string): boolean;
|
|
27
|
+
declare function MermaidImage({ source, title, errorText, loadingText, sourceLabel, light, dark, labels }: MermaidImageProps): react.JSX.Element;
|
|
28
|
+
|
|
29
|
+
export { MermaidImage, type MermaidImageProps, type StoredRender, isSafeStoredSvg };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { V as ViewerLabels } from './labels-nmukKYgL.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A diagram hyle already rendered (in the author's browser, sanitized and stored, ADR 0024): the reader gets a sized `<img>` and
|
|
6
|
+
* no layout runs in any browser. The source stays in the markup inside `<details>`, so crawlers and no-JS readers have it. Like
|
|
7
|
+
* MermaidDiagram it receives presentational values only, never a token or client; the SVG it fetches on click comes from the
|
|
8
|
+
* host's own same-origin asset route. If the image fails to load it falls back to MermaidDiagram.
|
|
9
|
+
*/
|
|
10
|
+
interface StoredRender {
|
|
11
|
+
src: string;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
interface MermaidImageProps {
|
|
16
|
+
source: string;
|
|
17
|
+
title: string;
|
|
18
|
+
errorText: string;
|
|
19
|
+
loadingText: string;
|
|
20
|
+
sourceLabel: string;
|
|
21
|
+
light: StoredRender;
|
|
22
|
+
dark: StoredRender;
|
|
23
|
+
labels?: ViewerLabels;
|
|
24
|
+
}
|
|
25
|
+
/** True when a fetched stored SVG still looks like what the server stores; the viewer inlines only those. */
|
|
26
|
+
declare function isSafeStoredSvg(svg: string): boolean;
|
|
27
|
+
declare function MermaidImage({ source, title, errorText, loadingText, sourceLabel, light, dark, labels }: MermaidImageProps): react.JSX.Element;
|
|
28
|
+
|
|
29
|
+
export { MermaidImage, type MermaidImageProps, type StoredRender, isSafeStoredSvg };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
pickMermaidTheme
|
|
4
|
+
} from "./chunk-PJMJMP66.js";
|
|
5
|
+
import {
|
|
6
|
+
VIEWER_LABELS_EN
|
|
7
|
+
} from "./chunk-BUJFMR3M.js";
|
|
8
|
+
|
|
9
|
+
// src/react/mermaid-image.tsx
|
|
10
|
+
import { useEffect, useRef, useState } from "react";
|
|
11
|
+
import { MermaidDiagram } from "./mermaid-diagram.js";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
var FORBIDDEN_IN_SVG = /<script|<foreignObject|\son\w+\s*=|javascript:/i;
|
|
14
|
+
var BAD_CSS = /\\|@(?!keyframes\b)|expression|-moz-binding|behavior|-webkit-image-set|(?:src|image|image-set|cross-fade|element|paint)\(|url\((?!\s*['"]?\s*#)/i;
|
|
15
|
+
function isSafeStoredSvg(svg) {
|
|
16
|
+
if (FORBIDDEN_IN_SVG.test(svg)) return false;
|
|
17
|
+
for (const m of svg.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>|\s[\w:-]+="([^"]*)"/g)) if (BAD_CSS.test(m[1] ?? m[2] ?? "")) return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
function MermaidImage({ source, title, errorText, loadingText, sourceLabel, light, dark, labels = VIEWER_LABELS_EN }) {
|
|
21
|
+
const figure = useRef(null);
|
|
22
|
+
const img = useRef(null);
|
|
23
|
+
const trigger = useRef(null);
|
|
24
|
+
const [theme, setTheme] = useState(null);
|
|
25
|
+
const [pending, setPending] = useState(false);
|
|
26
|
+
const [failed, setFailed] = useState(false);
|
|
27
|
+
const [view, setView] = useState(null);
|
|
28
|
+
const [Viewer, setViewer] = useState(null);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const scheme = window.matchMedia("(prefers-color-scheme: dark)");
|
|
31
|
+
const update = () => figure.current && setTheme(pickMermaidTheme(getComputedStyle(figure.current).backgroundColor, scheme.matches));
|
|
32
|
+
update();
|
|
33
|
+
const observer = new MutationObserver(update);
|
|
34
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-act", "data-theme", "class"] });
|
|
35
|
+
scheme.addEventListener("change", update);
|
|
36
|
+
return () => {
|
|
37
|
+
observer.disconnect();
|
|
38
|
+
scheme.removeEventListener("change", update);
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const el = img.current;
|
|
43
|
+
if (!el?.complete) setPending(true);
|
|
44
|
+
else if (el.naturalWidth === 0) setFailed(true);
|
|
45
|
+
}, []);
|
|
46
|
+
if (failed) return /* @__PURE__ */ jsx(MermaidDiagram, { source, title, errorText, loadingText, labels });
|
|
47
|
+
const active = theme === "dark" ? dark : light;
|
|
48
|
+
const expand = async (e) => {
|
|
49
|
+
if (e.target.closest("a")) return;
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(active.src);
|
|
52
|
+
const svg = response.ok ? await response.text() : "";
|
|
53
|
+
const id = /^\s*<svg\b[^>]*?\sid="([\w-]+)"/.exec(svg)?.[1];
|
|
54
|
+
if (!id || !isSafeStoredSvg(svg)) return;
|
|
55
|
+
const { DiagramViewer } = await import("./diagram-viewer-FJPED4SN.js");
|
|
56
|
+
setViewer(() => DiagramViewer);
|
|
57
|
+
setView({ svg, id });
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return /* @__PURE__ */ jsxs("figure", { ref: figure, className: "hyle-mermaid", "data-slot-component": "Mermaid", children: [
|
|
62
|
+
/* @__PURE__ */ jsx("button", { ref: trigger, type: "button", className: "hyle-mermaid-open", "aria-label": labels.expand, "aria-haspopup": "dialog", onClick: expand, children: /* @__PURE__ */ jsxs("span", { className: "hyle-mermaid-frame", style: { aspectRatio: `${active.width} / ${active.height}`, maxWidth: active.width }, children: [
|
|
63
|
+
pending ? /* @__PURE__ */ jsx("span", { className: "hyle-mermaid-loader", role: "status", "aria-busy": "true", children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: loadingText }) }) : null,
|
|
64
|
+
/* @__PURE__ */ jsxs("picture", { children: [
|
|
65
|
+
/* @__PURE__ */ jsx("source", { srcSet: dark.src, media: theme === null ? "(prefers-color-scheme: dark)" : theme === "dark" ? "all" : "not all" }),
|
|
66
|
+
/* @__PURE__ */ jsx("img", { ref: img, src: light.src, alt: title, width: light.width, height: light.height, decoding: "async", loading: "lazy", onLoad: () => setPending(false), onError: () => setFailed(true) })
|
|
67
|
+
] }),
|
|
68
|
+
/* @__PURE__ */ jsx("span", { className: "hyle-mermaid-hint", "aria-hidden": "true", children: labels.expandHint })
|
|
69
|
+
] }) }),
|
|
70
|
+
/* @__PURE__ */ jsxs("details", { className: "hyle-mermaid-source", children: [
|
|
71
|
+
/* @__PURE__ */ jsx("summary", { children: sourceLabel }),
|
|
72
|
+
/* @__PURE__ */ jsx("pre", { tabIndex: 0, children: /* @__PURE__ */ jsx("code", { className: "language-mermaid", children: source }) })
|
|
73
|
+
] }),
|
|
74
|
+
view && Viewer ? /* @__PURE__ */ jsx(
|
|
75
|
+
Viewer,
|
|
76
|
+
{
|
|
77
|
+
svg: view.svg,
|
|
78
|
+
svgId: view.id,
|
|
79
|
+
source,
|
|
80
|
+
title,
|
|
81
|
+
labels,
|
|
82
|
+
onClose: () => {
|
|
83
|
+
setView(null);
|
|
84
|
+
trigger.current?.focus({ preventScroll: true });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
) : null,
|
|
88
|
+
/* @__PURE__ */ jsx("figcaption", { className: "sr-only", children: title })
|
|
89
|
+
] });
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
MermaidImage,
|
|
93
|
+
isSafeStoredSvg
|
|
94
|
+
};
|