@schlessera/brain-ui-react 0.7.2 → 0.9.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.
Files changed (72) hide show
  1. package/dist/components/chat/brain-markdown.d.ts.map +1 -1
  2. package/dist/components/chat/brain-markdown.js +93 -55
  3. package/dist/components/chat/brain-markdown.js.map +1 -1
  4. package/dist/components/chat/chat-page.d.ts.map +1 -1
  5. package/dist/components/chat/chat-page.js +10 -1
  6. package/dist/components/chat/chat-page.js.map +1 -1
  7. package/dist/components/chat/copy-button.d.ts +6 -0
  8. package/dist/components/chat/copy-button.d.ts.map +1 -0
  9. package/dist/components/chat/copy-button.js +16 -0
  10. package/dist/components/chat/copy-button.js.map +1 -0
  11. package/dist/components/chat/mermaid-block.d.ts +14 -0
  12. package/dist/components/chat/mermaid-block.d.ts.map +1 -0
  13. package/dist/components/chat/mermaid-block.js +55 -0
  14. package/dist/components/chat/mermaid-block.js.map +1 -0
  15. package/dist/components/chat/mermaid-share.d.ts +5 -0
  16. package/dist/components/chat/mermaid-share.d.ts.map +1 -0
  17. package/dist/components/chat/mermaid-share.js +80 -0
  18. package/dist/components/chat/mermaid-share.js.map +1 -0
  19. package/dist/components/chat/mermaid-viewer.d.ts +6 -0
  20. package/dist/components/chat/mermaid-viewer.d.ts.map +1 -0
  21. package/dist/components/chat/mermaid-viewer.js +266 -0
  22. package/dist/components/chat/mermaid-viewer.js.map +1 -0
  23. package/dist/components/chat/message-share.d.ts.map +1 -1
  24. package/dist/components/chat/message-share.js +7 -4
  25. package/dist/components/chat/message-share.js.map +1 -1
  26. package/dist/components/chat/share-block.d.ts.map +1 -1
  27. package/dist/components/chat/share-block.js +5 -2
  28. package/dist/components/chat/share-block.js.map +1 -1
  29. package/dist/components/files/file-viewer.d.ts.map +1 -1
  30. package/dist/components/files/file-viewer.js +30 -5
  31. package/dist/components/files/file-viewer.js.map +1 -1
  32. package/dist/components/share/share-menu.d.ts +8 -1
  33. package/dist/components/share/share-menu.d.ts.map +1 -1
  34. package/dist/components/share/share-menu.js +10 -5
  35. package/dist/components/share/share-menu.js.map +1 -1
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +4 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/lib/client-environment.d.ts +29 -0
  41. package/dist/lib/client-environment.d.ts.map +1 -0
  42. package/dist/lib/client-environment.js +153 -0
  43. package/dist/lib/client-environment.js.map +1 -0
  44. package/dist/lib/mermaid-theme.d.ts +4 -0
  45. package/dist/lib/mermaid-theme.d.ts.map +1 -0
  46. package/dist/lib/mermaid-theme.js +221 -0
  47. package/dist/lib/mermaid-theme.js.map +1 -0
  48. package/dist/lib/mermaid.d.ts +62 -0
  49. package/dist/lib/mermaid.d.ts.map +1 -0
  50. package/dist/lib/mermaid.js +244 -0
  51. package/dist/lib/mermaid.js.map +1 -0
  52. package/dist/stores/file-store.d.ts.map +1 -1
  53. package/dist/stores/file-store.js +9 -2
  54. package/dist/stores/file-store.js.map +1 -1
  55. package/dist/styles.css +1 -1
  56. package/package.json +3 -2
  57. package/src/components/chat/brain-markdown.tsx +109 -80
  58. package/src/components/chat/chat-page.tsx +20 -1
  59. package/src/components/chat/copy-button.tsx +26 -0
  60. package/src/components/chat/mermaid-block.tsx +106 -0
  61. package/src/components/chat/mermaid-share.ts +91 -0
  62. package/src/components/chat/mermaid-viewer.tsx +336 -0
  63. package/src/components/chat/message-share.ts +7 -4
  64. package/src/components/chat/share-block.tsx +5 -2
  65. package/src/components/files/file-viewer.tsx +37 -5
  66. package/src/components/share/share-menu.tsx +20 -6
  67. package/src/index.ts +5 -0
  68. package/src/lib/client-environment.ts +152 -0
  69. package/src/lib/mermaid-theme.ts +246 -0
  70. package/src/lib/mermaid.ts +287 -0
  71. package/src/stores/file-store.ts +12 -2
  72. package/src/theme.css +10 -0
