UNPKG

webr

Version:

The statistical programming language R compiled into WASM for use in a web browser and node.

2 lines 134 kB
"use strict";var so=Object.create;var Na=Object.defineProperty;var io=Object.getOwnPropertyDescriptor;var oo=Object.getOwnPropertyNames;var lo=Object.getPrototypeOf,co=Object.prototype.hasOwnProperty;var Ua=e=>{throw TypeError(e)};var $=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var uo=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of oo(r))!co.call(e,a)&&a!==t&&Na(e,a,{get:()=>r[a],enumerable:!(n=io(r,a))||n.enumerable});return e};var Lt=(e,r,t)=>(t=e!=null?so(lo(e)):{},uo(r||!e||!e.__esModule?Na(t,"default",{value:e,enumerable:!0}):t,e));var Rn=(e,r,t)=>r.has(e)||Ua("Cannot "+t);var A=(e,r,t)=>(Rn(e,r,"read from private field"),t?t.call(e):r.get(e)),C=(e,r,t)=>r.has(e)?Ua("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t),z=(e,r,t,n)=>(Rn(e,r,"write to private field"),n?n.call(e,t):r.set(e,t),t),We=(e,r,t)=>(Rn(e,r,"access private method"),t);var Ca=(e,r,t,n)=>({set _(a){z(e,r,a,t)},get _(){return A(e,r,n)}});var $t=$(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});se.getUint64=se.getInt64=se.setInt64=se.setUint64=se.UINT32_MAX=void 0;se.UINT32_MAX=4294967295;function mo(e,r,t){let n=t/4294967296,a=t;e.setUint32(r,n),e.setUint32(r+4,a)}se.setUint64=mo;function yo(e,r,t){let n=Math.floor(t/4294967296),a=t;e.setUint32(r,n),e.setUint32(r+4,a)}se.setInt64=yo;function _o(e,r){let t=e.getInt32(r),n=e.getUint32(r+4);return t*4294967296+n}se.getInt64=_o;function bo(e,r){let t=e.getUint32(r),n=e.getUint32(r+4);return t*4294967296+n}se.getUint64=bo});var Br=$(X=>{"use strict";var kn,An,Dn;Object.defineProperty(X,"__esModule",{value:!0});X.utf8DecodeTD=X.TEXT_DECODER_THRESHOLD=X.utf8DecodeJs=X.utf8EncodeTE=X.TEXT_ENCODER_THRESHOLD=X.utf8EncodeJs=X.utf8Count=void 0;var Va=$t(),Lr=(typeof process>"u"||((kn=process==null?void 0:process.env)===null||kn===void 0?void 0:kn.TEXT_ENCODING)!=="never")&&typeof TextEncoder<"u"&&typeof TextDecoder<"u";function wo(e){let r=e.length,t=0,n=0;for(;n<r;){let a=e.charCodeAt(n++);if((a&4294967168)===0){t++;continue}else if((a&4294965248)===0)t+=2;else{if(a>=55296&&a<=56319&&n<r){let s=e.charCodeAt(n);(s&64512)===56320&&(++n,a=((a&1023)<<10)+(s&1023)+65536)}(a&4294901760)===0?t+=3:t+=4}}return t}X.utf8Count=wo;function Ro(e,r,t){let n=e.length,a=t,s=0;for(;s<n;){let i=e.charCodeAt(s++);if((i&4294967168)===0){r[a++]=i;continue}else if((i&4294965248)===0)r[a++]=i>>6&31|192;else{if(i>=55296&&i<=56319&&s<n){let o=e.charCodeAt(s);(o&64512)===56320&&(++s,i=((i&1023)<<10)+(o&1023)+65536)}(i&4294901760)===0?(r[a++]=i>>12&15|224,r[a++]=i>>6&63|128):(r[a++]=i>>18&7|240,r[a++]=i>>12&63|128,r[a++]=i>>6&63|128)}r[a++]=i&63|128}}X.utf8EncodeJs=Ro;var Vt=Lr?new TextEncoder:void 0;X.TEXT_ENCODER_THRESHOLD=Lr?typeof process<"u"&&((An=process==null?void 0:process.env)===null||An===void 0?void 0:An.TEXT_ENCODING)!=="force"?200:0:Va.UINT32_MAX;function xo(e,r,t){r.set(Vt.encode(e),t)}function Eo(e,r,t){Vt.encodeInto(e,r.subarray(t))}X.utf8EncodeTE=Vt!=null&&Vt.encodeInto?Eo:xo;var vo=4096;function So(e,r,t){let n=r,a=n+t,s=[],i="";for(;n<a;){let o=e[n++];if((o&128)===0)s.push(o);else if((o&224)===192){let d=e[n++]&63;s.push((o&31)<<6|d)}else if((o&240)===224){let d=e[n++]&63,l=e[n++]&63;s.push((o&31)<<12|d<<6|l)}else if((o&248)===240){let d=e[n++]&63,l=e[n++]&63,u=e[n++]&63,b=(o&7)<<18|d<<12|l<<6|u;b>65535&&(b-=65536,s.push(b>>>10&1023|55296),b=56320|b&1023),s.push(b)}else s.push(o);s.length>=vo&&(i+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(i+=String.fromCharCode(...s)),i}X.utf8DecodeJs=So;var To=Lr?new TextDecoder:null;X.TEXT_DECODER_THRESHOLD=Lr?typeof process<"u"&&((Dn=process==null?void 0:process.env)===null||Dn===void 0?void 0:Dn.TEXT_DECODER)!=="force"?200:0:Va.UINT32_MAX;function ko(e,r,t){let n=e.subarray(r,r+t);return To.decode(n)}X.utf8DecodeTD=ko});var On=$(zr=>{"use strict";Object.defineProperty(zr,"__esModule",{value:!0});zr.ExtData=void 0;var Pn=class{constructor(r,t){this.type=r,this.data=t}};zr.ExtData=Pn});var Hr=$(jr=>{"use strict";Object.defineProperty(jr,"__esModule",{value:!0});jr.DecodeError=void 0;var Mn=class e extends Error{constructor(r){super(r);let t=Object.create(e.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:e.name})}};jr.DecodeError=Mn});var In=$(Z=>{"use strict";Object.defineProperty(Z,"__esModule",{value:!0});Z.timestampExtension=Z.decodeTimestampExtension=Z.decodeTimestampToTimeSpec=Z.encodeTimestampExtension=Z.encodeDateToTimeSpec=Z.encodeTimeSpecToTimestamp=Z.EXT_TIMESTAMP=void 0;var Ao=Hr(),Za=$t();Z.EXT_TIMESTAMP=-1;var Do=4294967296-1,Po=17179869184-1;function Ja({sec:e,nsec:r}){if(e>=0&&r>=0&&e<=Po)if(r===0&&e<=Do){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let t=e/4294967296,n=e&4294967295,a=new Uint8Array(8),s=new DataView(a.buffer);return s.setUint32(0,r<<2|t&3),s.setUint32(4,n),a}else{let t=new Uint8Array(12),n=new DataView(t.buffer);return n.setUint32(0,r),(0,Za.setInt64)(n,4,e),t}}Z.encodeTimeSpecToTimestamp=Ja;function Xa(e){let r=e.getTime(),t=Math.floor(r/1e3),n=(r-t*1e3)*1e6,a=Math.floor(n/1e9);return{sec:t+a,nsec:n-a*1e9}}Z.encodeDateToTimeSpec=Xa;function Ga(e){if(e instanceof Date){let r=Xa(e);return Ja(r)}else return null}Z.encodeTimestampExtension=Ga;function Ka(e){let r=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:r.getUint32(0),nsec:0};case 8:{let t=r.getUint32(0),n=r.getUint32(4),a=(t&3)*4294967296+n,s=t>>>2;return{sec:a,nsec:s}}case 12:{let t=(0,Za.getInt64)(r,4),n=r.getUint32(0);return{sec:t,nsec:n}}default:throw new Ao.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}Z.decodeTimestampToTimeSpec=Ka;function Ya(e){let r=Ka(e);return new Date(r.sec*1e3+r.nsec/1e6)}Z.decodeTimestampExtension=Ya;Z.timestampExtension={type:Z.EXT_TIMESTAMP,encode:Ga,decode:Ya}});var Vr=$($r=>{"use strict";Object.defineProperty($r,"__esModule",{value:!0});$r.ExtensionCodec=void 0;var qr=On(),Oo=In(),Zt=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(Oo.timestampExtension)}register({type:r,encode:t,decode:n}){if(r>=0)this.encoders[r]=t,this.decoders[r]=n;else{let a=1+r;this.builtInEncoders[a]=t,this.builtInDecoders[a]=n}}tryToEncode(r,t){for(let n=0;n<this.builtInEncoders.length;n++){let a=this.builtInEncoders[n];if(a!=null){let s=a(r,t);if(s!=null){let i=-1-n;return new qr.ExtData(i,s)}}}for(let n=0;n<this.encoders.length;n++){let a=this.encoders[n];if(a!=null){let s=a(r,t);if(s!=null){let i=n;return new qr.ExtData(i,s)}}}return r instanceof qr.ExtData?r:null}decode(r,t,n){let a=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return a?a(r,t,n):new qr.ExtData(t,r)}};$r.ExtensionCodec=Zt;Zt.defaultCodec=new Zt});var Nn=$(yt=>{"use strict";Object.defineProperty(yt,"__esModule",{value:!0});yt.createDataView=yt.ensureUint8Array=void 0;function Qa(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e instanceof ArrayBuffer?new Uint8Array(e):Uint8Array.from(e)}yt.ensureUint8Array=Qa;function Mo(e){if(e instanceof ArrayBuffer)return new DataView(e);let r=Qa(e);return new DataView(r.buffer,r.byteOffset,r.byteLength)}yt.createDataView=Mo});var Cn=$(fe=>{"use strict";Object.defineProperty(fe,"__esModule",{value:!0});fe.Encoder=fe.DEFAULT_INITIAL_BUFFER_SIZE=fe.DEFAULT_MAX_DEPTH=void 0;var Jt=Br(),Io=Vr(),es=$t(),No=Nn();fe.DEFAULT_MAX_DEPTH=100;fe.DEFAULT_INITIAL_BUFFER_SIZE=2048;var Un=class{constructor(r=Io.ExtensionCodec.defaultCodec,t=void 0,n=fe.DEFAULT_MAX_DEPTH,a=fe.DEFAULT_INITIAL_BUFFER_SIZE,s=!1,i=!1,o=!1,d=!1){this.extensionCodec=r,this.context=t,this.maxDepth=n,this.initialBufferSize=a,this.sortKeys=s,this.forceFloat32=i,this.ignoreUndefined=o,this.forceIntegerToFloat=d,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}reinitializeState(){this.pos=0}encodeSharedRef(r){return this.reinitializeState(),this.doEncode(r,1),this.bytes.subarray(0,this.pos)}encode(r){return this.reinitializeState(),this.doEncode(r,1),this.bytes.slice(0,this.pos)}doEncode(r,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);r==null?this.encodeNil():typeof r=="boolean"?this.encodeBoolean(r):typeof r=="number"?this.encodeNumber(r):typeof r=="string"?this.encodeString(r):this.encodeObject(r,t)}ensureBufferSizeToWrite(r){let t=this.pos+r;this.view.byteLength<t&&this.resizeBuffer(t*2)}resizeBuffer(r){let t=new ArrayBuffer(r),n=new Uint8Array(t),a=new DataView(t);n.set(this.bytes),this.view=a,this.bytes=n}encodeNil(){this.writeU8(192)}encodeBoolean(r){r===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(r){Number.isSafeInteger(r)&&!this.forceIntegerToFloat?r>=0?r<128?this.writeU8(r):r<256?(this.writeU8(204),this.writeU8(r)):r<65536?(this.writeU8(205),this.writeU16(r)):r<4294967296?(this.writeU8(206),this.writeU32(r)):(this.writeU8(207),this.writeU64(r)):r>=-32?this.writeU8(224|r+32):r>=-128?(this.writeU8(208),this.writeI8(r)):r>=-32768?(this.writeU8(209),this.writeI16(r)):r>=-2147483648?(this.writeU8(210),this.writeI32(r)):(this.writeU8(211),this.writeI64(r)):this.forceFloat32?(this.writeU8(202),this.writeF32(r)):(this.writeU8(203),this.writeF64(r))}writeStringHeader(r){if(r<32)this.writeU8(160+r);else if(r<256)this.writeU8(217),this.writeU8(r);else if(r<65536)this.writeU8(218),this.writeU16(r);else if(r<4294967296)this.writeU8(219),this.writeU32(r);else throw new Error(`Too long string: ${r} bytes in UTF-8`)}encodeString(r){if(r.length>Jt.TEXT_ENCODER_THRESHOLD){let a=(0,Jt.utf8Count)(r);this.ensureBufferSizeToWrite(5+a),this.writeStringHeader(a),(0,Jt.utf8EncodeTE)(r,this.bytes,this.pos),this.pos+=a}else{let a=(0,Jt.utf8Count)(r);this.ensureBufferSizeToWrite(5+a),this.writeStringHeader(a),(0,Jt.utf8EncodeJs)(r,this.bytes,this.pos),this.pos+=a}}encodeObject(r,t){let n=this.extensionCodec.tryToEncode(r,this.context);if(n!=null)this.encodeExtension(n);else if(Array.isArray(r))this.encodeArray(r,t);else if(ArrayBuffer.isView(r))this.encodeBinary(r);else if(typeof r=="object")this.encodeMap(r,t);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(r)}`)}encodeBinary(r){let t=r.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else if(t<4294967296)this.writeU8(198),this.writeU32(t);else throw new Error(`Too large binary: ${t}`);let n=(0,No.ensureUint8Array)(r);this.writeU8a(n)}encodeArray(r,t){let n=r.length;if(n<16)this.writeU8(144+n);else if(n<65536)this.writeU8(220),this.writeU16(n);else if(n<4294967296)this.writeU8(221),this.writeU32(n);else throw new Error(`Too large array: ${n}`);for(let a of r)this.doEncode(a,t+1)}countWithoutUndefined(r,t){let n=0;for(let a of t)r[a]!==void 0&&n++;return n}encodeMap(r,t){let n=Object.keys(r);this.sortKeys&&n.sort();let a=this.ignoreUndefined?this.countWithoutUndefined(r,n):n.length;if(a<16)this.writeU8(128+a);else if(a<65536)this.writeU8(222),this.writeU16(a);else if(a<4294967296)this.writeU8(223),this.writeU32(a);else throw new Error(`Too large map object: ${a}`);for(let s of n){let i=r[s];this.ignoreUndefined&&i===void 0||(this.encodeString(s),this.doEncode(i,t+1))}}encodeExtension(r){let t=r.data.length;if(t===1)this.writeU8(212);else if(t===2)this.writeU8(213);else if(t===4)this.writeU8(214);else if(t===8)this.writeU8(215);else if(t===16)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else if(t<4294967296)this.writeU8(201),this.writeU32(t);else throw new Error(`Too large extension object: ${t}`);this.writeI8(r.type),this.writeU8a(r.data)}writeU8(r){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,r),this.pos++}writeU8a(r){let t=r.length;this.ensureBufferSizeToWrite(t),this.bytes.set(r,this.pos),this.pos+=t}writeI8(r){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,r),this.pos++}writeU16(r){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,r),this.pos+=2}writeI16(r){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,r),this.pos+=2}writeU32(r){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,r),this.pos+=4}writeI32(r){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,r),this.pos+=4}writeF32(r){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,r),this.pos+=4}writeF64(r){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,r),this.pos+=8}writeU64(r){this.ensureBufferSizeToWrite(8),(0,es.setUint64)(this.view,this.pos,r),this.pos+=8}writeI64(r){this.ensureBufferSizeToWrite(8),(0,es.setInt64)(this.view,this.pos,r),this.pos+=8}};fe.Encoder=Un});var ts=$(Zr=>{"use strict";Object.defineProperty(Zr,"__esModule",{value:!0});Zr.encode=void 0;var Uo=Cn(),Co={};function Fo(e,r=Co){return new Uo.Encoder(r.extensionCodec,r.context,r.maxDepth,r.initialBufferSize,r.sortKeys,r.forceFloat32,r.ignoreUndefined,r.forceIntegerToFloat).encodeSharedRef(e)}Zr.encode=Fo});var rs=$(Jr=>{"use strict";Object.defineProperty(Jr,"__esModule",{value:!0});Jr.prettyByte=void 0;function Wo(e){return`${e<0?"-":""}0x${Math.abs(e).toString(16).padStart(2,"0")}`}Jr.prettyByte=Wo});var ns=$(Xr=>{"use strict";Object.defineProperty(Xr,"__esModule",{value:!0});Xr.CachedKeyDecoder=void 0;var Lo=Br(),Bo=16,zo=16,Fn=class{constructor(r=Bo,t=zo){this.maxKeyLength=r,this.maxLengthPerKey=t,this.hit=0,this.miss=0,this.caches=[];for(let n=0;n<this.maxKeyLength;n++)this.caches.push([])}canBeCached(r){return r>0&&r<=this.maxKeyLength}find(r,t,n){let a=this.caches[n-1];e:for(let s of a){let i=s.bytes;for(let o=0;o<n;o++)if(i[o]!==r[t+o])continue e;return s.str}return null}store(r,t){let n=this.caches[r.length-1],a={bytes:r,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=a:n.push(a)}decode(r,t,n){let a=this.find(r,t,n);if(a!=null)return this.hit++,a;this.miss++;let s=(0,Lo.utf8DecodeJs)(r,t,n),i=Uint8Array.prototype.slice.call(r,t,t+n);return this.store(i,s),s}};Xr.CachedKeyDecoder=Fn});var Gr=$(Re=>{"use strict";Object.defineProperty(Re,"__esModule",{value:!0});Re.Decoder=Re.DataViewIndexOutOfBoundsError=void 0;var Wn=rs(),jo=Vr(),Qe=$t(),Ln=Br(),Bn=Nn(),Ho=ns(),we=Hr(),qo=e=>{let r=typeof e;return r==="string"||r==="number"},Xt=-1,jn=new DataView(new ArrayBuffer(0)),$o=new Uint8Array(jn.buffer);Re.DataViewIndexOutOfBoundsError=(()=>{try{jn.getInt8(0)}catch(e){return e.constructor}throw new Error("never reached")})();var as=new Re.DataViewIndexOutOfBoundsError("Insufficient data"),Vo=new Ho.CachedKeyDecoder,zn=class{constructor(r=jo.ExtensionCodec.defaultCodec,t=void 0,n=Qe.UINT32_MAX,a=Qe.UINT32_MAX,s=Qe.UINT32_MAX,i=Qe.UINT32_MAX,o=Qe.UINT32_MAX,d=Vo){this.extensionCodec=r,this.context=t,this.maxStrLength=n,this.maxBinLength=a,this.maxArrayLength=s,this.maxMapLength=i,this.maxExtLength=o,this.keyDecoder=d,this.totalPos=0,this.pos=0,this.view=jn,this.bytes=$o,this.headByte=Xt,this.stack=[]}reinitializeState(){this.totalPos=0,this.headByte=Xt,this.stack.length=0}setBuffer(r){this.bytes=(0,Bn.ensureUint8Array)(r),this.view=(0,Bn.createDataView)(this.bytes),this.pos=0}appendBuffer(r){if(this.headByte===Xt&&!this.hasRemaining(1))this.setBuffer(r);else{let t=this.bytes.subarray(this.pos),n=(0,Bn.ensureUint8Array)(r),a=new Uint8Array(t.length+n.length);a.set(t),a.set(n,t.length),this.setBuffer(a)}}hasRemaining(r){return this.view.byteLength-this.pos>=r}createExtraByteError(r){let{view:t,pos:n}=this;return new RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${r}]`)}decode(r){this.reinitializeState(),this.setBuffer(r);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}*decodeMulti(r){for(this.reinitializeState(),this.setBuffer(r);this.hasRemaining(1);)yield this.doDecodeSync()}async decodeAsync(r){let t=!1,n;for await(let o of r){if(t)throw this.createExtraByteError(this.totalPos);this.appendBuffer(o);try{n=this.doDecodeSync(),t=!0}catch(d){if(!(d instanceof Re.DataViewIndexOutOfBoundsError))throw d}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:a,pos:s,totalPos:i}=this;throw new RangeError(`Insufficient data in parsing ${(0,Wn.prettyByte)(a)} at ${i} (${s} in the current buffer)`)}decodeArrayStream(r){return this.decodeMultiAsync(r,!0)}decodeStream(r){return this.decodeMultiAsync(r,!1)}async*decodeMultiAsync(r,t){let n=t,a=-1;for await(let s of r){if(t&&a===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(s),n&&(a=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--a!==0;);}catch(i){if(!(i instanceof Re.DataViewIndexOutOfBoundsError))throw i}this.totalPos+=this.pos}}doDecodeSync(){e:for(;;){let r=this.readHeadByte(),t;if(r>=224)t=r-256;else if(r<192)if(r<128)t=r;else if(r<144){let a=r-128;if(a!==0){this.pushMapState(a),this.complete();continue e}else t={}}else if(r<160){let a=r-144;if(a!==0){this.pushArrayState(a),this.complete();continue e}else t=[]}else{let a=r-160;t=this.decodeUtf8String(a,0)}else if(r===192)t=null;else if(r===194)t=!1;else if(r===195)t=!0;else if(r===202)t=this.readF32();else if(r===203)t=this.readF64();else if(r===204)t=this.readU8();else if(r===205)t=this.readU16();else if(r===206)t=this.readU32();else if(r===207)t=this.readU64();else if(r===208)t=this.readI8();else if(r===209)t=this.readI16();else if(r===210)t=this.readI32();else if(r===211)t=this.readI64();else if(r===217){let a=this.lookU8();t=this.decodeUtf8String(a,1)}else if(r===218){let a=this.lookU16();t=this.decodeUtf8String(a,2)}else if(r===219){let a=this.lookU32();t=this.decodeUtf8String(a,4)}else if(r===220){let a=this.readU16();if(a!==0){this.pushArrayState(a),this.complete();continue e}else t=[]}else if(r===221){let a=this.readU32();if(a!==0){this.pushArrayState(a),this.complete();continue e}else t=[]}else if(r===222){let a=this.readU16();if(a!==0){this.pushMapState(a),this.complete();continue e}else t={}}else if(r===223){let a=this.readU32();if(a!==0){this.pushMapState(a),this.complete();continue e}else t={}}else if(r===196){let a=this.lookU8();t=this.decodeBinary(a,1)}else if(r===197){let a=this.lookU16();t=this.decodeBinary(a,2)}else if(r===198){let a=this.lookU32();t=this.decodeBinary(a,4)}else if(r===212)t=this.decodeExtension(1,0);else if(r===213)t=this.decodeExtension(2,0);else if(r===214)t=this.decodeExtension(4,0);else if(r===215)t=this.decodeExtension(8,0);else if(r===216)t=this.decodeExtension(16,0);else if(r===199){let a=this.lookU8();t=this.decodeExtension(a,1)}else if(r===200){let a=this.lookU16();t=this.decodeExtension(a,2)}else if(r===201){let a=this.lookU32();t=this.decodeExtension(a,4)}else throw new we.DecodeError(`Unrecognized type byte: ${(0,Wn.prettyByte)(r)}`);this.complete();let n=this.stack;for(;n.length>0;){let a=n[n.length-1];if(a.type===0)if(a.array[a.position]=t,a.position++,a.position===a.size)n.pop(),t=a.array;else continue e;else if(a.type===1){if(!qo(t))throw new we.DecodeError("The type of key must be string or number but "+typeof t);if(t==="__proto__")throw new we.DecodeError("The key __proto__ is not allowed");a.key=t,a.type=2;continue e}else if(a.map[a.key]=t,a.readCount++,a.readCount===a.size)n.pop(),t=a.map;else{a.key=null,a.type=1;continue e}}return t}}readHeadByte(){return this.headByte===Xt&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Xt}readArraySize(){let r=this.readHeadByte();switch(r){case 220:return this.readU16();case 221:return this.readU32();default:{if(r<160)return r-144;throw new we.DecodeError(`Unrecognized array type byte: ${(0,Wn.prettyByte)(r)}`)}}}pushMapState(r){if(r>this.maxMapLength)throw new we.DecodeError(`Max length exceeded: map length (${r}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.push({type:1,size:r,key:null,readCount:0,map:{}})}pushArrayState(r){if(r>this.maxArrayLength)throw new we.DecodeError(`Max length exceeded: array length (${r}) > maxArrayLength (${this.maxArrayLength})`);this.stack.push({type:0,size:r,array:new Array(r),position:0})}decodeUtf8String(r,t){var n;if(r>this.maxStrLength)throw new we.DecodeError(`Max length exceeded: UTF-8 byte length (${r}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+r)throw as;let a=this.pos+t,s;return this.stateIsMapKey()&&(!((n=this.keyDecoder)===null||n===void 0)&&n.canBeCached(r))?s=this.keyDecoder.decode(this.bytes,a,r):r>Ln.TEXT_DECODER_THRESHOLD?s=(0,Ln.utf8DecodeTD)(this.bytes,a,r):s=(0,Ln.utf8DecodeJs)(this.bytes,a,r),this.pos+=t+r,s}stateIsMapKey(){return this.stack.length>0?this.stack[this.stack.length-1].type===1:!1}decodeBinary(r,t){if(r>this.maxBinLength)throw new we.DecodeError(`Max length exceeded: bin length (${r}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(r+t))throw as;let n=this.pos+t,a=this.bytes.subarray(n,n+r);return this.pos+=t+r,a}decodeExtension(r,t){if(r>this.maxExtLength)throw new we.DecodeError(`Max length exceeded: ext length (${r}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),a=this.decodeBinary(r,t+1);return this.extensionCodec.decode(a,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let r=this.view.getUint8(this.pos);return this.pos++,r}readI8(){let r=this.view.getInt8(this.pos);return this.pos++,r}readU16(){let r=this.view.getUint16(this.pos);return this.pos+=2,r}readI16(){let r=this.view.getInt16(this.pos);return this.pos+=2,r}readU32(){let r=this.view.getUint32(this.pos);return this.pos+=4,r}readI32(){let r=this.view.getInt32(this.pos);return this.pos+=4,r}readU64(){let r=(0,Qe.getUint64)(this.view,this.pos);return this.pos+=8,r}readI64(){let r=(0,Qe.getInt64)(this.view,this.pos);return this.pos+=8,r}readF32(){let r=this.view.getFloat32(this.pos);return this.pos+=4,r}readF64(){let r=this.view.getFloat64(this.pos);return this.pos+=8,r}};Re.Decoder=zn});var Hn=$(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});he.decodeMulti=he.decode=he.defaultDecodeOptions=void 0;var ss=Gr();he.defaultDecodeOptions={};function Zo(e,r=he.defaultDecodeOptions){return new ss.Decoder(r.extensionCodec,r.context,r.maxStrLength,r.maxBinLength,r.maxArrayLength,r.maxMapLength,r.maxExtLength).decode(e)}he.decode=Zo;function Jo(e,r=he.defaultDecodeOptions){return new ss.Decoder(r.extensionCodec,r.context,r.maxStrLength,r.maxBinLength,r.maxArrayLength,r.maxMapLength,r.maxExtLength).decodeMulti(e)}he.decodeMulti=Jo});var ls=$(De=>{"use strict";Object.defineProperty(De,"__esModule",{value:!0});De.ensureAsyncIterable=De.asyncIterableFromStream=De.isAsyncIterable=void 0;function is(e){return e[Symbol.asyncIterator]!=null}De.isAsyncIterable=is;function Xo(e){if(e==null)throw new Error("Assertion Failure: value must not be null nor undefined")}async function*os(e){let r=e.getReader();try{for(;;){let{done:t,value:n}=await r.read();if(t)return;Xo(n),yield n}}finally{r.releaseLock()}}De.asyncIterableFromStream=os;function Go(e){return is(e)?e:os(e)}De.ensureAsyncIterable=Go});var us=$(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.decodeStream=pe.decodeMultiStream=pe.decodeArrayStream=pe.decodeAsync=void 0;var qn=Gr(),$n=ls(),Kr=Hn();async function Ko(e,r=Kr.defaultDecodeOptions){let t=(0,$n.ensureAsyncIterable)(e);return new qn.Decoder(r.extensionCodec,r.context,r.maxStrLength,r.maxBinLength,r.maxArrayLength,r.maxMapLength,r.maxExtLength).decodeAsync(t)}pe.decodeAsync=Ko;function Yo(e,r=Kr.defaultDecodeOptions){let t=(0,$n.ensureAsyncIterable)(e);return new qn.Decoder(r.extensionCodec,r.context,r.maxStrLength,r.maxBinLength,r.maxArrayLength,r.maxMapLength,r.maxExtLength).decodeArrayStream(t)}pe.decodeArrayStream=Yo;function cs(e,r=Kr.defaultDecodeOptions){let t=(0,$n.ensureAsyncIterable)(e);return new qn.Decoder(r.extensionCodec,r.context,r.maxStrLength,r.maxBinLength,r.maxArrayLength,r.maxMapLength,r.maxExtLength).decodeStream(t)}pe.decodeMultiStream=cs;function Qo(e,r=Kr.defaultDecodeOptions){return cs(e,r)}pe.decodeStream=Qo});var hs=$(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.decodeTimestampExtension=k.encodeTimestampExtension=k.decodeTimestampToTimeSpec=k.encodeTimeSpecToTimestamp=k.encodeDateToTimeSpec=k.EXT_TIMESTAMP=k.ExtData=k.ExtensionCodec=k.Encoder=k.DataViewIndexOutOfBoundsError=k.DecodeError=k.Decoder=k.decodeStream=k.decodeMultiStream=k.decodeArrayStream=k.decodeAsync=k.decodeMulti=k.decode=k.encode=void 0;var el=ts();Object.defineProperty(k,"encode",{enumerable:!0,get:function(){return el.encode}});var ds=Hn();Object.defineProperty(k,"decode",{enumerable:!0,get:function(){return ds.decode}});Object.defineProperty(k,"decodeMulti",{enumerable:!0,get:function(){return ds.decodeMulti}});var Yr=us();Object.defineProperty(k,"decodeAsync",{enumerable:!0,get:function(){return Yr.decodeAsync}});Object.defineProperty(k,"decodeArrayStream",{enumerable:!0,get:function(){return Yr.decodeArrayStream}});Object.defineProperty(k,"decodeMultiStream",{enumerable:!0,get:function(){return Yr.decodeMultiStream}});Object.defineProperty(k,"decodeStream",{enumerable:!0,get:function(){return Yr.decodeStream}});var fs=Gr();Object.defineProperty(k,"Decoder",{enumerable:!0,get:function(){return fs.Decoder}});Object.defineProperty(k,"DataViewIndexOutOfBoundsError",{enumerable:!0,get:function(){return fs.DataViewIndexOutOfBoundsError}});var tl=Hr();Object.defineProperty(k,"DecodeError",{enumerable:!0,get:function(){return tl.DecodeError}});var rl=Cn();Object.defineProperty(k,"Encoder",{enumerable:!0,get:function(){return rl.Encoder}});var nl=Vr();Object.defineProperty(k,"ExtensionCodec",{enumerable:!0,get:function(){return nl.ExtensionCodec}});var al=On();Object.defineProperty(k,"ExtData",{enumerable:!0,get:function(){return al.ExtData}});var _t=In();Object.defineProperty(k,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return _t.EXT_TIMESTAMP}});Object.defineProperty(k,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return _t.encodeDateToTimeSpec}});Object.defineProperty(k,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return _t.encodeTimeSpecToTimestamp}});Object.defineProperty(k,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return _t.decodeTimestampToTimeSpec}});Object.defineProperty(k,"encodeTimestampExtension",{enumerable:!0,get:function(){return _t.encodeTimestampExtension}});Object.defineProperty(k,"decodeTimestampExtension",{enumerable:!0,get:function(){return _t.decodeTimestampExtension}})});var Ki=$((Kh,Gi)=>{var Nt=require("fs"),Xi=require("url"),Qu=require("child_process").spawn;Gi.exports=Ma;Ma.XMLHttpRequest=Ma;function Ma(e){"use strict";e=e||{};var r=this,t=require("http"),n=require("https"),a,s,i={},o=!1,d={"User-Agent":"node-XMLHttpRequest",Accept:"*/*"},l=Object.assign({},d),u=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","content-transfer-encoding","cookie","cookie2","date","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","via"],b=["TRACE","TRACK","CONNECT"],g=!1,f=!1,y=!1,v={};this.UNSENT=0,this.OPENED=1,this.HEADERS_RECEIVED=2,this.LOADING=3,this.DONE=4,this.readyState=this.UNSENT,this.onreadystatechange=null,this.responseText="",this.responseXML="",this.response=Buffer.alloc(0),this.status=null,this.statusText=null;var R=function(p){return o||p&&u.indexOf(p.toLowerCase())===-1},w=function(p){return p&&b.indexOf(p)===-1};this.open=function(p,h,T,U,_){if(this.abort(),f=!1,y=!1,!w(p))throw new Error("SecurityError: Request method not allowed");i={method:p,url:h.toString(),async:typeof T!="boolean"?!0:T,user:U||null,password:_||null},S(this.OPENED)},this.setDisableHeaderCheck=function(p){o=p},this.setRequestHeader=function(p,h){if(this.readyState!=this.OPENED)throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");if(!R(p))return console.warn('Refused to set unsafe header "'+p+'"'),!1;if(g)throw new Error("INVALID_STATE_ERR: send flag is true");return l[p]=h,!0},this.getResponseHeader=function(p){return typeof p=="string"&&this.readyState>this.OPENED&&s.headers[p.toLowerCase()]&&!f?s.headers[p.toLowerCase()]:null},this.getAllResponseHeaders=function(){if(this.readyState<this.HEADERS_RECEIVED||f)return"";var p="";for(var h in s.headers)h!=="set-cookie"&&h!=="set-cookie2"&&(p+=h+": "+s.headers[h]+`\r `);return p.substr(0,p.length-2)},this.getRequestHeader=function(p){return typeof p=="string"&&l[p]?l[p]:""},this.send=function(p){if(this.readyState!=this.OPENED)throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called");if(g)throw new Error("INVALID_STATE_ERR: send has already been called");var h=!1,T=!1,U=Xi.parse(i.url),_;switch(U.protocol){case"https:":h=!0;case"http:":_=U.hostname;break;case"file:":T=!0;break;case void 0:case"":_="localhost";break;default:throw new Error("Protocol not supported.")}if(T){if(i.method!=="GET")throw new Error("XMLHttpRequest: Only GET method is supported");if(i.async)Nt.readFile(unescape(U.pathname),function(te,Fe){te?r.handleError(te,te.errno||-1):(r.status=200,r.responseText=Fe.toString("utf8"),r.response=Fe,S(r.DONE))});else try{this.response=Nt.readFileSync(unescape(U.pathname)),this.responseText=this.response.toString("utf8"),this.status=200,S(r.DONE)}catch(te){this.handleError(te,te.errno||-1)}return}var I=U.port||(h?443:80),P=U.pathname+(U.search?U.search:"");if(l.Host=_,h&&I===443||I===80||(l.Host+=":"+U.port),i.user){typeof i.password>"u"&&(i.password="");var E=new Buffer(i.user+":"+i.password);l.Authorization="Basic "+E.toString("base64")}i.method==="GET"||i.method==="HEAD"?p=null:p?(l["Content-Length"]=Buffer.isBuffer(p)?p.length:Buffer.byteLength(p),l["Content-Type"]||(l["Content-Type"]="text/plain;charset=UTF-8")):i.method==="POST"&&(l["Content-Length"]=0);var D=e.agent||!1,q={host:_,port:I,path:P,method:i.method,headers:l,agent:D};if(h&&(q.pfx=e.pfx,q.key=e.key,q.passphrase=e.passphrase,q.cert=e.cert,q.ca=e.ca,q.ciphers=e.ciphers,q.rejectUnauthorized=e.rejectUnauthorized!==!1),f=!1,i.async){var Ct=h?n.request:t.request;g=!0,r.dispatchEvent("readystatechange");var Ue=function(te){if(s=te,s.statusCode===302||s.statusCode===303||s.statusCode===307){i.url=s.headers.location;var Fe=Xi.parse(i.url);_=Fe.hostname;var Se={hostname:Fe.hostname,port:Fe.port,path:Fe.path,method:s.statusCode===303?"GET":i.method,headers:l};h&&(Se.pfx=e.pfx,Se.key=e.key,Se.passphrase=e.passphrase,Se.cert=e.cert,Se.ca=e.ca,Se.ciphers=e.ciphers,Se.rejectUnauthorized=e.rejectUnauthorized!==!1),a=Ct(Se,Ue).on("error",Ce),a.end();return}S(r.HEADERS_RECEIVED),r.status=s.statusCode,s.on("data",function(xr){if(xr){var ao=Buffer.from(xr);r.response=Buffer.concat([r.response,ao])}g&&S(r.LOADING)}),s.on("end",function(){g&&(g=!1,S(r.DONE),r.responseText=r.response.toString("utf8"))}),s.on("error",function(xr){r.handleError(xr)})},Ce=function(te){r.handleError(te)};a=Ct(q,Ue).on("error",Ce),e.autoUnref&&a.on("socket",te=>{te.unref()}),p&&a.write(p),a.end(),r.dispatchEvent("loadstart")}else{var Ft=".node-xmlhttprequest-content-"+process.pid,Wt=".node-xmlhttprequest-sync-"+process.pid;Nt.writeFileSync(Wt,"","utf8");for(var to="var http = require('http'), https = require('https'), fs = require('fs');var doRequest = http"+(h?"s":"")+".request;var options = "+JSON.stringify(q)+";var responseText = '';var responseData = Buffer.alloc(0);var req = doRequest(options, function(response) {response.on('data', function(chunk) { var data = Buffer.from(chunk); responseText += data.toString('utf8'); responseData = Buffer.concat([responseData, data]);});response.on('end', function() {fs.writeFileSync('"+Ft+"', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText, data: responseData.toString('base64')}}), 'utf8');fs.unlinkSync('"+Wt+"');});response.on('error', function(error) {fs.writeFileSync('"+Ft+"', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');fs.unlinkSync('"+Wt+"');});}).on('error', function(error) {fs.writeFileSync('"+Ft+"', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');fs.unlinkSync('"+Wt+"');});"+(p?"req.write('"+JSON.stringify(p).slice(1,-1).replace(/'/g,"\\'")+"');":"")+"req.end();",ro=Qu(process.argv[0],["-e",to]),sd;Nt.existsSync(Wt););if(r.responseText=Nt.readFileSync(Ft,"utf8"),ro.stdin.end(),Nt.unlinkSync(Ft),r.responseText.match(/^NODE-XMLHTTPREQUEST-ERROR:/)){var no=JSON.parse(r.responseText.replace(/^NODE-XMLHTTPREQUEST-ERROR:/,""));r.handleError(no,503)}else{r.status=r.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:([0-9]*),.*/,"$1");var wn=JSON.parse(r.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:[0-9]*,(.*)/,"$1"));s={statusCode:r.status,headers:wn.data.headers},r.responseText=wn.data.text,r.response=Buffer.from(wn.data.data,"base64"),S(r.DONE,!0)}}},this.handleError=function(p,h){this.status=h||0,this.statusText=p,this.responseText=p.stack,f=!0,S(this.DONE)},this.abort=function(){a&&(a.abort(),a=null),l=Object.assign({},d),this.responseText="",this.responseXML="",this.response=Buffer.alloc(0),f=y=!0,this.readyState!==this.UNSENT&&(this.readyState!==this.OPENED||g)&&this.readyState!==this.DONE&&(g=!1,S(this.DONE)),this.readyState=this.UNSENT},this.addEventListener=function(p,h){p in v||(v[p]=[]),v[p].push(h)},this.removeEventListener=function(p,h){p in v&&(v[p]=v[p].filter(function(T){return T!==h}))},this.dispatchEvent=function(p){if(typeof r["on"+p]=="function"&&(this.readyState===this.DONE&&i.async?setTimeout(function(){r["on"+p]()},0):r["on"+p]()),p in v)for(let h=0,T=v[p].length;h<T;h++)this.readyState===this.DONE?setTimeout(function(){v[p][h].call(r)},0):v[p][h].call(r)};var S=function(p){if(!(r.readyState===p||r.readyState===r.UNSENT&&y)&&(r.readyState=p,(i.async||r.readyState<r.OPENED||r.readyState===r.DONE)&&r.dispatchEvent("readystatechange"),r.readyState===r.DONE)){let h;y?h="abort":f?h="error":h="load",r.dispatchEvent(h),r.dispatchEvent("loadend")}}}});var Le=class extends Error{constructor(r){super(r),this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}};var Te=class extends Le{};var V=typeof process<"u"&&process.release&&process.release.name==="node",Bt;if(globalThis.document)Bt=e=>new Promise((r,t)=>{let n=document.createElement("script");n.src=e,n.onload=()=>r(),n.onerror=t,document.head.appendChild(n)});else if(globalThis.importScripts)Bt=async e=>{try{globalThis.importScripts(e)}catch(r){if(r instanceof TypeError)await Promise.resolve().then(()=>Lt(require(e)));else throw r}};else if(V)Bt=async e=>{let r=(await Promise.resolve().then(()=>Lt(require("path")))).default;await Promise.resolve().then(()=>Lt(require(r.resolve(e))))};else throw new Le("Cannot determine runtime environment");var le={null:0,symbol:1,pairlist:2,closure:3,environment:4,promise:5,call:6,special:7,builtin:8,string:9,logical:10,integer:13,double:14,complex:15,character:16,dots:17,any:18,list:19,expression:20,bytecode:21,pointer:22,weakref:23,raw:24,s4:25,new:30,free:31,function:99};function zt(e){return!!e&&typeof e=="object"&&Object.keys(le).includes(e.type)}function Be(e){return!!e&&typeof e=="object"&&"re"in e&&"im"in e}var c={};function Fa(e){Object.keys(e).forEach(r=>c._free(e[r]))}function ze(e){return c._Rf_protect(re(e)),e}function O(e,r){return c._Rf_protect(re(e)),++r.n,e}function Wa(e){let r=c._malloc(4);return c._R_ProtectWithIndex(re(e),r),{loc:c.getValue(r,"i32"),ptr:r}}function La(e){c._Rf_unprotect(1),c._free(e.ptr)}function Ba(e,r){return c._R_Reprotect(re(e),r.loc),e}function F(e){c._Rf_unprotect(e)}function xn(e,r,t){c._Rf_defineVar(re(r),re(t),re(e))}function be(e,r){let t={},n={n:0};try{let a=new ne(r);O(a,n),t.code=c.allocateUTF8(e);let s=c._R_ParseEvalString(t.code,a.ptr);return x.wrap(s)}finally{Fa(t),F(n.n)}}var ut=class extends Error{constructor(r,t){super(r),this.name="UnwindProtectException",this.cont=t}};function je(e,r){return c.getWasmTableEntry(c.GOT.ffi_safe_eval.value)(re(e),re(r))}var fo=new WeakMap;function za(e,r){return fo.set(e,r),e}function En(e){return typeof e=="string"&&e.length===jt}var jt=63;function He(){let e=Array.from({length:4},ho).join("-");if(e.length!==jt)throw new Error("comlink internal error: UUID has the wrong length");return e}function ho(){let e=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16),r=15-e.length;return r>0&&(e=Array.from({length:r},()=>0).join("")+e),e}function re(e){return Xe(e)?e.ptr:e}function Ge(e,r){if(c._TYPEOF(e.ptr)!==le[r])throw new Error(`Unexpected object type "${e.type()}" when expecting type "${r}"`)}var ke=new Map;function Ke(e,r){let t=re(r);if(c._R_PreserveObject(t),e!==void 0){if(En(e)){ke.get(e).push(t);return}throw new Error("Unexpected shelter type "+typeof e)}}function vn(e,r){let t=re(r);c._R_ReleaseObject(t);let n=ke.get(e),a=n.indexOf(t);if(a<0)throw new Error("Can't find object in shelter.");n.splice(a,1)}function Sn(e){let r=ke.get(e);for(let t of r)try{c._R_ReleaseObject(t)}catch(n){console.error(n)}ke.set(e,[])}function ja(e){if(zt(e))return new(qt(e.type))(e);if(typeof e>"u")return new ht;if(e&&typeof e=="object"&&"type"in e&&e.type==="null")return new ht;if(e===null)return new ae({type:"logical",names:null,values:[null]});if(typeof e=="boolean")return new ae(e);if(typeof e=="number")return new Je(e);if(typeof e=="string")return new ce(e);if(Be(e))return new pt(e);if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer)return new gt(e);if(Array.isArray(e))return po(e);if(typeof e=="object")return Ve.fromObject(e);throw new Error("R object construction for this JS object is not yet supported.")}function po(e){let r={n:0};if(e.every(n=>n&&typeof n=="object"&&!Xe(n)&&!Be(n))){let n=e,a=n.every(i=>Object.keys(i).filter(o=>!Object.keys(n[0]).includes(o)).length===0&&Object.keys(n[0]).filter(o=>!Object.keys(i).includes(o)).length===0),s=n.every(i=>Object.values(i).every(o=>qa(o)||Ha(o)));if(a&&s)return Ve.fromD3(n)}if(e.every(n=>typeof n=="boolean"||n===null))return new ae(e);if(e.every(n=>typeof n=="number"||n===null))return new Je(e);if(e.every(n=>typeof n=="string"||n===null))return new ce(e);try{let n=new ue([new j("c"),...e]);return O(n,r),n.eval()}finally{F(r.n)}}var B=class{constructor(r){this.ptr=r}type(){let r=c._TYPEOF(this.ptr);return Object.keys(le).find(n=>le[n]===r)}},ft,Er,qe=class qe extends B{constructor(t){if(!(t instanceof B))return ja(t);super(t.ptr);C(this,ft)}static wrap(t){let n=c._TYPEOF(t),a=Object.keys(le)[Object.values(le).indexOf(n)];return new(qt(a))(new B(t))}get[Symbol.toStringTag](){return`RObject:${this.type()}`}static getPersistentObject(t){return W[t]}getPropertyValue(t){return this[t]}inspect(){be(".Internal(inspect(x))",{x:this})}isNull(){return c._TYPEOF(this.ptr)===le.null}isNa(){try{let t=be("is.na(x)",{x:this});return ze(t),t.toBoolean()}finally{F(1)}}isUnbound(){return this.ptr===W.unboundValue.ptr}attrs(){return $e.wrap(c._ATTRIB(this.ptr))}class(){let t={n:0},n=new ue([new j("class"),this]);O(n,t);try{return n.eval()}finally{F(t.n)}}setNames(t){let n;if(t===null)n=W.null;else if(Array.isArray(t)&&t.every(a=>typeof a=="string"||a===null))n=new ce(t);else throw new Error("Argument to setNames must be null or an Array of strings or null");return c._Rf_setAttrib(this.ptr,W.namesSymbol.ptr,n.ptr),this}names(){let t=ce.wrap(c._Rf_getAttrib(this.ptr,W.namesSymbol.ptr));return t.isNull()?null:t.toArray()}includes(t){let n=this.names();return n&&n.includes(t)}toJs(t={depth:0},n=1){throw new Error("This R object cannot be converted to JS")}subset(t){return We(this,ft,Er).call(this,t,W.bracketSymbol.ptr)}get(t){return We(this,ft,Er).call(this,t,W.bracket2Symbol.ptr)}getDollar(t){return We(this,ft,Er).call(this,t,W.dollarSymbol.ptr)}pluck(...t){let n=Wa(W.null);try{let a=(i,o)=>{let d=i.get(o);return Ba(d,n)},s=t.reduce(a,this);return s.isNull()?void 0:s}finally{La(n)}}set(t,n){let a={n:0};try{let s=new qe(t);O(s,a);let i=new qe(n);O(i,a);let o=new j("[[<-"),d=c._Rf_lang4(o.ptr,this.ptr,s.ptr,i.ptr);return O(d,a),qe.wrap(je(d,W.baseEnv))}finally{F(a.n)}}static getMethods(t){let n=new Set,a=t;do Object.getOwnPropertyNames(a).map(s=>n.add(s));while(a=Object.getPrototypeOf(a));return[...n.keys()].filter(s=>typeof t[s]=="function")}};ft=new WeakSet,Er=function(t,n){let a={n:0};try{let s=new qe(t);O(s,a);let i=c._Rf_lang3(n,this.ptr,s.ptr);return O(i,a),qe.wrap(je(i,W.baseEnv))}finally{F(a.n)}};var x=qe,ht=class extends x{constructor(){return super(new B(c.getValue(c._R_NilValue,"*"))),this}toJs(){return{type:"null"}}},j=class extends x{constructor(r){if(r instanceof B){Ge(r,"symbol"),super(r);return}let t=c.allocateUTF8(r);try{super(new B(c._Rf_install(t)))}finally{c._free(t)}}toJs(){let r=this.toObject();return{type:"symbol",printname:r.printname,symvalue:r.symvalue,internal:r.internal}}toObject(){return{printname:this.printname().isUnbound()?null:this.printname().toString(),symvalue:this.symvalue().isUnbound()?null:this.symvalue().ptr,internal:this.internal().isNull()?null:this.internal().ptr}}toString(){return this.printname().toString()}printname(){return Ze.wrap(c._PRINTNAME(this.ptr))}symvalue(){return x.wrap(c._SYMVALUE(this.ptr))}internal(){return x.wrap(c._INTERNAL(this.ptr))}},$e=class e extends x{constructor(r){if(r instanceof B)return Ge(r,"pairlist"),super(r),this;let t={n:0};try{let{names:n,values:a}=mt(r),s=e.wrap(c._Rf_allocList(a.length));O(s,t);for(let[i,o]=[0,s];!o.isNull();[i,o]=[i+1,o.cdr()])o.setcar(new x(a[i]));s.setNames(n),super(s)}finally{F(t.n)}}get length(){return this.toArray().length}toArray(r={depth:1}){return this.toJs(r).values}toObject({allowDuplicateKey:r=!0,allowEmptyKey:t=!1,depth:n=-1}={}){let a=this.entries({depth:n}),s=a.map(([i])=>i);if(!r&&new Set(s).size!==s.length)throw new Error("Duplicate key when converting pairlist without allowDuplicateKey enabled");if(!t&&s.some(i=>!i))throw new Error("Empty or null key when converting pairlist without allowEmptyKey enabled");return Object.fromEntries(a.filter((i,o)=>a.findIndex(d=>d[0]===i[0])===o))}entries(r={depth:1}){let t=this.toJs(r);return t.values.map((n,a)=>[t.names?t.names[a]:null,n])}toJs(r={depth:0},t=1){let n=[],a=!1,s=[];for(let o=this;!o.isNull();o=o.cdr()){let d=o.tag();d.isNull()?n.push(""):(a=!0,n.push(d.toString())),r.depth&&t>=r.depth?s.push(o.car()):s.push(o.car().toJs(r,t+1))}return{type:"pairlist",names:a?n:null,values:s}}includes(r){return r in this.toObject()}setcar(r){c._SETCAR(this.ptr,r.ptr)}car(){return x.wrap(c._CAR(this.ptr))}cdr(){return x.wrap(c._CDR(this.ptr))}tag(){return x.wrap(c._TAG(this.ptr))}},ue=class e extends x{constructor(r){if(r instanceof B)return Ge(r,"call"),super(r),this;let t={n:0};try{let{values:n}=mt(r),a=n.map(i=>O(new x(i),t)),s=e.wrap(c._Rf_allocVector(le.call,n.length));O(s,t);for(let[i,o]=[0,s];!o.isNull();[i,o]=[i+1,o.cdr()])o.setcar(a[i]);super(s)}finally{F(t.n)}}setcar(r){c._SETCAR(this.ptr,r.ptr)}car(){return x.wrap(c._CAR(this.ptr))}cdr(){return x.wrap(c._CDR(this.ptr))}eval(){return c.webr.evalR(this,{env:W.baseEnv})}capture(r={}){return c.webr.captureR(this,r)}deparse(){let r={n:0};try{let t=c._Rf_lang2(new j("deparse1").ptr,c._Rf_lang2(new j("quote").ptr,this.ptr));O(t,r);let n=ce.wrap(je(t,W.baseEnv));return O(n,r),n.toString()}finally{F(r.n)}}},de=class e extends x{constructor(r,t=null){if(r instanceof B){if(Ge(r,"list"),super(r),t){if(t.length!==this.length)throw new Error("Can't construct named `RList`. Supplied `names` must be the same length as the list.");this.setNames(t)}return this}let n={n:0};try{let a=mt(r),s=c._Rf_allocVector(le.list,a.values.length);O(s,n),a.values.forEach((o,d)=>{$a(o)?c._SET_VECTOR_ELT(s,d,new e(o).ptr):c._SET_VECTOR_ELT(s,d,new x(o).ptr)});let i=t||a.names;if(i&&i.length!==a.values.length)throw new Error("Can't construct named `RList`. Supplied `names` must be the same length as the list.");x.wrap(s).setNames(i),super(new B(s))}finally{F(n.n)}}get length(){return c._LENGTH(this.ptr)}isDataFrame(){let r=$e.wrap(c._ATTRIB(this.ptr)).get("class");return!r.isNull()&&r.toArray().includes("data.frame")}toArray(r={depth:1}){return this.toJs(r).values}toObject({allowDuplicateKey:r=!0,allowEmptyKey:t=!1,depth:n=-1}={}){let a=this.entries({depth:n}),s=a.map(([i])=>i);if(!r&&new Set(s).size!==s.length)throw new Error("Duplicate key when converting list without allowDuplicateKey enabled");if(!t&&s.some(i=>!i))throw new Error("Empty or null key when converting list without allowEmptyKey enabled");return Object.fromEntries(a.filter((i,o)=>a.findIndex(d=>d[0]===i[0])===o))}toD3(){if(!this.isDataFrame())throw new Error("Can't convert R list object to D3 format. Object must be of class 'data.frame'.");return this.entries().reduce((t,n)=>(n[1].forEach((a,s)=>t[s]=Object.assign(t[s]||{},{[n[0]]:a})),t),[])}entries(r={depth:-1}){let t=this.toJs(r);return this.isDataFrame()&&r.depth<0&&(t.values=t.values.map(n=>n.toArray())),t.values.map((n,a)=>[t.names?t.names[a]:null,n])}toJs(r={depth:0},t=1){return{type:"list",names:this.names(),values:[...Array(this.length).keys()].map(n=>r.depth&&t>=r.depth?this.get(n+1):this.get(n+1).toJs(r,t+1))}}},Ve=class e extends de{constructor(r){if(r instanceof B){if(super(r),!this.isDataFrame())throw new Error("Can't construct `RDataFrame`. Supplied R object is not a `data.frame`.");return this}return e.fromObject(r)}static fromObject(r){let{names:t,values:n}=mt(r),a={n:0};try{let s=!!t&&t.length>0&&t.every(o=>o),i=n.length>0&&n.every(o=>Array.isArray(o)||ArrayBuffer.isView(o)||o instanceof ArrayBuffer);if(s&&i){let o=n,d=o.every(u=>u.length===o[0].length),l=o.every(u=>qa(u[0])||Ha(u[0]));if(d&&l){let u=new de({type:"list",names:t,values:o.map(g=>ja(g))});O(u,a);let b=new ue([new j("as.data.frame"),u]);return O(b,a),new e(b.eval())}}}finally{F(a.n)}throw new Error("Can't construct `data.frame`. Source object is not eligible.")}static fromD3(r){return this.fromObject(Object.fromEntries(Object.keys(r[0]).map(t=>[t,r.map(n=>n[t])])))}},dt=class extends x{exec(...r){let t={n:0};try{let n=new ue([this,...r]);return O(n,t),n.eval()}finally{F(t.n)}}capture(r={},...t){let n={n:0};try{let a=new ue([this,...t]);return O(a,n),a.capture(r)}finally{F(n.n)}}},vr=class vr extends x{constructor(r){if(r instanceof B){Ge(r,"string"),super(r);return}let t=c.allocateUTF8(r);try{super(new B(c._Rf_mkCharCE(t,vr.CEType.CE_UTF8)))}finally{c._free(t)}}toString(){let r=c._vmaxget();try{return c.UTF8ToString(c._Rf_translateCharUTF8(this.ptr))}finally{c._vmaxset(r)}}toJs(){return{type:"string",value:this.toString()}}};vr.CEType={CE_NATIVE:0,CE_UTF8:1,CE_LATIN1:2,CE_BYTES:3,CE_SYMBOL:5,CE_ANY:99};var Ze=vr,ne=class extends x{constructor(r={}){if(r instanceof B)return Ge(r,"environment"),super(r),this;let t=0;try{let{names:n,values:a}=mt(r),s=ze(c._R_NewEnv(W.globalEnv.ptr,0,0));++t,a.forEach((i,o)=>{let d=n?n[o]:null;if(!d)throw new Error("Can't create object in new environment with empty symbol name");let l=new j(d),u=ze(new x(i));try{xn(s,l,u)}finally{F(1)}}),super(new B(s))}finally{F(t)}}ls(r=!1,t=!0){return ce.wrap(c._R_lsInternal3(this.ptr,Number(r),Number(t))).toArray()}bind(r,t){let n=new j(r),a=ze(new x(t));try{xn(this,n,a)}finally{F(1)}}names(){return this.ls(!0,!0)}frame(){return x.wrap(c._FRAME(this.ptr))}subset(r){if(typeof r=="number")throw new Error("Object of type environment is not subsettable");return this.getDollar(r)}toObject({depth:r=-1}={}){let t=this.names();return Object.fromEntries([...Array(t.length).keys()].map(n=>{let a=this.getDollar(t[n]);return[t[n],r<0?a:a.toJs({depth:r})]}))}toJs(r={depth:0},t=1){let n=this.names(),a=[...Array(n.length).keys()].map(s=>r.depth&&t>=r.depth?this.getDollar(n[s]):this.getDollar(n[s]).toJs(r,t+1));return{type:"environment",names:n,values:a}}},Ae=class extends x{constructor(r,t,n){if(r instanceof B)return Ge(r,t),super(r),this;let a={n:0};try{let{names:s,values:i}=mt(r),o=c._Rf_allocVector(le[t],i.length);O(o,a),i.forEach(n(o)),x.wrap(o).setNames(s),super(new B(o))}finally{F(a.n)}}get length(){return c._LENGTH(this.ptr)}get(r){return super.get(r)}subset(r){return super.subset(r)}getDollar(){throw new Error("$ operator is invalid for atomic vectors")}detectMissing(){let r={n:0};try{let t=c._Rf_lang2(new j("is.na").ptr,this.ptr);O(t,r);let n=ae.wrap(je(t,W.baseEnv));O(n,r);let a=n.toTypedArray();return Array.from(a).map(s=>!!s)}finally{F(r.n)}}toArray(){let r=this.toTypedArray();return this.detectMissing().map((t,n)=>t?null:r[n])}toObject({allowDuplicateKey:r=!0,allowEmptyKey:t=!1}={}){let n=this.entries(),a=n.map(([s])=>s);if(!r&&new Set(a).size!==a.length)throw new Error("Duplicate key when converting atomic vector without allowDuplicateKey enabled");if(!t&&a.some(s=>!s))throw new Error("Empty or null key when converting atomic vector without allowEmptyKey enabled");return Object.fromEntries(n.filter((s,i)=>n.findIndex(o=>o[0]===s[0])===i))}entries(){let r=this.toArray(),t=this.names();return r.map((n,a)=>[t?t[a]:null,n])}toJs(){return{type:this.type(),names:this.names(),values:this.toArray()}}},Sr,Tr=class Tr extends Ae{constructor(r){super(r,"logical",A(Tr,Sr))}getBoolean(r){return this.get(r).toArray()[0]}toBoolean(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let r=this.getBoolean(1);if(r===null)throw new Error("Can't convert missing value `NA` to a JS boolean");return r}toTypedArray(){return new Int32Array(c.HEAP32.subarray(c._LOGICAL(this.ptr)/4,c._LOGICAL(this.ptr)/4+this.length))}toArray(){let r=this.toTypedArray();return this.detectMissing().map((t,n)=>t?null:!!r[n])}};Sr=new WeakMap,C(Tr,Sr,r=>{let t=c._LOGICAL(r),n=c.getValue(c._R_NaInt,"i32");return(a,s)=>{c.setValue(t+4*s,a===null?n:!!a,"i32")}});var ae=Tr,kr,Ar=class Ar extends Ae{constructor(r){super(r,"integer",A(Ar,kr))}getNumber(r){return this.get(r).toArray()[0]}toNumber(){if(thi