/* empty css      */
import { toJsxRuntime as e } from "../../hast-util-to-jsx-runtime/lib/index.js";
import { dequal as t } from "../../dequal/dist/index.js";
import { isSpecialLang as n } from "../../@shikijs/primitive/dist/index.js";
import { guessEmbeddedLanguages as r } from "../../@shikijs/core/dist/index.js";
import i from "../../clsx/dist/clsx.js";
import { forwardRef as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
//#region ../../node_modules/react-shiki/dist/component-C5lsWZSq.mjs
var p = (e) => {
	let n = c(e);
	return e !== n.current && !t(e, n.current) && (n.current = e), n.current;
}, m = (e, t, n) => {
	clearTimeout(t.current.timeoutId);
	let r = Math.max(0, t.current.nextAllowedTime - Date.now());
	t.current.timeoutId = setTimeout(() => {
		e(), t.current.nextAllowedTime = Date.now() + n;
	}, r);
}, h = "plaintext", g = (e, t, n) => {
	let i = n.getBundledLanguages();
	return r(e, t).flatMap((e) => i[e] ?? []);
}, _ = (e) => e == null ? [] : Array.isArray(e) ? e : [e], v = (e) => e == null ? null : typeof e == "string" ? `s:${e}` : `o:${e.name}::${e.scopeName}`, y = (e) => {
	let t = /* @__PURE__ */ new Set(), n = [];
	for (let r of e) {
		let e = v(r);
		e == null || t.has(e) || (t.add(e), n.push(r));
	}
	return n;
}, b = (e, t) => e == null ? !1 : typeof e == "string" ? e in t : typeof e.name == "string" && typeof e.scopeName == "string", x = (e, t) => n(e) || t.includes(e) ? e : h, S = (e, t, n, r) => {
	let i = _(t), a = _(r), o = [...i, ...a], s = h, c;
	if (e == null || typeof e == "string" && !e.trim()) return {
		languageId: s,
		langsToLoad: y([...a, ...i])
	};
	if (typeof e == "object") s = e.name, c = e;
	else {
		let t = e.toLowerCase(), r = (e) => e?.toLowerCase() === t, i = o.find((e) => typeof e == "object" && !!e && !!(r(e.name) || r(e.scopeName) || r(e.scopeName?.split(".").pop()) || e.aliases?.some(r) || e.fileTypes?.some(r)));
		i ? (s = i.name || e, c = i) : n?.[e] ? (s = n[e], c = n[e]) : (s = e, c = e);
	}
	return {
		languageId: s,
		langsToLoad: y([
			c,
			...a,
			...i
		])
	};
}, C = {
	light: "github-light",
	dark: "github-dark"
}, w = (e) => {
	if (typeof e != "object" || !e) return !1;
	let t = e, n = Array.isArray(t.tokenColors) || Array.isArray(t.settings), r = typeof t.name == "string" || typeof t.type == "string";
	return n && r;
};
function T(e) {
	if (typeof e != "object" || !e || w(e)) return {
		isMulti: !1,
		theme: e,
		themesToLoad: [e]
	};
	let t = Object.entries(e).filter(([e, t]) => e.trim() !== "" && (typeof t == "string" && t.trim() !== "" || w(t)));
	return t.length === 0 ? (console.warn("[react-shiki] invalid multi-theme config, falling back to defaults"), {
		isMulti: !0,
		themes: C,
		themesToLoad: Object.values(C)
	}) : (t.length !== Object.keys(e).length && console.warn("[react-shiki] multi-theme config contained invalid entries; they were dropped"), {
		isMulti: !0,
		themes: Object.fromEntries(t),
		themesToLoad: t.map(([, e]) => e)
	});
}
function E(e = 1) {
	return {
		name: "react-shiki:line-numbers",
		code(t) {
			if (this.addClassToHast(t, "has-line-numbers"), this.addClassToHast(t, "rs-has-line-numbers"), e !== 1) {
				let n = t.properties?.style || "", r = n ? `${n}; --line-start: ${e}` : `--line-start: ${e}`;
				t.properties = {
					...t.properties,
					style: r
				};
			}
		},
		line(e) {
			return this.addClassToHast(e, "line-numbers"), this.addClassToHast(e, "rs-line-number"), e;
		}
	};
}
var D = (e, t, n) => e.isMulti ? {
	themes: e.themes,
	defaultColor: t,
	cssVariablePrefix: n
} : { theme: e.theme }, O = (e, t, n) => {
	let { delay: r, customLanguages: i, preloadLanguages: a, outputFormat: o, highlighter: s, langAlias: c, engine: l, defaultColor: u, cssVariablePrefix: d, showLineNumbers: f, startingLineNumber: p, transformers: m, ...h } = n, g = [...m || []];
	return f && g.push(E(p)), {
		lang: e,
		...D(t, u, d),
		...h,
		transformers: g
	};
};
async function k(t, n, r, i) {
	let { languageId: a, langsToLoad: o, themesToLoad: s, shikiOptions: c } = n, l = r.highlighter ?? await (async () => {
		let e = await i(o, s, r.engine);
		return await e.loadLanguage(...g(t, a, e)), e;
	})(), p = x(a, l.getLoadedLanguages()), m = {
		...c,
		lang: p
	};
	return r.outputFormat === "html" ? l.codeToHtml(t, m) : e(l.codeToHast(t, m), {
		jsx: d,
		jsxs: f,
		Fragment: u
	});
}
var A = (e, t, n, r = {}, i) => {
	let [a, u] = l(null), d = p(t), f = p(n), h = p(r), g = s(() => {
		let { languageId: e, langsToLoad: t } = S(d, h.customLanguages, h.langAlias, h.preloadLanguages), n = T(f), r = O(e, n, h);
		return {
			languageId: e,
			langsToLoad: t,
			themesToLoad: n.themesToLoad,
			shikiOptions: r
		};
	}, [
		d,
		f,
		h
	]), _ = c(0), v = c({
		nextAllowedTime: 0,
		timeoutId: void 0
	});
	return o(() => {
		let t = ++_.current;
		if (!g.languageId) return;
		let n = async () => {
			try {
				let n = await k(e, g, h, i);
				t === _.current && u(n);
			} catch (e) {
				console.error("[react-shiki] highlight failed", e);
			}
		};
		return h.delay ? m(n, v, h.delay) : n(), () => {
			clearTimeout(v.current.timeoutId);
		};
	}, [
		e,
		g,
		h,
		i
	]), a;
}, j = (e) => a(({ language: t, theme: n, delay: r, transformers: a, defaultColor: o, cssVariablePrefix: s, addDefaultStyles: c = !0, style: l, langStyle: u, className: p, langClassName: m, showLanguage: h = !0, showLineNumbers: g = !1, startingLineNumber: _ = 1, children: v, as: y = "div", customLanguages: b, preloadLanguages: x, ...S }, C) => {
	let w = {
		delay: r,
		transformers: a,
		customLanguages: b,
		preloadLanguages: x,
		showLineNumbers: g,
		defaultColor: o,
		cssVariablePrefix: s,
		startingLineNumber: _,
		...S
	}, T = typeof t == "object" ? t.name || null : t?.trim() || null, E = e(v, t, n, w);
	return /* @__PURE__ */ f(y, {
		ref: C,
		"data-testid": "shiki-container",
		"data-slot": "container",
		className: i("rs-root", "not-prose", c && "rs-default-styles", p),
		style: l,
		children: [h && T ? /* @__PURE__ */ d("span", {
			id: "language-label",
			"data-slot": "language-label",
			className: i("rs-language-label", m),
			style: u,
			children: T
		}) : null, typeof E == "string" ? /* @__PURE__ */ d("div", {
			"data-slot": "content",
			dangerouslySetInnerHTML: { __html: E }
		}) : E]
	});
});
//#endregion
export { j as createShikiHighlighterComponent, b as isLoadableLanguage, A as useHighlight };

//# sourceMappingURL=component-C5lsWZSq.js.map