@lobehub/ui 6.3.0 → 6.4.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.
- package/es/Accordion/style.d.mts +1 -1
- package/es/Highlighter/FullFeatured.mjs +1 -1
- package/es/Highlighter/FullFeatured.mjs.map +1 -1
- package/es/Highlighter/Highlighter.mjs +1 -1
- package/es/Highlighter/SyntaxHighlighter/index.mjs +1 -1
- package/es/Highlighter/SyntaxHighlighter/index.mjs.map +1 -1
- package/es/Highlighter/style.mjs +5 -6
- package/es/Highlighter/style.mjs.map +1 -1
- package/es/Mermaid/FullFeatured.mjs +1 -1
- package/es/Mermaid/FullFeatured.mjs.map +1 -1
- package/es/Mermaid/Mermaid.mjs +1 -1
- 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 +2 -2
- 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 +3 -3
- package/es/eslint/index.d.mts +0 -8
- package/es/eslint/index.mjs +4 -28
- package/es/eslint/index.mjs.map +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/style.css +2 -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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
//#region src/Mermaid/themes.ts
|
|
2
|
+
const MERMAID_PRESETS = {
|
|
3
|
+
"zinc-light": {
|
|
4
|
+
bg: "#FFFFFF",
|
|
5
|
+
fg: "#27272A"
|
|
6
|
+
},
|
|
7
|
+
"zinc-dark": {
|
|
8
|
+
bg: "#18181B",
|
|
9
|
+
fg: "#FAFAFA"
|
|
10
|
+
},
|
|
11
|
+
"tokyo-night": {
|
|
12
|
+
accent: "#7aa2f7",
|
|
13
|
+
bg: "#1a1b26",
|
|
14
|
+
fg: "#a9b1d6",
|
|
15
|
+
line: "#3d59a1",
|
|
16
|
+
muted: "#565f89"
|
|
17
|
+
},
|
|
18
|
+
"tokyo-night-storm": {
|
|
19
|
+
accent: "#7aa2f7",
|
|
20
|
+
bg: "#24283b",
|
|
21
|
+
fg: "#a9b1d6",
|
|
22
|
+
line: "#3d59a1",
|
|
23
|
+
muted: "#565f89"
|
|
24
|
+
},
|
|
25
|
+
"tokyo-night-light": {
|
|
26
|
+
accent: "#34548a",
|
|
27
|
+
bg: "#d5d6db",
|
|
28
|
+
fg: "#343b58",
|
|
29
|
+
line: "#34548a",
|
|
30
|
+
muted: "#9699a3"
|
|
31
|
+
},
|
|
32
|
+
"catppuccin-mocha": {
|
|
33
|
+
accent: "#cba6f7",
|
|
34
|
+
bg: "#1e1e2e",
|
|
35
|
+
fg: "#cdd6f4",
|
|
36
|
+
line: "#585b70",
|
|
37
|
+
muted: "#6c7086"
|
|
38
|
+
},
|
|
39
|
+
"catppuccin-latte": {
|
|
40
|
+
accent: "#8839ef",
|
|
41
|
+
bg: "#eff1f5",
|
|
42
|
+
fg: "#4c4f69",
|
|
43
|
+
line: "#9ca0b0",
|
|
44
|
+
muted: "#9ca0b0"
|
|
45
|
+
},
|
|
46
|
+
"nord": {
|
|
47
|
+
accent: "#88c0d0",
|
|
48
|
+
bg: "#2e3440",
|
|
49
|
+
fg: "#d8dee9",
|
|
50
|
+
line: "#4c566a",
|
|
51
|
+
muted: "#616e88"
|
|
52
|
+
},
|
|
53
|
+
"nord-light": {
|
|
54
|
+
accent: "#5e81ac",
|
|
55
|
+
bg: "#eceff4",
|
|
56
|
+
fg: "#2e3440",
|
|
57
|
+
line: "#aab1c0",
|
|
58
|
+
muted: "#7b88a1"
|
|
59
|
+
},
|
|
60
|
+
"dracula": {
|
|
61
|
+
accent: "#bd93f9",
|
|
62
|
+
bg: "#282a36",
|
|
63
|
+
fg: "#f8f8f2",
|
|
64
|
+
line: "#6272a4",
|
|
65
|
+
muted: "#6272a4"
|
|
66
|
+
},
|
|
67
|
+
"github-light": {
|
|
68
|
+
accent: "#0969da",
|
|
69
|
+
bg: "#ffffff",
|
|
70
|
+
fg: "#1f2328",
|
|
71
|
+
line: "#d1d9e0",
|
|
72
|
+
muted: "#59636e"
|
|
73
|
+
},
|
|
74
|
+
"github-dark": {
|
|
75
|
+
accent: "#4493f8",
|
|
76
|
+
bg: "#0d1117",
|
|
77
|
+
fg: "#e6edf3",
|
|
78
|
+
line: "#3d444d",
|
|
79
|
+
muted: "#9198a1"
|
|
80
|
+
},
|
|
81
|
+
"solarized-light": {
|
|
82
|
+
accent: "#268bd2",
|
|
83
|
+
bg: "#fdf6e3",
|
|
84
|
+
fg: "#657b83",
|
|
85
|
+
line: "#93a1a1",
|
|
86
|
+
muted: "#93a1a1"
|
|
87
|
+
},
|
|
88
|
+
"solarized-dark": {
|
|
89
|
+
accent: "#268bd2",
|
|
90
|
+
bg: "#002b36",
|
|
91
|
+
fg: "#839496",
|
|
92
|
+
line: "#586e75",
|
|
93
|
+
muted: "#586e75"
|
|
94
|
+
},
|
|
95
|
+
"one-dark": {
|
|
96
|
+
accent: "#c678dd",
|
|
97
|
+
bg: "#282c34",
|
|
98
|
+
fg: "#abb2bf",
|
|
99
|
+
line: "#4b5263",
|
|
100
|
+
muted: "#5c6370"
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const isMermaidPreset = (theme) => !!theme && theme !== "lobe-theme" && Object.hasOwn(MERMAID_PRESETS, theme);
|
|
104
|
+
const sharedVars = {
|
|
105
|
+
"--pele-critical": "var(--lobe-color-error)",
|
|
106
|
+
"--pele-error": "var(--lobe-color-error)",
|
|
107
|
+
"--pele-font": "var(--lobe-font-family)",
|
|
108
|
+
"--pele-font-mono": "var(--lobe-font-family-code)",
|
|
109
|
+
"--pele-radius": "var(--lobe-border-radius)",
|
|
110
|
+
...Object.fromEntries([
|
|
111
|
+
"blue",
|
|
112
|
+
"gold",
|
|
113
|
+
"green",
|
|
114
|
+
"red",
|
|
115
|
+
"purple",
|
|
116
|
+
"cyan",
|
|
117
|
+
"orange",
|
|
118
|
+
"magenta"
|
|
119
|
+
].map((color, index) => [`--pele-series-${index + 1}`, `var(--lobe-${color})`]))
|
|
120
|
+
};
|
|
121
|
+
const LOBE_THEME_VARS = {
|
|
122
|
+
...sharedVars,
|
|
123
|
+
"--pele-accent": "var(--lobe-color-primary)",
|
|
124
|
+
"--pele-bg": "var(--lobe-color-bg-container)",
|
|
125
|
+
"--pele-border": "var(--lobe-color-border)",
|
|
126
|
+
"--pele-fg": "var(--lobe-color-text)",
|
|
127
|
+
"--pele-line": "var(--lobe-color-text-secondary)",
|
|
128
|
+
"--pele-muted": "var(--lobe-color-text-description)",
|
|
129
|
+
"--pele-surface": "var(--lobe-color-fill-tertiary)",
|
|
130
|
+
"--pele-surface-alt": "var(--lobe-color-fill-secondary)"
|
|
131
|
+
};
|
|
132
|
+
const mix = ({ bg, fg }, percent) => `color-mix(in srgb, ${fg} ${percent}%, ${bg})`;
|
|
133
|
+
const presetVars = (palette) => ({
|
|
134
|
+
...sharedVars,
|
|
135
|
+
"--pele-accent": palette.accent ?? palette.fg,
|
|
136
|
+
"--pele-bg": palette.bg,
|
|
137
|
+
"--pele-border": mix(palette, 20),
|
|
138
|
+
"--pele-fg": palette.fg,
|
|
139
|
+
"--pele-line": palette.line ?? mix(palette, 50),
|
|
140
|
+
"--pele-muted": palette.muted ?? mix(palette, 60),
|
|
141
|
+
"--pele-surface": mix(palette, 4),
|
|
142
|
+
"--pele-surface-alt": mix(palette, 10)
|
|
143
|
+
});
|
|
144
|
+
const PRESET_VARS = Object.fromEntries(Object.entries(MERMAID_PRESETS).map(([name, palette]) => [name, presetVars(palette)]));
|
|
145
|
+
const getMermaidThemeVars = (theme) => isMermaidPreset(theme) ? PRESET_VARS[theme] : LOBE_THEME_VARS;
|
|
146
|
+
//#endregion
|
|
147
|
+
export { MERMAID_PRESETS, getMermaidThemeVars, isMermaidPreset };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=themes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themes.mjs","names":[],"sources":["../../src/Mermaid/themes.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\ninterface MermaidPalette {\n accent?: string;\n bg: string;\n fg: string;\n line?: string;\n muted?: string;\n}\n\nexport const MERMAID_PRESETS = {\n 'zinc-light': { bg: '#FFFFFF', fg: '#27272A' },\n 'zinc-dark': { bg: '#18181B', fg: '#FAFAFA' },\n 'tokyo-night': {\n accent: '#7aa2f7',\n bg: '#1a1b26',\n fg: '#a9b1d6',\n line: '#3d59a1',\n muted: '#565f89',\n },\n 'tokyo-night-storm': {\n accent: '#7aa2f7',\n bg: '#24283b',\n fg: '#a9b1d6',\n line: '#3d59a1',\n muted: '#565f89',\n },\n 'tokyo-night-light': {\n accent: '#34548a',\n bg: '#d5d6db',\n fg: '#343b58',\n line: '#34548a',\n muted: '#9699a3',\n },\n 'catppuccin-mocha': {\n accent: '#cba6f7',\n bg: '#1e1e2e',\n fg: '#cdd6f4',\n line: '#585b70',\n muted: '#6c7086',\n },\n 'catppuccin-latte': {\n accent: '#8839ef',\n bg: '#eff1f5',\n fg: '#4c4f69',\n line: '#9ca0b0',\n muted: '#9ca0b0',\n },\n 'nord': { accent: '#88c0d0', bg: '#2e3440', fg: '#d8dee9', line: '#4c566a', muted: '#616e88' },\n 'nord-light': {\n accent: '#5e81ac',\n bg: '#eceff4',\n fg: '#2e3440',\n line: '#aab1c0',\n muted: '#7b88a1',\n },\n 'dracula': { accent: '#bd93f9', bg: '#282a36', fg: '#f8f8f2', line: '#6272a4', muted: '#6272a4' },\n 'github-light': {\n accent: '#0969da',\n bg: '#ffffff',\n fg: '#1f2328',\n line: '#d1d9e0',\n muted: '#59636e',\n },\n 'github-dark': {\n accent: '#4493f8',\n bg: '#0d1117',\n fg: '#e6edf3',\n line: '#3d444d',\n muted: '#9198a1',\n },\n 'solarized-light': {\n accent: '#268bd2',\n bg: '#fdf6e3',\n fg: '#657b83',\n line: '#93a1a1',\n muted: '#93a1a1',\n },\n 'solarized-dark': {\n accent: '#268bd2',\n bg: '#002b36',\n fg: '#839496',\n line: '#586e75',\n muted: '#586e75',\n },\n 'one-dark': {\n accent: '#c678dd',\n bg: '#282c34',\n fg: '#abb2bf',\n line: '#4b5263',\n muted: '#5c6370',\n },\n} satisfies Record<string, MermaidPalette>;\n\nexport type MermaidPresetName = keyof typeof MERMAID_PRESETS;\n\nexport type MermaidThemeName = 'lobe-theme' | MermaidPresetName;\n\nexport const isMermaidPreset = (theme?: string): theme is MermaidPresetName =>\n !!theme && theme !== 'lobe-theme' && Object.hasOwn(MERMAID_PRESETS, theme);\n\nconst SERIES = ['blue', 'gold', 'green', 'red', 'purple', 'cyan', 'orange', 'magenta'];\n\nconst seriesVars = Object.fromEntries(\n SERIES.map((color, index) => [`--pele-series-${index + 1}`, `var(--lobe-${color})`]),\n);\n\nconst sharedVars = {\n '--pele-critical': 'var(--lobe-color-error)',\n '--pele-error': 'var(--lobe-color-error)',\n '--pele-font': 'var(--lobe-font-family)',\n '--pele-font-mono': 'var(--lobe-font-family-code)',\n '--pele-radius': 'var(--lobe-border-radius)',\n ...seriesVars,\n};\n\nconst LOBE_THEME_VARS = {\n ...sharedVars,\n '--pele-accent': 'var(--lobe-color-primary)',\n '--pele-bg': 'var(--lobe-color-bg-container)',\n '--pele-border': 'var(--lobe-color-border)',\n '--pele-fg': 'var(--lobe-color-text)',\n '--pele-line': 'var(--lobe-color-text-secondary)',\n '--pele-muted': 'var(--lobe-color-text-description)',\n '--pele-surface': 'var(--lobe-color-fill-tertiary)',\n '--pele-surface-alt': 'var(--lobe-color-fill-secondary)',\n} as CSSProperties;\n\nconst mix = ({ bg, fg }: MermaidPalette, percent: number) =>\n `color-mix(in srgb, ${fg} ${percent}%, ${bg})`;\n\nconst presetVars = (palette: MermaidPalette) =>\n ({\n ...sharedVars,\n '--pele-accent': palette.accent ?? palette.fg,\n '--pele-bg': palette.bg,\n '--pele-border': mix(palette, 20),\n '--pele-fg': palette.fg,\n '--pele-line': palette.line ?? mix(palette, 50),\n '--pele-muted': palette.muted ?? mix(palette, 60),\n '--pele-surface': mix(palette, 4),\n '--pele-surface-alt': mix(palette, 10),\n }) as CSSProperties;\n\nconst PRESET_VARS = Object.fromEntries(\n Object.entries(MERMAID_PRESETS).map(([name, palette]) => [name, presetVars(palette)]),\n) as Record<MermaidPresetName, CSSProperties>;\n\nexport const getMermaidThemeVars = (theme?: string): CSSProperties =>\n isMermaidPreset(theme) ? PRESET_VARS[theme] : LOBE_THEME_VARS;\n"],"mappings":";AAUA,MAAa,kBAAkB;CAC7B,cAAc;EAAE,IAAI;EAAW,IAAI;CAAU;CAC7C,aAAa;EAAE,IAAI;EAAW,IAAI;CAAU;CAC5C,eAAe;EACb,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,qBAAqB;EACnB,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,qBAAqB;EACnB,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,oBAAoB;EAClB,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,oBAAoB;EAClB,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,QAAQ;EAAE,QAAQ;EAAW,IAAI;EAAW,IAAI;EAAW,MAAM;EAAW,OAAO;CAAU;CAC7F,cAAc;EACZ,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,WAAW;EAAE,QAAQ;EAAW,IAAI;EAAW,IAAI;EAAW,MAAM;EAAW,OAAO;CAAU;CAChG,gBAAgB;EACd,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,eAAe;EACb,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,mBAAmB;EACjB,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,kBAAkB;EAChB,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;CACA,YAAY;EACV,QAAQ;EACR,IAAI;EACJ,IAAI;EACJ,MAAM;EACN,OAAO;CACT;AACF;AAMA,MAAa,mBAAmB,UAC9B,CAAC,CAAC,SAAS,UAAU,gBAAgB,OAAO,OAAO,iBAAiB,KAAK;AAQ3E,MAAM,aAAa;CACjB,mBAAmB;CACnB,gBAAgB;CAChB,eAAe;CACf,oBAAoB;CACpB,iBAAiB;CACjB,GAViB,OAAO,YACxB;EAHc;EAAQ;EAAQ;EAAS;EAAO;EAAU;EAAQ;EAAU;CAGrE,CAAC,CAAC,KAAK,OAAO,UAAU,CAAC,iBAAiB,QAAQ,KAAK,cAAc,MAAM,EAAE,CAAC,CASvE;AACd;AAEA,MAAM,kBAAkB;CACtB,GAAG;CACH,iBAAiB;CACjB,aAAa;CACb,iBAAiB;CACjB,aAAa;CACb,eAAe;CACf,gBAAgB;CAChB,kBAAkB;CAClB,sBAAsB;AACxB;AAEA,MAAM,OAAO,EAAE,IAAI,MAAsB,YACvC,sBAAsB,GAAG,GAAG,QAAQ,KAAK,GAAG;AAE9C,MAAM,cAAc,aACjB;CACC,GAAG;CACH,iBAAiB,QAAQ,UAAU,QAAQ;CAC3C,aAAa,QAAQ;CACrB,iBAAiB,IAAI,SAAS,EAAE;CAChC,aAAa,QAAQ;CACrB,eAAe,QAAQ,QAAQ,IAAI,SAAS,EAAE;CAC9C,gBAAgB,QAAQ,SAAS,IAAI,SAAS,EAAE;CAChD,kBAAkB,IAAI,SAAS,CAAC;CAChC,sBAAsB,IAAI,SAAS,EAAE;AACvC;AAEF,MAAM,cAAc,OAAO,YACzB,OAAO,QAAQ,eAAe,CAAC,CAAC,KAAK,CAAC,MAAM,aAAa,CAAC,MAAM,WAAW,OAAO,CAAC,CAAC,CACtF;AAEA,MAAa,uBAAuB,UAClC,gBAAgB,KAAK,IAAI,YAAY,SAAS"}
|
package/es/Mermaid/type.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DivProps } from "../types/index.mjs";
|
|
2
2
|
import { ActionIconProps } from "../ActionIcon/type.mjs";
|
|
3
3
|
import "../ActionIcon/index.mjs";
|
|
4
|
+
import { MermaidThemeName } from "./themes.mjs";
|
|
4
5
|
import { CSSProperties, ReactNode, Ref } from "react";
|
|
5
|
-
import { ThemeName } from "beautiful-mermaid";
|
|
6
6
|
//#region src/Mermaid/type.d.ts
|
|
7
7
|
export interface SyntaxMermaidProps {
|
|
8
8
|
animated?: boolean;
|
|
@@ -45,7 +45,7 @@ export interface MermaidProps extends DivProps {
|
|
|
45
45
|
content?: CSSProperties;
|
|
46
46
|
header?: CSSProperties;
|
|
47
47
|
};
|
|
48
|
-
theme?:
|
|
48
|
+
theme?: MermaidThemeName;
|
|
49
49
|
variant?: 'filled' | 'outlined' | 'borderless';
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
package/es/Text/style.d.mts
CHANGED
|
@@ -14,13 +14,13 @@ export declare const textStyles: {
|
|
|
14
14
|
text: string;
|
|
15
15
|
disabled: string;
|
|
16
16
|
danger: string;
|
|
17
|
-
success: string;
|
|
18
|
-
info: string;
|
|
19
|
-
warning: string;
|
|
20
17
|
delete: string;
|
|
21
18
|
ellipsis: string;
|
|
22
19
|
italic: string;
|
|
23
20
|
underline: string;
|
|
21
|
+
success: string;
|
|
22
|
+
warning: string;
|
|
23
|
+
info: string;
|
|
24
24
|
ellipsisMulti: string;
|
|
25
25
|
secondary: string;
|
|
26
26
|
};
|
package/es/eslint/index.d.mts
CHANGED
|
@@ -7,10 +7,6 @@ export declare const restrictedImports: {
|
|
|
7
7
|
message: string;
|
|
8
8
|
name: string;
|
|
9
9
|
}[];
|
|
10
|
-
patterns: {
|
|
11
|
-
group: string[];
|
|
12
|
-
message: string;
|
|
13
|
-
}[];
|
|
14
10
|
})[];
|
|
15
11
|
};
|
|
16
12
|
};
|
|
@@ -47,10 +43,6 @@ declare const _default: ({
|
|
|
47
43
|
message: string;
|
|
48
44
|
name: string;
|
|
49
45
|
}[];
|
|
50
|
-
patterns: {
|
|
51
|
-
group: string[];
|
|
52
|
-
message: string;
|
|
53
|
-
}[];
|
|
54
46
|
})[];
|
|
55
47
|
};
|
|
56
48
|
} | {
|
package/es/eslint/index.mjs
CHANGED
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
import { noBaseUiSubpath } from "./noBaseUiSubpath.mjs";
|
|
2
2
|
import { noInlineFormSchema } from "./noInlineFormSchema.mjs";
|
|
3
3
|
//#region src/eslint/index.ts
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
message: REMOVED_ANTD_MESSAGE,
|
|
9
|
-
name: "antd"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
message: "Import createStaticStyles / cssVar / cx / css / keyframes / responsive / useTheme / useThemeMode / useResponsive from \"@lobehub/ui\" instead of antd-style.",
|
|
13
|
-
name: "antd-style"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
message: "Use `Spin variant=\"network\"` from \"@lobehub/ui\" instead.",
|
|
17
|
-
name: "thinking-orbs"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
patterns: [{
|
|
21
|
-
group: [
|
|
22
|
-
"antd/*",
|
|
23
|
-
"rc-*",
|
|
24
|
-
"@rc-component/*"
|
|
25
|
-
],
|
|
26
|
-
message: REMOVED_ANTD_MESSAGE
|
|
27
|
-
}, {
|
|
28
|
-
group: ["@ant-design/*"],
|
|
29
|
-
message: "@ant-design packages are not part of the @lobehub/ui stack anymore."
|
|
30
|
-
}]
|
|
31
|
-
}] } };
|
|
4
|
+
const restrictedImports = { rules: { "no-restricted-imports": ["error", { paths: [{
|
|
5
|
+
message: "Use `Spin variant=\"network\"` from \"@lobehub/ui\" instead.",
|
|
6
|
+
name: "thinking-orbs"
|
|
7
|
+
}] }] } };
|
|
32
8
|
const plugin = { rules: {
|
|
33
9
|
"no-base-ui-subpath": noBaseUiSubpath,
|
|
34
10
|
"no-inline-form-schema": noInlineFormSchema
|
package/es/eslint/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/eslint/index.ts"],"sourcesContent":["import { noBaseUiSubpath } from './noBaseUiSubpath';\nimport { noInlineFormSchema } from './noInlineFormSchema';\n\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/eslint/index.ts"],"sourcesContent":["import { noBaseUiSubpath } from './noBaseUiSubpath';\nimport { noInlineFormSchema } from './noInlineFormSchema';\n\nexport const restrictedImports = {\n rules: {\n 'no-restricted-imports': [\n 'error',\n {\n paths: [\n {\n message: 'Use `Spin variant=\"network\"` from \"@lobehub/ui\" instead.',\n name: 'thinking-orbs',\n },\n ],\n },\n ],\n },\n};\n\nconst plugin = {\n rules: {\n 'no-base-ui-subpath': noBaseUiSubpath,\n 'no-inline-form-schema': noInlineFormSchema,\n },\n};\n\nexport const subpathRules = {\n plugins: { '@lobehub/ui': plugin },\n rules: {\n '@lobehub/ui/no-base-ui-subpath': 'error',\n },\n};\n\nexport const formSchemaRules = {\n plugins: { '@lobehub/ui': plugin },\n rules: {\n '@lobehub/ui/no-inline-form-schema': 'warn',\n },\n};\n\nexport default [restrictedImports, subpathRules, formSchemaRules];\n"],"mappings":";;;AAGA,MAAa,oBAAoB,EAC/B,OAAO,EACL,yBAAyB,CACvB,SACA,EACE,OAAO,CACL;CACE,SAAS;CACT,MAAM;AACR,CACF,EACF,CACF,EACF,EACF;AAEA,MAAM,SAAS,EACb,OAAO;CACL,sBAAsB;CACtB,yBAAyB;AAC3B,EACF;AAEA,MAAa,eAAe;CAC1B,SAAS,EAAE,eAAe,OAAO;CACjC,OAAO,EACL,kCAAkC,QACpC;AACF;AAEA,MAAa,kBAAkB;CAC7B,SAAS,EAAE,eAAe,OAAO;CACjC,OAAO,EACL,qCAAqC,OACvC;AACF;AAEA,IAAA,iBAAe;CAAC;CAAmB;CAAc;AAAe"}
|
package/es/hooks/useMermaid.mjs
CHANGED
|
@@ -1,98 +1,37 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createCdnMermaidConfig, renderWithCdnMermaid } from "./useMermaidCdn.mjs";
|
|
5
|
-
import { useEffect, useId, useMemo, useState } from "react";
|
|
6
|
-
import { THEMES, renderMermaidSVG } from "beautiful-mermaid";
|
|
2
|
+
import { useId, useMemo } from "react";
|
|
3
|
+
import { render } from "pele";
|
|
7
4
|
//#region src/hooks/useMermaid.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* no re-render (or re-layout) when the appearance changes.
|
|
13
|
-
*/
|
|
14
|
-
const LOBE_THEME_OPTIONS = {
|
|
15
|
-
accent: "var(--lobe-color-primary)",
|
|
16
|
-
bg: "var(--lobe-color-bg-container)",
|
|
17
|
-
border: "var(--lobe-color-border)",
|
|
18
|
-
fg: "var(--lobe-color-text)",
|
|
19
|
-
line: "var(--lobe-color-text-secondary)",
|
|
20
|
-
muted: "var(--lobe-color-text-description)",
|
|
21
|
-
surface: "var(--lobe-color-fill-tertiary)",
|
|
22
|
-
transparent: true
|
|
5
|
+
const FALLBACK_FONT = "sans-serif";
|
|
6
|
+
const resolveFontFamily = () => {
|
|
7
|
+
if (typeof document === "undefined") return FALLBACK_FONT;
|
|
8
|
+
return globalThis.getComputedStyle(document.documentElement).getPropertyValue("--lobe-font-family").trim() || FALLBACK_FONT;
|
|
23
9
|
};
|
|
24
|
-
const
|
|
25
|
-
const createMermaidOptions = (customTheme) => isNamedTheme(customTheme) ? THEMES[customTheme] : LOBE_THEME_OPTIONS;
|
|
26
|
-
/**
|
|
27
|
-
* beautiful-mermaid covers six diagram types; anything else throws here and is
|
|
28
|
-
* handed to the CDN-loaded upstream mermaid instead.
|
|
29
|
-
*/
|
|
30
|
-
const renderMermaid = (content, scopeId, customTheme) => {
|
|
10
|
+
const renderMermaid = (content, scopeId) => {
|
|
31
11
|
if (!content) return { svg: "" };
|
|
32
12
|
try {
|
|
33
|
-
const svg =
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
const { svg } = render(content, {
|
|
14
|
+
fontFamily: resolveFontFamily(),
|
|
15
|
+
fontSize: 14,
|
|
16
|
+
idPrefix: scopeId
|
|
17
|
+
});
|
|
18
|
+
return { svg };
|
|
19
|
+
} catch (error) {
|
|
36
20
|
return {
|
|
37
|
-
error: "
|
|
21
|
+
error: error.message || "Failed to render diagram",
|
|
38
22
|
svg: ""
|
|
39
23
|
};
|
|
40
24
|
}
|
|
41
25
|
};
|
|
42
|
-
const
|
|
43
|
-
const { isDarkMode } = useThemeMode();
|
|
26
|
+
const useMermaidScopeId = () => {
|
|
44
27
|
const reactId = useId();
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (!enabled || !content) {
|
|
48
|
-
setResult({ svg: "" });
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
let active = true;
|
|
52
|
-
setResult({
|
|
53
|
-
loading: true,
|
|
54
|
-
svg: ""
|
|
55
|
-
});
|
|
56
|
-
const config = createCdnMermaidConfig(isDarkMode, isNamedTheme(customTheme) ? customTheme : void 0);
|
|
57
|
-
renderWithCdnMermaid(content, `mermaid-cdn-${reactId.replaceAll(":", "")}`, config).then((svg) => {
|
|
58
|
-
if (!active) return;
|
|
59
|
-
setResult(svg ? { svg } : {
|
|
60
|
-
error: "Failed to render diagram",
|
|
61
|
-
svg: ""
|
|
62
|
-
});
|
|
63
|
-
}).catch(() => {
|
|
64
|
-
if (active) setResult({
|
|
65
|
-
error: "Failed to render diagram",
|
|
66
|
-
svg: ""
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
return () => {
|
|
70
|
-
active = false;
|
|
71
|
-
};
|
|
72
|
-
}, [
|
|
73
|
-
enabled,
|
|
74
|
-
content,
|
|
75
|
-
isDarkMode,
|
|
76
|
-
customTheme,
|
|
77
|
-
reactId
|
|
78
|
-
]);
|
|
79
|
-
return result;
|
|
28
|
+
return useMemo(() => `mermaid-${reactId.replaceAll(":", "")}-`, [reactId]);
|
|
80
29
|
};
|
|
81
|
-
const useMermaid = (content
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
const primary = useMemo(() => renderMermaid(content, scopeId, customTheme), [
|
|
85
|
-
content,
|
|
86
|
-
scopeId,
|
|
87
|
-
customTheme
|
|
88
|
-
]);
|
|
89
|
-
const fallback = useCdnMermaidFallback(content, {
|
|
90
|
-
enabled: Boolean(primary.error),
|
|
91
|
-
theme: customTheme
|
|
92
|
-
});
|
|
93
|
-
return primary.error ? fallback : primary;
|
|
30
|
+
const useMermaid = (content) => {
|
|
31
|
+
const scopeId = useMermaidScopeId();
|
|
32
|
+
return useMemo(() => renderMermaid(content, scopeId), [content, scopeId]);
|
|
94
33
|
};
|
|
95
34
|
//#endregion
|
|
96
|
-
export {
|
|
35
|
+
export { renderMermaid, useMermaid, useMermaidScopeId };
|
|
97
36
|
|
|
98
37
|
//# sourceMappingURL=useMermaid.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMermaid.mjs","names":[],"sources":["../../src/hooks/useMermaid.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useMermaid.mjs","names":[],"sources":["../../src/hooks/useMermaid.ts"],"sourcesContent":["'use client';\n\nimport { render } from 'pele';\nimport { useId, useMemo } from 'react';\n\nexport type { MermaidThemeName } from '@/Mermaid/themes';\n\nexport interface MermaidRenderResult {\n error?: string;\n loading?: boolean;\n svg: string;\n}\n\nconst FALLBACK_FONT = 'sans-serif';\n\n// pele sizes nodes by measuring labels on a canvas, which cannot resolve var(),\n// so the theme font has to be read as a literal before rendering.\nconst resolveFontFamily = (): string => {\n if (typeof document === 'undefined') return FALLBACK_FONT;\n const value = globalThis\n .getComputedStyle(document.documentElement)\n .getPropertyValue('--lobe-font-family')\n .trim();\n return value || FALLBACK_FONT;\n};\n\nexport const renderMermaid = (content: string, scopeId: string): MermaidRenderResult => {\n if (!content) return { svg: '' };\n try {\n const { svg } = render(content, {\n fontFamily: resolveFontFamily(),\n fontSize: 14,\n idPrefix: scopeId,\n });\n return { svg };\n } catch (error) {\n return { error: (error as Error).message || 'Failed to render diagram', svg: '' };\n }\n};\n\nexport const useMermaidScopeId = () => {\n const reactId = useId();\n return useMemo(() => `mermaid-${reactId.replaceAll(':', '')}-`, [reactId]);\n};\n\nexport const useMermaid = (content: string): MermaidRenderResult => {\n const scopeId = useMermaidScopeId();\n return useMemo(() => renderMermaid(content, scopeId), [content, scopeId]);\n};\n"],"mappings":";;;;AAaA,MAAM,gBAAgB;AAItB,MAAM,0BAAkC;CACtC,IAAI,OAAO,aAAa,aAAa,OAAO;CAK5C,OAJc,WACX,iBAAiB,SAAS,eAAe,CAAC,CAC1C,iBAAiB,oBAAoB,CAAC,CACtC,KACQ,KAAK;AAClB;AAEA,MAAa,iBAAiB,SAAiB,YAAyC;CACtF,IAAI,CAAC,SAAS,OAAO,EAAE,KAAK,GAAG;CAC/B,IAAI;EACF,MAAM,EAAE,QAAQ,OAAO,SAAS;GAC9B,YAAY,kBAAkB;GAC9B,UAAU;GACV,UAAU;EACZ,CAAC;EACD,OAAO,EAAE,IAAI;CACf,SAAS,OAAO;EACd,OAAO;GAAE,OAAQ,MAAgB,WAAW;GAA4B,KAAK;EAAG;CAClF;AACF;AAEA,MAAa,0BAA0B;CACrC,MAAM,UAAU,MAAM;CACtB,OAAO,cAAc,WAAW,QAAQ,WAAW,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC;AAC3E;AAEA,MAAa,cAAc,YAAyC;CAClE,MAAM,UAAU,kBAAkB;CAClC,OAAO,cAAc,cAAc,SAAS,OAAO,GAAG,CAAC,SAAS,OAAO,CAAC;AAC1E"}
|
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { renderMermaid,
|
|
3
|
-
import { useEffect,
|
|
2
|
+
import { renderMermaid, useMermaidScopeId } from "./useMermaid.mjs";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
//#region src/hooks/useStreamMermaid.ts
|
|
5
5
|
const EMPTY = { svg: "" };
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const PENDING = {
|
|
7
|
+
loading: true,
|
|
8
|
+
svg: ""
|
|
9
|
+
};
|
|
10
|
+
const THROTTLE = 150;
|
|
11
|
+
const useStreamMermaid = (content, { enabled = true } = {}) => {
|
|
12
|
+
const scopeId = useMermaidScopeId();
|
|
13
|
+
const [result, setResult] = useState(EMPTY);
|
|
14
|
+
const lastRenderRef = useRef(0);
|
|
10
15
|
useEffect(() => {
|
|
11
16
|
if (!enabled || !content) {
|
|
12
|
-
|
|
17
|
+
setResult(EMPTY);
|
|
13
18
|
return;
|
|
14
19
|
}
|
|
20
|
+
const wait = Math.max(0, THROTTLE - (Date.now() - lastRenderRef.current));
|
|
15
21
|
const timer = setTimeout(() => {
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
lastRenderRef.current = Date.now();
|
|
23
|
+
const next = renderMermaid(content, scopeId);
|
|
24
|
+
setResult((previous) => {
|
|
25
|
+
if (!next.error) return next;
|
|
26
|
+
return previous.svg ? previous : PENDING;
|
|
27
|
+
});
|
|
28
|
+
}, wait);
|
|
18
29
|
return () => clearTimeout(timer);
|
|
19
30
|
}, [
|
|
20
31
|
enabled,
|
|
21
32
|
content,
|
|
22
|
-
scopeId
|
|
23
|
-
customTheme
|
|
33
|
+
scopeId
|
|
24
34
|
]);
|
|
25
|
-
|
|
26
|
-
enabled: enabled && Boolean(primary.error),
|
|
27
|
-
theme: customTheme
|
|
28
|
-
});
|
|
29
|
-
return primary.error ? fallback : primary;
|
|
35
|
+
return result;
|
|
30
36
|
};
|
|
31
37
|
//#endregion
|
|
32
38
|
export { useStreamMermaid };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamMermaid.mjs","names":[],"sources":["../../src/hooks/useStreamMermaid.ts"],"sourcesContent":["'use client';\n\nimport { useEffect,
|
|
1
|
+
{"version":3,"file":"useStreamMermaid.mjs","names":[],"sources":["../../src/hooks/useStreamMermaid.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { type MermaidRenderResult, renderMermaid, useMermaidScopeId } from './useMermaid';\n\nconst EMPTY: MermaidRenderResult = { svg: '' };\nconst PENDING: MermaidRenderResult = { loading: true, svg: '' };\nconst THROTTLE = 150;\n\n// Most prefixes of a diagram are not valid syntax yet, so a failed render keeps\n// the last good SVG instead of flashing an error; the static renderer that takes\n// over once streaming ends is the one that reports real errors.\nexport const useStreamMermaid = (\n content: string,\n { enabled = true }: { enabled?: boolean } = {},\n): MermaidRenderResult => {\n const scopeId = useMermaidScopeId();\n const [result, setResult] = useState<MermaidRenderResult>(EMPTY);\n const lastRenderRef = useRef(0);\n\n useEffect(() => {\n if (!enabled || !content) {\n setResult(EMPTY);\n return;\n }\n\n // Throttle rather than debounce: chunks arrive faster than any debounce\n // window, which would hold the diagram back until the stream pauses.\n const wait = Math.max(0, THROTTLE - (Date.now() - lastRenderRef.current));\n const timer = setTimeout(() => {\n lastRenderRef.current = Date.now();\n const next = renderMermaid(content, scopeId);\n setResult((previous) => {\n if (!next.error) return next;\n return previous.svg ? previous : PENDING;\n });\n }, wait);\n\n return () => clearTimeout(timer);\n }, [enabled, content, scopeId]);\n\n return result;\n};\n"],"mappings":";;;;AAMA,MAAM,QAA6B,EAAE,KAAK,GAAG;AAC7C,MAAM,UAA+B;CAAE,SAAS;CAAM,KAAK;AAAG;AAC9D,MAAM,WAAW;AAKjB,MAAa,oBACX,SACA,EAAE,UAAU,SAAgC,CAAC,MACrB;CACxB,MAAM,UAAU,kBAAkB;CAClC,MAAM,CAAC,QAAQ,aAAa,SAA8B,KAAK;CAC/D,MAAM,gBAAgB,OAAO,CAAC;CAE9B,gBAAgB;EACd,IAAI,CAAC,WAAW,CAAC,SAAS;GACxB,UAAU,KAAK;GACf;EACF;EAIA,MAAM,OAAO,KAAK,IAAI,GAAG,YAAY,KAAK,IAAI,IAAI,cAAc,QAAQ;EACxE,MAAM,QAAQ,iBAAiB;GAC7B,cAAc,UAAU,KAAK,IAAI;GACjC,MAAM,OAAO,cAAc,SAAS,OAAO;GAC3C,WAAW,aAAa;IACtB,IAAI,CAAC,KAAK,OAAO,OAAO;IACxB,OAAO,SAAS,MAAM,WAAW;GACnC,CAAC;EACH,GAAG,IAAI;EAEP,aAAa,aAAa,KAAK;CACjC,GAAG;EAAC;EAAS;EAAS;CAAO,CAAC;CAE9B,OAAO;AACT"}
|
package/es/style.css
CHANGED
|
@@ -1999,16 +1999,13 @@
|
|
|
1999
1999
|
}
|
|
2000
2000
|
|
|
2001
2001
|
.lobe-mermaid svg {
|
|
2002
|
-
width: 100%;
|
|
2002
|
+
max-width: 100%;
|
|
2003
2003
|
height: auto;
|
|
2004
2004
|
max-height: 480px;
|
|
2005
|
+
margin-inline: auto;
|
|
2005
2006
|
display: block;
|
|
2006
2007
|
}
|
|
2007
2008
|
|
|
2008
|
-
.lobe-mermaid svg text {
|
|
2009
|
-
font-family: var(--lobe-font-family);
|
|
2010
|
-
}
|
|
2011
|
-
|
|
2012
2009
|
.lobe-mermaid-transparent img {
|
|
2013
2010
|
background: none !important;
|
|
2014
2011
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/ui",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.1",
|
|
4
4
|
"description": "Lobe UI is an open-source UI component library for building AIGC web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -167,7 +167,6 @@
|
|
|
167
167
|
"@tanstack/form-core": "^1.33.5",
|
|
168
168
|
"@tanstack/react-table": "^9.2.8",
|
|
169
169
|
"@tanstack/react-virtual": "^3.14.18",
|
|
170
|
-
"beautiful-mermaid": "^1.1.3",
|
|
171
170
|
"chroma-js": "^3.2.0",
|
|
172
171
|
"clsx": "^2.1.1",
|
|
173
172
|
"dayjs": "^1.11.21",
|
|
@@ -179,6 +178,7 @@
|
|
|
179
178
|
"leva": "^0.10.1",
|
|
180
179
|
"lucide-react": "^1.55.0",
|
|
181
180
|
"motion": "^13.0.0 || ^14.0.0",
|
|
181
|
+
"pele": "^1.6.0",
|
|
182
182
|
"re-resizable": "^6.11.2",
|
|
183
183
|
"react-avatar-editor": "^16.0.0",
|
|
184
184
|
"react-error-boundary": "^6.1.6",
|
|
@@ -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
|