var Ur=Object.create;var ht=Object.defineProperty;var Mr=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var Fr=Object.getPrototypeOf,Br=Object.prototype.hasOwnProperty;var Nt=e=>{throw TypeError(e)};var jr=(e,t,r)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Wr=(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 pt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var zr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Nr(t))!Br.call(e,i)&&i!==r&&ht(e,i,{get:()=>t[i],enumerable:!(n=Mr(t,i))||n.enumerable});return e};var be=(e,t,r)=>(r=e!=null?Ur(Fr(e)):{},zr(t||!e||!e.__esModule?ht(r,"default",{value:e,enumerable:!0}):r,e));var E=(e,t,r)=>jr(e,typeof t!="symbol"?t+"":t,r),dt=(e,t,r)=>t.has(e)||Nt("Cannot "+r);var p=(e,t,r)=>(dt(e,t,"read from private field"),r?r.call(e):t.get(e)),x=(e,t,r)=>t.has(e)?Nt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),w=(e,t,r,n)=>(dt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),D=(e,t,r)=>(dt(e,t,"access private method"),r);var Ge=(e,t,r,n)=>({set _(i){w(e,t,i,r)},get _(){return p(e,t,n)}});var Ve=pt((ti,vt)=>{"use strict";var se=typeof Reflect=="object"?Reflect:null,Jt=se&&typeof se.apply=="function"?se.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Ke;se&&typeof se.ownKeys=="function"?Ke=se.ownKeys:Object.getOwnPropertySymbols?Ke=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Ke=function(t){return Object.getOwnPropertyNames(t)};function Xr(e){console&&console.warn&&console.warn(e)}var $t=Number.isNaN||function(t){return t!==t};function g(){g.init.call(this)}vt.exports=g;vt.exports.once=Zr;g.EventEmitter=g;g.prototype._events=void 0;g.prototype._eventsCount=0;g.prototype._maxListeners=void 0;var Ht=10;function Xe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return Ht},set:function(e){if(typeof e!="number"||e<0||$t(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ht=e}});g.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};g.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||$t(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 qt(e){return e._maxListeners===void 0?g.defaultMaxListeners:e._maxListeners}g.prototype.getMaxListeners=function(){return qt(this)};g.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=o[t];if(u===void 0)return!1;if(typeof u=="function")Jt(u,this,r);else for(var f=u.length,l=Qt(u,f),n=0;n0&&s.length>i&&!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,Xr(c)}return e}g.prototype.addListener=function(t,r){return Gt(this,t,r,!1)};g.prototype.on=g.prototype.addListener;g.prototype.prependListener=function(t,r){return Gt(this,t,r,!0)};function Vr(){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 Kt(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Vr.bind(n);return i.listener=r,n.wrapFn=i,i}g.prototype.once=function(t,r){return Xe(r),this.on(t,Kt(this,t,r)),this};g.prototype.prependOnceListener=function(t,r){return Xe(r),this.prependListener(t,Kt(this,t,r)),this};g.prototype.removeListener=function(t,r){var n,i,o,s,c;if(Xe(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Qr(n,o),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};g.prototype.off=g.prototype.removeListener;g.prototype.removeAllListeners=function(t){var r,n,i;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 o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(t,r[i]);return this};function Xt(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Yr(i):Qt(i,i.length)}g.prototype.listeners=function(t){return Xt(this,t,!0)};g.prototype.rawListeners=function(t){return Xt(this,t,!1)};g.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Vt.call(e,t)};g.prototype.listenerCount=Vt;function Vt(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}g.prototype.eventNames=function(){return this._eventsCount>0?Ke(this._events):[]};function Qt(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,i,o=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),i=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[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],i[t]=4>=e||4>t?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return nr(this,e,0)},decrypt:function(e){return nr(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],i,o,s,c=[],u=[],f,l,h,m;for(i=0;256>i;i++)u[(c[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[o]=h,n[h]=o,l=c[i=c[f=c[o]]],m=16843009*l^65537*i^257*f^16843008*o,l=257*c[h]^16843008*h,i=0;4>i;i++)e[i][o]=l=l<<24^l>>>8,t[i][h]=m=m<<24^m>>>8;for(i=0;5>i;i++)e[i]=e[i].slice(0),t[i]=t[i].slice(0)}};function nr(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],i=t[0]^n[0],o=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 O=c[1],N=c[2],z=c[3],Q=c[4];for(h=0;h>>24]^O[o>>16&255]^N[s>>8&255]^z[t&255]^n[m],u=e[o>>>24]^O[s>>16&255]^N[t>>8&255]^z[i&255]^n[m+1],f=e[s>>>24]^O[t>>16&255]^N[i>>8&255]^z[o&255]^n[m+2],t=e[t>>>24]^O[i>>16&255]^N[o>>8&255]^z[s&255]^n[m+3],m+=4,i=c,o=u,s=f;for(h=0;4>h;h++)d[r?3&-h:h]=Q[i>>>24]<<24^Q[o>>16&255]<<16^Q[s>>8&255]<<8^Q[t&255]^n[m++],c=i,i=o,o=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[i]<<32-t;return i=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(i),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,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>i)>>>26),6>i?(s=e[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,i=0,o=a.codec.base64.S,s=0,c;for(t&&(o=o.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>i),s=c<<32-i):(i+=6,s^=c<<32-i)}return i&56&&r.push(a.bitArray.partial(i&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(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(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,i=this.g,o=this.b,s=i[0],c=i[1],u=i[2],f=i[3],l=i[4],h=i[5],m=i[6],d=i[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))+o[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;i[0]=i[0]+s|0,i[1]=i[1]+c|0,i[2]=i[2]+u|0,i[3]=i[3]+f|0,i[4]=i[4]+l|0,i[5]=i[5]+h|0,i[6]=i[6]+m|0,i[7]=i[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(o=!0,i=2;i*i<=n;i++)if(n%i===0){o=!1;break}o&&(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,i=this.b,o=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],O=n[9],N=n[10],z=n[11],Q=n[12],Je=n[13],It=n[14],He=n[15],T;if(typeof Uint32Array<"u"){T=Array(160);for(var _=0;32>_;_++)T[_]=e[_]}else T=e;var _=o,I=s,ye=c,ne=u,ve=f,ie=l,ct=h,ge=m,J=d,U=O,$e=N,Ee=z,qe=Q,we=Je,ut=It,Ae=He;for(e=0;80>e;e++){if(16>e)t=T[2*e],r=T[2*e+1];else{r=T[2*(e-15)];var A=T[2*(e-15)+1];t=(A<<31|r>>>1)^(A<<24|r>>>8)^r>>>7;var H=(r<<31|A>>>1)^(r<<24|A>>>8)^(r<<25|A>>>7);r=T[2*(e-2)];var q=T[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),ft=T[2*(e-7)],lt=T[2*(e-16)],Le=T[2*(e-16)+1];r=H+T[2*(e-7)+1],t=t+ft+(r>>>0>>0?1:0),r+=q,t+=A+(r>>>0>>0?1:0),r+=Le,t+=lt+(r>>>0>>0?1:0)}T[2*e]=t|=0,T[2*e+1]=r|=0;var ft=J&$e^~J&qe,Ut=U&Ee^~U&we,q=_&ye^_&ve^ye&ve,Pr=I&ne^I&ie^ne&ie,lt=(I<<4|_>>>28)^(_<<30|I>>>2)^(_<<25|I>>>7),Le=(_<<4|I>>>28)^(I<<30|_>>>2)^(I<<25|_>>>7),Ir=i[2*e],Mt=i[2*e+1],A=Ae+((J<<18|U>>>14)^(J<<14|U>>>18)^(U<<23|J>>>9)),H=ut+((U<<18|J>>>14)^(U<<14|J>>>18)^(J<<23|U>>>9))+(A>>>0>>0?1:0),A=A+Ut,H=H+(ft+(A>>>0>>0?1:0)),A=A+Mt,H=H+(Ir+(A>>>0>>0?1:0)),A=A+r|0,H=H+(t+(A>>>0>>0?1:0));r=Le+Pr,t=lt+q+(r>>>0>>0?1:0),ut=qe,Ae=we,qe=$e,we=Ee,$e=J,Ee=U,U=ge+A|0,J=ct+H+(U>>>0>>0?1:0)|0,ct=ve,ge=ie,ve=ye,ie=ne,ye=_,ne=I,I=A+r|0,_=H+t+(I>>>0>>0?1:0)|0}s=n[1]=s+I|0,n[0]=o+_+(s>>>0>>0?1:0)|0,u=n[3]=u+ne|0,n[2]=c+ye+(u>>>0>>0?1:0)|0,l=n[5]=l+ie|0,n[4]=f+ve+(l>>>0>>0?1:0)|0,m=n[7]=m+ge|0,n[6]=h+ct+(m>>>0>>0?1:0)|0,O=n[9]=O+U|0,n[8]=d+J+(O>>>0>>0?1:0)|0,z=n[11]=z+Ee|0,n[10]=N+$e+(z>>>0>>0?1:0)|0,Je=n[13]=Je+we|0,n[12]=Q+qe+(Je>>>0>>0?1:0)|0,He=n[15]=He+Ae|0,n[14]=It+ut+(He>>>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(o=2;4>o&&f>>>8*o;o++);return o<15-u&&(o=15-u),r=c.clamp(r,8*(15-o)),t=a.mode.ccm.U(e,t,r,n,i,o),s=a.mode.ccm.V(e,s,r,t,i,o),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,i){i=i||64,n=n||[];var o=a.bitArray,s=o.bitLength(r)/8,f=o.bitLength(t),c=o.clamp(t,f-i),u=o.bitSlice(t,f-i),f=(f-i)/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=o.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,i,t),e=a.mode.ccm.U(e,c.data,r,n,i,t),!o.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,i,o){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|o-1)],n=c.concat(n,r),n[3]|=i,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;ti||16l&&(a.mode.ccm.da(s/u),l+=h),r[3]++,i=e.encrypt(r),t[s]^=i[0],t[s+1]^=i[1],t[s+2]^=i[2],t[s+3]^=i[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,i=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>i&&(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)),i=i||a.misc.hmac,e=new i(e);var o,s,c,u,f=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(i=o=e.encrypt(l.concat(t,[u])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=o),this.N++,this.b=a.hash.sha256.hash(this.b.concat(i)),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,o,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,o,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&&ir("seeded",Math.max(this.u,this.i)),ir("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,i=this.J[e],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===t&&o.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(et=typeof ce<"u"&&ce.exports){try{tt=Wr("crypto")}catch{tt=null}et=Ze=tt}if(et&&Ze.randomBytes)ke=Ze.randomBytes(128),ke=new Uint32Array(new Uint8Array(ke).buffer),a.random.addEntropy(ke,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Te=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Te);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Te);else break e;a.random.addEntropy(Te,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 ke,Ze,Te,et,tt;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 i=a.json,o=i.j({iv:a.random.randomWords(4,0)},i.defaults),s;if(i.j(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=a.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=a.codec.base64.toBits(o.iv)),!a.mode[o.mode]||!a.cipher[o.cipher]||typeof e=="string"&&100>=o.iter||o.ts!==64&&o.ts!==96&&o.ts!==128||o.ks!==128&&o.ks!==192&&o.ks!==256||2>o.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 On=Object.prototype.hasOwnProperty,S="~";function Re(){}Object.create&&(Re.prototype=Object.create(null),new Re().__proto__||(S=!1));function xn(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Ar(e,t,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new xn(r,n||e,i),s=S?S+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],o]:e._events[s].push(o):(e._events[s]=o,e._eventsCount++),e}function rt(e,t){--e._eventsCount===0?e._events=new Re:delete e._events[t]}function k(){this._events=new Re,this._eventsCount=0}k.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)On.call(r,n)&&t.push(S?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};k.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 i=0,o=n.length,s=new Array(o);i{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:i}};function oe(e,t,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,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?o(l.value):i(l.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ft(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 Bt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(d){return function(O){return Promise.resolve(O).then(d,h)}}function c(d,O){n[d]&&(i[d]=function(N){return new Promise(function(z,Q){o.push([d,N,z,Q])>1||u(d,N)})},O&&(i[d]=O(i[d])))}function u(d,O){try{f(n[d](O))}catch(N){m(o[0][3],N)}}function f(d){d.value instanceof G?Promise.resolve(d.value.v).then(l,h):m(o[0][2],d)}function l(d){u("next",d)}function h(d){u("throw",d)}function m(d,O){d(O),o.shift(),o.length&&u(o[0][0],o[0][1])}}function Hr(e){var t,r;return t={},n("next"),n("throw",function(i){throw i}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(i,o){t[i]=e[i]?function(s){return(r=!r)?{value:G(e[i](s)),done:!1}:o?o(s):s}:o}}function $r(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 Ft=="function"?Ft(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=e[o]&&function(s){return new Promise(function(c,u){s=e[o](s),i(c,u,s.done,s.value)})}}function i(o,s,c,u){Promise.resolve(u).then(function(f){o({value:f,done:c})},s)}}var b=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new F(n));return new e(r)}static fromPromise(t,r){let n=t.then(i=>new F(i)).catch(i=>new B(r(i)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(oe(this,void 0,void 0,function*(){try{return new F(yield t(...n))}catch(i){return new B(r?r(i):i)}}))}static combine(t){return qr(t)}static combineWithAllErrors(t){return Gr(t)}map(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isErr()?new B(r.error):new F(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);let n=yield t(r.value);return n.isErr()?new B(n.error):new F(r.value)})))}andTee(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);try{yield t(r.value)}catch{}return new F(r.value)})))}mapErr(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isOk()?new F(r.value):new B(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new B(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new F(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 Bt(this,arguments,function*(){return yield G(yield G(yield*Hr($r(yield G(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Bt(this,arguments,function*(){let r=yield G(this._promise);return r.isErr()&&(yield yield G(L(r.error))),yield G(r.value)})}},C=e=>new b(Promise.resolve(new F(e))),L=e=>new b(Promise.resolve(new B(e))),Cn=b.fromPromise,kn=b.fromSafePromise,Tn=b.fromThrowable,Wt=e=>{let t=re([]);for(let r of e)if(r.isErr()){t=Y(r.error);break}else t.map(n=>n.push(r.value));return t},qr=e=>b.fromSafePromise(Promise.all(e)).andThen(Wt),zt=e=>{let t=re([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=Y([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Gr=e=>b.fromSafePromise(Promise.all(e)).andThen(zt),mt;(function(e){function t(i,o){return(...s)=>{try{let c=i(...s);return re(c)}catch(c){return Y(o?o(c):c)}}}e.fromThrowable=t;function r(i){return Wt(i)}e.combine=r;function n(i){return zt(i)}e.combineWithAllErrors=n})(mt||(mt={}));var re=e=>new F(e);function Y(e){return new B(e)}var F=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return re(t(this.value))}mapErr(t){return re(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 re(this.value)}orElse(t){return re(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return b.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 jt("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},B=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return Y(this.error)}mapErr(t){return Y(t(this.error))}andThrough(t){return Y(this.error)}andTee(t){return Y(this.error)}andThen(t){return Y(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return L(this.error)}asyncAndThrough(t){return L(this.error)}asyncMap(t){return L(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield Y(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw jt("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Rn=mt.fromThrowable;var R=class extends Error{constructor(r,n={}){let{cause:i,context:o}=n;super(r,{cause:i});E(this,"context");this.name=this.constructor.name,this.context=o}};var K=class extends R{};var Oe=class extends K{constructor(){super(...arguments);E(this,"message","An error occured while trying to connect to WebSocket")}};var $=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 Kr=()=>typeof Deno<"u";var yt=e=>Kr()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e!=="encrypt"?`worker/${e}`:e}.js`));var er=be(Ve());var v=new er.default,Z=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e),gt=(e,t)=>{Z(e,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:t})},tr=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var ae=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),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}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),i,o,s,c,u=0,f=0;for(;u>4,n[u++]=(o&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var rr=new ae("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function xe(e){return rr.Encode(e)}function De(e){return rr.Decode(e)}var tn=new ae("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function Et(e){return tn.Decode(e)}var Lt=be(sr());var X=class extends R{};var ue=class extends X{constructor(){super(...arguments);E(this,"message","Unable to decrypt the provided data")}};var fe=class extends X{constructor(){super(...arguments);E(this,"message","Unable to encrypt the provided data")}};var ar=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return C(De(Lt.default.decrypt(e,r)))}catch(r){return L(new ue(void 0,{cause:$(r)}))}},cr=(e,t)=>{try{let r=Lt.default.encrypt(e,xe(t));return C({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return L(new fe(void 0,{cause:$(r)}))}};var ur=(e,t)=>lr(e).andThen(r=>b.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,De(t.data)),n=>new ue(void 0,{cause:$(n)}))),fr=(e,t)=>lr(e).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return b.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,t),i=>new fe(void 0,{cause:$(i)})).andThen(i=>C({algo:1,data:xe(i),iv:n}))}),lr=e=>b.fromPromise(crypto.subtle.importKey("raw",Et(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new X("Unable to import cryptography key",{cause:$(t)}));var hr=(e,t)=>t.algo===void 0||t.algo===0?ar(e,t):ur(e,t),pr=(e,t,r)=>(r===1&&typeof t=="string"&&(t=new TextEncoder().encode(t).buffer),r===0?cr(e,t):fr(e,t));var M={},mr=5,an=e=>(v.emit("UPLOAD_CANCELLED",e.success),C(void 0)),cn=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let i=JSON.parse(n);if(vn(i)){let o=r.shift();if(o){let s=JSON.parse(o);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),hr(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return i.part===0?(Z(t,{chunksReady:t.chunksReady+1,delAtFirstView:i.del_at_first_view,delay:i.delay,name:i.name,size:i.size,totalChunks:i.total,type:i.type,zipped:i.zipped}),v.emit("DOWNLOAD_STARTED")):Z(t,{chunksReady:t.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,i.part),++i.part===i.total?hn(t).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),C(void 0))):C(void 0)})}else{let s=new K("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),L(s)}}else{let o=new K(i.msg);return v.emit("OPERATION_FAILED",o),L(o)}}else{let i=new K("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",i),L(i)}},un=(e,t)=>{if(e.success)return e.j===0&&(Z(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),v.emit("UPLOAD_STARTED")),Z(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),v.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Z(t,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),C(void 0);{let r=new K(e.msg);return v.emit("OPERATION_FAILED",r),L(r)}},fn=(e,t)=>{let r=yn(e.data),n;if(r)if(!r.action&&r.msg){let i=new K(r.msg);return v.emit("OPERATION_FAILED",i),L(i)}else"delay"in r?n=un(r,t):n=an(r);else n=cn(e.data,t);return n},ln=e=>M!==void 0&&M[e]!==void 0&&M[e].readyState===WebSocket.CONNECTING,bt=e=>M!==void 0&&M[e]!==void 0&&M[e].readyState===WebSocket.OPEN;var hn=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},xt(dn(e),e,JSON.stringify(t))},Ot=(e,t,r)=>xt(mn(e),e,`${JSON.stringify(t)}XXMOJOXX${JSON.stringify(r)}`),xt=(e,t,r)=>bt(e)?(M[e].onmessage=n=>fn(n,t),M[e].send(r),C(void 0)):yr(e).andThen(()=>xt(e,t,r)),yr=(e,t=0)=>(!bt(e)&&!ln(e)&&(M[e]=new WebSocket(e),v.once("SOCKET_OPERATION_TERMINATED",()=>{M[e].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),M[e].onopen=()=>{v.emit("SOCKET_OPENED")},M[e].onclose=()=>{},M[e].onerror=()=>++t<=mr?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${mr}`),yr(e,t)):(v.emit("SOCKET_ONERROR"),L(new Oe(`Unable to connect to WebSocket ${e}.`)))),pn(e).andThen(()=>C(e)).orElse(r=>L(r))),pn=e=>b.fromPromise(new Promise((t,r)=>{bt(e)?t(void 0):(v.once("SOCKET_OPENED",()=>{t(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new Oe)}))}),t=>$(t));var vr=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},dn=e=>vr(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),mn=e=>vr(new URL(e.serverUrl),"upload").toString(),yn=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},vn=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Er=be(Ve());var wn=be(Ve());var Ln={},Os=new Er.default;var bn=()=>Object.values(Ln).filter(e=>e.uploadStatus===4),wr=e=>Object.keys(bn()).indexOf(e);var _t=be(Lr(),1);var Se=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ct=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},br=e=>globalThis.DOMException===void 0?new Ct(e):new DOMException(e),Or=e=>{let t=e.reason===void 0?br("This operation was aborted."):e.reason;return t instanceof Error?t:br(t)};function kt(e,t){let{milliseconds:r,fallback:n,message:i,customTimers:o={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(Or(m));let d=()=>{l(Or(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 Se;s=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof e.cancel=="function"&&e.cancel(),i===!1?f():i instanceof Error?l(i):(h.message=i!=null?i:`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await e)}catch(m){l(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},u}function Tt(e,t,r){let n=0,i=e.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(e[s],t)<=0?(n=++s,i-=o+1):i=o}return n}var V,Pe=class{constructor(){x(this,V,[])}enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,run:t};if(this.size&&p(this,V)[this.size-1].priority>=r.priority){p(this,V).push(n);return}let i=Tt(p(this,V),n,(o,s)=>s.priority-o.priority);p(this,V).splice(i,0,n)}dequeue(){let t=p(this,V).shift();return t==null?void 0:t.run}filter(t){return p(this,V).filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return p(this,V).length}};V=new WeakMap;var le,he,te,Ue,pe,Me,j,de,P,Ne,W,me,ee,Fe,y,xr,Dr,_r,Cr,kr,nt,Rt,St,it,Tr,ot,Ie=class extends _t.default{constructor(r){var n,i,o,s;super();x(this,y);x(this,le);x(this,he);x(this,te,0);x(this,Ue);x(this,pe);x(this,Me,0);x(this,j);x(this,de);x(this,P);x(this,Ne);x(this,W,0);x(this,me);x(this,ee);x(this,Fe);E(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Pe,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(i=(n=r.intervalCap)==null?void 0:n.toString())!=null?i:""}\` (${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=(o=r.interval)==null?void 0:o.toString())!=null?s:""}\` (${typeof r.interval})`);w(this,le,r.carryoverConcurrencyCount),w(this,he,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),w(this,Ue,r.intervalCap),w(this,pe,r.interval),w(this,P,new r.queueClass),w(this,Ne,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,w(this,Fe,r.throwOnTimeout===!0),w(this,ee,r.autoStart===!1)}get concurrency(){return p(this,me)}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,me,r),D(this,y,it).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,Fe),...n},new Promise((i,o)=>{p(this,P).enqueue(async()=>{var s;Ge(this,W)._++,Ge(this,te)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=kt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,D(this,y,Tr).call(this,n.signal)]));let u=await c;i(u),this.emit("completed",u)}catch(c){if(c instanceof Se&&!n.throwOnTimeout){i();return}o(c),this.emit("error",c)}finally{D(this,y,_r).call(this)}},n),this.emit("add"),D(this,y,nt).call(this)})}async addAll(r,n){return Promise.all(r.map(async i=>this.add(i,n)))}start(){return p(this,ee)?(w(this,ee,!1),D(this,y,it).call(this),this):this}pause(){w(this,ee,!0)}clear(){w(this,P,new(p(this,Ne)))}async onEmpty(){p(this,P).size!==0&&await D(this,y,ot).call(this,"empty")}async onSizeLessThan(r){p(this,P).sizep(this,P).size{D(this,y,Cr).call(this)},n)),!0}return!1},nt=function(){if(p(this,P).size===0)return p(this,j)&&clearInterval(p(this,j)),w(this,j,void 0),this.emit("empty"),p(this,W)===0&&this.emit("idle"),!1;if(!p(this,ee)){let r=!p(this,y,kr);if(p(this,y,xr)&&p(this,y,Dr)){let n=p(this,P).dequeue();return n?(this.emit("active"),n(),r&&D(this,y,Rt).call(this),!0):!1}}return!1},Rt=function(){p(this,he)||p(this,j)!==void 0||(w(this,j,setInterval(()=>{D(this,y,St).call(this)},p(this,pe))),w(this,Me,Date.now()+p(this,pe)))},St=function(){p(this,te)===0&&p(this,W)===0&&p(this,j)&&(clearInterval(p(this,j)),w(this,j,void 0)),w(this,te,p(this,le)?p(this,W):0),D(this,y,it).call(this)},it=function(){for(;D(this,y,nt).call(this););},Tr=async function(r){return new Promise((n,i)=>{r.addEventListener("abort",()=>{i(r.reason)},{once:!0})})},ot=async function(r,n){return new Promise(i=>{let o=()=>{n&&!n()||(this.off(r,o),i())};this.on(r,o)})};var st=class extends R{};var Be=class extends st{constructor(){super(...arguments);E(this,"message","Parameter cannot be undefined")}};var Rr=!1,Pt=navigator.hardwareConcurrency||1,We=new Ie({concurrency:Pt,autoStart:!1}),ze=0,at=!1,je,Sr=new Worker(yt("encrypt"),{type:"module"});self.onmessage=e=>{if(Rr||(tr(),Rr=!0,je=e.data.args.lufiFile,v.once("UPLOAD_STARTED",()=>{self.postMessage({event:"UPLOAD_STARTED"})}),v.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),ze--,!at&&ze{self.postMessage({event:"UPLOAD_COMPLETE"})}),v.on("FILE_UPDATED",Z)),e.data.args.chunk)return e.data.args.lufiFile=je,Dn(e.data,wr(je.keys.client)).mapErr(t=>{gt(je,t)});e.data.action===0?(at=!0,We.pause(),self.postMessage({event:"JOB_PAUSED"})):e.data.action===2?(at=!1,We.start(),self.postMessage({event:"JOB_RESUMED"})):gt(je,new Be)};var Dn=(e,t)=>{let{lufiFile:r,algo:n}=e.args;if(e.args.chunk&&n)e.args.chunk.index===0?pr(r.keys.client,e.args.chunk.buffer,n).map(i=>{Ot(r,{total:r.totalChunks,part:0,size:r.size,name:r.name,type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:null,i:t,file_pwd:r.password},i),ze++}):We.add(()=>{if(e.args.chunk){let i=()=>(ze++,new Promise(o=>{Sr.onmessage=s=>{e.args.chunk&&o(Ot(r,{total:r.totalChunks,part:e.args.chunk.index,size:r.size,name:r.name,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},s.data.encryptedData))}}));return Sr.postMessage(e,[e.args.chunk.buffer]),(at||ze===Pt)&&We.pause(),i()}});else return L(new Be("algo must be defined"));return C(void 0)};