text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).IJS={})}(this,(function(exports){"use strict";const bitMethods={getBit(t){return this.data[getSlot(t)]&1<<getShift(t)?1:0},setBit(t){this.data[getSlot(t)]|=1<<getShift(t)},clearBit(t){this.data[getSlot(t)]&=~(1<<getShift(t))},toggleBit(t){this.data[getSlot(t)]^=1<<getShift(t)},getBitXY(t,e){return t>=this.width||e>=this.height?0:this.getBit(e*this.width+t)},setBitXY(t,e){this.setBit(e*this.width+t)},clearBitXY(t,e){this.clearBit(e*this.width+t)},toggleBitXY(t,e){this.toggleBit(e*this.width+t)}};function getSlot(t){return t>>3}function getShift(t){return 7-(7&t)}function setBitMethods(t){for(const e in bitMethods)t.prototype[e]=bitMethods[e]}function checkProcessable(t,e={}){let{bitDepth:r,alpha:i,colorModel:n,components:s,channels:a}=e;if("string"!=typeof t||0===t.length)throw new TypeError("processName must be a string");if(r&&(Array.isArray(r)||(r=[r]),!r.includes(this.bitDepth)))throw new TypeError(`The process: ${t} can only be applied if bit depth is in: ${r}`);if(i&&(Array.isArray(i)||(i=[i]),!i.includes(this.alpha)))throw new TypeError(`The process: ${t} can only be applied if alpha is in: ${i}`);if(n&&(Array.isArray(n)||(n=[n]),!n.includes(this.colorModel)))throw new TypeError(`The process: ${t} can only be applied if color model is in: ${n}`);if(s&&(Array.isArray(s)||(s=[s]),!s.includes(this.components))){let e=`The process: ${t} can only be applied if the number of components is in: ${s}`;throw 1===s.length&&1===s[0]?new TypeError(`${e}.\rYou should transform your image using "image.grey()" before applying the algorithm.`):new TypeError(e)}if(a&&(Array.isArray(a)||(a=[a]),!a.includes(this.channels)))throw new TypeError(`The process: ${t} can only be applied if the number of channels is in: ${a}`)}function createBlob(t,e){t=t||[],"string"==typeof(e=e||{})&&(e={type:e});try{return new Blob(t,e)}catch(n){if("TypeError"!==n.name)throw n;for(var r=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),i=0;i<t.length;i+=1)r.append(t[i]);return r.getBlob(e.type)}}function dataURLToBlob(t){var e=t.match(/data:([^;]+)/)[1],r=t.replace(/^[^,]+,/,"");return createBlob([binaryStringToArrayBuffer(atob(r))],{type:e})}function canvasToBlob(t,e,r){return"function"==typeof t.toBlob?new Promise((function(i){t.toBlob(i,e,r)})):Promise.resolve(dataURLToBlob(t.toDataURL(e,r)))}function binaryStringToArrayBuffer(t){for(var e=t.length,r=new ArrayBuffer(e),i=new Uint8Array(r),n=-1;++n<e;)i[n]=t.charCodeAt(n);return r}var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getAugmentedNamespace(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})})),e}function createCommonjsModule(t){var e={exports:{}};return t(e,e.exports),e.exports}function commonjsRequire(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.')}
  /*! https://mths.be/utf8js v2.1.2 by @mathias */var utf8=createCommonjsModule((function(t,e){!function(r){var i=e,n=t&&t.exports==i&&t,s="object"==typeof commonjsGlobal&&commonjsGlobal;s.global!==s&&s.window!==s||(r=s);var a,o,h,l=String.fromCharCode;function c(t){for(var e,r,i=[],n=0,s=t.length;n<s;)(e=t.charCodeAt(n++))>=55296&&e<=56319&&n<s?56320==(64512&(r=t.charCodeAt(n++)))?i.push(((1023&e)<<10)+(1023&r)+65536):(i.push(e),n--):i.push(e);return i}function u(t){if(t>=55296&&t<=57343)throw Error("Lone surrogate U+"+t.toString(16).toUpperCase()+" is not a scalar value")}function f(t,e){return l(t>>e&63|128)}function d(t){if(0==(4294967168&t))return l(t);var e="";return 0==(4294965248&t)?e=l(t>>6&31|192):0==(4294901760&t)?(u(t),e=l(t>>12&15|224),e+=f(t,6)):0==(4292870144&t)&&(e=l(t>>18&7|240),e+=f(t,12),e+=f(t,6)),e+=l(63&t|128)}function m(){if(h>=o)throw Error("Invalid byte index");var t=255&a[h];if(h++,128==(192&t))return 63&t;throw Error("Invalid continuation byte")}function g(){var t,e;if(h>o)throw Error("Invalid byte index");if(h==o)return!1;if(t=255&a[h],h++,0==(128&t))return t;if(192==(224&t)){if((e=(31&t)<<6|m())>=128)return e;throw Error("Invalid continuation byte")}if(224==(240&t)){if((e=(15&t)<<12|m()<<6|m())>=2048)return u(e),e;throw Error("Invalid continuation byte")}if(240==(248&t)&&(e=(7&t)<<18|m()<<12|m()<<6|m())>=65536&&e<=1114111)return e;throw Error("Invalid UTF-8 detected")}var p={version:"2.1.2",encode:function(t){for(var e=c(t),r=e.length,i=-1,n="";++i<r;)n+=d(e[i]);return n},decode:function(t){a=c(t),o=a.length,h=0;for(var e,r=[];!1!==(e=g());)r.push(e);return function(t){for(var e,r=t.length,i=-1,n="";++i<r;)(e=t[i])>65535&&(n+=l((e-=65536)>>>10&1023|55296),e=56320|1023&e),n+=l(e);return n}(r)}};if(i&&!i.nodeType)if(n)n.exports=p;else{var w={}.hasOwnProperty;for(var _ in p)w.call(p,_)&&(i[_]=p[_])}else r.utf8=p}(commonjsGlobal)}));const defaultByteLength$2=8192,charArray$1=[];class IOBuffer$2{constructor(t,e){e=e||{};var r=!1;void 0===t&&(t=defaultByteLength$2),"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this._lastWrittenByte=t.byteLength);const i=e.offset?e.offset>>>0:0;let n=t.byteLength-i,s=i;t.buffer&&(t.byteLength!==t.buffer.byteLength&&(s=t.byteOffset+i),t=t.buffer),this._lastWrittenByte=r?n:0,this.buffer=t,this.length=n,this.byteLength=n,this.byteOffset=s,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,s,n),this._mark=0,this._marks=[]}available(t){return void 0===t&&(t=1),this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t){return void 0===t&&(t=1),this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t){if(void 0===t&&(t=1),!this.available(t)){const e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t){void 0===t&&(t=1);for(var e=new Uint8Array(t),r=0;r<t;r++)e[r]=this.readByte();return e}readInt16(){var t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){var t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){var t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){var t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){var t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){var t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t){void 0===t&&(t=1),charArray$1.length=t;for(var e=0;e<t;e++)charArray$1[e]=this.readChar();return charArray$1.join("")}readUtf8(t){void 0===t&&(t=1);const e=this.readChars(t);return utf8.decode(e)}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(var e=0;e<t.length;e++)this._data.setUint8(this.offset++,t[e]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(var e=0;e<t.length;e++)this.writeUint8(t.charCodeAt(e));return this}writeUtf8(t){const e=utf8.encode(t);return this.writeChars(e)}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this._lastWrittenByte)}getBuffer(){return"undefined"!=typeof Buffer?Buffer.from(this.toArray()):this.toArray()}_updateLastWrittenByte(){this.offset>this._lastWrittenByte&&(this._lastWrittenByte=this.offset)}}var IOBuffer_1$1=IOBuffer$2,constants$3={BITMAPV5HEADER:{LogicalColorSpace:{LCS_CALIBRATED_RGB:0,LCS_sRGB:1934772034,LCS_WINDOWS_COLOR_SPACE:1466527264},Compression:{BI_RGB:0,BI_RLE8:1,BI_RLE4:2,BI_BITFIELDS:3,BI_JPEG:4,BI_PNG:5,BI_CMYK:11,BI_CMYKRLE8:12,BI_CMYKRLE4:13},GamutMappingIntent:{LCS_GM_ABS_COLORIMETRIC:8,LCS_GM_BUSINESS:1,LCS_GM_GRAPHICS:2,LCS_GM_IMAGES:4}}};const tableLeft=[];for(var i$3=0;i$3<=8;i$3++)tableLeft.push(255<<i$3);var encode$3=function(t){if(1!==t.bitDepth)throw new Error("Only bitDepth of 1 is supported");if(!t.height||!t.width)throw new Error("ImageData width and height are required");if(1!==t.components)throw new Error("Only 1 component is supported");if(1!==t.channels)throw new Error("Only 1 channel is supported");var e=new IOBuffer_1$1;e.skip(14),writeBitmapV5Header(e,t),writeColorTable(e,t);const r=e.offset;return writePixelArray(e,t),e.rewind(),writeBitmapFileHeader(e,r),e.getBuffer()};function writePixelArray(t,e){const r=4*Math.floor((e.bitDepth*e.width+31)/32),i=Math.ceil(e.bitDepth*e.width/8),n=r-i,s=e.bitDepth*e.width%8,a=0===s?0:8-s,o=r*e.height;var h,l;const c=new IOBuffer_1$1(e.data);let u=0,f=0,d=8;t.mark(),l=c.readUint8();for(var m=e.height-1;m>=0;m--){const e=0===m;t.reset(),t.skip(m*r);for(var g=0;g<i;g++){const r=g===i-1;f<=a&&r?(t.writeByte(l<<f),0!==a&&a!==f||e||(h=l,l=c.readByte())):0===f?(h=l,l=c.readUint8(),t.writeByte(h)):(h=l,l=c.readUint8(),t.writeByte(h<<f&tableLeft[f]|l>>d)),r?(u+=s||8,t.skip(n),f=u%8,d=8-f):u+=8}}r>i&&(t.reset(),t.skip(o-1),t.writeUint8(0))}function writeColorTable(t,e){e.bitDepth>8||t.writeUint32(0).writeUint32(16777215)}function writeBitmapFileHeader(t,e){t.writeChars("BM"),t.writeInt32(t._lastWrittenByte),t.writeUint16(0),t.writeUint16(0),t.writeUint32(e)}function writeBitmapV5Header(t,e){t.writeUint32(124).writeInt32(e.width).writeInt32(e.height).writeUint16(1).writeUint16(e.bitDepth).writeUint32(constants$3.BITMAPV5HEADER.Compression.BI_RGB).writeUint32(e.width*e.height*e.bitDepth).writeInt32(0).writeInt32(0).writeUint32(Math.pow(2,e.bitDepth)).writeUint32(Math.pow(2,e.bitDepth)).writeUint32(4278190080).writeUint32(16711680).writeUint32(65280).writeUint32(255).writeUint32(constants$3.BITMAPV5HEADER.LogicalColorSpace.LCS_sRGB).skip(36).skip(12).writeUint32(constants$3.BITMAPV5HEADER.GamutMappingIntent.LCS_GM_IMAGES).skip(12)}var encode$2=encode$3;const decoder$1=new TextDecoder("utf-8");function decode$5(t){return decoder$1.decode(t)}const encoder$1=new TextEncoder;function encode$1(t){return encoder$1.encode(t)}const defaultByteLength$1=8192;class IOBuffer$1{constructor(t=defaultByteLength$1,e={}){let r=!1;"number"==typeof t?t=new ArrayBuffer(t):(r=!0,this.lastWrittenByte=t.byteLength);const i=e.offset?e.offset>>>0:0,n=t.byteLength-i;let s=i;(ArrayBuffer.isView(t)||t instanceof IOBuffer$1)&&(t.byteLength!==t.buffer.byteLength&&(s=t.byteOffset+i),t=t.buffer),this.lastWrittenByte=r?n:0,this.buffer=t,this.length=n,this.byteLength=n,this.byteOffset=s,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,s,n),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){const e=2*(this.offset+t),r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t=1){const e=new Uint8Array(t);for(let r=0;r<t;r++)e[r]=this.readByte();return e}readInt16(){const t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){const t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){const t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){const t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){const t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){const t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let e="";for(let r=0;r<t;r++)e+=this.readChar();return e}readUtf8(t=1){return decode$5(this.readBytes(t))}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let e=0;e<t.length;e++)this._data.setUint8(this.offset++,t[e]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let e=0;e<t.length;e++)this.writeUint8(t.charCodeAt(e));return this}writeUtf8(t){return this.writeBytes(encode$1(t))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}
  /*! pako 2.0.3 https://github.com/nodeca/pako @license (MIT AND Zlib) */const Z_FIXED=4,Z_BINARY=0,Z_TEXT=1,Z_UNKNOWN=2;function zero(t){let e=t.length;for(;--e>=0;)t[e]=0}const STORED_BLOCK=0,STATIC_TREES=1,DYN_TREES=2,MIN_MATCH=3,MAX_MATCH=258,LENGTH_CODES=29,LITERALS=256,L_CODES=LITERALS+1+LENGTH_CODES,D_CODES=30,BL_CODES=19,HEAP_SIZE=2*L_CODES+1,MAX_BITS=15,Buf_size=16,MAX_BL_BITS=7,END_BLOCK=256,REP_3_6=16,REPZ_3_10=17,REPZ_11_138=18,extra_lbits=new Uint8Array([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]),extra_dbits=new Uint8Array([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]),extra_blbits=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),bl_order=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),DIST_CODE_LEN=512,static_ltree=new Array(2*(L_CODES+2));zero(static_ltree);const static_dtree=new Array(2*D_CODES);zero(static_dtree);const _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);const _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);const base_length=new Array(LENGTH_CODES);zero(base_length);const base_dist=new Array(D_CODES);function StaticTreeDesc(t,e,r,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=r,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}let static_l_desc,static_d_desc,static_bl_desc;function TreeDesc(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}zero(base_dist);const d_code=t=>t<256?_dist_code[t]:_dist_code[256+(t>>>7)],put_short=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},send_bits=(t,e,r)=>{t.bi_valid>Buf_size-r?(t.bi_buf|=e<<t.bi_valid&65535,put_short(t,t.bi_buf),t.bi_buf=e>>Buf_size-t.bi_valid,t.bi_valid+=r-Buf_size):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=r)},send_code=(t,e,r)=>{send_bits(t,r[2*e],r[2*e+1])},bi_reverse=(t,e)=>{let r=0;do{r|=1&t,t>>>=1,r<<=1}while(--e>0);return r>>>1},bi_flush=t=>{16===t.bi_valid?(put_short(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)},gen_bitlen=(t,e)=>{const r=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,s=e.stat_desc.has_stree,a=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,c,u,f,d,m,g=0;for(f=0;f<=MAX_BITS;f++)t.bl_count[f]=0;for(r[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<HEAP_SIZE;l++)c=t.heap[l],f=r[2*r[2*c+1]+1]+1,f>h&&(f=h,g++),r[2*c+1]=f,c>i||(t.bl_count[f]++,d=0,c>=o&&(d=a[c-o]),m=r[2*c],t.opt_len+=m*(f+d),s&&(t.static_len+=m*(n[2*c+1]+d)));if(0!==g){do{for(f=h-1;0===t.bl_count[f];)f--;t.bl_count[f]--,t.bl_count[f+1]+=2,t.bl_count[h]--,g-=2}while(g>0);for(f=h;0!==f;f--)for(c=t.bl_count[f];0!==c;)u=t.heap[--l],u>i||(r[2*u+1]!==f&&(t.opt_len+=(f-r[2*u+1])*r[2*u],r[2*u+1]=f),c--)}},gen_codes=(t,e,r)=>{const i=new Array(MAX_BITS+1);let n,s,a=0;for(n=1;n<=MAX_BITS;n++)i[n]=a=a+r[n-1]<<1;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=bi_reverse(i[e]++,e))}},tr_static_init=()=>{let t,e,r,i,n;const s=new Array(MAX_BITS+1);for(r=0,i=0;i<LENGTH_CODES-1;i++)for(base_length[i]=r,t=0;t<1<<extra_lbits[i];t++)_length_code[r++]=i;for(_length_code[r-1]=i,n=0,i=0;i<16;i++)for(base_dist[i]=n,t=0;t<1<<extra_dbits[i];t++)_dist_code[n++]=i;for(n>>=7;i<D_CODES;i++)for(base_dist[i]=n<<7,t=0;t<1<<extra_dbits[i]-7;t++)_dist_code[256+n++]=i;for(e=0;e<=MAX_BITS;e++)s[e]=0;for(t=0;t<=143;)static_ltree[2*t+1]=8,t++,s[8]++;for(;t<=255;)static_ltree[2*t+1]=9,t++,s[9]++;for(;t<=279;)static_ltree[2*t+1]=7,t++,s[7]++;for(;t<=287;)static_ltree[2*t+1]=8,t++,s[8]++;for(gen_codes(static_ltree,L_CODES+1,s),t=0;t<D_CODES;t++)static_dtree[2*t+1]=5,static_dtree[2*t]=bi_reverse(t,5);static_l_desc=new StaticTreeDesc(static_ltree,extra_lbits,LITERALS+1,L_CODES,MAX_BITS),static_d_desc=new StaticTreeDesc(static_dtree,extra_dbits,0,D_CODES,MAX_BITS),static_bl_desc=new StaticTreeDesc(new Array(0),extra_blbits,0,BL_CODES,MAX_BL_BITS)},init_block=t=>{let e;for(e=0;e<L_CODES;e++)t.dyn_ltree[2*e]=0;for(e=0;e<D_CODES;e++)t.dyn_dtree[2*e]=0;for(e=0;e<BL_CODES;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*END_BLOCK]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},bi_windup=t=>{t.bi_valid>8?put_short(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},copy_block=(t,e,r,i)=>{bi_windup(t),i&&(put_short(t,r),put_short(t,~r)),t.pending_buf.set(t.window.subarray(e,e+r),t.pending),t.pending+=r},smaller=(t,e,r,i)=>{const n=2*e,s=2*r;return t[n]<t[s]||t[n]===t[s]&&i[e]<=i[r]},pqdownheap=(t,e,r)=>{const i=t.heap[r];let n=r<<1;for(;n<=t.heap_len&&(n<t.heap_len&&smaller(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!smaller(e,i,t.heap[n],t.depth));)t.heap[r]=t.heap[n],r=n,n<<=1;t.heap[r]=i},compress_block=(t,e,r)=>{let i,n,s,a,o=0;if(0!==t.last_lit)do{i=t.pending_buf[t.d_buf+2*o]<<8|t.pending_buf[t.d_buf+2*o+1],n=t.pending_buf[t.l_buf+o],o++,0===i?send_code(t,n,e):(s=_length_code[n],send_code(t,s+LITERALS+1,e),a=extra_lbits[s],0!==a&&(n-=base_length[s],send_bits(t,n,a)),i--,s=d_code(i),send_code(t,s,r),a=extra_dbits[s],0!==a&&(i-=base_dist[s],send_bits(t,i,a)))}while(o<t.last_lit);send_code(t,END_BLOCK,e)},build_tree=(t,e)=>{const r=e.dyn_tree,i=e.stat_desc.static_tree,n=e.stat_desc.has_stree,s=e.stat_desc.elems;let a,o,h,l=-1;for(t.heap_len=0,t.heap_max=HEAP_SIZE,a=0;a<s;a++)0!==r[2*a]?(t.heap[++t.heap_len]=l=a,t.depth[a]=0):r[2*a+1]=0;for(;t.heap_len<2;)h=t.heap[++t.heap_len]=l<2?++l:0,r[2*h]=1,t.depth[h]=0,t.opt_len--,n&&(t.static_len-=i[2*h+1]);for(e.max_code=l,a=t.heap_len>>1;a>=1;a--)pqdownheap(t,r,a);h=s;do{a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],pqdownheap(t,r,1),o=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=o,r[2*h]=r[2*a]+r[2*o],t.depth[h]=(t.depth[a]>=t.depth[o]?t.depth[a]:t.depth[o])+1,r[2*a+1]=r[2*o+1]=h,t.heap[1]=h++,pqdownheap(t,r,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],gen_bitlen(t,e),gen_codes(r,l,t.bl_count)},scan_tree=(t,e,r)=>{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),e[2*(r+1)+1]=65535,i=0;i<=r;i++)n=a,a=e[2*(i+1)+1],++o<h&&n===a||(o<l?t.bl_tree[2*n]+=o:0!==n?(n!==s&&t.bl_tree[2*n]++,t.bl_tree[2*REP_3_6]++):o<=10?t.bl_tree[2*REPZ_3_10]++:t.bl_tree[2*REPZ_11_138]++,o=0,s=n,0===a?(h=138,l=3):n===a?(h=6,l=3):(h=7,l=4))},send_tree=(t,e,r)=>{let i,n,s=-1,a=e[1],o=0,h=7,l=4;for(0===a&&(h=138,l=3),i=0;i<=r;i++)if(n=a,a=e[2*(i+1)+1],!(++o<h&&n===a)){if(o<l)do{send_code(t,n,t.bl_tree)}while(0!=--o);else 0!==n?(n!==s&&(send_code(t,n,t.bl_tree),o--),send_code(t,REP_3_6,t.bl_tree),send_bits(t,o-3,2)):o<=10?(send_code(t,REPZ_3_10,t.bl_tree),send_bits(t,o-3,3)):(send_code(t,REPZ_11_138,t.bl_tree),send_bits(t,o-11,7));o=0,s=n,0===a?(h=138,l=3):n===a?(h=6,l=3):(h=7,l=4)}},build_bl_tree=t=>{let e;for(scan_tree(t,t.dyn_ltree,t.l_desc.max_code),scan_tree(t,t.dyn_dtree,t.d_desc.max_code),build_tree(t,t.bl_desc),e=BL_CODES-1;e>=3&&0===t.bl_tree[2*bl_order[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e},send_all_trees=(t,e,r,i)=>{let n;for(send_bits(t,e-257,5),send_bits(t,r-1,5),send_bits(t,i-4,4),n=0;n<i;n++)send_bits(t,t.bl_tree[2*bl_order[n]+1],3);send_tree(t,t.dyn_ltree,e-1),send_tree(t,t.dyn_dtree,r-1)},detect_data_type=t=>{let e,r=4093624447;for(e=0;e<=31;e++,r>>>=1)if(1&r&&0!==t.dyn_ltree[2*e])return Z_BINARY;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return Z_TEXT;for(e=32;e<LITERALS;e++)if(0!==t.dyn_ltree[2*e])return Z_TEXT;return Z_BINARY};let static_init_done=!1;const _tr_init=t=>{static_init_done||(tr_static_init(),static_init_done=!0),t.l_desc=new TreeDesc(t.dyn_ltree,static_l_desc),t.d_desc=new TreeDesc(t.dyn_dtree,static_d_desc),t.bl_desc=new TreeDesc(t.bl_tree,static_bl_desc),t.bi_buf=0,t.bi_valid=0,init_block(t)},_tr_stored_block=(t,e,r,i)=>{send_bits(t,(STORED_BLOCK<<1)+(i?1:0),3),copy_block(t,e,r,!0)},_tr_align=t=>{send_bits(t,STATIC_TREES<<1,3),send_code(t,END_BLOCK,static_ltree),bi_flush(t)},_tr_flush_block=(t,e,r,i)=>{let n,s,a=0;t.level>0?(t.strm.data_type===Z_UNKNOWN&&(t.strm.data_type=detect_data_type(t)),build_tree(t,t.l_desc),build_tree(t,t.d_desc),a=build_bl_tree(t),n=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=n&&(n=s)):n=s=r+5,r+4<=n&&-1!==e?_tr_stored_block(t,e,r,i):t.strategy===Z_FIXED||s===n?(send_bits(t,(STATIC_TREES<<1)+(i?1:0),3),compress_block(t,static_ltree,static_dtree)):(send_bits(t,(DYN_TREES<<1)+(i?1:0),3),send_all_trees(t,t.l_desc.max_code+1,t.d_desc.max_code+1,a+1),compress_block(t,t.dyn_ltree,t.dyn_dtree)),init_block(t),i&&bi_windup(t)},_tr_tally=(t,e,r)=>(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&r,t.last_lit++,0===e?t.dyn_ltree[2*r]++:(t.matches++,e--,t.dyn_ltree[2*(_length_code[r]+LITERALS+1)]++,t.dyn_dtree[2*d_code(e)]++),t.last_lit===t.lit_bufsize-1);var _tr_init_1=_tr_init,_tr_stored_block_1=_tr_stored_block,_tr_flush_block_1=_tr_flush_block,_tr_tally_1=_tr_tally,_tr_align_1=_tr_align,trees={_tr_init:_tr_init_1,_tr_stored_block:_tr_stored_block_1,_tr_flush_block:_tr_flush_block_1,_tr_tally:_tr_tally_1,_tr_align:_tr_align_1};const adler32=(t,e,r,i)=>{let n=65535&t|0,s=t>>>16&65535|0,a=0;for(;0!==r;){a=r>2e3?2e3:r,r-=a;do{n=n+e[i++]|0,s=s+n|0}while(--a);n%=65521,s%=65521}return n|s<<16|0};var adler32_1=adler32;const makeTable=()=>{let t,e=[];for(var r=0;r<256;r++){t=r;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e},crcTable$1=new Uint32Array(makeTable()),crc32=(t,e,r,i)=>{const n=crcTable$1,s=i+r;t^=-1;for(let r=i;r<s;r++)t=t>>>8^n[255&(t^e[r])];return-1^t};var crc32_1=crc32,messages={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},constants={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:_tr_init$1,_tr_stored_block:_tr_stored_block$1,_tr_flush_block:_tr_flush_block$1,_tr_tally:_tr_tally$1,_tr_align:_tr_align$1}=trees,{Z_NO_FLUSH:Z_NO_FLUSH,Z_PARTIAL_FLUSH:Z_PARTIAL_FLUSH,Z_FULL_FLUSH:Z_FULL_FLUSH,Z_FINISH:Z_FINISH,Z_BLOCK:Z_BLOCK,Z_OK:Z_OK,Z_STREAM_END:Z_STREAM_END,Z_STREAM_ERROR:Z_STREAM_ERROR,Z_DATA_ERROR:Z_DATA_ERROR,Z_BUF_ERROR:Z_BUF_ERROR,Z_DEFAULT_COMPRESSION:Z_DEFAULT_COMPRESSION,Z_FILTERED:Z_FILTERED,Z_HUFFMAN_ONLY:Z_HUFFMAN_ONLY,Z_RLE:Z_RLE,Z_FIXED:Z_FIXED$1,Z_DEFAULT_STRATEGY:Z_DEFAULT_STRATEGY,Z_UNKNOWN:Z_UNKNOWN$1,Z_DEFLATED:Z_DEFLATED}=constants,MAX_MEM_LEVEL=9,MAX_WBITS=15,DEF_MEM_LEVEL=8,LENGTH_CODES$1=29,LITERALS$1=256,L_CODES$1=LITERALS$1+1+LENGTH_CODES$1,D_CODES$1=30,BL_CODES$1=19,HEAP_SIZE$1=2*L_CODES$1+1,MAX_BITS$1=15,MIN_MATCH$1=3,MAX_MATCH$1=258,MIN_LOOKAHEAD=MAX_MATCH$1+MIN_MATCH$1+1,PRESET_DICT=32,INIT_STATE=42,EXTRA_STATE=69,NAME_STATE=73,COMMENT_STATE=91,HCRC_STATE=103,BUSY_STATE=113,FINISH_STATE=666,BS_NEED_MORE=1,BS_BLOCK_DONE=2,BS_FINISH_STARTED=3,BS_FINISH_DONE=4,OS_CODE=3,err=(t,e)=>(t.msg=messages[e],e),rank=t=>(t<<1)-(t>4?9:0),zero$1=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let HASH_ZLIB=(t,e,r)=>(e<<t.hash_shift^r)&t.hash_mask,HASH=HASH_ZLIB;const flush_pending=t=>{const e=t.state;let r=e.pending;r>t.avail_out&&(r=t.avail_out),0!==r&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+r),t.next_out),t.next_out+=r,e.pending_out+=r,t.total_out+=r,t.avail_out-=r,e.pending-=r,0===e.pending&&(e.pending_out=0))},flush_block_only=(t,e)=>{_tr_flush_block$1(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,flush_pending(t.strm)},put_byte=(t,e)=>{t.pending_buf[t.pending++]=e},putShortMSB=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},read_buf=(t,e,r,i)=>{let n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,e.set(t.input.subarray(t.next_in,t.next_in+n),r),1===t.state.wrap?t.adler=adler32_1(t.adler,e,n,r):2===t.state.wrap&&(t.adler=crc32_1(t.adler,e,n,r)),t.next_in+=n,t.total_in+=n,n)},longest_match=(t,e)=>{let r,i,n=t.max_chain_length,s=t.strstart,a=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-MIN_LOOKAHEAD?t.strstart-(t.w_size-MIN_LOOKAHEAD):0,l=t.window,c=t.w_mask,u=t.prev,f=t.strstart+MAX_MATCH$1;let d=l[s+a-1],m=l[s+a];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do{if(r=e,l[r+a]===m&&l[r+a-1]===d&&l[r]===l[s]&&l[++r]===l[s+1]){s+=2,r++;do{}while(l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&l[++s]===l[++r]&&s<f);if(i=MAX_MATCH$1-(f-s),s=f-MAX_MATCH$1,i>a){if(t.match_start=e,a=i,i>=o)break;d=l[s+a-1],m=l[s+a]}}}while((e=u[e&c])>h&&0!=--n);return a<=t.lookahead?a:t.lookahead},fill_window=t=>{const e=t.w_size;let r,i,n,s,a;do{if(s=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-MIN_LOOKAHEAD)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,i=t.hash_size,r=i;do{n=t.head[--r],t.head[r]=n>=e?n-e:0}while(--i);i=e,r=i;do{n=t.prev[--r],t.prev[r]=n>=e?n-e:0}while(--i);s+=e}if(0===t.strm.avail_in)break;if(i=read_buf(t.strm,t.window,t.strstart+t.lookahead,s),t.lookahead+=i,t.lookahead+t.insert>=MIN_MATCH$1)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=HASH(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=HASH(t,t.ins_h,t.window[a+MIN_MATCH$1-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<MIN_MATCH$1)););}while(t.lookahead<MIN_LOOKAHEAD&&0!==t.strm.avail_in)},deflate_stored=(t,e)=>{let r=65535;for(r>t.pending_buf_size-5&&(r=t.pending_buf_size-5);;){if(t.lookahead<=1){if(fill_window(t),0===t.lookahead&&e===Z_NO_FLUSH)return BS_NEED_MORE;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const i=t.block_start+r;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,flush_block_only(t,!1),0===t.strm.avail_out))return BS_NEED_MORE;if(t.strstart-t.block_start>=t.w_size-MIN_LOOKAHEAD&&(flush_block_only(t,!1),0===t.strm.avail_out))return BS_NEED_MORE}return t.insert=0,e===Z_FINISH?(flush_block_only(t,!0),0===t.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):(t.strstart>t.block_start&&(flush_block_only(t,!1),t.strm.avail_out),BS_NEED_MORE)},deflate_fast=(t,e)=>{let r,i;for(;;){if(t.lookahead<MIN_LOOKAHEAD){if(fill_window(t),t.lookahead<MIN_LOOKAHEAD&&e===Z_NO_FLUSH)return BS_NEED_MORE;if(0===t.lookahead)break}if(r=0,t.lookahead>=MIN_MATCH$1&&(t.ins_h=HASH(t,t.ins_h,t.window[t.strstart+MIN_MATCH$1-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==r&&t.strstart-r<=t.w_size-MIN_LOOKAHEAD&&(t.match_length=longest_match(t,r)),t.match_length>=MIN_MATCH$1)if(i=_tr_tally$1(t,t.strstart-t.match_start,t.match_length-MIN_MATCH$1),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=MIN_MATCH$1){t.match_length--;do{t.strstart++,t.ins_h=HASH(t,t.ins_h,t.window[t.strstart+MIN_MATCH$1-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=HASH(t,t.ins_h,t.window[t.strstart+1]);else i=_tr_tally$1(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(flush_block_only(t,!1),0===t.strm.avail_out))return BS_NEED_MORE}return t.insert=t.strstart<MIN_MATCH$1-1?t.strstart:MIN_MATCH$1-1,e===Z_FINISH?(flush_block_only(t,!0),0===t.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):t.last_lit&&(flush_block_only(t,!1),0===t.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE},deflate_slow=(t,e)=>{let r,i,n;for(;;){if(t.lookahead<MIN_LOOKAHEAD){if(fill_window(t),t.lookahead<MIN_LOOKAHEAD&&e===Z_NO_FLUSH)return BS_NEED_MORE;if(0===t.lookahead)break}if(r=0,t.lookahead>=MIN_MATCH$1&&(t.ins_h=HASH(t,t.ins_h,t.window[t.strstart+MIN_MATCH$1-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=MIN_MATCH$1-1,0!==r&&t.prev_length<t.max_lazy_match&&t.strstart-r<=t.w_size-MIN_LOOKAHEAD&&(t.match_length=longest_match(t,r),t.match_length<=5&&(t.strategy===Z_FILTERED||t.match_length===MIN_MATCH$1&&t.strstart-t.match_start>4096)&&(t.match_length=MIN_MATCH$1-1)),t.prev_length>=MIN_MATCH$1&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-MIN_MATCH$1,i=_tr_tally$1(t,t.strstart-1-t.prev_match,t.prev_length-MIN_MATCH$1),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=n&&(t.ins_h=HASH(t,t.ins_h,t.window[t.strstart+MIN_MATCH$1-1]),r=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=MIN_MATCH$1-1,t.strstart++,i&&(flush_block_only(t,!1),0===t.strm.avail_out))return BS_NEED_MORE}else if(t.match_available){if(i=_tr_tally$1(t,0,t.window[t.strstart-1]),i&&flush_block_only(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return BS_NEED_MORE}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=_tr_tally$1(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<MIN_MATCH$1-1?t.strstart:MIN_MATCH$1-1,e===Z_FINISH?(flush_block_only(t,!0),0===t.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):t.last_lit&&(flush_block_only(t,!1),0===t.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE},deflate_rle=(t,e)=>{let r,i,n,s;const a=t.window;for(;;){if(t.lookahead<=MAX_MATCH$1){if(fill_window(t),t.lookahead<=MAX_MATCH$1&&e===Z_NO_FLUSH)return BS_NEED_MORE;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=MIN_MATCH$1&&t.strstart>0&&(n=t.strstart-1,i=a[n],i===a[++n]&&i===a[++n]&&i===a[++n])){s=t.strstart+MAX_MATCH$1;do{}while(i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&i===a[++n]&&n<s);t.match_length=MAX_MATCH$1-(s-n),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=MIN_MATCH$1?(r=_tr_tally$1(t,1,t.match_length-MIN_MATCH$1),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(r=_tr_tally$1(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),r&&(flush_block_only(t,!1),0===t.strm.avail_out))return BS_NEED_MORE}return t.insert=0,e===Z_FINISH?(flush_block_only(t,!0),0===t.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):t.last_lit&&(flush_block_only(t,!1),0===t.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE},deflate_huff=(t,e)=>{let r;for(;;){if(0===t.lookahead&&(fill_window(t),0===t.lookahead)){if(e===Z_NO_FLUSH)return BS_NEED_MORE;break}if(t.match_length=0,r=_tr_tally$1(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,r&&(flush_block_only(t,!1),0===t.strm.avail_out))return BS_NEED_MORE}return t.insert=0,e===Z_FINISH?(flush_block_only(t,!0),0===t.strm.avail_out?BS_FINISH_STARTED:BS_FINISH_DONE):t.last_lit&&(flush_block_only(t,!1),0===t.strm.avail_out)?BS_NEED_MORE:BS_BLOCK_DONE};function Config(t,e,r,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=r,this.max_chain=i,this.func=n}const configuration_table=[new Config(0,0,0,0,deflate_stored),new Config(4,4,8,4,deflate_fast),new Config(4,5,16,8,deflate_fast),new Config(4,6,32,32,deflate_fast),new Config(4,4,16,16,deflate_slow),new Config(8,16,32,32,deflate_slow),new Config(8,16,128,128,deflate_slow),new Config(8,32,128,256,deflate_slow),new Config(32,128,258,1024,deflate_slow),new Config(32,258,258,4096,deflate_slow)],lm_init=t=>{t.window_size=2*t.w_size,zero$1(t.head),t.max_lazy_match=configuration_table[t.level].max_lazy,t.good_match=configuration_table[t.level].good_length,t.nice_match=configuration_table[t.level].nice_length,t.max_chain_length=configuration_table[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=MIN_MATCH$1-1,t.match_available=0,t.ins_h=0};function DeflateState(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Z_DEFLATED,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(2*HEAP_SIZE$1),this.dyn_dtree=new Uint16Array(2*(2*D_CODES$1+1)),this.bl_tree=new Uint16Array(2*(2*BL_CODES$1+1)),zero$1(this.dyn_ltree),zero$1(this.dyn_dtree),zero$1(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(MAX_BITS$1+1),this.heap=new Uint16Array(2*L_CODES$1+1),zero$1(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*L_CODES$1+1),zero$1(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const deflateResetKeep=t=>{if(!t||!t.state)return err(t,Z_STREAM_ERROR);t.total_in=t.total_out=0,t.data_type=Z_UNKNOWN$1;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?INIT_STATE:BUSY_STATE,t.adler=2===e.wrap?0:1,e.last_flush=Z_NO_FLUSH,_tr_init$1(e),Z_OK},deflateReset=t=>{const e=deflateResetKeep(t);return e===Z_OK&&lm_init(t.state),e},deflateSetHeader=(t,e)=>t&&t.state?2!==t.state.wrap?Z_STREAM_ERROR:(t.state.gzhead=e,Z_OK):Z_STREAM_ERROR,deflateInit2=(t,e,r,i,n,s)=>{if(!t)return Z_STREAM_ERROR;let a=1;if(e===Z_DEFAULT_COMPRESSION&&(e=6),i<0?(a=0,i=-i):i>15&&(a=2,i-=16),n<1||n>MAX_MEM_LEVEL||r!==Z_DEFLATED||i<8||i>15||e<0||e>9||s<0||s>Z_FIXED$1)return err(t,Z_STREAM_ERROR);8===i&&(i=9);const o=new DeflateState;return t.state=o,o.strm=t,o.wrap=a,o.gzhead=null,o.w_bits=i,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=n+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+MIN_MATCH$1-1)/MIN_MATCH$1),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<n+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.d_buf=1*o.lit_bufsize,o.l_buf=3*o.lit_bufsize,o.level=e,o.strategy=s,o.method=r,deflateReset(t)},deflateInit=(t,e)=>deflateInit2(t,e,Z_DEFLATED,MAX_WBITS,DEF_MEM_LEVEL,Z_DEFAULT_STRATEGY),deflate=(t,e)=>{let r,i;if(!t||!t.state||e>Z_BLOCK||e<0)return t?err(t,Z_STREAM_ERROR):Z_STREAM_ERROR;const n=t.state;if(!t.output||!t.input&&0!==t.avail_in||n.status===FINISH_STATE&&e!==Z_FINISH)return err(t,0===t.avail_out?Z_BUF_ERROR:Z_STREAM_ERROR);n.strm=t;const s=n.last_flush;if(n.last_flush=e,n.status===INIT_STATE)if(2===n.wrap)t.adler=0,put_byte(n,31),put_byte(n,139),put_byte(n,8),n.gzhead?(put_byte(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),put_byte(n,255&n.gzhead.time),put_byte(n,n.gzhead.time>>8&255),put_byte(n,n.gzhead.time>>16&255),put_byte(n,n.gzhead.time>>24&255),put_byte(n,9===n.level?2:n.strategy>=Z_HUFFMAN_ONLY||n.level<2?4:0),put_byte(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(put_byte(n,255&n.gzhead.extra.length),put_byte(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(t.adler=crc32_1(t.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=EXTRA_STATE):(put_byte(n,0),put_byte(n,0),put_byte(n,0),put_byte(n,0),put_byte(n,0),put_byte(n,9===n.level?2:n.strategy>=Z_HUFFMAN_ONLY||n.level<2?4:0),put_byte(n,OS_CODE),n.status=BUSY_STATE);else{let e=Z_DEFLATED+(n.w_bits-8<<4)<<8,r=-1;r=n.strategy>=Z_HUFFMAN_ONLY||n.level<2?0:n.level<6?1:6===n.level?2:3,e|=r<<6,0!==n.strstart&&(e|=PRESET_DICT),e+=31-e%31,n.status=BUSY_STATE,putShortMSB(n,e),0!==n.strstart&&(putShortMSB(n,t.adler>>>16),putShortMSB(n,65535&t.adler)),t.adler=1}if(n.status===EXTRA_STATE)if(n.gzhead.extra){for(r=n.pending;n.gzindex<(65535&n.gzhead.extra.length)&&(n.pending!==n.pending_buf_size||(n.gzhead.hcrc&&n.pending>r&&(t.adler=crc32_1(t.adler,n.pending_buf,n.pending-r,r)),flush_pending(t),r=n.pending,n.pending!==n.pending_buf_size));)put_byte(n,255&n.gzhead.extra[n.gzindex]),n.gzindex++;n.gzhead.hcrc&&n.pending>r&&(t.adler=crc32_1(t.adler,n.pending_buf,n.pending-r,r)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=NAME_STATE)}else n.status=NAME_STATE;if(n.status===NAME_STATE)if(n.gzhead.name){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=crc32_1(t.adler,n.pending_buf,n.pending-r,r)),flush_pending(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindex<n.gzhead.name.length?255&n.gzhead.name.charCodeAt(n.gzindex++):0,put_byte(n,i)}while(0!==i);n.gzhead.hcrc&&n.pending>r&&(t.adler=crc32_1(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.gzindex=0,n.status=COMMENT_STATE)}else n.status=COMMENT_STATE;if(n.status===COMMENT_STATE)if(n.gzhead.comment){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(t.adler=crc32_1(t.adler,n.pending_buf,n.pending-r,r)),flush_pending(t),r=n.pending,n.pending===n.pending_buf_size)){i=1;break}i=n.gzindex<n.gzhead.comment.length?255&n.gzhead.comment.charCodeAt(n.gzindex++):0,put_byte(n,i)}while(0!==i);n.gzhead.hcrc&&n.pending>r&&(t.adler=crc32_1(t.adler,n.pending_buf,n.pending-r,r)),0===i&&(n.status=HCRC_STATE)}else n.status=HCRC_STATE;if(n.status===HCRC_STATE&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&flush_pending(t),n.pending+2<=n.pending_buf_size&&(put_byte(n,255&t.adler),put_byte(n,t.adler>>8&255),t.adler=0,n.status=BUSY_STATE)):n.status=BUSY_STATE),0!==n.pending){if(flush_pending(t),0===t.avail_out)return n.last_flush=-1,Z_OK}else if(0===t.avail_in&&rank(e)<=rank(s)&&e!==Z_FINISH)return err(t,Z_BUF_ERROR);if(n.status===FINISH_STATE&&0!==t.avail_in)return err(t,Z_BUF_ERROR);if(0!==t.avail_in||0!==n.lookahead||e!==Z_NO_FLUSH&&n.status!==FINISH_STATE){let r=n.strategy===Z_HUFFMAN_ONLY?deflate_huff(n,e):n.strategy===Z_RLE?deflate_rle(n,e):configuration_table[n.level].func(n,e);if(r!==BS_FINISH_STARTED&&r!==BS_FINISH_DONE||(n.status=FINISH_STATE),r===BS_NEED_MORE||r===BS_FINISH_STARTED)return 0===t.avail_out&&(n.last_flush=-1),Z_OK;if(r===BS_BLOCK_DONE&&(e===Z_PARTIAL_FLUSH?_tr_align$1(n):e!==Z_BLOCK&&(_tr_stored_block$1(n,0,0,!1),e===Z_FULL_FLUSH&&(zero$1(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),flush_pending(t),0===t.avail_out))return n.last_flush=-1,Z_OK}return e!==Z_FINISH?Z_OK:n.wrap<=0?Z_STREAM_END:(2===n.wrap?(put_byte(n,255&t.adler),put_byte(n,t.adler>>8&255),put_byte(n,t.adler>>16&255),put_byte(n,t.adler>>24&255),put_byte(n,255&t.total_in),put_byte(n,t.total_in>>8&255),put_byte(n,t.total_in>>16&255),put_byte(n,t.total_in>>24&255)):(putShortMSB(n,t.adler>>>16),putShortMSB(n,65535&t.adler)),flush_pending(t),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?Z_OK:Z_STREAM_END)},deflateEnd=t=>{if(!t||!t.state)return Z_STREAM_ERROR;const e=t.state.status;return e!==INIT_STATE&&e!==EXTRA_STATE&&e!==NAME_STATE&&e!==COMMENT_STATE&&e!==HCRC_STATE&&e!==BUSY_STATE&&e!==FINISH_STATE?err(t,Z_STREAM_ERROR):(t.state=null,e===BUSY_STATE?err(t,Z_DATA_ERROR):Z_OK)},deflateSetDictionary=(t,e)=>{let r=e.length;if(!t||!t.state)return Z_STREAM_ERROR;const i=t.state,n=i.wrap;if(2===n||1===n&&i.status!==INIT_STATE||i.lookahead)return Z_STREAM_ERROR;if(1===n&&(t.adler=adler32_1(t.adler,e,r,0)),i.wrap=0,r>=i.w_size){0===n&&(zero$1(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(r-i.w_size,r),0),e=t,r=i.w_size}const s=t.avail_in,a=t.next_in,o=t.input;for(t.avail_in=r,t.next_in=0,t.input=e,fill_window(i);i.lookahead>=MIN_MATCH$1;){let t=i.strstart,e=i.lookahead-(MIN_MATCH$1-1);do{i.ins_h=HASH(i,i.ins_h,i.window[t+MIN_MATCH$1-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=MIN_MATCH$1-1,fill_window(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=MIN_MATCH$1-1,i.match_available=0,t.next_in=a,t.input=o,t.avail_in=s,i.wrap=n,Z_OK};var deflateInit_1=deflateInit,deflateInit2_1=deflateInit2,deflateReset_1=deflateReset,deflateResetKeep_1=deflateResetKeep,deflateSetHeader_1=deflateSetHeader,deflate_2=deflate,deflateEnd_1=deflateEnd,deflateSetDictionary_1=deflateSetDictionary,deflateInfo="pako deflate (from Nodeca project)",deflate_1={deflateInit:deflateInit_1,deflateInit2:deflateInit2_1,deflateReset:deflateReset_1,deflateResetKeep:deflateResetKeep_1,deflateSetHeader:deflateSetHeader_1,deflate:deflate_2,deflateEnd:deflateEnd_1,deflateSetDictionary:deflateSetDictionary_1,deflateInfo:deflateInfo};const _has=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var assign=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const r=e.shift();if(r){if("object"!=typeof r)throw new TypeError(r+"must be non-object");for(const e in r)_has(r,e)&&(t[e]=r[e])}}return t},flattenChunks=t=>{let e=0;for(let r=0,i=t.length;r<i;r++)e+=t[r].length;const r=new Uint8Array(e);for(let e=0,i=0,n=t.length;e<n;e++){let n=t[e];r.set(n,i),i+=n.length}return r},common={assign:assign,flattenChunks:flattenChunks};let STR_APPLY_UIA_OK=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){STR_APPLY_UIA_OK=!1}const _utf8len=new Uint8Array(256);for(let t=0;t<256;t++)_utf8len[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;_utf8len[254]=_utf8len[254]=1;var string2buf=t=>{let e,r,i,n,s,a=t.length,o=0;for(n=0;n<a;n++)r=t.charCodeAt(n),55296==(64512&r)&&n+1<a&&(i=t.charCodeAt(n+1),56320==(64512&i)&&(r=65536+(r-55296<<10)+(i-56320),n++)),o+=r<128?1:r<2048?2:r<65536?3:4;for(e=new Uint8Array(o),s=0,n=0;s<o;n++)r=t.charCodeAt(n),55296==(64512&r)&&n+1<a&&(i=t.charCodeAt(n+1),56320==(64512&i)&&(r=65536+(r-55296<<10)+(i-56320),n++)),r<128?e[s++]=r:r<2048?(e[s++]=192|r>>>6,e[s++]=128|63&r):r<65536?(e[s++]=224|r>>>12,e[s++]=128|r>>>6&63,e[s++]=128|63&r):(e[s++]=240|r>>>18,e[s++]=128|r>>>12&63,e[s++]=128|r>>>6&63,e[s++]=128|63&r);return e};const buf2binstring=(t,e)=>{if(e<65534&&t.subarray&&STR_APPLY_UIA_OK)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let r="";for(let i=0;i<e;i++)r+=String.fromCharCode(t[i]);return r};var buf2string=(t,e)=>{let r,i;const n=e||t.length,s=new Array(2*n);for(i=0,r=0;r<n;){let e=t[r++];if(e<128){s[i++]=e;continue}let a=_utf8len[e];if(a>4)s[i++]=65533,r+=a-1;else{for(e&=2===a?31:3===a?15:7;a>1&&r<n;)e=e<<6|63&t[r++],a--;a>1?s[i++]=65533:e<65536?s[i++]=e:(e-=65536,s[i++]=55296|e>>10&1023,s[i++]=56320|1023&e)}}return buf2binstring(s,i)},utf8border=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let r=e-1;for(;r>=0&&128==(192&t[r]);)r--;return r<0||0===r?e:r+_utf8len[t[r]]>e?r:e},strings={string2buf:string2buf,buf2string:buf2string,utf8border:utf8border};function ZStream(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var zstream=ZStream;const toString$2=Object.prototype.toString,{Z_NO_FLUSH:Z_NO_FLUSH$1,Z_SYNC_FLUSH:Z_SYNC_FLUSH,Z_FULL_FLUSH:Z_FULL_FLUSH$1,Z_FINISH:Z_FINISH$1,Z_OK:Z_OK$1,Z_STREAM_END:Z_STREAM_END$1,Z_DEFAULT_COMPRESSION:Z_DEFAULT_COMPRESSION$1,Z_DEFAULT_STRATEGY:Z_DEFAULT_STRATEGY$1,Z_DEFLATED:Z_DEFLATED$1}=constants;function Deflate(t){this.options=common.assign({level:Z_DEFAULT_COMPRESSION$1,method:Z_DEFLATED$1,chunkSize:16384,windowBits:15,memLevel:8,strategy:Z_DEFAULT_STRATEGY$1},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;let r=deflate_1.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(r!==Z_OK$1)throw new Error(messages[r]);if(e.header&&deflate_1.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?strings.string2buf(e.dictionary):"[object ArrayBuffer]"===toString$2.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,r=deflate_1.deflateSetDictionary(this.strm,t),r!==Z_OK$1)throw new Error(messages[r]);this._dict_set=!0}}function deflate$1(t,e){const r=new Deflate(e);if(r.push(t,!0),r.err)throw r.msg||messages[r.err];return r.result}function deflateRaw(t,e){return(e=e||{}).raw=!0,deflate$1(t,e)}function gzip(t,e){return(e=e||{}).gzip=!0,deflate$1(t,e)}Deflate.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize;let n,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?Z_FINISH$1:Z_NO_FLUSH$1,"string"==typeof t?r.input=strings.string2buf(t):"[object ArrayBuffer]"===toString$2.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),(s===Z_SYNC_FLUSH||s===Z_FULL_FLUSH$1)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if(n=deflate_1.deflate(r,s),n===Z_STREAM_END$1)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),n=deflate_1.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Z_OK$1;if(0!==r.avail_out){if(s>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},Deflate.prototype.onData=function(t){this.chunks.push(t)},Deflate.prototype.onEnd=function(t){t===Z_OK$1&&(this.result=common.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Deflate_1=Deflate,deflate_2$1=deflate$1,deflateRaw_1=deflateRaw,gzip_1=gzip,constants$1=constants,deflate_1$1={Deflate:Deflate_1,deflate:deflate_2$1,deflateRaw:deflateRaw_1,gzip:gzip_1,constants:constants$1};const BAD=30,TYPE=12;var inffast=function(t,e){let r,i,n,s,a,o,h,l,c,u,f,d,m,g,p,w,_,b,y,M,x,v,E,A;const k=t.state;r=t.next_in,E=t.input,i=r+(t.avail_in-5),n=t.next_out,A=t.output,s=n-(e-t.avail_out),a=n+(t.avail_out-257),o=k.dmax,h=k.wsize,l=k.whave,c=k.wnext,u=k.window,f=k.hold,d=k.bits,m=k.lencode,g=k.distcode,p=(1<<k.lenbits)-1,w=(1<<k.distbits)-1;t:do{d<15&&(f+=E[r++]<<d,d+=8,f+=E[r++]<<d,d+=8),_=m[f&p];e:for(;;){if(b=_>>>24,f>>>=b,d-=b,b=_>>>16&255,0===b)A[n++]=65535&_;else{if(!(16&b)){if(0==(64&b)){_=m[(65535&_)+(f&(1<<b)-1)];continue e}if(32&b){k.mode=TYPE;break t}t.msg="invalid literal/length code",k.mode=BAD;break t}y=65535&_,b&=15,b&&(d<b&&(f+=E[r++]<<d,d+=8),y+=f&(1<<b)-1,f>>>=b,d-=b),d<15&&(f+=E[r++]<<d,d+=8,f+=E[r++]<<d,d+=8),_=g[f&w];r:for(;;){if(b=_>>>24,f>>>=b,d-=b,b=_>>>16&255,!(16&b)){if(0==(64&b)){_=g[(65535&_)+(f&(1<<b)-1)];continue r}t.msg="invalid distance code",k.mode=BAD;break t}if(M=65535&_,b&=15,d<b&&(f+=E[r++]<<d,d+=8,d<b&&(f+=E[r++]<<d,d+=8)),M+=f&(1<<b)-1,M>o){t.msg="invalid distance too far back",k.mode=BAD;break t}if(f>>>=b,d-=b,b=n-s,M>b){if(b=M-b,b>l&&k.sane){t.msg="invalid distance too far back",k.mode=BAD;break t}if(x=0,v=u,0===c){if(x+=h-b,b<y){y-=b;do{A[n++]=u[x++]}while(--b);x=n-M,v=A}}else if(c<b){if(x+=h+c-b,b-=c,b<y){y-=b;do{A[n++]=u[x++]}while(--b);if(x=0,c<y){b=c,y-=b;do{A[n++]=u[x++]}while(--b);x=n-M,v=A}}}else if(x+=c-b,b<y){y-=b;do{A[n++]=u[x++]}while(--b);x=n-M,v=A}for(;y>2;)A[n++]=v[x++],A[n++]=v[x++],A[n++]=v[x++],y-=3;y&&(A[n++]=v[x++],y>1&&(A[n++]=v[x++]))}else{x=n-M;do{A[n++]=A[x++],A[n++]=A[x++],A[n++]=A[x++],y-=3}while(y>2);y&&(A[n++]=A[x++],y>1&&(A[n++]=A[x++]))}break}}break}}while(r<i&&n<a);y=d>>3,r-=y,d-=y<<3,f&=(1<<d)-1,t.next_in=r,t.next_out=n,t.avail_in=r<i?i-r+5:5-(r-i),t.avail_out=n<a?a-n+257:257-(n-a),k.hold=f,k.bits=d};const MAXBITS=15,ENOUGH_LENS=852,ENOUGH_DISTS=592,CODES=0,LENS=1,DISTS=2,lbase=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),lext=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),dbase=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),dext=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),inflate_table=(t,e,r,i,n,s,a,o)=>{const h=o.bits;let l,c,u,f,d,m,g=0,p=0,w=0,_=0,b=0,y=0,M=0,x=0,v=0,E=0,A=null,k=0;const S=new Uint16Array(MAXBITS+1),I=new Uint16Array(MAXBITS+1);let D,R,T,C=null,$=0;for(g=0;g<=MAXBITS;g++)S[g]=0;for(p=0;p<i;p++)S[e[r+p]]++;for(b=h,_=MAXBITS;_>=1&&0===S[_];_--);if(b>_&&(b=_),0===_)return n[s++]=20971520,n[s++]=20971520,o.bits=1,0;for(w=1;w<_&&0===S[w];w++);for(b<w&&(b=w),x=1,g=1;g<=MAXBITS;g++)if(x<<=1,x-=S[g],x<0)return-1;if(x>0&&(t===CODES||1!==_))return-1;for(I[1]=0,g=1;g<MAXBITS;g++)I[g+1]=I[g]+S[g];for(p=0;p<i;p++)0!==e[r+p]&&(a[I[e[r+p]]++]=p);if(t===CODES?(A=C=a,m=19):t===LENS?(A=lbase,k-=257,C=lext,$-=257,m=256):(A=dbase,C=dext,m=-1),E=0,p=0,g=w,d=s,y=b,M=0,u=-1,v=1<<b,f=v-1,t===LENS&&v>ENOUGH_LENS||t===DISTS&&v>ENOUGH_DISTS)return 1;for(;;){D=g-M,a[p]<m?(R=0,T=a[p]):a[p]>m?(R=C[$+a[p]],T=A[k+a[p]]):(R=96,T=0),l=1<<g-M,c=1<<y,w=c;do{c-=l,n[d+(E>>M)+c]=D<<24|R<<16|T|0}while(0!==c);for(l=1<<g-1;E&l;)l>>=1;if(0!==l?(E&=l-1,E+=l):E=0,p++,0==--S[g]){if(g===_)break;g=e[r+a[p]]}if(g>b&&(E&f)!==u){for(0===M&&(M=b),d+=w,y=g-M,x=1<<y;y+M<_&&(x-=S[y+M],!(x<=0));)y++,x<<=1;if(v+=1<<y,t===LENS&&v>ENOUGH_LENS||t===DISTS&&v>ENOUGH_DISTS)return 1;u=E&f,n[u]=b<<24|y<<16|d-s|0}}return 0!==E&&(n[d+E]=g-M<<24|64<<16|0),o.bits=b,0};var inftrees=inflate_table;const CODES$1=0,LENS$1=1,DISTS$1=2,{Z_FINISH:Z_FINISH$2,Z_BLOCK:Z_BLOCK$1,Z_TREES:Z_TREES,Z_OK:Z_OK$2,Z_STREAM_END:Z_STREAM_END$2,Z_NEED_DICT:Z_NEED_DICT,Z_STREAM_ERROR:Z_STREAM_ERROR$1,Z_DATA_ERROR:Z_DATA_ERROR$1,Z_MEM_ERROR:Z_MEM_ERROR,Z_BUF_ERROR:Z_BUF_ERROR$1,Z_DEFLATED:Z_DEFLATED$2}=constants,HEAD=1,FLAGS=2,TIME=3,OS=4,EXLEN=5,EXTRA=6,NAME=7,COMMENT=8,HCRC=9,DICTID=10,DICT=11,TYPE$1=12,TYPEDO=13,STORED=14,COPY_=15,COPY=16,TABLE=17,LENLENS=18,CODELENS=19,LEN_=20,LEN=21,LENEXT=22,DIST=23,DISTEXT=24,MATCH=25,LIT=26,CHECK=27,LENGTH=28,DONE=29,BAD$1=30,MEM=31,SYNC=32,ENOUGH_LENS$1=852,ENOUGH_DISTS$1=592,MAX_WBITS$1=15,DEF_WBITS=MAX_WBITS$1,zswap32=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function InflateState(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const inflateResetKeep=t=>{if(!t||!t.state)return Z_STREAM_ERROR$1;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=HEAD,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(ENOUGH_LENS$1),e.distcode=e.distdyn=new Int32Array(ENOUGH_DISTS$1),e.sane=1,e.back=-1,Z_OK$2},inflateReset=t=>{if(!t||!t.state)return Z_STREAM_ERROR$1;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,inflateResetKeep(t)},inflateReset2=(t,e)=>{let r;if(!t||!t.state)return Z_STREAM_ERROR$1;const i=t.state;return e<0?(r=0,e=-e):(r=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?Z_STREAM_ERROR$1:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=r,i.wbits=e,inflateReset(t))},inflateInit2=(t,e)=>{if(!t)return Z_STREAM_ERROR$1;const r=new InflateState;t.state=r,r.window=null;const i=inflateReset2(t,e);return i!==Z_OK$2&&(t.state=null),i},inflateInit=t=>inflateInit2(t,DEF_WBITS);let virgin=!0,lenfix,distfix;const fixedtables=t=>{if(virgin){lenfix=new Int32Array(512),distfix=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(inftrees(LENS$1,t.lens,0,288,lenfix,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;inftrees(DISTS$1,t.lens,0,32,distfix,0,t.work,{bits:5}),virgin=!1}t.lencode=lenfix,t.lenbits=9,t.distcode=distfix,t.distbits=5},updatewindow=(t,e,r,i)=>{let n;const s=t.state;return null===s.window&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),i>=s.wsize?(s.window.set(e.subarray(r-s.wsize,r),0),s.wnext=0,s.whave=s.wsize):(n=s.wsize-s.wnext,n>i&&(n=i),s.window.set(e.subarray(r-i,r-i+n),s.wnext),(i-=n)?(s.window.set(e.subarray(r-i,r),0),s.wnext=i,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=n))),0},inflate=(t,e)=>{let r,i,n,s,a,o,h,l,c,u,f,d,m,g,p,w,_,b,y,M,x,v,E=0;const A=new Uint8Array(4);let k,S;const I=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return Z_STREAM_ERROR$1;r=t.state,r.mode===TYPE$1&&(r.mode=TYPEDO),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,u=o,f=h,v=Z_OK$2;t:for(;;)switch(r.mode){case HEAD:if(0===r.wrap){r.mode=TYPEDO;break}for(;c<16;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(2&r.wrap&&35615===l){r.check=0,A[0]=255&l,A[1]=l>>>8&255,r.check=crc32_1(r.check,A,2,0),l=0,c=0,r.mode=FLAGS;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",r.mode=BAD$1;break}if((15&l)!==Z_DEFLATED$2){t.msg="unknown compression method",r.mode=BAD$1;break}if(l>>>=4,c-=4,x=8+(15&l),0===r.wbits)r.wbits=x;else if(x>r.wbits){t.msg="invalid window size",r.mode=BAD$1;break}r.dmax=1<<r.wbits,t.adler=r.check=1,r.mode=512&l?DICTID:TYPE$1,l=0,c=0;break;case FLAGS:for(;c<16;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(r.flags=l,(255&r.flags)!==Z_DEFLATED$2){t.msg="unknown compression method",r.mode=BAD$1;break}if(57344&r.flags){t.msg="unknown header flags set",r.mode=BAD$1;break}r.head&&(r.head.text=l>>8&1),512&r.flags&&(A[0]=255&l,A[1]=l>>>8&255,r.check=crc32_1(r.check,A,2,0)),l=0,c=0,r.mode=TIME;case TIME:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}r.head&&(r.head.time=l),512&r.flags&&(A[0]=255&l,A[1]=l>>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,r.check=crc32_1(r.check,A,4,0)),l=0,c=0,r.mode=OS;case OS:for(;c<16;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}r.head&&(r.head.xflags=255&l,r.head.os=l>>8),512&r.flags&&(A[0]=255&l,A[1]=l>>>8&255,r.check=crc32_1(r.check,A,2,0)),l=0,c=0,r.mode=EXLEN;case EXLEN:if(1024&r.flags){for(;c<16;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}r.length=l,r.head&&(r.head.extra_len=l),512&r.flags&&(A[0]=255&l,A[1]=l>>>8&255,r.check=crc32_1(r.check,A,2,0)),l=0,c=0}else r.head&&(r.head.extra=null);r.mode=EXTRA;case EXTRA:if(1024&r.flags&&(d=r.length,d>o&&(d=o),d&&(r.head&&(x=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(i.subarray(s,s+d),x)),512&r.flags&&(r.check=crc32_1(r.check,i,d,s)),o-=d,s+=d,r.length-=d),r.length))break t;r.length=0,r.mode=NAME;case NAME:if(2048&r.flags){if(0===o)break t;d=0;do{x=i[s+d++],r.head&&x&&r.length<65536&&(r.head.name+=String.fromCharCode(x))}while(x&&d<o);if(512&r.flags&&(r.check=crc32_1(r.check,i,d,s)),o-=d,s+=d,x)break t}else r.head&&(r.head.name=null);r.length=0,r.mode=COMMENT;case COMMENT:if(4096&r.flags){if(0===o)break t;d=0;do{x=i[s+d++],r.head&&x&&r.length<65536&&(r.head.comment+=String.fromCharCode(x))}while(x&&d<o);if(512&r.flags&&(r.check=crc32_1(r.check,i,d,s)),o-=d,s+=d,x)break t}else r.head&&(r.head.comment=null);r.mode=HCRC;case HCRC:if(512&r.flags){for(;c<16;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(l!==(65535&r.check)){t.msg="header crc mismatch",r.mode=BAD$1;break}l=0,c=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),t.adler=r.check=0,r.mode=TYPE$1;break;case DICTID:for(;c<32;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}t.adler=r.check=zswap32(l),l=0,c=0,r.mode=DICT;case DICT:if(0===r.havedict)return t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,r.hold=l,r.bits=c,Z_NEED_DICT;t.adler=r.check=1,r.mode=TYPE$1;case TYPE$1:if(e===Z_BLOCK$1||e===Z_TREES)break t;case TYPEDO:if(r.last){l>>>=7&c,c-=7&c,r.mode=CHECK;break}for(;c<3;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}switch(r.last=1&l,l>>>=1,c-=1,3&l){case 0:r.mode=STORED;break;case 1:if(fixedtables(r),r.mode=LEN_,e===Z_TREES){l>>>=2,c-=2;break t}break;case 2:r.mode=TABLE;break;case 3:t.msg="invalid block type",r.mode=BAD$1}l>>>=2,c-=2;break;case STORED:for(l>>>=7&c,c-=7&c;c<32;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if((65535&l)!=(l>>>16^65535)){t.msg="invalid stored block lengths",r.mode=BAD$1;break}if(r.length=65535&l,l=0,c=0,r.mode=COPY_,e===Z_TREES)break t;case COPY_:r.mode=COPY;case COPY:if(d=r.length,d){if(d>o&&(d=o),d>h&&(d=h),0===d)break t;n.set(i.subarray(s,s+d),a),o-=d,s+=d,h-=d,a+=d,r.length-=d;break}r.mode=TYPE$1;break;case TABLE:for(;c<14;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(r.nlen=257+(31&l),l>>>=5,c-=5,r.ndist=1+(31&l),l>>>=5,c-=5,r.ncode=4+(15&l),l>>>=4,c-=4,r.nlen>286||r.ndist>30){t.msg="too many length or distance symbols",r.mode=BAD$1;break}r.have=0,r.mode=LENLENS;case LENLENS:for(;r.have<r.ncode;){for(;c<3;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}r.lens[I[r.have++]]=7&l,l>>>=3,c-=3}for(;r.have<19;)r.lens[I[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,k={bits:r.lenbits},v=inftrees(CODES$1,r.lens,0,19,r.lencode,0,r.work,k),r.lenbits=k.bits,v){t.msg="invalid code lengths set",r.mode=BAD$1;break}r.have=0,r.mode=CODELENS;case CODELENS:for(;r.have<r.nlen+r.ndist;){for(;E=r.lencode[l&(1<<r.lenbits)-1],p=E>>>24,w=E>>>16&255,_=65535&E,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(_<16)l>>>=p,c-=p,r.lens[r.have++]=_;else{if(16===_){for(S=p+2;c<S;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(l>>>=p,c-=p,0===r.have){t.msg="invalid bit length repeat",r.mode=BAD$1;break}x=r.lens[r.have-1],d=3+(3&l),l>>>=2,c-=2}else if(17===_){for(S=p+3;c<S;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}l>>>=p,c-=p,x=0,d=3+(7&l),l>>>=3,c-=3}else{for(S=p+7;c<S;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}l>>>=p,c-=p,x=0,d=11+(127&l),l>>>=7,c-=7}if(r.have+d>r.nlen+r.ndist){t.msg="invalid bit length repeat",r.mode=BAD$1;break}for(;d--;)r.lens[r.have++]=x}}if(r.mode===BAD$1)break;if(0===r.lens[256]){t.msg="invalid code -- missing end-of-block",r.mode=BAD$1;break}if(r.lenbits=9,k={bits:r.lenbits},v=inftrees(LENS$1,r.lens,0,r.nlen,r.lencode,0,r.work,k),r.lenbits=k.bits,v){t.msg="invalid literal/lengths set",r.mode=BAD$1;break}if(r.distbits=6,r.distcode=r.distdyn,k={bits:r.distbits},v=inftrees(DISTS$1,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,k),r.distbits=k.bits,v){t.msg="invalid distances set",r.mode=BAD$1;break}if(r.mode=LEN_,e===Z_TREES)break t;case LEN_:r.mode=LEN;case LEN:if(o>=6&&h>=258){t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,r.hold=l,r.bits=c,inffast(t,f),a=t.next_out,n=t.output,h=t.avail_out,s=t.next_in,i=t.input,o=t.avail_in,l=r.hold,c=r.bits,r.mode===TYPE$1&&(r.back=-1);break}for(r.back=0;E=r.lencode[l&(1<<r.lenbits)-1],p=E>>>24,w=E>>>16&255,_=65535&E,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(w&&0==(240&w)){for(b=p,y=w,M=_;E=r.lencode[M+((l&(1<<b+y)-1)>>b)],p=E>>>24,w=E>>>16&255,_=65535&E,!(b+p<=c);){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}l>>>=b,c-=b,r.back+=b}if(l>>>=p,c-=p,r.back+=p,r.length=_,0===w){r.mode=LIT;break}if(32&w){r.back=-1,r.mode=TYPE$1;break}if(64&w){t.msg="invalid literal/length code",r.mode=BAD$1;break}r.extra=15&w,r.mode=LENEXT;case LENEXT:if(r.extra){for(S=r.extra;c<S;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}r.length+=l&(1<<r.extra)-1,l>>>=r.extra,c-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=DIST;case DIST:for(;E=r.distcode[l&(1<<r.distbits)-1],p=E>>>24,w=E>>>16&255,_=65535&E,!(p<=c);){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(0==(240&w)){for(b=p,y=w,M=_;E=r.distcode[M+((l&(1<<b+y)-1)>>b)],p=E>>>24,w=E>>>16&255,_=65535&E,!(b+p<=c);){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}l>>>=b,c-=b,r.back+=b}if(l>>>=p,c-=p,r.back+=p,64&w){t.msg="invalid distance code",r.mode=BAD$1;break}r.offset=_,r.extra=15&w,r.mode=DISTEXT;case DISTEXT:if(r.extra){for(S=r.extra;c<S;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}r.offset+=l&(1<<r.extra)-1,l>>>=r.extra,c-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){t.msg="invalid distance too far back",r.mode=BAD$1;break}r.mode=MATCH;case MATCH:if(0===h)break t;if(d=f-h,r.offset>d){if(d=r.offset-d,d>r.whave&&r.sane){t.msg="invalid distance too far back",r.mode=BAD$1;break}d>r.wnext?(d-=r.wnext,m=r.wsize-d):m=r.wnext-d,d>r.length&&(d=r.length),g=r.window}else g=n,m=a-r.offset,d=r.length;d>h&&(d=h),h-=d,r.length-=d;do{n[a++]=g[m++]}while(--d);0===r.length&&(r.mode=LEN);break;case LIT:if(0===h)break t;n[a++]=r.length,h--,r.mode=LEN;break;case CHECK:if(r.wrap){for(;c<32;){if(0===o)break t;o--,l|=i[s++]<<c,c+=8}if(f-=h,t.total_out+=f,r.total+=f,f&&(t.adler=r.check=r.flags?crc32_1(r.check,n,f,a-f):adler32_1(r.check,n,f,a-f)),f=h,(r.flags?l:zswap32(l))!==r.check){t.msg="incorrect data check",r.mode=BAD$1;break}l=0,c=0}r.mode=LENGTH;case LENGTH:if(r.wrap&&r.flags){for(;c<32;){if(0===o)break t;o--,l+=i[s++]<<c,c+=8}if(l!==(4294967295&r.total)){t.msg="incorrect length check",r.mode=BAD$1;break}l=0,c=0}r.mode=DONE;case DONE:v=Z_STREAM_END$2;break t;case BAD$1:v=Z_DATA_ERROR$1;break t;case MEM:return Z_MEM_ERROR;case SYNC:default:return Z_STREAM_ERROR$1}return t.next_out=a,t.avail_out=h,t.next_in=s,t.avail_in=o,r.hold=l,r.bits=c,(r.wsize||f!==t.avail_out&&r.mode<BAD$1&&(r.mode<CHECK||e!==Z_FINISH$2))&&updatewindow(t,t.output,t.next_out,f-t.avail_out),u-=t.avail_in,f-=t.avail_out,t.total_in+=u,t.total_out+=f,r.total+=f,r.wrap&&f&&(t.adler=r.check=r.flags?crc32_1(r.check,n,f,t.next_out-f):adler32_1(r.check,n,f,t.next_out-f)),t.data_type=r.bits+(r.last?64:0)+(r.mode===TYPE$1?128:0)+(r.mode===LEN_||r.mode===COPY_?256:0),(0===u&&0===f||e===Z_FINISH$2)&&v===Z_OK$2&&(v=Z_BUF_ERROR$1),v},inflateEnd=t=>{if(!t||!t.state)return Z_STREAM_ERROR$1;let e=t.state;return e.window&&(e.window=null),t.state=null,Z_OK$2},inflateGetHeader=(t,e)=>{if(!t||!t.state)return Z_STREAM_ERROR$1;const r=t.state;return 0==(2&r.wrap)?Z_STREAM_ERROR$1:(r.head=e,e.done=!1,Z_OK$2)},inflateSetDictionary=(t,e)=>{const r=e.length;let i,n,s;return t&&t.state?(i=t.state,0!==i.wrap&&i.mode!==DICT?Z_STREAM_ERROR$1:i.mode===DICT&&(n=1,n=adler32_1(n,e,r,0),n!==i.check)?Z_DATA_ERROR$1:(s=updatewindow(t,e,r,r),s?(i.mode=MEM,Z_MEM_ERROR):(i.havedict=1,Z_OK$2))):Z_STREAM_ERROR$1};var inflateReset_1=inflateReset,inflateReset2_1=inflateReset2,inflateResetKeep_1=inflateResetKeep,inflateInit_1=inflateInit,inflateInit2_1=inflateInit2,inflate_2=inflate,inflateEnd_1=inflateEnd,inflateGetHeader_1=inflateGetHeader,inflateSetDictionary_1=inflateSetDictionary,inflateInfo="pako inflate (from Nodeca project)",inflate_1={inflateReset:inflateReset_1,inflateReset2:inflateReset2_1,inflateResetKeep:inflateResetKeep_1,inflateInit:inflateInit_1,inflateInit2:inflateInit2_1,inflate:inflate_2,inflateEnd:inflateEnd_1,inflateGetHeader:inflateGetHeader_1,inflateSetDictionary:inflateSetDictionary_1,inflateInfo:inflateInfo};function GZheader(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var gzheader=GZheader;const toString$1$1=Object.prototype.toString,{Z_NO_FLUSH:Z_NO_FLUSH$2,Z_FINISH:Z_FINISH$3,Z_OK:Z_OK$3,Z_STREAM_END:Z_STREAM_END$3,Z_NEED_DICT:Z_NEED_DICT$1,Z_STREAM_ERROR:Z_STREAM_ERROR$2,Z_DATA_ERROR:Z_DATA_ERROR$2,Z_MEM_ERROR:Z_MEM_ERROR$1}=constants;function Inflate(t){this.options=common.assign({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zstream,this.strm.avail_out=0;let r=inflate_1.inflateInit2(this.strm,e.windowBits);if(r!==Z_OK$3)throw new Error(messages[r]);if(this.header=new gzheader,inflate_1.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=strings.string2buf(e.dictionary):"[object ArrayBuffer]"===toString$1$1.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(r=inflate_1.inflateSetDictionary(this.strm,e.dictionary),r!==Z_OK$3)))throw new Error(messages[r])}function inflate$1(t,e){const r=new Inflate(e);if(r.push(t),r.err)throw r.msg||messages[r.err];return r.result}function inflateRaw(t,e){return(e=e||{}).raw=!0,inflate$1(t,e)}Inflate.prototype.push=function(t,e){const r=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let s,a,o;if(this.ended)return!1;for(a=e===~~e?e:!0===e?Z_FINISH$3:Z_NO_FLUSH$2,"[object ArrayBuffer]"===toString$1$1.call(t)?r.input=new Uint8Array(t):r.input=t,r.next_in=0,r.avail_in=r.input.length;;){for(0===r.avail_out&&(r.output=new Uint8Array(i),r.next_out=0,r.avail_out=i),s=inflate_1.inflate(r,a),s===Z_NEED_DICT$1&&n&&(s=inflate_1.inflateSetDictionary(r,n),s===Z_OK$3?s=inflate_1.inflate(r,a):s===Z_DATA_ERROR$2&&(s=Z_NEED_DICT$1));r.avail_in>0&&s===Z_STREAM_END$3&&r.state.wrap>0&&0!==t[r.next_in];)inflate_1.inflateReset(r),s=inflate_1.inflate(r,a);switch(s){case Z_STREAM_ERROR$2:case Z_DATA_ERROR$2:case Z_NEED_DICT$1:case Z_MEM_ERROR$1:return this.onEnd(s),this.ended=!0,!1}if(o=r.avail_out,r.next_out&&(0===r.avail_out||s===Z_STREAM_END$3))if("string"===this.options.to){let t=strings.utf8border(r.output,r.next_out),e=r.next_out-t,n=strings.buf2string(r.output,t);r.next_out=e,r.avail_out=i-e,e&&r.output.set(r.output.subarray(t,t+e),0),this.onData(n)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(s!==Z_OK$3||0!==o){if(s===Z_STREAM_END$3)return s=inflate_1.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===r.avail_in)break}}return!0},Inflate.prototype.onData=function(t){this.chunks.push(t)},Inflate.prototype.onEnd=function(t){t===Z_OK$3&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=common.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Inflate_1=Inflate,inflate_2$1=inflate$1,inflateRaw_1=inflateRaw,ungzip=inflate$1,constants$2=constants,inflate_1$1={Inflate:Inflate_1,inflate:inflate_2$1,inflateRaw:inflateRaw_1,ungzip:ungzip,constants:constants$2};const{Deflate:Deflate$1,deflate:deflate$2,deflateRaw:deflateRaw$1,gzip:gzip$1}=deflate_1$1,{Inflate:Inflate$1,inflate:inflate$2,inflateRaw:inflateRaw$1,ungzip:ungzip$1}=inflate_1$1;var deflate_1$2=deflate$2,Inflate_1$1=Inflate$1,inflate_1$2=inflate$2;const pngSignature=[137,80,78,71,13,10,26,10],crcTable=[];for(let t=0;t<256;t++){let e=t;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;crcTable[t]=e}const initialCrc=4294967295;function updateCrc(t,e,r){let i=t;for(let t=0;t<r;t++)i=crcTable[255&(i^e[t])]^i>>>8;return i}function crc(t,e){return(updateCrc(initialCrc,t,e)^initialCrc)>>>0}var ColorType,CompressionMethod,FilterMethod,InterlaceMethod;!function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.GREYSCALE=0]="GREYSCALE",t[t.TRUECOLOUR=2]="TRUECOLOUR",t[t.INDEXED_COLOUR=3]="INDEXED_COLOUR",t[t.GREYSCALE_ALPHA=4]="GREYSCALE_ALPHA",t[t.TRUECOLOUR_ALPHA=6]="TRUECOLOUR_ALPHA"}(ColorType||(ColorType={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.DEFLATE=0]="DEFLATE"}(CompressionMethod||(CompressionMethod={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.ADAPTIVE=0]="ADAPTIVE"}(FilterMethod||(FilterMethod={})),function(t){t[t.UNKNOWN=-1]="UNKNOWN",t[t.NO_INTERLACE=0]="NO_INTERLACE",t[t.ADAM7=1]="ADAM7"}(InterlaceMethod||(InterlaceMethod={}));const empty=new Uint8Array(0),NULL="\0",uint16=new Uint16Array([255]),uint8=new Uint8Array(uint16.buffer),osIsLittleEndian=255===uint8[0];class PNGDecoder extends IOBuffer$1{constructor(t,e={}){super(t);const{checkCrc:r=!1}=e;this._checkCrc=r,this._inflator=new Inflate_1$1,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._end=!1,this._hasPalette=!1,this._palette=[],this._compressionMethod=CompressionMethod.UNKNOWN,this._filterMethod=FilterMethod.UNKNOWN,this._interlaceMethod=InterlaceMethod.UNKNOWN,this._colorType=-1,this.setBigEndian()}decode(){for(this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(let t=0;t<pngSignature.length;t++)if(this.readUint8()!==pngSignature[t])throw new Error(`wrong PNG signature. Byte at ${t} should be ${pngSignature[t]}.`)}decodeChunk(){const t=this.readUint32(),e=this.readChars(4),r=this.offset;switch(e){case"IHDR":this.decodeIHDR();break;case"PLTE":this.decodePLTE(t);break;case"IDAT":this.decodeIDAT(t);break;case"IEND":this._end=!0;break;case"tRNS":this.decodetRNS(t);break;case"tEXt":this.decodetEXt(t);break;case"pHYs":this.decodepHYs();break;default:this.skip(t)}if(this.offset-r!==t)throw new Error(`Length mismatch while decoding chunk ${e}`);if(this._checkCrc){const r=this.readUint32(),i=t+4,n=crc(new Uint8Array(this.buffer,this.byteOffset+this.offset-i-4,i),i);if(n!==r)throw new Error(`CRC mismatch for chunk ${e}. Expected ${r}, found ${n}`)}else this.skip(4)}decodeIHDR(){const t=this._png;t.width=this.readUint32(),t.height=this.readUint32(),t.depth=checkBitDepth(this.readUint8());const e=this.readUint8();let r;switch(this._colorType=e,e){case ColorType.GREYSCALE:r=1;break;case ColorType.TRUECOLOUR:r=3;break;case ColorType.INDEXED_COLOUR:r=1;break;case ColorType.GREYSCALE_ALPHA:r=2;break;case ColorType.TRUECOLOUR_ALPHA:r=4;break;default:throw new Error(`Unknown color type: ${e}`)}if(this._png.channels=r,this._compressionMethod=this.readUint8(),this._compressionMethod!==CompressionMethod.DEFLATE)throw new Error(`Unsupported compression method: ${this._compressionMethod}`);this._filterMethod=this.readUint8(),this._interlaceMethod=this.readUint8()}decodePLTE(t){if(t%3!=0)throw new RangeError(`PLTE field length must be a multiple of 3. Got ${t}`);const e=t/3;this._hasPalette=!0;const r=[];this._palette=r;for(let t=0;t<e;t++)r.push([this.readUint8(),this.readUint8(),this.readUint8()])}decodeIDAT(t){this._inflator.push(new Uint8Array(this.buffer,this.offset+this.byteOffset,t)),this.skip(t)}decodetRNS(t){if(3===this._colorType){if(t>this._palette.length)throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${t} vs ${this._palette.length})`);let e=0;for(;e<t;e++){const t=this.readByte();this._palette[e].push(t)}for(;e<this._palette.length;e++)this._palette[e].push(255)}}decodetEXt(t){let e,r="";for(;(e=this.readChar())!==NULL;)r+=e;this._png.text[r]=this.readChars(t-r.length-1)}decodepHYs(){const t=this.readUint32(),e=this.readUint32(),r=this.readByte();this._png.resolution={x:t,y:e,unit:r}}decodeImage(){if(this._inflator.err)throw new Error(`Error while decompressing the data: ${this._inflator.err}`);const t=this._inflator.result;if(this._filterMethod!==FilterMethod.ADAPTIVE)throw new Error(`Filter method ${this._filterMethod} not supported`);if(this._interlaceMethod!==InterlaceMethod.NO_INTERLACE)throw new Error(`Interlace method ${this._interlaceMethod} not supported`);this.decodeInterlaceNull(t)}decodeInterlaceNull(t){const e=this._png.height,r=this._png.channels*this._png.depth/8,i=this._png.width*r,n=new Uint8Array(this._png.height*i);let s,a,o=empty,h=0;for(let l=0;l<e;l++){switch(s=t.subarray(h+1,h+1+i),a=n.subarray(l*i,(l+1)*i),t[h]){case 0:unfilterNone(s,a,i);break;case 1:unfilterSub(s,a,i,r);break;case 2:unfilterUp(s,a,o,i);break;case 3:unfilterAverage(s,a,o,i,r);break;case 4:unfilterPaeth(s,a,o,i,r);break;default:throw new Error(`Unsupported filter: ${t[h]}`)}o=a,h+=i+1}if(this._hasPalette&&(this._png.palette=this._palette),16===this._png.depth){const t=new Uint16Array(n.buffer);if(osIsLittleEndian)for(let e=0;e<t.length;e++)t[e]=swap16(t[e]);this._png.data=t}else this._png.data=n}}function unfilterNone(t,e,r){for(let i=0;i<r;i++)e[i]=t[i]}function unfilterSub(t,e,r,i){let n=0;for(;n<i;n++)e[n]=t[n];for(;n<r;n++)e[n]=t[n]+e[n-i]&255}function unfilterUp(t,e,r,i){let n=0;if(0===r.length)for(;n<i;n++)e[n]=t[n];else for(;n<i;n++)e[n]=t[n]+r[n]&255}function unfilterAverage(t,e,r,i,n){let s=0;if(0===r.length){for(;s<n;s++)e[s]=t[s];for(;s<i;s++)e[s]=t[s]+(e[s-n]>>1)&255}else{for(;s<n;s++)e[s]=t[s]+(r[s]>>1)&255;for(;s<i;s++)e[s]=t[s]+(e[s-n]+r[s]>>1)&255}}function unfilterPaeth(t,e,r,i,n){let s=0;if(0===r.length){for(;s<n;s++)e[s]=t[s];for(;s<i;s++)e[s]=t[s]+e[s-n]&255}else{for(;s<n;s++)e[s]=t[s]+r[s]&255;for(;s<i;s++)e[s]=t[s]+paethPredictor(e[s-n],r[s],r[s-n])&255}}function paethPredictor(t,e,r){const i=t+e-r,n=Math.abs(i-t),s=Math.abs(i-e),a=Math.abs(i-r);return n<=s&&n<=a?t:s<=a?e:r}function swap16(t){return(255&t)<<8|t>>8&255}function checkBitDepth(t){if(1!==t&&2!==t&&4!==t&&8!==t&&16!==t)throw new Error(`invalid bit depth: ${t}`);return t}const defaultZlibOptions={level:3};class PNGEncoder extends IOBuffer$1{constructor(t,e={}){super(),this._colorType=ColorType.UNKNOWN,this._zlibOptions=Object.assign({},defaultZlibOptions,e.zlib),this._png=this._checkData(t),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(pngSignature)}encodeIHDR(){this.writeUint32(13),this.writeChars("IHDR"),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.depth),this.writeByte(this._colorType),this.writeByte(CompressionMethod.DEFLATE),this.writeByte(FilterMethod.ADAPTIVE),this.writeByte(InterlaceMethod.NO_INTERLACE),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars("IEND"),this.writeCrc(4)}encodeIDAT(t){this.writeUint32(t.length),this.writeChars("IDAT"),this.writeBytes(t),this.writeCrc(t.length+4)}encodeData(){const{width:t,height:e,channels:r,depth:i,data:n}=this._png,s=r*t,a=(new IOBuffer$1).setBigEndian();let o=0;for(let t=0;t<e;t++)if(a.writeByte(0),8===i)o=writeDataBytes(n,a,s,o);else{if(16!==i)throw new Error("unreachable");o=writeDataUint16(n,a,s,o)}const h=a.toArray(),l=deflate_1$2(h,this._zlibOptions);this.encodeIDAT(l)}_checkData(t){const{colorType:e,channels:r,depth:i}=getColorType(t),n={width:checkInteger(t.width,"width"),height:checkInteger(t.height,"height"),channels:r,data:t.data,depth:i,text:{}};this._colorType=e;const s=n.width*n.height*r;if(n.data.length!==s)throw new RangeError(`wrong data size. Found ${n.data.length}, expected ${s}`);return n}writeCrc(t){this.writeUint32(crc(new Uint8Array(this.buffer,this.byteOffset+this.offset-t,t),t))}}function checkInteger(t,e){if(Number.isInteger(t)&&t>0)return t;throw new TypeError(`${e} must be a positive integer`)}function getColorType(t){const{channels:e=4,depth:r=8}=t;if(4!==e&&3!==e&&2!==e&&1!==e)throw new RangeError(`unsupported number of channels: ${e}`);if(8!==r&&16!==r)throw new RangeError(`unsupported bit depth: ${r}`);const i={channels:e,depth:r,colorType:ColorType.UNKNOWN};switch(e){case 4:i.colorType=ColorType.TRUECOLOUR_ALPHA;break;case 3:i.colorType=ColorType.TRUECOLOUR;break;case 1:i.colorType=ColorType.GREYSCALE;break;case 2:i.colorType=ColorType.GREYSCALE_ALPHA;break;default:throw new Error("unsupported number of channels")}return i}function writeDataBytes(t,e,r,i){for(let n=0;n<r;n++)e.writeByte(t[i++]);return i}function writeDataUint16(t,e,r,i){for(let n=0;n<r;n++)e.writeUint16(t[i++]);return i}function decodePNG(t,e){return new PNGDecoder(t,e).decode()}function encodePNG(t,e){return new PNGEncoder(t,e).encode()}var encoder=createCommonjsModule((function(t){function e(t){var e,r,i,n,s,a=Math.floor,o=new Array(64),h=new Array(64),l=new Array(64),c=new Array(64),u=new Array(65535),f=new Array(65535),d=new Array(64),m=new Array(64),g=[],p=0,w=7,_=new Array(64),b=new Array(64),y=new Array(64),M=new Array(256),x=new Array(2048),v=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63],E=[0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0],A=[0,1,2,3,4,5,6,7,8,9,10,11],k=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],S=[1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250],I=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],D=[0,1,2,3,4,5,6,7,8,9,10,11],R=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],T=[0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];function C(t,e){for(var r=0,i=0,n=new Array,s=1;s<=16;s++){for(var a=1;a<=t[s];a++)n[e[i]]=[],n[e[i]][0]=r,n[e[i]][1]=s,i++,r++;r*=2}return n}function $(t){for(var e=t[0],r=t[1]-1;r>=0;)e&1<<r&&(p|=1<<w),r--,--w<0&&(255==p?(B(255),B(0)):B(p),w=7,p=0)}function B(t){g.push(t)}function P(t){B(t>>8&255),B(255&t)}function O(t,e,r,i,n){for(var s,a=n[0],o=n[240],h=function(t,e){var r,i,n,s,a,o,h,l,c,u,f=0;for(c=0;c<8;++c){r=t[f],i=t[f+1],n=t[f+2],s=t[f+3],a=t[f+4],o=t[f+5],h=t[f+6];var m=r+(l=t[f+7]),g=r-l,p=i+h,w=i-h,_=n+o,b=n-o,y=s+a,M=s-a,x=m+y,v=m-y,E=p+_,A=p-_;t[f]=x+E,t[f+4]=x-E;var k=.707106781*(A+v);t[f+2]=v+k,t[f+6]=v-k;var S=.382683433*((x=M+b)-(A=w+g)),I=.5411961*x+S,D=1.306562965*A+S,R=.707106781*(E=b+w),T=g+R,C=g-R;t[f+5]=C+I,t[f+3]=C-I,t[f+1]=T+D,t[f+7]=T-D,f+=8}for(f=0,c=0;c<8;++c){r=t[f],i=t[f+8],n=t[f+16],s=t[f+24],a=t[f+32],o=t[f+40],h=t[f+48];var $=r+(l=t[f+56]),B=r-l,P=i+h,O=i-h,N=n+o,L=n-o,F=s+a,U=s-a,H=$+F,Y=$-F,V=P+N,z=P-N;t[f]=H+V,t[f+32]=H-V;var X=.707106781*(z+Y);t[f+16]=Y+X,t[f+48]=Y-X;var G=.382683433*((H=U+L)-(z=O+B)),Z=.5411961*H+G,j=1.306562965*z+G,K=.707106781*(V=L+O),q=B+K,W=B-K;t[f+40]=W+Z,t[f+24]=W-Z,t[f+8]=q+j,t[f+56]=q-j,f++}for(c=0;c<64;++c)u=t[c]*e[c],d[c]=u>0?u+.5|0:u-.5|0;return d}(t,e),l=0;l<64;++l)m[v[l]]=h[l];var c=m[0]-r;r=m[0],0==c?$(i[0]):($(i[f[s=32767+c]]),$(u[s]));for(var g=63;g>0&&0==m[g];g--);if(0==g)return $(a),r;for(var p,w=1;w<=g;){for(var _=w;0==m[w]&&w<=g;++w);var b=w-_;if(b>=16){p=b>>4;for(var y=1;y<=p;++y)$(o);b&=15}s=32767+m[w],$(n[(b<<4)+f[s]]),$(u[s]),w++}return 63!=g&&$(a),r}function N(t){if(t<=0&&(t=1),t>100&&(t=100),s!=t){(function(t){for(var e=[16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99],r=0;r<64;r++){var i=a((e[r]*t+50)/100);i<1?i=1:i>255&&(i=255),o[v[r]]=i}for(var n=[17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],s=0;s<64;s++){var u=a((n[s]*t+50)/100);u<1?u=1:u>255&&(u=255),h[v[s]]=u}for(var f=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],d=0,m=0;m<8;m++)for(var g=0;g<8;g++)l[d]=1/(o[v[d]]*f[m]*f[g]*8),c[d]=1/(h[v[d]]*f[m]*f[g]*8),d++})(t<50?Math.floor(5e3/t):Math.floor(200-2*t)),s=t}}this.encode=function(t,s){(new Date).getTime(),s&&N(s),g=new Array,p=0,w=7,P(65496),P(65504),P(16),B(74),B(70),B(73),B(70),B(0),B(1),B(1),B(0),P(1),P(1),B(0),B(0),function(t){if(t){P(65505),69===t[0]&&120===t[1]&&105===t[2]&&102===t[3]?P(t.length+2):(P(t.length+5+2),B(69),B(120),B(105),B(102),B(0));for(var e=0;e<t.length;e++)B(t[e])}}(t.exifBuffer),function(){P(65499),P(132),B(0);for(var t=0;t<64;t++)B(o[t]);B(1);for(var e=0;e<64;e++)B(h[e])}(),function(t,e){P(65472),P(17),B(8),P(e),P(t),B(3),B(1),B(17),B(0),B(2),B(17),B(1),B(3),B(17),B(1)}(t.width,t.height),function(){P(65476),P(418),B(0);for(var t=0;t<16;t++)B(E[t+1]);for(var e=0;e<=11;e++)B(A[e]);B(16);for(var r=0;r<16;r++)B(k[r+1]);for(var i=0;i<=161;i++)B(S[i]);B(1);for(var n=0;n<16;n++)B(I[n+1]);for(var s=0;s<=11;s++)B(D[s]);B(17);for(var a=0;a<16;a++)B(R[a+1]);for(var o=0;o<=161;o++)B(T[o])}(),P(65498),P(12),B(3),B(1),B(0),B(2),B(17),B(3),B(17),B(0),B(63),B(0);var a=0,u=0,f=0;p=0,w=7,this.encode.displayName="_encode_";for(var d,m,M,v,C,L,F,U,H,Y=t.data,V=t.width,z=t.height,X=4*V,G=0;G<z;){for(d=0;d<X;){for(L=C=X*G+d,F=-1,U=0,H=0;H<64;H++)L=C+(U=H>>3)*X+(F=4*(7&H)),G+U>=z&&(L-=X*(G+1+U-z)),d+F>=X&&(L-=d+F-X+4),m=Y[L++],M=Y[L++],v=Y[L++],_[H]=(x[m]+x[M+256>>0]+x[v+512>>0]>>16)-128,b[H]=(x[m+768>>0]+x[M+1024>>0]+x[v+1280>>0]>>16)-128,y[H]=(x[m+1280>>0]+x[M+1536>>0]+x[v+1792>>0]>>16)-128;a=O(_,l,a,e,i),u=O(b,c,u,r,n),f=O(y,c,f,r,n),d+=32}G+=8}if(w>=0){var Z=[];Z[1]=w+1,Z[0]=(1<<w+1)-1,$(Z)}return P(65497),Buffer.from(g)},(new Date).getTime(),t||(t=50),function(){for(var t=String.fromCharCode,e=0;e<256;e++)M[e]=t(e)}(),e=C(E,A),r=C(I,D),i=C(k,S),n=C(R,T),function(){for(var t=1,e=2,r=1;r<=15;r++){for(var i=t;i<e;i++)f[32767+i]=r,u[32767+i]=[],u[32767+i][1]=r,u[32767+i][0]=i;for(var n=-(e-1);n<=-t;n++)f[32767+n]=r,u[32767+n]=[],u[32767+n][1]=r,u[32767+n][0]=e-1+n;t<<=1,e<<=1}}(),function(){for(var t=0;t<256;t++)x[t]=19595*t,x[t+256>>0]=38470*t,x[t+512>>0]=7471*t+32768,x[t+768>>0]=-11059*t,x[t+1024>>0]=-21709*t,x[t+1280>>0]=32768*t+8421375,x[t+1536>>0]=-27439*t,x[t+1792>>0]=-5329*t}(),N(t),(new Date).getTime()}t.exports=function(t,r){void 0===r&&(r=50);return{data:new e(r).encode(t,r),width:t.width,height:t.height}}})),decoder=createCommonjsModule((function(t){var e=function(){var t=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),e=4017,r=799,i=3406,n=2276,s=1567,a=3784,o=5793,h=2896;function l(){}function c(t,e){for(var r,i,n=0,s=[],a=16;a>0&&!t[a-1];)a--;s.push({children:[],index:0});var o,h=s[0];for(r=0;r<a;r++){for(i=0;i<t[r];i++){for((h=s.pop()).children[h.index]=e[n];h.index>0;){if(0===s.length)throw new Error("Could not recreate Huffman Table");h=s.pop()}for(h.index++,s.push(h);s.length<=r;)s.push(o={children:[],index:0}),h.children[h.index]=o.children,h=o;n++}r+1<a&&(s.push(o={children:[],index:0}),h.children[h.index]=o.children,h=o)}return s[0].children}function u(e,r,i,n,s,a,o,h,l,c){i.precision,i.samplesPerLine,i.scanLines;var u=i.mcusPerLine,f=i.progressive;i.maxH,i.maxV;var d=r,m=0,g=0;function p(){if(g>0)return g--,m>>g&1;if(255==(m=e[r++])){var t=e[r++];if(t)throw new Error("unexpected marker: "+(m<<8|t).toString(16))}return g=7,m>>>7}function w(t){for(var e,r=t;null!==(e=p());){if("number"==typeof(r=r[e]))return r;if("object"!=typeof r)throw new Error("invalid huffman sequence")}return null}function _(t){for(var e=0;t>0;){var r=p();if(null===r)return;e=e<<1|r,t--}return e}function b(t){var e=_(t);return e>=1<<t-1?e:e+(-1<<t)+1}var y=0;var M,x=0;function v(t,e,r,i,n){var s=r%u,a=(r/u|0)*t.v+i,o=s*t.h+n;void 0===t.blocks[a]&&c.tolerantDecoding||e(t,t.blocks[a][o])}function E(t,e,r){var i=r/t.blocksPerLine|0,n=r%t.blocksPerLine;void 0===t.blocks[i]&&c.tolerantDecoding||e(t,t.blocks[i][n])}var A,k,S,I,D,R,T=n.length;R=f?0===a?0===h?function(t,e){var r=w(t.huffmanTableDC),i=0===r?0:b(r)<<l;e[0]=t.pred+=i}:function(t,e){e[0]|=p()<<l}:0===h?function(e,r){if(y>0)y--;else for(var i=a,n=o;i<=n;){var s=w(e.huffmanTableAC),h=15&s,c=s>>4;if(0!==h)r[t[i+=c]]=b(h)*(1<<l),i++;else{if(c<15){y=_(c)+(1<<c)-1;break}i+=16}}}:function(e,r){for(var i=a,n=o,s=0;i<=n;){var h=t[i],c=r[h]<0?-1:1;switch(x){case 0:var u=w(e.huffmanTableAC),f=15&u;if(s=u>>4,0===f)s<15?(y=_(s)+(1<<s),x=4):(s=16,x=1);else{if(1!==f)throw new Error("invalid ACn encoding");M=b(f),x=s?2:3}continue;case 1:case 2:r[h]?r[h]+=(p()<<l)*c:0==--s&&(x=2==x?3:0);break;case 3:r[h]?r[h]+=(p()<<l)*c:(r[h]=M<<l,x=0);break;case 4:r[h]&&(r[h]+=(p()<<l)*c)}i++}4===x&&0==--y&&(x=0)}:function(e,r){var i=w(e.huffmanTableDC),n=0===i?0:b(i);r[0]=e.pred+=n;for(var s=1;s<64;){var a=w(e.huffmanTableAC),o=15&a,h=a>>4;if(0!==o)r[t[s+=h]]=b(o),s++;else{if(h<15)break;s+=16}}};var C,$,B,P,O=0;for($=1==T?n[0].blocksPerLine*n[0].blocksPerColumn:u*i.mcusPerColumn,s||(s=$);O<$;){for(k=0;k<T;k++)n[k].pred=0;if(y=0,1==T)for(A=n[0],D=0;D<s;D++)E(A,R,O),O++;else for(D=0;D<s;D++){for(k=0;k<T;k++)for(B=(A=n[k]).h,P=A.v,S=0;S<P;S++)for(I=0;I<B;I++)v(A,R,O,S,I);if(++O===$)break}if(O===$)do{if(255===e[r]&&0!==e[r+1])break;r+=1}while(r<e.length-2);if(g=0,(C=e[r]<<8|e[r+1])<65280)throw new Error("marker was not found");if(!(C>=65488&&C<=65495))break;r+=2}return r-d}function f(t,l){var c,u,f=[],d=l.blocksPerLine,m=l.blocksPerColumn,g=d<<3,w=new Int32Array(64),_=new Uint8Array(64);function b(t,c,u){var f,d,m,g,p,w,_,b,y,M,x=l.quantizationTable,v=u;for(M=0;M<64;M++)v[M]=t[M]*x[M];for(M=0;M<8;++M){var E=8*M;0!=v[1+E]||0!=v[2+E]||0!=v[3+E]||0!=v[4+E]||0!=v[5+E]||0!=v[6+E]||0!=v[7+E]?(f=o*v[0+E]+128>>8,d=o*v[4+E]+128>>8,m=v[2+E],g=v[6+E],p=h*(v[1+E]-v[7+E])+128>>8,b=h*(v[1+E]+v[7+E])+128>>8,w=v[3+E]<<4,_=v[5+E]<<4,y=f-d+1>>1,f=f+d+1>>1,d=y,y=m*a+g*s+128>>8,m=m*s-g*a+128>>8,g=y,y=p-_+1>>1,p=p+_+1>>1,_=y,y=b+w+1>>1,w=b-w+1>>1,b=y,y=f-g+1>>1,f=f+g+1>>1,g=y,y=d-m+1>>1,d=d+m+1>>1,m=y,y=p*n+b*i+2048>>12,p=p*i-b*n+2048>>12,b=y,y=w*r+_*e+2048>>12,w=w*e-_*r+2048>>12,_=y,v[0+E]=f+b,v[7+E]=f-b,v[1+E]=d+_,v[6+E]=d-_,v[2+E]=m+w,v[5+E]=m-w,v[3+E]=g+p,v[4+E]=g-p):(y=o*v[0+E]+512>>10,v[0+E]=y,v[1+E]=y,v[2+E]=y,v[3+E]=y,v[4+E]=y,v[5+E]=y,v[6+E]=y,v[7+E]=y)}for(M=0;M<8;++M){var A=M;0!=v[8+A]||0!=v[16+A]||0!=v[24+A]||0!=v[32+A]||0!=v[40+A]||0!=v[48+A]||0!=v[56+A]?(f=o*v[0+A]+2048>>12,d=o*v[32+A]+2048>>12,m=v[16+A],g=v[48+A],p=h*(v[8+A]-v[56+A])+2048>>12,b=h*(v[8+A]+v[56+A])+2048>>12,w=v[24+A],_=v[40+A],y=f-d+1>>1,f=f+d+1>>1,d=y,y=m*a+g*s+2048>>12,m=m*s-g*a+2048>>12,g=y,y=p-_+1>>1,p=p+_+1>>1,_=y,y=b+w+1>>1,w=b-w+1>>1,b=y,y=f-g+1>>1,f=f+g+1>>1,g=y,y=d-m+1>>1,d=d+m+1>>1,m=y,y=p*n+b*i+2048>>12,p=p*i-b*n+2048>>12,b=y,y=w*r+_*e+2048>>12,w=w*e-_*r+2048>>12,_=y,v[0+A]=f+b,v[56+A]=f-b,v[8+A]=d+_,v[48+A]=d-_,v[16+A]=m+w,v[40+A]=m-w,v[24+A]=g+p,v[32+A]=g-p):(y=o*u[M+0]+8192>>14,v[0+A]=y,v[8+A]=y,v[16+A]=y,v[24+A]=y,v[32+A]=y,v[40+A]=y,v[48+A]=y,v[56+A]=y)}for(M=0;M<64;++M){var k=128+(v[M]+8>>4);c[M]=k<0?0:k>255?255:k}}p(g*m*8);for(var y=0;y<m;y++){var M=y<<3;for(c=0;c<8;c++)f.push(new Uint8Array(g));for(var x=0;x<d;x++){b(l.blocks[y][x],_,w);var v=0,E=x<<3;for(u=0;u<8;u++){var A=f[M+u];for(c=0;c<8;c++)A[E+c]=_[v++]}}}return f}function d(t){return t<0?0:t>255?255:t}l.prototype={load:function(t){var e=new XMLHttpRequest;e.open("GET",t,!0),e.responseType="arraybuffer",e.onload=function(){var t=new Uint8Array(e.response||e.mozResponseArrayBuffer);this.parse(t),this.onload&&this.onload()}.bind(this),e.send(null)},parse:function(e){var r=1e3*this.opts.maxResolutionInMP*1e3,i=0;function n(){var t=e[i]<<8|e[i+1];return i+=2,t}function s(t){var e,r,i=0,n=0;for(r in t.components)t.components.hasOwnProperty(r)&&(i<(e=t.components[r]).h&&(i=e.h),n<e.v&&(n=e.v));var s=Math.ceil(t.samplesPerLine/8/i),a=Math.ceil(t.scanLines/8/n);for(r in t.components)if(t.components.hasOwnProperty(r)){e=t.components[r];var o=Math.ceil(Math.ceil(t.samplesPerLine/8)*e.h/i),h=Math.ceil(Math.ceil(t.scanLines/8)*e.v/n),l=s*e.h,c=a*e.v,u=[];p(256*(c*l));for(var f=0;f<c;f++){for(var d=[],m=0;m<l;m++)d.push(new Int32Array(64));u.push(d)}e.blocksPerLine=o,e.blocksPerColumn=h,e.blocks=u}t.maxH=i,t.maxV=n,t.mcusPerLine=s,t.mcusPerColumn=a}e.length;var a,o,h,l,d=null,m=null,g=[],w=[],_=[],b=[],y=n(),M=-1;if(this.comments=[],65496!=y)throw new Error("SOI not found");for(y=n();65497!=y;){switch(y){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:var x=(h=void 0,l=void 0,h=n(),l=e.subarray(i,i+h-2),i+=l.length,l);if(65534===y){var v=String.fromCharCode.apply(null,x);this.comments.push(v)}65504===y&&74===x[0]&&70===x[1]&&73===x[2]&&70===x[3]&&0===x[4]&&(d={version:{major:x[5],minor:x[6]},densityUnits:x[7],xDensity:x[8]<<8|x[9],yDensity:x[10]<<8|x[11],thumbWidth:x[12],thumbHeight:x[13],thumbData:x.subarray(14,14+3*x[12]*x[13])}),65505===y&&69===x[0]&&120===x[1]&&105===x[2]&&102===x[3]&&0===x[4]&&(this.exifBuffer=x.subarray(5,x.length)),65518===y&&65===x[0]&&100===x[1]&&111===x[2]&&98===x[3]&&101===x[4]&&0===x[5]&&(m={version:x[6],flags0:x[7]<<8|x[8],flags1:x[9]<<8|x[10],transformCode:x[11]});break;case 65499:for(var E=n()+i-2;i<E;){var A=e[i++];p(256);var k=new Int32Array(64);if(A>>4==0)for(j=0;j<64;j++){k[t[j]]=e[i++]}else{if(A>>4!=1)throw new Error("DQT: invalid table spec");for(j=0;j<64;j++){k[t[j]]=n()}}g[15&A]=k}break;case 65472:case 65473:case 65474:n(),(a={}).extended=65473===y,a.progressive=65474===y,a.precision=e[i++],a.scanLines=n(),a.samplesPerLine=n(),a.components={},a.componentsOrder=[];var S=a.scanLines*a.samplesPerLine;if(S>r){var I=Math.ceil((S-r)/1e6);throw new Error(`maxResolutionInMP limit exceeded by ${I}MP`)}var D,R=e[i++];for(G=0;G<R;G++){D=e[i];var T=e[i+1]>>4,C=15&e[i+1],$=e[i+2];a.componentsOrder.push(D),a.components[D]={h:T,v:C,quantizationIdx:$},i+=3}s(a),w.push(a);break;case 65476:var B=n();for(G=2;G<B;){var P=e[i++],O=new Uint8Array(16),N=0;for(j=0;j<16;j++,i++)N+=O[j]=e[i];p(16+N);var L=new Uint8Array(N);for(j=0;j<N;j++,i++)L[j]=e[i];G+=17+N,(P>>4==0?b:_)[15&P]=c(O,L)}break;case 65501:n(),o=n();break;case 65500:n(),n();break;case 65498:n();var F=e[i++],U=[];for(G=0;G<F;G++){K=a.components[e[i++]];var H=e[i++];K.huffmanTableDC=b[H>>4],K.huffmanTableAC=_[15&H],U.push(K)}var Y=e[i++],V=e[i++],z=e[i++],X=u(e,i,a,U,o,Y,V,z>>4,15&z,this.opts);i+=X;break;case 65535:255!==e[i]&&i--;break;default:if(255==e[i-3]&&e[i-2]>=192&&e[i-2]<=254){i-=3;break}if(224===y||225==y){if(-1!==M)throw new Error(`first unknown JPEG marker at offset ${M.toString(16)}, second unknown JPEG marker ${y.toString(16)} at offset ${(i-1).toString(16)}`);M=i-1;const t=n();if(255===e[i+t-2]){i+=t-2;break}}throw new Error("unknown JPEG marker "+y.toString(16))}y=n()}if(1!=w.length)throw new Error("only single frame JPEGs supported");for(var G=0;G<w.length;G++){var Z=w[G].components;for(var j in Z)Z[j].quantizationTable=g[Z[j].quantizationIdx],delete Z[j].quantizationIdx}this.width=a.samplesPerLine,this.height=a.scanLines,this.jfif=d,this.adobe=m,this.components=[];for(G=0;G<a.componentsOrder.length;G++){var K=a.components[a.componentsOrder[G]];this.components.push({lines:f(0,K),scaleX:K.h/a.maxH,scaleY:K.v/a.maxV})}},getData:function(t,e){var r,i,n,s,a,o,h,l,c,u,f,m,g,w,_,b,y,M,x,v,E,A=this.width/t,k=this.height/e,S=0,I=t*e*this.components.length;p(I);var D=new Uint8Array(I);switch(this.components.length){case 1:for(r=this.components[0],u=0;u<e;u++)for(a=r.lines[0|u*r.scaleY*k],c=0;c<t;c++)f=a[0|c*r.scaleX*A],D[S++]=f;break;case 2:for(r=this.components[0],i=this.components[1],u=0;u<e;u++)for(a=r.lines[0|u*r.scaleY*k],o=i.lines[0|u*i.scaleY*k],c=0;c<t;c++)f=a[0|c*r.scaleX*A],D[S++]=f,f=o[0|c*i.scaleX*A],D[S++]=f;break;case 3:for(E=!0,this.adobe&&this.adobe.transformCode?E=!0:void 0!==this.opts.colorTransform&&(E=!!this.opts.colorTransform),r=this.components[0],i=this.components[1],n=this.components[2],u=0;u<e;u++)for(a=r.lines[0|u*r.scaleY*k],o=i.lines[0|u*i.scaleY*k],h=n.lines[0|u*n.scaleY*k],c=0;c<t;c++)E?(f=a[0|c*r.scaleX*A],m=o[0|c*i.scaleX*A],M=d(f+1.402*((g=h[0|c*n.scaleX*A])-128)),x=d(f-.3441363*(m-128)-.71413636*(g-128)),v=d(f+1.772*(m-128))):(M=a[0|c*r.scaleX*A],x=o[0|c*i.scaleX*A],v=h[0|c*n.scaleX*A]),D[S++]=M,D[S++]=x,D[S++]=v;break;case 4:if(!this.adobe)throw new Error("Unsupported color mode (4 components)");for(E=!1,this.adobe&&this.adobe.transformCode?E=!0:void 0!==this.opts.colorTransform&&(E=!!this.opts.colorTransform),r=this.components[0],i=this.components[1],n=this.components[2],s=this.components[3],u=0;u<e;u++)for(a=r.lines[0|u*r.scaleY*k],o=i.lines[0|u*i.scaleY*k],h=n.lines[0|u*n.scaleY*k],l=s.lines[0|u*s.scaleY*k],c=0;c<t;c++)E?(f=a[0|c*r.scaleX*A],m=o[0|c*i.scaleX*A],g=h[0|c*n.scaleX*A],w=l[0|c*s.scaleX*A],_=255-d(f+1.402*(g-128)),b=255-d(f-.3441363*(m-128)-.71413636*(g-128)),y=255-d(f+1.772*(m-128))):(_=a[0|c*r.scaleX*A],b=o[0|c*i.scaleX*A],y=h[0|c*n.scaleX*A],w=l[0|c*s.scaleX*A]),D[S++]=255-_,D[S++]=255-b,D[S++]=255-y,D[S++]=255-w;break;default:throw new Error("Unsupported color mode")}return D},copyToImageData:function(t,e){var r,i,n,s,a,o,h,l,c,u=t.width,f=t.height,m=t.data,g=this.getData(u,f),p=0,w=0;switch(this.components.length){case 1:for(i=0;i<f;i++)for(r=0;r<u;r++)n=g[p++],m[w++]=n,m[w++]=n,m[w++]=n,e&&(m[w++]=255);break;case 3:for(i=0;i<f;i++)for(r=0;r<u;r++)h=g[p++],l=g[p++],c=g[p++],m[w++]=h,m[w++]=l,m[w++]=c,e&&(m[w++]=255);break;case 4:for(i=0;i<f;i++)for(r=0;r<u;r++)a=g[p++],o=g[p++],n=g[p++],h=255-d(a*(1-(s=g[p++])/255)+s),l=255-d(o*(1-s/255)+s),c=255-d(n*(1-s/255)+s),m[w++]=h,m[w++]=l,m[w++]=c,e&&(m[w++]=255);break;default:throw new Error("Unsupported color mode")}}};var m=0,g=0;function p(t=0){var e=m+t;if(e>g){var r=Math.ceil((e-g)/1024/1024);throw new Error(`maxMemoryUsageInMB limit exceeded by at least ${r}MB`)}m=e}return l.resetMaxMemoryUsage=function(t){m=0,g=t},l.getBytesAllocated=function(){return m},l.requestMemoryAllocation=p,l}();t.exports=function(t,r={}){var i={colorTransform:void 0,useTArray:!1,formatAsRGBA:!0,tolerantDecoding:!0,maxResolutionInMP:100,maxMemoryUsageInMB:512,...r},n=new Uint8Array(t),s=new e;s.opts=i,e.resetMaxMemoryUsage(1024*i.maxMemoryUsageInMB*1024),s.parse(n);var a=i.formatAsRGBA?4:3,o=s.width*s.height*a;try{e.requestMemoryAllocation(o);var h={width:s.width,height:s.height,exifBuffer:s.exifBuffer,data:i.useTArray?new Uint8Array(o):Buffer.alloc(o)};s.comments.length>0&&(h.comments=s.comments)}catch(t){throw t instanceof RangeError?new Error("Could not allocate enough memory for the image. Required: "+o):t}return s.copyToImageData(h,i.formatAsRGBA),h}})),_jpegJs_0_4_3_jpegJs={encode:encoder,decode:decoder};let chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",lookup=new Uint8Array(256);for(let t=0;t<chars.length;t++)lookup[chars.charCodeAt(t)]=t;function encode(t){let e,r=t.length,i="";for(e=0;e<r;e+=3)i+=chars[t[e]>>2],i+=chars[(3&t[e])<<4|t[e+1]>>4],i+=chars[(15&t[e+1])<<2|t[e+2]>>6],i+=chars[63&t[e+2]];return r%3==2?i=`${i.substring(0,i.length-1)}=`:r%3==1&&(i=`${i.substring(0,i.length-2)}==`),i}function decode$4(t){let e,r,i,n,s=.75*t.length,a=t.length,o=0;"="===t[t.length-1]&&(s--,"="===t[t.length-2]&&s--);const h=new Uint8Array(s);for(let s=0;s<a;s+=4)e=lookup[t.charCodeAt(s)],r=lookup[t.charCodeAt(s+1)],i=lookup[t.charCodeAt(s+2)],n=lookup[t.charCodeAt(s+3)],h[o++]=e<<2|r>>4,h[o++]=(15&r)<<4|i>>2,h[o++]=(3&i)<<6|63&n;return h}function toBase64URL(t,e){return`data:${e};base64,${encode(t)}`}const ImageData=self.ImageData,DOMImage=self.Image;function createCanvas(t,e){let r=self.document.createElement("canvas");return r.width=t,r.height=e,r}function fetchBinary(t,{withCredentials:e=!1}={}){return new Promise((function(r,i){let n=new self.XMLHttpRequest;n.open("GET",t,!0),n.responseType="arraybuffer",n.withCredentials=e,n.onload=function(t){200!==this.status?i(t):r(this.response)},n.onerror=i,n.send()}))}function createWriteStream(){throw new Error("createWriteStream does not exist in the browser")}function writeFile(){throw new Error("writeFile does not exist in the browser")}function getType(t){return t.includes("/")||(t=`image/${t}`),t}function encodeJpeg(t,e={}){const r={width:t.width,height:t.height,data:t.getRGBAData()};return _jpegJs_0_4_3_jpegJs.encode(r,e.quality).data}function encodePng(t,e){const r={width:t.width,height:t.height,channels:t.channels,depth:t.bitDepth,data:t.data};return 1!==r.depth&&32!==r.depth||(r.depth=8,r.channels=4,r.data=t.getRGBAData()),encodePNG(r,e)}const exportMethods={save(t,e={}){const{useCanvas:r=!1,encoder:i}=e;let{format:n}=e;if(!n){const e=/\.(?<format>[a-zA-Z]+)$/.exec(t);e&&(n=e.groups.format.toLowerCase())}if(!n)throw new Error("file format not provided");return new Promise(((t,e)=>{let s,a;switch(n.toLowerCase()){case"png":r?s=this.getCanvas().pngStream():a=encodePng(this,i);break;case"jpg":case"jpeg":r?s=this.getCanvas().jpegStream():a=encodeJpeg(this,i);break;case"bmp":a=encode$2(this);break;default:throw new RangeError(`invalid output format: ${n}`)}if(s){let r=createWriteStream();r.on("finish",t),r.on("error",e),s.pipe(r)}else a&&writeFile()}))},toDataURL(t="image/png",e={}){"object"==typeof t&&(e=t,t="image/png");const{useCanvas:r=!1,encoder:i}=e;function n(e,r){return toBase64URL(e(r,i),t)}return"image/bmp"===(t=getType(t))?n(encode$2,this):"image/png"!==t||r?"image/jpeg"!==t||r?this.getCanvas().toDataURL(t):n(encodeJpeg,this):n(encodePng,this)},toBuffer(t={}){const{format:e="png",encoder:r}=t;switch(e.toLowerCase()){case"png":return encodePng(this,r);case"jpeg":case"jpg":return encodeJpeg(this,r);case"bmp":return encode$2(this);default:throw new RangeError(`invalid output format: ${e}`)}},toBase64(t="image/png",e={}){if(e.async)return this.toDataURL(t,e).then((function(t){return t.substring(t.indexOf(",")+1)}));{const r=this.toDataURL(t,e);return r.substring(r.indexOf(",")+1)}},toBlob(t="image/png",e=.8){return canvasToBlob(this.getCanvas(),t,e)},getCanvas(){const t=new ImageData(this.getRGBAData({clamped:!0}),this.width,this.height);let e=createCanvas(this.width,this.height);return e.getContext("2d").putImageData(t,0,0),e}};function setExportMethods(t){for(const e in exportMethods)t.prototype[e]=exportMethods[e]}var name="has-own",version="1.0.1",description="A safer .hasOwnProperty() - hasOwn(name, obj)",main="index.js",scripts={test:"make test"},author="Aaron Heckmann <aaron.heckmann+github@gmail.com>",license="MIT",repository={type:"git",url:"git://github.com/aheckmann/has-own.git"},homepage="https://github.com/aheckmann/has-own/",devDependencies={mocha:"^6.2.2"},__npminstall_done="Thu Apr 15 2021 16:59:03 GMT+0800 (中国标准时间)",_from="has-own@1.0.1",_resolved="https://registry.npm.taobao.org/has-own/download/has-own-1.0.1.tgz",require$$0$2={name:name,version:version,description:description,main:main,scripts:scripts,author:author,license:license,repository:repository,homepage:homepage,devDependencies:devDependencies,__npminstall_done:__npminstall_done,_from:_from,_resolved:_resolved},_hasOwn_1_0_1_hasOwn=createCommonjsModule((function(t,e){var r=Object.prototype.hasOwnProperty;t.exports=e=function(t,e){return r.call(e,t)},e.version=require$$0$2.version}));let computedPropertyDescriptor$1={configurable:!0,enumerable:!1,get:void 0};function extendMethod(t,e,r={}){let{inPlace:i=!1,returnThis:n=!0,partialArgs:s=[]}=r;return Image.prototype[t]=i?function(...t){this.computed=null;let r=e.apply(this,[...s,...t]);return n?this:r}:function(...t){return e.apply(this,[...s,...t])},Image}function extendProperty(t,e,r={}){let{partialArgs:i=[]}=r;return computedPropertyDescriptor$1.get=function(){if(null===this.computed)this.computed={};else if(_hasOwn_1_0_1_hasOwn(t,this.computed))return this.computed[t];let r=e.apply(this,i);return this.computed[t]=r,r},Object.defineProperty(Image.prototype,t,computedPropertyDescriptor$1),Image}const GREY$1="GREY",RGB$1="RGB",HSL="HSL",HSV="HSV",CMYK$1="CMYK";var ColorModel=Object.freeze({__proto__:null,GREY:GREY$1,RGB:RGB$1,HSL:HSL,HSV:HSV,CMYK:CMYK$1});function getRGBAData(t={}){const{clamped:e}=t;this.checkProcessable("getRGBAData",{components:[1,3],bitDepth:[1,8,16,32]});const r=this.width*this.height*4;let i=e?new Uint8ClampedArray(r):new Uint8Array(r);return 1===this.bitDepth?fillDataFromBinary(this,i):32===this.bitDepth?(this.checkProcessable("getRGBAData",{alpha:0}),1===this.components?fillDataFromGrey32(this,i):3===this.components&&(this.checkProcessable("getRGBAData",{colorModel:[RGB$1]}),fillDataFromRGB32(this,i))):1===this.components?fillDataFromGrey(this,i):3===this.components&&(this.checkProcessable("getRGBAData",{colorModel:[RGB$1]}),fillDataFromRGB(this,i)),1===this.alpha?(this.checkProcessable("getRGBAData",{bitDepth:[8,16]}),copyAlpha(this,i)):fillAlpha(this,i),i}function fillDataFromBinary(t,e){for(let r=0;r<t.size;r++){const i=t.getBit(r);e[4*r]=255*i,e[4*r+1]=255*i,e[4*r+2]=255*i}}function fillDataFromGrey32(t,e){const r=t.min[0],i=t.max[0]-r;for(let n=0;n<t.size;n++){const s=Math.floor(255*(t.data[n]-r)/i);e[4*n]=s,e[4*n+1]=s,e[4*n+2]=s}}function fillDataFromRGB32(t,e){const r=Math.min(...t.min),i=Math.max(...t.max)-r;for(let n=0;n<t.size;n++){const s=Math.floor(255*(t.data[3*n]-r)/i),a=Math.floor(255*(t.data[3*n+1]-r)/i),o=Math.floor(255*(t.data[3*n+2]-r)/i);e[4*n]=s,e[4*n+1]=a,e[4*n+2]=o}}function fillDataFromGrey(t,e){for(let r=0;r<t.size;r++)e[4*r]=t.data[r*t.channels]>>>t.bitDepth-8,e[4*r+1]=t.data[r*t.channels]>>>t.bitDepth-8,e[4*r+2]=t.data[r*t.channels]>>>t.bitDepth-8}function fillDataFromRGB(t,e){for(let r=0;r<t.size;r++)e[4*r]=t.data[r*t.channels]>>>t.bitDepth-8,e[4*r+1]=t.data[r*t.channels+1]>>>t.bitDepth-8,e[4*r+2]=t.data[r*t.channels+2]>>>t.bitDepth-8}function copyAlpha(t,e){for(let r=0;r<t.size;r++)e[4*r+3]=t.data[r*t.channels+t.components]>>t.bitDepth-8}function fillAlpha(t,e){for(let r=0;r<t.size;r++)e[4*r+3]=255}const BINARY="BINARY",GREY="GREY",GREYA="GREYA",RGB="RGB",RGBA="RGBA",CMYK="CMYK",CMYKA="CMYKA",kinds={};function getKind(t){const e=kinds[t];if(!e)throw new RangeError(`invalid image kind: ${t}`);return e}kinds[BINARY]={components:1,alpha:0,bitDepth:1,colorModel:GREY$1},kinds[GREYA]={components:1,alpha:1,bitDepth:8,colorModel:GREY$1},kinds[GREY]={components:1,alpha:0,bitDepth:8,colorModel:GREY$1},kinds[RGBA]={components:3,alpha:1,bitDepth:8,colorModel:RGB$1},kinds[RGB]={components:3,alpha:0,bitDepth:8,colorModel:RGB$1},kinds[CMYK]={components:4,alpha:0,bitDepth:8,colorModel:CMYK$1},kinds[CMYKA]={components:4,alpha:1,bitDepth:8,colorModel:CMYK$1};const validBitDepth=[1,8,16,32];function verifyKindDefinition(t){const{components:e,alpha:r,bitDepth:i,colorModel:n}=t;if(!Number.isInteger(e)||e<=0)throw new RangeError(`invalid components: ${e}. Must be a positive integer`);if(0!==r&&1!==r&&"boolean"!=typeof r)throw new TypeError(`invalid alpha: ${r}: must be a boolean, 0 or 1`);if(!validBitDepth.includes(i))throw new RangeError(`invalid bitDepth: ${i}. Must be one of ${validBitDepth.join(", ")}`);if(!ColorModel[n])throw new RangeError(`invalid colorModel: ${n}. Must be one of ${Object.keys(ColorModel).join(", ")}`)}function getTheoreticalPixelArraySize(t,e,r){let i=e*t;return 1===r&&(i=Math.ceil(i/8)),i}function createPixelArray(t,e,r,i,n,s){const a=i*t;let o;switch(n){case 1:o=new Uint8Array(Math.ceil(a/8));break;case 8:o=new Uint8Array(a);break;case 16:o=new Uint16Array(a);break;case 32:o=new Float32Array(a);break;default:throw new Error(`Cannot create pixel array for bit depth ${n}`)}if(r)for(let t=e;t<o.length;t+=i)o[t]=s;return o}const defaultByteLength=8192,charArray=[];class IOBuffer{constructor(t,e){e=e||{},void 0===t&&(t=defaultByteLength),"number"==typeof t&&(t=new ArrayBuffer(t));let r=t.byteLength;const i=e.offset?e.offset>>>0:0;t.buffer&&(r=t.byteLength-i,t=t.byteLength!==t.buffer.byteLength?t.buffer.slice(t.byteOffset+i,t.byteOffset+t.byteLength):i?t.buffer.slice(i):t.buffer),this.buffer=t,this.length=r,this.byteLength=r,this.byteOffset=0,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer),this._increment=r||defaultByteLength,this._mark=0}available(t){return void 0===t&&(t=1),this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){this.littleEndian=!0}isBigEndian(){return!this.littleEndian}setBigEndian(){this.littleEndian=!1}skip(t){void 0===t&&(t=1),this.offset+=t}seek(t){this.offset=t}mark(){this._mark=this.offset}reset(){this.offset=this._mark}rewind(){this.offset=0}ensureAvailable(t){if(void 0===t&&(t=1),!this.available(t)){const t=this._increment+this._increment;this._increment=t;const e=this.length+t,r=new Uint8Array(e);r.set(new Uint8Array(this.buffer)),this.buffer=r.buffer,this.length=e,this._data=new DataView(this.buffer)}}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t){void 0===t&&(t=1);for(var e=new Uint8Array(t),r=0;r<t;r++)e[r]=this.readByte();return e}readInt16(){var t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){var t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){var t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){var t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){var t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){var t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t){void 0===t&&(t=1),charArray.length=t;for(var e=0;e<t;e++)charArray[e]=this.readChar();return charArray.join("")}writeBoolean(t){this.writeUint8(t?255:0)}writeInt8(t){this.ensureAvailable(1),this._data.setInt8(this.offset++,t)}writeUint8(t){this.ensureAvailable(1),this._data.setUint8(this.offset++,t)}writeByte(t){this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(var e=0;e<t.length;e++)this._data.setUint8(this.offset++,t[e])}writeInt16(t){this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2}writeUint16(t){this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2}writeInt32(t){this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4}writeUint32(t){this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4}writeFloat32(t){this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4}writeFloat64(t){this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8}writeChar(t){this.writeUint8(t.charCodeAt(0))}writeChars(t){for(var e=0;e<t.length;e++)this.writeUint8(t.charCodeAt(e))}toArray(){return new Uint8Array(this.buffer,0,this.offset)}}var IOBuffer_1=IOBuffer;const tagsById$5={254:"NewSubfileType",255:"SubfileType",256:"ImageWidth",257:"ImageLength",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",263:"Threshholding",264:"CellWidth",265:"CellLength",266:"FillOrder",270:"ImageDescription",271:"Make",272:"Model",273:"StripOffsets",274:"Orientation",277:"SamplesPerPixel",278:"RowsPerStrip",279:"StripByteCounts",280:"MinSampleValue",281:"MaxSampleValue",282:"XResolution",283:"YResolution",284:"PlanarConfiguration",288:"FreeOffsets",289:"FreeByteCounts",290:"GrayResponseUnit",291:"GrayResponseCurve",296:"ResolutionUnit",305:"Software",306:"DateTime",315:"Artist",316:"HostComputer",320:"ColorMap",338:"ExtraSamples",33432:"Copyright",269:"DocumentName",285:"PageName",286:"XPosition",287:"YPosition",292:"T4Options",293:"T6Options",297:"PageNumber",301:"TransferFunction",317:"Predictor",318:"WhitePoint",319:"PrimaryChromaticities",321:"HalftoneHints",322:"TileWidth",323:"TileLength",324:"TileOffsets",325:"TileByteCounts",326:"BadFaxLines",327:"CleanFaxData",328:"ConsecutiveBadFaxLines",330:"SubIFDs",332:"InkSet",333:"InkNames",334:"NumberOfInks",336:"DotRange",337:"TargetPrinter",339:"SampleFormat",340:"SMinSampleValue",341:"SMaxSampleValue",342:"TransferRange",343:"ClipPath",344:"XClipPathUnits",345:"YClipPathUnits",346:"Indexed",347:"JPEGTables",351:"OPIProxy",400:"GlobalParametersIFD",401:"ProfileType",402:"FaxProfile",403:"CodingMethods",404:"VersionYear",405:"ModeNumber",433:"Decode",434:"DefaultImageColor",512:"JPEGProc",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",515:"JPEGRestartInterval",517:"JPEGLosslessPredictors",518:"JPEGPointTransforms",519:"JPEGQTables",520:"JPEGDCTables",521:"JPEGACTables",529:"YCbCrCoefficients",530:"YCbCrSubSampling",531:"YCbCrPositioning",532:"ReferenceBlackWhite",559:"StripRowCounts",700:"XMP",32781:"ImageID",34732:"ImageLayer",32932:"WangAnnotatio",33445:"MDFileTag",33446:"MDScalePixel",33447:"MDColorTable",33448:"MDLabName",33449:"MDSampleInfo",33450:"MDPrepDate",33451:"MDPrepTime",33452:"MDFileUnits",33550:"ModelPixelScaleTag",33723:"IPTC",33918:"INGRPacketDataTag",33919:"INGRFlagRegisters",33920:"IrasBTransformationMatrix",33922:"ModelTiepointTag",34264:"ModelTransformationTag",34377:"Photoshop",34665:"ExifIFD",34675:"ICCProfile",34735:"GeoKeyDirectoryTag",34736:"GeoDoubleParamsTag",34737:"GeoAsciiParamsTag",34853:"GPSIFD",34908:"HylaFAXFaxRecvParams",34909:"HylaFAXFaxSubAddress",34910:"HylaFAXFaxRecvTime",37724:"ImageSourceData",40965:"InteroperabilityIFD",42112:"GDAL_METADATA",42113:"GDAL_NODATA",50215:"OceScanjobDescription",50216:"OceApplicationSelector",50217:"OceIdentificationNumber",50218:"OceImageLogicCharacteristics",50706:"DNGVersion",50707:"DNGBackwardVersion",50708:"UniqueCameraModel",50709:"LocalizedCameraModel",50710:"CFAPlaneColor",50711:"CFALayout",50712:"LinearizationTable",50713:"BlackLevelRepeatDim",50714:"BlackLevel",50715:"BlackLevelDeltaH",50716:"BlackLevelDeltaV",50717:"WhiteLevel",50718:"DefaultScale",50719:"DefaultCropOrigin",50720:"DefaultCropSize",50721:"ColorMatrix1",50722:"ColorMatrix2",50723:"CameraCalibration1",50724:"CameraCalibration2",50725:"ReductionMatrix1",50726:"ReductionMatrix2",50727:"AnalogBalance",50728:"AsShotNeutral",50729:"AsShotWhiteXY",50730:"BaselineExposure",50731:"BaselineNoise",50732:"BaselineSharpness",50733:"BayerGreenSplit",50734:"LinearResponseLimit",50735:"CameraSerialNumber",50736:"LensInfo",50737:"ChromaBlurRadius",50738:"AntiAliasStrength",50740:"DNGPrivateData",50741:"MakerNoteSafety",50778:"CalibrationIlluminant1",50779:"CalibrationIlluminant2",50780:"BestQualityScale",50784:"AliasLayerMetadata"},tagsByName$5={};for(var i$2 in tagsById$5)tagsByName$5[tagsById$5[i$2]]=i$2;var standard$1={tagsById:tagsById$5,tagsByName:tagsByName$5};const tagsById$4={33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",34864:"SensitivityType",34865:"StandardOutputSensitivity",34866:"RecommendedExposureIndex",34867:"ISOSpeed",34868:"ISOSpeedLatitudeyyy",34869:"ISOSpeedLatitudezzz",36864:"ExifVersion",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBiasValue",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37386:"FocalLength",37396:"SubjectArea",37500:"MakerNote",37510:"UserComment",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",40964:"RelatedSoundFile",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRatio",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",42016:"ImageUniqueID",42032:"CameraOwnerName",42033:"BodySerialNumber",42034:"LensSpecification",42035:"LensMake",42036:"LensModel",42037:"LensSerialNumber",42240:"Gamma"},tagsByName$4={};for(var i$1 in tagsById$4)tagsByName$4[tagsById$4[i$1]]=i$1;var exif$1={tagsById:tagsById$4,tagsByName:tagsByName$4};const tagsById$3={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential",31:"GPSHPositioningError"},tagsByName$3={};for(var i in tagsById$3)tagsByName$3[tagsById$3[i]]=i;var gps$1={tagsById:tagsById$3,tagsByName:tagsByName$3};const tags$1={standard:standard$1,exif:exif$1,gps:gps$1};class IFD$1{constructor(t){if(!t)throw new Error("missing kind");this.data=null,this.fields=new Map,this.kind=t,this._map=null}get(t){if("number"==typeof t)return this.fields.get(t);if("string"==typeof t)return this.fields.get(tags$1[this.kind].tagsByName[t]);throw new Error("expected a number or string")}get map(){if(!this._map){this._map={};const e=tags$1[this.kind].tagsById;for(var t of this.fields.keys())e[t]&&(this._map[e[t]]=this.fields.get(t))}return this._map}}var ifd=IFD$1;const dateTimeRegex$1=/^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;class TiffIfd$1 extends ifd{constructor(){super("standard")}get size(){return this.width*this.height}get width(){return this.imageWidth}get height(){return this.imageLength}get components(){return this.samplesPerPixel}get date(){var t=new Date,e=dateTimeRegex$1.exec(this.dateTime);return t.setFullYear(e[1],e[2]-1,e[3]),t.setHours(e[4],e[5],e[6]),t}get newSubfileType(){return this.get(254)}get imageWidth(){return this.get(256)}get imageLength(){return this.get(257)}get bitsPerSample(){return this.get(258)}get compression(){return this.get(259)||1}get type(){return this.get(262)}get fillOrder(){return this.get(266)||1}get documentName(){return this.get(269)}get imageDescription(){return this.get(270)}get stripOffsets(){return alwaysArray$1(this.get(273))}get orientation(){return this.get(274)}get samplesPerPixel(){return this.get(277)}get rowsPerStrip(){return this.get(278)}get stripByteCounts(){return alwaysArray$1(this.get(279))}get minSampleValue(){return this.get(280)||0}get maxSampleValue(){return this.get(281)||Math.pow(2,this.bitsPerSample)-1}get xResolution(){return this.get(282)}get yResolution(){return this.get(283)}get planarConfiguration(){return this.get(284)||1}get resolutionUnit(){return this.get(296)||2}get dateTime(){return this.get(306)}get predictor(){return this.get(317)||1}get sampleFormat(){return this.get(339)||1}get sMinSampleValue(){return this.get(340)||this.minSampleValue}get sMaxSampleValue(){return this.get(341)||this.maxSampleValue}}function alwaysArray$1(t){return"number"==typeof t?[t]:t}var tiffIfd=TiffIfd$1,types$1=new Map([[1,[1,readByte$1]],[2,[1,readASCII$1]],[3,[2,readShort$1]],[4,[4,readLong$1]],[5,[8,readRational$1]],[6,[1,readSByte$1]],[7,[1,readByte$1]],[8,[2,readSShort$1]],[9,[4,readSLong$1]],[10,[8,readSRational$1]],[11,[4,readFloat$1]],[12,[8,readDouble$1]]]),getByteLength$1=function(t,e){return types$1.get(t)[0]*e},readData$1=function(t,e,r){return types$1.get(e)[1](t,r)};function readByte$1(t,e){if(1===e)return t.readUint8();for(var r=new Uint8Array(e),i=0;i<e;i++)r[i]=t.readUint8();return r}function readASCII$1(t,e){for(var r=[],i="",n=0;n<e;n++){var s=String.fromCharCode(t.readUint8());"\0"===s?(r.push(i),i=""):i+=s}return 1===r.length?r[0]:r}function readShort$1(t,e){if(1===e)return t.readUint16();for(var r=new Uint16Array(e),i=0;i<e;i++)r[i]=t.readUint16();return r}function readLong$1(t,e){if(1===e)return t.readUint32();for(var r=new Uint32Array(e),i=0;i<e;i++)r[i]=t.readUint32();return r}function readRational$1(t,e){if(1===e)return t.readUint32()/t.readUint32();for(var r=new Array(e),i=0;i<e;i++)r[i]=t.readUint32()/t.readUint32();return r}function readSByte$1(t,e){if(1===e)return t.readInt8();for(var r=new Int8Array(e),i=0;i<e;i++)r[i]=t.readInt8();return r}function readSShort$1(t,e){if(1===e)return t.readInt16();for(var r=new Int16Array(e),i=0;i<e;i++)r[i]=t.readInt16();return r}function readSLong$1(t,e){if(1===e)return t.readInt32();for(var r=new Int32Array(e),i=0;i<e;i++)r[i]=t.readInt32();return r}function readSRational$1(t,e){if(1===e)return t.readInt32()/t.readInt32();for(var r=new Array(e),i=0;i<e;i++)r[i]=t.readInt32()/t.readInt32();return r}function readFloat$1(t,e){if(1===e)return t.readFloat32();for(var r=new Float32Array(e),i=0;i<e;i++)r[i]=t.readFloat32();return r}function readDouble$1(t,e){if(1===e)return t.readFloat64();for(var r=new Float64Array(e),i=0;i<e;i++)r[i]=t.readFloat64();return r}var ifdValue={getByteLength:getByteLength$1,readData:readData$1};const defaultOptions$d={ignoreImageData:!1,onlyFirst:!1};class TIFFDecoder$1 extends IOBuffer_1{constructor(t,e){super(t,e),this._nextIFD=0}decode(t){t=Object.assign({},defaultOptions$d,t);const e=[];for(this.decodeHeader();this._nextIFD;)if(e.push(this.decodeIFD(t)),t.onlyFirst)return e[0];return e}decodeHeader(){let t=this.readUint16();if(18761===t)this.setLittleEndian();else{if(19789!==t)throw new Error("invalid byte order: 0x"+t.toString(16));this.setBigEndian()}if(t=this.readUint16(),42!==t)throw new Error("not a TIFF file");this._nextIFD=this.readUint32()}decodeIFD(t){var e;this.seek(this._nextIFD),e=t.kind?new ifd(t.kind):new tiffIfd;const r=this.readUint16();for(var i=0;i<r;i++)this.decodeIFDEntry(e);return t.ignoreImageData||this.decodeImageData(e),this._nextIFD=this.readUint32(),e}decodeIFDEntry(t){const e=this.offset,r=this.readUint16(),i=this.readUint16(),n=this.readUint32();if(i<1||i>12)return void this.skip(4);ifdValue.getByteLength(i,n)>4&&this.seek(this.readUint32());const s=ifdValue.readData(this,i,n);if(t.fields.set(r,s),34665===r||34853===r){let e,i=this.offset;34665===r?e="exif":34853===r&&(e="gps"),this._nextIFD=s,t[e]=this.decodeIFD({kind:e,ignoreImageData:!0}),this.offset=i}this.seek(e),this.skip(12)}decodeImageData(t){const e=t.orientation;switch(e&&1!==e&&unsupported$1("orientation",e),t.type){case 1:case 2:this.readStripData(t);break;default:unsupported$1("image type",t.type)}}readStripData(t){const e=t.width,r=t.height,i=validateBitDepth(t.bitsPerSample),n=t.sampleFormat;let s=e*r;const a=getDataArray$1(s,1,i,n),o=t.compression,h=t.rowsPerStrip*e,l=t.stripOffsets,c=t.stripByteCounts;for(var u=0,f=0;f<l.length;f++){var d=this.getStripData(o,l[f],c[f]),m=s>h?h:s;s-=m,8===i?u=fill8bit$1(a,d,u,m):16===i?u=fill16bit$1(a,d,u,m,this.isLittleEndian()):32===i&&3===n?u=fillFloat32$1(a,d,u,m,this.isLittleEndian()):unsupported$1("bitDepth",i)}t.data=a}getStripData(t,e,r){switch(t){case 1:return new DataView(this.buffer,e,r);case 2:case 32773:return unsupported$1("Compression",t);default:throw new Error("invalid compression: "+t)}}}var tiffDecoder=TIFFDecoder$1;function getDataArray$1(t,e,r,i){return 8===r?new Uint8Array(t*e):16===r?new Uint16Array(t*e):32===r&&3===i?new Float32Array(t*e):unsupported$1("bit depth / sample format",r+" / "+i)}function fill8bit$1(t,e,r,i){for(var n=0;n<i;n++)t[r++]=e.getUint8(n);return r}function fill16bit$1(t,e,r,i,n){for(var s=0;s<2*i;s+=2)t[r++]=e.getUint16(s,n);return r}function fillFloat32$1(t,e,r,i,n){for(var s=0;s<4*i;s+=4)t[r++]=e.getFloat32(s,n);return r}function unsupported$1(t,e){throw new Error("Unsupported "+t+": "+e)}function validateBitDepth(t){if(t.length){const r=t;t=r[0];for(var e=0;e<r.length;e++)r[e]!==t&&unsupported$1("bit depth",r)}return t}var decode$3=function(t,e){return new tiffDecoder(t,e).decode(e)},decode$2=decode$3,src$4={decode:decode$2};function decode$1(t){const e=new IOBuffer_1(t),r={};e.setBigEndian();if(65496!==e.readUint16())throw new Error("SOI marker not found. Not a valid JPEG file");if(65505===e.readUint16()){e.readUint16();const t=e.readBytes(6);if(69===t[0]&&120===t[1]&&105===t[2]&&102===t[3]&&0===t[4]&&0===t[5]){const t=src$4.decode(e,{onlyFirst:!0,ignoreImageData:!0,offset:e.offset});r.exif=t}}return r}var decode_1=decode$1,decode=decode_1,_fileType_10_11_0_fileType=createCommonjsModule((function(module){const toBytes=t=>[...t].map((t=>t.charCodeAt(0))),xpiZipFilename=toBytes("META-INF/mozilla.rsa"),oxmlContentTypes=toBytes("[Content_Types].xml"),oxmlRels=toBytes("_rels/.rels");function readUInt64LE(t,e=0){let r=t[e],i=1,n=0;for(;++n<8;)i*=256,r+=t[e+n]*i;return r}const fileType=t=>{if(!(t instanceof Uint8Array||t instanceof ArrayBuffer||Buffer.isBuffer(t)))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`Buffer\` or \`ArrayBuffer\`, got \`${typeof t}\``);const e=t instanceof Uint8Array?t:new Uint8Array(t);if(!(e&&e.length>1))return null;const r=(t,r)=>{r=Object.assign({offset:0},r);for(let i=0;i<t.length;i++)if(r.mask){if(t[i]!==(r.mask[i]&e[i+r.offset]))return!1}else if(t[i]!==e[i+r.offset])return!1;return!0},i=(t,e)=>r(toBytes(t),e);if(r([255,216,255]))return{ext:"jpg",mime:"image/jpeg"};if(r([137,80,78,71,13,10,26,10]))return{ext:"png",mime:"image/png"};if(r([71,73,70]))return{ext:"gif",mime:"image/gif"};if(r([87,69,66,80],{offset:8}))return{ext:"webp",mime:"image/webp"};if(r([70,76,73,70]))return{ext:"flif",mime:"image/flif"};if((r([73,73,42,0])||r([77,77,0,42]))&&r([67,82],{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(r([73,73,42,0])||r([77,77,0,42]))return{ext:"tif",mime:"image/tiff"};if(r([66,77]))return{ext:"bmp",mime:"image/bmp"};if(r([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(r([56,66,80,83]))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(r([80,75,3,4])){if(r([109,105,109,101,116,121,112,101,97,112,112,108,105,99,97,116,105,111,110,47,101,112,117,98,43,122,105,112],{offset:30}))return{ext:"epub",mime:"application/epub+zip"};if(r(xpiZipFilename,{offset:30}))return{ext:"xpi",mime:"application/x-xpinstall"};if(i("mimetypeapplication/vnd.oasis.opendocument.text",{offset:30}))return{ext:"odt",mime:"application/vnd.oasis.opendocument.text"};if(i("mimetypeapplication/vnd.oasis.opendocument.spreadsheet",{offset:30}))return{ext:"ods",mime:"application/vnd.oasis.opendocument.spreadsheet"};if(i("mimetypeapplication/vnd.oasis.opendocument.presentation",{offset:30}))return{ext:"odp",mime:"application/vnd.oasis.opendocument.presentation"};const t=(t,e=0)=>t.findIndex(((t,r,i)=>r>=e&&80===i[r]&&75===i[r+1]&&3===i[r+2]&&4===i[r+3]));let n=0,s=!1,a=null;do{const o=n+30;if(s||(s=r(oxmlContentTypes,{offset:o})||r(oxmlRels,{offset:o})),a||(i("word/",{offset:o})?a={ext:"docx",mime:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"}:i("ppt/",{offset:o})?a={ext:"pptx",mime:"application/vnd.openxmlformats-officedocument.presentationml.presentation"}:i("xl/",{offset:o})&&(a={ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})),s&&a)return a;n=t(e,o)}while(n>=0);if(a)return a}if(r([80,75])&&(3===e[2]||5===e[2]||7===e[2])&&(4===e[3]||6===e[3]||8===e[3]))return{ext:"zip",mime:"application/zip"};if(r([117,115,116,97,114],{offset:257}))return{ext:"tar",mime:"application/x-tar"};if(r([82,97,114,33,26,7])&&(0===e[6]||1===e[6]))return{ext:"rar",mime:"application/x-rar-compressed"};if(r([31,139,8]))return{ext:"gz",mime:"application/gzip"};if(r([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(r([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(r([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(r([51,103,112,53])||r([0,0,0])&&r([102,116,121,112],{offset:4})&&(r([109,112,52,49],{offset:8})||r([109,112,52,50],{offset:8})||r([105,115,111,109],{offset:8})||r([105,115,111,50],{offset:8})||r([109,109,112,52],{offset:8})||r([77,52,86],{offset:8})||r([100,97,115,104],{offset:8})))return{ext:"mp4",mime:"video/mp4"};if(r([77,84,104,100]))return{ext:"mid",mime:"audio/midi"};if(r([26,69,223,163])){const t=e.subarray(4,4100),r=t.findIndex(((t,e,r)=>66===r[e]&&130===r[e+1]));if(-1!==r){const e=r+3,i=r=>[...r].every(((r,i)=>t[e+i]===r.charCodeAt(0)));if(i("matroska"))return{ext:"mkv",mime:"video/x-matroska"};if(i("webm"))return{ext:"webm",mime:"video/webm"}}}if(r([0,0,0,20,102,116,121,112,113,116,32,32])||r([102,114,101,101],{offset:4})||r([102,116,121,112,113,116,32,32],{offset:4})||r([109,100,97,116],{offset:4})||r([109,111,111,118],{offset:4})||r([119,105,100,101],{offset:4}))return{ext:"mov",mime:"video/quicktime"};if(r([82,73,70,70])){if(r([65,86,73],{offset:8}))return{ext:"avi",mime:"video/vnd.avi"};if(r([87,65,86,69],{offset:8}))return{ext:"wav",mime:"audio/vnd.wave"};if(r([81,76,67,77],{offset:8}))return{ext:"qcp",mime:"audio/qcelp"}}if(r([48,38,178,117,142,102,207,17,166,217])){let t=30;do{const i=readUInt64LE(e,t+16);if(r([145,7,220,183,183,169,207,17,142,230,0,192,12,32,83,101],{offset:t})){if(r([64,158,105,248,77,91,207,17,168,253,0,128,95,92,68,43],{offset:t+24}))return{ext:"wma",mime:"audio/x-ms-wma"};if(r([192,239,25,188,77,91,207,17,168,253,0,128,95,92,68,43],{offset:t+24}))return{ext:"wmv",mime:"video/x-ms-asf"};break}t+=i}while(t+24<=e.length);return{ext:"asf",mime:"application/vnd.ms-asf"}}if(r([0,0,1,186])||r([0,0,1,179]))return{ext:"mpg",mime:"video/mpeg"};if(r([102,116,121,112,51,103],{offset:4}))return{ext:"3gp",mime:"video/3gpp"};for(let t=0;t<2&&t<e.length-16;t++){if(r([73,68,51],{offset:t})||r([255,226],{offset:t,mask:[255,226]}))return{ext:"mp3",mime:"audio/mpeg"};if(r([255,228],{offset:t,mask:[255,228]}))return{ext:"mp2",mime:"audio/mpeg"};if(r([255,248],{offset:t,mask:[255,252]}))return{ext:"mp2",mime:"audio/mpeg"};if(r([255,240],{offset:t,mask:[255,252]}))return{ext:"mp4",mime:"audio/mpeg"}}if(r([102,116,121,112,77,52,65],{offset:4}))return{ext:"m4a",mime:"audio/mp4"};if(r([79,112,117,115,72,101,97,100],{offset:28}))return{ext:"opus",mime:"audio/opus"};if(r([79,103,103,83]))return r([128,116,104,101,111,114,97],{offset:28})?{ext:"ogv",mime:"video/ogg"}:r([1,118,105,100,101,111,0],{offset:28})?{ext:"ogm",mime:"video/ogg"}:r([127,70,76,65,67],{offset:28})?{ext:"oga",mime:"audio/ogg"}:r([83,112,101,101,120,32,32],{offset:28})?{ext:"spx",mime:"audio/ogg"}:r([1,118,111,114,98,105,115],{offset:28})?{ext:"ogg",mime:"audio/ogg"}:{ext:"ogx",mime:"application/ogg"};if(r([102,76,97,67]))return{ext:"flac",mime:"audio/x-flac"};if(r([77,65,67,32]))return{ext:"ape",mime:"audio/ape"};if(r([119,118,112,107]))return{ext:"wv",mime:"audio/wavpack"};if(r([35,33,65,77,82,10]))return{ext:"amr",mime:"audio/amr"};if(r([37,80,68,70]))return{ext:"pdf",mime:"application/pdf"};if(r([77,90]))return{ext:"exe",mime:"application/x-msdownload"};if((67===e[0]||70===e[0])&&r([87,83],{offset:1}))return{ext:"swf",mime:"application/x-shockwave-flash"};if(r([123,92,114,116,102]))return{ext:"rtf",mime:"application/rtf"};if(r([0,97,115,109]))return{ext:"wasm",mime:"application/wasm"};if(r([119,79,70,70])&&(r([0,1,0,0],{offset:4})||r([79,84,84,79],{offset:4})))return{ext:"woff",mime:"font/woff"};if(r([119,79,70,50])&&(r([0,1,0,0],{offset:4})||r([79,84,84,79],{offset:4})))return{ext:"woff2",mime:"font/woff2"};if(r([76,80],{offset:34})&&(r([0,0,1],{offset:8})||r([1,0,2],{offset:8})||r([2,0,2],{offset:8})))return{ext:"eot",mime:"application/vnd.ms-fontobject"};if(r([0,1,0,0,0]))return{ext:"ttf",mime:"font/ttf"};if(r([79,84,84,79,0]))return{ext:"otf",mime:"font/otf"};if(r([0,0,1,0]))return{ext:"ico",mime:"image/x-icon"};if(r([0,0,2,0]))return{ext:"cur",mime:"image/x-icon"};if(r([70,76,86,1]))return{ext:"flv",mime:"video/x-flv"};if(r([37,33]))return{ext:"ps",mime:"application/postscript"};if(r([253,55,122,88,90,0]))return{ext:"xz",mime:"application/x-xz"};if(r([83,81,76,105]))return{ext:"sqlite",mime:"application/x-sqlite3"};if(r([78,69,83,26]))return{ext:"nes",mime:"application/x-nintendo-nes-rom"};if(r([67,114,50,52]))return{ext:"crx",mime:"application/x-google-chrome-extension"};if(r([77,83,67,70])||r([73,83,99,40]))return{ext:"cab",mime:"application/vnd.ms-cab-compressed"};if(r([33,60,97,114,99,104,62,10,100,101,98,105,97,110,45,98,105,110,97,114,121]))return{ext:"deb",mime:"application/x-deb"};if(r([33,60,97,114,99,104,62]))return{ext:"ar",mime:"application/x-unix-archive"};if(r([237,171,238,219]))return{ext:"rpm",mime:"application/x-rpm"};if(r([31,160])||r([31,157]))return{ext:"Z",mime:"application/x-compress"};if(r([76,90,73,80]))return{ext:"lz",mime:"application/x-lzip"};if(r([208,207,17,224,161,177,26,225]))return{ext:"msi",mime:"application/x-msi"};if(r([6,14,43,52,2,5,1,1,13,1,2,1,1,2]))return{ext:"mxf",mime:"application/mxf"};if(r([71],{offset:4})&&(r([71],{offset:192})||r([71],{offset:196})))return{ext:"mts",mime:"video/mp2t"};if(r([66,76,69,78,68,69,82]))return{ext:"blend",mime:"application/x-blender"};if(r([66,80,71,251]))return{ext:"bpg",mime:"image/bpg"};if(r([0,0,0,12,106,80,32,32,13,10,135,10])){if(r([106,112,50,32],{offset:20}))return{ext:"jp2",mime:"image/jp2"};if(r([106,112,120,32],{offset:20}))return{ext:"jpx",mime:"image/jpx"};if(r([106,112,109,32],{offset:20}))return{ext:"jpm",mime:"image/jpm"};if(r([109,106,112,50],{offset:20}))return{ext:"mj2",mime:"image/mj2"}}if(r([70,79,82,77]))return{ext:"aif",mime:"audio/aiff"};if(i("<?xml "))return{ext:"xml",mime:"application/xml"};if(r([66,79,79,75,77,79,66,73],{offset:60}))return{ext:"mobi",mime:"application/x-mobipocket-ebook"};if(r([102,116,121,112],{offset:4})){if(r([109,105,102,49],{offset:8}))return{ext:"heic",mime:"image/heif"};if(r([109,115,102,49],{offset:8}))return{ext:"heic",mime:"image/heif-sequence"};if(r([104,101,105,99],{offset:8})||r([104,101,105,120],{offset:8}))return{ext:"heic",mime:"image/heic"};if(r([104,101,118,99],{offset:8})||r([104,101,118,120],{offset:8}))return{ext:"heic",mime:"image/heic-sequence"}}return r([171,75,84,88,32,49,49,187,13,10,26,10])?{ext:"ktx",mime:"image/ktx"}:r([68,73,67,77],{offset:128})?{ext:"dcm",mime:"application/dicom"}:r([77,80,43])||r([77,80,67,75])?{ext:"mpc",mime:"audio/x-musepack"}:r([66,69,71,73,78,58])?{ext:"ics",mime:"text/calendar"}:r([103,108,84,70,2,0,0,0])?{ext:"glb",mime:"model/gltf-binary"}:r([212,195,178,161])||r([161,178,195,212])?{ext:"pcap",mime:"application/vnd.tcpdump.pcap"}:null};module.exports=fileType,module.exports.default=fileType,Object.defineProperty(fileType,"minimumBytes",{value:4100}),module.exports.stream=readableStream=>new Promise(((resolve,reject)=>{const stream=eval("require")("stream");readableStream.once("readable",(()=>{const t=new stream.PassThrough,e=readableStream.read(module.exports.minimumBytes)||readableStream.read();try{t.fileType=fileType(e)}catch(t){reject(t)}readableStream.unshift(e),stream.pipeline?resolve(stream.pipeline(readableStream,t,(()=>{}))):resolve(readableStream.pipe(t))}))}))}));const imageExts=new Set(["jpg","png","gif","webp","flif","cr2","tif","bmp","jxr","psd","ico","bpg","jp2","jpm","jpx","heic","cur","dcm"]),imageType=t=>{const e=_fileType_10_11_0_fileType(t);return imageExts.has(e&&e.ext)?e:null};var _imageType_4_1_0_imageType=imageType,_default=imageType;function applyHorizontalDifferencing8Bit(t,e,r){let i=0;for(;i<t.length;){for(let n=r;n<e*r;n+=r)for(let e=0;e<r;e++)t[i+n+e]=t[i+n+e]+t[i+n-(r-e)]&255;i+=e*r}}function applyHorizontalDifferencing16Bit(t,e,r){let i=0;for(;i<t.length;){for(let n=r;n<e*r;n+=r)for(let e=0;e<r;e++)t[i+n+e]=t[i+n+e]+t[i+n-(r-e)]&65535;i+=e*r}}Object.defineProperty(imageType,"minimumBytes",{value:_fileType_10_11_0_fileType.minimumBytes}),_imageType_4_1_0_imageType.default=_default;const tagsById$2={33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",34864:"SensitivityType",34865:"StandardOutputSensitivity",34866:"RecommendedExposureIndex",34867:"ISOSpeed",34868:"ISOSpeedLatitudeyyy",34869:"ISOSpeedLatitudezzz",36864:"ExifVersion",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBiasValue",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37386:"FocalLength",37396:"SubjectArea",37500:"MakerNote",37510:"UserComment",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",40964:"RelatedSoundFile",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRatio",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",42016:"ImageUniqueID",42032:"CameraOwnerName",42033:"BodySerialNumber",42034:"LensSpecification",42035:"LensMake",42036:"LensModel",42037:"LensSerialNumber",42240:"Gamma"},tagsByName$2={};for(let t in tagsById$2)tagsByName$2[tagsById$2[t]]=Number(t);var exif=Object.freeze({__proto__:null,tagsById:tagsById$2,tagsByName:tagsByName$2});const tagsById$1={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential",31:"GPSHPositioningError"},tagsByName$1={};for(let t in tagsById$1)tagsByName$1[tagsById$1[t]]=Number(t);var gps=Object.freeze({__proto__:null,tagsById:tagsById$1,tagsByName:tagsByName$1});const tagsById={254:"NewSubfileType",255:"SubfileType",256:"ImageWidth",257:"ImageLength",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",263:"Threshholding",264:"CellWidth",265:"CellLength",266:"FillOrder",270:"ImageDescription",271:"Make",272:"Model",273:"StripOffsets",274:"Orientation",277:"SamplesPerPixel",278:"RowsPerStrip",279:"StripByteCounts",280:"MinSampleValue",281:"MaxSampleValue",282:"XResolution",283:"YResolution",284:"PlanarConfiguration",288:"FreeOffsets",289:"FreeByteCounts",290:"GrayResponseUnit",291:"GrayResponseCurve",296:"ResolutionUnit",305:"Software",306:"DateTime",315:"Artist",316:"HostComputer",320:"ColorMap",338:"ExtraSamples",33432:"Copyright",269:"DocumentName",285:"PageName",286:"XPosition",287:"YPosition",292:"T4Options",293:"T6Options",297:"PageNumber",301:"TransferFunction",317:"Predictor",318:"WhitePoint",319:"PrimaryChromaticities",321:"HalftoneHints",322:"TileWidth",323:"TileLength",324:"TileOffsets",325:"TileByteCounts",326:"BadFaxLines",327:"CleanFaxData",328:"ConsecutiveBadFaxLines",330:"SubIFDs",332:"InkSet",333:"InkNames",334:"NumberOfInks",336:"DotRange",337:"TargetPrinter",339:"SampleFormat",340:"SMinSampleValue",341:"SMaxSampleValue",342:"TransferRange",343:"ClipPath",344:"XClipPathUnits",345:"YClipPathUnits",346:"Indexed",347:"JPEGTables",351:"OPIProxy",400:"GlobalParametersIFD",401:"ProfileType",402:"FaxProfile",403:"CodingMethods",404:"VersionYear",405:"ModeNumber",433:"Decode",434:"DefaultImageColor",512:"JPEGProc",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",515:"JPEGRestartInterval",517:"JPEGLosslessPredictors",518:"JPEGPointTransforms",519:"JPEGQTables",520:"JPEGDCTables",521:"JPEGACTables",529:"YCbCrCoefficients",530:"YCbCrSubSampling",531:"YCbCrPositioning",532:"ReferenceBlackWhite",559:"StripRowCounts",700:"XMP",32781:"ImageID",34732:"ImageLayer",32932:"WangAnnotatio",33445:"MDFileTag",33446:"MDScalePixel",33447:"MDColorTable",33448:"MDLabName",33449:"MDSampleInfo",33450:"MDPrepDate",33451:"MDPrepTime",33452:"MDFileUnits",33550:"ModelPixelScaleTag",33723:"IPTC",33918:"INGRPacketDataTag",33919:"INGRFlagRegisters",33920:"IrasBTransformationMatrix",33922:"ModelTiepointTag",34264:"ModelTransformationTag",34377:"Photoshop",34665:"ExifIFD",34675:"ICCProfile",34735:"GeoKeyDirectoryTag",34736:"GeoDoubleParamsTag",34737:"GeoAsciiParamsTag",34853:"GPSIFD",34908:"HylaFAXFaxRecvParams",34909:"HylaFAXFaxSubAddress",34910:"HylaFAXFaxRecvTime",37724:"ImageSourceData",40965:"InteroperabilityIFD",42112:"GDAL_METADATA",42113:"GDAL_NODATA",50215:"OceScanjobDescription",50216:"OceApplicationSelector",50217:"OceIdentificationNumber",50218:"OceImageLogicCharacteristics",50706:"DNGVersion",50707:"DNGBackwardVersion",50708:"UniqueCameraModel",50709:"LocalizedCameraModel",50710:"CFAPlaneColor",50711:"CFALayout",50712:"LinearizationTable",50713:"BlackLevelRepeatDim",50714:"BlackLevel",50715:"BlackLevelDeltaH",50716:"BlackLevelDeltaV",50717:"WhiteLevel",50718:"DefaultScale",50719:"DefaultCropOrigin",50720:"DefaultCropSize",50721:"ColorMatrix1",50722:"ColorMatrix2",50723:"CameraCalibration1",50724:"CameraCalibration2",50725:"ReductionMatrix1",50726:"ReductionMatrix2",50727:"AnalogBalance",50728:"AsShotNeutral",50729:"AsShotWhiteXY",50730:"BaselineExposure",50731:"BaselineNoise",50732:"BaselineSharpness",50733:"BayerGreenSplit",50734:"LinearResponseLimit",50735:"CameraSerialNumber",50736:"LensInfo",50737:"ChromaBlurRadius",50738:"AntiAliasStrength",50740:"DNGPrivateData",50741:"MakerNoteSafety",50778:"CalibrationIlluminant1",50779:"CalibrationIlluminant2",50780:"BestQualityScale",50784:"AliasLayerMetadata"},tagsByName={};for(let t in tagsById)tagsByName[tagsById[t]]=Number(t);var standard=Object.freeze({__proto__:null,tagsById:tagsById,tagsByName:tagsByName});const tags={standard:standard,exif:exif,gps:gps};class IFD{constructor(t){if(!t)throw new Error("missing kind");this.data=new Uint8Array,this.fields=new Map,this.kind=t,this._hasMap=!1,this._map={}}get(t){if("number"==typeof t)return this.fields.get(t);if("string"==typeof t)return this.fields.get(tags[this.kind].tagsByName[t]);throw new Error("expected a number or string")}get map(){if(!this._hasMap){const t=tags[this.kind].tagsById;for(let e of this.fields.keys())t[e]&&(this._map[t[e]]=this.fields.get(e));this._hasMap=!0}return this._map}}let types=new Map([[1,[1,readByte]],[2,[1,readASCII]],[3,[2,readShort]],[4,[4,readLong]],[5,[8,readRational]],[6,[1,readSByte]],[7,[1,readByte]],[8,[2,readSShort]],[9,[4,readSLong]],[10,[8,readSRational]],[11,[4,readFloat]],[12,[8,readDouble]]]);function getByteLength(t,e){const r=types.get(t);if(!r)throw new Error(`type not found: ${t}`);return r[0]*e}function readData(t,e,r){const i=types.get(e);if(!i)throw new Error(`type not found: ${e}`);return i[1](t,r)}function readByte(t,e){if(1===e)return t.readUint8();let r=new Uint8Array(e);for(let i=0;i<e;i++)r[i]=t.readUint8();return r}function readASCII(t,e){let r=[],i="";for(let n=0;n<e;n++){let e=String.fromCharCode(t.readUint8());"\0"===e?(r.push(i),i=""):i+=e}return 1===r.length?r[0]:r}function readShort(t,e){if(1===e)return t.readUint16();let r=new Uint16Array(e);for(let i=0;i<e;i++)r[i]=t.readUint16();return r}function readLong(t,e){if(1===e)return t.readUint32();let r=new Uint32Array(e);for(let i=0;i<e;i++)r[i]=t.readUint32();return r}function readRational(t,e){if(1===e)return t.readUint32()/t.readUint32();let r=new Array(e);for(let i=0;i<e;i++)r[i]=t.readUint32()/t.readUint32();return r}function readSByte(t,e){if(1===e)return t.readInt8();let r=new Int8Array(e);for(let i=0;i<e;i++)r[i]=t.readInt8();return r}function readSShort(t,e){if(1===e)return t.readInt16();let r=new Int16Array(e);for(let i=0;i<e;i++)r[i]=t.readInt16();return r}function readSLong(t,e){if(1===e)return t.readInt32();let r=new Int32Array(e);for(let i=0;i<e;i++)r[i]=t.readInt32();return r}function readSRational(t,e){if(1===e)return t.readInt32()/t.readInt32();let r=new Array(e);for(let i=0;i<e;i++)r[i]=t.readInt32()/t.readInt32();return r}function readFloat(t,e){if(1===e)return t.readFloat32();let r=new Float32Array(e);for(let i=0;i<e;i++)r[i]=t.readFloat32();return r}function readDouble(t,e){if(1===e)return t.readFloat64();let r=new Float64Array(e);for(let i=0;i<e;i++)r[i]=t.readFloat64();return r}const CLEAR_CODE=256,EOI_CODE=257,TABLE_START=258,MIN_BIT_LENGTH=9,stringTable=[];for(let t=0;t<256;t++)stringTable.push([t]);const dummyString=[0];for(let t=256;t<4096;t++)stringTable.push(dummyString);class LzwDecoder{constructor(t){this.stripArray=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Map;for(let t=0;t<256;t++)e.set(t,[t]);this.currentBit=0,this.tableLength=TABLE_START,this.currentBitLength=MIN_BIT_LENGTH,this.outData=new IOBuffer$1(t.byteLength)}decode(){let t=0,e=0;for(;(t=this.getNextCode())!==EOI_CODE;)if(t===CLEAR_CODE){if(this.initializeTable(),t=this.getNextCode(),t===EOI_CODE)break;this.writeString(this.stringFromCode(t)),e=t}else if(this.isInTable(t))this.writeString(this.stringFromCode(t)),this.addStringToTable(this.stringFromCode(e).concat(this.stringFromCode(t)[0])),e=t;else{const r=this.stringFromCode(e).concat(this.stringFromCode(e)[0]);this.writeString(r),this.addStringToTable(r),e=t}const r=this.outData.toArray();return new DataView(r.buffer,r.byteOffset,r.byteLength)}initializeTable(){this.tableLength=TABLE_START,this.currentBitLength=MIN_BIT_LENGTH}writeString(t){this.outData.writeBytes(t)}stringFromCode(t){return stringTable[t]}isInTable(t){return t<this.tableLength}addStringToTable(t){stringTable[this.tableLength++]=t,this.tableLength+1===2**this.currentBitLength&&this.currentBitLength++}getNextCode(){const t=this.currentBit%8,e=this.currentBit>>>3,r=8-t,i=this.currentBit+this.currentBitLength-8*(e+1);let n=8*(e+2)-(this.currentBit+this.currentBitLength);const s=8*(e+2)-this.currentBit;n=Math.max(0,n);let a=this.stripArray[e]&2**(8-t)-1;a<<=this.currentBitLength-r;let o=a;if(e+1<this.stripArray.length){let t=this.stripArray[e+1]>>>n;t<<=Math.max(0,this.currentBitLength-s),o+=t}if(i>8&&e+2<this.stripArray.length){const t=8*(e+3)-(this.currentBit+this.currentBitLength);o+=this.stripArray[e+2]>>>t}return this.currentBit+=this.currentBitLength,o}}function decompressLzw(t){return new LzwDecoder(t).decode()}const dateTimeRegex=/^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;class TiffIfd extends IFD{constructor(){super("standard")}get size(){return this.width*this.height}get width(){return this.imageWidth}get height(){return this.imageLength}get components(){return this.samplesPerPixel}get date(){let t=new Date,e=dateTimeRegex.exec(this.dateTime);if(null===e)throw new Error(`invalid dateTime: ${this.dateTime}`);return t.setFullYear(Number(e[1]),Number(e[2])-1,Number(e[3])),t.setHours(Number(e[4]),Number(e[5]),Number(e[6])),t}get newSubfileType(){return this.get("NewSubfileType")}get imageWidth(){return this.get("ImageWidth")}get imageLength(){return this.get("ImageLength")}get bitsPerSample(){const t=this.get("BitsPerSample");return t&&"number"!=typeof t?t[0]:t}get alpha(){const t=this.extraSamples;return!!t&&0!==t[0]}get associatedAlpha(){const t=this.extraSamples;return!!t&&1===t[0]}get extraSamples(){return alwaysArray(this.get("ExtraSamples"))}get compression(){return this.get("Compression")||1}get type(){return this.get("PhotometricInterpretation")}get fillOrder(){return this.get("FillOrder")||1}get documentName(){return this.get("DocumentName")}get imageDescription(){return this.get("ImageDescription")}get stripOffsets(){return alwaysArray(this.get("StripOffsets"))}get orientation(){return this.get("Orientation")}get samplesPerPixel(){return this.get("SamplesPerPixel")||1}get rowsPerStrip(){return this.get("RowsPerStrip")}get stripByteCounts(){return alwaysArray(this.get("StripByteCounts"))}get minSampleValue(){return this.get("MinSampleValue")||0}get maxSampleValue(){return this.get("MaxSampleValue")||Math.pow(2,this.bitsPerSample)-1}get xResolution(){return this.get("XResolution")}get yResolution(){return this.get("YResolution")}get planarConfiguration(){return this.get("PlanarConfiguration")||1}get resolutionUnit(){return this.get("ResolutionUnit")||2}get dateTime(){return this.get("DateTime")}get predictor(){return this.get("Predictor")||1}get sampleFormat(){return this.get("SampleFormat")||1}get sMinSampleValue(){return this.get("SMinSampleValue")||this.minSampleValue}get sMaxSampleValue(){return this.get("SMaxSampleValue")||this.maxSampleValue}get palette(){const t=2**this.bitsPerSample,e=this.get("ColorMap");if(!e)return;if(e.length!==3*t)throw new Error(`ColorMap size must be ${t}`);const r=[];for(let i=0;i<t;i++)r.push([e[i],e[i+t],e[i+2*t]]);return r}}function alwaysArray(t){return"number"==typeof t?[t]:t}function decompressZlib(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=inflate_1$2(e);return new DataView(r.buffer,r.byteOffset,r.byteLength)}const defaultOptions$c={ignoreImageData:!1,onlyFirst:!1};class TIFFDecoder extends IOBuffer$1{constructor(t){super(t),this._nextIFD=0}get isMultiPage(){let t=0;for(this.decodeHeader();this._nextIFD;)if(t++,this.decodeIFD({ignoreImageData:!0},!0),2===t)return!0;if(1===t)return!1;throw unsupported("ifdCount",t)}get pageCount(){let t=0;for(this.decodeHeader();this._nextIFD;)t++,this.decodeIFD({ignoreImageData:!0},!0);if(t>0)return t;throw unsupported("ifdCount",t)}decode(t={}){t=Object.assign({},defaultOptions$c,t);const e=[];for(this.decodeHeader();this._nextIFD;)if(e.push(this.decodeIFD(t,!0)),t.onlyFirst)return[e[0]];return e}decodeHeader(){const t=this.readUint16();if(18761===t)this.setLittleEndian();else{if(19789!==t)throw new Error(`invalid byte order: 0x${t.toString(16)}`);this.setBigEndian()}if(42!==this.readUint16())throw new Error("not a TIFF file");this._nextIFD=this.readUint32()}decodeIFD(t,e){let r;if(this.seek(this._nextIFD),e)r=new TiffIfd;else{if(!t.kind)throw new Error("kind is missing");r=new IFD(t.kind)}const i=this.readUint16();for(let t=0;t<i;t++)this.decodeIFDEntry(r);if(!t.ignoreImageData){if(!(r instanceof TiffIfd))throw new Error("must be a tiff ifd");this.decodeImageData(r)}return this._nextIFD=this.readUint32(),r}decodeIFDEntry(t){const e=this.offset,r=this.readUint16(),i=this.readUint16(),n=this.readUint32();if(i<1||i>12)return void this.skip(4);getByteLength(i,n)>4&&this.seek(this.readUint32());const s=readData(this,i,n);if(t.fields.set(r,s),34665===r||34853===r){let e=this.offset,i="exif";34665===r?i="exif":34853===r&&(i="gps"),this._nextIFD=s,t[i]=this.decodeIFD({kind:i,ignoreImageData:!0},!1),this.offset=e}this.seek(e),this.skip(12)}decodeImageData(t){const e=t.orientation;if(e&&1!==e)throw unsupported("orientation",e);switch(t.type){case 0:case 1:case 2:case 3:this.readStripData(t);break;default:throw unsupported("image type",t.type)}if(this.applyPredictor(t),this.convertAlpha(t),0===t.type){const e=t.bitsPerSample,r=Math.pow(2,e)-1;for(let e=0;e<t.data.length;e++)t.data[e]=r-t.data[e]}}readStripData(t){const e=t.width,r=t.height,i=t.bitsPerSample,n=t.sampleFormat,s=e*r*t.samplesPerPixel,a=getDataArray(s,i,n),o=t.rowsPerStrip*e*t.samplesPerPixel,h=t.stripOffsets,l=t.stripByteCounts;let c=s,u=0;for(let e=0;e<h.length;e++){let r=new DataView(this.buffer,h[e],l[e]),s=c>o?o:c;c-=s;let f=r;switch(t.compression){case 1:break;case 5:f=decompressLzw(r);break;case 8:f=decompressZlib(r);break;case 2:throw unsupported("Compression","CCITT Group 3");case 32773:throw unsupported("Compression","PackBits");default:throw unsupported("Compression",t.compression)}u=this.fillUncompressed(i,n,a,f,u,s)}t.data=a}fillUncompressed(t,e,r,i,n,s){if(8===t)return fill8bit(r,i,n,s);if(16===t)return fill16bit(r,i,n,s,this.isLittleEndian());if(32===t&&3===e)return fillFloat32(r,i,n,s,this.isLittleEndian());throw unsupported("bitDepth",t)}applyPredictor(t){const e=t.bitsPerSample;switch(t.predictor){case 1:break;case 2:if(8===e)applyHorizontalDifferencing8Bit(t.data,t.width,t.components);else{if(16!==e)throw new Error(`Horizontal differencing is only supported for images with a bit depth of ${e}`);applyHorizontalDifferencing16Bit(t.data,t.width,t.components)}break;default:throw new Error(`invalid predictor: ${t.predictor}`)}}convertAlpha(t){if(t.alpha&&t.associatedAlpha){const{data:e,components:r,maxSampleValue:i}=t;for(let t=0;t<e.length;t+=r){const n=e[t+r-1];for(let s=0;s<r-1;s++)e[t+s]=Math.round(e[t+s]*i/n)}}}}function getDataArray(t,e,r){if(8===e)return new Uint8Array(t);if(16===e)return new Uint16Array(t);if(32===e&&3===r)return new Float32Array(t);throw unsupported("bit depth / sample format",`${e} / ${r}`)}function fill8bit(t,e,r,i){for(let n=0;n<i;n++)t[r++]=e.getUint8(n);return r}function fill16bit(t,e,r,i,n){for(let s=0;s<2*i;s+=2)t[r++]=e.getUint16(s,n);return r}function fillFloat32(t,e,r,i,n){for(let s=0;s<4*i;s+=4)t[r++]=e.getFloat32(s,n);return r}function unsupported(t,e){return new Error(`Unsupported ${t}: ${e}`)}function decodeTIFF(t,e){return new TIFFDecoder(t).decode(e)}function matchAndCrop(t={}){let{algorithm:e="matchToPrevious",ignoreBorder:r=[0,0]}=t;this.checkProcessable("matchAndCrop",{bitDepth:[8,16]});let i="matchToPrevious"===e,n=this[0],s=[];s[0]={position:[0,0],image:this[0]};let a=[0,0];for(let t=1;t<this.length;t++){let e=n.getBestMatch(this[t],{border:r});s[t]={position:[e[0]+a[0],e[1]+a[1]],image:this[t]},i&&(a[0]+=e[0],a[1]+=e[1],n=this[t])}let o=0,h=0,l=0,c=0;for(let t=0;t<s.length;t++){let e=s[t];e.position[0]>o&&(o=e.position[0]),e.position[0]<h&&(h=e.position[0]),e.position[1]>l&&(l=e.position[1]),e.position[1]<c&&(c=e.position[1])}h=0-h,c=0-c;for(let t=0;t<s.length;t++){let e=s[t];e.crop=e.image.crop({x:o-e.position[0],y:l-e.position[1],width:n.width-h-o,height:n.height-c-l})}let u=[];for(let t=0;t<s.length;t++)u[t]=s[t].crop;return new Stack(u)}function min$2(){this.checkProcessable("min",{bitDepth:[8,16]});let t=this[0].min;for(let e=1;e<this.length;e++)for(let r=0;r<t.length;r++)t[r]=Math.min(t[r],this[e].min[r]);return t}function max$2(){this.checkProcessable("min",{bitDepth:[8,16]});let t=this[0].max;for(let e=1;e<this.length;e++)for(let r=0;r<t.length;r++)t[r]=Math.max(t[r],this[e].max[r]);return t}function median$2(t){let e=t.reduce(((t,e)=>t+e));if(0===e)throw new Error("unreachable");let r,i=0,n=0,s=e/2;for(;;){if(t[i]>0){if(void 0!==r)return(r+i)/2;if(n+=t[i],n>s)return i;n===s&&(r=i)}i++}}function mean$2(t){let e=0,r=0;for(let i=0;i<t.length;i++)e+=t[i],r+=t[i]*i;return 0===e?0:r/e}function median$1(){this.checkProcessable("median",{bitDepth:[8,16]});let t=this.getHistograms({maxSlots:this[0].maxValue+1}),e=new Array(t.length);for(let r=0;r<t.length;r++){let i=t[r];e[r]=median$2(i)}return e}function histogram(t){this.checkProcessable("min",{bitDepth:[8,16]});let e=this[0].getHistogram(t);for(let r=1;r<this.length;r++){let i=this[r].getHistogram(t);for(let t=0;t<e.length;t++)e[t]+=i[t]}return e}function histograms(t){this.checkProcessable("min",{bitDepth:[8,16]});let e=this[0].getHistograms(t),r=e[0].length;for(let i=1;i<this.length;i++){let n=this[i].getHistograms(t);for(let t=0;t<e.length;t++)for(let i=0;i<r;i++)e[t][i]+=n[t][i]}return e}function averageImage(){this.checkProcessable("averageImage",{bitDepth:[8,16]});let t=new Uint32Array(this[0].data.length);for(let e=0;e<this.length;e++){let r=this[e];for(let e=0;e<this[0].data.length;e++)t[e]+=r.data[e]}let e=Image.createFrom(this[0]),r=e.data;for(let e=0;e<this[0].data.length;e++)r[e]=t[e]/this.length;return e}function maxImage(){this.checkProcessable("max",{bitDepth:[8,16]});let t=Image.createFrom(this[0]);t.data.fill(0);for(const e of this)for(let r=0;r<t.data.length;r++)t.data[r]=Math.max(e.data[r],t.data[r]);return t}function minImage(){this.checkProcessable("max",{bitDepth:[8,16]});let t=Image.createFrom(this[0]);t.data.fill(t.maxValue);for(const e of this)for(let r=0;r<t.data.length;r++)t.data[r]=Math.min(e.data[r],t.data[r]);return t}function extend$2(t){t.extendMethod("matchAndCrop",matchAndCrop),t.extendMethod("getMin",min$2),t.extendMethod("getMax",max$2),t.extendMethod("getMedian",median$1),t.extendMethod("getHistogram",histogram),t.extendMethod("getHistograms",histograms),t.extendMethod("getAverage",averageImage),t.extendMethod("getAverageImage",averageImage),t.extendMethod("getMaxImage",maxImage),t.extendMethod("getMinImage",minImage)}let computedPropertyDescriptor={configurable:!0,enumerable:!1,get:void 0};class Stack extends Array{constructor(t){if(Array.isArray(t)){super(t.length);for(let e=0;e<t.length;e++)this[e]=t[e]}else"number"==typeof t?super(t):super();this.computed=null}static load(t){return Promise.all(t.map(Image.load)).then((t=>new Stack(t)))}static extendMethod(t,e,r={}){let{inPlace:i=!1,returnThis:n=!0,partialArgs:s=[]}=r;return Stack.prototype[t]=i?function(...t){this.computed=null;let r=e.apply(this,[...s,...t]);return n?this:r}:function(...t){return e.apply(this,[...s,...t])},Stack}static extendProperty(t,e,r={}){let{partialArgs:i=[]}=r;return computedPropertyDescriptor.get=function(){if(null===this.computed)this.computed={};else if(_hasOwn_1_0_1_hasOwn(t,this.computed))return this.computed[t];let r=e.apply(this,i);return this.computed[t]=r,r},Object.defineProperty(Stack.prototype,t,computedPropertyDescriptor),Stack}checkProcessable(t,e={}){if("string"!=typeof t)throw new TypeError("checkProcessable requires as first parameter the processName (a string)");if(0===this.size)throw new TypeError(`The process: ${t} can not be applied on an empty stack`);this[0].checkProcessable(t,e);for(let r=1;r<this.length;r++){if((void 0===e.sameSize||e.sameSize)&&this[0].width!==this[r].width)throw new TypeError(`The process: ${t} can not be applied if width is not identical in all images`);if((void 0===e.sameSize||e.sameSize)&&this[0].height!==this[r].height)throw new TypeError(`The process: ${t} can not be applied if height is not identical in all images`);if((void 0===e.sameAlpha||e.sameAlpha)&&this[0].alpha!==this[r].alpha)throw new TypeError(`The process: ${t} can not be applied if alpha is not identical in all images`);if((void 0===e.sameBitDepth||e.sameBitDepth)&&this[0].bitDepth!==this[r].bitDepth)throw new TypeError(`The process: ${t} can not be applied if bitDepth is not identical in all images`);if((void 0===e.sameColorModel||e.sameColorModel)&&this[0].colorModel!==this[r].colorModel)throw new TypeError(`The process: ${t} can not be applied if colorModel is not identical in all images`);if((void 0===e.sameNumberChannels||e.sameNumberChannels)&&this[0].channels!==this[r].channels)throw new TypeError(`The process: ${t} can not be applied if channels is not identical in all images`)}}}Array[Symbol.species]||(Stack.prototype.map=function(t,e){if("function"!=typeof t)throw new TypeError(`${t} is not a function`);let r=new Stack(this.length);for(let i=0;i<this.length;i++)r[i]=t.call(e,this[i],i,this);return r}),extend$2(Stack);const isDataURL=/^data:[a-z]+\/(?:[a-z]+);base64,/;function load(t,e){if("string"==typeof t)return loadURL(t,e);if(t instanceof ArrayBuffer)return Promise.resolve(loadBinary(new Uint8Array(t)));if(t.buffer)return Promise.resolve(loadBinary(t));throw new Error('argument to "load" must be a string or buffer.')}function loadBinary(t,e){const r=_imageType_4_1_0_imageType(t);if(r)switch(r.mime){case"image/png":return loadPNG(t);case"image/jpeg":return loadJPEG(t);case"image/tiff":return loadTIFF(t);default:return loadGeneric(i(r.mime))}return loadGeneric(i("application/octet-stream"));function i(r){return e||toBase64URL(t,r)}}function loadURL(t,e){const r=t.slice(0,64).match(isDataURL);let i;return i=null!==r?Promise.resolve(decode$4(t.slice(r[0].length))):fetchBinary(t,e),i.then((e=>loadBinary(new Uint8Array(e),r?t:void 0)))}function loadPNG(t){const e=decodePNG(t);let r,i=e.channels,n=0;return 2===i||4===i?(r=i-1,n=1):r=i,e.palette?loadPNGFromPalette(e):new Image(e.width,e.height,e.data,{components:r,alpha:n,bitDepth:e.depth})}function loadPNGFromPalette(t){const e=t.width*t.height,r=t.palette[0].length,i=new Uint8Array(e*r),n=8/t.depth,s=t.depth<8?n:1,a=parseInt("1".repeat(t.depth),2),o=4===r;let h=0;for(let r=0;r<e;r++){const e=Math.floor(r/s);let l=t.data[e];t.depth<8&&(l=l>>>t.depth*(n-1-r%n)&a);const c=t.palette[l];i[h++]=c[0],i[h++]=c[1],i[h++]=c[2],o&&(i[h++]=c[3])}return new Image(t.width,t.height,i,{components:3,alpha:o,bitDepth:8})}function loadJPEG(t){const e=decode(t);let r;e.exif&&(r=getMetadata(e.exif));const i=_jpegJs_0_4_3_jpegJs.decode(t,{useTArray:!0,maxMemoryUsageInMB:1024});return new Image(i.width,i.height,i.data,{meta:r})}function loadTIFF(t){let e=decodeTIFF(t);return 1===e.length?getImageFromIFD(e[0]):new Stack(e.map(getImageFromIFD))}function getMetadata(t){const e={tiff:{fields:t.fields,tags:t.map}};return t.exif&&(e.exif=t.exif),t.gps&&(e.gps=t.gps),e}function getImageFromIFD(t){if(3===t.type){const e=new Uint16Array(3*t.width*t.height),r=t.palette;let i=0;for(let n=0;n<t.data.length;n++){const s=r[t.data[n]];e[i++]=s[0],e[i++]=s[1],e[i++]=s[2]}return new Image(t.width,t.height,e,{components:3,alpha:t.alpha,colorModel:RGB$1,bitDepth:16,meta:getMetadata(t)})}return new Image(t.width,t.height,t.data,{components:2===t.type?3:1,alpha:t.alpha,colorModel:2===t.type?RGB$1:GREY$1,bitDepth:t.bitsPerSample.length?t.bitsPerSample[0]:t.bitsPerSample,meta:getMetadata(t)})}function loadGeneric(t,e){return e=e||{},new Promise((function(r,i){let n=new DOMImage;n.onload=function(){let t=n.width,i=n.height,s=createCanvas(t,i).getContext("2d");s.drawImage(n,0,0,t,i);let a=s.getImageData(0,0,t,i).data;r(new Image(t,i,a,e))},n.onerror=function(){i(new Error(`Could not load ${t}`))},n.src=t}))}const valueMethods={getValueXY(t,e,r){return this.data[(e*this.width+t)*this.channels+r]},setValueXY(t,e,r,i){return this.data[(e*this.width+t)*this.channels+r]=i,this.computed=null,this},getValue(t,e){return this.data[t*this.channels+e]},setValue(t,e,r){return this.data[t*this.channels+e]=r,this.computed=null,this},getPixelXY(t,e){return this.getPixel(e*this.width+t)},setPixelXY(t,e,r){return this.setPixel(e*this.width+t,r)},getPixel(t){const e=new Array(this.channels),r=t*this.channels;for(let t=0;t<this.channels;t++)e[t]=this.data[r+t];return e},setPixel(t,e){const r=t*this.channels;for(let t=0;t<e.length;t++)this.data[r+t]=e[t];return this.computed=null,this}};function setValueMethods(t){for(const e in valueMethods)t.prototype[e]=valueMethods[e]}function getImageParameters(t){return{width:t.width,height:t.height,components:t.components,alpha:t.alpha,colorModel:t.colorModel,bitDepth:t.bitDepth}}function getOutputImage(t,e,r,i={}){const{out:n}=e;if(void 0===n)return i.copy?t.clone():Image.createFrom(t,r);{if(!Image.isImage(n))throw new TypeError("out must be an Image object");const e=Object.assign(getImageParameters(t),r);for(const t in e)if(n[t]!==e[t])throw new RangeError(`cannot use out. Its ${t} must be "${e[t]}" (found "${n[t]}")`);return n}}function getOutputImageOrInPlace(t,e,r){if(void 0!==e.inPlace&&"boolean"!=typeof e.inPlace)throw new TypeError("inPlace option must be a boolean");if(e.inPlace){if(void 0!==e.out)throw new TypeError("out option must not be set if inPlace option is true");return t}return getOutputImage(t,e,null,r)}function abs(t={}){this.checkProcessable("abs",{bitDepth:[32]});const e=getOutputImageOrInPlace(this,t);return absolute(this,e),e}function absolute(t,e){for(let r=0;r<t.data.length;r++)e.data[r]=Math.abs(t.data[r])}function copyAlphaChannel(t,e){if(1===t.alpha&&1===e.alpha)for(let r=0;r<t.size;r++)e.data[r*e.channels+e.components]=t.data[r*t.channels+t.components]}function invert(t={}){this.checkProcessable("invert",{bitDepth:[1,8,16]});const e=getOutputImageOrInPlace(this,t);return 1===this.bitDepth?invertBinary(this,e):(invertColor(this,e),this!==e&&copyAlphaChannel(this,e)),e}function invertBinary(t,e){for(let r=0;r<t.data.length;r++)e.data[r]=~t.data[r]}function invertColor(t,e){for(let r=0;r<t.data.length;r+=t.channels)for(let i=0;i<t.components;i++)e.data[r+i]=t.maxValue-t.data[r+i]}function flipX(){this.checkProcessable("flipX",{bitDepth:[8,16]});for(let t=0;t<this.height;t++){let e=t*this.width*this.channels;for(let t=0;t<Math.floor(this.width/2);t++){let r=t*this.channels+e,i=(this.width-t-1)*this.channels+e;for(let t=0;t<this.channels;t++){let e=this.data[r+t];this.data[r+t]=this.data[i+t],this.data[i+t]=e}}}return this}function flipY(){this.checkProcessable("flipY",{bitDepth:[8,16]});for(let t=0;t<Math.floor(this.height/2);t++)for(let e=0;e<this.width;e++){let r=e*this.channels+t*this.width*this.channels,i=e*this.channels+(this.height-1-t)*this.channels*this.width;for(let t=0;t<this.channels;t++){let e=this.data[r+t];this.data[r+t]=this.data[i+t],this.data[i+t]=e}}return this}function blurFilter(t={}){const{radius:e=1}=t;if(e<1)throw new Error("radius must be greater than 1");const r=2*e+1,i=new Array(r);for(let t=0;t<r;t++){i[t]=new Array(r);for(let e=0;e<r;e++)i[t][e]=1/(r*r)}return this.convolution(i)}var medianQuickselect_min=createCommonjsModule((function(t){!function(){function e(t){for(var e=0,n=t.length-1,s=void 0,a=void 0,o=void 0,h=i(e,n);;){if(n<=e)return t[h];if(n==e+1)return t[e]>t[n]&&r(t,e,n),t[h];for(t[s=i(e,n)]>t[n]&&r(t,s,n),t[e]>t[n]&&r(t,e,n),t[s]>t[e]&&r(t,s,e),r(t,s,e+1),a=e+1,o=n;;){do{a++}while(t[e]>t[a]);do{o--}while(t[o]>t[e]);if(o<a)break;r(t,a,o)}r(t,e,o),o<=h&&(e=a),o>=h&&(n=o-1)}}var r=function(t,e,r){var i;return i=[t[r],t[e]],t[e]=i[0],t[r]=i[1],i},i=function(t,e){return~~((t+e)/2)};t.exports?t.exports=e:window.median=e}()}));function validateArrayOfChannels(t,e={}){let{channels:r,allowAlpha:i,defaultAlpha:n}=e;return"boolean"!=typeof i&&(i=!0),void 0===r?allChannels(t,n):validateChannels(t,r,i)}function allChannels(t,e){let r=e?t.channels:t.components,i=new Array(r);for(let t=0;t<r;t++)i[t]=t;return i}function validateChannels(t,e,r){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)e[i]=validateChannel(t,e[i],r);return e}function validateChannel(t,e,r=!0){if(void 0===e)throw new RangeError(`validateChannel : the channel has to be >=0 and <${t.channels}`);if("string"==typeof e){switch(t.colorModel){case GREY$1:break;case RGB$1:if("rgb".includes(e))switch(e){case"r":e=0;break;case"g":e=1;break;case"b":e=2}break;case HSL:if("hsl".includes(e))switch(e){case"h":e=0;break;case"s":e=1;break;case"l":e=2}break;case HSV:if("hsv".includes(e))switch(e){case"h":e=0;break;case"s":e=1;break;case"v":e=2}break;case CMYK$1:if("cmyk".includes(e))switch(e){case"c":e=0;break;case"m":e=1;break;case"y":e=2;break;case"k":e=3}break;default:throw new Error(`Unexpected color model: ${t.colorModel}`)}if("a"===e){if(!t.alpha)throw new Error("validateChannel : the image does not contain alpha channel");e=t.components}if("string"==typeof e)throw new Error(`validateChannel : undefined channel: ${e}`)}if(e>=t.channels)throw new RangeError(`validateChannel : the channel has to be >=0 and <${t.channels}`);if(!r&&e>=t.components)throw new RangeError("validateChannel : alpha channel may not be selected");return e}function medianFilter(t={}){let{radius:e=1,border:r="copy",channels:i}=t;if(this.checkProcessable("medianFilter",{bitDepth:[8,16]}),e<1)throw new Error("radius must be greater than 0");i=validateArrayOfChannels(this,i);let n=e,s=e,a=Image.createFrom(this),o=new Array((2*n+1)*(2*s+1));for(let t=0;t<i.length;t++){let e=i[t];for(let t=s;t<this.height-s;t++)for(let r=n;r<this.width-n;r++){let i=0;for(let a=-s;a<=s;a++)for(let s=-n;s<=n;s++){let n=((t+a)*this.width+r+s)*this.channels+e;o[i++]=this.data[n]}let h=(t*this.width+r)*this.channels+e;a.data[h]=medianQuickselect_min(o)}}if(this.alpha&&!i.includes(this.channels))for(let t=this.components;t<this.data.length;t+=this.channels)a.data[t]=this.data[t];return a.setBorder({size:[n,s],algorithm:r}),a}function gaussianFilter(t={}){let{radius:e=1,sigma:r,channels:i,border:n="copy"}=t;this.checkProcessable("gaussian",{bitDepth:[8,16]});const s=getKernel(e,r);return this.convolution([s,s],{border:n,channels:i,algorithm:"separable"})}function getKernel(t,e){const r=2*t+1,i=new Array(r),n=e||.3*(.5*(r-1)-1)+.8,s=-.5/(n*n);let a=0;for(let e=0;e<r;e++){const r=e-t,n=Math.exp(s*r*r);i[e]=n,a+=n}for(let t=0;t<r;t++)i[t]/=a;return i}const DISCRETE_LAPLACE_4=[[0,1,0],[1,-4,1],[0,1,0]],DISCRETE_LAPLACE_8=[[1,1,1],[1,-8,1],[1,1,1]],SOBEL_X=[[-1,0,1],[-2,0,2],[-1,0,1]],SOBEL_Y=[[-1,-2,-1],[0,0,0],[1,2,1]],SCHARR_X=[[3,0,-3],[10,0,-10],[3,0,-3]],SCHARR_Y=[[3,10,3],[0,0,0],[-3,-10,-3]],SECOND_DERIVATIVE=[[-1,-2,0,2,1],[-2,-4,0,4,2],[0,0,0,0,0],[1,2,0,-2,-1],[2,4,0,-4,-2]],SECOND_DERIVATIVE_INV=[[1,2,0,-2,-1],[2,4,0,-4,-2],[0,0,0,0,0],[-2,-4,0,4,2],[-1,-2,0,2,1]];var fftlib=createCommonjsModule((function(t,e){(function(){var t,r="0.3.0",i="2013-03";(t=e).toString=function(){return"version "+r+", released "+i};for(var n=0,s=null,a=null,o={init:function(t){if(0===t||0!=(t&t-1))throw new Error("init: radix-2 required");n=t,o._initArray(),o._makeBitReversalTable(),o._makeCosSinTable()},fft1d:function(t,e){o.fft(t,e,1)},ifft1d:function(t,e){var r=1/n;o.fft(t,e,-1);for(var i=0;i<n;i++)t[i]*=r,e[i]*=r},bt1d:function(t,e){o.fft(t,e,-1)},fft2d:function(t,e){for(var r=[],i=[],s=0,a=0;a<n;a++){s=a*n;for(var h=0;h<n;h++)r[h]=t[h+s],i[h]=e[h+s];o.fft1d(r,i);for(var l=0;l<n;l++)t[l+s]=r[l],e[l+s]=i[l]}for(var c=0;c<n;c++){for(var u=0;u<n;u++)s=c+u*n,r[u]=t[s],i[u]=e[s];o.fft1d(r,i);for(var f=0;f<n;f++)t[s=c+f*n]=r[f],e[s]=i[f]}},ifft2d:function(t,e){for(var r=[],i=[],s=0,a=0;a<n;a++){s=a*n;for(var h=0;h<n;h++)r[h]=t[h+s],i[h]=e[h+s];o.ifft1d(r,i);for(var l=0;l<n;l++)t[l+s]=r[l],e[l+s]=i[l]}for(var c=0;c<n;c++){for(var u=0;u<n;u++)s=c+u*n,r[u]=t[s],i[u]=e[s];o.ifft1d(r,i);for(var f=0;f<n;f++)t[s=c+f*n]=r[f],e[s]=i[f]}},fft:function(t,e,r){for(var i,o,h,l,c,u,f,d,m,g=n>>2,p=0;p<n;p++)p<(l=s[p])&&(c=t[p],t[p]=t[l],t[l]=c,c=e[p],e[p]=e[l],e[l]=c);for(var w=1;w<n;w<<=1){o=0,i=n/(w<<1);for(var _=0;_<w;_++){u=a[o+g],f=r*a[o];for(var b=_;b<n;b+=w<<1)d=u*t[h=b+w]+f*e[h],m=u*e[h]-f*t[h],t[h]=t[b]-d,t[b]+=d,e[h]=e[b]-m,e[b]+=m;o+=i}}},_initArray:function(){s="undefined"!=typeof Uint32Array?new Uint32Array(n):[],a="undefined"!=typeof Float64Array?new Float64Array(1.25*n):[]},_paddingZero:function(){},_makeBitReversalTable:function(){var t=0,e=0,r=0;for(s[0]=0;++t<n;){for(r=n>>1;r<=e;)e-=r,r>>=1;e+=r,s[t]=e}},_makeCosSinTable:function(){var t=n>>1,e=n>>2,r=n>>3,i=t+e,s=Math.sin(Math.PI/n),o=2*s*s,h=Math.sqrt(o*(2-o)),l=a[e]=1,c=a[0]=0;s=2*o;for(var u=1;u<r;u++)o+=s*(l-=o),h-=s*(c+=h),a[u]=c,a[e-u]=l;0!==r&&(a[r]=Math.sqrt(.5));for(var f=0;f<e;f++)a[t-f]=a[f];for(var d=0;d<i;d++)a[d+t]=-a[d]}},h=["init","fft1d","ifft1d","fft2d","ifft2d"],l=0;l<h.length;l++)t[h[l]]=o[h[l]];return t.bt=o.bt1d,t.fft=o.fft1d,t.ifft=o.ifft1d,t}).call(commonjsGlobal)})),FFTUtils$2={DEBUG:!1,ifft2DArray:function(t,e,r){var i=new Array(e*r),n=e/2,s=2*(r-1);fftlib.init(n);for(var a={re:new Array(n),im:new Array(n)},o=0;o<r;o++){for(var h=n-1;h>=0;h--)a.re[h]=t[2*h*r+o],a.im[h]=t[(2*h+1)*r+o];fftlib.bt(a.re,a.im);for(h=n-1;h>=0;h--)i[2*h*r+o]=a.re[h],i[(2*h+1)*r+o]=a.im[h]}var l=new Array(n*s);fftlib.init(s);var c={re:new Array(s),im:new Array(s)},u=s*n;for(h=0;h<e;h+=2){c.re[0]=i[h*r],c.im[0]=i[(h+1)*r];for(o=1;o<r;o++)c.re[o]=i[h*r+o],c.im[o]=i[(h+1)*r+o],c.re[s-o]=i[h*r+o],c.im[s-o]=-i[(h+1)*r+o];fftlib.bt(c.re,c.im);var f=h/2*s;for(o=s-1;o>=0;o--)l[f+o]=c.re[o]/u}return l},fft2DArray:function(t,e,r,i){Object.assign({},{inplace:!0});var n=r/2+1,s=2*e,a=new Array(s*n);fftlib.init(r);for(var o,h,l,c,u,f={re:new Array(r),im:new Array(r)},d={re:new Array(r),im:new Array(r)},m={re:new Array(r),im:new Array(r)},g=0;g<e/2;g++){o=2*g*r,f.re=t.slice(o,o+r),o=(2*g+1)*r,f.im=t.slice(o,o+r),fftlib.fft1d(f.re,f.im),this.reconstructTwoRealFFT(f,d,m),h=4*g*n,l=(4*g+1)*n,c=(4*g+2)*n,u=(4*g+3)*n;for(var p=n-1;p>=0;p--)a[h+p]=d.re[p],a[l+p]=d.im[p],a[c+p]=m.re[p],a[u+p]=m.im[p]}d=null,m=null;var w=new Array(s*n);fftlib.init(e);for(var _={re:new Array(e),im:new Array(e)},b=n-1;b>=0;b--){for(g=e-1;g>=0;g--)_.re[g]=a[2*g*n+b],_.im[g]=a[(2*g+1)*n+b],isNaN(_.re[g])&&(_.re[g]=0),isNaN(_.im[g])&&(_.im[g]=0);fftlib.fft1d(_.re,_.im);for(g=e-1;g>=0;g--)w[2*g*n+b]=_.re[g],w[(2*g+1)*n+b]=_.im[g]}return w},reconstructTwoRealFFT:function(t,e,r){var i,n,s,a,o,h=t.re.length;e.re[0]=t.re[0],e.im[0]=0,r.re[0]=t.im[0],r.im[0]=0;for(var l=h/2;l>0;l--)o=h-l,i=.5*(t.re[l]-t.re[o]),n=.5*(t.re[l]+t.re[o]),s=.5*(t.im[l]-t.im[o]),a=.5*(t.im[l]+t.im[o]),e.re[l]=n,e.im[l]=s,e.re[o]=n,e.im[o]=-s,r.re[l]=a,r.im[l]=-i,r.re[o]=a,r.im[o]=i},convolute2DI:function(t,e,r,i){for(var n,s,a=0;a<r/2;a++)for(var o=0;o<i;o++)n=t[2*a*i+o]*e[2*a*i+o]-t[(2*a+1)*i+o]*e[(2*a+1)*i+o],s=t[2*a*i+o]*e[(2*a+1)*i+o]+t[(2*a+1)*i+o]*e[2*a*i+o],t[2*a*i+o]=n,t[(2*a+1)*i+o]=s},convolute:function(t,e,r,i,n){for(var s=new Array(i*r),a=0;a<r*i;a++)s[a]=t[a];s=this.fft2DArray(s,r,i);var o,h=e.length,l=e[0].length,c=new Array(i*r);for(a=0;a<i*r;a++)c[a]=0;for(var u=Math.floor((h-1)/2),f=Math.floor((l-1)/2),d=0;d<h;d++){o=(d-u+r)%r;for(var m=0;m<l;m++)c[o*i+(m-f+i)%i]=e[d][m]}c=this.fft2DArray(c,r,i);var g=2*r,p=i/2+1;return this.convolute2DI(s,c,g,p),this.ifft2DArray(s,g,p)},toRadix2:function(t,e,r){var i,n,s,a,o=r,h=e;if(0===r||0!=(r&r-1)){for(o=0;r>>++o!=0;);o=1<<o}if(0===e||0!=(e&e-1)){for(h=0;e>>++h!=0;);h=1<<h}if(h==e&&o==r)return{data:t,rows:e,cols:r};var l=new Array(h*o),c=Math.floor((h-e)/2)-e,u=Math.floor((o-r)/2)-r;for(i=0;i<h;i++)for(s=i*o,a=(i-c)%e*r,n=0;n<o;n++)l[s+n]=t[a+(n-u)%r];return{data:l,rows:h,cols:o}},crop:function(t,e,r,i,n,s){if(e==i&&r==n)return t;Object.assign({},s);var a,o,h,l,c=new Array(n*i),u=Math.floor((e-i)/2),f=Math.floor((r-n)/2);for(h=0;h<i;h++)for(a=h*n,o=(h+u)*r,l=0;l<n;l++)c[a+l]=t[o+(l+f)];return c}},FFTUtils_1=FFTUtils$2,FFTUtils$1=FFTUtils_1,FFT=fftlib,src$3={FFTUtils:FFTUtils$1,FFT:FFT},FFTUtils=src$3.FFTUtils;function convolutionFFT(t,e,r){var i,n,s=matrix2Array(t),a=s.data,o=Object.assign({normalize:!1,divisor:1,rows:s.rows,cols:s.cols},r);if(!o.rows||!o.cols)throw new Error("Invalid number of rows or columns "+i+" "+n);i=o.rows,n=o.cols;var h,l,c=o.divisor,u=e.length,f=e[0].length;if(o.normalize)for(c=0,h=0;h<u;h++)for(l=0;l<f;l++)c+=e[h][l];if(0===c)throw new RangeError("convolution: The divisor is equal to zero");var d=FFTUtils.toRadix2(a,i,n),m=FFTUtils.convolute(d.data,e,d.rows,d.cols);if(m=FFTUtils.crop(m,d.rows,d.cols,i,n),0!=c&&1!=c)for(h=0;h<m.length;h++)m[h]/=c;return m}function convolutionDirect(t,e,r){var i,n,s=matrix2Array(t),a=s.data,o=Object.assign({normalize:!1,divisor:1,rows:s.rows,cols:s.cols},r);if(!o.rows||!o.cols)throw new Error("Invalid number of rows or columns "+i+" "+n);i=o.rows,n=o.cols;var h,l,c,u,f,d,m=o.divisor,g=e.length,p=e[0].length;if(o.normalize)for(m=0,h=0;h<g;h++)for(l=0;l<p;l++)m+=e[h][l];if(0===m)throw new RangeError("convolution: The divisor is equal to zero");var w=new Array(i*n),_=Math.floor(g/2),b=Math.floor(p/2);for(u=0;u<i;u++)for(c=0;c<n;c++){for(f=0,l=0;l<g;l++)for(h=0;h<p;h++)d=e[g-l-1][p-h-1],f+=a[(u+l-_+i)%i*n+(c+h-b+n)%n]*d;w[u*n+c]=f/m}return w}function LoG(t,e,r){var i=1e3;r&&r.factor&&(i=r.factor);var n,s,a,o,h=new Array(e);i*=-1;var l=(e-1)/2,c=2*t*t;for(n=0;n<e;n++)for(h[n]=new Array(e),o=(n-l)*(n-l),s=0;s<e;s++)a=-((s-l)*(s-l)+o)/c,h[n][s]=Math.round(i*(1+a)*Math.exp(a));return h}function matrix2Array(t){var e,r,i=t;if("number"!=typeof t[0]){e=t.length,r=t[0].length,i=new Array(e*r);for(var n=0;n<e;n++)for(var s=0;s<r;s++)i[n*r+s]=t[n][s]}else{var a=Math.sqrt(t.length);Number.isInteger(a)&&(e=a,r=a)}return{data:i,rows:e,cols:r}}var src$2={fft:convolutionFFT,direct:convolutionDirect,kernelFactory:{LoG:LoG},matrix2Array:matrix2Array},_isFinite_1_1_0_isFinite=Number.isFinite||function(t){return!("number"!=typeof t||t!=t||t===1/0||t===-1/0)},_isInteger_1_0_7_isInteger=Number.isInteger||function(t){return"number"==typeof t&&_isFinite_1_1_0_isFinite(t)&&Math.floor(t)===t};function validateKernel(t){let e,r;if(!Array.isArray(t))throw new Error(`validateKernel: Invalid Kernel: ${t}`);if(Array.isArray(t[0])){if(0==(1&t.length)||0==(1&t[0].length))throw new RangeError("validateKernel: Kernel rows and columns should be odd numbers");e=Math.floor(t.length/2),r=Math.floor(t[0].length/2)}else{let i=Math.sqrt(t.length);if(!_isInteger_1_0_7_isInteger(i))throw new RangeError("validateKernel: Kernel array should be a square");r=e=Math.floor(Math.sqrt(t.length)/2);let n=new Array(i);for(let e=0;e<i;e++){n[e]=new Array(i);for(let r=0;r<i;r++)n[e][r]=t[e*i+r]}t=n}return{kernel:t,kWidth:r,kHeight:e}}function clamp(t,e){return Math.round(Math.min(Math.max(t,0),e.maxValue))}function directConvolution(t,e,r){if(void 0===r){const i=t.length+e.length-1;r=new Array(i)}fill(r);for(var i=0;i<t.length;i++)for(var n=0;n<e.length;n++)r[i+n]+=t[i]*e[n];return r}function fill(t){for(var e=0;e<t.length;e++)t[e]=0}function convolutionSeparable(t,e,r,i){const n=new Array(t.length);let s,a,o,h;h=e[1],o=(h.length-1)/2,a=new Array(r+h.length-1),s=new Array(r);for(let e=0;e<i;e++){for(let i=0;i<r;i++)s[i]=t[e*r+i];directConvolution(s,h,a);for(let t=0;t<r;t++)n[e*r+t]=a[o+t]}h=e[0],o=(h.length-1)/2,a=new Array(i+h.length-1),s=new Array(i);for(let t=0;t<r;t++){for(let e=0;e<i;e++)s[e]=n[e*r+t];directConvolution(s,h,a);for(let e=0;e<i;e++)n[e*r+t]=a[o+e]}return n}const toString$1=Object.prototype.toString;function isAnyArray(t){return toString$1.call(t).endsWith("Array]")}function max$1(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!isAnyArray(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,i=void 0===r?0:r,n=e.toIndex,s=void 0===n?t.length:n;if(i<0||i>=t.length||!Number.isInteger(i))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=i||s>t.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=t[i],o=i+1;o<s;o++)t[o]>a&&(a=t[o]);return a}function min$1(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!isAnyArray(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,i=void 0===r?0:r,n=e.toIndex,s=void 0===n?t.length:n;if(i<0||i>=t.length||!Number.isInteger(i))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=i||s>t.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=t[i],o=i+1;o<s;o++)t[o]<a&&(a=t[o]);return a}function rescale(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!isAnyArray(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!isAnyArray(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var i=min$1(t),n=max$1(t);if(i===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var s=r.min,a=void 0===s?r.autoMinMax?i:0:s,o=r.max,h=void 0===o?r.autoMinMax?n:1:o;if(a>=h)throw new RangeError("min option must be smaller than max option");for(var l=(h-a)/(n-i),c=0;c<t.length;c++)e[c]=(t[c]-i)*l+a;return e}const indent=" ".repeat(2),indentData=" ".repeat(4);function inspectMatrix(){return inspectMatrixWithOptions(this)}function inspectMatrixWithOptions(t,e={}){const{maxRows:r=15,maxColumns:i=10,maxNumSize:n=8}=e;return`${t.constructor.name} {\n${indent}[\n${indentData}${inspectData(t,r,i,n)}\n${indent}]\n${indent}rows: ${t.rows}\n${indent}columns: ${t.columns}\n}`}function inspectData(t,e,r,i){const{rows:n,columns:s}=t,a=Math.min(n,e),o=Math.min(s,r),h=[];for(let e=0;e<a;e++){let r=[];for(let n=0;n<o;n++)r.push(formatNumber(t.get(e,n),i));h.push(`${r.join(" ")}`)}return o!==s&&(h[h.length-1]+=` ... ${s-r} more columns`),a!==n&&h.push(`... ${n-e} more rows`),h.join(`\n${indentData}`)}function formatNumber(t,e){const r=String(t);if(r.length<=e)return r.padEnd(e," ");const i=t.toPrecision(e-2);if(i.length<=e)return i;const n=t.toExponential(e-2),s=n.indexOf("e"),a=n.slice(s);return n.slice(0,e-a.length)+a}function installMathOperations(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}function checkRowIndex(t,e,r){let i=r?t.rows:t.rows-1;if(e<0||e>i)throw new RangeError("Row index out of range")}function checkColumnIndex(t,e,r){let i=r?t.columns:t.columns-1;if(e<0||e>i)throw new RangeError("Column index out of range")}function checkRowVector(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function checkColumnVector(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function checkIndices(t,e,r){return{row:checkRowIndices(t,e),column:checkColumnIndices(t,r)}}function checkRowIndices(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkColumnIndices(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");if(e.some((e=>e<0||e>=t.columns)))throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkRange(t,e,r,i,n){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(checkNumber("startRow",e),checkNumber("endRow",r),checkNumber("startColumn",i),checkNumber("endColumn",n),e>r||i>n||e<0||e>=t.rows||r<0||r>=t.rows||i<0||i>=t.columns||n<0||n>=t.columns)throw new RangeError("Submatrix indices are out of range")}function newArray$1(t,e=0){let r=[];for(let i=0;i<t;i++)r.push(e);return r}function checkNumber(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function checkNonEmpty(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}function sumByRow(t){let e=newArray$1(t.rows);for(let r=0;r<t.rows;++r)for(let i=0;i<t.columns;++i)e[r]+=t.get(r,i);return e}function sumByColumn(t){let e=newArray$1(t.columns);for(let r=0;r<t.rows;++r)for(let i=0;i<t.columns;++i)e[i]+=t.get(r,i);return e}function sumAll(t){let e=0;for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)e+=t.get(r,i);return e}function productByRow(t){let e=newArray$1(t.rows,1);for(let r=0;r<t.rows;++r)for(let i=0;i<t.columns;++i)e[r]*=t.get(r,i);return e}function productByColumn(t){let e=newArray$1(t.columns,1);for(let r=0;r<t.rows;++r)for(let i=0;i<t.columns;++i)e[i]*=t.get(r,i);return e}function productAll(t){let e=1;for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)e*=t.get(r,i);return e}function varianceByRow(t,e,r){const i=t.rows,n=t.columns,s=[];for(let a=0;a<i;a++){let i=0,o=0,h=0;for(let e=0;e<n;e++)h=t.get(a,e)-r[a],i+=h,o+=h*h;e?s.push((o-i*i/n)/(n-1)):s.push((o-i*i/n)/n)}return s}function varianceByColumn(t,e,r){const i=t.rows,n=t.columns,s=[];for(let a=0;a<n;a++){let n=0,o=0,h=0;for(let e=0;e<i;e++)h=t.get(e,a)-r[a],n+=h,o+=h*h;e?s.push((o-n*n/i)/(i-1)):s.push((o-n*n/i)/i)}return s}function varianceAll(t,e,r){const i=t.rows,n=t.columns,s=i*n;let a=0,o=0,h=0;for(let e=0;e<i;e++)for(let i=0;i<n;i++)h=t.get(e,i)-r,a+=h,o+=h*h;return e?(o-a*a/s)/(s-1):(o-a*a/s)/s}function centerByRow(t,e){for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)t.set(r,i,t.get(r,i)-e[r])}function centerByColumn(t,e){for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)t.set(r,i,t.get(r,i)-e[i])}function centerAll(t,e){for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)t.set(r,i,t.get(r,i)-e)}function getScaleByRow(t){const e=[];for(let r=0;r<t.rows;r++){let i=0;for(let e=0;e<t.columns;e++)i+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(i))}return e}function scaleByRow(t,e){for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)t.set(r,i,t.get(r,i)/e[r])}function getScaleByColumn(t){const e=[];for(let r=0;r<t.columns;r++){let i=0;for(let e=0;e<t.rows;e++)i+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(i))}return e}function scaleByColumn(t,e){for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)t.set(r,i,t.get(r,i)/e[i])}function getScaleAll(t){const e=t.size-1;let r=0;for(let i=0;i<t.columns;i++)for(let n=0;n<t.rows;n++)r+=Math.pow(t.get(n,i),2)/e;return Math.sqrt(r)}function scaleAll(t,e){for(let r=0;r<t.rows;r++)for(let i=0;i<t.columns;i++)t.set(r,i,t.get(r,i)/e)}class AbstractMatrix{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let i=new Matrix$2(t,e);for(let n=0;n<t;n++)for(let t=0;t<e;t++)i.set(n,t,r[n*e+t]);return i}static rowVector(t){let e=new Matrix$2(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new Matrix$2(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new Matrix$2(t,e)}static ones(t,e){return new Matrix$2(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:i=Math.random}=r;let n=new Matrix$2(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)n.set(r,t,i());return n}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:i=0,max:n=1e3,random:s=Math.random}=r;if(!Number.isInteger(i))throw new TypeError("min must be an integer");if(!Number.isInteger(n))throw new TypeError("max must be an integer");if(i>=n)throw new RangeError("min must be smaller than max");let a=n-i,o=new Matrix$2(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=i+Math.round(s()*a);o.set(r,t,e)}return o}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let i=Math.min(t,e),n=this.zeros(t,e);for(let t=0;t<i;t++)n.set(t,t,r);return n}static diag(t,e,r){let i=t.length;void 0===e&&(e=i),void 0===r&&(r=e);let n=Math.min(i,e,r),s=this.zeros(e,r);for(let e=0;e<n;e++)s.set(e,e,t[e]);return s}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,i=t.columns,n=new Matrix$2(r,i);for(let s=0;s<r;s++)for(let r=0;r<i;r++)n.set(s,r,Math.min(t.get(s,r),e.get(s,r)));return n}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,i=t.columns,n=new this(r,i);for(let s=0;s<r;s++)for(let r=0;r<i;r++)n.set(s,r,Math.max(t.get(s,r),e.get(s,r)));return n}static checkMatrix(t){return AbstractMatrix.isMatrix(t)?t:new Matrix$2(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,i=!0,n=!1;for(;t<this.rows&&i;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(i=!1,n=!0);t++}return i}isReducedEchelonForm(){let t=0,e=0,r=-1,i=!0,n=!1;for(;t<this.rows&&i;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(i=!1,n=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(i=!1);t++}return i}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let i=e;for(let n=e;n<t.rows;n++)t.get(n,r)>t.get(i,r)&&(i=n);if(0===t.get(i,r))r++;else{t.swapRows(e,i);let n=t.get(e,r);for(let i=r;i<t.columns;i++)t.set(e,i,t.get(e,i)/n);for(let i=e+1;i<t.rows;i++){let n=t.get(i,r)/t.get(e,r);t.set(i,r,0);for(let s=r+1;s<t.columns;s++)t.set(i,s,t.get(i,s)-t.get(e,s)*n)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,i=r-1;for(;i>=0;)if(0===t.maxRow(i))i--;else{let n=0,s=!1;for(;n<r&&!1===s;)1===t.get(i,n)?s=!0:n++;for(let r=0;r<i;r++){let s=t.get(r,n);for(let a=n;a<e;a++){let e=t.get(r,a)-s*t.get(i,a);t.set(r,a,e)}}i--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let i=new Matrix$2(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)i.setSubMatrix(this,this.rows*t,this.columns*e);return i}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){checkRowIndex(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Matrix$2.rowVector(this.getRow(t))}setRow(t,e){checkRowIndex(this,t),e=checkRowVector(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){checkRowIndex(this,t),checkRowIndex(this,e);for(let r=0;r<this.columns;r++){let i=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,i)}return this}getColumn(t){checkColumnIndex(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Matrix$2.columnVector(this.getColumn(t))}setColumn(t,e){checkColumnIndex(this,t),e=checkColumnVector(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){checkColumnIndex(this,t),checkColumnIndex(this,e);for(let r=0;r<this.rows;r++){let i=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,i)}return this}addRowVector(t){t=checkRowVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=checkRowVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=checkRowVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=checkRowVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=checkColumnVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=checkColumnVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=checkColumnVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=checkColumnVector(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){checkRowIndex(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){checkColumnIndex(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){if(this.isEmpty())return NaN;let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){checkNonEmpty(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let i=0;i<this.columns;i++)this.get(r,i)>t&&(t=this.get(r,i),e[0]=r,e[1]=i);return e}min(){if(this.isEmpty())return NaN;let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){checkNonEmpty(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let i=0;i<this.columns;i++)this.get(r,i)<t&&(t=this.get(r,i),e[0]=r,e[1]=i);return e}maxRow(t){if(checkRowIndex(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){checkRowIndex(this,t),checkNonEmpty(this);let e=this.get(t,0),r=[t,0];for(let i=1;i<this.columns;i++)this.get(t,i)>e&&(e=this.get(t,i),r[1]=i);return r}minRow(t){if(checkRowIndex(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){checkRowIndex(this,t),checkNonEmpty(this);let e=this.get(t,0),r=[t,0];for(let i=1;i<this.columns;i++)this.get(t,i)<e&&(e=this.get(t,i),r[1]=i);return r}maxColumn(t){if(checkColumnIndex(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){checkColumnIndex(this,t),checkNonEmpty(this);let e=this.get(0,t),r=[0,t];for(let i=1;i<this.rows;i++)this.get(i,t)>e&&(e=this.get(i,t),r[0]=i);return r}minColumn(t){if(checkColumnIndex(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){checkColumnIndex(this,t),checkNonEmpty(this);let e=this.get(0,t),r=[0,t];for(let i=1;i<this.rows;i++)this.get(i,t)<e&&(e=this.get(i,t),r[0]=i);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){AbstractMatrix.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let i=0;i<e.length;i++)r+=e[i]*t[i];return r}mmul(t){t=Matrix$2.checkMatrix(t);let e=this.rows,r=this.columns,i=t.columns,n=new Matrix$2(e,i),s=new Float64Array(r);for(let a=0;a<i;a++){for(let e=0;e<r;e++)s[e]=t.get(e,a);for(let t=0;t<e;t++){let e=0;for(let i=0;i<r;i++)e+=this.get(t,i)*s[i];n.set(t,a,e)}}return n}strassen2x2(t){t=Matrix$2.checkMatrix(t);let e=new Matrix$2(2,2);const r=this.get(0,0),i=t.get(0,0),n=this.get(0,1),s=t.get(0,1),a=this.get(1,0),o=t.get(1,0),h=this.get(1,1),l=t.get(1,1),c=(r+h)*(i+l),u=(a+h)*i,f=r*(s-l),d=h*(o-i),m=(r+n)*l,g=c+d-m+(n-h)*(o+l),p=f+m,w=u+d,_=c-u+f+(a-r)*(i+s);return e.set(0,0,g),e.set(0,1,p),e.set(1,0,w),e.set(1,1,_),e}strassen3x3(t){t=Matrix$2.checkMatrix(t);let e=new Matrix$2(3,3);const r=this.get(0,0),i=this.get(0,1),n=this.get(0,2),s=this.get(1,0),a=this.get(1,1),o=this.get(1,2),h=this.get(2,0),l=this.get(2,1),c=this.get(2,2),u=t.get(0,0),f=t.get(0,1),d=t.get(0,2),m=t.get(1,0),g=t.get(1,1),p=t.get(1,2),w=t.get(2,0),_=t.get(2,1),b=t.get(2,2),y=(r-s)*(-f+g),M=(-r+s+a)*(u-f+g),x=(s+a)*(-u+f),v=r*u,E=(-r+h+l)*(u-d+p),A=(-r+h)*(d-p),k=(h+l)*(-u+d),S=(-n+l+c)*(g+w-_),I=(n-c)*(g-_),D=n*w,R=(l+c)*(-w+_),T=(-n+a+o)*(p+w-b),C=(n-o)*(p-b),$=(a+o)*(-w+b),B=v+D+i*m,P=(r+i+n-s-a-l-c)*g+M+x+v+S+D+R,O=v+E+k+(r+i+n-a-o-h-l)*p+D+T+$,N=y+a*(-u+f+m-g-p-w+b)+M+v+D+T+C,L=y+M+x+v+o*_,F=D+T+C+$+s*d,U=v+E+A+l*(-u+d+m-g-p-w+_)+S+I+D,H=S+I+D+R+h*f,Y=v+E+A+k+c*b;return e.set(0,0,B),e.set(0,1,P),e.set(0,2,O),e.set(1,0,N),e.set(1,1,L),e.set(1,2,F),e.set(2,0,U),e.set(2,1,H),e.set(2,2,Y),e}mmulStrassen(t){t=Matrix$2.checkMatrix(t);let e=this.clone(),r=e.rows,i=e.columns,n=t.rows,s=t.columns;function a(t,e,r){let i=t.rows,n=t.columns;if(i===e&&n===r)return t;{let i=AbstractMatrix.zeros(e,r);return i=i.setSubMatrix(t,0,0),i}}i!==n&&console.warn(`Multiplying ${r} x ${i} and ${n} x ${s} matrix: dimensions do not match.`);let o=Math.max(r,n),h=Math.max(i,s);return e=a(e,o,h),function t(e,r,i,n){if(i<=512||n<=512)return e.mmul(r);i%2==1&&n%2==1?(e=a(e,i+1,n+1),r=a(r,i+1,n+1)):i%2==1?(e=a(e,i+1,n),r=a(r,i+1,n)):n%2==1&&(e=a(e,i,n+1),r=a(r,i,n+1));let s=parseInt(e.rows/2,10),o=parseInt(e.columns/2,10),h=e.subMatrix(0,s-1,0,o-1),l=r.subMatrix(0,s-1,0,o-1),c=e.subMatrix(0,s-1,o,e.columns-1),u=r.subMatrix(0,s-1,o,r.columns-1),f=e.subMatrix(s,e.rows-1,0,o-1),d=r.subMatrix(s,r.rows-1,0,o-1),m=e.subMatrix(s,e.rows-1,o,e.columns-1),g=r.subMatrix(s,r.rows-1,o,r.columns-1),p=t(AbstractMatrix.add(h,m),AbstractMatrix.add(l,g),s,o),w=t(AbstractMatrix.add(f,m),l,s,o),_=t(h,AbstractMatrix.sub(u,g),s,o),b=t(m,AbstractMatrix.sub(d,l),s,o),y=t(AbstractMatrix.add(h,c),g,s,o),M=t(AbstractMatrix.sub(f,h),AbstractMatrix.add(l,u),s,o),x=t(AbstractMatrix.sub(c,m),AbstractMatrix.add(d,g),s,o),v=AbstractMatrix.add(p,b);v.sub(y),v.add(x);let E=AbstractMatrix.add(_,y),A=AbstractMatrix.add(w,b),k=AbstractMatrix.sub(p,w);k.add(_),k.add(M);let S=AbstractMatrix.zeros(2*v.rows,2*v.columns);return S=S.setSubMatrix(v,0,0),S=S.setSubMatrix(E,v.rows,0),S=S.setSubMatrix(A,0,v.columns),S=S.setSubMatrix(k,v.rows,v.columns),S.subMatrix(0,i-1,0,n-1)}(e,t=a(t,o,h),o,h)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let i=new Matrix$2(this.rows,this.columns);for(let t=0;t<this.rows;t++){const n=this.getRow(t);n.length>0&&rescale(n,{min:e,max:r,output:n}),i.setRow(t,n)}return i}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let i=new Matrix$2(this.rows,this.columns);for(let t=0;t<this.columns;t++){const n=this.getColumn(t);n.length&&rescale(n,{min:e,max:r,output:n}),i.setColumn(t,n)}return i}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),i=this.get(e,this.columns-1-r);this.set(e,r,i),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),i=this.get(this.rows-1-r,e);this.set(r,e,i),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Matrix$2.checkMatrix(t);let e=this.rows,r=this.columns,i=t.rows,n=t.columns,s=new Matrix$2(e*i,r*n);for(let a=0;a<e;a++)for(let e=0;e<r;e++)for(let r=0;r<i;r++)for(let o=0;o<n;o++)s.set(i*a+r,n*e+o,this.get(a,e)*t.get(r,o));return s}kroneckerSum(t){if(t=Matrix$2.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,i=this.kroneckerProduct(Matrix$2.eye(r,r)),n=Matrix$2.eye(e,e).kroneckerProduct(t);return i.add(n)}transpose(){let t=new Matrix$2(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=compareNumbers){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=compareNumbers){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,i){checkRange(this,t,e,r,i);let n=new Matrix$2(e-t+1,i-r+1);for(let s=t;s<=e;s++)for(let e=r;e<=i;e++)n.set(s-t,e-r,this.get(s,e));return n}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let i=new Matrix$2(t.length,r-e+1);for(let n=0;n<t.length;n++)for(let s=e;s<=r;s++){if(t[n]<0||t[n]>=this.rows)throw new RangeError(`Row index out of range: ${t[n]}`);i.set(n,s-e,this.get(t[n],s))}return i}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let i=new Matrix$2(r-e+1,t.length);for(let n=0;n<t.length;n++)for(let s=e;s<=r;s++){if(t[n]<0||t[n]>=this.columns)throw new RangeError(`Column index out of range: ${t[n]}`);i.set(s-e,n,this.get(s,t[n]))}return i}setSubMatrix(t,e,r){if((t=Matrix$2.checkMatrix(t)).isEmpty())return this;checkRange(this,e,e+t.rows-1,r,r+t.columns-1);for(let i=0;i<t.rows;i++)for(let n=0;n<t.columns;n++)this.set(e+i,r+n,t.get(i,n));return this}selection(t,e){let r=checkIndices(this,t,e),i=new Matrix$2(t.length,e.length);for(let t=0;t<r.row.length;t++){let e=r.row[t];for(let n=0;n<r.column.length;n++){let s=r.column[n];i.set(t,n,this.get(e,s))}}return i}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Matrix$2(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return sumByRow(this);case"column":return sumByColumn(this);case void 0:return sumAll(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return productByRow(this);case"column":return productByColumn(this);case void 0:return productAll(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:i=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Array.isArray(i))throw new TypeError("mean must be an array");return varianceByRow(this,r,i);case"column":if(!Array.isArray(i))throw new TypeError("mean must be an array");return varianceByColumn(this,r,i);case void 0:if("number"!=typeof i)throw new TypeError("mean must be a number");return varianceAll(this,r,i);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Array.isArray(r))throw new TypeError("center must be an array");return centerByRow(this,r),this;case"column":if(!Array.isArray(r))throw new TypeError("center must be an array");return centerByColumn(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return centerAll(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=getScaleByRow(this);else if(!Array.isArray(r))throw new TypeError("scale must be an array");return scaleByRow(this,r),this;case"column":if(void 0===r)r=getScaleByColumn(this);else if(!Array.isArray(r))throw new TypeError("scale must be an array");return scaleByColumn(this,r),this;case void 0:if(void 0===r)r=getScaleAll(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return scaleAll(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return inspectMatrixWithOptions(this,t)}}function compareNumbers(t,e){return t-e}AbstractMatrix.prototype.klass="Matrix","undefined"!=typeof Symbol&&(AbstractMatrix.prototype[Symbol.for("nodejs.util.inspect.custom")]=inspectMatrix),AbstractMatrix.random=AbstractMatrix.rand,AbstractMatrix.randomInt=AbstractMatrix.randInt,AbstractMatrix.diagonal=AbstractMatrix.diag,AbstractMatrix.prototype.diagonal=AbstractMatrix.prototype.diag,AbstractMatrix.identity=AbstractMatrix.eye,AbstractMatrix.prototype.negate=AbstractMatrix.prototype.neg,AbstractMatrix.prototype.tensorProduct=AbstractMatrix.prototype.kroneckerProduct;class Matrix$2 extends AbstractMatrix{constructor(t,e){if(super(),Matrix$2.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let i=0;i<t;i++){if(r[i].length!==e)throw new RangeError("Inconsistent array dimensions");this.data.push(Float64Array.from(r[i]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return checkRowIndex(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),checkRowIndex(this,t,!0),e=Float64Array.from(checkRowVector(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){checkColumnIndex(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let i=0;i<t;i++)r[i]=this.data[e][i];for(let i=t+1;i<this.columns;i++)r[i-1]=this.data[e][i];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),checkColumnIndex(this,t,!0),e=checkColumnVector(this,e);for(let r=0;r<this.rows;r++){const i=new Float64Array(this.columns+1);let n=0;for(;n<t;n++)i[n]=this.data[r][n];for(i[n++]=e[r];n<this.columns+1;n++)i[n]=this.data[r][n-1];this.data[r]=i}return this.columns+=1,this}}installMathOperations(AbstractMatrix,Matrix$2);class BaseView extends AbstractMatrix{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class MatrixColumnView extends BaseView{constructor(t,e){checkColumnIndex(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class MatrixColumnSelectionView extends BaseView{constructor(t,e){e=checkColumnIndices(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class MatrixFlipColumnView extends BaseView{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}class MatrixFlipRowView extends BaseView{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class MatrixRowView extends BaseView{constructor(t,e){checkRowIndex(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class MatrixRowSelectionView extends BaseView{constructor(t,e){super(t,(e=checkRowIndices(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class MatrixSelectionView extends BaseView{constructor(t,e,r){let i=checkIndices(t,e,r);super(t,i.row.length,i.column.length),this.rowIndices=i.row,this.columnIndices=i.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class MatrixSubView extends BaseView{constructor(t,e,r,i,n){checkRange(t,e,r,i,n),super(t,r-e+1,n-i+1),this.startRow=e,this.startColumn=i}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class MatrixTransposeView$1 extends BaseView{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class WrapperMatrix1D extends AbstractMatrix{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let i=this._calculateIndex(t,e);return this.data[i]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class WrapperMatrix2D extends AbstractMatrix{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function wrap(t,e){if(Array.isArray(t))return t[0]&&Array.isArray(t[0])?new WrapperMatrix2D(t):new WrapperMatrix1D(t,e);throw new Error("the argument is not an array")}class LuDecomposition{constructor(t){let e,r,i,n,s,a,o,h,l,c=(t=WrapperMatrix2D.checkMatrix(t)).clone(),u=c.rows,f=c.columns,d=new Float64Array(u),m=1;for(e=0;e<u;e++)d[e]=e;for(h=new Float64Array(u),r=0;r<f;r++){for(e=0;e<u;e++)h[e]=c.get(e,r);for(e=0;e<u;e++){for(l=Math.min(e,r),s=0,i=0;i<l;i++)s+=c.get(e,i)*h[i];h[e]-=s,c.set(e,r,h[e])}for(n=r,e=r+1;e<u;e++)Math.abs(h[e])>Math.abs(h[n])&&(n=e);if(n!==r){for(i=0;i<f;i++)a=c.get(n,i),c.set(n,i,c.get(r,i)),c.set(r,i,a);o=d[n],d[n]=d[r],d[r]=o,m=-m}if(r<u&&0!==c.get(r,r))for(e=r+1;e<u;e++)c.set(e,r,c.get(e,r)/c.get(r,r))}this.LU=c,this.pivotVector=d,this.pivotSign=m}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(0===t.get(r,r))return!0;return!1}solve(t){t=Matrix$2.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let r,i,n,s=t.columns,a=t.subMatrixRow(this.pivotVector,0,s-1),o=e.columns;for(n=0;n<o;n++)for(r=n+1;r<o;r++)for(i=0;i<s;i++)a.set(r,i,a.get(r,i)-a.get(n,i)*e.get(r,n));for(n=o-1;n>=0;n--){for(i=0;i<s;i++)a.set(n,i,a.get(n,i)/e.get(n,n));for(r=0;r<n;r++)for(i=0;i<s;i++)a.set(r,i,a.get(r,i)-a.get(n,i)*e.get(r,n))}return a}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let i=0;i<r;i++)e*=t.get(i,i);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,i=new Matrix$2(e,r);for(let n=0;n<e;n++)for(let e=0;e<r;e++)n>e?i.set(n,e,t.get(n,e)):n===e?i.set(n,e,1):i.set(n,e,0);return i}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,i=new Matrix$2(e,r);for(let n=0;n<e;n++)for(let e=0;e<r;e++)n<=e?i.set(n,e,t.get(n,e)):i.set(n,e,0);return i}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function hypotenuse$1(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class QrDecomposition{constructor(t){let e,r,i,n,s=(t=WrapperMatrix2D.checkMatrix(t)).clone(),a=t.rows,o=t.columns,h=new Float64Array(o);for(i=0;i<o;i++){let t=0;for(e=i;e<a;e++)t=hypotenuse$1(t,s.get(e,i));if(0!==t){for(s.get(i,i)<0&&(t=-t),e=i;e<a;e++)s.set(e,i,s.get(e,i)/t);for(s.set(i,i,s.get(i,i)+1),r=i+1;r<o;r++){for(n=0,e=i;e<a;e++)n+=s.get(e,i)*s.get(e,r);for(n=-n/s.get(i,i),e=i;e<a;e++)s.set(e,r,s.get(e,r)+n*s.get(e,i))}}h[i]=-t}this.QR=s,this.Rdiag=h}solve(t){t=Matrix$2.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let i,n,s,a,o=t.columns,h=t.clone(),l=e.columns;for(s=0;s<l;s++)for(n=0;n<o;n++){for(a=0,i=s;i<r;i++)a+=e.get(i,s)*h.get(i,n);for(a=-a/e.get(s,s),i=s;i<r;i++)h.set(i,n,h.get(i,n)+a*e.get(i,s))}for(s=l-1;s>=0;s--){for(n=0;n<o;n++)h.set(s,n,h.get(s,n)/this.Rdiag[s]);for(i=0;i<s;i++)for(n=0;n<o;n++)h.set(i,n,h.get(i,n)-h.get(s,n)*e.get(i,s))}return h.subMatrix(0,l-1,0,o-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){let t,e,r=this.QR,i=r.columns,n=new Matrix$2(i,i);for(t=0;t<i;t++)for(e=0;e<i;e++)t<e?n.set(t,e,r.get(t,e)):t===e?n.set(t,e,this.Rdiag[t]):n.set(t,e,0);return n}get orthogonalMatrix(){let t,e,r,i,n=this.QR,s=n.rows,a=n.columns,o=new Matrix$2(s,a);for(r=a-1;r>=0;r--){for(t=0;t<s;t++)o.set(t,r,0);for(o.set(r,r,1),e=r;e<a;e++)if(0!==n.get(r,r)){for(i=0,t=r;t<s;t++)i+=n.get(t,r)*o.get(t,e);for(i=-i/n.get(r,r),t=r;t<s;t++)o.set(t,e,o.get(t,e)+i*n.get(t,r))}}return o}}class SingularValueDecomposition{constructor(t,e={}){if((t=WrapperMatrix2D.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,i=t.columns;const{computeLeftSingularVectors:n=!0,computeRightSingularVectors:s=!0,autoTranspose:a=!1}=e;let o,h=Boolean(n),l=Boolean(s),c=!1;if(r<i)if(a){o=t.transpose(),r=o.rows,i=o.columns,c=!0;let e=h;h=l,l=e}else o=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else o=t.clone();let u=Math.min(r,i),f=Math.min(r+1,i),d=new Float64Array(f),m=new Matrix$2(r,u),g=new Matrix$2(i,i),p=new Float64Array(i),w=new Float64Array(r),_=new Float64Array(f);for(let t=0;t<f;t++)_[t]=t;let b=Math.min(r-1,i),y=Math.max(0,Math.min(i-2,r)),M=Math.max(b,y);for(let t=0;t<M;t++){if(t<b){d[t]=0;for(let e=t;e<r;e++)d[t]=hypotenuse$1(d[t],o.get(e,t));if(0!==d[t]){o.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)o.set(e,t,o.get(e,t)/d[t]);o.set(t,t,o.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<i;e++){if(t<b&&0!==d[t]){let i=0;for(let n=t;n<r;n++)i+=o.get(n,t)*o.get(n,e);i=-i/o.get(t,t);for(let n=t;n<r;n++)o.set(n,e,o.get(n,e)+i*o.get(n,t))}p[e]=o.get(t,e)}if(h&&t<b)for(let e=t;e<r;e++)m.set(e,t,o.get(e,t));if(t<y){p[t]=0;for(let e=t+1;e<i;e++)p[t]=hypotenuse$1(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<i;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<i;r++)w[e]+=p[r]*o.get(e,r);for(let e=t+1;e<i;e++){let i=-p[e]/p[t+1];for(let n=t+1;n<r;n++)o.set(n,e,o.get(n,e)+i*w[n])}}if(l)for(let e=t+1;e<i;e++)g.set(e,t,p[e])}}let x=Math.min(i,r+1);if(b<i&&(d[b]=o.get(b,b)),r<x&&(d[x-1]=0),y+1<x&&(p[y]=o.get(y,x-1)),p[x-1]=0,h){for(let t=b;t<u;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=b-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<u;e++){let i=0;for(let n=t;n<r;n++)i+=m.get(n,t)*m.get(n,e);i=-i/m.get(t,t);for(let n=t;n<r;n++)m.set(n,e,m.get(n,e)+i*m.get(n,t))}for(let e=t;e<r;e++)m.set(e,t,-m.get(e,t));m.set(t,t,1+m.get(t,t));for(let e=0;e<t-1;e++)m.set(e,t,0)}else{for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}}if(l)for(let t=i-1;t>=0;t--){if(t<y&&0!==p[t])for(let e=t+1;e<i;e++){let r=0;for(let n=t+1;n<i;n++)r+=g.get(n,t)*g.get(n,e);r=-r/g.get(t+1,t);for(let n=t+1;n<i;n++)g.set(n,e,g.get(n,e)+r*g.get(n,t))}for(let e=0;e<i;e++)g.set(e,t,0);g.set(t,t,1)}let v=x-1,E=Number.EPSILON;for(;x>0;){let t,e;for(t=x-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+E*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===x-2)e=4;else{let r;for(r=x-1;r>=t&&r!==t;r--){let e=(r!==x?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(d[r])<=E*e){d[r]=0;break}}r===t?e=3:r===x-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[x-2];p[x-2]=0;for(let r=x-2;r>=t;r--){let n=hypotenuse$1(d[r],e),s=d[r]/n,a=e/n;if(d[r]=n,r!==t&&(e=-a*p[r-1],p[r-1]=s*p[r-1]),l)for(let t=0;t<i;t++)n=s*g.get(t,r)+a*g.get(t,x-1),g.set(t,x-1,-a*g.get(t,r)+s*g.get(t,x-1)),g.set(t,r,n)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let i=t;i<x;i++){let n=hypotenuse$1(d[i],e),s=d[i]/n,a=e/n;if(d[i]=n,e=-a*p[i],p[i]=s*p[i],h)for(let e=0;e<r;e++)n=s*m.get(e,i)+a*m.get(e,t-1),m.set(e,t-1,-a*m.get(e,i)+s*m.get(e,t-1)),m.set(e,i,n)}break}case 3:{const e=Math.max(Math.abs(d[x-1]),Math.abs(d[x-2]),Math.abs(p[x-2]),Math.abs(d[t]),Math.abs(p[t])),n=d[x-1]/e,s=d[x-2]/e,a=p[x-2]/e,o=d[t]/e,c=p[t]/e,u=((s+n)*(s-n)+a*a)/2,f=n*a*(n*a);let w=0;0===u&&0===f||(w=u<0?0-Math.sqrt(u*u+f):Math.sqrt(u*u+f),w=f/(u+w));let _=(o+n)*(o-n)+w,b=o*c;for(let e=t;e<x-1;e++){let n=hypotenuse$1(_,b);0===n&&(n=Number.MIN_VALUE);let s=_/n,a=b/n;if(e!==t&&(p[e-1]=n),_=s*d[e]+a*p[e],p[e]=s*p[e]-a*d[e],b=a*d[e+1],d[e+1]=s*d[e+1],l)for(let t=0;t<i;t++)n=s*g.get(t,e)+a*g.get(t,e+1),g.set(t,e+1,-a*g.get(t,e)+s*g.get(t,e+1)),g.set(t,e,n);if(n=hypotenuse$1(_,b),0===n&&(n=Number.MIN_VALUE),s=_/n,a=b/n,d[e]=n,_=s*p[e]+a*d[e+1],d[e+1]=-a*p[e]+s*d[e+1],b=a*p[e+1],p[e+1]=s*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)n=s*m.get(t,e)+a*m.get(t,e+1),m.set(t,e+1,-a*m.get(t,e)+s*m.get(t,e+1)),m.set(t,e,n)}p[x-2]=_;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,l))for(let e=0;e<=v;e++)g.set(e,t,-g.get(e,t));for(;t<v&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,l&&t<i-1)for(let r=0;r<i;r++)e=g.get(r,t+1),g.set(r,t+1,g.get(r,t)),g.set(r,t,e);if(h&&t<r-1)for(let i=0;i<r;i++)e=m.get(i,t+1),m.set(i,t+1,m.get(i,t)),m.set(i,t,e);t++}x--}}if(c){let t=g;g=m,m=t}this.m=r,this.n=i,this.s=d,this.U=m,this.V=g}solve(t){let e=t,r=this.threshold,i=this.s.length,n=Matrix$2.zeros(i,i);for(let t=0;t<i;t++)Math.abs(this.s[t])<=r?n.set(t,t,0):n.set(t,t,1/this.s[t]);let s=this.U,a=this.rightSingularVectors,o=a.mmul(n),h=a.rows,l=s.rows,c=Matrix$2.zeros(h,l);for(let t=0;t<h;t++)for(let e=0;e<l;e++){let r=0;for(let n=0;n<i;n++)r+=o.get(t,n)*s.get(e,n);c.set(t,e,r)}return c.mmul(e)}solveForDiagonal(t){return this.solve(Matrix$2.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,i=t.columns,n=new Matrix$2(r,this.s.length);for(let s=0;s<r;s++)for(let r=0;r<i;r++)Math.abs(this.s[r])>e&&n.set(s,r,t.get(s,r)/this.s[r]);let s=this.U,a=s.rows,o=s.columns,h=new Matrix$2(r,a);for(let t=0;t<r;t++)for(let e=0;e<a;e++){let r=0;for(let i=0;i<o;i++)r+=n.get(t,i)*s.get(e,i);h.set(t,e,r)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let i=0,n=r.length;i<n;i++)r[i]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Matrix$2.diag(this.s)}}function inverse(t,e=!1){return t=WrapperMatrix2D.checkMatrix(t),e?new SingularValueDecomposition(t).inverse():solve(t,Matrix$2.eye(t.rows))}function solve(t,e,r=!1){return t=WrapperMatrix2D.checkMatrix(t),e=WrapperMatrix2D.checkMatrix(e),r?new SingularValueDecomposition(t).solve(e):t.isSquare()?new LuDecomposition(t).solve(e):new QrDecomposition(t).solve(e)}function determinant(t){if((t=Matrix$2.checkMatrix(t)).isSquare()){if(0===t.columns)return 1;let e,r,i,n;if(2===t.columns)return e=t.get(0,0),r=t.get(0,1),i=t.get(1,0),n=t.get(1,1),e*n-r*i;if(3===t.columns){let n,s,a;return n=new MatrixSelectionView(t,[1,2],[1,2]),s=new MatrixSelectionView(t,[1,2],[0,2]),a=new MatrixSelectionView(t,[1,2],[0,1]),e=t.get(0,0),r=t.get(0,1),i=t.get(0,2),e*determinant(n)-r*determinant(s)+i*determinant(a)}return new LuDecomposition(t).determinant}throw Error("determinant can only be calculated for a square matrix")}function xrange(t,e){let r=[];for(let i=0;i<t;i++)i!==e&&r.push(i);return r}function dependenciesOneRow(t,e,r,i=1e-9,n=1e-9){if(t>n)return new Array(e.rows+1).fill(0);{let t=e.addRow(r,[0]);for(let e=0;e<t.rows;e++)Math.abs(t.get(e,0))<i&&t.set(e,0,0);return t.to1DArray()}}function linearDependencies(t,e={}){const{thresholdValue:r=1e-9,thresholdError:i=1e-9}=e;let n=(t=Matrix$2.checkMatrix(t)).rows,s=new Matrix$2(n,n);for(let e=0;e<n;e++){let a=Matrix$2.columnVector(t.getRow(e)),o=t.subMatrixRow(xrange(n,e)).transpose(),h=new SingularValueDecomposition(o).solve(a),l=Matrix$2.sub(a,o.mmul(h)).abs().max();s.setRow(e,dependenciesOneRow(l,h,e,r,i))}return s}function pseudoInverse(t,e=Number.EPSILON){if((t=Matrix$2.checkMatrix(t)).isEmpty())return t.transpose();let r=new SingularValueDecomposition(t,{autoTranspose:!0}),i=r.leftSingularVectors,n=r.rightSingularVectors,s=r.diagonal;for(let t=0;t<s.length;t++)Math.abs(s[t])>e?s[t]=1/s[t]:s[t]=0;return n.mmul(Matrix$2.diag(s).mmul(i.transpose()))}function covariance(t,e=t,r={}){t=new Matrix$2(t);let i=!1;if("object"!=typeof e||Matrix$2.isMatrix(e)||Array.isArray(e)?e=new Matrix$2(e):(r=e,e=t,i=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=r;n&&(t=t.center("column"),i||(e=e.center("column")));const s=t.transpose().mmul(e);for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)s.set(e,r,s.get(e,r)*(1/(t.rows-1)));return s}function correlation(t,e=t,r={}){t=new Matrix$2(t);let i=!1;if("object"!=typeof e||Matrix$2.isMatrix(e)||Array.isArray(e)?e=new Matrix$2(e):(r=e,e=t,i=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:s=!0}=r;n&&(t.center("column"),i||e.center("column")),s&&(t.scale("column"),i||e.scale("column"));const a=t.standardDeviation("column",{unbiased:!0}),o=i?a:e.standardDeviation("column",{unbiased:!0}),h=t.transpose().mmul(e);for(let e=0;e<h.rows;e++)for(let r=0;r<h.columns;r++)h.set(e,r,h.get(e,r)*(1/(a[e]*o[r]))*(1/(t.rows-1)));return h}class EigenvalueDecomposition{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=WrapperMatrix2D.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let i,n,s=t.columns,a=new Matrix$2(s,s),o=new Float64Array(s),h=new Float64Array(s),l=t,c=!1;if(c=!!r||t.isSymmetric(),c){for(i=0;i<s;i++)for(n=0;n<s;n++)a.set(i,n,l.get(i,n));tred2(s,h,o,a),tql2(s,h,o,a)}else{let t=new Matrix$2(s,s),e=new Float64Array(s);for(n=0;n<s;n++)for(i=0;i<s;i++)t.set(i,n,l.get(i,n));orthes(s,t,e,a),hqr2(s,h,o,a,t)}this.n=s,this.e=h,this.d=o,this.V=a}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t,e,r=this.n,i=this.e,n=this.d,s=new Matrix$2(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)s.set(t,e,0);s.set(t,t,n[t]),i[t]>0?s.set(t,t+1,i[t]):i[t]<0&&s.set(t,t-1,i[t])}return s}}function tred2(t,e,r,i){let n,s,a,o,h,l,c,u;for(h=0;h<t;h++)r[h]=i.get(t-1,h);for(o=t-1;o>0;o--){for(u=0,a=0,l=0;l<o;l++)u+=Math.abs(r[l]);if(0===u)for(e[o]=r[o-1],h=0;h<o;h++)r[h]=i.get(o-1,h),i.set(o,h,0),i.set(h,o,0);else{for(l=0;l<o;l++)r[l]/=u,a+=r[l]*r[l];for(n=r[o-1],s=Math.sqrt(a),n>0&&(s=-s),e[o]=u*s,a-=n*s,r[o-1]=n-s,h=0;h<o;h++)e[h]=0;for(h=0;h<o;h++){for(n=r[h],i.set(h,o,n),s=e[h]+i.get(h,h)*n,l=h+1;l<=o-1;l++)s+=i.get(l,h)*r[l],e[l]+=i.get(l,h)*n;e[h]=s}for(n=0,h=0;h<o;h++)e[h]/=a,n+=e[h]*r[h];for(c=n/(a+a),h=0;h<o;h++)e[h]-=c*r[h];for(h=0;h<o;h++){for(n=r[h],s=e[h],l=h;l<=o-1;l++)i.set(l,h,i.get(l,h)-(n*e[l]+s*r[l]));r[h]=i.get(o-1,h),i.set(o,h,0)}}r[o]=a}for(o=0;o<t-1;o++){if(i.set(t-1,o,i.get(o,o)),i.set(o,o,1),a=r[o+1],0!==a){for(l=0;l<=o;l++)r[l]=i.get(l,o+1)/a;for(h=0;h<=o;h++){for(s=0,l=0;l<=o;l++)s+=i.get(l,o+1)*i.get(l,h);for(l=0;l<=o;l++)i.set(l,h,i.get(l,h)-s*r[l])}}for(l=0;l<=o;l++)i.set(l,o+1,0)}for(h=0;h<t;h++)r[h]=i.get(t-1,h),i.set(t-1,h,0);i.set(t-1,t-1,1),e[0]=0}function tql2(t,e,r,i){let n,s,a,o,h,l,c,u,f,d,m,g,p,w,_,b;for(a=1;a<t;a++)e[a-1]=e[a];e[t-1]=0;let y=0,M=0,x=Number.EPSILON;for(l=0;l<t;l++){for(M=Math.max(M,Math.abs(r[l])+Math.abs(e[l])),c=l;c<t&&!(Math.abs(e[c])<=x*M);)c++;if(c>l)do{for(n=r[l],u=(r[l+1]-n)/(2*e[l]),f=hypotenuse$1(u,1),u<0&&(f=-f),r[l]=e[l]/(u+f),r[l+1]=e[l]*(u+f),d=r[l+1],s=n-r[l],a=l+2;a<t;a++)r[a]-=s;for(y+=s,u=r[c],m=1,g=m,p=m,w=e[l+1],_=0,b=0,a=c-1;a>=l;a--)for(p=g,g=m,b=_,n=m*e[a],s=m*u,f=hypotenuse$1(u,e[a]),e[a+1]=_*f,_=e[a]/f,m=u/f,u=m*r[a]-_*n,r[a+1]=s+_*(m*n+_*r[a]),h=0;h<t;h++)s=i.get(h,a+1),i.set(h,a+1,_*i.get(h,a)+m*s),i.set(h,a,m*i.get(h,a)-_*s);u=-_*b*p*w*e[l]/d,e[l]=_*u,r[l]=m*u}while(Math.abs(e[l])>x*M);r[l]=r[l]+y,e[l]=0}for(a=0;a<t-1;a++){for(h=a,u=r[a],o=a+1;o<t;o++)r[o]<u&&(h=o,u=r[o]);if(h!==a)for(r[h]=r[a],r[a]=u,o=0;o<t;o++)u=i.get(o,a),i.set(o,a,i.get(o,h)),i.set(o,h,u)}}function orthes(t,e,r,i){let n,s,a,o,h,l,c,u=t-1;for(l=1;l<=u-1;l++){for(c=0,o=l;o<=u;o++)c+=Math.abs(e.get(o,l-1));if(0!==c){for(a=0,o=u;o>=l;o--)r[o]=e.get(o,l-1)/c,a+=r[o]*r[o];for(s=Math.sqrt(a),r[l]>0&&(s=-s),a-=r[l]*s,r[l]=r[l]-s,h=l;h<t;h++){for(n=0,o=u;o>=l;o--)n+=r[o]*e.get(o,h);for(n/=a,o=l;o<=u;o++)e.set(o,h,e.get(o,h)-n*r[o])}for(o=0;o<=u;o++){for(n=0,h=u;h>=l;h--)n+=r[h]*e.get(o,h);for(n/=a,h=l;h<=u;h++)e.set(o,h,e.get(o,h)-n*r[h])}r[l]=c*r[l],e.set(l,l-1,c*s)}}for(o=0;o<t;o++)for(h=0;h<t;h++)i.set(o,h,o===h?1:0);for(l=u-1;l>=1;l--)if(0!==e.get(l,l-1)){for(o=l+1;o<=u;o++)r[o]=e.get(o,l-1);for(h=l;h<=u;h++){for(s=0,o=l;o<=u;o++)s+=r[o]*i.get(o,h);for(s=s/r[l]/e.get(l,l-1),o=l;o<=u;o++)i.set(o,h,i.get(o,h)+s*r[o])}}}function hqr2(t,e,r,i,n){let s,a,o,h,l,c,u,f,d,m,g,p,w,_,b,y=t-1,M=t-1,x=Number.EPSILON,v=0,E=0,A=0,k=0,S=0,I=0,D=0,R=0;for(s=0;s<t;s++)for((s<0||s>M)&&(r[s]=n.get(s,s),e[s]=0),a=Math.max(s-1,0);a<t;a++)E+=Math.abs(n.get(s,a));for(;y>=0;){for(h=y;h>0&&(I=Math.abs(n.get(h-1,h-1))+Math.abs(n.get(h,h)),0===I&&(I=E),!(Math.abs(n.get(h,h-1))<x*I));)h--;if(h===y)n.set(y,y,n.get(y,y)+v),r[y]=n.get(y,y),e[y]=0,y--,R=0;else if(h===y-1){if(u=n.get(y,y-1)*n.get(y-1,y),A=(n.get(y-1,y-1)-n.get(y,y))/2,k=A*A+u,D=Math.sqrt(Math.abs(k)),n.set(y,y,n.get(y,y)+v),n.set(y-1,y-1,n.get(y-1,y-1)+v),f=n.get(y,y),k>=0){for(D=A>=0?A+D:A-D,r[y-1]=f+D,r[y]=r[y-1],0!==D&&(r[y]=f-u/D),e[y-1]=0,e[y]=0,f=n.get(y,y-1),I=Math.abs(f)+Math.abs(D),A=f/I,k=D/I,S=Math.sqrt(A*A+k*k),A/=S,k/=S,a=y-1;a<t;a++)D=n.get(y-1,a),n.set(y-1,a,k*D+A*n.get(y,a)),n.set(y,a,k*n.get(y,a)-A*D);for(s=0;s<=y;s++)D=n.get(s,y-1),n.set(s,y-1,k*D+A*n.get(s,y)),n.set(s,y,k*n.get(s,y)-A*D);for(s=0;s<=M;s++)D=i.get(s,y-1),i.set(s,y-1,k*D+A*i.get(s,y)),i.set(s,y,k*i.get(s,y)-A*D)}else r[y-1]=f+A,r[y]=f+A,e[y-1]=D,e[y]=-D;y-=2,R=0}else{if(f=n.get(y,y),d=0,u=0,h<y&&(d=n.get(y-1,y-1),u=n.get(y,y-1)*n.get(y-1,y)),10===R){for(v+=f,s=0;s<=y;s++)n.set(s,s,n.get(s,s)-f);I=Math.abs(n.get(y,y-1))+Math.abs(n.get(y-1,y-2)),f=d=.75*I,u=-.4375*I*I}if(30===R&&(I=(d-f)/2,I=I*I+u,I>0)){for(I=Math.sqrt(I),d<f&&(I=-I),I=f-u/((d-f)/2+I),s=0;s<=y;s++)n.set(s,s,n.get(s,s)-I);v+=I,f=d=u=.964}for(R+=1,l=y-2;l>=h&&(D=n.get(l,l),S=f-D,I=d-D,A=(S*I-u)/n.get(l+1,l)+n.get(l,l+1),k=n.get(l+1,l+1)-D-S-I,S=n.get(l+2,l+1),I=Math.abs(A)+Math.abs(k)+Math.abs(S),A/=I,k/=I,S/=I,l!==h)&&!(Math.abs(n.get(l,l-1))*(Math.abs(k)+Math.abs(S))<x*(Math.abs(A)*(Math.abs(n.get(l-1,l-1))+Math.abs(D)+Math.abs(n.get(l+1,l+1)))));)l--;for(s=l+2;s<=y;s++)n.set(s,s-2,0),s>l+2&&n.set(s,s-3,0);for(o=l;o<=y-1&&(_=o!==y-1,o!==l&&(A=n.get(o,o-1),k=n.get(o+1,o-1),S=_?n.get(o+2,o-1):0,f=Math.abs(A)+Math.abs(k)+Math.abs(S),0!==f&&(A/=f,k/=f,S/=f)),0!==f);o++)if(I=Math.sqrt(A*A+k*k+S*S),A<0&&(I=-I),0!==I){for(o!==l?n.set(o,o-1,-I*f):h!==l&&n.set(o,o-1,-n.get(o,o-1)),A+=I,f=A/I,d=k/I,D=S/I,k/=A,S/=A,a=o;a<t;a++)A=n.get(o,a)+k*n.get(o+1,a),_&&(A+=S*n.get(o+2,a),n.set(o+2,a,n.get(o+2,a)-A*D)),n.set(o,a,n.get(o,a)-A*f),n.set(o+1,a,n.get(o+1,a)-A*d);for(s=0;s<=Math.min(y,o+3);s++)A=f*n.get(s,o)+d*n.get(s,o+1),_&&(A+=D*n.get(s,o+2),n.set(s,o+2,n.get(s,o+2)-A*S)),n.set(s,o,n.get(s,o)-A),n.set(s,o+1,n.get(s,o+1)-A*k);for(s=0;s<=M;s++)A=f*i.get(s,o)+d*i.get(s,o+1),_&&(A+=D*i.get(s,o+2),i.set(s,o+2,i.get(s,o+2)-A*S)),i.set(s,o,i.get(s,o)-A),i.set(s,o+1,i.get(s,o+1)-A*k)}}}if(0!==E){for(y=t-1;y>=0;y--)if(A=r[y],k=e[y],0===k)for(h=y,n.set(y,y,1),s=y-1;s>=0;s--){for(u=n.get(s,s)-A,S=0,a=h;a<=y;a++)S+=n.get(s,a)*n.get(a,y);if(e[s]<0)D=u,I=S;else if(h=s,0===e[s]?n.set(s,y,0!==u?-S/u:-S/(x*E)):(f=n.get(s,s+1),d=n.get(s+1,s),k=(r[s]-A)*(r[s]-A)+e[s]*e[s],c=(f*I-D*S)/k,n.set(s,y,c),n.set(s+1,y,Math.abs(f)>Math.abs(D)?(-S-u*c)/f:(-I-d*c)/D)),c=Math.abs(n.get(s,y)),x*c*c>1)for(a=s;a<=y;a++)n.set(a,y,n.get(a,y)/c)}else if(k<0)for(h=y-1,Math.abs(n.get(y,y-1))>Math.abs(n.get(y-1,y))?(n.set(y-1,y-1,k/n.get(y,y-1)),n.set(y-1,y,-(n.get(y,y)-A)/n.get(y,y-1))):(b=cdiv(0,-n.get(y-1,y),n.get(y-1,y-1)-A,k),n.set(y-1,y-1,b[0]),n.set(y-1,y,b[1])),n.set(y,y-1,0),n.set(y,y,1),s=y-2;s>=0;s--){for(m=0,g=0,a=h;a<=y;a++)m+=n.get(s,a)*n.get(a,y-1),g+=n.get(s,a)*n.get(a,y);if(u=n.get(s,s)-A,e[s]<0)D=u,S=m,I=g;else if(h=s,0===e[s]?(b=cdiv(-m,-g,u,k),n.set(s,y-1,b[0]),n.set(s,y,b[1])):(f=n.get(s,s+1),d=n.get(s+1,s),p=(r[s]-A)*(r[s]-A)+e[s]*e[s]-k*k,w=2*(r[s]-A)*k,0===p&&0===w&&(p=x*E*(Math.abs(u)+Math.abs(k)+Math.abs(f)+Math.abs(d)+Math.abs(D))),b=cdiv(f*S-D*m+k*g,f*I-D*g-k*m,p,w),n.set(s,y-1,b[0]),n.set(s,y,b[1]),Math.abs(f)>Math.abs(D)+Math.abs(k)?(n.set(s+1,y-1,(-m-u*n.get(s,y-1)+k*n.get(s,y))/f),n.set(s+1,y,(-g-u*n.get(s,y)-k*n.get(s,y-1))/f)):(b=cdiv(-S-d*n.get(s,y-1),-I-d*n.get(s,y),D,k),n.set(s+1,y-1,b[0]),n.set(s+1,y,b[1]))),c=Math.max(Math.abs(n.get(s,y-1)),Math.abs(n.get(s,y))),x*c*c>1)for(a=s;a<=y;a++)n.set(a,y-1,n.get(a,y-1)/c),n.set(a,y,n.get(a,y)/c)}for(s=0;s<t;s++)if(s<0||s>M)for(a=s;a<t;a++)i.set(s,a,n.get(s,a));for(a=t-1;a>=0;a--)for(s=0;s<=M;s++){for(D=0,o=0;o<=Math.min(a,M);o++)D+=i.get(s,o)*n.get(o,a);i.set(s,a,D)}}}function cdiv(t,e,r,i){let n,s;return Math.abs(r)>Math.abs(i)?(n=i/r,s=r+n*i,[(t+n*e)/s,(e-n*t)/s]):(n=r/i,s=i+n*r,[(n*t+e)/s,(n*e-t)/s])}class CholeskyDecomposition{constructor(t){if(!(t=WrapperMatrix2D.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,i,n=t,s=n.rows,a=new Matrix$2(s,s),o=!0;for(r=0;r<s;r++){let t=0;for(i=0;i<r;i++){let s=0;for(e=0;e<i;e++)s+=a.get(i,e)*a.get(r,e);s=(n.get(r,i)-s)/a.get(i,i),a.set(r,i,s),t+=s*s}for(t=n.get(r,r)-t,o&=t>0,a.set(r,r,Math.sqrt(Math.max(t,0))),i=r+1;i<s;i++)a.set(r,i,0)}this.L=a,this.positiveDefinite=Boolean(o)}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=WrapperMatrix2D.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(!1===this.isPositiveDefinite())throw new Error("Matrix is not positive definite");let i,n,s,a=t.columns,o=t.clone();for(s=0;s<r;s++)for(n=0;n<a;n++){for(i=0;i<s;i++)o.set(s,n,o.get(s,n)-o.get(i,n)*e.get(s,i));o.set(s,n,o.get(s,n)/e.get(s,s))}for(s=r-1;s>=0;s--)for(n=0;n<a;n++){for(i=s+1;i<r;i++)o.set(s,n,o.get(s,n)-o.get(i,n)*e.get(i,s));o.set(s,n,o.get(s,n)/e.get(s,s))}return o}get lowerTriangularMatrix(){return this.L}}class nipals{constructor(t,e={}){t=WrapperMatrix2D.checkMatrix(t);let{Y:r}=e;const{scaleScores:i=!1,maxIterations:n=1e3,terminationCriteria:s=1e-10}=e;let a;if(r){if(r=Array.isArray(r)&&"number"==typeof r[0]?Matrix$2.columnVector(r):WrapperMatrix2D.checkMatrix(r),!r.isColumnVector()||r.rows!==t.rows)throw new Error("Y must be a column vector of length X.rows");a=r}else a=t.getColumnVector(0);let o,h,l,c,u=1;for(let e=0;e<n&&u>s;e++)l=t.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),l=l.div(l.norm()),o=t.mmul(l).div(l.transpose().mmul(l).get(0,0)),e>0&&(u=o.clone().sub(c).pow(2).sum()),c=o.clone(),r?(h=r.transpose().mmul(o).div(o.transpose().mmul(o).get(0,0)),h=h.div(h.norm()),a=r.mmul(h).div(h.transpose().mmul(h).get(0,0))):a=o;if(r){let e=t.transpose().mmul(o).div(o.transpose().mmul(o).get(0,0));e=e.div(e.norm());let i=t.clone().sub(o.clone().mmul(e.transpose())),n=a.transpose().mmul(o).div(o.transpose().mmul(o).get(0,0)),s=r.clone().sub(o.clone().mulS(n.get(0,0)).mmul(h.transpose()));this.t=o,this.p=e.transpose(),this.w=l.transpose(),this.q=h,this.u=a,this.s=o.transpose().mmul(o),this.xResidual=i,this.yResidual=s,this.betas=n}else this.w=l.transpose(),this.s=o.transpose().mmul(o).sqrt(),this.t=i?o.clone().div(this.s.get(0,0)):o,this.xResidual=t.sub(o.mmul(l.transpose()))}}var src$1=Object.freeze({__proto__:null,AbstractMatrix:AbstractMatrix,default:Matrix$2,Matrix:Matrix$2,wrap:wrap,WrapperMatrix1D:WrapperMatrix1D,WrapperMatrix2D:WrapperMatrix2D,solve:solve,inverse:inverse,determinant:determinant,linearDependencies:linearDependencies,pseudoInverse:pseudoInverse,covariance:covariance,correlation:correlation,SingularValueDecomposition:SingularValueDecomposition,SVD:SingularValueDecomposition,EigenvalueDecomposition:EigenvalueDecomposition,EVD:EigenvalueDecomposition,CholeskyDecomposition:CholeskyDecomposition,CHO:CholeskyDecomposition,LuDecomposition:LuDecomposition,LU:LuDecomposition,QrDecomposition:QrDecomposition,QR:QrDecomposition,Nipals:nipals,NIPALS:nipals,MatrixColumnView:MatrixColumnView,MatrixColumnSelectionView:MatrixColumnSelectionView,MatrixFlipColumnView:MatrixFlipColumnView,MatrixFlipRowView:MatrixFlipRowView,MatrixRowView:MatrixRowView,MatrixRowSelectionView:MatrixRowSelectionView,MatrixSelectionView:MatrixSelectionView,MatrixSubView:MatrixSubView,MatrixTransposeView:MatrixTransposeView$1});function getSeparatedKernel(t){const e=new SingularValueDecomposition(t,{autoTranspose:!0});if(1!==e.rank)return null;const r=Math.sqrt(e.s[0]);return[e.U.to2DArray().map((t=>t[0]*r)),e.V.to2DArray().map((t=>t[0]*r))]}function convolution(t,e={}){let{channels:r,bitDepth:i,normalize:n=!1,divisor:s=1,border:a="copy",algorithm:o="auto"}=e,h={};i&&(h.bitDepth=i);let l,c,u=Image.createFrom(this,h);if(r=validateArrayOfChannels(this,r),"separable"!==o)({kernel:t}=validateKernel(t));else if(!Array.isArray(t)||2!==t.length)throw new RangeError("separable convolution requires two arrays of numbers to represent the kernel");if("auto"===o){let e=getSeparatedKernel(t);null!==e?(o="separable",t=e):o=(t.length>9||t[0].length>9)&&this.width<=4096&&this.height<=4096?"fft":"direct"}"separable"===o?(l=Math.floor(t[0].length/2),c=Math.floor(t[1].length/2)):(l=Math.floor(t.length/2),c=Math.floor(t[0].length/2));let f,d,m,g,p,w,_=u.isClamped,b=new Array(this.height*this.width);for(g=0;g<r.length;g++){for(p=r[g],m=0;m<this.height;m++)for(d=0;d<this.width;d++)f=m*this.width+d,b[f]=this.data[f*this.channels+p];if("direct"===o)w=src$2.direct(b,t,{rows:this.height,cols:this.width,normalize:n,divisor:s});else if("separable"===o){if(w=convolutionSeparable(b,t,this.width,this.height),n){s=0;for(let e=0;e<t[0].length;e++)for(let r=0;r<t[1].length;r++)s+=t[0][e]*t[1][r]}if(1!==s)for(let t=0;t<w.length;t++)w[t]/=s}else w=src$2.fft(b,t,{rows:this.height,cols:this.width,normalize:n,divisor:s});for(m=0;m<this.height;m++)for(d=0;d<this.width;d++)f=m*this.width+d,u.data[f*this.channels+p]=_?clamp(w[f],u):w[f]}if(this.alpha&&!r.includes(this.channels))for(d=this.components;d<this.data.length;d+=this.channels)u.data[d]=this.data[d];return"periodic"!==a&&u.setBorder({size:[c,l],algorithm:a}),u}function gradientFilter(t={}){let{direction:e="xy",border:r="copy",kernelX:i,kernelY:n,channels:s,bitDepth:a=this.bitDepth}=t;switch(this.checkProcessable("gradientFilter",{bitDepth:[8,16]}),e){case"x":if(!i)throw new Error("kernelX option is missing");return convolution.call(this,i,{channels:s,border:r,bitDepth:a});case"y":if(!n)throw new Error("kernelY option is missing");return convolution.call(this,n,{channels:s,border:r,bitDepth:a});case"xy":{if(!i)throw new Error("kernelX option is missing");if(!n)throw new Error("kernelY option is missing");const t=convolution.call(this,i,{channels:s,border:r,bitDepth:32}),e=convolution.call(this,n,{channels:s,border:r,bitDepth:32});return t.hypotenuse(e,{bitDepth:a,channels:s})}default:throw new Error(`Unknown parameter direction: ${e}`)}}function sobelFilter(t){return gradientFilter.call(this,Object.assign({},t,{kernelX:SOBEL_X,kernelY:SOBEL_Y}))}function scharrFilter(t){return gradientFilter.call(this,Object.assign({},t,{kernelX:SCHARR_X,kernelY:SCHARR_Y}))}var _newArray_1_0_0_newArray=newArray;function newArray(t,e){t=t||0;for(var r=new Array(t),i=0;i<t;i++)r[i]=e;return r}function level(t={}){let{algorithm:e="range",channels:r,min:i=this.min,max:n=this.max}=t;switch(this.checkProcessable("level",{bitDepth:[8,16,32]}),r=validateArrayOfChannels(this,{channels:r}),r.length!==this.channel&&(Array.isArray(i)&&i.length===this.channels&&(i=i.filter(((t,e)=>r.includes(e)))),Array.isArray(n)&&n.length===this.channels&&(n=n.filter(((t,e)=>r.includes(e))))),e){case"range":i<0&&(i=0),n>this.maxValue&&(n=this.maxValue),Array.isArray(i)||(i=_newArray_1_0_0_newArray(r.length,i)),Array.isArray(n)||(n=_newArray_1_0_0_newArray(r.length,n)),processImage(this,i,n,r);break;default:throw new Error(`level: algorithm not implement: ${e}`)}return this}function processImage(t,e,r,i){let n=1e-5,s=new Array(i.length);for(let a=0;a<i.length;a++)0===e[a]&&r[a]===t.maxValue||r[a]===e[a]?s[a]=0:s[a]=(t.maxValue+1-n)/(r[a]-e[a]),e[a]+=.499995/s[a];for(let r=0;r<i.length;r++){let n=i[r];if(0!==s[r])for(let i=0;i<t.data.length;i+=t.channels)t.data[i+n]=Math.min(Math.max(0,(t.data[i+n]-e[r])*s[r]+.5|0),t.maxValue)}}var toString=Object.prototype.toString,isArrayType=function(t){return"Array"===toString.call(t).substr(-6,5)};function checkNumberArray(t){if(isNaN(t)){if(t instanceof Image)return t.data;if(!isArrayType(t))throw new Error("checkNumberArray: the value should be either a number, array or Image");return t}if(t<=0)throw new Error("checkNumberArray: the value must be greater than 0");return t}function add(t,e={}){let{channels:r}=e;if(this.checkProcessable("add",{bitDepth:[8,16]}),r=validateArrayOfChannels(this,{channels:r}),t=checkNumberArray(t),isNaN(t)){if(this.data.length!==t.length)throw new Error("add: the data size is different");for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.max(0,Math.min(this.maxValue,this.data[e+i]+t[e+i]>>0))}}else for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.min(this.maxValue,this.data[e+i]+t>>0)}return this}function subtract(t,e={}){let{channels:r}=e;if(this.checkProcessable("subtract",{bitDepth:[8,16]}),r=validateArrayOfChannels(this,{channels:r}),t=checkNumberArray(t),isNaN(t)){if(this.data.length!==t.length)throw new Error("subtract: the data size is different");for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.max(0,Math.min(this.maxValue,this.data[e+i]-t[e+i]>>0))}}else for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.max(0,this.data[e+i]-t>>0)}return this}function subtractImage(t,e={}){let{channels:r,absolute:i=!1}=e;if(this.checkProcessable("subtractImage",{bitDepth:[8,16]}),this.width!==t.width||this.height!==t.height)throw new Error("subtractImage: both images must have the same size");if(this.alpha!==t.alpha||this.bitDepth!==t.bitDepth)throw new Error("subtractImage: both images must have the same alpha and bitDepth");if(this.channels!==t.channels)throw new Error("subtractImage: both images must have the same number of channels");let n=this.clone();r=validateArrayOfChannels(this,{channels:r});for(let e=0;e<r.length;e++){for(let s=r[e];s<this.data.length;s+=this.channels){let e=this.data[s]-t.data[s];n.data[s]=i?Math.abs(e):Math.max(e,0)}}return n}function hypotenuse(t,e={}){let{bitDepth:r=this.bitDepth,channels:i}=e;if(this.checkProcessable("hypotenuse",{bitDepth:[8,16,32]}),this.width!==t.width||this.height!==t.height)throw new Error("hypotenuse: both images must have the same size");if(this.alpha!==t.alpha||this.bitDepth!==t.bitDepth)throw new Error("hypotenuse: both images must have the same alpha and bitDepth");if(this.channels!==t.channels)throw new Error("hypotenuse: both images must have the same number of channels");let n=Image.createFrom(this,{bitDepth:r});i=validateArrayOfChannels(this,{channels:i});let s=n.isClamped;for(let e=0;e<i.length;e++){for(let r=i[e];r<this.data.length;r+=this.channels){let e=Math.hypot(this.data[r],t.data[r]);n.data[r]=s?Math.min(Math.max(Math.round(e),0),n.maxValue):e}}return n}function multiply(t,e={}){let{channels:r}=e;if(this.checkProcessable("multiply",{bitDepth:[8,16]}),t<=0)throw new Error("multiply: the value must be greater than 0");if(r=validateArrayOfChannels(this,{channels:r}),t=checkNumberArray(t),isNaN(t)){if(this.data.length!==t.length)throw new Error("multiply: the data size is different");for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.max(0,Math.min(this.maxValue,this.data[e+i]*t[e+i]>>0))}}else for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.min(this.maxValue,this.data[e+i]*t>>0)}return this}function divide(t,e={}){let{channels:r}=e;if(this.checkProcessable("divide",{bitDepth:[8,16]}),r=validateArrayOfChannels(this,{channels:r}),t=checkNumberArray(t),isNaN(t)){if(this.data.length!==t.length)throw new Error("divide: the: the data size is different");for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.max(0,Math.min(this.maxValue,this.data[e+i]/t[e+i]>>0))}}else for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<this.data.length;e+=this.channels)this.data[e+i]=Math.min(this.maxValue,this.data[e+i]/t>>0)}return this}class BaseRegression{constructor(){if(new.target===BaseRegression)throw new Error("BaseRegression must be subclassed")}predict(t){if("number"==typeof t)return this._predict(t);if(isAnyArray(t)){const e=[];for(let r=0;r<t.length;r++)e.push(this._predict(t[r]));return e}throw new TypeError("x must be a number or array")}_predict(){throw new Error("_predict must be implemented")}train(){}toString(){return""}toLaTeX(){return""}score(t,e){if(!isAnyArray(t)||!isAnyArray(e)||t.length!==e.length)throw new Error("x and y must be arrays of the same length");const r=t.length,i=new Array(r);for(let e=0;e<r;e++)i[e]=this._predict(t[e]);let n=0,s=0,a=0,o=0,h=0,l=0,c=0;for(let t=0;t<r;t++)n+=i[t],s+=e[t],h+=i[t]*i[t],l+=e[t]*e[t],c+=i[t]*e[t],0!==e[t]&&(a+=(e[t]-i[t])*(e[t]-i[t])/e[t]),o+=(e[t]-i[t])*(e[t]-i[t]);const u=(r*c-n*s)/Math.sqrt((r*h-n*n)*(r*l-s*s));return{r:u,r2:u*u,chi2:a,rmsd:Math.sqrt(o/r)}}}function squaredEuclidean$4(t,e){let r=0;for(let i=0;i<t.length;i++)r+=(t[i]-e[i])*(t[i]-e[i]);return r}function euclidean$2(t,e){return Math.sqrt(squaredEuclidean$4(t,e))}var euclidean$3=Object.freeze({__proto__:null,squaredEuclidean:squaredEuclidean$4,euclidean:euclidean$2}),require$$0$1=getAugmentedNamespace(euclidean$3);const{squaredEuclidean:squaredEuclidean$3}=require$$0$1,defaultOptions$b={sigma:1};class GaussianKernel{constructor(t){t=Object.assign({},defaultOptions$b,t),this.sigma=t.sigma,this.divisor=2*t.sigma*t.sigma}compute(t,e){const r=squaredEuclidean$3(t,e);return Math.exp(-r/this.divisor)}}var gaussianKernel=GaussianKernel;const defaultOptions$a={degree:1,constant:1,scale:1};class PolynomialKernel{constructor(t){t=Object.assign({},defaultOptions$a,t),this.degree=t.degree,this.constant=t.constant,this.scale=t.scale}compute(t,e){for(var r=0,i=0;i<t.length;i++)r+=t[i]*e[i];return Math.pow(this.scale*r+this.constant,this.degree)}}var polynomialKernel=PolynomialKernel;const defaultOptions$9={alpha:.01,constant:-Math.E};class SigmoidKernel{constructor(t){t=Object.assign({},defaultOptions$9,t),this.alpha=t.alpha,this.constant=t.constant}compute(t,e){for(var r=0,i=0;i<t.length;i++)r+=t[i]*e[i];return Math.tanh(this.alpha*r+this.constant)}}var sigmoidKernel=SigmoidKernel;const defaultOptions$8={sigma:1,degree:1};class ANOVAKernel{constructor(t){t=Object.assign({},defaultOptions$8,t),this.sigma=t.sigma,this.degree=t.degree}compute(t,e){for(var r=0,i=Math.min(t.length,e.length),n=1;n<=i;++n)r+=Math.pow(Math.exp(-this.sigma*Math.pow(Math.pow(t[n-1],n)-Math.pow(e[n-1],n),2)),this.degree);return r}}var anovaKernel=ANOVAKernel;const{squaredEuclidean:squaredEuclidean$2}=require$$0$1,defaultOptions$7={sigma:1};class CauchyKernel{constructor(t){t=Object.assign({},defaultOptions$7,t),this.sigma=t.sigma}compute(t,e){return 1/(1+squaredEuclidean$2(t,e)/(this.sigma*this.sigma))}}var cauchyKernel=CauchyKernel;const{euclidean:euclidean$1}=require$$0$1,defaultOptions$6={sigma:1};class ExponentialKernel{constructor(t){t=Object.assign({},defaultOptions$6,t),this.sigma=t.sigma,this.divisor=2*t.sigma*t.sigma}compute(t,e){const r=euclidean$1(t,e);return Math.exp(-r/this.divisor)}}var exponentialKernel=ExponentialKernel;class HistogramIntersectionKernel{compute(t,e){for(var r=Math.min(t.length,e.length),i=0,n=0;n<r;++n)i+=Math.min(t[n],e[n]);return i}}var histogramIntersectionKernel=HistogramIntersectionKernel;const{euclidean:euclidean}=require$$0$1,defaultOptions$5={sigma:1};class LaplacianKernel{constructor(t){t=Object.assign({},defaultOptions$5,t),this.sigma=t.sigma}compute(t,e){const r=euclidean(t,e);return Math.exp(-r/this.sigma)}}var laplacianKernel=LaplacianKernel;const{squaredEuclidean:squaredEuclidean$1}=require$$0$1,defaultOptions$4={constant:1};class MultiquadraticKernel{constructor(t){t=Object.assign({},defaultOptions$4,t),this.constant=t.constant}compute(t,e){return Math.sqrt(squaredEuclidean$1(t,e)+this.constant*this.constant)}}var multiquadraticKernel=MultiquadraticKernel;const{squaredEuclidean:squaredEuclidean}=require$$0$1,defaultOptions$3={constant:1};class RationalQuadraticKernel{constructor(t){t=Object.assign({},defaultOptions$3,t),this.constant=t.constant}compute(t,e){const r=squaredEuclidean(t,e);return 1-r/(r+this.constant)}}var rationalQuadraticKernel=RationalQuadraticKernel,require$$0=getAugmentedNamespace(src$1);const{Matrix:Matrix$1,MatrixTransposeView:MatrixTransposeView}=require$$0,kernelType={gaussian:gaussianKernel,rbf:gaussianKernel,polynomial:polynomialKernel,poly:polynomialKernel,anova:anovaKernel,cauchy:cauchyKernel,exponential:exponentialKernel,histogram:histogramIntersectionKernel,min:histogramIntersectionKernel,laplacian:laplacianKernel,multiquadratic:multiquadraticKernel,rational:rationalQuadraticKernel,sigmoid:sigmoidKernel,mlp:sigmoidKernel};class Kernel{constructor(t,e){if(this.kernelType=t,"linear"!==t)if("string"==typeof t){t=t.toLowerCase();var r=kernelType[t];if(!r)throw new Error(`unsupported kernel type: ${t}`);this.kernelFunction=new r(e)}else{if("object"!=typeof t||"function"!=typeof t.compute)throw new TypeError("first argument must be a valid kernel type or instance");this.kernelFunction=t}}compute(t,e){if(t=Matrix$1.checkMatrix(t),e=void 0===e?t:Matrix$1.checkMatrix(e),"linear"===this.kernelType)return t.mmul(new MatrixTransposeView(e));const r=new Matrix$1(t.rows,e.rows);if(t===e)for(let e=0;e<t.rows;e++)for(let i=e;i<t.rows;i++){const n=this.kernelFunction.compute(t.getRow(e),t.getRow(i));r.set(e,i,n),r.set(i,e,n)}else for(let i=0;i<t.rows;i++)for(let n=0;n<e.rows;n++)r.set(i,n,this.kernelFunction.compute(t.getRow(i),e.getRow(n)));return r}}var kernel$1=Kernel;const defaultOptions$2={lambda:.1,kernelType:"gaussian",kernelOptions:{},computeCoefficient:!1};class KernelRidgeRegression extends BaseRegression{constructor(t,e,r){if(super(),!0===t)this.alpha=e.alpha,this.inputs=e.inputs,this.kernelType=e.kernelType,this.kernelOptions=e.kernelOptions,this.kernel=new kernel$1(e.kernelType,e.kernelOptions);else{t=Matrix$2.checkMatrix(t),r=Object.assign({},defaultOptions$2,r);const i=new kernel$1(r.kernelType,r.kernelOptions),n=i.compute(t),s=t.rows;n.add(Matrix$2.eye(s,s).mul(r.lambda)),this.alpha=solve(n,e),this.inputs=t,this.kernelType=r.kernelType,this.kernelOptions=r.kernelOptions,this.kernel=i}}_predict(t){return this.kernel.compute([t],this.inputs).mmul(this.alpha).getRow(0)}toJSON(){return{name:"kernelRidgeRegression",alpha:this.alpha,inputs:this.inputs,kernelType:this.kernelType,kernelOptions:this.kernelOptions}}static load(t){if("kernelRidgeRegression"!==t.name)throw new TypeError("not a KRR model");return new KernelRidgeRegression(!0,t)}}function background$1(t,e,r){const i=new KernelRidgeRegression(t,e,r),n=new Array(this.size);for(let t=0;t<this.width;t++)for(let e=0;e<this.height;e++)n[e*this.width+t]=[t,e];const s=i.predict(n),a=Image.createFrom(this);for(let t=0;t<this.size;t++)a.data[t]=Math.min(this.maxValue,Math.max(0,s[t][0]));return a}function dilate(t={}){let{kernel:e=[[1,1,1],[1,1,1],[1,1,1]],iterations:r=1}=t;if(this.checkProcessable("dilate",{bitDepth:[1,8,16],components:1,alpha:0}),e.columns%2==0||e.rows%2==0)throw new TypeError("dilate: The number of rows and columns of the kernel must be odd");let i=!0;t:for(const t of e)for(const e of t)if(1!==e){i=!1;break t}let n=this;for(let t=0;t<r;t++)if(1===this.bitDepth)if(i){const t=n.clone();n=dilateOnceBinaryOnlyOnes(n,t,e.length,e[0].length)}else{n=dilateOnceBinary(n,Image.createFrom(n),e)}else if(i){n=dilateOnceGreyOnlyOnes(n,Image.createFrom(n),e.length,e[0].length)}else{n=dilateOnceGrey(n,Image.createFrom(n),e)}return n}function dilateOnceGrey(t,e,r){const i=r.length,n=r[0].length;let s=(i-1)/2,a=(n-1)/2;for(let o=0;o<t.height;o++)for(let h=0;h<t.width;h++){let l=0;for(let e=0;e<n;e++)for(let n=0;n<i;n++){if(1!==r[n][e])continue;let i=n-s+h,c=e-a+o;if(i<0||c<0||i>=t.width||c>=t.height)continue;const u=t.getValueXY(i,c,0);u>l&&(l=u)}e.setValueXY(h,o,0,l)}return e}function dilateOnceGreyOnlyOnes(t,e,r,i){const n=(r-1)/2,s=(i-1)/2,a=[];for(let e=0;e<t.width;e++)a.push(0);for(let r=0;r<t.height;r++){for(let e=0;e<t.width;e++){let i=0;for(let n=Math.max(0,r-s);n<Math.min(t.height,r+s+1);n++){const r=t.getValueXY(e,n,0);r>i&&(i=r)}a[e]=i}for(let i=0;i<t.width;i++){let s=0;for(let e=Math.max(0,i-n);e<Math.min(t.width,i+n+1);e++)a[e]>s&&(s=a[e]);e.setValueXY(i,r,0,s)}}return e}function dilateOnceBinary(t,e,r){const i=r.length,n=r[0].length;let s=(i-1)/2,a=(n-1)/2;for(let o=0;o<t.height;o++)for(let h=0;h<t.width;h++){let l=0;t:for(let e=0;e<n;e++)for(let n=0;n<i;n++){if(1!==r[n][e])continue;let i=n-s+h,c=e-a+o;if(c<0||i<0||i>=t.width||c>=t.height)continue;if(1===t.getBitXY(i,c)){l=1;break t}}1===l&&e.setBitXY(h,o)}return e}function dilateOnceBinaryOnlyOnes(t,e,r,i){const n=(r-1)/2,s=(i-1)/2,a=[];for(let e=0;e<t.width;e++)a.push(1);for(let r=0;r<t.height;r++){for(let e=0;e<t.width;e++){a[e]=0;for(let i=Math.max(0,r-s);i<Math.min(t.height,r+s+1);i++)if(1===t.getBitXY(e,i)){a[e]=1;break}}for(let i=0;i<t.width;i++)if(1!==e.getBitXY(i,r))for(let s=Math.max(0,i-n);s<Math.min(t.width,i+n+1);s++)if(1===a[s]){e.setBitXY(i,r);break}}return e}function erode(t={}){let{kernel:e=[[1,1,1],[1,1,1],[1,1,1]],iterations:r=1}=t;if(this.checkProcessable("erode",{bitDepth:[1,8,16],components:1,alpha:0}),e.columns%2==0||e.rows%2==0)throw new TypeError("erode: The number of rows and columns of the kernel must be odd");let i=!0;t:for(const t of e)for(const e of t)if(1!==e){i=!1;break t}let n=this;for(let t=0;t<r;t++)if(1===this.bitDepth)if(i){const t=n.clone();n=erodeOnceBinaryOnlyOnes(n,t,e.length,e[0].length)}else{n=erodeOnceBinary(n,Image.createFrom(n),e)}else if(i){n=erodeOnceGreyOnlyOnes(n,Image.createFrom(n),e.length,e[0].length)}else{n=erodeOnceGrey(n,Image.createFrom(n),e)}return n}function erodeOnceGrey(t,e,r){const i=r.length,n=r[0].length;let s=(i-1)/2,a=(n-1)/2;for(let o=0;o<t.height;o++)for(let h=0;h<t.width;h++){let l=t.maxValue;for(let e=0;e<n;e++)for(let n=0;n<i;n++){if(1!==r[n][e])continue;let i=n-s+h,c=e-a+o;if(i<0||c<0||i>=t.width||c>=t.height)continue;const u=t.getValueXY(i,c,0);u<l&&(l=u)}e.setValueXY(h,o,0,l)}return e}function erodeOnceGreyOnlyOnes(t,e,r,i){const n=(r-1)/2,s=(i-1)/2,a=[];for(let e=0;e<t.width;e++)a.push(0);for(let r=0;r<t.height;r++){for(let e=0;e<t.width;e++){let i=t.maxValue;for(let n=Math.max(0,r-s);n<Math.min(t.height,r+s+1);n++){const r=t.getValueXY(e,n,0);r<i&&(i=r)}a[e]=i}for(let i=0;i<t.width;i++){let s=t.maxValue;for(let e=Math.max(0,i-n);e<Math.min(t.width,i+n+1);e++)a[e]<s&&(s=a[e]);e.setValueXY(i,r,0,s)}}return e}function erodeOnceBinary(t,e,r){const i=r.length,n=r[0].length;let s=(i-1)/2,a=(n-1)/2;for(let o=0;o<t.height;o++)for(let h=0;h<t.width;h++){let l=1;t:for(let e=0;e<n;e++)for(let n=0;n<i;n++){if(1!==r[n][e])continue;let i=n-s+h,c=e-a+o;if(c<0||i<0||i>=t.width||c>=t.height)continue;if(0===t.getBitXY(i,c)){l=0;break t}}1===l&&e.setBitXY(h,o)}return e}function erodeOnceBinaryOnlyOnes(t,e,r,i){const n=(r-1)/2,s=(i-1)/2,a=[];for(let e=0;e<t.width;e++)a.push(0);for(let r=0;r<t.height;r++){for(let e=0;e<t.width;e++){a[e]=1;for(let i=Math.max(0,r-s);i<Math.min(t.height,r+s+1);i++)if(0===t.getBitXY(e,i)){a[e]=0;break}}for(let i=0;i<t.width;i++)if(0!==e.getBitXY(i,r))for(let s=Math.max(0,i-n);s<Math.min(t.width,i+n+1);s++)if(0===a[s]){e.clearBitXY(i,r);break}}return e}function open(t={}){let{kernel:e=[[1,1,1],[1,1,1],[1,1,1]],iterations:r=1}=t;if(this.checkProcessable("open",{bitDepth:[8,16],components:1,alpha:0}),e.columns%2==0||e.rows%2==0)throw new TypeError("open: The number of rows and columns of the kernel must be odd");let i=this;for(let t=0;t<r;t++)i=i.erode({kernel:e}),i=i.dilate({kernel:e});return i}function close(t={}){let{kernel:e=[[1,1,1],[1,1,1],[1,1,1]],iterations:r=1}=t;if(this.checkProcessable("close",{bitDepth:[1,8,16],components:1,alpha:0}),e.columns%2==0||e.rows%2==0)throw new TypeError("close: The number of rows and columns of the kernel must be odd");let i=this;for(let t=0;t<r;t++)i=i.dilate({kernel:e}).erode({kernel:e});return i}function topHat(t={}){let{kernel:e=[[1,1,1],[1,1,1],[1,1,1]],iterations:r=1}=t;if(this.checkProcessable("topHat",{bitDepth:[8,16],components:1,alpha:0}),e.length%2==0||e[0].length%2==0)throw new TypeError("topHat: The number of rows and columns of the kernel must be odd");let i=this;for(let t=0;t<r;t++){let t=i.open({kernel:e});i=t.subtractImage(i,{absolute:!0})}return i}function blackHat(t={}){let{kernel:e=[[1,1,1],[1,1,1],[1,1,1]],iterations:r=1}=t;if(this.checkProcessable("blackHat",{bitDepth:[8,16],components:1,alpha:0}),e.columns%2==0||e.rows%2==0)throw new TypeError("blackHat: The number of rows and columns of the kernel must be odd");let i=this;for(let t=0;t<r;t++){const t=i.close({kernel:e});i=t.subtractImage(i,{absolute:!0})}return i}function morphologicalGradient(t={}){let{kernel:e=[[1,1,1],[1,1,1],[1,1,1]],iterations:r=1}=t;if(this.checkProcessable("morphologicalGradient",{bitDepth:[8,16],components:1,alpha:0}),e.columns%2==0||e.rows%2==0)throw new TypeError("morphologicalGradient: The number of rows and columns of the kernel must be odd");let i=this;for(let t=0;t<r;t++){let t=i.dilate({kernel:e}),r=i.erode({kernel:e});i=t.subtractImage(r,{absolute:!0})}return i}function order4Points(t){let e=0,r=0,i=0,n=0,s=t[0][0],a=0;for(let e=1;e<t.length;e++)t[e][0]<s&&(s=t[e][0],a=e);let o=t[(a+1)%t.length][0],h=(a+1)%t.length;for(let e=1;e<t.length;e++)t[e][0]<o&&e!==a&&(o=t[e][0],h=e);return t[h][1]<t[a][1]?(e=t[h],n=t[a],a!==(h+1)%4?(r=t[(h+1)%4],i=t[(h+2)%4]):(r=t[(h+2)%4],i=t[(h+3)%4])):(n=t[h],e=t[a],h!==(a+1)%4?(r=t[(a+1)%4],i=t[(a+2)%4]):(r=t[(a+2)%4],i=t[(a+3)%4])),[e,r,i,n]}function distance2Points(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))}function crossVect(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function dotVect(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function computeWidthAndHeigth(t,e,r,i,n,s){let a=Math.max(distance2Points(t,e),distance2Points(i,r)),o=Math.max(distance2Points(t,i),distance2Points(e,r)),h=0,l=0,c=Math.ceil(n/2),u=Math.ceil(s/2),f=a/o,d=[t[0],t[1],1],m=[e[0],e[1],1],g=[i[0],i[1],1],p=[r[0],r[1],1],w=dotVect(crossVect(d,p),g)/dotVect(crossVect(m,p),g),_=dotVect(crossVect(d,p),m)/dotVect(crossVect(g,p),m),b=[w*m[0]-d[0],w*m[1]-d[1],w*m[2]-d[2]],y=[_*g[0]-d[0],_*g[1]-d[1],_*g[2]-d[2]],M=b[0],x=b[1],v=b[2],E=y[0],A=y[1],k=y[2],S=1/(v*k)*(M*E-(M*k+v*E)*c+v*k*c*c+(x*A-(x*k+v*A)*u+v*k*u*u));S=S>=0?Math.sqrt(S):Math.sqrt(-S);let I=new Matrix$2([[S,0,c],[0,S,u],[0,0,1]]),D=inverse(I.transpose()),R=inverse(I),T=Matrix$2.rowVector(b),C=Matrix$2.rowVector(y),$=Math.sqrt(dotVect(T.mmul(D).mmul(R).to1DArray(),b)/dotVect(C.mmul(D).mmul(R).to1DArray(),y));return 0===$||0===f?(h=Math.ceil(a),l=Math.ceil(o)):$<f?(h=Math.ceil(a),l=Math.ceil(h/$)):(l=Math.ceil(o),h=Math.ceil($*l)),[h,l]}function projectionPoint(t,e,r,i,n,s,a,o,h,l,c,u){let[f,d]=[(r*t+i*e+n)/(h*t+l*e+1),(s*t+a*e+o)/(h*t+l*e+1)];return c.getValueXY(Math.floor(f),Math.floor(d),u)}function warpingFourPoints(t,e={}){let{calculateRatio:r=!0}=e;if(4!==t.length)throw new Error(`The array pts must have four elements, which are the four corners. Currently, pts have ${t.length} elements`);let i,n,[s,a,o,h]=t,l=[s,a,o,h],[c,u,f,d]=order4Points(l);r?[i,n]=computeWidthAndHeigth(c,u,f,d,this.width,this.height):(i=Math.ceil(Math.max(distance2Points(c,u),distance2Points(d,f))),n=Math.ceil(Math.max(distance2Points(c,d),distance2Points(u,f))));let m=Image.createFrom(this,{width:i,height:n}),[g,p]=c,[w,_]=u,[b,y]=f,[M,x]=d,[v,E]=[0,0],[A,k]=[0,i-1],[S,I]=[n-1,i-1],[D,R]=[n-1,0],T=new Matrix$2([[v,E,1,0,0,0,-v*g,-E*g],[A,k,1,0,0,0,-A*w,-k*w],[S,I,1,0,0,0,-S*b,-E*b],[D,R,1,0,0,0,-D*M,-R*M],[0,0,0,v,E,1,-v*p,-E*p],[0,0,0,A,k,1,-A*_,-k*_],[0,0,0,S,I,1,-S*y,-I*y],[0,0,0,D,R,1,-D*x,-R*x]]),C=Matrix$2.columnVector([g,w,b,M,p,_,y,x]),$=new SingularValueDecomposition(T).solve(C),[B,P,O,N,L,F,U,H]=$.to1DArray(),Y=new Matrix$2(n,i);for(let t=0;t<this.channels;t++){for(let e=0;e<n;e++)for(let r=0;r<i;r++)Y.set(e,r,projectionPoint(e,r,B,P,O,N,L,F,U,H,this,t));m.setMatrix(Y,{channel:t})}return m}function crop(t={}){let{x:e=0,y:r=0,width:i=this.width-e,height:n=this.height-r}=t;if(this.checkProcessable("max",{bitDepth:[8,16]}),e=Math.round(e),r=Math.round(r),i=Math.round(i),n=Math.round(n),e>this.width-1||r>this.height-1)throw new RangeError(`crop: origin (x:${e}, y:${r}) out of range (${this.width-1}; ${this.height-1})`);if(i<=0||n<=0)throw new RangeError(`crop: width and height (width:${i}; height:${n}) must be positive numbers`);if(e<0||r<0)throw new RangeError(`crop: x and y (x:${e}, y:${r}) must be positive numbers`);if(i>this.width-e||n>this.height-r)throw new RangeError(`crop: (x: ${e}, y:${r}, width:${i}, height:${n}) size is out of range`);let s=Image.createFrom(this,{width:i,height:n,position:[e,r]}),a=i*this.channels,o=r+n,h=0,l=e*this.channels;for(let t=r;t<o;t++){let e=t*this.width*this.channels+l,r=e+a;for(;e<r;e++)s.data[h++]=this.data[e]}return s}function cropAlpha(t={}){this.checkProcessable("cropAlpha",{alpha:1});const{threshold:e=this.maxValue}=t;let r=findLeft(this,e,this.components);if(-1===r)throw new Error("Could not find new dimensions. Threshold may be too high.");let i=findTop(this,e,this.components,r),n=findBottom(this,e,this.components,r),s=findRight(this,e,this.components,r,i,n);return this.crop({x:r,y:i,width:s-r+1,height:n-i+1})}function findLeft(t,e,r){for(let i=0;i<t.width;i++)for(let n=0;n<t.height;n++)if(t.getValueXY(i,n,r)>=e)return i;return-1}function findTop(t,e,r,i){for(let n=0;n<t.height;n++)for(let s=i;s<t.width;s++)if(t.getValueXY(s,n,r)>=e)return n;return-1}function findBottom(t,e,r,i){for(let n=t.height-1;n>=0;n--)for(let s=i;s<t.width;s++)if(t.getValueXY(s,n,r)>=e)return n;return-1}function findRight(t,e,r,i,n,s){for(let a=t.width-1;a>=i;a--)for(let i=n;i<=s;i++)if(t.getValueXY(a,i,r)>=e)return a;return-1}function getFactor(t){if("string"==typeof t){const e=t[t.length-1];t=parseFloat(t),"%"===e&&(t/=100)}return t}function getThreshold$1(t,e){if(!e)throw Error("getThreshold : the maxValue should be specified");if("string"==typeof t){if("%"!==t[t.length-1])throw Error("getThreshold : if the value is a string it must finish by %");return parseFloat(t)/100*e}if("number"==typeof t)return t<1?t*e:t;throw Error("getThreshold : the value is not valid")}function factorDimensions(t,e,r){t=getFactor(t);let i=Math.round(t*e),n=Math.round(t*r);return i<=0&&(i=1),n<=0&&(n=1),{width:i,height:n}}function checkRow(t,e){if(e<0||e>=t.height)throw new RangeError(`row must be included between 0 and ${t.height-1}. Current value: ${e}`)}function checkColumn(t,e){if(e<0||e>=t.width)throw new RangeError(`column must be included between 0 and ${t.width-1}. Current value: ${e}`)}function checkChannel(t,e){if(e<0||e>=t.channels)throw new RangeError(`channel must be included between 0 and ${t.channels-1}. Current value: ${e}`)}const validInterpolations={nearestneighbor:"nearestNeighbor",nearestneighbour:"nearestNeighbor",bilinear:"bilinear"};function checkInterpolation(t){if("string"!=typeof t)throw new TypeError("interpolation must be a string");if(t=t.toLowerCase(),!validInterpolations[t])throw new RangeError(`invalid interpolation algorithm: ${t}`);return validInterpolations[t]}function nearestNeighbor(t,e,r){const i=this.width/e,n=this.height/r;if(this.bitDepth>1)for(let s=0;s<e;s++){const e=Math.floor((s+.5)*i);for(let i=0;i<r;i++){const r=Math.floor((i+.5)*n);for(let n=0;n<this.channels;n++)t.setValueXY(s,i,n,this.getValueXY(e,r,n))}}else for(let s=0;s<e;s++){const e=Math.floor((s+.5)*i);for(let i=0;i<r;i++){const r=Math.floor((i+.5)*n);this.getBitXY(e,r)&&t.setBitXY(s,i)}}}function resize(t={}){const{factor:e=1,interpolation:r=validInterpolations.nearestneighbor,preserveAspectRatio:i=!0}=t,n=checkInterpolation(r);let s=t.width,a=t.height;if(s||(s=a&&i?Math.round(a*(this.width/this.height)):this.width),a||(a=i?Math.round(s*(this.height/this.width)):this.height),({width:s,height:a}=factorDimensions(e,s,a)),s===this.width&&a===this.height){const t=this.clone();return t.position=[0,0],t}let o=Math.round((this.width-s)/2),h=Math.round((this.height-a)/2);const l=Image.createFrom(this,{width:s,height:a,position:[o,h]});switch(n){case validInterpolations.nearestneighbor:nearestNeighbor.call(this,l,s,a);break;default:throw new Error(`unsupported resize interpolation: ${n}`)}return l}function hsv(){this.checkProcessable("hsv",{bitDepth:[8,16],alpha:[0,1],colorModel:[RGB$1]});let t=Image.createFrom(this,{colorModel:HSV}),e=0,r=this.data;for(let i=0;i<r.length;i+=this.channels){let n=r[i],s=r[i+1],a=r[i+2],o=Math.min(n,s,a),h=Math.max(n,s,a),l=h-o,c=0,u=0===h?0:l/h,f=h;if(h!==o){switch(h){case n:c=(s-a)/l+(s<a?6:0);break;case s:c=(a-n)/l+2;break;case a:c=(n-s)/l+4;break;default:throw new Error("unreachable")}c/=6}t.data[e++]=c*this.maxValue,t.data[e++]=u*this.maxValue,t.data[e++]=f,this.alpha&&(t.data[e++]=r[i+3])}return t}function hsl$1(){this.checkProcessable("hsl",{bitDepth:[8,16],alpha:[0,1],colorModel:[RGB$1]});let t=Image.createFrom(this,{colorModel:HSL}),e=Math.floor(this.maxValue/2),r=0,i=this.data;for(let n=0;n<i.length;n+=this.channels){let s=i[n],a=i[n+1],o=i[n+2],h=Math.max(s,a,o),l=Math.min(s,a,o),c=0,u=0,f=(h+l)/2;if(h!==l){let t=h-l;switch(u=f>e?t/(2-h-l):t/(h+l),h){case s:c=(a-o)/t+(a<o?6:0);break;case a:c=(o-s)/t+2;break;case o:c=(s-a)/t+4;break;default:throw new Error("unreachable")}c/=6}t.data[r++]=c*this.maxValue,t.data[r++]=u*this.maxValue,t.data[r++]=f,this.alpha&&(t.data[r++]=i[n+3])}return t}function cmyk(){this.checkProcessable("cmyk",{bitDepth:[8,16],alpha:[0,1],colorModel:[RGB$1]});let t=Image.createFrom(this,{components:4,colorModel:CMYK$1}),e=0,r=this.data;for(let i=0;i<r.length;i+=this.channels){let n=r[i],s=r[i+1],a=r[i+2],o=Math.min(this.maxValue-n,this.maxValue-s,this.maxValue-a),h=(this.maxValue-n-o)/(1-o/this.maxValue),l=(this.maxValue-s-o)/(1-o/this.maxValue),c=(this.maxValue-a-o)/(1-o/this.maxValue);t.data[e++]=Math.round(h),t.data[e++]=Math.round(l),t.data[e++]=Math.round(c),t.data[e++]=Math.round(o),this.alpha&&(t.data[e++]=r[i+3])}return t}function rgba8(){return new Image(this.width,this.height,this.getRGBAData(),{kind:"RGBA",parent:this})}const methods$1={luma709:(t,e,r)=>(console.log("luma709"),t),luma601:(t,e,r)=>(console.log("red"),t),maximum:(t,e,r)=>t,minimum:(t,e,r)=>t,average:(t,e,r)=>t,minmax:(t,e,r)=>t,red:t=>t,green:(t,e)=>e,blue:(t,e,r)=>r,cyan(t,e,r,i){let n=methods$1.black(t,e,r,i);return(i.maxValue-t-n)/(1-n/i.maxValue)>>0},magenta(t,e,r,i){let n=methods$1.black(t,e,r,i);return(i.maxValue-e-n)/(1-n/i.maxValue)>>0},yellow(t,e,r,i){let n=methods$1.black(t,e,r,i);return(i.maxValue-r-n)/(1-n/i.maxValue)>>0},black:(t,e,r,i)=>Math.min(i.maxValue-t,i.maxValue-e,i.maxValue-r),hue(t,e,r,i){let n=methods$1.min(t,e,r),s=methods$1.max(t,e,r);if(s===n)return 0;let a=0,o=s-n;switch(s){case t:a=(e-r)/o+(e<r?6:0);break;case e:a=(r-t)/o+2;break;case r:a=(t-e)/o+4;break;default:throw new Error("unreachable")}return a/6*i.maxValue>>0},saturation(t,e,r,i){let n=methods$1.min(t,e,r),s=methods$1.max(t,e,r);return 0===s?0:(s-n)/s*i.maxValue},lightness:(t,e,r)=>(console.log("lightnesslightnesslightness"),t)};Object.defineProperty(methods$1,"luminosity",{enumerable:!1,value:methods$1.lightness}),Object.defineProperty(methods$1,"luminance",{enumerable:!1,value:methods$1.lightness}),Object.defineProperty(methods$1,"min",{enumerable:!1,value:methods$1.minimum}),Object.defineProperty(methods$1,"max",{enumerable:!1,value:methods$1.maximum}),Object.defineProperty(methods$1,"brightness",{enumerable:!1,value:methods$1.maximum});const names$1={};function grey(t={}){console.log("greygreygrey");let{algorithm:e="luma709",keepAlpha:r=!1,mergeAlpha:i=!0}=t;if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("algorithm must be a string or a function");this.checkProcessable("grey",{bitDepth:[8,16],alpha:[0,1]}),console.log("this.components",this.components),1===this.components&&(e="red"),r&=this.alpha,i&=this.alpha,r&&(i=!1);let n,s=getOutputImage(this,t,{components:1,alpha:r,colorModel:GREY$1});if("function"==typeof e)n=e;else if(n=methods$1[e.toLowerCase()],!n)throw new Error(`unsupported grey algorithm: ${e}`);let a=0;for(let t=0;t<this.data.length;t+=this.channels)i?(s.data[a++]=clamp(n(this.data[t],this.data[t+1],this.data[t+2],this)*this.data[t+this.components]/this.maxValue,this),s.data[a++]=this.data[t+3]):(s.data[a++]=clamp(n(this.data[t],this.data[t+1],this.data[t+2],this),this),s.alpha&&(s.data[a++]=this.data[t+this.components]));return s}function huang(t){let e=0;for(let r=0;r<t.length;r++)if(0!==t[r]){e=r;break}let r=t.length-1;for(let i=t.length-1;i>=e;i--)if(0!==t[i]){r=i;break}let i=1/(r-e),n=new Array(t.length),s=0,a=0;for(let r=e;r<t.length;r++)s+=r*t[r],a+=t[r],n[r]=s/a;let o=new Array(t.length);s=a=0;for(let e=r;e>0;e--)s+=e*t[e],a+=t[e],o[e-1]=s/a;let h=-1,l=Number.MAX_VALUE;for(let e=0;e<t.length;e++){let r,s=0;for(let a=0;a<=e;a++)r=1/(1+i*Math.abs(a-n[e])),r<1e-6||r>.999999||(s+=t[a]*(-r*Math.log(r)-(1-r)*Math.log(1-r)));for(let n=e+1;n<t.length;n++)r=1/(1+i*Math.abs(n-o[e])),r<1e-6||r>.999999||(s+=t[n]*(-r*Math.log(r)-(1-r)*Math.log(1-r)));s<l&&(l=s,h=e)}return h}function intermodes(t){let e=t.slice(),r=0;for(;!bimodalTest$1(e);){let i=0,n=0,s=e[0];for(let r=0;r<t.length-1;r++)i=n,n=s,s=e[r+1],e[r]=(i+n+s)/3;if(e[t.length-1]=(n+s)/3,r++,r>1e4)throw new Error("Intermodes Threshold not found after 10000 iterations")}let i=0;for(let r=1;r<t.length-1;r++)e[r-1]<e[r]&&e[r+1]<e[r]&&(i+=r);return Math.floor(i/2)}function bimodalTest$1(t){let e=!1,r=0;for(let e=1;e<t.length-1;e++)if(t[e-1]<t[e]&&t[e+1]<t[e]&&(r++,r>2))return!1;return 2===r&&(e=!0),e}function isodata(t){let e,r,i,n,s=0;for(let e=1;e<t.length;e++)if(t[e]>0){s=e+1;break}for(;;){e=0,i=0;for(let r=0;r<s;r++)i+=t[r],e+=t[r]*r;n=0,r=0;for(let e=s+1;e<t.length;e++)r+=t[e],n+=t[e]*e;if(i>0&&r>0&&(e/=i,n/=r,s===Math.round((e+n)/2)))break;if(s++,s>t.length-2)throw new Error("Threshold not found")}return s}function li(t,e){let r,i,n,s,a,o,h,l,c,u,f,d;f=.5,u=0;for(let e=0;e<t.length;e++)u+=e*t[e];u/=e,h=u;do{o=h,r=o+.5|0,i=0,s=0;for(let e=0;e<=r;e++)i+=e*t[e],s+=t[e];l=0===s?0:i/s,n=0,a=0;for(let e=r+1;e<t.length;e++)n+=e*t[e],a+=t[e];c=0===a?0:n/a,d=(l-c)/(Math.log(l)-Math.log(c)),h=d<-Number.EPSILON?d-.5|0:d+.5|0}while(Math.abs(h-o)>.5);return r}function maxEntropy(t,e){let r=new Array(t.length);for(let i=0;i<t.length;i++)r[i]=t[i]/e;let i=new Array(t.length),n=new Array(t.length);i[0]=r[0],n[0]=1-i[0];for(let e=1;e<t.length;e++)i[e]=i[e-1]+r[e],n[e]=1-i[e];let s=0;for(let e=0;e<t.length;e++)if(Math.abs(i[e])>=Number.EPSILON){s=e;break}let a=t.length-1;for(let e=t.length-1;e>=s;e--)if(Math.abs(n[e])>=Number.EPSILON){a=e;break}let o,h,l,c=-1,u=Number.MIN_VALUE;for(let e=s;e<=a;e++){h=0;for(let n=0;n<=e;n++)0!==t[n]&&(h-=r[n]/i[e]*Math.log(r[n]/i[e]));l=0;for(let i=e+1;i<t.length;i++)0!==t[i]&&(l-=r[i]/n[e]*Math.log(r[i]/n[e]));o=h+l,u<o&&(u=o,c=e)}return c}function mean$1(t,e){let r=0;for(let e=0;e<t.length;e++)r+=e*t[e];return Math.floor(r/e)}function minError(t,e){let r,i,n,s,a,o,h,l,c,u,f,d,m=-2,g=0;for(let e=0;e<t.length;e++)g+=e*t[e];for(g/=e,r=g;r!==m;){let e=sumA(t,r),g=sumA(t,t.length-1),p=sumB(t,r),w=sumB(t,t.length-1),_=sumC(t,r);if(i=p/e,n=(w-p)/(g-e),s=e/g,a=(g-e)/g,o=_/e-i*i,h=(sumC(t,t.length-1)-_)/(g-e)-n*n,l=1/o-1/h,c=i/o-n/h,u=i*i/o-n*n/h+Math.log10(o*(a*a)/(h*(s*s))),f=c*c-l*u,f<0)return r;m=r,d=(c+Math.sqrt(f))/l,r=isNaN(d)?m:Math.floor(d)}return r}function sumA(t,e){let r=0;for(let i=0;i<=e;i++)r+=t[i];return r}function sumB(t,e){let r=0;for(let i=0;i<=e;i++)r+=i*t[i];return r}function sumC(t,e){let r=0;for(let i=0;i<=e;i++)r+=i*i*t[i];return r}function minimum(t){if(t.length<2)return 0;let e=0,r=-1,i=-1,n=new Array(t.length);for(let e=0;e<t.length;e++)n[e]=t[e],t[e]>0&&(i=e);for(;!bimodalTest(n);)if(n=smoothed(n),e++,e>1e4)return r;return r=minimumBetweenPeeks(n,i),r}function smoothed(t){let e=new Array(t.length);for(let r=1;r<t.length-1;r++)e[r]=(t[r-1]+t[r]+t[r+1])/3;return e[0]=(t[0]+t[1])/3,e[t.length-1]=(t[t.length-2]+t[t.length-1])/3,e}function minimumBetweenPeeks(t,e){let r;for(let i=1;i<e;i++)if(t[i-1]>t[i]&&t[i+1]>=t[i]){r=i;break}return r}function bimodalTest(t){let e=t.length,r=!1,i=0;for(let r=1;r<e-1;r++)if(t[r-1]<t[r]&&t[r+1]<t[r]&&(i++,i>2))return!1;return 2===i&&(r=!0),r}function moments(t,e){let r,i,n,s,a,o,h=0,l=0,c=0,u=0,f=-1,d=t.length,m=new Array(d);for(let r=0;r<d;r++)m[r]=t[r]/e;for(let t=0;t<d;t++)h+=t*m[t],l+=t*t*m[t],c+=t*t*t*m[t];i=1*l-h*h,n=(-l*l+h*c)/i,s=(1*-c+l*h)/i,a=.5*(-s-Math.sqrt(s*s-4*n)),o=.5*(-s+Math.sqrt(s*s-4*n)),r=(o-h)/(o-a);for(let t=0;t<d;t++)if(u+=m[t],u>r){f=t;break}return f}function otsu(t,e){let r=0,i=0,n=0,s=0,a=0;for(let e=0;e<t.length;e++)a+=e*t[e];for(let o=0;o<t.length;o++){i+=t[o];const h=e-i;if(0===i||0===h)continue;r+=o*t[o];const l=(a-r)/h,c=i*h*(r/i-l)*(r/i-l);c>=n&&(s=o,n=c)}return s}function percentile(t){let e=-1,r=new Array(t.length),i=partialSum(t,t.length-1),n=1;for(let s=0;s<t.length;s++)r[s]=Math.abs(partialSum(t,s)/i-.5),r[s]<n&&(n=r[s],e=s);return e}function partialSum(t,e){let r=0;for(let i=0;i<=e;i++)r+=t[i];return r}function assertNumber(t){if("number"!=typeof t)throw new TypeError("Expected a number")}Object.keys(methods$1).forEach((t=>{names$1[t]=t}));var ascending=(t,e)=>(assertNumber(t),assertNumber(e),Number.isNaN(t)?-1:Number.isNaN(e)?1:t-e);function renyiEntropy(t,e){let r,i,n,s=new Array(t.length),a=new Array(t.length),o=new Array(t.length),h=0,l=0,c=0,u=0,f=0,d=0;for(let r=0;r<t.length;r++)s[r]=t[r]/e;a[0]=s[0],o[0]=1-a[0];for(let e=1;e<t.length;e++)a[e]=a[e-1]+s[e],o[e]=1-a[e];i=0;for(let e=0;e<t.length;e++)if(Math.abs(a[e])>=Number.EPSILON){i=e;break}n=t.length-1;for(let e=t.length-1;e>=i;e--)if(Math.abs(o[e])>=Number.EPSILON){n=e;break}for(let e=i;e<=n;e++){let r=0,i=0,n=0;for(let o=0;o<=e;o++)0!==t[o]&&(r-=s[o]/a[e]*Math.log(s[o]/a[e])),i+=Math.sqrt(s[o]/a[e]),n+=s[o]*s[o]/(a[e]*a[e]);let m=0,g=0,p=0;for(let r=e+1;r<t.length;r++)0!==t[r]&&(m-=s[r]/o[e]*Math.log(s[r]/o[e])),g+=Math.sqrt(s[r]/o[e]),p+=s[r]*s[r]/(o[e]*o[e]);let w=r+m,_=2*(i*g>0?Math.log(i*g):0),b=-1*(n*p>0?Math.log(n*p):0);w>u&&(u=w,h=e),_>f&&(f=_,l=e),b>d&&(d=b,c=e)}let m,g=[h,l,c];g.sort(ascending),m=Math.abs(g[0]-g[1])<=5?Math.abs(g[1]-g[2])<=5?[1,2,1]:[0,1,3]:Math.abs(g[1]-g[2])<=5?[3,1,0]:[1,2,1];let p=a[g[2]]-a[g[0]];return r=Math.round(g[0]*(a[g[0]]+.25*p*m[0])+.25*g[1]*p*m[1]+g[2]*(o[g[2]]+.25*p*m[2])),r}function shanbhag(t,e){let r=new Array(t.length);for(let i=0;i<t.length;i++)r[i]=t[i]/e;let i=new Array(t.length),n=new Array(t.length);i[0]=r[0],n[0]=1-i[0];for(let e=1;e<t.length;e++)i[e]=i[e-1]+r[e],n[e]=1-i[e];let s=0;for(let e=0;e<t.length;e++)if(Math.abs(i[e])>=Number.EPSILON){s=e;break}let a=t.length-1;for(let e=t.length-1;e>=s;e--)if(Math.abs(n[e])>=Number.EPSILON){a=e;break}let o,h,l,c,u=-1,f=Number.MAX_VALUE;for(let e=s;e<=a;e++){l=0,o=.5/i[e];for(let t=1;t<=e;t++)l-=r[t]*Math.log(1-o*i[t-1]);l*=o,c=0,o=.5/n[e];for(let i=e+1;i<t.length;i++)c-=r[i]*Math.log(1-o*n[i]);c*=o,h=Math.abs(l-c),h<f&&(f=h,u=e)}return u}function triangle$1(t){let e=0,r=0,i=0,n=0;for(let r=0;r<t.length;r++)if(t[r]>0){e=r;break}e>0&&e--;for(let e=t.length-1;e>0;e--)if(t[e]>0){n=e;break}n<t.length-1&&n++;for(let e=0;e<t.length;e++)t[e]>r&&(i=e,r=t[e]);let s,a,o,h=!1;if(i-e<n-i){h=!0;let r=0,s=t.length-1;for(;r<s;){let e=t[r];t[r]=t[s],t[s]=e,r++,s--}e=t.length-1-n,i=t.length-1-i}if(e===i)return e;s=t[i],a=e-i,o=Math.sqrt(s*s+a*a),s/=o,a/=o,o=s*e+a*t[e];let l=e,c=0;for(let r=e+1;r<=i;r++){let e=s*r+a*t[r]-o;e>c&&(l=r,c=e)}if(l--,h){let e=0,r=t.length-1;for(;e<r;){let i=t[e];t[e]=t[r],t[r]=i,e++,r--}return t.length-1-l}return l}function yen(t,e){let r=new Array(t.length);for(let i=0;i<t.length;i++)r[i]=t[i]/e;let i=new Array(t.length);i[0]=r[0];for(let e=1;e<t.length;e++)i[e]=i[e-1]+r[e];let n=new Array(t.length);n[0]=r[0]*r[0];for(let e=1;e<t.length;e++)n[e]=n[e-1]+r[e]*r[e];let s=new Array(t.length);s[t.length-1]=0;for(let e=t.length-2;e>=0;e--)s[e]=s[e+1]+r[e+1]*r[e+1];let a,o=-1,h=Number.MIN_VALUE;for(let e=0;e<t.length;e++)a=-1*(n[e]*s[e]>0?Math.log(n[e]*s[e]):0)+2*(i[e]*(1-i[e])>0?Math.log(i[e]*(1-i[e])):0),a>h&&(h=a,o=e);return o}const methods={huang:huang,intermodes:intermodes,isodata:isodata,li:li,maxentropy:maxEntropy,mean:mean$1,minerror:minError,minimum:minimum,moments:moments,otsu:otsu,percentile:percentile,renyientropy:renyiEntropy,shanbhag:shanbhag,triangle:triangle$1,yen:yen},names={};function getThreshold(t={}){let{algorithm:e=names.otsu}=t;this.checkProcessable("getThreshold",{components:1,bitDepth:[8,16]});let r=methods[e.toLowerCase()];if(r){return r(this.getHistogram(),this.size)}throw new Error(`unknown thresholding algorithm: ${e}`)}Object.keys(methods).forEach((t=>{names[t]=t}));const THRESHOLD="threshold";function mask(t={}){let{algorithm:e=THRESHOLD,threshold:r=.5,useAlpha:i=!0,invert:n=!1}=t;this.checkProcessable("mask",{components:1,bitDepth:[8,16]}),r=e===THRESHOLD?getThreshold$1(r,this.maxValue):getThreshold.call(this,t);let s=new Image(this.width,this.height,{kind:"BINARY",parent:this}),a=0;if(this.alpha&&i)for(let t=0;t<this.data.length;t+=this.channels){let e=this.data[t]+(this.maxValue-this.data[t])*(this.maxValue-this.data[t+1])/this.maxValue;(n&&e<=r||!n&&e>=r)&&s.setBit(a),a++}else for(let t=0;t<this.data.length;t+=this.channels)(n&&this.data[t]<=r||!n&&this.data[t]>=r)&&s.setBit(a),a++;return s}function copyImage(t,e,r,i){let n=t.width,s=t.height,a=e.width,o=t.channels;for(let h=0;h<n;h++)for(let l=0;l<s;l++)for(let s=0;s<o;s++){let c=(l*n+h)*o+s,u=((i+l)*a+r+h)*o+s;e.data[u]=t.data[c]}}function pad(t={}){let{size:e=0,algorithm:r="copy",color:i}=t;if(this.checkProcessable("pad",{bitDepth:[8,16]}),"set"===r){if(i.length!==this.channels)throw new Error(`pad: the color array must have the same length as the number of channels. Here: ${this.channels}`);for(let t=0;t<i.length;t++)0===i[t]&&(i[t]=.001)}else i=_newArray_1_0_0_newArray(this.channels,null);Array.isArray(e)||(e=[e,e]);let n=this.width+2*e[0],s=this.height+2*e[1],a=this.channels,o=Image.createFrom(this,{width:n,height:s});copyImage(this,o,e[0],e[1]);for(let t=e[0];t<n-e[0];t++)for(let r=0;r<a;r++){let h=i[r]||o.data[(e[1]*n+t)*a+r];for(let i=0;i<e[1];i++)o.data[(i*n+t)*a+r]=h;h=i[r]||o.data[((s-e[1]-1)*n+t)*a+r];for(let i=s-e[1];i<s;i++)o.data[(i*n+t)*a+r]=h}for(let t=0;t<s;t++)for(let r=0;r<a;r++){let s=i[r]||o.data[(t*n+e[0])*a+r];for(let i=0;i<e[0];i++)o.data[(t*n+i)*a+r]=s;s=i[r]||o.data[(t*n+n-e[0]-1)*a+r];for(let i=n-e[0];i<n;i++)o.data[(t*n+i)*a+r]=s}return o}function colorDepth(t=8){if(this.checkProcessable("colorDepth",{bitDepth:[1,8,16]}),![8,16].includes(t))throw Error("You need to specify the new colorDepth as 8 or 16");if(this.bitDepth===t)return this.clone();let e=Image.createFrom(this,{bitDepth:t});switch(t){case 8:if(1===this.bitDepth)for(let t=0;t<this.size;t++)this.getBit(t)&&(e.data[t]=255);else for(let t=0;t<this.data.length;t++)e.data[t]=this.data[t]>>8;break;case 16:if(1===this.bitDepth)for(let t=0;t<this.size;t++)this.getBit(t)&&(e.data[t]=65535);else for(let t=0;t<this.data.length;t++)e.data[t]=this.data[t]<<8|this.data[t];break;default:throw new Error("colorDepth conversion unexpected case")}return e}function rotateFree(t,e={}){const{interpolation:r=validInterpolations.nearestneighbor,width:i=this.width,height:n=this.height}=e;if("number"!=typeof t)throw new TypeError("degrees must be a number");const s=checkInterpolation(r),a=t*Math.PI/180,o=Math.floor(Math.abs(i*Math.cos(a))+Math.abs(n*Math.sin(a))),h=Math.floor(Math.abs(n*Math.cos(a))+Math.abs(i*Math.sin(a))),l=Image.createFrom(this,{width:o,height:h}),c=Math.cos(-a),u=Math.sin(-a);let f=o/2,d=h/2;o%2==0?(f-=.5,h%2==0?d-=.5:d=Math.floor(d)):(f=Math.floor(f),h%2==0?d-=.5:d=Math.floor(d));const m=Math.floor(i/2-f),g=Math.floor(n/2-d);switch(s){case validInterpolations.nearestneighbor:return rotateNearestNeighbor(this,l,m,g,f,d,c,u);case validInterpolations.bilinear:return rotateBilinear(this,l,m,g,f,d,c,u);default:throw new Error(`unsupported rotate interpolation: ${s}`)}}function rotateNearestNeighbor(t,e,r,i,n,s,a,o){for(let h=0;h<e.width;h+=1)for(let l=0;l<e.height;l+=1)for(let c=0;c<t.channels;c++){let u=Math.round((h-n)*a-(l-s)*o+n)+r,f=Math.round((l-s)*a+(h-n)*o+s)+i;u<0||u>=t.width||f<0||f>=t.height?1===t.alpha&&c===t.channels-1?e.setValueXY(h,l,c,0):e.setValueXY(h,l,c,t.maxValue):e.setValueXY(h,l,c,t.getValueXY(u,f,c))}return e}function rotateBilinear(t,e,r,i,n,s,a,o){let h=t.width*t.channels;for(let l=0;l<e.height;l++)for(let c=0;c<e.width;c++){let u=(c-n)*a-(l-s)*o+n+r,f=(l-s)*a+(c-n)*o+s+i,d=0|u,m=0|f,g=u-d,p=f-m;for(let r=0;r<t.channels;r++)if(u<0||u>=t.width||f<0||f>=t.height)1===t.alpha&&r===t.channels-1?e.setValueXY(c,l,r,0):e.setValueXY(c,l,r,t.maxValue);else{let i=(m*t.width+d)*t.channels+r,n=t.data[i],s=t.data[i+t.channels],a=t.data[i+h],o=n+g*(s-n)+p*(a-n)+g*p*(n-s-a+t.data[i+h+t.channels])|0;e.setValueXY(c,l,r,o)}}return e}function rotate$1(t,e){if("number"!=typeof t)throw new TypeError("angle must be a number");switch(t<0&&(t=360*Math.ceil(-t/360)+t),t%360){case 0:return this.clone();case 90:return rotateRight.call(this);case 180:return rotate180.call(this);case 270:return rotateLeft.call(this);default:return rotateFree.call(this,t,e)}}function rotateLeft(){const t=Image.createFrom(this,{width:this.height,height:this.width}),e=t.height-1;for(let r=0;r<this.height;r++)for(let i=0;i<this.width;i++)for(let n=0;n<this.channels;n++)t.setValueXY(r,e-i,n,this.getValueXY(i,r,n));return t}function rotateRight(){const t=Image.createFrom(this,{width:this.height,height:this.width}),e=t.width-1;for(let r=0;r<this.height;r++)for(let i=0;i<this.width;i++)for(let n=0;n<this.channels;n++)t.setValueXY(e-r,i,n,this.getValueXY(i,r,n));return t}function rotate180(){const t=Image.createFrom(this),e=t.width-1,r=t.height-1;for(let i=0;i<this.height;i++)for(let n=0;n<this.width;n++)for(let s=0;s<this.channels;s++)t.setValueXY(e-n,r-i,s,this.getValueXY(n,i,s));return t}function insert(t,e={}){const r=getImageParameters(t);this.checkProcessable("insert",r);let{x:i=0,y:n=0}=e;const s=getOutputImageOrInPlace(this,e,{copy:!0}),a=Math.min(s.height,n+t.height),o=Math.min(s.width,i+t.width);if(1===s.bitDepth)for(let e=n;e<a;e++)for(let r=i;r<o;r++){t.getBitXY(r-i,e-n)?s.setBitXY(r,e):s.clearBitXY(r,e)}else for(let e=n;e<a;e++)for(let r=i;r<o;r++)s.setPixelXY(r,e,t.getPixelXY(r-i,e-n));return s}function setBorder(t={}){let{size:e=0,algorithm:r="copy",color:i}=t;if(this.checkProcessable("setBorder",{bitDepth:[8,16,32,64]}),"set"===r){if(i.length!==this.channels)throw new Error(`setBorder: the color array must have the same length as the number of channels. Here: ${this.channels}`);for(let t=0;t<i.length;t++)0===i[t]&&(i[t]=.001)}else i=_newArray_1_0_0_newArray(this.channels,null);Array.isArray(e)||(e=[e,e]);let n=e[0],s=e[1],a=this.channels;for(let t=n;t<this.width-n;t++)for(let e=0;e<a;e++){let r=i[e]||this.data[(t+this.width*s)*a+e];for(let i=0;i<s;i++)this.data[(i*this.width+t)*a+e]=r;r=i[e]||this.data[(t+this.width*(this.height-s-1))*a+e];for(let i=this.height-s;i<this.height;i++)this.data[(i*this.width+t)*a+e]=r}for(let t=0;t<this.height;t++)for(let e=0;e<a;e++){let r=i[e]||this.data[(t*this.width+n)*a+e];for(let i=0;i<n;i++)this.data[(t*this.width+i)*a+e]=r;r=i[e]||this.data[(t*this.width+this.width-n-1)*a+e];for(let i=this.width-n;i<this.width;i++)this.data[(t*this.width+i)*a+e]=r}return this}function split(t={}){let{preserveAlpha:e=!0}=t;if(this.checkProcessable("split",{bitDepth:[8,16]}),1===this.components)return new Stack([this.clone()]);let r=new Stack,i=this.data;if(this.alpha&&e)for(let t=0;t<this.components;t++){let e=Image.createFrom(this,{components:1,alpha:!0,colorModel:GREY$1}),n=0;for(let r=0;r<i.length;r+=this.channels)e.data[n++]=i[r+t],e.data[n++]=i[r+this.components];r.push(e)}else for(let t=0;t<this.channels;t++){let e=Image.createFrom(this,{components:1,alpha:!1,colorModel:GREY$1}),n=0;for(let r=0;r<i.length;r+=this.channels)e.data[n++]=i[r+t];r.push(e)}return r}function getChannel(t,e={}){let{keepAlpha:r=!1,mergeAlpha:i=!1}=e;r&=this.alpha,i&=this.alpha,this.checkProcessable("getChannel",{bitDepth:[8,16]}),t=validateChannel(this,t);let n=Image.createFrom(this,{components:1,alpha:r,colorModel:GREY$1}),s=0;for(let e=0;e<this.data.length;e+=this.channels)i?n.data[s++]=this.data[e+t]*this.data[e+this.components]/this.maxValue:(n.data[s++]=this.data[e+t],r&&(n.data[s++]=this.data[e+this.components]));return n}function combineChannels(t=defaultCombineMethod,e={}){let{mergeAlpha:r=!1,keepAlpha:i=!1}=e;r&=this.alpha,i&=this.alpha,this.checkProcessable("combineChannels",{bitDepth:[8,16]});let n=Image.createFrom(this,{components:1,alpha:i,colorModel:GREY$1}),s=0;for(let e=0;e<this.size;e++){let a=t(this.getPixel(e));r?n.data[s++]=a*this.data[e*this.channels+this.components]/this.maxValue:(n.data[s++]=a,i&&(n.data[s++]=this.data[e*this.channels+this.components]))}return n}function defaultCombineMethod(t){return(t[0]+t[1]+t[2])/3}function setChannel(t,e){if(this.checkProcessable("setChannel",{bitDepth:[8,16]}),e.checkProcessable("setChannel (image parameter check)",{bitDepth:[this.bitDepth],alpha:[0],components:[1]}),e.width!==this.width||e.height!==this.height)throw new Error("Images must have exactly the same width and height");let r=t=validateChannel(this,t);for(let t=0;t<e.data.length;t++)this.data[r]=e.data[t],r+=this.channels;return this}function getSimilarity(t,e={}){let{shift:r=[0,0],average:i,channels:n,defaultAlpha:s,normalize:a,border:o=[0,0]}=e;if(this.checkProcessable("getSimilarity",{bitDepth:[8,16]}),Array.isArray(o)||(o=[o,o]),n=validateArrayOfChannels(this,{channels:n,defaultAlpha:s}),this.bitDepth!==t.bitDepth)throw new Error("Both images must have the same bitDepth");if(this.channels!==t.channels)throw new Error("Both images must have the same number of channels");if(this.colorModel!==t.colorModel)throw new Error("Both images must have the same colorModel");void 0===i&&(i=!0);let h=Math.max(o[0],-r[0]),l=Math.min(this.width-o[0],this.width-r[0]),c=Math.max(o[1],-r[1]),u=Math.min(this.height-o[1],this.height-r[1]),f=_newArray_1_0_0_newArray(n.length,0);for(let e=0;e<n.length;e++){let i=n[e],s=a?this.sum[i]:Math.max(this.sum[i],t.sum[i]),o=a?t.sum[i]:Math.max(this.sum[i],t.sum[i]);if(0!==s&&0!==o)for(let n=h;n<l;n++)for(let a=c;a<u;a++){let h=n*this.multiplierX+a*this.multiplierY+i,l=h+r[0]*this.multiplierX+r[1]*this.multiplierY;f[e]+=Math.min(this.data[h]/s,t.data[l]/o)}}return i?f.reduce(((t,e)=>t+e))/f.length:f}function getPixelsGrid(t={}){let{sampling:e=[10,10],painted:r=!1,mask:i}=t;this.checkProcessable("getPixelsGrid",{bitDepth:[8,16],channels:1}),Array.isArray(e)||(e=[e,e]);const n=e[0],s=e[1],a=[],o=[],h=this.width/n,l=this.height/s;let c=Math.floor(h/2);for(let t=0;t<n;t++){let t=Math.floor(l/2);for(let e=0;e<s;e++){let e=Math.round(c),r=Math.round(t);i&&!i.getBitXY(e,r)||(a.push([e,r]),o.push(this.getPixelXY(e,r))),t+=l}c+=h}const u={xyS:a,zS:o};return r&&(u.painted=this.rgba8().paintPoints(a)),u}function Matrix(t,e,r){const i=new Array(t);for(let r=0;r<t;r++)i[r]=new Array(e);if(r)for(let n=0;n<t;n++)for(let t=0;t<e;t++)i[n][t]=r;return i.width=t,i.height=e,Object.setPrototypeOf(i,Matrix.prototype),i}function getBestMatch(t,e={}){let{border:r}=e;if(this.checkProcessable("getChannel",{bitDepth:[8,16]}),this.bitDepth!==t.bitDepth)throw new Error("Both images must have the same bitDepth");if(this.channels!==t.channels)throw new Error("Both images must have the same number of channels");if(this.colorModel!==t.colorModel)throw new Error("Both images must have the same colorModel");let i=new Matrix(t.width,t.height,-1/0),n=Math.floor(t.width/2),s=Math.floor(t.height/2),a=n,o=s,h=!1;for(;!h;){let e=i.localSearch(n,s,-1/0);for(let n=0;n<e.length;n++){let s=e[n],h=this.getSimilarity(t,{border:r,shift:[a-s[0],o-s[1]]});i[s[0]][s[1]]=h}let l=i.localMax(n,s);l.position[0]!==n||l.position[1]!==s?(n=l.position[0],s=l.position[1]):h=!0}return[n-a,s-o]}function getRow(t,e=0){this.checkProcessable("getRow",{bitDepth:[8,16]}),checkRow(this,t),checkChannel(this,e);let r=new Array(this.width),i=0,n=t*this.width*this.channels+e,s=n+this.width*this.channels;for(let t=n;t<s;t+=this.channels)r[i++]=this.data[t];return r}function getColumn(t,e=0){this.checkProcessable("getColumn",{bitDepth:[8,16]}),checkColumn(this,t),checkChannel(this,e);let r=new Array(this.height),i=0,n=this.width*this.channels;for(let s=e+t*this.channels;s<this.data.length;s+=n)r[i++]=this.data[s];return r}function getMatrix(t={}){let{channel:e}=t;if(this.checkProcessable("getMatrix",{bitDepth:[8,16]}),void 0===e){if(this.components>1)throw new RangeError("You need to define the channel for an image that contains more than one channel");e=0}let r=new Matrix$2(this.height,this.width);for(let t=0;t<this.height;t++)for(let i=0;i<this.width;i++)r.set(t,i,this.getValueXY(i,t,e));return r}function setMatrix(t,e={}){t=new Matrix$2(t);let{channel:r}=e;if(this.checkProcessable("getMatrix",{bitDepth:[8,16]}),void 0===r){if(this.components>1)throw new RangeError("You need to define the channel for an image that contains more than one channel");r=0}if(this.width!==t.columns||this.height!==t.rows)throw new RangeError("The size of the matrix must be equal to the size of the image");for(let e=0;e<this.height;e++)for(let i=0;i<this.width;i++)this.setValueXY(i,e,r,t.get(e,i))}function getPixelsArray(){this.checkProcessable("getPixelsArray",{bitDepth:[8,16,32]});let t=new Array(this.size),e=0;for(let r=0;r<this.data.length;r+=this.channels){let i=new Array(this.components);for(let t=0;t<this.components;t++)i[t]=this.data[r+t];t[e++]=i}return t}function getIntersection(t){let e=this,r=e.getClosestCommonParent(t),i=e.getRelativePosition(r,{defaultFurther:!0}),n=getRelativePositionForAllPixels(e,i),s=t.getRelativePosition(r,{defaultFurther:!0}),a=getRelativePositionForAllPixels(t,s),o=getCommonSurface(n,a),h={whitePixelsMask1:[],whitePixelsMask2:[],commonWhitePixels:[]};for(let r=0;r<o.length;r++){let n=o[r],a=[n[0]-i[0],n[1]-i[1]],l=[n[0]-s[0],n[1]-s[1]],c=e.getBitXY(a[0],a[1]),u=t.getBitXY(l[0],l[1]);1===c&&1===u&&h.commonWhitePixels.push(n)}for(let t=0;t<n.length;t++){let r,i;0!==t&&(r=Math.floor(t/e.width),i=t%e.width),1===e.getBitXY(r,i)&&h.whitePixelsMask1.push(n[t])}for(let e=0;e<a.length;e++){let r=0,i=0;0!==e&&(r=Math.floor(e/t.width),i=e%t.width),1===t.getBitXY(r,i)&&h.whitePixelsMask2.push(a[e])}return h}function getRelativePositionForAllPixels(t,e){let r=[];for(let i=0;i<t.height;i++)for(let n=0;n<t.width;n++){let t=[i,n];r.push([t[0]+e[0],t[1]+e[1]])}return r}function getCommonSurface(t,e){let r=0,i=0,n=[];for(;r<t.length&&i<e.length;)t[r][0]===e[i][0]&&t[r][1]===e[i][1]?(n.push(t[r]),r++,i++):t[r][0]<e[i][0]||t[r][0]===e[i][0]&&t[r][1]<e[i][1]?r++:i++;return n}function getClosestCommonParent(t){let e,r=getDepth(this),i=getDepth(t);if(e=r>=i?getFurthestParent(this,r):getFurthestParent(t,i),0===r||0===i)return e;let n=this,s=t;for(;r!==i;)if(r>i){if(n=n.parent,null===n)return e;r-=1}else{if(s=s.parent,null===s)return e;i-=1}for(;n!==s&&null!==n&&null!==s;)if(n=n.parent,s=s.parent,null===n||null===s)return e;return n!==s?e:n}function getDepth(t){let e=0,r=t;for(;null!=r.parent;)r=r.parent,e++;return e}function getFurthestParent(t,e){let r=t;for(;e>0;)r=r.parent,e-=1;return r}Matrix.prototype.localMin=function(t,e){let r=this[t][e],i=[t,e];for(let n=Math.max(0,t-1);n<Math.min(this.length,t+2);n++)for(let t=Math.max(0,e-1);t<Math.min(this[0].length,e+2);t++)this[n][t]<r&&(r=this[n][t],i=[n,t]);return{position:i,value:r}},Matrix.prototype.localMax=function(t,e){let r=this[t][e],i=[t,e];for(let n=Math.max(0,t-1);n<Math.min(this.length,t+2);n++)for(let t=Math.max(0,e-1);t<Math.min(this[0].length,e+2);t++)this[n][t]>r&&(r=this[n][t],i=[n,t]);return{position:i,value:r}},Matrix.prototype.localSearch=function(t,e,r){let i=[];for(let n=Math.max(0,t-1);n<Math.min(this.length,t+2);n++)for(let t=Math.max(0,e-1);t<Math.min(this[0].length,e+2);t++)this[n][t]===r&&i.push([n,t]);return i};const defaultOptions$1={lowThreshold:10,highThreshold:30,gaussianBlur:1.1},Gx=[[-1,0,1],[-2,0,2],[-1,0,1]],Gy=[[-1,-2,-1],[0,0,0],[1,2,1]],convOptions={bitDepth:32,mode:"periodic"};function cannyEdgeDetector(t,e){t.checkProcessable("Canny edge detector",{bitDepth:8,channels:1,components:1}),e=Object.assign({},defaultOptions$1,e);const r=t.width,i=t.height,n=t.maxValue,s={sigma:e.gaussianBlur,radius:3},a=t.gaussianFilter(s),o=a.convolution(Gy,convOptions),h=a.convolution(Gx,convOptions),l=h.hypotenuse(o),c=t.constructor,u=new c(r,i,{kind:"GREY",bitDepth:32}),f=new c(r,i,{kind:"GREY",bitDepth:32}),d=new c(r,i,{kind:"GREY"});for(var m=1;m<r-1;m++)for(var g=1;g<i-1;g++){var p=(Math.round(Math.atan2(h.getValueXY(m,g,0),o.getValueXY(m,g,0))*(5/Math.PI))+5)%5;0===p&&(l.getValueXY(m,g,0)<=l.getValueXY(m,g-1,0)||l.getValueXY(m,g,0)<=l.getValueXY(m,g+1,0))||1===p&&(l.getValueXY(m,g,0)<=l.getValueXY(m-1,g+1,0)||l.getValueXY(m,g,0)<=l.getValueXY(m+1,g-1,0))||2===p&&(l.getValueXY(m,g,0)<=l.getValueXY(m-1,g,0)||l.getValueXY(m,g,0)<=l.getValueXY(m+1,g,0))||3===p&&(l.getValueXY(m,g,0)<=l.getValueXY(m-1,g-1,0)||l.getValueXY(m,g,0)<=l.getValueXY(m+1,g+1,0))||u.setValueXY(m,g,0,l.getValueXY(m,g,0))}for(m=0;m<r*i;++m){var w=u.data[m],_=0;w>e.highThreshold&&(_++,d.data[m]=n),w>e.lowThreshold&&_++,f.data[m]=_}var b=[];for(m=1;m<r-1;++m)for(g=1;g<i-1;++g)if(1===f.getValueXY(m,g,0))t:for(var y=m-1;y<m+2;++y)for(var M=g-1;M<g+2;++M)if(2===f.getValueXY(y,M,0)){b.push([m,g]),d.setValueXY(m,g,0,n);break t}for(;b.length>0;){var x=[];for(m=0;m<b.length;++m)for(g=-1;g<2;++g)for(y=-1;y<2;++y)if(0!==g||0!==y){var v=b[m][0]+g,E=b[m][1]+y;1===f.getValueXY(v,E,0)&&0===d.getValueXY(v,E,0)&&(x.push([v,E]),d.setValueXY(v,E,0,n))}b=x}return d}function cannyEdge(t){return cannyEdgeDetector(this,t)}function extract(t,e={}){let{position:r}=e;if(this.checkProcessable("extract",{bitDepth:[1,8,16]}),!r&&(r=t.getRelativePosition(this),!r))throw new Error("extract : can not extract an image because the relative position can not be determined, try to specify manually the position as an array of 2 elements [x,y].");if(this.bitDepth>1){let e=Image.createFrom(this,{width:t.width,height:t.height,alpha:1,position:r,parent:this});for(let i=0;i<t.width;i++)for(let n=0;n<t.height;n++){for(let t=0;t<this.channels;t++){let s=this.getValueXY(i+r[0],n+r[1],t);e.setValueXY(i,n,t,s)}t.getBitXY(i,n)||e.setValueXY(i,n,this.components,0)}return e}{let e=Image.createFrom(this,{width:t.width,height:t.height,position:r,parent:this});for(let i=0;i<t.height;i++)for(let n=0;n<t.width;n++)t.getBitXY(n,i)&&this.getBitXY(n+r[0],i+r[1])&&e.setBitXY(n,i);return e}}var fastList=createCommonjsModule((function(t,e){!function(){function e(t,e,r){this.next=r,r&&(r.prev=this),this.prev=e,e&&(e.next=this),this.data=t}function r(){if(!(this instanceof r))return new r;this._head=null,this._tail=null,this.length=0}r.prototype={push:function(t){this._tail=new e(t,this._tail,null),this._head||(this._head=this._tail),this.length++},pop:function(){if(0!==this.length){var t=this._tail;return this._tail=t.prev,t.prev&&(t.prev=this._tail.next=null),this.length--,1===this.length?this._head=this._tail:0===this.length&&(this._head=this._tail=null),t.data}},unshift:function(t){this._head=new e(t,null,this._head),this._tail||(this._tail=this._head),this.length++},shift:function(){if(0!==this.length){var t=this._head;return this._head=t.next,t.next&&(t.next=this._head.prev=null),this.length--,1===this.length?this._tail=this._head:0===this.length&&(this._head=this._tail=null),t.data}},item:function(t){t<0&&(t=this.length+t);for(var e=this._head;t-- >0&&e;)e=e.next;return e?e.data:void 0},slice:function(t,e){if(t||(t=0),e||(e=this.length),e<0&&(e=this.length+e),t<0&&(t=this.length+t),e===t)return[];if(e<t)throw new Error("invalid offset: "+t+","+e+" (length="+this.length+")");for(var r=e-t,i=new Array(r),n=0,s=this._head;t-- >0&&s;)s=s.next;for(;n<r&&s;)i[n++]=s.data,s=s.next;return i},drop:function(){r.call(this)},forEach:function(t,e){for(var r=this._head,i=0,n=this.length;i<n&&r;)t.call(e||this,r.data,i,this),r=r.next,i++},map:function(t,e){var i=new r;return this.forEach((function(r,n,s){i.push(t.call(e||s,r,n,s))})),i},filter:function(t,e){var i=new r;return this.forEach((function(r,n,s){t.call(e||s,r,n,s)&&i.push(r)})),i},reduce:function(t,e,r){var i=0,n=this._head,s=this.length;for(e||(i=1,e=n&&n.data,n=n&&n.next);i<s&&n;)e=t.call(r||this,e,n.data,this),i++,n=n.next;return e}},t.exports=r}()}));function floodFill(t={}){const{x:e=0,y:r=0,inPlace:i=!0}=t,n=i?this:Image.createFrom(this);this.checkProcessable("floodFill",{bitDepth:1});if(this.getBitXY(e,r))return n;const s=new fastList;for(s.push(new Node(e,r));s.length>0;){const t=s.shift();n.setBitXY(t.x,t.y);for(let e=t.x+1;e<this.width&&(!n.getBitXY(e,t.y)&&!this.getBitXY(e,t.y));e++)n.setBitXY(e,t.y),t.y+1<this.height&&!this.getBitXY(e,t.y+1)&&s.push(new Node(e,t.y+1)),t.y-1>=0&&!this.getBitXY(e,t.y-1)&&s.push(new Node(e,t.y-1));for(let e=t.x-1;e>=0&&(!n.getBitXY(e,t.y)&&!this.getBitXY(e,t.y));e++)n.setBitXY(e,t.y),t.y+1<this.height&&!this.getBitXY(e,t.y+1)&&s.push(new Node(e,t.y+1)),t.y-1>=0&&!this.getBitXY(e,t.y-1)&&s.push(new Node(e,t.y-1))}return n}function Node(t,e){this.x=t,this.y=e}function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function hsv2rgb(t,e,r){var i=[],n=(r/=100)*(e/=100),s=t/60,a=n*(1-Math.abs(s%2-1)),o=r-n;return i=s>=0&&s<1?[n,a,0]:s>=1&&s<2?[a,n,0]:s>=2&&s<3?[0,n,a]:t>=3&&s<4?[0,a,n]:t>=4&&s<5?[a,0,n]:t>=5&&s<=6?[n,0,a]:[0,0,0],{r:Math.round(255*(i[0]+o)),g:Math.round(255*(i[1]+o)),b:Math.round(255*(i[2]+o))}}function hsl2hsv(t,e,r){return{h:t,s:2*(e*=(r<50?r:100-r)/100)/(r+e)*100,v:r+e}}function hsl2rgb$1(t,e,r){var i=hsl2hsv(t,e,r);return hsv2rgb(i.h,i.s,i.v)}var colors={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,132,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,255,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,203],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[119,128,144],slategrey:[119,128,144],snow:[255,255,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,5]};function parse(t){return named(t)||hex3(t)||hex6(t)||rgb(t)||rgba$1(t)||hsl(t)||hsla(t)}function named(t){var e=colors[t.toLowerCase()];if(e)return{r:e[0],g:e[1],b:e[2],a:100}}function rgb(t){var e=t.match(/rgb\(([^)]+)\)/);if(e){var r=e[1].split(/ *, */).map(Number);return{r:r[0],g:r[1],b:r[2],a:100}}}function rgba$1(t){var e=t.match(/rgba\(([^)]+)\)/);if(e){var r=e[1].split(/ *, */).map(Number);return{r:r[0],g:r[1],b:r[2],a:100*r[3]}}}function hex6(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:100}}function hex3(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:100}}function hsl(t){var e=t.match(/hsl\(([^)]+)\)/);if(e){var r=e[1].split(/ *, */);return _extends({},hsl2rgb$1(parseInt(r[0],10),parseInt(r[1],10),parseInt(r[2],10)),{a:100})}}function hsla(t){var e=t.match(/hsla\(([^)]+)\)/);if(e){var r=e[1].split(/ *, */),i=parseInt(r[0],10),n=parseInt(r[1],10),s=parseInt(r[2],10),a=parseInt(100*parseFloat(r[3]),10);return _extends({},hsl2rgb$1(i,n,s),{a:a})}}function css2array(t){let e=parse(t);return[e.r,e.g,e.b,Math.round(255*e.a/100)]}function hue2rgb(t,e,r){return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t}function hsl2rgb(t,e,r){let i,n,s,a,o,h;return r/=100,0===(e/=100)?a=o=h=255*r:(n=r<=.5?r*(e+1):r+e-r*e,i=2*r-n,s=t/360,a=hue2rgb(i,n,s+1/3),o=hue2rgb(i,n,s),h=hue2rgb(i,n,s-1/3)),{r:a,g:o,b:h}}function getDistinctColors(t){let e=new Array(t),r=0;for(let i=0;i<360;i+=360/t){r++;let t=hsl2rgb(i,100,30+r%4*15);e[r-1]=[Math.round(255*t.r),Math.round(255*t.g),Math.round(255*t.b)]}return e}function getRandomColor(){return[Math.floor(256*Math.random()),Math.floor(256*Math.random()),Math.floor(256*Math.random())]}function getColors(t){let{color:e,colors:r,randomColors:i,numberColors:n=50}=t;if(e&&!Array.isArray(e)&&(e=css2array(e)),e)return[e];if(r)return r=r.map((function(t){return Array.isArray(t)?t:css2array(t)})),r;if(i){r=new Array(n);for(let t=0;t<n;t++)r[t]=getRandomColor()}return getDistinctColors(n)}function paintLabels(t,e,r={}){let{color:i="blue",colors:n,font:s="12px Helvetica",rotate:a=0}=r;if(this.checkProcessable("paintMasks",{channels:[3,4],bitDepth:[8,16],colorModel:RGB$1}),!Array.isArray(t))throw Error("paintLabels: labels must be an array");if(!Array.isArray(e))throw Error("paintLabels: positions must be an array");if(i&&!Array.isArray(i)&&(i=css2array(i)),n=n?n.map((function(t){return Array.isArray(t)?t:css2array(t)})):[i],t.length!==e.length)throw Error("paintLabels: positions and labels must be arrays from the same size");Array.isArray(s)||(s=[s]),Array.isArray(a)||(a=[a]);let o=this.getCanvas().getContext("2d");for(let r=0;r<t.length;r++){o.save();let i=n[r%n.length];o.fillStyle=`rgba(${i[0]},${i[1]},${i[2]},${i[3]/this.maxValue})`,o.font=s[r%s.length];let h=e[r];o.translate(h[0],h[1]),o.rotate(a[r%a.length]/180*Math.PI),o.fillText(t[r],0,0),o.restore()}return this.data=Uint8Array.from(o.getImageData(0,0,this.width,this.height).data),this}function paintMasks(t,e={}){let{alpha:r=255,labels:i=[],labelsPosition:n=[],labelColor:s="blue",labelFont:a="12px Helvetica"}=e;this.checkProcessable("paintMasks",{channels:[3,4],bitDepth:[8,16],colorModel:RGB$1});let o=getColors(Object.assign({},e,{numberColors:t.length}));Array.isArray(t)||(t=[t]);for(let e=0;e<t.length;e++){let i=t[e],n=o[e%o.length];for(let t=0;t<i.width;t++)for(let e=0;e<i.height;e++)if(i.getBitXY(t,e))for(let s=0;s<Math.min(this.components,n.length);s++)if(255===r)this.setValueXY(t+i.position[0],e+i.position[1],s,n[s]);else{let a=this.getValueXY(t+i.position[0],e+i.position[1],s);a=Math.round((a*(255-r)+n[s]*r)/255),this.setValueXY(t+i.position[0],e+i.position[1],s,a)}}if(Array.isArray(i)&&i.length>0){let e=this.getCanvas().getContext("2d");e.fillStyle=s,e.font=a;for(let r=0;r<Math.min(t.length,i.length);r++){let s=n[r]?n[r]:t[r].position;e.fillText(i[r],s[0],s[1])}this.data=Uint8Array.from(e.getImageData(0,0,this.width,this.height).data)}return this}function zerosMatrix(t,e){let r=new Array(t);for(let i=0;i<t;i++)r[i]=new Array(e).fill(0);return r}const cross=[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0]],smallCross=[[0,1,0],[1,1,1],[0,1,0]];class Shape{constructor(t={}){let{kind:e="cross",shape:r,size:i,width:n,height:s,filled:a=!0}=t;if(i&&(n=i,s=i),r)switch(r.toLowerCase()){case"square":case"rectangle":this.matrix=rectangle(n,s,{filled:a});break;case"circle":case"ellipse":this.matrix=ellipse(n,s,{filled:a});break;case"triangle":this.matrix=triangle(n,s,{filled:a});break;default:throw new Error(`Shape: unexpected shape: ${r}`)}else{if(!e)throw new Error("Shape: expected a kind or a shape option");switch(e.toLowerCase()){case"cross":this.matrix=cross;break;case"smallcross":this.matrix=smallCross;break;default:throw new Error(`Shape: unexpected kind: ${e}`)}}this.height=this.matrix.length,this.width=this.matrix[0].length,this.halfHeight=this.height/2>>0,this.halfWidth=this.width/2>>0}getPoints(){let t=this.matrix,e=[];for(let r=0;r<t.length;r++)for(let i=0;i<t[0].length;i++)t[r][i]&&e.push([i-this.halfWidth,r-this.halfHeight]);return e}getMask(){let t=new Image(this.width,this.height,{kind:BINARY});for(let e=0;e<this.matrix.length;e++)for(let r=0;r<this.matrix[0].length;r++)this.matrix[e][r]&&t.setBitXY(r,e);return t}}function rectangle(t,e,r){const i=zerosMatrix(e,t);if(r.filled)for(let r=0;r<e;r++)for(let e=0;e<t;e++)i[r][e]=1;else{for(let r of[0,e-1])for(let e=0;e<t;e++)i[r][e]=1;for(let r=0;r<e;r++)for(let e of[0,t-1])i[r][e]=1}return i}function ellipse(t,e,r){const i=zerosMatrix(e,t);let n=1-e%2,s=1-t%2,a=Math.floor((t-1)/2),o=Math.floor((e-1)/2),h=a*a,l=o*o;if(r.filled)for(let e=0;e<=o;e++){for(let r=a-Math.floor(Math.sqrt(h-h*e*e/l));r<=a;r++)i[o-e][r]=1,i[o+e+n][r]=1,i[o-e][t-r-1]=1,i[o+e+n][t-r-1]=1}else{for(let e=0;e<=o;e++){let r=a-Math.floor(Math.sqrt(h-h*e*e/l));i[o-e][r]=1,i[o+e+n][r]=1,i[o-e][t-r-1]=1,i[o+e+n][t-r-1]=1}for(let t=0;t<=a;t++){let r=o-Math.floor(Math.sqrt(l-l*t*t/h));i[r][a-t]=1,i[r][a+t+s]=1,i[e-r-1][a-t]=1,i[e-r-1][a+t+s]=1}}return i}function triangle(t,e,r){if(!r.filled)throw new Error("Non filled triangle is not implemented");const i=zerosMatrix(e,t);for(let r=0;r<e;r++){let n=Math.floor((1-r/e)*t/2);for(let e=n;e<t-n;e++)i[r][e]=1}return i}function paintPoints(t,e={}){let{shape:r}=e;this.checkProcessable("paintPoints",{bitDepth:[8,16]});let i=getColors(Object.assign({},e,{numberColors:t.length})),n=new Shape(r).getPoints(),s=Math.min(this.channels,i[0].length);for(let e=0;e<t.length;e++){let r=i[e%i.length],a=t[e][0],o=t[e][1];for(let t=0;t<n.length;t++){let e=n[t][0],i=n[t][1];if(a+e>=0&&o+i>=0&&a+e<this.width&&o+i<this.height){let t=(a+e+(o+i)*this.width)*this.channels;for(let e=0;e<s;e++)this.data[t+e]=r[e]}}}return this}function paintPolyline(t,e={}){let{color:r=[this.maxValue,0,0],closed:i=!1}=e;this.checkProcessable("paintPoints",{bitDepth:[1,8,16]});let n=Math.min(this.channels,r.length);for(let e=0;e<t.length-1+i;e++){let i=t[e],s=t[(e+1)%t.length],a=s[0]-i[0],o=s[1]-i[1],h=Math.max(Math.abs(a),Math.abs(o)),l=a/h,c=o/h,u=i[0],f=i[1];for(let t=0;t<=h;t++){let t=Math.round(u),e=Math.round(f);if(t>=0&&e>=0&&t<this.width&&e<this.height)if(1===this.bitDepth)this.setBitXY(t,e);else{let i=(t+e*this.width)*this.channels;for(let t=0;t<n;t++)this.data[i+t]=r[t]}u+=l,f+=c}}return this}function paintPolylines(t,e={}){let r=Object.assign({},e);this.checkProcessable("paintPolylines",{bitDepth:[8,16]});let i=getColors(Object.assign({},e,{numberColors:t.length}));for(let e=0;e<t.length;e++)r.color=i[e%i.length],this.paintPolyline(t[e],r);return this}function paintPolygon(t,e={}){let{color:r=[this.maxValue,0,0],filled:i=!1}=e;this.checkProcessable("paintPoints",{bitDepth:[1,8,16]}),e.closed=!0;let n=deleteDouble(t);if(!1===i)return this.paintPolyline(t,e);{let i=Array(this.height);for(let t=0;t<this.height;t++){i[t]=[];for(let e=0;e<this.width;e++)i[t].push(0)}for(let t=0;t<n.length;t++){const e=lineBetweenTwoPoints(n[t],n[(t+1)%n.length]);for(let t=0;t<this.height;t++)for(let r=0;r<this.width;r++)isAtTheRightOfTheLine(r,t,e,this.height)&&(i[t][r]=0===i[t][r]?1:0)}for(let t=0;t<this.height;t++)for(let e=0;e<this.width;e++)if(1===i[t][e])if(1===this.bitDepth)this.setBitXY(e,t);else{let i=Math.min(this.channels,r.length),n=(e+t*this.width)*this.channels;for(let t=0;t<i;t++)this.data[n+t]=r[t]}return this.paintPolyline(t,e)}}function deleteDouble(t){let e=[];for(let r=0;r<t.length;r++)t[r][0]===t[(r+1)%t.length][0]&&t[r][1]===t[(r+1)%t.length][1]||t[r][0]===t[(r-1+t.length)%t.length][0]&&t[r][1]===t[(r-1+t.length)%t.length][1]||t[(r+1)%t.length][0]===t[(r-1+t.length)%t.length][0]&&t[(r-1+t.length)%t.length][1]===t[(r+1)%t.length][1]||e.push(t[r]);return e}function lineBetweenTwoPoints(t,e){if(t[0]===e[0])return{a:0,b:t[0],vertical:!0};{const r=(e[1]-t[1])/(e[0]-t[0]);return{a:r,b:t[1]-r*t[0],vertical:!1}}}function isAtTheRightOfTheLine(t,e,r,i){if(!0===r.vertical)return r.b<=t;if(0===r.a)return!1;{const n=(e-r.b)/r.a;return n<t&&n>=0&&n<=i}}function paintPolygons(t,e={}){let r=Object.assign({},e);this.checkProcessable("paintPolygons",{bitDepth:[8,16]});let i=getColors(Object.assign({},e,{numberColors:t.length}));for(let e=0;e<t.length;e++)r.color=i[e%i.length],this.paintPolygon(t[e],r);return this}function getHistogram(t={}){let{maxSlots:e=256,channel:r,useAlpha:i=!0}=t;if(this.checkProcessable("getHistogram",{bitDepth:[1,8,16]}),void 0===r){if(this.components>1)throw new RangeError("You need to define the channel for an image that contains more than one channel");r=0}return getChannelHistogram.call(this,r,{useAlpha:i,maxSlots:e})}function getHistograms(t={}){const{maxSlots:e=256,useAlpha:r=!0}=t;this.checkProcessable("getHistograms",{bitDepth:[8,16]});let i=new Array(r?this.components:this.channels);for(let t=0;t<i.length;t++)i[t]=getChannelHistogram.call(this,t,{useAlpha:r,maxSlots:e});return i}function getChannelHistogram(t,e){let{useAlpha:r,maxSlots:i}=e;if(1===this.bitDepth){let t=[0,0];for(let e=0;e<this.height;e++)for(let r=0;r<this.width;r++){let i=this.getBitXY(e,r);0===i?t[0]+=1:1===i&&(t[1]+=1)}return t}let n=Math.log2(i);if(!_isInteger_1_0_7_isInteger(n))throw new RangeError("maxSlots must be a power of 2, for example: 64, 256, 1024");let s=0;this.bitDepth>n&&(s=this.bitDepth-n);let a=this.data,o=_newArray_1_0_0_newArray(Math.pow(2,Math.min(this.bitDepth,n)),0);if(r&&this.alpha){let e=this.channels-t-1;for(let r=t;r<a.length;r+=this.channels)o[a[r]>>s]+=a[r+e]/this.maxValue}else for(let e=t;e<a.length;e+=this.channels)o[a[e]>>s]++;return o}function getColorHistogram(t={}){let{useAlpha:e=!0,nbSlots:r=512}=t;this.checkProcessable("getColorHistogram",{bitDepth:[8,16],components:[3]});let i=Math.log(r)/Math.log(8);if(i!==Math.floor(i))throw new RangeError("nbSlots must be a power of 8. Usually 8, 64, 512 or 4096");let n=this.bitDepth-i,s=this.data,a=_newArray_1_0_0_newArray(Math.pow(8,i),0),o=Math.pow(2,2*i),h=Math.pow(2,i);for(let t=0;t<s.length;t+=this.channels){let r=(s[t]>>n)*o+(s[t+1]>>n)*h+(s[t+2]>>n);e&&this.alpha?a[r]+=s[t+this.channels-1]/this.maxValue:a[r]++}return a}function min(){this.checkProcessable("min",{bitDepth:[8,16,32]});let t=_newArray_1_0_0_newArray(this.channels,1/0);for(let e=0;e<this.data.length;e+=this.channels)for(let r=0;r<this.channels;r++)this.data[e+r]<t[r]&&(t[r]=this.data[e+r]);return t}function max(){this.checkProcessable("max",{bitDepth:[8,16,32]});let t=_newArray_1_0_0_newArray(this.channels,-1/0);for(let e=0;e<this.data.length;e+=this.channels)for(let r=0;r<this.channels;r++)this.data[e+r]>t[r]&&(t[r]=this.data[e+r]);return t}function sum(){this.checkProcessable("sum",{bitDepth:[8,16]});let t=_newArray_1_0_0_newArray(this.channels,0);for(let e=0;e<this.data.length;e+=this.channels)for(let r=0;r<this.channels;r++)t[r]+=this.data[e+r];return t}function getMoment(t=0,e=0){this.checkProcessable("getMoment",{bitDepth:[1]});let r=0;for(let i=0;i<this.width;i++)for(let n=0;n<this.height;n++)1===this.getBitXY(i,n)&&(r+=i**t*n**e);return r}function localMaxima(t={}){let{mask:e,region:r=3,removeClosePoints:i=0,invert:n=!1,maxEquals:s=2}=t,a=this;this.checkProcessable("localMaxima",{bitDepth:[8,16],components:1}),r*=4;let o=n?0:1,h=[1,0,-1,0,1,1,-1,-1,2,0,-2,0,2,2,-2,-2],l=[0,1,0,-1,1,-1,1,-1,0,2,0,-2,2,-2,2,-2],c=r<=8?1:2,u=[];for(let t=c;t<a.height-c;t++)for(let i=c;i<a.width-c;i++){if(e&&e.getBitXY(i,t)!==o)continue;let c=0,f=0,d=a.data[i+t*a.width];for(let e=0;e<r;e++)n?a.data[i+h[e]+(t+l[e])*a.width]>d&&c++:a.data[i+h[e]+(t+l[e])*a.width]<d&&c++,a.data[i+h[e]+(t+l[e])*a.width]===d&&f++;c+f===r&&f<=s&&u.push([i,t])}if(i>0)for(let t=0;t<u.length;t++)for(let e=t+1;e<u.length;e++)Math.sqrt(Math.pow(u[t][0]-u[e][0],2)+Math.pow(u[t][1]-u[e][1],2))<i&&(u[t][0]=u[t][0]+u[e][0]>>1,u[t][1]=u[t][1]+u[e][1]>>1,u.splice(e,1),e--);return u}function mean(){let t=this.getHistograms({maxSlots:this.maxValue+1}),e=new Array(t.length);for(let r=0;r<t.length;r++){let i=t[r];e[r]=mean$2(i)}return e}function median(){let t=this.getHistograms({maxSlots:this.maxValue+1}),e=new Array(t.length);for(let r=0;r<t.length;r++){let i=t[r];e[r]=median$2(i)}return e}function points(){this.checkProcessable("points",{bitDepth:[1]});const t=[];for(let e=0;e<this.width;e++)for(let r=0;r<this.height;r++)1===this.getBitXY(e,r)&&t.push([e,r]);return t}function extendedPoints(){this.checkProcessable("extendedPoints",{bitDepth:[1]});const t=[];for(let e=0;e<this.height;e++)for(let r=0;r<this.width;r++)1===this.getBitXY(r,e)&&(t.push([r,e]),1!==this.getBitXY(r+1,e)?(t.push([r+1,e]),t.push([r+1,e+1]),1!==this.getBitXY(r,e+1)&&t.push([r,e+1])):1!==this.getBitXY(r,e+1)&&(t.push([r,e+1]),t.push([r+1,e+1])));return t}function getRelativePosition(t,e={}){if(this===t)return[0,0];let r=[0,0],i=this;for(;i;){if(i===t)return r;i.position&&(r[0]+=i.position[0],r[1]+=i.position[1]),i=i.parent}return!!e.defaultFurther&&r}function countAlphaPixels(t={}){let{alpha:e=1}=t;this.checkProcessable("countAlphaPixels",{bitDepth:[8,16],alpha:1});let r=0;if(void 0!==e){for(let t=this.components;t<this.data.length;t+=this.channels)this.data[t]===e&&r++;return r}return this.size}function monotoneChainConvexHull$1(t,e={}){e.sorted||t.sort(byXThenY);const r=t.length,i=new Array(2*r);for(var n=0,s=0;s<r;s++){const e=t[s];for(;n>=2&&cw(i[n-2],i[n-1],e)<=0;)n--;i[n++]=e}const a=n+1;for(s=r-2;s>=0;s--){const e=t[s];for(;n>=a&&cw(i[n-2],i[n-1],e)<=0;)n--;i[n++]=e}return i.slice(0,n-1)}function cw(t,e,r){return(e[1]-t[1])*(r[0]-t[0])-(e[0]-t[0])*(r[1]-t[1])}function byXThenY(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]}function monotoneChainConvexHull(){return monotoneChainConvexHull$1(this.extendedPoints,{sorted:!1})}function round(t){for(let e=0;e<t.length;e++)t[e][0]=Math.round(t[e][0]),t[e][1]=Math.round(t[e][1]);return t}function difference(t,e){return[t[0]-e[0],t[1]-e[1]]}function normalize(t){let e=Math.sqrt(t[0]**2+t[1]**2);return[t[0]/e,t[1]/e]}function rotate(t,e,r){void 0===r&&(r=new Array(e.length));let i=Math.cos(t),n=Math.sin(t);for(let t=0;t<r.length;++t)r[t]=[i*e[t][0]-n*e[t][1],n*e[t][0]+i*e[t][1]];return r}function perimeter(t){let e=0;for(let r=0;r<t.length;r++){let i=t[r][0],n=t[r][1],s=t[r===t.length-1?0:r+1][0],a=t[r===t.length-1?0:r+1][1];e+=Math.sqrt((s-i)**2+(a-n)**2)}return e}function surface(t){let e=0;for(let r=0;r<t.length;r++){e+=t[r][0]*t[r===t.length-1?0:r+1][1]*.5,e-=t[r===t.length-1?0:r+1][0]*t[r][1]*.5}return Math.abs(e)}function minMax(t){let e=1/0,r=1/0,i=-1/0,n=-1/0;for(let s=0;s<t.length;s++)t[s][0]<e&&(e=t[s][0]),t[s][0]>i&&(i=t[s][0]),t[s][1]<r&&(r=t[s][1]),t[s][1]>n&&(n=t[s][1]);return[[e,r],[i,n]]}function moveToZeroZero(t,e){void 0===e&&(e=new Array(t.length).fill(0).map((()=>[])));let r=minMax(t),i=r[0][0],n=r[0][1];for(let r=0;r<t.length;r++)e[r][0]=t[r][0]-i,e[r][1]=t[r][1]-n;return e}function minimalBoundingRectangle(t={}){const{originalPoints:e=monotoneChainConvexHull.call(this)}=t;if(0===e.length)return[];if(1===e.length)return[e[0],e[0],e[0],e[0]];const r=new Array(e.length);let i,n=1/0,s=0;for(let t=0;t<r.length;t++){let a=getAngle$1(e[t],e[(t+1)%r.length]);rotate(-a,e,r);let o=r[t][0],h=r[t][1],l=r[(t+1)%r.length][0],c=r[(t+1)%r.length][1],u=!0,f=0,d=0,m=0;for(let t=0;t<r.length;t++){let e=r[t][0],i=r[t][1],n=(e-o)/(l-o);!0===u?(u=!1,f=n,d=n):(n<f&&(f=n),n>d&&(d=n));let s=(-(l-o)*i+l*h-c*o)/(l-o);Math.abs(s)>Math.abs(m)&&(m=s)}let g=[o+f*(l-o),h],p=[o+d*(l-o),h],w=Math.abs(m*(f-d)*(l-o));w<n&&(s=a,n=w,i=[g,p,[p[0],p[1]-m],[g[0],g[1]-m]])}return rotate(s,i,i),i}function getAngle$1(t,e){let r=normalize(difference(e,t)),i=Math.acos(r[0]);return r[1]<0?-i:i}function extend$1(t){let e={inPlace:!0};t.extendMethod("invert",invert),t.extendMethod("abs",abs),t.extendMethod("level",level,e),t.extendMethod("add",add,e),t.extendMethod("subtract",subtract,e),t.extendMethod("subtractImage",subtractImage),t.extendMethod("multiply",multiply,e),t.extendMethod("divide",divide,e),t.extendMethod("hypotenuse",hypotenuse),t.extendMethod("background",background$1),t.extendMethod("flipX",flipX),t.extendMethod("flipY",flipY),t.extendMethod("blurFilter",blurFilter),t.extendMethod("medianFilter",medianFilter),t.extendMethod("gaussianFilter",gaussianFilter),t.extendMethod("sobelFilter",sobelFilter),t.extendMethod("gradientFilter",gradientFilter),t.extendMethod("scharrFilter",scharrFilter),t.extendMethod("dilate",dilate),t.extendMethod("erode",erode),t.extendMethod("open",open),t.extendMethod("close",close),t.extendMethod("topHat",topHat),t.extendMethod("blackHat",blackHat),t.extendMethod("morphologicalGradient",morphologicalGradient),t.extendMethod("warpingFourPoints",warpingFourPoints),t.extendMethod("crop",crop),t.extendMethod("cropAlpha",cropAlpha),t.extendMethod("resize",resize).extendMethod("scale",resize),t.extendMethod("hsv",hsv),t.extendMethod("hsl",hsl$1),t.extendMethod("cmyk",cmyk),t.extendMethod("rgba8",rgba8),t.extendMethod("grey",grey).extendMethod("gray",grey),t.extendMethod("mask",mask),t.extendMethod("pad",pad),t.extendMethod("colorDepth",colorDepth),t.extendMethod("setBorder",setBorder,e),t.extendMethod("rotate",rotate$1),t.extendMethod("rotateLeft",rotateLeft),t.extendMethod("rotateRight",rotateRight),t.extendMethod("insert",insert),t.extendMethod("getRow",getRow),t.extendMethod("getColumn",getColumn),t.extendMethod("getMatrix",getMatrix),t.extendMethod("setMatrix",setMatrix),t.extendMethod("getPixelsArray",getPixelsArray),t.extendMethod("getIntersection",getIntersection),t.extendMethod("getClosestCommonParent",getClosestCommonParent),t.extendMethod("getThreshold",getThreshold),t.extendMethod("split",split),t.extendMethod("getChannel",getChannel),t.extendMethod("combineChannels",combineChannels),t.extendMethod("setChannel",setChannel),t.extendMethod("getSimilarity",getSimilarity),t.extendMethod("getPixelsGrid",getPixelsGrid),t.extendMethod("getBestMatch",getBestMatch),t.extendMethod("cannyEdge",cannyEdge),t.extendMethod("convolution",convolution),t.extendMethod("extract",extract),t.extendMethod("floodFill",floodFill),t.extendMethod("paintLabels",paintLabels,e),t.extendMethod("paintMasks",paintMasks,e),t.extendMethod("paintPoints",paintPoints,e),t.extendMethod("paintPolyline",paintPolyline,e),t.extendMethod("paintPolylines",paintPolylines,e),t.extendMethod("paintPolygon",paintPolygon,e),t.extendMethod("paintPolygons",paintPolygons,e),t.extendMethod("countAlphaPixels",countAlphaPixels),t.extendMethod("monotoneChainConvexHull",monotoneChainConvexHull),t.extendMethod("minimalBoundingRectangle",minimalBoundingRectangle),t.extendMethod("getHistogram",getHistogram).extendProperty("histogram",getHistogram),t.extendMethod("getHistograms",getHistograms).extendProperty("histograms",getHistograms),t.extendMethod("getColorHistogram",getColorHistogram).extendProperty("colorHistogram",getColorHistogram),t.extendMethod("getMin",min).extendProperty("min",min),t.extendMethod("getMax",max).extendProperty("max",max),t.extendMethod("getSum",sum).extendProperty("sum",sum),t.extendMethod("getMoment",getMoment).extendProperty("moment",getMoment),t.extendMethod("getLocalMaxima",localMaxima),t.extendMethod("getMedian",median).extendProperty("median",median),t.extendMethod("getMean",mean).extendProperty("mean",mean),t.extendMethod("getPoints",points).extendProperty("points",points),t.extendMethod("getExtendedPoints",extendedPoints).extendProperty("extendedPoints",extendedPoints),t.extendMethod("getRelativePosition",getRelativePosition)}var quantities=createCommonjsModule((function(t,e){t.exports=function(){function t(t){return"string"==typeof t||t instanceof String}var e=Number.isFinite||window.isFinite;function r(t){return e(t)}function i(t){return t}function n(t){var e={};return t.filter((function(t){return!e.hasOwnProperty(t)&&(e[t]=!0)}))}function s(t,e){if(e.length!==t.length)return!1;for(var r=0;r<t.length;r++){if(e[r].compareArray&&!e[r].compareArray(t[r]))return!1;if(e[r]!==t[r])return!1}return!0}function a(t,e){Object.keys(e).forEach((function(r){t[r]=e[r]}))}function o(){for(var t=1,e=0,r=0;r<arguments.length;r++){var i=arguments[r];e+=c(i),t*=i}return 0!==e?l(t,e):t}function h(t,e){if(0===e)throw new Error("Divide by zero");var r=Math.pow(10,c(e));return o(t,r/(r*e))}function l(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}function c(t){if(!isFinite(t))return 0;for(var e=0;t%1!=0;)t*=10,e++;return e}function u(){var t;if(!this)return t=Object.create(u.prototype),u.apply(t,arguments),t;t=Error.apply(this,arguments),this.name="QtyError",this.message=t.message,this.stack=t.stack}function f(t,e){throw new u("Incompatible units: "+t+" and "+e)}u.prototype=Object.create(Error.prototype,{constructor:{value:u}});var d={"<googol>":[["googol"],1e100,"prefix"],"<kibi>":[["Ki","Kibi","kibi"],Math.pow(2,10),"prefix"],"<mebi>":[["Mi","Mebi","mebi"],Math.pow(2,20),"prefix"],"<gibi>":[["Gi","Gibi","gibi"],Math.pow(2,30),"prefix"],"<tebi>":[["Ti","Tebi","tebi"],Math.pow(2,40),"prefix"],"<pebi>":[["Pi","Pebi","pebi"],Math.pow(2,50),"prefix"],"<exi>":[["Ei","Exi","exi"],Math.pow(2,60),"prefix"],"<zebi>":[["Zi","Zebi","zebi"],Math.pow(2,70),"prefix"],"<yebi>":[["Yi","Yebi","yebi"],Math.pow(2,80),"prefix"],"<yotta>":[["Y","Yotta","yotta"],1e24,"prefix"],"<zetta>":[["Z","Zetta","zetta"],1e21,"prefix"],"<exa>":[["E","Exa","exa"],1e18,"prefix"],"<peta>":[["P","Peta","peta"],1e15,"prefix"],"<tera>":[["T","Tera","tera"],1e12,"prefix"],"<giga>":[["G","Giga","giga"],1e9,"prefix"],"<mega>":[["M","Mega","mega"],1e6,"prefix"],"<kilo>":[["k","kilo"],1e3,"prefix"],"<hecto>":[["h","Hecto","hecto"],100,"prefix"],"<deca>":[["da","Deca","deca","deka"],10,"prefix"],"<deci>":[["d","Deci","deci"],.1,"prefix"],"<centi>":[["c","Centi","centi"],.01,"prefix"],"<milli>":[["m","Milli","milli"],.001,"prefix"],"<micro>":[["u","μ","µ","Micro","mc","micro"],1e-6,"prefix"],"<nano>":[["n","Nano","nano"],1e-9,"prefix"],"<pico>":[["p","Pico","pico"],1e-12,"prefix"],"<femto>":[["f","Femto","femto"],1e-15,"prefix"],"<atto>":[["a","Atto","atto"],1e-18,"prefix"],"<zepto>":[["z","Zepto","zepto"],1e-21,"prefix"],"<yocto>":[["y","Yocto","yocto"],1e-24,"prefix"],"<1>":[["1","<1>"],1,""],"<meter>":[["m","meter","meters","metre","metres"],1,"length",["<meter>"]],"<inch>":[["in","inch","inches",'"'],.0254,"length",["<meter>"]],"<foot>":[["ft","foot","feet","'"],.3048,"length",["<meter>"]],"<yard>":[["yd","yard","yards"],.9144,"length",["<meter>"]],"<mile>":[["mi","mile","miles"],1609.344,"length",["<meter>"]],"<naut-mile>":[["nmi","naut-mile"],1852,"length",["<meter>"]],"<league>":[["league","leagues"],4828,"length",["<meter>"]],"<furlong>":[["furlong","furlongs"],201.2,"length",["<meter>"]],"<rod>":[["rd","rod","rods"],5.029,"length",["<meter>"]],"<mil>":[["mil","mils"],254e-7,"length",["<meter>"]],"<angstrom>":[["ang","angstrom","angstroms"],1e-10,"length",["<meter>"]],"<fathom>":[["fathom","fathoms"],1.829,"length",["<meter>"]],"<pica>":[["pica","picas"],.00423333333,"length",["<meter>"]],"<point>":[["pt","point","points"],.000352777778,"length",["<meter>"]],"<redshift>":[["z","red-shift","redshift"],1302773e20,"length",["<meter>"]],"<AU>":[["AU","astronomical-unit"],1495979e5,"length",["<meter>"]],"<light-second>":[["ls","light-second"],299792500,"length",["<meter>"]],"<light-minute>":[["lmin","light-minute"],1798755e4,"length",["<meter>"]],"<light-year>":[["ly","light-year"],9460528e9,"length",["<meter>"]],"<parsec>":[["pc","parsec","parsecs"],3085678e10,"length",["<meter>"]],"<datamile>":[["DM","datamile"],1828.8,"length",["<meter>"]],"<kilogram>":[["kg","kilogram","kilograms"],1,"mass",["<kilogram>"]],"<AMU>":[["u","AMU","amu"],1660538921e-36,"mass",["<kilogram>"]],"<dalton>":[["Da","Dalton","Daltons","dalton","daltons"],1660538921e-36,"mass",["<kilogram>"]],"<slug>":[["slug","slugs"],14.5939029,"mass",["<kilogram>"]],"<short-ton>":[["tn","ton","short-ton"],907.18474,"mass",["<kilogram>"]],"<metric-ton>":[["tonne","metric-ton"],1e3,"mass",["<kilogram>"]],"<carat>":[["ct","carat","carats"],2e-4,"mass",["<kilogram>"]],"<pound>":[["lbs","lb","pound","pounds","#"],.45359237,"mass",["<kilogram>"]],"<ounce>":[["oz","ounce","ounces"],.0283495231,"mass",["<kilogram>"]],"<gram>":[["g","gram","grams","gramme","grammes"],.001,"mass",["<kilogram>"]],"<grain>":[["grain","grains","gr"],6479891e-11,"mass",["<kilogram>"]],"<dram>":[["dram","drams","dr"],.0017718452,"mass",["<kilogram>"]],"<stone>":[["stone","stones","st"],6.35029318,"mass",["<kilogram>"]],"<hectare>":[["hectare"],1e4,"area",["<meter>","<meter>"]],"<acre>":[["acre","acres"],4046.85642,"area",["<meter>","<meter>"]],"<sqft>":[["sqft"],1,"area",["<foot>","<foot>"]],"<liter>":[["l","L","liter","liters","litre","litres"],.001,"volume",["<meter>","<meter>","<meter>"]],"<gallon>":[["gal","gallon","gallons"],.0037854118,"volume",["<meter>","<meter>","<meter>"]],"<gallon-imp>":[["galimp","gallon-imp","gallons-imp"],.00454609,"volume",["<meter>","<meter>","<meter>"]],"<quart>":[["qt","quart","quarts"],.00094635295,"volume",["<meter>","<meter>","<meter>"]],"<pint>":[["pt","pint","pints"],.000473176475,"volume",["<meter>","<meter>","<meter>"]],"<pint-imp>":[["ptimp","pint-imp","pints-imp"],.00056826125,"volume",["<meter>","<meter>","<meter>"]],"<cup>":[["cu","cup","cups"],.000236588238,"volume",["<meter>","<meter>","<meter>"]],"<fluid-ounce>":[["floz","fluid-ounce","fluid-ounces"],295735297e-13,"volume",["<meter>","<meter>","<meter>"]],"<fluid-ounce-imp>":[["flozimp","floz-imp","fluid-ounce-imp","fluid-ounces-imp"],284130625e-13,"volume",["<meter>","<meter>","<meter>"]],"<tablespoon>":[["tb","tbsp","tbs","tablespoon","tablespoons"],147867648e-13,"volume",["<meter>","<meter>","<meter>"]],"<teaspoon>":[["tsp","teaspoon","teaspoons"],492892161e-14,"volume",["<meter>","<meter>","<meter>"]],"<bushel>":[["bu","bsh","bushel","bushels"],.035239072,"volume",["<meter>","<meter>","<meter>"]],"<oilbarrel>":[["bbl","oilbarrel","oilbarrels","oil-barrel","oil-barrels"],.158987294928,"volume",["<meter>","<meter>","<meter>"]],"<beerbarrel>":[["bl","bl-us","beerbarrel","beerbarrels","beer-barrel","beer-barrels"],.1173477658,"volume",["<meter>","<meter>","<meter>"]],"<beerbarrel-imp>":[["blimp","bl-imp","beerbarrel-imp","beerbarrels-imp","beer-barrel-imp","beer-barrels-imp"],.16365924,"volume",["<meter>","<meter>","<meter>"]],"<kph>":[["kph"],.277777778,"speed",["<meter>"],["<second>"]],"<mph>":[["mph"],.44704,"speed",["<meter>"],["<second>"]],"<knot>":[["kt","kn","kts","knot","knots"],.514444444,"speed",["<meter>"],["<second>"]],"<fps>":[["fps"],.3048,"speed",["<meter>"],["<second>"]],"<gee>":[["gee"],9.80665,"acceleration",["<meter>"],["<second>","<second>"]],"<Gal>":[["Gal"],.01,"acceleration",["<meter>"],["<second>","<second>"]],"<kelvin>":[["degK","kelvin"],1,"temperature",["<kelvin>"]],"<celsius>":[["degC","celsius","celsius","centigrade"],1,"temperature",["<kelvin>"]],"<fahrenheit>":[["degF","fahrenheit"],5/9,"temperature",["<kelvin>"]],"<rankine>":[["degR","rankine"],5/9,"temperature",["<kelvin>"]],"<temp-K>":[["tempK","temp-K"],1,"temperature",["<temp-K>"]],"<temp-C>":[["tempC","temp-C"],1,"temperature",["<temp-K>"]],"<temp-F>":[["tempF","temp-F"],5/9,"temperature",["<temp-K>"]],"<temp-R>":[["tempR","temp-R"],5/9,"temperature",["<temp-K>"]],"<second>":[["s","sec","secs","second","seconds"],1,"time",["<second>"]],"<minute>":[["min","mins","minute","minutes"],60,"time",["<second>"]],"<hour>":[["h","hr","hrs","hour","hours"],3600,"time",["<second>"]],"<day>":[["d","day","days"],86400,"time",["<second>"]],"<week>":[["wk","week","weeks"],604800,"time",["<second>"]],"<fortnight>":[["fortnight","fortnights"],1209600,"time",["<second>"]],"<year>":[["y","yr","year","years","annum"],31556926,"time",["<second>"]],"<decade>":[["decade","decades"],315569260,"time",["<second>"]],"<century>":[["century","centuries"],3155692600,"time",["<second>"]],"<pascal>":[["Pa","pascal","Pascal"],1,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<bar>":[["bar","bars"],1e5,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<mmHg>":[["mmHg"],133.322368,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<inHg>":[["inHg"],3386.3881472,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<torr>":[["torr"],133.322368,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<atm>":[["atm","ATM","atmosphere","atmospheres"],101325,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<psi>":[["psi"],6894.76,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<cmh2o>":[["cmH2O","cmh2o"],98.0638,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<inh2o>":[["inH2O","inh2o"],249.082052,"pressure",["<kilogram>"],["<meter>","<second>","<second>"]],"<poise>":[["P","poise"],.1,"viscosity",["<kilogram>"],["<meter>","<second>"]],"<stokes>":[["St","stokes"],1e-4,"viscosity",["<meter>","<meter>"],["<second>"]],"<mole>":[["mol","mole"],1,"substance",["<mole>"]],"<molar>":[["M","molar"],1e3,"concentration",["<mole>"],["<meter>","<meter>","<meter>"]],"<wtpercent>":[["wt%","wtpercent"],10,"concentration",["<kilogram>"],["<meter>","<meter>","<meter>"]],"<katal>":[["kat","katal","Katal"],1,"activity",["<mole>"],["<second>"]],"<unit>":[["U","enzUnit","unit"],16667e-19,"activity",["<mole>"],["<second>"]],"<farad>":[["F","farad","Farad"],1,"capacitance",["<second>","<second>","<second>","<second>","<ampere>","<ampere>"],["<meter>","<meter>","<kilogram>"]],"<coulomb>":[["C","coulomb","Coulomb"],1,"charge",["<ampere>","<second>"]],"<Ah>":[["Ah"],3600,"charge",["<ampere>","<second>"]],"<ampere>":[["A","Ampere","ampere","amp","amps"],1,"current",["<ampere>"]],"<siemens>":[["S","Siemens","siemens"],1,"conductance",["<second>","<second>","<second>","<ampere>","<ampere>"],["<kilogram>","<meter>","<meter>"]],"<henry>":[["H","Henry","henry"],1,"inductance",["<meter>","<meter>","<kilogram>"],["<second>","<second>","<ampere>","<ampere>"]],"<volt>":[["V","Volt","volt","volts"],1,"potential",["<meter>","<meter>","<kilogram>"],["<second>","<second>","<second>","<ampere>"]],"<ohm>":[["Ohm","ohm","Ω","Ω"],1,"resistance",["<meter>","<meter>","<kilogram>"],["<second>","<second>","<second>","<ampere>","<ampere>"]],"<weber>":[["Wb","weber","webers"],1,"magnetism",["<meter>","<meter>","<kilogram>"],["<second>","<second>","<ampere>"]],"<tesla>":[["T","tesla","teslas"],1,"magnetism",["<kilogram>"],["<second>","<second>","<ampere>"]],"<gauss>":[["G","gauss"],1e-4,"magnetism",["<kilogram>"],["<second>","<second>","<ampere>"]],"<maxwell>":[["Mx","maxwell","maxwells"],1e-8,"magnetism",["<meter>","<meter>","<kilogram>"],["<second>","<second>","<ampere>"]],"<oersted>":[["Oe","oersted","oersteds"],250/Math.PI,"magnetism",["<ampere>"],["<meter>"]],"<joule>":[["J","joule","Joule","joules"],1,"energy",["<meter>","<meter>","<kilogram>"],["<second>","<second>"]],"<erg>":[["erg","ergs"],1e-7,"energy",["<meter>","<meter>","<kilogram>"],["<second>","<second>"]],"<btu>":[["BTU","btu","BTUs"],1055.056,"energy",["<meter>","<meter>","<kilogram>"],["<second>","<second>"]],"<calorie>":[["cal","calorie","calories"],4.184,"energy",["<meter>","<meter>","<kilogram>"],["<second>","<second>"]],"<Calorie>":[["Cal","Calorie","Calories"],4184,"energy",["<meter>","<meter>","<kilogram>"],["<second>","<second>"]],"<therm-US>":[["th","therm","therms","Therm","therm-US"],105480400,"energy",["<meter>","<meter>","<kilogram>"],["<second>","<second>"]],"<Wh>":[["Wh"],3600,"energy",["<meter>","<meter>","<kilogram>"],["<second>","<second>"]],"<newton>":[["N","Newton","newton"],1,"force",["<kilogram>","<meter>"],["<second>","<second>"]],"<dyne>":[["dyn","dyne"],1e-5,"force",["<kilogram>","<meter>"],["<second>","<second>"]],"<pound-force>":[["lbf","pound-force"],4.448222,"force",["<kilogram>","<meter>"],["<second>","<second>"]],"<hertz>":[["Hz","hertz","Hertz"],1,"frequency",["<1>"],["<second>"]],"<radian>":[["rad","radian","radians"],1,"angle",["<radian>"]],"<degree>":[["deg","degree","degrees"],Math.PI/180,"angle",["<radian>"]],"<gradian>":[["gon","grad","gradian","grads"],Math.PI/200,"angle",["<radian>"]],"<steradian>":[["sr","steradian","steradians"],1,"solid_angle",["<steradian>"]],"<rotation>":[["rotation"],2*Math.PI,"angle",["<radian>"]],"<rpm>":[["rpm"],2*Math.PI/60,"angular_velocity",["<radian>"],["<second>"]],"<byte>":[["B","byte","bytes"],1,"information",["<byte>"]],"<bit>":[["b","bit","bits"],.125,"information",["<byte>"]],"<Bps>":[["Bps"],1,"information_rate",["<byte>"],["<second>"]],"<bps>":[["bps"],.125,"information_rate",["<byte>"],["<second>"]],"<dollar>":[["USD","dollar"],1,"currency",["<dollar>"]],"<cents>":[["cents"],.01,"currency",["<dollar>"]],"<candela>":[["cd","candela"],1,"luminosity",["<candela>"]],"<lumen>":[["lm","lumen"],1,"luminous_power",["<candela>","<steradian>"]],"<lux>":[["lux"],1,"illuminance",["<candela>","<steradian>"],["<meter>","<meter>"]],"<watt>":[["W","watt","watts"],1,"power",["<kilogram>","<meter>","<meter>"],["<second>","<second>","<second>"]],"<volt-ampere>":[["VA","volt-ampere"],1,"power",["<kilogram>","<meter>","<meter>"],["<second>","<second>","<second>"]],"<volt-ampere-reactive>":[["var","Var","VAr","VAR","volt-ampere-reactive"],1,"power",["<kilogram>","<meter>","<meter>"],["<second>","<second>","<second>"]],"<horsepower>":[["hp","horsepower"],745.699872,"power",["<kilogram>","<meter>","<meter>"],["<second>","<second>","<second>"]],"<gray>":[["Gy","gray","grays"],1,"radiation",["<meter>","<meter>"],["<second>","<second>"]],"<roentgen>":[["R","roentgen"],.00933,"radiation",["<meter>","<meter>"],["<second>","<second>"]],"<sievert>":[["Sv","sievert","sieverts"],1,"radiation",["<meter>","<meter>"],["<second>","<second>"]],"<becquerel>":[["Bq","becquerel","becquerels"],1,"radiation",["<1>"],["<second>"]],"<curie>":[["Ci","curie","curies"],37e9,"radiation",["<1>"],["<second>"]],"<cpm>":[["cpm"],1/60,"rate",["<count>"],["<second>"]],"<dpm>":[["dpm"],1/60,"rate",["<count>"],["<second>"]],"<bpm>":[["bpm"],1/60,"rate",["<count>"],["<second>"]],"<dot>":[["dot","dots"],1,"resolution",["<each>"]],"<pixel>":[["pixel","px"],1,"resolution",["<each>"]],"<ppi>":[["ppi"],1,"resolution",["<pixel>"],["<inch>"]],"<dpi>":[["dpi"],1,"typography",["<dot>"],["<inch>"]],"<cell>":[["cells","cell"],1,"counting",["<each>"]],"<each>":[["each"],1,"counting",["<each>"]],"<count>":[["count"],1,"counting",["<each>"]],"<base-pair>":[["bp","base-pair"],1,"counting",["<each>"]],"<nucleotide>":[["nt","nucleotide"],1,"counting",["<each>"]],"<molecule>":[["molecule","molecules"],1,"counting",["<1>"]],"<dozen>":[["doz","dz","dozen"],12,"prefix_only",["<each>"]],"<percent>":[["%","percent"],.01,"prefix_only",["<1>"]],"<ppm>":[["ppm"],1e-6,"prefix_only",["<1>"]],"<ppt>":[["ppt"],1e-9,"prefix_only",["<1>"]],"<gross>":[["gr","gross"],144,"prefix_only",["<dozen>","<dozen>"]],"<decibel>":[["dB","decibel","decibels"],1,"logarithmic",["<decibel>"]]},m=["<meter>","<kilogram>","<second>","<mole>","<ampere>","<radian>","<kelvin>","<temp-K>","<byte>","<dollar>","<candela>","<each>","<steradian>","<decibel>"],g="<1>",p=[g];function w(t,e){var i=e[1],n=e[3]||[],s=e[4]||[];if(!r(i))throw new u(t+": Invalid unit definition. 'scalar' must be a number");n.forEach((function(e){if(void 0===d[e])throw new u(t+": Invalid unit definition. Unit "+e+" in 'numerator' is not recognized")})),s.forEach((function(e){if(void 0===d[e])throw new u(t+": Invalid unit definition. Unit "+e+" in 'denominator' is not recognized")}))}var _={},b={},y={},M={},x={};for(var v in d)if(d.hasOwnProperty(v)){var E=d[v];if("prefix"===E[2]){_[v]=E[1];for(var A=0;A<E[0].length;A++)b[E[0][A]]=v}else{w(v,E),y[v]={scalar:E[1],numerator:E[3],denominator:E[4]};for(var k=0;k<E[0].length;k++)M[E[0][k]]=v}x[v]=E[0][0]}function S(t){var e,r=[],i=Object.keys(d);if(void 0===t)for(e=0;e<i.length;e++)-1===["","prefix"].indexOf(d[i[e]][2])&&r.push(i[e].substr(1,i[e].length-2));else{if(-1===this.getKinds().indexOf(t))throw new u("Kind not recognized");for(e=0;e<i.length;e++)d[i[e]][2]===t&&r.push(i[e].substr(1,i[e].length-2))}return r.sort((function(t,e){return t.toLowerCase()<e.toLowerCase()?-1:t.toLowerCase()>e.toLowerCase()?1:0}))}function I(t){if(!M[t])throw new u("Unit not recognized");return d[M[t]][0]}var D=["length","time","temperature","mass","current","substance","luminosity","currency","information","angle"];function R(){if(this.signature)return this.signature;for(var t=T.call(this),e=0;e<t.length;e++)t[e]*=Math.pow(20,e);return t.reduce((function(t,e){return t+e}),0)}function T(){if(!this.isBase())return T.call(this.toBase());for(var t,e,r=new Array(D.length),i=0;i<r.length;i++)r[i]=0;for(var n=0;n<this.numerator.length;n++)(t=d[this.numerator[n]])&&(e=D.indexOf(t[2]))>=0&&(r[e]=r[e]+1);for(var s=0;s<this.denominator.length;s++)(t=d[this.denominator[s]])&&(e=D.indexOf(t[2]))>=0&&(r[e]=r[e]-1);return r}var C="[+-]",$="\\d+",B="\\."+$,P=new RegExp("^("+C+"?\\s*(?:(?:"+$+"(?:"+B+")?)|(?:"+B+"))(?:[Ee]"+C+"?"+$+")?)?\\s*([^/]*)(?:/(.+))?$"),O="\\^|\\*{2}",N="[01234]",L=new RegExp("([^ \\*\\d]+?)(?:"+O+")?(-?"+N+"(?![a-zA-Z]))"),F=new RegExp("([^ \\*\\d]+?)(?:"+O+")?("+N+"(?![a-zA-Z]))");function U(e){t(e)||(e=e.toString()),e=e.trim();var r=P.exec(e);if(!r)throw new u(e+": Quantity not recognized");var i=r[1];i?(i=i.replace(/\s/g,""),this.scalar=parseFloat(i)):this.scalar=1;for(var n,s,a,o=r[2],h=r[3];r=L.exec(o);){if(n=parseFloat(r[2]),isNaN(n))throw new u("Unit exponent is not a number");if(0===n&&!z.test(r[1]))throw new u("Unit not recognized");s=r[1]+" ",a="";for(var l=0;l<Math.abs(n);l++)a+=s;n>=0?o=o.replace(r[0],a):(h=h?h+a:a,o=o.replace(r[0],""))}for(;r=F.exec(h);){if(n=parseFloat(r[2]),isNaN(n))throw new u("Unit exponent is not a number");if(0===n&&!z.test(r[1]))throw new u("Unit not recognized");s=r[1]+" ",a="";for(var c=0;c<n;c++)a+=s;h=h.replace(r[0],a)}o&&(this.numerator=Z(o.trim())),h&&(this.denominator=Z(h.trim()))}var H=Object.keys(b).sort((function(t,e){return e.length-t.length})).join("|"),Y=Object.keys(M).sort((function(t,e){return e.length-t.length})).join("|"),V="("+H+")??("+Y+")(?:\\b|$)",z=new RegExp("^\\s*("+V+"[\\s\\*]*)+$"),X=new RegExp(V,"g"),G={};function Z(t){var e=G[t];if(e)return e;var r,i=[];if(!z.test(t))throw new u("Unit not recognized");for(;r=X.exec(t);)i.push(r.slice(1));return i=(i=(i=i.map((function(t){return b[t[0]]?[b[t[0]],M[t[1]]]:[M[t[1]]]}))).reduce((function(t,e){return t.concat(e)}),[])).filter((function(t){return t})),G[t]=i,i}function j(e){if(!t(e))throw new u("Argument should be a string");try{return this(e)}catch(t){return null}}function K(t){return t instanceof q}function q(t,e){if(W.apply(null,arguments),!K(this))return new q(t,e);if(this.scalar=null,this.baseScalar=null,this.signature=null,this._conversionCache={},this.numerator=p,this.denominator=p,J(t)?(this.scalar=t.scalar,this.numerator=t.numerator&&0!==t.numerator.length?t.numerator:p,this.denominator=t.denominator&&0!==t.denominator.length?t.denominator:p):e?(U.call(this,e),this.scalar=t):U.call(this,t),this.denominator.join("*").indexOf("temp")>=0)throw new u("Cannot divide with temperatures");if(this.numerator.join("*").indexOf("temp")>=0){if(this.numerator.length>1)throw new u("Cannot multiply by temperatures");if(!s(this.denominator,p))throw new u("Cannot divide with temperatures")}if(this.initValue=t,Q.call(this),this.isTemperature()&&this.baseScalar<0)throw new u("Temperatures must not be less than absolute zero")}function W(e,i){if(i){if(!r(e)||!t(i))throw new u("Only number accepted as initialization value when units are explicitly provided")}else if(!(t(e)||r(e)||K(e)||J(e)))throw new u("Only string, number or quantity accepted as single initialization value")}function J(t){return t&&"object"==typeof t&&t.hasOwnProperty("scalar")}function Q(){if(this.baseScalar)return this.baseScalar;if(this.isBase())this.baseScalar=this.scalar,this.signature=R.call(this);else{var t=this.toBase();this.baseScalar=t.scalar,this.signature=t.signature}}q.prototype={constructor:q};var tt={"-312078":"elastance","-312058":"resistance","-312038":"inductance","-152058":"potential","-152040":"magnetism","-152038":"magnetism","-7997":"specific_volume","-79":"snap","-59":"jolt","-39":"acceleration","-38":"radiation","-20":"frequency","-19":"speed","-18":"viscosity","-17":"volumetric_flow","-1":"wavenumber",0:"unitless",1:"length",2:"area",3:"volume",20:"time",400:"temperature",7941:"yank",7942:"power",7959:"pressure",7961:"force",7962:"energy",7979:"viscosity",7981:"momentum",7982:"angular_momentum",7997:"density",7998:"area_density",8e3:"mass",152020:"radiation_exposure",159999:"magnetism",16e4:"current",160020:"charge",312058:"conductance",312078:"capacitance",3199980:"activity",3199997:"molar_concentration",32e5:"substance",63999998:"illuminance",64e6:"luminous_power",128e7:"currency",25599999980:"information_rate",256e8:"information",511999999980:"angular_velocity",512e9:"angle"};function et(){return n(Object.keys(tt).map((function(t){return tt[t]})))}function rt(t,e){var r=t.units(),i=e.to(r),n=q(st(r));return q({scalar:t.scalar-i.scalar,numerator:n.numerator,denominator:n.denominator})}function it(t,e){var r=e.to(st(t.units()));return q({scalar:t.scalar-r.scalar,numerator:t.numerator,denominator:t.denominator})}function nt(t,e){var r=e.to(st(t.units()));return q({scalar:t.scalar+r.scalar,numerator:t.numerator,denominator:t.denominator})}function st(t){if("tempK"===t)return"degK";if("tempC"===t)return"degC";if("tempF"===t)return"degF";if("tempR"===t)return"degR";throw new u("Unknown type for temp conversion from: "+t)}function at(t,e){var r,i=ot(t),n=e.units();if("degK"===n)r=i.scalar;else if("degC"===n)r=i.scalar;else if("degF"===n)r=9*i.scalar/5;else{if("degR"!==n)throw new u("Unknown type for degree conversion to: "+n);r=9*i.scalar/5}return q({scalar:r,numerator:e.numerator,denominator:e.denominator})}function ot(t){var e,r=t.units();if(r.match(/(deg)[CFRK]/))e=t.baseScalar;else if("tempK"===r)e=t.scalar;else if("tempC"===r)e=t.scalar;else if("tempF"===r)e=5*t.scalar/9;else{if("tempR"!==r)throw new u("Unknown type for temp conversion from: "+r);e=5*t.scalar/9}return q({scalar:e,numerator:["<kelvin>"],denominator:p})}function ht(t,e){var r,i=e.units();if("tempK"===i)r=t.baseScalar;else if("tempC"===i)r=t.baseScalar-273.15;else if("tempF"===i)r=9*t.baseScalar/5-459.67;else{if("tempR"!==i)throw new u("Unknown type for temp conversion to: "+i);r=9*t.baseScalar/5}return q({scalar:r,numerator:e.numerator,denominator:e.denominator})}function lt(t){var e,r=t.units();if(r.match(/(deg)[CFRK]/))e=t.baseScalar;else if("tempK"===r)e=t.scalar;else if("tempC"===r)e=t.scalar+273.15;else if("tempF"===r)e=5*(t.scalar+459.67)/9;else{if("tempR"!==r)throw new u("Unknown type for temp conversion from: "+r);e=5*t.scalar/9}return q({scalar:e,numerator:["<temp-K>"],denominator:p})}function ct(t,e){var r,n=q(t),s=q(e);return n.eq(s)?i:(r=n.isTemperature()?function(t){return n.mul(t).to(s).scalar}:function(t){return t*n.baseScalar/s.baseScalar},function(t){var e,i,n;if(Array.isArray(t)){for(i=t.length,n=[],e=0;e<i;e++)n.push(r(t[e]));return n}return r(t)})}q.prototype.kind=function(){return tt[this.signature.toString()]},a(q.prototype,{isDegrees:function(){return(null===this.signature||400===this.signature)&&1===this.numerator.length&&s(this.denominator,p)&&(this.numerator[0].match(/<temp-[CFRK]>/)||this.numerator[0].match(/<(kelvin|celsius|rankine|fahrenheit)>/))},isTemperature:function(){return this.isDegrees()&&this.numerator[0].match(/<temp-[CFRK]>/)}}),a(q.prototype,{to:function(e){var r,i;return null==e?this:t(e)?(r=this._conversionCache[e])?r:(i=q(e)).units()===this.units()?this:(this.isCompatible(i)?i=i.isTemperature()?ht(this,i):i.isDegrees()?at(this,i):q({scalar:h(this.baseScalar,i.baseScalar),numerator:i.numerator,denominator:i.denominator}):this.isInverse(i)?i=this.inverse().to(e):f(this.units(),i.units()),this._conversionCache[e]=i,i):this.to(e.units())},toBase:function(){if(this.isBase())return this;if(this.isTemperature())return lt(this);var t=ut[this.units()];return t||(t=ft(this.numerator,this.denominator),ut[this.units()]=t),t.mul(this.scalar)},toFloat:function(){if(this.isUnitless())return this.scalar;throw new u("Can't convert to Float unless unitless.  Use Unit#scalar")},toPrec:function(e){if(t(e)&&(e=q(e)),r(e)&&(e=q(e+" "+this.units())),this.isUnitless()?e.isUnitless()||f(this.units(),e.units()):e=e.to(this.units()),0===e.scalar)throw new u("Divide by zero");return q(o(Math.round(this.scalar/e.scalar),e.scalar)+this.units())}});var ut={};function ft(t,e){for(var r,i=[],n=[],s=1,a=0;a<t.length;a++)r=t[a],_[r]?s=o(s,_[r]):y[r]&&(s*=y[r].scalar,y[r].numerator&&i.push(y[r].numerator),y[r].denominator&&n.push(y[r].denominator));for(var h=0;h<e.length;h++)r=e[h],_[r]?s/=_[r]:y[r]&&(s/=y[r].scalar,y[r].numerator&&n.push(y[r].numerator),y[r].denominator&&i.push(y[r].denominator));return q({scalar:s,numerator:i=i.reduce((function(t,e){return t.concat(e)}),[]),denominator:n=n.reduce((function(t,e){return t.concat(e)}),[])})}function dt(t,e,r,i){function n(t){return t!==g}t=t.filter(n),r=r.filter(n),e=e.filter(n),i=i.filter(n);var s={};function a(t,e){for(var r,i,n,a=0;a<t.length;a++)if(_[t[a]]?(r=t[a+1],i=t[a],n=_[i],a++):(r=t[a],i=null,n=1),r&&r!==g)if(s[r]){s[r][0]+=e;var o=s[r][2]?_[s[r][2]]:1;s[r][1===e?3:4]*=h(n,o)}else s[r]=[e,r,i,1,1]}a(t,1),a(e,-1),a(r,1),a(i,-1);var o=[],l=[],c=1;for(var u in s)if(s.hasOwnProperty(u)){var f,d=s[u];if(d[0]>0)for(f=0;f<d[0];f++)o.push(null===d[2]?d[1]:[d[2],d[1]]);else if(d[0]<0)for(f=0;f<-d[0];f++)l.push(null===d[2]?d[1]:[d[2],d[1]]);c*=h(d[3],d[4])}return 0===o.length&&(o=p),0===l.length&&(l=p),[o=o.reduce((function(t,e){return t.concat(e)}),[]),l=l.reduce((function(t,e){return t.concat(e)}),[]),c]}function mt(){}function gt(t,e){return(t+" "+e).trim()}q.parse=j,q.getUnits=S,q.getAliases=I,q.mulSafe=o,q.divSafe=h,q.getKinds=et,q.swiftConverter=ct,q.Error=u,a(q.prototype,{add:function(e){if(t(e)&&(e=q(e)),this.isCompatible(e)||f(this.units(),e.units()),this.isTemperature()&&e.isTemperature())throw new u("Cannot add two temperatures");return this.isTemperature()?nt(this,e):e.isTemperature()?nt(e,this):q({scalar:this.scalar+e.to(this).scalar,numerator:this.numerator,denominator:this.denominator})},sub:function(e){if(t(e)&&(e=q(e)),this.isCompatible(e)||f(this.units(),e.units()),this.isTemperature()&&e.isTemperature())return rt(this,e);if(this.isTemperature())return it(this,e);if(e.isTemperature())throw new u("Cannot subtract a temperature from a differential degree unit");return q({scalar:this.scalar-e.to(this).scalar,numerator:this.numerator,denominator:this.denominator})},mul:function(e){if(r(e))return q({scalar:o(this.scalar,e),numerator:this.numerator,denominator:this.denominator});if(t(e)&&(e=q(e)),(this.isTemperature()||e.isTemperature())&&!this.isUnitless()&&!e.isUnitless())throw new u("Cannot multiply by temperatures");var i=this,n=e;i.isCompatible(n)&&400!==i.signature&&(n=n.to(i));var s=dt(i.numerator,i.denominator,n.numerator,n.denominator);return q({scalar:o(i.scalar,n.scalar,s[2]),numerator:s[0],denominator:s[1]})},div:function(e){if(r(e)){if(0===e)throw new u("Divide by zero");return q({scalar:this.scalar/e,numerator:this.numerator,denominator:this.denominator})}if(t(e)&&(e=q(e)),0===e.scalar)throw new u("Divide by zero");if(e.isTemperature())throw new u("Cannot divide with temperatures");if(this.isTemperature()&&!e.isUnitless())throw new u("Cannot divide with temperatures");var i=this,n=e;i.isCompatible(n)&&400!==i.signature&&(n=n.to(i));var s=dt(i.numerator,i.denominator,n.denominator,n.numerator);return q({scalar:o(i.scalar,s[2])/n.scalar,numerator:s[0],denominator:s[1]})},inverse:function(){if(this.isTemperature())throw new u("Cannot divide with temperatures");if(0===this.scalar)throw new u("Divide by zero");return q({scalar:1/this.scalar,numerator:this.denominator,denominator:this.numerator})}}),a(q.prototype,{eq:function(t){return 0===this.compareTo(t)},lt:function(t){return-1===this.compareTo(t)},lte:function(t){return this.eq(t)||this.lt(t)},gt:function(t){return 1===this.compareTo(t)},gte:function(t){return this.eq(t)||this.gt(t)},compareTo:function(e){return t(e)?this.compareTo(q(e)):(this.isCompatible(e)||f(this.units(),e.units()),this.baseScalar<e.baseScalar?-1:this.baseScalar===e.baseScalar?0:this.baseScalar>e.baseScalar?1:void 0)},same:function(t){return this.scalar===t.scalar&&this.units()===t.units()}}),a(q.prototype,{isUnitless:function(){return[this.numerator,this.denominator].every((function(t){return s(t,p)}))},isCompatible:function(e){return t(e)?this.isCompatible(q(e)):!!K(e)&&void 0!==e.signature&&this.signature===e.signature},isInverse:function(t){return this.inverse().isCompatible(t)},isBase:function(){return void 0!==this._isBase?this._isBase:this.isDegrees()&&this.numerator[0].match(/<(kelvin|temp-K)>/)?(this._isBase=!0,this._isBase):(this.numerator.concat(this.denominator).forEach((function(t){t!==g&&-1===m.indexOf(t)&&(this._isBase=!1)}),this),!1===this._isBase||(this._isBase=!0),this._isBase)}}),mt.prototype.get=function(t){return arguments.length>1&&(t=Array.apply(null,arguments)),t.reduce((function(e,r,i){if(e){var n=e[r];return i===t.length-1?n?n.data:void 0:n}}),this)},mt.prototype.set=function(t,e){return arguments.length>2&&(t=Array.prototype.slice.call(arguments,0,-1),e=arguments[arguments.length-1]),t.reduce((function(r,i,n){var s=r[i];return void 0===s&&(s=r[i]={}),n===t.length-1?(s.data=e,e):s}),this)},q.formatter=gt,a(q.prototype,{units:function(){if(void 0!==this._units)return this._units;var t=s(this.numerator,p),e=s(this.denominator,p);if(t&&e)return this._units="",this._units;var r=wt(this.numerator),i=wt(this.denominator);return this._units=r+(e?"":"/"+i),this._units},toString:function(e,i){var n;if(r(e))n=this.units(),i=e;else if(t(e))n=e;else if(K(e))return this.toPrec(e).toString(i);var s=this.to(n);return s=((void 0!==i?l(s.scalar,i):s.scalar)+" "+s.units()).trim()},format:function(t,e){1===arguments.length&&"function"==typeof t&&(e=t,t=void 0),e=e||q.formatter;var r=this.to(t);return e.call(this,r.scalar,r.units())}});var pt=new mt;function wt(t){var e=pt.get(t);return e||(e=s(t,p)?"1":bt(_t(t)).join("*"),pt.set(t,e),e)}function _t(t){for(var e,r,i=[],n=0;n<t.length;n++)e=t[n],r=t[n+1],_[e]?(i.push(x[e]+x[r]),n++):i.push(x[e]);return i}function bt(t){return t.reduce((function(t,e){var r=t[e];return r||t.push(r=t[e]=[e,0]),r[1]++,t}),[]).map((function(t){return t[0]+(t[1]>1?t[1]:"")}))}return q.version="1.7.6",q}()}));function deepValue(t,e=""){let r=e.split(".");for(let e of r){if(void 0===t[e])return;t=t[e]}return t}var twoProduct_1=twoProduct,SPLITTER=+(Math.pow(2,27)+1);function twoProduct(t,e,r){var i=t*e,n=SPLITTER*t,s=n-(n-t),a=t-s,o=SPLITTER*e,h=o-(o-e),l=e-h,c=a*l-(i-s*h-a*h-s*l);return r?(r[0]=c,r[1]=i,r):[c,i]}var robustSum=linearExpansionSum;function scalarScalar$1(t,e){var r=t+e,i=r-t,n=t-(r-i)+(e-i);return n?[n,r]:[r]}function linearExpansionSum(t,e){var r=0|t.length,i=0|e.length;if(1===r&&1===i)return scalarScalar$1(t[0],e[0]);var n,s,a=new Array(r+i),o=0,h=0,l=0,c=Math.abs,u=t[h],f=c(u),d=e[l],m=c(d);f<m?(s=u,(h+=1)<r&&(f=c(u=t[h]))):(s=d,(l+=1)<i&&(m=c(d=e[l]))),h<r&&f<m||l>=i?(n=u,(h+=1)<r&&(f=c(u=t[h]))):(n=d,(l+=1)<i&&(m=c(d=e[l])));for(var g,p,w=n+s,_=w-n,b=s-_,y=b,M=w;h<r&&l<i;)f<m?(n=u,(h+=1)<r&&(f=c(u=t[h]))):(n=d,(l+=1)<i&&(m=c(d=e[l]))),(b=(s=y)-(_=(w=n+s)-n))&&(a[o++]=b),y=M-((g=M+w)-(p=g-M))+(w-p),M=g;for(;h<r;)(b=(s=y)-(_=(w=(n=u)+s)-n))&&(a[o++]=b),y=M-((g=M+w)-(p=g-M))+(w-p),M=g,(h+=1)<r&&(u=t[h]);for(;l<i;)(b=(s=y)-(_=(w=(n=d)+s)-n))&&(a[o++]=b),y=M-((g=M+w)-(p=g-M))+(w-p),M=g,(l+=1)<i&&(d=e[l]);return y&&(a[o++]=y),M&&(a[o++]=M),o||(a[o++]=0),a.length=o,a}var twoSum=fastTwoSum;function fastTwoSum(t,e,r){var i=t+e,n=i-t,s=e-n,a=t-(i-n);return r?(r[0]=a+s,r[1]=i,r):[a+s,i]}var robustScale=scaleLinearExpansion;function scaleLinearExpansion(t,e){var r=t.length;if(1===r){var i=twoProduct_1(t[0],e);return i[0]?i:[i[1]]}var n=new Array(2*r),s=[.1,.1],a=[.1,.1],o=0;twoProduct_1(t[0],e,s),s[0]&&(n[o++]=s[0]);for(var h=1;h<r;++h){twoProduct_1(t[h],e,a);var l=s[1];twoSum(l,a[0],s),s[0]&&(n[o++]=s[0]);var c=a[1],u=s[1],f=c+u,d=u-(f-c);s[1]=f,d&&(n[o++]=d)}return s[1]&&(n[o++]=s[1]),0===o&&(n[o++]=0),n.length=o,n}var robustDiff=robustSubtract;function scalarScalar(t,e){var r=t+e,i=r-t,n=t-(r-i)+(e-i);return n?[n,r]:[r]}function robustSubtract(t,e){var r=0|t.length,i=0|e.length;if(1===r&&1===i)return scalarScalar(t[0],-e[0]);var n,s,a=new Array(r+i),o=0,h=0,l=0,c=Math.abs,u=t[h],f=c(u),d=-e[l],m=c(d);f<m?(s=u,(h+=1)<r&&(f=c(u=t[h]))):(s=d,(l+=1)<i&&(m=c(d=-e[l]))),h<r&&f<m||l>=i?(n=u,(h+=1)<r&&(f=c(u=t[h]))):(n=d,(l+=1)<i&&(m=c(d=-e[l])));for(var g,p,w=n+s,_=w-n,b=s-_,y=b,M=w;h<r&&l<i;)f<m?(n=u,(h+=1)<r&&(f=c(u=t[h]))):(n=d,(l+=1)<i&&(m=c(d=-e[l]))),(b=(s=y)-(_=(w=n+s)-n))&&(a[o++]=b),y=M-((g=M+w)-(p=g-M))+(w-p),M=g;for(;h<r;)(b=(s=y)-(_=(w=(n=u)+s)-n))&&(a[o++]=b),y=M-((g=M+w)-(p=g-M))+(w-p),M=g,(h+=1)<r&&(u=t[h]);for(;l<i;)(b=(s=y)-(_=(w=(n=d)+s)-n))&&(a[o++]=b),y=M-((g=M+w)-(p=g-M))+(w-p),M=g,(l+=1)<i&&(d=-e[l]);return y&&(a[o++]=y),M&&(a[o++]=M),o||(a[o++]=0),a.length=o,a}var orientation_1=createCommonjsModule((function(t){function e(t,e){for(var r=new Array(t.length-1),i=1;i<t.length;++i)for(var n=r[i-1]=new Array(t.length-1),s=0,a=0;s<t.length;++s)s!==e&&(n[a++]=t[i][s]);return r}function r(t){if(1===t.length)return t[0];if(2===t.length)return["sum(",t[0],",",t[1],")"].join("");var e=t.length>>1;return["sum(",r(t.slice(0,e)),",",r(t.slice(e)),")"].join("")}function i(t){if(2===t.length)return[["sum(prod(",t[0][0],",",t[1][1],"),prod(-",t[0][1],",",t[1][0],"))"].join("")];for(var n=[],s=0;s<t.length;++s)n.push(["scale(",r(i(e(t,s))),",",(a=s,1&a?"-":""),t[0][s],")"].join(""));return n;var a}function n(t){for(var n=[],s=[],a=function(t){for(var e=new Array(t),r=0;r<t;++r){e[r]=new Array(t);for(var i=0;i<t;++i)e[r][i]=["m",i,"[",t-r-1,"]"].join("")}return e}(t),o=[],h=0;h<t;++h)0==(1&h)?n.push.apply(n,i(e(a,h))):s.push.apply(s,i(e(a,h))),o.push("m"+h);var l=r(n),c=r(s),u="orientation"+t+"Exact",f=["function ",u,"(",o.join(),"){var p=",l,",n=",c,",d=sub(p,n);return d[d.length-1];};return ",u].join("");return new Function("sum","prod","scale","sub",f)(robustSum,twoProduct_1,robustScale,robustDiff)}var s=n(3),a=n(4),o=[function(){return 0},function(){return 0},function(t,e){return e[0]-t[0]},function(t,e,r){var i,n=(t[1]-r[1])*(e[0]-r[0]),a=(t[0]-r[0])*(e[1]-r[1]),o=n-a;if(n>0){if(a<=0)return o;i=n+a}else{if(!(n<0))return o;if(a>=0)return o;i=-(n+a)}var h=33306690738754716e-32*i;return o>=h||o<=-h?o:s(t,e,r)},function(t,e,r,i){var n=t[0]-i[0],s=e[0]-i[0],o=r[0]-i[0],h=t[1]-i[1],l=e[1]-i[1],c=r[1]-i[1],u=t[2]-i[2],f=e[2]-i[2],d=r[2]-i[2],m=s*c,g=o*l,p=o*h,w=n*c,_=n*l,b=s*h,y=u*(m-g)+f*(p-w)+d*(_-b),M=7771561172376103e-31*((Math.abs(m)+Math.abs(g))*Math.abs(u)+(Math.abs(p)+Math.abs(w))*Math.abs(f)+(Math.abs(_)+Math.abs(b))*Math.abs(d));return y>M||-y>M?y:a(t,e,r,i)}];function h(t){var e=o[t.length];return e||(e=o[t.length]=n(t.length)),e.apply(void 0,t)}!function(){for(;o.length<=5;)o.push(n(o.length));for(var e=[],r=["slow"],i=0;i<=5;++i)e.push("a"+i),r.push("o"+i);var s=["function getOrientation(",e.join(),"){switch(arguments.length){case 0:case 1:return 0;"];for(i=2;i<=5;++i)s.push("case ",i,":return o",i,"(",e.slice(0,i).join(),");");s.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation"),r.push(s.join(""));var a=Function.apply(void 0,r);for(t.exports=a.apply(void 0,[h].concat(o)),i=0;i<=5;++i)t.exports[i]=o[i]}()})),robustPnp=robustPointInPolygon;function robustPointInPolygon(t,e){for(var r=e[0],i=e[1],n=t.length,s=1,a=n,o=0,h=n-1;o<a;h=o++){var l=t[o],c=t[h],u=l[1],f=c[1];if(f<u){if(f<i&&i<u){if(0===(d=orientation_1(l,c,e)))return 0;s^=0<d|0}else if(i===u){if(u<t[(o+1)%n][1]){if(0===(d=orientation_1(l,c,e)))return 0;s^=0<d|0}}}else if(u<f){if(u<i&&i<f){if(0===(d=orientation_1(l,c,e)))return 0;s^=d<0|0}else if(i===u){if(t[(o+1)%n][1]<u){var d;if(0===(d=orientation_1(l,c,e)))return 0;s^=d<0|0}}}else if(i===u){var m=Math.min(l[0],c[0]),g=Math.max(l[0],c[0]);if(0===o){for(;h>0;){var p=(h+n-1)%n;if((b=t[p])[1]!==i)break;var w=b[0];m=Math.min(m,w),g=Math.max(g,w),h=p}if(0===h)return m<=r&&r<=g?0:1;a=h+1}for(var _=t[(h+n-1)%n][1];o+1<a;){var b;if((b=t[o+1])[1]!==i)break;w=b[0];m=Math.min(m,w),g=Math.max(g,w),o+=1}if(m<=r&&r<=g)return 0;var y=t[(o+1)%n][1];r<m&&_<i!=y<i&&(s^=1)}}return 2*s-1}function feretDiameters(t={}){const{originalPoints:e=monotoneChainConvexHull.call(this)}=t;if(0===e.length)return{min:0,max:0,minLine:[],maxLine:[],aspectRatio:1};if(1===e.length)return{min:1,max:1,minLine:[e[0],e[0]],maxLine:[e[0],e[0]],aspectRatio:1};const r=new Array(e.length);let i=1/0,n=0,s=[];for(let t=0;t<e.length;t++){let a=getAngle(e[t],e[(t+1)%e.length]);rotate(-a,e,r);let o=0,h=[];for(let i=0;i<e.length;i++){let e=Math.abs(r[t][1]-r[i][1]);e>o&&(o=e,h=[],h.push([r[i][0],r[t][1]],[r[i][0],r[i][1]]))}o<i&&(i=o,n=a,s=h)}rotate(n,s,s);let a=0,o=[],h=0;for(let t=0;t<e.length-1;t++)for(let r=t+1;r<e.length;r++){let i=(e[t][0]-e[r][0])**2+(e[t][1]-e[r][1])**2;i>h&&(h=i,a=Math.sqrt(i),o=[e[t],e[r]])}return{min:i,minLine:s,max:a,maxLine:o,aspectRatio:i/a}}function getAngle(t,e){let r=normalize(difference(e,t)),i=Math.acos(r[0]);return r[1]<0?-i:i}class Roi{constructor(t,e){this.map=t,this.id=e,this.minX=Number.POSITIVE_INFINITY,this.maxX=Number.NEGATIVE_INFINITY,this.minY=Number.POSITIVE_INFINITY,this.maxY=Number.NEGATIVE_INFINITY,this.meanX=0,this.meanY=0,this.surface=0,this.computed={}}getMask(t={}){const{scale:e=1,kind:r=""}=t;let i;switch(r){case"contour":i=this.contourMask;break;case"box":i=this.boxMask;break;case"filled":i=this.filledMask;break;case"center":i=this.centerMask;break;case"mbr":i=this.mbrFilledMask;break;case"hull":i=this.convexHullFilledMask;break;case"hullContour":i=this.convexHullMask;break;case"mbrContour":i=this.mbrMask;break;case"feret":i=this.feretMask;break;default:i=this.mask}return e<1&&(i=i.resize({factor:e}),i.parent=this.mask.parent,i.position[0]+=this.minX,i.position[1]+=this.minY),i}get mean(){throw new Error("Roi mean not implemented yet")}get center(){return this.computed.center||(this.computed.center=[this.width/2>>0,this.height/2>>0]),this.computed.center}get ratio(){return this.width/this.height}get width(){return this.maxX-this.minX+1}get height(){return this.maxY-this.minY+1}_computExternalIDs(){let t=this.borderIDs,e=this.borderLengths;this.computed.externalIDs=[],this.computed.externalLengths=[];let r=this.internalIDs;for(let i=0;i<t.length;i++)r.includes(t[i])||(this.computed.externalIDs.push(t[i]),this.computed.externalLengths.push(e[i]))}get externalIDs(){return this.computed.externalIDs||this._computExternalIDs(),this.computed.externalIDs}get externalLengths(){return this.computed.externalLengths||this._computExternalIDs(),this.computed.externalLengths}_computeBorderIDs(){let t=getBorders(this);this.computed.borderIDs=t.ids,this.computed.borderLengths=t.lengths}get borderIDs(){return this.computed.borderIDs||this._computeBorderIDs(),this.computed.borderIDs}get borderLengths(){return this.computed.borderLengths||this._computeBorderIDs(),this.computed.borderLengths}get boxIDs(){return this.computed.boxIDs||(this.computed.boxIDs=getBoxIDs(this)),this.computed.boxIDs}get internalIDs(){return this.computed.internalIDs||(this.computed.internalIDs=getInternalIDs(this)),this.computed.internalIDs}get box(){return this.computed.box||(this.computed.box=getBox(this)),this.computed.box}get external(){return this.computed.external||(this.computed.external=getExternal(this)),this.computed.external}get holesInfo(){return this.computed.holesInfo||(this.computed.holesInfo=getHolesInfo(this)),this.computed.holesInfo}get border(){return this.computed.border||(this.computed.border=getBorder(this)),this.computed.border}get contourMask(){if(!this.computed.contourMask){let t=new Image(this.width,this.height,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent});for(let e=0;e<this.width;e++)for(let r=0;r<this.height;r++)this.map.data[e+this.minX+(r+this.minY)*this.map.width]===this.id&&(e>0&&e<this.width-1&&r>0&&r<this.height-1&&this.map.data[e-1+this.minX+(r+this.minY)*this.map.width]===this.id&&this.map.data[e+1+this.minX+(r+this.minY)*this.map.width]===this.id&&this.map.data[e+this.minX+(r-1+this.minY)*this.map.width]===this.id&&this.map.data[e+this.minX+(r+1+this.minY)*this.map.width]===this.id||t.setBitXY(e,r));this.computed.contourMask=t}return this.computed.contourMask}get boxMask(){if(!this.computed.boxMask){let t=new Image(this.width,this.height,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent});for(let e=0;e<this.width;e++)t.setBitXY(e,0),t.setBitXY(e,this.height-1);for(let e=0;e<this.height;e++)t.setBitXY(0,e),t.setBitXY(this.width-1,e);this.computed.boxMask=t}return this.computed.boxMask}get mask(){if(!this.computed.mask){let t=new Image(this.width,this.height,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent});for(let e=0;e<this.width;e++)for(let r=0;r<this.height;r++)this.map.data[e+this.minX+(r+this.minY)*this.map.width]===this.id&&t.setBitXY(e,r);this.computed.mask=t}return this.computed.mask}get filledMask(){if(!this.computed.filledMask){let t=new Image(this.width,this.height,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent});for(let e=0;e<this.width;e++)for(let r=0;r<this.height;r++){let i=e+this.minX+(r+this.minY)*this.map.width;this.internalIDs.includes(this.map.data[i])&&t.setBitXY(e,r)}this.computed.filledMask=t}return this.computed.filledMask}get centerMask(){if(!this.computed.centerMask){let t=new Shape({kind:"smallCross"}).getMask();t.parent=this.map.parent,t.position=[this.minX+this.center[0]-1,this.minY+this.center[1]-1],this.computed.centerMask=t}return this.computed.centerMask}get convexHull(){if(!this.computed.convexHull){const t=[];for(let e=0;e<this.width;e++)for(let r=0;r<this.height;r++)this.map.data[e+this.minX+(r+this.minY)*this.map.width]===this.id&&(e>0&&e<this.width-1&&r>0&&r<this.height-1&&this.map.data[e-1+this.minX+(r+this.minY)*this.map.width]===this.id&&this.map.data[e+1+this.minX+(r+this.minY)*this.map.width]===this.id&&this.map.data[e+this.minX+(r-1+this.minY)*this.map.width]===this.id&&this.map.data[e+this.minX+(r+1+this.minY)*this.map.width]===this.id||(t.push([e,r]),t.push([e+1,r]),t.push([e,r+1]),t.push([e+1,r+1])));const e=monotoneChainConvexHull$1(t);this.computed.convexHull={polyline:e,surface:surface(e),perimeter:perimeter(e)}}return this.computed.convexHull}get convexHullMask(){if(!this.computed.convexHullMask){const t=this.convexHull,e=new Image(this.width+1,this.height+1,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent});e.paintPolyline(t.polyline,{closed:!0}),this.computed.convexHullMask=e}return this.computed.convexHullMask}get convexHullFilledMask(){if(!this.computed.convexHullFilledMask){const t=this.convexHull,e=new Image(this.width,this.height,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent});for(let r=0;r<this.width;r++)for(let i=0;i<this.height;i++)1!==robustPnp(t.polyline,[r,i])&&e.setBitXY(r,i);this.computed.convexHullFilledMask=e}return this.computed.convexHullFilledMask}get mbr(){if(!this.computed.mbr){let t=minimalBoundingRectangle({originalPoints:this.convexHull.polyline});if(0===t.length)this.computed.mbr={width:0,height:0,surface:0,perimeter:0,rectangle:t};else{let e=t[0],r=t[1],i=t[2],n=Math.sqrt((e[0]-r[0])**2+(e[1]-r[1])**2),s=Math.sqrt((i[0]-r[0])**2+(i[1]-r[1])**2);this.computed.mbr={width:n,height:s,elongation:1-n/s,aspectRatio:n/s,surface:n*s,perimeter:2*(n+s),rectangle:t}}}return this.computed.mbr}get fillRatio(){return this.surface/(this.surface+this.holesInfo.surface)}get feretDiameters(){return this.computed.feretDiameters||(this.computed.feretDiameters=feretDiameters({originalPoints:this.convexHull.polyline})),this.computed.feretDiameters}get eqpc(){return this.computed.eqpc||(this.computed.eqpc=2*Math.sqrt(this.surface/Math.PI)),this.computed.eqpc}get perimeterInfo(){return this.computed.perimeterInfo||(this.computed.perimeterInfo=getPerimeterInfo(this)),this.computed.perimeterInfo}get perimeter(){let t=this.perimeterInfo,e=2-Math.sqrt(2);return t.one+2*t.two+3*t.three+4*t.four-e*(t.two+2*t.three+t.four)}get ped(){return this.computed.ped||(this.computed.ped=this.perimeter/Math.PI),this.computed.ped}get feretMask(){if(!this.computed.feretMask){const t=new Image(this.width+1,this.height+1,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent});t.paintPolyline(this.feretDiameters.minLine),t.paintPolyline(this.feretDiameters.maxLine),this.computed.feretMask=t}return this.computed.feretMask}get mbrMask(){if(!this.computed.mbrMask){let t=round(this.mbr.rectangle);if(t.length>0){const e=minMax(t),r=new Image(e[1][0]-e[0][0]+1,e[1][1]-e[0][1]+1,{kind:BINARY,position:[this.minX+e[0][0],this.minY+e[0][1]],parent:this.map.parent});t=moveToZeroZero(t),r.paintPolyline(t,{closed:!0}),this.computed.mbrMask=r}else this.computed.mbrMask=new Image(1,1,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent})}return this.computed.mbrMask}get mbrFilledMask(){if(!this.computed.mbrFilledMask){const t=new Image(this.width,this.height,{kind:BINARY,position:[this.minX,this.minY],parent:this.map.parent}),e=this.mask.minimalBoundingRectangle();for(let r=0;r<this.width;r++)for(let i=0;i<this.height;i++)1!==robustPnp(e,[r,i])&&t.setBitXY(r,i);this.computed.mbrFilledMask=t}return this.computed.mbrFilledMask}get points(){if(!this.computed.points){let t=[];for(let e=0;e<this.height;e++)for(let r=0;r<this.width;r++){let i=(e+this.minY)*this.map.width+r+this.minX;this.map.data[i]===this.id&&t.push([r,e])}this.computed.points=t}return this.computed.points}get maxLengthPoints(){if(!this.computed.maxLengthPoints){let t,e=0;const r=this.points;for(let i=0;i<r.length;i++)for(let n=i+1;n<r.length;n++){let s=Math.pow(r[i][0]-r[n][0],2)+Math.pow(r[i][1]-r[n][1],2);s>=e&&(e=s,t=[r[i],r[n]])}this.computed.maxLengthPoints=t}return this.computed.maxLengthPoints}get maxLength(){if(!this.computed.maxLength){let t=Math.sqrt(Math.pow(this.maxLengthPoints[0][0]-this.maxLengthPoints[1][0],2)+Math.pow(this.maxLengthPoints[0][1]-this.maxLengthPoints[1][1],2));this.computed.maxLength=t}return this.computed.maxLength}get roundness(){return 4*this.surface/(Math.PI*this.feretDiameters.max**2)}get sphericity(){return 2*Math.sqrt(this.surface*Math.PI)/this.perimeter}get solidity(){return this.surface/this.convexHull.surface}get angle(){if(!this.computed.angle){let t=this.maxLengthPoints,e=180*-Math.atan2(t[0][1]-t[1][1],t[0][0]-t[1][0])/Math.PI;this.computed.angle=e}return this.computed.angle}toJSON(){return{id:this.id,minX:this.minX,maxX:this.maxX,minY:this.minY,maxY:this.maxY,meanX:this.meanX,meanY:this.meanY,height:this.height,width:this.width,surface:this.surface,mbrWidth:this.mbr.width,mbrHeight:this.mbr.height,mbrSurface:this.mbr.surface,eqpc:this.eqpc,ped:this.ped,feretDiameterMin:this.feretDiameters.min,feretDiameterMax:this.feretDiameters.max,aspectRatio:this.feretDiameters.aspectRatio,fillRatio:this.fillRatio,sphericity:this.sphericity,roundness:this.roundness,solidity:this.solidity,perimeter:this.perimeter}}}function getBorders(t){let e=t.map,r=e.data,i=new Set,n=new Map,s=new Set,a=[1,0,-1,0],o=[0,1,0,-1];for(let h=t.minX;h<=t.maxX;h++)for(let l=t.minY;l<=t.maxY;l++){if(r[h+l*e.width]===t.id)for(let c=0;c<4;c++){let u=h+a[c],f=l+o[c];if(u>=0&&f>=0&&u<e.width&&f<e.height){let a=u+f*e.width;if(r[a]!==t.id&&!s.has(a)){s.add(a),i.add(r[a]);let t=n.get(r[a]);t?n.set(r[a],++t):n.set(r[a],1)}}}}let h=Array.from(i),l=h.map((function(t){return n.get(t)}));return{ids:h,lengths:l}}function getBoxIDs(t){let e=new Set,r=t.map,i=r.data;for(let n of[0,t.height-1])for(let s=0;s<t.width;s++){let a=(n+t.minY)*r.width+s+t.minX;if(s-t.minX>0&&i[a]===t.id&&i[a-1]!==t.id){let t=i[a-1];e.add(t)}if(r.width-s-t.minX>1&&i[a]===t.id&&i[a+1]!==t.id){let t=i[a+1];e.add(t)}}for(let n of[0,t.width-1])for(let s=0;s<t.height;s++){let a=(s+t.minY)*r.width+n+t.minX;if(s-t.minY>0&&i[a]===t.id&&i[a-r.width]!==t.id){let t=i[a-r.width];e.add(t)}if(r.height-s-t.minY>1&&i[a]===t.id&&i[a+r.width]!==t.id){let t=i[a+r.width];e.add(t)}}return Array.from(e)}function getBox(t){let e=0,r=t.map,i=r.data,n=[0];t.height>1&&(n[1]=t.height-1);for(let s of n)for(let n=1;n<t.width-1;n++){i[(s+t.minY)*r.width+n+t.minX]===t.id&&e++}let s=[0];t.width>1&&(s[1]=t.width-1);for(let n of s)for(let s=0;s<t.height;s++){i[(s+t.minY)*r.width+n+t.minX]===t.id&&e++}return e}function getBorder(t){let e=0,r=t.map,i=r.data;for(let n=1;n<t.width-1;n++)for(let s=1;s<t.height-1;s++){let a=(s+t.minY)*r.width+n+t.minX;i[a]===t.id&&(i[a-1]===t.id&&i[a+1]===t.id&&i[a-r.width]===t.id&&i[a+r.width]===t.id||e++)}return e+t.box}function getPerimeterInfo(t){let e=t.map,r=e.data,i=0,n=0,s=0,a=0;for(let o=0;o<t.width;o++)for(let h=0;h<t.height;h++){let l=(h+t.minY)*e.width+o+t.minX;if(r[l]===t.id){let c=0;switch((0===o||t.externalIDs.includes(r[l-1]))&&c++,(o===t.width-1||t.externalIDs.includes(r[l+1]))&&c++,(0===h||t.externalIDs.includes(r[l-e.width]))&&c++,(h===t.height-1||t.externalIDs.includes(r[l+e.width]))&&c++,c){case 1:i++;break;case 2:n++;break;case 3:s++;break;case 4:a++}}}return{one:i,two:n,three:s,four:a}}function getExternal(t){let e=0,r=t.map,i=r.data;for(let n=1;n<t.width-1;n++)for(let s=1;s<t.height-1;s++){let a=(s+t.minY)*r.width+n+t.minX;i[a]===t.id&&(t.externalIDs.includes(i[a-1])||t.externalIDs.includes(i[a+1])||t.externalIDs.includes(i[a-r.width])||t.externalIDs.includes(i[a+r.width]))&&e++}return e+t.box}function getHolesInfo(t){let e=0,r=t.map.width,i=t.map.data;for(let n=1;n<t.width-1;n++)for(let s=1;s<t.height-1;s++){let a=(s+t.minY)*r+n+t.minX;t.internalIDs.includes(i[a])&&i[a]!==t.id&&e++}return{number:t.internalIDs.length-1,surface:e}}function getInternalIDs(t){let e=[t.id],r=t.map,i=r.data;if(t.height>2)for(let n=0;n<t.width;n++){let s=t.minY*r.width+n+t.minX;if(e.includes(i[s])){let n=i[s+r.width];e.includes(n)||t.boxIDs.includes(n)||e.push(n)}}let n=new Array(4);for(let s=1;s<t.width-1;s++)for(let a=1;a<t.height-1;a++){let o=(a+t.minY)*r.width+s+t.minX;if(e.includes(i[o])){n[0]=i[o-1],n[1]=i[o+1],n[2]=i[o-r.width],n[3]=i[o+r.width];for(let r=0;r<4;r++){let i=n[r];e.includes(i)||t.boxIDs.includes(i)||e.push(i)}}}return e}class RoiLayer{constructor(t,e){this.roiMap=t,this.options=e,this.roi=this.createRoi()}createRoi(){let t=this.roiMap.data,e={};this.roiMap.positive=0,this.roiMap.negative=0;for(let r=0;r<t.length;r++)t[r]&&!e[t[r]]&&(e[t[r]]=!0,t[r]>0?this.roiMap.positive++:this.roiMap.negative++);let r={};for(let t in e)r[t]=new Roi(this.roiMap,1*t);let i=this.roiMap.width,n=this.roiMap.height;for(let e=0;e<n;e++)for(let n=0;n<i;n++){let s=e*i+n;if(0!==t[s]){const i=r[t[s]];n<i.minX&&(i.minX=n),n>i.maxX&&(i.maxX=n),e<i.minY&&(i.minY=e),e>i.maxY&&(i.maxY=e),i.meanX+=n,i.meanY+=e,i.surface++}}let s=[];for(let t in e)r[t].meanX/=r[t].surface,r[t].meanY/=r[t].surface,s.push(r[t]);return s}}function commonBorderLength(t){let e=t.data,r=[1,0,-1,0],i=[0,1,0,-1],n=t.minMax,s=-n.min,a=n.max+s,o=[];for(let t=0;t<=a;t++)o.push(Object.create(null));for(let n=0;n<t.width;n++)for(let a=0;a<t.height;a++){let h=e[n+a*t.width];if(0!==h){let l=Object.create(null),c=!1;for(let u=0;u<4;u++){let f=n+r[u],d=a+i[u];if(f>=0&&d>=0&&f<t.width&&d<t.height){let r=e[f+d*t.width];h!==r&&(c=!0,0!==r&&void 0===l[r]&&(l[r]=!0,o[r+s][h]?o[r+s][h]++:o[r+s][h]=1))}else c=!0}c&&(o[h+s][h]?o[h+s][h]++:o[h+s][h]=1)}}let h={};for(let t=0;t<o.length;t++)Object.keys(o[t]).length>0&&(h[t-s]=o[t]);return h}function mergeRoi(t={}){const{algorithm:e="commonBorderLength",minCommonBorderLength:r=5,maxCommonBorderLength:i=100,minCommonBorderRatio:n=.3,maxCommonBorderRatio:s=1}=t;let a=function(t,e,n){return t[n]>=r&&t[n]<=i};"function"==typeof e&&(a=e),"commonborderratio"===e.toLowerCase()&&(a=function(t,e,r){let i=Math.min(t[r]/t[e],1);return i>=n&&i<=s});const o=this,h=o.commonBorderLength;let l={},c={};for(let t of Object.keys(h)){let e=h[t],r=Object.keys(e);for(let i of r)if(i!==t&&a(e,t,i)){let e=i;c[i]&&(e=c[i]);let r=t;if(c[t]&&(r=c[t]),Number(e)!==r){let t=Math.min(e,r),i=Math.max(e,r);if(l[t]||(l[t]={}),l[t][i]=!0,c[i]=t,l[i]){for(let e of Object.keys(l[i]))l[t][e]=!0,c[e]=t;delete l[i]}}}}let u=o.minMax,f=-u.min,d=u.max+f,m=new Array(d+1).fill(0);for(let t of Object.keys(c))m[Number(t)+f]=c[t];let g=o.data;for(let t=0;t<g.length;t++){let e=g[t];if(0!==e){let r=m[e+f];0!==r&&(g[t]=r)}}return o.computed={},o}class RoiMap{constructor(t,e){this.parent=t,this.width=t.width,this.height=t.height,this.data=e,this.negative=0,this.positive=0}get total(){return this.negative+this.positive}get minMax(){let t=Number.MAX_SAFE_INTEGER,e=Number.MIN_SAFE_INTEGER;for(let r=0;r<this.data.length;r++)this.data[r]<t&&(t=this.data[r]),this.data[r]>e&&(e=this.data[r]);return{min:t,max:e}}get commonBorderLength(){return commonBorderLength(this)}mergeRoi(t={}){return mergeRoi.call(this,t)}mergeRois(t){const e=t[0],r=t.slice(1);for(let t=0;t<this.data.length;t++)r.includes(this.data[t])&&(this.data[t]=e)}rowsInfo(){let t=new Array(this.height),e=0;for(let r=0;r<this.data.length;r+=this.width){let i={row:e,positivePixel:0,negativePixel:0,zeroPixel:0,positiveRoi:0,negativeRoi:0,medianChange:0};t[e++]=i;let n={},s={},a=[],o=this.data[r],h=0;for(let t=r;t<r+this.width;t++){let e=this.data[t];o!==e&&(o=e,a.push(h),h=0),h++,e>0?(i.positivePixel++,n[e]||(n[e]=!0)):e<0?(i.negativePixel++,s[e]||(s[e]=!0)):i.zeroPixel++}a.push(h),i.medianChange=a.sort(((t,e)=>t-e))[Math.floor(a.length/2)],i.positiveRoiIDs=Object.keys(n),i.negativeRoiIDs=Object.keys(s),i.positiveRoi=i.positiveRoiIDs.length,i.negativeRoi=i.negativeRoiIDs.length}return t}colsInfo(){let t=new Array(this.width),e=0;for(let r=0;r<this.width;r++){let i={col:e,positivePixel:0,negativePixel:0,zeroPixel:0,positiveRoi:0,negativeRoi:0,medianChange:0};t[e++]=i;let n={},s={},a=[],o=this.data[r],h=0;for(let t=r;t<r+this.data.length;t+=this.width){let e=this.data[t];o!==e&&(o=e,a.push(h),h=0),h++,e>0?(i.positivePixel++,n[e]||(n[e]=!0)):e<0?(i.negativePixel++,s[e]||(s[e]=!0)):i.zeroPixel++}a.push(h),i.medianChange=a.sort(((t,e)=>t-e))[Math.floor(a.length/2)],i.positiveRoiIDs=Object.keys(n),i.negativeRoiIDs=Object.keys(s),i.positiveRoi=i.positiveRoiIDs.length,i.negativeRoi=i.negativeRoiIDs.length}return t}}function fromMask(t,e={}){const{allowCorners:r=!1}=e,i=65535;let n=new Int16Array(t.size),s=0,a=0,o=new Uint16Array(65536),h=new Uint16Array(65536);for(let e=0;e<t.width;e++)for(let r=0;r<t.height;r++)0===n[r*t.width+e]&&l(e,r);function l(e,l){let c=0,u=0,f=t.getBitXY(e,l),d=f?++s:--a;if(s>32767||a<-32768)throw new Error("Too many regions of interest");for(o[0]=e,h[0]=l;c<=u;){let e=o[c&i],s=h[c&i];if(n[s*t.width+e]=d,e>0&&0===n[s*t.width+e-1]&&t.getBitXY(e-1,s)===f&&(u++,o[u&i]=e-1,h[u&i]=s,n[s*t.width+e-1]=-32768),s>0&&0===n[(s-1)*t.width+e]&&t.getBitXY(e,s-1)===f&&(u++,o[u&i]=e,h[u&i]=s-1,n[(s-1)*t.width+e]=-32768),e<t.width-1&&0===n[s*t.width+e+1]&&t.getBitXY(e+1,s)===f&&(u++,o[u&i]=e+1,h[u&i]=s,n[s*t.width+e+1]=-32768),s<t.height-1&&0===n[(s+1)*t.width+e]&&t.getBitXY(e,s+1)===f&&(u++,o[u&i]=e,h[u&i]=s+1,n[(s+1)*t.width+e]=-32768),r&&(e>0&&s>0&&0===n[(s-1)*t.width+e-1]&&t.getBitXY(e-1,s-1)===f&&(u++,o[u&i]=e-1,h[u&i]=s-1,n[(s-1)*t.width+e-1]=-32768),e<t.width-1&&s>0&&0===n[(s-1)*t.width+e+1]&&t.getBitXY(e+1,s-1)===f&&(u++,o[u&i]=e+1,h[u&i]=s-1,n[(s-1)*t.width+e+1]=-32768),e>0&&s<t.height-1&&0===n[(s+1)*t.width+e-1]&&t.getBitXY(e-1,s+1)===f&&(u++,o[u&i]=e-1,h[u&i]=s+1,n[(s+1)*t.width+e-1]=-32768),e<t.width-1&&s<t.height-1&&0===n[(s+1)*t.width+e+1]&&t.getBitXY(e+1,s+1)===f&&(u++,o[u&i]=e+1,h[u&i]=s+1,n[(s+1)*t.width+e+1]=-32768)),c++,u-c>i)throw new Error("analyseMask can not finish, the array to manage internal data is not big enough.You could improve mask by changing MAX_ARRAY")}}return new RoiMap(t,n)}class DisjointSet{constructor(){this.nodes=new Map}add(t){var e=this.nodes.get(t);return e||(e=new DisjointSetNode(t),this.nodes.set(t,e)),e}union(t,e){const r=this.find(t),i=this.find(e);r!==i&&(r.rank<i.rank?r.parent=i:r.rank>i.rank?i.parent=r:(i.parent=r,r.rank++))}find(t){for(var e=t;null!==e.parent;)e=e.parent;for(var r=t;null!==r.parent;){var i=r;r=r.parent,i.parent=e}return e}connected(t,e){return this.find(t)===this.find(e)}}var DisjointSet_1=DisjointSet;function DisjointSetNode(t){this.value=t,this.parent=null,this.rank=0}const direction4X=[-1,0],direction4Y=[0,-1],neighbours4=[null,null],direction8X=[-1,-1,0,1],direction8Y=[0,-1,-1,-1],neighbours8=[null,null,null,null];function fromMaskConnectedComponentLabelingAlgorithm(t,e={}){const{allowCorners:r=!1}=e;let i,n,s,a=4;if(r&&(a=8),8===a)i=direction8X,n=direction8Y,s=neighbours8;else{if(4!==a)throw new RangeError(`unsupported neighbours count: ${a}`);i=direction4X,n=direction4Y,s=neighbours4}const o=t.size,h=t.width,l=t.height,c=new Array(o),u=new Uint32Array(o),f=new DisjointSet_1;let d=1;for(let e=0;e<l;e++)for(let r=0;r<h;r++){const a=r+e*h;if(t.getBit(a)){let t=null;for(let a=0;a<s.length;a++){const o=r+i[a],u=e+n[a];if(o>=0&&u>=0&&o<h&&u<l){let e=c[o+u*h];e?(s[a]=e,(!t||s[a].value<t.value)&&(t=s[a])):s[a]=null}}if(t){c[a]=t;for(let e=0;e<s.length;e++)s[e]&&s[e]!==t&&f.union(t,s[e])}else c[a]=f.add(d++)}}for(let e=0;e<l;e++)for(let r=0;r<h;r++){const i=r+e*h;t.getBit(i)&&(u[i]=f.find(c[i]).value)}return new RoiMap(t,u)}function fromMaxima(t={}){let{allowCorner:e=!0,onlyTop:r=!1,invert:i=!1}=t,n=this;n.checkProcessable("fromMaxima",{components:[1]});let s=0,a=0,o=new Int16Array(n.size),h=new Int8Array(n.size),l=new Float32Array(n.size),c=1048575,u=new Uint16Array(1048576),f=new Uint16Array(1048576),d=0,m=0,g=new Uint16Array(1048576),p=new Uint16Array(1048576),w=0,_=0;for(!function({maxima:t=!0}){for(let r=1;r<n.height-1;r++)for(let i=1;i<n.width-1;i++){let l=i+r*n.width;if(0===h[l]){let h=t?n.data[l]:-n.data[i+r*n.width];if(n.data[r*n.width+i-1]>h)continue;if(n.data[r*n.width+i+1]>h)continue;if(n.data[(r-1)*n.width+i]>h)continue;if(n.data[(r+1)*n.width+i]>h)continue;if(e){if(n.data[(r-1)*n.width+i-1]>h)continue;if(n.data[(r-1)*n.width+i+1]>h)continue;if(n.data[(r+1)*n.width+i-1]>h)continue;if(n.data[(r+1)*n.width+i+1]>h)continue}o[l]=t?++s:--a,b(i,r)||(t?--s:++a)}}}(n);d<m;){y(u[d&c],f[d&c],2),d++}return new RoiMap(n,o);function b(t,e){let r=m;w=0,_=1,g[0]=t,p[0]=e;let i=!0;for(;w<_;){i&=y(g[w&c],p[w&c],1),w++}if(!i){for(let t=0;t<_;t++){let e=g[t&c],r=p[t&c]*n.width+e;o[r]=0}m=r}return i}function y(t,e,i){let s=o[e*n.width+t],a=n.data[e*n.width+t];for(let d=e-1;d<=e+1;d++)for(let e=t-1;e<=t+1;e++){let t=d*n.width+e;if(0===h[t])switch(h[t]=1,l[t]=n.data[t]-a,i){case 1:if(0===l[t]){if(0===e||0===d||e===n.width-1||d===n.height-1)return!1;o[t]=s,g[_&c]=e,p[_&c]=d,_++}else{if(l[t]>0)return!1;r||(o[t]=s,u[m&c]=e,f[m&c]=d,m++)}break;case 2:l[t]<=0&&(o[t]=s,u[m&c]=e,f[m&c]=d,m++);break;default:throw new Error("unreachable")}}return!0}}function fromPoints(t,e={}){let r=new Shape(e),i=new Int16Array(this.size),n=0,s=r.getPoints();for(let e=0;e<t.length;e++){n++;let r=t[e][0],a=t[e][1];for(let t=0;t<s.length;t++){let e=s[t][0],o=s[t][1];r+e>=0&&a+o>=0&&r+e<this.width&&a+o<this.height&&(i[r+e+(a+o)*this.width]=n)}}return new RoiMap(this,i)}var priorityQueue=createCommonjsModule((function(t,e){t.exports=function t(e,r,i){function n(a,o){if(!r[a]){if(!e[a]){var h="function"==typeof commonjsRequire&&commonjsRequire;if(!o&&h)return h(a,!0);if(s)return s(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[a]={exports:{}};e[a][0].call(c.exports,(function(t){var r=e[a][1][t];return n(r||t)}),c,c.exports,t,e,r,i)}return r[a].exports}for(var s="function"==typeof commonjsRequire&&commonjsRequire,a=0;a<i.length;a++)n(i[a]);return n}({1:[function(t,e,r){var i,n,s,a,o,h=function(t,e){for(var r in e)l.call(e,r)&&(t[r]=e[r]);function i(){this.constructor=t}return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},l={}.hasOwnProperty;i=t("./PriorityQueue/AbstractPriorityQueue"),n=t("./PriorityQueue/ArrayStrategy"),a=t("./PriorityQueue/BinaryHeapStrategy"),s=t("./PriorityQueue/BHeapStrategy"),(o=function(t){function e(t){t||(t={}),t.strategy||(t.strategy=a),t.comparator||(t.comparator=function(t,e){return(t||0)-(e||0)}),e.__super__.constructor.call(this,t)}return h(e,t),e}(i)).ArrayStrategy=n,o.BinaryHeapStrategy=a,o.BHeapStrategy=s,e.exports=o},{"./PriorityQueue/AbstractPriorityQueue":2,"./PriorityQueue/ArrayStrategy":3,"./PriorityQueue/BHeapStrategy":4,"./PriorityQueue/BinaryHeapStrategy":5}],2:[function(t,e,r){e.exports=function(){function t(t){var e;if(null==(null!=t?t.strategy:void 0))throw"Must pass options.strategy, a strategy";if(null==(null!=t?t.comparator:void 0))throw"Must pass options.comparator, a comparator";this.priv=new t.strategy(t),this.length=(null!=t&&null!=(e=t.initialValues)?e.length:void 0)||0}return t.prototype.queue=function(t){this.length++,this.priv.queue(t)},t.prototype.dequeue=function(t){if(!this.length)throw"Empty queue";return this.length--,this.priv.dequeue()},t.prototype.peek=function(t){if(!this.length)throw"Empty queue";return this.priv.peek()},t.prototype.clear=function(){return this.length=0,this.priv.clear()},t}()},{}],3:[function(t,e,r){var i;i=function(t,e,r){var i,n,s;for(n=0,i=t.length;n<i;)r(t[s=n+i>>>1],e)>=0?n=s+1:i=s;return n},e.exports=function(){function t(t){var e;this.options=t,this.comparator=this.options.comparator,this.data=(null!=(e=this.options.initialValues)?e.slice(0):void 0)||[],this.data.sort(this.comparator).reverse()}return t.prototype.queue=function(t){var e;e=i(this.data,t,this.comparator),this.data.splice(e,0,t)},t.prototype.dequeue=function(){return this.data.pop()},t.prototype.peek=function(){return this.data[this.data.length-1]},t.prototype.clear=function(){this.data.length=0},t}()},{}],4:[function(t,e,r){e.exports=function(){function t(t){var e,r,i,n,s,a,o,h;for(this.comparator=(null!=t?t.comparator:void 0)||function(t,e){return t-e},this.pageSize=(null!=t?t.pageSize:void 0)||512,this.length=0,o=0;1<<o<this.pageSize;)o+=1;if(1<<o!==this.pageSize)throw"pageSize must be a power of two";for(this._shift=o,this._emptyMemoryPageTemplate=e=[],r=0,s=this.pageSize;0<=s?r<s:r>s;0<=s?++r:--r)e.push(null);if(this._memory=[],this._mask=this.pageSize-1,t.initialValues)for(i=0,n=(a=t.initialValues).length;i<n;i++)h=a[i],this.queue(h)}return t.prototype.queue=function(t){this.length+=1,this._write(this.length,t),this._bubbleUp(this.length,t)},t.prototype.dequeue=function(){var t,e;return t=this._read(1),e=this._read(this.length),this.length-=1,this.length>0&&(this._write(1,e),this._bubbleDown(1,e)),t},t.prototype.peek=function(){return this._read(1)},t.prototype.clear=function(){this.length=0,this._memory.length=0},t.prototype._write=function(t,e){var r;for(r=t>>this._shift;r>=this._memory.length;)this._memory.push(this._emptyMemoryPageTemplate.slice(0));return this._memory[r][t&this._mask]=e},t.prototype._read=function(t){return this._memory[t>>this._shift][t&this._mask]},t.prototype._bubbleUp=function(t,e){var r,i,n,s;for(r=this.comparator;t>1&&(i=t&this._mask,t<this.pageSize||i>3?n=t&~this._mask|i>>1:i<2?(n=t-this.pageSize>>this._shift,n+=n&~(this._mask>>1),n|=this.pageSize>>1):n=t-2,!(r(s=this._read(n),e)<0));)this._write(n,e),this._write(t,s),t=n},t.prototype._bubbleDown=function(t,e){var r,i,n,s,a;for(a=this.comparator;t<this.length;)if(t>this._mask&&!(t&this._mask-1)?r=i=t+2:t&this.pageSize>>1?(r=(t&~this._mask)>>1,i=1+(r=1+(r|=t&this._mask>>1)<<this._shift)):i=(r=t+(t&this._mask))+1,r!==i&&i<=this.length)if(n=this._read(r),s=this._read(i),a(n,e)<0&&a(n,s)<=0)this._write(r,e),this._write(t,n),t=r;else{if(!(a(s,e)<0))break;this._write(i,e),this._write(t,s),t=i}else{if(!(r<=this.length))break;if(!(a(n=this._read(r),e)<0))break;this._write(r,e),this._write(t,n),t=r}},t}()},{}],5:[function(t,e,r){e.exports=function(){function t(t){var e;this.comparator=(null!=t?t.comparator:void 0)||function(t,e){return t-e},this.length=0,this.data=(null!=(e=t.initialValues)?e.slice(0):void 0)||[],this._heapify()}return t.prototype._heapify=function(){var t,e,r;if(this.data.length>0)for(t=e=1,r=this.data.length;1<=r?e<r:e>r;t=1<=r?++e:--e)this._bubbleUp(t)},t.prototype.queue=function(t){this.data.push(t),this._bubbleUp(this.data.length-1)},t.prototype.dequeue=function(){var t,e;return e=this.data[0],t=this.data.pop(),this.data.length>0&&(this.data[0]=t,this._bubbleDown(0)),e},t.prototype.peek=function(){return this.data[0]},t.prototype.clear=function(){this.length=0,this.data.length=0},t.prototype._bubbleUp=function(t){for(var e,r;t>0&&(e=t-1>>>1,this.comparator(this.data[t],this.data[e])<0);)r=this.data[e],this.data[e]=this.data[t],this.data[t]=r,t=e},t.prototype._bubbleDown=function(t){var e,r,i,n,s;for(e=this.data.length-1;n=1+(r=1+(t<<1)),i=t,r<=e&&this.comparator(this.data[r],this.data[i])<0&&(i=r),n<=e&&this.comparator(this.data[n],this.data[i])<0&&(i=n),i!==t;)s=this.data[i],this.data[i]=this.data[t],this.data[t]=s,t=i},t}()},{}]},{},[1])(1)}));const dxs=[1,0,-1,0,1,1,-1,-1],dys=[0,1,0,-1,1,-1,1,-1];function fromWaterShed(t={}){let{points:e,mask:r,image:i,fillMaxValue:n=this.maxValue,invert:s=!1}=t,a=i||this;a.checkProcessable("fromWaterShed",{bitDepth:[8,16],components:1}),s=!s,e||(e=a.getLocalMaxima({invert:s,mask:r}));let o=s?0:1,h=new Int16Array(a.size),l=a.width,c=a.height,u=new priorityQueue({comparator:(t,e)=>t[2]-e[2],strategy:priorityQueue.BinaryHeapStrategy});for(let t=0;t<e.length;t++){let r=e[t][0]+e[t][1]*l;h[r]=t+1;let i=a.data[r];(s&&i<=n||!s&&i>=n)&&u.queue([e[t][0],e[t][1],i])}for(;u.length>0;){let t=u.dequeue(),e=t[0]+t[1]*l;for(let i=0;i<4;i++){let f=t[0]+dxs[i],d=t[1]+dys[i];if(f>=0&&d>=0&&f<l&&d<c){let c=f+d*l;if(!r||r.getBit(c)===o){let r=a.data[c];(s&&r<=n||!s&&r>=n)&&0===h[c]&&(h[c]=h[e],u.queue([t[0]+dxs[i],t[1]+dys[i],r]))}}}}return new RoiMap(a,h)}class RoiManager{constructor(t,e={}){this._image=t,this._options=e,this._options.label||(this._options.label="default"),this._layers={},this._painted=null}fromMaxima(t={}){let e=Object.assign({},this._options,t),r=fromMaxima.call(this._image,t);this._layers[e.label]=new RoiLayer(r,e)}fromPoints(t,e={}){let r=Object.assign({},this._options,e),i=fromPoints.call(this._image,t,e);return this._layers[r.label]=new RoiLayer(i,r),this}putMap(t,e={}){let r=new RoiMap(this._image,t),i=Object.assign({},this._options,e);return this._layers[i.label]=new RoiLayer(r,i),this}fromWaterShed(t={}){let e=Object.assign({},this._options,t),r=fromWaterShed.call(this._image,t);this._layers[e.label]=new RoiLayer(r,e)}fromMask(t,e={}){let r=Object.assign({},this._options,e),i=fromMask.call(this._image,t,e);return this._layers[r.label]=new RoiLayer(i,r),this}fromMaskConnectedComponentLabelingAlgorithm(t,e={}){let r=Object.assign({},this._options,e),i=fromMaskConnectedComponentLabelingAlgorithm.call(this._image,t,e);return this._layers[r.label]=new RoiLayer(i,r),this}getMap(t={}){let e=Object.assign({},this._options,t);return this._assertLayerWithLabel(e.label),this._layers[e.label].roiMap}rowsInfo(t={}){return this.getMap(t).rowsInfo()}colsInfo(t={}){return this.getMap(t).rowsInfo()}getRoiIds(t={}){let e=this.getRois(t);if(e){let t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=e[r].id;return t}throw new Error("ROIs not found")}getRois(t={}){let{label:e=this._options.label,positive:r=!0,negative:i=!0,minSurface:n=0,maxSurface:s=Number.POSITIVE_INFINITY,minWidth:a=0,maxWidth:o=Number.POSITIVE_INFINITY,minHeight:h=0,maxHeight:l=Number.POSITIVE_INFINITY,minRatio:c=0,maxRatio:u=Number.POSITIVE_INFINITY}=t;if(!this._layers[e])throw new Error(`this Roi layer (${e}) does not exist`);const f=this._layers[e].roi,d=[];for(const t of f)(t.id<0&&i||t.id>0&&r)&&t.surface>=n&&t.surface<=s&&t.width>=a&&t.width<=o&&t.height>=h&&t.height<=l&&t.ratio>=c&&t.ratio<=u&&d.push(t);return d}getRoi(t,e={}){const{label:r=this._options.label}=e;if(!this._layers[r])throw new Error(`this Roi layer (${r}) does not exist`);const i=this._layers[r].roi.find((e=>e.id===t));if(!i)throw new Error(`found no Roi with id ${t}`);return i}getMasks(t={}){let e=this.getRois(t),r=new Array(e.length);for(let i=0;i<e.length;i++)r[i]=e[i].getMask(t);return r}getAnalysisMasks(t={}){const{analysisProperty:e}=t;let r=`${e}Mask`,i=this.getRois(t);return 0!==i.length&&i[0][r]?i.map((t=>t[r])):[]}getData(t={}){let e=Object.assign({},this._options,t);return this._assertLayerWithLabel(e.label),this._layers[e.label].roiMap.data}paint(t={}){let{labelProperty:e,analysisProperty:r}=t;this._painted||(this._painted=this._image.rgba8());let i=this.getMasks(t);if(e){const r=this.getRois(t);t.labels=r.map((t=>deepValue(t,e)));const i=Math.max(...t.labels);let n=!1,s=!1;if(e.includes("surface")?n=!0:/(?:perimeter|min|max|external|width|height|length)/.test(e)&&(s=!0),isFinite(i)){let e="";if("pixel"!==t.unit&&t.pixelSize&&(s||n)){e=n?`${t.unit}^2`:t.unit;let r=n?"m^2":"m",i=n?t.pixelSize**2:t.pixelSize;const s=quantities.swiftConverter(r,e);t.labels=t.labels.map((t=>s(i*t)))}t.labels=i>50?t.labels.map((t=>Math.round(t)+e)):i>10?t.labels.map((t=>t.toFixed(1)+e)):t.labels.map((t=>t.toFixed(2)+e))}t.labelsPosition=r.map((t=>[t.meanX,t.meanY]))}if(this._painted.paintMasks(i,t),r){let e=this.getAnalysisMasks(t);this._painted.paintMasks(e,{color:t.analysisColor,alpha:t.analysisAlpha})}return this._painted}getMask(t={}){let e=new Image(this._image.width,this._image.height,{kind:"BINARY"}),r=this.getMasks(t);for(let t=0;t<r.length;t++){let i=r[t];for(let t=0;t<i.width;t++)for(let r=0;r<i.height;r++)i.getBitXY(t,r)&&e.setBitXY(t+i.position[0],r+i.position[1])}return e}resetPainted(t={}){const{image:e}=t;this._painted=e?this.image.rgba8():this._image.rgba8()}mergeRoi(t={}){const e=this.getMap(t);return e.mergeRoi(t),this.putMap(e.data,t),this}mergeRois(t,e={}){if(!Array.isArray(t)||t.some((t=>!Number.isInteger(t))))throw new Error("Roi ids must be an array of integers");if(t.length<2)throw new Error("Roi ids must have at least two elements");if(new Set(t).size!==t.length)throw new Error("Roi ids must be all different");t.forEach((t=>this.getRoi(t)));const r=this.getMap(e);return r.mergeRois(t),this.putMap(r.data,e),this}findCorrespondingRoi(t,e={}){let r=this.getRois(e),i=[];for(let e=0;e<r.length;e++){let n=r[e],s=correspondingRoisInformation(n.minX,n.minY,n.points,t,Math.sign(n.id));i.push(s)}return i}_assertLayerWithLabel(t){if(!this._layers[t])throw new Error(`no layer with label ${t}`)}}function correspondingRoisInformation(t,e,r,i,n){let s={id:[],surface:[],roiSurfaceCovered:[],same:0,opposite:0,total:0};for(let n=0;n<r.length;n++){let a=r[n],o=a[0]+t+(a[1]+e)*i.width,h=i.data[o];(h>0||h<0)&&(s.id.includes(h)?s.surface[s.id.indexOf(h)]+=1:(s.id.push(h),s.surface.push(1)))}for(let t=0;t<s.id.length;t++){Math.sign(s.id[t])===n?s.same+=s.surface[t]:s.opposite+=s.surface[t],s.roiSurfaceCovered[t]=s.surface[t]/r.length}return s.total=s.opposite+s.same,s}const objectToString=Object.prototype.toString;class Image{constructor(t,e,r,i){if(1===arguments.length?(i=t,({width:t,height:e,data:r}=i)):r&&!r.length&&(i=r,({data:r}=i)),void 0===t&&(t=1),void 0===e&&(e=1),void 0===i&&(i={}),"object"!=typeof i||null===i)throw new TypeError("options must be an object");if(!Number.isInteger(t)||t<=0)throw new RangeError("width must be a positive integer");if(!Number.isInteger(e)||e<=0)throw new RangeError("height must be a positive integer");const{kind:n=RGBA}=i;if("string"!=typeof n)throw new TypeError("kind must be a string");const s=getKind(n),a=Object.assign({},i);for(const t in s)void 0===a[t]&&(a[t]=s[t]);verifyKindDefinition(a);const{components:o,bitDepth:h,colorModel:l}=a,c=a.alpha+0,u=t*e,f=o+c,d=32===h?Number.MAX_VALUE:2**h-1;if(void 0===r)r=createPixelArray(u,o,c,f,h,d);else{const t=getTheoreticalPixelArraySize(u,f,h);if(r.length!==t)throw new RangeError(`incorrect data size: ${r.length}. Should be ${t}`)}this.width=t,this.height=e,this.data=r,this.size=u,this.components=o,this.alpha=c,this.bitDepth=h,this.maxValue=d,this.colorModel=l,this.channels=f,this.meta=i.meta||{},Object.defineProperty(this,"parent",{enumerable:!1,writable:!0,configurable:!0,value:i.parent||null}),this.position=i.position||[0,0],this.computed=null,this.sizes=[this.width,this.height],this.multiplierX=this.channels,this.multiplierY=this.channels*this.width,this.isClamped=this.bitDepth<32,this.borderSizes=[0,0]}get[Symbol.toStringTag](){return"IJSImage"}static isImage(t){return"[object IJSImage]"===objectToString.call(t)}static fromCanvas(t){const e=t.getContext("2d").getImageData(0,0,t.width,t.height);return new Image(e.width,e.height,e.data)}static createFrom(t,e){const r=getImageParameters(t);return Object.assign(r,{parent:t,position:[0,0]},e),new Image(r)}getRoiManager(t){return new RoiManager(this,t)}clone(){const t=this.data.slice();return new Image(this.width,this.height,t,this)}apply(t){for(let e=0;e<this.height;e++)for(let r=0;r<this.width;r++){let i=(e*this.width+r)*this.channels;t.call(this,i)}}}function laplacianOfGaussian(t,e,r){let i,n,s,a,o=new Array(e);r||(r=100),r*=-1;let h=(e-1)/2,l=2*t*t;for(i=0;i<e;i++)for(o[i]=new Array(e),a=(i-h)*(i-h),n=0;n<e;n++)s=(n-h)*(n-h),o[i][n]=Math.round(r*(1-(s+a)/l)*Math.exp(-(s+a)/l));return o}setValueMethods(Image),setBitMethods(Image),setExportMethods(Image),Image.prototype.checkProcessable=checkProcessable,Image.prototype.getRGBAData=getRGBAData,Image.load=load,Image.extendMethod=extendMethod,Image.extendProperty=extendProperty,extend$1(Image);var kernel=Object.freeze({__proto__:null,laplacianOfGaussian:laplacianOfGaussian,DISCRETE_LAPLACE_4:DISCRETE_LAPLACE_4,DISCRETE_LAPLACE_8:DISCRETE_LAPLACE_8,SOBEL_X:SOBEL_X,SOBEL_Y:SOBEL_Y,SCHARR_X:SCHARR_X,SCHARR_Y:SCHARR_Y,SECOND_DERIVATIVE:SECOND_DERIVATIVE,SECOND_DERIVATIVE_INV:SECOND_DERIVATIVE_INV}),worker$2=function(){function t(){this._listeners={}}self.window=self,t.prototype.on=function(t,e){if(this._listeners[t])throw new RangeError("there is already a listener for "+t);if("function"!=typeof e)throw new TypeError("callback argument must be a function");this._listeners[t]=e},t.prototype._send=function(t,e,r){void 0===r?r=[]:Array.isArray(r)||(r=[r]),self.postMessage({id:t,data:e},r)},t.prototype._trigger=function(t,e){if(!this._listeners[t])throw new Error("event "+t+" is not defined");this._listeners[t].apply(null,e)};var e=new t;self.onmessage=function(t){switch(t.data.action){case"exec":t.data.args.unshift((function(r,i){e._send(t.data.id,r,i)})),e._trigger(t.data.event,t.data.args);break;case"ping":e._send(t.data.id,"pong");break;default:throw new Error("unexpected action: "+t.data.action)}}},workerStr=worker$2.toString().split('"CODE";'),newWorkerURL=function(t,e){var r=new Blob(["(",workerStr[0],"importScripts.apply(self, "+JSON.stringify(e)+");\n","(",t,")();",workerStr[1],")();"],{type:"application/javascript"});return URL.createObjectURL(r)},workerTemplate={newWorkerURL:newWorkerURL},CORES=navigator.hardwareConcurrency||1;function WorkerManager(t,e){if("string"!=typeof t&&"function"!=typeof t)throw new TypeError("func argument must be a function");if(void 0===e&&(e={}),"object"!=typeof e||null===e)throw new TypeError("options argument must be an object");this._workerCode=t.toString(),void 0===e.maxWorkers||"auto"===e.maxWorkers?this._numWorkers=Math.min(CORES-1,1):e.maxWorkers>0?this._numWorkers=Math.min(e.maxWorkers,CORES):this._numWorkers=CORES,this._workers=new Map,this._timeout=e.timeout||0,this._terminateOnError=!!e.terminateOnError;var r=e.deps;"string"==typeof r&&(r=[r]),Array.isArray(r)||(r=void 0),this._id=0,this._terminated=!1,this._working=0,this._waiting=[],this._init(r)}WorkerManager.prototype._init=function(t){for(var e=workerTemplate.newWorkerURL(this._workerCode,t),r=0;r<this._numWorkers;r++){var i=new Worker(e);i.onmessage=this._onmessage.bind(this,i),i.onerror=this._onerror.bind(this,i),i.running=!1,i.id=r,this._workers.set(i,null)}URL.revokeObjectURL(e)},WorkerManager.prototype._onerror=function(t,e){if(!this._terminated){this._working--,t.running=!1;var r=this._workers.get(t);r&&r[1](e.message),this._workers.set(t,null),this._terminateOnError?this.terminate():this._exec()}},WorkerManager.prototype._onmessage=function(t,e){if(!this._terminated){this._working--,t.running=!1;var r=this._workers.get(t);r&&r[0](e.data.data),this._workers.set(t,null),this._exec()}},WorkerManager.prototype._exec=function(){for(var t of this._workers.keys()){if(this._working===this._numWorkers||0===this._waiting.length)return;if(!t.running)for(var e=0;e<this._waiting.length;e++){var r=this._waiting[e];if("number"!=typeof r[4]||r[4]===t.id){this._waiting.splice(e,1),t.postMessage({action:"exec",event:r[0],args:r[1]},r[2]),t.running=!0,t.time=Date.now(),this._workers.set(t,r[3]),this._working++;break}}}},WorkerManager.prototype.terminate=function(){if(!this._terminated){for(var t of this._workers)t[0].terminate(),t[1]&&t[1][1](new Error("Terminated"));this._workers.clear(),this._waiting=[],this._working=0,this._terminated=!0}},WorkerManager.prototype.postAll=function(t,e){if(this._terminated)throw new Error("Cannot post (terminated)");var r=[];for(var i of this._workers.keys())r.push(this.post(t,e,[],i.id));return Promise.all(r)},WorkerManager.prototype.post=function(t,e,r,i){void 0===e&&(e=[]),void 0===r&&(r=[]),Array.isArray(e)||(e=[e]),Array.isArray(r)||(r=[r]);var n=this;return new Promise((function(s,a){if(n._terminated)throw new Error("Cannot post (terminated)");n._waiting.push([t,e,r,[s,a],i]),n._exec()}))};var src=WorkerManager;const defaultOptions={regression:{kernelType:"polynomial",kernelOptions:{degree:2,constant:1}},threshold:.02,roi:{minSurface:100,positive:!1},sampling:20,include:[]};function run(t,e,r){e=Object.assign({},defaultOptions,e);const i=this.manager;return Array.isArray(t)?Promise.all(t.map((function(t){const n=runOnce(i,t,e);return"function"==typeof r&&n.then(r),n}))):runOnce(i,t,e)}function runOnce(t,e,r){return t.post("data",[e,r]).then((function(t){for(let e in t)t[e]=new Image(t[e]);return t}))}function work(){worker.on("data",(function(t,e,r){e=new IJS(e);const i={},n=[],s=e.grey(),a=s.sobelFilter();d("sobel",a);const o=a.level().mask({threshold:r.threshold});d("mask",o);const h=a.getRoiManager();h.fromMask(o);const l=h.getMask(r.roi);d("realMask",l);const c=s.getPixelsGrid({sampling:r.sampling,mask:l}),u=e.getBackground(c.xyS,c.zS,r.regression);d("background",u);const f=e.subtract(u);function d(t,e){r.include.includes(t)&&(i[t]=e,n.push(e.data.buffer))}i.result=f,n.push(f.data.buffer),t(i,n)}))}const background={run:run,work:work};function extend(t){t.extendMethod("background",background)}class Worker$1{constructor(){this._url=null,this._deps=[null]}checkUrl(){if(null===this._url)throw new Error("image worker must be initialized with an URL")}get url(){return this._url}set url(t){if("string"!=typeof t)throw new TypeError("worker URL must be a string");this._url=t,this._deps[0]=t}static extendMethod(t,e){let r,i,n={};function s(...t){return r||(this.checkUrl(),i=this.url,r=new src(e.work,{deps:i}),n.manager=r),e.run.call(n,...t)}s.reset=function(){r&&(r.terminate(),r=new src(e.work,{deps:i}),n.manager=r)},Worker$1.prototype[t]=s}}extend(Worker$1);var worker$1=new Worker$1;const Static={grey:names$1,threshold:names};exports.Image=Image,exports.Kernel=kernel,exports.Shape=Shape,exports.Stack=Stack,exports.Static=Static,exports.Worker=worker$1,exports.default=Image,Object.defineProperty(exports,"__esModule",{value:!0})}));
  //# sourceMappingURL=joechen-image-js.min.js.map
  