2 lines
54 KiB
JavaScript
2 lines
54 KiB
JavaScript
var Ht=Object.create;var Te=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Vt=Object.getPrototypeOf,Yt=Object.prototype.hasOwnProperty;var et=t=>{throw TypeError(t)};var Kt=(t,e,r)=>e in t?Te(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Qt=(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 Me=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Zt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Gt(e))!Yt.call(t,o)&&o!==r&&Te(t,o,{get:()=>e[o],enumerable:!(n=Xt(e,o))||n.enumerable});return t};var Ne=(t,e,r)=>(r=t!=null?Ht(Vt(t)):{},Zt(e||!t||!t.__esModule?Te(r,"default",{value:t,enumerable:!0}):r,t));var T=(t,e,r)=>Kt(t,typeof e!="symbol"?e+"":e,r),Ue=(t,e,r)=>e.has(t)||et("Cannot "+r);var d=(t,e,r)=>(Ue(t,e,"read from private field"),r?r.call(t):e.get(t)),A=(t,e,r)=>e.has(t)?et("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),E=(t,e,r,n)=>(Ue(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),x=(t,e,r)=>(Ue(t,e,"access private method"),r);var Ae=(t,e,r,n)=>({set _(o){E(t,e,o,r)},get _(){return d(t,e,n)}});var ht=Me((jr,Be)=>{"use strict";var Y=typeof Reflect=="object"?Reflect:null,tt=Y&&typeof Y.apply=="function"?Y.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},xe;Y&&typeof Y.ownKeys=="function"?xe=Y.ownKeys:Object.getOwnPropertySymbols?xe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:xe=function(e){return Object.getOwnPropertyNames(e)};function er(t){console&&console.warn&&console.warn(t)}var nt=Number.isNaN||function(e){return e!==e};function w(){w.init.call(this)}Be.exports=w;Be.exports.once=or;w.EventEmitter=w;w.prototype._events=void 0;w.prototype._eventsCount=0;w.prototype._maxListeners=void 0;var rt=10;function Le(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 rt},set:function(t){if(typeof t!="number"||t<0||nt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");rt=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||nt(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 ot(t){return t._maxListeners===void 0?w.defaultMaxListeners:t._maxListeners}w.prototype.getMaxListeners=function(){return ot(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")tt(u,this,r);else for(var f=u.length,l=ut(u,f),n=0;n<f;++n)tt(l[n],this,r);return!0};function it(t,e,r,n){var o,i,s;if(Le(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=ot(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,er(c)}return t}w.prototype.addListener=function(e,r){return it(this,e,r,!1)};w.prototype.on=w.prototype.addListener;w.prototype.prependListener=function(e,r){return it(this,e,r,!0)};function tr(){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 st(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=tr.bind(n);return o.listener=r,n.wrapFn=o,o}w.prototype.once=function(e,r){return Le(r),this.on(e,st(this,e,r)),this};w.prototype.prependOnceListener=function(e,r){return Le(r),this.prependListener(e,st(this,e,r)),this};w.prototype.removeListener=function(e,r){var n,o,i,s,c;if(Le(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():rr(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 at(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?nr(o):ut(o,o.length)}w.prototype.listeners=function(e){return at(this,e,!0)};w.prototype.rawListeners=function(e){return at(this,e,!1)};w.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):ct.call(t,e)};w.prototype.listenerCount=ct;function ct(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?xe(this._events):[]};function ut(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function rr(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function nr(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function or(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))}ft(t,e,i,{once:!0}),e!=="error"&&ir(t,o,{once:!0})})}function ir(t,e,r){typeof t.on=="function"&&ft(t,"error",e,r)}function ft(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 _t=Me((Sn,ee)=>{"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.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[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 Lt(this,t,0)},decrypt:function(t){return Lt(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,l,h,p;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=c[o=c[f=c[i]]],p=16843009*l^65537*o^257*f^16843008*i,l=257*c[h]^16843008*h,o=0;4>o;o++)t[o][i]=l=l<<24^l>>>8,e[o][h]=p=p<<24^p>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function Lt(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,l=n.length/4-2,h,p=4,m=[0,0,0,0];c=t.s[r],t=c[0];var g=c[1],j=c[2],G=c[3],V=c[4];for(h=0;h<l;h++)c=t[o>>>24]^g[i>>16&255]^j[s>>8&255]^G[e&255]^n[p],u=t[i>>>24]^g[s>>16&255]^j[e>>8&255]^G[o&255]^n[p+1],f=t[s>>>24]^g[e>>16&255]^j[o>>8&255]^G[i&255]^n[p+2],e=t[e>>>24]^g[o>>16&255]^j[i>>8&255]^G[s&255]^n[p+3],p+=4,o=c,i=u,s=f;for(h=0;4>h;h++)m[r?3&-h:h]=V[o>>>24]<<24^V[i>>16&255]<<16^V[s>>8&255]<<8^V[e&255]^n[p++],c=o,o=i,i=s,s=e,e=c;return m}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.$(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.$(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},$: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},i: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.base32={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",X:"0123456789ABCDEFGHIJKLMNOPQRSTUV",BITS:32,BASE:5,REMAINING:27,fromBits:function(t,e,r){var n=a.codec.base32.BASE,o=a.codec.base32.REMAINING,i="",s=0,c=a.codec.base32.B,u=0,f=a.bitArray.bitLength(t);for(r&&(c=a.codec.base32.X),r=0;i.length*n<f;)i+=c.charAt((u^t[r]>>>s)>>>o),s<n?(u=t[r]<<n-s,s+=o,r++):(u<<=n,s-=n);for(;i.length&7&&!e;)i+="=";return i},toBits:function(t,e){t=t.replace(/\s|=/g,"").toUpperCase();var r=a.codec.base32.BITS,n=a.codec.base32.BASE,o=a.codec.base32.REMAINING,i=[],s,c=0,u=a.codec.base32.B,f=0,l,h="base32";for(e&&(u=a.codec.base32.X,h="base32hex"),s=0;s<t.length;s++){if(l=u.indexOf(t.charAt(s)),0>l){if(!e)try{return a.codec.base32hex.toBits(t)}catch{}throw new a.exception.invalid("this isn't "+h+"!")}c>o?(c-=o,i.push(f^l>>>c),f=l<<r-c):(c+=n,f^=l<<r-c)}return c&56&&i.push(a.bitArray.partial(c&56,f,1)),i}};a.codec.base32hex={fromBits:function(t,e){return a.codec.base32.fromBits(t,e,1)},toBits:function(t){return a.codec.base32.toBits(t,1)}};a.codec.base64={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(t,e,r){var n="",o=0,i=a.codec.base64.B,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.B,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.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):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.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.A=a.bitArray.concat(this.A,t);if(e=this.l,t=this.l=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)Fe(this,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)Fe(this,r.splice(0,16));return this},finalize:function(){var t,r=this.A,e=this.F,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.l/4294967296)),r.push(this.l|0);r.length;)Fe(this,r.splice(0,16));return this.reset(),e},Y:[],b:[],O: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.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function Fe(t,e){var r,n,o,i=t.F,s=t.b,c=i[0],u=i[1],f=i[2],l=i[3],h=i[4],p=i[5],m=i[6],g=i[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],o=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+e[r&15]+e[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(p^m))+s[r],g=m,m=p,p=h,h=l+n|0,l=f,f=u,u=c,c=n+(u&f^l&(u^f))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10)|0;i[0]=i[0]+c|0,i[1]=i[1]+u|0,i[2]=i[2]+f|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+p|0,i[6]=i[6]+m|0,i[7]=i[7]+g|0}a.mode.ccm={name:"ccm",G:[],listenProgress:function(t){a.mode.ccm.G.push(t)},unListenProgress:function(t){t=a.mode.ccm.G.indexOf(t),-1<t&&a.mode.ccm.G.splice(t,1)},fa:function(t){var e=a.mode.ccm.G.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.V(t,e,r,n,o,i),s=a.mode.ccm.C(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.C(t,c,r,u,o,e),t=a.mode.ccm.V(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},na:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.i;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},V:function(t,e,r,n,o,i){var s=a.bitArray,c=s.i;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.na(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)},C:function(t,e,r,n,o,i){var s,c=a.bitArray;s=c.i;var u=e.length,f=c.bitLength(e),l=u/50,h=l;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>l&&(a.mode.ccm.fa(s/u),l+=h),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.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");var s,c=a.mode.ocb2.S,u=a.bitArray,f=u.i,l=[0,0,0,0];r=c(t.encrypt(r));var h,p=[];for(n=n||[],o=o||64,s=0;s+4<e.length;s+=4)h=e.slice(s,s+4),l=f(l,h),p=p.concat(f(r,t.encrypt(f(r,h)))),r=c(r);return h=e.slice(s),e=u.bitLength(h),s=t.encrypt(f(r,[0,0,0,e])),h=u.clamp(f(h.concat([0,0,0]),s),e),l=f(l,f(h.concat([0,0,0]),s)),l=t.encrypt(f(l,f(r,c(r)))),n.length&&(l=f(l,i?n:a.mode.ocb2.pmac(t,n))),p.concat(u.concat(h,u.clamp(l,o)))},decrypt:function(t,e,r,n,o,i){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");o=o||64;var s=a.mode.ocb2.S,c=a.bitArray,u=c.i,f=[0,0,0,0],l=s(t.encrypt(r)),h,p,m=a.bitArray.bitLength(e)-o,g=[];for(n=n||[],r=0;r+4<m/32;r+=4)h=u(l,t.decrypt(u(l,e.slice(r,r+4)))),f=u(f,h),g=g.concat(h),l=s(l);if(p=m-32*r,h=t.encrypt(u(l,[0,0,0,p])),h=u(h,c.clamp(e.slice(r),p).concat([0,0,0])),f=u(f,h),f=t.encrypt(u(f,u(l,s(l)))),n.length&&(f=u(f,i?n:a.mode.ocb2.pmac(t,n))),!c.equal(c.clamp(f,o),c.bitSlice(e,m)))throw new a.exception.corrupt("ocb: tag doesn't match");return g.concat(c.clamp(h,p))},pmac:function(t,e){var r,n=a.mode.ocb2.S,o=a.bitArray,i=o.i,s=[0,0,0,0],c=t.encrypt([0,0,0,0]),c=i(c,n(n(c)));for(r=0;r+4<e.length;r+=4)c=n(c),s=i(s,t.encrypt(i(c,e.slice(r,r+4))));return r=e.slice(r),128>o.bitLength(r)&&(c=i(c,n(c)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(c,n(c))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};a.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=a.bitArray,n=n||[],t=a.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=a.bitArray,c=s.bitLength(i);if(o=o||128,n=n||[],o<=c?(e=s.bitSlice(i,c-o),i=s.bitSlice(i,0,c-o)):(e=i,i=[]),t=a.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new a.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,c=a.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=c(o,i)),s=(i[3]&1)!==0,n=3;0<n;n--)i[n]=i[n]>>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(t,e,r){var n,o=r.length;for(e=e.slice(0),n=0;n<o;n+=4)e[0]^=4294967295&r[n],e[1]^=4294967295&r[n+1],e[2]^=4294967295&r[n+2],e[3]^=4294967295&r[n+3],e=a.mode.gcm.ka(e,t);return e},C:function(t,e,r,n,o,i){var s,c,u,f,l,h,p,m,g=a.bitArray;for(h=r.length,p=g.bitLength(r),m=g.bitLength(n),c=g.bitLength(o),s=e.encrypt([0,0,0,0]),c===96?(o=o.slice(0),o=g.concat(o,[1])):(o=a.mode.gcm.j(s,[0,0,0,0],o),o=a.mode.gcm.j(s,o,[0,0,Math.floor(c/4294967296),c&4294967295])),c=a.mode.gcm.j(s,[0,0,0,0],n),l=o.slice(0),n=c.slice(0),t||(n=a.mode.gcm.j(s,c,r)),f=0;f<h;f+=4)l[3]++,u=e.encrypt(l),r[f]^=u[0],r[f+1]^=u[1],r[f+2]^=u[2],r[f+3]^=u[3];return r=g.clamp(r,p),t&&(n=a.mode.gcm.j(s,c,r)),t=[Math.floor(m/4294967296),m&4294967295,Math.floor(p/4294967296),p&4294967295],n=a.mode.gcm.j(s,n,t),u=e.encrypt(o),n[0]^=u[0],n[1]^=u[1],n[2]^=u[2],n[3]^=u[3],{tag:g.bitSlice(n,0,i),data:r}}};a.misc.hmac=function(t,e){this.W=e=e||a.hash.sha256;var r=[[],[]],n,o=e.prototype.blockSize/32;for(this.w=[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.w[0].update(r[0]),this.w[1].update(r[1]),this.R=new e(this.w[0])};a.misc.hmac.prototype.encrypt=a.misc.hmac.prototype.mac=function(t){if(this.aa)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.R=new this.W(this.w[0]),this.aa=!1};a.misc.hmac.prototype.update=function(t){this.aa=!0,this.R.update(t)};a.misc.hmac.prototype.digest=function(){var t=this.R.finalize(),t=new this.W(this.w[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=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=t.encrypt(l.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=l.clamp(f,n)),f};a.prng=function(t){this.c=[new a.hash.sha256],this.m=[0],this.P=0,this.H={},this.N=0,this.U={},this.Z=this.f=this.o=this.ha=0,this.b=[0,0,0,0,0,0,0,0],this.h=[0,0,0,0],this.L=void 0,this.M=t,this.D=!1,this.K={progress:{},seeded:{}},this.u=this.ga=0,this.I=1,this.J=2,this.ca=65536,this.T=[0,48,64,96,128,192,256,384,512,768,1024],this.da=3e4,this.ba=80};a.prng.prototype={randomWords:function(t,e){var r=[],n;n=this.isReady(e);var o;if(n===this.u)throw new a.exception.notReady("generator isn't seeded");if(n&this.J){n=!(n&this.I),o=[];var i=0,s;for(this.Z=o[0]=new Date().valueOf()+this.da,s=0;16>s;s++)o.push(4294967296*Math.random()|0);for(s=0;s<this.c.length&&(o=o.concat(this.c[s].finalize()),i+=this.m[s],this.m[s]=0,n||!(this.P&1<<s));s++);for(this.P>=1<<this.c.length&&(this.c.push(new a.hash.sha256),this.m.push(0)),this.f-=i,i>this.o&&(this.o=i),this.P++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.L=new a.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n<t;n+=4)(n+1)%this.ca===0&&bt(this),o=Je(this),r.push(o[0],o[1],o[2],o[3]);return bt(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.M=t},addEntropy:function(t,e,r){r=r||"user";var n,o,i=new Date().valueOf(),s=this.H[r],c=this.isReady(),u=0;switch(n=this.U[r],n===void 0&&(n=this.U[r]=this.ha++),s===void 0&&(s=this.H[r]=0),this.H[r]=(this.H[r]+1)%this.c.length,typeof t){case"number":e===void 0&&(e=1),this.c[s].update([n,this.N++,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.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[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.m[s]+=e,this.f+=e,c===this.u&&(this.isReady()!==this.u&&Ot("seeded",Math.max(this.o,this.f)),Ot("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:fe(this,this.ma),mouseCollector:fe(this,this.oa),keyboardCollector:fe(this,this.la),accelerometerCollector:fe(this,this.ea),touchCollector:fe(this,this.qa)},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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[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]},la:function(){ue(this,1)},oa: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"),ue(this,0)},qa:function(t){t=t.touches[0]||t.changedTouches[0],this.addEntropy([t.pageX||t.clientX,t.pageY||t.clientY],1,"touch"),ue(this,0)},ma:function(){ue(this,2)},ea: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"),ue(this,0)}};function Ot(t,e){var r,n=a.random.K[t],o=[];for(r in n)n.hasOwnProperty(r)&&o.push(n[r]);for(r=0;r<o.length;r++)o[r](e)}function ue(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 bt(t){t.b=Je(t).concat(Je(t)),t.L=new a.cipher.aes(t.b)}function Je(t){for(var e=0;4>e&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function fe(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(be=typeof ee<"u"&&ee.exports){try{_e=Qt("crypto")}catch{_e=null}be=Oe=_e}if(be&&Oe.randomBytes)he=Oe.randomBytes(128),he=new Uint32Array(new Uint8Array(he).buffer),a.random.addEntropy(he,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(le=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(le);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(le);else break e;a.random.addEntropy(le,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 he,Oe,le,be,_e;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=a.json,i=o.g({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.g(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.g(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.ja.apply(o,arguments);return o.encode(i)},ia:function(t,e,r,n){r=r||{},n=n||{};var o=a.json;e=o.g(o.g(o.g({},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.g(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.ia(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},g: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},sa:function(t,e){var r={},n;for(n in t)t.hasOwnProperty(n)&&t[n]!==e[n]&&(r[n]=t[n]);return r},ra: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.pa={};a.misc.cachedPbkdf2=function(t,e){var r=a.misc.pa,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 ee<"u"&&ee.exports&&(ee.exports=a);typeof define=="function"&&define([],function(){return a})});var Nt=Me((po,He)=>{"use strict";var Rr=Object.prototype.hasOwnProperty,D="~";function de(){}Object.create&&(de.prototype=Object.create(null),new de().__proto__||(D=!1));function Tr(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Mt(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Tr(r,n||t,o),s=D?D+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 De(t,e){--t._eventsCount===0?t._events=new de:delete t._events[e]}function _(){this._events=new de,this._eventsCount=0}_.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Rr.call(r,n)&&e.push(D?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};_.prototype.listeners=function(e){var r=D?D+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};_.prototype.listenerCount=function(e){var r=D?D+e:e,n=this._events[r];return n?n.fn?1:n.length:0};_.prototype.emit=function(e,r,n,o,i,s){var c=D?D+e:e;if(!this._events[c])return!1;var u=this._events[c],f=arguments.length,l,h;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(h=1,l=new Array(f-1);h<f;h++)l[h-1]=arguments[h];u.fn.apply(u.context,l)}else{var p=u.length,m;for(h=0;h<p;h++)switch(u[h].once&&this.removeListener(e,u[h].fn,void 0,!0),f){case 1:u[h].fn.call(u[h].context);break;case 2:u[h].fn.call(u[h].context,r);break;case 3:u[h].fn.call(u[h].context,r,n);break;case 4:u[h].fn.call(u[h].context,r,n,o);break;default:if(!l)for(m=1,l=new Array(f-1);m<f;m++)l[m-1]=arguments[m];u[h].fn.apply(u[h].context,l)}}return!0};_.prototype.on=function(e,r,n){return Mt(this,e,r,n,!1)};_.prototype.once=function(e,r,n){return Mt(this,e,r,n,!0)};_.prototype.removeListener=function(e,r,n,o){var i=D?D+e:e;if(!this._events[i])return this;if(!r)return De(this,i),this;var s=this._events[i];if(s.fn)s.fn===r&&(!o||s.once)&&(!n||s.context===n)&&De(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:De(this,i)}return this};_.prototype.removeAllListeners=function(e){var r;return e?(r=D?D+e:e,this._events[r]&&De(this,r)):(this._events=new de,this._eventsCount=0),this};_.prototype.off=_.prototype.removeListener;_.prototype.addListener=_.prototype.on;_.prefixed=D;_.EventEmitter=_;typeof He<"u"&&(He.exports=_)});var wt=Ne(ht());var sr={withStackTrace:!1},pt=(t,e,r=sr)=>{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 K(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(l){try{f(n.next(l))}catch(h){s(h)}}function u(l){try{f(n.throw(l))}catch(h){s(h)}}function f(l){l.done?i(l.value):o(l.value).then(c,u)}f((n=n.apply(t,e||[])).next())})}function lt(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 M(t){return this instanceof M?(this.v=t,this):new M(t)}function dt(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(m){return function(g){return Promise.resolve(g).then(m,h)}}function c(m,g){n[m]&&(o[m]=function(j){return new Promise(function(G,V){i.push([m,j,G,V])>1||u(m,j)})},g&&(o[m]=g(o[m])))}function u(m,g){try{f(n[m](g))}catch(j){p(i[0][3],j)}}function f(m){m.value instanceof M?Promise.resolve(m.value.v).then(l,h):p(i[0][2],m)}function l(m){u("next",m)}function h(m){u("throw",m)}function p(m,g){m(g),i.shift(),i.length&&u(i[0][0],i[0][1])}}function ar(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:M(t[o](s)),done:!1}:i?i(s):s}:i}}function cr(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 lt=="function"?lt(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 b=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new k(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new k(o)).catch(o=>new P(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(K(this,void 0,void 0,function*(){try{return new k(yield e(...n))}catch(o){return new P(r?r(o):o)}}))}static combine(e){return ur(e)}static combineWithAllErrors(e){return fr(e)}map(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){return r.isErr()?new P(r.error):new k(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){if(r.isErr())return new P(r.error);let n=yield e(r.value);return n.isErr()?new P(n.error):new k(r.value)})))}andTee(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){if(r.isErr())return new P(r.error);try{yield e(r.value)}catch{}return new k(r.value)})))}mapErr(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){return r.isOk()?new k(r.value):new P(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new P(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new k(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 dt(this,arguments,function*(){return yield M(yield M(yield*ar(cr(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return dt(this,arguments,function*(){let r=yield M(this._promise);return r.isErr()&&(yield yield M(O(r.error))),yield M(r.value)})}},N=t=>new b(Promise.resolve(new k(t))),O=t=>new b(Promise.resolve(new P(t))),Jr=b.fromPromise,zr=b.fromSafePromise,qr=b.fromThrowable,mt=t=>{let e=H([]);for(let r of t)if(r.isErr()){e=W(r.error);break}else e.map(n=>n.push(r.value));return e},ur=t=>b.fromSafePromise(Promise.all(t)).andThen(mt),yt=t=>{let e=H([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=W([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},fr=t=>b.fromSafePromise(Promise.all(t)).andThen(yt),je;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return H(c)}catch(c){return W(i?i(c):c)}}}t.fromThrowable=e;function r(o){return mt(o)}t.combine=r;function n(o){return yt(o)}t.combineWithAllErrors=n})(je||(je={}));var H=t=>new k(t);function W(t){return new P(t)}var k=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return H(e(this.value))}mapErr(e){return H(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 H(this.value)}orElse(e){return H(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return b.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 pt("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},P=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return W(this.error)}mapErr(e){return W(e(this.error))}andThrough(e){return W(this.error)}andTee(e){return W(this.error)}andThen(e){return W(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return O(this.error)}asyncAndThrough(e){return O(this.error)}asyncMap(e){return O(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield W(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw pt("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},$r=je.fromThrowable;var z=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});T(this,"context");this.name=this.constructor.name,this.context=i}};var X=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 hr=()=>typeof Deno<"u";var Q=t=>hr()?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 wt.default,L,vt=!1;self.onmessage=t=>{pr(t),vt||(vt=!0,v.once("OPERATION_FAILED",()=>{L&&L.terminate()}))};var F=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),Et=(t,e)=>{F(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},pr=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)L.postMessage(t.data);else{switch(r){case 2:L=new Worker(Q("cancel"),{type:"module"}),L.postMessage(t.data);break;case 3:L=new Worker(Q("download"),{type:"module"}),L.postMessage(t.data);break;case 4:L=new Worker(Q("infos"),{type:"module"}),L.postMessage(t.data);break;case 7:L=L||new Worker(Q("remove"),{type:"module"}),L.postMessage(t.data);break;case 9:L=L||new Worker(Q("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}`)}}},At=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var U=class extends z{};var ae=class extends U{constructor(){super(...arguments);T(this,"message","An error occured while trying to connect to WebSocket")}};var Z=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 mr=new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ce(t){return mr.Decode(t)}var yr=new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function We(t){return yr.Decode(t)}var St=Ne(_t());var q=class extends z{};var te=class extends q{constructor(){super(...arguments);T(this,"message","Unable to decrypt the provided data")}};var Ct=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return N(ce(St.default.decrypt(t,r)))}catch(r){return O(new te(void 0,{cause:X(r)}))}};var kt=(t,e)=>wr(t).andThen(r=>b.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,ce(e.data)),n=>new te(void 0,{cause:X(n)})));var wr=t=>b.fromPromise(crypto.subtle.importKey("raw",We(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new q("Unable to import cryptography key",{cause:X(e)}));var Pt=(t,e)=>e.algo===void 0||e.algo===0?Ct(t,e):kt(t,e);var C={},It=5,xr=t=>(v.emit("UPLOAD_CANCELLED",t.success),N(void 0)),Lr=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Pr(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),Pt(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(F(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")):F(e,{chunksReady:e.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?Dr(e).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),N(void 0))):N(void 0)})}else{let s=new U("Can't retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),O(s)}}else{let i=new U(o.msg);return v.emit("OPERATION_FAILED",i),O(i)}}else{let o=new U("Can't retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",o),O(o)}},Or=(t,e)=>{if(t.success)return t.j===0&&(F(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),v.emit("UPLOAD_STARTED")),F(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),v.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(F(e,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),N(void 0);{let r=new U(t.msg);return v.emit("OPERATION_FAILED",r),O(r)}},br=(t,e)=>{let r=kr(t.data),n;if(r)if(!r.action&&r.msg){let o=new U(r.msg);return v.emit("OPERATION_FAILED",o),O(o)}else"delay"in r?n=Or(r,e):n=xr(r);else n=Lr(t.data,e);return n},_r=t=>C!==void 0&&C[t]!==void 0&&C[t].readyState===WebSocket.CONNECTING,ze=t=>C!==void 0&&C[t]!==void 0&&C[t].readyState===WebSocket.OPEN;var qe=(t,e)=>{let r;return t.password?r={part:e,file_pwd:t.password}:r={part:e},$e(Tt(t),t,JSON.stringify(r))},Dr=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},$e(Tt(t),t,JSON.stringify(e))};var $e=(t,e,r)=>ze(t)?(C[t].onmessage=n=>br(n,e),C[t].send(r),N(void 0)):Rt(t).andThen(()=>$e(t,e,r)),Rt=(t,e=0)=>(!ze(t)&&!_r(t)&&(C[t]=new WebSocket(t),v.once("SOCKET_OPERATION_TERMINATED",()=>{C[t].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),C[t].onopen=()=>{v.emit("SOCKET_OPENED")},C[t].onclose=()=>{},C[t].onerror=()=>++e<=It?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${It}`),Rt(t,e)):(v.emit("SOCKET_ONERROR"),O(new ae(`Unable to connect to WebSocket ${t}.`)))),Sr(t).andThen(()=>N(t)).orElse(r=>O(r))),Sr=t=>b.fromPromise(new Promise((e,r)=>{ze(t)?e(void 0):(v.once("SOCKET_OPENED",()=>{e(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new ae)}))}),e=>X(e));var Cr=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,new URL(r.origin+r.pathname)},Tt=t=>Cr(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString();var kr=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Pr=t=>typeof t=="object"&&t!==null&&!("msg"in t);var Xe=Ne(Nt(),1);var pe=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ge=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ut=t=>globalThis.DOMException===void 0?new Ge(t):new DOMException(t),Bt=t=>{let e=t.reason===void 0?Ut("This operation was aborted."):t.reason;return e instanceof Error?e:Ut(e)};function Ve(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,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(e.signal){let{signal:p}=e;p.aborted&&l(Bt(p));let m=()=>{l(Bt(p))};p.addEventListener("abort",m,{once:!0}),t.finally(()=>{p.removeEventListener("abort",m)})}if(r===Number.POSITIVE_INFINITY){t.then(f,l);return}let h=new pe;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(p){l(p)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?f():o instanceof Error?l(o):(h.message=o!=null?o:`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await t)}catch(p){l(p)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Ye(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 B,me=class{constructor(){A(this,B,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&d(this,B)[this.size-1].priority>=r.priority){d(this,B).push(n);return}let o=Ye(d(this,B),n,(i,s)=>s.priority-i.priority);d(this,B).splice(o,0,n)}dequeue(){let e=d(this,B).shift();return e==null?void 0:e.run}filter(e){return d(this,B).filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return d(this,B).length}};B=new WeakMap;var re,ne,$,ve,oe,ge,I,ie,S,we,R,se,J,Ee,y,jt,Wt,Ft,Jt,zt,Se,Ke,Qe,Ce,qt,ke,ye=class extends Xe.default{constructor(r){var n,o,i,s;super();A(this,y);A(this,re);A(this,ne);A(this,$,0);A(this,ve);A(this,oe);A(this,ge,0);A(this,I);A(this,ie);A(this,S);A(this,we);A(this,R,0);A(this,se);A(this,J);A(this,Ee);T(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:me,...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})`);E(this,re,r.carryoverConcurrencyCount),E(this,ne,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),E(this,ve,r.intervalCap),E(this,oe,r.interval),E(this,S,new r.queueClass),E(this,we,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,E(this,Ee,r.throwOnTimeout===!0),E(this,J,r.autoStart===!1)}get concurrency(){return d(this,se)}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})`);E(this,se,r),x(this,y,Ce).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:d(this,Ee),...n},new Promise((o,i)=>{d(this,S).enqueue(async()=>{var s;Ae(this,R)._++,Ae(this,$)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=Ve(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,x(this,y,qt).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{x(this,y,Ft).call(this)}},n),this.emit("add"),x(this,y,Se).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return d(this,J)?(E(this,J,!1),x(this,y,Ce).call(this),this):this}pause(){E(this,J,!0)}clear(){E(this,S,new(d(this,we)))}async onEmpty(){d(this,S).size!==0&&await x(this,y,ke).call(this,"empty")}async onSizeLessThan(r){d(this,S).size<r||await x(this,y,ke).call(this,"next",()=>d(this,S).size<r)}async onIdle(){d(this,R)===0&&d(this,S).size===0||await x(this,y,ke).call(this,"idle")}get size(){return d(this,S).size}sizeBy(r){return d(this,S).filter(r).length}get pending(){return d(this,R)}get isPaused(){return d(this,J)}};re=new WeakMap,ne=new WeakMap,$=new WeakMap,ve=new WeakMap,oe=new WeakMap,ge=new WeakMap,I=new WeakMap,ie=new WeakMap,S=new WeakMap,we=new WeakMap,R=new WeakMap,se=new WeakMap,J=new WeakMap,Ee=new WeakMap,y=new WeakSet,jt=function(){return d(this,ne)||d(this,$)<d(this,ve)},Wt=function(){return d(this,R)<d(this,se)},Ft=function(){Ae(this,R)._--,x(this,y,Se).call(this),this.emit("next")},Jt=function(){x(this,y,Qe).call(this),x(this,y,Ke).call(this),E(this,ie,void 0)},zt=function(){let r=Date.now();if(d(this,I)===void 0){let n=d(this,ge)-r;if(n<0)E(this,$,d(this,re)?d(this,R):0);else return d(this,ie)===void 0&&E(this,ie,setTimeout(()=>{x(this,y,Jt).call(this)},n)),!0}return!1},Se=function(){if(d(this,S).size===0)return d(this,I)&&clearInterval(d(this,I)),E(this,I,void 0),this.emit("empty"),d(this,R)===0&&this.emit("idle"),!1;if(!d(this,J)){let r=!d(this,y,zt);if(d(this,y,jt)&&d(this,y,Wt)){let n=d(this,S).dequeue();return n?(this.emit("active"),n(),r&&x(this,y,Ke).call(this),!0):!1}}return!1},Ke=function(){d(this,ne)||d(this,I)!==void 0||(E(this,I,setInterval(()=>{x(this,y,Qe).call(this)},d(this,oe))),E(this,ge,Date.now()+d(this,oe)))},Qe=function(){d(this,$)===0&&d(this,R)===0&&d(this,I)&&(clearInterval(d(this,I)),E(this,I,void 0)),E(this,$,d(this,re)?d(this,R):0),x(this,y,Ce).call(this)},Ce=function(){for(;x(this,y,Se).call(this););},qt=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 Mr=[],Ze=navigator.hardwareConcurrency||4,Pe=new ye({concurrency:Ze,autoStart:!1}),Ie=0,$t=!1,Re=!1;self.onmessage=t=>{$t||(At(),$t=!0);let e=t.data;switch(e.action){case 5:Re=!0,self.postMessage({event:"JOB_PAUSED"});break;case 8:Re=!1,self.postMessage({event:"JOB_RESUMED"});break;default:v.once("DOWNLOAD_COMPLETE",()=>{self.postMessage({event:"DOWNLOAD_COMPLETE"})}),v.on("FILE_UPDATED",F),v.on("CHUNK_DOWNLOADED",(r,n)=>{self.postMessage({event:"CHUNK_DOWNLOADED",chunk:{buffer:r,index:n}})}),Nr(e).mapErr(r=>{Et(e.args.lufiFile,r)})}};var Nr=t=>{let{lufiFile:e}=t.args;return v.on("CHUNK_DOWNLOADED",(r,n)=>{Mr[n]=r,Ie--,!Re&&Ie<Ze&&Pe.start()}),v.on("DOWNLOAD_STARTED",async()=>{for(let r=1;r<e.totalChunks;r++)await Pe.add(async()=>{await qe(e,r),Ie++,(Re||Ie===Ze)&&Pe.pause()});Pe.start()}),qe(e,0)};export{Ze as QUEUE_CONCURRENCY_LIMIT,Ie as itemsInQueue,Pe as queue};
|