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