@cerebriline/ui 0.0.0-stage → 4.100.313

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 (222) hide show
  1. package/ADOPTION.md +833 -0
  2. package/LICENSE +201 -0
  3. package/RADIX-COLORS-LICENSE +21 -0
  4. package/README.md +427 -2
  5. package/components/agent-approval-card.css +70 -0
  6. package/components/agent-approval-card.tsx +109 -0
  7. package/components/agent-ask-question.css +103 -0
  8. package/components/agent-ask-question.tsx +276 -0
  9. package/components/agent-aurora.css +228 -0
  10. package/components/agent-aurora.tsx +96 -0
  11. package/components/agent-changes.css +13 -0
  12. package/components/agent-changes.tsx +167 -0
  13. package/components/agent-chat/agent-chat.css +556 -0
  14. package/components/agent-chat/index.tsx +1037 -0
  15. package/components/agent-chat/tool-diff.tsx +165 -0
  16. package/components/agent-chat/tool-summary/agents.ts +114 -0
  17. package/components/agent-chat/tool-summary/diff.ts +152 -0
  18. package/components/agent-chat/tool-summary/index.ts +928 -0
  19. package/components/agent-chat/tool-summary/parsers.ts +611 -0
  20. package/components/agent-chat/tool-summary/paths.ts +84 -0
  21. package/components/agent-chat/tool-summary/team.ts +401 -0
  22. package/components/agent-command-output.tsx +63 -0
  23. package/components/agent-composer.tsx +263 -0
  24. package/components/agent-context-usage.tsx +181 -0
  25. package/components/agent-conversation-layout.tsx +139 -0
  26. package/components/agent-hero-heading.css +53 -0
  27. package/components/agent-hero-heading.tsx +45 -0
  28. package/components/agent-image-lightbox.tsx +48 -0
  29. package/components/agent-prompt-queue.css +20 -0
  30. package/components/agent-prompt-queue.tsx +350 -0
  31. package/components/agent-pull-request-bar.css +13 -0
  32. package/components/agent-pull-request-bar.tsx +346 -0
  33. package/components/agent-quick-actions.css +19 -0
  34. package/components/agent-quick-actions.tsx +70 -0
  35. package/components/agent-session-row.tsx +183 -0
  36. package/components/agent-welcome-hero-pointer.ts +199 -0
  37. package/components/agent-welcome-hero.css +205 -0
  38. package/components/agent-welcome-hero.tsx +68 -0
  39. package/components/attachment-drop-zone.tsx +154 -0
  40. package/components/badge.tsx +21 -0
  41. package/components/button.tsx +324 -0
  42. package/components/generated-media.tsx +173 -0
  43. package/components/github-icon.tsx +19 -0
  44. package/components/index.ts +133 -0
  45. package/components/markdown.css +490 -0
  46. package/components/markdown.ts +365 -0
  47. package/components/mermaid-block.tsx +722 -0
  48. package/components/mermaid-diagram.ts +1260 -0
  49. package/components/mermaid-dom.ts +301 -0
  50. package/components/message-scroller.css +118 -0
  51. package/components/message-scroller.tsx +114 -0
  52. package/components/search-combobox.css +67 -0
  53. package/components/search-combobox.tsx +433 -0
  54. package/components/session-status.css +19 -0
  55. package/components/session-status.tsx +39 -0
  56. package/components/switch.css +221 -0
  57. package/components/switch.tsx +48 -0
  58. package/components.css +16 -0
  59. package/dist/components/agent-approval-card.d.ts +14 -0
  60. package/dist/components/agent-approval-card.d.ts.map +1 -0
  61. package/dist/components/agent-approval-card.js +12 -0
  62. package/dist/components/agent-approval-card.js.map +1 -0
  63. package/dist/components/agent-ask-question.d.ts +18 -0
  64. package/dist/components/agent-ask-question.d.ts.map +1 -0
  65. package/dist/components/agent-ask-question.js +101 -0
  66. package/dist/components/agent-ask-question.js.map +1 -0
  67. package/dist/components/agent-aurora.d.ts +3 -0
  68. package/dist/components/agent-aurora.d.ts.map +1 -0
  69. package/dist/components/agent-aurora.js +60 -0
  70. package/dist/components/agent-aurora.js.map +1 -0
  71. package/dist/components/agent-changes.d.ts +26 -0
  72. package/dist/components/agent-changes.d.ts.map +1 -0
  73. package/dist/components/agent-changes.js +19 -0
  74. package/dist/components/agent-changes.js.map +1 -0
  75. package/dist/components/agent-chat/disclosure.d.ts +25 -0
  76. package/dist/components/agent-chat/disclosure.d.ts.map +1 -0
  77. package/dist/components/agent-chat/disclosure.js +39 -0
  78. package/dist/components/agent-chat/disclosure.js.map +1 -0
  79. package/dist/components/agent-chat/index.d.ts +140 -0
  80. package/dist/components/agent-chat/index.d.ts.map +1 -0
  81. package/dist/components/agent-chat/index.js +379 -0
  82. package/dist/components/agent-chat/index.js.map +1 -0
  83. package/dist/components/agent-chat/tool-diff.d.ts +32 -0
  84. package/dist/components/agent-chat/tool-diff.d.ts.map +1 -0
  85. package/dist/components/agent-chat/tool-diff.js +97 -0
  86. package/dist/components/agent-chat/tool-diff.js.map +1 -0
  87. package/dist/components/agent-chat/tool-summary/agents.d.ts +10 -0
  88. package/dist/components/agent-chat/tool-summary/agents.d.ts.map +1 -0
  89. package/dist/components/agent-chat/tool-summary/agents.js +100 -0
  90. package/dist/components/agent-chat/tool-summary/agents.js.map +1 -0
  91. package/dist/components/agent-chat/tool-summary/diff.d.ts +22 -0
  92. package/dist/components/agent-chat/tool-summary/diff.d.ts.map +1 -0
  93. package/dist/components/agent-chat/tool-summary/diff.js +127 -0
  94. package/dist/components/agent-chat/tool-summary/diff.js.map +1 -0
  95. package/dist/components/agent-chat/tool-summary/index.d.ts +145 -0
  96. package/dist/components/agent-chat/tool-summary/index.d.ts.map +1 -0
  97. package/dist/components/agent-chat/tool-summary/index.js +663 -0
  98. package/dist/components/agent-chat/tool-summary/index.js.map +1 -0
  99. package/dist/components/agent-chat/tool-summary/parsers.d.ts +114 -0
  100. package/dist/components/agent-chat/tool-summary/parsers.d.ts.map +1 -0
  101. package/dist/components/agent-chat/tool-summary/parsers.js +502 -0
  102. package/dist/components/agent-chat/tool-summary/parsers.js.map +1 -0
  103. package/dist/components/agent-chat/tool-summary/paths.d.ts +10 -0
  104. package/dist/components/agent-chat/tool-summary/paths.d.ts.map +1 -0
  105. package/dist/components/agent-chat/tool-summary/paths.js +88 -0
  106. package/dist/components/agent-chat/tool-summary/paths.js.map +1 -0
  107. package/dist/components/agent-chat/tool-summary/team.d.ts +16 -0
  108. package/dist/components/agent-chat/tool-summary/team.d.ts.map +1 -0
  109. package/dist/components/agent-chat/tool-summary/team.js +283 -0
  110. package/dist/components/agent-chat/tool-summary/team.js.map +1 -0
  111. package/dist/components/agent-command-output.d.ts +14 -0
  112. package/dist/components/agent-command-output.d.ts.map +1 -0
  113. package/dist/components/agent-command-output.js +22 -0
  114. package/dist/components/agent-command-output.js.map +1 -0
  115. package/dist/components/agent-composer.d.ts +34 -0
  116. package/dist/components/agent-composer.d.ts.map +1 -0
  117. package/dist/components/agent-composer.js +65 -0
  118. package/dist/components/agent-composer.js.map +1 -0
  119. package/dist/components/agent-context-usage.d.ts +28 -0
  120. package/dist/components/agent-context-usage.d.ts.map +1 -0
  121. package/dist/components/agent-context-usage.js +51 -0
  122. package/dist/components/agent-context-usage.js.map +1 -0
  123. package/dist/components/agent-conversation-layout.d.ts +30 -0
  124. package/dist/components/agent-conversation-layout.d.ts.map +1 -0
  125. package/dist/components/agent-conversation-layout.js +24 -0
  126. package/dist/components/agent-conversation-layout.js.map +1 -0
  127. package/dist/components/agent-hero-heading.d.ts +2 -0
  128. package/dist/components/agent-hero-heading.d.ts.map +1 -0
  129. package/dist/components/agent-hero-heading.js +20 -0
  130. package/dist/components/agent-hero-heading.js.map +1 -0
  131. package/dist/components/agent-image-lightbox.d.ts +11 -0
  132. package/dist/components/agent-image-lightbox.d.ts.map +1 -0
  133. package/dist/components/agent-image-lightbox.js +8 -0
  134. package/dist/components/agent-image-lightbox.js.map +1 -0
  135. package/dist/components/agent-prompt-queue.d.ts +14 -0
  136. package/dist/components/agent-prompt-queue.d.ts.map +1 -0
  137. package/dist/components/agent-prompt-queue.js +114 -0
  138. package/dist/components/agent-prompt-queue.js.map +1 -0
  139. package/dist/components/agent-pull-request-bar.d.ts +72 -0
  140. package/dist/components/agent-pull-request-bar.d.ts.map +1 -0
  141. package/dist/components/agent-pull-request-bar.js +90 -0
  142. package/dist/components/agent-pull-request-bar.js.map +1 -0
  143. package/dist/components/agent-quick-actions.d.ts +14 -0
  144. package/dist/components/agent-quick-actions.d.ts.map +1 -0
  145. package/dist/components/agent-quick-actions.js +12 -0
  146. package/dist/components/agent-quick-actions.js.map +1 -0
  147. package/dist/components/agent-session-row.d.ts +45 -0
  148. package/dist/components/agent-session-row.d.ts.map +1 -0
  149. package/dist/components/agent-session-row.js +34 -0
  150. package/dist/components/agent-session-row.js.map +1 -0
  151. package/dist/components/agent-welcome-hero-pointer.d.ts +3 -0
  152. package/dist/components/agent-welcome-hero-pointer.d.ts.map +1 -0
  153. package/dist/components/agent-welcome-hero-pointer.js +169 -0
  154. package/dist/components/agent-welcome-hero-pointer.js.map +1 -0
  155. package/dist/components/agent-welcome-hero.d.ts +9 -0
  156. package/dist/components/agent-welcome-hero.d.ts.map +1 -0
  157. package/dist/components/agent-welcome-hero.js +14 -0
  158. package/dist/components/agent-welcome-hero.js.map +1 -0
  159. package/dist/components/attachment-drop-zone.d.ts +15 -0
  160. package/dist/components/attachment-drop-zone.d.ts.map +1 -0
  161. package/dist/components/attachment-drop-zone.js +64 -0
  162. package/dist/components/attachment-drop-zone.js.map +1 -0
  163. package/dist/components/badge.d.ts +5 -0
  164. package/dist/components/badge.d.ts.map +1 -0
  165. package/dist/components/badge.js +7 -0
  166. package/dist/components/badge.js.map +1 -0
  167. package/dist/components/button.d.ts +27 -0
  168. package/dist/components/button.d.ts.map +1 -0
  169. package/dist/components/button.js +209 -0
  170. package/dist/components/button.js.map +1 -0
  171. package/dist/components/generated-media.d.ts +12 -0
  172. package/dist/components/generated-media.d.ts.map +1 -0
  173. package/dist/components/generated-media.js +105 -0
  174. package/dist/components/generated-media.js.map +1 -0
  175. package/dist/components/github-icon.d.ts +3 -0
  176. package/dist/components/github-icon.d.ts.map +1 -0
  177. package/dist/components/github-icon.js +6 -0
  178. package/dist/components/github-icon.js.map +1 -0
  179. package/dist/components/index.d.ts +24 -0
  180. package/dist/components/index.d.ts.map +1 -0
  181. package/dist/components/index.js +25 -0
  182. package/dist/components/index.js.map +1 -0
  183. package/dist/components/markdown.d.ts +48 -0
  184. package/dist/components/markdown.d.ts.map +1 -0
  185. package/dist/components/markdown.js +264 -0
  186. package/dist/components/markdown.js.map +1 -0
  187. package/dist/components/mermaid-block.d.ts +14 -0
  188. package/dist/components/mermaid-block.d.ts.map +1 -0
  189. package/dist/components/mermaid-block.js +339 -0
  190. package/dist/components/mermaid-block.js.map +1 -0
  191. package/dist/components/mermaid-diagram.d.ts +264 -0
  192. package/dist/components/mermaid-diagram.d.ts.map +1 -0
  193. package/dist/components/mermaid-diagram.js +999 -0
  194. package/dist/components/mermaid-diagram.js.map +1 -0
  195. package/dist/components/mermaid-dom.d.ts +51 -0
  196. package/dist/components/mermaid-dom.d.ts.map +1 -0
  197. package/dist/components/mermaid-dom.js +246 -0
  198. package/dist/components/mermaid-dom.js.map +1 -0
  199. package/dist/components/message-scroller.d.ts +23 -0
  200. package/dist/components/message-scroller.d.ts.map +1 -0
  201. package/dist/components/message-scroller.js +31 -0
  202. package/dist/components/message-scroller.js.map +1 -0
  203. package/dist/components/search-combobox.d.ts +44 -0
  204. package/dist/components/search-combobox.d.ts.map +1 -0
  205. package/dist/components/search-combobox.js +191 -0
  206. package/dist/components/search-combobox.js.map +1 -0
  207. package/dist/components/session-status.d.ts +9 -0
  208. package/dist/components/session-status.d.ts.map +1 -0
  209. package/dist/components/session-status.js +11 -0
  210. package/dist/components/session-status.js.map +1 -0
  211. package/dist/components/switch.d.ts +7 -0
  212. package/dist/components/switch.d.ts.map +1 -0
  213. package/dist/components/switch.js +14 -0
  214. package/dist/components/switch.js.map +1 -0
  215. package/package.json +177 -5
  216. package/theme/base.css +83 -0
  217. package/theme/component-theme.css +126 -0
  218. package/theme/index.css +3 -0
  219. package/theme/palette.css +347 -0
  220. package/theme/scoped-tokens.css +503 -0
  221. package/theme/theme.css +90 -0
  222. package/theme/tokens.css +165 -0
