var ShikiError = class extends Error {
	constructor(e) {
		super(e), this.name = "ShikiError";
	}
};
function getHeapMax() {
	return 2147483648;
}
function _emscripten_get_now() {
	return typeof performance < "u" ? performance.now() : Date.now();
}
var alignUp = (e, u) => e + (u - e % u) % u;
async function main(e) {
	let p, m, h = {};
	function g(e) {
		m = e, h.HEAPU8 = new Uint8Array(e), h.HEAPU32 = new Uint32Array(e);
	}
	function _(e, u, d) {
		h.HEAPU8.copyWithin(e, u, u + d);
	}
	function v(e) {
		try {
			return p.grow(e - m.byteLength + 65535 >>> 16), g(p.buffer), 1;
		} catch {}
	}
	function y(e) {
		let d = h.HEAPU8.length;
		e >>>= 0;
		let p = getHeapMax();
		if (e > p) return !1;
		for (let u = 1; u <= 4; u *= 2) {
			let m = d * (1 + .2 / u);
			if (m = Math.min(m, e + 100663296), v(Math.min(p, alignUp(Math.max(e, m), 65536)))) return !0;
		}
		return !1;
	}
	let b = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
	function x(e, u, d = 1024) {
		let f = u + d, p = u;
		for (; e[p] && !(p >= f);) ++p;
		if (p - u > 16 && e.buffer && b) return b.decode(e.subarray(u, p));
		let m = "";
		for (; u < p;) {
			let d = e[u++];
			if (!(d & 128)) {
				m += String.fromCharCode(d);
				continue;
			}
			let f = e[u++] & 63;
			if ((d & 224) == 192) {
				m += String.fromCharCode((d & 31) << 6 | f);
				continue;
			}
			let p = e[u++] & 63;
			if (d = (d & 240) == 224 ? (d & 15) << 12 | f << 6 | p : (d & 7) << 18 | f << 12 | p << 6 | e[u++] & 63, d < 65536) m += String.fromCharCode(d);
			else {
				let e = d - 65536;
				m += String.fromCharCode(55296 | e >> 10, 56320 | e & 1023);
			}
		}
		return m;
	}
	function S(e, u) {
		return e ? x(h.HEAPU8, e, u) : "";
	}
	let C = {
		emscripten_get_now: _emscripten_get_now,
		emscripten_memcpy_big: _,
		emscripten_resize_heap: y,
		fd_write: () => 0
	};
	async function w() {
		let u = await e({
			env: C,
			wasi_snapshot_preview1: C
		});
		p = u.memory, g(p.buffer), Object.assign(h, u), h.UTF8ToString = S;
	}
	return await w(), h;
}
var __defProp = Object.defineProperty, __defNormalProp = (e, u, d) => u in e ? __defProp(e, u, {
	enumerable: !0,
	configurable: !0,
	writable: !0,
	value: d
}) : e[u] = d, __publicField = (e, u, d) => __defNormalProp(e, typeof u == "symbol" ? u : u + "", d), onigBinding = null;
function throwLastOnigError(u) {
	throw new ShikiError(u.UTF8ToString(u.getLastOnigError()));
}
var UtfString = class e {
	constructor(u) {
		__publicField(this, "utf16Length"), __publicField(this, "utf8Length"), __publicField(this, "utf16Value"), __publicField(this, "utf8Value"), __publicField(this, "utf16OffsetToUtf8"), __publicField(this, "utf8OffsetToUtf16");
		let d = u.length, f = e._utf8ByteLength(u), p = f !== d, m = p ? new Uint32Array(d + 1) : null;
		p && (m[d] = f);
		let h = p ? new Uint32Array(f + 1) : null;
		p && (h[f] = d);
		let _ = new Uint8Array(f), v = 0;
		for (let e = 0; e < d; e++) {
			let f = u.charCodeAt(e), g = f, y = !1;
			if (f >= 55296 && f <= 56319 && e + 1 < d) {
				let d = u.charCodeAt(e + 1);
				d >= 56320 && d <= 57343 && (g = (f - 55296 << 10) + 65536 | d - 56320, y = !0);
			}
			p && (m[e] = v, y && (m[e + 1] = v), g <= 127 ? h[v + 0] = e : g <= 2047 ? (h[v + 0] = e, h[v + 1] = e) : g <= 65535 ? (h[v + 0] = e, h[v + 1] = e, h[v + 2] = e) : (h[v + 0] = e, h[v + 1] = e, h[v + 2] = e, h[v + 3] = e)), g <= 127 ? _[v++] = g : g <= 2047 ? (_[v++] = 192 | (g & 1984) >>> 6, _[v++] = 128 | (g & 63) >>> 0) : g <= 65535 ? (_[v++] = 224 | (g & 61440) >>> 12, _[v++] = 128 | (g & 4032) >>> 6, _[v++] = 128 | (g & 63) >>> 0) : (_[v++] = 240 | (g & 1835008) >>> 18, _[v++] = 128 | (g & 258048) >>> 12, _[v++] = 128 | (g & 4032) >>> 6, _[v++] = 128 | (g & 63) >>> 0), y && e++;
		}
		this.utf16Length = d, this.utf8Length = f, this.utf16Value = u, this.utf8Value = _, this.utf16OffsetToUtf8 = m, this.utf8OffsetToUtf16 = h;
	}
	static _utf8ByteLength(e) {
		let u = 0;
		for (let d = 0, f = e.length; d < f; d++) {
			let p = e.charCodeAt(d), m = p, h = !1;
			if (p >= 55296 && p <= 56319 && d + 1 < f) {
				let u = e.charCodeAt(d + 1);
				u >= 56320 && u <= 57343 && (m = (p - 55296 << 10) + 65536 | u - 56320, h = !0);
			}
			m <= 127 ? u += 1 : m <= 2047 ? u += 2 : m <= 65535 ? u += 3 : u += 4, h && d++;
		}
		return u;
	}
	createString(e) {
		let u = e.omalloc(this.utf8Length);
		return e.HEAPU8.set(this.utf8Value, u), u;
	}
}, _OnigString = class u {
	constructor(d) {
		if (__publicField(this, "id", ++u.LAST_ID), __publicField(this, "_onigBinding"), __publicField(this, "content"), __publicField(this, "utf16Length"), __publicField(this, "utf8Length"), __publicField(this, "utf16OffsetToUtf8"), __publicField(this, "utf8OffsetToUtf16"), __publicField(this, "ptr"), !onigBinding) throw new ShikiError("Must invoke loadWasm first.");
		this._onigBinding = onigBinding, this.content = d;
		let f = new UtfString(d);
		this.utf16Length = f.utf16Length, this.utf8Length = f.utf8Length, this.utf16OffsetToUtf8 = f.utf16OffsetToUtf8, this.utf8OffsetToUtf16 = f.utf8OffsetToUtf16, this.utf8Length < 1e4 && !u._sharedPtrInUse ? (u._sharedPtr ||= onigBinding.omalloc(1e4), u._sharedPtrInUse = !0, onigBinding.HEAPU8.set(f.utf8Value, u._sharedPtr), this.ptr = u._sharedPtr) : this.ptr = f.createString(onigBinding);
	}
	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 === u._sharedPtr ? u._sharedPtrInUse = !1 : this._onigBinding.ofree(this.ptr);
	}
};
__publicField(_OnigString, "LAST_ID", 0), __publicField(_OnigString, "_sharedPtr", 0), __publicField(_OnigString, "_sharedPtrInUse", !1);
var OnigString = _OnigString, OnigScanner = class {
	constructor(u) {
		if (__publicField(this, "_onigBinding"), __publicField(this, "_ptr"), !onigBinding) throw new ShikiError("Must invoke loadWasm first.");
		let d = [], f = [];
		for (let e = 0, p = u.length; e < p; e++) {
			let p = new UtfString(u[e]);
			d[e] = p.createString(onigBinding), f[e] = p.utf8Length;
		}
		let p = onigBinding.omalloc(4 * u.length);
		onigBinding.HEAPU32.set(d, p / 4);
		let m = onigBinding.omalloc(4 * u.length);
		onigBinding.HEAPU32.set(f, m / 4);
		let h = onigBinding.createOnigScanner(p, m, u.length);
		for (let e = 0, f = u.length; e < f; e++) onigBinding.ofree(d[e]);
		onigBinding.ofree(m), onigBinding.ofree(p), h === 0 && throwLastOnigError(onigBinding), this._onigBinding = onigBinding, this._ptr = h;
	}
	dispose() {
		this._onigBinding.freeOnigScanner(this._ptr);
	}
	findNextMatchSync(e, u, d) {
		let f = 0;
		if (typeof d == "number" && (f = d), typeof e == "string") {
			e = new OnigString(e);
			let d = this._findNextMatchSync(e, u, !1, f);
			return e.dispose(), d;
		}
		return this._findNextMatchSync(e, u, !1, f);
	}
	_findNextMatchSync(e, u, d, f) {
		let p = this._onigBinding, m = p.findNextOnigScannerMatch(this._ptr, e.id, e.ptr, e.utf8Length, e.convertUtf16OffsetToUtf8(u), f);
		if (m === 0) return null;
		let h = p.HEAPU32, g = m / 4, _ = h[g++], v = h[g++], y = [];
		for (let u = 0; u < v; u++) {
			let d = e.convertUtf8OffsetToUtf16(h[g++]), f = e.convertUtf8OffsetToUtf16(h[g++]);
			y[u] = {
				start: d,
				end: f,
				length: f - d
			};
		}
		return {
			index: _,
			captureIndices: y
		};
	}
};
function isInstantiatorOptionsObject(e) {
	return typeof e.instantiator == "function";
}
function isInstantiatorModule(e) {
	return typeof e.default == "function";
}
function isDataOptionsObject(e) {
	return e.data !== void 0;
}
function isResponse(e) {
	return typeof Response < "u" && e instanceof Response;
}
function isArrayBuffer(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 initPromise;
function loadWasm(e) {
	if (initPromise) return initPromise;
	async function u() {
		onigBinding = await main(async (u) => {
			let d = e;
			return d = await d, typeof d == "function" && (d = await d(u)), typeof d == "function" && (d = await d(u)), isInstantiatorOptionsObject(d) ? d = await d.instantiator(u) : isInstantiatorModule(d) ? d = await d.default(u) : (isDataOptionsObject(d) && (d = d.data), isResponse(d) ? d = typeof WebAssembly.instantiateStreaming == "function" ? await _makeResponseStreamingLoader(d)(u) : await _makeResponseNonStreamingLoader(d)(u) : isArrayBuffer(d) || d instanceof WebAssembly.Module ? d = await _makeArrayBufferLoader(d)(u) : "default" in d && d.default instanceof WebAssembly.Module && (d = await _makeArrayBufferLoader(d.default)(u))), "instance" in d && (d = d.instance), "exports" in d && (d = d.exports), d;
		});
	}
	return initPromise = u(), initPromise;
}
function _makeArrayBufferLoader(e) {
	return (u) => WebAssembly.instantiate(e, u);
}
function _makeResponseStreamingLoader(e) {
	return (u) => WebAssembly.instantiateStreaming(e, u);
}
function _makeResponseNonStreamingLoader(e) {
	return async (u) => {
		let d = await e.arrayBuffer();
		return WebAssembly.instantiate(d, u);
	};
}
async function createOnigurumaEngine(e) {
	return e && await loadWasm(e), {
		createScanner(e) {
			return new OnigScanner(e.map((e) => typeof e == "string" ? e : e.source));
		},
		createString(e) {
			return new OnigString(e);
		}
	};
}
export { createOnigurumaEngine };
