@superlc/md-react 0.1.1 → 0.2.1

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