react-docs-ui 0.6.12 → 0.6.13

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.
Files changed (86) hide show
  1. package/dist/{AISettingsPanel-CaGVDZ2z.js → AISettingsPanel-KzfonkeY.js} +44 -44
  2. package/dist/DocsApp-DTFpyBOl.js +35170 -0
  3. package/dist/{GlobalContextMenu-CSEpdhY4.js → GlobalContextMenu-hGNTKw3S.js} +2 -2
  4. package/dist/MdxContent-B664V_Hk.js +812 -0
  5. package/dist/MdxContent.lazy-DsQt7MZQ.js +1512 -0
  6. package/dist/{SearchDialog-B67saUjp.js → SearchDialog-Cfam5kUW.js} +4 -4
  7. package/dist/{SearchRuntime-CsSmQWdV.js → SearchRuntime-Dk265vam.js} +2 -2
  8. package/dist/{context-menu-BX0jqPJI.js → context-menu-CBGG4zJl.js} +1 -1
  9. package/dist/docs-app.es.js +8 -2
  10. package/dist/index-ByXnCzVt.js +12 -0
  11. package/dist/react-docs-ui.css +1 -1
  12. package/dist/react-docs-ui.es.js +15 -15
  13. package/dist/types/components/FontProvider.d.ts.map +1 -1
  14. package/dist/types/components/MdxContent.d.ts.map +1 -1
  15. package/dist/types/components/MdxContent.lazy.d.ts.map +1 -1
  16. package/dist/types/docs-app.d.ts +3 -1
  17. package/dist/types/docs-app.d.ts.map +1 -1
  18. package/dist/types/lib/component-scanner.d.ts +1 -0
  19. package/dist/types/lib/component-scanner.d.ts.map +1 -1
  20. package/dist/types/lib/shiki-highlighter.d.ts +2 -0
  21. package/dist/types/lib/shiki-highlighter.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/dist/DocsApp-CEu0IOyd.js +0 -26909
  24. package/dist/MdxContent-Bbj-p4XT.js +0 -10512
  25. package/dist/MdxContent.lazy-BttoJj5k.js +0 -4
  26. package/dist/fonts/02c687e7ed17b3df.woff2 +0 -0
  27. package/dist/fonts/09d4de25241bfe76.woff +0 -0
  28. package/dist/fonts/09dfac589fa421e8.woff2 +0 -0
  29. package/dist/fonts/0d29b2b1f8303138.ttf +0 -0
  30. package/dist/fonts/0e9f19247ab3bbab.ttf +0 -0
  31. package/dist/fonts/1969dbe1bc0fb3ba.woff +0 -0
  32. package/dist/fonts/1f89d2fedc85c386.woff +0 -0
  33. package/dist/fonts/20b388d1a51f5745.ttf +0 -0
  34. package/dist/fonts/21851da450182870.ttf +0 -0
  35. package/dist/fonts/22d5c4e6cd1e9474.woff2 +0 -0
  36. package/dist/fonts/22e83d374a2e6691.woff +0 -0
  37. package/dist/fonts/2f36d9db5ff365d4.woff +0 -0
  38. package/dist/fonts/314032aa9f107304.woff2 +0 -0
  39. package/dist/fonts/3533cc38c9cdc602.ttf +0 -0
  40. package/dist/fonts/3d0f44e32f2e74f2.ttf +0 -0
  41. package/dist/fonts/4124e542a1b58f9d.woff +0 -0
  42. package/dist/fonts/46d68807665c21f9.ttf +0 -0
  43. package/dist/fonts/4e1eaced156586d3.ttf +0 -0
  44. package/dist/fonts/4fc7ad74569941de.woff +0 -0
  45. package/dist/fonts/552292117efd3f42.ttf +0 -0
  46. package/dist/fonts/552f66ef43fc7522.woff +0 -0
  47. package/dist/fonts/5600e0919751e982.woff +0 -0
  48. package/dist/fonts/58d42913cac4cb53.woff2 +0 -0
  49. package/dist/fonts/5cff588fceb2856c.ttf +0 -0
  50. package/dist/fonts/5d09426707f9d063.ttf +0 -0
  51. package/dist/fonts/607b70ee0da7b15f.woff2 +0 -0
  52. package/dist/fonts/6652f5c5affcddc6.ttf +0 -0
  53. package/dist/fonts/69732d145fb77d46.ttf +0 -0
  54. package/dist/fonts/69ed18356e7517f2.woff2 +0 -0
  55. package/dist/fonts/705a1783b9c1d57b.ttf +0 -0
  56. package/dist/fonts/72bb9b68fd978fda.woff +0 -0
  57. package/dist/fonts/745939d4e3f4755f.woff2 +0 -0
  58. package/dist/fonts/7591411ae35bc580.woff +0 -0
  59. package/dist/fonts/786e88705bcced94.woff2 +0 -0
  60. package/dist/fonts/79d8b432f0a85a07.woff +0 -0
  61. package/dist/fonts/83b99a8c57312e6e.woff2 +0 -0
  62. package/dist/fonts/83fb1a9d8474dd56.woff2 +0 -0
  63. package/dist/fonts/8cfd3def12a3c5ef.ttf +0 -0
  64. package/dist/fonts/90b626c33ef816d4.ttf +0 -0
  65. package/dist/fonts/96bbd8e3dc776eb1.woff +0 -0
  66. package/dist/fonts/99d6d1362d7b9b12.woff2 +0 -0
  67. package/dist/fonts/a27661173f0a7433.woff2 +0 -0
  68. package/dist/fonts/abe35a8c78edf887.woff +0 -0
  69. package/dist/fonts/ad9576beef3f1d4e.woff2 +0 -0
  70. package/dist/fonts/adbfefebea65cf02.ttf +0 -0
  71. package/dist/fonts/b4aab29b79f992e3.woff2 +0 -0
  72. package/dist/fonts/b9b897e4301ad703.woff2 +0 -0
  73. package/dist/fonts/be03438595f83d0f.ttf +0 -0
  74. package/dist/fonts/c2b56591519e9293.woff2 +0 -0
  75. package/dist/fonts/c505bdad51c9abfa.ttf +0 -0
  76. package/dist/fonts/c811e89c187ceac5.woff +0 -0
  77. package/dist/fonts/ce2290c5c835ea00.woff +0 -0
  78. package/dist/fonts/ce4cb83d70539101.woff2 +0 -0
  79. package/dist/fonts/d601cb8345d82ba5.ttf +0 -0
  80. package/dist/fonts/d6f6ac428c874555.woff +0 -0
  81. package/dist/fonts/debedc918129c66f.woff2 +0 -0
  82. package/dist/fonts/e079035466b8f120.woff +0 -0
  83. package/dist/fonts/e618042c847fd3b9.woff2 +0 -0
  84. package/dist/fonts/e71ae6d3e7debcfd.woff +0 -0
  85. package/dist/fonts/f61879e5a60b36a0.woff +0 -0
  86. package/dist/index-DHF5A5Uk.js +0 -12
