webr
Version:
The statistical programming language R compiled into WASM for use in a web browser and node.
1 lines • 66.5 kB
JavaScript
var Rs=Object.create;var gr=Object.defineProperty;var gs=Object.getOwnPropertyDescriptor;var bs=Object.getOwnPropertyNames;var ws=Object.getPrototypeOf,xs=Object.prototype.hasOwnProperty;var br=r=>{throw TypeError(r)};var ee=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var T=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Es=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of bs(e))!xs.call(r,n)&&n!==t&&gr(r,n,{get:()=>e[n],enumerable:!(s=gs(e,n))||s.enumerable});return r};var be=(r,e,t)=>(t=r!=null?Rs(ws(r)):{},Es(e||!r||!r.__esModule?gr(t,"default",{value:r,enumerable:!0}):t,r));var qt=(r,e,t)=>e.has(r)||br("Cannot "+t);var i=(r,e,t)=>(qt(r,e,"read from private field"),t?t.call(r):e.get(r)),p=(r,e,t)=>e.has(r)?br("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),m=(r,e,t,s)=>(qt(r,e,"write to private field"),s?s.call(r,t):e.set(r,t),t),M=(r,e,t)=>(qt(r,e,"access private method"),t);var De=T(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.getUint64=I.getInt64=I.setInt64=I.setUint64=I.UINT32_MAX=void 0;I.UINT32_MAX=4294967295;function ks(r,e,t){let s=t/4294967296,n=t;r.setUint32(e,s),r.setUint32(e+4,n)}I.setUint64=ks;function Ms(r,e,t){let s=Math.floor(t/4294967296),n=t;r.setUint32(e,s),r.setUint32(e+4,n)}I.setInt64=Ms;function Ws(r,e){let t=r.getInt32(e),s=r.getUint32(e+4);return t*4294967296+s}I.getInt64=Ws;function Ds(r,e){let t=r.getUint32(e),s=r.getUint32(e+4);return t*4294967296+s}I.getUint64=Ds});var ft=T(_=>{"use strict";var $t,Xt,Kt;Object.defineProperty(_,"__esModule",{value:!0});_.utf8DecodeTD=_.TEXT_DECODER_THRESHOLD=_.utf8DecodeJs=_.utf8EncodeTE=_.TEXT_ENCODER_THRESHOLD=_.utf8EncodeJs=_.utf8Count=void 0;var Ar=De(),yt=(typeof process>"u"||(($t=process==null?void 0:process.env)===null||$t===void 0?void 0:$t.TEXT_ENCODING)!=="never")&&typeof TextEncoder<"u"&&typeof TextDecoder<"u";function As(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}_.utf8Count=As;function Os(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 c=r.charCodeAt(o);(c&64512)===56320&&(++o,a=((a&1023)<<10)+(c&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}}_.utf8EncodeJs=Os;var Ae=yt?new TextEncoder:void 0;_.TEXT_ENCODER_THRESHOLD=yt?typeof process<"u"&&((Xt=process==null?void 0:process.env)===null||Xt===void 0?void 0:Xt.TEXT_ENCODING)!=="force"?200:0:Ar.UINT32_MAX;function Cs(r,e,t){e.set(Ae.encode(r),t)}function Is(r,e,t){Ae.encodeInto(r,e.subarray(t))}_.utf8EncodeTE=Ae!=null&&Ae.encodeInto?Is:Cs;var Us=4096;function Ns(r,e,t){let s=e,n=s+t,o=[],a="";for(;s<n;){let c=r[s++];if((c&128)===0)o.push(c);else if((c&224)===192){let u=r[s++]&63;o.push((c&31)<<6|u)}else if((c&240)===224){let u=r[s++]&63,k=r[s++]&63;o.push((c&31)<<12|u<<6|k)}else if((c&248)===240){let u=r[s++]&63,k=r[s++]&63,g=r[s++]&63,H=(c&7)<<18|u<<12|k<<6|g;H>65535&&(H-=65536,o.push(H>>>10&1023|55296),H=56320|H&1023),o.push(H)}else o.push(c);o.length>=Us&&(a+=String.fromCharCode(...o),o.length=0)}return o.length>0&&(a+=String.fromCharCode(...o)),a}_.utf8DecodeJs=Ns;var js=yt?new TextDecoder:null;_.TEXT_DECODER_THRESHOLD=yt?typeof process<"u"&&((Kt=process==null?void 0:process.env)===null||Kt===void 0?void 0:Kt.TEXT_DECODER)!=="force"?200:0:Ar.UINT32_MAX;function Bs(r,e,t){let s=r.subarray(e,e+t);return js.decode(s)}_.utf8DecodeTD=Bs});var Yt=T(mt=>{"use strict";Object.defineProperty(mt,"__esModule",{value:!0});mt.ExtData=void 0;var Qt=class{constructor(e,t){this.type=e,this.data=t}};mt.ExtData=Qt});var gt=T(Rt=>{"use strict";Object.defineProperty(Rt,"__esModule",{value:!0});Rt.DecodeError=void 0;var Zt=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})}};Rt.DecodeError=Zt});var er=T(P=>{"use strict";Object.defineProperty(P,"__esModule",{value:!0});P.timestampExtension=P.decodeTimestampExtension=P.decodeTimestampToTimeSpec=P.encodeTimestampExtension=P.encodeDateToTimeSpec=P.encodeTimeSpecToTimestamp=P.EXT_TIMESTAMP=void 0;var Ls=gt(),Or=De();P.EXT_TIMESTAMP=-1;var Fs=4294967296-1,qs=17179869184-1;function Cr({sec:r,nsec:e}){if(r>=0&&e>=0&&r<=qs)if(e===0&&r<=Fs){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,Or.setInt64)(s,4,r),t}}P.encodeTimeSpecToTimestamp=Cr;function Ir(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}}P.encodeDateToTimeSpec=Ir;function Ur(r){if(r instanceof Date){let e=Ir(r);return Cr(e)}else return null}P.encodeTimestampExtension=Ur;function Nr(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,Or.getInt64)(e,4),s=e.getUint32(0);return{sec:t,nsec:s}}default:throw new Ls.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${r.length}`)}}P.decodeTimestampToTimeSpec=Nr;function jr(r){let e=Nr(r);return new Date(e.sec*1e3+e.nsec/1e6)}P.decodeTimestampExtension=jr;P.timestampExtension={type:P.EXT_TIMESTAMP,encode:Ur,decode:jr}});var xt=T(wt=>{"use strict";Object.defineProperty(wt,"__esModule",{value:!0});wt.ExtensionCodec=void 0;var bt=Yt(),Vs=er(),Oe=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(Vs.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 bt.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 bt.ExtData(a,o)}}}return e instanceof bt.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 bt.ExtData(t,e)}};wt.ExtensionCodec=Oe;Oe.defaultCodec=new Oe});var tr=T(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});de.createDataView=de.ensureUint8Array=void 0;function Br(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)}de.ensureUint8Array=Br;function Js(r){if(r instanceof ArrayBuffer)return new DataView(r);let e=Br(r);return new DataView(e.buffer,e.byteOffset,e.byteLength)}de.createDataView=Js});var sr=T(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.Encoder=B.DEFAULT_INITIAL_BUFFER_SIZE=B.DEFAULT_MAX_DEPTH=void 0;var Ce=ft(),Hs=xt(),Lr=De(),zs=tr();B.DEFAULT_MAX_DEPTH=100;B.DEFAULT_INITIAL_BUFFER_SIZE=2048;var rr=class{constructor(e=Hs.ExtensionCodec.defaultCodec,t=void 0,s=B.DEFAULT_MAX_DEPTH,n=B.DEFAULT_INITIAL_BUFFER_SIZE,o=!1,a=!1,c=!1,u=!1){this.extensionCodec=e,this.context=t,this.maxDepth=s,this.initialBufferSize=n,this.sortKeys=o,this.forceFloat32=a,this.ignoreUndefined=c,this.forceIntegerToFloat=u,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>Ce.TEXT_ENCODER_THRESHOLD){let n=(0,Ce.utf8Count)(e);this.ensureBufferSizeToWrite(5+n),this.writeStringHeader(n),(0,Ce.utf8EncodeTE)(e,this.bytes,this.pos),this.pos+=n}else{let n=(0,Ce.utf8Count)(e);this.ensureBufferSizeToWrite(5+n),this.writeStringHeader(n),(0,Ce.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,zs.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,Lr.setUint64)(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),(0,Lr.setInt64)(this.view,this.pos,e),this.pos+=8}};B.Encoder=rr});var Fr=T(Et=>{"use strict";Object.defineProperty(Et,"__esModule",{value:!0});Et.encode=void 0;var Gs=sr(),$s={};function Xs(r,e=$s){return new Gs.Encoder(e.extensionCodec,e.context,e.maxDepth,e.initialBufferSize,e.sortKeys,e.forceFloat32,e.ignoreUndefined,e.forceIntegerToFloat).encodeSharedRef(r)}Et.encode=Xs});var qr=T(vt=>{"use strict";Object.defineProperty(vt,"__esModule",{value:!0});vt.prettyByte=void 0;function Ks(r){return`${r<0?"-":""}0x${Math.abs(r).toString(16).padStart(2,"0")}`}vt.prettyByte=Ks});var Vr=T(Pt=>{"use strict";Object.defineProperty(Pt,"__esModule",{value:!0});Pt.CachedKeyDecoder=void 0;var Qs=ft(),Ys=16,Zs=16,nr=class{constructor(e=Ys,t=Zs){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 c=0;c<s;c++)if(a[c]!==e[t+c])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,Qs.utf8DecodeJs)(e,t,s),a=Uint8Array.prototype.slice.call(e,t,t+s);return this.store(a,o),o}};Pt.CachedKeyDecoder=nr});var Tt=T($=>{"use strict";Object.defineProperty($,"__esModule",{value:!0});$.Decoder=$.DataViewIndexOutOfBoundsError=void 0;var or=qr(),en=xt(),oe=De(),ar=ft(),ir=tr(),tn=Vr(),G=gt(),rn=r=>{let e=typeof r;return e==="string"||e==="number"},Ie=-1,cr=new DataView(new ArrayBuffer(0)),sn=new Uint8Array(cr.buffer);$.DataViewIndexOutOfBoundsError=(()=>{try{cr.getInt8(0)}catch(r){return r.constructor}throw new Error("never reached")})();var Jr=new $.DataViewIndexOutOfBoundsError("Insufficient data"),nn=new tn.CachedKeyDecoder,lr=class{constructor(e=en.ExtensionCodec.defaultCodec,t=void 0,s=oe.UINT32_MAX,n=oe.UINT32_MAX,o=oe.UINT32_MAX,a=oe.UINT32_MAX,c=oe.UINT32_MAX,u=nn){this.extensionCodec=e,this.context=t,this.maxStrLength=s,this.maxBinLength=n,this.maxArrayLength=o,this.maxMapLength=a,this.maxExtLength=c,this.keyDecoder=u,this.totalPos=0,this.pos=0,this.view=cr,this.bytes=sn,this.headByte=Ie,this.stack=[]}reinitializeState(){this.totalPos=0,this.headByte=Ie,this.stack.length=0}setBuffer(e){this.bytes=(0,ir.ensureUint8Array)(e),this.view=(0,ir.createDataView)(this.bytes),this.pos=0}appendBuffer(e){if(this.headByte===Ie&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),s=(0,ir.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 c of e){if(t)throw this.createExtraByteError(this.totalPos);this.appendBuffer(c);try{s=this.doDecodeSync(),t=!0}catch(u){if(!(u instanceof $.DataViewIndexOutOfBoundsError))throw u}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,or.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 $.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 G.DecodeError(`Unrecognized type byte: ${(0,or.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(!rn(t))throw new G.DecodeError("The type of key must be string or number but "+typeof t);if(t==="__proto__")throw new G.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===Ie&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Ie}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 G.DecodeError(`Unrecognized array type byte: ${(0,or.prettyByte)(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new G.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 G.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 G.DecodeError(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw Jr;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>ar.TEXT_DECODER_THRESHOLD?o=(0,ar.utf8DecodeTD)(this.bytes,n,e):o=(0,ar.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 G.DecodeError(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw Jr;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 G.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,oe.getUint64)(this.view,this.pos);return this.pos+=8,e}readI64(){let e=(0,oe.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}};$.Decoder=lr});var ur=T(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.decodeMulti=L.decode=L.defaultDecodeOptions=void 0;var Hr=Tt();L.defaultDecodeOptions={};function on(r,e=L.defaultDecodeOptions){return new Hr.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decode(r)}L.decode=on;function an(r,e=L.defaultDecodeOptions){return new Hr.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeMulti(r)}L.decodeMulti=an});var $r=T(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.ensureAsyncIterable=Y.asyncIterableFromStream=Y.isAsyncIterable=void 0;function zr(r){return r[Symbol.asyncIterator]!=null}Y.isAsyncIterable=zr;function ln(r){if(r==null)throw new Error("Assertion Failure: value must not be null nor undefined")}async function*Gr(r){let e=r.getReader();try{for(;;){let{done:t,value:s}=await e.read();if(t)return;ln(s),yield s}}finally{e.releaseLock()}}Y.asyncIterableFromStream=Gr;function cn(r){return zr(r)?r:Gr(r)}Y.ensureAsyncIterable=cn});var Kr=T(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.decodeStream=F.decodeMultiStream=F.decodeArrayStream=F.decodeAsync=void 0;var pr=Tt(),dr=$r(),St=ur();async function un(r,e=St.defaultDecodeOptions){let t=(0,dr.ensureAsyncIterable)(r);return new pr.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeAsync(t)}F.decodeAsync=un;function pn(r,e=St.defaultDecodeOptions){let t=(0,dr.ensureAsyncIterable)(r);return new pr.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeArrayStream(t)}F.decodeArrayStream=pn;function Xr(r,e=St.defaultDecodeOptions){let t=(0,dr.ensureAsyncIterable)(r);return new pr.Decoder(e.extensionCodec,e.context,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength).decodeStream(t)}F.decodeMultiStream=Xr;function dn(r,e=St.defaultDecodeOptions){return Xr(r,e)}F.decodeStream=dn});var Zr=T(d=>{"use strict";Object.defineProperty(d,"__esModule",{value:!0});d.decodeTimestampExtension=d.encodeTimestampExtension=d.decodeTimestampToTimeSpec=d.encodeTimeSpecToTimestamp=d.encodeDateToTimeSpec=d.EXT_TIMESTAMP=d.ExtData=d.ExtensionCodec=d.Encoder=d.DataViewIndexOutOfBoundsError=d.DecodeError=d.Decoder=d.decodeStream=d.decodeMultiStream=d.decodeArrayStream=d.decodeAsync=d.decodeMulti=d.decode=d.encode=void 0;var hn=Fr();Object.defineProperty(d,"encode",{enumerable:!0,get:function(){return hn.encode}});var Qr=ur();Object.defineProperty(d,"decode",{enumerable:!0,get:function(){return Qr.decode}});Object.defineProperty(d,"decodeMulti",{enumerable:!0,get:function(){return Qr.decodeMulti}});var _t=Kr();Object.defineProperty(d,"decodeAsync",{enumerable:!0,get:function(){return _t.decodeAsync}});Object.defineProperty(d,"decodeArrayStream",{enumerable:!0,get:function(){return _t.decodeArrayStream}});Object.defineProperty(d,"decodeMultiStream",{enumerable:!0,get:function(){return _t.decodeMultiStream}});Object.defineProperty(d,"decodeStream",{enumerable:!0,get:function(){return _t.decodeStream}});var Yr=Tt();Object.defineProperty(d,"Decoder",{enumerable:!0,get:function(){return Yr.Decoder}});Object.defineProperty(d,"DataViewIndexOutOfBoundsError",{enumerable:!0,get:function(){return Yr.DataViewIndexOutOfBoundsError}});var yn=gt();Object.defineProperty(d,"DecodeError",{enumerable:!0,get:function(){return yn.DecodeError}});var fn=sr();Object.defineProperty(d,"Encoder",{enumerable:!0,get:function(){return fn.Encoder}});var mn=xt();Object.defineProperty(d,"ExtensionCodec",{enumerable:!0,get:function(){return mn.ExtensionCodec}});var Rn=Yt();Object.defineProperty(d,"ExtData",{enumerable:!0,get:function(){return Rn.ExtData}});var he=er();Object.defineProperty(d,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return he.EXT_TIMESTAMP}});Object.defineProperty(d,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return he.encodeDateToTimeSpec}});Object.defineProperty(d,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return he.encodeTimeSpecToTimestamp}});Object.defineProperty(d,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return he.decodeTimestampToTimeSpec}});Object.defineProperty(d,"encodeTimestampExtension",{enumerable:!0,get:function(){return he.encodeTimestampExtension}});Object.defineProperty(d,"decodeTimestampExtension",{enumerable:!0,get:function(){return he.decodeTimestampExtension}})});var D=class extends Error{constructor(e){super(e),this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}},A=class extends D{},O=class extends D{},X=class extends D{};var E=typeof process<"u"&&process.release&&process.release.name==="node",Vt;if(globalThis.document)Vt=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)Vt=async r=>{try{globalThis.importScripts(r)}catch(e){if(e instanceof TypeError)await Promise.resolve().then(()=>be(ee(r)));else throw e}};else if(E)Vt=async r=>{let e=(await Promise.resolve().then(()=>be(ee("path")))).default;await Promise.resolve().then(()=>be(ee(e.resolve(r))))};else throw new D("Cannot determine runtime environment");var U={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 we(r){return!!r&&typeof r=="object"&&Object.keys(U).includes(r.type)}function te(r){return!!r&&typeof r=="object"&&"re"in r&&"im"in r}var l={};function wr(r){Object.keys(r).forEach(e=>l._free(r[e]))}function xe(r){return l._Rf_protect(N(r)),r}function b(r,e){return l._Rf_protect(N(r)),++e.n,r}function xr(r){let e=l._malloc(4);return l._R_ProtectWithIndex(N(r),e),{loc:l.getValue(e,"i32"),ptr:e}}function Er(r){l._Rf_unprotect(1),l._free(r.ptr)}function vr(r,e){return l._R_Reprotect(N(r),e.loc),r}function v(r){l._Rf_unprotect(r)}function Jt(r,e,t){l._Rf_defineVar(N(e),N(t),N(r))}function Ht(r,e){let t={},s={n:0};try{let n=new ve(e);b(n,s),t.code=l.allocateUTF8(r);let o=l._R_ParseEvalString(t.code,n.ptr);return h.wrap(o)}finally{wr(t),v(s.n)}}function Ee(r,e){return l.getWasmTableEntry(l.GOT.ffi_safe_eval.value)(N(r),N(e))}var vs=new WeakMap;function Pr(r,e){return vs.set(r,e),r}function Tr(r){return typeof r=="string"&&r.length===zt}var zt=63;function Pe(){let r=Array.from({length:4},Ps).join("-");if(r.length!==zt)throw new Error("comlink internal error: UUID has the wrong length");return r}function Ps(){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 N(r){return Ye(r)?r.ptr:r}function ne(r,e){if(l._TYPEOF(r.ptr)!==U[e])throw new Error(`Unexpected object type "${r.type()}" when expecting type "${e}"`)}function Sr(r){if(we(r))return new(_r(r.type))(r);if(typeof r>"u")return new Te;if(r&&typeof r=="object"&&"type"in r&&r.type==="null")return new Te;if(r===null)return new se({type:"logical",names:null,values:[null]});if(typeof r=="boolean")return new se(r);if(typeof r=="number")return new We(r);if(typeof r=="string")return new z(r);if(te(r))return new Ke(r);if(ArrayBuffer.isView(r)||r instanceof ArrayBuffer)return new Qe(r);if(Array.isArray(r))return Ts(r);if(typeof r=="object")return ke.fromObject(r);throw new Error("R object construction for this JS object is not yet supported.")}function Ts(r){let e={n:0};if(r.every(s=>s&&typeof s=="object"&&!Ye(s)&&!te(s))){let s=r,n=s.every(a=>Object.keys(a).filter(c=>!Object.keys(s[0]).includes(c)).length===0&&Object.keys(s[0]).filter(c=>!Object.keys(a).includes(c)).length===0),o=s.every(a=>Object.values(a).every(c=>Mr(c)||kr(c)));if(n&&o)return ke.fromD3(s)}if(r.every(s=>typeof s=="boolean"||s===null))return new se(r);if(r.every(s=>typeof s=="number"||s===null))return new We(r);if(r.every(s=>typeof s=="string"||s===null))return new z(r);try{let s=new K([new C("c"),...r]);return b(s,e),s.eval()}finally{v(e.n)}}var w=class{constructor(e){this.ptr=e}type(){let e=l._TYPEOF(this.ptr);return Object.keys(U).find(s=>U[s]===e)}},ce,Xe,re=class re extends w{constructor(t){if(!(t instanceof w))return Sr(t);super(t.ptr);p(this,ce)}static wrap(t){let s=l._TYPEOF(t),n=Object.keys(U)[Object.values(U).indexOf(s)];return new(_r(n))(new w(t))}get[Symbol.toStringTag](){return`RObject:${this.type()}`}static getPersistentObject(t){return S[t]}getPropertyValue(t){return this[t]}inspect(){Ht(".Internal(inspect(x))",{x:this})}isNull(){return l._TYPEOF(this.ptr)===U.null}isNa(){try{let t=Ht("is.na(x)",{x:this});return xe(t),t.toBoolean()}finally{v(1)}}isUnbound(){return this.ptr===S.unboundValue.ptr}attrs(){return Se.wrap(l._ATTRIB(this.ptr))}class(){let t={n:0},s=new K([new C("class"),this]);b(s,t);try{return s.eval()}finally{v(t.n)}}setNames(t){let s;if(t===null)s=S.null;else if(Array.isArray(t)&&t.every(n=>typeof n=="string"||n===null))s=new z(t);else throw new Error("Argument to setNames must be null or an Array of strings or null");return l._Rf_setAttrib(this.ptr,S.namesSymbol.ptr,s.ptr),this}names(){let t=z.wrap(l._Rf_getAttrib(this.ptr,S.namesSymbol.ptr));return t.isNull()?null:t.toArray()}includes(t){let s=this.names();return s&&s.includes(t)}toJs(t={depth:0},s=1){throw new Error("This R object cannot be converted to JS")}subset(t){return M(this,ce,Xe).call(this,t,S.bracketSymbol.ptr)}get(t){return M(this,ce,Xe).call(this,t,S.bracket2Symbol.ptr)}getDollar(t){return M(this,ce,Xe).call(this,t,S.dollarSymbol.ptr)}pluck(...t){let s=xr(S.null);try{let n=(a,c)=>{let u=a.get(c);return vr(u,s)},o=t.reduce(n,this);return o.isNull()?void 0:o}finally{Er(s)}}set(t,s){let n={n:0};try{let o=new re(t);b(o,n);let a=new re(s);b(a,n);let c=new C("[[<-"),u=l._Rf_lang4(c.ptr,this.ptr,o.ptr,a.ptr);return b(u,n),re.wrap(Ee(u,S.baseEnv))}finally{v(n.n)}}static getMethods(t){let s=new Set,n=t;do Object.getOwnPropertyNames(n).map(o=>s.add(o));while(n=Object.getPrototypeOf(n));return[...s.keys()].filter(o=>typeof t[o]=="function")}};ce=new WeakSet,Xe=function(t,s){let n={n:0};try{let o=new re(t);b(o,n);let a=l._Rf_lang3(s,this.ptr,o.ptr);return b(a,n),re.wrap(Ee(a,S.baseEnv))}finally{v(n.n)}};var h=re,Te=class extends h{constructor(){return super(new w(l.getValue(l._R_NilValue,"*"))),this}toJs(){return{type:"null"}}},C=class extends h{constructor(e){if(e instanceof w){ne(e,"symbol"),super(e);return}let t=l.allocateUTF8(e);try{super(new w(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 Me.wrap(l._PRINTNAME(this.ptr))}symvalue(){return h.wrap(l._SYMVALUE(this.ptr))}internal(){return h.wrap(l._INTERNAL(this.ptr))}},Se=class r extends h{constructor(e){if(e instanceof w)return ne(e,"pairlist"),super(e),this;let t={n:0};try{let{names:s,values:n}=ue(e),o=r.wrap(l._Rf_allocList(n.length));b(o,t);for(let[a,c]=[0,o];!c.isNull();[a,c]=[a+1,c.cdr()])c.setcar(new h(n[a]));o.setNames(s),super(o)}finally{v(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,c)=>n.findIndex(u=>u[0]===a[0])===c))}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 c=this;!c.isNull();c=c.cdr()){let u=c.tag();u.isNull()?s.push(""):(n=!0,s.push(u.toString())),e.depth&&t>=e.depth?o.push(c.car()):o.push(c.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 h.wrap(l._CAR(this.ptr))}cdr(){return h.wrap(l._CDR(this.ptr))}tag(){return h.wrap(l._TAG(this.ptr))}},K=class r extends h{constructor(e){if(e instanceof w)return ne(e,"call"),super(e),this;let t={n:0};try{let{values:s}=ue(e),n=s.map(a=>b(new h(a),t)),o=r.wrap(l._Rf_allocVector(U.call,s.length));b(o,t);for(let[a,c]=[0,o];!c.isNull();[a,c]=[a+1,c.cdr()])c.setcar(n[a]);super(o)}finally{v(t.n)}}setcar(e){l._SETCAR(this.ptr,e.ptr)}car(){return h.wrap(l._CAR(this.ptr))}cdr(){return h.wrap(l._CDR(this.ptr))}eval(){return l.webr.evalR(this,{env:S.baseEnv})}capture(e={}){return l.webr.captureR(this,e)}deparse(){let e={n:0};try{let t=l._Rf_lang2(new C("deparse1").ptr,l._Rf_lang2(new C("quote").ptr,this.ptr));b(t,e);let s=z.wrap(Ee(t,S.baseEnv));return b(s,e),s.toString()}finally{v(e.n)}}},_e=class r extends h{constructor(e,t=null){if(e instanceof w){if(ne(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=ue(e),o=l._Rf_allocVector(U.list,n.values.length);b(o,s),n.values.forEach((c,u)=>{Wr(c)?l._SET_VECTOR_ELT(o,u,new r(c).ptr):l._SET_VECTOR_ELT(o,u,new h(c).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.");h.wrap(o).setNames(a),super(new w(o))}finally{v(s.n)}}get length(){return l._LENGTH(this.ptr)}isDataFrame(){let e=Se.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,c)=>n.findIndex(u=>u[0]===a[0])===c))}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))}}},ke=class r extends _e{constructor(e){if(e instanceof w){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}=ue(e),n={n:0};try{let o=!!t&&t.length>0&&t.every(c=>c),a=s.length>0&&s.every(c=>Array.isArray(c)||ArrayBuffer.isView(c)||c instanceof ArrayBuffer);if(o&&a){let c=s,u=c.every(g=>g.length===c[0].length),k=c.every(g=>Mr(g[0])||kr(g[0]));if(u&&k){let g=new _e({type:"list",names:t,values:c.map(ms=>Sr(ms))});b(g,n);let H=new K([new C("as.data.frame"),g]);return b(H,n),new r(H.eval())}}}finally{v(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])])))}},le=class extends h{exec(...e){let t={n:0};try{let s=new K([this,...e]);return b(s,t),s.eval()}finally{v(t.n)}}capture(e={},...t){let s={n:0};try{let n=new K([this,...t]);return b(n,s),n.capture(e)}finally{v(s.n)}}},Ze=class Ze extends h{constructor(e){if(e instanceof w){ne(e,"string"),super(e);return}let t=l.allocateUTF8(e);try{super(new w(l._Rf_mkCharCE(t,Ze.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()}}};Ze.CEType={CE_NATIVE:0,CE_UTF8:1,CE_LATIN1:2,CE_BYTES:3,CE_SYMBOL:5,CE_ANY:99};var Me=Ze,ve=class extends h{constructor(e={}){if(e instanceof w)return ne(e,"environment"),super(e),this;let t=0;try{let{names:s,values:n}=ue(e),o=xe(l._R_NewEnv(S.globalEnv.ptr,0,0));++t,n.forEach((a,c)=>{let u=s?s[c]:null;if(!u)throw new Error("Can't create object in new environment with empty symbol name");let k=new C(u),g=xe(new h(a));try{Jt(o,k,g)}finally{v(1)}}),super(new w(o))}finally{v(t)}}ls(e=!1,t=!0){return z.wrap(l._R_lsInternal3(this.ptr,Number(e),Number(t))).toArray()}bind(e,t){let s=new C(e),n=xe(new h(t));try{Jt(this,s,n)}finally{v(1)}}names(){return this.ls(!0,!0)}frame(){return h.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 h{constructor(e,t,s){if(e instanceof w)return ne(e,t),super(e),this;let n={n:0};try{let{names:o,values:a}=ue(e),c=l._Rf_allocVector(U[t],a.length);b(c,n),a.forEach(s(c)),h.wrap(c).setNames(o),super(new w(c))}finally{v(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 C("is.na").ptr,this.ptr);b(t,e);let s=se.wrap(Ee(t,S.baseEnv));b(s,e);let n=s.toTypedArray();return Array.from(n).map(o=>!!o)}finally{v(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(c=>c[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()}}},et,tt=class tt extends Q{constructor(e){super(e,"logical",i(tt,et))}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])}};et=new WeakMap,p(tt,et,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")}});var se=tt,rt,st=class st extends Q{constructor(e){super(e,"integer",i(st,rt))}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))}};rt=new WeakMap,p(st,rt,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")}});var Gt=st,nt,ot=class ot extends Q{constructor(e){super(e,"double",i(ot,nt))}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))}};nt=new WeakMap,p(ot,nt,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")}});var We=ot,at,it=class it extends Q{constructor(e){super(e,"complex",i(it,at))}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]})}};at=new WeakMap,p(it,at,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")}});var Ke=it,lt,ct=class ct extends Q{constructor(e){super(e,"character",i(ct,lt))}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)}}};lt=new WeakMap,p(ct,lt,e=>(t,s)=>{t===null?l._SET_STRING_ELT(e,s,S.naString.ptr):l._SET_STRING_ELT(e,s,new Me(t).ptr)});var z=ct,ut,pt=class pt extends Q{constructor(e){e instanceof ArrayBuffer&&(e=new Uint8Array(e)),super(e,"raw",i(pt,ut))}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))}};ut=new WeakMap,p(pt,ut,e=>{let t=l._RAW(e);return(s,n)=>{l.setValue(t+n,Number(s),"i8")}});var Qe=pt;function ue(r){return we(r)?r:Array.isArray(r)||ArrayBuffer.isView(r)?{names:null,values:r}:r&&typeof r=="object"&&!te(r)?{names:Object.keys(r),values:Object.values(r)}:{names:null,values:[r]}}function _r(r){let e={object:h,null:Te,symbol:C,pairlist:Se,closure:le,environment:ve,call:K,special:le,builtin:le,string:Me,logical:se,integer:Gt,double:We,complex:Ke,character:z,list:_e,raw:Qe,function:le,dataframe:ke};return r in e?e[r]:h}function Ye(r){return r instanceof h}function kr(r){let e=["logical","integer","double","complex","character"];return Ye(r)&&e.includes(r.type())||Ye(r)&&r.isNa()}function Mr(r){return r===null||typeof r=="number"||typeof r=="boolean"||typeof r=="string"||te(r)}var S;function pe(){let r={resolve:()=>{},reject:()=>{},promise:Promise.resolve()},e=new Promise((t,s)=>{r.resolve=t,r.reject=s});return r.promise=e,r}function Dr(r){return new Promise(e=>setTimeout(e,r))}function j(r,e,t,...s){return r==null||_s(r)?r:r instanceof ArrayBuffer?new Uint8Array(r):e(r)?t(r,...s):Array.isArray(r)||ArrayBuffer.isView(r)?r.map(n=>j(n,e,t,...s)):r instanceof w?r:typeof r=="object"?Object.fromEntries(Object.entries(r).map(([n,o])=>[n,j(o,e,t,...s)])):r}function dt(r,e,t){let s=new XMLHttpRequest;s.open("get",r,!0),s.onload=()=>{if(s.status>=200&&s.status<300)try{let n=new Worker(URL.createObjectURL(new Blob([s.responseText])));e(n)}catch(n){if(t)t(n instanceof Error?n:new Error(String(n)));else throw n}else t?t(new Error(`Worker loading error: HTTP ${s.status}`)):console.error(`HTTP Error: ${s.status}`)},s.onerror=()=>{t?t(new Error(`Network error loading ${r}`)):console.error(`Network error loading ${r}`)},s.send()}function ht(r){if(E)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 _s(r){return typeof ImageBitmap<"u"&&r instanceof ImageBitmap}function Wr(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)&&!ArrayBuffer.isView(r)&&!te(r)&&!we(r)&&!(r instanceof Date)&&!(r instanceof RegExp)&&!(r instanceof Error)&&!(r instanceof w)&&Object.getPrototypeOf(r)===Object.prototype}var rs=be(Zr());var gn=new TextEncoder;async function kt(r,e,t){try{let{taskId:s,sizeBuffer:n,dataBuffer:o,signalBuffer:a}=e,c=(0,rs.encode)(t),u=c.length<=o.length;if(Atomics.store(n,0,c.length),Atomics.store(n,1,+u),!u){let[k,g]=bn(r);o.set(gn.encode(k)),await es(a,s),o=(await g).dataBuffer}o.set(c),Atomics.store(n,1,1),await es(a,s)}catch(s){console.warn(s)}}function bn(r){let e=Pe();return[e,new Promise(t=>{E?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 es(r,e){let t=(e>>1)%32,s=1;for(;Atomics.compareExchange(r,t+1,0,e)!==0;)await Dr(s),s<32&&(s*=2);Atomics.or(r,0,1<<t),Atomics.notify(r,0)}var q,V,Ue,yr,ye=class{constructor(){p(this,Ue);p(this,q);p(this,V);m(this,V,[]),m(this,q,[])}reset(){m(this,V,[]),m(this,q,[])}put(e){i(this,V).length||M(this,Ue,yr).call(this),i(this,V).shift()(e)}async get(){return i(this,q).length||M(this,Ue,yr).call(this),i(this,q).shift()}isEmpty(){return!i(this,q).length}isBlocked(){return!!i(this,V).length}get length(){return i(this,q).length-i(this,V).length}};q=new WeakMap,V=new WeakMap,Ue=new WeakSet,yr=function(){i(this,q).push(new Promise(e=>{i(this,V).push(e)}))};function fr(r,e){return ns({type:"request",data:{uuid:Pe(),msg:r}},e)}function ss(r,e,t){return ns({type:"response",data:{uuid:r,resp:e}},t)}function ns(r,e){return e&&Pr(r,e),r}function os(r){let e=new A(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 wn(r){return!!r&&typeof r=="object"&&"payloadType"in r&&"obj"in r}function Mt(r){return wn(r)&&r.payloadType==="ptr"}var fe,Ne,me=class{constructor(){this.inputQueue=new ye;this.outputQueue=new ye;this.systemQueue=new ye;this.eventQueue=new Array;p(this,fe,new Map);p(this,Ne,!1)}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(i(this,Ne))throw new O("The webR communication channel has been closed.");this.inputQueue.put(e)}async request(e,t){let s=fr(e,t),{resolve:n,reject:o,promise:a}=pe();return i(this,fe).set(s.data.uuid,{resolve:n,reject:o}),this.write(s),a}putClosedMessage(){m(this,Ne,!0),this.outputQueue.put({type:"closed"})}resolveResponse(e){let t=e.data.uuid,s=i(this,fe).get(t);if(s){let n=e.data.resp.data;i(this,fe).delete(t),n.payloadType==="err"?s.reject(os(n)):s.resolve(n)}else console.warn("Can't find request.")}};fe=new W