diff --git a/themes/default/public/js/lufi.js b/themes/default/public/js/lufi.js index 3e43fac..0a92812 100755 --- a/themes/default/public/js/lufi.js +++ b/themes/default/public/js/lufi.js @@ -1 +1 @@ -var Be=Object.create;var X=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Fe=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty;var We=(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 se=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ke=(t,e)=>{for(var r in e)X(t,r,{get:e[r],enumerable:!0})},qe=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ne(e))!Je.call(t,o)&&o!==r&&X(t,o,{get:()=>e[o],enumerable:!(n=je(e,o))||n.enumerable});return t};var Q=(t,e,r)=>(r=t!=null?Be(Fe(t)):{},qe(e||!t||!t.__esModule?X(r,"default",{value:t,enumerable:!0}):r,t));var ee=se((Lt,Z)=>{"use strict";var R=typeof Reflect=="object"?Reflect:null,ce=R&&typeof R.apply=="function"?R.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},K;R&&typeof R.ownKeys=="function"?K=R.ownKeys:Object.getOwnPropertySymbols?K=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:K=function(e){return Object.getOwnPropertyNames(e)};function Ge(t){console&&console.warn&&console.warn(t)}var fe=Number.isNaN||function(e){return e!==e};function m(){m.init.call(this)}Z.exports=m;Z.exports.once=Ve;m.EventEmitter=m;m.prototype._events=void 0;m.prototype._eventsCount=0;m.prototype._maxListeners=void 0;var ae=10;function q(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 ae},set:function(t){if(typeof t!="number"||t<0||fe(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");ae=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||fe(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 ue(t){return t._maxListeners===void 0?m.defaultMaxListeners:t._maxListeners}m.prototype.getMaxListeners=function(){return ue(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=i[e];if(f===void 0)return!1;if(typeof f=="function")ce(f,this,r);else for(var u=f.length,l=me(f,u),n=0;n0&&s.length>o&&!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,Ge(a)}return t}m.prototype.addListener=function(e,r){return he(this,e,r,!1)};m.prototype.on=m.prototype.addListener;m.prototype.prependListener=function(e,r){return he(this,e,r,!0)};function ze(){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 le(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=ze.bind(n);return o.listener=r,n.wrapFn=o,o}m.prototype.once=function(e,r){return q(r),this.on(e,le(this,e,r)),this};m.prototype.prependOnceListener=function(e,r){return q(r),this.prependListener(e,le(this,e,r)),this};m.prototype.removeListener=function(e,r){var n,o,i,s,a;if(q(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():$e(n,i),n.length===1&&(o[e]=n[0]),o.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,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,r[o]);return this};function pe(t,e,r){var n=t._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?He(o):me(o,o.length)}m.prototype.listeners=function(e){return pe(this,e,!0)};m.prototype.rawListeners=function(e){return pe(this,e,!1)};m.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):de.call(t,e)};m.prototype.listenerCount=de;function de(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?K(this._events):[]};function me(t,e){for(var r=new Array(e),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new c.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^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],o[e]=4>=t||4>e?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};c.cipher.aes.prototype={encrypt:function(t){return De(this,t,0)},decrypt:function(t){return De(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,a=[],f=[],u,l,h,p;for(o=0;256>o;o++)f[(a[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=u||1,s=f[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],p=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)t[o][i]=l=l<<24^l>>>8,e[o][h]=p=p<<24^p>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function De(t,e,r){if(e.length!==4)throw new c.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,f,u,l=n.length/4-2,h,p=4,d=[0,0,0,0];a=t.s[r],t=a[0];var y=a[1],P=a[2],J=a[3],W=a[4];for(h=0;h>>24]^y[i>>16&255]^P[s>>8&255]^J[e&255]^n[p],f=t[i>>>24]^y[s>>16&255]^P[e>>8&255]^J[o&255]^n[p+1],u=t[s>>>24]^y[e>>16&255]^P[o>>8&255]^J[i&255]^n[p+2],e=t[e>>>24]^y[o>>16&255]^P[i>>8&255]^J[s&255]^n[p+3],p+=4,o=a,i=f,s=u;for(h=0;4>h;h++)d[r?3&-h:h]=W[o>>>24]<<24^W[i>>16&255]<<16^W[s>>8&255]<<8^W[e&255]^n[p++],a=o,o=i,i=s,s=e,e=a;return d}c.bitArray={bitSlice:function(t,e,r){return t=c.bitArray.$(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:c.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(c.bitArray.bitLength(t)!==c.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=c.bitArray.getPartial(o),n.push(c.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};c.codec.utf8String={fromBits:function(t){var e="",r=c.bitArray.bitLength(t),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>s)>>>o),sl){if(!e)try{return c.codec.base32hex.toBits(t)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=c.codec.base64.B,s=0,a;for(e&&(i=i.substr(0,62)+"-_"),n=0;na)throw new c.exception.invalid("this isn't base64!");26>>o),s=a<<32-o):(o+=6,s^=a<<32-o)}return o&56&&r.push(c.bitArray.partial(o&56,s,1)),r}};c.codec.base64url={fromBits:function(t){return c.codec.base64.fromBits(t,1,1)},toBits:function(t){return c.codec.base64.toBits(t,1)}};c.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()};c.hash.sha256.hash=function(t){return new c.hash.sha256().update(t).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.A=c.bitArray.concat(this.A,t);if(e=this.l,t=this.l=e+c.bitArray.bitLength(t),9007199254740991e;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>e&&(this.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function ne(t,e){var r,n,o,i=t.F,s=t.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],p=i[5],d=i[6],y=i[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],o=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+e[r&15]+e[r+9&15]|0),n=n+y+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(d^h&(p^d))+s[r],y=d,d=p,p=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+p|0,i[6]=i[6]+d|0,i[7]=i[7]+y|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(t){c.mode.ccm.G.push(t)},unListenProgress:function(t){t=c.mode.ccm.G.indexOf(t),-1f)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&u>>>8*i;i++);return i<15-f&&(i=15-f),r=a.clamp(r,8*(15-i)),e=c.mode.ccm.V(t,e,r,n,o,i),s=c.mode.ccm.C(t,s,r,e,o,i),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(e),a=i.clamp(e,u-o),f=i.bitSlice(e,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&u>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),a=c.mode.ccm.C(t,a,r,f,o,e),t=c.mode.ccm.V(t,a.data,r,n,o,e),!i.equal(a.tag,t))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(t,e,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,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;eo||16l&&(c.mode.ccm.fa(s/f),l+=h),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:a.clamp(e,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(t.encrypt(r));var h,p=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(a,n(a))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=c.bitArray,n=n||[],t=c.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(e=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(e=i,i=[]),t=c.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new c.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(t,e,r){var n,o=r.length;for(e=e.slice(0),n=0;no&&(t=e.hash(t)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),o=o||c.misc.hmac,t=new o(t);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=t.encrypt(l.concat(e,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[s].update(t);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=e,this.f+=e,a===this.u&&(this.isReady()!==this.u&&ke("seeded",Math.max(this.o,this.f)),ke("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:j(this,this.ma),mouseCollector:j(this,this.oa),keyboardCollector:j(this,this.la),accelerometerCollector:j(this,this.ea),touchCollector:j(this,this.qa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new c.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function j(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(z=typeof U<"u"&&U.exports){try{$=We("crypto")}catch{$=null}z=G=$}if(z&&G.randomBytes)N=G.randomBytes(128),N=new Uint32Array(new Uint8Array(N).buffer),c.random.addEntropy(N,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(F=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(F);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(F);else break e;c.random.addEntropy(F,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 N,G,F,z,$;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=c.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=c.codec.base64.toBits(i.iv)),!c.mode[i.mode]||!c.cipher[i.cipher]||typeof t=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=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||4lt,download:()=>pt,events:()=>ht,getFileIndexInQueue:()=>wt,infos:()=>dt,remove:()=>mt,upload:()=>gt});var Ie=Q(ee());var Xe={withStackTrace:!1},ve=(t,e,r=Xe)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:o}};function T(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function a(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(t,[])).next())})}function ge(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 k(t){return this instanceof k?(this.v=t,this):new k(t)}function Qe(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(p){n[p]&&(o[p]=function(d){return new Promise(function(y,P){i.push([p,d,y,P])>1||a(p,d)})})}function a(p,d){try{f(n[p](d))}catch(y){h(i[0][3],y)}}function f(p){p.value instanceof k?Promise.resolve(p.value.v).then(u,l):h(i[0][2],p)}function u(p){a("next",p)}function l(p){a("throw",p)}function h(p,d){p(d),i.shift(),i.length&&a(i[0][0],i[0][1])}}function Ze(t){var e,r;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=t[o]?function(s){return(r=!r)?{value:k(t[o](s)),done:o==="return"}:i?i(s):s}:i}}function et(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 ge=="function"?ge(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(a,f){s=t[i](s),o(a,f,s.done,s.value)})}}function o(i,s,a,f){Promise.resolve(f).then(function(u){i({value:u,done:a})},s)}}var g=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new E(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new E(o)).catch(o=>new L(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(T(this,void 0,void 0,function*(){try{return new E(yield e(...n))}catch(o){return new L(r?r(o):o)}}))}static combine(e){return tt(e)}static combineWithAllErrors(e){return rt(e)}map(e){return new t(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new L(r.error):new E(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new L(r.error);let n=yield e(r.value);return n.isErr()?new L(n.error):new E(r.value)})))}andTee(e){return new t(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new L(r.error);try{yield e(r.value)}catch{}return new E(r.value)})))}mapErr(e){return new t(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isOk()?new E(r.value):new L(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new L(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new E(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 Qe(this,arguments,function*(){return yield k(yield k(yield*Ze(et(yield k(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},S=t=>new g(Promise.resolve(new E(t))),w=t=>new g(Promise.resolve(new L(t))),At=g.fromPromise,bt=g.fromSafePromise,xt=g.fromThrowable,we=t=>{let e=b([]);for(let r of t)if(r.isErr()){e=A(r.error);break}else e.map(n=>n.push(r.value));return e},tt=t=>g.fromSafePromise(Promise.all(t)).andThen(we),Ee=t=>{let e=b([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=A([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},rt=t=>g.fromSafePromise(Promise.all(t)).andThen(Ee),te;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return b(a)}catch(a){return A(i?i(a):a)}}}t.fromThrowable=e;function r(o){return we(o)}t.combine=r;function n(o){return Ee(o)}t.combineWithAllErrors=n})(te||(te={}));var b=t=>new E(t);function A(t){return new L(t)}var E=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return b(e(this.value))}mapErr(e){return b(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 b(this.value)}orElse(e){return b(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return g.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 ve("Called `_unsafeUnwrapErr` on an Ok",this,e)}},L=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return A(this.error)}mapErr(e){return A(e(this.error))}andThrough(e){return A(this.error)}andTee(e){return A(this.error)}andThen(e){return A(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 A(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw ve("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Ot=te.fromThrowable;var _=class t{actionToken="";chunksReady=0;createdAt=0;delay=0;delAtFirstView=!1;keys={client:"",server:""};name="";password="";queueIndex=0;serverUrl;size=0;uploadStatus=3;totalChunks=0;type="";zipped=!1;constructor(e,r){this.serverUrl=e,Object.assign(this,r)}downloadUrl(){return new URL(`${new URL(this.serverUrl).href}r/${this.keys.server}#${this.keys.client}`)}removeUrl(){return new URL(`${new URL(this.serverUrl).href}d/${this.keys.server}/${this.actionToken}`)}static fromDownloadUrl(e,r=""){let n=e.pathname.split("r/"),o={client:e.hash.slice(1).split("&")[0],server:n[1]};return new t(e.origin+n[0],{keys:o,password:r})}static fromRemoveUrl(e,r=""){let n=e.pathname.split("d/"),o=n[1].split("/"),i={client:"",server:o[0]};return new t(e.origin+n[0],{keys:i,password:r,actionToken:o[1]})}};var be=Q(ee());var O=class extends Error{context;constructor(e,r={}){let{cause:n,context:o}=r;super(e,{cause:n}),this.name=this.constructor.name,this.context=o}};var v=t=>{if(t instanceof Error)return t;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(t)}catch{}return new Error(e)};var nt=()=>typeof Deno<"u",Ae=t=>nt()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var D=class{events=new be.default;lufiFile;tmpFile;tmpChunks=[];worker;isTerminated=!1;status=2;constructor(e){this.worker=new Worker(Ae("main"),{type:"module"}),this.lufiFile=e,this.events.once("JOB_TERMINATED",()=>{this.isTerminated=!0,this.terminate()}),this.events.once("OPERATION_FAILED",r=>{this.status=1,this.lufiFile.uploadStatus=2,this.events.emit("JOB_TERMINATED",r)}),this.onError(r=>console.error(r.error))}complete=()=>{this.status=0,this.events.emit("JOB_TERMINATED")};hasFailed=()=>this.status===1;onError=e=>(this.worker.onerror=r=>{e(r)},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);onMessageError=e=>(this.worker.onmessageerror=r=>{e(r)},this);onProgress=e=>(this.events.on("CHUNK_UPLOADED",()=>{e()}),this.events.on("CHUNK_DOWNLOADED",()=>{e()}),this);requestMessage=(e,r=[])=>(this.worker.postMessage(e,r),this);terminate=()=>(this.worker.terminate(),this);waitForCompletion=()=>this.isTerminated?this.status===0?S(this):w(v("Job has failed")):g.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("JOB_TERMINATED",()=>{this.status===0&&e(this)})}),e=>v(e));dispatchEvent=(e,r)=>{this.events.emit(e,r)}};var I=class{constructor(e,r){if(!e||e.length!=64)throw Error("Charset must contain 64 characters");this._charset=e,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(e){let r=e.byteLength;if(!r)return"";let n=new Uint8Array(e),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(e){if(e=(e||"").replace(/[\s]/g,""),!e)return new ArrayBuffer(0);if(!this._valid.test(e))throw Error("Invalid base64 input sequence");let r=Math.floor(e.length*.75);e[e.length-2]=="="?r-=2:e[e.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,a,f=0,u=0;for(;f>4,n[f++]=(i&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var er=new I("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");var it=new I("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function re(t){return it.Encode(t)}var ie=Q(Ce());var x=class extends O{};var M=class extends x{message="Unable to decrypt the provided data"};var Re=()=>{try{return S(ie.default.codec.base64.fromBits(ie.default.random.randomWords(8,10)))}catch(t){return w(new x("Unable to generate a random key",{cause:v(t)}))}};var Te=()=>g.fromPromise(new Promise(t=>crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]).then(e=>crypto.subtle.exportKey("raw",e).then(r=>t(re(r))).catch(r=>w(new M(void 0,{cause:v(r)})))).catch(e=>w(new M(void 0,{cause:v(e)})))),t=>new x("Unable to base64 encode the url",{cause:v(t)}));var Se=(t=1)=>t===0?Re():Te();var H=class extends O{message="An error occured while dealing with a file"};var V=class extends H{message="An error occured while operating on a file"};var Y=class extends V{message="An error occured while slicing a file"};var ut=15e5,C={},ht=new Ie.default,lt=t=>{t.terminate();let e=new D(t.lufiFile);return g.fromPromise(new Promise((r,n)=>{e.onMessage(o=>{o.data.event==="UPLOAD_CANCELLED"&&(C[e.lufiFile.keys.client].uploadStatus=0,r(e)),o.data.event==="OPERATION_FAILED"&&n(o.data.error)}).requestMessage({action:0,args:{lufiFile:e.lufiFile}})}),r=>v(r))},pt=(t,e)=>{let r=_.fromDownloadUrl(t,e),n=new D(r);return g.fromPromise(new Promise((o,i)=>n.onMessage(s=>{Ue(o,i,n,s),s.data.event==="CHUNK_DOWNLOADED"&&(n.tmpChunks[s.data.chunk.index]=new Blob([s.data.chunk.buffer])),s.data.event==="DOWNLOAD_COMPLETE"&&(n.tmpFile=new Blob(n.tmpChunks,{type:r.type}),n.tmpChunks=[],n.complete())}).requestMessage({action:1,args:{lufiFile:r}})),o=>v(o))},dt=(t,e)=>{let r=_.fromDownloadUrl(t,e),n=new D(r);return g.fromPromise(new Promise((o,i)=>{n.onMessage(s=>{s.data.event==="INFOS_RETRIEVED"&&(n.complete(),o(n)),s.data.event==="OPERATION_FAILED"&&i(s.data.error)}).requestMessage({action:2,args:{lufiFile:r}})}),o=>v(o))},mt=(t,e)=>{let r=_.fromRemoveUrl(t,e),n=new D(r);return g.fromPromise(new Promise((o,i)=>{n.onMessage(s=>{s.data.event==="FILE_REMOVED"&&(n.complete(),o(n)),s.data.event==="OPERATION_FAILED"&&i(s.data.error)}).requestMessage({action:4,args:{lufiFile:r}})}),o=>v(o))},yt=(t,e,r=ut)=>{let n=Math.ceil(t.size/r);if(C[e].totalChunks=n,n>0){let o=[];for(let i=0;iSe().andThen(s=>{C[s]=new _(t.toString(),{delay:r,delAtFirstView:n,zipped:o,password:i,name:e.name,size:e.size,type:e.type,keys:{client:s,server:""}});let a=new D(C[s]);return yt(e,s).asyncAndThen(f=>{C[s].uploadStatus=4;let u=new Promise((h,p)=>{a.onMessage(d=>{switch(Ue(h,p,a,d),d.data.event){case"UPLOAD_COMPLETE":a.complete(),a.lufiFile.uploadStatus=1;break}})}),l=async h=>{for(let[p,d]of h.entries()){let y=await d.arrayBuffer();a.requestMessage({action:5,args:{chunk:{buffer:y,index:p},lufiFile:C[s]}},[y])}};return g.fromSafePromise(l(f)).andThen(()=>g.fromPromise(u,h=>v(h)))}).orElse(f=>w(f))}),Ue=(t,e,r,n)=>{n.data.event==="SOCKET_OPENED"&&t(r),n.data.event==="OPERATION_FAILED"&&e(n.data.error)},vt=()=>Object.values(C).filter(t=>t.uploadStatus===4),wt=t=>Object.keys(vt()).indexOf(t);export{A as err,w as errAsync,Me as lufi,b as ok,S as okAsync}; +var Je=Object.create;var ee=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ge=Object.prototype.hasOwnProperty;var ze=(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 ue=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),$e=(t,e)=>{for(var r in e)ee(t,r,{get:e[r],enumerable:!0})},He=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ke(e))!Ge.call(t,i)&&i!==r&&ee(t,i,{get:()=>e[i],enumerable:!(n=We(e,i))||n.enumerable});return t};var te=(t,e,r)=>(r=t!=null?Je(qe(t)):{},He(e||!t||!t.__esModule?ee(r,"default",{value:t,enumerable:!0}):r,t));var ne=ue((Ot,re)=>{"use strict";var T=typeof Reflect=="object"?Reflect:null,he=T&&typeof T.apply=="function"?T.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},K;T&&typeof T.ownKeys=="function"?K=T.ownKeys:Object.getOwnPropertySymbols?K=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:K=function(e){return Object.getOwnPropertyNames(e)};function Ve(t){console&&console.warn&&console.warn(t)}var pe=Number.isNaN||function(e){return e!==e};function m(){m.init.call(this)}re.exports=m;re.exports.once=Ze;m.EventEmitter=m;m.prototype._events=void 0;m.prototype._eventsCount=0;m.prototype._maxListeners=void 0;var le=10;function q(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 le},set:function(t){if(typeof t!="number"||t<0||pe(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");le=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||pe(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 de(t){return t._maxListeners===void 0?m.defaultMaxListeners:t._maxListeners}m.prototype.getMaxListeners=function(){return de(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")he(f,this,r);else for(var u=f.length,l=we(f,u),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,Ve(a)}return t}m.prototype.addListener=function(e,r){return me(this,e,r,!1)};m.prototype.on=m.prototype.addListener;m.prototype.prependListener=function(e,r){return me(this,e,r,!0)};function Ye(){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 ye(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=Ye.bind(n);return i.listener=r,n.wrapFn=i,i}m.prototype.once=function(e,r){return q(r),this.on(e,ye(this,e,r)),this};m.prototype.prependOnceListener=function(e,r){return q(r),this.prependListener(e,ye(this,e,r)),this};m.prototype.removeListener=function(e,r){var n,i,o,s,a;if(q(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():Xe(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 ge(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?Qe(i):we(i,i.length)}m.prototype.listeners=function(e){return ge(this,e,!0)};m.prototype.rawListeners=function(e){return ge(this,e,!1)};m.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):ve.call(t,e)};m.prototype.listenerCount=ve;function ve(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?K(this._events):[]};function we(t,e){for(var r=new Array(e),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,r,n,i,o=this.s[0][4],s=this.s[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new c.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]]};c.cipher.aes.prototype={encrypt:function(t){return Pe(this,t,0)},decrypt:function(t){return Pe(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],i,o,s,a=[],f=[],u,l,h,p;for(i=0;256>i;i++)f[(a[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=u||1,s=f[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=a[i=a[u=a[o]]],p=16843009*l^65537*i^257*u^16843008*o,l=257*a[h]^16843008*h,i=0;4>i;i++)t[i][o]=l=l<<24^l>>>8,e[i][h]=p=p<<24^p>>>8;for(i=0;5>i;i++)t[i]=t[i].slice(0),e[i]=e[i].slice(0)}};function Pe(t,e,r){if(e.length!==4)throw new c.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,u,l=n.length/4-2,h,p=4,d=[0,0,0,0];a=t.s[r],t=a[0];var g=a[1],R=a[2],J=a[3],W=a[4];for(h=0;h>>24]^g[o>>16&255]^R[s>>8&255]^J[e&255]^n[p],f=t[o>>>24]^g[s>>16&255]^R[e>>8&255]^J[i&255]^n[p+1],u=t[s>>>24]^g[e>>16&255]^R[i>>8&255]^J[o&255]^n[p+2],e=t[e>>>24]^g[i>>16&255]^R[o>>8&255]^J[s&255]^n[p+3],p+=4,i=a,o=f,s=u;for(h=0;4>h;h++)d[r?3&-h:h]=W[i>>>24]<<24^W[o>>16&255]<<16^W[s>>8&255]<<8^W[e&255]^n[p++],a=i,i=o,o=s,s=e,e=a;return d}c.bitArray={bitSlice:function(t,e,r){return t=c.bitArray.$(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:c.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(c.bitArray.bitLength(t)!==c.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=c.bitArray.getPartial(i),n.push(c.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};c.codec.utf8String={fromBits:function(t){var e="",r=c.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>>s)>>>i),sl){if(!e)try{return c.codec.base32hex.toBits(t)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>i?(a-=i,o.push(u^l>>>a),u=l<>>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=c.codec.base64.B,s=0,a;for(e&&(o=o.substr(0,62)+"-_"),n=0;na)throw new c.exception.invalid("this isn't base64!");26>>i),s=a<<32-i):(i+=6,s^=a<<32-i)}return i&56&&r.push(c.bitArray.partial(i&56,s,1)),r}};c.codec.base64url={fromBits:function(t){return c.codec.base64.fromBits(t,1,1)},toBits:function(t){return c.codec.base64.toBits(t,1)}};c.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()};c.hash.sha256.hash=function(t){return new c.hash.sha256().update(t).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.A=c.bitArray.concat(this.A,t);if(e=this.l,t=this.l=e+c.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.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function ce(t,e){var r,n,i,o=t.F,s=t.b,a=o[0],f=o[1],u=o[2],l=o[3],h=o[4],p=o[5],d=o[6],g=o[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],i=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(i>>>17^i>>>19^i>>>10^i<<15^i<<13)+e[r&15]+e[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(d^h&(p^d))+s[r],g=d,d=p,p=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;o[0]=o[0]+a|0,o[1]=o[1]+f|0,o[2]=o[2]+u|0,o[3]=o[3]+l|0,o[4]=o[4]+h|0,o[5]=o[5]+p|0,o[6]=o[6]+d|0,o[7]=o[7]+g|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(t){c.mode.ccm.G.push(t)},unListenProgress:function(t){t=c.mode.ccm.G.indexOf(t),-1f)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&u>>>8*o;o++);return o<15-f&&(o=15-f),r=a.clamp(r,8*(15-o)),e=c.mode.ccm.V(t,e,r,n,i,o),s=c.mode.ccm.C(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=c.bitArray,s=o.bitLength(r)/8,u=o.bitLength(e),a=o.clamp(e,u-i),f=o.bitSlice(e,u-i),u=(u-i)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&u>>>8*e;e++);if(e<15-s&&(e=15-s),r=o.clamp(r,8*(15-e)),a=c.mode.ccm.C(t,a,r,f,i,e),t=c.mode.ccm.V(t,a.data,r,n,i,e),!o.equal(a.tag,t))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(t,e,r,n,i,o){var s=[],a=c.bitArray,f=a.i;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||16l&&(c.mode.ccm.fa(s/f),l+=h),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,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,i,o){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(t.encrypt(r));var h,p=[];for(n=n||[],i=i||64,s=0;s+4i.bitLength(r)&&(a=o(a,n(a)),r=i.concat(r,[-2147483648,0,0,0])),s=o(s,r),t.encrypt(o(n(o(a,n(a))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,i){var o=e.slice(0);return e=c.bitArray,n=n||[],t=c.mode.gcm.C(!0,t,o,n,r,i||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,i){var o=e.slice(0),s=c.bitArray,a=s.bitLength(o);if(i=i||128,n=n||[],i<=a?(e=s.bitSlice(o,a-i),o=s.bitSlice(o,0,a-i)):(e=o,o=[]),t=c.mode.gcm.C(!1,t,o,n,r,i),!s.equal(t.tag,e))throw new c.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,i,o,s,a=c.bitArray.i;for(i=[0,0,0,0],o=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(i=a(i,o)),s=(o[3]&1)!==0,n=3;0>>1|(o[n-1]&1)<<31;o[0]>>>=1,s&&(o[0]^=-520093696)}return i},j:function(t,e,r){var n,i=r.length;for(e=e.slice(0),n=0;ni&&(t=e.hash(t)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),i=i||c.misc.hmac,t=new i(t);var o,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(i=o=t.encrypt(l.concat(e,[f])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=o),this.P++,this.b=c.hash.sha256.hash(this.b.concat(i)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,o,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,o,t.length]),this.c[s].update(t);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=e,this.f+=e,a===this.u&&(this.isReady()!==this.u&&Re("seeded",Math.max(this.o,this.f)),Re("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:j(this,this.ma),mouseCollector:j(this,this.oa),keyboardCollector:j(this,this.la),accelerometerCollector:j(this,this.ea),touchCollector:j(this,this.qa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new c.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,i=this.K[t],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===e&&o.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function j(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(V=typeof U<"u"&&U.exports){try{Y=ze("crypto")}catch{Y=null}V=H=Y}if(V&&H.randomBytes)N=H.randomBytes(128),N=new Uint32Array(new Uint8Array(N).buffer),c.random.addEntropy(N,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(F=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(F);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(F);else break e;c.random.addEntropy(F,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 N,H,F,V,Y;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var i=c.json,o=i.g({iv:c.random.randomWords(4,0)},i.defaults),s;if(i.g(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=c.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=c.codec.base64.toBits(o.iv)),!c.mode[o.mode]||!c.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||4yt,download:()=>gt,events:()=>mt,getFileIndexInQueue:()=>bt,infos:()=>vt,remove:()=>wt,upload:()=>Lt});var je=te(ne());var tt={withStackTrace:!1},Ae=(t,e,r=tt)=>{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 S(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(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?o(l.value):i(l.value).then(a,f)}u((n=n.apply(t,[])).next())})}function Le(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 C(t){return this instanceof C?(this.v=t,this):new C(t)}function rt(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i={},s("next"),s("throw"),s("return"),i[Symbol.asyncIterator]=function(){return this},i;function s(p){n[p]&&(i[p]=function(d){return new Promise(function(g,R){o.push([p,d,g,R])>1||a(p,d)})})}function a(p,d){try{f(n[p](d))}catch(g){h(o[0][3],g)}}function f(p){p.value instanceof C?Promise.resolve(p.value.v).then(u,l):h(o[0][2],p)}function u(p){a("next",p)}function l(p){a("throw",p)}function h(p,d){p(d),o.shift(),o.length&&a(o[0][0],o[0][1])}}function nt(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:C(t[i](s)),done:i==="return"}:o?o(s):s}:o}}function it(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 Le=="function"?Le(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(u){o({value:u,done:a})},s)}}var y=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new E(n));return new t(r)}static fromPromise(e,r){let n=e.then(i=>new E(i)).catch(i=>new L(r(i)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(S(this,void 0,void 0,function*(){try{return new E(yield e(...n))}catch(i){return new L(r?r(i):i)}}))}static combine(e){return ot(e)}static combineWithAllErrors(e){return st(e)}map(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){return r.isErr()?new L(r.error):new E(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){if(r.isErr())return new L(r.error);let n=yield e(r.value);return n.isErr()?new L(n.error):new E(r.value)})))}andTee(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){if(r.isErr())return new L(r.error);try{yield e(r.value)}catch{}return new E(r.value)})))}mapErr(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){return r.isOk()?new E(r.value):new L(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new L(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new E(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 rt(this,arguments,function*(){return yield C(yield C(yield*nt(it(yield C(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},b=t=>new y(Promise.resolve(new E(t))),w=t=>new y(Promise.resolve(new L(t))),Dt=y.fromPromise,kt=y.fromSafePromise,_t=y.fromThrowable,be=t=>{let e=O([]);for(let r of t)if(r.isErr()){e=A(r.error);break}else e.map(n=>n.push(r.value));return e},ot=t=>y.fromSafePromise(Promise.all(t)).andThen(be),xe=t=>{let e=O([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=A([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},st=t=>y.fromSafePromise(Promise.all(t)).andThen(xe),ie;(function(t){function e(i,o){return(...s)=>{try{let a=i(...s);return O(a)}catch(a){return A(o?o(a):a)}}}t.fromThrowable=e;function r(i){return be(i)}t.combine=r;function n(i){return xe(i)}t.combineWithAllErrors=n})(ie||(ie={}));var O=t=>new E(t);function A(t){return new L(t)}var E=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return O(e(this.value))}mapErr(e){return O(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 O(this.value)}orElse(e){return O(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,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Ae("Called `_unsafeUnwrapErr` on an Ok",this,e)}},L=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return A(this.error)}mapErr(e){return A(e(this.error))}andThrough(e){return A(this.error)}andTee(e){return A(this.error)}andThen(e){return A(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 A(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ae("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Ct=ie.fromThrowable;var x=class t{actionToken="";chunksReady=0;createdAt=0;delay=0;delAtFirstView=!1;keys={client:"",server:""};name="";password="";queueIndex=0;serverUrl;size=0;uploadStatus=3;totalChunks=0;type="";zipped=!1;constructor(e,r){this.serverUrl=e,Object.assign(this,r)}downloadUrl(){return new URL(`${new URL(this.serverUrl).href}r/${this.keys.server}#${this.keys.client}`)}removeUrl(){return new URL(`${new URL(this.serverUrl).href}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 ke=te(ne());var D=class extends Error{context;constructor(e,r={}){let{cause:n,context:i}=r;super(e,{cause:n}),this.name=this.constructor.name,this.context=i}};var G=class extends D{message="Unable to connect. Is the computer able to access the url?"};var z=class extends D{message="The server returned an error"};var v=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)},oe=t=>{let e=t.href.match(/(.*?)\/?(?:[dr]{1}\/|login\/?|files\/?)/),r=e&&e[1]?e[1]:t.origin;return y.fromPromise(fetch(r+"/about/config"),n=>new G(void 0,{cause:v(n)})).andThen(n=>n.ok?y.fromPromise(n.json(),i=>v(i)):w(new z(void 0,{context:n.statusText})))},ct=()=>typeof Deno<"u",De=t=>ct()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`)),$=async t=>t?Array.from(new Uint8Array(await crypto.subtle.digest("SHA-512",new TextEncoder().encode(t)))).map(e=>e.toString(16).padStart(2,"0")).join(""):"";var _=class{events=new ke.default;lufiFile;tmpFile;tmpChunks=[];worker;isTerminated=!1;status=2;constructor(e){this.worker=new Worker(De("main"),{type:"module"}),this.lufiFile=e,this.events.once("JOB_TERMINATED",()=>{this.isTerminated=!0,this.terminate()}),this.events.once("OPERATION_FAILED",r=>{this.status=1,this.lufiFile.uploadStatus=2,this.events.emit("JOB_TERMINATED",r)}),this.onError(r=>console.error(r.error))}complete=()=>{this.status=0,this.events.emit("JOB_TERMINATED")};hasFailed=()=>this.status===1;onError=e=>(this.worker.onerror=r=>{e(r)},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);onMessageError=e=>(this.worker.onmessageerror=r=>{e(r)},this);onProgress=e=>(this.events.on("CHUNK_UPLOADED",()=>{e()}),this.events.on("CHUNK_DOWNLOADED",()=>{e()}),this);requestMessage=(e,r=[])=>(this.worker.postMessage(e,r),this);terminate=()=>(this.worker.terminate(),this);waitForCompletion=()=>this.isTerminated?this.status===0?b(this):w(v("Job has failed")):y.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("JOB_TERMINATED",()=>{this.status===0&&e(this)})}),e=>v(e));dispatchEvent=(e,r)=>{this.events.emit(e,r)}};var I=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,u=0;for(;f>4,n[f++]=(o&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var rr=new I("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");var ft=new I("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function se(t){return ft.Encode(t)}var fe=te(Se());var k=class extends D{};var M=class extends k{message="Unable to decrypt the provided data"};var Ue=()=>{try{return b(fe.default.codec.base64.fromBits(fe.default.random.randomWords(8,10)))}catch(t){return w(new k("Unable to generate a random key",{cause:v(t)}))}};var Me=()=>y.fromPromise(new Promise(t=>crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]).then(e=>crypto.subtle.exportKey("raw",e).then(r=>t(se(r))).catch(r=>w(new M(void 0,{cause:v(r)})))).catch(e=>w(new M(void 0,{cause:v(e)})))),t=>new k("Unable to base64 encode the url",{cause:v(t)}));var Be=(t=1)=>t===0?Ue():Me();var X=class extends D{message="An error occured while dealing with a file"};var Q=class extends X{message="An error occured while operating on a file"};var Z=class extends Q{message="An error occured while slicing a file"};var dt=15e5,P={},mt=new je.default,yt=t=>{t.terminate();let e=new _(t.lufiFile);return y.fromPromise(new Promise((r,n)=>{e.onMessage(i=>{i.data.event==="UPLOAD_CANCELLED"&&(P[e.lufiFile.keys.client].uploadStatus=0,r(e)),i.data.event==="OPERATION_FAILED"&&n(i.data.error)}).requestMessage({action:0,args:{lufiFile:e.lufiFile}})}),r=>v(r))},gt=(t,e)=>{let r;return e?r=oe(t).andThen(n=>n.version.tag>"0.07.0"?y.fromPromise($(e).then(i=>x.fromDownloadUrl(t,i)),i=>v(i)):b(x.fromDownloadUrl(t,e))):r=b(x.fromDownloadUrl(t)),r.andThen(n=>{let i=new _(n);return y.fromPromise(new Promise((o,s)=>i.onMessage(a=>{Ne(o,s,i,a),a.data.event==="CHUNK_DOWNLOADED"&&(i.tmpChunks[a.data.chunk.index]=new Blob([a.data.chunk.buffer])),a.data.event==="DOWNLOAD_COMPLETE"&&(i.tmpFile=new Blob(i.tmpChunks,{type:n.type}),i.tmpChunks=[],i.complete())}).requestMessage({action:1,args:{lufiFile:n}})),o=>v(o))})},vt=(t,e)=>{let r;return e?r=oe(t).andThen(n=>n.version.tag>"0.07.0"?y.fromPromise($(e).then(i=>x.fromDownloadUrl(t,i)),i=>v(i)):b(x.fromDownloadUrl(t,e))):r=b(x.fromDownloadUrl(t)),r.andThen(n=>b(new _(n))).andThen(n=>y.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="INFOS_RETRIEVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(s.data.error)}).requestMessage({action:2,args:{lufiFile:n.lufiFile}})}),i=>v(i)))},wt=(t,e)=>{let r=x.fromRemoveUrl(t,e),n=new _(r);return y.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="FILE_REMOVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(s.data.error)}).requestMessage({action:4,args:{lufiFile:r}})}),i=>v(i))},Et=(t,e,r=dt)=>{let n=Math.ceil(t.size/r);if(P[e].totalChunks=n,n>0){let i=[];for(let o=0;oBe().andThen(s=>y.fromPromise($(o).then(a=>(P[s]=new x(t.toString(),{delay:r,delAtFirstView:n,zipped:i,password:a,name:e.name,size:e.size,type:e.type,keys:{client:s,server:""}}),s)),a=>v(a))).andThen(s=>{let a=new _(P[s]);return Et(e,s).asyncAndThen(f=>{P[s].uploadStatus=4;let u=new Promise((h,p)=>{a.onMessage(d=>{switch(Ne(h,p,a,d),d.data.event){case"UPLOAD_COMPLETE":a.complete(),a.lufiFile.uploadStatus=1;break}})}),l=async h=>{for(let[p,d]of h.entries()){let g=await d.arrayBuffer();a.requestMessage({action:5,args:{chunk:{buffer:g,index:p},lufiFile:P[s]}},[g])}};return y.fromSafePromise(l(f)).andThen(()=>y.fromPromise(u,h=>v(h)))}).orElse(f=>w(f))}),Ne=(t,e,r,n)=>{n.data.event==="SOCKET_OPENED"&&t(r),n.data.event==="OPERATION_FAILED"&&e(n.data.error)},At=()=>Object.values(P).filter(t=>t.uploadStatus===4),bt=t=>Object.keys(At()).indexOf(t);export{A as err,w as errAsync,Fe as lufi,O as ok,b as okAsync};