import { __exportAll as e } from "../../../../_virtual/_rolldown/runtime.js";
//#region ../../node_modules/@shikijs/engine-oniguruma/dist/index.mjs
var t = /* @__PURE__ */ e({
	createOnigurumaEngine: () => k,
	getDefaultWasmLoader: () => O,
	loadWasm: () => S,
	setDefaultWasmLoader: () => D
}), n = class extends Error {
	constructor(e) {
		super(e), this.name = "ShikiError";
	}
};
function r() {
	return 2147483648;
}
function i() {
	return typeof performance < "u" ? performance.now() : Date.now();
}
var a = (e, t) => e + (t - e % t) % t;
async function o(e) {
	let t, n, o = {};
	function s(e) {
		n = e, o.HEAPU8 = new Uint8Array(e), o.HEAPU32 = new Uint32Array(e);
	}
	function c(e, t, n) {
		o.HEAPU8.copyWithin(e, t, t + n);
	}
	function l(e) {
		try {
			return t.grow(e - n.byteLength + 65535 >>> 16), s(t.buffer), 1;
		} catch {}
	}
	function u(e) {
		let t = o.HEAPU8.length;
		e >>>= 0;
		let n = r();
		if (e > n) return !1;
		for (let r = 1; r <= 4; r *= 2) {
			let i = t * (1 + .2 / r);
			if (i = Math.min(i, e + 100663296), l(Math.min(n, a(Math.max(e, i), 65536)))) return !0;
		}
		return !1;
	}
	let d = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
	function f(e, t, n = 1024) {
		let r = t + n, i = t;
		for (; e[i] && !(i >= r);) ++i;
		if (i - t > 16 && e.buffer && d) return d.decode(e.subarray(t, i));
		let a = "";
		for (; t < i;) {
			let n = e[t++];
			if (!(n & 128)) {
				a += String.fromCharCode(n);
				continue;
			}
			let r = e[t++] & 63;
			if ((n & 224) == 192) {
				a += String.fromCharCode((n & 31) << 6 | r);
				continue;
			}
			let i = e[t++] & 63;
			if (n = (n & 240) == 224 ? (n & 15) << 12 | r << 6 | i : (n & 7) << 18 | r << 12 | i << 6 | e[t++] & 63, n < 65536) a += String.fromCharCode(n);
			else {
				let e = n - 65536;
				a += String.fromCharCode(55296 | e >> 10, 56320 | e & 1023);
			}
		}
		return a;
	}
	function p(e, t) {
		return e ? f(o.HEAPU8, e, t) : "";
	}
	let m = {
		emscripten_get_now: i,
		emscripten_memcpy_big: c,
		emscripten_resize_heap: u,
		fd_write: () => 0
	};
	async function h() {
		let n = await e({
			env: m,
			wasi_snapshot_preview1: m
		});
		t = n.memory, s(t.buffer), Object.assign(o, n), o.UTF8ToString = p;
	}
	return await h(), o;
}
var s = Object.defineProperty, c = (e, t, n) => t in e ? s(e, t, {
	enumerable: !0,
	configurable: !0,
	writable: !0,
	value: n
}) : e[t] = n, l = (e, t, n) => c(e, typeof t == "symbol" ? t : t + "", n), u = null;
function d(e) {
	throw new n(e.UTF8ToString(e.getLastOnigError()));
}
var f = class e {
	constructor(t) {
		l(this, "utf16Length"), l(this, "utf8Length"), l(this, "utf16Value"), l(this, "utf8Value"), l(this, "utf16OffsetToUtf8"), l(this, "utf8OffsetToUtf16");
		let n = t.length, r = e._utf8ByteLength(t), i = r !== n, a = i ? new Uint32Array(n + 1) : null;
		i && (a[n] = r);
		let o = i ? new Uint32Array(r + 1) : null;
		i && (o[r] = n);
		let s = new Uint8Array(r), c = 0;
		for (let e = 0; e < n; e++) {
			let r = t.charCodeAt(e), l = r, u = !1;
			if (r >= 55296 && r <= 56319 && e + 1 < n) {
				let n = t.charCodeAt(e + 1);
				n >= 56320 && n <= 57343 && (l = (r - 55296 << 10) + 65536 | n - 56320, u = !0);
			}
			i && (a[e] = c, u && (a[e + 1] = c), l <= 127 ? o[c + 0] = e : l <= 2047 ? (o[c + 0] = e, o[c + 1] = e) : l <= 65535 ? (o[c + 0] = e, o[c + 1] = e, o[c + 2] = e) : (o[c + 0] = e, o[c + 1] = e, o[c + 2] = e, o[c + 3] = e)), l <= 127 ? s[c++] = l : l <= 2047 ? (s[c++] = 192 | (l & 1984) >>> 6, s[c++] = 128 | (l & 63) >>> 0) : l <= 65535 ? (s[c++] = 224 | (l & 61440) >>> 12, s[c++] = 128 | (l & 4032) >>> 6, s[c++] = 128 | (l & 63) >>> 0) : (s[c++] = 240 | (l & 1835008) >>> 18, s[c++] = 128 | (l & 258048) >>> 12, s[c++] = 128 | (l & 4032) >>> 6, s[c++] = 128 | (l & 63) >>> 0), u && e++;
		}
		this.utf16Length = n, this.utf8Length = r, this.utf16Value = t, this.utf8Value = s, this.utf16OffsetToUtf8 = a, this.utf8OffsetToUtf16 = o;
	}
	static _utf8ByteLength(e) {
		let t = 0;
		for (let n = 0, r = e.length; n < r; n++) {
			let i = e.charCodeAt(n), a = i, o = !1;
			if (i >= 55296 && i <= 56319 && n + 1 < r) {
				let t = e.charCodeAt(n + 1);
				t >= 56320 && t <= 57343 && (a = (i - 55296 << 10) + 65536 | t - 56320, o = !0);
			}
			a <= 127 ? t += 1 : a <= 2047 ? t += 2 : a <= 65535 ? t += 3 : t += 4, o && n++;
		}
		return t;
	}
	createString(e) {
		let t = e.omalloc(this.utf8Length);
		return e.HEAPU8.set(this.utf8Value, t), t;
	}
}, p = class e {
	constructor(t) {
		if (l(this, "id", ++e.LAST_ID), l(this, "_onigBinding"), l(this, "content"), l(this, "utf16Length"), l(this, "utf8Length"), l(this, "utf16OffsetToUtf8"), l(this, "utf8OffsetToUtf16"), l(this, "ptr"), !u) throw new n("Must invoke loadWasm first.");
		this._onigBinding = u, this.content = t;
		let r = new f(t);
		this.utf16Length = r.utf16Length, this.utf8Length = r.utf8Length, this.utf16OffsetToUtf8 = r.utf16OffsetToUtf8, this.utf8OffsetToUtf16 = r.utf8OffsetToUtf16, this.utf8Length < 1e4 && !e._sharedPtrInUse ? (e._sharedPtr ||= u.omalloc(1e4), e._sharedPtrInUse = !0, u.HEAPU8.set(r.utf8Value, e._sharedPtr), this.ptr = e._sharedPtr) : this.ptr = r.createString(u);
	}
	convertUtf8OffsetToUtf16(e) {
		return this.utf8OffsetToUtf16 ? e < 0 ? 0 : e > this.utf8Length ? this.utf16Length : this.utf8OffsetToUtf16[e] : e;
	}
	convertUtf16OffsetToUtf8(e) {
		return this.utf16OffsetToUtf8 ? e < 0 ? 0 : e > this.utf16Length ? this.utf8Length : this.utf16OffsetToUtf8[e] : e;
	}
	dispose() {
		this.ptr === e._sharedPtr ? e._sharedPtrInUse = !1 : this._onigBinding.ofree(this.ptr);
	}
};
l(p, "LAST_ID", 0), l(p, "_sharedPtr", 0), l(p, "_sharedPtrInUse", !1);
var m = p, h = class {
	constructor(e) {
		if (l(this, "_onigBinding"), l(this, "_ptr"), !u) throw new n("Must invoke loadWasm first.");
		let t = [], r = [];
		for (let n = 0, i = e.length; n < i; n++) {
			let i = new f(e[n]);
			t[n] = i.createString(u), r[n] = i.utf8Length;
		}
		let i = u.omalloc(4 * e.length);
		u.HEAPU32.set(t, i / 4);
		let a = u.omalloc(4 * e.length);
		u.HEAPU32.set(r, a / 4);
		let o = u.createOnigScanner(i, a, e.length);
		for (let n = 0, r = e.length; n < r; n++) u.ofree(t[n]);
		u.ofree(a), u.ofree(i), o === 0 && d(u), this._onigBinding = u, this._ptr = o;
	}
	dispose() {
		this._onigBinding.freeOnigScanner(this._ptr);
	}
	findNextMatchSync(e, t, n) {
		let r = 0;
		if (typeof n == "number" && (r = n), typeof e == "string") {
			e = new m(e);
			let n = this._findNextMatchSync(e, t, !1, r);
			return e.dispose(), n;
		}
		return this._findNextMatchSync(e, t, !1, r);
	}
	_findNextMatchSync(e, t, n, r) {
		let i = this._onigBinding, a = i.findNextOnigScannerMatch(this._ptr, e.id, e.ptr, e.utf8Length, e.convertUtf16OffsetToUtf8(t), r);
		if (a === 0) return null;
		let o = i.HEAPU32, s = a / 4, c = o[s++], l = o[s++], u = [];
		for (let t = 0; t < l; t++) {
			let n = e.convertUtf8OffsetToUtf16(o[s++]), r = e.convertUtf8OffsetToUtf16(o[s++]);
			u[t] = {
				start: n,
				end: r,
				length: r - n
			};
		}
		return {
			index: c,
			captureIndices: u
		};
	}
};
function g(e) {
	return typeof e.instantiator == "function";
}
function _(e) {
	return typeof e.default == "function";
}
function v(e) {
	return e.data !== void 0;
}
function y(e) {
	return typeof Response < "u" && e instanceof Response;
}
function b(e) {
	return typeof ArrayBuffer < "u" && (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) || typeof Buffer < "u" && Buffer.isBuffer?.(e) || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer || typeof Uint32Array < "u" && e instanceof Uint32Array;
}
var x;
function S(e) {
	if (x) return x;
	async function t() {
		u = await o(async (t) => {
			let n = e;
			return n = await n, typeof n == "function" && (n = await n(t)), typeof n == "function" && (n = await n(t)), g(n) ? n = await n.instantiator(t) : _(n) ? n = await n.default(t) : (v(n) && (n = n.data), y(n) ? n = typeof WebAssembly.instantiateStreaming == "function" ? await w(n)(t) : await T(n)(t) : b(n) || n instanceof WebAssembly.Module ? n = await C(n)(t) : "default" in n && n.default instanceof WebAssembly.Module && (n = await C(n.default)(t))), "instance" in n && (n = n.instance), "exports" in n && (n = n.exports), n;
		});
	}
	return x = t(), x;
}
function C(e) {
	return (t) => WebAssembly.instantiate(e, t);
}
function w(e) {
	return (t) => WebAssembly.instantiateStreaming(e, t);
}
function T(e) {
	return async (t) => {
		let n = await e.arrayBuffer();
		return WebAssembly.instantiate(n, t);
	};
}
var E;
function D(e) {
	E = e;
}
function O() {
	return E;
}
async function k(e) {
	return e && await S(e), {
		createScanner(e) {
			return new h(e.map((e) => typeof e == "string" ? e : e.source));
		},
		createString(e) {
			return new m(e);
		}
	};
}
//#endregion
export { k as createOnigurumaEngine, t as dist_exports, O as getDefaultWasmLoader, S as loadWasm, D as setDefaultWasmLoader };
