=31||typeof navigator<"u"&&((i=navigator.userAgent)==null?void 0:i.toLowerCase().match(/applewebkit\/(\d+)/))}function ts(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+zn(this.diff),!this.useColors)return;const e="color: "+this.color;t.splice(1,0,e,"color: inherit");let n=0,r=0;t[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(n++,i==="%c"&&(r=n))}),t.splice(r,0,e)}const ns=console.debug??console.log??(()=>{});function rs(t){try{t?Y==null||Y.setItem("debug",t):Y==null||Y.removeItem("debug")}catch{}}function is(){let t;try{t=Y==null?void 0:Y.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=Qi.DEBUG),t}function ss(){try{return localStorage}catch{}}function os(t){t.j=function(e){try{return JSON.stringify(e)}catch(n){return"[UnexpectedJSONParseError]: "+n.message}}}const J=Zi({formatArgs:ts,save:rs,load:is,useColors:es,setupFormatters:os,colors:Yi,storage:Y,log:ns});J.formatters.b=t=>t==null?"undefined":kr.baseEncode(t);J.formatters.t=t=>t==null?"undefined":Ar.baseEncode(t);J.formatters.m=t=>t==null?"undefined":Ht.baseEncode(t);J.formatters.p=t=>t==null?"undefined":t.toString();J.formatters.c=t=>t==null?"undefined":t.toString();J.formatters.k=t=>t==null?"undefined":t.toString();J.formatters.a=t=>t==null?"undefined":t.toString();function as(t){const e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function Pa(){return{forComponent(t){return us(t)}}}function us(t){let e=as(`${t}:trace`);return J.enabled(`${t}:trace`)&&J.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(e=J(`${t}:trace`)),Object.assign(J(t),{error:J(`${t}:error`),trace:e})}var Mn={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(d,g,h){this.fn=d,this.context=g,this.once=h||!1}function s(d,g,h,l,E){if(typeof h!="function")throw new TypeError("The listener must be a function");var _=new i(h,l||d,E),N=n?n+g:g;return d._events[N]?d._events[N].fn?d._events[N]=[d._events[N],_]:d._events[N].push(_):(d._events[N]=_,d._eventsCount++),d}function o(d,g){--d._eventsCount===0?d._events=new r:delete d._events[g]}function u(){this._events=new r,this._eventsCount=0}u.prototype.eventNames=function(){var g=[],h,l;if(this._eventsCount===0)return g;for(l in h=this._events)e.call(h,l)&&g.push(n?l.slice(1):l);return Object.getOwnPropertySymbols?g.concat(Object.getOwnPropertySymbols(h)):g},u.prototype.listeners=function(g){var h=n?n+g:g,l=this._events[h];if(!l)return[];if(l.fn)return[l.fn];for(var E=0,_=l.length,N=new Array(_);E<_;E++)N[E]=l[E].fn;return N},u.prototype.listenerCount=function(g){var h=n?n+g:g,l=this._events[h];return l?l.fn?1:l.length:0},u.prototype.emit=function(g,h,l,E,_,N){var a=n?n+g:g;if(!this._events[a])return!1;var c=this._events[a],p=arguments.length,D,w;if(c.fn){switch(c.once&&this.removeListener(g,c.fn,void 0,!0),p){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,h),!0;case 3:return c.fn.call(c.context,h,l),!0;case 4:return c.fn.call(c.context,h,l,E),!0;case 5:return c.fn.call(c.context,h,l,E,_),!0;case 6:return c.fn.call(c.context,h,l,E,_,N),!0}for(w=1,D=new Array(p-1);we.major?1:0}}f.uint=new f(0,"uint",!0);f.negint=new f(1,"negint",!0);f.bytes=new f(2,"bytes",!0);f.string=new f(3,"string",!0);f.array=new f(4,"array",!1);f.map=new f(5,"map",!1);f.tag=new f(6,"tag",!1);f.float=new f(7,"float",!0);f.false=new f(7,"false",!0);f.true=new f(7,"true",!0);f.null=new f(7,"null",!0);f.undefined=new f(7,"undefined",!0);f.break=new f(7,"break",!0);class m{constructor(e,n,r){this.type=e,this.value=n,this.encodedLength=r,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}}const $e=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",gs=new TextDecoder,ys=new TextEncoder;function ht(t){return $e&&globalThis.Buffer.isBuffer(t)}function qt(t){return t instanceof Uint8Array?ht(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}const ms=$e?(t,e,n)=>n-e>64?globalThis.Buffer.from(t.subarray(e,n)).toString("utf8"):wn(t,e,n):(t,e,n)=>n-e>64?gs.decode(t.subarray(e,n)):wn(t,e,n),jn=$e?t=>t.length>64?globalThis.Buffer.from(t):pn(t):t=>t.length>64?ys.encode(t):pn(t),ne=t=>Uint8Array.from(t),Wt=$e?(t,e,n)=>ht(t)?new Uint8Array(t.subarray(e,n)):t.slice(e,n):(t,e,n)=>t.slice(e,n),bs=$e?(t,e)=>(t=t.map(n=>n instanceof Uint8Array?n:globalThis.Buffer.from(n)),qt(globalThis.Buffer.concat(t,e))):(t,e)=>{const n=new Uint8Array(e);let r=0;for(let i of t)r+i.length>n.length&&(i=i.subarray(0,n.length-r)),n.set(i,r),r+=i.length;return n},xs=$e?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Es(t,e){if(ht(t)&&ht(e))return t.compare(e);for(let n=0;n>6|192,e[n++]=i&63|128):(i&64512)===55296&&r+1>18|240,e[n++]=i>>12&63|128,e[n++]=i>>6&63|128,e[n++]=i&63|128):(e[n++]=i>>12|224,e[n++]=i>>6&63|128,e[n++]=i&63|128)}return e}function wn(t,e,n){const r=[];for(;e239?4:i>223?3:i>191?2:1;if(e+o<=n){let u,d,g,h;switch(o){case 1:i<128&&(s=i);break;case 2:u=t[e+1],(u&192)===128&&(h=(i&31)<<6|u&63,h>127&&(s=h));break;case 3:u=t[e+1],d=t[e+2],(u&192)===128&&(d&192)===128&&(h=(i&15)<<12|(u&63)<<6|d&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:u=t[e+1],d=t[e+2],g=t[e+3],(u&192)===128&&(d&192)===128&&(g&192)===128&&(h=(i&15)<<18|(u&63)<<12|(d&63)<<6|g&63,h>65535&&h<1114112&&(s=h))}}s===null?(s=65533,o=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),e+=o}return Rn(r)}const gn=4096;function Rn(t){const e=t.length;if(e<=gn)return String.fromCharCode.apply(String,t);let n="",r=0;for(;rr.length/2?(n=this.cursor===r.length?r:r.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):n=Wt(r,0,this.cursor)}else n=bs(this.chunks,this.cursor);return e&&this.reset(),n}}const C="CBOR decode error:",lt="CBOR encode error:";function Fe(t,e,n){if(t.length-e>>8,r&255])}else if(n>>24&255,r>>>16&255,r>>>8&255,r&255])}else{const r=BigInt(n);if(r>BigInt(32)&BigInt(4294967295));i[8]=s&255,s=s>>8,i[7]=s&255,s=s>>8,i[6]=s&255,s=s>>8,i[5]=s&255,i[4]=o&255,o=o>>8,i[3]=o&255,o=o>>8,i[2]=o&255,o=o>>8,i[1]=o&255,t.push(i)}else throw new Error(`${C} encountered BigInt larger than allowable range`)}}be.encodedSize=function(e){return K.encodedSize(e.value)};K.encodedSize=function(e){return en.value?1:0};function vs(t,e,n,r){return new m(f.negint,-1-we(t,e+1,r),2)}function Ns(t,e,n,r){return new m(f.negint,-1-ge(t,e+1,r),3)}function Ts(t,e,n,r){return new m(f.negint,-1-ye(t,e+1,r),5)}const Xt=BigInt(-1),Hn=BigInt(1);function Ss(t,e,n,r){const i=me(t,e+1,r);if(typeof i!="bigint"){const s=-1-i;if(s>=Number.MIN_SAFE_INTEGER)return new m(f.negint,s,9)}if(r.allowBigInt!==!0)throw new Error(`${C} integers outside of the safe integer range are not supported`);return new m(f.negint,Xt-BigInt(i),9)}function Jt(t,e){const n=e.value,r=typeof n=="bigint"?n*Xt-Hn:n*-1-1;K(t,e.type.majorEncoded,r)}Jt.encodedSize=function(e){const n=e.value,r=typeof n=="bigint"?n*Xt-Hn:n*-1-1;return rn.value?-1:0};function Je(t,e,n,r){Fe(t,e,n+r);const i=Wt(t,e+n,e+n+r);return new m(f.bytes,i,n+r)}function $s(t,e,n,r){return Je(t,e,1,n)}function Fs(t,e,n,r){return Je(t,e,2,we(t,e+1,r))}function Bs(t,e,n,r){return Je(t,e,3,ge(t,e+1,r))}function Ls(t,e,n,r){return Je(t,e,5,ye(t,e+1,r))}function Ds(t,e,n,r){const i=me(t,e+1,r);if(typeof i=="bigint")throw new Error(`${C} 64-bit integer bytes lengths not supported`);return Je(t,e,9,i)}function dt(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===f.string?jn(t.value):t.value),t.encodedBytes}function bt(t,e){const n=dt(e);K(t,e.type.majorEncoded,n.length),t.push(n)}bt.encodedSize=function(e){const n=dt(e);return K.encodedSize(n.length)+n.length};bt.compareTokens=function(e,n){return Us(dt(e),dt(n))};function Us(t,e){return t.lengthe.length?1:Es(t,e)}function Ke(t,e,n,r,i){const s=n+r;Fe(t,e,s);const o=new m(f.string,ms(t,e+n,e+s),s);return i.retainStringBytes===!0&&(o.byteValue=Wt(t,e+n,e+s)),o}function Os(t,e,n,r){return Ke(t,e,1,n,r)}function Ps(t,e,n,r){return Ke(t,e,2,we(t,e+1,r),r)}function zs(t,e,n,r){return Ke(t,e,3,ge(t,e+1,r),r)}function Ms(t,e,n,r){return Ke(t,e,5,ye(t,e+1,r),r)}function js(t,e,n,r){const i=me(t,e+1,r);if(typeof i=="bigint")throw new Error(`${C} 64-bit integer string lengths not supported`);return Ke(t,e,9,i,r)}const Rs=bt;function Be(t,e,n,r){return new m(f.array,r,n)}function Vs(t,e,n,r){return Be(t,e,1,n)}function Hs(t,e,n,r){return Be(t,e,2,we(t,e+1,r))}function Gs(t,e,n,r){return Be(t,e,3,ge(t,e+1,r))}function qs(t,e,n,r){return Be(t,e,5,ye(t,e+1,r))}function Ws(t,e,n,r){const i=me(t,e+1,r);if(typeof i=="bigint")throw new Error(`${C} 64-bit integer array lengths not supported`);return Be(t,e,9,i)}function Xs(t,e,n,r){if(r.allowIndefinite===!1)throw new Error(`${C} indefinite length items not allowed`);return Be(t,e,1,1/0)}function Kt(t,e){K(t,f.array.majorEncoded,e.value)}Kt.compareTokens=be.compareTokens;Kt.encodedSize=function(e){return K.encodedSize(e.value)};function Le(t,e,n,r){return new m(f.map,r,n)}function Js(t,e,n,r){return Le(t,e,1,n)}function Ks(t,e,n,r){return Le(t,e,2,we(t,e+1,r))}function Zs(t,e,n,r){return Le(t,e,3,ge(t,e+1,r))}function Qs(t,e,n,r){return Le(t,e,5,ye(t,e+1,r))}function Ys(t,e,n,r){const i=me(t,e+1,r);if(typeof i=="bigint")throw new Error(`${C} 64-bit integer map lengths not supported`);return Le(t,e,9,i)}function eo(t,e,n,r){if(r.allowIndefinite===!1)throw new Error(`${C} indefinite length items not allowed`);return Le(t,e,1,1/0)}function Zt(t,e){K(t,f.map.majorEncoded,e.value)}Zt.compareTokens=be.compareTokens;Zt.encodedSize=function(e){return K.encodedSize(e.value)};function to(t,e,n,r){return new m(f.tag,n,1)}function no(t,e,n,r){return new m(f.tag,we(t,e+1,r),2)}function ro(t,e,n,r){return new m(f.tag,ge(t,e+1,r),3)}function io(t,e,n,r){return new m(f.tag,ye(t,e+1,r),5)}function so(t,e,n,r){return new m(f.tag,me(t,e+1,r),9)}function Qt(t,e){K(t,f.tag.majorEncoded,e.value)}Qt.compareTokens=be.compareTokens;Qt.encodedSize=function(e){return K.encodedSize(e.value)};const oo=20,ao=21,uo=22,co=23;function fo(t,e,n,r){if(r.allowUndefined===!1)throw new Error(`${C} undefined values are not supported`);return r.coerceUndefinedToNull===!0?new m(f.null,null,1):new m(f.undefined,void 0,1)}function ho(t,e,n,r){if(r.allowIndefinite===!1)throw new Error(`${C} indefinite length items not allowed`);return new m(f.break,void 0,1)}function Yt(t,e,n){if(n){if(n.allowNaN===!1&&Number.isNaN(t))throw new Error(`${C} NaN values are not supported`);if(n.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${C} Infinity values are not supported`)}return new m(f.float,t,e)}function lo(t,e,n,r){return Yt(tn(t,e+1),3,r)}function po(t,e,n,r){return Yt(nn(t,e+1),5,r)}function wo(t,e,n,r){return Yt(Xn(t,e+1),9,r)}function en(t,e,n){const r=e.value;if(r===!1)t.push([f.float.majorEncoded|oo]);else if(r===!0)t.push([f.float.majorEncoded|ao]);else if(r===null)t.push([f.float.majorEncoded|uo]);else if(r===void 0)t.push([f.float.majorEncoded|co]);else{let i,s=!1;(!n||n.float64!==!0)&&(qn(r),i=tn(Q,1),r===i||Number.isNaN(r)?(Q[0]=249,t.push(Q.slice(0,3)),s=!0):(Wn(r),i=nn(Q,1),r===i&&(Q[0]=250,t.push(Q.slice(0,5)),s=!0))),s||(go(r),i=Xn(Q,1),Q[0]=251,t.push(Q.slice(0,9)))}}en.encodedSize=function(e,n){const r=e.value;if(r===!1||r===!0||r===null||r===void 0)return 1;if(!n||n.float64!==!0){qn(r);let i=tn(Q,1);if(r===i||Number.isNaN(r))return 3;if(Wn(r),i=nn(Q,1),r===i)return 5}return 9};const Gn=new ArrayBuffer(9),G=new DataView(Gn,1),Q=new Uint8Array(Gn,0);function qn(t){if(t===1/0)G.setUint16(0,31744,!1);else if(t===-1/0)G.setUint16(0,64512,!1);else if(Number.isNaN(t))G.setUint16(0,32256,!1);else{G.setFloat32(0,t);const e=G.getUint32(0),n=(e&2139095040)>>23,r=e&8388607;if(n===255)G.setUint16(0,31744,!1);else if(n===0)G.setUint16(0,(t&2147483648)>>16|r>>13,!1);else{const i=n-127;i<-24?G.setUint16(0,0):i<-14?G.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):G.setUint16(0,(e&2147483648)>>16|i+15<<10|r>>13,!1)}}}function tn(t,e){if(t.length-e<2)throw new Error(`${C} not enough data for float16`);const n=(t[e]<<8)+t[e+1];if(n===31744)return 1/0;if(n===64512)return-1/0;if(n===32256)return NaN;const r=n>>10&31,i=n&1023;let s;return r===0?s=i*2**-24:r!==31?s=(i+1024)*2**(r-25):s=i===0?1/0:NaN,n&32768?-s:s}function Wn(t){G.setFloat32(0,t,!1)}function nn(t,e){if(t.length-e<4)throw new Error(`${C} not enough data for float32`);const n=(t.byteOffset||0)+e;return new DataView(t.buffer,n,4).getFloat32(0,!1)}function go(t){G.setFloat64(0,t,!1)}function Xn(t,e){if(t.length-e<8)throw new Error(`${C} not enough data for float64`);const n=(t.byteOffset||0)+e;return new DataView(t.buffer,n,8).getFloat64(0,!1)}en.compareTokens=be.compareTokens;function F(t,e,n){throw new Error(`${C} encountered invalid minor (${n}) for major ${t[e]>>>5}`)}function xt(t){return()=>{throw new Error(`${C} ${t}`)}}const y=[];for(let t=0;t<=23;t++)y[t]=F;y[24]=ks;y[25]=As;y[26]=Cs;y[27]=Is;y[28]=F;y[29]=F;y[30]=F;y[31]=F;for(let t=32;t<=55;t++)y[t]=F;y[56]=vs;y[57]=Ns;y[58]=Ts;y[59]=Ss;y[60]=F;y[61]=F;y[62]=F;y[63]=F;for(let t=64;t<=87;t++)y[t]=$s;y[88]=Fs;y[89]=Bs;y[90]=Ls;y[91]=Ds;y[92]=F;y[93]=F;y[94]=F;y[95]=xt("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)y[t]=Os;y[120]=Ps;y[121]=zs;y[122]=Ms;y[123]=js;y[124]=F;y[125]=F;y[126]=F;y[127]=xt("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)y[t]=Vs;y[152]=Hs;y[153]=Gs;y[154]=qs;y[155]=Ws;y[156]=F;y[157]=F;y[158]=F;y[159]=Xs;for(let t=160;t<=183;t++)y[t]=Js;y[184]=Ks;y[185]=Zs;y[186]=Qs;y[187]=Ys;y[188]=F;y[189]=F;y[190]=F;y[191]=eo;for(let t=192;t<=215;t++)y[t]=to;y[216]=no;y[217]=ro;y[218]=io;y[219]=so;y[220]=F;y[221]=F;y[222]=F;y[223]=F;for(let t=224;t<=243;t++)y[t]=xt("simple values are not supported");y[244]=F;y[245]=F;y[246]=F;y[247]=fo;y[248]=xt("simple values are not supported");y[249]=lo;y[250]=po;y[251]=wo;y[252]=F;y[253]=F;y[254]=F;y[255]=ho;const te=[];for(let t=0;t<24;t++)te[t]=new m(f.uint,t,1);for(let t=-1;t>=-24;t--)te[31-t]=new m(f.negint,t,1);te[64]=new m(f.bytes,new Uint8Array(0),1);te[96]=new m(f.string,"",1);te[128]=new m(f.array,0,1);te[160]=new m(f.map,0,1);te[244]=new m(f.false,!1,1);te[245]=new m(f.true,!0,1);te[246]=new m(f.null,null,1);function yo(t){switch(t.type){case f.false:return ne([244]);case f.true:return ne([245]);case f.null:return ne([246]);case f.bytes:return t.value.length?void 0:ne([64]);case f.string:return t.value===""?ne([96]):void 0;case f.array:return t.value===0?ne([128]):void 0;case f.map:return t.value===0?ne([160]):void 0;case f.uint:return t.value<24?ne([Number(t.value)]):void 0;case f.negint:if(t.value>=-24)return ne([31-Number(t.value)])}}const mo={float64:!1,mapSorter:Eo,quickEncodeToken:yo};function bo(){const t=[];return t[f.uint.major]=be,t[f.negint.major]=Jt,t[f.bytes.major]=bt,t[f.string.major]=Rs,t[f.array.major]=Kt,t[f.map.major]=Zt,t[f.tag.major]=Qt,t[f.float.major]=en,t}const Jn=bo(),Tt=new Vn;class pt{constructor(e,n){this.obj=e,this.parent=n}includes(e){let n=this;do if(n.obj===e)return!0;while(n=n.parent);return!1}static createCheck(e,n){if(e&&e.includes(n))throw new Error(`${lt} object contains circular references`);return new pt(n,e)}}const se={null:new m(f.null,null),undefined:new m(f.undefined,void 0),true:new m(f.true,!0),false:new m(f.false,!1),emptyArray:new m(f.array,0),emptyMap:new m(f.map,0)},fe={number(t,e,n,r){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new m(f.float,t):t>=0?new m(f.uint,t):new m(f.negint,t)},bigint(t,e,n,r){return t>=BigInt(0)?new m(f.uint,t):new m(f.negint,t)},Uint8Array(t,e,n,r){return new m(f.bytes,t)},string(t,e,n,r){return new m(f.string,t)},boolean(t,e,n,r){return t?se.true:se.false},null(t,e,n,r){return se.null},undefined(t,e,n,r){return se.undefined},ArrayBuffer(t,e,n,r){return new m(f.bytes,new Uint8Array(t))},DataView(t,e,n,r){return new m(f.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,n,r){if(!t.length)return n.addBreakTokens===!0?[se.emptyArray,new m(f.break)]:se.emptyArray;r=pt.createCheck(r,t);const i=[];let s=0;for(const o of t)i[s++]=ot(o,n,r);return n.addBreakTokens?[new m(f.array,t.length),i,new m(f.break)]:[new m(f.array,t.length),i]},Object(t,e,n,r){const i=e!=="Object",s=i?t.keys():Object.keys(t),o=i?t.size:s.length;if(!o)return n.addBreakTokens===!0?[se.emptyMap,new m(f.break)]:se.emptyMap;r=pt.createCheck(r,t);const u=[];let d=0;for(const g of s)u[d++]=[ot(g,n,r),ot(i?t.get(g):t[g],n,r)];return xo(u,n),n.addBreakTokens?[new m(f.map,o),u,new m(f.break)]:[new m(f.map,o),u]}};fe.Map=fe.Object;fe.Buffer=fe.Uint8Array;for(const t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))fe[`${t}Array`]=fe.DataView;function ot(t,e={},n){const r=ds(t),i=e&&e.typeEncoders&&e.typeEncoders[r]||fe[r];if(typeof i=="function"){const o=i(t,r,e,n);if(o!=null)return o}const s=fe[r];if(!s)throw new Error(`${lt} unsupported type: ${r}`);return s(t,r,e,n)}function xo(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Eo(t,e){const n=Array.isArray(t[0])?t[0][0]:t[0],r=Array.isArray(e[0])?e[0][0]:e[0];if(n.type!==r.type)return n.type.compare(r.type);const i=n.type.major,s=Jn[i].compareTokens(n,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Kn(t,e,n,r){if(Array.isArray(e))for(const i of e)Kn(t,i,n,r);else n[e.type.major](t,e,r)}function _o(t,e,n){const r=ot(t,n);if(!Array.isArray(r)&&n.quickEncodeToken){const i=n.quickEncodeToken(r);if(i)return i;const s=e[r.type.major];if(s.encodedSize){const o=s.encodedSize(r,n),u=new Vn(o);if(s(u,r,n),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${r} was wrong`);return qt(u.chunks[0])}}return Tt.reset(),Kn(Tt,r,e,n),Tt.toBytes(!0)}function za(t,e){return e=Object.assign({},mo,e),_o(t,Jn,e)}const ko={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0};class Ao{constructor(e,n={}){this._pos=0,this.data=e,this.options=n}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){const e=this.data[this._pos];let n=te[e];if(n===void 0){const r=y[e];if(!r)throw new Error(`${C} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);const i=e&31;n=r(this.data,this._pos,i,this.options)}return this._pos+=n.encodedLength,n}}const Re=Symbol.for("DONE"),Et=Symbol.for("BREAK");function Co(t,e,n){const r=[];for(let i=0;i0)throw new Error(`${C} too many terminals, data makes no sense`);return n}const Qn=42;function No(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function To(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;const e=ae.asCID(t);if(!e)return null;const n=new Uint8Array(e.bytes.byteLength+1);return n.set(e.bytes,1),[new m(f.tag,Qn),new m(f.bytes,n)]}function So(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function $o(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function Fo(t){for(const e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}const Bo={typeEncoders:{Map:Fo,Object:To,undefined:So,number:$o}};({...Bo.typeEncoders});function Lo(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return ae.decode(t.subarray(1))}const wt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};wt.tags[Qn]=Lo;({...wt,tags:wt.tags.slice()});const Ma=113,ja=t=>Zn(No(t),wt);class Ra extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){const n=this.inRecursive[this.inRecursive.length-1];n&&(n.type===f.array&&(n.elements++,n.elements!==1&&e.push([44])),n.type===f.map&&(n.elements++,n.elements!==1&&(n.elements%2===1?e.push([44]):e.push([58]))))}[f.uint.major](e,n){this.prefix(e);const r=String(n.value),i=[];for(let s=0;s32?qt(r):r)}[f.array.major](e,n){this.prefix(e),this.inRecursive.push({type:f.array,elements:0}),e.push([91])}[f.map.major](e,n){this.prefix(e),this.inRecursive.push({type:f.map,elements:0}),e.push([123])}[f.tag.major](e,n){}[f.float.major](e,n){if(n.type.name==="break"){const o=this.inRecursive.pop();if(o){if(o.type===f.array)e.push([93]);else if(o.type===f.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(n.value===void 0)throw new Error(`${lt} unsupported type: undefined`);if(this.prefix(e),n.type.name==="true"){e.push([116,114,117,101]);return}else if(n.type.name==="false"){e.push([102,97,108,115,101]);return}else if(n.type.name==="null"){e.push([110,117,108,108]);return}const r=String(n.value),i=[];let s=!1;for(let o=0;o=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos{for(;!this.done();){const d=this.ch();if(u.includes(d))this._pos++;else break}};if(this.ch()===45&&(n=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,r=!0;else return new m(f.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),n&&this._pos===e+1)throw new Error(`${C} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(r)throw new Error(`${C} unexpected token at position ${this._pos}`);r=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(r=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));const s=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),o=parseFloat(s);return r?new m(f.float,o,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(o)?new m(o>=0?f.uint:f.negint,o,this._pos-e):new m(o>=0?f.uint:f.negint,BigInt(s),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${C} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let s=this._pos,o=0;s=128)break;if(u===34){const d=String.fromCharCode.apply(null,this.data.subarray(this._pos,s));return this._pos=s+1,new m(f.string,d,o)}}const e=this._pos,n=[],r=()=>{if(this._pos+4>=this.data.length)throw new Error(`${C} unexpected end of unicode escape sequence at position ${this._pos}`);let s=0;for(let o=0;o<4;o++){let u=this.ch();if(u>=48&&u<=57)u-=48;else if(u>=97&&u<=102)u=u-97+10;else if(u>=65&&u<=70)u=u-65+10;else throw new Error(`${C} unexpected unicode escape character at position ${this._pos}`);s=s*16+u,this._pos++}return s},i=()=>{const s=this.ch();let o=null,u=s>239?4:s>223?3:s>191?2:1;if(this._pos+u>this.data.length)throw new Error(`${C} unexpected unicode sequence at position ${this._pos}`);let d,g,h,l;switch(u){case 1:s<128&&(o=s);break;case 2:d=this.data[this._pos+1],(d&192)===128&&(l=(s&31)<<6|d&63,l>127&&(o=l));break;case 3:d=this.data[this._pos+1],g=this.data[this._pos+2],(d&192)===128&&(g&192)===128&&(l=(s&15)<<12|(d&63)<<6|g&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:d=this.data[this._pos+1],g=this.data[this._pos+2],h=this.data[this._pos+3],(d&192)===128&&(g&192)===128&&(h&192)===128&&(l=(s&15)<<18|(d&63)<<12|(g&63)<<6|h&63,l>65535&&l<1114112&&(o=l))}o===null?(o=65533,u=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),this._pos+=u};for(;!this.done();){const s=this.ch();let o;switch(s){case 92:if(this._pos++,this.done())throw new Error(`${C} unexpected string termination at position ${this._pos}`);switch(o=this.ch(),this._pos++,o){case 34:case 39:case 92:case 47:n.push(o);break;case 98:n.push(8);break;case 116:n.push(9);break;case 110:n.push(10);break;case 102:n.push(12);break;case 114:n.push(13);break;case 117:n.push(r());break;default:throw new Error(`${C} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new m(f.string,Rn(n),this._pos-e);default:if(s<32)throw new Error(`${C} invalid control character at position ${this._pos}`);s<128?(n.push(s),this._pos++):i()}}throw new Error(`${C} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new m(f.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new m(f.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new m(f.null,null,4);case 102:return this.expect([102,97,108,115,101]),new m(f.false,!1,5);case 116:return this.expect([116,114,117,101]),new m(f.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${C} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new m(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${C} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new m(f.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new m(f.break,void 0,1);if(this.ch()!==44)throw new Error(`${C} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new m(f.break,void 0,1);const e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${C} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${C} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}}function Do(t,e){return e=Object.assign({tokenizer:new Yn(t,e)},e),Zn(t,e)}function Uo(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}class Oo extends Yn{constructor(e,n){super(e,n),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){const e=this._next();if(e.type===f.map){const n=this._next();if(n.type===f.string&&n.value==="/"){const r=this._next();if(r.type===f.string){if(this._next().type!==f.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(r),new m(f.tag,42,0)}if(r.type===f.map){const i=this._next();if(i.type===f.string&&i.value==="bytes"){const s=this._next();if(s.type===f.string){for(let u=0;u<2;u++)if(this._next().type!==f.break)throw new Error("Invalid encoded Bytes form");const o=Ht.decode(`m${s.value}`);return new m(f.bytes,o,s.value.length)}this.tokenBuffer.push(s)}this.tokenBuffer.push(i)}this.tokenBuffer.push(r)}this.tokenBuffer.push(n)}return e}}const Ft={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Ft.tags[42]=ae.parse;const Va=297,Ha=t=>{const e=Uo(t),n=Object.assign(Ft,{tokenizer:new Oo(e,Ft)});return Do(e,n)};new TextDecoder;new TextEncoder;const Po=new TextDecoder;function rn(t,e){let n=0;for(let r=0;;r+=7){if(r>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");const i=t[e++];if(n+=r<28?(i&127)<t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,r),r]}function er(t,e){let n;return[n,e]=rn(t,e),[n&7,n>>3,e]}function zo(t){const e={},n=t.length;let r=0;for(;rn)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Mo(t){const e=t.length;let n=0,r,i=!1,s;for(;ne)throw new Error("protobuf: (PBNode) unexpected end of data");const o={};return s&&(o.Data=s),o.Links=r||[],o}const tr=new TextEncoder,yn=2**32,jo=2**31;function Ro(t,e){let n=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");n=ze(e,n,t.Tsize)-1,e[n]=24}if(typeof t.Name=="string"){const r=tr.encode(t.Name);n-=r.length,e.set(r,n),n=ze(e,n,r.length)-1,e[n]=18}return t.Hash&&(n-=t.Hash.length,e.set(t.Hash,n),n=ze(e,n,t.Hash.length)-1,e[n]=10),e.length-n}function Vo(t){const e=Go(t),n=new Uint8Array(e);let r=e;if(t.Data&&(r-=t.Data.length,n.set(t.Data,r),r=ze(n,r,t.Data.length)-1,n[r]=10),t.Links)for(let i=t.Links.length-1;i>=0;i--){const s=Ro(t.Links[i],n.subarray(0,r));r-=s,r=ze(n,r,s)-1,n[r]=18}return n}function Ho(t){let e=0;if(t.Hash){const n=t.Hash.length;e+=1+n+xe(n)}if(typeof t.Name=="string"){const n=tr.encode(t.Name).length;e+=1+n+xe(n)}return typeof t.Tsize=="number"&&(e+=1+xe(t.Tsize)),e}function Go(t){let e=0;if(t.Data){const n=t.Data.length;e+=1+n+xe(n)}if(t.Links)for(const n of t.Links){const r=Ho(n);e+=1+r+xe(r)}return e}function ze(t,e,n){e-=xe(n);const r=e;for(;n>=jo;)t[e++]=n&127|128,n/=128;for(;n>=128;)t[e++]=n&127|128,n>>>=7;return t[e]=n,r}function xe(t){return t%2===0&&t++,Math.floor((qo(t)+6)/7)}function qo(t){let e=0;return t>=yn&&(t=Math.floor(t/yn),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Wo[t]}const Wo=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8],Xo=["Data","Links"],Jo=["Hash","Name","Tsize"],Bt=new TextEncoder;function nr(t,e){if(t===e)return 0;const n=t.Name?Bt.encode(t.Name):[],r=e.Name?Bt.encode(e.Name):[];let i=n.length,s=r.length;for(let o=0,u=Math.min(i,s);o!e.includes(n))}function rr(t){if(typeof t.asCID=="object"){const n=ae.asCID(t);if(!n)throw new TypeError("Invalid DAG-PB form");return{Hash:n}}if(typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");const e={};if(t.Hash){let n=ae.asCID(t.Hash);try{n||(typeof t.Hash=="string"?n=ae.parse(t.Hash):t.Hash instanceof Uint8Array&&(n=ae.decode(t.Hash)))}catch(r){throw new TypeError(`Invalid DAG-PB form: ${r.message}`)}n&&(e.Hash=n)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof t.Name=="string"&&(e.Name=t.Name),typeof t.Tsize=="number"&&(e.Tsize=t.Tsize),e}function ir(t){if((t instanceof Uint8Array||typeof t=="string")&&(t={Data:t}),typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");const e={};if(t.Data!==void 0)if(typeof t.Data=="string")e.Data=Bt.encode(t.Data);else if(t.Data instanceof Uint8Array)e.Data=t.Data;else throw new TypeError("Invalid DAG-PB form");if(t.Links!==void 0)if(Array.isArray(t.Links))e.Links=t.Links.map(rr),e.Links.sort(nr);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function sr(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!mn(t,Xo))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e0&&nr(n,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Ko(t,e=[]){return ir({Data:t,Links:e})}function Zo(t,e,n){return rr({Hash:n,Name:t,Tsize:e})}function Qo(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}const Yo="dag-pb",ea=112;function ta(t){sr(t);const e={};return t.Links&&(e.Links=t.Links.map(n=>{const r={};return n.Hash&&(r.Hash=n.Hash.bytes),n.Name!==void 0&&(r.Name=n.Name),n.Tsize!==void 0&&(r.Tsize=n.Tsize),r})),t.Data&&(e.Data=t.Data),Vo(e)}function na(t){const e=Qo(t),n=Mo(e),r={};return n.Data&&(r.Data=n.Data),n.Links&&(r.Links=n.Links.map(i=>{const s={};try{s.Hash=ae.decode(i.Hash)}catch{}if(!s.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(s.Name=i.Name),i.Tsize!==void 0&&(s.Tsize=i.Tsize),s})),r}const Ga=Object.freeze(Object.defineProperty({__proto__:null,code:ea,createLink:Zo,createNode:Ko,decode:na,encode:ta,name:Yo,prepare:ir,validate:sr},Symbol.toStringTag,{value:"Module"}));function ra(t){return t[Symbol.asyncIterator]!=null}function qa(t,e){let n=0;if(ra(t))return async function*(){for await(const d of t)await e(d,n++)&&(yield d)}();const r=Nn(t),{value:i,done:s}=r.next();if(s===!0)return function*(){}();const o=e(i,n++);if(typeof o.then=="function")return async function*(){await o&&(yield i);for(const d of r)await e(d,n++)&&(yield d)}();const u=e;return function*(){o===!0&&(yield i);for(const d of r)u(d,n++)&&(yield d)}()}class or extends Error{constructor(e){super(e),this.name="TimeoutError"}}class ia extends Error{constructor(e){super(),this.name="AbortError",this.message=e}}const bn=t=>globalThis.DOMException===void 0?new ia(t):new DOMException(t),xn=t=>{const e=t.reason===void 0?bn("This operation was aborted."):t.reason;return e instanceof Error?e:bn(e)};function sa(t,e){const{milliseconds:n,fallback:r,message:i,customTimers:s={setTimeout,clearTimeout}}=e;let o,u;const g=new Promise((h,l)=>{if(typeof n!="number"||Math.sign(n)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${n}\``);if(e.signal){const{signal:_}=e;_.aborted&&l(xn(_)),u=()=>{l(xn(_))},_.addEventListener("abort",u,{once:!0})}if(n===Number.POSITIVE_INFINITY){t.then(h,l);return}const E=new or;o=s.setTimeout.call(void 0,()=>{if(r){try{h(r())}catch(_){l(_)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?h():i instanceof Error?l(i):(E.message=i??`Promise timed out after ${n} milliseconds`,l(E))},n),(async()=>{try{h(await t)}catch(_){l(_)}})()}).finally(()=>{g.clear(),u&&e.signal&&e.signal.removeEventListener("abort",u)});return g.clear=()=>{s.clearTimeout.call(void 0,o),o=void 0},g}function oa(t,e,n){let r=0,i=t.length;for(;i>0;){const s=Math.trunc(i/2);let o=r+s;n(t[o],e)<=0?(r=++o,i-=s+1):i=s}return r}var q;class aa{constructor(){P(this,q,[])}enqueue(e,n){n={priority:0,...n};const r={priority:n.priority,id:n.id,run:e};if(this.size===0||A(this,q)[this.size-1].priority>=n.priority){A(this,q).push(r);return}const i=oa(A(this,q),r,(s,o)=>o.priority-s.priority);A(this,q).splice(i,0,r)}setPriority(e,n){const r=A(this,q).findIndex(s=>s.id===e);if(r===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);const[i]=A(this,q).splice(r,1);this.enqueue(i.run,{priority:n,id:e})}dequeue(){const e=A(this,q).shift();return e==null?void 0:e.run}filter(e){return A(this,q).filter(n=>n.priority===e.priority).map(n=>n.run)}get size(){return A(this,q).length}}q=new WeakMap;var Ee,_e,oe,He,ke,Ge,W,Ae,H,qe,X,Ce,re,We,mt,$,ar,ur,cr,fr,hr,at,Lt,Dt,ut,lr,ct;class Wa extends fs{constructor(n){var r,i;super();P(this,$);P(this,Ee);P(this,_e);P(this,oe,0);P(this,He);P(this,ke);P(this,Ge,0);P(this,W);P(this,Ae);P(this,H);P(this,qe);P(this,X,0);P(this,Ce);P(this,re);P(this,We);P(this,mt,1n);v(this,"timeout");if(n={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:aa,...n},!(typeof n.intervalCap=="number"&&n.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${((r=n.intervalCap)==null?void 0:r.toString())??""}\` (${typeof n.intervalCap})`);if(n.interval===void 0||!(Number.isFinite(n.interval)&&n.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${((i=n.interval)==null?void 0:i.toString())??""}\` (${typeof n.interval})`);U(this,Ee,n.carryoverConcurrencyCount),U(this,_e,n.intervalCap===Number.POSITIVE_INFINITY||n.interval===0),U(this,He,n.intervalCap),U(this,ke,n.interval),U(this,H,new n.queueClass),U(this,qe,n.queueClass),this.concurrency=n.concurrency,this.timeout=n.timeout,U(this,We,n.throwOnTimeout===!0),U(this,re,n.autoStart===!1)}get concurrency(){return A(this,Ce)}set concurrency(n){if(!(typeof n=="number"&&n>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${n}\` (${typeof n})`);U(this,Ce,n),z(this,$,ut).call(this)}setPriority(n,r){A(this,H).setPriority(n,r)}async add(n,r={}){return r.id??(r.id=(Ue(this,mt)._++).toString()),r={timeout:this.timeout,throwOnTimeout:A(this,We),...r},new Promise((i,s)=>{A(this,H).enqueue(async()=>{var o;Ue(this,X)._++;try{(o=r.signal)==null||o.throwIfAborted(),Ue(this,oe)._++;let u=n({signal:r.signal});r.timeout&&(u=sa(Promise.resolve(u),{milliseconds:r.timeout})),r.signal&&(u=Promise.race([u,z(this,$,lr).call(this,r.signal)]));const d=await u;i(d),this.emit("completed",d)}catch(u){if(u instanceof or&&!r.throwOnTimeout){i();return}s(u),this.emit("error",u)}finally{z(this,$,cr).call(this)}},r),this.emit("add"),z(this,$,at).call(this)})}async addAll(n,r){return Promise.all(n.map(async i=>this.add(i,r)))}start(){return A(this,re)?(U(this,re,!1),z(this,$,ut).call(this),this):this}pause(){U(this,re,!0)}clear(){U(this,H,new(A(this,qe)))}async onEmpty(){A(this,H).size!==0&&await z(this,$,ct).call(this,"empty")}async onSizeLessThan(n){A(this,H).sizeA(this,H).size{z(this,$,fr).call(this)},r)),!0}return!1},at=function(){if(A(this,H).size===0)return A(this,W)&&clearInterval(A(this,W)),U(this,W,void 0),this.emit("empty"),A(this,X)===0&&this.emit("idle"),!1;if(!A(this,re)){const n=!A(this,$,hr);if(A(this,$,ar)&&A(this,$,ur)){const r=A(this,H).dequeue();return r?(this.emit("active"),r(),n&&z(this,$,Lt).call(this),!0):!1}}return!1},Lt=function(){A(this,_e)||A(this,W)!==void 0||(U(this,W,setInterval(()=>{z(this,$,Dt).call(this)},A(this,ke))),U(this,Ge,Date.now()+A(this,ke)))},Dt=function(){A(this,oe)===0&&A(this,X)===0&&A(this,W)&&(clearInterval(A(this,W)),U(this,W,void 0)),U(this,oe,A(this,Ee)?A(this,X):0),z(this,$,ut).call(this)},ut=function(){for(;z(this,$,at).call(this););},lr=async function(n){return new Promise((r,i)=>{n.addEventListener("abort",()=>{i(n.reason)},{once:!0})})},ct=async function(n,r){return new Promise(i=>{const s=()=>{r&&!r()||(this.off(n,s),i())};this.on(n,s)})};function ua(t){return t[Symbol.asyncIterator]!=null}function Xa(t){if(ua(t))return(async()=>{for await(const e of t)return e})();for(const e of t)return e}function ca(t){return t[Symbol.asyncIterator]!=null}function Ja(t){if(ca(t))return(async()=>{const n=[];for await(const r of t)n.push(r);return n})();const e=[];for(const n of t)e.push(n);return e}const it=globalThis.CustomEvent??Event;async function*Ka(t,e={}){let n=e.concurrency??1/0;n<1&&(n=1/0);const r=e.ordered??!1,i=new EventTarget,s=[];let o=ee(),u=ee(),d=!1,g,h=!1;i.addEventListener("task-complete",()=>{u.resolve()}),Promise.resolve().then(async()=>{try{for await(const N of t){if(s.length===n&&(o=ee(),await o.promise),h)break;const a={done:!1};s.push(a),N().then(c=>{a.done=!0,a.ok=!0,a.value=c,i.dispatchEvent(new it("task-complete"))},c=>{a.done=!0,a.err=c,i.dispatchEvent(new it("task-complete"))})}d=!0,i.dispatchEvent(new it("task-complete"))}catch(N){g=N,i.dispatchEvent(new it("task-complete"))}});function l(){var N;return r?(N=s[0])==null?void 0:N.done:!!s.find(a=>a.done)}function*E(){for(;s.length>0&&s[0].done;){const N=s[0];if(s.shift(),N.ok)yield N.value;else throw h=!0,o.resolve(),N.err;o.resolve()}}function*_(){for(;l();)for(let N=0;N{if(Object.prototype.toString.call(t)!=="[object Object]")return!1;const e=Object.getPrototypeOf(t);return e===null||e===Object.prototype};const yt=fa,{hasOwnProperty:dr}=Object.prototype,{propertyIsEnumerable:ha}=Object,Se=(t,e,n)=>Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0}),la=Vi,En={concatArrays:!1,ignoreUndefined:!1},_t=t=>{const e=[];for(const n in t)dr.call(t,n)&&e.push(n);if(Object.getOwnPropertySymbols){const n=Object.getOwnPropertySymbols(t);for(const r of n)ha.call(t,r)&&e.push(r)}return e};function De(t){return Array.isArray(t)?da(t):yt(t)?pa(t):t}function da(t){const e=t.slice(0,0);return _t(t).forEach(n=>{Se(e,n,De(t[n]))}),e}function pa(t){const e=Object.getPrototypeOf(t)===null?Object.create(null):{};return _t(t).forEach(n=>{Se(e,n,De(t[n]))}),e}const pr=(t,e,n,r)=>(n.forEach(i=>{typeof e[i]>"u"&&r.ignoreUndefined||(i in t&&t[i]!==Object.getPrototypeOf(t)?Se(t,i,Ut(t[i],e[i],r)):Se(t,i,De(e[i])))}),t),wa=(t,e,n)=>{let r=t.slice(0,0),i=0;return[t,e].forEach(s=>{const o=[];for(let u=0;u!o.includes(u)),n)}),r};function Ut(t,e,n){return n.concatArrays&&Array.isArray(t)&&Array.isArray(e)?wa(t,e,n):!yt(e)||!yt(t)?De(e):pr(t,e,_t(e),n)}var ga=function(...t){const e=Ut(De(En),this!==la&&this||{},En);let n={_:{}};for(const r of t)if(r!==void 0){if(!yt(r))throw new TypeError("`"+r+"` is not an Option Object");n=Ut(n,{_:r},e)}return n._};const Za=Gt(ga);export{Ka as $,ea as A,$i as B,Ia as C,Ai as D,fs as E,Ma as F,Va as G,Na as H,na as I,Do as J,f as K,m as L,Ba as M,us as N,Nn as O,qa as P,Pa as Q,Vi as R,wi as S,Yn as T,st as U,Cn as V,tt as W,Xa as X,Wa as Y,Ja as Z,ka as _,Ir as a,sa as a0,Za as a1,or as a2,Ga as a3,ta as a4,Sa as a5,ir as a6,Dn as a7,ja as a8,Ha as a9,Ta as aa,Ea as b,ce as c,_a as d,Xe as e,Da as f,La as g,va as h,ie as i,Ca as j,Aa as k,$a as l,Ua as m,Lr as n,ln as o,ee as p,Fi as q,Nr as r,Fa as s,un as t,Ht as u,Oa as v,Gt as w,za as x,Zn as y,Rr as z};
//# sourceMappingURL=index-BqzxYBEc.js.map