@superlc/md-react 0.1.1 → 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,425 +1,953 @@
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 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
+ import { toJsxRuntime as W } from "hast-util-to-jsx-runtime";
5
+ async function ve(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 ge(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 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
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 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
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 [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
36
  "button",
37
37
  {
38
38
  type: "button",
39
- className: `md-copy-button${r ? " md-copy-button--copied" : ""}`,
40
- onClick: c,
41
- title: r ? "已复制" : "复制代码",
42
- "aria-label": r ? "已复制" : "复制代码",
43
- children: r ? /* @__PURE__ */ s(ie, {}) : /* @__PURE__ */ s(oe, {})
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
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 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
50
  }
51
- J.displayName = "CodeBlock";
52
- const ue = ({
53
- children: e,
54
- components: t,
55
- className: a,
56
- copyButton: o = !0,
57
- onCodeCopy: r,
58
- ...u
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
85
+ });
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
59
169
  }) => {
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
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());
65
199
  };
66
- return j(n, {
67
- Fragment: E,
68
- jsx: s,
69
- jsxs: A,
70
- components: m
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;
343
+ }
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,
566
+ className: c,
567
+ copyButton: l = !0,
568
+ onCodeCopy: a,
569
+ mermaid: i,
570
+ ...o
571
+ }) => {
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
71
596
  });
72
- }, [e, t, o, r, u]);
73
- return /* @__PURE__ */ s("div", { className: a, children: c });
597
+ }, [t, n, l, a, r, o]);
598
+ return /* @__PURE__ */ e("div", { className: c, children: b });
74
599
  };
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
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
86
611
  });
87
- }, [e, a, o]);
612
+ }, [t, c, l]);
88
613
  }
89
- const ee = z(
90
- ({ block: e, components: t }) => {
91
- if (!e.hast) return null;
614
+ const le = P(
615
+ ({ block: t, components: n }) => {
616
+ if (!t.hast) return null;
92
617
  try {
93
- return j(e.hast, {
94
- jsx: s,
95
- jsxs: A,
96
- Fragment: E,
97
- components: t
618
+ return W(t.hast, {
619
+ jsx: e,
620
+ jsxs: C,
621
+ Fragment: H,
622
+ components: n
98
623
  });
99
624
  } catch {
100
625
  return null;
101
626
  }
102
627
  },
103
- (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
104
629
  );
105
- ee.displayName = "StableBlock";
106
- function xe(e = {}) {
630
+ le.displayName = "StableBlock";
631
+ function _e(t = {}) {
107
632
  const {
108
- components: t,
109
- minUpdateInterval: a = 16,
110
- immediate: o = !1,
111
- 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);
633
+ components: n,
634
+ minUpdateInterval: c = 16,
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);
117
642
  }));
118
- }, [a, o]), B = S(
119
- (y) => {
120
- c.current.append(y), L();
643
+ }, [c, l]), B = p(
644
+ (R) => {
645
+ o.current.append(R), I();
121
646
  },
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();
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();
129
654
  },
130
655
  () => {
131
- c.current.finish(), v(!0), h(1), k("complete"), L();
656
+ o.current.finish(), d(!0), h(1), x("complete"), I();
132
657
  }
133
658
  );
134
659
  },
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);
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);
146
671
  }, []);
