"use strict";var Ve=Object.defineProperty;var yr=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var Nr=Object.prototype.hasOwnProperty;var br=(n,e)=>{for(var r in e)Ve(n,r,{get:e[r],enumerable:!0})},xr=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of vr(e))!Nr.call(n,s)&&s!==r&&Ve(n,s,{get:()=>e[s],enumerable:!(t=yr(e,s))||t.enumerable});return n};var Ar=n=>xr(Ve({},"__esModule",{value:!0}),n);var Xr={};br(Xr,{Feature:()=>R,OpaqueReference:()=>I,Serializer:()=>ie,SerovalDeserializationError:()=>Q,SerovalError:()=>U,SerovalMissingInstanceError:()=>g,SerovalMissingPluginError:()=>O,SerovalMissingReferenceError:()=>H,SerovalMissingReferenceForIdError:()=>Z,SerovalParserError:()=>P,SerovalSerializationError:()=>X,SerovalUnknownTypedArrayError:()=>ee,SerovalUnsupportedNodeError:()=>m,SerovalUnsupportedTypeError:()=>p,compileJSON:()=>Hr,createPlugin:()=>wr,createReference:()=>Le,createStream:()=>C,crossSerialize:()=>_r,crossSerializeAsync:()=>Mr,crossSerializeStream:()=>Ue,deserialize:()=>$r,fromCrossJSON:()=>Lr,fromJSON:()=>Zr,getCrossReferenceHeader:()=>Ke,resolvePlugins:()=>c,serialize:()=>Jr,serializeAsync:()=>Yr,toCrossJSON:()=>Ur,toCrossJSONAsync:()=>Wr,toCrossJSONStream:()=>Kr,toJSON:()=>Gr,toJSONAsync:()=>qr});module.exports=Ar(Xr);var R=(o=>(o[o.AggregateError=1]="AggregateError",o[o.ArrowFunction=2]="ArrowFunction",o[o.ErrorPrototypeStack=4]="ErrorPrototypeStack",o[o.ObjectAssign=8]="ObjectAssign",o[o.BigIntTypedArray=16]="BigIntTypedArray",o))(R||{});function Ir(n){switch(n){case'"':return'\\"';case"\\":return"\\\\";case` `:return"\\n";case"\r":return"\\r";case"\b":return"\\b";case" ":return"\\t";case"\f":return"\\f";case"<":return"\\x3C";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029";default:return}}function d(n){let e="",r=0,t;for(let s=0,o=n.length;s{n=r,e=t}),resolve(r){n(r)},reject(r){e(r)}}}function ze(n){return"__SEROVAL_STREAM__"in n}function C(){let n=new Set,e=[],r=!0,t=!0;function s(a){for(let l of n.keys())l.next(a)}function o(a){for(let l of n.keys())l.throw(a)}function i(a){for(let l of n.keys())l.return(a)}return{__SEROVAL_STREAM__:!0,on(a){r&&n.add(a);for(let l=0,u=e.length;l{r&&n.delete(a)}},next(a){r&&(e.push(a),s(a))},throw(a){r&&(e.push(a),o(a),r=!1,t=!1,n.clear())},return(a){r&&(e.push(a),i(a),r=!1,t=!0,n.clear())}}}function Te(n){let e=C(),r=n[Symbol.asyncIterator]();async function t(){try{let s=await r.next();s.done?e.return(s.value):(e.next(s.value),await t())}catch(s){e.throw(s)}}return t().catch(()=>{}),e}function ur(n){return()=>{let e=[],r=[],t=0,s=-1,o=!1;function i(){for(let l=0,u=r.length;l=e.length){let u=re();return r.push(u),await u.promise}return{done:!1,value:e[l]}}return t>s?{done:!0,value:void 0}:a()}}}}function W(n){let e=[],r=-1,t=-1,s=n[Symbol.iterator]();for(;;)try{let o=s.next();if(e.push(o.value),o.done){t=e.length-1;break}}catch(o){r=e.length,e.push(o)}return{v:e,t:r,d:t}}function dr(n){return()=>{let e=0;return{[Symbol.iterator](){return this},next(){if(e>n.d)return{done:!0,value:void 0};let r=e++,t=n.v[r];if(r===n.t)throw t;return{done:r===n.d,value:t}}}}}async function _e(n){try{return[1,await n]}catch(e){return[0,e]}}var K=class{constructor(e){this.marked=new Set;this.plugins=e.plugins,this.features=31^(e.disabledFeatures||0),this.refs=e.refs||new Map}markRef(e){this.marked.add(e)}isMarked(e){return this.marked.has(e)}getIndexedValue(e){let r=this.refs.get(e);if(r!=null)return this.markRef(r),{type:1,value:sr(r)};let t=this.refs.size;return this.refs.set(e,t),{type:0,value:t}}getReference(e){let r=this.getIndexedValue(e);return r.type===1?r:le(e)?{type:2,value:Be(r.value,e)}:r}getStrictReference(e){f(le(e),new p(e));let r=this.getIndexedValue(e);return r.type===1?r.value:Be(r.value,e)}parseFunction(e){return this.getStrictReference(e)}parseWellKnownSymbol(e){let r=this.getReference(e);return r.type!==0?r.value:(f(e in ue,new p(e)),or(r.value,e))}parseSpecialReference(e){let r=this.getIndexedValue(lr[e]);return r.type===1?r.value:{t:26,i:r.value,s:e,l:void 0,c:void 0,m:void 0,p:void 0,e:void 0,a:void 0,f:void 0,b:void 0,o:void 0}}parseIteratorFactory(){let e=this.getIndexedValue(ir);return e.type===1?e.value:{t:27,i:e.value,s:void 0,l:void 0,c:void 0,m:void 0,p:void 0,e:void 0,a:void 0,f:this.parseWellKnownSymbol(Symbol.iterator),b:void 0,o:void 0}}parseAsyncIteratorFactory(){let e=this.getIndexedValue(ar);return e.type===1?e.value:{t:29,i:e.value,s:void 0,l:void 0,c:void 0,m:void 0,p:void 0,e:void 0,a:[this.parseSpecialReference(1),this.parseWellKnownSymbol(Symbol.asyncIterator)],f:void 0,b:void 0,o:void 0}}createObjectNode(e,r,t,s){return{t:t?11:10,i:e,s:void 0,l:void 0,c:void 0,m:void 0,p:s,e:void 0,a:void 0,f:void 0,b:void 0,o:me(r)}}createMapNode(e,r,t,s){return{t:8,i:e,s:void 0,l:void 0,c:void 0,m:void 0,p:void 0,e:{k:r,v:t,s},a:void 0,f:this.parseSpecialReference(0),b:void 0,o:void 0}}createPromiseConstructorNode(e){return{t:22,i:e,s:void 0,l:void 0,c:void 0,m:void 0,p:void 0,e:void 0,a:void 0,f:this.parseSpecialReference(1),b:void 0,o:void 0}}};var z=class extends K{async parseItems(e){let r=[];for(let t=0,s=e.length;t{let o=[],i=r.on({next:a=>{this.markRef(e),this.parse(a).then(l=>{o.push(Pe(e,l))},l=>{s(l),i()})},throw:a=>{this.markRef(e),this.parse(a).then(l=>{o.push(Oe(e,l)),t(o),i()},l=>{s(l),i()})},return:a=>{this.markRef(e),this.parse(a).then(l=>{o.push(Ce(e,l)),t(o),i()},l=>{s(l),i()})}})}))}async parseObject(e,r){if(Array.isArray(r))return this.parseArray(e,r);if(ze(r))return this.parseStream(e,r);let t=r.constructor;if(t===I)return this.parse(r.replacement);let s=await this.parsePlugin(e,r);if(s)return s;switch(t){case Object:return this.parsePlainObject(e,r,!1);case void 0:return this.parsePlainObject(e,r,!0);case Date:return he(e,r);case RegExp:return ye(e,r);case Error:case EvalError:case RangeError:case ReferenceError:case SyntaxError:case TypeError:case URIError:return this.parseError(e,r);case Number:case Boolean:case String:case BigInt:return this.parseBoxed(e,r);case ArrayBuffer:return ve(e,r);case Int8Array:case Int16Array:case Int32Array:case Uint8Array:case Uint16Array:case Uint32Array:case Uint8ClampedArray:case Float32Array:case Float64Array:return this.parseTypedArray(e,r);case DataView:return this.parseDataView(e,r);case Map:return this.parseMap(e,r);case Set:return this.parseSet(e,r);default:break}if(t===Promise||r instanceof Promise)return this.parsePromise(e,r);let o=this.features;if(o&16)switch(t){case BigInt64Array:case BigUint64Array:return this.parseBigIntTypedArray(e,r);default:break}if(o&1&&typeof AggregateError!="undefined"&&(t===AggregateError||r instanceof AggregateError))return this.parseAggregateError(e,r);if(r instanceof Error)return this.parseError(e,r);if(Symbol.iterator in r||Symbol.asyncIterator in r)return this.parsePlainObject(e,r,!!t);throw new p(r)}async parse(e){try{switch(typeof e){case"boolean":return e?b:x;case"undefined":return ce;case"string":return A(e);case"number":return ge(e);case"bigint":return Se(e);case"object":{if(e){let r=this.getReference(e);return r.type===0?await this.parseObject(r.value,e):r.value}return fe}case"symbol":return this.parseWellKnownSymbol(e);case"function":return this.parseFunction(e);default:throw new p(e)}}catch(r){throw new P(r)}}};var L=class extends z{constructor(){super(...arguments);this.mode="cross"}};function cr(n){switch(n){case"Int8Array":return Int8Array;case"Int16Array":return Int16Array;case"Int32Array":return Int32Array;case"Uint8Array":return Uint8Array;case"Uint16Array":return Uint16Array;case"Uint32Array":return Uint32Array;case"Uint8ClampedArray":return Uint8ClampedArray;case"Float32Array":return Float32Array;case"Float64Array":return Float64Array;case"BigInt64Array":return BigInt64Array;case"BigUint64Array":return BigUint64Array;default:throw new ee(n)}}function fr(n,e){switch(e){case 3:return Object.freeze(n);case 1:return Object.preventExtensions(n);case 2:return Object.seal(n);default:return n}}var T=class{constructor(e){this.plugins=e.plugins,this.refs=e.refs||new Map}deserializeReference(e){return this.assignIndexedValue(e.i,Ye(y(e.s)))}deserializeArray(e){let r=e.l,t=this.assignIndexedValue(e.i,new Array(r)),s;for(let o=0;o="A"&&e<="Z"||e>="a"&&e<="z")&&zr.test(n)}function ne(n){switch(n.t){case 0:return n.s+"="+n.v;case 2:return n.s+".set("+n.k+","+n.v+")";case 1:return n.s+".add("+n.v+")";case 3:return n.s+".delete("+n.k+")"}}function Tr(n){let e=[],r=n[0];for(let t=1,s=n.length,o,i=r;t"+(r.startsWith("{")?"("+r+")":r):"function("+e.join(",")+"){return "+r+"}"}createEffectfulFunction(e,r){return this.features&2?(e.length===1?e[0]:"("+e.join(",")+")")+"=>{"+r+"}":"function("+e.join(",")+"){"+r+"}"}markRef(e){this.marked.add(e)}isMarked(e){return this.marked.has(e)}pushObjectFlag(e,r){e!==0&&(this.markRef(r),this.flags.push({type:e,value:this.getRefParam(r)}))}resolveFlags(){let e="";for(let r=0,t=this.flags,s=t.length;r=0&&s.toString()===r||Me(r);if(this.isIndexedValueInStack(t)){let i=this.getRefParam(t.i);return this.markRef(e.i),o&&s!==s?this.createObjectAssign(e.i,r,i):this.createArrayAssign(e.i,o?r:'"'+r+'"',i),""}return(o?r:'"'+r+'"')+":"+this.serialize(t)}return"["+this.serialize(r)+"]:"+this.serialize(t)}serializeProperties(e,r){let t=r.s;if(t){let s=r.k,o=r.v;this.stack.push(e.i);let i=this.serializeProperty(e,s[0],o[0]);for(let a=1,l=i;a=0&&i.toString()===t||Me(t);if(this.isIndexedValueInStack(s))a&&i!==i?this.createObjectAssign(e.i,t,o):this.createArrayAssign(e.i,a?t:'"'+t+'"',o);else{let l=this.assignments;this.assignments=r,a&&i!==i?this.createObjectAssign(e.i,t,o):this.createArrayAssign(e.i,a?t:'"'+t+'"',o),this.assignments=l}}serializeAssignment(e,r,t,s){if(typeof t=="string")this.serializeStringKeyAssignment(e,r,t,s);else{let o=this.stack;this.stack=[];let i=this.serialize(s);this.stack=o;let a=this.assignments;this.assignments=r,this.createArrayAssign(e.i,this.serialize(t),i),this.assignments=a}}serializeAssignments(e,r){let t=r.s;if(t){let s=[],o=r.k,i=r.v;this.stack.push(e.i);for(let a=0;as.d)return{done:!0,value:void 0};if(d=s.v[c=i++],c===s.t)throw d;return{done:c===s.d,value:d}")+"})"))),t&&(r+=")"),r}serializeIteratorFactoryInstance(e){return this.getConstructor(e.a[0])+"("+this.serialize(e.a[1])+")"}serializeAsyncIteratorFactory(e){let r=e.a[0],t=e.a[1],s="";r.t!==4&&(this.markRef(r.i),s+="("+this.serialize(r)),t.t!==4&&(this.markRef(t.i),s+=(s?",":"(")+this.serialize(t)),s&&(s+=",");let o=this.assignIndexedValue(e.i,this.createFunction(["s"],this.createFunction(["b","c","p","d","e","t","f"],"(b=[],c=0,p=[],d=-1,e=!1,f="+this.createEffectfulFunction(["i","l"],"for(i=0,l=p.length;i=b.length)?(p.push(t="+this.getRefParam(r.i)+"()),t):{done:!1,value:b[i]}}if(c>d)return{done:!0,value:void 0};if(v=b[i=c++],i!==d)return{done:!1,value:v};if(e)throw v;return{done:!0,value:v}")+"})")));return s?s+o+")":o}serializeAsyncIteratorFactoryInstance(e){return this.getConstructor(e.a[0])+"("+this.serialize(e.a[1])+")"}serializeStreamConstructor(e){let r=this.assignIndexedValue(e.i,this.getConstructor(e.f)+"()"),t=e.a.length;if(t){let s=this.serialize(e.a[0]);for(let o=1;o{let o=this.parseWithError(s);o&&this.onParse({t:23,i:r,s:void 0,l:void 0,c:void 0,m:void 0,p:void 0,e:void 0,a:[this.parseSpecialReference(2),o],f:void 0,b:void 0,o:void 0}),this.popPendingState()},s=>{if(this.alive){let o=this.parseWithError(s);o&&this.onParse({t:24,i:r,s:void 0,l:void 0,c:void 0,m:void 0,p:void 0,e:void 0,a:[this.parseSpecialReference(3),o],f:void 0,b:void 0,o:void 0})}this.popPendingState()}),this.pushPendingState(),this.createPromiseConstructorNode(r)}parsePlugin(r,t){let s=this.plugins;if(s)for(let o=0,i=s.length;o{if(this.alive){let i=this.parseWithError(o);i&&this.onParse(Pe(r,i))}},throw:o=>{if(this.alive){let i=this.parseWithError(o);i&&this.onParse(Oe(r,i))}this.popPendingState()},return:o=>{if(this.alive){let i=this.parseWithError(o);i&&this.onParse(Ce(r,i))}this.popPendingState()}}),s}parseWithError(r){try{return this.parse(r)}catch(t){this.onError(t);return}}start(r){let t=this.parseWithError(r);t&&(this.onParseInternal(t,!0),this.initial=!1,this.flush(),this.pending<=0&&this.destroy())}destroy(){this.alive&&(this.onDone(),this.alive=!1)}isAlive(){return this.alive}};var J=class extends se{constructor(){super(...arguments);this.mode="cross"}};var Y=class extends S{constructor(){super(...arguments);this.mode="cross"}};function _r(n,e={}){let r=c(e.plugins),t=new Y({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}),s=t.parse(n);return new F({plugins:r,features:t.features,scopeId:e.scopeId,markedRefs:t.marked}).serializeTop(s)}async function Mr(n,e={}){let r=c(e.plugins),t=new L({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}),s=await t.parse(n);return new F({plugins:r,features:t.features,scopeId:e.scopeId,markedRefs:t.marked}).serializeTop(s)}function Ur(n,e={}){let r=c(e.plugins);return new Y({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}).parse(n)}async function Wr(n,e={}){let r=c(e.plugins);return await new L({plugins:r,disabledFeatures:e.disabledFeatures,refs:e.refs}).parse(n)}function Ue(n,e){let r=c(e.plugins),t=new J({plugins:r,refs:e.refs,disabledFeatures:e.disabledFeatures,onParse(s,o){let i=new F({plugins:r,features:t.features,scopeId:e.scopeId,markedRefs:t.marked}),a;try{a=i.serializeTop(s)}catch(l){e.onError&&e.onError(l);return}e.onSerialize(a,o)},onError:e.onError,onDone:e.onDone});return t.start(n),()=>{t.destroy()}}function Kr(n,e){let r=c(e.plugins),t=new J({plugins:r,refs:e.refs,disabledFeatures:e.disabledFeatures,onParse:e.onParse,onError:e.onError,onDone:e.onDone});return t.start(n),()=>{t.destroy()}}function Lr(n,e){let r=c(e.plugins);return new te({plugins:r,refs:e.refs}).deserialize(n)}var $=class extends z{constructor(){super(...arguments);this.mode="vanilla"}};var oe=class extends T{constructor(r){super(r);this.mode="vanilla";this.marked=new Set(r.markedRefs)}assignIndexedValue(r,t){return this.marked.has(r)&&this.refs.set(r,t),t}};var Sr="hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_",mr=Sr.length,hr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_",gr=hr.length;function We(n){let e=n%mr,r=Sr[e];for(n=(n-e)/mr;n>0;)e=n%gr,r+=hr[e],n=(n-e)/gr;return r}var V=class extends k{constructor(){super(...arguments);this.mode="vanilla";this.valid=new Map;this.vars=[]}getRefParam(r){let t=this.valid.get(r);t==null&&(t=this.valid.size,this.valid.set(r,t));let s=this.vars[t];return s==null&&(s=We(t),this.vars[t]=s),s}assignIndexedValue(r,t){return this.isMarked(r)?this.getRefParam(r)+"="+t:t}serializePromiseConstructor(r){throw new m(r)}serializePromiseResolve(r){throw new m(r)}serializePromiseReject(r){throw new m(r)}serializeTop(r){let t=this.serialize(r);if(r.i!=null&&this.vars.length){let s=this.resolvePatches(),o=t;if(s){let i=this.getRefParam(r.i);o=t+","+s+i,t.startsWith(i+"=")||(o=i+"="+o),o="("+o+")"}return"("+this.createFunction(this.vars,o)+")()"}return r.t===10?"("+t+")":t}};var G=class extends S{constructor(){super(...arguments);this.mode="vanilla"}};function Jr(n,e={}){let r=c(e.plugins),t=new G({plugins:r,disabledFeatures:e.disabledFeatures}),s=t.parse(n);return new V({plugins:r,features:t.features,markedRefs:t.marked}).serializeTop(s)}async function Yr(n,e={}){let r=c(e.plugins),t=new $({plugins:r,disabledFeatures:e.disabledFeatures}),s=await t.parse(n);return new V({plugins:r,features:t.features,markedRefs:t.marked}).serializeTop(s)}function $r(n){return(0,eval)(n)}function Gr(n,e={}){let r=c(e.plugins),t=new G({plugins:r,disabledFeatures:e.disabledFeatures});return{t:t.parse(n),f:t.features,m:Array.from(t.marked)}}async function qr(n,e={}){let r=c(e.plugins),t=new $({plugins:r,disabledFeatures:e.disabledFeatures});return{t:await t.parse(n),f:t.features,m:Array.from(t.marked)}}function Hr(n,e={}){let r=c(e.plugins);return new V({plugins:r,features:n.f,markedRefs:n.m}).serializeTop(n.t)}function Zr(n,e={}){let r=c(e.plugins);return new oe({plugins:r,markedRefs:n.m}).deserialize(n.t)}var ie=class{constructor(e){this.options=e;this.alive=!0;this.flushed=!1;this.done=!1;this.pending=0;this.cleanups=[];this.refs=new Map;this.keys=new Set;this.ids=0;this.plugins=c(e.plugins)}write(e,r){this.alive&&!this.flushed&&(this.pending++,this.keys.add(e),this.cleanups.push(Ue(r,{plugins:this.plugins,scopeId:this.options.scopeId,refs:this.refs,disabledFeatures:this.options.disabledFeatures,onError:this.options.onError,onSerialize:(t,s)=>{this.alive&&this.options.onData(s?this.options.globalIdentifier+'["'+d(e)+'"]='+t:t)},onDone:()=>{this.alive&&(this.pending--,this.pending<=0&&this.flushed&&!this.done&&this.options.onDone&&(this.options.onDone(),this.done=!0))}})))}getNextID(){for(;this.keys.has(""+this.ids);)this.ids++;return""+this.ids}push(e){let r=this.getNextID();return this.write(r,e),r}flush(){this.alive&&(this.flushed=!0,this.pending<=0&&!this.done&&this.options.onDone&&(this.options.onDone(),this.done=!0))}close(){if(this.alive){for(let e=0,r=this.cleanups.length;e