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