@schlessera/brain-ui-react 0.8.0 → 0.10.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/dist/components/chat/chat-page.d.ts.map +1 -1
- package/dist/components/chat/chat-page.js +10 -1
- package/dist/components/chat/chat-page.js.map +1 -1
- package/dist/components/chat/copy-button.d.ts.map +1 -1
- package/dist/components/chat/copy-button.js +3 -1
- package/dist/components/chat/copy-button.js.map +1 -1
- package/dist/components/chat/mermaid-block.d.ts.map +1 -1
- package/dist/components/chat/mermaid-block.js +10 -2
- package/dist/components/chat/mermaid-block.js.map +1 -1
- package/dist/components/chat/mermaid-share.d.ts +5 -0
- package/dist/components/chat/mermaid-share.d.ts.map +1 -0
- package/dist/components/chat/mermaid-share.js +80 -0
- package/dist/components/chat/mermaid-share.js.map +1 -0
- package/dist/components/chat/mermaid-viewer.d.ts +6 -0
- package/dist/components/chat/mermaid-viewer.d.ts.map +1 -0
- package/dist/components/chat/mermaid-viewer.js +266 -0
- package/dist/components/chat/mermaid-viewer.js.map +1 -0
- package/dist/components/files/file-viewer.d.ts.map +1 -1
- package/dist/components/files/file-viewer.js +15 -0
- package/dist/components/files/file-viewer.js.map +1 -1
- package/dist/components/share/share-menu.d.ts +8 -1
- package/dist/components/share/share-menu.d.ts.map +1 -1
- package/dist/components/share/share-menu.js +10 -5
- package/dist/components/share/share-menu.js.map +1 -1
- package/dist/lib/client-environment.d.ts +29 -0
- package/dist/lib/client-environment.d.ts.map +1 -0
- package/dist/lib/client-environment.js +153 -0
- package/dist/lib/client-environment.js.map +1 -0
- package/dist/lib/mermaid-theme.d.ts +4 -0
- package/dist/lib/mermaid-theme.d.ts.map +1 -0
- package/dist/lib/mermaid-theme.js +221 -0
- package/dist/lib/mermaid-theme.js.map +1 -0
- package/dist/lib/mermaid.d.ts +15 -1
- package/dist/lib/mermaid.d.ts.map +1 -1
- package/dist/lib/mermaid.js +88 -38
- package/dist/lib/mermaid.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/src/components/chat/chat-page.tsx +20 -1
- package/src/components/chat/copy-button.tsx +3 -0
- package/src/components/chat/mermaid-block.tsx +38 -9
- package/src/components/chat/mermaid-share.ts +91 -0
- package/src/components/chat/mermaid-viewer.tsx +336 -0
- package/src/components/files/file-viewer.tsx +17 -0
- package/src/components/share/share-menu.tsx +20 -6
- package/src/lib/client-environment.ts +152 -0
- package/src/lib/mermaid-theme.ts +246 -0
- package/src/lib/mermaid.ts +90 -36
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-environment.js","sourceRoot":"","sources":["../../src/lib/client-environment.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,kEAAkE;AAClE,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAEzD,kFAAkF;AAClF,IAAI,UAAgE,CAAC;AACrE,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAAK,GAAG,KAAK;IACxD,IAAI,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,OAAO;QAAE,OAAO;IAC9C,IAAI,OAAO,SAAS,KAAK,WAAW;QAAE,OAAO;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC;IACrC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,gBAAgB,KAAK,UAAU;QAAE,OAAO;IACnE,OAAO,GAAG,IAAI,CAAC;IACf,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,UAAU,GAAG;YACX,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC;YACpD,UAAU,EAAE,OAAO,CAA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ACrF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type MermaidTheme = "dark" | "light";
|
|
2
|
+
/** Theme variables for a target surface, as mermaid's `themeVariables` object. */
|
|
3
|
+
export declare function mermaidThemeVariables(theme: MermaidTheme): Record<string, string | boolean>;
|
|
4
|
+
//# sourceMappingURL=mermaid-theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-theme.d.ts","sourceRoot":"","sources":["../../src/lib/mermaid-theme.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,CAAC;AA+N5C,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAE3F"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid theme variables for the two surfaces a diagram can land on.
|
|
3
|
+
*
|
|
4
|
+
* Mermaid's stock "dark" theme is a blue-grey palette that reads as foreign
|
|
5
|
+
* next to the app's warm-neutral chrome, and its "neutral" theme is what the
|
|
6
|
+
* share renderer used to emit. Both are replaced by the "base" theme plus the
|
|
7
|
+
* variables below, so an in-app diagram and a shared PNG are recognisably the
|
|
8
|
+
* same product.
|
|
9
|
+
*
|
|
10
|
+
* Two rules kept the palette honest:
|
|
11
|
+
* - Surfaces follow the tokens in theme.css, not approximations of them. A
|
|
12
|
+
* chat diagram sits on `--color-surface` (#141619), not on the page
|
|
13
|
+
* background, because MermaidBlock draws it on a raised plate.
|
|
14
|
+
* - Multi-series colors reuse CATEGORICAL_SLOTS from the graph view, which
|
|
15
|
+
* is the repo's one CVD-validated categorical palette. Slot order is the
|
|
16
|
+
* CVD-safety mechanism there and is preserved here.
|
|
17
|
+
*/
|
|
18
|
+
import { CATEGORICAL_SLOTS, OTHER_COLOR } from "../components/graph/lib/graph-helpers.js";
|
|
19
|
+
// These variables reach mermaid through initialize(), NOT through a
|
|
20
|
+
// `%%{init: …}%%` directive: mermaid's directive path rewrites `'` to `"`
|
|
21
|
+
// before parsing the JSON and drops any themeVariable containing a hyphen, so
|
|
22
|
+
// a font stack cannot survive it. See the note in mermaid.ts.
|
|
23
|
+
const SANS = '"Plus Jakarta Sans", system-ui, -apple-system, sans-serif';
|
|
24
|
+
/** Ordered series colors, long enough for the 12-slot scales mermaid asks for. */
|
|
25
|
+
const SERIES = [...CATEGORICAL_SLOTS, OTHER_COLOR, "#67b8e3", "#eab354", "#b197d4"];
|
|
26
|
+
/** Expand a scale into the `${prefix}0..count-1` (or 1-based) shape mermaid wants. */
|
|
27
|
+
function scale(prefix, count, oneBased = false) {
|
|
28
|
+
const out = {};
|
|
29
|
+
for (let i = 0; i < count; i++) {
|
|
30
|
+
out[`${prefix}${oneBased ? i + 1 : i}`] = SERIES[i % SERIES.length];
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Dark: the in-app palette. Node fills use `--color-surface-overlay` so nodes
|
|
36
|
+
* sit a step above the block's own `--color-surface` plate, and borders use
|
|
37
|
+
* #3d4150 rather than `--color-border` (#2a2d35) — a 1px border at the token
|
|
38
|
+
* value all but disappears against the plate at diagram scale.
|
|
39
|
+
*/
|
|
40
|
+
const DARK = {
|
|
41
|
+
darkMode: true,
|
|
42
|
+
background: "#141619",
|
|
43
|
+
fontFamily: SANS,
|
|
44
|
+
fontSize: "14px",
|
|
45
|
+
primaryColor: "#1e2128",
|
|
46
|
+
primaryTextColor: "#e8e4df",
|
|
47
|
+
primaryBorderColor: "#3d4150",
|
|
48
|
+
secondaryColor: "#1a1d22",
|
|
49
|
+
secondaryTextColor: "#e8e4df",
|
|
50
|
+
secondaryBorderColor: "#3d4150",
|
|
51
|
+
tertiaryColor: "#0c0e12",
|
|
52
|
+
tertiaryTextColor: "#8a8691",
|
|
53
|
+
tertiaryBorderColor: "#2a2d35",
|
|
54
|
+
mainBkg: "#1e2128",
|
|
55
|
+
nodeBorder: "#3d4150",
|
|
56
|
+
nodeTextColor: "#e8e4df",
|
|
57
|
+
textColor: "#e8e4df",
|
|
58
|
+
lineColor: "#8a8691",
|
|
59
|
+
defaultLinkColor: "#8a8691",
|
|
60
|
+
titleColor: "#e09f3e",
|
|
61
|
+
edgeLabelBackground: "#141619",
|
|
62
|
+
clusterBkg: "#0c0e12",
|
|
63
|
+
clusterBorder: "#2a2d35",
|
|
64
|
+
noteBkgColor: "#1a1d22",
|
|
65
|
+
noteTextColor: "#e8e4df",
|
|
66
|
+
noteBorderColor: "#e09f3e",
|
|
67
|
+
errorBkgColor: "#2a1a1a",
|
|
68
|
+
errorTextColor: "#f87171",
|
|
69
|
+
// Sequence
|
|
70
|
+
actorBkg: "#1e2128",
|
|
71
|
+
actorBorder: "#3d4150",
|
|
72
|
+
actorTextColor: "#e8e4df",
|
|
73
|
+
actorLineColor: "#3d4150",
|
|
74
|
+
signalColor: "#8a8691",
|
|
75
|
+
signalTextColor: "#e8e4df",
|
|
76
|
+
labelBoxBkgColor: "#1a1d22",
|
|
77
|
+
labelBoxBorderColor: "#2a2d35",
|
|
78
|
+
labelTextColor: "#e8e4df",
|
|
79
|
+
loopTextColor: "#e8e4df",
|
|
80
|
+
activationBkgColor: "#1a1d22",
|
|
81
|
+
activationBorderColor: "#5bb5a2",
|
|
82
|
+
sequenceNumberColor: "#0c0e12",
|
|
83
|
+
// State / class / journey
|
|
84
|
+
labelColor: "#e8e4df",
|
|
85
|
+
altBackground: "#0c0e12",
|
|
86
|
+
classText: "#e8e4df",
|
|
87
|
+
// Gantt
|
|
88
|
+
sectionBkgColor: "#1a1d22",
|
|
89
|
+
altSectionBkgColor: "#141619",
|
|
90
|
+
sectionBkgColor2: "#1e2128",
|
|
91
|
+
gridColor: "#2a2d35",
|
|
92
|
+
taskBkgColor: "#2a2d35",
|
|
93
|
+
taskTextColor: "#e8e4df",
|
|
94
|
+
taskTextOutsideColor: "#e8e4df",
|
|
95
|
+
taskTextDarkColor: "#0c0e12",
|
|
96
|
+
taskBorderColor: "#3d4150",
|
|
97
|
+
doneTaskBkgColor: "#565b66",
|
|
98
|
+
doneTaskBorderColor: "#3d4150",
|
|
99
|
+
activeTaskBkgColor: "#e09f3e",
|
|
100
|
+
activeTaskBorderColor: "#e09f3e",
|
|
101
|
+
critBkgColor: "#d03b3b",
|
|
102
|
+
critBorderColor: "#d03b3b",
|
|
103
|
+
todayLineColor: "#5bb5a2",
|
|
104
|
+
// Pie
|
|
105
|
+
pieTitleTextColor: "#e8e4df",
|
|
106
|
+
pieSectionTextColor: "#0c0e12",
|
|
107
|
+
pieLegendTextColor: "#e8e4df",
|
|
108
|
+
pieStrokeColor: "#141619",
|
|
109
|
+
pieOuterStrokeColor: "#2a2d35",
|
|
110
|
+
// Quadrant / requirement / misc surfaces that don't inherit cleanly
|
|
111
|
+
quadrant1Fill: "#1e2128",
|
|
112
|
+
quadrant2Fill: "#1a1d22",
|
|
113
|
+
quadrant3Fill: "#141619",
|
|
114
|
+
quadrant4Fill: "#1e2128",
|
|
115
|
+
quadrantPointFill: "#e09f3e",
|
|
116
|
+
quadrantTitleFill: "#e8e4df",
|
|
117
|
+
quadrantInternalBorderStrokeFill: "#2a2d35",
|
|
118
|
+
quadrantExternalBorderStrokeFill: "#3d4150",
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Light: what the share renderer emits. Tuned against the PNG/PDF template's
|
|
122
|
+
* own palette (`ui-server/src/render/template.ts`: #ffffff page, #f8fafc
|
|
123
|
+
* surface, #e5e7eb border, #1f2937 text) so a diagram doesn't look pasted in.
|
|
124
|
+
* The amber and teal are darkened from the app tokens — #e09f3e on white is a
|
|
125
|
+
* 1.9:1 line, unusable for edges or titles.
|
|
126
|
+
*/
|
|
127
|
+
const LIGHT = {
|
|
128
|
+
darkMode: false,
|
|
129
|
+
background: "#ffffff",
|
|
130
|
+
fontFamily: SANS,
|
|
131
|
+
fontSize: "14px",
|
|
132
|
+
primaryColor: "#f8fafc",
|
|
133
|
+
primaryTextColor: "#1f2937",
|
|
134
|
+
primaryBorderColor: "#c3c9d2",
|
|
135
|
+
secondaryColor: "#f3f4f6",
|
|
136
|
+
secondaryTextColor: "#1f2937",
|
|
137
|
+
secondaryBorderColor: "#c3c9d2",
|
|
138
|
+
tertiaryColor: "#ffffff",
|
|
139
|
+
tertiaryTextColor: "#6b7280",
|
|
140
|
+
tertiaryBorderColor: "#e5e7eb",
|
|
141
|
+
mainBkg: "#f8fafc",
|
|
142
|
+
nodeBorder: "#c3c9d2",
|
|
143
|
+
nodeTextColor: "#1f2937",
|
|
144
|
+
textColor: "#1f2937",
|
|
145
|
+
lineColor: "#6b7280",
|
|
146
|
+
defaultLinkColor: "#6b7280",
|
|
147
|
+
titleColor: "#9a6516",
|
|
148
|
+
edgeLabelBackground: "#ffffff",
|
|
149
|
+
clusterBkg: "#f3f4f6",
|
|
150
|
+
clusterBorder: "#d7dbe0",
|
|
151
|
+
noteBkgColor: "#fdf6e8",
|
|
152
|
+
noteTextColor: "#1f2937",
|
|
153
|
+
noteBorderColor: "#9a6516",
|
|
154
|
+
errorBkgColor: "#fdecec",
|
|
155
|
+
errorTextColor: "#b42323",
|
|
156
|
+
// Sequence
|
|
157
|
+
actorBkg: "#f8fafc",
|
|
158
|
+
actorBorder: "#c3c9d2",
|
|
159
|
+
actorTextColor: "#1f2937",
|
|
160
|
+
actorLineColor: "#c3c9d2",
|
|
161
|
+
signalColor: "#6b7280",
|
|
162
|
+
signalTextColor: "#1f2937",
|
|
163
|
+
labelBoxBkgColor: "#f3f4f6",
|
|
164
|
+
labelBoxBorderColor: "#d7dbe0",
|
|
165
|
+
labelTextColor: "#1f2937",
|
|
166
|
+
loopTextColor: "#1f2937",
|
|
167
|
+
activationBkgColor: "#f3f4f6",
|
|
168
|
+
activationBorderColor: "#2f7d6b",
|
|
169
|
+
sequenceNumberColor: "#ffffff",
|
|
170
|
+
// State / class / journey
|
|
171
|
+
labelColor: "#1f2937",
|
|
172
|
+
altBackground: "#f3f4f6",
|
|
173
|
+
classText: "#1f2937",
|
|
174
|
+
// Gantt
|
|
175
|
+
sectionBkgColor: "#f8fafc",
|
|
176
|
+
altSectionBkgColor: "#ffffff",
|
|
177
|
+
sectionBkgColor2: "#f3f4f6",
|
|
178
|
+
gridColor: "#e5e7eb",
|
|
179
|
+
taskBkgColor: "#e5e7eb",
|
|
180
|
+
taskTextColor: "#1f2937",
|
|
181
|
+
taskTextOutsideColor: "#1f2937",
|
|
182
|
+
taskTextDarkColor: "#1f2937",
|
|
183
|
+
taskBorderColor: "#c3c9d2",
|
|
184
|
+
doneTaskBkgColor: "#d7dbe0",
|
|
185
|
+
doneTaskBorderColor: "#c3c9d2",
|
|
186
|
+
activeTaskBkgColor: "#e0a75a",
|
|
187
|
+
activeTaskBorderColor: "#9a6516",
|
|
188
|
+
critBkgColor: "#e08a8a",
|
|
189
|
+
critBorderColor: "#b42323",
|
|
190
|
+
todayLineColor: "#2f7d6b",
|
|
191
|
+
// Pie
|
|
192
|
+
pieTitleTextColor: "#1f2937",
|
|
193
|
+
pieSectionTextColor: "#ffffff",
|
|
194
|
+
pieLegendTextColor: "#1f2937",
|
|
195
|
+
pieStrokeColor: "#ffffff",
|
|
196
|
+
pieOuterStrokeColor: "#d7dbe0",
|
|
197
|
+
// Quadrant
|
|
198
|
+
quadrant1Fill: "#f8fafc",
|
|
199
|
+
quadrant2Fill: "#f3f4f6",
|
|
200
|
+
quadrant3Fill: "#ffffff",
|
|
201
|
+
quadrant4Fill: "#f8fafc",
|
|
202
|
+
quadrantPointFill: "#9a6516",
|
|
203
|
+
quadrantTitleFill: "#1f2937",
|
|
204
|
+
quadrantInternalBorderStrokeFill: "#e5e7eb",
|
|
205
|
+
quadrantExternalBorderStrokeFill: "#d7dbe0",
|
|
206
|
+
};
|
|
207
|
+
const SERIES_SCALES = {
|
|
208
|
+
...scale("pie", 12, true), // pie1..pie12
|
|
209
|
+
...scale("cScale", 12), // cScale0..11 (journey, timeline, xychart)
|
|
210
|
+
...scale("fillType", 8), // fillType0..7 (class/state/journey sections)
|
|
211
|
+
...scale("git", 8), // git0..git7 (gitgraph branches)
|
|
212
|
+
};
|
|
213
|
+
const THEME_VARIABLES = {
|
|
214
|
+
dark: { ...DARK, ...SERIES_SCALES },
|
|
215
|
+
light: { ...LIGHT, ...SERIES_SCALES },
|
|
216
|
+
};
|
|
217
|
+
/** Theme variables for a target surface, as mermaid's `themeVariables` object. */
|
|
218
|
+
export function mermaidThemeVariables(theme) {
|
|
219
|
+
return THEME_VARIABLES[theme];
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=mermaid-theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-theme.js","sourceRoot":"","sources":["../../src/lib/mermaid-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAI1F,oEAAoE;AACpE,0EAA0E;AAC1E,8EAA8E;AAC9E,8DAA8D;AAC9D,MAAM,IAAI,GAAG,2DAA2D,CAAC;AAEzE,kFAAkF;AAClF,MAAM,MAAM,GAAG,CAAC,GAAG,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEpF,sFAAsF;AACtF,SAAS,KAAK,CAAC,MAAc,EAAE,KAAa,EAAE,QAAQ,GAAG,KAAK;IAC5D,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,GAAG,CAAC,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC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C1B,cAAc,EAAE,SAAS;IAEzB,MAAM;IACN,iBAAiB,EAAE,SAAS;IAC5B,mBAAmB,EAAE,SAAS;IAC9B,kBAAkB,EAAE,SAAS;IAC7B,cAAc,EAAE,SAAS;IACzB,mBAAmB,EAAE,SAAS;IAE9B,WAAW;IACX,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;IACxB,iBAAiB,EAAE,SAAS;IAC5B,iBAAiB,EAAE,SAAS;IAC5B,gCAAgC,EAAE,SAAS;IAC3C,gCAAgC,EAAE,SAAS;CAC5C,CAAC;AAEF,MAAM,aAAa,GAA2B;IAC5C,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,cAAc;IACzC,GAAG,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE,2CAA2C;IACnE,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,8CAA8C;IACvE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,iCAAiC;CACtD,CAAC;AAEF,MAAM,eAAe,GAA2D;IAC9E,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,aAAa,EAAE;IACnC,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,aAAa,EAAE;CACtC,CAAC;AAEF,kFAAkF;AAClF,MAAM,UAAU,qBAAqB,CAAC,KAAmB;IACvD,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/lib/mermaid.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* cached per (theme, source), which makes the per-token re-render of a
|
|
9
9
|
* streaming message a cache hit.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
import { type MermaidTheme } from "./mermaid-theme.js";
|
|
12
|
+
export type { MermaidTheme };
|
|
12
13
|
/** Synchronous cache lookup, so a remounted block can show its SVG without a flash. */
|
|
13
14
|
export declare function peekMermaidSvg(source: string, theme?: MermaidTheme): string | null;
|
|
14
15
|
/**
|
|
@@ -43,6 +44,19 @@ export declare function replaceMermaidFences(md: string, replacement: (fence: Me
|
|
|
43
44
|
/** Pure inlining step: substitute pre-rendered SVGs (by fence index) under the budget. */
|
|
44
45
|
export declare function inlineRenderedFences(md: string, rendered: (string | null)[], budget?: number): string;
|
|
45
46
|
export declare function inlineMermaidDiagrams(md: string, theme?: MermaidTheme): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Give a mermaid SVG an intrinsic pixel size taken from its viewBox.
|
|
49
|
+
*
|
|
50
|
+
* Mermaid ships its diagrams as `style="max-width: Npx"` with no width/height
|
|
51
|
+
* attribute, which is right for a responsive page and wrong for an export: a
|
|
52
|
+
* standalone .svg file then has no intrinsic size, and the PNG/PDF renderer
|
|
53
|
+
* lays it out at the full body width no matter how small the diagram is.
|
|
54
|
+
* Sizing it here is what lets the share page shrink-wrap the figure.
|
|
55
|
+
*
|
|
56
|
+
* Returns the input unchanged when there is no parseable viewBox — an
|
|
57
|
+
* un-sized export beats a corrupted one.
|
|
58
|
+
*/
|
|
59
|
+
export declare function sizeSvgForExport(svg: string, maxWidth?: number): string;
|
|
46
60
|
/** Whether a repo path is a standalone mermaid source file (previewable as a diagram). */
|
|
47
61
|
export declare function isMermaidPath(path: string): boolean;
|
|
48
62
|
//# sourceMappingURL=mermaid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../src/lib/mermaid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,
|
|
1
|
+
{"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../src/lib/mermaid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE9E,YAAY,EAAE,YAAY,EAAE,CAAC;AA8D7B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cached per (theme, source), which makes the per-token re-render of a
|
|
9
9
|
* streaming message a cache hit.
|
|
10
10
|
*/
|
|
11
|
+
import { mermaidThemeVariables } from "./mermaid-theme.js";
|
|
11
12
|
let mermaidPromise = null;
|
|
12
13
|
function loadMermaid() {
|
|
13
14
|
if (!mermaidPromise) {
|
|
14
|
-
mermaidPromise = import("mermaid").then((mod) =>
|
|
15
|
-
const mermaid = mod.default;
|
|
16
|
-
mermaid.initialize({
|
|
17
|
-
startOnLoad: false,
|
|
18
|
-
// "strict" sanitizes label HTML and blocks script/click payloads —
|
|
19
|
-
// diagram sources arrive from the model and from repo files.
|
|
20
|
-
securityLevel: "strict",
|
|
21
|
-
// Never inject mermaid's own error SVG into the document; failures
|
|
22
|
-
// surface as a null render result and the caller shows the source.
|
|
23
|
-
suppressErrorRendering: true,
|
|
24
|
-
theme: "dark",
|
|
25
|
-
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
26
|
-
});
|
|
27
|
-
return mermaid;
|
|
28
|
-
});
|
|
15
|
+
mermaidPromise = import("mermaid").then((mod) => mod.default);
|
|
29
16
|
}
|
|
30
17
|
return mermaidPromise;
|
|
31
18
|
}
|
|
32
|
-
|
|
19
|
+
/** Config shared by both themes; only `themeVariables` differs per render. */
|
|
20
|
+
function baseConfig(theme) {
|
|
21
|
+
return {
|
|
22
|
+
startOnLoad: false,
|
|
23
|
+
// "strict" sanitizes label HTML and blocks script/click payloads —
|
|
24
|
+
// diagram sources arrive from the model and from repo files.
|
|
25
|
+
securityLevel: "strict",
|
|
26
|
+
// Never inject mermaid's own error SVG into the document; failures
|
|
27
|
+
// surface as a null render result and the caller shows the source.
|
|
28
|
+
suppressErrorRendering: true,
|
|
29
|
+
theme: "base",
|
|
30
|
+
themeVariables: mermaidThemeVariables(theme),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
* mermaid.initialize(),
|
|
36
|
-
* in-app
|
|
37
|
-
*
|
|
34
|
+
* Renders are serialized through this chain because the theme is applied by
|
|
35
|
+
* re-calling mermaid.initialize(), which mutates GLOBAL config — a dark
|
|
36
|
+
* in-app render and a light share render would otherwise race and one would
|
|
37
|
+
* come out in the other's palette.
|
|
38
|
+
*
|
|
39
|
+
* The obvious alternative, a per-diagram `%%{init: …}%%` directive, does not
|
|
40
|
+
* work: mermaid rewrites every `'` to `"` before JSON.parse-ing a directive
|
|
41
|
+
* (chunk-NSK5VX7P), so a quoted font stack makes the whole directive
|
|
42
|
+
* unparseable and it is silently dropped; and its themeVariables sanitizer
|
|
43
|
+
* rejects any value outside /^[\\d "#%(),.;A-Za-z]+$/, which blanks every
|
|
44
|
+
* hyphenated CSS keyword (`system-ui`, `-apple-system`). A dropped directive
|
|
45
|
+
* fails SILENTLY — the diagram renders in whatever the last global config
|
|
46
|
+
* was — so this path is not worth the theming it appears to buy.
|
|
38
47
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
let renderChain = Promise.resolve();
|
|
49
|
+
function serialized(fn) {
|
|
50
|
+
const run = renderChain.then(fn, fn);
|
|
51
|
+
renderChain = run.then(() => undefined, () => undefined);
|
|
52
|
+
return run;
|
|
43
53
|
}
|
|
44
54
|
const svgCache = new Map();
|
|
45
55
|
const CACHE_MAX = 100;
|
|
@@ -66,18 +76,25 @@ export async function renderMermaidSvg(source, theme = "dark") {
|
|
|
66
76
|
return hit;
|
|
67
77
|
try {
|
|
68
78
|
const mermaid = await loadMermaid();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
return await serialized(async () => {
|
|
80
|
+
// Re-check inside the lock: an identical render may have been queued
|
|
81
|
+
// ahead of this one while both were waiting.
|
|
82
|
+
const queued = svgCache.get(key);
|
|
83
|
+
if (queued !== undefined)
|
|
84
|
+
return queued;
|
|
85
|
+
mermaid.initialize(baseConfig(theme));
|
|
86
|
+
const ok = await mermaid.parse(trimmed, { suppressErrors: true });
|
|
87
|
+
if (!ok)
|
|
88
|
+
return null;
|
|
89
|
+
const { svg } = await mermaid.render(`brain-mermaid-${++renderSeq}`, trimmed);
|
|
90
|
+
if (svgCache.size >= CACHE_MAX) {
|
|
91
|
+
const oldest = svgCache.keys().next().value;
|
|
92
|
+
if (oldest !== undefined)
|
|
93
|
+
svgCache.delete(oldest);
|
|
94
|
+
}
|
|
95
|
+
svgCache.set(key, svg);
|
|
96
|
+
return svg;
|
|
97
|
+
});
|
|
81
98
|
}
|
|
82
99
|
catch {
|
|
83
100
|
return null;
|
|
@@ -151,7 +168,7 @@ export function replaceMermaidFences(md, replacement) {
|
|
|
151
168
|
* block. Used by the share pipeline: the PNG/PDF renderer runs the page with
|
|
152
169
|
* JavaScript disabled and all network denied, so the diagram must already be
|
|
153
170
|
* SVG by the time the markdown reaches the server. Defaults to the light
|
|
154
|
-
*
|
|
171
|
+
* theme to match the share template. Fences that fail to render are
|
|
155
172
|
* left as code fences — the pre-feature behavior.
|
|
156
173
|
*/
|
|
157
174
|
/**
|
|
@@ -180,13 +197,46 @@ export function inlineRenderedFences(md, rendered, budget = INLINE_BUDGET_CHARS)
|
|
|
180
197
|
return html;
|
|
181
198
|
});
|
|
182
199
|
}
|
|
183
|
-
export async function inlineMermaidDiagrams(md, theme = "
|
|
200
|
+
export async function inlineMermaidDiagrams(md, theme = "light") {
|
|
184
201
|
const fences = findMermaidFences(md);
|
|
185
202
|
if (fences.length === 0)
|
|
186
203
|
return md;
|
|
187
204
|
const rendered = await Promise.all(fences.map((f) => renderMermaidSvg(f.source, theme)));
|
|
188
205
|
return inlineRenderedFences(md, rendered);
|
|
189
206
|
}
|
|
207
|
+
const SVG_OPEN_TAG_RE = /<svg\b[^>]*>/i;
|
|
208
|
+
const VIEWBOX_RE = /\bviewBox\s*=\s*"\s*[\d.+-]+\s+[\d.+-]+\s+([\d.+-]+)\s+([\d.+-]+)\s*"/i;
|
|
209
|
+
/**
|
|
210
|
+
* Give a mermaid SVG an intrinsic pixel size taken from its viewBox.
|
|
211
|
+
*
|
|
212
|
+
* Mermaid ships its diagrams as `style="max-width: Npx"` with no width/height
|
|
213
|
+
* attribute, which is right for a responsive page and wrong for an export: a
|
|
214
|
+
* standalone .svg file then has no intrinsic size, and the PNG/PDF renderer
|
|
215
|
+
* lays it out at the full body width no matter how small the diagram is.
|
|
216
|
+
* Sizing it here is what lets the share page shrink-wrap the figure.
|
|
217
|
+
*
|
|
218
|
+
* Returns the input unchanged when there is no parseable viewBox — an
|
|
219
|
+
* un-sized export beats a corrupted one.
|
|
220
|
+
*/
|
|
221
|
+
export function sizeSvgForExport(svg, maxWidth = 1200) {
|
|
222
|
+
const open = SVG_OPEN_TAG_RE.exec(svg);
|
|
223
|
+
if (!open)
|
|
224
|
+
return svg;
|
|
225
|
+
const tag = open[0];
|
|
226
|
+
const vb = VIEWBOX_RE.exec(tag);
|
|
227
|
+
if (!vb)
|
|
228
|
+
return svg;
|
|
229
|
+
const vbW = Number(vb[1]);
|
|
230
|
+
const vbH = Number(vb[2]);
|
|
231
|
+
if (!Number.isFinite(vbW) || !Number.isFinite(vbH) || vbW <= 0 || vbH <= 0)
|
|
232
|
+
return svg;
|
|
233
|
+
const width = Math.max(1, Math.min(maxWidth, Math.round(vbW)));
|
|
234
|
+
const height = Math.max(1, Math.round((width / vbW) * vbH));
|
|
235
|
+
const sized = tag
|
|
236
|
+
.replace(/\s(?:width|height|style)\s*=\s*"[^"]*"/gi, "")
|
|
237
|
+
.replace(/<svg\b/i, `<svg width="${width}" height="${height}"`);
|
|
238
|
+
return svg.slice(0, open.index) + sized + svg.slice(open.index + tag.length);
|
|
239
|
+
}
|
|
190
240
|
/** Whether a repo path is a standalone mermaid source file (previewable as a diagram). */
|
|
191
241
|
export function isMermaidPath(path) {
|
|
192
242
|
return /\.(mmd|mermaid)$/i.test(path);
|
package/dist/lib/mermaid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid.js","sourceRoot":"","sources":["../../src/lib/mermaid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"mermaid.js","sourceRoot":"","sources":["../../src/lib/mermaid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qBAAqB,EAAqB,MAAM,oBAAoB,CAAC;AAM9E,IAAI,cAAc,GAA+B,IAAI,CAAC;AAEtD,SAAS,WAAW;IAClB,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,8EAA8E;AAC9E,SAAS,UAAU,CAAC,KAAmB;IACrC,OAAO;QACL,WAAW,EAAE,KAAK;QAClB,mEAAmE;QACnE,6DAA6D;QAC7D,aAAa,EAAE,QAAiB;QAChC,mEAAmE;QACnE,mEAAmE;QACnE,sBAAsB,EAAE,IAAI;QAC5B,KAAK,EAAE,MAAe;QACtB,cAAc,EAAE,qBAAqB,CAAC,KAAK,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,IAAI,WAAW,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;AAEtD,SAAS,UAAU,CAAI,EAAoB;IACzC,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACrC,WAAW,GAAG,GAAG,CAAC,IAAI,CACpB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;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