147
- x(() => {
148
- n.current.setRate(r);
149
- }, [r]), x(() => () => {
150
- n.current.stop(), d.current !== null && cancelAnimationFrame(d.current);
672
+ z(() => {
673
+ r.current.setRate(a);
674
+ }, [a]), z(() => () => {
675
+ r.current.stop(), y.current !== null && cancelAnimationFrame(y.current);
151
676
  }, []);
152
- const i = c.current.getState(), l = c.current.getStats(), b = c.current.getContent(), M = F(() => i.blocks.map(
153
- (y) => s(
154
- ee,
677
+ const m = o.current.getState(), N = o.current.getStats(), M = o.current.getContent(), S = O(() => m.blocks.map(
678
+ (R) => e(
679
+ le,
155
680
  {
156
- block: y,
157
- components: t
681
+ block: R,
682
+ components: n
158
683
  },
159
- y.key
684
+ R.key
160
685
  )
161
- ), [i.blocks, t, p]);
686
+ ), [m.blocks, n, b]);
162
687
  return {
163
- element: F(() => i.blocks.length === 0 ? null : s(E, { children: M }), [M, i.blocks.length]),
688
+ element: O(() => m.blocks.length === 0 ? null : e(H, { children: S }), [S, m.blocks.length]),
164
689
  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,
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,
176
701
  outputStatus: g
177
702
  };
178
703
  }
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,
188
- "data-height": r,
189
- ...u
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,
711
+ className: c,
712
+ "data-width": l,
713
+ "data-height": a,
714
+ ...i
190
715
  }) => {
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(() => {
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(() => {
196
721
  h.current && clearTimeout(h.current), h.current = setTimeout(() => {
197
- v(!1);
198
- }, le);
722
+ d(!1);
723
+ }, De);
199
724
  }, []);
200
- return /* @__PURE__ */ A(
725
+ return /* @__PURE__ */ C(
201
726
  "span",
202
727
  {
203
- className: `md-image-container ${a || ""}`,
204
- style: { width: p, height: m },
728
+ className: `md-image-container ${c || ""}`,
729
+ style: { width: b, height: u },
205
730
  children: [
206
- n && /* @__PURE__ */ s(
731
+ r && /* @__PURE__ */ e(
207
732
  "img",
208
733
  {
209
- ref: C,
210
- src: n,
211
- alt: t,
734
+ ref: v,
735
+ src: r,
736
+ alt: n,
212
737
  onLoad: g,
213
738
  className: "md-image",
214
- ...u
739
+ ...i
215
740
  }
216
741
  ),
217
- w && /* @__PURE__ */ s("span", { className: "md-image-skeleton", children: /* @__PURE__ */ s(de, {}) })
742
+ f && /* @__PURE__ */ e("span", { className: "md-image-skeleton", children: /* @__PURE__ */ e(He, {}) })
218
743
  ]
219
744
  }
220
745
  );
221
746
  });
222
- te.displayName = "StreamingImage";
223
- let q = !1, V = null;
224
- async function re() {
747
+ ie.displayName = "StreamingImage";
748
+ let q = !1, Y = null;
749
+ async function ue() {
225
750
  if (!q)
226
- return V || (V = (async () => {
751
+ return Y || (Y = (async () => {
227
752
  await import("katex/dist/katex.min.css"), q = !0;
228
- })(), V);
753
+ })(), Y);
229
754
  }
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();
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();
236
761
  }
237
- const ne = z(
238
- ({ block: e, components: t }) => {
239
- if (!e.hast) return null;
762
+ const de = P(
763
+ ({ block: t, components: n }) => {
764
+ if (!t.hast) return null;
240
765
  try {
241
- return j(e.hast, {
242
- jsx: s,
243
- jsxs: A,
244
- Fragment: E,
245
- components: t
766
+ return W(t.hast, {
767
+ jsx: e,
768
+ jsxs: C,
769
+ Fragment: H,
770
+ components: n
246
771
  });
247
772
  } catch {
248
- return /* @__PURE__ */ s("div", { className: "parse-error", children: e.source });
773
+ return /* @__PURE__ */ e("div", { className: "parse-error", children: t.source });
249
774
  }
250
775
  },
251
- (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
252
777
  );
253
- ne.displayName = "StableBlock";
254
- const he = ({
255
- content: e,
256
- source: t,
257
- outputRate: a = "medium",
258
- isComplete: o = !1,
259
- 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,
778
+ de.displayName = "StableBlock";
779
+ const Oe = ({
780
+ content: t,
781
+ source: n,
782
+ outputRate: c = "medium",
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,
268
793
  ...h
269
794
  }) => {
270
- x(() => {
271
- h.math && pe();
795
+ z(() => {
796
+ h.math && $e();
272
797
  }, [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();
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();
277
802
  }));
278
803
  };
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();
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();
284
809
  },
285
810
  () => {
286
- g.current.finish(), r == null || r(), P();
811
+ g.current.finish(), a == null || a(), w();
287
812
  }
288
813
  )));
289
- }, [t, w, r, c]), x(() => {
290
- if (t !== void 0)
814
+ }, [n, f, a, o]), z(() => {
815
+ if (n !== void 0)
291
816
  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);
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);
297
822
  } else
298
- g.current.reset(), l && g.current.append(l);
299
- N.current = l, P();
823
+ g.current.reset(), N && g.current.append(N);
824
+ V.current = N, w();
300
825
  }
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;
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;
312
837
  }
