react-docs-ui 0.6.14 → 0.6.15

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