import { t as e } from "./utils-Ct96Mtjw.js";
import { S as t, b as n, c as r, d as i, h as a, l as o, p as s, s as c, t as l, v as u, x as d, y as f } from "./mdx-components-m1cGPhc8.js";
import { t as p } from "./use-toast-DK69oadB.js";
import { l as m, r as h, t as g, u as _ } from "./dialog-D8otbqQL.js";
import * as v from "react";
import { Check as y, Copy as b, Download as x, ExternalLink as S, Maximize as ee, Minimize as te, RefreshCw as ne, RotateCcw as re, RotateCw as ie, Search as ae, X as oe, ZoomIn as se, ZoomOut as ce } from "lucide-react";
import { Link as le, useParams as C } from "react-router-dom";
import { Fragment as w, jsx as T, jsxs as E } from "react/jsx-runtime";
import D from "remark-gfm";
import O from "remark-math";
import k from "react-markdown";
import A from "rehype-autolink-headings";
import j from "rehype-slug";
import M from "rehype-raw";
import N from "rehype-katex";
import { SKIP as P, visit as F } from "unist-util-visit";
import I from "katex-physics";
//#region src/lib/rehype-component.ts
function L(e) {
	let t = /* @__PURE__ */ new Map();
	for (let [n] of Object.entries(e)) {
		let e = n.toLowerCase(), r = e.replace(/\./g, "-");
		t.set(e, n), t.set(r, n);
	}
	return () => (e) => {
		F(e, "element", (e) => {
			let n = e.tagName.toLowerCase(), r = t.get(n);
			r && (e.tagName = r, e.properties = e.properties || {}, e.properties.isComponent = !0);
		});
	};
}
//#endregion
//#region src/lib/image-viewer.ts
var R = {
	"zh-cn": {
		preview: "预览图片",
		zoomIn: "放大",
		zoomOut: "缩小",
		fit: "适配窗口",
		actualSize: "原始比例",
		reset: "重置",
		rotateLeft: "左旋",
		rotateRight: "右旋",
		fullscreen: "全屏",
		download: "下载",
		openInNewTab: "新标签打开",
		close: "关闭图片查看器",
		imageAltFallback: "文档图片",
		downloadSuccess: "图片下载已开始",
		downloadError: "当前图片无法直接下载，请尝试新标签打开。",
		fullscreenError: "当前浏览器不支持全屏，已保留对话框预览。",
		openInNewTabError: "无法在新标签页打开图片。",
		imageLoadError: "图片加载失败"
	},
	en: {
		preview: "Preview image",
		zoomIn: "Zoom in",
		zoomOut: "Zoom out",
		fit: "Fit to viewport",
		actualSize: "Actual size",
		reset: "Reset",
		rotateLeft: "Rotate left",
		rotateRight: "Rotate right",
		fullscreen: "Fullscreen",
		download: "Download",
		openInNewTab: "Open in new tab",
		close: "Close image viewer",
		imageAltFallback: "Documentation image",
		downloadSuccess: "Image download started",
		downloadError: "This image cannot be downloaded directly. Try opening it in a new tab.",
		fullscreenError: "Fullscreen is not available in this browser. Dialog preview is still available.",
		openInNewTabError: "Unable to open the image in a new tab.",
		imageLoadError: "Failed to load image"
	}
};
function ue(e = "zh-cn", t) {
	return {
		...R[e === "en" ? "en" : "zh-cn"],
		...t
	};
}
//#endregion
//#region src/components/ImageViewer.tsx
var de = .2, fe = 5, pe = .2;
function z(e) {
	return Math.min(fe, Math.max(de, Number(e.toFixed(2))));
}
function me(e, t, n) {
	let r = (t || n || "image").trim().split("").map((e) => e.charCodeAt(0) < 32 || "<>:\"/\\|?*".includes(e) ? "-" : e).join("");
	return (e.split("?")[0]?.split("#")[0] ?? e).split("/").pop()?.trim() || r || "image";
}
function he(e, t) {
	let n = document.createElement("a");
	n.href = e, n.download = t, n.rel = "noopener noreferrer", document.body.appendChild(n), n.click(), document.body.removeChild(n);
}
function ge(e) {
	if (e.startsWith("blob:") || e.startsWith("data:")) return !0;
	try {
		return new URL(e, window.location.href).origin === window.location.origin;
	} catch {
		return !1;
	}
}
function B({ open: r, onOpenChange: i, src: a, alt: o, title: s, lang: c = "zh-cn", labels: l }) {
	let y = v.useMemo(() => ue(c, l), [c, l]), b = v.useRef(null), le = v.useRef(null), [C, w] = v.useState(1), [D, O] = v.useState(0), [k, A] = v.useState("fit"), [j, M] = v.useState(!1), [N, P] = v.useState(!1), [F, I] = v.useState({
		x: 0,
		y: 0
	}), [L, R] = v.useState(!1), B = v.useRef(/* @__PURE__ */ new Map()), V = v.useRef(null), H = v.useRef(null), U = o?.trim() || s?.trim() || y.imageAltFallback, W = v.useCallback(() => {
		w(1), O(0), A("fit"), P(!1), I({
			x: 0,
			y: 0
		}), R(!1), B.current.clear(), V.current = null, H.current = null;
	}, []);
	v.useEffect(() => {
		if (r) {
			W();
			return;
		}
		M(!1);
	}, [r, W]), v.useEffect(() => {
		document.fullscreenElement || M(!1);
	}, [r]), v.useEffect(() => {
		let e = () => {
			M(!!document.fullscreenElement);
		};
		return document.addEventListener("fullscreenchange", e), () => {
			document.removeEventListener("fullscreenchange", e);
		};
	}, []);
	let _e = v.useMemo(() => ({
		transform: `translate(${F.x}px, ${F.y}px) scale(${C}) rotate(${D}deg)`,
		transition: L ? "none" : "transform 160ms ease",
		cursor: N ? "default" : L ? "grabbing" : "grab"
	}), [
		L,
		N,
		D,
		C,
		F.x,
		F.y
	]), G = v.useCallback(() => {
		A("actual"), w((e) => z(e + pe));
	}, []), K = v.useCallback(() => {
		A("actual"), w((e) => z(e - pe));
	}, []), q = v.useCallback(() => {
		A("fit"), w(1), I({
			x: 0,
			y: 0
		});
	}, []), J = v.useCallback(() => {
		A("actual"), w(1), I({
			x: 0,
			y: 0
		});
	}, []), Y = v.useCallback(() => {
		O((e) => e - 90);
	}, []), X = v.useCallback(() => {
		O((e) => e + 90);
	}, []), Z = v.useCallback(async () => {
		let e = me(a, s, o), t = null;
		try {
			if (ge(a)) {
				he(a, e), p({ description: y.downloadSuccess });
				return;
			}
		} catch {}
		try {
			let n = await fetch(a, { mode: "cors" });
			if (!n.ok) throw Error(`Failed to fetch image: ${n.status}`);
			let r = await n.blob();
			t = URL.createObjectURL(r), he(t, e), p({ description: y.downloadSuccess });
		} catch {
			p({
				variant: "destructive",
				description: y.downloadError
			});
		} finally {
			t && URL.revokeObjectURL(t);
		}
	}, [
		o,
		y.downloadError,
		y.downloadSuccess,
		a,
		s
	]), ve = v.useCallback(() => {
		try {
			window.open(a, "_blank", "noopener,noreferrer");
		} catch {
			p({
				variant: "destructive",
				description: y.openInNewTabError
			});
		}
	}, [y.openInNewTabError, a]), Q = v.useCallback(async () => {
		let e = b.current;
		if (!e?.requestFullscreen) {
			p({ description: y.fullscreenError });
			return;
		}
		try {
			document.fullscreenElement ? await document.exitFullscreen() : await e.requestFullscreen();
		} catch {
			p({ description: y.fullscreenError });
		}
	}, [y.fullscreenError]);
	v.useEffect(() => {
		if (!r) return;
		let e = (e) => {
			e.key === "+" ? (e.preventDefault(), G()) : e.key === "-" ? (e.preventDefault(), K()) : e.key === "0" ? (e.preventDefault(), W()) : e.key === "f" || e.key === "F" ? (e.preventDefault(), Q()) : e.key === "[" ? (e.preventDefault(), Y()) : e.key === "]" && (e.preventDefault(), X());
		};
		return window.addEventListener("keydown", e), () => {
			window.removeEventListener("keydown", e);
		};
	}, [
		Q,
		r,
		W,
		Y,
		X,
		G,
		K
	]);
	let $ = v.useCallback((e) => {
		e.preventDefault(), e.stopPropagation(), e.deltaY < 0 ? G() : K();
	}, [G, K]);
	v.useEffect(() => {
		if (!r) return;
		let e = b.current;
		if (e) return e.addEventListener("wheel", $, { passive: !1 }), () => {
			e.removeEventListener("wheel", $);
		};
	}, [$, r]);
	let ye = v.useCallback((e) => {
		B.current.set(e.pointerId, {
			x: e.clientX,
			y: e.clientY
		});
		let t = Array.from(B.current.values());
		if (t.length === 2 && H.current) {
			let [e, n] = t, r = Math.hypot(n.x - e.x, n.y - e.y), i = z(H.current.startScale * (r / H.current.startDistance));
			A("actual"), w(i);
			return;
		}
		let n = V.current;
		!n || n.pointerId !== e.pointerId || I({
			x: n.originX + (e.clientX - n.startX),
			y: n.originY + (e.clientY - n.startY)
		});
	}, []), be = v.useCallback((e) => {
		e && b.current?.hasPointerCapture(e.pointerId) && b.current.releasePointerCapture(e.pointerId), e && B.current.delete(e.pointerId), V.current = null, B.current.size < 2 && (H.current = null), R(!1);
	}, []), xe = v.useCallback((e) => {
		if (e.button !== 0 || N) return;
		e.preventDefault(), e.stopPropagation(), e.currentTarget.setPointerCapture(e.pointerId), B.current.set(e.pointerId, {
			x: e.clientX,
			y: e.clientY
		});
		let t = Array.from(B.current.values());
		if (t.length === 2) {
			let [e, n] = t;
			H.current = {
				startDistance: Math.max(1, Math.hypot(n.x - e.x, n.y - e.y)),
				startScale: C
			}, V.current = null, R(!1);
			return;
		}
		V.current = {
			pointerId: e.pointerId,
			startX: e.clientX,
			startY: e.clientY,
			originX: F.x,
			originY: F.y
		}, R(!0);
	}, [
		N,
		C,
		F.x,
		F.y
	]);
	v.useEffect(() => {
		if (!r) return;
		let e = (e) => {
			let t = b.current, n = e.target;
			!t || !(n instanceof Node) || !t.contains(n) || !e.ctrlKey || $(e);
		};
		return window.addEventListener("wheel", e, {
			passive: !1,
			capture: !0
		}), () => {
			window.removeEventListener("wheel", e, { capture: !0 });
		};
	}, [$, r]);
	let Se = v.useMemo(() => [
		{
			key: "zoom-in",
			label: y.zoomIn,
			icon: se,
			onClick: G,
			disabled: N || C >= fe
		},
		{
			key: "zoom-out",
			label: y.zoomOut,
			icon: ce,
			onClick: K,
			disabled: N || C <= de
		},
		{
			key: "fit",
			label: y.fit,
			icon: te,
			onClick: q,
			disabled: N
		},
		{
			key: "actual-size",
			label: y.actualSize,
			icon: ae,
			onClick: J,
			disabled: N
		},
		{
			key: "reset",
			label: y.reset,
			icon: ne,
			onClick: W,
			disabled: N
		},
		{
			key: "rotate-left",
			label: y.rotateLeft,
			icon: re,
			onClick: Y,
			disabled: N
		},
		{
			key: "rotate-right",
			label: y.rotateRight,
			icon: ie,
			onClick: X,
			disabled: N
		},
		{
			key: "fullscreen",
			label: y.fullscreen,
			icon: ee,
			onClick: () => void Q(),
			disabled: !1
		},
		{
			key: "download",
			label: y.download,
			icon: x,
			onClick: Z,
			disabled: N
		},
		{
			key: "new-tab",
			label: y.openInNewTab,
			icon: S,
			onClick: ve,
			disabled: !1
		}
	], [
		Z,
		Q,
		ve,
		N,
		y.actualSize,
		y.download,
		y.fit,
		y.fullscreen,
		y.openInNewTab,
		y.reset,
		y.rotateLeft,
		y.rotateRight,
		y.zoomIn,
		y.zoomOut,
		W,
		Y,
		X,
		C,
		J,
		q,
		G,
		K
	]);
	return /* @__PURE__ */ T(g, {
		open: r,
		onOpenChange: i,
		children: /* @__PURE__ */ E(h, {
			showCloseButton: !1,
			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",
			children: [
				/* @__PURE__ */ T(_, { children: U }),
				/* @__PURE__ */ T(m, { children: y.close }),
				/* @__PURE__ */ E(n, {
					delayDuration: 100,
					children: [/* @__PURE__ */ E("div", {
						className: "flex items-center justify-between gap-3 rounded-lg border border-zinc-800 bg-zinc-900/80 px-3 py-2",
						children: [/* @__PURE__ */ E("div", {
							className: "min-w-0",
							children: [/* @__PURE__ */ T("p", {
								className: "truncate text-sm font-medium",
								children: U
							}), /* @__PURE__ */ E("p", {
								className: "text-xs text-zinc-400",
								children: [
									k === "fit" ? y.fit : `${Math.round(C * 100)}%`,
									D === 0 ? "" : ` · ${D}deg`,
									j ? ` · ${y.fullscreen}` : ""
								]
							})]
						}), /* @__PURE__ */ T(t, {
							type: "button",
							size: "icon",
							variant: "ghost",
							className: "h-9 w-9 shrink-0 text-zinc-100 hover:bg-zinc-800 hover:text-white",
							onClick: () => i(!1),
							"aria-label": y.close,
							title: y.close,
							children: /* @__PURE__ */ T(oe, { className: "h-4 w-4" })
						})]
					}), /* @__PURE__ */ T("div", {
						className: "overflow-x-auto rounded-lg border border-zinc-800 bg-zinc-900/80 px-2 py-2",
						children: /* @__PURE__ */ T("div", {
							className: "flex min-w-max items-center gap-2",
							children: Se.map((e) => {
								let n = e.icon;
								return /* @__PURE__ */ E(u, { children: [/* @__PURE__ */ T(d, {
									asChild: !0,
									children: /* @__PURE__ */ T(t, {
										type: "button",
										size: "icon",
										variant: "secondary",
										className: "h-9 w-9 bg-zinc-800 text-zinc-100 hover:bg-zinc-700",
										onClick: e.onClick,
										disabled: e.disabled,
										"aria-label": e.label,
										title: e.label,
										children: /* @__PURE__ */ T(n, { className: "h-4 w-4" })
									})
								}), /* @__PURE__ */ T(f, { children: e.label })] }, e.key);
							})
						})
					})]
				}),
				/* @__PURE__ */ T("div", {
					ref: b,
					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",
					onPointerDown: xe,
					onPointerMove: ye,
					onPointerUp: be,
					onPointerCancel: be,
					children: N ? /* @__PURE__ */ E("div", {
						className: "flex flex-col items-center gap-2 text-center",
						children: [
							/* @__PURE__ */ T("div", {
								className: "rounded-full border border-red-500/40 bg-red-500/10 p-3 text-red-300",
								children: /* @__PURE__ */ T(ae, { className: "h-5 w-5" })
							}),
							/* @__PURE__ */ T("p", {
								className: "text-sm font-medium",
								children: y.imageLoadError
							}),
							/* @__PURE__ */ T("p", {
								className: "max-w-md text-xs text-zinc-400",
								children: a
							})
						]
					}) : /* @__PURE__ */ T("img", {
						ref: le,
						src: a,
						alt: U,
						className: e("max-h-full max-w-full select-none rounded-lg object-contain shadow-2xl", k === "fit" ? "h-auto w-auto" : ""),
						style: _e,
						onError: () => P(!0),
						draggable: !1
					})
				})
			]
		})
	});
}
//#endregion
//#region src/components/MdxContent.tsx
function V() {
	return (e) => {
		F(e, "element", (e, t, n) => {
			if (e.tagName === "p" && n && typeof t == "number" && e.children.some((e) => e.type === "element" && (H(e) || e.tagName === "pre"))) {
				let r = [], i = [], a = () => {
					i.length > 0 && (r.push({
						type: "element",
						tagName: "p",
						properties: {},
						children: i
					}), i = []);
				};
				for (let t of e.children) t.type === "element" && (H(t) || t.tagName === "pre") ? (a(), r.push(t)) : i.push(t);
				return a(), n.children.splice(t, 1, ...r), [P, t];
			}
		});
	};
}
function H(e) {
	if ((e.properties || {}).isComponent) return !0;
	let t = e.tagName;
	return t.charAt(0) === t.charAt(0).toUpperCase() && t.charAt(0) !== t.charAt(0).toLowerCase();
}
function U(e) {
	if (typeof e == "number" && Number.isFinite(e)) return `${e}px`;
	if (typeof e != "string") return;
	let t = e.trim();
	if (t) return /^\d+(\.\d+)?$/.test(t) ? `${t}px` : t;
}
function W(e) {
	if (typeof e == "boolean") return e;
	if (typeof e != "string") return;
	let t = e.trim().toLowerCase();
	if ([
		"true",
		"1",
		"yes",
		"on"
	].includes(t)) return !0;
	if ([
		"false",
		"0",
		"no",
		"off"
	].includes(t)) return !1;
}
function _e(e, t) {
	let n = {
		title: e,
		width: U(t?.width),
		height: U(t?.height),
		inline: W(t?.["data-inline"] ?? t?.inline),
		offsetX: U(t?.["data-offset-x"] ?? t?.offsetX ?? t?.offsetx ?? t?.x),
		offsetY: U(t?.["data-offset-y"] ?? t?.offsetY ?? t?.offsety ?? t?.y),
		preview: W(t?.["data-preview"] ?? t?.preview)
	};
	if (!e || !/(^|\s)(width|height|w|h|size|preview|inline|x|y|offsetx|offsety)=/i.test(e)) return n;
	let r = e;
	return r = r.replace(/(^|\s)(width|height|w|h|size|preview|inline|x|y|offsetx|offsety)=(?:"([^"]+)"|'([^']+)'|([^\s]+))/gi, (e, t, r, i, a, o) => {
		let s = String(r).toLowerCase(), c = i ?? a ?? o ?? "";
		if (s === "preview") n.preview = W(c) ?? n.preview;
		else if (s === "inline") n.inline = W(c) ?? n.inline;
		else if (s === "size") {
			let [e, t] = c.split("x");
			n.width = U(e) ?? n.width, n.height = U(t ?? e) ?? n.height;
		} else s === "width" || s === "w" ? n.width = U(c) ?? n.width : s === "height" || s === "h" ? n.height = U(c) ?? n.height : s === "x" || s === "offsetx" ? n.offsetX = U(c) ?? n.offsetX : (s === "y" || s === "offsety") && (n.offsetY = U(c) ?? n.offsetY);
		return t;
	}), n.title = r.replace(/\s{2,}/g, " ").trim() || void 0, n;
}
function G(e) {
	let t = e, n = "";
	for (; t !== n;) n = t, t = t.replace(/<([A-Z][a-zA-Z0-9]*(?:\.[A-Z][a-zA-Z0-9]*)*)(\s+[^>]*)>([\s\S]*?)<\/\1>/g, (e, t, n, r) => {
		let i = K(n), a = t.toLowerCase().replace(/\./g, "-");
		return `<${a}${i}>${r}</${a}>`;
	}).replace(/<([A-Z][a-zA-Z0-9]*(?:\.[A-Z][a-zA-Z0-9]*)*)(\s+[^>]*?)\s*\/>/g, (e, t, n) => {
		let r = K(n), i = t.toLowerCase().replace(/\./g, "-");
		return `<${i}${r}></${i}>`;
	});
	return t;
}
function K(e) {
	if (!e) return "";
	let t = [], n = /(\w+)=(?:{([^}]+)}|"([^"]*)"|'([^']*)')/g, r;
	for (; (r = n.exec(e)) !== null;) {
		let [, e, n, i, a] = r, o = n || i || a || "";
		t.push(`data-${e}="${o}"`);
	}
	return t.length > 0 ? " " + t.join(" ") : "";
}
function q(e) {
	let t = {};
	for (let [n, r] of Object.entries(e)) if (n.startsWith("data-")) {
		let e = n.slice(5);
		if (r === "true") t[e] = !0;
		else if (r === "false") t[e] = !1;
		else if (r === "null") t[e] = null;
		else if (r === "undefined") t[e] = void 0;
		else if (!isNaN(Number(r)) && r !== "") t[e] = Number(r);
		else if (r.startsWith("[") && r.endsWith("]")) try {
			t[e] = JSON.parse(r);
		} catch {
			t[e] = r;
		}
		else if (r.startsWith("{") && r.endsWith("}")) try {
			t[e] = JSON.parse(r);
		} catch {
			t[e] = r;
		}
		else t[e] = r;
	}
	return t;
}
var J = {
	js: "JavaScript",
	javascript: "JavaScript",
	ts: "TypeScript",
	typescript: "TypeScript",
	jsx: "JSX",
	tsx: "TSX",
	bash: "Bash",
	shell: "Shell",
	sh: "Shell",
	python: "Python",
	py: "Python",
	java: "Java",
	c: "C",
	cpp: "C++",
	csharp: "C#",
	go: "Go",
	rust: "Rust",
	ruby: "Ruby",
	php: "PHP",
	swift: "Swift",
	kotlin: "Kotlin",
	sql: "SQL",
	json: "JSON",
	yaml: "YAML",
	yml: "YAML",
	toml: "TOML",
	markdown: "Markdown",
	md: "Markdown",
	html: "HTML",
	css: "CSS",
	scss: "SCSS",
	less: "Less",
	vue: "Vue",
	svelte: "Svelte",
	docker: "Docker",
	dockerfile: "Dockerfile",
	nginx: "Nginx",
	xml: "XML",
	diff: "Diff",
	text: "Text"
};
function Y({ className: e, children: t, meta: n, codeHighlight: r, shikiBundle: a }) {
	let [s, l] = v.useState(""), [u, d] = v.useState(!1), [f, p] = v.useState(!1), m = v.useMemo(() => n?.toLowerCase().includes("showlinenumbers") ?? !1, [n]), h = /language-(\w+)/.exec(e || ""), g = h ? h[1] : "text", _ = i(g), x = J[g.toLowerCase()] || g.toUpperCase(), S = v.useMemo(() => {
		let e = "";
		return e = typeof t == "string" ? t : v.Children.count(t) === 1 && typeof t == "string" ? String(t) : v.Children.toArray(t).map((e) => {
			if (typeof e == "string") return e;
			if (typeof e == "object" && e && "props" in e) {
				let t = e.props;
				if (t?.node?.type === "element") {
					let e = t.node.tagName || "span", n = t.children;
					return Array.isArray(n) && n.length === 0 ? `<${e} />` : `<${e}>${n.map((e) => typeof e == "string" ? e : e?.type === "text" && e.value || "").join("")}</${e}>`;
				}
			}
			return "";
		}).join(""), e.replace(/^\n+/, "").replace(/\n+$/, "");
	}, [t]);
	v.useEffect(() => {
		let e = () => {
			d(document.documentElement.classList.contains("dark"));
		};
		e();
		let t = new MutationObserver(() => e());
		return t.observe(document.documentElement, {
			attributes: !0,
			attributeFilter: ["class"]
		}), () => t.disconnect();
	}, []), v.useEffect(() => {
		o(S, {
			lang: _,
			theme: c(u, r, a),
			showLineNumbers: m
		}, r, a).then(l);
	}, [
		S,
		_,
		u,
		m,
		r,
		a
	]);
	let ee = v.useCallback(async () => {
		let e = async (e) => {
			if (navigator.clipboard && window.isSecureContext) await navigator.clipboard.writeText(e);
			else {
				let t = document.createElement("textarea");
				t.value = e, t.style.position = "fixed", t.style.left = "-9999px", t.style.top = "-9999px", document.body.appendChild(t), t.focus(), t.select();
				try {
					document.execCommand("copy");
				} finally {
					document.body.removeChild(t);
				}
			}
		};
		try {
			await e(S), p(!0), setTimeout(() => p(!1), 2e3);
		} catch (e) {
			console.error("Failed to copy:", e);
		}
	}, [S]);
	return s ? /* @__PURE__ */ E("div", {
		className: "code-block-wrapper",
		children: [
			/* @__PURE__ */ T("span", {
				className: "code-lang-label",
				children: x
			}),
			/* @__PURE__ */ T("button", {
				className: "code-copy-btn",
				onClick: ee,
				title: f ? "已复制" : "复制代码",
				"aria-label": "复制代码",
				children: f ? /* @__PURE__ */ T(y, { className: "h-4 w-4 text-green-500" }) : /* @__PURE__ */ T(b, { className: "h-4 w-4" })
			}),
			/* @__PURE__ */ T("pre", {
				className: `shiki-code-block${m ? " show-line-numbers" : ""}`,
				dangerouslySetInnerHTML: { __html: s }
			})
		]
	}) : /* @__PURE__ */ T("div", {
		className: "code-block-wrapper",
		children: /* @__PURE__ */ T("pre", {
			className: "shiki-code-block",
			children: /* @__PURE__ */ T("code", { children: S })
		})
	});
}
function X({ lang: e, viewerConfig: t, src: n, alt: r, title: i, className: a, node: o, ...s }) {
	let [c, l] = v.useState(!1), u = v.useMemo(() => ue(e, t?.labels), [e, t?.labels]), d = v.useMemo(() => _e(i, s), [s, i]), f = d.preview ?? t?.enabled !== !1, p = d.inline === !0, m = !!(d.width || d.height), h = v.useMemo(() => ({
		...s.style,
		width: d.width ?? s.style?.width,
		height: d.height ?? s.style?.height,
		transform: [s.style?.transform, d.offsetX || d.offsetY ? `translate(${d.offsetX ?? "0px"}, ${d.offsetY ?? "0px"})` : void 0].filter(Boolean).join(" ") || void 0
	}), [
		d.height,
		d.offsetX,
		d.offsetY,
		d.width,
		s.style
	]);
	return n ? f ? m || p ? /* @__PURE__ */ E(w, { children: [/* @__PURE__ */ T("button", {
		type: "button",
		className: "not-prose inline-flex max-w-full cursor-zoom-in align-middle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
		onClick: () => l(!0),
		"aria-label": u.preview,
		title: u.preview,
		children: /* @__PURE__ */ T("img", {
			...s,
			src: n,
			alt: r || u.imageAltFallback,
			title: d.title,
			className: a ?? (p ? "inline-block align-middle" : void 0),
			style: h
		})
	}), /* @__PURE__ */ T(B, {
		open: c,
		onOpenChange: l,
		src: n,
		alt: r,
		title: d.title,
		lang: e,
		labels: t?.labels
	})] }) : /* @__PURE__ */ E(w, { children: [/* @__PURE__ */ E("span", {
		className: "not-prose group relative my-6 block",
		children: [/* @__PURE__ */ T("button", {
			type: "button",
			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",
			onClick: () => l(!0),
			"aria-label": u.preview,
			title: u.preview,
			children: /* @__PURE__ */ T("img", {
				...s,
				src: n,
				alt: r || u.imageAltFallback,
				title: d.title,
				className: a ?? "h-auto w-full rounded-2xl object-contain",
				style: h
			})
		}), /* @__PURE__ */ E("button", {
			type: "button",
			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",
			onClick: () => l(!0),
			"aria-label": u.preview,
			children: [
				/* @__PURE__ */ T("span", {
					className: "sr-only",
					children: u.preview
				}),
				/* @__PURE__ */ E("svg", {
					"aria-hidden": "true",
					viewBox: "0 0 24 24",
					className: "h-3.5 w-3.5",
					fill: "none",
					stroke: "currentColor",
					strokeWidth: "2",
					strokeLinecap: "round",
					strokeLinejoin: "round",
					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", {
						cx: "12",
						cy: "12",
						r: "3"
					})]
				}),
				/* @__PURE__ */ T("span", { children: u.preview })
			]
		})]
	}), /* @__PURE__ */ T(B, {
		open: c,
		onOpenChange: l,
		src: n,
		alt: r,
		title: d.title,
		lang: e,
		labels: t?.labels
	})] }) : /* @__PURE__ */ T("img", {
		...s,
		src: n,
		alt: r || u.imageAltFallback,
		title: d.title,
		className: a ?? (p ? "inline-block align-middle" : void 0),
		style: h
	}) : null;
}
function Z({ source: e, skipFirstH1: t = !1, imageViewer: n, codeHighlight: i, shikiBundle: o }) {
	let c = C(), u = c.lang || "zh-cn", d = c.version, f = s();
	v.useEffect(() => {
		r(i, o);
	}, [i, o]);
	let p = v.useMemo(() => {
		if (!t) return e;
		let n = e.split("\n"), r = !1;
		return n.filter((e) => !r && e.startsWith("# ") ? (r = !0, !1) : !0).join("\n");
	}, [e, t]), m = v.useMemo(() => G(p), [p]), h = v.useMemo(() => {
		let e = /* @__PURE__ */ new Map();
		return f && Object.entries(f).forEach(([t, n]) => {
			let r = v.memo(({ children: e, ...t }) => {
				let r = q(t);
				return v.createElement(n, r, e);
			});
			if (e.set(t, r), e.set(t.toLowerCase(), r), t.includes(".")) {
				let [n, i] = t.split("."), a = `${n.toLowerCase()}-${i.toLowerCase()}`;
				e.set(a, r);
			}
		}), e;
	}, [f]), g = v.useMemo(() => Object.fromEntries(h), [h]);
	return /* @__PURE__ */ T("div", {
		className: "prose dark:prose-invert max-w-none",
		children: /* @__PURE__ */ T(k, {
			remarkPlugins: [D, O],
			rehypePlugins: [
				j,
				M,
				L(g),
				V,
				[A, { behavior: "append" }],
				[N, {
					strict: !1,
					trust: !0,
					macros: {
						"\\R": "\\mathbb{R}",
						"\\N": "\\mathbb{N}",
						"\\Z": "\\mathbb{Z}",
						"\\Q": "\\mathbb{Q}",
						"\\C": "\\mathbb{C}",
						...I
					}
				}]
			],
			components: {
				...g,
				table({ children: e, ...t }) {
					return /* @__PURE__ */ T("div", {
						className: "overflow-x-auto",
						children: /* @__PURE__ */ T("table", {
							...t,
							children: e
						})
					});
				},
				pre({ children: e, ...t }) {
					let n = v.Children.toArray(e).find((e) => e?.type === "code" || e?.props?.node?.tagName === "code");
					if (n) {
						let e = n.props, t = e?.className || "", r = /language-(\w+)/.exec(t), a = r ? r[1].toLowerCase() : "text", s = e?.node, c = e?.children, u = e?.["data-raw-value"];
						u && (c = u);
						let d = s?.data?.meta || "";
						return a === "mermaid" ? /* @__PURE__ */ T(l, { chart: typeof c == "string" ? c : String(c || "") }) : /* @__PURE__ */ T(Y, {
							className: t,
							meta: d,
							codeHighlight: i,
							shikiBundle: o,
							children: c
						});
					}
					return /* @__PURE__ */ T("pre", {
						...t,
						children: e
					});
				},
				a({ href: e, children: t, ...n }) {
					return e ? e.startsWith("#") ? /* @__PURE__ */ T("a", {
						href: e,
						...n,
						children: t
					}) : /^(https?:)?\/\//i.test(e) || e.startsWith("mailto:") || e.startsWith("tel:") ? /* @__PURE__ */ T("a", {
						href: e,
						target: "_blank",
						rel: "noopener noreferrer",
						...n,
						children: t
					}) : /* @__PURE__ */ T(le, {
						to: a(u, e.startsWith("/") ? e : `/${e}`, d),
						...n,
						children: t
					}) : /* @__PURE__ */ T("a", {
						...n,
						children: t
					});
				},
				img({ src: e, alt: t, title: r, className: i, node: a, ...o }) {
					return /* @__PURE__ */ T(X, {
						lang: u,
						viewerConfig: n,
						src: e,
						alt: t,
						title: r,
						className: i,
						node: a,
						...o
					});
				}
			},
			children: m
		})
	});
}
//#endregion
export { B as n, Z as t };
