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