diff --git a/CHANGES.md b/CHANGES.md index ca376187..9bd1404e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,12 @@ - FIX - バグ修正 +## 2021.2.2 +- [FIX] fflate package のバージョンを 0.7.1 から 0.7.3 に更新する + - 0.7.3 https://github.com/101arrowz/fflate/blob/master/CHANGELOG.md#073 + - 0.7.2 https://github.com/101arrowz/fflate/blob/master/CHANGELOG.md#072 + - @yuitowest + ## 2021.2.1 - [FIX] type redirect 時のシグナリングで接続エラーになった場合、例外が発火しなかった問題を修正する - @yuitowest diff --git a/dist/sora.js b/dist/sora.js index d7da88f3..5a8aabbd 100644 --- a/dist/sora.js +++ b/dist/sora.js @@ -1,7 +1,7 @@ /** * sora-js-sdk * WebRTC SFU Sora JavaScript SDK - * @version: 2021.2.1 + * @version: 2021.2.2 * @author: Shiguredo Inc. * @license: Apache-2.0 **/ @@ -828,8 +828,10 @@ // u16 "map": index -> # of codes with bit length = index var l = new u16(mb); // length of cd must be 288 (total # of codes) - for (; i < s; ++i) - ++l[cd[i] - 1]; + for (; i < s; ++i) { + if (cd[i]) + ++l[cd[i] - 1]; + } // u16 "map": index -> minimum code for bit length = index var le = new u16(mb); for (i = 0; i < mb; ++i) { @@ -915,7 +917,7 @@ if (e == null || e > v.length) e = v.length; // can't use .constructor in case user-supplied - var n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s); + var n = new (v.BYTES_PER_ELEMENT == 2 ? u16 : v.BYTES_PER_ELEMENT == 4 ? u32 : u8)(e - s); n.set(v.subarray(s, e)); return n; }; @@ -1363,15 +1365,11 @@ for (var i = 0; i <= s; i += 65535) { // end var e = i + 65535; - if (e < s) { - // write full block - pos = wfblk(w, pos, dat.subarray(i, e)); - } - else { + if (e >= s) { // write final block - w[i] = lst; - pos = wfblk(w, pos, dat.subarray(i, s)); + w[pos >> 3] = lst; } + pos = wfblk(w, pos + 1, dat.subarray(i, e)); } } else { @@ -1635,7 +1633,7 @@ } const message = { type: "connect", - sora_client: "Sora JavaScript SDK 2021.2.1", + sora_client: "Sora JavaScript SDK 2021.2.2", environment: window.navigator.userAgent, role: role, channel_id: channelId, @@ -4378,7 +4376,7 @@ * @public */ version: function () { - return "2021.2.1"; + return "2021.2.2"; }, /** * WebRTC のユーティリティ関数群 diff --git a/dist/sora.min.js b/dist/sora.min.js index f52d8207..5e141ea5 100644 --- a/dist/sora.min.js +++ b/dist/sora.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Sora=t()}(this,(function(){"use strict";class e{constructor(){if(!!!RTCRtpSender.prototype.createEncodedStreams)throw new Error("E2EE is not supported in this browser.");this.worker=null,this.onWorkerDisconnect=null}startWorker(){const e=atob("InVzZSBzdHJpY3QiOwovKiBlc2xpbnQtZGlzYWJsZSBAdHlwZXNjcmlwdC1lc2xpbnQvbm8tdW51c2VkLXZhcnMgKi8KY29uc3QgY29ubmVjdGlvbklkTGVuZ3RoID0gMjY7CmZ1bmN0aW9uIGJ5dGVDb3VudChuKSB7CiAgICBpZiAobiA9PSAwKSB7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9CiAgICAvLyBsb2cyNTYoeCkgPSBsb2coeCkgLyBsb2coMjU2KQogICAgcmV0dXJuIE1hdGguZmxvb3IoTWF0aC5sb2cobikgLyBNYXRoLmxvZygyICoqIDgpICsgMSk7Cn0KZnVuY3Rpb24gYXJyYXlCdWZmZXJUb051bWJlcihhcnJheUJ1ZmZlcikgewogICAgLy8gMzJiaXQg44G+44Gn44KS5oOz5a6aIChCaWdJbnQg44G444Gu5pu444GN5o+b44GI5pmC44Gr6KaB5L+u5q2jKQogICAgY29uc3QgbmV3QXJyYXlCdWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIoVWludDMyQXJyYXkuQllURVNfUEVSX0VMRU1FTlQpOwogICAgY29uc3QgbmV3RGF0YVZpZXcgPSBuZ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GVuKChkZXJpdmVLZXkpID0+IHsKICAgICAgICAgICAgICAgICAgICBzZXRTZWxmRGVyaXZlS2V5KHNlbGZDb25uZWN0aW9uSWQsIHNlbGZLZXlJZCwgZGVyaXZlS2V5KTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgZ2VuZXJhdGVXcml0ZUlWKG1hdGVyaWFsKS50aGVuKCh3cml0ZUlWKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgc2V0V3JpdGVJVihzZWxmQ29ubmVjdGlvbklkLCBzZWxmS2V5SWQsIHdyaXRlSVYpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZW91dElkKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSwgd2FpdGluZ1RpbWUgfHwgMCk7CiAgICAgICAgLy8gVE9ETzogKzEwMDAg44Gn6Y2155Sf5oiQ5b6M44Gr5a6f6KGM44GV44KM44KL44KI44GG44Gr44GX44Gm44GE44KL44GM55+t44GE5aC05ZCI44Gv5Ly444Gw44GZCiAgICAgICAgY29uc3QgcmVtb3ZhbFdhaXRpbmdUaW1lID0gKHdhaXRpbmdUaW1lIHx8IDApICsgMTAwMDsKICAgICAgICBpZiAocmVtb3ZhbFRpbWVvdXRJZCkgewogICAgICAgICAgICAvLyDli5XkvZzmuIjjgb/jgr/jgqTjg57jg7zmnInjgooKICAgICAgICAgICAgaWYgKHdhaXRpbmdUaW1lKSB7CiAgICAgICAgICAgICAgICAvLyBjb25uZWN0aW9uLmRlc3Ryb3llZAogICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHJlbW92YWxUaW1lb3V0SWQpOwogICAgICAgICAgICAgICAgcmVtb3ZhbFRpbWVvdXRJZCA9IHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIHJlbW92ZU9sZFJlbW90ZURlcml2ZUtleXMoKTsKICAgICAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQocmVtb3ZhbFRpbWVvdXRJZCk7CiAgICAgICAgICAgICAgICAgICAgcmVtb3ZhbFRpbWVvdXRJZCA9IDA7CiAgICAgICAgICAgICAgICB9LCByZW1vdmFsV2FpdGluZ1RpbWUpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICAvLyDli5XkvZzmuIjjgb/jgr/jgqTjg57jg7zjgarjgZcKICAgICAgICAgICAgLy8gY29ubmVjdGlvbi5jcmVhdGVkIOOBruWgtOWQiOOCguWwkeOBl+Wun+ihjOOCkumBheOCieOBm+OCiwogICAgICAgICAgICByZW1vdmFsVGltZW91dElkID0gc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICByZW1vdmVPbGRSZW1vdGVEZXJpdmVLZXlzKCk7CiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQocmVtb3ZhbFRpbWVvdXRJZCk7CiAgICAgICAgICAgICAgICByZW1vdmFsVGltZW91dElkID0gMDsKICAgICAgICAgICAgfSwgcmVtb3ZhbFdhaXRpbmdUaW1lKTsKICAgICAgICB9CiAgICB9CiAgICBlbHNlIGlmICh0eXBlID09PSAicmVtb3RlU2VjcmV0S2V5TWF0ZXJpYWxzIikgewogICAgICAgIGNvbnN0IHsgcmVtb3RlU2VjcmV0S2V5TWF0ZXJpYWxzIH0gPSBldmVudC5kYXRhOwogICAgICAgIGZvciAoY29uc3QgW2Nvbm5lY3Rpb25JZCwgcmVtb3RlU2VjcmV0S2V5TWF0ZXJpYWxdIG9mIE9iamVjdC5lbnRyaWVzKHJlbW90ZVNlY3JldEtleU1hdGVyaWFscykpIHsKICAgICAgICAgICAgY29uc3QgeyBrZXlJZCwgc2VjcmV0S2V5TWF0ZXJpYWwgfSA9IHJlbW90ZVNlY3JldEtleU1hdGVyaWFsOwogICAgICAgICAgICBjcnlwdG8uc3VidGxlCiAgICAgICAgICAgICAgICAuaW1wb3J0S2V5KCJyYXciLCBzZWNyZXRLZXlNYXRlcmlhbC5idWZmZXIsICJIS0RGIiwgZmFsc2UsIFsiZGVyaXZlQml0cyIsICJkZXJpdmVLZXkiXSkKICAgICAgICAgICAgICAgIC50aGVuKChtYXRlcmlhbCkgPT4gewogICAgICAgICAgICAgICAgZ2VuZXJhdGVEZXJpdmVLZXkobWF0ZXJpYWwpLnRoZW4oKGRlcml2ZUtleSkgPT4gewogICAgICAgICAgICAgICAgICAgIHNldFJlbW90ZURlcml2ZUtleShjb25uZWN0aW9uSWQsIGtleUlkLCBkZXJpdmVLZXkpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBnZW5lcmF0ZVdyaXRlSVYobWF0ZXJpYWwpLnRoZW4oKHdyaXRlSVYpID0+IHsKICAgICAgICAgICAgICAgICAgICBzZXRXcml0ZUlWKGNvbm5lY3Rpb25JZCwga2V5SWQsIHdyaXRlSVYpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBzZXRMYXRlc3RSZW1vdGVLZXlJZChjb25uZWN0aW9uSWQsIGtleUlkKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfQogICAgfQogICAgZWxzZSBpZiAodHlwZSA9PT0gInJlbW92ZVJlbW90ZURlcml2ZUtleSIpIHsKICAgICAgICBjb25zdCB7IGNvbm5lY3Rpb25JZCB9ID0gZXZlbnQuZGF0YTsKICAgICAgICByZW1vdmVEZXJpdmVLZXkoY29ubmVjdGlvbklkKTsKICAgIH0KICAgIGVsc2UgaWYgKHR5cGUgPT09ICJlbmNyeXB0IikgewogICAgICAgIGNvbnN0IHsgcmVhZGFibGVTdHJlYW0sIHdyaXRhYmxlU3RyZWFtIH0gPSBldmVudC5kYXRhOwogICAgICAgIGNvbnN0IHRyYW5zZm9ybVN0cmVhbSA9IG5ldyBUcmFuc2Zvcm1TdHJlYW0oewogICAgICAgICAgICB0cmFuc2Zvcm06IGVuY3J5cHRGdW5jdGlvbiwKICAgICAgICB9KTsKICAgICAgICByZWFkYWJsZVN0cmVhbS5waXBlVGhyb3VnaCh0cmFuc2Zvcm1TdHJlYW0pLnBpcGVUbyh3cml0YWJsZVN0cmVhbSk7CiAgICB9CiAgICBlbHNlIGlmICh0eXBlID09PSAiZGVjcnlwdCIpIHsKICAgICAgICBjb25zdCB7IHJlYWRhYmxlU3RyZWFtLCB3cml0YWJsZVN0cmVhbSB9ID0gZXZlbnQuZGF0YTsKICAgICAgICBjb25zdCB0cmFuc2Zvcm1TdHJlYW0gPSBuZXcgVHJhbnNmb3JtU3RyZWFtKHsKICAgICAgICAgICAgdHJhbnNmb3JtOiBkZWNyeXB0RnVuY3Rpb24sCiAgICAgICAgfSk7CiAgICAgICAgcmVhZGFibGVTdHJlYW0ucGlwZVRocm91Z2godHJhbnNmb3JtU3RyZWFtKS5waXBlVG8od3JpdGFibGVTdHJlYW0pOwogICAgfQogICAgZWxzZSBpZiAodHlwZSA9PT0gImNsZWFyIikgewogICAgICAgIGNvdW50TWFwLmNsZWFyKCk7CiAgICAgICAgd3JpdGVJVk1hcC5jbGVhcigpOwogICAgICAgIHJlbW90ZURlcml2ZUtleU1hcC5jbGVhcigpOwogICAgICAgIGxhdGVzdFJlbW90ZUtleUlkTWFwLmNsZWFyKCk7CiAgICAgICAgc2VsZkRlcml2ZUtleU1hcC5jbGVhcigpOwogICAgfQp9Owo=");this.worker=new Worker(URL.createObjectURL(new Blob([e],{type:"application/javascript"}))),this.worker.onmessage=e=>{const{operation:t}=e.data;"disconnect"===t&&"function"==typeof this.onWorkerDisconnect&&this.onWorkerDisconnect()}}clearWorker(){this.worker&&this.worker.postMessage({type:"clear"})}terminateWorker(){this.worker&&this.worker.terminate()}async init(){const{preKeyBundle:e}=await window.e2ee.init();return e}setupSenderTransform(e){if(!e.track)return;const t=e.createEncodedStreams(),n=t.readableStream||t.readable,i=t.writableStream||t.writable;if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");const s={type:"encrypt",readableStream:n,writableStream:i};this.worker.postMessage(s,[n,i])}setupReceiverTransform(e){const t=e.createEncodedStreams(),n=t.readableStream||t.readable,i=t.writableStream||t.writable;if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");const s={type:"decrypt",readableStream:n,writableStream:i};this.worker.postMessage(s,[n,i])}postRemoteSecretKeyMaterials(e){if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");this.worker.postMessage({type:"remoteSecretKeyMaterials",remoteSecretKeyMaterials:e.remoteSecretKeyMaterials})}postRemoveRemoteDeriveKey(e){if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");this.worker.postMessage({type:"removeRemoteDeriveKey",connectionId:e})}postSelfSecretKeyMaterial(e,t,n,i=0){if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");this.worker.postMessage({type:"selfSecretKeyMaterial",selfConnectionId:e,selfKeyId:t,selfSecretKeyMaterial:n,waitingTime:i})}startSession(e,t){const[n,i]=window.e2ee.startSession(e,t.identityKey,t.signedPreKey,t.preKeySignature);if(i)throw i;return n}stopSession(e){const[t,n]=window.e2ee.stopSession(e);if(n)throw n;return t}receiveMessage(e){const[t,n]=window.e2ee.receiveMessage(e);if(n)throw n;return t}start(e){const[t,n]=window.e2ee.start(e);if(n)throw n;return t}addPreKeyBundle(e,t){const n=window.e2ee.addPreKeyBundle(e,t.identityKey,t.signedPreKey,t.preKeySignature);if(n)throw n}selfFingerprint(){return window.e2ee.selfFingerprint()}remoteFingerprints(){return window.e2ee.remoteFingerprints()}static async loadWasm(e){if(void 0===!window.e2ee)return void console.warn("E2ee wasm is already loaded. Will not be reload.");if((()=>{if("undefined"!=typeof global);else if("undefined"!=typeof window)window.global=window;else{if("undefined"==typeof self)throw new Error("cannot export Go (neither global, window nor self is defined)");self.global=self}if(global.require||"undefined"==typeof require||(global.require=require),!global.fs&&global.require){const e=require("fs");0!==Object.keys(e)&&(global.fs=e)}const e=()=>{const e=new Error("not implemented");return e.code="ENOSYS",e};if(!global.fs){let t="";global.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(e,i){t+=n.decode(i);const s=t.lastIndexOf("\n");return-1!=s&&(console.log(t.substr(0,s)),t=t.substr(s+1)),i.length},write(t,n,i,s,a,o){0===i&&s===n.length&&null===a?o(null,this.writeSync(t,n)):o(e())},chmod(t,n,i){i(e())},chown(t,n,i,s){s(e())},close(t,n){n(e())},fchmod(t,n,i){i(e())},fchown(t,n,i,s){s(e())},fstat(t,n){n(e())},fsync(e,t){t(null)},ftruncate(t,n,i){i(e())},lchown(t,n,i,s){s(e())},link(t,n,i){i(e())},lstat(t,n){n(e())},mkdir(t,n,i){i(e())},open(t,n,i,s){s(e())},read(t,n,i,s,a,o){o(e())},readdir(t,n){n(e())},readlink(t,n){n(e())},rename(t,n,i){i(e())},rmdir(t,n){n(e())},stat(t,n){n(e())},symlink(t,n,i){i(e())},truncate(t,n,i){i(e())},unlink(t,n){n(e())},utimes(t,n,i,s){s(e())}}}if(global.process||(global.process={getuid:()=>-1,getgid:()=>-1,geteuid:()=>-1,getegid:()=>-1,getgroups(){throw e()},pid:-1,ppid:-1,umask(){throw e()},cwd(){throw e()},chdir(){throw e()}}),!global.crypto){const e=require("crypto");global.crypto={getRandomValues(t){e.randomFillSync(t)}}}global.performance||(global.performance={now(){const[e,t]=process.hrtime();return 1e3*e+t/1e6}}),global.TextEncoder||(global.TextEncoder=require("util").TextEncoder),global.TextDecoder||(global.TextDecoder=require("util").TextDecoder);const t=new TextEncoder("utf-8"),n=new TextDecoder("utf-8");if(global.Go=class{constructor(){this.argv=["js"],this.env={},this.exit=e=>{0!==e&&console.warn("exit code:",e)},this._exitPromise=new Promise((e=>{this._resolveExitPromise=e})),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;const e=(e,t)=>{this.mem.setUint32(e+0,t,!0),this.mem.setUint32(e+4,Math.floor(t/4294967296),!0)},i=e=>this.mem.getUint32(e+0,!0)+4294967296*this.mem.getInt32(e+4,!0),s=e=>{const t=this.mem.getFloat64(e,!0);if(0===t)return;if(!isNaN(t))return t;const n=this.mem.getUint32(e,!0);return this._values[n]},a=(e,t)=>{const n=2146959360;if("number"==typeof t&&0!==t)return isNaN(t)?(this.mem.setUint32(e+4,n,!0),void this.mem.setUint32(e,0,!0)):void this.mem.setFloat64(e,t,!0);if(void 0===t)return void this.mem.setFloat64(e,0,!0);let i=this._ids.get(t);void 0===i&&(i=this._idPool.pop(),void 0===i&&(i=this._values.length),this._values[i]=t,this._goRefCounts[i]=0,this._ids.set(t,i)),this._goRefCounts[i]++;let s=0;switch(typeof t){case"object":null!==t&&(s=1);break;case"string":s=2;break;case"symbol":s=3;break;case"function":s=4}this.mem.setUint32(e+4,n|s,!0),this.mem.setUint32(e,i,!0)},o=e=>{const t=i(e+0),n=i(e+8);return new Uint8Array(this._inst.exports.mem.buffer,t,n)},g=e=>{const t=i(e+0),n=i(e+8),a=new Array(n);for(let e=0;e{const t=i(e+0),s=i(e+8);return n.decode(new DataView(this._inst.exports.mem.buffer,t,s))},c=Date.now()-performance.now();this.importObject={go:{"runtime.wasmExit":e=>{const t=this.mem.getInt32(e+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(t)},"runtime.wasmWrite":e=>{const t=i(e+8),n=i(e+16),s=this.mem.getInt32(e+24,!0);fs.writeSync(t,new Uint8Array(this._inst.exports.mem.buffer,n,s))},"runtime.resetMemoryDataView":e=>{this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{e(t+8,1e6*(c+performance.now()))},"runtime.walltime1":t=>{const n=(new Date).getTime();e(t+8,n/1e3),this.mem.setInt32(t+16,n%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":e=>{const t=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(t,setTimeout((()=>{for(this._resume();this._scheduledTimeouts.has(t);)console.warn("scheduleTimeoutEvent: missed timeout event"),this._resume()}),i(e+8)+1)),this.mem.setInt32(e+16,t,!0)},"runtime.clearTimeoutEvent":e=>{const t=this.mem.getInt32(e+8,!0);clearTimeout(this._scheduledTimeouts.get(t)),this._scheduledTimeouts.delete(t)},"runtime.getRandomData":e=>{crypto.getRandomValues(o(e+8))},"syscall/js.finalizeRef":e=>{const t=this.mem.getUint32(e+8,!0);if(this._goRefCounts[t]--,0===this._goRefCounts[t]){const e=this._values[t];this._values[t]=null,this._ids.delete(e),this._idPool.push(t)}},"syscall/js.stringVal":e=>{a(e+24,l(e+8))},"syscall/js.valueGet":e=>{const t=Reflect.get(s(e+8),l(e+16));e=this._inst.exports.getsp(),a(e+32,t)},"syscall/js.valueSet":e=>{Reflect.set(s(e+8),l(e+16),s(e+32))},"syscall/js.valueDelete":e=>{Reflect.deleteProperty(s(e+8),l(e+16))},"syscall/js.valueIndex":e=>{a(e+24,Reflect.get(s(e+8),i(e+16)))},"syscall/js.valueSetIndex":e=>{Reflect.set(s(e+8),i(e+16),s(e+24))},"syscall/js.valueCall":e=>{try{const t=s(e+8),n=Reflect.get(t,l(e+16)),i=g(e+32),o=Reflect.apply(n,t,i);e=this._inst.exports.getsp(),a(e+56,o),this.mem.setUint8(e+64,1)}catch(t){a(e+56,t),this.mem.setUint8(e+64,0)}},"syscall/js.valueInvoke":e=>{try{const t=s(e+8),n=g(e+16),i=Reflect.apply(t,void 0,n);e=this._inst.exports.getsp(),a(e+40,i),this.mem.setUint8(e+48,1)}catch(t){a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueNew":e=>{try{const t=s(e+8),n=g(e+16),i=Reflect.construct(t,n);e=this._inst.exports.getsp(),a(e+40,i),this.mem.setUint8(e+48,1)}catch(t){a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueLength":t=>{e(t+16,parseInt(s(t+8).length))},"syscall/js.valuePrepareString":n=>{const i=t.encode(String(s(n+8)));a(n+16,i),e(n+24,i.length)},"syscall/js.valueLoadString":e=>{const t=s(e+8);o(e+16).set(t)},"syscall/js.valueInstanceOf":e=>{this.mem.setUint8(e+24,s(e+8)instanceof s(e+16)?1:0)},"syscall/js.copyBytesToGo":t=>{const n=o(t+8),i=s(t+32);if(!(i instanceof Uint8Array||i instanceof Uint8ClampedArray))return void this.mem.setUint8(t+48,0);const a=i.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{const n=s(t+8),i=o(t+16);if(!(n instanceof Uint8Array||n instanceof Uint8ClampedArray))return void this.mem.setUint8(t+48,0);const a=i.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},debug:e=>{console.log(e)}}}}async run(e){this._inst=e,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,global,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[global,5],[this,6]]),this._idPool=[],this.exited=!1;let n=4096;const i=e=>{const i=n,s=t.encode(e+"\0");return new Uint8Array(this.mem.buffer,n,s.length).set(s),n+=s.length,n%8!=0&&(n+=8-n%8),i},s=this.argv.length,a=[];this.argv.forEach((e=>{a.push(i(e))})),a.push(0),Object.keys(this.env).sort().forEach((e=>{a.push(i(`${e}=${this.env[e]}`))})),a.push(0);const o=n;a.forEach((e=>{this.mem.setUint32(n,e,!0),this.mem.setUint32(n+4,0,!0),n+=8})),this._inst.exports.run(s,o),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw new Error("Go program has already exited");this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(e){const t=this;return function(){const n={id:e,this:this,args:arguments};return t._pendingEvent=n,t._resume(),n.result}}},global.require&&global.require.main===module&&global.process&&global.process.versions&&!global.process.versions.electron){process.argv.length<3&&(console.error("usage: go_js_wasm_exec [wasm binary] [arguments]"),process.exit(1));const e=new Go;e.argv=process.argv.slice(2),e.env=Object.assign({TMPDIR:require("os").tmpdir()},process.env),e.exit=process.exit,WebAssembly.instantiate(fs.readFileSync(process.argv[2]),e.importObject).then((t=>(process.on("exit",(t=>{0!==t||e.exited||(e._pendingEvent={id:0},e._resume())})),e.run(t.instance)))).catch((e=>{console.error(e),process.exit(1)}))}})(),!window.Go)throw new Error(`Failed to load module Go. window.Go is ${window.Go}.`);const t=new Go,{instance:n}=await WebAssembly.instantiateStreaming(fetch(e),t.importObject);if(t.run(n),!window.e2ee)throw new Error(`Failed to load module e2ee. window.e2ee is ${window.e2ee}.`)}static version(){return"2021.1.0"}static wasmVersion(){return window.e2ee.version()}}var t=Uint8Array,n=Uint16Array,i=Uint32Array,s=new t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),a=new t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),o=new t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),g=function(e,t){for(var s=new n(31),a=0;a<31;++a)s[a]=t+=1<>>1|(21845&m)<<1;u=(61680&(u=(52428&u)>>>2|(13107&u)<<2))>>>4|(3855&u)<<4,I[m]=((65280&u)>>>8|(255&u)<<8)>>>1}var A=function(e,t,i){for(var s=e.length,a=0,o=new n(t);a>>c]=r}else for(g=new n(s),a=0;a>>15-e[a]);return g},b=new t(288);for(m=0;m<144;++m)b[m]=8;for(m=144;m<256;++m)b[m]=9;for(m=256;m<280;++m)b[m]=7;for(m=280;m<288;++m)b[m]=8;var p=new t(32);for(m=0;m<32;++m)p[m]=5;var Z=A(b,9,0),w=A(b,9,1),S=A(p,5,0),V=A(p,5,1),f=function(e){for(var t=e[0],n=1;nt&&(t=e[n]);return t},y=function(e,t,n){var i=t/8|0;return(e[i]|e[i+1]<<8)>>(7&t)&n},W=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},G=function(e){return(e+7)/8|0},k=function(e,s,a){(null==s||s<0)&&(s=0),(null==a||a>e.length)&&(a=e.length);var o=new(e instanceof n?n:e instanceof i?i:t)(a-s);return o.set(e.subarray(s,a)),o},R=["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"],v=function(e,t,n){var i=new Error(t||R[e]);if(i.code=e,Error.captureStackTrace&&Error.captureStackTrace(i,v),!n)throw i;return i},T=function(e,t,n){n<<=7&t;var i=t/8|0;e[i]|=n,e[i+1]|=n>>>8},X=function(e,t,n){n<<=7&t;var i=t/8|0;e[i]|=n,e[i+1]|=n>>>8,e[i+2]|=n>>>16},O=function(e,i){for(var s=[],a=0;aI&&(I=g[a].s);var m=new n(I+1),u=E(s[d-1],m,0);if(u>i){a=0;var A=0,b=u-i,p=1<i))break;A+=p-(1<>>=b;A>0;){var w=g[a].s;m[w]=0&&A;--a){var S=g[a].s;m[S]==i&&(--m[S],++A)}u=i}return[new t(m),u]},E=function(e,t,n){return-1==e.s?Math.max(E(e.l,t,n+1),E(e.r,t,n+1)):t[e.s]=n},N=function(e){for(var t=e.length;t&&!e[--t];);for(var i=new n(++t),s=0,a=e[0],o=1,g=function(e){i[s++]=e},l=1;l<=t;++l)if(e[l]==a&&l!=t)++o;else{if(!a&&o>2){for(;o>138;o-=138)g(32754);o>2&&(g(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(g(a),--o;o>6;o-=6)g(8304);o>2&&(g(o-3<<5|8208),o=0)}for(;o--;)g(a);o=1,a=e[l]}return[i.subarray(0,s),t]},B=function(e,t){for(var n=0,i=0;i>>8,e[s+2]=255^e[s],e[s+3]=255^e[s+1];for(var a=0;a4&&!D[o[U-1]];--U);var M,j,Q,H,x=h+5<<3,P=B(l,b)+B(c,p)+r,z=B(l,u)+B(c,f)+r+14+3*U+B(K,D)+(2*K[16]+3*K[17]+7*K[18]);if(x<=P&&x<=z)return Y(t,I,e.subarray(d,d+h));if(T(t,I,1+(z15&&(T(t,I,ee[L]>>>5&127),I+=ee[L]>>>12)}}}else M=Z,j=b,Q=S,H=p;for(L=0;L255){te=g[L]>>>18&31;X(t,I,M[te+257]),I+=j[te+257],te>7&&(T(t,I,g[L]>>>23&31),I+=s[te]);var ne=31&g[L];X(t,I,Q[ne]),I+=H[ne],ne>3&&(X(t,I,g[L]>>>5&8191),I+=a[ne])}else X(t,I,M[g[L]]),I+=j[g[L]];return X(t,I,M[256]),I+j[256]},L=new i([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),J=new t(0),D=function(e,o,g,l,c){return function(e,o,g,l,c,C){var d=e.length,I=new t(l+d+5*(1+Math.ceil(d/7e3))+c),m=I.subarray(l,I.length-c),u=0;if(!o||d<8)for(var A=0;A<=d;A+=65535){var b=A+65535;b>>13,w=8191&p,S=(1<7e3||N>24576)&&j>423){u=K(e,m,0,v,T,X,E,N,D,A-D,u),N=O=E=0,D=A;for(var Q=0;Q<286;++Q)T[Q]=0;for(Q=0;Q<30;++Q)X[Q]=0}var H=2,x=0,P=w,z=U-M&32767;if(j>2&&F==R(A-z))for(var _=Math.min(Z,j)-1,q=Math.min(32767,A),$=Math.min(258,j);z<=q&&--P&&U!=M;){if(e[A+H]==e[A+H-z]){for(var ee=0;ee<$&&e[A+ee]==e[A+ee-z];++ee);if(ee>H){if(H=ee,x=z,ee>_)break;var te=Math.min(z,ee-2),ne=0;for(Q=0;Qne&&(ne=se,M=ie)}}}z+=(U=M)-(M=V[U])+32768&32767}if(x){v[N++]=268435456|r[H]<<18|h[x];var ae=31&r[H],oe=31&h[x];E+=s[ae]+a[oe],++T[257+ae],++X[oe],B=A+H,++O}else v[N++]=e[A],++T[e[A]]}}u=K(e,m,C,v,T,X,E,N,D,A-D,u),!C&&7&u&&(u=Y(m,u+1,J))}return k(I,0,l+G(u)+c)}(e,null==o.level?6:o.level,null==o.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):12+o.mem,g,l,!c)};function F(e,t){t||(t={});var n=function(){var e=1,t=0;return{p:function(n){for(var i=e,s=t,a=0|n.length,o=0;o!=a;){for(var g=Math.min(o+2655,a);o>16),s=(65535&s)+15*(s>>16)}e=i,t=s},d:function(){return(255&(e%=65521))<<24|e>>>8<<16|(255&(t%=65521))<<8|t>>>8}}}();n.p(e);var i=D(e,t,2,4);return function(e,t){var n=t.level,i=0==n?0:n<6?1:9==n?3:2;e[0]=120,e[1]=i<<6|(i?32-2*i:1)}(i,t),function(e,t,n){for(;n;++t)e[t]=n,n>>>=8}(i,i.length-4,n.d()),i}function U(e,n){return function(e,n,i){var g=e.length;if(!g||i&&i.f&&!i.l)return n||new t(0);var l=!n||i,r=!i||i.i;i||(i={}),n||(n=new t(3*g));var C=function(e){var i=n.length;if(e>i){var s=new t(Math.max(2*i,e));s.set(n),n=s}},h=i.f||0,I=i.p||0,m=i.b||0,u=i.l,b=i.d,p=i.m,Z=i.n,S=8*g;do{if(!u){h=y(e,I,1);var R=y(e,I+1,3);if(I+=3,!R){var T=e[(F=G(I)+4)-4]|e[F-3]<<8,X=F+T;if(X>g){r&&v(0);break}l&&C(m+T),n.set(e.subarray(F,X),m),i.b=m+=T,i.p=I=8*X,i.f=h;continue}if(1==R)u=w,b=V,p=9,Z=5;else if(2==R){var O=y(e,I,31)+257,E=y(e,I+10,15)+4,N=O+y(e,I+5,31)+1;I+=14;for(var B=new t(N),Y=new t(19),K=0;K>>4)<16)B[K++]=F;else{var M=0,j=0;for(16==F?(j=3+y(e,I,3),I+=2,M=B[K-1]):17==F?(j=3+y(e,I,7),I+=3):18==F&&(j=11+y(e,I,127),I+=7);j--;)B[K++]=M}}var Q=B.subarray(0,O),H=B.subarray(O);p=f(Q),Z=f(H),u=A(Q,p,1),b=A(H,Z,1)}else v(1);if(I>S){r&&v(0);break}}l&&C(m+131072);for(var x=(1<>>4;if((I+=15&M)>S){r&&v(0);break}if(M||v(2),_<256)n[m++]=_;else{if(256==_){z=I,u=null;break}var q=_-254;if(_>264){var $=s[K=_-257];q=y(e,I,(1<<$)-1)+c[K],I+=$}var ee=b[W(e,I)&P],te=ee>>>4;if(ee||v(3),I+=15&ee,H=d[te],te>3&&($=a[te],H+=W(e,I)&(1<<$)-1,I+=$),I>S){r&&v(0);break}l&&C(m+131072);for(var ne=m+q;m>>4>7||(i[0]<<8|i[1])%31)&&v(6,"invalid zlib data"),32&i[1]&&v(6,"invalid zlib data: preset dictionaries not supported"),e.subarray(2,-4)),n);var i}var M="undefined"!=typeof TextDecoder&&new TextDecoder;try{M.decode(J,{stream:!0}),1}catch(e){}function j(e){if("object"!=typeof e||null===e)throw new Error("Failed to parse options dataChannels. Options dataChannels element must be type 'object'");const t=e,n={};return"string"==typeof t.label&&(n.label=t.label),"string"==typeof t.direction&&(n.direction=t.direction),"boolean"==typeof t.ordered&&(n.ordered=t.ordered),"boolean"==typeof t.compress&&(n.compress=t.compress),"number"==typeof t.maxPacketLifeTime&&(n.max_packet_life_time=t.maxPacketLifeTime),"number"==typeof t.maxRetransmits&&(n.max_retransmits=t.maxRetransmits),"string"==typeof t.protocol&&(n.protocol=t.protocol),n}function Q(){return"safari"===function(){const e=window.navigator.userAgent.toLocaleLowerCase();return-1!==e.indexOf("edge")?"edge":-1!==e.indexOf("chrome")&&-1===e.indexOf("edge")?"chrome":-1!==e.indexOf("safari")&&-1===e.indexOf("chrome")?"safari":-1!==e.indexOf("opera")?"opera":-1!==e.indexOf("firefox")?"firefox":null}()}function H(e,t,n,i,s,a){if("sendrecv"!==t&&"sendonly"!==t&&"recvonly"!==t)throw new Error("Unknown role type");if(null==n)throw new Error("channelId can not be null or undefined");const o={type:"connect",sora_client:"Sora JavaScript SDK 2021.2.1",environment:window.navigator.userAgent,role:t,channel_id:n,sdp:e,audio:!0,video:!0};if(void 0!==i&&(o.metadata=i),a&&(o.redirect=!0),"signalingNotifyMetadata"in s&&(o.signaling_notify_metadata=s.signalingNotifyMetadata),"multistream"in s&&!0===s.multistream&&(o.multistream=!0,"spotlight"in s&&(o.spotlight=s.spotlight,"spotlightNumber"in s&&(o.spotlight_number=s.spotlightNumber)),!0===o.spotlight)){const e=["none","r0","r1","r2"];void 0!==s.spotlightFocusRid&&0<=e.indexOf(s.spotlightFocusRid)&&(o.spotlight_focus_rid=s.spotlightFocusRid),void 0!==s.spotlightUnfocusRid&&0<=e.indexOf(s.spotlightUnfocusRid)&&(o.spotlight_unfocus_rid=s.spotlightUnfocusRid)}if("simulcast"in s||"simulcastRid"in s){"simulcast"in s&&!0===s.simulcast&&(o.simulcast=!0);const e=["r0","r1","r2"];void 0!==s.simulcastRid&&0<=e.indexOf(s.simulcastRid)&&(o.simulcast_rid=s.simulcastRid)}"clientId"in s&&void 0!==s.clientId&&(o.client_id=s.clientId),"dataChannelSignaling"in s&&"boolean"==typeof s.dataChannelSignaling&&(o.data_channel_signaling=s.dataChannelSignaling),"ignoreDisconnectWebSocket"in s&&"boolean"==typeof s.ignoreDisconnectWebSocket&&(o.ignore_disconnect_websocket=s.ignoreDisconnectWebSocket);const g=["audioCodecType","audioBitRate"],l=["audioOpusParamsChannels","audioOpusParamsClockRate","audioOpusParamsMaxplaybackrate","audioOpusParamsStereo","audioOpusParamsSpropStereo","audioOpusParamsMinptime","audioOpusParamsPtime","audioOpusParamsUseinbandfec","audioOpusParamsUsedtx"],c=["videoCodecType","videoBitRate"],r=Object.assign({},s);Object.keys(r).forEach((e=>{"audio"===e&&"boolean"==typeof r[e]||"video"===e&&"boolean"==typeof r[e]||0<=g.indexOf(e)&&null!==r[e]||0<=l.indexOf(e)&&null!==r[e]||0<=c.indexOf(e)&&null!==r[e]||delete r[e]})),void 0!==r.audio&&(o.audio=r.audio);const C=Object.keys(r).some((e=>0<=g.indexOf(e)));o.audio&&C&&(o.audio={},"audioCodecType"in r&&(o.audio.codec_type=r.audioCodecType),"audioBitRate"in r&&(o.audio.bit_rate=r.audioBitRate));const d=Object.keys(r).some((e=>0<=l.indexOf(e)));o.audio&&d&&("object"!=typeof o.audio&&(o.audio={}),o.audio.opus_params={},"audioOpusParamsChannels"in r&&(o.audio.opus_params.channels=r.audioOpusParamsChannels),"audioOpusParamsClockRate"in r&&(o.audio.opus_params.clock_rate=r.audioOpusParamsClockRate),"audioOpusParamsMaxplaybackrate"in r&&(o.audio.opus_params.maxplaybackrate=r.audioOpusParamsMaxplaybackrate),"audioOpusParamsStereo"in r&&(o.audio.opus_params.stereo=r.audioOpusParamsStereo),"audioOpusParamsSpropStereo"in r&&(o.audio.opus_params.sprop_stereo=r.audioOpusParamsSpropStereo),"audioOpusParamsMinptime"in r&&(o.audio.opus_params.minptime=r.audioOpusParamsMinptime),"audioOpusParamsPtime"in r&&(o.audio.opus_params.ptime=r.audioOpusParamsPtime),"audioOpusParamsUseinbandfec"in r&&(o.audio.opus_params.useinbandfec=r.audioOpusParamsUseinbandfec),"audioOpusParamsUsedtx"in r&&(o.audio.opus_params.usedtx=r.audioOpusParamsUsedtx)),void 0!==r.video&&(o.video=r.video);const h=Object.keys(r).some((e=>0<=c.indexOf(e)));if(o.video&&h&&(o.video={},"videoCodecType"in r&&(o.video.codec_type=r.videoCodecType),"videoBitRate"in r&&(o.video.bit_rate=r.videoBitRate)),o.simulcast&&!function(){if(!window.RTCRtpSender)return!1;if(!RTCRtpSender.getCapabilities)return!1;const e=RTCRtpSender.getCapabilities("video");if(!e)return!1;const t=e.headerExtensions.map((e=>e.uri));return["urn:ietf:params:rtp-hdrext:sdes:mid","urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"].every((e=>t.includes(e)))}()&&"recvonly"!==t)throw new Error("Simulcast can not be used with this browser");if(!0===s.e2ee){if(void 0===o.signaling_notify_metadata&&(o.signaling_notify_metadata={}),null===o.signaling_notify_metadata||"object"!=typeof o.signaling_notify_metadata)throw new Error("E2EE failed. Options signalingNotifyMetadata must be type 'object'");!0===o.video&&(o.video={}),o.video&&(o.video.codec_type="VP8"),o.e2ee=!0}return Array.isArray(s.dataChannels)&&0{},push:()=>{},addstream:()=>{},track:()=>{},removestream:()=>{},removetrack:()=>{},notify:()=>{},log:()=>{},timeout:()=>{},timeline:()=>{},signaling:()=>{},message:()=>{},datachannel:()=>{}},this.authMetadata=null,this.e2ee=null,this.connectionTimeoutTimerId=0,this.monitorSignalingWebSocketEventTimerId=0,this.monitorIceConnectionStateChangeTimerId=0,this.soraDataChannels={},this.mids={audio:"",video:""},this.signalingSwitched=!1,this.signalingOfferMessageDataChannels={}}on(e,t){"addstream"===e?console.warn("@deprecated addstream callback will be removed in a future version. Use track callback."):"removestream"===e&&console.warn("@deprecated removestream callback will be removed in a future version. Use removetrack callback."),e in this.callbacks&&(this.callbacks[e]=t)}stopAudioTrack(e){for(const t of e.getAudioTracks())t.enabled=!1;return new Promise((t=>{setTimeout((async()=>{for(const t of e.getAudioTracks())if(t.stop(),e.removeTrack(t),null!==this.pc){const e=this.pc.getSenders().find((e=>e.track&&e.track.id===t.id));e&&await e.replaceTrack(null)}t()}),100)}))}stopVideoTrack(e){for(const t of e.getVideoTracks())t.enabled=!1;return new Promise((t=>{setTimeout((async()=>{for(const t of e.getVideoTracks())if(t.stop(),e.removeTrack(t),null!==this.pc){const e=this.pc.getSenders().find((e=>e.track&&e.track.id===t.id));e&&await e.replaceTrack(null)}t()}),100)}))}async replaceAudioTrack(e,t){await this.stopAudioTrack(e);const n=this.getAudioTransceiver();if(null===n)throw new Error("Unable to set an audio track. Audio track sender is undefined");e.addTrack(t),await n.sender.replaceTrack(t)}async replaceVideoTrack(e,t){await this.stopVideoTrack(e);const n=this.getVideoTransceiver();if(null===n)throw new Error("Unable to set video track. Video track sender is undefined");e.addTrack(t),await n.sender.replaceTrack(t)}stopStream(){return new Promise(((e,t)=>(this.debug&&console.warn("@deprecated closing MediaStream in disconnect will be removed in a future version. Close every track in the MediaStream by yourself."),this.stream?(this.stream.getTracks().forEach((e=>{e.stop()})),this.stream=null,e()):e())))}async signalingTerminate(){await this.stopStream();for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&t.close(),delete this.soraDataChannels[e]}this.ws&&(this.ws.close(),this.ws=null),this.pc&&this.pc.close(),this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection()}async abendPeerConnectionState(e){this.clearMonitorIceConnectionStateChange(),await this.stopStream(),this.pc&&(this.pc.ondatachannel=null,this.pc.oniceconnectionstatechange=null,this.pc.onicegatheringstatechange=null,this.pc.onconnectionstatechange=null),this.ws&&(this.ws.onclose=e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason})},this.ws.onmessage=null,this.ws.onerror=null);for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onclose=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label)},t.onmessage=null,t.onerror=null)}for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&t.close(),delete this.soraDataChannels[e]}this.ws&&(this.ws.close(),this.ws=null),this.pc&&this.pc.close(),this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection();const t=this.soraCloseEvent("abend",e);this.callbacks.disconnect(t),this.writeSoraTimelineLog("disconnect-abend",t)}async abend(e,t){this.clearMonitorIceConnectionStateChange(),await this.stopStream(),this.pc&&(this.pc.ondatachannel=null,this.pc.oniceconnectionstatechange=null,this.pc.onicegatheringstatechange=null,this.pc.onconnectionstatechange=null),this.ws&&(this.ws.onclose=e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason})},this.ws.onmessage=null,this.ws.onerror=null);for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onclose=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label)},t.onmessage=null,t.onerror=null)}if(this.soraDataChannels.signaling){const t={type:"disconnect",reason:e};if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const e=F((new TextEncoder).encode(JSON.stringify(t)),{});if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(e),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,t)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}else if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(JSON.stringify(t)),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,t)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onerror=null,t.close()),delete this.soraDataChannels[e]}if(await this.disconnectWebSocket(e),await this.disconnectPeerConnection(),this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection(),"WEBSOCKET-ONCLOSE"===e&&t&&(1e3===t.code||1005===t.code)){const e=this.soraCloseEvent("normal","DISCONNECT",t);return this.writeSoraTimelineLog("disconnect-normal",e),void this.callbacks.disconnect(e)}const n=this.soraCloseEvent("abend",e,t);this.writeSoraTimelineLog("disconnect-abend",n),this.callbacks.disconnect(this.soraCloseEvent("abend",e,t))}initializeConnection(){this.clientId=null,this.connectionId=null,this.remoteConnectionIds=[],this.stream=null,this.ws=null,this.pc=null,this.encodings=[],this.authMetadata=null,this.e2ee=null,this.soraDataChannels={},this.mids={audio:"",video:""},this.signalingSwitched=!1,this.signalingOfferMessageDataChannels={},this.clearConnectionTimeout()}disconnectWebSocket(e){let t=0;return this.signalingSwitched?(this.ws&&(this.ws.close(),this.ws=null),Promise.resolve(null)):new Promise(((n,i)=>{if(!this.ws)return n(null);if(this.ws.onclose=e=>(this.ws&&(this.ws.close(),this.ws=null),clearTimeout(t),this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason}),n({code:e.code,reason:e.reason})),1!==this.ws.readyState)return this.ws.close(),this.ws=null,n(null);{const i={type:"disconnect",reason:e};this.ws.send(JSON.stringify(i)),this.writeWebSocketSignalingLog("send-disconnect",i),t=setTimeout((()=>{this.ws&&(this.ws.close(),this.ws=null),n({code:1006,reason:""})}),this.disconnectWaitTimeout)}}))}disconnectDataChannel(){const e=()=>{for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onerror=null,t.close()),delete this.soraDataChannels[e]}};return new Promise(((t,n)=>{if(!this.soraDataChannels.signaling)return e(),t({code:4999,reason:""});const i=setTimeout((()=>(e(),n())),this.disconnectWaitTimeout),s=[];for(const n of Object.keys(this.soraDataChannels)){const a=this.soraDataChannels[n];if(a){a.onerror=()=>(clearTimeout(i),e(),t({code:4999,reason:""}));const n=()=>new Promise(((e,t)=>{let n=0;const i=setInterval((()=>{n++,"closed"===a.readyState&&(clearInterval(i),e()),this.disconnectWaitTimeout<100*n&&(e(),clearInterval(i))}),100)}));s.push(n())}}Promise.all(s).then((()=>{0===Object.keys(this.soraDataChannels).length?t(null):t({code:4999,reason:""})})).finally((()=>{e(),clearTimeout(i)}));const a={type:"disconnect",reason:"NO-ERROR"};if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const e=F((new TextEncoder).encode(JSON.stringify(a)),{});if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(e),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,a)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}else if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(JSON.stringify(a)),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,a)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}))}disconnectPeerConnection(){return new Promise(((e,t)=>(this.pc&&"closed"!==this.pc.connectionState&&this.pc.close(),e())))}async disconnect(){this.clearMonitorIceConnectionStateChange(),await this.stopStream(),this.pc&&(this.pc.ondatachannel=null,this.pc.oniceconnectionstatechange=null,this.pc.onicegatheringstatechange=null,this.pc.onconnectionstatechange=null),this.ws&&(this.ws.onclose=e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason})},this.ws.onmessage=null,this.ws.onerror=null);for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onmessage=null,t.onclose=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label)})}let e=null;if(this.signalingSwitched){try{const t=await this.disconnectDataChannel();null!==t&&(e=this.soraCloseEvent("normal","DISCONNECT",t))}catch(t){e=this.soraCloseEvent("abend","DISCONNECT-TIMEOUT")}await this.disconnectWebSocket("NO-ERROR"),await this.disconnectPeerConnection()}else{const t=await this.disconnectWebSocket("NO-ERROR");await this.disconnectPeerConnection(),null!==t&&(e=this.soraCloseEvent("normal","DISCONNECT",t))}this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection(),e&&("abend"===e.type?this.writeSoraTimelineLog("disconnect-abend",e):"normal"===e.type&&this.writeSoraTimelineLog("disconnect-normal",e),this.callbacks.disconnect(e))}setupE2EE(){!0===this.options.e2ee&&(this.e2ee=new e,this.e2ee.onWorkerDisconnect=async()=>{await this.abend("INTERNAL-ERROR",{reason:"CRASH-E2EE-WORKER"})},this.e2ee.startWorker())}startE2EE(){if(!0===this.options.e2ee&&this.e2ee){if(!this.connectionId){const e=new Error;throw e.message="E2EE failed. Self connectionId is null",e}this.e2ee.clearWorker();const e=this.e2ee.start(this.connectionId);this.e2ee.postSelfSecretKeyMaterial(this.connectionId,e.selfKeyId,e.selfSecretKeyMaterial)}}async getSignalingWebSocket(e){if("string"==typeof e){const t=e;return new Promise(((e,n)=>{const i=new WebSocket(t);i.onclose=e=>{const t=new z(`Signaling failed. CloseEventCode:${e.code} CloseEventReason:'${e.reason}'`);t.code=e.code,t.reason=e.reason,this.writeWebSocketTimelineLog("onclose",t),n(t)},i.onopen=t=>{e(i)}}))}if(Array.isArray(e)){let t=!1;const n=e=>new Promise(((n,i)=>{const s=new WebSocket(e),a=setTimeout((()=>{this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"timeout",url:s.url}),s&&!t&&(s.onclose=null,s.onerror=null,s.onopen=null,s.close(),i())}),this.signalingCandidateTimeout);s.onclose=e=>{this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"close",url:s.url,message:"WebSocket closed",code:e.code,reason:e.reason}),s&&s.close(),clearInterval(a),i()},s.onerror=e=>{this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"error",url:s.url,message:"Failed to connect WebSocket"}),s&&(s.onclose=null,s.close()),clearInterval(a),i()},s.onopen=e=>{s&&(clearInterval(a),t?(this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"open",url:s.url,selected:!1}),s.onerror=null,s.onclose=null,s.onopen=null,s.close(),i()):(this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"open",url:s.url,selected:!0}),s.onerror=null,s.onclose=null,s.onopen=null,t=!0,n(s)))}}));try{return await Promise.any(e.map((e=>n(e))))}catch(e){throw new z("Signaling failed. All signaling URL candidates failed to connect")}}throw new z("Signaling failed. Invalid format signaling URL candidates")}async signaling(e,t=!1){const n=await this.createOffer();return this.trace("CREATE OFFER",n),new Promise(((i,s)=>{this.writeWebSocketSignalingLog("new-websocket",e.url),e.binaryType="arraybuffer",e.onclose=async e=>{const t=new z(`Signaling failed. CloseEventCode:${e.code} CloseEventReason:'${e.reason}'`);t.code=e.code,t.reason=e.reason,this.writeWebSocketTimelineLog("onclose",t),await this.signalingTerminate(),s(t)},e.onmessage=async e=>{if(e.data instanceof ArrayBuffer)return this.writeWebSocketSignalingLog("onmessage-e2ee",e.data),void this.signalingOnMessageE2EE(e.data);const t=JSON.parse(e.data);if("offer"==t.type)this.writeWebSocketSignalingLog("onmessage-offer",t),this.signalingOnMessageTypeOffer(t),i(t);else if("update"==t.type)this.writeWebSocketSignalingLog("onmessage-update",t),await this.signalingOnMessageTypeUpdate(t);else if("re-offer"==t.type)this.writeWebSocketSignalingLog("onmessage-re-offer",t),await this.signalingOnMessageTypeReOffer(t);else if("ping"==t.type)await this.signalingOnMessageTypePing(t);else if("push"==t.type)this.callbacks.push(t,"websocket");else if("notify"==t.type)"connection.created"===t.event_type?this.writeWebSocketTimelineLog("notify-connection.created",t):"connection.destroyed"===t.event_type&&this.writeWebSocketTimelineLog("notify-connection.destroyed",t),this.signalingOnMessageTypeNotify(t,"websocket");else if("switched"==t.type)this.writeWebSocketSignalingLog("onmessage-switched",t),this.signalingOnMessageTypeSwitched(t);else if("redirect"==t.type){this.writeWebSocketSignalingLog("onmessage-redirect",t);try{const e=await this.signalingOnMessageTypeRedirect(t);i(e)}catch(e){s(e)}}},(async()=>{let i;try{i=H(n.sdp||"",this.role,this.channelId,this.metadata,this.options,t)}catch(e){return void s(e)}if(i.e2ee&&this.e2ee){const e=await this.e2ee.init();i.signaling_notify_metadata.pre_key_bundle=e}this.trace("SIGNALING CONNECT MESSAGE",i),e&&(e.send(JSON.stringify(i)),this.writeWebSocketSignalingLog(`send-${i.type}`,i),this.ws=e)})()}))}async connectPeerConnection(e){let t=Object.assign({},e.config);if(this.e2ee&&(t=Object.assign({encodedInsertableStreams:!0},t)),void 0!==window.RTCPeerConnection.generateCertificate){const e=await window.RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"});t=Object.assign({certificates:[e]},t)}this.trace("PEER CONNECTION CONFIG",t),this.writePeerConnectionTimelineLog("new-peerconnection",t),this.pc=new window.RTCPeerConnection(t,this.constraints),this.pc.oniceconnectionstatechange=e=>{this.pc&&(this.writePeerConnectionTimelineLog("oniceconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),this.trace("ONICECONNECTIONSTATECHANGE ICECONNECTIONSTATE",this.pc.iceConnectionState))},this.pc.onicegatheringstatechange=e=>{this.pc&&this.writePeerConnectionTimelineLog("onicegatheringstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState})},this.pc.onconnectionstatechange=e=>{this.pc&&this.writePeerConnectionTimelineLog("onconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState})},this.pc.ondatachannel=e=>{this.onDataChannel(e)}}async setRemoteDescription(e){if(!this.pc)return;const t=new RTCSessionDescription({type:"offer",sdp:e.sdp});await this.pc.setRemoteDescription(t),this.writePeerConnectionTimelineLog("set-remote-description",t)}async createAnswer(e){if(!this.pc)return;for(const e of Object.values(this.mids)){const t=this.pc.getTransceivers().find((t=>t.mid===e));t&&"recvonly"===t.direction&&(t.direction="sendrecv")}if(this.options.simulcast&&("sendrecv"===this.role||"sendonly"===this.role)){const t=this.pc.getTransceivers().find((e=>{if(null!==e.mid&&null!==e.sender.track&&(null===e.currentDirection||"sendonly"===e.currentDirection))return""!==this.mids.video&&this.mids.video===e.mid||0<=e.mid.indexOf("video")?e:void 0}));if(t){await this.setSenderParameters(t,this.encodings),await this.setRemoteDescription(e),this.trace("TRANSCEIVER SENDER GET_PARAMETERS",t.sender.getParameters()),await this.setSenderParameters(t,this.encodings);const n=await this.pc.createAnswer();return await this.pc.setLocalDescription(n),void this.trace("TRANSCEIVER SENDER GET_PARAMETERS",t.sender.getParameters())}}const t=await this.pc.createAnswer();this.writePeerConnectionTimelineLog("create-answer",t),await this.pc.setLocalDescription(t),this.writePeerConnectionTimelineLog("set-local-description",t)}sendAnswer(){if(this.pc&&this.ws&&this.pc.localDescription){this.trace("ANSWER SDP",this.pc.localDescription.sdp);const e={type:"answer",sdp:this.pc.localDescription.sdp};this.ws.send(JSON.stringify(e)),this.writeWebSocketSignalingLog("send-answer",e)}}onIceCandidate(){return new Promise(((e,t)=>{this.pc&&(this.pc.oniceconnectionstatechange=t=>{this.pc&&(this.writePeerConnectionTimelineLog("oniceconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),this.trace("ONICECONNECTIONSTATECHANGE ICECONNECTIONSTATE",this.pc.iceConnectionState),"connected"===this.pc.iceConnectionState&&e())},this.pc.onicecandidate=t=>{if(this.writePeerConnectionTimelineLog("onicecandidate",t.candidate),this.pc&&this.trace("ONICECANDIDATE ICEGATHERINGSTATE",this.pc.iceGatheringState),null===t.candidate)e();else{const e=t.candidate.toJSON(),n=Object.assign(e,{type:"candidate"});this.trace("ONICECANDIDATE CANDIDATE MESSAGE",n),this.sendSignalingMessage(n)}})}))}waitChangeConnectionStateConnected(){return new Promise(((e,t)=>{if(this.pc&&void 0===this.pc.connectionState)return void e();const n=setInterval((()=>{if(this.pc)this.pc&&"connected"===this.pc.connectionState&&(clearInterval(n),e());else{const e=new Error;e.message="PeerConnection connectionState did not change to 'connected'",clearInterval(n),t(e)}}),10)}))}monitorSignalingWebSocketEvent(){return new Promise(((e,t)=>{this.monitorSignalingWebSocketEventTimerId=setInterval((()=>{this.ws&&(this.clearMonitorSignalingWebSocketEvent(),this.ws.onclose=async e=>{const n=new z(`Signaling failed. CloseEventCode:${e.code} CloseEventReason:'${e.reason}'`);n.code=e.code,n.reason=e.reason,this.writeWebSocketTimelineLog("onclose",n),await this.signalingTerminate(),t(n)},this.ws.onerror=async e=>{const n=new z("Signaling failed. WebSocket onerror was called");this.writeWebSocketSignalingLog("onerror",n),await this.signalingTerminate(),t(n)})}),100)}))}monitorWebSocketEvent(){this.ws&&(this.ws.onclose=async e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason}),await this.abend("WEBSOCKET-ONCLOSE",{code:e.code,reason:e.reason})},this.ws.onerror=async e=>{this.writeWebSocketSignalingLog("onerror"),await this.abend("WEBSOCKET-ONERROR")})}monitorPeerConnectionState(){this.pc&&(this.pc.oniceconnectionstatechange=async e=>{this.pc&&void 0===this.pc.connectionState&&(this.writePeerConnectionTimelineLog("oniceconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),this.trace("ONICECONNECTIONSTATECHANGE ICECONNECTIONSTATE",this.pc.iceConnectionState),clearTimeout(this.monitorIceConnectionStateChangeTimerId),"failed"===this.pc.iceConnectionState?await this.abendPeerConnectionState("ICE-CONNECTION-STATE-FAILED"):"disconnected"===this.pc.iceConnectionState&&(this.monitorIceConnectionStateChangeTimerId=setTimeout((async()=>{this.pc&&"disconnected"===this.pc.iceConnectionState&&await this.abendPeerConnectionState("ICE-CONNECTION-STATE-DISCONNECTED-TIMEOUT")}),1e4)))},this.pc.onconnectionstatechange=async e=>{this.pc&&(this.writePeerConnectionTimelineLog("onconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),"failed"===this.pc.connectionState&&await this.abendPeerConnectionState("CONNECTION-STATE-FAILED"))})}setConnectionTimeout(){return new Promise(((e,t)=>{0{if(!this.pc||this.pc&&void 0!==this.pc.connectionState&&"connected"!==this.pc.connectionState){const e=new Error;e.message="Signaling connection timeout",this.callbacks.timeout(),this.trace("DISCONNECT","Signaling connection timeout"),this.writePeerConnectionTimelineLog("signaling-connection-timeout",{connectionTimeout:this.connectionTimeout}),await this.signalingTerminate(),t(e)}}),this.connectionTimeout))}))}clearConnectionTimeout(){clearTimeout(this.connectionTimeoutTimerId)}clearMonitorSignalingWebSocketEvent(){clearInterval(this.monitorSignalingWebSocketEventTimerId)}clearMonitorIceConnectionStateChange(){clearInterval(this.monitorIceConnectionStateChangeTimerId)}trace(e,t){this.callbacks.log(e,t),this.debug&&function(e,t,n){const i=e=>{if(e&&"object"==typeof e){let t=null;try{t=Object.keys(JSON.parse(JSON.stringify(e)))}catch(e){}t&&Array.isArray(t)?t.forEach((t=>{console.group(t),i(e[t]),console.groupEnd()})):console.info(e)}else console.info(e)};let s="";window.performance&&(s="["+(window.performance.now()/1e3).toFixed(3)+"]"),e&&(s=s+"["+e+"]"),void 0!==console.info&&void 0!==console.group?(console.group(s+" "+t),i(n),console.groupEnd()):console.log(s+" "+t+"\n",n)}(this.clientId,e,t)}writeWebSocketSignalingLog(e,t){this.callbacks.signaling(_(e,t,"websocket")),this.writeWebSocketTimelineLog(e,t)}writeDataChannelSignalingLog(e,t,n){this.callbacks.signaling(_(e,n,"datachannel")),this.writeDataChannelTimelineLog(e,t,n)}writeWebSocketTimelineLog(e,t){const n=q(e,t,"websocket");this.callbacks.timeline(n)}writeDataChannelTimelineLog(e,t,n){const i=q(e,n,"datachannel",t.id,t.label);this.callbacks.timeline(i)}writePeerConnectionTimelineLog(e,t){const n=q(e,t,"peerconnection");this.callbacks.timeline(n)}writeSoraTimelineLog(e,t){const n=q(e,t,"sora");this.callbacks.timeline(n)}async createOffer(){const e=new window.RTCPeerConnection({iceServers:[]});if(Q()){e.addTransceiver("video",{direction:"recvonly"}),e.addTransceiver("audio",{direction:"recvonly"});const t=await e.createOffer();return e.close(),this.writePeerConnectionTimelineLog("create-offer",t),t}const t=await e.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0});return e.close(),this.writePeerConnectionTimelineLog("create-offer",t),t}signalingOnMessageE2EE(e){if(this.e2ee){const t=new Uint8Array(e),n=this.e2ee.receiveMessage(t);this.e2ee.postRemoteSecretKeyMaterials(n),n.messages.forEach((e=>{this.sendE2EEMessage(e.buffer)}))}}signalingOnMessageTypeOffer(e){if(this.clientId=e.client_id,this.connectionId=e.connection_id,void 0!==e.metadata&&(this.authMetadata=e.metadata),Array.isArray(e.encodings)&&(this.encodings=e.encodings),void 0!==e.mid&&void 0!==e.mid.audio&&(this.mids.audio=e.mid.audio),void 0!==e.mid&&void 0!==e.mid.video&&(this.mids.video=e.mid.video),e.data_channels)for(const t of e.data_channels)this.signalingOfferMessageDataChannels[t.label]=t;this.trace("SIGNALING OFFER MESSAGE",e),this.trace("OFFER SDP",e.sdp)}sendUpdateAnswer(){this.pc&&this.ws&&this.pc.localDescription&&(this.trace("ANSWER SDP",this.pc.localDescription.sdp),this.sendSignalingMessage({type:"update",sdp:this.pc.localDescription.sdp}))}sendReAnswer(){this.pc&&this.pc.localDescription&&(this.trace("RE ANSWER SDP",this.pc.localDescription.sdp),this.sendSignalingMessage({type:"re-answer",sdp:this.pc.localDescription.sdp}))}async signalingOnMessageTypeUpdate(e){this.trace("SIGNALING UPDATE MESSGE",e),this.trace("UPDATE SDP",e.sdp),await this.setRemoteDescription(e),await this.createAnswer(e),this.sendUpdateAnswer()}async signalingOnMessageTypeReOffer(e){this.trace("SIGNALING RE OFFER MESSGE",e),this.trace("RE OFFER SDP",e.sdp),await this.setRemoteDescription(e),await this.createAnswer(e),this.sendReAnswer()}async signalingOnMessageTypePing(e){const t={type:"pong"};if(e.stats){const e=await this.getStats();t.stats=e}this.ws&&this.ws.send(JSON.stringify(t))}signalingOnMessageTypeNotify(e,t){if("connection.created"===e.event_type){const t=e.connection_id;if(this.connectionId!==t){const n=P(x(e));if(n&&this.e2ee&&t){const e=this.e2ee.startSession(t,n);this.e2ee.postRemoteSecretKeyMaterials(e),e.messages.forEach((e=>{this.sendE2EEMessage(e.buffer)})),this.e2ee.postSelfSecretKeyMaterial(e.selfConnectionId,e.selfKeyId,e.selfSecretKeyMaterial)}}const n=function(e){return e.data&&Array.isArray(e.data)?e.data:e.metadata_list&&Array.isArray(e.metadata_list)?e.metadata_list:[]}(e);n.forEach((e=>{const t=P(x(e)),n=e.connection_id;n&&this.e2ee&&t&&this.e2ee.addPreKeyBundle(n,t)}))}else if("connection.destroyed"===e.event_type){const t=P(x(e)),n=e.connection_id;if(t&&this.e2ee&&n){const e=this.e2ee.stopSession(n);this.e2ee.postSelfSecretKeyMaterial(e.selfConnectionId,e.selfKeyId,e.selfSecretKeyMaterial,5e3),e.messages.forEach((e=>{this.sendE2EEMessage(e.buffer)})),this.e2ee.postRemoveRemoteDeriveKey(n)}}this.callbacks.notify(e,t)}signalingOnMessageTypeSwitched(e){if(this.signalingSwitched=!0,this.ws){e.ignore_disconnect_websocket&&(this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null),this.writeWebSocketSignalingLog("close"));for(const e of this.datachannels)this.callbacks.datachannel($(e))}}async signalingOnMessageTypeRedirect(e){this.ws&&(this.ws.onclose=null,this.ws.onerror=null,this.ws.close(),this.ws=null);const t=await this.getSignalingWebSocket(e.location);return await this.signaling(t,!0)}async setSenderParameters(e,t){const n=e.sender.getParameters();n.encodings=t,await e.sender.setParameters(n),this.trace("TRANSCEIVER SENDER SET_PARAMETERS",n),this.writePeerConnectionTimelineLog("transceiver-sender-set-parameters",n)}async getStats(){const e=[];if(!this.pc)return e;return(await this.pc.getStats()).forEach((t=>{e.push(t)})),e}onDataChannel(e){const t=e.channel;var n;this.writeDataChannelTimelineLog("ondatachannel",t,{binaryType:(n=t).binaryType,bufferedAmount:n.bufferedAmount,bufferedAmountLowThreshold:n.bufferedAmountLowThreshold,id:n.id,label:n.label,maxPacketLifeTime:n.maxPacketLifeTime,maxRetransmits:n.maxRetransmits,negotiated:n.negotiated,ordered:n.ordered,protocol:n.protocol,readyState:n.readyState,reliable:n.reliable}),e.channel.onbufferedamountlow=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onbufferedamountlow",t)},e.channel.onopen=e=>{const t=e.currentTarget;t.bufferedAmountLowThreshold=65536,t.binaryType="arraybuffer",this.soraDataChannels[t.label]=t,this.trace("OPEN DATA CHANNEL",t.label),"signaling"===t.label&&this.ws?this.writeDataChannelSignalingLog("onopen",t):this.writeDataChannelTimelineLog("onopen",t)},e.channel.onclose=async e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label),await this.disconnect()},e.channel.onerror=async e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onerror",t),this.trace("ERROR DATA CHANNEL",t.label),await this.abend("DATA-CHANNEL-ONERROR",{params:{label:t.label}})},"signaling"===e.channel.label?e.channel.onmessage=async e=>{const t=e.currentTarget;let n=e.data;if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const t=U(new Uint8Array(e.data));n=(new TextDecoder).decode(t)}const i=JSON.parse(n);this.writeDataChannelSignalingLog(`onmessage-${i.type}`,t,i),"re-offer"===i.type&&await this.signalingOnMessageTypeReOffer(i)}:"notify"===e.channel.label?e.channel.onmessage=e=>{const t=e.currentTarget;let n=e.data;if(this.signalingOfferMessageDataChannels.notify&&!0===this.signalingOfferMessageDataChannels.notify.compress){const t=U(new Uint8Array(e.data));n=(new TextDecoder).decode(t)}const i=JSON.parse(n);"connection.created"===i.event_type?this.writeDataChannelTimelineLog("notify-connection.created",t,i):"connection.destroyed"===i.event_type&&this.writeDataChannelTimelineLog("notify-connection.destroyed",t,i),this.signalingOnMessageTypeNotify(i,"datachannel")}:"push"===e.channel.label?e.channel.onmessage=e=>{let t=e.data;if(this.signalingOfferMessageDataChannels.push&&!0===this.signalingOfferMessageDataChannels.push.compress){const n=U(new Uint8Array(e.data));t=(new TextDecoder).decode(n)}const n=JSON.parse(t);this.callbacks.push(n,"datachannel")}:"e2ee"===e.channel.label?e.channel.onmessage=e=>{const t=e.currentTarget,n=e.data;this.signalingOnMessageE2EE(n),this.writeDataChannelSignalingLog("onmessage-e2ee",t,n)}:"stats"===e.channel.label?e.channel.onmessage=async e=>{let t=e.data;if(this.signalingOfferMessageDataChannels.stats&&!0===this.signalingOfferMessageDataChannels.stats.compress){const n=U(new Uint8Array(e.data));t=(new TextDecoder).decode(n)}if("req-stats"===JSON.parse(t).type){const e=await this.getStats();this.sendStatsMessage(e)}}:/^#.*/.exec(e.channel.label)&&(e.channel.onmessage=e=>{if(null===e.target)return;const t=e.target;let n=e.data;const i=this.signalingOfferMessageDataChannels[t.label];void 0!==i&&!0===i.compress&&(n=U(new Uint8Array(e.data)).buffer),this.callbacks.message(function(e,t){const n=new Event("message");return n.label=e,n.data=t,n}(t.label,n))})}sendSignalingMessage(e){if(this.soraDataChannels.signaling){if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const t=F((new TextEncoder).encode(JSON.stringify(e)),{});this.soraDataChannels.signaling.send(t)}else this.soraDataChannels.signaling.send(JSON.stringify(e));this.writeDataChannelSignalingLog(`send-${e.type}`,this.soraDataChannels.signaling,e)}else null!==this.ws&&(this.ws.send(JSON.stringify(e)),this.writeWebSocketSignalingLog(`send-${e.type}`,e))}sendE2EEMessage(e){this.soraDataChannels.e2ee?(this.soraDataChannels.e2ee.send(e),this.writeDataChannelSignalingLog("send-e2ee",this.soraDataChannels.e2ee,e)):null!==this.ws&&(this.ws.send(e),this.writeWebSocketSignalingLog("send-e2ee",e))}sendStatsMessage(e){if(this.soraDataChannels.stats){const t={type:"stats",reports:e};if(this.signalingOfferMessageDataChannels.stats&&!0===this.signalingOfferMessageDataChannels.stats.compress){const e=F((new TextEncoder).encode(JSON.stringify(t)),{});this.soraDataChannels.stats.send(e)}else this.soraDataChannels.stats.send(JSON.stringify(t))}}getAudioTransceiver(){if(this.pc&&this.mids.audio){return this.pc.getTransceivers().find((e=>e.mid===this.mids.audio))||null}return null}getVideoTransceiver(){if(this.pc&&this.mids.video){return this.pc.getTransceivers().find((e=>e.mid===this.mids.video))||null}return null}soraCloseEvent(e,t,n){const i=class extends Event{constructor(e,t,n){super(e),n&&(n.code&&(this.code=n.code),n.reason&&(this.reason=n.reason),n.params&&(this.params=n.params)),this.title=t}};return new i(e,t,n)}sendMessage(e,t){const n=this.soraDataChannels[e];if(null===this.pc)return;if(void 0===n)throw new Error("Could not find DataChannel");const i=this.signalingOfferMessageDataChannels[e];if(void 0!==i&&!0===i.compress){const e=F(t,{});n.send(e)}else n.send(t)}get e2eeSelfFingerprint(){if(this.options.e2ee&&this.e2ee)return this.e2ee.selfFingerprint()}get e2eeRemoteFingerprints(){if(this.options.e2ee&&this.e2ee)return this.e2ee.remoteFingerprints()}get audio(){return null!==this.getAudioTransceiver()}get video(){return null!==this.getVideoTransceiver()}get signalingUrl(){return this.signalingUrlCandidates}get connectedSignalingUrl(){return this.ws?this.ws.url:""}get datachannels(){if(!this.signalingSwitched)return[];const e=Object.keys(this.signalingOfferMessageDataChannels).filter((e=>/^#.*/.exec(e))),t=[];for(const n of e){const e=this.soraDataChannels[n];if(!e)continue;const i=this.signalingOfferMessageDataChannels[n];if(!i)continue;const s={label:e.label,ordered:e.ordered,protocol:e.protocol,compress:i.compress,direction:i.direction};"number"==typeof e.maxPacketLifeTime&&(s.maxPacketLifeTime=e.maxPacketLifeTime),"number"==typeof e.maxRetransmits&&(s.maxRetransmits=e.maxRetransmits),t.push(s)}return t}}class te extends ee{async connect(e){return this.options.multistream?await Promise.race([this.multiStream(e).finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]):await Promise.race([this.singleStream(e).finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]),this.monitorWebSocketEvent(),this.monitorPeerConnectionState(),e}async singleStream(e){await this.disconnect(),this.setupE2EE();const t=await this.getSignalingWebSocket(this.signalingUrlCandidates),n=await this.signaling(t);return this.startE2EE(),await this.connectPeerConnection(n),await this.setRemoteDescription(n),e.getTracks().forEach((t=>{this.pc&&this.pc.addTrack(t,e)})),this.stream=e,await this.createAnswer(n),this.sendAnswer(),this.pc&&this.e2ee&&this.pc.getSenders().forEach((e=>{this.e2ee&&this.e2ee.setupSenderTransform(e)})),await this.onIceCandidate(),await this.waitChangeConnectionStateConnected(),e}async multiStream(e){await this.disconnect(),this.setupE2EE();const t=await this.getSignalingWebSocket(this.signalingUrlCandidates),n=await this.signaling(t);return this.startE2EE(),await this.connectPeerConnection(n),this.pc&&(this.pc.ontrack=e=>{const t=e.streams[0];if(!t)return;const n={"stream.id":t.id,id:e.track.id,label:e.track.label,enabled:e.track.enabled,kind:e.track.kind,muted:e.track.muted,readyState:e.track.readyState};this.writePeerConnectionTimelineLog("ontrack",n),"default"!==t.id&&t.id!==this.connectionId&&(this.e2ee&&this.e2ee.setupReceiverTransform(e.receiver),this.callbacks.track(e),t.onremovetrack=e=>{if(this.callbacks.removetrack(e),e.target){const t=this.remoteConnectionIds.indexOf(e.target.id);-1{this.pc&&this.pc.addTrack(t,e)})),this.stream=e,await this.createAnswer(n),this.sendAnswer(),this.pc&&this.e2ee&&this.pc.getSenders().forEach((e=>{this.e2ee&&this.e2ee.setupSenderTransform(e)})),await this.onIceCandidate(),await this.waitChangeConnectionStateConnected(),e}}class ne extends ee{async connect(){if(this.options.multistream)return await Promise.race([this.multiStream().finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]),this.monitorWebSocketEvent(),void this.monitorPeerConnectionState();{const e=await Promise.race([this.singleStream().finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]);return this.monitorWebSocketEvent(),this.monitorPeerConnectionState(),e}}async singleStream(){await this.disconnect(),this.setupE2EE();const e=await this.getSignalingWebSocket(this.signalingUrlCandidates),t=await this.signaling(e);return this.startE2EE(),await this.connectPeerConnection(t),this.pc&&(this.pc.ontrack=e=>{this.stream=e.streams[0];const t=this.stream.id;if("default"===t)return;const n={"stream.id":t,id:e.track.id,label:e.track.label,enabled:e.track.enabled,kind:e.track.kind,muted:e.track.muted,readyState:e.track.readyState};this.writePeerConnectionTimelineLog("ontrack",n),this.e2ee&&this.e2ee.setupReceiverTransform(e.receiver),this.callbacks.track(e),this.stream.onremovetrack=e=>{if(this.callbacks.removetrack(e),e.target){const t=this.remoteConnectionIds.indexOf(e.target.id);-1{const t=e.streams[0];if("default"===t.id)return;if(t.id===this.connectionId)return;const n={"stream.id":t.id,id:e.track.id,label:e.track.label,enabled:e.track.enabled,kind:e.track.kind,muted:e.track.muted,readyState:e.track.readyState};this.writePeerConnectionTimelineLog("ontrack",n),this.e2ee&&this.e2ee.setupReceiverTransform(e.receiver),this.callbacks.track(e),t.onremovetrack=e=>{if(this.callbacks.removetrack(e),e.target){const t=this.remoteConnectionIds.indexOf(e.target.id);-1{const{operation:t}=e.data;"disconnect"===t&&"function"==typeof this.onWorkerDisconnect&&this.onWorkerDisconnect()}}clearWorker(){this.worker&&this.worker.postMessage({type:"clear"})}terminateWorker(){this.worker&&this.worker.terminate()}async init(){const{preKeyBundle:e}=await window.e2ee.init();return e}setupSenderTransform(e){if(!e.track)return;const t=e.createEncodedStreams(),n=t.readableStream||t.readable,i=t.writableStream||t.writable;if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");const s={type:"encrypt",readableStream:n,writableStream:i};this.worker.postMessage(s,[n,i])}setupReceiverTransform(e){const t=e.createEncodedStreams(),n=t.readableStream||t.readable,i=t.writableStream||t.writable;if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");const s={type:"decrypt",readableStream:n,writableStream:i};this.worker.postMessage(s,[n,i])}postRemoteSecretKeyMaterials(e){if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");this.worker.postMessage({type:"remoteSecretKeyMaterials",remoteSecretKeyMaterials:e.remoteSecretKeyMaterials})}postRemoveRemoteDeriveKey(e){if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");this.worker.postMessage({type:"removeRemoteDeriveKey",connectionId:e})}postSelfSecretKeyMaterial(e,t,n,i=0){if(!this.worker)throw new Error("Worker is null. Call startWorker in advance.");this.worker.postMessage({type:"selfSecretKeyMaterial",selfConnectionId:e,selfKeyId:t,selfSecretKeyMaterial:n,waitingTime:i})}startSession(e,t){const[n,i]=window.e2ee.startSession(e,t.identityKey,t.signedPreKey,t.preKeySignature);if(i)throw i;return n}stopSession(e){const[t,n]=window.e2ee.stopSession(e);if(n)throw n;return t}receiveMessage(e){const[t,n]=window.e2ee.receiveMessage(e);if(n)throw n;return t}start(e){const[t,n]=window.e2ee.start(e);if(n)throw n;return t}addPreKeyBundle(e,t){const n=window.e2ee.addPreKeyBundle(e,t.identityKey,t.signedPreKey,t.preKeySignature);if(n)throw n}selfFingerprint(){return window.e2ee.selfFingerprint()}remoteFingerprints(){return window.e2ee.remoteFingerprints()}static async loadWasm(e){if(void 0===!window.e2ee)return void console.warn("E2ee wasm is already loaded. Will not be reload.");if((()=>{if("undefined"!=typeof global);else if("undefined"!=typeof window)window.global=window;else{if("undefined"==typeof self)throw new Error("cannot export Go (neither global, window nor self is defined)");self.global=self}if(global.require||"undefined"==typeof require||(global.require=require),!global.fs&&global.require){const e=require("fs");0!==Object.keys(e)&&(global.fs=e)}const e=()=>{const e=new Error("not implemented");return e.code="ENOSYS",e};if(!global.fs){let t="";global.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(e,i){t+=n.decode(i);const s=t.lastIndexOf("\n");return-1!=s&&(console.log(t.substr(0,s)),t=t.substr(s+1)),i.length},write(t,n,i,s,a,o){0===i&&s===n.length&&null===a?o(null,this.writeSync(t,n)):o(e())},chmod(t,n,i){i(e())},chown(t,n,i,s){s(e())},close(t,n){n(e())},fchmod(t,n,i){i(e())},fchown(t,n,i,s){s(e())},fstat(t,n){n(e())},fsync(e,t){t(null)},ftruncate(t,n,i){i(e())},lchown(t,n,i,s){s(e())},link(t,n,i){i(e())},lstat(t,n){n(e())},mkdir(t,n,i){i(e())},open(t,n,i,s){s(e())},read(t,n,i,s,a,o){o(e())},readdir(t,n){n(e())},readlink(t,n){n(e())},rename(t,n,i){i(e())},rmdir(t,n){n(e())},stat(t,n){n(e())},symlink(t,n,i){i(e())},truncate(t,n,i){i(e())},unlink(t,n){n(e())},utimes(t,n,i,s){s(e())}}}if(global.process||(global.process={getuid:()=>-1,getgid:()=>-1,geteuid:()=>-1,getegid:()=>-1,getgroups(){throw e()},pid:-1,ppid:-1,umask(){throw e()},cwd(){throw e()},chdir(){throw e()}}),!global.crypto){const e=require("crypto");global.crypto={getRandomValues(t){e.randomFillSync(t)}}}global.performance||(global.performance={now(){const[e,t]=process.hrtime();return 1e3*e+t/1e6}}),global.TextEncoder||(global.TextEncoder=require("util").TextEncoder),global.TextDecoder||(global.TextDecoder=require("util").TextDecoder);const t=new TextEncoder("utf-8"),n=new TextDecoder("utf-8");if(global.Go=class{constructor(){this.argv=["js"],this.env={},this.exit=e=>{0!==e&&console.warn("exit code:",e)},this._exitPromise=new Promise((e=>{this._resolveExitPromise=e})),this._pendingEvent=null,this._scheduledTimeouts=new Map,this._nextCallbackTimeoutID=1;const e=(e,t)=>{this.mem.setUint32(e+0,t,!0),this.mem.setUint32(e+4,Math.floor(t/4294967296),!0)},i=e=>this.mem.getUint32(e+0,!0)+4294967296*this.mem.getInt32(e+4,!0),s=e=>{const t=this.mem.getFloat64(e,!0);if(0===t)return;if(!isNaN(t))return t;const n=this.mem.getUint32(e,!0);return this._values[n]},a=(e,t)=>{const n=2146959360;if("number"==typeof t&&0!==t)return isNaN(t)?(this.mem.setUint32(e+4,n,!0),void this.mem.setUint32(e,0,!0)):void this.mem.setFloat64(e,t,!0);if(void 0===t)return void this.mem.setFloat64(e,0,!0);let i=this._ids.get(t);void 0===i&&(i=this._idPool.pop(),void 0===i&&(i=this._values.length),this._values[i]=t,this._goRefCounts[i]=0,this._ids.set(t,i)),this._goRefCounts[i]++;let s=0;switch(typeof t){case"object":null!==t&&(s=1);break;case"string":s=2;break;case"symbol":s=3;break;case"function":s=4}this.mem.setUint32(e+4,n|s,!0),this.mem.setUint32(e,i,!0)},o=e=>{const t=i(e+0),n=i(e+8);return new Uint8Array(this._inst.exports.mem.buffer,t,n)},g=e=>{const t=i(e+0),n=i(e+8),a=new Array(n);for(let e=0;e{const t=i(e+0),s=i(e+8);return n.decode(new DataView(this._inst.exports.mem.buffer,t,s))},c=Date.now()-performance.now();this.importObject={go:{"runtime.wasmExit":e=>{const t=this.mem.getInt32(e+8,!0);this.exited=!0,delete this._inst,delete this._values,delete this._goRefCounts,delete this._ids,delete this._idPool,this.exit(t)},"runtime.wasmWrite":e=>{const t=i(e+8),n=i(e+16),s=this.mem.getInt32(e+24,!0);fs.writeSync(t,new Uint8Array(this._inst.exports.mem.buffer,n,s))},"runtime.resetMemoryDataView":e=>{this.mem=new DataView(this._inst.exports.mem.buffer)},"runtime.nanotime1":t=>{e(t+8,1e6*(c+performance.now()))},"runtime.walltime1":t=>{const n=(new Date).getTime();e(t+8,n/1e3),this.mem.setInt32(t+16,n%1e3*1e6,!0)},"runtime.scheduleTimeoutEvent":e=>{const t=this._nextCallbackTimeoutID;this._nextCallbackTimeoutID++,this._scheduledTimeouts.set(t,setTimeout((()=>{for(this._resume();this._scheduledTimeouts.has(t);)console.warn("scheduleTimeoutEvent: missed timeout event"),this._resume()}),i(e+8)+1)),this.mem.setInt32(e+16,t,!0)},"runtime.clearTimeoutEvent":e=>{const t=this.mem.getInt32(e+8,!0);clearTimeout(this._scheduledTimeouts.get(t)),this._scheduledTimeouts.delete(t)},"runtime.getRandomData":e=>{crypto.getRandomValues(o(e+8))},"syscall/js.finalizeRef":e=>{const t=this.mem.getUint32(e+8,!0);if(this._goRefCounts[t]--,0===this._goRefCounts[t]){const e=this._values[t];this._values[t]=null,this._ids.delete(e),this._idPool.push(t)}},"syscall/js.stringVal":e=>{a(e+24,l(e+8))},"syscall/js.valueGet":e=>{const t=Reflect.get(s(e+8),l(e+16));e=this._inst.exports.getsp(),a(e+32,t)},"syscall/js.valueSet":e=>{Reflect.set(s(e+8),l(e+16),s(e+32))},"syscall/js.valueDelete":e=>{Reflect.deleteProperty(s(e+8),l(e+16))},"syscall/js.valueIndex":e=>{a(e+24,Reflect.get(s(e+8),i(e+16)))},"syscall/js.valueSetIndex":e=>{Reflect.set(s(e+8),i(e+16),s(e+24))},"syscall/js.valueCall":e=>{try{const t=s(e+8),n=Reflect.get(t,l(e+16)),i=g(e+32),o=Reflect.apply(n,t,i);e=this._inst.exports.getsp(),a(e+56,o),this.mem.setUint8(e+64,1)}catch(t){a(e+56,t),this.mem.setUint8(e+64,0)}},"syscall/js.valueInvoke":e=>{try{const t=s(e+8),n=g(e+16),i=Reflect.apply(t,void 0,n);e=this._inst.exports.getsp(),a(e+40,i),this.mem.setUint8(e+48,1)}catch(t){a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueNew":e=>{try{const t=s(e+8),n=g(e+16),i=Reflect.construct(t,n);e=this._inst.exports.getsp(),a(e+40,i),this.mem.setUint8(e+48,1)}catch(t){a(e+40,t),this.mem.setUint8(e+48,0)}},"syscall/js.valueLength":t=>{e(t+16,parseInt(s(t+8).length))},"syscall/js.valuePrepareString":n=>{const i=t.encode(String(s(n+8)));a(n+16,i),e(n+24,i.length)},"syscall/js.valueLoadString":e=>{const t=s(e+8);o(e+16).set(t)},"syscall/js.valueInstanceOf":e=>{this.mem.setUint8(e+24,s(e+8)instanceof s(e+16)?1:0)},"syscall/js.copyBytesToGo":t=>{const n=o(t+8),i=s(t+32);if(!(i instanceof Uint8Array||i instanceof Uint8ClampedArray))return void this.mem.setUint8(t+48,0);const a=i.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},"syscall/js.copyBytesToJS":t=>{const n=s(t+8),i=o(t+16);if(!(n instanceof Uint8Array||n instanceof Uint8ClampedArray))return void this.mem.setUint8(t+48,0);const a=i.subarray(0,n.length);n.set(a),e(t+40,a.length),this.mem.setUint8(t+48,1)},debug:e=>{console.log(e)}}}}async run(e){this._inst=e,this.mem=new DataView(this._inst.exports.mem.buffer),this._values=[NaN,0,null,!0,!1,global,this],this._goRefCounts=new Array(this._values.length).fill(1/0),this._ids=new Map([[0,1],[null,2],[!0,3],[!1,4],[global,5],[this,6]]),this._idPool=[],this.exited=!1;let n=4096;const i=e=>{const i=n,s=t.encode(e+"\0");return new Uint8Array(this.mem.buffer,n,s.length).set(s),n+=s.length,n%8!=0&&(n+=8-n%8),i},s=this.argv.length,a=[];this.argv.forEach((e=>{a.push(i(e))})),a.push(0),Object.keys(this.env).sort().forEach((e=>{a.push(i(`${e}=${this.env[e]}`))})),a.push(0);const o=n;a.forEach((e=>{this.mem.setUint32(n,e,!0),this.mem.setUint32(n+4,0,!0),n+=8})),this._inst.exports.run(s,o),this.exited&&this._resolveExitPromise(),await this._exitPromise}_resume(){if(this.exited)throw new Error("Go program has already exited");this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(e){const t=this;return function(){const n={id:e,this:this,args:arguments};return t._pendingEvent=n,t._resume(),n.result}}},global.require&&global.require.main===module&&global.process&&global.process.versions&&!global.process.versions.electron){process.argv.length<3&&(console.error("usage: go_js_wasm_exec [wasm binary] [arguments]"),process.exit(1));const e=new Go;e.argv=process.argv.slice(2),e.env=Object.assign({TMPDIR:require("os").tmpdir()},process.env),e.exit=process.exit,WebAssembly.instantiate(fs.readFileSync(process.argv[2]),e.importObject).then((t=>(process.on("exit",(t=>{0!==t||e.exited||(e._pendingEvent={id:0},e._resume())})),e.run(t.instance)))).catch((e=>{console.error(e),process.exit(1)}))}})(),!window.Go)throw new Error(`Failed to load module Go. window.Go is ${window.Go}.`);const t=new Go,{instance:n}=await WebAssembly.instantiateStreaming(fetch(e),t.importObject);if(t.run(n),!window.e2ee)throw new Error(`Failed to load module e2ee. window.e2ee is ${window.e2ee}.`)}static version(){return"2021.1.0"}static wasmVersion(){return window.e2ee.version()}}var t=Uint8Array,n=Uint16Array,i=Uint32Array,s=new t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),a=new t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),o=new t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),g=function(e,t){for(var s=new n(31),a=0;a<31;++a)s[a]=t+=1<>>1|(21845&m)<<1;u=(61680&(u=(52428&u)>>>2|(13107&u)<<2))>>>4|(3855&u)<<4,I[m]=((65280&u)>>>8|(255&u)<<8)>>>1}var A=function(e,t,i){for(var s=e.length,a=0,o=new n(t);a>>c]=r}else for(g=new n(s),a=0;a>>15-e[a]);return g},b=new t(288);for(m=0;m<144;++m)b[m]=8;for(m=144;m<256;++m)b[m]=9;for(m=256;m<280;++m)b[m]=7;for(m=280;m<288;++m)b[m]=8;var p=new t(32);for(m=0;m<32;++m)p[m]=5;var Z=A(b,9,0),w=A(b,9,1),S=A(p,5,0),V=A(p,5,1),f=function(e){for(var t=e[0],n=1;nt&&(t=e[n]);return t},y=function(e,t,n){var i=t/8|0;return(e[i]|e[i+1]<<8)>>(7&t)&n},W=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(7&t)},G=function(e){return(e+7)/8|0},k=function(e,s,a){(null==s||s<0)&&(s=0),(null==a||a>e.length)&&(a=e.length);var o=new(2==e.BYTES_PER_ELEMENT?n:4==e.BYTES_PER_ELEMENT?i:t)(a-s);return o.set(e.subarray(s,a)),o},R=["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"],v=function(e,t,n){var i=new Error(t||R[e]);if(i.code=e,Error.captureStackTrace&&Error.captureStackTrace(i,v),!n)throw i;return i},T=function(e,t,n){n<<=7&t;var i=t/8|0;e[i]|=n,e[i+1]|=n>>>8},X=function(e,t,n){n<<=7&t;var i=t/8|0;e[i]|=n,e[i+1]|=n>>>8,e[i+2]|=n>>>16},E=function(e,i){for(var s=[],a=0;aI&&(I=g[a].s);var m=new n(I+1),u=O(s[d-1],m,0);if(u>i){a=0;var A=0,b=u-i,p=1<i))break;A+=p-(1<>>=b;A>0;){var w=g[a].s;m[w]=0&&A;--a){var S=g[a].s;m[S]==i&&(--m[S],++A)}u=i}return[new t(m),u]},O=function(e,t,n){return-1==e.s?Math.max(O(e.l,t,n+1),O(e.r,t,n+1)):t[e.s]=n},N=function(e){for(var t=e.length;t&&!e[--t];);for(var i=new n(++t),s=0,a=e[0],o=1,g=function(e){i[s++]=e},l=1;l<=t;++l)if(e[l]==a&&l!=t)++o;else{if(!a&&o>2){for(;o>138;o-=138)g(32754);o>2&&(g(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(g(a),--o;o>6;o-=6)g(8304);o>2&&(g(o-3<<5|8208),o=0)}for(;o--;)g(a);o=1,a=e[l]}return[i.subarray(0,s),t]},B=function(e,t){for(var n=0,i=0;i>>8,e[s+2]=255^e[s],e[s+3]=255^e[s+1];for(var a=0;a4&&!D[o[U-1]];--U);var M,j,Q,H,x=h+5<<3,P=B(l,b)+B(c,p)+r,z=B(l,u)+B(c,f)+r+14+3*U+B(K,D)+(2*K[16]+3*K[17]+7*K[18]);if(x<=P&&x<=z)return Y(t,I,e.subarray(d,d+h));if(T(t,I,1+(z15&&(T(t,I,ee[L]>>>5&127),I+=ee[L]>>>12)}}}else M=Z,j=b,Q=S,H=p;for(L=0;L255){te=g[L]>>>18&31;X(t,I,M[te+257]),I+=j[te+257],te>7&&(T(t,I,g[L]>>>23&31),I+=s[te]);var ne=31&g[L];X(t,I,Q[ne]),I+=H[ne],ne>3&&(X(t,I,g[L]>>>5&8191),I+=a[ne])}else X(t,I,M[g[L]]),I+=j[g[L]];return X(t,I,M[256]),I+j[256]},L=new i([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),J=new t(0),D=function(e,o,g,l,c){return function(e,o,g,l,c,C){var d=e.length,I=new t(l+d+5*(1+Math.ceil(d/7e3))+c),m=I.subarray(l,I.length-c),u=0;if(!o||d<8)for(var A=0;A<=d;A+=65535){var b=A+65535;b>=d&&(m[u>>3]=C),u=Y(m,u+1,e.subarray(A,b))}else{for(var p=L[o-1],Z=p>>>13,w=8191&p,S=(1<7e3||N>24576)&&j>423){u=K(e,m,0,v,T,X,O,N,D,A-D,u),N=E=O=0,D=A;for(var Q=0;Q<286;++Q)T[Q]=0;for(Q=0;Q<30;++Q)X[Q]=0}var H=2,x=0,P=w,z=U-M&32767;if(j>2&&F==R(A-z))for(var _=Math.min(Z,j)-1,q=Math.min(32767,A),$=Math.min(258,j);z<=q&&--P&&U!=M;){if(e[A+H]==e[A+H-z]){for(var ee=0;ee<$&&e[A+ee]==e[A+ee-z];++ee);if(ee>H){if(H=ee,x=z,ee>_)break;var te=Math.min(z,ee-2),ne=0;for(Q=0;Qne&&(ne=se,M=ie)}}}z+=(U=M)-(M=V[U])+32768&32767}if(x){v[N++]=268435456|r[H]<<18|h[x];var ae=31&r[H],oe=31&h[x];O+=s[ae]+a[oe],++T[257+ae],++X[oe],B=A+H,++E}else v[N++]=e[A],++T[e[A]]}}u=K(e,m,C,v,T,X,O,N,D,A-D,u),!C&&7&u&&(u=Y(m,u+1,J))}return k(I,0,l+G(u)+c)}(e,null==o.level?6:o.level,null==o.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):12+o.mem,g,l,!c)};function F(e,t){t||(t={});var n=function(){var e=1,t=0;return{p:function(n){for(var i=e,s=t,a=0|n.length,o=0;o!=a;){for(var g=Math.min(o+2655,a);o>16),s=(65535&s)+15*(s>>16)}e=i,t=s},d:function(){return(255&(e%=65521))<<24|e>>>8<<16|(255&(t%=65521))<<8|t>>>8}}}();n.p(e);var i=D(e,t,2,4);return function(e,t){var n=t.level,i=0==n?0:n<6?1:9==n?3:2;e[0]=120,e[1]=i<<6|(i?32-2*i:1)}(i,t),function(e,t,n){for(;n;++t)e[t]=n,n>>>=8}(i,i.length-4,n.d()),i}function U(e,n){return function(e,n,i){var g=e.length;if(!g||i&&i.f&&!i.l)return n||new t(0);var l=!n||i,r=!i||i.i;i||(i={}),n||(n=new t(3*g));var C=function(e){var i=n.length;if(e>i){var s=new t(Math.max(2*i,e));s.set(n),n=s}},h=i.f||0,I=i.p||0,m=i.b||0,u=i.l,b=i.d,p=i.m,Z=i.n,S=8*g;do{if(!u){h=y(e,I,1);var R=y(e,I+1,3);if(I+=3,!R){var T=e[(F=G(I)+4)-4]|e[F-3]<<8,X=F+T;if(X>g){r&&v(0);break}l&&C(m+T),n.set(e.subarray(F,X),m),i.b=m+=T,i.p=I=8*X,i.f=h;continue}if(1==R)u=w,b=V,p=9,Z=5;else if(2==R){var E=y(e,I,31)+257,O=y(e,I+10,15)+4,N=E+y(e,I+5,31)+1;I+=14;for(var B=new t(N),Y=new t(19),K=0;K>>4)<16)B[K++]=F;else{var M=0,j=0;for(16==F?(j=3+y(e,I,3),I+=2,M=B[K-1]):17==F?(j=3+y(e,I,7),I+=3):18==F&&(j=11+y(e,I,127),I+=7);j--;)B[K++]=M}}var Q=B.subarray(0,E),H=B.subarray(E);p=f(Q),Z=f(H),u=A(Q,p,1),b=A(H,Z,1)}else v(1);if(I>S){r&&v(0);break}}l&&C(m+131072);for(var x=(1<>>4;if((I+=15&M)>S){r&&v(0);break}if(M||v(2),_<256)n[m++]=_;else{if(256==_){z=I,u=null;break}var q=_-254;if(_>264){var $=s[K=_-257];q=y(e,I,(1<<$)-1)+c[K],I+=$}var ee=b[W(e,I)&P],te=ee>>>4;if(ee||v(3),I+=15&ee,H=d[te],te>3&&($=a[te],H+=W(e,I)&(1<<$)-1,I+=$),I>S){r&&v(0);break}l&&C(m+131072);for(var ne=m+q;m>>4>7||(i[0]<<8|i[1])%31)&&v(6,"invalid zlib data"),32&i[1]&&v(6,"invalid zlib data: preset dictionaries not supported"),e.subarray(2,-4)),n);var i}var M="undefined"!=typeof TextDecoder&&new TextDecoder;try{M.decode(J,{stream:!0}),1}catch(e){}function j(e){if("object"!=typeof e||null===e)throw new Error("Failed to parse options dataChannels. Options dataChannels element must be type 'object'");const t=e,n={};return"string"==typeof t.label&&(n.label=t.label),"string"==typeof t.direction&&(n.direction=t.direction),"boolean"==typeof t.ordered&&(n.ordered=t.ordered),"boolean"==typeof t.compress&&(n.compress=t.compress),"number"==typeof t.maxPacketLifeTime&&(n.max_packet_life_time=t.maxPacketLifeTime),"number"==typeof t.maxRetransmits&&(n.max_retransmits=t.maxRetransmits),"string"==typeof t.protocol&&(n.protocol=t.protocol),n}function Q(){return"safari"===function(){const e=window.navigator.userAgent.toLocaleLowerCase();return-1!==e.indexOf("edge")?"edge":-1!==e.indexOf("chrome")&&-1===e.indexOf("edge")?"chrome":-1!==e.indexOf("safari")&&-1===e.indexOf("chrome")?"safari":-1!==e.indexOf("opera")?"opera":-1!==e.indexOf("firefox")?"firefox":null}()}function H(e,t,n,i,s,a){if("sendrecv"!==t&&"sendonly"!==t&&"recvonly"!==t)throw new Error("Unknown role type");if(null==n)throw new Error("channelId can not be null or undefined");const o={type:"connect",sora_client:"Sora JavaScript SDK 2021.2.2",environment:window.navigator.userAgent,role:t,channel_id:n,sdp:e,audio:!0,video:!0};if(void 0!==i&&(o.metadata=i),a&&(o.redirect=!0),"signalingNotifyMetadata"in s&&(o.signaling_notify_metadata=s.signalingNotifyMetadata),"multistream"in s&&!0===s.multistream&&(o.multistream=!0,"spotlight"in s&&(o.spotlight=s.spotlight,"spotlightNumber"in s&&(o.spotlight_number=s.spotlightNumber)),!0===o.spotlight)){const e=["none","r0","r1","r2"];void 0!==s.spotlightFocusRid&&0<=e.indexOf(s.spotlightFocusRid)&&(o.spotlight_focus_rid=s.spotlightFocusRid),void 0!==s.spotlightUnfocusRid&&0<=e.indexOf(s.spotlightUnfocusRid)&&(o.spotlight_unfocus_rid=s.spotlightUnfocusRid)}if("simulcast"in s||"simulcastRid"in s){"simulcast"in s&&!0===s.simulcast&&(o.simulcast=!0);const e=["r0","r1","r2"];void 0!==s.simulcastRid&&0<=e.indexOf(s.simulcastRid)&&(o.simulcast_rid=s.simulcastRid)}"clientId"in s&&void 0!==s.clientId&&(o.client_id=s.clientId),"dataChannelSignaling"in s&&"boolean"==typeof s.dataChannelSignaling&&(o.data_channel_signaling=s.dataChannelSignaling),"ignoreDisconnectWebSocket"in s&&"boolean"==typeof s.ignoreDisconnectWebSocket&&(o.ignore_disconnect_websocket=s.ignoreDisconnectWebSocket);const g=["audioCodecType","audioBitRate"],l=["audioOpusParamsChannels","audioOpusParamsClockRate","audioOpusParamsMaxplaybackrate","audioOpusParamsStereo","audioOpusParamsSpropStereo","audioOpusParamsMinptime","audioOpusParamsPtime","audioOpusParamsUseinbandfec","audioOpusParamsUsedtx"],c=["videoCodecType","videoBitRate"],r=Object.assign({},s);Object.keys(r).forEach((e=>{"audio"===e&&"boolean"==typeof r[e]||"video"===e&&"boolean"==typeof r[e]||0<=g.indexOf(e)&&null!==r[e]||0<=l.indexOf(e)&&null!==r[e]||0<=c.indexOf(e)&&null!==r[e]||delete r[e]})),void 0!==r.audio&&(o.audio=r.audio);const C=Object.keys(r).some((e=>0<=g.indexOf(e)));o.audio&&C&&(o.audio={},"audioCodecType"in r&&(o.audio.codec_type=r.audioCodecType),"audioBitRate"in r&&(o.audio.bit_rate=r.audioBitRate));const d=Object.keys(r).some((e=>0<=l.indexOf(e)));o.audio&&d&&("object"!=typeof o.audio&&(o.audio={}),o.audio.opus_params={},"audioOpusParamsChannels"in r&&(o.audio.opus_params.channels=r.audioOpusParamsChannels),"audioOpusParamsClockRate"in r&&(o.audio.opus_params.clock_rate=r.audioOpusParamsClockRate),"audioOpusParamsMaxplaybackrate"in r&&(o.audio.opus_params.maxplaybackrate=r.audioOpusParamsMaxplaybackrate),"audioOpusParamsStereo"in r&&(o.audio.opus_params.stereo=r.audioOpusParamsStereo),"audioOpusParamsSpropStereo"in r&&(o.audio.opus_params.sprop_stereo=r.audioOpusParamsSpropStereo),"audioOpusParamsMinptime"in r&&(o.audio.opus_params.minptime=r.audioOpusParamsMinptime),"audioOpusParamsPtime"in r&&(o.audio.opus_params.ptime=r.audioOpusParamsPtime),"audioOpusParamsUseinbandfec"in r&&(o.audio.opus_params.useinbandfec=r.audioOpusParamsUseinbandfec),"audioOpusParamsUsedtx"in r&&(o.audio.opus_params.usedtx=r.audioOpusParamsUsedtx)),void 0!==r.video&&(o.video=r.video);const h=Object.keys(r).some((e=>0<=c.indexOf(e)));if(o.video&&h&&(o.video={},"videoCodecType"in r&&(o.video.codec_type=r.videoCodecType),"videoBitRate"in r&&(o.video.bit_rate=r.videoBitRate)),o.simulcast&&!function(){if(!window.RTCRtpSender)return!1;if(!RTCRtpSender.getCapabilities)return!1;const e=RTCRtpSender.getCapabilities("video");if(!e)return!1;const t=e.headerExtensions.map((e=>e.uri));return["urn:ietf:params:rtp-hdrext:sdes:mid","urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"].every((e=>t.includes(e)))}()&&"recvonly"!==t)throw new Error("Simulcast can not be used with this browser");if(!0===s.e2ee){if(void 0===o.signaling_notify_metadata&&(o.signaling_notify_metadata={}),null===o.signaling_notify_metadata||"object"!=typeof o.signaling_notify_metadata)throw new Error("E2EE failed. Options signalingNotifyMetadata must be type 'object'");!0===o.video&&(o.video={}),o.video&&(o.video.codec_type="VP8"),o.e2ee=!0}return Array.isArray(s.dataChannels)&&0{},push:()=>{},addstream:()=>{},track:()=>{},removestream:()=>{},removetrack:()=>{},notify:()=>{},log:()=>{},timeout:()=>{},timeline:()=>{},signaling:()=>{},message:()=>{},datachannel:()=>{}},this.authMetadata=null,this.e2ee=null,this.connectionTimeoutTimerId=0,this.monitorSignalingWebSocketEventTimerId=0,this.monitorIceConnectionStateChangeTimerId=0,this.soraDataChannels={},this.mids={audio:"",video:""},this.signalingSwitched=!1,this.signalingOfferMessageDataChannels={}}on(e,t){"addstream"===e?console.warn("@deprecated addstream callback will be removed in a future version. Use track callback."):"removestream"===e&&console.warn("@deprecated removestream callback will be removed in a future version. Use removetrack callback."),e in this.callbacks&&(this.callbacks[e]=t)}stopAudioTrack(e){for(const t of e.getAudioTracks())t.enabled=!1;return new Promise((t=>{setTimeout((async()=>{for(const t of e.getAudioTracks())if(t.stop(),e.removeTrack(t),null!==this.pc){const e=this.pc.getSenders().find((e=>e.track&&e.track.id===t.id));e&&await e.replaceTrack(null)}t()}),100)}))}stopVideoTrack(e){for(const t of e.getVideoTracks())t.enabled=!1;return new Promise((t=>{setTimeout((async()=>{for(const t of e.getVideoTracks())if(t.stop(),e.removeTrack(t),null!==this.pc){const e=this.pc.getSenders().find((e=>e.track&&e.track.id===t.id));e&&await e.replaceTrack(null)}t()}),100)}))}async replaceAudioTrack(e,t){await this.stopAudioTrack(e);const n=this.getAudioTransceiver();if(null===n)throw new Error("Unable to set an audio track. Audio track sender is undefined");e.addTrack(t),await n.sender.replaceTrack(t)}async replaceVideoTrack(e,t){await this.stopVideoTrack(e);const n=this.getVideoTransceiver();if(null===n)throw new Error("Unable to set video track. Video track sender is undefined");e.addTrack(t),await n.sender.replaceTrack(t)}stopStream(){return new Promise(((e,t)=>(this.debug&&console.warn("@deprecated closing MediaStream in disconnect will be removed in a future version. Close every track in the MediaStream by yourself."),this.stream?(this.stream.getTracks().forEach((e=>{e.stop()})),this.stream=null,e()):e())))}async signalingTerminate(){await this.stopStream();for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&t.close(),delete this.soraDataChannels[e]}this.ws&&(this.ws.close(),this.ws=null),this.pc&&this.pc.close(),this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection()}async abendPeerConnectionState(e){this.clearMonitorIceConnectionStateChange(),await this.stopStream(),this.pc&&(this.pc.ondatachannel=null,this.pc.oniceconnectionstatechange=null,this.pc.onicegatheringstatechange=null,this.pc.onconnectionstatechange=null),this.ws&&(this.ws.onclose=e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason})},this.ws.onmessage=null,this.ws.onerror=null);for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onclose=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label)},t.onmessage=null,t.onerror=null)}for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&t.close(),delete this.soraDataChannels[e]}this.ws&&(this.ws.close(),this.ws=null),this.pc&&this.pc.close(),this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection();const t=this.soraCloseEvent("abend",e);this.callbacks.disconnect(t),this.writeSoraTimelineLog("disconnect-abend",t)}async abend(e,t){this.clearMonitorIceConnectionStateChange(),await this.stopStream(),this.pc&&(this.pc.ondatachannel=null,this.pc.oniceconnectionstatechange=null,this.pc.onicegatheringstatechange=null,this.pc.onconnectionstatechange=null),this.ws&&(this.ws.onclose=e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason})},this.ws.onmessage=null,this.ws.onerror=null);for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onclose=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label)},t.onmessage=null,t.onerror=null)}if(this.soraDataChannels.signaling){const t={type:"disconnect",reason:e};if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const e=F((new TextEncoder).encode(JSON.stringify(t)),{});if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(e),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,t)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}else if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(JSON.stringify(t)),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,t)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onerror=null,t.close()),delete this.soraDataChannels[e]}if(await this.disconnectWebSocket(e),await this.disconnectPeerConnection(),this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection(),"WEBSOCKET-ONCLOSE"===e&&t&&(1e3===t.code||1005===t.code)){const e=this.soraCloseEvent("normal","DISCONNECT",t);return this.writeSoraTimelineLog("disconnect-normal",e),void this.callbacks.disconnect(e)}const n=this.soraCloseEvent("abend",e,t);this.writeSoraTimelineLog("disconnect-abend",n),this.callbacks.disconnect(this.soraCloseEvent("abend",e,t))}initializeConnection(){this.clientId=null,this.connectionId=null,this.remoteConnectionIds=[],this.stream=null,this.ws=null,this.pc=null,this.encodings=[],this.authMetadata=null,this.e2ee=null,this.soraDataChannels={},this.mids={audio:"",video:""},this.signalingSwitched=!1,this.signalingOfferMessageDataChannels={},this.clearConnectionTimeout()}disconnectWebSocket(e){let t=0;return this.signalingSwitched?(this.ws&&(this.ws.close(),this.ws=null),Promise.resolve(null)):new Promise(((n,i)=>{if(!this.ws)return n(null);if(this.ws.onclose=e=>(this.ws&&(this.ws.close(),this.ws=null),clearTimeout(t),this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason}),n({code:e.code,reason:e.reason})),1!==this.ws.readyState)return this.ws.close(),this.ws=null,n(null);{const i={type:"disconnect",reason:e};this.ws.send(JSON.stringify(i)),this.writeWebSocketSignalingLog("send-disconnect",i),t=setTimeout((()=>{this.ws&&(this.ws.close(),this.ws=null),n({code:1006,reason:""})}),this.disconnectWaitTimeout)}}))}disconnectDataChannel(){const e=()=>{for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onerror=null,t.close()),delete this.soraDataChannels[e]}};return new Promise(((t,n)=>{if(!this.soraDataChannels.signaling)return e(),t({code:4999,reason:""});const i=setTimeout((()=>(e(),n())),this.disconnectWaitTimeout),s=[];for(const n of Object.keys(this.soraDataChannels)){const a=this.soraDataChannels[n];if(a){a.onerror=()=>(clearTimeout(i),e(),t({code:4999,reason:""}));const n=()=>new Promise(((e,t)=>{let n=0;const i=setInterval((()=>{n++,"closed"===a.readyState&&(clearInterval(i),e()),this.disconnectWaitTimeout<100*n&&(e(),clearInterval(i))}),100)}));s.push(n())}}Promise.all(s).then((()=>{0===Object.keys(this.soraDataChannels).length?t(null):t({code:4999,reason:""})})).finally((()=>{e(),clearTimeout(i)}));const a={type:"disconnect",reason:"NO-ERROR"};if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const e=F((new TextEncoder).encode(JSON.stringify(a)),{});if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(e),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,a)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}else if("open"===this.soraDataChannels.signaling.readyState)try{this.soraDataChannels.signaling.send(JSON.stringify(a)),this.writeDataChannelSignalingLog("send-disconnect",this.soraDataChannels.signaling,a)}catch(e){const t=e.message;this.writeDataChannelSignalingLog("failed-to-send-disconnect",this.soraDataChannels.signaling,t)}}))}disconnectPeerConnection(){return new Promise(((e,t)=>(this.pc&&"closed"!==this.pc.connectionState&&this.pc.close(),e())))}async disconnect(){this.clearMonitorIceConnectionStateChange(),await this.stopStream(),this.pc&&(this.pc.ondatachannel=null,this.pc.oniceconnectionstatechange=null,this.pc.onicegatheringstatechange=null,this.pc.onconnectionstatechange=null),this.ws&&(this.ws.onclose=e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason})},this.ws.onmessage=null,this.ws.onerror=null);for(const e of Object.keys(this.soraDataChannels)){const t=this.soraDataChannels[e];t&&(t.onmessage=null,t.onclose=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label)})}let e=null;if(this.signalingSwitched){try{const t=await this.disconnectDataChannel();null!==t&&(e=this.soraCloseEvent("normal","DISCONNECT",t))}catch(t){e=this.soraCloseEvent("abend","DISCONNECT-TIMEOUT")}await this.disconnectWebSocket("NO-ERROR"),await this.disconnectPeerConnection()}else{const t=await this.disconnectWebSocket("NO-ERROR");await this.disconnectPeerConnection(),null!==t&&(e=this.soraCloseEvent("normal","DISCONNECT",t))}this.e2ee&&this.e2ee.terminateWorker(),this.initializeConnection(),e&&("abend"===e.type?this.writeSoraTimelineLog("disconnect-abend",e):"normal"===e.type&&this.writeSoraTimelineLog("disconnect-normal",e),this.callbacks.disconnect(e))}setupE2EE(){!0===this.options.e2ee&&(this.e2ee=new e,this.e2ee.onWorkerDisconnect=async()=>{await this.abend("INTERNAL-ERROR",{reason:"CRASH-E2EE-WORKER"})},this.e2ee.startWorker())}startE2EE(){if(!0===this.options.e2ee&&this.e2ee){if(!this.connectionId){const e=new Error;throw e.message="E2EE failed. Self connectionId is null",e}this.e2ee.clearWorker();const e=this.e2ee.start(this.connectionId);this.e2ee.postSelfSecretKeyMaterial(this.connectionId,e.selfKeyId,e.selfSecretKeyMaterial)}}async getSignalingWebSocket(e){if("string"==typeof e){const t=e;return new Promise(((e,n)=>{const i=new WebSocket(t);i.onclose=e=>{const t=new z(`Signaling failed. CloseEventCode:${e.code} CloseEventReason:'${e.reason}'`);t.code=e.code,t.reason=e.reason,this.writeWebSocketTimelineLog("onclose",t),n(t)},i.onopen=t=>{e(i)}}))}if(Array.isArray(e)){let t=!1;const n=e=>new Promise(((n,i)=>{const s=new WebSocket(e),a=setTimeout((()=>{this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"timeout",url:s.url}),s&&!t&&(s.onclose=null,s.onerror=null,s.onopen=null,s.close(),i())}),this.signalingCandidateTimeout);s.onclose=e=>{this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"close",url:s.url,message:"WebSocket closed",code:e.code,reason:e.reason}),s&&s.close(),clearInterval(a),i()},s.onerror=e=>{this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"error",url:s.url,message:"Failed to connect WebSocket"}),s&&(s.onclose=null,s.close()),clearInterval(a),i()},s.onopen=e=>{s&&(clearInterval(a),t?(this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"open",url:s.url,selected:!1}),s.onerror=null,s.onclose=null,s.onopen=null,s.close(),i()):(this.writeWebSocketSignalingLog("signaling-url-canidate",{type:"open",url:s.url,selected:!0}),s.onerror=null,s.onclose=null,s.onopen=null,t=!0,n(s)))}}));try{return await Promise.any(e.map((e=>n(e))))}catch(e){throw new z("Signaling failed. All signaling URL candidates failed to connect")}}throw new z("Signaling failed. Invalid format signaling URL candidates")}async signaling(e,t=!1){const n=await this.createOffer();return this.trace("CREATE OFFER",n),new Promise(((i,s)=>{this.writeWebSocketSignalingLog("new-websocket",e.url),e.binaryType="arraybuffer",e.onclose=async e=>{const t=new z(`Signaling failed. CloseEventCode:${e.code} CloseEventReason:'${e.reason}'`);t.code=e.code,t.reason=e.reason,this.writeWebSocketTimelineLog("onclose",t),await this.signalingTerminate(),s(t)},e.onmessage=async e=>{if(e.data instanceof ArrayBuffer)return this.writeWebSocketSignalingLog("onmessage-e2ee",e.data),void this.signalingOnMessageE2EE(e.data);const t=JSON.parse(e.data);if("offer"==t.type)this.writeWebSocketSignalingLog("onmessage-offer",t),this.signalingOnMessageTypeOffer(t),i(t);else if("update"==t.type)this.writeWebSocketSignalingLog("onmessage-update",t),await this.signalingOnMessageTypeUpdate(t);else if("re-offer"==t.type)this.writeWebSocketSignalingLog("onmessage-re-offer",t),await this.signalingOnMessageTypeReOffer(t);else if("ping"==t.type)await this.signalingOnMessageTypePing(t);else if("push"==t.type)this.callbacks.push(t,"websocket");else if("notify"==t.type)"connection.created"===t.event_type?this.writeWebSocketTimelineLog("notify-connection.created",t):"connection.destroyed"===t.event_type&&this.writeWebSocketTimelineLog("notify-connection.destroyed",t),this.signalingOnMessageTypeNotify(t,"websocket");else if("switched"==t.type)this.writeWebSocketSignalingLog("onmessage-switched",t),this.signalingOnMessageTypeSwitched(t);else if("redirect"==t.type){this.writeWebSocketSignalingLog("onmessage-redirect",t);try{const e=await this.signalingOnMessageTypeRedirect(t);i(e)}catch(e){s(e)}}},(async()=>{let i;try{i=H(n.sdp||"",this.role,this.channelId,this.metadata,this.options,t)}catch(e){return void s(e)}if(i.e2ee&&this.e2ee){const e=await this.e2ee.init();i.signaling_notify_metadata.pre_key_bundle=e}this.trace("SIGNALING CONNECT MESSAGE",i),e&&(e.send(JSON.stringify(i)),this.writeWebSocketSignalingLog(`send-${i.type}`,i),this.ws=e)})()}))}async connectPeerConnection(e){let t=Object.assign({},e.config);if(this.e2ee&&(t=Object.assign({encodedInsertableStreams:!0},t)),void 0!==window.RTCPeerConnection.generateCertificate){const e=await window.RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"});t=Object.assign({certificates:[e]},t)}this.trace("PEER CONNECTION CONFIG",t),this.writePeerConnectionTimelineLog("new-peerconnection",t),this.pc=new window.RTCPeerConnection(t,this.constraints),this.pc.oniceconnectionstatechange=e=>{this.pc&&(this.writePeerConnectionTimelineLog("oniceconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),this.trace("ONICECONNECTIONSTATECHANGE ICECONNECTIONSTATE",this.pc.iceConnectionState))},this.pc.onicegatheringstatechange=e=>{this.pc&&this.writePeerConnectionTimelineLog("onicegatheringstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState})},this.pc.onconnectionstatechange=e=>{this.pc&&this.writePeerConnectionTimelineLog("onconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState})},this.pc.ondatachannel=e=>{this.onDataChannel(e)}}async setRemoteDescription(e){if(!this.pc)return;const t=new RTCSessionDescription({type:"offer",sdp:e.sdp});await this.pc.setRemoteDescription(t),this.writePeerConnectionTimelineLog("set-remote-description",t)}async createAnswer(e){if(!this.pc)return;for(const e of Object.values(this.mids)){const t=this.pc.getTransceivers().find((t=>t.mid===e));t&&"recvonly"===t.direction&&(t.direction="sendrecv")}if(this.options.simulcast&&("sendrecv"===this.role||"sendonly"===this.role)){const t=this.pc.getTransceivers().find((e=>{if(null!==e.mid&&null!==e.sender.track&&(null===e.currentDirection||"sendonly"===e.currentDirection))return""!==this.mids.video&&this.mids.video===e.mid||0<=e.mid.indexOf("video")?e:void 0}));if(t){await this.setSenderParameters(t,this.encodings),await this.setRemoteDescription(e),this.trace("TRANSCEIVER SENDER GET_PARAMETERS",t.sender.getParameters()),await this.setSenderParameters(t,this.encodings);const n=await this.pc.createAnswer();return await this.pc.setLocalDescription(n),void this.trace("TRANSCEIVER SENDER GET_PARAMETERS",t.sender.getParameters())}}const t=await this.pc.createAnswer();this.writePeerConnectionTimelineLog("create-answer",t),await this.pc.setLocalDescription(t),this.writePeerConnectionTimelineLog("set-local-description",t)}sendAnswer(){if(this.pc&&this.ws&&this.pc.localDescription){this.trace("ANSWER SDP",this.pc.localDescription.sdp);const e={type:"answer",sdp:this.pc.localDescription.sdp};this.ws.send(JSON.stringify(e)),this.writeWebSocketSignalingLog("send-answer",e)}}onIceCandidate(){return new Promise(((e,t)=>{this.pc&&(this.pc.oniceconnectionstatechange=t=>{this.pc&&(this.writePeerConnectionTimelineLog("oniceconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),this.trace("ONICECONNECTIONSTATECHANGE ICECONNECTIONSTATE",this.pc.iceConnectionState),"connected"===this.pc.iceConnectionState&&e())},this.pc.onicecandidate=t=>{if(this.writePeerConnectionTimelineLog("onicecandidate",t.candidate),this.pc&&this.trace("ONICECANDIDATE ICEGATHERINGSTATE",this.pc.iceGatheringState),null===t.candidate)e();else{const e=t.candidate.toJSON(),n=Object.assign(e,{type:"candidate"});this.trace("ONICECANDIDATE CANDIDATE MESSAGE",n),this.sendSignalingMessage(n)}})}))}waitChangeConnectionStateConnected(){return new Promise(((e,t)=>{if(this.pc&&void 0===this.pc.connectionState)return void e();const n=setInterval((()=>{if(this.pc)this.pc&&"connected"===this.pc.connectionState&&(clearInterval(n),e());else{const e=new Error;e.message="PeerConnection connectionState did not change to 'connected'",clearInterval(n),t(e)}}),10)}))}monitorSignalingWebSocketEvent(){return new Promise(((e,t)=>{this.monitorSignalingWebSocketEventTimerId=setInterval((()=>{this.ws&&(this.clearMonitorSignalingWebSocketEvent(),this.ws.onclose=async e=>{const n=new z(`Signaling failed. CloseEventCode:${e.code} CloseEventReason:'${e.reason}'`);n.code=e.code,n.reason=e.reason,this.writeWebSocketTimelineLog("onclose",n),await this.signalingTerminate(),t(n)},this.ws.onerror=async e=>{const n=new z("Signaling failed. WebSocket onerror was called");this.writeWebSocketSignalingLog("onerror",n),await this.signalingTerminate(),t(n)})}),100)}))}monitorWebSocketEvent(){this.ws&&(this.ws.onclose=async e=>{this.writeWebSocketTimelineLog("onclose",{code:e.code,reason:e.reason}),await this.abend("WEBSOCKET-ONCLOSE",{code:e.code,reason:e.reason})},this.ws.onerror=async e=>{this.writeWebSocketSignalingLog("onerror"),await this.abend("WEBSOCKET-ONERROR")})}monitorPeerConnectionState(){this.pc&&(this.pc.oniceconnectionstatechange=async e=>{this.pc&&void 0===this.pc.connectionState&&(this.writePeerConnectionTimelineLog("oniceconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),this.trace("ONICECONNECTIONSTATECHANGE ICECONNECTIONSTATE",this.pc.iceConnectionState),clearTimeout(this.monitorIceConnectionStateChangeTimerId),"failed"===this.pc.iceConnectionState?await this.abendPeerConnectionState("ICE-CONNECTION-STATE-FAILED"):"disconnected"===this.pc.iceConnectionState&&(this.monitorIceConnectionStateChangeTimerId=setTimeout((async()=>{this.pc&&"disconnected"===this.pc.iceConnectionState&&await this.abendPeerConnectionState("ICE-CONNECTION-STATE-DISCONNECTED-TIMEOUT")}),1e4)))},this.pc.onconnectionstatechange=async e=>{this.pc&&(this.writePeerConnectionTimelineLog("onconnectionstatechange",{connectionState:this.pc.connectionState,iceConnectionState:this.pc.iceConnectionState,iceGatheringState:this.pc.iceGatheringState}),"failed"===this.pc.connectionState&&await this.abendPeerConnectionState("CONNECTION-STATE-FAILED"))})}setConnectionTimeout(){return new Promise(((e,t)=>{0{if(!this.pc||this.pc&&void 0!==this.pc.connectionState&&"connected"!==this.pc.connectionState){const e=new Error;e.message="Signaling connection timeout",this.callbacks.timeout(),this.trace("DISCONNECT","Signaling connection timeout"),this.writePeerConnectionTimelineLog("signaling-connection-timeout",{connectionTimeout:this.connectionTimeout}),await this.signalingTerminate(),t(e)}}),this.connectionTimeout))}))}clearConnectionTimeout(){clearTimeout(this.connectionTimeoutTimerId)}clearMonitorSignalingWebSocketEvent(){clearInterval(this.monitorSignalingWebSocketEventTimerId)}clearMonitorIceConnectionStateChange(){clearInterval(this.monitorIceConnectionStateChangeTimerId)}trace(e,t){this.callbacks.log(e,t),this.debug&&function(e,t,n){const i=e=>{if(e&&"object"==typeof e){let t=null;try{t=Object.keys(JSON.parse(JSON.stringify(e)))}catch(e){}t&&Array.isArray(t)?t.forEach((t=>{console.group(t),i(e[t]),console.groupEnd()})):console.info(e)}else console.info(e)};let s="";window.performance&&(s="["+(window.performance.now()/1e3).toFixed(3)+"]"),e&&(s=s+"["+e+"]"),void 0!==console.info&&void 0!==console.group?(console.group(s+" "+t),i(n),console.groupEnd()):console.log(s+" "+t+"\n",n)}(this.clientId,e,t)}writeWebSocketSignalingLog(e,t){this.callbacks.signaling(_(e,t,"websocket")),this.writeWebSocketTimelineLog(e,t)}writeDataChannelSignalingLog(e,t,n){this.callbacks.signaling(_(e,n,"datachannel")),this.writeDataChannelTimelineLog(e,t,n)}writeWebSocketTimelineLog(e,t){const n=q(e,t,"websocket");this.callbacks.timeline(n)}writeDataChannelTimelineLog(e,t,n){const i=q(e,n,"datachannel",t.id,t.label);this.callbacks.timeline(i)}writePeerConnectionTimelineLog(e,t){const n=q(e,t,"peerconnection");this.callbacks.timeline(n)}writeSoraTimelineLog(e,t){const n=q(e,t,"sora");this.callbacks.timeline(n)}async createOffer(){const e=new window.RTCPeerConnection({iceServers:[]});if(Q()){e.addTransceiver("video",{direction:"recvonly"}),e.addTransceiver("audio",{direction:"recvonly"});const t=await e.createOffer();return e.close(),this.writePeerConnectionTimelineLog("create-offer",t),t}const t=await e.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0});return e.close(),this.writePeerConnectionTimelineLog("create-offer",t),t}signalingOnMessageE2EE(e){if(this.e2ee){const t=new Uint8Array(e),n=this.e2ee.receiveMessage(t);this.e2ee.postRemoteSecretKeyMaterials(n),n.messages.forEach((e=>{this.sendE2EEMessage(e.buffer)}))}}signalingOnMessageTypeOffer(e){if(this.clientId=e.client_id,this.connectionId=e.connection_id,void 0!==e.metadata&&(this.authMetadata=e.metadata),Array.isArray(e.encodings)&&(this.encodings=e.encodings),void 0!==e.mid&&void 0!==e.mid.audio&&(this.mids.audio=e.mid.audio),void 0!==e.mid&&void 0!==e.mid.video&&(this.mids.video=e.mid.video),e.data_channels)for(const t of e.data_channels)this.signalingOfferMessageDataChannels[t.label]=t;this.trace("SIGNALING OFFER MESSAGE",e),this.trace("OFFER SDP",e.sdp)}sendUpdateAnswer(){this.pc&&this.ws&&this.pc.localDescription&&(this.trace("ANSWER SDP",this.pc.localDescription.sdp),this.sendSignalingMessage({type:"update",sdp:this.pc.localDescription.sdp}))}sendReAnswer(){this.pc&&this.pc.localDescription&&(this.trace("RE ANSWER SDP",this.pc.localDescription.sdp),this.sendSignalingMessage({type:"re-answer",sdp:this.pc.localDescription.sdp}))}async signalingOnMessageTypeUpdate(e){this.trace("SIGNALING UPDATE MESSGE",e),this.trace("UPDATE SDP",e.sdp),await this.setRemoteDescription(e),await this.createAnswer(e),this.sendUpdateAnswer()}async signalingOnMessageTypeReOffer(e){this.trace("SIGNALING RE OFFER MESSGE",e),this.trace("RE OFFER SDP",e.sdp),await this.setRemoteDescription(e),await this.createAnswer(e),this.sendReAnswer()}async signalingOnMessageTypePing(e){const t={type:"pong"};if(e.stats){const e=await this.getStats();t.stats=e}this.ws&&this.ws.send(JSON.stringify(t))}signalingOnMessageTypeNotify(e,t){if("connection.created"===e.event_type){const t=e.connection_id;if(this.connectionId!==t){const n=P(x(e));if(n&&this.e2ee&&t){const e=this.e2ee.startSession(t,n);this.e2ee.postRemoteSecretKeyMaterials(e),e.messages.forEach((e=>{this.sendE2EEMessage(e.buffer)})),this.e2ee.postSelfSecretKeyMaterial(e.selfConnectionId,e.selfKeyId,e.selfSecretKeyMaterial)}}const n=function(e){return e.data&&Array.isArray(e.data)?e.data:e.metadata_list&&Array.isArray(e.metadata_list)?e.metadata_list:[]}(e);n.forEach((e=>{const t=P(x(e)),n=e.connection_id;n&&this.e2ee&&t&&this.e2ee.addPreKeyBundle(n,t)}))}else if("connection.destroyed"===e.event_type){const t=P(x(e)),n=e.connection_id;if(t&&this.e2ee&&n){const e=this.e2ee.stopSession(n);this.e2ee.postSelfSecretKeyMaterial(e.selfConnectionId,e.selfKeyId,e.selfSecretKeyMaterial,5e3),e.messages.forEach((e=>{this.sendE2EEMessage(e.buffer)})),this.e2ee.postRemoveRemoteDeriveKey(n)}}this.callbacks.notify(e,t)}signalingOnMessageTypeSwitched(e){if(this.signalingSwitched=!0,this.ws){e.ignore_disconnect_websocket&&(this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null),this.writeWebSocketSignalingLog("close"));for(const e of this.datachannels)this.callbacks.datachannel($(e))}}async signalingOnMessageTypeRedirect(e){this.ws&&(this.ws.onclose=null,this.ws.onerror=null,this.ws.close(),this.ws=null);const t=await this.getSignalingWebSocket(e.location);return await this.signaling(t,!0)}async setSenderParameters(e,t){const n=e.sender.getParameters();n.encodings=t,await e.sender.setParameters(n),this.trace("TRANSCEIVER SENDER SET_PARAMETERS",n),this.writePeerConnectionTimelineLog("transceiver-sender-set-parameters",n)}async getStats(){const e=[];if(!this.pc)return e;return(await this.pc.getStats()).forEach((t=>{e.push(t)})),e}onDataChannel(e){const t=e.channel;var n;this.writeDataChannelTimelineLog("ondatachannel",t,{binaryType:(n=t).binaryType,bufferedAmount:n.bufferedAmount,bufferedAmountLowThreshold:n.bufferedAmountLowThreshold,id:n.id,label:n.label,maxPacketLifeTime:n.maxPacketLifeTime,maxRetransmits:n.maxRetransmits,negotiated:n.negotiated,ordered:n.ordered,protocol:n.protocol,readyState:n.readyState,reliable:n.reliable}),e.channel.onbufferedamountlow=e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onbufferedamountlow",t)},e.channel.onopen=e=>{const t=e.currentTarget;t.bufferedAmountLowThreshold=65536,t.binaryType="arraybuffer",this.soraDataChannels[t.label]=t,this.trace("OPEN DATA CHANNEL",t.label),"signaling"===t.label&&this.ws?this.writeDataChannelSignalingLog("onopen",t):this.writeDataChannelTimelineLog("onopen",t)},e.channel.onclose=async e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onclose",t),this.trace("CLOSE DATA CHANNEL",t.label),await this.disconnect()},e.channel.onerror=async e=>{const t=e.currentTarget;this.writeDataChannelTimelineLog("onerror",t),this.trace("ERROR DATA CHANNEL",t.label),await this.abend("DATA-CHANNEL-ONERROR",{params:{label:t.label}})},"signaling"===e.channel.label?e.channel.onmessage=async e=>{const t=e.currentTarget;let n=e.data;if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const t=U(new Uint8Array(e.data));n=(new TextDecoder).decode(t)}const i=JSON.parse(n);this.writeDataChannelSignalingLog(`onmessage-${i.type}`,t,i),"re-offer"===i.type&&await this.signalingOnMessageTypeReOffer(i)}:"notify"===e.channel.label?e.channel.onmessage=e=>{const t=e.currentTarget;let n=e.data;if(this.signalingOfferMessageDataChannels.notify&&!0===this.signalingOfferMessageDataChannels.notify.compress){const t=U(new Uint8Array(e.data));n=(new TextDecoder).decode(t)}const i=JSON.parse(n);"connection.created"===i.event_type?this.writeDataChannelTimelineLog("notify-connection.created",t,i):"connection.destroyed"===i.event_type&&this.writeDataChannelTimelineLog("notify-connection.destroyed",t,i),this.signalingOnMessageTypeNotify(i,"datachannel")}:"push"===e.channel.label?e.channel.onmessage=e=>{let t=e.data;if(this.signalingOfferMessageDataChannels.push&&!0===this.signalingOfferMessageDataChannels.push.compress){const n=U(new Uint8Array(e.data));t=(new TextDecoder).decode(n)}const n=JSON.parse(t);this.callbacks.push(n,"datachannel")}:"e2ee"===e.channel.label?e.channel.onmessage=e=>{const t=e.currentTarget,n=e.data;this.signalingOnMessageE2EE(n),this.writeDataChannelSignalingLog("onmessage-e2ee",t,n)}:"stats"===e.channel.label?e.channel.onmessage=async e=>{let t=e.data;if(this.signalingOfferMessageDataChannels.stats&&!0===this.signalingOfferMessageDataChannels.stats.compress){const n=U(new Uint8Array(e.data));t=(new TextDecoder).decode(n)}if("req-stats"===JSON.parse(t).type){const e=await this.getStats();this.sendStatsMessage(e)}}:/^#.*/.exec(e.channel.label)&&(e.channel.onmessage=e=>{if(null===e.target)return;const t=e.target;let n=e.data;const i=this.signalingOfferMessageDataChannels[t.label];void 0!==i&&!0===i.compress&&(n=U(new Uint8Array(e.data)).buffer),this.callbacks.message(function(e,t){const n=new Event("message");return n.label=e,n.data=t,n}(t.label,n))})}sendSignalingMessage(e){if(this.soraDataChannels.signaling){if(this.signalingOfferMessageDataChannels.signaling&&!0===this.signalingOfferMessageDataChannels.signaling.compress){const t=F((new TextEncoder).encode(JSON.stringify(e)),{});this.soraDataChannels.signaling.send(t)}else this.soraDataChannels.signaling.send(JSON.stringify(e));this.writeDataChannelSignalingLog(`send-${e.type}`,this.soraDataChannels.signaling,e)}else null!==this.ws&&(this.ws.send(JSON.stringify(e)),this.writeWebSocketSignalingLog(`send-${e.type}`,e))}sendE2EEMessage(e){this.soraDataChannels.e2ee?(this.soraDataChannels.e2ee.send(e),this.writeDataChannelSignalingLog("send-e2ee",this.soraDataChannels.e2ee,e)):null!==this.ws&&(this.ws.send(e),this.writeWebSocketSignalingLog("send-e2ee",e))}sendStatsMessage(e){if(this.soraDataChannels.stats){const t={type:"stats",reports:e};if(this.signalingOfferMessageDataChannels.stats&&!0===this.signalingOfferMessageDataChannels.stats.compress){const e=F((new TextEncoder).encode(JSON.stringify(t)),{});this.soraDataChannels.stats.send(e)}else this.soraDataChannels.stats.send(JSON.stringify(t))}}getAudioTransceiver(){if(this.pc&&this.mids.audio){return this.pc.getTransceivers().find((e=>e.mid===this.mids.audio))||null}return null}getVideoTransceiver(){if(this.pc&&this.mids.video){return this.pc.getTransceivers().find((e=>e.mid===this.mids.video))||null}return null}soraCloseEvent(e,t,n){const i=class extends Event{constructor(e,t,n){super(e),n&&(n.code&&(this.code=n.code),n.reason&&(this.reason=n.reason),n.params&&(this.params=n.params)),this.title=t}};return new i(e,t,n)}sendMessage(e,t){const n=this.soraDataChannels[e];if(null===this.pc)return;if(void 0===n)throw new Error("Could not find DataChannel");const i=this.signalingOfferMessageDataChannels[e];if(void 0!==i&&!0===i.compress){const e=F(t,{});n.send(e)}else n.send(t)}get e2eeSelfFingerprint(){if(this.options.e2ee&&this.e2ee)return this.e2ee.selfFingerprint()}get e2eeRemoteFingerprints(){if(this.options.e2ee&&this.e2ee)return this.e2ee.remoteFingerprints()}get audio(){return null!==this.getAudioTransceiver()}get video(){return null!==this.getVideoTransceiver()}get signalingUrl(){return this.signalingUrlCandidates}get connectedSignalingUrl(){return this.ws?this.ws.url:""}get datachannels(){if(!this.signalingSwitched)return[];const e=Object.keys(this.signalingOfferMessageDataChannels).filter((e=>/^#.*/.exec(e))),t=[];for(const n of e){const e=this.soraDataChannels[n];if(!e)continue;const i=this.signalingOfferMessageDataChannels[n];if(!i)continue;const s={label:e.label,ordered:e.ordered,protocol:e.protocol,compress:i.compress,direction:i.direction};"number"==typeof e.maxPacketLifeTime&&(s.maxPacketLifeTime=e.maxPacketLifeTime),"number"==typeof e.maxRetransmits&&(s.maxRetransmits=e.maxRetransmits),t.push(s)}return t}}class te extends ee{async connect(e){return this.options.multistream?await Promise.race([this.multiStream(e).finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]):await Promise.race([this.singleStream(e).finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]),this.monitorWebSocketEvent(),this.monitorPeerConnectionState(),e}async singleStream(e){await this.disconnect(),this.setupE2EE();const t=await this.getSignalingWebSocket(this.signalingUrlCandidates),n=await this.signaling(t);return this.startE2EE(),await this.connectPeerConnection(n),await this.setRemoteDescription(n),e.getTracks().forEach((t=>{this.pc&&this.pc.addTrack(t,e)})),this.stream=e,await this.createAnswer(n),this.sendAnswer(),this.pc&&this.e2ee&&this.pc.getSenders().forEach((e=>{this.e2ee&&this.e2ee.setupSenderTransform(e)})),await this.onIceCandidate(),await this.waitChangeConnectionStateConnected(),e}async multiStream(e){await this.disconnect(),this.setupE2EE();const t=await this.getSignalingWebSocket(this.signalingUrlCandidates),n=await this.signaling(t);return this.startE2EE(),await this.connectPeerConnection(n),this.pc&&(this.pc.ontrack=e=>{const t=e.streams[0];if(!t)return;const n={"stream.id":t.id,id:e.track.id,label:e.track.label,enabled:e.track.enabled,kind:e.track.kind,muted:e.track.muted,readyState:e.track.readyState};this.writePeerConnectionTimelineLog("ontrack",n),"default"!==t.id&&t.id!==this.connectionId&&(this.e2ee&&this.e2ee.setupReceiverTransform(e.receiver),this.callbacks.track(e),t.onremovetrack=e=>{if(this.callbacks.removetrack(e),e.target){const t=this.remoteConnectionIds.indexOf(e.target.id);-1{this.pc&&this.pc.addTrack(t,e)})),this.stream=e,await this.createAnswer(n),this.sendAnswer(),this.pc&&this.e2ee&&this.pc.getSenders().forEach((e=>{this.e2ee&&this.e2ee.setupSenderTransform(e)})),await this.onIceCandidate(),await this.waitChangeConnectionStateConnected(),e}}class ne extends ee{async connect(){if(this.options.multistream)return await Promise.race([this.multiStream().finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]),this.monitorWebSocketEvent(),void this.monitorPeerConnectionState();{const e=await Promise.race([this.singleStream().finally((()=>{this.clearConnectionTimeout(),this.clearMonitorSignalingWebSocketEvent()})),this.setConnectionTimeout(),this.monitorSignalingWebSocketEvent()]);return this.monitorWebSocketEvent(),this.monitorPeerConnectionState(),e}}async singleStream(){await this.disconnect(),this.setupE2EE();const e=await this.getSignalingWebSocket(this.signalingUrlCandidates),t=await this.signaling(e);return this.startE2EE(),await this.connectPeerConnection(t),this.pc&&(this.pc.ontrack=e=>{this.stream=e.streams[0];const t=this.stream.id;if("default"===t)return;const n={"stream.id":t,id:e.track.id,label:e.track.label,enabled:e.track.enabled,kind:e.track.kind,muted:e.track.muted,readyState:e.track.readyState};this.writePeerConnectionTimelineLog("ontrack",n),this.e2ee&&this.e2ee.setupReceiverTransform(e.receiver),this.callbacks.track(e),this.stream.onremovetrack=e=>{if(this.callbacks.removetrack(e),e.target){const t=this.remoteConnectionIds.indexOf(e.target.id);-1{const t=e.streams[0];if("default"===t.id)return;if(t.id===this.connectionId)return;const n={"stream.id":t.id,id:e.track.id,label:e.track.label,enabled:e.track.enabled,kind:e.track.kind,muted:e.track.muted,readyState:e.track.readyState};this.writePeerConnectionTimelineLog("ontrack",n),this.e2ee&&this.e2ee.setupReceiverTransform(e.receiver),this.callbacks.track(e),t.onremovetrack=e=>{if(this.callbacks.removetrack(e),e.target){const t=this.remoteConnectionIds.indexOf(e.target.id);-1 {\n const { operation } = event.data;\n if (operation === \"disconnect\" && typeof this.onWorkerDisconnect === \"function\") {\n this.onWorkerDisconnect();\n }\n };\n }\n // worker の掃除をする\n clearWorker() {\n if (this.worker) {\n this.worker.postMessage({\n type: \"clear\",\n });\n }\n }\n // worker を終了する\n terminateWorker() {\n if (this.worker) {\n this.worker.terminate();\n }\n }\n // 初期化処理\n async init() {\n const { preKeyBundle } = await window.e2ee.init();\n return preKeyBundle;\n }\n setupSenderTransform(sender) {\n if (!sender.track) {\n return;\n }\n // @ts-ignore トライアル段階の API なので無視する\n const senderStreams = sender.createEncodedStreams();\n const readableStream = senderStreams.readableStream || senderStreams.readable;\n const writableStream = senderStreams.writableStream || senderStreams.writable;\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n const message = {\n type: \"encrypt\",\n readableStream: readableStream,\n writableStream: writableStream,\n };\n this.worker.postMessage(message, [readableStream, writableStream]);\n }\n setupReceiverTransform(receiver) {\n // @ts-ignore トライアル段階の API なので無視する\n const receiverStreams = receiver.createEncodedStreams();\n const readableStream = receiverStreams.readableStream || receiverStreams.readable;\n const writableStream = receiverStreams.writableStream || receiverStreams.writable;\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n const message = {\n type: \"decrypt\",\n readableStream: readableStream,\n writableStream: writableStream,\n };\n this.worker.postMessage(message, [readableStream, writableStream]);\n }\n postRemoteSecretKeyMaterials(result) {\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n this.worker.postMessage({\n type: \"remoteSecretKeyMaterials\",\n remoteSecretKeyMaterials: result.remoteSecretKeyMaterials,\n });\n }\n postRemoveRemoteDeriveKey(connectionId) {\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n this.worker.postMessage({\n type: \"removeRemoteDeriveKey\",\n connectionId: connectionId,\n });\n }\n postSelfSecretKeyMaterial(selfConnectionId, selfKeyId, selfSecretKeyMaterial, waitingTime = 0) {\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n this.worker.postMessage({\n type: \"selfSecretKeyMaterial\",\n selfConnectionId: selfConnectionId,\n selfKeyId: selfKeyId,\n selfSecretKeyMaterial: selfSecretKeyMaterial,\n waitingTime: waitingTime,\n });\n }\n startSession(connectionId, preKeyBundle) {\n const [result, err] = window.e2ee.startSession(connectionId, preKeyBundle.identityKey, preKeyBundle.signedPreKey, preKeyBundle.preKeySignature);\n if (err) {\n throw err;\n }\n return result;\n }\n stopSession(connectionId) {\n const [result, err] = window.e2ee.stopSession(connectionId);\n if (err) {\n throw err;\n }\n return result;\n }\n receiveMessage(message) {\n const [result, err] = window.e2ee.receiveMessage(message);\n if (err) {\n throw err;\n }\n return result;\n }\n start(selfConnectionId) {\n const [result, err] = window.e2ee.start(selfConnectionId);\n if (err) {\n throw err;\n }\n return result;\n }\n addPreKeyBundle(connectionId, preKeyBundle) {\n const err = window.e2ee.addPreKeyBundle(connectionId, preKeyBundle.identityKey, preKeyBundle.signedPreKey, preKeyBundle.preKeySignature);\n if (err) {\n throw err;\n }\n }\n selfFingerprint() {\n return window.e2ee.selfFingerprint();\n }\n remoteFingerprints() {\n return window.e2ee.remoteFingerprints();\n }\n static async loadWasm(wasmUrl) {\n if (!window.e2ee === undefined) {\n console.warn(\"E2ee wasm is already loaded. Will not be reload.\");\n return;\n }\n WasmExec();\n if (!window.Go) {\n throw new Error(`Failed to load module Go. window.Go is ${window.Go}.`);\n }\n const go = new Go();\n const { instance } = await WebAssembly.instantiateStreaming(fetch(wasmUrl), go.importObject);\n go.run(instance);\n if (!window.e2ee) {\n throw new Error(`Failed to load module e2ee. window.e2ee is ${window.e2ee}.`);\n }\n }\n static version() {\n return \"2021.1.0\";\n }\n static wasmVersion() {\n return window.e2ee.version();\n }\n}\n\nexport { SoraE2EE as default };\n","// Copyright 2018 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\nexport default function () {\n\t(() => {\n\t\t// Map multiple JavaScript environments to a single common API,\n\t\t// preferring web standards over Node.js API.\n\t\t//\n\t\t// Environments considered:\n\t\t// - Browsers\n\t\t// - Node.js\n\t\t// - Electron\n\t\t// - Parcel\n\t\n\t\tif (typeof global !== \"undefined\") {\n\t\t\t// global already exists\n\t\t} else if (typeof window !== \"undefined\") {\n\t\t\twindow.global = window;\n\t\t} else if (typeof self !== \"undefined\") {\n\t\t\tself.global = self;\n\t\t} else {\n\t\t\tthrow new Error(\"cannot export Go (neither global, window nor self is defined)\");\n\t\t}\n\t\n\t\tif (!global.require && typeof require !== \"undefined\") {\n\t\t\tglobal.require = require;\n\t\t}\n\t\n\t\tif (!global.fs && global.require) {\n\t\t\tconst fs = require(\"fs\");\n\t\t\tif (Object.keys(fs) !== 0) {\n\t\t\t\tglobal.fs = fs;\n\t\t\t}\n\t\t}\n\t\n\t\tconst enosys = () => {\n\t\t\tconst err = new Error(\"not implemented\");\n\t\t\terr.code = \"ENOSYS\";\n\t\t\treturn err;\n\t\t};\n\t\n\t\tif (!global.fs) {\n\t\t\tlet outputBuf = \"\";\n\t\t\tglobal.fs = {\n\t\t\t\tconstants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused\n\t\t\t\twriteSync(fd, buf) {\n\t\t\t\t\toutputBuf += decoder.decode(buf);\n\t\t\t\t\tconst nl = outputBuf.lastIndexOf(\"\\n\");\n\t\t\t\t\tif (nl != -1) {\n\t\t\t\t\t\tconsole.log(outputBuf.substr(0, nl));\n\t\t\t\t\t\toutputBuf = outputBuf.substr(nl + 1);\n\t\t\t\t\t}\n\t\t\t\t\treturn buf.length;\n\t\t\t\t},\n\t\t\t\twrite(fd, buf, offset, length, position, callback) {\n\t\t\t\t\tif (offset !== 0 || length !== buf.length || position !== null) {\n\t\t\t\t\t\tcallback(enosys());\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst n = this.writeSync(fd, buf);\n\t\t\t\t\tcallback(null, n);\n\t\t\t\t},\n\t\t\t\tchmod(path, mode, callback) { callback(enosys()); },\n\t\t\t\tchown(path, uid, gid, callback) { callback(enosys()); },\n\t\t\t\tclose(fd, callback) { callback(enosys()); },\n\t\t\t\tfchmod(fd, mode, callback) { callback(enosys()); },\n\t\t\t\tfchown(fd, uid, gid, callback) { callback(enosys()); },\n\t\t\t\tfstat(fd, callback) { callback(enosys()); },\n\t\t\t\tfsync(fd, callback) { callback(null); },\n\t\t\t\tftruncate(fd, length, callback) { callback(enosys()); },\n\t\t\t\tlchown(path, uid, gid, callback) { callback(enosys()); },\n\t\t\t\tlink(path, link, callback) { callback(enosys()); },\n\t\t\t\tlstat(path, callback) { callback(enosys()); },\n\t\t\t\tmkdir(path, perm, callback) { callback(enosys()); },\n\t\t\t\topen(path, flags, mode, callback) { callback(enosys()); },\n\t\t\t\tread(fd, buffer, offset, length, position, callback) { callback(enosys()); },\n\t\t\t\treaddir(path, callback) { callback(enosys()); },\n\t\t\t\treadlink(path, callback) { callback(enosys()); },\n\t\t\t\trename(from, to, callback) { callback(enosys()); },\n\t\t\t\trmdir(path, callback) { callback(enosys()); },\n\t\t\t\tstat(path, callback) { callback(enosys()); },\n\t\t\t\tsymlink(path, link, callback) { callback(enosys()); },\n\t\t\t\ttruncate(path, length, callback) { callback(enosys()); },\n\t\t\t\tunlink(path, callback) { callback(enosys()); },\n\t\t\t\tutimes(path, atime, mtime, callback) { callback(enosys()); },\n\t\t\t};\n\t\t}\n\t\n\t\tif (!global.process) {\n\t\t\tglobal.process = {\n\t\t\t\tgetuid() { return -1; },\n\t\t\t\tgetgid() { return -1; },\n\t\t\t\tgeteuid() { return -1; },\n\t\t\t\tgetegid() { return -1; },\n\t\t\t\tgetgroups() { throw enosys(); },\n\t\t\t\tpid: -1,\n\t\t\t\tppid: -1,\n\t\t\t\tumask() { throw enosys(); },\n\t\t\t\tcwd() { throw enosys(); },\n\t\t\t\tchdir() { throw enosys(); },\n\t\t\t}\n\t\t}\n\t\n\t\tif (!global.crypto) {\n\t\t\tconst nodeCrypto = require(\"crypto\");\n\t\t\tglobal.crypto = {\n\t\t\t\tgetRandomValues(b) {\n\t\t\t\t\tnodeCrypto.randomFillSync(b);\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\n\t\tif (!global.performance) {\n\t\t\tglobal.performance = {\n\t\t\t\tnow() {\n\t\t\t\t\tconst [sec, nsec] = process.hrtime();\n\t\t\t\t\treturn sec * 1000 + nsec / 1000000;\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\n\t\tif (!global.TextEncoder) {\n\t\t\tglobal.TextEncoder = require(\"util\").TextEncoder;\n\t\t}\n\t\n\t\tif (!global.TextDecoder) {\n\t\t\tglobal.TextDecoder = require(\"util\").TextDecoder;\n\t\t}\n\t\n\t\t// End of polyfills for common API.\n\t\n\t\tconst encoder = new TextEncoder(\"utf-8\");\n\t\tconst decoder = new TextDecoder(\"utf-8\");\n\t\n\t\tglobal.Go = class {\n\t\t\tconstructor() {\n\t\t\t\tthis.argv = [\"js\"];\n\t\t\t\tthis.env = {};\n\t\t\t\tthis.exit = (code) => {\n\t\t\t\t\tif (code !== 0) {\n\t\t\t\t\t\tconsole.warn(\"exit code:\", code);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tthis._exitPromise = new Promise((resolve) => {\n\t\t\t\t\tthis._resolveExitPromise = resolve;\n\t\t\t\t});\n\t\t\t\tthis._pendingEvent = null;\n\t\t\t\tthis._scheduledTimeouts = new Map();\n\t\t\t\tthis._nextCallbackTimeoutID = 1;\n\t\n\t\t\t\tconst setInt64 = (addr, v) => {\n\t\t\t\t\tthis.mem.setUint32(addr + 0, v, true);\n\t\t\t\t\tthis.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n\t\t\t\t}\n\t\n\t\t\t\tconst getInt64 = (addr) => {\n\t\t\t\t\tconst low = this.mem.getUint32(addr + 0, true);\n\t\t\t\t\tconst high = this.mem.getInt32(addr + 4, true);\n\t\t\t\t\treturn low + high * 4294967296;\n\t\t\t\t}\n\t\n\t\t\t\tconst loadValue = (addr) => {\n\t\t\t\t\tconst f = this.mem.getFloat64(addr, true);\n\t\t\t\t\tif (f === 0) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\tif (!isNaN(f)) {\n\t\t\t\t\t\treturn f;\n\t\t\t\t\t}\n\t\n\t\t\t\t\tconst id = this.mem.getUint32(addr, true);\n\t\t\t\t\treturn this._values[id];\n\t\t\t\t}\n\t\n\t\t\t\tconst storeValue = (addr, v) => {\n\t\t\t\t\tconst nanHead = 0x7FF80000;\n\t\n\t\t\t\t\tif (typeof v === \"number\" && v !== 0) {\n\t\t\t\t\t\tif (isNaN(v)) {\n\t\t\t\t\t\t\tthis.mem.setUint32(addr + 4, nanHead, true);\n\t\t\t\t\t\t\tthis.mem.setUint32(addr, 0, true);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.mem.setFloat64(addr, v, true);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (v === undefined) {\n\t\t\t\t\t\tthis.mem.setFloat64(addr, 0, true);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\n\t\t\t\t\tlet id = this._ids.get(v);\n\t\t\t\t\tif (id === undefined) {\n\t\t\t\t\t\tid = this._idPool.pop();\n\t\t\t\t\t\tif (id === undefined) {\n\t\t\t\t\t\t\tid = this._values.length;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis._values[id] = v;\n\t\t\t\t\t\tthis._goRefCounts[id] = 0;\n\t\t\t\t\t\tthis._ids.set(v, id);\n\t\t\t\t\t}\n\t\t\t\t\tthis._goRefCounts[id]++;\n\t\t\t\t\tlet typeFlag = 0;\n\t\t\t\t\tswitch (typeof v) {\n\t\t\t\t\t\tcase \"object\":\n\t\t\t\t\t\t\tif (v !== null) {\n\t\t\t\t\t\t\t\ttypeFlag = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\ttypeFlag = 2;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"symbol\":\n\t\t\t\t\t\t\ttypeFlag = 3;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"function\":\n\t\t\t\t\t\t\ttypeFlag = 4;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tthis.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n\t\t\t\t\tthis.mem.setUint32(addr, id, true);\n\t\t\t\t}\n\t\n\t\t\t\tconst loadSlice = (addr) => {\n\t\t\t\t\tconst array = getInt64(addr + 0);\n\t\t\t\t\tconst len = getInt64(addr + 8);\n\t\t\t\t\treturn new Uint8Array(this._inst.exports.mem.buffer, array, len);\n\t\t\t\t}\n\t\n\t\t\t\tconst loadSliceOfValues = (addr) => {\n\t\t\t\t\tconst array = getInt64(addr + 0);\n\t\t\t\t\tconst len = getInt64(addr + 8);\n\t\t\t\t\tconst a = new Array(len);\n\t\t\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\t\t\ta[i] = loadValue(array + i * 8);\n\t\t\t\t\t}\n\t\t\t\t\treturn a;\n\t\t\t\t}\n\t\n\t\t\t\tconst loadString = (addr) => {\n\t\t\t\t\tconst saddr = getInt64(addr + 0);\n\t\t\t\t\tconst len = getInt64(addr + 8);\n\t\t\t\t\treturn decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n\t\t\t\t}\n\t\n\t\t\t\tconst timeOrigin = Date.now() - performance.now();\n\t\t\t\tthis.importObject = {\n\t\t\t\t\tgo: {\n\t\t\t\t\t\t// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n\t\t\t\t\t\t// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n\t\t\t\t\t\t// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n\t\t\t\t\t\t// This changes the SP, thus we have to update the SP used by the imported function.\n\t\n\t\t\t\t\t\t// func wasmExit(code int32)\n\t\t\t\t\t\t\"runtime.wasmExit\": (sp) => {\n\t\t\t\t\t\t\tconst code = this.mem.getInt32(sp + 8, true);\n\t\t\t\t\t\t\tthis.exited = true;\n\t\t\t\t\t\t\tdelete this._inst;\n\t\t\t\t\t\t\tdelete this._values;\n\t\t\t\t\t\t\tdelete this._goRefCounts;\n\t\t\t\t\t\t\tdelete this._ids;\n\t\t\t\t\t\t\tdelete this._idPool;\n\t\t\t\t\t\t\tthis.exit(code);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n\t\t\t\t\t\t\"runtime.wasmWrite\": (sp) => {\n\t\t\t\t\t\t\tconst fd = getInt64(sp + 8);\n\t\t\t\t\t\t\tconst p = getInt64(sp + 16);\n\t\t\t\t\t\t\tconst n = this.mem.getInt32(sp + 24, true);\n\t\t\t\t\t\t\tfs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func resetMemoryDataView()\n\t\t\t\t\t\t\"runtime.resetMemoryDataView\": (sp) => {\n\t\t\t\t\t\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func nanotime1() int64\n\t\t\t\t\t\t\"runtime.nanotime1\": (sp) => {\n\t\t\t\t\t\t\tsetInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func walltime1() (sec int64, nsec int32)\n\t\t\t\t\t\t\"runtime.walltime1\": (sp) => {\n\t\t\t\t\t\t\tconst msec = (new Date).getTime();\n\t\t\t\t\t\t\tsetInt64(sp + 8, msec / 1000);\n\t\t\t\t\t\t\tthis.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func scheduleTimeoutEvent(delay int64) int32\n\t\t\t\t\t\t\"runtime.scheduleTimeoutEvent\": (sp) => {\n\t\t\t\t\t\t\tconst id = this._nextCallbackTimeoutID;\n\t\t\t\t\t\t\tthis._nextCallbackTimeoutID++;\n\t\t\t\t\t\t\tthis._scheduledTimeouts.set(id, setTimeout(\n\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\tthis._resume();\n\t\t\t\t\t\t\t\t\twhile (this._scheduledTimeouts.has(id)) {\n\t\t\t\t\t\t\t\t\t\t// for some reason Go failed to register the timeout event, log and try again\n\t\t\t\t\t\t\t\t\t\t// (temporary workaround for https://github.com/golang/go/issues/28975)\n\t\t\t\t\t\t\t\t\t\tconsole.warn(\"scheduleTimeoutEvent: missed timeout event\");\n\t\t\t\t\t\t\t\t\t\tthis._resume();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tgetInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early\n\t\t\t\t\t\t\t));\n\t\t\t\t\t\t\tthis.mem.setInt32(sp + 16, id, true);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func clearTimeoutEvent(id int32)\n\t\t\t\t\t\t\"runtime.clearTimeoutEvent\": (sp) => {\n\t\t\t\t\t\t\tconst id = this.mem.getInt32(sp + 8, true);\n\t\t\t\t\t\t\tclearTimeout(this._scheduledTimeouts.get(id));\n\t\t\t\t\t\t\tthis._scheduledTimeouts.delete(id);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func getRandomData(r []byte)\n\t\t\t\t\t\t\"runtime.getRandomData\": (sp) => {\n\t\t\t\t\t\t\tcrypto.getRandomValues(loadSlice(sp + 8));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func finalizeRef(v ref)\n\t\t\t\t\t\t\"syscall/js.finalizeRef\": (sp) => {\n\t\t\t\t\t\t\tconst id = this.mem.getUint32(sp + 8, true);\n\t\t\t\t\t\t\tthis._goRefCounts[id]--;\n\t\t\t\t\t\t\tif (this._goRefCounts[id] === 0) {\n\t\t\t\t\t\t\t\tconst v = this._values[id];\n\t\t\t\t\t\t\t\tthis._values[id] = null;\n\t\t\t\t\t\t\t\tthis._ids.delete(v);\n\t\t\t\t\t\t\t\tthis._idPool.push(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func stringVal(value string) ref\n\t\t\t\t\t\t\"syscall/js.stringVal\": (sp) => {\n\t\t\t\t\t\t\tstoreValue(sp + 24, loadString(sp + 8));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueGet(v ref, p string) ref\n\t\t\t\t\t\t\"syscall/js.valueGet\": (sp) => {\n\t\t\t\t\t\t\tconst result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\tstoreValue(sp + 32, result);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueSet(v ref, p string, x ref)\n\t\t\t\t\t\t\"syscall/js.valueSet\": (sp) => {\n\t\t\t\t\t\t\tReflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueDelete(v ref, p string)\n\t\t\t\t\t\t\"syscall/js.valueDelete\": (sp) => {\n\t\t\t\t\t\t\tReflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueIndex(v ref, i int) ref\n\t\t\t\t\t\t\"syscall/js.valueIndex\": (sp) => {\n\t\t\t\t\t\t\tstoreValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// valueSetIndex(v ref, i int, x ref)\n\t\t\t\t\t\t\"syscall/js.valueSetIndex\": (sp) => {\n\t\t\t\t\t\t\tReflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueCall(v ref, m string, args []ref) (ref, bool)\n\t\t\t\t\t\t\"syscall/js.valueCall\": (sp) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\t\t\tconst m = Reflect.get(v, loadString(sp + 16));\n\t\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 32);\n\t\t\t\t\t\t\t\tconst result = Reflect.apply(m, v, args);\n\t\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\t\tstoreValue(sp + 56, result);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 1);\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tstoreValue(sp + 56, err);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueInvoke(v ref, args []ref) (ref, bool)\n\t\t\t\t\t\t\"syscall/js.valueInvoke\": (sp) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);\n\t\t\t\t\t\t\t\tconst result = Reflect.apply(v, undefined, args);\n\t\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, result);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, err);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueNew(v ref, args []ref) (ref, bool)\n\t\t\t\t\t\t\"syscall/js.valueNew\": (sp) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);\n\t\t\t\t\t\t\t\tconst result = Reflect.construct(v, args);\n\t\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, result);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, err);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueLength(v ref) int\n\t\t\t\t\t\t\"syscall/js.valueLength\": (sp) => {\n\t\t\t\t\t\t\tsetInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// valuePrepareString(v ref) (ref, int)\n\t\t\t\t\t\t\"syscall/js.valuePrepareString\": (sp) => {\n\t\t\t\t\t\t\tconst str = encoder.encode(String(loadValue(sp + 8)));\n\t\t\t\t\t\t\tstoreValue(sp + 16, str);\n\t\t\t\t\t\t\tsetInt64(sp + 24, str.length);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// valueLoadString(v ref, b []byte)\n\t\t\t\t\t\t\"syscall/js.valueLoadString\": (sp) => {\n\t\t\t\t\t\t\tconst str = loadValue(sp + 8);\n\t\t\t\t\t\t\tloadSlice(sp + 16).set(str);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueInstanceOf(v ref, t ref) bool\n\t\t\t\t\t\t\"syscall/js.valueInstanceOf\": (sp) => {\n\t\t\t\t\t\t\tthis.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func copyBytesToGo(dst []byte, src ref) (int, bool)\n\t\t\t\t\t\t\"syscall/js.copyBytesToGo\": (sp) => {\n\t\t\t\t\t\t\tconst dst = loadSlice(sp + 8);\n\t\t\t\t\t\t\tconst src = loadValue(sp + 32);\n\t\t\t\t\t\t\tif (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);\n\t\t\t\t\t\t\tdst.set(toCopy);\n\t\t\t\t\t\t\tsetInt64(sp + 40, toCopy.length);\n\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func copyBytesToJS(dst ref, src []byte) (int, bool)\n\t\t\t\t\t\t\"syscall/js.copyBytesToJS\": (sp) => {\n\t\t\t\t\t\t\tconst dst = loadValue(sp + 8);\n\t\t\t\t\t\t\tconst src = loadSlice(sp + 16);\n\t\t\t\t\t\t\tif (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);\n\t\t\t\t\t\t\tdst.set(toCopy);\n\t\t\t\t\t\t\tsetInt64(sp + 40, toCopy.length);\n\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t\"debug\": (value) => {\n\t\t\t\t\t\t\tconsole.log(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\n\t\t\tasync run(instance) {\n\t\t\t\tthis._inst = instance;\n\t\t\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);\n\t\t\t\tthis._values = [ // JS values that Go currently has references to, indexed by reference id\n\t\t\t\t\tNaN,\n\t\t\t\t\t0,\n\t\t\t\t\tnull,\n\t\t\t\t\ttrue,\n\t\t\t\t\tfalse,\n\t\t\t\t\tglobal,\n\t\t\t\t\tthis,\n\t\t\t\t];\n\t\t\t\tthis._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id\n\t\t\t\tthis._ids = new Map([ // mapping from JS values to reference ids\n\t\t\t\t\t[0, 1],\n\t\t\t\t\t[null, 2],\n\t\t\t\t\t[true, 3],\n\t\t\t\t\t[false, 4],\n\t\t\t\t\t[global, 5],\n\t\t\t\t\t[this, 6],\n\t\t\t\t]);\n\t\t\t\tthis._idPool = []; // unused ids that have been garbage collected\n\t\t\t\tthis.exited = false; // whether the Go program has exited\n\t\n\t\t\t\t// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.\n\t\t\t\tlet offset = 4096;\n\t\n\t\t\t\tconst strPtr = (str) => {\n\t\t\t\t\tconst ptr = offset;\n\t\t\t\t\tconst bytes = encoder.encode(str + \"\\0\");\n\t\t\t\t\tnew Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n\t\t\t\t\toffset += bytes.length;\n\t\t\t\t\tif (offset % 8 !== 0) {\n\t\t\t\t\t\toffset += 8 - (offset % 8);\n\t\t\t\t\t}\n\t\t\t\t\treturn ptr;\n\t\t\t\t};\n\t\n\t\t\t\tconst argc = this.argv.length;\n\t\n\t\t\t\tconst argvPtrs = [];\n\t\t\t\tthis.argv.forEach((arg) => {\n\t\t\t\t\targvPtrs.push(strPtr(arg));\n\t\t\t\t});\n\t\t\t\targvPtrs.push(0);\n\t\n\t\t\t\tconst keys = Object.keys(this.env).sort();\n\t\t\t\tkeys.forEach((key) => {\n\t\t\t\t\targvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n\t\t\t\t});\n\t\t\t\targvPtrs.push(0);\n\t\n\t\t\t\tconst argv = offset;\n\t\t\t\targvPtrs.forEach((ptr) => {\n\t\t\t\t\tthis.mem.setUint32(offset, ptr, true);\n\t\t\t\t\tthis.mem.setUint32(offset + 4, 0, true);\n\t\t\t\t\toffset += 8;\n\t\t\t\t});\n\t\n\t\t\t\tthis._inst.exports.run(argc, argv);\n\t\t\t\tif (this.exited) {\n\t\t\t\t\tthis._resolveExitPromise();\n\t\t\t\t}\n\t\t\t\tawait this._exitPromise;\n\t\t\t}\n\t\n\t\t\t_resume() {\n\t\t\t\tif (this.exited) {\n\t\t\t\t\tthrow new Error(\"Go program has already exited\");\n\t\t\t\t}\n\t\t\t\tthis._inst.exports.resume();\n\t\t\t\tif (this.exited) {\n\t\t\t\t\tthis._resolveExitPromise();\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t_makeFuncWrapper(id) {\n\t\t\t\tconst go = this;\n\t\t\t\treturn function () {\n\t\t\t\t\tconst event = { id: id, this: this, args: arguments };\n\t\t\t\t\tgo._pendingEvent = event;\n\t\t\t\t\tgo._resume();\n\t\t\t\t\treturn event.result;\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\n\t\tif (\n\t\t\tglobal.require &&\n\t\t\tglobal.require.main === module &&\n\t\t\tglobal.process &&\n\t\t\tglobal.process.versions &&\n\t\t\t!global.process.versions.electron\n\t\t) {\n\t\t\tif (process.argv.length < 3) {\n\t\t\t\tconsole.error(\"usage: go_js_wasm_exec [wasm binary] [arguments]\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\n\t\t\tconst go = new Go();\n\t\t\tgo.argv = process.argv.slice(2);\n\t\t\tgo.env = Object.assign({ TMPDIR: require(\"os\").tmpdir() }, process.env);\n\t\t\tgo.exit = process.exit;\n\t\t\tWebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {\n\t\t\t\tprocess.on(\"exit\", (code) => { // Node.js exits if no event handler is pending\n\t\t\t\t\tif (code === 0 && !go.exited) {\n\t\t\t\t\t\t// deadlock, make Go print error and stack traces\n\t\t\t\t\t\tgo._pendingEvent = { id: 0 };\n\t\t\t\t\t\tgo._resume();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn go.run(result.instance);\n\t\t\t}).catch((err) => {\n\t\t\t\tconsole.error(err);\n\t\t\t\tprocess.exit(1);\n\t\t\t});\n\t\t}\n\t})();\n}\n","// DEFLATE is a complex format; to read this code, you should probably check the RFC first:\n// https://tools.ietf.org/html/rfc1951\n// You may also wish to take a look at the guide I made about this program:\n// https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad\n// Some of the following code is similar to that of UZIP.js:\n// https://github.com/photopea/UZIP.js\n// However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.\n// Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint\n// is better for memory in most engines (I *think*).\nvar ch2 = {};\nvar wk = (function (c, id, msg, transfer, cb) {\n var w = new Worker(ch2[id] || (ch2[id] = URL.createObjectURL(new Blob([\n c + ';addEventListener(\"error\",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'\n ], { type: 'text/javascript' }))));\n w.onmessage = function (e) {\n var d = e.data, ed = d.$e$;\n if (ed) {\n var err = new Error(ed[0]);\n err['code'] = ed[1];\n err.stack = ed[2];\n cb(err, null);\n }\n else\n cb(null, d);\n };\n w.postMessage(msg, transfer);\n return w;\n});\n\n// aliases for shorter compressed code (most minifers don't do this)\nvar u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;\n// fixed length extra bits\nvar 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]);\n// fixed distance extra bits\n// see fleb note\nvar 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]);\n// code length index map\nvar clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);\n// get base, reverse index map from extra bits\nvar freb = function (eb, start) {\n var b = new u16(31);\n for (var i = 0; i < 31; ++i) {\n b[i] = start += 1 << eb[i - 1];\n }\n // numbers here are at max 18 bits\n var r = new u32(b[30]);\n for (var i = 1; i < 30; ++i) {\n for (var j = b[i]; j < b[i + 1]; ++j) {\n r[j] = ((j - b[i]) << 5) | i;\n }\n }\n return [b, r];\n};\nvar _a = freb(fleb, 2), fl = _a[0], revfl = _a[1];\n// we can ignore the fact that the other numbers are wrong; they never happen anyway\nfl[28] = 258, revfl[258] = 28;\nvar _b = freb(fdeb, 0), fd = _b[0], revfd = _b[1];\n// map of value to reverse (assuming 16 bits)\nvar rev = new u16(32768);\nfor (var i = 0; i < 32768; ++i) {\n // reverse table algorithm from SO\n var x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);\n x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);\n x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);\n rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;\n}\n// create huffman tree from u8 \"map\": index -> code length for code index\n// mb (max bits) must be at most 15\n// TODO: optimize/split up?\nvar hMap = (function (cd, mb, r) {\n var s = cd.length;\n // index\n var i = 0;\n // u16 \"map\": index -> # of codes with bit length = index\n var l = new u16(mb);\n // length of cd must be 288 (total # of codes)\n for (; i < s; ++i)\n ++l[cd[i] - 1];\n // u16 \"map\": index -> minimum code for bit length = index\n var le = new u16(mb);\n for (i = 0; i < mb; ++i) {\n le[i] = (le[i - 1] + l[i - 1]) << 1;\n }\n var co;\n if (r) {\n // u16 \"map\": index -> number of actual bits, symbol for code\n co = new u16(1 << mb);\n // bits to remove for reverser\n var rvb = 15 - mb;\n for (i = 0; i < s; ++i) {\n // ignore 0 lengths\n if (cd[i]) {\n // num encoding both symbol and bits read\n var sv = (i << 4) | cd[i];\n // free bits\n var r_1 = mb - cd[i];\n // start value\n var v = le[cd[i] - 1]++ << r_1;\n // m is end value\n for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {\n // every 16 bit value starting with the code yields the same result\n co[rev[v] >>> rvb] = sv;\n }\n }\n }\n }\n else {\n co = new u16(s);\n for (i = 0; i < s; ++i) {\n if (cd[i]) {\n co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);\n }\n }\n }\n return co;\n});\n// fixed length tree\nvar flt = new u8(288);\nfor (var i = 0; i < 144; ++i)\n flt[i] = 8;\nfor (var i = 144; i < 256; ++i)\n flt[i] = 9;\nfor (var i = 256; i < 280; ++i)\n flt[i] = 7;\nfor (var i = 280; i < 288; ++i)\n flt[i] = 8;\n// fixed distance tree\nvar fdt = new u8(32);\nfor (var i = 0; i < 32; ++i)\n fdt[i] = 5;\n// fixed length map\nvar flm = /*#__PURE__*/ hMap(flt, 9, 0), flrm = /*#__PURE__*/ hMap(flt, 9, 1);\n// fixed distance map\nvar fdm = /*#__PURE__*/ hMap(fdt, 5, 0), fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);\n// find max of array\nvar max = function (a) {\n var m = a[0];\n for (var i = 1; i < a.length; ++i) {\n if (a[i] > m)\n m = a[i];\n }\n return m;\n};\n// read d, starting at bit p and mask with m\nvar bits = function (d, p, m) {\n var o = (p / 8) | 0;\n return ((d[o] | (d[o + 1] << 8)) >> (p & 7)) & m;\n};\n// read d, starting at bit p continuing for at least 16 bits\nvar bits16 = function (d, p) {\n var o = (p / 8) | 0;\n return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >> (p & 7));\n};\n// get end of byte\nvar shft = function (p) { return ((p + 7) / 8) | 0; };\n// typed array slice - allows garbage collector to free original reference,\n// while being more compatible than .slice\nvar slc = function (v, s, e) {\n if (s == null || s < 0)\n s = 0;\n if (e == null || e > v.length)\n e = v.length;\n // can't use .constructor in case user-supplied\n var n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s);\n n.set(v.subarray(s, e));\n return n;\n};\n/**\n * Codes for errors generated within this library\n */\nexport var FlateErrorCode = {\n UnexpectedEOF: 0,\n InvalidBlockType: 1,\n InvalidLengthLiteral: 2,\n InvalidDistance: 3,\n StreamFinished: 4,\n NoStreamHandler: 5,\n InvalidHeader: 6,\n NoCallback: 7,\n InvalidUTF8: 8,\n ExtraFieldTooLong: 9,\n InvalidDate: 10,\n FilenameTooLong: 11,\n StreamFinishing: 12,\n InvalidZipData: 13,\n UnknownCompressionMethod: 14\n};\n// error codes\nvar ec = [\n 'unexpected EOF',\n 'invalid block type',\n 'invalid length/literal',\n 'invalid distance',\n 'stream finished',\n 'no stream handler',\n ,\n 'no callback',\n 'invalid UTF-8 data',\n 'extra field too long',\n 'date not in range 1980-2099',\n 'filename too long',\n 'stream finishing',\n 'invalid zip data'\n // determined by unknown compression method\n];\n;\nvar err = function (ind, msg, nt) {\n var e = new Error(msg || ec[ind]);\n e.code = ind;\n if (Error.captureStackTrace)\n Error.captureStackTrace(e, err);\n if (!nt)\n throw e;\n return e;\n};\n// expands raw DEFLATE data\nvar inflt = function (dat, buf, st) {\n // source length\n var sl = dat.length;\n if (!sl || (st && st.f && !st.l))\n return buf || new u8(0);\n // have to estimate size\n var noBuf = !buf || st;\n // no state\n var noSt = !st || st.i;\n if (!st)\n st = {};\n // Assumes roughly 33% compression ratio average\n if (!buf)\n buf = new u8(sl * 3);\n // ensure buffer can fit at least l elements\n var cbuf = function (l) {\n var bl = buf.length;\n // need to increase size to fit\n if (l > bl) {\n // Double or set to necessary, whichever is greater\n var nbuf = new u8(Math.max(bl * 2, l));\n nbuf.set(buf);\n buf = nbuf;\n }\n };\n // last chunk bitpos bytes\n 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;\n // total bits\n var tbts = sl * 8;\n do {\n if (!lm) {\n // BFINAL - this is only 1 when last chunk is next\n final = bits(dat, pos, 1);\n // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman\n var type = bits(dat, pos + 1, 3);\n pos += 3;\n if (!type) {\n // go to end of byte boundary\n var s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;\n if (t > sl) {\n if (noSt)\n err(0);\n break;\n }\n // ensure size\n if (noBuf)\n cbuf(bt + l);\n // Copy over uncompressed data\n buf.set(dat.subarray(s, t), bt);\n // Get new bitpos, update byte count\n st.b = bt += l, st.p = pos = t * 8, st.f = final;\n continue;\n }\n else if (type == 1)\n lm = flrm, dm = fdrm, lbt = 9, dbt = 5;\n else if (type == 2) {\n // literal lengths\n var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;\n var tl = hLit + bits(dat, pos + 5, 31) + 1;\n pos += 14;\n // length+distance tree\n var ldt = new u8(tl);\n // code length tree\n var clt = new u8(19);\n for (var i = 0; i < hcLen; ++i) {\n // use index map to get real code\n clt[clim[i]] = bits(dat, pos + i * 3, 7);\n }\n pos += hcLen * 3;\n // code lengths bits\n var clb = max(clt), clbmsk = (1 << clb) - 1;\n // code lengths map\n var clm = hMap(clt, clb, 1);\n for (var i = 0; i < tl;) {\n var r = clm[bits(dat, pos, clbmsk)];\n // bits read\n pos += r & 15;\n // symbol\n var s = r >>> 4;\n // code length to copy\n if (s < 16) {\n ldt[i++] = s;\n }\n else {\n // copy count\n var c = 0, n = 0;\n if (s == 16)\n n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];\n else if (s == 17)\n n = 3 + bits(dat, pos, 7), pos += 3;\n else if (s == 18)\n n = 11 + bits(dat, pos, 127), pos += 7;\n while (n--)\n ldt[i++] = c;\n }\n }\n // length tree distance tree\n var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);\n // max length bits\n lbt = max(lt);\n // max dist bits\n dbt = max(dt);\n lm = hMap(lt, lbt, 1);\n dm = hMap(dt, dbt, 1);\n }\n else\n err(1);\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n }\n // Make sure the buffer can hold this + the largest possible addition\n // Maximum chunk size (practically, theoretically infinite) is 2^17;\n if (noBuf)\n cbuf(bt + 131072);\n var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;\n var lpos = pos;\n for (;; lpos = pos) {\n // bits read, code\n var c = lm[bits16(dat, pos) & lms], sym = c >>> 4;\n pos += c & 15;\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n if (!c)\n err(2);\n if (sym < 256)\n buf[bt++] = sym;\n else if (sym == 256) {\n lpos = pos, lm = null;\n break;\n }\n else {\n var add = sym - 254;\n // no extra bits needed if less\n if (sym > 264) {\n // index\n var i = sym - 257, b = fleb[i];\n add = bits(dat, pos, (1 << b) - 1) + fl[i];\n pos += b;\n }\n // dist\n var d = dm[bits16(dat, pos) & dms], dsym = d >>> 4;\n if (!d)\n err(3);\n pos += d & 15;\n var dt = fd[dsym];\n if (dsym > 3) {\n var b = fdeb[dsym];\n dt += bits16(dat, pos) & ((1 << b) - 1), pos += b;\n }\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n if (noBuf)\n cbuf(bt + 131072);\n var end = bt + add;\n for (; bt < end; bt += 4) {\n buf[bt] = buf[bt - dt];\n buf[bt + 1] = buf[bt + 1 - dt];\n buf[bt + 2] = buf[bt + 2 - dt];\n buf[bt + 3] = buf[bt + 3 - dt];\n }\n bt = end;\n }\n }\n st.l = lm, st.p = lpos, st.b = bt, st.f = final;\n if (lm)\n final = 1, st.m = lbt, st.d = dm, st.n = dbt;\n } while (!final);\n return bt == buf.length ? buf : slc(buf, 0, bt);\n};\n// starting at p, write the minimum number of bits that can hold v to d\nvar wbits = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n};\n// starting at p, write the minimum number of bits (>8) that can hold v to d\nvar wbits16 = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n d[o + 2] |= v >>> 16;\n};\n// creates code lengths from a frequency table\nvar hTree = function (d, mb) {\n // Need extra info to make a tree\n var t = [];\n for (var i = 0; i < d.length; ++i) {\n if (d[i])\n t.push({ s: i, f: d[i] });\n }\n var s = t.length;\n var t2 = t.slice();\n if (!s)\n return [et, 0];\n if (s == 1) {\n var v = new u8(t[0].s + 1);\n v[t[0].s] = 1;\n return [v, 1];\n }\n t.sort(function (a, b) { return a.f - b.f; });\n // after i2 reaches last ind, will be stopped\n // freq must be greater than largest possible number of symbols\n t.push({ s: -1, f: 25001 });\n var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;\n t[0] = { s: -1, f: l.f + r.f, l: l, r: r };\n // efficient algorithm from UZIP.js\n // i0 is lookbehind, i2 is lookahead - after processing two low-freq\n // symbols that combined have high freq, will start processing i2 (high-freq,\n // non-composite) symbols instead\n // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/\n while (i1 != s - 1) {\n l = t[t[i0].f < t[i2].f ? i0++ : i2++];\n r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];\n t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };\n }\n var maxSym = t2[0].s;\n for (var i = 1; i < s; ++i) {\n if (t2[i].s > maxSym)\n maxSym = t2[i].s;\n }\n // code lengths\n var tr = new u16(maxSym + 1);\n // max bits in tree\n var mbt = ln(t[i1 - 1], tr, 0);\n if (mbt > mb) {\n // more algorithms from UZIP.js\n // TODO: find out how this code works (debt)\n // ind debt\n var i = 0, dt = 0;\n // left cost\n var lft = mbt - mb, cst = 1 << lft;\n t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });\n for (; i < s; ++i) {\n var i2_1 = t2[i].s;\n if (tr[i2_1] > mb) {\n dt += cst - (1 << (mbt - tr[i2_1]));\n tr[i2_1] = mb;\n }\n else\n break;\n }\n dt >>>= lft;\n while (dt > 0) {\n var i2_2 = t2[i].s;\n if (tr[i2_2] < mb)\n dt -= 1 << (mb - tr[i2_2]++ - 1);\n else\n ++i;\n }\n for (; i >= 0 && dt; --i) {\n var i2_3 = t2[i].s;\n if (tr[i2_3] == mb) {\n --tr[i2_3];\n ++dt;\n }\n }\n mbt = mb;\n }\n return [new u8(tr), mbt];\n};\n// get the max length and assign length codes\nvar ln = function (n, l, d) {\n return n.s == -1\n ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))\n : (l[n.s] = d);\n};\n// length codes generation\nvar lc = function (c) {\n var s = c.length;\n // Note that the semicolon was intentional\n while (s && !c[--s])\n ;\n var cl = new u16(++s);\n // ind num streak\n var cli = 0, cln = c[0], cls = 1;\n var w = function (v) { cl[cli++] = v; };\n for (var i = 1; i <= s; ++i) {\n if (c[i] == cln && i != s)\n ++cls;\n else {\n if (!cln && cls > 2) {\n for (; cls > 138; cls -= 138)\n w(32754);\n if (cls > 2) {\n w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);\n cls = 0;\n }\n }\n else if (cls > 3) {\n w(cln), --cls;\n for (; cls > 6; cls -= 6)\n w(8304);\n if (cls > 2)\n w(((cls - 3) << 5) | 8208), cls = 0;\n }\n while (cls--)\n w(cln);\n cls = 1;\n cln = c[i];\n }\n }\n return [cl.subarray(0, cli), s];\n};\n// calculate the length of output from tree, code lengths\nvar clen = function (cf, cl) {\n var l = 0;\n for (var i = 0; i < cl.length; ++i)\n l += cf[i] * cl[i];\n return l;\n};\n// writes a fixed block\n// returns the new bit pos\nvar wfblk = function (out, pos, dat) {\n // no need to write 00 as type: TypedArray defaults to 0\n var s = dat.length;\n var o = shft(pos + 2);\n out[o] = s & 255;\n out[o + 1] = s >>> 8;\n out[o + 2] = out[o] ^ 255;\n out[o + 3] = out[o + 1] ^ 255;\n for (var i = 0; i < s; ++i)\n out[o + i + 4] = dat[i];\n return (o + 4 + s) * 8;\n};\n// writes a block\nvar wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {\n wbits(out, p++, final);\n ++lf[256];\n var _a = hTree(lf, 15), dlt = _a[0], mlb = _a[1];\n var _b = hTree(df, 15), ddt = _b[0], mdb = _b[1];\n var _c = lc(dlt), lclt = _c[0], nlc = _c[1];\n var _d = lc(ddt), lcdt = _d[0], ndc = _d[1];\n var lcfreq = new u16(19);\n for (var i = 0; i < lclt.length; ++i)\n lcfreq[lclt[i] & 31]++;\n for (var i = 0; i < lcdt.length; ++i)\n lcfreq[lcdt[i] & 31]++;\n var _e = hTree(lcfreq, 7), lct = _e[0], mlcb = _e[1];\n var nlcc = 19;\n for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)\n ;\n var flen = (bl + 5) << 3;\n var ftlen = clen(lf, flt) + clen(df, fdt) + eb;\n var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + (2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18]);\n if (flen <= ftlen && flen <= dtlen)\n return wfblk(out, p, dat.subarray(bs, bs + bl));\n var lm, ll, dm, dl;\n wbits(out, p, 1 + (dtlen < ftlen)), p += 2;\n if (dtlen < ftlen) {\n lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;\n var llm = hMap(lct, mlcb, 0);\n wbits(out, p, nlc - 257);\n wbits(out, p + 5, ndc - 1);\n wbits(out, p + 10, nlcc - 4);\n p += 14;\n for (var i = 0; i < nlcc; ++i)\n wbits(out, p + 3 * i, lct[clim[i]]);\n p += 3 * nlcc;\n var lcts = [lclt, lcdt];\n for (var it = 0; it < 2; ++it) {\n var clct = lcts[it];\n for (var i = 0; i < clct.length; ++i) {\n var len = clct[i] & 31;\n wbits(out, p, llm[len]), p += lct[len];\n if (len > 15)\n wbits(out, p, (clct[i] >>> 5) & 127), p += clct[i] >>> 12;\n }\n }\n }\n else {\n lm = flm, ll = flt, dm = fdm, dl = fdt;\n }\n for (var i = 0; i < li; ++i) {\n if (syms[i] > 255) {\n var len = (syms[i] >>> 18) & 31;\n wbits16(out, p, lm[len + 257]), p += ll[len + 257];\n if (len > 7)\n wbits(out, p, (syms[i] >>> 23) & 31), p += fleb[len];\n var dst = syms[i] & 31;\n wbits16(out, p, dm[dst]), p += dl[dst];\n if (dst > 3)\n wbits16(out, p, (syms[i] >>> 5) & 8191), p += fdeb[dst];\n }\n else {\n wbits16(out, p, lm[syms[i]]), p += ll[syms[i]];\n }\n }\n wbits16(out, p, lm[256]);\n return p + ll[256];\n};\n// deflate options (nice << 13) | chain\nvar deo = /*#__PURE__*/ new u32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);\n// empty\nvar et = /*#__PURE__*/ new u8(0);\n// compresses data into a raw DEFLATE buffer\nvar dflt = function (dat, lvl, plvl, pre, post, lst) {\n var s = dat.length;\n var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);\n // writing to this writes to the output buffer\n var w = o.subarray(pre, o.length - post);\n var pos = 0;\n if (!lvl || s < 8) {\n for (var i = 0; i <= s; i += 65535) {\n // end\n var e = i + 65535;\n if (e < s) {\n // write full block\n pos = wfblk(w, pos, dat.subarray(i, e));\n }\n else {\n // write final block\n w[i] = lst;\n pos = wfblk(w, pos, dat.subarray(i, s));\n }\n }\n }\n else {\n var opt = deo[lvl - 1];\n var n = opt >>> 13, c = opt & 8191;\n var msk_1 = (1 << plvl) - 1;\n // prev 2-byte val map curr 2-byte val map\n var prev = new u16(32768), head = new u16(msk_1 + 1);\n var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;\n var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };\n // 24576 is an arbitrary number of maximum symbols per block\n // 424 buffer for last block\n var syms = new u32(25000);\n // length/literal freq distance freq\n var lf = new u16(288), df = new u16(32);\n // l/lcnt exbits index l/lind waitdx bitpos\n var lc_1 = 0, eb = 0, i = 0, li = 0, wi = 0, bs = 0;\n for (; i < s; ++i) {\n // hash value\n // deopt when i > s - 3 - at end, deopt acceptable\n var hv = hsh(i);\n // index mod 32768 previous index mod\n var imod = i & 32767, pimod = head[hv];\n prev[imod] = pimod;\n head[hv] = imod;\n // We always should modify head and prev, but only add symbols if\n // this data is not yet processed (\"wait\" for wait index)\n if (wi <= i) {\n // bytes remaining\n var rem = s - i;\n if ((lc_1 > 7000 || li > 24576) && rem > 423) {\n pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);\n li = lc_1 = eb = 0, bs = i;\n for (var j = 0; j < 286; ++j)\n lf[j] = 0;\n for (var j = 0; j < 30; ++j)\n df[j] = 0;\n }\n // len dist chain\n var l = 2, d = 0, ch_1 = c, dif = (imod - pimod) & 32767;\n if (rem > 2 && hv == hsh(i - dif)) {\n var maxn = Math.min(n, rem) - 1;\n var maxd = Math.min(32767, i);\n // max possible length\n // not capped at dif because decompressors implement \"rolling\" index population\n var ml = Math.min(258, rem);\n while (dif <= maxd && --ch_1 && imod != pimod) {\n if (dat[i + l] == dat[i + l - dif]) {\n var nl = 0;\n for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)\n ;\n if (nl > l) {\n l = nl, d = dif;\n // break out early when we reach \"nice\" (we are satisfied enough)\n if (nl > maxn)\n break;\n // now, find the rarest 2-byte sequence within this\n // length of literals and search for that instead.\n // Much faster than just using the start\n var mmd = Math.min(dif, nl - 2);\n var md = 0;\n for (var j = 0; j < mmd; ++j) {\n var ti = (i - dif + j + 32768) & 32767;\n var pti = prev[ti];\n var cd = (ti - pti + 32768) & 32767;\n if (cd > md)\n md = cd, pimod = ti;\n }\n }\n }\n // check the previous match\n imod = pimod, pimod = prev[imod];\n dif += (imod - pimod + 32768) & 32767;\n }\n }\n // d will be nonzero only when a match was found\n if (d) {\n // store both dist and len data in one Uint32\n // Make sure this is recognized as a len/dist with 28th bit (2^28)\n syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];\n var lin = revfl[l] & 31, din = revfd[d] & 31;\n eb += fleb[lin] + fdeb[din];\n ++lf[257 + lin];\n ++df[din];\n wi = i + l;\n ++lc_1;\n }\n else {\n syms[li++] = dat[i];\n ++lf[dat[i]];\n }\n }\n }\n pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);\n // this is the easiest way to avoid needing to maintain state\n if (!lst && pos & 7)\n pos = wfblk(w, pos + 1, et);\n }\n return slc(o, 0, pre + shft(pos) + post);\n};\n// CRC32 table\nvar crct = /*#__PURE__*/ (function () {\n var t = new Int32Array(256);\n for (var i = 0; i < 256; ++i) {\n var c = i, k = 9;\n while (--k)\n c = ((c & 1) && -306674912) ^ (c >>> 1);\n t[i] = c;\n }\n return t;\n})();\n// CRC32\nvar crc = function () {\n var c = -1;\n return {\n p: function (d) {\n // closures have awful performance\n var cr = c;\n for (var i = 0; i < d.length; ++i)\n cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);\n c = cr;\n },\n d: function () { return ~c; }\n };\n};\n// Alder32\nvar adler = function () {\n var a = 1, b = 0;\n return {\n p: function (d) {\n // closures have awful performance\n var n = a, m = b;\n var l = d.length | 0;\n for (var i = 0; i != l;) {\n var e = Math.min(i + 2655, l);\n for (; i < e; ++i)\n m += n += d[i];\n n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);\n }\n a = n, b = m;\n },\n d: function () {\n a %= 65521, b %= 65521;\n return (a & 255) << 24 | (a >>> 8) << 16 | (b & 255) << 8 | (b >>> 8);\n }\n };\n};\n;\n// deflate with opts\nvar dopt = function (dat, opt, pre, post, st) {\n return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : (12 + opt.mem), pre, post, !st);\n};\n// Walmart object spread\nvar mrg = function (a, b) {\n var o = {};\n for (var k in a)\n o[k] = a[k];\n for (var k in b)\n o[k] = b[k];\n return o;\n};\n// worker clone\n// This is possibly the craziest part of the entire codebase, despite how simple it may seem.\n// The only parameter to this function is a closure that returns an array of variables outside of the function scope.\n// We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.\n// We will return an object mapping of true variable name to value (basically, the current scope as a JS object).\n// The reason we can't just use the original variable names is minifiers mangling the toplevel scope.\n// This took me three weeks to figure out how to do.\nvar wcln = function (fn, fnStr, td) {\n var dt = fn();\n var st = fn.toString();\n var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/ /g, '').split(',');\n for (var i = 0; i < dt.length; ++i) {\n var v = dt[i], k = ks[i];\n if (typeof v == 'function') {\n fnStr += ';' + k + '=';\n var st_1 = v.toString();\n if (v.prototype) {\n // for global objects\n if (st_1.indexOf('[native code]') != -1) {\n var spInd = st_1.indexOf(' ', 8) + 1;\n fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));\n }\n else {\n fnStr += st_1;\n for (var t in v.prototype)\n fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();\n }\n }\n else\n fnStr += st_1;\n }\n else\n td[k] = v;\n }\n return [fnStr, td];\n};\nvar ch = [];\n// clone bufs\nvar cbfs = function (v) {\n var tl = [];\n for (var k in v) {\n if (v[k] instanceof u8 || v[k] instanceof u16 || v[k] instanceof u32)\n tl.push((v[k] = new v[k].constructor(v[k])).buffer);\n }\n return tl;\n};\n// use a worker to execute code\nvar wrkr = function (fns, init, id, cb) {\n var _a;\n if (!ch[id]) {\n var fnStr = '', td_1 = {}, m = fns.length - 1;\n for (var i = 0; i < m; ++i)\n _a = wcln(fns[i], fnStr, td_1), fnStr = _a[0], td_1 = _a[1];\n ch[id] = wcln(fns[m], fnStr, td_1);\n }\n var td = mrg({}, ch[id][1]);\n return wk(ch[id][0] + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);\n};\n// base async inflate fn\nvar bInflt = function () { return [u8, u16, u32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gu8]; };\nvar bDflt = function () { return [u8, u16, u32, 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]; };\n// gzip extra\nvar gze = function () { return [gzh, gzhl, wbytes, crc, crct]; };\n// gunzip extra\nvar guze = function () { return [gzs, gzl]; };\n// zlib extra\nvar zle = function () { return [zlh, wbytes, adler]; };\n// unzlib extra\nvar zule = function () { return [zlv]; };\n// post buf\nvar pbf = function (msg) { return postMessage(msg, [msg.buffer]); };\n// get u8\nvar gu8 = function (o) { return o && o.size && new u8(o.size); };\n// async helper\nvar cbify = function (dat, opts, fns, init, id, cb) {\n var w = wrkr(fns, init, id, function (err, dat) {\n w.terminate();\n cb(err, dat);\n });\n w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);\n return function () { w.terminate(); };\n};\n// auto stream\nvar astrm = function (strm) {\n strm.ondata = function (dat, final) { return postMessage([dat, final], [dat.buffer]); };\n return function (ev) { return strm.push(ev.data[0], ev.data[1]); };\n};\n// async stream attach\nvar astrmify = function (fns, strm, opts, init, id) {\n var t;\n var w = wrkr(fns, init, id, function (err, dat) {\n if (err)\n w.terminate(), strm.ondata.call(strm, err);\n else {\n if (dat[1])\n w.terminate();\n strm.ondata.call(strm, err, dat[0], dat[1]);\n }\n });\n w.postMessage(opts);\n strm.push = function (d, f) {\n if (!strm.ondata)\n err(5);\n if (t)\n strm.ondata(err(4, 0, 1), null, !!f);\n w.postMessage([d, t = f], [d.buffer]);\n };\n strm.terminate = function () { w.terminate(); };\n};\n// read 2 bytes\nvar b2 = function (d, b) { return d[b] | (d[b + 1] << 8); };\n// read 4 bytes\nvar b4 = function (d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; };\nvar b8 = function (d, b) { return b4(d, b) + (b4(d, b + 4) * 4294967296); };\n// write bytes\nvar wbytes = function (d, b, v) {\n for (; v; ++b)\n d[b] = v, v >>>= 8;\n};\n// gzip header\nvar gzh = function (c, o) {\n var fn = o.filename;\n c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix\n if (o.mtime != 0)\n wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000));\n if (fn) {\n c[3] = 8;\n for (var i = 0; i <= fn.length; ++i)\n c[i + 10] = fn.charCodeAt(i);\n }\n};\n// gzip footer: -8 to -4 = CRC, -4 to -0 is length\n// gzip start\nvar gzs = function (d) {\n if (d[0] != 31 || d[1] != 139 || d[2] != 8)\n err(6, 'invalid gzip data');\n var flg = d[3];\n var st = 10;\n if (flg & 4)\n st += d[10] | (d[11] << 8) + 2;\n for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])\n ;\n return st + (flg & 2);\n};\n// gzip length\nvar gzl = function (d) {\n var l = d.length;\n return ((d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16) | (d[l - 1] << 24)) >>> 0;\n};\n// gzip header length\nvar gzhl = function (o) { return 10 + ((o.filename && (o.filename.length + 1)) || 0); };\n// zlib header\nvar zlh = function (c, o) {\n var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;\n c[0] = 120, c[1] = (fl << 6) | (fl ? (32 - 2 * fl) : 1);\n};\n// zlib valid\nvar zlv = function (d) {\n if ((d[0] & 15) != 8 || (d[0] >>> 4) > 7 || ((d[0] << 8 | d[1]) % 31))\n err(6, 'invalid zlib data');\n if (d[1] & 32)\n err(6, 'invalid zlib data: preset dictionaries not supported');\n};\nfunction AsyncCmpStrm(opts, cb) {\n if (!cb && typeof opts == 'function')\n cb = opts, opts = {};\n this.ondata = cb;\n return opts;\n}\n// zlib footer: -4 to -0 is Adler32\n/**\n * Streaming DEFLATE compression\n */\nvar Deflate = /*#__PURE__*/ (function () {\n function Deflate(opts, cb) {\n if (!cb && typeof opts == 'function')\n cb = opts, opts = {};\n this.ondata = cb;\n this.o = opts || {};\n }\n Deflate.prototype.p = function (c, f) {\n this.ondata(dopt(c, this.o, 0, 0, !f), f);\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Deflate.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n this.d = final;\n this.p(chunk, final || false);\n };\n return Deflate;\n}());\nexport { Deflate };\n/**\n * Asynchronous streaming DEFLATE compression\n */\nvar AsyncDeflate = /*#__PURE__*/ (function () {\n function AsyncDeflate(opts, cb) {\n astrmify([\n bDflt,\n function () { return [astrm, Deflate]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Deflate(ev.data);\n onmessage = astrm(strm);\n }, 6);\n }\n return AsyncDeflate;\n}());\nexport { AsyncDeflate };\nexport function deflate(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);\n}\n/**\n * Compresses data with DEFLATE without any wrapper\n * @param data The data to compress\n * @param opts The compression options\n * @returns The deflated version of the data\n */\nexport function deflateSync(data, opts) {\n return dopt(data, opts || {}, 0, 0);\n}\n/**\n * Streaming DEFLATE decompression\n */\nvar Inflate = /*#__PURE__*/ (function () {\n /**\n * Creates an inflation stream\n * @param cb The callback to call whenever data is inflated\n */\n function Inflate(cb) {\n this.s = {};\n this.p = new u8(0);\n this.ondata = cb;\n }\n Inflate.prototype.e = function (c) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n var l = this.p.length;\n var n = new u8(l + c.length);\n n.set(this.p), n.set(c, l), this.p = n;\n };\n Inflate.prototype.c = function (final) {\n this.d = this.s.i = final || false;\n var bts = this.s.b;\n var dt = inflt(this.p, this.o, this.s);\n this.ondata(slc(dt, bts, this.s.b), this.d);\n this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;\n this.p = slc(this.p, (this.s.p / 8) | 0), this.s.p &= 7;\n };\n /**\n * Pushes a chunk to be inflated\n * @param chunk The chunk to push\n * @param final Whether this is the final chunk\n */\n Inflate.prototype.push = function (chunk, final) {\n this.e(chunk), this.c(final);\n };\n return Inflate;\n}());\nexport { Inflate };\n/**\n * Asynchronous streaming DEFLATE decompression\n */\nvar AsyncInflate = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous inflation stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncInflate(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n function () { return [astrm, Inflate]; }\n ], this, 0, function () {\n var strm = new Inflate();\n onmessage = astrm(strm);\n }, 7);\n }\n return AsyncInflate;\n}());\nexport { AsyncInflate };\nexport function inflate(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt\n ], function (ev) { return pbf(inflateSync(ev.data[0], gu8(ev.data[1]))); }, 1, cb);\n}\n/**\n * Expands DEFLATE data with no wrapper\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function inflateSync(data, out) {\n return inflt(data, out);\n}\n// before you yell at me for not just using extends, my reason is that TS inheritance is hard to workerize.\n/**\n * Streaming GZIP compression\n */\nvar Gzip = /*#__PURE__*/ (function () {\n function Gzip(opts, cb) {\n this.c = crc();\n this.l = 0;\n this.v = 1;\n Deflate.call(this, opts, cb);\n }\n /**\n * Pushes a chunk to be GZIPped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Gzip.prototype.push = function (chunk, final) {\n Deflate.prototype.push.call(this, chunk, final);\n };\n Gzip.prototype.p = function (c, f) {\n this.c.p(c);\n this.l += c.length;\n var raw = dopt(c, this.o, this.v && gzhl(this.o), f && 8, !f);\n if (this.v)\n gzh(raw, this.o), this.v = 0;\n if (f)\n wbytes(raw, raw.length - 8, this.c.d()), wbytes(raw, raw.length - 4, this.l);\n this.ondata(raw, f);\n };\n return Gzip;\n}());\nexport { Gzip };\n/**\n * Asynchronous streaming GZIP compression\n */\nvar AsyncGzip = /*#__PURE__*/ (function () {\n function AsyncGzip(opts, cb) {\n astrmify([\n bDflt,\n gze,\n function () { return [astrm, Deflate, Gzip]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Gzip(ev.data);\n onmessage = astrm(strm);\n }, 8);\n }\n return AsyncGzip;\n}());\nexport { AsyncGzip };\nexport function gzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n gze,\n function () { return [gzipSync]; }\n ], function (ev) { return pbf(gzipSync(ev.data[0], ev.data[1])); }, 2, cb);\n}\n/**\n * Compresses data with GZIP\n * @param data The data to compress\n * @param opts The compression options\n * @returns The gzipped version of the data\n */\nexport function gzipSync(data, opts) {\n if (!opts)\n opts = {};\n var c = crc(), l = data.length;\n c.p(data);\n var d = dopt(data, opts, gzhl(opts), 8), s = d.length;\n return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d;\n}\n/**\n * Streaming GZIP decompression\n */\nvar Gunzip = /*#__PURE__*/ (function () {\n /**\n * Creates a GUNZIP stream\n * @param cb The callback to call whenever data is inflated\n */\n function Gunzip(cb) {\n this.v = 1;\n Inflate.call(this, cb);\n }\n /**\n * Pushes a chunk to be GUNZIPped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Gunzip.prototype.push = function (chunk, final) {\n Inflate.prototype.e.call(this, chunk);\n if (this.v) {\n var s = this.p.length > 3 ? gzs(this.p) : 4;\n if (s >= this.p.length && !final)\n return;\n this.p = this.p.subarray(s), this.v = 0;\n }\n if (final) {\n if (this.p.length < 8)\n err(6, 'invalid gzip data');\n this.p = this.p.subarray(0, -8);\n }\n // necessary to prevent TS from using the closure value\n // This allows for workerization to function correctly\n Inflate.prototype.c.call(this, final);\n };\n return Gunzip;\n}());\nexport { Gunzip };\n/**\n * Asynchronous streaming GZIP decompression\n */\nvar AsyncGunzip = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous GUNZIP stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncGunzip(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n guze,\n function () { return [astrm, Inflate, Gunzip]; }\n ], this, 0, function () {\n var strm = new Gunzip();\n onmessage = astrm(strm);\n }, 9);\n }\n return AsyncGunzip;\n}());\nexport { AsyncGunzip };\nexport function gunzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt,\n guze,\n function () { return [gunzipSync]; }\n ], function (ev) { return pbf(gunzipSync(ev.data[0])); }, 3, cb);\n}\n/**\n * Expands GZIP data\n * @param data The data to decompress\n * @param out Where to write the data. GZIP already encodes the output size, so providing this doesn't save memory.\n * @returns The decompressed version of the data\n */\nexport function gunzipSync(data, out) {\n return inflt(data.subarray(gzs(data), -8), out || new u8(gzl(data)));\n}\n/**\n * Streaming Zlib compression\n */\nvar Zlib = /*#__PURE__*/ (function () {\n function Zlib(opts, cb) {\n this.c = adler();\n this.v = 1;\n Deflate.call(this, opts, cb);\n }\n /**\n * Pushes a chunk to be zlibbed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Zlib.prototype.push = function (chunk, final) {\n Deflate.prototype.push.call(this, chunk, final);\n };\n Zlib.prototype.p = function (c, f) {\n this.c.p(c);\n var raw = dopt(c, this.o, this.v && 2, f && 4, !f);\n if (this.v)\n zlh(raw, this.o), this.v = 0;\n if (f)\n wbytes(raw, raw.length - 4, this.c.d());\n this.ondata(raw, f);\n };\n return Zlib;\n}());\nexport { Zlib };\n/**\n * Asynchronous streaming Zlib compression\n */\nvar AsyncZlib = /*#__PURE__*/ (function () {\n function AsyncZlib(opts, cb) {\n astrmify([\n bDflt,\n zle,\n function () { return [astrm, Deflate, Zlib]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Zlib(ev.data);\n onmessage = astrm(strm);\n }, 10);\n }\n return AsyncZlib;\n}());\nexport { AsyncZlib };\nexport function zlib(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n zle,\n function () { return [zlibSync]; }\n ], function (ev) { return pbf(zlibSync(ev.data[0], ev.data[1])); }, 4, cb);\n}\n/**\n * Compress data with Zlib\n * @param data The data to compress\n * @param opts The compression options\n * @returns The zlib-compressed version of the data\n */\nexport function zlibSync(data, opts) {\n if (!opts)\n opts = {};\n var a = adler();\n a.p(data);\n var d = dopt(data, opts, 2, 4);\n return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;\n}\n/**\n * Streaming Zlib decompression\n */\nvar Unzlib = /*#__PURE__*/ (function () {\n /**\n * Creates a Zlib decompression stream\n * @param cb The callback to call whenever data is inflated\n */\n function Unzlib(cb) {\n this.v = 1;\n Inflate.call(this, cb);\n }\n /**\n * Pushes a chunk to be unzlibbed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Unzlib.prototype.push = function (chunk, final) {\n Inflate.prototype.e.call(this, chunk);\n if (this.v) {\n if (this.p.length < 2 && !final)\n return;\n this.p = this.p.subarray(2), this.v = 0;\n }\n if (final) {\n if (this.p.length < 4)\n err(6, 'invalid zlib data');\n this.p = this.p.subarray(0, -4);\n }\n // necessary to prevent TS from using the closure value\n // This allows for workerization to function correctly\n Inflate.prototype.c.call(this, final);\n };\n return Unzlib;\n}());\nexport { Unzlib };\n/**\n * Asynchronous streaming Zlib decompression\n */\nvar AsyncUnzlib = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous Zlib decompression stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncUnzlib(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n zule,\n function () { return [astrm, Inflate, Unzlib]; }\n ], this, 0, function () {\n var strm = new Unzlib();\n onmessage = astrm(strm);\n }, 11);\n }\n return AsyncUnzlib;\n}());\nexport { AsyncUnzlib };\nexport function unzlib(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt,\n zule,\n function () { return [unzlibSync]; }\n ], function (ev) { return pbf(unzlibSync(ev.data[0], gu8(ev.data[1]))); }, 5, cb);\n}\n/**\n * Expands Zlib data\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function unzlibSync(data, out) {\n return inflt((zlv(data), data.subarray(2, -4)), out);\n}\n// Default algorithm for compression (used because having a known output size allows faster decompression)\nexport { gzip as compress, AsyncGzip as AsyncCompress };\n// Default algorithm for compression (used because having a known output size allows faster decompression)\nexport { gzipSync as compressSync, Gzip as Compress };\n/**\n * Streaming GZIP, Zlib, or raw DEFLATE decompression\n */\nvar Decompress = /*#__PURE__*/ (function () {\n /**\n * Creates a decompression stream\n * @param cb The callback to call whenever data is decompressed\n */\n function Decompress(cb) {\n this.G = Gunzip;\n this.I = Inflate;\n this.Z = Unzlib;\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be decompressed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Decompress.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (!this.s) {\n if (this.p && this.p.length) {\n var n = new u8(this.p.length + chunk.length);\n n.set(this.p), n.set(chunk, this.p.length);\n }\n else\n this.p = chunk;\n if (this.p.length > 2) {\n var _this_1 = this;\n var cb = function () { _this_1.ondata.apply(_this_1, arguments); };\n this.s = (this.p[0] == 31 && this.p[1] == 139 && this.p[2] == 8)\n ? new this.G(cb)\n : ((this.p[0] & 15) != 8 || (this.p[0] >> 4) > 7 || ((this.p[0] << 8 | this.p[1]) % 31))\n ? new this.I(cb)\n : new this.Z(cb);\n this.s.push(this.p, final);\n this.p = null;\n }\n }\n else\n this.s.push(chunk, final);\n };\n return Decompress;\n}());\nexport { Decompress };\n/**\n * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression\n */\nvar AsyncDecompress = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous decompression stream\n * @param cb The callback to call whenever data is decompressed\n */\n function AsyncDecompress(cb) {\n this.G = AsyncGunzip;\n this.I = AsyncInflate;\n this.Z = AsyncUnzlib;\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be decompressed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n AsyncDecompress.prototype.push = function (chunk, final) {\n Decompress.prototype.push.call(this, chunk, final);\n };\n return AsyncDecompress;\n}());\nexport { AsyncDecompress };\nexport function decompress(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return (data[0] == 31 && data[1] == 139 && data[2] == 8)\n ? gunzip(data, opts, cb)\n : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))\n ? inflate(data, opts, cb)\n : unzlib(data, opts, cb);\n}\n/**\n * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function decompressSync(data, out) {\n return (data[0] == 31 && data[1] == 139 && data[2] == 8)\n ? gunzipSync(data, out)\n : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))\n ? inflateSync(data, out)\n : unzlibSync(data, out);\n}\n// flatten a directory structure\nvar fltn = function (d, p, t, o) {\n for (var k in d) {\n var val = d[k], n = p + k;\n if (val instanceof u8)\n t[n] = [val, o];\n else if (Array.isArray(val))\n t[n] = [val[0], mrg(o, val[1])];\n else\n fltn(val, n + '/', t, o);\n }\n};\n// text encoder\nvar te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();\n// text decoder\nvar td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();\n// text decoder stream\nvar tds = 0;\ntry {\n td.decode(et, { stream: true });\n tds = 1;\n}\ncatch (e) { }\n// decode UTF8\nvar dutf8 = function (d) {\n for (var r = '', i = 0;;) {\n var c = d[i++];\n var eb = (c > 127) + (c > 223) + (c > 239);\n if (i + eb > d.length)\n return [r, slc(d, i - 1)];\n if (!eb)\n r += String.fromCharCode(c);\n else if (eb == 3) {\n c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536,\n r += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023));\n }\n else if (eb & 1)\n r += String.fromCharCode((c & 31) << 6 | (d[i++] & 63));\n else\n r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63));\n }\n};\n/**\n * Streaming UTF-8 decoding\n */\nvar DecodeUTF8 = /*#__PURE__*/ (function () {\n /**\n * Creates a UTF-8 decoding stream\n * @param cb The callback to call whenever data is decoded\n */\n function DecodeUTF8(cb) {\n this.ondata = cb;\n if (tds)\n this.t = new TextDecoder();\n else\n this.p = et;\n }\n /**\n * Pushes a chunk to be decoded from UTF-8 binary\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n DecodeUTF8.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n final = !!final;\n if (this.t) {\n this.ondata(this.t.decode(chunk, { stream: true }), final);\n if (final) {\n if (this.t.decode().length)\n err(8);\n this.t = null;\n }\n return;\n }\n if (!this.p)\n err(4);\n var dat = new u8(this.p.length + chunk.length);\n dat.set(this.p);\n dat.set(chunk, this.p.length);\n var _a = dutf8(dat), ch = _a[0], np = _a[1];\n if (final) {\n if (np.length)\n err(8);\n this.p = null;\n }\n else\n this.p = np;\n this.ondata(ch, final);\n };\n return DecodeUTF8;\n}());\nexport { DecodeUTF8 };\n/**\n * Streaming UTF-8 encoding\n */\nvar EncodeUTF8 = /*#__PURE__*/ (function () {\n /**\n * Creates a UTF-8 decoding stream\n * @param cb The callback to call whenever data is encoded\n */\n function EncodeUTF8(cb) {\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be encoded to UTF-8\n * @param chunk The string data to push\n * @param final Whether this is the last chunk\n */\n EncodeUTF8.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n this.ondata(strToU8(chunk), this.d = final || false);\n };\n return EncodeUTF8;\n}());\nexport { EncodeUTF8 };\n/**\n * Converts a string into a Uint8Array for use with compression/decompression methods\n * @param str The string to encode\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\n * not need to be true unless decoding a binary string.\n * @returns The string encoded in UTF-8/Latin-1 binary\n */\nexport function strToU8(str, latin1) {\n if (latin1) {\n var ar_1 = new u8(str.length);\n for (var i = 0; i < str.length; ++i)\n ar_1[i] = str.charCodeAt(i);\n return ar_1;\n }\n if (te)\n return te.encode(str);\n var l = str.length;\n var ar = new u8(str.length + (str.length >> 1));\n var ai = 0;\n var w = function (v) { ar[ai++] = v; };\n for (var i = 0; i < l; ++i) {\n if (ai + 5 > ar.length) {\n var n = new u8(ai + 8 + ((l - i) << 1));\n n.set(ar);\n ar = n;\n }\n var c = str.charCodeAt(i);\n if (c < 128 || latin1)\n w(c);\n else if (c < 2048)\n w(192 | (c >> 6)), w(128 | (c & 63));\n else if (c > 55295 && c < 57344)\n c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),\n w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n else\n w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n }\n return slc(ar, 0, ai);\n}\n/**\n * Converts a Uint8Array to a string\n * @param dat The data to decode to string\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\n * not need to be true unless encoding to binary string.\n * @returns The original UTF-8/Latin-1 string\n */\nexport function strFromU8(dat, latin1) {\n if (latin1) {\n var r = '';\n for (var i = 0; i < dat.length; i += 16384)\n r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));\n return r;\n }\n else if (td)\n return td.decode(dat);\n else {\n var _a = dutf8(dat), out = _a[0], ext = _a[1];\n if (ext.length)\n err(8);\n return out;\n }\n}\n;\n// deflate bit flag\nvar dbf = function (l) { return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0; };\n// skip local zip header\nvar slzh = function (d, b) { return b + 30 + b2(d, b + 26) + b2(d, b + 28); };\n// read zip header\nvar zh = function (d, b, z) {\n 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);\n var _a = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a[0], su = _a[1], off = _a[2];\n return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off];\n};\n// read zip64 extra field\nvar z64e = function (d, b) {\n for (; b2(d, b) != 1; b += 4 + b2(d, b + 2))\n ;\n return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)];\n};\n// extra field length\nvar exfl = function (ex) {\n var le = 0;\n if (ex) {\n for (var k in ex) {\n var l = ex[k].length;\n if (l > 65535)\n err(9);\n le += l + 4;\n }\n }\n return le;\n};\n// write zip header\nvar wzh = function (d, b, f, fn, u, c, ce, co) {\n var fl = fn.length, ex = f.extra, col = co && co.length;\n var exl = exfl(ex);\n wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;\n if (ce != null)\n d[b++] = 20, d[b++] = f.os;\n d[b] = 20, b += 2; // spec compliance? what's that?\n d[b++] = (f.flag << 1) | (c == null && 8), d[b++] = u && 8;\n d[b++] = f.compression & 255, d[b++] = f.compression >> 8;\n var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;\n if (y < 0 || y > 119)\n err(10);\n wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >>> 1)), b += 4;\n if (c != null) {\n wbytes(d, b, f.crc);\n wbytes(d, b + 4, c);\n wbytes(d, b + 8, f.size);\n }\n wbytes(d, b + 12, fl);\n wbytes(d, b + 14, exl), b += 16;\n if (ce != null) {\n wbytes(d, b, col);\n wbytes(d, b + 6, f.attrs);\n wbytes(d, b + 10, ce), b += 14;\n }\n d.set(fn, b);\n b += fl;\n if (exl) {\n for (var k in ex) {\n var exf = ex[k], l = exf.length;\n wbytes(d, b, +k);\n wbytes(d, b + 2, l);\n d.set(exf, b + 4), b += 4 + l;\n }\n }\n if (col)\n d.set(co, b), b += col;\n return b;\n};\n// write zip footer (end of central directory)\nvar wzf = function (o, b, c, d, e) {\n wbytes(o, b, 0x6054B50); // skip disk\n wbytes(o, b + 8, c);\n wbytes(o, b + 10, c);\n wbytes(o, b + 12, d);\n wbytes(o, b + 16, e);\n};\n/**\n * A pass-through stream to keep data uncompressed in a ZIP archive.\n */\nvar ZipPassThrough = /*#__PURE__*/ (function () {\n /**\n * Creates a pass-through stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n */\n function ZipPassThrough(filename) {\n this.filename = filename;\n this.c = crc();\n this.size = 0;\n this.compression = 0;\n }\n /**\n * Processes a chunk and pushes to the output stream. You can override this\n * method in a subclass for custom behavior, but by default this passes\n * the data through. You must call this.ondata(err, chunk, final) at some\n * point in this method.\n * @param chunk The chunk to process\n * @param final Whether this is the last chunk\n */\n ZipPassThrough.prototype.process = function (chunk, final) {\n this.ondata(null, chunk, final);\n };\n /**\n * Pushes a chunk to be added. If you are subclassing this with a custom\n * compression algorithm, note that you must push data from the source\n * file only, pre-compression.\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n ZipPassThrough.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n this.c.p(chunk);\n this.size += chunk.length;\n if (final)\n this.crc = this.c.d();\n this.process(chunk, final || false);\n };\n return ZipPassThrough;\n}());\nexport { ZipPassThrough };\n// I don't extend because TypeScript extension adds 1kB of runtime bloat\n/**\n * Streaming DEFLATE compression for ZIP archives. Prefer using AsyncZipDeflate\n * for better performance\n */\nvar ZipDeflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n * @param opts The compression options\n */\n function ZipDeflate(filename, opts) {\n var _this_1 = this;\n if (!opts)\n opts = {};\n ZipPassThrough.call(this, filename);\n this.d = new Deflate(opts, function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n this.compression = 8;\n this.flag = dbf(opts.level);\n }\n ZipDeflate.prototype.process = function (chunk, final) {\n try {\n this.d.push(chunk, final);\n }\n catch (e) {\n this.ondata(e, null, final);\n }\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n ZipDeflate.prototype.push = function (chunk, final) {\n ZipPassThrough.prototype.push.call(this, chunk, final);\n };\n return ZipDeflate;\n}());\nexport { ZipDeflate };\n/**\n * Asynchronous streaming DEFLATE compression for ZIP archives\n */\nvar AsyncZipDeflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n * @param opts The compression options\n */\n function AsyncZipDeflate(filename, opts) {\n var _this_1 = this;\n if (!opts)\n opts = {};\n ZipPassThrough.call(this, filename);\n this.d = new AsyncDeflate(opts, function (err, dat, final) {\n _this_1.ondata(err, dat, final);\n });\n this.compression = 8;\n this.flag = dbf(opts.level);\n this.terminate = this.d.terminate;\n }\n AsyncZipDeflate.prototype.process = function (chunk, final) {\n this.d.push(chunk, final);\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n AsyncZipDeflate.prototype.push = function (chunk, final) {\n ZipPassThrough.prototype.push.call(this, chunk, final);\n };\n return AsyncZipDeflate;\n}());\nexport { AsyncZipDeflate };\n// TODO: Better tree shaking\n/**\n * A zippable archive to which files can incrementally be added\n */\nvar Zip = /*#__PURE__*/ (function () {\n /**\n * Creates an empty ZIP archive to which files can be added\n * @param cb The callback to call whenever data for the generated ZIP archive\n * is available\n */\n function Zip(cb) {\n this.ondata = cb;\n this.u = [];\n this.d = 1;\n }\n /**\n * Adds a file to the ZIP archive\n * @param file The file stream to add\n */\n Zip.prototype.add = function (file) {\n var _this_1 = this;\n if (!this.ondata)\n err(5);\n // finishing or finished\n if (this.d & 2)\n this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);\n else {\n var f = strToU8(file.filename), fl_1 = f.length;\n var com = file.comment, o = com && strToU8(com);\n var u = fl_1 != file.filename.length || (o && (com.length != o.length));\n var hl_1 = fl_1 + exfl(file.extra) + 30;\n if (fl_1 > 65535)\n this.ondata(err(11, 0, 1), null, false);\n var header = new u8(hl_1);\n wzh(header, 0, file, f, u);\n var chks_1 = [header];\n var pAll_1 = function () {\n for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {\n var chk = chks_2[_i];\n _this_1.ondata(null, chk, false);\n }\n chks_1 = [];\n };\n var tr_1 = this.d;\n this.d = 0;\n var ind_1 = this.u.length;\n var uf_1 = mrg(file, {\n f: f,\n u: u,\n o: o,\n t: function () {\n if (file.terminate)\n file.terminate();\n },\n r: function () {\n pAll_1();\n if (tr_1) {\n var nxt = _this_1.u[ind_1 + 1];\n if (nxt)\n nxt.r();\n else\n _this_1.d = 1;\n }\n tr_1 = 1;\n }\n });\n var cl_1 = 0;\n file.ondata = function (err, dat, final) {\n if (err) {\n _this_1.ondata(err, dat, final);\n _this_1.terminate();\n }\n else {\n cl_1 += dat.length;\n chks_1.push(dat);\n if (final) {\n var dd = new u8(16);\n wbytes(dd, 0, 0x8074B50);\n wbytes(dd, 4, file.crc);\n wbytes(dd, 8, cl_1);\n wbytes(dd, 12, file.size);\n chks_1.push(dd);\n uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file.crc, uf_1.size = file.size;\n if (tr_1)\n uf_1.r();\n tr_1 = 1;\n }\n else if (tr_1)\n pAll_1();\n }\n };\n this.u.push(uf_1);\n }\n };\n /**\n * Ends the process of adding files and prepares to emit the final chunks.\n * This *must* be called after adding all desired files for the resulting\n * ZIP file to work properly.\n */\n Zip.prototype.end = function () {\n var _this_1 = this;\n if (this.d & 2) {\n this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);\n return;\n }\n if (this.d)\n this.e();\n else\n this.u.push({\n r: function () {\n if (!(_this_1.d & 1))\n return;\n _this_1.u.splice(-1, 1);\n _this_1.e();\n },\n t: function () { }\n });\n this.d = 3;\n };\n Zip.prototype.e = function () {\n var bt = 0, l = 0, tl = 0;\n for (var _i = 0, _a = this.u; _i < _a.length; _i++) {\n var f = _a[_i];\n tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);\n }\n var out = new u8(tl + 22);\n for (var _b = 0, _c = this.u; _b < _c.length; _b++) {\n var f = _c[_b];\n wzh(out, bt, f, f.f, f.u, f.c, l, f.o);\n bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;\n }\n wzf(out, bt, this.u.length, tl, l);\n this.ondata(null, out, true);\n this.d = 2;\n };\n /**\n * A method to terminate any internal workers used by the stream. Subsequent\n * calls to add() will fail.\n */\n Zip.prototype.terminate = function () {\n for (var _i = 0, _a = this.u; _i < _a.length; _i++) {\n var f = _a[_i];\n f.t();\n }\n this.d = 2;\n };\n return Zip;\n}());\nexport { Zip };\nexport function zip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n var r = {};\n fltn(data, '', r, opts);\n var k = Object.keys(r);\n var lft = k.length, o = 0, tot = 0;\n var slft = lft, files = new Array(lft);\n var term = [];\n var tAll = function () {\n for (var i = 0; i < term.length; ++i)\n term[i]();\n };\n var cbd = function (a, b) {\n mt(function () { cb(a, b); });\n };\n mt(function () { cbd = cb; });\n var cbf = function () {\n var out = new u8(tot + 22), oe = o, cdl = tot - o;\n tot = 0;\n for (var i = 0; i < slft; ++i) {\n var f = files[i];\n try {\n var l = f.c.length;\n wzh(out, tot, f, f.f, f.u, l);\n var badd = 30 + f.f.length + exfl(f.extra);\n var loc = tot + badd;\n out.set(f.c, loc);\n wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;\n }\n catch (e) {\n return cbd(e, null);\n }\n }\n wzf(out, o, files.length, cdl, oe);\n cbd(null, out);\n };\n if (!lft)\n cbf();\n var _loop_1 = function (i) {\n var fn = k[i];\n var _a = r[fn], file = _a[0], p = _a[1];\n var c = crc(), size = file.length;\n c.p(file);\n var f = strToU8(fn), s = f.length;\n var com = p.comment, m = com && strToU8(com), ms = m && m.length;\n var exl = exfl(p.extra);\n var compression = p.level == 0 ? 0 : 8;\n var cbl = function (e, d) {\n if (e) {\n tAll();\n cbd(e, null);\n }\n else {\n var l = d.length;\n files[i] = mrg(p, {\n size: size,\n crc: c.d(),\n c: d,\n f: f,\n m: m,\n u: s != fn.length || (m && (com.length != ms)),\n compression: compression\n });\n o += 30 + s + exl + l;\n tot += 76 + 2 * (s + exl) + (ms || 0) + l;\n if (!--lft)\n cbf();\n }\n };\n if (s > 65535)\n cbl(err(11, 0, 1), null);\n if (!compression)\n cbl(null, file);\n else if (size < 160000) {\n try {\n cbl(null, deflateSync(file, p));\n }\n catch (e) {\n cbl(e, null);\n }\n }\n else\n term.push(deflate(file, p, cbl));\n };\n // Cannot use lft because it can decrease\n for (var i = 0; i < slft; ++i) {\n _loop_1(i);\n }\n return tAll;\n}\n/**\n * Synchronously creates a ZIP file. Prefer using `zip` for better performance\n * with more than one file.\n * @param data The directory structure for the ZIP archive\n * @param opts The main options, merged with per-file options\n * @returns The generated ZIP archive\n */\nexport function zipSync(data, opts) {\n if (!opts)\n opts = {};\n var r = {};\n var files = [];\n fltn(data, '', r, opts);\n var o = 0;\n var tot = 0;\n for (var fn in r) {\n var _a = r[fn], file = _a[0], p = _a[1];\n var compression = p.level == 0 ? 0 : 8;\n var f = strToU8(fn), s = f.length;\n var com = p.comment, m = com && strToU8(com), ms = m && m.length;\n var exl = exfl(p.extra);\n if (s > 65535)\n err(11);\n var d = compression ? deflateSync(file, p) : file, l = d.length;\n var c = crc();\n c.p(file);\n files.push(mrg(p, {\n size: file.length,\n crc: c.d(),\n c: d,\n f: f,\n m: m,\n u: s != fn.length || (m && (com.length != ms)),\n o: o,\n compression: compression\n }));\n o += 30 + s + exl + l;\n tot += 76 + 2 * (s + exl) + (ms || 0) + l;\n }\n var out = new u8(tot + 22), oe = o, cdl = tot - o;\n for (var i = 0; i < files.length; ++i) {\n var f = files[i];\n wzh(out, f.o, f, f.f, f.u, f.c.length);\n var badd = 30 + f.f.length + exfl(f.extra);\n out.set(f.c, f.o + badd);\n wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);\n }\n wzf(out, o, files.length, cdl, oe);\n return out;\n}\n/**\n * Streaming pass-through decompression for ZIP archives\n */\nvar UnzipPassThrough = /*#__PURE__*/ (function () {\n function UnzipPassThrough() {\n }\n UnzipPassThrough.prototype.push = function (data, final) {\n this.ondata(null, data, final);\n };\n UnzipPassThrough.compression = 0;\n return UnzipPassThrough;\n}());\nexport { UnzipPassThrough };\n/**\n * Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for\n * better performance.\n */\nvar UnzipInflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE decompression that can be used in ZIP archives\n */\n function UnzipInflate() {\n var _this_1 = this;\n this.i = new Inflate(function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n }\n UnzipInflate.prototype.push = function (data, final) {\n try {\n this.i.push(data, final);\n }\n catch (e) {\n this.ondata(e, null, final);\n }\n };\n UnzipInflate.compression = 8;\n return UnzipInflate;\n}());\nexport { UnzipInflate };\n/**\n * Asynchronous streaming DEFLATE decompression for ZIP archives\n */\nvar AsyncUnzipInflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE decompression that can be used in ZIP archives\n */\n function AsyncUnzipInflate(_, sz) {\n var _this_1 = this;\n if (sz < 320000) {\n this.i = new Inflate(function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n }\n else {\n this.i = new AsyncInflate(function (err, dat, final) {\n _this_1.ondata(err, dat, final);\n });\n this.terminate = this.i.terminate;\n }\n }\n AsyncUnzipInflate.prototype.push = function (data, final) {\n if (this.i.terminate)\n data = slc(data, 0);\n this.i.push(data, final);\n };\n AsyncUnzipInflate.compression = 8;\n return AsyncUnzipInflate;\n}());\nexport { AsyncUnzipInflate };\n/**\n * A ZIP archive decompression stream that emits files as they are discovered\n */\nvar Unzip = /*#__PURE__*/ (function () {\n /**\n * Creates a ZIP decompression stream\n * @param cb The callback to call whenever a file in the ZIP archive is found\n */\n function Unzip(cb) {\n this.onfile = cb;\n this.k = [];\n this.o = {\n 0: UnzipPassThrough\n };\n this.p = et;\n }\n /**\n * Pushes a chunk to be unzipped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Unzip.prototype.push = function (chunk, final) {\n var _this_1 = this;\n if (!this.onfile)\n err(5);\n if (!this.p)\n err(4);\n if (this.c > 0) {\n var len = Math.min(this.c, chunk.length);\n var toAdd = chunk.subarray(0, len);\n this.c -= len;\n if (this.d)\n this.d.push(toAdd, !this.c);\n else\n this.k[0].push(toAdd);\n chunk = chunk.subarray(len);\n if (chunk.length)\n return this.push(chunk, final);\n }\n else {\n var f = 0, i = 0, is = void 0, buf = void 0;\n if (!this.p.length)\n buf = chunk;\n else if (!chunk.length)\n buf = this.p;\n else {\n buf = new u8(this.p.length + chunk.length);\n buf.set(this.p), buf.set(chunk, this.p.length);\n }\n var l = buf.length, oc = this.c, add = oc && this.d;\n var _loop_2 = function () {\n var _a;\n var sig = b4(buf, i);\n if (sig == 0x4034B50) {\n f = 1, is = i;\n this_1.d = null;\n this_1.c = 0;\n var bf = b2(buf, i + 6), cmp_1 = b2(buf, i + 8), u = bf & 2048, dd = bf & 8, fnl = b2(buf, i + 26), es = b2(buf, i + 28);\n if (l > i + 30 + fnl + es) {\n var chks_3 = [];\n this_1.k.unshift(chks_3);\n f = 2;\n var sc_1 = b4(buf, i + 18), su_1 = b4(buf, i + 22);\n var fn_1 = strFromU8(buf.subarray(i + 30, i += 30 + fnl), !u);\n if (sc_1 == 4294967295) {\n _a = dd ? [-2] : z64e(buf, i), sc_1 = _a[0], su_1 = _a[1];\n }\n else if (dd)\n sc_1 = -1;\n i += es;\n this_1.c = sc_1;\n var d_1;\n var file_1 = {\n name: fn_1,\n compression: cmp_1,\n start: function () {\n if (!file_1.ondata)\n err(5);\n if (!sc_1)\n file_1.ondata(null, et, true);\n else {\n var ctr = _this_1.o[cmp_1];\n if (!ctr)\n file_1.ondata(err(14, 'unknown compression type ' + cmp_1, 1), null, false);\n d_1 = sc_1 < 0 ? new ctr(fn_1) : new ctr(fn_1, sc_1, su_1);\n d_1.ondata = function (err, dat, final) { file_1.ondata(err, dat, final); };\n for (var _i = 0, chks_4 = chks_3; _i < chks_4.length; _i++) {\n var dat = chks_4[_i];\n d_1.push(dat, false);\n }\n if (_this_1.k[0] == chks_3 && _this_1.c)\n _this_1.d = d_1;\n else\n d_1.push(et, true);\n }\n },\n terminate: function () {\n if (d_1 && d_1.terminate)\n d_1.terminate();\n }\n };\n if (sc_1 >= 0)\n file_1.size = sc_1, file_1.originalSize = su_1;\n this_1.onfile(file_1);\n }\n return \"break\";\n }\n else if (oc) {\n if (sig == 0x8074B50) {\n is = i += 12 + (oc == -2 && 8), f = 3, this_1.c = 0;\n return \"break\";\n }\n else if (sig == 0x2014B50) {\n is = i -= 4, f = 3, this_1.c = 0;\n return \"break\";\n }\n }\n };\n var this_1 = this;\n for (; i < l - 4; ++i) {\n var state_1 = _loop_2();\n if (state_1 === \"break\")\n break;\n }\n this.p = et;\n if (oc < 0) {\n var dat = f ? buf.subarray(0, is - 12 - (oc == -2 && 8) - (b4(buf, is - 16) == 0x8074B50 && 4)) : buf.subarray(0, i);\n if (add)\n add.push(dat, !!f);\n else\n this.k[+(f == 2)].push(dat);\n }\n if (f & 2)\n return this.push(buf.subarray(i), final);\n this.p = buf.subarray(i);\n }\n if (final) {\n if (this.c)\n err(13);\n this.p = null;\n }\n };\n /**\n * Registers a decoder with the stream, allowing for files compressed with\n * the compression type provided to be expanded correctly\n * @param decoder The decoder constructor\n */\n Unzip.prototype.register = function (decoder) {\n this.o[decoder.compression] = decoder;\n };\n return Unzip;\n}());\nexport { Unzip };\nvar mt = typeof queueMicrotask == 'function' ? queueMicrotask : typeof setTimeout == 'function' ? setTimeout : function (fn) { fn(); };\nexport function unzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n var term = [];\n var tAll = function () {\n for (var i = 0; i < term.length; ++i)\n term[i]();\n };\n var files = {};\n var cbd = function (a, b) {\n mt(function () { cb(a, b); });\n };\n mt(function () { cbd = cb; });\n var e = data.length - 22;\n for (; b4(data, e) != 0x6054B50; --e) {\n if (!e || data.length - e > 65558) {\n cbd(err(13, 0, 1), null);\n return tAll;\n }\n }\n ;\n var lft = b2(data, e + 8);\n if (lft) {\n var c = lft;\n var o = b4(data, e + 16);\n var z = o == 4294967295;\n if (z) {\n e = b4(data, e - 12);\n if (b4(data, e) != 0x6064B50) {\n cbd(err(13, 0, 1), null);\n return tAll;\n }\n c = lft = b4(data, e + 32);\n o = b4(data, e + 48);\n }\n var fltr = opts && opts.filter;\n var _loop_3 = function (i) {\n var _a = zh(data, o, z), c_1 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);\n o = no;\n var cbl = function (e, d) {\n if (e) {\n tAll();\n cbd(e, null);\n }\n else {\n if (d)\n files[fn] = d;\n if (!--lft)\n cbd(null, files);\n }\n };\n if (!fltr || fltr({\n name: fn,\n size: sc,\n originalSize: su,\n compression: c_1\n })) {\n if (!c_1)\n cbl(null, slc(data, b, b + sc));\n else if (c_1 == 8) {\n var infl = data.subarray(b, b + sc);\n if (sc < 320000) {\n try {\n cbl(null, inflateSync(infl, new u8(su)));\n }\n catch (e) {\n cbl(e, null);\n }\n }\n else\n term.push(inflate(infl, { size: su }, cbl));\n }\n else\n cbl(err(14, 'unknown compression type ' + c_1, 1), null);\n }\n else\n cbl(null, null);\n };\n for (var i = 0; i < c; ++i) {\n _loop_3(i);\n }\n }\n else\n cbd(null, {});\n return tAll;\n}\n/**\n * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better\n * performance with more than one file.\n * @param data The raw compressed ZIP file\n * @param opts The ZIP extraction options\n * @returns The decompressed files\n */\nexport function unzipSync(data, opts) {\n var files = {};\n var e = data.length - 22;\n for (; b4(data, e) != 0x6054B50; --e) {\n if (!e || data.length - e > 65558)\n err(13);\n }\n ;\n var c = b2(data, e + 8);\n if (!c)\n return {};\n var o = b4(data, e + 16);\n var z = o == 4294967295;\n if (z) {\n e = b4(data, e - 12);\n if (b4(data, e) != 0x6064B50)\n err(13);\n c = b4(data, e + 32);\n o = b4(data, e + 48);\n }\n var fltr = opts && opts.filter;\n for (var i = 0; i < c; ++i) {\n var _a = zh(data, o, z), c_2 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);\n o = no;\n if (!fltr || fltr({\n name: fn,\n size: sc,\n originalSize: su,\n compression: c_2\n })) {\n if (!c_2)\n files[fn] = slc(data, b, b + sc);\n else if (c_2 == 8)\n files[fn] = inflateSync(data.subarray(b, b + sc), new u8(su));\n else\n err(14, 'unknown compression type ' + c_2);\n }\n }\n return files;\n}\n"],"names":["SoraE2EE","constructor","RTCRtpSender","prototype","createEncodedStreams","Error","this","worker","onWorkerDisconnect","startWorker","workerScript","atob","Worker","URL","createObjectURL","Blob","type","onmessage","event","operation","data","clearWorker","postMessage","terminateWorker","terminate","async","preKeyBundle","window","e2ee","init","setupSenderTransform","sender","track","senderStreams","readableStream","readable","writableStream","writable","message","setupReceiverTransform","receiver","receiverStreams","postRemoteSecretKeyMaterials","result","remoteSecretKeyMaterials","postRemoveRemoteDeriveKey","connectionId","postSelfSecretKeyMaterial","selfConnectionId","selfKeyId","selfSecretKeyMaterial","waitingTime","startSession","err","identityKey","signedPreKey","preKeySignature","stopSession","receiveMessage","start","addPreKeyBundle","selfFingerprint","remoteFingerprints","static","wasmUrl","undefined","console","warn","global","self","require","fs","Object","keys","enosys","code","outputBuf","constants","O_WRONLY","O_RDWR","O_CREAT","O_TRUNC","O_APPEND","O_EXCL","writeSync","fd","buf","decoder","decode","nl","lastIndexOf","log","substr","length","write","offset","position","callback","chmod","path","mode","chown","uid","gid","close","fchmod","fchown","fstat","fsync","ftruncate","lchown","link","lstat","mkdir","perm","open","flags","read","buffer","readdir","readlink","rename","from","to","rmdir","stat","symlink","truncate","unlink","utimes","atime","mtime","process","getuid","getgid","geteuid","getegid","getgroups","pid","ppid","umask","cwd","chdir","crypto","nodeCrypto","getRandomValues","b","randomFillSync","performance","now","sec","nsec","hrtime","TextEncoder","TextDecoder","encoder","Go","argv","env","exit","_exitPromise","Promise","resolve","_resolveExitPromise","_pendingEvent","_scheduledTimeouts","Map","_nextCallbackTimeoutID","setInt64","addr","v","mem","setUint32","Math","floor","getInt64","getUint32","getInt32","loadValue","f","getFloat64","isNaN","id","_values","storeValue","nanHead","setFloat64","_ids","get","_idPool","pop","_goRefCounts","set","typeFlag","loadSlice","array","len","Uint8Array","_inst","exports","loadSliceOfValues","a","Array","i","loadString","saddr","DataView","timeOrigin","Date","importObject","go","sp","exited","p","n","msec","getTime","setInt32","setTimeout","_resume","has","clearTimeout","delete","push","Reflect","getsp","deleteProperty","m","args","apply","setUint8","construct","parseInt","str","encode","String","dst","src","Uint8ClampedArray","toCopy","subarray","debug","value","instance","NaN","fill","Infinity","strPtr","ptr","bytes","argc","argvPtrs","forEach","arg","sort","key","run","resume","_makeFuncWrapper","arguments","main","module","versions","electron","error","slice","assign","TMPDIR","tmpdir","WebAssembly","instantiate","readFileSync","then","on","catch","instantiateStreaming","fetch","version","u8","u16","Uint16Array","u32","Uint32Array","fleb","fdeb","clim","freb","eb","r","j","_a","fl","revfl","_b","revfd","rev","x","hMap","cd","mb","s","l","co","le","rvb","sv","r_1","flt","fdt","flm","flrm","fdm","fdrm","max","bits","d","o","bits16","shft","slc","e","ec","ind","msg","nt","captureStackTrace","wbits","wbits16","hTree","t","t2","et","i0","i1","i2","maxSym","tr","mbt","ln","dt","lft","cst","i2_1","i2_2","i2_3","lc","c","cl","cli","cln","cls","w","clen","cf","wfblk","out","pos","dat","wblk","final","syms","lf","df","li","bs","bl","dlt","mlb","ddt","mdb","_c","lclt","nlc","_d","lcdt","ndc","lcfreq","_e","lct","mlcb","nlcc","lm","ll","dm","dl","flen","ftlen","dtlen","llm","lcts","it","clct","deo","dopt","opt","pre","post","st","lvl","plvl","lst","ceil","msk_1","prev","head","bs1_1","bs2_1","hsh","lc_1","wi","hv","imod","pimod","rem","ch_1","dif","maxn","min","maxd","ml","mmd","md","ti","lin","din","dflt","level","zlibSync","opts","adler","lv","zlh","wbytes","unzlibSync","sl","noBuf","noSt","cbuf","nbuf","bt","lbt","dbt","tbts","hLit","hcLen","tl","ldt","clt","clb","clbmsk","clm","lt","lms","dms","lpos","sym","add","dsym","end","inflt","td","stream"],"mappings":"qOAWA,MAAMA,EACFC,cAII,MADoCC,aAAaC,UAAUC,qBAEvD,MAAM,IAAIC,MAAM,0CAEpBC,KAAKC,OAAS,KACdD,KAAKE,mBAAqB,KAG9BC,cAEI,MAAMC,EAAeC,KAfP,wjwBAgBdL,KAAKC,OAAS,IAAIK,OAAOC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,GAAe,CAAEM,KAAM,6BAC9EV,KAAKC,OAAOU,UAAaC,IACrB,MAAMC,UAAEA,GAAcD,EAAME,KACV,eAAdD,GAAiE,mBAA5Bb,KAAKE,oBAC1CF,KAAKE,sBAKjBa,cACQf,KAAKC,QACLD,KAAKC,OAAOe,YAAY,CACpBN,KAAM,UAKlBO,kBACQjB,KAAKC,QACLD,KAAKC,OAAOiB,YAIpBC,aACI,MAAMC,aAAEA,SAAuBC,OAAOC,KAAKC,OAC3C,OAAOH,EAEXI,qBAAqBC,GACjB,IAAKA,EAAOC,MACR,OAGJ,MAAMC,EAAgBF,EAAO3B,uB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AflT,aAA4C,IAAIA,YAGhE,IACIkT,EAAGpX,OAAOmP,EAAI,CAAEkI,QAAQ,IAClB,EAEV,MAAO7I"} \ No newline at end of file +{"version":3,"file":"sora.min.js","sources":["../packages/e2ee/dist/sora_e2ee.mjs","../packages/go-wasm/src/wasm_exec.js","../node_modules/fflate/esm/browser.js"],"sourcesContent":["/**\n * @sora/e2ee\n * WebRTC SFU Sora JavaScript E2EE Library\n * @version: 2021.1.0\n * @author: Shiguredo Inc.\n * @license: Apache-2.0\n **/\n\nimport WasmExec from '@sora/go-wasm';\n\nconst WORKER_SCRIPT = \"InVzZSBzdHJpY3QiOwovKiBlc2xpbnQtZGlzYWJsZSBAdHlwZXNjcmlwdC1lc2xpbnQvbm8tdW51c2VkLXZhcnMgKi8KY29uc3QgY29ubmVjdGlvbklkTGVuZ3RoID0gMjY7CmZ1bmN0aW9uIGJ5dGVDb3VudChuKSB7CiAgICBpZiAobiA9PSAwKSB7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9CiAgICAvLyBsb2cyNTYoeCkgPSBsb2coeCkgLyBsb2coMjU2KQogICAgcmV0dXJuIE1hdGguZmxvb3IoTWF0aC5sb2cobikgLyBNYXRoLmxvZygyICoqIDgpICsgMSk7Cn0KZnVuY3Rpb24gYXJyYXlCdWZmZXJUb051bWJlcihhcnJheUJ1ZmZlcikgewogICAgLy8gMzJiaXQg44G+44Gn44KS5oOz5a6aIChCaWdJbnQg44G444Gu5pu444GN5o+b44GI5pmC44Gr6KaB5L+u5q2jKQogICAgY29uc3QgbmV3QXJyYXlCdWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIoVWludDMyQXJyYXkuQllURVNfUEVSX0VMRU1FTlQpOwogICAgY29uc3QgbmV3RGF0YVZpZXcgPSBuZXcgRGF0YVZpZXcobmV3QXJyYXlCdWZmZXIpOwogICAgY29uc3QgZGF0YVZpZXcgPSBuZXcgRGF0YVZpZXcoYXJyYXlCdWZmZXIpOwogICAgY29uc3QgcGFkZGluZ0x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sKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgZ2VuZXJhdGVXcml0ZUlWKG1hdGVyaWFsKS50aGVuKCh3cml0ZUlWKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgc2V0V3JpdGVJVihzZWxmQ29ubmVjdGlvbklkLCBzZWxmS2V5SWQsIHdyaXRlSVYpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQodGltZW91dElkKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSwgd2FpdGluZ1RpbWUgfHwgMCk7CiAgICAgICAgLy8gVE9ETzogKzEwMDAg44Gn6Y2155Sf5oiQ5b6M44Gr5a6f6KGM44GV44KM44KL44KI44GG44Gr44GX44Gm44GE44KL44GM55+t44GE5aC05ZCI44Gv5Ly444Gw44GZCiAgICAgICAgY29uc3QgcmVtb3ZhbFdhaXRpbmdUaW1lID0gKHdhaXRpbmdUaW1lIHx8IDApICsgMTAwMDsKICAgICAgICBpZiAocmVtb3ZhbFRpbWVvdXRJZCkgewogICAgICAgICAgICAvLyDli5XkvZzmuIjjgb/jgr/jgqTjg57jg7zmnInjgooKICAgICAgICAgICAgaWYgKHdhaXRpbmdUaW1lKSB7CiAgICAgICAgICAgICAgICAvLyBjb25uZWN0aW9uLmRlc3Ryb3llZAogICAgICAgICAgICAgICAgY2xlYXJUaW1lb3V0KHJlbW92YWxUaW1lb3V0SWQpOwogICAgICAgICAgICAgICAgcmVtb3ZhbFRpbWVvdXRJZCA9IHNldFRpbWVvdXQoKCkgPT4gewogICAgICAgICAgICAgICAgICAgIHJlbW92ZU9sZFJlbW90ZURlcml2ZUtleXMoKTsKICAgICAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQocmVtb3ZhbFRpbWVvdXRJZCk7CiAgICAgICAgICAgICAgICAgICAgcmVtb3ZhbFRpbWVvdXRJZCA9IDA7CiAgICAgICAgICAgICAgICB9LCByZW1vdmFsV2FpdGluZ1RpbWUpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICAvLyDli5XkvZzmuIjjgb/jgr/jgqTjg57jg7zjgarjgZcKICAgICAgICAgICAgLy8gY29ubmVjdGlvbi5jcmVhdGVkIOOBruWgtOWQiOOCguWwkeOBl+Wun+ihjOOCkumBheOCieOBm+OCiwogICAgICAgICAgICByZW1vdmFsVGltZW91dElkID0gc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICByZW1vdmVPbGRSZW1vdGVEZXJpdmVLZXlzKCk7CiAgICAgICAgICAgICAgICBjbGVhclRpbWVvdXQocmVtb3ZhbFRpbWVvdXRJZCk7CiAgICAgICAgICAgICAgICByZW1vdmFsVGltZW91dElkID0gMDsKICAgICAgICAgICAgfSwgcmVtb3ZhbFdhaXRpbmdUaW1lKTsKICAgICAgICB9CiAgICB9CiAgICBlbHNlIGlmICh0eXBlID09PSAicmVtb3RlU2VjcmV0S2V5TWF0ZXJpYWxzIikgewogICAgICAgIGNvbnN0IHsgcmVtb3RlU2VjcmV0S2V5TWF0ZXJpYWxzIH0gPSBldmVudC5kYXRhOwogICAgICAgIGZvciAoY29uc3QgW2Nvbm5lY3Rpb25JZCwgcmVtb3RlU2VjcmV0S2V5TWF0ZXJpYWxdIG9mIE9iamVjdC5lbnRyaWVzKHJlbW90ZVNlY3JldEtleU1hdGVyaWFscykpIHsKICAgICAgICAgICAgY29uc3QgeyBrZXlJZCwgc2VjcmV0S2V5TWF0ZXJpYWwgfSA9IHJlbW90ZVNlY3JldEtleU1hdGVyaWFsOwogICAgICAgICAgICBjcnlwdG8uc3VidGxlCiAgICAgICAgICAgICAgICAuaW1wb3J0S2V5KCJyYXciLCBzZWNyZXRLZXlNYXRlcmlhbC5idWZmZXIsICJIS0RGIiwgZmFsc2UsIFsiZGVyaXZlQml0cyIsICJkZXJpdmVLZXkiXSkKICAgICAgICAgICAgICAgIC50aGVuKChtYXRlcmlhbCkgPT4gewogICAgICAgICAgICAgICAgZ2VuZXJhdGVEZXJpdmVLZXkobWF0ZXJpYWwpLnRoZW4oKGRlcml2ZUtleSkgPT4gewogICAgICAgICAgICAgICAgICAgIHNldFJlbW90ZURlcml2ZUtleShjb25uZWN0aW9uSWQsIGtleUlkLCBkZXJpdmVLZXkpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBnZW5lcmF0ZVdyaXRlSVYobWF0ZXJpYWwpLnRoZW4oKHdyaXRlSVYpID0+IHsKICAgICAgICAgICAgICAgICAgICBzZXRXcml0ZUlWKGNvbm5lY3Rpb25JZCwga2V5SWQsIHdyaXRlSVYpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBzZXRMYXRlc3RSZW1vdGVLZXlJZChjb25uZWN0aW9uSWQsIGtleUlkKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfQogICAgfQogICAgZWxzZSBpZiAodHlwZSA9PT0gInJlbW92ZVJlbW90ZURlcml2ZUtleSIpIHsKICAgICAgICBjb25zdCB7IGNvbm5lY3Rpb25JZCB9ID0gZXZlbnQuZGF0YTsKICAgICAgICByZW1vdmVEZXJpdmVLZXkoY29ubmVjdGlvbklkKTsKICAgIH0KICAgIGVsc2UgaWYgKHR5cGUgPT09ICJlbmNyeXB0IikgewogICAgICAgIGNvbnN0IHsgcmVhZGFibGVTdHJlYW0sIHdyaXRhYmxlU3RyZWFtIH0gPSBldmVudC5kYXRhOwogICAgICAgIGNvbnN0IHRyYW5zZm9ybVN0cmVhbSA9IG5ldyBUcmFuc2Zvcm1TdHJlYW0oewogICAgICAgICAgICB0cmFuc2Zvcm06IGVuY3J5cHRGdW5jdGlvbiwKICAgICAgICB9KTsKICAgICAgICByZWFkYWJsZVN0cmVhbS5waXBlVGhyb3VnaCh0cmFuc2Zvcm1TdHJlYW0pLnBpcGVUbyh3cml0YWJsZVN0cmVhbSk7CiAgICB9CiAgICBlbHNlIGlmICh0eXBlID09PSAiZGVjcnlwdCIpIHsKICAgICAgICBjb25zdCB7IHJlYWRhYmxlU3RyZWFtLCB3cml0YWJsZVN0cmVhbSB9ID0gZXZlbnQuZGF0YTsKICAgICAgICBjb25zdCB0cmFuc2Zvcm1TdHJlYW0gPSBuZXcgVHJhbnNmb3JtU3RyZWFtKHsKICAgICAgICAgICAgdHJhbnNmb3JtOiBkZWNyeXB0RnVuY3Rpb24sCiAgICAgICAgfSk7CiAgICAgICAgcmVhZGFibGVTdHJlYW0ucGlwZVRocm91Z2godHJhbnNmb3JtU3RyZWFtKS5waXBlVG8od3JpdGFibGVTdHJlYW0pOwogICAgfQogICAgZWxzZSBpZiAodHlwZSA9PT0gImNsZWFyIikgewogICAgICAgIGNvdW50TWFwLmNsZWFyKCk7CiAgICAgICAgd3JpdGVJVk1hcC5jbGVhcigpOwogICAgICAgIHJlbW90ZURlcml2ZUtleU1hcC5jbGVhcigpOwogICAgICAgIGxhdGVzdFJlbW90ZUtleUlkTWFwLmNsZWFyKCk7CiAgICAgICAgc2VsZkRlcml2ZUtleU1hcC5jbGVhcigpOwogICAgfQp9Owo=\";\nclass SoraE2EE {\n constructor() {\n // 対応しているかどうかの判断\n // @ts-ignore トライアル段階の API なので無視する\n const supportsInsertableStreams = !!RTCRtpSender.prototype.createEncodedStreams;\n if (!supportsInsertableStreams) {\n throw new Error(\"E2EE is not supported in this browser.\");\n }\n this.worker = null;\n this.onWorkerDisconnect = null;\n }\n // worker を起動する\n startWorker() {\n // ワーカーを起動する\n const workerScript = atob(WORKER_SCRIPT);\n this.worker = new Worker(URL.createObjectURL(new Blob([workerScript], { type: \"application/javascript\" })));\n this.worker.onmessage = (event) => {\n const { operation } = event.data;\n if (operation === \"disconnect\" && typeof this.onWorkerDisconnect === \"function\") {\n this.onWorkerDisconnect();\n }\n };\n }\n // worker の掃除をする\n clearWorker() {\n if (this.worker) {\n this.worker.postMessage({\n type: \"clear\",\n });\n }\n }\n // worker を終了する\n terminateWorker() {\n if (this.worker) {\n this.worker.terminate();\n }\n }\n // 初期化処理\n async init() {\n const { preKeyBundle } = await window.e2ee.init();\n return preKeyBundle;\n }\n setupSenderTransform(sender) {\n if (!sender.track) {\n return;\n }\n // @ts-ignore トライアル段階の API なので無視する\n const senderStreams = sender.createEncodedStreams();\n const readableStream = senderStreams.readableStream || senderStreams.readable;\n const writableStream = senderStreams.writableStream || senderStreams.writable;\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n const message = {\n type: \"encrypt\",\n readableStream: readableStream,\n writableStream: writableStream,\n };\n this.worker.postMessage(message, [readableStream, writableStream]);\n }\n setupReceiverTransform(receiver) {\n // @ts-ignore トライアル段階の API なので無視する\n const receiverStreams = receiver.createEncodedStreams();\n const readableStream = receiverStreams.readableStream || receiverStreams.readable;\n const writableStream = receiverStreams.writableStream || receiverStreams.writable;\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n const message = {\n type: \"decrypt\",\n readableStream: readableStream,\n writableStream: writableStream,\n };\n this.worker.postMessage(message, [readableStream, writableStream]);\n }\n postRemoteSecretKeyMaterials(result) {\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n this.worker.postMessage({\n type: \"remoteSecretKeyMaterials\",\n remoteSecretKeyMaterials: result.remoteSecretKeyMaterials,\n });\n }\n postRemoveRemoteDeriveKey(connectionId) {\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n this.worker.postMessage({\n type: \"removeRemoteDeriveKey\",\n connectionId: connectionId,\n });\n }\n postSelfSecretKeyMaterial(selfConnectionId, selfKeyId, selfSecretKeyMaterial, waitingTime = 0) {\n if (!this.worker) {\n throw new Error(\"Worker is null. Call startWorker in advance.\");\n }\n this.worker.postMessage({\n type: \"selfSecretKeyMaterial\",\n selfConnectionId: selfConnectionId,\n selfKeyId: selfKeyId,\n selfSecretKeyMaterial: selfSecretKeyMaterial,\n waitingTime: waitingTime,\n });\n }\n startSession(connectionId, preKeyBundle) {\n const [result, err] = window.e2ee.startSession(connectionId, preKeyBundle.identityKey, preKeyBundle.signedPreKey, preKeyBundle.preKeySignature);\n if (err) {\n throw err;\n }\n return result;\n }\n stopSession(connectionId) {\n const [result, err] = window.e2ee.stopSession(connectionId);\n if (err) {\n throw err;\n }\n return result;\n }\n receiveMessage(message) {\n const [result, err] = window.e2ee.receiveMessage(message);\n if (err) {\n throw err;\n }\n return result;\n }\n start(selfConnectionId) {\n const [result, err] = window.e2ee.start(selfConnectionId);\n if (err) {\n throw err;\n }\n return result;\n }\n addPreKeyBundle(connectionId, preKeyBundle) {\n const err = window.e2ee.addPreKeyBundle(connectionId, preKeyBundle.identityKey, preKeyBundle.signedPreKey, preKeyBundle.preKeySignature);\n if (err) {\n throw err;\n }\n }\n selfFingerprint() {\n return window.e2ee.selfFingerprint();\n }\n remoteFingerprints() {\n return window.e2ee.remoteFingerprints();\n }\n static async loadWasm(wasmUrl) {\n if (!window.e2ee === undefined) {\n console.warn(\"E2ee wasm is already loaded. Will not be reload.\");\n return;\n }\n WasmExec();\n if (!window.Go) {\n throw new Error(`Failed to load module Go. window.Go is ${window.Go}.`);\n }\n const go = new Go();\n const { instance } = await WebAssembly.instantiateStreaming(fetch(wasmUrl), go.importObject);\n go.run(instance);\n if (!window.e2ee) {\n throw new Error(`Failed to load module e2ee. window.e2ee is ${window.e2ee}.`);\n }\n }\n static version() {\n return \"2021.1.0\";\n }\n static wasmVersion() {\n return window.e2ee.version();\n }\n}\n\nexport { SoraE2EE as default };\n","// Copyright 2018 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\nexport default function () {\n\t(() => {\n\t\t// Map multiple JavaScript environments to a single common API,\n\t\t// preferring web standards over Node.js API.\n\t\t//\n\t\t// Environments considered:\n\t\t// - Browsers\n\t\t// - Node.js\n\t\t// - Electron\n\t\t// - Parcel\n\t\n\t\tif (typeof global !== \"undefined\") {\n\t\t\t// global already exists\n\t\t} else if (typeof window !== \"undefined\") {\n\t\t\twindow.global = window;\n\t\t} else if (typeof self !== \"undefined\") {\n\t\t\tself.global = self;\n\t\t} else {\n\t\t\tthrow new Error(\"cannot export Go (neither global, window nor self is defined)\");\n\t\t}\n\t\n\t\tif (!global.require && typeof require !== \"undefined\") {\n\t\t\tglobal.require = require;\n\t\t}\n\t\n\t\tif (!global.fs && global.require) {\n\t\t\tconst fs = require(\"fs\");\n\t\t\tif (Object.keys(fs) !== 0) {\n\t\t\t\tglobal.fs = fs;\n\t\t\t}\n\t\t}\n\t\n\t\tconst enosys = () => {\n\t\t\tconst err = new Error(\"not implemented\");\n\t\t\terr.code = \"ENOSYS\";\n\t\t\treturn err;\n\t\t};\n\t\n\t\tif (!global.fs) {\n\t\t\tlet outputBuf = \"\";\n\t\t\tglobal.fs = {\n\t\t\t\tconstants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused\n\t\t\t\twriteSync(fd, buf) {\n\t\t\t\t\toutputBuf += decoder.decode(buf);\n\t\t\t\t\tconst nl = outputBuf.lastIndexOf(\"\\n\");\n\t\t\t\t\tif (nl != -1) {\n\t\t\t\t\t\tconsole.log(outputBuf.substr(0, nl));\n\t\t\t\t\t\toutputBuf = outputBuf.substr(nl + 1);\n\t\t\t\t\t}\n\t\t\t\t\treturn buf.length;\n\t\t\t\t},\n\t\t\t\twrite(fd, buf, offset, length, position, callback) {\n\t\t\t\t\tif (offset !== 0 || length !== buf.length || position !== null) {\n\t\t\t\t\t\tcallback(enosys());\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst n = this.writeSync(fd, buf);\n\t\t\t\t\tcallback(null, n);\n\t\t\t\t},\n\t\t\t\tchmod(path, mode, callback) { callback(enosys()); },\n\t\t\t\tchown(path, uid, gid, callback) { callback(enosys()); },\n\t\t\t\tclose(fd, callback) { callback(enosys()); },\n\t\t\t\tfchmod(fd, mode, callback) { callback(enosys()); },\n\t\t\t\tfchown(fd, uid, gid, callback) { callback(enosys()); },\n\t\t\t\tfstat(fd, callback) { callback(enosys()); },\n\t\t\t\tfsync(fd, callback) { callback(null); },\n\t\t\t\tftruncate(fd, length, callback) { callback(enosys()); },\n\t\t\t\tlchown(path, uid, gid, callback) { callback(enosys()); },\n\t\t\t\tlink(path, link, callback) { callback(enosys()); },\n\t\t\t\tlstat(path, callback) { callback(enosys()); },\n\t\t\t\tmkdir(path, perm, callback) { callback(enosys()); },\n\t\t\t\topen(path, flags, mode, callback) { callback(enosys()); },\n\t\t\t\tread(fd, buffer, offset, length, position, callback) { callback(enosys()); },\n\t\t\t\treaddir(path, callback) { callback(enosys()); },\n\t\t\t\treadlink(path, callback) { callback(enosys()); },\n\t\t\t\trename(from, to, callback) { callback(enosys()); },\n\t\t\t\trmdir(path, callback) { callback(enosys()); },\n\t\t\t\tstat(path, callback) { callback(enosys()); },\n\t\t\t\tsymlink(path, link, callback) { callback(enosys()); },\n\t\t\t\ttruncate(path, length, callback) { callback(enosys()); },\n\t\t\t\tunlink(path, callback) { callback(enosys()); },\n\t\t\t\tutimes(path, atime, mtime, callback) { callback(enosys()); },\n\t\t\t};\n\t\t}\n\t\n\t\tif (!global.process) {\n\t\t\tglobal.process = {\n\t\t\t\tgetuid() { return -1; },\n\t\t\t\tgetgid() { return -1; },\n\t\t\t\tgeteuid() { return -1; },\n\t\t\t\tgetegid() { return -1; },\n\t\t\t\tgetgroups() { throw enosys(); },\n\t\t\t\tpid: -1,\n\t\t\t\tppid: -1,\n\t\t\t\tumask() { throw enosys(); },\n\t\t\t\tcwd() { throw enosys(); },\n\t\t\t\tchdir() { throw enosys(); },\n\t\t\t}\n\t\t}\n\t\n\t\tif (!global.crypto) {\n\t\t\tconst nodeCrypto = require(\"crypto\");\n\t\t\tglobal.crypto = {\n\t\t\t\tgetRandomValues(b) {\n\t\t\t\t\tnodeCrypto.randomFillSync(b);\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\n\t\tif (!global.performance) {\n\t\t\tglobal.performance = {\n\t\t\t\tnow() {\n\t\t\t\t\tconst [sec, nsec] = process.hrtime();\n\t\t\t\t\treturn sec * 1000 + nsec / 1000000;\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\n\t\tif (!global.TextEncoder) {\n\t\t\tglobal.TextEncoder = require(\"util\").TextEncoder;\n\t\t}\n\t\n\t\tif (!global.TextDecoder) {\n\t\t\tglobal.TextDecoder = require(\"util\").TextDecoder;\n\t\t}\n\t\n\t\t// End of polyfills for common API.\n\t\n\t\tconst encoder = new TextEncoder(\"utf-8\");\n\t\tconst decoder = new TextDecoder(\"utf-8\");\n\t\n\t\tglobal.Go = class {\n\t\t\tconstructor() {\n\t\t\t\tthis.argv = [\"js\"];\n\t\t\t\tthis.env = {};\n\t\t\t\tthis.exit = (code) => {\n\t\t\t\t\tif (code !== 0) {\n\t\t\t\t\t\tconsole.warn(\"exit code:\", code);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tthis._exitPromise = new Promise((resolve) => {\n\t\t\t\t\tthis._resolveExitPromise = resolve;\n\t\t\t\t});\n\t\t\t\tthis._pendingEvent = null;\n\t\t\t\tthis._scheduledTimeouts = new Map();\n\t\t\t\tthis._nextCallbackTimeoutID = 1;\n\t\n\t\t\t\tconst setInt64 = (addr, v) => {\n\t\t\t\t\tthis.mem.setUint32(addr + 0, v, true);\n\t\t\t\t\tthis.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n\t\t\t\t}\n\t\n\t\t\t\tconst getInt64 = (addr) => {\n\t\t\t\t\tconst low = this.mem.getUint32(addr + 0, true);\n\t\t\t\t\tconst high = this.mem.getInt32(addr + 4, true);\n\t\t\t\t\treturn low + high * 4294967296;\n\t\t\t\t}\n\t\n\t\t\t\tconst loadValue = (addr) => {\n\t\t\t\t\tconst f = this.mem.getFloat64(addr, true);\n\t\t\t\t\tif (f === 0) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\tif (!isNaN(f)) {\n\t\t\t\t\t\treturn f;\n\t\t\t\t\t}\n\t\n\t\t\t\t\tconst id = this.mem.getUint32(addr, true);\n\t\t\t\t\treturn this._values[id];\n\t\t\t\t}\n\t\n\t\t\t\tconst storeValue = (addr, v) => {\n\t\t\t\t\tconst nanHead = 0x7FF80000;\n\t\n\t\t\t\t\tif (typeof v === \"number\" && v !== 0) {\n\t\t\t\t\t\tif (isNaN(v)) {\n\t\t\t\t\t\t\tthis.mem.setUint32(addr + 4, nanHead, true);\n\t\t\t\t\t\t\tthis.mem.setUint32(addr, 0, true);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.mem.setFloat64(addr, v, true);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (v === undefined) {\n\t\t\t\t\t\tthis.mem.setFloat64(addr, 0, true);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\n\t\t\t\t\tlet id = this._ids.get(v);\n\t\t\t\t\tif (id === undefined) {\n\t\t\t\t\t\tid = this._idPool.pop();\n\t\t\t\t\t\tif (id === undefined) {\n\t\t\t\t\t\t\tid = this._values.length;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis._values[id] = v;\n\t\t\t\t\t\tthis._goRefCounts[id] = 0;\n\t\t\t\t\t\tthis._ids.set(v, id);\n\t\t\t\t\t}\n\t\t\t\t\tthis._goRefCounts[id]++;\n\t\t\t\t\tlet typeFlag = 0;\n\t\t\t\t\tswitch (typeof v) {\n\t\t\t\t\t\tcase \"object\":\n\t\t\t\t\t\t\tif (v !== null) {\n\t\t\t\t\t\t\t\ttypeFlag = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"string\":\n\t\t\t\t\t\t\ttypeFlag = 2;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"symbol\":\n\t\t\t\t\t\t\ttypeFlag = 3;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"function\":\n\t\t\t\t\t\t\ttypeFlag = 4;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tthis.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n\t\t\t\t\tthis.mem.setUint32(addr, id, true);\n\t\t\t\t}\n\t\n\t\t\t\tconst loadSlice = (addr) => {\n\t\t\t\t\tconst array = getInt64(addr + 0);\n\t\t\t\t\tconst len = getInt64(addr + 8);\n\t\t\t\t\treturn new Uint8Array(this._inst.exports.mem.buffer, array, len);\n\t\t\t\t}\n\t\n\t\t\t\tconst loadSliceOfValues = (addr) => {\n\t\t\t\t\tconst array = getInt64(addr + 0);\n\t\t\t\t\tconst len = getInt64(addr + 8);\n\t\t\t\t\tconst a = new Array(len);\n\t\t\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\t\t\ta[i] = loadValue(array + i * 8);\n\t\t\t\t\t}\n\t\t\t\t\treturn a;\n\t\t\t\t}\n\t\n\t\t\t\tconst loadString = (addr) => {\n\t\t\t\t\tconst saddr = getInt64(addr + 0);\n\t\t\t\t\tconst len = getInt64(addr + 8);\n\t\t\t\t\treturn decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n\t\t\t\t}\n\t\n\t\t\t\tconst timeOrigin = Date.now() - performance.now();\n\t\t\t\tthis.importObject = {\n\t\t\t\t\tgo: {\n\t\t\t\t\t\t// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n\t\t\t\t\t\t// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n\t\t\t\t\t\t// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n\t\t\t\t\t\t// This changes the SP, thus we have to update the SP used by the imported function.\n\t\n\t\t\t\t\t\t// func wasmExit(code int32)\n\t\t\t\t\t\t\"runtime.wasmExit\": (sp) => {\n\t\t\t\t\t\t\tconst code = this.mem.getInt32(sp + 8, true);\n\t\t\t\t\t\t\tthis.exited = true;\n\t\t\t\t\t\t\tdelete this._inst;\n\t\t\t\t\t\t\tdelete this._values;\n\t\t\t\t\t\t\tdelete this._goRefCounts;\n\t\t\t\t\t\t\tdelete this._ids;\n\t\t\t\t\t\t\tdelete this._idPool;\n\t\t\t\t\t\t\tthis.exit(code);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n\t\t\t\t\t\t\"runtime.wasmWrite\": (sp) => {\n\t\t\t\t\t\t\tconst fd = getInt64(sp + 8);\n\t\t\t\t\t\t\tconst p = getInt64(sp + 16);\n\t\t\t\t\t\t\tconst n = this.mem.getInt32(sp + 24, true);\n\t\t\t\t\t\t\tfs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func resetMemoryDataView()\n\t\t\t\t\t\t\"runtime.resetMemoryDataView\": (sp) => {\n\t\t\t\t\t\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func nanotime1() int64\n\t\t\t\t\t\t\"runtime.nanotime1\": (sp) => {\n\t\t\t\t\t\t\tsetInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func walltime1() (sec int64, nsec int32)\n\t\t\t\t\t\t\"runtime.walltime1\": (sp) => {\n\t\t\t\t\t\t\tconst msec = (new Date).getTime();\n\t\t\t\t\t\t\tsetInt64(sp + 8, msec / 1000);\n\t\t\t\t\t\t\tthis.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func scheduleTimeoutEvent(delay int64) int32\n\t\t\t\t\t\t\"runtime.scheduleTimeoutEvent\": (sp) => {\n\t\t\t\t\t\t\tconst id = this._nextCallbackTimeoutID;\n\t\t\t\t\t\t\tthis._nextCallbackTimeoutID++;\n\t\t\t\t\t\t\tthis._scheduledTimeouts.set(id, setTimeout(\n\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\tthis._resume();\n\t\t\t\t\t\t\t\t\twhile (this._scheduledTimeouts.has(id)) {\n\t\t\t\t\t\t\t\t\t\t// for some reason Go failed to register the timeout event, log and try again\n\t\t\t\t\t\t\t\t\t\t// (temporary workaround for https://github.com/golang/go/issues/28975)\n\t\t\t\t\t\t\t\t\t\tconsole.warn(\"scheduleTimeoutEvent: missed timeout event\");\n\t\t\t\t\t\t\t\t\t\tthis._resume();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tgetInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early\n\t\t\t\t\t\t\t));\n\t\t\t\t\t\t\tthis.mem.setInt32(sp + 16, id, true);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func clearTimeoutEvent(id int32)\n\t\t\t\t\t\t\"runtime.clearTimeoutEvent\": (sp) => {\n\t\t\t\t\t\t\tconst id = this.mem.getInt32(sp + 8, true);\n\t\t\t\t\t\t\tclearTimeout(this._scheduledTimeouts.get(id));\n\t\t\t\t\t\t\tthis._scheduledTimeouts.delete(id);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func getRandomData(r []byte)\n\t\t\t\t\t\t\"runtime.getRandomData\": (sp) => {\n\t\t\t\t\t\t\tcrypto.getRandomValues(loadSlice(sp + 8));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func finalizeRef(v ref)\n\t\t\t\t\t\t\"syscall/js.finalizeRef\": (sp) => {\n\t\t\t\t\t\t\tconst id = this.mem.getUint32(sp + 8, true);\n\t\t\t\t\t\t\tthis._goRefCounts[id]--;\n\t\t\t\t\t\t\tif (this._goRefCounts[id] === 0) {\n\t\t\t\t\t\t\t\tconst v = this._values[id];\n\t\t\t\t\t\t\t\tthis._values[id] = null;\n\t\t\t\t\t\t\t\tthis._ids.delete(v);\n\t\t\t\t\t\t\t\tthis._idPool.push(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func stringVal(value string) ref\n\t\t\t\t\t\t\"syscall/js.stringVal\": (sp) => {\n\t\t\t\t\t\t\tstoreValue(sp + 24, loadString(sp + 8));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueGet(v ref, p string) ref\n\t\t\t\t\t\t\"syscall/js.valueGet\": (sp) => {\n\t\t\t\t\t\t\tconst result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\tstoreValue(sp + 32, result);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueSet(v ref, p string, x ref)\n\t\t\t\t\t\t\"syscall/js.valueSet\": (sp) => {\n\t\t\t\t\t\t\tReflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueDelete(v ref, p string)\n\t\t\t\t\t\t\"syscall/js.valueDelete\": (sp) => {\n\t\t\t\t\t\t\tReflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueIndex(v ref, i int) ref\n\t\t\t\t\t\t\"syscall/js.valueIndex\": (sp) => {\n\t\t\t\t\t\t\tstoreValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// valueSetIndex(v ref, i int, x ref)\n\t\t\t\t\t\t\"syscall/js.valueSetIndex\": (sp) => {\n\t\t\t\t\t\t\tReflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueCall(v ref, m string, args []ref) (ref, bool)\n\t\t\t\t\t\t\"syscall/js.valueCall\": (sp) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\t\t\tconst m = Reflect.get(v, loadString(sp + 16));\n\t\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 32);\n\t\t\t\t\t\t\t\tconst result = Reflect.apply(m, v, args);\n\t\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\t\tstoreValue(sp + 56, result);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 1);\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tstoreValue(sp + 56, err);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueInvoke(v ref, args []ref) (ref, bool)\n\t\t\t\t\t\t\"syscall/js.valueInvoke\": (sp) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);\n\t\t\t\t\t\t\t\tconst result = Reflect.apply(v, undefined, args);\n\t\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, result);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, err);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueNew(v ref, args []ref) (ref, bool)\n\t\t\t\t\t\t\"syscall/js.valueNew\": (sp) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);\n\t\t\t\t\t\t\t\tconst result = Reflect.construct(v, args);\n\t\t\t\t\t\t\t\tsp = this._inst.exports.getsp(); // see comment above\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, result);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\tstoreValue(sp + 40, err);\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueLength(v ref) int\n\t\t\t\t\t\t\"syscall/js.valueLength\": (sp) => {\n\t\t\t\t\t\t\tsetInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// valuePrepareString(v ref) (ref, int)\n\t\t\t\t\t\t\"syscall/js.valuePrepareString\": (sp) => {\n\t\t\t\t\t\t\tconst str = encoder.encode(String(loadValue(sp + 8)));\n\t\t\t\t\t\t\tstoreValue(sp + 16, str);\n\t\t\t\t\t\t\tsetInt64(sp + 24, str.length);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// valueLoadString(v ref, b []byte)\n\t\t\t\t\t\t\"syscall/js.valueLoadString\": (sp) => {\n\t\t\t\t\t\t\tconst str = loadValue(sp + 8);\n\t\t\t\t\t\t\tloadSlice(sp + 16).set(str);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func valueInstanceOf(v ref, t ref) bool\n\t\t\t\t\t\t\"syscall/js.valueInstanceOf\": (sp) => {\n\t\t\t\t\t\t\tthis.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func copyBytesToGo(dst []byte, src ref) (int, bool)\n\t\t\t\t\t\t\"syscall/js.copyBytesToGo\": (sp) => {\n\t\t\t\t\t\t\tconst dst = loadSlice(sp + 8);\n\t\t\t\t\t\t\tconst src = loadValue(sp + 32);\n\t\t\t\t\t\t\tif (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);\n\t\t\t\t\t\t\tdst.set(toCopy);\n\t\t\t\t\t\t\tsetInt64(sp + 40, toCopy.length);\n\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t// func copyBytesToJS(dst ref, src []byte) (int, bool)\n\t\t\t\t\t\t\"syscall/js.copyBytesToJS\": (sp) => {\n\t\t\t\t\t\t\tconst dst = loadValue(sp + 8);\n\t\t\t\t\t\t\tconst src = loadSlice(sp + 16);\n\t\t\t\t\t\t\tif (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n\t\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);\n\t\t\t\t\t\t\tdst.set(toCopy);\n\t\t\t\t\t\t\tsetInt64(sp + 40, toCopy.length);\n\t\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t\t},\n\t\n\t\t\t\t\t\t\"debug\": (value) => {\n\t\t\t\t\t\t\tconsole.log(value);\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\n\t\t\tasync run(instance) {\n\t\t\t\tthis._inst = instance;\n\t\t\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);\n\t\t\t\tthis._values = [ // JS values that Go currently has references to, indexed by reference id\n\t\t\t\t\tNaN,\n\t\t\t\t\t0,\n\t\t\t\t\tnull,\n\t\t\t\t\ttrue,\n\t\t\t\t\tfalse,\n\t\t\t\t\tglobal,\n\t\t\t\t\tthis,\n\t\t\t\t];\n\t\t\t\tthis._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id\n\t\t\t\tthis._ids = new Map([ // mapping from JS values to reference ids\n\t\t\t\t\t[0, 1],\n\t\t\t\t\t[null, 2],\n\t\t\t\t\t[true, 3],\n\t\t\t\t\t[false, 4],\n\t\t\t\t\t[global, 5],\n\t\t\t\t\t[this, 6],\n\t\t\t\t]);\n\t\t\t\tthis._idPool = []; // unused ids that have been garbage collected\n\t\t\t\tthis.exited = false; // whether the Go program has exited\n\t\n\t\t\t\t// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.\n\t\t\t\tlet offset = 4096;\n\t\n\t\t\t\tconst strPtr = (str) => {\n\t\t\t\t\tconst ptr = offset;\n\t\t\t\t\tconst bytes = encoder.encode(str + \"\\0\");\n\t\t\t\t\tnew Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n\t\t\t\t\toffset += bytes.length;\n\t\t\t\t\tif (offset % 8 !== 0) {\n\t\t\t\t\t\toffset += 8 - (offset % 8);\n\t\t\t\t\t}\n\t\t\t\t\treturn ptr;\n\t\t\t\t};\n\t\n\t\t\t\tconst argc = this.argv.length;\n\t\n\t\t\t\tconst argvPtrs = [];\n\t\t\t\tthis.argv.forEach((arg) => {\n\t\t\t\t\targvPtrs.push(strPtr(arg));\n\t\t\t\t});\n\t\t\t\targvPtrs.push(0);\n\t\n\t\t\t\tconst keys = Object.keys(this.env).sort();\n\t\t\t\tkeys.forEach((key) => {\n\t\t\t\t\targvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n\t\t\t\t});\n\t\t\t\targvPtrs.push(0);\n\t\n\t\t\t\tconst argv = offset;\n\t\t\t\targvPtrs.forEach((ptr) => {\n\t\t\t\t\tthis.mem.setUint32(offset, ptr, true);\n\t\t\t\t\tthis.mem.setUint32(offset + 4, 0, true);\n\t\t\t\t\toffset += 8;\n\t\t\t\t});\n\t\n\t\t\t\tthis._inst.exports.run(argc, argv);\n\t\t\t\tif (this.exited) {\n\t\t\t\t\tthis._resolveExitPromise();\n\t\t\t\t}\n\t\t\t\tawait this._exitPromise;\n\t\t\t}\n\t\n\t\t\t_resume() {\n\t\t\t\tif (this.exited) {\n\t\t\t\t\tthrow new Error(\"Go program has already exited\");\n\t\t\t\t}\n\t\t\t\tthis._inst.exports.resume();\n\t\t\t\tif (this.exited) {\n\t\t\t\t\tthis._resolveExitPromise();\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\t_makeFuncWrapper(id) {\n\t\t\t\tconst go = this;\n\t\t\t\treturn function () {\n\t\t\t\t\tconst event = { id: id, this: this, args: arguments };\n\t\t\t\t\tgo._pendingEvent = event;\n\t\t\t\t\tgo._resume();\n\t\t\t\t\treturn event.result;\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\n\t\tif (\n\t\t\tglobal.require &&\n\t\t\tglobal.require.main === module &&\n\t\t\tglobal.process &&\n\t\t\tglobal.process.versions &&\n\t\t\t!global.process.versions.electron\n\t\t) {\n\t\t\tif (process.argv.length < 3) {\n\t\t\t\tconsole.error(\"usage: go_js_wasm_exec [wasm binary] [arguments]\");\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\n\t\t\tconst go = new Go();\n\t\t\tgo.argv = process.argv.slice(2);\n\t\t\tgo.env = Object.assign({ TMPDIR: require(\"os\").tmpdir() }, process.env);\n\t\t\tgo.exit = process.exit;\n\t\t\tWebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {\n\t\t\t\tprocess.on(\"exit\", (code) => { // Node.js exits if no event handler is pending\n\t\t\t\t\tif (code === 0 && !go.exited) {\n\t\t\t\t\t\t// deadlock, make Go print error and stack traces\n\t\t\t\t\t\tgo._pendingEvent = { id: 0 };\n\t\t\t\t\t\tgo._resume();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn go.run(result.instance);\n\t\t\t}).catch((err) => {\n\t\t\t\tconsole.error(err);\n\t\t\t\tprocess.exit(1);\n\t\t\t});\n\t\t}\n\t})();\n}\n","// DEFLATE is a complex format; to read this code, you should probably check the RFC first:\n// https://tools.ietf.org/html/rfc1951\n// You may also wish to take a look at the guide I made about this program:\n// https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad\n// Some of the following code is similar to that of UZIP.js:\n// https://github.com/photopea/UZIP.js\n// However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.\n// Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint\n// is better for memory in most engines (I *think*).\nvar ch2 = {};\nvar wk = (function (c, id, msg, transfer, cb) {\n var w = new Worker(ch2[id] || (ch2[id] = URL.createObjectURL(new Blob([\n c + ';addEventListener(\"error\",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'\n ], { type: 'text/javascript' }))));\n w.onmessage = function (e) {\n var d = e.data, ed = d.$e$;\n if (ed) {\n var err = new Error(ed[0]);\n err['code'] = ed[1];\n err.stack = ed[2];\n cb(err, null);\n }\n else\n cb(null, d);\n };\n w.postMessage(msg, transfer);\n return w;\n});\n\n// aliases for shorter compressed code (most minifers don't do this)\nvar u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;\n// fixed length extra bits\nvar 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]);\n// fixed distance extra bits\n// see fleb note\nvar 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]);\n// code length index map\nvar clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);\n// get base, reverse index map from extra bits\nvar freb = function (eb, start) {\n var b = new u16(31);\n for (var i = 0; i < 31; ++i) {\n b[i] = start += 1 << eb[i - 1];\n }\n // numbers here are at max 18 bits\n var r = new u32(b[30]);\n for (var i = 1; i < 30; ++i) {\n for (var j = b[i]; j < b[i + 1]; ++j) {\n r[j] = ((j - b[i]) << 5) | i;\n }\n }\n return [b, r];\n};\nvar _a = freb(fleb, 2), fl = _a[0], revfl = _a[1];\n// we can ignore the fact that the other numbers are wrong; they never happen anyway\nfl[28] = 258, revfl[258] = 28;\nvar _b = freb(fdeb, 0), fd = _b[0], revfd = _b[1];\n// map of value to reverse (assuming 16 bits)\nvar rev = new u16(32768);\nfor (var i = 0; i < 32768; ++i) {\n // reverse table algorithm from SO\n var x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);\n x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);\n x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);\n rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;\n}\n// create huffman tree from u8 \"map\": index -> code length for code index\n// mb (max bits) must be at most 15\n// TODO: optimize/split up?\nvar hMap = (function (cd, mb, r) {\n var s = cd.length;\n // index\n var i = 0;\n // u16 \"map\": index -> # of codes with bit length = index\n var l = new u16(mb);\n // length of cd must be 288 (total # of codes)\n for (; i < s; ++i) {\n if (cd[i])\n ++l[cd[i] - 1];\n }\n // u16 \"map\": index -> minimum code for bit length = index\n var le = new u16(mb);\n for (i = 0; i < mb; ++i) {\n le[i] = (le[i - 1] + l[i - 1]) << 1;\n }\n var co;\n if (r) {\n // u16 \"map\": index -> number of actual bits, symbol for code\n co = new u16(1 << mb);\n // bits to remove for reverser\n var rvb = 15 - mb;\n for (i = 0; i < s; ++i) {\n // ignore 0 lengths\n if (cd[i]) {\n // num encoding both symbol and bits read\n var sv = (i << 4) | cd[i];\n // free bits\n var r_1 = mb - cd[i];\n // start value\n var v = le[cd[i] - 1]++ << r_1;\n // m is end value\n for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {\n // every 16 bit value starting with the code yields the same result\n co[rev[v] >>> rvb] = sv;\n }\n }\n }\n }\n else {\n co = new u16(s);\n for (i = 0; i < s; ++i) {\n if (cd[i]) {\n co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);\n }\n }\n }\n return co;\n});\n// fixed length tree\nvar flt = new u8(288);\nfor (var i = 0; i < 144; ++i)\n flt[i] = 8;\nfor (var i = 144; i < 256; ++i)\n flt[i] = 9;\nfor (var i = 256; i < 280; ++i)\n flt[i] = 7;\nfor (var i = 280; i < 288; ++i)\n flt[i] = 8;\n// fixed distance tree\nvar fdt = new u8(32);\nfor (var i = 0; i < 32; ++i)\n fdt[i] = 5;\n// fixed length map\nvar flm = /*#__PURE__*/ hMap(flt, 9, 0), flrm = /*#__PURE__*/ hMap(flt, 9, 1);\n// fixed distance map\nvar fdm = /*#__PURE__*/ hMap(fdt, 5, 0), fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);\n// find max of array\nvar max = function (a) {\n var m = a[0];\n for (var i = 1; i < a.length; ++i) {\n if (a[i] > m)\n m = a[i];\n }\n return m;\n};\n// read d, starting at bit p and mask with m\nvar bits = function (d, p, m) {\n var o = (p / 8) | 0;\n return ((d[o] | (d[o + 1] << 8)) >> (p & 7)) & m;\n};\n// read d, starting at bit p continuing for at least 16 bits\nvar bits16 = function (d, p) {\n var o = (p / 8) | 0;\n return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >> (p & 7));\n};\n// get end of byte\nvar shft = function (p) { return ((p + 7) / 8) | 0; };\n// typed array slice - allows garbage collector to free original reference,\n// while being more compatible than .slice\nvar slc = function (v, s, e) {\n if (s == null || s < 0)\n s = 0;\n if (e == null || e > v.length)\n e = v.length;\n // can't use .constructor in case user-supplied\n var n = new (v.BYTES_PER_ELEMENT == 2 ? u16 : v.BYTES_PER_ELEMENT == 4 ? u32 : u8)(e - s);\n n.set(v.subarray(s, e));\n return n;\n};\n/**\n * Codes for errors generated within this library\n */\nexport var FlateErrorCode = {\n UnexpectedEOF: 0,\n InvalidBlockType: 1,\n InvalidLengthLiteral: 2,\n InvalidDistance: 3,\n StreamFinished: 4,\n NoStreamHandler: 5,\n InvalidHeader: 6,\n NoCallback: 7,\n InvalidUTF8: 8,\n ExtraFieldTooLong: 9,\n InvalidDate: 10,\n FilenameTooLong: 11,\n StreamFinishing: 12,\n InvalidZipData: 13,\n UnknownCompressionMethod: 14\n};\n// error codes\nvar ec = [\n 'unexpected EOF',\n 'invalid block type',\n 'invalid length/literal',\n 'invalid distance',\n 'stream finished',\n 'no stream handler',\n ,\n 'no callback',\n 'invalid UTF-8 data',\n 'extra field too long',\n 'date not in range 1980-2099',\n 'filename too long',\n 'stream finishing',\n 'invalid zip data'\n // determined by unknown compression method\n];\n;\nvar err = function (ind, msg, nt) {\n var e = new Error(msg || ec[ind]);\n e.code = ind;\n if (Error.captureStackTrace)\n Error.captureStackTrace(e, err);\n if (!nt)\n throw e;\n return e;\n};\n// expands raw DEFLATE data\nvar inflt = function (dat, buf, st) {\n // source length\n var sl = dat.length;\n if (!sl || (st && st.f && !st.l))\n return buf || new u8(0);\n // have to estimate size\n var noBuf = !buf || st;\n // no state\n var noSt = !st || st.i;\n if (!st)\n st = {};\n // Assumes roughly 33% compression ratio average\n if (!buf)\n buf = new u8(sl * 3);\n // ensure buffer can fit at least l elements\n var cbuf = function (l) {\n var bl = buf.length;\n // need to increase size to fit\n if (l > bl) {\n // Double or set to necessary, whichever is greater\n var nbuf = new u8(Math.max(bl * 2, l));\n nbuf.set(buf);\n buf = nbuf;\n }\n };\n // last chunk bitpos bytes\n 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;\n // total bits\n var tbts = sl * 8;\n do {\n if (!lm) {\n // BFINAL - this is only 1 when last chunk is next\n final = bits(dat, pos, 1);\n // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman\n var type = bits(dat, pos + 1, 3);\n pos += 3;\n if (!type) {\n // go to end of byte boundary\n var s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;\n if (t > sl) {\n if (noSt)\n err(0);\n break;\n }\n // ensure size\n if (noBuf)\n cbuf(bt + l);\n // Copy over uncompressed data\n buf.set(dat.subarray(s, t), bt);\n // Get new bitpos, update byte count\n st.b = bt += l, st.p = pos = t * 8, st.f = final;\n continue;\n }\n else if (type == 1)\n lm = flrm, dm = fdrm, lbt = 9, dbt = 5;\n else if (type == 2) {\n // literal lengths\n var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;\n var tl = hLit + bits(dat, pos + 5, 31) + 1;\n pos += 14;\n // length+distance tree\n var ldt = new u8(tl);\n // code length tree\n var clt = new u8(19);\n for (var i = 0; i < hcLen; ++i) {\n // use index map to get real code\n clt[clim[i]] = bits(dat, pos + i * 3, 7);\n }\n pos += hcLen * 3;\n // code lengths bits\n var clb = max(clt), clbmsk = (1 << clb) - 1;\n // code lengths map\n var clm = hMap(clt, clb, 1);\n for (var i = 0; i < tl;) {\n var r = clm[bits(dat, pos, clbmsk)];\n // bits read\n pos += r & 15;\n // symbol\n var s = r >>> 4;\n // code length to copy\n if (s < 16) {\n ldt[i++] = s;\n }\n else {\n // copy count\n var c = 0, n = 0;\n if (s == 16)\n n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];\n else if (s == 17)\n n = 3 + bits(dat, pos, 7), pos += 3;\n else if (s == 18)\n n = 11 + bits(dat, pos, 127), pos += 7;\n while (n--)\n ldt[i++] = c;\n }\n }\n // length tree distance tree\n var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);\n // max length bits\n lbt = max(lt);\n // max dist bits\n dbt = max(dt);\n lm = hMap(lt, lbt, 1);\n dm = hMap(dt, dbt, 1);\n }\n else\n err(1);\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n }\n // Make sure the buffer can hold this + the largest possible addition\n // Maximum chunk size (practically, theoretically infinite) is 2^17;\n if (noBuf)\n cbuf(bt + 131072);\n var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;\n var lpos = pos;\n for (;; lpos = pos) {\n // bits read, code\n var c = lm[bits16(dat, pos) & lms], sym = c >>> 4;\n pos += c & 15;\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n if (!c)\n err(2);\n if (sym < 256)\n buf[bt++] = sym;\n else if (sym == 256) {\n lpos = pos, lm = null;\n break;\n }\n else {\n var add = sym - 254;\n // no extra bits needed if less\n if (sym > 264) {\n // index\n var i = sym - 257, b = fleb[i];\n add = bits(dat, pos, (1 << b) - 1) + fl[i];\n pos += b;\n }\n // dist\n var d = dm[bits16(dat, pos) & dms], dsym = d >>> 4;\n if (!d)\n err(3);\n pos += d & 15;\n var dt = fd[dsym];\n if (dsym > 3) {\n var b = fdeb[dsym];\n dt += bits16(dat, pos) & ((1 << b) - 1), pos += b;\n }\n if (pos > tbts) {\n if (noSt)\n err(0);\n break;\n }\n if (noBuf)\n cbuf(bt + 131072);\n var end = bt + add;\n for (; bt < end; bt += 4) {\n buf[bt] = buf[bt - dt];\n buf[bt + 1] = buf[bt + 1 - dt];\n buf[bt + 2] = buf[bt + 2 - dt];\n buf[bt + 3] = buf[bt + 3 - dt];\n }\n bt = end;\n }\n }\n st.l = lm, st.p = lpos, st.b = bt, st.f = final;\n if (lm)\n final = 1, st.m = lbt, st.d = dm, st.n = dbt;\n } while (!final);\n return bt == buf.length ? buf : slc(buf, 0, bt);\n};\n// starting at p, write the minimum number of bits that can hold v to d\nvar wbits = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n};\n// starting at p, write the minimum number of bits (>8) that can hold v to d\nvar wbits16 = function (d, p, v) {\n v <<= p & 7;\n var o = (p / 8) | 0;\n d[o] |= v;\n d[o + 1] |= v >>> 8;\n d[o + 2] |= v >>> 16;\n};\n// creates code lengths from a frequency table\nvar hTree = function (d, mb) {\n // Need extra info to make a tree\n var t = [];\n for (var i = 0; i < d.length; ++i) {\n if (d[i])\n t.push({ s: i, f: d[i] });\n }\n var s = t.length;\n var t2 = t.slice();\n if (!s)\n return [et, 0];\n if (s == 1) {\n var v = new u8(t[0].s + 1);\n v[t[0].s] = 1;\n return [v, 1];\n }\n t.sort(function (a, b) { return a.f - b.f; });\n // after i2 reaches last ind, will be stopped\n // freq must be greater than largest possible number of symbols\n t.push({ s: -1, f: 25001 });\n var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;\n t[0] = { s: -1, f: l.f + r.f, l: l, r: r };\n // efficient algorithm from UZIP.js\n // i0 is lookbehind, i2 is lookahead - after processing two low-freq\n // symbols that combined have high freq, will start processing i2 (high-freq,\n // non-composite) symbols instead\n // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/\n while (i1 != s - 1) {\n l = t[t[i0].f < t[i2].f ? i0++ : i2++];\n r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];\n t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };\n }\n var maxSym = t2[0].s;\n for (var i = 1; i < s; ++i) {\n if (t2[i].s > maxSym)\n maxSym = t2[i].s;\n }\n // code lengths\n var tr = new u16(maxSym + 1);\n // max bits in tree\n var mbt = ln(t[i1 - 1], tr, 0);\n if (mbt > mb) {\n // more algorithms from UZIP.js\n // TODO: find out how this code works (debt)\n // ind debt\n var i = 0, dt = 0;\n // left cost\n var lft = mbt - mb, cst = 1 << lft;\n t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });\n for (; i < s; ++i) {\n var i2_1 = t2[i].s;\n if (tr[i2_1] > mb) {\n dt += cst - (1 << (mbt - tr[i2_1]));\n tr[i2_1] = mb;\n }\n else\n break;\n }\n dt >>>= lft;\n while (dt > 0) {\n var i2_2 = t2[i].s;\n if (tr[i2_2] < mb)\n dt -= 1 << (mb - tr[i2_2]++ - 1);\n else\n ++i;\n }\n for (; i >= 0 && dt; --i) {\n var i2_3 = t2[i].s;\n if (tr[i2_3] == mb) {\n --tr[i2_3];\n ++dt;\n }\n }\n mbt = mb;\n }\n return [new u8(tr), mbt];\n};\n// get the max length and assign length codes\nvar ln = function (n, l, d) {\n return n.s == -1\n ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))\n : (l[n.s] = d);\n};\n// length codes generation\nvar lc = function (c) {\n var s = c.length;\n // Note that the semicolon was intentional\n while (s && !c[--s])\n ;\n var cl = new u16(++s);\n // ind num streak\n var cli = 0, cln = c[0], cls = 1;\n var w = function (v) { cl[cli++] = v; };\n for (var i = 1; i <= s; ++i) {\n if (c[i] == cln && i != s)\n ++cls;\n else {\n if (!cln && cls > 2) {\n for (; cls > 138; cls -= 138)\n w(32754);\n if (cls > 2) {\n w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);\n cls = 0;\n }\n }\n else if (cls > 3) {\n w(cln), --cls;\n for (; cls > 6; cls -= 6)\n w(8304);\n if (cls > 2)\n w(((cls - 3) << 5) | 8208), cls = 0;\n }\n while (cls--)\n w(cln);\n cls = 1;\n cln = c[i];\n }\n }\n return [cl.subarray(0, cli), s];\n};\n// calculate the length of output from tree, code lengths\nvar clen = function (cf, cl) {\n var l = 0;\n for (var i = 0; i < cl.length; ++i)\n l += cf[i] * cl[i];\n return l;\n};\n// writes a fixed block\n// returns the new bit pos\nvar wfblk = function (out, pos, dat) {\n // no need to write 00 as type: TypedArray defaults to 0\n var s = dat.length;\n var o = shft(pos + 2);\n out[o] = s & 255;\n out[o + 1] = s >>> 8;\n out[o + 2] = out[o] ^ 255;\n out[o + 3] = out[o + 1] ^ 255;\n for (var i = 0; i < s; ++i)\n out[o + i + 4] = dat[i];\n return (o + 4 + s) * 8;\n};\n// writes a block\nvar wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {\n wbits(out, p++, final);\n ++lf[256];\n var _a = hTree(lf, 15), dlt = _a[0], mlb = _a[1];\n var _b = hTree(df, 15), ddt = _b[0], mdb = _b[1];\n var _c = lc(dlt), lclt = _c[0], nlc = _c[1];\n var _d = lc(ddt), lcdt = _d[0], ndc = _d[1];\n var lcfreq = new u16(19);\n for (var i = 0; i < lclt.length; ++i)\n lcfreq[lclt[i] & 31]++;\n for (var i = 0; i < lcdt.length; ++i)\n lcfreq[lcdt[i] & 31]++;\n var _e = hTree(lcfreq, 7), lct = _e[0], mlcb = _e[1];\n var nlcc = 19;\n for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)\n ;\n var flen = (bl + 5) << 3;\n var ftlen = clen(lf, flt) + clen(df, fdt) + eb;\n var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + (2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18]);\n if (flen <= ftlen && flen <= dtlen)\n return wfblk(out, p, dat.subarray(bs, bs + bl));\n var lm, ll, dm, dl;\n wbits(out, p, 1 + (dtlen < ftlen)), p += 2;\n if (dtlen < ftlen) {\n lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;\n var llm = hMap(lct, mlcb, 0);\n wbits(out, p, nlc - 257);\n wbits(out, p + 5, ndc - 1);\n wbits(out, p + 10, nlcc - 4);\n p += 14;\n for (var i = 0; i < nlcc; ++i)\n wbits(out, p + 3 * i, lct[clim[i]]);\n p += 3 * nlcc;\n var lcts = [lclt, lcdt];\n for (var it = 0; it < 2; ++it) {\n var clct = lcts[it];\n for (var i = 0; i < clct.length; ++i) {\n var len = clct[i] & 31;\n wbits(out, p, llm[len]), p += lct[len];\n if (len > 15)\n wbits(out, p, (clct[i] >>> 5) & 127), p += clct[i] >>> 12;\n }\n }\n }\n else {\n lm = flm, ll = flt, dm = fdm, dl = fdt;\n }\n for (var i = 0; i < li; ++i) {\n if (syms[i] > 255) {\n var len = (syms[i] >>> 18) & 31;\n wbits16(out, p, lm[len + 257]), p += ll[len + 257];\n if (len > 7)\n wbits(out, p, (syms[i] >>> 23) & 31), p += fleb[len];\n var dst = syms[i] & 31;\n wbits16(out, p, dm[dst]), p += dl[dst];\n if (dst > 3)\n wbits16(out, p, (syms[i] >>> 5) & 8191), p += fdeb[dst];\n }\n else {\n wbits16(out, p, lm[syms[i]]), p += ll[syms[i]];\n }\n }\n wbits16(out, p, lm[256]);\n return p + ll[256];\n};\n// deflate options (nice << 13) | chain\nvar deo = /*#__PURE__*/ new u32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);\n// empty\nvar et = /*#__PURE__*/ new u8(0);\n// compresses data into a raw DEFLATE buffer\nvar dflt = function (dat, lvl, plvl, pre, post, lst) {\n var s = dat.length;\n var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);\n // writing to this writes to the output buffer\n var w = o.subarray(pre, o.length - post);\n var pos = 0;\n if (!lvl || s < 8) {\n for (var i = 0; i <= s; i += 65535) {\n // end\n var e = i + 65535;\n if (e >= s) {\n // write final block\n w[pos >> 3] = lst;\n }\n pos = wfblk(w, pos + 1, dat.subarray(i, e));\n }\n }\n else {\n var opt = deo[lvl - 1];\n var n = opt >>> 13, c = opt & 8191;\n var msk_1 = (1 << plvl) - 1;\n // prev 2-byte val map curr 2-byte val map\n var prev = new u16(32768), head = new u16(msk_1 + 1);\n var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;\n var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };\n // 24576 is an arbitrary number of maximum symbols per block\n // 424 buffer for last block\n var syms = new u32(25000);\n // length/literal freq distance freq\n var lf = new u16(288), df = new u16(32);\n // l/lcnt exbits index l/lind waitdx bitpos\n var lc_1 = 0, eb = 0, i = 0, li = 0, wi = 0, bs = 0;\n for (; i < s; ++i) {\n // hash value\n // deopt when i > s - 3 - at end, deopt acceptable\n var hv = hsh(i);\n // index mod 32768 previous index mod\n var imod = i & 32767, pimod = head[hv];\n prev[imod] = pimod;\n head[hv] = imod;\n // We always should modify head and prev, but only add symbols if\n // this data is not yet processed (\"wait\" for wait index)\n if (wi <= i) {\n // bytes remaining\n var rem = s - i;\n if ((lc_1 > 7000 || li > 24576) && rem > 423) {\n pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);\n li = lc_1 = eb = 0, bs = i;\n for (var j = 0; j < 286; ++j)\n lf[j] = 0;\n for (var j = 0; j < 30; ++j)\n df[j] = 0;\n }\n // len dist chain\n var l = 2, d = 0, ch_1 = c, dif = (imod - pimod) & 32767;\n if (rem > 2 && hv == hsh(i - dif)) {\n var maxn = Math.min(n, rem) - 1;\n var maxd = Math.min(32767, i);\n // max possible length\n // not capped at dif because decompressors implement \"rolling\" index population\n var ml = Math.min(258, rem);\n while (dif <= maxd && --ch_1 && imod != pimod) {\n if (dat[i + l] == dat[i + l - dif]) {\n var nl = 0;\n for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)\n ;\n if (nl > l) {\n l = nl, d = dif;\n // break out early when we reach \"nice\" (we are satisfied enough)\n if (nl > maxn)\n break;\n // now, find the rarest 2-byte sequence within this\n // length of literals and search for that instead.\n // Much faster than just using the start\n var mmd = Math.min(dif, nl - 2);\n var md = 0;\n for (var j = 0; j < mmd; ++j) {\n var ti = (i - dif + j + 32768) & 32767;\n var pti = prev[ti];\n var cd = (ti - pti + 32768) & 32767;\n if (cd > md)\n md = cd, pimod = ti;\n }\n }\n }\n // check the previous match\n imod = pimod, pimod = prev[imod];\n dif += (imod - pimod + 32768) & 32767;\n }\n }\n // d will be nonzero only when a match was found\n if (d) {\n // store both dist and len data in one Uint32\n // Make sure this is recognized as a len/dist with 28th bit (2^28)\n syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];\n var lin = revfl[l] & 31, din = revfd[d] & 31;\n eb += fleb[lin] + fdeb[din];\n ++lf[257 + lin];\n ++df[din];\n wi = i + l;\n ++lc_1;\n }\n else {\n syms[li++] = dat[i];\n ++lf[dat[i]];\n }\n }\n }\n pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);\n // this is the easiest way to avoid needing to maintain state\n if (!lst && pos & 7)\n pos = wfblk(w, pos + 1, et);\n }\n return slc(o, 0, pre + shft(pos) + post);\n};\n// CRC32 table\nvar crct = /*#__PURE__*/ (function () {\n var t = new Int32Array(256);\n for (var i = 0; i < 256; ++i) {\n var c = i, k = 9;\n while (--k)\n c = ((c & 1) && -306674912) ^ (c >>> 1);\n t[i] = c;\n }\n return t;\n})();\n// CRC32\nvar crc = function () {\n var c = -1;\n return {\n p: function (d) {\n // closures have awful performance\n var cr = c;\n for (var i = 0; i < d.length; ++i)\n cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);\n c = cr;\n },\n d: function () { return ~c; }\n };\n};\n// Alder32\nvar adler = function () {\n var a = 1, b = 0;\n return {\n p: function (d) {\n // closures have awful performance\n var n = a, m = b;\n var l = d.length | 0;\n for (var i = 0; i != l;) {\n var e = Math.min(i + 2655, l);\n for (; i < e; ++i)\n m += n += d[i];\n n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);\n }\n a = n, b = m;\n },\n d: function () {\n a %= 65521, b %= 65521;\n return (a & 255) << 24 | (a >>> 8) << 16 | (b & 255) << 8 | (b >>> 8);\n }\n };\n};\n;\n// deflate with opts\nvar dopt = function (dat, opt, pre, post, st) {\n return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : (12 + opt.mem), pre, post, !st);\n};\n// Walmart object spread\nvar mrg = function (a, b) {\n var o = {};\n for (var k in a)\n o[k] = a[k];\n for (var k in b)\n o[k] = b[k];\n return o;\n};\n// worker clone\n// This is possibly the craziest part of the entire codebase, despite how simple it may seem.\n// The only parameter to this function is a closure that returns an array of variables outside of the function scope.\n// We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.\n// We will return an object mapping of true variable name to value (basically, the current scope as a JS object).\n// The reason we can't just use the original variable names is minifiers mangling the toplevel scope.\n// This took me three weeks to figure out how to do.\nvar wcln = function (fn, fnStr, td) {\n var dt = fn();\n var st = fn.toString();\n var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/\\s+/g, '').split(',');\n for (var i = 0; i < dt.length; ++i) {\n var v = dt[i], k = ks[i];\n if (typeof v == 'function') {\n fnStr += ';' + k + '=';\n var st_1 = v.toString();\n if (v.prototype) {\n // for global objects\n if (st_1.indexOf('[native code]') != -1) {\n var spInd = st_1.indexOf(' ', 8) + 1;\n fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));\n }\n else {\n fnStr += st_1;\n for (var t in v.prototype)\n fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();\n }\n }\n else\n fnStr += st_1;\n }\n else\n td[k] = v;\n }\n return [fnStr, td];\n};\nvar ch = [];\n// clone bufs\nvar cbfs = function (v) {\n var tl = [];\n for (var k in v) {\n if (v[k].buffer) {\n tl.push((v[k] = new v[k].constructor(v[k])).buffer);\n }\n }\n return tl;\n};\n// use a worker to execute code\nvar wrkr = function (fns, init, id, cb) {\n var _a;\n if (!ch[id]) {\n var fnStr = '', td_1 = {}, m = fns.length - 1;\n for (var i = 0; i < m; ++i)\n _a = wcln(fns[i], fnStr, td_1), fnStr = _a[0], td_1 = _a[1];\n ch[id] = wcln(fns[m], fnStr, td_1);\n }\n var td = mrg({}, ch[id][1]);\n return wk(ch[id][0] + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);\n};\n// base async inflate fn\nvar bInflt = function () { return [u8, u16, u32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gu8]; };\nvar bDflt = function () { return [u8, u16, u32, 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]; };\n// gzip extra\nvar gze = function () { return [gzh, gzhl, wbytes, crc, crct]; };\n// gunzip extra\nvar guze = function () { return [gzs, gzl]; };\n// zlib extra\nvar zle = function () { return [zlh, wbytes, adler]; };\n// unzlib extra\nvar zule = function () { return [zlv]; };\n// post buf\nvar pbf = function (msg) { return postMessage(msg, [msg.buffer]); };\n// get u8\nvar gu8 = function (o) { return o && o.size && new u8(o.size); };\n// async helper\nvar cbify = function (dat, opts, fns, init, id, cb) {\n var w = wrkr(fns, init, id, function (err, dat) {\n w.terminate();\n cb(err, dat);\n });\n w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);\n return function () { w.terminate(); };\n};\n// auto stream\nvar astrm = function (strm) {\n strm.ondata = function (dat, final) { return postMessage([dat, final], [dat.buffer]); };\n return function (ev) { return strm.push(ev.data[0], ev.data[1]); };\n};\n// async stream attach\nvar astrmify = function (fns, strm, opts, init, id) {\n var t;\n var w = wrkr(fns, init, id, function (err, dat) {\n if (err)\n w.terminate(), strm.ondata.call(strm, err);\n else {\n if (dat[1])\n w.terminate();\n strm.ondata.call(strm, err, dat[0], dat[1]);\n }\n });\n w.postMessage(opts);\n strm.push = function (d, f) {\n if (!strm.ondata)\n err(5);\n if (t)\n strm.ondata(err(4, 0, 1), null, !!f);\n w.postMessage([d, t = f], [d.buffer]);\n };\n strm.terminate = function () { w.terminate(); };\n};\n// read 2 bytes\nvar b2 = function (d, b) { return d[b] | (d[b + 1] << 8); };\n// read 4 bytes\nvar b4 = function (d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; };\nvar b8 = function (d, b) { return b4(d, b) + (b4(d, b + 4) * 4294967296); };\n// write bytes\nvar wbytes = function (d, b, v) {\n for (; v; ++b)\n d[b] = v, v >>>= 8;\n};\n// gzip header\nvar gzh = function (c, o) {\n var fn = o.filename;\n c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix\n if (o.mtime != 0)\n wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000));\n if (fn) {\n c[3] = 8;\n for (var i = 0; i <= fn.length; ++i)\n c[i + 10] = fn.charCodeAt(i);\n }\n};\n// gzip footer: -8 to -4 = CRC, -4 to -0 is length\n// gzip start\nvar gzs = function (d) {\n if (d[0] != 31 || d[1] != 139 || d[2] != 8)\n err(6, 'invalid gzip data');\n var flg = d[3];\n var st = 10;\n if (flg & 4)\n st += d[10] | (d[11] << 8) + 2;\n for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])\n ;\n return st + (flg & 2);\n};\n// gzip length\nvar gzl = function (d) {\n var l = d.length;\n return ((d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16) | (d[l - 1] << 24)) >>> 0;\n};\n// gzip header length\nvar gzhl = function (o) { return 10 + ((o.filename && (o.filename.length + 1)) || 0); };\n// zlib header\nvar zlh = function (c, o) {\n var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;\n c[0] = 120, c[1] = (fl << 6) | (fl ? (32 - 2 * fl) : 1);\n};\n// zlib valid\nvar zlv = function (d) {\n if ((d[0] & 15) != 8 || (d[0] >>> 4) > 7 || ((d[0] << 8 | d[1]) % 31))\n err(6, 'invalid zlib data');\n if (d[1] & 32)\n err(6, 'invalid zlib data: preset dictionaries not supported');\n};\nfunction AsyncCmpStrm(opts, cb) {\n if (!cb && typeof opts == 'function')\n cb = opts, opts = {};\n this.ondata = cb;\n return opts;\n}\n// zlib footer: -4 to -0 is Adler32\n/**\n * Streaming DEFLATE compression\n */\nvar Deflate = /*#__PURE__*/ (function () {\n function Deflate(opts, cb) {\n if (!cb && typeof opts == 'function')\n cb = opts, opts = {};\n this.ondata = cb;\n this.o = opts || {};\n }\n Deflate.prototype.p = function (c, f) {\n this.ondata(dopt(c, this.o, 0, 0, !f), f);\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Deflate.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n this.d = final;\n this.p(chunk, final || false);\n };\n return Deflate;\n}());\nexport { Deflate };\n/**\n * Asynchronous streaming DEFLATE compression\n */\nvar AsyncDeflate = /*#__PURE__*/ (function () {\n function AsyncDeflate(opts, cb) {\n astrmify([\n bDflt,\n function () { return [astrm, Deflate]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Deflate(ev.data);\n onmessage = astrm(strm);\n }, 6);\n }\n return AsyncDeflate;\n}());\nexport { AsyncDeflate };\nexport function deflate(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);\n}\n/**\n * Compresses data with DEFLATE without any wrapper\n * @param data The data to compress\n * @param opts The compression options\n * @returns The deflated version of the data\n */\nexport function deflateSync(data, opts) {\n return dopt(data, opts || {}, 0, 0);\n}\n/**\n * Streaming DEFLATE decompression\n */\nvar Inflate = /*#__PURE__*/ (function () {\n /**\n * Creates an inflation stream\n * @param cb The callback to call whenever data is inflated\n */\n function Inflate(cb) {\n this.s = {};\n this.p = new u8(0);\n this.ondata = cb;\n }\n Inflate.prototype.e = function (c) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n var l = this.p.length;\n var n = new u8(l + c.length);\n n.set(this.p), n.set(c, l), this.p = n;\n };\n Inflate.prototype.c = function (final) {\n this.d = this.s.i = final || false;\n var bts = this.s.b;\n var dt = inflt(this.p, this.o, this.s);\n this.ondata(slc(dt, bts, this.s.b), this.d);\n this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;\n this.p = slc(this.p, (this.s.p / 8) | 0), this.s.p &= 7;\n };\n /**\n * Pushes a chunk to be inflated\n * @param chunk The chunk to push\n * @param final Whether this is the final chunk\n */\n Inflate.prototype.push = function (chunk, final) {\n this.e(chunk), this.c(final);\n };\n return Inflate;\n}());\nexport { Inflate };\n/**\n * Asynchronous streaming DEFLATE decompression\n */\nvar AsyncInflate = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous inflation stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncInflate(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n function () { return [astrm, Inflate]; }\n ], this, 0, function () {\n var strm = new Inflate();\n onmessage = astrm(strm);\n }, 7);\n }\n return AsyncInflate;\n}());\nexport { AsyncInflate };\nexport function inflate(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt\n ], function (ev) { return pbf(inflateSync(ev.data[0], gu8(ev.data[1]))); }, 1, cb);\n}\n/**\n * Expands DEFLATE data with no wrapper\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function inflateSync(data, out) {\n return inflt(data, out);\n}\n// before you yell at me for not just using extends, my reason is that TS inheritance is hard to workerize.\n/**\n * Streaming GZIP compression\n */\nvar Gzip = /*#__PURE__*/ (function () {\n function Gzip(opts, cb) {\n this.c = crc();\n this.l = 0;\n this.v = 1;\n Deflate.call(this, opts, cb);\n }\n /**\n * Pushes a chunk to be GZIPped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Gzip.prototype.push = function (chunk, final) {\n Deflate.prototype.push.call(this, chunk, final);\n };\n Gzip.prototype.p = function (c, f) {\n this.c.p(c);\n this.l += c.length;\n var raw = dopt(c, this.o, this.v && gzhl(this.o), f && 8, !f);\n if (this.v)\n gzh(raw, this.o), this.v = 0;\n if (f)\n wbytes(raw, raw.length - 8, this.c.d()), wbytes(raw, raw.length - 4, this.l);\n this.ondata(raw, f);\n };\n return Gzip;\n}());\nexport { Gzip };\n/**\n * Asynchronous streaming GZIP compression\n */\nvar AsyncGzip = /*#__PURE__*/ (function () {\n function AsyncGzip(opts, cb) {\n astrmify([\n bDflt,\n gze,\n function () { return [astrm, Deflate, Gzip]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Gzip(ev.data);\n onmessage = astrm(strm);\n }, 8);\n }\n return AsyncGzip;\n}());\nexport { AsyncGzip };\nexport function gzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n gze,\n function () { return [gzipSync]; }\n ], function (ev) { return pbf(gzipSync(ev.data[0], ev.data[1])); }, 2, cb);\n}\n/**\n * Compresses data with GZIP\n * @param data The data to compress\n * @param opts The compression options\n * @returns The gzipped version of the data\n */\nexport function gzipSync(data, opts) {\n if (!opts)\n opts = {};\n var c = crc(), l = data.length;\n c.p(data);\n var d = dopt(data, opts, gzhl(opts), 8), s = d.length;\n return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d;\n}\n/**\n * Streaming GZIP decompression\n */\nvar Gunzip = /*#__PURE__*/ (function () {\n /**\n * Creates a GUNZIP stream\n * @param cb The callback to call whenever data is inflated\n */\n function Gunzip(cb) {\n this.v = 1;\n Inflate.call(this, cb);\n }\n /**\n * Pushes a chunk to be GUNZIPped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Gunzip.prototype.push = function (chunk, final) {\n Inflate.prototype.e.call(this, chunk);\n if (this.v) {\n var s = this.p.length > 3 ? gzs(this.p) : 4;\n if (s >= this.p.length && !final)\n return;\n this.p = this.p.subarray(s), this.v = 0;\n }\n if (final) {\n if (this.p.length < 8)\n err(6, 'invalid gzip data');\n this.p = this.p.subarray(0, -8);\n }\n // necessary to prevent TS from using the closure value\n // This allows for workerization to function correctly\n Inflate.prototype.c.call(this, final);\n };\n return Gunzip;\n}());\nexport { Gunzip };\n/**\n * Asynchronous streaming GZIP decompression\n */\nvar AsyncGunzip = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous GUNZIP stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncGunzip(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n guze,\n function () { return [astrm, Inflate, Gunzip]; }\n ], this, 0, function () {\n var strm = new Gunzip();\n onmessage = astrm(strm);\n }, 9);\n }\n return AsyncGunzip;\n}());\nexport { AsyncGunzip };\nexport function gunzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt,\n guze,\n function () { return [gunzipSync]; }\n ], function (ev) { return pbf(gunzipSync(ev.data[0])); }, 3, cb);\n}\n/**\n * Expands GZIP data\n * @param data The data to decompress\n * @param out Where to write the data. GZIP already encodes the output size, so providing this doesn't save memory.\n * @returns The decompressed version of the data\n */\nexport function gunzipSync(data, out) {\n return inflt(data.subarray(gzs(data), -8), out || new u8(gzl(data)));\n}\n/**\n * Streaming Zlib compression\n */\nvar Zlib = /*#__PURE__*/ (function () {\n function Zlib(opts, cb) {\n this.c = adler();\n this.v = 1;\n Deflate.call(this, opts, cb);\n }\n /**\n * Pushes a chunk to be zlibbed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Zlib.prototype.push = function (chunk, final) {\n Deflate.prototype.push.call(this, chunk, final);\n };\n Zlib.prototype.p = function (c, f) {\n this.c.p(c);\n var raw = dopt(c, this.o, this.v && 2, f && 4, !f);\n if (this.v)\n zlh(raw, this.o), this.v = 0;\n if (f)\n wbytes(raw, raw.length - 4, this.c.d());\n this.ondata(raw, f);\n };\n return Zlib;\n}());\nexport { Zlib };\n/**\n * Asynchronous streaming Zlib compression\n */\nvar AsyncZlib = /*#__PURE__*/ (function () {\n function AsyncZlib(opts, cb) {\n astrmify([\n bDflt,\n zle,\n function () { return [astrm, Deflate, Zlib]; }\n ], this, AsyncCmpStrm.call(this, opts, cb), function (ev) {\n var strm = new Zlib(ev.data);\n onmessage = astrm(strm);\n }, 10);\n }\n return AsyncZlib;\n}());\nexport { AsyncZlib };\nexport function zlib(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bDflt,\n zle,\n function () { return [zlibSync]; }\n ], function (ev) { return pbf(zlibSync(ev.data[0], ev.data[1])); }, 4, cb);\n}\n/**\n * Compress data with Zlib\n * @param data The data to compress\n * @param opts The compression options\n * @returns The zlib-compressed version of the data\n */\nexport function zlibSync(data, opts) {\n if (!opts)\n opts = {};\n var a = adler();\n a.p(data);\n var d = dopt(data, opts, 2, 4);\n return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;\n}\n/**\n * Streaming Zlib decompression\n */\nvar Unzlib = /*#__PURE__*/ (function () {\n /**\n * Creates a Zlib decompression stream\n * @param cb The callback to call whenever data is inflated\n */\n function Unzlib(cb) {\n this.v = 1;\n Inflate.call(this, cb);\n }\n /**\n * Pushes a chunk to be unzlibbed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Unzlib.prototype.push = function (chunk, final) {\n Inflate.prototype.e.call(this, chunk);\n if (this.v) {\n if (this.p.length < 2 && !final)\n return;\n this.p = this.p.subarray(2), this.v = 0;\n }\n if (final) {\n if (this.p.length < 4)\n err(6, 'invalid zlib data');\n this.p = this.p.subarray(0, -4);\n }\n // necessary to prevent TS from using the closure value\n // This allows for workerization to function correctly\n Inflate.prototype.c.call(this, final);\n };\n return Unzlib;\n}());\nexport { Unzlib };\n/**\n * Asynchronous streaming Zlib decompression\n */\nvar AsyncUnzlib = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous Zlib decompression stream\n * @param cb The callback to call whenever data is deflated\n */\n function AsyncUnzlib(cb) {\n this.ondata = cb;\n astrmify([\n bInflt,\n zule,\n function () { return [astrm, Inflate, Unzlib]; }\n ], this, 0, function () {\n var strm = new Unzlib();\n onmessage = astrm(strm);\n }, 11);\n }\n return AsyncUnzlib;\n}());\nexport { AsyncUnzlib };\nexport function unzlib(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return cbify(data, opts, [\n bInflt,\n zule,\n function () { return [unzlibSync]; }\n ], function (ev) { return pbf(unzlibSync(ev.data[0], gu8(ev.data[1]))); }, 5, cb);\n}\n/**\n * Expands Zlib data\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function unzlibSync(data, out) {\n return inflt((zlv(data), data.subarray(2, -4)), out);\n}\n// Default algorithm for compression (used because having a known output size allows faster decompression)\nexport { gzip as compress, AsyncGzip as AsyncCompress };\n// Default algorithm for compression (used because having a known output size allows faster decompression)\nexport { gzipSync as compressSync, Gzip as Compress };\n/**\n * Streaming GZIP, Zlib, or raw DEFLATE decompression\n */\nvar Decompress = /*#__PURE__*/ (function () {\n /**\n * Creates a decompression stream\n * @param cb The callback to call whenever data is decompressed\n */\n function Decompress(cb) {\n this.G = Gunzip;\n this.I = Inflate;\n this.Z = Unzlib;\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be decompressed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Decompress.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (!this.s) {\n if (this.p && this.p.length) {\n var n = new u8(this.p.length + chunk.length);\n n.set(this.p), n.set(chunk, this.p.length);\n }\n else\n this.p = chunk;\n if (this.p.length > 2) {\n var _this_1 = this;\n var cb = function () { _this_1.ondata.apply(_this_1, arguments); };\n this.s = (this.p[0] == 31 && this.p[1] == 139 && this.p[2] == 8)\n ? new this.G(cb)\n : ((this.p[0] & 15) != 8 || (this.p[0] >> 4) > 7 || ((this.p[0] << 8 | this.p[1]) % 31))\n ? new this.I(cb)\n : new this.Z(cb);\n this.s.push(this.p, final);\n this.p = null;\n }\n }\n else\n this.s.push(chunk, final);\n };\n return Decompress;\n}());\nexport { Decompress };\n/**\n * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression\n */\nvar AsyncDecompress = /*#__PURE__*/ (function () {\n /**\n * Creates an asynchronous decompression stream\n * @param cb The callback to call whenever data is decompressed\n */\n function AsyncDecompress(cb) {\n this.G = AsyncGunzip;\n this.I = AsyncInflate;\n this.Z = AsyncUnzlib;\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be decompressed\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n AsyncDecompress.prototype.push = function (chunk, final) {\n Decompress.prototype.push.call(this, chunk, final);\n };\n return AsyncDecompress;\n}());\nexport { AsyncDecompress };\nexport function decompress(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n return (data[0] == 31 && data[1] == 139 && data[2] == 8)\n ? gunzip(data, opts, cb)\n : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))\n ? inflate(data, opts, cb)\n : unzlib(data, opts, cb);\n}\n/**\n * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format\n * @param data The data to decompress\n * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.\n * @returns The decompressed version of the data\n */\nexport function decompressSync(data, out) {\n return (data[0] == 31 && data[1] == 139 && data[2] == 8)\n ? gunzipSync(data, out)\n : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))\n ? inflateSync(data, out)\n : unzlibSync(data, out);\n}\n// flatten a directory structure\nvar fltn = function (d, p, t, o) {\n for (var k in d) {\n var val = d[k], n = p + k, op = o;\n if (Array.isArray(val))\n op = mrg(o, val[1]), val = val[0];\n if (val instanceof u8)\n t[n] = [val, op];\n else {\n t[n += '/'] = [new u8(0), op];\n fltn(val, n, t, o);\n }\n }\n};\n// text encoder\nvar te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();\n// text decoder\nvar td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();\n// text decoder stream\nvar tds = 0;\ntry {\n td.decode(et, { stream: true });\n tds = 1;\n}\ncatch (e) { }\n// decode UTF8\nvar dutf8 = function (d) {\n for (var r = '', i = 0;;) {\n var c = d[i++];\n var eb = (c > 127) + (c > 223) + (c > 239);\n if (i + eb > d.length)\n return [r, slc(d, i - 1)];\n if (!eb)\n r += String.fromCharCode(c);\n else if (eb == 3) {\n c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536,\n r += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023));\n }\n else if (eb & 1)\n r += String.fromCharCode((c & 31) << 6 | (d[i++] & 63));\n else\n r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63));\n }\n};\n/**\n * Streaming UTF-8 decoding\n */\nvar DecodeUTF8 = /*#__PURE__*/ (function () {\n /**\n * Creates a UTF-8 decoding stream\n * @param cb The callback to call whenever data is decoded\n */\n function DecodeUTF8(cb) {\n this.ondata = cb;\n if (tds)\n this.t = new TextDecoder();\n else\n this.p = et;\n }\n /**\n * Pushes a chunk to be decoded from UTF-8 binary\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n DecodeUTF8.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n final = !!final;\n if (this.t) {\n this.ondata(this.t.decode(chunk, { stream: true }), final);\n if (final) {\n if (this.t.decode().length)\n err(8);\n this.t = null;\n }\n return;\n }\n if (!this.p)\n err(4);\n var dat = new u8(this.p.length + chunk.length);\n dat.set(this.p);\n dat.set(chunk, this.p.length);\n var _a = dutf8(dat), ch = _a[0], np = _a[1];\n if (final) {\n if (np.length)\n err(8);\n this.p = null;\n }\n else\n this.p = np;\n this.ondata(ch, final);\n };\n return DecodeUTF8;\n}());\nexport { DecodeUTF8 };\n/**\n * Streaming UTF-8 encoding\n */\nvar EncodeUTF8 = /*#__PURE__*/ (function () {\n /**\n * Creates a UTF-8 decoding stream\n * @param cb The callback to call whenever data is encoded\n */\n function EncodeUTF8(cb) {\n this.ondata = cb;\n }\n /**\n * Pushes a chunk to be encoded to UTF-8\n * @param chunk The string data to push\n * @param final Whether this is the last chunk\n */\n EncodeUTF8.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n if (this.d)\n err(4);\n this.ondata(strToU8(chunk), this.d = final || false);\n };\n return EncodeUTF8;\n}());\nexport { EncodeUTF8 };\n/**\n * Converts a string into a Uint8Array for use with compression/decompression methods\n * @param str The string to encode\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\n * not need to be true unless decoding a binary string.\n * @returns The string encoded in UTF-8/Latin-1 binary\n */\nexport function strToU8(str, latin1) {\n if (latin1) {\n var ar_1 = new u8(str.length);\n for (var i = 0; i < str.length; ++i)\n ar_1[i] = str.charCodeAt(i);\n return ar_1;\n }\n if (te)\n return te.encode(str);\n var l = str.length;\n var ar = new u8(str.length + (str.length >> 1));\n var ai = 0;\n var w = function (v) { ar[ai++] = v; };\n for (var i = 0; i < l; ++i) {\n if (ai + 5 > ar.length) {\n var n = new u8(ai + 8 + ((l - i) << 1));\n n.set(ar);\n ar = n;\n }\n var c = str.charCodeAt(i);\n if (c < 128 || latin1)\n w(c);\n else if (c < 2048)\n w(192 | (c >> 6)), w(128 | (c & 63));\n else if (c > 55295 && c < 57344)\n c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),\n w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n else\n w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));\n }\n return slc(ar, 0, ai);\n}\n/**\n * Converts a Uint8Array to a string\n * @param dat The data to decode to string\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\n * not need to be true unless encoding to binary string.\n * @returns The original UTF-8/Latin-1 string\n */\nexport function strFromU8(dat, latin1) {\n if (latin1) {\n var r = '';\n for (var i = 0; i < dat.length; i += 16384)\n r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));\n return r;\n }\n else if (td)\n return td.decode(dat);\n else {\n var _a = dutf8(dat), out = _a[0], ext = _a[1];\n if (ext.length)\n err(8);\n return out;\n }\n}\n;\n// deflate bit flag\nvar dbf = function (l) { return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0; };\n// skip local zip header\nvar slzh = function (d, b) { return b + 30 + b2(d, b + 26) + b2(d, b + 28); };\n// read zip header\nvar zh = function (d, b, z) {\n 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);\n var _a = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a[0], su = _a[1], off = _a[2];\n return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off];\n};\n// read zip64 extra field\nvar z64e = function (d, b) {\n for (; b2(d, b) != 1; b += 4 + b2(d, b + 2))\n ;\n return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)];\n};\n// extra field length\nvar exfl = function (ex) {\n var le = 0;\n if (ex) {\n for (var k in ex) {\n var l = ex[k].length;\n if (l > 65535)\n err(9);\n le += l + 4;\n }\n }\n return le;\n};\n// write zip header\nvar wzh = function (d, b, f, fn, u, c, ce, co) {\n var fl = fn.length, ex = f.extra, col = co && co.length;\n var exl = exfl(ex);\n wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;\n if (ce != null)\n d[b++] = 20, d[b++] = f.os;\n d[b] = 20, b += 2; // spec compliance? what's that?\n d[b++] = (f.flag << 1) | (c == null && 8), d[b++] = u && 8;\n d[b++] = f.compression & 255, d[b++] = f.compression >> 8;\n var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;\n if (y < 0 || y > 119)\n err(10);\n wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >>> 1)), b += 4;\n if (c != null) {\n wbytes(d, b, f.crc);\n wbytes(d, b + 4, c);\n wbytes(d, b + 8, f.size);\n }\n wbytes(d, b + 12, fl);\n wbytes(d, b + 14, exl), b += 16;\n if (ce != null) {\n wbytes(d, b, col);\n wbytes(d, b + 6, f.attrs);\n wbytes(d, b + 10, ce), b += 14;\n }\n d.set(fn, b);\n b += fl;\n if (exl) {\n for (var k in ex) {\n var exf = ex[k], l = exf.length;\n wbytes(d, b, +k);\n wbytes(d, b + 2, l);\n d.set(exf, b + 4), b += 4 + l;\n }\n }\n if (col)\n d.set(co, b), b += col;\n return b;\n};\n// write zip footer (end of central directory)\nvar wzf = function (o, b, c, d, e) {\n wbytes(o, b, 0x6054B50); // skip disk\n wbytes(o, b + 8, c);\n wbytes(o, b + 10, c);\n wbytes(o, b + 12, d);\n wbytes(o, b + 16, e);\n};\n/**\n * A pass-through stream to keep data uncompressed in a ZIP archive.\n */\nvar ZipPassThrough = /*#__PURE__*/ (function () {\n /**\n * Creates a pass-through stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n */\n function ZipPassThrough(filename) {\n this.filename = filename;\n this.c = crc();\n this.size = 0;\n this.compression = 0;\n }\n /**\n * Processes a chunk and pushes to the output stream. You can override this\n * method in a subclass for custom behavior, but by default this passes\n * the data through. You must call this.ondata(err, chunk, final) at some\n * point in this method.\n * @param chunk The chunk to process\n * @param final Whether this is the last chunk\n */\n ZipPassThrough.prototype.process = function (chunk, final) {\n this.ondata(null, chunk, final);\n };\n /**\n * Pushes a chunk to be added. If you are subclassing this with a custom\n * compression algorithm, note that you must push data from the source\n * file only, pre-compression.\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n ZipPassThrough.prototype.push = function (chunk, final) {\n if (!this.ondata)\n err(5);\n this.c.p(chunk);\n this.size += chunk.length;\n if (final)\n this.crc = this.c.d();\n this.process(chunk, final || false);\n };\n return ZipPassThrough;\n}());\nexport { ZipPassThrough };\n// I don't extend because TypeScript extension adds 1kB of runtime bloat\n/**\n * Streaming DEFLATE compression for ZIP archives. Prefer using AsyncZipDeflate\n * for better performance\n */\nvar ZipDeflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n * @param opts The compression options\n */\n function ZipDeflate(filename, opts) {\n var _this_1 = this;\n if (!opts)\n opts = {};\n ZipPassThrough.call(this, filename);\n this.d = new Deflate(opts, function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n this.compression = 8;\n this.flag = dbf(opts.level);\n }\n ZipDeflate.prototype.process = function (chunk, final) {\n try {\n this.d.push(chunk, final);\n }\n catch (e) {\n this.ondata(e, null, final);\n }\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n ZipDeflate.prototype.push = function (chunk, final) {\n ZipPassThrough.prototype.push.call(this, chunk, final);\n };\n return ZipDeflate;\n}());\nexport { ZipDeflate };\n/**\n * Asynchronous streaming DEFLATE compression for ZIP archives\n */\nvar AsyncZipDeflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE stream that can be added to ZIP archives\n * @param filename The filename to associate with this data stream\n * @param opts The compression options\n */\n function AsyncZipDeflate(filename, opts) {\n var _this_1 = this;\n if (!opts)\n opts = {};\n ZipPassThrough.call(this, filename);\n this.d = new AsyncDeflate(opts, function (err, dat, final) {\n _this_1.ondata(err, dat, final);\n });\n this.compression = 8;\n this.flag = dbf(opts.level);\n this.terminate = this.d.terminate;\n }\n AsyncZipDeflate.prototype.process = function (chunk, final) {\n this.d.push(chunk, final);\n };\n /**\n * Pushes a chunk to be deflated\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n AsyncZipDeflate.prototype.push = function (chunk, final) {\n ZipPassThrough.prototype.push.call(this, chunk, final);\n };\n return AsyncZipDeflate;\n}());\nexport { AsyncZipDeflate };\n// TODO: Better tree shaking\n/**\n * A zippable archive to which files can incrementally be added\n */\nvar Zip = /*#__PURE__*/ (function () {\n /**\n * Creates an empty ZIP archive to which files can be added\n * @param cb The callback to call whenever data for the generated ZIP archive\n * is available\n */\n function Zip(cb) {\n this.ondata = cb;\n this.u = [];\n this.d = 1;\n }\n /**\n * Adds a file to the ZIP archive\n * @param file The file stream to add\n */\n Zip.prototype.add = function (file) {\n var _this_1 = this;\n if (!this.ondata)\n err(5);\n // finishing or finished\n if (this.d & 2)\n this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);\n else {\n var f = strToU8(file.filename), fl_1 = f.length;\n var com = file.comment, o = com && strToU8(com);\n var u = fl_1 != file.filename.length || (o && (com.length != o.length));\n var hl_1 = fl_1 + exfl(file.extra) + 30;\n if (fl_1 > 65535)\n this.ondata(err(11, 0, 1), null, false);\n var header = new u8(hl_1);\n wzh(header, 0, file, f, u);\n var chks_1 = [header];\n var pAll_1 = function () {\n for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {\n var chk = chks_2[_i];\n _this_1.ondata(null, chk, false);\n }\n chks_1 = [];\n };\n var tr_1 = this.d;\n this.d = 0;\n var ind_1 = this.u.length;\n var uf_1 = mrg(file, {\n f: f,\n u: u,\n o: o,\n t: function () {\n if (file.terminate)\n file.terminate();\n },\n r: function () {\n pAll_1();\n if (tr_1) {\n var nxt = _this_1.u[ind_1 + 1];\n if (nxt)\n nxt.r();\n else\n _this_1.d = 1;\n }\n tr_1 = 1;\n }\n });\n var cl_1 = 0;\n file.ondata = function (err, dat, final) {\n if (err) {\n _this_1.ondata(err, dat, final);\n _this_1.terminate();\n }\n else {\n cl_1 += dat.length;\n chks_1.push(dat);\n if (final) {\n var dd = new u8(16);\n wbytes(dd, 0, 0x8074B50);\n wbytes(dd, 4, file.crc);\n wbytes(dd, 8, cl_1);\n wbytes(dd, 12, file.size);\n chks_1.push(dd);\n uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file.crc, uf_1.size = file.size;\n if (tr_1)\n uf_1.r();\n tr_1 = 1;\n }\n else if (tr_1)\n pAll_1();\n }\n };\n this.u.push(uf_1);\n }\n };\n /**\n * Ends the process of adding files and prepares to emit the final chunks.\n * This *must* be called after adding all desired files for the resulting\n * ZIP file to work properly.\n */\n Zip.prototype.end = function () {\n var _this_1 = this;\n if (this.d & 2) {\n this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);\n return;\n }\n if (this.d)\n this.e();\n else\n this.u.push({\n r: function () {\n if (!(_this_1.d & 1))\n return;\n _this_1.u.splice(-1, 1);\n _this_1.e();\n },\n t: function () { }\n });\n this.d = 3;\n };\n Zip.prototype.e = function () {\n var bt = 0, l = 0, tl = 0;\n for (var _i = 0, _a = this.u; _i < _a.length; _i++) {\n var f = _a[_i];\n tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);\n }\n var out = new u8(tl + 22);\n for (var _b = 0, _c = this.u; _b < _c.length; _b++) {\n var f = _c[_b];\n wzh(out, bt, f, f.f, f.u, f.c, l, f.o);\n bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;\n }\n wzf(out, bt, this.u.length, tl, l);\n this.ondata(null, out, true);\n this.d = 2;\n };\n /**\n * A method to terminate any internal workers used by the stream. Subsequent\n * calls to add() will fail.\n */\n Zip.prototype.terminate = function () {\n for (var _i = 0, _a = this.u; _i < _a.length; _i++) {\n var f = _a[_i];\n f.t();\n }\n this.d = 2;\n };\n return Zip;\n}());\nexport { Zip };\nexport function zip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n var r = {};\n fltn(data, '', r, opts);\n var k = Object.keys(r);\n var lft = k.length, o = 0, tot = 0;\n var slft = lft, files = new Array(lft);\n var term = [];\n var tAll = function () {\n for (var i = 0; i < term.length; ++i)\n term[i]();\n };\n var cbd = function (a, b) {\n mt(function () { cb(a, b); });\n };\n mt(function () { cbd = cb; });\n var cbf = function () {\n var out = new u8(tot + 22), oe = o, cdl = tot - o;\n tot = 0;\n for (var i = 0; i < slft; ++i) {\n var f = files[i];\n try {\n var l = f.c.length;\n wzh(out, tot, f, f.f, f.u, l);\n var badd = 30 + f.f.length + exfl(f.extra);\n var loc = tot + badd;\n out.set(f.c, loc);\n wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;\n }\n catch (e) {\n return cbd(e, null);\n }\n }\n wzf(out, o, files.length, cdl, oe);\n cbd(null, out);\n };\n if (!lft)\n cbf();\n var _loop_1 = function (i) {\n var fn = k[i];\n var _a = r[fn], file = _a[0], p = _a[1];\n var c = crc(), size = file.length;\n c.p(file);\n var f = strToU8(fn), s = f.length;\n var com = p.comment, m = com && strToU8(com), ms = m && m.length;\n var exl = exfl(p.extra);\n var compression = p.level == 0 ? 0 : 8;\n var cbl = function (e, d) {\n if (e) {\n tAll();\n cbd(e, null);\n }\n else {\n var l = d.length;\n files[i] = mrg(p, {\n size: size,\n crc: c.d(),\n c: d,\n f: f,\n m: m,\n u: s != fn.length || (m && (com.length != ms)),\n compression: compression\n });\n o += 30 + s + exl + l;\n tot += 76 + 2 * (s + exl) + (ms || 0) + l;\n if (!--lft)\n cbf();\n }\n };\n if (s > 65535)\n cbl(err(11, 0, 1), null);\n if (!compression)\n cbl(null, file);\n else if (size < 160000) {\n try {\n cbl(null, deflateSync(file, p));\n }\n catch (e) {\n cbl(e, null);\n }\n }\n else\n term.push(deflate(file, p, cbl));\n };\n // Cannot use lft because it can decrease\n for (var i = 0; i < slft; ++i) {\n _loop_1(i);\n }\n return tAll;\n}\n/**\n * Synchronously creates a ZIP file. Prefer using `zip` for better performance\n * with more than one file.\n * @param data The directory structure for the ZIP archive\n * @param opts The main options, merged with per-file options\n * @returns The generated ZIP archive\n */\nexport function zipSync(data, opts) {\n if (!opts)\n opts = {};\n var r = {};\n var files = [];\n fltn(data, '', r, opts);\n var o = 0;\n var tot = 0;\n for (var fn in r) {\n var _a = r[fn], file = _a[0], p = _a[1];\n var compression = p.level == 0 ? 0 : 8;\n var f = strToU8(fn), s = f.length;\n var com = p.comment, m = com && strToU8(com), ms = m && m.length;\n var exl = exfl(p.extra);\n if (s > 65535)\n err(11);\n var d = compression ? deflateSync(file, p) : file, l = d.length;\n var c = crc();\n c.p(file);\n files.push(mrg(p, {\n size: file.length,\n crc: c.d(),\n c: d,\n f: f,\n m: m,\n u: s != fn.length || (m && (com.length != ms)),\n o: o,\n compression: compression\n }));\n o += 30 + s + exl + l;\n tot += 76 + 2 * (s + exl) + (ms || 0) + l;\n }\n var out = new u8(tot + 22), oe = o, cdl = tot - o;\n for (var i = 0; i < files.length; ++i) {\n var f = files[i];\n wzh(out, f.o, f, f.f, f.u, f.c.length);\n var badd = 30 + f.f.length + exfl(f.extra);\n out.set(f.c, f.o + badd);\n wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);\n }\n wzf(out, o, files.length, cdl, oe);\n return out;\n}\n/**\n * Streaming pass-through decompression for ZIP archives\n */\nvar UnzipPassThrough = /*#__PURE__*/ (function () {\n function UnzipPassThrough() {\n }\n UnzipPassThrough.prototype.push = function (data, final) {\n this.ondata(null, data, final);\n };\n UnzipPassThrough.compression = 0;\n return UnzipPassThrough;\n}());\nexport { UnzipPassThrough };\n/**\n * Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for\n * better performance.\n */\nvar UnzipInflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE decompression that can be used in ZIP archives\n */\n function UnzipInflate() {\n var _this_1 = this;\n this.i = new Inflate(function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n }\n UnzipInflate.prototype.push = function (data, final) {\n try {\n this.i.push(data, final);\n }\n catch (e) {\n this.ondata(e, null, final);\n }\n };\n UnzipInflate.compression = 8;\n return UnzipInflate;\n}());\nexport { UnzipInflate };\n/**\n * Asynchronous streaming DEFLATE decompression for ZIP archives\n */\nvar AsyncUnzipInflate = /*#__PURE__*/ (function () {\n /**\n * Creates a DEFLATE decompression that can be used in ZIP archives\n */\n function AsyncUnzipInflate(_, sz) {\n var _this_1 = this;\n if (sz < 320000) {\n this.i = new Inflate(function (dat, final) {\n _this_1.ondata(null, dat, final);\n });\n }\n else {\n this.i = new AsyncInflate(function (err, dat, final) {\n _this_1.ondata(err, dat, final);\n });\n this.terminate = this.i.terminate;\n }\n }\n AsyncUnzipInflate.prototype.push = function (data, final) {\n if (this.i.terminate)\n data = slc(data, 0);\n this.i.push(data, final);\n };\n AsyncUnzipInflate.compression = 8;\n return AsyncUnzipInflate;\n}());\nexport { AsyncUnzipInflate };\n/**\n * A ZIP archive decompression stream that emits files as they are discovered\n */\nvar Unzip = /*#__PURE__*/ (function () {\n /**\n * Creates a ZIP decompression stream\n * @param cb The callback to call whenever a file in the ZIP archive is found\n */\n function Unzip(cb) {\n this.onfile = cb;\n this.k = [];\n this.o = {\n 0: UnzipPassThrough\n };\n this.p = et;\n }\n /**\n * Pushes a chunk to be unzipped\n * @param chunk The chunk to push\n * @param final Whether this is the last chunk\n */\n Unzip.prototype.push = function (chunk, final) {\n var _this_1 = this;\n if (!this.onfile)\n err(5);\n if (!this.p)\n err(4);\n if (this.c > 0) {\n var len = Math.min(this.c, chunk.length);\n var toAdd = chunk.subarray(0, len);\n this.c -= len;\n if (this.d)\n this.d.push(toAdd, !this.c);\n else\n this.k[0].push(toAdd);\n chunk = chunk.subarray(len);\n if (chunk.length)\n return this.push(chunk, final);\n }\n else {\n var f = 0, i = 0, is = void 0, buf = void 0;\n if (!this.p.length)\n buf = chunk;\n else if (!chunk.length)\n buf = this.p;\n else {\n buf = new u8(this.p.length + chunk.length);\n buf.set(this.p), buf.set(chunk, this.p.length);\n }\n var l = buf.length, oc = this.c, add = oc && this.d;\n var _loop_2 = function () {\n var _a;\n var sig = b4(buf, i);\n if (sig == 0x4034B50) {\n f = 1, is = i;\n this_1.d = null;\n this_1.c = 0;\n var bf = b2(buf, i + 6), cmp_1 = b2(buf, i + 8), u = bf & 2048, dd = bf & 8, fnl = b2(buf, i + 26), es = b2(buf, i + 28);\n if (l > i + 30 + fnl + es) {\n var chks_3 = [];\n this_1.k.unshift(chks_3);\n f = 2;\n var sc_1 = b4(buf, i + 18), su_1 = b4(buf, i + 22);\n var fn_1 = strFromU8(buf.subarray(i + 30, i += 30 + fnl), !u);\n if (sc_1 == 4294967295) {\n _a = dd ? [-2] : z64e(buf, i), sc_1 = _a[0], su_1 = _a[1];\n }\n else if (dd)\n sc_1 = -1;\n i += es;\n this_1.c = sc_1;\n var d_1;\n var file_1 = {\n name: fn_1,\n compression: cmp_1,\n start: function () {\n if (!file_1.ondata)\n err(5);\n if (!sc_1)\n file_1.ondata(null, et, true);\n else {\n var ctr = _this_1.o[cmp_1];\n if (!ctr)\n file_1.ondata(err(14, 'unknown compression type ' + cmp_1, 1), null, false);\n d_1 = sc_1 < 0 ? new ctr(fn_1) : new ctr(fn_1, sc_1, su_1);\n d_1.ondata = function (err, dat, final) { file_1.ondata(err, dat, final); };\n for (var _i = 0, chks_4 = chks_3; _i < chks_4.length; _i++) {\n var dat = chks_4[_i];\n d_1.push(dat, false);\n }\n if (_this_1.k[0] == chks_3 && _this_1.c)\n _this_1.d = d_1;\n else\n d_1.push(et, true);\n }\n },\n terminate: function () {\n if (d_1 && d_1.terminate)\n d_1.terminate();\n }\n };\n if (sc_1 >= 0)\n file_1.size = sc_1, file_1.originalSize = su_1;\n this_1.onfile(file_1);\n }\n return \"break\";\n }\n else if (oc) {\n if (sig == 0x8074B50) {\n is = i += 12 + (oc == -2 && 8), f = 3, this_1.c = 0;\n return \"break\";\n }\n else if (sig == 0x2014B50) {\n is = i -= 4, f = 3, this_1.c = 0;\n return \"break\";\n }\n }\n };\n var this_1 = this;\n for (; i < l - 4; ++i) {\n var state_1 = _loop_2();\n if (state_1 === \"break\")\n break;\n }\n this.p = et;\n if (oc < 0) {\n var dat = f ? buf.subarray(0, is - 12 - (oc == -2 && 8) - (b4(buf, is - 16) == 0x8074B50 && 4)) : buf.subarray(0, i);\n if (add)\n add.push(dat, !!f);\n else\n this.k[+(f == 2)].push(dat);\n }\n if (f & 2)\n return this.push(buf.subarray(i), final);\n this.p = buf.subarray(i);\n }\n if (final) {\n if (this.c)\n err(13);\n this.p = null;\n }\n };\n /**\n * Registers a decoder with the stream, allowing for files compressed with\n * the compression type provided to be expanded correctly\n * @param decoder The decoder constructor\n */\n Unzip.prototype.register = function (decoder) {\n this.o[decoder.compression] = decoder;\n };\n return Unzip;\n}());\nexport { Unzip };\nvar mt = typeof queueMicrotask == 'function' ? queueMicrotask : typeof setTimeout == 'function' ? setTimeout : function (fn) { fn(); };\nexport function unzip(data, opts, cb) {\n if (!cb)\n cb = opts, opts = {};\n if (typeof cb != 'function')\n err(7);\n var term = [];\n var tAll = function () {\n for (var i = 0; i < term.length; ++i)\n term[i]();\n };\n var files = {};\n var cbd = function (a, b) {\n mt(function () { cb(a, b); });\n };\n mt(function () { cbd = cb; });\n var e = data.length - 22;\n for (; b4(data, e) != 0x6054B50; --e) {\n if (!e || data.length - e > 65558) {\n cbd(err(13, 0, 1), null);\n return tAll;\n }\n }\n ;\n var lft = b2(data, e + 8);\n if (lft) {\n var c = lft;\n var o = b4(data, e + 16);\n var z = o == 4294967295;\n if (z) {\n e = b4(data, e - 12);\n if (b4(data, e) != 0x6064B50) {\n cbd(err(13, 0, 1), null);\n return tAll;\n }\n c = lft = b4(data, e + 32);\n o = b4(data, e + 48);\n }\n var fltr = opts && opts.filter;\n var _loop_3 = function (i) {\n var _a = zh(data, o, z), c_1 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);\n o = no;\n var cbl = function (e, d) {\n if (e) {\n tAll();\n cbd(e, null);\n }\n else {\n if (d)\n files[fn] = d;\n if (!--lft)\n cbd(null, files);\n }\n };\n if (!fltr || fltr({\n name: fn,\n size: sc,\n originalSize: su,\n compression: c_1\n })) {\n if (!c_1)\n cbl(null, slc(data, b, b + sc));\n else if (c_1 == 8) {\n var infl = data.subarray(b, b + sc);\n if (sc < 320000) {\n try {\n cbl(null, inflateSync(infl, new u8(su)));\n }\n catch (e) {\n cbl(e, null);\n }\n }\n else\n term.push(inflate(infl, { size: su }, cbl));\n }\n else\n cbl(err(14, 'unknown compression type ' + c_1, 1), null);\n }\n else\n cbl(null, null);\n };\n for (var i = 0; i < c; ++i) {\n _loop_3(i);\n }\n }\n else\n cbd(null, {});\n return tAll;\n}\n/**\n * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better\n * performance with more than one file.\n * @param data The raw compressed ZIP file\n * @param opts The ZIP extraction options\n * @returns The decompressed files\n */\nexport function unzipSync(data, opts) {\n var files = {};\n var e = data.length - 22;\n for (; b4(data, e) != 0x6054B50; --e) {\n if (!e || data.length - e > 65558)\n err(13);\n }\n ;\n var c = b2(data, e + 8);\n if (!c)\n return {};\n var o = b4(data, e + 16);\n var z = o == 4294967295;\n if (z) {\n e = b4(data, e - 12);\n if (b4(data, e) != 0x6064B50)\n err(13);\n c = b4(data, e + 32);\n o = b4(data, e + 48);\n }\n var fltr = opts && opts.filter;\n for (var i = 0; i < c; ++i) {\n var _a = zh(data, o, z), c_2 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);\n o = no;\n if (!fltr || fltr({\n name: fn,\n size: sc,\n originalSize: su,\n compression: c_2\n })) {\n if (!c_2)\n files[fn] = slc(data, b, b + sc);\n else if (c_2 == 8)\n files[fn] = inflateSync(data.subarray(b, b + sc), new u8(su));\n else\n err(14, 'unknown compression type ' + c_2);\n }\n }\n return files;\n}\n"],"names":["SoraE2EE","constructor","RTCRtpSender","prototype","createEncodedStreams","Error","this","worker","onWorkerDisconnect","startWorker","workerScript","atob","Worker","URL","createObjectURL","Blob","type","onmessage","event","operation","data","clearWorker","postMessage","terminateWorker","terminate","async","preKeyBundle","window","e2ee","init","setupSenderTransform","sender","track","senderStreams","readableStream","readable","writableStream","writable","message","setupReceiverTransform","receiver","receiverStreams","postRemoteSecretKeyMaterials","result","remoteSecretKeyMaterials","postRemoveRemoteDeriveKey","connectionId","postSelfSecretKeyMaterial","selfConnectionId","selfKeyId","selfSecretKeyMaterial","waitingTime","startSession","err","identityKey","signedPreKey","preKeySignature","stopSession","receiveMessage","start","addPreKeyBundle","selfFingerprint","remoteFingerprints","static","wasmUrl","undefined","console","warn","global","self","require","fs","Object","keys","enosys","code","outputBuf","constants","O_WRONLY","O_RDWR","O_CREAT","O_TRUNC","O_APPEND","O_EXCL","writeSync","fd","buf","decoder","decode","nl","lastIndexOf","log","substr","length","write","offset","position","callback","chmod","path","mode","chown","uid","gid","close","fchmod","fchown","fstat","fsync","ftruncate","lchown","link","lstat","mkdir","perm","open","flags","read","buffer","readdir","readlink","rename","from","to","rmdir","stat","symlink","truncate","unlink","utimes","atime","mtime","process","getuid","getgid","geteuid","getegid","getgroups","pid","ppid","umask","cwd","chdir","crypto","nodeCrypto","getRandomValues","b","randomFillSync","performance","now","sec","nsec","hrtime","TextEncoder","TextDecoder","encoder","Go","argv","env","exit","_exitPromise","Promise","resolve","_resolveExitPromise","_pendingEvent","_scheduledTimeouts","Map","_nextCallbackTimeoutID","setInt64","addr","v","mem","setUint32","Math","floor","getInt64","getUint32","getInt32","loadValue","f","getFloat64","isNaN","id","_values","storeValue","nanHead","setFloat64","_ids","get","_idPool","pop","_goRefCounts","set","typeFlag","loadSlice","array","len","Uint8Array","_inst","exports","loadSliceOfValues","a","Array","i","loadString","saddr","DataView","timeOrigin","Date","importObject","go","sp","exited","p","n","msec","getTime","setInt32","setTimeout","_resume","has","clearTimeout","delete","push","Reflect","getsp","deleteProperty","m","args","apply","setUint8","construct","parseInt","str","encode","String","dst","src","Uint8ClampedArray","toCopy","subarray","debug","value","instance","NaN","fill","Infinity","strPtr","ptr","bytes","argc","argvPtrs","forEach","arg","sort","key","run","resume","_makeFuncWrapper","arguments","main","module","versions","electron","error","slice","assign","TMPDIR","tmpdir","WebAssembly","instantiate","readFileSync","then","on","catch","instantiateStreaming","fetch","version","u8","u16","Uint16Array","u32","Uint32Array","fleb","fdeb","clim","freb","eb","r","j","_a","fl","revfl","_b","revfd","rev","x","hMap","cd","mb","s","l","co","le","rvb","sv","r_1","flt","fdt","flm","flrm","fdm","fdrm","max","bits","d","o","bits16","shft","slc","e","BYTES_PER_ELEMENT","ec","ind","msg","nt","captureStackTrace","wbits","wbits16","hTree","t","t2","et","i0","i1","i2","maxSym","tr","mbt","ln","dt","lft","cst","i2_1","i2_2","i2_3","lc","c","cl","cli","cln","cls","w","clen","cf","wfblk","out","pos","dat","wblk","final","syms","lf","df","li","bs","bl","dlt","mlb","ddt","mdb","_c","lclt","nlc","_d","lcdt","ndc","lcfreq","_e","lct","mlcb","nlcc","lm","ll","dm","dl","flen","ftlen","dtlen","llm","lcts","it","clct","deo","dopt","opt","pre","post","st","lvl","plvl","lst","ceil","msk_1","prev","head","bs1_1","bs2_1","hsh","lc_1","wi","hv","imod","pimod","rem","ch_1","dif","maxn","min","maxd","ml","mmd","md","ti","lin","din","dflt","level","zlibSync","opts","adler","lv","zlh","wbytes","unzlibSync","sl","noBuf","noSt","cbuf","nbuf","bt","lbt","dbt","tbts","hLit","hcLen","tl","ldt","clt","clb","clbmsk","clm","lt","lms","dms","lpos","sym","add","dsym","end","inflt","td","stream"],"mappings":"qOAWA,MAAMA,EACFC,cAII,MADoCC,aAAaC,UAAUC,qBAEvD,MAAM,IAAIC,MAAM,0CAEpBC,KAAKC,OAAS,KACdD,KAAKE,mBAAqB,KAG9BC,cAEI,MAAMC,EAAeC,KAfP,wjwBAgBdL,KAAKC,OAAS,IAAIK,OAAOC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,GAAe,CAAEM,KAAM,6BAC9EV,KAAKC,OAAOU,UAAaC,IACrB,MAAMC,UAAEA,GAAcD,EAAME,KACV,eAAdD,GAAiE,mBAA5Bb,KAAKE,oBAC1CF,KAAKE,sBAKjBa,cACQf,KAAKC,QACLD,KAAKC,OAAOe,YAAY,CACpBN,KAAM,UAKlBO,kBACQjB,KAAKC,QAC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,EAAI,EAAG,qBACA,GAAPsQ,EAAE,IACFtQ,EAAI,EAAG,wDAoccjC,EAAK4N,SAAS,GAAI,IAAKoH,GAxc1C,IAAUzC,EA+jBpB,IAAIkJ,EAA2B,oBAAfnT,aAA4C,IAAIA,YAGhE,IACImT,EAAGrX,OAAOoP,EAAI,CAAEkI,QAAQ,IAClB,EAEV,MAAO9I"} \ No newline at end of file diff --git a/dist/sora.mjs b/dist/sora.mjs index b1636656..9a225189 100644 --- a/dist/sora.mjs +++ b/dist/sora.mjs @@ -1,7 +1,7 @@ /** * sora-js-sdk * WebRTC SFU Sora JavaScript SDK - * @version: 2021.2.1 + * @version: 2021.2.2 * @author: Shiguredo Inc. * @license: Apache-2.0 **/ @@ -822,8 +822,10 @@ var hMap = (function (cd, mb, r) { // u16 "map": index -> # of codes with bit length = index var l = new u16(mb); // length of cd must be 288 (total # of codes) - for (; i < s; ++i) - ++l[cd[i] - 1]; + for (; i < s; ++i) { + if (cd[i]) + ++l[cd[i] - 1]; + } // u16 "map": index -> minimum code for bit length = index var le = new u16(mb); for (i = 0; i < mb; ++i) { @@ -909,7 +911,7 @@ var slc = function (v, s, e) { if (e == null || e > v.length) e = v.length; // can't use .constructor in case user-supplied - var n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s); + var n = new (v.BYTES_PER_ELEMENT == 2 ? u16 : v.BYTES_PER_ELEMENT == 4 ? u32 : u8)(e - s); n.set(v.subarray(s, e)); return n; }; @@ -1357,15 +1359,11 @@ var dflt = function (dat, lvl, plvl, pre, post, lst) { for (var i = 0; i <= s; i += 65535) { // end var e = i + 65535; - if (e < s) { - // write full block - pos = wfblk(w, pos, dat.subarray(i, e)); - } - else { + if (e >= s) { // write final block - w[i] = lst; - pos = wfblk(w, pos, dat.subarray(i, s)); + w[pos >> 3] = lst; } + pos = wfblk(w, pos + 1, dat.subarray(i, e)); } } else { @@ -1629,7 +1627,7 @@ function createSignalingMessage(offerSDP, role, channelId, metadata, options, re } const message = { type: "connect", - sora_client: "Sora JavaScript SDK 2021.2.1", + sora_client: "Sora JavaScript SDK 2021.2.2", environment: window.navigator.userAgent, role: role, channel_id: channelId, @@ -4372,7 +4370,7 @@ var sora = { * @public */ version: function () { - return "2021.2.1"; + return "2021.2.2"; }, /** * WebRTC のユーティリティ関数群 diff --git a/package-lock.json b/package-lock.json index d5778b21..78dd755d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sora-js-sdk", - "version": "2021.2.0", + "version": "2021.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "sora-js-sdk", - "version": "2021.2.0", + "version": "2021.2.2", "license": "Apache-2.0", "workspaces": [ "packages/go-wasm", @@ -3488,9 +3488,9 @@ } }, "node_modules/fflate": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.1.tgz", - "integrity": "sha512-VYM2Xy1gSA5MerKzCnmmuV2XljkpKwgJBKezW+495TTnTCh1x5HcYa1aH8wRU/MfTGhW4ziXqgwprgQUVl3Ohw==" + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.3.tgz", + "integrity": "sha512-0Zz1jOzJWERhyhsimS54VTqOteCNwRtIlh8isdL0AXLo0g7xNTfTL7oWrkmCnPhZGocKIkWHBistBrrpoNH3aw==" }, "node_modules/figgy-pudding": { "version": "3.5.2", @@ -8323,7 +8323,7 @@ "name": "@sora/sdk", "dependencies": { "@sora/e2ee": "^2021.1.0", - "fflate": "^0.7.1", + "fflate": "^0.7.3", "rollup-plugin-terser": "^7.0.2" }, "devDependencies": { @@ -9392,7 +9392,7 @@ "eslint": "7.32.0", "eslint-config-prettier": "8.3.0", "eslint-plugin-prettier": "4.0.0", - "fflate": "^0.7.1", + "fflate": "^0.7.3", "jest": "^27.2.4", "prettier": "^2.4.1", "rollup": "^2.58.0", @@ -11055,9 +11055,9 @@ } }, "fflate": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.1.tgz", - "integrity": "sha512-VYM2Xy1gSA5MerKzCnmmuV2XljkpKwgJBKezW+495TTnTCh1x5HcYa1aH8wRU/MfTGhW4ziXqgwprgQUVl3Ohw==" + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.3.tgz", + "integrity": "sha512-0Zz1jOzJWERhyhsimS54VTqOteCNwRtIlh8isdL0AXLo0g7xNTfTL7oWrkmCnPhZGocKIkWHBistBrrpoNH3aw==" }, "figgy-pudding": { "version": "3.5.2", diff --git a/package.json b/package.json index 7ec27c3d..70586dc7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sora-js-sdk", - "version": "2021.2.1", + "version": "2021.2.2", "description": "WebRTC SFU Sora JavaScript SDK", "main": "dist/sora.min.js", "module": "dist/sora.mjs", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 6b9449a1..3b72c0a5 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@sora/e2ee": "^2021.1.0", - "fflate": "^0.7.1", + "fflate": "^0.7.3", "rollup-plugin-terser": "^7.0.2" } }