@octanejs/streamdown 0.1.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 (69) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +39 -0
  3. package/UPSTREAM.md +15 -0
  4. package/dist/client/chunks/chunk-6IDAODM4.js +4809 -0
  5. package/dist/client/chunks/highlighted-body-PYQZ7NZ4.js +69 -0
  6. package/dist/client/chunks/mermaid-I6WR5JDC.js +7 -0
  7. package/dist/client/cjk.js +104 -0
  8. package/dist/client/code.js +115 -0
  9. package/dist/client/index.js +57 -0
  10. package/dist/client/math.js +30 -0
  11. package/dist/client/mermaid.js +46 -0
  12. package/dist/server/chunks/chunk-55X6YY2C.js +4526 -0
  13. package/dist/server/chunks/highlighted-body-NLELYOBH.js +60 -0
  14. package/dist/server/chunks/mermaid-SICAYVAP.js +7 -0
  15. package/dist/server/cjk.js +104 -0
  16. package/dist/server/code.js +115 -0
  17. package/dist/server/index.js +57 -0
  18. package/dist/server/math.js +30 -0
  19. package/dist/server/mermaid.js +46 -0
  20. package/dist/styles.css +35 -0
  21. package/dist/types/cjk.d.ts +32 -0
  22. package/dist/types/code.d.ts +58 -0
  23. package/dist/types/hooks/use-deferred-render.d.ts +60 -0
  24. package/dist/types/index.d.ts +161 -0
  25. package/dist/types/lib/animate.d.ts +33 -0
  26. package/dist/types/lib/block-incomplete-context.d.ts +15 -0
  27. package/dist/types/lib/code-block/body.d.ts +12 -0
  28. package/dist/types/lib/code-block/container.d.ts +10 -0
  29. package/dist/types/lib/code-block/context.d.ts +7 -0
  30. package/dist/types/lib/code-block/copy-button.d.ts +10 -0
  31. package/dist/types/lib/code-block/download-button.d.ts +10 -0
  32. package/dist/types/lib/code-block/header.d.ts +6 -0
  33. package/dist/types/lib/code-block/highlighted-body.d.ts +12 -0
  34. package/dist/types/lib/code-block/index.d.ts +14 -0
  35. package/dist/types/lib/code-block/skeleton.d.ts +2 -0
  36. package/dist/types/lib/components.d.ts +3 -0
  37. package/dist/types/lib/detect-direction.d.ts +14 -0
  38. package/dist/types/lib/icon-context.d.ts +25 -0
  39. package/dist/types/lib/icons.d.ts +17 -0
  40. package/dist/types/lib/image.d.ts +6 -0
  41. package/dist/types/lib/incomplete-code-utils.d.ts +25 -0
  42. package/dist/types/lib/link-modal.d.ts +9 -0
  43. package/dist/types/lib/markdown.d.ts +33 -0
  44. package/dist/types/lib/mermaid/download-button.d.ts +13 -0
  45. package/dist/types/lib/mermaid/fullscreen-button.d.ts +11 -0
  46. package/dist/types/lib/mermaid/index.d.ts +11 -0
  47. package/dist/types/lib/mermaid/pan-zoom.d.ts +14 -0
  48. package/dist/types/lib/mermaid/utils.d.ts +7 -0
  49. package/dist/types/lib/parse-blocks.d.ts +2 -0
  50. package/dist/types/lib/plugin-context.d.ts +30 -0
  51. package/dist/types/lib/plugin-types.d.ts +151 -0
  52. package/dist/types/lib/prefix-context.d.ts +13 -0
  53. package/dist/types/lib/preprocess-custom-tags.d.ts +20 -0
  54. package/dist/types/lib/preprocess-literal-tag-content.d.ts +25 -0
  55. package/dist/types/lib/rehype/literal-tag-content.d.ts +13 -0
  56. package/dist/types/lib/remark/code-meta.d.ts +10 -0
  57. package/dist/types/lib/remark/escape-html.d.ts +4 -0
  58. package/dist/types/lib/scroll-lock.d.ts +3 -0
  59. package/dist/types/lib/table/copy-dropdown.d.ts +10 -0
  60. package/dist/types/lib/table/download-dropdown.d.ts +18 -0
  61. package/dist/types/lib/table/fullscreen-button.d.ts +10 -0
  62. package/dist/types/lib/table/index.d.ts +10 -0
  63. package/dist/types/lib/table/utils.d.ts +11 -0
  64. package/dist/types/lib/translations-context.d.ts +35 -0
  65. package/dist/types/lib/types.d.ts +17 -0
  66. package/dist/types/lib/utils.d.ts +19 -0
  67. package/dist/types/math.d.ts +44 -0
  68. package/dist/types/mermaid-plugin.d.ts +44 -0
  69. package/package.json +121 -0
