@superlc/md-react 0.1.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -1,347 +1,953 @@
1
- import { jsxs as B, jsx as o, Fragment as E } from "react/jsx-runtime";
2
- import Q, { useMemo as P, memo as F, useRef as d, useState as T, useCallback as N, useEffect as y, useLayoutEffect as ee } from "react";
3
- import { parseToHast as te, createStreamingParser as V, OutputRateController as J } from "@superlc/md-core";
1
+ import { jsxs as C, jsx as e, Fragment as H } from "react/jsx-runtime";
2
+ import U, { useState as E, useCallback as p, useRef as k, useEffect as z, useMemo as O, memo as P, useLayoutEffect as me } from "react";
3
+ import { detectColorScheme as fe, observeColorScheme as he, downloadAsPng as pe, MermaidRenderer as be, parseToHast as J, createStreamingParser as Q, OutputRateController as ee } from "@superlc/md-core";
4
4
  import { toJsxRuntime as W } from "hast-util-to-jsx-runtime";
5
- function re(e, t = {}) {
6
- const { components: c = {}, ...a } = t;
7
- return P(() => {
8
- if (!e) return null;
9
- const r = te(e, a);
10
- return W(r, {
11
- Fragment: E,
12
- jsx: o,
13
- jsxs: B,
14
- components: c
5
+ async function ve(t) {
6
+ try {
7
+ return await navigator.clipboard.writeText(t), !0;
8
+ } catch {
9
+ return ge(t);
10
+ }
11
+ }
12
+ function ge(t) {
13
+ const n = document.createElement("textarea");
14
+ n.value = t, n.style.position = "fixed", n.style.left = "-9999px", document.body.appendChild(n), n.select();
15
+ try {
16
+ return document.execCommand("copy"), !0;
17
+ } catch {
18
+ return !1;
19
+ } finally {
20
+ document.body.removeChild(n);
21
+ }
22
+ }
23
+ const ye = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" }) }), we = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }), K = ({
24
+ children: t,
25
+ showCopyButton: n = !0,
26
+ onCopy: c,
27
+ className: l
28
+ }) => {
29
+ const [a, i] = E(!1), o = p(async () => {
30
+ const r = j(t);
31
+ await ve(r) && (i(!0), c == null || c(r), setTimeout(() => i(!1), 2e3));
32
+ }, [t, c]);
33
+ return /* @__PURE__ */ C("div", { className: `md-code-block-wrapper${l ? ` ${l}` : ""}`, children: [
34
+ /* @__PURE__ */ e("pre", { children: t }),
35
+ n && /* @__PURE__ */ e(
36
+ "button",
37
+ {
38
+ type: "button",
39
+ className: `md-copy-button${a ? " md-copy-button--copied" : ""}`,
40
+ onClick: o,
41
+ title: a ? "已复制" : "复制代码",
42
+ "aria-label": a ? "已复制" : "复制代码",
43
+ children: a ? /* @__PURE__ */ e(we, {}) : /* @__PURE__ */ e(ye, {})
44
+ }
45
+ )
46
+ ] });
47
+ };
48
+ function j(t) {
49
+ return typeof t == "string" ? t : typeof t == "number" ? String(t) : Array.isArray(t) ? t.map(j).join("") : U.isValidElement(t) ? j(t.props.children) : "";
50
+ }
51
+ K.displayName = "CodeBlock";
52
+ const ke = {
53
+ min: 0.25,
54
+ max: 4,
55
+ step: 0.25,
56
+ default: 1
57
+ };
58
+ function te(t = {}) {
59
+ const {
60
+ config: n,
61
+ enableDrag: c = !1,
62
+ enableWheelZoom: l = !1
63
+ } = t, a = { ...ke, ...n }, i = k(null), o = k(!1), r = k({ x: 0, y: 0 }), b = k({ x: 0, y: 0 }), [u, f] = E({
64
+ scale: a.default,
65
+ translateX: 0,
66
+ translateY: 0
67
+ }), d = p(
68
+ (s) => Math.max(a.min, Math.min(a.max, s)),
69
+ [a.min, a.max]
70
+ ), v = p(() => {
71
+ f((s) => ({
72
+ ...s,
73
+ scale: d(s.scale + a.step)
74
+ }));
75
+ }, [d, a.step]), h = p(() => {
76
+ f((s) => ({
77
+ ...s,
78
+ scale: d(s.scale - a.step)
79
+ }));
80
+ }, [d, a.step]), g = p(() => {
81
+ f({
82
+ scale: a.default,
83
+ translateX: 0,
84
+ translateY: 0
15
85
  });
16
- }, [e, c, a]);
86
+ }, [a.default]), x = p(
87
+ (s) => {
88
+ f((w) => ({
89
+ ...w,
90
+ scale: d(s)
91
+ }));
92
+ },
93
+ [d]
94
+ ), V = p(
95
+ (s, w) => {
96
+ const L = s.width / w.width, D = s.height / w.height, F = Math.min(L, D) * 0.95;
97
+ f({
98
+ scale: d(F),
99
+ translateX: 0,
100
+ translateY: 0
101
+ });
102
+ },
103
+ [d]
104
+ ), y = p(
105
+ (s) => {
106
+ c && (s.preventDefault(), o.current = !0, r.current = { x: s.clientX, y: s.clientY }, b.current = { x: u.translateX, y: u.translateY });
107
+ },
108
+ [c, u.translateX, u.translateY]
109
+ );
110
+ z(() => {
111
+ if (!c) return;
112
+ const s = (L) => {
113
+ if (!o.current) return;
114
+ const D = L.clientX - r.current.x, F = L.clientY - r.current.y;
115
+ f((m) => ({
116
+ ...m,
117
+ translateX: b.current.x + D,
118
+ translateY: b.current.y + F
119
+ }));
120
+ }, w = () => {
121
+ o.current = !1;
122
+ };
123
+ return document.addEventListener("mousemove", s), document.addEventListener("mouseup", w), () => {
124
+ document.removeEventListener("mousemove", s), document.removeEventListener("mouseup", w);
125
+ };
126
+ }, [c]);
127
+ const I = p(
128
+ (s) => {
129
+ if (!l) return;
130
+ s.preventDefault();
131
+ const w = s.deltaY > 0 ? -a.step : a.step;
132
+ f((L) => ({
133
+ ...L,
134
+ scale: d(L.scale + w)
135
+ }));
136
+ },
137
+ [l, a.step, d]
138
+ ), B = p(() => {
139
+ g();
140
+ }, [g]), T = {
141
+ transform: `translate(${u.translateX}px, ${u.translateY}px) scale(${u.scale})`,
142
+ transformOrigin: "center center",
143
+ transition: o.current ? "none" : "transform 0.2s ease-out",
144
+ cursor: c ? o.current ? "grabbing" : "grab" : "default"
145
+ };
146
+ return {
147
+ state: u,
148
+ zoomIn: v,
149
+ zoomOut: h,
150
+ reset: g,
151
+ fitToContainer: V,
152
+ setScale: x,
153
+ canZoomIn: u.scale < a.max,
154
+ canZoomOut: u.scale > a.min,
155
+ containerRef: i,
156
+ contentStyle: T,
157
+ handlers: {
158
+ onMouseDown: y,
159
+ onWheel: I,
160
+ onDoubleClick: B
161
+ }
162
+ };
163
+ }
164
+ const Ce = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z" }) }), xe = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z" }) }), ne = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zm.5-7H9v2H7v1h2v2h1v-2h2V9h-2V7z" }) }), re = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7V9z" }) }), ae = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z" }) }), Ne = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" }) }), Me = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z" }) }), ce = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" }) }), Se = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }) }), ze = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" }) }), Le = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }), se = ({
165
+ svg: t,
166
+ open: n,
167
+ onClose: c,
168
+ onDownload: l
169
+ }) => {
170
+ const a = k(null), i = k(null), o = k(null), [r, b] = E(!1), {
171
+ state: u,
172
+ zoomIn: f,
173
+ zoomOut: d,
174
+ reset: v,
175
+ fitToContainer: h,
176
+ canZoomIn: g,
177
+ canZoomOut: x,
178
+ contentStyle: V,
179
+ handlers: y
180
+ } = te({
181
+ enableDrag: !0,
182
+ enableWheelZoom: !0
183
+ }), I = p(async () => {
184
+ if (a.current)
185
+ try {
186
+ await a.current.requestFullscreen(), b(!0);
187
+ } catch {
188
+ b(!0);
189
+ }
190
+ }, []), B = p(() => {
191
+ document.fullscreenElement && document.exitFullscreen().catch(() => {
192
+ }), b(!1), c();
193
+ }, [c]);
194
+ z(() => {
195
+ n ? I() : r && B();
196
+ }, [n, I, B, r]), z(() => {
197
+ const s = () => {
198
+ !document.fullscreenElement && r && (b(!1), c());
199
+ };
200
+ return document.addEventListener("fullscreenchange", s), () => document.removeEventListener("fullscreenchange", s);
201
+ }, [r, c]), z(() => {
202
+ if (!r) return;
203
+ const s = (w) => {
204
+ switch (w.key) {
205
+ case "+":
206
+ case "=":
207
+ f();
208
+ break;
209
+ case "-":
210
+ d();
211
+ break;
212
+ case "0":
213
+ v();
214
+ break;
215
+ }
216
+ };
217
+ return document.addEventListener("keydown", s), () => document.removeEventListener("keydown", s);
218
+ }, [r, f, d, v]);
219
+ const T = p(() => {
220
+ if (!i.current || !o.current) return;
221
+ const s = i.current.getBoundingClientRect(), w = o.current.querySelector("svg");
222
+ if (w) {
223
+ const L = w.getBoundingClientRect();
224
+ h(s, L);
225
+ }
226
+ }, [h]);
227
+ return /* @__PURE__ */ e(
228
+ "div",
229
+ {
230
+ ref: a,
231
+ className: `md-mermaid-fullscreen-wrapper${r ? " md-mermaid-fullscreen-wrapper--active" : ""}`,
232
+ role: "dialog",
233
+ "aria-modal": "true",
234
+ "aria-label": "Mermaid 图表全屏预览",
235
+ "aria-hidden": !r,
236
+ children: r && /* @__PURE__ */ C(H, { children: [
237
+ /* @__PURE__ */ C("div", { className: "md-mermaid-fullscreen-toolbar", children: [
238
+ /* @__PURE__ */ C("div", { className: "md-mermaid-toolbar-group", children: [
239
+ /* @__PURE__ */ e(
240
+ "button",
241
+ {
242
+ type: "button",
243
+ className: "md-mermaid-toolbar-btn",
244
+ onClick: d,
245
+ disabled: !x,
246
+ title: "缩小 (-)",
247
+ "aria-label": "缩小",
248
+ children: /* @__PURE__ */ e(re, {})
249
+ }
250
+ ),
251
+ /* @__PURE__ */ C("span", { className: "md-mermaid-zoom-label", children: [
252
+ Math.round(u.scale * 100),
253
+ "%"
254
+ ] }),
255
+ /* @__PURE__ */ e(
256
+ "button",
257
+ {
258
+ type: "button",
259
+ className: "md-mermaid-toolbar-btn",
260
+ onClick: f,
261
+ disabled: !g,
262
+ title: "放大 (+)",
263
+ "aria-label": "放大",
264
+ children: /* @__PURE__ */ e(ne, {})
265
+ }
266
+ ),
267
+ /* @__PURE__ */ e("span", { className: "md-mermaid-toolbar-divider" }),
268
+ /* @__PURE__ */ e(
269
+ "button",
270
+ {
271
+ type: "button",
272
+ className: "md-mermaid-toolbar-btn",
273
+ onClick: v,
274
+ title: "重置 (0)",
275
+ "aria-label": "重置",
276
+ children: /* @__PURE__ */ e(ae, {})
277
+ }
278
+ ),
279
+ /* @__PURE__ */ e(
280
+ "button",
281
+ {
282
+ type: "button",
283
+ className: "md-mermaid-toolbar-btn",
284
+ onClick: T,
285
+ title: "适应窗口",
286
+ "aria-label": "适应窗口",
287
+ children: /* @__PURE__ */ e(Me, {})
288
+ }
289
+ )
290
+ ] }),
291
+ /* @__PURE__ */ C("div", { className: "md-mermaid-toolbar-group", children: [
292
+ l && /* @__PURE__ */ e(
293
+ "button",
294
+ {
295
+ type: "button",
296
+ className: "md-mermaid-toolbar-btn",
297
+ onClick: l,
298
+ title: "下载 PNG",
299
+ "aria-label": "下载",
300
+ children: /* @__PURE__ */ e(ce, {})
301
+ }
302
+ ),
303
+ /* @__PURE__ */ e(
304
+ "button",
305
+ {
306
+ type: "button",
307
+ className: "md-mermaid-toolbar-btn",
308
+ onClick: B,
309
+ title: "退出全屏 (Esc)",
310
+ "aria-label": "退出全屏",
311
+ children: /* @__PURE__ */ e(Se, {})
312
+ }
313
+ )
314
+ ] })
315
+ ] }),
316
+ /* @__PURE__ */ e(
317
+ "div",
318
+ {
319
+ ref: i,
320
+ className: "md-mermaid-fullscreen-content",
321
+ onWheel: y.onWheel,
322
+ children: /* @__PURE__ */ e(
323
+ "div",
324
+ {
325
+ ref: o,
326
+ className: "md-mermaid-fullscreen-svg",
327
+ style: V,
328
+ onMouseDown: y.onMouseDown,
329
+ onDoubleClick: y.onDoubleClick,
330
+ dangerouslySetInnerHTML: { __html: t }
331
+ }
332
+ )
333
+ }
334
+ )
335
+ ] })
336
+ }
337
+ );
338
+ };
339
+ se.displayName = "MermaidFullscreenViewer";
340
+ let Z = null;
341
+ function Ie(t = "auto") {
342
+ return Z ? Z.setTheme(t ?? "auto") : Z = new be({ theme: t }), Z;
17
343
  }
