@lobehub/ui 6.2.0 → 6.4.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/es/Mermaid/SyntaxMermaid/MermaidSvg.mjs +2 -3
- package/es/Mermaid/SyntaxMermaid/MermaidSvg.mjs.map +1 -1
- package/es/Mermaid/SyntaxMermaid/StaticMermaid.mjs +3 -1
- package/es/Mermaid/SyntaxMermaid/StaticMermaid.mjs.map +1 -1
- package/es/Mermaid/SyntaxMermaid/StreamMermaid.mjs +3 -4
- package/es/Mermaid/SyntaxMermaid/StreamMermaid.mjs.map +1 -1
- package/es/Mermaid/SyntaxMermaid/index.mjs +1 -1
- package/es/Mermaid/SyntaxMermaid/index.mjs.map +1 -1
- package/es/Mermaid/SyntaxMermaid/standaloneSvg.mjs +32 -0
- package/es/Mermaid/SyntaxMermaid/standaloneSvg.mjs.map +1 -0
- package/es/Mermaid/const.mjs +2 -2
- package/es/Mermaid/const.mjs.map +1 -1
- package/es/Mermaid/index.d.mts +13 -2
- package/es/Mermaid/index.mjs +12 -1
- package/es/Mermaid/index.mjs.map +1 -0
- package/es/Mermaid/themes.d.mts +107 -0
- package/es/Mermaid/themes.mjs +149 -0
- package/es/Mermaid/themes.mjs.map +1 -0
- package/es/Mermaid/type.d.mts +2 -2
- package/es/Text/style.d.mts +2 -2
- package/es/ToggleGroup/ToggleGroup.d.mts +1 -1
- package/es/ToggleGroup/ToggleGroup.mjs +18 -9
- package/es/ToggleGroup/ToggleGroup.mjs.map +1 -1
- package/es/ToggleGroup/atoms.mjs +16 -4
- package/es/ToggleGroup/atoms.mjs.map +1 -1
- package/es/ToggleGroup/style.d.mts +36 -2
- package/es/ToggleGroup/style.mjs +42 -2
- package/es/ToggleGroup/style.mjs.map +1 -1
- package/es/ToggleGroup/type.d.mts +21 -5
- package/es/eslint/index.d.mts +1 -1
- package/es/hooks/useMermaid.mjs +21 -82
- package/es/hooks/useMermaid.mjs.map +1 -1
- package/es/hooks/useStreamMermaid.mjs +22 -16
- package/es/hooks/useStreamMermaid.mjs.map +1 -1
- package/es/node_modules/.pnpm/{eslint@10.12.0_jiti@2.6.1_supports-color@10.2.2 → eslint@10.13.0_jiti@2.6.1_supports-color@10.2.2}/node_modules/eslint/lib/types/index.d.mts +1 -1
- package/es/style.css +6 -5
- package/package.json +2 -2
- package/es/Mermaid/SyntaxMermaid/prepareInlineSvg.mjs +0 -54
- package/es/Mermaid/SyntaxMermaid/prepareInlineSvg.mjs.map +0 -1
- package/es/Mermaid/SyntaxMermaid/prepareMermaidSvg.mjs +0 -20
- package/es/Mermaid/SyntaxMermaid/prepareMermaidSvg.mjs.map +0 -1
- package/es/hooks/useMermaidCdn.d.mts +0 -9
- package/es/hooks/useMermaidCdn.mjs +0 -97
- package/es/hooks/useMermaidCdn.mjs.map +0 -1
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//#region src/Mermaid/SyntaxMermaid/prepareInlineSvg.ts
|
|
2
|
-
/**
|
|
3
|
-
* Root custom properties beautiful-mermaid reads; everything else in its
|
|
4
|
-
* stylesheet is derived from these via color-mix().
|
|
5
|
-
*/
|
|
6
|
-
const MERMAID_ROOT_VARS = [
|
|
7
|
-
"--bg",
|
|
8
|
-
"--fg",
|
|
9
|
-
"--line",
|
|
10
|
-
"--accent",
|
|
11
|
-
"--muted",
|
|
12
|
-
"--surface",
|
|
13
|
-
"--border"
|
|
14
|
-
];
|
|
15
|
-
const styleBlockPattern = /<style>([\s\S]*?)<\/style>/;
|
|
16
|
-
const scopeCssSelectors = (css, scope) => css.replaceAll(/(^|})([^{}@]+)\{/g, (_match, tail, selectors) => {
|
|
17
|
-
return `${tail}\n${selectors.split(",").map((selector) => selector.trim()).filter(Boolean).map((selector) => selector === "svg" ? scope : `${scope} ${selector}`).join(", ")} {`;
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* A <style> element inside inline SVG applies to the whole document, so the
|
|
21
|
-
* generated rules must be scoped to this diagram before being injected. The
|
|
22
|
-
* font @import is dropped because inline rendering would actually issue the
|
|
23
|
-
* Google Fonts request that an <img>-loaded SVG silently blocks, and the bare
|
|
24
|
-
* `text` rule is dropped so page CSS can supply the theme font instead.
|
|
25
|
-
*/
|
|
26
|
-
const prepareInlineMermaidSvg = (svg, scopeId) => {
|
|
27
|
-
if (!svg) return svg;
|
|
28
|
-
return svg.replace(/<svg\b/, `<svg id="${scopeId}"`).replace(styleBlockPattern, (_match, css) => {
|
|
29
|
-
const withoutFontRule = css.replaceAll(/@import[^;]*;/g, "").replaceAll(/(^|})\s*text\s*\{[^{}]*\}/g, "$1");
|
|
30
|
-
return `<style>${scopeCssSelectors(withoutFontRule, `#${scopeId}`)}</style>`;
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Inline SVG resolves `var(--lobe-*)` from the page, but a Blob-loaded copy is an
|
|
35
|
-
* isolated document with no access to them, so the root variables are baked in
|
|
36
|
-
* as literal values before serializing for preview or download.
|
|
37
|
-
*/
|
|
38
|
-
const toStandaloneSvgString = (element) => {
|
|
39
|
-
const clone = element.cloneNode(true);
|
|
40
|
-
const computed = globalThis.getComputedStyle(element);
|
|
41
|
-
for (const name of MERMAID_ROOT_VARS) {
|
|
42
|
-
const value = computed.getPropertyValue(name).trim();
|
|
43
|
-
if (value) clone.style.setProperty(name, value);
|
|
44
|
-
}
|
|
45
|
-
const background = computed.getPropertyValue("--bg").trim();
|
|
46
|
-
if (background) clone.style.setProperty("background", background);
|
|
47
|
-
const fontFamily = computed.fontFamily;
|
|
48
|
-
if (fontFamily) clone.style.setProperty("font-family", fontFamily);
|
|
49
|
-
return new XMLSerializer().serializeToString(clone);
|
|
50
|
-
};
|
|
51
|
-
//#endregion
|
|
52
|
-
export { MERMAID_ROOT_VARS, prepareInlineMermaidSvg, toStandaloneSvgString };
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=prepareInlineSvg.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepareInlineSvg.mjs","names":[],"sources":["../../../src/Mermaid/SyntaxMermaid/prepareInlineSvg.ts"],"sourcesContent":["/**\n * Root custom properties beautiful-mermaid reads; everything else in its\n * stylesheet is derived from these via color-mix().\n */\nexport const MERMAID_ROOT_VARS = [\n '--bg',\n '--fg',\n '--line',\n '--accent',\n '--muted',\n '--surface',\n '--border',\n];\n\nconst styleBlockPattern = /<style>([\\s\\S]*?)<\\/style>/;\n\nconst scopeCssSelectors = (css: string, scope: string): string =>\n css.replaceAll(/(^|})([^{}@]+)\\{/g, (_match, tail: string, selectors: string) => {\n const scoped = selectors\n .split(',')\n .map((selector) => selector.trim())\n .filter(Boolean)\n // The generated sheet targets `svg` for the root itself, not a descendant\n .map((selector) => (selector === 'svg' ? scope : `${scope} ${selector}`))\n .join(', ');\n\n return `${tail}\\n${scoped} {`;\n });\n\n/**\n * A <style> element inside inline SVG applies to the whole document, so the\n * generated rules must be scoped to this diagram before being injected. The\n * font @import is dropped because inline rendering would actually issue the\n * Google Fonts request that an <img>-loaded SVG silently blocks, and the bare\n * `text` rule is dropped so page CSS can supply the theme font instead.\n */\nexport const prepareInlineMermaidSvg = (svg: string, scopeId: string): string => {\n if (!svg) return svg;\n\n const withId = svg.replace(/<svg\\b/, `<svg id=\"${scopeId}\"`);\n\n return withId.replace(styleBlockPattern, (_match, css: string) => {\n const withoutImports = css.replaceAll(/@import[^;]*;/g, '');\n const withoutFontRule = withoutImports.replaceAll(/(^|})\\s*text\\s*\\{[^{}]*\\}/g, '$1');\n\n return `<style>${scopeCssSelectors(withoutFontRule, `#${scopeId}`)}</style>`;\n });\n};\n\n/**\n * Inline SVG resolves `var(--lobe-*)` from the page, but a Blob-loaded copy is an\n * isolated document with no access to them, so the root variables are baked in\n * as literal values before serializing for preview or download.\n */\nexport const toStandaloneSvgString = (element: SVGElement): string => {\n const clone = element.cloneNode(true) as SVGElement;\n const computed = globalThis.getComputedStyle(element);\n\n for (const name of MERMAID_ROOT_VARS) {\n const value = computed.getPropertyValue(name).trim();\n if (value) clone.style.setProperty(name, value);\n }\n\n // The diagram is rendered transparent so it inherits the page surface, but a\n // standalone copy has nothing behind it: without an explicit fill the viewer\n // scrim (and whatever it lets through) shows straight through the diagram.\n const background = computed.getPropertyValue('--bg').trim();\n if (background) clone.style.setProperty('background', background);\n\n const fontFamily = computed.fontFamily;\n if (fontFamily) clone.style.setProperty('font-family', fontFamily);\n\n return new XMLSerializer().serializeToString(clone);\n};\n"],"mappings":";;;;;AAIA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,oBAAoB;AAE1B,MAAM,qBAAqB,KAAa,UACtC,IAAI,WAAW,sBAAsB,QAAQ,MAAc,cAAsB;CAS/E,OAAO,GAAG,KAAK,IARA,UACZ,MAAM,GAAG,CAAC,CACV,KAAK,aAAa,SAAS,KAAK,CAAC,CAAC,CAClC,OAAO,OAAO,CAAC,CAEf,KAAK,aAAc,aAAa,QAAQ,QAAQ,GAAG,MAAM,GAAG,UAAW,CAAC,CACxE,KAAK,IAEgB,EAAE;AAC5B,CAAC;;;;;;;;AASH,MAAa,2BAA2B,KAAa,YAA4B;CAC/E,IAAI,CAAC,KAAK,OAAO;CAIjB,OAFe,IAAI,QAAQ,UAAU,YAAY,QAAQ,EAE7C,CAAC,CAAC,QAAQ,oBAAoB,QAAQ,QAAgB;EAEhE,MAAM,kBADiB,IAAI,WAAW,kBAAkB,EACnB,CAAC,CAAC,WAAW,8BAA8B,IAAI;EAEpF,OAAO,UAAU,kBAAkB,iBAAiB,IAAI,SAAS,EAAE;CACrE,CAAC;AACH;;;;;;AAOA,MAAa,yBAAyB,YAAgC;CACpE,MAAM,QAAQ,QAAQ,UAAU,IAAI;CACpC,MAAM,WAAW,WAAW,iBAAiB,OAAO;CAEpD,KAAK,MAAM,QAAQ,mBAAmB;EACpC,MAAM,QAAQ,SAAS,iBAAiB,IAAI,CAAC,CAAC,KAAK;EACnD,IAAI,OAAO,MAAM,MAAM,YAAY,MAAM,KAAK;CAChD;CAKA,MAAM,aAAa,SAAS,iBAAiB,MAAM,CAAC,CAAC,KAAK;CAC1D,IAAI,YAAY,MAAM,MAAM,YAAY,cAAc,UAAU;CAEhE,MAAM,aAAa,SAAS;CAC5B,IAAI,YAAY,MAAM,MAAM,YAAY,eAAe,UAAU;CAEjE,OAAO,IAAI,cAAc,CAAC,CAAC,kBAAkB,KAAK;AACpD"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/Mermaid/SyntaxMermaid/prepareMermaidSvg.ts
|
|
2
|
-
const voidElementPattern = new RegExp(`<(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)((?:\\s[^>]*?)?)\\s*/?>`, "gi");
|
|
3
|
-
const ensureXmlSafeVoidElements = (svg) => svg.replaceAll(voidElementPattern, "<$1$2/>");
|
|
4
|
-
const applyFirefoxSizeFix = (svg) => {
|
|
5
|
-
if (typeof window === "undefined" || typeof navigator === "undefined" || !navigator.userAgent.includes("Firefox") || typeof DOMParser === "undefined") return svg;
|
|
6
|
-
const svgDoc = new DOMParser().parseFromString(svg, "image/svg+xml");
|
|
7
|
-
if (svgDoc.querySelector("parsererror")) return svg;
|
|
8
|
-
const svgElement = svgDoc.documentElement;
|
|
9
|
-
if (!svgElement || svgElement.localName !== "svg" || !svgElement.hasAttribute("viewBox")) return svg;
|
|
10
|
-
const viewBoxParts = svgElement.getAttribute("viewBox").split(" ");
|
|
11
|
-
if (viewBoxParts.length !== 4) return svg;
|
|
12
|
-
svgElement.setAttribute("width", viewBoxParts[2]);
|
|
13
|
-
svgElement.setAttribute("height", viewBoxParts[3]);
|
|
14
|
-
return new XMLSerializer().serializeToString(svgDoc);
|
|
15
|
-
};
|
|
16
|
-
const prepareMermaidSvgString = (svg) => applyFirefoxSizeFix(ensureXmlSafeVoidElements(svg));
|
|
17
|
-
//#endregion
|
|
18
|
-
export { prepareMermaidSvgString };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=prepareMermaidSvg.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepareMermaidSvg.mjs","names":[],"sources":["../../../src/Mermaid/SyntaxMermaid/prepareMermaidSvg.ts"],"sourcesContent":["const VOID_ELEMENTS = 'area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr';\nconst voidElementPattern = new RegExp(`<(${VOID_ELEMENTS})((?:\\\\s[^>]*?)?)\\\\s*/?>`, 'gi');\n\n// Mermaid serializes HTML labels (foreignObject) with HTML rules, leaving void elements\n// like <br> unclosed. When that SVG string is loaded as a standalone image/svg+xml Blob,\n// the browser parses it as strict XML, rejects the unclosed tag, and fails the whole image.\nconst ensureXmlSafeVoidElements = (svg: string): string =>\n svg.replaceAll(voidElementPattern, '<$1$2/>');\n\nconst applyFirefoxSizeFix = (svg: string): string => {\n if (\n typeof window === 'undefined' ||\n typeof navigator === 'undefined' ||\n !navigator.userAgent.includes('Firefox') ||\n typeof DOMParser === 'undefined'\n ) {\n return svg;\n }\n\n const svgDoc = new DOMParser().parseFromString(svg, 'image/svg+xml');\n if (svgDoc.querySelector('parsererror')) return svg;\n\n const svgElement = svgDoc.documentElement;\n if (!svgElement || svgElement.localName !== 'svg' || !svgElement.hasAttribute('viewBox')) {\n return svg;\n }\n\n const viewBoxParts = svgElement.getAttribute('viewBox')!.split(' ');\n if (viewBoxParts.length !== 4) return svg;\n\n svgElement.setAttribute('width', viewBoxParts[2]!);\n svgElement.setAttribute('height', viewBoxParts[3]!);\n return new XMLSerializer().serializeToString(svgDoc);\n};\n\nexport const prepareMermaidSvgString = (svg: string): string =>\n applyFirefoxSizeFix(ensureXmlSafeVoidElements(svg));\n"],"mappings":";AACA,MAAM,qBAAqB,IAAI,OAAO,kGAA8C,IAAI;AAKxF,MAAM,6BAA6B,QACjC,IAAI,WAAW,oBAAoB,SAAS;AAE9C,MAAM,uBAAuB,QAAwB;CACnD,IACE,OAAO,WAAW,eAClB,OAAO,cAAc,eACrB,CAAC,UAAU,UAAU,SAAS,SAAS,KACvC,OAAO,cAAc,aAErB,OAAO;CAGT,MAAM,SAAS,IAAI,UAAU,CAAC,CAAC,gBAAgB,KAAK,eAAe;CACnE,IAAI,OAAO,cAAc,aAAa,GAAG,OAAO;CAEhD,MAAM,aAAa,OAAO;CAC1B,IAAI,CAAC,cAAc,WAAW,cAAc,SAAS,CAAC,WAAW,aAAa,SAAS,GACrF,OAAO;CAGT,MAAM,eAAe,WAAW,aAAa,SAAS,CAAC,CAAE,MAAM,GAAG;CAClE,IAAI,aAAa,WAAW,GAAG,OAAO;CAEtC,WAAW,aAAa,SAAS,aAAa,EAAG;CACjD,WAAW,aAAa,UAAU,aAAa,EAAG;CAClD,OAAO,IAAI,cAAc,CAAC,CAAC,kBAAkB,MAAM;AACrD;AAEA,MAAa,2BAA2B,QACtC,oBAAoB,0BAA0B,GAAG,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
//#region src/hooks/useMermaidCdn.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Point the fallback loader at a mirror, or at a self-hosted copy for offline
|
|
4
|
-
* and strict-CSP deployments. Resets any in-flight load.
|
|
5
|
-
*/
|
|
6
|
-
export declare const setMermaidCdnUrl: (url: string) => void;
|
|
7
|
-
export declare const getMermaidCdnUrl: () => string;
|
|
8
|
-
//#endregion
|
|
9
|
-
//# sourceMappingURL=useMermaidCdn.d.mts.map
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
//#region src/hooks/useMermaidCdn.ts
|
|
3
|
-
let mermaidCdnUrl = "https://esm.sh/mermaid@11";
|
|
4
|
-
let mermaidPromise = null;
|
|
5
|
-
/**
|
|
6
|
-
* Point the fallback loader at a mirror, or at a self-hosted copy for offline
|
|
7
|
-
* and strict-CSP deployments. Resets any in-flight load.
|
|
8
|
-
*/
|
|
9
|
-
const setMermaidCdnUrl = (url) => {
|
|
10
|
-
if (url === mermaidCdnUrl) return;
|
|
11
|
-
mermaidCdnUrl = url;
|
|
12
|
-
mermaidPromise = null;
|
|
13
|
-
};
|
|
14
|
-
const getMermaidCdnUrl = () => mermaidCdnUrl;
|
|
15
|
-
const loadCdnMermaid = () => {
|
|
16
|
-
if (typeof window === "undefined") return Promise.resolve(null);
|
|
17
|
-
mermaidPromise ??= import(
|
|
18
|
-
/* @vite-ignore */
|
|
19
|
-
mermaidCdnUrl
|
|
20
|
-
).then((mod) => mod.default ?? mod).catch(() => null);
|
|
21
|
-
return mermaidPromise;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Upstream mermaid runs colour maths over themeVariables, so it needs literal
|
|
25
|
-
* values rather than var() references. Reading antd's CSS variables here keeps
|
|
26
|
-
* the cost off the render path — no theme context subscription, and it only
|
|
27
|
-
* runs for the diagram types that actually fall back to the CDN.
|
|
28
|
-
*/
|
|
29
|
-
const readCssVars = (names) => {
|
|
30
|
-
const result = {};
|
|
31
|
-
if (typeof document === "undefined") return result;
|
|
32
|
-
const computed = globalThis.getComputedStyle(document.documentElement);
|
|
33
|
-
for (const [key, variable] of Object.entries(names)) result[key] = computed.getPropertyValue(variable).trim() || void 0;
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
const createCdnMermaidConfig = (isDarkMode, customTheme) => {
|
|
37
|
-
const token = readCssVars({
|
|
38
|
-
border: "--lobe-color-border",
|
|
39
|
-
error: "--lobe-color-error",
|
|
40
|
-
fontFamily: "--lobe-font-family",
|
|
41
|
-
fontFamilyCode: "--lobe-font-family-code",
|
|
42
|
-
infoBg: "--lobe-color-info-bg",
|
|
43
|
-
infoBorder: "--lobe-color-info-border",
|
|
44
|
-
infoText: "--lobe-color-info-text",
|
|
45
|
-
primary: "--lobe-color-primary",
|
|
46
|
-
success: "--lobe-color-success",
|
|
47
|
-
successBg: "--lobe-color-success-bg",
|
|
48
|
-
successBorder: "--lobe-color-success-border",
|
|
49
|
-
successText: "--lobe-color-success-text",
|
|
50
|
-
text: "--lobe-color-text",
|
|
51
|
-
textDescription: "--lobe-color-text-description",
|
|
52
|
-
textSecondary: "--lobe-color-text-secondary",
|
|
53
|
-
bgContainer: "--lobe-color-bg-container",
|
|
54
|
-
warning: "--lobe-color-warning"
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
fontFamily: token.fontFamilyCode,
|
|
58
|
-
gantt: { useWidth: 1920 },
|
|
59
|
-
securityLevel: "strict",
|
|
60
|
-
startOnLoad: false,
|
|
61
|
-
theme: customTheme || (isDarkMode ? "dark" : "neutral"),
|
|
62
|
-
themeVariables: customTheme ? void 0 : {
|
|
63
|
-
errorBkgColor: token.textDescription,
|
|
64
|
-
errorTextColor: token.textDescription,
|
|
65
|
-
fontFamily: token.fontFamily,
|
|
66
|
-
lineColor: token.textSecondary,
|
|
67
|
-
mainBkg: token.bgContainer,
|
|
68
|
-
noteBkgColor: token.infoBg,
|
|
69
|
-
noteTextColor: token.infoText,
|
|
70
|
-
pie1: token.primary,
|
|
71
|
-
pie2: token.warning,
|
|
72
|
-
pie3: token.success,
|
|
73
|
-
pie4: token.error,
|
|
74
|
-
primaryBorderColor: token.border,
|
|
75
|
-
primaryColor: token.bgContainer,
|
|
76
|
-
primaryTextColor: token.text,
|
|
77
|
-
secondaryBorderColor: token.infoBorder,
|
|
78
|
-
secondaryColor: token.infoBg,
|
|
79
|
-
secondaryTextColor: token.infoText,
|
|
80
|
-
tertiaryBorderColor: token.successBorder,
|
|
81
|
-
tertiaryColor: token.successBg,
|
|
82
|
-
tertiaryTextColor: token.successText,
|
|
83
|
-
textColor: token.text
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
const renderWithCdnMermaid = async (content, id, config) => {
|
|
88
|
-
const mermaid = await loadCdnMermaid();
|
|
89
|
-
if (!mermaid) return "";
|
|
90
|
-
mermaid.initialize(config);
|
|
91
|
-
const { svg } = await mermaid.render(id, content);
|
|
92
|
-
return svg;
|
|
93
|
-
};
|
|
94
|
-
//#endregion
|
|
95
|
-
export { createCdnMermaidConfig, getMermaidCdnUrl, loadCdnMermaid, renderWithCdnMermaid, setMermaidCdnUrl };
|
|
96
|
-
|
|
97
|
-
//# sourceMappingURL=useMermaidCdn.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMermaidCdn.mjs","names":[],"sources":["../../src/hooks/useMermaidCdn.ts"],"sourcesContent":["'use client';\n\ninterface CdnMermaidConfig {\n fontFamily?: string;\n gantt?: { useWidth?: number };\n securityLevel?: string;\n startOnLoad?: boolean;\n theme?: string;\n themeVariables?: Record<string, string | undefined>;\n}\n\ninterface CdnMermaidApi {\n initialize: (config: CdnMermaidConfig) => void;\n render: (id: string, content: string) => Promise<{ svg: string }>;\n}\n\nconst DEFAULT_MERMAID_CDN_URL = 'https://esm.sh/mermaid@11';\n\nlet mermaidCdnUrl = DEFAULT_MERMAID_CDN_URL;\nlet mermaidPromise: Promise<CdnMermaidApi | null> | null = null;\n\n/**\n * Point the fallback loader at a mirror, or at a self-hosted copy for offline\n * and strict-CSP deployments. Resets any in-flight load.\n */\nexport const setMermaidCdnUrl = (url: string) => {\n if (url === mermaidCdnUrl) return;\n mermaidCdnUrl = url;\n mermaidPromise = null;\n};\n\nexport const getMermaidCdnUrl = () => mermaidCdnUrl;\n\nexport const loadCdnMermaid = (): Promise<CdnMermaidApi | null> => {\n if (typeof window === 'undefined') return Promise.resolve(null);\n\n mermaidPromise ??= import(/* @vite-ignore */ mermaidCdnUrl)\n .then((mod) => (mod.default ?? mod) as CdnMermaidApi)\n .catch(() => null);\n\n return mermaidPromise;\n};\n\n/**\n * Upstream mermaid runs colour maths over themeVariables, so it needs literal\n * values rather than var() references. Reading antd's CSS variables here keeps\n * the cost off the render path — no theme context subscription, and it only\n * runs for the diagram types that actually fall back to the CDN.\n */\nconst readCssVars = <T extends string>(names: Record<T, string>): Record<T, string | undefined> => {\n const result = {} as Record<T, string | undefined>;\n if (typeof document === 'undefined') return result;\n\n const computed = globalThis.getComputedStyle(document.documentElement);\n for (const [key, variable] of Object.entries(names) as [T, string][]) {\n result[key] = computed.getPropertyValue(variable).trim() || undefined;\n }\n return result;\n};\n\nexport const createCdnMermaidConfig = (\n isDarkMode: boolean,\n customTheme?: string,\n): CdnMermaidConfig => {\n const token = readCssVars({\n border: '--lobe-color-border',\n error: '--lobe-color-error',\n fontFamily: '--lobe-font-family',\n fontFamilyCode: '--lobe-font-family-code',\n infoBg: '--lobe-color-info-bg',\n infoBorder: '--lobe-color-info-border',\n infoText: '--lobe-color-info-text',\n primary: '--lobe-color-primary',\n success: '--lobe-color-success',\n successBg: '--lobe-color-success-bg',\n successBorder: '--lobe-color-success-border',\n successText: '--lobe-color-success-text',\n text: '--lobe-color-text',\n textDescription: '--lobe-color-text-description',\n textSecondary: '--lobe-color-text-secondary',\n bgContainer: '--lobe-color-bg-container',\n warning: '--lobe-color-warning',\n });\n\n return {\n fontFamily: token.fontFamilyCode,\n gantt: { useWidth: 1920 },\n // SECURITY: 'strict' keeps Mermaid from rendering node labels via innerHTML,\n // which would be an XSS vector for model-generated diagram content.\n securityLevel: 'strict',\n startOnLoad: false,\n theme: customTheme || (isDarkMode ? 'dark' : 'neutral'),\n themeVariables: customTheme\n ? undefined\n : {\n errorBkgColor: token.textDescription,\n errorTextColor: token.textDescription,\n fontFamily: token.fontFamily,\n lineColor: token.textSecondary,\n mainBkg: token.bgContainer,\n noteBkgColor: token.infoBg,\n noteTextColor: token.infoText,\n pie1: token.primary,\n pie2: token.warning,\n pie3: token.success,\n pie4: token.error,\n primaryBorderColor: token.border,\n primaryColor: token.bgContainer,\n primaryTextColor: token.text,\n secondaryBorderColor: token.infoBorder,\n secondaryColor: token.infoBg,\n secondaryTextColor: token.infoText,\n tertiaryBorderColor: token.successBorder,\n tertiaryColor: token.successBg,\n tertiaryTextColor: token.successText,\n textColor: token.text,\n },\n };\n};\n\nexport const renderWithCdnMermaid = async (\n content: string,\n id: string,\n config: CdnMermaidConfig,\n): Promise<string> => {\n const mermaid = await loadCdnMermaid();\n if (!mermaid) return '';\n\n mermaid.initialize(config);\n const { svg } = await mermaid.render(id, content);\n return svg;\n};\n"],"mappings":";;AAkBA,IAAI,gBAAgB;AACpB,IAAI,iBAAuD;;;;;AAM3D,MAAa,oBAAoB,QAAgB;CAC/C,IAAI,QAAQ,eAAe;CAC3B,gBAAgB;CAChB,iBAAiB;AACnB;AAEA,MAAa,yBAAyB;AAEtC,MAAa,uBAAsD;CACjE,IAAI,OAAO,WAAW,aAAa,OAAO,QAAQ,QAAQ,IAAI;CAE9D,mBAAmB;;EAA0B;CAAc,CACxD,MAAM,QAAS,IAAI,WAAW,GAAqB,CAAC,CACpD,YAAY,IAAI;CAEnB,OAAO;AACT;;;;;;;AAQA,MAAM,eAAiC,UAA4D;CACjG,MAAM,SAAS,CAAC;CAChB,IAAI,OAAO,aAAa,aAAa,OAAO;CAE5C,MAAM,WAAW,WAAW,iBAAiB,SAAS,eAAe;CACrE,KAAK,MAAM,CAAC,KAAK,aAAa,OAAO,QAAQ,KAAK,GAChD,OAAO,OAAO,SAAS,iBAAiB,QAAQ,CAAC,CAAC,KAAK,KAAK,KAAA;CAE9D,OAAO;AACT;AAEA,MAAa,0BACX,YACA,gBACqB;CACrB,MAAM,QAAQ,YAAY;EACxB,QAAQ;EACR,OAAO;EACP,YAAY;EACZ,gBAAgB;EAChB,QAAQ;EACR,YAAY;EACZ,UAAU;EACV,SAAS;EACT,SAAS;EACT,WAAW;EACX,eAAe;EACf,aAAa;EACb,MAAM;EACN,iBAAiB;EACjB,eAAe;EACf,aAAa;EACb,SAAS;CACX,CAAC;CAED,OAAO;EACL,YAAY,MAAM;EAClB,OAAO,EAAE,UAAU,KAAK;EAGxB,eAAe;EACf,aAAa;EACb,OAAO,gBAAgB,aAAa,SAAS;EAC7C,gBAAgB,cACZ,KAAA,IACA;GACE,eAAe,MAAM;GACrB,gBAAgB,MAAM;GACtB,YAAY,MAAM;GAClB,WAAW,MAAM;GACjB,SAAS,MAAM;GACf,cAAc,MAAM;GACpB,eAAe,MAAM;GACrB,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,oBAAoB,MAAM;GAC1B,cAAc,MAAM;GACpB,kBAAkB,MAAM;GACxB,sBAAsB,MAAM;GAC5B,gBAAgB,MAAM;GACtB,oBAAoB,MAAM;GAC1B,qBAAqB,MAAM;GAC3B,eAAe,MAAM;GACrB,mBAAmB,MAAM;GACzB,WAAW,MAAM;EACnB;CACN;AACF;AAEA,MAAa,uBAAuB,OAClC,SACA,IACA,WACoB;CACpB,MAAM,UAAU,MAAM,eAAe;CACrC,IAAI,CAAC,SAAS,OAAO;CAErB,QAAQ,WAAW,MAAM;CACzB,MAAM,EAAE,QAAQ,MAAM,QAAQ,OAAO,IAAI,OAAO;CAChD,OAAO;AACT"}
|