webr
Version:
The statistical programming language R compiled into WASM for use in a web browser and node.
1 lines • 66.4 kB
JavaScript
"use strict";var mr=Object.create;var Te=Object.defineProperty;var Rr=Object.getOwnPropertyDescriptor;var gr=Object.getOwnPropertyNames;var br=Object.getPrototypeOf,wr=Object.prototype.hasOwnProperty;var w=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),xr=(r,e)=>{for(var t in e)Te(r,t,{get:e[t],enumerable:!0})},Pt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of gr(e))!wr.call(r,n)&&n!==t&&Te(r,n,{get:()=>e[n],enumerable:!(s=Rr(e,n))||s.enumerable});return r};var Tt=(r,e,t)=>(t=r!=null?mr(br(r)):{},Pt(e||!r||!r.__esModule?Te(t,"default",{value:r,enumerable:!0}):t,r)),Er=r=>Pt(Te({},"__esModule",{value:!0}),r);var fe=w(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.getUint64=k.getInt64=k.setInt64=k.setUint64=k.UINT32_MAX=void 0;k.UINT32_MAX=4294967295;function kr(r,e,t){let s=t/4294967296,n=t;r.setUint32(e,s),r.setUint32(e+4,n)}k.setUint64=kr;function Mr(r,e,t){let s=Math.floor(t/4294967296),n=t;r.setUint32(e,s),r.setUint32(e+4,n)}k.setInt64=Mr;function Wr(r,e){let t=r.getInt32(e),s=r.getUint32(e+4);return t*4294967296+s}k.getInt64=Wr;function Ar(r,e){let t=r.getUint32(e),s=r.getUint32(e+4);return t*4294967296+s}k.getUint64=Ar});var Ae=w(E=>{"use strict";var et,tt,rt;Object.defineProperty(E,"__esModule",{value:!0});E.utf8DecodeTD=E.TEXT_DECODER_THRESHOLD=E.utf8DecodeJs=E.utf8EncodeTE=E.TEXT_ENCODER_THRESHOLD=E.utf8EncodeJs=E.utf8Count=void 0;var Nt=fe(),We=(typeof process>"u"||((et=process==null?void 0:process.env)===null||et===void 0?void 0:et.TEXT_ENCODING)!=="never")&&typeof TextEncoder<"u"&&typeof TextDecoder<"u";function Or(r){let e=r.length,t=0,s=0;for(;s<e;){let n=r.charCodeAt(s++);if((n&4294967168)===0){t++;continue}else if((n&4294965248)===0)t+=2;else{if(n>=55296&&n<=56319&&s<e){let o=r.charCodeAt(s);(o&64512)===56320&&(++s,n=((n&1023)<<10)+(o&1023)+65536)}(n&4294901760)===0?t+=3:t+=4}}return t}E.utf8Count=Or;function Dr(r,e,t){let s=r.length,n=t,o=0;for(;o<s;){let a=r.charCodeAt(o++);if((a&4294967168)===0){e[n++]=a;continue}else if((a&4294965248)===0)e[n++]=a>>6&31|192;else{if(a>=55296&&a<=56319&&o<s){let i=r.charCodeAt(o);(i&64512)===56320&&(++o,a=((a&1023)<<10)+(i&1023)+65536)}(a&4294901760)===0?(e[n++]=a>>12&15|224,e[n++]=a>>6&63|128):(e[n++]=a>>18&7|240,e[n++]=a>>12&63|128,e[n++]=a>>6&63|128)}e[n++]=a&63|128}}E.utf8EncodeJs=Dr;var me=We?new TextEncoder:void 0;E.TEXT_ENCODER_THRESHOLD=We?typeof process<"u"&&((tt=process==null?void 0:process.env)===null||tt===void 0?void 0:tt.TEXT_ENCODING)!=="force"?200:0:Nt.UINT32_MAX;function Cr(r,e,t){e.set(me.encode(r),t)}function Ir(r,e,t){me.encodeInto(r,e.subarray(t))}E.utf8EncodeTE=me?.encodeInto?Ir:Cr;var Ur=4096;function Nr(r,e,t){let s=e,n=s+t,o=[],a="";for(;s<n;){let i=r[s++];if((i&128)===0)o.push(i);else if((i&224)===192){let c=r[s++]&63;o.push((i&31)<<6|c)}else if((i&240)===224){let c=r[s++]&63,R=r[s++]&63;o.push((i&31)<<12|c<<6|R)}else if((i&248)===240){let c=r[s++]&63,R=r[s++]&63,d=r[s++]&63,M=(i&7)<<18|c<<12|R<<6|d;M>65535&&(M-=65536,o.push(M>>>10&1023|55296),M=56320|M&1023),o.push(M)}else o.push(i);o.length>=Ur&&(a+=String.fromCharCode(...o),o.length=0)}return o.length>0&&(a+=String.fromCharCode(...o)),a}E.utf8DecodeJs=Nr;var Br=We?new TextDecoder:null;E.TEXT_DECODER_THRESHOLD=We?typeof process<"u"&&((rt=process==null?void 0:process.env)===null||rt===void 0?void 0:rt.TEXT_DECODER)!=="force"?200:0:Nt.UINT32_MAX;function jr(r,e,t){let s=r.subarray(e,e+t);return Br.decode(s)}E.utf8DecodeTD=jr});var nt=w(Oe=>{"use strict";Object.defineProperty(Oe,"__esModule",{value:!0});Oe.ExtData=void 0;var st=class{constructor(e,t){this.type=e,this.data=t}};Oe.ExtData=st});var Ce=w(De=>{"use strict";Object.defineProperty(De,"__esModule",{value:!0});De.DecodeError=void 0;var ot=class r extends Error{constructor(e){super(e);let t=Object.create(r.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:r.name})}};De.DecodeError=ot});var at=w(b=>{"use strict";Object.defineProperty(b,"__esModule",{value:!0});b.timestampExtension=b.decodeTimestampExtension=b.decodeTimestampToTimeSpec=b.encodeTimestampExtension=b.encodeDateToTimeSpec=b.encodeTimeSpecToTimestamp=b.EXT_TIMESTAMP=void 0;var Lr=Ce(),Bt=fe();b.EXT_TIMESTAMP=-1;var Fr=4294967296-1,qr=17179869184-1;function jt({sec:r,nsec:e}){if(r>=0&&e>=0&&r<=qr)if(e===0&&r<=Fr){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,r),t}else{let t=r/4294967296,s=r&4294967295,n=new Uint8Array(8),o=new DataView(n.buffer);return o.setUint32(0,e<<2|t&3),o.setUint32(4,s),n}else{let t=new Uint8Array(12),s=new DataView(t.buffer);return s.setUint32(0,e),(0,Bt.setInt64)(s,4,r),t}}b.encodeTimeSpecToTimestamp=jt;function Lt(r){let e=r.getTime(),t=Math.floor(e/1e3),s=(e-t*1e3)*1e6,n=Math.floor(s/1e9);return{sec:t+n,nsec:s-n*1e9}}b.encodeDateToTimeSpec=Lt;function Ft(r){if(r instanceof Date){let e=Lt(r);return jt(e)}else return null}b.encodeTimestampExtension=Ft;function qt(r){let e=new DataView(r.buffer,r.byteOffset,r.byteLength);switch(r.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{let t=e.getUint32(0),s=e.getUint32(4),n=(t&3)*4294967296+s,o=t>>>2;return{sec:n,nsec:o}}case 12:{let t=(0,Bt.getInt64)(e,4),s=e.getUint32(0);return{sec:t,nsec:s}}default:throw new Lr.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${r.length}`)}}b.decodeTimestampToTimeSpec=qt;function Vt(r){let e=qt(r);return new Date(e.sec*1e3+e.nsec/1e6)}b.decodeTimestampExtension=Vt;b.timestampExtension={type:b.EXT_TIMESTAMP,encode:Ft,decode:Vt}});var Ne=w(Ue=>{"use strict";Object.defineProperty(Ue,"__esModule",{value:!0});Ue.ExtensionCodec=void 0;var Ie=nt(),Vr=at(),Re=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(Vr.timestampExtension)}register({type:e,encode:t,decode:s}){if(e>=0)this.encoders[e]=t,this.decoders[e]=s;else{let n=1+e;this.builtInEncoders[n]=t,this.builtInDecoders[n]=s}}tryToEncode(e,t){for(let s=0;s<this.builtInEncoders.length;s++){let n=this.builtInEncoders[s];if(n!=null){let o=n(e,t);if(o!=null){let a=-1-s;return new Ie.ExtData(a,o)}}}for(let s=0;s<this.encoders.length;s++){let n=this.encoders[s];if(n!=null){let o=n(e,t);if(o!=null){let a=s;return new Ie.ExtData(a,o)}}}return e instanceof Ie.ExtData?e:null}decode(e,t,s){let n=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return n?n(e,t,s):new Ie.ExtData(t,e)}};Ue.ExtensionCodec=Re;Re.defaultCodec=new Re});var it=w(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.createDataView=te.ensureUint8Array=void 0;function Jt(r){return r instanceof Uint8Array?r:ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r instanceof ArrayBuffer?new Uint8Array(r):Uint8Array.from(r)}te.ensureUint8Array=Jt;function Jr(r){if(r instanceof ArrayBuffer)return new DataView(r);let e=Jt(r);return new DataView(e.buffer,e.byteOffset,e.byteLength)}te.createDataView=Jr});var ct=w(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.Encoder=C.DEFAULT_INITIAL_BUFFER_SIZE=C.DEFAULT_MAX_DEPTH=void 0;var ge=Ae(),Hr=Ne(),Ht=fe(),zr=it();C.DEFAULT_MAX_DEPTH=100;C.DEFAULT_INITIAL_BUFFER_SIZE=2048;var lt=class{constructor(e=Hr.ExtensionCodec.defaultCodec,t=void 0,s=C.DEFAULT_MAX_DEPTH,n=C.DEFAULT_INITIAL_BUFFER_SIZE,o=!1,a=!1,i=!1,c=!1){this.extensionCodec=e,this.context=t,this.maxDepth=s,this.initialBufferSize=n,this.sortKeys=o,this.forceFloat32=a,this.ignoreUndefined=i,this.forceIntegerToFloat=c,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}reinitializeState(){this.pos=0}encodeSharedRef(e){return this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}encode(e){return this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}doEncode(e,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){let t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(t*2)}resizeBuffer(e){let t=new ArrayBuffer(e),s=new Uint8Array(t),n=new DataView(t);s.set(this.bytes),this.view=n,this.bytes=s}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){Number.isSafeInteger(e)&&!this.forceIntegerToFloat?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):(this.writeU8(211),this.writeI64(e)):this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){if(e.length>ge.TEXT_ENCODER_THRESHOLD){let n=(0,ge.utf8Count)(e);this.ensureBufferSizeToWrite(5+n),this.writeStringHeader(n),(0,ge.utf8EncodeTE)(e,this.bytes,this.pos),this.pos+=n}else{let n=(0,ge.utf8Count)(e);this.ensureBufferSizeToWrite(5+n),this.writeStringHeader(n),(0,ge.utf8EncodeJs)(e,this.bytes,this.pos),this.pos+=n}}encodeObject(e,t){let s=this.extensionCodec.tryToEncode(e,this.context);if(s!=null)this.encodeExtension(s);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,t);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){let t=e.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 s=(0,zr.ensureUint8Array)(e);this.writeU8a(s)}encodeArray(e,t){let s=e.length;if(s<16)this.writeU8(144+s);else if(s<65536)this.writeU8(220),this.writeU16(s);else if(s<4294967296)this.writeU8(221),this.writeU32(s);else throw new Error(`Too large array: ${s}`);for(let n of e)this.doEncode(n,t+1)}countWithoutUndefined(e,t){let s=0;for(let n of t)e[n]!==void 0&&s++;return s}encodeMap(e,t){let s=Object.keys(e);this.sortKeys&&s.sort();let n=this.ignoreUndefined?this.countWithoutUndefined(e,s):s.length;if(n<16)this.writeU8(128+n);else if(n<65536)this.writeU8(222),this.writeU16(n);else if(n<4294967296)this.writeU8(223),this.writeU32(n);else throw new Error(`Too large map object: ${n}`);for(let o of s){let a=e[o];this.ignoreUndefined&&a===void 0||(this.encodeString(o),this.doEncode(a,t+1))}}encodeExtension(e){let t=e.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(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){let t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),(0,Ht.setUint64)(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),(0,Ht.setInt64)(this.view,this.pos,e),this.pos+=8}};C.Encoder=lt});var zt=w(Be=>{"use strict";Object.defineProperty(Be,"__esModule",{value:!0});Be.encode=void 0;var Gr=ct(),$r={};function Xr(r,e=$r){return new Gr.Encoder(e.extensionCodec,e.context,e.maxDepth,e.initialBufferSize,e.sortKeys,e.forceFloat32,e.ignoreUndefined,e.forceIntegerToFloat).encodeSharedRef(r)}Be.encode=Xr});var Gt=w(je=>{"use strict";Object.defineProperty(je,"__esModule",{value:!0});je.prettyByte=void 0;function Kr(r){return`${r<0?"-":""}0x${Math.abs(r).toString(16).padStart(2,"0")}`}je.prettyByte=Kr});var $t=w(Le=>{"use strict";Object.defineProperty(Le,"__esModule",{value:!0});Le.CachedKeyDecoder=void 0;var Qr=Ae(),Yr=16,Zr=16,ut=class{constructor(e=Yr,t=Zr){this.maxKeyLength=e,this.maxLengthPerKey=t,this.hit=0,this.miss=0,this.caches=[];for(let s=0;s<this.maxKeyLength;s++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,s){let n=this.caches[s-1];e:for(let o of n){let a=o.bytes;for(let i=0;i<s;i++)if(a[i]!==e[t+i])continue e;return o.str}return null}store(e,t){let s=this.caches[e.length-1],n={bytes:e,str:t};s.length>=this.maxLengthPerKey?s[Math.random()*s.length|0]=n:s.push(n)}decode(e,t,s){let n=this.find(e,t,s);if(n!=null)return this.hit++,n;this.miss++;let o=(0,Qr.utf8DecodeJs)(e,t,s),a=Uint8Array.prototype.slice.call(e,t,t+s);return this.store(a,o),o}};Le.CachedKeyDecoder=ut});var Fe=w(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.Decoder=L.DataViewIndexOutOfBoundsError=void 0;var pt=Gt(),es=Ne(),X=fe(),dt=Ae(),ht=it(),ts=$t(),j=Ce(),rs=r=>{let e=typeof r;return e==="string"||e==="number"},be=-1,ft=new DataView(new ArrayBuffer(0)),ss=new Uint8Array(ft.buffer);L.DataViewIndexOutOfBoundsError=(()=>{try{ft.getInt8(0)}catch(r){return r.constructor}throw new Error("never reached")})();var Xt=new L.DataViewIndexOutOfBoundsError("Insufficient data"),ns=new ts.CachedKeyDecoder,yt=class{constructor(e=es.ExtensionCodec.defaultCodec,t=void 0,s=X.UINT32_MAX,n=X.UINT32_MAX,o=X.UINT32_MAX,a=X.UINT32_MAX,i=X.UINT32_MAX,c=ns){this.extensionCodec=e,this.context=t,this.maxStrLength=s,this.maxBinLength=n,this.maxArrayLength=o,this.maxMapLength=a,this.maxExtLength=i,this.keyDecoder=c,this.totalPos=0,this.pos=0,this.view=ft,this.bytes=ss,this.headByte=be,this.stack=[]}reinitializeState(){this.totalPos=0,this.headByte=be,this.stack.length=0}setBuffer(e){this.bytes=(0,ht.ensureUint8Array)(e),this.view=(0,ht.createDataView)(this.bytes),this.pos=0}appendBuffer(e){if(this.headByte===be&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),s=(0,ht.ensureUint8Array)(e),n=new Uint8Array(t.length+s.length);n.set(t),n.set(s,t.length),this.setBuffer(n)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:s}=this;return new RangeError(`Extra ${t.byteLength-s} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}*decodeMulti(e){for(this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}async decodeAsync(e){let t=!1,s;for await(let i of e){if(t)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i);try{s=this.doDecodeSync(),t=!0}catch(c){if(!(c instanceof L.DataViewIndexOutOfBoundsError))throw c}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return s}let{headByte:n,pos:o,totalPos:a}=this;throw new RangeError(`Insufficient data in parsing ${(0,pt.prettyByte)(n)} at ${a} (${o} in the current buffer)`)}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){let s=t,n=-1;for await(let o of e){if(t&&n===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(o),s&&(n=this.readArraySize(),s=!1,this.complete());try{for(;yield this.doDecodeSync(),--n!==0;);}catch(a){if(!(a instanceof L.DataViewIndexOutOfBoundsError))throw a}this.totalPos+=this.pos}}doDecodeSync(){e:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else{let n=e-160;t=this.decodeUtf8String(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)t=this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)t=this.readI64();else if(e===217){let n=this.lookU8();t=this.decodeUtf8String(n,1)}else if(e===218){let n=this.lookU16();t=this.decodeUtf8String(n,2)}else if(e===219){let n=this.lookU32();t=this.decodeUtf8String(n,4)}else if(e===220){let n=this.readU16();if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else if(e===221){let n=this.readU32();if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else if(e===222){let n=this.readU16();if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e===223){let n=this.readU32();if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e===196){let n=this.lookU8();t=this.decodeBinary(n,1)}else if(e===197){let n=this.lookU16();t=this.decodeBinary(n,2)}else if(e===198){let n=this.lookU32();t=this.decodeBinary(n,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let n=this.lookU8();t=this.decodeExtension(n,1)}else if(e===200){let n=this.lookU16();t=this.decodeExtension(n,2)}else if(e===201){let n=this.lookU32();t=this.decodeExtension(n,4)}else throw new j.DecodeError(`Unrecognized type byte: ${(0,pt.prettyByte)(e)}`);this.complete();let s=this.stack;for(;s.length>0;){let n=s[s.length-1];if(n.type===0)if(n.array[n.position]=t,n.position++,n.position===n.size)s.pop(),t=n.array;else continue e;else if(n.type===1){if(!rs(t))throw new j.DecodeError("The type of key must be string or number but "+typeof t);if(t==="__proto__")throw new j.DecodeError("The key __proto__ is not allowed");n.key=t,n.type=2;continue e}else if(n.map[n.key]=t,n.readCount++,n.readCount===n.size)s.pop(),t=n.map;else{n.key=null,n.type=1;continue e}}return t}}readHeadByte(){return this.headByte===be&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=be}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new j.DecodeError(`Unrecognized array type byte: ${(0,pt.prettyByte)(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new j.DecodeError(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.push({type:1,size:e,key:null,readCount:0,map:{}})}pushArrayState(e){if(e>this.maxArrayLength)throw new j.DecodeError(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.push({type:0,size:e,array:new Array(e),position:0})}decodeUtf8String(e,t){var s;if(e>this.maxStrLength)throw new j.DecodeError(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw Xt;let n=this.pos+t,o;return this.stateIsMapKey()&&(!((s=this.keyDecoder)===null||s===void 0)&&s.canBeCached(e))?o=this.keyDecoder.decode(this.bytes,n,e):e>dt.TEXT_DECODER_THRESHOLD?o=(0,dt.utf8DecodeTD)(this.bytes,n,e):o=(0,dt.utf8DecodeJs)(this.bytes,n,e),this.pos+=t+e,o}stateIsMapKey(){return this.stack.length>0?this.stack[this.stack.length-1].type===1:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new j.DecodeError(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw Xt;let s=this.pos+t,n=this.bytes.subarray(s,s+e);return this.pos+=t+e,n}decodeExtension(e,t){if(e>this.maxExtLength)throw new j.DecodeError(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let s=this.view.getInt8(this.pos+t),n=this.decodeBinary(e,t+1);return this.extensionCodec.decode(n,s,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 e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=(0,X.getUint64)(this.view,this.pos);return this.pos+=8,e}readI64(){let e=(0,X.getInt64)(this.view,this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};L.Decoder=yt});var mt=w(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.decodeMulti=I.decode=I.defaultDecodeOptions=void 0;var Kt=Fe();I.defaultDecodeOptions={};function os(r,e=I.defaultDecodeOptions){return new Kt.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decode(r)}I.decode=os;function as(r,e=I.defaultDecodeOptions){return new Kt.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeMulti(r)}I.decodeMulti=as});var Zt=w(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.ensureAsyncIterable=V.asyncIterableFromStream=V.isAsyncIterable=void 0;function Qt(r){return r[Symbol.asyncIterator]!=null}V.isAsyncIterable=Qt;function is(r){if(r==null)throw new Error("Assertion Failure: value must not be null nor undefined")}async function*Yt(r){let e=r.getReader();try{for(;;){let{done:t,value:s}=await e.read();if(t)return;is(s),yield s}}finally{e.releaseLock()}}V.asyncIterableFromStream=Yt;function ls(r){return Qt(r)?r:Yt(r)}V.ensureAsyncIterable=ls});var tr=w(U=>{"use strict";Object.defineProperty(U,"__esModule",{value:!0});U.decodeStream=U.decodeMultiStream=U.decodeArrayStream=U.decodeAsync=void 0;var Rt=Fe(),gt=Zt(),qe=mt();async function cs(r,e=qe.defaultDecodeOptions){let t=(0,gt.ensureAsyncIterable)(r);return new Rt.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeAsync(t)}U.decodeAsync=cs;function us(r,e=qe.defaultDecodeOptions){let t=(0,gt.ensureAsyncIterable)(r);return new Rt.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeArrayStream(t)}U.decodeArrayStream=us;function er(r,e=qe.defaultDecodeOptions){let t=(0,gt.ensureAsyncIterable)(r);return new Rt.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeStream(t)}U.decodeMultiStream=er;function ps(r,e=qe.defaultDecodeOptions){return er(r,e)}U.decodeStream=ps});var nr=w(u=>{"use strict";Object.defineProperty(u,"__esModule",{value:!0});u.decodeTimestampExtension=u.encodeTimestampExtension=u.decodeTimestampToTimeSpec=u.encodeTimeSpecToTimestamp=u.encodeDateToTimeSpec=u.EXT_TIMESTAMP=u.ExtData=u.ExtensionCodec=u.Encoder=u.DataViewIndexOutOfBoundsError=u.DecodeError=u.Decoder=u.decodeStream=u.decodeMultiStream=u.decodeArrayStream=u.decodeAsync=u.decodeMulti=u.decode=u.encode=void 0;var ds=zt();Object.defineProperty(u,"encode",{enumerable:!0,get:function(){return ds.encode}});var rr=mt();Object.defineProperty(u,"decode",{enumerable:!0,get:function(){return rr.decode}});Object.defineProperty(u,"decodeMulti",{enumerable:!0,get:function(){return rr.decodeMulti}});var Ve=tr();Object.defineProperty(u,"decodeAsync",{enumerable:!0,get:function(){return Ve.decodeAsync}});Object.defineProperty(u,"decodeArrayStream",{enumerable:!0,get:function(){return Ve.decodeArrayStream}});Object.defineProperty(u,"decodeMultiStream",{enumerable:!0,get:function(){return Ve.decodeMultiStream}});Object.defineProperty(u,"decodeStream",{enumerable:!0,get:function(){return Ve.decodeStream}});var sr=Fe();Object.defineProperty(u,"Decoder",{enumerable:!0,get:function(){return sr.Decoder}});Object.defineProperty(u,"DataViewIndexOutOfBoundsError",{enumerable:!0,get:function(){return sr.DataViewIndexOutOfBoundsError}});var hs=Ce();Object.defineProperty(u,"DecodeError",{enumerable:!0,get:function(){return hs.DecodeError}});var ys=ct();Object.defineProperty(u,"Encoder",{enumerable:!0,get:function(){return ys.Encoder}});var fs=Ne();Object.defineProperty(u,"ExtensionCodec",{enumerable:!0,get:function(){return fs.ExtensionCodec}});var ms=nt();Object.defineProperty(u,"ExtData",{enumerable:!0,get:function(){return ms.ExtData}});var re=at();Object.defineProperty(u,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return re.EXT_TIMESTAMP}});Object.defineProperty(u,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return re.encodeDateToTimeSpec}});Object.defineProperty(u,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return re.encodeTimeSpecToTimestamp}});Object.defineProperty(u,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return re.decodeTimestampToTimeSpec}});Object.defineProperty(u,"encodeTimestampExtension",{enumerable:!0,get:function(){return re.encodeTimestampExtension}});Object.defineProperty(u,"decodeTimestampExtension",{enumerable:!0,get:function(){return re.decodeTimestampExtension}})});var Ns={};xr(Ns,{ChannelType:()=>A,Console:()=>Ge,Shelter:()=>ve,WebR:()=>Ee,WebRChannelError:()=>S,WebRError:()=>P,WebRPayloadError:()=>N,WebRWorkerError:()=>T,isRCall:()=>As,isRCharacter:()=>ks,isRComplex:()=>_s,isRDouble:()=>Ss,isREnvironment:()=>vs,isRFunction:()=>vt,isRInteger:()=>Ts,isRList:()=>Ms,isRLogical:()=>Ps,isRNull:()=>ws,isRObject:()=>m,isRPairlist:()=>Es,isRRaw:()=>Ws,isRSymbol:()=>xs,isShelterID:()=>Qe});module.exports=Er(Ns);var P=class extends Error{constructor(e){super(e),this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}},T=class extends P{},S=class extends P{},N=class extends P{};var h=typeof process<"u"&&process.release&&process.release.name==="node",$e;if(globalThis.document)$e=r=>new Promise((e,t)=>{let s=document.createElement("script");s.src=r,s.onload=()=>e(),s.onerror=t,document.head.appendChild(s)});else if(globalThis.importScripts)$e=async r=>{try{globalThis.importScripts(r)}catch(e){if(e instanceof TypeError)await import(r);else throw e}};else if(h)$e=async r=>{await import((await import("path")).default.resolve(r))};else throw new P("Cannot determine runtime environment");var W={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 oe(r){return!!r&&typeof r=="object"&&Object.keys(W).includes(r.type)}function H(r){return!!r&&typeof r=="object"&&"re"in r&&"im"in r}var l={};function St(r){Object.keys(r).forEach(e=>l._free(r[e]))}function ae(r){return l._Rf_protect(O(r)),r}function y(r,e){return l._Rf_protect(O(r)),++e.n,r}function _t(r){let e=l._malloc(4);return l._R_ProtectWithIndex(O(r),e),{loc:l.getValue(e,"i32"),ptr:e}}function kt(r){l._Rf_unprotect(1),l._free(r.ptr)}function Mt(r,e){return l._R_Reprotect(O(r),e.loc),r}function g(r){l._Rf_unprotect(r)}function Xe(r,e,t){l._Rf_defineVar(O(e),O(t),O(r))}function Ke(r,e){let t={},s={n:0};try{let n=new le(e);y(n,s),t.code=l.allocateUTF8(r);let o=l._R_ParseEvalString(t.code,n.ptr);return p.wrap(o)}finally{St(t),g(s.n)}}function ie(r,e){return l.getWasmTableEntry(l.GOT.ffi_safe_eval.value)(O(r),O(e))}var vr=new WeakMap;function Wt(r,e){return vr.set(r,e),r}function Qe(r){return typeof r=="string"&&r.length===Ye}var Ye=63;function Q(){let r=Array.from({length:4},Pr).join("-");if(r.length!==Ye)throw new Error("comlink internal error: UUID has the wrong length");return r}function Pr(){let r=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16),e=15-r.length;return e>0&&(r=Array.from({length:e},()=>0).join("")+r),r}function O(r){return ke(r)?r.ptr:r}function G(r,e){if(l._TYPEOF(r.ptr)!==W[e])throw new Error(`Unexpected object type "${r.type()}" when expecting type "${e}"`)}function At(r){if(oe(r))return new(Ot(r.type))(r);if(typeof r>"u")return new ce;if(r&&typeof r=="object"&&"type"in r&&r.type==="null")return new ce;if(r===null)return new z({type:"logical",names:null,values:[null]});if(typeof r=="boolean")return new z(r);if(typeof r=="number")return new ye(r);if(typeof r=="string")return new B(r);if(H(r))return new Se(r);if(ArrayBuffer.isView(r)||r instanceof ArrayBuffer)return new _e(r);if(Array.isArray(r))return Tr(r);if(typeof r=="object")return de.fromObject(r);throw new Error("R object construction for this JS object is not yet supported.")}function Tr(r){let e={n:0};if(r.every(s=>s&&typeof s=="object"&&!ke(s)&&!H(s))){let s=r,n=s.every(a=>Object.keys(a).filter(i=>!Object.keys(s[0]).includes(i)).length===0&&Object.keys(s[0]).filter(i=>!Object.keys(a).includes(i)).length===0),o=s.every(a=>Object.values(a).every(i=>Ct(i)||Dt(i)));if(n&&o)return de.fromD3(s)}if(r.every(s=>typeof s=="boolean"||s===null))return new z(r);if(r.every(s=>typeof s=="number"||s===null))return new ye(r);if(r.every(s=>typeof s=="string"||s===null))return new B(r);try{let s=new F([new _("c"),...r]);return y(s,e),s.eval()}finally{g(e.n)}}var f=class{constructor(e){this.ptr=e}type(){let e=l._TYPEOF(this.ptr);return Object.keys(W).find(s=>W[s]===e)}},p=class r extends f{constructor(e){if(!(e instanceof f))return At(e);super(e.ptr)}static wrap(e){let t=l._TYPEOF(e),s=Object.keys(W)[Object.values(W).indexOf(t)];return new(Ot(s))(new f(e))}get[Symbol.toStringTag](){return`RObject:${this.type()}`}static getPersistentObject(e){return x[e]}getPropertyValue(e){return this[e]}inspect(){Ke(".Internal(inspect(x))",{x:this})}isNull(){return l._TYPEOF(this.ptr)===W.null}isNa(){try{let e=Ke("is.na(x)",{x:this});return ae(e),e.toBoolean()}finally{g(1)}}isUnbound(){return this.ptr===x.unboundValue.ptr}attrs(){return ue.wrap(l._ATTRIB(this.ptr))}class(){let e={n:0},t=new F([new _("class"),this]);y(t,e);try{return t.eval()}finally{g(e.n)}}setNames(e){let t;if(e===null)t=x.null;else if(Array.isArray(e)&&e.every(s=>typeof s=="string"||s===null))t=new B(e);else throw new Error("Argument to setNames must be null or an Array of strings or null");return l._Rf_setAttrib(this.ptr,x.namesSymbol.ptr,t.ptr),this}names(){let e=B.wrap(l._Rf_getAttrib(this.ptr,x.namesSymbol.ptr));return e.isNull()?null:e.toArray()}includes(e){let t=this.names();return t&&t.includes(e)}toJs(e={depth:0},t=1){throw new Error("This R object cannot be converted to JS")}subset(e){return this.#e(e,x.bracketSymbol.ptr)}get(e){return this.#e(e,x.bracket2Symbol.ptr)}getDollar(e){return this.#e(e,x.dollarSymbol.ptr)}#e(e,t){let s={n:0};try{let n=new r(e);y(n,s);let o=l._Rf_lang3(t,this.ptr,n.ptr);return y(o,s),r.wrap(ie(o,x.baseEnv))}finally{g(s.n)}}pluck(...e){let t=_t(x.null);try{let s=(o,a)=>{let i=o.get(a);return Mt(i,t)},n=e.reduce(s,this);return n.isNull()?void 0:n}finally{kt(t)}}set(e,t){let s={n:0};try{let n=new r(e);y(n,s);let o=new r(t);y(o,s);let a=new _("[[<-"),i=l._Rf_lang4(a.ptr,this.ptr,n.ptr,o.ptr);return y(i,s),r.wrap(ie(i,x.baseEnv))}finally{g(s.n)}}static getMethods(e){let t=new Set,s=e;do Object.getOwnPropertyNames(s).map(n=>t.add(n));while(s=Object.getPrototypeOf(s));return[...t.keys()].filter(n=>typeof e[n]=="function")}},ce=class extends p{constructor(){return super(new f(l.getValue(l._R_NilValue,"*"))),this}toJs(){return{type:"null"}}},_=class extends p{constructor(e){if(e instanceof f){G(e,"symbol"),super(e);return}let t=l.allocateUTF8(e);try{super(new f(l._Rf_install(t)))}finally{l._free(t)}}toJs(){let e=this.toObject();return{type:"symbol",printname:e.printname,symvalue:e.symvalue,internal:e.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 he.wrap(l._PRINTNAME(this.ptr))}symvalue(){return p.wrap(l._SYMVALUE(this.ptr))}internal(){return p.wrap(l._INTERNAL(this.ptr))}},ue=class r extends p{constructor(e){if(e instanceof f)return G(e,"pairlist"),super(e),this;let t={n:0};try{let{names:s,values:n}=Z(e),o=r.wrap(l._Rf_allocList(n.length));y(o,t);for(let[a,i]=[0,o];!i.isNull();[a,i]=[a+1,i.cdr()])i.setcar(new p(n[a]));o.setNames(s),super(o)}finally{g(t.n)}}get length(){return this.toArray().length}toArray(e={depth:1}){return this.toJs(e).values}toObject({allowDuplicateKey:e=!0,allowEmptyKey:t=!1,depth:s=-1}={}){let n=this.entries({depth:s}),o=n.map(([a])=>a);if(!e&&new Set(o).size!==o.length)throw new Error("Duplicate key when converting pairlist without allowDuplicateKey enabled");if(!t&&o.some(a=>!a))throw new Error("Empty or null key when converting pairlist without allowEmptyKey enabled");return Object.fromEntries(n.filter((a,i)=>n.findIndex(c=>c[0]===a[0])===i))}entries(e={depth:1}){let t=this.toJs(e);return t.values.map((s,n)=>[t.names?t.names[n]:null,s])}toJs(e={depth:0},t=1){let s=[],n=!1,o=[];for(let i=this;!i.isNull();i=i.cdr()){let c=i.tag();c.isNull()?s.push(""):(n=!0,s.push(c.toString())),e.depth&&t>=e.depth?o.push(i.car()):o.push(i.car().toJs(e,t+1))}return{type:"pairlist",names:n?s:null,values:o}}includes(e){return e in this.toObject()}setcar(e){l._SETCAR(this.ptr,e.ptr)}car(){return p.wrap(l._CAR(this.ptr))}cdr(){return p.wrap(l._CDR(this.ptr))}tag(){return p.wrap(l._TAG(this.ptr))}},F=class r extends p{constructor(e){if(e instanceof f)return G(e,"call"),super(e),this;let t={n:0};try{let{values:s}=Z(e),n=s.map(a=>y(new p(a),t)),o=r.wrap(l._Rf_allocVector(W.call,s.length));y(o,t);for(let[a,i]=[0,o];!i.isNull();[a,i]=[a+1,i.cdr()])i.setcar(n[a]);super(o)}finally{g(t.n)}}setcar(e){l._SETCAR(this.ptr,e.ptr)}car(){return p.wrap(l._CAR(this.ptr))}cdr(){return p.wrap(l._CDR(this.ptr))}eval(){return l.webr.evalR(this,{env:x.baseEnv})}capture(e={}){return l.webr.captureR(this,e)}deparse(){let e={n:0};try{let t=l._Rf_lang2(new _("deparse1").ptr,l._Rf_lang2(new _("quote").ptr,this.ptr));y(t,e);let s=B.wrap(ie(t,x.baseEnv));return y(s,e),s.toString()}finally{g(e.n)}}},pe=class r extends p{constructor(e,t=null){if(e instanceof f){if(G(e,"list"),super(e),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 s={n:0};try{let n=Z(e),o=l._Rf_allocVector(W.list,n.values.length);y(o,s),n.values.forEach((i,c)=>{It(i)?l._SET_VECTOR_ELT(o,c,new r(i).ptr):l._SET_VECTOR_ELT(o,c,new p(i).ptr)});let a=t||n.names;if(a&&a.length!==n.values.length)throw new Error("Can't construct named `RList`. Supplied `names` must be the same length as the list.");p.wrap(o).setNames(a),super(new f(o))}finally{g(s.n)}}get length(){return l._LENGTH(this.ptr)}isDataFrame(){let e=ue.wrap(l._ATTRIB(this.ptr)).get("class");return!e.isNull()&&e.toArray().includes("data.frame")}toArray(e={depth:1}){return this.toJs(e).values}toObject({allowDuplicateKey:e=!0,allowEmptyKey:t=!1,depth:s=-1}={}){let n=this.entries({depth:s}),o=n.map(([a])=>a);if(!e&&new Set(o).size!==o.length)throw new Error("Duplicate key when converting list without allowDuplicateKey enabled");if(!t&&o.some(a=>!a))throw new Error("Empty or null key when converting list without allowEmptyKey enabled");return Object.fromEntries(n.filter((a,i)=>n.findIndex(c=>c[0]===a[0])===i))}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,s)=>(s[1].forEach((n,o)=>t[o]=Object.assign(t[o]||{},{[s[0]]:n})),t),[])}entries(e={depth:-1}){let t=this.toJs(e);return this.isDataFrame()&&e.depth<0&&(t.values=t.values.map(s=>s.toArray())),t.values.map((s,n)=>[t.names?t.names[n]:null,s])}toJs(e={depth:0},t=1){return{type:"list",names:this.names(),values:[...Array(this.length).keys()].map(s=>e.depth&&t>=e.depth?this.get(s+1):this.get(s+1).toJs(e,t+1))}}},de=class r extends pe{constructor(e){if(e instanceof f){if(super(e),!this.isDataFrame())throw new Error("Can't construct `RDataFrame`. Supplied R object is not a `data.frame`.");return this}return r.fromObject(e)}static fromObject(e){let{names:t,values:s}=Z(e),n={n:0};try{let o=!!t&&t.length>0&&t.every(i=>i),a=s.length>0&&s.every(i=>Array.isArray(i)||ArrayBuffer.isView(i)||i instanceof ArrayBuffer);if(o&&a){let i=s,c=i.every(d=>d.length===i[0].length),R=i.every(d=>Ct(d[0])||Dt(d[0]));if(c&&R){let d=new pe({type:"list",names:t,values:i.map(Pe=>At(Pe))});y(d,n);let M=new F([new _("as.data.frame"),d]);return y(M,n),new r(M.eval())}}}finally{g(n.n)}throw new Error("Can't construct `data.frame`. Source object is not eligible.")}static fromD3(e){return this.fromObject(Object.fromEntries(Object.keys(e[0]).map(t=>[t,e.map(s=>s[t])])))}},Y=class extends p{exec(...e){let t={n:0};try{let s=new F([this,...e]);return y(s,t),s.eval()}finally{g(t.n)}}capture(e={},...t){let s={n:0};try{let n=new F([this,...t]);return y(n,s),n.capture(e)}finally{g(s.n)}}},he=class r extends p{static{this.CEType={CE_NATIVE:0,CE_UTF8:1,CE_LATIN1:2,CE_BYTES:3,CE_SYMBOL:5,CE_ANY:99}}constructor(e){if(e instanceof f){G(e,"string"),super(e);return}let t=l.allocateUTF8(e);try{super(new f(l._Rf_mkCharCE(t,r.CEType.CE_UTF8)))}finally{l._free(t)}}toString(){let e=l._vmaxget();try{return l.UTF8ToString(l._Rf_translateCharUTF8(this.ptr))}finally{l._vmaxset(e)}}toJs(){return{type:"string",value:this.toString()}}},le=class extends p{constructor(e={}){if(e instanceof f)return G(e,"environment"),super(e),this;let t=0;try{let{names:s,values:n}=Z(e),o=ae(l._R_NewEnv(x.globalEnv.ptr,0,0));++t,n.forEach((a,i)=>{let c=s?s[i]:null;if(!c)throw new Error("Can't create object in new environment with empty symbol name");let R=new _(c),d=ae(new p(a));try{Xe(o,R,d)}finally{g(1)}}),super(new f(o))}finally{g(t)}}ls(e=!1,t=!0){return B.wrap(l._R_lsInternal3(this.ptr,Number(e),Number(t))).toArray()}bind(e,t){let s=new _(e),n=ae(new p(t));try{Xe(this,s,n)}finally{g(1)}}names(){return this.ls(!0,!0)}frame(){return p.wrap(l._FRAME(this.ptr))}subset(e){if(typeof e=="number")throw new Error("Object of type environment is not subsettable");return this.getDollar(e)}toObject({depth:e=-1}={}){let t=this.names();return Object.fromEntries([...Array(t.length).keys()].map(s=>{let n=this.getDollar(t[s]);return[t[s],e<0?n:n.toJs({depth:e})]}))}toJs(e={depth:0},t=1){let s=this.names(),n=[...Array(s.length).keys()].map(o=>e.depth&&t>=e.depth?this.getDollar(s[o]):this.getDollar(s[o]).toJs(e,t+1));return{type:"environment",names:s,values:n}}},q=class extends p{constructor(e,t,s){if(e instanceof f)return G(e,t),super(e),this;let n={n:0};try{let{names:o,values:a}=Z(e),i=l._Rf_allocVector(W[t],a.length);y(i,n),a.forEach(s(i)),p.wrap(i).setNames(o),super(new f(i))}finally{g(n.n)}}get length(){return l._LENGTH(this.ptr)}get(e){return super.get(e)}subset(e){return super.subset(e)}getDollar(){throw new Error("$ operator is invalid for atomic vectors")}detectMissing(){let e={n:0};try{let t=l._Rf_lang2(new _("is.na").ptr,this.ptr);y(t,e);let s=z.wrap(ie(t,x.baseEnv));y(s,e);let n=s.toTypedArray();return Array.from(n).map(o=>!!o)}finally{g(e.n)}}toArray(){let e=this.toTypedArray();return this.detectMissing().map((t,s)=>t?null:e[s])}toObject({allowDuplicateKey:e=!0,allowEmptyKey:t=!1}={}){let s=this.entries(),n=s.map(([o])=>o);if(!e&&new Set(n).size!==n.length)throw new Error("Duplicate key when converting atomic vector without allowDuplicateKey enabled");if(!t&&n.some(o=>!o))throw new Error("Empty or null key when converting atomic vector without allowEmptyKey enabled");return Object.fromEntries(s.filter((o,a)=>s.findIndex(i=>i[0]===o[0])===a))}entries(){let e=this.toArray(),t=this.names();return e.map((s,n)=>[t?t[n]:null,s])}toJs(){return{type:this.type(),names:this.names(),values:this.toArray()}}},z=class r extends q{constructor(e){super(e,"logical",r.#e)}static#e=e=>{let t=l._LOGICAL(e),s=l.getValue(l._R_NaInt,"i32");return(n,o)=>{l.setValue(t+4*o,n===null?s:!!n,"i32")}};getBoolean(e){return this.get(e).toArray()[0]}toBoolean(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let e=this.getBoolean(1);if(e===null)throw new Error("Can't convert missing value `NA` to a JS boolean");return e}toTypedArray(){return new Int32Array(l.HEAP32.subarray(l._LOGICAL(this.ptr)/4,l._LOGICAL(this.ptr)/4+this.length))}toArray(){let e=this.toTypedArray();return this.detectMissing().map((t,s)=>t?null:!!e[s])}},Ze=class r extends q{constructor(e){super(e,"integer",r.#e)}static#e=e=>{let t=l._INTEGER(e),s=l.getValue(l._R_NaInt,"i32");return(n,o)=>{l.setValue(t+4*o,n===null?s:Math.round(Number(n)),"i32")}};getNumber(e){return this.get(e).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let e=this.getNumber(1);if(e===null)throw new Error("Can't convert missing value `NA` to a JS number");return e}toTypedArray(){return new Int32Array(l.HEAP32.subarray(l._INTEGER(this.ptr)/4,l._INTEGER(this.ptr)/4+this.length))}},ye=class r extends q{constructor(e){super(e,"double",r.#e)}static#e=e=>{let t=l._REAL(e),s=l.getValue(l._R_NaReal,"double");return(n,o)=>{l.setValue(t+8*o,n===null?s:n,"double")}};getNumber(e){return this.get(e).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let e=this.getNumber(1);if(e===null)throw new Error("Can't convert missing value `NA` to a JS number");return e}toTypedArray(){return new Float64Array(l.HEAPF64.subarray(l._REAL(this.ptr)/8,l._REAL(this.ptr)/8+this.length))}},Se=class r extends q{constructor(e){super(e,"complex",r.#e)}static#e=e=>{let t=l._COMPLEX(e),s=l.getValue(l._R_NaReal,"double");return(n,o)=>{l.setValue(t+8*(2*o),n===null?s:n.re,"double"),l.setValue(t+8*(2*o+1),n===null?s:n.im,"double")}};getComplex(e){return this.get(e).toArray()[0]}toComplex(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let e=this.getComplex(1);if(e===null)throw new Error("Can't convert missing value `NA` to a JS object");return e}toTypedArray(){return new Float64Array(l.HEAPF64.subarray(l._COMPLEX(this.ptr)/8,l._COMPLEX(this.ptr)/8+2*this.length))}toArray(){let e=this.toTypedArray();return this.detectMissing().map((t,s)=>t?null:{re:e[2*s],im:e[2*s+1]})}},B=class r extends q{constructor(e){super(e,"character",r.#e)}static#e=e=>(t,s)=>{t===null?l._SET_STRING_ELT(e,s,x.naString.ptr):l._SET_STRING_ELT(e,s,new he(t).ptr)};getString(e){return this.get(e).toArray()[0]}toString(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let e=this.getString(1);if(e===null)throw new Error("Can't convert missing value `NA` to a JS string");return e}toTypedArray(){return new Uint32Array(l.HEAPU32.subarray(l._STRING_PTR(this.ptr)/4,l._STRING_PTR(this.ptr)/4+this.length))}toArray(){let e=l._vmaxget();try{return this.detectMissing().map((t,s)=>t?null:l.UTF8ToString(l._Rf_translateCharUTF8(l._STRING_ELT(this.ptr,s))))}finally{l._vmaxset(e)}}},_e=class r extends q{constructor(e){e instanceof ArrayBuffer&&(e=new Uint8Array(e)),super(e,"raw",r.#e)}static#e=e=>{let t=l._RAW(e);return(s,n)=>{l.setValue(t+n,Number(s),"i8")}};getNumber(e){return this.get(e).toArray()[0]}toNumber(){if(this.length!==1)throw new Error("Can't convert atomic vector of length > 1 to a scalar JS value");let e=this.getNumber(1);if(e===null)throw new Error("Can't convert missing value `NA` to a JS number");return e}toTypedArray(){return new Uint8Array(l.HEAPU8.subarray(l._RAW(this.ptr),l._RAW(this.ptr)+this.length))}};function Z(r){return oe(r)?r:Array.isArray(r)||ArrayBuffer.isView(r)?{names:null,values:r}:r&&typeof r=="object"&&!H(r)?{names:Object.keys(r),values:Object.values(r)}:{names:null,values:[r]}}function Ot(r){let e={object:p,null:ce,symbol:_,pairlist:ue,closure:Y,environment:le,call:F,special:Y,builtin:Y,string:he,logical:z,integer:Ze,double:ye,complex:Se,character:B,list:pe,raw:_e,function:Y,dataframe:de};return r in e?e[r]:p}function ke(r){return r instanceof p}function Dt(r){let e=["logical","integer","double","complex","character"];return ke(r)&&e.includes(r.type())||ke(r)&&r.isNa()}function Ct(r){return r===null||typeof r=="number"||typeof r=="boolean"||typeof r=="string"||H(r)}var x;function $(){let r={resolve:(()=>{}),reject:(()=>{}),promise:Promise.resolve()},e=new Promise((t,s)=>{r.resolve=t,r.reject=s});return r.promise=e,r}function Ut(r){return new Promise(e=>setTimeout(e,r))}function D(r,e,t,...s){return r==null||_r(r)?r:r instanceof ArrayBuffer?new Uint8Array(r):e(r)?t(r,...s):Array.isArray(r)||ArrayBuffer.isView(r)?r.map(n=>D(n,e,t,...s)):r instanceof f?r:typeof r=="object"?Object.fromEntries(Object.entries(r).map(([n,o])=>[n,D(o,e,t,...s)])):r}function ee(r,e,t,s,n=!0){let o=new XMLHttpRequest;o.open("get",r,n),o.onload=()=>{if(o.status>=200&&o.status<300)try{let a=new Worker(URL.createObjectURL(new Blob([o.responseText])),s);e(a)}catch(a){if(t)t(a instanceof Error?a:new Error(String(a)));else throw a}else t?t(new Error(`Worker loading error: HTTP ${o.status}`)):console.error(`HTTP Error: ${o.status}`)},o.onerror=()=>{t?t(new Error(`Network error loading ${r}`)):console.error(`Network error loading ${r}`)},o.send()}function Me(r){if(h)return!1;let e=new URL(location.href),t=new URL(r,location.origin);return!(e.host===t.host&&e.port===t.port&&e.protocol===t.protocol)}function _r(r){return typeof ImageBitmap<"u"&&r instanceof ImageBitmap}function It(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)&&!ArrayBuffer.isView(r)&&!H(r)&&!oe(r)&&!(r instanceof Date)&&!(r instanceof RegExp)&&!(r instanceof Error)&&!(r instanceof f)&&Object.getPrototypeOf(r)===Object.prototype}var ir=Tt(nr());var Rs=new TextEncoder;async function K(r,e,t){try{let{taskId:s,sizeBuffer:n,dataBuffer:o,signalBuffer:a}=e,i=(0,ir.encode)(t),c=i.length<=o.length;if(Atomics.store(n,0,i.length),Atomics.store(n,1,+c),!c){let[R,d]=gs(r);o.set(Rs.encode(R)),await or(a,s),o=(await d).dataBuffer}o.set(i),Atomics.store(n,1,1),await or(a,s)}catch(s){console.warn(s)}}function gs(r){let e=Q();return[e,new Promise(t=>{h?r.once("message",s=>{!s.id||s.id!==e||t(s)}):r.addEventListener("message",function s(n){!n.data||!n.data.id||n.data.id!==e||(r.removeEventListener("message",s),t(n.data))}),r.start&&r.start()})]}async function or(r,e){let t=(e>>1)%32,s=1;for(;Atomics.compareExchange(r,t+1,0,e)!==0;)await Ut(s),s<32&&(s*=2);Atomics.or(r,0,1<<t),Atomics.notify(r,0)}var se=class{#e;#t;constructor(){this.#t=[],this.#e=[]}reset(){this.#t=[],this.#e=[]}put(e){this.#t.length||this.#r(),this.#t.shift()(e)}async get(){return this.#e.length||this.#r(),this.#e.shift()}isEmpty(){return!this.#e.length}isBlocked(){return!!this.#t.length}get length(){return this.#e.length-this.#t.length}#r(){this.#e.push(new Promise(e=>{this.#t.push(e)}))}};function wt(r,e){return cr({type:"request",data:{uuid:Q(),msg:r}},e)}function lr(r,e,t){return cr({type:"response",data:{uuid:r,resp:e}},t)}function cr(r,e){return e&&Wt(r,e),r}function ur(r){let e=new T(r.obj.message);return r.obj.name=="ErrnoError"?e.message=`ErrnoError: ${String(r.obj.errno)}`:r.obj.name!=="Error"&&(e.name=r.obj.name),e.stack=r.obj.stack,e}function bs(r){return!!r&&typeof r=="object"&&"payloadType"in r&&"obj"in r}function Je(r){return bs(r)&&r.payloadType==="ptr"}var ne=class{constructor(){this.inputQueue=new se;this.outputQueue=new se;this.systemQueue=new se;this.eventQueue=new Array;this.#e=new Map;this.#t=!1}#e;#t;async read(){return await this.outputQueue.get()}async flush(){let e=[];for(;!this.outputQueue.isEmpty();)e.push(await this.read());return e}async readSystem(){return await this.systemQueue.get()}write(e){if(this.#t)throw new S("The webR communication channel has been closed.");this.inputQueue.put(e)}async request(e,t){let s=wt(e,t),{resolve:n,reject:o,promise:a}=$();return this.#e.set(s.data.uuid,{resolve:n,reject:o}),this.write(s),a}putClosedMessage(){this.#t=!0,this.outputQueue.put({type:"closed"})}resolveResponse(e){let t=e.data.uuid,s=this.#e.get(t);if(s){let n=e.data.resp.data;this.#e.delete(t),n.payloadType==="err"?s.reject(ur(n)):s.resolve(n)}else console.warn("Can't find request.")}};var Eo=new TextDecoder("utf-8");var vo=new Int32Array(new ArrayBuffer(4));var He=class{constructor(e){this.chan=e;this.WebSocket=h?require("ws"):WebSocket}#e=new Map;new(e,t,s){let n=new this.WebSocket(t,s||[]);n.binaryType="arraybuffer",n.addEventListener("open",()=>{this.chan.emit({type:"websocket-open",data:{uuid:e}})}),n.addEventListener("message",o=>{let a=new Uint8Array(o.data);this.chan.emit({type:"websocket-message",data:{uuid:e,data:a}})}),n.addEventListener("close",o=>{this.chan.emit({type:"websocket-close",data:{uuid:e,code:o.code,reason:o.reason}})}),n.addEventListener("error",()=>{this.chan.emit({type:"websocket-error",data:{uuid:e}})}),this.#e.set(e,n)}send(e,t){this.#e