@@ -0,0 +1,301 @@
1
+ import type { MermaidConfig } from "mermaid";
2
+ import {
3
+ buildMermaidConfig,
4
+ cssColorToHex,
5
+ encodePngWithinLimit,
6
+ FALLBACK_MERMAID_TOKENS,
7
+ type MermaidColorMode,
8
+ type MermaidThemeTokens,
9
+ normalizeMermaidTokens,
10
+ prepareSvgForRaster,
11
+ resolveMermaidFontFamily,
12
+ resolvePngDesiredScale,
13
+ } from "./mermaid-diagram.js";
14
+
15
+ /**
16
+ * Browser-only glue for the owned Mermaid block: samples the live Cline design
17
+ * tokens (oklch CSS custom properties) as concrete sRGB, watches for light/dark
18
+ * and accent changes, and rasterizes/saves diagrams. All entry points are safe
19
+ * to import in Node; DOM access happens only inside the functions.
20
+ */
21
+
22
+ // Custom property backing each Mermaid theme token.
23
+ const TOKEN_VARIABLES = {
24
+ background: "--card",
25
+ border: "--border",
26
+ error: "--destructive",
27
+ foreground: "--foreground",
28
+ muted: "--muted",
29
+ mutedForeground: "--muted-foreground",
30
+ primary: "--primary",
31
+ } satisfies Record<keyof MermaidThemeTokens, string>;
32
+
33
+ const FONT_VARIABLE = "--font-sans";
34
+
35
+ // Attributes that change the resolved tokens: `.dark` (@cline/ui theme),
36
+ // the desktop theme/accent data attributes, and inline style overrides.
37
+ const THEME_ATTRIBUTES = [
38
+ "class",
39
+ "data-cline-accent",
40
+ "data-cline-hub-theme",
41
+ "data-theme",
42
+ "style",
43
+ ];
44
+
45
+ export interface ResolvedMermaidTheme {
46
+ /** Font stack from the `--font-sans` token, with a system fallback. */
47
+ fontFamily: string;
48
+ /** Stable signature; changes only when the rendered theme would change. */
49
+ key: string;
50
+ mode: MermaidColorMode;
51
+ tokens: MermaidThemeTokens;
52
+ }
53
+
54
+ export function detectColorMode(root?: Element): MermaidColorMode {
55
+ if (typeof document === "undefined") return "light";
56
+ const html = document.documentElement;
57
+ const scope = root ?? html;
58
+ if (scope.closest(".dark") || html.classList.contains("dark")) return "dark";
59
+ const declared =
60
+ html.getAttribute("data-cline-hub-theme") ?? html.dataset.theme;
61
+ return declared === "dark" ? "dark" : "light";
62
+ }
63
+
64
+ let scratchContext: CanvasRenderingContext2D | null | undefined;
65
+
66
+ /** Canvas fallback for color syntaxes the pure parser doesn't cover. */
67
+ function canvasColorToHex(value: string): string | null {
68
+ if (typeof document === "undefined") return null;
69
+ if (scratchContext === undefined) {
70
+ const canvas = document.createElement("canvas");
71
+ canvas.width = 1;
72
+ canvas.height = 1;
73
+ scratchContext = canvas.getContext("2d", { willReadFrequently: true });
74
+ }
75
+ const context = scratchContext;
76
+ if (!context) return null;
77
+ // An invalid assignment is ignored, leaving the sentinel in place.
78
+ context.fillStyle = "#010203";
79
+ context.fillStyle = value;
80
+ if (context.fillStyle === "#010203" && cssColorToHex(value) === null) {
81
+ return null;
82
+ }
83
+ context.clearRect(0, 0, 1, 1);
84
+ context.fillRect(0, 0, 1, 1);
85
+ const [r = 0, g = 0, b = 0, a = 255] = context.getImageData(0, 0, 1, 1).data;
86
+ if (a === 0) return null;
87
+ const channel = (n: number) => n.toString(16).padStart(2, "0");
88
+ return `#${channel(r)}${channel(g)}${channel(b)}`;
89
+ }
90
+
91
+ function resolveTokenColor(style: CSSStyleDeclaration, name: string): string {
92
+ const raw = style.getPropertyValue(name).trim();
93
+ if (!raw) return "";
94
+ return cssColorToHex(raw) ?? canvasColorToHex(raw) ?? "";
95
+ }
96
+
97
+ /**
98
+ * Reads the design tokens in effect at `element` (so scoped-token embeds and
99
+ * accent overrides are honored) and resolves them to `#rrggbb`. Tokens that
100
+ * cannot be resolved fall back to the palette for the detected mode.
101
+ */
102
+ export function readMermaidTheme(element?: Element): ResolvedMermaidTheme {
103
+ if (typeof document === "undefined") {
104
+ const tokens = FALLBACK_MERMAID_TOKENS.light;
105
+ const fontFamily = resolveMermaidFontFamily(undefined);
106
+ return {
107
+ fontFamily,
108
+ key: JSON.stringify(["light", tokens, fontFamily]),
109
+ mode: "light",
110
+ tokens,
111
+ };
112
+ }
113
+ const target = element ?? document.documentElement;
114
+ const mode = detectColorMode(target);
115
+ const style = getComputedStyle(target);
116
+ const resolve = (name: string) => resolveTokenColor(style, name);
117
+ // Explicit per-key reads keep the result typed without a key cast; an empty
118
+ // string means "unresolved" and is replaced by the palette in normalize.
119
+ const raw: MermaidThemeTokens = {
120
+ background: resolve(TOKEN_VARIABLES.background),
121
+ border: resolve(TOKEN_VARIABLES.border),
122
+ error: resolve(TOKEN_VARIABLES.error),
123
+ foreground: resolve(TOKEN_VARIABLES.foreground),
124
+ muted: resolve(TOKEN_VARIABLES.muted),
125
+ mutedForeground: resolve(TOKEN_VARIABLES.mutedForeground),
126
+ primary: resolve(TOKEN_VARIABLES.primary),
127
+ };
128
+ const tokens = normalizeMermaidTokens(raw, mode);
129
+ const fontFamily = resolveMermaidFontFamily(
130
+ style.getPropertyValue(FONT_VARIABLE),
131
+ );
132
+ return {
133
+ fontFamily,
134
+ key: JSON.stringify([mode, tokens, fontFamily]),
135
+ mode,
136
+ tokens,
137
+ };
138
+ }
139
+
140
+ /** Themed Mermaid config for the tokens currently in effect. */
141
+ export function resolveThemedMermaidConfig(element?: Element): MermaidConfig {
142
+ const { fontFamily, mode, tokens } = readMermaidTheme(element);
143
+ return buildMermaidConfig(tokens, mode, { fontFamily });
144
+ }
145
+
146
+ /**
147
+ * Calls `onChange` when light/dark, the accent palette, or inline token
148
+ * overrides change on the document root. Returns a cleanup function.
149
+ */
150
+ export function observeThemeChanges(onChange: () => void): () => void {
151
+ if (
152
+ typeof MutationObserver === "undefined" ||
153
+ typeof document === "undefined"
154
+ ) {
155
+ return () => {};
156
+ }
157
+ const observer = new MutationObserver(onChange);
158
+ observer.observe(document.documentElement, {
159
+ attributeFilter: THEME_ATTRIBUTES,
160
+ attributes: true,
161
+ });
162
+ return () => observer.disconnect();
163
+ }
164
+
165
+ const FONT_WAIT_MS = 1500;
166
+
167
+ /**
168
+ * Waits (bounded) for web fonts so Mermaid measures text with Inter rather
169
+ * than a fallback face. Never rejects and never blocks longer than 1.5s.
170
+ */
171
+ export async function waitForFonts(): Promise<void> {
172
+ if (typeof document === "undefined" || !document.fonts) return;
173
+ let timer: ReturnType<typeof setTimeout> | undefined;
174
+ const timeout = new Promise<void>((resolve) => {
175
+ timer = setTimeout(resolve, FONT_WAIT_MS);
176
+ });
177
+ try {
178
+ await Promise.race([document.fonts.ready.then(() => undefined), timeout]);
179
+ } catch {
180
+ // A failed font wait must not block rendering.
181
+ } finally {
182
+ clearTimeout(timer);
183
+ }
184
+ }
185
+
186
+ function svgToDataUrl(svg: string): string {
187
+ const bytes = new TextEncoder().encode(svg);
188
+ let binary = "";
189
+ const chunk = 0x8000;
190
+ for (let offset = 0; offset < bytes.length; offset += chunk) {
191
+ binary += String.fromCharCode(...bytes.subarray(offset, offset + chunk));
192
+ }
193
+ return `data:image/svg+xml;base64,${btoa(binary)}`;
194
+ }
195
+
196
+ function loadImage(
197
+ src: string,
198
+ width: number,
199
+ height: number,
200
+ ): Promise<HTMLImageElement> {
201
+ return new Promise((resolve, reject) => {
202
+ const image = new Image(width, height);
203
+ image.onload = () => resolve(image);
204
+ image.onerror = () => reject(new Error("Failed to load diagram image"));
205
+ image.src = src;
206
+ });
207
+ }
208
+
209
+ /**
210
+ * Rasterizes a Mermaid SVG to an opaque PNG filled with `background`. Loads the
211
+ * SVG as a data: URL (as Streamdown's exporter does; no object URL to revoke and
212
+ * no canvas taint from blob: origins), sizes the canvas at 2x-3x (following the
213
+ * device pixel ratio) with the longest edge capped (see `computePngExportSize`),
214
+ * and waits for fonts first.
215
+ */
216
+ export async function svgToPngBlob(
217
+ svg: string,
218
+ background: string,
219
+ ): Promise<Blob> {
220
+ await waitForFonts();
221
+ const prepared = prepareSvgForRaster(svg);
222
+ const image = await loadImage(
223
+ svgToDataUrl(prepared.svg),
224
+ prepared.width,
225
+ prepared.height,
226
+ );
227
+ // Oversize results (dense diagrams) are re-encoded at a lower scale so the
228
+ // PNG stays under the ~5 MiB attachment limit.
229
+ return encodePngWithinLimit(
230
+ prepared,
231
+ (size) => encodeCanvasPng(image, size, background),
232
+ resolvePngDesiredScale(
233
+ typeof window === "undefined" ? undefined : window.devicePixelRatio,
234
+ ),
235
+ );
236
+ }
237
+
238
+ function encodeCanvasPng(
239
+ image: HTMLImageElement,
240
+ size: { height: number; width: number },
241
+ background: string,
242
+ ): Promise<Blob> {
243
+ const canvas = document.createElement("canvas");
244
+ canvas.width = size.width;
245
+ canvas.height = size.height;
246
+ const context = canvas.getContext("2d");
247
+ if (!context) return Promise.reject(new Error("Canvas is unavailable"));
248
+ // Opaque themed surface, never transparent: pasted into a light or dark
249
+ // composer the diagram keeps a readable background.
250
+ context.fillStyle = background;
251
+ context.fillRect(0, 0, size.width, size.height);
252
+ context.drawImage(image, 0, 0, size.width, size.height);
253
+ return new Promise<Blob>((resolve, reject) => {
254
+ try {
255
+ canvas.toBlob((blob) => {
256
+ if (blob) resolve(blob);
257
+ else reject(new Error("Failed to encode PNG"));
258
+ }, "image/png");
259
+ } catch (error) {
260
+ reject(error);
261
+ }
262
+ });
263
+ }
264
+
265
+ const REVOKE_DELAY_MS = 1000;
266
+
267
+ /**
268
+ * Anchor+blob download (same mechanism as Streamdown's built-in exports). The
269
+ * object URL is revoked shortly after the click: revoking synchronously can
270
+ * cancel the download in WebKit.
271
+ */
272
+ export function downloadBlob(blob: Blob, filename: string): void {
273
+ const url = URL.createObjectURL(blob);
274
+ try {
275
+ const anchor = document.createElement("a");
276
+ anchor.href = url;
277
+ anchor.download = filename;
278
+ document.body.appendChild(anchor);
279
+ anchor.click();
280
+ document.body.removeChild(anchor);
281
+ } finally {
282
+ setTimeout(() => URL.revokeObjectURL(url), REVOKE_DELAY_MS);
283
+ }
284
+ }
285
+
286
+ export function downloadText(text: string, filename: string): void {
287
+ downloadBlob(
288
+ new Blob([text], { type: "text/plain;charset=utf-8" }),
289
+ filename,
290
+ );
291
+ }
292
+
293
+ /**
294
+ * Mermaid renders into a temporary `#d<id>` container in <body>. It removes it
295
+ * on success; this makes sure a failed render never leaves one behind. Only the
296
+ * container is removed: the SVG's own `#<id>` may already live in our tree.
297
+ */
298
+ export function cleanupMermaidArtifacts(id: string): void {
299
+ if (typeof document === "undefined") return;
300
+ document.getElementById(`d${id}`)?.remove();
301
+ }
@@ -0,0 +1,118 @@
1
+ @layer components {
2
+ .cline-message-scroller {
3
+ position: relative;
4
+ display: flex;
5
+ flex-direction: column;
6
+ width: 100%;
7
+ height: 100%;
8
+ min-width: 0;
9
+ min-height: 0;
10
+ overflow: hidden;
11
+ }
12
+
13
+ .cline-message-scroller-viewport {
14
+ width: 100%;
15
+ height: 100%;
16
+ min-width: 0;
17
+ min-height: 0;
18
+ overflow-y: auto;
19
+ overscroll-behavior: contain;
20
+ scrollbar-gutter: stable;
21
+ }
22
+
23
+ .cline-message-scroller-viewport[data-pending-scroll] {
24
+ visibility: hidden;
25
+ }
26
+
27
+ .cline-message-scroller-content {
28
+ display: flex;
29
+ flex-direction: column;
30
+ height: max-content;
31
+ min-height: 100%;
32
+ gap: 1.5rem;
33
+ }
34
+
35
+ .cline-message-scroller-item {
36
+ min-width: 0;
37
+ flex-shrink: 0;
38
+ }
39
+
40
+ .cline-message-scroller-button {
41
+ position: absolute;
42
+ inset-inline-start: 50%;
43
+ bottom: 1rem;
44
+ z-index: 10;
45
+ display: inline-flex;
46
+ align-items: center;
47
+ justify-content: center;
48
+ width: 2.5rem;
49
+ height: 2.5rem;
50
+ transform: translateX(-50%);
51
+ border: 1px solid var(--border);
52
+ border-radius: 9999px;
53
+ background: var(--background);
54
+ color: var(--foreground);
55
+ box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
56
+ cursor: pointer;
57
+ opacity: 0.8;
58
+ transition:
59
+ opacity 200ms,
60
+ translate 200ms;
61
+ }
62
+
63
+ .cline-message-scroller-button:hover {
64
+ background: var(--popover);
65
+ opacity: 1;
66
+ }
67
+
68
+ .cline-message-scroller-button:focus-visible {
69
+ opacity: 1;
70
+ outline: 2px solid var(--ring);
71
+ outline-offset: 2px;
72
+ }
73
+
74
+ .cline-message-scroller-button[data-active="false"] {
75
+ pointer-events: none;
76
+ opacity: 0;
77
+ translate: 0 100%;
78
+ }
79
+
80
+ .cline-message-scroller-button[data-direction="start"] {
81
+ top: 1rem;
82
+ bottom: auto;
83
+ }
84
+
85
+ .cline-message-scroller-button[data-direction="start"][data-active="false"] {
86
+ translate: 0 -100%;
87
+ }
88
+
89
+ .cline-message-scroller-button svg {
90
+ width: 1rem;
91
+ height: 1rem;
92
+ }
93
+
94
+ .cline-message-scroller-button[data-direction="start"] svg {
95
+ rotate: 180deg;
96
+ }
97
+
98
+ .cline-message-scroller-button:dir(rtl) {
99
+ transform: translateX(50%);
100
+ }
101
+
102
+ .cline-message-scroller-button-label {
103
+ position: absolute;
104
+ width: 1px;
105
+ height: 1px;
106
+ padding: 0;
107
+ overflow: hidden;
108
+ clip: rect(0, 0, 0, 0);
109
+ white-space: nowrap;
110
+ border: 0;
111
+ }
112
+
113
+ @media (prefers-reduced-motion: reduce) {
114
+ .cline-message-scroller-button {
115
+ transition: none;
116
+ }
117
+ }
118
+ }
@@ -0,0 +1,114 @@
1
+ "use client";
2
+
3
+ // Styled composition of shadcn/ui's Message Scroller. The upstream primitive
4
+ // owns anchoring, streamed output, visibility tracking, and scroll commands.
5
+ import { MessageScroller as Primitive } from "@shadcn/react/message-scroller";
6
+ import { clsx } from "clsx";
7
+ import { ArrowDownIcon } from "lucide-react";
8
+ import type { ComponentProps } from "react";
9
+
10
+ export {
11
+ useMessageScroller,
12
+ useMessageScrollerScrollable,
13
+ useMessageScrollerVisibility,
14
+ } from "@shadcn/react/message-scroller";
15
+
16
+ export type MessageScrollerProviderProps = ComponentProps<
17
+ typeof Primitive.Provider
18
+ >;
19
+ export type MessageScrollerProps = ComponentProps<typeof Primitive.Root>;
20
+ export type MessageScrollerViewportProps = ComponentProps<
21
+ typeof Primitive.Viewport
22
+ >;
23
+ export type MessageScrollerContentProps = ComponentProps<
24
+ typeof Primitive.Content
25
+ >;
26
+ export type MessageScrollerItemProps = ComponentProps<typeof Primitive.Item>;
27
+ export type MessageScrollerButtonProps = ComponentProps<
28
+ typeof Primitive.Button
29
+ >;
30
+
31
+ export const MessageScrollerProvider = Primitive.Provider;
32
+
33
+ export function MessageScroller({ className, ...props }: MessageScrollerProps) {
34
+ return (
35
+ <Primitive.Root
36
+ data-slot="message-scroller"
37
+ className={clsx("cline-message-scroller", className)}
38
+ {...props}
39
+ />
40
+ );
41
+ }
42
+
43
+ export function MessageScrollerViewport({
44
+ className,
45
+ ...props
46
+ }: MessageScrollerViewportProps) {
47
+ return (
48
+ <Primitive.Viewport
49
+ data-slot="message-scroller-viewport"
50
+ className={clsx("cline-message-scroller-viewport", className)}
51
+ {...props}
52
+ />
53
+ );
54
+ }
55
+
56
+ export function MessageScrollerContent({
57
+ className,
58
+ ...props
59
+ }: MessageScrollerContentProps) {
60
+ return (
61
+ <Primitive.Content
62
+ data-slot="message-scroller-content"
63
+ className={clsx("cline-message-scroller-content", className)}
64
+ {...props}
65
+ />
66
+ );
67
+ }
68
+
69
+ export function MessageScrollerItem({
70
+ className,
71
+ ...props
72
+ }: MessageScrollerItemProps) {
73
+ return (
74
+ <Primitive.Item
75
+ data-slot="message-scroller-item"
76
+ className={clsx("cline-message-scroller-item", className)}
77
+ {...props}
78
+ />
79
+ );
80
+ }
81
+
82
+ export function MessageScrollerButton({
83
+ behavior,
84
+ direction = "end",
85
+ className,
86
+ children,
87
+ ...props
88
+ }: MessageScrollerButtonProps) {
89
+ const resolvedBehavior =
90
+ behavior ??
91
+ (typeof window !== "undefined" &&
92
+ typeof window.matchMedia === "function" &&
93
+ window.matchMedia("(prefers-reduced-motion: reduce)").matches
94
+ ? "auto"
95
+ : "smooth");
96
+ return (
97
+ <Primitive.Button
98
+ data-slot="message-scroller-button"
99
+ behavior={resolvedBehavior}
100
+ direction={direction}
101
+ className={clsx("cline-message-scroller-button", className)}
102
+ {...props}
103
+ >
104
+ {children ?? (
105
+ <>
106
+ <ArrowDownIcon aria-hidden="true" />
107
+ <span className="cline-message-scroller-button-label">
108
+ {direction === "end" ? "Scroll to end" : "Scroll to start"}
109
+ </span>
110
+ </>
111
+ )}
112
+ </Primitive.Button>
113
+ );
114
+ }
@@ -0,0 +1,67 @@
1
+ .cline-ui-search-combobox__panel,
2
+ .cline-ui-search-combobox__search-row {
3
+ border-style: solid;
4
+ }
5
+
6
+ .cline-ui-search-combobox__trigger {
7
+ font-family: inherit;
8
+ font-style: inherit;
9
+ font-variant: inherit;
10
+ letter-spacing: inherit;
11
+ line-height: inherit;
12
+ }
13
+
14
+ .cline-ui-search-combobox__search {
15
+ font-family: inherit;
16
+ font-style: inherit;
17
+ font-variant: inherit;
18
+ font-weight: inherit;
19
+ }
20
+
21
+ .cline-ui-search-combobox__option {
22
+ font-family: inherit;
23
+ font-style: inherit;
24
+ font-variant: inherit;
25
+ font-weight: inherit;
26
+ line-height: inherit;
27
+ }
28
+
29
+ /* Selected row: the semantic accent surface (step 3) is too faint in light
30
+ * mode to read as "selected"; step 4 keeps the row unmistakably highlighted
31
+ * in both themes without touching the shared --accent token. */
32
+ .cline-ui-search-combobox__option[aria-selected="true"] {
33
+ background-color: var(--accent-4, var(--accent));
34
+ }
35
+
36
+ /* Open animation matching the shadcn/Radix dropdowns (fade + slight zoom,
37
+ * sliding from the trigger side) so pickers and selects feel like one set. */
38
+ @keyframes cline-ui-search-combobox-open {
39
+ from {
40
+ opacity: 0;
41
+ transform: translateY(var(--cline-ui-search-combobox-slide, 0)) scale(0.97);
42
+ }
43
+ to {
44
+ opacity: 1;
45
+ transform: none;
46
+ }
47
+ }
48
+
49
+ .cline-ui-search-combobox__panel {
50
+ animation: cline-ui-search-combobox-open 150ms ease-out;
51
+ }
52
+
53
+ .cline-ui-search-combobox__panel--bottom {
54
+ --cline-ui-search-combobox-slide: -0.25rem;
55
+ transform-origin: top;
56
+ }
57
+
58
+ .cline-ui-search-combobox__panel--top {
59
+ --cline-ui-search-combobox-slide: 0.25rem;
60
+ transform-origin: bottom;
61
+ }
62
+
63
+ @media (prefers-reduced-motion: reduce) {
64
+ .cline-ui-search-combobox__panel {
65
+ animation: none;
66
+ }
67
+ }