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