313
- }), x(() => () => {
314
- k.current.stop(), R.current !== null && cancelAnimationFrame(R.current);
838
+ }), z(() => () => {
839
+ x.current.stop(), s.current !== null && cancelAnimationFrame(s.current);
315
840
  }, []);
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,
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,
321
846
  {
322
- showCopyButton: l.stable && v,
323
- onCopy: C,
324
- ...b
847
+ showCopyButton: N.stable && d,
848
+ onCopy: v,
849
+ ...M
325
850
  }
326
851
  );
327
852
  };
328
- return D.blocks.map((l) => {
329
- const b = i(l), M = {
330
- img: te,
331
- ...b ? { pre: b } : {},
332
- ...n
853
+ return L.blocks.map((N) => {
854
+ const M = m(N), S = {
855
+ img: ie,
856
+ ...M ? { pre: M } : {},
857
+ ...r
333
858
  };
334
- return /* @__PURE__ */ s(
335
- ne,
859
+ return /* @__PURE__ */ e(
860
+ de,
336
861
  {
337
- block: l,
338
- components: M
862
+ block: N,
863
+ components: S
339
864
  },
340
- l.key
865
+ N.key
341
866
  );
342
867
  });
343
- }, [D.blocks, n, v, C]);
344
- return /* @__PURE__ */ s("div", { className: p, "data-streaming": !H, children: O });
868
+ }, [L.blocks, r, d, v]);
869
+ return /* @__PURE__ */ e("div", { className: b, "data-streaming": !D, children: F });
345
870
  };
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;
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;
353
878
  return;
354
879
  }
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(
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(
360
885
  "span",
361
886
  {
362
887
  className: "md-animation-text",
363
- style: { animation: p },
364
- children: m
888
+ style: { animation: b },
889
+ children: u
365
890
  },
366
- `animation-text-${w}`
891
+ `animation-text-${f}`
367
892
  )) });
368
893
  });
369
- ge.displayName = "AnimationText";
370
- let $ = null;
894
+ Pe.displayName = "AnimationText";
895
+ let X = null;
371
896
  try {
372
- $ = require("dompurify");
897
+ X = require("dompurify");
373
898
  } catch {
374
899
  }
375
- function Re() {
376
- return $ !== null;
900
+ function je() {
901
+ return X !== null;
377
902
  }
378
- function Se(e, t) {
379
- if (!$)
380
- return e;
381
- const a = {
903
+ function qe(t, n) {
904
+ if (!X)
905
+ return t;
906
+ const c = {
382
907
  ADD_ATTR: ["target", "rel", "data-block-key", "data-pending", "data-predicted"],
383
- ...t
908
+ ...n
384
909
  };
385
- return $.default.sanitize(e, a);
910
+ return X.default.sanitize(t, c);
386
911
  }
387
- function X(e) {
388
- if (e.type === "root")
912
+ function G(t) {
913
+ if (t.type === "root")
389
914
  return {
390
- ...e,
915
+ ...t,
391
916
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
- children: e.children.map((r) => r.type === "element" ? X(r) : r)
917
+ children: t.children.map((a) => a.type === "element" ? G(a) : a)
393
918
  };
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)))
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)))
402
927
  continue;
403
928
  }
404
- o[r] = u;
929
+ l[a] = i;
405
930
  }
406
931
  }
407
932
  return {
408
- ...e,
409
- properties: o,
933
+ ...t,
934
+ properties: l,
410
935
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
411
- children: e.children.map((r) => r.type === "element" ? X(r) : r)
936
+ children: t.children.map((a) => a.type === "element" ? G(a) : a)
412
937
  };
413
938
  }
414
939
  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
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
425
953
  };