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

2 lines
54 KiB
JavaScript

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