UNPKG

jsox

Version:

Java Script Object eXchange.

2 lines (1 loc) 31.7 kB
"use strict";const e=JSON;if(void 0===t)var t={};const n=t||{};t.JSOX=n,n.version="1.2.120",function(){const t="function"==typeof BigInt,r=["ab","u8","cu8","s8","u16","s16","u32","s32","u64","s64","f32","f64"];let s=null,i=null;const a=[ArrayBuffer,Uint8Array,Uint8ClampedArray,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,null,null,Float32Array,Float64Array],l=29,o=30,c=31,u={true:!0,false:!1,null:null,NaN:NaN,Infinity:1/0,undefined:void 0};class f extends Date{constructor(e,t){super(e),this.ns=t||0}}n.DateNS=f;const p=[];function g(){let e=p.pop();return e||(e={context:0,current_proto:null,current_class:null,current_class_field:0,arrayType:-1,valueType:0,elements:null}),e}function h(e){p.push(e)}n.updateContext=function(){};const b=[];function y(e){b.push(e)}n.escape=function(e){let t,n="";if(!e)return e;for(t=0;t<e.length;t++)'"'!=e[t]&&"\\"!=e[t]&&"`"!=e[t]&&"'"!=e[t]||(n+="\\"),n+=e[t];return n};let d=new WeakMap,m=new Map,v=new Map,k=[];n.reset=function(){d=new WeakMap,m=new Map,v=new Map,k=[]},n.begin=function(e,n){const s={name:null,value_type:0,string:"",contains:null,className:null},i={line:1,col:1};let u,p,d=0,m=new Map,k=0,w=!0,x=!1,_=!1,N=null,O=null,j={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last?this.last.next=t:this.first=t,this.last=t,this.length++},pop(){let e=this.last;return(this.last=e.prior)||(this.first=null),e.next=this.saved,this.last&&(this.last.next=null),e.next||(e.first=null),this.saved=e,this.length--,e.node},length:0},E=[],A={},T=null,D=null,I=0,M=-1,P=0,C=0,X=!1,J=!1,F=!1,$=!1,B=!1,U={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last?this.last.next=t:this.first=t,this.last=t},shift(){let e=this.first;return e?((this.first=e.next)||(this.last=null),e.next=this.saved,this.saved=e,e.node):null},unshift(e){let t=this.saved;this.saved=t.next,t.node=e,t.next=this.first,t.prior=null,this.first||(this.last=t),this.first=t}},q=null,R=!1,H=!1,z=!1,W=!1,L=!1,Y=!1,G=!1,V=0,K=0,Q=!1,Z=!1,ee=!1;function te(e){throw new Error(`${e} at ${d} [${i.line}:${i.col}]`)}return{fromJSOX(e,t,n){if(m.get(e))throw new Error("Existing fromJSOX has been registered for prototype");if(t||(t=function(){}),t&&!("constructor"in t))throw new Error("Please pass a prototype like thing...");m.set(e,{protoCon:t.prototype.constructor,cb:n})},registerFromJSOX(e,t){throw new Error("registerFromJSOX is deprecated, please update to use fromJSOX instead:"+e+t.toString())},finalError(){0!==C&&(1===C&&te("Comment began at end of document"),3===C&&te("Open comment '/*' is missing close at end of document"),4===C&&te("Incomplete '/* *' close at end of document")),R&&te("Incomplete string")},value(){this.finalError();let e=N;return N=void 0,e},reset(){k=0,w=!0,U.last&&(U.last.next=U.save),U.save=U.first,U.first=U.last=null,j.last&&(j.last.next=j.save),j.length=0,j.save=U.first,j.first=j.last=null,p=void 0,P=0,E=[],A={},T=null,D=null,I=0,s.value_type=0,s.name=null,s.string="",s.className=null,i.line=1,i.col=1,_=!1,C=0,Q=!1,R=!1,z=!1,W=!1,Z=!1},usePrototype(e,t){A[e]=t},write(t){let r;if("string"!=typeof t&&void 0!==t&&(t=String(t)),!w)throw new Error("Parser is still in an error state, please reset before resuming");for(r=this._write(t,!1);r>0&&("function"==typeof n&&function e(t,r){let s,i,a=t[r];if(a&&"object"==typeof a)for(s in a)Object.prototype.hasOwnProperty.call(a,s)&&(i=e(a,s),void 0!==i?a[s]=i:delete a[s]);return n.call(t,r,a)}({"":N},""),N=e(N),!(r<2));r=this._write());},parse(e,t){"string"!=typeof e&&(e=String(e)),this.reset();const n=this._write(e,!0);if(n>0){let e=this.value();if(void 0===e&&n>1)throw new Error("Pending value could not complete");return e="function"==typeof t?function e(n,r){let s,i,a=n[r];if(a&&"object"==typeof a)for(s in a)Object.prototype.hasOwnProperty.call(a,s)&&(i=e(a,s),void 0!==i?a[s]=i:delete a[s]);return t.call(n,r,a)}({"":e},""):e,e}this.finalError()},_write(e,n){let A,te,ne,re=0;function se(e,t){throw new Error(`${e} '${String.fromCodePoint(t)}' unexpected at ${d} (near '${ne.substr(d>4?d-4:0,d>4?3:d-1)}[${String.fromCodePoint(t)}]${ne.substr(d,10)}') [${i.line}:${i.col}]`)}function ie(){s.value_type=0,s.string="",s.contains=null}function ae(){let e=null;switch(s.value_type){case 5:if(!(s.string.length>13||13==s.string.length&&s[0]>"2")||Z||B||$||J||(ee=!0),ee){if(t)return BigInt(s.string);throw new Error("no builtin BigInt()",0)}if(Z){const e=s.string.match(/\.(\d\d\d\d*)/),t=e?e[1]:null;if(!t||t.length<4){const e=new Date(s.string);return isNaN(e.getTime())&&se("Bad Date format",A),e}{let e=t.substr(3);for(;e.length<6;)e+="0";const n=new f(s.string,Number(e));return isNaN(n.getTime())&&se("Bad DateNS format"+n+n.getTime(),A),n}}return(_?-1:1)*Number(s.string);case 4:if(s.className){if(e=m.get(s.className),e||(e=v.get(s.className)),e&&e.cb)return s.className=null,e.cb.call(s.string);throw new Error("Double string error, no constructor for: new "+s.className+"("+s.string+")")}return s.string;case 2:return!0;case 3:return!1;case 7:case 8:return NaN;case 9:return-1/0;case 10:return 1/0;case 1:return null;case-1:case 12:return;case 6:return s.className&&(e=m.get(s.className),e||(e=v.get(s.className)),s.className=null,e&&e.cb)?s.contains=e.cb.call(s.contains):s.contains;case 13:if(M>=0){let e;if(e=s.contains.length?S(s.contains[0]):S(s.string),0===M)return M=-1,e;{const t=new a[M](e);return M=-1,t}}if(-2===M){let e,t=O;const n=s.contains.length;for(e=0;e<n;e++){const r=s.contains[e];let i=t[r];if(!i){let r=j.first,a=0;for(;r&&a<n&&a<j.length;){const n=s.contains[a];if(!r.next||n!==r.next.node.name)break;if(r.next)if("number"==typeof n){const e=r.next.node.elements;if(e&&n>=e.length){if(a===j.length-1){console.log("This is actually at the current object so use that",a,s.contains,p),i=p,a++,r=r.next;break}if(r.next.next&&n===e.length){i=r.next.next.node.elements,r=r.next,a++,t=i;continue}i=p,a++;break}}else{if(n!==r.next.node.name){i=r.next.node.elements[n],e=a;break}i=r.next.next?r.next.next.node.elements:p}else i=i[n];r=r.next,a++}e=a<n?a-1:a}if("object"==typeof i&&!i)throw new Error("Path did not resolve properly:"+s.contains+" at "+r+"("+e+")");t=i}return M=-3,t}return s.className&&(e=m.get(s.className),e||(e=v.get(s.className)),s.className=null,e&&e.cb)?e.cb.call(s.contains):s.contains;default:console.log("Unhandled value conversion.",s)}}function le(){if(-3==M)return 6===s.value_type&&p.push(s.contains),void(M=-1);if(12===s.value_type)p.push(void 0),delete p[p.length-1];else p.push(ae());ie()}function oe(){if(-3===M&&13===s.value_type)return ie(),void(M=-1);if(12===s.value_type)return;!s.name&&D&&(s.name=D.fields[I++]);let e=ae();T&&T.protoDef&&T.protoDef.cb?(e=T.protoDef.cb.call(p,s.name,e),e&&(p[s.name]=e)):p[s.name]=e,ie()}function ce(e){if(0!==k){switch(_&&se("Negative outside of quotes, being converted to a string (would lose count of leading '-' characters)",e),k){case c:switch(s.value_type){case 2:s.string+="true";break;case 3:s.string+="false";break;case 1:s.string+="null";break;case 10:s.string+="Infinity";break;case 9:s.string+="-Infinity",se("Negative outside of quotes, being converted to a string",e);break;case 8:s.string+="NaN";break;case 7:s.string+="-NaN",se("Negative outside of quotes, being converted to a string",e);break;case-1:s.string+="undefined";break;case 4:case 0:break;default:console.log("Value of type "+s.value_type+" is not restored...")}break;case 1:s.string+="t";break;case 2:s.string+="tr";break;case 3:s.string+="tru";break;case 5:s.string+="f";break;case 6:s.string+="fa";break;case 7:s.string+="fal";break;case 8:s.string+="fals";break;case 9:s.string+="n";break;case 10:s.string+="nu";break;case 11:s.string+="nul";break;case 12:s.string+="u";break;case 13:s.string+="un";break;case 14:s.string+="und";break;case 15:s.string+="unde";break;case 16:s.string+="undef";break;case 17:s.string+="undefi";break;case 18:s.string+="undefin";break;case 19:s.string+="undefine";break;case 20:s.string+="N";break;case 21:s.string+="Na";break;case 22:s.string+="I";break;case 23:s.string+="In";break;case 24:s.string+="Inf";break;case 25:s.string+="Infi";break;case 26:s.string+="Infin";break;case 27:s.string+="Infini";break;case 28:s.string+="Infinit";break;case 0:case l:case o:break;case 32:se("String-keyword recovery fail (after whitespace)",e)}s.value_type=4,k<l&&(k=c)}else k=c,s.value_type=4;if(123==e)pe();else if(91==e)ge();else if(44==e);else{if(32==e||13==e||10==e||9==e||65279==e||8232==e||8233==e)return;44==e||125==e||93==e||58==e?se("Invalid character near identifier",e):s.string+=u}}function ue(e){let t=0;for(;0==t&&d<ne.length;){u=ne.charAt(d);let n=ne.codePointAt(d++);if(n>=65536&&(u+=ne.charAt(d),d++),i.col++,n==e)z?(G?se("Incomplete hexidecimal sequence",n):Y?se("Incomplete long unicode sequence",n):L&&se("Incomplete unicode sequence",n),W?(W=!1,t=1):s.string+=u,z=!1):t=1;else if(z){if(L){if(125==n){s.string+=String.fromCodePoint(V),L=!1,Y=!1,z=!1;continue}if(V*=16,n>=48&&n<=57)V+=n-48;else if(n>=65&&n<=70)V+=n-65+10;else{if(!(n>=97&&n<=102)){se("(escaped character, parsing hex of \\u)",n),t=-1,L=!1,z=!1;continue}V+=n-97+10}continue}if(G||Y){if(0===K&&123===n){L=!0;continue}if(K<2||Y&&K<4){if(V*=16,n>=48&&n<=57)V+=n-48;else if(n>=65&&n<=70)V+=n-65+10;else{if(!(n>=97&&n<=102)){se(Y?"(escaped character, parsing hex of \\u)":"(escaped character, parsing hex of \\x)",n),t=-1,G=!1,z=!1;continue}V+=n-97+10}K++,Y?4==K&&(s.string+=String.fromCodePoint(V),Y=!1,z=!1):2==K&&(s.string+=String.fromCodePoint(V),G=!1,z=!1);continue}}switch(n){case 13:W=!0,i.col=1;continue;case 8232:case 8233:i.col=1;case 10:W?W=!1:i.col=1,i.line++;break;case 116:s.string+="\t";break;case 98:s.string+="\b";break;case 110:s.string+="\n";break;case 114:s.string+="\r";break;case 102:s.string+="\f";break;case 118:s.string+="\v";break;case 48:s.string+="\0";break;case 120:G=!0,K=0,V=0;continue;case 117:Y=!0,K=0,V=0;continue;default:s.string+=u}z=!1}else 92===n?z?(s.string+="\\",z=!1):(z=!0,V=0,K=0):(W&&(W=!1,i.line++,i.col=2),s.string+=u)}return t}function fe(){let e;for(;(e=d)<ne.length;){u=ne.charAt(e);let t=ne.codePointAt(d++);if(t>=256){i.col-=d-e,d=e;break}if(95!=t)if(i.col++,t>=48&&t<=57)F&&(B=!0),s.string+=u;else if(45==t||43==t)0==s.string.length||F&&!$&&!B?(45!=t||F||(_=!_),s.string+=u,$=!0):(_&&(s.string="-"+s.string,_=!1),s.string+=u,Z=!0);else{if(78==t){if(0==k)return H=!1,void(k=20);se("fault while parsing number;",t);break}if(73==t){if(0==k)return H=!1,void(k=22);se("fault while parsing number;",t);break}if(58==t&&Z)_&&(s.string="-"+s.string,_=!1),s.string+=u,Z=!0;else if(84==t&&Z)_&&(s.string="-"+s.string,_=!1),s.string+=u,Z=!0;else if(90==t&&Z)_&&(s.string="-"+s.string,_=!1),s.string+=u,Z=!0;else if(46==t){if(J||X||F){w=!1,se("fault while parsing number;",t);break}s.string+=u,J=!0}else{if(110==t){ee=!0;break}if(X&&(t>=95&&t<=102||t>=65&&t<=70))s.string+=u;else if(120==t||98==t||111==t||88==t||66==t||79==t){if(X||"0"!=s.string){w=!1,se("fault while parsing number;",t);break}X=!0,s.string+=u}else{if(101!=t&&69!=t){if(32==t||13==t||10==t||9==t||47==t||35==t||44==t||125==t||93==t||123==t||91==t||34==t||39==t||96==t||58==t){i.col-=d-e,d=e;break}n&&(w=!1,se("fault while parsing number;",t));break}if(F){w=!1,se("fault while parsing number;",t);break}s.string+=u,F=!0}}}}n||d!=ne.length?(H=!1,s.value_type=5,0==P&&(Q=!0)):H=!0}function pe(){let e,t=2,n=null,r={};if(k>0&&k<l&&ce(123),e=he(),0==P)if(k==l||k==c&&(e||s.string.length)){if(e&&e.protoDef&&e.protoDef.protoCon&&(r=new e.protoDef.protoCon),!e||!e.protoDef&&s.string){if(n=E.find((e=>e.name===s.string)),n)x?(n.fields.length=0,t=4):(r=new n.protoCon,t=5);else{function a(){}E.push(n={name:s.string,protoCon:e&&e.protoDef&&e.protoDef.protoCon||a.constructor,fields:[]}),t=4}x=!1}D=n,k=0}else k=l;else if(k==l||1===P||3===P||5==P)if(0!=k||4==s.value_type){if(e&&e.protoDef)r=new e.protoDef.protoCon;else if(n=E.find((e=>e.name===s.string)),n)t=5,r={};else{function o(){}m.set(s.string,{protoCon:o.prototype.constructor,cb:null}),r=new o}k=0}else k=0;else if(2==P&&0==k)return se("fault while parsing; getting field name unexpected ",A),w=!1,!1;let i=g();return s.value_type=6,0===P?p=r:1==P?s.name=p.length:3!=P&&5!=P||(!s.name&&D&&(s.name=D.fields[I++]),p[s.name]=r),i.context=P,i.elements=p,i.name=s.name,i.current_proto=T,i.current_class=D,i.current_class_field=I,i.valueType=s.value_type,i.arrayType=M,i.className=s.className,s.className=null,s.name=null,T=e,D=n,I=0,p=r,O||(O=p),j.push(i),ie(),P=t,!0}function ge(){if(k>0&&k<l&&ce(91),k==c&&s.string.length){let e=r.findIndex((e=>e===s.string));k=0,e>=0?(M=e,s.className=s.string,s.string=null):"ref"===s.string?(s.className=null,M=-2):m.get(s.string)||v.get(s.string)?s.className=s.string:se(`Unknown type '${s.string}' specified for array`,A)}else if(2==P||k==l||k==o)return se("Fault while parsing; while getting field name unexpected",A),w=!1,!1;{let e=g();s.value_type=13;let t=[];if(0==P)p=t;else if(1==P)-1==M&&p.push(t),s.name=p.length;else if(3==P)if(s.name||(console.log("This says it's resolved......."),M=-3),T&&T.protoDef)if(T.protoDef.cb){const e=T.protoDef.cb.call(p,s.name,t);void 0!==e&&(t=p[s.name]=e)}else p[s.name]=t;else p[s.name]=t;e.context=P,e.elements=p,e.name=s.name,e.current_proto=T,e.current_class=D,e.current_class_field=I,e.valueType=s.value_type,e.arrayType=-1==M?-3:M,e.className=s.className,M=-1,s.className=null,s.name=null,T=null,D=null,I=0,p=t,O||(O=t),j.push(e),ie(),P=1}return!0}function he(){const e={protoDef:null,cls:null};return((e.protoDef=m.get(s.string))||(e.protoDef=v.get(s.string)))&&(s.className||(s.className=s.string,s.string=null)),s.string&&(e.cls=E.find((e=>e.name===s.string)),!e.protoDef&&e.cls),e.protoDef||e.cls?e:null}if(!w)return-1;for(e&&e.length?(te=function(){let e=b.pop();return e?e.n=0:e={buf:null,n:0},e}(),te.buf=e,U.push(te)):(H&&(H=!1,s.value_type=5,0==P&&(Q=!0),re=1),0!==P&&se("Unclosed object at end of stream.",A));w&&(te=U.shift());){if(d=te.n,ne=te.buf,R){let e=ue(q);e<0?w=!1:e>0&&(R=!1,w&&(s.value_type=4))}for(H&&fe();!Q&&w&&d<ne.length;)if(u=ne.charAt(d),A=ne.codePointAt(d++),A>=65536&&(u+=ne.charAt(d),d++),i.col++,C)if(1==C)if(42==A)C=3;else{if(47!=A)return se("fault while parsing;",A);C=2}else 2==C?10!=A&&13!=A||(C=0):3==C?42==A&&(C=4):C=47==A?0:3;else{switch(A){case 35:C=2;break;case 47:C=1;break;case 123:pe();break;case 91:ge();break;case 58:if(5==P)k=0,s.name=s.string,s.string="",s.value_type=0;else if(2==P||4==P)if(4==P){if(!Object.keys(p).length){console.log("This is a full object, not a class def...",s.className);const e=()=>{};m.set(j.last.node.current_class.name,{protoCon:e.prototype.constructor,cb:null}),p=new e,P=3,s.name=s.string,k=0,s.string="",s.value_type=0,console.log("don't do default;s do a revive...")}}else 0!=k&&k!=c&&k!=l&&k!=o&&ce(32),k=0,s.name=s.string,s.string="",P=2===P?3:6,s.value_type=0;else{if(0==P){console.log("Override colon found, allow class redefinition",P),x=!0;break}se(1==P?"(in array, got colon out of string):parsing fault;":3==P?"String unexpected":"(outside any object, got colon out of string):parsing fault;",A),w=!1}break;case 125:if(k==c&&(k=0),4==P)if(D){s.string&&D.fields.push(s.string),ie();let e=j.pop();P=0,k=0,s.name=e.name,p=e.elements,D=e.current_class,I=e.current_class_field,M=e.arrayType,s.value_type=e.valueType,s.className=e.className,O=null,h(e)}else se("State error; gathering class fields, and lost the class",A);else if(2==P||5==P){0!=s.value_type&&(D&&(s.name=D.fields[I++]),oe()),s.value_type=6,T&&T.protoDef&&(console.log("SOMETHING SHOULD AHVE BEEN REPLACED HERE??",T),console.log("The other version only revives on init"),p=new T.protoDef.cb(p,void 0,void 0)),s.contains=p,s.string="";let e=j.pop();P=e.context,s.name=e.name,p=e.elements,D=e.current_class,T=e.current_proto,I=e.current_class_field,M=e.arrayType,s.value_type=e.valueType,s.className=e.className,h(e),0==P&&(Q=!0)}else if(3==P){0===s.value_type&&se("Fault while parsing; unexpected",A),oe(),s.value_type=6,s.contains=p,k=0;let e=j.pop();P=e.context,s.name=e.name,p=e.elements,T=e.current_proto,D=e.current_class,I=e.current_class_field,M=e.arrayType,s.value_type=e.valueType,s.className=e.className,h(e),0==P&&(Q=!0)}else se("Fault while parsing; unexpected",A),w=!1;_=!1;break;case 93:if(k>=o&&(k=0),1==P){0!=s.value_type&&le(),s.contains=p;{let e=j.pop();s.name=e.name,s.className=e.className,P=e.context,p=e.elements,T=e.current_proto,D=e.current_class,I=e.current_class_field,M=e.arrayType,s.value_type=e.valueType,h(e)}s.value_type=13,0==P&&(Q=!0)}else se(`bad context ${P}; fault while parsing`,A),w=!1;_=!1;break;case 44:k<o&&0!=k&&ce(A),k!=c&&k!=l||(k=0),4==P?D?(D.fields.push(s.string),s.string="",k=l):se("State error; gathering class fields, and lost the class",A):2==P?D?(s.name=D.fields[I++],0!=s.value_type&&(oe(),ie())):(s.string||s.value_type)&&se("State error; comma in field name and/or lost the class",A):5==P?(D?(-3==M||s.name||(s.name=D.fields[I++]),0!=s.value_type&&(-3!=M&&oe(),ie())):0!=s.value_type&&(oe(),ie()),s.name=null):1==P?(0==s.value_type&&(s.value_type=12),le(),ie(),k=0):3==P&&0!=s.value_type?(P=2,0!=s.value_type&&(oe(),ie()),k=0):(w=!1,se("bad context; excessive commas while parsing;",A)),_=!1;break;default:switch(A){default:if(0!=P&&(3!=P||k!=l)&&2!=P&&k!=l&&4!=P){if(0==k&&(A>=48&&A<=57||43==A||46==A||45==A))X=!1,F=!1,Z=!1,ee=!1,$=!1,B=!1,J=!1,s.string=u,te.n=d,fe();else if(0==s.value_type)0!=k?ce(A):(k=c,s.string+=u,s.value_type=4);else if(2==P)se("Multiple values found in field name",A);else if(3==P)if(4!=s.value_type&&(6!=s.value_type&&13!=s.value_type||se("String unexpected",A),ce(A)),k==o){he()?s.string=u:se("String unexpected",A)}else k==c?s.string+=u:se("String unexpected",A);else if(1==P){if(k==o){s.className||(s.className=s.string,s.string=""),s.string+=u;break}k==c&&(s.string+=u)}break}switch(A){case 96:case 34:case 39:if(0==k||k==l){s.string.length&&(console.log("IN ARRAY AND FIXING?"),s.className=s.string,s.string=""),ue(A)?s.value_type=4:(q=A,R=!0)}else se("fault while parsing; quote not at start of field name",A);break;case 10:i.line++,i.col=1;case 13:case 32:case 8232:case 8233:case 9:case 65279:if(0===P&&k===c){k=0,0===P&&(Q=!0);break}if(0===k||k===o){0==P&&s.value_type&&(Q=!0);break}if(k===l){if(0===P){k=0,Q=!0;break}s.string.length&&console.log("STEP TO NEXT TOKEN."),k=o}else w=!1,se("fault while parsing; whitepsace unexpected",A);break;default:if(0==k&&(A>=48&&A<=57||43==A||46==A||45==A)){X=!1,F=!1,Z=!1,ee=!1,$=!1,B=!1,J=!1,s.string=u,te.n=d,fe();break}if(k===o&&(w=!1,se("fault while parsing; character unexpected",A)),0===k){k=l,s.value_type=4,s.string+=u;break}if(0==s.value_type)0!==k&&k!==c&&ce(A);else{if(k===c||k===l){s.string+=u;break}if(2==P){if(k==l){s.string+=u;break}se("Multiple values found in field name",A)}3==P&&se("String unexpected",A)}}break;case 96:case 34:case 39:s.string&&(s.className=s.string),s.string="",ue(A)?(s.value_type=4,k=c):(q=A,R=!0);break;case 10:i.line++,i.col=1;case 32:case 9:case 13:case 8232:case 8233:case 65279:if(k==c){if(0==P){k=0,Q=!0;break}if(3==P){k=32;break}if(2==P){k=o;break}if(1==P){k=o;break}}if(0==k||k==o)break;k==l?s.string.length&&(k=o):k<c&&ce(A);break;case 116:0==k?k=1:27==k?k=28:ce(A);break;case 114:1==k?k=2:ce(A);break;case 117:2==k?k=3:9==k?k=10:0==k?k=12:ce(A);break;case 101:3==k?(s.value_type=2,k=c):8==k?(s.value_type=3,k=c):14==k?k=15:18==k?k=19:ce(A);break;case 110:0==k?k=9:12==k?k=13:17==k?k=18:22==k?k=23:25==k?k=26:ce(A);break;case 100:13==k?k=14:19==k?(s.value_type=-1,k=c):ce(A);break;case 105:16==k?k=17:24==k?k=25:26==k?k=27:ce(A);break;case 108:10==k?k=11:11==k?(s.value_type=1,k=c):6==k?k=7:ce(A);break;case 102:0==k?k=5:15==k?k=16:23==k?k=24:ce(A);break;case 97:5==k?k=6:20==k?k=21:ce(A);break;case 115:7==k?k=8:ce(A);break;case 73:0==k?k=22:ce(A);break;case 78:0==k?k=20:21==k?(s.value_type=_?7:8,_=!1,k=c):ce(A);break;case 121:28==k?(s.value_type=_?9:10,_=!1,k=c):ce(A);break;case 45:0==k?_=!_:ce(A);break;case 43:0!==k&&ce(A)}}if(Q){k==c&&(k=0);break}}if(d==ne.length?(y(te),R||H||2==P?re=0:0!=P||0==s.value_type&&!N||(Q=!0,re=1)):(te.n=d,U.unshift(te),re=2),Q){O=null;break}}return w?(Q&&0!=s.value_type&&(k=0,N=ae(),_=!1,s.string="",s.value_type=0),Q=!1,re):-1}}};const w=[Object.freeze(n.begin())];let x=0;function _(){return this&&this.valueOf()}n.parse=function(e,t){let r,s=x++;w.length<=s&&w.push(Object.freeze(n.begin())),r=w[s],"string"!=typeof e&&(e=String(e)),r.reset();const i=r._write(e,!0);if(i>0){let e=r.value();if(void 0===e&&i>1)throw new Error("Pending value could not complete");return e="function"==typeof t?function e(n,r){let s,i,a=n[r];if(a&&"object"==typeof a)for(s in a)Object.prototype.hasOwnProperty.call(a,s)&&(i=e(a,s),void 0!==i?a[s]=i:delete a[s]);return t.call(n,r,a)}({"":e},""):e,x--,e}r.finalError()},n.defineClass=function(e,t){let n,r=Object.keys(t);for(let e=1;e<r.length;e++){let t,n;(t=r[e-1])>(n=r[e])&&(r[e-1]=n,r[e]=t,e?e-=2:e--)}k.push(n={name:e,tag:r.toString(),proto:Object.getPrototypeOf(t),fields:Object.keys(t)});for(let e=1;e<n.fields.length;e++)if(n.fields[e]<n.fields[e-1]){let t=n.fields[e-1];n.fields[e-1]=n.fields[e],n.fields[e]=t,e>1&&(e-=2)}n.proto===Object.getPrototypeOf({})&&(n.proto=null)},n.toJSOX=n.registerToJSOX=function(e,t,n){if(t.prototype&&t.prototype===Object.prototype){let r=Object.keys(t).toString();if(m.get(r))throw new Error("Existing toJSOX has been registered for object type");m.set(r,{external:!0,name:e,cb:n})}else{if(d.get(t.prototype))throw new Error("Existing toJSOX has been registered for prototype");d.set(t.prototype,{external:!0,name:e||n.constructor.name,cb:n})}},n.fromJSOX=function(e,t,n){if(t||(t=function(){}.prototype),v.get(e))throw new Error("Existing fromJSOX has been registered for prototype");if(t&&!("constructor"in t))throw new Error("Please pass a prototype like thing...");v.set(e,{protoCon:t.prototype.constructor,cb:n})},n.registerFromJSOX=function(e,t){throw new Error("deprecated; please adjust code to use fromJSOX:"+e+t.toString())},n.addType=function(e,t,r,s){n.toJSOX(e,t,r),n.fromJSOX(e,t,s)},n.registerToFrom=function(e,t){throw new Error("registerToFrom deprecated; please use addType:"+e+t.toString())},n.stringifier=function(){let t=[],r='"',a=new WeakMap;const l=[];let o=[];const c=new WeakMap,p=new Map;let g=null;const h=[];let b=!1;function y(e){return"string"==typeof e&&""===e?'""':"number"!=typeof e||isNaN(e)?e.includes("\ufeff")||e in u||/[0-9\-]/.test(e[0])||/[\n\r\t #\[\]{}()<>\~!+*/.:,\-"'`]/.test(e)?r+n.escape(e)+r:e:["'",e.toString(),"'"].join("")}d.get(Object.prototype)||(d.set(Object.prototype,{external:!1,name:Object.prototype.constructor.name,cb:null}),d.set(Date.prototype,{external:!1,name:"Date",cb:function(){if(-621672192e5===this.getTime())return"0000-01-01T00:00:00.000Z";let e=-this.getTimezoneOffset(),t=e>=0?"+":"-",n=function(e){let t=Math.floor(Math.abs(e));return(t<10?"0":"")+t};return[this.getFullYear(),"-",n(this.getMonth()+1),"-",n(this.getDate()),"T",n(this.getHours()),":",n(this.getMinutes()),":",n(this.getSeconds()),"."+function(e){let t=Math.floor(Math.abs(e));return(t<100?"0":"")+(t<10?"0":"")+t}(this.getMilliseconds())+t,n(e/60),":",n(e%60)].join("")}}),d.set(f.prototype,{external:!1,name:"DateNS",cb:function(){let e=-this.getTimezoneOffset(),t=e>=0?"+":"-",n=function(e){let t=Math.floor(Math.abs(e));return(t<10?"0":"")+t};return[this.getFullYear(),"-",n(this.getMonth()+1),"-",n(this.getDate()),"T",n(this.getHours()),":",n(this.getMinutes()),":",n(this.getSeconds()),"."+function(e){let t=Math.floor(Math.abs(e));return(t<100?"0":"")+(t<10?"0":"")+t}(this.getMilliseconds())+function(e){let t=Math.floor(Math.abs(e));return(t<1e5?"0":"")+(t<1e4?"0":"")+(t<1e3?"0":"")+(t<100?"0":"")+(t<10?"0":"")+t}(this.ns)+t,n(e/60),":",n(e%60)].join("")}}),d.set(Boolean.prototype,{external:!1,name:"Boolean",cb:_}),d.set(Number.prototype,{external:!1,name:"Number",cb:function(){return isNaN(this)?"NaN":isFinite(this)?String(this):this<0?"-Infinity":"Infinity"}}),d.set(String.prototype,{external:!1,name:"String",cb:function(){return'"'+n.escape(_.apply(this))+'"'}}),"function"==typeof BigInt&&d.set(BigInt.prototype,{external:!1,name:"BigInt",cb:function(){return this+"n"}}),d.set(ArrayBuffer.prototype,{external:!0,name:"ab",cb:function(){return"["+y(j(this))+"]"}}),d.set(Uint8Array.prototype,{external:!0,name:"u8",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Uint8ClampedArray.prototype,{external:!0,name:"uc8",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Int8Array.prototype,{external:!0,name:"s8",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Uint16Array.prototype,{external:!0,name:"u16",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Int16Array.prototype,{external:!0,name:"s16",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Uint32Array.prototype,{external:!0,name:"u32",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Int32Array.prototype,{external:!0,name:"s32",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Float32Array.prototype,{external:!0,name:"f32",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Float64Array.prototype,{external:!0,name:"f64",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(Float64Array.prototype,{external:!0,name:"f64",cb:function(){return"["+y(j(this.buffer))+"]"}}),d.set(RegExp.prototype,i={external:!0,name:"regex",cb:function(e,t){return"'"+escape(this.source)+"'"}}),v.set("regex",{protoCon:RegExp,cb:function(e,t){return new RegExp(this)}}),d.set(Map.prototype,i={external:!0,name:"map",cb:null}),v.set("map",{protoCon:Map,cb:function(e,t){if(!e)return this;this.set(e,t)}}),d.set(Array.prototype,s={external:!1,name:Array.prototype.constructor.name,cb:null}));const w={defineClass(e,n){let r,s=Object.keys(n);for(let e=1;e<s.length;e++){let t,n;(t=s[e-1])>(n=s[e])&&(s[e-1]=n,s[e]=t,e?e-=2:e--)}t.push(r={name:e,tag:s.toString(),proto:Object.getPrototypeOf(n),fields:Object.keys(n)});for(let e=1;e<r.fields.length;e++)if(r.fields[e]<r.fields[e-1]){let t=r.fields[e-1];r.fields[e-1]=r.fields[e],r.fields[e]=t,e>1&&(e-=2)}r.proto===Object.getPrototypeOf({})&&(r.proto=null)},setDefaultObjectToJSOX(e){g=e},isEncoding:e=>!!o.find(((t,n)=>t===e&&n<o.length-1)),encodeObject(e){return g?g.apply(e,[this]):e},stringify:(e,n,r)=>function(e,n,r){if(void 0===e)return"undefined";if(null===e)return;let u,f,v,_;const O=typeof r,j=typeof n;if(u="",f="","number"===O)for(_=0;_<r;_+=1)f+=" ";else"string"===O&&(f=r);if(v=n,n&&"function"!==j&&("object"!==j||"number"!=typeof n.length))throw new Error("JSOX.stringify");l.length=0,a=new WeakMap;const S=E("",{"":e});return k.length=0,S;function E(e,n){var r=u;const a=s.cb,_=i.cb;s.cb=j,i.cb=S;const O=A(e,n);return s.cb=a,i.cb=_,O;function j(){let e,t=[],n=l.length;for(let e=0;e<this.length;e+=1)l[n]=e,t[e]=E(e,this)||"null";return l.length=n,o.length=n,e=0===t.length?"[]":u?["[\n",u,t.join(",\n"+u),"\n",r,"]"].join(""):"["+t.join(",")+"]",e}function S(){let e={tmp:null},t="{",n=!0;for(let[r,s]of this){e.tmp=s;let i=l.length;l[i]=r,t+=(n?"":",")+y(r)+":"+E("tmp",e),l.length=i,n=!1}return t+="}",t}function A(e,n){let s,i,a,_,O,j,S,A=l.length,T=!0,D=n[e],I="object"==typeof D;I&&null!==D&&g&&(h.find((e=>e===D))||(h.push(D),o[A]=D,T=!1,D=g.apply(D,[w]),I="object"==typeof D,h.pop(),o.length=A,I="object"==typeof D));const M=null!=D&&Object.getPrototypeOf(D);let P=M&&(c.get(M)||d.get(M)||null),C=!P&&null!=D&&(p.get(Object.keys(D).toString())||m.get(Object.keys(D).toString())||null);"function"==typeof v&&(T=!1,D=v.call(n,e,D));let X=P&&P.cb||C&&C.cb;if(null!=D&&"object"==typeof D&&"function"==typeof X)if(h.find((e=>e===D)))a=x(D);else{if("object"==typeof D&&(a=x(D),a))return a;h.push(D),o[A]=D,D=X.call(D,w),T=!1,h.pop(),P&&P.name&&"string"==typeof D&&"-"!==D[0]&&(D[0]<"0"||D[0]>"9")&&'"'!==D[0]&&"'"!==D[0]&&"`"!==D[0]&&"["!==D[0]&&"{"!==D[0]&&(D=" "+D),o.length=A}else if("object"==typeof D&&(a=x(D),a))return a;switch(typeof D){case"bigint":return D+"n";case"string":{D=T?y(D):D;let n="";return""===e&&(n=t.map((e=>e.name+"{"+e.fields.join(",")+"}")).join(u?"\n":"")+k.map((e=>e.name+"{"+e.fields.join(",")+"}")).join(u?"\n":"")+(u?"\n":"")),P&&P.external?n+P.name+D:C&&C.external?n+C.name+D:n+D}case"number":case"boolean":case"null":return String(D);case"object":if(a)return"ref"+a;if(!D)return"null";if(u+=f,O=null,j=[],v&&"object"==typeof v){for(_=v.length,O=N(D,v),s=0;s<_;s+=1)"string"==typeof v[s]&&(i=v[s],l[A]=i,a=E(i,D),void 0!==a&&(O?j.push(a):j.push(y(i)+(u?": ":":")+a)));l.splice(A,1)}else{O=N(D);let e=[];for(i in D)if((!b||Object.prototype.propertyIsEnumerable.call(D,i))&&Object.prototype.hasOwnProperty.call(D,i)){let t;for(t=0;t<e.length;t++)if(e[t]>i){e.splice(t,0,i);break}t==e.length&&e.push(i)}for(let t=0;t<e.length;t++)i=e[t],Object.prototype.hasOwnProperty.call(D,i)&&(l[A]=i,a=E(i,D),void 0!==a&&(O?j.push(a):j.push(y(i)+(u?": ":":")+a)));l.splice(A,1)}S=""===e?(t.map((e=>e.name+"{"+e.fields.join(",")+"}")).join(u?"\n":"")||k.map((e=>e.name+"{"+e.fields.join(",")+"}")).join(u?"\n":""))+(u?"\n":""):"",P&&P.external&&(S+=y(P.name));let n=null;return O&&(n=y(O.name)),a=S+(0===j.length?"{}":u?(O?n:"")+"{\n"+u+j.join(",\n"+u)+"\n"+r+"}":(O?n:"")+"{"+j.join(",")+"}"),u=r,a}}}}(e,n,r),setQuote(e){r=e},registerToJSOX(e,t,n){return this.toJSOX(e,t,n)},toJSOX(e,t,n){if(t.prototype&&t.prototype!==Object.prototype){if(c.get(t.prototype))throw new Error("Existing toJSOX has been registered for prototype");c.set(t.prototype,{external:!0,name:e||n.constructor.name,cb:n})}else{let r=Object.keys(t).toString();if(p.get(r))throw new Error("Existing toJSOX has been registered for object type");p.set(r,{external:!0,name:e,cb:n})}},get ignoreNonEnumerable(){return b},set ignoreNonEnumerable(e){b=e}};return w;function x(t){if(null===t)return;let n=a.get(t);if(n)return"ref"+n;a.set(t,e.stringify(l))}function N(e,n){let r,s,i=Object.getPrototypeOf(e);if(s=t.find((e=>{if(e.proto&&e.proto===i)return!0})),s)return s;if(t.length||k.length){if(n)n=n.map((e=>"string"==typeof e?e:void 0)),r=n.toString();else{let t=Object.keys(e);for(let e=1;e<t.length;e++){let n,r;(n=t[e-1])>(r=t[e])&&(t[e-1]=r,t[e]=n,e?e-=2:e--)}r=t.toString()}s=t.find((e=>{if(e.tag===r)return!0})),s||(s=k.find((e=>{if(e.tag===r)return!0})))}return s}};const N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$_",O={"~":-1,"=":-1,$:62,_:63,"+":62,"-":62,".":62,"/":63,",":63};for(let e=0;e<N.length;e++)O[N[e]]=e;function j(e){let t,n,r,s,i,a="",l=new Uint8Array(e),o=l.byteLength,c=o%3,u=o-c;for(let e=0;e<u;e+=3)i=l[e]<<16|l[e+1]<<8|l[e+2],t=(16515072&i)>>18,n=(258048&i)>>12,r=(4032&i)>>6,s=63&i,a+=N[t]+N[n]+N[r]+N[s];return 1==c?(i=l[u],t=(252&i)>>2,n=(3&i)<<4,a+=N[t]+N[n]+"=="):2==c&&(i=l[u]<<8|l[u+1],t=(64512&i)>>10,n=(1008&i)>>4,r=(15&i)<<2,a+=N[t]+N[n]+N[r]+"="),a}function S(e){let t;t=e.length%4==1?3*((e.length+3)/4|0)-3:e.length%4==2?3*((e.length+3)/4|0)-2:e.length%4==3?3*((e.length+3)/4|0)-1:-1==O[e[e.length-3]]?3*((e.length+3)/4|0)-3:-1==O[e[e.length-2]]?3*((e.length+3)/4|0)-2:-1==O[e[e.length-1]]?3*((e.length+3)/4|0)-1:3*((e.length+3)/4|0);let n,r=new ArrayBuffer(t),s=new Uint8Array(r),i=e.length+3>>2;for(n=0;n<i;n++){let t=O[e[4*n]],r=4*n+1<e.length?O[e[4*n+1]]:-1,i=r>=0&&4*n+2<e.length?O[e[4*n+2]]:-1,a=i>=0&&4*n+3<e.length?O[e[4*n+3]]:-1;r>=0&&(s[3*n+0]=t<<2|r>>4),i>=0&&(s[3*n+1]=r<<4|i>>2&15),a>=0&&(s[3*n+2]=i<<6|63&a)}return r}Object.freeze(O),n.stringify=function(e,t,r){return n.stringifier().stringify(e,t,r)},[[0,256,[16767487,16739071,130048,3670016,0,16777208,16777215,8388607]]].map((e=>({firstChar:e[0],lastChar:e[1],bits:e[2]})))}();