18
- const ne = ({
19
- children: e,
20
- components: t,
344
+ async function Ee(t) {
345
+ try {
346
+ return await navigator.clipboard.writeText(t), !0;
347
+ } catch {
348
+ const n = document.createElement("textarea");
349
+ n.value = t, n.style.position = "fixed", n.style.left = "-9999px", document.body.appendChild(n), n.select();
350
+ try {
351
+ return document.execCommand("copy"), !0;
352
+ } catch {
353
+ return !1;
354
+ } finally {
355
+ document.body.removeChild(n);
356
+ }
357
+ }
358
+ }
359
+ const oe = ({
360
+ code: t,
361
+ theme: n = "auto",
362
+ showToolbar: c = !0,
363
+ onCopy: l,
364
+ className: a
365
+ }) => {
366
+ const [i, o] = E("preview"), [r, b] = E(null), [u, f] = E(!0), [d, v] = E(!1), [h, g] = E(!1), x = k(null), [V, y] = E(() => fe()), {
367
+ state: I,
368
+ zoomIn: B,
369
+ zoomOut: T,
370
+ reset: s,
371
+ canZoomIn: w,
372
+ canZoomOut: L,
373
+ contentStyle: D
374
+ } = te();
375
+ z(() => {
376
+ if (n === "auto")
377
+ return he((S) => {
378
+ y(S);
379
+ });
380
+ }, [n]), z(() => {
381
+ let S = !1;
382
+ return (async () => {
383
+ f(!0);
384
+ const $ = await Ie(n).render(t);
385
+ S || (b($), f(!1), $.success || o("code"));
386
+ })(), () => {
387
+ S = !0;
388
+ };
389
+ }, [t, n, V]);
390
+ const F = p(async () => {
391
+ await Ee(t) && (g(!0), l == null || l(t), setTimeout(() => g(!1), 2e3));
392
+ }, [t, l]), m = p(async () => {
393
+ var S;
394
+ if (r != null && r.svg)
395
+ try {
396
+ const A = ((S = window.matchMedia) == null ? void 0 : S.call(window, "(prefers-color-scheme: dark)").matches) ?? !1;
397
+ await pe(r.svg, {
398
+ backgroundColor: A ? "#1a1a2e" : "#ffffff",
399
+ padding: 20,
400
+ scale: 2
401
+ });
402
+ } catch (A) {
403
+ console.error("Download failed:", A);
404
+ }
405
+ }, [r]), N = p(() => {
406
+ v((S) => !S);
407
+ }, []), M = (r == null ? void 0 : r.success) && r.svg;
408
+ return /* @__PURE__ */ C("div", { className: `md-mermaid-block${a ? ` ${a}` : ""}`, children: [
409
+ c && /* @__PURE__ */ C("div", { className: "md-mermaid-toolbar", children: [
410
+ /* @__PURE__ */ C("div", { className: "md-mermaid-toolbar-group md-mermaid-mode-switch", children: [
411
+ /* @__PURE__ */ e(
412
+ "button",
413
+ {
414
+ type: "button",
415
+ className: `md-mermaid-toolbar-btn${i === "preview" ? " md-mermaid-toolbar-btn--active" : ""}`,
416
+ onClick: () => o("preview"),
417
+ disabled: !M,
418
+ title: "图片模式",
419
+ "aria-label": "图片模式",
420
+ children: /* @__PURE__ */ e(Ce, {})
421
+ }
422
+ ),
423
+ /* @__PURE__ */ e(
424
+ "button",
425
+ {
426
+ type: "button",
427
+ className: `md-mermaid-toolbar-btn${i === "code" ? " md-mermaid-toolbar-btn--active" : ""}`,
428
+ onClick: () => o("code"),
429
+ title: "代码模式",
430
+ "aria-label": "代码模式",
431
+ children: /* @__PURE__ */ e(xe, {})
432
+ }
433
+ )
434
+ ] }),
435
+ i === "preview" && M && /* @__PURE__ */ C("div", { className: "md-mermaid-toolbar-group", children: [
436
+ /* @__PURE__ */ e(
437
+ "button",
438
+ {
439
+ type: "button",
440
+ className: "md-mermaid-toolbar-btn",
441
+ onClick: T,
442
+ disabled: !L,
443
+ title: "缩小",
444
+ "aria-label": "缩小",
445
+ children: /* @__PURE__ */ e(re, {})
446
+ }
447
+ ),
448
+ /* @__PURE__ */ C("span", { className: "md-mermaid-zoom-label", children: [
449
+ Math.round(I.scale * 100),
450
+ "%"
451
+ ] }),
452
+ /* @__PURE__ */ e(
453
+ "button",
454
+ {
455
+ type: "button",
456
+ className: "md-mermaid-toolbar-btn",
457
+ onClick: B,
458
+ disabled: !w,
459
+ title: "放大",
460
+ "aria-label": "放大",
461
+ children: /* @__PURE__ */ e(ne, {})
462
+ }
463
+ ),
464
+ /* @__PURE__ */ e(
465
+ "button",
466
+ {
467
+ type: "button",
468
+ className: "md-mermaid-toolbar-btn",
469
+ onClick: s,
470
+ title: "重置",
471
+ "aria-label": "重置缩放",
472
+ children: /* @__PURE__ */ e(ae, {})
473
+ }
474
+ )
475
+ ] }),
476
+ /* @__PURE__ */ C("div", { className: "md-mermaid-toolbar-group", children: [
477
+ i === "preview" && M && /* @__PURE__ */ C(H, { children: [
478
+ /* @__PURE__ */ e(
479
+ "button",
480
+ {
481
+ type: "button",
482
+ className: "md-mermaid-toolbar-btn",
483
+ onClick: N,
484
+ title: "全屏",
485
+ "aria-label": "全屏查看",
486
+ children: /* @__PURE__ */ e(Ne, {})
487
+ }
488
+ ),
489
+ /* @__PURE__ */ e(
490
+ "button",
491
+ {
492
+ type: "button",
493
+ className: "md-mermaid-toolbar-btn",
494
+ onClick: m,
495
+ title: "下载 PNG",
496
+ "aria-label": "下载",
497
+ children: /* @__PURE__ */ e(ce, {})
498
+ }
499
+ )
500
+ ] }),
501
+ i === "code" && /* @__PURE__ */ e(
502
+ "button",
503
+ {
504
+ type: "button",
505
+ className: `md-mermaid-toolbar-btn${h ? " md-mermaid-toolbar-btn--success" : ""}`,
506
+ onClick: F,
507
+ title: h ? "已复制" : "复制代码",
508
+ "aria-label": h ? "已复制" : "复制代码",
509
+ children: h ? /* @__PURE__ */ e(Le, {}) : /* @__PURE__ */ e(ze, {})
510
+ }
511
+ )
512
+ ] })
513
+ ] }),
514
+ /* @__PURE__ */ e("div", { className: "md-mermaid-content", ref: x, children: u ? (
515
+ // Loading 骨架屏
516
+ /* @__PURE__ */ e("div", { className: "md-mermaid-skeleton", children: /* @__PURE__ */ e("div", { className: "md-mermaid-skeleton-box" }) })
517
+ ) : i === "preview" && M && (r != null && r.svg) ? (
518
+ // 图片模式
519
+ /* @__PURE__ */ e("div", { className: "md-mermaid-preview", style: { overflow: "hidden" }, children: /* @__PURE__ */ e(
520
+ "div",
521
+ {
522
+ className: "md-mermaid-svg-container",
523
+ style: D,
524
+ dangerouslySetInnerHTML: { __html: r.svg }
525
+ }
526
+ ) })
527
+ ) : (
528
+ // 代码模式
529
+ /* @__PURE__ */ C("div", { className: "md-mermaid-code", children: [
530
+ /* @__PURE__ */ e("pre", { children: /* @__PURE__ */ e("code", { className: "language-mermaid", children: t }) }),
531
+ r && !r.success && /* @__PURE__ */ C("div", { className: "md-mermaid-error", children: [
532
+ /* @__PURE__ */ e("span", { children: "渲染失败: " }),
533
+ /* @__PURE__ */ e("span", { children: r.error })
534
+ ] })
535
+ ] })
536
+ ) }),
537
+ M && (r == null ? void 0 : r.svg) && /* @__PURE__ */ e(
538
+ se,
539
+ {
540
+ svg: r.svg,
541
+ open: d,
542
+ onClose: () => v(!1),
543
+ onDownload: m
544
+ }
545
+ )
546
+ ] });
547
+ };
548
+ oe.displayName = "MermaidBlock";
549
+ function Ve(t) {
550
+ const n = t.children;
551
+ if (!U.isValidElement(n)) return !1;
552
+ const c = n.props, l = c == null ? void 0 : c.className;
553
+ return typeof l == "string" ? l.includes("language-mermaid") : !1;
554
+ }
555
+ function Re(t) {
556
+ if (!U.isValidElement(t)) return "";
557
+ const n = t.props, c = n == null ? void 0 : n.children;
558
+ return typeof c == "string" ? c : Array.isArray(c) ? c.map((l) => typeof l == "string" ? l : "").join("") : "";
559
+ }
560
+ function Be(t) {
561
+ return t ? t === !0 ? { enabled: !0 } : t.enabled !== !1 ? t : null : null;
562
+ }
563
+ const Te = ({
564
+ children: t,
565
+ components: n,
21
566
  className: c,
22
- ...a
567
+ copyButton: l = !0,
568
+ onCodeCopy: a,
569
+ mermaid: i,
570
+ ...o
23
571
  }) => {
24
- const r = re(e, { components: t, ...a });
25
- return /* @__PURE__ */ o("div", { className: c, children: r });
572
+ const r = Be(i), b = O(() => {
573
+ if (!t) return null;
574
+ const u = J(t, o), d = {
575
+ pre: (v) => {
576
+ if (r && Ve(v)) {
577
+ const h = Re(v.children);
578
+ return /* @__PURE__ */ e(
579
+ oe,
580
+ {
581
+ code: h,
582
+ theme: r.theme,
583
+ onCopy: a
584
+ }
585
+ );
586
+ }
587
+ return l ? /* @__PURE__ */ e(K, { showCopyButton: l, onCopy: a, ...v }) : /* @__PURE__ */ e("pre", { ...v });
588
+ },
589
+ ...n
590
+ };
591
+ return W(u, {
592
+ Fragment: H,
593
+ jsx: e,
594
+ jsxs: C,
595
+ components: d
596
+ });
597
+ }, [t, n, l, a, r, o]);
598
+ return /* @__PURE__ */ e("div", { className: c, children: b });
26
599
  };
27
- ne.displayName = "Markdown";
28
- const X = F(
29
- ({ block: e, components: t }) => {
30
- if (!e.hast) return null;
600
+ Te.displayName = "Markdown";
601
+ function We(t, n = {}) {
602
+ const { components: c = {}, ...l } = n;
603
+ return O(() => {
604
+ if (!t) return null;
605
+ const a = J(t, l);
606
+ return W(a, {
607
+ Fragment: H,
608
+ jsx: e,
609
+ jsxs: C,
610
+ components: c
611
+ });
612
+ }, [t, c, l]);
613
+ }
614
+ const le = P(
615
+ ({ block: t, components: n }) => {
616
+ if (!t.hast) return null;
31
617
  try {
32
- return W(e.hast, {
33
- jsx: o,
34
- jsxs: B,
35
- Fragment: E,
36
- components: t
618
+ return W(t.hast, {
619
+ jsx: e,
620
+ jsxs: C,
621
+ Fragment: H,
622
+ components: n
37
623
  });
38
624
  } catch {
39
625
  return null;
40
626
  }
41
627
  },
42
- (e, t) => e.block.key === t.block.key && e.block.stable && t.block.stable
628
+ (t, n) => t.block.key === n.block.key && t.block.stable && n.block.stable
43
629
  );
44
- X.displayName = "StableBlock";
45
- function ge(e = {}) {
630
+ le.displayName = "StableBlock";
631
+ function _e(t = {}) {
46
632
  const {
47
- components: t,
633
+ components: n,
48
634
  minUpdateInterval: c = 16,
49
- immediate: a = !1,
50
- outputRate: r = "medium",
51
- ...g
52
- } = e, s = d(V(g)), n = d(new J(r)), [x, p] = T(0), [b, k] = T(!1), [u, l] = T(0), [L, v] = T("idle"), A = d(0), m = d(null), S = N(() => {
53
- const h = performance.now(), D = h - A.current;
54
- a || D >= c ? (A.current = h, p((H) => H + 1)) : m.current === null && (m.current = window.requestAnimationFrame(() => {
55
- m.current = null, A.current = performance.now(), p((H) => H + 1);
635
+ immediate: l = !1,
636
+ outputRate: a = "medium",
637
+ ...i
638
+ } = t, o = k(Q(i)), r = k(new ee(a)), [b, u] = E(0), [f, d] = E(!1), [v, h] = E(0), [g, x] = E("idle"), V = k(0), y = k(null), I = p(() => {
639
+ const R = performance.now(), $ = R - V.current;
640
+ l || $ >= c ? (V.current = R, u((_) => _ + 1)) : y.current === null && (y.current = window.requestAnimationFrame(() => {
641
+ y.current = null, V.current = performance.now(), u((_) => _ + 1);
56
642
  }));
57
- }, [c, a]), R = N(
58
- (h) => {
59
- s.current.append(h), S();
643
+ }, [c, l]), B = p(
644
+ (R) => {
645
+ o.current.append(R), I();
60
646
  },
61
- [S]
62
- ), M = N(
63
- (h) => {
64
- s.current.reset(), k(!1), l(0), v("running"), n.current.start(
65
- h,
66
- (D) => {
67
- D && s.current.append(D), l(n.current.progress), S();
647
+ [I]
648
+ ), T = p(
649
+ (R) => {
650
+ o.current.reset(), d(!1), h(0), x("running"), r.current.start(
651
+ R,
652
+ ($) => {
653
+ $ && o.current.append($), h(r.current.progress), I();
68
654
  },
69
655
  () => {
70
- s.current.finish(), k(!0), l(1), v("complete"), S();
656
+ o.current.finish(), d(!0), h(1), x("complete"), I();
71
657
  }
72
658
  );
73
659
  },
74
- [S]
75
- ), I = N(() => {
76
- n.current.pause(), v(n.current.status);
77
- }, []), j = N(() => {
78
- n.current.resume(), v(n.current.status);
79
- }, []), $ = N(() => {
80
- n.current.skipToEnd(), v(n.current.status), l(1);
81
- }, []), i = N(() => {
82
- n.current.stop(), s.current.finish(), k(!0), v("complete"), m.current !== null && (cancelAnimationFrame(m.current), m.current = null), p((h) => h + 1);
83
- }, []), f = N(() => {
84
- n.current.stop(), s.current.reset(), k(!1), l(0), v("idle"), m.current !== null && (cancelAnimationFrame(m.current), m.current = null), p((h) => h + 1);
660
+ [I]
661
+ ), s = p(() => {
662
+ r.current.pause(), x(r.current.status);
663
+ }, []), w = p(() => {
664
+ r.current.resume(), x(r.current.status);
665
+ }, []), L = p(() => {
666
+ r.current.skipToEnd(), x(r.current.status), h(1);
667
+ }, []), D = p(() => {
668
+ r.current.stop(), o.current.finish(), d(!0), x("complete"), y.current !== null && (cancelAnimationFrame(y.current), y.current = null), u((R) => R + 1);
669
+ }, []), F = p(() => {
670
+ r.current.stop(), o.current.reset(), d(!1), h(0), x("idle"), y.current !== null && (cancelAnimationFrame(y.current), y.current = null), u((R) => R + 1);
85
671
  }, []);
86
- y(() => {
87
- n.current.setRate(r);
88
- }, [r]), y(() => () => {
89
- n.current.stop(), m.current !== null && cancelAnimationFrame(m.current);
672
+ z(() => {
673
+ r.current.setRate(a);
674
+ }, [a]), z(() => () => {
675
+ r.current.stop(), y.current !== null && cancelAnimationFrame(y.current);
90
676
  }, []);
91
- const w = s.current.getState(), z = s.current.getStats(), C = s.current.getContent(), _ = P(() => w.blocks.map(
92
- (h) => o(
93
- X,
677
+ const m = o.current.getState(), N = o.current.getStats(), M = o.current.getContent(), S = O(() => m.blocks.map(
678
+ (R) => e(
679
+ le,
94
680
  {
95
- block: h,
96
- components: t
681
+ block: R,
682
+ components: n
97
683
  },
98
- h.key
684
+ R.key
99
685
  )
100
- ), [w.blocks, t, x]);
686
+ ), [m.blocks, n, b]);
101
687
  return {
102
- element: P(() => w.blocks.length === 0 ? null : o(E, { children: _ }), [_, w.blocks.length]),
103
- append: R,
104
- start: M,
105
- pause: I,
106
- resume: j,
107
- skipToEnd: $,
108
- reset: f,
109
- finish: i,
110
- blocks: w.blocks,
111
- stats: z,
112
- isComplete: b,
113
- content: C,
114
- progress: u,
115
- outputStatus: L
688
+ element: O(() => m.blocks.length === 0 ? null : e(H, { children: S }), [S, m.blocks.length]),
689
+ append: B,
690
+ start: T,
691
+ pause: s,
692
+ resume: w,
693
+ skipToEnd: L,
694
+ reset: F,
695
+ finish: D,
696
+ blocks: m.blocks,
697
+ stats: N,
698
+ isComplete: f,
699
+ content: M,
700
+ progress: v,
701
+ outputStatus: g
116
702
  };
117
703
  }
118
- const se = 16, ce = "data:image/svg+xml,", ae = () => /* @__PURE__ */ B("svg", { width: "48", height: "36", viewBox: "0 0 48 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
119
- /* @__PURE__ */ o("rect", { x: "0", y: "0", width: "48", height: "36", rx: "3", className: "md-image-skeleton-icon" }),
120
- /* @__PURE__ */ o("circle", { cx: "12", cy: "10", r: "5", className: "md-image-skeleton-icon-detail" }),
121
- /* @__PURE__ */ o("path", { d: "M0 36 L0 24 L16 16 L28 26 L48 12 L48 36 Z", className: "md-image-skeleton-icon-detail" })
122
- ] }), Y = F(({
123
- src: e,
124
- alt: t,
704
+ const De = 16, Fe = "data:image/svg+xml,", He = () => /* @__PURE__ */ C("svg", { width: "48", height: "36", viewBox: "0 0 48 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
705
+ /* @__PURE__ */ e("rect", { x: "0", y: "0", width: "48", height: "36", rx: "3", className: "md-image-skeleton-icon" }),
706
+ /* @__PURE__ */ e("circle", { cx: "12", cy: "10", r: "5", className: "md-image-skeleton-icon-detail" }),
707
+ /* @__PURE__ */ e("path", { d: "M0 36 L0 24 L16 16 L28 26 L48 12 L48 36 Z", className: "md-image-skeleton-icon-detail" })
708
+ ] }), ie = P(({
709
+ src: t,
710
+ alt: n,
125
711
  className: c,
126
- "data-width": a,
127
- "data-height": r,
128
- ...g
712
+ "data-width": l,
713
+ "data-height": a,
714
+ ...i
129
715
  }) => {
130
- const n = (e == null ? void 0 : e.startsWith(ce)) ? void 0 : e, x = a ? Number(a) : 200, p = r ? Number(r) : 120, [b, k] = T(!0), u = d(null), l = d(null);
131
- ee(() => {
132
- u.current && n && u.current.complete && u.current.naturalWidth > 0 && k(!1);
133
- }, [n]);
134
- const L = N(() => {
135
- l.current && clearTimeout(l.current), l.current = setTimeout(() => {
136
- k(!1);
137
- }, se);
716
+ const r = (t == null ? void 0 : t.startsWith(Fe)) ? void 0 : t, b = l ? Number(l) : 200, u = a ? Number(a) : 120, [f, d] = E(!0), v = k(null), h = k(null);
717
+ me(() => {
718
+ v.current && r && v.current.complete && v.current.naturalWidth > 0 && d(!1);
719
+ }, [r]);
720
+ const g = p(() => {
721
+ h.current && clearTimeout(h.current), h.current = setTimeout(() => {
722
+ d(!1);
723
+ }, De);
138
724
  }, []);
139
- return /* @__PURE__ */ B(
725
+ return /* @__PURE__ */ C(
140
726
  "span",
141
727
  {
142
728
  className: `md-image-container ${c || ""}`,
143
- style: { width: x, height: p },
729
+ style: { width: b, height: u },
144
730
  children: [
145
- n && /* @__PURE__ */ o(
731
+ r && /* @__PURE__ */ e(
146
732
  "img",
147
733
  {
148
- ref: u,
149
- src: n,
150
- alt: t,
151
- onLoad: L,
734
+ ref: v,
735
+ src: r,
736
+ alt: n,
737
+ onLoad: g,
152
738
  className: "md-image",
153
- ...g
739
+ ...i
154
740
  }
155
741
  ),
156
- b && /* @__PURE__ */ o("span", { className: "md-image-skeleton", children: /* @__PURE__ */ o(ae, {}) })
742
+ f && /* @__PURE__ */ e("span", { className: "md-image-skeleton", children: /* @__PURE__ */ e(He, {}) })
157
743
  ]
158
744
  }
159
745
  );
160
746
  });
161
- Y.displayName = "StreamingImage";
162
- let K = !1, O = null;
163
- async function Z() {
164
- if (!K)
165
- return O || (O = (async () => {
166
- await import("katex/dist/katex.min.css"), K = !0;
167
- })(), O);
747
+ ie.displayName = "StreamingImage";
748
+ let q = !1, Y = null;
749
+ async function ue() {
750
+ if (!q)
751
+ return Y || (Y = (async () => {
752
+ await import("katex/dist/katex.min.css"), q = !0;
753
+ })(), Y);
168
754
  }
169
- const ie = F(({ children: e }) => (y(() => {
170
- K || Z();
171
- }, []), /* @__PURE__ */ o(E, { children: e })));
172
- ie.displayName = "MathProvider";
173
- function oe() {
174
- return Z();
755
+ const Ae = P(({ children: t }) => (z(() => {
756
+ q || ue();
757
+ }, []), /* @__PURE__ */ e(H, { children: t })));
758
+ Ae.displayName = "MathProvider";
759
+ function $e() {
760
+ return ue();
175
761
  }
176
- const G = F(
177
- ({ block: e, components: t }) => {
178
- if (!e.hast) return null;
762
+ const de = P(
763
+ ({ block: t, components: n }) => {
764
+ if (!t.hast) return null;
179
765
  try {
180
- return W(e.hast, {
181
- jsx: o,
182
- jsxs: B,
183
- Fragment: E,
184
- components: t
766
+ return W(t.hast, {
767
+ jsx: e,
768
+ jsxs: C,
769
+ Fragment: H,
770
+ components: n
185
771
  });
186
772
  } catch {
187
- return /* @__PURE__ */ o("div", { className: "parse-error", children: e.source });
773
+ return /* @__PURE__ */ e("div", { className: "parse-error", children: t.source });
188
774
  }
189
775
  },
190
- (e, t) => e.block.key === t.block.key && e.block.stable && t.block.stable
776
+ (t, n) => t.block.key === n.block.key && t.block.stable && n.block.stable
191
777
  );
192
- G.displayName = "StableBlock";
193
- const ue = ({
194
- content: e,
195
- source: t,
778
+ de.displayName = "StableBlock";
779
+ const Oe = ({
780
+ content: t,
781
+ source: n,
196
782
  outputRate: c = "medium",
197
- isComplete: a = !1,
198
- onComplete: r,
199
- onBlockStable: g,
200
- onProgress: s,
201
- components: n,
202
- className: x,
203
- minUpdateInterval: p = 16,
204
- autoStart: b = !0,
205
- ...k
783
+ isComplete: l = !1,
784
+ onComplete: a,
785
+ onBlockStable: i,
786
+ onProgress: o,
787
+ components: r,
788
+ className: b,
789
+ minUpdateInterval: u = 16,
790
+ autoStart: f = !0,
791
+ copyButton: d = !0,
792
+ onCodeCopy: v,
793
+ ...h
206
794
  }) => {
207
- y(() => {
208
- k.math && oe();
209
- }, [k.math]);
210
- const u = d(V(k)), l = d(new J(c)), L = d(""), v = d(void 0), A = d([]), [, m] = Q.useReducer((i) => i + 1, 0), S = d(0), R = d(null), M = () => {
211
- const i = performance.now();
212
- i - S.current >= p ? (S.current = i, m()) : R.current === null && (R.current = window.requestAnimationFrame(() => {
213
- R.current = null, S.current = performance.now(), m();
795
+ z(() => {
796
+ h.math && $e();
797
+ }, [h.math]);
798
+ const g = k(Q(h)), x = k(new ee(c)), V = k(""), y = k(void 0), I = k([]), [, B] = U.useReducer((m) => m + 1, 0), T = k(0), s = k(null), w = () => {
799
+ const m = performance.now();
800
+ m - T.current >= u ? (T.current = m, B()) : s.current === null && (s.current = window.requestAnimationFrame(() => {
801
+ s.current = null, T.current = performance.now(), B();
214
802
  }));
215
803
  };
216
- y(() => {
217
- t !== void 0 && t !== v.current && (v.current = t, b && t && (u.current.reset(), L.current = "", l.current.start(
218
- t,
219
- (i) => {
220
- i && (u.current.append(i), L.current += i), s == null || s(l.current.progress), M();
804
+ z(() => {
805
+ n !== void 0 && n !== y.current && (y.current = n, f && n && (g.current.reset(), V.current = "", x.current.start(
806
+ n,
807
+ (m) => {
808
+ m && (g.current.append(m), V.current += m), o == null || o(x.current.progress), w();
221
809
  },
222
810
  () => {
223
- u.current.finish(), r == null || r(), M();
811
+ g.current.finish(), a == null || a(), w();
224
812
  }
225
813
  )));
226
- }, [t, b, r, s]), y(() => {
227
- if (t !== void 0)
814
+ }, [n, f, a, o]), z(() => {
815
+ if (n !== void 0)
228
816
  return;
229
- const i = L.current, f = e || "";
230
- if (f !== i) {
231
- if (f.startsWith(i)) {
232
- const w = f.slice(i.length);
233
- w && u.current.append(w);
817
+ const m = V.current, N = t || "";
818
+ if (N !== m) {
819
+ if (N.startsWith(m)) {
820
+ const M = N.slice(m.length);
821
+ M && g.current.append(M);
234
822
  } else
235
- u.current.reset(), f && u.current.append(f);
236
- L.current = f, M();
823
+ g.current.reset(), N && g.current.append(N);
824
+ V.current = N, w();
237
825
  }
238
- }, [e, t]), y(() => {
239
- t === void 0 && a && (u.current.finish(), R.current !== null && (cancelAnimationFrame(R.current), R.current = null), m(), r == null || r());
240
- }, [a, r, t]), y(() => {
241
- l.current.setRate(c);
242
- }, [c]), y(() => {
243
- if (g) {
244
- const i = u.current.getState().blocks, f = A.current;
245
- i.forEach((w, z) => {
246
- const C = f[z];
247
- w.stable && (!C || !C.stable) && g(w);
248
- }), A.current = i;
826
+ }, [t, n]), z(() => {
827
+ n === void 0 && l && (g.current.finish(), s.current !== null && (cancelAnimationFrame(s.current), s.current = null), B(), a == null || a());
828
+ }, [l, a, n]), z(() => {
829
+ x.current.setRate(c);
830
+ }, [c]), z(() => {
831
+ if (i) {
832
+ const m = g.current.getState().blocks, N = I.current;
833
+ m.forEach((M, S) => {
834
+ const A = N[S];
835
+ M.stable && (!A || !A.stable) && i(M);
836
+ }), I.current = m;
249
837
  }
250
- }), y(() => () => {
251
- l.current.stop(), R.current !== null && cancelAnimationFrame(R.current);
838
+ }), z(() => () => {
839
+ x.current.stop(), s.current !== null && cancelAnimationFrame(s.current);
252
840
  }, []);
253
- const I = u.current.getState(), j = t !== void 0 ? l.current.status === "complete" : a, $ = P(() => {
254
- const i = {
255
- img: Y,
256
- ...n
841
+ const L = g.current.getState(), D = n !== void 0 ? x.current.status === "complete" : l, F = O(() => {
842
+ const m = (N) => {
843
+ if (d)
844
+ return (M) => /* @__PURE__ */ e(
845
+ K,
846
+ {
847
+ showCopyButton: N.stable && d,
848
+ onCopy: v,
849
+ ...M
850
+ }
851
+ );
257
852
  };
258
- return I.blocks.map((f) => /* @__PURE__ */ o(
259
- G,
260
- {
261
- block: f,
262
- components: i
263
- },
264
- f.key
265
- ));
266
- }, [I.blocks, n]);
267
- return /* @__PURE__ */ o("div", { className: x, "data-streaming": !j, children: $ });
853
+ return L.blocks.map((N) => {
854
+ const M = m(N), S = {
855
+ img: ie,
856
+ ...M ? { pre: M } : {},
857
+ ...r
858
+ };
859
+ return /* @__PURE__ */ e(
860
+ de,
861
+ {
862
+ block: N,
863
+ components: S
864
+ },
865
+ N.key
866
+ );
867
+ });
868
+ }, [L.blocks, r, d, v]);
869
+ return /* @__PURE__ */ e("div", { className: b, "data-streaming": !D, children: F });
268
870
  };
269
- ue.displayName = "StreamingMarkdown";
270
- const le = F((e) => {
271
- const { text: t, animationConfig: c } = e, { fadeDuration: a = 200, easing: r = "ease-in-out" } = c || {}, [g, s] = T([]), n = d("");
272
- y(() => {
273
- if (t === n.current) return;
274
- if (!(n.current && t.indexOf(n.current) === 0)) {
275
- s([t]), n.current = t;
871
+ Oe.displayName = "StreamingMarkdown";
872
+ const Pe = P((t) => {
873
+ const { text: n, animationConfig: c } = t, { fadeDuration: l = 200, easing: a = "ease-in-out" } = c || {}, [i, o] = E([]), r = k("");
874
+ z(() => {
875
+ if (n === r.current) return;
876
+ if (!(r.current && n.indexOf(r.current) === 0)) {
877
+ o([n]), r.current = n;
276
878
  return;
277
879
  }
278
- const p = t.slice(n.current.length);
279
- p && (s((b) => [...b, p]), n.current = t);
280
- }, [t]);
281
- const x = `md-fade-in ${a}ms ${r} forwards`;
282
- return /* @__PURE__ */ o(E, { children: g.map((p, b) => /* @__PURE__ */ o(
880
+ const u = n.slice(r.current.length);
881
+ u && (o((f) => [...f, u]), r.current = n);
882
+ }, [n]);
883
+ const b = `md-fade-in ${l}ms ${a} forwards`;
884
+ return /* @__PURE__ */ e(H, { children: i.map((u, f) => /* @__PURE__ */ e(
283
885
  "span",
284
886
  {
285
887
  className: "md-animation-text",
286
- style: { animation: x },
287
- children: p
888
+ style: { animation: b },
889
+ children: u
288
890
  },
289
- `animation-text-${b}`
891
+ `animation-text-${f}`
290
892
  )) });
291
893
  });
292
- le.displayName = "AnimationText";
293
- let U = null;
894
+ Pe.displayName = "AnimationText";
895
+ let X = null;
294
896
  try {
295
- U = require("dompurify");
897
+ X = require("dompurify");
296
898
  } catch {
297
899
  }
298
- function ke() {
299
- return U !== null;
900
+ function je() {
901
+ return X !== null;
300
902
  }
301
- function we(e, t) {
302
- if (!U)
303
- return e;
903
+ function qe(t, n) {
904
+ if (!X)
905
+ return t;
304
906
  const c = {
305
907
  ADD_ATTR: ["target", "rel", "data-block-key", "data-pending", "data-predicted"],
306
- ...t
908
+ ...n
307
909
  };
308
- return U.default.sanitize(e, c);
910
+ return X.default.sanitize(t, c);
309
911
  }
310
- function q(e) {
311
- if (e.type === "root")
912
+ function G(t) {
913
+ if (t.type === "root")
312
914
  return {
313
- ...e,
915
+ ...t,
314
916
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
315
- children: e.children.map((r) => r.type === "element" ? q(r) : r)
917
+ children: t.children.map((a) => a.type === "element" ? G(a) : a)
316
918
  };
317
- const t = ["onclick", "onerror", "onload", "onmouseover", "onfocus", "onblur"], c = ["javascript:", "vbscript:", "data:text/html"], a = {};
318
- if (e.properties)
319
- for (const [r, g] of Object.entries(e.properties)) {
320
- const s = r.toLowerCase();
321
- if (!(t.includes(s) || s.startsWith("on"))) {
322
- if ((s === "href" || s === "src") && typeof g == "string") {
323
- const n = g.toLowerCase().trim();
324
- if (c.some((x) => n.startsWith(x)))
919
+ const n = ["onclick", "onerror", "onload", "onmouseover", "onfocus", "onblur"], c = ["javascript:", "vbscript:", "data:text/html"], l = {};
920
+ if (t.properties)
921
+ for (const [a, i] of Object.entries(t.properties)) {
922
+ const o = a.toLowerCase();
923
+ if (!(n.includes(o) || o.startsWith("on"))) {
924
+ if ((o === "href" || o === "src") && typeof i == "string") {
925
+ const r = i.toLowerCase().trim();
926
+ if (c.some((b) => r.startsWith(b)))
325
927
  continue;
326
928
  }
327
- a[r] = g;
929
+ l[a] = i;
328
930
  }
329
931
  }
330
932
  return {
331
- ...e,
332
- properties: a,
933
+ ...t,
934
+ properties: l,
333
935
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
334
- children: e.children.map((r) => r.type === "element" ? q(r) : r)
936
+ children: t.children.map((a) => a.type === "element" ? G(a) : a)
335
937
  };
336
938
  }
337
939
  export {
338
- le as AnimationText,
339
- ne as Markdown,
340
- Y as StreamingImage,
341
- ue as StreamingMarkdown,
342
- ke as isDOMPurifyAvailable,
343
- q as sanitizeHast,
344
- we as sanitizeHtml,
345
- re as useMarkdown,
346
- ge as useStreamingMarkdown
940
+ Pe as AnimationText,
941
+ K as CodeBlock,
942
+ Te as Markdown,
943
+ oe as MermaidBlock,
944
+ se as MermaidFullscreenViewer,
945
+ ie as StreamingImage,
946
+ Oe as StreamingMarkdown,
947
+ je as isDOMPurifyAvailable,
948
+ G as sanitizeHast,
949
+ qe as sanitizeHtml,
950
+ We as useMarkdown,
951
+ _e as useStreamingMarkdown,
952
+ te as useZoom
347
953
  };