@@ -17,8 +17,17 @@ interface ShareMenuProps {
17
17
  title?: string;
18
18
  /** When provided, override the default icon button with a custom trigger. */
19
19
  className?: string;
20
- /** Optional render-prop for a custom trigger; receives the click handler. */
21
- renderTrigger?: (props: { onClick: () => void; busy: boolean }) => React.ReactNode;
20
+ /**
21
+ * Optional render-prop for a custom trigger. Receives the click handler plus
22
+ * the status icon, so a custom trigger keeps the busy/done/error feedback
23
+ * instead of silently swallowing it.
24
+ */
25
+ renderTrigger?: (props: {
26
+ onClick: () => void;
27
+ busy: boolean;
28
+ status: Status;
29
+ icon: React.ReactNode;
30
+ }) => React.ReactNode;
22
31
  }
23
32
 
24
33
  type Status = "idle" | "busy" | "done" | "error";
@@ -35,13 +44,18 @@ export function ShareMenu({ options, title = "Share", className, renderTrigger }
35
44
  if (!wrapperRef.current?.contains(e.target as Node)) setOpen(false);
36
45
  };
37
46
  const onKey = (e: KeyboardEvent) => {
38
- if (e.key === "Escape") setOpen(false);
47
+ if (e.key !== "Escape") return;
48
+ // Captured and stopped: an Escape that dismisses this menu must not also
49
+ // reach whatever the menu is layered over (the diagram viewer closes on
50
+ // Escape too, and dismissing both at once reads as a bug).
51
+ e.stopPropagation();
52
+ setOpen(false);
39
53
  };
40
54
  document.addEventListener("mousedown", onDocClick);
41
- document.addEventListener("keydown", onKey);
55
+ document.addEventListener("keydown", onKey, true);
42
56
  return () => {
43
57
  document.removeEventListener("mousedown", onDocClick);
44
- document.removeEventListener("keydown", onKey);
58
+ document.removeEventListener("keydown", onKey, true);
45
59
  };
46
60
  }, [open]);
47
61
 