@@ -0,0 +1,4526 @@
1
+ // octane-no-slot: this package already contains compiler-assigned hook slots.
2
+
3
+ // src/lib/mermaid/index.tsrx
4
+ import {
5
+ createElement as _$createElement18,
6
+ createScopedElement as _$createScopedElement19,
7
+ createScopedValue as _$createScopedValue21,
8
+ positionalChildren as _$positionalChildren14,
9
+ useContext as useContext15,
10
+ useEffect as useEffect12,
11
+ useRef as useRef10,
12
+ useState as useState13
13
+ } from "octane/server";
14
+
15
+ // src/hooks/use-deferred-render.tsrx
16
+ import { useEffect, useMemo, useRef, useState } from "octane/server";
17
+ var DEFERRED_RENDER_DEBOUNCE_DELAY = 300;
18
+ var DEFERRED_RENDER_ROOT_MARGIN = "300px";
19
+ var DEFERRED_RENDER_IDLE_TIMEOUT = 500;
20
+ function withoutSlot(value) {
21
+ return typeof value === "symbol" ? void 0 : value;
22
+ }
23
+ function useDeferredRender(options = {}) {
24
+ const {
25
+ immediate = false,
26
+ debounceDelay = DEFERRED_RENDER_DEBOUNCE_DELAY,
27
+ rootMargin = DEFERRED_RENDER_ROOT_MARGIN,
28
+ idleTimeout = DEFERRED_RENDER_IDLE_TIMEOUT
29
+ } = withoutSlot(options) ?? {};
30
+ const [shouldRender, setShouldRender] = useState(false);
31
+ const containerRef = useRef(null);
32
+ const renderTimeoutRef = useRef(null);
33
+ const idleCallbackRef = useRef(null);
34
+ const requestIdleCallbackPolyfill = useMemo(
35
+ () => (callback) => {
36
+ const start = Date.now();
37
+ return window.setTimeout(
38
+ () => {
39
+ callback({
40
+ didTimeout: false,
41
+ timeRemaining: () => Math.max(0, 50 - (Date.now() - start))
42
+ });
43
+ },
44
+ 1
45
+ );
46
+ },
47
+ []
48
+ );
49
+ const requestIdleCallbackWrapper = useMemo(
50
+ () => typeof window !== "undefined" && window.requestIdleCallback ? (cb, opts) => window.requestIdleCallback(cb, opts) : requestIdleCallbackPolyfill,
51
+ [requestIdleCallbackPolyfill]
52
+ );
53
+ const cancelIdleCallbackWrapper = useMemo(
54
+ () => typeof window !== "undefined" && window.cancelIdleCallback ? (id) => window.cancelIdleCallback(id) : (id) => {
55
+ clearTimeout(id);
56
+ },
57
+ []
58
+ );
59
+ useEffect(
60
+ () => {
61
+ if (immediate) {
62
+ setShouldRender(true);
63
+ return;
64
+ }
65
+ const container = containerRef.current;
66
+ if (!container) {
67
+ return;
68
+ }
69
+ if (renderTimeoutRef.current) {
70
+ clearTimeout(renderTimeoutRef.current);
71
+ renderTimeoutRef.current = null;
72
+ }
73
+ if (idleCallbackRef.current) {
74
+ cancelIdleCallbackWrapper(idleCallbackRef.current);
75
+ idleCallbackRef.current = null;
76
+ }
77
+ const clearPendingRenders = () => {
78
+ if (renderTimeoutRef.current) {
79
+ clearTimeout(renderTimeoutRef.current);
80
+ renderTimeoutRef.current = null;
81
+ }
82
+ if (idleCallbackRef.current) {
83
+ cancelIdleCallbackWrapper(idleCallbackRef.current);
84
+ idleCallbackRef.current = null;
85
+ }
86
+ };
87
+ const scheduleRender = (obs) => {
88
+ idleCallbackRef.current = requestIdleCallbackWrapper(
89
+ (deadline) => {
90
+ if (deadline.timeRemaining() > 0 || deadline.didTimeout) {
91
+ setShouldRender(true);
92
+ obs.disconnect();
93
+ } else {
94
+ idleCallbackRef.current = requestIdleCallbackWrapper(
95
+ () => {
96
+ setShouldRender(true);
97
+ obs.disconnect();
98
+ },
99
+ { timeout: idleTimeout / 2 }
100
+ );
101
+ }
102
+ },
103
+ { timeout: idleTimeout }
104
+ );
105
+ };
106
+ const handleIntersecting = (obs) => {
107
+ clearPendingRenders();
108
+ renderTimeoutRef.current = window.setTimeout(
109
+ () => {
110
+ const records = obs.takeRecords();
111
+ const isStillInView = records.length === 0 || (records.at(-1)?.isIntersecting ?? false);
112
+ if (isStillInView) {
113
+ scheduleRender(obs);
114
+ }
115
+ },
116
+ debounceDelay
117
+ );
118
+ };
119
+ const handleIntersection = (entry, obs) => {
120
+ if (entry.isIntersecting) {
121
+ handleIntersecting(obs);
122
+ } else {
123
+ clearPendingRenders();
124
+ }
125
+ };
126
+ const observer = new IntersectionObserver(
127
+ (entries) => {
128
+ for (const entry of entries) {
129
+ handleIntersection(entry, observer);
130
+ }
131
+ },
132
+ { rootMargin, threshold: 0 }
133
+ );
134
+ observer.observe(container);
135
+ return () => {
136
+ if (renderTimeoutRef.current) {
137
+ clearTimeout(renderTimeoutRef.current);
138
+ }
139
+ if (idleCallbackRef.current) {
140
+ cancelIdleCallbackWrapper(idleCallbackRef.current);
141
+ }
142
+ observer.disconnect();
143
+ };
144
+ },
145
+ [
146
+ immediate,
147
+ debounceDelay,
148
+ rootMargin,
149
+ idleTimeout,
150
+ cancelIdleCallbackWrapper,
151
+ requestIdleCallbackWrapper
152
+ ]
153
+ );
154
+ return { shouldRender, containerRef };
155
+ }
156
+
157
+ // src/index.tsrx
158
+ import {
159
+ createContext as createContext7,
160
+ createElement as createElement3,
161
+ createElement as _$createElement16,
162
+ createScopedElement as _$createScopedElement17,
163
+ createScopedValue as _$createScopedValue19,
164
+ memo as memo3,
165
+ positionalChildren as _$positionalChildren12,
166
+ useEffect as useEffect10,
167
+ useId,
168
+ useMemo as useMemo4,
169
+ useRef as useRef8,
170
+ useState as useState11,
171
+ useTransition
172
+ } from "octane/server";
173
+ import { harden } from "rehype-harden";
174
+ import rehypeRaw2 from "rehype-raw";
175
+ import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
176
+ import remarkGfm from "remark-gfm";
177
+ import remend from "remend";
178
+
179
+ // src/lib/animate.ts
180
+ import { SKIP, visitParents } from "unist-util-visit-parents";
181
+ var WHITESPACE_RE = /\s/;
182
+ var WHITESPACE_ONLY_RE = /^\s+$/;
183
+ var SKIP_TAGS = /* @__PURE__ */ new Set(["code", "pre", "svg", "math", "annotation"]);
184
+ var isElement = (node) => typeof node === "object" && node !== null && "type" in node && node.type === "element";
185
+ var hasSkipAncestor = (ancestors) => ancestors.some((ancestor) => isElement(ancestor) && SKIP_TAGS.has(ancestor.tagName));
186
+ var splitByWord = (text) => {
187
+ const parts = [];
188
+ let current = "";
189
+ let inWhitespace = false;
190
+ for (const char of text) {
191
+ const isWs = WHITESPACE_RE.test(char);
192
+ if (isWs !== inWhitespace && current) {
193
+ parts.push(current);
194
+ current = "";
195
+ }
196
+ current += char;
197
+ inWhitespace = isWs;
198
+ }
199
+ if (current) {
200
+ parts.push(current);
201
+ }
202
+ return parts;
203
+ };
204
+ var splitByChar = (text) => {
205
+ const parts = [];
206
+ let wsBuffer = "";
207
+ for (const char of text) {
208
+ if (WHITESPACE_RE.test(char)) {
209
+ wsBuffer += char;
210
+ } else {
211
+ if (wsBuffer) {
212
+ parts.push(wsBuffer);
213
+ wsBuffer = "";
214
+ }
215
+ parts.push(char);
216
+ }
217
+ }
218
+ if (wsBuffer) {
219
+ parts.push(wsBuffer);
220
+ }
221
+ return parts;
222
+ };
223
+ var makeSpan = (word, animation, duration, easing, skipAnimation, delay) => {
224
+ let style = `--sd-animation:sd-${animation};--sd-duration:${skipAnimation ? 0 : duration}ms;--sd-easing:${easing}`;
225
+ if (delay) {
226
+ style += `;--sd-delay:${delay}ms`;
227
+ }
228
+ return {
229
+ type: "element",
230
+ tagName: "span",
231
+ properties: {
232
+ "data-sd-animate": true,
233
+ style
234
+ },
235
+ children: [{ type: "text", value: word }]
236
+ };
237
+ };
238
+ var createAnimateRenderState = () => ({
239
+ prevContentLength: 0,
240
+ lastRenderCharCount: 0
241
+ });
242
+ var processTextNode = (node, ancestors, config, renderState, charCounter) => {
243
+ const ancestor = ancestors.at(-1);
244
+ if (!(ancestor && "children" in ancestor)) {
245
+ return;
246
+ }
247
+ if (hasSkipAncestor(ancestors)) {
248
+ return SKIP;
249
+ }
250
+ const parent = ancestor;
251
+ const index = parent.children.indexOf(node);
252
+ if (index === -1) {
253
+ return;
254
+ }
255
+ const text = node.value;
256
+ if (!text.trim()) {
257
+ charCounter.count += text.length;
258
+ return;
259
+ }
260
+ const parts = config.sep === "char" ? splitByChar(text) : splitByWord(text);
261
+ const prevLen = renderState.prevContentLength;
262
+ const nodes = parts.map((part) => {
263
+ const partStart = charCounter.count;
264
+ charCounter.count += part.length;
265
+ if (WHITESPACE_ONLY_RE.test(part)) {
266
+ return { type: "text", value: part };
267
+ }
268
+ const skipAnimation = prevLen > 0 && partStart < prevLen;
269
+ const delay = skipAnimation ? 0 : charCounter.newIndex++ * config.stagger;
270
+ return makeSpan(part, config.animation, config.duration, config.easing, skipAnimation, delay);
271
+ });
272
+ parent.children.splice(index, 1, ...nodes);
273
+ return index + nodes.length;
274
+ };
275
+ var instanceId = 0;
276
+ function createAnimatePlugin(options) {
277
+ const config = {
278
+ animation: options?.animation ?? "fadeIn",
279
+ duration: options?.duration ?? 150,
280
+ easing: options?.easing ?? "ease",
281
+ sep: options?.sep ?? "word",
282
+ stagger: options?.stagger ?? 40
283
+ };
284
+ const renderStates = /* @__PURE__ */ new Map();
285
+ let activeBlock = "static";
286
+ const getRenderState = () => {
287
+ let state = renderStates.get(activeBlock);
288
+ if (!state) {
289
+ state = createAnimateRenderState();
290
+ renderStates.set(activeBlock, state);
291
+ }
292
+ return state;
293
+ };
294
+ const id = instanceId++;
295
+ const rehypeAnimate = () => (tree) => {
296
+ const renderState = getRenderState();
297
+ const charCounter = { count: 0, newIndex: 0 };
298
+ visitParents(
299
+ tree,
300
+ "text",
301
+ (node, ancestors) => processTextNode(node, ancestors, config, renderState, charCounter)
302
+ );
303
+ renderState.lastRenderCharCount = charCounter.count;
304
+ renderState.prevContentLength = 0;
305
+ };
306
+ Object.defineProperty(rehypeAnimate, "name", {
307
+ value: `rehypeAnimate$${id}`
308
+ });
309
+ return {
310
+ name: "animate",
311
+ type: "animate",
312
+ rehypePlugin: rehypeAnimate,
313
+ setActiveBlock(key) {
314
+ activeBlock = key;
315
+ },
316
+ setPrevContentLength(length) {
317
+ getRenderState().prevContentLength = length;
318
+ },
319
+ getLastRenderCharCount() {
320
+ const renderState = getRenderState();
321
+ const count = renderState.lastRenderCharCount;
322
+ renderState.lastRenderCharCount = 0;
323
+ return count;
324
+ }
325
+ };
326
+ }
327
+ var animate = createAnimatePlugin();
328
+
329
+ // src/lib/block-incomplete-context.ts
330
+ import { createContext, useContext } from "octane/server";
331
+ var BlockIncompleteContext = createContext(false);
332
+ var useIsCodeFenceIncomplete = () => useContext(BlockIncompleteContext);
333
+
334
+ // src/lib/components.tsrx
335
+ import {
336
+ Fragment as _$Fragment4,
337
+ Suspense as Suspense2,
338
+ cloneElement,
339
+ createElement as _$createElement15,
340
+ createScopedElement as _$createScopedElement16,
341
+ createScopedValue as _$createScopedValue18,
342
+ isValidElement,
343
+ lazy as lazy2,
344
+ memo as memo2,
345
+ positionalChildren as _$positionalChildren11,
346
+ useCallback as useCallback3,
347
+ useContext as useContext14,
348
+ useState as useState10
349
+ } from "octane/server";
350
+
351
+ // src/lib/code-block/index.tsrx
352
+ import {
353
+ Suspense,
354
+ createElement as _$createElement2,
355
+ createScopedElement as _$createScopedElement3,
356
+ createScopedValue as _$createScopedValue4,
357
+ lazy,
358
+ positionalChildren as _$positionalChildren,
359
+ useMemo as useMemo3
360
+ } from "octane/server";
361
+
362
+ // src/lib/prefix-context.tsrx
363
+ import { createContext as createContext2, useContext as useContext2 } from "octane/server";
364
+
365
+ // src/lib/utils.ts
366
+ import { clsx } from "clsx";
367
+ import { twMerge } from "tailwind-merge";
368
+ var cn = (...inputs) => twMerge(clsx(inputs));
369
+ var prefixClasses = (prefix, classString) => {
370
+ if (!prefix || !classString) return classString;
371
+ const prefixWithColon = `${prefix}:`;
372
+ return classString.split(/\s+/).filter(Boolean).map((cls) => cls.startsWith(prefixWithColon) ? cls : `${prefix}:${cls}`).join(" ");
373
+ };
374
+ var createCn = (prefix) => {
375
+ if (!prefix) return cn;
376
+ return (...inputs) => prefixClasses(prefix, twMerge(clsx(inputs)));
377
+ };
378
+ var save = (filename, content, mimeType) => {
379
+ const bom = typeof content === "string" && mimeType.startsWith("text/csv") ? "\uFEFF" : "";
380
+ const blob = typeof content === "string" ? new Blob([bom + content], { type: mimeType }) : content;
381
+ const url = URL.createObjectURL(blob);
382
+ const a = document.createElement("a");
383
+ a.href = url;
384
+ a.download = filename;
385
+ document.body.appendChild(a);
386
+ a.click();
387
+ document.body.removeChild(a);
388
+ URL.revokeObjectURL(url);
389
+ };
390
+
391
+ // src/lib/prefix-context.tsrx
392
+ var PrefixContext = createContext2(cn);
393
+ var useCn = () => useContext2(PrefixContext);
394
+
395
+ // src/lib/code-block/body.tsrx
396
+ import {
397
+ createScopedElement as _$createScopedElement,
398
+ createScopedValue as _$createScopedValue,
399
+ memo,
400
+ useMemo as useMemo2
401
+ } from "octane/server";
402
+ var LINE_NUMBER_CLASSES_BASE = cn("before:content-[counter(line)]", "before:inline-block", "before:[counter-increment:line]", "before:w-6", "before:mr-4", "before:text-[13px]", "before:text-right", "before:text-muted-foreground/50", "before:font-mono", "before:select-none");
403
+ var parseRootStyle = (rootStyle) => {
404
+ const style = {};
405
+ for (const decl of rootStyle.split(";")) {
406
+ const idx = decl.indexOf(":");
407
+ if (idx > 0) {
408
+ const prop = decl.slice(0, idx).trim();
409
+ const val = decl.slice(idx + 1).trim();
410
+ if (prop && val) {
411
+ style[prop] = val;
412
+ }
413
+ }
414
+ }
415
+ return style;
416
+ };
417
+ var CodeBlockBody = memo(
418
+ ({
419
+ children,
420
+ result,
421
+ language,
422
+ className,
423
+ startLine,
424
+ lineNumbers = true,
425
+ ...rest
426
+ }) => {
427
+ const cn2 = useCn();
428
+ const lineClasses = useMemo2(() => cn2("block", lineNumbers && LINE_NUMBER_CLASSES_BASE), [cn2, lineNumbers]);
429
+ const preStyle = useMemo2(
430
+ () => {
431
+ const style = {};
432
+ if (result.bg) {
433
+ style["--sdm-bg"] = result.bg;
434
+ }
435
+ if (result.fg) {
436
+ style["--sdm-fg"] = result.fg;
437
+ }
438
+ if (result.rootStyle) {
439
+ Object.assign(style, parseRootStyle(result.rootStyle));
440
+ }
441
+ return style;
442
+ },
443
+ [result.bg, result.fg, result.rootStyle]
444
+ );
445
+ return _$createScopedValue(() => _$createScopedElement(
446
+ "div",
447
+ {
448
+ className: cn2(className, "overflow-x-auto rounded-md border border-border bg-background p-4 text-sm"),
449
+ "data-language": language,
450
+ "data-streamdown": "code-block-body",
451
+ ...rest
452
+ },
453
+ () => _$createScopedValue(() => _$createScopedElement(
454
+ "pre",
455
+ {
456
+ className: cn2(className, "bg-[var(--sdm-bg,inherit)]", "dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))]"),
457
+ style: preStyle
458
+ },
459
+ () => _$createScopedValue(() => _$createScopedElement(
460
+ "code",
461
+ {
462
+ className: lineNumbers ? cn2("[counter-increment:line_0] [counter-reset:line]") : void 0,
463
+ style: lineNumbers && startLine && startLine > 1 ? { counterReset: `line ${startLine - 1}` } : void 0
464
+ },
465
+ () => result.tokens.map((row, index) => _$createScopedElement("span", { className: lineClasses, key: index }, () => row.length === 0 || row.length === 1 && row[0].content === "" ? "\n" : row.map((token, tokenIndex) => {
466
+ const tokenStyle = {};
467
+ let hasBg = Boolean(token.bgColor);
468
+ if (token.color) {
469
+ tokenStyle["--sdm-c"] = token.color;
470
+ }
471
+ if (token.bgColor) {
472
+ tokenStyle["--sdm-tbg"] = token.bgColor;
473
+ }
474
+ if (token.htmlStyle) {
475
+ for (const [key, value] of Object.entries(token.htmlStyle)) {
476
+ if (key === "color") {
477
+ tokenStyle["--sdm-c"] = value;
478
+ } else if (key === "background-color") {
479
+ tokenStyle["--sdm-tbg"] = value;
480
+ hasBg = true;
481
+ } else {
482
+ tokenStyle[key] = value;
483
+ }
484
+ }
485
+ }
486
+ return _$createScopedElement(
487
+ "span",
488
+ {
489
+ className: cn2("text-[var(--sdm-c,inherit)]", "dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]", hasBg && "bg-[var(--sdm-tbg)]", hasBg && "dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),
490
+ key: tokenIndex,
491
+ style: tokenStyle,
492
+ ...token.htmlAttrs
493
+ },
494
+ () => token.content
495
+ );
496
+ })))
497
+ ))
498
+ ))
499
+ ));
500
+ },
501
+ (prevProps, nextProps) => {
502
+ return prevProps.result === nextProps.result && prevProps.language === nextProps.language && prevProps.className === nextProps.className && prevProps.startLine === nextProps.startLine && prevProps.lineNumbers === nextProps.lineNumbers;
503
+ }
504
+ );
505
+
506
+ // src/lib/code-block/container.tsrx
507
+ import {
508
+ createElement as _$createElement,
509
+ createScopedValue as _$createScopedValue2
510
+ } from "octane/server";
511
+ var CodeBlockContainer = ({ className, language, style, isIncomplete, ...props }) => {
512
+ const cn2 = useCn();
513
+ return _$createScopedValue2(() => _$createElement("div", {
514
+ className: cn2("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2", className),
515
+ "data-incomplete": isIncomplete || void 0,
516
+ "data-language": language,
517
+ "data-streamdown": "code-block",
518
+ style: {
519
+ contentVisibility: "auto",
520
+ containIntrinsicSize: "auto 200px",
521
+ ...style
522
+ },
523
+ ...props
524
+ }));
525
+ };
526
+
527
+ // src/lib/code-block/context.tsrx
528
+ import { createContext as createContext3, useContext as useContext3 } from "octane/server";
529
+ var CodeBlockContext = createContext3({ code: "" });
530
+ var useCodeBlockContext = () => useContext3(CodeBlockContext);
531
+
532
+ // src/lib/code-block/header.tsrx
533
+ import {
534
+ createScopedElement as _$createScopedElement2,
535
+ createScopedValue as _$createScopedValue3
536
+ } from "octane/server";
537
+ var CodeBlockHeader = ({ language }) => {
538
+ const cn2 = useCn();
539
+ return _$createScopedValue3(() => _$createScopedElement2(
540
+ "div",
541
+ {
542
+ className: cn2("flex h-8 items-center text-muted-foreground text-xs"),
543
+ "data-language": language,
544
+ "data-streamdown": "code-block-header"
545
+ },
546
+ () => _$createScopedValue3(() => _$createScopedElement2("span", { className: cn2("ml-1 font-mono lowercase") }, () => language))
547
+ ));
548
+ };
549
+
550
+ // src/lib/code-block/index.tsrx
551
+ var trimTrailingNewlines = (str) => {
552
+ let end = str.length;
553
+ while (end > 0 && str[end - 1] === "\n") {
554
+ end--;
555
+ }
556
+ return str.slice(0, end);
557
+ };
558
+ var HighlightedCodeBlockBody = /* @__PURE__ */ lazy(() => import("./highlighted-body-NLELYOBH.js").then((mod) => ({ default: mod.HighlightedCodeBlockBody })));
559
+ var CodeBlock = ({
560
+ code,
561
+ language,
562
+ className,
563
+ children,
564
+ isIncomplete = false,
565
+ startLine,
566
+ lineNumbers,
567
+ ...rest
568
+ }) => {
569
+ const cn2 = useCn();
570
+ const trimmedCode = useMemo3(() => trimTrailingNewlines(code), [code]);
571
+ const raw = useMemo3(
572
+ () => ({
573
+ bg: "transparent",
574
+ fg: "inherit",
575
+ tokens: trimmedCode.split("\n").map((line) => [
576
+ {
577
+ content: line,
578
+ color: "inherit",
579
+ bgColor: "transparent",
580
+ htmlStyle: {},
581
+ offset: 0
582
+ }
583
+ ])
584
+ }),
585
+ [trimmedCode]
586
+ );
587
+ return _$createScopedValue4(() => _$createScopedElement3(CodeBlockContext.Provider, { value: { code } }, () => _$createScopedValue4(() => _$createScopedElement3(CodeBlockContainer, { isIncomplete, language }, () => _$positionalChildren([
588
+ _$createScopedValue4(() => _$createElement2(CodeBlockHeader, { language })),
589
+ children ? _$createScopedValue4(() => _$createScopedElement3(
590
+ "div",
591
+ {
592
+ className: cn2("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end")
593
+ },
594
+ () => _$createScopedValue4(() => _$createScopedElement3(
595
+ "div",
596
+ {
597
+ className: cn2("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),
598
+ "data-streamdown": "code-block-actions"
599
+ },
600
+ () => children
601
+ ))
602
+ )) : null,
603
+ _$createScopedValue4(() => _$createScopedElement3(
604
+ Suspense,
605
+ {
606
+ fallback: _$createScopedValue4(() => _$createElement2(CodeBlockBody, {
607
+ className,
608
+ language,
609
+ lineNumbers,
610
+ result: raw,
611
+ startLine,
612
+ ...rest
613
+ }))
614
+ },
615
+ () => _$createScopedValue4(() => _$createElement2(HighlightedCodeBlockBody, {
616
+ className,
617
+ code: trimmedCode,
618
+ language,
619
+ lineNumbers,
620
+ raw,
621
+ startLine,
622
+ ...rest
623
+ }))
624
+ ))
625
+ ])))));
626
+ };
627
+
628
+ // src/lib/code-block/copy-button.tsrx
629
+ import {
630
+ createElement as _$createElement4,
631
+ createScopedElement as _$createScopedElement5,
632
+ createScopedValue as _$createScopedValue7,
633
+ useContext as useContext6,
634
+ useEffect as useEffect2,
635
+ useRef as useRef3,
636
+ useState as useState2
637
+ } from "octane/server";
638
+
639
+ // src/lib/icon-context.tsrx
640
+ import {
641
+ createContext as createContext4,
642
+ createScopedElement as _$createScopedElement4,
643
+ createScopedValue as _$createScopedValue6,
644
+ useContext as useContext4,
645
+ useRef as useRef2
646
+ } from "octane/server";
647
+
648
+ // src/lib/icons.tsrx
649
+ import {
650
+ createElement as _$createElement3,
651
+ createScopedValue as _$createScopedValue5
652
+ } from "octane/server";
653
+ var CheckIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
654
+ "svg",
655
+ {
656
+ color: "currentColor",
657
+ height: size,
658
+ strokeLinejoin: "round",
659
+ viewBox: "0 0 16 16",
660
+ width: size,
661
+ ...props
662
+ },
663
+ _$createElement3("path", {
664
+ clipRule: "evenodd",
665
+ d: "M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",
666
+ fill: "currentColor",
667
+ fillRule: "evenodd"
668
+ })
669
+ ));
670
+ var CopyIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
671
+ "svg",
672
+ {
673
+ color: "currentColor",
674
+ height: size,
675
+ strokeLinejoin: "round",
676
+ viewBox: "0 0 16 16",
677
+ width: size,
678
+ ...props
679
+ },
680
+ _$createElement3("path", {
681
+ clipRule: "evenodd",
682
+ d: "M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",
683
+ fill: "currentColor",
684
+ fillRule: "evenodd"
685
+ })
686
+ ));
687
+ var DownloadIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
688
+ "svg",
689
+ {
690
+ color: "currentColor",
691
+ height: size,
692
+ strokeLinejoin: "round",
693
+ viewBox: "0 0 16 16",
694
+ width: size,
695
+ ...props
696
+ },
697
+ _$createElement3("path", {
698
+ clipRule: "evenodd",
699
+ d: "M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",
700
+ fill: "currentColor",
701
+ fillRule: "evenodd"
702
+ })
703
+ ));
704
+ var Loader2Icon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
705
+ "svg",
706
+ {
707
+ color: "currentColor",
708
+ height: size,
709
+ strokeLinejoin: "round",
710
+ viewBox: "0 0 16 16",
711
+ width: size,
712
+ ...props
713
+ },
714
+ _$createElement3("path", { d: "M8 0V4", stroke: "currentColor", strokeWidth: "1.5" }),
715
+ _$createElement3("path", {
716
+ d: "M8 16V12",
717
+ opacity: "0.5",
718
+ stroke: "currentColor",
719
+ strokeWidth: "1.5"
720
+ }),
721
+ _$createElement3("path", {
722
+ d: "M3.29773 1.52783L5.64887 4.7639",
723
+ opacity: "0.9",
724
+ stroke: "currentColor",
725
+ strokeWidth: "1.5"
726
+ }),
727
+ _$createElement3("path", {
728
+ d: "M12.7023 1.52783L10.3511 4.7639",
729
+ opacity: "0.1",
730
+ stroke: "currentColor",
731
+ strokeWidth: "1.5"
732
+ }),
733
+ _$createElement3("path", {
734
+ d: "M12.7023 14.472L10.3511 11.236",
735
+ opacity: "0.4",
736
+ stroke: "currentColor",
737
+ strokeWidth: "1.5"
738
+ }),
739
+ _$createElement3("path", {
740
+ d: "M3.29773 14.472L5.64887 11.236",
741
+ opacity: "0.6",
742
+ stroke: "currentColor",
743
+ strokeWidth: "1.5"
744
+ }),
745
+ _$createElement3("path", {
746
+ d: "M15.6085 5.52783L11.8043 6.7639",
747
+ opacity: "0.2",
748
+ stroke: "currentColor",
749
+ strokeWidth: "1.5"
750
+ }),
751
+ _$createElement3("path", {
752
+ d: "M0.391602 10.472L4.19583 9.23598",
753
+ opacity: "0.7",
754
+ stroke: "currentColor",
755
+ strokeWidth: "1.5"
756
+ }),
757
+ _$createElement3("path", {
758
+ d: "M15.6085 10.4722L11.8043 9.2361",
759
+ opacity: "0.3",
760
+ stroke: "currentColor",
761
+ strokeWidth: "1.5"
762
+ }),
763
+ _$createElement3("path", {
764
+ d: "M0.391602 5.52783L4.19583 6.7639",
765
+ opacity: "0.8",
766
+ stroke: "currentColor",
767
+ strokeWidth: "1.5"
768
+ })
769
+ ));
770
+ var Maximize2Icon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
771
+ "svg",
772
+ {
773
+ color: "currentColor",
774
+ height: size,
775
+ strokeLinejoin: "round",
776
+ viewBox: "0 0 16 16",
777
+ width: size,
778
+ ...props
779
+ },
780
+ _$createElement3("path", {
781
+ clipRule: "evenodd",
782
+ d: "M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",
783
+ fill: "currentColor",
784
+ fillRule: "evenodd"
785
+ })
786
+ ));
787
+ var RotateCcwIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
788
+ "svg",
789
+ {
790
+ color: "currentColor",
791
+ height: size,
792
+ strokeLinejoin: "round",
793
+ viewBox: "0 0 16 16",
794
+ width: size,
795
+ ...props
796
+ },
797
+ _$createElement3("path", {
798
+ clipRule: "evenodd",
799
+ d: "M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",
800
+ fill: "currentColor",
801
+ fillRule: "evenodd"
802
+ })
803
+ ));
804
+ var XIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
805
+ "svg",
806
+ {
807
+ color: "currentColor",
808
+ height: size,
809
+ strokeLinejoin: "round",
810
+ viewBox: "0 0 16 16",
811
+ width: size,
812
+ ...props
813
+ },
814
+ _$createElement3("path", {
815
+ clipRule: "evenodd",
816
+ d: "M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",
817
+ fill: "currentColor",
818
+ fillRule: "evenodd"
819
+ })
820
+ ));
821
+ var ExternalLinkIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
822
+ "svg",
823
+ {
824
+ color: "currentColor",
825
+ height: size,
826
+ strokeLinejoin: "round",
827
+ viewBox: "0 0 16 16",
828
+ width: size,
829
+ ...props
830
+ },
831
+ _$createElement3("path", {
832
+ clipRule: "evenodd",
833
+ d: "M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",
834
+ fill: "currentColor",
835
+ fillRule: "evenodd"
836
+ })
837
+ ));
838
+ var ZoomInIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
839
+ "svg",
840
+ {
841
+ color: "currentColor",
842
+ height: size,
843
+ strokeLinejoin: "round",
844
+ viewBox: "0 0 16 16",
845
+ width: size,
846
+ ...props
847
+ },
848
+ _$createElement3("path", {
849
+ clipRule: "evenodd",
850
+ d: "M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",
851
+ fill: "currentColor",
852
+ fillRule: "evenodd"
853
+ })
854
+ ));
855
+ var ZoomOutIcon = ({ size = 16, ...props }) => _$createScopedValue5(() => _$createElement3(
856
+ "svg",
857
+ {
858
+ color: "currentColor",
859
+ height: size,
860
+ strokeLinejoin: "round",
861
+ viewBox: "0 0 16 16",
862
+ width: size,
863
+ ...props
864
+ },
865
+ _$createElement3("path", {
866
+ clipRule: "evenodd",
867
+ d: "M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",
868
+ fill: "currentColor",
869
+ fillRule: "evenodd"
870
+ })
871
+ ));
872
+
873
+ // src/lib/icon-context.tsrx
874
+ var defaultIcons = {
875
+ CheckIcon,
876
+ CopyIcon,
877
+ DownloadIcon,
878
+ ExternalLinkIcon,
879
+ Loader2Icon,
880
+ Maximize2Icon,
881
+ RotateCcwIcon,
882
+ XIcon,
883
+ ZoomInIcon,
884
+ ZoomOutIcon
885
+ };
886
+ var IconContext = createContext4(defaultIcons);
887
+ var shallowEqual = (a, b) => {
888
+ if (a === b) {
889
+ return true;
890
+ }
891
+ if (!(a && b)) {
892
+ return a === b;
893
+ }
894
+ const keysA = Object.keys(a);
895
+ const keysB = Object.keys(b);
896
+ if (keysA.length !== keysB.length) {
897
+ return false;
898
+ }
899
+ return keysA.every((key) => a[key] === b[key]);
900
+ };
901
+ var IconProvider = ({ icons, children }) => {
902
+ const prevIconsRef = useRef2(icons);
903
+ const prevValueRef = useRef2(icons ? { ...defaultIcons, ...icons } : defaultIcons);
904
+ if (!shallowEqual(prevIconsRef.current, icons)) {
905
+ prevIconsRef.current = icons;
906
+ prevValueRef.current = icons ? { ...defaultIcons, ...icons } : defaultIcons;
907
+ }
908
+ const value = prevValueRef.current;
909
+ return _$createScopedValue6(() => _$createScopedElement4(IconContext.Provider, { value }, () => children));
910
+ };
911
+ var useIcons = () => useContext4(IconContext);
912
+
913
+ // src/lib/translations-context.tsrx
914
+ import { createContext as createContext5, useContext as useContext5 } from "octane/server";
915
+ var defaultTranslations = {
916
+ copyCode: "Copy Code",
917
+ downloadFile: "Download file",
918
+ downloadDiagram: "Download diagram",
919
+ downloadDiagramAsSvg: "Download diagram as SVG",
920
+ downloadDiagramAsPng: "Download diagram as PNG",
921
+ downloadDiagramAsMmd: "Download diagram as MMD",
922
+ viewFullscreen: "View fullscreen",
923
+ exitFullscreen: "Exit fullscreen",
924
+ mermaidFormatSvg: "SVG",
925
+ mermaidFormatPng: "PNG",
926
+ mermaidFormatMmd: "MMD",
927
+ copyTable: "Copy table",
928
+ copyTableAsMarkdown: "Copy table as Markdown",
929
+ copyTableAsCsv: "Copy table as CSV",
930
+ copyTableAsTsv: "Copy table as TSV",
931
+ downloadTable: "Download table",
932
+ downloadTableAsCsv: "Download table as CSV",
933
+ downloadTableAsMarkdown: "Download table as Markdown",
934
+ tableFormatMarkdown: "Markdown",
935
+ tableFormatCsv: "CSV",
936
+ tableFormatTsv: "TSV",
937
+ imageNotAvailable: "Image not available",
938
+ downloadImage: "Download image",
939
+ openExternalLink: "Open external link?",
940
+ externalLinkWarning: "You're about to visit an external website.",
941
+ close: "Close",
942
+ copyLink: "Copy link",
943
+ copied: "Copied",
944
+ openLink: "Open link"
945
+ };
946
+ var TranslationsContext = createContext5(defaultTranslations);
947
+ var useTranslations = () => useContext5(TranslationsContext);
948
+
949
+ // src/lib/code-block/copy-button.tsrx
950
+ var CodeBlockCopyButton = ({
951
+ onCopy,
952
+ onError,
953
+ timeout = 2e3,
954
+ children,
955
+ className,
956
+ code: propCode,
957
+ ...props
958
+ }) => {
959
+ const cn2 = useCn();
960
+ const [isCopied, setIsCopied] = useState2(false);
961
+ const timeoutRef = useRef3(0);
962
+ const { code: contextCode } = useCodeBlockContext();
963
+ const { isAnimating } = useContext6(StreamdownContext);
964
+ const t = useTranslations();
965
+ const code = propCode ?? contextCode;
966
+ const copyToClipboard = async () => {
967
+ if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
968
+ onError?.(new Error("Clipboard API not available"));
969
+ return;
970
+ }
971
+ try {
972
+ if (!isCopied) {
973
+ await navigator.clipboard.writeText(code);
974
+ setIsCopied(true);
975
+ onCopy?.();
976
+ timeoutRef.current = window.setTimeout(() => setIsCopied(false), timeout);
977
+ }
978
+ } catch (error) {
979
+ onError?.(error);
980
+ }
981
+ };
982
+ useEffect2(
983
+ () => () => {
984
+ window.clearTimeout(timeoutRef.current);
985
+ },
986
+ []
987
+ );
988
+ const icons = useIcons();
989
+ const Icon = isCopied ? icons.CheckIcon : icons.CopyIcon;
990
+ return _$createScopedValue7(() => _$createScopedElement5(
991
+ "button",
992
+ {
993
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
994
+ "data-streamdown": "code-block-copy-button",
995
+ disabled: isAnimating,
996
+ onClick: copyToClipboard,
997
+ title: t.copyCode,
998
+ type: "button",
999
+ ...props
1000
+ },
1001
+ () => children ?? _$createElement4(Icon, { size: 14 })
1002
+ ));
1003
+ };
1004
+
1005
+ // src/lib/code-block/download-button.tsrx
1006
+ import {
1007
+ createElement as _$createElement5,
1008
+ createScopedElement as _$createScopedElement6,
1009
+ createScopedValue as _$createScopedValue8,
1010
+ useContext as useContext7
1011
+ } from "octane/server";
1012
+ var languageExtensionMap = {
1013
+ "1c": "1c",
1014
+ "1c-query": "1cq",
1015
+ abap: "abap",
1016
+ "actionscript-3": "as",
1017
+ ada: "ada",
1018
+ adoc: "adoc",
1019
+ "angular-html": "html",
1020
+ "angular-ts": "ts",
1021
+ apache: "conf",
1022
+ apex: "cls",
1023
+ apl: "apl",
1024
+ applescript: "applescript",
1025
+ ara: "ara",
1026
+ asciidoc: "adoc",
1027
+ asm: "asm",
1028
+ astro: "astro",
1029
+ awk: "awk",
1030
+ ballerina: "bal",
1031
+ bash: "sh",
1032
+ bat: "bat",
1033
+ batch: "bat",
1034
+ be: "be",
1035
+ beancount: "beancount",
1036
+ berry: "berry",
1037
+ bibtex: "bib",
1038
+ bicep: "bicep",
1039
+ blade: "blade.php",
1040
+ bsl: "bsl",
1041
+ c: "c",
1042
+ "c#": "cs",
1043
+ "c++": "cpp",
1044
+ cadence: "cdc",
1045
+ cairo: "cairo",
1046
+ cdc: "cdc",
1047
+ clarity: "clar",
1048
+ clj: "clj",
1049
+ clojure: "clj",
1050
+ "closure-templates": "soy",
1051
+ cmake: "cmake",
1052
+ cmd: "cmd",
1053
+ cobol: "cob",
1054
+ codeowners: "CODEOWNERS",
1055
+ codeql: "ql",
1056
+ coffee: "coffee",
1057
+ coffeescript: "coffee",
1058
+ "common-lisp": "lisp",
1059
+ console: "sh",
1060
+ coq: "v",
1061
+ cpp: "cpp",
1062
+ cql: "cql",
1063
+ crystal: "cr",
1064
+ cs: "cs",
1065
+ csharp: "cs",
1066
+ css: "css",
1067
+ csv: "csv",
1068
+ cue: "cue",
1069
+ cypher: "cql",
1070
+ d: "d",
1071
+ dart: "dart",
1072
+ dax: "dax",
1073
+ desktop: "desktop",
1074
+ diff: "diff",
1075
+ docker: "dockerfile",
1076
+ dockerfile: "dockerfile",
1077
+ dotenv: "env",
1078
+ "dream-maker": "dm",
1079
+ edge: "edge",
1080
+ elisp: "el",
1081
+ elixir: "ex",
1082
+ elm: "elm",
1083
+ "emacs-lisp": "el",
1084
+ erb: "erb",
1085
+ erl: "erl",
1086
+ erlang: "erl",
1087
+ f: "f",
1088
+ "f#": "fs",
1089
+ f03: "f03",
1090
+ f08: "f08",
1091
+ f18: "f18",
1092
+ f77: "f77",
1093
+ f90: "f90",
1094
+ f95: "f95",
1095
+ fennel: "fnl",
1096
+ fish: "fish",
1097
+ fluent: "ftl",
1098
+ for: "for",
1099
+ "fortran-fixed-form": "f",
1100
+ "fortran-free-form": "f90",
1101
+ fs: "fs",
1102
+ fsharp: "fs",
1103
+ fsl: "fsl",
1104
+ ftl: "ftl",
1105
+ gdresource: "tres",
1106
+ gdscript: "gd",
1107
+ gdshader: "gdshader",
1108
+ genie: "gs",
1109
+ gherkin: "feature",
1110
+ "git-commit": "gitcommit",
1111
+ "git-rebase": "gitrebase",
1112
+ gjs: "js",
1113
+ gleam: "gleam",
1114
+ "glimmer-js": "js",
1115
+ "glimmer-ts": "ts",
1116
+ glsl: "glsl",
1117
+ gnuplot: "plt",
1118
+ go: "go",
1119
+ gql: "gql",
1120
+ graphql: "graphql",
1121
+ groovy: "groovy",
1122
+ gts: "gts",
1123
+ hack: "hack",
1124
+ haml: "haml",
1125
+ handlebars: "hbs",
1126
+ haskell: "hs",
1127
+ haxe: "hx",
1128
+ hbs: "hbs",
1129
+ hcl: "hcl",
1130
+ hjson: "hjson",
1131
+ hlsl: "hlsl",
1132
+ hs: "hs",
1133
+ html: "html",
1134
+ "html-derivative": "html",
1135
+ http: "http",
1136
+ hxml: "hxml",
1137
+ hy: "hy",
1138
+ imba: "imba",
1139
+ ini: "ini",
1140
+ jade: "jade",
1141
+ java: "java",
1142
+ javascript: "js",
1143
+ jinja: "jinja",
1144
+ jison: "jison",
1145
+ jl: "jl",
1146
+ js: "js",
1147
+ json: "json",
1148
+ json5: "json5",
1149
+ jsonc: "jsonc",
1150
+ jsonl: "jsonl",
1151
+ jsonnet: "jsonnet",
1152
+ jssm: "jssm",
1153
+ jsx: "jsx",
1154
+ julia: "jl",
1155
+ kotlin: "kt",
1156
+ kql: "kql",
1157
+ kt: "kt",
1158
+ kts: "kts",
1159
+ kusto: "kql",
1160
+ latex: "tex",
1161
+ lean: "lean",
1162
+ lean4: "lean",
1163
+ less: "less",
1164
+ liquid: "liquid",
1165
+ lisp: "lisp",
1166
+ lit: "lit",
1167
+ llvm: "ll",
1168
+ log: "log",
1169
+ logo: "logo",
1170
+ lua: "lua",
1171
+ luau: "luau",
1172
+ make: "mak",
1173
+ makefile: "mak",
1174
+ markdown: "md",
1175
+ marko: "marko",
1176
+ matlab: "m",
1177
+ md: "md",
1178
+ mdc: "mdc",
1179
+ mdx: "mdx",
1180
+ mediawiki: "wiki",
1181
+ mermaid: "mmd",
1182
+ mips: "s",
1183
+ mipsasm: "s",
1184
+ mmd: "mmd",
1185
+ mojo: "mojo",
1186
+ move: "move",
1187
+ nar: "nar",
1188
+ narrat: "narrat",
1189
+ nextflow: "nf",
1190
+ nf: "nf",
1191
+ nginx: "conf",
1192
+ nim: "nim",
1193
+ nix: "nix",
1194
+ nu: "nu",
1195
+ nushell: "nu",
1196
+ objc: "m",
1197
+ "objective-c": "m",
1198
+ "objective-cpp": "mm",
1199
+ ocaml: "ml",
1200
+ pascal: "pas",
1201
+ perl: "pl",
1202
+ perl6: "p6",
1203
+ php: "php",
1204
+ plsql: "pls",
1205
+ po: "po",
1206
+ polar: "polar",
1207
+ postcss: "pcss",
1208
+ pot: "pot",
1209
+ potx: "potx",
1210
+ powerquery: "pq",
1211
+ powershell: "ps1",
1212
+ prisma: "prisma",
1213
+ prolog: "pl",
1214
+ properties: "properties",
1215
+ proto: "proto",
1216
+ protobuf: "proto",
1217
+ ps: "ps",
1218
+ ps1: "ps1",
1219
+ pug: "pug",
1220
+ puppet: "pp",
1221
+ purescript: "purs",
1222
+ py: "py",
1223
+ python: "py",
1224
+ ql: "ql",
1225
+ qml: "qml",
1226
+ qmldir: "qmldir",
1227
+ qss: "qss",
1228
+ r: "r",
1229
+ racket: "rkt",
1230
+ raku: "raku",
1231
+ razor: "cshtml",
1232
+ rb: "rb",
1233
+ reg: "reg",
1234
+ regex: "regex",
1235
+ regexp: "regexp",
1236
+ rel: "rel",
1237
+ riscv: "s",
1238
+ rs: "rs",
1239
+ rst: "rst",
1240
+ ruby: "rb",
1241
+ rust: "rs",
1242
+ sas: "sas",
1243
+ sass: "sass",
1244
+ scala: "scala",
1245
+ scheme: "scm",
1246
+ scss: "scss",
1247
+ sdbl: "sdbl",
1248
+ sh: "sh",
1249
+ shader: "shader",
1250
+ shaderlab: "shader",
1251
+ shell: "sh",
1252
+ shellscript: "sh",
1253
+ shellsession: "sh",
1254
+ smalltalk: "st",
1255
+ solidity: "sol",
1256
+ soy: "soy",
1257
+ sparql: "rq",
1258
+ spl: "spl",
1259
+ splunk: "spl",
1260
+ sql: "sql",
1261
+ "ssh-config": "config",
1262
+ stata: "do",
1263
+ styl: "styl",
1264
+ stylus: "styl",
1265
+ svelte: "svelte",
1266
+ swift: "swift",
1267
+ "system-verilog": "sv",
1268
+ systemd: "service",
1269
+ talon: "talon",
1270
+ talonscript: "talon",
1271
+ tasl: "tasl",
1272
+ tcl: "tcl",
1273
+ templ: "templ",
1274
+ terraform: "tf",
1275
+ tex: "tex",
1276
+ tf: "tf",
1277
+ tfvars: "tfvars",
1278
+ toml: "toml",
1279
+ ts: "ts",
1280
+ "ts-tags": "ts",
1281
+ tsp: "tsp",
1282
+ tsv: "tsv",
1283
+ tsx: "tsx",
1284
+ turtle: "ttl",
1285
+ twig: "twig",
1286
+ typ: "typ",
1287
+ typescript: "ts",
1288
+ typespec: "tsp",
1289
+ typst: "typ",
1290
+ v: "v",
1291
+ vala: "vala",
1292
+ vb: "vb",
1293
+ verilog: "v",
1294
+ vhdl: "vhdl",
1295
+ vim: "vim",
1296
+ viml: "vim",
1297
+ vimscript: "vim",
1298
+ vue: "vue",
1299
+ "vue-html": "html",
1300
+ "vue-vine": "vine",
1301
+ vy: "vy",
1302
+ vyper: "vy",
1303
+ wasm: "wasm",
1304
+ wenyan: "wy",
1305
+ wgsl: "wgsl",
1306
+ wiki: "wiki",
1307
+ wikitext: "wiki",
1308
+ wit: "wit",
1309
+ wl: "wl",
1310
+ wolfram: "wl",
1311
+ xml: "xml",
1312
+ xsl: "xsl",
1313
+ yaml: "yaml",
1314
+ yml: "yml",
1315
+ zenscript: "zs",
1316
+ zig: "zig",
1317
+ zsh: "zsh",
1318
+ \u6587\u8A00: "wy"
1319
+ };
1320
+ var CodeBlockDownloadButton = ({
1321
+ onDownload,
1322
+ onError,
1323
+ language,
1324
+ children,
1325
+ className,
1326
+ code: propCode,
1327
+ ...props
1328
+ }) => {
1329
+ const cn2 = useCn();
1330
+ const { code: contextCode } = useCodeBlockContext();
1331
+ const { isAnimating } = useContext7(StreamdownContext);
1332
+ const t = useTranslations();
1333
+ const icons = useIcons();
1334
+ const code = propCode ?? contextCode;
1335
+ const extension = language && language in languageExtensionMap ? languageExtensionMap[language] : "txt";
1336
+ const filename = `file.${extension}`;
1337
+ const mimeType = "text/plain";
1338
+ const downloadCode = () => {
1339
+ try {
1340
+ save(filename, code, mimeType);
1341
+ onDownload?.();
1342
+ } catch (error) {
1343
+ onError?.(error);
1344
+ }
1345
+ };
1346
+ return _$createScopedValue8(() => _$createScopedElement6(
1347
+ "button",
1348
+ {
1349
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
1350
+ "data-streamdown": "code-block-download-button",
1351
+ disabled: isAnimating,
1352
+ onClick: downloadCode,
1353
+ title: t.downloadFile,
1354
+ type: "button",
1355
+ ...props
1356
+ },
1357
+ () => children ?? _$createScopedValue8(() => _$createElement5(icons.DownloadIcon, { size: 14 }))
1358
+ ));
1359
+ };
1360
+
1361
+ // src/lib/code-block/skeleton.tsrx
1362
+ import {
1363
+ createElement as _$createElement6,
1364
+ createScopedElement as _$createScopedElement7,
1365
+ createScopedValue as _$createScopedValue9,
1366
+ positionalChildren as _$positionalChildren2
1367
+ } from "octane/server";
1368
+ var CodeBlockSkeleton = () => {
1369
+ const { Loader2Icon: Loader2Icon2 } = useIcons();
1370
+ const cn2 = useCn();
1371
+ return _$createScopedValue9(() => _$createScopedElement7(
1372
+ "div",
1373
+ {
1374
+ className: cn2("w-full divide-y divide-border overflow-hidden rounded-xl border border-border")
1375
+ },
1376
+ () => _$positionalChildren2([
1377
+ _$createScopedValue9(() => _$createElement6("div", { className: cn2("h-[46px] w-full bg-muted/80") })),
1378
+ _$createScopedValue9(() => _$createScopedElement7("div", { className: cn2("flex w-full items-center justify-center p-4") }, () => _$createScopedValue9(() => _$createElement6(Loader2Icon2, { className: cn2("size-4 animate-spin") }))))
1379
+ ])
1380
+ ));
1381
+ };
1382
+
1383
+ // src/lib/image.tsrx
1384
+ import {
1385
+ createElement,
1386
+ createElement as _$createElement7,
1387
+ createScopedElement as _$createScopedElement8,
1388
+ createScopedValue as _$createScopedValue10,
1389
+ positionalChildren as _$positionalChildren3,
1390
+ useCallback,
1391
+ useEffect as useEffect3,
1392
+ useRef as useRef4,
1393
+ useState as useState3
1394
+ } from "octane/server";
1395
+ var fileExtensionPattern = /\.[^/.]+$/;
1396
+ var ImageComponent = ({
1397
+ node,
1398
+ className,
1399
+ src,
1400
+ alt,
1401
+ onLoad: onLoadProp,
1402
+ onError: onErrorProp,
1403
+ ...props
1404
+ }) => {
1405
+ const { DownloadIcon: DownloadIcon2 } = useIcons();
1406
+ const cn2 = useCn();
1407
+ const imgRef = useRef4(null);
1408
+ const [imageState, setImageState] = useState3({ error: false, loaded: false, source: src });
1409
+ const t = useTranslations();
1410
+ const imageLoaded = imageState.source === src && imageState.loaded;
1411
+ const imageError = imageState.source === src && imageState.error;
1412
+ const hasExplicitDimensions = props.width != null || props.height != null;
1413
+ const showDownload = (imageLoaded || hasExplicitDimensions) && !imageError;
1414
+ const showFallback = imageError && !hasExplicitDimensions;
1415
+ useEffect3(
1416
+ () => {
1417
+ setImageState((state) => state.source === src ? state : { error: false, loaded: false, source: src });
1418
+ const img = imgRef.current;
1419
+ if (img?.complete) {
1420
+ const loaded = img.naturalWidth > 0;
1421
+ setImageState({ error: !loaded, loaded, source: src });
1422
+ }
1423
+ },
1424
+ [src]
1425
+ );
1426
+ const handleLoad = useCallback(
1427
+ (event) => {
1428
+ setImageState({ error: false, loaded: true, source: src });
1429
+ onLoadProp?.(event);
1430
+ },
1431
+ [onLoadProp, src]
1432
+ );
1433
+ const handleError = useCallback(
1434
+ (event) => {
1435
+ setImageState({ error: true, loaded: false, source: src });
1436
+ onErrorProp?.(event);
1437
+ },
1438
+ [onErrorProp, src]
1439
+ );
1440
+ const downloadImage = async () => {
1441
+ if (!src) {
1442
+ return;
1443
+ }
1444
+ try {
1445
+ const response = await fetch(src);
1446
+ const blob = await response.blob();
1447
+ const urlPath = new URL(src, window.location.origin).pathname;
1448
+ const originalFilename = urlPath.split("/").pop() || "";
1449
+ const extension = originalFilename.split(".").pop();
1450
+ const hasExtension = originalFilename.includes(".") && extension !== void 0 && extension.length <= 4;
1451
+ let filename = "";
1452
+ if (hasExtension) {
1453
+ filename = originalFilename;
1454
+ } else {
1455
+ const mimeType = blob.type;
1456
+ let fileExtension = "png";
1457
+ if (mimeType.includes("jpeg") || mimeType.includes("jpg")) {
1458
+ fileExtension = "jpg";
1459
+ } else if (mimeType.includes("png")) {
1460
+ fileExtension = "png";
1461
+ } else if (mimeType.includes("svg")) {
1462
+ fileExtension = "svg";
1463
+ } else if (mimeType.includes("gif")) {
1464
+ fileExtension = "gif";
1465
+ } else if (mimeType.includes("webp")) {
1466
+ fileExtension = "webp";
1467
+ }
1468
+ const baseName = alt || originalFilename || "image";
1469
+ filename = `${baseName.replace(fileExtensionPattern, "")}.${fileExtension}`;
1470
+ }
1471
+ save(filename, blob, blob.type);
1472
+ } catch {
1473
+ window.open(src, "_blank");
1474
+ }
1475
+ };
1476
+ if (!src) {
1477
+ return null;
1478
+ }
1479
+ const image = createElement("img", {
1480
+ ...props,
1481
+ alt,
1482
+ className: cn2("max-w-full rounded-lg", showFallback && "hidden", className),
1483
+ "data-streamdown": "image",
1484
+ onError: handleError,
1485
+ onLoad: handleLoad,
1486
+ ref: imgRef,
1487
+ src
1488
+ });
1489
+ return _$createScopedValue10(() => _$createScopedElement8(
1490
+ "div",
1491
+ {
1492
+ className: cn2("group relative my-4 inline-block"),
1493
+ "data-streamdown": "image-wrapper"
1494
+ },
1495
+ () => _$positionalChildren3([
1496
+ image,
1497
+ showFallback && _$createScopedValue10(() => _$createScopedElement8(
1498
+ "span",
1499
+ {
1500
+ className: cn2("text-muted-foreground text-xs italic"),
1501
+ "data-streamdown": "image-fallback"
1502
+ },
1503
+ () => t.imageNotAvailable
1504
+ )),
1505
+ _$createScopedValue10(() => _$createElement7("div", {
1506
+ className: cn2("pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block")
1507
+ })),
1508
+ showDownload && _$createScopedValue10(() => _$createScopedElement8(
1509
+ "button",
1510
+ {
1511
+ className: cn2("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background", "opacity-0 group-hover:opacity-100"),
1512
+ onClick: downloadImage,
1513
+ title: t.downloadImage,
1514
+ type: "button"
1515
+ },
1516
+ () => _$createElement7(DownloadIcon2, { size: 14 })
1517
+ ))
1518
+ ])
1519
+ ));
1520
+ };
1521
+
1522
+ // src/lib/link-modal.tsrx
1523
+ import {
1524
+ Fragment as _$Fragment,
1525
+ createElement as _$createElement8,
1526
+ createScopedElement as _$createScopedElement9,
1527
+ createScopedValue as _$createScopedValue11,
1528
+ positionalChildren as _$positionalChildren4,
1529
+ useCallback as useCallback2,
1530
+ useEffect as useEffect4,
1531
+ useState as useState4
1532
+ } from "octane/server";
1533
+
1534
+ // src/lib/scroll-lock.ts
1535
+ var activeCount = 0;
1536
+ var lockBodyScroll = () => {
1537
+ activeCount += 1;
1538
+ if (activeCount === 1) {
1539
+ document.body.style.overflow = "hidden";
1540
+ }
1541
+ };
1542
+ var unlockBodyScroll = () => {
1543
+ activeCount = Math.max(0, activeCount - 1);
1544
+ if (activeCount === 0) {
1545
+ document.body.style.overflow = "";
1546
+ }
1547
+ };
1548
+
1549
+ // src/lib/link-modal.tsrx
1550
+ var LinkSafetyModal = ({ url, isOpen, onClose, onConfirm }) => {
1551
+ const { CheckIcon: CheckIcon2, CopyIcon: CopyIcon2, ExternalLinkIcon: ExternalLinkIcon2, XIcon: XIcon2 } = useIcons();
1552
+ const cn2 = useCn();
1553
+ const [copied, setCopied] = useState4(false);
1554
+ const t = useTranslations();
1555
+ const handleCopy = useCallback2(
1556
+ async () => {
1557
+ try {
1558
+ await navigator.clipboard.writeText(url);
1559
+ setCopied(true);
1560
+ setTimeout(() => setCopied(false), 2e3);
1561
+ } catch {
1562
+ }
1563
+ },
1564
+ [url]
1565
+ );
1566
+ const handleConfirm = useCallback2(
1567
+ () => {
1568
+ onConfirm();
1569
+ onClose();
1570
+ },
1571
+ [onConfirm, onClose]
1572
+ );
1573
+ useEffect4(
1574
+ () => {
1575
+ if (isOpen) {
1576
+ lockBodyScroll();
1577
+ const handleEsc = (e) => {
1578
+ if (e.key === "Escape") {
1579
+ onClose();
1580
+ }
1581
+ };
1582
+ document.addEventListener("keydown", handleEsc);
1583
+ return () => {
1584
+ document.removeEventListener("keydown", handleEsc);
1585
+ unlockBodyScroll();
1586
+ };
1587
+ }
1588
+ },
1589
+ [isOpen, onClose]
1590
+ );
1591
+ if (!isOpen) {
1592
+ return null;
1593
+ }
1594
+ return _$createScopedValue11(() => _$createScopedElement9(
1595
+ "div",
1596
+ {
1597
+ className: cn2("fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm"),
1598
+ "data-streamdown": "link-safety-modal",
1599
+ onClick: onClose,
1600
+ onKeyDown: (e) => {
1601
+ if (e.key === "Escape") {
1602
+ onClose();
1603
+ }
1604
+ },
1605
+ role: "button",
1606
+ tabIndex: 0
1607
+ },
1608
+ () => _$createScopedValue11(() => _$createScopedElement9(
1609
+ "div",
1610
+ {
1611
+ className: cn2("relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg"),
1612
+ onClick: (e) => e.stopPropagation(),
1613
+ onKeyDown: (e) => e.stopPropagation(),
1614
+ role: "presentation"
1615
+ },
1616
+ () => _$positionalChildren4([
1617
+ _$createScopedValue11(() => _$createScopedElement9(
1618
+ "button",
1619
+ {
1620
+ className: cn2("absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),
1621
+ onClick: onClose,
1622
+ title: t.close,
1623
+ type: "button"
1624
+ },
1625
+ () => _$createElement8(XIcon2, { size: 16 })
1626
+ )),
1627
+ _$createScopedValue11(() => _$createScopedElement9("div", { className: cn2("flex flex-col gap-2") }, () => _$positionalChildren4([
1628
+ _$createScopedValue11(() => _$createScopedElement9(
1629
+ "div",
1630
+ {
1631
+ className: cn2("flex items-center gap-2 font-semibold text-lg")
1632
+ },
1633
+ () => _$positionalChildren4([
1634
+ _$createElement8(ExternalLinkIcon2, { size: 20 }),
1635
+ _$createScopedElement9("span", {}, () => t.openExternalLink)
1636
+ ])
1637
+ )),
1638
+ _$createScopedValue11(() => _$createScopedElement9("p", { className: cn2("text-muted-foreground text-sm") }, () => t.externalLinkWarning))
1639
+ ]))),
1640
+ _$createScopedValue11(() => _$createScopedElement9(
1641
+ "div",
1642
+ {
1643
+ className: cn2("break-all rounded-md bg-muted p-3 font-mono text-sm", url.length > 100 && "max-h-32 overflow-y-auto")
1644
+ },
1645
+ () => url
1646
+ )),
1647
+ _$createScopedValue11(() => _$createScopedElement9("div", { className: cn2("flex gap-2") }, () => _$positionalChildren4([
1648
+ _$createScopedValue11(() => _$createScopedElement9(
1649
+ "button",
1650
+ {
1651
+ className: cn2("flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted"),
1652
+ onClick: handleCopy,
1653
+ type: "button"
1654
+ },
1655
+ () => copied ? _$createScopedElement9(_$Fragment, {}, () => _$positionalChildren4([
1656
+ _$createElement8(CheckIcon2, { size: 14 }),
1657
+ _$createScopedElement9("span", {}, () => t.copied)
1658
+ ])) : _$createScopedElement9(_$Fragment, {}, () => _$positionalChildren4([
1659
+ _$createElement8(CopyIcon2, { size: 14 }),
1660
+ _$createScopedElement9("span", {}, () => t.copyLink)
1661
+ ]))
1662
+ )),
1663
+ _$createScopedValue11(() => _$createScopedElement9(
1664
+ "button",
1665
+ {
1666
+ className: cn2("flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90"),
1667
+ onClick: handleConfirm,
1668
+ type: "button"
1669
+ },
1670
+ () => _$positionalChildren4([
1671
+ _$createElement8(ExternalLinkIcon2, { size: 14 }),
1672
+ _$createScopedElement9("span", {}, () => t.openLink)
1673
+ ])
1674
+ ))
1675
+ ])))
1676
+ ])
1677
+ ))
1678
+ ));
1679
+ };
1680
+
1681
+ // src/lib/mermaid/download-button.tsrx
1682
+ import {
1683
+ createElement as _$createElement9,
1684
+ createScopedElement as _$createScopedElement10,
1685
+ createScopedValue as _$createScopedValue12,
1686
+ positionalChildren as _$positionalChildren5,
1687
+ useContext as useContext9,
1688
+ useEffect as useEffect5,
1689
+ useRef as useRef5,
1690
+ useState as useState5
1691
+ } from "octane/server";
1692
+
1693
+ // src/lib/plugin-context.tsrx
1694
+ import { createContext as createContext6, useContext as useContext8 } from "octane/server";
1695
+ var PluginContext = createContext6(null);
1696
+ var usePlugins = () => useContext8(PluginContext);
1697
+ var useCodePlugin = () => {
1698
+ const plugins = usePlugins();
1699
+ return plugins?.code ?? null;
1700
+ };
1701
+ var useMermaidPlugin = () => {
1702
+ const plugins = usePlugins();
1703
+ return plugins?.mermaid ?? null;
1704
+ };
1705
+ var useCustomRenderer = (language) => {
1706
+ const plugins = usePlugins();
1707
+ if (!(plugins?.renderers && language)) {
1708
+ return null;
1709
+ }
1710
+ return plugins.renderers.find((r) => Array.isArray(r.language) ? r.language.includes(language) : r.language === language) ?? null;
1711
+ };
1712
+
1713
+ // src/lib/mermaid/utils.ts
1714
+ var svgToPngBlob = (svgString, options) => {
1715
+ const scale = options?.scale ?? 5;
1716
+ return new Promise((resolve, reject) => {
1717
+ const encoded = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgString)));
1718
+ const img = new Image();
1719
+ img.crossOrigin = "anonymous";
1720
+ img.onload = () => {
1721
+ const canvas = document.createElement("canvas");
1722
+ const w = img.width * scale;
1723
+ const h = img.height * scale;
1724
+ canvas.width = w;
1725
+ canvas.height = h;
1726
+ const ctx = canvas.getContext("2d");
1727
+ if (!ctx) {
1728
+ reject(new Error("Failed to create 2D canvas context for PNG export"));
1729
+ return;
1730
+ }
1731
+ ctx.drawImage(img, 0, 0, w, h);
1732
+ canvas.toBlob((blob) => {
1733
+ if (!blob) {
1734
+ reject(new Error("Failed to create PNG blob"));
1735
+ return;
1736
+ }
1737
+ resolve(blob);
1738
+ }, "image/png");
1739
+ };
1740
+ img.onerror = () => reject(new Error("Failed to load SVG image"));
1741
+ img.src = encoded;
1742
+ });
1743
+ };
1744
+
1745
+ // src/lib/mermaid/download-button.tsrx
1746
+ var MermaidDownloadDropdown = ({ chart, children, className, onDownload, config, onError }) => {
1747
+ const cn2 = useCn();
1748
+ const [isOpen, setIsOpen] = useState5(false);
1749
+ const dropdownRef = useRef5(null);
1750
+ const { isAnimating } = useContext9(StreamdownContext);
1751
+ const icons = useIcons();
1752
+ const mermaidPlugin = useMermaidPlugin();
1753
+ const t = useTranslations();
1754
+ const downloadMermaid = async (format) => {
1755
+ try {
1756
+ if (format === "mmd") {
1757
+ const filename = "diagram.mmd";
1758
+ const mimeType = "text/plain";
1759
+ save(filename, chart, mimeType);
1760
+ setIsOpen(false);
1761
+ onDownload?.(format);
1762
+ return;
1763
+ }
1764
+ if (!mermaidPlugin) {
1765
+ onError?.(new Error("Mermaid plugin not available"));
1766
+ return;
1767
+ }
1768
+ const mermaid = mermaidPlugin.getMermaid(config);
1769
+ const chartHash = chart.split("").reduce(
1770
+ (acc, char) => {
1771
+ return (acc << 5) - acc + char.charCodeAt(0) | 0;
1772
+ },
1773
+ 0
1774
+ );
1775
+ const uniqueId = `mermaid-${Math.abs(chartHash)}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1776
+ const { svg } = await mermaid.render(uniqueId, chart);
1777
+ if (!svg) {
1778
+ onError?.(new Error("SVG not found. Please wait for the diagram to render."));
1779
+ return;
1780
+ }
1781
+ if (format === "svg") {
1782
+ const filename = "diagram.svg";
1783
+ const mimeType = "image/svg+xml";
1784
+ save(filename, svg, mimeType);
1785
+ setIsOpen(false);
1786
+ onDownload?.(format);
1787
+ return;
1788
+ }
1789
+ if (format === "png") {
1790
+ const blob = await svgToPngBlob(svg);
1791
+ save("diagram.png", blob, "image/png");
1792
+ onDownload?.(format);
1793
+ setIsOpen(false);
1794
+ return;
1795
+ }
1796
+ } catch (error) {
1797
+ onError?.(error);
1798
+ }
1799
+ };
1800
+ useEffect5(
1801
+ () => {
1802
+ const handleClickOutside = (event) => {
1803
+ const path = event.composedPath();
1804
+ if (dropdownRef.current && !path.includes(dropdownRef.current)) {
1805
+ setIsOpen(false);
1806
+ }
1807
+ };
1808
+ document.addEventListener("mousedown", handleClickOutside);
1809
+ return () => {
1810
+ document.removeEventListener("mousedown", handleClickOutside);
1811
+ };
1812
+ },
1813
+ []
1814
+ );
1815
+ return _$createScopedValue12(() => _$createScopedElement10("div", { className: cn2("relative"), ref: dropdownRef }, () => _$positionalChildren5([
1816
+ _$createScopedValue12(() => _$createScopedElement10(
1817
+ "button",
1818
+ {
1819
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
1820
+ disabled: isAnimating,
1821
+ onClick: () => setIsOpen(!isOpen),
1822
+ title: t.downloadDiagram,
1823
+ type: "button"
1824
+ },
1825
+ () => children ?? _$createScopedValue12(() => _$createElement9(icons.DownloadIcon, { size: 14 }))
1826
+ )),
1827
+ isOpen ? _$createScopedValue12(() => _$createScopedElement10(
1828
+ "div",
1829
+ {
1830
+ className: cn2("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg")
1831
+ },
1832
+ () => _$positionalChildren5([
1833
+ _$createScopedValue12(() => _$createScopedElement10(
1834
+ "button",
1835
+ {
1836
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
1837
+ onClick: () => downloadMermaid("svg"),
1838
+ title: t.downloadDiagramAsSvg,
1839
+ type: "button"
1840
+ },
1841
+ () => t.mermaidFormatSvg
1842
+ )),
1843
+ _$createScopedValue12(() => _$createScopedElement10(
1844
+ "button",
1845
+ {
1846
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
1847
+ onClick: () => downloadMermaid("png"),
1848
+ title: t.downloadDiagramAsPng,
1849
+ type: "button"
1850
+ },
1851
+ () => t.mermaidFormatPng
1852
+ )),
1853
+ _$createScopedValue12(() => _$createScopedElement10(
1854
+ "button",
1855
+ {
1856
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
1857
+ onClick: () => downloadMermaid("mmd"),
1858
+ title: t.downloadDiagramAsMmd,
1859
+ type: "button"
1860
+ },
1861
+ () => t.mermaidFormatMmd
1862
+ ))
1863
+ ])
1864
+ )) : null
1865
+ ])));
1866
+ };
1867
+
1868
+ // src/lib/mermaid/fullscreen-button.tsrx
1869
+ import {
1870
+ Fragment as _$Fragment2,
1871
+ createElement as _$createElement10,
1872
+ createPortal,
1873
+ createScopedElement as _$createScopedElement11,
1874
+ createScopedValue as _$createScopedValue13,
1875
+ positionalChildren as _$positionalChildren6,
1876
+ useContext as useContext10,
1877
+ useEffect as useEffect6,
1878
+ useState as useState6
1879
+ } from "octane/server";
1880
+ var MermaidFullscreenButton = ({ chart, config, onFullscreen, onExit, className, ...props }) => {
1881
+ const { Maximize2Icon: Maximize2Icon2, XIcon: XIcon2 } = useIcons();
1882
+ const cn2 = useCn();
1883
+ const [isFullscreen, setIsFullscreen] = useState6(false);
1884
+ const { isAnimating, controls: controlsConfig } = useContext10(StreamdownContext);
1885
+ const t = useTranslations();
1886
+ const showPanZoomControls = (() => {
1887
+ if (typeof controlsConfig === "boolean") {
1888
+ return controlsConfig;
1889
+ }
1890
+ const mermaidCtl = controlsConfig.mermaid;
1891
+ if (mermaidCtl === false) {
1892
+ return false;
1893
+ }
1894
+ if (mermaidCtl === true || mermaidCtl === void 0) {
1895
+ return true;
1896
+ }
1897
+ return mermaidCtl.panZoom !== false;
1898
+ })();
1899
+ const handleToggle = () => {
1900
+ setIsFullscreen(!isFullscreen);
1901
+ };
1902
+ useEffect6(
1903
+ () => {
1904
+ if (isFullscreen) {
1905
+ lockBodyScroll();
1906
+ const handleEsc = (e) => {
1907
+ if (e.key === "Escape") {
1908
+ setIsFullscreen(false);
1909
+ }
1910
+ };
1911
+ document.addEventListener("keydown", handleEsc);
1912
+ return () => {
1913
+ document.removeEventListener("keydown", handleEsc);
1914
+ unlockBodyScroll();
1915
+ };
1916
+ }
1917
+ },
1918
+ [isFullscreen]
1919
+ );
1920
+ useEffect6(
1921
+ () => {
1922
+ if (isFullscreen) {
1923
+ onFullscreen?.();
1924
+ } else if (onExit) {
1925
+ onExit();
1926
+ }
1927
+ },
1928
+ [isFullscreen, onFullscreen, onExit]
1929
+ );
1930
+ return _$createScopedElement11(_$Fragment2, {}, () => _$positionalChildren6([
1931
+ _$createScopedValue13(() => _$createScopedElement11(
1932
+ "button",
1933
+ {
1934
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
1935
+ disabled: isAnimating,
1936
+ onClick: handleToggle,
1937
+ title: t.viewFullscreen,
1938
+ type: "button",
1939
+ ...props
1940
+ },
1941
+ () => _$createElement10(Maximize2Icon2, { size: 14 })
1942
+ )),
1943
+ isFullscreen ? createPortal(
1944
+ _$createScopedValue13(() => _$createScopedElement11(
1945
+ "div",
1946
+ {
1947
+ className: cn2("fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"),
1948
+ onClick: handleToggle,
1949
+ onKeyDown: (e) => {
1950
+ if (e.key === "Escape") {
1951
+ handleToggle();
1952
+ }
1953
+ },
1954
+ role: "button",
1955
+ tabIndex: 0
1956
+ },
1957
+ () => _$positionalChildren6([
1958
+ _$createScopedValue13(() => _$createScopedElement11(
1959
+ "button",
1960
+ {
1961
+ className: cn2("absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),
1962
+ onClick: handleToggle,
1963
+ title: t.exitFullscreen,
1964
+ type: "button"
1965
+ },
1966
+ () => _$createElement10(XIcon2, { size: 20 })
1967
+ )),
1968
+ _$createScopedValue13(() => _$createScopedElement11(
1969
+ "div",
1970
+ {
1971
+ className: cn2("flex size-full items-center justify-center p-4"),
1972
+ onClick: (e) => e.stopPropagation(),
1973
+ onKeyDown: (e) => e.stopPropagation(),
1974
+ role: "presentation"
1975
+ },
1976
+ () => _$createScopedValue13(() => _$createElement10(Mermaid, {
1977
+ chart,
1978
+ className: cn2("size-full [&_svg]:h-auto [&_svg]:w-auto"),
1979
+ config,
1980
+ fullscreen: true,
1981
+ showControls: showPanZoomControls
1982
+ }))
1983
+ ))
1984
+ ])
1985
+ )),
1986
+ document.body
1987
+ ) : null
1988
+ ]));
1989
+ };
1990
+
1991
+ // src/lib/table/index.tsrx
1992
+ import {
1993
+ createElement as _$createElement14,
1994
+ createScopedElement as _$createScopedElement15,
1995
+ createScopedValue as _$createScopedValue17,
1996
+ positionalChildren as _$positionalChildren10
1997
+ } from "octane/server";
1998
+
1999
+ // src/lib/table/copy-dropdown.tsrx
2000
+ import {
2001
+ createElement as _$createElement11,
2002
+ createScopedElement as _$createScopedElement12,
2003
+ createScopedValue as _$createScopedValue14,
2004
+ positionalChildren as _$positionalChildren7,
2005
+ useContext as useContext11,
2006
+ useEffect as useEffect7,
2007
+ useRef as useRef6,
2008
+ useState as useState7
2009
+ } from "octane/server";
2010
+
2011
+ // src/lib/table/utils.ts
2012
+ var TABLE_CONTAINER_SELECTOR = '[data-streamdown="table-wrapper"], [data-streamdown="table-fullscreen"]';
2013
+ var findTableForControl = (control) => control?.closest(TABLE_CONTAINER_SELECTOR)?.querySelector('table[data-streamdown="table"]') ?? null;
2014
+ var extractTableDataFromElement = (tableElement) => {
2015
+ const headers = [];
2016
+ const rows = [];
2017
+ const headerCells = tableElement.querySelectorAll("thead th");
2018
+ for (const cell of headerCells) {
2019
+ headers.push(cell.textContent?.trim() || "");
2020
+ }
2021
+ const bodyRows = tableElement.querySelectorAll("tbody tr");
2022
+ for (const row of bodyRows) {
2023
+ const rowData = [];
2024
+ const cells = row.querySelectorAll("td");
2025
+ for (const cell of cells) {
2026
+ rowData.push(cell.textContent?.trim() || "");
2027
+ }
2028
+ rows.push(rowData);
2029
+ }
2030
+ return { headers, rows };
2031
+ };
2032
+ var tableDataToCSV = (data) => {
2033
+ const { headers, rows } = data;
2034
+ const escapeCSV = (value) => {
2035
+ let needsEscaping = false;
2036
+ let hasQuote = false;
2037
+ for (const char of value) {
2038
+ if (char === '"') {
2039
+ needsEscaping = true;
2040
+ hasQuote = true;
2041
+ break;
2042
+ }
2043
+ if (char === "," || char === "\n") {
2044
+ needsEscaping = true;
2045
+ }
2046
+ }
2047
+ if (!needsEscaping) {
2048
+ return value;
2049
+ }
2050
+ if (hasQuote) {
2051
+ return `"${value.replace(/"/g, '""')}"`;
2052
+ }
2053
+ return `"${value}"`;
2054
+ };
2055
+ const totalRows = headers.length > 0 ? rows.length + 1 : rows.length;
2056
+ const csvRows = new Array(totalRows);
2057
+ let rowIndex = 0;
2058
+ if (headers.length > 0) {
2059
+ csvRows[rowIndex] = headers.map(escapeCSV).join(",");
2060
+ rowIndex += 1;
2061
+ }
2062
+ for (const row of rows) {
2063
+ csvRows[rowIndex] = row.map(escapeCSV).join(",");
2064
+ rowIndex += 1;
2065
+ }
2066
+ return csvRows.join("\n");
2067
+ };
2068
+ var tableDataToTSV = (data) => {
2069
+ const { headers, rows } = data;
2070
+ const escapeTSV = (value) => {
2071
+ let needsEscaping = false;
2072
+ for (const char of value) {
2073
+ if (char === " " || char === "\n" || char === "\r") {
2074
+ needsEscaping = true;
2075
+ break;
2076
+ }
2077
+ }
2078
+ if (!needsEscaping) {
2079
+ return value;
2080
+ }
2081
+ const parts = [];
2082
+ for (const char of value) {
2083
+ if (char === " ") {
2084
+ parts.push("\\t");
2085
+ } else if (char === "\n") {
2086
+ parts.push("\\n");
2087
+ } else if (char === "\r") {
2088
+ parts.push("\\r");
2089
+ } else {
2090
+ parts.push(char);
2091
+ }
2092
+ }
2093
+ return parts.join("");
2094
+ };
2095
+ const totalRows = headers.length > 0 ? rows.length + 1 : rows.length;
2096
+ const tsvRows = new Array(totalRows);
2097
+ let rowIndex = 0;
2098
+ if (headers.length > 0) {
2099
+ tsvRows[rowIndex] = headers.map(escapeTSV).join(" ");
2100
+ rowIndex += 1;
2101
+ }
2102
+ for (const row of rows) {
2103
+ tsvRows[rowIndex] = row.map(escapeTSV).join(" ");
2104
+ rowIndex += 1;
2105
+ }
2106
+ return tsvRows.join("\n");
2107
+ };
2108
+ var escapeMarkdownTableCell = (cell) => {
2109
+ let needsEscaping = false;
2110
+ for (const char of cell) {
2111
+ if (char === "\\" || char === "|") {
2112
+ needsEscaping = true;
2113
+ break;
2114
+ }
2115
+ }
2116
+ if (!needsEscaping) {
2117
+ return cell;
2118
+ }
2119
+ const parts = [];
2120
+ for (const char of cell) {
2121
+ if (char === "\\") {
2122
+ parts.push("\\\\");
2123
+ } else if (char === "|") {
2124
+ parts.push("\\|");
2125
+ } else {
2126
+ parts.push(char);
2127
+ }
2128
+ }
2129
+ return parts.join("");
2130
+ };
2131
+ var tableDataToMarkdown = (data) => {
2132
+ const { headers, rows } = data;
2133
+ if (headers.length === 0) {
2134
+ return "";
2135
+ }
2136
+ const markdownRows = new Array(rows.length + 2);
2137
+ let rowIndex = 0;
2138
+ const escapedHeaders = headers.map((h) => escapeMarkdownTableCell(h));
2139
+ markdownRows[rowIndex] = `| ${escapedHeaders.join(" | ")} |`;
2140
+ rowIndex += 1;
2141
+ const separatorParts = new Array(headers.length);
2142
+ for (let i = 0; i < headers.length; i += 1) {
2143
+ separatorParts[i] = "---";
2144
+ }
2145
+ markdownRows[rowIndex] = `| ${separatorParts.join(" | ")} |`;
2146
+ rowIndex += 1;
2147
+ for (const row of rows) {
2148
+ if (row.length < headers.length) {
2149
+ const paddedRow = new Array(headers.length);
2150
+ for (let i = 0; i < headers.length; i += 1) {
2151
+ paddedRow[i] = i < row.length ? escapeMarkdownTableCell(row[i]) : "";
2152
+ }
2153
+ markdownRows[rowIndex] = `| ${paddedRow.join(" | ")} |`;
2154
+ rowIndex += 1;
2155
+ } else {
2156
+ const escapedRow = row.map((cell) => escapeMarkdownTableCell(cell));
2157
+ markdownRows[rowIndex] = `| ${escapedRow.join(" | ")} |`;
2158
+ rowIndex += 1;
2159
+ }
2160
+ }
2161
+ return markdownRows.join("\n");
2162
+ };
2163
+
2164
+ // src/lib/table/copy-dropdown.tsrx
2165
+ var TableCopyDropdown = ({ children, className, onCopy, onError, timeout = 2e3 }) => {
2166
+ const cn2 = useCn();
2167
+ const [isOpen, setIsOpen] = useState7(false);
2168
+ const [isCopied, setIsCopied] = useState7(false);
2169
+ const dropdownRef = useRef6(null);
2170
+ const timeoutRef = useRef6(0);
2171
+ const { isAnimating } = useContext11(StreamdownContext);
2172
+ const t = useTranslations();
2173
+ const copyTableData = async (format) => {
2174
+ if (typeof window === "undefined" || !navigator?.clipboard?.write) {
2175
+ onError?.(new Error("Clipboard API not available"));
2176
+ return;
2177
+ }
2178
+ try {
2179
+ const tableElement = findTableForControl(dropdownRef.current);
2180
+ if (!tableElement) {
2181
+ onError?.(new Error("Table not found"));
2182
+ return;
2183
+ }
2184
+ const tableData = extractTableDataFromElement(tableElement);
2185
+ const formatters = {
2186
+ csv: tableDataToCSV,
2187
+ tsv: tableDataToTSV,
2188
+ md: tableDataToMarkdown
2189
+ };
2190
+ const formatter = formatters[format] || tableDataToMarkdown;
2191
+ const content = formatter(tableData);
2192
+ const clipboardItemData = new ClipboardItem({
2193
+ "text/plain": new Blob([content], { type: "text/plain" }),
2194
+ "text/html": new Blob([tableElement.outerHTML], { type: "text/html" })
2195
+ });
2196
+ await navigator.clipboard.write([clipboardItemData]);
2197
+ setIsCopied(true);
2198
+ setIsOpen(false);
2199
+ onCopy?.(format);
2200
+ timeoutRef.current = window.setTimeout(() => setIsCopied(false), timeout);
2201
+ } catch (error) {
2202
+ onError?.(error);
2203
+ }
2204
+ };
2205
+ useEffect7(
2206
+ () => {
2207
+ const handleClickOutside = (event) => {
2208
+ const path = event.composedPath();
2209
+ if (dropdownRef.current && !path.includes(dropdownRef.current)) {
2210
+ setIsOpen(false);
2211
+ }
2212
+ };
2213
+ document.addEventListener("mousedown", handleClickOutside);
2214
+ return () => {
2215
+ document.removeEventListener("mousedown", handleClickOutside);
2216
+ window.clearTimeout(timeoutRef.current);
2217
+ };
2218
+ },
2219
+ []
2220
+ );
2221
+ const icons = useIcons();
2222
+ const Icon = isCopied ? icons.CheckIcon : icons.CopyIcon;
2223
+ return _$createScopedValue14(() => _$createScopedElement12("div", { className: cn2("relative"), ref: dropdownRef }, () => _$positionalChildren7([
2224
+ _$createScopedValue14(() => _$createScopedElement12(
2225
+ "button",
2226
+ {
2227
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
2228
+ disabled: isAnimating,
2229
+ onClick: () => setIsOpen(!isOpen),
2230
+ title: t.copyTable,
2231
+ type: "button"
2232
+ },
2233
+ () => children ?? _$createElement11(Icon, { height: 14, width: 14 })
2234
+ )),
2235
+ isOpen ? _$createScopedValue14(() => _$createScopedElement12(
2236
+ "div",
2237
+ {
2238
+ className: cn2("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg")
2239
+ },
2240
+ () => _$positionalChildren7([
2241
+ _$createScopedValue14(() => _$createScopedElement12(
2242
+ "button",
2243
+ {
2244
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
2245
+ onClick: () => copyTableData("md"),
2246
+ title: t.copyTableAsMarkdown,
2247
+ type: "button"
2248
+ },
2249
+ () => t.tableFormatMarkdown
2250
+ )),
2251
+ _$createScopedValue14(() => _$createScopedElement12(
2252
+ "button",
2253
+ {
2254
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
2255
+ onClick: () => copyTableData("csv"),
2256
+ title: t.copyTableAsCsv,
2257
+ type: "button"
2258
+ },
2259
+ () => t.tableFormatCsv
2260
+ )),
2261
+ _$createScopedValue14(() => _$createScopedElement12(
2262
+ "button",
2263
+ {
2264
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
2265
+ onClick: () => copyTableData("tsv"),
2266
+ title: t.copyTableAsTsv,
2267
+ type: "button"
2268
+ },
2269
+ () => t.tableFormatTsv
2270
+ ))
2271
+ ])
2272
+ )) : null
2273
+ ])));
2274
+ };
2275
+
2276
+ // src/lib/table/download-dropdown.tsrx
2277
+ import {
2278
+ createElement as _$createElement12,
2279
+ createScopedElement as _$createScopedElement13,
2280
+ createScopedValue as _$createScopedValue15,
2281
+ positionalChildren as _$positionalChildren8,
2282
+ useContext as useContext12,
2283
+ useEffect as useEffect8,
2284
+ useRef as useRef7,
2285
+ useState as useState8
2286
+ } from "octane/server";
2287
+ var TableDownloadButton = ({
2288
+ children,
2289
+ className,
2290
+ onDownload,
2291
+ onError,
2292
+ format = "csv",
2293
+ filename
2294
+ }) => {
2295
+ const cn2 = useCn();
2296
+ const { isAnimating } = useContext12(StreamdownContext);
2297
+ const t = useTranslations();
2298
+ const icons = useIcons();
2299
+ const downloadTableData = (event) => {
2300
+ try {
2301
+ const tableElement = findTableForControl(event.currentTarget);
2302
+ if (!tableElement) {
2303
+ onError?.(new Error("Table not found"));
2304
+ return;
2305
+ }
2306
+ const tableData = extractTableDataFromElement(tableElement);
2307
+ let content = "";
2308
+ let mimeType = "";
2309
+ let extension = "";
2310
+ switch (format) {
2311
+ case "csv":
2312
+ content = tableDataToCSV(tableData);
2313
+ mimeType = "text/csv";
2314
+ extension = "csv";
2315
+ break;
2316
+ case "markdown":
2317
+ content = tableDataToMarkdown(tableData);
2318
+ mimeType = "text/markdown";
2319
+ extension = "md";
2320
+ break;
2321
+ default:
2322
+ content = tableDataToCSV(tableData);
2323
+ mimeType = "text/csv";
2324
+ extension = "csv";
2325
+ }
2326
+ save(`${filename || "table"}.${extension}`, content, mimeType);
2327
+ onDownload?.();
2328
+ } catch (error) {
2329
+ onError?.(error);
2330
+ }
2331
+ };
2332
+ return _$createScopedValue15(() => _$createScopedElement13(
2333
+ "button",
2334
+ {
2335
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
2336
+ disabled: isAnimating,
2337
+ onClick: downloadTableData,
2338
+ title: format === "csv" ? t.downloadTableAsCsv : t.downloadTableAsMarkdown,
2339
+ type: "button"
2340
+ },
2341
+ () => children ?? _$createScopedValue15(() => _$createElement12(icons.DownloadIcon, { size: 14 }))
2342
+ ));
2343
+ };
2344
+ var TableDownloadDropdown = ({ children, className, onDownload, onError }) => {
2345
+ const cn2 = useCn();
2346
+ const [isOpen, setIsOpen] = useState8(false);
2347
+ const dropdownRef = useRef7(null);
2348
+ const { isAnimating } = useContext12(StreamdownContext);
2349
+ const t = useTranslations();
2350
+ const icons = useIcons();
2351
+ const downloadTableData = (format) => {
2352
+ try {
2353
+ const tableElement = findTableForControl(dropdownRef.current);
2354
+ if (!tableElement) {
2355
+ onError?.(new Error("Table not found"));
2356
+ return;
2357
+ }
2358
+ const tableData = extractTableDataFromElement(tableElement);
2359
+ const content = format === "csv" ? tableDataToCSV(tableData) : tableDataToMarkdown(tableData);
2360
+ const extension = format === "csv" ? "csv" : "md";
2361
+ const filename = `table.${extension}`;
2362
+ const mimeType = format === "csv" ? "text/csv" : "text/markdown";
2363
+ save(filename, content, mimeType);
2364
+ setIsOpen(false);
2365
+ onDownload?.(format);
2366
+ } catch (error) {
2367
+ onError?.(error);
2368
+ }
2369
+ };
2370
+ useEffect8(
2371
+ () => {
2372
+ const handleClickOutside = (event) => {
2373
+ const path = event.composedPath();
2374
+ if (dropdownRef.current && !path.includes(dropdownRef.current)) {
2375
+ setIsOpen(false);
2376
+ }
2377
+ };
2378
+ document.addEventListener("mousedown", handleClickOutside);
2379
+ return () => {
2380
+ document.removeEventListener("mousedown", handleClickOutside);
2381
+ };
2382
+ },
2383
+ []
2384
+ );
2385
+ return _$createScopedValue15(() => _$createScopedElement13("div", { className: cn2("relative"), ref: dropdownRef }, () => _$positionalChildren8([
2386
+ _$createScopedValue15(() => _$createScopedElement13(
2387
+ "button",
2388
+ {
2389
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
2390
+ disabled: isAnimating,
2391
+ onClick: () => setIsOpen(!isOpen),
2392
+ title: t.downloadTable,
2393
+ type: "button"
2394
+ },
2395
+ () => children ?? _$createScopedValue15(() => _$createElement12(icons.DownloadIcon, { size: 14 }))
2396
+ )),
2397
+ isOpen ? _$createScopedValue15(() => _$createScopedElement13(
2398
+ "div",
2399
+ {
2400
+ className: cn2("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg")
2401
+ },
2402
+ () => _$positionalChildren8([
2403
+ _$createScopedValue15(() => _$createScopedElement13(
2404
+ "button",
2405
+ {
2406
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
2407
+ onClick: () => downloadTableData("csv"),
2408
+ title: t.downloadTableAsCsv,
2409
+ type: "button"
2410
+ },
2411
+ () => t.tableFormatCsv
2412
+ )),
2413
+ _$createScopedValue15(() => _$createScopedElement13(
2414
+ "button",
2415
+ {
2416
+ className: cn2("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),
2417
+ onClick: () => downloadTableData("markdown"),
2418
+ title: t.downloadTableAsMarkdown,
2419
+ type: "button"
2420
+ },
2421
+ () => t.tableFormatMarkdown
2422
+ ))
2423
+ ])
2424
+ )) : null
2425
+ ])));
2426
+ };
2427
+
2428
+ // src/lib/table/fullscreen-button.tsrx
2429
+ import {
2430
+ Fragment as _$Fragment3,
2431
+ createElement as _$createElement13,
2432
+ createPortal as createPortal2,
2433
+ createScopedElement as _$createScopedElement14,
2434
+ createScopedValue as _$createScopedValue16,
2435
+ positionalChildren as _$positionalChildren9,
2436
+ useContext as useContext13,
2437
+ useEffect as useEffect9,
2438
+ useState as useState9
2439
+ } from "octane/server";
2440
+ var TableFullscreenButton = ({ children, className, showCopy = true, showDownload = true }) => {
2441
+ const { Maximize2Icon: Maximize2Icon2, XIcon: XIcon2 } = useIcons();
2442
+ const cn2 = useCn();
2443
+ const [isFullscreen, setIsFullscreen] = useState9(false);
2444
+ const { isAnimating } = useContext13(StreamdownContext);
2445
+ const t = useTranslations();
2446
+ const handleOpen = () => {
2447
+ setIsFullscreen(true);
2448
+ };
2449
+ const handleClose = () => {
2450
+ setIsFullscreen(false);
2451
+ };
2452
+ useEffect9(
2453
+ () => {
2454
+ if (isFullscreen) {
2455
+ lockBodyScroll();
2456
+ const handleEsc = (e) => {
2457
+ if (e.key === "Escape") {
2458
+ setIsFullscreen(false);
2459
+ }
2460
+ };
2461
+ document.addEventListener("keydown", handleEsc);
2462
+ return () => {
2463
+ document.removeEventListener("keydown", handleEsc);
2464
+ unlockBodyScroll();
2465
+ };
2466
+ }
2467
+ },
2468
+ [isFullscreen]
2469
+ );
2470
+ return _$createScopedElement14(_$Fragment3, {}, () => _$positionalChildren9([
2471
+ _$createScopedValue16(() => _$createScopedElement14(
2472
+ "button",
2473
+ {
2474
+ className: cn2("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", className),
2475
+ disabled: isAnimating,
2476
+ onClick: handleOpen,
2477
+ title: t.viewFullscreen,
2478
+ type: "button"
2479
+ },
2480
+ () => _$createElement13(Maximize2Icon2, { size: 14 })
2481
+ )),
2482
+ isFullscreen ? createPortal2(
2483
+ _$createScopedValue16(() => _$createScopedElement14(
2484
+ "div",
2485
+ {
2486
+ "aria-label": t.viewFullscreen,
2487
+ "aria-modal": "true",
2488
+ className: cn2("fixed inset-0 z-50 flex flex-col bg-background"),
2489
+ "data-streamdown": "table-fullscreen",
2490
+ onClick: handleClose,
2491
+ onKeyDown: (e) => {
2492
+ if (e.key === "Escape") {
2493
+ handleClose();
2494
+ }
2495
+ },
2496
+ role: "dialog"
2497
+ },
2498
+ () => _$createScopedValue16(() => _$createScopedElement14(
2499
+ "div",
2500
+ {
2501
+ className: cn2("flex h-full flex-col"),
2502
+ onClick: (e) => e.stopPropagation(),
2503
+ onKeyDown: (e) => e.stopPropagation(),
2504
+ role: "presentation"
2505
+ },
2506
+ () => _$positionalChildren9([
2507
+ _$createScopedValue16(() => _$createScopedElement14("div", { className: cn2("flex items-center justify-end gap-1 p-4") }, () => _$positionalChildren9([
2508
+ showCopy ? _$createElement13(TableCopyDropdown, {}) : null,
2509
+ showDownload ? _$createElement13(TableDownloadDropdown, {}) : null,
2510
+ _$createScopedValue16(() => _$createScopedElement14(
2511
+ "button",
2512
+ {
2513
+ className: cn2("rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),
2514
+ onClick: handleClose,
2515
+ title: t.exitFullscreen,
2516
+ type: "button"
2517
+ },
2518
+ () => _$createElement13(XIcon2, { size: 20 })
2519
+ ))
2520
+ ]))),
2521
+ _$createScopedValue16(() => _$createScopedElement14(
2522
+ "div",
2523
+ {
2524
+ className: cn2("flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10")
2525
+ },
2526
+ () => _$createScopedValue16(() => _$createScopedElement14(
2527
+ "table",
2528
+ {
2529
+ className: cn2("w-full border-collapse border border-border"),
2530
+ "data-streamdown": "table"
2531
+ },
2532
+ () => children
2533
+ ))
2534
+ ))
2535
+ ])
2536
+ ))
2537
+ )),
2538
+ document.body
2539
+ ) : null
2540
+ ]));
2541
+ };
2542
+
2543
+ // src/lib/table/index.tsrx
2544
+ var Table = ({
2545
+ children,
2546
+ className,
2547
+ showControls,
2548
+ showCopy = true,
2549
+ showDownload = true,
2550
+ showFullscreen = true,
2551
+ ...props
2552
+ }) => {
2553
+ const cn2 = useCn();
2554
+ const hasCopy = showControls && showCopy;
2555
+ const hasDownload = showControls && showDownload;
2556
+ const hasFullscreen = showControls && showFullscreen;
2557
+ const hasAnyControl = hasCopy || hasDownload || hasFullscreen;
2558
+ return _$createScopedValue17(() => _$createScopedElement15(
2559
+ "div",
2560
+ {
2561
+ className: cn2("my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2"),
2562
+ "data-streamdown": "table-wrapper"
2563
+ },
2564
+ () => _$positionalChildren10([
2565
+ hasAnyControl ? _$createScopedValue17(() => _$createScopedElement15("div", { className: cn2("flex items-center justify-end gap-1") }, () => _$positionalChildren10([
2566
+ hasCopy ? _$createElement14(TableCopyDropdown, {}) : null,
2567
+ hasDownload ? _$createElement14(TableDownloadDropdown, {}) : null,
2568
+ hasFullscreen ? _$createScopedValue17(() => _$createScopedElement15(TableFullscreenButton, { showCopy: hasCopy, showDownload: hasDownload }, () => children)) : null
2569
+ ]))) : null,
2570
+ _$createScopedValue17(() => _$createScopedElement15(
2571
+ "div",
2572
+ {
2573
+ className: cn2("border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background")
2574
+ },
2575
+ () => _$createScopedValue17(() => _$createScopedElement15(
2576
+ "table",
2577
+ {
2578
+ className: cn2("w-full divide-y divide-border", className),
2579
+ "data-streamdown": "table",
2580
+ ...props
2581
+ },
2582
+ () => children
2583
+ ))
2584
+ ))
2585
+ ])
2586
+ ));
2587
+ };
2588
+
2589
+ // src/lib/components.tsrx
2590
+ var START_LINE_PATTERN = /startLine=(\d+)/;
2591
+ var NO_LINE_NUMBERS_PATTERN = /\bnoLineNumbers\b/;
2592
+ var Mermaid2 = /* @__PURE__ */ lazy2(() => import("./mermaid-SICAYVAP.js").then((mod) => ({ default: mod.Mermaid })));
2593
+ var LANGUAGE_REGEX = /language-([^\s]+)/;
2594
+ function sameNodePosition(prev, next) {
2595
+ if (!(prev?.position || next?.position)) {
2596
+ return true;
2597
+ }
2598
+ if (!(prev?.position && next?.position)) {
2599
+ return false;
2600
+ }
2601
+ const prevStart = prev.position.start;
2602
+ const nextStart = next.position.start;
2603
+ const prevEnd = prev.position.end;
2604
+ const nextEnd = next.position.end;
2605
+ return prevStart?.line === nextStart?.line && prevStart?.column === nextStart?.column && prevEnd?.line === nextEnd?.line && prevEnd?.column === nextEnd?.column;
2606
+ }
2607
+ function sameClassAndNode(prev, next) {
2608
+ return prev.className === next.className && sameNodePosition(prev.node, next.node);
2609
+ }
2610
+ var shouldShowControls = (config, type) => {
2611
+ if (typeof config === "boolean") {
2612
+ return config;
2613
+ }
2614
+ return config[type] !== false;
2615
+ };
2616
+ var shouldShowTableControl = (config, controlType) => {
2617
+ if (typeof config === "boolean") {
2618
+ return config;
2619
+ }
2620
+ const tableConfig = config.table;
2621
+ if (tableConfig === false) {
2622
+ return false;
2623
+ }
2624
+ if (tableConfig === true || tableConfig === void 0) {
2625
+ return true;
2626
+ }
2627
+ return tableConfig[controlType] !== false;
2628
+ };
2629
+ var shouldShowCodeControl = (config, controlType) => {
2630
+ if (typeof config === "boolean") {
2631
+ return config;
2632
+ }
2633
+ const codeConfig = config.code;
2634
+ if (codeConfig === false) {
2635
+ return false;
2636
+ }
2637
+ if (codeConfig === true || codeConfig === void 0) {
2638
+ return true;
2639
+ }
2640
+ return codeConfig[controlType] !== false;
2641
+ };
2642
+ var shouldShowMermaidControl = (config, controlType) => {
2643
+ if (typeof config === "boolean") {
2644
+ return config;
2645
+ }
2646
+ const mermaidConfig = config.mermaid;
2647
+ if (mermaidConfig === false) {
2648
+ return false;
2649
+ }
2650
+ if (mermaidConfig === true || mermaidConfig === void 0) {
2651
+ return true;
2652
+ }
2653
+ return mermaidConfig[controlType] !== false;
2654
+ };
2655
+ var MemoOl = memo2(
2656
+ ({ children, className, node, ...props }) => {
2657
+ const cn2 = useCn();
2658
+ return _$createScopedValue18(() => _$createScopedElement16(
2659
+ "ol",
2660
+ {
2661
+ className: cn2("list-inside list-decimal whitespace-normal [li_&]:pl-6", className),
2662
+ "data-streamdown": "ordered-list",
2663
+ ...props
2664
+ },
2665
+ () => children
2666
+ ));
2667
+ },
2668
+ (p, n) => sameClassAndNode(p, n)
2669
+ );
2670
+ Object.assign(MemoOl, { displayName: "MarkdownOl" });
2671
+ var MemoLi = memo2(
2672
+ ({ children, className, node, ...props }) => {
2673
+ const cn2 = useCn();
2674
+ return _$createScopedValue18(() => _$createScopedElement16(
2675
+ "li",
2676
+ {
2677
+ className: cn2("py-1 [&>p]:inline", className),
2678
+ "data-streamdown": "list-item",
2679
+ ...props
2680
+ },
2681
+ () => children
2682
+ ));
2683
+ },
2684
+ (p, n) => p.className === n.className && sameNodePosition(p.node, n.node)
2685
+ );
2686
+ Object.assign(MemoLi, { displayName: "MarkdownLi" });
2687
+ var MemoUl = memo2(
2688
+ ({ children, className, node, ...props }) => {
2689
+ const cn2 = useCn();
2690
+ return _$createScopedValue18(() => _$createScopedElement16(
2691
+ "ul",
2692
+ {
2693
+ className: cn2("list-inside list-disc whitespace-normal [li_&]:pl-6", className),
2694
+ "data-streamdown": "unordered-list",
2695
+ ...props
2696
+ },
2697
+ () => children
2698
+ ));
2699
+ },
2700
+ (p, n) => sameClassAndNode(p, n)
2701
+ );
2702
+ Object.assign(MemoUl, { displayName: "MarkdownUl" });
2703
+ var MemoHr = memo2(
2704
+ ({ className, node, ...props }) => {
2705
+ const cn2 = useCn();
2706
+ return _$createScopedValue18(() => _$createElement15("hr", {
2707
+ className: cn2("my-6 border-border", className),
2708
+ "data-streamdown": "horizontal-rule",
2709
+ ...props
2710
+ }));
2711
+ },
2712
+ (p, n) => sameClassAndNode(p, n)
2713
+ );
2714
+ Object.assign(MemoHr, { displayName: "MarkdownHr" });
2715
+ var MemoStrong = memo2(
2716
+ ({ children, className, node, ...props }) => {
2717
+ const cn2 = useCn();
2718
+ return _$createScopedValue18(() => _$createScopedElement16(
2719
+ "span",
2720
+ {
2721
+ className: cn2("font-semibold", className),
2722
+ "data-streamdown": "strong",
2723
+ ...props
2724
+ },
2725
+ () => children
2726
+ ));
2727
+ },
2728
+ (p, n) => sameClassAndNode(p, n)
2729
+ );
2730
+ Object.assign(MemoStrong, { displayName: "MarkdownStrong" });
2731
+ var LinkComponent = ({ children, className, href, node, ...props }) => {
2732
+ const cn2 = useCn();
2733
+ const { linkSafety } = useContext14(StreamdownContext);
2734
+ const [isModalOpen, setIsModalOpen] = useState10(false);
2735
+ const isIncomplete = href === "streamdown:incomplete-link";
2736
+ const handleClick = useCallback3(
2737
+ async (e) => {
2738
+ if (!(linkSafety?.enabled && href) || isIncomplete) {
2739
+ return;
2740
+ }
2741
+ e.preventDefault();
2742
+ if (linkSafety.onLinkCheck) {
2743
+ const isAllowed = await linkSafety.onLinkCheck(href);
2744
+ if (isAllowed) {
2745
+ window.open(href, "_blank", "noreferrer");
2746
+ return;
2747
+ }
2748
+ }
2749
+ setIsModalOpen(true);
2750
+ },
2751
+ [linkSafety, href, isIncomplete]
2752
+ );
2753
+ const handleConfirm = useCallback3(
2754
+ () => {
2755
+ if (href) {
2756
+ window.open(href, "_blank", "noreferrer");
2757
+ }
2758
+ },
2759
+ [href]
2760
+ );
2761
+ const handleCloseModal = useCallback3(
2762
+ () => {
2763
+ setIsModalOpen(false);
2764
+ },
2765
+ []
2766
+ );
2767
+ const modalProps = {
2768
+ url: href ?? "",
2769
+ isOpen: isModalOpen,
2770
+ onClose: handleCloseModal,
2771
+ onConfirm: handleConfirm
2772
+ };
2773
+ if (linkSafety?.enabled && href) {
2774
+ return _$createScopedElement16(_$Fragment4, {}, () => _$positionalChildren11([
2775
+ _$createScopedValue18(() => _$createScopedElement16(
2776
+ "button",
2777
+ {
2778
+ className: cn2("wrap-anywhere appearance-none text-left font-medium text-primary underline", className),
2779
+ "data-incomplete": isIncomplete,
2780
+ "data-streamdown": "link",
2781
+ onClick: handleClick,
2782
+ type: "button"
2783
+ },
2784
+ () => children
2785
+ )),
2786
+ linkSafety.renderModal ? linkSafety.renderModal(modalProps) : _$createScopedValue18(() => _$createElement15(LinkSafetyModal, { ...modalProps }))
2787
+ ]));
2788
+ }
2789
+ return _$createScopedValue18(() => _$createScopedElement16(
2790
+ "a",
2791
+ {
2792
+ className: cn2("wrap-anywhere font-medium text-primary underline", className),
2793
+ "data-incomplete": isIncomplete,
2794
+ "data-streamdown": "link",
2795
+ href,
2796
+ rel: "noreferrer",
2797
+ target: "_blank",
2798
+ ...props
2799
+ },
2800
+ () => children
2801
+ ));
2802
+ };
2803
+ var MemoA = memo2(LinkComponent, (p, n) => sameClassAndNode(p, n) && p.href === n.href);
2804
+ Object.assign(MemoA, { displayName: "MarkdownA" });
2805
+ var MemoH1 = memo2(
2806
+ ({ children, className, node, ...props }) => {
2807
+ const cn2 = useCn();
2808
+ return _$createScopedValue18(() => _$createScopedElement16(
2809
+ "h1",
2810
+ {
2811
+ className: cn2("mt-6 mb-2 font-semibold text-3xl", className),
2812
+ "data-streamdown": "heading-1",
2813
+ ...props
2814
+ },
2815
+ () => children
2816
+ ));
2817
+ },
2818
+ (p, n) => sameClassAndNode(p, n)
2819
+ );
2820
+ Object.assign(MemoH1, { displayName: "MarkdownH1" });
2821
+ var MemoH2 = memo2(
2822
+ ({ children, className, node, ...props }) => {
2823
+ const cn2 = useCn();
2824
+ return _$createScopedValue18(() => _$createScopedElement16(
2825
+ "h2",
2826
+ {
2827
+ className: cn2("mt-6 mb-2 font-semibold text-2xl", className),
2828
+ "data-streamdown": "heading-2",
2829
+ ...props
2830
+ },
2831
+ () => children
2832
+ ));
2833
+ },
2834
+ (p, n) => sameClassAndNode(p, n)
2835
+ );
2836
+ Object.assign(MemoH2, { displayName: "MarkdownH2" });
2837
+ var MemoH3 = memo2(
2838
+ ({ children, className, node, ...props }) => {
2839
+ const cn2 = useCn();
2840
+ return _$createScopedValue18(() => _$createScopedElement16(
2841
+ "h3",
2842
+ {
2843
+ className: cn2("mt-6 mb-2 font-semibold text-xl", className),
2844
+ "data-streamdown": "heading-3",
2845
+ ...props
2846
+ },
2847
+ () => children
2848
+ ));
2849
+ },
2850
+ (p, n) => sameClassAndNode(p, n)
2851
+ );
2852
+ Object.assign(MemoH3, { displayName: "MarkdownH3" });
2853
+ var MemoH4 = memo2(
2854
+ ({ children, className, node, ...props }) => {
2855
+ const cn2 = useCn();
2856
+ return _$createScopedValue18(() => _$createScopedElement16(
2857
+ "h4",
2858
+ {
2859
+ className: cn2("mt-6 mb-2 font-semibold text-lg", className),
2860
+ "data-streamdown": "heading-4",
2861
+ ...props
2862
+ },
2863
+ () => children
2864
+ ));
2865
+ },
2866
+ (p, n) => sameClassAndNode(p, n)
2867
+ );
2868
+ Object.assign(MemoH4, { displayName: "MarkdownH4" });
2869
+ var MemoH5 = memo2(
2870
+ ({ children, className, node, ...props }) => {
2871
+ const cn2 = useCn();
2872
+ return _$createScopedValue18(() => _$createScopedElement16(
2873
+ "h5",
2874
+ {
2875
+ className: cn2("mt-6 mb-2 font-semibold text-base", className),
2876
+ "data-streamdown": "heading-5",
2877
+ ...props
2878
+ },
2879
+ () => children
2880
+ ));
2881
+ },
2882
+ (p, n) => sameClassAndNode(p, n)
2883
+ );
2884
+ Object.assign(MemoH5, { displayName: "MarkdownH5" });
2885
+ var MemoH6 = memo2(
2886
+ ({ children, className, node, ...props }) => {
2887
+ const cn2 = useCn();
2888
+ return _$createScopedValue18(() => _$createScopedElement16(
2889
+ "h6",
2890
+ {
2891
+ className: cn2("mt-6 mb-2 font-semibold text-sm", className),
2892
+ "data-streamdown": "heading-6",
2893
+ ...props
2894
+ },
2895
+ () => children
2896
+ ));
2897
+ },
2898
+ (p, n) => sameClassAndNode(p, n)
2899
+ );
2900
+ Object.assign(MemoH6, { displayName: "MarkdownH6" });
2901
+ var MemoTable = memo2(
2902
+ ({ children, className, node, ...props }) => {
2903
+ const { controls: controlsConfig } = useContext14(StreamdownContext);
2904
+ const showTableControls = shouldShowControls(controlsConfig, "table");
2905
+ const showCopy = shouldShowTableControl(controlsConfig, "copy");
2906
+ const showDownload = shouldShowTableControl(controlsConfig, "download");
2907
+ const showFullscreen = shouldShowTableControl(controlsConfig, "fullscreen");
2908
+ return _$createScopedValue18(() => _$createScopedElement16(
2909
+ Table,
2910
+ {
2911
+ className,
2912
+ showControls: showTableControls,
2913
+ showCopy,
2914
+ showDownload,
2915
+ showFullscreen,
2916
+ ...props
2917
+ },
2918
+ () => children
2919
+ ));
2920
+ },
2921
+ (p, n) => sameClassAndNode(p, n)
2922
+ );
2923
+ Object.assign(MemoTable, { displayName: "MarkdownTable" });
2924
+ var MemoThead = memo2(
2925
+ ({ children, className, node, ...props }) => {
2926
+ const cn2 = useCn();
2927
+ return _$createScopedValue18(() => _$createScopedElement16(
2928
+ "thead",
2929
+ {
2930
+ className: cn2("bg-muted/80", className),
2931
+ "data-streamdown": "table-header",
2932
+ ...props
2933
+ },
2934
+ () => children
2935
+ ));
2936
+ },
2937
+ (p, n) => sameClassAndNode(p, n)
2938
+ );
2939
+ Object.assign(MemoThead, { displayName: "MarkdownThead" });
2940
+ var MemoTbody = memo2(
2941
+ ({ children, className, node, ...props }) => {
2942
+ const cn2 = useCn();
2943
+ return _$createScopedValue18(() => _$createScopedElement16(
2944
+ "tbody",
2945
+ {
2946
+ className: cn2("divide-y divide-border", className),
2947
+ "data-streamdown": "table-body",
2948
+ ...props
2949
+ },
2950
+ () => children
2951
+ ));
2952
+ },
2953
+ (p, n) => sameClassAndNode(p, n)
2954
+ );
2955
+ Object.assign(MemoTbody, { displayName: "MarkdownTbody" });
2956
+ var MemoTr = memo2(
2957
+ ({ children, className, node, ...props }) => {
2958
+ const cn2 = useCn();
2959
+ return _$createScopedValue18(() => _$createScopedElement16(
2960
+ "tr",
2961
+ {
2962
+ className: cn2("border-border", className),
2963
+ "data-streamdown": "table-row",
2964
+ ...props
2965
+ },
2966
+ () => children
2967
+ ));
2968
+ },
2969
+ (p, n) => sameClassAndNode(p, n)
2970
+ );
2971
+ Object.assign(MemoTr, { displayName: "MarkdownTr" });
2972
+ var MemoTh = memo2(
2973
+ ({ children, className, node, ...props }) => {
2974
+ const cn2 = useCn();
2975
+ return _$createScopedValue18(() => _$createScopedElement16(
2976
+ "th",
2977
+ {
2978
+ className: cn2("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm", className),
2979
+ "data-streamdown": "table-header-cell",
2980
+ ...props
2981
+ },
2982
+ () => children
2983
+ ));
2984
+ },
2985
+ (p, n) => sameClassAndNode(p, n)
2986
+ );
2987
+ Object.assign(MemoTh, { displayName: "MarkdownTh" });
2988
+ var MemoTd = memo2(
2989
+ ({ children, className, node, ...props }) => {
2990
+ const cn2 = useCn();
2991
+ return _$createScopedValue18(() => _$createScopedElement16(
2992
+ "td",
2993
+ {
2994
+ className: cn2("px-4 py-2 text-sm", className),
2995
+ "data-streamdown": "table-cell",
2996
+ ...props
2997
+ },
2998
+ () => children
2999
+ ));
3000
+ },
3001
+ (p, n) => sameClassAndNode(p, n)
3002
+ );
3003
+ Object.assign(MemoTd, { displayName: "MarkdownTd" });
3004
+ var MemoBlockquote = memo2(
3005
+ ({ children, className, node, ...props }) => {
3006
+ const cn2 = useCn();
3007
+ return _$createScopedValue18(() => _$createScopedElement16(
3008
+ "blockquote",
3009
+ {
3010
+ className: cn2("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic", className),
3011
+ "data-streamdown": "blockquote",
3012
+ ...props
3013
+ },
3014
+ () => children
3015
+ ));
3016
+ },
3017
+ (p, n) => sameClassAndNode(p, n)
3018
+ );
3019
+ Object.assign(MemoBlockquote, { displayName: "MarkdownBlockquote" });
3020
+ var MemoSup = memo2(
3021
+ ({ children, className, node, ...props }) => {
3022
+ const cn2 = useCn();
3023
+ return _$createScopedValue18(() => _$createScopedElement16(
3024
+ "sup",
3025
+ {
3026
+ className: cn2("text-sm", className),
3027
+ "data-streamdown": "superscript",
3028
+ ...props
3029
+ },
3030
+ () => children
3031
+ ));
3032
+ },
3033
+ (p, n) => sameClassAndNode(p, n)
3034
+ );
3035
+ Object.assign(MemoSup, { displayName: "MarkdownSup" });
3036
+ var MemoSub = memo2(
3037
+ ({ children, className, node, ...props }) => {
3038
+ const cn2 = useCn();
3039
+ return _$createScopedValue18(() => _$createScopedElement16(
3040
+ "sub",
3041
+ {
3042
+ className: cn2("text-sm", className),
3043
+ "data-streamdown": "subscript",
3044
+ ...props
3045
+ },
3046
+ () => children
3047
+ ));
3048
+ },
3049
+ (p, n) => sameClassAndNode(p, n)
3050
+ );
3051
+ Object.assign(MemoSub, { displayName: "MarkdownSub" });
3052
+ var MemoSection = memo2(
3053
+ ({ children, className, node, ...props }) => {
3054
+ const isFootnotesSection = "data-footnotes" in props;
3055
+ if (isFootnotesSection) {
3056
+ const isEmptyFootnote = (listItem) => {
3057
+ if (!isValidElement(listItem)) {
3058
+ return false;
3059
+ }
3060
+ const itemChildren = Array.isArray(listItem.props.children) ? listItem.props.children : [listItem.props.children];
3061
+ let hasContent = false;
3062
+ let hasBackref = false;
3063
+ for (const itemChild of itemChildren) {
3064
+ if (!itemChild) {
3065
+ continue;
3066
+ }
3067
+ if (typeof itemChild === "string") {
3068
+ if (itemChild.trim() !== "") {
3069
+ hasContent = true;
3070
+ }
3071
+ } else if (isValidElement(itemChild)) {
3072
+ if (itemChild.props?.["data-footnote-backref"] !== void 0) {
3073
+ hasBackref = true;
3074
+ } else {
3075
+ const grandChildren = Array.isArray(itemChild.props.children) ? itemChild.props.children : [itemChild.props.children];
3076
+ for (const grandChild of grandChildren) {
3077
+ if (typeof grandChild === "string" && grandChild.trim() !== "") {
3078
+ hasContent = true;
3079
+ break;
3080
+ }
3081
+ if (isValidElement(grandChild) && grandChild.props?.["data-footnote-backref"] === void 0) {
3082
+ hasContent = true;
3083
+ break;
3084
+ }
3085
+ }
3086
+ }
3087
+ }
3088
+ }
3089
+ return hasBackref && !hasContent;
3090
+ };
3091
+ const processedChildren = Array.isArray(children) ? children.map((child) => {
3092
+ if (!isValidElement(child)) {
3093
+ return child;
3094
+ }
3095
+ if (child.type === MemoOl) {
3096
+ const listChildren = Array.isArray(child.props.children) ? child.props.children : [child.props.children];
3097
+ const filteredListChildren = listChildren.filter((listItem) => !isEmptyFootnote(listItem));
3098
+ if (filteredListChildren.length === 0) {
3099
+ return null;
3100
+ }
3101
+ return cloneElement(child, { children: filteredListChildren });
3102
+ }
3103
+ return child;
3104
+ }) : children;
3105
+ const hasAnyContent = Array.isArray(processedChildren) ? processedChildren.some((child) => child !== null) : processedChildren !== null;
3106
+ if (!hasAnyContent) {
3107
+ return null;
3108
+ }
3109
+ return _$createScopedValue18(() => _$createScopedElement16("section", { className, ...props }, () => processedChildren));
3110
+ }
3111
+ return _$createScopedValue18(() => _$createScopedElement16("section", { className, ...props }, () => children));
3112
+ },
3113
+ (p, n) => sameClassAndNode(p, n)
3114
+ );
3115
+ Object.assign(MemoSection, { displayName: "MarkdownSection" });
3116
+ var CodeComponent = ({ node, className, children, ...props }) => {
3117
+ const cn2 = useCn();
3118
+ const inline = !("data-block" in props);
3119
+ const {
3120
+ mermaid: mermaidContext,
3121
+ controls: controlsConfig,
3122
+ lineNumbers: contextLineNumbers
3123
+ } = useContext14(StreamdownContext);
3124
+ const mermaidPlugin = useMermaidPlugin();
3125
+ const isBlockIncomplete = useIsCodeFenceIncomplete();
3126
+ const match = className?.match(LANGUAGE_REGEX);
3127
+ const language = match?.at(1) ?? "";
3128
+ const customRenderer = useCustomRenderer(language);
3129
+ if (inline) {
3130
+ return _$createScopedValue18(() => _$createScopedElement16(
3131
+ "code",
3132
+ {
3133
+ className: cn2("rounded bg-muted px-1.5 py-0.5 font-mono text-sm", className),
3134
+ "data-streamdown": "inline-code",
3135
+ ...props
3136
+ },
3137
+ () => children
3138
+ ));
3139
+ }
3140
+ const metastring = node?.properties?.metastring;
3141
+ const startLineMatch = metastring?.match(START_LINE_PATTERN);
3142
+ const parsedStartLine = startLineMatch ? Number.parseInt(startLineMatch[1], 10) : void 0;
3143
+ const startLine = parsedStartLine !== void 0 && parsedStartLine >= 1 ? parsedStartLine : void 0;
3144
+ const metaNoLineNumbers = metastring ? NO_LINE_NUMBERS_PATTERN.test(metastring) : false;
3145
+ const showLineNumbers = !metaNoLineNumbers && contextLineNumbers !== false;
3146
+ let code = "";
3147
+ if (isValidElement(children) && children.props && typeof children.props === "object" && "children" in children.props && typeof children.props.children === "string") {
3148
+ code = children.props.children;
3149
+ } else if (typeof children === "string") {
3150
+ code = children;
3151
+ }
3152
+ if (customRenderer) {
3153
+ const CustomComponent = customRenderer.component;
3154
+ return _$createScopedValue18(() => _$createScopedElement16(Suspense2, { fallback: _$createElement15(CodeBlockSkeleton, {}) }, () => _$createScopedValue18(() => _$createElement15(CustomComponent, {
3155
+ code,
3156
+ isIncomplete: isBlockIncomplete,
3157
+ language,
3158
+ meta: metastring
3159
+ }))));
3160
+ }
3161
+ if (language === "mermaid" && mermaidPlugin) {
3162
+ const showMermaidControls = shouldShowControls(controlsConfig, "mermaid");
3163
+ const showDownload2 = shouldShowMermaidControl(controlsConfig, "download");
3164
+ const showCopy2 = shouldShowMermaidControl(controlsConfig, "copy");
3165
+ const showFullscreen = shouldShowMermaidControl(controlsConfig, "fullscreen");
3166
+ const showPanZoomControls = shouldShowMermaidControl(controlsConfig, "panZoom");
3167
+ const shouldShowMermaidControls = showMermaidControls && (showDownload2 || showCopy2 || showFullscreen);
3168
+ return _$createScopedValue18(() => _$createScopedElement16(Suspense2, { fallback: _$createElement15(CodeBlockSkeleton, {}) }, () => _$createScopedValue18(() => _$createScopedElement16(
3169
+ "div",
3170
+ {
3171
+ className: cn2("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2", className),
3172
+ "data-streamdown": "mermaid-block"
3173
+ },
3174
+ () => _$positionalChildren11([
3175
+ _$createScopedValue18(() => _$createScopedElement16(
3176
+ "div",
3177
+ {
3178
+ className: cn2("flex h-8 items-center text-muted-foreground text-xs")
3179
+ },
3180
+ () => _$createScopedValue18(() => _$createElement15("span", { className: cn2("ml-1 font-mono lowercase") }, "mermaid"))
3181
+ )),
3182
+ shouldShowMermaidControls ? _$createScopedValue18(() => _$createScopedElement16(
3183
+ "div",
3184
+ {
3185
+ className: cn2("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end")
3186
+ },
3187
+ () => _$createScopedValue18(() => _$createScopedElement16(
3188
+ "div",
3189
+ {
3190
+ className: cn2("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),
3191
+ "data-streamdown": "mermaid-block-actions"
3192
+ },
3193
+ () => _$positionalChildren11([
3194
+ showDownload2 ? _$createScopedValue18(() => _$createElement15(MermaidDownloadDropdown, { chart: code, config: mermaidContext?.config })) : null,
3195
+ showCopy2 ? _$createScopedValue18(() => _$createElement15(CodeBlockCopyButton, { code })) : null,
3196
+ showFullscreen ? _$createScopedValue18(() => _$createElement15(MermaidFullscreenButton, { chart: code, config: mermaidContext?.config })) : null
3197
+ ])
3198
+ ))
3199
+ )) : null,
3200
+ _$createScopedValue18(() => _$createScopedElement16(
3201
+ "div",
3202
+ {
3203
+ className: cn2("rounded-md border border-border bg-background")
3204
+ },
3205
+ () => _$createScopedValue18(() => _$createElement15(Mermaid2, {
3206
+ chart: code,
3207
+ config: mermaidContext?.config,
3208
+ showControls: showPanZoomControls
3209
+ }))
3210
+ ))
3211
+ ])
3212
+ ))));
3213
+ }
3214
+ const showCodeControls = shouldShowControls(controlsConfig, "code");
3215
+ const showDownload = shouldShowCodeControl(controlsConfig, "download");
3216
+ const showCopy = shouldShowCodeControl(controlsConfig, "copy");
3217
+ const shouldShowCodeControls = showCodeControls && (showDownload || showCopy);
3218
+ return _$createScopedValue18(() => _$createScopedElement16(
3219
+ CodeBlock,
3220
+ {
3221
+ className,
3222
+ code,
3223
+ isIncomplete: isBlockIncomplete,
3224
+ language,
3225
+ lineNumbers: showLineNumbers,
3226
+ startLine
3227
+ },
3228
+ () => shouldShowCodeControls ? _$createScopedElement16(_$Fragment4, {}, () => _$positionalChildren11([
3229
+ showDownload ? _$createScopedValue18(() => _$createElement15(CodeBlockDownloadButton, { code, language })) : null,
3230
+ showCopy ? _$createElement15(CodeBlockCopyButton, {}) : null
3231
+ ])) : null
3232
+ ));
3233
+ };
3234
+ var MemoCode = memo2(CodeComponent, (p, n) => p.className === n.className && sameNodePosition(p.node, n.node));
3235
+ Object.assign(MemoCode, { displayName: "MarkdownCode" });
3236
+ var MemoImg = memo2(ImageComponent);
3237
+ Object.assign(MemoImg, { displayName: "MarkdownImg" });
3238
+ var MemoParagraph = memo2(({ children, node, ...props }) => {
3239
+ const childArray = Array.isArray(children) ? children : [children];
3240
+ const validChildren = childArray.filter((child) => child !== null && child !== void 0 && child !== "");
3241
+ if (validChildren.length === 1 && isValidElement(validChildren[0])) {
3242
+ const node2 = validChildren[0].props.node;
3243
+ const tagName = node2?.tagName;
3244
+ if (tagName === "img") {
3245
+ return _$createScopedElement16(_$Fragment4, {}, () => _$positionalChildren11([children]));
3246
+ }
3247
+ if (tagName === "code") {
3248
+ const childProps = validChildren[0].props;
3249
+ if ("data-block" in childProps) {
3250
+ return _$createScopedElement16(_$Fragment4, {}, () => _$positionalChildren11([children]));
3251
+ }
3252
+ }
3253
+ }
3254
+ return _$createScopedValue18(() => _$createScopedElement16("p", { ...props }, () => children));
3255
+ });
3256
+ Object.assign(MemoParagraph, { displayName: "MarkdownParagraph" });
3257
+ var components = {
3258
+ ol: MemoOl,
3259
+ li: MemoLi,
3260
+ ul: MemoUl,
3261
+ hr: MemoHr,
3262
+ strong: MemoStrong,
3263
+ a: MemoA,
3264
+ h1: MemoH1,
3265
+ h2: MemoH2,
3266
+ h3: MemoH3,
3267
+ h4: MemoH4,
3268
+ h5: MemoH5,
3269
+ h6: MemoH6,
3270
+ table: MemoTable,
3271
+ thead: MemoThead,
3272
+ tbody: MemoTbody,
3273
+ tr: MemoTr,
3274
+ th: MemoTh,
3275
+ td: MemoTd,
3276
+ blockquote: MemoBlockquote,
3277
+ code: MemoCode,
3278
+ img: MemoImg,
3279
+ pre: ({ children }) => {
3280
+ if (isValidElement(children)) {
3281
+ return cloneElement(children, { "data-block": "true" });
3282
+ }
3283
+ return children;
3284
+ },
3285
+ sup: MemoSup,
3286
+ sub: MemoSub,
3287
+ p: MemoParagraph,
3288
+ section: MemoSection
3289
+ };
3290
+
3291
+ // src/lib/detect-direction.ts
3292
+ var RTL_PATTERN = /[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/;
3293
+ var LETTER_PATTERN = /\p{L}/u;
3294
+ function detectTextDirection(text) {
3295
+ const stripped = text.replace(/^#{1,6}\s+/gm, "").replace(/(\*{1,3}|_{1,3})/g, "").replace(/`[^`]*`/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/^[\s>*\-+\d.]+/gm, "");
3296
+ for (const char of stripped) {
3297
+ if (RTL_PATTERN.test(char)) {
3298
+ return "rtl";
3299
+ }
3300
+ if (LETTER_PATTERN.test(char)) {
3301
+ return "ltr";
3302
+ }
3303
+ }
3304
+ return "ltr";
3305
+ }
3306
+
3307
+ // src/lib/incomplete-code-utils.ts
3308
+ var CODE_FENCE_PATTERN = /^[ \t]{0,3}(`{3,}|~{3,})/;
3309
+ var TABLE_DELIMITER_PATTERN = /^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/;
3310
+ var hasIncompleteCodeFence = (markdown) => {
3311
+ const lines = markdown.split("\n");
3312
+ let openFenceChar = null;
3313
+ let openFenceLength = 0;
3314
+ for (const line of lines) {
3315
+ const match = CODE_FENCE_PATTERN.exec(line);
3316
+ if (openFenceChar === null) {
3317
+ if (match) {
3318
+ const fenceRun = match[1];
3319
+ openFenceChar = fenceRun[0];
3320
+ openFenceLength = fenceRun.length;
3321
+ }
3322
+ } else if (match) {
3323
+ const fenceRun = match[1];
3324
+ const char = fenceRun[0];
3325
+ const length = fenceRun.length;
3326
+ if (char === openFenceChar && length >= openFenceLength) {
3327
+ openFenceChar = null;
3328
+ openFenceLength = 0;
3329
+ }
3330
+ }
3331
+ }
3332
+ return openFenceChar !== null;
3333
+ };
3334
+ var hasTable = (markdown) => {
3335
+ const lines = markdown.split("\n");
3336
+ for (const line of lines) {
3337
+ const trimmed = line.trim();
3338
+ if (trimmed.length > 0 && trimmed.includes("|") && TABLE_DELIMITER_PATTERN.test(trimmed)) {
3339
+ return true;
3340
+ }
3341
+ }
3342
+ return false;
3343
+ };
3344
+
3345
+ // src/lib/markdown.tsrx
3346
+ import { Fragment, createElement as createElement2 } from "octane/server";
3347
+ import { toJsxRuntime } from "hast-util-to-jsx-runtime";
3348
+ import { urlAttributes } from "html-url-attributes";
3349
+ import rehypeRaw from "rehype-raw";
3350
+ import remarkParse from "remark-parse";
3351
+ import remarkRehype from "remark-rehype";
3352
+ import { unified } from "unified";
3353
+ import { visit as visit2 } from "unist-util-visit";
3354
+
3355
+ // src/lib/remark/escape-html.ts
3356
+ import { visit } from "unist-util-visit";
3357
+ var remarkEscapeHtml = () => (tree) => {
3358
+ visit(tree, "html", (node, index, parent) => {
3359
+ if (!parent || typeof index !== "number") {
3360
+ return;
3361
+ }
3362
+ parent.children[index] = {
3363
+ type: "text",
3364
+ value: node.value
3365
+ };
3366
+ });
3367
+ };
3368
+
3369
+ // src/lib/markdown.tsrx
3370
+ var EMPTY_PLUGINS = [];
3371
+ var DEFAULT_REMARK_REHYPE_OPTIONS = { allowDangerousHtml: true };
3372
+ var pluginNameCache = /* @__PURE__ */ new WeakMap();
3373
+ var ProcessorCache = class {
3374
+ cache = /* @__PURE__ */ new Map();
3375
+ keyCache = /* @__PURE__ */ new WeakMap();
3376
+ maxSize = 100;
3377
+ generateCacheKey(options) {
3378
+ const cachedKey = this.keyCache.get(options);
3379
+ if (cachedKey) {
3380
+ return cachedKey;
3381
+ }
3382
+ const rehypePlugins = options.rehypePlugins;
3383
+ const remarkPlugins = options.remarkPlugins;
3384
+ const remarkRehypeOptions = options.remarkRehypeOptions;
3385
+ if (!(rehypePlugins || remarkPlugins || remarkRehypeOptions)) {
3386
+ const key2 = "default";
3387
+ this.keyCache.set(options, key2);
3388
+ return key2;
3389
+ }
3390
+ const serializePlugins = (plugins) => {
3391
+ if (!plugins || plugins.length === 0) {
3392
+ return "";
3393
+ }
3394
+ let result = "";
3395
+ for (let i = 0; i < plugins.length; i += 1) {
3396
+ const plugin = plugins[i];
3397
+ if (i > 0) {
3398
+ result += ",";
3399
+ }
3400
+ if (Array.isArray(plugin)) {
3401
+ const [pluginFn, pluginOptions] = plugin;
3402
+ if (typeof pluginFn === "function") {
3403
+ let name = pluginNameCache.get(pluginFn);
3404
+ if (!name) {
3405
+ name = pluginFn.name;
3406
+ pluginNameCache.set(pluginFn, name);
3407
+ }
3408
+ result += name;
3409
+ } else {
3410
+ result += String(pluginFn);
3411
+ }
3412
+ result += ":";
3413
+ result += JSON.stringify(pluginOptions);
3414
+ } else if (typeof plugin === "function") {
3415
+ let name = pluginNameCache.get(plugin);
3416
+ if (!name) {
3417
+ name = plugin.name;
3418
+ pluginNameCache.set(plugin, name);
3419
+ }
3420
+ result += name;
3421
+ } else {
3422
+ result += String(plugin);
3423
+ }
3424
+ }
3425
+ return result;
3426
+ };
3427
+ const rehypeKey = serializePlugins(rehypePlugins);
3428
+ const remarkKey = serializePlugins(remarkPlugins);
3429
+ const optionsKey = remarkRehypeOptions ? JSON.stringify(remarkRehypeOptions) : "";
3430
+ const key = `${remarkKey}::${rehypeKey}::${optionsKey}`;
3431
+ this.keyCache.set(options, key);
3432
+ return key;
3433
+ }
3434
+ get(options) {
3435
+ const key = this.generateCacheKey(options);
3436
+ const processor = this.cache.get(key);
3437
+ if (processor) {
3438
+ this.cache.delete(key);
3439
+ this.cache.set(key, processor);
3440
+ }
3441
+ return processor;
3442
+ }
3443
+ set(options, processor) {
3444
+ const key = this.generateCacheKey(options);
3445
+ if (this.cache.size >= this.maxSize) {
3446
+ const firstKey = this.cache.keys().next().value;
3447
+ if (firstKey) {
3448
+ this.cache.delete(firstKey);
3449
+ }
3450
+ }
3451
+ this.cache.set(key, processor);
3452
+ }
3453
+ clear() {
3454
+ this.cache.clear();
3455
+ }
3456
+ };
3457
+ var processorCache = new ProcessorCache();
3458
+ var Markdown = (options) => {
3459
+ const processor = getCachedProcessor(options);
3460
+ const content = options.children || "";
3461
+ const tree = processor.runSync(processor.parse(content), content);
3462
+ return post(tree, options);
3463
+ };
3464
+ var getCachedProcessor = (options) => {
3465
+ const cached = processorCache.get(options);
3466
+ if (cached) {
3467
+ return cached;
3468
+ }
3469
+ const processor = createProcessor(options);
3470
+ processorCache.set(options, processor);
3471
+ return processor;
3472
+ };
3473
+ var hasRehypeRaw = (plugins) => plugins.some((plugin) => Array.isArray(plugin) ? plugin[0] === rehypeRaw : plugin === rehypeRaw);
3474
+ var createProcessor = (options) => {
3475
+ const rehypePlugins = options.rehypePlugins || EMPTY_PLUGINS;
3476
+ const remarkPlugins = options.remarkPlugins || EMPTY_PLUGINS;
3477
+ const finalRemarkPlugins = hasRehypeRaw(rehypePlugins) ? remarkPlugins : [...remarkPlugins, remarkEscapeHtml];
3478
+ const remarkRehypeOptions = options.remarkRehypeOptions ? {
3479
+ ...DEFAULT_REMARK_REHYPE_OPTIONS,
3480
+ ...options.remarkRehypeOptions
3481
+ } : DEFAULT_REMARK_REHYPE_OPTIONS;
3482
+ return unified().use(remarkParse).use(finalRemarkPlugins).use(remarkRehype, remarkRehypeOptions).use(rehypePlugins);
3483
+ };
3484
+ var defaultUrlTransform = (value) => value;
3485
+ var handleRawNode = (parent, index, skipHtml, value) => {
3486
+ if (skipHtml) {
3487
+ parent.children.splice(index, 1);
3488
+ } else {
3489
+ parent.children[index] = { type: "text", value };
3490
+ }
3491
+ };
3492
+ var transformUrls = (node, transform) => {
3493
+ for (const key in urlAttributes) {
3494
+ if (Object.hasOwn(urlAttributes, key) && Object.hasOwn(node.properties, key)) {
3495
+ const value = node.properties[key];
3496
+ const test = urlAttributes[key];
3497
+ if (test === null || test.includes(node.tagName)) {
3498
+ node.properties[key] = transform(String(value || ""), key, node) ?? void 0;
3499
+ }
3500
+ }
3501
+ }
3502
+ };
3503
+ var shouldRemoveElement = (node, index, parent, allowedElements, disallowedElements, allowElement) => {
3504
+ let remove = false;
3505
+ if (allowedElements) {
3506
+ remove = !allowedElements.includes(node.tagName);
3507
+ } else if (disallowedElements) {
3508
+ remove = disallowedElements.includes(node.tagName);
3509
+ }
3510
+ if (!remove && allowElement && typeof index === "number") {
3511
+ remove = !allowElement(node, index, parent);
3512
+ }
3513
+ return remove;
3514
+ };
3515
+ var jsx = (type, props, key) => createElement2(type, key === void 0 ? props : { ...props, key });
3516
+ var jsxs = jsx;
3517
+ var post = (tree, options) => {
3518
+ const {
3519
+ allowElement,
3520
+ allowedElements,
3521
+ disallowedElements,
3522
+ skipHtml,
3523
+ unwrapDisallowed,
3524
+ urlTransform
3525
+ } = options;
3526
+ const hasFiltering = allowElement || allowedElements || disallowedElements || skipHtml || urlTransform;
3527
+ if (hasFiltering) {
3528
+ const transform = urlTransform || defaultUrlTransform;
3529
+ visit2(tree, (node, index, parent) => {
3530
+ if (node.type === "raw" && parent && typeof index === "number") {
3531
+ handleRawNode(parent, index, skipHtml, node.value);
3532
+ return index;
3533
+ }
3534
+ if (node.type === "element") {
3535
+ transformUrls(node, transform);
3536
+ const remove = shouldRemoveElement(node, index, parent, allowedElements, disallowedElements, allowElement);
3537
+ if (remove && parent && typeof index === "number") {
3538
+ if (unwrapDisallowed && node.children) {
3539
+ parent.children.splice(index, 1, ...node.children);
3540
+ } else {
3541
+ parent.children.splice(index, 1);
3542
+ }
3543
+ return index;
3544
+ }
3545
+ }
3546
+ });
3547
+ }
3548
+ return toJsxRuntime(tree, {
3549
+ Fragment,
3550
+ components: options.components,
3551
+ ignoreInvalidStyle: true,
3552
+ jsx,
3553
+ jsxs,
3554
+ passKeys: true,
3555
+ passNode: true
3556
+ });
3557
+ };
3558
+
3559
+ // src/lib/parse-blocks.tsrx
3560
+ import { Lexer } from "marked";
3561
+ var footnoteReferencePattern = /\[\^[\w-]{1,200}\](?!:)/;
3562
+ var footnoteDefinitionPattern = /\[\^[\w-]{1,200}\]:/;
3563
+ var openingTagPattern = /<(\w+)[\s>]/;
3564
+ var voidElements = /* @__PURE__ */ new Set([
3565
+ "area",
3566
+ "base",
3567
+ "br",
3568
+ "col",
3569
+ "embed",
3570
+ "hr",
3571
+ "img",
3572
+ "input",
3573
+ "link",
3574
+ "meta",
3575
+ "param",
3576
+ "source",
3577
+ "track",
3578
+ "wbr"
3579
+ ]);
3580
+ var openTagPatternCache = /* @__PURE__ */ new Map();
3581
+ var closeTagPatternCache = /* @__PURE__ */ new Map();
3582
+ var getOpenTagPattern = (tagName) => {
3583
+ const normalizedTag = tagName.toLowerCase();
3584
+ const cached = openTagPatternCache.get(normalizedTag);
3585
+ if (cached) {
3586
+ return cached;
3587
+ }
3588
+ const pattern = new RegExp(`<${normalizedTag}(?=[\\s>/])[^>]*>`, "gi");
3589
+ openTagPatternCache.set(normalizedTag, pattern);
3590
+ return pattern;
3591
+ };
3592
+ var getCloseTagPattern = (tagName) => {
3593
+ const normalizedTag = tagName.toLowerCase();
3594
+ const cached = closeTagPatternCache.get(normalizedTag);
3595
+ if (cached) {
3596
+ return cached;
3597
+ }
3598
+ const pattern = new RegExp(`</${normalizedTag}(?=[\\s>])[^>]*>`, "gi");
3599
+ closeTagPatternCache.set(normalizedTag, pattern);
3600
+ return pattern;
3601
+ };
3602
+ var countNonSelfClosingOpenTags = (block, tagName) => {
3603
+ if (voidElements.has(tagName.toLowerCase())) {
3604
+ return 0;
3605
+ }
3606
+ const matches = block.match(getOpenTagPattern(tagName));
3607
+ if (!matches) {
3608
+ return 0;
3609
+ }
3610
+ let count = 0;
3611
+ for (const match of matches) {
3612
+ if (!match.trimEnd().endsWith("/>")) {
3613
+ count += 1;
3614
+ }
3615
+ }
3616
+ return count;
3617
+ };
3618
+ var countClosingTags = (block, tagName) => {
3619
+ const matches = block.match(getCloseTagPattern(tagName));
3620
+ return matches ? matches.length : 0;
3621
+ };
3622
+ var countDoubleDollars = (str) => {
3623
+ let count = 0;
3624
+ for (let i = 0; i < str.length - 1; i += 1) {
3625
+ if (str[i] === "$" && str[i + 1] === "$") {
3626
+ count += 1;
3627
+ i += 1;
3628
+ }
3629
+ }
3630
+ return count;
3631
+ };
3632
+ var parseMarkdownIntoBlocks = (markdown) => {
3633
+ const hasFootnoteReference = footnoteReferencePattern.test(markdown);
3634
+ const hasFootnoteDefinition = footnoteDefinitionPattern.test(markdown);
3635
+ if (hasFootnoteReference || hasFootnoteDefinition) {
3636
+ return [markdown];
3637
+ }
3638
+ const tokens = Lexer.lex(markdown, { gfm: true });
3639
+ const mergedBlocks = [];
3640
+ const htmlStack = [];
3641
+ let previousTokenWasCode = false;
3642
+ for (const token of tokens) {
3643
+ const currentBlock = token.raw;
3644
+ const mergedBlocksLen = mergedBlocks.length;
3645
+ if (htmlStack.length > 0) {
3646
+ mergedBlocks[mergedBlocksLen - 1] += currentBlock;
3647
+ const trackedTag = htmlStack.at(-1);
3648
+ const newOpenTags = countNonSelfClosingOpenTags(currentBlock, trackedTag);
3649
+ const newCloseTags = countClosingTags(currentBlock, trackedTag);
3650
+ for (let i = 0; i < newOpenTags; i += 1) {
3651
+ htmlStack.push(trackedTag);
3652
+ }
3653
+ for (let i = 0; i < newCloseTags; i += 1) {
3654
+ if (htmlStack.length > 0 && htmlStack.at(-1) === trackedTag) {
3655
+ htmlStack.pop();
3656
+ }
3657
+ }
3658
+ continue;
3659
+ }
3660
+ if (token.type === "html" && token.block) {
3661
+ const openingTagMatch = currentBlock.match(openingTagPattern);
3662
+ if (openingTagMatch) {
3663
+ const tagName = openingTagMatch[1];
3664
+ const openTags = countNonSelfClosingOpenTags(currentBlock, tagName);
3665
+ const closeTags = countClosingTags(currentBlock, tagName);
3666
+ if (openTags > closeTags) {
3667
+ htmlStack.push(tagName);
3668
+ }
3669
+ }
3670
+ }
3671
+ if (mergedBlocksLen > 0 && !previousTokenWasCode) {
3672
+ const previousBlock = mergedBlocks[mergedBlocksLen - 1];
3673
+ const prevDollarCount = countDoubleDollars(previousBlock);
3674
+ if (prevDollarCount % 2 === 1) {
3675
+ mergedBlocks[mergedBlocksLen - 1] = previousBlock + currentBlock;
3676
+ continue;
3677
+ }
3678
+ }
3679
+ mergedBlocks.push(currentBlock);
3680
+ if (token.type !== "space") {
3681
+ previousTokenWasCode = token.type === "code";
3682
+ }
3683
+ }
3684
+ return mergedBlocks;
3685
+ };
3686
+
3687
+ // src/lib/preprocess-custom-tags.ts
3688
+ var preprocessCustomTags = (markdown, tagNames) => {
3689
+ if (!tagNames.length) {
3690
+ return markdown;
3691
+ }
3692
+ let result = markdown;
3693
+ for (const tagName of tagNames) {
3694
+ const pattern = new RegExp(
3695
+ `(<${tagName}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${tagName}\\s*>)`,
3696
+ "gi"
3697
+ );
3698
+ result = result.replace(pattern, (_match, open, content, close) => {
3699
+ if (!content.includes("\n\n")) {
3700
+ return open + content + close;
3701
+ }
3702
+ const fixedContent = content.replace(/\n\n/g, "\n<!---->\n");
3703
+ const paddedContent = (fixedContent.startsWith("\n") ? "" : "\n") + fixedContent + (fixedContent.endsWith("\n") ? "" : "\n");
3704
+ return `${open}${paddedContent}${close}
3705
+
3706
+ `;
3707
+ });
3708
+ }
3709
+ return result;
3710
+ };
3711
+
3712
+ // src/lib/preprocess-literal-tag-content.ts
3713
+ var MARKDOWN_ESCAPE_RE = /([\\`*_~[\]|])/g;
3714
+ var escapeMarkdown = (text) => text.replace(MARKDOWN_ESCAPE_RE, "\\$1");
3715
+ var preprocessLiteralTagContent = (markdown, tagNames) => {
3716
+ if (!tagNames.length) {
3717
+ return markdown;
3718
+ }
3719
+ let result = markdown;
3720
+ for (const tagName of tagNames) {
3721
+ const pattern = new RegExp(
3722
+ `(<${tagName}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${tagName}\\s*>)`,
3723
+ "gi"
3724
+ );
3725
+ result = result.replace(pattern, (_match, open, content, close) => {
3726
+ const escaped = escapeMarkdown(content).replace(/\n\n/g, "&#10;&#10;");
3727
+ return open + escaped + close;
3728
+ });
3729
+ }
3730
+ return result;
3731
+ };
3732
+
3733
+ // src/lib/rehype/literal-tag-content.ts
3734
+ import { visit as visit3 } from "unist-util-visit";
3735
+ var collectText = (node) => {
3736
+ if (node.type === "text") {
3737
+ return node.value;
3738
+ }
3739
+ if ("children" in node && Array.isArray(node.children)) {
3740
+ return node.children.map(collectText).join("");
3741
+ }
3742
+ return "";
3743
+ };
3744
+ var rehypeLiteralTagContent = (tagNames) => (tree) => {
3745
+ if (!tagNames || tagNames.length === 0) {
3746
+ return;
3747
+ }
3748
+ const tagSet = new Set(tagNames.map((t) => t.toLowerCase()));
3749
+ visit3(tree, "element", (node) => {
3750
+ if (tagSet.has(node.tagName.toLowerCase())) {
3751
+ const text = collectText(node);
3752
+ node.children = text ? [{ type: "text", value: text }] : [];
3753
+ }
3754
+ });
3755
+ };
3756
+
3757
+ // src/lib/remark/code-meta.ts
3758
+ import { visit as visit4 } from "unist-util-visit";
3759
+ var remarkCodeMeta = () => (tree) => {
3760
+ visit4(tree, "code", (node) => {
3761
+ if (node.meta) {
3762
+ node.data = node.data ?? {};
3763
+ node.data.hProperties = {
3764
+ ...node.data.hProperties ?? {},
3765
+ metastring: node.meta
3766
+ };
3767
+ }
3768
+ });
3769
+ };
3770
+
3771
+ // src/index.tsrx
3772
+ var HTML_BLOCK_START_PATTERN = /^[ \t]*<[\w!/?-]/;
3773
+ var HTML_LINE_INDENT_PATTERN = /(^|\n)[ \t]{4,}(?=<[\w!/?-])/g;
3774
+ var normalizeHtmlIndentation = (content) => {
3775
+ if (typeof content !== "string" || content.length === 0) {
3776
+ return content;
3777
+ }
3778
+ if (!HTML_BLOCK_START_PATTERN.test(content)) {
3779
+ return content;
3780
+ }
3781
+ return content.replace(HTML_LINE_INDENT_PATTERN, "$1");
3782
+ };
3783
+ var defaultSanitizeSchema = {
3784
+ ...defaultSchema,
3785
+ protocols: {
3786
+ ...defaultSchema.protocols,
3787
+ href: [...defaultSchema.protocols?.href ?? [], "tel"]
3788
+ },
3789
+ attributes: {
3790
+ ...defaultSchema.attributes,
3791
+ code: [...defaultSchema.attributes?.code ?? [], "metastring"]
3792
+ }
3793
+ };
3794
+ var defaultRehypePlugins = {
3795
+ raw: rehypeRaw2,
3796
+ sanitize: [rehypeSanitize, defaultSanitizeSchema],
3797
+ harden: [
3798
+ harden,
3799
+ {
3800
+ allowedImagePrefixes: ["*"],
3801
+ allowedLinkPrefixes: ["*"],
3802
+ allowedProtocols: ["*"],
3803
+ defaultOrigin: void 0,
3804
+ allowDataImages: true
3805
+ }
3806
+ ]
3807
+ };
3808
+ var defaultRemarkPlugins = { gfm: [remarkGfm, {}], codeMeta: remarkCodeMeta };
3809
+ var defaultRehypePluginsArray = Object.values(defaultRehypePlugins);
3810
+ var defaultRemarkPluginsArray = Object.values(defaultRemarkPlugins);
3811
+ var carets = { block: " \u258B", circle: " \u25CF" };
3812
+ var defaultShikiTheme = ["github-light", "github-dark"];
3813
+ var defaultLinkSafetyConfig = { enabled: true };
3814
+ var defaultStreamdownContext = {
3815
+ shikiTheme: defaultShikiTheme,
3816
+ controls: true,
3817
+ isAnimating: false,
3818
+ lineNumbers: true,
3819
+ mode: "streaming",
3820
+ mermaid: void 0,
3821
+ linkSafety: defaultLinkSafetyConfig
3822
+ };
3823
+ var StreamdownContext = createContext7(defaultStreamdownContext);
3824
+ var Block = memo3(({
3825
+ content,
3826
+ shouldParseIncompleteMarkdown: _,
3827
+ shouldNormalizeHtmlIndentation,
3828
+ index,
3829
+ isIncomplete,
3830
+ dir,
3831
+ animatePlugin: animatePluginProp,
3832
+ ...props
3833
+ }) => {
3834
+ if (animatePluginProp) {
3835
+ animatePluginProp.setActiveBlock(index);
3836
+ const prevCount = animatePluginProp.getLastRenderCharCount();
3837
+ animatePluginProp.setPrevContentLength(prevCount);
3838
+ }
3839
+ const normalizedContent = typeof content === "string" && shouldNormalizeHtmlIndentation ? normalizeHtmlIndentation(content) : content;
3840
+ const inner = _$createScopedValue19(() => _$createScopedElement17(Markdown, { ...props }, () => normalizedContent));
3841
+ return _$createScopedValue19(() => _$createScopedElement17(BlockIncompleteContext.Provider, { value: isIncomplete }, () => dir ? _$createScopedValue19(() => _$createScopedElement17("div", { dir, style: { display: "contents" } }, () => inner)) : inner));
3842
+ });
3843
+ Object.assign(Block, { displayName: "Block" });
3844
+ var Streamdown = memo3(({
3845
+ children,
3846
+ mode = "streaming",
3847
+ dir,
3848
+ parseIncompleteMarkdown: shouldParseIncompleteMarkdown = true,
3849
+ normalizeHtmlIndentation: shouldNormalizeHtmlIndentation = false,
3850
+ components: components2,
3851
+ rehypePlugins = defaultRehypePluginsArray,
3852
+ remarkPlugins = defaultRemarkPluginsArray,
3853
+ className,
3854
+ shikiTheme = defaultShikiTheme,
3855
+ mermaid,
3856
+ controls = true,
3857
+ isAnimating = false,
3858
+ animated,
3859
+ BlockComponent = Block,
3860
+ parseMarkdownIntoBlocksFn = parseMarkdownIntoBlocks,
3861
+ caret,
3862
+ plugins,
3863
+ remend: remendOptions,
3864
+ linkSafety = defaultLinkSafetyConfig,
3865
+ lineNumbers = true,
3866
+ allowedTags,
3867
+ literalTagContent,
3868
+ translations,
3869
+ icons: iconOverrides,
3870
+ prefix,
3871
+ onAnimationStart,
3872
+ onAnimationEnd,
3873
+ ...props
3874
+ }) => {
3875
+ const generatedId = useId();
3876
+ const [_isPending, startTransition] = useTransition();
3877
+ const prefixedCn = useMemo4(() => createCn(prefix), [prefix]);
3878
+ const prevIsAnimatingRef = useRef8(null);
3879
+ const onAnimationStartRef = useRef8(onAnimationStart);
3880
+ const onAnimationEndRef = useRef8(onAnimationEnd);
3881
+ onAnimationStartRef.current = onAnimationStart;
3882
+ onAnimationEndRef.current = onAnimationEnd;
3883
+ useEffect10(
3884
+ () => {
3885
+ if (mode === "static") {
3886
+ return;
3887
+ }
3888
+ const prev = prevIsAnimatingRef.current;
3889
+ prevIsAnimatingRef.current = isAnimating;
3890
+ if (prev === null) {
3891
+ if (isAnimating) {
3892
+ onAnimationStartRef.current?.();
3893
+ }
3894
+ return;
3895
+ }
3896
+ if (isAnimating && !prev) {
3897
+ onAnimationStartRef.current?.();
3898
+ } else if (!isAnimating && prev) {
3899
+ onAnimationEndRef.current?.();
3900
+ }
3901
+ },
3902
+ [isAnimating, mode]
3903
+ );
3904
+ const allowedTagNames = useMemo4(() => allowedTags ? Object.keys(allowedTags) : [], [allowedTags]);
3905
+ const processedChildren = useMemo4(
3906
+ () => {
3907
+ if (typeof children !== "string") {
3908
+ return "";
3909
+ }
3910
+ let result = mode === "streaming" && shouldParseIncompleteMarkdown ? remend(children, remendOptions) : children;
3911
+ if (literalTagContent && literalTagContent.length > 0) {
3912
+ result = preprocessLiteralTagContent(result, literalTagContent);
3913
+ }
3914
+ if (allowedTagNames.length > 0) {
3915
+ result = preprocessCustomTags(result, allowedTagNames);
3916
+ }
3917
+ return result;
3918
+ },
3919
+ [
3920
+ children,
3921
+ mode,
3922
+ shouldParseIncompleteMarkdown,
3923
+ remendOptions,
3924
+ allowedTagNames,
3925
+ literalTagContent
3926
+ ]
3927
+ );
3928
+ const blocks = useMemo4(() => parseMarkdownIntoBlocksFn(processedChildren), [processedChildren, parseMarkdownIntoBlocksFn]);
3929
+ const [displayBlocks, setDisplayBlocks] = useState11(blocks);
3930
+ useEffect10(
3931
+ () => {
3932
+ if (mode === "streaming" && !animatePlugin) {
3933
+ startTransition(() => {
3934
+ setDisplayBlocks(blocks);
3935
+ });
3936
+ } else {
3937
+ setDisplayBlocks(blocks);
3938
+ }
3939
+ },
3940
+ [blocks, mode]
3941
+ );
3942
+ const blocksToRender = mode === "streaming" ? displayBlocks : blocks;
3943
+ const blockDirections = useMemo4(() => dir === "auto" ? blocksToRender.map(detectTextDirection) : void 0, [blocksToRender, dir]);
3944
+ const blockKeys = useMemo4(() => blocksToRender.map((_block, idx) => `${generatedId}-${idx}`), [blocksToRender.length, generatedId]);
3945
+ const animatedKey = useMemo4(
3946
+ () => {
3947
+ if (animated === true) {
3948
+ return "true";
3949
+ }
3950
+ if (animated) {
3951
+ return JSON.stringify(animated);
3952
+ }
3953
+ return "";
3954
+ },
3955
+ [animated]
3956
+ );
3957
+ const animatePlugin = useMemo4(
3958
+ () => {
3959
+ if (!animatedKey) {
3960
+ return null;
3961
+ }
3962
+ if (animatedKey === "true") {
3963
+ return createAnimatePlugin();
3964
+ }
3965
+ return createAnimatePlugin(animated);
3966
+ },
3967
+ [animatedKey]
3968
+ );
3969
+ const contextValue = useMemo4(
3970
+ () => ({
3971
+ shikiTheme: plugins?.code?.getThemes() ?? shikiTheme,
3972
+ controls,
3973
+ isAnimating,
3974
+ lineNumbers,
3975
+ mode,
3976
+ mermaid,
3977
+ linkSafety
3978
+ }),
3979
+ [
3980
+ shikiTheme,
3981
+ controls,
3982
+ isAnimating,
3983
+ lineNumbers,
3984
+ mode,
3985
+ mermaid,
3986
+ linkSafety,
3987
+ plugins?.code
3988
+ ]
3989
+ );
3990
+ const translationsKey = useMemo4(() => translations ? JSON.stringify(translations) : "", [translations]);
3991
+ const translationsValue = useMemo4(() => ({ ...defaultTranslations, ...translations }), [translationsKey]);
3992
+ const mergedComponents = useMemo4(
3993
+ () => {
3994
+ const { inlineCode, ...userComponents } = components2 ?? {};
3995
+ const merged = { ...components, ...userComponents };
3996
+ if (inlineCode) {
3997
+ const BlockCode = merged.code;
3998
+ merged.code = (props2) => {
3999
+ const isInline = !("data-block" in props2);
4000
+ if (isInline) {
4001
+ return createElement3(inlineCode, props2);
4002
+ }
4003
+ return BlockCode ? createElement3(BlockCode, props2) : null;
4004
+ };
4005
+ }
4006
+ return merged;
4007
+ },
4008
+ [components2]
4009
+ );
4010
+ const mergedRemarkPlugins = useMemo4(
4011
+ () => {
4012
+ let result = [];
4013
+ if (plugins?.cjk) {
4014
+ result = [...result, ...plugins.cjk.remarkPluginsBefore];
4015
+ }
4016
+ result = [...result, ...remarkPlugins];
4017
+ if (plugins?.cjk) {
4018
+ result = [...result, ...plugins.cjk.remarkPluginsAfter];
4019
+ }
4020
+ if (plugins?.math) {
4021
+ result = [...result, plugins.math.remarkPlugin];
4022
+ }
4023
+ return result;
4024
+ },
4025
+ [remarkPlugins, plugins?.math, plugins?.cjk]
4026
+ );
4027
+ const mergedRehypePlugins = useMemo4(
4028
+ () => {
4029
+ let result = rehypePlugins;
4030
+ if (allowedTags && Object.keys(allowedTags).length > 0 && rehypePlugins === defaultRehypePluginsArray) {
4031
+ const extendedSchema = {
4032
+ ...defaultSanitizeSchema,
4033
+ tagNames: [
4034
+ ...defaultSanitizeSchema.tagNames ?? [],
4035
+ ...Object.keys(allowedTags)
4036
+ ],
4037
+ attributes: { ...defaultSanitizeSchema.attributes, ...allowedTags }
4038
+ };
4039
+ result = [
4040
+ defaultRehypePlugins.raw,
4041
+ [rehypeSanitize, extendedSchema],
4042
+ defaultRehypePlugins.harden
4043
+ ];
4044
+ }
4045
+ if (literalTagContent && literalTagContent.length > 0) {
4046
+ result = [...result, [rehypeLiteralTagContent, literalTagContent]];
4047
+ }
4048
+ if (plugins?.math) {
4049
+ result = [...result, plugins.math.rehypePlugin];
4050
+ }
4051
+ if (animatePlugin && isAnimating) {
4052
+ result = [...result, animatePlugin.rehypePlugin];
4053
+ }
4054
+ return result;
4055
+ },
4056
+ [
4057
+ rehypePlugins,
4058
+ plugins?.math,
4059
+ animatePlugin,
4060
+ isAnimating,
4061
+ allowedTags,
4062
+ literalTagContent
4063
+ ]
4064
+ );
4065
+ const shouldHideCaret = useMemo4(
4066
+ () => {
4067
+ if (!isAnimating || blocksToRender.length === 0) {
4068
+ return false;
4069
+ }
4070
+ const lastBlock = blocksToRender.at(-1);
4071
+ return hasIncompleteCodeFence(lastBlock) || hasTable(lastBlock);
4072
+ },
4073
+ [isAnimating, blocksToRender]
4074
+ );
4075
+ const style = useMemo4(
4076
+ () => caret && isAnimating && !shouldHideCaret ? { "--streamdown-caret": `"${carets[caret]}"` } : void 0,
4077
+ [caret, isAnimating, shouldHideCaret]
4078
+ );
4079
+ if (mode === "static") {
4080
+ animatePlugin?.setActiveBlock("static");
4081
+ return _$createScopedValue19(() => _$createScopedElement17(TranslationsContext.Provider, { value: translationsValue }, () => _$createScopedValue19(() => _$createScopedElement17(PluginContext.Provider, { value: plugins ?? null }, () => _$createScopedValue19(() => _$createScopedElement17(StreamdownContext.Provider, { value: contextValue }, () => _$createScopedValue19(() => _$createScopedElement17(IconProvider, { icons: iconOverrides }, () => _$createScopedValue19(() => _$createScopedElement17(PrefixContext.Provider, { value: prefixedCn }, () => _$createScopedValue19(() => _$createScopedElement17(
4082
+ "div",
4083
+ {
4084
+ className: prefixedCn("space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0", className),
4085
+ dir: dir === "auto" ? detectTextDirection(processedChildren) : dir
4086
+ },
4087
+ () => _$createScopedValue19(() => _$createScopedElement17(
4088
+ Markdown,
4089
+ {
4090
+ components: mergedComponents,
4091
+ rehypePlugins: mergedRehypePlugins,
4092
+ remarkPlugins: mergedRemarkPlugins,
4093
+ ...props
4094
+ },
4095
+ () => processedChildren
4096
+ ))
4097
+ ))))))))))));
4098
+ }
4099
+ return _$createScopedValue19(() => _$createScopedElement17(TranslationsContext.Provider, { value: translationsValue }, () => _$createScopedValue19(() => _$createScopedElement17(PluginContext.Provider, { value: plugins ?? null }, () => _$createScopedValue19(() => _$createScopedElement17(StreamdownContext.Provider, { value: contextValue }, () => _$createScopedValue19(() => _$createScopedElement17(IconProvider, { icons: iconOverrides }, () => _$createScopedValue19(() => _$createScopedElement17(PrefixContext.Provider, { value: prefixedCn }, () => _$createScopedValue19(() => _$createScopedElement17(
4100
+ "div",
4101
+ {
4102
+ className: prefixedCn(
4103
+ "space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
4104
+ caret && !shouldHideCaret ? "[&>*:last-child]:after:inline [&>*:last-child]:after:align-baseline [&>*:last-child]:after:content-[var(--streamdown-caret)]" : null,
4105
+ className
4106
+ ),
4107
+ style
4108
+ },
4109
+ () => _$positionalChildren12([
4110
+ blocksToRender.length === 0 && caret && isAnimating && _$createElement16("span", {}),
4111
+ blocksToRender.map((block, index) => {
4112
+ const isLastBlock = index === blocksToRender.length - 1;
4113
+ const isIncomplete = isAnimating && isLastBlock && hasIncompleteCodeFence(block);
4114
+ return _$createElement16(BlockComponent, {
4115
+ animatePlugin,
4116
+ components: mergedComponents,
4117
+ content: block,
4118
+ dir: blockDirections?.[index] ?? (dir !== "auto" ? dir : void 0),
4119
+ index,
4120
+ isIncomplete,
4121
+ key: blockKeys[index],
4122
+ rehypePlugins: mergedRehypePlugins,
4123
+ remarkPlugins: mergedRemarkPlugins,
4124
+ shouldNormalizeHtmlIndentation,
4125
+ shouldParseIncompleteMarkdown,
4126
+ ...props
4127
+ });
4128
+ })
4129
+ ])
4130
+ ))))))))))));
4131
+ });
4132
+ Object.assign(Streamdown, { displayName: "Streamdown" });
4133
+
4134
+ // src/lib/mermaid/pan-zoom.tsrx
4135
+ import {
4136
+ createElement as _$createElement17,
4137
+ createScopedElement as _$createScopedElement18,
4138
+ createScopedValue as _$createScopedValue20,
4139
+ positionalChildren as _$positionalChildren13,
4140
+ useCallback as useCallback4,
4141
+ useEffect as useEffect11,
4142
+ useRef as useRef9,
4143
+ useState as useState12
4144
+ } from "octane/server";
4145
+ var PanZoom = ({
4146
+ children,
4147
+ className,
4148
+ minZoom = 0.5,
4149
+ maxZoom = 3,
4150
+ zoomStep = 0.1,
4151
+ showControls = true,
4152
+ initialZoom = 1,
4153
+ fullscreen = false
4154
+ }) => {
4155
+ const { RotateCcwIcon: RotateCcwIcon2, ZoomInIcon: ZoomInIcon2, ZoomOutIcon: ZoomOutIcon2 } = useIcons();
4156
+ const cn2 = useCn();
4157
+ const containerRef = useRef9(null);
4158
+ const contentRef = useRef9(null);
4159
+ const [zoom, setZoom] = useState12(initialZoom);
4160
+ const [pan, setPan] = useState12({ x: 0, y: 0 });
4161
+ const [isPanning, setIsPanning] = useState12(false);
4162
+ const [panStart, setPanStart] = useState12({ x: 0, y: 0 });
4163
+ const [panStartPosition, setPanStartPosition] = useState12({ x: 0, y: 0 });
4164
+ const handleZoom = useCallback4(
4165
+ (delta) => {
4166
+ setZoom((prevZoom) => {
4167
+ const newZoom = Math.max(minZoom, Math.min(maxZoom, prevZoom + delta));
4168
+ return newZoom;
4169
+ });
4170
+ },
4171
+ [minZoom, maxZoom]
4172
+ );
4173
+ const handleZoomIn = useCallback4(
4174
+ () => {
4175
+ handleZoom(zoomStep);
4176
+ },
4177
+ [handleZoom, zoomStep]
4178
+ );
4179
+ const handleZoomOut = useCallback4(
4180
+ () => {
4181
+ handleZoom(-zoomStep);
4182
+ },
4183
+ [handleZoom, zoomStep]
4184
+ );
4185
+ const handleReset = useCallback4(
4186
+ () => {
4187
+ setZoom(initialZoom);
4188
+ setPan({ x: 0, y: 0 });
4189
+ },
4190
+ [initialZoom]
4191
+ );
4192
+ const handleWheel = useCallback4(
4193
+ (e) => {
4194
+ e.preventDefault();
4195
+ const delta = e.deltaY > 0 ? -zoomStep : zoomStep;
4196
+ handleZoom(delta);
4197
+ },
4198
+ [handleZoom, zoomStep]
4199
+ );
4200
+ const handlePointerDown = useCallback4(
4201
+ (e) => {
4202
+ if (e.button !== 0 || e.isPrimary === false) {
4203
+ return;
4204
+ }
4205
+ setIsPanning(true);
4206
+ setPanStart({ x: e.clientX, y: e.clientY });
4207
+ setPanStartPosition(pan);
4208
+ const target = e.currentTarget;
4209
+ if (target instanceof HTMLElement) {
4210
+ target.setPointerCapture(e.pointerId);
4211
+ }
4212
+ },
4213
+ [pan]
4214
+ );
4215
+ const handlePointerMove = useCallback4(
4216
+ (e) => {
4217
+ if (!isPanning) {
4218
+ return;
4219
+ }
4220
+ e.preventDefault();
4221
+ const deltaX = e.clientX - panStart.x;
4222
+ const deltaY = e.clientY - panStart.y;
4223
+ setPan({
4224
+ x: panStartPosition.x + deltaX,
4225
+ y: panStartPosition.y + deltaY
4226
+ });
4227
+ },
4228
+ [isPanning, panStart, panStartPosition]
4229
+ );
4230
+ const handlePointerUp = useCallback4(
4231
+ (e) => {
4232
+ setIsPanning(false);
4233
+ const target = e.currentTarget;
4234
+ if (target instanceof HTMLElement) {
4235
+ target.releasePointerCapture(e.pointerId);
4236
+ }
4237
+ },
4238
+ []
4239
+ );
4240
+ useEffect11(
4241
+ () => {
4242
+ const container = containerRef.current;
4243
+ if (!container) {
4244
+ return;
4245
+ }
4246
+ container.addEventListener("wheel", handleWheel, { passive: false });
4247
+ return () => {
4248
+ container.removeEventListener("wheel", handleWheel);
4249
+ };
4250
+ },
4251
+ [handleWheel]
4252
+ );
4253
+ useEffect11(
4254
+ () => {
4255
+ const content = contentRef.current;
4256
+ if (!content) {
4257
+ return;
4258
+ }
4259
+ if (isPanning) {
4260
+ document.body.style.userSelect = "none";
4261
+ content.addEventListener("pointermove", handlePointerMove, { passive: false });
4262
+ content.addEventListener("pointerup", handlePointerUp);
4263
+ content.addEventListener("pointercancel", handlePointerUp);
4264
+ return () => {
4265
+ document.body.style.userSelect = "";
4266
+ content.removeEventListener("pointermove", handlePointerMove);
4267
+ content.removeEventListener("pointerup", handlePointerUp);
4268
+ content.removeEventListener("pointercancel", handlePointerUp);
4269
+ };
4270
+ }
4271
+ },
4272
+ [isPanning, handlePointerMove, handlePointerUp]
4273
+ );
4274
+ return _$createScopedValue20(() => _$createScopedElement18(
4275
+ "div",
4276
+ {
4277
+ className: cn2("relative flex flex-col", fullscreen ? "h-full w-full" : "min-h-28 w-full", className),
4278
+ ref: containerRef,
4279
+ style: { cursor: isPanning ? "grabbing" : "grab" }
4280
+ },
4281
+ () => _$positionalChildren13([
4282
+ showControls ? _$createScopedValue20(() => _$createScopedElement18(
4283
+ "div",
4284
+ {
4285
+ className: cn2("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/80 p-1 supports-[backdrop-filter]:bg-background/70 supports-[backdrop-filter]:backdrop-blur-sm", fullscreen ? "bottom-4 left-4" : "bottom-2 left-2")
4286
+ },
4287
+ () => _$positionalChildren13([
4288
+ _$createScopedValue20(() => _$createScopedElement18(
4289
+ "button",
4290
+ {
4291
+ className: cn2("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),
4292
+ disabled: zoom >= maxZoom,
4293
+ onClick: handleZoomIn,
4294
+ title: "Zoom in",
4295
+ type: "button"
4296
+ },
4297
+ () => _$createElement17(ZoomInIcon2, { size: 16 })
4298
+ )),
4299
+ _$createScopedValue20(() => _$createScopedElement18(
4300
+ "button",
4301
+ {
4302
+ className: cn2("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),
4303
+ disabled: zoom <= minZoom,
4304
+ onClick: handleZoomOut,
4305
+ title: "Zoom out",
4306
+ type: "button"
4307
+ },
4308
+ () => _$createElement17(ZoomOutIcon2, { size: 16 })
4309
+ )),
4310
+ _$createScopedValue20(() => _$createScopedElement18(
4311
+ "button",
4312
+ {
4313
+ className: cn2("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"),
4314
+ onClick: handleReset,
4315
+ title: "Reset zoom and pan",
4316
+ type: "button"
4317
+ },
4318
+ () => _$createElement17(RotateCcwIcon2, { size: 16 })
4319
+ ))
4320
+ ])
4321
+ )) : null,
4322
+ _$createScopedValue20(() => _$createScopedElement18(
4323
+ "div",
4324
+ {
4325
+ className: cn2("flex-1 origin-center transition-transform duration-150 ease-out", fullscreen ? "flex h-full w-full items-center justify-center" : "flex w-full items-center justify-center"),
4326
+ onPointerDown: handlePointerDown,
4327
+ ref: contentRef,
4328
+ role: "application",
4329
+ style: {
4330
+ transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`,
4331
+ transformOrigin: "center center",
4332
+ touchAction: "none",
4333
+ willChange: "transform"
4334
+ }
4335
+ },
4336
+ () => children
4337
+ ))
4338
+ ])
4339
+ ));
4340
+ };
4341
+
4342
+ // src/lib/mermaid/index.tsrx
4343
+ var Mermaid = ({
4344
+ chart,
4345
+ className,
4346
+ config,
4347
+ fullscreen = false,
4348
+ showControls = true
4349
+ }) => {
4350
+ const cn2 = useCn();
4351
+ const [error, setError] = useState13(null);
4352
+ const [isLoading, setIsLoading] = useState13(false);
4353
+ const [svgContent, setSvgContent] = useState13("");
4354
+ const [lastValidSvg, setLastValidSvg] = useState13("");
4355
+ const [retryCount, setRetryCount] = useState13(0);
4356
+ const activeRenderRef = useRef10(null);
4357
+ const { mermaid: mermaidContext } = useContext15(StreamdownContext);
4358
+ const mermaidPlugin = useMermaidPlugin();
4359
+ const ErrorComponent = mermaidContext?.errorComponent;
4360
+ const { shouldRender, containerRef } = useDeferredRender({ immediate: fullscreen });
4361
+ useEffect12(
4362
+ () => {
4363
+ const renderRequest = {};
4364
+ activeRenderRef.current = renderRequest;
4365
+ const cancelRender = () => {
4366
+ if (activeRenderRef.current === renderRequest) {
4367
+ activeRenderRef.current = null;
4368
+ }
4369
+ };
4370
+ if (!shouldRender) {
4371
+ return cancelRender;
4372
+ }
4373
+ if (!mermaidPlugin) {
4374
+ setIsLoading(false);
4375
+ setError("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");
4376
+ return cancelRender;
4377
+ }
4378
+ const renderChart = async () => {
4379
+ try {
4380
+ setError(null);
4381
+ setIsLoading(true);
4382
+ const mermaid = mermaidPlugin.getMermaid(config);
4383
+ const chartHash = chart.split("").reduce(
4384
+ (acc, char) => {
4385
+ return (acc << 5) - acc + char.charCodeAt(0) | 0;
4386
+ },
4387
+ 0
4388
+ );
4389
+ const uniqueId = `mermaid-${Math.abs(chartHash)}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
4390
+ const { svg } = await mermaid.render(uniqueId, chart);
4391
+ if (activeRenderRef.current !== renderRequest) {
4392
+ return;
4393
+ }
4394
+ setSvgContent(svg);
4395
+ setLastValidSvg(svg);
4396
+ } catch (err) {
4397
+ if (activeRenderRef.current !== renderRequest) {
4398
+ return;
4399
+ }
4400
+ if (!(lastValidSvg || svgContent)) {
4401
+ const errorMessage = err instanceof Error ? err.message : "Failed to render Mermaid chart";
4402
+ setError(errorMessage);
4403
+ }
4404
+ } finally {
4405
+ if (activeRenderRef.current === renderRequest) {
4406
+ setIsLoading(false);
4407
+ }
4408
+ }
4409
+ };
4410
+ renderChart();
4411
+ return cancelRender;
4412
+ },
4413
+ [chart, config, retryCount, shouldRender, mermaidPlugin]
4414
+ );
4415
+ if (!(shouldRender || svgContent || lastValidSvg)) {
4416
+ return _$createScopedValue21(() => _$createElement18("div", {
4417
+ className: cn2("my-4 min-h-[200px]", className),
4418
+ ref: containerRef
4419
+ }));
4420
+ }
4421
+ if (isLoading && !svgContent && !lastValidSvg) {
4422
+ return _$createScopedValue21(() => _$createScopedElement19(
4423
+ "div",
4424
+ {
4425
+ className: cn2("my-4 flex justify-center p-4", className),
4426
+ ref: containerRef
4427
+ },
4428
+ () => _$createScopedValue21(() => _$createScopedElement19(
4429
+ "div",
4430
+ {
4431
+ className: cn2("flex items-center space-x-2 text-muted-foreground")
4432
+ },
4433
+ () => _$positionalChildren14([
4434
+ _$createScopedValue21(() => _$createElement18("div", {
4435
+ className: cn2("h-4 w-4 animate-spin rounded-full border-current border-b-2")
4436
+ })),
4437
+ _$createScopedValue21(() => _$createElement18("span", { className: cn2("text-sm") }, "Loading diagram..."))
4438
+ ])
4439
+ ))
4440
+ ));
4441
+ }
4442
+ if (error && !svgContent && !lastValidSvg) {
4443
+ const retry = () => setRetryCount((count) => count + 1);
4444
+ if (ErrorComponent) {
4445
+ return _$createScopedValue21(() => _$createScopedElement19("div", { ref: containerRef }, () => _$createScopedValue21(() => _$createElement18(ErrorComponent, { chart, error, retry }))));
4446
+ }
4447
+ return _$createScopedValue21(() => _$createScopedElement19(
4448
+ "div",
4449
+ {
4450
+ className: cn2("rounded-md bg-red-50 p-4", className),
4451
+ ref: containerRef
4452
+ },
4453
+ () => _$positionalChildren14([
4454
+ _$createScopedValue21(() => _$createScopedElement19("p", { className: cn2("font-mono text-red-700 text-sm") }, () => _$positionalChildren14(["\n Mermaid Error:\n ", error]))),
4455
+ _$createScopedValue21(() => _$createScopedElement19("details", { className: cn2("mt-2") }, () => _$positionalChildren14([
4456
+ _$createScopedValue21(() => _$createElement18("summary", { className: cn2("cursor-pointer text-red-600 text-xs") }, "\n Show Code\n ")),
4457
+ _$createScopedValue21(() => _$createScopedElement19(
4458
+ "pre",
4459
+ {
4460
+ className: cn2("mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs")
4461
+ },
4462
+ () => chart
4463
+ ))
4464
+ ])))
4465
+ ])
4466
+ ));
4467
+ }
4468
+ const displaySvg = svgContent || lastValidSvg;
4469
+ return _$createScopedValue21(() => _$createScopedElement19(
4470
+ "div",
4471
+ {
4472
+ className: cn2("size-full", className),
4473
+ "data-streamdown": "mermaid",
4474
+ ref: containerRef
4475
+ },
4476
+ () => _$createScopedValue21(() => _$createScopedElement19(
4477
+ PanZoom,
4478
+ {
4479
+ className: cn2(fullscreen ? "size-full overflow-hidden" : "overflow-hidden", className),
4480
+ fullscreen,
4481
+ maxZoom: 3,
4482
+ minZoom: 0.5,
4483
+ showControls,
4484
+ zoomStep: 0.1
4485
+ },
4486
+ () => _$createScopedValue21(() => _$createElement18("div", {
4487
+ "aria-label": "Mermaid chart",
4488
+ className: cn2("flex justify-center", fullscreen ? "size-full items-center" : null),
4489
+ dangerouslySetInnerHTML: { __html: displaySvg },
4490
+ role: "img"
4491
+ }))
4492
+ ))
4493
+ ));
4494
+ };
4495
+
4496
+ export {
4497
+ createAnimatePlugin,
4498
+ useIsCodeFenceIncomplete,
4499
+ CodeBlockBody,
4500
+ CodeBlockContainer,
4501
+ CodeBlockHeader,
4502
+ useCodePlugin,
4503
+ CodeBlock,
4504
+ defaultTranslations,
4505
+ CodeBlockCopyButton,
4506
+ CodeBlockDownloadButton,
4507
+ CodeBlockSkeleton,
4508
+ Mermaid,
4509
+ extractTableDataFromElement,
4510
+ tableDataToCSV,
4511
+ tableDataToTSV,
4512
+ escapeMarkdownTableCell,
4513
+ tableDataToMarkdown,
4514
+ TableCopyDropdown,
4515
+ TableDownloadButton,
4516
+ TableDownloadDropdown,
4517
+ detectTextDirection,
4518
+ defaultUrlTransform,
4519
+ parseMarkdownIntoBlocks,
4520
+ normalizeHtmlIndentation,
4521
+ defaultRehypePlugins,
4522
+ defaultRemarkPlugins,
4523
+ StreamdownContext,
4524
+ Block,
4525
+ Streamdown
4526
+ };