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