@@ -87,7 +101,7 @@ export function ShareMenu({ options, title = "Share", className, renderTrigger }
87
101
  return (
88
102
  <div ref={wrapperRef} className={cn("relative inline-flex", className)}>
89
103
  {renderTrigger ? (
90
- renderTrigger({ onClick: handleTrigger, busy: status === "busy" })
104
+ renderTrigger({ onClick: handleTrigger, busy: status === "busy", status, icon })
91
105
  ) : (
92
106
  <button
93
107
  onClick={handleTrigger}
package/src/index.ts CHANGED
@@ -20,6 +20,11 @@ export { GraphPage } from "./components/graph/graph-page.js";
20
20
  // Markdown renderer (also useful standalone, e.g. for a dev kitchen sink).
21
21
  export { BrainMarkdown } from "./components/chat/brain-markdown.js";
22
22
 
23
+ // Mermaid: standalone diagram block (streaming-safe) + the fence-to-SVG
24
+ // inliner the share pipeline uses before handing markdown to the no-JS renderer.
25
+ export { MermaidBlock } from "./components/chat/mermaid-block.js";
26
+ export { inlineMermaidDiagrams, renderMermaidSvg } from "./lib/mermaid.js";
27
+
23
28
  // Stores + selectors the shell reads (service-worker busy check, deep links).
24
29
  export {
25
30
  useChatStore,
@@ -0,0 +1,152 @@
1
+ import type { ClientEnvironment } from "@schlessera/brain-ui-sdk/protocol";
2
+
3
+ /**
4
+ * What this browser can actually do, measured rather than guessed.
5
+ *
6
+ * The agent is told this so it stops offering things the device can't do —
7
+ * "share that to WhatsApp" on a desktop with no share sheet, "take a photo of
8
+ * it" on a machine with no camera, "I'll check where you are" with
9
+ * geolocation unavailable. Every check is feature detection; nothing here
10
+ * parses a user-agent string, which is both unreliable and a fingerprinting
11
+ * surface we have no use for.
12
+ *
13
+ * Deliberately NOT included: anything that would prompt. Device presence is
14
+ * read from enumerateDevices(), which reports KINDS without permission (labels
15
+ * stay empty) — asking the reader for camera permission in order to write a
16
+ * system prompt would be a hostile trade.
17
+ */
18
+
19
+ /** Marks the element whose width is the actual reading column. */
20
+ export const READING_COLUMN_ATTR = "data-reading-column";
21
+
22
+ /** Cached device inventory; undefined until the async probe has answered once. */
23
+ let mediaKinds: { camera: boolean; microphone: boolean } | undefined;
24
+ let probing = false;
25
+ let deviceListenerBound = false;
26
+
27
+ /**
28
+ * Ask which input devices exist. Cheap, permission-free, and async — so it is
29
+ * primed in the background and read synchronously at send time. The first
30
+ * message of a session may go out without the camera/mic facts rather than
31
+ * blocking on a device enumeration.
32
+ */
33
+ export async function primeClientEnvironment(force = false): Promise<void> {
34
+ if ((mediaKinds && !force) || probing) return;
35
+ if (typeof navigator === "undefined") return;
36
+ const media = navigator.mediaDevices;
37
+ if (!media || typeof media.enumerateDevices !== "function") return;
38
+ probing = true;
39
+ try {
40
+ const devices = await media.enumerateDevices();
41
+ mediaKinds = {
42
+ camera: devices.some((d) => d.kind === "videoinput"),
43
+ microphone: devices.some((d) => d.kind === "audioinput"),
44
+ };
45
+ // A headset plugged in (or a webcam unplugged) mid-conversation changes
46
+ // the honest answer, so the cache follows the hardware.
47
+ if (!deviceListenerBound && typeof media.addEventListener === "function") {
48
+ deviceListenerBound = true;
49
+ media.addEventListener("devicechange", () => void primeClientEnvironment(true));
50
+ }
51
+ } catch {
52
+ // Enumeration blocked (permissions policy, older browser) — leave the
53
+ // capability unreported rather than guessing it exists.
54
+ } finally {
55
+ probing = false;
56
+ }
57
+ }
58
+
59
+ /** @internal Test seam — drops the cached device inventory. */
60
+ export function resetClientEnvironmentCache(): void {
61
+ mediaKinds = undefined;
62
+ probing = false;
63
+ deviceListenerBound = false;
64
+ }
65
+
66
+ export function detectClientEnvironment(): ClientEnvironment | undefined {
67
+ if (typeof window === "undefined" || typeof navigator === "undefined") return undefined;
68
+ // Fire-and-forget: answers by the next message even if this one misses it.
69
+ void primeClientEnvironment();
70
+
71
+ const coarse = matches("(pointer: coarse)");
72
+ const env: ClientEnvironment = { formFactor: formFactor(coarse) };
73
+
74
+ if (coarse) env.touch = true;
75
+ if (matches("(display-mode: standalone)") || matches("(display-mode: fullscreen)")) {
76
+ env.standalone = true;
77
+ }
78
+
79
+ if (mediaKinds?.camera) env.camera = true;
80
+ if (mediaKinds?.microphone) env.microphone = true;
81
+ // getUserMedia and geolocation both require a secure context, which is also
82
+ // what the location tool needs.
83
+ if (navigator.geolocation && window.isSecureContext !== false) env.geolocation = true;
84
+
85
+ if (typeof navigator.share === "function") {
86
+ env.share = true;
87
+ // canShare({files}) needs a real File to answer honestly; a 1-byte probe
88
+ // is what the share paths themselves check before offering an image.
89
+ try {
90
+ const probe = new File([new Uint8Array(1)], "probe.png", { type: "image/png" });
91
+ if (typeof navigator.canShare === "function" && navigator.canShare({ files: [probe] })) {
92
+ env.shareFiles = true;
93
+ }
94
+ } catch {
95
+ // No File constructor / canShare threw — leave shareFiles unset.
96
+ }
97
+ }
98
+
99
+ const column = readingColumnWidth();
100
+ if (column) env.viewportWidth = column;
101
+
102
+ // Both are re-validated server-side against the platform's own locale and
103
+ // timezone databases; anything unrecognized is dropped there.
104
+ const locale = navigator.language;
105
+ if (locale && locale.length <= 35) env.locale = locale;
106
+ try {
107
+ const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
108
+ if (zone && zone.length <= 64) env.timeZone = zone;
109
+ } catch {
110
+ // Intl unavailable — omit.
111
+ }
112
+
113
+ return env;
114
+ }
115
+
116
+ /**
117
+ * Phone vs tablet from the SHORT edge of the screen, not from the current
118
+ * window width: a phone in landscape is 900+px wide and would otherwise be
119
+ * reported as a tablet, flipping the device description (and busting the
120
+ * prompt cache) every time the reader rotates.
121
+ */
122
+ function formFactor(coarse: boolean): ClientEnvironment["formFactor"] {
123
+ if (!coarse) return "desktop";
124
+ const w = window.screen?.width ?? window.innerWidth ?? 0;
125
+ const h = window.screen?.height ?? window.innerHeight ?? 0;
126
+ const shortEdge = w && h ? Math.min(w, h) : w || h;
127
+ return shortEdge && shortEdge >= 600 ? "tablet" : "phone";
128
+ }
129
+
130
+ /**
131
+ * Width of the column text actually renders into — the chat layout caps it far
132
+ * below the window — rounded to 50px so that dragging a window edge does not
133
+ * rewrite the system prompt (and invalidate its cache) on every message.
134
+ */
135
+ function readingColumnWidth(): number | undefined {
136
+ const el = document.querySelector(`[${READING_COLUMN_ATTR}]`);
137
+ const measured =
138
+ el?.getBoundingClientRect().width ||
139
+ window.innerWidth ||
140
+ document.documentElement?.clientWidth ||
141
+ 0;
142
+ if (!measured) return undefined;
143
+ return Math.max(50, Math.round(measured / 50) * 50);
144
+ }
145
+
146
+ function matches(query: string): boolean {
147
+ try {
148
+ return typeof window.matchMedia === "function" && window.matchMedia(query).matches;
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
@@ -0,0 +1,246 @@
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
+
20
+ export type MermaidTheme = "dark" | "light";
21
+
22
+ // These variables reach mermaid through initialize(), NOT through a
23
+ // `%%{init: …}%%` directive: mermaid's directive path rewrites `'` to `"`
24
+ // before parsing the JSON and drops any themeVariable containing a hyphen, so
25
+ // a font stack cannot survive it. See the note in mermaid.ts.
26
+ const SANS = '"Plus Jakarta Sans", system-ui, -apple-system, sans-serif';
27
+
28
+ /** Ordered series colors, long enough for the 12-slot scales mermaid asks for. */
29
+ const SERIES = [...CATEGORICAL_SLOTS, OTHER_COLOR, "#67b8e3", "#eab354", "#b197d4"];
30
+
31
+ /** Expand a scale into the `${prefix}0..count-1` (or 1-based) shape mermaid wants. */
32
+ function scale(prefix: string, count: number, oneBased = false): Record<string, string> {
33
+ const out: Record<string, string> = {};
34
+ for (let i = 0; i < count; i++) {
35
+ out[`${prefix}${oneBased ? i + 1 : i}`] = SERIES[i % SERIES.length];
36
+ }
37
+ return out;
38
+ }
39
+
40
+ /**
41
+ * Dark: the in-app palette. Node fills use `--color-surface-overlay` so nodes
42
+ * sit a step above the block's own `--color-surface` plate, and borders use
43
+ * #3d4150 rather than `--color-border` (#2a2d35) — a 1px border at the token
44
+ * value all but disappears against the plate at diagram scale.
45
+ */
46
+ const DARK: Record<string, string | boolean> = {
47
+ darkMode: true,
48
+ background: "#141619",
49
+ fontFamily: SANS,
50
+ fontSize: "14px",
51
+
52
+ primaryColor: "#1e2128",
53
+ primaryTextColor: "#e8e4df",
54
+ primaryBorderColor: "#3d4150",
55
+ secondaryColor: "#1a1d22",
56
+ secondaryTextColor: "#e8e4df",
57
+ secondaryBorderColor: "#3d4150",
58
+ tertiaryColor: "#0c0e12",
59
+ tertiaryTextColor: "#8a8691",
60
+ tertiaryBorderColor: "#2a2d35",
61
+
62
+ mainBkg: "#1e2128",
63
+ nodeBorder: "#3d4150",
64
+ nodeTextColor: "#e8e4df",
65
+ textColor: "#e8e4df",
66
+ lineColor: "#8a8691",
67
+ defaultLinkColor: "#8a8691",
68
+ titleColor: "#e09f3e",
69
+ edgeLabelBackground: "#141619",
70
+ clusterBkg: "#0c0e12",
71
+ clusterBorder: "#2a2d35",
72
+
73
+ noteBkgColor: "#1a1d22",
74
+ noteTextColor: "#e8e4df",
75
+ noteBorderColor: "#e09f3e",
76
+ errorBkgColor: "#2a1a1a",
77
+ errorTextColor: "#f87171",
78
+
79
+ // Sequence
80
+ actorBkg: "#1e2128",
81
+ actorBorder: "#3d4150",
82
+ actorTextColor: "#e8e4df",
83
+ actorLineColor: "#3d4150",
84
+ signalColor: "#8a8691",
85
+ signalTextColor: "#e8e4df",
86
+ labelBoxBkgColor: "#1a1d22",
87
+ labelBoxBorderColor: "#2a2d35",
88
+ labelTextColor: "#e8e4df",
89
+ loopTextColor: "#e8e4df",
90
+ activationBkgColor: "#1a1d22",
91
+ activationBorderColor: "#5bb5a2",
92
+ sequenceNumberColor: "#0c0e12",
93
+
94
+ // State / class / journey
95
+ labelColor: "#e8e4df",
96
+ altBackground: "#0c0e12",
97
+ classText: "#e8e4df",
98
+
99
+ // Gantt
100
+ sectionBkgColor: "#1a1d22",
101
+ altSectionBkgColor: "#141619",
102
+ sectionBkgColor2: "#1e2128",
103
+ gridColor: "#2a2d35",
104
+ taskBkgColor: "#2a2d35",
105
+ taskTextColor: "#e8e4df",
106
+ taskTextOutsideColor: "#e8e4df",
107
+ taskTextDarkColor: "#0c0e12",
108
+ taskBorderColor: "#3d4150",
109
+ doneTaskBkgColor: "#565b66",
110
+ doneTaskBorderColor: "#3d4150",
111
+ activeTaskBkgColor: "#e09f3e",
112
+ activeTaskBorderColor: "#e09f3e",
113
+ critBkgColor: "#d03b3b",
114
+ critBorderColor: "#d03b3b",
115
+ todayLineColor: "#5bb5a2",
116
+
117
+ // Pie
118
+ pieTitleTextColor: "#e8e4df",
119
+ pieSectionTextColor: "#0c0e12",
120
+ pieLegendTextColor: "#e8e4df",
121
+ pieStrokeColor: "#141619",
122
+ pieOuterStrokeColor: "#2a2d35",
123
+
124
+ // Quadrant / requirement / misc surfaces that don't inherit cleanly
125
+ quadrant1Fill: "#1e2128",
126
+ quadrant2Fill: "#1a1d22",
127
+ quadrant3Fill: "#141619",
128
+ quadrant4Fill: "#1e2128",
129
+ quadrantPointFill: "#e09f3e",
130
+ quadrantTitleFill: "#e8e4df",
131
+ quadrantInternalBorderStrokeFill: "#2a2d35",
132
+ quadrantExternalBorderStrokeFill: "#3d4150",
133
+ };
134
+
135
+ /**
136
+ * Light: what the share renderer emits. Tuned against the PNG/PDF template's
137
+ * own palette (`ui-server/src/render/template.ts`: #ffffff page, #f8fafc
138
+ * surface, #e5e7eb border, #1f2937 text) so a diagram doesn't look pasted in.
139
+ * The amber and teal are darkened from the app tokens — #e09f3e on white is a
140
+ * 1.9:1 line, unusable for edges or titles.
141
+ */
142
+ const LIGHT: Record<string, string | boolean> = {
143
+ darkMode: false,
144
+ background: "#ffffff",
145
+ fontFamily: SANS,
146
+ fontSize: "14px",
147
+
148
+ primaryColor: "#f8fafc",
149
+ primaryTextColor: "#1f2937",
150
+ primaryBorderColor: "#c3c9d2",
151
+ secondaryColor: "#f3f4f6",
152
+ secondaryTextColor: "#1f2937",
153
+ secondaryBorderColor: "#c3c9d2",
154
+ tertiaryColor: "#ffffff",
155
+ tertiaryTextColor: "#6b7280",
156
+ tertiaryBorderColor: "#e5e7eb",
157
+
158
+ mainBkg: "#f8fafc",
159
+ nodeBorder: "#c3c9d2",
160
+ nodeTextColor: "#1f2937",
161
+ textColor: "#1f2937",
162
+ lineColor: "#6b7280",
163
+ defaultLinkColor: "#6b7280",
164
+ titleColor: "#9a6516",
165
+ edgeLabelBackground: "#ffffff",
166
+ clusterBkg: "#f3f4f6",
167
+ clusterBorder: "#d7dbe0",
168
+
169
+ noteBkgColor: "#fdf6e8",
170
+ noteTextColor: "#1f2937",
171
+ noteBorderColor: "#9a6516",
172
+ errorBkgColor: "#fdecec",
173
+ errorTextColor: "#b42323",
174
+
175
+ // Sequence
176
+ actorBkg: "#f8fafc",
177
+ actorBorder: "#c3c9d2",
178
+ actorTextColor: "#1f2937",
179
+ actorLineColor: "#c3c9d2",
180
+ signalColor: "#6b7280",
181
+ signalTextColor: "#1f2937",
182
+ labelBoxBkgColor: "#f3f4f6",
183
+ labelBoxBorderColor: "#d7dbe0",
184
+ labelTextColor: "#1f2937",
185
+ loopTextColor: "#1f2937",
186
+ activationBkgColor: "#f3f4f6",
187
+ activationBorderColor: "#2f7d6b",
188
+ sequenceNumberColor: "#ffffff",
189
+
190
+ // State / class / journey
191
+ labelColor: "#1f2937",
192
+ altBackground: "#f3f4f6",
193
+ classText: "#1f2937",
194
+
195
+ // Gantt
196
+ sectionBkgColor: "#f8fafc",
197
+ altSectionBkgColor: "#ffffff",
198
+ sectionBkgColor2: "#f3f4f6",
199
+ gridColor: "#e5e7eb",
200
+ taskBkgColor: "#e5e7eb",
201
+ taskTextColor: "#1f2937",
202
+ taskTextOutsideColor: "#1f2937",
203
+ taskTextDarkColor: "#1f2937",
204
+ taskBorderColor: "#c3c9d2",
205
+ doneTaskBkgColor: "#d7dbe0",
206
+ doneTaskBorderColor: "#c3c9d2",
207
+ activeTaskBkgColor: "#e0a75a",
208
+ activeTaskBorderColor: "#9a6516",
209
+ critBkgColor: "#e08a8a",
210
+ critBorderColor: "#b42323",
211
+ todayLineColor: "#2f7d6b",
212
+
213
+ // Pie
214
+ pieTitleTextColor: "#1f2937",
215
+ pieSectionTextColor: "#ffffff",
216
+ pieLegendTextColor: "#1f2937",
217
+ pieStrokeColor: "#ffffff",
218
+ pieOuterStrokeColor: "#d7dbe0",
219
+
220
+ // Quadrant
221
+ quadrant1Fill: "#f8fafc",
222
+ quadrant2Fill: "#f3f4f6",
223
+ quadrant3Fill: "#ffffff",
224
+ quadrant4Fill: "#f8fafc",
225
+ quadrantPointFill: "#9a6516",
226
+ quadrantTitleFill: "#1f2937",
227
+ quadrantInternalBorderStrokeFill: "#e5e7eb",
228
+ quadrantExternalBorderStrokeFill: "#d7dbe0",
229
+ };
230
+
231
+ const SERIES_SCALES: Record<string, string> = {
232
+ ...scale("pie", 12, true), // pie1..pie12
233
+ ...scale("cScale", 12), // cScale0..11 (journey, timeline, xychart)
234
+ ...scale("fillType", 8), // fillType0..7 (class/state/journey sections)
235
+ ...scale("git", 8), // git0..git7 (gitgraph branches)
236
+ };
237
+
238
+ const THEME_VARIABLES: Record<MermaidTheme, Record<string, string | boolean>> = {
239
+ dark: { ...DARK, ...SERIES_SCALES },
240
+ light: { ...LIGHT, ...SERIES_SCALES },
241
+ };
242
+
243
+ /** Theme variables for a target surface, as mermaid's `themeVariables` object. */
244
+ export function mermaidThemeVariables(theme: MermaidTheme): Record<string, string | boolean> {
245
+ return THEME_VARIABLES[theme];
246
+ }