diff --git a/themes/default/public/js/lufi.js b/themes/default/public/js/lufi.js index e3b702e..f688227 100755 --- a/themes/default/public/js/lufi.js +++ b/themes/default/public/js/lufi.js @@ -1 +1 @@ -var qr=Object.create;var $e=Object.defineProperty;var Kr=Object.getOwnPropertyDescriptor;var Zr=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Vr=Object.prototype.hasOwnProperty;var Xr=(t,e,r)=>e in t?$e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Qr=(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 Gt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Yr=(t,e)=>{for(var r in e)$e(t,r,{get:e[r],enumerable:!0})},en=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Zr(e))!Vr.call(t,i)&&i!==r&&$e(t,i,{get:()=>e[i],enumerable:!(n=Kr(e,i))||n.enumerable});return t};var Et=(t,e,r)=>(r=t!=null?qr($r(t)):{},en(e||!t||!t.__esModule?$e(r,"default",{value:t,enumerable:!0}):r,t));var d=(t,e,r)=>Xr(t,typeof e!="symbol"?e+"":e,r);var xt=Gt((ei,At)=>{"use strict";var Oe=typeof Reflect=="object"?Reflect:null,Wt=Oe&&typeof Oe.apply=="function"?Oe.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Ve;Oe&&typeof Oe.ownKeys=="function"?Ve=Oe.ownKeys:Object.getOwnPropertySymbols?Ve=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Ve=function(e){return Object.getOwnPropertyNames(e)};function tn(t){console&&console.warn&&console.warn(t)}var qt=Number.isNaN||function(e){return e!==e};function M(){M.init.call(this)}At.exports=M;At.exports.once=sn;M.EventEmitter=M;M.prototype._events=void 0;M.prototype._eventsCount=0;M.prototype._maxListeners=void 0;var Ht=10;function Xe(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(M,"defaultMaxListeners",{enumerable:!0,get:function(){return Ht},set:function(t){if(typeof t!="number"||t<0||qt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Ht=t}});M.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};M.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||qt(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 Kt(t){return t._maxListeners===void 0?M.defaultMaxListeners:t._maxListeners}M.prototype.getMaxListeners=function(){return Kt(this)};M.prototype.emit=function(e){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var f=o[e];if(f===void 0)return!1;if(typeof f=="function")Wt(f,this,r);else for(var c=f.length,h=Qt(f,c),n=0;n0&&s.length>i&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,tn(a)}return t}M.prototype.addListener=function(e,r){return Zt(this,e,r,!1)};M.prototype.on=M.prototype.addListener;M.prototype.prependListener=function(e,r){return Zt(this,e,r,!0)};function rn(){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 $t(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=rn.bind(n);return i.listener=r,n.wrapFn=i,i}M.prototype.once=function(e,r){return Xe(r),this.on(e,$t(this,e,r)),this};M.prototype.prependOnceListener=function(e,r){return Xe(r),this.prependListener(e,$t(this,e,r)),this};M.prototype.removeListener=function(e,r){var n,i,o,s,a;if(Xe(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,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){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():nn(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};M.prototype.off=M.prototype.removeListener;M.prototype.removeAllListeners=function(e){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[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(e,r[i]);return this};function Vt(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?on(i):Qt(i,i.length)}M.prototype.listeners=function(e){return Vt(this,e,!0)};M.prototype.rawListeners=function(e){return Vt(this,e,!1)};M.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Xt.call(t,e)};M.prototype.listenerCount=Xt;function Xt(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}M.prototype.eventNames=function(){return this._eventsCount>0?Ve(this._events):[]};function Qt(t,e){for(var r=new Array(e),n=0;n{"use strict";var u={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}}};u.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,i,o=this.w[0][4],s=this.w[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new u.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),i=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[r&255],t%e===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],i[e]=4>=t||4>e?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};u.cipher.aes.prototype={encrypt:function(t){return fr(this,t,0)},decrypt:function(t){return fr(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],i,o,s,a=[],f=[],c,h,l,p;for(i=0;256>i;i++)f[(a[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=c||1,s=f[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=a[i=a[c=a[o]]],p=16843009*h^65537*i^257*c^16843008*o,h=257*a[l]^16843008*l,i=0;4>i;i++)t[i][o]=h=h<<24^h>>>8,e[i][l]=p=p<<24^p>>>8;for(i=0;5>i;i++)t[i]=t[i].slice(0),e[i]=e[i].slice(0)}};function fr(t,e,r){if(e.length!==4)throw new u.exception.invalid("invalid aes block size");var n=t.b[r],i=e[0]^n[0],o=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,f,c,h=n.length/4-2,l,p=4,v=[0,0,0,0];a=t.w[r],t=a[0];var A=a[1],E=a[2],y=a[3],D=a[4];for(l=0;l>>24]^A[o>>16&255]^E[s>>8&255]^y[e&255]^n[p],f=t[o>>>24]^A[s>>16&255]^E[e>>8&255]^y[i&255]^n[p+1],c=t[s>>>24]^A[e>>16&255]^E[i>>8&255]^y[o&255]^n[p+2],e=t[e>>>24]^A[i>>16&255]^E[o>>8&255]^y[s&255]^n[p+3],p+=4,i=a,o=f,s=c;for(l=0;4>l;l++)v[r?3&-l:l]=D[i>>>24]<<24^D[o>>16&255]<<16^D[s>>8&255]<<8^D[e&255]^n[p++],a=i,i=o,o=s,s=e,e=a;return v}u.bitArray={bitSlice:function(t,e,r){return t=u.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:u.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<>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(u.bitArray.bitLength(t)!==u.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[i]<<32-e;return i=t.length?t[t.length-1]:0,t=u.bitArray.getPartial(i),n.push(u.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};u.codec.utf8String={fromBits:function(t){var e="",r=u.bitArray.bitLength(t),n,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>i)>>>26),6>i?(s=t[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,i=0,o=u.codec.base64.S,s=0,a;for(e&&(o=o.substr(0,62)+"-_"),n=0;na)throw new u.exception.invalid("this isn't base64!");26>>i),s=a<<32-i):(i+=6,s^=a<<32-i)}return i&56&&r.push(u.bitArray.partial(i&56,s,1)),r}};u.codec.base64url={fromBits:function(t){return u.codec.base64.fromBits(t,1,1)},toBits:function(t){return u.codec.base64.toBits(t,1)}};u.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};u.hash.sha256.hash=function(t){return new u.hash.sha256().update(t).finalize()};u.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=u.codec.utf8String.toBits(t));var e,r=this.f=u.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+u.bitArray.bitLength(t),9007199254740991e;r++){for(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,i=this.g,o=this.b,s=i[0],a=i[1],f=i[2],c=i[3],h=i[4],l=i[5],p=i[6],v=i[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+v+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(p^h&(l^p))+o[e],v=p,p=l,l=h,h=c+r|0,c=f,f=a,a=s,s=r+(a&f^c&(a^f))+(a>>>2^a>>>13^a>>>22^a<<30^a<<19^a<<10)|0;i[0]=i[0]+s|0,i[1]=i[1]+a|0,i[2]=i[2]+f|0,i[3]=i[3]+c|0,i[4]=i[4]+h|0,i[5]=i[5]+l|0,i[6]=i[6]+p|0,i[7]=i[7]+v|0}};u.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};u.hash.sha512.hash=function(t){return new u.hash.sha512().update(t).finalize()};u.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=u.codec.utf8String.toBits(t));var e,r=this.f=u.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+u.bitArray.bitLength(t),9007199254740991r;n++){for(o=!0,i=2;i*i<=n;i++)if(n%i===0){o=!1;break}o&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,i=this.b,o=n[0],s=n[1],a=n[2],f=n[3],c=n[4],h=n[5],l=n[6],p=n[7],v=n[8],A=n[9],E=n[10],y=n[11],D=n[12],I=n[13],O=n[14],w=n[15],x;if(typeof Uint32Array<"u"){x=Array(160);for(var L=0;32>L;L++)x[L]=t[L]}else x=t;var L=o,b=s,g=a,m=f,k=c,C=h,F=l,V=p,P=v,S=A,_=E,R=y,K=D,G=I,me=O,Z=w;for(t=0;80>t;t++){if(16>t)e=x[2*t],r=x[2*t+1];else{r=x[2*(t-15)];var z=x[2*(t-15)+1];e=(z<<31|r>>>1)^(z<<24|r>>>8)^r>>>7;var X=(r<<31|z>>>1)^(r<<24|z>>>8)^(r<<25|z>>>7);r=x[2*(t-2)];var N=x[2*(t-2)+1],z=(N<<13|r>>>19)^(r<<3|N>>>29)^r>>>6,N=(r<<13|N>>>19)^(N<<3|r>>>29)^(r<<26|N>>>6),re=x[2*(t-7)],te=x[2*(t-16)],ne=x[2*(t-16)+1];r=X+x[2*(t-7)+1],e=e+re+(r>>>0>>0?1:0),r+=N,e+=z+(r>>>0>>0?1:0),r+=ne,e+=te+(r>>>0>>0?1:0)}x[2*t]=e|=0,x[2*t+1]=r|=0;var re=P&_^~P&K,Y=S&R^~S&G,N=L&g^L&k^g&k,j=b&m^b&C^m&C,te=(b<<4|L>>>28)^(L<<30|b>>>2)^(L<<25|b>>>7),ne=(L<<4|b>>>28)^(b<<30|L>>>2)^(b<<25|L>>>7),ge=i[2*t],Le=i[2*t+1],z=Z+((P<<18|S>>>14)^(P<<14|S>>>18)^(S<<23|P>>>9)),X=me+((S<<18|P>>>14)^(S<<14|P>>>18)^(P<<23|S>>>9))+(z>>>0>>0?1:0),z=z+Y,X=X+(re+(z>>>0>>0?1:0)),z=z+Le,X=X+(ge+(z>>>0>>0?1:0)),z=z+r|0,X=X+(e+(z>>>0>>0?1:0));r=ne+j,e=te+N+(r>>>0>>0?1:0),me=K,Z=G,K=_,G=R,_=P,R=S,S=V+z|0,P=F+X+(S>>>0>>0?1:0)|0,F=k,V=C,k=g,C=m,g=L,m=b,b=z+r|0,L=X+e+(b>>>0>>0?1:0)|0}s=n[1]=s+b|0,n[0]=o+L+(s>>>0>>0?1:0)|0,f=n[3]=f+m|0,n[2]=a+g+(f>>>0>>0?1:0)|0,h=n[5]=h+C|0,n[4]=c+k+(h>>>0>>0?1:0)|0,p=n[7]=p+V|0,n[6]=l+F+(p>>>0>>0?1:0)|0,A=n[9]=A+S|0,n[8]=v+P+(A>>>0>>0?1:0)|0,y=n[11]=y+R|0,n[10]=E+_+(y>>>0>>0?1:0)|0,I=n[13]=I+G|0,n[12]=D+K+(I>>>0>>0?1:0)|0,w=n[15]=w+Z|0,n[14]=O+me+(w>>>0>>0?1:0)|0}};u.mode.ccm={name:"ccm",F:[],listenProgress:function(t){u.mode.ccm.F.push(t)},unListenProgress:function(t){t=u.mode.ccm.F.indexOf(t),-1f)throw new u.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&c>>>8*o;o++);return o<15-f&&(o=15-f),r=a.clamp(r,8*(15-o)),e=u.mode.ccm.U(t,e,r,n,i,o),s=u.mode.ccm.V(t,s,r,e,i,o),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,i){i=i||64,n=n||[];var o=u.bitArray,s=o.bitLength(r)/8,c=o.bitLength(e),a=o.clamp(e,c-i),f=o.bitSlice(e,c-i),c=(c-i)/8;if(7>s)throw new u.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&c>>>8*e;e++);if(e<15-s&&(e=15-s),r=o.clamp(r,8*(15-e)),a=u.mode.ccm.V(t,a,r,f,i,e),t=u.mode.ccm.U(t,a.data,r,n,i,e),!o.equal(a.tag,t))throw new u.exception.corrupt("ccm: tag doesn't match");return a.data},ma:function(t,e,r,n,i,o){var s=[],a=u.bitArray,f=a.P;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|o-1)],n=a.concat(n,r),n[3]|=i,n=t.encrypt(n),e.length)for(r=a.bitLength(e)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,e),e=0;ei||16h&&(u.mode.ccm.da(s/f),h+=l),r[3]++,i=t.encrypt(r),e[s]^=i[0],e[s+1]^=i[1],e[s+2]^=i[2],e[s+3]^=i[3];return{tag:n,data:a.clamp(e,c)}}};u.misc.hmac=function(t,e){this.W=e=e||u.hash.sha256;var r=[[],[]],n,i=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>i&&(t=e.hash(t)),n=0;nn||0>r)throw new u.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=u.codec.utf8String.toBits(t)),typeof e=="string"&&(e=u.codec.utf8String.toBits(e)),i=i||u.misc.hmac,t=new i(t);var o,s,a,f,c=[],h=u.bitArray;for(f=1;32*c.length<(n||1);f++){for(i=o=t.encrypt(h.concat(e,[f])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=o),this.N++,this.b=u.hash.sha256.hash(this.b.concat(i)),this.K=new u.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,e,o,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,o,t.length]),this.h[s].update(t);break;default:f=1}if(f)throw new u.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,a===this.A&&(this.isReady()!==this.A&&cr("seeded",Math.max(this.u,this.i)),cr("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:je(this,this.la),mouseCollector:je(this,this.na),keyboardCollector:je(this,this.ja),accelerometerCollector:je(this,this.ca),touchCollector:je(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new u.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,i=this.J[t],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===e&&o.push(n);for(r=0;re&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function je(t,e){return function(){e.apply(t,arguments)}}u.random=new u.prng(6);e:try{if(tt=typeof Re<"u"&&Re.exports){try{rt=Qr("crypto")}catch{rt=null}tt=et=rt}if(tt&&et.randomBytes)Je=et.randomBytes(128),Je=new Uint32Array(new Uint8Array(Je).buffer),u.random.addEntropy(Je,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Ge=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Ge);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Ge);else break e;u.random.addEntropy(Ge,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 Je,et,Ge,tt,rt;u.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,r,n){r=r||{},n=n||{};var i=u.json,o=i.j({iv:u.random.randomWords(4,0)},i.defaults),s;if(i.j(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=u.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=u.codec.base64.toBits(o.iv)),!u.mode[o.mode]||!u.cipher[o.cipher]||typeof t=="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=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||4Jr,cancel:()=>jn,compress:()=>Gr,decompress:()=>Jn,download:()=>Gn,events:()=>gt,getFileIndexInQueue:()=>Xn,infos:()=>Wn,pause:()=>Hn,remove:()=>qn,resume:()=>Kn,upload:()=>$n});var jr=Et(xt());var un={withStackTrace:!1},rr=(t,e,r=un)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:i}};function Ce(t,e,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 a(h){try{c(n.next(h))}catch(l){s(l)}}function f(h){try{c(n.throw(h))}catch(l){s(l)}}function c(h){h.done?o(h.value):i(h.value).then(a,f)}c((n=n.apply(t,e||[])).next())})}function er(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 he(t){return this instanceof he?(this.v=t,this):new he(t)}function tr(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(v){return function(A){return Promise.resolve(A).then(v,l)}}function a(v,A){n[v]&&(i[v]=function(E){return new Promise(function(y,D){o.push([v,E,y,D])>1||f(v,E)})},A&&(i[v]=A(i[v])))}function f(v,A){try{c(n[v](A))}catch(E){p(o[0][3],E)}}function c(v){v.value instanceof he?Promise.resolve(v.value.v).then(h,l):p(o[0][2],v)}function h(v){f("next",v)}function l(v){f("throw",v)}function p(v,A){v(A),o.shift(),o.length&&f(o[0][0],o[0][1])}}function fn(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,o){e[i]=t[i]?function(s){return(r=!r)?{value:he(t[i](s)),done:!1}:o?o(s):s}:o}}function cn(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 er=="function"?er(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(s){return new Promise(function(a,f){s=t[o](s),i(a,f,s.done,s.value)})}}function i(o,s,a,f){Promise.resolve(f).then(function(c){o({value:c,done:a})},s)}}var U=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new ie(n));return new t(r)}static fromPromise(e,r){let n=e.then(i=>new ie(i)).catch(i=>new oe(r(i)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(Ce(this,void 0,void 0,function*(){try{return new ie(yield e(...n))}catch(i){return new oe(r?r(i):i)}}))}static combine(e){return hn(e)}static combineWithAllErrors(e){return ln(e)}map(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){return r.isErr()?new oe(r.error):new ie(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){if(r.isErr())return new oe(r.error);let n=yield e(r.value);return n.isErr()?new oe(n.error):new ie(r.value)})))}andTee(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){if(r.isErr())return new oe(r.error);try{yield e(r.value)}catch{}return new ie(r.value)})))}mapErr(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){return r.isOk()?new ie(r.value):new oe(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new oe(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new ie(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 tr(this,arguments,function*(){return yield he(yield he(yield*fn(cn(yield he(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return tr(this,arguments,function*(){let r=yield he(this._promise);return r.isErr()&&(yield yield he(W(r.error))),yield he(r.value)})}},H=t=>new U(Promise.resolve(new ie(t))),W=t=>new U(Promise.resolve(new oe(t))),ti=U.fromPromise,ri=U.fromSafePromise,ni=U.fromThrowable,nr=t=>{let e=we([]);for(let r of t)if(r.isErr()){e=le(r.error);break}else e.map(n=>n.push(r.value));return e},hn=t=>U.fromSafePromise(Promise.all(t)).andThen(nr),ir=t=>{let e=we([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=le([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},ln=t=>U.fromSafePromise(Promise.all(t)).andThen(ir),Lt;(function(t){function e(i,o){return(...s)=>{try{let a=i(...s);return we(a)}catch(a){return le(o?o(a):a)}}}t.fromThrowable=e;function r(i){return nr(i)}t.combine=r;function n(i){return ir(i)}t.combineWithAllErrors=n})(Lt||(Lt={}));var we=t=>new ie(t);function le(t){return new oe(t)}var ie=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return we(e(this.value))}mapErr(e){return we(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 we(this.value)}orElse(e){return we(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return U.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 rr("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},oe=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return le(this.error)}mapErr(e){return le(e(this.error))}andThrough(e){return le(this.error)}andTee(e){return le(this.error)}andThen(e){return le(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return W(this.error)}asyncAndThrough(e){return W(this.error)}asyncMap(e){return W(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield le(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw rr("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},ii=Lt.fromThrowable;var Ee=class t{constructor(e,r){d(this,"actionToken","");d(this,"chunksReady",0);d(this,"createdAt",0);d(this,"delay",0);d(this,"delAtFirstView",!1);d(this,"keys",{client:"",server:""});d(this,"name","");d(this,"password","");d(this,"queueIndex",0);d(this,"serverUrl");d(this,"size",0);d(this,"uploadStatus",3);d(this,"totalChunks",0);d(this,"type","");d(this,"zipped",!1);this.serverUrl=e,Object.assign(this,r)}downloadUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}r/${this.keys.server}#${this.keys.client}`)}removeUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}d/${this.keys.server}/${this.actionToken}`)}static fromDownloadUrl(e,r=""){let n=e.pathname.split("r/"),i={client:e.hash.slice(1).split("&")[0],server:n[1]};return new t(e.origin+n[0],{keys:i,password:r})}static fromRemoveUrl(e,r=""){let n=e.pathname.split("d/"),i=n[1].split("/"),o={client:"",server:i[0]};return new t(e.origin+n[0],{keys:o,password:r,actionToken:i[1]})}};var ur=Et(xt());var $=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 Qe=class extends ${constructor(){super(...arguments);d(this,"message","Unable to connect. Is the computer able to access the url?")}};var Ye=class extends ${constructor(){super(...arguments);d(this,"message","The server returned an error")}};var J=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)},sr=t=>{let e=t.href.match(/(.*?)\/?(?:\/[dr]{1}\/|login\/?|files\/?)/),r=e&&e[1]?e[1]:t.origin;return U.fromPromise(fetch(r+"/about/config"),n=>new Qe(void 0,{cause:J(n)})).andThen(n=>n.ok?U.fromPromise(n.json(),i=>J(i)):W(new Ye(void 0,{context:n.statusText})))},ar=()=>typeof Deno<"u",bt=()=>ar()||globalThis.isSecureContext||globalThis.location.protocol==="https:",Se=t=>ar()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t!=="encrypt"?`worker/${t}`:t}.js`));var Ae=class{constructor(e,r){d(this,"events",new ur.default);d(this,"lufiFile");d(this,"status",2);d(this,"downloadedFile");d(this,"worker");d(this,"isTerminated",!1);d(this,"complete",()=>{this.status=0,this.events.emit("JOB_TERMINATED")});d(this,"hasFailed",()=>this.status===1);d(this,"onError",e=>(this.worker.onerror=r=>{e(r)},this));d(this,"onMessage",e=>(this.worker.onmessage=r=>{e&&e(r);let n=r.data.event;n&&(n==="FILE_UPDATED"?Object.assign(this.lufiFile,r.data.lufiFile):this.dispatchEvent(n,r.data.error))},this));d(this,"onMessageError",e=>(this.worker.onmessageerror=r=>{e(r)},this));d(this,"onProgress",e=>(this.events.on("CHUNK_UPLOADED",()=>{e()}),this.events.on("CHUNK_DOWNLOADED",()=>{e()}),this));d(this,"requestMessage",(e,r=[])=>(this.worker.postMessage(e,r),this));d(this,"terminate",()=>(this.worker.terminate(),this));d(this,"waitForCompletion",()=>this.isTerminated?this.status===0?H(this):W(J("Job has failed")):U.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("JOB_TERMINATED",()=>{this.status===0&&e(this)})}),e=>J(e)));d(this,"waitForStart",()=>U.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("UPLOAD_STARTED",()=>{e(this)}),this.events.once("DOWNLOAD_STARTED",()=>{e(this)})}),e=>J(e)));d(this,"dispatchEvent",(e,r)=>{this.events.emit(e,r)});switch(r){case 0:this.worker=new Worker(Se("cancel"),{type:"module"});break;case 1:this.worker=new Worker(Se("download"),{type:"module"});break;case 2:this.worker=new Worker(Se("infos"),{type:"module"});break;case 3:this.worker=new Worker(Se("remove"),{type:"module"});break;case 4:this.worker=new Worker(Se("upload"),{type:"module"});break}this.lufiFile=e,this.events.once("JOB_TERMINATED",()=>{this.isTerminated=!0,this.terminate()}),this.events.once("OPERATION_FAILED",n=>{this.status=1,this.lufiFile.uploadStatus=2,this.events.emit("JOB_TERMINATED",n)}),this.onError(n=>console.error(n.error))}};var ke=(r=>(r[r.Sjcl=0]="Sjcl",r[r.WebCrypto=1]="WebCrypto",r))(ke||{});var Pe=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),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}Decode(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),i,o,s,a,f=0,c=0;for(;f>4,n[f++]=(o&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var zi=new Pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");var dn=new Pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function Dt(t){return dn.Encode(t)}var We=Et(lr());var ue=class extends ${};var Te=class extends ue{constructor(){super(...arguments);d(this,"message","Unable to hash the provided string")}};var pr=()=>{try{return H(We.default.codec.base64.fromBits(We.default.random.randomWords(8,10)))}catch(t){return W(new ue("Unable to generate key",{cause:J(t)}))}},vr=t=>{try{return H(We.default.codec.hex.fromBits(We.default.hash.sha512.hash(t)))}catch(e){return W(new Te(void 0,{cause:J(e)}))}};var mr=()=>U.fromPromise(new Promise((t,e)=>crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]).then(r=>crypto.subtle.exportKey("raw",r).then(n=>t(Dt(n))).catch(n=>{e(new ue("Unable to base64 encode the url",{cause:J(n)}))})).catch(r=>e(r))),t=>new ue("Unable to generate key",{cause:J(t)})),dr=t=>{let e=async()=>Array.from(new Uint8Array(await crypto.subtle.digest("SHA-512",new TextEncoder().encode(t)))).map(r=>r.toString(16).padStart(2,"0")).join("");return U.fromPromise(e(),r=>new Te(void 0,{cause:J(r)}))};var yr=(t=1)=>t===0?pr():mr(),Ct=(t,e)=>e===0?vr(t):dr(t);var gr={},Dn=function(t,e,r,n,i){var o=new Worker(gr[e]||(gr[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return o.onmessage=function(s){var a=s.data,f=a.$e$;if(f){var c=new Error(f[0]);c.code=f[1],c.stack=f[2],i(c,null)}else i(null,a)},o.postMessage(r,n),o},B=Uint8Array,ee=Uint16Array,Ke=Int32Array,Fe=new B([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ze=new B([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),He=new B([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Lr=function(t,e){for(var r=new ee(31),n=0;n<31;++n)r[n]=e+=1<>1|(T&21845)<<1,de=(de&52428)>>2|(de&13107)<<2,de=(de&61680)>>4|(de&3855)<<4,qe[T]=((de&65280)>>8|(de&255)<<8)>>1;var de,T,ae=function(t,e,r){for(var n=t.length,i=0,o=new ee(e);i>f]=c}else for(a=new ee(n),i=0;i>15-t[i]);return a},ye=new B(288);for(T=0;T<144;++T)ye[T]=8;var T;for(T=144;T<256;++T)ye[T]=9;var T;for(T=256;T<280;++T)ye[T]=7;var T;for(T=280;T<288;++T)ye[T]=8;var T,Me=new B(32);for(T=0;T<32;++T)Me[T]=5;var T,Cr=ae(ye,9,0),Sr=ae(ye,9,1),kr=ae(Me,5,0),Pr=ae(Me,5,1),it=function(t){for(var e=t[0],r=1;re&&(e=t[r]);return e},se=function(t,e,r){var n=e/8|0;return(t[n]|t[n+1]<<8)>>(e&7)&r},ot=function(t,e){var r=e/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(e&7)},Ze=function(t){return(t+7)/8|0},be=function(t,e,r){return(e==null||e<0)&&(e=0),(r==null||r>t.length)&&(r=t.length),new B(t.subarray(e,r))};var Rr=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],q=function(t,e,r){var n=new Error(e||Rr[t]);if(n.code=t,Error.captureStackTrace&&Error.captureStackTrace(n,q),!r)throw n;return n},Tr=function(t,e,r,n){var i=t.length,o=n?n.length:0;if(!i||e.f&&!e.l)return r||new B(0);var s=!r,a=s||e.i!=2,f=e.i;s&&(r=new B(i*3));var c=function(X){var _e=r.length;if(X>_e){var De=new B(Math.max(_e*2,X));De.set(r),r=De}},h=e.f||0,l=e.p||0,p=e.b||0,v=e.l,A=e.d,E=e.m,y=e.n,D=i*8;do{if(!v){h=se(t,l,1);var I=se(t,l+1,3);if(l+=3,I)if(I==1)v=Sr,A=Pr,E=9,y=5;else if(I==2){var L=se(t,l,31)+257,b=se(t,l+10,15)+4,g=L+se(t,l+5,31)+1;l+=14;for(var m=new B(g),k=new B(19),C=0;C>4;if(O<16)m[C++]=O;else{var _=0,R=0;for(O==16?(R=3+se(t,l,3),l+=2,_=m[C-1]):O==17?(R=3+se(t,l,7),l+=3):O==18&&(R=11+se(t,l,127),l+=7);R--;)m[C++]=_}}var K=m.subarray(0,L),G=m.subarray(L);E=it(K),y=it(G),v=ae(K,E,1),A=ae(G,y,1)}else q(1);else{var O=Ze(l)+4,w=t[O-4]|t[O-3]<<8,x=O+w;if(x>i){f&&q(0);break}a&&c(p+w),r.set(t.subarray(O,x),p),e.b=p+=w,e.p=l=x*8,e.f=h;continue}if(l>D){f&&q(0);break}}a&&c(p+131072);for(var me=(1<>4;if(l+=_&15,l>D){f&&q(0);break}if(_||q(2),Y<256)r[p++]=Y;else if(Y==256){re=l,v=null;break}else{var N=Y-254;if(Y>264){var C=Y-257,j=Fe[C];N=se(t,l,(1<>4;te||q(3),l+=te&15;var G=Or[ne];if(ne>3){var j=ze[ne];G+=ot(t,l)&(1<D){f&&q(0);break}a&&c(p+131072);var ge=p+N;if(p>8},Ue=function(t,e,r){r<<=e&7;var n=e/8|0;t[n]|=r,t[n+1]|=r>>8,t[n+2]|=r>>16},st=function(t,e){for(var r=[],n=0;np&&(p=o[n].s);var v=new ee(p+1),A=ut(r[h-1],v,0);if(A>e){var n=0,E=0,y=A-e,D=1<e)E+=D-(1<>=y;E>0;){var O=o[n].s;v[O]=0&&E;--n){var w=o[n].s;v[w]==e&&(--v[w],++E)}A=e}return{t:new B(v),l:A}},ut=function(t,e,r){return t.s==-1?Math.max(ut(t.l,e,r+1),ut(t.r,e,r+1)):e[t.s]=r},Pt=function(t){for(var e=t.length;e&&!t[--e];);for(var r=new ee(++e),n=0,i=t[0],o=1,s=function(f){r[n++]=f},a=1;a<=e;++a)if(t[a]==i&&a!=e)++o;else{if(!i&&o>2){for(;o>138;o-=138)s(32754);o>2&&(s(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(s(i),--o;o>6;o-=6)s(8304);o>2&&(s(o-3<<5|8208),o=0)}for(;o--;)s(i);o=1,i=t[a]}return{c:r.subarray(0,n),n:e}},Ie=function(t,e){for(var r=0,n=0;n>8,t[i+2]=t[i]^255,t[i+3]=t[i+1]^255;for(var o=0;o4&&!k[He[F-1]];--F);var V=c+5<<3,P=Ie(i,ye)+Ie(o,Me)+s,S=Ie(i,p)+Ie(o,E)+s+14+3*F+Ie(b,k)+2*b[16]+3*b[17]+7*b[18];if(f>=0&&V<=P&&V<=S)return Mt(e,h,t.subarray(f,f+c));var _,R,K,G;if(pe(e,h,1+(S15&&(pe(e,h,Y[g]>>5&127),h+=Y[g]>>12)}}else _=Cr,R=ye,K=kr,G=Me;for(var g=0;g255){var N=j>>18&31;Ue(e,h,_[N+257]),h+=R[N+257],N>7&&(pe(e,h,j>>23&31),h+=Fe[N]);var te=j&31;Ue(e,h,K[te]),h+=G[te],te>3&&(Ue(e,h,j>>5&8191),h+=ze[te])}else Ue(e,h,_[j]),h+=R[j]}return Ue(e,h,_[256]),h+R[256]},Ur=new Ke([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Ft=new B(0),Ir=function(t,e,r,n,i,o){var s=o.z||t.length,a=new B(n+s+5*(1+Math.ceil(s/7e3))+i),f=a.subarray(n,a.length-i),c=o.l,h=(o.r||0)&7;if(e){h&&(f[0]=o.r>>3);for(var l=Ur[e-1],p=l>>13,v=l&8191,A=(1<7e3||k>24576)&&(_>423||!c)){h=Rt(t,f,0,w,x,L,g,k,F,m-F,h),k=b=g=0,F=m;for(var R=0;R<286;++R)x[R]=0;for(var R=0;R<30;++R)L[R]=0}var K=2,G=0,me=v,Z=P-S&32767;if(_>2&&V==O(m-Z))for(var re=Math.min(p,_)-1,Y=Math.min(32767,m),N=Math.min(258,_);Z<=Y&&--me&&P!=S;){if(t[m+K]==t[m+K-Z]){for(var j=0;jK){if(K=j,G=Z,j>re)break;for(var te=Math.min(Z,j-2),ne=0,R=0;Rne&&(ne=z,S=ge)}}}P=S,S=E[P],Z+=P-S&32767}if(G){w[k++]=268435456|at[K]<<18|kt[G];var X=at[K]&31,_e=kt[G]&31;g+=Fe[X]+ze[_e],++x[257+X],++L[_e],C=m+K,++b}else w[k++]=t[m],++x[t[m]]}}for(m=Math.max(m,C);m=s&&(f[h/8|0]=c,De=s),h=Mt(f,h+1,t.subarray(m,De))}o.i=s}return be(a,0,n+Ze(h)+i)},On=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var r=e,n=9;--n;)r=(r&1&&-306674912)^r>>>1;t[e]=r}return t}(),Cn=function(){var t=-1;return{p:function(e){for(var r=t,n=0;n>>8;t=r},d:function(){return~t}}};var Mr=function(t,e,r,n,i){if(!i&&(i={l:1},e.dictionary)){var o=e.dictionary.subarray(-32768),s=new B(o.length+t.length);s.set(o),s.set(t,o.length),t=s,i.w=o.length}return Ir(t,e.level==null?6:e.level,e.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):20:12+e.mem,r,n,i)},zt=function(t,e){var r={};for(var n in t)r[n]=t[n];for(var n in e)r[n]=e[n];return r},wr=function(t,e,r){for(var n=t(),i=t.toString(),o=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),s=0;s>>0},St=function(t,e){return fe(t,e)+fe(t,e+4)*4294967296},Q=function(t,e,r){for(;r;++e)t[e]=r,r>>>=8};function Tn(t,e,r){return r||(r=e,e={}),typeof r!="function"&&q(7),zr(t,e,[Rn],function(n){return ct(Bt(n.data[0],n.data[1]))},0,r)}function Bt(t,e){return Mr(t,e||{},0,0)}function Un(t,e,r){return r||(r=e,e={}),typeof r!="function"&&q(7),zr(t,e,[Pn],function(n){return ct(_t(n.data[0],Fr(n.data[1])))},1,r)}function _t(t,e){return Tr(t,{i:2},e&&e.out,e&&e.dictionary)}var Br=function(t,e,r,n){for(var i in t){var o=t[i],s=e+i,a=n;Array.isArray(o)&&(a=zt(n,o[1]),o=o[0]),o instanceof B?r[s]=[o,a]:(r[s+="/"]=[new B(0),a],Br(o,s,r,n))}},Er=typeof TextEncoder<"u"&&new TextEncoder,Tt=typeof TextDecoder<"u"&&new TextDecoder,In=0;try{Tt.decode(Ft,{stream:!0}),In=1}catch{}var Mn=function(t){for(var e="",r=0;;){var n=t[r++],i=(n>127)+(n>223)+(n>239);if(r+i>t.length)return{s:e,r:be(t,r-1)};i?i==3?(n=((n&15)<<18|(t[r++]&63)<<12|(t[r++]&63)<<6|t[r++]&63)-65536,e+=String.fromCharCode(55296|n>>10,56320|n&1023)):i&1?e+=String.fromCharCode((n&31)<<6|t[r++]&63):e+=String.fromCharCode((n&15)<<12|(t[r++]&63)<<6|t[r++]&63):e+=String.fromCharCode(n)}};function Ar(t,e){if(e){for(var r=new B(t.length),n=0;n>1)),s=0,a=function(h){o[s++]=h},n=0;no.length){var f=new B(s+8+(i-n<<1));f.set(o),o=f}var c=t.charCodeAt(n);c<128||e?a(c):c<2048?(a(192|c>>6),a(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|t.charCodeAt(++n)&1023,a(240|c>>18),a(128|c>>12&63),a(128|c>>6&63),a(128|c&63)):(a(224|c>>12),a(128|c>>6&63),a(128|c&63))}return be(o,0,s)}function Fn(t,e){if(e){for(var r="",n=0;n65535&&q(9),e+=n+4}return e},xr=function(t,e,r,n,i,o,s,a){var f=n.length,c=r.extra,h=a&&a.length,l=Ut(c);Q(t,e,s!=null?33639248:67324752),e+=4,s!=null&&(t[e++]=20,t[e++]=r.os),t[e]=20,e+=2,t[e++]=r.flag<<1|(o<0&&8),t[e++]=i&&8,t[e++]=r.compression&255,t[e++]=r.compression>>8;var p=new Date(r.mtime==null?Date.now():r.mtime),v=p.getFullYear()-1980;if((v<0||v>119)&&q(10),Q(t,e,v<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,o!=-1&&(Q(t,e,r.crc),Q(t,e+4,o<0?-o-2:o),Q(t,e+8,r.size)),Q(t,e+12,f),Q(t,e+14,l),e+=16,s!=null&&(Q(t,e,h),Q(t,e+6,r.attrs),Q(t,e+10,s),e+=14),t.set(n,e),e+=f,l)for(var A in c){var E=c[A],y=E.length;Q(t,e,+A),Q(t,e+2,y),t.set(E,e+4),e+=4+y}return h&&(t.set(a,e),e+=h),e},Nn=function(t,e,r,n,i){Q(t,e,101010256),Q(t,e+8,r),Q(t,e+10,r),Q(t,e+12,n),Q(t,e+16,i)};function _r(t,e,r){r||(r=e,e={}),typeof r!="function"&&q(7);var n={};Br(t,"",n,e);var i=Object.keys(n),o=i.length,s=0,a=0,f=o,c=new Array(o),h=[],l=function(){for(var y=0;y65535&&P(q(11,0,1),null),!V)P(null,O);else if(L<16e4)try{P(null,Bt(O,w))}catch(S){P(S,null)}else h.push(Tn(O,w,P))},E=0;E65558)return s(q(13,0,1),null),i;var f=ve(t,a+8);if(f){var c=f,h=fe(t,a+16),l=h==4294967295||c==65535;if(l){var p=fe(t,a-12);l=fe(t,p)==101075792,l&&(c=f=fe(t,p+32),h=fe(t,p+48))}for(var v=e&&e.filter,A=function(y){var D=Bn(t,h,l),I=D[0],O=D[1],w=D[2],x=D[3],L=D[4],b=D[5],g=zn(t,b);h=L;var m=function(C,F){C?(i(),s(C,null)):(F&&(o[x]=F),--f||s(null,o))};if(!v||v({name:x,size:O,originalSize:w,compression:I}))if(!I)m(null,be(t,g,g+O));else if(I==8){var k=t.subarray(g,g+O);if(w<524288||O>.8*w)try{m(null,_t(k,{out:new B(w)}))}catch(C){m(C,null)}else n.push(Un(k,{size:w},m))}else m(q(14,"unknown compression type "+I,1),null);else m(null,null)},E=0;E{t.terminate();let e=new Ae(t.lufiFile,0);return U.fromPromise(new Promise((r,n)=>{e.onMessage(i=>{i.data.event==="UPLOAD_CANCELLED"&&(xe[e.lufiFile.keys.client].uploadStatus=0,r(e)),i.data.event==="OPERATION_FAILED"&&n(new ce("An error occured while trying to cancel an upload",{cause:i.data.error}))}).requestMessage({args:{lufiFile:e.lufiFile}})}),r=>J(r))},Jr=(t,e={})=>{let r=async n=>{var i;for(let o of n){let s=((i=o.name.split("/"))==null?void 0:i.pop())||o.name,a=s.split(".").shift(),f=s.split(".").pop(),c=s;if(e[c]!==void 0){let h=1;do c=`${a}_(${h}).${f}`,h++;while(e[c]!==void 0)}gt.emit("ARCHIVE_ADDED_FILE",{name:c,size:o.size}),e[c]=await o.bytes()}};return U.fromPromise(r(t),n=>J(n)).andThen(()=>H(e))},Gr=(t,e)=>{let r=()=>new Promise((n,i)=>{_r(t,(o,s)=>{o&&i(o),n(s)})});return U.fromPromise(r(),n=>n).andThen(n=>{try{return H(new File([new Blob([n])],e,{type:"application/zip"}))}catch(i){return W(i)}}).orElse(n=>W(new ht(void 0,{cause:J(n)})))},Jn=t=>{let e=async()=>{let r=await t.bytes();return new Promise((n,i)=>{Nr(r,(o,s)=>{o&&i(o),n(s)})})};return U.fromPromise(e(),r=>r).andThen(r=>{try{let n=[];for(let i in r)n.push(new File([new Blob([r[i]])],i));return H(n)}catch(n){return W(n)}}).orElse(r=>W(new lt(void 0,{cause:J(r)})))},Wr=(t,e)=>e?sr(t).andThen(r=>{if(r.version.tag>"0.07.0"){let n=bt()?1:0;return Ct(e,n).andThen(i=>H(Ee.fromDownloadUrl(t,i)))}else return H(Ee.fromDownloadUrl(t,e))}):H(Ee.fromDownloadUrl(t)),Gn=(t,e)=>Wr(t,e).andThen(r=>{let n=new Ae(r,1);return U.fromPromise(new Promise((i,o)=>n.onMessage(s=>{Hr(i,o,n,s),s.data.event==="CHUNK_DOWNLOADED"&&(n.downloadedFile=new File(Qn(n.downloadedFile,s.data.chunk),r.name,{type:r.type})),s.data.event==="DOWNLOAD_COMPLETE"&&n.complete()}).requestMessage({args:{lufiFile:r}})),i=>new pt(void 0,{cause:J(i)}))}),Wn=(t,e)=>Wr(t,e).andThen(r=>H(new Ae(r,2))).andThen(r=>U.fromPromise(new Promise((n,i)=>{r.onMessage(o=>{o.data.event==="INFOS_RETRIEVED"&&(r.complete(),n(r)),o.data.event==="OPERATION_FAILED"&&i(new ce("An error occured while trying to retrieve informations of the file",{cause:o.data.error}))}).requestMessage({args:{lufiFile:r.lufiFile}})}),n=>new vt(void 0,{cause:J(n)}))),Hn=t=>{try{return t.status=3,H(t.requestMessage({action:0,args:{lufiFile:t.lufiFile}}))}catch(e){return W(new mt(void 0,{cause:J(e)}))}},qn=(t,e)=>{let r=Ee.fromRemoveUrl(t,e),n=new Ae(r,3);return U.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="FILE_REMOVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(new ce("An error occured while trying to remove a file",{cause:s.data.error()}))}).requestMessage({args:{lufiFile:r}})}),i=>J(i))},Kn=t=>{try{return t.status=2,H(t.requestMessage({action:2,args:{lufiFile:t.lufiFile}}))}catch(e){return W(new dt(void 0,{cause:J(e)}))}},Zn=(t,e,r,n=jt)=>{gt.emit("SLICE_STARTED",xe[t.lufiFile.keys.client]);let i=Math.ceil(e.size/n)||1;return xe[t.lufiFile.keys.client].totalChunks=i,(async()=>{for(let s=0;s{t.events.once("UPLOAD_STARTED",()=>{h(void 0)})})}})(),H(void 0)},Nt=(t,e,r,n,i,o,s)=>yr(s).andThen(a=>o?Ct(o,s).andThen(f=>H({password:f,clientKey:a})):H({password:o,clientKey:a})).andThen(({password:a,clientKey:f})=>{xe[f]=new Ee(t.toString(),{delay:r,delAtFirstView:n,zipped:i,password:a,name:e.name.split("/").pop(),size:e.size,type:e.type,keys:{client:f,server:""}});let c=new Ae(xe[f],4);return xe[f].uploadStatus=4,Zn(c,e,s).andThen(()=>U.fromPromise(new Promise((h,l)=>{c.onMessage(p=>{switch(Hr(h,l,c,p),p.data.event){case"UPLOAD_COMPLETE":c.complete(),c.lufiFile.uploadStatus=1;break}})}),h=>J(h)))}),$n=(t,e,r=0,n=!1,i=!1,o="documents.zip",s="",a=1)=>{let f=[];return i?e.length===1&&e[0].type==="application/zip"?f.push(Nt(t,e[0],r,n,i,s,a)):f.push(Jr(e).andThen(c=>Gr(c,o).andThen(h=>(gt.emit("ARCHIVE_CREATED",h),Nt(t,h,r,n,i,s,a))))):e.forEach(c=>{f.push(Nt(t,c,r,n,i,s,a))}),U.combine(f).orElse(c=>W(new yt(void 0,{cause:c})))},Hr=(t,e,r,n)=>{n.data.event==="SOCKET_OPENED"&&t(r),n.data.event==="OPERATION_FAILED"&&e(new ce("The job returned an error",{cause:n.data.error}))},Vn=()=>Object.values(xe).filter(t=>t.uploadStatus===4),Xn=t=>Object.keys(Vn()).indexOf(t),Qn=(t,e)=>{if(t){let r=t.slice(0,e.index*jt),n=t.slice(e.index*jt);return[new Blob([r,e.buffer,n])]}else return[new Blob([e.buffer])]};export{ke as CryptoAlgorithm,U as ResultAsync,le as err,W as errAsync,bt as isSecureContext,Jt as lufi,we as ok,H as okAsync}; +var Hr=Object.create;var $e=Object.defineProperty;var qr=Object.getOwnPropertyDescriptor;var Kr=Object.getOwnPropertyNames;var Zr=Object.getPrototypeOf,$r=Object.prototype.hasOwnProperty;var Vr=(t,e,r)=>e in t?$e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Qr=(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 Jt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xr=(t,e)=>{for(var r in e)$e(t,r,{get:e[r],enumerable:!0})},Yr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Kr(e))!$r.call(t,i)&&i!==r&&$e(t,i,{get:()=>e[i],enumerable:!(n=qr(e,i))||n.enumerable});return t};var Et=(t,e,r)=>(r=t!=null?Hr(Zr(t)):{},Yr(e||!t||!t.__esModule?$e(r,"default",{value:t,enumerable:!0}):r,t));var d=(t,e,r)=>Vr(t,typeof e!="symbol"?e+"":e,r);var xt=Jt((Yn,At)=>{"use strict";var Oe=typeof Reflect=="object"?Reflect:null,Gt=Oe&&typeof Oe.apply=="function"?Oe.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Ve;Oe&&typeof Oe.ownKeys=="function"?Ve=Oe.ownKeys:Object.getOwnPropertySymbols?Ve=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Ve=function(e){return Object.getOwnPropertyNames(e)};function en(t){console&&console.warn&&console.warn(t)}var Ht=Number.isNaN||function(e){return e!==e};function M(){M.init.call(this)}At.exports=M;At.exports.once=on;M.EventEmitter=M;M.prototype._events=void 0;M.prototype._eventsCount=0;M.prototype._maxListeners=void 0;var Wt=10;function Qe(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(M,"defaultMaxListeners",{enumerable:!0,get:function(){return Wt},set:function(t){if(typeof t!="number"||t<0||Ht(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Wt=t}});M.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};M.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Ht(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 qt(t){return t._maxListeners===void 0?M.defaultMaxListeners:t._maxListeners}M.prototype.getMaxListeners=function(){return qt(this)};M.prototype.emit=function(e){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var f=o[e];if(f===void 0)return!1;if(typeof f=="function")Gt(f,this,r);else for(var c=f.length,h=Qt(f,c),n=0;n0&&s.length>i&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,en(a)}return t}M.prototype.addListener=function(e,r){return Kt(this,e,r,!1)};M.prototype.on=M.prototype.addListener;M.prototype.prependListener=function(e,r){return Kt(this,e,r,!0)};function tn(){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 Zt(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=tn.bind(n);return i.listener=r,n.wrapFn=i,i}M.prototype.once=function(e,r){return Qe(r),this.on(e,Zt(this,e,r)),this};M.prototype.prependOnceListener=function(e,r){return Qe(r),this.prependListener(e,Zt(this,e,r)),this};M.prototype.removeListener=function(e,r){var n,i,o,s,a;if(Qe(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,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){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():rn(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};M.prototype.off=M.prototype.removeListener;M.prototype.removeAllListeners=function(e){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[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(e,r[i]);return this};function $t(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?nn(i):Qt(i,i.length)}M.prototype.listeners=function(e){return $t(this,e,!0)};M.prototype.rawListeners=function(e){return $t(this,e,!1)};M.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Vt.call(t,e)};M.prototype.listenerCount=Vt;function Vt(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}M.prototype.eventNames=function(){return this._eventsCount>0?Ve(this._events):[]};function Qt(t,e){for(var r=new Array(e),n=0;n{"use strict";var u={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}}};u.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,i,o=this.w[0][4],s=this.w[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new u.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),i=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[r&255],t%e===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],i[e]=4>=t||4>e?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};u.cipher.aes.prototype={encrypt:function(t){return ur(this,t,0)},decrypt:function(t){return ur(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],i,o,s,a=[],f=[],c,h,l,p;for(i=0;256>i;i++)f[(a[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=c||1,s=f[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=a[i=a[c=a[o]]],p=16843009*h^65537*i^257*c^16843008*o,h=257*a[l]^16843008*l,i=0;4>i;i++)t[i][o]=h=h<<24^h>>>8,e[i][l]=p=p<<24^p>>>8;for(i=0;5>i;i++)t[i]=t[i].slice(0),e[i]=e[i].slice(0)}};function ur(t,e,r){if(e.length!==4)throw new u.exception.invalid("invalid aes block size");var n=t.b[r],i=e[0]^n[0],o=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,f,c,h=n.length/4-2,l,p=4,v=[0,0,0,0];a=t.w[r],t=a[0];var A=a[1],E=a[2],y=a[3],b=a[4];for(l=0;l>>24]^A[o>>16&255]^E[s>>8&255]^y[e&255]^n[p],f=t[o>>>24]^A[s>>16&255]^E[e>>8&255]^y[i&255]^n[p+1],c=t[s>>>24]^A[e>>16&255]^E[i>>8&255]^y[o&255]^n[p+2],e=t[e>>>24]^A[i>>16&255]^E[o>>8&255]^y[s&255]^n[p+3],p+=4,i=a,o=f,s=c;for(l=0;4>l;l++)v[r?3&-l:l]=b[i>>>24]<<24^b[o>>16&255]<<16^b[s>>8&255]<<8^b[e&255]^n[p++],a=i,i=o,o=s,s=e,e=a;return v}u.bitArray={bitSlice:function(t,e,r){return t=u.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:u.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<>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(u.bitArray.bitLength(t)!==u.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[i]<<32-e;return i=t.length?t[t.length-1]:0,t=u.bitArray.getPartial(i),n.push(u.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};u.codec.utf8String={fromBits:function(t){var e="",r=u.bitArray.bitLength(t),n,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>i)>>>26),6>i?(s=t[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,i=0,o=u.codec.base64.S,s=0,a;for(e&&(o=o.substr(0,62)+"-_"),n=0;na)throw new u.exception.invalid("this isn't base64!");26>>i),s=a<<32-i):(i+=6,s^=a<<32-i)}return i&56&&r.push(u.bitArray.partial(i&56,s,1)),r}};u.codec.base64url={fromBits:function(t){return u.codec.base64.fromBits(t,1,1)},toBits:function(t){return u.codec.base64.toBits(t,1)}};u.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};u.hash.sha256.hash=function(t){return new u.hash.sha256().update(t).finalize()};u.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=u.codec.utf8String.toBits(t));var e,r=this.f=u.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+u.bitArray.bitLength(t),9007199254740991e;r++){for(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,i=this.g,o=this.b,s=i[0],a=i[1],f=i[2],c=i[3],h=i[4],l=i[5],p=i[6],v=i[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+v+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(p^h&(l^p))+o[e],v=p,p=l,l=h,h=c+r|0,c=f,f=a,a=s,s=r+(a&f^c&(a^f))+(a>>>2^a>>>13^a>>>22^a<<30^a<<19^a<<10)|0;i[0]=i[0]+s|0,i[1]=i[1]+a|0,i[2]=i[2]+f|0,i[3]=i[3]+c|0,i[4]=i[4]+h|0,i[5]=i[5]+l|0,i[6]=i[6]+p|0,i[7]=i[7]+v|0}};u.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};u.hash.sha512.hash=function(t){return new u.hash.sha512().update(t).finalize()};u.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=u.codec.utf8String.toBits(t));var e,r=this.f=u.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+u.bitArray.bitLength(t),9007199254740991r;n++){for(o=!0,i=2;i*i<=n;i++)if(n%i===0){o=!1;break}o&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,i=this.b,o=n[0],s=n[1],a=n[2],f=n[3],c=n[4],h=n[5],l=n[6],p=n[7],v=n[8],A=n[9],E=n[10],y=n[11],b=n[12],I=n[13],O=n[14],w=n[15],x;if(typeof Uint32Array<"u"){x=Array(160);for(var L=0;32>L;L++)x[L]=t[L]}else x=t;var L=o,D=s,g=a,m=f,k=c,C=h,F=l,V=p,P=v,S=A,_=E,R=y,K=b,G=I,me=O,Z=w;for(t=0;80>t;t++){if(16>t)e=x[2*t],r=x[2*t+1];else{r=x[2*(t-15)];var z=x[2*(t-15)+1];e=(z<<31|r>>>1)^(z<<24|r>>>8)^r>>>7;var Q=(r<<31|z>>>1)^(r<<24|z>>>8)^(r<<25|z>>>7);r=x[2*(t-2)];var N=x[2*(t-2)+1],z=(N<<13|r>>>19)^(r<<3|N>>>29)^r>>>6,N=(r<<13|N>>>19)^(N<<3|r>>>29)^(r<<26|N>>>6),re=x[2*(t-7)],te=x[2*(t-16)],ne=x[2*(t-16)+1];r=Q+x[2*(t-7)+1],e=e+re+(r>>>0>>0?1:0),r+=N,e+=z+(r>>>0>>0?1:0),r+=ne,e+=te+(r>>>0>>0?1:0)}x[2*t]=e|=0,x[2*t+1]=r|=0;var re=P&_^~P&K,Y=S&R^~S&G,N=L&g^L&k^g&k,j=D&m^D&C^m&C,te=(D<<4|L>>>28)^(L<<30|D>>>2)^(L<<25|D>>>7),ne=(L<<4|D>>>28)^(D<<30|L>>>2)^(D<<25|L>>>7),ge=i[2*t],Le=i[2*t+1],z=Z+((P<<18|S>>>14)^(P<<14|S>>>18)^(S<<23|P>>>9)),Q=me+((S<<18|P>>>14)^(S<<14|P>>>18)^(P<<23|S>>>9))+(z>>>0>>0?1:0),z=z+Y,Q=Q+(re+(z>>>0>>0?1:0)),z=z+Le,Q=Q+(ge+(z>>>0>>0?1:0)),z=z+r|0,Q=Q+(e+(z>>>0>>0?1:0));r=ne+j,e=te+N+(r>>>0>>0?1:0),me=K,Z=G,K=_,G=R,_=P,R=S,S=V+z|0,P=F+Q+(S>>>0>>0?1:0)|0,F=k,V=C,k=g,C=m,g=L,m=D,D=z+r|0,L=Q+e+(D>>>0>>0?1:0)|0}s=n[1]=s+D|0,n[0]=o+L+(s>>>0>>0?1:0)|0,f=n[3]=f+m|0,n[2]=a+g+(f>>>0>>0?1:0)|0,h=n[5]=h+C|0,n[4]=c+k+(h>>>0>>0?1:0)|0,p=n[7]=p+V|0,n[6]=l+F+(p>>>0>>0?1:0)|0,A=n[9]=A+S|0,n[8]=v+P+(A>>>0>>0?1:0)|0,y=n[11]=y+R|0,n[10]=E+_+(y>>>0>>0?1:0)|0,I=n[13]=I+G|0,n[12]=b+K+(I>>>0>>0?1:0)|0,w=n[15]=w+Z|0,n[14]=O+me+(w>>>0>>0?1:0)|0}};u.mode.ccm={name:"ccm",F:[],listenProgress:function(t){u.mode.ccm.F.push(t)},unListenProgress:function(t){t=u.mode.ccm.F.indexOf(t),-1f)throw new u.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&c>>>8*o;o++);return o<15-f&&(o=15-f),r=a.clamp(r,8*(15-o)),e=u.mode.ccm.U(t,e,r,n,i,o),s=u.mode.ccm.V(t,s,r,e,i,o),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,i){i=i||64,n=n||[];var o=u.bitArray,s=o.bitLength(r)/8,c=o.bitLength(e),a=o.clamp(e,c-i),f=o.bitSlice(e,c-i),c=(c-i)/8;if(7>s)throw new u.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&c>>>8*e;e++);if(e<15-s&&(e=15-s),r=o.clamp(r,8*(15-e)),a=u.mode.ccm.V(t,a,r,f,i,e),t=u.mode.ccm.U(t,a.data,r,n,i,e),!o.equal(a.tag,t))throw new u.exception.corrupt("ccm: tag doesn't match");return a.data},ma:function(t,e,r,n,i,o){var s=[],a=u.bitArray,f=a.P;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|o-1)],n=a.concat(n,r),n[3]|=i,n=t.encrypt(n),e.length)for(r=a.bitLength(e)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,e),e=0;ei||16h&&(u.mode.ccm.da(s/f),h+=l),r[3]++,i=t.encrypt(r),e[s]^=i[0],e[s+1]^=i[1],e[s+2]^=i[2],e[s+3]^=i[3];return{tag:n,data:a.clamp(e,c)}}};u.misc.hmac=function(t,e){this.W=e=e||u.hash.sha256;var r=[[],[]],n,i=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>i&&(t=e.hash(t)),n=0;nn||0>r)throw new u.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=u.codec.utf8String.toBits(t)),typeof e=="string"&&(e=u.codec.utf8String.toBits(e)),i=i||u.misc.hmac,t=new i(t);var o,s,a,f,c=[],h=u.bitArray;for(f=1;32*c.length<(n||1);f++){for(i=o=t.encrypt(h.concat(e,[f])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=o),this.N++,this.b=u.hash.sha256.hash(this.b.concat(i)),this.K=new u.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,e,o,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,o,t.length]),this.h[s].update(t);break;default:f=1}if(f)throw new u.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,a===this.A&&(this.isReady()!==this.A&&fr("seeded",Math.max(this.u,this.i)),fr("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:je(this,this.la),mouseCollector:je(this,this.na),keyboardCollector:je(this,this.ja),accelerometerCollector:je(this,this.ca),touchCollector:je(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new u.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,i=this.J[t],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===e&&o.push(n);for(r=0;re&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function je(t,e){return function(){e.apply(t,arguments)}}u.random=new u.prng(6);e:try{if(tt=typeof Re<"u"&&Re.exports){try{rt=Qr("crypto")}catch{rt=null}tt=et=rt}if(tt&&et.randomBytes)Je=et.randomBytes(128),Je=new Uint32Array(new Uint8Array(Je).buffer),u.random.addEntropy(Je,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Ge=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Ge);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Ge);else break e;u.random.addEntropy(Ge,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 Je,et,Ge,tt,rt;u.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,r,n){r=r||{},n=n||{};var i=u.json,o=i.j({iv:u.random.randomWords(4,0)},i.defaults),s;if(i.j(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=u.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=u.codec.base64.toBits(o.iv)),!u.mode[o.mode]||!u.cipher[o.cipher]||typeof t=="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=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||4jr,cancel:()=>jn,compress:()=>Jr,decompress:()=>Jn,download:()=>Gn,events:()=>gt,getFileIndexInQueue:()=>Qn,infos:()=>Wn,pause:()=>Hn,remove:()=>qn,resume:()=>Kn,upload:()=>$n});var Nr=Et(xt());var an={withStackTrace:!1},tr=(t,e,r=an)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:i}};function Ce(t,e,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 a(h){try{c(n.next(h))}catch(l){s(l)}}function f(h){try{c(n.throw(h))}catch(l){s(l)}}function c(h){h.done?o(h.value):i(h.value).then(a,f)}c((n=n.apply(t,e||[])).next())})}function Yt(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 he(t){return this instanceof he?(this.v=t,this):new he(t)}function er(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(v){return function(A){return Promise.resolve(A).then(v,l)}}function a(v,A){n[v]&&(i[v]=function(E){return new Promise(function(y,b){o.push([v,E,y,b])>1||f(v,E)})},A&&(i[v]=A(i[v])))}function f(v,A){try{c(n[v](A))}catch(E){p(o[0][3],E)}}function c(v){v.value instanceof he?Promise.resolve(v.value.v).then(h,l):p(o[0][2],v)}function h(v){f("next",v)}function l(v){f("throw",v)}function p(v,A){v(A),o.shift(),o.length&&f(o[0][0],o[0][1])}}function un(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,o){e[i]=t[i]?function(s){return(r=!r)?{value:he(t[i](s)),done:!1}:o?o(s):s}:o}}function fn(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 Yt=="function"?Yt(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(s){return new Promise(function(a,f){s=t[o](s),i(a,f,s.done,s.value)})}}function i(o,s,a,f){Promise.resolve(f).then(function(c){o({value:c,done:a})},s)}}var U=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new ie(n));return new t(r)}static fromPromise(e,r){let n=e.then(i=>new ie(i)).catch(i=>new oe(r(i)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(Ce(this,void 0,void 0,function*(){try{return new ie(yield e(...n))}catch(i){return new oe(r?r(i):i)}}))}static combine(e){return cn(e)}static combineWithAllErrors(e){return hn(e)}map(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){return r.isErr()?new oe(r.error):new ie(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){if(r.isErr())return new oe(r.error);let n=yield e(r.value);return n.isErr()?new oe(n.error):new ie(r.value)})))}andTee(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){if(r.isErr())return new oe(r.error);try{yield e(r.value)}catch{}return new ie(r.value)})))}mapErr(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){return r.isOk()?new ie(r.value):new oe(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new oe(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>Ce(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new ie(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 er(this,arguments,function*(){return yield he(yield he(yield*un(fn(yield he(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return er(this,arguments,function*(){let r=yield he(this._promise);return r.isErr()&&(yield yield he(W(r.error))),yield he(r.value)})}},H=t=>new U(Promise.resolve(new ie(t))),W=t=>new U(Promise.resolve(new oe(t))),ei=U.fromPromise,ti=U.fromSafePromise,ri=U.fromThrowable,rr=t=>{let e=we([]);for(let r of t)if(r.isErr()){e=le(r.error);break}else e.map(n=>n.push(r.value));return e},cn=t=>U.fromSafePromise(Promise.all(t)).andThen(rr),nr=t=>{let e=we([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=le([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},hn=t=>U.fromSafePromise(Promise.all(t)).andThen(nr),Lt;(function(t){function e(i,o){return(...s)=>{try{let a=i(...s);return we(a)}catch(a){return le(o?o(a):a)}}}t.fromThrowable=e;function r(i){return rr(i)}t.combine=r;function n(i){return nr(i)}t.combineWithAllErrors=n})(Lt||(Lt={}));var we=t=>new ie(t);function le(t){return new oe(t)}var ie=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return we(e(this.value))}mapErr(e){return we(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 we(this.value)}orElse(e){return we(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return U.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 tr("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},oe=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return le(this.error)}mapErr(e){return le(e(this.error))}andThrough(e){return le(this.error)}andTee(e){return le(this.error)}andThen(e){return le(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return W(this.error)}asyncAndThrough(e){return W(this.error)}asyncMap(e){return W(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield le(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw tr("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},ni=Lt.fromThrowable;var Ee=class t{constructor(e,r){d(this,"actionToken","");d(this,"chunksReady",0);d(this,"createdAt",0);d(this,"delay",0);d(this,"delAtFirstView",!1);d(this,"keys",{client:"",server:""});d(this,"name","");d(this,"password","");d(this,"queueIndex",0);d(this,"serverUrl");d(this,"size",0);d(this,"uploadStatus",3);d(this,"totalChunks",0);d(this,"type","");d(this,"zipped",!1);this.serverUrl=e,Object.assign(this,r)}downloadUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}r/${this.keys.server}#${this.keys.client}`)}removeUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}d/${this.keys.server}/${this.actionToken}`)}static fromDownloadUrl(e,r=""){let n=e.pathname.split("r/"),i={client:e.hash.slice(1).split("&")[0],server:n[1]};return new t(e.origin+n[0],{keys:i,password:r})}static fromRemoveUrl(e,r=""){let n=e.pathname.split("d/"),i=n[1].split("/"),o={client:"",server:i[0]};return new t(e.origin+n[0],{keys:o,password:r,actionToken:i[1]})}};var ar=Et(xt());var $=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 Xe=class extends ${constructor(){super(...arguments);d(this,"message","Unable to connect. Is the computer able to access the url?")}};var Ye=class extends ${constructor(){super(...arguments);d(this,"message","The server returned an error")}};var J=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)},or=t=>{let e=t.href.match(/(.*?)\/?(?:\/[dr]{1}\/|login\/?|files\/?)/),r=e&&e[1]?e[1]:t.origin;return U.fromPromise(fetch(r+"/about/config"),n=>new Xe(void 0,{cause:J(n)})).andThen(n=>n.ok?U.fromPromise(n.json(),i=>J(i)):W(new Ye(void 0,{context:n.statusText})))},sr=()=>typeof Deno<"u",Dt=()=>sr()||globalThis.isSecureContext||globalThis.location.protocol==="https:",Se=t=>sr()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t!=="encrypt"?`worker/${t}`:t}.js`));var Ae=class{constructor(e,r){d(this,"events",new ar.default);d(this,"lufiFile");d(this,"status",2);d(this,"downloadedFile");d(this,"worker");d(this,"isTerminated",!1);d(this,"complete",()=>{this.status=0,this.events.emit("JOB_TERMINATED")});d(this,"hasFailed",()=>this.status===1);d(this,"onError",e=>(this.worker.onerror=r=>{e(r)},this));d(this,"onMessage",e=>(this.worker.onmessage=r=>{e&&e(r);let n=r.data.event;n&&(n==="FILE_UPDATED"?Object.assign(this.lufiFile,r.data.lufiFile):this.dispatchEvent(n,r.data.error))},this));d(this,"onMessageError",e=>(this.worker.onmessageerror=r=>{e(r)},this));d(this,"onProgress",e=>(this.events.on("CHUNK_UPLOADED",()=>{e()}),this.events.on("CHUNK_DOWNLOADED",()=>{e()}),this));d(this,"requestMessage",(e,r=[])=>(this.worker.postMessage(e,r),this));d(this,"terminate",()=>(this.worker.terminate(),this));d(this,"waitForCompletion",()=>this.isTerminated?this.status===0?H(this):W(J("Job has failed")):U.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("JOB_TERMINATED",()=>{this.status===0&&e(this)})}),e=>J(e)));d(this,"waitForStart",()=>U.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("UPLOAD_STARTED",()=>{e(this)}),this.events.once("DOWNLOAD_STARTED",()=>{e(this)})}),e=>J(e)));d(this,"dispatchEvent",(e,r)=>{this.events.emit(e,r)});switch(r){case 0:this.worker=new Worker(Se("cancel"),{type:"module"});break;case 1:this.worker=new Worker(Se("download"),{type:"module"});break;case 2:this.worker=new Worker(Se("infos"),{type:"module"});break;case 3:this.worker=new Worker(Se("remove"),{type:"module"});break;case 4:this.worker=new Worker(Se("upload"),{type:"module"});break}this.lufiFile=e,this.events.once("JOB_TERMINATED",()=>{this.isTerminated=!0,this.terminate()}),this.events.once("OPERATION_FAILED",n=>{this.status=1,this.lufiFile.uploadStatus=2,this.events.emit("JOB_TERMINATED",n)}),this.onError(n=>console.error(n.error))}};var ke=(r=>(r[r.Sjcl=0]="Sjcl",r[r.WebCrypto=1]="WebCrypto",r))(ke||{});var Pe=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),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}Decode(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),i,o,s,a,f=0,c=0;for(;f>4,n[f++]=(o&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var Fi=new Pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");var mn=new Pe("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function bt(t){return mn.Encode(t)}var We=Et(hr());var ue=class extends ${};var Te=class extends ue{constructor(){super(...arguments);d(this,"message","Unable to hash the provided string")}};var lr=()=>{try{return H(We.default.codec.base64.fromBits(We.default.random.randomWords(8,10)))}catch(t){return W(new ue("Unable to generate key",{cause:J(t)}))}},pr=t=>{try{return H(We.default.codec.hex.fromBits(We.default.hash.sha512.hash(t)))}catch(e){return W(new Te(void 0,{cause:J(e)}))}};var vr=()=>U.fromPromise(new Promise((t,e)=>crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]).then(r=>crypto.subtle.exportKey("raw",r).then(n=>t(bt(n))).catch(n=>{e(new ue("Unable to base64 encode the url",{cause:J(n)}))})).catch(r=>e(r))),t=>new ue("Unable to generate key",{cause:J(t)})),mr=t=>{let e=async()=>Array.from(new Uint8Array(await crypto.subtle.digest("SHA-512",new TextEncoder().encode(t)))).map(r=>r.toString(16).padStart(2,"0")).join("");return U.fromPromise(e(),r=>new Te(void 0,{cause:J(r)}))};var dr=(t=1)=>t===0?lr():vr(),Ct=(t,e)=>e===0?pr(t):mr(t);var yr={},Dn=function(t,e,r,n,i){var o=new Worker(yr[e]||(yr[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return o.onmessage=function(s){var a=s.data,f=a.$e$;if(f){var c=new Error(f[0]);c.code=f[1],c.stack=f[2],i(c,null)}else i(null,a)},o.postMessage(r,n),o},B=Uint8Array,ee=Uint16Array,Ke=Int32Array,Fe=new B([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ze=new B([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),He=new B([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),xr=function(t,e){for(var r=new ee(31),n=0;n<31;++n)r[n]=e+=1<>1|(T&21845)<<1,de=(de&52428)>>2|(de&13107)<<2,de=(de&61680)>>4|(de&3855)<<4,qe[T]=((de&65280)>>8|(de&255)<<8)>>1;var de,T,ae=function(t,e,r){for(var n=t.length,i=0,o=new ee(e);i>f]=c}else for(a=new ee(n),i=0;i>15-t[i]);return a},ye=new B(288);for(T=0;T<144;++T)ye[T]=8;var T;for(T=144;T<256;++T)ye[T]=9;var T;for(T=256;T<280;++T)ye[T]=7;var T;for(T=280;T<288;++T)ye[T]=8;var T,Me=new B(32);for(T=0;T<32;++T)Me[T]=5;var T,Or=ae(ye,9,0),Cr=ae(ye,9,1),Sr=ae(Me,5,0),kr=ae(Me,5,1),it=function(t){for(var e=t[0],r=1;re&&(e=t[r]);return e},se=function(t,e,r){var n=e/8|0;return(t[n]|t[n+1]<<8)>>(e&7)&r},ot=function(t,e){var r=e/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(e&7)},Ze=function(t){return(t+7)/8|0},De=function(t,e,r){return(e==null||e<0)&&(e=0),(r==null||r>t.length)&&(r=t.length),new B(t.subarray(e,r))};var Pr=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],q=function(t,e,r){var n=new Error(e||Pr[t]);if(n.code=t,Error.captureStackTrace&&Error.captureStackTrace(n,q),!r)throw n;return n},Rr=function(t,e,r,n){var i=t.length,o=n?n.length:0;if(!i||e.f&&!e.l)return r||new B(0);var s=!r,a=s||e.i!=2,f=e.i;s&&(r=new B(i*3));var c=function(Q){var _e=r.length;if(Q>_e){var be=new B(Math.max(_e*2,Q));be.set(r),r=be}},h=e.f||0,l=e.p||0,p=e.b||0,v=e.l,A=e.d,E=e.m,y=e.n,b=i*8;do{if(!v){h=se(t,l,1);var I=se(t,l+1,3);if(l+=3,I)if(I==1)v=Cr,A=kr,E=9,y=5;else if(I==2){var L=se(t,l,31)+257,D=se(t,l+10,15)+4,g=L+se(t,l+5,31)+1;l+=14;for(var m=new B(g),k=new B(19),C=0;C>4;if(O<16)m[C++]=O;else{var _=0,R=0;for(O==16?(R=3+se(t,l,3),l+=2,_=m[C-1]):O==17?(R=3+se(t,l,7),l+=3):O==18&&(R=11+se(t,l,127),l+=7);R--;)m[C++]=_}}var K=m.subarray(0,L),G=m.subarray(L);E=it(K),y=it(G),v=ae(K,E,1),A=ae(G,y,1)}else q(1);else{var O=Ze(l)+4,w=t[O-4]|t[O-3]<<8,x=O+w;if(x>i){f&&q(0);break}a&&c(p+w),r.set(t.subarray(O,x),p),e.b=p+=w,e.p=l=x*8,e.f=h;continue}if(l>b){f&&q(0);break}}a&&c(p+131072);for(var me=(1<>4;if(l+=_&15,l>b){f&&q(0);break}if(_||q(2),Y<256)r[p++]=Y;else if(Y==256){re=l,v=null;break}else{var N=Y-254;if(Y>264){var C=Y-257,j=Fe[C];N=se(t,l,(1<>4;te||q(3),l+=te&15;var G=br[ne];if(ne>3){var j=ze[ne];G+=ot(t,l)&(1<b){f&&q(0);break}a&&c(p+131072);var ge=p+N;if(p>8},Ue=function(t,e,r){r<<=e&7;var n=e/8|0;t[n]|=r,t[n+1]|=r>>8,t[n+2]|=r>>16},st=function(t,e){for(var r=[],n=0;np&&(p=o[n].s);var v=new ee(p+1),A=ut(r[h-1],v,0);if(A>e){var n=0,E=0,y=A-e,b=1<e)E+=b-(1<>=y;E>0;){var O=o[n].s;v[O]=0&&E;--n){var w=o[n].s;v[w]==e&&(--v[w],++E)}A=e}return{t:new B(v),l:A}},ut=function(t,e,r){return t.s==-1?Math.max(ut(t.l,e,r+1),ut(t.r,e,r+1)):e[t.s]=r},Pt=function(t){for(var e=t.length;e&&!t[--e];);for(var r=new ee(++e),n=0,i=t[0],o=1,s=function(f){r[n++]=f},a=1;a<=e;++a)if(t[a]==i&&a!=e)++o;else{if(!i&&o>2){for(;o>138;o-=138)s(32754);o>2&&(s(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(s(i),--o;o>6;o-=6)s(8304);o>2&&(s(o-3<<5|8208),o=0)}for(;o--;)s(i);o=1,i=t[a]}return{c:r.subarray(0,n),n:e}},Ie=function(t,e){for(var r=0,n=0;n>8,t[i+2]=t[i]^255,t[i+3]=t[i+1]^255;for(var o=0;o4&&!k[He[F-1]];--F);var V=c+5<<3,P=Ie(i,ye)+Ie(o,Me)+s,S=Ie(i,p)+Ie(o,E)+s+14+3*F+Ie(D,k)+2*D[16]+3*D[17]+7*D[18];if(f>=0&&V<=P&&V<=S)return Mt(e,h,t.subarray(f,f+c));var _,R,K,G;if(pe(e,h,1+(S15&&(pe(e,h,Y[g]>>5&127),h+=Y[g]>>12)}}else _=Or,R=ye,K=Sr,G=Me;for(var g=0;g255){var N=j>>18&31;Ue(e,h,_[N+257]),h+=R[N+257],N>7&&(pe(e,h,j>>23&31),h+=Fe[N]);var te=j&31;Ue(e,h,K[te]),h+=G[te],te>3&&(Ue(e,h,j>>5&8191),h+=ze[te])}else Ue(e,h,_[j]),h+=R[j]}return Ue(e,h,_[256]),h+R[256]},Tr=new Ke([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Ft=new B(0),Ur=function(t,e,r,n,i,o){var s=o.z||t.length,a=new B(n+s+5*(1+Math.ceil(s/7e3))+i),f=a.subarray(n,a.length-i),c=o.l,h=(o.r||0)&7;if(e){h&&(f[0]=o.r>>3);for(var l=Tr[e-1],p=l>>13,v=l&8191,A=(1<7e3||k>24576)&&(_>423||!c)){h=Rt(t,f,0,w,x,L,g,k,F,m-F,h),k=D=g=0,F=m;for(var R=0;R<286;++R)x[R]=0;for(var R=0;R<30;++R)L[R]=0}var K=2,G=0,me=v,Z=P-S&32767;if(_>2&&V==O(m-Z))for(var re=Math.min(p,_)-1,Y=Math.min(32767,m),N=Math.min(258,_);Z<=Y&&--me&&P!=S;){if(t[m+K]==t[m+K-Z]){for(var j=0;jK){if(K=j,G=Z,j>re)break;for(var te=Math.min(Z,j-2),ne=0,R=0;Rne&&(ne=z,S=ge)}}}P=S,S=E[P],Z+=P-S&32767}if(G){w[k++]=268435456|at[K]<<18|kt[G];var Q=at[K]&31,_e=kt[G]&31;g+=Fe[Q]+ze[_e],++x[257+Q],++L[_e],C=m+K,++D}else w[k++]=t[m],++x[t[m]]}}for(m=Math.max(m,C);m=s&&(f[h/8|0]=c,be=s),h=Mt(f,h+1,t.subarray(m,be))}o.i=s}return De(a,0,n+Ze(h)+i)},bn=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var r=e,n=9;--n;)r=(r&1&&-306674912)^r>>>1;t[e]=r}return t}(),On=function(){var t=-1;return{p:function(e){for(var r=t,n=0;n>>8;t=r},d:function(){return~t}}};var Ir=function(t,e,r,n,i){if(!i&&(i={l:1},e.dictionary)){var o=e.dictionary.subarray(-32768),s=new B(o.length+t.length);s.set(o),s.set(t,o.length),t=s,i.w=o.length}return Ur(t,e.level==null?6:e.level,e.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):20:12+e.mem,r,n,i)},zt=function(t,e){var r={};for(var n in t)r[n]=t[n];for(var n in e)r[n]=e[n];return r},gr=function(t,e,r){for(var n=t(),i=t.toString(),o=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),s=0;s>>0},St=function(t,e){return fe(t,e)+fe(t,e+4)*4294967296},X=function(t,e,r){for(;r;++e)t[e]=r,r>>>=8};function Rn(t,e,r){return r||(r=e,e={}),typeof r!="function"&&q(7),Fr(t,e,[Pn],function(n){return ct(Bt(n.data[0],n.data[1]))},0,r)}function Bt(t,e){return Ir(t,e||{},0,0)}function Tn(t,e,r){return r||(r=e,e={}),typeof r!="function"&&q(7),Fr(t,e,[kn],function(n){return ct(_t(n.data[0],Mr(n.data[1])))},1,r)}function _t(t,e){return Rr(t,{i:2},e&&e.out,e&&e.dictionary)}var zr=function(t,e,r,n){for(var i in t){var o=t[i],s=e+i,a=n;Array.isArray(o)&&(a=zt(n,o[1]),o=o[0]),o instanceof B?r[s]=[o,a]:(r[s+="/"]=[new B(0),a],zr(o,s,r,n))}},wr=typeof TextEncoder<"u"&&new TextEncoder,Tt=typeof TextDecoder<"u"&&new TextDecoder,Un=0;try{Tt.decode(Ft,{stream:!0}),Un=1}catch{}var In=function(t){for(var e="",r=0;;){var n=t[r++],i=(n>127)+(n>223)+(n>239);if(r+i>t.length)return{s:e,r:De(t,r-1)};i?i==3?(n=((n&15)<<18|(t[r++]&63)<<12|(t[r++]&63)<<6|t[r++]&63)-65536,e+=String.fromCharCode(55296|n>>10,56320|n&1023)):i&1?e+=String.fromCharCode((n&31)<<6|t[r++]&63):e+=String.fromCharCode((n&15)<<12|(t[r++]&63)<<6|t[r++]&63):e+=String.fromCharCode(n)}};function Er(t,e){if(e){for(var r=new B(t.length),n=0;n>1)),s=0,a=function(h){o[s++]=h},n=0;no.length){var f=new B(s+8+(i-n<<1));f.set(o),o=f}var c=t.charCodeAt(n);c<128||e?a(c):c<2048?(a(192|c>>6),a(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|t.charCodeAt(++n)&1023,a(240|c>>18),a(128|c>>12&63),a(128|c>>6&63),a(128|c&63)):(a(224|c>>12),a(128|c>>6&63),a(128|c&63))}return De(o,0,s)}function Mn(t,e){if(e){for(var r="",n=0;n65535&&q(9),e+=n+4}return e},Ar=function(t,e,r,n,i,o,s,a){var f=n.length,c=r.extra,h=a&&a.length,l=Ut(c);X(t,e,s!=null?33639248:67324752),e+=4,s!=null&&(t[e++]=20,t[e++]=r.os),t[e]=20,e+=2,t[e++]=r.flag<<1|(o<0&&8),t[e++]=i&&8,t[e++]=r.compression&255,t[e++]=r.compression>>8;var p=new Date(r.mtime==null?Date.now():r.mtime),v=p.getFullYear()-1980;if((v<0||v>119)&&q(10),X(t,e,v<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,o!=-1&&(X(t,e,r.crc),X(t,e+4,o<0?-o-2:o),X(t,e+8,r.size)),X(t,e+12,f),X(t,e+14,l),e+=16,s!=null&&(X(t,e,h),X(t,e+6,r.attrs),X(t,e+10,s),e+=14),t.set(n,e),e+=f,l)for(var A in c){var E=c[A],y=E.length;X(t,e,+A),X(t,e+2,y),t.set(E,e+4),e+=4+y}return h&&(t.set(a,e),e+=h),e},_n=function(t,e,r,n,i){X(t,e,101010256),X(t,e+8,r),X(t,e+10,r),X(t,e+12,n),X(t,e+16,i)};function Br(t,e,r){r||(r=e,e={}),typeof r!="function"&&q(7);var n={};zr(t,"",n,e);var i=Object.keys(n),o=i.length,s=0,a=0,f=o,c=new Array(o),h=[],l=function(){for(var y=0;y65535&&P(q(11,0,1),null),!V)P(null,O);else if(L<16e4)try{P(null,Bt(O,w))}catch(S){P(S,null)}else h.push(Rn(O,w,P))},E=0;E65558)return s(q(13,0,1),null),i;var f=ve(t,a+8);if(f){var c=f,h=fe(t,a+16),l=h==4294967295||c==65535;if(l){var p=fe(t,a-12);l=fe(t,p)==101075792,l&&(c=f=fe(t,p+32),h=fe(t,p+48))}for(var v=e&&e.filter,A=function(y){var b=zn(t,h,l),I=b[0],O=b[1],w=b[2],x=b[3],L=b[4],D=b[5],g=Fn(t,D);h=L;var m=function(C,F){C?(i(),s(C,null)):(F&&(o[x]=F),--f||s(null,o))};if(!v||v({name:x,size:O,originalSize:w,compression:I}))if(!I)m(null,De(t,g,g+O));else if(I==8){var k=t.subarray(g,g+O);if(w<524288||O>.8*w)try{m(null,_t(k,{out:new B(w)}))}catch(C){m(C,null)}else n.push(Tn(k,{size:w},m))}else m(q(14,"unknown compression type "+I,1),null);else m(null,null)},E=0;E{t.terminate();let e=new Ae(t.lufiFile,0);return U.fromPromise(new Promise((r,n)=>{e.onMessage(i=>{i.data.event==="UPLOAD_CANCELLED"&&(xe[e.lufiFile.keys.client].uploadStatus=0,r(e)),i.data.event==="OPERATION_FAILED"&&n(new ce("An error occured while trying to cancel an upload",{cause:i.data.error}))}).requestMessage({args:{lufiFile:e.lufiFile}})}),r=>J(r))},jr=(t,e={})=>{let r=async n=>{var i;for(let o of n){let s=((i=o.name.split("/"))==null?void 0:i.pop())||o.name,a=s.split(".").shift(),f=s.split(".").pop(),c=s;if(e[c]!==void 0){let h=1;do c=`${a}_(${h}).${f}`,h++;while(e[c]!==void 0)}gt.emit("ARCHIVE_ADDED_FILE",{name:c,size:o.size}),e[c]=await o.bytes()}};return U.fromPromise(r(t),n=>J(n)).andThen(()=>H(e))},Jr=(t,e)=>{let r=()=>new Promise((n,i)=>{Br(t,(o,s)=>{o&&i(o),n(s)})});return U.fromPromise(r(),n=>n).andThen(n=>{try{return H(new File([new Blob([n])],e,{type:"application/zip"}))}catch(i){return W(i)}}).orElse(n=>W(new ht(void 0,{cause:J(n)})))},Jn=t=>{let e=async()=>{let r=await t.bytes();return new Promise((n,i)=>{_r(r,(o,s)=>{o&&i(o),n(s)})})};return U.fromPromise(e(),r=>r).andThen(r=>{try{let n=[];for(let i in r)n.push(new File([new Blob([r[i]])],i));return H(n)}catch(n){return W(n)}}).orElse(r=>W(new lt(void 0,{cause:J(r)})))},Gr=(t,e)=>e?or(t).andThen(r=>{if(r.version.tag>"0.07.0"){let n=Dt()?1:0;return Ct(e,n).andThen(i=>H(Ee.fromDownloadUrl(t,i)))}else return H(Ee.fromDownloadUrl(t,e))}):H(Ee.fromDownloadUrl(t)),Gn=(t,e)=>Gr(t,e).andThen(r=>{let n=new Ae(r,1);return U.fromPromise(new Promise((i,o)=>{let s=[];return n.onMessage(a=>{Wr(i,o,n,a),a.data.event==="CHUNK_DOWNLOADED"&&(s.push(a.data.chunk.buffer),s.length>=50&&(n.downloadedFile=new File(n.downloadedFile?[n.downloadedFile.slice()].concat(s):s,r.name,{type:r.type}),s.length=0)),a.data.event==="DOWNLOAD_COMPLETE"&&(n.downloadedFile=new File(n.downloadedFile?[n.downloadedFile.slice()].concat(s):s,r.name,{type:r.type}),s.length=0,n.complete())}).requestMessage({args:{lufiFile:r}})}),i=>new pt(void 0,{cause:J(i)}))}),Wn=(t,e)=>Gr(t,e).andThen(r=>H(new Ae(r,2))).andThen(r=>U.fromPromise(new Promise((n,i)=>{r.onMessage(o=>{o.data.event==="INFOS_RETRIEVED"&&(r.complete(),n(r)),o.data.event==="OPERATION_FAILED"&&i(new ce("An error occured while trying to retrieve informations of the file",{cause:o.data.error}))}).requestMessage({args:{lufiFile:r.lufiFile}})}),n=>new vt(void 0,{cause:J(n)}))),Hn=t=>{try{return t.status=3,H(t.requestMessage({action:0,args:{lufiFile:t.lufiFile}}))}catch(e){return W(new mt(void 0,{cause:J(e)}))}},qn=(t,e)=>{let r=Ee.fromRemoveUrl(t,e),n=new Ae(r,3);return U.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="FILE_REMOVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(new ce("An error occured while trying to remove a file",{cause:s.data.error()}))}).requestMessage({args:{lufiFile:r}})}),i=>J(i))},Kn=t=>{try{return t.status=2,H(t.requestMessage({action:2,args:{lufiFile:t.lufiFile}}))}catch(e){return W(new dt(void 0,{cause:J(e)}))}},Zn=(t,e,r,n=Nn)=>{gt.emit("SLICE_STARTED",xe[t.lufiFile.keys.client]);let i=Math.ceil(e.size/n)||1,o=navigator.hardwareConcurrency||1;return xe[t.lufiFile.keys.client].totalChunks=i,(async()=>{for(let a=0;a{t.events.once("UPLOAD_STARTED",()=>{p(void 0)})}):a%o===0&&await new Promise(p=>{t.events.once("CHUNK_UPLOADED",()=>{p(void 0)})})}})(),H(void 0)},Nt=(t,e,r,n,i,o,s)=>dr(s).andThen(a=>o?Ct(o,s).andThen(f=>H({password:f,clientKey:a})):H({password:o,clientKey:a})).andThen(({password:a,clientKey:f})=>{xe[f]=new Ee(t.toString(),{delay:r,delAtFirstView:n,zipped:i,password:a,name:e.name.split("/").pop(),size:e.size,type:e.type,keys:{client:f,server:""}});let c=new Ae(xe[f],4);return xe[f].uploadStatus=4,Zn(c,e,s).andThen(()=>U.fromPromise(new Promise((h,l)=>{c.onMessage(p=>{switch(Wr(h,l,c,p),p.data.event){case"UPLOAD_COMPLETE":c.complete(),c.lufiFile.uploadStatus=1;break}})}),h=>J(h)))}),$n=(t,e,r=0,n=!1,i=!1,o="documents.zip",s="",a=1)=>{let f=[];return i?e.length===1&&e[0].type==="application/zip"?f.push(Nt(t,e[0],r,n,i,s,a)):f.push(jr(e).andThen(c=>Jr(c,o).andThen(h=>(gt.emit("ARCHIVE_CREATED",h),Nt(t,h,r,n,i,s,a))))):e.forEach(c=>{f.push(Nt(t,c,r,n,i,s,a))}),U.combine(f).orElse(c=>W(new yt(void 0,{cause:c})))},Wr=(t,e,r,n)=>{n.data.event==="SOCKET_OPENED"&&t(r),n.data.event==="OPERATION_FAILED"&&e(new ce("The job returned an error",{cause:n.data.error}))},Vn=()=>Object.values(xe).filter(t=>t.uploadStatus===4),Qn=t=>Object.keys(Vn()).indexOf(t);export{ke as CryptoAlgorithm,U as ResultAsync,le as err,W as errAsync,Dt as isSecureContext,jt as lufi,we as ok,H as okAsync}; diff --git a/themes/default/public/js/worker/main.js b/themes/default/public/js/worker/main.js index ffc1906..6cc715f 100644 --- a/themes/default/public/js/worker/main.js +++ b/themes/default/public/js/worker/main.js @@ -1 +1 @@ -var V=Object.create;var C=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var oe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ie=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of re(e))!ne.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=ee(e,o))||n.enumerable});return r};var se=(r,e,t)=>(t=r!=null?V(te(r)):{},ie(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var $=oe((De,M)=>{"use strict";var g=typeof Reflect=="object"?Reflect:null,U=g&&typeof g.apply=="function"?g.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},O;g&&typeof g.ownKeys=="function"?O=g.ownKeys:Object.getOwnPropertySymbols?O=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:O=function(e){return Object.getOwnPropertyNames(e)};function ue(r){console&&console.warn&&console.warn(r)}var R=Number.isNaN||function(e){return e!==e};function a(){a.init.call(this)}M.exports=a;M.exports.once=le;a.EventEmitter=a;a.prototype._events=void 0;a.prototype._eventsCount=0;a.prototype._maxListeners=void 0;var F=10;function A(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return F},set:function(r){if(typeof r!="number"||r<0||R(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");F=r}});a.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};a.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||R(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 T(r){return r._maxListeners===void 0?a.defaultMaxListeners:r._maxListeners}a.prototype.getMaxListeners=function(){return T(this)};a.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var f=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw f.context=i,f}var h=s[e];if(h===void 0)return!1;if(typeof h=="function")U(h,this,t);else for(var d=h.length,u=H(h,d),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=r,f.type=e,f.count=i.length,ue(f)}return r}a.prototype.addListener=function(e,t){return j(this,e,t,!1)};a.prototype.on=a.prototype.addListener;a.prototype.prependListener=function(e,t){return j(this,e,t,!0)};function ae(){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 N(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=ae.bind(n);return o.listener=t,n.wrapFn=o,o}a.prototype.once=function(e,t){return A(t),this.on(e,N(this,e,t)),this};a.prototype.prependOnceListener=function(e,t){return A(t),this.prependListener(e,N(this,e,t)),this};a.prototype.removeListener=function(e,t){var n,o,s,i,f;if(A(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(s=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){f=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():fe(n,s),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,f||t)}return this};a.prototype.off=a.prototype.removeListener;a.prototype.removeAllListeners=function(e){var t,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 s=Object.keys(n),i;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function W(r,e,t){var n=r._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?t?[o.listener||o]:[o]:t?ce(o):H(o,o.length)}a.prototype.listeners=function(e){return W(this,e,!0)};a.prototype.rawListeners=function(e){return W(this,e,!1)};a.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):J.call(r,e)};a.prototype.listenerCount=J;function J(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}a.prototype.eventNames=function(){return this._eventsCount>0?O(this._events):[]};function H(r,e){for(var t=new Array(e),n=0;n(u[u.ARCHIVE_ADD=0]="ARCHIVE_ADD",u[u.ARCHHIVE_COMPRESS=1]="ARCHHIVE_COMPRESS",u[u.CANCEL=2]="CANCEL",u[u.DOWNLOAD=3]="DOWNLOAD",u[u.INFOS=4]="INFOS",u[u.PAUSE=5]="PAUSE",u[u.PROVIDE_FILE=6]="PROVIDE_FILE",u[u.REMOVE=7]="REMOVE",u[u.RESUME=8]="RESUME",u[u.UPLOAD=9]="UPLOAD",u))(k||{});var pe={withStackTrace:!1},q=(r,e,t=pe)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function b(r,e,t,n){function o(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function f(u){try{d(n.next(u))}catch(L){i(L)}}function h(u){try{d(n.throw(u))}catch(L){i(L)}}function d(u){u.done?s(u.value):o(u.value).then(f,h)}d((n=n.apply(r,[])).next())})}function G(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(r){return this instanceof y?(this.v=r,this):new y(r)}function me(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,s=[];return o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o;function i(l){n[l]&&(o[l]=function(_){return new Promise(function(x,K){s.push([l,_,x,K])>1||f(l,_)})})}function f(l,_){try{h(n[l](_))}catch(x){L(s[0][3],x)}}function h(l){l.value instanceof y?Promise.resolve(l.value.v).then(d,u):L(s[0][2],l)}function d(l){f("next",l)}function u(l){f("throw",l)}function L(l,_){l(_),s.shift(),s.length&&f(s[0][0],s[0][1])}}function de(r){var e,t;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,s){e[o]=r[o]?function(i){return(t=!t)?{value:y(r[o](i)),done:o==="return"}:s?s(i):i}:s}}function ve(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof G=="function"?G(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(s){t[s]=r[s]&&function(i){return new Promise(function(f,h){i=r[s](i),o(f,h,i.done,i.value)})}}function o(s,i,f,h){Promise.resolve(h).then(function(d){s({value:d,done:f})},i)}}var v=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new m(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new m(o)).catch(o=>new p(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(b(this,void 0,void 0,function*(){try{return new m(yield e(...n))}catch(o){return new p(t?t(o):o)}}))}static combine(e){return Ee(e)}static combineWithAllErrors(e){return we(e)}map(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?new p(t.error):new m(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);let n=yield e(t.value);return n.isErr()?new p(n.error):new m(t.value)})))}andTee(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);try{yield e(t.value)}catch{}return new m(t.value)})))}mapErr(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isOk()?new m(t.value):new p(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new p(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new m(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return me(this,arguments,function*(){return yield y(yield y(yield*de(ve(yield y(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var P=r=>new v(Promise.resolve(new p(r))),xe=v.fromPromise,Me=v.fromSafePromise,ke=v.fromThrowable,z=r=>{let e=w([]);for(let t of r)if(t.isErr()){e=E(t.error);break}else e.map(n=>n.push(t.value));return e},Ee=r=>v.fromSafePromise(Promise.all(r)).andThen(z),Q=r=>{let e=w([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=E([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},we=r=>v.fromSafePromise(Promise.all(r)).andThen(Q),I;(function(r){function e(o,s){return(...i)=>{try{let f=o(...i);return w(f)}catch(f){return E(s?s(f):f)}}}r.fromThrowable=e;function t(o){return z(o)}r.combine=t;function n(o){return Q(o)}r.combineWithAllErrors=n})(I||(I={}));var w=r=>new m(r);function E(r){return new p(r)}var m=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return w(e(this.value))}mapErr(e){return w(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return w(this.value)}orElse(e){return w(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return v.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw q("Called `_unsafeUnwrapErr` on an Ok",this,e)}},p=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return E(this.error)}mapErr(e){return E(e(this.error))}andThrough(e){return E(this.error)}andTee(e){return E(this.error)}andThen(e){return E(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return P(this.error)}asyncAndThrough(e){return P(this.error)}asyncMap(e){return P(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield E(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw q("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Ie=I.fromThrowable;var Le=()=>typeof Deno<"u",D=r=>Le()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var S=new Y.default,c,X=!1;self.onmessage=r=>{ge(r),X||(X=!0,S.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var _e=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),Ve=(r,e)=>{_e(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},ge=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)c.postMessage(r.data);else{switch(t){case 2:c=new Worker(D("cancel"),{type:"module"}),c.postMessage(r.data);break;case 3:c=new Worker(D("download"),{type:"module"}),c.postMessage(r.data);break;case 4:c=new Worker(D("infos"),{type:"module"}),c.postMessage(r.data);break;case 7:c=c||new Worker(D("remove"),{type:"module"}),c.postMessage(r.data);break;case 9:c=c||new Worker(D("upload"),{type:"module"}),c.postMessage(r.data);break;default:console.error("Action not found")}c.onmessage=n=>{e&&e(n),self.postMessage(n.data)},c.onerror=n=>{console.error(`Error: ${n.message}`)}}},er=()=>{S.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),S.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},rr=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(k).includes(r.action);export{S as events,er as init,rr as isWorkerActionMessage,Ve as sendFileError,_e as updateFile}; +var te=Object.create;var R=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var ue=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ae=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of oe(e))!ie.call(r,o)&&o!==t&&R(r,o,{get:()=>e[o],enumerable:!(n=ne(e,o))||n.enumerable});return r};var fe=(r,e,t)=>(t=r!=null?te(se(r)):{},ae(e||!r||!r.__esModule?R(t,"default",{value:r,enumerable:!0}):t,r));var G=ue((Ae,M)=>{"use strict";var b=typeof Reflect=="object"?Reflect:null,U=b&&typeof b.apply=="function"?b.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;b&&typeof b.ownKeys=="function"?P=b.ownKeys:Object.getOwnPropertySymbols?P=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:P=function(e){return Object.getOwnPropertyNames(e)};function ce(r){console&&console.warn&&console.warn(r)}var T=Number.isNaN||function(e){return e!==e};function a(){a.init.call(this)}M.exports=a;M.exports.once=de;a.EventEmitter=a;a.prototype._events=void 0;a.prototype._eventsCount=0;a.prototype._maxListeners=void 0;var F=10;function x(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return F},set:function(r){if(typeof r!="number"||r<0||T(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");F=r}});a.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};a.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||T(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 j(r){return r._maxListeners===void 0?a.defaultMaxListeners:r._maxListeners}a.prototype.getMaxListeners=function(){return j(this)};a.prototype.emit=function(e){for(var t=[],n=1;n0&&(s=t[0]),s instanceof Error)throw s;var f=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw f.context=s,f}var h=i[e];if(h===void 0)return!1;if(typeof h=="function")U(h,this,t);else for(var m=h.length,u=B(h,m),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=r,f.type=e,f.count=s.length,ce(f)}return r}a.prototype.addListener=function(e,t){return N(this,e,t,!1)};a.prototype.on=a.prototype.addListener;a.prototype.prependListener=function(e,t){return N(this,e,t,!0)};function le(){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 W(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=le.bind(n);return o.listener=t,n.wrapFn=o,o}a.prototype.once=function(e,t){return x(t),this.on(e,W(this,e,t)),this};a.prototype.prependOnceListener=function(e,t){return x(t),this.prependListener(e,W(this,e,t)),this};a.prototype.removeListener=function(e,t){var n,o,i,s,f;if(x(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){f=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():he(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,f||t)}return this};a.prototype.off=a.prototype.removeListener;a.prototype.removeAllListeners=function(e){var t,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=0;o--)this.removeListener(e,t[o]);return this};function J(r,e,t){var n=r._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?t?[o.listener||o]:[o]:t?pe(o):B(o,o.length)}a.prototype.listeners=function(e){return J(this,e,!0)};a.prototype.rawListeners=function(e){return J(this,e,!1)};a.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):H.call(r,e)};a.prototype.listenerCount=H;function H(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}a.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function B(r,e){for(var t=new Array(e),n=0;n(u[u.ARCHIVE_ADD=0]="ARCHIVE_ADD",u[u.ARCHHIVE_COMPRESS=1]="ARCHHIVE_COMPRESS",u[u.CANCEL=2]="CANCEL",u[u.DOWNLOAD=3]="DOWNLOAD",u[u.INFOS=4]="INFOS",u[u.PAUSE=5]="PAUSE",u[u.PROVIDE_FILE=6]="PROVIDE_FILE",u[u.REMOVE=7]="REMOVE",u[u.RESUME=8]="RESUME",u[u.UPLOAD=9]="UPLOAD",u))(k||{});var ve={withStackTrace:!1},Q=(r,e,t=ve)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function g(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function f(u){try{m(n.next(u))}catch(_){s(_)}}function h(u){try{m(n.throw(u))}catch(_){s(_)}}function m(u){u.done?i(u.value):o(u.value).then(f,h)}m((n=n.apply(r,e||[])).next())})}function q(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(r){return this instanceof v?(this.v=r,this):new v(r)}function z(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),f("next"),f("throw"),f("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(c){return function(w){return Promise.resolve(w).then(c,_)}}function f(c,w){n[c]&&(o[c]=function(A){return new Promise(function(ee,re){i.push([c,A,ee,re])>1||h(c,A)})},w&&(o[c]=w(o[c])))}function h(c,w){try{m(n[c](w))}catch(A){C(i[0][3],A)}}function m(c){c.value instanceof v?Promise.resolve(c.value.v).then(u,_):C(i[0][2],c)}function u(c){h("next",c)}function _(c){h("throw",c)}function C(c,w){c(w),i.shift(),i.length&&h(i[0][0],i[0][1])}}function ye(r){var e,t;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]=r[o]?function(s){return(t=!t)?{value:v(r[o](s)),done:!1}:i?i(s):s}:i}}function Ee(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof q=="function"?q(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=r[i]&&function(s){return new Promise(function(f,h){s=r[i](s),o(f,h,s.done,s.value)})}}function o(i,s,f,h){Promise.resolve(h).then(function(m){i({value:m,done:f})},s)}}var y=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new d(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new d(o)).catch(o=>new p(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(g(this,void 0,void 0,function*(){try{return new d(yield e(...n))}catch(o){return new p(t?t(o):o)}}))}static combine(e){return we(e)}static combineWithAllErrors(e){return Le(e)}map(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isErr()?new p(t.error):new d(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);let n=yield e(t.value);return n.isErr()?new p(n.error):new d(t.value)})))}andTee(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);try{yield e(t.value)}catch{}return new d(t.value)})))}mapErr(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isOk()?new d(t.value):new p(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new p(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new d(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return z(this,arguments,function*(){return yield v(yield v(yield*ye(Ee(yield v(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}[Symbol.asyncIterator](){return z(this,arguments,function*(){let t=yield v(this._promise);return t.isErr()&&(yield yield v(O(t.error))),yield v(t.value)})}};var O=r=>new y(Promise.resolve(new p(r))),ke=y.fromPromise,Ie=y.fromSafePromise,Se=y.fromThrowable,Z=r=>{let e=L([]);for(let t of r)if(t.isErr()){e=E(t.error);break}else e.map(n=>n.push(t.value));return e},we=r=>y.fromSafePromise(Promise.all(r)).andThen(Z),X=r=>{let e=L([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=E([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Le=r=>y.fromSafePromise(Promise.all(r)).andThen(X),I;(function(r){function e(o,i){return(...s)=>{try{let f=o(...s);return L(f)}catch(f){return E(i?i(f):f)}}}r.fromThrowable=e;function t(o){return Z(o)}r.combine=t;function n(o){return X(o)}r.combineWithAllErrors=n})(I||(I={}));var L=r=>new d(r);function E(r){return new p(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return L(e(this.value))}mapErr(e){return L(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return L(this.value)}orElse(e){return L(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return y.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Q("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 E(this.error)}mapErr(e){return E(e(this.error))}andThrough(e){return E(this.error)}andTee(e){return E(this.error)}andThen(e){return E(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,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield E(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Q("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Ce=I.fromThrowable;var be=()=>typeof Deno<"u";var D=r=>be()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var S=new V.default,l,K=!1;self.onmessage=r=>{De(r),K||(K=!0,S.once("OPERATION_FAILED",()=>{l&&l.terminate()}))};var ge=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),rr=(r,e)=>{ge(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},De=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)l.postMessage(r.data,r.data);else{switch(t){case 2:l=new Worker(D("cancel"),{type:"module"}),l.postMessage(r.data,r.data);break;case 3:l=new Worker(D("download"),{type:"module"}),l.postMessage(r.data,r.data);break;case 4:l=new Worker(D("infos"),{type:"module"}),l.postMessage(r.data,r.data);break;case 7:l=l||new Worker(D("remove"),{type:"module"}),l.postMessage(r.data,r.data);break;case 9:l=l||new Worker(D("upload"),{type:"module"}),l.postMessage(r.data,r.data);break;default:console.error("Action not found")}l.onmessage=n=>{e&&e(n),self.postMessage(n.data,n.data)},l.onerror=n=>{console.error(`Error: ${n.message}`)}}},tr=()=>{S.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),S.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},nr=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(k).includes(r.action);export{S as events,tr as init,nr as isWorkerActionMessage,rr as sendFileError,ge as updateFile}; diff --git a/themes/default/public/js/worker/upload.js b/themes/default/public/js/worker/upload.js index 94c4232..bb1cc07 100644 --- a/themes/default/public/js/worker/upload.js +++ b/themes/default/public/js/worker/upload.js @@ -1 +1 @@ -var Ur=Object.create;var ht=Object.defineProperty;var Mr=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var Fr=Object.getPrototypeOf,Br=Object.prototype.hasOwnProperty;var Nt=e=>{throw TypeError(e)};var jr=(e,t,r)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Wr=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var pt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var zr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Nr(t))!Br.call(e,i)&&i!==r&&ht(e,i,{get:()=>t[i],enumerable:!(n=Mr(t,i))||n.enumerable});return e};var be=(e,t,r)=>(r=e!=null?Ur(Fr(e)):{},zr(t||!e||!e.__esModule?ht(r,"default",{value:e,enumerable:!0}):r,e));var E=(e,t,r)=>jr(e,typeof t!="symbol"?t+"":t,r),dt=(e,t,r)=>t.has(e)||Nt("Cannot "+r);var p=(e,t,r)=>(dt(e,t,"read from private field"),r?r.call(e):t.get(e)),x=(e,t,r)=>t.has(e)?Nt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),w=(e,t,r,n)=>(dt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),D=(e,t,r)=>(dt(e,t,"access private method"),r);var Ge=(e,t,r,n)=>({set _(i){w(e,t,i,r)},get _(){return p(e,t,n)}});var Ve=pt((ti,vt)=>{"use strict";var se=typeof Reflect=="object"?Reflect:null,Jt=se&&typeof se.apply=="function"?se.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Ke;se&&typeof se.ownKeys=="function"?Ke=se.ownKeys:Object.getOwnPropertySymbols?Ke=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Ke=function(t){return Object.getOwnPropertyNames(t)};function Xr(e){console&&console.warn&&console.warn(e)}var $t=Number.isNaN||function(t){return t!==t};function g(){g.init.call(this)}vt.exports=g;vt.exports.once=Zr;g.EventEmitter=g;g.prototype._events=void 0;g.prototype._eventsCount=0;g.prototype._maxListeners=void 0;var Ht=10;function Xe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return Ht},set:function(e){if(typeof e!="number"||e<0||$t(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ht=e}});g.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};g.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||$t(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function qt(e){return e._maxListeners===void 0?g.defaultMaxListeners:e._maxListeners}g.prototype.getMaxListeners=function(){return qt(this)};g.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=o[t];if(u===void 0)return!1;if(typeof u=="function")Jt(u,this,r);else for(var f=u.length,l=Qt(u,f),n=0;n0&&s.length>i&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,Xr(c)}return e}g.prototype.addListener=function(t,r){return Gt(this,t,r,!1)};g.prototype.on=g.prototype.addListener;g.prototype.prependListener=function(t,r){return Gt(this,t,r,!0)};function Vr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Kt(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Vr.bind(n);return i.listener=r,n.wrapFn=i,i}g.prototype.once=function(t,r){return Xe(r),this.on(t,Kt(this,t,r)),this};g.prototype.prependOnceListener=function(t,r){return Xe(r),this.prependListener(t,Kt(this,t,r)),this};g.prototype.removeListener=function(t,r){var n,i,o,s,c;if(Xe(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Qr(n,o),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};g.prototype.off=g.prototype.removeListener;g.prototype.removeAllListeners=function(t){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(t,r[i]);return this};function Xt(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Yr(i):Qt(i,i.length)}g.prototype.listeners=function(t){return Xt(this,t,!0)};g.prototype.rawListeners=function(t){return Xt(this,t,!1)};g.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Vt.call(e,t)};g.prototype.listenerCount=Vt;function Vt(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}g.prototype.eventNames=function(){return this._eventsCount>0?Ke(this._events):[]};function Qt(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,i,o=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),i=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],i[t]=4>=e||4>t?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return nr(this,e,0)},decrypt:function(e){return nr(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],i,o,s,c=[],u=[],f,l,h,m;for(i=0;256>i;i++)u[(c[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[o]=h,n[h]=o,l=c[i=c[f=c[o]]],m=16843009*l^65537*i^257*f^16843008*o,l=257*c[h]^16843008*h,i=0;4>i;i++)e[i][o]=l=l<<24^l>>>8,t[i][h]=m=m<<24^m>>>8;for(i=0;5>i;i++)e[i]=e[i].slice(0),t[i]=t[i].slice(0)}};function nr(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],i=t[0]^n[0],o=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,l=n.length/4-2,h,m=4,d=[0,0,0,0];c=e.w[r],e=c[0];var O=c[1],N=c[2],z=c[3],Q=c[4];for(h=0;h>>24]^O[o>>16&255]^N[s>>8&255]^z[t&255]^n[m],u=e[o>>>24]^O[s>>16&255]^N[t>>8&255]^z[i&255]^n[m+1],f=e[s>>>24]^O[t>>16&255]^N[i>>8&255]^z[o&255]^n[m+2],t=e[t>>>24]^O[i>>16&255]^N[o>>8&255]^z[s&255]^n[m+3],m+=4,i=c,o=u,s=f;for(h=0;4>h;h++)d[r?3&-h:h]=Q[i>>>24]<<24^Q[o>>16&255]<<16^Q[s>>8&255]<<8^Q[t&255]^n[m++],c=i,i=o,o=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[i]<<32-t;return i=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(i),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>i)>>>26),6>i?(s=e[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,i=0,o=a.codec.base64.S,s=0,c;for(t&&(o=o.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>i),s=c<<32-i):(i+=6,s^=c<<32-i)}return i&56&&r.push(a.bitArray.partial(i&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,i=this.g,o=this.b,s=i[0],c=i[1],u=i[2],f=i[3],l=i[4],h=i[5],m=i[6],d=i[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(m^l&(h^m))+o[t],d=m,m=h,h=l,l=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;i[0]=i[0]+s|0,i[1]=i[1]+c|0,i[2]=i[2]+u|0,i[3]=i[3]+f|0,i[4]=i[4]+l|0,i[5]=i[5]+h|0,i[6]=i[6]+m|0,i[7]=i[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(o=!0,i=2;i*i<=n;i++)if(n%i===0){o=!1;break}o&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,i=this.b,o=n[0],s=n[1],c=n[2],u=n[3],f=n[4],l=n[5],h=n[6],m=n[7],d=n[8],O=n[9],N=n[10],z=n[11],Q=n[12],Je=n[13],It=n[14],He=n[15],R;if(typeof Uint32Array<"u"){R=Array(160);for(var _=0;32>_;_++)R[_]=e[_]}else R=e;var _=o,I=s,ye=c,ne=u,ve=f,ie=l,ct=h,ge=m,J=d,U=O,$e=N,Ee=z,qe=Q,we=Je,ut=It,Ae=He;for(e=0;80>e;e++){if(16>e)t=R[2*e],r=R[2*e+1];else{r=R[2*(e-15)];var A=R[2*(e-15)+1];t=(A<<31|r>>>1)^(A<<24|r>>>8)^r>>>7;var H=(r<<31|A>>>1)^(r<<24|A>>>8)^(r<<25|A>>>7);r=R[2*(e-2)];var q=R[2*(e-2)+1],A=(q<<13|r>>>19)^(r<<3|q>>>29)^r>>>6,q=(r<<13|q>>>19)^(q<<3|r>>>29)^(r<<26|q>>>6),ft=R[2*(e-7)],lt=R[2*(e-16)],Le=R[2*(e-16)+1];r=H+R[2*(e-7)+1],t=t+ft+(r>>>0>>0?1:0),r+=q,t+=A+(r>>>0>>0?1:0),r+=Le,t+=lt+(r>>>0>>0?1:0)}R[2*e]=t|=0,R[2*e+1]=r|=0;var ft=J&$e^~J&qe,Ut=U&Ee^~U&we,q=_&ye^_&ve^ye&ve,kr=I&ne^I&ie^ne&ie,lt=(I<<4|_>>>28)^(_<<30|I>>>2)^(_<<25|I>>>7),Le=(_<<4|I>>>28)^(I<<30|_>>>2)^(I<<25|_>>>7),Ir=i[2*e],Mt=i[2*e+1],A=Ae+((J<<18|U>>>14)^(J<<14|U>>>18)^(U<<23|J>>>9)),H=ut+((U<<18|J>>>14)^(U<<14|J>>>18)^(J<<23|U>>>9))+(A>>>0>>0?1:0),A=A+Ut,H=H+(ft+(A>>>0>>0?1:0)),A=A+Mt,H=H+(Ir+(A>>>0>>0?1:0)),A=A+r|0,H=H+(t+(A>>>0>>0?1:0));r=Le+kr,t=lt+q+(r>>>0>>0?1:0),ut=qe,Ae=we,qe=$e,we=Ee,$e=J,Ee=U,U=ge+A|0,J=ct+H+(U>>>0>>0?1:0)|0,ct=ve,ge=ie,ve=ye,ie=ne,ye=_,ne=I,I=A+r|0,_=H+t+(I>>>0>>0?1:0)|0}s=n[1]=s+I|0,n[0]=o+_+(s>>>0>>0?1:0)|0,u=n[3]=u+ne|0,n[2]=c+ye+(u>>>0>>0?1:0)|0,l=n[5]=l+ie|0,n[4]=f+ve+(l>>>0>>0?1:0)|0,m=n[7]=m+ge|0,n[6]=h+ct+(m>>>0>>0?1:0)|0,O=n[9]=O+U|0,n[8]=d+J+(O>>>0>>0?1:0)|0,z=n[11]=z+Ee|0,n[10]=N+$e+(z>>>0>>0?1:0)|0,Je=n[13]=Je+we|0,n[12]=Q+qe+(Je>>>0>>0?1:0)|0,He=n[15]=He+Ae|0,n[14]=It+ut+(He>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&f>>>8*o;o++);return o<15-u&&(o=15-u),r=c.clamp(r,8*(15-o)),t=a.mode.ccm.U(e,t,r,n,i,o),s=a.mode.ccm.V(e,s,r,t,i,o),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,i){i=i||64,n=n||[];var o=a.bitArray,s=o.bitLength(r)/8,f=o.bitLength(t),c=o.clamp(t,f-i),u=o.bitSlice(t,f-i),f=(f-i)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=o.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,i,t),e=a.mode.ccm.U(e,c.data,r,n,i,t),!o.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,i,o){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|o-1)],n=c.concat(n,r),n[3]|=i,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;ti||16l&&(a.mode.ccm.da(s/u),l+=h),r[3]++,i=e.encrypt(r),t[s]^=i[0],t[s+1]^=i[1],t[s+2]^=i[2],t[s+3]^=i[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,i=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>i&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),i=i||a.misc.hmac,e=new i(e);var o,s,c,u,f=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(i=o=e.encrypt(l.concat(t,[u])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=o),this.N++,this.b=a.hash.sha256.hash(this.b.concat(i)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,o,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,o,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&ir("seeded",Math.max(this.u,this.i)),ir("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:Ce(this,this.la),mouseCollector:Ce(this,this.na),keyboardCollector:Ce(this,this.ja),accelerometerCollector:Ce(this,this.ca),touchCollector:Ce(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,i=this.J[e],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===t&&o.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function Ce(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(et=typeof ce<"u"&&ce.exports){try{tt=Wr("crypto")}catch{tt=null}et=Ze=tt}if(et&&Ze.randomBytes)Te=Ze.randomBytes(128),Te=new Uint32Array(new Uint8Array(Te).buffer),a.random.addEntropy(Te,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Re=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Re);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Re);else break e;a.random.addEntropy(Re,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 Te,Ze,Re,et,tt;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var i=a.json,o=i.j({iv:a.random.randomWords(4,0)},i.defaults),s;if(i.j(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=a.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=a.codec.base64.toBits(o.iv)),!a.mode[o.mode]||!a.cipher[o.cipher]||typeof e=="string"&&100>=o.iter||o.ts!==64&&o.ts!==96&&o.ts!==128||o.ks!==128&&o.ks!==192&&o.ks!==256||2>o.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{"use strict";var On=Object.prototype.hasOwnProperty,S="~";function Pe(){}Object.create&&(Pe.prototype=Object.create(null),new Pe().__proto__||(S=!1));function xn(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Ar(e,t,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new xn(r,n||e,i),s=S?S+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],o]:e._events[s].push(o):(e._events[s]=o,e._eventsCount++),e}function rt(e,t){--e._eventsCount===0?e._events=new Pe:delete e._events[t]}function T(){this._events=new Pe,this._eventsCount=0}T.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)On.call(r,n)&&t.push(S?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};T.prototype.listeners=function(t){var r=S?S+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:i}};function oe(e,t,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(l){try{f(n.next(l))}catch(h){s(h)}}function u(l){try{f(n.throw(l))}catch(h){s(h)}}function f(l){l.done?o(l.value):i(l.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ft(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function G(e){return this instanceof G?(this.v=e,this):new G(e)}function Bt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(d){return function(O){return Promise.resolve(O).then(d,h)}}function c(d,O){n[d]&&(i[d]=function(N){return new Promise(function(z,Q){o.push([d,N,z,Q])>1||u(d,N)})},O&&(i[d]=O(i[d])))}function u(d,O){try{f(n[d](O))}catch(N){m(o[0][3],N)}}function f(d){d.value instanceof G?Promise.resolve(d.value.v).then(l,h):m(o[0][2],d)}function l(d){u("next",d)}function h(d){u("throw",d)}function m(d,O){d(O),o.shift(),o.length&&u(o[0][0],o[0][1])}}function Hr(e){var t,r;return t={},n("next"),n("throw",function(i){throw i}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(i,o){t[i]=e[i]?function(s){return(r=!r)?{value:G(e[i](s)),done:!1}:o?o(s):s}:o}}function $r(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ft=="function"?Ft(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=e[o]&&function(s){return new Promise(function(c,u){s=e[o](s),i(c,u,s.done,s.value)})}}function i(o,s,c,u){Promise.resolve(u).then(function(f){o({value:f,done:c})},s)}}var b=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new F(n));return new e(r)}static fromPromise(t,r){let n=t.then(i=>new F(i)).catch(i=>new B(r(i)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(oe(this,void 0,void 0,function*(){try{return new F(yield t(...n))}catch(i){return new B(r?r(i):i)}}))}static combine(t){return qr(t)}static combineWithAllErrors(t){return Gr(t)}map(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isErr()?new B(r.error):new F(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);let n=yield t(r.value);return n.isErr()?new B(n.error):new F(r.value)})))}andTee(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);try{yield t(r.value)}catch{}return new F(r.value)})))}mapErr(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isOk()?new F(r.value):new B(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new B(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new F(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Bt(this,arguments,function*(){return yield G(yield G(yield*Hr($r(yield G(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Bt(this,arguments,function*(){let r=yield G(this._promise);return r.isErr()&&(yield yield G(L(r.error))),yield G(r.value)})}},C=e=>new b(Promise.resolve(new F(e))),L=e=>new b(Promise.resolve(new B(e))),Cn=b.fromPromise,Tn=b.fromSafePromise,Rn=b.fromThrowable,Wt=e=>{let t=re([]);for(let r of e)if(r.isErr()){t=Y(r.error);break}else t.map(n=>n.push(r.value));return t},qr=e=>b.fromSafePromise(Promise.all(e)).andThen(Wt),zt=e=>{let t=re([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=Y([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Gr=e=>b.fromSafePromise(Promise.all(e)).andThen(zt),mt;(function(e){function t(i,o){return(...s)=>{try{let c=i(...s);return re(c)}catch(c){return Y(o?o(c):c)}}}e.fromThrowable=t;function r(i){return Wt(i)}e.combine=r;function n(i){return zt(i)}e.combineWithAllErrors=n})(mt||(mt={}));var re=e=>new F(e);function Y(e){return new B(e)}var F=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return re(t(this.value))}mapErr(t){return re(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return re(this.value)}orElse(t){return re(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return b.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw jt("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},B=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return Y(this.error)}mapErr(t){return Y(t(this.error))}andThrough(t){return Y(this.error)}andTee(t){return Y(this.error)}andThen(t){return Y(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return L(this.error)}asyncAndThrough(t){return L(this.error)}asyncMap(t){return L(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield Y(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw jt("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Pn=mt.fromThrowable;var P=class extends Error{constructor(r,n={}){let{cause:i,context:o}=n;super(r,{cause:i});E(this,"context");this.name=this.constructor.name,this.context=o}};var K=class extends P{};var Oe=class extends K{constructor(){super(...arguments);E(this,"message","An error occured while trying to connect to WebSocket")}};var $=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Kr=()=>typeof Deno<"u";var yt=e=>Kr()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e!=="encrypt"?`worker/${e}`:e}.js`));var er=be(Ve());var v=new er.default,Z=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e),gt=(e,t)=>{Z(e,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:t})},tr=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var ae=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),i,o,s,c,u=0,f=0;for(;u>4,n[u++]=(o&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var rr=new ae("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function xe(e){return rr.Encode(e)}function De(e){return rr.Decode(e)}var tn=new ae("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function Et(e){return tn.Decode(e)}var Lt=be(sr());var X=class extends P{};var ue=class extends X{constructor(){super(...arguments);E(this,"message","Unable to decrypt the provided data")}};var fe=class extends X{constructor(){super(...arguments);E(this,"message","Unable to encrypt the provided data")}};var ar=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return C(De(Lt.default.decrypt(e,r)))}catch(r){return L(new ue(void 0,{cause:$(r)}))}},cr=(e,t)=>{try{let r=Lt.default.encrypt(e,xe(t));return C({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return L(new fe(void 0,{cause:$(r)}))}};var ur=(e,t)=>lr(e).andThen(r=>b.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,t.data),n=>new ue(void 0,{cause:$(n)}))),fr=(e,t)=>lr(e).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return b.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,t),i=>new fe(void 0,{cause:$(i)})).andThen(i=>C({algo:1,data:i,iv:n}))}),lr=e=>b.fromPromise(crypto.subtle.importKey("raw",Et(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new X("Unable to import cryptography key",{cause:$(t)}));var hr=(e,t)=>t.algo===void 0||t.algo===0?ar(e,t):ur(e,t),pr=(e,t,r)=>r===0?cr(e,t):fr(e,t);var M={},mr=5,an=e=>(v.emit("UPLOAD_CANCELLED",e.success),C(void 0)),cn=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let i=JSON.parse(n);if(vn(i)){let o=r.shift();if(o){let s=JSON.parse(o);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv)),s.data=De(s.data)),hr(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return i.part===0?(Z(t,{chunksReady:t.chunksReady+1,delAtFirstView:i.del_at_first_view,delay:i.delay,name:i.name,size:i.size,totalChunks:i.total,type:i.type,zipped:i.zipped}),v.emit("DOWNLOAD_STARTED")):Z(t,{chunksReady:t.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,i.part),t.chunksReady===i.total?hn(t).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),C(void 0))):C(void 0)})}else{let s=new K("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),L(s)}}else{let o=new K(i.msg);return v.emit("OPERATION_FAILED",o),L(o)}}else{let i=new K("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",i),L(i)}},un=(e,t)=>{if(e.success)return e.j===0&&(Z(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),v.emit("UPLOAD_STARTED")),Z(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),v.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Z(t,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),C(void 0);{let r=new K(e.msg);return v.emit("OPERATION_FAILED",r),L(r)}},fn=(e,t)=>{let r=yn(e.data),n;if(r)if(!r.action&&r.msg){let i=new K(r.msg);return v.emit("OPERATION_FAILED",i),L(i)}else"delay"in r?n=un(r,t):n=an(r);else n=cn(e.data,t);return n},ln=e=>M!==void 0&&M[e]!==void 0&&M[e].readyState===WebSocket.CONNECTING,bt=e=>M!==void 0&&M[e]!==void 0&&M[e].readyState===WebSocket.OPEN;var hn=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},xt(dn(e),e,JSON.stringify(t))},Ot=(e,t,r)=>(r.data=xe(r.data),xt(mn(e),e,`${JSON.stringify(t)}XXMOJOXX${JSON.stringify(r)}`)),xt=(e,t,r)=>bt(e)?(M[e].send(r),C(void 0)):yr(e).andThen(()=>(M[e].onmessage=n=>fn(n,t),xt(e,t,r))),yr=(e,t=0)=>(!bt(e)&&!ln(e)&&(M[e]=new WebSocket(e),v.once("SOCKET_OPERATION_TERMINATED",()=>{M[e].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),M[e].onopen=()=>{v.emit("SOCKET_OPENED")},M[e].onclose=()=>{},M[e].onerror=()=>++t<=mr?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${mr}`),yr(e,t)):(v.emit("SOCKET_ONERROR"),L(new Oe(`Unable to connect to WebSocket ${e}.`)))),pn(e).andThen(()=>C(e)).orElse(r=>L(r))),pn=e=>b.fromPromise(new Promise((t,r)=>{bt(e)?t(void 0):(v.once("SOCKET_OPENED",()=>{t(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new Oe)}))}),t=>$(t));var vr=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},dn=e=>vr(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),mn=e=>vr(new URL(e.serverUrl),"upload").toString(),yn=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},vn=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Er=be(Ve());var wn=be(Ve());var Ln={},Os=new Er.default;var bn=()=>Object.values(Ln).filter(e=>e.uploadStatus===4),wr=e=>Object.keys(bn()).indexOf(e);var _t=be(Lr(),1);var Se=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ct=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},br=e=>globalThis.DOMException===void 0?new Ct(e):new DOMException(e),Or=e=>{let t=e.reason===void 0?br("This operation was aborted."):e.reason;return t instanceof Error?t:br(t)};function Tt(e,t){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=t,s,u=new Promise((f,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:m}=t;m.aborted&&l(Or(m));let d=()=>{l(Or(m))};m.addEventListener("abort",d,{once:!0}),e.finally(()=>{m.removeEventListener("abort",d)})}if(r===Number.POSITIVE_INFINITY){e.then(f,l);return}let h=new Se;s=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof e.cancel=="function"&&e.cancel(),i===!1?f():i instanceof Error?l(i):(h.message=i!=null?i:`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await e)}catch(m){l(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},u}function 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 V,ke=class{constructor(){x(this,V,[])}enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,run:t};if(this.size&&p(this,V)[this.size-1].priority>=r.priority){p(this,V).push(n);return}let i=Rt(p(this,V),n,(o,s)=>s.priority-o.priority);p(this,V).splice(i,0,n)}dequeue(){let t=p(this,V).shift();return t==null?void 0:t.run}filter(t){return p(this,V).filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return p(this,V).length}};V=new WeakMap;var le,he,te,Ue,pe,Me,j,de,k,Ne,W,me,ee,Fe,y,xr,Dr,_r,Cr,Tr,nt,Pt,St,it,Rr,ot,Ie=class extends _t.default{constructor(r){var n,i,o,s;super();x(this,y);x(this,le);x(this,he);x(this,te,0);x(this,Ue);x(this,pe);x(this,Me,0);x(this,j);x(this,de);x(this,k);x(this,Ne);x(this,W,0);x(this,me);x(this,ee);x(this,Fe);E(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:ke,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(i=(n=r.intervalCap)==null?void 0:n.toString())!=null?i:""}\` (${typeof r.intervalCap})`);if(r.interval===void 0||!(Number.isFinite(r.interval)&&r.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(s=(o=r.interval)==null?void 0:o.toString())!=null?s:""}\` (${typeof r.interval})`);w(this,le,r.carryoverConcurrencyCount),w(this,he,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),w(this,Ue,r.intervalCap),w(this,pe,r.interval),w(this,k,new r.queueClass),w(this,Ne,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,w(this,Fe,r.throwOnTimeout===!0),w(this,ee,r.autoStart===!1)}get concurrency(){return p(this,me)}set concurrency(r){if(!(typeof r=="number"&&r>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${r}\` (${typeof r})`);w(this,me,r),D(this,y,it).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,Fe),...n},new Promise((i,o)=>{p(this,k).enqueue(async()=>{var s;Ge(this,W)._++,Ge(this,te)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=Tt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,D(this,y,Rr).call(this,n.signal)]));let u=await c;i(u),this.emit("completed",u)}catch(c){if(c instanceof Se&&!n.throwOnTimeout){i();return}o(c),this.emit("error",c)}finally{D(this,y,_r).call(this)}},n),this.emit("add"),D(this,y,nt).call(this)})}async addAll(r,n){return Promise.all(r.map(async i=>this.add(i,n)))}start(){return p(this,ee)?(w(this,ee,!1),D(this,y,it).call(this),this):this}pause(){w(this,ee,!0)}clear(){w(this,k,new(p(this,Ne)))}async onEmpty(){p(this,k).size!==0&&await D(this,y,ot).call(this,"empty")}async onSizeLessThan(r){p(this,k).sizep(this,k).size{D(this,y,Cr).call(this)},n)),!0}return!1},nt=function(){if(p(this,k).size===0)return p(this,j)&&clearInterval(p(this,j)),w(this,j,void 0),this.emit("empty"),p(this,W)===0&&this.emit("idle"),!1;if(!p(this,ee)){let r=!p(this,y,Tr);if(p(this,y,xr)&&p(this,y,Dr)){let n=p(this,k).dequeue();return n?(this.emit("active"),n(),r&&D(this,y,Pt).call(this),!0):!1}}return!1},Pt=function(){p(this,he)||p(this,j)!==void 0||(w(this,j,setInterval(()=>{D(this,y,St).call(this)},p(this,pe))),w(this,Me,Date.now()+p(this,pe)))},St=function(){p(this,te)===0&&p(this,W)===0&&p(this,j)&&(clearInterval(p(this,j)),w(this,j,void 0)),w(this,te,p(this,le)?p(this,W):0),D(this,y,it).call(this)},it=function(){for(;D(this,y,nt).call(this););},Rr=async function(r){return new Promise((n,i)=>{r.addEventListener("abort",()=>{i(r.reason)},{once:!0})})},ot=async function(r,n){return new Promise(i=>{let o=()=>{n&&!n()||(this.off(r,o),i())};this.on(r,o)})};var st=class extends P{};var Be=class extends st{constructor(){super(...arguments);E(this,"message","Parameter cannot be undefined")}};var Pr=!1,kt=navigator.hardwareConcurrency||1,We=new Ie({concurrency:kt,autoStart:!1}),ze=0,at=!1,je,Sr=new Worker(yt("encrypt"),{type:"module"});self.onmessage=e=>{if(Pr||(tr(),Pr=!0,je=e.data.args.lufiFile,v.once("UPLOAD_STARTED",()=>{self.postMessage({event:"UPLOAD_STARTED"})}),v.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),ze--,!at&&ze{self.postMessage({event:"UPLOAD_COMPLETE"})}),v.on("FILE_UPDATED",Z)),e.data.args.chunk)return e.data.args.lufiFile=je,Dn(e.data,wr(je.keys.client)).mapErr(t=>{gt(je,t)});e.data.action===0?(at=!0,We.pause(),self.postMessage({event:"JOB_PAUSED"})):e.data.action===2?(at=!1,We.start(),self.postMessage({event:"JOB_RESUMED"})):gt(je,new Be)};var Dn=(e,t)=>{let{lufiFile:r,algo:n}=e.args;if(e.args.chunk&&n)e.args.chunk.index===0?pr(r.keys.client,e.args.chunk.buffer,n).map(i=>{Ot(r,{total:r.totalChunks,part:0,size:r.size,name:r.name,type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:null,i:t,file_pwd:r.password},i),ze++}):We.add(()=>{if(e.args.chunk){let i=()=>(ze++,new Promise(o=>{Sr.onmessage=s=>{o(Ot(r,{total:r.totalChunks,part:s.data.chunkIndex,size:r.size,name:r.name,type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:r.keys.server,i:t,file_pwd:r.password},s.data.encryptedData))}}));return Sr.postMessage(e,[e.args.chunk.buffer]),(at||ze===kt)&&We.pause(),i()}});else return L(new Be("algo must be defined"));return C(void 0)}; +var Nr=Object.create;var ht=Object.defineProperty;var Fr=Object.getOwnPropertyDescriptor;var Br=Object.getOwnPropertyNames;var Wr=Object.getPrototypeOf,jr=Object.prototype.hasOwnProperty;var Nt=e=>{throw TypeError(e)};var zr=(e,t,r)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Jr=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var pt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Hr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Br(t))!jr.call(e,i)&&i!==r&&ht(e,i,{get:()=>t[i],enumerable:!(n=Fr(t,i))||n.enumerable});return e};var be=(e,t,r)=>(r=e!=null?Nr(Wr(e)):{},Hr(t||!e||!e.__esModule?ht(r,"default",{value:e,enumerable:!0}):r,e));var w=(e,t,r)=>zr(e,typeof t!="symbol"?t+"":t,r),dt=(e,t,r)=>t.has(e)||Nt("Cannot "+r);var p=(e,t,r)=>(dt(e,t,"read from private field"),r?r.call(e):t.get(e)),x=(e,t,r)=>t.has(e)?Nt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),E=(e,t,r,n)=>(dt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),D=(e,t,r)=>(dt(e,t,"access private method"),r);var Ge=(e,t,r,n)=>({set _(i){E(e,t,i,r)},get _(){return p(e,t,n)}});var Ve=pt((ni,vt)=>{"use strict";var se=typeof Reflect=="object"?Reflect:null,Jt=se&&typeof se.apply=="function"?se.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Ke;se&&typeof se.ownKeys=="function"?Ke=se.ownKeys:Object.getOwnPropertySymbols?Ke=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Ke=function(t){return Object.getOwnPropertyNames(t)};function Qr(e){console&&console.warn&&console.warn(e)}var $t=Number.isNaN||function(t){return t!==t};function g(){g.init.call(this)}vt.exports=g;vt.exports.once=tn;g.EventEmitter=g;g.prototype._events=void 0;g.prototype._eventsCount=0;g.prototype._maxListeners=void 0;var Ht=10;function Xe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return Ht},set:function(e){if(typeof e!="number"||e<0||$t(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ht=e}});g.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};g.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||$t(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function qt(e){return e._maxListeners===void 0?g.defaultMaxListeners:e._maxListeners}g.prototype.getMaxListeners=function(){return qt(this)};g.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=o[t];if(u===void 0)return!1;if(typeof u=="function")Jt(u,this,r);else for(var f=u.length,l=Qt(u,f),n=0;n0&&s.length>i&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,Qr(c)}return e}g.prototype.addListener=function(t,r){return Gt(this,t,r,!1)};g.prototype.on=g.prototype.addListener;g.prototype.prependListener=function(t,r){return Gt(this,t,r,!0)};function Yr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Kt(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=Yr.bind(n);return i.listener=r,n.wrapFn=i,i}g.prototype.once=function(t,r){return Xe(r),this.on(t,Kt(this,t,r)),this};g.prototype.prependOnceListener=function(t,r){return Xe(r),this.prependListener(t,Kt(this,t,r)),this};g.prototype.removeListener=function(t,r){var n,i,o,s,c;if(Xe(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Zr(n,o),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};g.prototype.off=g.prototype.removeListener;g.prototype.removeAllListeners=function(t){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(t,r[i]);return this};function Xt(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?en(i):Qt(i,i.length)}g.prototype.listeners=function(t){return Xt(this,t,!0)};g.prototype.rawListeners=function(t){return Xt(this,t,!1)};g.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Vt.call(e,t)};g.prototype.listenerCount=Vt;function Vt(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}g.prototype.eventNames=function(){return this._eventsCount>0?Ke(this._events):[]};function Qt(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,i,o=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),i=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],i[t]=4>=e||4>t?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return nr(this,e,0)},decrypt:function(e){return nr(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],i,o,s,c=[],u=[],f,l,h,m;for(i=0;256>i;i++)u[(c[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[o]=h,n[h]=o,l=c[i=c[f=c[o]]],m=16843009*l^65537*i^257*f^16843008*o,l=257*c[h]^16843008*h,i=0;4>i;i++)e[i][o]=l=l<<24^l>>>8,t[i][h]=m=m<<24^m>>>8;for(i=0;5>i;i++)e[i]=e[i].slice(0),t[i]=t[i].slice(0)}};function nr(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],i=t[0]^n[0],o=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,l=n.length/4-2,h,m=4,d=[0,0,0,0];c=e.w[r],e=c[0];var O=c[1],N=c[2],z=c[3],Q=c[4];for(h=0;h>>24]^O[o>>16&255]^N[s>>8&255]^z[t&255]^n[m],u=e[o>>>24]^O[s>>16&255]^N[t>>8&255]^z[i&255]^n[m+1],f=e[s>>>24]^O[t>>16&255]^N[i>>8&255]^z[o&255]^n[m+2],t=e[t>>>24]^O[i>>16&255]^N[o>>8&255]^z[s&255]^n[m+3],m+=4,i=c,o=u,s=f;for(h=0;4>h;h++)d[r?3&-h:h]=Q[i>>>24]<<24^Q[o>>16&255]<<16^Q[s>>8&255]<<8^Q[t&255]^n[m++],c=i,i=o,o=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[i]<<32-t;return i=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(i),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>i)>>>26),6>i?(s=e[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,i=0,o=a.codec.base64.S,s=0,c;for(t&&(o=o.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>i),s=c<<32-i):(i+=6,s^=c<<32-i)}return i&56&&r.push(a.bitArray.partial(i&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,i=this.g,o=this.b,s=i[0],c=i[1],u=i[2],f=i[3],l=i[4],h=i[5],m=i[6],d=i[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(m^l&(h^m))+o[t],d=m,m=h,h=l,l=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;i[0]=i[0]+s|0,i[1]=i[1]+c|0,i[2]=i[2]+u|0,i[3]=i[3]+f|0,i[4]=i[4]+l|0,i[5]=i[5]+h|0,i[6]=i[6]+m|0,i[7]=i[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(o=!0,i=2;i*i<=n;i++)if(n%i===0){o=!1;break}o&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,i=this.b,o=n[0],s=n[1],c=n[2],u=n[3],f=n[4],l=n[5],h=n[6],m=n[7],d=n[8],O=n[9],N=n[10],z=n[11],Q=n[12],Je=n[13],It=n[14],He=n[15],P;if(typeof Uint32Array<"u"){P=Array(160);for(var _=0;32>_;_++)P[_]=e[_]}else P=e;var _=o,I=s,ye=c,ne=u,ve=f,ie=l,ct=h,ge=m,J=d,U=O,$e=N,we=z,qe=Q,Ee=Je,ut=It,Ae=He;for(e=0;80>e;e++){if(16>e)t=P[2*e],r=P[2*e+1];else{r=P[2*(e-15)];var A=P[2*(e-15)+1];t=(A<<31|r>>>1)^(A<<24|r>>>8)^r>>>7;var H=(r<<31|A>>>1)^(r<<24|A>>>8)^(r<<25|A>>>7);r=P[2*(e-2)];var q=P[2*(e-2)+1],A=(q<<13|r>>>19)^(r<<3|q>>>29)^r>>>6,q=(r<<13|q>>>19)^(q<<3|r>>>29)^(r<<26|q>>>6),ft=P[2*(e-7)],lt=P[2*(e-16)],Le=P[2*(e-16)+1];r=H+P[2*(e-7)+1],t=t+ft+(r>>>0>>0?1:0),r+=q,t+=A+(r>>>0>>0?1:0),r+=Le,t+=lt+(r>>>0>>0?1:0)}P[2*e]=t|=0,P[2*e+1]=r|=0;var ft=J&$e^~J&qe,Ut=U&we^~U&Ee,q=_&ye^_&ve^ye&ve,Ur=I&ne^I&ie^ne&ie,lt=(I<<4|_>>>28)^(_<<30|I>>>2)^(_<<25|I>>>7),Le=(_<<4|I>>>28)^(I<<30|_>>>2)^(I<<25|_>>>7),Mr=i[2*e],Mt=i[2*e+1],A=Ae+((J<<18|U>>>14)^(J<<14|U>>>18)^(U<<23|J>>>9)),H=ut+((U<<18|J>>>14)^(U<<14|J>>>18)^(J<<23|U>>>9))+(A>>>0>>0?1:0),A=A+Ut,H=H+(ft+(A>>>0>>0?1:0)),A=A+Mt,H=H+(Mr+(A>>>0>>0?1:0)),A=A+r|0,H=H+(t+(A>>>0>>0?1:0));r=Le+Ur,t=lt+q+(r>>>0>>0?1:0),ut=qe,Ae=Ee,qe=$e,Ee=we,$e=J,we=U,U=ge+A|0,J=ct+H+(U>>>0>>0?1:0)|0,ct=ve,ge=ie,ve=ye,ie=ne,ye=_,ne=I,I=A+r|0,_=H+t+(I>>>0>>0?1:0)|0}s=n[1]=s+I|0,n[0]=o+_+(s>>>0>>0?1:0)|0,u=n[3]=u+ne|0,n[2]=c+ye+(u>>>0>>0?1:0)|0,l=n[5]=l+ie|0,n[4]=f+ve+(l>>>0>>0?1:0)|0,m=n[7]=m+ge|0,n[6]=h+ct+(m>>>0>>0?1:0)|0,O=n[9]=O+U|0,n[8]=d+J+(O>>>0>>0?1:0)|0,z=n[11]=z+we|0,n[10]=N+$e+(z>>>0>>0?1:0)|0,Je=n[13]=Je+Ee|0,n[12]=Q+qe+(Je>>>0>>0?1:0)|0,He=n[15]=He+Ae|0,n[14]=It+ut+(He>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&f>>>8*o;o++);return o<15-u&&(o=15-u),r=c.clamp(r,8*(15-o)),t=a.mode.ccm.U(e,t,r,n,i,o),s=a.mode.ccm.V(e,s,r,t,i,o),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,i){i=i||64,n=n||[];var o=a.bitArray,s=o.bitLength(r)/8,f=o.bitLength(t),c=o.clamp(t,f-i),u=o.bitSlice(t,f-i),f=(f-i)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=o.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,i,t),e=a.mode.ccm.U(e,c.data,r,n,i,t),!o.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,i,o){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|o-1)],n=c.concat(n,r),n[3]|=i,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;ti||16l&&(a.mode.ccm.da(s/u),l+=h),r[3]++,i=e.encrypt(r),t[s]^=i[0],t[s+1]^=i[1],t[s+2]^=i[2],t[s+3]^=i[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,i=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>i&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),i=i||a.misc.hmac,e=new i(e);var o,s,c,u,f=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(i=o=e.encrypt(l.concat(t,[u])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=o),this.N++,this.b=a.hash.sha256.hash(this.b.concat(i)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,o,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,o,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&ir("seeded",Math.max(this.u,this.i)),ir("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:Ce(this,this.la),mouseCollector:Ce(this,this.na),keyboardCollector:Ce(this,this.ja),accelerometerCollector:Ce(this,this.ca),touchCollector:Ce(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,i=this.J[e],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===t&&o.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function Ce(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(et=typeof ce<"u"&&ce.exports){try{tt=Jr("crypto")}catch{tt=null}et=Ze=tt}if(et&&Ze.randomBytes)Te=Ze.randomBytes(128),Te=new Uint32Array(new Uint8Array(Te).buffer),a.random.addEntropy(Te,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Pe=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Pe);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Pe);else break e;a.random.addEntropy(Pe,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 Te,Ze,Pe,et,tt;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var i=a.json,o=i.j({iv:a.random.randomWords(4,0)},i.defaults),s;if(i.j(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=a.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=a.codec.base64.toBits(o.iv)),!a.mode[o.mode]||!a.cipher[o.cipher]||typeof e=="string"&&100>=o.iter||o.ts!==64&&o.ts!==96&&o.ts!==128||o.ks!==128&&o.ks!==192&&o.ks!==256||2>o.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{"use strict";var Dn=Object.prototype.hasOwnProperty,k="~";function Re(){}Object.create&&(Re.prototype=Object.create(null),new Re().__proto__||(k=!1));function _n(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Ar(e,t,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new _n(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 rt(e,t){--e._eventsCount===0?e._events=new Re:delete e._events[t]}function T(){this._events=new Re,this._eventsCount=0}T.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Dn.call(r,n)&&t.push(k?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};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{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:i}};function oe(e,t,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(l){try{f(n.next(l))}catch(h){s(h)}}function u(l){try{f(n.throw(l))}catch(h){s(h)}}function f(l){l.done?o(l.value):i(l.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ft(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function G(e){return this instanceof G?(this.v=e,this):new G(e)}function Bt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(d){return function(O){return Promise.resolve(O).then(d,h)}}function c(d,O){n[d]&&(i[d]=function(N){return new Promise(function(z,Q){o.push([d,N,z,Q])>1||u(d,N)})},O&&(i[d]=O(i[d])))}function u(d,O){try{f(n[d](O))}catch(N){m(o[0][3],N)}}function f(d){d.value instanceof G?Promise.resolve(d.value.v).then(l,h):m(o[0][2],d)}function l(d){u("next",d)}function h(d){u("throw",d)}function m(d,O){d(O),o.shift(),o.length&&u(o[0][0],o[0][1])}}function qr(e){var t,r;return t={},n("next"),n("throw",function(i){throw i}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(i,o){t[i]=e[i]?function(s){return(r=!r)?{value:G(e[i](s)),done:!1}:o?o(s):s}:o}}function Gr(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ft=="function"?Ft(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=e[o]&&function(s){return new Promise(function(c,u){s=e[o](s),i(c,u,s.done,s.value)})}}function i(o,s,c,u){Promise.resolve(u).then(function(f){o({value:f,done:c})},s)}}var b=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new F(n));return new e(r)}static fromPromise(t,r){let n=t.then(i=>new F(i)).catch(i=>new B(r(i)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(oe(this,void 0,void 0,function*(){try{return new F(yield t(...n))}catch(i){return new B(r?r(i):i)}}))}static combine(t){return Kr(t)}static combineWithAllErrors(t){return Xr(t)}map(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isErr()?new B(r.error):new F(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);let n=yield t(r.value);return n.isErr()?new B(n.error):new F(r.value)})))}andTee(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);try{yield t(r.value)}catch{}return new F(r.value)})))}mapErr(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isOk()?new F(r.value):new B(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new B(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>oe(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new F(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Bt(this,arguments,function*(){return yield G(yield G(yield*qr(Gr(yield G(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Bt(this,arguments,function*(){let r=yield G(this._promise);return r.isErr()&&(yield yield G(L(r.error))),yield G(r.value)})}},C=e=>new b(Promise.resolve(new F(e))),L=e=>new b(Promise.resolve(new B(e))),Pn=b.fromPromise,Rn=b.fromSafePromise,kn=b.fromThrowable,jt=e=>{let t=re([]);for(let r of e)if(r.isErr()){t=Y(r.error);break}else t.map(n=>n.push(r.value));return t},Kr=e=>b.fromSafePromise(Promise.all(e)).andThen(jt),zt=e=>{let t=re([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=Y([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Xr=e=>b.fromSafePromise(Promise.all(e)).andThen(zt),mt;(function(e){function t(i,o){return(...s)=>{try{let c=i(...s);return re(c)}catch(c){return Y(o?o(c):c)}}}e.fromThrowable=t;function r(i){return jt(i)}e.combine=r;function n(i){return zt(i)}e.combineWithAllErrors=n})(mt||(mt={}));var re=e=>new F(e);function Y(e){return new B(e)}var F=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return re(t(this.value))}mapErr(t){return re(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return re(this.value)}orElse(t){return re(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return b.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw Wt("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},B=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return Y(this.error)}mapErr(t){return Y(t(this.error))}andThrough(t){return Y(this.error)}andTee(t){return Y(this.error)}andThen(t){return Y(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return L(this.error)}asyncAndThrough(t){return L(this.error)}asyncMap(t){return L(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield Y(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Wt("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Sn=mt.fromThrowable;var R=class extends Error{constructor(r,n={}){let{cause:i,context:o}=n;super(r,{cause:i});w(this,"context");this.name=this.constructor.name,this.context=o}};var K=class extends R{};var Oe=class extends K{constructor(){super(...arguments);w(this,"message","An error occured while trying to connect to WebSocket")}};var $=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Vr=()=>typeof Deno<"u";var yt=e=>Vr()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e!=="encrypt"?`worker/${e}`:e}.js`));var er=be(Ve());var v=new er.default,Z=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e),gt=(e,t)=>{Z(e,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:t})},tr=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var ae=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),i,o,s,c,u=0,f=0;for(;u>4,n[u++]=(o&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var rr=new ae("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function xe(e){return rr.Encode(e)}function De(e){return rr.Decode(e)}var nn=new ae("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function wt(e){return nn.Decode(e)}var Lt=be(sr());var X=class extends R{};var ue=class extends X{constructor(){super(...arguments);w(this,"message","Unable to decrypt the provided data")}};var fe=class extends X{constructor(){super(...arguments);w(this,"message","Unable to encrypt the provided data")}};var ar=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return C(De(Lt.default.decrypt(e,r)))}catch(r){return L(new ue(void 0,{cause:$(r)}))}},cr=(e,t)=>{try{let r=Lt.default.encrypt(e,xe(t));return C({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return L(new fe(void 0,{cause:$(r)}))}};var ur=(e,t)=>lr(e).andThen(r=>b.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,t.data),n=>new ue(void 0,{cause:$(n)}))),fr=(e,t)=>lr(e).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return b.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,t),i=>new fe(void 0,{cause:$(i)})).andThen(i=>C({algo:1,data:i,iv:n}))}),lr=e=>b.fromPromise(crypto.subtle.importKey("raw",wt(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new X("Unable to import cryptography key",{cause:$(t)}));var hr=(e,t)=>t.algo===void 0||t.algo===0?ar(e,t):ur(e,t),pr=(e,t,r)=>r===0?cr(e,t):fr(e,t);var M={},mr=5,un=e=>(v.emit("UPLOAD_CANCELLED",e.success),C(void 0)),fn=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let i=JSON.parse(n);if(wn(i)){let o=r.shift();if(o){let s=JSON.parse(o);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv)),s.data=De(s.data)),hr(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return i.part===0?(Z(t,{chunksReady:t.chunksReady+1,delAtFirstView:i.del_at_first_view,delay:i.delay,name:i.name,size:i.size,totalChunks:i.total,type:i.type,zipped:i.zipped}),v.emit("DOWNLOAD_STARTED")):Z(t,{chunksReady:t.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,i.part),t.chunksReady===i.total?dn(t).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),C(void 0))):C(void 0)})}else{let s=new K("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),L(s)}}else{let o=new K(i.msg);return v.emit("OPERATION_FAILED",o),L(o)}}else{let i=new K("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",i),L(i)}},ln=(e,t)=>{if(e.success)return e.j===0&&(Z(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),v.emit("UPLOAD_STARTED")),Z(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),v.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Z(t,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),C(void 0);{let r=new K(e.msg);return v.emit("OPERATION_FAILED",r),L(r)}},hn=(e,t)=>{let r=gn(e.data),n;if(r)if(!r.action&&r.msg){let i=new K(r.msg);return v.emit("OPERATION_FAILED",i),L(i)}else"delay"in r?n=ln(r,t):n=un(r);else n=fn(e.data,t);return n},pn=e=>M!==void 0&&M[e]!==void 0&&M[e].readyState===WebSocket.CONNECTING,bt=e=>M!==void 0&&M[e]!==void 0&&M[e].readyState===WebSocket.OPEN;var dn=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},xt(yn(e),e,JSON.stringify(t))},Ot=(e,t,r)=>(r.data=xe(r.data),xt(vn(e),e,`${JSON.stringify(t)}XXMOJOXX${JSON.stringify(r)}`)),xt=(e,t,r)=>bt(e)?(M[e].send(r),C(void 0)):yr(e).andThen(()=>(M[e].onmessage=n=>hn(n,t),xt(e,t,r))),yr=(e,t=0)=>(!bt(e)&&!pn(e)&&(M[e]=new WebSocket(e),v.once("SOCKET_OPERATION_TERMINATED",()=>{M[e].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),M[e].onopen=()=>{v.emit("SOCKET_OPENED")},M[e].onclose=()=>{},M[e].onerror=()=>++t<=mr?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${mr}`),yr(e,t)):(v.emit("SOCKET_ONERROR"),L(new Oe(`Unable to connect to WebSocket ${e}.`)))),mn(e).andThen(()=>C(e)).orElse(r=>L(r))),mn=e=>b.fromPromise(new Promise((t,r)=>{bt(e)?t(void 0):(v.once("SOCKET_OPENED",()=>{t(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new Oe)}))}),t=>$(t));var vr=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},yn=e=>vr(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),vn=e=>vr(new URL(e.serverUrl),"upload").toString(),gn=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},wn=e=>typeof e=="object"&&e!==null&&!("msg"in e);var wr=be(Ve());var Ln=be(Ve());var On={},Ds=new wr.default;var xn=()=>Object.values(On).filter(e=>e.uploadStatus===4),Er=e=>Object.keys(xn()).indexOf(e);var _t=be(Lr(),1);var ke=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ct=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},br=e=>globalThis.DOMException===void 0?new Ct(e):new DOMException(e),Or=e=>{let t=e.reason===void 0?br("This operation was aborted."):e.reason;return t instanceof Error?t:br(t)};function Tt(e,t){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=t,s,u=new Promise((f,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:m}=t;m.aborted&&l(Or(m));let d=()=>{l(Or(m))};m.addEventListener("abort",d,{once:!0}),e.finally(()=>{m.removeEventListener("abort",d)})}if(r===Number.POSITIVE_INFINITY){e.then(f,l);return}let h=new ke;s=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof e.cancel=="function"&&e.cancel(),i===!1?f():i instanceof Error?l(i):(h.message=i!=null?i:`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await e)}catch(m){l(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},u}function Pt(e,t,r){let n=0,i=e.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(e[s],t)<=0?(n=++s,i-=o+1):i=o}return n}var V,Se=class{constructor(){x(this,V,[])}enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,run:t};if(this.size&&p(this,V)[this.size-1].priority>=r.priority){p(this,V).push(n);return}let i=Pt(p(this,V),n,(o,s)=>s.priority-o.priority);p(this,V).splice(i,0,n)}dequeue(){let t=p(this,V).shift();return t==null?void 0:t.run}filter(t){return p(this,V).filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return p(this,V).length}};V=new WeakMap;var le,he,te,Ue,pe,Me,W,de,S,Ne,j,me,ee,Fe,y,xr,Dr,_r,Cr,Tr,nt,Rt,kt,it,Pr,ot,Ie=class extends _t.default{constructor(r){var n,i,o,s;super();x(this,y);x(this,le);x(this,he);x(this,te,0);x(this,Ue);x(this,pe);x(this,Me,0);x(this,W);x(this,de);x(this,S);x(this,Ne);x(this,j,0);x(this,me);x(this,ee);x(this,Fe);w(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Se,...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})`);E(this,le,r.carryoverConcurrencyCount),E(this,he,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),E(this,Ue,r.intervalCap),E(this,pe,r.interval),E(this,S,new r.queueClass),E(this,Ne,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,E(this,Fe,r.throwOnTimeout===!0),E(this,ee,r.autoStart===!1)}get concurrency(){return p(this,me)}set concurrency(r){if(!(typeof r=="number"&&r>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${r}\` (${typeof r})`);E(this,me,r),D(this,y,it).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,Fe),...n},new Promise((i,o)=>{p(this,S).enqueue(async()=>{var s;Ge(this,j)._++,Ge(this,te)._++;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,D(this,y,Pr).call(this,n.signal)]));let u=await c;i(u),this.emit("completed",u)}catch(c){if(c instanceof ke&&!n.throwOnTimeout){i();return}o(c),this.emit("error",c)}finally{D(this,y,_r).call(this)}},n),this.emit("add"),D(this,y,nt).call(this)})}async addAll(r,n){return Promise.all(r.map(async i=>this.add(i,n)))}start(){return p(this,ee)?(E(this,ee,!1),D(this,y,it).call(this),this):this}pause(){E(this,ee,!0)}clear(){E(this,S,new(p(this,Ne)))}async onEmpty(){p(this,S).size!==0&&await D(this,y,ot).call(this,"empty")}async onSizeLessThan(r){p(this,S).sizep(this,S).size{D(this,y,Cr).call(this)},n)),!0}return!1},nt=function(){if(p(this,S).size===0)return p(this,W)&&clearInterval(p(this,W)),E(this,W,void 0),this.emit("empty"),p(this,j)===0&&this.emit("idle"),!1;if(!p(this,ee)){let r=!p(this,y,Tr);if(p(this,y,xr)&&p(this,y,Dr)){let n=p(this,S).dequeue();return n?(this.emit("active"),n(),r&&D(this,y,Rt).call(this),!0):!1}}return!1},Rt=function(){p(this,he)||p(this,W)!==void 0||(E(this,W,setInterval(()=>{D(this,y,kt).call(this)},p(this,pe))),E(this,Me,Date.now()+p(this,pe)))},kt=function(){p(this,te)===0&&p(this,j)===0&&p(this,W)&&(clearInterval(p(this,W)),E(this,W,void 0)),E(this,te,p(this,le)?p(this,j):0),D(this,y,it).call(this)},it=function(){for(;D(this,y,nt).call(this););},Pr=async function(r){return new Promise((n,i)=>{r.addEventListener("abort",()=>{i(r.reason)},{once:!0})})},ot=async function(r,n){return new Promise(i=>{let o=()=>{n&&!n()||(this.off(r,o),i())};this.on(r,o)})};var st=class extends R{};var Be=class extends st{constructor(){super(...arguments);w(this,"message","Parameter cannot be undefined")}};var Rr=!1,St=navigator.hardwareConcurrency||1,ze=new Ie({concurrency:St,autoStart:!1}),je=0,at=!1,We,kr=new Worker(yt("encrypt"),{type:"module"});self.onmessage=e=>{if(Rr||(tr(),Rr=!0,We=e.data.args.lufiFile,v.once("UPLOAD_STARTED",()=>{self.postMessage({event:"UPLOAD_STARTED"})}),v.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),je--,ze.isPaused&&!at&&je{self.postMessage({event:"UPLOAD_COMPLETE"})}),v.on("FILE_UPDATED",Z)),e.data.args.chunk)return e.data.args.lufiFile=We,Cn(e.data,Er(We.keys.client)).mapErr(t=>{gt(We,t)});e.data.action===0?(at=!0,Ir()):e.data.action===2?(at=!1,Sr()):gt(We,new Be)};var Cn=(e,t)=>{let{lufiFile:r,algo:n}=e.args;if(e.args.chunk&&n)e.args.chunk.index===0?pr(r.keys.client,e.args.chunk.buffer,n).map(i=>{Ot(r,{total:r.totalChunks,part:0,size:r.size,name:r.name,type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:null,i:t,file_pwd:r.password},i),je++}):ze.add(()=>{if(e.args.chunk){let i=()=>(je++,new Promise(o=>{kr.onmessage=s=>{o(Ot(r,{total:r.totalChunks,part:s.data.chunkIndex,size:r.size,name:r.name,type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:r.keys.server,i:t,file_pwd:r.password},s.data.encryptedData))}}));kr.postMessage(e,[e.args.chunk.buffer]),!ze.isPaused&&(at||je===St)&&Ir(),i()}});else return L(new Be("algo must be defined"));return C(void 0)},Ir=()=>{ze.pause(),self.postMessage({event:"JOB_PAUSED"})},Sr=()=>{ze.start(),self.postMessage({event:"JOB_RESUMED"})};