@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.
- package/ADOPTION.md +833 -0
- package/LICENSE +201 -0
- package/RADIX-COLORS-LICENSE +21 -0
- package/README.md +427 -2
- package/components/agent-approval-card.css +70 -0
- package/components/agent-approval-card.tsx +109 -0
- package/components/agent-ask-question.css +103 -0
- package/components/agent-ask-question.tsx +276 -0
- package/components/agent-aurora.css +228 -0
- package/components/agent-aurora.tsx +96 -0
- package/components/agent-changes.css +13 -0
- package/components/agent-changes.tsx +167 -0
- package/components/agent-chat/agent-chat.css +556 -0
- package/components/agent-chat/index.tsx +1037 -0
- package/components/agent-chat/tool-diff.tsx +165 -0
- package/components/agent-chat/tool-summary/agents.ts +114 -0
- package/components/agent-chat/tool-summary/diff.ts +152 -0
- package/components/agent-chat/tool-summary/index.ts +928 -0
- package/components/agent-chat/tool-summary/parsers.ts +611 -0
- package/components/agent-chat/tool-summary/paths.ts +84 -0
- package/components/agent-chat/tool-summary/team.ts +401 -0
- package/components/agent-command-output.tsx +63 -0
- package/components/agent-composer.tsx +263 -0
- package/components/agent-context-usage.tsx +181 -0
- package/components/agent-conversation-layout.tsx +139 -0
- package/components/agent-hero-heading.css +53 -0
- package/components/agent-hero-heading.tsx +45 -0
- package/components/agent-image-lightbox.tsx +48 -0
- package/components/agent-prompt-queue.css +20 -0
- package/components/agent-prompt-queue.tsx +350 -0
- package/components/agent-pull-request-bar.css +13 -0
- package/components/agent-pull-request-bar.tsx +346 -0
- package/components/agent-quick-actions.css +19 -0
- package/components/agent-quick-actions.tsx +70 -0
- package/components/agent-session-row.tsx +183 -0
- package/components/agent-welcome-hero-pointer.ts +199 -0
- package/components/agent-welcome-hero.css +205 -0
- package/components/agent-welcome-hero.tsx +68 -0
- package/components/attachment-drop-zone.tsx +154 -0
- package/components/badge.tsx +21 -0
- package/components/button.tsx +324 -0
- package/components/generated-media.tsx +173 -0
- package/components/github-icon.tsx +19 -0
- package/components/index.ts +133 -0
- package/components/markdown.css +490 -0
- package/components/markdown.ts +365 -0
- package/components/mermaid-block.tsx +722 -0
- package/components/mermaid-diagram.ts +1260 -0
- package/components/mermaid-dom.ts +301 -0
- package/components/message-scroller.css +118 -0
- package/components/message-scroller.tsx +114 -0
- package/components/search-combobox.css +67 -0
- package/components/search-combobox.tsx +433 -0
- package/components/session-status.css +19 -0
- package/components/session-status.tsx +39 -0
- package/components/switch.css +221 -0
- package/components/switch.tsx +48 -0
- package/components.css +16 -0
- package/dist/components/agent-approval-card.d.ts +14 -0
- package/dist/components/agent-approval-card.d.ts.map +1 -0
- package/dist/components/agent-approval-card.js +12 -0
- package/dist/components/agent-approval-card.js.map +1 -0
- package/dist/components/agent-ask-question.d.ts +18 -0
- package/dist/components/agent-ask-question.d.ts.map +1 -0
- package/dist/components/agent-ask-question.js +101 -0
- package/dist/components/agent-ask-question.js.map +1 -0
- package/dist/components/agent-aurora.d.ts +3 -0
- package/dist/components/agent-aurora.d.ts.map +1 -0
- package/dist/components/agent-aurora.js +60 -0
- package/dist/components/agent-aurora.js.map +1 -0
- package/dist/components/agent-changes.d.ts +26 -0
- package/dist/components/agent-changes.d.ts.map +1 -0
- package/dist/components/agent-changes.js +19 -0
- package/dist/components/agent-changes.js.map +1 -0
- package/dist/components/agent-chat/disclosure.d.ts +25 -0
- package/dist/components/agent-chat/disclosure.d.ts.map +1 -0
- package/dist/components/agent-chat/disclosure.js +39 -0
- package/dist/components/agent-chat/disclosure.js.map +1 -0
- package/dist/components/agent-chat/index.d.ts +140 -0
- package/dist/components/agent-chat/index.d.ts.map +1 -0
- package/dist/components/agent-chat/index.js +379 -0
- package/dist/components/agent-chat/index.js.map +1 -0
- package/dist/components/agent-chat/tool-diff.d.ts +32 -0
- package/dist/components/agent-chat/tool-diff.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-diff.js +97 -0
- package/dist/components/agent-chat/tool-diff.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/agents.d.ts +10 -0
- package/dist/components/agent-chat/tool-summary/agents.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/agents.js +100 -0
- package/dist/components/agent-chat/tool-summary/agents.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/diff.d.ts +22 -0
- package/dist/components/agent-chat/tool-summary/diff.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/diff.js +127 -0
- package/dist/components/agent-chat/tool-summary/diff.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/index.d.ts +145 -0
- package/dist/components/agent-chat/tool-summary/index.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/index.js +663 -0
- package/dist/components/agent-chat/tool-summary/index.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/parsers.d.ts +114 -0
- package/dist/components/agent-chat/tool-summary/parsers.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/parsers.js +502 -0
- package/dist/components/agent-chat/tool-summary/parsers.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/paths.d.ts +10 -0
- package/dist/components/agent-chat/tool-summary/paths.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/paths.js +88 -0
- package/dist/components/agent-chat/tool-summary/paths.js.map +1 -0
- package/dist/components/agent-chat/tool-summary/team.d.ts +16 -0
- package/dist/components/agent-chat/tool-summary/team.d.ts.map +1 -0
- package/dist/components/agent-chat/tool-summary/team.js +283 -0
- package/dist/components/agent-chat/tool-summary/team.js.map +1 -0
- package/dist/components/agent-command-output.d.ts +14 -0
- package/dist/components/agent-command-output.d.ts.map +1 -0
- package/dist/components/agent-command-output.js +22 -0
- package/dist/components/agent-command-output.js.map +1 -0
- package/dist/components/agent-composer.d.ts +34 -0
- package/dist/components/agent-composer.d.ts.map +1 -0
- package/dist/components/agent-composer.js +65 -0
- package/dist/components/agent-composer.js.map +1 -0
- package/dist/components/agent-context-usage.d.ts +28 -0
- package/dist/components/agent-context-usage.d.ts.map +1 -0
- package/dist/components/agent-context-usage.js +51 -0
- package/dist/components/agent-context-usage.js.map +1 -0
- package/dist/components/agent-conversation-layout.d.ts +30 -0
- package/dist/components/agent-conversation-layout.d.ts.map +1 -0
- package/dist/components/agent-conversation-layout.js +24 -0
- package/dist/components/agent-conversation-layout.js.map +1 -0
- package/dist/components/agent-hero-heading.d.ts +2 -0
- package/dist/components/agent-hero-heading.d.ts.map +1 -0
- package/dist/components/agent-hero-heading.js +20 -0
- package/dist/components/agent-hero-heading.js.map +1 -0
- package/dist/components/agent-image-lightbox.d.ts +11 -0
- package/dist/components/agent-image-lightbox.d.ts.map +1 -0
- package/dist/components/agent-image-lightbox.js +8 -0
- package/dist/components/agent-image-lightbox.js.map +1 -0
- package/dist/components/agent-prompt-queue.d.ts +14 -0
- package/dist/components/agent-prompt-queue.d.ts.map +1 -0
- package/dist/components/agent-prompt-queue.js +114 -0
- package/dist/components/agent-prompt-queue.js.map +1 -0
- package/dist/components/agent-pull-request-bar.d.ts +72 -0
- package/dist/components/agent-pull-request-bar.d.ts.map +1 -0
- package/dist/components/agent-pull-request-bar.js +90 -0
- package/dist/components/agent-pull-request-bar.js.map +1 -0
- package/dist/components/agent-quick-actions.d.ts +14 -0
- package/dist/components/agent-quick-actions.d.ts.map +1 -0
- package/dist/components/agent-quick-actions.js +12 -0
- package/dist/components/agent-quick-actions.js.map +1 -0
- package/dist/components/agent-session-row.d.ts +45 -0
- package/dist/components/agent-session-row.d.ts.map +1 -0
- package/dist/components/agent-session-row.js +34 -0
- package/dist/components/agent-session-row.js.map +1 -0
- package/dist/components/agent-welcome-hero-pointer.d.ts +3 -0
- package/dist/components/agent-welcome-hero-pointer.d.ts.map +1 -0
- package/dist/components/agent-welcome-hero-pointer.js +169 -0
- package/dist/components/agent-welcome-hero-pointer.js.map +1 -0
- package/dist/components/agent-welcome-hero.d.ts +9 -0
- package/dist/components/agent-welcome-hero.d.ts.map +1 -0
- package/dist/components/agent-welcome-hero.js +14 -0
- package/dist/components/agent-welcome-hero.js.map +1 -0
- package/dist/components/attachment-drop-zone.d.ts +15 -0
- package/dist/components/attachment-drop-zone.d.ts.map +1 -0
- package/dist/components/attachment-drop-zone.js +64 -0
- package/dist/components/attachment-drop-zone.js.map +1 -0
- package/dist/components/badge.d.ts +5 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +7 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/button.d.ts +27 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +209 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/generated-media.d.ts +12 -0
- package/dist/components/generated-media.d.ts.map +1 -0
- package/dist/components/generated-media.js +105 -0
- package/dist/components/generated-media.js.map +1 -0
- package/dist/components/github-icon.d.ts +3 -0
- package/dist/components/github-icon.d.ts.map +1 -0
- package/dist/components/github-icon.js +6 -0
- package/dist/components/github-icon.js.map +1 -0
- package/dist/components/index.d.ts +24 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +25 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/markdown.d.ts +48 -0
- package/dist/components/markdown.d.ts.map +1 -0
- package/dist/components/markdown.js +264 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/mermaid-block.d.ts +14 -0
- package/dist/components/mermaid-block.d.ts.map +1 -0
- package/dist/components/mermaid-block.js +339 -0
- package/dist/components/mermaid-block.js.map +1 -0
- package/dist/components/mermaid-diagram.d.ts +264 -0
- package/dist/components/mermaid-diagram.d.ts.map +1 -0
- package/dist/components/mermaid-diagram.js +999 -0
- package/dist/components/mermaid-diagram.js.map +1 -0
- package/dist/components/mermaid-dom.d.ts +51 -0
- package/dist/components/mermaid-dom.d.ts.map +1 -0
- package/dist/components/mermaid-dom.js +246 -0
- package/dist/components/mermaid-dom.js.map +1 -0
- package/dist/components/message-scroller.d.ts +23 -0
- package/dist/components/message-scroller.d.ts.map +1 -0
- package/dist/components/message-scroller.js +31 -0
- package/dist/components/message-scroller.js.map +1 -0
- package/dist/components/search-combobox.d.ts +44 -0
- package/dist/components/search-combobox.d.ts.map +1 -0
- package/dist/components/search-combobox.js +191 -0
- package/dist/components/search-combobox.js.map +1 -0
- package/dist/components/session-status.d.ts +9 -0
- package/dist/components/session-status.d.ts.map +1 -0
- package/dist/components/session-status.js +11 -0
- package/dist/components/session-status.js.map +1 -0
- package/dist/components/switch.d.ts +7 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +14 -0
- package/dist/components/switch.js.map +1 -0
- package/package.json +177 -5
- package/theme/base.css +83 -0
- package/theme/component-theme.css +126 -0
- package/theme/index.css +3 -0
- package/theme/palette.css +347 -0
- package/theme/scoped-tokens.css +503 -0
- package/theme/theme.css +90 -0
- package/theme/tokens.css +165 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { buildMermaidConfig, createDefaultMermaidConfig, createMermaidService, defaultMermaidLoader, } from "./mermaid-diagram.js";
|
|
2
|
+
import { readMermaidTheme } from "./mermaid-dom.js";
|
|
3
|
+
/** Copy on code blocks; no downloads; no mermaid/table chrome. The matching
|
|
4
|
+
* CSS hides the code-block header and reveals the copy control on hover. */
|
|
5
|
+
export const agentMarkdownControls = {
|
|
6
|
+
code: { copy: true, download: false },
|
|
7
|
+
mermaid: false,
|
|
8
|
+
table: false,
|
|
9
|
+
};
|
|
10
|
+
/** Desktop/host opt-in controls for interactive Mermaid diagrams. The default
|
|
11
|
+
* controls above stay diagram-free so existing consumers don't change unless
|
|
12
|
+
* they also register a Mermaid DiagramPlugin. */
|
|
13
|
+
export const agentMarkdownControlsWithMermaid = {
|
|
14
|
+
...agentMarkdownControls,
|
|
15
|
+
mermaid: {
|
|
16
|
+
copy: true,
|
|
17
|
+
download: true,
|
|
18
|
+
fullscreen: true,
|
|
19
|
+
panZoom: true,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export { buildMermaidConfig, buildMermaidThemeVariables, createDefaultMermaidConfig, DIAGRAM_LINK_HREF_ATTRIBUTE, neutralizeDiagramLinks, } from "./mermaid-diagram.js";
|
|
23
|
+
/** Base-theme defaults from the palette (light); hosts with a DOM resolve the
|
|
24
|
+
* live design tokens instead, see `resolveThemedMermaidConfig`. */
|
|
25
|
+
export const DEFAULT_MERMAID_CONFIG = createDefaultMermaidConfig("light");
|
|
26
|
+
/**
|
|
27
|
+
* Creates a Streamdown Mermaid *diagram plugin* (Streamdown's built-in block
|
|
28
|
+
* chrome). Hosts that want the owned block (filename header, PNG/MMD
|
|
29
|
+
* downloads, themed PNGs) register `createMermaidRenderer` from
|
|
30
|
+
* `@cerebriline/ui/components/mermaid-block` instead.
|
|
31
|
+
*
|
|
32
|
+
* The default config is resolved from the live Cline design tokens at render
|
|
33
|
+
* time (falling back to the palette without a DOM) and re-applied when the
|
|
34
|
+
* resolved theme changes; configs supplied through `getMermaid(config)` layer
|
|
35
|
+
* on top, with `securityLevel` always forced to `strict`.
|
|
36
|
+
*/
|
|
37
|
+
export function createLazyMermaidPlugin(loader = defaultMermaidLoader) {
|
|
38
|
+
const service = createMermaidService(loader);
|
|
39
|
+
let overrides = {};
|
|
40
|
+
let cached;
|
|
41
|
+
const instance = {
|
|
42
|
+
initialize(nextConfig) {
|
|
43
|
+
overrides = { ...overrides, ...nextConfig };
|
|
44
|
+
cached = undefined;
|
|
45
|
+
},
|
|
46
|
+
render(id, source) {
|
|
47
|
+
const theme = readMermaidTheme();
|
|
48
|
+
// One config object per theme key so the shared service only calls
|
|
49
|
+
// `initialize` when the theme or the overrides change.
|
|
50
|
+
if (cached?.key !== theme.key) {
|
|
51
|
+
cached = {
|
|
52
|
+
config: {
|
|
53
|
+
...buildMermaidConfig(theme.tokens, theme.mode, {
|
|
54
|
+
fontFamily: theme.fontFamily,
|
|
55
|
+
}),
|
|
56
|
+
...overrides,
|
|
57
|
+
securityLevel: "strict",
|
|
58
|
+
},
|
|
59
|
+
key: theme.key,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return service.render(id, source, cached.config);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
getMermaid(nextConfig) {
|
|
67
|
+
if (nextConfig)
|
|
68
|
+
instance.initialize(nextConfig);
|
|
69
|
+
return instance;
|
|
70
|
+
},
|
|
71
|
+
language: "mermaid",
|
|
72
|
+
name: "mermaid",
|
|
73
|
+
type: "diagram",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export const SUPPORTED_MARKDOWN_LANGUAGES = [
|
|
77
|
+
"bash",
|
|
78
|
+
"css",
|
|
79
|
+
"diff",
|
|
80
|
+
"html",
|
|
81
|
+
"javascript",
|
|
82
|
+
"json",
|
|
83
|
+
"jsonc",
|
|
84
|
+
"jsx",
|
|
85
|
+
"markdown",
|
|
86
|
+
"python",
|
|
87
|
+
"shellscript",
|
|
88
|
+
"tsx",
|
|
89
|
+
"typescript",
|
|
90
|
+
"yaml",
|
|
91
|
+
];
|
|
92
|
+
const SUPPORTED_LANGUAGE_SET = new Set(SUPPORTED_MARKDOWN_LANGUAGES);
|
|
93
|
+
const LANGUAGE_ALIASES = {
|
|
94
|
+
cjs: "javascript",
|
|
95
|
+
console: "shellscript",
|
|
96
|
+
htm: "html",
|
|
97
|
+
js: "javascript",
|
|
98
|
+
json5: "jsonc",
|
|
99
|
+
md: "markdown",
|
|
100
|
+
mjs: "javascript",
|
|
101
|
+
py: "python",
|
|
102
|
+
sh: "shellscript",
|
|
103
|
+
shell: "shellscript",
|
|
104
|
+
ts: "typescript",
|
|
105
|
+
yml: "yaml",
|
|
106
|
+
};
|
|
107
|
+
const LANGUAGE_LOADERS = {
|
|
108
|
+
bash: () => import("@shikijs/langs/bash").then((module) => module.default),
|
|
109
|
+
css: () => import("@shikijs/langs/css").then((module) => module.default),
|
|
110
|
+
diff: () => import("@shikijs/langs/diff").then((module) => module.default),
|
|
111
|
+
html: () => import("@shikijs/langs/html").then((module) => module.default),
|
|
112
|
+
javascript: () => import("@shikijs/langs/javascript").then((module) => module.default),
|
|
113
|
+
json: () => import("@shikijs/langs/json").then((module) => module.default),
|
|
114
|
+
jsonc: () => import("@shikijs/langs/jsonc").then((module) => module.default),
|
|
115
|
+
jsx: () => import("@shikijs/langs/jsx").then((module) => module.default),
|
|
116
|
+
markdown: () => import("@shikijs/langs/markdown").then((module) => module.default),
|
|
117
|
+
python: () => import("@shikijs/langs/python").then((module) => module.default),
|
|
118
|
+
shellscript: () => import("@shikijs/langs/shellscript").then((module) => module.default),
|
|
119
|
+
tsx: () => import("@shikijs/langs/tsx").then((module) => module.default),
|
|
120
|
+
typescript: () => import("@shikijs/langs/typescript").then((module) => module.default),
|
|
121
|
+
yaml: () => import("@shikijs/langs/yaml").then((module) => module.default),
|
|
122
|
+
};
|
|
123
|
+
const LIGHT_THEME = "github-light";
|
|
124
|
+
const DARK_THEME = "github-dark";
|
|
125
|
+
const MAX_CACHED_RESULTS = 256;
|
|
126
|
+
let highlighterPromise;
|
|
127
|
+
let themesPromise;
|
|
128
|
+
const languagePromises = new Map();
|
|
129
|
+
const resultCache = new Map();
|
|
130
|
+
const pendingHighlights = new Map();
|
|
131
|
+
const loggedFailures = new Set();
|
|
132
|
+
function normalizeLanguage(language) {
|
|
133
|
+
const normalized = language.trim().toLowerCase();
|
|
134
|
+
if (!normalized)
|
|
135
|
+
return null;
|
|
136
|
+
const aliased = LANGUAGE_ALIASES[normalized] ?? normalized;
|
|
137
|
+
return SUPPORTED_LANGUAGE_SET.has(aliased)
|
|
138
|
+
? aliased
|
|
139
|
+
: null;
|
|
140
|
+
}
|
|
141
|
+
function getHighlighter() {
|
|
142
|
+
if (!highlighterPromise) {
|
|
143
|
+
highlighterPromise = Promise.all([
|
|
144
|
+
import("shiki/core"),
|
|
145
|
+
import("shiki/engine/javascript"),
|
|
146
|
+
]).then(([core, engine]) => core.createHighlighterCore({
|
|
147
|
+
engine: engine.createJavaScriptRegexEngine({ forgiving: true }),
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
return highlighterPromise;
|
|
151
|
+
}
|
|
152
|
+
function ensureThemes(highlighter) {
|
|
153
|
+
if (!themesPromise) {
|
|
154
|
+
themesPromise = Promise.all([
|
|
155
|
+
import("@shikijs/themes/github-light").then((module) => module.default),
|
|
156
|
+
import("@shikijs/themes/github-dark").then((module) => module.default),
|
|
157
|
+
]).then((themes) => highlighter.loadTheme(...themes));
|
|
158
|
+
}
|
|
159
|
+
return themesPromise;
|
|
160
|
+
}
|
|
161
|
+
function ensureLanguage(highlighter, language) {
|
|
162
|
+
const existing = languagePromises.get(language);
|
|
163
|
+
if (existing)
|
|
164
|
+
return existing;
|
|
165
|
+
const loading = LANGUAGE_LOADERS[language]().then((registrations) => highlighter.loadLanguage(...registrations));
|
|
166
|
+
languagePromises.set(language, loading);
|
|
167
|
+
return loading;
|
|
168
|
+
}
|
|
169
|
+
function rawHighlight(code) {
|
|
170
|
+
return {
|
|
171
|
+
bg: "transparent",
|
|
172
|
+
fg: "inherit",
|
|
173
|
+
tokens: code.split("\n").map((line) => line
|
|
174
|
+
? [
|
|
175
|
+
{
|
|
176
|
+
bgColor: "transparent",
|
|
177
|
+
color: "inherit",
|
|
178
|
+
content: line,
|
|
179
|
+
htmlStyle: {},
|
|
180
|
+
offset: 0,
|
|
181
|
+
},
|
|
182
|
+
]
|
|
183
|
+
: []),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function cacheResult(key, result) {
|
|
187
|
+
resultCache.delete(key);
|
|
188
|
+
resultCache.set(key, result);
|
|
189
|
+
if (resultCache.size <= MAX_CACHED_RESULTS)
|
|
190
|
+
return;
|
|
191
|
+
const oldestKey = resultCache.keys().next().value;
|
|
192
|
+
if (oldestKey !== undefined)
|
|
193
|
+
resultCache.delete(oldestKey);
|
|
194
|
+
}
|
|
195
|
+
function reportHighlightFailure(language, error) {
|
|
196
|
+
if (loggedFailures.has(language))
|
|
197
|
+
return;
|
|
198
|
+
loggedFailures.add(language);
|
|
199
|
+
console.warn(`Syntax highlighting unavailable for ${language}; rendering plain code.`, error);
|
|
200
|
+
}
|
|
201
|
+
function loadHighlight(code, language) {
|
|
202
|
+
const cacheKey = `${language}\0${code}`;
|
|
203
|
+
const cached = resultCache.get(cacheKey);
|
|
204
|
+
if (cached)
|
|
205
|
+
return Promise.resolve(cached);
|
|
206
|
+
const pending = pendingHighlights.get(cacheKey);
|
|
207
|
+
if (pending)
|
|
208
|
+
return pending;
|
|
209
|
+
const loading = getHighlighter()
|
|
210
|
+
.then(async (highlighter) => {
|
|
211
|
+
await ensureThemes(highlighter);
|
|
212
|
+
await ensureLanguage(highlighter, language);
|
|
213
|
+
const result = highlighter.codeToTokens(code, {
|
|
214
|
+
lang: language,
|
|
215
|
+
themes: {
|
|
216
|
+
dark: DARK_THEME,
|
|
217
|
+
light: LIGHT_THEME,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
bg: result.bg,
|
|
222
|
+
fg: result.fg,
|
|
223
|
+
rootStyle: result.rootStyle,
|
|
224
|
+
tokens: result.tokens,
|
|
225
|
+
};
|
|
226
|
+
})
|
|
227
|
+
.catch((error) => {
|
|
228
|
+
reportHighlightFailure(language, error);
|
|
229
|
+
return rawHighlight(code);
|
|
230
|
+
})
|
|
231
|
+
.then((result) => {
|
|
232
|
+
cacheResult(cacheKey, result);
|
|
233
|
+
return result;
|
|
234
|
+
})
|
|
235
|
+
.finally(() => {
|
|
236
|
+
pendingHighlights.delete(cacheKey);
|
|
237
|
+
});
|
|
238
|
+
pendingHighlights.set(cacheKey, loading);
|
|
239
|
+
return loading;
|
|
240
|
+
}
|
|
241
|
+
// Annotated (not `satisfies`) so the emitted declaration names the public
|
|
242
|
+
// CodeHighlighterPlugin type instead of streamdown's unexported internals.
|
|
243
|
+
export const markdownCodeHighlighter = {
|
|
244
|
+
getSupportedLanguages: () => [...SUPPORTED_MARKDOWN_LANGUAGES],
|
|
245
|
+
getThemes: () => [LIGHT_THEME, DARK_THEME],
|
|
246
|
+
highlight: ({ code, language }, callback) => {
|
|
247
|
+
const normalizedLanguage = normalizeLanguage(language);
|
|
248
|
+
if (!normalizedLanguage)
|
|
249
|
+
return rawHighlight(code);
|
|
250
|
+
const cacheKey = `${normalizedLanguage}\0${code}`;
|
|
251
|
+
const cached = resultCache.get(cacheKey);
|
|
252
|
+
if (cached)
|
|
253
|
+
return cached;
|
|
254
|
+
const loading = loadHighlight(code, normalizedLanguage);
|
|
255
|
+
if (callback) {
|
|
256
|
+
void loading.then((result) => callback(result));
|
|
257
|
+
}
|
|
258
|
+
return null;
|
|
259
|
+
},
|
|
260
|
+
name: "shiki",
|
|
261
|
+
supportsLanguage: (language) => normalizeLanguage(language) !== null,
|
|
262
|
+
type: "code-highlighter",
|
|
263
|
+
};
|
|
264
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../components/markdown.ts"],"names":[],"mappings":"AAWA,OAAO,EACN,kBAAkB,EAClB,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,GAGpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAyBpD;4EAC4E;AAC5E,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACpC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;IACrC,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,KAAK;CACa,CAAC;AAE3B;;iDAEiD;AACjD,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC/C,GAAG,qBAAqB;IACxB,OAAO,EAAE;QACR,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,IAAI;KACb;CACwB,CAAC;AAE3B,OAAO,EACN,kBAAkB,EAClB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAM3B,sBAAsB,GACtB,MAAM,sBAAsB,CAA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YAAY,CAAC,IAAI,CAAC,CAAC;QAEnD,MAAM,QAAQ,GAAG,GAAG,kBAAkB,KAAK,IAAI,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAE1B,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;QACxD,IAAI,QAAQ,EAAE,CAAC;YACd,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,EAAE,OAAO;IACb,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,IAAI;IACpE,IAAI,EAAE,kBAAkB;CACxB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CustomRenderer, CustomRendererProps } from "streamdown";
|
|
2
|
+
import { type MermaidModuleLoader, type MermaidService } from "./mermaid-diagram.js";
|
|
3
|
+
export interface MermaidBlockProps extends CustomRendererProps {
|
|
4
|
+
service: MermaidService;
|
|
5
|
+
}
|
|
6
|
+
export declare function MermaidBlock({ code, isIncomplete, meta, service, }: MermaidBlockProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
/**
|
|
8
|
+
* Streamdown custom renderer for ```mermaid fences. Register with
|
|
9
|
+
* `plugins={{ renderers: [createMermaidRenderer()] }}`; Streamdown checks custom
|
|
10
|
+
* renderers before its built-in Mermaid block, so no `mermaid` plugin is
|
|
11
|
+
* needed. Create it once (module scope) so the component identity is stable.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createMermaidRenderer(loader?: MermaidModuleLoader): CustomRenderer;
|
|
14
|
+
//# sourceMappingURL=mermaid-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-block.d.ts","sourceRoot":"","sources":["../../components/mermaid-block.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAON,KAAK,mBAAmB,EACxB,KAAK,cAAc,EAMnB,MAAM,sBAAsB,CAAC;AAgf9B,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC7D,OAAO,EAAE,cAAc,CAAC;CACxB;AAED,wBAAgB,YAAY,CAAC,EAC5B,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,OAAO,GACP,EAAE,iBAAiB,2CA0KnB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,MAAM,CAAC,EAAE,mBAAmB,GAC1B,cAAc,CAMhB"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import { buildMermaidConfig, createMermaidService, describeMermaidError, diagramFileName, INITIAL_DIAGRAM_VIEW, normalizeDiagramSource, resolveDiagramSlug, stepDiagramZoom, wheelZoomScale, zoomViewAtPoint, } from "./mermaid-diagram.js";
|
|
5
|
+
import { cleanupMermaidArtifacts, downloadBlob, downloadText, observeThemeChanges, readMermaidTheme, svgToPngBlob, waitForFonts, } from "./mermaid-dom.js";
|
|
6
|
+
const COPIED_RESET_MS = 1500;
|
|
7
|
+
const NOTICE_RESET_MS = 4000;
|
|
8
|
+
let cachedConfig;
|
|
9
|
+
/** One config object per theme so `initialize` only reruns when it changes. */
|
|
10
|
+
function themedConfig(theme) {
|
|
11
|
+
if (cachedConfig?.key !== theme.key) {
|
|
12
|
+
cachedConfig = {
|
|
13
|
+
config: buildMermaidConfig(theme.tokens, theme.mode, {
|
|
14
|
+
fontFamily: theme.fontFamily,
|
|
15
|
+
}),
|
|
16
|
+
key: theme.key,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return cachedConfig.config;
|
|
20
|
+
}
|
|
21
|
+
function Icon({ children }) {
|
|
22
|
+
return (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "14", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", width: "14", xmlns: "http://www.w3.org/2000/svg", children: children }));
|
|
23
|
+
}
|
|
24
|
+
const ICONS = {
|
|
25
|
+
check: _jsx("path", { d: "M20 6 9 17l-5-5" }),
|
|
26
|
+
copy: (_jsxs(_Fragment, { children: [_jsx("rect", { height: "13", rx: "2", width: "13", x: "9", y: "9" }), _jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })] })),
|
|
27
|
+
download: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }), _jsx("path", { d: "m7 10 5 5 5-5" }), _jsx("path", { d: "M12 15V3" })] })),
|
|
28
|
+
enter: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M15 3h6v6" }), _jsx("path", { d: "M9 21H3v-6" }), _jsx("path", { d: "m21 3-7 7" }), _jsx("path", { d: "m3 21 7-7" })] })),
|
|
29
|
+
exit: (_jsxs(_Fragment, { children: [_jsx("path", { d: "m14 10 7-7" }), _jsx("path", { d: "M20 10h-6V4" }), _jsx("path", { d: "m3 21 7-7" }), _jsx("path", { d: "M4 14h6v6" })] })),
|
|
30
|
+
reset: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M3 12a9 9 0 1 0 3-6.7" }), _jsx("path", { d: "M3 4v5h5" })] })),
|
|
31
|
+
zoomIn: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "11", cy: "11", r: "8" }), _jsx("path", { d: "m21 21-4.3-4.3" }), _jsx("path", { d: "M11 8v6" }), _jsx("path", { d: "M8 11h6" })] })),
|
|
32
|
+
zoomOut: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "11", cy: "11", r: "8" }), _jsx("path", { d: "m21 21-4.3-4.3" }), _jsx("path", { d: "M8 11h6" })] })),
|
|
33
|
+
};
|
|
34
|
+
function ToolbarButton({ children, disabled, label, onClick, buttonRef, }) {
|
|
35
|
+
return (_jsx("button", { "aria-label": label, className: "cline-mermaid__button", disabled: disabled, onClick: onClick, ref: buttonRef, title: label, type: "button", children: children }));
|
|
36
|
+
}
|
|
37
|
+
function DownloadMenu({ onMmd, onPng, pngDisabled, }) {
|
|
38
|
+
const [open, setOpen] = useState(false);
|
|
39
|
+
const rootRef = useRef(null);
|
|
40
|
+
const triggerRef = useRef(null);
|
|
41
|
+
const close = useCallback((restoreFocus) => {
|
|
42
|
+
setOpen(false);
|
|
43
|
+
if (restoreFocus)
|
|
44
|
+
triggerRef.current?.focus();
|
|
45
|
+
}, []);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!open)
|
|
48
|
+
return;
|
|
49
|
+
rootRef.current?.querySelector('[role="menuitem"]')?.focus();
|
|
50
|
+
const onPointerDown = (event) => {
|
|
51
|
+
if (event.target instanceof Node &&
|
|
52
|
+
rootRef.current?.contains(event.target)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setOpen(false);
|
|
56
|
+
};
|
|
57
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
58
|
+
return () => document.removeEventListener("pointerdown", onPointerDown);
|
|
59
|
+
}, [open]);
|
|
60
|
+
const onMenuKeyDown = (event) => {
|
|
61
|
+
if (event.key === "Escape") {
|
|
62
|
+
// Keep an enclosing fullscreen dialog open.
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
event.stopPropagation();
|
|
65
|
+
close(true);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp")
|
|
69
|
+
return;
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
const items = [
|
|
72
|
+
...event.currentTarget.querySelectorAll('[role="menuitem"]'),
|
|
73
|
+
].filter((item) => !item.hasAttribute("disabled"));
|
|
74
|
+
if (items.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
const active = document.activeElement;
|
|
77
|
+
const index = active instanceof HTMLElement ? items.indexOf(active) : -1;
|
|
78
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
79
|
+
items[(index + step + items.length) % items.length]?.focus();
|
|
80
|
+
};
|
|
81
|
+
const choose = (action) => () => {
|
|
82
|
+
close(true);
|
|
83
|
+
action();
|
|
84
|
+
};
|
|
85
|
+
return (_jsxs("div", { className: "cline-mermaid__menu-root", ref: rootRef, children: [_jsx("button", { "aria-expanded": open, "aria-haspopup": "menu", "aria-label": "Download diagram", className: "cline-mermaid__button", onClick: () => setOpen((current) => !current), ref: triggerRef, title: "Download diagram", type: "button", children: _jsx(Icon, { children: ICONS.download }) }), open ? (_jsxs("div", { "aria-label": "Download diagram", className: "cline-mermaid__menu", onKeyDown: onMenuKeyDown, role: "menu", tabIndex: -1, children: [_jsx("button", { className: "cline-mermaid__menu-item", disabled: pngDisabled, onClick: choose(onPng), role: "menuitem", type: "button", children: "PNG image" }), _jsx("button", { className: "cline-mermaid__menu-item", onClick: choose(onMmd), role: "menuitem", type: "button", children: "Mermaid source (.mmd)" })] })) : null] }));
|
|
86
|
+
}
|
|
87
|
+
function useDiagramView({ interactive }) {
|
|
88
|
+
const [view, setView] = useState(INITIAL_DIAGRAM_VIEW);
|
|
89
|
+
// State-backed ref: the viewport mounts only once the SVG is ready.
|
|
90
|
+
const [viewport, setViewport] = useState(null);
|
|
91
|
+
const drag = useRef(null);
|
|
92
|
+
const zoomBy = useCallback((direction) => {
|
|
93
|
+
const rect = viewport?.getBoundingClientRect();
|
|
94
|
+
const center = rect
|
|
95
|
+
? { x: rect.width / 2, y: rect.height / 2 }
|
|
96
|
+
: { x: 0, y: 0 };
|
|
97
|
+
setView((current) => {
|
|
98
|
+
const next = zoomViewAtPoint(current, stepDiagramZoom(current.scale, direction), center);
|
|
99
|
+
return next.scale === 1 ? INITIAL_DIAGRAM_VIEW : next;
|
|
100
|
+
});
|
|
101
|
+
}, [viewport]);
|
|
102
|
+
const reset = useCallback(() => setView(INITIAL_DIAGRAM_VIEW), []);
|
|
103
|
+
// Native listener: React's onWheel is passive and cannot preventDefault.
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!viewport)
|
|
106
|
+
return;
|
|
107
|
+
const onWheel = (event) => {
|
|
108
|
+
// Inline, a plain wheel keeps scrolling the chat; pinch (ctrlKey) and
|
|
109
|
+
// cmd/ctrl+wheel zoom instead.
|
|
110
|
+
if (!interactive && !event.ctrlKey && !event.metaKey)
|
|
111
|
+
return;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
const rect = viewport.getBoundingClientRect();
|
|
114
|
+
const point = {
|
|
115
|
+
x: event.clientX - rect.left,
|
|
116
|
+
y: event.clientY - rect.top,
|
|
117
|
+
};
|
|
118
|
+
setView((current) => zoomViewAtPoint(current, wheelZoomScale(current.scale, event.deltaY), point));
|
|
119
|
+
};
|
|
120
|
+
viewport.addEventListener("wheel", onWheel, { passive: false });
|
|
121
|
+
return () => viewport.removeEventListener("wheel", onWheel);
|
|
122
|
+
}, [viewport, interactive]);
|
|
123
|
+
const canPan = interactive || view.scale !== 1;
|
|
124
|
+
const onPointerDown = (event) => {
|
|
125
|
+
if (!canPan || event.button !== 0)
|
|
126
|
+
return;
|
|
127
|
+
drag.current = {
|
|
128
|
+
originX: view.x,
|
|
129
|
+
originY: view.y,
|
|
130
|
+
pointerId: event.pointerId,
|
|
131
|
+
startX: event.clientX,
|
|
132
|
+
startY: event.clientY,
|
|
133
|
+
};
|
|
134
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
135
|
+
};
|
|
136
|
+
const onPointerMove = (event) => {
|
|
137
|
+
const active = drag.current;
|
|
138
|
+
if (!active || active.pointerId !== event.pointerId)
|
|
139
|
+
return;
|
|
140
|
+
const x = active.originX + event.clientX - active.startX;
|
|
141
|
+
const y = active.originY + event.clientY - active.startY;
|
|
142
|
+
setView((current) => ({ ...current, x, y }));
|
|
143
|
+
};
|
|
144
|
+
const endDrag = (event) => {
|
|
145
|
+
if (drag.current?.pointerId !== event.pointerId)
|
|
146
|
+
return;
|
|
147
|
+
drag.current = null;
|
|
148
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
canPan,
|
|
152
|
+
pointerHandlers: {
|
|
153
|
+
onPointerCancel: endDrag,
|
|
154
|
+
onPointerDown,
|
|
155
|
+
onPointerMove,
|
|
156
|
+
onPointerUp: endDrag,
|
|
157
|
+
},
|
|
158
|
+
reset,
|
|
159
|
+
setViewport,
|
|
160
|
+
view,
|
|
161
|
+
zoomIn: () => zoomBy("in"),
|
|
162
|
+
zoomOut: () => zoomBy("out"),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function ZoomControls({ api }) {
|
|
166
|
+
const percent = Math.round(api.view.scale * 100);
|
|
167
|
+
return (_jsxs(_Fragment, { children: [_jsx(ToolbarButton, { label: "Zoom out", onClick: api.zoomOut, children: _jsx(Icon, { children: ICONS.zoomOut }) }), _jsx(ToolbarButton, { label: "Zoom in", onClick: api.zoomIn, children: _jsx(Icon, { children: ICONS.zoomIn }) }), _jsx(ToolbarButton, { disabled: api.view === INITIAL_DIAGRAM_VIEW, label: `Reset zoom (${percent}%)`, onClick: api.reset, children: _jsx(Icon, { children: ICONS.reset }) })] }));
|
|
168
|
+
}
|
|
169
|
+
function DiagramViewport({ api, label, svg, }) {
|
|
170
|
+
return (_jsx("div", { className: "cline-mermaid__viewport", "data-pannable": api.canPan || undefined, ref: api.setViewport, ...api.pointerHandlers, children: _jsx("div", { "aria-label": label, className: "cline-mermaid__canvas",
|
|
171
|
+
// Mermaid runs with securityLevel "strict", which sanitizes the SVG.
|
|
172
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: sanitized Mermaid SVG output.
|
|
173
|
+
dangerouslySetInnerHTML: { __html: svg }, role: "img", style: {
|
|
174
|
+
transform: `translate(${api.view.x}px, ${api.view.y}px) scale(${api.view.scale})`,
|
|
175
|
+
} }) }));
|
|
176
|
+
}
|
|
177
|
+
function FullscreenDialog({ filename, label, onClose, svg, }) {
|
|
178
|
+
const dialogRef = useRef(null);
|
|
179
|
+
const api = useDiagramView({ interactive: true });
|
|
180
|
+
// A modal <dialog> renders in the top layer, so no ancestor's overflow,
|
|
181
|
+
// transform or containment can clip or mis-position it; it also traps
|
|
182
|
+
// focus and closes on Escape natively. jsdom lacks showModal, hence the
|
|
183
|
+
// attribute fallback (plus an explicit Escape handler below).
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
const dialog = dialogRef.current;
|
|
186
|
+
if (!dialog)
|
|
187
|
+
return;
|
|
188
|
+
if (typeof dialog.showModal === "function") {
|
|
189
|
+
if (!dialog.open)
|
|
190
|
+
dialog.showModal();
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
dialog.setAttribute("open", "");
|
|
194
|
+
}
|
|
195
|
+
return () => {
|
|
196
|
+
if (typeof dialog.close === "function" && dialog.open)
|
|
197
|
+
dialog.close();
|
|
198
|
+
};
|
|
199
|
+
}, []);
|
|
200
|
+
const onKeyDown = (event) => {
|
|
201
|
+
if (event.key !== "Escape" || event.defaultPrevented)
|
|
202
|
+
return;
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
onClose();
|
|
205
|
+
};
|
|
206
|
+
return (_jsxs("dialog", { "aria-label": `${filename} (fullscreen)`, className: "cline-mermaid__dialog", onCancel: (event) => {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
onClose();
|
|
209
|
+
}, onKeyDown: onKeyDown, ref: dialogRef, children: [_jsxs("div", { className: "cline-mermaid__header", children: [_jsx("span", { className: "cline-mermaid__filename", children: filename }), _jsxs("div", { "aria-label": "Diagram actions", className: "cline-mermaid__actions", role: "toolbar", children: [_jsx(ZoomControls, { api: api }), _jsx(ToolbarButton, { label: "Exit fullscreen", onClick: onClose, children: _jsx(Icon, { children: ICONS.exit }) })] })] }), _jsx(DiagramViewport, { api: api, label: label, svg: svg })] }));
|
|
210
|
+
}
|
|
211
|
+
function useMermaidTheme(elementRef) {
|
|
212
|
+
const [theme, setTheme] = useState();
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
const update = () => {
|
|
215
|
+
const next = readMermaidTheme(elementRef.current ?? undefined);
|
|
216
|
+
setTheme((current) => (current?.key === next.key ? current : next));
|
|
217
|
+
};
|
|
218
|
+
update();
|
|
219
|
+
return observeThemeChanges(update);
|
|
220
|
+
}, [elementRef]);
|
|
221
|
+
return theme;
|
|
222
|
+
}
|
|
223
|
+
function useTimedFlag() {
|
|
224
|
+
const [active, setActive] = useState(false);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (!active)
|
|
227
|
+
return;
|
|
228
|
+
const timer = setTimeout(() => setActive(false), COPIED_RESET_MS);
|
|
229
|
+
return () => clearTimeout(timer);
|
|
230
|
+
}, [active]);
|
|
231
|
+
return [active, () => setActive(true)];
|
|
232
|
+
}
|
|
233
|
+
export function MermaidBlock({ code, isIncomplete, meta, service, }) {
|
|
234
|
+
const instanceId = useId().replace(/[^a-zA-Z0-9]/g, "");
|
|
235
|
+
const renderCount = useRef(0);
|
|
236
|
+
const figureRef = useRef(null);
|
|
237
|
+
const fullscreenTriggerRef = useRef(null);
|
|
238
|
+
const theme = useMermaidTheme(figureRef);
|
|
239
|
+
const [state, setState] = useState({ status: "pending" });
|
|
240
|
+
const [retryCount, setRetryCount] = useState(0);
|
|
241
|
+
const [fullscreen, setFullscreen] = useState(false);
|
|
242
|
+
const [copied, markCopied] = useTimedFlag();
|
|
243
|
+
const [notice, setNotice] = useState(null);
|
|
244
|
+
const api = useDiagramView({ interactive: false });
|
|
245
|
+
const slug = useMemo(() => resolveDiagramSlug({ meta, source: code }), [meta, code]);
|
|
246
|
+
const sourceName = diagramFileName(slug, "mmd");
|
|
247
|
+
// Render only once the fence is closed: partial sources either fail to parse
|
|
248
|
+
// or draw a misleading half-diagram. Until then (and while re-rendering after
|
|
249
|
+
// a theme/source change) the last good SVG or a skeleton stays on screen.
|
|
250
|
+
useEffect(() => {
|
|
251
|
+
if (isIncomplete || !theme)
|
|
252
|
+
return;
|
|
253
|
+
let cancelled = false;
|
|
254
|
+
renderCount.current += 1;
|
|
255
|
+
const id = `cline-mermaid-${instanceId}-${retryCount}-${renderCount.current}`;
|
|
256
|
+
void (async () => {
|
|
257
|
+
try {
|
|
258
|
+
await waitForFonts();
|
|
259
|
+
const { svg } = await service.render(id, code, themedConfig(theme));
|
|
260
|
+
if (!cancelled) {
|
|
261
|
+
setState({
|
|
262
|
+
background: theme.tokens.background,
|
|
263
|
+
status: "ready",
|
|
264
|
+
svg,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
if (!cancelled) {
|
|
270
|
+
setState({ message: describeMermaidError(error), status: "error" });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
cleanupMermaidArtifacts(id);
|
|
275
|
+
}
|
|
276
|
+
})();
|
|
277
|
+
return () => {
|
|
278
|
+
cancelled = true;
|
|
279
|
+
};
|
|
280
|
+
}, [code, instanceId, isIncomplete, retryCount, service, theme]);
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
if (!notice)
|
|
283
|
+
return;
|
|
284
|
+
const timer = setTimeout(() => setNotice(null), NOTICE_RESET_MS);
|
|
285
|
+
return () => clearTimeout(timer);
|
|
286
|
+
}, [notice]);
|
|
287
|
+
const copySource = async () => {
|
|
288
|
+
try {
|
|
289
|
+
await navigator.clipboard.writeText(normalizeDiagramSource(code));
|
|
290
|
+
markCopied();
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
setNotice("Couldn't copy the diagram source.");
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
const downloadMmd = () => {
|
|
297
|
+
try {
|
|
298
|
+
downloadText(normalizeDiagramSource(code), sourceName);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
setNotice("Couldn't save the diagram source.");
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const downloadPng = async () => {
|
|
305
|
+
if (state.status !== "ready")
|
|
306
|
+
return;
|
|
307
|
+
try {
|
|
308
|
+
const blob = await svgToPngBlob(state.svg, state.background);
|
|
309
|
+
downloadBlob(blob, diagramFileName(slug, "png"));
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
setNotice("Couldn't export the PNG. Download the .mmd source instead.");
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const closeFullscreen = useCallback(() => {
|
|
316
|
+
setFullscreen(false);
|
|
317
|
+
fullscreenTriggerRef.current?.focus();
|
|
318
|
+
}, []);
|
|
319
|
+
const ready = state.status === "ready";
|
|
320
|
+
const label = `Mermaid diagram: ${slug}`;
|
|
321
|
+
return (_jsxs("figure", { className: "cline-mermaid", "data-cline-mermaid": state.status, "data-streamdown": "mermaid-block", ref: figureRef, children: [_jsxs("figcaption", { className: "cline-mermaid__header", children: [_jsx("span", { className: "cline-mermaid__filename", title: sourceName, children: sourceName }), _jsxs("div", { "aria-label": "Diagram actions", className: "cline-mermaid__actions", role: "toolbar", children: [ready ? _jsx(ZoomControls, { api: api }) : null, _jsx(ToolbarButton, { label: copied ? "Copied" : "Copy diagram source", onClick: () => void copySource(), children: _jsx(Icon, { children: copied ? ICONS.check : ICONS.copy }) }), _jsx(DownloadMenu, { onMmd: downloadMmd, onPng: () => void downloadPng(), pngDisabled: !ready }), _jsx(ToolbarButton, { buttonRef: fullscreenTriggerRef, disabled: !ready, label: "View fullscreen", onClick: () => setFullscreen(true), children: _jsx(Icon, { children: ICONS.enter }) })] })] }), state.status === "ready" ? (_jsx(DiagramViewport, { api: api, label: label, svg: state.svg })) : null, state.status === "pending" ? (_jsxs("output", { "aria-busy": "true", className: "cline-mermaid__skeleton", children: [_jsx("span", { "aria-hidden": "true", className: "cline-mermaid__spinner" }), isIncomplete ? "Drawing diagram…" : "Rendering diagram…"] })) : null, state.status === "error" ? (_jsxs("div", { className: "cline-mermaid__error", role: "alert", children: [_jsxs("p", { children: ["Mermaid Error: ", state.message] }), _jsx("pre", { children: _jsx("code", { children: code }) }), _jsx("button", { className: "cline-mermaid__retry", onClick: () => {
|
|
322
|
+
setState({ status: "pending" });
|
|
323
|
+
setRetryCount((count) => count + 1);
|
|
324
|
+
}, type: "button", children: "Retry" })] })) : null, notice ? (_jsx("output", { className: "cline-mermaid__notice", children: notice })) : null, fullscreen && state.status === "ready" ? (_jsx(FullscreenDialog, { filename: sourceName, label: label, onClose: closeFullscreen, svg: state.svg })) : null] }));
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Streamdown custom renderer for ```mermaid fences. Register with
|
|
328
|
+
* `plugins={{ renderers: [createMermaidRenderer()] }}`; Streamdown checks custom
|
|
329
|
+
* renderers before its built-in Mermaid block, so no `mermaid` plugin is
|
|
330
|
+
* needed. Create it once (module scope) so the component identity is stable.
|
|
331
|
+
*/
|
|
332
|
+
export function createMermaidRenderer(loader) {
|
|
333
|
+
const service = createMermaidService(loader);
|
|
334
|
+
function MermaidRenderer(props) {
|
|
335
|
+
return _jsx(MermaidBlock, { ...props, service: service });
|
|
336
|
+
}
|
|
337
|
+
return { component: MermaidRenderer, language: "mermaid" };
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=mermaid-block.js.map
|