var kr=Object.create;var lt=Object.defineProperty;var Cr=Object.getOwnPropertyDescriptor;var Pr=Object.getOwnPropertyNames;var Sr=Object.getPrototypeOf,Tr=Object.prototype.hasOwnProperty;var Rt=e=>{throw TypeError(e)};var Rr=(e,t,r)=>t in e?lt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ir=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var ht=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Mr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pr(t))!Tr.call(e,o)&&o!==r&<(e,o,{get:()=>t[o],enumerable:!(n=Cr(t,o))||n.enumerable});return e};var xe=(e,t,r)=>(r=e!=null?kr(Sr(e)):{},Mr(t||!e||!e.__esModule?lt(r,"default",{value:e,enumerable:!0}):r,e));var E=(e,t,r)=>Rr(e,typeof t!="symbol"?t+"":t,r),pt=(e,t,r)=>t.has(e)||Rt("Cannot "+r);var p=(e,t,r)=>(pt(e,t,"read from private field"),r?r.call(e):t.get(e)),L=(e,t,r)=>t.has(e)?Rt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),w=(e,t,r,n)=>(pt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),x=(e,t,r)=>(pt(e,t,"access private method"),r);var He=(e,t,r,n)=>({set _(o){w(e,t,o,r)},get _(){return p(e,t,n)}});var Ge=ht((Zn,mt)=>{"use strict";var ce=typeof Reflect=="object"?Reflect:null,Bt=ce&&typeof ce.apply=="function"?ce.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},$e;ce&&typeof ce.ownKeys=="function"?$e=ce.ownKeys:Object.getOwnPropertySymbols?$e=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:$e=function(t){return Object.getOwnPropertyNames(t)};function zr(e){console&&console.warn&&console.warn(e)}var Wt=Number.isNaN||function(t){return t!==t};function v(){v.init.call(this)}mt.exports=v;mt.exports.once=qr;v.EventEmitter=v;v.prototype._events=void 0;v.prototype._eventsCount=0;v.prototype._maxListeners=void 0;var jt=10;function qe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(v,"defaultMaxListeners",{enumerable:!0,get:function(){return jt},set:function(e){if(typeof e!="number"||e<0||Wt(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");jt=e}});v.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};v.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Wt(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function zt(e){return e._maxListeners===void 0?v.defaultMaxListeners:e._maxListeners}v.prototype.getMaxListeners=function(){return zt(this)};v.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")Bt(u,this,r);else for(var f=u.length,l=Gt(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,zr(c)}return e}v.prototype.addListener=function(t,r){return Jt(this,t,r,!1)};v.prototype.on=v.prototype.addListener;v.prototype.prependListener=function(t,r){return Jt(this,t,r,!0)};function Jr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ht(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Jr.bind(n);return o.listener=r,n.wrapFn=o,o}v.prototype.once=function(t,r){return qe(r),this.on(t,Ht(this,t,r)),this};v.prototype.prependOnceListener=function(t,r){return qe(r),this.prependListener(t,Ht(this,t,r)),this};v.prototype.removeListener=function(t,r){var n,o,i,s,c;if(qe(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Hr(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};v.prototype.off=v.prototype.removeListener;v.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function $t(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?$r(o):Gt(o,o.length)}v.prototype.listeners=function(t){return $t(this,t,!0)};v.prototype.rawListeners=function(t){return $t(this,t,!1)};v.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):qt.call(e,t)};v.prototype.listenerCount=qt;function qt(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}v.prototype.eventNames=function(){return this._eventsCount>0?$e(this._events):[]};function Gt(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return er(this,e,0)},decrypt:function(e){return er(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,l,h,m;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=c[o=c[f=c[i]]],m=16843009*l^65537*o^257*f^16843008*i,l=257*c[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=m=m<<24^m>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function er(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,l=n.length/4-2,h,m=4,d=[0,0,0,0];c=e.w[r],e=c[0];var b=c[1],F=c[2],J=c[3],K=c[4];for(h=0;h>>24]^b[i>>16&255]^F[s>>8&255]^J[t&255]^n[m],u=e[i>>>24]^b[s>>16&255]^F[t>>8&255]^J[o&255]^n[m+1],f=e[s>>>24]^b[t>>16&255]^F[o>>8&255]^J[i&255]^n[m+2],t=e[t>>>24]^b[o>>16&255]^F[i>>8&255]^J[s&255]^n[m+3],m+=4,o=c,i=u,s=f;for(h=0;4>h;h++)d[r?3&-h:h]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[t&255]^n[m++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],l=o[4],h=o[5],m=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(m^l&(h^m))+i[t],d=m,m=h,h=l,l=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+l|0,o[5]=o[5]+h|0,o[6]=o[6]+m|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],l=n[5],h=n[6],m=n[7],d=n[8],b=n[9],F=n[10],J=n[11],K=n[12],je=n[13],Pt=n[14],We=n[15],P;if(typeof Uint32Array<"u"){P=Array(160);for(var k=0;32>k;k++)P[k]=e[k]}else P=e;var k=i,M=s,ve=c,ie=u,Ee=f,se=l,at=h,we=m,H=d,U=b,ze=F,Ae=J,Je=K,be=je,ct=Pt,Le=We;for(e=0;80>e;e++){if(16>e)t=P[2*e],r=P[2*e+1];else{r=P[2*(e-15)];var A=P[2*(e-15)+1];t=(A<<31|r>>>1)^(A<<24|r>>>8)^r>>>7;var $=(r<<31|A>>>1)^(r<<24|A>>>8)^(r<<25|A>>>7);r=P[2*(e-2)];var q=P[2*(e-2)+1],A=(q<<13|r>>>19)^(r<<3|q>>>29)^r>>>6,q=(r<<13|q>>>19)^(q<<3|r>>>29)^(r<<26|q>>>6),ut=P[2*(e-7)],ft=P[2*(e-16)],Oe=P[2*(e-16)+1];r=$+P[2*(e-7)+1],t=t+ut+(r>>>0<$>>>0?1:0),r+=q,t+=A+(r>>>0>>0?1:0),r+=Oe,t+=ft+(r>>>0>>0?1:0)}P[2*e]=t|=0,P[2*e+1]=r|=0;var ut=H&ze^~H&Je,St=U&Ae^~U&be,q=k&ve^k&Ee^ve&Ee,Dr=M&ie^M&se^ie&se,ft=(M<<4|k>>>28)^(k<<30|M>>>2)^(k<<25|M>>>7),Oe=(k<<4|M>>>28)^(M<<30|k>>>2)^(M<<25|k>>>7),_r=o[2*e],Tt=o[2*e+1],A=Le+((H<<18|U>>>14)^(H<<14|U>>>18)^(U<<23|H>>>9)),$=ct+((U<<18|H>>>14)^(U<<14|H>>>18)^(H<<23|U>>>9))+(A>>>0>>0?1:0),A=A+St,$=$+(ut+(A>>>0>>0?1:0)),A=A+Tt,$=$+(_r+(A>>>0>>0?1:0)),A=A+r|0,$=$+(t+(A>>>0>>0?1:0));r=Oe+Dr,t=ft+q+(r>>>0>>0?1:0),ct=Je,Le=be,Je=ze,be=Ae,ze=H,Ae=U,U=we+A|0,H=at+$+(U>>>0>>0?1:0)|0,at=Ee,we=se,Ee=ve,se=ie,ve=k,ie=M,M=A+r|0,k=$+t+(M>>>0>>0?1:0)|0}s=n[1]=s+M|0,n[0]=i+k+(s>>>0>>0?1:0)|0,u=n[3]=u+ie|0,n[2]=c+ve+(u>>>0>>0?1:0)|0,l=n[5]=l+se|0,n[4]=f+Ee+(l>>>0>>0?1:0)|0,m=n[7]=m+we|0,n[6]=h+at+(m>>>0>>0?1:0)|0,b=n[9]=b+U|0,n[8]=d+H+(b>>>0>>0?1:0)|0,J=n[11]=J+Ae|0,n[10]=F+ze+(J>>>0>>0?1:0)|0,je=n[13]=je+be|0,n[12]=K+Je+(je>>>0>>0?1:0)|0,We=n[15]=We+Le|0,n[14]=Pt+ct+(We>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;to||16l&&(a.mode.ccm.da(s/u),l+=h),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(l.concat(t,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&tr("seeded",Math.max(this.u,this.i)),tr("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:Ce(this,this.la),mouseCollector:Ce(this,this.na),keyboardCollector:Ce(this,this.ja),accelerometerCollector:Ce(this,this.ca),touchCollector:Ce(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function Ce(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(Qe=typeof fe<"u"&&fe.exports){try{Ze=Ir("crypto")}catch{Ze=null}Qe=Ke=Ze}if(Qe&&Ke.randomBytes)Pe=Ke.randomBytes(128),Pe=new Uint32Array(new Uint8Array(Pe).buffer),a.random.addEntropy(Pe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Se=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Se);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Se);else break e;a.random.addEntropy(Se,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var Pe,Ke,Se,Qe,Ze;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof e=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{"use strict";var An=Object.prototype.hasOwnProperty,S="~";function Te(){}Object.create&&(Te.prototype=Object.create(null),new Te().__proto__||(S=!1));function bn(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function mr(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new bn(r,n||e,o),s=S?S+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function et(e,t){--e._eventsCount===0?e._events=new Te:delete e._events[t]}function C(){this._events=new Te,this._eventsCount=0}C.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)An.call(r,n)&&t.push(S?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};C.prototype.listeners=function(t){var r=S?S+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function ae(e,t,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(l){try{f(n.next(l))}catch(h){s(h)}}function u(l){try{f(n.throw(l))}catch(h){s(h)}}function f(l){l.done?i(l.value):o(l.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function It(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function G(e){return this instanceof G?(this.v=e,this):new G(e)}function Mt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(b){return Promise.resolve(b).then(d,h)}}function c(d,b){n[d]&&(o[d]=function(F){return new Promise(function(J,K){i.push([d,F,J,K])>1||u(d,F)})},b&&(o[d]=b(o[d])))}function u(d,b){try{f(n[d](b))}catch(F){m(i[0][3],F)}}function f(d){d.value instanceof G?Promise.resolve(d.value.v).then(l,h):m(i[0][2],d)}function l(d){u("next",d)}function h(d){u("throw",d)}function m(d,b){d(b),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Nr(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:G(e[o](s)),done:!1}:i?i(s):s}:i}}function Fr(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof It=="function"?It(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var O=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new B(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new B(o)).catch(o=>new j(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(ae(this,void 0,void 0,function*(){try{return new B(yield t(...n))}catch(o){return new j(r?r(o):o)}}))}static combine(t){return Br(t)}static combineWithAllErrors(t){return jr(t)}map(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?new j(r.error):new B(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new j(r.error);let n=yield t(r.value);return n.isErr()?new j(n.error):new B(r.value)})))}andTee(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new j(r.error);try{yield t(r.value)}catch{}return new B(r.value)})))}mapErr(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isOk()?new B(r.value):new j(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new j(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new B(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Mt(this,arguments,function*(){return yield G(yield G(yield*Nr(Fr(yield G(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Mt(this,arguments,function*(){let r=yield G(this._promise);return r.isErr()&&(yield yield G(D(r.error))),yield G(r.value)})}},T=e=>new O(Promise.resolve(new B(e))),D=e=>new O(Promise.resolve(new j(e))),Dn=O.fromPromise,_n=O.fromSafePromise,kn=O.fromThrowable,Nt=e=>{let t=ne([]);for(let r of e)if(r.isErr()){t=V(r.error);break}else t.map(n=>n.push(r.value));return t},Br=e=>O.fromSafePromise(Promise.all(e)).andThen(Nt),Ft=e=>{let t=ne([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=V([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},jr=e=>O.fromSafePromise(Promise.all(e)).andThen(Ft),dt;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return ne(c)}catch(c){return V(i?i(c):c)}}}e.fromThrowable=t;function r(o){return Nt(o)}e.combine=r;function n(o){return Ft(o)}e.combineWithAllErrors=n})(dt||(dt={}));var ne=e=>new B(e);function V(e){return new j(e)}var B=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return ne(t(this.value))}mapErr(t){return ne(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return ne(this.value)}orElse(t){return ne(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return O.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw Ut("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},j=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return V(this.error)}mapErr(t){return V(t(this.error))}andThrough(t){return V(this.error)}andTee(t){return V(this.error)}andThen(t){return V(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return D(this.error)}asyncAndThrough(t){return D(this.error)}asyncMap(t){return D(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield V(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ut("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Cn=dt.fromThrowable;var R=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});E(this,"context");this.name=this.constructor.name,this.context=i}};var Q=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Wr=()=>typeof Deno<"u";var Z=e=>Wr()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var X=class extends R{};var De=class extends X{constructor(){super(...arguments);E(this,"message","An error occured while trying to connect to WebSocket")}};var Kt=xe(Ge());var g=new Kt.default,_,Xt=!1;self.onmessage=e=>{Vr(e),Xt||(Xt=!0,g.once("OPERATION_FAILED",()=>{_&&_.terminate()}))};var ee=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e),Ye=(e,t)=>{ee(e,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:t})},Vr=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)_.postMessage(e.data);else{switch(r){case 2:_=new Worker(Z("cancel"),{type:"module"}),_.postMessage(e.data);break;case 3:_=new Worker(Z("download"),{type:"module"}),_.postMessage(e.data);break;case 4:_=new Worker(Z("infos"),{type:"module"}),_.postMessage(e.data);break;case 7:_=_||new Worker(Z("remove"),{type:"module"}),_.postMessage(e.data);break;case 9:_=_||new Worker(Z("upload"),{type:"module"}),_.postMessage(e.data);break;default:console.error("Action not found")}_.onmessage=n=>{t&&t(n),self.postMessage(n.data)},_.onerror=n=>{console.error(`Error: ${n.message}`)}}},Qt=()=>{g.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),g.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var ue=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Xr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function _e(e){return Xr.Decode(e)}var Yr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function yt(e){return Yr.Decode(e)}var or=xe(nr());var te=class extends R{};var le=class extends te{constructor(){super(...arguments);E(this,"message","Unable to decrypt the provided data")}};var ir=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return T(_e(or.default.decrypt(e,r)))}catch(r){return D(new le(void 0,{cause:Q(r)}))}};var sr=(e,t)=>tn(e).andThen(r=>O.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,_e(t.data)),n=>new le(void 0,{cause:Q(n)})));var tn=e=>O.fromPromise(crypto.subtle.importKey("raw",yt(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new te("Unable to import cryptography key",{cause:Q(t)}));var ar=(e,t)=>t.algo===void 0||t.algo===0?ir(e,t):sr(e,t);var N={},ur=5,nn=e=>(g.emit("UPLOAD_CANCELLED",e.success),T(void 0)),on=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(dn(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),ar(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(ee(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),g.emit("DOWNLOAD_STARTED")):ee(t,{chunksReady:t.chunksReady+1}),g.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?un(t).andThen(()=>(g.emit("DOWNLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED"),T(void 0))):T(void 0)})}else{let s=new X("Cannot retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",s),D(s)}}else{let i=new X(o.msg);return g.emit("OPERATION_FAILED",i),D(i)}}else{let o=new X("Cannot retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",o),D(o)}},sn=(e,t)=>{if(e.success)return e.j===0&&(ee(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),g.emit("UPLOAD_STARTED")),ee(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),g.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(ee(t,{uploadStatus:1}),g.emit("UPLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED")),T(void 0);{let r=new X(e.msg);return g.emit("OPERATION_FAILED",r),D(r)}},an=(e,t)=>{let r=pn(e.data),n;if(r)if(!r.action&&r.msg){let o=new X(r.msg);return g.emit("OPERATION_FAILED",o),D(o)}else"delay"in r?n=sn(r,t):n=nn(r);else n=on(e.data,t);return n},cn=e=>N!==void 0&&N[e]!==void 0&&N[e].readyState===WebSocket.CONNECTING,Et=e=>N!==void 0&&N[e]!==void 0&&N[e].readyState===WebSocket.OPEN;var un=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},At(ln(e),e,JSON.stringify(t))},wt=(e,t,r)=>At(hn(e),e,`${JSON.stringify(t)}XXMOJOXX${JSON.stringify(r)}`),At=(e,t,r)=>Et(e)?(N[e].onmessage=n=>an(n,t),N[e].send(r),T(void 0)):fr(e).andThen(()=>At(e,t,r)),fr=(e,t=0)=>(!Et(e)&&!cn(e)&&(N[e]=new WebSocket(e),g.once("SOCKET_OPERATION_TERMINATED",()=>{N[e].close()}),g.once("OPERATION_FAILED",()=>{g.emit("SOCKET_OPERATION_TERMINATED")}),N[e].onopen=()=>{g.emit("SOCKET_OPENED")},N[e].onclose=()=>{},N[e].onerror=()=>++t<=ur?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${ur}`),fr(e,t)):(g.emit("SOCKET_ONERROR"),D(new De(`Unable to connect to WebSocket ${e}.`)))),fn(e).andThen(()=>T(e)).orElse(r=>D(r))),fn=e=>O.fromPromise(new Promise((t,r)=>{Et(e)?t(void 0):(g.once("SOCKET_OPENED",()=>{t(void 0)}),g.on("SOCKET_ONERROR",()=>{r(new De)}))}),t=>Q(t));var lr=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},ln=e=>lr(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),hn=e=>lr(new URL(e.serverUrl),"upload").toString(),pn=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},dn=e=>typeof e=="object"&&e!==null&&!("msg"in e);var pr=xe(Ge());var gn=xe(Ge());var En={},Ms=new pr.default;var wn=()=>Object.values(En).filter(e=>e.uploadStatus===4),dr=e=>Object.keys(wn()).indexOf(e);var Lt=xe(yr(),1);var Re=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ot=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},gr=e=>globalThis.DOMException===void 0?new Ot(e):new DOMException(e),vr=e=>{let t=e.reason===void 0?gr("This operation was aborted."):e.reason;return t instanceof Error?t:gr(t)};function xt(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,u=new Promise((f,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:m}=t;m.aborted&&l(vr(m));let d=()=>{l(vr(m))};m.addEventListener("abort",d,{once:!0}),e.finally(()=>{m.removeEventListener("abort",d)})}if(r===Number.POSITIVE_INFINITY){e.then(f,l);return}let h=new Re;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?l(o):(h.message=o!=null?o:`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await e)}catch(m){l(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Dt(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var Y,Ie=class{constructor(){L(this,Y,[])}enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,run:t};if(this.size&&p(this,Y)[this.size-1].priority>=r.priority){p(this,Y).push(n);return}let o=Dt(p(this,Y),n,(i,s)=>s.priority-i.priority);p(this,Y).splice(o,0,n)}dequeue(){let t=p(this,Y).shift();return t==null?void 0:t.run}filter(t){return p(this,Y).filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return p(this,Y).length}};Y=new WeakMap;var he,pe,oe,Ue,de,Ne,W,me,I,Fe,z,ye,re,Be,y,Er,wr,Ar,br,Lr,tt,_t,kt,rt,Or,nt,Me=class extends Lt.default{constructor(r){var n,o,i,s;super();L(this,y);L(this,he);L(this,pe);L(this,oe,0);L(this,Ue);L(this,de);L(this,Ne,0);L(this,W);L(this,me);L(this,I);L(this,Fe);L(this,z,0);L(this,ye);L(this,re);L(this,Be);E(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ie,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(o=(n=r.intervalCap)==null?void 0:n.toString())!=null?o:""}\` (${typeof r.intervalCap})`);if(r.interval===void 0||!(Number.isFinite(r.interval)&&r.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(s=(i=r.interval)==null?void 0:i.toString())!=null?s:""}\` (${typeof r.interval})`);w(this,he,r.carryoverConcurrencyCount),w(this,pe,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),w(this,Ue,r.intervalCap),w(this,de,r.interval),w(this,I,new r.queueClass),w(this,Fe,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,w(this,Be,r.throwOnTimeout===!0),w(this,re,r.autoStart===!1)}get concurrency(){return p(this,ye)}set concurrency(r){if(!(typeof r=="number"&&r>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${r}\` (${typeof r})`);w(this,ye,r),x(this,y,rt).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,Be),...n},new Promise((o,i)=>{p(this,I).enqueue(async()=>{var s;He(this,z)._++,He(this,oe)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=xt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,x(this,y,Or).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof Re&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{x(this,y,Ar).call(this)}},n),this.emit("add"),x(this,y,tt).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return p(this,re)?(w(this,re,!1),x(this,y,rt).call(this),this):this}pause(){w(this,re,!0)}clear(){w(this,I,new(p(this,Fe)))}async onEmpty(){p(this,I).size!==0&&await x(this,y,nt).call(this,"empty")}async onSizeLessThan(r){p(this,I).sizep(this,I).size{x(this,y,br).call(this)},n)),!0}return!1},tt=function(){if(p(this,I).size===0)return p(this,W)&&clearInterval(p(this,W)),w(this,W,void 0),this.emit("empty"),p(this,z)===0&&this.emit("idle"),!1;if(!p(this,re)){let r=!p(this,y,Lr);if(p(this,y,Er)&&p(this,y,wr)){let n=p(this,I).dequeue();return n?(this.emit("active"),n(),r&&x(this,y,_t).call(this),!0):!1}}return!1},_t=function(){p(this,pe)||p(this,W)!==void 0||(w(this,W,setInterval(()=>{x(this,y,kt).call(this)},p(this,de))),w(this,Ne,Date.now()+p(this,de)))},kt=function(){p(this,oe)===0&&p(this,z)===0&&p(this,W)&&(clearInterval(p(this,W)),w(this,W,void 0)),w(this,oe,p(this,he)?p(this,z):0),x(this,y,rt).call(this)},rt=function(){for(;x(this,y,tt).call(this););},Or=async function(r){return new Promise((n,o)=>{r.addEventListener("abort",()=>{o(r.reason)},{once:!0})})},nt=async function(r,n){return new Promise(o=>{let i=()=>{n&&!n()||(this.off(r,i),o())};this.on(r,i)})};var xr=!1,Ct=navigator.hardwareConcurrency||4,ge=new Me({concurrency:Ct,autoStart:!1}),it=0,st=[],ot=!1;self.onmessage=e=>{let t=e.data,{chunk:r,lufiFile:n}=t.args;if(xr||(Qt(),xr=!0),r){if(st[r.index]=r,st.length===n.totalChunks)return g.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),g.on("FILE_UPDATED",ee),g.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),it--,!ot&&itOn(e,dr(e.args.lufiFile.keys.client)),On=(e,t)=>{let{lufiFile:r}=e.args,n=new Worker(Z("encrypt"),{type:"module"});return g.on("UPLOAD_STARTED",()=>{n.onmessage=async o=>{if(o.data.encryptedData){let{encryptedData:i}=o.data;await ge.add(async()=>{await wt(r,{total:r.totalChunks,part:o.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:r.keys.server,i:t,file_pwd:r.password},i),it++,(ot||it===Ct)&&ge.pause()})}ge.start(),o.data.error&&(Ye(r,o.data.error),n.terminate())};for(let o=1;o{if(o.data.encryptedData){let{encryptedData:i}=o.data;wt(r,{total:r.totalChunks,part:o.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:null,i:t,file_pwd:r.password},i).mapErr(s=>{Ye(r,s)})}o.data.error&&Ye(r,o.data.error)},e.args.chunk=st[0],n.postMessage(e),T(void 0)};