//#region ../../node_modules/@ungap/structured-clone/esm/serialize.js
var e = "", { toString: t } = {}, { keys: n } = Object, r = (n) => {
	let r = typeof n;
	if (r !== "object" || !n) return [0, r];
	let i = t.call(n).slice(8, -1);
	switch (i) {
		case "Array": return [1, e];
		case "Object": return [2, e];
		case "Date": return [3, e];
		case "RegExp": return [4, e];
		case "Map": return [5, e];
		case "Set": return [6, e];
		case "DataView": return [1, i];
	}
	return i.includes("Array") ? [1, i] : i.includes("Error") ? [7, i] : [2, i];
}, i = ([e, t]) => e === 0 && (t === "function" || t === "symbol"), a = (e, t, a, o) => {
	let s = (e, t) => {
		let n = o.push(e) - 1;
		return a.set(t, n), n;
	}, c = (o) => {
		if (a.has(o)) return a.get(o);
		let [l, u] = r(o);
		switch (l) {
			case 0: {
				let t = o;
				switch (u) {
					case "bigint":
						l = 8, t = o.toString();
						break;
					case "function":
					case "symbol":
						if (e) throw TypeError("unable to serialize " + u);
						t = null;
						break;
					case "undefined": return s([-1], o);
				}
				return s([l, t], o);
			}
			case 1: {
				if (u) {
					let e = o;
					return u === "DataView" ? e = new Uint8Array(o.buffer) : u === "ArrayBuffer" && (e = new Uint8Array(o)), s([u, [...e]], o);
				}
				let e = [], t = s([l, e], o);
				for (let t of o) e.push(c(t));
				return t;
			}
			case 2: {
				if (u) switch (u) {
					case "BigInt": return s([u, o.toString()], o);
					case "Boolean":
					case "Number":
					case "String": return s([u, o.valueOf()], o);
				}
				if (t && "toJSON" in o) return c(o.toJSON());
				let a = [], d = s([l, a], o);
				for (let t of n(o)) (e || !i(r(o[t]))) && a.push([c(t), c(o[t])]);
				return d;
			}
			case 3: return s([l, o.toISOString()], o);
			case 4: {
				let { source: e, flags: t } = o;
				return s([l, {
					source: e,
					flags: t
				}], o);
			}
			case 5: {
				let t = [], n = s([l, t], o);
				for (let [n, a] of o) (e || !(i(r(n)) || i(r(a)))) && t.push([c(n), c(a)]);
				return n;
			}
			case 6: {
				let t = [], n = s([l, t], o);
				for (let n of o) (e || !i(r(n))) && t.push(c(n));
				return n;
			}
		}
		let { message: d } = o;
		return s([l, {
			name: u,
			message: d
		}], o);
	};
	return c;
}, o = (e, { json: t, lossy: n } = {}) => {
	let r = [];
	return a(!(t || n), !!t, /* @__PURE__ */ new Map(), r)(e), r;
};
//#endregion
export { o as serialize };