@@ -0,0 +1,812 @@
1
+ import { aE as R, j as t, d as de, h as me, aF as pe, aG as fe, a2 as he, B as H, a0 as be, a3 as ge, a1 as we, c as xe, aB as ye, aH as ke, aI as Ce, aJ as Ne, aK as je } from "./DocsApp-DTFpyBOl.js";
2
+ import * as r from "react";
3
+ import ve from "react-markdown";
4
+ import Se from "rehype-autolink-headings";
5
+ import Ee from "rehype-slug";
6
+ import Le from "remark-gfm";
7
+ import ze from "rehype-raw";
8
+ import Me from "remark-math";
9
+ import Te from "rehype-katex";
10
+ import { useParams as De, Link as Ae } from "react-router-dom";
11
+ import { visit as te, SKIP as Ie } from "unist-util-visit";
12
+ import { ZoomIn as Re, ZoomOut as Pe, Minimize as $e, Search as K, RefreshCw as Fe, RotateCcw as Oe, RotateCw as _e, Maximize as We, Download as Ze, ExternalLink as Xe, X as Ue, Check as Ye, Copy as Je } from "lucide-react";
13
+ import Ve from "katex-physics";
14
+ function Be(l) {
15
+ const s = /* @__PURE__ */ new Map();
16
+ for (const [n] of Object.entries(l)) {
17
+ const o = n.toLowerCase(), i = o.replace(/\./g, "-");
18
+ s.set(o, n), s.set(i, n);
19
+ }
20
+ return () => (n) => {
21
+ te(n, "element", (o) => {
22
+ const i = o.tagName.toLowerCase(), m = s.get(i);
23
+ m && (o.tagName = m, o.properties = o.properties || {}, o.properties.isComponent = !0);
24
+ });
25
+ };
26
+ }
27
+ const He = {
28
+ "zh-cn": {
29
+ preview: "预览图片",
30
+ zoomIn: "放大",
31
+ zoomOut: "缩小",
32
+ fit: "适配窗口",
33
+ actualSize: "原始比例",
34
+ reset: "重置",
35
+ rotateLeft: "左旋",
36
+ rotateRight: "右旋",
37
+ fullscreen: "全屏",
38
+ download: "下载",
39
+ openInNewTab: "新标签打开",
40
+ close: "关闭图片查看器",
41
+ imageAltFallback: "文档图片",
42
+ downloadSuccess: "图片下载已开始",
43
+ downloadError: "当前图片无法直接下载,请尝试新标签打开。",
44
+ fullscreenError: "当前浏览器不支持全屏,已保留对话框预览。",
45
+ openInNewTabError: "无法在新标签页打开图片。",
46
+ imageLoadError: "图片加载失败"
47
+ },
48
+ en: {
49
+ preview: "Preview image",
50
+ zoomIn: "Zoom in",
51
+ zoomOut: "Zoom out",
52
+ fit: "Fit to viewport",
53
+ actualSize: "Actual size",
54
+ reset: "Reset",
55
+ rotateLeft: "Rotate left",
56
+ rotateRight: "Rotate right",
57
+ fullscreen: "Fullscreen",
58
+ download: "Download",
59
+ openInNewTab: "Open in new tab",
60
+ close: "Close image viewer",
61
+ imageAltFallback: "Documentation image",
62
+ downloadSuccess: "Image download started",
63
+ downloadError: "This image cannot be downloaded directly. Try opening it in a new tab.",
64
+ fullscreenError: "Fullscreen is not available in this browser. Dialog preview is still available.",
65
+ openInNewTabError: "Unable to open the image in a new tab.",
66
+ imageLoadError: "Failed to load image"
67
+ }
68
+ };
69
+ function re(l = "zh-cn", s) {
70
+ return {
71
+ ...He[l === "en" ? "en" : "zh-cn"],
72
+ ...s
73
+ };
74
+ }
75
+ const ne = 0.2, oe = 5, Q = 0.2;
76
+ function Z(l) {
77
+ return Math.min(oe, Math.max(ne, Number(l.toFixed(2))));
78
+ }
79
+ function Ke(l, s, n) {
80
+ const o = (s || n || "image").trim().split("").map((b) => b.charCodeAt(0) < 32 || '<>:"/\\|?*'.includes(b) ? "-" : b).join("");
81
+ return (l.split("?")[0]?.split("#")[0] ?? l).split("/").pop()?.trim() || o || "image";
82
+ }
83
+ function q(l, s) {
84
+ const n = document.createElement("a");
85
+ n.href = l, n.download = s, n.rel = "noopener noreferrer", document.body.appendChild(n), n.click(), document.body.removeChild(n);
86
+ }
87
+ function Qe(l) {
88
+ if (l.startsWith("blob:") || l.startsWith("data:"))
89
+ return !0;
90
+ try {
91
+ return new URL(l, window.location.href).origin === window.location.origin;
92
+ } catch {
93
+ return !1;
94
+ }
95
+ }
96
+ function qe({
97
+ open: l,
98
+ onOpenChange: s,
99
+ src: n,
100
+ alt: o,
101
+ title: i,
102
+ lang: m = "zh-cn",
103
+ labels: b
104
+ }) {
105
+ const a = r.useMemo(
106
+ () => re(m, b),
107
+ [m, b]
108
+ ), w = r.useRef(null), S = r.useRef(null), [g, j] = r.useState(1), [u, p] = r.useState(0), [y, f] = r.useState("fit"), [k, N] = r.useState(!1), [c, x] = r.useState(!1), [h, L] = r.useState({ x: 0, y: 0 }), [z, M] = r.useState(!1), v = r.useRef(
109
+ /* @__PURE__ */ new Map()
110
+ ), P = r.useRef(null), T = r.useRef(null), W = o?.trim() || i?.trim() || a.imageAltFallback, D = r.useCallback(() => {
111
+ j(1), p(0), f("fit"), x(!1), L({ x: 0, y: 0 }), M(!1), v.current.clear(), P.current = null, T.current = null;
112
+ }, []);
113
+ r.useEffect(() => {
114
+ if (l) {
115
+ D();
116
+ return;
117
+ }
118
+ N(!1);
119
+ }, [l, D]), r.useEffect(() => {
120
+ document.fullscreenElement || N(!1);
121
+ }, [l]), r.useEffect(() => {
122
+ const e = () => {
123
+ N(!!document.fullscreenElement);
124
+ };
125
+ return document.addEventListener("fullscreenchange", e), () => {
126
+ document.removeEventListener("fullscreenchange", e);
127
+ };
128
+ }, []);
129
+ const ae = r.useMemo(() => ({
130
+ transform: `translate(${h.x}px, ${h.y}px) scale(${g}) rotate(${u}deg)`,
131
+ transition: z ? "none" : "transform 160ms ease",
132
+ cursor: c ? "default" : z ? "grabbing" : "grab"
133
+ }), [z, c, u, g, h.x, h.y]), A = r.useCallback(() => {
134
+ f("actual"), j((e) => Z(e + Q));
135
+ }, []), I = r.useCallback(() => {
136
+ f("actual"), j((e) => Z(e - Q));
137
+ }, []), X = r.useCallback(() => {
138
+ f("fit"), j(1), L({ x: 0, y: 0 });
139
+ }, []), U = r.useCallback(() => {
140
+ f("actual"), j(1), L({ x: 0, y: 0 });
141
+ }, []), F = r.useCallback(() => {
142
+ p((e) => e - 90);
143
+ }, []), O = r.useCallback(() => {
144
+ p((e) => e + 90);
145
+ }, []), Y = r.useCallback(async () => {
146
+ const e = Ke(n, i, o);
147
+ let d = null;
148
+ try {
149
+ if (Qe(n)) {
150
+ q(n, e), R({ description: a.downloadSuccess });
151
+ return;
152
+ }
153
+ } catch {
154
+ }
155
+ try {
156
+ const C = await fetch(n, { mode: "cors" });
157
+ if (!C.ok)
158
+ throw new Error(`Failed to fetch image: ${C.status}`);
159
+ const E = await C.blob();
160
+ d = URL.createObjectURL(E), q(d, e), R({ description: a.downloadSuccess });
161
+ } catch {
162
+ R({
163
+ variant: "destructive",
164
+ description: a.downloadError
165
+ });
166
+ } finally {
167
+ d && URL.revokeObjectURL(d);
168
+ }
169
+ }, [o, a.downloadError, a.downloadSuccess, n, i]), J = r.useCallback(() => {
170
+ try {
171
+ window.open(n, "_blank", "noopener,noreferrer");
172
+ } catch {
173
+ R({
174
+ variant: "destructive",
175
+ description: a.openInNewTabError
176
+ });
177
+ }
178
+ }, [a.openInNewTabError, n]), _ = r.useCallback(async () => {
179
+ const e = w.current;
180
+ if (!e?.requestFullscreen) {
181
+ R({ description: a.fullscreenError });
182
+ return;
183
+ }
184
+ try {
185
+ document.fullscreenElement ? await document.exitFullscreen() : await e.requestFullscreen();
186
+ } catch {
187
+ R({ description: a.fullscreenError });
188
+ }
189
+ }, [a.fullscreenError]);
190
+ r.useEffect(() => {
191
+ if (!l) return;
192
+ const e = (d) => {
193
+ d.key === "+" ? (d.preventDefault(), A()) : d.key === "-" ? (d.preventDefault(), I()) : d.key === "0" ? (d.preventDefault(), D()) : d.key === "f" || d.key === "F" ? (d.preventDefault(), _()) : d.key === "[" ? (d.preventDefault(), F()) : d.key === "]" && (d.preventDefault(), O());
194
+ };
195
+ return window.addEventListener("keydown", e), () => {
196
+ window.removeEventListener("keydown", e);
197
+ };
198
+ }, [_, l, D, F, O, A, I]);
199
+ const $ = r.useCallback(
200
+ (e) => {
201
+ e.preventDefault(), e.stopPropagation(), e.deltaY < 0 ? A() : I();
202
+ },
203
+ [A, I]
204
+ );
205
+ r.useEffect(() => {
206
+ if (!l) return;
207
+ const e = w.current;
208
+ if (e)
209
+ return e.addEventListener("wheel", $, { passive: !1 }), () => {
210
+ e.removeEventListener("wheel", $);
211
+ };
212
+ }, [$, l]);
213
+ const se = r.useCallback((e) => {
214
+ v.current.set(e.pointerId, {
215
+ x: e.clientX,
216
+ y: e.clientY
217
+ });
218
+ const d = Array.from(v.current.values());
219
+ if (d.length === 2 && T.current) {
220
+ const [E, B] = d, ce = Math.hypot(B.x - E.x, B.y - E.y), ue = Z(
221
+ T.current.startScale * (ce / T.current.startDistance)
222
+ );
223
+ f("actual"), j(ue);
224
+ return;
225
+ }
226
+ const C = P.current;
227
+ !C || C.pointerId !== e.pointerId || L({
228
+ x: C.originX + (e.clientX - C.startX),
229
+ y: C.originY + (e.clientY - C.startY)
230
+ });
231
+ }, []), V = r.useCallback((e) => {
232
+ e && w.current?.hasPointerCapture(e.pointerId) && w.current.releasePointerCapture(e.pointerId), e && v.current.delete(e.pointerId), P.current = null, v.current.size < 2 && (T.current = null), M(!1);
233
+ }, []), le = r.useCallback(
234
+ (e) => {
235
+ if (e.button !== 0 || c)
236
+ return;
237
+ e.preventDefault(), e.stopPropagation(), e.currentTarget.setPointerCapture(e.pointerId), v.current.set(e.pointerId, {
238
+ x: e.clientX,
239
+ y: e.clientY
240
+ });
241
+ const d = Array.from(v.current.values());
242
+ if (d.length === 2) {
243
+ const [C, E] = d;
244
+ T.current = {
245
+ startDistance: Math.max(
246
+ 1,
247
+ Math.hypot(E.x - C.x, E.y - C.y)
248
+ ),
249
+ startScale: g
250
+ }, P.current = null, M(!1);
251
+ return;
252
+ }
253
+ P.current = {
254
+ pointerId: e.pointerId,
255
+ startX: e.clientX,
256
+ startY: e.clientY,
257
+ originX: h.x,
258
+ originY: h.y
259
+ }, M(!0);
260
+ },
261
+ [c, g, h.x, h.y]
262
+ );
263
+ r.useEffect(() => {
264
+ if (!l) return;
265
+ const e = (d) => {
266
+ const C = w.current, E = d.target;
267
+ !C || !(E instanceof Node) || !C.contains(E) || !d.ctrlKey || $(d);
268
+ };
269
+ return window.addEventListener("wheel", e, {
270
+ passive: !1,
271
+ capture: !0
272
+ }), () => {
273
+ window.removeEventListener("wheel", e, {
274
+ capture: !0
275
+ });
276
+ };
277
+ }, [$, l]);
278
+ const ie = r.useMemo(
279
+ () => [
280
+ { key: "zoom-in", label: a.zoomIn, icon: Re, onClick: A, disabled: c || g >= oe },
281
+ { key: "zoom-out", label: a.zoomOut, icon: Pe, onClick: I, disabled: c || g <= ne },
282
+ { key: "fit", label: a.fit, icon: $e, onClick: X, disabled: c },
283
+ { key: "actual-size", label: a.actualSize, icon: K, onClick: U, disabled: c },
284
+ { key: "reset", label: a.reset, icon: Fe, onClick: D, disabled: c },
285
+ { key: "rotate-left", label: a.rotateLeft, icon: Oe, onClick: F, disabled: c },
286
+ { key: "rotate-right", label: a.rotateRight, icon: _e, onClick: O, disabled: c },
287
+ { key: "fullscreen", label: a.fullscreen, icon: We, onClick: () => {
288
+ _();
289
+ }, disabled: !1 },
290
+ { key: "download", label: a.download, icon: Ze, onClick: Y, disabled: c },
291
+ { key: "new-tab", label: a.openInNewTab, icon: Xe, onClick: J, disabled: !1 }
292
+ ],
293
+ [
294
+ Y,
295
+ _,
296
+ J,
297
+ c,
298
+ a.actualSize,
299
+ a.download,
300
+ a.fit,
301
+ a.fullscreen,
302
+ a.openInNewTab,
303
+ a.reset,
304
+ a.rotateLeft,
305
+ a.rotateRight,
306
+ a.zoomIn,
307
+ a.zoomOut,
308
+ D,
309
+ F,
310
+ O,
311
+ g,
312
+ U,
313
+ X,
314
+ A,
315
+ I
316
+ ]
317
+ );
318
+ return /* @__PURE__ */ t.jsx(de, { open: l, onOpenChange: s, children: /* @__PURE__ */ t.jsxs(
319
+ me,
320
+ {
321
+ showCloseButton: !1,
322
+ className: "flex h-[min(94vh,980px)] w-[calc(100vw-0.75rem)] sm:w-[40rem] md:w-[52rem] lg:w-[64rem] xl:w-[74rem] 2xl:w-[86rem] max-w-[calc(100vw-0.75rem)] flex-col gap-3 border-zinc-800 bg-zinc-950 p-3 text-zinc-50 sm:max-w-[calc(100vw-2rem)] sm:p-4",
323
+ children: [
324
+ /* @__PURE__ */ t.jsx(pe, { children: W }),
325
+ /* @__PURE__ */ t.jsx(fe, { children: a.close }),
326
+ /* @__PURE__ */ t.jsxs(he, { delayDuration: 100, children: [
327
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center justify-between gap-3 rounded-lg border border-zinc-800 bg-zinc-900/80 px-3 py-2", children: [
328
+ /* @__PURE__ */ t.jsxs("div", { className: "min-w-0", children: [
329
+ /* @__PURE__ */ t.jsx("p", { className: "truncate text-sm font-medium", children: W }),
330
+ /* @__PURE__ */ t.jsxs("p", { className: "text-xs text-zinc-400", children: [
331
+ y === "fit" ? a.fit : `${Math.round(g * 100)}%`,
332
+ u !== 0 ? ` · ${u}deg` : "",
333
+ k ? ` · ${a.fullscreen}` : ""
334
+ ] })
335
+ ] }),
336
+ /* @__PURE__ */ t.jsx(
337
+ H,
338
+ {
339
+ type: "button",
340
+ size: "icon",
341
+ variant: "ghost",
342
+ className: "h-9 w-9 shrink-0 text-zinc-100 hover:bg-zinc-800 hover:text-white",
343
+ onClick: () => s(!1),
344
+ "aria-label": a.close,
345
+ title: a.close,
346
+ children: /* @__PURE__ */ t.jsx(Ue, { className: "h-4 w-4" })
347
+ }
348
+ )
349
+ ] }),
350
+ /* @__PURE__ */ t.jsx("div", { className: "overflow-x-auto rounded-lg border border-zinc-800 bg-zinc-900/80 px-2 py-2", children: /* @__PURE__ */ t.jsx("div", { className: "flex min-w-max items-center gap-2", children: ie.map((e) => {
351
+ const d = e.icon;
352
+ return /* @__PURE__ */ t.jsxs(be, { children: [
353
+ /* @__PURE__ */ t.jsx(ge, { asChild: !0, children: /* @__PURE__ */ t.jsx(
354
+ H,
355
+ {
356
+ type: "button",
357
+ size: "icon",
358
+ variant: "secondary",
359
+ className: "h-9 w-9 bg-zinc-800 text-zinc-100 hover:bg-zinc-700",
360
+ onClick: e.onClick,
361
+ disabled: e.disabled,
362
+ "aria-label": e.label,
363
+ title: e.label,
364
+ children: /* @__PURE__ */ t.jsx(d, { className: "h-4 w-4" })
365
+ }
366
+ ) }),
367
+ /* @__PURE__ */ t.jsx(we, { children: e.label })
368
+ ] }, e.key);
369
+ }) }) })
370
+ ] }),
371
+ /* @__PURE__ */ t.jsx(
372
+ "div",
373
+ {
374
+ ref: w,
375
+ className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden rounded-xl border border-zinc-800 bg-[radial-gradient(circle_at_top,_rgba(255,255,255,0.08),_transparent_40%),linear-gradient(180deg,_rgba(24,24,27,0.9),_rgba(9,9,11,1))] p-4 touch-none",
376
+ onPointerDown: le,
377
+ onPointerMove: se,
378
+ onPointerUp: V,
379
+ onPointerCancel: V,
380
+ children: c ? /* @__PURE__ */ t.jsxs("div", { className: "flex flex-col items-center gap-2 text-center", children: [
381
+ /* @__PURE__ */ t.jsx("div", { className: "rounded-full border border-red-500/40 bg-red-500/10 p-3 text-red-300", children: /* @__PURE__ */ t.jsx(K, { className: "h-5 w-5" }) }),
382
+ /* @__PURE__ */ t.jsx("p", { className: "text-sm font-medium", children: a.imageLoadError }),
383
+ /* @__PURE__ */ t.jsx("p", { className: "max-w-md text-xs text-zinc-400", children: n })
384
+ ] }) : /* @__PURE__ */ t.jsx(
385
+ "img",
386
+ {
387
+ ref: S,
388
+ src: n,
389
+ alt: W,
390
+ className: xe(
391
+ "max-h-full max-w-full select-none rounded-lg object-contain shadow-2xl",
392
+ y === "fit" ? "h-auto w-auto" : ""
393
+ ),
394
+ style: ae,
395
+ onError: () => x(!0),
396
+ draggable: !1
397
+ }
398
+ )
399
+ }
400
+ )
401
+ ]
402
+ }
403
+ ) });
404
+ }
405
+ function Ge() {
406
+ return (l) => {
407
+ te(l, "element", (s, n, o) => {
408
+ if (s.tagName === "p" && o && typeof n == "number" && s.children.some(
409
+ (m) => m.type === "element" && (G(m) || m.tagName === "pre")
410
+ )) {
411
+ const m = [];
412
+ let b = [];
413
+ const a = () => {
414
+ b.length > 0 && (m.push({
415
+ type: "element",
416
+ tagName: "p",
417
+ properties: {},
418
+ children: b
419
+ }), b = []);
420
+ };
421
+ for (const w of s.children)
422
+ w.type === "element" && (G(w) || w.tagName === "pre") ? (a(), m.push(w)) : b.push(w);
423
+ return a(), o.children.splice(n, 1, ...m), [Ie, n];
424
+ }
425
+ });
426
+ };
427
+ }
428
+ function G(l) {
429
+ if ((l.properties || {}).isComponent) return !0;
430
+ const n = l.tagName;
431
+ return n.charAt(0) === n.charAt(0).toUpperCase() && n.charAt(0) !== n.charAt(0).toLowerCase();
432
+ }
433
+ function et(l) {
434
+ return l.replace(/<([A-Z][a-zA-Z0-9]*(?:\.[A-Z][a-zA-Z0-9]*)*)(\s+[^>]*)>([\s\S]*?)<\/\1>/g, (s, n, o, i) => {
435
+ const m = ee(o), b = n.toLowerCase().replace(/\./g, "-");
436
+ return `<${b}${m}>${i}</${b}>`;
437
+ }).replace(/<([A-Z][a-zA-Z0-9]*(?:\.[A-Z][a-zA-Z0-9]*)*)(\s+[^>]*?)\s*\/>/g, (s, n, o) => {
438
+ const i = ee(o), m = n.toLowerCase().replace(/\./g, "-");
439
+ return `<${m}${i}></${m}>`;
440
+ });
441
+ }
442
+ function ee(l) {
443
+ if (!l) return "";
444
+ const s = [], n = /(\w+)=(?:{([^}]+)}|"([^"]*)"|'([^']*)')/g;
445
+ let o;
446
+ for (; (o = n.exec(l)) !== null; ) {
447
+ const [, i, m, b, a] = o, w = m || b || a || "";
448
+ s.push(`data-${i}="${w}"`);
449
+ }
450
+ return s.length > 0 ? " " + s.join(" ") : "";
451
+ }
452
+ function tt(l) {
453
+ const s = {};
454
+ for (const [n, o] of Object.entries(l))
455
+ if (n.startsWith("data-")) {
456
+ const i = n.slice(5);
457
+ if (o === "true")
458
+ s[i] = !0;
459
+ else if (o === "false")
460
+ s[i] = !1;
461
+ else if (o === "null")
462
+ s[i] = null;
463
+ else if (o === "undefined")
464
+ s[i] = void 0;
465
+ else if (!isNaN(Number(o)) && o !== "")
466
+ s[i] = Number(o);
467
+ else if (o.startsWith("[") && o.endsWith("]"))
468
+ try {
469
+ s[i] = JSON.parse(o);
470
+ } catch {
471
+ s[i] = o;
472
+ }
473
+ else if (o.startsWith("{") && o.endsWith("}"))
474
+ try {
475
+ s[i] = JSON.parse(o);
476
+ } catch {
477
+ s[i] = o;
478
+ }
479
+ else
480
+ s[i] = o;
481
+ }
482
+ return s;
483
+ }
484
+ const rt = {
485
+ js: "JavaScript",
486
+ javascript: "JavaScript",
487
+ ts: "TypeScript",
488
+ typescript: "TypeScript",
489
+ jsx: "JSX",
490
+ tsx: "TSX",
491
+ bash: "Bash",
492
+ shell: "Shell",
493
+ sh: "Shell",
494
+ python: "Python",
495
+ py: "Python",
496
+ java: "Java",
497
+ c: "C",
498
+ cpp: "C++",
499
+ csharp: "C#",
500
+ go: "Go",
501
+ rust: "Rust",
502
+ ruby: "Ruby",
503
+ php: "PHP",
504
+ swift: "Swift",
505
+ kotlin: "Kotlin",
506
+ sql: "SQL",
507
+ json: "JSON",
508
+ yaml: "YAML",
509
+ yml: "YAML",
510
+ toml: "TOML",
511
+ markdown: "Markdown",
512
+ md: "Markdown",
513
+ html: "HTML",
514
+ css: "CSS",
515
+ scss: "SCSS",
516
+ less: "Less",
517
+ vue: "Vue",
518
+ svelte: "Svelte",
519
+ docker: "Docker",
520
+ dockerfile: "Dockerfile",
521
+ nginx: "Nginx",
522
+ xml: "XML",
523
+ diff: "Diff",
524
+ text: "Text"
525
+ };
526
+ function nt({
527
+ className: l,
528
+ children: s,
529
+ meta: n,
530
+ codeHighlight: o,
531
+ shikiBundle: i
532
+ }) {
533
+ const [m, b] = r.useState(""), [a, w] = r.useState(!1), [S, g] = r.useState(!1), j = r.useMemo(() => n?.toLowerCase().includes("showlinenumbers") ?? !1, [n]), u = /language-(\w+)/.exec(l || ""), p = u ? u[1] : "text", y = Ce(p), f = rt[p.toLowerCase()] || p.toUpperCase(), k = r.useMemo(() => {
534
+ let c = "";
535
+ return typeof s == "string" ? c = s : r.Children.count(s) === 1 && typeof s == "string" ? c = String(s) : c = r.Children.toArray(s).map((x) => {
536
+ if (typeof x == "string") return x;
537
+ if (typeof x == "object" && x !== null && "props" in x) {
538
+ const h = x.props;
539
+ if (h?.node?.type === "element") {
540
+ const L = h.node.tagName || "span", z = h.children;
541
+ if (Array.isArray(z) && z.length === 0)
542
+ return `<${L} />`;
543
+ const M = z.map((v) => typeof v == "string" ? v : v?.type === "text" && v.value || "").join("");
544
+ return `<${L}>${M}</${L}>`;
545
+ }
546
+ }
547
+ return "";
548
+ }).join(""), c.replace(/^\n+/, "").replace(/\n+$/, "");
549
+ }, [s]);
550
+ r.useEffect(() => {
551
+ const c = () => {
552
+ w(document.documentElement.classList.contains("dark"));
553
+ };
554
+ c();
555
+ const x = new MutationObserver(() => c());
556
+ return x.observe(document.documentElement, { attributes: !0, attributeFilter: ["class"] }), () => x.disconnect();
557
+ }, []), r.useEffect(() => {
558
+ const c = Ne(a, o, i);
559
+ je(
560
+ k,
561
+ { lang: y, theme: c, showLineNumbers: j },
562
+ o,
563
+ i
564
+ ).then(b);
565
+ }, [k, y, a, j, o, i]);
566
+ const N = r.useCallback(async () => {
567
+ const c = async (x) => {
568
+ if (navigator.clipboard && window.isSecureContext)
569
+ await navigator.clipboard.writeText(x);
570
+ else {
571
+ const h = document.createElement("textarea");
572
+ h.value = x, h.style.position = "fixed", h.style.left = "-9999px", h.style.top = "-9999px", document.body.appendChild(h), h.focus(), h.select();
573
+ try {
574
+ document.execCommand("copy");
575
+ } finally {
576
+ document.body.removeChild(h);
577
+ }
578
+ }
579
+ };
580
+ try {
581
+ await c(k), g(!0), setTimeout(() => g(!1), 2e3);
582
+ } catch (x) {
583
+ console.error("Failed to copy:", x);
584
+ }
585
+ }, [k]);
586
+ return m ? /* @__PURE__ */ t.jsxs("div", { className: "code-block-wrapper", children: [
587
+ /* @__PURE__ */ t.jsx("span", { className: "code-lang-label", children: f }),
588
+ /* @__PURE__ */ t.jsx(
589
+ "button",
590
+ {
591
+ className: "code-copy-btn",
592
+ onClick: N,
593
+ title: S ? "已复制" : "复制代码",
594
+ "aria-label": "复制代码",
595
+ children: S ? /* @__PURE__ */ t.jsx(Ye, { className: "h-4 w-4 text-green-500" }) : /* @__PURE__ */ t.jsx(Je, { className: "h-4 w-4" })
596
+ }
597
+ ),
598
+ /* @__PURE__ */ t.jsx(
599
+ "pre",
600
+ {
601
+ className: `shiki-code-block${j ? " show-line-numbers" : ""}`,
602
+ dangerouslySetInnerHTML: { __html: m }
603
+ }
604
+ )
605
+ ] }) : /* @__PURE__ */ t.jsx("div", { className: "code-block-wrapper", children: /* @__PURE__ */ t.jsx("pre", { className: "shiki-code-block", children: /* @__PURE__ */ t.jsx("code", { children: k }) }) });
606
+ }
607
+ function ot({
608
+ lang: l,
609
+ viewerConfig: s,
610
+ src: n,
611
+ alt: o,
612
+ title: i,
613
+ className: m,
614
+ node: b,
615
+ ...a
616
+ }) {
617
+ const [w, S] = r.useState(!1), g = r.useMemo(
618
+ () => re(l, s?.labels),
619
+ [l, s?.labels]
620
+ );
621
+ return n ? s?.enabled === !1 ? /* @__PURE__ */ t.jsx(
622
+ "img",
623
+ {
624
+ src: n,
625
+ alt: o || g.imageAltFallback,
626
+ title: i,
627
+ className: m,
628
+ ...a
629
+ }
630
+ ) : /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
631
+ /* @__PURE__ */ t.jsxs("span", { className: "not-prose group relative my-6 block", children: [
632
+ /* @__PURE__ */ t.jsx(
633
+ "button",
634
+ {
635
+ type: "button",
636
+ className: "block w-full cursor-zoom-in overflow-hidden rounded-2xl border border-border/60 bg-muted/20 shadow-sm transition duration-200 hover:-translate-y-0.5 hover:shadow-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
637
+ onClick: () => S(!0),
638
+ "aria-label": g.preview,
639
+ title: g.preview,
640
+ children: /* @__PURE__ */ t.jsx(
641
+ "img",
642
+ {
643
+ src: n,
644
+ alt: o || g.imageAltFallback,
645
+ title: i,
646
+ className: m ?? "h-auto w-full rounded-2xl object-contain",
647
+ ...a
648
+ }
649
+ )
650
+ }
651
+ ),
652
+ /* @__PURE__ */ t.jsxs(
653
+ "button",
654
+ {
655
+ type: "button",
656
+ className: "absolute right-3 top-3 inline-flex items-center gap-2 rounded-full border border-white/20 bg-black/65 px-3 py-1.5 text-xs font-medium text-white opacity-0 shadow-lg transition group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70",
657
+ onClick: () => S(!0),
658
+ "aria-label": g.preview,
659
+ children: [
660
+ /* @__PURE__ */ t.jsx("span", { className: "sr-only", children: g.preview }),
661
+ /* @__PURE__ */ t.jsxs(
662
+ "svg",
663
+ {
664
+ "aria-hidden": "true",
665
+ viewBox: "0 0 24 24",
666
+ className: "h-3.5 w-3.5",
667
+ fill: "none",
668
+ stroke: "currentColor",
669
+ strokeWidth: "2",
670
+ strokeLinecap: "round",
671
+ strokeLinejoin: "round",
672
+ children: [
673
+ /* @__PURE__ */ t.jsx("path", { d: "M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6-10-6-10-6Z" }),
674
+ /* @__PURE__ */ t.jsx("circle", { cx: "12", cy: "12", r: "3" })
675
+ ]
676
+ }
677
+ ),
678
+ /* @__PURE__ */ t.jsx("span", { children: g.preview })
679
+ ]
680
+ }
681
+ )
682
+ ] }),
683
+ /* @__PURE__ */ t.jsx(
684
+ qe,
685
+ {
686
+ open: w,
687
+ onOpenChange: S,
688
+ src: n,
689
+ alt: o,
690
+ title: i,
691
+ lang: l,
692
+ labels: s?.labels
693
+ }
694
+ )
695
+ ] }) : null;
696
+ }
697
+ function gt({
698
+ source: l,
699
+ skipFirstH1: s = !1,
700
+ imageViewer: n,
701
+ codeHighlight: o,
702
+ shikiBundle: i
703
+ }) {
704
+ const b = De().lang || "zh-cn", a = ye();
705
+ r.useEffect(() => {
706
+ ke(o, i);
707
+ }, [o, i]);
708
+ const w = r.useMemo(() => {
709
+ if (!s) return l;
710
+ const u = l.split(`
711
+ `);
712
+ let p = !1;
713
+ return u.filter((f) => !p && f.startsWith("# ") ? (p = !0, !1) : !0).join(`
714
+ `);
715
+ }, [l, s]), S = r.useMemo(() => et(w), [w]), g = r.useMemo(() => {
716
+ const u = /* @__PURE__ */ new Map();
717
+ return a && Object.entries(a).forEach(([p, y]) => {
718
+ const f = r.memo(({ children: k, ...N }) => {
719
+ const c = tt(N);
720
+ return r.createElement(y, c, k);
721
+ });
722
+ if (u.set(p, f), p.includes(".")) {
723
+ const [k, N] = p.split("."), c = `${k.toLowerCase()}-${N.toLowerCase()}`;
724
+ u.set(c, f);
725
+ }
726
+ }), u;
727
+ }, [a]), j = r.useMemo(() => Object.fromEntries(g), [g]);
728
+ return /* @__PURE__ */ t.jsx("div", { className: "prose dark:prose-invert max-w-none", children: /* @__PURE__ */ t.jsx(
729
+ ve,
730
+ {
731
+ remarkPlugins: [Le, Me],
732
+ rehypePlugins: [
733
+ Ee,
734
+ ze,
735
+ Be(j),
736
+ Ge,
737
+ [Se, { behavior: "append" }],
738
+ [Te, {
739
+ strict: !1,
740
+ trust: !0,
741
+ macros: {
742
+ "\\R": "\\mathbb{R}",
743
+ "\\N": "\\mathbb{N}",
744
+ "\\Z": "\\mathbb{Z}",
745
+ "\\Q": "\\mathbb{Q}",
746
+ "\\C": "\\mathbb{C}",
747
+ ...Ve
748
+ }
749
+ }]
750
+ ],
751
+ components: {
752
+ ...j,
753
+ table({ children: u, ...p }) {
754
+ return /* @__PURE__ */ t.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ t.jsx("table", { ...p, children: u }) });
755
+ },
756
+ // 使用 Shiki 渲染代码块 - 在 pre 组件中处理
757
+ pre({ children: u, ...p }) {
758
+ const y = r.Children.toArray(u).find(
759
+ (f) => f?.type === "code" || f?.props?.node?.tagName === "code"
760
+ );
761
+ if (y) {
762
+ const f = y.props, k = f?.className || "", N = f?.node;
763
+ let c = f?.children;
764
+ const x = f?.["data-raw-value"];
765
+ x && (c = x);
766
+ const h = N?.data?.meta || "";
767
+ return /* @__PURE__ */ t.jsx(
768
+ nt,
769
+ {
770
+ className: k,
771
+ meta: h,
772
+ codeHighlight: o,
773
+ shikiBundle: i,
774
+ children: c
775
+ }
776
+ );
777
+ }
778
+ return /* @__PURE__ */ t.jsx("pre", { ...p, children: u });
779
+ },
780
+ a({ href: u, children: p, ...y }) {
781
+ if (!u) return /* @__PURE__ */ t.jsx("a", { ...y, children: p });
782
+ if (u.startsWith("#"))
783
+ return /* @__PURE__ */ t.jsx("a", { href: u, ...y, children: p });
784
+ if (/^(https?:)?\/\//i.test(u) || u.startsWith("mailto:") || u.startsWith("tel:"))
785
+ return /* @__PURE__ */ t.jsx("a", { href: u, target: "_blank", rel: "noopener noreferrer", ...y, children: p });
786
+ const k = u.startsWith("/") ? u : `/${u}`, N = `/${b}${k}`;
787
+ return /* @__PURE__ */ t.jsx(Ae, { to: N, ...y, children: p });
788
+ },
789
+ img({ src: u, alt: p, title: y, className: f, node: k, ...N }) {
790
+ return /* @__PURE__ */ t.jsx(
791
+ ot,
792
+ {
793
+ lang: b,
794
+ viewerConfig: n,
795
+ src: u,
796
+ alt: p,
797
+ title: y,
798
+ className: f,
799
+ node: k,
800
+ ...N
801
+ }
802
+ );
803
+ }
804
+ },
805
+ children: S
806
+ }
807
+ ) });
808
+ }
809
+ export {
810
+ qe as I,
811
+ gt as M
812
+ };