From 51f3181b4ab0a60f77279f1e6a9ba4ecec0ac9cf Mon Sep 17 00:00:00 2001 From: Booteille Date: Tue, 12 Nov 2024 13:34:50 +0100 Subject: [PATCH] Update lufi to only use Lufi API --- .gitignore | 4 + .../ansible-role-lufi/templates/lufi.conf.j2 | 2 +- CHANGELOG | 4 + README.md | 0 lib/Lufi/Plugin/Headers.pm | 2 +- lufi-provisioning.lock | 0 lufi.conf.template | 2 +- themes/default/public/js/jszip.min.js | 6262 ++++++++++++++++- themes/default/public/js/lufi-common.js | 45 +- themes/default/public/js/lufi-down.js | 110 +- themes/default/public/js/lufi-files.js | 506 +- themes/default/public/js/lufi-up.js | 377 +- themes/default/public/js/lufi.js | 3548 +++++++++- themes/default/public/js/sidenav.js | 4 +- themes/default/public/js/worker/cancel.js | 2112 +++++- themes/default/public/js/worker/download.js | 2805 +++++++- themes/default/public/js/worker/encrypt.js | 1880 ++++- themes/default/public/js/worker/infos.js | 2109 +++++- themes/default/public/js/worker/main.js | 935 ++- themes/default/public/js/worker/remove.js | 930 ++- themes/default/public/js/worker/upload.js | 2861 +++++++- themes/default/templates/partial/files.js.ep | 10 +- 22 files changed, 24038 insertions(+), 470 deletions(-) mode change 100644 => 100755 README.md create mode 100644 lufi-provisioning.lock diff --git a/.gitignore b/.gitignore index f8d4701..3c87138 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ stop-upload themes/* !themes/default !themes/default/* +.stignore +.stfolder/ +TODO + diff --git a/.provision/ansible-role-lufi/templates/lufi.conf.j2 b/.provision/ansible-role-lufi/templates/lufi.conf.j2 index 9b9ee5f..7cdce96 100644 --- a/.provision/ansible-role-lufi/templates/lufi.conf.j2 +++ b/.provision/ansible-role-lufi/templates/lufi.conf.j2 @@ -307,7 +307,7 @@ # Set to '' to disable CSP header # https://content-security-policy.com/ provides a good documentation about CSP. # https://report-uri.com/home/generate provides a tool to generate a CSP header. - # optional, default is "base-uri 'self'; connect-src 'self' ws://YOUR_HOST; default-src 'none'; font-src 'self'; form-action 'self'; frame-ancestors 'none'; img-src 'self' blob:; media-src blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'" + # optional, default is "base-uri 'self'; connect-src 'self' ws://YOUR_HOST; default-src 'none'; font-src 'self'; form-action 'self'; frame-ancestors 'none'; img-src 'self' blob:; media-src blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'" #csp => "", # X-Frame-Options header that will be sent by Lufi diff --git a/CHANGELOG b/CHANGELOG index 9605258..7ecf9f7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ Revision history for Lufi 0.08.0 ????-??-?? + - Use Lufi API + - Password encryption is now done client side, through Lufi API + - Update default CSP to allow "blob:" + 0.07.0 2023-12-25 - ⬆️ — Update jQuery diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/lib/Lufi/Plugin/Headers.pm b/lib/Lufi/Plugin/Headers.pm index 55aba11..99c336e 100644 --- a/lib/Lufi/Plugin/Headers.pm +++ b/lib/Lufi/Plugin/Headers.pm @@ -11,7 +11,7 @@ sub register { if (!defined($app->config('csp')) || (defined($app->config('csp')) && $app->config('csp') ne '')) { my $directives = { 'default-src' => "'none'", - 'script-src' => "'self' 'unsafe-inline' 'unsafe-eval'", + 'script-src' => "'self' 'unsafe-inline' 'unsafe-eval' blob:", 'style-src' => "'self' 'unsafe-inline'", 'img-src' => "'self' blob:", 'media-src' => "blob:", diff --git a/lufi-provisioning.lock b/lufi-provisioning.lock new file mode 100644 index 0000000..e69de29 diff --git a/lufi.conf.template b/lufi.conf.template index a9f43b7..0f4d83c 100644 --- a/lufi.conf.template +++ b/lufi.conf.template @@ -337,7 +337,7 @@ # Set to '' to disable CSP header # https://content-security-policy.com/ provides a good documentation about CSP. # https://report-uri.com/home/generate provides a tool to generate a CSP header. - # optional, default is "base-uri 'self'; connect-src 'self' ws://YOUR_HOST; default-src 'none'; font-src 'self'; form-action 'self'; frame-ancestors 'none'; img-src 'self' blob:; media-src blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'" + # optional, default is "base-uri 'self'; connect-src 'self' ws://YOUR_HOST; default-src 'none'; font-src 'self'; form-action 'self'; frame-ancestors 'none'; img-src 'self' blob:; media-src blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'" #csp => "", # X-Frame-Options header that will be sent by Lufi diff --git a/themes/default/public/js/jszip.min.js b/themes/default/public/js/jszip.min.js index 7e2110b..5e9e95f 100644 --- a/themes/default/public/js/jszip.min.js +++ b/themes/default/public/js/jszip.min.js @@ -9,7 +9,6261 @@ Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/js JSZip uses the library pako released under the MIT license : https://github.com/nodeca/pako/blob/master/LICENSE */ -!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.JSZip=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g>2,h=(3&b)<<4|c>>4,i=n>1?(15&c)<<2|e>>6:64,j=n>2?63&e:64,k.push(f.charAt(g)+f.charAt(h)+f.charAt(i)+f.charAt(j));return k.join("")},c.decode=function(a){var b,c,d,g,h,i,j,k=0,l=0,m="data:";if(a.substr(0,m.length)===m)throw new Error("Invalid base64 input, it looks like a data url.");a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");var n=3*a.length/4;if(a.charAt(a.length-1)===f.charAt(64)&&n--,a.charAt(a.length-2)===f.charAt(64)&&n--,n%1!==0)throw new Error("Invalid base64 input, bad content length.");var o;for(o=e.uint8array?new Uint8Array(0|n):new Array(0|n);k>4,c=(15&h)<<4|i>>2,d=(3&i)<<6|j,o[l++]=b,64!==i&&(o[l++]=c),64!==j&&(o[l++]=d);return o}},{"./support":30,"./utils":32}],2:[function(a,b,c){"use strict";function d(a,b,c,d,e){this.compressedSize=a,this.uncompressedSize=b,this.crc32=c,this.compression=d,this.compressedContent=e}var e=a("./external"),f=a("./stream/DataWorker"),g=a("./stream/DataLengthProbe"),h=a("./stream/Crc32Probe"),g=a("./stream/DataLengthProbe");d.prototype={getContentWorker:function(){var a=new f(e.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new g("data_length")),b=this;return a.on("end",function(){if(this.streamInfo.data_length!==b.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),a},getCompressedWorker:function(){return new f(e.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},d.createWorkerFrom=function(a,b,c){return a.pipe(new h).pipe(new g("uncompressedSize")).pipe(b.compressWorker(c)).pipe(new g("compressedSize")).withStreamInfo("compression",b)},b.exports=d},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(a,b,c){"use strict";var d=a("./stream/GenericWorker");c.STORE={magic:"\0\0",compressWorker:function(a){return new d("STORE compression")},uncompressWorker:function(){return new d("STORE decompression")}},c.DEFLATE=a("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(a,b,c){"use strict";function d(){for(var a,b=[],c=0;c<256;c++){a=c;for(var d=0;d<8;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}function e(a,b,c,d){var e=h,f=d+c;a^=-1;for(var g=d;g>>8^e[255&(a^b[g])];return a^-1}function f(a,b,c,d){var e=h,f=d+c;a^=-1;for(var g=d;g>>8^e[255&(a^b.charCodeAt(g))];return a^-1}var g=a("./utils"),h=d();b.exports=function(a,b){if("undefined"==typeof a||!a.length)return 0;var c="string"!==g.getTypeOf(a);return c?e(0|b,a,a.length,0):f(0|b,a,a.length,0)}},{"./utils":32}],5:[function(a,b,c){"use strict";c.base64=!1,c.binary=!1,c.dir=!1,c.createFolders=!0,c.date=null,c.compression=null,c.compressionOptions=null,c.comment=null,c.unixPermissions=null,c.dosPermissions=null},{}],6:[function(a,b,c){"use strict";var d=null;d="undefined"!=typeof Promise?Promise:a("lie"),b.exports={Promise:d}},{lie:37}],7:[function(a,b,c){"use strict";function d(a,b){h.call(this,"FlateWorker/"+a),this._pako=null,this._pakoAction=a,this._pakoOptions=b,this.meta={}}var e="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,f=a("pako"),g=a("./utils"),h=a("./stream/GenericWorker"),i=e?"uint8array":"array";c.magic="\b\0",g.inherits(d,h),d.prototype.processChunk=function(a){this.meta=a.meta,null===this._pako&&this._createPako(),this._pako.push(g.transformTo(i,a.data),!1)},d.prototype.flush=function(){h.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},d.prototype.cleanUp=function(){h.prototype.cleanUp.call(this),this._pako=null},d.prototype._createPako=function(){this._pako=new f[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var a=this;this._pako.onData=function(b){a.push({data:b,meta:a.meta})}},c.compressWorker=function(a){return new d("Deflate",a)},c.uncompressWorker=function(){return new d("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(a,b,c){"use strict";function d(a,b,c,d){f.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=b,this.zipPlatform=c,this.encodeFileName=d,this.streamFiles=a,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}var e=a("../utils"),f=a("../stream/GenericWorker"),g=a("../utf8"),h=a("../crc32"),i=a("../signature"),j=function(a,b){var c,d="";for(c=0;c>>=8;return d},k=function(a,b){var c=a;return a||(c=b?16893:33204),(65535&c)<<16},l=function(a,b){return 63&(a||0)},m=function(a,b,c,d,f,m){var n,o,p=a.file,q=a.compression,r=m!==g.utf8encode,s=e.transformTo("string",m(p.name)),t=e.transformTo("string",g.utf8encode(p.name)),u=p.comment,v=e.transformTo("string",m(u)),w=e.transformTo("string",g.utf8encode(u)),x=t.length!==p.name.length,y=w.length!==u.length,z="",A="",B="",C=p.dir,D=p.date,E={crc32:0,compressedSize:0,uncompressedSize:0};b&&!c||(E.crc32=a.crc32,E.compressedSize=a.compressedSize,E.uncompressedSize=a.uncompressedSize);var F=0;b&&(F|=8),r||!x&&!y||(F|=2048);var G=0,H=0;C&&(G|=16),"UNIX"===f?(H=798,G|=k(p.unixPermissions,C)):(H=20,G|=l(p.dosPermissions,C)),n=D.getUTCHours(),n<<=6,n|=D.getUTCMinutes(),n<<=5,n|=D.getUTCSeconds()/2,o=D.getUTCFullYear()-1980,o<<=4,o|=D.getUTCMonth()+1,o<<=5,o|=D.getUTCDate(),x&&(A=j(1,1)+j(h(s),4)+t,z+="up"+j(A.length,2)+A),y&&(B=j(1,1)+j(h(v),4)+w,z+="uc"+j(B.length,2)+B);var I="";I+="\n\0",I+=j(F,2),I+=q.magic,I+=j(n,2),I+=j(o,2),I+=j(E.crc32,4),I+=j(E.compressedSize,4),I+=j(E.uncompressedSize,4),I+=j(s.length,2),I+=j(z.length,2);var J=i.LOCAL_FILE_HEADER+I+s+z,K=i.CENTRAL_FILE_HEADER+j(H,2)+I+j(v.length,2)+"\0\0\0\0"+j(G,4)+j(d,4)+s+z+v;return{fileRecord:J,dirRecord:K}},n=function(a,b,c,d,f){var g="",h=e.transformTo("string",f(d));return g=i.CENTRAL_DIRECTORY_END+"\0\0\0\0"+j(a,2)+j(a,2)+j(b,4)+j(c,4)+j(h.length,2)+h},o=function(a){var b="";return b=i.DATA_DESCRIPTOR+j(a.crc32,4)+j(a.compressedSize,4)+j(a.uncompressedSize,4)};e.inherits(d,f),d.prototype.push=function(a){var b=a.meta.percent||0,c=this.entriesCount,d=this._sources.length;this.accumulate?this.contentBuffer.push(a):(this.bytesWritten+=a.data.length,f.prototype.push.call(this,{data:a.data,meta:{currentFile:this.currentFile,percent:c?(b+100*(c-d-1))/c:100}}))},d.prototype.openedSource=function(a){this.currentSourceOffset=this.bytesWritten,this.currentFile=a.file.name;var b=this.streamFiles&&!a.file.dir;if(b){var c=m(a,b,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:c.fileRecord,meta:{percent:0}})}else this.accumulate=!0},d.prototype.closedSource=function(a){this.accumulate=!1;var b=this.streamFiles&&!a.file.dir,c=m(a,b,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(c.dirRecord),b)this.push({data:o(a),meta:{percent:100}});else for(this.push({data:c.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},d.prototype.flush=function(){for(var a=this.bytesWritten,b=0;b0?a.substring(0,b):""},q=function(a){return"/"!==a.slice(-1)&&(a+="/"),a},r=function(a,b){return b="undefined"!=typeof b?b:i.createFolders,a=q(a),this.files[a]||o.call(this,a,null,{dir:!0,createFolders:b}),this.files[a]},s={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(a){var b,c,d;for(b in this.files)this.files.hasOwnProperty(b)&&(d=this.files[b],c=b.slice(this.root.length,b.length),c&&b.slice(0,this.root.length)===this.root&&a(c,d))},filter:function(a){var b=[];return this.forEach(function(c,d){a(c,d)&&b.push(d)}),b},file:function(a,b,c){if(1===arguments.length){if(d(a)){var e=a;return this.filter(function(a,b){return!b.dir&&e.test(a)})}var f=this.files[this.root+a];return f&&!f.dir?f:null}return a=this.root+a,o.call(this,a,b,c),this},folder:function(a){if(!a)return this;if(d(a))return this.filter(function(b,c){return c.dir&&a.test(b)});var b=this.root+a,c=r.call(this,b),e=this.clone();return e.root=c.name,e},remove:function(a){a=this.root+a;var b=this.files[a];if(b||("/"!==a.slice(-1)&&(a+="/"),b=this.files[a]),b&&!b.dir)delete this.files[a];else for(var c=this.filter(function(b,c){return c.name.slice(0,a.length)===a}),d=0;d=0;--f)if(this.data[f]===b&&this.data[f+1]===c&&this.data[f+2]===d&&this.data[f+3]===e)return f-this.zero;return-1},d.prototype.readAndCheckSignature=function(a){var b=a.charCodeAt(0),c=a.charCodeAt(1),d=a.charCodeAt(2),e=a.charCodeAt(3),f=this.readData(4);return b===f[0]&&c===f[1]&&d===f[2]&&e===f[3]},d.prototype.readData=function(a){if(this.checkOffset(a),0===a)return[];var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./DataReader":18}],18:[function(a,b,c){"use strict";function d(a){this.data=a,this.length=a.length,this.index=0,this.zero=0}var e=a("../utils");d.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length=this.index;b--)c=(c<<8)+this.byteAt(b);return this.index+=a,c},readString:function(a){return e.transformTo("string",this.readData(a))},readData:function(a){},lastIndexOfSignature:function(a){},readAndCheckSignature:function(a){},readDate:function(){var a=this.readInt(4);return new Date(Date.UTC((a>>25&127)+1980,(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1))}},b.exports=d},{"../utils":32}],19:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./Uint8ArrayReader"),f=a("../utils");f.inherits(d,e),d.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./DataReader"),f=a("../utils");f.inherits(d,e),d.prototype.byteAt=function(a){return this.data.charCodeAt(this.zero+a)},d.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)-this.zero},d.prototype.readAndCheckSignature=function(a){var b=this.readData(4);return a===b},d.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./DataReader":18}],21:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./ArrayReader"),f=a("../utils");f.inherits(d,e),d.prototype.readData=function(a){if(this.checkOffset(a),0===a)return new Uint8Array(0);var b=this.data.subarray(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./ArrayReader":17}],22:[function(a,b,c){"use strict";var d=a("../utils"),e=a("../support"),f=a("./ArrayReader"),g=a("./StringReader"),h=a("./NodeBufferReader"),i=a("./Uint8ArrayReader");b.exports=function(a){var b=d.getTypeOf(a);return d.checkSupport(b),"string"!==b||e.uint8array?"nodebuffer"===b?new h(a):e.uint8array?new i(d.transformTo("uint8array",a)):new f(d.transformTo("array",a)):new g(a)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(a,b,c){"use strict";c.LOCAL_FILE_HEADER="PK",c.CENTRAL_FILE_HEADER="PK",c.CENTRAL_DIRECTORY_END="PK",c.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",c.ZIP64_CENTRAL_DIRECTORY_END="PK",c.DATA_DESCRIPTOR="PK\b"},{}],24:[function(a,b,c){"use strict";function d(a){e.call(this,"ConvertWorker to "+a),this.destType=a}var e=a("./GenericWorker"),f=a("../utils");f.inherits(d,e),d.prototype.processChunk=function(a){this.push({data:f.transformTo(this.destType,a.data),meta:a.meta})},b.exports=d},{"../utils":32,"./GenericWorker":28}],25:[function(a,b,c){"use strict";function d(){e.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}var e=a("./GenericWorker"),f=a("../crc32"),g=a("../utils");g.inherits(d,e),d.prototype.processChunk=function(a){this.streamInfo.crc32=f(a.data,this.streamInfo.crc32||0),this.push(a)},b.exports=d},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(a,b,c){"use strict";function d(a){f.call(this,"DataLengthProbe for "+a),this.propName=a,this.withStreamInfo(a,0)}var e=a("../utils"),f=a("./GenericWorker");e.inherits(d,f),d.prototype.processChunk=function(a){if(a){var b=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=b+a.data.length}f.prototype.processChunk.call(this,a)},b.exports=d},{"../utils":32,"./GenericWorker":28}],27:[function(a,b,c){"use strict";function d(a){f.call(this,"DataWorker");var b=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,a.then(function(a){b.dataIsReady=!0,b.data=a,b.max=a&&a.length||0,b.type=e.getTypeOf(a),b.isPaused||b._tickAndRepeat()},function(a){b.error(a)})}var e=a("../utils"),f=a("./GenericWorker"),g=16384;e.inherits(d,f),d.prototype.cleanUp=function(){f.prototype.cleanUp.call(this),this.data=null},d.prototype.resume=function(){return!!f.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,e.delay(this._tickAndRepeat,[],this)),!0)},d.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(e.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},d.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var a=g,b=null,c=Math.min(this.max,this.index+a);if(this.index>=this.max)return this.end();switch(this.type){case"string":b=this.data.substring(this.index,c);break;case"uint8array":b=this.data.subarray(this.index,c);break;case"array":case"nodebuffer":b=this.data.slice(this.index,c)}return this.index=c,this.push({data:b,meta:{percent:this.max?this.index/this.max*100:0}})},b.exports=d},{"../utils":32,"./GenericWorker":28}],28:[function(a,b,c){"use strict";function d(a){this.name=a||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}d.prototype={push:function(a){this.emit("data",a)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(a){this.emit("error",a)}return!0},error:function(a){return!this.isFinished&&(this.isPaused?this.generatedError=a:(this.isFinished=!0,this.emit("error",a),this.previous&&this.previous.error(a),this.cleanUp()),!0)},on:function(a,b){return this._listeners[a].push(b),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,b){if(this._listeners[a])for(var c=0;c "+a:a}},b.exports=d},{}],29:[function(a,b,c){"use strict";function d(a,b,c){switch(a){case"blob":return h.newBlob(h.transformTo("arraybuffer",b),c);case"base64":return k.encode(b);default:return h.transformTo(a,b)}}function e(a,b){var c,d=0,e=null,f=0;for(c=0;c=252?6:k>=248?5:k>=240?4:k>=224?3:k>=192?2:1;j[254]=j[254]=1;var l=function(a){var b,c,d,e,f,h=a.length,i=0;for(e=0;e>>6,b[f++]=128|63&c):c<65536?(b[f++]=224|c>>>12,b[f++]=128|c>>>6&63,b[f++]=128|63&c):(b[f++]=240|c>>>18,b[f++]=128|c>>>12&63,b[f++]=128|c>>>6&63,b[f++]=128|63&c);return b},m=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return c<0?b:0===c?b:c+j[a[c]]>b?c:b},n=function(a){var b,c,d,e,g=a.length,h=new Array(2*g);for(c=0,b=0;b4)h[c++]=65533,b+=e-1;else{for(d&=2===e?31:3===e?15:7;e>1&&b1?h[c++]=65533:d<65536?h[c++]=d:(d-=65536,h[c++]=55296|d>>10&1023,h[c++]=56320|1023&d)}return h.length!==c&&(h.subarray?h=h.subarray(0,c):h.length=c),f.applyFromCharCode(h)};c.utf8encode=function(a){return g.nodebuffer?h.newBufferFrom(a,"utf-8"):l(a)},c.utf8decode=function(a){return g.nodebuffer?f.transformTo("nodebuffer",a).toString("utf-8"):(a=f.transformTo(g.uint8array?"uint8array":"array",a),n(a))},f.inherits(d,i),d.prototype.processChunk=function(a){var b=f.transformTo(g.uint8array?"uint8array":"array",a.data);if(this.leftOver&&this.leftOver.length){if(g.uint8array){var d=b;b=new Uint8Array(d.length+this.leftOver.length),b.set(this.leftOver,0),b.set(d,this.leftOver.length)}else b=this.leftOver.concat(b);this.leftOver=null}var e=m(b),h=b;e!==b.length&&(g.uint8array?(h=b.subarray(0,e),this.leftOver=b.subarray(e,b.length)):(h=b.slice(0,e),this.leftOver=b.slice(e,b.length))),this.push({data:c.utf8decode(h),meta:a.meta})},d.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:c.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},c.Utf8DecodeWorker=d,f.inherits(e,i),e.prototype.processChunk=function(a){this.push({data:c.utf8encode(a.data),meta:a.meta})},c.Utf8EncodeWorker=e},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(a,b,c){"use strict";function d(a){var b=null;return b=i.uint8array?new Uint8Array(a.length):new Array(a.length),f(a,b)}function e(a){return a}function f(a,b){for(var c=0;c1;)try{return n.stringifyByChunk(a,d,b)}catch(f){b=Math.floor(b/2)}return n.stringifyByChar(a)}function h(a,b){for(var c=0;c1)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var a,b;for(a=0;a0)this.isSignature(c,g.CENTRAL_FILE_HEADER)||(this.reader.zero=e);else if(e<0)throw new Error("Corrupted zip: missing "+Math.abs(e)+" bytes.")},prepareReader:function(a){this.reader=e(a)},load:function(a){this.prepareReader(a),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},b.exports=d},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utf8":31,"./utils":32,"./zipEntry":34}],34:[function(a,b,c){"use strict";function d(a,b){this.options=a,this.loadOptions=b}var e=a("./reader/readerFor"),f=a("./utils"),g=a("./compressedObject"),h=a("./crc32"),i=a("./utf8"),j=a("./compressions"),k=a("./support"),l=0,m=3,n=function(a){for(var b in j)if(j.hasOwnProperty(b)&&j[b].magic===a)return j[b];return null};d.prototype={isEncrypted:function(){return 1===(1&this.bitFlag)},useUTF8:function(){return 2048===(2048&this.bitFlag)},readLocalPart:function(a){var b,c;if(a.skip(22),this.fileNameLength=a.readInt(2),c=a.readInt(2),this.fileName=a.readData(this.fileNameLength),a.skip(c),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize === -1 || uncompressedSize === -1)");if(b=n(this.compressionMethod),null===b)throw new Error("Corrupted zip : compression "+f.pretty(this.compressionMethod)+" unknown (inner file : "+f.transformTo("string",this.fileName)+")");this.decompressed=new g(this.compressedSize,this.uncompressedSize,this.crc32,b,a.readData(this.compressedSize))},readCentralPart:function(a){this.versionMadeBy=a.readInt(2),a.skip(2),this.bitFlag=a.readInt(2),this.compressionMethod=a.readString(2),this.date=a.readDate(),this.crc32=a.readInt(4),this.compressedSize=a.readInt(4),this.uncompressedSize=a.readInt(4);var b=a.readInt(2);if(this.extraFieldsLength=a.readInt(2),this.fileCommentLength=a.readInt(2),this.diskNumberStart=a.readInt(2),this.internalFileAttributes=a.readInt(2),this.externalFileAttributes=a.readInt(4),this.localHeaderOffset=a.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");a.skip(b),this.readExtraFields(a),this.parseZIP64ExtraField(a),this.fileComment=a.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var a=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),a===l&&(this.dosPermissions=63&this.externalFileAttributes),a===m&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(a){if(this.extraFields[1]){var b=e(this.extraFields[1].value);this.uncompressedSize===f.MAX_VALUE_32BITS&&(this.uncompressedSize=b.readInt(8)),this.compressedSize===f.MAX_VALUE_32BITS&&(this.compressedSize=b.readInt(8)),this.localHeaderOffset===f.MAX_VALUE_32BITS&&(this.localHeaderOffset=b.readInt(8)),this.diskNumberStart===f.MAX_VALUE_32BITS&&(this.diskNumberStart=b.readInt(4))}},readExtraFields:function(a){var b,c,d,e=a.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});a.index0?b.windowBits=-b.windowBits:b.gzip&&b.windowBits>0&&b.windowBits<16&&(b.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var c=h.deflateInit2(this.strm,b.level,b.method,b.windowBits,b.memLevel,b.strategy);if(c!==p)throw new Error(k[c]);if(b.header&&h.deflateSetHeader(this.strm,b.header),b.dictionary){var e;if(e="string"==typeof b.dictionary?j.string2buf(b.dictionary):"[object ArrayBuffer]"===m.call(b.dictionary)?new Uint8Array(b.dictionary):b.dictionary,c=h.deflateSetDictionary(this.strm,e),c!==p)throw new Error(k[c]);this._dict_set=!0}}function e(a,b){var c=new d(b);if(c.push(a,!0),c.err)throw c.msg||k[c.err];return c.result}function f(a,b){return b=b||{},b.raw=!0,e(a,b)}function g(a,b){return b=b||{},b.gzip=!0,e(a,b)}var h=a("./zlib/deflate"),i=a("./utils/common"),j=a("./utils/strings"),k=a("./zlib/messages"),l=a("./zlib/zstream"),m=Object.prototype.toString,n=0,o=4,p=0,q=1,r=2,s=-1,t=0,u=8;d.prototype.push=function(a,b){var c,d,e=this.strm,f=this.options.chunkSize;if(this.ended)return!1;d=b===~~b?b:b===!0?o:n,"string"==typeof a?e.input=j.string2buf(a):"[object ArrayBuffer]"===m.call(a)?e.input=new Uint8Array(a):e.input=a,e.next_in=0,e.avail_in=e.input.length;do{if(0===e.avail_out&&(e.output=new i.Buf8(f),e.next_out=0,e.avail_out=f),c=h.deflate(e,d),c!==q&&c!==p)return this.onEnd(c),this.ended=!0,!1;0!==e.avail_out&&(0!==e.avail_in||d!==o&&d!==r)||("string"===this.options.to?this.onData(j.buf2binstring(i.shrinkBuf(e.output,e.next_out))):this.onData(i.shrinkBuf(e.output,e.next_out)))}while((e.avail_in>0||0===e.avail_out)&&c!==q);return d===o?(c=h.deflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===p):d!==r||(this.onEnd(p),e.avail_out=0,!0)},d.prototype.onData=function(a){this.chunks.push(a)},d.prototype.onEnd=function(a){a===p&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=i.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Deflate=d,c.deflate=e,c.deflateRaw=f,c.gzip=g},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(a,b,c){"use strict";function d(a){if(!(this instanceof d))return new d(a);this.options=h.assign({chunkSize:16384,windowBits:0,to:""},a||{});var b=this.options;b.raw&&b.windowBits>=0&&b.windowBits<16&&(b.windowBits=-b.windowBits,0===b.windowBits&&(b.windowBits=-15)),!(b.windowBits>=0&&b.windowBits<16)||a&&a.windowBits||(b.windowBits+=32),b.windowBits>15&&b.windowBits<48&&0===(15&b.windowBits)&&(b.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var c=g.inflateInit2(this.strm,b.windowBits);if(c!==j.Z_OK)throw new Error(k[c]);this.header=new m,g.inflateGetHeader(this.strm,this.header)}function e(a,b){var c=new d(b);if(c.push(a,!0),c.err)throw c.msg||k[c.err];return c.result}function f(a,b){return b=b||{},b.raw=!0,e(a,b)}var g=a("./zlib/inflate"),h=a("./utils/common"),i=a("./utils/strings"),j=a("./zlib/constants"),k=a("./zlib/messages"),l=a("./zlib/zstream"),m=a("./zlib/gzheader"),n=Object.prototype.toString;d.prototype.push=function(a,b){var c,d,e,f,k,l,m=this.strm,o=this.options.chunkSize,p=this.options.dictionary,q=!1;if(this.ended)return!1;d=b===~~b?b:b===!0?j.Z_FINISH:j.Z_NO_FLUSH,"string"==typeof a?m.input=i.binstring2buf(a):"[object ArrayBuffer]"===n.call(a)?m.input=new Uint8Array(a):m.input=a,m.next_in=0,m.avail_in=m.input.length;do{if(0===m.avail_out&&(m.output=new h.Buf8(o),m.next_out=0,m.avail_out=o),c=g.inflate(m,j.Z_NO_FLUSH),c===j.Z_NEED_DICT&&p&&(l="string"==typeof p?i.string2buf(p):"[object ArrayBuffer]"===n.call(p)?new Uint8Array(p):p,c=g.inflateSetDictionary(this.strm,l)),c===j.Z_BUF_ERROR&&q===!0&&(c=j.Z_OK,q=!1),c!==j.Z_STREAM_END&&c!==j.Z_OK)return this.onEnd(c),this.ended=!0,!1;m.next_out&&(0!==m.avail_out&&c!==j.Z_STREAM_END&&(0!==m.avail_in||d!==j.Z_FINISH&&d!==j.Z_SYNC_FLUSH)||("string"===this.options.to?(e=i.utf8border(m.output,m.next_out),f=m.next_out-e,k=i.buf2string(m.output,e),m.next_out=f,m.avail_out=o-f,f&&h.arraySet(m.output,m.output,e,f,0),this.onData(k)):this.onData(h.shrinkBuf(m.output,m.next_out)))),0===m.avail_in&&0===m.avail_out&&(q=!0)}while((m.avail_in>0||0===m.avail_out)&&c!==j.Z_STREAM_END);return c===j.Z_STREAM_END&&(d=j.Z_FINISH),d===j.Z_FINISH?(c=g.inflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===j.Z_OK):d!==j.Z_SYNC_FLUSH||(this.onEnd(j.Z_OK),m.avail_out=0,!0)},d.prototype.onData=function(a){this.chunks.push(a)},d.prototype.onEnd=function(a){a===j.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=h.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Inflate=d,c.inflate=e,c.inflateRaw=f,c.ungzip=e},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;c.assign=function(a){for(var b=Array.prototype.slice.call(arguments,1);b.length;){var c=b.shift();if(c){if("object"!=typeof c)throw new TypeError(c+"must be non-object");for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}}return a},c.shrinkBuf=function(a,b){return a.length===b?a:a.subarray?a.subarray(0,b):(a.length=b,a)};var e={arraySet:function(a,b,c,d,e){if(b.subarray&&a.subarray)return void a.set(b.subarray(c,c+d),e);for(var f=0;f=252?6:j>=248?5:j>=240?4:j>=224?3:j>=192?2:1;i[254]=i[254]=1,c.string2buf=function(a){var b,c,d,f,g,h=a.length,i=0;for(f=0;f>>6,b[g++]=128|63&c):c<65536?(b[g++]=224|c>>>12,b[g++]=128|c>>>6&63,b[g++]=128|63&c):(b[g++]=240|c>>>18,b[g++]=128|c>>>12&63,b[g++]=128|c>>>6&63,b[g++]=128|63&c);return b},c.buf2binstring=function(a){return d(a,a.length)},c.binstring2buf=function(a){for(var b=new e.Buf8(a.length),c=0,d=b.length;c4)j[e++]=65533,c+=g-1;else{for(f&=2===g?31:3===g?15:7;g>1&&c1?j[e++]=65533:f<65536?j[e++]=f:(f-=65536,j[e++]=55296|f>>10&1023,j[e++]=56320|1023&f)}return d(j,e)},c.utf8border=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return c<0?b:0===c?b:c+i[a[c]]>b?c:b}},{"./common":41}],43:[function(a,b,c){"use strict";function d(a,b,c,d){for(var e=65535&a|0,f=a>>>16&65535|0,g=0;0!==c;){g=c>2e3?2e3:c,c-=g;do e=e+b[d++]|0,f=f+e|0;while(--g);e%=65521,f%=65521}return e|f<<16|0}b.exports=d},{}],44:[function(a,b,c){"use strict";b.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(a,b,c){"use strict";function d(){for(var a,b=[],c=0;c<256;c++){a=c;for(var d=0;d<8;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}function e(a,b,c,d){var e=f,g=d+c;a^=-1;for(var h=d;h>>8^e[255&(a^b[h])];return a^-1}var f=d();b.exports=e},{}],46:[function(a,b,c){"use strict";function d(a,b){return a.msg=I[b],b}function e(a){return(a<<1)-(a>4?9:0)}function f(a){for(var b=a.length;--b>=0;)a[b]=0}function g(a){var b=a.state,c=b.pending;c>a.avail_out&&(c=a.avail_out),0!==c&&(E.arraySet(a.output,b.pending_buf,b.pending_out,c,a.next_out),a.next_out+=c,b.pending_out+=c,a.total_out+=c,a.avail_out-=c,b.pending-=c,0===b.pending&&(b.pending_out=0))}function h(a,b){F._tr_flush_block(a,a.block_start>=0?a.block_start:-1,a.strstart-a.block_start,b),a.block_start=a.strstart,g(a.strm)}function i(a,b){a.pending_buf[a.pending++]=b}function j(a,b){a.pending_buf[a.pending++]=b>>>8&255,a.pending_buf[a.pending++]=255&b}function k(a,b,c,d){var e=a.avail_in;return e>d&&(e=d),0===e?0:(a.avail_in-=e,E.arraySet(b,a.input,a.next_in,e,c),1===a.state.wrap?a.adler=G(a.adler,b,e,c):2===a.state.wrap&&(a.adler=H(a.adler,b,e,c)),a.next_in+=e,a.total_in+=e,e)}function l(a,b){var c,d,e=a.max_chain_length,f=a.strstart,g=a.prev_length,h=a.nice_match,i=a.strstart>a.w_size-la?a.strstart-(a.w_size-la):0,j=a.window,k=a.w_mask,l=a.prev,m=a.strstart+ka,n=j[f+g-1],o=j[f+g];a.prev_length>=a.good_match&&(e>>=2),h>a.lookahead&&(h=a.lookahead);do if(c=b,j[c+g]===o&&j[c+g-1]===n&&j[c]===j[f]&&j[++c]===j[f+1]){f+=2,c++;do;while(j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&fg){if(a.match_start=b,g=d,d>=h)break;n=j[f+g-1],o=j[f+g]}}while((b=l[b&k])>i&&0!==--e);return g<=a.lookahead?g:a.lookahead}function m(a){var b,c,d,e,f,g=a.w_size;do{if(e=a.window_size-a.lookahead-a.strstart,a.strstart>=g+(g-la)){E.arraySet(a.window,a.window,g,g,0),a.match_start-=g,a.strstart-=g,a.block_start-=g,c=a.hash_size,b=c;do d=a.head[--b],a.head[b]=d>=g?d-g:0;while(--c);c=g,b=c;do d=a.prev[--b],a.prev[b]=d>=g?d-g:0;while(--c);e+=g}if(0===a.strm.avail_in)break;if(c=k(a.strm,a.window,a.strstart+a.lookahead,e),a.lookahead+=c,a.lookahead+a.insert>=ja)for(f=a.strstart-a.insert,a.ins_h=a.window[f],a.ins_h=(a.ins_h<a.pending_buf_size-5&&(c=a.pending_buf_size-5);;){if(a.lookahead<=1){if(m(a),0===a.lookahead&&b===J)return ua;if(0===a.lookahead)break}a.strstart+=a.lookahead,a.lookahead=0;var d=a.block_start+c;if((0===a.strstart||a.strstart>=d)&&(a.lookahead=a.strstart-d,a.strstart=d,h(a,!1),0===a.strm.avail_out))return ua;if(a.strstart-a.block_start>=a.w_size-la&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.strstart>a.block_start&&(h(a,!1),0===a.strm.avail_out)?ua:ua}function o(a,b){for(var c,d;;){if(a.lookahead=ja&&(a.ins_h=(a.ins_h<=ja)if(d=F._tr_tally(a,a.strstart-a.match_start,a.match_length-ja),a.lookahead-=a.match_length,a.match_length<=a.max_lazy_match&&a.lookahead>=ja){a.match_length--;do a.strstart++,a.ins_h=(a.ins_h<=ja&&(a.ins_h=(a.ins_h<4096)&&(a.match_length=ja-1)),a.prev_length>=ja&&a.match_length<=a.prev_length){e=a.strstart+a.lookahead-ja,d=F._tr_tally(a,a.strstart-1-a.prev_match,a.prev_length-ja),a.lookahead-=a.prev_length-1,a.prev_length-=2;do++a.strstart<=e&&(a.ins_h=(a.ins_h<=ja&&a.strstart>0&&(e=a.strstart-1,d=g[e],d===g[++e]&&d===g[++e]&&d===g[++e])){f=a.strstart+ka;do;while(d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&ea.lookahead&&(a.match_length=a.lookahead)}if(a.match_length>=ja?(c=F._tr_tally(a,1,a.match_length-ja),a.lookahead-=a.match_length,a.strstart+=a.match_length,a.match_length=0):(c=F._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++),c&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function r(a,b){for(var c;;){if(0===a.lookahead&&(m(a),0===a.lookahead)){if(b===J)return ua;break}if(a.match_length=0,c=F._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++,c&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function s(a,b,c,d,e){this.good_length=a,this.max_lazy=b,this.nice_length=c,this.max_chain=d,this.func=e}function t(a){a.window_size=2*a.w_size,f(a.head),a.max_lazy_match=D[a.level].max_lazy,a.good_match=D[a.level].good_length,a.nice_match=D[a.level].nice_length,a.max_chain_length=D[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=ja-1,a.match_available=0,a.ins_h=0}function u(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=$,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new E.Buf16(2*ha),this.dyn_dtree=new E.Buf16(2*(2*fa+1)),this.bl_tree=new E.Buf16(2*(2*ga+1)),f(this.dyn_ltree),f(this.dyn_dtree),f(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new E.Buf16(ia+1),this.heap=new E.Buf16(2*ea+1),f(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new E.Buf16(2*ea+1),f(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function v(a){var b;return a&&a.state?(a.total_in=a.total_out=0,a.data_type=Z,b=a.state,b.pending=0,b.pending_out=0,b.wrap<0&&(b.wrap=-b.wrap),b.status=b.wrap?na:sa,a.adler=2===b.wrap?0:1,b.last_flush=J,F._tr_init(b),O):d(a,Q)}function w(a){var b=v(a);return b===O&&t(a.state),b}function x(a,b){return a&&a.state?2!==a.state.wrap?Q:(a.state.gzhead=b,O):Q}function y(a,b,c,e,f,g){if(!a)return Q;var h=1;if(b===T&&(b=6),e<0?(h=0,e=-e):e>15&&(h=2,e-=16),f<1||f>_||c!==$||e<8||e>15||b<0||b>9||g<0||g>X)return d(a,Q);8===e&&(e=9);var i=new u;return a.state=i,i.strm=a,i.wrap=h,i.gzhead=null,i.w_bits=e,i.w_size=1<N||b<0)return a?d(a,Q):Q;if(h=a.state,!a.output||!a.input&&0!==a.avail_in||h.status===ta&&b!==M)return d(a,0===a.avail_out?S:Q);if(h.strm=a,c=h.last_flush,h.last_flush=b,h.status===na)if(2===h.wrap)a.adler=0,i(h,31),i(h,139),i(h,8),h.gzhead?(i(h,(h.gzhead.text?1:0)+(h.gzhead.hcrc?2:0)+(h.gzhead.extra?4:0)+(h.gzhead.name?8:0)+(h.gzhead.comment?16:0)),i(h,255&h.gzhead.time),i(h,h.gzhead.time>>8&255),i(h,h.gzhead.time>>16&255),i(h,h.gzhead.time>>24&255),i(h,9===h.level?2:h.strategy>=V||h.level<2?4:0),i(h,255&h.gzhead.os),h.gzhead.extra&&h.gzhead.extra.length&&(i(h,255&h.gzhead.extra.length),i(h,h.gzhead.extra.length>>8&255)),h.gzhead.hcrc&&(a.adler=H(a.adler,h.pending_buf,h.pending,0)),h.gzindex=0,h.status=oa):(i(h,0),i(h,0),i(h,0),i(h,0),i(h,0),i(h,9===h.level?2:h.strategy>=V||h.level<2?4:0),i(h,ya),h.status=sa);else{var m=$+(h.w_bits-8<<4)<<8,n=-1;n=h.strategy>=V||h.level<2?0:h.level<6?1:6===h.level?2:3,m|=n<<6,0!==h.strstart&&(m|=ma),m+=31-m%31,h.status=sa,j(h,m),0!==h.strstart&&(j(h,a.adler>>>16),j(h,65535&a.adler)),a.adler=1}if(h.status===oa)if(h.gzhead.extra){for(k=h.pending;h.gzindex<(65535&h.gzhead.extra.length)&&(h.pending!==h.pending_buf_size||(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending!==h.pending_buf_size));)i(h,255&h.gzhead.extra[h.gzindex]),h.gzindex++;h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),h.gzindex===h.gzhead.extra.length&&(h.gzindex=0,h.status=pa)}else h.status=pa;if(h.status===pa)if(h.gzhead.name){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindexk&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.gzindex=0,h.status=qa)}else h.status=qa;if(h.status===qa)if(h.gzhead.comment){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindexk&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.status=ra)}else h.status=ra;if(h.status===ra&&(h.gzhead.hcrc?(h.pending+2>h.pending_buf_size&&g(a),h.pending+2<=h.pending_buf_size&&(i(h,255&a.adler),i(h,a.adler>>8&255),a.adler=0,h.status=sa)):h.status=sa),0!==h.pending){if(g(a),0===a.avail_out)return h.last_flush=-1,O}else if(0===a.avail_in&&e(b)<=e(c)&&b!==M)return d(a,S);if(h.status===ta&&0!==a.avail_in)return d(a,S);if(0!==a.avail_in||0!==h.lookahead||b!==J&&h.status!==ta){var o=h.strategy===V?r(h,b):h.strategy===W?q(h,b):D[h.level].func(h,b);if(o!==wa&&o!==xa||(h.status=ta),o===ua||o===wa)return 0===a.avail_out&&(h.last_flush=-1),O;if(o===va&&(b===K?F._tr_align(h):b!==N&&(F._tr_stored_block(h,0,0,!1),b===L&&(f(h.head),0===h.lookahead&&(h.strstart=0,h.block_start=0,h.insert=0))),g(a),0===a.avail_out))return h.last_flush=-1,O}return b!==M?O:h.wrap<=0?P:(2===h.wrap?(i(h,255&a.adler),i(h,a.adler>>8&255),i(h,a.adler>>16&255),i(h,a.adler>>24&255),i(h,255&a.total_in),i(h,a.total_in>>8&255),i(h,a.total_in>>16&255),i(h,a.total_in>>24&255)):(j(h,a.adler>>>16),j(h,65535&a.adler)),g(a),h.wrap>0&&(h.wrap=-h.wrap),0!==h.pending?O:P)}function B(a){var b;return a&&a.state?(b=a.state.status,b!==na&&b!==oa&&b!==pa&&b!==qa&&b!==ra&&b!==sa&&b!==ta?d(a,Q):(a.state=null,b===sa?d(a,R):O)):Q}function C(a,b){var c,d,e,g,h,i,j,k,l=b.length;if(!a||!a.state)return Q;if(c=a.state,g=c.wrap,2===g||1===g&&c.status!==na||c.lookahead)return Q;for(1===g&&(a.adler=G(a.adler,b,l,0)),c.wrap=0,l>=c.w_size&&(0===g&&(f(c.head),c.strstart=0,c.block_start=0,c.insert=0),k=new E.Buf8(c.w_size),E.arraySet(k,b,l-c.w_size,c.w_size,0),b=k,l=c.w_size),h=a.avail_in,i=a.next_in,j=a.input,a.avail_in=l,a.next_in=0,a.input=b,m(c);c.lookahead>=ja;){d=c.strstart,e=c.lookahead-(ja-1);do c.ins_h=(c.ins_h<>>24,p>>>=w,q-=w,w=v>>>16&255,0===w)C[h++]=65535&v;else{if(!(16&w)){if(0===(64&w)){v=r[(65535&v)+(p&(1<>>=w,q-=w),q<15&&(p+=B[f++]<>>24,p>>>=w,q-=w,w=v>>>16&255,!(16&w)){if(0===(64&w)){v=s[(65535&v)+(p&(1<k){a.msg="invalid distance too far back",c.mode=d;break a}if(p>>>=w,q-=w,w=h-i,y>w){if(w=y-w,w>m&&c.sane){a.msg="invalid distance too far back",c.mode=d;break a}if(z=0,A=o,0===n){if(z+=l-w,w2;)C[h++]=A[z++],C[h++]=A[z++],C[h++]=A[z++],x-=3;x&&(C[h++]=A[z++],x>1&&(C[h++]=A[z++]))}else{z=h-y;do C[h++]=C[z++],C[h++]=C[z++],C[h++]=C[z++],x-=3;while(x>2);x&&(C[h++]=C[z++],x>1&&(C[h++]=C[z++]))}break}}break}}while(f>3,f-=x,q-=x<<3,p&=(1<>>24&255)+(a>>>8&65280)+((65280&a)<<8)+((255&a)<<24)}function e(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function f(a){var b;return a&&a.state?(b=a.state,a.total_in=a.total_out=b.total=0,a.msg="",b.wrap&&(a.adler=1&b.wrap),b.mode=L,b.last=0,b.havedict=0,b.dmax=32768,b.head=null,b.hold=0,b.bits=0,b.lencode=b.lendyn=new s.Buf32(pa),b.distcode=b.distdyn=new s.Buf32(qa),b.sane=1,b.back=-1,D):G}function g(a){var b;return a&&a.state?(b=a.state,b.wsize=0,b.whave=0,b.wnext=0,f(a)):G}function h(a,b){var c,d;return a&&a.state?(d=a.state,b<0?(c=0,b=-b):(c=(b>>4)+1,b<48&&(b&=15)),b&&(b<8||b>15)?G:(null!==d.window&&d.wbits!==b&&(d.window=null),d.wrap=c,d.wbits=b,g(a))):G}function i(a,b){var c,d;return a?(d=new e,a.state=d,d.window=null,c=h(a,b),c!==D&&(a.state=null),c):G}function j(a){return i(a,sa)}function k(a){if(ta){var b;for(q=new s.Buf32(512),r=new s.Buf32(32),b=0;b<144;)a.lens[b++]=8;for(;b<256;)a.lens[b++]=9;for(;b<280;)a.lens[b++]=7;for(;b<288;)a.lens[b++]=8;for(w(y,a.lens,0,288,q,0,a.work,{bits:9}),b=0;b<32;)a.lens[b++]=5;w(z,a.lens,0,32,r,0,a.work,{bits:5}),ta=!1}a.lencode=q,a.lenbits=9,a.distcode=r,a.distbits=5}function l(a,b,c,d){var e,f=a.state;return null===f.window&&(f.wsize=1<=f.wsize?(s.arraySet(f.window,b,c-f.wsize,f.wsize,0),f.wnext=0,f.whave=f.wsize):(e=f.wsize-f.wnext,e>d&&(e=d),s.arraySet(f.window,b,c-d,e,f.wnext),d-=e,d?(s.arraySet(f.window,b,c-d,d,0),f.wnext=d,f.whave=f.wsize):(f.wnext+=e,f.wnext===f.wsize&&(f.wnext=0),f.whave>>8&255,c.check=u(c.check,Ba,2,0),m=0,n=0,c.mode=M;break}if(c.flags=0,c.head&&(c.head.done=!1),!(1&c.wrap)||(((255&m)<<8)+(m>>8))%31){a.msg="incorrect header check",c.mode=ma;break}if((15&m)!==K){a.msg="unknown compression method",c.mode=ma;break}if(m>>>=4,n-=4,wa=(15&m)+8,0===c.wbits)c.wbits=wa;else if(wa>c.wbits){a.msg="invalid window size",c.mode=ma;break}c.dmax=1<>8&1),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0,c.mode=N;case N:for(;n<32;){if(0===i)break a;i--,m+=e[g++]<>>8&255,Ba[2]=m>>>16&255,Ba[3]=m>>>24&255,c.check=u(c.check,Ba,4,0)),m=0,n=0,c.mode=O;case O:for(;n<16;){if(0===i)break a;i--,m+=e[g++]<>8),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0,c.mode=P;case P:if(1024&c.flags){for(;n<16;){if(0===i)break a;i--,m+=e[g++]<>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0}else c.head&&(c.head.extra=null);c.mode=Q;case Q:if(1024&c.flags&&(q=c.length,q>i&&(q=i),q&&(c.head&&(wa=c.head.extra_len-c.length,c.head.extra||(c.head.extra=new Array(c.head.extra_len)),s.arraySet(c.head.extra,e,g,q,wa)),512&c.flags&&(c.check=u(c.check,e,q,g)),i-=q,g+=q,c.length-=q),c.length))break a;c.length=0,c.mode=R;case R:if(2048&c.flags){if(0===i)break a;q=0;do wa=e[g+q++],c.head&&wa&&c.length<65536&&(c.head.name+=String.fromCharCode(wa));while(wa&&q>9&1,c.head.done=!0),a.adler=c.check=0,c.mode=W;break;case U:for(;n<32;){if(0===i)break a;i--,m+=e[g++]<>>=7&n,n-=7&n,c.mode=ja;break}for(;n<3;){if(0===i)break a;i--,m+=e[g++]<>>=1,n-=1,3&m){case 0:c.mode=Y;break;case 1:if(k(c),c.mode=ca,b===C){m>>>=2,n-=2;break a}break;case 2:c.mode=_;break;case 3:a.msg="invalid block type",c.mode=ma}m>>>=2,n-=2;break;case Y:for(m>>>=7&n,n-=7&n;n<32;){if(0===i)break a;i--,m+=e[g++]<>>16^65535)){a.msg="invalid stored block lengths",c.mode=ma;break}if(c.length=65535&m,m=0,n=0,c.mode=Z,b===C)break a;case Z:c.mode=$;case $:if(q=c.length){if(q>i&&(q=i),q>j&&(q=j),0===q)break a;s.arraySet(f,e,g,q,h),i-=q,g+=q,j-=q,h+=q,c.length-=q;break}c.mode=W;break;case _:for(;n<14;){if(0===i)break a;i--,m+=e[g++]<>>=5,n-=5,c.ndist=(31&m)+1,m>>>=5,n-=5,c.ncode=(15&m)+4,m>>>=4,n-=4,c.nlen>286||c.ndist>30){a.msg="too many length or distance symbols",c.mode=ma;break}c.have=0,c.mode=aa;case aa:for(;c.have>>=3,n-=3}for(;c.have<19;)c.lens[Ca[c.have++]]=0;if(c.lencode=c.lendyn,c.lenbits=7,ya={bits:c.lenbits},xa=w(x,c.lens,0,19,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid code lengths set",c.mode=ma;break}c.have=0,c.mode=ba;case ba:for(;c.have>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<>>=qa,n-=qa,c.lens[c.have++]=sa;else{if(16===sa){for(za=qa+2;n>>=qa,n-=qa,0===c.have){a.msg="invalid bit length repeat",c.mode=ma;break}wa=c.lens[c.have-1],q=3+(3&m),m>>>=2,n-=2}else if(17===sa){for(za=qa+3;n>>=qa,n-=qa,wa=0,q=3+(7&m),m>>>=3,n-=3}else{for(za=qa+7;n>>=qa,n-=qa,wa=0,q=11+(127&m),m>>>=7,n-=7}if(c.have+q>c.nlen+c.ndist){a.msg="invalid bit length repeat",c.mode=ma;break}for(;q--;)c.lens[c.have++]=wa}}if(c.mode===ma)break;if(0===c.lens[256]){a.msg="invalid code -- missing end-of-block",c.mode=ma;break}if(c.lenbits=9,ya={bits:c.lenbits},xa=w(y,c.lens,0,c.nlen,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid literal/lengths set",c.mode=ma;break}if(c.distbits=6,c.distcode=c.distdyn,ya={bits:c.distbits},xa=w(z,c.lens,c.nlen,c.ndist,c.distcode,0,c.work,ya),c.distbits=ya.bits,xa){a.msg="invalid distances set",c.mode=ma;break}if(c.mode=ca,b===C)break a;case ca:c.mode=da;case da:if(i>=6&&j>=258){a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,v(a,p),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,c.mode===W&&(c.back=-1);break}for(c.back=0;Aa=c.lencode[m&(1<>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(ta+qa<=n);){if(0===i)break a;i--,m+=e[g++]<>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,c.length=sa,0===ra){c.mode=ia;break}if(32&ra){c.back=-1,c.mode=W;break}if(64&ra){a.msg="invalid literal/length code",c.mode=ma;break}c.extra=15&ra,c.mode=ea;case ea:if(c.extra){for(za=c.extra;n>>=c.extra,n-=c.extra,c.back+=c.extra}c.was=c.length,c.mode=fa;case fa:for(;Aa=c.distcode[m&(1<>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(ta+qa<=n);){if(0===i)break a;i--,m+=e[g++]<>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,64&ra){a.msg="invalid distance code",c.mode=ma;break}c.offset=sa,c.extra=15&ra,c.mode=ga;case ga:if(c.extra){for(za=c.extra;n>>=c.extra,n-=c.extra,c.back+=c.extra}if(c.offset>c.dmax){a.msg="invalid distance too far back",c.mode=ma;break}c.mode=ha;case ha:if(0===j)break a;if(q=p-j,c.offset>q){if(q=c.offset-q,q>c.whave&&c.sane){a.msg="invalid distance too far back",c.mode=ma;break}q>c.wnext?(q-=c.wnext,r=c.wsize-q):r=c.wnext-q,q>c.length&&(q=c.length),pa=c.window}else pa=f,r=h-c.offset,q=c.length;q>j&&(q=j),j-=q,c.length-=q;do f[h++]=pa[r++];while(--q);0===c.length&&(c.mode=da);break;case ia:if(0===j)break a;f[h++]=c.length,j--,c.mode=da;break;case ja:if(c.wrap){for(;n<32;){if(0===i)break a;i--,m|=e[g++]<=1&&0===P[G];G--);if(H>G&&(H=G),0===G)return p[q++]=20971520,p[q++]=20971520,s.bits=1,0;for(F=1;F0&&(a===h||1!==G))return-1;for(Q[1]=0,D=1;Df||a===j&&L>g)return 1;for(;;){z=D-J,r[E]y?(A=R[S+r[E]],B=N[O+r[E]]):(A=96,B=0),t=1<>J)+u]=z<<24|A<<16|B|0;while(0!==u);for(t=1<>=1;if(0!==t?(M&=t-1,M+=t):M=0,E++,0===--P[D]){if(D===G)break;D=b[c+r[E]]}if(D>H&&(M&w)!==v){for(0===J&&(J=H),x+=F,I=D-J,K=1<f||a===j&&L>g)return 1;v=M&w,p[v]=H<<24|I<<16|x-q|0}}return 0!==M&&(p[x+M]=D-J<<24|64<<16|0),s.bits=H,0}},{"../utils/common":41}],51:[function(a,b,c){"use strict";b.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(a,b,c){"use strict";function d(a){for(var b=a.length;--b>=0;)a[b]=0}function e(a,b,c,d,e){this.static_tree=a,this.extra_bits=b,this.extra_base=c,this.elems=d,this.max_length=e,this.has_stree=a&&a.length}function f(a,b){this.dyn_tree=a,this.max_code=0,this.stat_desc=b}function g(a){return a<256?ia[a]:ia[256+(a>>>7)]}function h(a,b){a.pending_buf[a.pending++]=255&b,a.pending_buf[a.pending++]=b>>>8&255}function i(a,b,c){a.bi_valid>X-c?(a.bi_buf|=b<>X-a.bi_valid,a.bi_valid+=c-X):(a.bi_buf|=b<>>=1,c<<=1;while(--b>0);return c>>>1}function l(a){16===a.bi_valid?(h(a,a.bi_buf),a.bi_buf=0,a.bi_valid=0):a.bi_valid>=8&&(a.pending_buf[a.pending++]=255&a.bi_buf,a.bi_buf>>=8,a.bi_valid-=8)}function m(a,b){var c,d,e,f,g,h,i=b.dyn_tree,j=b.max_code,k=b.stat_desc.static_tree,l=b.stat_desc.has_stree,m=b.stat_desc.extra_bits,n=b.stat_desc.extra_base,o=b.stat_desc.max_length,p=0;for(f=0;f<=W;f++)a.bl_count[f]=0;for(i[2*a.heap[a.heap_max]+1]=0,c=a.heap_max+1;co&&(f=o,p++),i[2*d+1]=f,d>j||(a.bl_count[f]++,g=0,d>=n&&(g=m[d-n]),h=i[2*d],a.opt_len+=h*(f+g),l&&(a.static_len+=h*(k[2*d+1]+g)));if(0!==p){do{for(f=o-1;0===a.bl_count[f];)f--;a.bl_count[f]--,a.bl_count[f+1]+=2,a.bl_count[o]--,p-=2}while(p>0);for(f=o;0!==f;f--)for(d=a.bl_count[f];0!==d;)e=a.heap[--c],e>j||(i[2*e+1]!==f&&(a.opt_len+=(f-i[2*e+1])*i[2*e],i[2*e+1]=f),d--)}}function n(a,b,c){var d,e,f=new Array(W+1),g=0;for(d=1;d<=W;d++)f[d]=g=g+c[d-1]<<1;for(e=0;e<=b;e++){var h=a[2*e+1];0!==h&&(a[2*e]=k(f[h]++,h))}}function o(){var a,b,c,d,f,g=new Array(W+1);for(c=0,d=0;d>=7;d8?h(a,a.bi_buf):a.bi_valid>0&&(a.pending_buf[a.pending++]=a.bi_buf),a.bi_buf=0,a.bi_valid=0}function r(a,b,c,d){q(a),d&&(h(a,c),h(a,~c)),G.arraySet(a.pending_buf,a.window,b,c,a.pending),a.pending+=c}function s(a,b,c,d){var e=2*b,f=2*c;return a[e]>1;c>=1;c--)t(a,f,c);e=i;do c=a.heap[1],a.heap[1]=a.heap[a.heap_len--],t(a,f,1),d=a.heap[1],a.heap[--a.heap_max]=c,a.heap[--a.heap_max]=d,f[2*e]=f[2*c]+f[2*d],a.depth[e]=(a.depth[c]>=a.depth[d]?a.depth[c]:a.depth[d])+1,f[2*c+1]=f[2*d+1]=e,a.heap[1]=e++,t(a,f,1);while(a.heap_len>=2);a.heap[--a.heap_max]=a.heap[1],m(a,b),n(f,j,a.bl_count)}function w(a,b,c){var d,e,f=-1,g=b[1],h=0,i=7,j=4;for(0===g&&(i=138,j=3),b[2*(c+1)+1]=65535,d=0;d<=c;d++)e=g,g=b[2*(d+1)+1],++h=3&&0===a.bl_tree[2*ea[b]+1];b--);return a.opt_len+=3*(b+1)+5+5+4,b}function z(a,b,c,d){var e;for(i(a,b-257,5),i(a,c-1,5),i(a,d-4,4),e=0;e>>=1)if(1&c&&0!==a.dyn_ltree[2*b])return I;if(0!==a.dyn_ltree[18]||0!==a.dyn_ltree[20]||0!==a.dyn_ltree[26])return J;for(b=32;b0?(a.strm.data_type===K&&(a.strm.data_type=A(a)),v(a,a.l_desc),v(a,a.d_desc),g=y(a),e=a.opt_len+3+7>>>3,f=a.static_len+3+7>>>3,f<=e&&(e=f)):e=f=c+5,c+4<=e&&b!==-1?C(a,b,c,d):a.strategy===H||f===e?(i(a,(M<<1)+(d?1:0),3),u(a,ga,ha)):(i(a,(N<<1)+(d?1:0),3),z(a,a.l_desc.max_code+1,a.d_desc.max_code+1,g+1),u(a,a.dyn_ltree,a.dyn_dtree)),p(a),d&&q(a)}function F(a,b,c){return a.pending_buf[a.d_buf+2*a.last_lit]=b>>>8&255,a.pending_buf[a.d_buf+2*a.last_lit+1]=255&b,a.pending_buf[a.l_buf+a.last_lit]=255&c,a.last_lit++,0===b?a.dyn_ltree[2*c]++:(a.matches++,b--,a.dyn_ltree[2*(ja[c]+R+1)]++,a.dyn_dtree[2*g(b)]++),a.last_lit===a.lit_bufsize-1}var G=a("../utils/common"),H=4,I=0,J=1,K=2,L=0,M=1,N=2,O=3,P=258,Q=29,R=256,S=R+1+Q,T=30,U=19,V=2*S+1,W=15,X=16,Y=7,Z=256,$=16,_=17,aa=18,ba=[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],ca=[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],da=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ea=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],fa=512,ga=new Array(2*(S+2)); -d(ga);var ha=new Array(2*T);d(ha);var ia=new Array(fa);d(ia);var ja=new Array(P-O+1);d(ja);var ka=new Array(Q);d(ka);var la=new Array(T);d(la);var ma,na,oa,pa=!1;c._tr_init=B,c._tr_stored_block=C,c._tr_flush_block=E,c._tr_tally=F,c._tr_align=D},{"../utils/common":41}],53:[function(a,b,c){"use strict";function d(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}b.exports=d},{}],54:[function(a,b,c){"use strict";b.exports="function"==typeof setImmediate?setImmediate:function(){var a=[].slice.apply(arguments);a.splice(1,0,0),setTimeout.apply(null,a)}},{}]},{},[10])(10)}); \ No newline at end of file +!(function (a) { + if ("object" == typeof exports && "undefined" != typeof module) + module.exports = a(); + else if ("function" == typeof define && define.amd) define([], a); + else { + var b; + (b = + "undefined" != typeof window + ? window + : "undefined" != typeof global + ? global + : "undefined" != typeof self + ? self + : this), + (b.JSZip = a()); + } +})(function () { + return (function a(b, c, d) { + function e(g, h) { + if (!c[g]) { + if (!b[g]) { + var i = "function" == typeof require && require; + if (!h && i) return i(g, !0); + if (f) return f(g, !0); + var j = new Error("Cannot find module '" + g + "'"); + throw ((j.code = "MODULE_NOT_FOUND"), j); + } + var k = (c[g] = { exports: {} }); + b[g][0].call( + k.exports, + function (a) { + var c = b[g][1][a]; + return e(c ? c : a); + }, + k, + k.exports, + a, + b, + c, + d + ); + } + return c[g].exports; + } + for ( + var f = "function" == typeof require && require, g = 0; + g < d.length; + g++ + ) + e(d[g]); + return e; + })( + { + 1: [ + function (a, b, c) { + "use strict"; + var d = a("./utils"), + e = a("./support"), + f = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + (c.encode = function (a) { + for ( + var b, + c, + e, + g, + h, + i, + j, + k = [], + l = 0, + m = a.length, + n = m, + o = "string" !== d.getTypeOf(a); + l < a.length; + + ) + (n = m - l), + o + ? ((b = a[l++]), + (c = l < m ? a[l++] : 0), + (e = l < m ? a[l++] : 0)) + : ((b = a.charCodeAt(l++)), + (c = l < m ? a.charCodeAt(l++) : 0), + (e = l < m ? a.charCodeAt(l++) : 0)), + (g = b >> 2), + (h = ((3 & b) << 4) | (c >> 4)), + (i = n > 1 ? ((15 & c) << 2) | (e >> 6) : 64), + (j = n > 2 ? 63 & e : 64), + k.push(f.charAt(g) + f.charAt(h) + f.charAt(i) + f.charAt(j)); + return k.join(""); + }), + (c.decode = function (a) { + var b, + c, + d, + g, + h, + i, + j, + k = 0, + l = 0, + m = "data:"; + if (a.substr(0, m.length) === m) + throw new Error( + "Invalid base64 input, it looks like a data url." + ); + a = a.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + var n = (3 * a.length) / 4; + if ( + (a.charAt(a.length - 1) === f.charAt(64) && n--, + a.charAt(a.length - 2) === f.charAt(64) && n--, + n % 1 !== 0) + ) + throw new Error("Invalid base64 input, bad content length."); + var o; + for ( + o = e.uint8array ? new Uint8Array(0 | n) : new Array(0 | n); + k < a.length; + + ) + (g = f.indexOf(a.charAt(k++))), + (h = f.indexOf(a.charAt(k++))), + (i = f.indexOf(a.charAt(k++))), + (j = f.indexOf(a.charAt(k++))), + (b = (g << 2) | (h >> 4)), + (c = ((15 & h) << 4) | (i >> 2)), + (d = ((3 & i) << 6) | j), + (o[l++] = b), + 64 !== i && (o[l++] = c), + 64 !== j && (o[l++] = d); + return o; + }); + }, + { "./support": 30, "./utils": 32 }, + ], + 2: [ + function (a, b, c) { + "use strict"; + function d(a, b, c, d, e) { + (this.compressedSize = a), + (this.uncompressedSize = b), + (this.crc32 = c), + (this.compression = d), + (this.compressedContent = e); + } + var e = a("./external"), + f = a("./stream/DataWorker"), + g = a("./stream/DataLengthProbe"), + h = a("./stream/Crc32Probe"), + g = a("./stream/DataLengthProbe"); + (d.prototype = { + getContentWorker: function () { + var a = new f(e.Promise.resolve(this.compressedContent)) + .pipe(this.compression.uncompressWorker()) + .pipe(new g("data_length")), + b = this; + return ( + a.on("end", function () { + if (this.streamInfo.data_length !== b.uncompressedSize) + throw new Error("Bug : uncompressed data size mismatch"); + }), + a + ); + }, + getCompressedWorker: function () { + return new f(e.Promise.resolve(this.compressedContent)) + .withStreamInfo("compressedSize", this.compressedSize) + .withStreamInfo("uncompressedSize", this.uncompressedSize) + .withStreamInfo("crc32", this.crc32) + .withStreamInfo("compression", this.compression); + }, + }), + (d.createWorkerFrom = function (a, b, c) { + return a + .pipe(new h()) + .pipe(new g("uncompressedSize")) + .pipe(b.compressWorker(c)) + .pipe(new g("compressedSize")) + .withStreamInfo("compression", b); + }), + (b.exports = d); + }, + { + "./external": 6, + "./stream/Crc32Probe": 25, + "./stream/DataLengthProbe": 26, + "./stream/DataWorker": 27, + }, + ], + 3: [ + function (a, b, c) { + "use strict"; + var d = a("./stream/GenericWorker"); + (c.STORE = { + magic: "\0\0", + compressWorker: function (a) { + return new d("STORE compression"); + }, + uncompressWorker: function () { + return new d("STORE decompression"); + }, + }), + (c.DEFLATE = a("./flate")); + }, + { "./flate": 7, "./stream/GenericWorker": 28 }, + ], + 4: [ + function (a, b, c) { + "use strict"; + function d() { + for (var a, b = [], c = 0; c < 256; c++) { + a = c; + for (var d = 0; d < 8; d++) + a = 1 & a ? 3988292384 ^ (a >>> 1) : a >>> 1; + b[c] = a; + } + return b; + } + function e(a, b, c, d) { + var e = h, + f = d + c; + a ^= -1; + for (var g = d; g < f; g++) a = (a >>> 8) ^ e[255 & (a ^ b[g])]; + return a ^ -1; + } + function f(a, b, c, d) { + var e = h, + f = d + c; + a ^= -1; + for (var g = d; g < f; g++) + a = (a >>> 8) ^ e[255 & (a ^ b.charCodeAt(g))]; + return a ^ -1; + } + var g = a("./utils"), + h = d(); + b.exports = function (a, b) { + if ("undefined" == typeof a || !a.length) return 0; + var c = "string" !== g.getTypeOf(a); + return c ? e(0 | b, a, a.length, 0) : f(0 | b, a, a.length, 0); + }; + }, + { "./utils": 32 }, + ], + 5: [ + function (a, b, c) { + "use strict"; + (c.base64 = !1), + (c.binary = !1), + (c.dir = !1), + (c.createFolders = !0), + (c.date = null), + (c.compression = null), + (c.compressionOptions = null), + (c.comment = null), + (c.unixPermissions = null), + (c.dosPermissions = null); + }, + {}, + ], + 6: [ + function (a, b, c) { + "use strict"; + var d = null; + (d = "undefined" != typeof Promise ? Promise : a("lie")), + (b.exports = { Promise: d }); + }, + { lie: 37 }, + ], + 7: [ + function (a, b, c) { + "use strict"; + function d(a, b) { + h.call(this, "FlateWorker/" + a), + (this._pako = null), + (this._pakoAction = a), + (this._pakoOptions = b), + (this.meta = {}); + } + var e = + "undefined" != typeof Uint8Array && + "undefined" != typeof Uint16Array && + "undefined" != typeof Uint32Array, + f = a("pako"), + g = a("./utils"), + h = a("./stream/GenericWorker"), + i = e ? "uint8array" : "array"; + (c.magic = "\b\0"), + g.inherits(d, h), + (d.prototype.processChunk = function (a) { + (this.meta = a.meta), + null === this._pako && this._createPako(), + this._pako.push(g.transformTo(i, a.data), !1); + }), + (d.prototype.flush = function () { + h.prototype.flush.call(this), + null === this._pako && this._createPako(), + this._pako.push([], !0); + }), + (d.prototype.cleanUp = function () { + h.prototype.cleanUp.call(this), (this._pako = null); + }), + (d.prototype._createPako = function () { + this._pako = new f[this._pakoAction]({ + raw: !0, + level: this._pakoOptions.level || -1, + }); + var a = this; + this._pako.onData = function (b) { + a.push({ data: b, meta: a.meta }); + }; + }), + (c.compressWorker = function (a) { + return new d("Deflate", a); + }), + (c.uncompressWorker = function () { + return new d("Inflate", {}); + }); + }, + { "./stream/GenericWorker": 28, "./utils": 32, "pako": 38 }, + ], + 8: [ + function (a, b, c) { + "use strict"; + function d(a, b, c, d) { + f.call(this, "ZipFileWorker"), + (this.bytesWritten = 0), + (this.zipComment = b), + (this.zipPlatform = c), + (this.encodeFileName = d), + (this.streamFiles = a), + (this.accumulate = !1), + (this.contentBuffer = []), + (this.dirRecords = []), + (this.currentSourceOffset = 0), + (this.entriesCount = 0), + (this.currentFile = null), + (this._sources = []); + } + var e = a("../utils"), + f = a("../stream/GenericWorker"), + g = a("../utf8"), + h = a("../crc32"), + i = a("../signature"), + j = function (a, b) { + var c, + d = ""; + for (c = 0; c < b; c++) + (d += String.fromCharCode(255 & a)), (a >>>= 8); + return d; + }, + k = function (a, b) { + var c = a; + return a || (c = b ? 16893 : 33204), (65535 & c) << 16; + }, + l = function (a, b) { + return 63 & (a || 0); + }, + m = function (a, b, c, d, f, m) { + var n, + o, + p = a.file, + q = a.compression, + r = m !== g.utf8encode, + s = e.transformTo("string", m(p.name)), + t = e.transformTo("string", g.utf8encode(p.name)), + u = p.comment, + v = e.transformTo("string", m(u)), + w = e.transformTo("string", g.utf8encode(u)), + x = t.length !== p.name.length, + y = w.length !== u.length, + z = "", + A = "", + B = "", + C = p.dir, + D = p.date, + E = { crc32: 0, compressedSize: 0, uncompressedSize: 0 }; + (b && !c) || + ((E.crc32 = a.crc32), + (E.compressedSize = a.compressedSize), + (E.uncompressedSize = a.uncompressedSize)); + var F = 0; + b && (F |= 8), r || (!x && !y) || (F |= 2048); + var G = 0, + H = 0; + C && (G |= 16), + "UNIX" === f + ? ((H = 798), (G |= k(p.unixPermissions, C))) + : ((H = 20), (G |= l(p.dosPermissions, C))), + (n = D.getUTCHours()), + (n <<= 6), + (n |= D.getUTCMinutes()), + (n <<= 5), + (n |= D.getUTCSeconds() / 2), + (o = D.getUTCFullYear() - 1980), + (o <<= 4), + (o |= D.getUTCMonth() + 1), + (o <<= 5), + (o |= D.getUTCDate()), + x && + ((A = j(1, 1) + j(h(s), 4) + t), + (z += "up" + j(A.length, 2) + A)), + y && + ((B = j(1, 1) + j(h(v), 4) + w), + (z += "uc" + j(B.length, 2) + B)); + var I = ""; + (I += "\n\0"), + (I += j(F, 2)), + (I += q.magic), + (I += j(n, 2)), + (I += j(o, 2)), + (I += j(E.crc32, 4)), + (I += j(E.compressedSize, 4)), + (I += j(E.uncompressedSize, 4)), + (I += j(s.length, 2)), + (I += j(z.length, 2)); + var J = i.LOCAL_FILE_HEADER + I + s + z, + K = + i.CENTRAL_FILE_HEADER + + j(H, 2) + + I + + j(v.length, 2) + + "\0\0\0\0" + + j(G, 4) + + j(d, 4) + + s + + z + + v; + return { fileRecord: J, dirRecord: K }; + }, + n = function (a, b, c, d, f) { + var g = "", + h = e.transformTo("string", f(d)); + return (g = + i.CENTRAL_DIRECTORY_END + + "\0\0\0\0" + + j(a, 2) + + j(a, 2) + + j(b, 4) + + j(c, 4) + + j(h.length, 2) + + h); + }, + o = function (a) { + var b = ""; + return (b = + i.DATA_DESCRIPTOR + + j(a.crc32, 4) + + j(a.compressedSize, 4) + + j(a.uncompressedSize, 4)); + }; + e.inherits(d, f), + (d.prototype.push = function (a) { + var b = a.meta.percent || 0, + c = this.entriesCount, + d = this._sources.length; + this.accumulate + ? this.contentBuffer.push(a) + : ((this.bytesWritten += a.data.length), + f.prototype.push.call(this, { + data: a.data, + meta: { + currentFile: this.currentFile, + percent: c ? (b + 100 * (c - d - 1)) / c : 100, + }, + })); + }), + (d.prototype.openedSource = function (a) { + (this.currentSourceOffset = this.bytesWritten), + (this.currentFile = a.file.name); + var b = this.streamFiles && !a.file.dir; + if (b) { + var c = m( + a, + b, + !1, + this.currentSourceOffset, + this.zipPlatform, + this.encodeFileName + ); + this.push({ data: c.fileRecord, meta: { percent: 0 } }); + } else this.accumulate = !0; + }), + (d.prototype.closedSource = function (a) { + this.accumulate = !1; + var b = this.streamFiles && !a.file.dir, + c = m( + a, + b, + !0, + this.currentSourceOffset, + this.zipPlatform, + this.encodeFileName + ); + if ((this.dirRecords.push(c.dirRecord), b)) + this.push({ data: o(a), meta: { percent: 100 } }); + else + for ( + this.push({ data: c.fileRecord, meta: { percent: 0 } }); + this.contentBuffer.length; + + ) + this.push(this.contentBuffer.shift()); + this.currentFile = null; + }), + (d.prototype.flush = function () { + for ( + var a = this.bytesWritten, b = 0; + b < this.dirRecords.length; + b++ + ) + this.push({ data: this.dirRecords[b], meta: { percent: 100 } }); + var c = this.bytesWritten - a, + d = n( + this.dirRecords.length, + c, + a, + this.zipComment, + this.encodeFileName + ); + this.push({ data: d, meta: { percent: 100 } }); + }), + (d.prototype.prepareNextSource = function () { + (this.previous = this._sources.shift()), + this.openedSource(this.previous.streamInfo), + this.isPaused ? this.previous.pause() : this.previous.resume(); + }), + (d.prototype.registerPrevious = function (a) { + this._sources.push(a); + var b = this; + return ( + a.on("data", function (a) { + b.processChunk(a); + }), + a.on("end", function () { + b.closedSource(b.previous.streamInfo), + b._sources.length ? b.prepareNextSource() : b.end(); + }), + a.on("error", function (a) { + b.error(a); + }), + this + ); + }), + (d.prototype.resume = function () { + return ( + !!f.prototype.resume.call(this) && + (!this.previous && this._sources.length + ? (this.prepareNextSource(), !0) + : this.previous || this._sources.length || this.generatedError + ? void 0 + : (this.end(), !0)) + ); + }), + (d.prototype.error = function (a) { + var b = this._sources; + if (!f.prototype.error.call(this, a)) return !1; + for (var c = 0; c < b.length; c++) + try { + b[c].error(a); + } catch (a) {} + return !0; + }), + (d.prototype.lock = function () { + f.prototype.lock.call(this); + for (var a = this._sources, b = 0; b < a.length; b++) a[b].lock(); + }), + (b.exports = d); + }, + { + "../crc32": 4, + "../signature": 23, + "../stream/GenericWorker": 28, + "../utf8": 31, + "../utils": 32, + }, + ], + 9: [ + function (a, b, c) { + "use strict"; + var d = a("../compressions"), + e = a("./ZipFileWorker"), + f = function (a, b) { + var c = a || b, + e = d[c]; + if (!e) + throw new Error(c + " is not a valid compression method !"); + return e; + }; + c.generateWorker = function (a, b, c) { + var d = new e(b.streamFiles, c, b.platform, b.encodeFileName), + g = 0; + try { + a.forEach(function (a, c) { + g++; + var e = f(c.options.compression, b.compression), + h = + c.options.compressionOptions || b.compressionOptions || {}, + i = c.dir, + j = c.date; + c._compressWorker(e, h) + .withStreamInfo("file", { + name: a, + dir: i, + date: j, + comment: c.comment || "", + unixPermissions: c.unixPermissions, + dosPermissions: c.dosPermissions, + }) + .pipe(d); + }), + (d.entriesCount = g); + } catch (h) { + d.error(h); + } + return d; + }; + }, + { "../compressions": 3, "./ZipFileWorker": 8 }, + ], + 10: [ + function (a, b, c) { + "use strict"; + function d() { + if (!(this instanceof d)) return new d(); + if (arguments.length) + throw new Error( + "The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide." + ); + (this.files = {}), + (this.comment = null), + (this.root = ""), + (this.clone = function () { + var a = new d(); + for (var b in this) + "function" != typeof this[b] && (a[b] = this[b]); + return a; + }); + } + (d.prototype = a("./object")), + (d.prototype.loadAsync = a("./load")), + (d.support = a("./support")), + (d.defaults = a("./defaults")), + (d.version = "3.2.0"), + (d.loadAsync = function (a, b) { + return new d().loadAsync(a, b); + }), + (d.external = a("./external")), + (b.exports = d); + }, + { + "./defaults": 5, + "./external": 6, + "./load": 11, + "./object": 15, + "./support": 30, + }, + ], + 11: [ + function (a, b, c) { + "use strict"; + function d(a) { + return new f.Promise(function (b, c) { + var d = a.decompressed.getContentWorker().pipe(new i()); + d.on("error", function (a) { + c(a); + }) + .on("end", function () { + d.streamInfo.crc32 !== a.decompressed.crc32 + ? c(new Error("Corrupted zip : CRC32 mismatch")) + : b(); + }) + .resume(); + }); + } + var e = a("./utils"), + f = a("./external"), + g = a("./utf8"), + e = a("./utils"), + h = a("./zipEntries"), + i = a("./stream/Crc32Probe"), + j = a("./nodejsUtils"); + b.exports = function (a, b) { + var c = this; + return ( + (b = e.extend(b || {}, { + base64: !1, + checkCRC32: !1, + optimizedBinaryString: !1, + createFolders: !1, + decodeFileName: g.utf8decode, + })), + j.isNode && j.isStream(a) + ? f.Promise.reject( + new Error( + "JSZip can't accept a stream when loading a zip file." + ) + ) + : e + .prepareContent( + "the loaded zip file", + a, + !0, + b.optimizedBinaryString, + b.base64 + ) + .then(function (a) { + var c = new h(b); + return c.load(a), c; + }) + .then(function (a) { + var c = [f.Promise.resolve(a)], + e = a.files; + if (b.checkCRC32) + for (var g = 0; g < e.length; g++) c.push(d(e[g])); + return f.Promise.all(c); + }) + .then(function (a) { + for ( + var d = a.shift(), e = d.files, f = 0; + f < e.length; + f++ + ) { + var g = e[f]; + c.file(g.fileNameStr, g.decompressed, { + binary: !0, + optimizedBinaryString: !0, + date: g.date, + dir: g.dir, + comment: g.fileCommentStr.length + ? g.fileCommentStr + : null, + unixPermissions: g.unixPermissions, + dosPermissions: g.dosPermissions, + createFolders: b.createFolders, + }); + } + return ( + d.zipComment.length && (c.comment = d.zipComment), c + ); + }) + ); + }; + }, + { + "./external": 6, + "./nodejsUtils": 14, + "./stream/Crc32Probe": 25, + "./utf8": 31, + "./utils": 32, + "./zipEntries": 33, + }, + ], + 12: [ + function (a, b, c) { + "use strict"; + function d(a, b) { + f.call(this, "Nodejs stream input adapter for " + a), + (this._upstreamEnded = !1), + this._bindStream(b); + } + var e = a("../utils"), + f = a("../stream/GenericWorker"); + e.inherits(d, f), + (d.prototype._bindStream = function (a) { + var b = this; + (this._stream = a), + a.pause(), + a + .on("data", function (a) { + b.push({ data: a, meta: { percent: 0 } }); + }) + .on("error", function (a) { + b.isPaused ? (this.generatedError = a) : b.error(a); + }) + .on("end", function () { + b.isPaused ? (b._upstreamEnded = !0) : b.end(); + }); + }), + (d.prototype.pause = function () { + return ( + !!f.prototype.pause.call(this) && (this._stream.pause(), !0) + ); + }), + (d.prototype.resume = function () { + return ( + !!f.prototype.resume.call(this) && + (this._upstreamEnded ? this.end() : this._stream.resume(), !0) + ); + }), + (b.exports = d); + }, + { "../stream/GenericWorker": 28, "../utils": 32 }, + ], + 13: [ + function (a, b, c) { + "use strict"; + function d(a, b, c) { + e.call(this, b), (this._helper = a); + var d = this; + a.on("data", function (a, b) { + d.push(a) || d._helper.pause(), c && c(b); + }) + .on("error", function (a) { + d.emit("error", a); + }) + .on("end", function () { + d.push(null); + }); + } + var e = a("readable-stream").Readable, + f = a("../utils"); + f.inherits(d, e), + (d.prototype._read = function () { + this._helper.resume(); + }), + (b.exports = d); + }, + { "../utils": 32, "readable-stream": 16 }, + ], + 14: [ + function (a, b, c) { + "use strict"; + b.exports = { + isNode: "undefined" != typeof Buffer, + newBufferFrom: function (a, b) { + if (Buffer.from && Buffer.from !== Uint8Array.from) + return Buffer.from(a, b); + if ("number" == typeof a) + throw new Error('The "data" argument must not be a number'); + return new Buffer(a, b); + }, + allocBuffer: function (a) { + if (Buffer.alloc) return Buffer.alloc(a); + var b = new Buffer(a); + return b.fill(0), b; + }, + isBuffer: function (a) { + return Buffer.isBuffer(a); + }, + isStream: function (a) { + return ( + a && + "function" == typeof a.on && + "function" == typeof a.pause && + "function" == typeof a.resume + ); + }, + }; + }, + {}, + ], + 15: [ + function (a, b, c) { + "use strict"; + function d(a) { + return "[object RegExp]" === Object.prototype.toString.call(a); + } + var e = a("./utf8"), + f = a("./utils"), + g = a("./stream/GenericWorker"), + h = a("./stream/StreamHelper"), + i = a("./defaults"), + j = a("./compressedObject"), + k = a("./zipObject"), + l = a("./generate"), + m = a("./nodejsUtils"), + n = a("./nodejs/NodejsStreamInputAdapter"), + o = function (a, b, c) { + var d, + e = f.getTypeOf(b), + h = f.extend(c || {}, i); + (h.date = h.date || new Date()), + null !== h.compression && + (h.compression = h.compression.toUpperCase()), + "string" == typeof h.unixPermissions && + (h.unixPermissions = parseInt(h.unixPermissions, 8)), + h.unixPermissions && 16384 & h.unixPermissions && (h.dir = !0), + h.dosPermissions && 16 & h.dosPermissions && (h.dir = !0), + h.dir && (a = q(a)), + h.createFolders && (d = p(a)) && r.call(this, d, !0); + var l = "string" === e && h.binary === !1 && h.base64 === !1; + (c && "undefined" != typeof c.binary) || (h.binary = !l); + var o = b instanceof j && 0 === b.uncompressedSize; + (o || h.dir || !b || 0 === b.length) && + ((h.base64 = !1), + (h.binary = !0), + (b = ""), + (h.compression = "STORE"), + (e = "string")); + var s = null; + s = + b instanceof j || b instanceof g + ? b + : m.isNode && m.isStream(b) + ? new n(a, b) + : f.prepareContent( + a, + b, + h.binary, + h.optimizedBinaryString, + h.base64 + ); + var t = new k(a, s, h); + this.files[a] = t; + }, + p = function (a) { + "/" === a.slice(-1) && (a = a.substring(0, a.length - 1)); + var b = a.lastIndexOf("/"); + return b > 0 ? a.substring(0, b) : ""; + }, + q = function (a) { + return "/" !== a.slice(-1) && (a += "/"), a; + }, + r = function (a, b) { + return ( + (b = "undefined" != typeof b ? b : i.createFolders), + (a = q(a)), + this.files[a] || + o.call(this, a, null, { dir: !0, createFolders: b }), + this.files[a] + ); + }, + s = { + load: function () { + throw new Error( + "This method has been removed in JSZip 3.0, please check the upgrade guide." + ); + }, + forEach: function (a) { + var b, c, d; + for (b in this.files) + this.files.hasOwnProperty(b) && + ((d = this.files[b]), + (c = b.slice(this.root.length, b.length)), + c && b.slice(0, this.root.length) === this.root && a(c, d)); + }, + filter: function (a) { + var b = []; + return ( + this.forEach(function (c, d) { + a(c, d) && b.push(d); + }), + b + ); + }, + file: function (a, b, c) { + if (1 === arguments.length) { + if (d(a)) { + var e = a; + return this.filter(function (a, b) { + return !b.dir && e.test(a); + }); + } + var f = this.files[this.root + a]; + return f && !f.dir ? f : null; + } + return (a = this.root + a), o.call(this, a, b, c), this; + }, + folder: function (a) { + if (!a) return this; + if (d(a)) + return this.filter(function (b, c) { + return c.dir && a.test(b); + }); + var b = this.root + a, + c = r.call(this, b), + e = this.clone(); + return (e.root = c.name), e; + }, + remove: function (a) { + a = this.root + a; + var b = this.files[a]; + if ( + (b || + ("/" !== a.slice(-1) && (a += "/"), (b = this.files[a])), + b && !b.dir) + ) + delete this.files[a]; + else + for ( + var c = this.filter(function (b, c) { + return c.name.slice(0, a.length) === a; + }), + d = 0; + d < c.length; + d++ + ) + delete this.files[c[d].name]; + return this; + }, + generate: function (a) { + throw new Error( + "This method has been removed in JSZip 3.0, please check the upgrade guide." + ); + }, + generateInternalStream: function (a) { + var b, + c = {}; + try { + if ( + ((c = f.extend(a || {}, { + streamFiles: !1, + compression: "STORE", + compressionOptions: null, + type: "", + platform: "DOS", + comment: null, + mimeType: "application/zip", + encodeFileName: e.utf8encode, + })), + (c.type = c.type.toLowerCase()), + (c.compression = c.compression.toUpperCase()), + "binarystring" === c.type && (c.type = "string"), + !c.type) + ) + throw new Error("No output type specified."); + f.checkSupport(c.type), + ("darwin" !== c.platform && + "freebsd" !== c.platform && + "linux" !== c.platform && + "sunos" !== c.platform) || + (c.platform = "UNIX"), + "win32" === c.platform && (c.platform = "DOS"); + var d = c.comment || this.comment || ""; + b = l.generateWorker(this, c, d); + } catch (i) { + (b = new g("error")), b.error(i); + } + return new h(b, c.type || "string", c.mimeType); + }, + generateAsync: function (a, b) { + return this.generateInternalStream(a).accumulate(b); + }, + generateNodeStream: function (a, b) { + return ( + (a = a || {}), + a.type || (a.type = "nodebuffer"), + this.generateInternalStream(a).toNodejsStream(b) + ); + }, + }; + b.exports = s; + }, + { + "./compressedObject": 2, + "./defaults": 5, + "./generate": 9, + "./nodejs/NodejsStreamInputAdapter": 12, + "./nodejsUtils": 14, + "./stream/GenericWorker": 28, + "./stream/StreamHelper": 29, + "./utf8": 31, + "./utils": 32, + "./zipObject": 35, + }, + ], + 16: [ + function (a, b, c) { + b.exports = a("stream"); + }, + { stream: void 0 }, + ], + 17: [ + function (a, b, c) { + "use strict"; + function d(a) { + e.call(this, a); + for (var b = 0; b < this.data.length; b++) a[b] = 255 & a[b]; + } + var e = a("./DataReader"), + f = a("../utils"); + f.inherits(d, e), + (d.prototype.byteAt = function (a) { + return this.data[this.zero + a]; + }), + (d.prototype.lastIndexOfSignature = function (a) { + for ( + var b = a.charCodeAt(0), + c = a.charCodeAt(1), + d = a.charCodeAt(2), + e = a.charCodeAt(3), + f = this.length - 4; + f >= 0; + --f + ) + if ( + this.data[f] === b && + this.data[f + 1] === c && + this.data[f + 2] === d && + this.data[f + 3] === e + ) + return f - this.zero; + return -1; + }), + (d.prototype.readAndCheckSignature = function (a) { + var b = a.charCodeAt(0), + c = a.charCodeAt(1), + d = a.charCodeAt(2), + e = a.charCodeAt(3), + f = this.readData(4); + return b === f[0] && c === f[1] && d === f[2] && e === f[3]; + }), + (d.prototype.readData = function (a) { + if ((this.checkOffset(a), 0 === a)) return []; + var b = this.data.slice( + this.zero + this.index, + this.zero + this.index + a + ); + return (this.index += a), b; + }), + (b.exports = d); + }, + { "../utils": 32, "./DataReader": 18 }, + ], + 18: [ + function (a, b, c) { + "use strict"; + function d(a) { + (this.data = a), + (this.length = a.length), + (this.index = 0), + (this.zero = 0); + } + var e = a("../utils"); + (d.prototype = { + checkOffset: function (a) { + this.checkIndex(this.index + a); + }, + checkIndex: function (a) { + if (this.length < this.zero + a || a < 0) + throw new Error( + "End of data reached (data length = " + + this.length + + ", asked index = " + + a + + "). Corrupted zip ?" + ); + }, + setIndex: function (a) { + this.checkIndex(a), (this.index = a); + }, + skip: function (a) { + this.setIndex(this.index + a); + }, + byteAt: function (a) {}, + readInt: function (a) { + var b, + c = 0; + for ( + this.checkOffset(a), b = this.index + a - 1; + b >= this.index; + b-- + ) + c = (c << 8) + this.byteAt(b); + return (this.index += a), c; + }, + readString: function (a) { + return e.transformTo("string", this.readData(a)); + }, + readData: function (a) {}, + lastIndexOfSignature: function (a) {}, + readAndCheckSignature: function (a) {}, + readDate: function () { + var a = this.readInt(4); + return new Date( + Date.UTC( + ((a >> 25) & 127) + 1980, + ((a >> 21) & 15) - 1, + (a >> 16) & 31, + (a >> 11) & 31, + (a >> 5) & 63, + (31 & a) << 1 + ) + ); + }, + }), + (b.exports = d); + }, + { "../utils": 32 }, + ], + 19: [ + function (a, b, c) { + "use strict"; + function d(a) { + e.call(this, a); + } + var e = a("./Uint8ArrayReader"), + f = a("../utils"); + f.inherits(d, e), + (d.prototype.readData = function (a) { + this.checkOffset(a); + var b = this.data.slice( + this.zero + this.index, + this.zero + this.index + a + ); + return (this.index += a), b; + }), + (b.exports = d); + }, + { "../utils": 32, "./Uint8ArrayReader": 21 }, + ], + 20: [ + function (a, b, c) { + "use strict"; + function d(a) { + e.call(this, a); + } + var e = a("./DataReader"), + f = a("../utils"); + f.inherits(d, e), + (d.prototype.byteAt = function (a) { + return this.data.charCodeAt(this.zero + a); + }), + (d.prototype.lastIndexOfSignature = function (a) { + return this.data.lastIndexOf(a) - this.zero; + }), + (d.prototype.readAndCheckSignature = function (a) { + var b = this.readData(4); + return a === b; + }), + (d.prototype.readData = function (a) { + this.checkOffset(a); + var b = this.data.slice( + this.zero + this.index, + this.zero + this.index + a + ); + return (this.index += a), b; + }), + (b.exports = d); + }, + { "../utils": 32, "./DataReader": 18 }, + ], + 21: [ + function (a, b, c) { + "use strict"; + function d(a) { + e.call(this, a); + } + var e = a("./ArrayReader"), + f = a("../utils"); + f.inherits(d, e), + (d.prototype.readData = function (a) { + if ((this.checkOffset(a), 0 === a)) return new Uint8Array(0); + var b = this.data.subarray( + this.zero + this.index, + this.zero + this.index + a + ); + return (this.index += a), b; + }), + (b.exports = d); + }, + { "../utils": 32, "./ArrayReader": 17 }, + ], + 22: [ + function (a, b, c) { + "use strict"; + var d = a("../utils"), + e = a("../support"), + f = a("./ArrayReader"), + g = a("./StringReader"), + h = a("./NodeBufferReader"), + i = a("./Uint8ArrayReader"); + b.exports = function (a) { + var b = d.getTypeOf(a); + return ( + d.checkSupport(b), + "string" !== b || e.uint8array + ? "nodebuffer" === b + ? new h(a) + : e.uint8array + ? new i(d.transformTo("uint8array", a)) + : new f(d.transformTo("array", a)) + : new g(a) + ); + }; + }, + { + "../support": 30, + "../utils": 32, + "./ArrayReader": 17, + "./NodeBufferReader": 19, + "./StringReader": 20, + "./Uint8ArrayReader": 21, + }, + ], + 23: [ + function (a, b, c) { + "use strict"; + (c.LOCAL_FILE_HEADER = "PK"), + (c.CENTRAL_FILE_HEADER = "PK"), + (c.CENTRAL_DIRECTORY_END = "PK"), + (c.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK"), + (c.ZIP64_CENTRAL_DIRECTORY_END = "PK"), + (c.DATA_DESCRIPTOR = "PK\b"); + }, + {}, + ], + 24: [ + function (a, b, c) { + "use strict"; + function d(a) { + e.call(this, "ConvertWorker to " + a), (this.destType = a); + } + var e = a("./GenericWorker"), + f = a("../utils"); + f.inherits(d, e), + (d.prototype.processChunk = function (a) { + this.push({ + data: f.transformTo(this.destType, a.data), + meta: a.meta, + }); + }), + (b.exports = d); + }, + { "../utils": 32, "./GenericWorker": 28 }, + ], + 25: [ + function (a, b, c) { + "use strict"; + function d() { + e.call(this, "Crc32Probe"), this.withStreamInfo("crc32", 0); + } + var e = a("./GenericWorker"), + f = a("../crc32"), + g = a("../utils"); + g.inherits(d, e), + (d.prototype.processChunk = function (a) { + (this.streamInfo.crc32 = f(a.data, this.streamInfo.crc32 || 0)), + this.push(a); + }), + (b.exports = d); + }, + { "../crc32": 4, "../utils": 32, "./GenericWorker": 28 }, + ], + 26: [ + function (a, b, c) { + "use strict"; + function d(a) { + f.call(this, "DataLengthProbe for " + a), + (this.propName = a), + this.withStreamInfo(a, 0); + } + var e = a("../utils"), + f = a("./GenericWorker"); + e.inherits(d, f), + (d.prototype.processChunk = function (a) { + if (a) { + var b = this.streamInfo[this.propName] || 0; + this.streamInfo[this.propName] = b + a.data.length; + } + f.prototype.processChunk.call(this, a); + }), + (b.exports = d); + }, + { "../utils": 32, "./GenericWorker": 28 }, + ], + 27: [ + function (a, b, c) { + "use strict"; + function d(a) { + f.call(this, "DataWorker"); + var b = this; + (this.dataIsReady = !1), + (this.index = 0), + (this.max = 0), + (this.data = null), + (this.type = ""), + (this._tickScheduled = !1), + a.then( + function (a) { + (b.dataIsReady = !0), + (b.data = a), + (b.max = (a && a.length) || 0), + (b.type = e.getTypeOf(a)), + b.isPaused || b._tickAndRepeat(); + }, + function (a) { + b.error(a); + } + ); + } + var e = a("../utils"), + f = a("./GenericWorker"), + g = 16384; + e.inherits(d, f), + (d.prototype.cleanUp = function () { + f.prototype.cleanUp.call(this), (this.data = null); + }), + (d.prototype.resume = function () { + return ( + !!f.prototype.resume.call(this) && + (!this._tickScheduled && + this.dataIsReady && + ((this._tickScheduled = !0), + e.delay(this._tickAndRepeat, [], this)), + !0) + ); + }), + (d.prototype._tickAndRepeat = function () { + (this._tickScheduled = !1), + this.isPaused || + this.isFinished || + (this._tick(), + this.isFinished || + (e.delay(this._tickAndRepeat, [], this), + (this._tickScheduled = !0))); + }), + (d.prototype._tick = function () { + if (this.isPaused || this.isFinished) return !1; + var a = g, + b = null, + c = Math.min(this.max, this.index + a); + if (this.index >= this.max) return this.end(); + switch (this.type) { + case "string": + b = this.data.substring(this.index, c); + break; + case "uint8array": + b = this.data.subarray(this.index, c); + break; + case "array": + case "nodebuffer": + b = this.data.slice(this.index, c); + } + return ( + (this.index = c), + this.push({ + data: b, + meta: { + percent: this.max ? (this.index / this.max) * 100 : 0, + }, + }) + ); + }), + (b.exports = d); + }, + { "../utils": 32, "./GenericWorker": 28 }, + ], + 28: [ + function (a, b, c) { + "use strict"; + function d(a) { + (this.name = a || "default"), + (this.streamInfo = {}), + (this.generatedError = null), + (this.extraStreamInfo = {}), + (this.isPaused = !0), + (this.isFinished = !1), + (this.isLocked = !1), + (this._listeners = { data: [], end: [], error: [] }), + (this.previous = null); + } + (d.prototype = { + push: function (a) { + this.emit("data", a); + }, + end: function () { + if (this.isFinished) return !1; + this.flush(); + try { + this.emit("end"), this.cleanUp(), (this.isFinished = !0); + } catch (a) { + this.emit("error", a); + } + return !0; + }, + error: function (a) { + return ( + !this.isFinished && + (this.isPaused + ? (this.generatedError = a) + : ((this.isFinished = !0), + this.emit("error", a), + this.previous && this.previous.error(a), + this.cleanUp()), + !0) + ); + }, + on: function (a, b) { + return this._listeners[a].push(b), this; + }, + cleanUp: function () { + (this.streamInfo = + this.generatedError = + this.extraStreamInfo = + null), + (this._listeners = []); + }, + emit: function (a, b) { + if (this._listeners[a]) + for (var c = 0; c < this._listeners[a].length; c++) + this._listeners[a][c].call(this, b); + }, + pipe: function (a) { + return a.registerPrevious(this); + }, + registerPrevious: function (a) { + if (this.isLocked) + throw new Error( + "The stream '" + this + "' has already been used." + ); + (this.streamInfo = a.streamInfo), + this.mergeStreamInfo(), + (this.previous = a); + var b = this; + return ( + a.on("data", function (a) { + b.processChunk(a); + }), + a.on("end", function () { + b.end(); + }), + a.on("error", function (a) { + b.error(a); + }), + this + ); + }, + pause: function () { + return ( + !this.isPaused && + !this.isFinished && + ((this.isPaused = !0), + this.previous && this.previous.pause(), + !0) + ); + }, + resume: function () { + if (!this.isPaused || this.isFinished) return !1; + this.isPaused = !1; + var a = !1; + return ( + this.generatedError && + (this.error(this.generatedError), (a = !0)), + this.previous && this.previous.resume(), + !a + ); + }, + flush: function () {}, + processChunk: function (a) { + this.push(a); + }, + withStreamInfo: function (a, b) { + return ( + (this.extraStreamInfo[a] = b), this.mergeStreamInfo(), this + ); + }, + mergeStreamInfo: function () { + for (var a in this.extraStreamInfo) + this.extraStreamInfo.hasOwnProperty(a) && + (this.streamInfo[a] = this.extraStreamInfo[a]); + }, + lock: function () { + if (this.isLocked) + throw new Error( + "The stream '" + this + "' has already been used." + ); + (this.isLocked = !0), this.previous && this.previous.lock(); + }, + toString: function () { + var a = "Worker " + this.name; + return this.previous ? this.previous + " -> " + a : a; + }, + }), + (b.exports = d); + }, + {}, + ], + 29: [ + function (a, b, c) { + "use strict"; + function d(a, b, c) { + switch (a) { + case "blob": + return h.newBlob(h.transformTo("arraybuffer", b), c); + case "base64": + return k.encode(b); + default: + return h.transformTo(a, b); + } + } + function e(a, b) { + var c, + d = 0, + e = null, + f = 0; + for (c = 0; c < b.length; c++) f += b[c].length; + switch (a) { + case "string": + return b.join(""); + case "array": + return Array.prototype.concat.apply([], b); + case "uint8array": + for (e = new Uint8Array(f), c = 0; c < b.length; c++) + e.set(b[c], d), (d += b[c].length); + return e; + case "nodebuffer": + return Buffer.concat(b); + default: + throw new Error("concat : unsupported type '" + a + "'"); + } + } + function f(a, b) { + return new m.Promise(function (c, f) { + var g = [], + h = a._internalType, + i = a._outputType, + j = a._mimeType; + a.on("data", function (a, c) { + g.push(a), b && b(c); + }) + .on("error", function (a) { + (g = []), f(a); + }) + .on("end", function () { + try { + var a = d(i, e(h, g), j); + c(a); + } catch (b) { + f(b); + } + g = []; + }) + .resume(); + }); + } + function g(a, b, c) { + var d = b; + switch (b) { + case "blob": + case "arraybuffer": + d = "uint8array"; + break; + case "base64": + d = "string"; + } + try { + (this._internalType = d), + (this._outputType = b), + (this._mimeType = c), + h.checkSupport(d), + (this._worker = a.pipe(new i(d))), + a.lock(); + } catch (e) { + (this._worker = new j("error")), this._worker.error(e); + } + } + var h = a("../utils"), + i = a("./ConvertWorker"), + j = a("./GenericWorker"), + k = a("../base64"), + l = a("../support"), + m = a("../external"), + n = null; + if (l.nodestream) + try { + n = a("../nodejs/NodejsStreamOutputAdapter"); + } catch (o) {} + (g.prototype = { + accumulate: function (a) { + return f(this, a); + }, + on: function (a, b) { + var c = this; + return ( + "data" === a + ? this._worker.on(a, function (a) { + b.call(c, a.data, a.meta); + }) + : this._worker.on(a, function () { + h.delay(b, arguments, c); + }), + this + ); + }, + resume: function () { + return h.delay(this._worker.resume, [], this._worker), this; + }, + pause: function () { + return this._worker.pause(), this; + }, + toNodejsStream: function (a) { + if ( + (h.checkSupport("nodestream"), + "nodebuffer" !== this._outputType) + ) + throw new Error( + this._outputType + " is not supported by this method" + ); + return new n( + this, + { objectMode: "nodebuffer" !== this._outputType }, + a + ); + }, + }), + (b.exports = g); + }, + { + "../base64": 1, + "../external": 6, + "../nodejs/NodejsStreamOutputAdapter": 13, + "../support": 30, + "../utils": 32, + "./ConvertWorker": 24, + "./GenericWorker": 28, + }, + ], + 30: [ + function (a, b, c) { + "use strict"; + if ( + ((c.base64 = !0), + (c.array = !0), + (c.string = !0), + (c.arraybuffer = + "undefined" != typeof ArrayBuffer && + "undefined" != typeof Uint8Array), + (c.nodebuffer = "undefined" != typeof Buffer), + (c.uint8array = "undefined" != typeof Uint8Array), + "undefined" == typeof ArrayBuffer) + ) + c.blob = !1; + else { + var d = new ArrayBuffer(0); + try { + c.blob = 0 === new Blob([d], { type: "application/zip" }).size; + } catch (e) { + try { + var f = + self.BlobBuilder || + self.WebKitBlobBuilder || + self.MozBlobBuilder || + self.MSBlobBuilder, + g = new f(); + g.append(d), (c.blob = 0 === g.getBlob("application/zip").size); + } catch (e) { + c.blob = !1; + } + } + } + try { + c.nodestream = !!a("readable-stream").Readable; + } catch (e) { + c.nodestream = !1; + } + }, + { "readable-stream": 16 }, + ], + 31: [ + function (a, b, c) { + "use strict"; + function d() { + i.call(this, "utf-8 decode"), (this.leftOver = null); + } + function e() { + i.call(this, "utf-8 encode"); + } + for ( + var f = a("./utils"), + g = a("./support"), + h = a("./nodejsUtils"), + i = a("./stream/GenericWorker"), + j = new Array(256), + k = 0; + k < 256; + k++ + ) + j[k] = + k >= 252 + ? 6 + : k >= 248 + ? 5 + : k >= 240 + ? 4 + : k >= 224 + ? 3 + : k >= 192 + ? 2 + : 1; + j[254] = j[254] = 1; + var l = function (a) { + var b, + c, + d, + e, + f, + h = a.length, + i = 0; + for (e = 0; e < h; e++) + (c = a.charCodeAt(e)), + 55296 === (64512 & c) && + e + 1 < h && + ((d = a.charCodeAt(e + 1)), + 56320 === (64512 & d) && + ((c = 65536 + ((c - 55296) << 10) + (d - 56320)), e++)), + (i += c < 128 ? 1 : c < 2048 ? 2 : c < 65536 ? 3 : 4); + for ( + b = g.uint8array ? new Uint8Array(i) : new Array(i), + f = 0, + e = 0; + f < i; + e++ + ) + (c = a.charCodeAt(e)), + 55296 === (64512 & c) && + e + 1 < h && + ((d = a.charCodeAt(e + 1)), + 56320 === (64512 & d) && + ((c = 65536 + ((c - 55296) << 10) + (d - 56320)), e++)), + c < 128 + ? (b[f++] = c) + : c < 2048 + ? ((b[f++] = 192 | (c >>> 6)), (b[f++] = 128 | (63 & c))) + : c < 65536 + ? ((b[f++] = 224 | (c >>> 12)), + (b[f++] = 128 | ((c >>> 6) & 63)), + (b[f++] = 128 | (63 & c))) + : ((b[f++] = 240 | (c >>> 18)), + (b[f++] = 128 | ((c >>> 12) & 63)), + (b[f++] = 128 | ((c >>> 6) & 63)), + (b[f++] = 128 | (63 & c))); + return b; + }, + m = function (a, b) { + var c; + for ( + b = b || a.length, b > a.length && (b = a.length), c = b - 1; + c >= 0 && 128 === (192 & a[c]); + + ) + c--; + return c < 0 ? b : 0 === c ? b : c + j[a[c]] > b ? c : b; + }, + n = function (a) { + var b, + c, + d, + e, + g = a.length, + h = new Array(2 * g); + for (c = 0, b = 0; b < g; ) + if (((d = a[b++]), d < 128)) h[c++] = d; + else if (((e = j[d]), e > 4)) (h[c++] = 65533), (b += e - 1); + else { + for (d &= 2 === e ? 31 : 3 === e ? 15 : 7; e > 1 && b < g; ) + (d = (d << 6) | (63 & a[b++])), e--; + e > 1 + ? (h[c++] = 65533) + : d < 65536 + ? (h[c++] = d) + : ((d -= 65536), + (h[c++] = 55296 | ((d >> 10) & 1023)), + (h[c++] = 56320 | (1023 & d))); + } + return ( + h.length !== c && + (h.subarray ? (h = h.subarray(0, c)) : (h.length = c)), + f.applyFromCharCode(h) + ); + }; + (c.utf8encode = function (a) { + return g.nodebuffer ? h.newBufferFrom(a, "utf-8") : l(a); + }), + (c.utf8decode = function (a) { + return g.nodebuffer + ? f.transformTo("nodebuffer", a).toString("utf-8") + : ((a = f.transformTo( + g.uint8array ? "uint8array" : "array", + a + )), + n(a)); + }), + f.inherits(d, i), + (d.prototype.processChunk = function (a) { + var b = f.transformTo( + g.uint8array ? "uint8array" : "array", + a.data + ); + if (this.leftOver && this.leftOver.length) { + if (g.uint8array) { + var d = b; + (b = new Uint8Array(d.length + this.leftOver.length)), + b.set(this.leftOver, 0), + b.set(d, this.leftOver.length); + } else b = this.leftOver.concat(b); + this.leftOver = null; + } + var e = m(b), + h = b; + e !== b.length && + (g.uint8array + ? ((h = b.subarray(0, e)), + (this.leftOver = b.subarray(e, b.length))) + : ((h = b.slice(0, e)), + (this.leftOver = b.slice(e, b.length)))), + this.push({ data: c.utf8decode(h), meta: a.meta }); + }), + (d.prototype.flush = function () { + this.leftOver && + this.leftOver.length && + (this.push({ data: c.utf8decode(this.leftOver), meta: {} }), + (this.leftOver = null)); + }), + (c.Utf8DecodeWorker = d), + f.inherits(e, i), + (e.prototype.processChunk = function (a) { + this.push({ data: c.utf8encode(a.data), meta: a.meta }); + }), + (c.Utf8EncodeWorker = e); + }, + { + "./nodejsUtils": 14, + "./stream/GenericWorker": 28, + "./support": 30, + "./utils": 32, + }, + ], + 32: [ + function (a, b, c) { + "use strict"; + function d(a) { + var b = null; + return ( + (b = i.uint8array + ? new Uint8Array(a.length) + : new Array(a.length)), + f(a, b) + ); + } + function e(a) { + return a; + } + function f(a, b) { + for (var c = 0; c < a.length; ++c) b[c] = 255 & a.charCodeAt(c); + return b; + } + function g(a) { + var b = 65536, + d = c.getTypeOf(a), + e = !0; + if ( + ("uint8array" === d + ? (e = n.applyCanBeUsed.uint8array) + : "nodebuffer" === d && (e = n.applyCanBeUsed.nodebuffer), + e) + ) + for (; b > 1; ) + try { + return n.stringifyByChunk(a, d, b); + } catch (f) { + b = Math.floor(b / 2); + } + return n.stringifyByChar(a); + } + function h(a, b) { + for (var c = 0; c < a.length; c++) b[c] = a[c]; + return b; + } + var i = a("./support"), + j = a("./base64"), + k = a("./nodejsUtils"), + l = a("set-immediate-shim"), + m = a("./external"); + c.newBlob = function (a, b) { + c.checkSupport("blob"); + try { + return new Blob([a], { type: b }); + } catch (d) { + try { + var e = + self.BlobBuilder || + self.WebKitBlobBuilder || + self.MozBlobBuilder || + self.MSBlobBuilder, + f = new e(); + return f.append(a), f.getBlob(b); + } catch (d) { + throw new Error("Bug : can't construct the Blob."); + } + } + }; + var n = { + stringifyByChunk: function (a, b, c) { + var d = [], + e = 0, + f = a.length; + if (f <= c) return String.fromCharCode.apply(null, a); + for (; e < f; ) + "array" === b || "nodebuffer" === b + ? d.push( + String.fromCharCode.apply( + null, + a.slice(e, Math.min(e + c, f)) + ) + ) + : d.push( + String.fromCharCode.apply( + null, + a.subarray(e, Math.min(e + c, f)) + ) + ), + (e += c); + return d.join(""); + }, + stringifyByChar: function (a) { + for (var b = "", c = 0; c < a.length; c++) + b += String.fromCharCode(a[c]); + return b; + }, + applyCanBeUsed: { + uint8array: (function () { + try { + return ( + i.uint8array && + 1 === + String.fromCharCode.apply(null, new Uint8Array(1)).length + ); + } catch (a) { + return !1; + } + })(), + nodebuffer: (function () { + try { + return ( + i.nodebuffer && + 1 === + String.fromCharCode.apply(null, k.allocBuffer(1)).length + ); + } catch (a) { + return !1; + } + })(), + }, + }; + c.applyFromCharCode = g; + var o = {}; + (o.string = { + string: e, + array: function (a) { + return f(a, new Array(a.length)); + }, + arraybuffer: function (a) { + return o.string.uint8array(a).buffer; + }, + uint8array: function (a) { + return f(a, new Uint8Array(a.length)); + }, + nodebuffer: function (a) { + return f(a, k.allocBuffer(a.length)); + }, + }), + (o.array = { + string: g, + array: e, + arraybuffer: function (a) { + return new Uint8Array(a).buffer; + }, + uint8array: function (a) { + return new Uint8Array(a); + }, + nodebuffer: function (a) { + return k.newBufferFrom(a); + }, + }), + (o.arraybuffer = { + string: function (a) { + return g(new Uint8Array(a)); + }, + array: function (a) { + return h(new Uint8Array(a), new Array(a.byteLength)); + }, + arraybuffer: e, + uint8array: function (a) { + return new Uint8Array(a); + }, + nodebuffer: function (a) { + return k.newBufferFrom(new Uint8Array(a)); + }, + }), + (o.uint8array = { + string: g, + array: function (a) { + return h(a, new Array(a.length)); + }, + arraybuffer: function (a) { + return a.buffer; + }, + uint8array: e, + nodebuffer: function (a) { + return k.newBufferFrom(a); + }, + }), + (o.nodebuffer = { + string: g, + array: function (a) { + return h(a, new Array(a.length)); + }, + arraybuffer: function (a) { + return o.nodebuffer.uint8array(a).buffer; + }, + uint8array: function (a) { + return h(a, new Uint8Array(a.length)); + }, + nodebuffer: e, + }), + (c.transformTo = function (a, b) { + if ((b || (b = ""), !a)) return b; + c.checkSupport(a); + var d = c.getTypeOf(b), + e = o[d][a](b); + return e; + }), + (c.getTypeOf = function (a) { + return "string" == typeof a + ? "string" + : "[object Array]" === Object.prototype.toString.call(a) + ? "array" + : i.nodebuffer && k.isBuffer(a) + ? "nodebuffer" + : i.uint8array && a instanceof Uint8Array + ? "uint8array" + : i.arraybuffer && a instanceof ArrayBuffer + ? "arraybuffer" + : void 0; + }), + (c.checkSupport = function (a) { + var b = i[a.toLowerCase()]; + if (!b) throw new Error(a + " is not supported by this platform"); + }), + (c.MAX_VALUE_16BITS = 65535), + (c.MAX_VALUE_32BITS = -1), + (c.pretty = function (a) { + var b, + c, + d = ""; + for (c = 0; c < (a || "").length; c++) + (b = a.charCodeAt(c)), + (d += + "\\x" + (b < 16 ? "0" : "") + b.toString(16).toUpperCase()); + return d; + }), + (c.delay = function (a, b, c) { + l(function () { + a.apply(c || null, b || []); + }); + }), + (c.inherits = function (a, b) { + var c = function () {}; + (c.prototype = b.prototype), (a.prototype = new c()); + }), + (c.extend = function () { + var a, + b, + c = {}; + for (a = 0; a < arguments.length; a++) + for (b in arguments[a]) + arguments[a].hasOwnProperty(b) && + "undefined" == typeof c[b] && + (c[b] = arguments[a][b]); + return c; + }), + (c.prepareContent = function (a, b, e, f, g) { + var h = m.Promise.resolve(b).then(function (a) { + var b = + i.blob && + (a instanceof Blob || + ["[object File]", "[object Blob]"].indexOf( + Object.prototype.toString.call(a) + ) !== -1); + return b && "undefined" != typeof FileReader + ? new m.Promise(function (b, c) { + var d = new FileReader(); + (d.onload = function (a) { + b(a.target.result); + }), + (d.onerror = function (a) { + c(a.target.error); + }), + d.readAsArrayBuffer(a); + }) + : a; + }); + return h.then(function (b) { + var h = c.getTypeOf(b); + return h + ? ("arraybuffer" === h + ? (b = c.transformTo("uint8array", b)) + : "string" === h && + (g ? (b = j.decode(b)) : e && f !== !0 && (b = d(b))), + b) + : m.Promise.reject( + new Error( + "Can't read the data of '" + + a + + "'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?" + ) + ); + }); + }); + }, + { + "./base64": 1, + "./external": 6, + "./nodejsUtils": 14, + "./support": 30, + "set-immediate-shim": 54, + }, + ], + 33: [ + function (a, b, c) { + "use strict"; + function d(a) { + (this.files = []), (this.loadOptions = a); + } + var e = a("./reader/readerFor"), + f = a("./utils"), + g = a("./signature"), + h = a("./zipEntry"), + i = (a("./utf8"), a("./support")); + (d.prototype = { + checkSignature: function (a) { + if (!this.reader.readAndCheckSignature(a)) { + this.reader.index -= 4; + var b = this.reader.readString(4); + throw new Error( + "Corrupted zip or bug: unexpected signature (" + + f.pretty(b) + + ", expected " + + f.pretty(a) + + ")" + ); + } + }, + isSignature: function (a, b) { + var c = this.reader.index; + this.reader.setIndex(a); + var d = this.reader.readString(4), + e = d === b; + return this.reader.setIndex(c), e; + }, + readBlockEndOfCentral: function () { + (this.diskNumber = this.reader.readInt(2)), + (this.diskWithCentralDirStart = this.reader.readInt(2)), + (this.centralDirRecordsOnThisDisk = this.reader.readInt(2)), + (this.centralDirRecords = this.reader.readInt(2)), + (this.centralDirSize = this.reader.readInt(4)), + (this.centralDirOffset = this.reader.readInt(4)), + (this.zipCommentLength = this.reader.readInt(2)); + var a = this.reader.readData(this.zipCommentLength), + b = i.uint8array ? "uint8array" : "array", + c = f.transformTo(b, a); + this.zipComment = this.loadOptions.decodeFileName(c); + }, + readBlockZip64EndOfCentral: function () { + (this.zip64EndOfCentralSize = this.reader.readInt(8)), + this.reader.skip(4), + (this.diskNumber = this.reader.readInt(4)), + (this.diskWithCentralDirStart = this.reader.readInt(4)), + (this.centralDirRecordsOnThisDisk = this.reader.readInt(8)), + (this.centralDirRecords = this.reader.readInt(8)), + (this.centralDirSize = this.reader.readInt(8)), + (this.centralDirOffset = this.reader.readInt(8)), + (this.zip64ExtensibleData = {}); + for ( + var a, b, c, d = this.zip64EndOfCentralSize - 44, e = 0; + e < d; + + ) + (a = this.reader.readInt(2)), + (b = this.reader.readInt(4)), + (c = this.reader.readData(b)), + (this.zip64ExtensibleData[a] = { + id: a, + length: b, + value: c, + }); + }, + readBlockZip64EndOfCentralLocator: function () { + if ( + ((this.diskWithZip64CentralDirStart = this.reader.readInt(4)), + (this.relativeOffsetEndOfZip64CentralDir = + this.reader.readInt(8)), + (this.disksCount = this.reader.readInt(4)), + this.disksCount > 1) + ) + throw new Error("Multi-volumes zip are not supported"); + }, + readLocalFiles: function () { + var a, b; + for (a = 0; a < this.files.length; a++) + (b = this.files[a]), + this.reader.setIndex(b.localHeaderOffset), + this.checkSignature(g.LOCAL_FILE_HEADER), + b.readLocalPart(this.reader), + b.handleUTF8(), + b.processAttributes(); + }, + readCentralDir: function () { + var a; + for ( + this.reader.setIndex(this.centralDirOffset); + this.reader.readAndCheckSignature(g.CENTRAL_FILE_HEADER); + + ) + (a = new h({ zip64: this.zip64 }, this.loadOptions)), + a.readCentralPart(this.reader), + this.files.push(a); + if ( + this.centralDirRecords !== this.files.length && + 0 !== this.centralDirRecords && + 0 === this.files.length + ) + throw new Error( + "Corrupted zip or bug: expected " + + this.centralDirRecords + + " records in central dir, got " + + this.files.length + ); + }, + readEndOfCentral: function () { + var a = this.reader.lastIndexOfSignature(g.CENTRAL_DIRECTORY_END); + if (a < 0) { + var b = !this.isSignature(0, g.LOCAL_FILE_HEADER); + throw b + ? new Error( + "Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html" + ) + : new Error( + "Corrupted zip: can't find end of central directory" + ); + } + this.reader.setIndex(a); + var c = a; + if ( + (this.checkSignature(g.CENTRAL_DIRECTORY_END), + this.readBlockEndOfCentral(), + this.diskNumber === f.MAX_VALUE_16BITS || + this.diskWithCentralDirStart === f.MAX_VALUE_16BITS || + this.centralDirRecordsOnThisDisk === f.MAX_VALUE_16BITS || + this.centralDirRecords === f.MAX_VALUE_16BITS || + this.centralDirSize === f.MAX_VALUE_32BITS || + this.centralDirOffset === f.MAX_VALUE_32BITS) + ) { + if ( + ((this.zip64 = !0), + (a = this.reader.lastIndexOfSignature( + g.ZIP64_CENTRAL_DIRECTORY_LOCATOR + )), + a < 0) + ) + throw new Error( + "Corrupted zip: can't find the ZIP64 end of central directory locator" + ); + if ( + (this.reader.setIndex(a), + this.checkSignature(g.ZIP64_CENTRAL_DIRECTORY_LOCATOR), + this.readBlockZip64EndOfCentralLocator(), + !this.isSignature( + this.relativeOffsetEndOfZip64CentralDir, + g.ZIP64_CENTRAL_DIRECTORY_END + ) && + ((this.relativeOffsetEndOfZip64CentralDir = + this.reader.lastIndexOfSignature( + g.ZIP64_CENTRAL_DIRECTORY_END + )), + this.relativeOffsetEndOfZip64CentralDir < 0)) + ) + throw new Error( + "Corrupted zip: can't find the ZIP64 end of central directory" + ); + this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir), + this.checkSignature(g.ZIP64_CENTRAL_DIRECTORY_END), + this.readBlockZip64EndOfCentral(); + } + var d = this.centralDirOffset + this.centralDirSize; + this.zip64 && ((d += 20), (d += 12 + this.zip64EndOfCentralSize)); + var e = c - d; + if (e > 0) + this.isSignature(c, g.CENTRAL_FILE_HEADER) || + (this.reader.zero = e); + else if (e < 0) + throw new Error( + "Corrupted zip: missing " + Math.abs(e) + " bytes." + ); + }, + prepareReader: function (a) { + this.reader = e(a); + }, + load: function (a) { + this.prepareReader(a), + this.readEndOfCentral(), + this.readCentralDir(), + this.readLocalFiles(); + }, + }), + (b.exports = d); + }, + { + "./reader/readerFor": 22, + "./signature": 23, + "./support": 30, + "./utf8": 31, + "./utils": 32, + "./zipEntry": 34, + }, + ], + 34: [ + function (a, b, c) { + "use strict"; + function d(a, b) { + (this.options = a), (this.loadOptions = b); + } + var e = a("./reader/readerFor"), + f = a("./utils"), + g = a("./compressedObject"), + h = a("./crc32"), + i = a("./utf8"), + j = a("./compressions"), + k = a("./support"), + l = 0, + m = 3, + n = function (a) { + for (var b in j) + if (j.hasOwnProperty(b) && j[b].magic === a) return j[b]; + return null; + }; + (d.prototype = { + isEncrypted: function () { + return 1 === (1 & this.bitFlag); + }, + useUTF8: function () { + return 2048 === (2048 & this.bitFlag); + }, + readLocalPart: function (a) { + var b, c; + if ( + (a.skip(22), + (this.fileNameLength = a.readInt(2)), + (c = a.readInt(2)), + (this.fileName = a.readData(this.fileNameLength)), + a.skip(c), + this.compressedSize === -1 || this.uncompressedSize === -1) + ) + throw new Error( + "Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize === -1 || uncompressedSize === -1)" + ); + if (((b = n(this.compressionMethod)), null === b)) + throw new Error( + "Corrupted zip : compression " + + f.pretty(this.compressionMethod) + + " unknown (inner file : " + + f.transformTo("string", this.fileName) + + ")" + ); + this.decompressed = new g( + this.compressedSize, + this.uncompressedSize, + this.crc32, + b, + a.readData(this.compressedSize) + ); + }, + readCentralPart: function (a) { + (this.versionMadeBy = a.readInt(2)), + a.skip(2), + (this.bitFlag = a.readInt(2)), + (this.compressionMethod = a.readString(2)), + (this.date = a.readDate()), + (this.crc32 = a.readInt(4)), + (this.compressedSize = a.readInt(4)), + (this.uncompressedSize = a.readInt(4)); + var b = a.readInt(2); + if ( + ((this.extraFieldsLength = a.readInt(2)), + (this.fileCommentLength = a.readInt(2)), + (this.diskNumberStart = a.readInt(2)), + (this.internalFileAttributes = a.readInt(2)), + (this.externalFileAttributes = a.readInt(4)), + (this.localHeaderOffset = a.readInt(4)), + this.isEncrypted()) + ) + throw new Error("Encrypted zip are not supported"); + a.skip(b), + this.readExtraFields(a), + this.parseZIP64ExtraField(a), + (this.fileComment = a.readData(this.fileCommentLength)); + }, + processAttributes: function () { + (this.unixPermissions = null), (this.dosPermissions = null); + var a = this.versionMadeBy >> 8; + (this.dir = !!(16 & this.externalFileAttributes)), + a === l && + (this.dosPermissions = 63 & this.externalFileAttributes), + a === m && + (this.unixPermissions = + (this.externalFileAttributes >> 16) & 65535), + this.dir || + "/" !== this.fileNameStr.slice(-1) || + (this.dir = !0); + }, + parseZIP64ExtraField: function (a) { + if (this.extraFields[1]) { + var b = e(this.extraFields[1].value); + this.uncompressedSize === f.MAX_VALUE_32BITS && + (this.uncompressedSize = b.readInt(8)), + this.compressedSize === f.MAX_VALUE_32BITS && + (this.compressedSize = b.readInt(8)), + this.localHeaderOffset === f.MAX_VALUE_32BITS && + (this.localHeaderOffset = b.readInt(8)), + this.diskNumberStart === f.MAX_VALUE_32BITS && + (this.diskNumberStart = b.readInt(4)); + } + }, + readExtraFields: function (a) { + var b, + c, + d, + e = a.index + this.extraFieldsLength; + for (this.extraFields || (this.extraFields = {}); a.index < e; ) + (b = a.readInt(2)), + (c = a.readInt(2)), + (d = a.readData(c)), + (this.extraFields[b] = { id: b, length: c, value: d }); + }, + handleUTF8: function () { + var a = k.uint8array ? "uint8array" : "array"; + if (this.useUTF8()) + (this.fileNameStr = i.utf8decode(this.fileName)), + (this.fileCommentStr = i.utf8decode(this.fileComment)); + else { + var b = this.findExtraFieldUnicodePath(); + if (null !== b) this.fileNameStr = b; + else { + var c = f.transformTo(a, this.fileName); + this.fileNameStr = this.loadOptions.decodeFileName(c); + } + var d = this.findExtraFieldUnicodeComment(); + if (null !== d) this.fileCommentStr = d; + else { + var e = f.transformTo(a, this.fileComment); + this.fileCommentStr = this.loadOptions.decodeFileName(e); + } + } + }, + findExtraFieldUnicodePath: function () { + var a = this.extraFields[28789]; + if (a) { + var b = e(a.value); + return 1 !== b.readInt(1) + ? null + : h(this.fileName) !== b.readInt(4) + ? null + : i.utf8decode(b.readData(a.length - 5)); + } + return null; + }, + findExtraFieldUnicodeComment: function () { + var a = this.extraFields[25461]; + if (a) { + var b = e(a.value); + return 1 !== b.readInt(1) + ? null + : h(this.fileComment) !== b.readInt(4) + ? null + : i.utf8decode(b.readData(a.length - 5)); + } + return null; + }, + }), + (b.exports = d); + }, + { + "./compressedObject": 2, + "./compressions": 3, + "./crc32": 4, + "./reader/readerFor": 22, + "./support": 30, + "./utf8": 31, + "./utils": 32, + }, + ], + 35: [ + function (a, b, c) { + "use strict"; + var d = a("./stream/StreamHelper"), + e = a("./stream/DataWorker"), + f = a("./utf8"), + g = a("./compressedObject"), + h = a("./stream/GenericWorker"), + i = function (a, b, c) { + (this.name = a), + (this.dir = c.dir), + (this.date = c.date), + (this.comment = c.comment), + (this.unixPermissions = c.unixPermissions), + (this.dosPermissions = c.dosPermissions), + (this._data = b), + (this._dataBinary = c.binary), + (this.options = { + compression: c.compression, + compressionOptions: c.compressionOptions, + }); + }; + i.prototype = { + internalStream: function (a) { + var b = null, + c = "string"; + try { + if (!a) throw new Error("No output type specified."); + c = a.toLowerCase(); + var e = "string" === c || "text" === c; + ("binarystring" !== c && "text" !== c) || (c = "string"), + (b = this._decompressWorker()); + var g = !this._dataBinary; + g && !e && (b = b.pipe(new f.Utf8EncodeWorker())), + !g && e && (b = b.pipe(new f.Utf8DecodeWorker())); + } catch (i) { + (b = new h("error")), b.error(i); + } + return new d(b, c, ""); + }, + async: function (a, b) { + return this.internalStream(a).accumulate(b); + }, + nodeStream: function (a, b) { + return this.internalStream(a || "nodebuffer").toNodejsStream(b); + }, + _compressWorker: function (a, b) { + if ( + this._data instanceof g && + this._data.compression.magic === a.magic + ) + return this._data.getCompressedWorker(); + var c = this._decompressWorker(); + return ( + this._dataBinary || (c = c.pipe(new f.Utf8EncodeWorker())), + g.createWorkerFrom(c, a, b) + ); + }, + _decompressWorker: function () { + return this._data instanceof g + ? this._data.getContentWorker() + : this._data instanceof h + ? this._data + : new e(this._data); + }, + }; + for ( + var j = [ + "asText", + "asBinary", + "asNodeBuffer", + "asUint8Array", + "asArrayBuffer", + ], + k = function () { + throw new Error( + "This method has been removed in JSZip 3.0, please check the upgrade guide." + ); + }, + l = 0; + l < j.length; + l++ + ) + i.prototype[j[l]] = k; + b.exports = i; + }, + { + "./compressedObject": 2, + "./stream/DataWorker": 27, + "./stream/GenericWorker": 28, + "./stream/StreamHelper": 29, + "./utf8": 31, + }, + ], + 36: [ + function (a, b, c) { + (function (a) { + "use strict"; + function c() { + k = !0; + for (var a, b, c = l.length; c; ) { + for (b = l, l = [], a = -1; ++a < c; ) b[a](); + c = l.length; + } + k = !1; + } + function d(a) { + 1 !== l.push(a) || k || e(); + } + var e, + f = a.MutationObserver || a.WebKitMutationObserver; + if (f) { + var g = 0, + h = new f(c), + i = a.document.createTextNode(""); + h.observe(i, { characterData: !0 }), + (e = function () { + i.data = g = ++g % 2; + }); + } else if (a.setImmediate || "undefined" == typeof a.MessageChannel) + e = + "document" in a && + "onreadystatechange" in a.document.createElement("script") + ? function () { + var b = a.document.createElement("script"); + (b.onreadystatechange = function () { + c(), + (b.onreadystatechange = null), + b.parentNode.removeChild(b), + (b = null); + }), + a.document.documentElement.appendChild(b); + } + : function () { + setTimeout(c, 0); + }; + else { + var j = new a.MessageChannel(); + (j.port1.onmessage = c), + (e = function () { + j.port2.postMessage(0); + }); + } + var k, + l = []; + b.exports = d; + }).call( + this, + "undefined" != typeof global + ? global + : "undefined" != typeof self + ? self + : "undefined" != typeof window + ? window + : {} + ); + }, + {}, + ], + 37: [ + function (a, b, c) { + "use strict"; + function d() {} + function e(a) { + if ("function" != typeof a) + throw new TypeError("resolver must be a function"); + (this.state = s), + (this.queue = []), + (this.outcome = void 0), + a !== d && i(this, a); + } + function f(a, b, c) { + (this.promise = a), + "function" == typeof b && + ((this.onFulfilled = b), + (this.callFulfilled = this.otherCallFulfilled)), + "function" == typeof c && + ((this.onRejected = c), + (this.callRejected = this.otherCallRejected)); + } + function g(a, b, c) { + o(function () { + var d; + try { + d = b(c); + } catch (e) { + return p.reject(a, e); + } + d === a + ? p.reject( + a, + new TypeError("Cannot resolve promise with itself") + ) + : p.resolve(a, d); + }); + } + function h(a) { + var b = a && a.then; + if ( + a && + ("object" == typeof a || "function" == typeof a) && + "function" == typeof b + ) + return function () { + b.apply(a, arguments); + }; + } + function i(a, b) { + function c(b) { + f || ((f = !0), p.reject(a, b)); + } + function d(b) { + f || ((f = !0), p.resolve(a, b)); + } + function e() { + b(d, c); + } + var f = !1, + g = j(e); + "error" === g.status && c(g.value); + } + function j(a, b) { + var c = {}; + try { + (c.value = a(b)), (c.status = "success"); + } catch (d) { + (c.status = "error"), (c.value = d); + } + return c; + } + function k(a) { + return a instanceof this ? a : p.resolve(new this(d), a); + } + function l(a) { + var b = new this(d); + return p.reject(b, a); + } + function m(a) { + function b(a, b) { + function d(a) { + (g[b] = a), ++h !== e || f || ((f = !0), p.resolve(j, g)); + } + c.resolve(a).then(d, function (a) { + f || ((f = !0), p.reject(j, a)); + }); + } + var c = this; + if ("[object Array]" !== Object.prototype.toString.call(a)) + return this.reject(new TypeError("must be an array")); + var e = a.length, + f = !1; + if (!e) return this.resolve([]); + for ( + var g = new Array(e), h = 0, i = -1, j = new this(d); + ++i < e; + + ) + b(a[i], i); + return j; + } + function n(a) { + function b(a) { + c.resolve(a).then( + function (a) { + f || ((f = !0), p.resolve(h, a)); + }, + function (a) { + f || ((f = !0), p.reject(h, a)); + } + ); + } + var c = this; + if ("[object Array]" !== Object.prototype.toString.call(a)) + return this.reject(new TypeError("must be an array")); + var e = a.length, + f = !1; + if (!e) return this.resolve([]); + for (var g = -1, h = new this(d); ++g < e; ) b(a[g]); + return h; + } + var o = a("immediate"), + p = {}, + q = ["REJECTED"], + r = ["FULFILLED"], + s = ["PENDING"]; + (b.exports = e), + (e.prototype["finally"] = function (a) { + function b(b) { + function c() { + return b; + } + return d.resolve(a()).then(c); + } + function c(b) { + function c() { + throw b; + } + return d.resolve(a()).then(c); + } + if ("function" != typeof a) return this; + var d = this.constructor; + return this.then(b, c); + }), + (e.prototype["catch"] = function (a) { + return this.then(null, a); + }), + (e.prototype.then = function (a, b) { + if ( + ("function" != typeof a && this.state === r) || + ("function" != typeof b && this.state === q) + ) + return this; + var c = new this.constructor(d); + if (this.state !== s) { + var e = this.state === r ? a : b; + g(c, e, this.outcome); + } else this.queue.push(new f(c, a, b)); + return c; + }), + (f.prototype.callFulfilled = function (a) { + p.resolve(this.promise, a); + }), + (f.prototype.otherCallFulfilled = function (a) { + g(this.promise, this.onFulfilled, a); + }), + (f.prototype.callRejected = function (a) { + p.reject(this.promise, a); + }), + (f.prototype.otherCallRejected = function (a) { + g(this.promise, this.onRejected, a); + }), + (p.resolve = function (a, b) { + var c = j(h, b); + if ("error" === c.status) return p.reject(a, c.value); + var d = c.value; + if (d) i(a, d); + else { + (a.state = r), (a.outcome = b); + for (var e = -1, f = a.queue.length; ++e < f; ) + a.queue[e].callFulfilled(b); + } + return a; + }), + (p.reject = function (a, b) { + (a.state = q), (a.outcome = b); + for (var c = -1, d = a.queue.length; ++c < d; ) + a.queue[c].callRejected(b); + return a; + }), + (e.resolve = k), + (e.reject = l), + (e.all = m), + (e.race = n); + }, + { immediate: 36 }, + ], + 38: [ + function (a, b, c) { + "use strict"; + var d = a("./lib/utils/common").assign, + e = a("./lib/deflate"), + f = a("./lib/inflate"), + g = a("./lib/zlib/constants"), + h = {}; + d(h, e, f, g), (b.exports = h); + }, + { + "./lib/deflate": 39, + "./lib/inflate": 40, + "./lib/utils/common": 41, + "./lib/zlib/constants": 44, + }, + ], + 39: [ + function (a, b, c) { + "use strict"; + function d(a) { + if (!(this instanceof d)) return new d(a); + this.options = i.assign( + { + level: s, + method: u, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: t, + to: "", + }, + a || {} + ); + var b = this.options; + b.raw && b.windowBits > 0 + ? (b.windowBits = -b.windowBits) + : b.gzip && + b.windowBits > 0 && + b.windowBits < 16 && + (b.windowBits += 16), + (this.err = 0), + (this.msg = ""), + (this.ended = !1), + (this.chunks = []), + (this.strm = new l()), + (this.strm.avail_out = 0); + var c = h.deflateInit2( + this.strm, + b.level, + b.method, + b.windowBits, + b.memLevel, + b.strategy + ); + if (c !== p) throw new Error(k[c]); + if ( + (b.header && h.deflateSetHeader(this.strm, b.header), + b.dictionary) + ) { + var e; + if ( + ((e = + "string" == typeof b.dictionary + ? j.string2buf(b.dictionary) + : "[object ArrayBuffer]" === m.call(b.dictionary) + ? new Uint8Array(b.dictionary) + : b.dictionary), + (c = h.deflateSetDictionary(this.strm, e)), + c !== p) + ) + throw new Error(k[c]); + this._dict_set = !0; + } + } + function e(a, b) { + var c = new d(b); + if ((c.push(a, !0), c.err)) throw c.msg || k[c.err]; + return c.result; + } + function f(a, b) { + return (b = b || {}), (b.raw = !0), e(a, b); + } + function g(a, b) { + return (b = b || {}), (b.gzip = !0), e(a, b); + } + var h = a("./zlib/deflate"), + i = a("./utils/common"), + j = a("./utils/strings"), + k = a("./zlib/messages"), + l = a("./zlib/zstream"), + m = Object.prototype.toString, + n = 0, + o = 4, + p = 0, + q = 1, + r = 2, + s = -1, + t = 0, + u = 8; + (d.prototype.push = function (a, b) { + var c, + d, + e = this.strm, + f = this.options.chunkSize; + if (this.ended) return !1; + (d = b === ~~b ? b : b === !0 ? o : n), + "string" == typeof a + ? (e.input = j.string2buf(a)) + : "[object ArrayBuffer]" === m.call(a) + ? (e.input = new Uint8Array(a)) + : (e.input = a), + (e.next_in = 0), + (e.avail_in = e.input.length); + do { + if ( + (0 === e.avail_out && + ((e.output = new i.Buf8(f)), + (e.next_out = 0), + (e.avail_out = f)), + (c = h.deflate(e, d)), + c !== q && c !== p) + ) + return this.onEnd(c), (this.ended = !0), !1; + (0 !== e.avail_out && + (0 !== e.avail_in || (d !== o && d !== r))) || + ("string" === this.options.to + ? this.onData( + j.buf2binstring(i.shrinkBuf(e.output, e.next_out)) + ) + : this.onData(i.shrinkBuf(e.output, e.next_out))); + } while ((e.avail_in > 0 || 0 === e.avail_out) && c !== q); + return d === o + ? ((c = h.deflateEnd(this.strm)), + this.onEnd(c), + (this.ended = !0), + c === p) + : d !== r || (this.onEnd(p), (e.avail_out = 0), !0); + }), + (d.prototype.onData = function (a) { + this.chunks.push(a); + }), + (d.prototype.onEnd = function (a) { + a === p && + ("string" === this.options.to + ? (this.result = this.chunks.join("")) + : (this.result = i.flattenChunks(this.chunks))), + (this.chunks = []), + (this.err = a), + (this.msg = this.strm.msg); + }), + (c.Deflate = d), + (c.deflate = e), + (c.deflateRaw = f), + (c.gzip = g); + }, + { + "./utils/common": 41, + "./utils/strings": 42, + "./zlib/deflate": 46, + "./zlib/messages": 51, + "./zlib/zstream": 53, + }, + ], + 40: [ + function (a, b, c) { + "use strict"; + function d(a) { + if (!(this instanceof d)) return new d(a); + this.options = h.assign( + { chunkSize: 16384, windowBits: 0, to: "" }, + a || {} + ); + var b = this.options; + b.raw && + b.windowBits >= 0 && + b.windowBits < 16 && + ((b.windowBits = -b.windowBits), + 0 === b.windowBits && (b.windowBits = -15)), + !(b.windowBits >= 0 && b.windowBits < 16) || + (a && a.windowBits) || + (b.windowBits += 32), + b.windowBits > 15 && + b.windowBits < 48 && + 0 === (15 & b.windowBits) && + (b.windowBits |= 15), + (this.err = 0), + (this.msg = ""), + (this.ended = !1), + (this.chunks = []), + (this.strm = new l()), + (this.strm.avail_out = 0); + var c = g.inflateInit2(this.strm, b.windowBits); + if (c !== j.Z_OK) throw new Error(k[c]); + (this.header = new m()), g.inflateGetHeader(this.strm, this.header); + } + function e(a, b) { + var c = new d(b); + if ((c.push(a, !0), c.err)) throw c.msg || k[c.err]; + return c.result; + } + function f(a, b) { + return (b = b || {}), (b.raw = !0), e(a, b); + } + var g = a("./zlib/inflate"), + h = a("./utils/common"), + i = a("./utils/strings"), + j = a("./zlib/constants"), + k = a("./zlib/messages"), + l = a("./zlib/zstream"), + m = a("./zlib/gzheader"), + n = Object.prototype.toString; + (d.prototype.push = function (a, b) { + var c, + d, + e, + f, + k, + l, + m = this.strm, + o = this.options.chunkSize, + p = this.options.dictionary, + q = !1; + if (this.ended) return !1; + (d = b === ~~b ? b : b === !0 ? j.Z_FINISH : j.Z_NO_FLUSH), + "string" == typeof a + ? (m.input = i.binstring2buf(a)) + : "[object ArrayBuffer]" === n.call(a) + ? (m.input = new Uint8Array(a)) + : (m.input = a), + (m.next_in = 0), + (m.avail_in = m.input.length); + do { + if ( + (0 === m.avail_out && + ((m.output = new h.Buf8(o)), + (m.next_out = 0), + (m.avail_out = o)), + (c = g.inflate(m, j.Z_NO_FLUSH)), + c === j.Z_NEED_DICT && + p && + ((l = + "string" == typeof p + ? i.string2buf(p) + : "[object ArrayBuffer]" === n.call(p) + ? new Uint8Array(p) + : p), + (c = g.inflateSetDictionary(this.strm, l))), + c === j.Z_BUF_ERROR && q === !0 && ((c = j.Z_OK), (q = !1)), + c !== j.Z_STREAM_END && c !== j.Z_OK) + ) + return this.onEnd(c), (this.ended = !0), !1; + m.next_out && + ((0 !== m.avail_out && + c !== j.Z_STREAM_END && + (0 !== m.avail_in || + (d !== j.Z_FINISH && d !== j.Z_SYNC_FLUSH))) || + ("string" === this.options.to + ? ((e = i.utf8border(m.output, m.next_out)), + (f = m.next_out - e), + (k = i.buf2string(m.output, e)), + (m.next_out = f), + (m.avail_out = o - f), + f && h.arraySet(m.output, m.output, e, f, 0), + this.onData(k)) + : this.onData(h.shrinkBuf(m.output, m.next_out)))), + 0 === m.avail_in && 0 === m.avail_out && (q = !0); + } while ( + (m.avail_in > 0 || 0 === m.avail_out) && + c !== j.Z_STREAM_END + ); + return ( + c === j.Z_STREAM_END && (d = j.Z_FINISH), + d === j.Z_FINISH + ? ((c = g.inflateEnd(this.strm)), + this.onEnd(c), + (this.ended = !0), + c === j.Z_OK) + : d !== j.Z_SYNC_FLUSH || + (this.onEnd(j.Z_OK), (m.avail_out = 0), !0) + ); + }), + (d.prototype.onData = function (a) { + this.chunks.push(a); + }), + (d.prototype.onEnd = function (a) { + a === j.Z_OK && + ("string" === this.options.to + ? (this.result = this.chunks.join("")) + : (this.result = h.flattenChunks(this.chunks))), + (this.chunks = []), + (this.err = a), + (this.msg = this.strm.msg); + }), + (c.Inflate = d), + (c.inflate = e), + (c.inflateRaw = f), + (c.ungzip = e); + }, + { + "./utils/common": 41, + "./utils/strings": 42, + "./zlib/constants": 44, + "./zlib/gzheader": 47, + "./zlib/inflate": 49, + "./zlib/messages": 51, + "./zlib/zstream": 53, + }, + ], + 41: [ + function (a, b, c) { + "use strict"; + var d = + "undefined" != typeof Uint8Array && + "undefined" != typeof Uint16Array && + "undefined" != typeof Int32Array; + (c.assign = function (a) { + for (var b = Array.prototype.slice.call(arguments, 1); b.length; ) { + var c = b.shift(); + if (c) { + if ("object" != typeof c) + throw new TypeError(c + "must be non-object"); + for (var d in c) c.hasOwnProperty(d) && (a[d] = c[d]); + } + } + return a; + }), + (c.shrinkBuf = function (a, b) { + return a.length === b + ? a + : a.subarray + ? a.subarray(0, b) + : ((a.length = b), a); + }); + var e = { + arraySet: function (a, b, c, d, e) { + if (b.subarray && a.subarray) + return void a.set(b.subarray(c, c + d), e); + for (var f = 0; f < d; f++) a[e + f] = b[c + f]; + }, + flattenChunks: function (a) { + var b, c, d, e, f, g; + for (d = 0, b = 0, c = a.length; b < c; b++) d += a[b].length; + for ( + g = new Uint8Array(d), e = 0, b = 0, c = a.length; + b < c; + b++ + ) + (f = a[b]), g.set(f, e), (e += f.length); + return g; + }, + }, + f = { + arraySet: function (a, b, c, d, e) { + for (var f = 0; f < d; f++) a[e + f] = b[c + f]; + }, + flattenChunks: function (a) { + return [].concat.apply([], a); + }, + }; + (c.setTyped = function (a) { + a + ? ((c.Buf8 = Uint8Array), + (c.Buf16 = Uint16Array), + (c.Buf32 = Int32Array), + c.assign(c, e)) + : ((c.Buf8 = Array), + (c.Buf16 = Array), + (c.Buf32 = Array), + c.assign(c, f)); + }), + c.setTyped(d); + }, + {}, + ], + 42: [ + function (a, b, c) { + "use strict"; + function d(a, b) { + if (b < 65537 && ((a.subarray && g) || (!a.subarray && f))) + return String.fromCharCode.apply(null, e.shrinkBuf(a, b)); + for (var c = "", d = 0; d < b; d++) c += String.fromCharCode(a[d]); + return c; + } + var e = a("./common"), + f = !0, + g = !0; + try { + String.fromCharCode.apply(null, [0]); + } catch (h) { + f = !1; + } + try { + String.fromCharCode.apply(null, new Uint8Array(1)); + } catch (h) { + g = !1; + } + for (var i = new e.Buf8(256), j = 0; j < 256; j++) + i[j] = + j >= 252 + ? 6 + : j >= 248 + ? 5 + : j >= 240 + ? 4 + : j >= 224 + ? 3 + : j >= 192 + ? 2 + : 1; + (i[254] = i[254] = 1), + (c.string2buf = function (a) { + var b, + c, + d, + f, + g, + h = a.length, + i = 0; + for (f = 0; f < h; f++) + (c = a.charCodeAt(f)), + 55296 === (64512 & c) && + f + 1 < h && + ((d = a.charCodeAt(f + 1)), + 56320 === (64512 & d) && + ((c = 65536 + ((c - 55296) << 10) + (d - 56320)), f++)), + (i += c < 128 ? 1 : c < 2048 ? 2 : c < 65536 ? 3 : 4); + for (b = new e.Buf8(i), g = 0, f = 0; g < i; f++) + (c = a.charCodeAt(f)), + 55296 === (64512 & c) && + f + 1 < h && + ((d = a.charCodeAt(f + 1)), + 56320 === (64512 & d) && + ((c = 65536 + ((c - 55296) << 10) + (d - 56320)), f++)), + c < 128 + ? (b[g++] = c) + : c < 2048 + ? ((b[g++] = 192 | (c >>> 6)), (b[g++] = 128 | (63 & c))) + : c < 65536 + ? ((b[g++] = 224 | (c >>> 12)), + (b[g++] = 128 | ((c >>> 6) & 63)), + (b[g++] = 128 | (63 & c))) + : ((b[g++] = 240 | (c >>> 18)), + (b[g++] = 128 | ((c >>> 12) & 63)), + (b[g++] = 128 | ((c >>> 6) & 63)), + (b[g++] = 128 | (63 & c))); + return b; + }), + (c.buf2binstring = function (a) { + return d(a, a.length); + }), + (c.binstring2buf = function (a) { + for ( + var b = new e.Buf8(a.length), c = 0, d = b.length; + c < d; + c++ + ) + b[c] = a.charCodeAt(c); + return b; + }), + (c.buf2string = function (a, b) { + var c, + e, + f, + g, + h = b || a.length, + j = new Array(2 * h); + for (e = 0, c = 0; c < h; ) + if (((f = a[c++]), f < 128)) j[e++] = f; + else if (((g = i[f]), g > 4)) (j[e++] = 65533), (c += g - 1); + else { + for (f &= 2 === g ? 31 : 3 === g ? 15 : 7; g > 1 && c < h; ) + (f = (f << 6) | (63 & a[c++])), g--; + g > 1 + ? (j[e++] = 65533) + : f < 65536 + ? (j[e++] = f) + : ((f -= 65536), + (j[e++] = 55296 | ((f >> 10) & 1023)), + (j[e++] = 56320 | (1023 & f))); + } + return d(j, e); + }), + (c.utf8border = function (a, b) { + var c; + for ( + b = b || a.length, b > a.length && (b = a.length), c = b - 1; + c >= 0 && 128 === (192 & a[c]); + + ) + c--; + return c < 0 ? b : 0 === c ? b : c + i[a[c]] > b ? c : b; + }); + }, + { "./common": 41 }, + ], + 43: [ + function (a, b, c) { + "use strict"; + function d(a, b, c, d) { + for ( + var e = (65535 & a) | 0, f = ((a >>> 16) & 65535) | 0, g = 0; + 0 !== c; + + ) { + (g = c > 2e3 ? 2e3 : c), (c -= g); + do (e = (e + b[d++]) | 0), (f = (f + e) | 0); + while (--g); + (e %= 65521), (f %= 65521); + } + return e | (f << 16) | 0; + } + b.exports = d; + }, + {}, + ], + 44: [ + function (a, b, c) { + "use strict"; + b.exports = { + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_BUF_ERROR: -5, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + Z_BINARY: 0, + Z_TEXT: 1, + Z_UNKNOWN: 2, + Z_DEFLATED: 8, + }; + }, + {}, + ], + 45: [ + function (a, b, c) { + "use strict"; + function d() { + for (var a, b = [], c = 0; c < 256; c++) { + a = c; + for (var d = 0; d < 8; d++) + a = 1 & a ? 3988292384 ^ (a >>> 1) : a >>> 1; + b[c] = a; + } + return b; + } + function e(a, b, c, d) { + var e = f, + g = d + c; + a ^= -1; + for (var h = d; h < g; h++) a = (a >>> 8) ^ e[255 & (a ^ b[h])]; + return a ^ -1; + } + var f = d(); + b.exports = e; + }, + {}, + ], + 46: [ + function (a, b, c) { + "use strict"; + function d(a, b) { + return (a.msg = I[b]), b; + } + function e(a) { + return (a << 1) - (a > 4 ? 9 : 0); + } + function f(a) { + for (var b = a.length; --b >= 0; ) a[b] = 0; + } + function g(a) { + var b = a.state, + c = b.pending; + c > a.avail_out && (c = a.avail_out), + 0 !== c && + (E.arraySet( + a.output, + b.pending_buf, + b.pending_out, + c, + a.next_out + ), + (a.next_out += c), + (b.pending_out += c), + (a.total_out += c), + (a.avail_out -= c), + (b.pending -= c), + 0 === b.pending && (b.pending_out = 0)); + } + function h(a, b) { + F._tr_flush_block( + a, + a.block_start >= 0 ? a.block_start : -1, + a.strstart - a.block_start, + b + ), + (a.block_start = a.strstart), + g(a.strm); + } + function i(a, b) { + a.pending_buf[a.pending++] = b; + } + function j(a, b) { + (a.pending_buf[a.pending++] = (b >>> 8) & 255), + (a.pending_buf[a.pending++] = 255 & b); + } + function k(a, b, c, d) { + var e = a.avail_in; + return ( + e > d && (e = d), + 0 === e + ? 0 + : ((a.avail_in -= e), + E.arraySet(b, a.input, a.next_in, e, c), + 1 === a.state.wrap + ? (a.adler = G(a.adler, b, e, c)) + : 2 === a.state.wrap && (a.adler = H(a.adler, b, e, c)), + (a.next_in += e), + (a.total_in += e), + e) + ); + } + function l(a, b) { + var c, + d, + e = a.max_chain_length, + f = a.strstart, + g = a.prev_length, + h = a.nice_match, + i = a.strstart > a.w_size - la ? a.strstart - (a.w_size - la) : 0, + j = a.window, + k = a.w_mask, + l = a.prev, + m = a.strstart + ka, + n = j[f + g - 1], + o = j[f + g]; + a.prev_length >= a.good_match && (e >>= 2), + h > a.lookahead && (h = a.lookahead); + do + if ( + ((c = b), + j[c + g] === o && + j[c + g - 1] === n && + j[c] === j[f] && + j[++c] === j[f + 1]) + ) { + (f += 2), c++; + do; + while ( + j[++f] === j[++c] && + j[++f] === j[++c] && + j[++f] === j[++c] && + j[++f] === j[++c] && + j[++f] === j[++c] && + j[++f] === j[++c] && + j[++f] === j[++c] && + j[++f] === j[++c] && + f < m + ); + if (((d = ka - (m - f)), (f = m - ka), d > g)) { + if (((a.match_start = b), (g = d), d >= h)) break; + (n = j[f + g - 1]), (o = j[f + g]); + } + } + while ((b = l[b & k]) > i && 0 !== --e); + return g <= a.lookahead ? g : a.lookahead; + } + function m(a) { + var b, + c, + d, + e, + f, + g = a.w_size; + do { + if ( + ((e = a.window_size - a.lookahead - a.strstart), + a.strstart >= g + (g - la)) + ) { + E.arraySet(a.window, a.window, g, g, 0), + (a.match_start -= g), + (a.strstart -= g), + (a.block_start -= g), + (c = a.hash_size), + (b = c); + do (d = a.head[--b]), (a.head[b] = d >= g ? d - g : 0); + while (--c); + (c = g), (b = c); + do (d = a.prev[--b]), (a.prev[b] = d >= g ? d - g : 0); + while (--c); + e += g; + } + if (0 === a.strm.avail_in) break; + if ( + ((c = k(a.strm, a.window, a.strstart + a.lookahead, e)), + (a.lookahead += c), + a.lookahead + a.insert >= ja) + ) + for ( + f = a.strstart - a.insert, + a.ins_h = a.window[f], + a.ins_h = + ((a.ins_h << a.hash_shift) ^ a.window[f + 1]) & + a.hash_mask; + a.insert && + ((a.ins_h = + ((a.ins_h << a.hash_shift) ^ a.window[f + ja - 1]) & + a.hash_mask), + (a.prev[f & a.w_mask] = a.head[a.ins_h]), + (a.head[a.ins_h] = f), + f++, + a.insert--, + !(a.lookahead + a.insert < ja)); + + ); + } while (a.lookahead < la && 0 !== a.strm.avail_in); + } + function n(a, b) { + var c = 65535; + for ( + c > a.pending_buf_size - 5 && (c = a.pending_buf_size - 5); + ; + + ) { + if (a.lookahead <= 1) { + if ((m(a), 0 === a.lookahead && b === J)) return ua; + if (0 === a.lookahead) break; + } + (a.strstart += a.lookahead), (a.lookahead = 0); + var d = a.block_start + c; + if ( + (0 === a.strstart || a.strstart >= d) && + ((a.lookahead = a.strstart - d), + (a.strstart = d), + h(a, !1), + 0 === a.strm.avail_out) + ) + return ua; + if ( + a.strstart - a.block_start >= a.w_size - la && + (h(a, !1), 0 === a.strm.avail_out) + ) + return ua; + } + return ( + (a.insert = 0), + b === M + ? (h(a, !0), 0 === a.strm.avail_out ? wa : xa) + : a.strstart > a.block_start && + (h(a, !1), 0 === a.strm.avail_out) + ? ua + : ua + ); + } + function o(a, b) { + for (var c, d; ; ) { + if (a.lookahead < la) { + if ((m(a), a.lookahead < la && b === J)) return ua; + if (0 === a.lookahead) break; + } + if ( + ((c = 0), + a.lookahead >= ja && + ((a.ins_h = + ((a.ins_h << a.hash_shift) ^ + a.window[a.strstart + ja - 1]) & + a.hash_mask), + (c = a.prev[a.strstart & a.w_mask] = a.head[a.ins_h]), + (a.head[a.ins_h] = a.strstart)), + 0 !== c && + a.strstart - c <= a.w_size - la && + (a.match_length = l(a, c)), + a.match_length >= ja) + ) + if ( + ((d = F._tr_tally( + a, + a.strstart - a.match_start, + a.match_length - ja + )), + (a.lookahead -= a.match_length), + a.match_length <= a.max_lazy_match && a.lookahead >= ja) + ) { + a.match_length--; + do + a.strstart++, + (a.ins_h = + ((a.ins_h << a.hash_shift) ^ + a.window[a.strstart + ja - 1]) & + a.hash_mask), + (c = a.prev[a.strstart & a.w_mask] = a.head[a.ins_h]), + (a.head[a.ins_h] = a.strstart); + while (0 !== --a.match_length); + a.strstart++; + } else + (a.strstart += a.match_length), + (a.match_length = 0), + (a.ins_h = a.window[a.strstart]), + (a.ins_h = + ((a.ins_h << a.hash_shift) ^ a.window[a.strstart + 1]) & + a.hash_mask); + else + (d = F._tr_tally(a, 0, a.window[a.strstart])), + a.lookahead--, + a.strstart++; + if (d && (h(a, !1), 0 === a.strm.avail_out)) return ua; + } + return ( + (a.insert = a.strstart < ja - 1 ? a.strstart : ja - 1), + b === M + ? (h(a, !0), 0 === a.strm.avail_out ? wa : xa) + : a.last_lit && (h(a, !1), 0 === a.strm.avail_out) + ? ua + : va + ); + } + function p(a, b) { + for (var c, d, e; ; ) { + if (a.lookahead < la) { + if ((m(a), a.lookahead < la && b === J)) return ua; + if (0 === a.lookahead) break; + } + if ( + ((c = 0), + a.lookahead >= ja && + ((a.ins_h = + ((a.ins_h << a.hash_shift) ^ + a.window[a.strstart + ja - 1]) & + a.hash_mask), + (c = a.prev[a.strstart & a.w_mask] = a.head[a.ins_h]), + (a.head[a.ins_h] = a.strstart)), + (a.prev_length = a.match_length), + (a.prev_match = a.match_start), + (a.match_length = ja - 1), + 0 !== c && + a.prev_length < a.max_lazy_match && + a.strstart - c <= a.w_size - la && + ((a.match_length = l(a, c)), + a.match_length <= 5 && + (a.strategy === U || + (a.match_length === ja && + a.strstart - a.match_start > 4096)) && + (a.match_length = ja - 1)), + a.prev_length >= ja && a.match_length <= a.prev_length) + ) { + (e = a.strstart + a.lookahead - ja), + (d = F._tr_tally( + a, + a.strstart - 1 - a.prev_match, + a.prev_length - ja + )), + (a.lookahead -= a.prev_length - 1), + (a.prev_length -= 2); + do + ++a.strstart <= e && + ((a.ins_h = + ((a.ins_h << a.hash_shift) ^ + a.window[a.strstart + ja - 1]) & + a.hash_mask), + (c = a.prev[a.strstart & a.w_mask] = a.head[a.ins_h]), + (a.head[a.ins_h] = a.strstart)); + while (0 !== --a.prev_length); + if ( + ((a.match_available = 0), + (a.match_length = ja - 1), + a.strstart++, + d && (h(a, !1), 0 === a.strm.avail_out)) + ) + return ua; + } else if (a.match_available) { + if ( + ((d = F._tr_tally(a, 0, a.window[a.strstart - 1])), + d && h(a, !1), + a.strstart++, + a.lookahead--, + 0 === a.strm.avail_out) + ) + return ua; + } else (a.match_available = 1), a.strstart++, a.lookahead--; + } + return ( + a.match_available && + ((d = F._tr_tally(a, 0, a.window[a.strstart - 1])), + (a.match_available = 0)), + (a.insert = a.strstart < ja - 1 ? a.strstart : ja - 1), + b === M + ? (h(a, !0), 0 === a.strm.avail_out ? wa : xa) + : a.last_lit && (h(a, !1), 0 === a.strm.avail_out) + ? ua + : va + ); + } + function q(a, b) { + for (var c, d, e, f, g = a.window; ; ) { + if (a.lookahead <= ka) { + if ((m(a), a.lookahead <= ka && b === J)) return ua; + if (0 === a.lookahead) break; + } + if ( + ((a.match_length = 0), + a.lookahead >= ja && + a.strstart > 0 && + ((e = a.strstart - 1), + (d = g[e]), + d === g[++e] && d === g[++e] && d === g[++e])) + ) { + f = a.strstart + ka; + do; + while ( + d === g[++e] && + d === g[++e] && + d === g[++e] && + d === g[++e] && + d === g[++e] && + d === g[++e] && + d === g[++e] && + d === g[++e] && + e < f + ); + (a.match_length = ka - (f - e)), + a.match_length > a.lookahead && + (a.match_length = a.lookahead); + } + if ( + (a.match_length >= ja + ? ((c = F._tr_tally(a, 1, a.match_length - ja)), + (a.lookahead -= a.match_length), + (a.strstart += a.match_length), + (a.match_length = 0)) + : ((c = F._tr_tally(a, 0, a.window[a.strstart])), + a.lookahead--, + a.strstart++), + c && (h(a, !1), 0 === a.strm.avail_out)) + ) + return ua; + } + return ( + (a.insert = 0), + b === M + ? (h(a, !0), 0 === a.strm.avail_out ? wa : xa) + : a.last_lit && (h(a, !1), 0 === a.strm.avail_out) + ? ua + : va + ); + } + function r(a, b) { + for (var c; ; ) { + if (0 === a.lookahead && (m(a), 0 === a.lookahead)) { + if (b === J) return ua; + break; + } + if ( + ((a.match_length = 0), + (c = F._tr_tally(a, 0, a.window[a.strstart])), + a.lookahead--, + a.strstart++, + c && (h(a, !1), 0 === a.strm.avail_out)) + ) + return ua; + } + return ( + (a.insert = 0), + b === M + ? (h(a, !0), 0 === a.strm.avail_out ? wa : xa) + : a.last_lit && (h(a, !1), 0 === a.strm.avail_out) + ? ua + : va + ); + } + function s(a, b, c, d, e) { + (this.good_length = a), + (this.max_lazy = b), + (this.nice_length = c), + (this.max_chain = d), + (this.func = e); + } + function t(a) { + (a.window_size = 2 * a.w_size), + f(a.head), + (a.max_lazy_match = D[a.level].max_lazy), + (a.good_match = D[a.level].good_length), + (a.nice_match = D[a.level].nice_length), + (a.max_chain_length = D[a.level].max_chain), + (a.strstart = 0), + (a.block_start = 0), + (a.lookahead = 0), + (a.insert = 0), + (a.match_length = a.prev_length = ja - 1), + (a.match_available = 0), + (a.ins_h = 0); + } + function u() { + (this.strm = null), + (this.status = 0), + (this.pending_buf = null), + (this.pending_buf_size = 0), + (this.pending_out = 0), + (this.pending = 0), + (this.wrap = 0), + (this.gzhead = null), + (this.gzindex = 0), + (this.method = $), + (this.last_flush = -1), + (this.w_size = 0), + (this.w_bits = 0), + (this.w_mask = 0), + (this.window = null), + (this.window_size = 0), + (this.prev = null), + (this.head = null), + (this.ins_h = 0), + (this.hash_size = 0), + (this.hash_bits = 0), + (this.hash_mask = 0), + (this.hash_shift = 0), + (this.block_start = 0), + (this.match_length = 0), + (this.prev_match = 0), + (this.match_available = 0), + (this.strstart = 0), + (this.match_start = 0), + (this.lookahead = 0), + (this.prev_length = 0), + (this.max_chain_length = 0), + (this.max_lazy_match = 0), + (this.level = 0), + (this.strategy = 0), + (this.good_match = 0), + (this.nice_match = 0), + (this.dyn_ltree = new E.Buf16(2 * ha)), + (this.dyn_dtree = new E.Buf16(2 * (2 * fa + 1))), + (this.bl_tree = new E.Buf16(2 * (2 * ga + 1))), + f(this.dyn_ltree), + f(this.dyn_dtree), + f(this.bl_tree), + (this.l_desc = null), + (this.d_desc = null), + (this.bl_desc = null), + (this.bl_count = new E.Buf16(ia + 1)), + (this.heap = new E.Buf16(2 * ea + 1)), + f(this.heap), + (this.heap_len = 0), + (this.heap_max = 0), + (this.depth = new E.Buf16(2 * ea + 1)), + f(this.depth), + (this.l_buf = 0), + (this.lit_bufsize = 0), + (this.last_lit = 0), + (this.d_buf = 0), + (this.opt_len = 0), + (this.static_len = 0), + (this.matches = 0), + (this.insert = 0), + (this.bi_buf = 0), + (this.bi_valid = 0); + } + function v(a) { + var b; + return a && a.state + ? ((a.total_in = a.total_out = 0), + (a.data_type = Z), + (b = a.state), + (b.pending = 0), + (b.pending_out = 0), + b.wrap < 0 && (b.wrap = -b.wrap), + (b.status = b.wrap ? na : sa), + (a.adler = 2 === b.wrap ? 0 : 1), + (b.last_flush = J), + F._tr_init(b), + O) + : d(a, Q); + } + function w(a) { + var b = v(a); + return b === O && t(a.state), b; + } + function x(a, b) { + return a && a.state + ? 2 !== a.state.wrap + ? Q + : ((a.state.gzhead = b), O) + : Q; + } + function y(a, b, c, e, f, g) { + if (!a) return Q; + var h = 1; + if ( + (b === T && (b = 6), + e < 0 ? ((h = 0), (e = -e)) : e > 15 && ((h = 2), (e -= 16)), + f < 1 || + f > _ || + c !== $ || + e < 8 || + e > 15 || + b < 0 || + b > 9 || + g < 0 || + g > X) + ) + return d(a, Q); + 8 === e && (e = 9); + var i = new u(); + return ( + (a.state = i), + (i.strm = a), + (i.wrap = h), + (i.gzhead = null), + (i.w_bits = e), + (i.w_size = 1 << i.w_bits), + (i.w_mask = i.w_size - 1), + (i.hash_bits = f + 7), + (i.hash_size = 1 << i.hash_bits), + (i.hash_mask = i.hash_size - 1), + (i.hash_shift = ~~((i.hash_bits + ja - 1) / ja)), + (i.window = new E.Buf8(2 * i.w_size)), + (i.head = new E.Buf16(i.hash_size)), + (i.prev = new E.Buf16(i.w_size)), + (i.lit_bufsize = 1 << (f + 6)), + (i.pending_buf_size = 4 * i.lit_bufsize), + (i.pending_buf = new E.Buf8(i.pending_buf_size)), + (i.d_buf = 1 * i.lit_bufsize), + (i.l_buf = 3 * i.lit_bufsize), + (i.level = b), + (i.strategy = g), + (i.method = c), + w(a) + ); + } + function z(a, b) { + return y(a, b, $, aa, ba, Y); + } + function A(a, b) { + var c, h, k, l; + if (!a || !a.state || b > N || b < 0) return a ? d(a, Q) : Q; + if ( + ((h = a.state), + !a.output || + (!a.input && 0 !== a.avail_in) || + (h.status === ta && b !== M)) + ) + return d(a, 0 === a.avail_out ? S : Q); + if ( + ((h.strm = a), + (c = h.last_flush), + (h.last_flush = b), + h.status === na) + ) + if (2 === h.wrap) + (a.adler = 0), + i(h, 31), + i(h, 139), + i(h, 8), + h.gzhead + ? (i( + h, + (h.gzhead.text ? 1 : 0) + + (h.gzhead.hcrc ? 2 : 0) + + (h.gzhead.extra ? 4 : 0) + + (h.gzhead.name ? 8 : 0) + + (h.gzhead.comment ? 16 : 0) + ), + i(h, 255 & h.gzhead.time), + i(h, (h.gzhead.time >> 8) & 255), + i(h, (h.gzhead.time >> 16) & 255), + i(h, (h.gzhead.time >> 24) & 255), + i( + h, + 9 === h.level + ? 2 + : h.strategy >= V || h.level < 2 + ? 4 + : 0 + ), + i(h, 255 & h.gzhead.os), + h.gzhead.extra && + h.gzhead.extra.length && + (i(h, 255 & h.gzhead.extra.length), + i(h, (h.gzhead.extra.length >> 8) & 255)), + h.gzhead.hcrc && + (a.adler = H(a.adler, h.pending_buf, h.pending, 0)), + (h.gzindex = 0), + (h.status = oa)) + : (i(h, 0), + i(h, 0), + i(h, 0), + i(h, 0), + i(h, 0), + i( + h, + 9 === h.level + ? 2 + : h.strategy >= V || h.level < 2 + ? 4 + : 0 + ), + i(h, ya), + (h.status = sa)); + else { + var m = ($ + ((h.w_bits - 8) << 4)) << 8, + n = -1; + (n = + h.strategy >= V || h.level < 2 + ? 0 + : h.level < 6 + ? 1 + : 6 === h.level + ? 2 + : 3), + (m |= n << 6), + 0 !== h.strstart && (m |= ma), + (m += 31 - (m % 31)), + (h.status = sa), + j(h, m), + 0 !== h.strstart && + (j(h, a.adler >>> 16), j(h, 65535 & a.adler)), + (a.adler = 1); + } + if (h.status === oa) + if (h.gzhead.extra) { + for ( + k = h.pending; + h.gzindex < (65535 & h.gzhead.extra.length) && + (h.pending !== h.pending_buf_size || + (h.gzhead.hcrc && + h.pending > k && + (a.adler = H(a.adler, h.pending_buf, h.pending - k, k)), + g(a), + (k = h.pending), + h.pending !== h.pending_buf_size)); + + ) + i(h, 255 & h.gzhead.extra[h.gzindex]), h.gzindex++; + h.gzhead.hcrc && + h.pending > k && + (a.adler = H(a.adler, h.pending_buf, h.pending - k, k)), + h.gzindex === h.gzhead.extra.length && + ((h.gzindex = 0), (h.status = pa)); + } else h.status = pa; + if (h.status === pa) + if (h.gzhead.name) { + k = h.pending; + do { + if ( + h.pending === h.pending_buf_size && + (h.gzhead.hcrc && + h.pending > k && + (a.adler = H(a.adler, h.pending_buf, h.pending - k, k)), + g(a), + (k = h.pending), + h.pending === h.pending_buf_size) + ) { + l = 1; + break; + } + (l = + h.gzindex < h.gzhead.name.length + ? 255 & h.gzhead.name.charCodeAt(h.gzindex++) + : 0), + i(h, l); + } while (0 !== l); + h.gzhead.hcrc && + h.pending > k && + (a.adler = H(a.adler, h.pending_buf, h.pending - k, k)), + 0 === l && ((h.gzindex = 0), (h.status = qa)); + } else h.status = qa; + if (h.status === qa) + if (h.gzhead.comment) { + k = h.pending; + do { + if ( + h.pending === h.pending_buf_size && + (h.gzhead.hcrc && + h.pending > k && + (a.adler = H(a.adler, h.pending_buf, h.pending - k, k)), + g(a), + (k = h.pending), + h.pending === h.pending_buf_size) + ) { + l = 1; + break; + } + (l = + h.gzindex < h.gzhead.comment.length + ? 255 & h.gzhead.comment.charCodeAt(h.gzindex++) + : 0), + i(h, l); + } while (0 !== l); + h.gzhead.hcrc && + h.pending > k && + (a.adler = H(a.adler, h.pending_buf, h.pending - k, k)), + 0 === l && (h.status = ra); + } else h.status = ra; + if ( + (h.status === ra && + (h.gzhead.hcrc + ? (h.pending + 2 > h.pending_buf_size && g(a), + h.pending + 2 <= h.pending_buf_size && + (i(h, 255 & a.adler), + i(h, (a.adler >> 8) & 255), + (a.adler = 0), + (h.status = sa))) + : (h.status = sa)), + 0 !== h.pending) + ) { + if ((g(a), 0 === a.avail_out)) return (h.last_flush = -1), O; + } else if (0 === a.avail_in && e(b) <= e(c) && b !== M) + return d(a, S); + if (h.status === ta && 0 !== a.avail_in) return d(a, S); + if ( + 0 !== a.avail_in || + 0 !== h.lookahead || + (b !== J && h.status !== ta) + ) { + var o = + h.strategy === V + ? r(h, b) + : h.strategy === W + ? q(h, b) + : D[h.level].func(h, b); + if ( + ((o !== wa && o !== xa) || (h.status = ta), + o === ua || o === wa) + ) + return 0 === a.avail_out && (h.last_flush = -1), O; + if ( + o === va && + (b === K + ? F._tr_align(h) + : b !== N && + (F._tr_stored_block(h, 0, 0, !1), + b === L && + (f(h.head), + 0 === h.lookahead && + ((h.strstart = 0), + (h.block_start = 0), + (h.insert = 0)))), + g(a), + 0 === a.avail_out) + ) + return (h.last_flush = -1), O; + } + return b !== M + ? O + : h.wrap <= 0 + ? P + : (2 === h.wrap + ? (i(h, 255 & a.adler), + i(h, (a.adler >> 8) & 255), + i(h, (a.adler >> 16) & 255), + i(h, (a.adler >> 24) & 255), + i(h, 255 & a.total_in), + i(h, (a.total_in >> 8) & 255), + i(h, (a.total_in >> 16) & 255), + i(h, (a.total_in >> 24) & 255)) + : (j(h, a.adler >>> 16), j(h, 65535 & a.adler)), + g(a), + h.wrap > 0 && (h.wrap = -h.wrap), + 0 !== h.pending ? O : P); + } + function B(a) { + var b; + return a && a.state + ? ((b = a.state.status), + b !== na && + b !== oa && + b !== pa && + b !== qa && + b !== ra && + b !== sa && + b !== ta + ? d(a, Q) + : ((a.state = null), b === sa ? d(a, R) : O)) + : Q; + } + function C(a, b) { + var c, + d, + e, + g, + h, + i, + j, + k, + l = b.length; + if (!a || !a.state) return Q; + if ( + ((c = a.state), + (g = c.wrap), + 2 === g || (1 === g && c.status !== na) || c.lookahead) + ) + return Q; + for ( + 1 === g && (a.adler = G(a.adler, b, l, 0)), + c.wrap = 0, + l >= c.w_size && + (0 === g && + (f(c.head), + (c.strstart = 0), + (c.block_start = 0), + (c.insert = 0)), + (k = new E.Buf8(c.w_size)), + E.arraySet(k, b, l - c.w_size, c.w_size, 0), + (b = k), + (l = c.w_size)), + h = a.avail_in, + i = a.next_in, + j = a.input, + a.avail_in = l, + a.next_in = 0, + a.input = b, + m(c); + c.lookahead >= ja; + + ) { + (d = c.strstart), (e = c.lookahead - (ja - 1)); + do + (c.ins_h = + ((c.ins_h << c.hash_shift) ^ c.window[d + ja - 1]) & + c.hash_mask), + (c.prev[d & c.w_mask] = c.head[c.ins_h]), + (c.head[c.ins_h] = d), + d++; + while (--e); + (c.strstart = d), (c.lookahead = ja - 1), m(c); + } + return ( + (c.strstart += c.lookahead), + (c.block_start = c.strstart), + (c.insert = c.lookahead), + (c.lookahead = 0), + (c.match_length = c.prev_length = ja - 1), + (c.match_available = 0), + (a.next_in = i), + (a.input = j), + (a.avail_in = h), + (c.wrap = g), + O + ); + } + var D, + E = a("../utils/common"), + F = a("./trees"), + G = a("./adler32"), + H = a("./crc32"), + I = a("./messages"), + J = 0, + K = 1, + L = 3, + M = 4, + N = 5, + O = 0, + P = 1, + Q = -2, + R = -3, + S = -5, + T = -1, + U = 1, + V = 2, + W = 3, + X = 4, + Y = 0, + Z = 2, + $ = 8, + _ = 9, + aa = 15, + ba = 8, + ca = 29, + da = 256, + ea = da + 1 + ca, + fa = 30, + ga = 19, + ha = 2 * ea + 1, + ia = 15, + ja = 3, + ka = 258, + la = ka + ja + 1, + ma = 32, + na = 42, + oa = 69, + pa = 73, + qa = 91, + ra = 103, + sa = 113, + ta = 666, + ua = 1, + va = 2, + wa = 3, + xa = 4, + ya = 3; + (D = [ + new s(0, 0, 0, 0, n), + new s(4, 4, 8, 4, o), + new s(4, 5, 16, 8, o), + new s(4, 6, 32, 32, o), + new s(4, 4, 16, 16, p), + new s(8, 16, 32, 32, p), + new s(8, 16, 128, 128, p), + new s(8, 32, 128, 256, p), + new s(32, 128, 258, 1024, p), + new s(32, 258, 258, 4096, p), + ]), + (c.deflateInit = z), + (c.deflateInit2 = y), + (c.deflateReset = w), + (c.deflateResetKeep = v), + (c.deflateSetHeader = x), + (c.deflate = A), + (c.deflateEnd = B), + (c.deflateSetDictionary = C), + (c.deflateInfo = "pako deflate (from Nodeca project)"); + }, + { + "../utils/common": 41, + "./adler32": 43, + "./crc32": 45, + "./messages": 51, + "./trees": 52, + }, + ], + 47: [ + function (a, b, c) { + "use strict"; + function d() { + (this.text = 0), + (this.time = 0), + (this.xflags = 0), + (this.os = 0), + (this.extra = null), + (this.extra_len = 0), + (this.name = ""), + (this.comment = ""), + (this.hcrc = 0), + (this.done = !1); + } + b.exports = d; + }, + {}, + ], + 48: [ + function (a, b, c) { + "use strict"; + var d = 30, + e = 12; + b.exports = function (a, b) { + var c, + f, + g, + h, + i, + j, + k, + l, + m, + n, + o, + p, + q, + r, + s, + t, + u, + v, + w, + x, + y, + z, + A, + B, + C; + (c = a.state), + (f = a.next_in), + (B = a.input), + (g = f + (a.avail_in - 5)), + (h = a.next_out), + (C = a.output), + (i = h - (b - a.avail_out)), + (j = h + (a.avail_out - 257)), + (k = c.dmax), + (l = c.wsize), + (m = c.whave), + (n = c.wnext), + (o = c.window), + (p = c.hold), + (q = c.bits), + (r = c.lencode), + (s = c.distcode), + (t = (1 << c.lenbits) - 1), + (u = (1 << c.distbits) - 1); + a: do { + q < 15 && + ((p += B[f++] << q), (q += 8), (p += B[f++] << q), (q += 8)), + (v = r[p & t]); + b: for (;;) { + if ( + ((w = v >>> 24), + (p >>>= w), + (q -= w), + (w = (v >>> 16) & 255), + 0 === w) + ) + C[h++] = 65535 & v; + else { + if (!(16 & w)) { + if (0 === (64 & w)) { + v = r[(65535 & v) + (p & ((1 << w) - 1))]; + continue b; + } + if (32 & w) { + c.mode = e; + break a; + } + (a.msg = "invalid literal/length code"), (c.mode = d); + break a; + } + (x = 65535 & v), + (w &= 15), + w && + (q < w && ((p += B[f++] << q), (q += 8)), + (x += p & ((1 << w) - 1)), + (p >>>= w), + (q -= w)), + q < 15 && + ((p += B[f++] << q), + (q += 8), + (p += B[f++] << q), + (q += 8)), + (v = s[p & u]); + c: for (;;) { + if ( + ((w = v >>> 24), + (p >>>= w), + (q -= w), + (w = (v >>> 16) & 255), + !(16 & w)) + ) { + if (0 === (64 & w)) { + v = s[(65535 & v) + (p & ((1 << w) - 1))]; + continue c; + } + (a.msg = "invalid distance code"), (c.mode = d); + break a; + } + if ( + ((y = 65535 & v), + (w &= 15), + q < w && + ((p += B[f++] << q), + (q += 8), + q < w && ((p += B[f++] << q), (q += 8))), + (y += p & ((1 << w) - 1)), + y > k) + ) { + (a.msg = "invalid distance too far back"), (c.mode = d); + break a; + } + if (((p >>>= w), (q -= w), (w = h - i), y > w)) { + if (((w = y - w), w > m && c.sane)) { + (a.msg = "invalid distance too far back"), (c.mode = d); + break a; + } + if (((z = 0), (A = o), 0 === n)) { + if (((z += l - w), w < x)) { + x -= w; + do C[h++] = o[z++]; + while (--w); + (z = h - y), (A = C); + } + } else if (n < w) { + if (((z += l + n - w), (w -= n), w < x)) { + x -= w; + do C[h++] = o[z++]; + while (--w); + if (((z = 0), n < x)) { + (w = n), (x -= w); + do C[h++] = o[z++]; + while (--w); + (z = h - y), (A = C); + } + } + } else if (((z += n - w), w < x)) { + x -= w; + do C[h++] = o[z++]; + while (--w); + (z = h - y), (A = C); + } + for (; x > 2; ) + (C[h++] = A[z++]), + (C[h++] = A[z++]), + (C[h++] = A[z++]), + (x -= 3); + x && ((C[h++] = A[z++]), x > 1 && (C[h++] = A[z++])); + } else { + z = h - y; + do + (C[h++] = C[z++]), + (C[h++] = C[z++]), + (C[h++] = C[z++]), + (x -= 3); + while (x > 2); + x && ((C[h++] = C[z++]), x > 1 && (C[h++] = C[z++])); + } + break; + } + } + break; + } + } while (f < g && h < j); + (x = q >> 3), + (f -= x), + (q -= x << 3), + (p &= (1 << q) - 1), + (a.next_in = f), + (a.next_out = h), + (a.avail_in = f < g ? 5 + (g - f) : 5 - (f - g)), + (a.avail_out = h < j ? 257 + (j - h) : 257 - (h - j)), + (c.hold = p), + (c.bits = q); + }; + }, + {}, + ], + 49: [ + function (a, b, c) { + "use strict"; + function d(a) { + return ( + ((a >>> 24) & 255) + + ((a >>> 8) & 65280) + + ((65280 & a) << 8) + + ((255 & a) << 24) + ); + } + function e() { + (this.mode = 0), + (this.last = !1), + (this.wrap = 0), + (this.havedict = !1), + (this.flags = 0), + (this.dmax = 0), + (this.check = 0), + (this.total = 0), + (this.head = null), + (this.wbits = 0), + (this.wsize = 0), + (this.whave = 0), + (this.wnext = 0), + (this.window = null), + (this.hold = 0), + (this.bits = 0), + (this.length = 0), + (this.offset = 0), + (this.extra = 0), + (this.lencode = null), + (this.distcode = null), + (this.lenbits = 0), + (this.distbits = 0), + (this.ncode = 0), + (this.nlen = 0), + (this.ndist = 0), + (this.have = 0), + (this.next = null), + (this.lens = new s.Buf16(320)), + (this.work = new s.Buf16(288)), + (this.lendyn = null), + (this.distdyn = null), + (this.sane = 0), + (this.back = 0), + (this.was = 0); + } + function f(a) { + var b; + return a && a.state + ? ((b = a.state), + (a.total_in = a.total_out = b.total = 0), + (a.msg = ""), + b.wrap && (a.adler = 1 & b.wrap), + (b.mode = L), + (b.last = 0), + (b.havedict = 0), + (b.dmax = 32768), + (b.head = null), + (b.hold = 0), + (b.bits = 0), + (b.lencode = b.lendyn = new s.Buf32(pa)), + (b.distcode = b.distdyn = new s.Buf32(qa)), + (b.sane = 1), + (b.back = -1), + D) + : G; + } + function g(a) { + var b; + return a && a.state + ? ((b = a.state), + (b.wsize = 0), + (b.whave = 0), + (b.wnext = 0), + f(a)) + : G; + } + function h(a, b) { + var c, d; + return a && a.state + ? ((d = a.state), + b < 0 + ? ((c = 0), (b = -b)) + : ((c = (b >> 4) + 1), b < 48 && (b &= 15)), + b && (b < 8 || b > 15) + ? G + : (null !== d.window && d.wbits !== b && (d.window = null), + (d.wrap = c), + (d.wbits = b), + g(a))) + : G; + } + function i(a, b) { + var c, d; + return a + ? ((d = new e()), + (a.state = d), + (d.window = null), + (c = h(a, b)), + c !== D && (a.state = null), + c) + : G; + } + function j(a) { + return i(a, sa); + } + function k(a) { + if (ta) { + var b; + for (q = new s.Buf32(512), r = new s.Buf32(32), b = 0; b < 144; ) + a.lens[b++] = 8; + for (; b < 256; ) a.lens[b++] = 9; + for (; b < 280; ) a.lens[b++] = 7; + for (; b < 288; ) a.lens[b++] = 8; + for ( + w(y, a.lens, 0, 288, q, 0, a.work, { bits: 9 }), b = 0; + b < 32; + + ) + a.lens[b++] = 5; + w(z, a.lens, 0, 32, r, 0, a.work, { bits: 5 }), (ta = !1); + } + (a.lencode = q), + (a.lenbits = 9), + (a.distcode = r), + (a.distbits = 5); + } + function l(a, b, c, d) { + var e, + f = a.state; + return ( + null === f.window && + ((f.wsize = 1 << f.wbits), + (f.wnext = 0), + (f.whave = 0), + (f.window = new s.Buf8(f.wsize))), + d >= f.wsize + ? (s.arraySet(f.window, b, c - f.wsize, f.wsize, 0), + (f.wnext = 0), + (f.whave = f.wsize)) + : ((e = f.wsize - f.wnext), + e > d && (e = d), + s.arraySet(f.window, b, c - d, e, f.wnext), + (d -= e), + d + ? (s.arraySet(f.window, b, c - d, d, 0), + (f.wnext = d), + (f.whave = f.wsize)) + : ((f.wnext += e), + f.wnext === f.wsize && (f.wnext = 0), + f.whave < f.wsize && (f.whave += e))), + 0 + ); + } + function m(a, b) { + var c, + e, + f, + g, + h, + i, + j, + m, + n, + o, + p, + q, + r, + pa, + qa, + ra, + sa, + ta, + ua, + va, + wa, + xa, + ya, + za, + Aa = 0, + Ba = new s.Buf8(4), + Ca = [ + 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, + 15, + ]; + if (!a || !a.state || !a.output || (!a.input && 0 !== a.avail_in)) + return G; + (c = a.state), + c.mode === W && (c.mode = X), + (h = a.next_out), + (f = a.output), + (j = a.avail_out), + (g = a.next_in), + (e = a.input), + (i = a.avail_in), + (m = c.hold), + (n = c.bits), + (o = i), + (p = j), + (xa = D); + a: for (;;) + switch (c.mode) { + case L: + if (0 === c.wrap) { + c.mode = X; + break; + } + for (; n < 16; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (2 & c.wrap && 35615 === m) { + (c.check = 0), + (Ba[0] = 255 & m), + (Ba[1] = (m >>> 8) & 255), + (c.check = u(c.check, Ba, 2, 0)), + (m = 0), + (n = 0), + (c.mode = M); + break; + } + if ( + ((c.flags = 0), + c.head && (c.head.done = !1), + !(1 & c.wrap) || (((255 & m) << 8) + (m >> 8)) % 31) + ) { + (a.msg = "incorrect header check"), (c.mode = ma); + break; + } + if ((15 & m) !== K) { + (a.msg = "unknown compression method"), (c.mode = ma); + break; + } + if ( + ((m >>>= 4), (n -= 4), (wa = (15 & m) + 8), 0 === c.wbits) + ) + c.wbits = wa; + else if (wa > c.wbits) { + (a.msg = "invalid window size"), (c.mode = ma); + break; + } + (c.dmax = 1 << wa), + (a.adler = c.check = 1), + (c.mode = 512 & m ? U : W), + (m = 0), + (n = 0); + break; + case M: + for (; n < 16; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (((c.flags = m), (255 & c.flags) !== K)) { + (a.msg = "unknown compression method"), (c.mode = ma); + break; + } + if (57344 & c.flags) { + (a.msg = "unknown header flags set"), (c.mode = ma); + break; + } + c.head && (c.head.text = (m >> 8) & 1), + 512 & c.flags && + ((Ba[0] = 255 & m), + (Ba[1] = (m >>> 8) & 255), + (c.check = u(c.check, Ba, 2, 0))), + (m = 0), + (n = 0), + (c.mode = N); + case N: + for (; n < 32; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + c.head && (c.head.time = m), + 512 & c.flags && + ((Ba[0] = 255 & m), + (Ba[1] = (m >>> 8) & 255), + (Ba[2] = (m >>> 16) & 255), + (Ba[3] = (m >>> 24) & 255), + (c.check = u(c.check, Ba, 4, 0))), + (m = 0), + (n = 0), + (c.mode = O); + case O: + for (; n < 16; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + c.head && ((c.head.xflags = 255 & m), (c.head.os = m >> 8)), + 512 & c.flags && + ((Ba[0] = 255 & m), + (Ba[1] = (m >>> 8) & 255), + (c.check = u(c.check, Ba, 2, 0))), + (m = 0), + (n = 0), + (c.mode = P); + case P: + if (1024 & c.flags) { + for (; n < 16; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (c.length = m), + c.head && (c.head.extra_len = m), + 512 & c.flags && + ((Ba[0] = 255 & m), + (Ba[1] = (m >>> 8) & 255), + (c.check = u(c.check, Ba, 2, 0))), + (m = 0), + (n = 0); + } else c.head && (c.head.extra = null); + c.mode = Q; + case Q: + if ( + 1024 & c.flags && + ((q = c.length), + q > i && (q = i), + q && + (c.head && + ((wa = c.head.extra_len - c.length), + c.head.extra || + (c.head.extra = new Array(c.head.extra_len)), + s.arraySet(c.head.extra, e, g, q, wa)), + 512 & c.flags && (c.check = u(c.check, e, q, g)), + (i -= q), + (g += q), + (c.length -= q)), + c.length) + ) + break a; + (c.length = 0), (c.mode = R); + case R: + if (2048 & c.flags) { + if (0 === i) break a; + q = 0; + do + (wa = e[g + q++]), + c.head && + wa && + c.length < 65536 && + (c.head.name += String.fromCharCode(wa)); + while (wa && q < i); + if ( + (512 & c.flags && (c.check = u(c.check, e, q, g)), + (i -= q), + (g += q), + wa) + ) + break a; + } else c.head && (c.head.name = null); + (c.length = 0), (c.mode = S); + case S: + if (4096 & c.flags) { + if (0 === i) break a; + q = 0; + do + (wa = e[g + q++]), + c.head && + wa && + c.length < 65536 && + (c.head.comment += String.fromCharCode(wa)); + while (wa && q < i); + if ( + (512 & c.flags && (c.check = u(c.check, e, q, g)), + (i -= q), + (g += q), + wa) + ) + break a; + } else c.head && (c.head.comment = null); + c.mode = T; + case T: + if (512 & c.flags) { + for (; n < 16; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (m !== (65535 & c.check)) { + (a.msg = "header crc mismatch"), (c.mode = ma); + break; + } + (m = 0), (n = 0); + } + c.head && + ((c.head.hcrc = (c.flags >> 9) & 1), (c.head.done = !0)), + (a.adler = c.check = 0), + (c.mode = W); + break; + case U: + for (; n < 32; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (a.adler = c.check = d(m)), (m = 0), (n = 0), (c.mode = V); + case V: + if (0 === c.havedict) + return ( + (a.next_out = h), + (a.avail_out = j), + (a.next_in = g), + (a.avail_in = i), + (c.hold = m), + (c.bits = n), + F + ); + (a.adler = c.check = 1), (c.mode = W); + case W: + if (b === B || b === C) break a; + case X: + if (c.last) { + (m >>>= 7 & n), (n -= 7 & n), (c.mode = ja); + break; + } + for (; n < 3; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + switch (((c.last = 1 & m), (m >>>= 1), (n -= 1), 3 & m)) { + case 0: + c.mode = Y; + break; + case 1: + if ((k(c), (c.mode = ca), b === C)) { + (m >>>= 2), (n -= 2); + break a; + } + break; + case 2: + c.mode = _; + break; + case 3: + (a.msg = "invalid block type"), (c.mode = ma); + } + (m >>>= 2), (n -= 2); + break; + case Y: + for (m >>>= 7 & n, n -= 7 & n; n < 32; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if ((65535 & m) !== ((m >>> 16) ^ 65535)) { + (a.msg = "invalid stored block lengths"), (c.mode = ma); + break; + } + if ( + ((c.length = 65535 & m), + (m = 0), + (n = 0), + (c.mode = Z), + b === C) + ) + break a; + case Z: + c.mode = $; + case $: + if ((q = c.length)) { + if ((q > i && (q = i), q > j && (q = j), 0 === q)) break a; + s.arraySet(f, e, g, q, h), + (i -= q), + (g += q), + (j -= q), + (h += q), + (c.length -= q); + break; + } + c.mode = W; + break; + case _: + for (; n < 14; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if ( + ((c.nlen = (31 & m) + 257), + (m >>>= 5), + (n -= 5), + (c.ndist = (31 & m) + 1), + (m >>>= 5), + (n -= 5), + (c.ncode = (15 & m) + 4), + (m >>>= 4), + (n -= 4), + c.nlen > 286 || c.ndist > 30) + ) { + (a.msg = "too many length or distance symbols"), + (c.mode = ma); + break; + } + (c.have = 0), (c.mode = aa); + case aa: + for (; c.have < c.ncode; ) { + for (; n < 3; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (c.lens[Ca[c.have++]] = 7 & m), (m >>>= 3), (n -= 3); + } + for (; c.have < 19; ) c.lens[Ca[c.have++]] = 0; + if ( + ((c.lencode = c.lendyn), + (c.lenbits = 7), + (ya = { bits: c.lenbits }), + (xa = w(x, c.lens, 0, 19, c.lencode, 0, c.work, ya)), + (c.lenbits = ya.bits), + xa) + ) { + (a.msg = "invalid code lengths set"), (c.mode = ma); + break; + } + (c.have = 0), (c.mode = ba); + case ba: + for (; c.have < c.nlen + c.ndist; ) { + for ( + ; + (Aa = c.lencode[m & ((1 << c.lenbits) - 1)]), + (qa = Aa >>> 24), + (ra = (Aa >>> 16) & 255), + (sa = 65535 & Aa), + !(qa <= n); + + ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (sa < 16) + (m >>>= qa), (n -= qa), (c.lens[c.have++] = sa); + else { + if (16 === sa) { + for (za = qa + 2; n < za; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (((m >>>= qa), (n -= qa), 0 === c.have)) { + (a.msg = "invalid bit length repeat"), (c.mode = ma); + break; + } + (wa = c.lens[c.have - 1]), + (q = 3 + (3 & m)), + (m >>>= 2), + (n -= 2); + } else if (17 === sa) { + for (za = qa + 3; n < za; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (m >>>= qa), + (n -= qa), + (wa = 0), + (q = 3 + (7 & m)), + (m >>>= 3), + (n -= 3); + } else { + for (za = qa + 7; n < za; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (m >>>= qa), + (n -= qa), + (wa = 0), + (q = 11 + (127 & m)), + (m >>>= 7), + (n -= 7); + } + if (c.have + q > c.nlen + c.ndist) { + (a.msg = "invalid bit length repeat"), (c.mode = ma); + break; + } + for (; q--; ) c.lens[c.have++] = wa; + } + } + if (c.mode === ma) break; + if (0 === c.lens[256]) { + (a.msg = "invalid code -- missing end-of-block"), + (c.mode = ma); + break; + } + if ( + ((c.lenbits = 9), + (ya = { bits: c.lenbits }), + (xa = w(y, c.lens, 0, c.nlen, c.lencode, 0, c.work, ya)), + (c.lenbits = ya.bits), + xa) + ) { + (a.msg = "invalid literal/lengths set"), (c.mode = ma); + break; + } + if ( + ((c.distbits = 6), + (c.distcode = c.distdyn), + (ya = { bits: c.distbits }), + (xa = w( + z, + c.lens, + c.nlen, + c.ndist, + c.distcode, + 0, + c.work, + ya + )), + (c.distbits = ya.bits), + xa) + ) { + (a.msg = "invalid distances set"), (c.mode = ma); + break; + } + if (((c.mode = ca), b === C)) break a; + case ca: + c.mode = da; + case da: + if (i >= 6 && j >= 258) { + (a.next_out = h), + (a.avail_out = j), + (a.next_in = g), + (a.avail_in = i), + (c.hold = m), + (c.bits = n), + v(a, p), + (h = a.next_out), + (f = a.output), + (j = a.avail_out), + (g = a.next_in), + (e = a.input), + (i = a.avail_in), + (m = c.hold), + (n = c.bits), + c.mode === W && (c.back = -1); + break; + } + for ( + c.back = 0; + (Aa = c.lencode[m & ((1 << c.lenbits) - 1)]), + (qa = Aa >>> 24), + (ra = (Aa >>> 16) & 255), + (sa = 65535 & Aa), + !(qa <= n); + + ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (ra && 0 === (240 & ra)) { + for ( + ta = qa, ua = ra, va = sa; + (Aa = + c.lencode[va + ((m & ((1 << (ta + ua)) - 1)) >> ta)]), + (qa = Aa >>> 24), + (ra = (Aa >>> 16) & 255), + (sa = 65535 & Aa), + !(ta + qa <= n); + + ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (m >>>= ta), (n -= ta), (c.back += ta); + } + if ( + ((m >>>= qa), + (n -= qa), + (c.back += qa), + (c.length = sa), + 0 === ra) + ) { + c.mode = ia; + break; + } + if (32 & ra) { + (c.back = -1), (c.mode = W); + break; + } + if (64 & ra) { + (a.msg = "invalid literal/length code"), (c.mode = ma); + break; + } + (c.extra = 15 & ra), (c.mode = ea); + case ea: + if (c.extra) { + for (za = c.extra; n < za; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (c.length += m & ((1 << c.extra) - 1)), + (m >>>= c.extra), + (n -= c.extra), + (c.back += c.extra); + } + (c.was = c.length), (c.mode = fa); + case fa: + for ( + ; + (Aa = c.distcode[m & ((1 << c.distbits) - 1)]), + (qa = Aa >>> 24), + (ra = (Aa >>> 16) & 255), + (sa = 65535 & Aa), + !(qa <= n); + + ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (0 === (240 & ra)) { + for ( + ta = qa, ua = ra, va = sa; + (Aa = + c.distcode[va + ((m & ((1 << (ta + ua)) - 1)) >> ta)]), + (qa = Aa >>> 24), + (ra = (Aa >>> 16) & 255), + (sa = 65535 & Aa), + !(ta + qa <= n); + + ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (m >>>= ta), (n -= ta), (c.back += ta); + } + if (((m >>>= qa), (n -= qa), (c.back += qa), 64 & ra)) { + (a.msg = "invalid distance code"), (c.mode = ma); + break; + } + (c.offset = sa), (c.extra = 15 & ra), (c.mode = ga); + case ga: + if (c.extra) { + for (za = c.extra; n < za; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + (c.offset += m & ((1 << c.extra) - 1)), + (m >>>= c.extra), + (n -= c.extra), + (c.back += c.extra); + } + if (c.offset > c.dmax) { + (a.msg = "invalid distance too far back"), (c.mode = ma); + break; + } + c.mode = ha; + case ha: + if (0 === j) break a; + if (((q = p - j), c.offset > q)) { + if (((q = c.offset - q), q > c.whave && c.sane)) { + (a.msg = "invalid distance too far back"), (c.mode = ma); + break; + } + q > c.wnext + ? ((q -= c.wnext), (r = c.wsize - q)) + : (r = c.wnext - q), + q > c.length && (q = c.length), + (pa = c.window); + } else (pa = f), (r = h - c.offset), (q = c.length); + q > j && (q = j), (j -= q), (c.length -= q); + do f[h++] = pa[r++]; + while (--q); + 0 === c.length && (c.mode = da); + break; + case ia: + if (0 === j) break a; + (f[h++] = c.length), j--, (c.mode = da); + break; + case ja: + if (c.wrap) { + for (; n < 32; ) { + if (0 === i) break a; + i--, (m |= e[g++] << n), (n += 8); + } + if ( + ((p -= j), + (a.total_out += p), + (c.total += p), + p && + (a.adler = c.check = + c.flags + ? u(c.check, f, p, h - p) + : t(c.check, f, p, h - p)), + (p = j), + (c.flags ? m : d(m)) !== c.check) + ) { + (a.msg = "incorrect data check"), (c.mode = ma); + break; + } + (m = 0), (n = 0); + } + c.mode = ka; + case ka: + if (c.wrap && c.flags) { + for (; n < 32; ) { + if (0 === i) break a; + i--, (m += e[g++] << n), (n += 8); + } + if (m !== (4294967295 & c.total)) { + (a.msg = "incorrect length check"), (c.mode = ma); + break; + } + (m = 0), (n = 0); + } + c.mode = la; + case la: + xa = E; + break a; + case ma: + xa = H; + break a; + case na: + return I; + case oa: + default: + return G; + } + return ( + (a.next_out = h), + (a.avail_out = j), + (a.next_in = g), + (a.avail_in = i), + (c.hold = m), + (c.bits = n), + (c.wsize || + (p !== a.avail_out && + c.mode < ma && + (c.mode < ja || b !== A))) && + l(a, a.output, a.next_out, p - a.avail_out) + ? ((c.mode = na), I) + : ((o -= a.avail_in), + (p -= a.avail_out), + (a.total_in += o), + (a.total_out += p), + (c.total += p), + c.wrap && + p && + (a.adler = c.check = + c.flags + ? u(c.check, f, p, a.next_out - p) + : t(c.check, f, p, a.next_out - p)), + (a.data_type = + c.bits + + (c.last ? 64 : 0) + + (c.mode === W ? 128 : 0) + + (c.mode === ca || c.mode === Z ? 256 : 0)), + ((0 === o && 0 === p) || b === A) && xa === D && (xa = J), + xa) + ); + } + function n(a) { + if (!a || !a.state) return G; + var b = a.state; + return b.window && (b.window = null), (a.state = null), D; + } + function o(a, b) { + var c; + return a && a.state + ? ((c = a.state), + 0 === (2 & c.wrap) ? G : ((c.head = b), (b.done = !1), D)) + : G; + } + function p(a, b) { + var c, + d, + e, + f = b.length; + return a && a.state + ? ((c = a.state), + 0 !== c.wrap && c.mode !== V + ? G + : c.mode === V && + ((d = 1), (d = t(d, b, f, 0)), d !== c.check) + ? H + : (e = l(a, b, f, f)) + ? ((c.mode = na), I) + : ((c.havedict = 1), D)) + : G; + } + var q, + r, + s = a("../utils/common"), + t = a("./adler32"), + u = a("./crc32"), + v = a("./inffast"), + w = a("./inftrees"), + x = 0, + y = 1, + z = 2, + A = 4, + B = 5, + C = 6, + D = 0, + E = 1, + F = 2, + G = -2, + H = -3, + I = -4, + J = -5, + K = 8, + L = 1, + M = 2, + N = 3, + O = 4, + P = 5, + Q = 6, + R = 7, + S = 8, + T = 9, + U = 10, + V = 11, + W = 12, + X = 13, + Y = 14, + Z = 15, + $ = 16, + _ = 17, + aa = 18, + ba = 19, + ca = 20, + da = 21, + ea = 22, + fa = 23, + ga = 24, + ha = 25, + ia = 26, + ja = 27, + ka = 28, + la = 29, + ma = 30, + na = 31, + oa = 32, + pa = 852, + qa = 592, + ra = 15, + sa = ra, + ta = !0; + (c.inflateReset = g), + (c.inflateReset2 = h), + (c.inflateResetKeep = f), + (c.inflateInit = j), + (c.inflateInit2 = i), + (c.inflate = m), + (c.inflateEnd = n), + (c.inflateGetHeader = o), + (c.inflateSetDictionary = p), + (c.inflateInfo = "pako inflate (from Nodeca project)"); + }, + { + "../utils/common": 41, + "./adler32": 43, + "./crc32": 45, + "./inffast": 48, + "./inftrees": 50, + }, + ], + 50: [ + function (a, b, c) { + "use strict"; + var d = a("../utils/common"), + e = 15, + f = 852, + g = 592, + h = 0, + i = 1, + j = 2, + k = [ + 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, + 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0, + ], + l = [ + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78, + ], + m = [ + 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, + 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, + 16385, 24577, 0, 0, + ], + n = [ + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64, + ]; + b.exports = function (a, b, c, o, p, q, r, s) { + var t, + u, + v, + w, + x, + y, + z, + A, + B, + C = s.bits, + D = 0, + E = 0, + F = 0, + G = 0, + H = 0, + I = 0, + J = 0, + K = 0, + L = 0, + M = 0, + N = null, + O = 0, + P = new d.Buf16(e + 1), + Q = new d.Buf16(e + 1), + R = null, + S = 0; + for (D = 0; D <= e; D++) P[D] = 0; + for (E = 0; E < o; E++) P[b[c + E]]++; + for (H = C, G = e; G >= 1 && 0 === P[G]; G--); + if ((H > G && (H = G), 0 === G)) + return (p[q++] = 20971520), (p[q++] = 20971520), (s.bits = 1), 0; + for (F = 1; F < G && 0 === P[F]; F++); + for (H < F && (H = F), K = 1, D = 1; D <= e; D++) + if (((K <<= 1), (K -= P[D]), K < 0)) return -1; + if (K > 0 && (a === h || 1 !== G)) return -1; + for (Q[1] = 0, D = 1; D < e; D++) Q[D + 1] = Q[D] + P[D]; + for (E = 0; E < o; E++) 0 !== b[c + E] && (r[Q[b[c + E]]++] = E); + if ( + (a === h + ? ((N = R = r), (y = 19)) + : a === i + ? ((N = k), (O -= 257), (R = l), (S -= 257), (y = 256)) + : ((N = m), (R = n), (y = -1)), + (M = 0), + (E = 0), + (D = F), + (x = q), + (I = H), + (J = 0), + (v = -1), + (L = 1 << H), + (w = L - 1), + (a === i && L > f) || (a === j && L > g)) + ) + return 1; + for (;;) { + (z = D - J), + r[E] < y + ? ((A = 0), (B = r[E])) + : r[E] > y + ? ((A = R[S + r[E]]), (B = N[O + r[E]])) + : ((A = 96), (B = 0)), + (t = 1 << (D - J)), + (u = 1 << I), + (F = u); + do + (u -= t), (p[x + (M >> J) + u] = (z << 24) | (A << 16) | B | 0); + while (0 !== u); + for (t = 1 << (D - 1); M & t; ) t >>= 1; + if ( + (0 !== t ? ((M &= t - 1), (M += t)) : (M = 0), + E++, + 0 === --P[D]) + ) { + if (D === G) break; + D = b[c + r[E]]; + } + if (D > H && (M & w) !== v) { + for ( + 0 === J && (J = H), x += F, I = D - J, K = 1 << I; + I + J < G && ((K -= P[I + J]), !(K <= 0)); + + ) + I++, (K <<= 1); + if (((L += 1 << I), (a === i && L > f) || (a === j && L > g))) + return 1; + (v = M & w), (p[v] = (H << 24) | (I << 16) | (x - q) | 0); + } + } + return ( + 0 !== M && (p[x + M] = ((D - J) << 24) | (64 << 16) | 0), + (s.bits = H), + 0 + ); + }; + }, + { "../utils/common": 41 }, + ], + 51: [ + function (a, b, c) { + "use strict"; + b.exports = { + "2": "need dictionary", + "1": "stream end", + "0": "", + "-1": "file error", + "-2": "stream error", + "-3": "data error", + "-4": "insufficient memory", + "-5": "buffer error", + "-6": "incompatible version", + }; + }, + {}, + ], + 52: [ + function (a, b, c) { + "use strict"; + function d(a) { + for (var b = a.length; --b >= 0; ) a[b] = 0; + } + function e(a, b, c, d, e) { + (this.static_tree = a), + (this.extra_bits = b), + (this.extra_base = c), + (this.elems = d), + (this.max_length = e), + (this.has_stree = a && a.length); + } + function f(a, b) { + (this.dyn_tree = a), (this.max_code = 0), (this.stat_desc = b); + } + function g(a) { + return a < 256 ? ia[a] : ia[256 + (a >>> 7)]; + } + function h(a, b) { + (a.pending_buf[a.pending++] = 255 & b), + (a.pending_buf[a.pending++] = (b >>> 8) & 255); + } + function i(a, b, c) { + a.bi_valid > X - c + ? ((a.bi_buf |= (b << a.bi_valid) & 65535), + h(a, a.bi_buf), + (a.bi_buf = b >> (X - a.bi_valid)), + (a.bi_valid += c - X)) + : ((a.bi_buf |= (b << a.bi_valid) & 65535), (a.bi_valid += c)); + } + function j(a, b, c) { + i(a, c[2 * b], c[2 * b + 1]); + } + function k(a, b) { + var c = 0; + do (c |= 1 & a), (a >>>= 1), (c <<= 1); + while (--b > 0); + return c >>> 1; + } + function l(a) { + 16 === a.bi_valid + ? (h(a, a.bi_buf), (a.bi_buf = 0), (a.bi_valid = 0)) + : a.bi_valid >= 8 && + ((a.pending_buf[a.pending++] = 255 & a.bi_buf), + (a.bi_buf >>= 8), + (a.bi_valid -= 8)); + } + function m(a, b) { + var c, + d, + e, + f, + g, + h, + i = b.dyn_tree, + j = b.max_code, + k = b.stat_desc.static_tree, + l = b.stat_desc.has_stree, + m = b.stat_desc.extra_bits, + n = b.stat_desc.extra_base, + o = b.stat_desc.max_length, + p = 0; + for (f = 0; f <= W; f++) a.bl_count[f] = 0; + for ( + i[2 * a.heap[a.heap_max] + 1] = 0, c = a.heap_max + 1; + c < V; + c++ + ) + (d = a.heap[c]), + (f = i[2 * i[2 * d + 1] + 1] + 1), + f > o && ((f = o), p++), + (i[2 * d + 1] = f), + d > j || + (a.bl_count[f]++, + (g = 0), + d >= n && (g = m[d - n]), + (h = i[2 * d]), + (a.opt_len += h * (f + g)), + l && (a.static_len += h * (k[2 * d + 1] + g))); + if (0 !== p) { + do { + for (f = o - 1; 0 === a.bl_count[f]; ) f--; + a.bl_count[f]--, + (a.bl_count[f + 1] += 2), + a.bl_count[o]--, + (p -= 2); + } while (p > 0); + for (f = o; 0 !== f; f--) + for (d = a.bl_count[f]; 0 !== d; ) + (e = a.heap[--c]), + e > j || + (i[2 * e + 1] !== f && + ((a.opt_len += (f - i[2 * e + 1]) * i[2 * e]), + (i[2 * e + 1] = f)), + d--); + } + } + function n(a, b, c) { + var d, + e, + f = new Array(W + 1), + g = 0; + for (d = 1; d <= W; d++) f[d] = g = (g + c[d - 1]) << 1; + for (e = 0; e <= b; e++) { + var h = a[2 * e + 1]; + 0 !== h && (a[2 * e] = k(f[h]++, h)); + } + } + function o() { + var a, + b, + c, + d, + f, + g = new Array(W + 1); + for (c = 0, d = 0; d < Q - 1; d++) + for (ka[d] = c, a = 0; a < 1 << ba[d]; a++) ja[c++] = d; + for (ja[c - 1] = d, f = 0, d = 0; d < 16; d++) + for (la[d] = f, a = 0; a < 1 << ca[d]; a++) ia[f++] = d; + for (f >>= 7; d < T; d++) + for (la[d] = f << 7, a = 0; a < 1 << (ca[d] - 7); a++) + ia[256 + f++] = d; + for (b = 0; b <= W; b++) g[b] = 0; + for (a = 0; a <= 143; ) (ga[2 * a + 1] = 8), a++, g[8]++; + for (; a <= 255; ) (ga[2 * a + 1] = 9), a++, g[9]++; + for (; a <= 279; ) (ga[2 * a + 1] = 7), a++, g[7]++; + for (; a <= 287; ) (ga[2 * a + 1] = 8), a++, g[8]++; + for (n(ga, S + 1, g), a = 0; a < T; a++) + (ha[2 * a + 1] = 5), (ha[2 * a] = k(a, 5)); + (ma = new e(ga, ba, R + 1, S, W)), + (na = new e(ha, ca, 0, T, W)), + (oa = new e(new Array(0), da, 0, U, Y)); + } + function p(a) { + var b; + for (b = 0; b < S; b++) a.dyn_ltree[2 * b] = 0; + for (b = 0; b < T; b++) a.dyn_dtree[2 * b] = 0; + for (b = 0; b < U; b++) a.bl_tree[2 * b] = 0; + (a.dyn_ltree[2 * Z] = 1), + (a.opt_len = a.static_len = 0), + (a.last_lit = a.matches = 0); + } + function q(a) { + a.bi_valid > 8 + ? h(a, a.bi_buf) + : a.bi_valid > 0 && (a.pending_buf[a.pending++] = a.bi_buf), + (a.bi_buf = 0), + (a.bi_valid = 0); + } + function r(a, b, c, d) { + q(a), + d && (h(a, c), h(a, ~c)), + G.arraySet(a.pending_buf, a.window, b, c, a.pending), + (a.pending += c); + } + function s(a, b, c, d) { + var e = 2 * b, + f = 2 * c; + return a[e] < a[f] || (a[e] === a[f] && d[b] <= d[c]); + } + function t(a, b, c) { + for ( + var d = a.heap[c], e = c << 1; + e <= a.heap_len && + (e < a.heap_len && s(b, a.heap[e + 1], a.heap[e], a.depth) && e++, + !s(b, d, a.heap[e], a.depth)); + + ) + (a.heap[c] = a.heap[e]), (c = e), (e <<= 1); + a.heap[c] = d; + } + function u(a, b, c) { + var d, + e, + f, + h, + k = 0; + if (0 !== a.last_lit) + do + (d = + (a.pending_buf[a.d_buf + 2 * k] << 8) | + a.pending_buf[a.d_buf + 2 * k + 1]), + (e = a.pending_buf[a.l_buf + k]), + k++, + 0 === d + ? j(a, e, b) + : ((f = ja[e]), + j(a, f + R + 1, b), + (h = ba[f]), + 0 !== h && ((e -= ka[f]), i(a, e, h)), + d--, + (f = g(d)), + j(a, f, c), + (h = ca[f]), + 0 !== h && ((d -= la[f]), i(a, d, h))); + while (k < a.last_lit); + j(a, Z, b); + } + function v(a, b) { + var c, + d, + e, + f = b.dyn_tree, + g = b.stat_desc.static_tree, + h = b.stat_desc.has_stree, + i = b.stat_desc.elems, + j = -1; + for (a.heap_len = 0, a.heap_max = V, c = 0; c < i; c++) + 0 !== f[2 * c] + ? ((a.heap[++a.heap_len] = j = c), (a.depth[c] = 0)) + : (f[2 * c + 1] = 0); + for (; a.heap_len < 2; ) + (e = a.heap[++a.heap_len] = j < 2 ? ++j : 0), + (f[2 * e] = 1), + (a.depth[e] = 0), + a.opt_len--, + h && (a.static_len -= g[2 * e + 1]); + for (b.max_code = j, c = a.heap_len >> 1; c >= 1; c--) t(a, f, c); + e = i; + do + (c = a.heap[1]), + (a.heap[1] = a.heap[a.heap_len--]), + t(a, f, 1), + (d = a.heap[1]), + (a.heap[--a.heap_max] = c), + (a.heap[--a.heap_max] = d), + (f[2 * e] = f[2 * c] + f[2 * d]), + (a.depth[e] = + (a.depth[c] >= a.depth[d] ? a.depth[c] : a.depth[d]) + 1), + (f[2 * c + 1] = f[2 * d + 1] = e), + (a.heap[1] = e++), + t(a, f, 1); + while (a.heap_len >= 2); + (a.heap[--a.heap_max] = a.heap[1]), m(a, b), n(f, j, a.bl_count); + } + function w(a, b, c) { + var d, + e, + f = -1, + g = b[1], + h = 0, + i = 7, + j = 4; + for ( + 0 === g && ((i = 138), (j = 3)), + b[2 * (c + 1) + 1] = 65535, + d = 0; + d <= c; + d++ + ) + (e = g), + (g = b[2 * (d + 1) + 1]), + (++h < i && e === g) || + (h < j + ? (a.bl_tree[2 * e] += h) + : 0 !== e + ? (e !== f && a.bl_tree[2 * e]++, a.bl_tree[2 * $]++) + : h <= 10 + ? a.bl_tree[2 * _]++ + : a.bl_tree[2 * aa]++, + (h = 0), + (f = e), + 0 === g + ? ((i = 138), (j = 3)) + : e === g + ? ((i = 6), (j = 3)) + : ((i = 7), (j = 4))); + } + function x(a, b, c) { + var d, + e, + f = -1, + g = b[1], + h = 0, + k = 7, + l = 4; + for (0 === g && ((k = 138), (l = 3)), d = 0; d <= c; d++) + if (((e = g), (g = b[2 * (d + 1) + 1]), !(++h < k && e === g))) { + if (h < l) { + do j(a, e, a.bl_tree); + while (0 !== --h); + } else + 0 !== e + ? (e !== f && (j(a, e, a.bl_tree), h--), + j(a, $, a.bl_tree), + i(a, h - 3, 2)) + : h <= 10 + ? (j(a, _, a.bl_tree), i(a, h - 3, 3)) + : (j(a, aa, a.bl_tree), i(a, h - 11, 7)); + (h = 0), + (f = e), + 0 === g + ? ((k = 138), (l = 3)) + : e === g + ? ((k = 6), (l = 3)) + : ((k = 7), (l = 4)); + } + } + function y(a) { + var b; + for ( + w(a, a.dyn_ltree, a.l_desc.max_code), + w(a, a.dyn_dtree, a.d_desc.max_code), + v(a, a.bl_desc), + b = U - 1; + b >= 3 && 0 === a.bl_tree[2 * ea[b] + 1]; + b-- + ); + return (a.opt_len += 3 * (b + 1) + 5 + 5 + 4), b; + } + function z(a, b, c, d) { + var e; + for ( + i(a, b - 257, 5), i(a, c - 1, 5), i(a, d - 4, 4), e = 0; + e < d; + e++ + ) + i(a, a.bl_tree[2 * ea[e] + 1], 3); + x(a, a.dyn_ltree, b - 1), x(a, a.dyn_dtree, c - 1); + } + function A(a) { + var b, + c = 4093624447; + for (b = 0; b <= 31; b++, c >>>= 1) + if (1 & c && 0 !== a.dyn_ltree[2 * b]) return I; + if ( + 0 !== a.dyn_ltree[18] || + 0 !== a.dyn_ltree[20] || + 0 !== a.dyn_ltree[26] + ) + return J; + for (b = 32; b < R; b++) if (0 !== a.dyn_ltree[2 * b]) return J; + return I; + } + function B(a) { + pa || (o(), (pa = !0)), + (a.l_desc = new f(a.dyn_ltree, ma)), + (a.d_desc = new f(a.dyn_dtree, na)), + (a.bl_desc = new f(a.bl_tree, oa)), + (a.bi_buf = 0), + (a.bi_valid = 0), + p(a); + } + function C(a, b, c, d) { + i(a, (L << 1) + (d ? 1 : 0), 3), r(a, b, c, !0); + } + function D(a) { + i(a, M << 1, 3), j(a, Z, ga), l(a); + } + function E(a, b, c, d) { + var e, + f, + g = 0; + a.level > 0 + ? (a.strm.data_type === K && (a.strm.data_type = A(a)), + v(a, a.l_desc), + v(a, a.d_desc), + (g = y(a)), + (e = (a.opt_len + 3 + 7) >>> 3), + (f = (a.static_len + 3 + 7) >>> 3), + f <= e && (e = f)) + : (e = f = c + 5), + c + 4 <= e && b !== -1 + ? C(a, b, c, d) + : a.strategy === H || f === e + ? (i(a, (M << 1) + (d ? 1 : 0), 3), u(a, ga, ha)) + : (i(a, (N << 1) + (d ? 1 : 0), 3), + z(a, a.l_desc.max_code + 1, a.d_desc.max_code + 1, g + 1), + u(a, a.dyn_ltree, a.dyn_dtree)), + p(a), + d && q(a); + } + function F(a, b, c) { + return ( + (a.pending_buf[a.d_buf + 2 * a.last_lit] = (b >>> 8) & 255), + (a.pending_buf[a.d_buf + 2 * a.last_lit + 1] = 255 & b), + (a.pending_buf[a.l_buf + a.last_lit] = 255 & c), + a.last_lit++, + 0 === b + ? a.dyn_ltree[2 * c]++ + : (a.matches++, + b--, + a.dyn_ltree[2 * (ja[c] + R + 1)]++, + a.dyn_dtree[2 * g(b)]++), + a.last_lit === a.lit_bufsize - 1 + ); + } + var G = a("../utils/common"), + H = 4, + I = 0, + J = 1, + K = 2, + L = 0, + M = 1, + N = 2, + O = 3, + P = 258, + Q = 29, + R = 256, + S = R + 1 + Q, + T = 30, + U = 19, + V = 2 * S + 1, + W = 15, + X = 16, + Y = 7, + Z = 256, + $ = 16, + _ = 17, + aa = 18, + ba = [ + 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, + ], + ca = [ + 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, + ], + da = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7], + ea = [ + 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, + ], + fa = 512, + ga = new Array(2 * (S + 2)); + d(ga); + var ha = new Array(2 * T); + d(ha); + var ia = new Array(fa); + d(ia); + var ja = new Array(P - O + 1); + d(ja); + var ka = new Array(Q); + d(ka); + var la = new Array(T); + d(la); + var ma, + na, + oa, + pa = !1; + (c._tr_init = B), + (c._tr_stored_block = C), + (c._tr_flush_block = E), + (c._tr_tally = F), + (c._tr_align = D); + }, + { "../utils/common": 41 }, + ], + 53: [ + function (a, b, c) { + "use strict"; + function d() { + (this.input = null), + (this.next_in = 0), + (this.avail_in = 0), + (this.total_in = 0), + (this.output = null), + (this.next_out = 0), + (this.avail_out = 0), + (this.total_out = 0), + (this.msg = ""), + (this.state = null), + (this.data_type = 2), + (this.adler = 0); + } + b.exports = d; + }, + {}, + ], + 54: [ + function (a, b, c) { + "use strict"; + b.exports = + "function" == typeof setImmediate + ? setImmediate + : function () { + var a = [].slice.apply(arguments); + a.splice(1, 0, 0), setTimeout.apply(null, a); + }; + }, + {}, + ], + }, + {}, + [10] + )(10); +}); diff --git a/themes/default/public/js/lufi-common.js b/themes/default/public/js/lufi-common.js index 5c5cacb..48e6c6c 100644 --- a/themes/default/public/js/lufi-common.js +++ b/themes/default/public/js/lufi-common.js @@ -1,34 +1,37 @@ // vim:set sw=4 ts=4 sts=4 ft=javascript expandtab: // Escape HTML chars var entityMap = { - "&": "&", - "<": "<", - ">": ">", - '"': '"', - "'": ''', - "/": '/' + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'", + "/": "/", }; function escapeHtml(string) { - return String(string).replace(/[&<>"'\/]/g, function (s) { - return entityMap[s]; - }); + return String(string).replace(/[&<>"'\/]/g, function (s) { + return entityMap[s]; + }); } function changeLang() { - window.location = langUrl + $(this).val(); + window.location = langUrl + $(this).val(); } function formatDate(unixTimestamp) { - return new Date(unixTimestamp * 1000).toLocaleString(window.navigator.language, { - year: 'numeric', - month: 'long', - day: 'numeric', - weekday: 'long', - hour: '2-digit', - minute: '2-digit', - }) + return new Date(unixTimestamp * 1000).toLocaleString( + window.navigator.language, + { + year: "numeric", + month: "long", + day: "numeric", + weekday: "long", + hour: "2-digit", + minute: "2-digit", + } + ); } $(document).ready(function () { - $('select').material_select(); - $(".select-lang select").on('change', changeLang); - $(".select-lang-mobile select").on('change', changeLang); + $("select").material_select(); + $(".select-lang select").on("change", changeLang); + $(".select-lang-mobile select").on("change", changeLang); }); diff --git a/themes/default/public/js/lufi-down.js b/themes/default/public/js/lufi-down.js index 3e58861..8a1b7ab 100755 --- a/themes/default/public/js/lufi-down.js +++ b/themes/default/public/js/lufi-down.js @@ -17,14 +17,17 @@ const filesizeDOM = document.getElementById("filesize"); document.addEventListener("DOMContentLoaded", () => { let go = true; - filesizeDOM.innerHTML = filesize(filesizeDOM.attributes.getNamedItem("data-filesize").value, { - base: 10, - }); + filesizeDOM.innerHTML = filesize( + filesizeDOM.attributes.getNamedItem("data-filesize").value, + { + base: 10, + } + ); if (isPasswordNeeded()) { go = false; - passwordDOM.focus() + passwordDOM.focus(); onPasswordEvents(); } @@ -34,12 +37,12 @@ document.addEventListener("DOMContentLoaded", () => { } }); -const isPasswordNeeded = () => document.querySelectorAll("#file_pwd").length === 1 +const isPasswordNeeded = () => + document.querySelectorAll("#file_pwd").length === 1; const startDownload = () => { warnOnReload(); - lufi .download(window.location, passwordDOM?.value) .andThen((job) => { @@ -53,7 +56,7 @@ const startDownload = () => { job.terminate(); filesizeDOM.parentElement.append(abortedDOM); - warnOnReload(false) + warnOnReload(false); document.getElementById("reloadLocation").onclick = (e) => { e.preventDefault(); @@ -65,8 +68,8 @@ const startDownload = () => { }) .mapErr((error) => { addAlert(error.message); - warnOnReload(false) - remove(["abort"]) + warnOnReload(false); + remove(["abort"]); }) .andThen((job) => { notify(i18n.fileDownloaded, job.lufiFile.name); @@ -115,20 +118,22 @@ const remove = (elements) => { if (document.getElementById(id)) { document.getElementById(id).remove(); } else { - console.error(`${id} does not exist`) + console.error(`${id} does not exist`); } }); }; const onPasswordEvents = () => { const callback = () => { - document.getElementsByClassName("file-progress")[0].classList.remove("hide"); + document + .getElementsByClassName("file-progress")[0] + .classList.remove("hide"); document.getElementsByClassName("file-abort")[0].classList.remove("hide"); passwordDOM.parentElement.parentElement.classList.add("hide"); startDownload(); - } + }; document.getElementById("go").onclick = () => { callback(); @@ -138,8 +143,8 @@ const onPasswordEvents = () => { if (event.key === "Enter") { callback(); } - } -} + }; +}; // Something's wring const addAlert = (msg) => { @@ -156,7 +161,7 @@ const addAlert = (msg) => { ${msg} `; -} +}; const warnOnReload = (toWarn = true) => { if (toWarn) { @@ -164,14 +169,15 @@ const warnOnReload = (toWarn = true) => { } else { window.onbeforeunload = null; } -} +}; const updateProgress = (lufiFile) => { // Update loading text loadingDOM.textContent = i18n.loading.replace(/XX1/, lufiFile.chunksReady); // Update progress bar - const percent = Math.round((1000 * lufiFile.chunksReady) / lufiFile.totalChunks) / 10; + const percent = + Math.round((1000 * lufiFile.chunksReady) / lufiFile.totalChunks) / 10; const wClass = percent.toString().replace(".", "-"); const pb = document.getElementById("pb"); @@ -179,59 +185,61 @@ const updateProgress = (lufiFile) => { pb.attributes.getNamedItem("aria-valuenow").value = percent; document.getElementById("pbt").innerHTML = `${percent}%`; -} +}; const showZipContent = (blob) => { - const showZipContentDOM = document.getElementById('showZipContent'); + const showZipContentDOM = document.getElementById("showZipContent"); const showZipContentDOMListener = () => { - JSZip.loadAsync(blob) - .then((zip) => { - const newElement = document.createElement("div"); + JSZip.loadAsync(blob).then((zip) => { + const newElement = document.createElement("div"); - let innerHTML = `

${i18n.zipContent}

    `; + let innerHTML = `

    ${i18n.zipContent}

      `; - - zip.forEach(function (_relativePath, zipEntry) { - innerHTML += `
    • + zip.forEach(function (_relativePath, zipEntry) { + innerHTML += `
    • ${escapeHtml(zipEntry.name)} - (${filesize(zipEntry._data.uncompressedSize, { base: 10 })}) + (${filesize(zipEntry._data.uncompressedSize, { + base: 10, + })}) -
    • ` - }); + `; + }); - innerHTML += '
    '; + innerHTML += "
"; - newElement.innerHTML = innerHTML + newElement.innerHTML = innerHTML; - pbd.append(newElement); + pbd.append(newElement); - console.debug() + console.debug(); - document.querySelectorAll('.download-zip-content').forEach((element) => { - const elementListener = (e) => { - e.preventDefault(); - var filename = element.getAttribute('download'); - zip.files[filename].async('blob').then((blob) => { - element.removeEventListener('click', elementListener); - element.setAttribute('href', URL.createObjectURL(blob)); - element.click(); - }); - }; - element.addEventListener('click', elementListener); + document.querySelectorAll(".download-zip-content").forEach((element) => { + const elementListener = (e) => { + e.preventDefault(); + var filename = element.getAttribute("download"); + zip.files[filename].async("blob").then((blob) => { + element.removeEventListener("click", elementListener); + element.setAttribute("href", URL.createObjectURL(blob)); + element.click(); + }); + }; + element.addEventListener("click", elementListener); - showZipContentDOM.style.display = "none"; + showZipContentDOM.style.display = "none"; - showZipContentDOM.removeEventListener('click', showZipContentDOMListener); - }); - }) + showZipContentDOM.removeEventListener( + "click", + showZipContentDOMListener + ); + }); + }); }; - showZipContentDOM.onclick = showZipContentDOMListener - -} + showZipContentDOM.onclick = showZipContentDOMListener; +}; diff --git a/themes/default/public/js/lufi-files.js b/themes/default/public/js/lufi-files.js index 325469a..a7ee7e2 100644 --- a/themes/default/public/js/lufi-files.js +++ b/themes/default/public/js/lufi-files.js @@ -1,217 +1,248 @@ // vim:set sw=4 ts=4 sts=4 ft=javascript expandtab: // Add item to localStorage -function addItem(item) { - var files = localStorage.getItem(`${window.prefix}files`); - if (files === null) { - files = new Array(); - } else { - files = JSON.parse(files); - } - files.push(item); - localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); -} +const addItem = (item) => { + const files = JSON.parse(localStorage.getItem(`${window.prefix}files`)) || []; -function delItem(name) { - var files = localStorage.getItem(`${window.prefix}files`); - if (files === null) { - files = new Array(); - } else { - files = JSON.parse(files); + files.push(item); + localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); +}; + +const delItem = (name) => { + const files = JSON.parse(localStorage.getItem(`${window.prefix}files`)) || []; + + let i; + for (i = 0; i < files.length; i++) { + if (files[i].short === name) { + files.splice(i, 1); } - var i; + } + localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); +}; + +const itemExists = (name) => { + let files = localStorage.getItem(`${window.prefix}files`); + if (files === null) { + return false; + } else { + files = JSON.parse(files); + + let i; for (i = 0; i < files.length; i++) { - if (files[i].short === name) { - files.splice(i, 1); - } + if (files[i].short === name) { + return true; + } } - localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); -} + return false; + } +}; -function itemExists(name) { - var files = localStorage.getItem(`${window.prefix}files`); - if (files === null) { - return false; +const invertSelection = (event) => { + event.preventDefault(); + document.querySelectorAll('input[type="checkbox"]').forEach((element) => { + element.click(); + + if (element.getAttribute("data-checked") === "data-checked") { + element.setAttribute("data-checked", null); } else { - files = JSON.parse(files); - var i; - for (i = 0; i < files.length; i++) { - if (files[i].short === name) { - return true; - } - } - return false; + element.setAttribute("data-checked", "data-checked"); } -} + }); + evaluateMassDelete(); +}; -function invertSelection(event) { - event.preventDefault(); - $('input[type="checkbox"]').each(function() { - var el = $(this); - el.click(); - if (el.attr('data-checked') && el.attr('data-checked') === 'data-checked') { - el.attr('data-checked', null); - } else { - el.attr('data-checked', 'data-checked'); +const purgeExpired = (event) => { + event.preventDefault(); + + const files = JSON.parse(localStorage.getItem(`${window.prefix}files`)); + + files.forEach(function (element) { + fetch(counterURL, { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + }, + body: new URLSearchParams({ + short: element.short, + token: element.token, + }), + }) + .then((response) => { + if (!response.ok) { + throw new Error("Request error."); } - }); - evaluateMassDelete(); -} -function purgeExpired(event) { - event.preventDefault(); - var files = JSON.parse(localStorage.getItem(`${window.prefix}files`)); + return response.json(); + }) + .then((data) => { + if (data.success) { + if (data.deleted) { + const elementToRemove = document.querySelector( + `#count-${data.short}` + ); - files.forEach(function(element, index, array) { - $.ajax({ - url: counterURL, - method: 'POST', - dataType: 'json', - data: { - short: element.short, - token: element.token - }, - success: function(data, textStatus, jqXHR) { - if (data.success) { - if (data.deleted) { - $(`#count-${data.short}`).parent().remove(); - delItem(data.short); - } - } + if (elementToRemove) { + elementToRemove.parentElement.remove(); } - }); - }); -} -function exportStorage(event) { - event.preventDefault(); - var a = $(''); - a.hide(); - $('body').append(a); - - var storageData = [localStorage.getItem(`${window.prefix}files`)]; - var exportFile = new Blob(storageData, {type : 'application/json'}); - var url = window.URL.createObjectURL(exportFile); - - a.attr('href', url); - a.attr('download', 'data.json'); - $('#data-json')[0].click(); - $('#data-json').remove(); -} - -function importStorage(f) { - var reader = new FileReader(); - reader.addEventListener("loadend", function() { - try { - var newFiles = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(reader.result))); - var i; - var hasImported = 0; - for (i = 0; i < newFiles.length; i++) { - var item = newFiles[i]; - if (validURL(item.url) && !itemExists(item.short)) { - addItem(item); - hasImported++; - } - } - populateFilesTable(); - - Materialize.toast(i18n.importProcessed); - } catch(err) { - alert(err); + delItem(data.short); + } } - }); - reader.readAsArrayBuffer(f[0]); -} + }); + }); +}; -function validURL(str) { +const exportStorage = (event) => { + event.preventDefault(); + + const a = document.createElement("a"); + a.id = "data-json"; + + a.style.display = "none"; + + document.body.append(a); + + const storageData = [localStorage.getItem(`${window.prefix}files`)]; + const exportFile = new Blob(storageData, { type: "application/json" }); + const url = window.URL.createObjectURL(exportFile); + + a.setAttribute("href", url); + a.setAttribute("download", "data.json"); + + a.click(); + a.remove(); +}; + +const importStorage = (f) => { + let reader = new FileReader(); + + reader.addEventListener("loadend", () => { try { - var url = new URL(str); - if (url.host) { - return true; - } else { - return false; + const newFiles = JSON.parse( + String.fromCharCode.apply(null, new Uint8Array(reader.result)) + ); + let i; + let hasImported = 0; + for (i = 0; i < newFiles.length; i++) { + const item = newFiles[i]; + if (validURL(item.url) && !itemExists(item.short)) { + addItem(item); + hasImported++; } - } catch(e) { - return false; - } -} + } + populateFilesTable(); -function delFile() { - var dlink = $(this).attr('data-dlink'); - var short = $(this).attr('data-short'); - $.ajax({ - url: dlink, - method: 'GET', - data: { - _format: 'json' - }, - success: function(data) { - if (data.success) { - $(`#row-${short}`).remove(); - delItem(short); - } else { - alert(data.msg); - } - evaluateMassDelete(); - }, - error: function() { - }, - complete: function() { - } + Materialize.toast(i18n.importProcessed); + } catch (err) { + alert(err); + } + }); + reader.readAsArrayBuffer(f[0]); +}; + +const validURL = (str) => { + try { + return new URL(str).host ? true : false; + } catch (e) { + return false; + } +}; + +const delFile = (element) => { + const deleteUrl = new URL(element.getAttribute("data-dlink")); + const short = element.getAttribute("data-short"); + + deleteUrl.searchParams.append("_format", "json"); + + fetch(deleteUrl, { + method: "GET", + }) + .then((response) => { + if (!response.ok) { + throw new Error("Network error while deleting file"); + } + + return response.json(); + }) + .then((data) => { + if (data.success) { + document.getElementById(`row-${short}`).remove(); + delItem(short); + } else { + alert(data.msg); + } + evaluateMassDelete(); }); -} +}; -function evaluateMassDelete() { - if ($('input[data-checked="data-checked"]').length > 0) { - $('#mass-delete').removeAttr('disabled'); - $('#mass-delete').removeClass('disabled'); +const evaluateMassDelete = () => { + const massDeleteDOM = document.getElementById("mass-delete"); + + if ( + document.querySelectorAll('input[data-checked="data-checked"]').length > 0 + ) { + massDeleteDOM.removeAttribute("disabled"); + massDeleteDOM.classList.remove("disabled"); + } else { + massDeleteDOM.setAttribute("disabled", "disabled"); + massDeleteDOM.classList.add("disabled"); + } +}; + +const massDelete = (event) => { + event.preventDefault(); + document + .querySelectorAll('input[data-checked="data-checked"]') + .forEach(delFile); +}; + +const populateFilesTable = () => { + const myFilesDOM = document.getElementById("myfiles"); + + myFilesDOM.innerHTML = ""; + + let files = localStorage.getItem(`${window.prefix}files`); + if (files === null) { + var filesWithoutPrefix = localStorage.getItem("files"); + if (filesWithoutPrefix !== null) { + if (window.confirm(i18n.importFilesWithoutPrefix)) { + localStorage.setItem(`${window.prefix}files`, filesWithoutPrefix); + files = JSON.parse(filesWithoutPrefix); + } else { + localStorage.setItem(`${window.prefix}files`, JSON.stringify([])); + files = []; + } } else { - $('#mass-delete').attr('disabled'); - $('#mass-delete').addClass('disabled'); + files = []; } -} + } else { + files = JSON.parse(files); + } -function massDelete(event) { - event.preventDefault(); - $('input[data-checked="data-checked"]').each(delFile); -} - -function populateFilesTable() { - $('#myfiles').empty(); - - var files = localStorage.getItem(`${window.prefix}files`); - if (files === null) { - var filesWithoutPrefix = localStorage.getItem('files'); - if (filesWithoutPrefix !== null) { - if (window.confirm(i18n.importFilesWithoutPrefix)) { - localStorage.setItem(`${window.prefix}files`, filesWithoutPrefix); - files = JSON.parse(filesWithoutPrefix); - } else { - localStorage.setItem(`${window.prefix}files`, JSON.stringify([])); - files = new Array(); - } - } else { - files = new Array(); - } + files.sort(function (a, b) { + if (a.created_at < b.created_at) { + return -1; + } else if (a.created_at > b.created_at) { + return 1; } else { - files = JSON.parse(files); + return 0; } - files.sort(function(a, b) { - if (a.created_at < b.created_at) { - return -1; - } else if (a.created_at > b.created_at) { - return 1; - } else { - return 0 - } - }); - files.forEach(function(element, index, array) { - var del_view = (element.del_at_first_view) ? '' : ''; - var dlink = `${actionURL}d/${element.short}/${element.token}`; - var limit = (element.delay === 0) ? i18n.noExpiration : formatDate(element.delay * 86400 + element.created_at); - var created_at = formatDate(element.created_at); + }); - var tr = $(``); - tr.html(` + files.forEach(function (element) { + const del_view = element.del_at_first_view + ? '' + : ''; + const dlink = `${actionURL}d/${element.short}/${element.token}`; + const limit = + element.delay === 0 + ? i18n.noExpiration + : formatDate(element.delay * 86400 + element.created_at); + const created_at = formatDate(element.created_at); + + const tr = document.createElement("tr"); + tr.id = `row-${element.short}`; + + tr.innerHTML = ` - - `); - $('#myfiles').append(tr); - $(`#del-${element.short}`).on('click', delFile); - $(`label[for="check-${element.short}"]`).on('click', function(){ - if ($(`#check-${element.short}`).attr('data-checked') && $(`#check-${element.short}`).attr('data-checked') === 'data-checked') { - $(`#check-${element.short}`).attr('data-checked', null); + `; + + myFilesDOM.append(tr); + + document.getElementById(`del-${element.short}`).onclick = (event) => + delFile(event.target.parentElement); + + document.querySelector(`label[for="check-${element.short}"]`).onclick = ( + event + ) => { + const checkDOM = document.getElementById(`check-${element.short}`); + + if (checkDOM.getAttribute("data-checked") === "data-checked") { + checkDOM.setAttribute("data-checked", null); + } else { + checkDOM.setAttribute("data-checked", "data-checked"); + } + + evaluateMassDelete(); + }; + + fetch(counterURL, { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + }, + body: new URLSearchParams({ + short: element.short, + token: element.token, + }), + }) + .then((response) => { + if (!response.ok) { + throw new Error("Request error."); + } + + return response.json(); + }) + .then((data) => { + if (data.success) { + if (data.deleted) { + const countDOM = document.getElementById(`count-${data.short}`); + + countDOM.innerHTML = data.counter; + + if (data.deleted) { + countDOM.parentElement.classList.add("purple", "lighten-4"); } else { - $(`#check-${element.short}`).attr('data-checked', 'data-checked'); - } - evaluateMassDelete(); - }); + alert(data.msg); + countDOM.parentElement.remove(); - $.ajax({ - url: counterURL, - method: 'POST', - dataType: 'json', - data: { - short: element.short, - token: element.token - }, - success: function(data, textStatus, jqXHR) { - if (data.success) { - $(`#count-${data.short}`).html(data.counter); - if (data.deleted) { - $(`#count-${data.short}`).parent().addClass('purple lighten-4'); - } - } else { - alert(data.msg); - $(`#count-${data.short}`).parent().remove(); - if (data.missing) { - delItem(data.short); - } - } + if (data.missing) { + delItem(data.short); + } } - }); - }); -} + } + } + }); + }); +}; -function clickImport(event) { - event.preventDefault(); - $('#import').click(); -} +const clickImport = (event) => { + event.preventDefault(); + document.getElementById("import").click(); +}; diff --git a/themes/default/public/js/lufi-up.js b/themes/default/public/js/lufi-up.js index 340463b..f8f5ef6 100755 --- a/themes/default/public/js/lufi-up.js +++ b/themes/default/public/js/lufi-up.js @@ -1,24 +1,25 @@ // vim:set sw=4 ts=4 sts=4 ft=javascript expandtab: -import { lufi, okAsync, errAsync } from "/js/lufi.js"; +import { + lufi, + okAsync, + ResultAsync, + isSecureContext, + CryptoAlgorithm, +} from "/js/lufi.js"; // Cancelled files indexes window.cancelled = []; -// Set websocket -// window.ws = spawnWebsocket(0, function () { -// return null; -// }); -// Use slice of 0.75MB -window.sliceLength = 750000; // Global zip objects for currently created zip file -window.zip = null; window.zipSize = 0; // Init the list of files (used by LDAP invitation feature) window.filesURLs = []; +let archiveEntries; + // Copy a link to clipboard function copyToClipboard(txt) { - var textArea = document.createElement("textarea"); + const textArea = document.createElement("textarea"); textArea.className = "textarea-hidden"; textArea.value = txt; @@ -56,7 +57,16 @@ function copyAllToClipboard(event) { } // Add item to localStorage -function addItem(name, url, size, del_at_first_view, created_at, delay, short, token) { +function addItem( + name, + url, + size, + del_at_first_view, + created_at, + delay, + short, + token +) { let files = localStorage.getItem(`${window.prefix}files`); files = JSON.parse(files) || []; @@ -79,7 +89,10 @@ function destroyBlock(clientKey) { if (document.querySelectorAll(".link-input").length === 0) { document.getElementById("misc").innerHTML = ""; - if (document.querySelectorAll("#results li").length === 0 && window.fileList === null) { + if ( + document.querySelectorAll("#results li").length === 0 && + window.fileList === null + ) { document.getElementById("results").style.display = "none"; } } else { @@ -93,7 +106,8 @@ function firstViewClicking() { .getElementById("first-view") .setAttribute( "data-checked", - document.getElementById("first-view").getAttribute("data-checked") === "data-checked" + document.getElementById("first-view").getAttribute("data-checked") === + "data-checked" ? null : "data-checked" ); @@ -101,9 +115,11 @@ function firstViewClicking() { // When clicking on zip checkbox function zipClicking() { - if (document.getElementById("zip-files").getAttribute("data-checked") === "data-checked") { + if ( + document.getElementById("zip-files").getAttribute("data-checked") === + "data-checked" + ) { window.zipSize = 0; - window.zip = null; document.getElementById("zip-files").removeAttribute("data-checked"); document.getElementById("zipname").value = "documents.zip"; document.getElementById("zipname-input").classList.add("hide"); @@ -112,7 +128,9 @@ function zipClicking() { document.getElementById("zip-parts").innerHTML = ""; document.getElementById("delete-day").removeAttribute("disabled"); } else { - document.getElementById("zip-files").setAttribute("data-checked", "data-checked"); + document + .getElementById("zip-files") + .setAttribute("data-checked", "data-checked"); document.getElementById("zipname-input").classList.remove("hide"); document.getElementById("zip-size").innerText = filesize(window.zipSize); } @@ -120,14 +138,10 @@ function zipClicking() { // Get the zip file name const getZipname = () => { - var zipname = document.getElementById("zipname").value || "documents.zip"; + let zipname = document.getElementById("zipname").value || "documents.zip"; if (!zipname.endsWith(".zip")) { - if (zipname.endsWith(".")) { - zipname += "zip"; - } else { - zipname += ".zip"; - } + zipname += zipname.endsWith(".") ? "zip" : ".zip"; } return escapeHtml(zipname); @@ -141,8 +155,8 @@ const updateZipname = () => { // Create blob from zip const uploadZip = (e) => { e.preventDefault(); - var delay = document.getElementById("delete-day"); - var del_at_first_view = document.getElementById("first-view"); + const delay = document.getElementById("delete-day"); + const del_at_first_view = document.getElementById("first-view"); document.getElementById("zip-files").disabled = true; document.getElementById("file-browser-button").disabled = true; document.getElementById("file-browser-span").classList.add("disabled"); @@ -150,33 +164,52 @@ const uploadZip = (e) => { document.getElementById("zip-parts").textContent = ""; document.getElementById("zip-compressing").classList.remove("hide"); - window.zip.generateAsync({ type: "blob" }).then((zipFile) => { - // if '#zipping' is hidden, the zipping has been aborted - if (!document.getElementById("zipping").classList.contains("hide")) { - window.zip = null; - document.getElementById("zipping").classList.add("hide"); - document.getElementById("files").classList.remove("m6"); - document.getElementById("files").classList.add("m12"); - document.getElementById("zipname-input").classList.add("hide"); - document.getElementById("zip-compressing").classList.add("hide"); - document.getElementById("uploadZip").classList.remove("hide"); - document.getElementById("results").style.display = "block"; - document.getElementById("zip-files").disabled = false; - var zipname = getZipname(); - const password = document.getElementById("file_pwd").value; + const zipname = getZipname(); - var file = new File([zipFile], zipname, { type: "application/zip" }); + lufi + .compress(archiveEntries, zipname) + .andThen((zipFile) => { + // if '#zipping' is hidden, the zipping has been aborted + if (!document.getElementById("zipping").classList.contains("hide")) { + document.getElementById("zipping").classList.add("hide"); + document.getElementById("files").classList.remove("m6"); + document.getElementById("files").classList.add("m12"); + document.getElementById("zipname-input").classList.add("hide"); + document.getElementById("zip-compressing").classList.add("hide"); + document.getElementById("uploadZip").classList.remove("hide"); + document.getElementById("results").style.display = "block"; + document.getElementById("zip-files").disabled = false; + document.getElementById("zip-files").removeAttribute("data-checked"); + document.getElementById("zip-files").checked = false; - Materialize.toast(i18n.enqueued.replace("XXX", zipname), 3000, "teal accent-3"); + const password = document.getElementById("file_pwd").value; - window.fileList = window.fileList || [file]; + Materialize.toast( + i18n.enqueued.replace("XXX", zipname), + 3000, + "teal accent-3" + ); - startUpload(file, delay.value, del_at_first_view.checked, true, password); - } - document.getElementById("file-browser-button").disabled = false; - document.getElementById("file-browser-span").classList.remove("disabled"); - }); + window.fileList = window.fileList || [zipFile]; + + startUpload( + [zipFile], + delay.value, + del_at_first_view.checked, + true, + zipname, + password + ); + + archiveEntries = undefined; + } + document.getElementById("file-browser-button").disabled = false; + document.getElementById("file-browser-span").classList.remove("disabled"); + + return okAsync(undefined); + }) + .orElse((error) => console.error(error.message)); }; // Update the mail link @@ -239,8 +272,7 @@ const handleDrop = (evt) => { evt.stopPropagation(); evt.preventDefault(); - var f = evt.dataTransfer.files; // FileList object - handleFiles(f); + handleFiles(evt.dataTransfer.files); }; const handleDragOver = (evt) => { @@ -259,9 +291,11 @@ const bindDropZone = () => { document.getElementById("file-browser-span").classList.add("cyan"); document.getElementById("file-browser-button").disabled = false; - document.getElementById("file-browser-button").addEventListener("change", (e) => { - handleFiles(e.target.files); - }); + document + .getElementById("file-browser-button") + .addEventListener("change", (e) => { + handleFiles(e.target.files); + }); }; // On page load @@ -278,99 +312,129 @@ document.addEventListener("DOMContentLoaded", () => { ); } - document.querySelector('label[for="first-view"]').addEventListener("click", firstViewClicking); - document.querySelector('label[for="zip-files"]').addEventListener("click", zipClicking); + document + .querySelector('label[for="first-view"]') + .addEventListener("click", firstViewClicking); + document + .querySelector('label[for="zip-files"]') + .addEventListener("click", zipClicking); document.getElementById("zipname").addEventListener("input", updateZipname); document.getElementById("uploadZip").addEventListener("click", uploadZip); document.getElementById("reset-zipping").addEventListener("click", () => { - window.zip = null; + archiveEntries = undefined; document.querySelector('label[for="zip-files"]').click(); document.getElementById("zip-files").disabled = false; + document.getElementById("zip-files").removeAttribute("data-checked"); document.getElementById("zip-compressing").classList.add("hide"); document.getElementById("file-browser-button").disabled = false; document.getElementById("file-browser-span").classList.remove("disabled"); - document.getElementById("files").classList.remove("m6").classList.add("m12"); + document.getElementById("files").classList.replace("m6", "m12"); }); }); -const startUpload = (file, delay, delAtFirstView, isZipped, password) => { +const startUpload = ( + files, + delay, + delAtFirstView, + isZipped, + zipName, + password +) => { let clientKey; - lufi - .upload(window.location, file, delay, delAtFirstView, isZipped, password) - .andThen((job) => { - clientKey = job.lufiFile.keys.client; + return lufi + .upload( + window.location, + files, + delay, + delAtFirstView, + isZipped, + zipName, + password, + isSecureContext() ? CryptoAlgorithm.WebCrypto : CryptoAlgorithm.Sjcl + ) + .andThen((jobs) => + ResultAsync.combine( + jobs.map((job) => { + clientKey = job.lufiFile.keys.client; - createUploadBox(job); + createUploadBox(job); - job.onProgress(() => { - updateProgressBar(job.lufiFile); - }); + job.onProgress(() => { + updateProgressBar(job.lufiFile); + }); - return job.waitForCompletion(); - }) - .andThen((job) => { - notify(i18n.fileUploaded, job.lufiFile.name); + return job + .waitForCompletion() + .andThen((job) => { + notify(i18n.fileUploaded, job.lufiFile.name); - if (isGuest) { - sendFilesURLs(); - } + if (isGuest) { + sendFilesURLs(); + } - uploadBoxComplete(job.lufiFile); + uploadBoxComplete(job.lufiFile); - // Add the file to localStorage - if (!isGuest) { - addItem( - job.lufiFile.name, - job.lufiFile.downloadUrl(), - job.lufiFile.size, - delAtFirstView, - job.lufiFile.createdAt, - delay, - job.lufiFile.keys.server, - job.lufiFile.actionToken - ); - } + // Add the file to localStorage + if (!isGuest) { + addItem( + job.lufiFile.name, + job.lufiFile.downloadUrl(), + job.lufiFile.size, + delAtFirstView, + job.lufiFile.createdAt, + delay, + job.lufiFile.keys.server, + job.lufiFile.actionToken + ); + } - if (isGuest && job.lufiFile.keys.server !== null) { - window.filesURLs.push( - JSON.stringify({ - name: job.lufiFile.name, - short: job.lufiFile.keys.server, - url: job.lufiFile.downloadUrl(), - size: job.lufiFile.size, - created_at: job.lufiFile.createdAt, - delay, - token: job.lufiFile.actionToken, - }) - ); - } + if (isGuest && job.lufiFile.keys.server !== null) { + window.filesURLs.push( + JSON.stringify({ + name: job.lufiFile.name, + short: job.lufiFile.keys.server, + url: job.lufiFile.downloadUrl(), + size: job.lufiFile.size, + created_at: job.lufiFile.createdAt, + delay, + token: job.lufiFile.actionToken, + }) + ); + } - return okAsync(job); - }) - .mapErr((error) => { - if (clientKey) { - showAlertOnFile(error.message, clientKey); - } else { - console.error(error.message); - } + return okAsync(job); + }) + .mapErr((error) => { + if (clientKey) { + showAlertOnFile(error.message, clientKey); + } else { + console.error(error.message); + } - if (isGuest) { - sendFilesURLs(); - } - }); + if (isGuest) { + sendFilesURLs(); + } + }); + }) + ) + ); }; const handleFiles = (files = []) => { const filesArray = Array.from(files); const isZipped = - document.getElementById("zip-files").getAttribute("data-checked") === "data-checked"; + document.getElementById("zip-files").getAttribute("data-checked") === + "data-checked"; + + document.body.style.cursor = "wait"; if (!isZipped) { const delay = document.getElementById("delete-day").value; const delAtFirstView = - document.getElementById("first-view").getAttribute("data-checked") === "data-checked"; + document.getElementById("first-view").getAttribute("data-checked") === + "data-checked"; const password = document.getElementById("file_pwd").value; if (window.fileList === undefined || window.fileList === null) { @@ -392,43 +456,43 @@ const handleFiles = (files = []) => { window.fileList = window.fileList.concat(filesArray); // Concatenate new files } - filesArray.forEach((file) => { - startUpload(file, delay, delAtFirstView, isZipped, password); - }); + document.body.style.cursor = "default"; + + startUpload(filesArray, delay, delAtFirstView, isZipped, password); } else { - window.zip = window.zip || new JSZip(); + lufi + .addFilesToArchive(filesArray, archiveEntries) + .andThen((entries) => { + archiveEntries = entries; - document.getElementById("zipping").classList.remove("hide"); - const filesElement = document.getElementById("files"); - filesElement.classList.remove("m12"); - filesElement.classList.add("m6"); + document.getElementById("zipping").classList.remove("hide"); + const filesElement = document.getElementById("files"); + filesElement.classList.replace("m12", "m6"); - for (let i = 0; i < files.length; i++) { - const element = files.item(i); - let filename = element.name; - const originalName = filename; - let counter = 0; + const zipPartsDOM = document.getElementById("zip-parts"); - // Ensure unique filename - while (window.zip.files[filename] !== undefined) { - counter++; - const extensionIndex = originalName.lastIndexOf("."); - const baseName = originalName.substring(0, extensionIndex); - const extension = originalName.substring(extensionIndex); - filename = `${baseName}_(${counter})${extension}`; - } + zipPartsDOM.replaceChildren(); - // Add the file to the zip - window.zip.file(filename, element); - window.zipSize += element.size; + for (const [name, file] of Object.entries(archiveEntries)) { + window.zipSize += file.length; - // Update DOM - document.getElementById("zip-size").textContent = filesize(window.zipSize); - const zipPartsElement = document.getElementById("zip-parts"); - const listItem = document.createElement("li"); - listItem.innerHTML = `— ${escapeHtml(filename)} (${filesize(element.size)})`; - zipPartsElement.appendChild(listItem); - } + const listItemDOM = document.createElement("li"); + listItemDOM.innerHTML = `— ${escapeHtml(name)} (${filesize( + file.length + )})`; + + zipPartsDOM.appendChild(listItemDOM); + } + + document.getElementById("zip-size").textContent = filesize( + window.zipSize + ); + + document.body.style.cursor = "default"; + + return okAsync(undefined); + }) + .orElse((error) => console.error(error.message)); } }; @@ -450,7 +514,9 @@ const createUploadBox = (job) => {
${job.lufiFile.name} - (${filesize(job.lufiFile.size)}) + (${filesize( + job.lufiFile.size + )})

@@ -501,7 +567,9 @@ const uploadBoxComplete = (lufiFile) => { const limit = lufiFile.delay === 0 ? i18n.noLimit - : `${i18n.expiration} ${formatDate(lufiFile.delay * 86400 + lufiFile.createdAt)}`; + : `${i18n.expiration} ${formatDate( + lufiFile.delay * 86400 + lufiFile.createdAt + )}`; if (!isGuest) { nameDOM.innerHTML += `${sizeDOM.innerHTML}
${limit}`; @@ -542,10 +610,12 @@ const uploadBoxComplete = (lufiFile) => { p1.appendChild(newDivDOM); // Copy URL to clipboard - document.getElementById(`copyurl-${clientKey}`).addEventListener("click", (e) => { - e.preventDefault(); - copyToClipboard(downloadUrl); - }); + document + .getElementById(`copyurl-${clientKey}`) + .addEventListener("click", (e) => { + e.preventDefault(); + copyToClipboard(downloadUrl); + }); // Select input text on click document.querySelectorAll("input[type='text']").forEach((input) => { @@ -562,14 +632,17 @@ const uploadBoxComplete = (lufiFile) => { ${i18n.copyAll} ${i18n.mailTo} `; - document.getElementById("copyall").addEventListener("click", copyAllToClipboard); + document + .getElementById("copyall") + .addEventListener("click", copyAllToClipboard); } else { updateMailLink(); } }; const updateProgressBar = (lufiFile) => { - const percent = Math.round((1000 * lufiFile.chunksReady) / lufiFile.totalChunks) / 10; + const percent = + Math.round((1000 * lufiFile.chunksReady) / lufiFile.totalChunks) / 10; const wClass = percent.toString().replace(".", "-"); const dp = document.getElementById(`progress-${lufiFile.keys.client}`); @@ -578,5 +651,7 @@ const updateProgressBar = (lufiFile) => { dp.classList.add(`width-${wClass}`); dp.setAttribute("aria-valuenow", percent); - document.getElementById(`parts-${lufiFile.keys.client}`).innerHTML = `${percent.toFixed(1)}%`; + document.getElementById( + `parts-${lufiFile.keys.client}` + ).innerHTML = `${percent.toFixed(1)}%`; }; diff --git a/themes/default/public/js/lufi.js b/themes/default/public/js/lufi.js index 0a92812..cb81f59 100755 --- a/themes/default/public/js/lufi.js +++ b/themes/default/public/js/lufi.js @@ -1 +1,3547 @@ -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}; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __defNormalProp = (obj3, key, value) => key in obj3 ? __defProp(obj3, key, { enumerable: true, configurable: true, writable: true, value }) : obj3[key] = value; +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); +var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __publicField = (obj3, key, value) => __defNormalProp(obj3, typeof key !== "symbol" ? key + "" : key, value); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter3() { + EventEmitter3.init.call(this); + } + module.exports = EventEmitter3; + module.exports.once = once; + EventEmitter3.EventEmitter = EventEmitter3; + EventEmitter3.prototype._events = void 0; + EventEmitter3.prototype._eventsCount = 0; + EventEmitter3.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter3, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter3.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter3.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter3.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter3.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter3.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events2 = this._events; + if (events2 !== void 0) + doError = doError && events2.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err3 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err3.context = er; + throw err3; + } + var handler = events2[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events2; + var existing; + checkListener(listener); + events2 = target._events; + if (events2 === void 0) { + events2 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events2.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events2 = target._events; + } + existing = events2[type]; + } + if (existing === void 0) { + existing = events2[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events2[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter3.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter3.prototype.on = EventEmitter3.prototype.addListener; + EventEmitter3.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter3.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter3.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter3.prototype.removeListener = function removeListener(type, listener) { + var list, events2, position, i, originalListener; + checkListener(listener); + events2 = this._events; + if (events2 === void 0) + return this; + list = events2[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events2[type]; + if (events2.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events2[type] = list[0]; + if (events2.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter3.prototype.off = EventEmitter3.prototype.removeListener; + EventEmitter3.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events2, i; + events2 = this._events; + if (events2 === void 0) + return this; + if (events2.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events2[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events2[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events2); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events2[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events2 = target._events; + if (events2 === void 0) + return []; + var evlistener = events2[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter3.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter3.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter3.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter3.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events2 = this._events; + if (events2 !== void 0) { + var evlistener = events2[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter3.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err3) { + emitter.removeListener(name, resolver); + reject(err3); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js +var require_sjcl = __commonJS({ + "node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js"(exports, module) { + "use strict"; + var sjcl2 = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function(a) { + this.toString = function() { + return "CORRUPT: " + this.message; + }; + this.message = a; + }, invalid: function(a) { + this.toString = function() { + return "INVALID: " + this.message; + }; + this.message = a; + }, bug: function(a) { + this.toString = function() { + return "BUG: " + this.message; + }; + this.message = a; + }, notReady: function(a) { + this.toString = function() { + return "NOT READY: " + this.message; + }; + this.message = a; + } } }; + sjcl2.cipher.aes = function(a) { + this.s[0][0][0] || this.O(); + var b, c, d, e, f = this.s[0][4], g = this.s[1]; + b = a.length; + var h = 1; + if (4 !== b && 6 !== b && 8 !== b) throw new sjcl2.exception.invalid("invalid aes key size"); + this.b = [d = a.slice(0), e = []]; + for (a = b; a < 4 * b + 28; a++) { + c = d[a - 1]; + if (0 === a % b || 8 === b && 4 === a % b) c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7)); + d[a] = d[a - b] ^ c; + } + for (b = 0; a; b++, a--) c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & 255]]; + }; + sjcl2.cipher.aes.prototype = { encrypt: function(a) { + return t(this, a, 0); + }, decrypt: function(a) { + return t(this, a, 1); + }, s: [[[], [], [], [], []], [[], [], [], [], []]], O: function() { + var a = this.s[0], b = this.s[1], c = a[4], d = b[4], e, f, g, h = [], k = [], l, n, m, p; + for (e = 0; 256 > e; e++) k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e; + for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, n = h[e = h[l = h[f]]], p = 16843009 * n ^ 65537 * e ^ 257 * l ^ 16843008 * f, n = 257 * h[m] ^ 16843008 * m, e = 0; 4 > e; e++) a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8; + for (e = 0; 5 > e; e++) a[e] = a[e].slice(0), b[e] = b[e].slice(0); + } }; + function t(a, b, c) { + if (4 !== b.length) throw new sjcl2.exception.invalid("invalid aes block size"); + var d = a.b[c], e = b[0] ^ d[0], f = b[c ? 3 : 1] ^ d[1], g = b[2] ^ d[2]; + b = b[c ? 1 : 3] ^ d[3]; + var h, k, l, n = d.length / 4 - 2, m, p = 4, r = [0, 0, 0, 0]; + h = a.s[c]; + a = h[0]; + var q = h[1], v = h[2], w = h[3], x = h[4]; + for (m = 0; m < n; m++) h = a[e >>> 24] ^ q[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ q[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], l = a[g >>> 24] ^ q[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ q[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = l; + for (m = 0; 4 > m; m++) r[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h; + return r; + } + sjcl2.bitArray = { bitSlice: function(a, b, c) { + a = sjcl2.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1); + return void 0 === c ? a : sjcl2.bitArray.clamp(a, c - b); + }, extract: function(a, b, c) { + var d = Math.floor(-b - c & 31); + return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1; + }, concat: function(a, b) { + if (0 === a.length || 0 === b.length) return a.concat(b); + var c = a[a.length - 1], d = sjcl2.bitArray.getPartial(c); + return 32 === d ? a.concat(b) : sjcl2.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1)); + }, bitLength: function(a) { + var b = a.length; + return 0 === b ? 0 : 32 * (b - 1) + sjcl2.bitArray.getPartial(a[b - 1]); + }, clamp: function(a, b) { + if (32 * a.length < b) return a; + a = a.slice(0, Math.ceil(b / 32)); + var c = a.length; + b = b & 31; + 0 < c && b && (a[c - 1] = sjcl2.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)); + return a; + }, partial: function(a, b, c) { + return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 1099511627776 * a; + }, getPartial: function(a) { + return Math.round(a / 1099511627776) || 32; + }, equal: function(a, b) { + if (sjcl2.bitArray.bitLength(a) !== sjcl2.bitArray.bitLength(b)) return false; + var c = 0, d; + for (d = 0; d < a.length; d++) c |= a[d] ^ b[d]; + return 0 === c; + }, $: function(a, b, c, d) { + var e; + e = 0; + for (void 0 === d && (d = []); 32 <= b; b -= 32) d.push(c), c = 0; + if (0 === b) return d.concat(a); + for (e = 0; e < a.length; e++) d.push(c | a[e] >>> b), c = a[e] << 32 - b; + e = a.length ? a[a.length - 1] : 0; + a = sjcl2.bitArray.getPartial(e); + d.push(sjcl2.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1)); + return d; + }, i: function(a, b) { + return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; + }, byteswapM: function(a) { + var b, c; + for (b = 0; b < a.length; ++b) c = a[b], a[b] = c >>> 24 | c >>> 8 & 65280 | (c & 65280) << 8 | c << 24; + return a; + } }; + sjcl2.codec.utf8String = { fromBits: function(a) { + var b = "", c = sjcl2.bitArray.bitLength(a), d, e; + for (d = 0; d < c / 8; d++) 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8; + return decodeURIComponent(escape(b)); + }, toBits: function(a) { + a = unescape(encodeURIComponent(a)); + var b = [], c, d = 0; + for (c = 0; c < a.length; c++) d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); + c & 3 && b.push(sjcl2.bitArray.partial(8 * (c & 3), d)); + return b; + } }; + sjcl2.codec.hex = { fromBits: function(a) { + var b = "", c; + for (c = 0; c < a.length; c++) b += ((a[c] | 0) + 263882790666240).toString(16).substr(4); + return b.substr(0, sjcl2.bitArray.bitLength(a) / 4); + }, toBits: function(a) { + var b, c = [], d; + a = a.replace(/\s|0x/g, ""); + d = a.length; + a = a + "00000000"; + for (b = 0; b < a.length; b += 8) c.push(parseInt(a.substr(b, 8), 16) ^ 0); + return sjcl2.bitArray.clamp(c, 4 * d); + } }; + sjcl2.codec.base32 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", X: "0123456789ABCDEFGHIJKLMNOPQRSTUV", BITS: 32, BASE: 5, REMAINING: 27, fromBits: function(a, b, c) { + var d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = "", g = 0, h = sjcl2.codec.base32.B, k = 0, l = sjcl2.bitArray.bitLength(a); + c && (h = sjcl2.codec.base32.X); + for (c = 0; f.length * d < l; ) f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d); + for (; f.length & 7 && !b; ) f += "="; + return f; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, "").toUpperCase(); + var c = sjcl2.codec.base32.BITS, d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = [], g, h = 0, k = sjcl2.codec.base32.B, l = 0, n, m = "base32"; + b && (k = sjcl2.codec.base32.X, m = "base32hex"); + for (g = 0; g < a.length; g++) { + n = k.indexOf(a.charAt(g)); + if (0 > n) { + if (!b) try { + return sjcl2.codec.base32hex.toBits(a); + } catch (p) { + } + throw new sjcl2.exception.invalid("this isn't " + m + "!"); + } + h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h); + } + h & 56 && f.push(sjcl2.bitArray.partial(h & 56, l, 1)); + return f; + } }; + sjcl2.codec.base32hex = { fromBits: function(a, b) { + return sjcl2.codec.base32.fromBits(a, b, 1); + }, toBits: function(a) { + return sjcl2.codec.base32.toBits(a, 1); + } }; + sjcl2.codec.base64 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", fromBits: function(a, b, c) { + var d = "", e = 0, f = sjcl2.codec.base64.B, g = 0, h = sjcl2.bitArray.bitLength(a); + c && (f = f.substr(0, 62) + "-_"); + for (c = 0; 6 * d.length < h; ) d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6); + for (; d.length & 3 && !b; ) d += "="; + return d; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, ""); + var c = [], d, e = 0, f = sjcl2.codec.base64.B, g = 0, h; + b && (f = f.substr(0, 62) + "-_"); + for (d = 0; d < a.length; d++) { + h = f.indexOf(a.charAt(d)); + if (0 > h) throw new sjcl2.exception.invalid("this isn't base64!"); + 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e); + } + e & 56 && c.push(sjcl2.bitArray.partial(e & 56, g, 1)); + return c; + } }; + sjcl2.codec.base64url = { fromBits: function(a) { + return sjcl2.codec.base64.fromBits(a, 1, 1); + }, toBits: function(a) { + return sjcl2.codec.base64.toBits(a, 1); + } }; + sjcl2.hash.sha256 = function(a) { + this.b[0] || this.O(); + a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset(); + }; + sjcl2.hash.sha256.hash = function(a) { + return new sjcl2.hash.sha256().update(a).finalize(); + }; + sjcl2.hash.sha256.prototype = { blockSize: 512, reset: function() { + this.F = this.Y.slice(0); + this.A = []; + this.l = 0; + return this; + }, update: function(a) { + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + var b, c = this.A = sjcl2.bitArray.concat(this.A, a); + b = this.l; + a = this.l = b + sjcl2.bitArray.bitLength(a); + if (9007199254740991 < a) throw new sjcl2.exception.invalid("Cannot hash more than 2^53 - 1 bits"); + if ("undefined" !== typeof Uint32Array) { + var d = new Uint32Array(c), e = 0; + for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, d.subarray( + 16 * e, + 16 * (e + 1) + )), e += 1; + c.splice(0, 16 * e); + } else for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, c.splice(0, 16)); + return this; + }, finalize: function() { + var a, b = this.A, c = this.F, b = sjcl2.bitArray.concat(b, [sjcl2.bitArray.partial(1, 1)]); + for (a = b.length + 2; a & 15; a++) b.push(0); + b.push(Math.floor(this.l / 4294967296)); + for (b.push(this.l | 0); b.length; ) u(this, b.splice(0, 16)); + this.reset(); + return c; + }, Y: [], b: [], O: function() { + function a(a2) { + return 4294967296 * (a2 - Math.floor(a2)) | 0; + } + for (var b = 0, c = 2, d, e; 64 > b; c++) { + e = true; + for (d = 2; d * d <= c; d++) if (0 === c % d) { + e = false; + break; + } + e && (8 > b && (this.Y[b] = a(Math.pow(c, 0.5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++); + } + } }; + function u(a, b) { + var c, d, e, f = a.F, g = a.b, h = f[0], k = f[1], l = f[2], n = f[3], m = f[4], p = f[5], r = f[6], q = f[7]; + for (c = 0; 64 > c; c++) 16 > c ? d = b[c] : (d = b[c + 1 & 15], e = b[c + 14 & 15], d = b[c & 15] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + b[c & 15] + b[c + 9 & 15] | 0), d = d + q + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (r ^ m & (p ^ r)) + g[c], q = r, r = p, p = m, m = n + d | 0, n = l, l = k, k = h, h = d + (k & l ^ n & (k ^ l)) + (k >>> 2 ^ k >>> 13 ^ k >>> 22 ^ k << 30 ^ k << 19 ^ k << 10) | 0; + f[0] = f[0] + h | 0; + f[1] = f[1] + k | 0; + f[2] = f[2] + l | 0; + f[3] = f[3] + n | 0; + f[4] = f[4] + m | 0; + f[5] = f[5] + p | 0; + f[6] = f[6] + r | 0; + f[7] = f[7] + q | 0; + } + sjcl2.mode.ccm = { name: "ccm", G: [], listenProgress: function(a) { + sjcl2.mode.ccm.G.push(a); + }, unListenProgress: function(a) { + a = sjcl2.mode.ccm.G.indexOf(a); + -1 < a && sjcl2.mode.ccm.G.splice(a, 1); + }, fa: function(a) { + var b = sjcl2.mode.ccm.G.slice(), c; + for (c = 0; c < b.length; c += 1) b[c](a); + }, encrypt: function(a, b, c, d, e) { + var f, g = b.slice(0), h = sjcl2.bitArray, k = h.bitLength(c) / 8, l = h.bitLength(g) / 8; + e = e || 64; + d = d || []; + if (7 > k) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (f = 2; 4 > f && l >>> 8 * f; f++) ; + f < 15 - k && (f = 15 - k); + c = h.clamp( + c, + 8 * (15 - f) + ); + b = sjcl2.mode.ccm.V(a, b, c, d, e, f); + g = sjcl2.mode.ccm.C(a, g, c, b, e, f); + return h.concat(g.data, g.tag); + }, decrypt: function(a, b, c, d, e) { + e = e || 64; + d = d || []; + var f = sjcl2.bitArray, g = f.bitLength(c) / 8, h = f.bitLength(b), k = f.clamp(b, h - e), l = f.bitSlice(b, h - e), h = (h - e) / 8; + if (7 > g) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (b = 2; 4 > b && h >>> 8 * b; b++) ; + b < 15 - g && (b = 15 - g); + c = f.clamp(c, 8 * (15 - b)); + k = sjcl2.mode.ccm.C(a, k, c, l, e, b); + a = sjcl2.mode.ccm.V(a, k.data, c, d, e, b); + if (!f.equal(k.tag, a)) throw new sjcl2.exception.corrupt("ccm: tag doesn't match"); + return k.data; + }, na: function(a, b, c, d, e, f) { + var g = [], h = sjcl2.bitArray, k = h.i; + d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)]; + d = h.concat(d, c); + d[3] |= e; + d = a.encrypt(d); + if (b.length) for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 4294967295 >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); + return d; + }, V: function(a, b, c, d, e, f) { + var g = sjcl2.bitArray, h = g.i; + e /= 8; + if (e % 2 || 4 > e || 16 < e) throw new sjcl2.exception.invalid("ccm: invalid tag length"); + if (4294967295 < d.length || 4294967295 < b.length) throw new sjcl2.exception.bug("ccm: can't deal with 4GiB or more data"); + c = sjcl2.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f); + for (d = 0; d < b.length; d += 4) c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); + return g.clamp(c, 8 * e); + }, C: function(a, b, c, d, e, f) { + var g, h = sjcl2.bitArray; + g = h.i; + var k = b.length, l = h.bitLength(b), n = k / 50, m = n; + c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4); + d = h.bitSlice(g(d, a.encrypt(c)), 0, e); + if (!k) return { tag: d, data: [] }; + for (g = 0; g < k; g += 4) g > n && (sjcl2.mode.ccm.fa(g / k), n += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3]; + return { tag: d, data: h.clamp(b, l) }; + } }; + sjcl2.mode.ocb2 = { name: "ocb2", encrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + var g, h = sjcl2.mode.ocb2.S, k = sjcl2.bitArray, l = k.i, n = [0, 0, 0, 0]; + c = h(a.encrypt(c)); + var m, p = []; + d = d || []; + e = e || 64; + for (g = 0; g + 4 < b.length; g += 4) m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c); + m = b.slice(g); + b = k.bitLength(m); + g = a.encrypt(l(c, [0, 0, 0, b])); + m = k.clamp(l(m.concat([0, 0, 0]), g), b); + n = l(n, l(m.concat([0, 0, 0]), g)); + n = a.encrypt(l(n, l(c, h(c)))); + d.length && (n = l(n, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + return p.concat(k.concat(m, k.clamp(n, e))); + }, decrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + e = e || 64; + var g = sjcl2.mode.ocb2.S, h = sjcl2.bitArray, k = h.i, l = [0, 0, 0, 0], n = g(a.encrypt(c)), m, p, r = sjcl2.bitArray.bitLength(b) - e, q = []; + d = d || []; + for (c = 0; c + 4 < r / 32; c += 4) m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n); + p = r - 32 * c; + m = a.encrypt(k(n, [0, 0, 0, p])); + m = k(m, h.clamp(b.slice(c), p).concat([ + 0, + 0, + 0 + ])); + l = k(l, m); + l = a.encrypt(k(l, k(n, g(n)))); + d.length && (l = k(l, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl2.exception.corrupt("ocb: tag doesn't match"); + return q.concat(h.clamp(m, p)); + }, pmac: function(a, b) { + var c, d = sjcl2.mode.ocb2.S, e = sjcl2.bitArray, f = e.i, g = [0, 0, 0, 0], h = a.encrypt([0, 0, 0, 0]), h = f(h, d(d(h))); + for (c = 0; c + 4 < b.length; c += 4) h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4)))); + c = b.slice(c); + 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0])); + g = f(g, c); + return a.encrypt(f(d(f(h, d(h))), g)); + }, S: function(a) { + return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)]; + } }; + sjcl2.mode.gcm = { name: "gcm", encrypt: function(a, b, c, d, e) { + var f = b.slice(0); + b = sjcl2.bitArray; + d = d || []; + a = sjcl2.mode.gcm.C(true, a, f, d, c, e || 128); + return b.concat(a.data, a.tag); + }, decrypt: function(a, b, c, d, e) { + var f = b.slice(0), g = sjcl2.bitArray, h = g.bitLength(f); + e = e || 128; + d = d || []; + e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []); + a = sjcl2.mode.gcm.C(false, a, f, d, c, e); + if (!g.equal(a.tag, b)) throw new sjcl2.exception.corrupt("gcm: tag doesn't match"); + return a.data; + }, ka: function(a, b) { + var c, d, e, f, g, h = sjcl2.bitArray.i; + e = [ + 0, + 0, + 0, + 0 + ]; + f = b.slice(0); + for (c = 0; 128 > c; c++) { + (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f)); + g = 0 !== (f[3] & 1); + for (d = 3; 0 < d; d--) f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31; + f[0] >>>= 1; + g && (f[0] ^= -520093696); + } + return e; + }, j: function(a, b, c) { + var d, e = c.length; + b = b.slice(0); + for (d = 0; d < e; d += 4) b[0] ^= 4294967295 & c[d], b[1] ^= 4294967295 & c[d + 1], b[2] ^= 4294967295 & c[d + 2], b[3] ^= 4294967295 & c[d + 3], b = sjcl2.mode.gcm.ka(b, a); + return b; + }, C: function(a, b, c, d, e, f) { + var g, h, k, l, n, m, p, r, q = sjcl2.bitArray; + m = c.length; + p = q.bitLength(c); + r = q.bitLength(d); + h = q.bitLength(e); + g = b.encrypt([0, 0, 0, 0]); + 96 === h ? (e = e.slice(0), e = q.concat(e, [1])) : (e = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], e), e = sjcl2.mode.gcm.j(g, e, [0, 0, Math.floor(h / 4294967296), h & 4294967295])); + h = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], d); + n = e.slice(0); + d = h.slice(0); + a || (d = sjcl2.mode.gcm.j(g, h, c)); + for (l = 0; l < m; l += 4) n[3]++, k = b.encrypt(n), c[l] ^= k[0], c[l + 1] ^= k[1], c[l + 2] ^= k[2], c[l + 3] ^= k[3]; + c = q.clamp(c, p); + a && (d = sjcl2.mode.gcm.j(g, h, c)); + a = [Math.floor(r / 4294967296), r & 4294967295, Math.floor(p / 4294967296), p & 4294967295]; + d = sjcl2.mode.gcm.j(g, d, a); + k = b.encrypt(e); + d[0] ^= k[0]; + d[1] ^= k[1]; + d[2] ^= k[2]; + d[3] ^= k[3]; + return { tag: q.bitSlice(d, 0, f), data: c }; + } }; + sjcl2.misc.hmac = function(a, b) { + this.W = b = b || sjcl2.hash.sha256; + var c = [[], []], d, e = b.prototype.blockSize / 32; + this.w = [new b(), new b()]; + a.length > e && (a = b.hash(a)); + for (d = 0; d < e; d++) c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828; + this.w[0].update(c[0]); + this.w[1].update(c[1]); + this.R = new b(this.w[0]); + }; + sjcl2.misc.hmac.prototype.encrypt = sjcl2.misc.hmac.prototype.mac = function(a) { + if (this.aa) throw new sjcl2.exception.invalid("encrypt on already updated hmac called!"); + this.update(a); + return this.digest(a); + }; + sjcl2.misc.hmac.prototype.reset = function() { + this.R = new this.W(this.w[0]); + this.aa = false; + }; + sjcl2.misc.hmac.prototype.update = function(a) { + this.aa = true; + this.R.update(a); + }; + sjcl2.misc.hmac.prototype.digest = function() { + var a = this.R.finalize(), a = new this.W(this.w[1]).update(a).finalize(); + this.reset(); + return a; + }; + sjcl2.misc.pbkdf2 = function(a, b, c, d, e) { + c = c || 1e4; + if (0 > d || 0 > c) throw new sjcl2.exception.invalid("invalid params to pbkdf2"); + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + e = e || sjcl2.misc.hmac; + a = new e(a); + var f, g, h, k, l = [], n = sjcl2.bitArray; + for (k = 1; 32 * l.length < (d || 1); k++) { + e = f = a.encrypt(n.concat(b, [k])); + for (g = 1; g < c; g++) for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h]; + l = l.concat(e); + } + d && (l = n.clamp(l, d)); + return l; + }; + sjcl2.prng = function(a) { + this.c = [new sjcl2.hash.sha256()]; + this.m = [0]; + this.P = 0; + this.H = {}; + this.N = 0; + this.U = {}; + this.Z = this.f = this.o = this.ha = 0; + this.b = [0, 0, 0, 0, 0, 0, 0, 0]; + this.h = [0, 0, 0, 0]; + this.L = void 0; + this.M = a; + this.D = false; + this.K = { progress: {}, seeded: {} }; + this.u = this.ga = 0; + this.I = 1; + this.J = 2; + this.ca = 65536; + this.T = [0, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024]; + this.da = 3e4; + this.ba = 80; + }; + sjcl2.prng.prototype = { + randomWords: function(a, b) { + var c = [], d; + d = this.isReady(b); + var e; + if (d === this.u) throw new sjcl2.exception.notReady("generator isn't seeded"); + if (d & this.J) { + d = !(d & this.I); + e = []; + var f = 0, g; + this.Z = e[0] = (/* @__PURE__ */ new Date()).valueOf() + this.da; + for (g = 0; 16 > g; g++) e.push(4294967296 * Math.random() | 0); + for (g = 0; g < this.c.length && (e = e.concat(this.c[g].finalize()), f += this.m[g], this.m[g] = 0, d || !(this.P & 1 << g)); g++) ; + this.P >= 1 << this.c.length && (this.c.push(new sjcl2.hash.sha256()), this.m.push(0)); + this.f -= f; + f > this.o && (this.o = f); + this.P++; + this.b = sjcl2.hash.sha256.hash(this.b.concat(e)); + this.L = new sjcl2.cipher.aes(this.b); + for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) ; + } + for (d = 0; d < a; d += 4) 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]); + y(this); + return c.slice(0, a); + }, + setDefaultParanoia: function(a, b) { + if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) throw new sjcl2.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); + this.M = a; + }, + addEntropy: function(a, b, c) { + c = c || "user"; + var d, e, f = (/* @__PURE__ */ new Date()).valueOf(), g = this.H[c], h = this.isReady(), k = 0; + d = this.U[c]; + void 0 === d && (d = this.U[c] = this.ha++); + void 0 === g && (g = this.H[c] = 0); + this.H[c] = (this.H[c] + 1) % this.c.length; + switch (typeof a) { + case "number": + void 0 === b && (b = 1); + this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]); + break; + case "object": + c = Object.prototype.toString.call(a); + if ("[object Uint32Array]" === c) { + e = []; + for (c = 0; c < a.length; c++) e.push(a[c]); + a = e; + } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) "number" !== typeof a[c] && (k = 1); + if (!k) { + if (void 0 === b) for (c = b = 0; c < a.length; c++) for (e = a[c]; 0 < e; ) b++, e = e >>> 1; + this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a)); + } + break; + case "string": + void 0 === b && (b = a.length); + this.c[g].update([d, this.N++, 3, b, f, a.length]); + this.c[g].update(a); + break; + default: + k = 1; + } + if (k) throw new sjcl2.exception.bug("random: addEntropy only supports number, array of numbers or string"); + this.m[g] += b; + this.f += b; + h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress())); + }, + isReady: function(a) { + a = this.T[void 0 !== a ? a : this.M]; + return this.o && this.o >= a ? this.m[0] > this.ba && (/* @__PURE__ */ new Date()).valueOf() > this.Z ? this.J | this.I : this.I : this.f >= a ? this.J | this.u : this.u; + }, + getProgress: function(a) { + a = this.T[a ? a : this.M]; + return this.o >= a ? 1 : this.f > a ? 1 : this.f / a; + }, + startCollectors: function() { + if (!this.D) { + this.a = { loadTimeCollector: B(this, this.ma), mouseCollector: B(this, this.oa), keyboardCollector: B(this, this.la), accelerometerCollector: B(this, this.ea), touchCollector: B(this, this.qa) }; + if (window.addEventListener) window.addEventListener( + "load", + this.a.loadTimeCollector, + false + ), window.addEventListener("mousemove", this.a.mouseCollector, false), window.addEventListener("keypress", this.a.keyboardCollector, false), window.addEventListener("devicemotion", this.a.accelerometerCollector, false), window.addEventListener("touchmove", this.a.touchCollector, false); + 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 sjcl2.exception.bug("can't attach event"); + this.D = true; + } + }, + stopCollectors: function() { + this.D && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, false), window.removeEventListener("mousemove", this.a.mouseCollector, false), window.removeEventListener("keypress", this.a.keyboardCollector, false), window.removeEventListener("devicemotion", this.a.accelerometerCollector, false), window.removeEventListener("touchmove", this.a.touchCollector, false)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent( + "onmousemove", + this.a.mouseCollector + ), document.detachEvent("keypress", this.a.keyboardCollector)), this.D = false); + }, + addEventListener: function(a, b) { + this.K[a][this.ga++] = b; + }, + removeEventListener: function(a, b) { + var c, d, e = this.K[a], f = []; + for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d); + for (c = 0; c < f.length; c++) d = f[c], delete e[d]; + }, + la: function() { + C(this, 1); + }, + oa: function(a) { + var b, c; + try { + b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0; + } catch (d) { + c = b = 0; + } + 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); + C(this, 0); + }, + qa: function(a) { + a = a.touches[0] || a.changedTouches[0]; + this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); + C(this, 0); + }, + ma: function() { + C(this, 2); + }, + ea: function(a) { + a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; + if (window.orientation) { + var b = window.orientation; + "number" === typeof b && this.addEntropy(b, 1, "accelerometer"); + } + a && this.addEntropy(a, 2, "accelerometer"); + C(this, 0); + } + }; + function A(a, b) { + var c, d = sjcl2.random.K[a], e = []; + for (c in d) d.hasOwnProperty(c) && e.push(d[c]); + for (c = 0; c < e.length; c++) e[c](b); + } + function C(a, b) { + "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy((/* @__PURE__ */ new Date()).valueOf(), b, "loadtime"); + } + function y(a) { + a.b = z(a).concat(z(a)); + a.L = new sjcl2.cipher.aes(a.b); + } + function z(a) { + for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) ; + return a.L.encrypt(a.h); + } + function B(a, b) { + return function() { + b.apply(a, arguments); + }; + } + sjcl2.random = new sjcl2.prng(6); + a: try { + if (G = "undefined" !== typeof module && module.exports) { + try { + H = __require("crypto"); + } catch (a) { + H = null; + } + G = E = H; + } + if (G && E.randomBytes) D = E.randomBytes(128), D = new Uint32Array(new Uint8Array(D).buffer), sjcl2.random.addEntropy(D, 1024, "crypto['randomBytes']"); + else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { + F = new Uint32Array(32); + if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F); + else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F); + else break a; + sjcl2.random.addEntropy(F, 1024, "crypto['getRandomValues']"); + } + } catch (a) { + "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a)); + } + var D; + var E; + var F; + var G; + var H; + sjcl2.json = { defaults: { v: 1, iter: 1e4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, ja: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json, f = e.g({ iv: sjcl2.random.randomWords(4, 0) }, e.defaults), g; + e.g(f, c); + c = f.adata; + "string" === typeof f.salt && (f.salt = sjcl2.codec.base64.toBits(f.salt)); + "string" === typeof f.iv && (f.iv = sjcl2.codec.base64.toBits(f.iv)); + if (!sjcl2.mode[f.mode] || !sjcl2.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 256 !== f.ks || 2 > f.iv.length || 4 < f.iv.length) throw new sjcl2.exception.invalid("json encrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + "string" === typeof c && (f.adata = c = sjcl2.codec.utf8String.toBits(c)); + g = new sjcl2.cipher[f.cipher](a); + e.g(d, f); + d.key = a; + f.ct = "ccm" === f.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl2.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); + return f; + }, encrypt: function(a, b, c, d) { + var e = sjcl2.json, f = e.ja.apply(e, arguments); + return e.encode(f); + }, ia: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json; + b = e.g(e.g(e.g({}, e.defaults), b), c, true); + var f, g; + f = b.adata; + "string" === typeof b.salt && (b.salt = sjcl2.codec.base64.toBits(b.salt)); + "string" === typeof b.iv && (b.iv = sjcl2.codec.base64.toBits(b.iv)); + if (!sjcl2.mode[b.mode] || !sjcl2.cipher[b.cipher] || "string" === typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 256 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) throw new sjcl2.exception.invalid("json decrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.secretKey && (a = a.unkem(sjcl2.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); + "string" === typeof f && (f = sjcl2.codec.utf8String.toBits(f)); + g = new sjcl2.cipher[b.cipher](a); + f = "ccm" === b.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl2.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); + e.g(d, b); + d.key = a; + return 1 === c.raw ? f : sjcl2.codec.utf8String.fromBits(f); + }, decrypt: function(a, b, c, d) { + var e = sjcl2.json; + return e.ia(a, e.decode(b), c, d); + }, encode: function(a) { + var b, c = "{", d = ""; + for (b in a) if (a.hasOwnProperty(b)) { + if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl2.exception.invalid("json encode: invalid property name"); + c += d + '"' + b + '":'; + d = ","; + switch (typeof a[b]) { + case "number": + case "boolean": + c += a[b]; + break; + case "string": + c += '"' + escape(a[b]) + '"'; + break; + case "object": + c += '"' + sjcl2.codec.base64.fromBits(a[b], 0) + '"'; + break; + default: + throw new sjcl2.exception.bug("json encode: unsupported type"); + } + } + return c + "}"; + }, decode: function(a) { + a = a.replace(/\s/g, ""); + if (!a.match(/^\{.*\}$/)) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + a = a.replace(/^\{|\}$/g, "").split(/,/); + var b = {}, c, d; + for (c = 0; c < a.length; c++) { + if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl2.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]); + } + return b; + }, g: function(a, b, c) { + void 0 === a && (a = {}); + if (void 0 === b) return a; + for (var d in b) if (b.hasOwnProperty(d)) { + if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl2.exception.invalid("required parameter overridden"); + a[d] = b[d]; + } + return a; + }, sa: function(a, b) { + var c = {}, d; + for (d in a) a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); + return c; + }, ra: function(a, b) { + var c = {}, d; + for (d = 0; d < b.length; d++) void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); + return c; + } }; + sjcl2.encrypt = sjcl2.json.encrypt; + sjcl2.decrypt = sjcl2.json.decrypt; + sjcl2.misc.pa = {}; + sjcl2.misc.cachedPbkdf2 = function(a, b) { + var c = sjcl2.misc.pa, d; + b = b || {}; + d = b.iter || 1e3; + c = c[a] = c[a] || {}; + d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl2.random.randomWords(2, 0) }; + c = void 0 === b.salt ? d.firstSalt : b.salt; + d[c] = d[c] || sjcl2.misc.pbkdf2(a, c, b.iter); + return { key: d[c].slice(0), salt: c.slice(0) }; + }; + "undefined" !== typeof module && module.exports && (module.exports = sjcl2); + "function" === typeof define && define([], function() { + return sjcl2; + }); + } +}); + +// src/api/lufi.ts +var lufi_exports = {}; +__export(lufi_exports, { + addFilesToArchive: () => addFilesToArchive, + cancel: () => cancel, + compress: () => compress, + decompress: () => decompress, + download: () => download, + events: () => events, + getFileIndexInQueue: () => getFileIndexInQueue, + infos: () => infos, + pause: () => pause, + remove: () => remove, + resume: () => resume, + upload: () => upload +}); +var import_events2 = __toESM(require_events()); + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume2(n, v); + }); + }; + } + function resume2(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume2("next", value); + } + function reject(value) { + resume2("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume2(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var okAsync = (value) => new ResultAsync(Promise.resolve(new Ok(value))); +var errAsync = (err3) => new ResultAsync(Promise.resolve(new Err(err3))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result3) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result3.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result3.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result3.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err3) { + return new Err(err3); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err3) { + return err3(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/entities/lufi-file.ts +var LufiFile = class _LufiFile { + constructor(serverUrl, properties) { + __publicField(this, "actionToken", ""); + __publicField(this, "chunksReady", 0); + __publicField(this, "createdAt", 0); + __publicField(this, "delay", 0); + __publicField(this, "delAtFirstView", false); + __publicField(this, "keys", { client: "", server: "" }); + __publicField(this, "name", ""); + __publicField(this, "password", ""); + __publicField(this, "queueIndex", 0); + __publicField(this, "serverUrl"); + __publicField(this, "size", 0); + __publicField(this, "uploadStatus", 3 /* INITIALIZED */); + __publicField(this, "totalChunks", 0); + __publicField(this, "type", ""); + __publicField(this, "zipped", false); + this.serverUrl = serverUrl; + Object.assign(this, properties); + } + downloadUrl() { + const serverUrl = new URL(this.serverUrl); + return new URL( + `${serverUrl.origin + serverUrl.pathname}r/${this.keys.server}#${this.keys.client}` + ); + } + removeUrl() { + const serverUrl = new URL(this.serverUrl); + return new URL( + `${serverUrl.origin + serverUrl.pathname}d/${this.keys.server}/${this.actionToken}` + ); + } + static fromDownloadUrl(downloadUrl, password = "") { + const pathinfos = downloadUrl.pathname.split("r/"); + const keys = { + client: downloadUrl.hash.slice(1).split("&")[0], + server: pathinfos[1] + }; + return new _LufiFile(downloadUrl.origin + pathinfos[0], { + keys, + password + }); + } + static fromRemoveUrl(removeUrl, password = "") { + const pathInfos = removeUrl.pathname.split("d/"); + const splittedPath = pathInfos[1].split("/"); + const keys = { client: "", server: splittedPath[0] }; + return new _LufiFile(removeUrl.origin + pathInfos[0], { + keys, + password, + actionToken: splittedPath[1] + }); + } +}; + +// src/entities/lufi-job.ts +var import_events = __toESM(require_events()); + +// src/error/base-error.ts +var BaseError = class extends Error { + constructor(message, options = {}) { + const { cause, context } = options; + super(message, { cause }); + __publicField(this, "context"); + this.name = this.constructor.name; + this.context = context; + } +}; + +// src/error/connection-error.ts +var ConnectionError = class extends BaseError { + constructor() { + super(...arguments); + __publicField(this, "message", "Unable to connect. Is the computer able to access the url?"); + } +}; + +// src/error/server-error.ts +var ServerError = class extends BaseError { + constructor() { + super(...arguments); + __publicField(this, "message", "The server returned an error"); + } +}; + +// src/utils.ts +var ensureError = (value) => { + if (value instanceof Error) return value; + let stringified = "[Unable to stringify the thrown value]"; + try { + stringified = JSON.stringify(value); + } catch (_error) { + } + const error = new Error(stringified); + return error; +}; +var fetchServerConfig = (instanceUrl) => { + const originMatches = instanceUrl.href.match( + /(.*?)\/?(?:[dr]{1}\/|login\/?|files\/?)/ + ); + const urlOrigin = originMatches && originMatches[1] ? originMatches[1] : instanceUrl.origin; + return ResultAsync.fromPromise( + fetch(urlOrigin + "/about/config"), + (error) => new ConnectionError(void 0, { + cause: ensureError(error) + }) + ).andThen((response) => { + if (response.ok) { + return ResultAsync.fromPromise( + response.json(), + (error) => ensureError(error) + ); + } else { + return errAsync( + new ServerError(void 0, { context: response.statusText }) + ); + } + }); +}; +var isDenoRuntime = () => typeof Deno !== "undefined"; +var isSecureContext = () => { + return isDenoRuntime() || typeof window !== "undefined" && (window.isSecureContext || window.location.protocol === "https:"); +}; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); +var hashPassword = async (password) => password ? Array.from( + new Uint8Array( + await crypto.subtle.digest( + "SHA-512", + new TextEncoder().encode(password) + ) + ) +).map((b) => b.toString(16).padStart(2, "0")).join("") : ""; + +// src/entities/lufi-job.ts +var LufiJob = class { + constructor(lufiFile) { + __publicField(this, "events", new import_events.default()); + __publicField(this, "lufiFile"); + __publicField(this, "status", 2 /* ONGOING */); + __publicField(this, "tmpFile"); + __publicField(this, "tmpChunks", []); + __publicField(this, "worker"); + __publicField(this, "isTerminated", false); + /** + * Tells the worker the job is complete + */ + __publicField(this, "complete", () => { + this.status = 0 /* COMPLETE */; + this.events.emit("JOB_TERMINATED" /* JOB_TERMINATED */); + }); + __publicField(this, "hasFailed", () => this.status === 1 /* FAILED */); + __publicField(this, "onError", (callback) => { + this.worker.onerror = (event) => { + callback(event); + }; + return this; + }); + __publicField(this, "onMessage", (callback) => { + this.worker.onmessage = (e) => { + if (callback) { + callback(e); + } + const event = e.data.event; + if (event) { + if (event === "FILE_UPDATED" /* FILE_UPDATED */) { + Object.assign(this.lufiFile, e.data.lufiFile); + } else { + this.dispatchEvent(event, e.data.error); + } + } + }; + return this; + }); + __publicField(this, "onMessageError", (callback) => { + this.worker.onmessageerror = (event) => { + callback(event); + }; + return this; + }); + __publicField(this, "onProgress", (callback) => { + this.events.on("CHUNK_UPLOADED" /* CHUNK_UPLOADED */, () => { + callback(); + }); + this.events.on("CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, () => { + callback(); + }); + return this; + }); + __publicField(this, "requestMessage", (msg, transferable = []) => { + this.worker.postMessage(msg, transferable); + return this; + }); + __publicField(this, "terminate", () => { + this.worker.terminate(); + return this; + }); + __publicField(this, "waitForCompletion", () => { + if (this.isTerminated) { + if (this.status === 0 /* COMPLETE */) { + return okAsync(this); + } else { + return errAsync(ensureError("Job has failed")); + } + } else { + return ResultAsync.fromPromise( + new Promise((resolve, reject) => { + this.events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + reject(error); + }); + this.events.once("JOB_TERMINATED" /* JOB_TERMINATED */, () => { + if (this.status === 0 /* COMPLETE */) { + resolve(this); + } + }); + }), + (error) => ensureError(error) + ); + } + }); + __publicField(this, "dispatchEvent", (event, error) => { + this.events.emit(event, error); + }); + this.worker = new Worker(workerUrl("main"), { type: "module" }); + this.lufiFile = lufiFile; + this.events.once("JOB_TERMINATED" /* JOB_TERMINATED */, () => { + this.isTerminated = true; + this.terminate(); + }); + this.events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + this.status = 1 /* FAILED */; + this.lufiFile.uploadStatus = 2 /* FAILED */; + this.events.emit("JOB_TERMINATED" /* JOB_TERMINATED */, error); + }); + this.onError((event) => console.error(event.error)); + } +}; + +// src/enum/crypto-algorithm.ts +var CryptoAlgorithm = /* @__PURE__ */ ((CryptoAlgorithm2) => { + CryptoAlgorithm2[CryptoAlgorithm2["Sjcl"] = 0] = "Sjcl"; + CryptoAlgorithm2[CryptoAlgorithm2["WebCrypto"] = 1] = "WebCrypto"; + return CryptoAlgorithm2; +})(CryptoAlgorithm || {}); + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/encoding.js +var Encoding = class { + /** + * + * @param charset Charset to use for base64 encoding. This must be 64-characters long. + * @param noPadding If true, encoded strings won't include padding. + */ + constructor(charset, noPadding) { + if (!charset || charset.length != 64) { + throw Error("Charset must contain 64 characters"); + } + this._charset = charset; + this._noPadding = !!noPadding; + this._valid = new RegExp("^[" + this._charset.replace("-", "\\-") + "]+={0,2}$"); + } + /** + * Encode an ArrayBuffer to base64 in a string. + * @param ab Data to encode to base64 + * @returns Base64-encoded string + */ + Encode(ab) { + const len = ab.byteLength; + if (!len) { + return ""; + } + const view = new Uint8Array(ab); + let res = ""; + for (let i = 0; i < len; i += 3) { + res += this._charset[view[i] >> 2] + this._charset[(view[i] & 3) << 4 | view[i + 1] >> 4] + this._charset[(view[i + 1] & 15) << 2 | view[i + 2] >> 6] + this._charset[view[i + 2] & 63]; + } + if (len % 3 == 2) { + res = res.substring(0, res.length - 1); + if (!this._noPadding) { + res += "="; + } + } else if (len % 3 == 1) { + res = res.substring(0, res.length - 2); + if (!this._noPadding) { + res += "=="; + } + } + return res; + } + /** + * Decode a string from base64. Padding is always optional. + * @param str Base64-encoded string + * @returns Data decoded from the base64 string + */ + Decode(str) { + str = (str || "").replace(/[\s]/g, ""); + if (!str) { + return new ArrayBuffer(0); + } + if (!this._valid.test(str)) { + throw Error("Invalid base64 input sequence"); + } + let viewLen = Math.floor(str.length * 0.75); + if (str[str.length - 2] == "=") { + viewLen -= 2; + } else if (str[str.length - 1] == "=") { + viewLen--; + } + const view = new Uint8Array(viewLen); + let enc1, enc2, enc3, enc4, i = 0, j = 0; + while (i < str.length * 0.75) { + enc1 = this._charset.indexOf(str.charAt(j++)); + enc2 = this._charset.indexOf(str.charAt(j++)); + enc3 = this._charset.indexOf(str.charAt(j++)); + enc4 = this._charset.indexOf(str.charAt(j++)); + view[i++] = enc1 << 2 | enc2 >> 4; + view[i++] = (enc2 & 15) << 4 | enc3 >> 2; + view[i++] = (enc3 & 3) << 6 | enc4; + } + return view.buffer; + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/standard.js +var obj = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/url.js +var obj2 = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", true); +function Encode(ab) { + return obj2.Encode(ab); +} + +// src/api/crypto/sjcl.ts +var import_sjcl = __toESM(require_sjcl()); + +// src/error/crypto/crypto-error.ts +var CryptoError = class extends BaseError { +}; + +// src/error/crypto/decryption-error.ts +var DecryptionError = class extends CryptoError { + constructor() { + super(...arguments); + __publicField(this, "message", "Unable to decrypt the provided data"); + } +}; + +// src/api/crypto/sjcl.ts +var generateKey = () => { + try { + return okAsync(import_sjcl.default.codec.base64.fromBits(import_sjcl.default.random.randomWords(8, 10))); + } catch (e) { + return errAsync( + new CryptoError("Unable to generate a random key", { + cause: ensureError(e) + }) + ); + } +}; + +// src/api/crypto/web.ts +var generateKey2 = () => { + return ResultAsync.fromPromise( + new Promise( + (resolve) => crypto.subtle.generateKey( + { + name: "AES-GCM", + length: 256 + }, + true, + ["encrypt", "decrypt"] + ).then( + (generatedKey) => crypto.subtle.exportKey("raw", generatedKey).then((key) => resolve(Encode(key))).catch( + (error) => errAsync( + new DecryptionError(void 0, { cause: ensureError(error) }) + ) + ) + ).catch( + (error) => errAsync( + new DecryptionError(void 0, { cause: ensureError(error) }) + ) + ) + ), + (error) => new CryptoError("Unable to base64 encode the url", { + cause: ensureError(error) + }) + ); +}; + +// src/api/crypto.ts +var generateKey3 = (algo = 1 /* WebCrypto */) => { + return algo === 0 /* Sjcl */ ? generateKey() : generateKey2(); +}; + +// src/error/file/file-error.ts +var FileError = class extends BaseError { + constructor() { + super(...arguments); + __publicField(this, "message", "An error occured while dealing with a file"); + } +}; + +// src/error/file/file-operation-error.ts +var FileOperationError = class extends FileError { + constructor() { + super(...arguments); + __publicField(this, "message", "An error occured while operating on a file"); + } +}; + +// src/error/file/file-slicing-error.ts +var FileSlicingError = class extends FileOperationError { + constructor() { + super(...arguments); + __publicField(this, "message", "An error occured while slicing a file"); + } +}; + +// node_modules/.deno/fflate@0.8.2/node_modules/fflate/esm/browser.js +var ch2 = {}; +var wk = function(c, id, msg, transfer, cb) { + var w = new Worker(ch2[id] || (ch2[id] = URL.createObjectURL(new Blob([ + c + ';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})' + ], { type: "text/javascript" })))); + w.onmessage = function(e) { + var d = e.data, ed = d.$e$; + if (ed) { + var err3 = new Error(ed[0]); + err3["code"] = ed[1]; + err3.stack = ed[2]; + cb(err3, null); + } else + cb(null, d); + }; + w.postMessage(msg, transfer); + return w; +}; +var u8 = Uint8Array; +var u16 = Uint16Array; +var i32 = Int32Array; +var fleb = new u8([ + 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, + /* unused */ + 0, + 0, + /* impossible */ + 0 +]); +var fdeb = new u8([ + 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, + /* unused */ + 0, + 0 +]); +var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); +var freb = function(eb, start) { + var b = new u16(31); + for (var i = 0; i < 31; ++i) { + b[i] = start += 1 << eb[i - 1]; + } + var r = new i32(b[30]); + for (var i = 1; i < 30; ++i) { + for (var j = b[i]; j < b[i + 1]; ++j) { + r[j] = j - b[i] << 5 | i; + } + } + return { b, r }; +}; +var _a = freb(fleb, 2); +var fl = _a.b; +var revfl = _a.r; +fl[28] = 258, revfl[258] = 28; +var _b = freb(fdeb, 0); +var fd = _b.b; +var revfd = _b.r; +var rev = new u16(32768); +for (i = 0; i < 32768; ++i) { + x = (i & 43690) >> 1 | (i & 21845) << 1; + x = (x & 52428) >> 2 | (x & 13107) << 2; + x = (x & 61680) >> 4 | (x & 3855) << 4; + rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1; +} +var x; +var i; +var hMap = function(cd, mb, r) { + var s = cd.length; + var i = 0; + var l = new u16(mb); + for (; i < s; ++i) { + if (cd[i]) + ++l[cd[i] - 1]; + } + var le = new u16(mb); + for (i = 1; i < mb; ++i) { + le[i] = le[i - 1] + l[i - 1] << 1; + } + var co; + if (r) { + co = new u16(1 << mb); + var rvb = 15 - mb; + for (i = 0; i < s; ++i) { + if (cd[i]) { + var sv = i << 4 | cd[i]; + var r_1 = mb - cd[i]; + var v = le[cd[i] - 1]++ << r_1; + for (var m = v | (1 << r_1) - 1; v <= m; ++v) { + co[rev[v] >> rvb] = sv; + } + } + } + } else { + co = new u16(s); + for (i = 0; i < s; ++i) { + if (cd[i]) { + co[i] = rev[le[cd[i] - 1]++] >> 15 - cd[i]; + } + } + } + return co; +}; +var flt = new u8(288); +for (i = 0; i < 144; ++i) + flt[i] = 8; +var i; +for (i = 144; i < 256; ++i) + flt[i] = 9; +var i; +for (i = 256; i < 280; ++i) + flt[i] = 7; +var i; +for (i = 280; i < 288; ++i) + flt[i] = 8; +var i; +var fdt = new u8(32); +for (i = 0; i < 32; ++i) + fdt[i] = 5; +var i; +var flm = /* @__PURE__ */ hMap(flt, 9, 0); +var flrm = /* @__PURE__ */ hMap(flt, 9, 1); +var fdm = /* @__PURE__ */ hMap(fdt, 5, 0); +var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1); +var max = function(a) { + var m = a[0]; + for (var i = 1; i < a.length; ++i) { + if (a[i] > m) + m = a[i]; + } + return m; +}; +var bits = function(d, p, m) { + var o = p / 8 | 0; + return (d[o] | d[o + 1] << 8) >> (p & 7) & m; +}; +var bits16 = function(d, p) { + var o = p / 8 | 0; + return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7); +}; +var shft = function(p) { + return (p + 7) / 8 | 0; +}; +var slc = function(v, s, e) { + if (s == null || s < 0) + s = 0; + if (e == null || e > v.length) + e = v.length; + return new u8(v.subarray(s, e)); +}; +var ec = [ + "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" + // determined by unknown compression method +]; +var err2 = function(ind, msg, nt) { + var e = new Error(msg || ec[ind]); + e.code = ind; + if (Error.captureStackTrace) + Error.captureStackTrace(e, err2); + if (!nt) + throw e; + return e; +}; +var inflt = function(dat, st, buf, dict) { + var sl = dat.length, dl = dict ? dict.length : 0; + if (!sl || st.f && !st.l) + return buf || new u8(0); + var noBuf = !buf; + var resize = noBuf || st.i != 2; + var noSt = st.i; + if (noBuf) + buf = new u8(sl * 3); + var cbuf = function(l2) { + var bl = buf.length; + if (l2 > bl) { + var nbuf = new u8(Math.max(bl * 2, l2)); + nbuf.set(buf); + buf = nbuf; + } + }; + var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n; + var tbts = sl * 8; + do { + if (!lm) { + final = bits(dat, pos, 1); + var type = bits(dat, pos + 1, 3); + pos += 3; + if (!type) { + var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l; + if (t > sl) { + if (noSt) + err2(0); + break; + } + if (resize) + cbuf(bt + l); + buf.set(dat.subarray(s, t), bt); + st.b = bt += l, st.p = pos = t * 8, st.f = final; + continue; + } else if (type == 1) + lm = flrm, dm = fdrm, lbt = 9, dbt = 5; + else if (type == 2) { + var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4; + var tl = hLit + bits(dat, pos + 5, 31) + 1; + pos += 14; + var ldt = new u8(tl); + var clt = new u8(19); + for (var i = 0; i < hcLen; ++i) { + clt[clim[i]] = bits(dat, pos + i * 3, 7); + } + pos += hcLen * 3; + var clb = max(clt), clbmsk = (1 << clb) - 1; + var clm = hMap(clt, clb, 1); + for (var i = 0; i < tl; ) { + var r = clm[bits(dat, pos, clbmsk)]; + pos += r & 15; + var s = r >> 4; + if (s < 16) { + ldt[i++] = s; + } else { + var c = 0, n = 0; + if (s == 16) + n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1]; + else if (s == 17) + n = 3 + bits(dat, pos, 7), pos += 3; + else if (s == 18) + n = 11 + bits(dat, pos, 127), pos += 7; + while (n--) + ldt[i++] = c; + } + } + var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit); + lbt = max(lt); + dbt = max(dt); + lm = hMap(lt, lbt, 1); + dm = hMap(dt, dbt, 1); + } else + err2(1); + if (pos > tbts) { + if (noSt) + err2(0); + break; + } + } + if (resize) + cbuf(bt + 131072); + var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1; + var lpos = pos; + for (; ; lpos = pos) { + var c = lm[bits16(dat, pos) & lms], sym = c >> 4; + pos += c & 15; + if (pos > tbts) { + if (noSt) + err2(0); + break; + } + if (!c) + err2(2); + if (sym < 256) + buf[bt++] = sym; + else if (sym == 256) { + lpos = pos, lm = null; + break; + } else { + var add = sym - 254; + if (sym > 264) { + var i = sym - 257, b = fleb[i]; + add = bits(dat, pos, (1 << b) - 1) + fl[i]; + pos += b; + } + var d = dm[bits16(dat, pos) & dms], dsym = d >> 4; + if (!d) + err2(3); + pos += d & 15; + var dt = fd[dsym]; + if (dsym > 3) { + var b = fdeb[dsym]; + dt += bits16(dat, pos) & (1 << b) - 1, pos += b; + } + if (pos > tbts) { + if (noSt) + err2(0); + break; + } + if (resize) + cbuf(bt + 131072); + var end = bt + add; + if (bt < dt) { + var shift = dl - dt, dend = Math.min(dt, end); + if (shift + bt < 0) + err2(3); + for (; bt < dend; ++bt) + buf[bt] = dict[shift + bt]; + } + for (; bt < end; ++bt) + buf[bt] = buf[bt - dt]; + } + } + st.l = lm, st.p = lpos, st.b = bt, st.f = final; + if (lm) + final = 1, st.m = lbt, st.d = dm, st.n = dbt; + } while (!final); + return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt); +}; +var wbits = function(d, p, v) { + v <<= p & 7; + var o = p / 8 | 0; + d[o] |= v; + d[o + 1] |= v >> 8; +}; +var wbits16 = function(d, p, v) { + v <<= p & 7; + var o = p / 8 | 0; + d[o] |= v; + d[o + 1] |= v >> 8; + d[o + 2] |= v >> 16; +}; +var hTree = function(d, mb) { + var t = []; + for (var i = 0; i < d.length; ++i) { + if (d[i]) + t.push({ s: i, f: d[i] }); + } + var s = t.length; + var t2 = t.slice(); + if (!s) + return { t: et, l: 0 }; + if (s == 1) { + var v = new u8(t[0].s + 1); + v[t[0].s] = 1; + return { t: v, l: 1 }; + } + t.sort(function(a, b) { + return a.f - b.f; + }); + t.push({ s: -1, f: 25001 }); + var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2; + t[0] = { s: -1, f: l.f + r.f, l, r }; + while (i1 != s - 1) { + l = t[t[i0].f < t[i2].f ? i0++ : i2++]; + r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++]; + t[i1++] = { s: -1, f: l.f + r.f, l, r }; + } + var maxSym = t2[0].s; + for (var i = 1; i < s; ++i) { + if (t2[i].s > maxSym) + maxSym = t2[i].s; + } + var tr = new u16(maxSym + 1); + var mbt = ln(t[i1 - 1], tr, 0); + if (mbt > mb) { + var i = 0, dt = 0; + var lft = mbt - mb, cst = 1 << lft; + t2.sort(function(a, b) { + return tr[b.s] - tr[a.s] || a.f - b.f; + }); + for (; i < s; ++i) { + var i2_1 = t2[i].s; + if (tr[i2_1] > mb) { + dt += cst - (1 << mbt - tr[i2_1]); + tr[i2_1] = mb; + } else + break; + } + dt >>= lft; + while (dt > 0) { + var i2_2 = t2[i].s; + if (tr[i2_2] < mb) + dt -= 1 << mb - tr[i2_2]++ - 1; + else + ++i; + } + for (; i >= 0 && dt; --i) { + var i2_3 = t2[i].s; + if (tr[i2_3] == mb) { + --tr[i2_3]; + ++dt; + } + } + mbt = mb; + } + return { t: new u8(tr), l: mbt }; +}; +var ln = function(n, l, d) { + return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d; +}; +var lc = function(c) { + var s = c.length; + while (s && !c[--s]) + ; + var cl = new u16(++s); + var cli = 0, cln = c[0], cls = 1; + var w = function(v) { + cl[cli++] = v; + }; + for (var i = 1; i <= s; ++i) { + if (c[i] == cln && i != s) + ++cls; + else { + if (!cln && cls > 2) { + for (; cls > 138; cls -= 138) + w(32754); + if (cls > 2) { + w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305); + cls = 0; + } + } else if (cls > 3) { + w(cln), --cls; + for (; cls > 6; cls -= 6) + w(8304); + if (cls > 2) + w(cls - 3 << 5 | 8208), cls = 0; + } + while (cls--) + w(cln); + cls = 1; + cln = c[i]; + } + } + return { c: cl.subarray(0, cli), n: s }; +}; +var clen = function(cf, cl) { + var l = 0; + for (var i = 0; i < cl.length; ++i) + l += cf[i] * cl[i]; + return l; +}; +var wfblk = function(out, pos, dat) { + var s = dat.length; + var o = shft(pos + 2); + out[o] = s & 255; + out[o + 1] = s >> 8; + out[o + 2] = out[o] ^ 255; + out[o + 3] = out[o + 1] ^ 255; + for (var i = 0; i < s; ++i) + out[o + i + 4] = dat[i]; + return (o + 4 + s) * 8; +}; +var wblk = function(dat, out, final, syms, lf, df, eb, li, bs, bl, p) { + wbits(out, p++, final); + ++lf[256]; + var _a2 = hTree(lf, 15), dlt = _a2.t, mlb = _a2.l; + var _b2 = hTree(df, 15), ddt = _b2.t, mdb = _b2.l; + var _c = lc(dlt), lclt = _c.c, nlc = _c.n; + var _d = lc(ddt), lcdt = _d.c, ndc = _d.n; + var lcfreq = new u16(19); + for (var i = 0; i < lclt.length; ++i) + ++lcfreq[lclt[i] & 31]; + for (var i = 0; i < lcdt.length; ++i) + ++lcfreq[lcdt[i] & 31]; + var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l; + var nlcc = 19; + for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc) + ; + var flen = bl + 5 << 3; + var ftlen = clen(lf, flt) + clen(df, fdt) + eb; + var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18]; + if (bs >= 0 && flen <= ftlen && flen <= dtlen) + return wfblk(out, p, dat.subarray(bs, bs + bl)); + var lm, ll, dm, dl; + wbits(out, p, 1 + (dtlen < ftlen)), p += 2; + if (dtlen < ftlen) { + lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt; + var llm = hMap(lct, mlcb, 0); + wbits(out, p, nlc - 257); + wbits(out, p + 5, ndc - 1); + wbits(out, p + 10, nlcc - 4); + p += 14; + for (var i = 0; i < nlcc; ++i) + wbits(out, p + 3 * i, lct[clim[i]]); + p += 3 * nlcc; + var lcts = [lclt, lcdt]; + for (var it = 0; it < 2; ++it) { + var clct = lcts[it]; + for (var i = 0; i < clct.length; ++i) { + var len = clct[i] & 31; + wbits(out, p, llm[len]), p += lct[len]; + if (len > 15) + wbits(out, p, clct[i] >> 5 & 127), p += clct[i] >> 12; + } + } + } else { + lm = flm, ll = flt, dm = fdm, dl = fdt; + } + for (var i = 0; i < li; ++i) { + var sym = syms[i]; + if (sym > 255) { + var len = sym >> 18 & 31; + wbits16(out, p, lm[len + 257]), p += ll[len + 257]; + if (len > 7) + wbits(out, p, sym >> 23 & 31), p += fleb[len]; + var dst = sym & 31; + wbits16(out, p, dm[dst]), p += dl[dst]; + if (dst > 3) + wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst]; + } else { + wbits16(out, p, lm[sym]), p += ll[sym]; + } + } + wbits16(out, p, lm[256]); + return p + ll[256]; +}; +var deo = /* @__PURE__ */ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]); +var et = /* @__PURE__ */ new u8(0); +var dflt = function(dat, lvl, plvl, pre, post, st) { + var s = st.z || dat.length; + var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7e3)) + post); + var w = o.subarray(pre, o.length - post); + var lst = st.l; + var pos = (st.r || 0) & 7; + if (lvl) { + if (pos) + w[0] = st.r >> 3; + var opt = deo[lvl - 1]; + var n = opt >> 13, c = opt & 8191; + var msk_1 = (1 << plvl) - 1; + var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1); + var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1; + var hsh = function(i2) { + return (dat[i2] ^ dat[i2 + 1] << bs1_1 ^ dat[i2 + 2] << bs2_1) & msk_1; + }; + var syms = new i32(25e3); + var lf = new u16(288), df = new u16(32); + var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0; + for (; i + 2 < s; ++i) { + var hv = hsh(i); + var imod = i & 32767, pimod = head[hv]; + prev[imod] = pimod; + head[hv] = imod; + if (wi <= i) { + var rem = s - i; + if ((lc_1 > 7e3 || li > 24576) && (rem > 423 || !lst)) { + pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos); + li = lc_1 = eb = 0, bs = i; + for (var j = 0; j < 286; ++j) + lf[j] = 0; + for (var j = 0; j < 30; ++j) + df[j] = 0; + } + var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767; + if (rem > 2 && hv == hsh(i - dif)) { + var maxn = Math.min(n, rem) - 1; + var maxd = Math.min(32767, i); + var ml = Math.min(258, rem); + while (dif <= maxd && --ch_1 && imod != pimod) { + if (dat[i + l] == dat[i + l - dif]) { + var nl = 0; + for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl) + ; + if (nl > l) { + l = nl, d = dif; + if (nl > maxn) + break; + var mmd = Math.min(dif, nl - 2); + var md = 0; + for (var j = 0; j < mmd; ++j) { + var ti = i - dif + j & 32767; + var pti = prev[ti]; + var cd = ti - pti & 32767; + if (cd > md) + md = cd, pimod = ti; + } + } + } + imod = pimod, pimod = prev[imod]; + dif += imod - pimod & 32767; + } + } + if (d) { + syms[li++] = 268435456 | revfl[l] << 18 | revfd[d]; + var lin = revfl[l] & 31, din = revfd[d] & 31; + eb += fleb[lin] + fdeb[din]; + ++lf[257 + lin]; + ++df[din]; + wi = i + l; + ++lc_1; + } else { + syms[li++] = dat[i]; + ++lf[dat[i]]; + } + } + } + for (i = Math.max(i, wi); i < s; ++i) { + syms[li++] = dat[i]; + ++lf[dat[i]]; + } + pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos); + if (!lst) { + st.r = pos & 7 | w[pos / 8 | 0] << 3; + pos -= 7; + st.h = head, st.p = prev, st.i = i, st.w = wi; + } + } else { + for (var i = st.w || 0; i < s + lst; i += 65535) { + var e = i + 65535; + if (e >= s) { + w[pos / 8 | 0] = lst; + e = s; + } + pos = wfblk(w, pos + 1, dat.subarray(i, e)); + } + st.i = s; + } + return slc(o, 0, pre + shft(pos) + post); +}; +var crct = /* @__PURE__ */ function() { + var t = new Int32Array(256); + for (var i = 0; i < 256; ++i) { + var c = i, k = 9; + while (--k) + c = (c & 1 && -306674912) ^ c >>> 1; + t[i] = c; + } + return t; +}(); +var crc = function() { + var c = -1; + return { + p: function(d) { + var cr = c; + for (var i = 0; i < d.length; ++i) + cr = crct[cr & 255 ^ d[i]] ^ cr >>> 8; + c = cr; + }, + d: function() { + return ~c; + } + }; +}; +var dopt = function(dat, opt, pre, post, st) { + if (!st) { + st = { l: 1 }; + if (opt.dictionary) { + var dict = opt.dictionary.subarray(-32768); + var newDat = new u8(dict.length + dat.length); + newDat.set(dict); + newDat.set(dat, dict.length); + dat = newDat; + st.w = dict.length; + } + } + return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st); +}; +var mrg = function(a, b) { + var o = {}; + for (var k in a) + o[k] = a[k]; + for (var k in b) + o[k] = b[k]; + return o; +}; +var wcln = function(fn, fnStr, td2) { + var dt = fn(); + var st = fn.toString(); + var ks = st.slice(st.indexOf("[") + 1, st.lastIndexOf("]")).replace(/\s+/g, "").split(","); + for (var i = 0; i < dt.length; ++i) { + var v = dt[i], k = ks[i]; + if (typeof v == "function") { + fnStr += ";" + k + "="; + var st_1 = v.toString(); + if (v.prototype) { + if (st_1.indexOf("[native code]") != -1) { + var spInd = st_1.indexOf(" ", 8) + 1; + fnStr += st_1.slice(spInd, st_1.indexOf("(", spInd)); + } else { + fnStr += st_1; + for (var t in v.prototype) + fnStr += ";" + k + ".prototype." + t + "=" + v.prototype[t].toString(); + } + } else + fnStr += st_1; + } else + td2[k] = v; + } + return fnStr; +}; +var ch = []; +var cbfs = function(v) { + var tl = []; + for (var k in v) { + if (v[k].buffer) { + tl.push((v[k] = new v[k].constructor(v[k])).buffer); + } + } + return tl; +}; +var wrkr = function(fns, init, id, cb) { + if (!ch[id]) { + var fnStr = "", td_1 = {}, m = fns.length - 1; + for (var i = 0; i < m; ++i) + fnStr = wcln(fns[i], fnStr, td_1); + ch[id] = { c: wcln(fns[m], fnStr, td_1), e: td_1 }; + } + var td2 = mrg({}, ch[id].e); + return wk(ch[id].c + ";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=" + init.toString() + "}", id, td2, cbfs(td2), cb); +}; +var bInflt = function() { + return [u8, u16, i32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err2, inflt, inflateSync, pbf, gopt]; +}; +var bDflt = function() { + return [u8, u16, i32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf]; +}; +var pbf = function(msg) { + return postMessage(msg, [msg.buffer]); +}; +var gopt = function(o) { + return o && { + out: o.size && new u8(o.size), + dictionary: o.dictionary + }; +}; +var cbify = function(dat, opts, fns, init, id, cb) { + var w = wrkr(fns, init, id, function(err3, dat2) { + w.terminate(); + cb(err3, dat2); + }); + w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []); + return function() { + w.terminate(); + }; +}; +var b2 = function(d, b) { + return d[b] | d[b + 1] << 8; +}; +var b4 = function(d, b) { + return (d[b] | d[b + 1] << 8 | d[b + 2] << 16 | d[b + 3] << 24) >>> 0; +}; +var b8 = function(d, b) { + return b4(d, b) + b4(d, b + 4) * 4294967296; +}; +var wbytes = function(d, b, v) { + for (; v; ++b) + d[b] = v, v >>>= 8; +}; +function deflate(data, opts, cb) { + if (!cb) + cb = opts, opts = {}; + if (typeof cb != "function") + err2(7); + return cbify(data, opts, [ + bDflt + ], function(ev) { + return pbf(deflateSync(ev.data[0], ev.data[1])); + }, 0, cb); +} +function deflateSync(data, opts) { + return dopt(data, opts || {}, 0, 0); +} +function inflate(data, opts, cb) { + if (!cb) + cb = opts, opts = {}; + if (typeof cb != "function") + err2(7); + return cbify(data, opts, [ + bInflt + ], function(ev) { + return pbf(inflateSync(ev.data[0], gopt(ev.data[1]))); + }, 1, cb); +} +function inflateSync(data, opts) { + return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary); +} +var fltn = function(d, p, t, o) { + for (var k in d) { + var val = d[k], n = p + k, op = o; + if (Array.isArray(val)) + op = mrg(o, val[1]), val = val[0]; + if (val instanceof u8) + t[n] = [val, op]; + else { + t[n += "/"] = [new u8(0), op]; + fltn(val, n, t, o); + } + } +}; +var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder(); +var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder(); +var tds = 0; +try { + td.decode(et, { stream: true }); + tds = 1; +} catch (e) { +} +var dutf8 = function(d) { + for (var r = "", i = 0; ; ) { + var c = d[i++]; + var eb = (c > 127) + (c > 223) + (c > 239); + if (i + eb > d.length) + return { s: r, r: slc(d, i - 1) }; + if (!eb) + r += String.fromCharCode(c); + else if (eb == 3) { + c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | d[i++] & 63) - 65536, r += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023); + } else if (eb & 1) + r += String.fromCharCode((c & 31) << 6 | d[i++] & 63); + else + r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | d[i++] & 63); + } +}; +function strToU8(str, latin1) { + if (latin1) { + var ar_1 = new u8(str.length); + for (var i = 0; i < str.length; ++i) + ar_1[i] = str.charCodeAt(i); + return ar_1; + } + if (te) + return te.encode(str); + var l = str.length; + var ar = new u8(str.length + (str.length >> 1)); + var ai = 0; + var w = function(v) { + ar[ai++] = v; + }; + for (var i = 0; i < l; ++i) { + if (ai + 5 > ar.length) { + var n = new u8(ai + 8 + (l - i << 1)); + n.set(ar); + ar = n; + } + var c = str.charCodeAt(i); + if (c < 128 || latin1) + w(c); + else if (c < 2048) + w(192 | c >> 6), w(128 | c & 63); + else if (c > 55295 && c < 57344) + c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63); + else + w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63); + } + return slc(ar, 0, ai); +} +function strFromU8(dat, latin1) { + if (latin1) { + var r = ""; + for (var i = 0; i < dat.length; i += 16384) + r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384)); + return r; + } else if (td) { + return td.decode(dat); + } else { + var _a2 = dutf8(dat), s = _a2.s, r = _a2.r; + if (r.length) + err2(8); + return s; + } +} +var slzh = function(d, b) { + return b + 30 + b2(d, b + 26) + b2(d, b + 28); +}; +var zh = function(d, b, z) { + var fnl = b2(d, b + 28), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl, bs = b4(d, b + 20); + var _a2 = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a2[0], su = _a2[1], off = _a2[2]; + return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off]; +}; +var z64e = function(d, b) { + for (; b2(d, b) != 1; b += 4 + b2(d, b + 2)) + ; + return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)]; +}; +var exfl = function(ex) { + var le = 0; + if (ex) { + for (var k in ex) { + var l = ex[k].length; + if (l > 65535) + err2(9); + le += l + 4; + } + } + return le; +}; +var wzh = function(d, b, f, fn, u, c, ce, co) { + var fl2 = fn.length, ex = f.extra, col = co && co.length; + var exl = exfl(ex); + wbytes(d, b, ce != null ? 33639248 : 67324752), b += 4; + if (ce != null) + d[b++] = 20, d[b++] = f.os; + d[b] = 20, b += 2; + d[b++] = f.flag << 1 | (c < 0 && 8), d[b++] = u && 8; + d[b++] = f.compression & 255, d[b++] = f.compression >> 8; + var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980; + if (y < 0 || y > 119) + err2(10); + wbytes(d, b, y << 25 | dt.getMonth() + 1 << 21 | dt.getDate() << 16 | dt.getHours() << 11 | dt.getMinutes() << 5 | dt.getSeconds() >> 1), b += 4; + if (c != -1) { + wbytes(d, b, f.crc); + wbytes(d, b + 4, c < 0 ? -c - 2 : c); + wbytes(d, b + 8, f.size); + } + wbytes(d, b + 12, fl2); + wbytes(d, b + 14, exl), b += 16; + if (ce != null) { + wbytes(d, b, col); + wbytes(d, b + 6, f.attrs); + wbytes(d, b + 10, ce), b += 14; + } + d.set(fn, b); + b += fl2; + if (exl) { + for (var k in ex) { + var exf = ex[k], l = exf.length; + wbytes(d, b, +k); + wbytes(d, b + 2, l); + d.set(exf, b + 4), b += 4 + l; + } + } + if (col) + d.set(co, b), b += col; + return b; +}; +var wzf = function(o, b, c, d, e) { + wbytes(o, b, 101010256); + wbytes(o, b + 8, c); + wbytes(o, b + 10, c); + wbytes(o, b + 12, d); + wbytes(o, b + 16, e); +}; +function zip(data, opts, cb) { + if (!cb) + cb = opts, opts = {}; + if (typeof cb != "function") + err2(7); + var r = {}; + fltn(data, "", r, opts); + var k = Object.keys(r); + var lft = k.length, o = 0, tot = 0; + var slft = lft, files2 = new Array(lft); + var term = []; + var tAll = function() { + for (var i2 = 0; i2 < term.length; ++i2) + term[i2](); + }; + var cbd = function(a, b) { + mt(function() { + cb(a, b); + }); + }; + mt(function() { + cbd = cb; + }); + var cbf = function() { + var out = new u8(tot + 22), oe = o, cdl = tot - o; + tot = 0; + for (var i2 = 0; i2 < slft; ++i2) { + var f = files2[i2]; + try { + var l = f.c.length; + wzh(out, tot, f, f.f, f.u, l); + var badd = 30 + f.f.length + exfl(f.extra); + var loc = tot + badd; + out.set(f.c, loc); + wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l; + } catch (e) { + return cbd(e, null); + } + } + wzf(out, o, files2.length, cdl, oe); + cbd(null, out); + }; + if (!lft) + cbf(); + var _loop_1 = function(i2) { + var fn = k[i2]; + var _a2 = r[fn], file = _a2[0], p = _a2[1]; + var c = crc(), size = file.length; + c.p(file); + var f = strToU8(fn), s = f.length; + var com = p.comment, m = com && strToU8(com), ms = m && m.length; + var exl = exfl(p.extra); + var compression = p.level == 0 ? 0 : 8; + var cbl = function(e, d) { + if (e) { + tAll(); + cbd(e, null); + } else { + var l = d.length; + files2[i2] = mrg(p, { + size, + crc: c.d(), + c: d, + f, + m, + u: s != fn.length || m && com.length != ms, + compression + }); + o += 30 + s + exl + l; + tot += 76 + 2 * (s + exl) + (ms || 0) + l; + if (!--lft) + cbf(); + } + }; + if (s > 65535) + cbl(err2(11, 0, 1), null); + if (!compression) + cbl(null, file); + else if (size < 16e4) { + try { + cbl(null, deflateSync(file, p)); + } catch (e) { + cbl(e, null); + } + } else + term.push(deflate(file, p, cbl)); + }; + for (var i = 0; i < slft; ++i) { + _loop_1(i); + } + return tAll; +} +var mt = typeof queueMicrotask == "function" ? queueMicrotask : typeof setTimeout == "function" ? setTimeout : function(fn) { + fn(); +}; +function unzip(data, opts, cb) { + if (!cb) + cb = opts, opts = {}; + if (typeof cb != "function") + err2(7); + var term = []; + var tAll = function() { + for (var i2 = 0; i2 < term.length; ++i2) + term[i2](); + }; + var files2 = {}; + var cbd = function(a, b) { + mt(function() { + cb(a, b); + }); + }; + mt(function() { + cbd = cb; + }); + var e = data.length - 22; + for (; b4(data, e) != 101010256; --e) { + if (!e || data.length - e > 65558) { + cbd(err2(13, 0, 1), null); + return tAll; + } + } + ; + var lft = b2(data, e + 8); + if (lft) { + var c = lft; + var o = b4(data, e + 16); + var z = o == 4294967295 || c == 65535; + if (z) { + var ze = b4(data, e - 12); + z = b4(data, ze) == 101075792; + if (z) { + c = lft = b4(data, ze + 32); + o = b4(data, ze + 48); + } + } + var fltr = opts && opts.filter; + var _loop_3 = function(i2) { + var _a2 = zh(data, o, z), c_1 = _a2[0], sc = _a2[1], su = _a2[2], fn = _a2[3], no = _a2[4], off = _a2[5], b = slzh(data, off); + o = no; + var cbl = function(e2, d) { + if (e2) { + tAll(); + cbd(e2, null); + } else { + if (d) + files2[fn] = d; + if (!--lft) + cbd(null, files2); + } + }; + if (!fltr || fltr({ + name: fn, + size: sc, + originalSize: su, + compression: c_1 + })) { + if (!c_1) + cbl(null, slc(data, b, b + sc)); + else if (c_1 == 8) { + var infl = data.subarray(b, b + sc); + if (su < 524288 || sc > 0.8 * su) { + try { + cbl(null, inflateSync(infl, { out: new u8(su) })); + } catch (e2) { + cbl(e2, null); + } + } else + term.push(inflate(infl, { size: su }, cbl)); + } else + cbl(err2(14, "unknown compression type " + c_1, 1), null); + } else + cbl(null, null); + }; + for (var i = 0; i < c; ++i) { + _loop_3(i); + } + } else + cbd(null, {}); + return tAll; +} + +// src/api/lufi.ts +var CHUNK_LENGTH = 15e5; +var files = {}; +var events = new import_events2.default(); +var cancel = (uploadJob) => { + uploadJob.terminate(); + const job = new LufiJob(uploadJob.lufiFile); + return ResultAsync.fromPromise( + new Promise((resolve, reject) => { + job.onMessage((event) => { + if (event.data.event === "UPLOAD_CANCELLED" /* UPLOAD_CANCELLED */) { + files[job.lufiFile.keys.client].uploadStatus = 0 /* CANCELED */; + resolve(job); + } + if (event.data.event === "OPERATION_FAILED" /* OPERATION_FAILED */) { + reject(event.data.error); + } + }).requestMessage({ + action: 2 /* CANCEL */, + args: { + lufiFile: job.lufiFile + } + }); + }), + (error) => ensureError(error) + ); +}; +var addFilesToArchive = (files2, archiveEntries = {}) => { + const asyncLoop = async (files3) => { + var _a2; + for (const file of files3) { + const nameWithExtension = ((_a2 = file.name.split("/")) == null ? void 0 : _a2.pop()) || file.name; + const nameWithoutExtension = nameWithExtension.split(".").shift(); + const extension = nameWithExtension.split(".").pop(); + let name = nameWithExtension; + if (archiveEntries[name] !== void 0) { + let i = 1; + do { + name = `${nameWithoutExtension}_(${i}).${extension}`; + i++; + } while (archiveEntries[name] !== void 0); + } + events.emit("ARCHIVE_ADDED_FILE" /* ARCHIVE_ADDED_FILE */, { name, size: file.size }); + archiveEntries[name] = await file.bytes(); + } + }; + return ResultAsync.fromPromise( + asyncLoop(files2), + (error) => ensureError(error) + ).andThen(() => okAsync(archiveEntries)); +}; +var compress = (archiveEntries, archiveName) => { + const promiseZip = () => new Promise((resolve, reject) => { + zip(archiveEntries, (error, data) => { + if (error) reject(error); + resolve(data); + }); + }); + return ResultAsync.fromPromise( + promiseZip(), + (error) => ensureError(error) + ).andThen((bytes) => { + return okAsync( + new File( + [new Blob([bytes])], + archiveName, + { + type: "application/zip" + } + ) + ); + }).orElse((error) => errAsync(error)); +}; +var decompress = (zipFile) => { + const unzipPromise = async () => { + const fileBytes = await zipFile.bytes(); + return new Promise((resolve, reject) => { + unzip(fileBytes, (error, files2) => { + if (error) reject(error); + resolve(files2); + }); + }); + }; + return ResultAsync.fromPromise(unzipPromise(), (error) => ensureError(error)).andThen((files2) => { + const unzippedFiles = []; + for (const path in files2) { + unzippedFiles.push(new File([new Blob([files2[path]])], path)); + } + return okAsync(unzippedFiles); + }); +}; +var download = (downloadUrl, password) => { + let lufiResult; + if (password) { + lufiResult = fetchServerConfig(downloadUrl).andThen((config) => { + if (config.version.tag > "0.07.0") { + return ResultAsync.fromPromise( + hashPassword(password).then((hashedPassword) => { + return LufiFile.fromDownloadUrl(downloadUrl, hashedPassword); + }), + (error) => ensureError(error) + ); + } else { + return okAsync(LufiFile.fromDownloadUrl(downloadUrl, password)); + } + }); + } else { + lufiResult = okAsync(LufiFile.fromDownloadUrl(downloadUrl)); + } + return lufiResult.andThen((lufiFile) => { + const job = new LufiJob(lufiFile); + return ResultAsync.fromPromise( + new Promise( + (resolve, reject) => job.onMessage((event) => { + handleSocketResults(resolve, reject, job, event); + if (event.data.event === "CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */) { + job.tmpChunks[event.data.chunk.index] = new Blob([ + event.data.chunk.buffer + ]); + } + if (event.data.event === "DOWNLOAD_COMPLETE" /* DOWNLOAD_COMPLETE */) { + job.tmpFile = new Blob(job.tmpChunks, { type: lufiFile.type }); + job.tmpChunks = []; + job.complete(); + } + }).requestMessage({ + action: 3 /* DOWNLOAD */, + args: { + lufiFile + } + }) + ), + (error) => ensureError(error) + ); + }); +}; +var infos = (downloadUrl, password) => { + let lufiResult; + if (password) { + lufiResult = fetchServerConfig(downloadUrl).andThen((config) => { + if (config.version.tag > "0.07.0") { + return ResultAsync.fromPromise( + hashPassword(password).then((hashedPassword) => { + return LufiFile.fromDownloadUrl(downloadUrl, hashedPassword); + }), + (error) => ensureError(error) + ); + } else { + return okAsync(LufiFile.fromDownloadUrl(downloadUrl, password)); + } + }); + } else { + lufiResult = okAsync(LufiFile.fromDownloadUrl(downloadUrl)); + } + return lufiResult.andThen((lufiFile) => okAsync(new LufiJob(lufiFile))).andThen( + (job) => ResultAsync.fromPromise( + new Promise((resolve, reject) => { + job.onMessage((event) => { + if (event.data.event === "INFOS_RETRIEVED" /* INFOS_RETRIEVED */) { + job.complete(); + resolve(job); + } + if (event.data.event === "OPERATION_FAILED" /* OPERATION_FAILED */) { + reject(event.data.error); + } + }).requestMessage({ + action: 4 /* INFOS */, + args: { lufiFile: job.lufiFile } + }); + }), + (error) => ensureError(error) + ) + ); +}; +var pause = (job) => { + job.status = 3 /* PAUSED */; + return okAsync( + job.requestMessage({ + action: 5 /* PAUSE */, + args: { lufiFile: job.lufiFile } + }) + ); +}; +var remove = (removeUrl, password) => { + const lufiFile = LufiFile.fromRemoveUrl(removeUrl, password); + const job = new LufiJob(lufiFile); + return ResultAsync.fromPromise( + new Promise((resolve, reject) => { + job.onMessage((event) => { + if (event.data.event === "FILE_REMOVED" /* FILE_REMOVED */) { + job.complete(); + resolve(job); + } + if (event.data.event === "OPERATION_FAILED" /* OPERATION_FAILED */) { + reject(event.data.error); + } + }).requestMessage({ action: 7 /* REMOVE */, args: { lufiFile } }); + }), + (error) => ensureError(error) + ); +}; +var resume = (job) => { + job.status = 2 /* ONGOING */; + return okAsync( + job.requestMessage({ + action: 8 /* RESUME */, + args: { lufiFile: job.lufiFile } + }) + ); +}; +var slice = (file, clientKey, chunkLength = CHUNK_LENGTH) => { + const totalChunks = Math.ceil(file.size / chunkLength); + files[clientKey].totalChunks = totalChunks; + if (totalChunks > 0) { + const chunks = []; + for (let i = 0; i < totalChunks; i++) { + const start = i * chunkLength; + const end = Math.min(start + chunkLength, file.size); + chunks.push(file.slice(start, end, file.type)); + } + return ok(chunks); + } else { + return err(new FileSlicingError()); + } +}; +var upload = (serverUrl, filesToUpload, delay = 0, delAtFirstView = false, zipped = false, zipName = "documents.zip", password = "", algo = 1 /* WebCrypto */) => { + const operations = []; + if (!zipped) { + filesToUpload.forEach((file) => { + operations.push(startUpload( + serverUrl, + file, + delay, + delAtFirstView, + zipped, + password, + algo + )); + }); + } else { + if (filesToUpload.length === 1 && filesToUpload[0].type === "application/zip") { + operations.push( + startUpload( + serverUrl, + filesToUpload[0], + delay, + delAtFirstView, + zipped, + password, + algo + ) + ); + } else { + operations.push( + addFilesToArchive(filesToUpload).andThen( + (archiveEntries) => compress(archiveEntries, zipName).andThen((file) => { + events.emit("ARCHIVE_CREATED" /* ARCHIVE_CREATED */, file); + return startUpload( + serverUrl, + file, + delay, + delAtFirstView, + zipped, + password, + algo + ); + }) + ) + ); + } + } + return ResultAsync.combine(operations); +}; +var startUpload = (serverUrl, file, delay, delAtFirstView, zipped, password, algo) => generateKey3( + algo +).andThen( + (clientKey) => { + return ResultAsync.fromPromise( + hashPassword(password).then((hashedPassword) => { + files[clientKey] = new LufiFile(serverUrl.toString(), { + delay, + delAtFirstView, + zipped, + password: hashedPassword, + name: file.name.split("/").pop(), + // Remove path from filename + size: file.size, + type: file.type, + keys: { client: clientKey, server: "" } + }); + return clientKey; + }), + (error) => ensureError(error) + ); + } +).andThen((clientKey) => { + const job = new LufiJob(files[clientKey]); + return slice(file, clientKey).asyncAndThen((chunks) => { + files[clientKey].uploadStatus = 4 /* QUEUED */; + const resultPromise = new Promise((resolve, reject) => { + job.onMessage((event) => { + handleSocketResults(resolve, reject, job, event); + switch (event.data.event) { + case "UPLOAD_COMPLETE" /* UPLOAD_COMPLETE */: + { + job.complete(); + job.lufiFile.uploadStatus = 1 /* COMPLETE */; + } + break; + } + }); + }); + const sendChunks = async (chunks2) => { + for (const [index, chunk] of chunks2.entries()) { + const buffer = await chunk.arrayBuffer(); + job.requestMessage( + { + action: 9 /* UPLOAD */, + args: { + chunk: { buffer, index }, + lufiFile: files[clientKey], + algo + } + }, + [buffer] + ); + } + }; + return ResultAsync.fromPromise( + sendChunks(chunks), + (error) => ensureError(error) + ).andThen( + () => ResultAsync.fromPromise(resultPromise, (error) => ensureError(error)) + ); + }).orElse((error) => errAsync(error)); +}); +var handleSocketResults = (resolve, reject, job, event) => { + if (event.data.event === "SOCKET_OPENED" /* SOCKET_OPENED */) { + resolve(job); + } + if (event.data.event === "OPERATION_FAILED" /* OPERATION_FAILED */) { + reject(event.data.error); + } +}; +var getFilesQueued = () => Object.values(files).filter( + (file) => file.uploadStatus === 4 /* QUEUED */ +); +var getFileIndexInQueue = (clientKey) => Object.keys(getFilesQueued()).indexOf(clientKey); +export { + CryptoAlgorithm, + ResultAsync, + err, + errAsync, + isSecureContext, + lufi_exports as lufi, + ok, + okAsync +}; diff --git a/themes/default/public/js/sidenav.js b/themes/default/public/js/sidenav.js index 0f5fe1f..5d6b2fa 100644 --- a/themes/default/public/js/sidenav.js +++ b/themes/default/public/js/sidenav.js @@ -1,3 +1,3 @@ -$(document).ready(function() { - $(".button-collapse").sideNav(); +$(document).ready(function () { + $(".button-collapse").sideNav(); }); diff --git a/themes/default/public/js/worker/cancel.js b/themes/default/public/js/worker/cancel.js index 160ec2a..ed00eb9 100644 --- a/themes/default/public/js/worker/cancel.js +++ b/themes/default/public/js/worker/cancel.js @@ -1 +1,2111 @@ -var Xe=Object.create;var se=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var qe=(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 ce=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var He=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ge(t))!Ke.call(e,o)&&o!==r&&se(e,o,{get:()=>t[o],enumerable:!(n=ze(t,o))||n.enumerable});return e};var ae=(e,t,r)=>(r=e!=null?Xe($e(e)):{},He(t||!e||!e.__esModule?se(r,"default",{value:e,enumerable:!0}):r,e));var we=ce((Mt,Q)=>{"use strict";var M=typeof Reflect=="object"?Reflect:null,fe=M&&typeof M.apply=="function"?M.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},q;M&&typeof M.ownKeys=="function"?q=M.ownKeys:Object.getOwnPropertySymbols?q=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:q=function(t){return Object.getOwnPropertyNames(t)};function Ye(e){console&&console.warn&&console.warn(e)}var he=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}Q.exports=p;Q.exports.once=et;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var ue=10;function H(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(p,"defaultMaxListeners",{enumerable:!0,get:function(){return ue},set:function(e){if(typeof e!="number"||e<0||he(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ue=e}});p.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};p.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||he(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 le(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return le(this)};p.prototype.emit=function(t){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[t];if(f===void 0)return!1;if(typeof f=="function")fe(f,this,r);else for(var u=f.length,l=ge(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(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,Ye(a)}return e}p.prototype.addListener=function(t,r){return de(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return de(this,t,r,!0)};function Ve(){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 pe(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Ve.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return H(r),this.on(t,pe(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return H(r),this.prependListener(t,pe(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(H(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,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():Ze(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};p.prototype.off=p.prototype.removeListener;p.prototype.removeAllListeners=function(t){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[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function me(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Qe(o):ge(o,o.length)}p.prototype.listeners=function(t){return me(this,t,!0)};p.prototype.rawListeners=function(t){return me(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ye.call(e,t)};p.prototype.listenerCount=ye;function ye(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}p.prototype.eventNames=function(){return this._eventsCount>0?q(this._events):[]};function ge(e,t){for(var r=new Array(t),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(e){this.s[0][0][0]||this.O();var t,r,n,o,i=this.s[0][4],s=this.s[1];t=e.length;var a=1;if(t!==4&&t!==6&&t!==8)throw new c.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?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(e){return Se(this,e,0)},decrypt:function(e){return Se(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],o,i,s,a=[],f=[],u,l,h,d;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]]],d=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Se(e,t,r){if(t.length!==4)throw new c.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var a,f,u,l=n.length/4-2,h,d=4,y=[0,0,0,0];a=e.s[r],e=a[0];var g=a[1],P=a[2],$=a[3],K=a[4];for(h=0;h>>24]^g[i>>16&255]^P[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^P[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^P[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^P[i>>8&255]^$[s&255]^n[d+3],d+=4,o=a,i=f,s=u;for(h=0;4>h;h++)y[r?3&-h:h]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[t&255]^n[d++],a=o,o=i,i=s,s=t,t=a;return y}c.bitArray={bitSlice:function(e,t,r){return e=c.bitArray.$(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:c.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(c.bitArray.bitLength(e)!==c.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=c.bitArray.getPartial(o),n.push(c.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};c.codec.utf8String={fromBits:function(e){var t="",r=c.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>s)>>>o),sl){if(!t)try{return c.codec.base32hex.toBits(e)}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=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=c.codec.base64.B,s=0,a;for(t&&(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(e){return c.codec.base64.fromBits(e,1,1)},toBits:function(e){return c.codec.base64.toBits(e,1)}};c.hash.sha256=function(e){this.b[0]||this.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):this.reset()};c.hash.sha256.hash=function(e){return new c.hash.sha256().update(e).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=c.codec.utf8String.toBits(e));var t,r=this.A=c.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+c.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function re(e,t){var r,n,o,i=e.F,s=e.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],d=i[5],y=i[6],g=i[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],o=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+t[r&15]+t[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(d^y))+s[r],g=y,y=d,d=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]+d|0,i[6]=i[6]+y|0,i[7]=i[7]+g|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(e){c.mode.ccm.G.push(e)},unListenProgress:function(e){e=c.mode.ccm.G.indexOf(e),-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)),t=c.mode.ccm.V(e,t,r,n,o,i),s=c.mode.ccm.C(e,s,r,t,o,i),a.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(t),a=i.clamp(t,u-o),f=i.bitSlice(t,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&u>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),a=c.mode.ccm.C(e,a,r,f,o,t),e=c.mode.ccm.V(e,a.data,r,n,o,t),!i.equal(a.tag,e))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(e,t,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=a.bitLength(t)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,t),t=0;to||16l&&(c.mode.ccm.fa(s/f),l+=h),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:a.clamp(t,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(e,t,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(e.encrypt(r));var h,d=[];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),e.encrypt(i(n(i(a,n(a))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,o){var i=t.slice(0);return t=c.bitArray,n=n||[],e=c.mode.gcm.C(!0,e,i,n,r,o||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,o){var i=t.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(t=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(t=i,i=[]),e=c.mode.gcm.C(!1,e,i,n,r,o),!s.equal(e.tag,t))throw new c.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=(e[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(e,t,r){var n,o=r.length;for(t=t.slice(0),n=0;no&&(e=t.hash(e)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),o=o||c.misc.hmac,e=new o(e);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=e.encrypt(l.concat(t,[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,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,i,e.length]),this.c[s].update(e);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=t,this.f+=t,a===this.u&&(this.isReady()!==this.u&&Ce("seeded",Math.max(this.o,this.f)),Ce("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:X(this,this.ma),mouseCollector:X(this,this.oa),keyboardCollector:X(this,this.la),accelerometerCollector:X(this,this.ea),touchCollector:X(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(e,t){this.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,o=this.K[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function X(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(V=typeof j<"u"&&j.exports){try{Z=qe("crypto")}catch{Z=null}V=Y=Z}if(V&&Y.randomBytes)z=Y.randomBytes(128),z=new Uint32Array(new Uint8Array(z).buffer),c.random.addEntropy(z,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;c.random.addEntropy(G,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 z,Y,G,V,Z;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var 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 e=="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=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{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function T(e,t,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(e,[])).next())})}function Ee(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 C(e){return this instanceof C?(this.v=e,this):new C(e)}function nt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(d){n[d]&&(o[d]=function(y){return new Promise(function(g,P){i.push([d,y,g,P])>1||a(d,y)})})}function a(d,y){try{f(n[d](y))}catch(g){h(i[0][3],g)}}function f(d){d.value instanceof C?Promise.resolve(d.value.v).then(u,l):h(i[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function h(d,y){d(y),i.shift(),i.length&&a(i[0][0],i[0][1])}}function ot(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:C(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function it(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 Ee=="function"?Ee(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(a,f){s=e[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 v=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new L(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new L(o)).catch(o=>new O(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(T(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new O(r?r(o):o)}}))}static combine(t){return st(t)}static combineWithAllErrors(t){return ct(t)}map(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new O(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);let n=yield t(r.value);return n.isErr()?new O(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new O(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new O(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new L(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 nt(this,arguments,function*(){return yield C(yield C(yield*ot(it(yield C(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},x=e=>new v(Promise.resolve(new L(e))),E=e=>new v(Promise.resolve(new O(e))),Nt=v.fromPromise,Ut=v.fromSafePromise,jt=v.fromThrowable,Le=e=>{let t=S([]);for(let r of e)if(r.isErr()){t=k(r.error);break}else t.map(n=>n.push(r.value));return t},st=e=>v.fromSafePromise(Promise.all(e)).andThen(Le),Oe=e=>{let t=S([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=k([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},ct=e=>v.fromSafePromise(Promise.all(e)).andThen(Oe),ee;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return S(a)}catch(a){return k(i?i(a):a)}}}e.fromThrowable=t;function r(o){return Le(o)}e.combine=r;function n(o){return Oe(o)}e.combineWithAllErrors=n})(ee||(ee={}));var S=e=>new L(e);function k(e){return new O(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return S(t(this.value))}mapErr(t){return S(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 S(this.value)}orElse(t){return S(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return v.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 Ae("Called `_unsafeUnwrapErr` on an Ok",this,t)}},O=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return k(this.error)}mapErr(t){return k(t(this.error))}andThrough(t){return k(this.error)}andTee(t){return k(this.error)}andThen(t){return k(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return E(this.error)}asyncAndThrough(t){return E(this.error)}asyncMap(t){return E(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield k(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ae("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Bt=ee.fromThrowable;var D=class extends Error{context;constructor(t,r={}){let{cause:n,context:o}=r;super(t,{cause:n}),this.name=this.constructor.name,this.context=o}};var R=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 at=()=>typeof Deno<"u",I=e=>at()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var m=new ke.default,w,xe=!1;self.onmessage=e=>{ut(e),xe||(xe=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var N=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var ut=(e,t)=>{let{action:r}=e.data;switch(r){case 0:w=new Worker(I("cancel"),{type:"module"}),w.postMessage(e.data);break;case 1:w=new Worker(I("download"),{type:"module"}),w.postMessage(e.data);break;case 2:w=new Worker(I("infos"),{type:"module"}),w.postMessage(e.data);break;case 4:w=w||new Worker(I("remove"),{type:"module"}),w.postMessage(e.data);break;case 5:{w=w||new Worker(I("upload"),{type:"module"}),w.postMessage(e.data);break}default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},De=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var b=class extends D{};var W=class extends b{message="An error occured while trying to connect to WebSocket"};var U=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),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(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),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 ht=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function J(e){return ht.Decode(e)}var lt=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function te(e){return lt.Decode(e)}var Te=ae(Pe());var _=class extends D{};var B=class extends _{message="Unable to decrypt the provided data"};var Ie=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return x(J(Te.default.decrypt(e,r)))}catch(r){return E(new B(void 0,{cause:R(r)}))}};var Ne=(e,t)=>mt(e).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,J(t.data)),n=>new B(void 0,{cause:R(n)})));var mt=e=>v.fromPromise(crypto.subtle.importKey("raw",te(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:R(t)}));var Ue=(e,t)=>t.algo===void 0||t.algo===0?Ie(e,t):Ne(e,t);var A={},je=5,vt=e=>(m.emit("UPLOAD_CANCELLED",e.success),x(void 0)),wt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(_t(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),Ue(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(N(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):N(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Ot(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),x(void 0))):x(void 0)})}else{let s=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new b(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Et=(e,t)=>{if(e.success)return e.j===0&&(N(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),N(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(N(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),x(void 0);{let r=new b(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},At=(e,t)=>{let r=Dt(e.data),n;if(r)if(!r.action&&r.msg){let o=new b(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Et(r,t):n=vt(r);else n=wt(e.data,t);return n},Lt=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,oe=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN,Be=e=>ie(kt(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var Ot=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ie(bt(e),e,JSON.stringify(t))};var ie=(e,t,r)=>oe(e)?(A[e].onmessage=n=>At(n,t),A[e].send(r),x(void 0)):We(e).andThen(()=>ie(e,t,r)),We=(e,t=0)=>(!oe(e)&&!Lt(e)&&(A[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{m.emit("SOCKET_OPENED")},A[e].onclose=()=>{},A[e].onerror=()=>++t<=je?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${je}`),We(e,t)):(m.emit("SOCKET_ONERROR"),E(new W(`Unable to connect to WebSocket ${e}.`)))),xt(e).andThen(()=>x(e)).orElse(r=>E(r))),xt=e=>v.fromPromise(new Promise((t,r)=>{oe(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new W)}))}),t=>R(t));var Je=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,r},bt=e=>Je(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),kt=e=>Je(new URL(e.serverUrl),"upload").toString(),Dt=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},_t=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Fe=!1;self.onmessage=e=>{Fe||(De(),Fe=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),Ct(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Ct=e=>Be(e.args.lufiFile); +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __defNormalProp = (obj3, key, value) => key in obj3 ? __defProp(obj3, key, { enumerable: true, configurable: true, writable: true, value }) : obj3[key] = value; +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); +var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __publicField = (obj3, key, value) => __defNormalProp(obj3, typeof key !== "symbol" ? key + "" : key, value); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter2() { + EventEmitter2.init.call(this); + } + module.exports = EventEmitter2; + module.exports.once = once; + EventEmitter2.EventEmitter = EventEmitter2; + EventEmitter2.prototype._events = void 0; + EventEmitter2.prototype._eventsCount = 0; + EventEmitter2.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter2, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter2.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter2.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter2.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter2.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter2.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events2 = this._events; + if (events2 !== void 0) + doError = doError && events2.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err2 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err2.context = er; + throw err2; + } + var handler = events2[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events2; + var existing; + checkListener(listener); + events2 = target._events; + if (events2 === void 0) { + events2 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events2.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events2 = target._events; + } + existing = events2[type]; + } + if (existing === void 0) { + existing = events2[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events2[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter2.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter2.prototype.on = EventEmitter2.prototype.addListener; + EventEmitter2.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter2.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.removeListener = function removeListener(type, listener) { + var list, events2, position, i, originalListener; + checkListener(listener); + events2 = this._events; + if (events2 === void 0) + return this; + list = events2[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events2[type]; + if (events2.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events2[type] = list[0]; + if (events2.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; + EventEmitter2.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events2, i; + events2 = this._events; + if (events2 === void 0) + return this; + if (events2.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events2[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events2[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events2); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events2[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events2 = target._events; + if (events2 === void 0) + return []; + var evlistener = events2[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter2.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter2.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter2.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter2.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events2 = this._events; + if (events2 !== void 0) { + var evlistener = events2[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter2.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err2) { + emitter.removeListener(name, resolver); + reject(err2); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js +var require_sjcl = __commonJS({ + "node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js"(exports, module) { + "use strict"; + var sjcl2 = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function(a) { + this.toString = function() { + return "CORRUPT: " + this.message; + }; + this.message = a; + }, invalid: function(a) { + this.toString = function() { + return "INVALID: " + this.message; + }; + this.message = a; + }, bug: function(a) { + this.toString = function() { + return "BUG: " + this.message; + }; + this.message = a; + }, notReady: function(a) { + this.toString = function() { + return "NOT READY: " + this.message; + }; + this.message = a; + } } }; + sjcl2.cipher.aes = function(a) { + this.s[0][0][0] || this.O(); + var b, c, d, e, f = this.s[0][4], g = this.s[1]; + b = a.length; + var h = 1; + if (4 !== b && 6 !== b && 8 !== b) throw new sjcl2.exception.invalid("invalid aes key size"); + this.b = [d = a.slice(0), e = []]; + for (a = b; a < 4 * b + 28; a++) { + c = d[a - 1]; + if (0 === a % b || 8 === b && 4 === a % b) c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7)); + d[a] = d[a - b] ^ c; + } + for (b = 0; a; b++, a--) c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & 255]]; + }; + sjcl2.cipher.aes.prototype = { encrypt: function(a) { + return t(this, a, 0); + }, decrypt: function(a) { + return t(this, a, 1); + }, s: [[[], [], [], [], []], [[], [], [], [], []]], O: function() { + var a = this.s[0], b = this.s[1], c = a[4], d = b[4], e, f, g, h = [], k = [], l, n, m, p; + for (e = 0; 256 > e; e++) k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e; + for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, n = h[e = h[l = h[f]]], p = 16843009 * n ^ 65537 * e ^ 257 * l ^ 16843008 * f, n = 257 * h[m] ^ 16843008 * m, e = 0; 4 > e; e++) a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8; + for (e = 0; 5 > e; e++) a[e] = a[e].slice(0), b[e] = b[e].slice(0); + } }; + function t(a, b, c) { + if (4 !== b.length) throw new sjcl2.exception.invalid("invalid aes block size"); + var d = a.b[c], e = b[0] ^ d[0], f = b[c ? 3 : 1] ^ d[1], g = b[2] ^ d[2]; + b = b[c ? 1 : 3] ^ d[3]; + var h, k, l, n = d.length / 4 - 2, m, p = 4, r = [0, 0, 0, 0]; + h = a.s[c]; + a = h[0]; + var q = h[1], v = h[2], w = h[3], x = h[4]; + for (m = 0; m < n; m++) h = a[e >>> 24] ^ q[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ q[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], l = a[g >>> 24] ^ q[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ q[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = l; + for (m = 0; 4 > m; m++) r[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h; + return r; + } + sjcl2.bitArray = { bitSlice: function(a, b, c) { + a = sjcl2.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1); + return void 0 === c ? a : sjcl2.bitArray.clamp(a, c - b); + }, extract: function(a, b, c) { + var d = Math.floor(-b - c & 31); + return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1; + }, concat: function(a, b) { + if (0 === a.length || 0 === b.length) return a.concat(b); + var c = a[a.length - 1], d = sjcl2.bitArray.getPartial(c); + return 32 === d ? a.concat(b) : sjcl2.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1)); + }, bitLength: function(a) { + var b = a.length; + return 0 === b ? 0 : 32 * (b - 1) + sjcl2.bitArray.getPartial(a[b - 1]); + }, clamp: function(a, b) { + if (32 * a.length < b) return a; + a = a.slice(0, Math.ceil(b / 32)); + var c = a.length; + b = b & 31; + 0 < c && b && (a[c - 1] = sjcl2.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)); + return a; + }, partial: function(a, b, c) { + return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 1099511627776 * a; + }, getPartial: function(a) { + return Math.round(a / 1099511627776) || 32; + }, equal: function(a, b) { + if (sjcl2.bitArray.bitLength(a) !== sjcl2.bitArray.bitLength(b)) return false; + var c = 0, d; + for (d = 0; d < a.length; d++) c |= a[d] ^ b[d]; + return 0 === c; + }, $: function(a, b, c, d) { + var e; + e = 0; + for (void 0 === d && (d = []); 32 <= b; b -= 32) d.push(c), c = 0; + if (0 === b) return d.concat(a); + for (e = 0; e < a.length; e++) d.push(c | a[e] >>> b), c = a[e] << 32 - b; + e = a.length ? a[a.length - 1] : 0; + a = sjcl2.bitArray.getPartial(e); + d.push(sjcl2.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1)); + return d; + }, i: function(a, b) { + return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; + }, byteswapM: function(a) { + var b, c; + for (b = 0; b < a.length; ++b) c = a[b], a[b] = c >>> 24 | c >>> 8 & 65280 | (c & 65280) << 8 | c << 24; + return a; + } }; + sjcl2.codec.utf8String = { fromBits: function(a) { + var b = "", c = sjcl2.bitArray.bitLength(a), d, e; + for (d = 0; d < c / 8; d++) 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8; + return decodeURIComponent(escape(b)); + }, toBits: function(a) { + a = unescape(encodeURIComponent(a)); + var b = [], c, d = 0; + for (c = 0; c < a.length; c++) d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); + c & 3 && b.push(sjcl2.bitArray.partial(8 * (c & 3), d)); + return b; + } }; + sjcl2.codec.hex = { fromBits: function(a) { + var b = "", c; + for (c = 0; c < a.length; c++) b += ((a[c] | 0) + 263882790666240).toString(16).substr(4); + return b.substr(0, sjcl2.bitArray.bitLength(a) / 4); + }, toBits: function(a) { + var b, c = [], d; + a = a.replace(/\s|0x/g, ""); + d = a.length; + a = a + "00000000"; + for (b = 0; b < a.length; b += 8) c.push(parseInt(a.substr(b, 8), 16) ^ 0); + return sjcl2.bitArray.clamp(c, 4 * d); + } }; + sjcl2.codec.base32 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", X: "0123456789ABCDEFGHIJKLMNOPQRSTUV", BITS: 32, BASE: 5, REMAINING: 27, fromBits: function(a, b, c) { + var d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = "", g = 0, h = sjcl2.codec.base32.B, k = 0, l = sjcl2.bitArray.bitLength(a); + c && (h = sjcl2.codec.base32.X); + for (c = 0; f.length * d < l; ) f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d); + for (; f.length & 7 && !b; ) f += "="; + return f; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, "").toUpperCase(); + var c = sjcl2.codec.base32.BITS, d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = [], g, h = 0, k = sjcl2.codec.base32.B, l = 0, n, m = "base32"; + b && (k = sjcl2.codec.base32.X, m = "base32hex"); + for (g = 0; g < a.length; g++) { + n = k.indexOf(a.charAt(g)); + if (0 > n) { + if (!b) try { + return sjcl2.codec.base32hex.toBits(a); + } catch (p) { + } + throw new sjcl2.exception.invalid("this isn't " + m + "!"); + } + h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h); + } + h & 56 && f.push(sjcl2.bitArray.partial(h & 56, l, 1)); + return f; + } }; + sjcl2.codec.base32hex = { fromBits: function(a, b) { + return sjcl2.codec.base32.fromBits(a, b, 1); + }, toBits: function(a) { + return sjcl2.codec.base32.toBits(a, 1); + } }; + sjcl2.codec.base64 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", fromBits: function(a, b, c) { + var d = "", e = 0, f = sjcl2.codec.base64.B, g = 0, h = sjcl2.bitArray.bitLength(a); + c && (f = f.substr(0, 62) + "-_"); + for (c = 0; 6 * d.length < h; ) d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6); + for (; d.length & 3 && !b; ) d += "="; + return d; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, ""); + var c = [], d, e = 0, f = sjcl2.codec.base64.B, g = 0, h; + b && (f = f.substr(0, 62) + "-_"); + for (d = 0; d < a.length; d++) { + h = f.indexOf(a.charAt(d)); + if (0 > h) throw new sjcl2.exception.invalid("this isn't base64!"); + 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e); + } + e & 56 && c.push(sjcl2.bitArray.partial(e & 56, g, 1)); + return c; + } }; + sjcl2.codec.base64url = { fromBits: function(a) { + return sjcl2.codec.base64.fromBits(a, 1, 1); + }, toBits: function(a) { + return sjcl2.codec.base64.toBits(a, 1); + } }; + sjcl2.hash.sha256 = function(a) { + this.b[0] || this.O(); + a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset(); + }; + sjcl2.hash.sha256.hash = function(a) { + return new sjcl2.hash.sha256().update(a).finalize(); + }; + sjcl2.hash.sha256.prototype = { blockSize: 512, reset: function() { + this.F = this.Y.slice(0); + this.A = []; + this.l = 0; + return this; + }, update: function(a) { + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + var b, c = this.A = sjcl2.bitArray.concat(this.A, a); + b = this.l; + a = this.l = b + sjcl2.bitArray.bitLength(a); + if (9007199254740991 < a) throw new sjcl2.exception.invalid("Cannot hash more than 2^53 - 1 bits"); + if ("undefined" !== typeof Uint32Array) { + var d = new Uint32Array(c), e = 0; + for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, d.subarray( + 16 * e, + 16 * (e + 1) + )), e += 1; + c.splice(0, 16 * e); + } else for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, c.splice(0, 16)); + return this; + }, finalize: function() { + var a, b = this.A, c = this.F, b = sjcl2.bitArray.concat(b, [sjcl2.bitArray.partial(1, 1)]); + for (a = b.length + 2; a & 15; a++) b.push(0); + b.push(Math.floor(this.l / 4294967296)); + for (b.push(this.l | 0); b.length; ) u(this, b.splice(0, 16)); + this.reset(); + return c; + }, Y: [], b: [], O: function() { + function a(a2) { + return 4294967296 * (a2 - Math.floor(a2)) | 0; + } + for (var b = 0, c = 2, d, e; 64 > b; c++) { + e = true; + for (d = 2; d * d <= c; d++) if (0 === c % d) { + e = false; + break; + } + e && (8 > b && (this.Y[b] = a(Math.pow(c, 0.5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++); + } + } }; + function u(a, b) { + var c, d, e, f = a.F, g = a.b, h = f[0], k = f[1], l = f[2], n = f[3], m = f[4], p = f[5], r = f[6], q = f[7]; + for (c = 0; 64 > c; c++) 16 > c ? d = b[c] : (d = b[c + 1 & 15], e = b[c + 14 & 15], d = b[c & 15] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + b[c & 15] + b[c + 9 & 15] | 0), d = d + q + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (r ^ m & (p ^ r)) + g[c], q = r, r = p, p = m, m = n + d | 0, n = l, l = k, k = h, h = d + (k & l ^ n & (k ^ l)) + (k >>> 2 ^ k >>> 13 ^ k >>> 22 ^ k << 30 ^ k << 19 ^ k << 10) | 0; + f[0] = f[0] + h | 0; + f[1] = f[1] + k | 0; + f[2] = f[2] + l | 0; + f[3] = f[3] + n | 0; + f[4] = f[4] + m | 0; + f[5] = f[5] + p | 0; + f[6] = f[6] + r | 0; + f[7] = f[7] + q | 0; + } + sjcl2.mode.ccm = { name: "ccm", G: [], listenProgress: function(a) { + sjcl2.mode.ccm.G.push(a); + }, unListenProgress: function(a) { + a = sjcl2.mode.ccm.G.indexOf(a); + -1 < a && sjcl2.mode.ccm.G.splice(a, 1); + }, fa: function(a) { + var b = sjcl2.mode.ccm.G.slice(), c; + for (c = 0; c < b.length; c += 1) b[c](a); + }, encrypt: function(a, b, c, d, e) { + var f, g = b.slice(0), h = sjcl2.bitArray, k = h.bitLength(c) / 8, l = h.bitLength(g) / 8; + e = e || 64; + d = d || []; + if (7 > k) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (f = 2; 4 > f && l >>> 8 * f; f++) ; + f < 15 - k && (f = 15 - k); + c = h.clamp( + c, + 8 * (15 - f) + ); + b = sjcl2.mode.ccm.V(a, b, c, d, e, f); + g = sjcl2.mode.ccm.C(a, g, c, b, e, f); + return h.concat(g.data, g.tag); + }, decrypt: function(a, b, c, d, e) { + e = e || 64; + d = d || []; + var f = sjcl2.bitArray, g = f.bitLength(c) / 8, h = f.bitLength(b), k = f.clamp(b, h - e), l = f.bitSlice(b, h - e), h = (h - e) / 8; + if (7 > g) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (b = 2; 4 > b && h >>> 8 * b; b++) ; + b < 15 - g && (b = 15 - g); + c = f.clamp(c, 8 * (15 - b)); + k = sjcl2.mode.ccm.C(a, k, c, l, e, b); + a = sjcl2.mode.ccm.V(a, k.data, c, d, e, b); + if (!f.equal(k.tag, a)) throw new sjcl2.exception.corrupt("ccm: tag doesn't match"); + return k.data; + }, na: function(a, b, c, d, e, f) { + var g = [], h = sjcl2.bitArray, k = h.i; + d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)]; + d = h.concat(d, c); + d[3] |= e; + d = a.encrypt(d); + if (b.length) for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 4294967295 >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); + return d; + }, V: function(a, b, c, d, e, f) { + var g = sjcl2.bitArray, h = g.i; + e /= 8; + if (e % 2 || 4 > e || 16 < e) throw new sjcl2.exception.invalid("ccm: invalid tag length"); + if (4294967295 < d.length || 4294967295 < b.length) throw new sjcl2.exception.bug("ccm: can't deal with 4GiB or more data"); + c = sjcl2.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f); + for (d = 0; d < b.length; d += 4) c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); + return g.clamp(c, 8 * e); + }, C: function(a, b, c, d, e, f) { + var g, h = sjcl2.bitArray; + g = h.i; + var k = b.length, l = h.bitLength(b), n = k / 50, m = n; + c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4); + d = h.bitSlice(g(d, a.encrypt(c)), 0, e); + if (!k) return { tag: d, data: [] }; + for (g = 0; g < k; g += 4) g > n && (sjcl2.mode.ccm.fa(g / k), n += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3]; + return { tag: d, data: h.clamp(b, l) }; + } }; + sjcl2.mode.ocb2 = { name: "ocb2", encrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + var g, h = sjcl2.mode.ocb2.S, k = sjcl2.bitArray, l = k.i, n = [0, 0, 0, 0]; + c = h(a.encrypt(c)); + var m, p = []; + d = d || []; + e = e || 64; + for (g = 0; g + 4 < b.length; g += 4) m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c); + m = b.slice(g); + b = k.bitLength(m); + g = a.encrypt(l(c, [0, 0, 0, b])); + m = k.clamp(l(m.concat([0, 0, 0]), g), b); + n = l(n, l(m.concat([0, 0, 0]), g)); + n = a.encrypt(l(n, l(c, h(c)))); + d.length && (n = l(n, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + return p.concat(k.concat(m, k.clamp(n, e))); + }, decrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + e = e || 64; + var g = sjcl2.mode.ocb2.S, h = sjcl2.bitArray, k = h.i, l = [0, 0, 0, 0], n = g(a.encrypt(c)), m, p, r = sjcl2.bitArray.bitLength(b) - e, q = []; + d = d || []; + for (c = 0; c + 4 < r / 32; c += 4) m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n); + p = r - 32 * c; + m = a.encrypt(k(n, [0, 0, 0, p])); + m = k(m, h.clamp(b.slice(c), p).concat([ + 0, + 0, + 0 + ])); + l = k(l, m); + l = a.encrypt(k(l, k(n, g(n)))); + d.length && (l = k(l, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl2.exception.corrupt("ocb: tag doesn't match"); + return q.concat(h.clamp(m, p)); + }, pmac: function(a, b) { + var c, d = sjcl2.mode.ocb2.S, e = sjcl2.bitArray, f = e.i, g = [0, 0, 0, 0], h = a.encrypt([0, 0, 0, 0]), h = f(h, d(d(h))); + for (c = 0; c + 4 < b.length; c += 4) h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4)))); + c = b.slice(c); + 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0])); + g = f(g, c); + return a.encrypt(f(d(f(h, d(h))), g)); + }, S: function(a) { + return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)]; + } }; + sjcl2.mode.gcm = { name: "gcm", encrypt: function(a, b, c, d, e) { + var f = b.slice(0); + b = sjcl2.bitArray; + d = d || []; + a = sjcl2.mode.gcm.C(true, a, f, d, c, e || 128); + return b.concat(a.data, a.tag); + }, decrypt: function(a, b, c, d, e) { + var f = b.slice(0), g = sjcl2.bitArray, h = g.bitLength(f); + e = e || 128; + d = d || []; + e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []); + a = sjcl2.mode.gcm.C(false, a, f, d, c, e); + if (!g.equal(a.tag, b)) throw new sjcl2.exception.corrupt("gcm: tag doesn't match"); + return a.data; + }, ka: function(a, b) { + var c, d, e, f, g, h = sjcl2.bitArray.i; + e = [ + 0, + 0, + 0, + 0 + ]; + f = b.slice(0); + for (c = 0; 128 > c; c++) { + (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f)); + g = 0 !== (f[3] & 1); + for (d = 3; 0 < d; d--) f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31; + f[0] >>>= 1; + g && (f[0] ^= -520093696); + } + return e; + }, j: function(a, b, c) { + var d, e = c.length; + b = b.slice(0); + for (d = 0; d < e; d += 4) b[0] ^= 4294967295 & c[d], b[1] ^= 4294967295 & c[d + 1], b[2] ^= 4294967295 & c[d + 2], b[3] ^= 4294967295 & c[d + 3], b = sjcl2.mode.gcm.ka(b, a); + return b; + }, C: function(a, b, c, d, e, f) { + var g, h, k, l, n, m, p, r, q = sjcl2.bitArray; + m = c.length; + p = q.bitLength(c); + r = q.bitLength(d); + h = q.bitLength(e); + g = b.encrypt([0, 0, 0, 0]); + 96 === h ? (e = e.slice(0), e = q.concat(e, [1])) : (e = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], e), e = sjcl2.mode.gcm.j(g, e, [0, 0, Math.floor(h / 4294967296), h & 4294967295])); + h = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], d); + n = e.slice(0); + d = h.slice(0); + a || (d = sjcl2.mode.gcm.j(g, h, c)); + for (l = 0; l < m; l += 4) n[3]++, k = b.encrypt(n), c[l] ^= k[0], c[l + 1] ^= k[1], c[l + 2] ^= k[2], c[l + 3] ^= k[3]; + c = q.clamp(c, p); + a && (d = sjcl2.mode.gcm.j(g, h, c)); + a = [Math.floor(r / 4294967296), r & 4294967295, Math.floor(p / 4294967296), p & 4294967295]; + d = sjcl2.mode.gcm.j(g, d, a); + k = b.encrypt(e); + d[0] ^= k[0]; + d[1] ^= k[1]; + d[2] ^= k[2]; + d[3] ^= k[3]; + return { tag: q.bitSlice(d, 0, f), data: c }; + } }; + sjcl2.misc.hmac = function(a, b) { + this.W = b = b || sjcl2.hash.sha256; + var c = [[], []], d, e = b.prototype.blockSize / 32; + this.w = [new b(), new b()]; + a.length > e && (a = b.hash(a)); + for (d = 0; d < e; d++) c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828; + this.w[0].update(c[0]); + this.w[1].update(c[1]); + this.R = new b(this.w[0]); + }; + sjcl2.misc.hmac.prototype.encrypt = sjcl2.misc.hmac.prototype.mac = function(a) { + if (this.aa) throw new sjcl2.exception.invalid("encrypt on already updated hmac called!"); + this.update(a); + return this.digest(a); + }; + sjcl2.misc.hmac.prototype.reset = function() { + this.R = new this.W(this.w[0]); + this.aa = false; + }; + sjcl2.misc.hmac.prototype.update = function(a) { + this.aa = true; + this.R.update(a); + }; + sjcl2.misc.hmac.prototype.digest = function() { + var a = this.R.finalize(), a = new this.W(this.w[1]).update(a).finalize(); + this.reset(); + return a; + }; + sjcl2.misc.pbkdf2 = function(a, b, c, d, e) { + c = c || 1e4; + if (0 > d || 0 > c) throw new sjcl2.exception.invalid("invalid params to pbkdf2"); + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + e = e || sjcl2.misc.hmac; + a = new e(a); + var f, g, h, k, l = [], n = sjcl2.bitArray; + for (k = 1; 32 * l.length < (d || 1); k++) { + e = f = a.encrypt(n.concat(b, [k])); + for (g = 1; g < c; g++) for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h]; + l = l.concat(e); + } + d && (l = n.clamp(l, d)); + return l; + }; + sjcl2.prng = function(a) { + this.c = [new sjcl2.hash.sha256()]; + this.m = [0]; + this.P = 0; + this.H = {}; + this.N = 0; + this.U = {}; + this.Z = this.f = this.o = this.ha = 0; + this.b = [0, 0, 0, 0, 0, 0, 0, 0]; + this.h = [0, 0, 0, 0]; + this.L = void 0; + this.M = a; + this.D = false; + this.K = { progress: {}, seeded: {} }; + this.u = this.ga = 0; + this.I = 1; + this.J = 2; + this.ca = 65536; + this.T = [0, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024]; + this.da = 3e4; + this.ba = 80; + }; + sjcl2.prng.prototype = { + randomWords: function(a, b) { + var c = [], d; + d = this.isReady(b); + var e; + if (d === this.u) throw new sjcl2.exception.notReady("generator isn't seeded"); + if (d & this.J) { + d = !(d & this.I); + e = []; + var f = 0, g; + this.Z = e[0] = (/* @__PURE__ */ new Date()).valueOf() + this.da; + for (g = 0; 16 > g; g++) e.push(4294967296 * Math.random() | 0); + for (g = 0; g < this.c.length && (e = e.concat(this.c[g].finalize()), f += this.m[g], this.m[g] = 0, d || !(this.P & 1 << g)); g++) ; + this.P >= 1 << this.c.length && (this.c.push(new sjcl2.hash.sha256()), this.m.push(0)); + this.f -= f; + f > this.o && (this.o = f); + this.P++; + this.b = sjcl2.hash.sha256.hash(this.b.concat(e)); + this.L = new sjcl2.cipher.aes(this.b); + for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) ; + } + for (d = 0; d < a; d += 4) 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]); + y(this); + return c.slice(0, a); + }, + setDefaultParanoia: function(a, b) { + if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) throw new sjcl2.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); + this.M = a; + }, + addEntropy: function(a, b, c) { + c = c || "user"; + var d, e, f = (/* @__PURE__ */ new Date()).valueOf(), g = this.H[c], h = this.isReady(), k = 0; + d = this.U[c]; + void 0 === d && (d = this.U[c] = this.ha++); + void 0 === g && (g = this.H[c] = 0); + this.H[c] = (this.H[c] + 1) % this.c.length; + switch (typeof a) { + case "number": + void 0 === b && (b = 1); + this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]); + break; + case "object": + c = Object.prototype.toString.call(a); + if ("[object Uint32Array]" === c) { + e = []; + for (c = 0; c < a.length; c++) e.push(a[c]); + a = e; + } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) "number" !== typeof a[c] && (k = 1); + if (!k) { + if (void 0 === b) for (c = b = 0; c < a.length; c++) for (e = a[c]; 0 < e; ) b++, e = e >>> 1; + this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a)); + } + break; + case "string": + void 0 === b && (b = a.length); + this.c[g].update([d, this.N++, 3, b, f, a.length]); + this.c[g].update(a); + break; + default: + k = 1; + } + if (k) throw new sjcl2.exception.bug("random: addEntropy only supports number, array of numbers or string"); + this.m[g] += b; + this.f += b; + h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress())); + }, + isReady: function(a) { + a = this.T[void 0 !== a ? a : this.M]; + return this.o && this.o >= a ? this.m[0] > this.ba && (/* @__PURE__ */ new Date()).valueOf() > this.Z ? this.J | this.I : this.I : this.f >= a ? this.J | this.u : this.u; + }, + getProgress: function(a) { + a = this.T[a ? a : this.M]; + return this.o >= a ? 1 : this.f > a ? 1 : this.f / a; + }, + startCollectors: function() { + if (!this.D) { + this.a = { loadTimeCollector: B(this, this.ma), mouseCollector: B(this, this.oa), keyboardCollector: B(this, this.la), accelerometerCollector: B(this, this.ea), touchCollector: B(this, this.qa) }; + if (window.addEventListener) window.addEventListener( + "load", + this.a.loadTimeCollector, + false + ), window.addEventListener("mousemove", this.a.mouseCollector, false), window.addEventListener("keypress", this.a.keyboardCollector, false), window.addEventListener("devicemotion", this.a.accelerometerCollector, false), window.addEventListener("touchmove", this.a.touchCollector, false); + 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 sjcl2.exception.bug("can't attach event"); + this.D = true; + } + }, + stopCollectors: function() { + this.D && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, false), window.removeEventListener("mousemove", this.a.mouseCollector, false), window.removeEventListener("keypress", this.a.keyboardCollector, false), window.removeEventListener("devicemotion", this.a.accelerometerCollector, false), window.removeEventListener("touchmove", this.a.touchCollector, false)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent( + "onmousemove", + this.a.mouseCollector + ), document.detachEvent("keypress", this.a.keyboardCollector)), this.D = false); + }, + addEventListener: function(a, b) { + this.K[a][this.ga++] = b; + }, + removeEventListener: function(a, b) { + var c, d, e = this.K[a], f = []; + for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d); + for (c = 0; c < f.length; c++) d = f[c], delete e[d]; + }, + la: function() { + C(this, 1); + }, + oa: function(a) { + var b, c; + try { + b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0; + } catch (d) { + c = b = 0; + } + 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); + C(this, 0); + }, + qa: function(a) { + a = a.touches[0] || a.changedTouches[0]; + this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); + C(this, 0); + }, + ma: function() { + C(this, 2); + }, + ea: function(a) { + a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; + if (window.orientation) { + var b = window.orientation; + "number" === typeof b && this.addEntropy(b, 1, "accelerometer"); + } + a && this.addEntropy(a, 2, "accelerometer"); + C(this, 0); + } + }; + function A(a, b) { + var c, d = sjcl2.random.K[a], e = []; + for (c in d) d.hasOwnProperty(c) && e.push(d[c]); + for (c = 0; c < e.length; c++) e[c](b); + } + function C(a, b) { + "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy((/* @__PURE__ */ new Date()).valueOf(), b, "loadtime"); + } + function y(a) { + a.b = z(a).concat(z(a)); + a.L = new sjcl2.cipher.aes(a.b); + } + function z(a) { + for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) ; + return a.L.encrypt(a.h); + } + function B(a, b) { + return function() { + b.apply(a, arguments); + }; + } + sjcl2.random = new sjcl2.prng(6); + a: try { + if (G = "undefined" !== typeof module && module.exports) { + try { + H = __require("crypto"); + } catch (a) { + H = null; + } + G = E = H; + } + if (G && E.randomBytes) D = E.randomBytes(128), D = new Uint32Array(new Uint8Array(D).buffer), sjcl2.random.addEntropy(D, 1024, "crypto['randomBytes']"); + else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { + F = new Uint32Array(32); + if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F); + else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F); + else break a; + sjcl2.random.addEntropy(F, 1024, "crypto['getRandomValues']"); + } + } catch (a) { + "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a)); + } + var D; + var E; + var F; + var G; + var H; + sjcl2.json = { defaults: { v: 1, iter: 1e4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, ja: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json, f = e.g({ iv: sjcl2.random.randomWords(4, 0) }, e.defaults), g; + e.g(f, c); + c = f.adata; + "string" === typeof f.salt && (f.salt = sjcl2.codec.base64.toBits(f.salt)); + "string" === typeof f.iv && (f.iv = sjcl2.codec.base64.toBits(f.iv)); + if (!sjcl2.mode[f.mode] || !sjcl2.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 256 !== f.ks || 2 > f.iv.length || 4 < f.iv.length) throw new sjcl2.exception.invalid("json encrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + "string" === typeof c && (f.adata = c = sjcl2.codec.utf8String.toBits(c)); + g = new sjcl2.cipher[f.cipher](a); + e.g(d, f); + d.key = a; + f.ct = "ccm" === f.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl2.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); + return f; + }, encrypt: function(a, b, c, d) { + var e = sjcl2.json, f = e.ja.apply(e, arguments); + return e.encode(f); + }, ia: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json; + b = e.g(e.g(e.g({}, e.defaults), b), c, true); + var f, g; + f = b.adata; + "string" === typeof b.salt && (b.salt = sjcl2.codec.base64.toBits(b.salt)); + "string" === typeof b.iv && (b.iv = sjcl2.codec.base64.toBits(b.iv)); + if (!sjcl2.mode[b.mode] || !sjcl2.cipher[b.cipher] || "string" === typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 256 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) throw new sjcl2.exception.invalid("json decrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.secretKey && (a = a.unkem(sjcl2.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); + "string" === typeof f && (f = sjcl2.codec.utf8String.toBits(f)); + g = new sjcl2.cipher[b.cipher](a); + f = "ccm" === b.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl2.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); + e.g(d, b); + d.key = a; + return 1 === c.raw ? f : sjcl2.codec.utf8String.fromBits(f); + }, decrypt: function(a, b, c, d) { + var e = sjcl2.json; + return e.ia(a, e.decode(b), c, d); + }, encode: function(a) { + var b, c = "{", d = ""; + for (b in a) if (a.hasOwnProperty(b)) { + if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl2.exception.invalid("json encode: invalid property name"); + c += d + '"' + b + '":'; + d = ","; + switch (typeof a[b]) { + case "number": + case "boolean": + c += a[b]; + break; + case "string": + c += '"' + escape(a[b]) + '"'; + break; + case "object": + c += '"' + sjcl2.codec.base64.fromBits(a[b], 0) + '"'; + break; + default: + throw new sjcl2.exception.bug("json encode: unsupported type"); + } + } + return c + "}"; + }, decode: function(a) { + a = a.replace(/\s/g, ""); + if (!a.match(/^\{.*\}$/)) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + a = a.replace(/^\{|\}$/g, "").split(/,/); + var b = {}, c, d; + for (c = 0; c < a.length; c++) { + if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl2.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]); + } + return b; + }, g: function(a, b, c) { + void 0 === a && (a = {}); + if (void 0 === b) return a; + for (var d in b) if (b.hasOwnProperty(d)) { + if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl2.exception.invalid("required parameter overridden"); + a[d] = b[d]; + } + return a; + }, sa: function(a, b) { + var c = {}, d; + for (d in a) a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); + return c; + }, ra: function(a, b) { + var c = {}, d; + for (d = 0; d < b.length; d++) void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); + return c; + } }; + sjcl2.encrypt = sjcl2.json.encrypt; + sjcl2.decrypt = sjcl2.json.decrypt; + sjcl2.misc.pa = {}; + sjcl2.misc.cachedPbkdf2 = function(a, b) { + var c = sjcl2.misc.pa, d; + b = b || {}; + d = b.iter || 1e3; + c = c[a] = c[a] || {}; + d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl2.random.randomWords(2, 0) }; + c = void 0 === b.salt ? d.firstSalt : b.salt; + d[c] = d[c] || sjcl2.misc.pbkdf2(a, c, b.iter); + return { key: d[c].slice(0), salt: c.slice(0) }; + }; + "undefined" !== typeof module && module.exports && (module.exports = sjcl2); + "function" === typeof define && define([], function() { + return sjcl2; + }); + } +}); + +// src/worker/main.ts +var import_events = __toESM(require_events()); + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var okAsync = (value) => new ResultAsync(Promise.resolve(new Ok(value))); +var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result2) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result2.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result2.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result2.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err2) { + return new Err(err2); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err2) { + return err2(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/error/base-error.ts +var BaseError = class extends Error { + constructor(message, options = {}) { + const { cause, context } = options; + super(message, { cause }); + __publicField(this, "context"); + this.name = this.constructor.name; + this.context = context; + } +}; + +// src/utils.ts +var ensureError = (value) => { + if (value instanceof Error) return value; + let stringified = "[Unable to stringify the thrown value]"; + try { + stringified = JSON.stringify(value); + } catch (_error) { + } + const error = new Error(stringified); + return error; +}; +var isDenoRuntime = () => typeof Deno !== "undefined"; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); + +// src/worker/main.ts +var events = new import_events.default(); +var worker; +var isInitialized = false; +self.onmessage = (event) => { + addWorker(event); + if (!isInitialized) { + isInitialized = true; + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + if (worker) { + worker.terminate(); + } + }); + } +}; +var updateFile = (lufiFile, args) => { + Object.assign(lufiFile, args); + if (typeof WorkerGlobalScope !== "undefined") { + self.postMessage({ + event: "FILE_UPDATED" /* FILE_UPDATED */, + lufiFile + }); + } + return lufiFile; +}; +var addWorker = (event, callback) => { + const { action } = event.data; + if (action === 5 /* PAUSE */ || action === 8 /* RESUME */) { + worker.postMessage(event.data); + } else { + switch (action) { + case 2 /* CANCEL */: + { + worker = new Worker(workerUrl("cancel"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 3 /* DOWNLOAD */: + { + worker = new Worker(workerUrl("download"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 4 /* INFOS */: + { + worker = new Worker(workerUrl("infos"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 7 /* REMOVE */: + { + worker = worker || new Worker(workerUrl("remove"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 9 /* UPLOAD */: + { + worker = worker || new Worker(workerUrl("upload"), { type: "module" }); + worker.postMessage(event.data); + } + break; + default: { + console.error("Action not found"); + } + } + worker.onmessage = (e) => { + if (callback) callback(e); + self.postMessage(e.data); + }; + worker.onerror = (error) => { + console.error(`Error: ${error.message}`); + }; + } +}; +var init = () => { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + self.postMessage({ + event: "SOCKET_OPENED" /* SOCKET_OPENED */ + }); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); + }); +}; + +// src/error/websocket/websocket-error.ts +var WebSocketError = class extends BaseError { +}; + +// src/error/websocket/websocket-connection-error.ts +var WebSocketConnectionError = class extends WebSocketError { + constructor() { + super(...arguments); + __publicField(this, "message", "An error occured while trying to connect to WebSocket"); + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/encoding.js +var Encoding = class { + /** + * + * @param charset Charset to use for base64 encoding. This must be 64-characters long. + * @param noPadding If true, encoded strings won't include padding. + */ + constructor(charset, noPadding) { + if (!charset || charset.length != 64) { + throw Error("Charset must contain 64 characters"); + } + this._charset = charset; + this._noPadding = !!noPadding; + this._valid = new RegExp("^[" + this._charset.replace("-", "\\-") + "]+={0,2}$"); + } + /** + * Encode an ArrayBuffer to base64 in a string. + * @param ab Data to encode to base64 + * @returns Base64-encoded string + */ + Encode(ab) { + const len = ab.byteLength; + if (!len) { + return ""; + } + const view = new Uint8Array(ab); + let res = ""; + for (let i = 0; i < len; i += 3) { + res += this._charset[view[i] >> 2] + this._charset[(view[i] & 3) << 4 | view[i + 1] >> 4] + this._charset[(view[i + 1] & 15) << 2 | view[i + 2] >> 6] + this._charset[view[i + 2] & 63]; + } + if (len % 3 == 2) { + res = res.substring(0, res.length - 1); + if (!this._noPadding) { + res += "="; + } + } else if (len % 3 == 1) { + res = res.substring(0, res.length - 2); + if (!this._noPadding) { + res += "=="; + } + } + return res; + } + /** + * Decode a string from base64. Padding is always optional. + * @param str Base64-encoded string + * @returns Data decoded from the base64 string + */ + Decode(str) { + str = (str || "").replace(/[\s]/g, ""); + if (!str) { + return new ArrayBuffer(0); + } + if (!this._valid.test(str)) { + throw Error("Invalid base64 input sequence"); + } + let viewLen = Math.floor(str.length * 0.75); + if (str[str.length - 2] == "=") { + viewLen -= 2; + } else if (str[str.length - 1] == "=") { + viewLen--; + } + const view = new Uint8Array(viewLen); + let enc1, enc2, enc3, enc4, i = 0, j = 0; + while (i < str.length * 0.75) { + enc1 = this._charset.indexOf(str.charAt(j++)); + enc2 = this._charset.indexOf(str.charAt(j++)); + enc3 = this._charset.indexOf(str.charAt(j++)); + enc4 = this._charset.indexOf(str.charAt(j++)); + view[i++] = enc1 << 2 | enc2 >> 4; + view[i++] = (enc2 & 15) << 4 | enc3 >> 2; + view[i++] = (enc3 & 3) << 6 | enc4; + } + return view.buffer; + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/standard.js +var obj = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +function Decode(str) { + return obj.Decode(str); +} + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/url.js +var obj2 = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", true); +function Decode2(str) { + return obj2.Decode(str); +} + +// src/api/crypto/sjcl.ts +var import_sjcl = __toESM(require_sjcl()); + +// src/error/crypto/crypto-error.ts +var CryptoError = class extends BaseError { +}; + +// src/error/crypto/decryption-error.ts +var DecryptionError = class extends CryptoError { + constructor() { + super(...arguments); + __publicField(this, "message", "Unable to decrypt the provided data"); + } +}; + +// src/api/crypto/sjcl.ts +var decrypt = (key, encryptedData) => { + try { + const data = typeof encryptedData === "string" ? encryptedData : encryptedData.data; + return okAsync(Decode(import_sjcl.default.decrypt(key, data))); + } catch (error) { + return errAsync( + new DecryptionError(void 0, { cause: ensureError(error) }) + ); + } +}; + +// src/api/crypto/web.ts +var decrypt2 = (key, encrypted) => { + return importKey(key).andThen( + (importedKey) => ResultAsync.fromPromise( + crypto.subtle.decrypt( + { + name: "AES-GCM", + iv: encrypted.iv + }, + importedKey, + Decode(encrypted.data) + ), + (error) => new DecryptionError(void 0, { cause: ensureError(error) }) + ) + ); +}; +var importKey = (key) => { + return ResultAsync.fromPromise( + crypto.subtle.importKey( + "raw", + Decode2(key), + { name: "AES-GCM" }, + false, + [ + "encrypt", + "decrypt" + ] + ), + (error) => new CryptoError("Unable to import cryptography key", { + cause: ensureError(error) + }) + ); +}; + +// src/api/crypto.ts +var decrypt3 = (key, value) => { + return value.algo === void 0 || value.algo === 0 /* Sjcl */ ? decrypt(key, value) : decrypt2(key, value); +}; + +// src/api/websocket.ts +var sockets = {}; +var MAX_ERRORS = 5; +var onCancelMessage = (data) => { + events.emit("UPLOAD_CANCELLED" /* UPLOAD_CANCELLED */, data.success); + return okAsync(void 0); +}; +var onDownloadMessage = (response, lufiFile) => { + const result = response.split("XXMOJOXX"); + const metadataString = result.shift(); + if (metadataString !== void 0) { + const metadata = JSON.parse(metadataString); + if (isServerDownloadChunkSuccessMetadata(metadata)) { + const dataString = result.shift(); + if (dataString) { + const encryptedData = JSON.parse(dataString); + if (encryptedData.iv) { + encryptedData.iv = new Uint8Array(Object.values(encryptedData.iv)); + } + return decrypt3(lufiFile.keys.client, encryptedData).andThen( + (decryptedPart) => { + const chunk = typeof decryptedPart === "string" ? new TextEncoder().encode(decryptedPart).buffer : decryptedPart; + if (metadata.part === 0) { + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + delAtFirstView: metadata.del_at_first_view, + delay: metadata.delay, + name: metadata.name, + size: metadata.size, + totalChunks: metadata.total, + type: metadata.type, + zipped: metadata.zipped + }); + events.emit("DOWNLOAD_STARTED" /* DOWNLOAD_STARTED */); + } else { + updateFile(lufiFile, { chunksReady: lufiFile.chunksReady + 1 }); + } + events.emit("CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, chunk, metadata.part); + if (++metadata.part === metadata.total) { + return endDownload(lufiFile).andThen(() => { + events.emit("DOWNLOAD_COMPLETE" /* DOWNLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + return okAsync(void 0); + }); + } + return okAsync(void 0); + } + ); + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError(metadata.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onUploadMessage = (response, lufiFile) => { + if (response.success) { + if (response.j === 0) { + updateFile(lufiFile, { + keys: { client: lufiFile.keys.client, server: response.short }, + actionToken: response.token, + queueIndex: response.i + }); + events.emit("UPLOAD_STARTED" /* UPLOAD_STARTED */); + } + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + createdAt: response.created_at + }); + events.emit("CHUNK_UPLOADED" /* CHUNK_UPLOADED */); + if (lufiFile.chunksReady === lufiFile.totalChunks) { + updateFile(lufiFile, { uploadStatus: 1 /* COMPLETE */ }); + events.emit("UPLOAD_COMPLETE" /* UPLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + } + return okAsync(void 0); + } else { + const error = new WebSocketError(response.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onMessage = (e, lufiFile) => { + const data = tryParseJson(e.data); + let callback; + if (data) { + if (!data.action && data.msg) { + const error = new WebSocketError(data.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } else { + if ("delay" in data) { + callback = onUploadMessage(data, lufiFile); + } else { + callback = onCancelMessage(data); + } + } + } else { + callback = onDownloadMessage(e.data, lufiFile); + } + return callback; +}; +var isConnecting = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.CONNECTING; +var isSpawned = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.OPEN; +var cancelUpload = (lufiFile) => { + return sendMessage( + uploadSocketUrl(lufiFile), + lufiFile, + `${JSON.stringify({ + id: lufiFile.keys.server, + mod_token: lufiFile.actionToken, + cancel: true, + i: lufiFile.queueIndex + })}XXMOJOXXuseless` + ); +}; +var endDownload = (lufiFile) => { + let message; + if (lufiFile.password) { + message = { ended: true, file_pwd: lufiFile.password }; + } else { + message = { ended: true }; + } + return sendMessage( + downloadSocketUrl(lufiFile), + lufiFile, + JSON.stringify(message) + ); +}; +var sendMessage = (socketUrl, lufiFile, message) => { + if (!isSpawned(socketUrl)) { + return spawn(socketUrl).andThen( + () => sendMessage(socketUrl, lufiFile, message) + ); + } else { + sockets[socketUrl].onmessage = (e) => onMessage(e, lufiFile); + sockets[socketUrl].send(message); + return okAsync(void 0); + } +}; +var spawn = (socketKey, errorCount = 0) => { + if (!isSpawned(socketKey) && !isConnecting(socketKey)) { + sockets[socketKey] = new WebSocket(socketKey); + events.once("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */, () => { + sockets[socketKey].close(); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + }); + sockets[socketKey].onopen = () => { + events.emit("SOCKET_OPENED" /* SOCKET_OPENED */); + }; + sockets[socketKey].onclose = () => { + }; + sockets[socketKey].onerror = () => { + if (++errorCount <= MAX_ERRORS) { + console.error( + `An error happened while trying to connect to WebSocket ${socketKey}. Trying again. ${errorCount} / ${MAX_ERRORS}` + ); + return spawn(socketKey, errorCount); + } else { + events.emit("SOCKET_ONERROR" /* SOCKET_ONERROR */); + return errAsync( + new WebSocketConnectionError( + `Unable to connect to WebSocket ${socketKey}.` + ) + ); + } + }; + } + return waitForConnection(socketKey).andThen(() => okAsync(socketKey)).orElse((error) => errAsync(error)); +}; +var waitForConnection = (socketKey) => ResultAsync.fromPromise( + new Promise((resolve, reject) => { + if (!isSpawned(socketKey)) { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + resolve(void 0); + }); + events.on("SOCKET_ONERROR" /* SOCKET_ONERROR */, () => { + reject(new WebSocketConnectionError()); + }); + } else { + resolve(void 0); + } + }), + (error) => { + return ensureError(error); + } +); +var buildSocketUrl = (instanceUrl, pathname) => { + const url = new URL(instanceUrl); + url.protocol = url.protocol === "http:" ? "ws:" : "wss:"; + url.pathname += pathname; + return new URL(url.origin + url.pathname); +}; +var downloadSocketUrl = (lufiFile) => { + return buildSocketUrl( + new URL(lufiFile.serverUrl), + "download" /* DOWNLOAD */ + `/${lufiFile.keys.server}` + ).toString(); +}; +var uploadSocketUrl = (lufiFile) => { + return buildSocketUrl(new URL(lufiFile.serverUrl), "upload" /* UPLOAD */).toString(); +}; +var tryParseJson = (data) => { + try { + const parsedObject = JSON.parse(data); + if (parsedObject && typeof parsedObject === "object") { + return parsedObject; + } + } catch (_e) { + } + return false; +}; +var isServerDownloadChunkSuccessMetadata = (message) => { + return typeof message === "object" && message !== null && !("msg" in message); +}; + +// src/worker/cancel.ts +var isInitiated = false; +self.onmessage = (event) => { + if (!isInitiated) { + init(); + isInitiated = true; + } + events.on("UPLOAD_CANCELLED" /* UPLOAD_CANCELLED */, (success) => { + self.postMessage({ event: "UPLOAD_CANCELLED" /* UPLOAD_CANCELLED */, success }); + }); + cancelUpload2(event.data).mapErr((error) => { + self.postMessage({ + event: "OPERATION_FAILED" /* OPERATION_FAILED */, + error + }); + }); +}; +var cancelUpload2 = (workerMessage) => cancelUpload(workerMessage.args.lufiFile); diff --git a/themes/default/public/js/worker/download.js b/themes/default/public/js/worker/download.js index 6f4f09c..33c0b61 100644 --- a/themes/default/public/js/worker/download.js +++ b/themes/default/public/js/worker/download.js @@ -1 +1,2804 @@ -var ut=Object.create;var Le=Object.defineProperty;var ft=Object.getOwnPropertyDescriptor;var ht=Object.getOwnPropertyNames;var lt=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty;var pt=(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 ce=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var mt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ht(e))!dt.call(t,o)&&o!==r&&Le(t,o,{get:()=>e[o],enumerable:!(n=ft(e,o))||n.enumerable});return t};var ue=(t,e,r)=>(r=t!=null?ut(lt(t)):{},mt(e||!t||!t.__esModule?Le(r,"default",{value:t,enumerable:!0}):r,t));var Me=ce((tr,fe)=>{"use strict";var N=typeof Reflect=="object"?Reflect:null,be=N&&typeof N.apply=="function"?N.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},ee;N&&typeof N.ownKeys=="function"?ee=N.ownKeys:Object.getOwnPropertySymbols?ee=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ee=function(e){return Object.getOwnPropertyNames(e)};function yt(t){console&&console.warn&&console.warn(t)}var De=Number.isNaN||function(e){return e!==e};function y(){y.init.call(this)}fe.exports=y;fe.exports.once=Et;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var _e=10;function te(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(y,"defaultMaxListeners",{enumerable:!0,get:function(){return _e},set:function(t){if(typeof t!="number"||t<0||De(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");_e=t}});y.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};y.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||De(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 Ce(t){return t._maxListeners===void 0?y.defaultMaxListeners:t._maxListeners}y.prototype.getMaxListeners=function(){return Ce(this)};y.prototype.emit=function(e){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=i[e];if(u===void 0)return!1;if(typeof u=="function")be(u,this,r);else for(var f=u.length,l=Pe(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,yt(c)}return t}y.prototype.addListener=function(e,r){return ke(this,e,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(e,r){return ke(this,e,r,!0)};function vt(){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 Se(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=vt.bind(n);return o.listener=r,n.wrapFn=o,o}y.prototype.once=function(e,r){return te(r),this.on(e,Se(this,e,r)),this};y.prototype.prependOnceListener=function(e,r){return te(r),this.prependListener(e,Se(this,e,r)),this};y.prototype.removeListener=function(e,r){var n,o,i,s,c;if(te(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():gt(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};y.prototype.off=y.prototype.removeListener;y.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 Te(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?wt(o):Pe(o,o.length)}y.prototype.listeners=function(e){return Te(this,e,!0)};y.prototype.rawListeners=function(e){return Te(this,e,!1)};y.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Ie.call(t,e)};y.prototype.listenerCount=Ie;function Ie(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}y.prototype.eventNames=function(){return this._eventsCount>0?ee(this._events):[]};function Pe(t,e){for(var r=new Array(e),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};a.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[1];e=t.length;var c=1;if(e!==4&&e!==6&&e!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],o[e]=4>=t||4>e?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(t){return Xe(this,t,0)},decrypt:function(t){return Xe(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,l,h,d;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=c[o=c[f=c[i]]],d=16843009*l^65537*o^257*f^16843008*i,l=257*c[h]^16843008*h,o=0;4>o;o++)t[o][i]=l=l<<24^l>>>8,e[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function Xe(t,e,r){if(e.length!==4)throw new a.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var c,u,f,l=n.length/4-2,h,d=4,p=[0,0,0,0];c=t.s[r],t=c[0];var v=c[1],M=c[2],Q=c[3],Z=c[4];for(h=0;h>>24]^v[i>>16&255]^M[s>>8&255]^Q[e&255]^n[d],u=t[i>>>24]^v[s>>16&255]^M[e>>8&255]^Q[o&255]^n[d+1],f=t[s>>>24]^v[e>>16&255]^M[o>>8&255]^Q[i&255]^n[d+2],e=t[e>>>24]^v[o>>16&255]^M[i>>8&255]^Q[s&255]^n[d+3],d+=4,o=c,i=u,s=f;for(h=0;4>h;h++)p[r?3&-h:h]=Z[o>>>24]<<24^Z[i>>16&255]<<16^Z[s>>8&255]<<8^Z[e&255]^n[d++],c=o,o=i,i=s,s=e,e=c;return p}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.$(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:a.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(a.bitArray.bitLength(t)!==a.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=a.bitArray.getPartial(o),n.push(a.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};a.codec.utf8String={fromBits:function(t){var e="",r=a.bitArray.bitLength(t),n,o;for(n=0;n>>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 a.codec.base32hex.toBits(t)}catch{}throw new a.exception.invalid("this isn't "+h+"!")}c>o?(c-=o,i.push(f^l>>>c),f=l<>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.B,s=0,c;for(e&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(t){return a.codec.base64.fromBits(t,1,1)},toBits:function(t){return a.codec.base64.toBits(t,1)}};a.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()};a.hash.sha256.hash=function(t){return new a.hash.sha256().update(t).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.A=a.bitArray.concat(this.A,t);if(e=this.l,t=this.l=e+a.bitArray.bitLength(t),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 de(t,e){var r,n,o,i=t.F,s=t.b,c=i[0],u=i[1],f=i[2],l=i[3],h=i[4],d=i[5],p=i[6],v=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+v+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(p^h&(d^p))+s[r],v=p,p=d,d=h,h=l+n|0,l=f,f=u,u=c,c=n+(u&f^l&(u^f))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10)|0;i[0]=i[0]+c|0,i[1]=i[1]+u|0,i[2]=i[2]+f|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+d|0,i[6]=i[6]+p|0,i[7]=i[7]+v|0}a.mode.ccm={name:"ccm",G:[],listenProgress:function(t){a.mode.ccm.G.push(t)},unListenProgress:function(t){t=a.mode.ccm.G.indexOf(t),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),e=a.mode.ccm.V(t,e,r,n,o,i),s=a.mode.ccm.C(t,s,r,e,o,i),c.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(e),c=i.clamp(e,f-o),u=i.bitSlice(e,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&f>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),c=a.mode.ccm.C(t,c,r,u,o,e),t=a.mode.ccm.V(t,c.data,r,n,o,e),!i.equal(c.tag,t))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},na:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.i;if(n=[c.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=t.encrypt(n),e.length)for(r=c.bitLength(e)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,e),e=0;eo||16l&&(a.mode.ccm.fa(s/u),l+=h),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:c.clamp(e,f)}}};a.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");var s,c=a.mode.ocb2.S,u=a.bitArray,f=u.i,l=[0,0,0,0];r=c(t.encrypt(r));var h,d=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(c=i(c,n(c)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(c,n(c))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};a.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=a.bitArray,n=n||[],t=a.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=a.bitArray,c=s.bitLength(i);if(o=o||128,n=n||[],o<=c?(e=s.bitSlice(i,c-o),i=s.bitSlice(i,0,c-o)):(e=i,i=[]),t=a.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new a.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,c=a.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=c(o,i)),s=(i[3]&1)!==0,n=3;0>>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 a.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),o=o||a.misc.hmac,t=new o(t);var i,s,c,u,f=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=t.encrypt(l.concat(e,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.L=new a.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[s].update(t);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=e,this.f+=e,c===this.u&&(this.isReady()!==this.u&&Ge("seeded",Math.max(this.o,this.f)),Ge("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:$(this,this.ma),mouseCollector:$(this,this.oa),keyboardCollector:$(this,this.la),accelerometerCollector:$(this,this.ea),touchCollector:$(this,this.qa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function $(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(ne=typeof W<"u"&&W.exports){try{oe=pt("crypto")}catch{oe=null}ne=re=oe}if(ne&&re.randomBytes)X=re.randomBytes(128),X=new Uint32Array(new Uint8Array(X).buffer),a.random.addEntropy(X,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;a.random.addEntropy(G,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 X,re,G,ne,oe;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=a.json,i=o.g({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.g(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof t=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=e.iter||e.ts!==64&&e.ts!==96&&e.ts!==128||e.ks!==128&&e.ks!==192&&e.ks!==256||!e.iv||2>e.iv.length||4{"use strict";var Ht=Object.prototype.hasOwnProperty,x="~";function K(){}Object.create&&(K.prototype=Object.create(null),new K().__proto__||(x=!1));function Yt(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function ot(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Yt(r,n||t,o),s=x?x+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function ie(t,e){--t._eventsCount===0?t._events=new K:delete t._events[e]}function E(){this._events=new K,this._eventsCount=0}E.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Ht.call(r,n)&&e.push(x?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};E.prototype.listeners=function(e){var r=x?x+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o{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 U(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(l){try{f(n.next(l))}catch(h){s(h)}}function u(l){try{f(n.throw(l))}catch(h){s(h)}}function f(l){l.done?i(l.value):o(l.value).then(c,u)}f((n=n.apply(t,[])).next())})}function Ne(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 P(t){return this instanceof P?(this.v=t,this):new P(t)}function Ot(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(d){n[d]&&(o[d]=function(p){return new Promise(function(v,M){i.push([d,p,v,M])>1||c(d,p)})})}function c(d,p){try{u(n[d](p))}catch(v){h(i[0][3],v)}}function u(d){d.value instanceof P?Promise.resolve(d.value.v).then(f,l):h(i[0][2],d)}function f(d){c("next",d)}function l(d){c("throw",d)}function h(d,p){d(p),i.shift(),i.length&&c(i[0][0],i[0][1])}}function Lt(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:P(t[o](s)),done:o==="return"}:i?i(s):s}:i}}function bt(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 Ne=="function"?Ne(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(c,u){s=t[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var g=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new L(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new L(o)).catch(o=>new b(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(U(this,void 0,void 0,function*(){try{return new L(yield e(...n))}catch(o){return new b(r?r(o):o)}}))}static combine(e){return _t(e)}static combineWithAllErrors(e){return Dt(e)}map(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?new b(r.error):new L(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new b(r.error);let n=yield e(r.value);return n.isErr()?new b(n.error):new L(r.value)})))}andTee(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new b(r.error);try{yield e(r.value)}catch{}return new L(r.value)})))}mapErr(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new b(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new b(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new L(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 Ot(this,arguments,function*(){return yield P(yield P(yield*Lt(bt(yield P(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},_=t=>new g(Promise.resolve(new L(t))),A=t=>new g(Promise.resolve(new b(t))),or=g.fromPromise,ir=g.fromSafePromise,sr=g.fromThrowable,Be=t=>{let e=I([]);for(let r of t)if(r.isErr()){e=C(r.error);break}else e.map(n=>n.push(r.value));return e},_t=t=>g.fromSafePromise(Promise.all(t)).andThen(Be),je=t=>{let e=I([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=C([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},Dt=t=>g.fromSafePromise(Promise.all(t)).andThen(je),he;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return I(c)}catch(c){return C(i?i(c):c)}}}t.fromThrowable=e;function r(o){return Be(o)}t.combine=r;function n(o){return je(o)}t.combineWithAllErrors=n})(he||(he={}));var I=t=>new L(t);function C(t){return new b(t)}var L=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return I(e(this.value))}mapErr(e){return I(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 I(this.value)}orElse(e){return I(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 Ue("Called `_unsafeUnwrapErr` on an Ok",this,e)}},b=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return C(this.error)}mapErr(e){return C(e(this.error))}andThrough(e){return C(this.error)}andTee(e){return C(this.error)}andThen(e){return C(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return A(this.error)}asyncAndThrough(e){return A(this.error)}asyncMap(e){return A(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield C(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ue("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},ar=he.fromThrowable;var S=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 R=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 Ct=()=>typeof Deno<"u",B=t=>Ct()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var m=new ze.default,w,We=!1;self.onmessage=t=>{St(t),We||(We=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var k=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),Je=(t,e)=>{k(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},St=(t,e)=>{let{action:r}=t.data;switch(r){case 0:w=new Worker(B("cancel"),{type:"module"}),w.postMessage(t.data);break;case 1:w=new Worker(B("download"),{type:"module"}),w.postMessage(t.data);break;case 2:w=new Worker(B("infos"),{type:"module"}),w.postMessage(t.data);break;case 4:w=w||new Worker(B("remove"),{type:"module"}),w.postMessage(t.data);break;case 5:{w=w||new Worker(B("upload"),{type:"module"}),w.postMessage(t.data);break}default:console.error("Action not found")}w.onmessage=n=>{e&&e(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},qe=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var D=class extends S{};var z=class extends D{message="An error occured while trying to connect to WebSocket"};var j=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,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Tt=new j("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function J(t){return Tt.Decode(t)}var It=new j("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function le(t){return It.Decode(t)}var Ve=ue(He());var T=class extends S{};var F=class extends T{message="Unable to decrypt the provided data"};var Qe=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return _(J(Ve.default.decrypt(t,r)))}catch(r){return A(new F(void 0,{cause:R(r)}))}};var Ze=(t,e)=>Mt(t).andThen(r=>g.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,J(e.data)),n=>new F(void 0,{cause:R(n)})));var Mt=t=>g.fromPromise(crypto.subtle.importKey("raw",le(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new T("Unable to import cryptography key",{cause:R(e)}));var et=(t,e)=>e.algo===void 0||e.algo===0?Qe(t,e):Ze(t,e);var O={},tt=5,Bt=t=>(m.emit("UPLOAD_CANCELLED",t.success),_(void 0)),jt=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Gt(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),et(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(k(e,{chunksReady:e.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):k(e,{chunksReady:e.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?Jt(e).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),_(void 0))):_(void 0)})}else{let s=new D("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),A(s)}}else{let i=new D(o.msg);return m.emit("OPERATION_FAILED",i),A(i)}}else{let o=new D("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),A(o)}},Wt=(t,e)=>{if(t.success)return t.j===0&&(k(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),m.emit("UPLOAD_STARTED")),k(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),m.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(k(e,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),_(void 0);{let r=new D(t.msg);return m.emit("OPERATION_FAILED",r),A(r)}},Ft=(t,e)=>{let r=Xt(t.data),n;if(r)if(!r.action&&r.msg){let o=new D(r.msg);return m.emit("OPERATION_FAILED",o),A(o)}else"delay"in r?n=Wt(r,e):n=Bt(r);else n=jt(t.data,e);return n},zt=t=>O!==void 0&&O[t]!==void 0&&O[t].readyState===WebSocket.CONNECTING,me=t=>O!==void 0&&O[t]!==void 0&&O[t].readyState===WebSocket.OPEN;var ye=(t,e)=>{let r;return t.password?r={part:e,file_pwd:t.password}:r={part:e},ve(nt(t),t,JSON.stringify(r))},Jt=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},ve(nt(t),t,JSON.stringify(e))};var ve=(t,e,r)=>me(t)?(O[t].onmessage=n=>Ft(n,e),O[t].send(r),_(void 0)):rt(t).andThen(()=>ve(t,e,r)),rt=(t,e=0)=>(!me(t)&&!zt(t)&&(O[t]=new WebSocket(t),m.once("SOCKET_OPERATION_TERMINATED",()=>{O[t].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),O[t].onopen=()=>{m.emit("SOCKET_OPENED")},O[t].onclose=()=>{},O[t].onerror=()=>++e<=tt?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${tt}`),rt(t,e)):(m.emit("SOCKET_ONERROR"),A(new z(`Unable to connect to WebSocket ${t}.`)))),qt(t).andThen(()=>_(t)).orElse(r=>A(r))),qt=t=>g.fromPromise(new Promise((e,r)=>{me(t)?e(void 0):(m.once("SOCKET_OPENED",()=>{e(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new z)}))}),e=>R(e));var $t=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,r},nt=t=>$t(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString();var Xt=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Gt=t=>typeof t=="object"&&t!==null&&!("msg"in t);var we=ue(it(),1);var H=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ee=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},st=t=>globalThis.DOMException===void 0?new Ee(t):new DOMException(t),at=t=>{let e=t.reason===void 0?st("This operation was aborted."):t.reason;return e instanceof Error?e:st(e)};function Ae(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((f,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:d}=e;d.aborted&&l(at(d));let p=()=>{l(at(d))};d.addEventListener("abort",p,{once:!0}),t.finally(()=>{d.removeEventListener("abort",p)})}if(r===Number.POSITIVE_INFINITY){t.then(f,l);return}let h=new H;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){l(d)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?f():o instanceof Error?l(o):(h.message=o??`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await t)}catch(d){l(d)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function xe(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Y=class{#e=[];enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let o=xe(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var V=class extends we.default{#e;#s;#i=0;#d;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#o;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Y,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#s=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#w(){return this.#s||this.#i{this.#x()},r)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#O;if(this.#w&&this.#E){let r=this.#t.dequeue();return r?(this.emit("active"),r(),e&&this.#v(),!0):!1}}return!1}#v(){this.#s||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#i===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#i=this.#e?this.#n:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#h()}async#L(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#i++;try{r.signal?.throwIfAborted();let i=e({signal:r.signal});r.timeout&&(i=Ae(Promise.resolve(i),{milliseconds:r.timeout})),r.signal&&(i=Promise.race([i,this.#L(r.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof H&&!r.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#A()}},r),this.emit("add"),this.#f()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#o?(this.#o=!1,this.#h(),this):this}pause(){this.#o=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#l("empty")}async onSizeLessThan(e){this.#t.sizethis.#t.size{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#o}};var Vt=[],Oe=8,se=new V({concurrency:Oe,autoStart:!1}),ae=0,ct=!1;self.onmessage=t=>{ct||(qe(),ct=!0);let e=t.data;m.once("DOWNLOAD_COMPLETE",()=>{self.postMessage({event:"DOWNLOAD_COMPLETE"})}),m.on("FILE_UPDATED",k),m.on("CHUNK_DOWNLOADED",(r,n)=>{self.postMessage({event:"CHUNK_DOWNLOADED",chunk:{buffer:r,index:n}})}),Qt(e).mapErr(r=>{Je(e.args.lufiFile,r)})};var Qt=t=>{let{lufiFile:e}=t.args;return m.on("CHUNK_DOWNLOADED",(r,n)=>{Vt[n]=r,ae--,ae{for(let r=1;r{await ye(e,r),ae++,ae===Oe&&se.pause()});se.start()}),ye(e,0)};export{Oe as QUEUE_CONCURRENCY_LIMIT,ae as itemsInQueue,se as queue}; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __typeError = (msg) => { + throw TypeError(msg); +}; +var __defNormalProp = (obj3, key, value) => key in obj3 ? __defProp(obj3, key, { enumerable: true, configurable: true, writable: true, value }) : obj3[key] = value; +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); +var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __publicField = (obj3, key, value) => __defNormalProp(obj3, typeof key !== "symbol" ? key + "" : key, value); +var __accessCheck = (obj3, member, msg) => member.has(obj3) || __typeError("Cannot " + msg); +var __privateGet = (obj3, member, getter) => (__accessCheck(obj3, member, "read from private field"), getter ? getter.call(obj3) : member.get(obj3)); +var __privateAdd = (obj3, member, value) => member.has(obj3) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj3) : member.set(obj3, value); +var __privateSet = (obj3, member, value, setter) => (__accessCheck(obj3, member, "write to private field"), setter ? setter.call(obj3, value) : member.set(obj3, value), value); +var __privateMethod = (obj3, member, method) => (__accessCheck(obj3, member, "access private method"), method); +var __privateWrapper = (obj3, member, setter, getter) => ({ + set _(value) { + __privateSet(obj3, member, value, setter); + }, + get _() { + return __privateGet(obj3, member, getter); + } +}); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter3() { + EventEmitter3.init.call(this); + } + module.exports = EventEmitter3; + module.exports.once = once; + EventEmitter3.EventEmitter = EventEmitter3; + EventEmitter3.prototype._events = void 0; + EventEmitter3.prototype._eventsCount = 0; + EventEmitter3.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter3, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter3.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter3.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter3.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter3.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter3.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events2 = this._events; + if (events2 !== void 0) + doError = doError && events2.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err2 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err2.context = er; + throw err2; + } + var handler = events2[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events2; + var existing; + checkListener(listener); + events2 = target._events; + if (events2 === void 0) { + events2 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events2.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events2 = target._events; + } + existing = events2[type]; + } + if (existing === void 0) { + existing = events2[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events2[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter3.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter3.prototype.on = EventEmitter3.prototype.addListener; + EventEmitter3.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter3.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter3.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter3.prototype.removeListener = function removeListener(type, listener) { + var list, events2, position, i, originalListener; + checkListener(listener); + events2 = this._events; + if (events2 === void 0) + return this; + list = events2[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events2[type]; + if (events2.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events2[type] = list[0]; + if (events2.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter3.prototype.off = EventEmitter3.prototype.removeListener; + EventEmitter3.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events2, i; + events2 = this._events; + if (events2 === void 0) + return this; + if (events2.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events2[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events2[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events2); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events2[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events2 = target._events; + if (events2 === void 0) + return []; + var evlistener = events2[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter3.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter3.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter3.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter3.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events2 = this._events; + if (events2 !== void 0) { + var evlistener = events2[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter3.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err2) { + emitter.removeListener(name, resolver); + reject(err2); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js +var require_sjcl = __commonJS({ + "node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js"(exports, module) { + "use strict"; + var sjcl2 = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function(a) { + this.toString = function() { + return "CORRUPT: " + this.message; + }; + this.message = a; + }, invalid: function(a) { + this.toString = function() { + return "INVALID: " + this.message; + }; + this.message = a; + }, bug: function(a) { + this.toString = function() { + return "BUG: " + this.message; + }; + this.message = a; + }, notReady: function(a) { + this.toString = function() { + return "NOT READY: " + this.message; + }; + this.message = a; + } } }; + sjcl2.cipher.aes = function(a) { + this.s[0][0][0] || this.O(); + var b, c, d, e, f = this.s[0][4], g = this.s[1]; + b = a.length; + var h = 1; + if (4 !== b && 6 !== b && 8 !== b) throw new sjcl2.exception.invalid("invalid aes key size"); + this.b = [d = a.slice(0), e = []]; + for (a = b; a < 4 * b + 28; a++) { + c = d[a - 1]; + if (0 === a % b || 8 === b && 4 === a % b) c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7)); + d[a] = d[a - b] ^ c; + } + for (b = 0; a; b++, a--) c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & 255]]; + }; + sjcl2.cipher.aes.prototype = { encrypt: function(a) { + return t(this, a, 0); + }, decrypt: function(a) { + return t(this, a, 1); + }, s: [[[], [], [], [], []], [[], [], [], [], []]], O: function() { + var a = this.s[0], b = this.s[1], c = a[4], d = b[4], e, f, g, h = [], k = [], l, n, m, p; + for (e = 0; 256 > e; e++) k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e; + for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, n = h[e = h[l = h[f]]], p = 16843009 * n ^ 65537 * e ^ 257 * l ^ 16843008 * f, n = 257 * h[m] ^ 16843008 * m, e = 0; 4 > e; e++) a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8; + for (e = 0; 5 > e; e++) a[e] = a[e].slice(0), b[e] = b[e].slice(0); + } }; + function t(a, b, c) { + if (4 !== b.length) throw new sjcl2.exception.invalid("invalid aes block size"); + var d = a.b[c], e = b[0] ^ d[0], f = b[c ? 3 : 1] ^ d[1], g = b[2] ^ d[2]; + b = b[c ? 1 : 3] ^ d[3]; + var h, k, l, n = d.length / 4 - 2, m, p = 4, r = [0, 0, 0, 0]; + h = a.s[c]; + a = h[0]; + var q = h[1], v = h[2], w = h[3], x = h[4]; + for (m = 0; m < n; m++) h = a[e >>> 24] ^ q[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ q[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], l = a[g >>> 24] ^ q[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ q[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = l; + for (m = 0; 4 > m; m++) r[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h; + return r; + } + sjcl2.bitArray = { bitSlice: function(a, b, c) { + a = sjcl2.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1); + return void 0 === c ? a : sjcl2.bitArray.clamp(a, c - b); + }, extract: function(a, b, c) { + var d = Math.floor(-b - c & 31); + return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1; + }, concat: function(a, b) { + if (0 === a.length || 0 === b.length) return a.concat(b); + var c = a[a.length - 1], d = sjcl2.bitArray.getPartial(c); + return 32 === d ? a.concat(b) : sjcl2.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1)); + }, bitLength: function(a) { + var b = a.length; + return 0 === b ? 0 : 32 * (b - 1) + sjcl2.bitArray.getPartial(a[b - 1]); + }, clamp: function(a, b) { + if (32 * a.length < b) return a; + a = a.slice(0, Math.ceil(b / 32)); + var c = a.length; + b = b & 31; + 0 < c && b && (a[c - 1] = sjcl2.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)); + return a; + }, partial: function(a, b, c) { + return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 1099511627776 * a; + }, getPartial: function(a) { + return Math.round(a / 1099511627776) || 32; + }, equal: function(a, b) { + if (sjcl2.bitArray.bitLength(a) !== sjcl2.bitArray.bitLength(b)) return false; + var c = 0, d; + for (d = 0; d < a.length; d++) c |= a[d] ^ b[d]; + return 0 === c; + }, $: function(a, b, c, d) { + var e; + e = 0; + for (void 0 === d && (d = []); 32 <= b; b -= 32) d.push(c), c = 0; + if (0 === b) return d.concat(a); + for (e = 0; e < a.length; e++) d.push(c | a[e] >>> b), c = a[e] << 32 - b; + e = a.length ? a[a.length - 1] : 0; + a = sjcl2.bitArray.getPartial(e); + d.push(sjcl2.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1)); + return d; + }, i: function(a, b) { + return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; + }, byteswapM: function(a) { + var b, c; + for (b = 0; b < a.length; ++b) c = a[b], a[b] = c >>> 24 | c >>> 8 & 65280 | (c & 65280) << 8 | c << 24; + return a; + } }; + sjcl2.codec.utf8String = { fromBits: function(a) { + var b = "", c = sjcl2.bitArray.bitLength(a), d, e; + for (d = 0; d < c / 8; d++) 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8; + return decodeURIComponent(escape(b)); + }, toBits: function(a) { + a = unescape(encodeURIComponent(a)); + var b = [], c, d = 0; + for (c = 0; c < a.length; c++) d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); + c & 3 && b.push(sjcl2.bitArray.partial(8 * (c & 3), d)); + return b; + } }; + sjcl2.codec.hex = { fromBits: function(a) { + var b = "", c; + for (c = 0; c < a.length; c++) b += ((a[c] | 0) + 263882790666240).toString(16).substr(4); + return b.substr(0, sjcl2.bitArray.bitLength(a) / 4); + }, toBits: function(a) { + var b, c = [], d; + a = a.replace(/\s|0x/g, ""); + d = a.length; + a = a + "00000000"; + for (b = 0; b < a.length; b += 8) c.push(parseInt(a.substr(b, 8), 16) ^ 0); + return sjcl2.bitArray.clamp(c, 4 * d); + } }; + sjcl2.codec.base32 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", X: "0123456789ABCDEFGHIJKLMNOPQRSTUV", BITS: 32, BASE: 5, REMAINING: 27, fromBits: function(a, b, c) { + var d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = "", g = 0, h = sjcl2.codec.base32.B, k = 0, l = sjcl2.bitArray.bitLength(a); + c && (h = sjcl2.codec.base32.X); + for (c = 0; f.length * d < l; ) f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d); + for (; f.length & 7 && !b; ) f += "="; + return f; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, "").toUpperCase(); + var c = sjcl2.codec.base32.BITS, d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = [], g, h = 0, k = sjcl2.codec.base32.B, l = 0, n, m = "base32"; + b && (k = sjcl2.codec.base32.X, m = "base32hex"); + for (g = 0; g < a.length; g++) { + n = k.indexOf(a.charAt(g)); + if (0 > n) { + if (!b) try { + return sjcl2.codec.base32hex.toBits(a); + } catch (p) { + } + throw new sjcl2.exception.invalid("this isn't " + m + "!"); + } + h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h); + } + h & 56 && f.push(sjcl2.bitArray.partial(h & 56, l, 1)); + return f; + } }; + sjcl2.codec.base32hex = { fromBits: function(a, b) { + return sjcl2.codec.base32.fromBits(a, b, 1); + }, toBits: function(a) { + return sjcl2.codec.base32.toBits(a, 1); + } }; + sjcl2.codec.base64 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", fromBits: function(a, b, c) { + var d = "", e = 0, f = sjcl2.codec.base64.B, g = 0, h = sjcl2.bitArray.bitLength(a); + c && (f = f.substr(0, 62) + "-_"); + for (c = 0; 6 * d.length < h; ) d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6); + for (; d.length & 3 && !b; ) d += "="; + return d; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, ""); + var c = [], d, e = 0, f = sjcl2.codec.base64.B, g = 0, h; + b && (f = f.substr(0, 62) + "-_"); + for (d = 0; d < a.length; d++) { + h = f.indexOf(a.charAt(d)); + if (0 > h) throw new sjcl2.exception.invalid("this isn't base64!"); + 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e); + } + e & 56 && c.push(sjcl2.bitArray.partial(e & 56, g, 1)); + return c; + } }; + sjcl2.codec.base64url = { fromBits: function(a) { + return sjcl2.codec.base64.fromBits(a, 1, 1); + }, toBits: function(a) { + return sjcl2.codec.base64.toBits(a, 1); + } }; + sjcl2.hash.sha256 = function(a) { + this.b[0] || this.O(); + a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset(); + }; + sjcl2.hash.sha256.hash = function(a) { + return new sjcl2.hash.sha256().update(a).finalize(); + }; + sjcl2.hash.sha256.prototype = { blockSize: 512, reset: function() { + this.F = this.Y.slice(0); + this.A = []; + this.l = 0; + return this; + }, update: function(a) { + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + var b, c = this.A = sjcl2.bitArray.concat(this.A, a); + b = this.l; + a = this.l = b + sjcl2.bitArray.bitLength(a); + if (9007199254740991 < a) throw new sjcl2.exception.invalid("Cannot hash more than 2^53 - 1 bits"); + if ("undefined" !== typeof Uint32Array) { + var d = new Uint32Array(c), e = 0; + for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, d.subarray( + 16 * e, + 16 * (e + 1) + )), e += 1; + c.splice(0, 16 * e); + } else for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, c.splice(0, 16)); + return this; + }, finalize: function() { + var a, b = this.A, c = this.F, b = sjcl2.bitArray.concat(b, [sjcl2.bitArray.partial(1, 1)]); + for (a = b.length + 2; a & 15; a++) b.push(0); + b.push(Math.floor(this.l / 4294967296)); + for (b.push(this.l | 0); b.length; ) u(this, b.splice(0, 16)); + this.reset(); + return c; + }, Y: [], b: [], O: function() { + function a(a2) { + return 4294967296 * (a2 - Math.floor(a2)) | 0; + } + for (var b = 0, c = 2, d, e; 64 > b; c++) { + e = true; + for (d = 2; d * d <= c; d++) if (0 === c % d) { + e = false; + break; + } + e && (8 > b && (this.Y[b] = a(Math.pow(c, 0.5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++); + } + } }; + function u(a, b) { + var c, d, e, f = a.F, g = a.b, h = f[0], k = f[1], l = f[2], n = f[3], m = f[4], p = f[5], r = f[6], q = f[7]; + for (c = 0; 64 > c; c++) 16 > c ? d = b[c] : (d = b[c + 1 & 15], e = b[c + 14 & 15], d = b[c & 15] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + b[c & 15] + b[c + 9 & 15] | 0), d = d + q + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (r ^ m & (p ^ r)) + g[c], q = r, r = p, p = m, m = n + d | 0, n = l, l = k, k = h, h = d + (k & l ^ n & (k ^ l)) + (k >>> 2 ^ k >>> 13 ^ k >>> 22 ^ k << 30 ^ k << 19 ^ k << 10) | 0; + f[0] = f[0] + h | 0; + f[1] = f[1] + k | 0; + f[2] = f[2] + l | 0; + f[3] = f[3] + n | 0; + f[4] = f[4] + m | 0; + f[5] = f[5] + p | 0; + f[6] = f[6] + r | 0; + f[7] = f[7] + q | 0; + } + sjcl2.mode.ccm = { name: "ccm", G: [], listenProgress: function(a) { + sjcl2.mode.ccm.G.push(a); + }, unListenProgress: function(a) { + a = sjcl2.mode.ccm.G.indexOf(a); + -1 < a && sjcl2.mode.ccm.G.splice(a, 1); + }, fa: function(a) { + var b = sjcl2.mode.ccm.G.slice(), c; + for (c = 0; c < b.length; c += 1) b[c](a); + }, encrypt: function(a, b, c, d, e) { + var f, g = b.slice(0), h = sjcl2.bitArray, k = h.bitLength(c) / 8, l = h.bitLength(g) / 8; + e = e || 64; + d = d || []; + if (7 > k) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (f = 2; 4 > f && l >>> 8 * f; f++) ; + f < 15 - k && (f = 15 - k); + c = h.clamp( + c, + 8 * (15 - f) + ); + b = sjcl2.mode.ccm.V(a, b, c, d, e, f); + g = sjcl2.mode.ccm.C(a, g, c, b, e, f); + return h.concat(g.data, g.tag); + }, decrypt: function(a, b, c, d, e) { + e = e || 64; + d = d || []; + var f = sjcl2.bitArray, g = f.bitLength(c) / 8, h = f.bitLength(b), k = f.clamp(b, h - e), l = f.bitSlice(b, h - e), h = (h - e) / 8; + if (7 > g) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (b = 2; 4 > b && h >>> 8 * b; b++) ; + b < 15 - g && (b = 15 - g); + c = f.clamp(c, 8 * (15 - b)); + k = sjcl2.mode.ccm.C(a, k, c, l, e, b); + a = sjcl2.mode.ccm.V(a, k.data, c, d, e, b); + if (!f.equal(k.tag, a)) throw new sjcl2.exception.corrupt("ccm: tag doesn't match"); + return k.data; + }, na: function(a, b, c, d, e, f) { + var g = [], h = sjcl2.bitArray, k = h.i; + d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)]; + d = h.concat(d, c); + d[3] |= e; + d = a.encrypt(d); + if (b.length) for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 4294967295 >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); + return d; + }, V: function(a, b, c, d, e, f) { + var g = sjcl2.bitArray, h = g.i; + e /= 8; + if (e % 2 || 4 > e || 16 < e) throw new sjcl2.exception.invalid("ccm: invalid tag length"); + if (4294967295 < d.length || 4294967295 < b.length) throw new sjcl2.exception.bug("ccm: can't deal with 4GiB or more data"); + c = sjcl2.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f); + for (d = 0; d < b.length; d += 4) c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); + return g.clamp(c, 8 * e); + }, C: function(a, b, c, d, e, f) { + var g, h = sjcl2.bitArray; + g = h.i; + var k = b.length, l = h.bitLength(b), n = k / 50, m = n; + c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4); + d = h.bitSlice(g(d, a.encrypt(c)), 0, e); + if (!k) return { tag: d, data: [] }; + for (g = 0; g < k; g += 4) g > n && (sjcl2.mode.ccm.fa(g / k), n += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3]; + return { tag: d, data: h.clamp(b, l) }; + } }; + sjcl2.mode.ocb2 = { name: "ocb2", encrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + var g, h = sjcl2.mode.ocb2.S, k = sjcl2.bitArray, l = k.i, n = [0, 0, 0, 0]; + c = h(a.encrypt(c)); + var m, p = []; + d = d || []; + e = e || 64; + for (g = 0; g + 4 < b.length; g += 4) m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c); + m = b.slice(g); + b = k.bitLength(m); + g = a.encrypt(l(c, [0, 0, 0, b])); + m = k.clamp(l(m.concat([0, 0, 0]), g), b); + n = l(n, l(m.concat([0, 0, 0]), g)); + n = a.encrypt(l(n, l(c, h(c)))); + d.length && (n = l(n, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + return p.concat(k.concat(m, k.clamp(n, e))); + }, decrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + e = e || 64; + var g = sjcl2.mode.ocb2.S, h = sjcl2.bitArray, k = h.i, l = [0, 0, 0, 0], n = g(a.encrypt(c)), m, p, r = sjcl2.bitArray.bitLength(b) - e, q = []; + d = d || []; + for (c = 0; c + 4 < r / 32; c += 4) m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n); + p = r - 32 * c; + m = a.encrypt(k(n, [0, 0, 0, p])); + m = k(m, h.clamp(b.slice(c), p).concat([ + 0, + 0, + 0 + ])); + l = k(l, m); + l = a.encrypt(k(l, k(n, g(n)))); + d.length && (l = k(l, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl2.exception.corrupt("ocb: tag doesn't match"); + return q.concat(h.clamp(m, p)); + }, pmac: function(a, b) { + var c, d = sjcl2.mode.ocb2.S, e = sjcl2.bitArray, f = e.i, g = [0, 0, 0, 0], h = a.encrypt([0, 0, 0, 0]), h = f(h, d(d(h))); + for (c = 0; c + 4 < b.length; c += 4) h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4)))); + c = b.slice(c); + 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0])); + g = f(g, c); + return a.encrypt(f(d(f(h, d(h))), g)); + }, S: function(a) { + return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)]; + } }; + sjcl2.mode.gcm = { name: "gcm", encrypt: function(a, b, c, d, e) { + var f = b.slice(0); + b = sjcl2.bitArray; + d = d || []; + a = sjcl2.mode.gcm.C(true, a, f, d, c, e || 128); + return b.concat(a.data, a.tag); + }, decrypt: function(a, b, c, d, e) { + var f = b.slice(0), g = sjcl2.bitArray, h = g.bitLength(f); + e = e || 128; + d = d || []; + e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []); + a = sjcl2.mode.gcm.C(false, a, f, d, c, e); + if (!g.equal(a.tag, b)) throw new sjcl2.exception.corrupt("gcm: tag doesn't match"); + return a.data; + }, ka: function(a, b) { + var c, d, e, f, g, h = sjcl2.bitArray.i; + e = [ + 0, + 0, + 0, + 0 + ]; + f = b.slice(0); + for (c = 0; 128 > c; c++) { + (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f)); + g = 0 !== (f[3] & 1); + for (d = 3; 0 < d; d--) f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31; + f[0] >>>= 1; + g && (f[0] ^= -520093696); + } + return e; + }, j: function(a, b, c) { + var d, e = c.length; + b = b.slice(0); + for (d = 0; d < e; d += 4) b[0] ^= 4294967295 & c[d], b[1] ^= 4294967295 & c[d + 1], b[2] ^= 4294967295 & c[d + 2], b[3] ^= 4294967295 & c[d + 3], b = sjcl2.mode.gcm.ka(b, a); + return b; + }, C: function(a, b, c, d, e, f) { + var g, h, k, l, n, m, p, r, q = sjcl2.bitArray; + m = c.length; + p = q.bitLength(c); + r = q.bitLength(d); + h = q.bitLength(e); + g = b.encrypt([0, 0, 0, 0]); + 96 === h ? (e = e.slice(0), e = q.concat(e, [1])) : (e = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], e), e = sjcl2.mode.gcm.j(g, e, [0, 0, Math.floor(h / 4294967296), h & 4294967295])); + h = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], d); + n = e.slice(0); + d = h.slice(0); + a || (d = sjcl2.mode.gcm.j(g, h, c)); + for (l = 0; l < m; l += 4) n[3]++, k = b.encrypt(n), c[l] ^= k[0], c[l + 1] ^= k[1], c[l + 2] ^= k[2], c[l + 3] ^= k[3]; + c = q.clamp(c, p); + a && (d = sjcl2.mode.gcm.j(g, h, c)); + a = [Math.floor(r / 4294967296), r & 4294967295, Math.floor(p / 4294967296), p & 4294967295]; + d = sjcl2.mode.gcm.j(g, d, a); + k = b.encrypt(e); + d[0] ^= k[0]; + d[1] ^= k[1]; + d[2] ^= k[2]; + d[3] ^= k[3]; + return { tag: q.bitSlice(d, 0, f), data: c }; + } }; + sjcl2.misc.hmac = function(a, b) { + this.W = b = b || sjcl2.hash.sha256; + var c = [[], []], d, e = b.prototype.blockSize / 32; + this.w = [new b(), new b()]; + a.length > e && (a = b.hash(a)); + for (d = 0; d < e; d++) c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828; + this.w[0].update(c[0]); + this.w[1].update(c[1]); + this.R = new b(this.w[0]); + }; + sjcl2.misc.hmac.prototype.encrypt = sjcl2.misc.hmac.prototype.mac = function(a) { + if (this.aa) throw new sjcl2.exception.invalid("encrypt on already updated hmac called!"); + this.update(a); + return this.digest(a); + }; + sjcl2.misc.hmac.prototype.reset = function() { + this.R = new this.W(this.w[0]); + this.aa = false; + }; + sjcl2.misc.hmac.prototype.update = function(a) { + this.aa = true; + this.R.update(a); + }; + sjcl2.misc.hmac.prototype.digest = function() { + var a = this.R.finalize(), a = new this.W(this.w[1]).update(a).finalize(); + this.reset(); + return a; + }; + sjcl2.misc.pbkdf2 = function(a, b, c, d, e) { + c = c || 1e4; + if (0 > d || 0 > c) throw new sjcl2.exception.invalid("invalid params to pbkdf2"); + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + e = e || sjcl2.misc.hmac; + a = new e(a); + var f, g, h, k, l = [], n = sjcl2.bitArray; + for (k = 1; 32 * l.length < (d || 1); k++) { + e = f = a.encrypt(n.concat(b, [k])); + for (g = 1; g < c; g++) for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h]; + l = l.concat(e); + } + d && (l = n.clamp(l, d)); + return l; + }; + sjcl2.prng = function(a) { + this.c = [new sjcl2.hash.sha256()]; + this.m = [0]; + this.P = 0; + this.H = {}; + this.N = 0; + this.U = {}; + this.Z = this.f = this.o = this.ha = 0; + this.b = [0, 0, 0, 0, 0, 0, 0, 0]; + this.h = [0, 0, 0, 0]; + this.L = void 0; + this.M = a; + this.D = false; + this.K = { progress: {}, seeded: {} }; + this.u = this.ga = 0; + this.I = 1; + this.J = 2; + this.ca = 65536; + this.T = [0, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024]; + this.da = 3e4; + this.ba = 80; + }; + sjcl2.prng.prototype = { + randomWords: function(a, b) { + var c = [], d; + d = this.isReady(b); + var e; + if (d === this.u) throw new sjcl2.exception.notReady("generator isn't seeded"); + if (d & this.J) { + d = !(d & this.I); + e = []; + var f = 0, g; + this.Z = e[0] = (/* @__PURE__ */ new Date()).valueOf() + this.da; + for (g = 0; 16 > g; g++) e.push(4294967296 * Math.random() | 0); + for (g = 0; g < this.c.length && (e = e.concat(this.c[g].finalize()), f += this.m[g], this.m[g] = 0, d || !(this.P & 1 << g)); g++) ; + this.P >= 1 << this.c.length && (this.c.push(new sjcl2.hash.sha256()), this.m.push(0)); + this.f -= f; + f > this.o && (this.o = f); + this.P++; + this.b = sjcl2.hash.sha256.hash(this.b.concat(e)); + this.L = new sjcl2.cipher.aes(this.b); + for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) ; + } + for (d = 0; d < a; d += 4) 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]); + y(this); + return c.slice(0, a); + }, + setDefaultParanoia: function(a, b) { + if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) throw new sjcl2.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); + this.M = a; + }, + addEntropy: function(a, b, c) { + c = c || "user"; + var d, e, f = (/* @__PURE__ */ new Date()).valueOf(), g = this.H[c], h = this.isReady(), k = 0; + d = this.U[c]; + void 0 === d && (d = this.U[c] = this.ha++); + void 0 === g && (g = this.H[c] = 0); + this.H[c] = (this.H[c] + 1) % this.c.length; + switch (typeof a) { + case "number": + void 0 === b && (b = 1); + this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]); + break; + case "object": + c = Object.prototype.toString.call(a); + if ("[object Uint32Array]" === c) { + e = []; + for (c = 0; c < a.length; c++) e.push(a[c]); + a = e; + } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) "number" !== typeof a[c] && (k = 1); + if (!k) { + if (void 0 === b) for (c = b = 0; c < a.length; c++) for (e = a[c]; 0 < e; ) b++, e = e >>> 1; + this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a)); + } + break; + case "string": + void 0 === b && (b = a.length); + this.c[g].update([d, this.N++, 3, b, f, a.length]); + this.c[g].update(a); + break; + default: + k = 1; + } + if (k) throw new sjcl2.exception.bug("random: addEntropy only supports number, array of numbers or string"); + this.m[g] += b; + this.f += b; + h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress())); + }, + isReady: function(a) { + a = this.T[void 0 !== a ? a : this.M]; + return this.o && this.o >= a ? this.m[0] > this.ba && (/* @__PURE__ */ new Date()).valueOf() > this.Z ? this.J | this.I : this.I : this.f >= a ? this.J | this.u : this.u; + }, + getProgress: function(a) { + a = this.T[a ? a : this.M]; + return this.o >= a ? 1 : this.f > a ? 1 : this.f / a; + }, + startCollectors: function() { + if (!this.D) { + this.a = { loadTimeCollector: B(this, this.ma), mouseCollector: B(this, this.oa), keyboardCollector: B(this, this.la), accelerometerCollector: B(this, this.ea), touchCollector: B(this, this.qa) }; + if (window.addEventListener) window.addEventListener( + "load", + this.a.loadTimeCollector, + false + ), window.addEventListener("mousemove", this.a.mouseCollector, false), window.addEventListener("keypress", this.a.keyboardCollector, false), window.addEventListener("devicemotion", this.a.accelerometerCollector, false), window.addEventListener("touchmove", this.a.touchCollector, false); + 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 sjcl2.exception.bug("can't attach event"); + this.D = true; + } + }, + stopCollectors: function() { + this.D && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, false), window.removeEventListener("mousemove", this.a.mouseCollector, false), window.removeEventListener("keypress", this.a.keyboardCollector, false), window.removeEventListener("devicemotion", this.a.accelerometerCollector, false), window.removeEventListener("touchmove", this.a.touchCollector, false)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent( + "onmousemove", + this.a.mouseCollector + ), document.detachEvent("keypress", this.a.keyboardCollector)), this.D = false); + }, + addEventListener: function(a, b) { + this.K[a][this.ga++] = b; + }, + removeEventListener: function(a, b) { + var c, d, e = this.K[a], f = []; + for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d); + for (c = 0; c < f.length; c++) d = f[c], delete e[d]; + }, + la: function() { + C(this, 1); + }, + oa: function(a) { + var b, c; + try { + b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0; + } catch (d) { + c = b = 0; + } + 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); + C(this, 0); + }, + qa: function(a) { + a = a.touches[0] || a.changedTouches[0]; + this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); + C(this, 0); + }, + ma: function() { + C(this, 2); + }, + ea: function(a) { + a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; + if (window.orientation) { + var b = window.orientation; + "number" === typeof b && this.addEntropy(b, 1, "accelerometer"); + } + a && this.addEntropy(a, 2, "accelerometer"); + C(this, 0); + } + }; + function A(a, b) { + var c, d = sjcl2.random.K[a], e = []; + for (c in d) d.hasOwnProperty(c) && e.push(d[c]); + for (c = 0; c < e.length; c++) e[c](b); + } + function C(a, b) { + "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy((/* @__PURE__ */ new Date()).valueOf(), b, "loadtime"); + } + function y(a) { + a.b = z(a).concat(z(a)); + a.L = new sjcl2.cipher.aes(a.b); + } + function z(a) { + for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) ; + return a.L.encrypt(a.h); + } + function B(a, b) { + return function() { + b.apply(a, arguments); + }; + } + sjcl2.random = new sjcl2.prng(6); + a: try { + if (G = "undefined" !== typeof module && module.exports) { + try { + H = __require("crypto"); + } catch (a) { + H = null; + } + G = E = H; + } + if (G && E.randomBytes) D = E.randomBytes(128), D = new Uint32Array(new Uint8Array(D).buffer), sjcl2.random.addEntropy(D, 1024, "crypto['randomBytes']"); + else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { + F = new Uint32Array(32); + if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F); + else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F); + else break a; + sjcl2.random.addEntropy(F, 1024, "crypto['getRandomValues']"); + } + } catch (a) { + "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a)); + } + var D; + var E; + var F; + var G; + var H; + sjcl2.json = { defaults: { v: 1, iter: 1e4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, ja: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json, f = e.g({ iv: sjcl2.random.randomWords(4, 0) }, e.defaults), g; + e.g(f, c); + c = f.adata; + "string" === typeof f.salt && (f.salt = sjcl2.codec.base64.toBits(f.salt)); + "string" === typeof f.iv && (f.iv = sjcl2.codec.base64.toBits(f.iv)); + if (!sjcl2.mode[f.mode] || !sjcl2.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 256 !== f.ks || 2 > f.iv.length || 4 < f.iv.length) throw new sjcl2.exception.invalid("json encrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + "string" === typeof c && (f.adata = c = sjcl2.codec.utf8String.toBits(c)); + g = new sjcl2.cipher[f.cipher](a); + e.g(d, f); + d.key = a; + f.ct = "ccm" === f.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl2.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); + return f; + }, encrypt: function(a, b, c, d) { + var e = sjcl2.json, f = e.ja.apply(e, arguments); + return e.encode(f); + }, ia: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json; + b = e.g(e.g(e.g({}, e.defaults), b), c, true); + var f, g; + f = b.adata; + "string" === typeof b.salt && (b.salt = sjcl2.codec.base64.toBits(b.salt)); + "string" === typeof b.iv && (b.iv = sjcl2.codec.base64.toBits(b.iv)); + if (!sjcl2.mode[b.mode] || !sjcl2.cipher[b.cipher] || "string" === typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 256 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) throw new sjcl2.exception.invalid("json decrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.secretKey && (a = a.unkem(sjcl2.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); + "string" === typeof f && (f = sjcl2.codec.utf8String.toBits(f)); + g = new sjcl2.cipher[b.cipher](a); + f = "ccm" === b.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl2.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); + e.g(d, b); + d.key = a; + return 1 === c.raw ? f : sjcl2.codec.utf8String.fromBits(f); + }, decrypt: function(a, b, c, d) { + var e = sjcl2.json; + return e.ia(a, e.decode(b), c, d); + }, encode: function(a) { + var b, c = "{", d = ""; + for (b in a) if (a.hasOwnProperty(b)) { + if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl2.exception.invalid("json encode: invalid property name"); + c += d + '"' + b + '":'; + d = ","; + switch (typeof a[b]) { + case "number": + case "boolean": + c += a[b]; + break; + case "string": + c += '"' + escape(a[b]) + '"'; + break; + case "object": + c += '"' + sjcl2.codec.base64.fromBits(a[b], 0) + '"'; + break; + default: + throw new sjcl2.exception.bug("json encode: unsupported type"); + } + } + return c + "}"; + }, decode: function(a) { + a = a.replace(/\s/g, ""); + if (!a.match(/^\{.*\}$/)) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + a = a.replace(/^\{|\}$/g, "").split(/,/); + var b = {}, c, d; + for (c = 0; c < a.length; c++) { + if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl2.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]); + } + return b; + }, g: function(a, b, c) { + void 0 === a && (a = {}); + if (void 0 === b) return a; + for (var d in b) if (b.hasOwnProperty(d)) { + if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl2.exception.invalid("required parameter overridden"); + a[d] = b[d]; + } + return a; + }, sa: function(a, b) { + var c = {}, d; + for (d in a) a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); + return c; + }, ra: function(a, b) { + var c = {}, d; + for (d = 0; d < b.length; d++) void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); + return c; + } }; + sjcl2.encrypt = sjcl2.json.encrypt; + sjcl2.decrypt = sjcl2.json.decrypt; + sjcl2.misc.pa = {}; + sjcl2.misc.cachedPbkdf2 = function(a, b) { + var c = sjcl2.misc.pa, d; + b = b || {}; + d = b.iter || 1e3; + c = c[a] = c[a] || {}; + d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl2.random.randomWords(2, 0) }; + c = void 0 === b.salt ? d.firstSalt : b.salt; + d[c] = d[c] || sjcl2.misc.pbkdf2(a, c, b.iter); + return { key: d[c].slice(0), salt: c.slice(0) }; + }; + "undefined" !== typeof module && module.exports && (module.exports = sjcl2); + "function" === typeof define && define([], function() { + return sjcl2; + }); + } +}); + +// node_modules/.deno/eventemitter3@5.0.1/node_modules/eventemitter3/index.js +var require_eventemitter3 = __commonJS({ + "node_modules/.deno/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) { + "use strict"; + var has = Object.prototype.hasOwnProperty; + var prefix = "~"; + function Events() { + } + if (Object.create) { + Events.prototype = /* @__PURE__ */ Object.create(null); + if (!new Events().__proto__) prefix = false; + } + function EE(fn, context, once) { + this.fn = fn; + this.context = context; + this.once = once || false; + } + function addListener(emitter, event, fn, context, once) { + if (typeof fn !== "function") { + throw new TypeError("The listener must be a function"); + } + var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event; + if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; + else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); + else emitter._events[evt] = [emitter._events[evt], listener]; + return emitter; + } + function clearEvent(emitter, evt) { + if (--emitter._eventsCount === 0) emitter._events = new Events(); + else delete emitter._events[evt]; + } + function EventEmitter3() { + this._events = new Events(); + this._eventsCount = 0; + } + EventEmitter3.prototype.eventNames = function eventNames() { + var names = [], events2, name; + if (this._eventsCount === 0) return names; + for (name in events2 = this._events) { + if (has.call(events2, name)) names.push(prefix ? name.slice(1) : name); + } + if (Object.getOwnPropertySymbols) { + return names.concat(Object.getOwnPropertySymbols(events2)); + } + return names; + }; + EventEmitter3.prototype.listeners = function listeners(event) { + var evt = prefix ? prefix + event : event, handlers = this._events[evt]; + if (!handlers) return []; + if (handlers.fn) return [handlers.fn]; + for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { + ee[i] = handlers[i].fn; + } + return ee; + }; + EventEmitter3.prototype.listenerCount = function listenerCount(event) { + var evt = prefix ? prefix + event : event, listeners = this._events[evt]; + if (!listeners) return 0; + if (listeners.fn) return 1; + return listeners.length; + }; + EventEmitter3.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { + var evt = prefix ? prefix + event : event; + if (!this._events[evt]) return false; + var listeners = this._events[evt], len = arguments.length, args, i; + if (listeners.fn) { + if (listeners.once) this.removeListener(event, listeners.fn, void 0, true); + switch (len) { + case 1: + return listeners.fn.call(listeners.context), true; + case 2: + return listeners.fn.call(listeners.context, a1), true; + case 3: + return listeners.fn.call(listeners.context, a1, a2), true; + case 4: + return listeners.fn.call(listeners.context, a1, a2, a3), true; + case 5: + return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; + case 6: + return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; + } + for (i = 1, args = new Array(len - 1); i < len; i++) { + args[i - 1] = arguments[i]; + } + listeners.fn.apply(listeners.context, args); + } else { + var length = listeners.length, j; + for (i = 0; i < length; i++) { + if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true); + switch (len) { + case 1: + listeners[i].fn.call(listeners[i].context); + break; + case 2: + listeners[i].fn.call(listeners[i].context, a1); + break; + case 3: + listeners[i].fn.call(listeners[i].context, a1, a2); + break; + case 4: + listeners[i].fn.call(listeners[i].context, a1, a2, a3); + break; + default: + if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) { + args[j - 1] = arguments[j]; + } + listeners[i].fn.apply(listeners[i].context, args); + } + } + } + return true; + }; + EventEmitter3.prototype.on = function on(event, fn, context) { + return addListener(this, event, fn, context, false); + }; + EventEmitter3.prototype.once = function once(event, fn, context) { + return addListener(this, event, fn, context, true); + }; + EventEmitter3.prototype.removeListener = function removeListener(event, fn, context, once) { + var evt = prefix ? prefix + event : event; + if (!this._events[evt]) return this; + if (!fn) { + clearEvent(this, evt); + return this; + } + var listeners = this._events[evt]; + if (listeners.fn) { + if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) { + clearEvent(this, evt); + } + } else { + for (var i = 0, events2 = [], length = listeners.length; i < length; i++) { + if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) { + events2.push(listeners[i]); + } + } + if (events2.length) this._events[evt] = events2.length === 1 ? events2[0] : events2; + else clearEvent(this, evt); + } + return this; + }; + EventEmitter3.prototype.removeAllListeners = function removeAllListeners(event) { + var evt; + if (event) { + evt = prefix ? prefix + event : event; + if (this._events[evt]) clearEvent(this, evt); + } else { + this._events = new Events(); + this._eventsCount = 0; + } + return this; + }; + EventEmitter3.prototype.off = EventEmitter3.prototype.removeListener; + EventEmitter3.prototype.addListener = EventEmitter3.prototype.on; + EventEmitter3.prefixed = prefix; + EventEmitter3.EventEmitter = EventEmitter3; + if ("undefined" !== typeof module) { + module.exports = EventEmitter3; + } + } +}); + +// src/worker/main.ts +var import_events = __toESM(require_events()); + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var okAsync = (value) => new ResultAsync(Promise.resolve(new Ok(value))); +var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result2) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result2.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result2.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result2.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err2) { + return new Err(err2); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err2) { + return err2(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/error/base-error.ts +var BaseError = class extends Error { + constructor(message, options = {}) { + const { cause, context } = options; + super(message, { cause }); + __publicField(this, "context"); + this.name = this.constructor.name; + this.context = context; + } +}; + +// src/utils.ts +var ensureError = (value) => { + if (value instanceof Error) return value; + let stringified = "[Unable to stringify the thrown value]"; + try { + stringified = JSON.stringify(value); + } catch (_error) { + } + const error = new Error(stringified); + return error; +}; +var isDenoRuntime = () => typeof Deno !== "undefined"; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); + +// src/worker/main.ts +var events = new import_events.default(); +var worker; +var isInitialized = false; +self.onmessage = (event) => { + addWorker(event); + if (!isInitialized) { + isInitialized = true; + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + if (worker) { + worker.terminate(); + } + }); + } +}; +var updateFile = (lufiFile, args) => { + Object.assign(lufiFile, args); + if (typeof WorkerGlobalScope !== "undefined") { + self.postMessage({ + event: "FILE_UPDATED" /* FILE_UPDATED */, + lufiFile + }); + } + return lufiFile; +}; +var sendFileError = (lufiFile, error) => { + updateFile(lufiFile, { uploadStatus: 2 /* FAILED */ }); + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); +}; +var addWorker = (event, callback) => { + const { action } = event.data; + if (action === 5 /* PAUSE */ || action === 8 /* RESUME */) { + worker.postMessage(event.data); + } else { + switch (action) { + case 2 /* CANCEL */: + { + worker = new Worker(workerUrl("cancel"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 3 /* DOWNLOAD */: + { + worker = new Worker(workerUrl("download"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 4 /* INFOS */: + { + worker = new Worker(workerUrl("infos"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 7 /* REMOVE */: + { + worker = worker || new Worker(workerUrl("remove"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 9 /* UPLOAD */: + { + worker = worker || new Worker(workerUrl("upload"), { type: "module" }); + worker.postMessage(event.data); + } + break; + default: { + console.error("Action not found"); + } + } + worker.onmessage = (e) => { + if (callback) callback(e); + self.postMessage(e.data); + }; + worker.onerror = (error) => { + console.error(`Error: ${error.message}`); + }; + } +}; +var init = () => { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + self.postMessage({ + event: "SOCKET_OPENED" /* SOCKET_OPENED */ + }); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); + }); +}; + +// src/error/websocket/websocket-error.ts +var WebSocketError = class extends BaseError { +}; + +// src/error/websocket/websocket-connection-error.ts +var WebSocketConnectionError = class extends WebSocketError { + constructor() { + super(...arguments); + __publicField(this, "message", "An error occured while trying to connect to WebSocket"); + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/encoding.js +var Encoding = class { + /** + * + * @param charset Charset to use for base64 encoding. This must be 64-characters long. + * @param noPadding If true, encoded strings won't include padding. + */ + constructor(charset, noPadding) { + if (!charset || charset.length != 64) { + throw Error("Charset must contain 64 characters"); + } + this._charset = charset; + this._noPadding = !!noPadding; + this._valid = new RegExp("^[" + this._charset.replace("-", "\\-") + "]+={0,2}$"); + } + /** + * Encode an ArrayBuffer to base64 in a string. + * @param ab Data to encode to base64 + * @returns Base64-encoded string + */ + Encode(ab) { + const len = ab.byteLength; + if (!len) { + return ""; + } + const view = new Uint8Array(ab); + let res = ""; + for (let i = 0; i < len; i += 3) { + res += this._charset[view[i] >> 2] + this._charset[(view[i] & 3) << 4 | view[i + 1] >> 4] + this._charset[(view[i + 1] & 15) << 2 | view[i + 2] >> 6] + this._charset[view[i + 2] & 63]; + } + if (len % 3 == 2) { + res = res.substring(0, res.length - 1); + if (!this._noPadding) { + res += "="; + } + } else if (len % 3 == 1) { + res = res.substring(0, res.length - 2); + if (!this._noPadding) { + res += "=="; + } + } + return res; + } + /** + * Decode a string from base64. Padding is always optional. + * @param str Base64-encoded string + * @returns Data decoded from the base64 string + */ + Decode(str) { + str = (str || "").replace(/[\s]/g, ""); + if (!str) { + return new ArrayBuffer(0); + } + if (!this._valid.test(str)) { + throw Error("Invalid base64 input sequence"); + } + let viewLen = Math.floor(str.length * 0.75); + if (str[str.length - 2] == "=") { + viewLen -= 2; + } else if (str[str.length - 1] == "=") { + viewLen--; + } + const view = new Uint8Array(viewLen); + let enc1, enc2, enc3, enc4, i = 0, j = 0; + while (i < str.length * 0.75) { + enc1 = this._charset.indexOf(str.charAt(j++)); + enc2 = this._charset.indexOf(str.charAt(j++)); + enc3 = this._charset.indexOf(str.charAt(j++)); + enc4 = this._charset.indexOf(str.charAt(j++)); + view[i++] = enc1 << 2 | enc2 >> 4; + view[i++] = (enc2 & 15) << 4 | enc3 >> 2; + view[i++] = (enc3 & 3) << 6 | enc4; + } + return view.buffer; + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/standard.js +var obj = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +function Decode(str) { + return obj.Decode(str); +} + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/url.js +var obj2 = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", true); +function Decode2(str) { + return obj2.Decode(str); +} + +// src/api/crypto/sjcl.ts +var import_sjcl = __toESM(require_sjcl()); + +// src/error/crypto/crypto-error.ts +var CryptoError = class extends BaseError { +}; + +// src/error/crypto/decryption-error.ts +var DecryptionError = class extends CryptoError { + constructor() { + super(...arguments); + __publicField(this, "message", "Unable to decrypt the provided data"); + } +}; + +// src/api/crypto/sjcl.ts +var decrypt = (key, encryptedData) => { + try { + const data = typeof encryptedData === "string" ? encryptedData : encryptedData.data; + return okAsync(Decode(import_sjcl.default.decrypt(key, data))); + } catch (error) { + return errAsync( + new DecryptionError(void 0, { cause: ensureError(error) }) + ); + } +}; + +// src/api/crypto/web.ts +var decrypt2 = (key, encrypted) => { + return importKey(key).andThen( + (importedKey) => ResultAsync.fromPromise( + crypto.subtle.decrypt( + { + name: "AES-GCM", + iv: encrypted.iv + }, + importedKey, + Decode(encrypted.data) + ), + (error) => new DecryptionError(void 0, { cause: ensureError(error) }) + ) + ); +}; +var importKey = (key) => { + return ResultAsync.fromPromise( + crypto.subtle.importKey( + "raw", + Decode2(key), + { name: "AES-GCM" }, + false, + [ + "encrypt", + "decrypt" + ] + ), + (error) => new CryptoError("Unable to import cryptography key", { + cause: ensureError(error) + }) + ); +}; + +// src/api/crypto.ts +var decrypt3 = (key, value) => { + return value.algo === void 0 || value.algo === 0 /* Sjcl */ ? decrypt(key, value) : decrypt2(key, value); +}; + +// src/api/websocket.ts +var sockets = {}; +var MAX_ERRORS = 5; +var onCancelMessage = (data) => { + events.emit("UPLOAD_CANCELLED" /* UPLOAD_CANCELLED */, data.success); + return okAsync(void 0); +}; +var onDownloadMessage = (response, lufiFile) => { + const result = response.split("XXMOJOXX"); + const metadataString = result.shift(); + if (metadataString !== void 0) { + const metadata = JSON.parse(metadataString); + if (isServerDownloadChunkSuccessMetadata(metadata)) { + const dataString = result.shift(); + if (dataString) { + const encryptedData = JSON.parse(dataString); + if (encryptedData.iv) { + encryptedData.iv = new Uint8Array(Object.values(encryptedData.iv)); + } + return decrypt3(lufiFile.keys.client, encryptedData).andThen( + (decryptedPart) => { + const chunk = typeof decryptedPart === "string" ? new TextEncoder().encode(decryptedPart).buffer : decryptedPart; + if (metadata.part === 0) { + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + delAtFirstView: metadata.del_at_first_view, + delay: metadata.delay, + name: metadata.name, + size: metadata.size, + totalChunks: metadata.total, + type: metadata.type, + zipped: metadata.zipped + }); + events.emit("DOWNLOAD_STARTED" /* DOWNLOAD_STARTED */); + } else { + updateFile(lufiFile, { chunksReady: lufiFile.chunksReady + 1 }); + } + events.emit("CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, chunk, metadata.part); + if (++metadata.part === metadata.total) { + return endDownload(lufiFile).andThen(() => { + events.emit("DOWNLOAD_COMPLETE" /* DOWNLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + return okAsync(void 0); + }); + } + return okAsync(void 0); + } + ); + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError(metadata.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onUploadMessage = (response, lufiFile) => { + if (response.success) { + if (response.j === 0) { + updateFile(lufiFile, { + keys: { client: lufiFile.keys.client, server: response.short }, + actionToken: response.token, + queueIndex: response.i + }); + events.emit("UPLOAD_STARTED" /* UPLOAD_STARTED */); + } + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + createdAt: response.created_at + }); + events.emit("CHUNK_UPLOADED" /* CHUNK_UPLOADED */); + if (lufiFile.chunksReady === lufiFile.totalChunks) { + updateFile(lufiFile, { uploadStatus: 1 /* COMPLETE */ }); + events.emit("UPLOAD_COMPLETE" /* UPLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + } + return okAsync(void 0); + } else { + const error = new WebSocketError(response.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onMessage = (e, lufiFile) => { + const data = tryParseJson(e.data); + let callback; + if (data) { + if (!data.action && data.msg) { + const error = new WebSocketError(data.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } else { + if ("delay" in data) { + callback = onUploadMessage(data, lufiFile); + } else { + callback = onCancelMessage(data); + } + } + } else { + callback = onDownloadMessage(e.data, lufiFile); + } + return callback; +}; +var isConnecting = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.CONNECTING; +var isSpawned = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.OPEN; +var downloadChunk = (lufiFile, chunkNumber) => { + let message; + if (lufiFile.password) { + message = { part: chunkNumber, file_pwd: lufiFile.password }; + } else { + message = { part: chunkNumber }; + } + return sendMessage( + downloadSocketUrl(lufiFile), + lufiFile, + JSON.stringify(message) + ); +}; +var endDownload = (lufiFile) => { + let message; + if (lufiFile.password) { + message = { ended: true, file_pwd: lufiFile.password }; + } else { + message = { ended: true }; + } + return sendMessage( + downloadSocketUrl(lufiFile), + lufiFile, + JSON.stringify(message) + ); +}; +var sendMessage = (socketUrl, lufiFile, message) => { + if (!isSpawned(socketUrl)) { + return spawn(socketUrl).andThen( + () => sendMessage(socketUrl, lufiFile, message) + ); + } else { + sockets[socketUrl].onmessage = (e) => onMessage(e, lufiFile); + sockets[socketUrl].send(message); + return okAsync(void 0); + } +}; +var spawn = (socketKey, errorCount = 0) => { + if (!isSpawned(socketKey) && !isConnecting(socketKey)) { + sockets[socketKey] = new WebSocket(socketKey); + events.once("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */, () => { + sockets[socketKey].close(); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + }); + sockets[socketKey].onopen = () => { + events.emit("SOCKET_OPENED" /* SOCKET_OPENED */); + }; + sockets[socketKey].onclose = () => { + }; + sockets[socketKey].onerror = () => { + if (++errorCount <= MAX_ERRORS) { + console.error( + `An error happened while trying to connect to WebSocket ${socketKey}. Trying again. ${errorCount} / ${MAX_ERRORS}` + ); + return spawn(socketKey, errorCount); + } else { + events.emit("SOCKET_ONERROR" /* SOCKET_ONERROR */); + return errAsync( + new WebSocketConnectionError( + `Unable to connect to WebSocket ${socketKey}.` + ) + ); + } + }; + } + return waitForConnection(socketKey).andThen(() => okAsync(socketKey)).orElse((error) => errAsync(error)); +}; +var waitForConnection = (socketKey) => ResultAsync.fromPromise( + new Promise((resolve, reject) => { + if (!isSpawned(socketKey)) { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + resolve(void 0); + }); + events.on("SOCKET_ONERROR" /* SOCKET_ONERROR */, () => { + reject(new WebSocketConnectionError()); + }); + } else { + resolve(void 0); + } + }), + (error) => { + return ensureError(error); + } +); +var buildSocketUrl = (instanceUrl, pathname) => { + const url = new URL(instanceUrl); + url.protocol = url.protocol === "http:" ? "ws:" : "wss:"; + url.pathname += pathname; + return new URL(url.origin + url.pathname); +}; +var downloadSocketUrl = (lufiFile) => { + return buildSocketUrl( + new URL(lufiFile.serverUrl), + "download" /* DOWNLOAD */ + `/${lufiFile.keys.server}` + ).toString(); +}; +var tryParseJson = (data) => { + try { + const parsedObject = JSON.parse(data); + if (parsedObject && typeof parsedObject === "object") { + return parsedObject; + } + } catch (_e) { + } + return false; +}; +var isServerDownloadChunkSuccessMetadata = (message) => { + return typeof message === "object" && message !== null && !("msg" in message); +}; + +// node_modules/.deno/eventemitter3@5.0.1/node_modules/eventemitter3/index.mjs +var import_index = __toESM(require_eventemitter3(), 1); + +// node_modules/.deno/p-timeout@6.1.3/node_modules/p-timeout/index.js +var TimeoutError = class extends Error { + constructor(message) { + super(message); + this.name = "TimeoutError"; + } +}; +var AbortError = class extends Error { + constructor(message) { + super(); + this.name = "AbortError"; + this.message = message; + } +}; +var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new AbortError(errorMessage) : new DOMException(errorMessage); +var getAbortedReason = (signal) => { + const reason = signal.reason === void 0 ? getDOMException("This operation was aborted.") : signal.reason; + return reason instanceof Error ? reason : getDOMException(reason); +}; +function pTimeout(promise, options) { + const { + milliseconds, + fallback, + message, + customTimers = { setTimeout, clearTimeout } + } = options; + let timer; + const wrappedPromise = new Promise((resolve, reject) => { + if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) { + throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``); + } + if (options.signal) { + const { signal } = options; + if (signal.aborted) { + reject(getAbortedReason(signal)); + } + const abortHandler = () => { + reject(getAbortedReason(signal)); + }; + signal.addEventListener("abort", abortHandler, { once: true }); + promise.finally(() => { + signal.removeEventListener("abort", abortHandler); + }); + } + if (milliseconds === Number.POSITIVE_INFINITY) { + promise.then(resolve, reject); + return; + } + const timeoutError = new TimeoutError(); + timer = customTimers.setTimeout.call(void 0, () => { + if (fallback) { + try { + resolve(fallback()); + } catch (error) { + reject(error); + } + return; + } + if (typeof promise.cancel === "function") { + promise.cancel(); + } + if (message === false) { + resolve(); + } else if (message instanceof Error) { + reject(message); + } else { + timeoutError.message = message != null ? message : `Promise timed out after ${milliseconds} milliseconds`; + reject(timeoutError); + } + }, milliseconds); + (async () => { + try { + resolve(await promise); + } catch (error) { + reject(error); + } + })(); + }); + const cancelablePromise = wrappedPromise.finally(() => { + cancelablePromise.clear(); + }); + cancelablePromise.clear = () => { + customTimers.clearTimeout.call(void 0, timer); + timer = void 0; + }; + return cancelablePromise; +} + +// node_modules/.deno/p-queue@8.0.1/node_modules/p-queue/dist/lower-bound.js +function lowerBound(array, value, comparator) { + let first = 0; + let count = array.length; + while (count > 0) { + const step = Math.trunc(count / 2); + let it = first + step; + if (comparator(array[it], value) <= 0) { + first = ++it; + count -= step + 1; + } else { + count = step; + } + } + return first; +} + +// node_modules/.deno/p-queue@8.0.1/node_modules/p-queue/dist/priority-queue.js +var _queue; +var PriorityQueue = class { + constructor() { + __privateAdd(this, _queue, []); + } + enqueue(run, options) { + options = { + priority: 0, + ...options + }; + const element = { + priority: options.priority, + run + }; + if (this.size && __privateGet(this, _queue)[this.size - 1].priority >= options.priority) { + __privateGet(this, _queue).push(element); + return; + } + const index = lowerBound(__privateGet(this, _queue), element, (a, b) => b.priority - a.priority); + __privateGet(this, _queue).splice(index, 0, element); + } + dequeue() { + const item = __privateGet(this, _queue).shift(); + return item == null ? void 0 : item.run; + } + filter(options) { + return __privateGet(this, _queue).filter((element) => element.priority === options.priority).map((element) => element.run); + } + get size() { + return __privateGet(this, _queue).length; + } +}; +_queue = new WeakMap(); + +// node_modules/.deno/p-queue@8.0.1/node_modules/p-queue/dist/index.js +var _carryoverConcurrencyCount, _isIntervalIgnored, _intervalCount, _intervalCap, _interval, _intervalEnd, _intervalId, _timeoutId, _queue2, _queueClass, _pending, _concurrency, _isPaused, _throwOnTimeout, _PQueue_instances, doesIntervalAllowAnother_get, doesConcurrentAllowAnother_get, next_fn, onResumeInterval_fn, isIntervalPaused_get, tryToStartAnother_fn, initializeIntervalIfNeeded_fn, onInterval_fn, processQueue_fn, throwOnAbort_fn, onEvent_fn; +var PQueue = class extends import_index.default { + // TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()` + constructor(options) { + var _a, _b, _c, _d; + super(); + __privateAdd(this, _PQueue_instances); + __privateAdd(this, _carryoverConcurrencyCount); + __privateAdd(this, _isIntervalIgnored); + __privateAdd(this, _intervalCount, 0); + __privateAdd(this, _intervalCap); + __privateAdd(this, _interval); + __privateAdd(this, _intervalEnd, 0); + __privateAdd(this, _intervalId); + __privateAdd(this, _timeoutId); + __privateAdd(this, _queue2); + __privateAdd(this, _queueClass); + __privateAdd(this, _pending, 0); + // The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194 + __privateAdd(this, _concurrency); + __privateAdd(this, _isPaused); + __privateAdd(this, _throwOnTimeout); + /** + Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already. + + Applies to each future operation. + */ + __publicField(this, "timeout"); + options = { + carryoverConcurrencyCount: false, + intervalCap: Number.POSITIVE_INFINITY, + interval: 0, + concurrency: Number.POSITIVE_INFINITY, + autoStart: true, + queueClass: PriorityQueue, + ...options + }; + if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) { + throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(_b = (_a = options.intervalCap) == null ? void 0 : _a.toString()) != null ? _b : ""}\` (${typeof options.intervalCap})`); + } + if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) { + throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(_d = (_c = options.interval) == null ? void 0 : _c.toString()) != null ? _d : ""}\` (${typeof options.interval})`); + } + __privateSet(this, _carryoverConcurrencyCount, options.carryoverConcurrencyCount); + __privateSet(this, _isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0); + __privateSet(this, _intervalCap, options.intervalCap); + __privateSet(this, _interval, options.interval); + __privateSet(this, _queue2, new options.queueClass()); + __privateSet(this, _queueClass, options.queueClass); + this.concurrency = options.concurrency; + this.timeout = options.timeout; + __privateSet(this, _throwOnTimeout, options.throwOnTimeout === true); + __privateSet(this, _isPaused, options.autoStart === false); + } + get concurrency() { + return __privateGet(this, _concurrency); + } + set concurrency(newConcurrency) { + if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) { + throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`); + } + __privateSet(this, _concurrency, newConcurrency); + __privateMethod(this, _PQueue_instances, processQueue_fn).call(this); + } + async add(function_, options = {}) { + options = { + timeout: this.timeout, + throwOnTimeout: __privateGet(this, _throwOnTimeout), + ...options + }; + return new Promise((resolve, reject) => { + __privateGet(this, _queue2).enqueue(async () => { + var _a; + __privateWrapper(this, _pending)._++; + __privateWrapper(this, _intervalCount)._++; + try { + (_a = options.signal) == null ? void 0 : _a.throwIfAborted(); + let operation = function_({ signal: options.signal }); + if (options.timeout) { + operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout }); + } + if (options.signal) { + operation = Promise.race([operation, __privateMethod(this, _PQueue_instances, throwOnAbort_fn).call(this, options.signal)]); + } + const result = await operation; + resolve(result); + this.emit("completed", result); + } catch (error) { + if (error instanceof TimeoutError && !options.throwOnTimeout) { + resolve(); + return; + } + reject(error); + this.emit("error", error); + } finally { + __privateMethod(this, _PQueue_instances, next_fn).call(this); + } + }, options); + this.emit("add"); + __privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this); + }); + } + async addAll(functions, options) { + return Promise.all(functions.map(async (function_) => this.add(function_, options))); + } + /** + Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.) + */ + start() { + if (!__privateGet(this, _isPaused)) { + return this; + } + __privateSet(this, _isPaused, false); + __privateMethod(this, _PQueue_instances, processQueue_fn).call(this); + return this; + } + /** + Put queue execution on hold. + */ + pause() { + __privateSet(this, _isPaused, true); + } + /** + Clear the queue. + */ + clear() { + __privateSet(this, _queue2, new (__privateGet(this, _queueClass))()); + } + /** + Can be called multiple times. Useful if you for example add additional items at a later time. + + @returns A promise that settles when the queue becomes empty. + */ + async onEmpty() { + if (__privateGet(this, _queue2).size === 0) { + return; + } + await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "empty"); + } + /** + @returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`. + + If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item. + + Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation. + */ + async onSizeLessThan(limit) { + if (__privateGet(this, _queue2).size < limit) { + return; + } + await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "next", () => __privateGet(this, _queue2).size < limit); + } + /** + The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet. + + @returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`. + */ + async onIdle() { + if (__privateGet(this, _pending) === 0 && __privateGet(this, _queue2).size === 0) { + return; + } + await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "idle"); + } + /** + Size of the queue, the number of queued items waiting to run. + */ + get size() { + return __privateGet(this, _queue2).size; + } + /** + Size of the queue, filtered by the given options. + + For example, this can be used to find the number of items remaining in the queue with a specific priority level. + */ + sizeBy(options) { + return __privateGet(this, _queue2).filter(options).length; + } + /** + Number of running items (no longer in the queue). + */ + get pending() { + return __privateGet(this, _pending); + } + /** + Whether the queue is currently paused. + */ + get isPaused() { + return __privateGet(this, _isPaused); + } +}; +_carryoverConcurrencyCount = new WeakMap(); +_isIntervalIgnored = new WeakMap(); +_intervalCount = new WeakMap(); +_intervalCap = new WeakMap(); +_interval = new WeakMap(); +_intervalEnd = new WeakMap(); +_intervalId = new WeakMap(); +_timeoutId = new WeakMap(); +_queue2 = new WeakMap(); +_queueClass = new WeakMap(); +_pending = new WeakMap(); +_concurrency = new WeakMap(); +_isPaused = new WeakMap(); +_throwOnTimeout = new WeakMap(); +_PQueue_instances = new WeakSet(); +doesIntervalAllowAnother_get = function() { + return __privateGet(this, _isIntervalIgnored) || __privateGet(this, _intervalCount) < __privateGet(this, _intervalCap); +}; +doesConcurrentAllowAnother_get = function() { + return __privateGet(this, _pending) < __privateGet(this, _concurrency); +}; +next_fn = function() { + __privateWrapper(this, _pending)._--; + __privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this); + this.emit("next"); +}; +onResumeInterval_fn = function() { + __privateMethod(this, _PQueue_instances, onInterval_fn).call(this); + __privateMethod(this, _PQueue_instances, initializeIntervalIfNeeded_fn).call(this); + __privateSet(this, _timeoutId, void 0); +}; +isIntervalPaused_get = function() { + const now = Date.now(); + if (__privateGet(this, _intervalId) === void 0) { + const delay = __privateGet(this, _intervalEnd) - now; + if (delay < 0) { + __privateSet(this, _intervalCount, __privateGet(this, _carryoverConcurrencyCount) ? __privateGet(this, _pending) : 0); + } else { + if (__privateGet(this, _timeoutId) === void 0) { + __privateSet(this, _timeoutId, setTimeout(() => { + __privateMethod(this, _PQueue_instances, onResumeInterval_fn).call(this); + }, delay)); + } + return true; + } + } + return false; +}; +tryToStartAnother_fn = function() { + if (__privateGet(this, _queue2).size === 0) { + if (__privateGet(this, _intervalId)) { + clearInterval(__privateGet(this, _intervalId)); + } + __privateSet(this, _intervalId, void 0); + this.emit("empty"); + if (__privateGet(this, _pending) === 0) { + this.emit("idle"); + } + return false; + } + if (!__privateGet(this, _isPaused)) { + const canInitializeInterval = !__privateGet(this, _PQueue_instances, isIntervalPaused_get); + if (__privateGet(this, _PQueue_instances, doesIntervalAllowAnother_get) && __privateGet(this, _PQueue_instances, doesConcurrentAllowAnother_get)) { + const job = __privateGet(this, _queue2).dequeue(); + if (!job) { + return false; + } + this.emit("active"); + job(); + if (canInitializeInterval) { + __privateMethod(this, _PQueue_instances, initializeIntervalIfNeeded_fn).call(this); + } + return true; + } + } + return false; +}; +initializeIntervalIfNeeded_fn = function() { + if (__privateGet(this, _isIntervalIgnored) || __privateGet(this, _intervalId) !== void 0) { + return; + } + __privateSet(this, _intervalId, setInterval(() => { + __privateMethod(this, _PQueue_instances, onInterval_fn).call(this); + }, __privateGet(this, _interval))); + __privateSet(this, _intervalEnd, Date.now() + __privateGet(this, _interval)); +}; +onInterval_fn = function() { + if (__privateGet(this, _intervalCount) === 0 && __privateGet(this, _pending) === 0 && __privateGet(this, _intervalId)) { + clearInterval(__privateGet(this, _intervalId)); + __privateSet(this, _intervalId, void 0); + } + __privateSet(this, _intervalCount, __privateGet(this, _carryoverConcurrencyCount) ? __privateGet(this, _pending) : 0); + __privateMethod(this, _PQueue_instances, processQueue_fn).call(this); +}; +/** +Executes all queued functions until it reaches the limit. +*/ +processQueue_fn = function() { + while (__privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this)) { + } +}; +throwOnAbort_fn = async function(signal) { + return new Promise((_resolve, reject) => { + signal.addEventListener("abort", () => { + reject(signal.reason); + }, { once: true }); + }); +}; +onEvent_fn = async function(event, filter) { + return new Promise((resolve) => { + const listener = () => { + if (filter && !filter()) { + return; + } + this.off(event, listener); + resolve(); + }; + this.on(event, listener); + }); +}; + +// src/worker/download.ts +var chunks = []; +var QUEUE_CONCURRENCY_LIMIT = navigator.hardwareConcurrency || 4; +var queue = new PQueue({ + concurrency: QUEUE_CONCURRENCY_LIMIT, + autoStart: false +}); +var itemsInQueue = 0; +var isInitiated = false; +var isPaused = false; +self.onmessage = (event) => { + if (!isInitiated) { + init(); + isInitiated = true; + } + const data = event.data; + switch (data.action) { + case 5 /* PAUSE */: + { + isPaused = true; + self.postMessage({ event: "JOB_PAUSED" /* JOB_PAUSED */ }); + } + break; + case 8 /* RESUME */: + { + isPaused = false; + self.postMessage({ event: "JOB_RESUMED" /* JOB_RESUMED */ }); + } + break; + default: + events.once("DOWNLOAD_COMPLETE" /* DOWNLOAD_COMPLETE */, () => { + self.postMessage({ event: "DOWNLOAD_COMPLETE" /* DOWNLOAD_COMPLETE */ }); + }); + events.on("FILE_UPDATED" /* FILE_UPDATED */, updateFile); + events.on("CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, (chunk, index) => { + self.postMessage({ + event: "CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, + chunk: { buffer: chunk, index } + }); + }); + download(data).mapErr((error) => { + sendFileError(data.args.lufiFile, error); + }); + } +}; +var download = (workerMessage) => { + const { lufiFile } = workerMessage.args; + events.on( + "CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, + (chunk, chunkNumber) => { + chunks[chunkNumber] = chunk; + itemsInQueue--; + if (!isPaused && itemsInQueue < QUEUE_CONCURRENCY_LIMIT) { + queue.start(); + } + } + ); + events.on("DOWNLOAD_STARTED" /* DOWNLOAD_STARTED */, async () => { + for (let i = 1; i < lufiFile.totalChunks; i++) { + await queue.add(async () => { + await downloadChunk(lufiFile, i); + itemsInQueue++; + if (isPaused || itemsInQueue === QUEUE_CONCURRENCY_LIMIT) { + queue.pause(); + } + }); + } + queue.start(); + }); + return downloadChunk(lufiFile, 0); +}; +export { + QUEUE_CONCURRENCY_LIMIT, + itemsInQueue, + queue +}; diff --git a/themes/default/public/js/worker/encrypt.js b/themes/default/public/js/worker/encrypt.js index 1ddf039..2d47299 100644 --- a/themes/default/public/js/worker/encrypt.js +++ b/themes/default/public/js/worker/encrypt.js @@ -1 +1,1879 @@ -var Me=Object.create;var ee=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Ie=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty;var Te=(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 te=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ue=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Be(e))!je.call(t,o)&&o!==r&&ee(t,o,{get:()=>e[o],enumerable:!(n=Re(e,o))||n.enumerable});return t};var re=(t,e,r)=>(r=t!=null?Me(Ie(t)):{},Ue(e||!t||!t.__esModule?ee(r,"default",{value:t,enumerable:!0}):r,t));var he=te((Lt,S)=>{"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 ae(this,t,0)},decrypt:function(t){return ae(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 ae(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,m=[0,0,0,0];a=t.s[r],t=a[0];var y=a[1],_=a[2],N=a[3],W=a[4];for(h=0;h>>24]^y[i>>16&255]^_[s>>8&255]^N[e&255]^n[p],f=t[i>>>24]^y[s>>16&255]^_[e>>8&255]^N[o&255]^n[p+1],u=t[s>>>24]^y[e>>16&255]^_[o>>8&255]^N[i&255]^n[p+2],e=t[e>>>24]^y[o>>16&255]^_[i>>8&255]^N[s&255]^n[p+3],p+=4,o=a,i=f,s=u;for(h=0;4>h;h++)m[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 m}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 X(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],m=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)+(m^h&(p^m))+s[r],y=m,m=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]+m|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&&fe("seeded",Math.max(this.o,this.f)),fe("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(G=typeof S<"u"&&S.exports){try{J=Te("crypto")}catch{J=null}G=K=J}if(G&&K.randomBytes)T=K.randomBytes(128),T=new Uint32Array(new Uint8Array(T).buffer),c.random.addEntropy(T,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(U=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(U);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(U);else break e;c.random.addEntropy(U,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 T,K,U,G,J;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||4{"use strict";var R=typeof Reflect=="object"?Reflect:null,ge=R&&typeof R.apply=="function"?R.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},q;R&&typeof R.ownKeys=="function"?q=R.ownKeys:Object.getOwnPropertySymbols?q=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:q=function(e){return Object.getOwnPropertyNames(e)};function et(t){console&&console.warn&&console.warn(t)}var we=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}Z.exports=d;Z.exports.once=ot;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var ve=10;function $(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(d,"defaultMaxListeners",{enumerable:!0,get:function(){return ve},set:function(t){if(typeof t!="number"||t<0||we(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");ve=t}});d.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};d.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||we(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 Ee(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Ee(this)};d.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")ge(f,this,r);else for(var u=f.length,l=ke(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,et(a)}return t}d.prototype.addListener=function(e,r){return Ae(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return Ae(this,e,r,!0)};function tt(){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 xe(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=tt.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return $(r),this.on(e,xe(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return $(r),this.prependListener(e,xe(this,e,r)),this};d.prototype.removeListener=function(e,r){var n,o,i,s,a;if($(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():rt(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};d.prototype.off=d.prototype.removeListener;d.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 Le(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?nt(o):ke(o,o.length)}d.prototype.listeners=function(e){return Le(this,e,!0)};d.prototype.rawListeners=function(e){return Le(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):be.call(t,e)};d.prototype.listenerCount=be;function be(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}d.prototype.eventNames=function(){return this._eventsCount>0?q(this._events):[]};function ke(t,e){for(var r=new Array(e),n=0;n>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 Ne=new D("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function B(t){return Ne.Encode(t)}var We=new D("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function H(t){return We.Decode(t)}var Ke={withStackTrace:!1},ie=(t,e,r=Ke)=>{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 C(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 oe(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 b(t){return this instanceof b?(this.v=t,this):new b(t)}function Ge(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(m){return new Promise(function(y,_){i.push([p,m,y,_])>1||a(p,m)})})}function a(p,m){try{f(n[p](m))}catch(y){h(i[0][3],y)}}function f(p){p.value instanceof b?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,m){p(m),i.shift(),i.length&&a(i[0][0],i[0][1])}}function Je(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:b(t[o](s)),done:o==="return"}:i?i(s):s}:i}}function ze(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 oe=="function"?oe(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 v=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new w(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new w(o)).catch(o=>new E(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(C(this,void 0,void 0,function*(){try{return new w(yield e(...n))}catch(o){return new E(r?r(o):o)}}))}static combine(e){return qe(e)}static combineWithAllErrors(e){return $e(e)}map(e){return new t(this._promise.then(r=>C(this,void 0,void 0,function*(){return r.isErr()?new E(r.error):new w(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>C(this,void 0,void 0,function*(){if(r.isErr())return new E(r.error);let n=yield e(r.value);return n.isErr()?new E(n.error):new w(r.value)})))}andTee(e){return new t(this._promise.then(r=>C(this,void 0,void 0,function*(){if(r.isErr())return new E(r.error);try{yield e(r.value)}catch{}return new w(r.value)})))}mapErr(e){return new t(this._promise.then(r=>C(this,void 0,void 0,function*(){return r.isOk()?new w(r.value):new E(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new E(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>C(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new w(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 Ge(this,arguments,function*(){return yield b(yield b(yield*Je(ze(yield b(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},F=t=>new v(Promise.resolve(new w(t))),k=t=>new v(Promise.resolve(new E(t))),vt=v.fromPromise,wt=v.fromSafePromise,Et=v.fromThrowable,se=t=>{let e=L([]);for(let r of t)if(r.isErr()){e=A(r.error);break}else e.map(n=>n.push(r.value));return e},qe=t=>v.fromSafePromise(Promise.all(t)).andThen(se),ce=t=>{let e=L([]);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},$e=t=>v.fromSafePromise(Promise.all(t)).andThen(ce),Y;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return L(a)}catch(a){return A(i?i(a):a)}}}t.fromThrowable=e;function r(o){return se(o)}t.combine=r;function n(o){return ce(o)}t.combineWithAllErrors=n})(Y||(Y={}));var L=t=>new w(t);function A(t){return new E(t)}var w=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(r=>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 v.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 ie("Called `_unsafeUnwrapErr` on an Ok",this,e)}},E=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 k(this.error)}asyncAndThrough(e){return k(this.error)}asyncMap(e){return k(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 ie("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},At=Y.fromThrowable;var pe=re(he());var P=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 x=class extends P{};var z=class extends x{message="Unable to encrypt the provided data"};var O=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 He=()=>typeof Deno<"u",M=t=>He()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var de=(t,e)=>{try{let r=pe.default.encrypt(t,B(e));return F({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return k(new z(void 0,{cause:O(r)}))}};var me=(t,e)=>Ve(t).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return v.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,e),o=>O(o)).andThen(o=>F({algo:1,data:B(o),iv:n}))}),Ve=t=>v.fromPromise(crypto.subtle.importKey("raw",H(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new x("Unable to import cryptography key",{cause:O(e)}));var ye=(t,e,r=1)=>{let n;return r===0?n=de(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=me(t,e)),n};var Ce=re(_e());var Q=new Ce.default,g,De=!1;self.onmessage=t=>{ct(t),De||(De=!0,Q.once("OPERATION_FAILED",()=>{g&&g.terminate()}))};var ct=(t,e)=>{let{action:r}=t.data;switch(r){case 0:g=new Worker(M("cancel"),{type:"module"}),g.postMessage(t.data);break;case 1:g=new Worker(M("download"),{type:"module"}),g.postMessage(t.data);break;case 2:g=new Worker(M("infos"),{type:"module"}),g.postMessage(t.data);break;case 4:g=g||new Worker(M("remove"),{type:"module"}),g.postMessage(t.data);break;case 5:{g=g||new Worker(M("upload"),{type:"module"}),g.postMessage(t.data);break}default:console.error("Action not found")}g.onmessage=n=>{e&&e(n),self.postMessage(n.data)},g.onerror=n=>{console.error(`Error: ${n.message}`)}},Se=()=>{Q.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),Q.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Pe=!1;self.onmessage=t=>{Pe||(Se(),Pe=!0);let{lufiFile:e,chunk:r}=t.data.args;r?e.uploadStatus!==2?ye(e.keys.client,r.buffer).map(n=>{self.postMessage({encryptedData:n,chunkIndex:r.index})}).mapErr(n=>{self.postMessage({error:n})}):self.postMessage({error:"File upload already failed"}):self.postMessage({error:O("Buffer cannot be undefined")})}; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __defNormalProp = (obj3, key, value) => key in obj3 ? __defProp(obj3, key, { enumerable: true, configurable: true, writable: true, value }) : obj3[key] = value; +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); +var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __publicField = (obj3, key, value) => __defNormalProp(obj3, typeof key !== "symbol" ? key + "" : key, value); + +// node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js +var require_sjcl = __commonJS({ + "node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js"(exports, module) { + "use strict"; + var sjcl2 = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function(a) { + this.toString = function() { + return "CORRUPT: " + this.message; + }; + this.message = a; + }, invalid: function(a) { + this.toString = function() { + return "INVALID: " + this.message; + }; + this.message = a; + }, bug: function(a) { + this.toString = function() { + return "BUG: " + this.message; + }; + this.message = a; + }, notReady: function(a) { + this.toString = function() { + return "NOT READY: " + this.message; + }; + this.message = a; + } } }; + sjcl2.cipher.aes = function(a) { + this.s[0][0][0] || this.O(); + var b, c, d, e, f = this.s[0][4], g = this.s[1]; + b = a.length; + var h = 1; + if (4 !== b && 6 !== b && 8 !== b) throw new sjcl2.exception.invalid("invalid aes key size"); + this.b = [d = a.slice(0), e = []]; + for (a = b; a < 4 * b + 28; a++) { + c = d[a - 1]; + if (0 === a % b || 8 === b && 4 === a % b) c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7)); + d[a] = d[a - b] ^ c; + } + for (b = 0; a; b++, a--) c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & 255]]; + }; + sjcl2.cipher.aes.prototype = { encrypt: function(a) { + return t(this, a, 0); + }, decrypt: function(a) { + return t(this, a, 1); + }, s: [[[], [], [], [], []], [[], [], [], [], []]], O: function() { + var a = this.s[0], b = this.s[1], c = a[4], d = b[4], e, f, g, h = [], k = [], l, n, m, p; + for (e = 0; 256 > e; e++) k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e; + for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, n = h[e = h[l = h[f]]], p = 16843009 * n ^ 65537 * e ^ 257 * l ^ 16843008 * f, n = 257 * h[m] ^ 16843008 * m, e = 0; 4 > e; e++) a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8; + for (e = 0; 5 > e; e++) a[e] = a[e].slice(0), b[e] = b[e].slice(0); + } }; + function t(a, b, c) { + if (4 !== b.length) throw new sjcl2.exception.invalid("invalid aes block size"); + var d = a.b[c], e = b[0] ^ d[0], f = b[c ? 3 : 1] ^ d[1], g = b[2] ^ d[2]; + b = b[c ? 1 : 3] ^ d[3]; + var h, k, l, n = d.length / 4 - 2, m, p = 4, r = [0, 0, 0, 0]; + h = a.s[c]; + a = h[0]; + var q = h[1], v = h[2], w = h[3], x = h[4]; + for (m = 0; m < n; m++) h = a[e >>> 24] ^ q[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ q[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], l = a[g >>> 24] ^ q[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ q[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = l; + for (m = 0; 4 > m; m++) r[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h; + return r; + } + sjcl2.bitArray = { bitSlice: function(a, b, c) { + a = sjcl2.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1); + return void 0 === c ? a : sjcl2.bitArray.clamp(a, c - b); + }, extract: function(a, b, c) { + var d = Math.floor(-b - c & 31); + return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1; + }, concat: function(a, b) { + if (0 === a.length || 0 === b.length) return a.concat(b); + var c = a[a.length - 1], d = sjcl2.bitArray.getPartial(c); + return 32 === d ? a.concat(b) : sjcl2.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1)); + }, bitLength: function(a) { + var b = a.length; + return 0 === b ? 0 : 32 * (b - 1) + sjcl2.bitArray.getPartial(a[b - 1]); + }, clamp: function(a, b) { + if (32 * a.length < b) return a; + a = a.slice(0, Math.ceil(b / 32)); + var c = a.length; + b = b & 31; + 0 < c && b && (a[c - 1] = sjcl2.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)); + return a; + }, partial: function(a, b, c) { + return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 1099511627776 * a; + }, getPartial: function(a) { + return Math.round(a / 1099511627776) || 32; + }, equal: function(a, b) { + if (sjcl2.bitArray.bitLength(a) !== sjcl2.bitArray.bitLength(b)) return false; + var c = 0, d; + for (d = 0; d < a.length; d++) c |= a[d] ^ b[d]; + return 0 === c; + }, $: function(a, b, c, d) { + var e; + e = 0; + for (void 0 === d && (d = []); 32 <= b; b -= 32) d.push(c), c = 0; + if (0 === b) return d.concat(a); + for (e = 0; e < a.length; e++) d.push(c | a[e] >>> b), c = a[e] << 32 - b; + e = a.length ? a[a.length - 1] : 0; + a = sjcl2.bitArray.getPartial(e); + d.push(sjcl2.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1)); + return d; + }, i: function(a, b) { + return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; + }, byteswapM: function(a) { + var b, c; + for (b = 0; b < a.length; ++b) c = a[b], a[b] = c >>> 24 | c >>> 8 & 65280 | (c & 65280) << 8 | c << 24; + return a; + } }; + sjcl2.codec.utf8String = { fromBits: function(a) { + var b = "", c = sjcl2.bitArray.bitLength(a), d, e; + for (d = 0; d < c / 8; d++) 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8; + return decodeURIComponent(escape(b)); + }, toBits: function(a) { + a = unescape(encodeURIComponent(a)); + var b = [], c, d = 0; + for (c = 0; c < a.length; c++) d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); + c & 3 && b.push(sjcl2.bitArray.partial(8 * (c & 3), d)); + return b; + } }; + sjcl2.codec.hex = { fromBits: function(a) { + var b = "", c; + for (c = 0; c < a.length; c++) b += ((a[c] | 0) + 263882790666240).toString(16).substr(4); + return b.substr(0, sjcl2.bitArray.bitLength(a) / 4); + }, toBits: function(a) { + var b, c = [], d; + a = a.replace(/\s|0x/g, ""); + d = a.length; + a = a + "00000000"; + for (b = 0; b < a.length; b += 8) c.push(parseInt(a.substr(b, 8), 16) ^ 0); + return sjcl2.bitArray.clamp(c, 4 * d); + } }; + sjcl2.codec.base32 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", X: "0123456789ABCDEFGHIJKLMNOPQRSTUV", BITS: 32, BASE: 5, REMAINING: 27, fromBits: function(a, b, c) { + var d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = "", g = 0, h = sjcl2.codec.base32.B, k = 0, l = sjcl2.bitArray.bitLength(a); + c && (h = sjcl2.codec.base32.X); + for (c = 0; f.length * d < l; ) f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d); + for (; f.length & 7 && !b; ) f += "="; + return f; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, "").toUpperCase(); + var c = sjcl2.codec.base32.BITS, d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = [], g, h = 0, k = sjcl2.codec.base32.B, l = 0, n, m = "base32"; + b && (k = sjcl2.codec.base32.X, m = "base32hex"); + for (g = 0; g < a.length; g++) { + n = k.indexOf(a.charAt(g)); + if (0 > n) { + if (!b) try { + return sjcl2.codec.base32hex.toBits(a); + } catch (p) { + } + throw new sjcl2.exception.invalid("this isn't " + m + "!"); + } + h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h); + } + h & 56 && f.push(sjcl2.bitArray.partial(h & 56, l, 1)); + return f; + } }; + sjcl2.codec.base32hex = { fromBits: function(a, b) { + return sjcl2.codec.base32.fromBits(a, b, 1); + }, toBits: function(a) { + return sjcl2.codec.base32.toBits(a, 1); + } }; + sjcl2.codec.base64 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", fromBits: function(a, b, c) { + var d = "", e = 0, f = sjcl2.codec.base64.B, g = 0, h = sjcl2.bitArray.bitLength(a); + c && (f = f.substr(0, 62) + "-_"); + for (c = 0; 6 * d.length < h; ) d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6); + for (; d.length & 3 && !b; ) d += "="; + return d; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, ""); + var c = [], d, e = 0, f = sjcl2.codec.base64.B, g = 0, h; + b && (f = f.substr(0, 62) + "-_"); + for (d = 0; d < a.length; d++) { + h = f.indexOf(a.charAt(d)); + if (0 > h) throw new sjcl2.exception.invalid("this isn't base64!"); + 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e); + } + e & 56 && c.push(sjcl2.bitArray.partial(e & 56, g, 1)); + return c; + } }; + sjcl2.codec.base64url = { fromBits: function(a) { + return sjcl2.codec.base64.fromBits(a, 1, 1); + }, toBits: function(a) { + return sjcl2.codec.base64.toBits(a, 1); + } }; + sjcl2.hash.sha256 = function(a) { + this.b[0] || this.O(); + a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset(); + }; + sjcl2.hash.sha256.hash = function(a) { + return new sjcl2.hash.sha256().update(a).finalize(); + }; + sjcl2.hash.sha256.prototype = { blockSize: 512, reset: function() { + this.F = this.Y.slice(0); + this.A = []; + this.l = 0; + return this; + }, update: function(a) { + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + var b, c = this.A = sjcl2.bitArray.concat(this.A, a); + b = this.l; + a = this.l = b + sjcl2.bitArray.bitLength(a); + if (9007199254740991 < a) throw new sjcl2.exception.invalid("Cannot hash more than 2^53 - 1 bits"); + if ("undefined" !== typeof Uint32Array) { + var d = new Uint32Array(c), e = 0; + for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, d.subarray( + 16 * e, + 16 * (e + 1) + )), e += 1; + c.splice(0, 16 * e); + } else for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, c.splice(0, 16)); + return this; + }, finalize: function() { + var a, b = this.A, c = this.F, b = sjcl2.bitArray.concat(b, [sjcl2.bitArray.partial(1, 1)]); + for (a = b.length + 2; a & 15; a++) b.push(0); + b.push(Math.floor(this.l / 4294967296)); + for (b.push(this.l | 0); b.length; ) u(this, b.splice(0, 16)); + this.reset(); + return c; + }, Y: [], b: [], O: function() { + function a(a2) { + return 4294967296 * (a2 - Math.floor(a2)) | 0; + } + for (var b = 0, c = 2, d, e; 64 > b; c++) { + e = true; + for (d = 2; d * d <= c; d++) if (0 === c % d) { + e = false; + break; + } + e && (8 > b && (this.Y[b] = a(Math.pow(c, 0.5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++); + } + } }; + function u(a, b) { + var c, d, e, f = a.F, g = a.b, h = f[0], k = f[1], l = f[2], n = f[3], m = f[4], p = f[5], r = f[6], q = f[7]; + for (c = 0; 64 > c; c++) 16 > c ? d = b[c] : (d = b[c + 1 & 15], e = b[c + 14 & 15], d = b[c & 15] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + b[c & 15] + b[c + 9 & 15] | 0), d = d + q + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (r ^ m & (p ^ r)) + g[c], q = r, r = p, p = m, m = n + d | 0, n = l, l = k, k = h, h = d + (k & l ^ n & (k ^ l)) + (k >>> 2 ^ k >>> 13 ^ k >>> 22 ^ k << 30 ^ k << 19 ^ k << 10) | 0; + f[0] = f[0] + h | 0; + f[1] = f[1] + k | 0; + f[2] = f[2] + l | 0; + f[3] = f[3] + n | 0; + f[4] = f[4] + m | 0; + f[5] = f[5] + p | 0; + f[6] = f[6] + r | 0; + f[7] = f[7] + q | 0; + } + sjcl2.mode.ccm = { name: "ccm", G: [], listenProgress: function(a) { + sjcl2.mode.ccm.G.push(a); + }, unListenProgress: function(a) { + a = sjcl2.mode.ccm.G.indexOf(a); + -1 < a && sjcl2.mode.ccm.G.splice(a, 1); + }, fa: function(a) { + var b = sjcl2.mode.ccm.G.slice(), c; + for (c = 0; c < b.length; c += 1) b[c](a); + }, encrypt: function(a, b, c, d, e) { + var f, g = b.slice(0), h = sjcl2.bitArray, k = h.bitLength(c) / 8, l = h.bitLength(g) / 8; + e = e || 64; + d = d || []; + if (7 > k) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (f = 2; 4 > f && l >>> 8 * f; f++) ; + f < 15 - k && (f = 15 - k); + c = h.clamp( + c, + 8 * (15 - f) + ); + b = sjcl2.mode.ccm.V(a, b, c, d, e, f); + g = sjcl2.mode.ccm.C(a, g, c, b, e, f); + return h.concat(g.data, g.tag); + }, decrypt: function(a, b, c, d, e) { + e = e || 64; + d = d || []; + var f = sjcl2.bitArray, g = f.bitLength(c) / 8, h = f.bitLength(b), k = f.clamp(b, h - e), l = f.bitSlice(b, h - e), h = (h - e) / 8; + if (7 > g) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (b = 2; 4 > b && h >>> 8 * b; b++) ; + b < 15 - g && (b = 15 - g); + c = f.clamp(c, 8 * (15 - b)); + k = sjcl2.mode.ccm.C(a, k, c, l, e, b); + a = sjcl2.mode.ccm.V(a, k.data, c, d, e, b); + if (!f.equal(k.tag, a)) throw new sjcl2.exception.corrupt("ccm: tag doesn't match"); + return k.data; + }, na: function(a, b, c, d, e, f) { + var g = [], h = sjcl2.bitArray, k = h.i; + d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)]; + d = h.concat(d, c); + d[3] |= e; + d = a.encrypt(d); + if (b.length) for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 4294967295 >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); + return d; + }, V: function(a, b, c, d, e, f) { + var g = sjcl2.bitArray, h = g.i; + e /= 8; + if (e % 2 || 4 > e || 16 < e) throw new sjcl2.exception.invalid("ccm: invalid tag length"); + if (4294967295 < d.length || 4294967295 < b.length) throw new sjcl2.exception.bug("ccm: can't deal with 4GiB or more data"); + c = sjcl2.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f); + for (d = 0; d < b.length; d += 4) c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); + return g.clamp(c, 8 * e); + }, C: function(a, b, c, d, e, f) { + var g, h = sjcl2.bitArray; + g = h.i; + var k = b.length, l = h.bitLength(b), n = k / 50, m = n; + c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4); + d = h.bitSlice(g(d, a.encrypt(c)), 0, e); + if (!k) return { tag: d, data: [] }; + for (g = 0; g < k; g += 4) g > n && (sjcl2.mode.ccm.fa(g / k), n += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3]; + return { tag: d, data: h.clamp(b, l) }; + } }; + sjcl2.mode.ocb2 = { name: "ocb2", encrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + var g, h = sjcl2.mode.ocb2.S, k = sjcl2.bitArray, l = k.i, n = [0, 0, 0, 0]; + c = h(a.encrypt(c)); + var m, p = []; + d = d || []; + e = e || 64; + for (g = 0; g + 4 < b.length; g += 4) m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c); + m = b.slice(g); + b = k.bitLength(m); + g = a.encrypt(l(c, [0, 0, 0, b])); + m = k.clamp(l(m.concat([0, 0, 0]), g), b); + n = l(n, l(m.concat([0, 0, 0]), g)); + n = a.encrypt(l(n, l(c, h(c)))); + d.length && (n = l(n, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + return p.concat(k.concat(m, k.clamp(n, e))); + }, decrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + e = e || 64; + var g = sjcl2.mode.ocb2.S, h = sjcl2.bitArray, k = h.i, l = [0, 0, 0, 0], n = g(a.encrypt(c)), m, p, r = sjcl2.bitArray.bitLength(b) - e, q = []; + d = d || []; + for (c = 0; c + 4 < r / 32; c += 4) m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n); + p = r - 32 * c; + m = a.encrypt(k(n, [0, 0, 0, p])); + m = k(m, h.clamp(b.slice(c), p).concat([ + 0, + 0, + 0 + ])); + l = k(l, m); + l = a.encrypt(k(l, k(n, g(n)))); + d.length && (l = k(l, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl2.exception.corrupt("ocb: tag doesn't match"); + return q.concat(h.clamp(m, p)); + }, pmac: function(a, b) { + var c, d = sjcl2.mode.ocb2.S, e = sjcl2.bitArray, f = e.i, g = [0, 0, 0, 0], h = a.encrypt([0, 0, 0, 0]), h = f(h, d(d(h))); + for (c = 0; c + 4 < b.length; c += 4) h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4)))); + c = b.slice(c); + 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0])); + g = f(g, c); + return a.encrypt(f(d(f(h, d(h))), g)); + }, S: function(a) { + return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)]; + } }; + sjcl2.mode.gcm = { name: "gcm", encrypt: function(a, b, c, d, e) { + var f = b.slice(0); + b = sjcl2.bitArray; + d = d || []; + a = sjcl2.mode.gcm.C(true, a, f, d, c, e || 128); + return b.concat(a.data, a.tag); + }, decrypt: function(a, b, c, d, e) { + var f = b.slice(0), g = sjcl2.bitArray, h = g.bitLength(f); + e = e || 128; + d = d || []; + e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []); + a = sjcl2.mode.gcm.C(false, a, f, d, c, e); + if (!g.equal(a.tag, b)) throw new sjcl2.exception.corrupt("gcm: tag doesn't match"); + return a.data; + }, ka: function(a, b) { + var c, d, e, f, g, h = sjcl2.bitArray.i; + e = [ + 0, + 0, + 0, + 0 + ]; + f = b.slice(0); + for (c = 0; 128 > c; c++) { + (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f)); + g = 0 !== (f[3] & 1); + for (d = 3; 0 < d; d--) f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31; + f[0] >>>= 1; + g && (f[0] ^= -520093696); + } + return e; + }, j: function(a, b, c) { + var d, e = c.length; + b = b.slice(0); + for (d = 0; d < e; d += 4) b[0] ^= 4294967295 & c[d], b[1] ^= 4294967295 & c[d + 1], b[2] ^= 4294967295 & c[d + 2], b[3] ^= 4294967295 & c[d + 3], b = sjcl2.mode.gcm.ka(b, a); + return b; + }, C: function(a, b, c, d, e, f) { + var g, h, k, l, n, m, p, r, q = sjcl2.bitArray; + m = c.length; + p = q.bitLength(c); + r = q.bitLength(d); + h = q.bitLength(e); + g = b.encrypt([0, 0, 0, 0]); + 96 === h ? (e = e.slice(0), e = q.concat(e, [1])) : (e = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], e), e = sjcl2.mode.gcm.j(g, e, [0, 0, Math.floor(h / 4294967296), h & 4294967295])); + h = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], d); + n = e.slice(0); + d = h.slice(0); + a || (d = sjcl2.mode.gcm.j(g, h, c)); + for (l = 0; l < m; l += 4) n[3]++, k = b.encrypt(n), c[l] ^= k[0], c[l + 1] ^= k[1], c[l + 2] ^= k[2], c[l + 3] ^= k[3]; + c = q.clamp(c, p); + a && (d = sjcl2.mode.gcm.j(g, h, c)); + a = [Math.floor(r / 4294967296), r & 4294967295, Math.floor(p / 4294967296), p & 4294967295]; + d = sjcl2.mode.gcm.j(g, d, a); + k = b.encrypt(e); + d[0] ^= k[0]; + d[1] ^= k[1]; + d[2] ^= k[2]; + d[3] ^= k[3]; + return { tag: q.bitSlice(d, 0, f), data: c }; + } }; + sjcl2.misc.hmac = function(a, b) { + this.W = b = b || sjcl2.hash.sha256; + var c = [[], []], d, e = b.prototype.blockSize / 32; + this.w = [new b(), new b()]; + a.length > e && (a = b.hash(a)); + for (d = 0; d < e; d++) c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828; + this.w[0].update(c[0]); + this.w[1].update(c[1]); + this.R = new b(this.w[0]); + }; + sjcl2.misc.hmac.prototype.encrypt = sjcl2.misc.hmac.prototype.mac = function(a) { + if (this.aa) throw new sjcl2.exception.invalid("encrypt on already updated hmac called!"); + this.update(a); + return this.digest(a); + }; + sjcl2.misc.hmac.prototype.reset = function() { + this.R = new this.W(this.w[0]); + this.aa = false; + }; + sjcl2.misc.hmac.prototype.update = function(a) { + this.aa = true; + this.R.update(a); + }; + sjcl2.misc.hmac.prototype.digest = function() { + var a = this.R.finalize(), a = new this.W(this.w[1]).update(a).finalize(); + this.reset(); + return a; + }; + sjcl2.misc.pbkdf2 = function(a, b, c, d, e) { + c = c || 1e4; + if (0 > d || 0 > c) throw new sjcl2.exception.invalid("invalid params to pbkdf2"); + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + e = e || sjcl2.misc.hmac; + a = new e(a); + var f, g, h, k, l = [], n = sjcl2.bitArray; + for (k = 1; 32 * l.length < (d || 1); k++) { + e = f = a.encrypt(n.concat(b, [k])); + for (g = 1; g < c; g++) for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h]; + l = l.concat(e); + } + d && (l = n.clamp(l, d)); + return l; + }; + sjcl2.prng = function(a) { + this.c = [new sjcl2.hash.sha256()]; + this.m = [0]; + this.P = 0; + this.H = {}; + this.N = 0; + this.U = {}; + this.Z = this.f = this.o = this.ha = 0; + this.b = [0, 0, 0, 0, 0, 0, 0, 0]; + this.h = [0, 0, 0, 0]; + this.L = void 0; + this.M = a; + this.D = false; + this.K = { progress: {}, seeded: {} }; + this.u = this.ga = 0; + this.I = 1; + this.J = 2; + this.ca = 65536; + this.T = [0, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024]; + this.da = 3e4; + this.ba = 80; + }; + sjcl2.prng.prototype = { + randomWords: function(a, b) { + var c = [], d; + d = this.isReady(b); + var e; + if (d === this.u) throw new sjcl2.exception.notReady("generator isn't seeded"); + if (d & this.J) { + d = !(d & this.I); + e = []; + var f = 0, g; + this.Z = e[0] = (/* @__PURE__ */ new Date()).valueOf() + this.da; + for (g = 0; 16 > g; g++) e.push(4294967296 * Math.random() | 0); + for (g = 0; g < this.c.length && (e = e.concat(this.c[g].finalize()), f += this.m[g], this.m[g] = 0, d || !(this.P & 1 << g)); g++) ; + this.P >= 1 << this.c.length && (this.c.push(new sjcl2.hash.sha256()), this.m.push(0)); + this.f -= f; + f > this.o && (this.o = f); + this.P++; + this.b = sjcl2.hash.sha256.hash(this.b.concat(e)); + this.L = new sjcl2.cipher.aes(this.b); + for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) ; + } + for (d = 0; d < a; d += 4) 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]); + y(this); + return c.slice(0, a); + }, + setDefaultParanoia: function(a, b) { + if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) throw new sjcl2.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); + this.M = a; + }, + addEntropy: function(a, b, c) { + c = c || "user"; + var d, e, f = (/* @__PURE__ */ new Date()).valueOf(), g = this.H[c], h = this.isReady(), k = 0; + d = this.U[c]; + void 0 === d && (d = this.U[c] = this.ha++); + void 0 === g && (g = this.H[c] = 0); + this.H[c] = (this.H[c] + 1) % this.c.length; + switch (typeof a) { + case "number": + void 0 === b && (b = 1); + this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]); + break; + case "object": + c = Object.prototype.toString.call(a); + if ("[object Uint32Array]" === c) { + e = []; + for (c = 0; c < a.length; c++) e.push(a[c]); + a = e; + } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) "number" !== typeof a[c] && (k = 1); + if (!k) { + if (void 0 === b) for (c = b = 0; c < a.length; c++) for (e = a[c]; 0 < e; ) b++, e = e >>> 1; + this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a)); + } + break; + case "string": + void 0 === b && (b = a.length); + this.c[g].update([d, this.N++, 3, b, f, a.length]); + this.c[g].update(a); + break; + default: + k = 1; + } + if (k) throw new sjcl2.exception.bug("random: addEntropy only supports number, array of numbers or string"); + this.m[g] += b; + this.f += b; + h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress())); + }, + isReady: function(a) { + a = this.T[void 0 !== a ? a : this.M]; + return this.o && this.o >= a ? this.m[0] > this.ba && (/* @__PURE__ */ new Date()).valueOf() > this.Z ? this.J | this.I : this.I : this.f >= a ? this.J | this.u : this.u; + }, + getProgress: function(a) { + a = this.T[a ? a : this.M]; + return this.o >= a ? 1 : this.f > a ? 1 : this.f / a; + }, + startCollectors: function() { + if (!this.D) { + this.a = { loadTimeCollector: B(this, this.ma), mouseCollector: B(this, this.oa), keyboardCollector: B(this, this.la), accelerometerCollector: B(this, this.ea), touchCollector: B(this, this.qa) }; + if (window.addEventListener) window.addEventListener( + "load", + this.a.loadTimeCollector, + false + ), window.addEventListener("mousemove", this.a.mouseCollector, false), window.addEventListener("keypress", this.a.keyboardCollector, false), window.addEventListener("devicemotion", this.a.accelerometerCollector, false), window.addEventListener("touchmove", this.a.touchCollector, false); + 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 sjcl2.exception.bug("can't attach event"); + this.D = true; + } + }, + stopCollectors: function() { + this.D && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, false), window.removeEventListener("mousemove", this.a.mouseCollector, false), window.removeEventListener("keypress", this.a.keyboardCollector, false), window.removeEventListener("devicemotion", this.a.accelerometerCollector, false), window.removeEventListener("touchmove", this.a.touchCollector, false)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent( + "onmousemove", + this.a.mouseCollector + ), document.detachEvent("keypress", this.a.keyboardCollector)), this.D = false); + }, + addEventListener: function(a, b) { + this.K[a][this.ga++] = b; + }, + removeEventListener: function(a, b) { + var c, d, e = this.K[a], f = []; + for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d); + for (c = 0; c < f.length; c++) d = f[c], delete e[d]; + }, + la: function() { + C(this, 1); + }, + oa: function(a) { + var b, c; + try { + b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0; + } catch (d) { + c = b = 0; + } + 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); + C(this, 0); + }, + qa: function(a) { + a = a.touches[0] || a.changedTouches[0]; + this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); + C(this, 0); + }, + ma: function() { + C(this, 2); + }, + ea: function(a) { + a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; + if (window.orientation) { + var b = window.orientation; + "number" === typeof b && this.addEntropy(b, 1, "accelerometer"); + } + a && this.addEntropy(a, 2, "accelerometer"); + C(this, 0); + } + }; + function A(a, b) { + var c, d = sjcl2.random.K[a], e = []; + for (c in d) d.hasOwnProperty(c) && e.push(d[c]); + for (c = 0; c < e.length; c++) e[c](b); + } + function C(a, b) { + "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy((/* @__PURE__ */ new Date()).valueOf(), b, "loadtime"); + } + function y(a) { + a.b = z(a).concat(z(a)); + a.L = new sjcl2.cipher.aes(a.b); + } + function z(a) { + for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) ; + return a.L.encrypt(a.h); + } + function B(a, b) { + return function() { + b.apply(a, arguments); + }; + } + sjcl2.random = new sjcl2.prng(6); + a: try { + if (G = "undefined" !== typeof module && module.exports) { + try { + H = __require("crypto"); + } catch (a) { + H = null; + } + G = E = H; + } + if (G && E.randomBytes) D = E.randomBytes(128), D = new Uint32Array(new Uint8Array(D).buffer), sjcl2.random.addEntropy(D, 1024, "crypto['randomBytes']"); + else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { + F = new Uint32Array(32); + if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F); + else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F); + else break a; + sjcl2.random.addEntropy(F, 1024, "crypto['getRandomValues']"); + } + } catch (a) { + "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a)); + } + var D; + var E; + var F; + var G; + var H; + sjcl2.json = { defaults: { v: 1, iter: 1e4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, ja: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json, f = e.g({ iv: sjcl2.random.randomWords(4, 0) }, e.defaults), g; + e.g(f, c); + c = f.adata; + "string" === typeof f.salt && (f.salt = sjcl2.codec.base64.toBits(f.salt)); + "string" === typeof f.iv && (f.iv = sjcl2.codec.base64.toBits(f.iv)); + if (!sjcl2.mode[f.mode] || !sjcl2.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 256 !== f.ks || 2 > f.iv.length || 4 < f.iv.length) throw new sjcl2.exception.invalid("json encrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + "string" === typeof c && (f.adata = c = sjcl2.codec.utf8String.toBits(c)); + g = new sjcl2.cipher[f.cipher](a); + e.g(d, f); + d.key = a; + f.ct = "ccm" === f.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl2.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); + return f; + }, encrypt: function(a, b, c, d) { + var e = sjcl2.json, f = e.ja.apply(e, arguments); + return e.encode(f); + }, ia: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json; + b = e.g(e.g(e.g({}, e.defaults), b), c, true); + var f, g; + f = b.adata; + "string" === typeof b.salt && (b.salt = sjcl2.codec.base64.toBits(b.salt)); + "string" === typeof b.iv && (b.iv = sjcl2.codec.base64.toBits(b.iv)); + if (!sjcl2.mode[b.mode] || !sjcl2.cipher[b.cipher] || "string" === typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 256 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) throw new sjcl2.exception.invalid("json decrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.secretKey && (a = a.unkem(sjcl2.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); + "string" === typeof f && (f = sjcl2.codec.utf8String.toBits(f)); + g = new sjcl2.cipher[b.cipher](a); + f = "ccm" === b.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl2.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); + e.g(d, b); + d.key = a; + return 1 === c.raw ? f : sjcl2.codec.utf8String.fromBits(f); + }, decrypt: function(a, b, c, d) { + var e = sjcl2.json; + return e.ia(a, e.decode(b), c, d); + }, encode: function(a) { + var b, c = "{", d = ""; + for (b in a) if (a.hasOwnProperty(b)) { + if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl2.exception.invalid("json encode: invalid property name"); + c += d + '"' + b + '":'; + d = ","; + switch (typeof a[b]) { + case "number": + case "boolean": + c += a[b]; + break; + case "string": + c += '"' + escape(a[b]) + '"'; + break; + case "object": + c += '"' + sjcl2.codec.base64.fromBits(a[b], 0) + '"'; + break; + default: + throw new sjcl2.exception.bug("json encode: unsupported type"); + } + } + return c + "}"; + }, decode: function(a) { + a = a.replace(/\s/g, ""); + if (!a.match(/^\{.*\}$/)) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + a = a.replace(/^\{|\}$/g, "").split(/,/); + var b = {}, c, d; + for (c = 0; c < a.length; c++) { + if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl2.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]); + } + return b; + }, g: function(a, b, c) { + void 0 === a && (a = {}); + if (void 0 === b) return a; + for (var d in b) if (b.hasOwnProperty(d)) { + if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl2.exception.invalid("required parameter overridden"); + a[d] = b[d]; + } + return a; + }, sa: function(a, b) { + var c = {}, d; + for (d in a) a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); + return c; + }, ra: function(a, b) { + var c = {}, d; + for (d = 0; d < b.length; d++) void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); + return c; + } }; + sjcl2.encrypt = sjcl2.json.encrypt; + sjcl2.decrypt = sjcl2.json.decrypt; + sjcl2.misc.pa = {}; + sjcl2.misc.cachedPbkdf2 = function(a, b) { + var c = sjcl2.misc.pa, d; + b = b || {}; + d = b.iter || 1e3; + c = c[a] = c[a] || {}; + d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl2.random.randomWords(2, 0) }; + c = void 0 === b.salt ? d.firstSalt : b.salt; + d[c] = d[c] || sjcl2.misc.pbkdf2(a, c, b.iter); + return { key: d[c].slice(0), salt: c.slice(0) }; + }; + "undefined" !== typeof module && module.exports && (module.exports = sjcl2); + "function" === typeof define && define([], function() { + return sjcl2; + }); + } +}); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter2() { + EventEmitter2.init.call(this); + } + module.exports = EventEmitter2; + module.exports.once = once; + EventEmitter2.EventEmitter = EventEmitter2; + EventEmitter2.prototype._events = void 0; + EventEmitter2.prototype._eventsCount = 0; + EventEmitter2.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter2, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter2.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter2.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter2.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter2.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter2.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events2 = this._events; + if (events2 !== void 0) + doError = doError && events2.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err2 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err2.context = er; + throw err2; + } + var handler = events2[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events2; + var existing; + checkListener(listener); + events2 = target._events; + if (events2 === void 0) { + events2 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events2.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events2 = target._events; + } + existing = events2[type]; + } + if (existing === void 0) { + existing = events2[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events2[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter2.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter2.prototype.on = EventEmitter2.prototype.addListener; + EventEmitter2.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter2.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.removeListener = function removeListener(type, listener) { + var list, events2, position, i, originalListener; + checkListener(listener); + events2 = this._events; + if (events2 === void 0) + return this; + list = events2[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events2[type]; + if (events2.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events2[type] = list[0]; + if (events2.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; + EventEmitter2.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events2, i; + events2 = this._events; + if (events2 === void 0) + return this; + if (events2.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events2[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events2[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events2); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events2[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events2 = target._events; + if (events2 === void 0) + return []; + var evlistener = events2[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter2.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter2.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter2.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter2.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events2 = this._events; + if (events2 !== void 0) { + var evlistener = events2[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter2.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err2) { + emitter.removeListener(name, resolver); + reject(err2); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/encoding.js +var Encoding = class { + /** + * + * @param charset Charset to use for base64 encoding. This must be 64-characters long. + * @param noPadding If true, encoded strings won't include padding. + */ + constructor(charset, noPadding) { + if (!charset || charset.length != 64) { + throw Error("Charset must contain 64 characters"); + } + this._charset = charset; + this._noPadding = !!noPadding; + this._valid = new RegExp("^[" + this._charset.replace("-", "\\-") + "]+={0,2}$"); + } + /** + * Encode an ArrayBuffer to base64 in a string. + * @param ab Data to encode to base64 + * @returns Base64-encoded string + */ + Encode(ab) { + const len = ab.byteLength; + if (!len) { + return ""; + } + const view = new Uint8Array(ab); + let res = ""; + for (let i = 0; i < len; i += 3) { + res += this._charset[view[i] >> 2] + this._charset[(view[i] & 3) << 4 | view[i + 1] >> 4] + this._charset[(view[i + 1] & 15) << 2 | view[i + 2] >> 6] + this._charset[view[i + 2] & 63]; + } + if (len % 3 == 2) { + res = res.substring(0, res.length - 1); + if (!this._noPadding) { + res += "="; + } + } else if (len % 3 == 1) { + res = res.substring(0, res.length - 2); + if (!this._noPadding) { + res += "=="; + } + } + return res; + } + /** + * Decode a string from base64. Padding is always optional. + * @param str Base64-encoded string + * @returns Data decoded from the base64 string + */ + Decode(str) { + str = (str || "").replace(/[\s]/g, ""); + if (!str) { + return new ArrayBuffer(0); + } + if (!this._valid.test(str)) { + throw Error("Invalid base64 input sequence"); + } + let viewLen = Math.floor(str.length * 0.75); + if (str[str.length - 2] == "=") { + viewLen -= 2; + } else if (str[str.length - 1] == "=") { + viewLen--; + } + const view = new Uint8Array(viewLen); + let enc1, enc2, enc3, enc4, i = 0, j = 0; + while (i < str.length * 0.75) { + enc1 = this._charset.indexOf(str.charAt(j++)); + enc2 = this._charset.indexOf(str.charAt(j++)); + enc3 = this._charset.indexOf(str.charAt(j++)); + enc4 = this._charset.indexOf(str.charAt(j++)); + view[i++] = enc1 << 2 | enc2 >> 4; + view[i++] = (enc2 & 15) << 4 | enc3 >> 2; + view[i++] = (enc3 & 3) << 6 | enc4; + } + return view.buffer; + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/standard.js +var obj = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +function Encode(ab) { + return obj.Encode(ab); +} + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/url.js +var obj2 = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", true); +function Decode(str) { + return obj2.Decode(str); +} + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var okAsync = (value) => new ResultAsync(Promise.resolve(new Ok(value))); +var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result2) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result2.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result2.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result2.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err2) { + return new Err(err2); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err2) { + return err2(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/api/crypto/sjcl.ts +var import_sjcl = __toESM(require_sjcl()); + +// src/error/base-error.ts +var BaseError = class extends Error { + constructor(message, options = {}) { + const { cause, context } = options; + super(message, { cause }); + __publicField(this, "context"); + this.name = this.constructor.name; + this.context = context; + } +}; + +// src/error/crypto/crypto-error.ts +var CryptoError = class extends BaseError { +}; + +// src/error/crypto/encryption-error.ts +var EncryptionError = class extends CryptoError { + constructor() { + super(...arguments); + __publicField(this, "message", "Unable to encrypt the provided data"); + } +}; + +// src/utils.ts +var ensureError = (value) => { + if (value instanceof Error) return value; + let stringified = "[Unable to stringify the thrown value]"; + try { + stringified = JSON.stringify(value); + } catch (_error) { + } + const error = new Error(stringified); + return error; +}; +var isDenoRuntime = () => typeof Deno !== "undefined"; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); + +// src/api/crypto/sjcl.ts +var encrypt = (key, value) => { + try { + const encrypted = import_sjcl.default.encrypt(key, Encode(value)); + return okAsync({ + algo: 0 /* Sjcl */, + data: encrypted, + iv: JSON.parse(encrypted).iv + }); + } catch (e) { + return errAsync(new EncryptionError(void 0, { cause: ensureError(e) })); + } +}; + +// src/api/crypto/web.ts +var encrypt2 = (key, value) => { + return importKey(key).andThen((importedKey) => { + const iv = crypto.getRandomValues(new Uint8Array(12)); + return ResultAsync.fromPromise( + crypto.subtle.encrypt( + { + name: "AES-GCM", + iv + }, + importedKey, + value + ), + (error) => ensureError(error) + ).andThen((encrypted) => { + return okAsync({ + algo: 1 /* WebCrypto */, + data: Encode(encrypted), + iv + }); + }); + }); +}; +var importKey = (key) => { + return ResultAsync.fromPromise( + crypto.subtle.importKey( + "raw", + Decode(key), + { name: "AES-GCM" }, + false, + [ + "encrypt", + "decrypt" + ] + ), + (error) => new CryptoError("Unable to import cryptography key", { + cause: ensureError(error) + }) + ); +}; + +// src/api/crypto.ts +var encrypt3 = (key, value, algo) => { + let encrypted; + if (algo === 0 /* Sjcl */) { + console.debug("sjcl"); + encrypted = encrypt(key, value); + } else { + if (typeof value === "string") { + value = new TextEncoder().encode(value).buffer; + } + encrypted = encrypt2(key, value); + } + return encrypted; +}; + +// src/worker/main.ts +var import_events = __toESM(require_events()); +var events = new import_events.default(); +var worker; +var isInitialized = false; +self.onmessage = (event) => { + addWorker(event); + if (!isInitialized) { + isInitialized = true; + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + if (worker) { + worker.terminate(); + } + }); + } +}; +var addWorker = (event, callback) => { + const { action } = event.data; + if (action === 5 /* PAUSE */ || action === 8 /* RESUME */) { + worker.postMessage(event.data); + } else { + switch (action) { + case 2 /* CANCEL */: + { + worker = new Worker(workerUrl("cancel"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 3 /* DOWNLOAD */: + { + worker = new Worker(workerUrl("download"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 4 /* INFOS */: + { + worker = new Worker(workerUrl("infos"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 7 /* REMOVE */: + { + worker = worker || new Worker(workerUrl("remove"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 9 /* UPLOAD */: + { + worker = worker || new Worker(workerUrl("upload"), { type: "module" }); + worker.postMessage(event.data); + } + break; + default: { + console.error("Action not found"); + } + } + worker.onmessage = (e) => { + if (callback) callback(e); + self.postMessage(e.data); + }; + worker.onerror = (error) => { + console.error(`Error: ${error.message}`); + }; + } +}; +var init = () => { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + self.postMessage({ + event: "SOCKET_OPENED" /* SOCKET_OPENED */ + }); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); + }); +}; + +// src/worker/encrypt.ts +var isInitiated = false; +self.onmessage = (event) => { + if (!isInitiated) { + init(); + isInitiated = true; + } + const { lufiFile, chunk, algo } = event.data.args; + if (chunk && typeof algo !== "undefined") { + if (lufiFile.uploadStatus !== 2 /* FAILED */) { + encrypt3(lufiFile.keys.client, chunk.buffer, algo).map((encryptedData) => { + self.postMessage({ encryptedData, chunkIndex: chunk.index }); + }).mapErr((error) => { + self.postMessage({ error }); + }); + } else { + self.postMessage({ error: "File upload already failed" }); + } + } else { + self.postMessage({ error: ensureError("Buffer cannot be undefined") }); + } +}; diff --git a/themes/default/public/js/worker/infos.js b/themes/default/public/js/worker/infos.js index bc5664f..55697ea 100644 --- a/themes/default/public/js/worker/infos.js +++ b/themes/default/public/js/worker/infos.js @@ -1 +1,2108 @@ -var Xe=Object.create;var ce=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var qe=(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 ae=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var He=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ge(t))!Ke.call(e,o)&&o!==r&&ce(e,o,{get:()=>t[o],enumerable:!(n=ze(t,o))||n.enumerable});return e};var fe=(e,t,r)=>(r=e!=null?Xe($e(e)):{},He(t||!e||!e.__esModule?ce(r,"default",{value:e,enumerable:!0}):r,e));var xe=ae((er,te)=>{"use strict";var I=typeof Reflect=="object"?Reflect:null,pe=I&&typeof I.apply=="function"?I.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},q;I&&typeof I.ownKeys=="function"?q=I.ownKeys:Object.getOwnPropertySymbols?q=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:q=function(t){return Object.getOwnPropertyNames(t)};function nt(e){console&&console.warn&&console.warn(e)}var ye=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}te.exports=p;te.exports.once=ct;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var me=10;function H(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(p,"defaultMaxListeners",{enumerable:!0,get:function(){return me},set:function(e){if(typeof e!="number"||e<0||ye(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");me=e}});p.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};p.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ye(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 ge(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return ge(this)};p.prototype.emit=function(t){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[t];if(f===void 0)return!1;if(typeof f=="function")pe(f,this,r);else for(var u=f.length,l=Le(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(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,nt(a)}return e}p.prototype.addListener=function(t,r){return ve(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return ve(this,t,r,!0)};function ot(){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 we(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=ot.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return H(r),this.on(t,we(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return H(r),this.prependListener(t,we(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(H(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,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():it(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};p.prototype.off=p.prototype.removeListener;p.prototype.removeAllListeners=function(t){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[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function Ee(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?st(o):Le(o,o.length)}p.prototype.listeners=function(t){return Ee(this,t,!0)};p.prototype.rawListeners=function(t){return Ee(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Ae.call(e,t)};p.prototype.listenerCount=Ae;function Ae(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}p.prototype.eventNames=function(){return this._eventsCount>0?q(this._events):[]};function Le(e,t){for(var r=new Array(t),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(e){this.s[0][0][0]||this.O();var t,r,n,o,i=this.s[0][4],s=this.s[1];t=e.length;var a=1;if(t!==4&&t!==6&&t!==8)throw new c.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?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(e){return Ce(this,e,0)},decrypt:function(e){return Ce(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],o,i,s,a=[],f=[],u,l,h,d;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]]],d=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Ce(e,t,r){if(t.length!==4)throw new c.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var a,f,u,l=n.length/4-2,h,d=4,y=[0,0,0,0];a=e.s[r],e=a[0];var g=a[1],P=a[2],$=a[3],K=a[4];for(h=0;h>>24]^g[i>>16&255]^P[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^P[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^P[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^P[i>>8&255]^$[s&255]^n[d+3],d+=4,o=a,i=f,s=u;for(h=0;4>h;h++)y[r?3&-h:h]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[t&255]^n[d++],a=o,o=i,i=s,s=t,t=a;return y}c.bitArray={bitSlice:function(e,t,r){return e=c.bitArray.$(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:c.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(c.bitArray.bitLength(e)!==c.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=c.bitArray.getPartial(o),n.push(c.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};c.codec.utf8String={fromBits:function(e){var t="",r=c.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>s)>>>o),sl){if(!t)try{return c.codec.base32hex.toBits(e)}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=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=c.codec.base64.B,s=0,a;for(t&&(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(e){return c.codec.base64.fromBits(e,1,1)},toBits:function(e){return c.codec.base64.toBits(e,1)}};c.hash.sha256=function(e){this.b[0]||this.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):this.reset()};c.hash.sha256.hash=function(e){return new c.hash.sha256().update(e).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=c.codec.utf8String.toBits(e));var t,r=this.A=c.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+c.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function ne(e,t){var r,n,o,i=e.F,s=e.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],d=i[5],y=i[6],g=i[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],o=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+t[r&15]+t[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(d^y))+s[r],g=y,y=d,d=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]+d|0,i[6]=i[6]+y|0,i[7]=i[7]+g|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(e){c.mode.ccm.G.push(e)},unListenProgress:function(e){e=c.mode.ccm.G.indexOf(e),-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)),t=c.mode.ccm.V(e,t,r,n,o,i),s=c.mode.ccm.C(e,s,r,t,o,i),a.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(t),a=i.clamp(t,u-o),f=i.bitSlice(t,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&u>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),a=c.mode.ccm.C(e,a,r,f,o,t),e=c.mode.ccm.V(e,a.data,r,n,o,t),!i.equal(a.tag,e))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(e,t,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=a.bitLength(t)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,t),t=0;to||16l&&(c.mode.ccm.fa(s/f),l+=h),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:a.clamp(t,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(e,t,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(e.encrypt(r));var h,d=[];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),e.encrypt(i(n(i(a,n(a))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,o){var i=t.slice(0);return t=c.bitArray,n=n||[],e=c.mode.gcm.C(!0,e,i,n,r,o||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,o){var i=t.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(t=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(t=i,i=[]),e=c.mode.gcm.C(!1,e,i,n,r,o),!s.equal(e.tag,t))throw new c.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=(e[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(e,t,r){var n,o=r.length;for(t=t.slice(0),n=0;no&&(e=t.hash(e)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),o=o||c.misc.hmac,e=new o(e);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=e.encrypt(l.concat(t,[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,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,i,e.length]),this.c[s].update(e);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=t,this.f+=t,a===this.u&&(this.isReady()!==this.u&&Re("seeded",Math.max(this.o,this.f)),Re("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:X(this,this.ma),mouseCollector:X(this,this.oa),keyboardCollector:X(this,this.la),accelerometerCollector:X(this,this.ea),touchCollector:X(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(e,t){this.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,o=this.K[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function X(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Y=typeof j<"u"&&j.exports){try{Z=qe("crypto")}catch{Z=null}Y=V=Z}if(Y&&V.randomBytes)z=V.randomBytes(128),z=new Uint32Array(new Uint8Array(z).buffer),c.random.addEntropy(z,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;c.random.addEntropy(G,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 z,V,G,Y,Z;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var 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 e=="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=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{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function T(e,t,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(e,[])).next())})}function ue(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 C(e){return this instanceof C?(this.v=e,this):new C(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(d){n[d]&&(o[d]=function(y){return new Promise(function(g,P){i.push([d,y,g,P])>1||a(d,y)})})}function a(d,y){try{f(n[d](y))}catch(g){h(i[0][3],g)}}function f(d){d.value instanceof C?Promise.resolve(d.value.v).then(u,l):h(i[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function h(d,y){d(y),i.shift(),i.length&&a(i[0][0],i[0][1])}}function Ze(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:C(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function Qe(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 ue=="function"?ue(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(a,f){s=e[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 v=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new L(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new L(o)).catch(o=>new O(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(T(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new O(r?r(o):o)}}))}static combine(t){return et(t)}static combineWithAllErrors(t){return tt(t)}map(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new O(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);let n=yield t(r.value);return n.isErr()?new O(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new O(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new O(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new L(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 Ye(this,arguments,function*(){return yield C(yield C(yield*Ze(Qe(yield C(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},x=e=>new v(Promise.resolve(new L(e))),E=e=>new v(Promise.resolve(new O(e))),Rt=v.fromPromise,Pt=v.fromSafePromise,Tt=v.fromThrowable,le=e=>{let t=S([]);for(let r of e)if(r.isErr()){t=k(r.error);break}else t.map(n=>n.push(r.value));return t},et=e=>v.fromSafePromise(Promise.all(e)).andThen(le),de=e=>{let t=S([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=k([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},tt=e=>v.fromSafePromise(Promise.all(e)).andThen(de),ee;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return S(a)}catch(a){return k(i?i(a):a)}}}e.fromThrowable=t;function r(o){return le(o)}e.combine=r;function n(o){return de(o)}e.combineWithAllErrors=n})(ee||(ee={}));var S=e=>new L(e);function k(e){return new O(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return S(t(this.value))}mapErr(t){return S(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 S(this.value)}orElse(t){return S(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return v.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 he("Called `_unsafeUnwrapErr` on an Ok",this,t)}},O=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return k(this.error)}mapErr(t){return k(t(this.error))}andThrough(t){return k(this.error)}andTee(t){return k(this.error)}andThen(t){return k(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return E(this.error)}asyncAndThrough(t){return E(this.error)}asyncMap(t){return E(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield k(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw he("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Mt=ee.fromThrowable;var D=class extends Error{context;constructor(t,r={}){let{cause:n,context:o}=r;super(t,{cause:n}),this.name=this.constructor.name,this.context=o}};var b=class extends D{};var W=class extends b{message="An error occured while trying to connect to WebSocket"};var R=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 rt=()=>typeof Deno<"u",M=e=>rt()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var De=fe(xe());var m=new De.default,w,be=!1;self.onmessage=e=>{ut(e),be||(be=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var N=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var ut=(e,t)=>{let{action:r}=e.data;switch(r){case 0:w=new Worker(M("cancel"),{type:"module"}),w.postMessage(e.data);break;case 1:w=new Worker(M("download"),{type:"module"}),w.postMessage(e.data);break;case 2:w=new Worker(M("infos"),{type:"module"}),w.postMessage(e.data);break;case 4:w=w||new Worker(M("remove"),{type:"module"}),w.postMessage(e.data);break;case 5:{w=w||new Worker(M("upload"),{type:"module"}),w.postMessage(e.data);break}default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},_e=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var U=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),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(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),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 ht=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function F(e){return ht.Decode(e)}var lt=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function re(e){return lt.Decode(e)}var Ie=fe(Te());var _=class extends D{};var B=class extends _{message="Unable to decrypt the provided data"};var Ne=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return x(F(Ie.default.decrypt(e,r)))}catch(r){return E(new B(void 0,{cause:R(r)}))}};var Ue=(e,t)=>mt(e).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,F(t.data)),n=>new B(void 0,{cause:R(n)})));var mt=e=>v.fromPromise(crypto.subtle.importKey("raw",re(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:R(t)}));var je=(e,t)=>t.algo===void 0||t.algo===0?Ne(e,t):Ue(e,t);var A={},Be=5,vt=e=>(m.emit("UPLOAD_CANCELLED",e.success),x(void 0)),wt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Dt(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),je(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(N(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):N(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Ot(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),x(void 0))):x(void 0)})}else{let s=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new b(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Et=(e,t)=>{if(e.success)return e.j===0&&(N(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),N(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(N(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),x(void 0);{let r=new b(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},At=(e,t)=>{let r=kt(e.data),n;if(r)if(!r.action&&r.msg){let o=new b(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Et(r,t):n=vt(r);else n=wt(e.data,t);return n},Lt=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,ie=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN;var We=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},se(Q(e),e,JSON.stringify(r))},Ot=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},se(Q(e),e,JSON.stringify(t))};var se=(e,t,r)=>ie(e)?(A[e].onmessage=n=>At(n,t),A[e].send(r),x(void 0)):Fe(e).andThen(()=>se(e,t,r)),Fe=(e,t=0)=>(!ie(e)&&!Lt(e)&&(A[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{m.emit("SOCKET_OPENED")},A[e].onclose=()=>{},A[e].onerror=()=>++t<=Be?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${Be}`),Fe(e,t)):(m.emit("SOCKET_ONERROR"),E(new W(`Unable to connect to WebSocket ${e}.`)))),xt(e).andThen(()=>x(e)).orElse(r=>E(r))),xt=e=>v.fromPromise(new Promise((t,r)=>{ie(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new W)}))}),t=>R(t));var bt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,r},Q=e=>bt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString();var kt=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},Dt=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Je=!1;self.onmessage=e=>{Je||(_e(),Je=!0),m.on("DOWNLOAD_STARTED",()=>{A[Q(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),St(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var St=e=>We(e.args.lufiFile,0); +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __defNormalProp = (obj3, key, value) => key in obj3 ? __defProp(obj3, key, { enumerable: true, configurable: true, writable: true, value }) : obj3[key] = value; +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); +var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __publicField = (obj3, key, value) => __defNormalProp(obj3, typeof key !== "symbol" ? key + "" : key, value); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter2() { + EventEmitter2.init.call(this); + } + module.exports = EventEmitter2; + module.exports.once = once; + EventEmitter2.EventEmitter = EventEmitter2; + EventEmitter2.prototype._events = void 0; + EventEmitter2.prototype._eventsCount = 0; + EventEmitter2.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter2, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter2.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter2.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter2.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter2.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter2.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events2 = this._events; + if (events2 !== void 0) + doError = doError && events2.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err2 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err2.context = er; + throw err2; + } + var handler = events2[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events2; + var existing; + checkListener(listener); + events2 = target._events; + if (events2 === void 0) { + events2 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events2.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events2 = target._events; + } + existing = events2[type]; + } + if (existing === void 0) { + existing = events2[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events2[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter2.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter2.prototype.on = EventEmitter2.prototype.addListener; + EventEmitter2.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter2.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.removeListener = function removeListener(type, listener) { + var list, events2, position, i, originalListener; + checkListener(listener); + events2 = this._events; + if (events2 === void 0) + return this; + list = events2[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events2[type]; + if (events2.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events2[type] = list[0]; + if (events2.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; + EventEmitter2.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events2, i; + events2 = this._events; + if (events2 === void 0) + return this; + if (events2.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events2[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events2[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events2); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events2[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events2 = target._events; + if (events2 === void 0) + return []; + var evlistener = events2[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter2.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter2.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter2.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter2.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events2 = this._events; + if (events2 !== void 0) { + var evlistener = events2[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter2.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err2) { + emitter.removeListener(name, resolver); + reject(err2); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js +var require_sjcl = __commonJS({ + "node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js"(exports, module) { + "use strict"; + var sjcl2 = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function(a) { + this.toString = function() { + return "CORRUPT: " + this.message; + }; + this.message = a; + }, invalid: function(a) { + this.toString = function() { + return "INVALID: " + this.message; + }; + this.message = a; + }, bug: function(a) { + this.toString = function() { + return "BUG: " + this.message; + }; + this.message = a; + }, notReady: function(a) { + this.toString = function() { + return "NOT READY: " + this.message; + }; + this.message = a; + } } }; + sjcl2.cipher.aes = function(a) { + this.s[0][0][0] || this.O(); + var b, c, d, e, f = this.s[0][4], g = this.s[1]; + b = a.length; + var h = 1; + if (4 !== b && 6 !== b && 8 !== b) throw new sjcl2.exception.invalid("invalid aes key size"); + this.b = [d = a.slice(0), e = []]; + for (a = b; a < 4 * b + 28; a++) { + c = d[a - 1]; + if (0 === a % b || 8 === b && 4 === a % b) c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7)); + d[a] = d[a - b] ^ c; + } + for (b = 0; a; b++, a--) c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & 255]]; + }; + sjcl2.cipher.aes.prototype = { encrypt: function(a) { + return t(this, a, 0); + }, decrypt: function(a) { + return t(this, a, 1); + }, s: [[[], [], [], [], []], [[], [], [], [], []]], O: function() { + var a = this.s[0], b = this.s[1], c = a[4], d = b[4], e, f, g, h = [], k = [], l, n, m, p; + for (e = 0; 256 > e; e++) k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e; + for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, n = h[e = h[l = h[f]]], p = 16843009 * n ^ 65537 * e ^ 257 * l ^ 16843008 * f, n = 257 * h[m] ^ 16843008 * m, e = 0; 4 > e; e++) a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8; + for (e = 0; 5 > e; e++) a[e] = a[e].slice(0), b[e] = b[e].slice(0); + } }; + function t(a, b, c) { + if (4 !== b.length) throw new sjcl2.exception.invalid("invalid aes block size"); + var d = a.b[c], e = b[0] ^ d[0], f = b[c ? 3 : 1] ^ d[1], g = b[2] ^ d[2]; + b = b[c ? 1 : 3] ^ d[3]; + var h, k, l, n = d.length / 4 - 2, m, p = 4, r = [0, 0, 0, 0]; + h = a.s[c]; + a = h[0]; + var q = h[1], v = h[2], w = h[3], x = h[4]; + for (m = 0; m < n; m++) h = a[e >>> 24] ^ q[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ q[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], l = a[g >>> 24] ^ q[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ q[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = l; + for (m = 0; 4 > m; m++) r[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h; + return r; + } + sjcl2.bitArray = { bitSlice: function(a, b, c) { + a = sjcl2.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1); + return void 0 === c ? a : sjcl2.bitArray.clamp(a, c - b); + }, extract: function(a, b, c) { + var d = Math.floor(-b - c & 31); + return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1; + }, concat: function(a, b) { + if (0 === a.length || 0 === b.length) return a.concat(b); + var c = a[a.length - 1], d = sjcl2.bitArray.getPartial(c); + return 32 === d ? a.concat(b) : sjcl2.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1)); + }, bitLength: function(a) { + var b = a.length; + return 0 === b ? 0 : 32 * (b - 1) + sjcl2.bitArray.getPartial(a[b - 1]); + }, clamp: function(a, b) { + if (32 * a.length < b) return a; + a = a.slice(0, Math.ceil(b / 32)); + var c = a.length; + b = b & 31; + 0 < c && b && (a[c - 1] = sjcl2.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)); + return a; + }, partial: function(a, b, c) { + return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 1099511627776 * a; + }, getPartial: function(a) { + return Math.round(a / 1099511627776) || 32; + }, equal: function(a, b) { + if (sjcl2.bitArray.bitLength(a) !== sjcl2.bitArray.bitLength(b)) return false; + var c = 0, d; + for (d = 0; d < a.length; d++) c |= a[d] ^ b[d]; + return 0 === c; + }, $: function(a, b, c, d) { + var e; + e = 0; + for (void 0 === d && (d = []); 32 <= b; b -= 32) d.push(c), c = 0; + if (0 === b) return d.concat(a); + for (e = 0; e < a.length; e++) d.push(c | a[e] >>> b), c = a[e] << 32 - b; + e = a.length ? a[a.length - 1] : 0; + a = sjcl2.bitArray.getPartial(e); + d.push(sjcl2.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1)); + return d; + }, i: function(a, b) { + return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; + }, byteswapM: function(a) { + var b, c; + for (b = 0; b < a.length; ++b) c = a[b], a[b] = c >>> 24 | c >>> 8 & 65280 | (c & 65280) << 8 | c << 24; + return a; + } }; + sjcl2.codec.utf8String = { fromBits: function(a) { + var b = "", c = sjcl2.bitArray.bitLength(a), d, e; + for (d = 0; d < c / 8; d++) 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8; + return decodeURIComponent(escape(b)); + }, toBits: function(a) { + a = unescape(encodeURIComponent(a)); + var b = [], c, d = 0; + for (c = 0; c < a.length; c++) d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); + c & 3 && b.push(sjcl2.bitArray.partial(8 * (c & 3), d)); + return b; + } }; + sjcl2.codec.hex = { fromBits: function(a) { + var b = "", c; + for (c = 0; c < a.length; c++) b += ((a[c] | 0) + 263882790666240).toString(16).substr(4); + return b.substr(0, sjcl2.bitArray.bitLength(a) / 4); + }, toBits: function(a) { + var b, c = [], d; + a = a.replace(/\s|0x/g, ""); + d = a.length; + a = a + "00000000"; + for (b = 0; b < a.length; b += 8) c.push(parseInt(a.substr(b, 8), 16) ^ 0); + return sjcl2.bitArray.clamp(c, 4 * d); + } }; + sjcl2.codec.base32 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", X: "0123456789ABCDEFGHIJKLMNOPQRSTUV", BITS: 32, BASE: 5, REMAINING: 27, fromBits: function(a, b, c) { + var d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = "", g = 0, h = sjcl2.codec.base32.B, k = 0, l = sjcl2.bitArray.bitLength(a); + c && (h = sjcl2.codec.base32.X); + for (c = 0; f.length * d < l; ) f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d); + for (; f.length & 7 && !b; ) f += "="; + return f; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, "").toUpperCase(); + var c = sjcl2.codec.base32.BITS, d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = [], g, h = 0, k = sjcl2.codec.base32.B, l = 0, n, m = "base32"; + b && (k = sjcl2.codec.base32.X, m = "base32hex"); + for (g = 0; g < a.length; g++) { + n = k.indexOf(a.charAt(g)); + if (0 > n) { + if (!b) try { + return sjcl2.codec.base32hex.toBits(a); + } catch (p) { + } + throw new sjcl2.exception.invalid("this isn't " + m + "!"); + } + h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h); + } + h & 56 && f.push(sjcl2.bitArray.partial(h & 56, l, 1)); + return f; + } }; + sjcl2.codec.base32hex = { fromBits: function(a, b) { + return sjcl2.codec.base32.fromBits(a, b, 1); + }, toBits: function(a) { + return sjcl2.codec.base32.toBits(a, 1); + } }; + sjcl2.codec.base64 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", fromBits: function(a, b, c) { + var d = "", e = 0, f = sjcl2.codec.base64.B, g = 0, h = sjcl2.bitArray.bitLength(a); + c && (f = f.substr(0, 62) + "-_"); + for (c = 0; 6 * d.length < h; ) d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6); + for (; d.length & 3 && !b; ) d += "="; + return d; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, ""); + var c = [], d, e = 0, f = sjcl2.codec.base64.B, g = 0, h; + b && (f = f.substr(0, 62) + "-_"); + for (d = 0; d < a.length; d++) { + h = f.indexOf(a.charAt(d)); + if (0 > h) throw new sjcl2.exception.invalid("this isn't base64!"); + 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e); + } + e & 56 && c.push(sjcl2.bitArray.partial(e & 56, g, 1)); + return c; + } }; + sjcl2.codec.base64url = { fromBits: function(a) { + return sjcl2.codec.base64.fromBits(a, 1, 1); + }, toBits: function(a) { + return sjcl2.codec.base64.toBits(a, 1); + } }; + sjcl2.hash.sha256 = function(a) { + this.b[0] || this.O(); + a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset(); + }; + sjcl2.hash.sha256.hash = function(a) { + return new sjcl2.hash.sha256().update(a).finalize(); + }; + sjcl2.hash.sha256.prototype = { blockSize: 512, reset: function() { + this.F = this.Y.slice(0); + this.A = []; + this.l = 0; + return this; + }, update: function(a) { + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + var b, c = this.A = sjcl2.bitArray.concat(this.A, a); + b = this.l; + a = this.l = b + sjcl2.bitArray.bitLength(a); + if (9007199254740991 < a) throw new sjcl2.exception.invalid("Cannot hash more than 2^53 - 1 bits"); + if ("undefined" !== typeof Uint32Array) { + var d = new Uint32Array(c), e = 0; + for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, d.subarray( + 16 * e, + 16 * (e + 1) + )), e += 1; + c.splice(0, 16 * e); + } else for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, c.splice(0, 16)); + return this; + }, finalize: function() { + var a, b = this.A, c = this.F, b = sjcl2.bitArray.concat(b, [sjcl2.bitArray.partial(1, 1)]); + for (a = b.length + 2; a & 15; a++) b.push(0); + b.push(Math.floor(this.l / 4294967296)); + for (b.push(this.l | 0); b.length; ) u(this, b.splice(0, 16)); + this.reset(); + return c; + }, Y: [], b: [], O: function() { + function a(a2) { + return 4294967296 * (a2 - Math.floor(a2)) | 0; + } + for (var b = 0, c = 2, d, e; 64 > b; c++) { + e = true; + for (d = 2; d * d <= c; d++) if (0 === c % d) { + e = false; + break; + } + e && (8 > b && (this.Y[b] = a(Math.pow(c, 0.5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++); + } + } }; + function u(a, b) { + var c, d, e, f = a.F, g = a.b, h = f[0], k = f[1], l = f[2], n = f[3], m = f[4], p = f[5], r = f[6], q = f[7]; + for (c = 0; 64 > c; c++) 16 > c ? d = b[c] : (d = b[c + 1 & 15], e = b[c + 14 & 15], d = b[c & 15] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + b[c & 15] + b[c + 9 & 15] | 0), d = d + q + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (r ^ m & (p ^ r)) + g[c], q = r, r = p, p = m, m = n + d | 0, n = l, l = k, k = h, h = d + (k & l ^ n & (k ^ l)) + (k >>> 2 ^ k >>> 13 ^ k >>> 22 ^ k << 30 ^ k << 19 ^ k << 10) | 0; + f[0] = f[0] + h | 0; + f[1] = f[1] + k | 0; + f[2] = f[2] + l | 0; + f[3] = f[3] + n | 0; + f[4] = f[4] + m | 0; + f[5] = f[5] + p | 0; + f[6] = f[6] + r | 0; + f[7] = f[7] + q | 0; + } + sjcl2.mode.ccm = { name: "ccm", G: [], listenProgress: function(a) { + sjcl2.mode.ccm.G.push(a); + }, unListenProgress: function(a) { + a = sjcl2.mode.ccm.G.indexOf(a); + -1 < a && sjcl2.mode.ccm.G.splice(a, 1); + }, fa: function(a) { + var b = sjcl2.mode.ccm.G.slice(), c; + for (c = 0; c < b.length; c += 1) b[c](a); + }, encrypt: function(a, b, c, d, e) { + var f, g = b.slice(0), h = sjcl2.bitArray, k = h.bitLength(c) / 8, l = h.bitLength(g) / 8; + e = e || 64; + d = d || []; + if (7 > k) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (f = 2; 4 > f && l >>> 8 * f; f++) ; + f < 15 - k && (f = 15 - k); + c = h.clamp( + c, + 8 * (15 - f) + ); + b = sjcl2.mode.ccm.V(a, b, c, d, e, f); + g = sjcl2.mode.ccm.C(a, g, c, b, e, f); + return h.concat(g.data, g.tag); + }, decrypt: function(a, b, c, d, e) { + e = e || 64; + d = d || []; + var f = sjcl2.bitArray, g = f.bitLength(c) / 8, h = f.bitLength(b), k = f.clamp(b, h - e), l = f.bitSlice(b, h - e), h = (h - e) / 8; + if (7 > g) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (b = 2; 4 > b && h >>> 8 * b; b++) ; + b < 15 - g && (b = 15 - g); + c = f.clamp(c, 8 * (15 - b)); + k = sjcl2.mode.ccm.C(a, k, c, l, e, b); + a = sjcl2.mode.ccm.V(a, k.data, c, d, e, b); + if (!f.equal(k.tag, a)) throw new sjcl2.exception.corrupt("ccm: tag doesn't match"); + return k.data; + }, na: function(a, b, c, d, e, f) { + var g = [], h = sjcl2.bitArray, k = h.i; + d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)]; + d = h.concat(d, c); + d[3] |= e; + d = a.encrypt(d); + if (b.length) for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 4294967295 >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); + return d; + }, V: function(a, b, c, d, e, f) { + var g = sjcl2.bitArray, h = g.i; + e /= 8; + if (e % 2 || 4 > e || 16 < e) throw new sjcl2.exception.invalid("ccm: invalid tag length"); + if (4294967295 < d.length || 4294967295 < b.length) throw new sjcl2.exception.bug("ccm: can't deal with 4GiB or more data"); + c = sjcl2.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f); + for (d = 0; d < b.length; d += 4) c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); + return g.clamp(c, 8 * e); + }, C: function(a, b, c, d, e, f) { + var g, h = sjcl2.bitArray; + g = h.i; + var k = b.length, l = h.bitLength(b), n = k / 50, m = n; + c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4); + d = h.bitSlice(g(d, a.encrypt(c)), 0, e); + if (!k) return { tag: d, data: [] }; + for (g = 0; g < k; g += 4) g > n && (sjcl2.mode.ccm.fa(g / k), n += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3]; + return { tag: d, data: h.clamp(b, l) }; + } }; + sjcl2.mode.ocb2 = { name: "ocb2", encrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + var g, h = sjcl2.mode.ocb2.S, k = sjcl2.bitArray, l = k.i, n = [0, 0, 0, 0]; + c = h(a.encrypt(c)); + var m, p = []; + d = d || []; + e = e || 64; + for (g = 0; g + 4 < b.length; g += 4) m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c); + m = b.slice(g); + b = k.bitLength(m); + g = a.encrypt(l(c, [0, 0, 0, b])); + m = k.clamp(l(m.concat([0, 0, 0]), g), b); + n = l(n, l(m.concat([0, 0, 0]), g)); + n = a.encrypt(l(n, l(c, h(c)))); + d.length && (n = l(n, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + return p.concat(k.concat(m, k.clamp(n, e))); + }, decrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + e = e || 64; + var g = sjcl2.mode.ocb2.S, h = sjcl2.bitArray, k = h.i, l = [0, 0, 0, 0], n = g(a.encrypt(c)), m, p, r = sjcl2.bitArray.bitLength(b) - e, q = []; + d = d || []; + for (c = 0; c + 4 < r / 32; c += 4) m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n); + p = r - 32 * c; + m = a.encrypt(k(n, [0, 0, 0, p])); + m = k(m, h.clamp(b.slice(c), p).concat([ + 0, + 0, + 0 + ])); + l = k(l, m); + l = a.encrypt(k(l, k(n, g(n)))); + d.length && (l = k(l, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl2.exception.corrupt("ocb: tag doesn't match"); + return q.concat(h.clamp(m, p)); + }, pmac: function(a, b) { + var c, d = sjcl2.mode.ocb2.S, e = sjcl2.bitArray, f = e.i, g = [0, 0, 0, 0], h = a.encrypt([0, 0, 0, 0]), h = f(h, d(d(h))); + for (c = 0; c + 4 < b.length; c += 4) h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4)))); + c = b.slice(c); + 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0])); + g = f(g, c); + return a.encrypt(f(d(f(h, d(h))), g)); + }, S: function(a) { + return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)]; + } }; + sjcl2.mode.gcm = { name: "gcm", encrypt: function(a, b, c, d, e) { + var f = b.slice(0); + b = sjcl2.bitArray; + d = d || []; + a = sjcl2.mode.gcm.C(true, a, f, d, c, e || 128); + return b.concat(a.data, a.tag); + }, decrypt: function(a, b, c, d, e) { + var f = b.slice(0), g = sjcl2.bitArray, h = g.bitLength(f); + e = e || 128; + d = d || []; + e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []); + a = sjcl2.mode.gcm.C(false, a, f, d, c, e); + if (!g.equal(a.tag, b)) throw new sjcl2.exception.corrupt("gcm: tag doesn't match"); + return a.data; + }, ka: function(a, b) { + var c, d, e, f, g, h = sjcl2.bitArray.i; + e = [ + 0, + 0, + 0, + 0 + ]; + f = b.slice(0); + for (c = 0; 128 > c; c++) { + (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f)); + g = 0 !== (f[3] & 1); + for (d = 3; 0 < d; d--) f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31; + f[0] >>>= 1; + g && (f[0] ^= -520093696); + } + return e; + }, j: function(a, b, c) { + var d, e = c.length; + b = b.slice(0); + for (d = 0; d < e; d += 4) b[0] ^= 4294967295 & c[d], b[1] ^= 4294967295 & c[d + 1], b[2] ^= 4294967295 & c[d + 2], b[3] ^= 4294967295 & c[d + 3], b = sjcl2.mode.gcm.ka(b, a); + return b; + }, C: function(a, b, c, d, e, f) { + var g, h, k, l, n, m, p, r, q = sjcl2.bitArray; + m = c.length; + p = q.bitLength(c); + r = q.bitLength(d); + h = q.bitLength(e); + g = b.encrypt([0, 0, 0, 0]); + 96 === h ? (e = e.slice(0), e = q.concat(e, [1])) : (e = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], e), e = sjcl2.mode.gcm.j(g, e, [0, 0, Math.floor(h / 4294967296), h & 4294967295])); + h = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], d); + n = e.slice(0); + d = h.slice(0); + a || (d = sjcl2.mode.gcm.j(g, h, c)); + for (l = 0; l < m; l += 4) n[3]++, k = b.encrypt(n), c[l] ^= k[0], c[l + 1] ^= k[1], c[l + 2] ^= k[2], c[l + 3] ^= k[3]; + c = q.clamp(c, p); + a && (d = sjcl2.mode.gcm.j(g, h, c)); + a = [Math.floor(r / 4294967296), r & 4294967295, Math.floor(p / 4294967296), p & 4294967295]; + d = sjcl2.mode.gcm.j(g, d, a); + k = b.encrypt(e); + d[0] ^= k[0]; + d[1] ^= k[1]; + d[2] ^= k[2]; + d[3] ^= k[3]; + return { tag: q.bitSlice(d, 0, f), data: c }; + } }; + sjcl2.misc.hmac = function(a, b) { + this.W = b = b || sjcl2.hash.sha256; + var c = [[], []], d, e = b.prototype.blockSize / 32; + this.w = [new b(), new b()]; + a.length > e && (a = b.hash(a)); + for (d = 0; d < e; d++) c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828; + this.w[0].update(c[0]); + this.w[1].update(c[1]); + this.R = new b(this.w[0]); + }; + sjcl2.misc.hmac.prototype.encrypt = sjcl2.misc.hmac.prototype.mac = function(a) { + if (this.aa) throw new sjcl2.exception.invalid("encrypt on already updated hmac called!"); + this.update(a); + return this.digest(a); + }; + sjcl2.misc.hmac.prototype.reset = function() { + this.R = new this.W(this.w[0]); + this.aa = false; + }; + sjcl2.misc.hmac.prototype.update = function(a) { + this.aa = true; + this.R.update(a); + }; + sjcl2.misc.hmac.prototype.digest = function() { + var a = this.R.finalize(), a = new this.W(this.w[1]).update(a).finalize(); + this.reset(); + return a; + }; + sjcl2.misc.pbkdf2 = function(a, b, c, d, e) { + c = c || 1e4; + if (0 > d || 0 > c) throw new sjcl2.exception.invalid("invalid params to pbkdf2"); + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + e = e || sjcl2.misc.hmac; + a = new e(a); + var f, g, h, k, l = [], n = sjcl2.bitArray; + for (k = 1; 32 * l.length < (d || 1); k++) { + e = f = a.encrypt(n.concat(b, [k])); + for (g = 1; g < c; g++) for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h]; + l = l.concat(e); + } + d && (l = n.clamp(l, d)); + return l; + }; + sjcl2.prng = function(a) { + this.c = [new sjcl2.hash.sha256()]; + this.m = [0]; + this.P = 0; + this.H = {}; + this.N = 0; + this.U = {}; + this.Z = this.f = this.o = this.ha = 0; + this.b = [0, 0, 0, 0, 0, 0, 0, 0]; + this.h = [0, 0, 0, 0]; + this.L = void 0; + this.M = a; + this.D = false; + this.K = { progress: {}, seeded: {} }; + this.u = this.ga = 0; + this.I = 1; + this.J = 2; + this.ca = 65536; + this.T = [0, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024]; + this.da = 3e4; + this.ba = 80; + }; + sjcl2.prng.prototype = { + randomWords: function(a, b) { + var c = [], d; + d = this.isReady(b); + var e; + if (d === this.u) throw new sjcl2.exception.notReady("generator isn't seeded"); + if (d & this.J) { + d = !(d & this.I); + e = []; + var f = 0, g; + this.Z = e[0] = (/* @__PURE__ */ new Date()).valueOf() + this.da; + for (g = 0; 16 > g; g++) e.push(4294967296 * Math.random() | 0); + for (g = 0; g < this.c.length && (e = e.concat(this.c[g].finalize()), f += this.m[g], this.m[g] = 0, d || !(this.P & 1 << g)); g++) ; + this.P >= 1 << this.c.length && (this.c.push(new sjcl2.hash.sha256()), this.m.push(0)); + this.f -= f; + f > this.o && (this.o = f); + this.P++; + this.b = sjcl2.hash.sha256.hash(this.b.concat(e)); + this.L = new sjcl2.cipher.aes(this.b); + for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) ; + } + for (d = 0; d < a; d += 4) 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]); + y(this); + return c.slice(0, a); + }, + setDefaultParanoia: function(a, b) { + if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) throw new sjcl2.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); + this.M = a; + }, + addEntropy: function(a, b, c) { + c = c || "user"; + var d, e, f = (/* @__PURE__ */ new Date()).valueOf(), g = this.H[c], h = this.isReady(), k = 0; + d = this.U[c]; + void 0 === d && (d = this.U[c] = this.ha++); + void 0 === g && (g = this.H[c] = 0); + this.H[c] = (this.H[c] + 1) % this.c.length; + switch (typeof a) { + case "number": + void 0 === b && (b = 1); + this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]); + break; + case "object": + c = Object.prototype.toString.call(a); + if ("[object Uint32Array]" === c) { + e = []; + for (c = 0; c < a.length; c++) e.push(a[c]); + a = e; + } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) "number" !== typeof a[c] && (k = 1); + if (!k) { + if (void 0 === b) for (c = b = 0; c < a.length; c++) for (e = a[c]; 0 < e; ) b++, e = e >>> 1; + this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a)); + } + break; + case "string": + void 0 === b && (b = a.length); + this.c[g].update([d, this.N++, 3, b, f, a.length]); + this.c[g].update(a); + break; + default: + k = 1; + } + if (k) throw new sjcl2.exception.bug("random: addEntropy only supports number, array of numbers or string"); + this.m[g] += b; + this.f += b; + h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress())); + }, + isReady: function(a) { + a = this.T[void 0 !== a ? a : this.M]; + return this.o && this.o >= a ? this.m[0] > this.ba && (/* @__PURE__ */ new Date()).valueOf() > this.Z ? this.J | this.I : this.I : this.f >= a ? this.J | this.u : this.u; + }, + getProgress: function(a) { + a = this.T[a ? a : this.M]; + return this.o >= a ? 1 : this.f > a ? 1 : this.f / a; + }, + startCollectors: function() { + if (!this.D) { + this.a = { loadTimeCollector: B(this, this.ma), mouseCollector: B(this, this.oa), keyboardCollector: B(this, this.la), accelerometerCollector: B(this, this.ea), touchCollector: B(this, this.qa) }; + if (window.addEventListener) window.addEventListener( + "load", + this.a.loadTimeCollector, + false + ), window.addEventListener("mousemove", this.a.mouseCollector, false), window.addEventListener("keypress", this.a.keyboardCollector, false), window.addEventListener("devicemotion", this.a.accelerometerCollector, false), window.addEventListener("touchmove", this.a.touchCollector, false); + 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 sjcl2.exception.bug("can't attach event"); + this.D = true; + } + }, + stopCollectors: function() { + this.D && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, false), window.removeEventListener("mousemove", this.a.mouseCollector, false), window.removeEventListener("keypress", this.a.keyboardCollector, false), window.removeEventListener("devicemotion", this.a.accelerometerCollector, false), window.removeEventListener("touchmove", this.a.touchCollector, false)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent( + "onmousemove", + this.a.mouseCollector + ), document.detachEvent("keypress", this.a.keyboardCollector)), this.D = false); + }, + addEventListener: function(a, b) { + this.K[a][this.ga++] = b; + }, + removeEventListener: function(a, b) { + var c, d, e = this.K[a], f = []; + for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d); + for (c = 0; c < f.length; c++) d = f[c], delete e[d]; + }, + la: function() { + C(this, 1); + }, + oa: function(a) { + var b, c; + try { + b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0; + } catch (d) { + c = b = 0; + } + 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); + C(this, 0); + }, + qa: function(a) { + a = a.touches[0] || a.changedTouches[0]; + this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); + C(this, 0); + }, + ma: function() { + C(this, 2); + }, + ea: function(a) { + a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; + if (window.orientation) { + var b = window.orientation; + "number" === typeof b && this.addEntropy(b, 1, "accelerometer"); + } + a && this.addEntropy(a, 2, "accelerometer"); + C(this, 0); + } + }; + function A(a, b) { + var c, d = sjcl2.random.K[a], e = []; + for (c in d) d.hasOwnProperty(c) && e.push(d[c]); + for (c = 0; c < e.length; c++) e[c](b); + } + function C(a, b) { + "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy((/* @__PURE__ */ new Date()).valueOf(), b, "loadtime"); + } + function y(a) { + a.b = z(a).concat(z(a)); + a.L = new sjcl2.cipher.aes(a.b); + } + function z(a) { + for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) ; + return a.L.encrypt(a.h); + } + function B(a, b) { + return function() { + b.apply(a, arguments); + }; + } + sjcl2.random = new sjcl2.prng(6); + a: try { + if (G = "undefined" !== typeof module && module.exports) { + try { + H = __require("crypto"); + } catch (a) { + H = null; + } + G = E = H; + } + if (G && E.randomBytes) D = E.randomBytes(128), D = new Uint32Array(new Uint8Array(D).buffer), sjcl2.random.addEntropy(D, 1024, "crypto['randomBytes']"); + else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { + F = new Uint32Array(32); + if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F); + else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F); + else break a; + sjcl2.random.addEntropy(F, 1024, "crypto['getRandomValues']"); + } + } catch (a) { + "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a)); + } + var D; + var E; + var F; + var G; + var H; + sjcl2.json = { defaults: { v: 1, iter: 1e4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, ja: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json, f = e.g({ iv: sjcl2.random.randomWords(4, 0) }, e.defaults), g; + e.g(f, c); + c = f.adata; + "string" === typeof f.salt && (f.salt = sjcl2.codec.base64.toBits(f.salt)); + "string" === typeof f.iv && (f.iv = sjcl2.codec.base64.toBits(f.iv)); + if (!sjcl2.mode[f.mode] || !sjcl2.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 256 !== f.ks || 2 > f.iv.length || 4 < f.iv.length) throw new sjcl2.exception.invalid("json encrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + "string" === typeof c && (f.adata = c = sjcl2.codec.utf8String.toBits(c)); + g = new sjcl2.cipher[f.cipher](a); + e.g(d, f); + d.key = a; + f.ct = "ccm" === f.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl2.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); + return f; + }, encrypt: function(a, b, c, d) { + var e = sjcl2.json, f = e.ja.apply(e, arguments); + return e.encode(f); + }, ia: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json; + b = e.g(e.g(e.g({}, e.defaults), b), c, true); + var f, g; + f = b.adata; + "string" === typeof b.salt && (b.salt = sjcl2.codec.base64.toBits(b.salt)); + "string" === typeof b.iv && (b.iv = sjcl2.codec.base64.toBits(b.iv)); + if (!sjcl2.mode[b.mode] || !sjcl2.cipher[b.cipher] || "string" === typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 256 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) throw new sjcl2.exception.invalid("json decrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.secretKey && (a = a.unkem(sjcl2.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); + "string" === typeof f && (f = sjcl2.codec.utf8String.toBits(f)); + g = new sjcl2.cipher[b.cipher](a); + f = "ccm" === b.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl2.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); + e.g(d, b); + d.key = a; + return 1 === c.raw ? f : sjcl2.codec.utf8String.fromBits(f); + }, decrypt: function(a, b, c, d) { + var e = sjcl2.json; + return e.ia(a, e.decode(b), c, d); + }, encode: function(a) { + var b, c = "{", d = ""; + for (b in a) if (a.hasOwnProperty(b)) { + if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl2.exception.invalid("json encode: invalid property name"); + c += d + '"' + b + '":'; + d = ","; + switch (typeof a[b]) { + case "number": + case "boolean": + c += a[b]; + break; + case "string": + c += '"' + escape(a[b]) + '"'; + break; + case "object": + c += '"' + sjcl2.codec.base64.fromBits(a[b], 0) + '"'; + break; + default: + throw new sjcl2.exception.bug("json encode: unsupported type"); + } + } + return c + "}"; + }, decode: function(a) { + a = a.replace(/\s/g, ""); + if (!a.match(/^\{.*\}$/)) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + a = a.replace(/^\{|\}$/g, "").split(/,/); + var b = {}, c, d; + for (c = 0; c < a.length; c++) { + if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl2.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]); + } + return b; + }, g: function(a, b, c) { + void 0 === a && (a = {}); + if (void 0 === b) return a; + for (var d in b) if (b.hasOwnProperty(d)) { + if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl2.exception.invalid("required parameter overridden"); + a[d] = b[d]; + } + return a; + }, sa: function(a, b) { + var c = {}, d; + for (d in a) a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); + return c; + }, ra: function(a, b) { + var c = {}, d; + for (d = 0; d < b.length; d++) void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); + return c; + } }; + sjcl2.encrypt = sjcl2.json.encrypt; + sjcl2.decrypt = sjcl2.json.decrypt; + sjcl2.misc.pa = {}; + sjcl2.misc.cachedPbkdf2 = function(a, b) { + var c = sjcl2.misc.pa, d; + b = b || {}; + d = b.iter || 1e3; + c = c[a] = c[a] || {}; + d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl2.random.randomWords(2, 0) }; + c = void 0 === b.salt ? d.firstSalt : b.salt; + d[c] = d[c] || sjcl2.misc.pbkdf2(a, c, b.iter); + return { key: d[c].slice(0), salt: c.slice(0) }; + }; + "undefined" !== typeof module && module.exports && (module.exports = sjcl2); + "function" === typeof define && define([], function() { + return sjcl2; + }); + } +}); + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var okAsync = (value) => new ResultAsync(Promise.resolve(new Ok(value))); +var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result2) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result2.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result2.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result2.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err2) { + return new Err(err2); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err2) { + return err2(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/error/base-error.ts +var BaseError = class extends Error { + constructor(message, options = {}) { + const { cause, context } = options; + super(message, { cause }); + __publicField(this, "context"); + this.name = this.constructor.name; + this.context = context; + } +}; + +// src/error/websocket/websocket-error.ts +var WebSocketError = class extends BaseError { +}; + +// src/error/websocket/websocket-connection-error.ts +var WebSocketConnectionError = class extends WebSocketError { + constructor() { + super(...arguments); + __publicField(this, "message", "An error occured while trying to connect to WebSocket"); + } +}; + +// src/utils.ts +var ensureError = (value) => { + if (value instanceof Error) return value; + let stringified = "[Unable to stringify the thrown value]"; + try { + stringified = JSON.stringify(value); + } catch (_error) { + } + const error = new Error(stringified); + return error; +}; +var isDenoRuntime = () => typeof Deno !== "undefined"; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); + +// src/worker/main.ts +var import_events = __toESM(require_events()); +var events = new import_events.default(); +var worker; +var isInitialized = false; +self.onmessage = (event) => { + addWorker(event); + if (!isInitialized) { + isInitialized = true; + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + if (worker) { + worker.terminate(); + } + }); + } +}; +var updateFile = (lufiFile, args) => { + Object.assign(lufiFile, args); + if (typeof WorkerGlobalScope !== "undefined") { + self.postMessage({ + event: "FILE_UPDATED" /* FILE_UPDATED */, + lufiFile + }); + } + return lufiFile; +}; +var addWorker = (event, callback) => { + const { action } = event.data; + if (action === 5 /* PAUSE */ || action === 8 /* RESUME */) { + worker.postMessage(event.data); + } else { + switch (action) { + case 2 /* CANCEL */: + { + worker = new Worker(workerUrl("cancel"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 3 /* DOWNLOAD */: + { + worker = new Worker(workerUrl("download"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 4 /* INFOS */: + { + worker = new Worker(workerUrl("infos"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 7 /* REMOVE */: + { + worker = worker || new Worker(workerUrl("remove"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 9 /* UPLOAD */: + { + worker = worker || new Worker(workerUrl("upload"), { type: "module" }); + worker.postMessage(event.data); + } + break; + default: { + console.error("Action not found"); + } + } + worker.onmessage = (e) => { + if (callback) callback(e); + self.postMessage(e.data); + }; + worker.onerror = (error) => { + console.error(`Error: ${error.message}`); + }; + } +}; +var init = () => { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + self.postMessage({ + event: "SOCKET_OPENED" /* SOCKET_OPENED */ + }); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); + }); +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/encoding.js +var Encoding = class { + /** + * + * @param charset Charset to use for base64 encoding. This must be 64-characters long. + * @param noPadding If true, encoded strings won't include padding. + */ + constructor(charset, noPadding) { + if (!charset || charset.length != 64) { + throw Error("Charset must contain 64 characters"); + } + this._charset = charset; + this._noPadding = !!noPadding; + this._valid = new RegExp("^[" + this._charset.replace("-", "\\-") + "]+={0,2}$"); + } + /** + * Encode an ArrayBuffer to base64 in a string. + * @param ab Data to encode to base64 + * @returns Base64-encoded string + */ + Encode(ab) { + const len = ab.byteLength; + if (!len) { + return ""; + } + const view = new Uint8Array(ab); + let res = ""; + for (let i = 0; i < len; i += 3) { + res += this._charset[view[i] >> 2] + this._charset[(view[i] & 3) << 4 | view[i + 1] >> 4] + this._charset[(view[i + 1] & 15) << 2 | view[i + 2] >> 6] + this._charset[view[i + 2] & 63]; + } + if (len % 3 == 2) { + res = res.substring(0, res.length - 1); + if (!this._noPadding) { + res += "="; + } + } else if (len % 3 == 1) { + res = res.substring(0, res.length - 2); + if (!this._noPadding) { + res += "=="; + } + } + return res; + } + /** + * Decode a string from base64. Padding is always optional. + * @param str Base64-encoded string + * @returns Data decoded from the base64 string + */ + Decode(str) { + str = (str || "").replace(/[\s]/g, ""); + if (!str) { + return new ArrayBuffer(0); + } + if (!this._valid.test(str)) { + throw Error("Invalid base64 input sequence"); + } + let viewLen = Math.floor(str.length * 0.75); + if (str[str.length - 2] == "=") { + viewLen -= 2; + } else if (str[str.length - 1] == "=") { + viewLen--; + } + const view = new Uint8Array(viewLen); + let enc1, enc2, enc3, enc4, i = 0, j = 0; + while (i < str.length * 0.75) { + enc1 = this._charset.indexOf(str.charAt(j++)); + enc2 = this._charset.indexOf(str.charAt(j++)); + enc3 = this._charset.indexOf(str.charAt(j++)); + enc4 = this._charset.indexOf(str.charAt(j++)); + view[i++] = enc1 << 2 | enc2 >> 4; + view[i++] = (enc2 & 15) << 4 | enc3 >> 2; + view[i++] = (enc3 & 3) << 6 | enc4; + } + return view.buffer; + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/standard.js +var obj = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +function Decode(str) { + return obj.Decode(str); +} + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/url.js +var obj2 = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", true); +function Decode2(str) { + return obj2.Decode(str); +} + +// src/api/crypto/sjcl.ts +var import_sjcl = __toESM(require_sjcl()); + +// src/error/crypto/crypto-error.ts +var CryptoError = class extends BaseError { +}; + +// src/error/crypto/decryption-error.ts +var DecryptionError = class extends CryptoError { + constructor() { + super(...arguments); + __publicField(this, "message", "Unable to decrypt the provided data"); + } +}; + +// src/api/crypto/sjcl.ts +var decrypt = (key, encryptedData) => { + try { + const data = typeof encryptedData === "string" ? encryptedData : encryptedData.data; + return okAsync(Decode(import_sjcl.default.decrypt(key, data))); + } catch (error) { + return errAsync( + new DecryptionError(void 0, { cause: ensureError(error) }) + ); + } +}; + +// src/api/crypto/web.ts +var decrypt2 = (key, encrypted) => { + return importKey(key).andThen( + (importedKey) => ResultAsync.fromPromise( + crypto.subtle.decrypt( + { + name: "AES-GCM", + iv: encrypted.iv + }, + importedKey, + Decode(encrypted.data) + ), + (error) => new DecryptionError(void 0, { cause: ensureError(error) }) + ) + ); +}; +var importKey = (key) => { + return ResultAsync.fromPromise( + crypto.subtle.importKey( + "raw", + Decode2(key), + { name: "AES-GCM" }, + false, + [ + "encrypt", + "decrypt" + ] + ), + (error) => new CryptoError("Unable to import cryptography key", { + cause: ensureError(error) + }) + ); +}; + +// src/api/crypto.ts +var decrypt3 = (key, value) => { + return value.algo === void 0 || value.algo === 0 /* Sjcl */ ? decrypt(key, value) : decrypt2(key, value); +}; + +// src/api/websocket.ts +var sockets = {}; +var MAX_ERRORS = 5; +var onCancelMessage = (data) => { + events.emit("UPLOAD_CANCELLED" /* UPLOAD_CANCELLED */, data.success); + return okAsync(void 0); +}; +var onDownloadMessage = (response, lufiFile) => { + const result = response.split("XXMOJOXX"); + const metadataString = result.shift(); + if (metadataString !== void 0) { + const metadata = JSON.parse(metadataString); + if (isServerDownloadChunkSuccessMetadata(metadata)) { + const dataString = result.shift(); + if (dataString) { + const encryptedData = JSON.parse(dataString); + if (encryptedData.iv) { + encryptedData.iv = new Uint8Array(Object.values(encryptedData.iv)); + } + return decrypt3(lufiFile.keys.client, encryptedData).andThen( + (decryptedPart) => { + const chunk = typeof decryptedPart === "string" ? new TextEncoder().encode(decryptedPart).buffer : decryptedPart; + if (metadata.part === 0) { + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + delAtFirstView: metadata.del_at_first_view, + delay: metadata.delay, + name: metadata.name, + size: metadata.size, + totalChunks: metadata.total, + type: metadata.type, + zipped: metadata.zipped + }); + events.emit("DOWNLOAD_STARTED" /* DOWNLOAD_STARTED */); + } else { + updateFile(lufiFile, { chunksReady: lufiFile.chunksReady + 1 }); + } + events.emit("CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, chunk, metadata.part); + if (++metadata.part === metadata.total) { + return endDownload(lufiFile).andThen(() => { + events.emit("DOWNLOAD_COMPLETE" /* DOWNLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + return okAsync(void 0); + }); + } + return okAsync(void 0); + } + ); + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError(metadata.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onUploadMessage = (response, lufiFile) => { + if (response.success) { + if (response.j === 0) { + updateFile(lufiFile, { + keys: { client: lufiFile.keys.client, server: response.short }, + actionToken: response.token, + queueIndex: response.i + }); + events.emit("UPLOAD_STARTED" /* UPLOAD_STARTED */); + } + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + createdAt: response.created_at + }); + events.emit("CHUNK_UPLOADED" /* CHUNK_UPLOADED */); + if (lufiFile.chunksReady === lufiFile.totalChunks) { + updateFile(lufiFile, { uploadStatus: 1 /* COMPLETE */ }); + events.emit("UPLOAD_COMPLETE" /* UPLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + } + return okAsync(void 0); + } else { + const error = new WebSocketError(response.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onMessage = (e, lufiFile) => { + const data = tryParseJson(e.data); + let callback; + if (data) { + if (!data.action && data.msg) { + const error = new WebSocketError(data.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } else { + if ("delay" in data) { + callback = onUploadMessage(data, lufiFile); + } else { + callback = onCancelMessage(data); + } + } + } else { + callback = onDownloadMessage(e.data, lufiFile); + } + return callback; +}; +var isConnecting = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.CONNECTING; +var isSpawned = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.OPEN; +var downloadChunk = (lufiFile, chunkNumber) => { + let message; + if (lufiFile.password) { + message = { part: chunkNumber, file_pwd: lufiFile.password }; + } else { + message = { part: chunkNumber }; + } + return sendMessage( + downloadSocketUrl(lufiFile), + lufiFile, + JSON.stringify(message) + ); +}; +var endDownload = (lufiFile) => { + let message; + if (lufiFile.password) { + message = { ended: true, file_pwd: lufiFile.password }; + } else { + message = { ended: true }; + } + return sendMessage( + downloadSocketUrl(lufiFile), + lufiFile, + JSON.stringify(message) + ); +}; +var sendMessage = (socketUrl, lufiFile, message) => { + if (!isSpawned(socketUrl)) { + return spawn(socketUrl).andThen( + () => sendMessage(socketUrl, lufiFile, message) + ); + } else { + sockets[socketUrl].onmessage = (e) => onMessage(e, lufiFile); + sockets[socketUrl].send(message); + return okAsync(void 0); + } +}; +var spawn = (socketKey, errorCount = 0) => { + if (!isSpawned(socketKey) && !isConnecting(socketKey)) { + sockets[socketKey] = new WebSocket(socketKey); + events.once("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */, () => { + sockets[socketKey].close(); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + }); + sockets[socketKey].onopen = () => { + events.emit("SOCKET_OPENED" /* SOCKET_OPENED */); + }; + sockets[socketKey].onclose = () => { + }; + sockets[socketKey].onerror = () => { + if (++errorCount <= MAX_ERRORS) { + console.error( + `An error happened while trying to connect to WebSocket ${socketKey}. Trying again. ${errorCount} / ${MAX_ERRORS}` + ); + return spawn(socketKey, errorCount); + } else { + events.emit("SOCKET_ONERROR" /* SOCKET_ONERROR */); + return errAsync( + new WebSocketConnectionError( + `Unable to connect to WebSocket ${socketKey}.` + ) + ); + } + }; + } + return waitForConnection(socketKey).andThen(() => okAsync(socketKey)).orElse((error) => errAsync(error)); +}; +var waitForConnection = (socketKey) => ResultAsync.fromPromise( + new Promise((resolve, reject) => { + if (!isSpawned(socketKey)) { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + resolve(void 0); + }); + events.on("SOCKET_ONERROR" /* SOCKET_ONERROR */, () => { + reject(new WebSocketConnectionError()); + }); + } else { + resolve(void 0); + } + }), + (error) => { + return ensureError(error); + } +); +var buildSocketUrl = (instanceUrl, pathname) => { + const url = new URL(instanceUrl); + url.protocol = url.protocol === "http:" ? "ws:" : "wss:"; + url.pathname += pathname; + return new URL(url.origin + url.pathname); +}; +var downloadSocketUrl = (lufiFile) => { + return buildSocketUrl( + new URL(lufiFile.serverUrl), + "download" /* DOWNLOAD */ + `/${lufiFile.keys.server}` + ).toString(); +}; +var tryParseJson = (data) => { + try { + const parsedObject = JSON.parse(data); + if (parsedObject && typeof parsedObject === "object") { + return parsedObject; + } + } catch (_e) { + } + return false; +}; +var isServerDownloadChunkSuccessMetadata = (message) => { + return typeof message === "object" && message !== null && !("msg" in message); +}; + +// src/worker/infos.ts +var isInitiated = false; +self.onmessage = (event) => { + if (!isInitiated) { + init(); + isInitiated = true; + } + events.on("DOWNLOAD_STARTED" /* DOWNLOAD_STARTED */, () => { + sockets[downloadSocketUrl(event.data.args.lufiFile)].close(); + self.postMessage({ event: "INFOS_RETRIEVED" /* INFOS_RETRIEVED */ }); + }); + retrieveInfos(event.data).mapErr((error) => { + self.postMessage({ + event: "OPERATION_FAILED" /* OPERATION_FAILED */, + error + }); + }); +}; +var retrieveInfos = (workerMessage) => downloadChunk(workerMessage.args.lufiFile, 0); diff --git a/themes/default/public/js/worker/main.js b/themes/default/public/js/worker/main.js index 3cdbc18..bdaf6bf 100644 --- a/themes/default/public/js/worker/main.js +++ b/themes/default/public/js/worker/main.js @@ -1 +1,934 @@ -var Y=Object.create;var C=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var ne=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var oe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ee(e))!te.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=V(e,o))||n.enumerable});return r};var ie=(r,e,t)=>(t=r!=null?Y(re(r)):{},oe(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var $=ne((Oe,k)=>{"use strict";var g=typeof Reflect=="object"?Reflect:null,R=g&&typeof g.apply=="function"?g.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},D;g&&typeof g.ownKeys=="function"?D=g.ownKeys:Object.getOwnPropertySymbols?D=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:D=function(e){return Object.getOwnPropertyNames(e)};function se(r){console&&console.warn&&console.warn(r)}var N=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}k.exports=u;k.exports.once=ce;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var S=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(u,"defaultMaxListeners",{enumerable:!0,get:function(){return S},set:function(r){if(typeof r!="number"||r<0||N(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");S=r}});u.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};u.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||N(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 F(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return F(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(l===void 0)return!1;if(typeof l=="function")R(l,this,t);else for(var d=l.length,p=H(l,d),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=e,a.count=i.length,se(a)}return r}u.prototype.addListener=function(e,t){return U(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return U(this,e,t,!0)};function ue(){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=ue.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return A(t),this.on(e,W(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return A(t),this.prependListener(e,W(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,s,i,a;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){a=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():ae(n,s),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};u.prototype.off=u.prototype.removeListener;u.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 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?fe(o):H(o,o.length)}u.prototype.listeners=function(e){return j(this,e,!0)};u.prototype.rawListeners=function(e){return j(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):J.call(r,e)};u.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}u.prototype.eventNames=function(){return this._eventsCount>0?D(this._events):[]};function H(r,e){for(var t=new Array(e),n=0;n(i[i.CANCEL=0]="CANCEL",i[i.DOWNLOAD=1]="DOWNLOAD",i[i.INFOS=2]="INFOS",i[i.PROVIDE_FILE=3]="PROVIDE_FILE",i[i.REMOVE=4]="REMOVE",i[i.UPLOAD=5]="UPLOAD",i))(M||{});var he={withStackTrace:!1},G=(r,e,t=he)=>{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 O(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 a(p){try{d(n.next(p))}catch(L){i(L)}}function l(p){try{d(n.throw(p))}catch(L){i(L)}}function d(p){p.done?s(p.value):o(p.value).then(a,l)}d((n=n.apply(r,[])).next())})}function B(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 E(r){return this instanceof E?(this.v=r,this):new E(r)}function pe(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(f){n[f]&&(o[f]=function(_){return new Promise(function(P,X){s.push([f,_,P,X])>1||a(f,_)})})}function a(f,_){try{l(n[f](_))}catch(P){L(s[0][3],P)}}function l(f){f.value instanceof E?Promise.resolve(f.value.v).then(d,p):L(s[0][2],f)}function d(f){a("next",f)}function p(f){a("throw",f)}function L(f,_){f(_),s.shift(),s.length&&a(s[0][0],s[0][1])}}function me(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:E(r[o](i)),done:o==="return"}:s?s(i):i}:s}}function de(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 B=="function"?B(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(a,l){i=r[s](i),o(a,l,i.done,i.value)})}}function o(s,i,a,l){Promise.resolve(l).then(function(d){s({value:d,done:a})},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 h(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(O(this,void 0,void 0,function*(){try{return new m(yield e(...n))}catch(o){return new h(t?t(o):o)}}))}static combine(e){return ve(e)}static combineWithAllErrors(e){return we(e)}map(e){return new r(this._promise.then(t=>O(this,void 0,void 0,function*(){return t.isErr()?new h(t.error):new m(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>O(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);let n=yield e(t.value);return n.isErr()?new h(n.error):new m(t.value)})))}andTee(e){return new r(this._promise.then(t=>O(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);try{yield e(t.value)}catch{}return new m(t.value)})))}mapErr(e){return new r(this._promise.then(t=>O(this,void 0,void 0,function*(){return t.isOk()?new m(t.value):new h(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new h(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>O(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 pe(this,arguments,function*(){return yield E(yield E(yield*me(de(yield E(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var x=r=>new v(Promise.resolve(new h(r))),xe=v.fromPromise,Pe=v.fromSafePromise,ke=v.fromThrowable,q=r=>{let e=y([]);for(let t of r)if(t.isErr()){e=w(t.error);break}else e.map(n=>n.push(t.value));return e},ve=r=>v.fromSafePromise(Promise.all(r)).andThen(q),z=r=>{let e=y([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=w([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},we=r=>v.fromSafePromise(Promise.all(r)).andThen(z),I;(function(r){function e(o,s){return(...i)=>{try{let a=o(...i);return y(a)}catch(a){return w(s?s(a):a)}}}r.fromThrowable=e;function t(o){return q(o)}r.combine=t;function n(o){return z(o)}r.combineWithAllErrors=n})(I||(I={}));var y=r=>new m(r);function w(r){return new h(r)}var m=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return y(e(this.value))}mapErr(e){return y(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 y(this.value)}orElse(e){return y(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 G("Called `_unsafeUnwrapErr` on an Ok",this,e)}},h=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return w(this.error)}mapErr(e){return w(e(this.error))}andThrough(e){return w(this.error)}andTee(e){return w(this.error)}andThen(e){return w(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return x(this.error)}asyncAndThrough(e){return x(this.error)}asyncMap(e){return x(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield w(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw G("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Me=I.fromThrowable;var Ee=()=>typeof Deno<"u",b=r=>Ee()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var T=new Z.default,c,Q=!1;self.onmessage=r=>{_e(r),Q||(Q=!0,T.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Le=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),Qe=(r,e)=>{Le(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},_e=(r,e)=>{let{action:t}=r.data;switch(t){case 0:c=new Worker(b("cancel"),{type:"module"}),c.postMessage(r.data);break;case 1:c=new Worker(b("download"),{type:"module"}),c.postMessage(r.data);break;case 2:c=new Worker(b("infos"),{type:"module"}),c.postMessage(r.data);break;case 4:c=c||new Worker(b("remove"),{type:"module"}),c.postMessage(r.data);break;case 5:{c=c||new Worker(b("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}`)}},Ze=()=>{T.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),T.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},Xe=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(M).includes(r.action);export{T as events,Ze as init,Xe as isWorkerActionMessage,Qe as sendFileError,Le as updateFile}; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __commonJS = (cb, mod) => function __require() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter2() { + EventEmitter2.init.call(this); + } + module.exports = EventEmitter2; + module.exports.once = once; + EventEmitter2.EventEmitter = EventEmitter2; + EventEmitter2.prototype._events = void 0; + EventEmitter2.prototype._eventsCount = 0; + EventEmitter2.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter2, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter2.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter2.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter2.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter2.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter2.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events2 = this._events; + if (events2 !== void 0) + doError = doError && events2.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err2 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err2.context = er; + throw err2; + } + var handler = events2[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events2; + var existing; + checkListener(listener); + events2 = target._events; + if (events2 === void 0) { + events2 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events2.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events2 = target._events; + } + existing = events2[type]; + } + if (existing === void 0) { + existing = events2[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events2[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter2.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter2.prototype.on = EventEmitter2.prototype.addListener; + EventEmitter2.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter2.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.removeListener = function removeListener(type, listener) { + var list, events2, position, i, originalListener; + checkListener(listener); + events2 = this._events; + if (events2 === void 0) + return this; + list = events2[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events2[type]; + if (events2.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events2[type] = list[0]; + if (events2.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; + EventEmitter2.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events2, i; + events2 = this._events; + if (events2 === void 0) + return this; + if (events2.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events2[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events2[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events2); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events2[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events2 = target._events; + if (events2 === void 0) + return []; + var evlistener = events2[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter2.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter2.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter2.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter2.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events2 = this._events; + if (events2 !== void 0) { + var evlistener = events2[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter2.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err2) { + emitter.removeListener(name, resolver); + reject(err2); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// src/worker/main.ts +var import_events = __toESM(require_events()); + +// src/enum/worker-action.ts +var WORKER_ACTION = /* @__PURE__ */ ((WORKER_ACTION2) => { + WORKER_ACTION2[WORKER_ACTION2["ARCHIVE_ADD"] = 0] = "ARCHIVE_ADD"; + WORKER_ACTION2[WORKER_ACTION2["ARCHHIVE_COMPRESS"] = 1] = "ARCHHIVE_COMPRESS"; + WORKER_ACTION2[WORKER_ACTION2["CANCEL"] = 2] = "CANCEL"; + WORKER_ACTION2[WORKER_ACTION2["DOWNLOAD"] = 3] = "DOWNLOAD"; + WORKER_ACTION2[WORKER_ACTION2["INFOS"] = 4] = "INFOS"; + WORKER_ACTION2[WORKER_ACTION2["PAUSE"] = 5] = "PAUSE"; + WORKER_ACTION2[WORKER_ACTION2["PROVIDE_FILE"] = 6] = "PROVIDE_FILE"; + WORKER_ACTION2[WORKER_ACTION2["REMOVE"] = 7] = "REMOVE"; + WORKER_ACTION2[WORKER_ACTION2["RESUME"] = 8] = "RESUME"; + WORKER_ACTION2[WORKER_ACTION2["UPLOAD"] = 9] = "UPLOAD"; + return WORKER_ACTION2; +})(WORKER_ACTION || {}); + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result2) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result2.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result2.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result2.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err2) { + return new Err(err2); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err2) { + return err2(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/utils.ts +var isDenoRuntime = () => typeof Deno !== "undefined"; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); + +// src/worker/main.ts +var events = new import_events.default(); +var worker; +var isInitialized = false; +self.onmessage = (event) => { + addWorker(event); + if (!isInitialized) { + isInitialized = true; + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + if (worker) { + worker.terminate(); + } + }); + } +}; +var updateFile = (lufiFile, args) => { + Object.assign(lufiFile, args); + if (typeof WorkerGlobalScope !== "undefined") { + self.postMessage({ + event: "FILE_UPDATED" /* FILE_UPDATED */, + lufiFile + }); + } + return lufiFile; +}; +var sendFileError = (lufiFile, error) => { + updateFile(lufiFile, { uploadStatus: 2 /* FAILED */ }); + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); +}; +var addWorker = (event, callback) => { + const { action } = event.data; + if (action === 5 /* PAUSE */ || action === 8 /* RESUME */) { + worker.postMessage(event.data); + } else { + switch (action) { + case 2 /* CANCEL */: + { + worker = new Worker(workerUrl("cancel"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 3 /* DOWNLOAD */: + { + worker = new Worker(workerUrl("download"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 4 /* INFOS */: + { + worker = new Worker(workerUrl("infos"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 7 /* REMOVE */: + { + worker = worker || new Worker(workerUrl("remove"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 9 /* UPLOAD */: + { + worker = worker || new Worker(workerUrl("upload"), { type: "module" }); + worker.postMessage(event.data); + } + break; + default: { + console.error("Action not found"); + } + } + worker.onmessage = (e) => { + if (callback) callback(e); + self.postMessage(e.data); + }; + worker.onerror = (error) => { + console.error(`Error: ${error.message}`); + }; + } +}; +var init = () => { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + self.postMessage({ + event: "SOCKET_OPENED" /* SOCKET_OPENED */ + }); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); + }); +}; +var isWorkerActionMessage = (message) => { + return typeof message === "object" && message !== null && "action" in message && Object.values(WORKER_ACTION).includes(message.action); +}; +export { + events, + init, + isWorkerActionMessage, + sendFileError, + updateFile +}; diff --git a/themes/default/public/js/worker/remove.js b/themes/default/public/js/worker/remove.js index 9075416..8990105 100644 --- a/themes/default/public/js/worker/remove.js +++ b/themes/default/public/js/worker/remove.js @@ -1 +1,929 @@ -var ee=Object.create;var T=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var se=(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 te(e))!oe.call(r,o)&&o!==t&&T(r,o,{get:()=>e[o],enumerable:!(n=re(e,o))||n.enumerable});return r};var ue=(r,e,t)=>(t=r!=null?ee(ne(r)):{},ie(e||!r||!r.__esModule?T(t,"default",{value:r,enumerable:!0}):t,r));var Q=se((He,M)=>{"use strict";var b=typeof Reflect=="object"?Reflect:null,W=b&&typeof b.apply=="function"?b.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},A;b&&typeof b.ownKeys=="function"?A=b.ownKeys:Object.getOwnPropertySymbols?A=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:A=function(e){return Object.getOwnPropertyNames(e)};function ve(r){console&&console.warn&&console.warn(r)}var j=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}M.exports=u;M.exports.once=Le;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var U=10;function k(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(u,"defaultMaxListeners",{enumerable:!0,get:function(){return U},set:function(r){if(typeof r!="number"||r<0||j(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");U=r}});u.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};u.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||j(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?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return J(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=i[e];if(l===void 0)return!1;if(typeof l=="function")W(l,this,t);else for(var v=l.length,m=G(l,v),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=r,a.type=e,a.count=s.length,ve(a)}return r}u.prototype.addListener=function(e,t){return $(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return $(this,e,t,!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 H(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=ye.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return k(t),this.on(e,H(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return k(t),this.prependListener(e,H(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,i,s,a;if(k(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){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ee(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};u.prototype.off=u.prototype.removeListener;u.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 K(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?we(o):G(o,o.length)}u.prototype.listeners=function(e){return K(this,e,!0)};u.prototype.rawListeners=function(e){return K(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):B.call(r,e)};u.prototype.listenerCount=B;function B(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}u.prototype.eventNames=function(){return this._eventsCount>0?A(this._events):[]};function G(r,e){for(var t=new Array(e),n=0;n{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 _(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 a(m){try{v(n.next(m))}catch(L){s(L)}}function l(m){try{v(n.throw(m))}catch(L){s(L)}}function v(m){m.done?i(m.value):o(m.value).then(a,l)}v((n=n.apply(r,[])).next())})}function R(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 w(r){return this instanceof w?(this.v=r,this):new w(r)}function fe(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(f){n[f]&&(o[f]=function(g){return new Promise(function(P,V){i.push([f,g,P,V])>1||a(f,g)})})}function a(f,g){try{l(n[f](g))}catch(P){L(i[0][3],P)}}function l(f){f.value instanceof w?Promise.resolve(f.value.v).then(v,m):L(i[0][2],f)}function v(f){a("next",f)}function m(f){a("throw",f)}function L(f,g){f(g),i.shift(),i.length&&a(i[0][0],i[0][1])}}function ce(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:w(r[o](s)),done:o==="return"}:i?i(s):s}:i}}function le(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 R=="function"?R(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(a,l){s=r[i](s),o(a,l,s.done,s.value)})}}function o(i,s,a,l){Promise.resolve(l).then(function(v){i({value:v,done:a})},s)}}var p=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 h(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(_(this,void 0,void 0,function*(){try{return new d(yield e(...n))}catch(o){return new h(t?t(o):o)}}))}static combine(e){return he(e)}static combineWithAllErrors(e){return pe(e)}map(e){return new r(this._promise.then(t=>_(this,void 0,void 0,function*(){return t.isErr()?new h(t.error):new d(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>_(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);let n=yield e(t.value);return n.isErr()?new h(n.error):new d(t.value)})))}andTee(e){return new r(this._promise.then(t=>_(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);try{yield e(t.value)}catch{}return new d(t.value)})))}mapErr(e){return new r(this._promise.then(t=>_(this,void 0,void 0,function*(){return t.isOk()?new d(t.value):new h(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new h(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>_(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 fe(this,arguments,function*(){return yield w(yield w(yield*ce(le(yield w(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var D=r=>new p(Promise.resolve(new h(r))),ke=p.fromPromise,Pe=p.fromSafePromise,xe=p.fromThrowable,F=r=>{let e=E([]);for(let t of r)if(t.isErr()){e=y(t.error);break}else e.map(n=>n.push(t.value));return e},he=r=>p.fromSafePromise(Promise.all(r)).andThen(F),N=r=>{let e=E([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=y([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},pe=r=>p.fromSafePromise(Promise.all(r)).andThen(N),x;(function(r){function e(o,i){return(...s)=>{try{let a=o(...s);return E(a)}catch(a){return y(i?i(a):a)}}}r.fromThrowable=e;function t(o){return F(o)}r.combine=t;function n(o){return N(o)}r.combineWithAllErrors=n})(x||(x={}));var E=r=>new d(r);function y(r){return new h(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return E(e(this.value))}mapErr(e){return E(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 E(this.value)}orElse(e){return E(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return p.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 C("Called `_unsafeUnwrapErr` on an Ok",this,e)}},h=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return y(this.error)}mapErr(e){return y(e(this.error))}andThrough(e){return y(this.error)}andTee(e){return y(this.error)}andThen(e){return y(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return D(this.error)}asyncAndThrough(e){return D(this.error)}asyncMap(e){return D(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield y(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw C("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Me=x.fromThrowable;var S=r=>{if(r instanceof Error)return r;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(r)}catch{}return new Error(e)};var de=()=>typeof Deno<"u",O=r=>de()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var q=ue(Q());var I=new q.default,c,Z=!1;self.onmessage=r=>{Oe(r),Z||(Z=!0,I.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Oe=(r,e)=>{let{action:t}=r.data;switch(t){case 0:c=new Worker(O("cancel"),{type:"module"}),c.postMessage(r.data);break;case 1:c=new Worker(O("download"),{type:"module"}),c.postMessage(r.data);break;case 2:c=new Worker(O("infos"),{type:"module"}),c.postMessage(r.data);break;case 4:c=c||new Worker(O("remove"),{type:"module"}),c.postMessage(r.data);break;case 5:{c=c||new Worker(O("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}`)}},X=()=>{I.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),I.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var Y=!1;self.onmessage=r=>{Y||(X(),Y=!0),be(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var be=r=>p.fromPromise(new Promise((e,t)=>{let n=r.args.lufiFile;fetch(`${new URL(n.serverUrl).href}d/${n.keys.server}/${n.actionToken}`).then(o=>o.ok?e(void 0):t(o.statusText))}),e=>S(e)); +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __commonJS = (cb, mod) => function __require() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter2() { + EventEmitter2.init.call(this); + } + module.exports = EventEmitter2; + module.exports.once = once; + EventEmitter2.EventEmitter = EventEmitter2; + EventEmitter2.prototype._events = void 0; + EventEmitter2.prototype._eventsCount = 0; + EventEmitter2.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter2, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter2.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter2.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter2.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter2.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter2.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events2 = this._events; + if (events2 !== void 0) + doError = doError && events2.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err2 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err2.context = er; + throw err2; + } + var handler = events2[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events2; + var existing; + checkListener(listener); + events2 = target._events; + if (events2 === void 0) { + events2 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events2.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events2 = target._events; + } + existing = events2[type]; + } + if (existing === void 0) { + existing = events2[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events2[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter2.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter2.prototype.on = EventEmitter2.prototype.addListener; + EventEmitter2.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter2.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter2.prototype.removeListener = function removeListener(type, listener) { + var list, events2, position, i, originalListener; + checkListener(listener); + events2 = this._events; + if (events2 === void 0) + return this; + list = events2[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events2[type]; + if (events2.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events2[type] = list[0]; + if (events2.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener; + EventEmitter2.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events2, i; + events2 = this._events; + if (events2 === void 0) + return this; + if (events2.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events2[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events2[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events2); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events2[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events2 = target._events; + if (events2 === void 0) + return []; + var evlistener = events2[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter2.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter2.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter2.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter2.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events2 = this._events; + if (events2 !== void 0) { + var evlistener = events2[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter2.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err2) { + emitter.removeListener(name, resolver); + reject(err2); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result2) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result2.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result2.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result2.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err2) { + return new Err(err2); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err2) { + return err2(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/utils.ts +var ensureError = (value) => { + if (value instanceof Error) return value; + let stringified = "[Unable to stringify the thrown value]"; + try { + stringified = JSON.stringify(value); + } catch (_error) { + } + const error = new Error(stringified); + return error; +}; +var isDenoRuntime = () => typeof Deno !== "undefined"; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); + +// src/worker/main.ts +var import_events = __toESM(require_events()); +var events = new import_events.default(); +var worker; +var isInitialized = false; +self.onmessage = (event) => { + addWorker(event); + if (!isInitialized) { + isInitialized = true; + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + if (worker) { + worker.terminate(); + } + }); + } +}; +var addWorker = (event, callback) => { + const { action } = event.data; + if (action === 5 /* PAUSE */ || action === 8 /* RESUME */) { + worker.postMessage(event.data); + } else { + switch (action) { + case 2 /* CANCEL */: + { + worker = new Worker(workerUrl("cancel"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 3 /* DOWNLOAD */: + { + worker = new Worker(workerUrl("download"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 4 /* INFOS */: + { + worker = new Worker(workerUrl("infos"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 7 /* REMOVE */: + { + worker = worker || new Worker(workerUrl("remove"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 9 /* UPLOAD */: + { + worker = worker || new Worker(workerUrl("upload"), { type: "module" }); + worker.postMessage(event.data); + } + break; + default: { + console.error("Action not found"); + } + } + worker.onmessage = (e) => { + if (callback) callback(e); + self.postMessage(e.data); + }; + worker.onerror = (error) => { + console.error(`Error: ${error.message}`); + }; + } +}; +var init = () => { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + self.postMessage({ + event: "SOCKET_OPENED" /* SOCKET_OPENED */ + }); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); + }); +}; + +// src/worker/remove.ts +var isInitiated = false; +self.onmessage = (event) => { + if (!isInitiated) { + init(); + isInitiated = true; + } + removeFile(event.data).map(() => { + self.postMessage({ event: "FILE_REMOVED" /* FILE_REMOVED */ }); + }).mapErr((error) => { + self.postMessage({ + event: "OPERATION_FAILED" /* OPERATION_FAILED */, + error + }); + }); +}; +var removeFile = (workerMessage) => ResultAsync.fromPromise( + new Promise((resolve, reject) => { + const lufiFile = workerMessage.args.lufiFile; + fetch( + `${new URL(lufiFile.serverUrl).href}d/${lufiFile.keys.server}/${lufiFile.actionToken}` + ).then((request) => request.ok ? resolve(void 0) : reject(request.statusText)); + }), + (error) => ensureError(error) +); diff --git a/themes/default/public/js/worker/upload.js b/themes/default/public/js/worker/upload.js index be06e61..d03e708 100644 --- a/themes/default/public/js/worker/upload.js +++ b/themes/default/public/js/worker/upload.js @@ -1 +1,2860 @@ -var pt=Object.create;var Ce=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,vt=Object.prototype.hasOwnProperty;var wt=(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 pe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Et=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yt(e))!vt.call(t,i)&&i!==r&&Ce(t,i,{get:()=>e[i],enumerable:!(n=mt(e,i))||n.enumerable});return t};var z=(t,e,r)=>(r=t!=null?pt(gt(t)):{},Et(e||!t||!t.__esModule?Ce(r,"default",{value:t,enumerable:!0}):r,t));var ie=pe((Pr,ye)=>{"use strict";var B=typeof Reflect=="object"?Reflect:null,Ie=B&&typeof B.apply=="function"?B.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},re;B&&typeof B.ownKeys=="function"?re=B.ownKeys:Object.getOwnPropertySymbols?re=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:re=function(e){return Object.getOwnPropertyNames(e)};function kt(t){console&&console.warn&&console.warn(t)}var Ne=Number.isNaN||function(e){return e!==e};function y(){y.init.call(this)}ye.exports=y;ye.exports.once=Rt;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var Me=10;function ne(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(y,"defaultMaxListeners",{enumerable:!0,get:function(){return Me},set:function(t){if(typeof t!="number"||t<0||Ne(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Me=t}});y.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};y.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Ne(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?y.defaultMaxListeners:t._maxListeners}y.prototype.getMaxListeners=function(){return Ue(this)};y.prototype.emit=function(e){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[e];if(u===void 0)return!1;if(typeof u=="function")Ie(u,this,r);else for(var f=u.length,h=ze(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(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,kt(c)}return t}y.prototype.addListener=function(e,r){return Be(this,e,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(e,r){return Be(this,e,r,!0)};function Ct(){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 Fe(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=Ct.bind(n);return i.listener=r,n.wrapFn=i,i}y.prototype.once=function(e,r){return ne(r),this.on(e,Fe(this,e,r)),this};y.prototype.prependOnceListener=function(e,r){return ne(r),this.prependListener(e,Fe(this,e,r)),this};y.prototype.removeListener=function(e,r){var n,i,o,s,c;if(ne(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){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Tt(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};y.prototype.off=y.prototype.removeListener;y.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 je(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?Pt(i):ze(i,i.length)}y.prototype.listeners=function(e){return je(this,e,!0)};y.prototype.rawListeners=function(e){return je(this,e,!1)};y.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):We.call(t,e)};y.prototype.listenerCount=We;function We(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}y.prototype.eventNames=function(){return this._eventsCount>0?re(this._events):[]};function ze(t,e){for(var r=new Array(e),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};a.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,r,n,i,o=this.s[0][4],s=this.s[1];e=t.length;var c=1;if(e!==4&&e!==6&&e!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),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^c<<24,c=c<<1^283*(c>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],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]]};a.cipher.aes.prototype={encrypt:function(t){return Ve(this,t,0)},decrypt:function(t){return Ve(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],i,o,s,c=[],u=[],f,h,l,d;for(i=0;256>i;i++)u[(c[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[o]=l,n[l]=o,h=c[i=c[f=c[o]]],d=16843009*h^65537*i^257*f^16843008*o,h=257*c[l]^16843008*l,i=0;4>i;i++)t[i][o]=h=h<<24^h>>>8,e[i][l]=d=d<<24^d>>>8;for(i=0;5>i;i++)t[i]=t[i].slice(0),e[i]=e[i].slice(0)}};function Ve(t,e,r){if(e.length!==4)throw new a.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 c,u,f,h=n.length/4-2,l,d=4,p=[0,0,0,0];c=t.s[r],t=c[0];var g=c[1],N=c[2],ee=c[3],te=c[4];for(l=0;l>>24]^g[o>>16&255]^N[s>>8&255]^ee[e&255]^n[d],u=t[o>>>24]^g[s>>16&255]^N[e>>8&255]^ee[i&255]^n[d+1],f=t[s>>>24]^g[e>>16&255]^N[i>>8&255]^ee[o&255]^n[d+2],e=t[e>>>24]^g[i>>16&255]^N[o>>8&255]^ee[s&255]^n[d+3],d+=4,i=c,o=u,s=f;for(l=0;4>l;l++)p[r?3&-l:l]=te[i>>>24]<<24^te[o>>16&255]<<16^te[s>>8&255]<<8^te[e&255]^n[d++],c=i,i=o,o=s,s=e,e=c;return p}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.$(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:a.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(a.bitArray.bitLength(t)!==a.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[i]<<32-e;return i=t.length?t[t.length-1]:0,t=a.bitArray.getPartial(i),n.push(a.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};a.codec.utf8String={fromBits:function(t){var e="",r=a.bitArray.bitLength(t),n,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),sh){if(!e)try{return a.codec.base32hex.toBits(t)}catch{}throw new a.exception.invalid("this isn't "+l+"!")}c>i?(c-=i,o.push(f^h>>>c),f=h<>>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=a.codec.base64.B,s=0,c;for(e&&(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(t){return a.codec.base64.fromBits(t,1,1)},toBits:function(t){return a.codec.base64.toBits(t,1)}};a.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()};a.hash.sha256.hash=function(t){return new a.hash.sha256().update(t).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.A=a.bitArray.concat(this.A,t);if(e=this.l,t=this.l=e+a.bitArray.bitLength(t),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 ve(t,e){var r,n,i,o=t.F,s=t.b,c=o[0],u=o[1],f=o[2],h=o[3],l=o[4],d=o[5],p=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+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(p^l&(d^p))+s[r],g=p,p=d,d=l,l=h+n|0,h=f,f=u,u=c,c=n+(u&f^h&(u^f))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10)|0;o[0]=o[0]+c|0,o[1]=o[1]+u|0,o[2]=o[2]+f|0,o[3]=o[3]+h|0,o[4]=o[4]+l|0,o[5]=o[5]+d|0,o[6]=o[6]+p|0,o[7]=o[7]+g|0}a.mode.ccm={name:"ccm",G:[],listenProgress:function(t){a.mode.ccm.G.push(t)},unListenProgress:function(t){t=a.mode.ccm.G.indexOf(t),-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)),e=a.mode.ccm.V(t,e,r,n,i,o),s=a.mode.ccm.C(t,s,r,e,i,o),c.concat(s.data,s.tag)},decrypt:function(t,e,r,n,i){i=i||64,n=n||[];var o=a.bitArray,s=o.bitLength(r)/8,f=o.bitLength(e),c=o.clamp(e,f-i),u=o.bitSlice(e,f-i),f=(f-i)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&f>>>8*e;e++);if(e<15-s&&(e=15-s),r=o.clamp(r,8*(15-e)),c=a.mode.ccm.C(t,c,r,u,i,e),t=a.mode.ccm.V(t,c.data,r,n,i,e),!o.equal(c.tag,t))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},na:function(t,e,r,n,i,o){var s=[],c=a.bitArray,u=c.i;if(n=[c.partial(8,(e.length?64:0)|n-2<<2|o-1)],n=c.concat(n,r),n[3]|=i,n=t.encrypt(n),e.length)for(r=c.bitLength(e)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,e),e=0;ei||16h&&(a.mode.ccm.fa(s/u),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:c.clamp(e,f)}}};a.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,i,o){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");var s,c=a.mode.ocb2.S,u=a.bitArray,f=u.i,h=[0,0,0,0];r=c(t.encrypt(r));var l,d=[];for(n=n||[],i=i||64,s=0;s+4i.bitLength(r)&&(c=o(c,n(c)),r=i.concat(r,[-2147483648,0,0,0])),s=o(s,r),t.encrypt(o(n(o(c,n(c))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};a.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,i){var o=e.slice(0);return e=a.bitArray,n=n||[],t=a.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=a.bitArray,c=s.bitLength(o);if(i=i||128,n=n||[],i<=c?(e=s.bitSlice(o,c-i),o=s.bitSlice(o,0,c-i)):(e=o,o=[]),t=a.mode.gcm.C(!1,t,o,n,r,i),!s.equal(t.tag,e))throw new a.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,i,o,s,c=a.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=c(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 a.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),i=i||a.misc.hmac,t=new i(t);var o,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(i=o=t.encrypt(h.concat(e,[u])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=o),this.P++,this.b=a.hash.sha256.hash(this.b.concat(i)),this.L=new a.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>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:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=e,this.f+=e,c===this.u&&(this.isReady()!==this.u&&Xe("seeded",Math.max(this.o,this.f)),Xe("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:K(this,this.ma),mouseCollector:K(this,this.oa),keyboardCollector:K(this,this.la),accelerometerCollector:K(this,this.ea),touchCollector:K(this,this.qa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,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 K(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(ce=typeof j<"u"&&j.exports){try{ue=wt("crypto")}catch{ue=null}ce=ae=ue}if(ce&&ae.randomBytes)V=ae.randomBytes(128),V=new Uint32Array(new Uint8Array(V).buffer),a.random.addEntropy(V,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(X=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(X);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(X);else break e;a.random.addEntropy(X,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 V,ae,X,ce,ue;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var i=a.json,o=i.g({iv:a.random.randomWords(4,0)},i.defaults),s;if(i.g(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=a.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=a.codec.base64.toBits(o.iv)),!a.mode[o.mode]||!a.cipher[o.cipher]||typeof 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||4{"use strict";var nr=Object.prototype.hasOwnProperty,L="~";function H(){}Object.create&&(H.prototype=Object.create(null),new H().__proto__||(L=!1));function ir(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function ut(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new ir(r,n||t,i),s=L?L+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function fe(t,e){--t._eventsCount===0?t._events=new H:delete t._events[e]}function A(){this._events=new H,this._eventsCount=0}A.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)nr.call(r,n)&&e.push(L?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};A.prototype.listeners=function(e){var r=L?L+e:e,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=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 U(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 c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?o(h.value):i(h.value).then(c,u)}f((n=n.apply(t,[])).next())})}function Te(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function M(t){return this instanceof M?(this.v=t,this):new M(t)}function Lt(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(d){n[d]&&(i[d]=function(p){return new Promise(function(g,N){o.push([d,p,g,N])>1||c(d,p)})})}function c(d,p){try{u(n[d](p))}catch(g){l(o[0][3],g)}}function u(d){d.value instanceof M?Promise.resolve(d.value.v).then(f,h):l(o[0][2],d)}function f(d){c("next",d)}function h(d){c("throw",d)}function l(d,p){d(p),o.shift(),o.length&&c(o[0][0],o[0][1])}}function Ot(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:M(t[i](s)),done:i==="return"}:o?o(s):s}:o}}function bt(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 Te=="function"?Te(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(c,u){s=t[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 v=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new x(n));return new t(r)}static fromPromise(e,r){let n=e.then(i=>new x(i)).catch(i=>new _(r(i)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(U(this,void 0,void 0,function*(){try{return new x(yield e(...n))}catch(i){return new _(r?r(i):i)}}))}static combine(e){return xt(e)}static combineWithAllErrors(e){return _t(e)}map(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new x(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield e(r.value);return n.isErr()?new _(n.error):new x(r.value)})))}andTee(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield e(r.value)}catch{}return new x(r.value)})))}mapErr(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isOk()?new x(r.value):new _(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new x(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 Lt(this,arguments,function*(){return yield M(yield M(yield*Ot(bt(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},O=t=>new v(Promise.resolve(new x(t))),w=t=>new v(Promise.resolve(new _(t))),cr=v.fromPromise,ur=v.fromSafePromise,fr=v.fromThrowable,Re=t=>{let e=S([]);for(let r of t)if(r.isErr()){e=k(r.error);break}else e.map(n=>n.push(r.value));return e},xt=t=>v.fromSafePromise(Promise.all(t)).andThen(Re),Se=t=>{let e=S([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=k([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},_t=t=>v.fromSafePromise(Promise.all(t)).andThen(Se),me;(function(t){function e(i,o){return(...s)=>{try{let c=i(...s);return S(c)}catch(c){return k(o?o(c):c)}}}t.fromThrowable=e;function r(i){return Re(i)}t.combine=r;function n(i){return Se(i)}t.combineWithAllErrors=n})(me||(me={}));var S=t=>new x(t);function k(t){return new _(t)}var x=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return S(e(this.value))}mapErr(e){return S(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 S(this.value)}orElse(e){return S(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,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Pe("Called `_unsafeUnwrapErr` on an Ok",this,e)}},_=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return k(this.error)}mapErr(e){return k(e(this.error))}andThrough(e){return k(this.error)}andTee(e){return k(this.error)}andThen(e){return k(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 k(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Pe("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},lr=me.fromThrowable;var T=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 D=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 Dt=()=>typeof Deno<"u",P=t=>Dt()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var C=class extends T{};var J=class extends C{message="An error occured while trying to connect to WebSocket"};var $e=z(ie());var m=new $e.default,E,qe=!1;self.onmessage=t=>{Mt(t),qe||(qe=!0,m.once("OPERATION_FAILED",()=>{E&&E.terminate()}))};var R=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),q=(t,e)=>{R(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},Mt=(t,e)=>{let{action:r}=t.data;switch(r){case 0:E=new Worker(P("cancel"),{type:"module"}),E.postMessage(t.data);break;case 1:E=new Worker(P("download"),{type:"module"}),E.postMessage(t.data);break;case 2:E=new Worker(P("infos"),{type:"module"}),E.postMessage(t.data);break;case 4:E=E||new Worker(P("remove"),{type:"module"}),E.postMessage(t.data);break;case 5:{E=E||new Worker(P("upload"),{type:"module"}),E.postMessage(t.data);break}default:console.error("Action not found")}E.onmessage=n=>{e&&e(n),self.postMessage(n.data)},E.onerror=n=>{console.error(`Error: ${n.message}`)}},Ge=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var F=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,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 Nt=new F("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function $(t){return Nt.Decode(t)}var Ut=new F("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ge(t){return Ut.Decode(t)}var Ze=z(Ye());var I=class extends T{};var W=class extends I{message="Unable to decrypt the provided data"};var et=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return O($(Ze.default.decrypt(t,r)))}catch(r){return w(new W(void 0,{cause:D(r)}))}};var tt=(t,e)=>jt(t).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,$(e.data)),n=>new W(void 0,{cause:D(n)})));var jt=t=>v.fromPromise(crypto.subtle.importKey("raw",ge(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new I("Unable to import cryptography key",{cause:D(e)}));var rt=(t,e)=>e.algo===void 0||e.algo===0?et(t,e):tt(t,e);var b={},it=5,zt=t=>(m.emit("UPLOAD_CANCELLED",t.success),O(void 0)),Jt=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let i=JSON.parse(n);if(Qt(i)){let o=r.shift();if(o){let s=JSON.parse(o);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),rt(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return i.part===0?(R(e,{chunksReady:e.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}),m.emit("DOWNLOAD_STARTED")):R(e,{chunksReady:e.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,i.part),++i.part===i.total?Kt(e).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),O(void 0))):O(void 0)})}else{let s=new C("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),w(s)}}else{let o=new C(i.msg);return m.emit("OPERATION_FAILED",o),w(o)}}else{let i=new C("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",i),w(i)}},qt=(t,e)=>{if(t.success)return t.j===0&&(R(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),m.emit("UPLOAD_STARTED")),R(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),m.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(R(e,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),O(void 0);{let r=new C(t.msg);return m.emit("OPERATION_FAILED",r),w(r)}},$t=(t,e)=>{let r=Yt(t.data),n;if(r)if(!r.action&&r.msg){let i=new C(r.msg);return m.emit("OPERATION_FAILED",i),w(i)}else"delay"in r?n=qt(r,e):n=zt(r);else n=Jt(t.data,e);return n},Gt=t=>b!==void 0&&b[t]!==void 0&&b[t].readyState===WebSocket.CONNECTING,Ee=t=>b!==void 0&&b[t]!==void 0&&b[t].readyState===WebSocket.OPEN;var Kt=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},Le(Xt(t),t,JSON.stringify(e))},Ae=(t,e,r)=>Le(Ht(t),t,`${JSON.stringify(e)}XXMOJOXX${JSON.stringify(r)}`),Le=(t,e,r)=>Ee(t)?(b[t].onmessage=n=>$t(n,e),b[t].send(r),O(void 0)):ot(t).andThen(()=>Le(t,e,r)),ot=(t,e=0)=>(!Ee(t)&&!Gt(t)&&(b[t]=new WebSocket(t),m.once("SOCKET_OPERATION_TERMINATED",()=>{b[t].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),b[t].onopen=()=>{m.emit("SOCKET_OPENED")},b[t].onclose=()=>{},b[t].onerror=()=>++e<=it?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${it}`),ot(t,e)):(m.emit("SOCKET_ONERROR"),w(new J(`Unable to connect to WebSocket ${t}.`)))),Vt(t).andThen(()=>O(t)).orElse(r=>w(r))),Vt=t=>v.fromPromise(new Promise((e,r)=>{Ee(t)?e(void 0):(m.once("SOCKET_OPENED",()=>{e(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new J)}))}),e=>D(e));var st=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,r},Xt=t=>st(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString(),Ht=t=>st(new URL(t.serverUrl),"upload").toString(),Yt=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Qt=t=>typeof t=="object"&&t!==null&&!("msg"in t);var at=z(ie());var er=z(ie());var tr={},fi=new at.default;var rr=()=>Object.values(tr).filter(t=>t.uploadStatus===4),ct=t=>Object.keys(rr()).indexOf(t);var be=z(ft(),1);var Y=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},xe=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},lt=t=>globalThis.DOMException===void 0?new xe(t):new DOMException(t),ht=t=>{let e=t.reason===void 0?lt("This operation was aborted."):t.reason;return e instanceof Error?e:lt(e)};function _e(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,u=new Promise((f,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:d}=e;d.aborted&&h(ht(d));let p=()=>{h(ht(d))};d.addEventListener("abort",p,{once:!0}),t.finally(()=>{d.removeEventListener("abort",p)})}if(r===Number.POSITIVE_INFINITY){t.then(f,h);return}let l=new Y;s=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){h(d)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?f():i instanceof Error?h(i):(l.message=i??`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await t)}catch(d){h(d)}})()}).finally(()=>{u.clear()});return u.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},u}function De(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Q=class{#e=[];enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let i=De(this.#e,n,(o,s)=>s.priority-o.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Z=class extends be.default{#e;#s;#o=0;#d;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Q,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#s=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#w(){return this.#s||this.#o{this.#L()},r)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#O;if(this.#w&&this.#E){let r=this.#t.dequeue();return r?(this.emit("active"),r(),e&&this.#g(),!0):!1}}return!1}#g(){this.#s||this.#r!==void 0||(this.#r=setInterval(()=>{this.#v()},this.#a),this.#p=Date.now()+this.#a)}#v(){this.#o===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#o=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#l()}async#b(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,i)=>{this.#t.enqueue(async()=>{this.#n++,this.#o++;try{r.signal?.throwIfAborted();let o=e({signal:r.signal});r.timeout&&(o=_e(Promise.resolve(o),{milliseconds:r.timeout})),r.signal&&(o=Promise.race([o,this.#b(r.signal)]));let s=await o;n(s),this.emit("completed",s)}catch(o){if(o instanceof Y&&!r.throwOnTimeout){n();return}i(o),this.emit("error",o)}finally{this.#A()}},r),this.emit("add"),this.#f()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.sizethis.#t.size{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};var dt=!1,ke=8,le=new Z({concurrency:ke,autoStart:!1}),he=0,de=[];self.onmessage=t=>{let{chunk:e,lufiFile:r}=t.data.args;if(dt||(Ge(),dt=!0),e){if(de[e.index]=e,de.length===r.totalChunks)return m.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),m.on("FILE_UPDATED",R),m.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),he--,hesr(t,ct(t.args.lufiFile.keys.client)),sr=(t,e)=>{let{lufiFile:r}=t.args,n=new Worker(P("encrypt"),{type:"module"});return m.on("UPLOAD_STARTED",()=>{n.onmessage=async i=>{if(i.data.encryptedData){let{encryptedData:o}=i.data;await le.add(async()=>{await Ae(r,{total:r.totalChunks,part:i.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:r.keys.server,i:e,file_pwd:r.password},o),he++,he===ke&&le.pause()})}le.start(),i.data.error&&(q(r,i.data.error),n.terminate())};for(let i=1;i{if(i.data.encryptedData){let{encryptedData:o}=i.data;Ae(r,{total:r.totalChunks,part:i.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:null,i:e,file_pwd:r.password},o).mapErr(s=>{q(r,s)})}i.data.error&&q(r,i.data.error)},t.args.chunk=de[0],n.postMessage(t),O(void 0)}; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __typeError = (msg) => { + throw TypeError(msg); +}; +var __defNormalProp = (obj3, key, value) => key in obj3 ? __defProp(obj3, key, { enumerable: true, configurable: true, writable: true, value }) : obj3[key] = value; +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); +var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __publicField = (obj3, key, value) => __defNormalProp(obj3, typeof key !== "symbol" ? key + "" : key, value); +var __accessCheck = (obj3, member, msg) => member.has(obj3) || __typeError("Cannot " + msg); +var __privateGet = (obj3, member, getter) => (__accessCheck(obj3, member, "read from private field"), getter ? getter.call(obj3) : member.get(obj3)); +var __privateAdd = (obj3, member, value) => member.has(obj3) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj3) : member.set(obj3, value); +var __privateSet = (obj3, member, value, setter) => (__accessCheck(obj3, member, "write to private field"), setter ? setter.call(obj3, value) : member.set(obj3, value), value); +var __privateMethod = (obj3, member, method) => (__accessCheck(obj3, member, "access private method"), method); +var __privateWrapper = (obj3, member, setter, getter) => ({ + set _(value) { + __privateSet(obj3, member, value, setter); + }, + get _() { + return __privateGet(obj3, member, getter); + } +}); + +// node_modules/.deno/events@3.3.0/node_modules/events/events.js +var require_events = __commonJS({ + "node_modules/.deno/events@3.3.0/node_modules/events/events.js"(exports, module) { + "use strict"; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys2(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) { + return value !== value; + }; + function EventEmitter5() { + EventEmitter5.init.call(this); + } + module.exports = EventEmitter5; + module.exports.once = once; + EventEmitter5.EventEmitter = EventEmitter5; + EventEmitter5.prototype._events = void 0; + EventEmitter5.prototype._eventsCount = 0; + EventEmitter5.prototype._maxListeners = void 0; + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } + } + Object.defineProperty(EventEmitter5, "defaultMaxListeners", { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter5.init = function() { + if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || void 0; + }; + EventEmitter5.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === void 0) + return EventEmitter5.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter5.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter5.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events3 = this._events; + if (events3 !== void 0) + doError = doError && events3.error === void 0; + else if (!doError) + return false; + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + throw er; + } + var err2 = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err2.context = er; + throw err2; + } + var handler = events3[type]; + if (handler === void 0) + return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events3; + var existing; + checkListener(listener); + events3 = target._events; + if (events3 === void 0) { + events3 = target._events = /* @__PURE__ */ Object.create(null); + target._eventsCount = 0; + } else { + if (events3.newListener !== void 0) { + target.emit( + "newListener", + type, + listener.listener ? listener.listener : listener + ); + events3 = target._events; + } + existing = events3[type]; + } + if (existing === void 0) { + existing = events3[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + existing = events3[type] = prepend ? [listener, existing] : [existing, listener]; + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter5.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter5.prototype.on = EventEmitter5.prototype.addListener; + EventEmitter5.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: void 0, target, type, listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter5.prototype.once = function once2(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter5.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter5.prototype.removeListener = function removeListener(type, listener) { + var list, events3, position, i, originalListener; + checkListener(listener); + events3 = this._events; + if (events3 === void 0) + return this; + list = events3[type]; + if (list === void 0) + return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else { + delete events3[type]; + if (events3.removeListener) + this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) + return this; + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + if (list.length === 1) + events3[type] = list[0]; + if (events3.removeListener !== void 0) + this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter5.prototype.off = EventEmitter5.prototype.removeListener; + EventEmitter5.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events3, i; + events3 = this._events; + if (events3 === void 0) + return this; + if (events3.removeListener === void 0) { + if (arguments.length === 0) { + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + } else if (events3[type] !== void 0) { + if (--this._eventsCount === 0) + this._events = /* @__PURE__ */ Object.create(null); + else + delete events3[type]; + } + return this; + } + if (arguments.length === 0) { + var keys = Object.keys(events3); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = /* @__PURE__ */ Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events3[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== void 0) { + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events3 = target._events; + if (events3 === void 0) + return []; + var evlistener = events3[type]; + if (evlistener === void 0) + return []; + if (typeof evlistener === "function") + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter5.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter5.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter5.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter5.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events3 = this._events; + if (events3 !== void 0) { + var evlistener = events3[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== void 0) { + return evlistener.length; + } + } + return 0; + } + EventEmitter5.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function(resolve, reject) { + function errorListener(err2) { + emitter.removeListener(name, resolver); + reject(err2); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + ; + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + emitter.addEventListener(name, function wrapListener(arg) { + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } + } + } +}); + +// node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js +var require_sjcl = __commonJS({ + "node_modules/.deno/sjcl@1.0.8/node_modules/sjcl/sjcl.js"(exports, module) { + "use strict"; + var sjcl2 = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function(a) { + this.toString = function() { + return "CORRUPT: " + this.message; + }; + this.message = a; + }, invalid: function(a) { + this.toString = function() { + return "INVALID: " + this.message; + }; + this.message = a; + }, bug: function(a) { + this.toString = function() { + return "BUG: " + this.message; + }; + this.message = a; + }, notReady: function(a) { + this.toString = function() { + return "NOT READY: " + this.message; + }; + this.message = a; + } } }; + sjcl2.cipher.aes = function(a) { + this.s[0][0][0] || this.O(); + var b, c, d, e, f = this.s[0][4], g = this.s[1]; + b = a.length; + var h = 1; + if (4 !== b && 6 !== b && 8 !== b) throw new sjcl2.exception.invalid("invalid aes key size"); + this.b = [d = a.slice(0), e = []]; + for (a = b; a < 4 * b + 28; a++) { + c = d[a - 1]; + if (0 === a % b || 8 === b && 4 === a % b) c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7)); + d[a] = d[a - b] ^ c; + } + for (b = 0; a; b++, a--) c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & 255]]; + }; + sjcl2.cipher.aes.prototype = { encrypt: function(a) { + return t(this, a, 0); + }, decrypt: function(a) { + return t(this, a, 1); + }, s: [[[], [], [], [], []], [[], [], [], [], []]], O: function() { + var a = this.s[0], b = this.s[1], c = a[4], d = b[4], e, f, g, h = [], k = [], l, n, m, p; + for (e = 0; 256 > e; e++) k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e; + for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, n = h[e = h[l = h[f]]], p = 16843009 * n ^ 65537 * e ^ 257 * l ^ 16843008 * f, n = 257 * h[m] ^ 16843008 * m, e = 0; 4 > e; e++) a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8; + for (e = 0; 5 > e; e++) a[e] = a[e].slice(0), b[e] = b[e].slice(0); + } }; + function t(a, b, c) { + if (4 !== b.length) throw new sjcl2.exception.invalid("invalid aes block size"); + var d = a.b[c], e = b[0] ^ d[0], f = b[c ? 3 : 1] ^ d[1], g = b[2] ^ d[2]; + b = b[c ? 1 : 3] ^ d[3]; + var h, k, l, n = d.length / 4 - 2, m, p = 4, r = [0, 0, 0, 0]; + h = a.s[c]; + a = h[0]; + var q = h[1], v = h[2], w = h[3], x = h[4]; + for (m = 0; m < n; m++) h = a[e >>> 24] ^ q[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ q[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], l = a[g >>> 24] ^ q[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ q[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = l; + for (m = 0; 4 > m; m++) r[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h; + return r; + } + sjcl2.bitArray = { bitSlice: function(a, b, c) { + a = sjcl2.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1); + return void 0 === c ? a : sjcl2.bitArray.clamp(a, c - b); + }, extract: function(a, b, c) { + var d = Math.floor(-b - c & 31); + return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1; + }, concat: function(a, b) { + if (0 === a.length || 0 === b.length) return a.concat(b); + var c = a[a.length - 1], d = sjcl2.bitArray.getPartial(c); + return 32 === d ? a.concat(b) : sjcl2.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1)); + }, bitLength: function(a) { + var b = a.length; + return 0 === b ? 0 : 32 * (b - 1) + sjcl2.bitArray.getPartial(a[b - 1]); + }, clamp: function(a, b) { + if (32 * a.length < b) return a; + a = a.slice(0, Math.ceil(b / 32)); + var c = a.length; + b = b & 31; + 0 < c && b && (a[c - 1] = sjcl2.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)); + return a; + }, partial: function(a, b, c) { + return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 1099511627776 * a; + }, getPartial: function(a) { + return Math.round(a / 1099511627776) || 32; + }, equal: function(a, b) { + if (sjcl2.bitArray.bitLength(a) !== sjcl2.bitArray.bitLength(b)) return false; + var c = 0, d; + for (d = 0; d < a.length; d++) c |= a[d] ^ b[d]; + return 0 === c; + }, $: function(a, b, c, d) { + var e; + e = 0; + for (void 0 === d && (d = []); 32 <= b; b -= 32) d.push(c), c = 0; + if (0 === b) return d.concat(a); + for (e = 0; e < a.length; e++) d.push(c | a[e] >>> b), c = a[e] << 32 - b; + e = a.length ? a[a.length - 1] : 0; + a = sjcl2.bitArray.getPartial(e); + d.push(sjcl2.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1)); + return d; + }, i: function(a, b) { + return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; + }, byteswapM: function(a) { + var b, c; + for (b = 0; b < a.length; ++b) c = a[b], a[b] = c >>> 24 | c >>> 8 & 65280 | (c & 65280) << 8 | c << 24; + return a; + } }; + sjcl2.codec.utf8String = { fromBits: function(a) { + var b = "", c = sjcl2.bitArray.bitLength(a), d, e; + for (d = 0; d < c / 8; d++) 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8; + return decodeURIComponent(escape(b)); + }, toBits: function(a) { + a = unescape(encodeURIComponent(a)); + var b = [], c, d = 0; + for (c = 0; c < a.length; c++) d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); + c & 3 && b.push(sjcl2.bitArray.partial(8 * (c & 3), d)); + return b; + } }; + sjcl2.codec.hex = { fromBits: function(a) { + var b = "", c; + for (c = 0; c < a.length; c++) b += ((a[c] | 0) + 263882790666240).toString(16).substr(4); + return b.substr(0, sjcl2.bitArray.bitLength(a) / 4); + }, toBits: function(a) { + var b, c = [], d; + a = a.replace(/\s|0x/g, ""); + d = a.length; + a = a + "00000000"; + for (b = 0; b < a.length; b += 8) c.push(parseInt(a.substr(b, 8), 16) ^ 0); + return sjcl2.bitArray.clamp(c, 4 * d); + } }; + sjcl2.codec.base32 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", X: "0123456789ABCDEFGHIJKLMNOPQRSTUV", BITS: 32, BASE: 5, REMAINING: 27, fromBits: function(a, b, c) { + var d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = "", g = 0, h = sjcl2.codec.base32.B, k = 0, l = sjcl2.bitArray.bitLength(a); + c && (h = sjcl2.codec.base32.X); + for (c = 0; f.length * d < l; ) f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d); + for (; f.length & 7 && !b; ) f += "="; + return f; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, "").toUpperCase(); + var c = sjcl2.codec.base32.BITS, d = sjcl2.codec.base32.BASE, e = sjcl2.codec.base32.REMAINING, f = [], g, h = 0, k = sjcl2.codec.base32.B, l = 0, n, m = "base32"; + b && (k = sjcl2.codec.base32.X, m = "base32hex"); + for (g = 0; g < a.length; g++) { + n = k.indexOf(a.charAt(g)); + if (0 > n) { + if (!b) try { + return sjcl2.codec.base32hex.toBits(a); + } catch (p) { + } + throw new sjcl2.exception.invalid("this isn't " + m + "!"); + } + h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h); + } + h & 56 && f.push(sjcl2.bitArray.partial(h & 56, l, 1)); + return f; + } }; + sjcl2.codec.base32hex = { fromBits: function(a, b) { + return sjcl2.codec.base32.fromBits(a, b, 1); + }, toBits: function(a) { + return sjcl2.codec.base32.toBits(a, 1); + } }; + sjcl2.codec.base64 = { B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", fromBits: function(a, b, c) { + var d = "", e = 0, f = sjcl2.codec.base64.B, g = 0, h = sjcl2.bitArray.bitLength(a); + c && (f = f.substr(0, 62) + "-_"); + for (c = 0; 6 * d.length < h; ) d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6); + for (; d.length & 3 && !b; ) d += "="; + return d; + }, toBits: function(a, b) { + a = a.replace(/\s|=/g, ""); + var c = [], d, e = 0, f = sjcl2.codec.base64.B, g = 0, h; + b && (f = f.substr(0, 62) + "-_"); + for (d = 0; d < a.length; d++) { + h = f.indexOf(a.charAt(d)); + if (0 > h) throw new sjcl2.exception.invalid("this isn't base64!"); + 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e); + } + e & 56 && c.push(sjcl2.bitArray.partial(e & 56, g, 1)); + return c; + } }; + sjcl2.codec.base64url = { fromBits: function(a) { + return sjcl2.codec.base64.fromBits(a, 1, 1); + }, toBits: function(a) { + return sjcl2.codec.base64.toBits(a, 1); + } }; + sjcl2.hash.sha256 = function(a) { + this.b[0] || this.O(); + a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset(); + }; + sjcl2.hash.sha256.hash = function(a) { + return new sjcl2.hash.sha256().update(a).finalize(); + }; + sjcl2.hash.sha256.prototype = { blockSize: 512, reset: function() { + this.F = this.Y.slice(0); + this.A = []; + this.l = 0; + return this; + }, update: function(a) { + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + var b, c = this.A = sjcl2.bitArray.concat(this.A, a); + b = this.l; + a = this.l = b + sjcl2.bitArray.bitLength(a); + if (9007199254740991 < a) throw new sjcl2.exception.invalid("Cannot hash more than 2^53 - 1 bits"); + if ("undefined" !== typeof Uint32Array) { + var d = new Uint32Array(c), e = 0; + for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, d.subarray( + 16 * e, + 16 * (e + 1) + )), e += 1; + c.splice(0, 16 * e); + } else for (b = 512 + b - (512 + b & 511); b <= a; b += 512) u(this, c.splice(0, 16)); + return this; + }, finalize: function() { + var a, b = this.A, c = this.F, b = sjcl2.bitArray.concat(b, [sjcl2.bitArray.partial(1, 1)]); + for (a = b.length + 2; a & 15; a++) b.push(0); + b.push(Math.floor(this.l / 4294967296)); + for (b.push(this.l | 0); b.length; ) u(this, b.splice(0, 16)); + this.reset(); + return c; + }, Y: [], b: [], O: function() { + function a(a2) { + return 4294967296 * (a2 - Math.floor(a2)) | 0; + } + for (var b = 0, c = 2, d, e; 64 > b; c++) { + e = true; + for (d = 2; d * d <= c; d++) if (0 === c % d) { + e = false; + break; + } + e && (8 > b && (this.Y[b] = a(Math.pow(c, 0.5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++); + } + } }; + function u(a, b) { + var c, d, e, f = a.F, g = a.b, h = f[0], k = f[1], l = f[2], n = f[3], m = f[4], p = f[5], r = f[6], q = f[7]; + for (c = 0; 64 > c; c++) 16 > c ? d = b[c] : (d = b[c + 1 & 15], e = b[c + 14 & 15], d = b[c & 15] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + b[c & 15] + b[c + 9 & 15] | 0), d = d + q + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (r ^ m & (p ^ r)) + g[c], q = r, r = p, p = m, m = n + d | 0, n = l, l = k, k = h, h = d + (k & l ^ n & (k ^ l)) + (k >>> 2 ^ k >>> 13 ^ k >>> 22 ^ k << 30 ^ k << 19 ^ k << 10) | 0; + f[0] = f[0] + h | 0; + f[1] = f[1] + k | 0; + f[2] = f[2] + l | 0; + f[3] = f[3] + n | 0; + f[4] = f[4] + m | 0; + f[5] = f[5] + p | 0; + f[6] = f[6] + r | 0; + f[7] = f[7] + q | 0; + } + sjcl2.mode.ccm = { name: "ccm", G: [], listenProgress: function(a) { + sjcl2.mode.ccm.G.push(a); + }, unListenProgress: function(a) { + a = sjcl2.mode.ccm.G.indexOf(a); + -1 < a && sjcl2.mode.ccm.G.splice(a, 1); + }, fa: function(a) { + var b = sjcl2.mode.ccm.G.slice(), c; + for (c = 0; c < b.length; c += 1) b[c](a); + }, encrypt: function(a, b, c, d, e) { + var f, g = b.slice(0), h = sjcl2.bitArray, k = h.bitLength(c) / 8, l = h.bitLength(g) / 8; + e = e || 64; + d = d || []; + if (7 > k) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (f = 2; 4 > f && l >>> 8 * f; f++) ; + f < 15 - k && (f = 15 - k); + c = h.clamp( + c, + 8 * (15 - f) + ); + b = sjcl2.mode.ccm.V(a, b, c, d, e, f); + g = sjcl2.mode.ccm.C(a, g, c, b, e, f); + return h.concat(g.data, g.tag); + }, decrypt: function(a, b, c, d, e) { + e = e || 64; + d = d || []; + var f = sjcl2.bitArray, g = f.bitLength(c) / 8, h = f.bitLength(b), k = f.clamp(b, h - e), l = f.bitSlice(b, h - e), h = (h - e) / 8; + if (7 > g) throw new sjcl2.exception.invalid("ccm: iv must be at least 7 bytes"); + for (b = 2; 4 > b && h >>> 8 * b; b++) ; + b < 15 - g && (b = 15 - g); + c = f.clamp(c, 8 * (15 - b)); + k = sjcl2.mode.ccm.C(a, k, c, l, e, b); + a = sjcl2.mode.ccm.V(a, k.data, c, d, e, b); + if (!f.equal(k.tag, a)) throw new sjcl2.exception.corrupt("ccm: tag doesn't match"); + return k.data; + }, na: function(a, b, c, d, e, f) { + var g = [], h = sjcl2.bitArray, k = h.i; + d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)]; + d = h.concat(d, c); + d[3] |= e; + d = a.encrypt(d); + if (b.length) for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 4294967295 >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); + return d; + }, V: function(a, b, c, d, e, f) { + var g = sjcl2.bitArray, h = g.i; + e /= 8; + if (e % 2 || 4 > e || 16 < e) throw new sjcl2.exception.invalid("ccm: invalid tag length"); + if (4294967295 < d.length || 4294967295 < b.length) throw new sjcl2.exception.bug("ccm: can't deal with 4GiB or more data"); + c = sjcl2.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f); + for (d = 0; d < b.length; d += 4) c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); + return g.clamp(c, 8 * e); + }, C: function(a, b, c, d, e, f) { + var g, h = sjcl2.bitArray; + g = h.i; + var k = b.length, l = h.bitLength(b), n = k / 50, m = n; + c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4); + d = h.bitSlice(g(d, a.encrypt(c)), 0, e); + if (!k) return { tag: d, data: [] }; + for (g = 0; g < k; g += 4) g > n && (sjcl2.mode.ccm.fa(g / k), n += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3]; + return { tag: d, data: h.clamp(b, l) }; + } }; + sjcl2.mode.ocb2 = { name: "ocb2", encrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + var g, h = sjcl2.mode.ocb2.S, k = sjcl2.bitArray, l = k.i, n = [0, 0, 0, 0]; + c = h(a.encrypt(c)); + var m, p = []; + d = d || []; + e = e || 64; + for (g = 0; g + 4 < b.length; g += 4) m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c); + m = b.slice(g); + b = k.bitLength(m); + g = a.encrypt(l(c, [0, 0, 0, b])); + m = k.clamp(l(m.concat([0, 0, 0]), g), b); + n = l(n, l(m.concat([0, 0, 0]), g)); + n = a.encrypt(l(n, l(c, h(c)))); + d.length && (n = l(n, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + return p.concat(k.concat(m, k.clamp(n, e))); + }, decrypt: function(a, b, c, d, e, f) { + if (128 !== sjcl2.bitArray.bitLength(c)) throw new sjcl2.exception.invalid("ocb iv must be 128 bits"); + e = e || 64; + var g = sjcl2.mode.ocb2.S, h = sjcl2.bitArray, k = h.i, l = [0, 0, 0, 0], n = g(a.encrypt(c)), m, p, r = sjcl2.bitArray.bitLength(b) - e, q = []; + d = d || []; + for (c = 0; c + 4 < r / 32; c += 4) m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n); + p = r - 32 * c; + m = a.encrypt(k(n, [0, 0, 0, p])); + m = k(m, h.clamp(b.slice(c), p).concat([ + 0, + 0, + 0 + ])); + l = k(l, m); + l = a.encrypt(k(l, k(n, g(n)))); + d.length && (l = k(l, f ? d : sjcl2.mode.ocb2.pmac(a, d))); + if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl2.exception.corrupt("ocb: tag doesn't match"); + return q.concat(h.clamp(m, p)); + }, pmac: function(a, b) { + var c, d = sjcl2.mode.ocb2.S, e = sjcl2.bitArray, f = e.i, g = [0, 0, 0, 0], h = a.encrypt([0, 0, 0, 0]), h = f(h, d(d(h))); + for (c = 0; c + 4 < b.length; c += 4) h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4)))); + c = b.slice(c); + 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0])); + g = f(g, c); + return a.encrypt(f(d(f(h, d(h))), g)); + }, S: function(a) { + return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)]; + } }; + sjcl2.mode.gcm = { name: "gcm", encrypt: function(a, b, c, d, e) { + var f = b.slice(0); + b = sjcl2.bitArray; + d = d || []; + a = sjcl2.mode.gcm.C(true, a, f, d, c, e || 128); + return b.concat(a.data, a.tag); + }, decrypt: function(a, b, c, d, e) { + var f = b.slice(0), g = sjcl2.bitArray, h = g.bitLength(f); + e = e || 128; + d = d || []; + e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []); + a = sjcl2.mode.gcm.C(false, a, f, d, c, e); + if (!g.equal(a.tag, b)) throw new sjcl2.exception.corrupt("gcm: tag doesn't match"); + return a.data; + }, ka: function(a, b) { + var c, d, e, f, g, h = sjcl2.bitArray.i; + e = [ + 0, + 0, + 0, + 0 + ]; + f = b.slice(0); + for (c = 0; 128 > c; c++) { + (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f)); + g = 0 !== (f[3] & 1); + for (d = 3; 0 < d; d--) f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31; + f[0] >>>= 1; + g && (f[0] ^= -520093696); + } + return e; + }, j: function(a, b, c) { + var d, e = c.length; + b = b.slice(0); + for (d = 0; d < e; d += 4) b[0] ^= 4294967295 & c[d], b[1] ^= 4294967295 & c[d + 1], b[2] ^= 4294967295 & c[d + 2], b[3] ^= 4294967295 & c[d + 3], b = sjcl2.mode.gcm.ka(b, a); + return b; + }, C: function(a, b, c, d, e, f) { + var g, h, k, l, n, m, p, r, q = sjcl2.bitArray; + m = c.length; + p = q.bitLength(c); + r = q.bitLength(d); + h = q.bitLength(e); + g = b.encrypt([0, 0, 0, 0]); + 96 === h ? (e = e.slice(0), e = q.concat(e, [1])) : (e = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], e), e = sjcl2.mode.gcm.j(g, e, [0, 0, Math.floor(h / 4294967296), h & 4294967295])); + h = sjcl2.mode.gcm.j(g, [0, 0, 0, 0], d); + n = e.slice(0); + d = h.slice(0); + a || (d = sjcl2.mode.gcm.j(g, h, c)); + for (l = 0; l < m; l += 4) n[3]++, k = b.encrypt(n), c[l] ^= k[0], c[l + 1] ^= k[1], c[l + 2] ^= k[2], c[l + 3] ^= k[3]; + c = q.clamp(c, p); + a && (d = sjcl2.mode.gcm.j(g, h, c)); + a = [Math.floor(r / 4294967296), r & 4294967295, Math.floor(p / 4294967296), p & 4294967295]; + d = sjcl2.mode.gcm.j(g, d, a); + k = b.encrypt(e); + d[0] ^= k[0]; + d[1] ^= k[1]; + d[2] ^= k[2]; + d[3] ^= k[3]; + return { tag: q.bitSlice(d, 0, f), data: c }; + } }; + sjcl2.misc.hmac = function(a, b) { + this.W = b = b || sjcl2.hash.sha256; + var c = [[], []], d, e = b.prototype.blockSize / 32; + this.w = [new b(), new b()]; + a.length > e && (a = b.hash(a)); + for (d = 0; d < e; d++) c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828; + this.w[0].update(c[0]); + this.w[1].update(c[1]); + this.R = new b(this.w[0]); + }; + sjcl2.misc.hmac.prototype.encrypt = sjcl2.misc.hmac.prototype.mac = function(a) { + if (this.aa) throw new sjcl2.exception.invalid("encrypt on already updated hmac called!"); + this.update(a); + return this.digest(a); + }; + sjcl2.misc.hmac.prototype.reset = function() { + this.R = new this.W(this.w[0]); + this.aa = false; + }; + sjcl2.misc.hmac.prototype.update = function(a) { + this.aa = true; + this.R.update(a); + }; + sjcl2.misc.hmac.prototype.digest = function() { + var a = this.R.finalize(), a = new this.W(this.w[1]).update(a).finalize(); + this.reset(); + return a; + }; + sjcl2.misc.pbkdf2 = function(a, b, c, d, e) { + c = c || 1e4; + if (0 > d || 0 > c) throw new sjcl2.exception.invalid("invalid params to pbkdf2"); + "string" === typeof a && (a = sjcl2.codec.utf8String.toBits(a)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + e = e || sjcl2.misc.hmac; + a = new e(a); + var f, g, h, k, l = [], n = sjcl2.bitArray; + for (k = 1; 32 * l.length < (d || 1); k++) { + e = f = a.encrypt(n.concat(b, [k])); + for (g = 1; g < c; g++) for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h]; + l = l.concat(e); + } + d && (l = n.clamp(l, d)); + return l; + }; + sjcl2.prng = function(a) { + this.c = [new sjcl2.hash.sha256()]; + this.m = [0]; + this.P = 0; + this.H = {}; + this.N = 0; + this.U = {}; + this.Z = this.f = this.o = this.ha = 0; + this.b = [0, 0, 0, 0, 0, 0, 0, 0]; + this.h = [0, 0, 0, 0]; + this.L = void 0; + this.M = a; + this.D = false; + this.K = { progress: {}, seeded: {} }; + this.u = this.ga = 0; + this.I = 1; + this.J = 2; + this.ca = 65536; + this.T = [0, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024]; + this.da = 3e4; + this.ba = 80; + }; + sjcl2.prng.prototype = { + randomWords: function(a, b) { + var c = [], d; + d = this.isReady(b); + var e; + if (d === this.u) throw new sjcl2.exception.notReady("generator isn't seeded"); + if (d & this.J) { + d = !(d & this.I); + e = []; + var f = 0, g; + this.Z = e[0] = (/* @__PURE__ */ new Date()).valueOf() + this.da; + for (g = 0; 16 > g; g++) e.push(4294967296 * Math.random() | 0); + for (g = 0; g < this.c.length && (e = e.concat(this.c[g].finalize()), f += this.m[g], this.m[g] = 0, d || !(this.P & 1 << g)); g++) ; + this.P >= 1 << this.c.length && (this.c.push(new sjcl2.hash.sha256()), this.m.push(0)); + this.f -= f; + f > this.o && (this.o = f); + this.P++; + this.b = sjcl2.hash.sha256.hash(this.b.concat(e)); + this.L = new sjcl2.cipher.aes(this.b); + for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) ; + } + for (d = 0; d < a; d += 4) 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]); + y(this); + return c.slice(0, a); + }, + setDefaultParanoia: function(a, b) { + if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) throw new sjcl2.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); + this.M = a; + }, + addEntropy: function(a, b, c) { + c = c || "user"; + var d, e, f = (/* @__PURE__ */ new Date()).valueOf(), g = this.H[c], h = this.isReady(), k = 0; + d = this.U[c]; + void 0 === d && (d = this.U[c] = this.ha++); + void 0 === g && (g = this.H[c] = 0); + this.H[c] = (this.H[c] + 1) % this.c.length; + switch (typeof a) { + case "number": + void 0 === b && (b = 1); + this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]); + break; + case "object": + c = Object.prototype.toString.call(a); + if ("[object Uint32Array]" === c) { + e = []; + for (c = 0; c < a.length; c++) e.push(a[c]); + a = e; + } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) "number" !== typeof a[c] && (k = 1); + if (!k) { + if (void 0 === b) for (c = b = 0; c < a.length; c++) for (e = a[c]; 0 < e; ) b++, e = e >>> 1; + this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a)); + } + break; + case "string": + void 0 === b && (b = a.length); + this.c[g].update([d, this.N++, 3, b, f, a.length]); + this.c[g].update(a); + break; + default: + k = 1; + } + if (k) throw new sjcl2.exception.bug("random: addEntropy only supports number, array of numbers or string"); + this.m[g] += b; + this.f += b; + h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress())); + }, + isReady: function(a) { + a = this.T[void 0 !== a ? a : this.M]; + return this.o && this.o >= a ? this.m[0] > this.ba && (/* @__PURE__ */ new Date()).valueOf() > this.Z ? this.J | this.I : this.I : this.f >= a ? this.J | this.u : this.u; + }, + getProgress: function(a) { + a = this.T[a ? a : this.M]; + return this.o >= a ? 1 : this.f > a ? 1 : this.f / a; + }, + startCollectors: function() { + if (!this.D) { + this.a = { loadTimeCollector: B(this, this.ma), mouseCollector: B(this, this.oa), keyboardCollector: B(this, this.la), accelerometerCollector: B(this, this.ea), touchCollector: B(this, this.qa) }; + if (window.addEventListener) window.addEventListener( + "load", + this.a.loadTimeCollector, + false + ), window.addEventListener("mousemove", this.a.mouseCollector, false), window.addEventListener("keypress", this.a.keyboardCollector, false), window.addEventListener("devicemotion", this.a.accelerometerCollector, false), window.addEventListener("touchmove", this.a.touchCollector, false); + 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 sjcl2.exception.bug("can't attach event"); + this.D = true; + } + }, + stopCollectors: function() { + this.D && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, false), window.removeEventListener("mousemove", this.a.mouseCollector, false), window.removeEventListener("keypress", this.a.keyboardCollector, false), window.removeEventListener("devicemotion", this.a.accelerometerCollector, false), window.removeEventListener("touchmove", this.a.touchCollector, false)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent( + "onmousemove", + this.a.mouseCollector + ), document.detachEvent("keypress", this.a.keyboardCollector)), this.D = false); + }, + addEventListener: function(a, b) { + this.K[a][this.ga++] = b; + }, + removeEventListener: function(a, b) { + var c, d, e = this.K[a], f = []; + for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d); + for (c = 0; c < f.length; c++) d = f[c], delete e[d]; + }, + la: function() { + C(this, 1); + }, + oa: function(a) { + var b, c; + try { + b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0; + } catch (d) { + c = b = 0; + } + 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); + C(this, 0); + }, + qa: function(a) { + a = a.touches[0] || a.changedTouches[0]; + this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); + C(this, 0); + }, + ma: function() { + C(this, 2); + }, + ea: function(a) { + a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; + if (window.orientation) { + var b = window.orientation; + "number" === typeof b && this.addEntropy(b, 1, "accelerometer"); + } + a && this.addEntropy(a, 2, "accelerometer"); + C(this, 0); + } + }; + function A(a, b) { + var c, d = sjcl2.random.K[a], e = []; + for (c in d) d.hasOwnProperty(c) && e.push(d[c]); + for (c = 0; c < e.length; c++) e[c](b); + } + function C(a, b) { + "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy((/* @__PURE__ */ new Date()).valueOf(), b, "loadtime"); + } + function y(a) { + a.b = z(a).concat(z(a)); + a.L = new sjcl2.cipher.aes(a.b); + } + function z(a) { + for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) ; + return a.L.encrypt(a.h); + } + function B(a, b) { + return function() { + b.apply(a, arguments); + }; + } + sjcl2.random = new sjcl2.prng(6); + a: try { + if (G = "undefined" !== typeof module && module.exports) { + try { + H = __require("crypto"); + } catch (a) { + H = null; + } + G = E = H; + } + if (G && E.randomBytes) D = E.randomBytes(128), D = new Uint32Array(new Uint8Array(D).buffer), sjcl2.random.addEntropy(D, 1024, "crypto['randomBytes']"); + else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { + F = new Uint32Array(32); + if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F); + else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F); + else break a; + sjcl2.random.addEntropy(F, 1024, "crypto['getRandomValues']"); + } + } catch (a) { + "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a)); + } + var D; + var E; + var F; + var G; + var H; + sjcl2.json = { defaults: { v: 1, iter: 1e4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, ja: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json, f = e.g({ iv: sjcl2.random.randomWords(4, 0) }, e.defaults), g; + e.g(f, c); + c = f.adata; + "string" === typeof f.salt && (f.salt = sjcl2.codec.base64.toBits(f.salt)); + "string" === typeof f.iv && (f.iv = sjcl2.codec.base64.toBits(f.iv)); + if (!sjcl2.mode[f.mode] || !sjcl2.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 256 !== f.ks || 2 > f.iv.length || 4 < f.iv.length) throw new sjcl2.exception.invalid("json encrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32)); + "string" === typeof b && (b = sjcl2.codec.utf8String.toBits(b)); + "string" === typeof c && (f.adata = c = sjcl2.codec.utf8String.toBits(c)); + g = new sjcl2.cipher[f.cipher](a); + e.g(d, f); + d.key = a; + f.ct = "ccm" === f.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl2.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); + return f; + }, encrypt: function(a, b, c, d) { + var e = sjcl2.json, f = e.ja.apply(e, arguments); + return e.encode(f); + }, ia: function(a, b, c, d) { + c = c || {}; + d = d || {}; + var e = sjcl2.json; + b = e.g(e.g(e.g({}, e.defaults), b), c, true); + var f, g; + f = b.adata; + "string" === typeof b.salt && (b.salt = sjcl2.codec.base64.toBits(b.salt)); + "string" === typeof b.iv && (b.iv = sjcl2.codec.base64.toBits(b.iv)); + if (!sjcl2.mode[b.mode] || !sjcl2.cipher[b.cipher] || "string" === typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 256 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) throw new sjcl2.exception.invalid("json decrypt: invalid parameters"); + "string" === typeof a ? (g = sjcl2.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl2.ecc && a instanceof sjcl2.ecc.elGamal.secretKey && (a = a.unkem(sjcl2.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); + "string" === typeof f && (f = sjcl2.codec.utf8String.toBits(f)); + g = new sjcl2.cipher[b.cipher](a); + f = "ccm" === b.mode && sjcl2.arrayBuffer && sjcl2.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl2.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl2.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); + e.g(d, b); + d.key = a; + return 1 === c.raw ? f : sjcl2.codec.utf8String.fromBits(f); + }, decrypt: function(a, b, c, d) { + var e = sjcl2.json; + return e.ia(a, e.decode(b), c, d); + }, encode: function(a) { + var b, c = "{", d = ""; + for (b in a) if (a.hasOwnProperty(b)) { + if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl2.exception.invalid("json encode: invalid property name"); + c += d + '"' + b + '":'; + d = ","; + switch (typeof a[b]) { + case "number": + case "boolean": + c += a[b]; + break; + case "string": + c += '"' + escape(a[b]) + '"'; + break; + case "object": + c += '"' + sjcl2.codec.base64.fromBits(a[b], 0) + '"'; + break; + default: + throw new sjcl2.exception.bug("json encode: unsupported type"); + } + } + return c + "}"; + }, decode: function(a) { + a = a.replace(/\s/g, ""); + if (!a.match(/^\{.*\}$/)) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + a = a.replace(/^\{|\}$/g, "").split(/,/); + var b = {}, c, d; + for (c = 0; c < a.length; c++) { + if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) throw new sjcl2.exception.invalid("json decode: this isn't json!"); + null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl2.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]); + } + return b; + }, g: function(a, b, c) { + void 0 === a && (a = {}); + if (void 0 === b) return a; + for (var d in b) if (b.hasOwnProperty(d)) { + if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl2.exception.invalid("required parameter overridden"); + a[d] = b[d]; + } + return a; + }, sa: function(a, b) { + var c = {}, d; + for (d in a) a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); + return c; + }, ra: function(a, b) { + var c = {}, d; + for (d = 0; d < b.length; d++) void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); + return c; + } }; + sjcl2.encrypt = sjcl2.json.encrypt; + sjcl2.decrypt = sjcl2.json.decrypt; + sjcl2.misc.pa = {}; + sjcl2.misc.cachedPbkdf2 = function(a, b) { + var c = sjcl2.misc.pa, d; + b = b || {}; + d = b.iter || 1e3; + c = c[a] = c[a] || {}; + d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl2.random.randomWords(2, 0) }; + c = void 0 === b.salt ? d.firstSalt : b.salt; + d[c] = d[c] || sjcl2.misc.pbkdf2(a, c, b.iter); + return { key: d[c].slice(0), salt: c.slice(0) }; + }; + "undefined" !== typeof module && module.exports && (module.exports = sjcl2); + "function" === typeof define && define([], function() { + return sjcl2; + }); + } +}); + +// node_modules/.deno/eventemitter3@5.0.1/node_modules/eventemitter3/index.js +var require_eventemitter3 = __commonJS({ + "node_modules/.deno/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) { + "use strict"; + var has = Object.prototype.hasOwnProperty; + var prefix = "~"; + function Events() { + } + if (Object.create) { + Events.prototype = /* @__PURE__ */ Object.create(null); + if (!new Events().__proto__) prefix = false; + } + function EE(fn, context, once) { + this.fn = fn; + this.context = context; + this.once = once || false; + } + function addListener(emitter, event, fn, context, once) { + if (typeof fn !== "function") { + throw new TypeError("The listener must be a function"); + } + var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event; + if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; + else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); + else emitter._events[evt] = [emitter._events[evt], listener]; + return emitter; + } + function clearEvent(emitter, evt) { + if (--emitter._eventsCount === 0) emitter._events = new Events(); + else delete emitter._events[evt]; + } + function EventEmitter5() { + this._events = new Events(); + this._eventsCount = 0; + } + EventEmitter5.prototype.eventNames = function eventNames() { + var names = [], events3, name; + if (this._eventsCount === 0) return names; + for (name in events3 = this._events) { + if (has.call(events3, name)) names.push(prefix ? name.slice(1) : name); + } + if (Object.getOwnPropertySymbols) { + return names.concat(Object.getOwnPropertySymbols(events3)); + } + return names; + }; + EventEmitter5.prototype.listeners = function listeners(event) { + var evt = prefix ? prefix + event : event, handlers = this._events[evt]; + if (!handlers) return []; + if (handlers.fn) return [handlers.fn]; + for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { + ee[i] = handlers[i].fn; + } + return ee; + }; + EventEmitter5.prototype.listenerCount = function listenerCount(event) { + var evt = prefix ? prefix + event : event, listeners = this._events[evt]; + if (!listeners) return 0; + if (listeners.fn) return 1; + return listeners.length; + }; + EventEmitter5.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { + var evt = prefix ? prefix + event : event; + if (!this._events[evt]) return false; + var listeners = this._events[evt], len = arguments.length, args, i; + if (listeners.fn) { + if (listeners.once) this.removeListener(event, listeners.fn, void 0, true); + switch (len) { + case 1: + return listeners.fn.call(listeners.context), true; + case 2: + return listeners.fn.call(listeners.context, a1), true; + case 3: + return listeners.fn.call(listeners.context, a1, a2), true; + case 4: + return listeners.fn.call(listeners.context, a1, a2, a3), true; + case 5: + return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; + case 6: + return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; + } + for (i = 1, args = new Array(len - 1); i < len; i++) { + args[i - 1] = arguments[i]; + } + listeners.fn.apply(listeners.context, args); + } else { + var length = listeners.length, j; + for (i = 0; i < length; i++) { + if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true); + switch (len) { + case 1: + listeners[i].fn.call(listeners[i].context); + break; + case 2: + listeners[i].fn.call(listeners[i].context, a1); + break; + case 3: + listeners[i].fn.call(listeners[i].context, a1, a2); + break; + case 4: + listeners[i].fn.call(listeners[i].context, a1, a2, a3); + break; + default: + if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) { + args[j - 1] = arguments[j]; + } + listeners[i].fn.apply(listeners[i].context, args); + } + } + } + return true; + }; + EventEmitter5.prototype.on = function on(event, fn, context) { + return addListener(this, event, fn, context, false); + }; + EventEmitter5.prototype.once = function once(event, fn, context) { + return addListener(this, event, fn, context, true); + }; + EventEmitter5.prototype.removeListener = function removeListener(event, fn, context, once) { + var evt = prefix ? prefix + event : event; + if (!this._events[evt]) return this; + if (!fn) { + clearEvent(this, evt); + return this; + } + var listeners = this._events[evt]; + if (listeners.fn) { + if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) { + clearEvent(this, evt); + } + } else { + for (var i = 0, events3 = [], length = listeners.length; i < length; i++) { + if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) { + events3.push(listeners[i]); + } + } + if (events3.length) this._events[evt] = events3.length === 1 ? events3[0] : events3; + else clearEvent(this, evt); + } + return this; + }; + EventEmitter5.prototype.removeAllListeners = function removeAllListeners(event) { + var evt; + if (event) { + evt = prefix ? prefix + event : event; + if (this._events[evt]) clearEvent(this, evt); + } else { + this._events = new Events(); + this._eventsCount = 0; + } + return this; + }; + EventEmitter5.prototype.off = EventEmitter5.prototype.removeListener; + EventEmitter5.prototype.addListener = EventEmitter5.prototype.on; + EventEmitter5.prefixed = prefix; + EventEmitter5.EventEmitter = EventEmitter5; + if ("undefined" !== typeof module) { + module.exports = EventEmitter5; + } + } +}); + +// node_modules/.deno/neverthrow@8.0.0/node_modules/neverthrow/dist/index.es.js +var defaultErrorConfig = { + withStackTrace: false +}; +var createNeverThrowError = (message, result, config = defaultErrorConfig) => { + const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error }; + const maybeStack = config.withStackTrace ? new Error().stack : void 0; + return { + data, + message, + stack: maybeStack + }; +}; +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, [])).next()); + }); +} +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function() { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} +function __await(v) { + return this instanceof __await ? (this.v = v, this) : new __await(v); +} +function __asyncGenerator(thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i; + function verb(n) { + if (g[n]) i[n] = function(v) { + return new Promise(function(a, b) { + q.push([n, v, a, b]) > 1 || resume(n, v); + }); + }; + } + function resume(n, v) { + try { + step(g[n](v)); + } catch (e) { + settle(q[0][3], e); + } + } + function step(r) { + r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); + } + function fulfill(value) { + resume("next", value); + } + function reject(value) { + resume("throw", value); + } + function settle(f, v) { + if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); + } +} +function __asyncDelegator(o) { + var i, p; + return i = {}, verb("next"), verb("throw", function(e) { + throw e; + }), verb("return"), i[Symbol.iterator] = function() { + return this; + }, i; + function verb(n, f) { + i[n] = o[n] ? function(v) { + return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; + } : f; + } +} +function __asyncValues(o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator], i; + return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { + return this; + }, i); + function verb(n) { + i[n] = o[n] && function(v) { + return new Promise(function(resolve, reject) { + v = o[n](v), settle(resolve, reject, v.done, v.value); + }); + }; + } + function settle(resolve, reject, d, v) { + Promise.resolve(v).then(function(v2) { + resolve({ value: v2, done: d }); + }, reject); + } +} +var ResultAsync = class _ResultAsync { + constructor(res) { + this._promise = res; + } + static fromSafePromise(promise) { + const newPromise = promise.then((value) => new Ok(value)); + return new _ResultAsync(newPromise); + } + static fromPromise(promise, errorFn) { + const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e))); + return new _ResultAsync(newPromise); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromThrowable(fn, errorFn) { + return (...args) => { + return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () { + try { + return new Ok(yield fn(...args)); + } catch (error) { + return new Err(errorFn ? errorFn(error) : error); + } + }))()); + }; + } + static combine(asyncResultList) { + return combineResultAsyncList(asyncResultList); + } + static combineWithAllErrors(asyncResultList) { + return combineResultAsyncListWithAllErrors(asyncResultList); + } + map(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + return new Ok(yield f(res.value)); + }))); + } + andThrough(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + const newRes = yield f(res.value); + if (newRes.isErr()) { + return new Err(newRes.error); + } + return new Ok(res.value); + }))); + } + andTee(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return new Err(res.error); + } + try { + yield f(res.value); + } catch (e) { + } + return new Ok(res.value); + }))); + } + mapErr(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isOk()) { + return new Ok(res.value); + } + return new Err(yield f(res.error)); + }))); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return new _ResultAsync(this._promise.then((res) => { + if (res.isErr()) { + return new Err(res.error); + } + const newValue = f(res.value); + return newValue instanceof _ResultAsync ? newValue._promise : newValue; + })); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () { + if (res.isErr()) { + return f(res.error); + } + return new Ok(res.value); + }))); + } + match(ok2, _err) { + return this._promise.then((res) => res.match(ok2, _err)); + } + unwrapOr(t) { + return this._promise.then((res) => res.unwrapOr(t)); + } + /** + * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`. + */ + safeUnwrap() { + return __asyncGenerator(this, arguments, function* safeUnwrap_1() { + return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap())))))); + }); + } + // Makes ResultAsync implement PromiseLike + then(successCallback, failureCallback) { + return this._promise.then(successCallback, failureCallback); + } +}; +var okAsync = (value) => new ResultAsync(Promise.resolve(new Ok(value))); +var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2))); +var fromPromise = ResultAsync.fromPromise; +var fromSafePromise = ResultAsync.fromSafePromise; +var fromAsyncThrowable = ResultAsync.fromThrowable; +var combineResultList = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr()) { + acc = err(result.error); + break; + } else { + acc.map((list) => list.push(result.value)); + } + } + return acc; +}; +var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList); +var combineResultListWithAllErrors = (resultList) => { + let acc = ok([]); + for (const result of resultList) { + if (result.isErr() && acc.isErr()) { + acc.error.push(result.error); + } else if (result.isErr() && acc.isOk()) { + acc = err([result.error]); + } else if (result.isOk() && acc.isOk()) { + acc.value.push(result.value); + } + } + return acc; +}; +var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors); +var Result; +(function(Result3) { + function fromThrowable2(fn, errorFn) { + return (...args) => { + try { + const result = fn(...args); + return ok(result); + } catch (e) { + return err(errorFn ? errorFn(e) : e); + } + }; + } + Result3.fromThrowable = fromThrowable2; + function combine(resultList) { + return combineResultList(resultList); + } + Result3.combine = combine; + function combineWithAllErrors(resultList) { + return combineResultListWithAllErrors(resultList); + } + Result3.combineWithAllErrors = combineWithAllErrors; +})(Result || (Result = {})); +var ok = (value) => new Ok(value); +function err(err2) { + return new Err(err2); +} +var Ok = class { + constructor(value) { + this.value = value; + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return ok(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + mapErr(_f) { + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThrough(f) { + return f(this.value).map((_value) => this.value); + } + andTee(f) { + try { + f(this.value); + } catch (e) { + } + return ok(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(_f) { + return ok(this.value); + } + asyncAndThen(f) { + return f(this.value); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + asyncAndThrough(f) { + return f(this.value).map(() => this.value); + } + asyncMap(f) { + return ResultAsync.fromSafePromise(f(this.value)); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + unwrapOr(_v) { + return this.value; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + match(ok2, _err) { + return ok2(this.value); + } + safeUnwrap() { + const value = this.value; + return function* () { + return value; + }(); + } + _unsafeUnwrap(_) { + return this.value; + } + _unsafeUnwrapErr(config) { + throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config); + } +}; +var Err = class { + constructor(error) { + this.error = error; + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + map(_f) { + return err(this.error); + } + mapErr(f) { + return err(f(this.error)); + } + andThrough(_f) { + return err(this.error); + } + andTee(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + andThen(_f) { + return err(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + orElse(f) { + return f(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncAndThen(_f) { + return errAsync(this.error); + } + asyncAndThrough(_f) { + return errAsync(this.error); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + asyncMap(_f) { + return errAsync(this.error); + } + unwrapOr(v) { + return v; + } + match(_ok, err2) { + return err2(this.error); + } + safeUnwrap() { + const error = this.error; + return function* () { + yield err(error); + throw new Error("Do not use this generator out of `safeTry`"); + }(); + } + _unsafeUnwrap(config) { + throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config); + } + _unsafeUnwrapErr(_) { + return this.error; + } +}; +var fromThrowable = Result.fromThrowable; + +// src/error/base-error.ts +var BaseError = class extends Error { + constructor(message, options = {}) { + const { cause, context } = options; + super(message, { cause }); + __publicField(this, "context"); + this.name = this.constructor.name; + this.context = context; + } +}; + +// src/utils.ts +var ensureError = (value) => { + if (value instanceof Error) return value; + let stringified = "[Unable to stringify the thrown value]"; + try { + stringified = JSON.stringify(value); + } catch (_error) { + } + const error = new Error(stringified); + return error; +}; +var isDenoRuntime = () => typeof Deno !== "undefined"; +var workerUrl = (relativePath) => isDenoRuntime() ? new URL(`./worker/${relativePath}.ts`, new URL(".", import.meta.url).href) : new URL( + import.meta.resolve( + `./${relativePath === "main" ? `worker/${relativePath}` : relativePath}.js` + ) +); + +// src/error/websocket/websocket-error.ts +var WebSocketError = class extends BaseError { +}; + +// src/error/websocket/websocket-connection-error.ts +var WebSocketConnectionError = class extends WebSocketError { + constructor() { + super(...arguments); + __publicField(this, "message", "An error occured while trying to connect to WebSocket"); + } +}; + +// src/worker/main.ts +var import_events = __toESM(require_events()); +var events = new import_events.default(); +var worker; +var isInitialized = false; +self.onmessage = (event) => { + addWorker(event); + if (!isInitialized) { + isInitialized = true; + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + if (worker) { + worker.terminate(); + } + }); + } +}; +var updateFile = (lufiFile, args) => { + Object.assign(lufiFile, args); + if (typeof WorkerGlobalScope !== "undefined") { + self.postMessage({ + event: "FILE_UPDATED" /* FILE_UPDATED */, + lufiFile + }); + } + return lufiFile; +}; +var sendFileError = (lufiFile, error) => { + updateFile(lufiFile, { uploadStatus: 2 /* FAILED */ }); + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); +}; +var addWorker = (event, callback) => { + const { action } = event.data; + if (action === 5 /* PAUSE */ || action === 8 /* RESUME */) { + worker.postMessage(event.data); + } else { + switch (action) { + case 2 /* CANCEL */: + { + worker = new Worker(workerUrl("cancel"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 3 /* DOWNLOAD */: + { + worker = new Worker(workerUrl("download"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 4 /* INFOS */: + { + worker = new Worker(workerUrl("infos"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 7 /* REMOVE */: + { + worker = worker || new Worker(workerUrl("remove"), { type: "module" }); + worker.postMessage(event.data); + } + break; + case 9 /* UPLOAD */: + { + worker = worker || new Worker(workerUrl("upload"), { type: "module" }); + worker.postMessage(event.data); + } + break; + default: { + console.error("Action not found"); + } + } + worker.onmessage = (e) => { + if (callback) callback(e); + self.postMessage(e.data); + }; + worker.onerror = (error) => { + console.error(`Error: ${error.message}`); + }; + } +}; +var init = () => { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + self.postMessage({ + event: "SOCKET_OPENED" /* SOCKET_OPENED */ + }); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, (error) => { + self.postMessage({ event: "OPERATION_FAILED" /* OPERATION_FAILED */, error }); + }); +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/encoding.js +var Encoding = class { + /** + * + * @param charset Charset to use for base64 encoding. This must be 64-characters long. + * @param noPadding If true, encoded strings won't include padding. + */ + constructor(charset, noPadding) { + if (!charset || charset.length != 64) { + throw Error("Charset must contain 64 characters"); + } + this._charset = charset; + this._noPadding = !!noPadding; + this._valid = new RegExp("^[" + this._charset.replace("-", "\\-") + "]+={0,2}$"); + } + /** + * Encode an ArrayBuffer to base64 in a string. + * @param ab Data to encode to base64 + * @returns Base64-encoded string + */ + Encode(ab) { + const len = ab.byteLength; + if (!len) { + return ""; + } + const view = new Uint8Array(ab); + let res = ""; + for (let i = 0; i < len; i += 3) { + res += this._charset[view[i] >> 2] + this._charset[(view[i] & 3) << 4 | view[i + 1] >> 4] + this._charset[(view[i + 1] & 15) << 2 | view[i + 2] >> 6] + this._charset[view[i + 2] & 63]; + } + if (len % 3 == 2) { + res = res.substring(0, res.length - 1); + if (!this._noPadding) { + res += "="; + } + } else if (len % 3 == 1) { + res = res.substring(0, res.length - 2); + if (!this._noPadding) { + res += "=="; + } + } + return res; + } + /** + * Decode a string from base64. Padding is always optional. + * @param str Base64-encoded string + * @returns Data decoded from the base64 string + */ + Decode(str) { + str = (str || "").replace(/[\s]/g, ""); + if (!str) { + return new ArrayBuffer(0); + } + if (!this._valid.test(str)) { + throw Error("Invalid base64 input sequence"); + } + let viewLen = Math.floor(str.length * 0.75); + if (str[str.length - 2] == "=") { + viewLen -= 2; + } else if (str[str.length - 1] == "=") { + viewLen--; + } + const view = new Uint8Array(viewLen); + let enc1, enc2, enc3, enc4, i = 0, j = 0; + while (i < str.length * 0.75) { + enc1 = this._charset.indexOf(str.charAt(j++)); + enc2 = this._charset.indexOf(str.charAt(j++)); + enc3 = this._charset.indexOf(str.charAt(j++)); + enc4 = this._charset.indexOf(str.charAt(j++)); + view[i++] = enc1 << 2 | enc2 >> 4; + view[i++] = (enc2 & 15) << 4 | enc3 >> 2; + view[i++] = (enc3 & 3) << 6 | enc4; + } + return view.buffer; + } +}; + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/standard.js +var obj = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); +function Decode(str) { + return obj.Decode(str); +} + +// node_modules/.deno/arraybuffer-encoding@1.1.0/node_modules/arraybuffer-encoding/dist/esm/base64/url.js +var obj2 = new Encoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", true); +function Decode2(str) { + return obj2.Decode(str); +} + +// src/api/crypto/sjcl.ts +var import_sjcl = __toESM(require_sjcl()); + +// src/error/crypto/crypto-error.ts +var CryptoError = class extends BaseError { +}; + +// src/error/crypto/decryption-error.ts +var DecryptionError = class extends CryptoError { + constructor() { + super(...arguments); + __publicField(this, "message", "Unable to decrypt the provided data"); + } +}; + +// src/api/crypto/sjcl.ts +var decrypt = (key, encryptedData) => { + try { + const data = typeof encryptedData === "string" ? encryptedData : encryptedData.data; + return okAsync(Decode(import_sjcl.default.decrypt(key, data))); + } catch (error) { + return errAsync( + new DecryptionError(void 0, { cause: ensureError(error) }) + ); + } +}; + +// src/api/crypto/web.ts +var decrypt2 = (key, encrypted) => { + return importKey(key).andThen( + (importedKey) => ResultAsync.fromPromise( + crypto.subtle.decrypt( + { + name: "AES-GCM", + iv: encrypted.iv + }, + importedKey, + Decode(encrypted.data) + ), + (error) => new DecryptionError(void 0, { cause: ensureError(error) }) + ) + ); +}; +var importKey = (key) => { + return ResultAsync.fromPromise( + crypto.subtle.importKey( + "raw", + Decode2(key), + { name: "AES-GCM" }, + false, + [ + "encrypt", + "decrypt" + ] + ), + (error) => new CryptoError("Unable to import cryptography key", { + cause: ensureError(error) + }) + ); +}; + +// src/api/crypto.ts +var decrypt3 = (key, value) => { + return value.algo === void 0 || value.algo === 0 /* Sjcl */ ? decrypt(key, value) : decrypt2(key, value); +}; + +// src/api/websocket.ts +var sockets = {}; +var MAX_ERRORS = 5; +var onCancelMessage = (data) => { + events.emit("UPLOAD_CANCELLED" /* UPLOAD_CANCELLED */, data.success); + return okAsync(void 0); +}; +var onDownloadMessage = (response, lufiFile) => { + const result = response.split("XXMOJOXX"); + const metadataString = result.shift(); + if (metadataString !== void 0) { + const metadata = JSON.parse(metadataString); + if (isServerDownloadChunkSuccessMetadata(metadata)) { + const dataString = result.shift(); + if (dataString) { + const encryptedData = JSON.parse(dataString); + if (encryptedData.iv) { + encryptedData.iv = new Uint8Array(Object.values(encryptedData.iv)); + } + return decrypt3(lufiFile.keys.client, encryptedData).andThen( + (decryptedPart) => { + const chunk = typeof decryptedPart === "string" ? new TextEncoder().encode(decryptedPart).buffer : decryptedPart; + if (metadata.part === 0) { + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + delAtFirstView: metadata.del_at_first_view, + delay: metadata.delay, + name: metadata.name, + size: metadata.size, + totalChunks: metadata.total, + type: metadata.type, + zipped: metadata.zipped + }); + events.emit("DOWNLOAD_STARTED" /* DOWNLOAD_STARTED */); + } else { + updateFile(lufiFile, { chunksReady: lufiFile.chunksReady + 1 }); + } + events.emit("CHUNK_DOWNLOADED" /* CHUNK_DOWNLOADED */, chunk, metadata.part); + if (++metadata.part === metadata.total) { + return endDownload(lufiFile).andThen(() => { + events.emit("DOWNLOAD_COMPLETE" /* DOWNLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + return okAsync(void 0); + }); + } + return okAsync(void 0); + } + ); + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError(metadata.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } + } else { + const error = new WebSocketError( + "Can't retrieve metadata from data received by the server" + ); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onUploadMessage = (response, lufiFile) => { + if (response.success) { + if (response.j === 0) { + updateFile(lufiFile, { + keys: { client: lufiFile.keys.client, server: response.short }, + actionToken: response.token, + queueIndex: response.i + }); + events.emit("UPLOAD_STARTED" /* UPLOAD_STARTED */); + } + updateFile(lufiFile, { + chunksReady: lufiFile.chunksReady + 1, + createdAt: response.created_at + }); + events.emit("CHUNK_UPLOADED" /* CHUNK_UPLOADED */); + if (lufiFile.chunksReady === lufiFile.totalChunks) { + updateFile(lufiFile, { uploadStatus: 1 /* COMPLETE */ }); + events.emit("UPLOAD_COMPLETE" /* UPLOAD_COMPLETE */); + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + } + return okAsync(void 0); + } else { + const error = new WebSocketError(response.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } +}; +var onMessage = (e, lufiFile) => { + const data = tryParseJson(e.data); + let callback; + if (data) { + if (!data.action && data.msg) { + const error = new WebSocketError(data.msg); + events.emit("OPERATION_FAILED" /* OPERATION_FAILED */, error); + return errAsync(error); + } else { + if ("delay" in data) { + callback = onUploadMessage(data, lufiFile); + } else { + callback = onCancelMessage(data); + } + } + } else { + callback = onDownloadMessage(e.data, lufiFile); + } + return callback; +}; +var isConnecting = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.CONNECTING; +var isSpawned = (socketKey) => sockets !== void 0 && sockets[socketKey] !== void 0 && sockets[socketKey].readyState === WebSocket.OPEN; +var endDownload = (lufiFile) => { + let message; + if (lufiFile.password) { + message = { ended: true, file_pwd: lufiFile.password }; + } else { + message = { ended: true }; + } + return sendMessage( + downloadSocketUrl(lufiFile), + lufiFile, + JSON.stringify(message) + ); +}; +var uploadChunk = (lufiFile, metadata, encryptedData) => sendMessage( + uploadSocketUrl(lufiFile), + lufiFile, + `${JSON.stringify(metadata)}XXMOJOXX${JSON.stringify(encryptedData)}` +); +var sendMessage = (socketUrl, lufiFile, message) => { + if (!isSpawned(socketUrl)) { + return spawn(socketUrl).andThen( + () => sendMessage(socketUrl, lufiFile, message) + ); + } else { + sockets[socketUrl].onmessage = (e) => onMessage(e, lufiFile); + sockets[socketUrl].send(message); + return okAsync(void 0); + } +}; +var spawn = (socketKey, errorCount = 0) => { + if (!isSpawned(socketKey) && !isConnecting(socketKey)) { + sockets[socketKey] = new WebSocket(socketKey); + events.once("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */, () => { + sockets[socketKey].close(); + }); + events.once("OPERATION_FAILED" /* OPERATION_FAILED */, () => { + events.emit("SOCKET_OPERATION_TERMINATED" /* SOCKET_OPERATION_TERMINATED */); + }); + sockets[socketKey].onopen = () => { + events.emit("SOCKET_OPENED" /* SOCKET_OPENED */); + }; + sockets[socketKey].onclose = () => { + }; + sockets[socketKey].onerror = () => { + if (++errorCount <= MAX_ERRORS) { + console.error( + `An error happened while trying to connect to WebSocket ${socketKey}. Trying again. ${errorCount} / ${MAX_ERRORS}` + ); + return spawn(socketKey, errorCount); + } else { + events.emit("SOCKET_ONERROR" /* SOCKET_ONERROR */); + return errAsync( + new WebSocketConnectionError( + `Unable to connect to WebSocket ${socketKey}.` + ) + ); + } + }; + } + return waitForConnection(socketKey).andThen(() => okAsync(socketKey)).orElse((error) => errAsync(error)); +}; +var waitForConnection = (socketKey) => ResultAsync.fromPromise( + new Promise((resolve, reject) => { + if (!isSpawned(socketKey)) { + events.once("SOCKET_OPENED" /* SOCKET_OPENED */, () => { + resolve(void 0); + }); + events.on("SOCKET_ONERROR" /* SOCKET_ONERROR */, () => { + reject(new WebSocketConnectionError()); + }); + } else { + resolve(void 0); + } + }), + (error) => { + return ensureError(error); + } +); +var buildSocketUrl = (instanceUrl, pathname) => { + const url = new URL(instanceUrl); + url.protocol = url.protocol === "http:" ? "ws:" : "wss:"; + url.pathname += pathname; + return new URL(url.origin + url.pathname); +}; +var downloadSocketUrl = (lufiFile) => { + return buildSocketUrl( + new URL(lufiFile.serverUrl), + "download" /* DOWNLOAD */ + `/${lufiFile.keys.server}` + ).toString(); +}; +var uploadSocketUrl = (lufiFile) => { + return buildSocketUrl(new URL(lufiFile.serverUrl), "upload" /* UPLOAD */).toString(); +}; +var tryParseJson = (data) => { + try { + const parsedObject = JSON.parse(data); + if (parsedObject && typeof parsedObject === "object") { + return parsedObject; + } + } catch (_e) { + } + return false; +}; +var isServerDownloadChunkSuccessMetadata = (message) => { + return typeof message === "object" && message !== null && !("msg" in message); +}; + +// src/api/lufi.ts +var import_events3 = __toESM(require_events()); + +// src/entities/lufi-job.ts +var import_events2 = __toESM(require_events()); + +// src/api/lufi.ts +var files = {}; +var events2 = new import_events3.default(); +var getFilesQueued = () => Object.values(files).filter( + (file) => file.uploadStatus === 4 /* QUEUED */ +); +var getFileIndexInQueue = (clientKey) => Object.keys(getFilesQueued()).indexOf(clientKey); + +// node_modules/.deno/eventemitter3@5.0.1/node_modules/eventemitter3/index.mjs +var import_index = __toESM(require_eventemitter3(), 1); + +// node_modules/.deno/p-timeout@6.1.3/node_modules/p-timeout/index.js +var TimeoutError = class extends Error { + constructor(message) { + super(message); + this.name = "TimeoutError"; + } +}; +var AbortError = class extends Error { + constructor(message) { + super(); + this.name = "AbortError"; + this.message = message; + } +}; +var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new AbortError(errorMessage) : new DOMException(errorMessage); +var getAbortedReason = (signal) => { + const reason = signal.reason === void 0 ? getDOMException("This operation was aborted.") : signal.reason; + return reason instanceof Error ? reason : getDOMException(reason); +}; +function pTimeout(promise, options) { + const { + milliseconds, + fallback, + message, + customTimers = { setTimeout, clearTimeout } + } = options; + let timer; + const wrappedPromise = new Promise((resolve, reject) => { + if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) { + throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``); + } + if (options.signal) { + const { signal } = options; + if (signal.aborted) { + reject(getAbortedReason(signal)); + } + const abortHandler = () => { + reject(getAbortedReason(signal)); + }; + signal.addEventListener("abort", abortHandler, { once: true }); + promise.finally(() => { + signal.removeEventListener("abort", abortHandler); + }); + } + if (milliseconds === Number.POSITIVE_INFINITY) { + promise.then(resolve, reject); + return; + } + const timeoutError = new TimeoutError(); + timer = customTimers.setTimeout.call(void 0, () => { + if (fallback) { + try { + resolve(fallback()); + } catch (error) { + reject(error); + } + return; + } + if (typeof promise.cancel === "function") { + promise.cancel(); + } + if (message === false) { + resolve(); + } else if (message instanceof Error) { + reject(message); + } else { + timeoutError.message = message != null ? message : `Promise timed out after ${milliseconds} milliseconds`; + reject(timeoutError); + } + }, milliseconds); + (async () => { + try { + resolve(await promise); + } catch (error) { + reject(error); + } + })(); + }); + const cancelablePromise = wrappedPromise.finally(() => { + cancelablePromise.clear(); + }); + cancelablePromise.clear = () => { + customTimers.clearTimeout.call(void 0, timer); + timer = void 0; + }; + return cancelablePromise; +} + +// node_modules/.deno/p-queue@8.0.1/node_modules/p-queue/dist/lower-bound.js +function lowerBound(array, value, comparator) { + let first = 0; + let count = array.length; + while (count > 0) { + const step = Math.trunc(count / 2); + let it = first + step; + if (comparator(array[it], value) <= 0) { + first = ++it; + count -= step + 1; + } else { + count = step; + } + } + return first; +} + +// node_modules/.deno/p-queue@8.0.1/node_modules/p-queue/dist/priority-queue.js +var _queue; +var PriorityQueue = class { + constructor() { + __privateAdd(this, _queue, []); + } + enqueue(run, options) { + options = { + priority: 0, + ...options + }; + const element = { + priority: options.priority, + run + }; + if (this.size && __privateGet(this, _queue)[this.size - 1].priority >= options.priority) { + __privateGet(this, _queue).push(element); + return; + } + const index = lowerBound(__privateGet(this, _queue), element, (a, b) => b.priority - a.priority); + __privateGet(this, _queue).splice(index, 0, element); + } + dequeue() { + const item = __privateGet(this, _queue).shift(); + return item == null ? void 0 : item.run; + } + filter(options) { + return __privateGet(this, _queue).filter((element) => element.priority === options.priority).map((element) => element.run); + } + get size() { + return __privateGet(this, _queue).length; + } +}; +_queue = new WeakMap(); + +// node_modules/.deno/p-queue@8.0.1/node_modules/p-queue/dist/index.js +var _carryoverConcurrencyCount, _isIntervalIgnored, _intervalCount, _intervalCap, _interval, _intervalEnd, _intervalId, _timeoutId, _queue2, _queueClass, _pending, _concurrency, _isPaused, _throwOnTimeout, _PQueue_instances, doesIntervalAllowAnother_get, doesConcurrentAllowAnother_get, next_fn, onResumeInterval_fn, isIntervalPaused_get, tryToStartAnother_fn, initializeIntervalIfNeeded_fn, onInterval_fn, processQueue_fn, throwOnAbort_fn, onEvent_fn; +var PQueue = class extends import_index.default { + // TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()` + constructor(options) { + var _a, _b, _c, _d; + super(); + __privateAdd(this, _PQueue_instances); + __privateAdd(this, _carryoverConcurrencyCount); + __privateAdd(this, _isIntervalIgnored); + __privateAdd(this, _intervalCount, 0); + __privateAdd(this, _intervalCap); + __privateAdd(this, _interval); + __privateAdd(this, _intervalEnd, 0); + __privateAdd(this, _intervalId); + __privateAdd(this, _timeoutId); + __privateAdd(this, _queue2); + __privateAdd(this, _queueClass); + __privateAdd(this, _pending, 0); + // The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194 + __privateAdd(this, _concurrency); + __privateAdd(this, _isPaused); + __privateAdd(this, _throwOnTimeout); + /** + Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already. + + Applies to each future operation. + */ + __publicField(this, "timeout"); + options = { + carryoverConcurrencyCount: false, + intervalCap: Number.POSITIVE_INFINITY, + interval: 0, + concurrency: Number.POSITIVE_INFINITY, + autoStart: true, + queueClass: PriorityQueue, + ...options + }; + if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) { + throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(_b = (_a = options.intervalCap) == null ? void 0 : _a.toString()) != null ? _b : ""}\` (${typeof options.intervalCap})`); + } + if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) { + throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(_d = (_c = options.interval) == null ? void 0 : _c.toString()) != null ? _d : ""}\` (${typeof options.interval})`); + } + __privateSet(this, _carryoverConcurrencyCount, options.carryoverConcurrencyCount); + __privateSet(this, _isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0); + __privateSet(this, _intervalCap, options.intervalCap); + __privateSet(this, _interval, options.interval); + __privateSet(this, _queue2, new options.queueClass()); + __privateSet(this, _queueClass, options.queueClass); + this.concurrency = options.concurrency; + this.timeout = options.timeout; + __privateSet(this, _throwOnTimeout, options.throwOnTimeout === true); + __privateSet(this, _isPaused, options.autoStart === false); + } + get concurrency() { + return __privateGet(this, _concurrency); + } + set concurrency(newConcurrency) { + if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) { + throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`); + } + __privateSet(this, _concurrency, newConcurrency); + __privateMethod(this, _PQueue_instances, processQueue_fn).call(this); + } + async add(function_, options = {}) { + options = { + timeout: this.timeout, + throwOnTimeout: __privateGet(this, _throwOnTimeout), + ...options + }; + return new Promise((resolve, reject) => { + __privateGet(this, _queue2).enqueue(async () => { + var _a; + __privateWrapper(this, _pending)._++; + __privateWrapper(this, _intervalCount)._++; + try { + (_a = options.signal) == null ? void 0 : _a.throwIfAborted(); + let operation = function_({ signal: options.signal }); + if (options.timeout) { + operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout }); + } + if (options.signal) { + operation = Promise.race([operation, __privateMethod(this, _PQueue_instances, throwOnAbort_fn).call(this, options.signal)]); + } + const result = await operation; + resolve(result); + this.emit("completed", result); + } catch (error) { + if (error instanceof TimeoutError && !options.throwOnTimeout) { + resolve(); + return; + } + reject(error); + this.emit("error", error); + } finally { + __privateMethod(this, _PQueue_instances, next_fn).call(this); + } + }, options); + this.emit("add"); + __privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this); + }); + } + async addAll(functions, options) { + return Promise.all(functions.map(async (function_) => this.add(function_, options))); + } + /** + Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.) + */ + start() { + if (!__privateGet(this, _isPaused)) { + return this; + } + __privateSet(this, _isPaused, false); + __privateMethod(this, _PQueue_instances, processQueue_fn).call(this); + return this; + } + /** + Put queue execution on hold. + */ + pause() { + __privateSet(this, _isPaused, true); + } + /** + Clear the queue. + */ + clear() { + __privateSet(this, _queue2, new (__privateGet(this, _queueClass))()); + } + /** + Can be called multiple times. Useful if you for example add additional items at a later time. + + @returns A promise that settles when the queue becomes empty. + */ + async onEmpty() { + if (__privateGet(this, _queue2).size === 0) { + return; + } + await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "empty"); + } + /** + @returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`. + + If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item. + + Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation. + */ + async onSizeLessThan(limit) { + if (__privateGet(this, _queue2).size < limit) { + return; + } + await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "next", () => __privateGet(this, _queue2).size < limit); + } + /** + The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet. + + @returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`. + */ + async onIdle() { + if (__privateGet(this, _pending) === 0 && __privateGet(this, _queue2).size === 0) { + return; + } + await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "idle"); + } + /** + Size of the queue, the number of queued items waiting to run. + */ + get size() { + return __privateGet(this, _queue2).size; + } + /** + Size of the queue, filtered by the given options. + + For example, this can be used to find the number of items remaining in the queue with a specific priority level. + */ + sizeBy(options) { + return __privateGet(this, _queue2).filter(options).length; + } + /** + Number of running items (no longer in the queue). + */ + get pending() { + return __privateGet(this, _pending); + } + /** + Whether the queue is currently paused. + */ + get isPaused() { + return __privateGet(this, _isPaused); + } +}; +_carryoverConcurrencyCount = new WeakMap(); +_isIntervalIgnored = new WeakMap(); +_intervalCount = new WeakMap(); +_intervalCap = new WeakMap(); +_interval = new WeakMap(); +_intervalEnd = new WeakMap(); +_intervalId = new WeakMap(); +_timeoutId = new WeakMap(); +_queue2 = new WeakMap(); +_queueClass = new WeakMap(); +_pending = new WeakMap(); +_concurrency = new WeakMap(); +_isPaused = new WeakMap(); +_throwOnTimeout = new WeakMap(); +_PQueue_instances = new WeakSet(); +doesIntervalAllowAnother_get = function() { + return __privateGet(this, _isIntervalIgnored) || __privateGet(this, _intervalCount) < __privateGet(this, _intervalCap); +}; +doesConcurrentAllowAnother_get = function() { + return __privateGet(this, _pending) < __privateGet(this, _concurrency); +}; +next_fn = function() { + __privateWrapper(this, _pending)._--; + __privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this); + this.emit("next"); +}; +onResumeInterval_fn = function() { + __privateMethod(this, _PQueue_instances, onInterval_fn).call(this); + __privateMethod(this, _PQueue_instances, initializeIntervalIfNeeded_fn).call(this); + __privateSet(this, _timeoutId, void 0); +}; +isIntervalPaused_get = function() { + const now = Date.now(); + if (__privateGet(this, _intervalId) === void 0) { + const delay = __privateGet(this, _intervalEnd) - now; + if (delay < 0) { + __privateSet(this, _intervalCount, __privateGet(this, _carryoverConcurrencyCount) ? __privateGet(this, _pending) : 0); + } else { + if (__privateGet(this, _timeoutId) === void 0) { + __privateSet(this, _timeoutId, setTimeout(() => { + __privateMethod(this, _PQueue_instances, onResumeInterval_fn).call(this); + }, delay)); + } + return true; + } + } + return false; +}; +tryToStartAnother_fn = function() { + if (__privateGet(this, _queue2).size === 0) { + if (__privateGet(this, _intervalId)) { + clearInterval(__privateGet(this, _intervalId)); + } + __privateSet(this, _intervalId, void 0); + this.emit("empty"); + if (__privateGet(this, _pending) === 0) { + this.emit("idle"); + } + return false; + } + if (!__privateGet(this, _isPaused)) { + const canInitializeInterval = !__privateGet(this, _PQueue_instances, isIntervalPaused_get); + if (__privateGet(this, _PQueue_instances, doesIntervalAllowAnother_get) && __privateGet(this, _PQueue_instances, doesConcurrentAllowAnother_get)) { + const job = __privateGet(this, _queue2).dequeue(); + if (!job) { + return false; + } + this.emit("active"); + job(); + if (canInitializeInterval) { + __privateMethod(this, _PQueue_instances, initializeIntervalIfNeeded_fn).call(this); + } + return true; + } + } + return false; +}; +initializeIntervalIfNeeded_fn = function() { + if (__privateGet(this, _isIntervalIgnored) || __privateGet(this, _intervalId) !== void 0) { + return; + } + __privateSet(this, _intervalId, setInterval(() => { + __privateMethod(this, _PQueue_instances, onInterval_fn).call(this); + }, __privateGet(this, _interval))); + __privateSet(this, _intervalEnd, Date.now() + __privateGet(this, _interval)); +}; +onInterval_fn = function() { + if (__privateGet(this, _intervalCount) === 0 && __privateGet(this, _pending) === 0 && __privateGet(this, _intervalId)) { + clearInterval(__privateGet(this, _intervalId)); + __privateSet(this, _intervalId, void 0); + } + __privateSet(this, _intervalCount, __privateGet(this, _carryoverConcurrencyCount) ? __privateGet(this, _pending) : 0); + __privateMethod(this, _PQueue_instances, processQueue_fn).call(this); +}; +/** +Executes all queued functions until it reaches the limit. +*/ +processQueue_fn = function() { + while (__privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this)) { + } +}; +throwOnAbort_fn = async function(signal) { + return new Promise((_resolve, reject) => { + signal.addEventListener("abort", () => { + reject(signal.reason); + }, { once: true }); + }); +}; +onEvent_fn = async function(event, filter) { + return new Promise((resolve) => { + const listener = () => { + if (filter && !filter()) { + return; + } + this.off(event, listener); + resolve(); + }; + this.on(event, listener); + }); +}; + +// src/worker/upload.ts +var isInitialized2 = false; +var QUEUE_CONCURRENCY_LIMIT = navigator.hardwareConcurrency || 4; +var queue = new PQueue({ + concurrency: QUEUE_CONCURRENCY_LIMIT, + autoStart: false +}); +var itemsInQueue = 0; +var chunks = []; +var isPaused = false; +self.onmessage = (event) => { + const data = event.data; + const { chunk, lufiFile } = data.args; + if (!isInitialized2) { + init(); + isInitialized2 = true; + } + if (chunk) { + chunks[chunk.index] = chunk; + if (chunks.length === lufiFile.totalChunks) { + events.once("UPLOAD_COMPLETE" /* UPLOAD_COMPLETE */, () => { + self.postMessage({ + event: "UPLOAD_COMPLETE" /* UPLOAD_COMPLETE */ + }); + }); + events.on("FILE_UPDATED" /* FILE_UPDATED */, updateFile); + events.on("CHUNK_UPLOADED" /* CHUNK_UPLOADED */, () => { + self.postMessage({ event: "CHUNK_UPLOADED" /* CHUNK_UPLOADED */ }); + itemsInQueue--; + if (!isPaused && itemsInQueue < QUEUE_CONCURRENCY_LIMIT) { + queue.start(); + } + }); + return upload(event.data); + } + } else { + if (data.action === 5 /* PAUSE */) { + isPaused = true; + queue.pause(); + self.postMessage({ event: "JOB_PAUSED" /* JOB_PAUSED */ }); + } + if (data.action === 8 /* RESUME */) { + isPaused = false; + queue.start(); + self.postMessage({ event: "JOB_RESUMED" /* JOB_RESUMED */ }); + } + } +}; +var upload = (workerMessage) => startUpload( + workerMessage, + getFileIndexInQueue(workerMessage.args.lufiFile.keys.client) +); +var startUpload = (workerMessage, queueIndex) => { + const { lufiFile } = workerMessage.args; + const job = new Worker(workerUrl("encrypt"), { type: "module" }); + events.on("UPLOAD_STARTED" /* UPLOAD_STARTED */, () => { + job.onmessage = async (event) => { + if (event.data.encryptedData) { + const { encryptedData } = event.data; + await queue.add(async () => { + await uploadChunk( + lufiFile, + { + total: lufiFile.totalChunks, + part: event.data.chunkIndex, + size: lufiFile.size, + name: lufiFile.name.split("/").pop(), + type: lufiFile.type, + delay: lufiFile.delay, + del_at_first_view: lufiFile.delAtFirstView, + zipped: lufiFile.zipped, + id: lufiFile.keys.server, + i: queueIndex, + file_pwd: lufiFile.password + }, + encryptedData + ); + itemsInQueue++; + if (isPaused || itemsInQueue === QUEUE_CONCURRENCY_LIMIT) { + queue.pause(); + } + }); + } + queue.start(); + if (event.data.error) { + sendFileError(lufiFile, event.data.error); + job.terminate(); + } + }; + for (let i = 1; i < lufiFile.totalChunks; i++) { + workerMessage.args.chunk = chunks[i]; + job.postMessage(workerMessage); + } + }); + job.onmessage = (event) => { + if (event.data.encryptedData) { + const { encryptedData } = event.data; + uploadChunk( + lufiFile, + { + total: lufiFile.totalChunks, + part: event.data.chunkIndex, + size: lufiFile.size, + name: lufiFile.name.split("/").pop(), + type: lufiFile.type, + delay: lufiFile.delay, + del_at_first_view: lufiFile.delAtFirstView, + zipped: lufiFile.zipped, + id: null, + i: queueIndex, + file_pwd: lufiFile.password + }, + encryptedData + ).mapErr((error) => { + sendFileError(lufiFile, error); + }); + } + if (event.data.error) { + sendFileError(lufiFile, event.data.error); + } + }; + workerMessage.args.chunk = chunks[0]; + job.postMessage(workerMessage); + return okAsync(void 0); +}; diff --git a/themes/default/templates/partial/files.js.ep b/themes/default/templates/partial/files.js.ep index bbd79ec..b58e21a 100644 --- a/themes/default/templates/partial/files.js.ep +++ b/themes/default/templates/partial/files.js.ep @@ -13,10 +13,10 @@ var i18n = { }; $(document).ready(function() { populateFilesTable(); - $('#invertSelection').on('click', invertSelection); - $('#exportStorage').on('click', exportStorage); - $('#purgeExpired').on('click', purgeExpired); - $('#clickImport').on('click', clickImport); - $('#mass-delete').on('click', massDelete); + document.getElementById('invertSelection').onclick = (event) => invertSelection(event); + document.getElementById('exportStorage').onclick = (event) => exportStorage(event); + document.getElementById('purgeExpired').onclick = (event) => purgeExpired(event); + document.getElementById('clickImport').onclick = (event) => clickImport(event); + document.getElementById('mass-delete').onclick = (event) => massDelete(event); });