"use client";
import { SKIP, visitParents } from "../../unist-util-visit-parents/lib/index.js";
import { visit } from "../../unist-util-visit/lib/index.js";
import remarkGfm from "../../remark-gfm/lib/index.js";
import { harden } from "../../rehype-harden/dist/index.js";
import rehypeRaw from "../../rehype-raw/lib/index.js";
import { defaultSchema } from "../../hast-util-sanitize/lib/schema.js";
import rehypeSanitize from "../../rehype-sanitize/lib/index.js";
import { pr } from "../../remend/dist/index.js";
import { toJsxRuntime } from "../../hast-util-to-jsx-runtime/lib/index.js";
import { urlAttributes } from "../../html-url-attributes/lib/index.js";
import remarkParse from "../../remark-parse/lib/index.js";
import remarkRehype from "../../remark-rehype/lib/index.js";
import { unified } from "../../unified/lib/index.js";
import { x } from "../node_modules/marked/lib/marked.esm.js";
import { Suspense, cloneElement, createContext, isValidElement, lazy, memo, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useTransition } from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { createPortal } from "react-dom";
var Oo = 300, Vo = "300px", Ao = 500;
function Ge(e = {}) {
	let { immediate: n = !1, debounceDelay: r = Oo, rootMargin: i = Vo, idleTimeout: a = Ao } = e, [o, s] = useState(!1), c = useRef(null), l = useRef(null), u = useRef(null), d = useMemo(() => (e) => {
		let n = Date.now();
		return window.setTimeout(() => {
			e({
				didTimeout: !1,
				timeRemaining: () => Math.max(0, 50 - (Date.now() - n))
			});
		}, 1);
	}, []), p = useMemo(() => typeof window < "u" && window.requestIdleCallback ? (e, n) => window.requestIdleCallback(e, n) : d, [d]), m = useMemo(() => typeof window < "u" && window.cancelIdleCallback ? (e) => window.cancelIdleCallback(e) : (e) => {
		clearTimeout(e);
	}, []);
	return useEffect(() => {
		if (n) {
			s(!0);
			return;
		}
		let e = c.current;
		if (!e) return;
		l.current &&= (clearTimeout(l.current), null), u.current &&= (m(u.current), null);
		let o = () => {
			l.current &&= (clearTimeout(l.current), null), u.current &&= (m(u.current), null);
		}, d = (e) => {
			u.current = p((n) => {
				n.timeRemaining() > 0 || n.didTimeout ? (s(!0), e.disconnect()) : u.current = p(() => {
					s(!0), e.disconnect();
				}, { timeout: a / 2 });
			}, { timeout: a });
		}, h = (e) => {
			o(), l.current = window.setTimeout(() => {
				var n;
				let r = e.takeRecords();
				(r.length === 0 || (n = r.at(-1)?.isIntersecting) != null && n) && d(e);
			}, r);
		}, g = (e, n) => {
			e.isIntersecting ? h(n) : o();
		}, _ = new IntersectionObserver((e) => {
			for (let n of e) g(n, _);
		}, {
			rootMargin: i,
			threshold: 0
		});
		return _.observe(e), () => {
			l.current && clearTimeout(l.current), u.current && m(u.current), _.disconnect();
		};
	}, [
		n,
		r,
		i,
		a,
		m,
		p
	]), {
		shouldRender: o,
		containerRef: c
	};
}
var Ye = /\s/, qo = /^\s+$/, _o = new Set([
	"code",
	"pre",
	"svg",
	"math",
	"annotation"
]), Zo = (e) => typeof e == "object" && !!e && "type" in e && e.type === "element", Wo = (e) => e.some((e) => Zo(e) && _o.has(e.tagName)), $o = (e) => {
	let n = [], r = "", i = !1;
	for (let a of e) {
		let e = Ye.test(a);
		e !== i && r && (n.push(r), r = ""), r += a, i = e;
	}
	return r && n.push(r), n;
}, Fo = (e) => {
	let n = [], r = "";
	for (let i of e) Ye.test(i) ? r += i : (r &&= (n.push(r), ""), n.push(i));
	return r && n.push(r), n;
}, Uo = (e, n, r, i) => ({
	type: "element",
	tagName: "span",
	properties: {
		"data-sd-animate": !0,
		style: `--sd-animation:sd-${n};--sd-duration:${r}ms;--sd-easing:${i}`
	},
	children: [{
		type: "text",
		value: e
	}]
}), Xo = (n, r, i) => {
	let a = r.at(-1);
	if (!(a && "children" in a)) return;
	if (Wo(r)) return SKIP;
	let o = a, s = o.children.indexOf(n);
	if (s === -1) return;
	let c = n.value;
	if (!c.trim()) return;
	let l = (i.sep === "char" ? Fo(c) : $o(c)).map((e) => qo.test(e) ? {
		type: "text",
		value: e
	} : Uo(e, i.animation, i.duration, i.easing));
	return o.children.splice(s, 1, ...l), s + l.length;
};
function Q(e) {
	let r = {
		animation: e?.animation ?? "fadeIn",
		duration: e?.duration ?? 150,
		easing: e?.easing ?? "ease",
		sep: e?.sep ?? "word"
	};
	return {
		name: "animate",
		type: "animate",
		rehypePlugin: () => (e) => {
			visitParents(e, "text", (e, n) => Xo(e, n, r));
		}
	};
}
Q();
var Re = createContext(!1), Ie = () => useContext(Re), f = (...e) => twMerge(clsx(e)), q = (e, n, r) => {
	let i = typeof n == "string" ? new Blob([n], { type: r }) : n, a = URL.createObjectURL(i), o = document.createElement("a");
	o.href = a, o.download = e, document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(a);
}, tn = f("block", "before:content-[counter(line)]", "before:inline-block", "before:[counter-increment:line]", "before:w-6", "before:mr-4", "before:text-[13px]", "before:text-right", "before:text-muted-foreground/50", "before:font-mono", "before:select-none"), on = (e) => {
	let n = {};
	for (let r of e.split(";")) {
		let e = r.indexOf(":");
		if (e > 0) {
			let i = r.slice(0, e).trim(), a = r.slice(e + 1).trim();
			i && a && (n[i] = a);
		}
	}
	return n;
}, Qe = memo(({ children: e, result: n, language: r, className: i, ...a }) => {
	let o = useMemo(() => {
		let e = {};
		return n.bg && (e["--sdm-bg"] = n.bg), n.fg && (e["--sdm-fg"] = n.fg), n.rootStyle && Object.assign(e, on(n.rootStyle)), e;
	}, [
		n.bg,
		n.fg,
		n.rootStyle
	]);
	return jsx("div", {
		className: f(i, "overflow-hidden rounded-md border border-border bg-background p-4 text-sm"),
		"data-language": r,
		"data-streamdown": "code-block-body",
		...a,
		children: jsx("pre", {
			className: f(i, "bg-[var(--sdm-bg,inherit]", "dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]"),
			style: o,
			children: jsx("code", {
				className: "[counter-increment:line_0] [counter-reset:line]",
				children: n.tokens.map((e, n) => jsx("span", {
					className: tn,
					children: e.map((e, n) => {
						let r = {}, i = !!e.bgColor;
						if (e.color && (r["--sdm-c"] = e.color), e.bgColor && (r["--sdm-tbg"] = e.bgColor), e.htmlStyle) for (let [n, a] of Object.entries(e.htmlStyle)) n === "color" ? r["--sdm-c"] = a : n === "background-color" ? (r["--sdm-tbg"] = a, i = !0) : r[n] = a;
						return jsx("span", {
							className: f("text-[var(--sdm-c,inherit)]", "dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]", i && "bg-[var(--sdm-tbg)]", i && "dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),
							style: r,
							...e.htmlAttrs,
							children: e.content
						}, n);
					})
				}, n))
			})
		})
	});
}, (e, n) => e.result === n.result && e.language === n.language && e.className === n.className), et = ({ className: e, language: n, style: r, isIncomplete: i, ...a }) => jsx("div", {
	className: f("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2", e),
	"data-incomplete": i || void 0,
	"data-language": n,
	"data-streamdown": "code-block",
	style: {
		contentVisibility: "auto",
		containIntrinsicSize: "auto 200px",
		...r
	},
	...a
}), Se = createContext({ code: "" }), de = () => useContext(Se), ot = ({ language: e }) => jsx("div", {
	className: "flex h-8 items-center text-muted-foreground text-xs",
	"data-language": e,
	"data-streamdown": "code-block-header",
	children: jsx("span", {
		className: "ml-1 font-mono lowercase",
		children: e
	})
}), cn = /\n+$/, dn = lazy(() => import("./highlighted-body-B3W2YXNL.js").then((e) => ({ default: e.HighlightedCodeBlockBody }))), rt = ({ code: e, language: n, className: r, children: i, isIncomplete: a = !1, ...o }) => {
	let s = useMemo(() => e.replace(cn, ""), [e]), c = useMemo(() => ({
		bg: "transparent",
		fg: "inherit",
		tokens: s.split("\n").map((e) => [{
			content: e,
			color: "inherit",
			bgColor: "transparent",
			htmlStyle: {},
			offset: 0
		}])
	}), [s]);
	return jsx(Se.Provider, {
		value: { code: e },
		children: jsxs(et, {
			isIncomplete: a,
			language: n,
			children: [
				jsx(ot, { language: n }),
				i ? jsx("div", {
					className: "pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end",
					children: jsx("div", {
						className: "pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur",
						"data-streamdown": "code-block-actions",
						children: i
					})
				}) : null,
				jsx(Suspense, {
					fallback: jsx(Qe, {
						className: r,
						language: n,
						result: c,
						...o
					}),
					children: jsx(dn, {
						className: r,
						code: s,
						language: n,
						raw: c,
						...o
					})
				})
			]
		})
	});
}, J = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), K = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), Z = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), st = (e) => jsxs("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: [
		jsx("path", {
			d: "M8 0V4",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M8 16V12",
			opacity: "0.5",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M3.29773 1.52783L5.64887 4.7639",
			opacity: "0.9",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M12.7023 1.52783L10.3511 4.7639",
			opacity: "0.1",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M12.7023 14.472L10.3511 11.236",
			opacity: "0.4",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M3.29773 14.472L5.64887 11.236",
			opacity: "0.6",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M15.6085 5.52783L11.8043 6.7639",
			opacity: "0.2",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M0.391602 10.472L4.19583 9.23598",
			opacity: "0.7",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M15.6085 10.4722L11.8043 9.2361",
			opacity: "0.3",
			stroke: "currentColor",
			strokeWidth: "1.5"
		}),
		jsx("path", {
			d: "M0.391602 5.52783L4.19583 6.7639",
			opacity: "0.8",
			stroke: "currentColor",
			strokeWidth: "1.5"
		})
	]
}), at = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), it = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), me = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), Ee = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), lt = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), ct = (e) => jsx("svg", {
	color: "currentColor",
	height: 16,
	strokeLinejoin: "round",
	viewBox: "0 0 16 16",
	width: 16,
	...e,
	children: jsx("path", {
		clipRule: "evenodd",
		d: "M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",
		fill: "currentColor",
		fillRule: "evenodd"
	})
}), He = ({ onCopy: e, onError: n, timeout: r = 2e3, children: i, className: a, code: o, ...s }) => {
	let [c, l] = useState(!1), u = useRef(0), { code: d } = de(), { isAnimating: p } = useContext(R), m = o ?? d, h = async () => {
		var i;
		if (typeof window > "u" || !((i = navigator == null ? void 0 : navigator.clipboard) != null && i.writeText)) {
			n?.(/* @__PURE__ */ Error("Clipboard API not available"));
			return;
		}
		try {
			c || (await navigator.clipboard.writeText(m), l(!0), e?.(), u.current = window.setTimeout(() => l(!1), r));
		} catch (e) {
			n?.(e);
		}
	};
	useEffect(() => () => {
		window.clearTimeout(u.current);
	}, []);
	let g = c ? J : K;
	return jsx("button", {
		className: f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", a),
		"data-streamdown": "code-block-copy-button",
		disabled: p,
		onClick: h,
		title: "Copy Code",
		type: "button",
		...s,
		children: i ?? jsx(g, { size: 14 })
	});
}, mt = {
	"1c": "1c",
	"1c-query": "1cq",
	abap: "abap",
	"actionscript-3": "as",
	ada: "ada",
	adoc: "adoc",
	"angular-html": "html",
	"angular-ts": "ts",
	apache: "conf",
	apex: "cls",
	apl: "apl",
	applescript: "applescript",
	ara: "ara",
	asciidoc: "adoc",
	asm: "asm",
	astro: "astro",
	awk: "awk",
	ballerina: "bal",
	bash: "sh",
	bat: "bat",
	batch: "bat",
	be: "be",
	beancount: "beancount",
	berry: "berry",
	bibtex: "bib",
	bicep: "bicep",
	blade: "blade.php",
	bsl: "bsl",
	c: "c",
	"c#": "cs",
	"c++": "cpp",
	cadence: "cdc",
	cairo: "cairo",
	cdc: "cdc",
	clarity: "clar",
	clj: "clj",
	clojure: "clj",
	"closure-templates": "soy",
	cmake: "cmake",
	cmd: "cmd",
	cobol: "cob",
	codeowners: "CODEOWNERS",
	codeql: "ql",
	coffee: "coffee",
	coffeescript: "coffee",
	"common-lisp": "lisp",
	console: "sh",
	coq: "v",
	cpp: "cpp",
	cql: "cql",
	crystal: "cr",
	cs: "cs",
	csharp: "cs",
	css: "css",
	csv: "csv",
	cue: "cue",
	cypher: "cql",
	d: "d",
	dart: "dart",
	dax: "dax",
	desktop: "desktop",
	diff: "diff",
	docker: "dockerfile",
	dockerfile: "dockerfile",
	dotenv: "env",
	"dream-maker": "dm",
	edge: "edge",
	elisp: "el",
	elixir: "ex",
	elm: "elm",
	"emacs-lisp": "el",
	erb: "erb",
	erl: "erl",
	erlang: "erl",
	f: "f",
	"f#": "fs",
	f03: "f03",
	f08: "f08",
	f18: "f18",
	f77: "f77",
	f90: "f90",
	f95: "f95",
	fennel: "fnl",
	fish: "fish",
	fluent: "ftl",
	for: "for",
	"fortran-fixed-form": "f",
	"fortran-free-form": "f90",
	fs: "fs",
	fsharp: "fs",
	fsl: "fsl",
	ftl: "ftl",
	gdresource: "tres",
	gdscript: "gd",
	gdshader: "gdshader",
	genie: "gs",
	gherkin: "feature",
	"git-commit": "gitcommit",
	"git-rebase": "gitrebase",
	gjs: "js",
	gleam: "gleam",
	"glimmer-js": "js",
	"glimmer-ts": "ts",
	glsl: "glsl",
	gnuplot: "plt",
	go: "go",
	gql: "gql",
	graphql: "graphql",
	groovy: "groovy",
	gts: "gts",
	hack: "hack",
	haml: "haml",
	handlebars: "hbs",
	haskell: "hs",
	haxe: "hx",
	hbs: "hbs",
	hcl: "hcl",
	hjson: "hjson",
	hlsl: "hlsl",
	hs: "hs",
	html: "html",
	"html-derivative": "html",
	http: "http",
	hxml: "hxml",
	hy: "hy",
	imba: "imba",
	ini: "ini",
	jade: "jade",
	java: "java",
	javascript: "js",
	jinja: "jinja",
	jison: "jison",
	jl: "jl",
	js: "js",
	json: "json",
	json5: "json5",
	jsonc: "jsonc",
	jsonl: "jsonl",
	jsonnet: "jsonnet",
	jssm: "jssm",
	jsx: "jsx",
	julia: "jl",
	kotlin: "kt",
	kql: "kql",
	kt: "kt",
	kts: "kts",
	kusto: "kql",
	latex: "tex",
	lean: "lean",
	lean4: "lean",
	less: "less",
	liquid: "liquid",
	lisp: "lisp",
	lit: "lit",
	llvm: "ll",
	log: "log",
	logo: "logo",
	lua: "lua",
	luau: "luau",
	make: "mak",
	makefile: "mak",
	markdown: "md",
	marko: "marko",
	matlab: "m",
	md: "md",
	mdc: "mdc",
	mdx: "mdx",
	mediawiki: "wiki",
	mermaid: "mmd",
	mips: "s",
	mipsasm: "s",
	mmd: "mmd",
	mojo: "mojo",
	move: "move",
	nar: "nar",
	narrat: "narrat",
	nextflow: "nf",
	nf: "nf",
	nginx: "conf",
	nim: "nim",
	nix: "nix",
	nu: "nu",
	nushell: "nu",
	objc: "m",
	"objective-c": "m",
	"objective-cpp": "mm",
	ocaml: "ml",
	pascal: "pas",
	perl: "pl",
	perl6: "p6",
	php: "php",
	plsql: "pls",
	po: "po",
	polar: "polar",
	postcss: "pcss",
	pot: "pot",
	potx: "potx",
	powerquery: "pq",
	powershell: "ps1",
	prisma: "prisma",
	prolog: "pl",
	properties: "properties",
	proto: "proto",
	protobuf: "proto",
	ps: "ps",
	ps1: "ps1",
	pug: "pug",
	puppet: "pp",
	purescript: "purs",
	py: "py",
	python: "py",
	ql: "ql",
	qml: "qml",
	qmldir: "qmldir",
	qss: "qss",
	r: "r",
	racket: "rkt",
	raku: "raku",
	razor: "cshtml",
	rb: "rb",
	reg: "reg",
	regex: "regex",
	regexp: "regexp",
	rel: "rel",
	riscv: "s",
	rs: "rs",
	rst: "rst",
	ruby: "rb",
	rust: "rs",
	sas: "sas",
	sass: "sass",
	scala: "scala",
	scheme: "scm",
	scss: "scss",
	sdbl: "sdbl",
	sh: "sh",
	shader: "shader",
	shaderlab: "shader",
	shell: "sh",
	shellscript: "sh",
	shellsession: "sh",
	smalltalk: "st",
	solidity: "sol",
	soy: "soy",
	sparql: "rq",
	spl: "spl",
	splunk: "spl",
	sql: "sql",
	"ssh-config": "config",
	stata: "do",
	styl: "styl",
	stylus: "styl",
	svelte: "svelte",
	swift: "swift",
	"system-verilog": "sv",
	systemd: "service",
	talon: "talon",
	talonscript: "talon",
	tasl: "tasl",
	tcl: "tcl",
	templ: "templ",
	terraform: "tf",
	tex: "tex",
	tf: "tf",
	tfvars: "tfvars",
	toml: "toml",
	ts: "ts",
	"ts-tags": "ts",
	tsp: "tsp",
	tsv: "tsv",
	tsx: "tsx",
	turtle: "ttl",
	twig: "twig",
	typ: "typ",
	typescript: "ts",
	typespec: "tsp",
	typst: "typ",
	v: "v",
	vala: "vala",
	vb: "vb",
	verilog: "v",
	vhdl: "vhdl",
	vim: "vim",
	viml: "vim",
	vimscript: "vim",
	vue: "vue",
	"vue-html": "html",
	"vue-vine": "vine",
	vy: "vy",
	vyper: "vy",
	wasm: "wasm",
	wenyan: "wy",
	wgsl: "wgsl",
	wiki: "wiki",
	wikitext: "wiki",
	wit: "wit",
	wl: "wl",
	wolfram: "wl",
	xml: "xml",
	xsl: "xsl",
	yaml: "yaml",
	yml: "yml",
	zenscript: "zs",
	zig: "zig",
	zsh: "zsh",
	文言: "wy"
}, ut = ({ onDownload: e, onError: n, language: r, children: i, className: a, code: o, ...s }) => {
	let { code: c } = de(), { isAnimating: l } = useContext(R), u = o ?? c, d = `file.${r && r in mt ? mt[r] : "txt"}`, p = () => {
		try {
			q(d, u, "text/plain"), e?.();
		} catch (e) {
			n?.(e);
		}
	};
	return jsx("button", {
		className: f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", a),
		"data-streamdown": "code-block-download-button",
		disabled: l,
		onClick: p,
		title: "Download file",
		type: "button",
		...s,
		children: i ?? jsx(Z, { size: 14 })
	});
}, ft = () => jsxs("div", {
	className: "w-full divide-y divide-border overflow-hidden rounded-xl border border-border",
	children: [jsx("div", { className: "h-[46px] w-full bg-muted/80" }), jsx("div", {
		className: "flex w-full items-center justify-center p-4",
		children: jsx(st, { className: "size-4 animate-spin" })
	})]
}), Cn = /\.[^/.]+$/, ht = ({ node: e, className: n, src: r, alt: i, onLoad: a, onError: o, ...s }) => {
	let c = useRef(null), [l, u] = useState(!1), [d, p] = useState(!1), m = s.width != null || s.height != null, h = (l || m) && !d, g = d && !m;
	useEffect(() => {
		let e = c.current;
		if (e != null && e.complete) {
			let n = e.naturalWidth > 0;
			u(n), p(!n);
		}
	}, []);
	let _ = useCallback((e) => {
		u(!0), p(!1), a?.(e);
	}, [a]), v = useCallback((e) => {
		u(!1), p(!0), o?.(e);
	}, [o]), y = async () => {
		if (r) try {
			let e = await (await fetch(r)).blob(), n = new URL(r, window.location.origin).pathname.split("/").pop() || "", a = n.split(".").pop(), o = n.includes(".") && a !== void 0 && a.length <= 4, s = "";
			if (o) s = n;
			else {
				let r = e.type, a = "png";
				r.includes("jpeg") || r.includes("jpg") ? a = "jpg" : r.includes("png") ? a = "png" : r.includes("svg") ? a = "svg" : r.includes("gif") ? a = "gif" : r.includes("webp") && (a = "webp"), s = `${(i || n || "image").replace(Cn, "")}.${a}`;
			}
			q(s, e, e.type);
		} catch {
			window.open(r, "_blank");
		}
	};
	return r ? jsxs("div", {
		className: "group relative my-4 inline-block",
		"data-streamdown": "image-wrapper",
		children: [
			jsx("img", {
				alt: i,
				className: f("max-w-full rounded-lg", g && "hidden", n),
				"data-streamdown": "image",
				onError: v,
				onLoad: _,
				ref: c,
				src: r,
				...s
			}),
			g && jsx("span", {
				className: "text-muted-foreground text-xs italic",
				"data-streamdown": "image-fallback",
				children: "Image not available"
			}),
			jsx("div", { className: "pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block" }),
			h && jsx("button", {
				className: f("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background", "opacity-0 group-hover:opacity-100"),
				onClick: y,
				title: "Download image",
				type: "button",
				children: jsx(Z, { size: 14 })
			})
		]
	}) : null;
}, oe = 0, Mn = () => {
	oe += 1, oe === 1 && (document.body.style.overflow = "hidden");
}, Tn = () => {
	oe = Math.max(0, oe - 1), oe === 0 && (document.body.style.overflow = "");
}, kt = ({ url: e, isOpen: n, onClose: r, onConfirm: i }) => {
	let [a, o] = useState(!1), s = useCallback(async () => {
		try {
			await navigator.clipboard.writeText(e), o(!0), setTimeout(() => o(!1), 2e3);
		} catch {}
	}, [e]), c = useCallback(() => {
		i(), r();
	}, [i, r]);
	return useEffect(() => {
		if (n) {
			Mn();
			let e = (e) => {
				e.key === "Escape" && r();
			};
			return document.addEventListener("keydown", e), () => {
				document.removeEventListener("keydown", e), Tn();
			};
		}
	}, [n, r]), n ? jsx("div", {
		className: "fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm",
		"data-streamdown": "link-safety-modal",
		onClick: r,
		onKeyDown: (e) => {
			e.key === "Escape" && r();
		},
		role: "button",
		tabIndex: 0,
		children: jsxs("div", {
			className: "relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg",
			onClick: (e) => e.stopPropagation(),
			onKeyDown: (e) => e.stopPropagation(),
			role: "presentation",
			children: [
				jsx("button", {
					className: "absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",
					onClick: r,
					title: "Close",
					type: "button",
					children: jsx(me, { size: 16 })
				}),
				jsxs("div", {
					className: "flex flex-col gap-2",
					children: [jsxs("div", {
						className: "flex items-center gap-2 font-semibold text-lg",
						children: [jsx(Ee, { size: 20 }), jsx("span", { children: "Open external link?" })]
					}), jsx("p", {
						className: "text-muted-foreground text-sm",
						children: "You're about to visit an external website."
					})]
				}),
				jsx("div", {
					className: f("break-all rounded-md bg-muted p-3 font-mono text-sm", e.length > 100 && "max-h-32 overflow-y-auto"),
					children: e
				}),
				jsxs("div", {
					className: "flex gap-2",
					children: [jsx("button", {
						className: "flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted",
						onClick: s,
						type: "button",
						children: a ? jsxs(Fragment$1, { children: [jsx(J, { size: 14 }), jsx("span", { children: "Copied" })] }) : jsxs(Fragment$1, { children: [jsx(K, { size: 14 }), jsx("span", { children: "Copy link" })] })
					}), jsxs("button", {
						className: "flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90",
						onClick: c,
						type: "button",
						children: [jsx(Ee, { size: 14 }), jsx("span", { children: "Open link" })]
					})]
				})
			]
		})
	}) : null;
}, pe = createContext(null), Ct = () => useContext(pe), Ks = () => Ct()?.code ?? null, G = () => Ct()?.mermaid ?? null, vt = (e, n) => new Promise((n, r) => {
	let i = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(e))), a = new Image();
	a.crossOrigin = "anonymous", a.onload = () => {
		let e = document.createElement("canvas"), i = a.width * 5, o = a.height * 5;
		e.width = i, e.height = o;
		let s = e.getContext("2d");
		if (!s) {
			r(/* @__PURE__ */ Error("Failed to create 2D canvas context for PNG export"));
			return;
		}
		s.drawImage(a, 0, 0, i, o), e.toBlob((e) => {
			if (!e) {
				r(/* @__PURE__ */ Error("Failed to create PNG blob"));
				return;
			}
			n(e);
		}, "image/png");
	}, a.onerror = () => r(/* @__PURE__ */ Error("Failed to load SVG image")), a.src = i;
}), Pt = ({ chart: e, children: n, className: r, onDownload: i, config: a, onError: o }) => {
	let [s, c] = useState(!1), l = useRef(null), { isAnimating: u } = useContext(R), d = G(), p = async (n) => {
		try {
			if (n === "mmd") {
				q("diagram.mmd", e, "text/plain"), c(!1), i?.(n);
				return;
			}
			if (!d) {
				o?.(/* @__PURE__ */ Error("Mermaid plugin not available"));
				return;
			}
			let r = d.getMermaid(a), s = e.split("").reduce((e, n) => (e << 5) - e + n.charCodeAt(0) | 0, 0), l = `mermaid-${Math.abs(s)}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, { svg: u } = await r.render(l, e);
			if (!u) {
				o?.(/* @__PURE__ */ Error("SVG not found. Please wait for the diagram to render."));
				return;
			}
			if (n === "svg") {
				q("diagram.svg", u, "image/svg+xml"), c(!1), i?.(n);
				return;
			}
			if (n === "png") {
				q("diagram.png", await vt(u), "image/png"), i?.(n), c(!1);
				return;
			}
		} catch (e) {
			o?.(e);
		}
	};
	return useEffect(() => {
		let e = (e) => {
			let n = e.composedPath();
			l.current && !n.includes(l.current) && c(!1);
		};
		return document.addEventListener("mousedown", e), () => {
			document.removeEventListener("mousedown", e);
		};
	}, []), jsxs("div", {
		className: "relative",
		ref: l,
		children: [jsx("button", {
			className: f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", r),
			disabled: u,
			onClick: () => c(!s),
			title: "Download diagram",
			type: "button",
			children: n ?? jsx(Z, { size: 14 })
		}), s ? jsxs("div", {
			className: "absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",
			children: [
				jsx("button", {
					className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
					onClick: () => p("svg"),
					title: "Download diagram as SVG",
					type: "button",
					children: "SVG"
				}),
				jsx("button", {
					className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
					onClick: () => p("png"),
					title: "Download diagram as PNG",
					type: "button",
					children: "PNG"
				}),
				jsx("button", {
					className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
					onClick: () => p("mmd"),
					title: "Download diagram as MMD",
					type: "button",
					children: "MMD"
				})
			]
		}) : null]
	});
}, re = 0, On = () => {
	re += 1, re === 1 && (document.body.style.overflow = "hidden");
}, Vn = () => {
	re = Math.max(0, re - 1), re === 0 && (document.body.style.overflow = "");
}, Lt = ({ chart: e, config: n, onFullscreen: r, onExit: i, className: a, ...o }) => {
	let [s, c] = useState(!1), { isAnimating: l, controls: u } = useContext(R), d = (() => {
		if (typeof u == "boolean") return u;
		let e = u.mermaid;
		return e === !1 ? !1 : e === !0 || e === void 0 ? !0 : e.panZoom !== !1;
	})(), p = () => {
		c(!s);
	};
	return useEffect(() => {
		if (s) {
			On();
			let e = (e) => {
				e.key === "Escape" && c(!1);
			};
			return document.addEventListener("keydown", e), () => {
				document.removeEventListener("keydown", e), Vn();
			};
		}
	}, [s]), useEffect(() => {
		s ? r?.() : i && i();
	}, [
		s,
		r,
		i
	]), jsxs(Fragment$1, { children: [jsx("button", {
		className: f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", a),
		disabled: l,
		onClick: p,
		title: "View fullscreen",
		type: "button",
		...o,
		children: jsx(at, { size: 14 })
	}), s ? createPortal(jsxs("div", {
		className: "fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",
		onClick: p,
		onKeyDown: (e) => {
			e.key === "Escape" && p();
		},
		role: "button",
		tabIndex: 0,
		children: [jsx("button", {
			className: "absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",
			onClick: p,
			title: "Exit fullscreen",
			type: "button",
			children: jsx(me, { size: 20 })
		}), jsx("div", {
			className: "flex size-full items-center justify-center p-4",
			onClick: (e) => e.stopPropagation(),
			onKeyDown: (e) => e.stopPropagation(),
			role: "presentation",
			children: jsx(Nt, {
				chart: e,
				className: "size-full [&_svg]:h-auto [&_svg]:w-auto",
				config: n,
				fullscreen: !0,
				showControls: d
			})
		})]
	}), document.body) : null] });
}, ue = (e) => {
	let n = [], r = [], i = e.querySelectorAll("thead th");
	for (let e of i) n.push(e.textContent?.trim() || "");
	let a = e.querySelectorAll("tbody tr");
	for (let e of a) {
		let n = [], i = e.querySelectorAll("td");
		for (let e of i) n.push(e.textContent?.trim() || "");
		r.push(n);
	}
	return {
		headers: n,
		rows: r
	};
}, fe = (e) => {
	let { headers: n, rows: r } = e, i = (e) => {
		let n = !1, r = !1;
		for (let i of e) {
			if (i === "\"") {
				n = !0, r = !0;
				break;
			}
			(i === "," || i === "\n") && (n = !0);
		}
		return n ? r ? `"${e.replace(/"/g, "\"\"")}"` : `"${e}"` : e;
	}, a = n.length > 0 ? r.length + 1 : r.length, o = Array(a), s = 0;
	n.length > 0 && (o[s] = n.map(i).join(","), s += 1);
	for (let e of r) o[s] = e.map(i).join(","), s += 1;
	return o.join("\n");
}, Rt = (e) => {
	let { headers: n, rows: r } = e, i = (e) => {
		let n = !1;
		for (let r of e) if (r === "	" || r === "\n" || r === "\r") {
			n = !0;
			break;
		}
		if (!n) return e;
		let r = [];
		for (let n of e) n === "	" ? r.push("\\t") : n === "\n" ? r.push("\\n") : n === "\r" ? r.push("\\r") : r.push(n);
		return r.join("");
	}, a = n.length > 0 ? r.length + 1 : r.length, o = Array(a), s = 0;
	n.length > 0 && (o[s] = n.map(i).join("	"), s += 1);
	for (let e of r) o[s] = e.map(i).join("	"), s += 1;
	return o.join("\n");
}, De = (e) => {
	let n = !1;
	for (let r of e) if (r === "\\" || r === "|") {
		n = !0;
		break;
	}
	if (!n) return e;
	let r = [];
	for (let n of e) n === "\\" ? r.push("\\\\") : n === "|" ? r.push("\\|") : r.push(n);
	return r.join("");
}, se = (e) => {
	let { headers: n, rows: r } = e;
	if (n.length === 0) return "";
	let i = Array(r.length + 2), a = 0;
	i[a] = `| ${n.map((e) => De(e)).join(" | ")} |`, a += 1;
	let o = Array(n.length);
	for (let e = 0; e < n.length; e += 1) o[e] = "---";
	i[a] = `| ${o.join(" | ")} |`, a += 1;
	for (let e of r) if (e.length < n.length) {
		let r = Array(n.length);
		for (let i = 0; i < n.length; i += 1) r[i] = i < e.length ? De(e[i]) : "";
		i[a] = `| ${r.join(" | ")} |`, a += 1;
	} else i[a] = `| ${e.map((e) => De(e)).join(" | ")} |`, a += 1;
	return i.join("\n");
}, Ht = ({ children: e, className: n, onCopy: r, onError: i, timeout: a = 2e3 }) => {
	let [o, s] = useState(!1), [c, l] = useState(!1), u = useRef(null), d = useRef(0), { isAnimating: p } = useContext(R), m = async (e) => {
		var n;
		if (typeof window > "u" || !((n = navigator == null ? void 0 : navigator.clipboard) != null && n.write)) {
			i?.(/* @__PURE__ */ Error("Clipboard API not available"));
			return;
		}
		try {
			let n = (u.current?.closest("[data-streamdown=\"table-wrapper\"]"))?.querySelector("table");
			if (!n) {
				i?.(/* @__PURE__ */ Error("Table not found"));
				return;
			}
			let o = ue(n), c = ({
				csv: fe,
				tsv: Rt,
				md: se
			}[e] || se)(o), p = new ClipboardItem({
				"text/plain": new Blob([c], { type: "text/plain" }),
				"text/html": new Blob([n.outerHTML], { type: "text/html" })
			});
			await navigator.clipboard.write([p]), l(!0), s(!1), r?.(e), d.current = window.setTimeout(() => l(!1), a);
		} catch (e) {
			i?.(e);
		}
	};
	useEffect(() => {
		let e = (e) => {
			let n = e.composedPath();
			u.current && !n.includes(u.current) && s(!1);
		};
		return document.addEventListener("mousedown", e), () => {
			document.removeEventListener("mousedown", e), window.clearTimeout(d.current);
		};
	}, []);
	let h = c ? J : K;
	return jsxs("div", {
		className: "relative",
		ref: u,
		children: [jsx("button", {
			className: f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", n),
			disabled: p,
			onClick: () => s(!o),
			title: "Copy table",
			type: "button",
			children: e ?? jsx(h, { size: 14 })
		}), o ? jsxs("div", {
			className: "absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",
			children: [
				jsx("button", {
					className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
					onClick: () => m("md"),
					title: "Copy table as Markdown",
					type: "button",
					children: "Markdown"
				}),
				jsx("button", {
					className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
					onClick: () => m("csv"),
					title: "Copy table as CSV",
					type: "button",
					children: "CSV"
				}),
				jsx("button", {
					className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
					onClick: () => m("tsv"),
					title: "Copy table as TSV",
					type: "button",
					children: "TSV"
				})
			]
		}) : null]
	});
}, Dt = ({ children: e, className: n, onDownload: r, onError: i }) => {
	let [a, o] = useState(!1), s = useRef(null), { isAnimating: c } = useContext(R), l = (e) => {
		try {
			let n = (s.current?.closest("[data-streamdown=\"table-wrapper\"]"))?.querySelector("table");
			if (!n) {
				i?.(/* @__PURE__ */ Error("Table not found"));
				return;
			}
			let a = ue(n), c = e === "csv" ? fe(a) : se(a);
			q(`table.${e === "csv" ? "csv" : "md"}`, c, e === "csv" ? "text/csv" : "text/markdown"), o(!1), r?.(e);
		} catch (e) {
			i?.(e);
		}
	};
	return useEffect(() => {
		let e = (e) => {
			let n = e.composedPath();
			s.current && !n.includes(s.current) && o(!1);
		};
		return document.addEventListener("mousedown", e), () => {
			document.removeEventListener("mousedown", e);
		};
	}, []), jsxs("div", {
		className: "relative",
		ref: s,
		children: [jsx("button", {
			className: f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50", n),
			disabled: c,
			onClick: () => o(!a),
			title: "Download table",
			type: "button",
			children: e ?? jsx(Z, { size: 14 })
		}), a ? jsxs("div", {
			className: "absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",
			children: [jsx("button", {
				className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
				onClick: () => l("csv"),
				title: "Download table as CSV",
				type: "button",
				children: "CSV"
			}), jsx("button", {
				className: "w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",
				onClick: () => l("markdown"),
				title: "Download table as Markdown",
				type: "button",
				children: "Markdown"
			})]
		}) : null]
	});
}, Vt = ({ children: e, className: n, showControls: r, ...i }) => jsxs("div", {
	className: "my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2",
	"data-streamdown": "table-wrapper",
	children: [r ? jsxs("div", {
		className: "flex items-center justify-end gap-1",
		children: [jsx(Ht, {}), jsx(Dt, {})]
	}) : null, jsx("div", {
		className: "border-collapse overflow-x-auto overscroll-y-auto rounded-md border border-border bg-background",
		children: jsx("table", {
			className: f("w-full divide-y divide-border", n),
			"data-streamdown": "table",
			...i,
			children: e
		})
	})]
}), Jn = lazy(() => import("./mermaid-3ZIDBTTL.js").then((e) => ({ default: e.Mermaid }))), Kn = /language-([^\s]+)/;
function ke(e, n) {
	if (!(e != null && e.position || n != null && n.position)) return !0;
	if (!(e != null && e.position && n != null && n.position)) return !1;
	let r = e.position.start, i = n.position.start, a = e.position.end, o = n.position.end;
	return r?.line === i?.line && r?.column === i?.column && a?.line === o?.line && a?.column === o?.column;
}
function N(e, n) {
	return e.className === n.className && ke(e.node, n.node);
}
var Ve = (e, n) => typeof e == "boolean" ? e : e[n] !== !1, he = (e, n) => {
	if (typeof e == "boolean") return e;
	let r = e.mermaid;
	return r === !1 ? !1 : r === !0 || r === void 0 ? !0 : r[n] !== !1;
}, je = memo(({ children: e, className: n, node: r, ...i }) => jsx("ol", {
	className: f("list-inside list-decimal whitespace-normal [li_&]:pl-6", n),
	"data-streamdown": "ordered-list",
	...i,
	children: e
}), (e, n) => N(e, n));
je.displayName = "MarkdownOl";
var At = memo(({ children: e, className: n, node: r, ...i }) => jsx("li", {
	className: f("py-1 [&>p]:inline", n),
	"data-streamdown": "list-item",
	...i,
	children: e
}), (e, n) => e.className === n.className && ke(e.node, n.node));
At.displayName = "MarkdownLi";
var jt = memo(({ children: e, className: n, node: r, ...i }) => jsx("ul", {
	className: f("list-inside list-disc whitespace-normal [li_&]:pl-6", n),
	"data-streamdown": "unordered-list",
	...i,
	children: e
}), (e, n) => N(e, n));
jt.displayName = "MarkdownUl";
var zt = memo(({ className: e, node: n, ...r }) => jsx("hr", {
	className: f("my-6 border-border", e),
	"data-streamdown": "horizontal-rule",
	...r
}), (e, n) => N(e, n));
zt.displayName = "MarkdownHr";
var qt = memo(({ children: e, className: n, node: r, ...i }) => jsx("span", {
	className: f("font-semibold", n),
	"data-streamdown": "strong",
	...i,
	children: e
}), (e, n) => N(e, n));
qt.displayName = "MarkdownStrong";
var _t = memo(({ children: e, className: n, href: r, node: i, ...a }) => {
	let { linkSafety: o } = useContext(R), [s, c] = useState(!1), l = r === "streamdown:incomplete-link", u = useCallback(async (e) => {
		if (!(!(o != null && o.enabled && r) || l)) {
			if (e.preventDefault(), o.onLinkCheck && await o.onLinkCheck(r)) {
				window.open(r, "_blank", "noreferrer");
				return;
			}
			c(!0);
		}
	}, [
		o,
		r,
		l
	]), d = useCallback(() => {
		r && window.open(r, "_blank", "noreferrer");
	}, [r]), p = useCallback(() => {
		c(!1);
	}, []), m = {
		url: r ?? "",
		isOpen: s,
		onClose: p,
		onConfirm: d
	};
	return o != null && o.enabled && r ? jsxs(Fragment$1, { children: [jsx("button", {
		className: f("wrap-anywhere appearance-none text-left font-medium text-primary underline", n),
		"data-incomplete": l,
		"data-streamdown": "link",
		onClick: u,
		type: "button",
		children: e
	}), o.renderModal ? o.renderModal(m) : jsx(kt, { ...m })] }) : jsx("a", {
		className: f("wrap-anywhere font-medium text-primary underline", n),
		"data-incomplete": l,
		"data-streamdown": "link",
		href: r,
		rel: "noreferrer",
		target: "_blank",
		...a,
		children: e
	});
}, (e, n) => N(e, n) && e.href === n.href);
_t.displayName = "MarkdownA";
var Zt = memo(({ children: e, className: n, node: r, ...i }) => jsx("h1", {
	className: f("mt-6 mb-2 font-semibold text-3xl", n),
	"data-streamdown": "heading-1",
	...i,
	children: e
}), (e, n) => N(e, n));
Zt.displayName = "MarkdownH1";
var Wt = memo(({ children: e, className: n, node: r, ...i }) => jsx("h2", {
	className: f("mt-6 mb-2 font-semibold text-2xl", n),
	"data-streamdown": "heading-2",
	...i,
	children: e
}), (e, n) => N(e, n));
Wt.displayName = "MarkdownH2";
var $t = memo(({ children: e, className: n, node: r, ...i }) => jsx("h3", {
	className: f("mt-6 mb-2 font-semibold text-xl", n),
	"data-streamdown": "heading-3",
	...i,
	children: e
}), (e, n) => N(e, n));
$t.displayName = "MarkdownH3";
var Ft = memo(({ children: e, className: n, node: r, ...i }) => jsx("h4", {
	className: f("mt-6 mb-2 font-semibold text-lg", n),
	"data-streamdown": "heading-4",
	...i,
	children: e
}), (e, n) => N(e, n));
Ft.displayName = "MarkdownH4";
var Ut = memo(({ children: e, className: n, node: r, ...i }) => jsx("h5", {
	className: f("mt-6 mb-2 font-semibold text-base", n),
	"data-streamdown": "heading-5",
	...i,
	children: e
}), (e, n) => N(e, n));
Ut.displayName = "MarkdownH5";
var Xt = memo(({ children: e, className: n, node: r, ...i }) => jsx("h6", {
	className: f("mt-6 mb-2 font-semibold text-sm", n),
	"data-streamdown": "heading-6",
	...i,
	children: e
}), (e, n) => N(e, n));
Xt.displayName = "MarkdownH6";
var Jt = memo(({ children: e, className: n, node: r, ...i }) => {
	let { controls: a } = useContext(R);
	return jsx(Vt, {
		className: n,
		showControls: Ve(a, "table"),
		...i,
		children: e
	});
}, (e, n) => N(e, n));
Jt.displayName = "MarkdownTable";
var Kt = memo(({ children: e, className: n, node: r, ...i }) => jsx("thead", {
	className: f("bg-muted/80", n),
	"data-streamdown": "table-header",
	...i,
	children: e
}), (e, n) => N(e, n));
Kt.displayName = "MarkdownThead";
var Gt = memo(({ children: e, className: n, node: r, ...i }) => jsx("tbody", {
	className: f("divide-y divide-border", n),
	"data-streamdown": "table-body",
	...i,
	children: e
}), (e, n) => N(e, n));
Gt.displayName = "MarkdownTbody";
var Yt = memo(({ children: e, className: n, node: r, ...i }) => jsx("tr", {
	className: f("border-border", n),
	"data-streamdown": "table-row",
	...i,
	children: e
}), (e, n) => N(e, n));
Yt.displayName = "MarkdownTr";
var Qt = memo(({ children: e, className: n, node: r, ...i }) => jsx("th", {
	className: f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm", n),
	"data-streamdown": "table-header-cell",
	...i,
	children: e
}), (e, n) => N(e, n));
Qt.displayName = "MarkdownTh";
var eo = memo(({ children: e, className: n, node: r, ...i }) => jsx("td", {
	className: f("px-4 py-2 text-sm", n),
	"data-streamdown": "table-cell",
	...i,
	children: e
}), (e, n) => N(e, n));
eo.displayName = "MarkdownTd";
var to = memo(({ children: e, className: n, node: r, ...i }) => jsx("blockquote", {
	className: f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic", n),
	"data-streamdown": "blockquote",
	...i,
	children: e
}), (e, n) => N(e, n));
to.displayName = "MarkdownBlockquote";
var oo = memo(({ children: e, className: n, node: r, ...i }) => jsx("sup", {
	className: f("text-sm", n),
	"data-streamdown": "superscript",
	...i,
	children: e
}), (e, n) => N(e, n));
oo.displayName = "MarkdownSup";
var no = memo(({ children: e, className: n, node: r, ...i }) => jsx("sub", {
	className: f("text-sm", n),
	"data-streamdown": "subscript",
	...i,
	children: e
}), (e, n) => N(e, n));
no.displayName = "MarkdownSub";
var ro = memo(({ children: e, className: n, node: r, ...i }) => {
	if ("data-footnotes" in i) {
		let r = (e) => {
			if (!isValidElement(e)) return !1;
			let n = Array.isArray(e.props.children) ? e.props.children : [e.props.children], r = !1, i = !1;
			for (let e of n) if (e) {
				if (typeof e == "string") e.trim() !== "" && (r = !0);
				else if (isValidElement(e)) if (e.props?.["data-footnote-backref"] !== void 0) i = !0;
				else {
					let n = Array.isArray(e.props.children) ? e.props.children : [e.props.children];
					for (let e of n) {
						if (typeof e == "string" && e.trim() !== "") {
							r = !0;
							break;
						}
						if (isValidElement(e) && e.props?.["data-footnote-backref"] === void 0) {
							r = !0;
							break;
						}
					}
				}
			}
			return i && !r;
		}, a = Array.isArray(e) ? e.map((e) => {
			if (!isValidElement(e)) return e;
			if (e.type === je) {
				let n = (Array.isArray(e.props.children) ? e.props.children : [e.props.children]).filter((e) => !r(e));
				return n.length === 0 ? null : {
					...e,
					props: {
						...e.props,
						children: n
					}
				};
			}
			return e;
		}) : e;
		return (Array.isArray(a) ? a.some((e) => e !== null) : a !== null) ? jsx("section", {
			className: n,
			...i,
			children: a
		}) : null;
	}
	return jsx("section", {
		className: n,
		...i,
		children: e
	});
}, (e, n) => N(e, n));
ro.displayName = "MarkdownSection";
var so = memo(({ node: e, className: n, children: r, ...i }) => {
	let a = !("data-block" in i), { mermaid: o, controls: s } = useContext(R), c = G(), l = Ie();
	if (a) return jsx("code", {
		className: f("rounded bg-muted px-1.5 py-0.5 font-mono text-sm", n),
		"data-streamdown": "inline-code",
		...i,
		children: r
	});
	let u = (n?.match(Kn))?.at(1) ?? "", d = "";
	if (isValidElement(r) && r.props && typeof r.props == "object" && "children" in r.props && typeof r.props.children == "string" ? d = r.props.children : typeof r == "string" && (d = r), u === "mermaid" && c) {
		let e = Ve(s, "mermaid"), r = he(s, "download"), i = he(s, "copy"), a = he(s, "fullscreen"), c = he(s, "panZoom"), l = e && (r || i || a);
		return jsx(Suspense, {
			fallback: jsx(ft, {}),
			children: jsxs("div", {
				className: f("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2", n),
				"data-streamdown": "mermaid-block",
				children: [
					jsx("div", {
						className: "flex h-8 items-center text-muted-foreground text-xs",
						children: jsx("span", {
							className: "ml-1 font-mono lowercase",
							children: "mermaid"
						})
					}),
					l ? jsx("div", {
						className: "pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end",
						children: jsxs("div", {
							className: "pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur",
							"data-streamdown": "mermaid-block-actions",
							children: [
								r ? jsx(Pt, {
									chart: d,
									config: o?.config
								}) : null,
								i ? jsx(He, { code: d }) : null,
								a ? jsx(Lt, {
									chart: d,
									config: o?.config
								}) : null
							]
						})
					}) : null,
					jsx("div", {
						className: "rounded-md border border-border bg-background",
						children: jsx(Jn, {
							chart: d,
							config: o?.config,
							showControls: c
						})
					})
				]
			})
		});
	}
	let p = Ve(s, "code");
	return jsx(rt, {
		className: n,
		code: d,
		isIncomplete: l,
		language: u,
		children: p ? jsxs(Fragment$1, { children: [jsx(ut, {
			code: d,
			language: u
		}), jsx(He, {})] }) : null
	});
}, (e, n) => e.className === n.className && ke(e.node, n.node));
so.displayName = "MarkdownCode";
var ao = memo(ht, (e, n) => e.className === n.className && ke(e.node, n.node));
ao.displayName = "MarkdownImg";
var io = memo(({ children: e, node: n, ...r }) => {
	let i = (Array.isArray(e) ? e : [e]).filter((e) => e != null && e !== "");
	if (i.length === 1 && isValidElement(i[0])) {
		let n = i[0].props.node?.tagName;
		if (n === "img" || n === "code" && "data-block" in i[0].props) return jsx(Fragment$1, { children: e });
	}
	return jsx("p", {
		...r,
		children: e
	});
}, (e, n) => N(e, n));
io.displayName = "MarkdownParagraph";
var lo = {
	ol: je,
	li: At,
	ul: jt,
	hr: zt,
	strong: qt,
	a: _t,
	h1: Zt,
	h2: Wt,
	h3: $t,
	h4: Ft,
	h5: Ut,
	h6: Xt,
	table: Jt,
	thead: Kt,
	tbody: Gt,
	tr: Yt,
	th: Qt,
	td: eo,
	blockquote: to,
	code: so,
	img: ao,
	pre: ({ children: e }) => isValidElement(e) ? cloneElement(e, { "data-block": "true" }) : e,
	sup: oo,
	sub: no,
	p: io,
	section: ro
}, Qn = /^[ \t]{0,3}(`{3,}|~{3,})/, er = /^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/, ze = (e) => {
	let n = e.split("\n"), r = null, i = 0;
	for (let e of n) {
		let n = Qn.exec(e);
		if (r === null) {
			if (n) {
				let e = n[1];
				r = e[0], i = e.length;
			}
		} else if (n) {
			let e = n[1], a = e[0], o = e.length;
			a === r && o >= i && (r = null, i = 0);
		}
	}
	return r !== null;
}, co = (e) => {
	let n = e.split("\n");
	for (let e of n) {
		let n = e.trim();
		if (n.length > 0 && n.includes("|") && er.test(n)) return !0;
	}
	return !1;
}, mo = () => (e) => {
	visit(e, "html", (e, n, r) => {
		!r || typeof n != "number" || (r.children[n] = {
			type: "text",
			value: e.value
		});
	});
}, uo = [], fo = { allowDangerousHtml: !0 }, Ce = /* @__PURE__ */ new WeakMap(), go = new class {
	constructor() {
		this.cache = /* @__PURE__ */ new Map(), this.keyCache = /* @__PURE__ */ new WeakMap(), this.maxSize = 100;
	}
	generateCacheKey(e) {
		let n = this.keyCache.get(e);
		if (n) return n;
		let r = e.rehypePlugins, i = e.remarkPlugins, a = e.remarkRehypeOptions;
		if (!(r || i || a)) {
			let n = "default";
			return this.keyCache.set(e, n), n;
		}
		let o = (e) => {
			if (!e || e.length === 0) return "";
			let n = "";
			for (let r = 0; r < e.length; r += 1) {
				let i = e[r];
				if (r > 0 && (n += ","), Array.isArray(i)) {
					let [e, r] = i;
					if (typeof e == "function") {
						let r = Ce.get(e);
						r || (r = e.name, Ce.set(e, r)), n += r;
					} else n += String(e);
					n += ":", n += JSON.stringify(r);
				} else if (typeof i == "function") {
					let e = Ce.get(i);
					e || (e = i.name, Ce.set(i, e)), n += e;
				} else n += String(i);
			}
			return n;
		}, s = o(r), c = `${o(i)}::${s}::${a ? JSON.stringify(a) : ""}`;
		return this.keyCache.set(e, c), c;
	}
	get(e) {
		let n = this.generateCacheKey(e), r = this.cache.get(n);
		return r && (this.cache.delete(n), this.cache.set(n, r)), r;
	}
	set(e, n) {
		let r = this.generateCacheKey(e);
		if (this.cache.size >= this.maxSize) {
			let e = this.cache.keys().next().value;
			e && this.cache.delete(e);
		}
		this.cache.set(r, n);
	}
	clear() {
		this.cache.clear();
	}
}(), Ze = (e) => {
	let n = dr(e), r = e.children || "";
	return br(n.runSync(n.parse(r), r), e);
}, dr = (e) => {
	let n = go.get(e);
	if (n) return n;
	let r = pr$1(e);
	return go.set(e, r), r;
}, mr = (e) => e.some((e) => Array.isArray(e) ? e[0] === rehypeRaw : e === rehypeRaw), pr$1 = (e) => {
	let n = e.rehypePlugins || uo, r = e.remarkPlugins || uo, i = mr(n) ? r : [...r, mo], a = e.remarkRehypeOptions ? {
		...fo,
		...e.remarkRehypeOptions
	} : fo;
	return unified().use(remarkParse).use(i).use(remarkRehype, a).use(n);
}, bo = (e) => e, ur = (e, n, r, i) => {
	r ? e.children.splice(n, 1) : e.children[n] = {
		type: "text",
		value: i
	};
}, fr = (e, n) => {
	for (let r in urlAttributes) if (Object.hasOwn(urlAttributes, r) && Object.hasOwn(e.properties, r)) {
		let i = e.properties[r], a = urlAttributes[r];
		(a === null || a.includes(e.tagName)) && (e.properties[r] = n(String(i || ""), r, e) ?? void 0);
	}
}, gr = (e, n, r, i, a, o) => {
	let s = !1;
	return i ? s = !i.includes(e.tagName) : a && (s = a.includes(e.tagName)), !s && o && typeof n == "number" && (s = !o(e, n, r)), s;
}, br = (e, n) => {
	let { allowElement: i, allowedElements: a, disallowedElements: o, skipHtml: s, unwrapDisallowed: c, urlTransform: l } = n;
	if (i || a || o || s || l) {
		let n = l || bo;
		visit(e, (e, r, l) => {
			if (e.type === "raw" && l && typeof r == "number") return ur(l, r, s, e.value), r;
			if (e.type === "element" && (fr(e, n), gr(e, r, l, a, o, i) && l && typeof r == "number")) return c && e.children ? l.children.splice(r, 1, ...e.children) : l.children.splice(r, 1), r;
		});
	}
	return toJsxRuntime(e, {
		Fragment: Fragment$1,
		components: n.components,
		ignoreInvalidStyle: !0,
		jsx,
		jsxs,
		passKeys: !0,
		passNode: !0
	});
}, yr = /\[\^[\w-]{1,200}\](?!:)/, wr = /\[\^[\w-]{1,200}\]:/, kr = /<(\w+)[\s>]/, Cr = new Set([
	"area",
	"base",
	"br",
	"col",
	"embed",
	"hr",
	"img",
	"input",
	"link",
	"meta",
	"param",
	"source",
	"track",
	"wbr"
]), ho = /* @__PURE__ */ new Map(), yo = /* @__PURE__ */ new Map(), vr = (e) => {
	let n = e.toLowerCase(), r = ho.get(n);
	if (r) return r;
	let i = RegExp(`<${n}(?=[\\s>/])[^>]*>`, "gi");
	return ho.set(n, i), i;
}, xr = (e) => {
	let n = e.toLowerCase(), r = yo.get(n);
	if (r) return r;
	let i = RegExp(`</${n}(?=[\\s>])[^>]*>`, "gi");
	return yo.set(n, i), i;
}, wo = (e, n) => {
	if (Cr.has(n.toLowerCase())) return 0;
	let r = e.match(vr(n));
	if (!r) return 0;
	let i = 0;
	for (let e of r) e.trimEnd().endsWith("/>") || (i += 1);
	return i;
}, ko = (e, n) => {
	let r = e.match(xr(n));
	return r ? r.length : 0;
}, Pr = (e) => {
	let n = 0;
	for (let r = 0; r < e.length - 1; r += 1) e[r] === "$" && e[r + 1] === "$" && (n += 1, r += 1);
	return n;
}, We = (e) => {
	let n = yr.test(e), r = wr.test(e);
	if (n || r) return [e];
	let i = x.lex(e, { gfm: !0 }), a = [], o = [], s = !1;
	for (let e of i) {
		let n = e.raw, r = a.length;
		if (o.length > 0) {
			a[r - 1] += n;
			let e = o.at(-1), i = wo(n, e), s = ko(n, e);
			for (let n = 0; n < i; n += 1) o.push(e);
			for (let n = 0; n < s; n += 1) o.length > 0 && o.at(-1) === e && o.pop();
			continue;
		}
		if (e.type === "html" && e.block) {
			let e = n.match(kr);
			if (e) {
				let r = e[1];
				wo(n, r) > ko(n, r) && o.push(r);
			}
		}
		if (r > 0 && !s) {
			let e = a[r - 1];
			if (Pr(e) % 2 == 1) {
				a[r - 1] = e + n;
				continue;
			}
		}
		a.push(n), e.type !== "space" && (s = e.type === "code");
	}
	return a;
}, Co = (e, n) => {
	if (!n.length) return e;
	let r = e;
	for (let e of n) {
		let n = RegExp(`(<${e}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${e}\\s*>)`, "gi");
		r = r.replace(n, (e, n, r, i) => n + r.replace(/\n\n/g, "\n<!---->\n") + i);
	}
	return r;
}, Br = /^[ \t]*<[\w!/?-]/, Dr = /(^|\n)[ \t]{4,}(?=<[\w!/?-])/g, Or = (e) => typeof e != "string" || e.length === 0 || !Br.test(e) ? e : e.replace(Dr, "$1"), ve = {
	...defaultSchema,
	protocols: {
		...defaultSchema.protocols,
		href: [...defaultSchema.protocols?.href ?? [], "tel"]
	}
}, Fe = {
	raw: rehypeRaw,
	sanitize: [rehypeSanitize, ve],
	harden: [harden, {
		allowedImagePrefixes: ["*"],
		allowedLinkPrefixes: ["*"],
		allowedProtocols: ["*"],
		defaultOrigin: void 0,
		allowDataImages: !0
	}]
}, Vr = { gfm: [remarkGfm, {}] }, vo = Object.values(Fe), Ar = Object.values(Vr), jr = {
	block: " ▋",
	circle: " ●"
}, R = createContext({
	shikiTheme: ["github-light", "github-dark"],
	controls: !0,
	isAnimating: !1,
	mode: "streaming",
	mermaid: void 0,
	linkSafety: { enabled: !0 }
}), No = memo(({ content: e, shouldParseIncompleteMarkdown: n, shouldNormalizeHtmlIndentation: r, index: i, isIncomplete: a, ...o }) => {
	let s = typeof e == "string" && r ? Or(e) : e;
	return jsx(Re.Provider, {
		value: a,
		children: jsx(Ze, {
			...o,
			children: s
		})
	});
}, (e, n) => {
	if (e.content !== n.content || e.shouldNormalizeHtmlIndentation !== n.shouldNormalizeHtmlIndentation || e.index !== n.index || e.isIncomplete !== n.isIncomplete) return !1;
	if (e.components !== n.components) {
		let r = Object.keys(e.components || {}), i = Object.keys(n.components || {});
		if (r.length !== i.length || r.some((r) => e.components?.[r] !== n.components?.[r])) return !1;
	}
	return !(e.rehypePlugins !== n.rehypePlugins || e.remarkPlugins !== n.remarkPlugins);
});
No.displayName = "Block";
var qr = ["github-light", "github-dark"], _r = memo(({ children: e, mode: n = "streaming", parseIncompleteMarkdown: r = !0, normalizeHtmlIndentation: i = !1, components: a, rehypePlugins: o = vo, remarkPlugins: s = Ar, className: u, shikiTheme: d = qr, mermaid: p, controls: m = !0, isAnimating: h = !1, animated: g, BlockComponent: _ = No, parseMarkdownIntoBlocksFn: v = We, caret: y, plugins: b, remend: S, linkSafety: C = { enabled: !0 }, allowedTags: w, ...T }) => {
	let O = useId(), [A, j] = useTransition(), M = useMemo(() => w ? Object.keys(w) : [], [w]), P = useMemo(() => {
		if (typeof e != "string") return "";
		let i = n === "streaming" && r ? pr(e, S) : e;
		return M.length > 0 && (i = Co(i, M)), i;
	}, [
		e,
		n,
		r,
		S,
		M
	]), F = useMemo(() => v(P), [P, v]), [I, L] = useState(F);
	useEffect(() => {
		n === "streaming" ? j(() => {
			L(F);
		}) : L(F);
	}, [F, n]);
	let z = n === "streaming" ? I : F, B = useMemo(() => z.map((e, n) => `${O}-${n}`), [z.length, O]), V = useMemo(() => g ? g === !0 ? Q() : Q(g) : null, [g]), H = useMemo(() => ({
		shikiTheme: (b?.code)?.getThemes() ?? d,
		controls: m,
		isAnimating: h,
		mode: n,
		mermaid: p,
		linkSafety: C
	}), [
		d,
		m,
		h,
		n,
		p,
		C,
		b?.code
	]), U = useMemo(() => ({
		...lo,
		...a
	}), [a]), W = useMemo(() => {
		let e = [];
		return b != null && b.cjk && (e = [...e, ...b.cjk.remarkPluginsBefore]), e = [...e, ...s], b != null && b.cjk && (e = [...e, ...b.cjk.remarkPluginsAfter]), b != null && b.math && (e = [...e, b.math.remarkPlugin]), e;
	}, [
		s,
		b?.math,
		b?.cjk
	]), Y = useMemo(() => {
		let e = o;
		if (w && Object.keys(w).length > 0 && o === vo) {
			let n = {
				...ve,
				tagNames: [...ve.tagNames ?? [], ...Object.keys(w)],
				attributes: {
					...ve.attributes,
					...w
				}
			};
			e = [
				Fe.raw,
				[rehypeSanitize, n],
				Fe.harden
			];
		}
		return b != null && b.math && (e = [...e, b.math.rehypePlugin]), V && h && (e = [...e, V.rehypePlugin]), e;
	}, [
		o,
		b?.math,
		V,
		h,
		w
	]), X = useMemo(() => {
		if (!h || z.length === 0) return !1;
		let e = z.at(-1);
		return ze(e) || co(e);
	}, [h, z]), $ = useMemo(() => y && h && !X ? { "--streamdown-caret": `"${jr[y]}"` } : void 0, [
		y,
		h,
		X
	]);
	return n === "static" ? jsx(pe.Provider, {
		value: b ?? null,
		children: jsx(R.Provider, {
			value: H,
			children: jsx("div", {
				className: f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0", u),
				children: jsx(Ze, {
					components: U,
					rehypePlugins: Y,
					remarkPlugins: W,
					...T,
					children: P
				})
			})
		})
	}) : jsx(pe.Provider, {
		value: b ?? null,
		children: jsx(R.Provider, {
			value: H,
			children: jsxs("div", {
				className: f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0", y && !X ? "*:last:after:inline *:last:after:align-baseline *:last:after:content-[var(--streamdown-caret)]" : null, u),
				style: $,
				children: [z.length === 0 && y && h && jsx("span", {}), z.map((e, n) => {
					let a = n === z.length - 1;
					return jsx(_, {
						components: U,
						content: e,
						index: n,
						isIncomplete: h && a && ze(e),
						rehypePlugins: Y,
						remarkPlugins: W,
						shouldNormalizeHtmlIndentation: i,
						shouldParseIncompleteMarkdown: r,
						...T
					}, B[n]);
				})]
			})
		})
	});
}, (e, n) => e.children === n.children && e.shikiTheme === n.shikiTheme && e.isAnimating === n.isAnimating && e.animated === n.animated && e.mode === n.mode && e.plugins === n.plugins && e.className === n.className && e.linkSafety === n.linkSafety && e.normalizeHtmlIndentation === n.normalizeHtmlIndentation);
_r.displayName = "Streamdown";
var So = ({ children: e, className: n, minZoom: r = .5, maxZoom: i = 3, zoomStep: a = .1, showControls: o = !0, initialZoom: s = 1, fullscreen: c = !1 }) => {
	let l = useRef(null), u = useRef(null), [d, p] = useState(s), [m, h] = useState({
		x: 0,
		y: 0
	}), [g, _] = useState(!1), [v, y] = useState({
		x: 0,
		y: 0
	}), [b, S] = useState({
		x: 0,
		y: 0
	}), C = useCallback((e) => {
		p((n) => Math.max(r, Math.min(i, n + e)));
	}, [r, i]), T = useCallback(() => {
		C(a);
	}, [C, a]), E = useCallback(() => {
		C(-a);
	}, [C, a]), D = useCallback(() => {
		p(s), h({
			x: 0,
			y: 0
		});
	}, [s]), k = useCallback((e) => {
		e.preventDefault(), C(e.deltaY > 0 ? -a : a);
	}, [C, a]), A = useCallback((e) => {
		if (e.button !== 0 || e.isPrimary === !1) return;
		_(!0), y({
			x: e.clientX,
			y: e.clientY
		}), S(m);
		let n = e.currentTarget;
		n instanceof HTMLElement && n.setPointerCapture(e.pointerId);
	}, [m]), j = useCallback((e) => {
		if (!g) return;
		e.preventDefault();
		let n = e.clientX - v.x, r = e.clientY - v.y;
		h({
			x: b.x + n,
			y: b.y + r
		});
	}, [
		g,
		v,
		b
	]), M = useCallback((e) => {
		_(!1);
		let n = e.currentTarget;
		n instanceof HTMLElement && n.releasePointerCapture(e.pointerId);
	}, []);
	return useEffect(() => {
		let e = l.current;
		if (e) return e.addEventListener("wheel", k, { passive: !1 }), () => {
			e.removeEventListener("wheel", k);
		};
	}, [k]), useEffect(() => {
		let e = u.current;
		if (e && g) return document.body.style.userSelect = "none", e.addEventListener("pointermove", j, { passive: !1 }), e.addEventListener("pointerup", M), e.addEventListener("pointercancel", M), () => {
			document.body.style.userSelect = "", e.removeEventListener("pointermove", j), e.removeEventListener("pointerup", M), e.removeEventListener("pointercancel", M);
		};
	}, [
		g,
		j,
		M
	]), jsxs("div", {
		className: f("relative flex flex-col", c ? "h-full w-full" : "min-h-28 w-full", n),
		ref: l,
		style: { cursor: g ? "grabbing" : "grab" },
		children: [o ? jsxs("div", {
			className: f("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/80 p-1 supports-[backdrop-filter]:bg-background/70 supports-[backdrop-filter]:backdrop-blur-sm", c ? "bottom-4 left-4" : "bottom-2 left-2"),
			children: [
				jsx("button", {
					className: "flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",
					disabled: d >= i,
					onClick: T,
					title: "Zoom in",
					type: "button",
					children: jsx(lt, { size: 16 })
				}),
				jsx("button", {
					className: "flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",
					disabled: d <= r,
					onClick: E,
					title: "Zoom out",
					type: "button",
					children: jsx(ct, { size: 16 })
				}),
				jsx("button", {
					className: "flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
					onClick: D,
					title: "Reset zoom and pan",
					type: "button",
					children: jsx(it, { size: 16 })
				})
			]
		}) : null, jsx("div", {
			className: f("flex-1 origin-center transition-transform duration-150 ease-out", c ? "flex h-full w-full items-center justify-center" : "flex w-full items-center justify-center"),
			onPointerDown: A,
			ref: u,
			role: "application",
			style: {
				transform: `translate(${m.x}px, ${m.y}px) scale(${d})`,
				transformOrigin: "center center",
				touchAction: "none",
				willChange: "transform"
			},
			children: e
		})]
	});
}, Nt = ({ chart: e, className: n, config: r, fullscreen: i = !1, showControls: a = !0 }) => {
	let [o, s] = useState(null), [c, l] = useState(!1), [u, d] = useState(""), [p, m] = useState(""), [h, g] = useState(0), { mermaid: _ } = useContext(R), v = G(), y = _?.errorComponent, { shouldRender: b, containerRef: S } = Ge({ immediate: i });
	if (useEffect(() => {
		if (b) {
			if (!v) {
				s("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");
				return;
			}
			(async () => {
				try {
					s(null), l(!0);
					let n = v.getMermaid(r), i = e.split("").reduce((e, n) => (e << 5) - e + n.charCodeAt(0) | 0, 0), a = `mermaid-${Math.abs(i)}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, { svg: o } = await n.render(a, e);
					d(o), m(o);
				} catch (e) {
					p || u || s(e instanceof Error ? e.message : "Failed to render Mermaid chart");
				} finally {
					l(!1);
				}
			})();
		}
	}, [
		e,
		r,
		h,
		b,
		v
	]), !(b || u || p)) return jsx("div", {
		className: f("my-4 min-h-[200px]", n),
		ref: S
	});
	if (c && !u && !p) return jsx("div", {
		className: f("my-4 flex justify-center p-4", n),
		ref: S,
		children: jsxs("div", {
			className: "flex items-center space-x-2 text-muted-foreground",
			children: [jsx("div", { className: "h-4 w-4 animate-spin rounded-full border-current border-b-2" }), jsx("span", {
				className: "text-sm",
				children: "Loading diagram..."
			})]
		})
	});
	if (o && !u && !p) return y ? jsx("div", {
		ref: S,
		children: jsx(y, {
			chart: e,
			error: o,
			retry: () => g((e) => e + 1)
		})
	}) : jsxs("div", {
		className: f("rounded-md bg-red-50 p-4", n),
		ref: S,
		children: [jsxs("p", {
			className: "font-mono text-red-700 text-sm",
			children: ["Mermaid Error: ", o]
		}), jsxs("details", {
			className: "mt-2",
			children: [jsx("summary", {
				className: "cursor-pointer text-red-600 text-xs",
				children: "Show Code"
			}), jsx("pre", {
				className: "mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",
				children: e
			})]
		})]
	});
	let C = u || p;
	return jsx("div", {
		className: f("size-full", n),
		"data-streamdown": "mermaid",
		ref: S,
		children: jsx(So, {
			className: f(i ? "size-full overflow-hidden" : "overflow-hidden", n),
			fullscreen: i,
			maxZoom: 3,
			minZoom: .5,
			showControls: a,
			zoomStep: .1,
			children: jsx("div", {
				"aria-label": "Mermaid chart",
				className: f("flex justify-center", i ? "size-full items-center" : null),
				dangerouslySetInnerHTML: { __html: C },
				role: "img"
			})
		})
	});
};
export { Fe, Ie, Ks, No, Nt, Or, Q, Qe, R, Vr, We, _r, bo };
