lufi/themes/default/public/js/worker/download.js

2 lines
54 KiB
JavaScript

var Ar=Object.create;var it=Object.defineProperty;var xr=Object.getOwnPropertyDescriptor;var Or=Object.getOwnPropertyNames;var Lr=Object.getPrototypeOf,br=Object.prototype.hasOwnProperty;var Dt=t=>{throw TypeError(t)};var _r=(t,e,r)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Dr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var st=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Cr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Or(e))!br.call(t,o)&&o!==r&&it(t,o,{get:()=>e[o],enumerable:!(n=xr(e,o))||n.enumerable});return t};var at=(t,e,r)=>(r=t!=null?Ar(Lr(t)):{},Cr(e||!t||!t.__esModule?it(r,"default",{value:t,enumerable:!0}):r,t));var U=(t,e,r)=>_r(t,typeof e!="symbol"?e+"":e,r),ct=(t,e,r)=>e.has(t)||Dt("Cannot "+r);var d=(t,e,r)=>(ct(t,e,"read from private field"),r?r.call(t):e.get(t)),x=(t,e,r)=>e.has(t)?Dt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),g=(t,e,r,n)=>(ct(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),O=(t,e,r)=>(ct(t,e,"access private method"),r);var ze=(t,e,r,n)=>({set _(o){g(t,e,o,r)},get _(){return d(t,e,n)}});var Bt=st((vn,ut)=>{"use strict";var se=typeof Reflect=="object"?Reflect:null,Ct=se&&typeof se.apply=="function"?se.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Je;se&&typeof se.ownKeys=="function"?Je=se.ownKeys:Object.getOwnPropertySymbols?Je=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Je=function(e){return Object.getOwnPropertyNames(e)};function Sr(t){console&&console.warn&&console.warn(t)}var kt=Number.isNaN||function(e){return e!==e};function w(){w.init.call(this)}ut.exports=w;ut.exports.once=Tr;w.EventEmitter=w;w.prototype._events=void 0;w.prototype._eventsCount=0;w.prototype._maxListeners=void 0;var St=10;function He(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(w,"defaultMaxListeners",{enumerable:!0,get:function(){return St},set:function(t){if(typeof t!="number"||t<0||kt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");St=t}});w.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};w.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||kt(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function Pt(t){return t._maxListeners===void 0?w.defaultMaxListeners:t._maxListeners}w.prototype.getMaxListeners=function(){return Pt(this)};w.prototype.emit=function(e){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var o=e==="error",i=this._events;if(i!==void 0)o=o&&i.error===void 0;else if(!o)return!1;if(o){var s;if(r.length>0&&(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[e];if(u===void 0)return!1;if(typeof u=="function")Ct(u,this,r);else for(var f=u.length,h=Ut(u,f),n=0;n<f;++n)Ct(h[n],this,r);return!0};function Rt(t,e,r,n){var o,i,s;if(He(r),i=t._events,i===void 0?(i=t._events=Object.create(null),t._eventsCount=0):(i.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),i=t._events),s=i[e]),s===void 0)s=i[e]=r,++t._eventsCount;else if(typeof s=="function"?s=i[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),o=Pt(t),o>0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,Sr(c)}return t}w.prototype.addListener=function(e,r){return Rt(this,e,r,!1)};w.prototype.on=w.prototype.addListener;w.prototype.prependListener=function(e,r){return Rt(this,e,r,!0)};function kr(){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 Tt(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=kr.bind(n);return o.listener=r,n.wrapFn=o,o}w.prototype.once=function(e,r){return He(r),this.on(e,Tt(this,e,r)),this};w.prototype.prependOnceListener=function(e,r){return He(r),this.prependListener(e,Tt(this,e,r)),this};w.prototype.removeListener=function(e,r){var n,o,i,s,c;if(He(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,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():Pr(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};w.prototype.off=w.prototype.removeListener;w.prototype.removeAllListeners=function(e){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[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o<i.length;++o)s=i[o],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(o=r.length-1;o>=0;o--)this.removeListener(e,r[o]);return this};function It(t,e,r){var n=t._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Rr(o):Ut(o,o.length)}w.prototype.listeners=function(e){return It(this,e,!0)};w.prototype.rawListeners=function(e){return It(this,e,!1)};w.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Mt.call(t,e)};w.prototype.listenerCount=Mt;function Mt(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}w.prototype.eventNames=function(){return this._eventsCount>0?Je(this._events):[]};function Ut(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function Pr(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function Rr(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function Tr(t,e){return new Promise(function(r,n){function o(s){t.removeListener(e,i),n(s)}function i(){typeof t.removeListener=="function"&&t.removeListener("error",o),r([].slice.call(arguments))}Nt(t,e,i,{once:!0}),e!=="error"&&Ir(t,o,{once:!0})})}function Ir(t,e,r){typeof t.on=="function"&&Nt(t,"error",e,r)}function Nt(t,e,r,n){if(typeof t.on=="function")n.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function o(i){n.once&&t.removeEventListener(e,o),r(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}});var Zt=st((io,fe)=>{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};a.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,o,i=this.w[0][4],s=this.w[1];e=t.length;var c=1;if(e!==4&&e!==6&&e!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],o[e]=4>=t||4>e?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(t){return Vt(this,t,0)},decrypt:function(t){return Vt(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,h,l,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(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=c[o=c[f=c[i]]],m=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)t[o][i]=h=h<<24^h>>>8,e[o][l]=m=m<<24^m>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function Vt(t,e,r){if(e.length!==4)throw new a.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var c,u,f,h=n.length/4-2,l,m=4,p=[0,0,0,0];c=t.w[r],t=c[0];var A=c[1],M=c[2],F=c[3],Y=c[4];for(l=0;l<h;l++)c=t[o>>>24]^A[i>>16&255]^M[s>>8&255]^F[e&255]^n[m],u=t[i>>>24]^A[s>>16&255]^M[e>>8&255]^F[o&255]^n[m+1],f=t[s>>>24]^A[e>>16&255]^M[o>>8&255]^F[i&255]^n[m+2],e=t[e>>>24]^A[o>>16&255]^M[i>>8&255]^F[s&255]^n[m+3],m+=4,o=c,i=u,s=f;for(l=0;4>l;l++)p[r?3&-l:l]=Y[o>>>24]<<24^Y[i>>16&255]<<16^Y[s>>8&255]<<8^Y[e&255]^n[m++],c=o,o=i,i=s,s=e,e=c;return p}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:a.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<<r)-1},concat:function(t,e){if(t.length===0||e.length===0)return t.concat(e);var r=t[t.length-1],n=a.bitArray.getPartial(r);return n===32?t.concat(e):a.bitArray.Y(e,n,r|0,t.slice(0,t.length-1))},bitLength:function(t){var e=t.length;return e===0?0:32*(e-1)+a.bitArray.getPartial(t[e-1])},clamp:function(t,e){if(32*t.length<e)return t;t=t.slice(0,Math.ceil(e/32));var r=t.length;return e=e&31,0<r&&e&&(t[r-1]=a.bitArray.partial(e,t[r-1]&2147483648>>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(a.bitArray.bitLength(t)!==a.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n<t.length;n++)r|=t[n]^e[n];return r===0},Y:function(t,e,r,n){var o;for(o=0,n===void 0&&(n=[]);32<=e;e-=32)n.push(r),r=0;if(e===0)return n.concat(t);for(o=0;o<t.length;o++)n.push(r|t[o]>>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=a.bitArray.getPartial(o),n.push(a.bitArray.partial(e+t&31,32<e+t?r:n.pop(),1)),n},P:function(t,e){return[t[0]^e[0],t[1]^e[1],t[2]^e[2],t[3]^e[3]]},byteswapM:function(t){var e,r;for(e=0;e<t.length;++e)r=t[e],t[e]=r>>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};a.codec.utf8String={fromBits:function(t){var e="",r=a.bitArray.bitLength(t),n,o;for(n=0;n<r/8;n++)!(n&3)&&(o=t[n/4]),e+=String.fromCharCode(o>>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r<t.length;r++)n=n<<8|t.charCodeAt(r),(r&3)===3&&(e.push(n),n=0);return r&3&&e.push(a.bitArray.partial(8*(r&3),n)),e}};a.codec.hex={fromBits:function(t){var e="",r;for(r=0;r<t.length;r++)e+=((t[r]|0)+0xf00000000000).toString(16).substr(4);return e.substr(0,a.bitArray.bitLength(t)/4)},toBits:function(t){var e,r=[],n;for(t=t.replace(/\s|0x/g,""),n=t.length,t=t+"00000000",e=0;e<t.length;e+=8)r.push(parseInt(t.substr(e,8),16)^0);return a.bitArray.clamp(r,4*n)}};a.codec.base64={S:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(t,e,r){var n="",o=0,i=a.codec.base64.S,s=0,c=a.bitArray.bitLength(t);for(r&&(i=i.substr(0,62)+"-_"),r=0;6*n.length<c;)n+=i.charAt((s^t[r]>>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(e&&(i=i.substr(0,62)+"-_"),n=0;n<t.length;n++){if(c=i.indexOf(t.charAt(n)),0>c)throw new a.exception.invalid("this isn't base64!");26<o?(o-=26,r.push(s^c>>>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(t){return a.codec.base64.fromBits(t,1,1)},toBits:function(t){return a.codec.base64.toBits(t,1)}};a.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};a.hash.sha256.hash=function(t){return new a.hash.sha256().update(t).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.f=a.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+a.bitArray.bitLength(t),9007199254740991<t)throw new a.exception.invalid("Cannot hash more than 2^53 - 1 bits");if(typeof Uint32Array<"u"){var n=new Uint32Array(r),o=0;for(e=512+e-(512+e&511);e<=t;e+=512)this.l(n.subarray(16*o,16*(o+1))),o+=1;r.splice(0,16*o)}else for(e=512+e-(512+e&511);e<=t;e+=512)this.l(r.splice(0,16));return this},finalize:function(){var t,r=this.f,e=this.g,r=a.bitArray.concat(r,[a.bitArray.partial(1,1)]);for(t=r.length+2;t&15;t++)r.push(0);for(r.push(Math.floor(this.c/4294967296)),r.push(this.c|0);r.length;)this.l(r.splice(0,16));return this.reset(),e},o:[],b:[],C:function(){function t(i){return 4294967296*(i-Math.floor(i))|0}for(var e=0,r=2,n,o;64>e;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],m=o[6],p=o[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+p+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(l^m))+i[e],p=m,m=l,l=h,h=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]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+m|0,o[7]=o[7]+p|0}};a.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};a.hash.sha512.hash=function(t){return new a.hash.sha512().update(t).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.f=a.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+a.bitArray.bitLength(t),9007199254740991<t)throw new a.exception.invalid("Cannot hash more than 2^53 - 1 bits");if(typeof Uint32Array<"u"){var n=new Uint32Array(r),o=0;for(e=1024+e-(1024+e&1023);e<=t;e+=1024)this.l(n.subarray(32*o,32*(o+1))),o+=1;r.splice(0,32*o)}else for(e=1024+e-(1024+e&1023);e<=t;e+=1024)this.l(r.splice(0,32));return this},finalize:function(){var t,r=this.f,e=this.g,r=a.bitArray.concat(r,[a.bitArray.partial(1,1)]);for(t=r.length+4;t&31;t++)r.push(0);for(r.push(0),r.push(0),r.push(Math.floor(this.c/4294967296)),r.push(this.c|0);r.length;)this.l(r.splice(0,32));return this.reset(),e},o:[],ia:[12372232,13281083,9762859,1914609,15106769,4090911,4308331,8266105],b:[],ka:[2666018,15689165,5061423,9034684,4764984,380953,1658779,7176472,197186,7368638,14987916,16757986,8096111,1480369,13046325,6891156,15813330,5187043,9229749,11312229,2818677,10937475,4324308,1135541,6741931,11809296,16458047,15666916,11046850,698149,229999,945776,13774844,2541862,12856045,9810911,11494366,7844520,15576806,8533307,15795044,4337665,16291729,5553712,15684120,6662416,7413802,12308920,13816008,4303699,9366425,10176680,13195875,4295371,6546291,11712675,15708924,1519456,15772530,6568428,6495784,8568297,13007125,7492395,2515356,12632583,14740254,7262584,1535930,13146278,16321966,1853211,294276,13051027,13221564,1051980,4080310,6651434,14088940,4675607],C:function(){function t(s){return 4294967296*(s-Math.floor(s))|0}function e(s){return 1099511627776*(s-Math.floor(s))&255}for(var r=0,n=2,o,i;80>r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],m=n[7],p=n[8],A=n[9],M=n[10],F=n[11],Y=n[12],Be=n[13],Lt=n[14],je=n[15],C;if(typeof Uint32Array<"u"){C=Array(160);for(var b=0;32>b;b++)C[b]=t[b]}else C=t;var b=i,R=s,ve=c,oe=u,we=f,ie=h,tt=l,ge=m,z=p,T=A,We=M,Ee=F,Fe=Y,Ae=Be,rt=Lt,xe=je;for(t=0;80>t;t++){if(16>t)e=C[2*t],r=C[2*t+1];else{r=C[2*(t-15)];var E=C[2*(t-15)+1];e=(E<<31|r>>>1)^(E<<24|r>>>8)^r>>>7;var J=(r<<31|E>>>1)^(r<<24|E>>>8)^(r<<25|E>>>7);r=C[2*(t-2)];var H=C[2*(t-2)+1],E=(H<<13|r>>>19)^(r<<3|H>>>29)^r>>>6,H=(r<<13|H>>>19)^(H<<3|r>>>29)^(r<<26|H>>>6),nt=C[2*(t-7)],ot=C[2*(t-16)],Oe=C[2*(t-16)+1];r=J+C[2*(t-7)+1],e=e+nt+(r>>>0<J>>>0?1:0),r+=H,e+=E+(r>>>0<H>>>0?1:0),r+=Oe,e+=ot+(r>>>0<Oe>>>0?1:0)}C[2*t]=e|=0,C[2*t+1]=r|=0;var nt=z&We^~z&Fe,bt=T&Ee^~T&Ae,H=b&ve^b&we^ve&we,gr=R&oe^R&ie^oe&ie,ot=(R<<4|b>>>28)^(b<<30|R>>>2)^(b<<25|R>>>7),Oe=(b<<4|R>>>28)^(R<<30|b>>>2)^(R<<25|b>>>7),Er=o[2*t],_t=o[2*t+1],E=xe+((z<<18|T>>>14)^(z<<14|T>>>18)^(T<<23|z>>>9)),J=rt+((T<<18|z>>>14)^(T<<14|z>>>18)^(z<<23|T>>>9))+(E>>>0<xe>>>0?1:0),E=E+bt,J=J+(nt+(E>>>0<bt>>>0?1:0)),E=E+_t,J=J+(Er+(E>>>0<_t>>>0?1:0)),E=E+r|0,J=J+(e+(E>>>0<r>>>0?1:0));r=Oe+gr,e=ot+H+(r>>>0<Oe>>>0?1:0),rt=Fe,xe=Ae,Fe=We,Ae=Ee,We=z,Ee=T,T=ge+E|0,z=tt+J+(T>>>0<ge>>>0?1:0)|0,tt=we,ge=ie,we=ve,ie=oe,ve=b,oe=R,R=E+r|0,b=J+e+(R>>>0<E>>>0?1:0)|0}s=n[1]=s+R|0,n[0]=i+b+(s>>>0<R>>>0?1:0)|0,u=n[3]=u+oe|0,n[2]=c+ve+(u>>>0<oe>>>0?1:0)|0,h=n[5]=h+ie|0,n[4]=f+we+(h>>>0<ie>>>0?1:0)|0,m=n[7]=m+ge|0,n[6]=l+tt+(m>>>0<ge>>>0?1:0)|0,A=n[9]=A+T|0,n[8]=p+z+(A>>>0<T>>>0?1:0)|0,F=n[11]=F+Ee|0,n[10]=M+We+(F>>>0<Ee>>>0?1:0)|0,Be=n[13]=Be+Ae|0,n[12]=Y+Fe+(Be>>>0<Ae>>>0?1:0)|0,je=n[15]=je+xe|0,n[14]=Lt+rt+(je>>>0<xe>>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(t){a.mode.ccm.F.push(t)},unListenProgress:function(t){t=a.mode.ccm.F.indexOf(t),-1<t&&a.mode.ccm.F.splice(t,1)},da:function(t){var e=a.mode.ccm.F.slice(),r;for(r=0;r<e.length;r+=1)e[r](t)},encrypt:function(t,e,r,n,o){var i,s=e.slice(0),c=a.bitArray,u=c.bitLength(r)/8,f=c.bitLength(s)/8;if(o=o||64,n=n||[],7>u)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)),e=a.mode.ccm.U(t,e,r,n,o,i),s=a.mode.ccm.V(t,s,r,e,o,i),c.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(e),c=i.clamp(e,f-o),u=i.bitSlice(e,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&f>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),c=a.mode.ccm.V(t,c,r,u,o,e),t=a.mode.ccm.U(t,c.data,r,n,o,e),!i.equal(c.tag,t))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=t.encrypt(n),e.length)for(r=c.bitLength(e)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,e),e=0;e<s.length;e+=4)n=t.encrypt(u(n,s.slice(e,e+4).concat([0,0,0])));return n},U:function(t,e,r,n,o,i){var s=a.bitArray,c=s.P;if(o/=8,o%2||4>o||16<o)throw new a.exception.invalid("ccm: invalid tag length");if(4294967295<n.length||4294967295<e.length)throw new a.exception.bug("ccm: can't deal with 4GiB or more data");for(r=a.mode.ccm.ma(t,n,r,o,s.bitLength(e)/8,i),n=0;n<e.length;n+=4)r=t.encrypt(c(r,e.slice(n,n+4).concat([0,0,0])));return s.clamp(r,8*o)},V:function(t,e,r,n,o,i){var s,c=a.bitArray;s=c.P;var u=e.length,f=c.bitLength(e),h=u/50,l=h;if(r=c.concat([c.partial(8,i-1)],r).concat([0,0,0]).slice(0,4),n=c.bitSlice(s(n,t.encrypt(r)),0,o),!u)return{tag:n,data:[]};for(s=0;s<u;s+=4)s>h&&(a.mode.ccm.da(s/u),h+=l),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:c.clamp(e,f)}}};a.misc.hmac=function(t,e){this.W=e=e||a.hash.sha256;var r=[[],[]],n,o=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>o&&(t=e.hash(t)),n=0;n<o;n++)r[0][n]=t[n]^909522486,r[1][n]=t[n]^1549556828;this.B[0].update(r[0]),this.B[1].update(r[1]),this.O=new e(this.B[0])};a.misc.hmac.prototype.encrypt=a.misc.hmac.prototype.mac=function(t){if(this.Z)throw new a.exception.invalid("encrypt on already updated hmac called!");return this.update(t),this.digest(t)};a.misc.hmac.prototype.reset=function(){this.O=new this.W(this.B[0]),this.Z=!1};a.misc.hmac.prototype.update=function(t){this.Z=!0,this.O.update(t)};a.misc.hmac.prototype.digest=function(){var t=this.O.finalize(),t=new this.W(this.B[1]).update(t).finalize();return this.reset(),t};a.misc.pbkdf2=function(t,e,r,n,o){if(r=r||1e4,0>n||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),o=o||a.misc.hmac,t=new o(t);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=t.encrypt(h.concat(e,[u])),s=1;s<r;s++)for(i=t.encrypt(i),c=0;c<i.length;c++)o[c]^=i[c];f=f.concat(o)}return n&&(f=h.clamp(f,n)),f};a.prng=function(t){this.h=[new a.hash.sha256],this.s=[0],this.N=0,this.G={},this.M=0,this.T={},this.X=this.i=this.u=this.fa=0,this.b=[0,0,0,0,0,0,0,0],this.m=[0,0,0,0],this.K=void 0,this.L=t,this.D=!1,this.J={progress:{},seeded:{}},this.A=this.ea=0,this.H=1,this.I=2,this.aa=65536,this.R=[0,48,64,96,128,192,256,384,512,768,1024],this.ba=3e4,this.$=80};a.prng.prototype={randomWords:function(t,e){var r=[],n;n=this.isReady(e);var o;if(n===this.A)throw new a.exception.notReady("generator isn't seeded");if(n&this.I){n=!(n&this.H),o=[];var i=0,s;for(this.X=o[0]=new Date().valueOf()+this.ba,s=0;16>s;s++)o.push(4294967296*Math.random()|0);for(s=0;s<this.h.length&&(o=o.concat(this.h[s].finalize()),i+=this.s[s],this.s[s]=0,n||!(this.N&1<<s));s++);for(this.N>=1<<this.h.length&&(this.h.push(new a.hash.sha256),this.s.push(0)),this.i-=i,i>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<t;n+=4)(n+1)%this.aa===0&&Qt(this),o=lt(this),r.push(o[0],o[1],o[2],o[3]);return Qt(this),r.slice(0,t)},setDefaultParanoia:function(t,e){if(t===0&&e!=="Setting paranoia=0 will ruin your security; use it only for testing")throw new a.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");this.L=t},addEntropy:function(t,e,r){r=r||"user";var n,o,i=new Date().valueOf(),s=this.G[r],c=this.isReady(),u=0;switch(n=this.T[r],n===void 0&&(n=this.T[r]=this.fa++),s===void 0&&(s=this.G[r]=0),this.G[r]=(this.G[r]+1)%this.h.length,typeof t){case"number":e===void 0&&(e=1),this.h[s].update([n,this.M++,1,e,i,1,t|0]);break;case"object":if(r=Object.prototype.toString.call(t),r==="[object Uint32Array]"){for(o=[],r=0;r<t.length;r++)o.push(t[r]);t=o}else for(r!=="[object Array]"&&(u=1),r=0;r<t.length&&!u;r++)typeof t[r]!="number"&&(u=1);if(!u){if(e===void 0)for(r=e=0;r<t.length;r++)for(o=t[r];0<o;)e++,o=o>>>1;this.h[s].update([n,this.M++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,i,t.length]),this.h[s].update(t);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,c===this.A&&(this.isReady()!==this.A&&Kt("seeded",Math.max(this.u,this.i)),Kt("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:De(this,this.la),mouseCollector:De(this,this.na),keyboardCollector:De(this,this.ja),accelerometerCollector:De(this,this.ca),touchCollector:De(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(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,o=this.J[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;r<i.length;r++)n=i[r],delete o[n]},ja:function(){_e(this,1)},na:function(t){var e,r;try{e=t.x||t.clientX||t.offsetX||0,r=t.y||t.clientY||t.offsetY||0}catch{r=e=0}e!=0&&r!=0&&this.addEntropy([e,r],2,"mouse"),_e(this,0)},pa:function(t){t=t.touches[0]||t.changedTouches[0],this.addEntropy([t.pageX||t.clientX,t.pageY||t.clientY],1,"touch"),_e(this,0)},la:function(){_e(this,2)},ca:function(t){if(t=t.accelerationIncludingGravity.x||t.accelerationIncludingGravity.y||t.accelerationIncludingGravity.z,window.orientation){var e=window.orientation;typeof e=="number"&&this.addEntropy(e,1,"accelerometer")}t&&this.addEntropy(t,2,"accelerometer"),_e(this,0)}};function Kt(t,e){var r,n=a.random.J[t],o=[];for(r in n)n.hasOwnProperty(r)&&o.push(n[r]);for(r=0;r<o.length;r++)o[r](e)}function _e(t,e){typeof window<"u"&&window.performance&&typeof window.performance.now=="function"?t.addEntropy(window.performance.now(),e,"loadtime"):t.addEntropy(new Date().valueOf(),e,"loadtime")}function Qt(t){t.b=lt(t).concat(lt(t)),t.K=new a.cipher.aes(t.b)}function lt(t){for(var e=0;4>e&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function De(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(Xe=typeof fe<"u"&&fe.exports){try{Ge=Dr("crypto")}catch{Ge=null}Xe=$e=Ge}if(Xe&&$e.randomBytes)Ce=$e.randomBytes(128),Ce=new Uint32Array(new Uint8Array(Ce).buffer),a.random.addEntropy(Ce,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(t){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}var Ce,$e,Se,Xe,Ge;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,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 t=="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<i.iv.length)throw new a.exception.invalid("json encrypt: invalid parameters");return typeof t=="string"?(s=a.misc.cachedPbkdf2(t,i),t=s.key.slice(0,i.ks/32),i.salt=s.salt):a.ecc&&t instanceof a.ecc.elGamal.publicKey&&(s=t.kem(),i.kemtag=s.tag,t=s.key.slice(0,i.ks/32)),typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof r=="string"&&(i.adata=r=a.codec.utf8String.toBits(r)),s=new a.cipher[i.cipher](t),o.j(n,i),n.key=t,i.ct=i.mode==="ccm"&&a.arrayBuffer&&a.arrayBuffer.ccm&&e instanceof ArrayBuffer?a.arrayBuffer.ccm.encrypt(s,e,i.iv,r,i.ts):a.mode[i.mode].encrypt(s,e,i.iv,r,i.ts),i},encrypt:function(t,e,r,n){var o=a.json,i=o.ha.apply(o,arguments);return o.encode(i)},ga:function(t,e,r,n){r=r||{},n=n||{};var o=a.json;e=o.j(o.j(o.j({},o.defaults),e),r,!0);var i,s;if(i=e.adata,typeof e.salt=="string"&&(e.salt=a.codec.base64.toBits(e.salt)),typeof e.iv=="string"&&(e.iv=a.codec.base64.toBits(e.iv)),!a.mode[e.mode]||!a.cipher[e.cipher]||typeof t=="string"&&100>=e.iter||e.ts!==64&&e.ts!==96&&e.ts!==128||e.ks!==128&&e.ks!==192&&e.ks!==256||!e.iv||2>e.iv.length||4<e.iv.length)throw new a.exception.invalid("json decrypt: invalid parameters");return typeof t=="string"?(s=a.misc.cachedPbkdf2(t,e),t=s.key.slice(0,e.ks/32),e.salt=s.salt):a.ecc&&t instanceof a.ecc.elGamal.secretKey&&(t=t.unkem(a.codec.base64.toBits(e.kemtag)).slice(0,e.ks/32)),typeof i=="string"&&(i=a.codec.utf8String.toBits(i)),s=new a.cipher[e.cipher](t),i=e.mode==="ccm"&&a.arrayBuffer&&a.arrayBuffer.ccm&&e.ct instanceof ArrayBuffer?a.arrayBuffer.ccm.decrypt(s,e.ct,e.iv,e.tag,i,e.ts):a.mode[e.mode].decrypt(s,e.ct,e.iv,i,e.ts),o.j(n,e),n.key=t,r.raw===1?i:a.codec.utf8String.fromBits(i)},decrypt:function(t,e,r,n){var o=a.json;return o.ga(t,o.decode(e),r,n)},encode:function(t){var e,r="{",n="";for(e in t)if(t.hasOwnProperty(e)){if(!e.match(/^[a-z0-9]+$/i))throw new a.exception.invalid("json encode: invalid property name");switch(r+=n+'"'+e+'":',n=",",typeof t[e]){case"number":case"boolean":r+=t[e];break;case"string":r+='"'+escape(t[e])+'"';break;case"object":r+='"'+a.codec.base64.fromBits(t[e],0)+'"';break;default:throw new a.exception.bug("json encode: unsupported type")}}return r+"}"},decode:function(t){if(t=t.replace(/\s/g,""),!t.match(/^\{.*\}$/))throw new a.exception.invalid("json decode: this isn't json!");t=t.replace(/^\{|\}$/g,"").split(/,/);var e={},r,n;for(r=0;r<t.length;r++){if(!(n=t[r].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)))throw new a.exception.invalid("json decode: this isn't json!");n[3]!=null?e[n[2]]=parseInt(n[3],10):n[4]!=null?e[n[2]]=n[2].match(/^(ct|adata|salt|iv)$/)?a.codec.base64.toBits(n[4]):unescape(n[4]):n[5]!=null&&(e[n[2]]=n[5]==="true")}return e},j:function(t,e,r){if(t===void 0&&(t={}),e===void 0)return t;for(var n in e)if(e.hasOwnProperty(n)){if(r&&t[n]!==void 0&&t[n]!==e[n])throw new a.exception.invalid("required parameter overridden");t[n]=e[n]}return t},ra:function(t,e){var r={},n;for(n in t)t.hasOwnProperty(n)&&t[n]!==e[n]&&(r[n]=t[n]);return r},qa:function(t,e){var r={},n;for(n=0;n<e.length;n++)t[e[n]]!==void 0&&(r[e[n]]=t[e[n]]);return r}};a.encrypt=a.json.encrypt;a.decrypt=a.json.decrypt;a.misc.oa={};a.misc.cachedPbkdf2=function(t,e){var r=a.misc.oa,n;return e=e||{},n=e.iter||1e3,r=r[t]=r[t]||{},n=r[n]=r[n]||{firstSalt:e.salt&&e.salt.length?e.salt.slice(0):a.random.randomWords(2,0)},r=e.salt===void 0?n.firstSalt:e.salt,n[r]=n[r]||a.misc.pbkdf2(t,r,e.iter),{key:n[r].slice(0),salt:r.slice(0)}};typeof fe<"u"&&fe.exports&&(fe.exports=a);typeof define=="function"&&define([],function(){return a})});var ur=st((Qo,yt)=>{"use strict";var hn=Object.prototype.hasOwnProperty,k="~";function ke(){}Object.create&&(ke.prototype=Object.create(null),new ke().__proto__||(k=!1));function ln(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function cr(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new ln(r,n||t,o),s=k?k+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function qe(t,e){--t._eventsCount===0?t._events=new ke:delete t._events[e]}function D(){this._events=new ke,this._eventsCount=0}D.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)hn.call(r,n)&&e.push(k?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};D.prototype.listeners=function(e){var r=k?k+e:e,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<i;o++)s[o]=n[o].fn;return s};D.prototype.listenerCount=function(e){var r=k?k+e:e,n=this._events[r];return n?n.fn?1:n.length:0};D.prototype.emit=function(e,r,n,o,i,s){var c=k?k+e:e;if(!this._events[c])return!1;var u=this._events[c],f=arguments.length,h,l;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),f){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,r),!0;case 3:return u.fn.call(u.context,r,n),!0;case 4:return u.fn.call(u.context,r,n,o),!0;case 5:return u.fn.call(u.context,r,n,o,i),!0;case 6:return u.fn.call(u.context,r,n,o,i,s),!0}for(l=1,h=new Array(f-1);l<f;l++)h[l-1]=arguments[l];u.fn.apply(u.context,h)}else{var m=u.length,p;for(l=0;l<m;l++)switch(u[l].once&&this.removeListener(e,u[l].fn,void 0,!0),f){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,r);break;case 3:u[l].fn.call(u[l].context,r,n);break;case 4:u[l].fn.call(u[l].context,r,n,o);break;default:if(!h)for(p=1,h=new Array(f-1);p<f;p++)h[p-1]=arguments[p];u[l].fn.apply(u[l].context,h)}}return!0};D.prototype.on=function(e,r,n){return cr(this,e,r,n,!1)};D.prototype.once=function(e,r,n){return cr(this,e,r,n,!0)};D.prototype.removeListener=function(e,r,n,o){var i=k?k+e:e;if(!this._events[i])return this;if(!r)return qe(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&qe(this,i);else{for(var c=0,u=[],f=s.length;c<f;c++)(s[c].fn!==r||o&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[i]=u.length===1?u[0]:u:qe(this,i)}return this};D.prototype.removeAllListeners=function(e){var r;return e?(r=k?k+e:e,this._events[r]&&qe(this,r)):(this._events=new ke,this._eventsCount=0),this};D.prototype.off=D.prototype.removeListener;D.prototype.addListener=D.prototype.on;D.prefixed=k;D.EventEmitter=D;typeof yt<"u"&&(yt.exports=D)});var Xt=at(Bt());var Mr={withStackTrace:!1},Ft=(t,e,r=Mr)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:o}};function ae(t,e,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(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(t,e||[])).next())})}function jt(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function $(t){return this instanceof $?(this.v=t,this):new $(t)}function Wt(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),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(p){return function(A){return Promise.resolve(A).then(p,l)}}function c(p,A){n[p]&&(o[p]=function(M){return new Promise(function(F,Y){i.push([p,M,F,Y])>1||u(p,M)})},A&&(o[p]=A(o[p])))}function u(p,A){try{f(n[p](A))}catch(M){m(i[0][3],M)}}function f(p){p.value instanceof $?Promise.resolve(p.value.v).then(h,l):m(i[0][2],p)}function h(p){u("next",p)}function l(p){u("throw",p)}function m(p,A){p(A),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Ur(t){var e,r;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=t[o]?function(s){return(r=!r)?{value:$(t[o](s)),done:!1}:i?i(s):s}:i}}function Nr(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof jt=="function"?jt(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(c,u){s=t[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 _=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new N(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new N(o)).catch(o=>new B(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(ae(this,void 0,void 0,function*(){try{return new N(yield e(...n))}catch(o){return new B(r?r(o):o)}}))}static combine(e){return Br(e)}static combineWithAllErrors(e){return jr(e)}map(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?new B(r.error):new N(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);let n=yield e(r.value);return n.isErr()?new B(n.error):new N(r.value)})))}andTee(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);try{yield e(r.value)}catch{}return new N(r.value)})))}mapErr(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isOk()?new N(r.value):new B(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new B(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new N(r.value)})))}match(e,r){return this._promise.then(n=>n.match(e,r))}unwrapOr(e){return this._promise.then(r=>r.unwrapOr(e))}safeUnwrap(){return Wt(this,arguments,function*(){return yield $(yield $(yield*Ur(Nr(yield $(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return Wt(this,arguments,function*(){let r=yield $(this._promise);return r.isErr()&&(yield yield $(S(r.error))),yield $(r.value)})}},X=t=>new _(Promise.resolve(new N(t))),S=t=>new _(Promise.resolve(new B(t))),En=_.fromPromise,An=_.fromSafePromise,xn=_.fromThrowable,zt=t=>{let e=re([]);for(let r of t)if(r.isErr()){e=V(r.error);break}else e.map(n=>n.push(r.value));return e},Br=t=>_.fromSafePromise(Promise.all(t)).andThen(zt),Jt=t=>{let e=re([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=V([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},jr=t=>_.fromSafePromise(Promise.all(t)).andThen(Jt),ft;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return re(c)}catch(c){return V(i?i(c):c)}}}t.fromThrowable=e;function r(o){return zt(o)}t.combine=r;function n(o){return Jt(o)}t.combineWithAllErrors=n})(ft||(ft={}));var re=t=>new N(t);function V(t){return new B(t)}var N=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return re(e(this.value))}mapErr(e){return re(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(r=>this.value)}andTee(e){try{e(this.value)}catch{}return re(this.value)}orElse(e){return re(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return _.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Ft("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},B=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return V(this.error)}mapErr(e){return V(e(this.error))}andThrough(e){return V(this.error)}andTee(e){return V(this.error)}andThen(e){return V(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return S(this.error)}asyncAndThrough(e){return S(this.error)}asyncMap(e){return S(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield V(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ft("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},On=ft.fromThrowable;var ee=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});U(this,"context");this.name=this.constructor.name,this.context=i}};var ne=t=>{if(t instanceof Error)return t;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(t)}catch{}return new Error(e)};var Wr=()=>typeof Deno<"u";var ce=t=>Wr()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var v=new Xt.default,L,Ht=!1;self.onmessage=t=>{Jr(t),Ht||(Ht=!0,v.once("OPERATION_FAILED",()=>{L&&L.terminate()}))};var K=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),Gt=(t,e)=>{K(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},Jr=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)L.postMessage(t.data);else{switch(r){case 2:L=new Worker(ce("cancel"),{type:"module"}),L.postMessage(t.data);break;case 3:L=new Worker(ce("download"),{type:"module"}),L.postMessage(t.data);break;case 4:L=new Worker(ce("infos"),{type:"module"}),L.postMessage(t.data);break;case 7:L=L||new Worker(ce("remove"),{type:"module"}),L.postMessage(t.data);break;case 9:L=L||new Worker(ce("upload"),{type:"module"}),L.postMessage(t.data);break;default:console.error("Action not found")}L.onmessage=n=>{e&&e(n),self.postMessage(n.data)},L.onerror=n=>{console.error(`Error: ${n.message}`)}}},qt=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var G=class extends ee{};var Le=class extends G{constructor(){super(...arguments);U(this,"message","An error occured while trying to connect to WebSocket")}};var ue=class{constructor(e,r){if(!e||e.length!=64)throw Error("Charset must contain 64 characters");this._charset=e,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(e){let r=e.byteLength;if(!r)return"";let n=new Uint8Array(e),o="";for(let i=0;i<r;i+=3)o+=this._charset[n[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(e){if(e=(e||"").replace(/[\s]/g,""),!e)return new ArrayBuffer(0);if(!this._valid.test(e))throw Error("Invalid base64 input sequence");let r=Math.floor(e.length*.75);e[e.length-2]=="="?r-=2:e[e.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u<e.length*.75;)o=this._charset.indexOf(e.charAt(f++)),i=this._charset.indexOf(e.charAt(f++)),s=this._charset.indexOf(e.charAt(f++)),c=this._charset.indexOf(e.charAt(f++)),n[u++]=o<<2|i>>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Hr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function be(t){return Hr.Decode(t)}var $r=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ht(t){return $r.Decode(t)}var tr=at(Zt());var Q=class extends ee{};var he=class extends Q{constructor(){super(...arguments);U(this,"message","Unable to decrypt the provided data")}};var rr=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return X(be(tr.default.decrypt(t,r)))}catch(r){return S(new he(void 0,{cause:ne(r)}))}};var nr=(t,e)=>Vr(t).andThen(r=>_.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,be(e.data)),n=>new he(void 0,{cause:ne(n)})));var Vr=t=>_.fromPromise(crypto.subtle.importKey("raw",ht(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new Q("Unable to import cryptography key",{cause:ne(e)}));var or=(t,e)=>e.algo===void 0||e.algo===0?rr(t,e):nr(t,e);var I={},ir=5,Zr=t=>(v.emit("UPLOAD_CANCELLED",t.success),X(void 0)),en=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(un(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),or(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(K(e,{chunksReady:e.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}),v.emit("DOWNLOAD_STARTED")):K(e,{chunksReady:e.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?on(e).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),X(void 0))):X(void 0)})}else{let s=new G("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),S(s)}}else{let i=new G(o.msg);return v.emit("OPERATION_FAILED",i),S(i)}}else{let o=new G("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",o),S(o)}},tn=(t,e)=>{if(t.success)return t.j===0&&(K(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),v.emit("UPLOAD_STARTED")),K(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),v.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(K(e,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),X(void 0);{let r=new G(t.msg);return v.emit("OPERATION_FAILED",r),S(r)}},rn=(t,e)=>{let r=cn(t.data),n;if(r)if(!r.action&&r.msg){let o=new G(r.msg);return v.emit("OPERATION_FAILED",o),S(o)}else"delay"in r?n=tn(r,e):n=Zr(r);else n=en(t.data,e);return n},nn=t=>I!==void 0&&I[t]!==void 0&&I[t].readyState===WebSocket.CONNECTING,dt=t=>I!==void 0&&I[t]!==void 0&&I[t].readyState===WebSocket.OPEN;var pt=(t,e)=>{let r;return t.password?r={part:e,file_pwd:t.password}:r={part:e},mt(ar(t),t,JSON.stringify(r))},on=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},mt(ar(t),t,JSON.stringify(e))};var mt=(t,e,r)=>dt(t)?(I[t].onmessage=n=>rn(n,e),I[t].send(r),X(void 0)):sr(t).andThen(()=>mt(t,e,r)),sr=(t,e=0)=>(!dt(t)&&!nn(t)&&(I[t]=new WebSocket(t),v.once("SOCKET_OPERATION_TERMINATED",()=>{I[t].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),I[t].onopen=()=>{v.emit("SOCKET_OPENED")},I[t].onclose=()=>{},I[t].onerror=()=>++e<=ir?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${ir}`),sr(t,e)):(v.emit("SOCKET_ONERROR"),S(new Le(`Unable to connect to WebSocket ${t}.`)))),sn(t).andThen(()=>X(t)).orElse(r=>S(r))),sn=t=>_.fromPromise(new Promise((e,r)=>{dt(t)?e(void 0):(v.once("SOCKET_OPENED",()=>{e(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new Le)}))}),e=>ne(e));var an=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,new URL(r.origin+r.pathname)},ar=t=>an(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString();var cn=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},un=t=>typeof t=="object"&&t!==null&&!("msg"in t);var vt=at(ur(),1);var Pe=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},wt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},fr=t=>globalThis.DOMException===void 0?new wt(t):new DOMException(t),hr=t=>{let e=t.reason===void 0?fr("This operation was aborted."):t.reason;return e instanceof Error?e:fr(e)};function gt(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((f,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:m}=e;m.aborted&&h(hr(m));let p=()=>{h(hr(m))};m.addEventListener("abort",p,{once:!0}),t.finally(()=>{m.removeEventListener("abort",p)})}if(r===Number.POSITIVE_INFINITY){t.then(f,h);return}let l=new Pe;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){h(m)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?f():o instanceof Error?h(o):(l.message=o!=null?o:`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await t)}catch(m){h(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Et(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var q,Re=class{constructor(){x(this,q,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&d(this,q)[this.size-1].priority>=r.priority){d(this,q).push(n);return}let o=Et(d(this,q),n,(i,s)=>s.priority-i.priority);d(this,q).splice(o,0,n)}dequeue(){let e=d(this,q).shift();return e==null?void 0:e.run}filter(e){return d(this,q).filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return d(this,q).length}};q=new WeakMap;var le,de,te,Ie,pe,Me,j,me,P,Ue,W,ye,Z,Ne,y,lr,dr,pr,mr,yr,Ye,At,xt,Ve,vr,Ke,Te=class extends vt.default{constructor(r){var n,o,i,s;super();x(this,y);x(this,le);x(this,de);x(this,te,0);x(this,Ie);x(this,pe);x(this,Me,0);x(this,j);x(this,me);x(this,P);x(this,Ue);x(this,W,0);x(this,ye);x(this,Z);x(this,Ne);U(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Re,...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})`);g(this,le,r.carryoverConcurrencyCount),g(this,de,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),g(this,Ie,r.intervalCap),g(this,pe,r.interval),g(this,P,new r.queueClass),g(this,Ue,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,g(this,Ne,r.throwOnTimeout===!0),g(this,Z,r.autoStart===!1)}get concurrency(){return d(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})`);g(this,ye,r),O(this,y,Ve).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:d(this,Ne),...n},new Promise((o,i)=>{d(this,P).enqueue(async()=>{var s;ze(this,W)._++,ze(this,te)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=gt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,O(this,y,vr).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof Pe&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{O(this,y,pr).call(this)}},n),this.emit("add"),O(this,y,Ye).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return d(this,Z)?(g(this,Z,!1),O(this,y,Ve).call(this),this):this}pause(){g(this,Z,!0)}clear(){g(this,P,new(d(this,Ue)))}async onEmpty(){d(this,P).size!==0&&await O(this,y,Ke).call(this,"empty")}async onSizeLessThan(r){d(this,P).size<r||await O(this,y,Ke).call(this,"next",()=>d(this,P).size<r)}async onIdle(){d(this,W)===0&&d(this,P).size===0||await O(this,y,Ke).call(this,"idle")}get size(){return d(this,P).size}sizeBy(r){return d(this,P).filter(r).length}get pending(){return d(this,W)}get isPaused(){return d(this,Z)}};le=new WeakMap,de=new WeakMap,te=new WeakMap,Ie=new WeakMap,pe=new WeakMap,Me=new WeakMap,j=new WeakMap,me=new WeakMap,P=new WeakMap,Ue=new WeakMap,W=new WeakMap,ye=new WeakMap,Z=new WeakMap,Ne=new WeakMap,y=new WeakSet,lr=function(){return d(this,de)||d(this,te)<d(this,Ie)},dr=function(){return d(this,W)<d(this,ye)},pr=function(){ze(this,W)._--,O(this,y,Ye).call(this),this.emit("next")},mr=function(){O(this,y,xt).call(this),O(this,y,At).call(this),g(this,me,void 0)},yr=function(){let r=Date.now();if(d(this,j)===void 0){let n=d(this,Me)-r;if(n<0)g(this,te,d(this,le)?d(this,W):0);else return d(this,me)===void 0&&g(this,me,setTimeout(()=>{O(this,y,mr).call(this)},n)),!0}return!1},Ye=function(){if(d(this,P).size===0)return d(this,j)&&clearInterval(d(this,j)),g(this,j,void 0),this.emit("empty"),d(this,W)===0&&this.emit("idle"),!1;if(!d(this,Z)){let r=!d(this,y,yr);if(d(this,y,lr)&&d(this,y,dr)){let n=d(this,P).dequeue();return n?(this.emit("active"),n(),r&&O(this,y,At).call(this),!0):!1}}return!1},At=function(){d(this,de)||d(this,j)!==void 0||(g(this,j,setInterval(()=>{O(this,y,xt).call(this)},d(this,pe))),g(this,Me,Date.now()+d(this,pe)))},xt=function(){d(this,te)===0&&d(this,W)===0&&d(this,j)&&(clearInterval(d(this,j)),g(this,j,void 0)),g(this,te,d(this,le)?d(this,W):0),O(this,y,Ve).call(this)},Ve=function(){for(;O(this,y,Ye).call(this););},vr=async function(r){return new Promise((n,o)=>{r.addEventListener("abort",()=>{o(r.reason)},{once:!0})})},Ke=async function(r,n){return new Promise(o=>{let i=()=>{n&&!n()||(this.off(r,i),o())};this.on(r,i)})};var dn=[],Ot=navigator.hardwareConcurrency||4,Qe=new Te({concurrency:Ot,autoStart:!1}),Ze=0,wr=!1,et=!1;self.onmessage=t=>{wr||(qt(),wr=!0);let e=t.data;switch(e.action){case 5:et=!0,self.postMessage({event:"JOB_PAUSED"});break;case 8:et=!1,self.postMessage({event:"JOB_RESUMED"});break;default:v.once("DOWNLOAD_COMPLETE",()=>{self.postMessage({event:"DOWNLOAD_COMPLETE"})}),v.on("FILE_UPDATED",K),v.on("CHUNK_DOWNLOADED",(r,n)=>{self.postMessage({event:"CHUNK_DOWNLOADED",chunk:{buffer:r,index:n}})}),pn(e).mapErr(r=>{Gt(e.args.lufiFile,r)})}};var pn=t=>{let{lufiFile:e}=t.args;return v.on("CHUNK_DOWNLOADED",(r,n)=>{dn[n]=r,Ze--,!et&&Ze<Ot&&Qe.start()}),v.on("DOWNLOAD_STARTED",async()=>{for(let r=1;r<e.totalChunks;r++)await Qe.add(async()=>{await pt(e,r),Ze++,(et||Ze===Ot)&&Qe.pause()});Qe.start()}),pt(e,0)};export{Ot as QUEUE_CONCURRENCY_LIMIT,Ze as itemsInQueue,Qe as queue};