text: (function(e,t){'object'==typeof exports&&'undefined'!=typeof module?t(exports):'function'==typeof define&&define.amd?define(['exports'],t):t(e.IJS={})})(this,function(e){'use strict';function t(e){return e>>3}function a(e){return 7-(7&e)}function n(e){for(var t in br)e.prototype[t]=br[t]}function o(e,t){e=e||[],t=t||{},'string'==typeof t&&(t={type:t});try{return new Blob(e,t)}catch(i){if('TypeError'!==i.name)throw i;for(var a='undefined'==typeof BlobBuilder?'undefined'==typeof MSBlobBuilder?'undefined'==typeof MozBlobBuilder?WebKitBlobBuilder:MozBlobBuilder:MSBlobBuilder:BlobBuilder,n=new a,o=0;o<e.length;o+=1)n.append(e[o]);return n.getBlob(t.type)}}function s(e){var t=e.match(/data:([^;]+)/)[1],i=e.replace(/^[^,]+,/,''),a=l(atob(i));return o([a],{type:t})}function r(e,t,i){return'function'==typeof e.toBlob?new Promise(function(a){e.toBlob(a,t,i)}):Promise.resolve(s(e.toDataURL(t,i)))}function l(e){for(var t=e.length,a=new ArrayBuffer(t),n=new Uint8Array(a),o=-1;++o<t;)n[o]=e.charCodeAt(o);return a}function d(){throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs')}function h(e,t){return t={exports:{}},e(t,t.exports),t.exports}function g(e,t){const a=4*ur((t.bitDepth*t.width+31)/32),n=pr(t.bitDepth*t.width/8),o=t.bitDepth*t.width%8,s=0===o?0:8-o,r=a*t.height;var l,d;const h=new kr(t.data);let g=0,m=0,c=8;e.mark(),d=h.readUint8();for(var p=t.height-1;0<=p;p--){const t=0===p;e.reset(),e.skip(p*a);for(var u=0;u<n;u++){const i=u===n-1;m<=s&&i?(e.writeByte(d<<m),(0==s||s==m)&&!t&&(l=d,d=h.readByte())):0==m?(l=d,d=h.readUint8(),e.writeByte(l)):(l=d,d=h.readUint8(),e.writeByte(l<<m&vr[m]|d>>c)),i?(g+=o||8,e.skip(a-n),m=g%8,c=8-m):g+=8}}a>n&&(e.reset(),e.skip(r-1),e.writeUint8(0))}function m(e,t){8<t.bitDepth||e.writeUint32(0).writeUint32(16777215)}function p(e,t){e.writeChars('BM'),e.writeInt32(e._lastWrittenByte),e.writeUint16(0),e.writeUint16(0),e.writeUint32(t)}function u(e,t){e.writeUint32(124).writeInt32(t.width).writeInt32(t.height).writeUint16(1).writeUint16(t.bitDepth).writeUint32(yr.BITMAPV5HEADER.Compression.BI_RGB).writeUint32(t.width*t.height*t.bitDepth).writeInt32(0).writeInt32(0).writeUint32(cr(2,t.bitDepth)).writeUint32(cr(2,t.bitDepth)).writeUint32(4278190080).writeUint32(16711680).writeUint32(65280).writeUint32(255).writeUint32(yr.BITMAPV5HEADER.LogicalColorSpace.LCS_sRGB).skip(36).skip(12).writeUint32(yr.BITMAPV5HEADER.GamutMappingIntent.LCS_GM_IMAGES).skip(12)}function f(e){for(var t=e.length;0<=--t;)e[t]=0}function b(e,t,i,a,n){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=a,this.max_length=n,this.has_stree=e&&e.length}function _(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function w(e){return 256>e?Fr[e]:Fr[256+(e>>>7)]}function x(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=255&t>>>8}function k(e,t,i){e.bi_valid>16-i?(e.bi_buf|=65535&t<<e.bi_valid,x(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=i-16):(e.bi_buf|=65535&t<<e.bi_valid,e.bi_valid+=i)}function y(e,t,i){k(e,i[2*t],i[2*t+1])}function v(e,t){var i=0;do i|=1&e,e>>>=1,i<<=1;while(0<--t);return i>>>1}function D(e){16===e.bi_valid?(x(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}function S(e,t){var i=t.dyn_tree,a=t.max_code,o=t.stat_desc.static_tree,s=t.stat_desc.has_stree,r=t.stat_desc.extra_bits,l=t.stat_desc.extra_base,d=t.stat_desc.max_length,g=0,c,p,u,b,_,w;for(b=0;b<=15;b++)e.bl_count[b]=0;for(i[2*e.heap[e.heap_max]+1]=0,c=e.heap_max+1;573>c;c++)(p=e.heap[c],b=i[2*i[2*p+1]+1]+1,b>d&&(b=d,g++),i[2*p+1]=b,!(p>a))&&(e.bl_count[b]++,_=0,p>=l&&(_=r[p-l]),w=i[2*p],e.opt_len+=w*(b+_),s&&(e.static_len+=w*(o[2*p+1]+_)));if(0!=g){do{for(b=d-1;0===e.bl_count[b];)b--;e.bl_count[b]--,e.bl_count[b+1]+=2,e.bl_count[d]--,g-=2}while(0<g);for(b=d;0!==b;b--)for(p=e.bl_count[b];0!==p;)(u=e.heap[--c],!(u>a))&&(i[2*u+1]!==b&&(e.opt_len+=(b-i[2*u+1])*i[2*u],i[2*u+1]=b),p--)}}function M(e,t,i){var a=Array(16),o=0,s,r;for(s=1;s<=15;s++)a[s]=o=o+i[s-1]<<1;for(r=0;r<=t;r++){var l=e[2*r+1];0!==l&&(e[2*r]=v(a[l]++,l))}}function j(){var e=Array(16),t,i,a,o,s;for(a=0,o=0;o<28;o++)for(Vr[o]=a,t=0;t<1<<Ar[o];t++)Xr[a++]=o;for(Xr[a-1]=o,s=0,o=0;16>o;o++)for(Ur[o]=s,t=0;t<1<<zr[o];t++)Fr[s++]=o;for(s>>=7;o<30;o++)for(Ur[o]=s<<7,t=0;t<1<<zr[o]-7;t++)Fr[256+s++]=o;for(i=0;i<=15;i++)e[i]=0;for(t=0;143>=t;)Er[2*t+1]=8,t++,e[8]++;for(;255>=t;)Er[2*t+1]=9,t++,e[9]++;for(;279>=t;)Er[2*t+1]=7,t++,e[7]++;for(;287>=t;)Er[2*t+1]=8,t++,e[8]++;for(M(Er,287,e),t=0;t<30;t++)Tr[2*t+1]=5,Tr[2*t]=v(t,5);Zr=new b(Er,Ar,257,286,15),Kr=new b(Tr,zr,0,30,15),Jr=new b([],Yr,0,19,7)}function P(e){var t;for(t=0;t<286;t++)e.dyn_ltree[2*t]=0;for(t=0;t<30;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function I(e){8<e.bi_valid?x(e,e.bi_buf):0<e.bi_valid&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function B(e,t,i,a){I(e),a&&(x(e,i),x(e,~i)),Mr.arraySet(e.pending_buf,e.window,t,i,e.pending),e.pending+=i}function C(e,t,i,a){var n=2*t,o=2*i;return e[n]<e[o]||e[n]===e[o]&&a[t]<=a[i]}function R(e,t,i){for(var a=e.heap[i],n=i<<1;n<=e.heap_len&&(n<e.heap_len&&C(t,e.heap[n+1],e.heap[n],e.depth)&&n++,!C(t,a,e.heap[n],e.depth));)e.heap[i]=e.heap[n],i=n,n<<=1;e.heap[i]=a}function A(e,t,i){var a=0,n,o,s,r;if(0!==e.last_lit)do n=e.pending_buf[e.d_buf+2*a]<<8|e.pending_buf[e.d_buf+2*a+1],o=e.pending_buf[e.l_buf+a],a++,0===n?y(e,o,t):(s=Xr[o],y(e,s+256+1,t),r=Ar[s],0!==r&&(o-=Vr[s],k(e,o,r)),n--,s=w(n),y(e,s,i),r=zr[s],0!==r&&(n-=Ur[s],k(e,n,r)));while(a<e.last_lit);y(e,256,t)}function z(e,t){var i=t.dyn_tree,a=t.stat_desc.static_tree,o=t.stat_desc.has_stree,s=t.stat_desc.elems,r=-1,l,d,h;for(e.heap_len=0,e.heap_max=573,l=0;l<s;l++)0===i[2*l]?i[2*l+1]=0:(e.heap[++e.heap_len]=r=l,e.depth[l]=0);for(;2>e.heap_len;)h=e.heap[++e.heap_len]=2>r?++r:0,i[2*h]=1,e.depth[h]=0,e.opt_len--,o&&(e.static_len-=a[2*h+1]);for(t.max_code=r,l=e.heap_len>>1;1<=l;l--)R(e,i,l);h=s;do l=e.heap[1],e.heap[1]=e.heap[e.heap_len--],R(e,i,1),d=e.heap[1],e.heap[--e.heap_max]=l,e.heap[--e.heap_max]=d,i[2*h]=i[2*l]+i[2*d],e.depth[h]=(e.depth[l]>=e.depth[d]?e.depth[l]:e.depth[d])+1,i[2*l+1]=i[2*d+1]=h,e.heap[1]=h++,R(e,i,1);while(2<=e.heap_len);e.heap[--e.heap_max]=e.heap[1],S(e,t),M(i,r,e.bl_count)}function Y(e,t,i){var a=-1,o=t[1],s=0,r=7,l=4,d,h;for(0===o&&(r=138,l=3),t[2*(i+1)+1]=65535,d=0;d<=i;d++){if(h=o,o=t[2*(d+1)+1],++s<r&&h===o)continue;else s<l?e.bl_tree[2*h]+=s:0===h?10>=s?e.bl_tree[34]++:e.bl_tree[36]++:(h!==a&&e.bl_tree[2*h]++,e.bl_tree[32]++);s=0,a=h,0===o?(r=138,l=3):h===o?(r=6,l=3):(r=7,l=4)}}function L(e,t,i){var a=-1,o=t[1],s=0,r=7,l=4,d,h;for(0===o&&(r=138,l=3),d=0;d<=i;d++){if(h=o,o=t[2*(d+1)+1],++s<r&&h===o)continue;else if(s<l)do y(e,h,e.bl_tree);while(0!=--s);else 0===h?10>=s?(y(e,17,e.bl_tree),k(e,s-3,3)):(y(e,18,e.bl_tree),k(e,s-11,7)):(h!==a&&(y(e,h,e.bl_tree),s--),y(e,16,e.bl_tree),k(e,s-3,2));s=0,a=h,0===o?(r=138,l=3):h===o?(r=6,l=3):(r=7,l=4)}}function E(e){var t;for(Y(e,e.dyn_ltree,e.l_desc.max_code),Y(e,e.dyn_dtree,e.d_desc.max_code),z(e,e.bl_desc),t=18;3<=t&&0===e.bl_tree[2*Lr[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t}function T(e,t,i,a){var n;for(k(e,t-257,5),k(e,i-1,5),k(e,a-4,4),n=0;n<a;n++)k(e,e.bl_tree[2*Lr[n]+1],3);L(e,e.dyn_ltree,t-1),L(e,e.dyn_dtree,i-1)}function F(e){var t=4093624447,i;for(i=0;31>=i;i++,t>>>=1)if(1&t&&0!==e.dyn_ltree[2*i])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(i=32;i<256;i++)if(0!==e.dyn_ltree[2*i])return 1;return 0}function X(e){Gr||(j(),Gr=!0),e.l_desc=new _(e.dyn_ltree,Zr),e.d_desc=new _(e.dyn_dtree,Kr),e.bl_desc=new _(e.bl_tree,Jr),e.bi_buf=0,e.bi_valid=0,P(e)}function V(e,t,i,a){k(e,0+(a?1:0),3),B(e,t,i,!0)}function U(){for(var e=[],t=0,i;256>t;t++){i=t;for(var a=0;8>a;a++)i=1&i?3988292384^i>>>1:i>>>1;e[t]=i}return e}function G(e,t,a,n){e^=-1;for(var o=n;o<n+a;o++)e=e>>>8^Hr[255&(e^t[o])];return-1^e}function O(e,t){return e.msg=Wr[t],t}function N(e){return(e<<1)-(4<e?9:0)}function H(e){for(var t=e.length;0<=--t;)e[t]=0}function W(e){var t=e.state,i=t.pending;i>e.avail_out&&(i=e.avail_out);0===i||(Mr.arraySet(e.output,t.pending_buf,t.pending_out,i,e.next_out),e.next_out+=i,t.pending_out+=i,e.total_out+=i,e.avail_out-=i,t.pending-=i,0===t.pending&&(t.pending_out=0))}function Z(e,t){Or._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,W(e.strm)}function K(e,t){e.pending_buf[e.pending++]=t}function J(e,t){e.pending_buf[e.pending++]=255&t>>>8,e.pending_buf[e.pending++]=255&t}function Q(e,t,i,a){var n=e.avail_in;return(n>a&&(n=a),0===n)?0:(e.avail_in-=n,Mr.arraySet(t,e.input,e.next_in,n,i),1===e.state.wrap?e.adler=Nr(e.adler,t,n,i):2===e.state.wrap&&(e.adler=qr(e.adler,t,n,i)),e.next_in+=n,e.total_in+=n,n)}function $(e,t){var i=e.max_chain_length,a=e.strstart,n=e.prev_length,o=e.nice_match,s=e.strstart>e.w_size-262?e.strstart-(e.w_size-262):0,r=e.window,l=e.w_mask,d=e.prev,h=e.strstart+258,g=r[a+n-1],m=r[a+n],c,p;e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do{if(c=t,r[c+n]!==m||r[c+n-1]!==g||r[c]!==r[a]||r[++c]!==r[a+1])continue;a+=2,c++;do;while(r[++a]===r[++c]&&r[++a]===r[++c]&&r[++a]===r[++c]&&r[++a]===r[++c]&&r[++a]===r[++c]&&r[++a]===r[++c]&&r[++a]===r[++c]&&r[++a]===r[++c]&&a<h);if(p=258-(h-a),a=h-258,p>n){if(e.match_start=t,n=p,p>=o)break;g=r[a+n-1],m=r[a+n]}}while((t=d[t&l])>s&&0!=--i);return n<=e.lookahead?n:e.lookahead}function ee(e){var t=e.w_size,i,a,o,s,r;do{if(s=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-262)){Mr.arraySet(e.window,e.window,t,t,0),e.match_start-=t,e.strstart-=t,e.block_start-=t,a=e.hash_size,i=a;do o=e.head[--i],e.head[i]=o>=t?o-t:0;while(--a);a=t,i=a;do o=e.prev[--i],e.prev[i]=o>=t?o-t:0;while(--a);s+=t}if(0===e.strm.avail_in)break;if(a=Q(e.strm,e.window,e.strstart+e.lookahead,s),e.lookahead+=a,3<=e.lookahead+e.insert)for(r=e.strstart-e.insert,e.ins_h=e.window[r],e.ins_h=(e.ins_h<<e.hash_shift^e.window[r+1])&e.hash_mask;e.insert&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[r+3-1])&e.hash_mask,e.prev[r&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=r,r++,e.insert--,!(3>e.lookahead+e.insert)););}while(262>e.lookahead&&0!==e.strm.avail_in)}function te(e,t){for(var i,a;;){if(262>e.lookahead){if(ee(e),262>e.lookahead&&0===t)return 1;if(0===e.lookahead)break}if(i=0,3<=e.lookahead&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+3-1])&e.hash_mask,i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==i&&e.strstart-i<=e.w_size-262&&(e.match_length=$(e,i)),!(3<=e.match_length))a=Or._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;else if(a=Or._tr_tally(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&3<=e.lookahead){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+3-1])&e.hash_mask,i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(0!=--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+1])&e.hash_mask;if(a&&(Z(e,!1),0===e.strm.avail_out))return 1}return e.insert=2>e.strstart?e.strstart:2,4===t?(Z(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Z(e,!1),0===e.strm.avail_out)?1:2}function ie(e,t){for(var i,a,n;;){if(262>e.lookahead){if(ee(e),262>e.lookahead&&0===t)return 1;if(0===e.lookahead)break}if(i=0,3<=e.lookahead&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+3-1])&e.hash_mask,i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==i&&e.prev_length<e.max_lazy_match&&e.strstart-i<=e.w_size-262&&(e.match_length=$(e,i),5>=e.match_length&&(1===e.strategy||3===e.match_length&&4096<e.strstart-e.match_start)&&(e.match_length=2)),3<=e.prev_length&&e.match_length<=e.prev_length){n=e.strstart+e.lookahead-3,a=Or._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=n&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+3-1])&e.hash_mask,i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(0!=--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,a&&(Z(e,!1),0===e.strm.avail_out))return 1}else if(!e.match_available)e.match_available=1,e.strstart++,e.lookahead--;else if(a=Or._tr_tally(e,0,e.window[e.strstart-1]),a&&Z(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}return e.match_available&&(a=Or._tr_tally(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=2>e.strstart?e.strstart:2,4===t?(Z(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Z(e,!1),0===e.strm.avail_out)?1:2}function ae(e,t){for(var i=e.window,a,n,o,s;;){if(258>=e.lookahead){if(ee(e),258>=e.lookahead&&0===t)return 1;if(0===e.lookahead)break}if(e.match_length=0,3<=e.lookahead&&0<e.strstart&&(o=e.strstart-1,n=i[o],n===i[++o]&&n===i[++o]&&n===i[++o])){s=e.strstart+258;do;while(n===i[++o]&&n===i[++o]&&n===i[++o]&&n===i[++o]&&n===i[++o]&&n===i[++o]&&n===i[++o]&&n===i[++o]&&o<s);e.match_length=258-(s-o),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(3<=e.match_length?(a=Or._tr_tally(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(a=Or._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),a&&(Z(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,4===t?(Z(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Z(e,!1),0===e.strm.avail_out)?1:2}function ne(e,t){for(var i;;){if(0===e.lookahead&&(ee(e),0===e.lookahead)){if(0===t)return 1;break}if(e.match_length=0,i=Or._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(Z(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,4===t?(Z(e,!0),0===e.strm.avail_out?3:4):e.last_lit&&(Z(e,!1),0===e.strm.avail_out)?1:2}function oe(e,t,i,a,n){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=a,this.func=n}function se(e){e.window_size=2*e.w_size,H(e.head),e.max_lazy_match=Qr[e.level].max_lazy,e.good_match=Qr[e.level].good_length,e.nice_match=Qr[e.level].nice_length,e.max_chain_length=Qr[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0}function re(){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=8,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 Mr.Buf16(1146),this.dyn_dtree=new Mr.Buf16(122),this.bl_tree=new Mr.Buf16(78),H(this.dyn_ltree),H(this.dyn_dtree),H(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Mr.Buf16(16),this.heap=new Mr.Buf16(573),H(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Mr.Buf16(573),H(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function le(e){var t;return e&&e.state?(e.total_in=e.total_out=0,e.data_type=2,t=e.state,t.pending=0,t.pending_out=0,0>t.wrap&&(t.wrap=-t.wrap),t.status=t.wrap?42:113,e.adler=2===t.wrap?0:1,t.last_flush=0,Or._tr_init(t),0):O(e,-2)}function de(e){var t=le(e);return 0===t&&se(e.state),t}function he(e,t,i,a,n,o){if(!e)return -2;var r=1;if(-1===t&&(t=6),0>a?(r=0,a=-a):15<a&&(r=2,a-=16),1>n||9<n||8!==i||8>a||15<a||0>t||9<t||0>o||4<o)return O(e,-2);8===a&&(a=9);var l=new re;return e.state=l,l.strm=e,l.wrap=r,l.gzhead=null,l.w_bits=a,l.w_size=1<<l.w_bits,l.w_mask=l.w_size-1,l.hash_bits=n+7,l.hash_size=1<<l.hash_bits,l.hash_mask=l.hash_size-1,l.hash_shift=~~((l.hash_bits+3-1)/3),l.window=new Mr.Buf8(2*l.w_size),l.head=new Mr.Buf16(l.hash_size),l.prev=new Mr.Buf16(l.w_size),l.lit_bufsize=1<<n+6,l.pending_buf_size=4*l.lit_bufsize,l.pending_buf=new Mr.Buf8(l.pending_buf_size),l.d_buf=1*l.lit_bufsize,l.l_buf=3*l.lit_bufsize,l.level=t,l.strategy=o,l.method=i,de(e)}function ge(e,t){var i,a,n,o;if(!e||!e.state||5<t||0>t)return e?O(e,-2):-2;if(a=e.state,!e.output||!e.input&&0!==e.avail_in||666===a.status&&4!==t)return O(e,0===e.avail_out?-5:-2);if(a.strm=e,i=a.last_flush,a.last_flush=t,42===a.status)if(2===a.wrap)e.adler=0,K(a,31),K(a,139),K(a,8),a.gzhead?(K(a,(a.gzhead.text?1:0)+(a.gzhead.hcrc?2:0)+(a.gzhead.extra?4:0)+(a.gzhead.name?8:0)+(a.gzhead.comment?16:0)),K(a,255&a.gzhead.time),K(a,255&a.gzhead.time>>8),K(a,255&a.gzhead.time>>16),K(a,255&a.gzhead.time>>24),K(a,9===a.level?2:2<=a.strategy||2>a.level?4:0),K(a,255&a.gzhead.os),a.gzhead.extra&&a.gzhead.extra.length&&(K(a,255&a.gzhead.extra.length),K(a,255&a.gzhead.extra.length>>8)),a.gzhead.hcrc&&(e.adler=qr(e.adler,a.pending_buf,a.pending,0)),a.gzindex=0,a.status=69):(K(a,0),K(a,0),K(a,0),K(a,0),K(a,0),K(a,9===a.level?2:2<=a.strategy||2>a.level?4:0),K(a,3),a.status=113);else{var r=8+(a.w_bits-8<<4)<<8,l=-1;l=2<=a.strategy||2>a.level?0:6>a.level?1:6===a.level?2:3,r|=l<<6,0!==a.strstart&&(r|=32),r+=31-r%31,a.status=113,J(a,r),0!==a.strstart&&(J(a,e.adler>>>16),J(a,65535&e.adler)),e.adler=1}if(69===a.status)if(a.gzhead.extra){for(n=a.pending;a.gzindex<(65535&a.gzhead.extra.length)&&!(a.pending===a.pending_buf_size&&(a.gzhead.hcrc&&a.pending>n&&(e.adler=qr(e.adler,a.pending_buf,a.pending-n,n)),W(e),n=a.pending,a.pending===a.pending_buf_size));)K(a,255&a.gzhead.extra[a.gzindex]),a.gzindex++;a.gzhead.hcrc&&a.pending>n&&(e.adler=qr(e.adler,a.pending_buf,a.pending-n,n)),a.gzindex===a.gzhead.extra.length&&(a.gzindex=0,a.status=73)}else a.status=73;if(73===a.status)if(a.gzhead.name){n=a.pending;do{if(a.pending===a.pending_buf_size&&(a.gzhead.hcrc&&a.pending>n&&(e.adler=qr(e.adler,a.pending_buf,a.pending-n,n)),W(e),n=a.pending,a.pending===a.pending_buf_size)){o=1;break}o=a.gzindex<a.gzhead.name.length?255&a.gzhead.name.charCodeAt(a.gzindex++):0,K(a,o)}while(0!==o);a.gzhead.hcrc&&a.pending>n&&(e.adler=qr(e.adler,a.pending_buf,a.pending-n,n)),0===o&&(a.gzindex=0,a.status=91)}else a.status=91;if(91===a.status)if(a.gzhead.comment){n=a.pending;do{if(a.pending===a.pending_buf_size&&(a.gzhead.hcrc&&a.pending>n&&(e.adler=qr(e.adler,a.pending_buf,a.pending-n,n)),W(e),n=a.pending,a.pending===a.pending_buf_size)){o=1;break}o=a.gzindex<a.gzhead.comment.length?255&a.gzhead.comment.charCodeAt(a.gzindex++):0,K(a,o)}while(0!==o);a.gzhead.hcrc&&a.pending>n&&(e.adler=qr(e.adler,a.pending_buf,a.pending-n,n)),0===o&&(a.status=103)}else a.status=103;if(103===a.status&&(a.gzhead.hcrc?(a.pending+2>a.pending_buf_size&&W(e),a.pending+2<=a.pending_buf_size&&(K(a,255&e.adler),K(a,255&e.adler>>8),e.adler=0,a.status=113)):a.status=113),0!==a.pending){if(W(e),0===e.avail_out)return a.last_flush=-1,0;}else if(0===e.avail_in&&N(t)<=N(i)&&4!==t)return O(e,-5);if(666===a.status&&0!==e.avail_in)return O(e,-5);if(0!==e.avail_in||0!==a.lookahead||0!==t&&666!==a.status){var d=2===a.strategy?ne(a,t):3===a.strategy?ae(a,t):Qr[a.level].func(a,t);if((3===d||4===d)&&(a.status=666),1===d||3===d)return 0===e.avail_out&&(a.last_flush=-1),0;if(2===d&&(1===t?Or._tr_align(a):5!==t&&(Or._tr_stored_block(a,0,0,!1),3===t&&(H(a.head),0===a.lookahead&&(a.strstart=0,a.block_start=0,a.insert=0))),W(e),0===e.avail_out))return a.last_flush=-1,0}return 4===t?0>=a.wrap?1:(2===a.wrap?(K(a,255&e.adler),K(a,255&e.adler>>8),K(a,255&e.adler>>16),K(a,255&e.adler>>24),K(a,255&e.total_in),K(a,255&e.total_in>>8),K(a,255&e.total_in>>16),K(a,255&e.total_in>>24)):(J(a,e.adler>>>16),J(a,65535&e.adler)),W(e),0<a.wrap&&(a.wrap=-a.wrap),0===a.pending?1:0):0}function me(e,t){if(65537>t&&(e.subarray&&tl||!e.subarray&&el))return fr.apply(null,Mr.shrinkBuf(e,t));for(var a='',n=0;n<t;n++)a+=fr(e[n]);return a}function ce(e){if(!(this instanceof ce))return new ce(e);this.options=Mr.assign({level:-1,method:8,chunkSize:16384,windowBits:15,memLevel:8,strategy:0,to:''},e||{});var t=this.options;t.raw&&0<t.windowBits?t.windowBits=-t.windowBits:t.gzip&&0<t.windowBits&&16>t.windowBits&&(t.windowBits+=16),this.err=0,this.msg='',this.ended=!1,this.chunks=[],this.strm=new ll,this.strm.avail_out=0;var i=$r.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(0!==i)throw new Error(Wr[i]);if(t.header&&$r.deflateSetHeader(this.strm,t.header),t.dictionary){var a;if(a='string'==typeof t.dictionary?rl.string2buf(t.dictionary):'[object ArrayBuffer]'===dl.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,i=$r.deflateSetDictionary(this.strm,a),0!==i)throw new Error(Wr[i]);this._dict_set=!0}}function pe(e,t){var i=new ce(t);if(i.push(e,!0),i.err)throw i.msg||Wr[i.err];return i.result}function ue(e){return(255&e>>>24)+(65280&e>>>8)+((65280&e)<<8)+((255&e)<<24)}function fe(){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 Mr.Buf16(320),this.work=new Mr.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function be(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg='',t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Mr.Buf32(852),t.distcode=t.distdyn=new Mr.Buf32(592),t.sane=1,t.back=-1,0):-2}function _e(e){var t;return e&&e.state?(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,be(e)):-2}function we(e,t){var i,a;return e&&e.state?(a=e.state,0>t?(i=0,t=-t):(i=(t>>4)+1,48>t&&(t&=15)),t&&(8>t||15<t))?-2:(null!==a.window&&a.wbits!==t&&(a.window=null),a.wrap=i,a.wbits=t,_e(e)):-2}function xe(e,t){var i,a;return e?(a=new fe,e.state=a,a.window=null,i=we(e,t),0!==i&&(e.state=null),i):-2}function ke(e){if(fl){var t;for(kl=new Mr.Buf32(512),yl=new Mr.Buf32(32),t=0;144>t;)e.lens[t++]=8;for(;256>t;)e.lens[t++]=9;for(;280>t;)e.lens[t++]=7;for(;288>t;)e.lens[t++]=8;for(ul(1,e.lens,0,288,kl,0,e.work,{bits:9}),t=0;32>t;)e.lens[t++]=5;ul(2,e.lens,0,32,yl,0,e.work,{bits:5}),fl=!1}e.lencode=kl,e.lenbits=9,e.distcode=yl,e.distbits=5}function ye(e,t,i,a){var n=e.state,o;return null===n.window&&(n.wsize=1<<n.wbits,n.wnext=0,n.whave=0,n.window=new Mr.Buf8(n.wsize)),a>=n.wsize?(Mr.arraySet(n.window,t,i-n.wsize,n.wsize,0),n.wnext=0,n.whave=n.wsize):(o=n.wsize-n.wnext,o>a&&(o=a),Mr.arraySet(n.window,t,i-a,o,n.wnext),a-=o,a?(Mr.arraySet(n.window,t,i-a,a,0),n.wnext=a,n.whave=n.wsize):(n.wnext+=o,n.wnext===n.wsize&&(n.wnext=0),n.whave<n.wsize&&(n.whave+=o))),0}function ve(e){if(!(this instanceof ve))return new ve(e);this.options=Mr.assign({chunkSize:16384,windowBits:0,to:''},e||{});var t=this.options;t.raw&&0<=t.windowBits&&16>t.windowBits&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),0<=t.windowBits&&16>t.windowBits&&!(e&&e.windowBits)&&(t.windowBits+=32),15<t.windowBits&&48>t.windowBits&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg='',this.ended=!1,this.chunks=[],this.strm=new ll,this.strm.avail_out=0;var i=bl.inflateInit2(this.strm,t.windowBits);if(i!==_l.Z_OK)throw new Error(Wr[i]);this.header=new wl,bl.inflateGetHeader(this.strm,this.header)}function De(e,t){var i=new ve(t);if(i.push(e,!0),i.err)throw i.msg||Wr[i.err];return i.result}function Se(e,t,i){for(var a=e,o=0;o<i;o++)a=Il[255&(a^t[o])]^a>>>8;return a}function Me(e,t){return(Se(Cl,e,t)^Cl)>>>0}function je(e,t,a){for(var n=0;n<a;n++)t[n]=e[n]}function Pe(e,t,a,n){for(var o=0;o<n;o++)t[o]=e[o];for(;o<a;o++)t[o]=255&e[o]+t[o-n]}function Ie(e,t,a,n){var o=0;if(0===a.length)for(;o<n;o++)t[o]=e[o];else for(;o<n;o++)t[o]=255&e[o]+a[o]}function Be(e,t,a,n,o){var s=0;if(0===a.length){for(;s<o;s++)t[s]=e[s];for(;s<n;s++)t[s]=255&e[s]+(t[s-o]>>1)}else{for(;s<o;s++)t[s]=255&e[s]+(a[s]>>1);for(;s<n;s++)t[s]=255&e[s]+(t[s-o]+a[s]>>1)}}function Ce(e,t,a,n,o){var s=0;if(0===a.length){for(;s<o;s++)t[s]=e[s];for(;s<n;s++)t[s]=255&e[s]+t[s-o]}else{for(;s<o;s++)t[s]=255&e[s]+a[s];for(;s<n;s++)t[s]=255&e[s]+Re(t[s-o],a[s],a[s-o])}}function Re(e,t,i){var a=e+t-i,n=mr(a-e),o=mr(a-t),s=mr(a-i);return n<=o&&n<=s?e:o<=s?t:i}function Ae(e){return(255&e)<<8|255&e>>8}function ze(e,t){if(gr(e)&&0<e)return e;throw new TypeError(`${t} must be a positive integer`)}function Ye(e){const{components:t=3,alpha:i=!0,bitDepth:a=8}=e;if(3!==t&&1!==t)throw new RangeError(`unsupported number of components: ${t}`);if(8!==a&&16!==a)throw new RangeError(`unsupported bit depth: ${a}`);const n=t+ +i,o={channels:n,bitDepth:a};switch(n){case 4:o.colourType=6;break;case 3:o.colourType=2;break;case 1:o.colourType=0;break;case 2:o.colourType=4;break;default:throw new Error(`unsupported number of channels: ${n}`);}return o}function Le(e,t,i,a){for(var n=0;n<i;n++)t.writeByte(e[a++]);return a}function Ee(e,t,i,a){for(var n=0;n<i;n++)t.writeUint16(e[a++]);return a}function Te(e,t={}){const i=new Ll(e,t);return i.decode()}function Fe(e,t={}){const i=new Tl(e,t);return i.encode()}function Xe(e){function t(e){for(var a=[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],n=0,o;64>n;n++)o=b((a[n]*e+50)/100),1>o?o=1:255<o&&(o=255),x[L[n]]=o;for(var s=[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],r=0,l;64>r;r++)l=b((s[r]*e+50)/100),1>l?l=1:255<l&&(l=255),y[L[r]]=l;for(var d=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],h=0,g=0;8>g;g++)for(var m=0;8>m;m++)v[h]=1/(8*(x[L[h]]*d[g]*d[m])),D[h]=1/(8*(y[L[h]]*d[g]*d[m])),h++}function i(e,t){for(var i=0,a=0,n=[],o=1;16>=o;o++){for(var s=1;s<=e[o];s++)n[t[a]]=[],n[t[a]][0]=i,n[t[a]][1]=o,a++,i++;i*=2}return n}function a(){N=i(E,T),H=i(V,U),q=i(F,X),W=i(G,O)}function n(){for(var e=1,t=2,i=1;15>=i;i++){for(var a=e;a<t;a++)S[32767+a]=i,k[32767+a]=[],k[32767+a][1]=i,k[32767+a][0]=a;for(var n=-(t-1);n<=-e;n++)S[32767+n]=i,k[32767+n]=[],k[32767+n][1]=i,k[32767+n][0]=t-1+n;e<<=1,t<<=1}}function o(){for(var e=0;256>e;e++)Y[e]=19595*e,Y[e+256>>0]=38470*e,Y[e+512>>0]=7471*e+32768,Y[e+768>>0]=-11059*e,Y[e+1024>>0]=-21709*e,Y[e+1280>>0]=32768*e+8421375,Y[e+1536>>0]=-27439*e,Y[e+1792>>0]=-5329*e}function s(e){for(var t=e[0],i=e[1]-1;0<=i;)t&1<<i&&(I|=1<<B),i--,B--,0>B&&(255==I?(r(255),r(0)):r(I),B=7,I=0)}function r(e){j.push(e)}function d(e){r(255&e>>8),r(255&e)}function l(e,t){var a=0,n,o,s,r,l,d,h,g,m;for(m=0;m<8;++m){n=e[a],o=e[a+1],s=e[a+2],r=e[a+3],l=e[a+4],d=e[a+5],h=e[a+6],g=e[a+7];var c=n+g,p=n-g,u=o+h,f=o-h,b=s+d,_=s-d,w=r+l,x=r-l,k=c+w,y=c-w,v=u+b,D=u-b;e[a]=k+v,e[a+4]=k-v;var S=.707106781*(D+y);e[a+2]=y+S,e[a+6]=y-S,k=x+_,v=_+f,D=f+p;var j=.382683433*(k-D),P=.5411961*k+j,I=1.306562965*D+j,B=.707106781*v,C=p+B,R=p-B;e[a+5]=R+P,e[a+3]=R-P,e[a+1]=C+I,e[a+7]=C-I,a+=8}for(a=0,m=0;m<8;++m){n=e[a],o=e[a+8],s=e[a+16],r=e[a+24],l=e[a+32],d=e[a+40],h=e[a+48],g=e[a+56];var A=n+g,z=n-g,Y=o+h,L=o-h,E=s+d,T=s-d,F=r+l,X=r-l,V=A+F,U=A-F,G=Y+E,O=Y-E;e[a]=V+G,e[a+32]=V-G;var N=.707106781*(O+U);e[a+16]=U+N,e[a+48]=U-N,V=X+T,G=T+L,O=L+z;var H=.382683433*(V-O),q=.5411961*V+H,W=1.306562965*O+H,Z=.707106781*G,K=z+Z,J=z-Z;e[a+40]=J+q,e[a+24]=J-q,e[a+8]=K+W,e[a+56]=K-W,a++}var Q;for(m=0;m<64;++m)Q=e[m]*t[m],M[m]=0<Q?0|Q+.5:0|Q-.5;return M}function h(){d(65504),d(16),r(74),r(70),r(73),r(70),r(0),r(1),r(1),r(0),d(1),d(1),r(0),r(0)}function m(e,t){d(65472),d(17),r(8),d(t),d(e),r(3),r(1),r(17),r(0),r(2),r(17),r(1),r(3),r(17),r(1)}function c(){d(65499),d(132),r(0);for(var e=0;64>e;e++)r(x[e]);r(1);for(var t=0;64>t;t++)r(y[t])}function u(){d(65476),d(418),r(0);for(var e=0;16>e;e++)r(E[e+1]);for(var t=0;11>=t;t++)r(T[t]);r(16);for(var a=0;16>a;a++)r(F[a+1]);for(var s=0;161>=s;s++)r(X[s]);r(1);for(var h=0;16>h;h++)r(V[h+1]);for(var g=0;11>=g;g++)r(U[g]);r(17);for(var c=0;16>c;c++)r(G[c+1]);for(var u=0;161>=u;u++)r(O[u])}function f(){d(65498),d(12),r(3),r(1),r(0),r(2),r(17),r(3),r(17),r(0),r(63),r(0)}function _(e,t,a,n,o){for(var r=o[0],d=o[240],h=l(e,t),g=0,m;64>g;++g)P[L[g]]=h[g];var c=P[0]-a;a=P[0],0==c?s(n[0]):(m=32767+c,s(n[S[m]]),s(k[m]));for(var p=63;0<p&&0==P[p];p--);if(0==p)return s(r),a;for(var u=1,f;u<=p;){for(var b=u;0==P[u]&&u<=p;++u);var _=u-b;if(16<=_){f=_>>4;for(var w=1;w<=f;++w)s(d);_&=15}m=32767+P[u],s(o[(_<<4)+S[m]]),s(k[m]),u++}return 63!=p&&s(r),a}function g(){for(var e=0;256>e;e++)z[e]=fr(e)}function w(e){if(0>=e&&(e=1),100<e&&(e=100),Z!=e){var i=0;i=50>e?ur(5e3/e):ur(200-2*e),t(i),Z=e}}function p(){var t=new Date().getTime();e||(e=50),g(),a(),n(),o(),w(e);new Date().getTime()-t}var b=ur,x=Array(64),y=Array(64),v=Array(64),D=Array(64),k=Array(65535),S=Array(65535),M=Array(64),P=Array(64),j=[],I=0,B=7,C=Array(64),R=Array(64),A=Array(64),z=Array(256),Y=Array(2048),L=[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],T=[0,1,2,3,4,5,6,7,8,9,10,11],F=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],X=[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],V=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],U=[0,1,2,3,4,5,6,7,8,9,10,11],G=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],O=[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],N,H,q,W,Z;this.encode=function(e,t){var i=new Date().getTime();t&&w(t),j=[],I=0,B=7,d(65496),h(),c(),m(e.width,e.height),u(),f();var a=0,n=0,o=0;I=0,B=7,this.encode.displayName='_encode_';for(var l=e.data,k=e.width,S=e.height,M=4*k,P=0,z,L,E,T,F,X,V,U,G;P<S;){for(z=0;z<M;){for(F=M*P+z,X=F,V=-1,U=0,G=0;64>G;G++)U=G>>3,V=4*(7&G),X=F+U*M+V,P+U>=S&&(X-=M*(P+1+U-S)),z+V>=M&&(X-=z+V-M+4),L=l[X++],E=l[X++],T=l[X++],C[G]=(Y[L]+Y[E+256>>0]+Y[T+512>>0]>>16)-128,R[G]=(Y[L+768>>0]+Y[E+1024>>0]+Y[T+1280>>0]>>16)-128,A[G]=(Y[L+1280>>0]+Y[E+1536>>0]+Y[T+1792>>0]>>16)-128;a=_(C,v,a,N,q),n=_(R,D,n,H,W),o=_(A,D,o,H,W),z+=32}P+=8}if(0<=B){var O=[];O[1]=B+1,O[0]=(1<<B+1)-1,s(O)}return d(65497),new Buffer(j);var Z='data:image/jpeg;base64,'+Fl(j.join(''))},p()}function Ve(e,t){'undefined'==typeof t&&(t=50);var i=new Xe(t),a=i.encode(e,t);return{data:a,width:e.width,height:e.height}}function Ue(e,t){var i=new Uint8Array(e),a=new Xl;a.parse(i);var n={width:a.width,height:a.height,data:t?new Uint8Array(4*(a.width*a.height)):new Buffer(4*(a.width*a.height))};return a.copyToImageData(n),n}function Ge(e){var t=void 0,a=e.length,n='';for(t=0;t<a;t+=3)n+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'[e[t]>>2],n+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'[(3&e[t])<<4|e[t+1]>>4],n+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'[(15&e[t+1])<<2|e[t+2]>>6],n+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'[63&e[t+2]];return 2==a%3?n=`${n.substring(0,n.length-1)}=`:1==a%3&&(n=`${n.substring(0,n.length-2)}==`),n}function Oe(e){var t=.75*e.length,i=e.length,a=0,n=void 0,o=void 0,s=void 0,r=void 0;'='===e[e.length-1]&&(t--,'='===e[e.length-2]&&t--);for(var l=new Uint8Array(t),d=0;d<i;d+=4)n=Ol[e.charCodeAt(d)],o=Ol[e.charCodeAt(d+1)],s=Ol[e.charCodeAt(d+2)],r=Ol[e.charCodeAt(d+3)],l[a++]=n<<2|o>>4,l[a++]=(15&o)<<4|s>>2,l[a++]=(3&s)<<6|63&r;return l}function Ne(e,t){var i=Ge(e);return`data:${t};base64,${i}`}function He(e,t){var i=self.document.createElement('canvas');return i.width=e,i.height=t,i}function qe(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},i=t.withCredentials;return new Promise(function(t,a){var n=new self.XMLHttpRequest;n.open('GET',e,!0),n.responseType='arraybuffer',n.withCredentials=i!==void 0&&i,n.onload=function(i){200===this.status?t(this.response):a(i)},n.onerror=a,n.send()})}function We(){throw new Error('createWriteStream does not exist in the browser')}function Ze(){throw new Error('writeFile does not exist in the browser')}function Ke(e){return e.includes('/')||(e=`image/${e}`),e}function Je(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},i={width:e.width,height:e.height,data:e.getRGBAData()};return Ul(i,t.quality).data}function Qe(e,t){var i={width:e.width,height:e.height,components:e.components,alpha:e.alpha,bitDepth:e.bitDepth,data:e.data};return(1===i.bitDepth||32===i.bitDepth)&&(i.bitDepth=8,i.components=3,i.alpha=1,i.data=e.getRGBAData()),Fe(i,t)}function $e(e){for(var t in Wl)e.prototype[t]=Wl[t]}function et(e,t){for(var a=0,n;a<e.size;a++)n=e.getBit(a),t[4*a]=255*n,t[4*a+1]=255*n,t[4*a+2]=255*n}function tt(e,t){for(var a=e.min[0],n=e.max[0],o=0,s;o<e.size;o++)s=ur(255*(e.data[o]-a)/(n-a)),t[4*o]=s,t[4*o+1]=s,t[4*o+2]=s}function it(e,t){for(var a=hr(...e.min),n=dr(...e.max),o=n-a,s=0;s<e.size;s++){var r=ur(255*(e.data[3*s]-a)/o),l=ur(255*(e.data[3*s+1]-a)/o),d=ur(255*(e.data[3*s+2]-a)/o);t[4*s]=r,t[4*s+1]=l,t[4*s+2]=d}}function at(e,t){for(var a=0;a<e.size;a++)t[4*a]=e.data[a*e.channels]>>>e.bitDepth-8,t[4*a+1]=e.data[a*e.channels]>>>e.bitDepth-8,t[4*a+2]=e.data[a*e.channels]>>>e.bitDepth-8}function nt(e,t){for(var a=0;a<e.size;a++)t[4*a]=e.data[a*e.channels]>>>e.bitDepth-8,t[4*a+1]=e.data[a*e.channels+1]>>>e.bitDepth-8,t[4*a+2]=e.data[a*e.channels+2]>>>e.bitDepth-8}function ot(e,t){for(var a=0;a<e.size;a++)t[4*a+3]=e.data[a*e.channels+e.components]>>e.bitDepth-8}function st(e,t){for(var a=0;a<e.size;a++)t[4*a+3]=255}function rt(e){var t=dd[e];if(!t)throw new RangeError(`invalid image kind: ${e}`);return t}function lt(e){var t=e.components,i=e.alpha,a=e.bitDepth,n=e.colorModel;if(!gr(t)||0>=t)throw new RangeError(`invalid components: ${t}. Must be a positive integer`);if(0!==i&&1!==i&&'boolean'!=typeof i)throw new TypeError(`invalid alpha: ${i}: must be a boolean, 0 or 1`);if(!hd.includes(a))throw new RangeError(`invalid bitDepth: ${a}. Must be one of ${hd.join(', ')}`);if(!ld[n])throw new RangeError(`invalid colorModel: ${n}. Must be one of ${Object.keys(ld).join(', ')}`)}function dt(e,t,i){var a=t*e;return 1===i&&(a=pr(a/8)),a}function ht(e,t,a,n,o,s){var r=n*e,l=void 0;switch(o){case 1:l=new Uint8Array(pr(r/8));break;case 8:l=new Uint8Array(r);break;case 16:l=new Uint16Array(r);break;case 32:l=new Float32Array(r);break;default:throw new Error(`Cannot create pixel array for bit depth ${o}`);}if(a)for(var d=t;d<l.length;d+=n)l[d]=s;return l}function gt(e){return'number'==typeof e?[e]:e}function mt(e,t){if(1===t)return e.readUint8();for(var a=new Uint8Array(t),n=0;n<t;n++)a[n]=e.readUint8();return a}function ct(e,t){for(var a=[],n='',o=0,s;o<t;o++)s=fr(e.readUint8()),'\0'===s?(a.push(n),n=''):n+=s;return 1===a.length?a[0]:a}function pt(e,t){if(1===t)return e.readUint16();for(var a=new Uint16Array(t),n=0;n<t;n++)a[n]=e.readUint16();return a}function ut(e,t){if(1===t)return e.readUint32();for(var a=new Uint32Array(t),n=0;n<t;n++)a[n]=e.readUint32();return a}function ft(e,t){if(1===t)return e.readUint32()/e.readUint32();for(var a=Array(t),n=0;n<t;n++)a[n]=e.readUint32()/e.readUint32();return a}function bt(e,t){if(1===t)return e.readInt8();for(var a=new Int8Array(t),n=0;n<t;n++)a[n]=e.readInt8();return a}function _t(e,t){if(1===t)return e.readInt16();for(var a=new Int16Array(t),n=0;n<t;n++)a[n]=e.readInt16();return a}function wt(e,t){if(1===t)return e.readInt32();for(var a=new Int32Array(t),n=0;n<t;n++)a[n]=e.readInt32();return a}function xt(e,t){if(1===t)return e.readInt32()/e.readInt32();for(var a=Array(t),n=0;n<t;n++)a[n]=e.readInt32()/e.readInt32();return a}function kt(e,t){if(1===t)return e.readFloat32();for(var a=new Float32Array(t),n=0;n<t;n++)a[n]=e.readFloat32();return a}function yt(e,t){if(1===t)return e.readFloat64();for(var a=new Float64Array(t),n=0;n<t;n++)a[n]=e.readFloat64();return a}function vt(e,t,i,a){return 8===i?new Uint8Array(e*t):16===i?new Uint16Array(e*t):32===i&&3===a?new Float32Array(e*t):jt('bit depth / sample format',i+' / '+a)}function Dt(e,t,a,n){for(var o=0;o<n;o++)e[a++]=t.getUint8(o);return a}function St(e,t,a,n,o){for(var s=0;s<2*n;s+=2)e[a++]=t.getUint16(s,o);return a}function Mt(e,t,a,n,o){for(var s=0;s<4*n;s+=4)e[a++]=t.getFloat32(s,o);return a}function jt(e,t){throw new Error('Unsupported '+e+': '+t)}function Pt(e){if(e.length){const i=e;e=i[0];for(var t=0;t<i.length;t++)i[t]!==e&&jt('bit depth',i)}return e}function It(e){return'number'==typeof e?[e]:e}function Bt(e,t){return Kd.get(e)[0]*t}function Ct(e,t,i){return Kd.get(t)[1](e,i)}function Rt(e,t){if(1===t)return e.readUint8();for(var a=new Uint8Array(t),n=0;n<t;n++)a[n]=e.readUint8();return a}function At(e,t){for(var a=[],n='',o=0,s;o<t;o++)s=fr(e.readUint8()),'\0'===s?(a.push(n),n=''):n+=s;return 1===a.length?a[0]:a}function zt(e,t){if(1===t)return e.readUint16();for(var a=new Uint16Array(t),n=0;n<t;n++)a[n]=e.readUint16();return a}function Yt(e,t){if(1===t)return e.readUint32();for(var a=new Uint32Array(t),n=0;n<t;n++)a[n]=e.readUint32();return a}function Lt(e,t){if(1===t)return e.readUint32()/e.readUint32();for(var a=Array(t),n=0;n<t;n++)a[n]=e.readUint32()/e.readUint32();return a}function Et(e,t){if(1===t)return e.readInt8();for(var a=new Int8Array(t),n=0;n<t;n++)a[n]=e.readInt8();return a}function Tt(e,t){if(1===t)return e.readInt16();for(var a=new Int16Array(t),n=0;n<t;n++)a[n]=e.readInt16();return a}function Ft(e,t){if(1===t)return e.readInt32();for(var a=new Int32Array(t),n=0;n<t;n++)a[n]=e.readInt32();return a}function Xt(e,t){if(1===t)return e.readInt32()/e.readInt32();for(var a=Array(t),n=0;n<t;n++)a[n]=e.readInt32()/e.readInt32();return a}function Vt(e,t){if(1===t)return e.readFloat32();for(var a=new Float32Array(t),n=0;n<t;n++)a[n]=e.readFloat32();return a}function Ut(e,t){if(1===t)return e.readFloat64();for(var a=new Float64Array(t),n=0;n<t;n++)a[n]=e.readFloat64();return a}function Gt(e,t,i,a){if(8===i)return new Uint8Array(e*t);if(16===i)return new Uint16Array(e*t);if(32===i&&3===a)return new Float32Array(e*t);throw qt('bit depth / sample format',i+' / '+a)}function Ot(e,t,a,n){for(var o=0;o<n;o++)e[a++]=t.getUint8(o);return a}function Nt(e,t,a,n,o){for(var s=0;s<2*n;s+=2)e[a++]=t.getUint16(s,o);return a}function Ht(e,t,a,n,o){for(var s=0;s<4*n;s+=4)e[a++]=t.getFloat32(s,o);return a}function qt(e,t){return new Error('Unsupported '+e+': '+t)}function Wt(e){if(e.length){const i=e;e=i[0];for(var t=0;t<i.length;t++)if(i[t]!==e)throw qt('bit depth',i)}return e}function Zt(e,t={}){const i=new Qd(e,t);return i.decode(t)}function Kt(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.algorithm,a=t===void 0?'matchToPrevious':t,n=e.ignoreBorder,o=n===void 0?[0,0]:n;this.checkProcessable('matchAndCrop',{bitDepth:[8,16]});var s=this[0],r=[];r[0]={position:[0,0],image:this[0]};for(var l=[0,0],d=1,h;d<this.length;d++)h=s.getBestMatch(this[d],{border:o}),r[d]={position:[h[0]+l[0],h[1]+l[1]],image:this[d]},'matchToPrevious'===a&&(l[0]+=h[0],l[1]+=h[1],s=this[d]);for(var g=0,m=0,c=0,p=0,u=0,f;u<r.length;u++)f=r[u],f.position[0]>g&&(g=f.position[0]),f.position[0]<m&&(m=f.position[0]),f.position[1]>c&&(c=f.position[1]),f.position[1]<p&&(p=f.position[1]);m=0-m,p=0-p;for(var b=0,_;b<r.length;b++)_=r[b],_.crop=_.image.crop({x:g-_.position[0],y:c-_.position[1],width:s.width-m-g,height:s.height-p-c});for(var w=[],x=0;x<r.length;x++)w[x]=r[x].crop;return new ah(w)}function Jt(){this.checkProcessable('min',{bitDepth:[8,16]});for(var e=this[0].min,t=1;t<this.length;t++)for(var a=0;a<e.length;a++)e[a]=hr(e[a],this[t].min[a]);return e}function Qt(){this.checkProcessable('min',{bitDepth:[8,16]});for(var e=this[0].max,t=1;t<this.length;t++)for(var a=0;a<e.length;a++)e[a]=dr(e[a],this[t].max[a]);return e}function $t(e){var t=e.reduce((e,t)=>e+t);if(0===t)throw new Error('unreachable');for(var i=0,a=0,n=t/2,o=void 0;;){if(0<e[i]){if(void 0!=o)return(o+i)/2;if(a+=e[i],a>n)return i;a===n&&(o=i)}i++}}function ei(e){for(var t=0,a=0,n=0;n<e.length;n++)t+=e[n],a+=e[n]*n;return 0===t?0:a/t}function ti(){this.checkProcessable('median',{bitDepth:[8,16]});for(var e=this.getHistograms({maxSlots:this[0].maxValue+1}),t=Array(e.length),i=0,a;i<e.length;i++)a=e[i],t[i]=$t(a);return t}function ii(e){this.checkProcessable('min',{bitDepth:[8,16]});for(var t=this[0].getHistogram(e),a=1,n;a<this.length;a++){n=this[a].getHistogram(e);for(var o=0;o<t.length;o++)t[o]+=n[o]}return t}function ai(e){this.checkProcessable('min',{bitDepth:[8,16]});for(var t=this[0].getHistograms(e),a=t[0].length,n=1,o;n<this.length;n++){o=this[n].getHistograms(e);for(var s=0;s<t.length;s++)for(var r=0;r<a;r++)t[s][r]+=o[s][r]}return t}function ni(){this.checkProcessable('average',{bitDepth:[8,16]});for(var e=new Uint32Array(this[0].data.length),t=0,a;t<this.length;t++){a=this[t];for(var n=0;n<this[0].data.length;n++)e[n]+=a.data[n]}for(var o=tc.createFrom(this[0]),s=o.data,r=0;r<this[0].data.length;r++)s[r]=e[r]/this.length;return o}function oi(e,t){function i(i){return t?t:Ne(e,i)}var a=th(e);if(a)switch(a.mime){case'image/png':return ri(e);case'image/jpeg':return li(e);case'image/tiff':return di(e);default:return mi(i(a.mime));}return mi(i('application/octet-stream'))}function si(e,t){var i=e.slice(0,64).match(nh),a=void 0;return a=null===i?qe(e,t):Promise.resolve(Oe(e.slice(i[0].length))),a.then(t=>{var a=new Uint8Array(t);return oi(a,i?e:void 0)})}function ri(e){var t=Te(e),i=t.bitDepth,a=t.data,n=t.colourType,o=void 0,s=0;switch(n){case 0:o=1;break;case 2:o=3;break;case 4:o=1,s=1;break;case 6:o=3,s=1;break;default:throw new Error(`Unexpected colourType: ${n}`);}return new tc(t.width,t.height,a,{components:o,alpha:s,bitDepth:i})}function li(e){var t=Ad(e),i=void 0;t.exif&&(i=hi(t.exif));var a=Gl(e,!0);return new tc(a.width,a.height,a.data,{meta:i})}function di(e){var t=Zt(e);return 1===t.length?gi(t[0]):new ah(t.map(gi))}function hi(e){var t={tiff:e};return e.exif&&(t.exif=e.exif),e.gps&&(t.gps=e.gps),t}function gi(e){return new tc(e.width,e.height,e.data,{components:1,alpha:0,colorModel:'GREY',bitDepth:e.bitsPerSample.length?e.bitsPerSample[0]:e.bitsPerSample,meta:hi(e)})}function mi(e,t){return t=t||{},new Promise(function(i,a){var n=new ql;n.onload=function(){var e=n.width,a=n.height,o=He(e,a),s=o.getContext('2d');s.drawImage(n,0,0,e,a);var r=s.getImageData(0,0,e,a).data;i(new tc(e,a,r,t))},n.onerror=function(){a(new Error(`Could not load ${e}`))},n.src=e})}function ci(e){for(var t in oh)e.prototype[t]=oh[t]}function pi(e){return{width:e.width,height:e.height,components:e.components,alpha:e.alpha,colorModel:e.colorModel,bitDepth:e.bitDepth}}function ui(e,t,i){var a=3<arguments.length&&arguments[3]!==void 0?arguments[3]:{},n=t.out;if(n===void 0)return a.copy?e.clone():tc.createFrom(e,i);if(!tc.isImage(n))throw new TypeError('out must be an Image object');var o=Object.assign(pi(e),i);for(var s in o)if(n[s]!==o[s])throw new RangeError(`cannot use out. Its ${s} must be "${o[s]}" (found "${n[s]}")`);return n}function fi(e,t,i){if(t.inPlace!==void 0&&'boolean'!=typeof t.inPlace)throw new TypeError('inPlace option must be a boolean');if(t.inPlace){if(void 0!==t.out)throw new TypeError('out option must not be set if inPlace option is true');return e}return ui(e,t,null,i)}function bi(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.checkProcessable('abs',{bitDepth:[32]});var t=fi(this,e);return _i(this,t),t}function _i(e,t){for(var a=0;a<e.data.length;a++)t.data[a]=mr(e.data[a])}function wi(e,t){if(1===e.alpha&&1===t.alpha)for(var a=0;a<e.size;a++)t.data[a*t.channels+t.components]=e.data[a*e.channels+e.components]}function xi(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.checkProcessable('invert',{bitDepth:[1,8,16]});var t=fi(this,e);return 1===this.bitDepth?ki(this,t):(yi(this,t),this!==t&&wi(this,t)),t}function ki(e,t){for(var a=0;a<e.data.length;a++)t.data[a]=~e.data[a]}function yi(e,t){for(var i=0;i<e.data.length;i+=e.channels)for(var a=0;a<e.components;a++)t.data[i+a]=e.maxValue-e.data[i+a]}function vi(){this.checkProcessable('flipX',{bitDepth:[8,16]});for(var e=0,t;e<this.height;e++){t=e*this.width*this.channels;for(var a=0;a<ur(this.width/2);a++)for(var n=a*this.channels+t,o=(this.width-a-1)*this.channels+t,s=0,r;s<this.channels;s++)r=this.data[n+s],this.data[n+s]=this.data[o+s],this.data[o+s]=r}return this}function Di(){this.checkProcessable('flipY',{bitDepth:[8,16]});for(var e=0;e<ur(this.height/2);e++)for(var t=0;t<this.width;t++)for(var a=t*this.channels+e*this.width*this.channels,n=t*this.channels+(this.height-1-e)*this.channels*this.width,o=0,s;o<this.channels;o++)s=this.data[a+o],this.data[a+o]=this.data[n+o],this.data[n+o]=s;return this}function Si(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.radius,a=t===void 0?1:t;if(1>a)throw new Error('radius must be greater than 1');for(var o=2*a+1,n=Array(o),s=0;s<o;s++){n[s]=Array(o);for(var r=0;r<o;r++)n[s][r]=1}for(var l=0;l<n.length;l++)n[l]=1;return this.convolution(n)}function Mi(e){if('number'!=typeof e||sh(e))throw new TypeError('Expected a number')}function ji(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=t.channels,a=t.allowAlpha,n=t.defaultAlpha;return'boolean'!=typeof a&&(a=!0),'undefined'==typeof i?Pi(e,n):Ii(e,i,a)}function Pi(e,t){for(var a=t?e.channels:e.components,n=Array(a),o=0;o<a;o++)n[o]=o;return n}function Ii(e,t,i){Array.isArray(t)||(t=[t]);for(var a=0;a<t.length;a++)t[a]=Bi(e,t[a],i);return t}function Bi(e,t){var i=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2];if(t===void 0)throw new RangeError(`validateChannel : the channel has to be >=0 and <${e.channels}`);if('string'==typeof t){switch(e.colorModel){case'GREY':break;case'RGB':'rgb'.includes(t)&&('r'===t?t=0:'g'===t?t=1:'b'===t?t=2:void 0);break;case'HSL':'hsl'.includes(t)&&('h'===t?t=0:'s'===t?t=1:'l'===t?t=2:void 0);break;case'HSV':'hsv'.includes(t)&&('h'===t?t=0:'s'===t?t=1:'v'===t?t=2:void 0);break;case'CMYK':'cmyk'.includes(t)&&('c'===t?t=0:'m'===t?t=1:'y'===t?t=2:'k'===t?t=3:void 0);break;default:throw new Error(`Unexpected color model: ${e.colorModel}`);}if('a'===t){if(!e.alpha)throw new Error('validateChannel : the image does not contain alpha channel');t=e.components}if('string'==typeof t)throw new Error(`validateChannel : undefined channel: ${t}`)}if(t>=e.channels)throw new RangeError(`validateChannel : the channel has to be >=0 and <${e.channels}`);if(!i&&t>=e.components)throw new RangeError('validateChannel : alpha channel may not be selected');return t}function Ci(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.radius,a=void 0===t?1:t,o=e.border,s=void 0===o?'copy':o,r=e.channels;if(this.checkProcessable('medianFilter',{bitDepth:[8,16]}),1>a)throw new Error('radius must be greater than 0');r=ji(this,r,!0);for(var l=a,d=a,h=tc.createFrom(this),g=(2*l+1)*(2*d+1),m=ur(g/2),p=Array(g),u=0,f;u<r.length;u++){f=r[u];for(var b=d;b<this.height-d;b++)for(var _=l,w;_<this.width-l;_++){w=0;for(var k=-d;k<=d;k++)for(var v=-l,D;v<=l;v++)D=((b+k)*this.width+_+v)*this.channels+f,p[w++]=this.data[D];var S=(b*this.width+_)*this.channels+f,M=p.sort(rh)[m];h.data[S]=M}}if(this.alpha&&!r.includes(this.channels))for(var P=this.components;P<this.data.length;P+=this.channels)h.data[P]=this.data[P];return h.setBorder({size:[l,d],algorithm:s}),h}function Ri(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.radius,i=t===void 0?1:t,a=e.sigma,n=e.channels,o=e.border,s=o===void 0?'copy':o;this.checkProcessable('gaussian',{bitDepth:[8,16]});var r=Ai(i,a);return this.convolution([r,r],{border:s,channels:n,algorithm:'separable'})}function Ai(e,a){for(var o=2*e+1,n=Array(o),s=a?a:.3*(.5*(o-1)-1)+.8,r=0,l=0;l<o;l++){var d=l-e,h=rr(-.5/(s*s)*d*d);n[l]=h,r+=h}for(var t=0;t<o;t++)n[t]/=r;return n}function zi(e,t,a){var n=Ei(e),o=n.data,s=Object.assign({normalize:!1,divisor:1,rows:n.rows,cols:n.cols},a),r,l;if(s.rows&&s.cols)r=s.rows,l=s.cols;else throw new Error('Invalid number of rows or columns '+r+' '+l);var d=s.divisor,h=t.length,g=t[0].length,m,c;if(s.normalize)for(d=0,m=0;m<h;m++)for(c=0;c<g;c++)d+=t[m][c];if(0===d)throw new RangeError('convolution: The divisor is equal to zero');var p=ch.toRadix2(o,r,l),u=ch.convolute(p.data,t,p.rows,p.cols);if(u=ch.crop(u,p.rows,p.cols,r,l),0!=d&&1!=d)for(m=0;m<u.length;m++)u[m]/=d;return u}function Yi(e,t,a){var n=Ei(e),o=n.data,s=Object.assign({normalize:!1,divisor:1,rows:n.rows,cols:n.cols},a),r,l;if(s.rows&&s.cols)r=s.rows,l=s.cols;else throw new Error('Invalid number of rows or columns '+r+' '+l);var d=s.divisor,h=t.length,g=t[0].length,m,c,p,u,f,b,_,w,k;if(s.normalize)for(d=0,m=0;m<h;m++)for(c=0;c<g;c++)d+=t[m][c];if(0===d)throw new RangeError('convolution: The divisor is equal to zero');var v=Array(r*l),D=ur(h/2),S=ur(g/2);for(u=0;u<r;u++)for(p=0;p<l;p++){for(b=0,c=0;c<h;c++)for(m=0;m<g;m++)_=t[h-c-1][g-m-1],w=(u+c-D+r)%r,k=(p+m-S+l)%l,f=w*l+k,b+=o[f]*_;f=u*l+p,v[f]=b/d}return v}function Li(e,t,a){var n=1e3;a&&a.factor&&(n=a.factor);var o=Array(t),s,r,l,d;n*=-1;var h=(t-1)/2;for(s=0;s<t;s++)for(o[s]=Array(t),d=(s-h)*(s-h),r=0;r<t;r++)l=-((r-h)*(r-h)+d)/(2*e*e),o[s][r]=ar(n*(1+l)*rr(l));return o}function Ei(e){var t=e,a,n;if('number'!=typeof e[0]){a=e.length,n=e[0].length,t=Array(a*n);for(var o=0;o<a;o++)for(var s=0;s<n;s++)t[o*n+s]=e[o][s]}else{var r=nr(e.length);gr(r)&&(a=r,n=r)}return{data:t,rows:a,cols:n}}function Ti(e){var t,a;if(!Array.isArray(e))throw new Error(`validateKernel: Invalid Kernel: ${e}`);else if(!Array.isArray(e[0])){var n=nr(e.length);if(_h(n))a=t=ur(nr(e.length)/2);else throw new RangeError('validateKernel: Kernel array should be a square');for(var o=Array(n),s=0;s<n;s++){o[s]=Array(n);for(var r=0;r<n;r++)o[s][r]=e[s*n+r]}e=o}else if(0==(1&e.length)||0==(1&e[0].length))throw new RangeError('validateKernel: Kernel rows and columns should be odd numbers');else t=ur(e.length/2),a=ur(e[0].length/2);return{kernel:e,kWidth:a,kHeight:t}}function Fi(e,t,a){if(a===void 0){const i=e.length+t.length-1;a=Array(i)}Xi(a);for(var n=0;n<e.length;n++)for(var o=0;o<t.length;o++)a[n+o]+=e[n]*t[o];return a}function Xi(e){for(var t=0;t<e.length;t++)e[t]=0}function Vi(e,t,i,a){var n=Array(e.length),o=void 0,s=void 0,r=void 0,l=void 0;l=t[1],r=(l.length-1)/2,s=Array(i+l.length-1),o=Array(i);for(var d=0;d<a;d++){for(var h=0;h<i;h++)o[h]=e[d*i+h];Fi(o,l,s);for(var g=0;g<i;g++)n[d*i+g]=s[r+g]}l=t[0],r=(l.length-1)/2,s=Array(a+l.length-1),o=Array(a);for(var m=0;m<i;m++){for(var c=0;c<a;c++)o[c]=n[c*i+m];Fi(o,l,s);for(var p=0;p<a;p++)n[p*i+m]=s[r+p]}return n}function Ui(e,t){return ar(hr(dr(e,0),t.maxValue))}function Gi(e){if(!Array.isArray(e))throw new Error('input must be an array');if(0===e.length)throw new Error('input must not be empty');for(var t=e[0],a=1;a<e.length;a++)e[a]>t&&(t=e[a]);return t}function Oi(e){if(!Array.isArray(e))throw new Error('input must be an array');if(0===e.length)throw new Error('input must not be empty');for(var t=e[0],a=1;a<e.length;a++)e[a]<t&&(t=e[a]);return t}function Ni(e,t={}){if(!Array.isArray(e))throw new TypeError('input must be an array');else if(0===e.length)throw new TypeError('input must not be empty');let a;if(t.output!==void 0){if(!Array.isArray(t.output))throw new TypeError('output option must be an array if specified');a=t.output}else a=Array(e.length);const n=Oi(e),o=Gi(e);if(n===o)throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array');const{min:s=t.autoMinMax?n:0,max:r=t.autoMinMax?o:1}=t;if(s>=r)throw new RangeError('min option must be smaller than max option');for(var l=0;l<e.length;l++)a[l]=(e[l]-n)*((r-s)/(o-n))+s;return a}function Hi(e,t){var i=0;return mr(e)>mr(t)?(i=t/e,mr(e)*nr(1+i*i)):0===t?0:(i=e/t,mr(t)*nr(1+i*i))}function qi(e,t,a){for(var n=Array(e),o=0;o<e;o++){n[o]=Array(t);for(var s=0;s<t;s++)n[o][s]=a}return n}function Wi(e,t,i){var a=i?e.rows:e.rows-1;if(0>t||t>a)throw new RangeError('Row index out of range')}function Zi(e,t,i){var a=i?e.columns:e.columns-1;if(0>t||t>a)throw new RangeError('Column index out of range')}function Ki(e,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==e.columns)throw new RangeError('vector size must be the same as the number of columns');return t}function Ji(e,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==e.rows)throw new RangeError('vector size must be the same as the number of rows');return t}function Qi(e,t,i){return{row:$i(e,t),column:ea(e,i)}}function $i(e,t){if('object'!=typeof t)throw new TypeError('unexpected type for row indices');var i=t.some(t=>0>t||t>=e.rows);if(i)throw new RangeError('row indices are out of range');return Array.isArray(t)||(t=Array.from(t)),t}function ea(e,t){if('object'!=typeof t)throw new TypeError('unexpected type for column indices');var i=t.some(t=>0>t||t>=e.columns);if(i)throw new RangeError('column indices are out of range');return Array.isArray(t)||(t=Array.from(t)),t}function ta(e,t,i,a,n){if(5!==arguments.length)throw new RangeError('expected 4 arguments');if(oa('startRow',t),oa('endRow',i),oa('startColumn',a),oa('endColumn',n),t>i||a>n||0>t||t>=e.rows||0>i||i>=e.rows||0>a||a>=e.columns||0>n||n>=e.columns)throw new RangeError('Submatrix indices are out of range')}function ia(e){for(var t=Ch.zeros(e.rows,1),a=0;a<e.rows;++a)for(var n=0;n<e.columns;++n)t.set(a,0,t.get(a,0)+e.get(a,n));return t}function aa(e){for(var t=Ch.zeros(1,e.columns),a=0;a<e.rows;++a)for(var n=0;n<e.columns;++n)t.set(0,n,t.get(0,n)+e.get(a,n));return t}function na(e){for(var t=0,a=0;a<e.rows;a++)for(var n=0;n<e.columns;n++)t+=e.get(a,n);return t}function oa(e,t){if('number'!=typeof t)throw new TypeError(`${e} must be a number`)}function sa(e){function t(e,t){return e-t}function a(e,t){for(var i in t)e=e.replace(new RegExp(`%${i}%`,'g'),t[i]);return e}e===void 0&&(e=Object);class n extends e{static get[Symbol.species](){return this}static from1DArray(e,t,i){if(e*t!==i.length)throw new RangeError('Data length does not match given dimensions');for(var a=new this(e,t),n=0;n<e;n++)for(var o=0;o<t;o++)a.set(n,o,i[n*t+o]);return a}static rowVector(e){for(var t=new this(1,e.length),a=0;a<e.length;a++)t.set(0,a,e[a]);return t}static columnVector(e){for(var t=new this(e.length,1),a=0;a<e.length;a++)t.set(a,0,e[a]);return t}static empty(e,t){return new this(e,t)}static zeros(e,t){return this.empty(e,t).fill(0)}static ones(e,t){return this.empty(e,t).fill(1)}static rand(e,t,a){a===void 0&&(a=Math.random);for(var n=this.empty(e,t),o=0;o<e;o++)for(var s=0;s<t;s++)n.set(o,s,a());return n}static randInt(e,t,a,n){a===void 0&&(a=1e3),n===void 0&&(n=Math.random);for(var o=this.empty(e,t),s=0;s<e;s++)for(var r=0,l;r<t;r++)l=ur(n()*a),o.set(s,r,l);return o}static eye(e,t,a){t===void 0&&(t=e),a===void 0&&(a=1);for(var n=hr(e,t),o=this.zeros(e,t),s=0;s<n;s++)o.set(s,s,a);return o}static diag(e,t,a){var n=e.length;t===void 0&&(t=n),a===void 0&&(a=t);for(var o=hr(n,t,a),s=this.zeros(t,a),r=0;r<o;r++)s.set(r,r,e[r]);return s}static min(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);for(var a=e.rows,n=e.columns,o=new this(a,n),s=0;s<a;s++)for(var r=0;r<n;r++)o.set(s,r,hr(e.get(s,r),t.get(s,r)));return o}static max(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);for(var a=e.rows,n=e.columns,o=new this(a,n),s=0;s<a;s++)for(var r=0;r<n;r++)o.set(s,r,dr(e.get(s,r),t.get(s,r)));return o}static checkMatrix(e){return n.isMatrix(e)?e:new this(e)}static isMatrix(e){return null!=e&&'Matrix'===e.klass}get size(){return this.rows*this.columns}apply(e){if('function'!=typeof e)throw new TypeError('callback must be a function');for(var t=this.rows,a=this.columns,n=0;n<t;n++)for(var o=0;o<a;o++)e.call(this,n,o);return this}to1DArray(){for(var e=Array(this.size),t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)e[t*this.columns+a]=this.get(t,a);return e}to2DArray(){for(var e=Array(this.rows),t=0;t<this.rows;t++){e[t]=Array(this.columns);for(var a=0;a<this.columns;a++)e[t][a]=this.get(t,a)}return e}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var e=0;e<this.rows;e++)for(var t=0;t<=e;t++)if(this.get(e,t)!==this.get(t,e))return!1;return!0}return!1}set(){throw new Error('set method is unimplemented')}get(){throw new Error('get method is unimplemented')}repeat(e,t){e=e||1,t=t||1;for(var a=new this.constructor[Symbol.species](this.rows*e,this.columns*t),n=0;n<e;n++)for(var o=0;o<t;o++)a.setSubMatrix(this,this.rows*n,this.columns*o);return a}fill(e){for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,e);return this}neg(){return this.mulS(-1)}getRow(e){Wi(this,e);for(var t=Array(this.columns),a=0;a<this.columns;a++)t[a]=this.get(e,a);return t}getRowVector(e){return this.constructor.rowVector(this.getRow(e))}setRow(e,t){Wi(this,e),t=Ki(this,t);for(var a=0;a<this.columns;a++)this.set(e,a,t[a]);return this}swapRows(e,t){Wi(this,e),Wi(this,t);for(var a=0,n;a<this.columns;a++)n=this.get(e,a),this.set(e,a,this.get(t,a)),this.set(t,a,n);return this}getColumn(e){Zi(this,e);for(var t=Array(this.rows),a=0;a<this.rows;a++)t[a]=this.get(a,e);return t}getColumnVector(e){return this.constructor.columnVector(this.getColumn(e))}setColumn(e,t){Zi(this,e),t=Ji(this,t);for(var a=0;a<this.rows;a++)this.set(a,e,t[a]);return this}swapColumns(e,t){Zi(this,e),Zi(this,t);for(var a=0,n;a<this.rows;a++)n=this.get(a,e),this.set(a,e,this.get(a,t)),this.set(a,t,n);return this}addRowVector(e){e=Ki(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)+e[a]);return this}subRowVector(e){e=Ki(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)-e[a]);return this}mulRowVector(e){e=Ki(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)*e[a]);return this}divRowVector(e){e=Ki(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)/e[a]);return this}addColumnVector(e){e=Ji(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)+e[t]);return this}subColumnVector(e){e=Ji(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)-e[t]);return this}mulColumnVector(e){e=Ji(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)*e[t]);return this}divColumnVector(e){e=Ji(this,e);for(var t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.set(t,a,this.get(t,a)/e[t]);return this}mulRow(e,t){Wi(this,e);for(var a=0;a<this.columns;a++)this.set(e,a,this.get(e,a)*t);return this}mulColumn(e,t){Zi(this,e);for(var a=0;a<this.rows;a++)this.set(a,e,this.get(a,e)*t);return this}max(){for(var e=this.get(0,0),t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.get(t,a)>e&&(e=this.get(t,a));return e}maxIndex(){for(var e=this.get(0,0),t=[0,0],a=0;a<this.rows;a++)for(var n=0;n<this.columns;n++)this.get(a,n)>e&&(e=this.get(a,n),t[0]=a,t[1]=n);return t}min(){for(var e=this.get(0,0),t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)this.get(t,a)<e&&(e=this.get(t,a));return e}minIndex(){for(var e=this.get(0,0),t=[0,0],a=0;a<this.rows;a++)for(var n=0;n<this.columns;n++)this.get(a,n)<e&&(e=this.get(a,n),t[0]=a,t[1]=n);return t}maxRow(e){Wi(this,e);for(var t=this.get(e,0),a=1;a<this.columns;a++)this.get(e,a)>t&&(t=this.get(e,a));return t}maxRowIndex(e){Wi(this,e);for(var t=this.get(e,0),a=[e,0],n=1;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),a[1]=n);return a}minRow(e){Wi(this,e);for(var t=this.get(e,0),a=1;a<this.columns;a++)this.get(e,a)<t&&(t=this.get(e,a));return t}minRowIndex(e){Wi(this,e);for(var t=this.get(e,0),a=[e,0],n=1;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),a[1]=n);return a}maxColumn(e){Zi(this,e);for(var t=this.get(0,e),a=1;a<this.rows;a++)this.get(a,e)>t&&(t=this.get(a,e));return t}maxColumnIndex(e){Zi(this,e);for(var t=this.get(0,e),a=[0,e],n=1;n<this.rows;n++)this.get(n,e)>t&&(t=this.get(n,e),a[0]=n);return a}minColumn(e){Zi(this,e);for(var t=this.get(0,e),a=1;a<this.rows;a++)this.get(a,e)<t&&(t=this.get(a,e));return t}minColumnIndex(e){Zi(this,e);for(var t=this.get(0,e),a=[0,e],n=1;n<this.rows;n++)this.get(n,e)<t&&(t=this.get(n,e),a[0]=n);return a}diag(){for(var e=hr(this.rows,this.columns),t=Array(e),a=0;a<e;a++)t[a]=this.get(a,a);return t}sum(e){return'row'===e?ia(this):'column'===e?aa(this):na(this)}mean(){return this.sum()/this.size}prod(){for(var e=1,t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)e*=this.get(t,a);return e}norm(e='frobenius'){var t=0;if('max'===e)return this.max();if('frobenius'===e){for(var a=0;a<this.rows;a++)for(var n=0;n<this.columns;n++)t+=this.get(a,n)*this.get(a,n);return nr(t)}throw new RangeError(`unknown norm type: ${e}`)}cumulativeSum(){for(var e=0,t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)e+=this.get(t,a),this.set(t,a,e);return this}dot(e){n.isMatrix(e)&&(e=e.to1DArray());var t=this.to1DArray();if(t.length!==e.length)throw new RangeError('vectors do not have the same size');for(var a=0,o=0;o<t.length;o++)a+=t[o]*e[o];return a}mmul(e){e=this.constructor.checkMatrix(e),this.columns!==e.rows&&console.warn('Number of columns of left matrix are not equal to number of rows of right matrix.');for(var t=this.rows,a=this.columns,n=e.columns,o=new this.constructor[Symbol.species](t,n),r=Array(a),l=0;l<n;l++){for(var d=0;d<a;d++)r[d]=e.get(d,l);for(var h=0,g;h<t;h++){for(g=0,d=0;d<a;d++)g+=this.get(h,d)*r[d];o.set(h,l,g)}}return o}strassen2x2(e){var t=new this.constructor[Symbol.species](2,2);const i=this.get(0,0),a=e.get(0,0),n=this.get(0,1),o=e.get(0,1),s=this.get(1,0),r=e.get(1,0),l=this.get(1,1),d=e.get(1,1),h=(i+l)*(a+d),g=(s+l)*a,m=i*(o-d),c=l*(r-a),p=(i+n)*d;return t.set(0,0,h+c-p+(n-l)*(r+d)),t.set(0,1,m+p),t.set(1,0,g+c),t.set(1,1,h-g+m+(s-i)*(a+o)),t}strassen3x3(e){var t=new this.constructor[Symbol.species](3,3);const i=this.get(0,0),a=this.get(0,1),n=this.get(0,2),o=this.get(1,0),s=this.get(1,1),r=this.get(1,2),l=this.get(2,0),d=this.get(2,1),h=this.get(2,2),g=e.get(0,0),m=e.get(0,1),c=e.get(0,2),p=e.get(1,0),u=e.get(1,1),f=e.get(1,2),b=e.get(2,0),_=e.get(2,1),w=e.get(2,2),x=(i-o)*(-m+u),k=(-i+o+s)*(g-m+u),y=(o+s)*(-g+m),v=i*g,D=(-i+l+d)*(g-c+f),S=(-i+l)*(c-f),M=(l+d)*(-g+c),j=(-n+d+h)*(u+b-_),P=(n-h)*(u-_),I=n*b,B=(d+h)*(-b+_),C=(-n+s+r)*(f+b-w),R=(n-r)*(f-w),A=(s+r)*(-b+w);return t.set(0,0,v+I+a*p),t.set(0,1,(i+a+n-o-s-d-h)*u+k+y+v+j+I+B),t.set(0,2,v+D+M+(i+a+n-s-r-l-d)*f+I+C+A),t.set(1,0,x+s*(-g+m+p-u-f-b+w)+k+v+I+C+R),t.set(1,1,x+k+y+v+r*_),t.set(1,2,I+C+R+A+o*c),t.set(2,0,v+D+S+d*(-g+c+p-u-f-b+_)+j+P+I),t.set(2,1,j+P+I+B+l*m),t.set(2,2,v+D+S+M+h*w),t}mmulStrassen(e){function t(e,t,i){var a=e.rows,o=e.columns;if(a===t&&o===i)return e;var s=n.zeros(t,i);return s=s.setSubMatrix(e,0,0),s}function i(e,o,s,r){if(512>=s||512>=r)return e.mmul(o);1==s%2&&1==r%2?(e=t(e,s+1,r+1),o=t(o,s+1,r+1)):1==s%2?(e=t(e,s+1,r),o=t(o,s+1,r)):1==r%2&&(e=t(e,s,r+1),o=t(o,s,r+1));var l=parseInt(e.rows/2,10),d=parseInt(e.columns/2,10),h=e.subMatrix(0,l-1,0,d-1),g=o.subMatrix(0,l-1,0,d-1),m=e.subMatrix(0,l-1,d,e.columns-1),c=o.subMatrix(0,l-1,d,o.columns-1),p=e.subMatrix(l,e.rows-1,0,d-1),u=o.subMatrix(l,o.rows-1,0,d-1),f=e.subMatrix(l,e.rows-1,d,e.columns-1),_=o.subMatrix(l,o.rows-1,d,o.columns-1),w=i(n.add(h,f),n.add(g,_),l,d),x=i(n.add(p,f),g,l,d),k=i(h,n.sub(c,_),l,d),y=i(f,n.sub(u,g),l,d),v=i(n.add(h,m),_,l,d),D=i(n.sub(p,h),n.add(g,c),l,d),S=i(n.sub(m,f),n.add(u,_),l,d),M=n.add(w,y);M.sub(v),M.add(S);var j=n.add(k,v),P=n.add(x,y),I=n.sub(w,x);I.add(k),I.add(D);var B=n.zeros(2*M.rows,2*M.columns);return B=B.setSubMatrix(M,0,0),B=B.setSubMatrix(j,M.rows,0),B=B.setSubMatrix(P,0,M.columns),B=B.setSubMatrix(I,M.rows,M.columns),B.subMatrix(0,s-1,0,r-1)}var a=this.clone(),o=a.rows,s=a.columns,l=e.rows,d=e.columns;s!==l&&console.warn(`Multiplying ${o} x ${s} and ${l} x ${d} matrix: dimensions do not match.`);var h=dr(o,l),r=dr(s,d);return a=t(a,h,r),e=t(e,h,r),i(a,e,h,r)}scaleRows(e,t){if(e=void 0===e?0:e,t=void 0===t?1:t,e>=t)throw new RangeError('min should be strictly smaller than max');for(var a=this.constructor.empty(this.rows,this.columns),n=0,o;n<this.rows;n++)o=Ni(this.getRow(n),{min:e,max:t}),a.setRow(n,o);return a}scaleColumns(e,t){if(e=void 0===e?0:e,t=void 0===t?1:t,e>=t)throw new RangeError('min should be strictly smaller than max');for(var a=this.constructor.empty(this.rows,this.columns),n=0,o;n<this.columns;n++)o=Ni(this.getColumn(n),{min:e,max:t}),a.setColumn(n,o);return a}kroneckerProduct(e){e=this.constructor.checkMatrix(e);for(var t=this.rows,a=this.columns,n=e.rows,o=e.columns,s=new this.constructor[Symbol.species](t*n,a*o),r=0;r<t;r++)for(var d=0;d<a;d++)for(var h=0;h<n;h++)for(var g=0;g<o;g++)s[n*r+h][o*d+g]=this.get(r,d)*e.get(h,g);return s}transpose(){for(var e=new this.constructor[Symbol.species](this.columns,this.rows),t=0;t<this.rows;t++)for(var a=0;a<this.columns;a++)e.set(a,t,this.get(t,a));return e}sortRows(e){e===void 0&&(e=t);for(var a=0;a<this.rows;a++)this.setRow(a,this.getRow(a).sort(e));return this}sortColumns(e){e===void 0&&(e=t);for(var a=0;a<this.columns;a++)this.setColumn(a,this.getColumn(a).sort(e));return this}subMatrix(e,t,a,n){ta(this,e,t,a,n);for(var o=new this.constructor[Symbol.species](t-e+1,n-a+1),s=e;s<=t;s++)for(var r=a;r<=n;r++)o[s-e][r-a]=this.get(s,r);return o}subMatrixRow(e,t,a){if(void 0===t&&(t=0),void 0===a&&(a=this.columns-1),t>a||0>t||t>=this.columns||0>a||a>=this.columns)throw new RangeError('Argument out of range');for(var n=new this.constructor[Symbol.species](e.length,a-t+1),o=0;o<e.length;o++)for(var s=t;s<=a;s++){if(0>e[o]||e[o]>=this.rows)throw new RangeError(`Row index out of range: ${e[o]}`);n.set(o,s-t,this.get(e[o],s))}return n}subMatrixColumn(e,t,a){if(void 0===t&&(t=0),void 0===a&&(a=this.rows-1),t>a||0>t||t>=this.rows||0>a||a>=this.rows)throw new RangeError('Argument out of range');for(var n=new this.constructor[Symbol.species](a-t+1,e.length),o=0;o<e.length;o++)for(var s=t;s<=a;s++){if(0>e[o]||e[o]>=this.columns)throw new RangeError(`Column index out of range: ${e[o]}`);n.set(s-t,o,this.get(s,e[o]))}return n}setSubMatrix(e,t,a){e=this.constructor.checkMatrix(e);var n=t+e.rows-1,o=a+e.columns-1;ta(this,t,n,a,o);for(var s=0;s<e.rows;s++)for(var r=0;r<e.columns;r++)this[t+s][a+r]=e.get(s,r);return this}selection(e,t){for(var a=Qi(this,e,t),n=new this.constructor[Symbol.species](e.length,t.length),o=0,s;o<a.row.length;o++){s=a.row[o];for(var r=0,l;r<a.column.length;r++)l=a.column[r],n[o][r]=this.get(s,l)}return n}trace(){for(var e=hr(this.rows,this.columns),t=0,a=0;a<e;a++)t+=this.get(a,a);return t}transposeView(){return new yh(this)}rowView(e){return Wi(this,e),new vh(this,e)}columnView(e){return Zi(this,e),new Ph(this,e)}flipRowView(){return new Ih(this)}flipColumnView(){return new Bh(this)}subMatrixView(e,t,i,a){return new Dh(this,e,t,i,a)}selectionView(e,t){return new Sh(this,e,t)}rowSelectionView(e){return new Mh(this,e)}columnSelectionView(e){return new jh(this,e)}det(){if(this.isSquare()){var e,t,i,n;if(2===this.columns)return e=this.get(0,0),t=this.get(0,1),i=this.get(1,0),n=this.get(1,1),e*n-t*i;if(3===this.columns){var o,s,r;return o=this.selectionView([1,2],[1,2]),s=this.selectionView([1,2],[0,2]),r=this.selectionView([1,2],[0,1]),e=this.get(0,0),t=this.get(0,1),i=this.get(0,2),e*o.det()-t*s.det()+i*r.det()}return new wh(this).determinant}throw Error('Determinant can only be calculated for a square matrix.')}pseudoInverse(e){void 0===e&&(e=ir);for(var t=new xh(this,{autoTranspose:!0}),a=t.leftSingularVectors,n=t.rightSingularVectors,o=t.diagonal,r=0;r<o.length;r++)o[r]=mr(o[r])>e?1/o[r]:0;return o=this.constructor[Symbol.species].diag(o),n.mmul(o.mmul(a.transposeView()))}clone(){for(var e=new this.constructor[Symbol.species](this.rows,this.columns),t=0;t<this.rows;t++)for(var i=0;i<this.columns;i++)e.set(t,i,this.get(t,i));return e}}n.prototype.klass='Matrix',n.random=n.rand,n.diagonal=n.diag,n.prototype.diagonal=n.prototype.diag,n.identity=n.eye,n.prototype.negate=n.prototype.neg,n.prototype.tensorProduct=n.prototype.kroneckerProduct,n.prototype.determinant=n.prototype.det;var o=`
  (function %name%(value) {
      if (typeof value === 'number') return this.%name%S(value);
      return this.%name%M(value);
  })
  `,s=`
  (function %name%S(value) {
      for (var i = 0; i < this.rows; i++) {
          for (var j = 0; j < this.columns; j++) {
              this.set(i, j, this.get(i, j) %op% value);
          }
      }
      return this;
  })
  `,r=`
  (function %name%M(matrix) {
      matrix = this.constructor.checkMatrix(matrix);
      if (this.rows !== matrix.rows ||
          this.columns !== matrix.columns) {
          throw new RangeError('Matrices dimensions must be equal');
      }
      for (var i = 0; i < this.rows; i++) {
          for (var j = 0; j < this.columns; j++) {
              this.set(i, j, this.get(i, j) %op% matrix.get(i, j));
          }
      }
      return this;
  })
  `,l=`
  (function %name%(matrix, value) {
      var newMatrix = new this[Symbol.species](matrix);
      return newMatrix.%name%(value);
  })
  `,d=`
  (function %name%() {
      for (var i = 0; i < this.rows; i++) {
          for (var j = 0; j < this.columns; j++) {
              this.set(i, j, %method%(this.get(i, j)));
          }
      }
      return this;
  })
  `,h=`
  (function %name%(matrix) {
      var newMatrix = new this[Symbol.species](matrix);
      return newMatrix.%name%();
  })
  `,g=`
  (function %name%(%args%) {
      for (var i = 0; i < this.rows; i++) {
          for (var j = 0; j < this.columns; j++) {
              this.set(i, j, %method%(this.get(i, j), %args%));
          }
      }
      return this;
  })
  `,m=`
  (function %name%(matrix, %args%) {
      var newMatrix = new this[Symbol.species](matrix);
      return newMatrix.%name%(%args%);
  })
  `,c=`
  (function %name%S(value) {
      for (var i = 0; i < this.rows; i++) {
          for (var j = 0; j < this.columns; j++) {
              this.set(i, j, %method%(this.get(i, j), value));
          }
      }
      return this;
  })
  `,p=`
  (function %name%M(matrix) {
      matrix = this.constructor.checkMatrix(matrix);
      if (this.rows !== matrix.rows ||
          this.columns !== matrix.columns) {
          throw new RangeError('Matrices dimensions must be equal');
      }
      for (var i = 0; i < this.rows; i++) {
          for (var j = 0; j < this.columns; j++) {
              this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));
          }
      }
      return this;
  })
  `,u=`
  (function %name%(value) {
      if (typeof value === 'number') return this.%name%S(value);
      return this.%name%M(value);
  })
  `,f=[['+','add'],['-','sub','subtract'],['*','mul','multiply'],['/','div','divide'],['%','mod','modulus'],['&','and'],['|','or'],['^','xor'],['<<','leftShift'],['>>','signPropagatingRightShift'],['>>>','rightShift','zeroFillRightShift']],b=eval,_;for(var w of f){var x=b(a('\n(function %name%(value) {\n    if (typeof value === \'number\') return this.%name%S(value);\n    return this.%name%M(value);\n})\n',{name:w[1],op:w[0]})),k=b(a('\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% value);\n        }\n    }\n    return this;\n})\n',{name:`${w[1]}S`,op:w[0]})),y=b(a('\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError(\'Matrices dimensions must be equal\');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% matrix.get(i, j));\n        }\n    }\n    return this;\n})\n',{name:`${w[1]}M`,op:w[0]})),v=b(a('\n(function %name%(matrix, value) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(value);\n})\n',{name:w[1]}));for(_=1;_<w.length;_++)n.prototype[w[_]]=x,n.prototype[`${w[_]}S`]=k,n.prototype[`${w[_]}M`]=y,n[w[_]]=v}var D=[['~','not']];['abs','acos','acosh','asin','asinh','atan','atanh','cbrt','ceil','clz32','cos','cosh','exp','expm1','floor','fround','log','log1p','log10','log2','round','sign','sin','sinh','sqrt','tan','tanh','trunc'].forEach(function(e){D.push([`Math.${e}`,e])});for(var S of D){var M=b(a('\n(function %name%() {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j)));\n        }\n    }\n    return this;\n})\n',{name:S[1],method:S[0]})),j=b(a('\n(function %name%(matrix) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%();\n})\n',{name:S[1]}));for(_=1;_<S.length;_++)n.prototype[S[_]]=M,n[S[_]]=j}var P=[['Math.pow',1,'pow']];for(var I of P){var B='arg0';for(_=1;_<I[1];_++)B+=`, arg${_}`;if(1!==I[1]){var C=b(a('\n(function %name%(%args%) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), %args%));\n        }\n    }\n    return this;\n})\n',{name:I[2],method:I[0],args:B})),R=b(a('\n(function %name%(matrix, %args%) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(%args%);\n})\n',{name:I[2],args:B}));for(_=2;_<I.length;_++)n.prototype[I[_]]=C,n[I[_]]=R}else{var A={name:I[2],args:B,method:I[0]},z=b(a('\n(function %name%(value) {\n    if (typeof value === \'number\') return this.%name%S(value);\n    return this.%name%M(value);\n})\n',A)),Y=b(a('\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), value));\n        }\n    }\n    return this;\n})\n',A)),L=b(a('\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError(\'Matrices dimensions must be equal\');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));\n        }\n    }\n    return this;\n})\n',A)),E=b(a('\n(function %name%(matrix, %args%) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(%args%);\n})\n',A));for(_=2;_<I.length;_++)n.prototype[I[_]]=z,n.prototype[`${I[_]}M`]=L,n.prototype[`${I[_]}S`]=Y,n[I[_]]=E}}return n}function ra(e,t=!1){return e=Ah.checkMatrix(e),t?new xh(e).inverse():la(e,Ch.eye(e.rows))}function la(e,t,i=!1){return e=Ah.checkMatrix(e),t=Ah.checkMatrix(t),i?new xh(e).solve(t):e.isSquare()?new wh(e).solve(t):new zh(e).solve(t)}function da(e,t){for(var a=[],n=0;n<e;n++)n!==t&&a.push(n);return a}function ha(e,t,a,n=1e-9,o=1e-9){if(e>o)return Array(t.rows+1).fill(0);for(var s=t.addRow(a,[0]),r=0;r<s.rows;r++)mr(s.get(r,0))<n&&s.set(r,0,0);return s.to1DArray()}function ga(e,t={}){const{thresholdValue:a=1e-9,thresholdError:o=1e-9}=t;for(var s=e.rows,n=new Ch(s,s),r=0;r<s;r++){var l=Ch.columnVector(e.getRow(r)),d=e.subMatrixRow(da(s,r)).transposeView(),h=new xh(d),g=h.solve(l),m=Gi(Ch.sub(l,d.mmul(g)).abs().to1DArray());n.setRow(r,ha(m,g,r,a,o))}return n}function ma(t,a,e,n){var o,s,r,l,d,m,c,p;for(d=0;d<t;d++)e[d]=n[t-1][d];for(l=t-1;0<l;l--){for(p=0,r=0,m=0;m<l;m++)p+=mr(e[m]);if(0===p)for(a[l]=e[l-1],d=0;d<l;d++)e[d]=n[l-1][d],n[l][d]=0,n[d][l]=0;else{for(m=0;m<l;m++)e[m]/=p,r+=e[m]*e[m];for(o=e[l-1],s=nr(r),0<o&&(s=-s),a[l]=p*s,r-=o*s,e[l-1]=o-s,d=0;d<l;d++)a[d]=0;for(d=0;d<l;d++){for(o=e[d],n[d][l]=o,s=a[d]+n[d][d]*o,m=d+1;m<=l-1;m++)s+=n[m][d]*e[m],a[m]+=n[m][d]*o;a[d]=s}for(o=0,d=0;d<l;d++)a[d]/=r,o+=a[d]*e[d];for(c=o/(r+r),d=0;d<l;d++)a[d]-=c*e[d];for(d=0;d<l;d++){for(o=e[d],s=a[d],m=d;m<=l-1;m++)n[m][d]-=o*a[m]+s*e[m];e[d]=n[l-1][d],n[l][d]=0}}e[l]=r}for(l=0;l<t-1;l++){if(n[t-1][l]=n[l][l],n[l][l]=1,r=e[l+1],0!==r){for(m=0;m<=l;m++)e[m]=n[m][l+1]/r;for(d=0;d<=l;d++){for(s=0,m=0;m<=l;m++)s+=n[m][l+1]*n[m][d];for(m=0;m<=l;m++)n[m][d]-=s*e[m]}}for(m=0;m<=l;m++)n[m][l+1]=0}for(d=0;d<t;d++)e[d]=n[t-1][d],n[t-1][d]=0;n[t-1][t-1]=1,a[0]=0}function ca(t,a,e,n){var o,d,u,b,_,w,x,y,v,D,S,M,P,I,B,C;for(u=1;u<t;u++)a[u-1]=a[u];a[t-1]=0;var R=0,A=0,z=ir;for(w=0;w<t;w++){for(A=dr(A,mr(e[w])+mr(a[w])),x=w;x<t&&!(mr(a[x])<=z*A);)x++;if(x>w)do{for(o=e[w],y=(e[w+1]-o)/(2*a[w]),v=Hi(y,1),0>y&&(v=-v),e[w]=a[w]/(y+v),e[w+1]=a[w]*(y+v),D=e[w+1],d=o-e[w],u=w+2;u<t;u++)e[u]-=d;for(R+=d,y=e[x],S=1,M=S,P=S,I=a[w+1],B=0,C=0,u=x-1;u>=w;u--)for(P=M,M=S,C=B,o=S*a[u],d=S*y,v=Hi(y,a[u]),a[u+1]=B*v,B=a[u]/v,S=y/v,y=S*e[u]-B*o,e[u+1]=d+B*(S*o+B*e[u]),_=0;_<t;_++)d=n[_][u+1],n[_][u+1]=B*n[_][u]+S*d,n[_][u]=S*n[_][u]-B*d;y=-B*C*P*I*a[w]/D,a[w]=B*y,e[w]=S*y}while(mr(a[w])>z*A);e[w]+=R,a[w]=0}for(u=0;u<t-1;u++){for(_=u,y=e[u],b=u+1;b<t;b++)e[b]<y&&(_=b,y=e[b]);if(_!==u)for(e[_]=e[u],e[u]=y,b=0;b<t;b++)y=n[b][u],n[b][u]=n[b][_],n[b][_]=y}}function pa(e,t,a,n){var o=e-1,s,r,l,d,c,p,u;for(p=1;p<=o-1;p++){for(u=0,d=p;d<=o;d++)u+=mr(t[d][p-1]);if(0!==u){for(l=0,d=o;d>=p;d--)a[d]=t[d][p-1]/u,l+=a[d]*a[d];for(r=nr(l),0<a[p]&&(r=-r),l-=a[p]*r,a[p]-=r,c=p;c<e;c++){for(s=0,d=o;d>=p;d--)s+=a[d]*t[d][c];for(s/=l,d=p;d<=o;d++)t[d][c]-=s*a[d]}for(d=0;d<=o;d++){for(s=0,c=o;c>=p;c--)s+=a[c]*t[d][c];for(s/=l,c=p;c<=o;c++)t[d][c]-=s*a[c]}a[p]=u*a[p],t[p][p-1]=u*r}}for(d=0;d<e;d++)for(c=0;c<e;c++)n[d][c]=d===c?1:0;for(p=o-1;p>=1;p--)if(0!==t[p][p-1]){for(d=p+1;d<=o;d++)a[d]=t[d][p-1];for(c=p;c<=o;c++){for(r=0,d=p;d<=o;d++)r+=a[d]*n[d][c];for(r=r/a[p]/t[p][p-1],d=p;d<=o;d++)n[d][c]+=r*a[d]}}}function ua(a,o,e,d,h){var g=a-1,c=a-1,u=ir,f=0,b=0,_=0,v=0,D=0,S=0,M=0,P=0,I,B,C,R,A,Y,L,E,T,F,X,V,U,G,O;for(I=0;I<a;I++)for((0>I||I>c)&&(e[I]=h[I][I],o[I]=0),B=dr(I-1,0);B<a;B++)b+=mr(h[I][B]);for(;g>=0;){for(R=g;0<R&&(S=mr(h[R-1][R-1])+mr(h[R][R]),0===S&&(S=b),!(mr(h[R][R-1])<u*S));)R--;if(R===g)h[g][g]+=f,e[g]=h[g][g],o[g]=0,g--,P=0;else if(R===g-1){if(L=h[g][g-1]*h[g-1][g],_=(h[g-1][g-1]-h[g][g])/2,v=_*_+L,M=nr(mr(v)),h[g][g]+=f,h[g-1][g-1]=h[g-1][g-1]+f,E=h[g][g],0<=v){for(M=0<=_?_+M:_-M,e[g-1]=E+M,e[g]=e[g-1],0!==M&&(e[g]=E-L/M),o[g-1]=0,o[g]=0,E=h[g][g-1],S=mr(E)+mr(M),_=E/S,v=M/S,D=nr(_*_+v*v),_/=D,v/=D,B=g-1;B<a;B++)M=h[g-1][B],h[g-1][B]=v*M+_*h[g][B],h[g][B]=v*h[g][B]-_*M;for(I=0;I<=g;I++)M=h[I][g-1],h[I][g-1]=v*M+_*h[I][g],h[I][g]=v*h[I][g]-_*M;for(I=0;I<=c;I++)M=d[I][g-1],d[I][g-1]=v*M+_*d[I][g],d[I][g]=v*d[I][g]-_*M}else e[g-1]=E+_,e[g]=E+_,o[g-1]=M,o[g]=-M;g-=2,P=0}else{if(E=h[g][g],T=0,L=0,R<g&&(T=h[g-1][g-1],L=h[g][g-1]*h[g-1][g]),10==P){for(f+=E,I=0;I<=g;I++)h[I][I]-=E;S=mr(h[g][g-1])+mr(h[g-1][g-2]),E=T=.75*S,L=-.4375*S*S}if(30==P&&(S=(T-E)/2,S=S*S+L,0<S)){for(S=nr(S),T<E&&(S=-S),S=E-L/((T-E)/2+S),I=0;I<=g;I++)h[I][I]-=S;f+=S,E=T=L=.964}for(++P,A=g-2;A>=R&&(M=h[A][A],D=E-M,S=T-M,_=(D*S-L)/h[A+1][A]+h[A][A+1],v=h[A+1][A+1]-M-D-S,D=h[A+2][A+1],S=mr(_)+mr(v)+mr(D),_/=S,v/=S,D/=S,A!=R)&&!(mr(h[A][A-1])*(mr(v)+mr(D))<u*(mr(_)*(mr(h[A-1][A-1])+mr(M)+mr(h[A+1][A+1]))));)A--;for(I=A+2;I<=g;I++)h[I][I-2]=0,I>A+2&&(h[I][I-3]=0);for(C=A;C<=g-1&&(G=C!==g-1,C!==A&&(_=h[C][C-1],v=h[C+1][C-1],D=G?h[C+2][C-1]:0,E=mr(_)+mr(v)+mr(D),0!==E&&(_/=E,v/=E,D/=E)),0!==E);C++)if(S=nr(_*_+v*v+D*D),0>_&&(S=-S),0!==S){for(C===A?R!==A&&(h[C][C-1]=-h[C][C-1]):h[C][C-1]=-S*E,_+=S,E=_/S,T=v/S,M=D/S,v/=_,D/=_,B=C;B<a;B++)_=h[C][B]+v*h[C+1][B],G&&(_+=D*h[C+2][B],h[C+2][B]=h[C+2][B]-_*M),h[C][B]-=_*E,h[C+1][B]=h[C+1][B]-_*T;for(I=0;I<=hr(g,C+3);I++)_=E*h[I][C]+T*h[I][C+1],G&&(_+=M*h[I][C+2],h[I][C+2]=h[I][C+2]-_*D),h[I][C]-=_,h[I][C+1]=h[I][C+1]-_*v;for(I=0;I<=c;I++)_=E*d[I][C]+T*d[I][C+1],G&&(_+=M*d[I][C+2],d[I][C+2]=d[I][C+2]-_*D),d[I][C]-=_,d[I][C+1]=d[I][C+1]-_*v}}}if(0!==b){for(g=a-1;0<=g;g--)if(_=e[g],v=o[g],0===v)for(R=g,h[g][g]=1,I=g-1;0<=I;I--){for(L=h[I][I]-_,D=0,B=R;B<=g;B++)D+=h[I][B]*h[B][g];if(0>o[I])M=L,S=D;else if(R=I,0===o[I]?h[I][g]=0===L?-D/(u*b):-D/L:(E=h[I][I+1],T=h[I+1][I],v=(e[I]-_)*(e[I]-_)+o[I]*o[I],Y=(E*S-M*D)/v,h[I][g]=Y,h[I+1][g]=mr(E)>mr(M)?(-D-L*Y)/E:(-S-T*Y)/M),Y=mr(h[I][g]),1<u*Y*Y)for(B=I;B<=g;B++)h[B][g]/=Y}else if(0>v)for(R=g-1,mr(h[g][g-1])>mr(h[g-1][g])?(h[g-1][g-1]=v/h[g][g-1],h[g-1][g]=-(h[g][g]-_)/h[g][g-1]):(O=fa(0,-h[g-1][g],h[g-1][g-1]-_,v),h[g-1][g-1]=O[0],h[g-1][g]=O[1]),h[g][g-1]=0,h[g][g]=1,I=g-2;0<=I;I--){for(F=0,X=0,B=R;B<=g;B++)F+=h[I][B]*h[B][g-1],X+=h[I][B]*h[B][g];if(L=h[I][I]-_,0>o[I])M=L,D=F,S=X;else if(R=I,0===o[I]?(O=fa(-F,-X,L,v),h[I][g-1]=O[0],h[I][g]=O[1]):(E=h[I][I+1],T=h[I+1][I],V=(e[I]-_)*(e[I]-_)+o[I]*o[I]-v*v,U=2*(e[I]-_)*v,0===V&&0===U&&(V=u*b*(mr(L)+mr(v)+mr(E)+mr(T)+mr(M))),O=fa(E*D-M*F+v*X,E*S-M*X-v*F,V,U),h[I][g-1]=O[0],h[I][g]=O[1],mr(E)>mr(M)+mr(v)?(h[I+1][g-1]=(-F-L*h[I][g-1]+v*h[I][g])/E,h[I+1][g]=(-X-L*h[I][g]-v*h[I][g-1])/E):(O=fa(-D-T*h[I][g-1],-S-T*h[I][g],M,v),h[I+1][g-1]=O[0],h[I+1][g]=O[1])),Y=dr(mr(h[I][g-1]),mr(h[I][g])),1<u*Y*Y)for(B=I;B<=g;B++)h[B][g-1]=h[B][g-1]/Y,h[B][g]/=Y}for(I=0;I<a;I++)if(0>I||I>c)for(B=I;B<a;B++)d[I][B]=h[I][B];for(B=a-1;0<=B;B--)for(I=0;I<=c;I++){for(M=0,C=0;C<=hr(B,c);C++)M+=d[I][C]*h[C][B];d[I][B]=M}}}function fa(e,t,i,a){var n,o;return mr(i)>mr(a)?(n=a/i,o=i+n*a,[(e+n*t)/o,(t-n*e)/o]):(n=i/a,o=a+n*i,[(n*e+t)/o,(n*t-e)/o])}function ba(e){var t=new xh(e,{autoTranspose:!0});if(1!==t.rank)return null;var i=nr(t.s[0]),a=t.U.map(e=>e[0]*i),n=t.V.map(e=>e[0]*i);return[a,n]}function _a(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.channels,n=t.bitDepth,o=t.normalize,s=void 0!==o&&o,r=t.divisor,l=void 0===r?1:r,d=t.border,h=void 0===d?'copy':d,g=t.algorithm,m=void 0===g?'auto':g,p=tc.createFrom(this,{bitDepth:n});if(a=ji(this,a,!0),'separable'!==m){var u=Ti(e);e=u.kernel}else if(!Array.isArray(e)||2!==e.length)throw new RangeError('separable convolution requires two arrays of numbers to represent the kernel');if('auto'===m){var f=ba(e);null===f?(9<e.length||9<e[0].length)&&4096>=this.width&&4096>=this.height?m='fft':m='direct':(m='separable',e=f)}var b,_;'separable'===m?(b=ur(e[0].length/2),_=ur(e[1].length/2)):(b=ur(e.length/2),_=ur(e[0].length/2));var w=p.isClamped,k=Array(this.height*this.width),v=void 0,D=void 0,S=void 0,M=void 0,P=void 0,I=void 0;for(M=0;M<a.length;M++){for(P=a[M],S=0;S<this.height;S++)for(D=0;D<this.width;D++)v=S*this.width+D,k[v]=this.data[v*this.channels+P];if('direct'===m)I=fh(k,e,{rows:this.height,cols:this.width,normalize:s,divisor:l});else if('separable'===m){if(I=Vi(k,e,this.width,this.height),s){l=0;for(var B=0;B<e[0].length;B++)for(var C=0;C<e[1].length;C++)l+=e[0][B]*e[1][C]}if(1!==l)for(var R=0;R<I.length;R++)I[R]/=l}else I=uh(k,e,{rows:this.height,cols:this.width,normalize:s,divisor:l});for(S=0;S<this.height;S++)for(D=0;D<this.width;D++)v=S*this.width+D,p.data[v*this.channels+P]=w?Ui(I[v],p):I[v]}if(this.alpha&&!a.includes(this.channels))for(D=this.components;D<this.data.length;D+=this.channels)p.data[D]=this.data[D];return'periodic'!==h&&p.setBorder({size:[_,b],algorithm:h}),p}function wa(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.direction,i=void 0===t?'xy':t,a=e.border,n=void 0===a?'copy':a,o=e.kernelX,s=e.kernelY,r=e.channels,l=e.bitDepth,d=void 0===l?this.bitDepth:l;switch(this.checkProcessable('gradientFilter',{bitDepth:[8,16]}),i){case'x':if(!o)throw new Error('kernelX option is missing');return _a.call(this,o,{channels:r,border:n,bitDepth:d});case'y':if(!s)throw new Error('kernelY option is missing');return _a.call(this,s,{channels:r,border:n,bitDepth:d});case'xy':{if(!o)throw new Error('kernelX option is missing');if(!s)throw new Error('kernelY option is missing');var h=_a.call(this,o,{channels:r,border:n,bitDepth:32}),g=_a.call(this,s,{channels:r,border:n,bitDepth:32});return h.hypotenuse(g,{bitDepth:d,channels:r})}default:throw new Error(`Unknown parameter direction: ${i}`);}}function xa(e){return wa.call(this,Object.assign({},e,{kernelX:lh,kernelY:dh}))}function ka(e){return wa.call(this,Object.assign({},e,{kernelX:hh,kernelY:gh}))}function ya(e,t){e=e||0;for(var a=Array(e),o=0;o<e;o++)a[o]=t;return a}function va(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.algorithm,i=void 0===t?'range':t,n=e.channels,a=e.min,o=void 0===a?this.min:a,s=e.max,r=void 0===s?this.max:s;switch(this.checkProcessable('level',{bitDepth:[8,16,32]}),n=ji(this,{channels:n}),n.length!==this.channel&&(Array.isArray(o)&&o.length===this.channels&&(o=o.filter((e,t)=>n.includes(t))),Array.isArray(r)&&r.length===this.channels&&(r=r.filter((e,t)=>n.includes(t)))),i){case'range':0>o&&(o=0),r>this.maxValue&&(r=this.maxValue),Array.isArray(o)||(o=Th(n.length,o)),Array.isArray(r)||(r=Th(n.length,r)),Da(this,o,r,n);break;default:throw new Error(`level: algorithm not implement: ${i}`);}return this}function Da(e,t,a,n){for(var o=1e-5,s=Array(n.length),r=0;r<n.length;r++)s[r]=0===t[r]&&a[r]===e.maxValue?0:a[r]===t[r]?0:(e.maxValue+1-o)/(a[r]-t[r]),t[r]+=(.5-o/2)/s[r];for(var l=0,d;l<n.length;l++)if(d=n[l],0!==s[l])for(var h=0;h<e.data.length;h+=e.channels)e.data[h+d]=hr(dr(0,0|(e.data[h+d]-t[l])*s[l]+.5),e.maxValue)}function Sa(e){if(!isNaN(e)){if(0>=e)throw new Error('checkNumberArray: the value must be greater than 0');return e}if(e instanceof tc)return e.data;if(!Xh(e))throw new Error('checkNumberArray: the value should be either a number, array or Image');return e}function Ma(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.channels;if(this.checkProcessable('add',{bitDepth:[8,16]}),a=ji(this,{channels:a}),e=Sa(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=hr(this.maxValue,this.data[s+o]+e>>0)}else{if(this.data.length!==e.length)throw new Error('add: the data size is different');for(var r=0,l;r<a.length;r++){l=a[r];for(var d=0;d<this.data.length;d+=this.channels)this.data[d+l]=dr(0,hr(this.maxValue,this.data[d+l]+e[d+l]>>0))}}return this}function ja(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.channels;if(this.checkProcessable('subtract',{bitDepth:[8,16]}),a=ji(this,{channels:a}),e=Sa(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=dr(0,this.data[s+o]-e>>0)}else{if(this.data.length!==e.length)throw new Error('substract: the data size is different');for(var r=0,l;r<a.length;r++){l=a[r];for(var d=0;d<this.data.length;d+=this.channels)this.data[d+l]=dr(0,hr(this.maxValue,this.data[d+l]-e[d+l]>>0))}}return this}function Pa(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.bitDepth,n=void 0===a?this.bitDepth:a,o=t.channels,s=t.absolute;if(this.checkProcessable('substractImage',{bitDepth:[8,16]}),this.width!==e.width||this.height!==e.height)throw new Error('substractImage: both images must have the same size');if(this.alpha!==e.alpha||this.bitDepth!==e.bitDepth)throw new Error('substractImage: both images must have the same alpha and bitDepth');if(this.channels!==e.channels)throw new Error('substractImage: both images must have the same number of channels');var r=tc.createFrom(this,{bitDepth:n});o=ji(this,{channels:o});for(var l=0,d;l<o.length;l++){d=o[l];for(var h=d,g;h<this.data.length;h+=this.channels)g=this.data[h]-e.data[h],r.data[h]=void 0!==s&&s?mr(g):dr(g,0)}return r}function Ia(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.bitDepth,n=void 0===a?this.bitDepth:a,o=t.channels;if(this.checkProcessable('hypotenuse',{bitDepth:[8,16,32]}),this.width!==e.width||this.height!==e.height)throw new Error('hypotenuse: both images must have the same size');if(this.alpha!==e.alpha||this.bitDepth!==e.bitDepth)throw new Error('hypotenuse: both images must have the same alpha and bitDepth');if(this.channels!==e.channels)throw new Error('hypotenuse: both images must have the same number of channels');var s=tc.createFrom(this,{bitDepth:n});o=ji(this,{channels:o});for(var r=s.isClamped,l=0,d;l<o.length;l++){d=o[l];for(var h=d,g;h<this.data.length;h+=this.channels)g=Math.hypot(this.data[h],e.data[h]),s.data[h]=r?hr(dr(ar(g),0),s.maxValue):g}return s}function Ba(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.channels;if(this.checkProcessable('multiply',{bitDepth:[8,16]}),0>=e)throw new Error('multiply: the value must be greater than 0');if(a=ji(this,{channels:a}),e=Sa(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=hr(this.maxValue,this.data[s+o]*e>>0)}else{if(this.data.length!==e.length)throw new Error('multiply: the data size is different');for(var r=0,l;r<a.length;r++){l=a[r];for(var d=0;d<this.data.length;d+=this.channels)this.data[d+l]=dr(0,hr(this.maxValue,this.data[d+l]*e[d+l]>>0))}}return this}function Ca(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.channels;if(this.checkProcessable('divide',{bitDepth:[8,16]}),a=ji(this,{channels:a}),e=Sa(e),!isNaN(e))for(var n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<this.data.length;s+=this.channels)this.data[s+o]=hr(this.maxValue,this.data[s+o]/e>>0)}else{if(this.data.length!==e.length)throw new Error('divide: the: the data size is different');for(var r=0,l;r<a.length;r++){l=a[r];for(var d=0;d<this.data.length;d+=this.channels)this.data[d+l]=dr(0,hr(this.maxValue,this.data[d+l]/e[d+l]>>0))}}return this}function Ra(e,t){for(var a=0,n=0;n<e.length;n++)a+=(e[n]-t[n])*(e[n]-t[n]);return a}function Aa(e,t){return nr(Ra(e,t))}function za(e,t,a){for(var n=new hg(e,t,a),o=Array(this.size),s=0;s<this.width;s++)for(var r=0;r<this.height;r++)o[r*this.width+s]=[s,r];for(var l=n.predict(o),d=tc.createFrom(this),h=0;h<this.size;h++)d.data[h]=hr(this.maxValue,dr(0,l[h][0]));return d}function Ya(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kernel,a=void 0===t?[[1,1,1],[1,1,1],[1,1,1]]:t,n=e.iterations,o=void 0===n?1:n;if(this.checkProcessable('dilate',{bitDepth:[1,8,16],components:1,alpha:0}),0==a.columns%2||0==a.rows%2)throw new TypeError('dilate: The number of rows and columns of the kernel must be odd');var s=!0;outer:for(var r of a)for(var l of r)if(1!==l){s=!1;break outer}for(var d=this,h=0;h<o;h++)if(1===this.bitDepth){if(s){var g=d.clone();d=Fa(d,g,a.length,a[0].length)}else{var m=tc.createFrom(d);d=Ta(d,m,a)}}else if(s){var c=tc.createFrom(d);d=Ea(d,c,a.length,a[0].length)}else{var p=tc.createFrom(d);d=La(d,p,a)}return d}function La(e,t,a){for(var n=a.length,o=a[0].length,s=0;s<e.height;s++)for(var r=0,l;r<e.width;r++){l=0;for(var d=0;d<o;d++)for(var h=0;h<n;h++)if(1===a[h][d]){var g=h-(n-1)/2+r,i=d-(o-1)/2+s;if(!(0>g||0>i||g>=e.width||i>=e.height)){var m=e.getValueXY(g,i,0);m>l&&(l=m)}}t.setValueXY(r,s,0,l)}return t}function Ea(e,t,a,n){for(var o=(a-1)/2,s=(n-1)/2,r=[],l=0;l<e.width;l++)r.push(0);for(var d=0;d<e.height;d++){for(var g=0,m;g<e.width;g++){m=0;for(var c=dr(0,d-s),p;c<hr(e.height,d+s+1);c++)p=e.getValueXY(g,c,0),p>m&&(m=p);r[g]=m}for(var u=0,f;u<e.width;u++){f=0;for(var b=dr(0,u-o);b<hr(e.width,u+o+1);b++)r[b]>f&&(f=r[b]);t.setValueXY(u,d,0,f)}}return t}function Ta(e,t,a){for(var n=a.length,o=a[0].length,s=0;s<e.height;s++)for(var r=0,l;r<e.width;r++){l=0;intLoop:for(var d=0;d<o;d++)for(var h=0;h<n;h++)if(1===a[h][d]){var g=h-(n-1)/2+r,i=d-(o-1)/2+s;if(!(0>i||0>g||g>=e.width||i>=e.height)){var m=e.getBitXY(g,i);if(1===m){l=1;break intLoop}}}1==l&&t.setBitXY(r,s)}return t}function Fa(e,t,a,n){for(var o=(a-1)/2,s=(n-1)/2,r=[],l=0;l<e.width;l++)r.push(1);for(var d=0;d<e.height;d++){for(var g=0;g<e.width;g++){r[g]=0;for(var m=dr(0,d-s);m<hr(e.height,d+s+1);m++)if(1===e.getBitXY(g,m)){r[g]=1;break}}for(var c=0;c<e.width;c++)if(1!==t.getBitXY(c,d))for(var p=dr(0,c-o);p<hr(e.width,c+o+1);p++)if(1===r[p]){t.setBitXY(c,d);break}}return t}function Xa(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kernel,a=void 0===t?[[1,1,1],[1,1,1],[1,1,1]]:t,n=e.iterations,o=void 0===n?1:n;if(this.checkProcessable('erode',{bitDepth:[1,8,16],components:1,alpha:0}),0==a.columns%2||0==a.rows%2)throw new TypeError('erode: The number of rows and columns of the kernel must be odd');var s=!0;outer:for(var r of a)for(var l of r)if(1!==l){s=!1;break outer}for(var d=this,h=0;h<o;h++)if(1===this.bitDepth){if(s){var g=d.clone();d=Oa(d,g,a.length,a[0].length)}else{var m=tc.createFrom(d);d=Ga(d,m,a)}}else if(s){var c=tc.createFrom(d);d=Ua(d,c,a.length,a[0].length)}else{var p=tc.createFrom(d);d=Va(d,p,a)}return d}function Va(e,t,a){for(var n=a.length,o=a[0].length,s=0;s<e.height;s++)for(var r=0,l;r<e.width;r++){l=e.maxValue;for(var d=0;d<o;d++)for(var h=0;h<n;h++)if(1===a[h][d]){var g=h-(n-1)/2+r,i=d-(o-1)/2+s;if(!(0>g||0>i||g>=e.width||i>=e.height)){var m=e.getValueXY(g,i,0);m<l&&(l=m)}}t.setValueXY(r,s,0,l)}return t}function Ua(e,t,a,n){for(var o=(a-1)/2,s=(n-1)/2,r=[],l=0;l<e.width;l++)r.push(0);for(var d=0;d<e.height;d++){for(var g=0,m;g<e.width;g++){m=e.maxValue;for(var c=dr(0,d-s),p;c<hr(e.height,d+s+1);c++)p=e.getValueXY(g,c,0),p<m&&(m=p);r[g]=m}for(var u=0,f;u<e.width;u++){f=e.maxValue;for(var b=dr(0,u-o);b<hr(e.width,u+o+1);b++)r[b]<f&&(f=r[b]);t.setValueXY(u,d,0,f)}}return t}function Ga(e,t,a){for(var n=a.length,o=a[0].length,s=0;s<e.height;s++)for(var r=0,l;r<e.width;r++){l=1;intLoop:for(var d=0;d<o;d++)for(var h=0;h<n;h++)if(1===a[h][d]){var g=h-(n-1)/2+r,i=d-(o-1)/2+s;if(!(0>i||0>g||g>=e.width||i>=e.height)){var m=e.getBitXY(g,i);if(0===m){l=0;break intLoop}}}1==l&&t.setBitXY(r,s)}return t}function Oa(e,t,a,n){for(var o=(a-1)/2,s=(n-1)/2,r=[],l=0;l<e.width;l++)r.push(0);for(var d=0;d<e.height;d++){for(var g=0;g<e.width;g++){r[g]=1;for(var m=dr(0,d-s);m<hr(e.height,d+s+1);m++)if(0===e.getBitXY(g,m)){r[g]=0;break}}for(var c=0;c<e.width;c++)if(0!==t.getBitXY(c,d))for(var p=dr(0,c-o);p<hr(e.width,c+o+1);p++)if(0===r[p]){t.clearBitXY(c,d);break}}return t}function Na(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kernel,a=void 0===t?[[1,1,1],[1,1,1],[1,1,1]]:t,n=e.iterations,o=void 0===n?1:n;if(this.checkProcessable('open',{bitDepth:[8,16],components:1,alpha:0}),0==a.columns%2||0==a.rows%2)throw new TypeError('open: The number of rows and columns of the kernel must be odd');for(var s=this,r=0;r<o;r++)s=s.erode({kernel:a}),s=s.dilate({kernel:a});return s}function Ha(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kernel,a=void 0===t?[[1,1,1],[1,1,1],[1,1,1]]:t,n=e.iterations,o=void 0===n?1:n;if(this.checkProcessable('close',{bitDepth:[1,8,16],components:1,alpha:0}),0==a.columns%2||0==a.rows%2)throw new TypeError('close: The number of rows and columns of the kernel must be odd');for(var s=this,r=0;r<o;r++)s=s.dilate({kernel:a}).erode({kernel:a});return s}function qa(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kernel,a=void 0===t?[[1,1,1],[1,1,1],[1,1,1]]:t,n=e.iterations,o=void 0===n?1:n;if(this.checkProcessable('topHat',{bitDepth:[8,16],components:1,alpha:0}),0==a.columns%2||0==a.rows%2)throw new TypeError('topHat: The number of rows and columns of the kernel must be odd');for(var s=this,r=0,l;r<o;r++)l=s.open({kernel:a}),s=l.subtractImage(s,{absolute:!0});return s}function Wa(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kernel,a=void 0===t?[[1,1,1],[1,1,1],[1,1,1]]:t,n=e.iterations,o=void 0===n?1:n;if(this.checkProcessable('blackHat',{bitDepth:[8,16],components:1,alpha:0}),0==a.columns%2||0==a.rows%2)throw new TypeError('blackHat: The number of rows and columns of the kernel must be odd');for(var s=this,r=0,l;r<o;r++)l=s.close({kernel:a}),s=l.subtractImage(s,{absolute:!0});return s}function Za(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kernel,a=void 0===t?[[1,1,1],[1,1,1],[1,1,1]]:t,n=e.iterations,o=void 0===n?1:n;if(this.checkProcessable('morphologicalGradient',{bitDepth:[8,16],components:1,alpha:0}),0==a.columns%2||0==a.rows%2)throw new TypeError('morphologicalGradient: The number of rows and columns of the kernel must be odd');for(var s=this,r=0;r<o;r++){var l=s.dilate({kernel:a}),d=s.erode({kernel:a});s=l.subtractImage(d,{absolute:!0})}return s}function Ka(e){for(var t=0,a=0,n=0,o=0,s=e[0][0],r=0,l=1;l<e.length;l++)e[l][0]<s&&(s=e[l][0],r=l);for(var d=e[(r+1)%e.length][0],h=(r+1)%e.length,g=1;g<e.length;g++)e[g][0]<d&&g!==r&&(d=e[g][0],h=g);return e[h][1]<e[r][1]?(t=e[h],o=e[r],r===(h+1)%4?(a=e[(h+2)%4],n=e[(h+3)%4]):(a=e[(h+1)%4],n=e[(h+2)%4])):(o=e[h],t=e[r],h===(r+1)%4?(a=e[(r+2)%4],n=e[(r+3)%4]):(a=e[(r+1)%4],n=e[(r+2)%4])),[t,a,n,o]}function Ja(e,t){return nr(cr(e[0]-t[0],2)+cr(e[1]-t[1],2))}function Qa(e,t){var i=[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];return i}function $a(e,t){var i=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];return i}function en(e,t,i,a,n,o){var s=dr(Ja(e,t),Ja(a,i)),r=dr(Ja(e,a),Ja(t,i)),l=0,d=0,h=pr(n/2),g=pr(o/2),m=s/r,c=[e[0],e[1],1],p=[t[0],t[1],1],u=[a[0],a[1],1],b=[i[0],i[1],1],_=$a(Qa(c,b),u)/$a(Qa(p,b),u),w=$a(Qa(c,b),p)/$a(Qa(u,b),p),x=[_*p[0]-c[0],_*p[1]-c[1],_*p[2]-c[2]],k=[w*u[0]-c[0],w*u[1]-c[1],w*u[2]-c[2]],y=x[0],v=x[1],D=x[2],S=k[0],M=k[1],j=k[2],P=1/(D*j)*(y*S-(y*j+D*S)*h+D*j*h*h+(v*M-(v*j+D*M)*g+D*j*g*g));P=0<=P?nr(P):nr(-P);var I=new Ch([[P,0,h],[0,P,g],[0,0,1]]),B=I.transpose(),C=ra(B),R=ra(I),A=Ch.rowVector(x),z=Ch.rowVector(k),Y=nr($a(A.mmul(C).mmul(R).to1DArray(),x)/$a(z.mmul(C).mmul(R).to1DArray(),k));return 0===Y||0==m?(l=pr(s),d=pr(r)):Y<m?(l=pr(s),d=pr(l/Y)):(d=pr(r),l=pr(Y*d)),[l,d]}function tn(t,i,n,a,o,s,r,e,l,d,h,g){return h.getValueXY(ur((n*t+a*i+o)/(l*t+d*i+1)),ur((s*t+r*i+e)/(l*t+d*i+1)),g)}function an(t){var n=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},o=n.calculateRatio;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`);var s=pm(t,4),r=s[0],l=s[1],m=s[2],p=s[3],u=Ka([r,l,m,p]),_=pm(u,4),w=_[0],x=_[1],k=_[2],y=_[3],v=void 0,M=void 0;if(!(o!==void 0)||o){var P=en(w,x,k,y,this.width,this.height),I=pm(P,2);v=I[0],M=I[1]}else v=pr(dr(Ja(w,x),Ja(y,k))),M=pr(dr(Ja(w,y),Ja(x,k)));for(var B=tc.createFrom(this,{width:v,height:M}),C=pm(w,2),R=C[0],A=C[1],z=pm(x,2),Y=z[0],L=z[1],E=pm(k,2),F=E[0],X=E[1],V=pm(y,2),U=V[0],G=V[1],O=v-1,N=M-1,H=v-1,q=M-1,W=new Ch([[0,0,1,0,0,0,-0*R,-0*R],[0,O,1,0,0,0,-0*Y,-O*Y],[N,H,1,0,0,0,-N*F,-0*F],[q,0,1,0,0,0,-q*U,-0*U],[0,0,0,0,0,1,-0*A,-0*A],[0,0,0,0,O,1,-0*L,-O*L],[0,0,0,N,H,1,-N*X,-H*X],[0,0,0,q,0,1,-q*G,-0*G]]),S=Ch.columnVector([R,Y,F,U,A,L,X,G]),D=new xh(W),Z=D.solve(S),T=Z.to1DArray(),K=pm(T,8),J=K[0],a=K[1],b=K[2],c=K[3],d=K[4],e=K[5],f=K[6],g=K[7],h=new Ch(M,v),Q=0;Q<this.channels;Q++){for(var $=0;$<M;$++)for(var ee=0;ee<v;ee++)h.set($,ee,tn($,ee,J,a,b,c,d,e,f,g,this,Q));B.setMatrix(h,{channel:Q})}return B}function nn(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.x,a=void 0===t?0:t,n=e.y,o=void 0===n?0:n,s=e.width,r=void 0===s?this.width-a:s,l=e.height,d=void 0===l?this.height-o:l;if(this.checkProcessable('max',{bitDepth:[8,16]}),a=ar(a),o=ar(o),r=ar(r),d=ar(d),a>this.width-1||o>this.height-1)throw new RangeError(`crop: origin (x:${a}, y:${o}) out of range (${this.width-1}; ${this.height-1})`);if(0>=r||0>=d)throw new RangeError(`crop: width and height (width:${r}; height:${d}) must be positive numbers`);if(0>a||0>o)throw new RangeError(`crop: x and y (x:${a}, y:${o}) must be positive numbers`);if(r>this.width-a||d>this.height-o)throw new RangeError(`crop: (x: ${a}, y:${o}, width:${r}, height:${d}) size is out of range`);for(var h=tc.createFrom(this,{width:r,height:d,position:[a,o]}),g=r*this.channels,m=o+d,c=0,p=a*this.channels,u=o;u<m;u++)for(var f=u*this.width*this.channels+p,b=f+g;f<b;f++)h.data[c++]=this.data[f];return h}function on(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{};this.checkProcessable('cropAlpha',{alpha:1});var t=e.threshold,i=t===void 0?this.maxValue:t,a=sn(this,i,this.components);if(-1===a)throw new Error('Could not find new dimensions. Threshold may be too high.');var n=rn(this,i,this.components,a),o=ln(this,i,this.components,a),s=dn(this,i,this.components,a,n,o);return this.crop({x:a,y:n,width:s-a+1,height:o-n+1})}function sn(e,t,i){for(var a=0;a<e.width;a++)for(var n=0;n<e.height;n++)if(e.getValueXY(a,n,i)>=t)return a;return-1}function rn(e,t,i,a){for(var n=0;n<e.height;n++)for(var o=a;o<e.width;o++)if(e.getValueXY(o,n,i)>=t)return n;return-1}function ln(e,t,i,a){for(var n=e.height-1;0<=n;n--)for(var o=a;o<e.width;o++)if(e.getValueXY(o,n,i)>=t)return n;return-1}function dn(e,t,i,a,n,o){for(var s=e.width-1;s>=a;s--)for(var r=n;r<=o;r++)if(e.getValueXY(s,r,i)>=t)return s;return-1}function hn(e){if('string'==typeof e){var t=e[e.length-1];e=parseFloat(e),'%'===t&&(e/=100)}return e}function gn(e,t){if(!t)throw Error('getThreshold : the maxValue should be specified');if('string'==typeof e){var i=e[e.length-1];if('%'!==i)throw Error('getThreshold : if the value is a string it must finish by %');return parseFloat(e)/100*t}if('number'==typeof e)return 1>e?e*t:e;throw Error('getThreshold : the value is not valid')}function mn(e,t,i){e=hn(e);var a=ar(e*t),n=ar(e*i);return 0>=a&&(a=1),0>=n&&(n=1),{width:a,height:n}}function cn(e,t){if(0>t||t>=e.height)throw new RangeError(`row must be included between 0 and ${e.height-1}. Current value: ${t}`)}function pn(e,t){if(0>t||t>=e.width)throw new RangeError(`column must be included between 0 and ${e.width-1}. Current value: ${t}`)}function un(e,t){if(0>t||t>=e.channels)throw new RangeError(`channel must be included between 0 and ${e.channels-1}. Current value: ${t}`)}function fn(e){if('string'!=typeof e)throw new TypeError('interpolation must be a string');if(e=e.toLowerCase(),!um[e])throw new RangeError(`invalid interpolation algorithm: ${e}`);return um[e]}function bn(e,t,a){var n=this.width/t,o=this.height/a;if(1<this.bitDepth)for(var s=0,r;s<t;s++){r=ur((s+.5)*n);for(var l=0,d;l<a;l++){d=ur((l+.5)*o);for(var g=0;g<this.channels;g++)e.setValueXY(s,l,g,this.getValueXY(r,d,g))}}else for(var m=0,p;m<t;m++){p=ur((m+.5)*n);for(var u=0,f;u<a;u++)f=ur((u+.5)*o),this.getBitXY(p,f)&&e.setBitXY(m,u)}}function _n(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.factor,i=void 0===t?1:t,a=e.interpolation,n=void 0===a?um.nearestneighbor:a,o=e.preserveAspectRatio,s=void 0===o||o,r=fn(n),l=e.width,d=e.height;l||(d&&s?l=ar(d*(this.width/this.height)):l=this.width),d||(s?d=ar(l*(this.height/this.width)):d=this.height);var h=mn(i,l,d);if(l=h.width,d=h.height,l===this.width&&d===this.height){var g=this.clone();return g.position=[0,0],g}var m=ar((this.width-l)/2),c=ar((this.height-d)/2),p=tc.createFrom(this,{width:l,height:d,position:[m,c]});switch(r){case um.nearestneighbor:bn.call(this,p,l,d);break;default:throw new Error(`unsupported resize interpolation: ${r}`);}return p}function wn(){this.checkProcessable('hsv',{bitDepth:[8,16],alpha:[0,1],colorModel:['RGB']});for(var e=tc.createFrom(this,{colorModel:'HSV'}),t=0,a=this.data,n=0;n<a.length;n+=this.channels){var o=a[n],s=a[n+1],r=a[n+2],l=hr(o,s,r),d=dr(o,s,r),h=d-l,g=0,m=0===d?0:h/d;if(d!==l){switch(d){case o:g=(s-r)/h+(s<r?6:0);break;case s:g=(r-o)/h+2;break;case r:g=(o-s)/h+4;break;default:throw new Error('unreachable');}g/=6}e.data[t++]=g*this.maxValue,e.data[t++]=m*this.maxValue,e.data[t++]=d,this.alpha&&(e.data[t++]=a[n+3])}return e}function xn(){this.checkProcessable('hsl',{bitDepth:[8,16],alpha:[0,1],colorModel:['RGB']});for(var e=tc.createFrom(this,{colorModel:'HSL'}),t=ur(this.maxValue/2),a=0,n=this.data,o=0;o<n.length;o+=this.channels){var s=n[o],r=n[o+1],l=n[o+2],d=dr(s,r,l),h=hr(s,r,l),g=0,m=0,c=(d+h)/2;if(d!==h){var p=d-h;switch(m=c>t?p/(2-d-h):p/(d+h),d){case s:g=(r-l)/p+(r<l?6:0);break;case r:g=(l-s)/p+2;break;case l:g=(s-r)/p+4;break;default:throw new Error('unreachable');}g/=6}e.data[a++]=g*this.maxValue,e.data[a++]=m*this.maxValue,e.data[a++]=c,this.alpha&&(e.data[a++]=n[o+3])}return e}function kn(){this.checkProcessable('cmyk',{bitDepth:[8,16],alpha:[0,1],colorModel:['RGB']});for(var e=tc.createFrom(this,{components:4,colorModel:'CMYK'}),t=0,a=this.data,n=0;n<a.length;n+=this.channels){var o=a[n],s=a[n+1],r=a[n+2],l=hr(this.maxValue-o,this.maxValue-s,this.maxValue-r),d=(this.maxValue-o-l)/(1-l/this.maxValue),h=(this.maxValue-s-l)/(1-l/this.maxValue),g=(this.maxValue-r-l)/(1-l/this.maxValue);e.data[t++]=ar(d),e.data[t++]=ar(h),e.data[t++]=ar(g),e.data[t++]=ar(l),this.alpha&&(e.data[t++]=a[n+3])}return e}function yn(){return new tc(this.width,this.height,this.getRGBAData(),{kind:'RGBA',parent:this})}function vn(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.algorithm,a=t===void 0?'luma709':t,n=e.keepAlpha,o=n!==void 0&&n,s=e.mergeAlpha,r=!(s!==void 0)||s;this.checkProcessable('grey',{bitDepth:[8,16],alpha:[0,1]}),1===this.components&&(a='red'),o&=this.alpha,r&=this.alpha,o&&(r=!1);var l=ui(this,e,{components:1,alpha:o,colorModel:'GREY'}),d=fm[a.toLowerCase()];if(!d)throw new Error(`unsupported grey algorithm: ${a}`);for(var h=0,g=0;g<this.data.length;g+=this.channels)r?l.data[h++]=Ui(d(this.data,g,this)*this.data[g+this.components]/this.maxValue,this):(l.data[h++]=Ui(d(this.data,g,this),this),l.alpha&&(l.data[h++]=this.data[g+this.components]));return l}function Dn(e){for(var t=e.slice(),a=0;!Sn(t);){for(var n=0,o=0,s=t[0],r=0;r<e.length-1;r++)n=o,o=s,s=t[r+1],t[r]=(n+o+s)/3;if(t[e.length-1]=(o+s)/3,a++,1e4<a)throw new Error('Intermodes Threshold not found after 10000 iterations')}for(var l=0,d=1;d<e.length-1;d++)t[d-1]<t[d]&&t[d+1]<t[d]&&(l+=d);return ur(l/2)}function Sn(e){for(var t=!1,i=0,a=1;a<e.length-1;a++)if(e[a-1]<e[a]&&e[a+1]<e[a]&&(i++,2<i))return!1;return 2==i&&(t=!0),t}function Mn(e){for(var t=void 0,a=void 0,n=void 0,o=void 0,s=0,r=1;r<e.length;r++)if(0<e[r]){s=r+1;break}for(;;){t=0,n=0;for(var d=0;d<s;d++)n+=e[d],t+=e[d]*d;o=0,a=0;for(var m=s+1;m<e.length;m++)a+=e[m],o+=e[m]*m;if(0<n&&0<a&&(t/=n,o/=a,s===ar((t+o)/2)))break;if(s++,s>e.length-2)throw new Error('Threshold not found')}return s}function jn(e,t){for(var a=0,n=0;n<e.length;n++)a+=n*e[n];return ur(a/t)}function Pn(e,t){for(var i=void 0,a=-2,n=void 0,o=void 0,s=void 0,r=void 0,l=void 0,d=void 0,h=void 0,g=void 0,m=void 0,c=void 0,u=void 0,f=0,b=0;b<e.length;b++)f+=b*e[b];for(f/=t,i=f;i!==a;){var _=In(e,i),w=In(e,e.length-1),x=Bn(e,i),k=Bn(e,e.length-1),y=Cn(e,i),v=Cn(e,e.length-1);if(n=x/_,o=(k-x)/(w-_),s=_/w,r=(w-_)/w,l=y/_-n*n,d=(v-y)/(w-_)-o*o,h=1/l-1/d,g=n/l-o/d,m=n*n/l-o*o/d+Math.log10(l*(r*r)/(d*(s*s))),c=g*g-h*m,0>c)return i;a=i,u=(g+nr(c))/h,i=isNaN(u)?a:ur(u)}return i}function In(e,t){for(var a=0,n=0;n<=t;n++)a+=e[n];return a}function Bn(e,t){for(var a=0,n=0;n<=t;n++)a+=n*e[n];return a}function Cn(e,t){for(var a=0,n=0;n<=t;n++)a+=n*n*e[n];return a}function Rn(e){if(2>e.length)return 0;for(var t=0,a=-1,n=-1,o=Array(e.length),s=0;s<e.length;s++)o[s]=e[s],0<e[s]&&(n=s);for(;!Yn(o);)if(o=An(o),t++,1e4<t)return a;return a=zn(o,n),a}function An(e){for(var t=Array(e.length),a=1;a<e.length-1;a++)t[a]=(e[a-1]+e[a]+e[a+1])/3;return t[0]=(e[0]+e[1])/3,t[e.length-1]=(e[e.length-2]+e[e.length-1])/3,t}function zn(e,t){for(var a=void 0,n=1;n<t;n++)if(e[n-1]>e[n]&&e[n+1]>=e[n]){a=n;break}return a}function Yn(e){for(var t=e.length,i=!1,a=0,n=1;n<t-1;n++)if(e[n-1]<e[n]&&e[n+1]<e[n]&&(a++,2<a))return!1;return 2==a&&(i=!0),i}function Ln(e,t){for(var a=0,n=0,o=0,s=0,r=void 0,l=void 0,d=void 0,h=void 0,g=void 0,m=void 0,c=-1,p=e.length,u=Array(p),f=0;f<p;f++)u[f]=e[f]/t;for(var b=0;b<p;b++)a+=b*u[b],n+=b*b*u[b],o+=b*b*b*u[b];l=1*n-a*a,d=(-n*n+a*o)/l,h=(1*-o+n*a)/l,g=.5*(-h-nr(h*h-4*d)),m=.5*(-h+nr(h*h-4*d)),r=(m-a)/(m-g);for(var _=0;_<p;_++)if(s+=u[_],s>r){c=_;break}return c}function En(e,t){for(var a=0,n=0,o=0,s=0,r=0,l=0;l<e.length;l++)r+=l*e[l];for(var d=0;d<e.length;d++){n+=e[d];var h=t-n;if(0!=n&&0!=h){a+=d*e[d];var g=(r-a)/h,m=n*h*(a/n-g)*(a/n-g);m>=o&&(s=d,o=m)}}return s}function Tn(e){for(var t=-1,a=Array(e.length),n=Fn(e,e.length-1),o=1,s=0;s<e.length;s++)a[s]=mr(Fn(e,s)/n-.5),a[s]<o&&(o=a[s],t=s);return t}function Fn(e,t){for(var a=0,n=0;n<=t;n++)a+=e[n];return a}function Xn(e){for(var t=0,a=0,n=0,o=0,s=0;s<e.length;s++)if(0<e[s]){t=s;break}0<t&&t--;for(var r=e.length-1;0<r;r--)if(0<e[r]){o=r;break}o<e.length-1&&o++;for(var l=0;l<e.length;l++)e[l]>a&&(n=l,a=e[l]);var h=!1;if(n-t<o-n){h=!0;for(var g=0,m=e.length-1,c;g<m;)c=e[g],e[g]=e[m],e[m]=c,g++,m--;t=e.length-1-o,n=e.length-1-n}if(t===n)return t;var p,u,f;p=e[n],u=t-n,f=nr(p*p+u*u),p/=f,u/=f,f=p*t+u*e[t];for(var b=t,_=0,w=t+1,x;w<=n;w++)x=p*w+u*e[w]-f,x>_&&(b=w,_=x);if(b--,h){for(var k=0,y=e.length-1,v;k<y;)v=e[k],e[k]=e[y],e[y]=v,k++,y--;return e.length-1-b}return b}function Vn(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.algorithm,i=t===void 0?wm.otsu:t;this.checkProcessable('getThreshold',{components:1,bitDepth:[8,16]});var a=_m[i.toLowerCase()];if(a){var n=this.getHistogram();return a(n,this.size)}throw new Error(`unknown thresholding algorithm: ${i}`)}function Un(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.algorithm,a=t===void 0?'threshold':t,n=e.threshold,o=n===void 0?.5:n,s=e.useAlpha,r=e.invert,l=r!==void 0&&r;this.checkProcessable('mask',{components:1,bitDepth:[8,16]}),o='threshold'===a?gn(o,this.maxValue):Vn.call(this,e);var d=new tc(this.width,this.height,{kind:'BINARY',parent:this}),h=0;if(this.alpha&&(!(s!==void 0)||s))for(var g=0,m;g<this.data.length;g+=this.channels)m=this.data[g]+(this.maxValue-this.data[g])*(this.maxValue-this.data[g+1])/this.maxValue,(l&&m<=o||!l&&m>=o)&&d.setBit(h),h++;else for(var c=0;c<this.data.length;c+=this.channels)(l&&this.data[c]<=o||!l&&this.data[c]>=o)&&d.setBit(h),h++;return d}function Gn(e,t,a,n){for(var o=e.width,s=e.height,r=t.width,l=e.channels,d=0;d<o;d++)for(var h=0;h<s;h++)for(var g=0;g<l;g++){var m=(h*o+d)*l+g,c=((n+h)*r+a+d)*l+g;t.data[c]=e.data[m]}}function On(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.size,a=void 0===t?0:t,n=e.algorithm,o=void 0===n?'copy':n,s=e.color;if(this.checkProcessable('pad',{bitDepth:[8,16]}),'set'===o){if(s.length!==this.channels)throw new Error(`pad: the color array must have the same length as the number of channels. Here: ${this.channels}`);for(var r=0;r<s.length;r++)0===s[r]&&(s[r]=.001)}else s=Th(this.channels,null);Array.isArray(a)||(a=[a,a]);var l=this.width+2*a[0],d=this.height+2*a[1],h=this.channels,g=tc.createFrom(this,{width:l,height:d});Gn(this,g,a[0],a[1]);for(var m=a[0];m<l-a[0];m++)for(var c=0,p;c<h;c++){p=s[c]||g.data[(a[1]*l+m)*h+c];for(var u=0;u<a[1];u++)g.data[(u*l+m)*h+c]=p;p=s[c]||g.data[((d-a[1]-1)*l+m)*h+c];for(var f=d-a[1];f<d;f++)g.data[(f*l+m)*h+c]=p}for(var b=0;b<d;b++)for(var _=0,w;_<h;_++){w=s[_]||g.data[(b*l+a[0])*h+_];for(var x=0;x<a[0];x++)g.data[(b*l+x)*h+_]=w;w=s[_]||g.data[(b*l+l-a[0]-1)*h+_];for(var y=l-a[0];y<l;y++)g.data[(b*l+y)*h+_]=w}return g}function Nn(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:8;if(this.checkProcessable('colorDepth',{bitDepth:[1,8,16]}),![8,16].includes(e))throw Error('You need to specify the new colorDepth as 8 or 16');if(this.bitDepth===e)return this.clone();var t=tc.createFrom(this,{bitDepth:e});switch(e){case 8:if(1===this.bitDepth)for(var a=0;a<this.size;a++)this.getBit(a)&&(t.data[a]=255);else for(var n=0;n<this.data.length;n++)t.data[n]=this.data[n]>>8;break;case 16:if(1===this.bitDepth)for(var o=0;o<this.size;o++)this.getBit(o)&&(t.data[o]=65535);else for(var s=0;s<this.data.length;s++)t.data[s]=this.data[s]<<8|this.data[s];break;default:throw new Error('colorDepth conversion unexpected case');}return t}function Hn(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},i=t.interpolation,a=i===void 0?um.nearestneighbor:i,n=t.width,o=n===void 0?this.width:n,s=t.height,r=s===void 0?this.height:s;if('number'!=typeof e)throw new TypeError('degrees must be a number');var l=fn(a),d=e*sr/180,h=ur(mr(o*Qs(d))+mr(r*or(d))),g=ur(mr(r*Qs(d))+mr(o*or(d))),m=tc.createFrom(this,{width:h,height:g}),c=Qs(-d),p=or(-d),u=h/2,f=g/2;0==h%2?(u-=.5,0==g%2?f-=.5:f=ur(f)):(u=ur(u),0==g%2?f-=.5:f=ur(f));var b=ur(o/2-u),_=ur(r/2-f);switch(l){case um.nearestneighbor:return qn(this,m,b,_,u,f,c,p);case um.bilinear:return Wn(this,m,b,_,u,f,c,p);default:throw new Error(`unsupported rotate interpolation: ${l}`);}}function qn(e,t,a,n,o,s,r,l){for(var d=0;d<t.width;d+=1)for(var h=0;h<t.height;h+=1)for(var g=0;g<e.channels;g++){var m=ar((d-o)*r-(h-s)*l+o)+a,p=ar((h-s)*r+(d-o)*l+s)+n;0>m||m>=e.width||0>p||p>=e.height?1===e.alpha&&g===e.channels-1?t.setValueXY(d,h,g,0):t.setValueXY(d,h,g,e.maxValue):t.setValueXY(d,h,g,e.getValueXY(m,p,g))}return t}function Wn(e,t,a,n,o,s,r,l){for(var d=e.width*e.channels,h=0;h<t.height;h++)for(var g=0;g<t.width;g++)for(var m=(g-o)*r-(h-s)*l+o+a,p=(h-s)*r+(g-o)*l+s+n,u=0|m,f=0|p,b=m-u,_=p-f,w=0;w<e.channels;w++)if(0>m||m>=e.width||0>p||p>=e.height)1===e.alpha&&w===e.channels-1?t.setValueXY(g,h,w,0):t.setValueXY(g,h,w,e.maxValue);else{var x=(f*e.width+u)*e.channels+w,k=e.data[x],y=e.data[x+e.channels],v=e.data[x+d],S=e.data[x+d+e.channels];t.setValueXY(g,h,w,0|k+b*(y-k)+_*(v-k)+b*_*(k-y-v+S))}return t}function Zn(e,t){if('number'!=typeof e)throw new TypeError('angle must be a number');switch(0>e&&(e=360*pr(-e/360)+e),e%360){case 0:return this.clone();case 90:return Jn.call(this);case 180:return Qn.call(this);case 270:return Kn.call(this);default:return Hn.call(this,e,t);}}function Kn(){for(var e=tc.createFrom(this,{width:this.height,height:this.width}),t=e.height-1,a=0;a<this.height;a++)for(var n=0;n<this.width;n++)for(var o=0;o<this.channels;o++)e.setValueXY(a,t-n,o,this.getValueXY(n,a,o));return e}function Jn(){for(var e=tc.createFrom(this,{width:this.height,height:this.width}),t=e.width-1,a=0;a<this.height;a++)for(var n=0;n<this.width;n++)for(var o=0;o<this.channels;o++)e.setValueXY(t-a,n,o,this.getValueXY(n,a,o));return e}function Qn(){for(var e=tc.createFrom(this),t=e.width-1,a=e.height-1,n=0;n<this.height;n++)for(var o=0;o<this.width;o++)for(var s=0;s<this.channels;s++)e.setValueXY(t-o,a-n,s,this.getValueXY(o,n,s));return e}function $n(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=pi(e);this.checkProcessable('insert',a);var n=t.x,o=n===void 0?0:n,s=t.y,r=s===void 0?0:s,l=fi(this,t,{copy:!0}),d=hr(l.height,r+e.height),h=hr(l.width,o+e.width);if(1===l.bitDepth)for(var g=r;g<d;g++)for(var m=o,c;m<h;m++)c=e.getBitXY(m-o,g-r),c?l.setBitXY(m,g):l.clearBitXY(m,g);else for(var p=r;p<d;p++)for(var u=o;u<h;u++)l.setPixelXY(u,p,e.getPixelXY(u-o,p-r));return l}function eo(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.size,a=void 0===t?0:t,n=e.algorithm,o=void 0===n?'copy':n,s=e.color;if(this.checkProcessable('setBorder',{bitDepth:[8,16,32,64]}),'set'===o){if(s.length!==this.channels)throw new Error(`setBorder: the color array must have the same length as the number of channels. Here: ${this.channels}`);for(var r=0;r<s.length;r++)0===s[r]&&(s[r]=.001)}else s=Th(this.channels,null);Array.isArray(a)||(a=[a,a]);for(var l=a[0],d=a[1],h=this.channels,g=l;g<this.width-l;g++)for(var m=0,c;m<h;m++){c=s[m]||this.data[(g+this.width*d)*h+m];for(var p=0;p<d;p++)this.data[(p*this.width+g)*h+m]=c;c=s[m]||this.data[(g+this.width*(this.height-d-1))*h+m];for(var u=this.height-d;u<this.height;u++)this.data[(u*this.width+g)*h+m]=c}for(var f=0;f<this.height;f++)for(var b=0,_;b<h;b++){_=s[b]||this.data[(f*this.width+l)*h+b];for(var w=0;w<l;w++)this.data[(f*this.width+w)*h+b]=_;_=s[b]||this.data[(f*this.width+this.width-l-1)*h+b];for(var x=this.width-l;x<this.width;x++)this.data[(f*this.width+x)*h+b]=_}return this}function to(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.preserveAlpha;if(this.checkProcessable('split',{bitDepth:[8,16]}),1===this.components)return new ah([this.clone()]);var a=new ah,n=this.data;if(this.alpha&&(void 0===t||t))for(var o=0;o<this.components;o++){for(var s=tc.createFrom(this,{components:1,alpha:!0,colorModel:'GREY'}),r=0,l=0;l<n.length;l+=this.channels)s.data[r++]=n[l+o],s.data[r++]=n[l+this.components];a.push(s)}else for(var d=0;d<this.channels;d++){for(var h=tc.createFrom(this,{components:1,alpha:!1,colorModel:'GREY'}),g=0,m=0;m<n.length;m+=this.channels)h.data[g++]=n[m+d];a.push(h)}return a}function io(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},i=t.keepAlpha,a=i!==void 0&&i,n=t.mergeAlpha,o=n!==void 0&&n;a&=this.alpha,o&=this.alpha,this.checkProcessable('getChannel',{bitDepth:[8,16]}),e=Bi(this,e);for(var s=tc.createFrom(this,{components:1,alpha:a,colorModel:'GREY'}),r=0,l=0;l<this.data.length;l+=this.channels)o?s.data[r++]=this.data[l+e]*this.data[l+this.components]/this.maxValue:(s.data[r++]=this.data[l+e],a&&(s.data[r++]=this.data[l+this.components]));return s}function ao(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:no,t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=t.mergeAlpha,n=a!==void 0&&a,o=t.keepAlpha,s=o!==void 0&&o;n&=this.alpha,s&=this.alpha,this.checkProcessable('combineChannels',{bitDepth:[8,16]});for(var r=tc.createFrom(this,{components:1,alpha:s,colorModel:'GREY'}),l=0,d=0,h;d<this.size;d++)h=e(this.getPixel(d)),n?r.data[l++]=h*this.data[d*this.channels+this.components]/this.maxValue:(r.data[l++]=h,s&&(r.data[l++]=this.data[d*this.channels+this.components]));return r}function no(e){return(e[0]+e[1]+e[2])/3}function oo(e,t){if(this.checkProcessable('setChannel',{bitDepth:[8,16]}),t.checkProcessable('setChannel (image parameter check)',{bitDepth:[this.bitDepth],alpha:[0],components:[1]}),t.width!==this.width||t.height!==this.height)throw new Error('Images must have exactly the same width and height');e=Bi(this,e);for(var a=e,n=0;n<t.data.length;n++)this.data[a]=t.data[n],a+=this.channels;return this}function so(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.shift,n=void 0===a?[0,0]:a,o=t.average,s=t.channels,r=t.defaultAlpha,l=t.normalize,d=t.border,h=void 0===d?[0,0]:d;if(this.checkProcessable('getSimilarity',{bitDepth:[8,16]}),Array.isArray(h)||(h=[h,h]),s=ji(this,{channels:s,defaultAlpha:r}),this.bitDepth!==e.bitDepth)throw new Error('Both images must have the same bitDepth');if(this.channels!==e.channels)throw new Error('Both images must have the same number of channels');if(this.colorModel!==e.colorModel)throw new Error('Both images must have the same colorModel');'undefined'==typeof o&&(o=!0);for(var g=dr(h[0],-n[0]),m=hr(this.width-h[0],this.width-n[0]),p=dr(h[1],-n[1]),u=hr(this.height-h[1],this.height-n[1]),f=Th(s.length,0),b=0;b<s.length;b++){var _=s[b],c=l?this.sum[_]:dr(this.sum[_],e.sum[_]),w=l?e.sum[_]:dr(this.sum[_],e.sum[_]);if(0!==c&&0!==w)for(var k=g;k<m;k++)for(var v=p;v<u;v++){var D=k*this.multiplierX+v*this.multiplierY+_,S=D+n[0]*this.multiplierX+n[1]*this.multiplierY;f[b]+=hr(this.data[D]/c,e.data[S]/w)}}return o?f.reduce((e,t)=>e+t)/f.length:f}function ro(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.sampling,a=void 0===t?[10,10]:t,n=e.painted,o=e.mask;this.checkProcessable('getPixelsGrid',{bitDepth:[8,16],channels:1}),Array.isArray(a)||(a=[a,a]);for(var s=a[0],r=a[1],l=s*r,d=Array(l),h=Array(l),g=this.width/s,m=this.height/r,c=ur(g/2),p=0,u=0,f;u<s;u++){f=ur(m/2);for(var b=0;b<r;b++){var _=ar(c),w=ar(f);(!o||o.getBitXY(_,w))&&(d[p]=[_,w],h[p]=this.getPixelXY(_,w),p++),f+=m}c+=g}d.length=p,h.length=p;var x={xyS:d,zS:h};return void 0!==n&&n&&(x.painted=this.rgba8().paintPoints(d)),x}function lo(e,t,i){for(var a=Array(e),n=0;n<e;n++)a[n]=Array(t);if(i)for(var o=0;o<e;o++)for(var s=0;s<t;s++)a[o][s]=i;return a.width=e,a.height=t,Object.setPrototypeOf(a,lo.prototype),a}function ho(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},a=t.border;if(this.checkProcessable('getChannel',{bitDepth:[8,16]}),this.bitDepth!==e.bitDepth)throw new Error('Both images must have the same bitDepth');if(this.channels!==e.channels)throw new Error('Both images must have the same number of channels');if(this.colorModel!==e.colorModel)throw new Error('Both images must have the same colorModel');for(var n=new lo(e.width,e.height,-Infinity),o=ur(e.width/2),s=ur(e.height/2),r=o,l=s,d=!1;!d;){for(var h=n.localSearch(o,s,-Infinity),g=0;g<h.length;g++){var m=h[g],c=this.getSimilarity(e,{border:a,shift:[r-m[0],l-m[1]]});n[m[0]][m[1]]=c}var p=n.localMax(o,s);p.position[0]!==o||p.position[1]!==s?(o=p.position[0],s=p.position[1]):d=!0}return[o-r,s-l]}function go(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0;this.checkProcessable('getRow',{bitDepth:[8,16]}),cn(this,e),un(this,t);for(var i=Array(this.width),a=0,n=e*this.width*this.channels+t,o=n+this.width*this.channels,s=n;s<o;s+=this.channels)i[a++]=this.data[s];return i}function mo(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0;this.checkProcessable('getColumn',{bitDepth:[8,16]}),pn(this,e),un(this,t);for(var i=Array(this.height),a=0,n=this.width*this.channels,o=t+e*this.channels;o<this.data.length;o+=n)i[a++]=this.data[o];return i}function co(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.channel;if(this.checkProcessable('getMatrix',{bitDepth:[8,16]}),void 0===t){if(1<this.components)throw new RangeError('You need to define the channel for an image that contains more than one channel');t=0}for(var i=new Ch(this.height,this.width),a=0;a<this.height;a++)for(var n=0;n<this.width;n++)i.set(a,n,this.getValueXY(n,a,t));return i}function po(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=t.channel;if(this.checkProcessable('getMatrix',{bitDepth:[8,16]}),void 0===i){if(1<this.components)throw new RangeError('You need to define the channel for an image that contains more than one channel');i=0}if(!e.length||!e[0].length||this.width!==e.columns||this.height!==e.rows)throw new RangeError('The size of the matrix must be equal to the size of the image');for(var a=0;a<this.height;a++)for(var n=0;n<this.width;n++)this.setValueXY(n,a,i,e.get(a,n))}function uo(){this.checkProcessable('getPixelsArray',{bitDepth:[8,16,32]});for(var e=Array(this.size),t=0,a=0,n;a<this.data.length;a+=this.channels){n=Array(this.components);for(var o=0;o<this.components;o++)n[o]=this.data[a+o];e[t++]=n}return e}function fo(e){for(var t=this,a=t.getClosestCommonParent(e),n=t.getRelativePosition(a,{defaultFurther:!0}),o=bo(t,n),s=e.getRelativePosition(a,{defaultFurther:!0}),r=bo(e,s),l=_o(o,r),d={whitePixelsMask1:[],whitePixelsMask2:[],commonWhitePixels:[]},h=0;h<l.length;h++){var g=l[h],m=[g[0]-n[0],g[1]-n[1]],c=[g[0]-s[0],g[1]-s[1]],p=t.getBitXY(m[0],m[1]),u=e.getBitXY(c[0],c[1]);1===p&&1===u&&d.commonWhitePixels.push(g)}for(var f=0;f<o.length;f++){var b=void 0,_=void 0;0!==f&&(b=ur(f/(t.width-1)),_=f%(t.width-1)),1===t.getBitXY(b,_)&&d.whitePixelsMask1.push(o[f])}for(var w=0;w<r.length;w++){var x=0,k=0;0!==w&&(x=ur(w/(e.width-1)),k=w%(e.width-1)),1===e.getBitXY(x,k)&&d.whitePixelsMask2.push(r[w])}return d}function bo(e,t){for(var a=[],n=0;n<e.height;n++)for(var o=0,s;o<e.width;o++)s=[n,o],a.push([s[0]+t[0],s[1]+t[1]]);return a}function _o(e,t){for(var a=0,n=0,o=[];a<e.length&&n<t.length;)e[a][0]===t[n][0]&&e[a][1]===t[n][1]?(o.push(e[a]),a++,n++):e[a][0]<t[n][0]||e[a][0]===t[n][0]&&e[a][1]<t[n][1]?a++:n++;return o}function wo(e){var t=xo(this),i=xo(e),a=void 0;if(a=t>=i?ko(this,t):ko(e,i),0===t||0===i)return a;for(var n=this,o=e;t!==i;)if(t>i){if(n=n.parent,null===n)return a;--t}else{if(o=o.parent,null===o)return a;--i}for(;n!==o&&null!==n&&null!==o;)if(n=n.parent,o=o.parent,null===n||null===o)return a;return n===o?n:a}function xo(e){for(var t=0,i=e;null!=i.parent;)i=i.parent,t++;return t}function ko(e,t){for(var i=e;0<t;)i=i.parent,--t;return i}function yo(e,t){e.checkProcessable('Canny edge detector',{bitDepth:8,channels:1,components:1}),t=Object.assign({},xm,t);const a=e.width,n=e.height,o=e.maxValue,s={sigma:t.gaussianBlur,radius:3},r=e.gaussianFilter(s),d=r.convolution(ym,vm),h=r.convolution(km,vm),g=h.hypotenuse(d),m=e.constructor,c=new m(a,n,{kind:'GREY',bitDepth:32}),p=new m(a,n,{kind:'GREY',bitDepth:32}),u=new m(a,n,{kind:'GREY'});for(var f=1;f<a-1;f++)for(var b=1,_;b<n-1;b++)_=(ar(Js(h.getValueXY(f,b,0),d.getValueXY(f,b,0))*(5/sr))+5)%5,0===_&&(g.getValueXY(f,b,0)<=g.getValueXY(f,b-1,0)||g.getValueXY(f,b,0)<=g.getValueXY(f,b+1,0))||1===_&&(g.getValueXY(f,b,0)<=g.getValueXY(f-1,b+1,0)||g.getValueXY(f,b,0)<=g.getValueXY(f+1,b-1,0))||2===_&&(g.getValueXY(f,b,0)<=g.getValueXY(f-1,b,0)||g.getValueXY(f,b,0)<=g.getValueXY(f+1,b,0))||3===_&&(g.getValueXY(f,b,0)<=g.getValueXY(f-1,b-1,0)||g.getValueXY(f,b,0)<=g.getValueXY(f+1,b+1,0))||c.setValueXY(f,b,0,g.getValueXY(f,b,0));for(f=0;f<a*n;++f){var w=c.data[f],x=0;w>t.highThreshold&&(x++,u.data[f]=o),w>t.lowThreshold&&x++,p.data[f]=x}var y=[];for(f=1;f<a-1;++f)for(b=1;b<n-1;++b)if(1===p.getValueXY(f,b,0))outer:for(var v=f-1;v<f+2;++v)for(var D=b-1;D<b+2;++D)if(2===p.getValueXY(v,D,0)){y.push([f,b]),u.setValueXY(f,b,0,o);break outer}for(;0<y.length;){var S=[];for(f=0;f<y.length;++f)for(b=-1;2>b;++b)for(v=-1;2>v;++v)if(0!==b||0!==v){var M=y[f][0]+b,P=y[f][1]+v;1===p.getValueXY(M,P,0)&&0===u.getValueXY(M,P,0)&&(S.push([M,P]),u.setValueXY(M,P,0,o))}y=S}return u}function vo(e){return yo(this,e)}function Do(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=t.position;if(this.checkProcessable('extract',{bitDepth:[1,8,16]}),!i&&(i=e.getRelativePosition(this),!i))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(1<this.bitDepth){for(var a=tc.createFrom(this,{width:e.width,height:e.height,alpha:1,position:i,parent:this}),n=0;n<e.width;n++)for(var o=0;o<e.height;o++){for(var s=0,r;s<this.channels;s++)r=this.getValueXY(n+i[0],o+i[1],s),a.setValueXY(n,o,s,r);e.getBitXY(n,o)||a.setValueXY(n,o,this.components,0)}return a}for(var l=tc.createFrom(this,{width:e.width,height:e.height,position:i,parent:this}),d=0;d<e.height;d++)for(var h=0;h<e.width;h++)e.getBitXY(h,d)&&this.getBitXY(h+i[0],d+i[1])&&l.setBitXY(h,d);return l}function So(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.x,a=void 0===t?0:t,n=e.y,o=void 0===n?0:n,s=e.inPlace,r=void 0===s||s?this:tc.createFrom(this);if(this.checkProcessable('floodFill',{bitDepth:1}),1===this.bitDepth){var l=this.getBitXY(a,o);if(l)return r;var d=new Dm;for(d.push(new Mo(a,o));0<d.length;){var h=d.shift();r.setBitXY(h.x,h.y);for(var g=h.x+1;g<this.width&&!r.getBitXY(g,h.y)&&!this.getBitXY(g,h.y);g++)r.setBitXY(g,h.y),h.y+1<this.height&&!this.getBitXY(g,h.y+1)&&d.push(new Mo(g,h.y+1)),0<=h.y-1&&!this.getBitXY(g,h.y-1)&&d.push(new Mo(g,h.y-1));for(var m=h.x-1;0<=m&&!r.getBitXY(m,h.y)&&!this.getBitXY(m,h.y);m++)r.setBitXY(m,h.y),h.y+1<this.height&&!this.getBitXY(m,h.y+1)&&d.push(new Mo(m,h.y+1)),0<=h.y-1&&!this.getBitXY(m,h.y-1)&&d.push(new Mo(m,h.y-1))}}return r}function Mo(e,t){this.x=e,this.y=t}function jo(e){var t=e.toString(16);return 1===t.length?'0'+t:t}function Po(e){for(var t=1;t<arguments.length;t++){var a=null==arguments[t]?{}:arguments[t],n=Object.keys(a);'function'==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(a).filter(function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}))),n.forEach(function(t){Io(e,t,a[t])})}return e}function Io(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function Bo(e){var t=Bm[e.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:100}:void 0}function Co(e){var t=e.match(/rgb\(([^)]+)\)/);if(t){var i=t[1].split(/ *, */).map(Number);return{r:i[0],g:i[1],b:i[2],a:100}}}function Ro(e){var t=e.match(/rgba\(([^)]+)\)/);if(t){var i=t[1].split(/ *, */).map(Number);return{r:i[0],g:i[1],b:i[2],a:100*i[3]}}}function Ao(e){if('#'===e[0]&&7===e.length)return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:100}}function zo(e){if('#'===e[0]&&4===e.length)return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:100}}function Yo(e){var t=e.match(/hsl\(([^)]+)\)/);if(t){var i=t[1].split(/ *, */),a=parseInt(i[0],10),n=parseInt(i[1],10),o=parseInt(i[2],10),s=Im(a,n,o);return Po({},s,{a:100})}}function Lo(e){var t=e.match(/hsla\(([^)]+)\)/);if(t){var i=t[1].split(/ *, */),n=parseInt(i[0],10),o=parseInt(i[1],10),s=parseInt(i[2],10),r=parseInt(100*parseFloat(i[3]),10),a=Im(n,o,s);return Po({},a,{a:r})}}function Eo(e){var t=Cm(e);return[t.r,t.g,t.b,ar(255*t.a/100)]}function To(e,i,a){return 0>a&&(a+=1),1<a&&(a-=1),a<1/6?e+6*(i-e)*a:a<1/2?i:a<2/3?e+6*((i-e)*(2/3-a)):e}function Fo(e,t,i){var a,n,o,d,h,m;return t/=100,i/=100,0===t?d=h=m=255*i:(n=.5>=i?i*(t+1):i+t-i*t,a=2*i-n,o=e/360,d=To(a,n,o+1/3),h=To(a,n,o),m=To(a,n,o-1/3)),{r:d,g:h,b:m}}function Xo(e){for(var t=Array(e),a=0,n=0;360>n;n+=360/e){a++;var o=Fo(n,100,30+15*(a%4));t[a-1]=[ar(255*o.r),ar(255*o.g),ar(255*o.b)]}return t}function Vo(){return[ur(256*Math.random()),ur(256*Math.random()),ur(256*Math.random())]}function Uo(e){var t=e.color,a=e.colors,n=e.randomColors,o=e.numberColors,s=void 0===o?50:o;if(t&&!Array.isArray(t)&&(t=Eo(t)),t)return[t];if(a)return a=a.map(function(e){return Array.isArray(e)?e:Eo(e)}),a;if(n){a=Array(s);for(var r=0;r<s;r++)a[r]=Vo()}return Xo(s)}function Go(e,t){var a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},n=a.color,o=void 0===n?'blue':n,s=a.colors,r=a.font,l=void 0===r?'12px Helvetica':r,d=a.rotate,h=void 0===d?0:d;if(this.checkProcessable('paintMasks',{channels:[3,4],bitDepth:[8,16],colorModel:'RGB'}),!Array.isArray(e))throw Error('paintLabels: labels must be an array');if(!Array.isArray(t))throw Error('paintLabels: positions must be an array');if(o&&!Array.isArray(o)&&(o=Eo(o)),s=s?s.map(function(e){return Array.isArray(e)?e:Eo(e)}):[o],e.length!==t.length)throw Error('paintLabels: positions and labels must be arrays from the same size');Array.isArray(l)||(l=[l]),Array.isArray(h)||(h=[h]);for(var g=this.getCanvas(),m=g.getContext('2d'),c=0;c<e.length;c++){m.save();var p=s[c%s.length];m.fillStyle=`rgba(${p[0]},${p[1]},${p[2]},${p[3]/this.maxValue})`,m.font=l[c%l.length];var u=t[c];m.translate(u[0],u[1]),m.rotate(h[c%h.length]/180*sr),m.fillText(e[c],0,0),m.restore()}return this.data=Uint8Array.from(m.getImageData(0,0,this.width,this.height).data),this}function Oo(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=t.alpha,n=a===void 0?255:a,o=t.labels,s=o===void 0?[]:o,r=t.labelsPosition,l=r===void 0?[]:r,d=t.labelColor,h=d===void 0?'blue':d,g=t.labelFont,m=g===void 0?'12px Helvetica':g;this.checkProcessable('paintMasks',{channels:[3,4],bitDepth:[8,16],colorModel:'RGB'});var c=Uo(Object.assign({},t,{numberColors:e.length}));Array.isArray(e)||(e=[e]);for(var p=0;p<e.length;p++)for(var u=e[p],f=c[p%c.length],b=0;b<u.width;b++)for(var _=0;_<u.height;_++)if(u.getBitXY(b,_))for(var w=0;w<hr(this.components,f.length);w++)if(255===n)this.setValueXY(b+u.position[0],_+u.position[1],w,f[w]);else{var k=this.getValueXY(b+u.position[0],_+u.position[1],w);k=ar((k*(255-n)+f[w]*n)/255),this.setValueXY(b+u.position[0],_+u.position[1],w,k)}if(Array.isArray(s)&&0<s.length){var v=this.getCanvas(),D=v.getContext('2d');D.fillStyle=h,D.font=m;for(var S=0,M;S<hr(e.length,s.length);S++)M=l[S]?l[S]:e[S].position,D.fillText(s[S],M[0],M[1]);this.data=Uint8Array.from(D.getImageData(0,0,this.width,this.height).data)}return this}function No(e,t,i){var a=Ch.zeros(t,e);if(i.filled)for(var n=0;n<t;n++)for(var o=0;o<e;o++)a.set(n,o,1);else{for(var s of[0,t-1])for(var r=0;r<e;r++)a.set(s,r,1);for(var l=0;l<t;l++)for(var d of[0,e-1])a.set(l,d,1)}return a}function Ho(e,t,i){var n=Ch.zeros(t,e,i),o=1-t%2,s=1-e%2,r=ur((e-1)/2),a=ur((t-1)/2),l=r*r,d=a*a;if(i.filled)for(var h=0,g;h<=a;h++){g=ur(nr(l-l*h*h/d));for(var m=r-g;m<=r;m++)n.set(a-h,m,1),n.set(a+h+o,m,1),n.set(a-h,e-m-1,1),n.set(a+h+o,e-m-1,1)}else{for(var c=0;c<=a;c++){var p=ur(nr(l-l*c*c/d)),u=r-p;n.set(a-c,u,1),n.set(a+c+o,u,1),n.set(a-c,e-u-1,1),n.set(a+c+o,e-u-1,1)}for(var f=0;f<=r;f++){var b=ur(nr(d-d*f*f/l)),_=a-b;n.set(_,r-f,1),n.set(_,r+f+s,1),n.set(t-_-1,r-f,1),n.set(t-_-1,r+f+s,1)}}return n}function qo(e,t,i){if(!i.filled)throw new Error('Non filled triangle is not implemented');for(var a=Ch.zeros(t,e,i),n=0,o;n<t;n++){o=ur((1-n/t)*e/2);for(var s=o;s<e-o;s++)a.set(n,s,1)}return a}function Wo(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=t.shape;this.checkProcessable('paintPoints',{bitDepth:[8,16]});for(var n=Uo(Object.assign({},t,{numberColors:e.length})),o=new zm(a).getPoints(),s=hr(this.channels,n[0].length),r=0;r<e.length;r++)for(var l=n[r%n.length],d=e[r][0],h=e[r][1],g=0;g<o.length;g++){var m=o[g][0],c=o[g][1];if(0<=d+m&&0<=h+c&&d+m<this.width&&h+c<this.height)for(var p=(d+m+(h+c)*this.width)*this.channels,u=0;u<s;u++)this.data[p+u]=l[u]}return this}function Zo(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=t.color,n=a===void 0?[this.maxValue,0,0]:a,o=t.closed;this.checkProcessable('paintPoints',{bitDepth:[8,16]});for(var s=hr(this.channels,n.length),r=0;r<e.length-1+(o!==void 0&&o);r++)for(var l=e[r],d=e[(r+1)%e.length],h=d[0]-l[0],g=d[1]-l[1],m=dr(mr(h),mr(g)),c=l[0],p=l[1],u=0;u<=m;u++){var f=ar(c),b=ar(p);if(0<=f&&0<=b&&f<this.width&&b<this.height)for(var _=(f+b*this.width)*this.channels,w=0;w<s;w++)this.data[_+w]=n[w];c+=h/m,p+=g/m}return this}function Ko(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=Object.assign({},t);this.checkProcessable('paintPolylines',{bitDepth:[8,16]});for(var n=Uo(Object.assign({},t,{numberColors:e.length})),o=0;o<e.length;o++)a.color=n[o%n.length],this.paintPolyline(e[o],a);return this}function Jo(e){for(var t=[],a=0;a<e.length;a++)if(e[a][0]===e[(a+1)%e.length][0]&&e[a][1]===e[(a+1)%e.length][1])continue;else if(e[a][0]===e[(a-1+e.length)%e.length][0]&&e[a][1]===e[(a-1+e.length)%e.length][1])continue;else if(e[(a+1)%e.length][0]===e[(a-1+e.length)%e.length][0]&&e[(a-1+e.length)%e.length][1]===e[(a+1)%e.length][1])continue;else t.push(e[a]);return t}function Qo(e,t){if(e[0]===t[0])return{a:0,b:e[0],vertical:!0};var i=(t[1]-e[1])/(t[0]-e[0]),a=e[1]-i*e[0];return{a:i,b:a,vertical:!1}}function $o(e,t,i,a){if(!0===i.vertical)return i.b<=e;if(0===i.a)return!1;var n=(t-i.b)/i.a;return n<e&&0<=n&&n<=a}function es(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=t.color,n=a===void 0?[this.maxValue,0,0]:a,o=t.filled;this.checkProcessable('paintPoints',{bitDepth:[8,16]}),t.closed=!0;var s=Jo(e);if(!1===(o!==void 0&&o))return this.paintPolyline(e,t);for(var r=Array(this.height),l=0;l<this.height;l++){r[l]=[];for(var d=0;d<this.width;d++)r[l].push(0)}for(var h=0,g;h<s.length;h++){g=Qo(s[h],s[(h+1)%s.length]);for(var m=0;m<this.height;m++)for(var c=0;c<this.width;c++)$o(c,m,g,this.height)&&(r[m][c]=0===r[m][c]?1:0)}for(var u=0;u<this.height;u++)for(var f=0;f<this.width;f++)if(1===r[u][f])for(var b=hr(this.channels,n.length),_=(f+u*this.width)*this.channels,w=0;w<b;w++)this.data[_+w]=n[w];return this.paintPolyline(e,t)}function ts(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=Object.assign({},t);this.checkProcessable('paintPolygons',{bitDepth:[8,16]});for(var n=Uo(Object.assign({},t,{numberColors:e.length})),o=0;o<e.length;o++)a.color=n[o%n.length],this.paintPolygon(e[o],a);return this}function is(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.maxSlots,i=void 0===t?256:t,a=e.channel,n=e.useAlpha;if(this.checkProcessable('getHistogram',{bitDepth:[1,8,16]}),void 0===a){if(1<this.components)throw new RangeError('You need to define the channel for an image that contains more than one channel');a=0}return ns.call(this,a,{useAlpha:void 0===n||n,maxSlots:i})}function as(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.maxSlots,a=t===void 0?256:t,n=e.useAlpha,o=!(n!==void 0)||n;this.checkProcessable('getHistograms',{bitDepth:[8,16]});for(var s=Array(o?this.components:this.channels),r=0;r<s.length;r++)s[r]=ns.call(this,r,{useAlpha:o,maxSlots:a});return s}function ns(e,t){var a=t.useAlpha,n=t.maxSlots;if(1===this.bitDepth){for(var o=[0,0],s=0;s<this.height;s++)for(var r=0,l;r<this.width;r++)l=this.getBitXY(s,r),0===l?o[0]+=1:1===l&&(o[1]+=1);return o}var d=Math.log2(n);if(!_h(d))throw new RangeError('maxSlots must be a power of 2, for example: 64, 256, 1024');var h=0;this.bitDepth>d&&(h=this.bitDepth-d);var g=this.data,m=Th(cr(2,hr(this.bitDepth,d)),0);if(a&&this.alpha)for(var c=this.channels-e-1,p=e;p<g.length;p+=this.channels)m[g[p]>>h]+=g[p+c]/this.maxValue;else for(var u=e;u<g.length;u+=this.channels)m[g[u]>>h]++;return m}function os(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.useAlpha,a=e.nbSlots,n=a===void 0?512:a;this.checkProcessable('getColorHistogram',{bitDepth:[8,16],components:[3]});var o=er(n)/2.0794415416798357;if(o!==ur(o))throw new RangeError('nbSlots must be a power of 8. Usually 8, 64, 512 or 4096');for(var s=this.bitDepth-o,r=this.data,l=Th(cr(8,o),0),d=cr(2,2*o),h=cr(2,o),g=0,m;g<r.length;g+=this.channels)m=(r[g]>>s)*d+(r[g+1]>>s)*h+(r[g+2]>>s),(!(t!==void 0)||t)&&this.alpha?l[m]+=r[g+this.channels-1]/this.maxValue:l[m]++;return l}function ss(){this.checkProcessable('min',{bitDepth:[8,16,32]});for(var e=Th(this.channels,+Infinity),t=0;t<this.data.length;t+=this.channels)for(var a=0;a<this.channels;a++)this.data[t+a]<e[a]&&(e[a]=this.data[t+a]);return e}function rs(){this.checkProcessable('max',{bitDepth:[8,16,32]});for(var e=Th(this.channels,-Infinity),t=0;t<this.data.length;t+=this.channels)for(var a=0;a<this.channels;a++)this.data[t+a]>e[a]&&(e[a]=this.data[t+a]);return e}function ls(){this.checkProcessable('sum',{bitDepth:[8,16]});for(var e=Th(this.channels,0),t=0;t<this.data.length;t+=this.channels)for(var a=0;a<this.channels;a++)e[a]+=this.data[t+a];return e}function ds(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:0,t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0;this.checkProcessable('getMoment',{bitDepth:[1]});for(var i=0,a=0;a<this.width;a++)for(var n=0;n<this.height;n++)1===this.getBitXY(a,n)&&(i+=cr(a,e)*cr(n,t));return i}function hs(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.mask,a=e.region,n=a===void 0?3:a,o=e.removeClosePoints,s=o===void 0?0:o,r=e.invert,l=r!==void 0&&r,d=e.maxEquals,h=d===void 0?2:d,g=this;this.checkProcessable('localMaxima',{bitDepth:[8,16],components:1}),n*=4;for(var m=l?0:1,c=[1,0,-1,0,1,1,-1,-1,2,0,-2,0,2,2,-2,-2],p=[0,1,0,-1,1,-1,1,-1,0,2,0,-2,2,-2,2,-2],u=8>=n?1:2,f=[],b=u;b<g.height-u;b++)for(var _=u;_<g.width-u;_++)if(!(t&&t.getBitXY(_,b)!==m)){for(var w=0,x=0,k=g.data[_+b*g.width],y=0;y<n;y++)l?g.data[_+c[y]+(b+p[y])*g.width]>k&&w++:g.data[_+c[y]+(b+p[y])*g.width]<k&&w++,g.data[_+c[y]+(b+p[y])*g.width]===k&&x++;w+x===n&&x<=h&&f.push([_,b])}if(0<s)for(var v=0;v<f.length;v++)for(var D=v+1;D<f.length;D++)nr(cr(f[v][0]-f[D][0],2)+cr(f[v][1]-f[D][1],2))<s&&(f[v][0]=f[v][0]+f[D][0]>>1,f[v][1]=f[v][1]+f[D][1]>>1,f.splice(D,1),D--);return f}function gs(){for(var e=this.getHistograms({maxSlots:this.maxValue+1}),t=Array(e.length),i=0,a;i<e.length;i++)a=e[i],t[i]=ei(a);return t}function ms(){for(var e=this.getHistograms({maxSlots:this.maxValue+1}),t=Array(e.length),i=0,a;i<e.length;i++)a=e[i],t[i]=$t(a);return t}function cs(){this.checkProcessable('points',{bitDepth:[1]});for(var e=Array(this.size),t=0,i=0;i<this.width;i++)for(var a=0;a<this.height;a++)1===this.getBitXY(i,a)&&(e[t++]=[i,a]);return e.length=t,e}function ps(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};if(this===e)return[0,0];for(var i=[0,0],a=this;a;){if(a===e)return i;a.position&&(i[0]+=a.position[0],i[1]+=a.position[1]),a=a.parent}return!!t.defaultFurther&&i}function us(){return this.checkProcessable('getSvd',{bitDepth:[1]}),new xh(this.points)}function fs(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.alpha,a=t===void 0?1:t;this.checkProcessable('countAlphaPixels',{bitDepth:[8,16],alpha:1});var n=0;if(a!==void 0){for(var o=this.components;o<this.data.length;o+=this.channels)this.data[o]===a&&n++;return n}return this.size}function bs(e,a={}){a.sorted||e.sort(ws);const o=e.length,n=Array(2*o);for(var s=0,r=0;r<o;r++){const t=e[r];for(;2<=s&&0>=_s(n[s-2],n[s-1],t);)s--;n[s++]=t}const l=s+1;for(r=o-2;0<=r;r--){const t=e[r];for(;s>=l&&0>=_s(n[s-2],n[s-1],t);)s--;n[s++]=t}return n.slice(0,s-1)}function _s(e,t,i){return(t[1]-e[1])*(i[0]-e[0])-(t[0]-e[0])*(i[1]-e[1])}function ws(e,t){return e[0]===t[0]?e[1]-t[1]:e[0]-t[0]}function xs(){var e=this;e.checkProcessable('monotoneChainConvexHull',{bitDepth:1});var t=e.getPoints();return bs(t,{sorted:!0})}function ks(e,t){return[e[0]-t[0],e[1]-t[1]]}function ys(e){var t=nr(cr(e[0],2)+cr(e[1],2));return[e[0]/t,e[1]/t]}function vs(e,t,a){a===void 0&&(a=Array(t.length));for(var n=Qs(e),o=or(e),s=0;s<a.length;++s)a[s]=[n*t[s][0]-o*t[s][1],o*t[s][0]+n*t[s][1]];return a}function Ds(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},a=e.originalPoints,n=void 0===a?xs.call(this):a;if(0===n.length)return[];if(1===n.length)return[n[0],n[0],n[0],n[0]];for(var o=Array(n.length),s=+Infinity,r=0,l=void 0,d=0,h;d<o.length;d++){h=Ss(n[d],n[(d+1)%o.length]),vs(-h,n,o);for(var g=o[d][0],m=o[d][1],c=o[(d+1)%o.length][0],p=o[(d+1)%o.length][1],u=!0,f=0,b=0,_=0,w=0;w<o.length;w++){var x=o[w][0],k=o[w][1],y=(x-g)/(c-g);!0==u?(u=!1,f=y,b=y):(y<f&&(f=y),y>b&&(b=y));var t=(-(c-g)*k+c*m-p*g)/(c-g);mr(t)>mr(_)&&(_=t)}var v=[g+f*(c-g),m],D=[g+b*(c-g),m],S=mr(_*(f-b)*(c-g));S<s&&(r=h,s=S,l=[v,D,[D[0],D[1]-_],[v[0],v[1]-_]])}return vs(r,l,l),l}function Ss(e,t){var i=ks(t,e),a=ys(i),n=Math.acos(a[0]);return 0>a[1]?-n:n}function Ms(e){for(var t=e.data,a=[1,0,-1,0],n=[0,1,0,-1],o=e.minMax,s=-o.min,r=o.max+s,l=[],d=0;d<=r;d++)l.push(Object.create(null));for(var h=0;h<e.width;h++)for(var g=0;g<e.height;g++){var m=h+g*e.width,c=t[m];if(0!==c){for(var p=Object.create(null),u=!1,f=0;4>f;f++){var b=h+a[f],_=g+n[f];if(0<=b&&0<=_&&b<e.width&&_<e.height){var w=t[b+_*e.width];c!==w&&(u=!0,0!==w&&p[w]===void 0&&(p[w]=!0,l[w+s][c]?l[w+s][c]++:l[w+s][c]=1))}else u=!0}u&&(l[c+s][c]?l[c+s][c]++:l[c+s][c]=1)}}for(var k={},v=0;v<l.length;v++)0<Object.keys(l[v]).length&&(k[v-s]=l[v]);return k}function js(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.algorithm,a=void 0===t?'commonBorderLength':t,n=e.minCommonBorderLength,o=void 0===n?5:n,s=e.maxCommonBorderLength,r=void 0===s?100:s,l=e.minCommonBorderRatio,d=void 0===l?.3:l,h=e.maxCommonBorderRatio,g=void 0===h?1:h,m=function(e,t,i){return e[i]>=o&&e[i]<=r};'function'==typeof a&&(m=a),'commonborderratio'===a.toLowerCase()&&(m=function(e,t,i){var a=hr(e[i]/e[t],1);return a>=d&&a<=g});var c=this,p=c.commonBorderLength,u={},f={};for(var b of Object.keys(p)){var _=p[b],w=Object.keys(_);for(var x of w)if(x!==b&&m(_,b,x)){var k=x;f[x]&&(k=f[x]);var y=b;if(f[b]&&(y=f[b]),+k!==y){var v=hr(k,y),D=dr(k,y);if(u[v]||(u[v]={}),u[v][D]=!0,f[D]=v,u[D]){for(var S of Object.keys(u[D]))u[v][S]=!0,f[S]=v;delete u[D]}}}}var M=c.minMax,j=-M.min,P=M.max+j,I=Array(P+1).fill(0);for(var B of Object.keys(f))I[+B+j]=f[B];for(var C=c.data,R=0,A;R<C.length;R++)if(A=C[R],0!==A){var z=I[A+j];0!==z&&(C[R]=z)}return c.computed={},c}function Ps(e){function t(t,i){var a=0,h=0,g=e.getBitXY(t,i),m=g?++s:--r;if(32767<s||-32768>r)throw new Error('Too many regions of interest');for(l[0]=t,d[0]=i;a<=h;){var c=l[65535&a],p=d[65535&a];if(o[p*e.width+c]=m,0<c&&0===o[p*e.width+c-1]&&e.getBitXY(c-1,p)===g&&(h++,l[65535&h]=c-1,d[65535&h]=p,o[p*e.width+c-1]=-32768),0<p&&0===o[(p-1)*e.width+c]&&e.getBitXY(c,p-1)===g&&(h++,l[65535&h]=c,d[65535&h]=p-1,o[(p-1)*e.width+c]=-32768),c<e.width-1&&0===o[p*e.width+c+1]&&e.getBitXY(c+1,p)===g&&(h++,l[65535&h]=c+1,d[65535&h]=p,o[p*e.width+c+1]=-32768),p<e.height-1&&0===o[(p+1)*e.width+c]&&e.getBitXY(c,p+1)===g&&(h++,l[65535&h]=c,d[65535&h]=p+1,o[(p+1)*e.width+c]=-32768),n&&(0<c&&0<p&&0===o[(p-1)*e.width+c-1]&&e.getBitXY(c-1,p-1)===g&&(h++,l[65535&h]=c-1,d[65535&h]=p-1,o[(p-1)*e.width+c-1]=-32768),c<e.width-1&&0<p&&0===o[(p-1)*e.width+c+1]&&e.getBitXY(c+1,p-1)===g&&(h++,l[65535&h]=c+1,d[65535&h]=p-1,o[(p-1)*e.width+c+1]=-32768),0<c&&p<e.height-1&&0===o[(p+1)*e.width+c-1]&&e.getBitXY(c-1,p+1)===g&&(h++,l[65535&h]=c-1,d[65535&h]=p+1,o[(p+1)*e.width+c-1]=-32768),c<e.width-1&&p<e.height-1&&0===o[(p+1)*e.width+c+1]&&e.getBitXY(c+1,p+1)===g&&(h++,l[65535&h]=c+1,d[65535&h]=p+1,o[(p+1)*e.width+c+1]=-32768)),a++,65535<h-a)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')}}for(var i=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=i.allowCorners,n=a!==void 0&&a,o=new Int16Array(e.size),s=0,r=0,l=new Uint16Array(65536),d=new Uint16Array(65536),h=0;h<e.width;h++)for(var g=0;g<e.height;g++)0===o[g*e.width+h]&&t(h,g);return new Ym(e,o)}function Is(e){this.value=e,this.parent=null,this.rank=0}function Bs(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=t.allowCorners,n=4;a!==void 0&&a&&(n=8);var o=void 0,s=void 0,r=void 0;if(8==n)o=Xm,s=Vm,r=Um;else if(4==n)o=Em,s=Tm,r=Fm;else throw new RangeError(`unsupported neighbours count: ${n}`);for(var l=e.size,d=e.width,h=e.height,g=Array(l),m=new Uint32Array(l),c=new Lm,p=1,u=0;u<h;u++)for(var f=0,b;f<d;f++)if(b=f+u*d,e.getBit(b)){for(var _=null,w=0;w<r.length;w++){var x=f+o[w],y=u+s[w];if(0<=x&&0<=y&&x<d&&y<h){var v=g[x+y*d];v?(r[w]=v,(!_||r[w].value<_.value)&&(_=r[w])):r[w]=null}}if(!_)g[b]=c.add(p++);else{g[b]=_;for(var D=0;D<r.length;D++)r[D]&&r[D]!==_&&c.union(_,r[D])}}for(var S=0;S<h;S++)for(var M=0,P;M<d;M++)P=M+S*d,e.getBit(P)&&(m[P]=c.find(g[P]).value);return new Ym(e,m)}function Cs(){function e(e){for(var i=e.maxima,a=!(i!==void 0)||i,n=1;n<d.height-1;n++)for(var s=1,r;s<d.width-1;s++)if(r=s+n*d.width,0===c[r]){var l=a?d.data[r]:-d.data[s+n*d.width];if(d.data[n*d.width+s-1]>l)continue;if(d.data[n*d.width+s+1]>l)continue;if(d.data[(n-1)*d.width+s]>l)continue;if(d.data[(n+1)*d.width+s]>l)continue;if(o){if(d.data[(n-1)*d.width+s-1]>l)continue;if(d.data[(n-1)*d.width+s+1]>l)continue;if(d.data[(n+1)*d.width+s-1]>l)continue;if(d.data[(n+1)*d.width+s+1]>l)continue}m[r]=a?++h:--g;var p=t(s,n,1);p||(a?--h:++g)}}function t(e,t){var a=_;x=0,v=1,w[0]=e,k[0]=t;for(var n=!0;x<v;){var o=w[x&1048575],s=k[x&1048575];n&=i(o,s,1),x++}if(!n){for(var r=0;r<v;r++){var l=w[r&1048575],h=k[r&1048575],g=h*d.width+l;m[g]=0}_=a}return n}function i(e,t,i){for(var a=m[t*d.width+e],n=d.data[t*d.width+e],o=t-1;o<=t+1;o++)for(var s=e-1,l;s<=e+1;s++)if(l=o*d.width+s,0===c[l])switch(c[l]=1,p[l]=d.data[l]-n,i){case 1:if(0===p[l]){if(0===s||0===o||s===d.width-1||o===d.height-1)return!1;m[l]=a,w[1048575&v]=s,k[1048575&v]=o,v++}else{if(0<p[l])return!1;r||(m[l]=a,u[1048575&_]=s,f[1048575&_]=o,_++)}break;case 2:0>=p[l]&&(m[l]=a,u[1048575&_]=s,f[1048575&_]=o,_++);break;default:throw new Error('unreachable');}return!0}var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},n=a.allowCorner,o=!(n!==void 0)||n,s=a.onlyTop,r=s!==void 0&&s,l=a.invert,d=this;d.checkProcessable('fromMaxima',{components:[1]});var h=0,g=0,m=new Int16Array(d.size),c=new Int8Array(d.size),p=new Float32Array(d.size),u=new Uint16Array(1048576),f=new Uint16Array(1048576),b=0,_=0,w=new Uint16Array(1048576),k=new Uint16Array(1048576),x=0,v=0;for(e(d,{maxima:!(l!==void 0&&l)});b<_;){var y=u[b&1048575],D=f[b&1048575];i(y,D,2),b++}return new Ym(d,m)}function Rs(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.points,a=e.mask,n=e.image,o=e.fillMaxValue,s=o===void 0?this.maxValue:o,r=e.invert,l=r!==void 0&&r,d=n||this;d.checkProcessable('fromWaterShed',{bitDepth:[8,16],components:1}),l=!l,t||(t=d.getLocalMaxima({invert:l,mask:a}));for(var h=l?0:1,g=new Int16Array(d.size),m=d.width,c=d.height,p=new Gm({comparator:(e,t)=>e[2]-t[2],strategy:Gm.BinaryHeapStrategy}),u=0,f;u<t.length;u++){f=t[u][0]+t[u][1]*m,g[f]=u+1;var b=d.data[f];(l&&b<=s||!l&&b>=s)&&p.queue([t[u][0],t[u][1],b])}for(;0<p.length;)for(var _=p.dequeue(),w=_[0]+_[1]*m,x=0;4>x;x++){var k=_[0]+Om[x],y=_[1]+Nm[x];if(0<=k&&0<=y&&k<m&&y<c){var v=k+y*m;if(!a||a.getBit(v)===h){var D=d.data[v];(l&&D<=s||!l&&D>=s)&&0===g[v]&&(g[v]=g[w],p.queue([_[0]+Om[x],_[1]+Nm[x],D]))}}}return new Ym(d,g)}function As(e){for(var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=new zm(t),n=new Int16Array(this.size),o=0,s=a.getPoints(),r=0;r<e.length;r++){o++;for(var l=e[r][0],d=e[r][1],h=0;h<s.length;h++){var g=s[h][0],m=s[h][1];0<=l+g&&0<=d+m&&l+g<this.width&&d+m<this.height&&(n[l+g+(d+m)*this.width]=o)}}return new Ym(this,n)}function zs(e,t,i){var a=e*t,n=134217729*e,o=n-(n-e),s=e-o,r=134217729*t,l=r-(r-t),d=t-l,h=s*d-(a-o*l-s*l-o*d);return i?(i[0]=h,i[1]=a,i):[h,a]}function Ys(e,t){var i=e+t,a=i-e,n=e-(i-a)+(t-a);return n?[n,i]:[i]}function Ls(o,e){var s=o.length;if(1===s){var n=Hm(o[0],e);return n[0]?n:[n[1]]}var r=Array(2*s),l=[.1,.1],d=[.1,.1],t=0;Hm(o[0],e,l),l[0]&&(r[t++]=l[0]);for(var h=1;h<s;++h){Hm(o[h],e,d);var g=l[1];Wm(g,d[0],l),l[0]&&(r[t++]=l[0]);var m=d[1],a=l[1],c=m+a,p=a-(c-m);l[1]=c,p&&(r[t++]=p)}return l[1]&&(r[t++]=l[1]),0===t&&(r[t++]=0),r.length=t,r}function Es(e,t){var i=e+t,a=i-e,n=e-(i-a)+(t-a);return n?[n,i]:[i]}function Ts(e,t){for(var o=t[0],r=t[1],l=e.length,n=1,d=l,h=0,g=l-1;h<d;g=h++){var m=e[h],a=e[g],u=m[1],f=a[1];if(f<u){if(f<r&&r<u){var b=Km(m,a,t);if(0===b)return 0;n^=0|0<b}else if(r===u){var _=e[(h+1)%l],w=_[1];if(u<w){var b=Km(m,a,t);if(0===b)return 0;n^=0|0<b}}}else if(u<f){if(u<r&&r<f){var b=Km(m,a,t);if(0===b)return 0;n^=0|0>b}else if(r===u){var _=e[(h+1)%l],w=_[1];if(w<u){var b=Km(m,a,t);if(0===b)return 0;n^=0|0>b}}}else if(r===u){var x=hr(m[0],a[0]),y=dr(m[0],a[0]);if(0===h){for(;0<g;){var v=(g+l-1)%l,k=e[v];if(k[1]!==r)break;var D=k[0];x=hr(x,D),y=dr(y,D),g=v}if(0===g)return x<=o&&o<=y?0:1;d=g+1}for(var S=e[(g+l-1)%l][1];h+1<d;){var k=e[h+1];if(k[1]!==r)break;var D=k[0];x=hr(x,D),y=dr(y,D),h+=1}if(x<=o&&o<=y)return 0;var M=e[(h+1)%l][1];o<x&&S<r!=M<r&&(n^=1)}}return 2*n-1}function Fs(e){for(var t=e.map,i=t.data,a=new Set,n=new Map,o=new Set,s=[1,0,-1,0],r=[0,1,0,-1],l=e.minX;l<=e.maxX;l++)for(var d=e.minY,h;d<=e.maxY;d++)if(h=l+d*t.width,i[h]===e.id)for(var g=0;4>g;g++){var m=l+s[g],c=d+r[g];if(0<=m&&0<=c&&m<t.width&&c<t.height){var p=m+c*t.width;if(i[p]!==e.id&&!o.has(p)){o.add(p),a.add(i[p]);var u=n.get(i[p]);u?n.set(i[p],++u):n.set(i[p],1)}}}var f=Array.from(a),b=f.map(function(e){return n.get(e)});return{ids:f,lengths:b}}function Xs(e){var t=new Set,i=e.map,a=i.data;for(var n of[0,e.height-1])for(var o=0,s;o<e.width;o++){if(s=(n+e.minY)*i.width+o+e.minX,0<o-e.minX&&a[s]===e.id&&a[s-1]!==e.id){var r=a[s-1];t.add(r)}if(1<i.width-o-e.minX&&a[s]===e.id&&a[s+1]!==e.id){var l=a[s+1];t.add(l)}}for(var d of[0,e.width-1])for(var h=0,g;h<e.height;h++){if(g=(h+e.minY)*i.width+d+e.minX,0<h-e.minY&&a[g]===e.id&&a[g-i.width]!==e.id){var m=a[g-i.width];t.add(m)}if(1<i.height-h-e.minY&&a[g]===e.id&&a[g+i.width]!==e.id){var c=a[g+i.width];t.add(c)}}return Array.from(t)}function Vs(e){var t=0,i=e.map,a=i.data,n=[0];1<e.height&&(n[1]=e.height-1);for(var o of n)for(var s=1,r;s<e.width-1;s++)r=(o+e.minY)*i.width+s+e.minX,a[r]===e.id&&t++;var l=[0];1<e.width&&(l[1]=e.width-1);for(var d of l)for(var h=0,g;h<e.height;h++)g=(h+e.minY)*i.width+d+e.minX,a[g]===e.id&&t++;return t}function Us(e){for(var t=0,i=e.map,a=i.data,n=1;n<e.width-1;n++)for(var o=1,s;o<e.height-1;o++)s=(o+e.minY)*i.width+n+e.minX,a[s]===e.id&&(a[s-1]!==e.id||a[s+1]!==e.id||a[s-i.width]!==e.id||a[s+i.width]!==e.id)&&t++;return t+e.box}function Gs(e){for(var t=0,i=e.map,a=i.data,n=1;n<e.width-1;n++)for(var o=1,s;o<e.height-1;o++)s=(o+e.minY)*i.width+n+e.minX,a[s]===e.id&&(e.externalIDs.includes(a[s-1])||e.externalIDs.includes(a[s+1])||e.externalIDs.includes(a[s-i.width])||e.externalIDs.includes(a[s+i.width]))&&t++;return t+e.box}function Os(e){var t=[e.id],a=e.map,n=a.data;if(2<e.height)for(var o=0,s;o<e.width;o++)if(s=e.minY*a.width+o+e.minX,t.includes(n[s])){var r=n[s+a.width];t.includes(r)||e.boxIDs.includes(r)||t.push(r)}for(var l=[,,,,],d=1;d<e.width-1;d++)for(var h=1,g;h<e.height-1;h++)if(g=(h+e.minY)*a.width+d+e.minX,t.includes(n[g])){l[0]=n[g-1],l[1]=n[g+1],l[2]=n[g-a.width],l[3]=n[g+a.width];for(var m=0,c;4>m;m++)c=l[m],t.includes(c)||e.boxIDs.includes(c)||t.push(c)}return t}function Ns(e,t,a,n,o){for(var s={id:[],surface:[],roiSurfaceCovered:[],same:0,opposite:0,total:0},r=0;r<a.length;r++){var l=a[r],d=l[0],h=l[1],g=d+e+(h+t)*n.width,m=n.data[g];(0<m||0>m)&&(s.id.includes(m)?s.surface[s.id.indexOf(m)]+=1:(s.id.push(m),s.surface.push(1)))}for(var c=0,p;c<s.id.length;c++)p=Zs(s.id[c]),p===o?s.same+=s.surface[c]:s.opposite+=s.surface[c],s.roiSurfaceCovered[c]=s.surface[c]/a.length;return s.total=s.opposite+s.same,s}function Hs(e,t,a){var n=Array(t),o=void 0,s=void 0,r=void 0,l=void 0;a||(a=100),a*=-1;var d=(t-1)/2,h=2*e*e;for(o=0;o<t;o++)for(n[o]=Array(t),l=(o-d)*(o-d),s=0;s<t;s++)r=(s-d)*(s-d),n[o][s]=ar(a*(1-(r+l)/h)*rr(-(r+l)/h));return n}function qs(e,t){if('string'!=typeof e&&'function'!=typeof e)throw new TypeError('func argument must be a function');if(void 0===t&&(t={}),'object'!=typeof t||null===t)throw new TypeError('options argument must be an object');this._workerCode=e.toString(),this._numWorkers=void 0===t.maxWorkers||'auto'===t.maxWorkers?hr(oc-1,1):0<t.maxWorkers?hr(t.maxWorkers,oc):oc,this._workers=new Map,this._timeout=t.timeout||0,this._terminateOnError=!!t.terminateOnError;var i=t.deps;'string'==typeof i&&(i=[i]),Array.isArray(i)||(i=void 0),this._id=0,this._terminated=!1,this._working=0,this._waiting=[],this._init(i)}function Ws(e,t,i){return e.post('data',[t,i]).then(function(e){for(var t in e)e[t]=new tc(e[t]);return e})}var Zs=Math.sign,Ks=Number.POSITIVE_INFINITY,Js=Math.atan2,Qs=Math.cos,$s=Number.MAX_VALUE,er=Math.log,tr=Number.MIN_VALUE,ir=Number.EPSILON,ar=Math.round,nr=Math.sqrt,or=Math.sin,sr=Math.PI,rr=Math.exp,lr=Number.isNaN,dr=Math.max,hr=Math.min,gr=Number.isInteger,mr=Math.abs,cr=Math.pow,pr=Math.ceil,ur=Math.floor,fr=String.fromCharCode,br={getBit(e){return this.data[t(e)]&1<<a(e)?1:0},setBit(e){this.data[t(e)]|=1<<a(e)},clearBit(e){this.data[t(e)]&=~(1<<a(e))},toggleBit(e){this.data[t(e)]^=1<<a(e)},getBitXY(e,t){return this.getBit(t*this.width+e)},setBitXY(e,t){this.setBit(t*this.width+e)},clearBitXY(e,t){this.clearBit(t*this.width+e)},toggleBitXY(e,t){this.toggleBit(t*this.width+e)}},_r='undefined'==typeof window?'undefined'==typeof global?'undefined'==typeof self?{}:self:global:window,wr=h(function(e,t){(function(i){function a(e){for(var t=[],i=0,a=e.length,n,o;i<a;)n=e.charCodeAt(i++),55296<=n&&56319>=n&&i<a?(o=e.charCodeAt(i++),56320==(64512&o)?t.push(((1023&n)<<10)+(1023&o)+65536):(t.push(n),i--)):t.push(n);return t}function n(e){for(var t=e.length,i=-1,a='',n;++i<t;)n=e[i],65535<n&&(n-=65536,a+=p(55296|1023&n>>>10),n=56320|1023&n),a+=p(n);return a}function o(e){if(55296<=e&&57343>=e)throw Error('Lone surrogate U+'+e.toString(16).toUpperCase()+' is not a scalar value')}function s(e,t){return p(128|63&e>>t)}function r(e){if(0==(4294967168&e))return p(e);var t='';return 0==(4294965248&e)?t=p(192|31&e>>6):0==(4294901760&e)?(o(e),t=p(224|15&e>>12),t+=s(e,6)):0==(4292870144&e)&&(t=p(240|7&e>>18),t+=s(e,12),t+=s(e,6)),t+=p(128|63&e),t}function l(){if(_>=b)throw Error('Invalid byte index');var e=255&f[_];if(_++,128==(192&e))return 63&e;throw Error('Invalid continuation byte')}function d(){var e,t,i,a,n;if(_>b)throw Error('Invalid byte index');if(_==b)return!1;if(e=255&f[_],_++,0==(128&e))return e;if(192==(224&e)){if(t=l(),n=(31&e)<<6|t,128<=n)return n;throw Error('Invalid continuation byte')}if(224==(240&e)){if(t=l(),i=l(),n=(15&e)<<12|t<<6|i,2048<=n)return o(n),n;throw Error('Invalid continuation byte')}if(240==(248&e)&&(t=l(),i=l(),a=l(),n=(7&e)<<18|t<<12|i<<6|a,65536<=n&&1114111>=n))return n;throw Error('Invalid UTF-8 detected')}function h(e){f=a(e),b=f.length,_=0;for(var t=[],i;!1!==(i=d());)t.push(i);return n(t)}var g=t,m=e&&e.exports==g&&e,c='object'==typeof _r&&_r;(c.global===c||c.window===c)&&(i=c);var p=fr,u={version:'2.1.2',encode:function(e){for(var t=a(e),i=t.length,n=-1,o='',s;++n<i;)s=t[n],o+=r(s);return o},decode:h},f,b,_;if(!g||g.nodeType)i.utf8=u;else if(m)m.exports=u;else{var w={}.hasOwnProperty;for(var x in u)w.call(u,x)&&(g[x]=u[x])}})(_r)});const xr=[];var kr=class{constructor(e,t){t=t||{};var i=!1;e===void 0&&(e=8192),'number'==typeof e?e=new ArrayBuffer(e):(i=!0,this._lastWrittenByte=e.byteLength);const a=t.offset?t.offset>>>0:0;let n=e.byteLength-a,o=a;e.buffer&&(e.byteLength!==e.buffer.byteLength&&(o=e.byteOffset+a),e=e.buffer),this._lastWrittenByte=i?n:0,this.buffer=e,this.length=n,this.byteLength=n,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,n),this._mark=0,this._marks=[]}available(e){return void 0===e&&(e=1),this.offset+e<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(e){return void 0===e&&(e=1),this.offset+=e,this}seek(e){return this.offset=e,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 e=this._marks.pop();if(void 0===e)throw new Error('Mark stack empty');return this.seek(e),this}rewind(){return this.offset=0,this}ensureAvailable(e){if(void 0===e&&(e=1),!this.available(e)){const t=this.offset+e,i=2*t,a=new Uint8Array(i);a.set(new Uint8Array(this.buffer)),this.buffer=a.buffer,this.length=this.byteLength=i,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(e){e===void 0&&(e=1);for(var t=new Uint8Array(e),a=0;a<e;a++)t[a]=this.readByte();return t}readInt16(){var e=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}readUint16(){var e=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}readInt32(){var e=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}readUint32(){var e=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat32(){var e=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat64(){var e=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}readChar(){return fr(this.readInt8())}readChars(e){e===void 0&&(e=1),xr.length=e;for(var t=0;t<e;t++)xr[t]=this.readChar();return xr.join('')}readUtf8(e){e===void 0&&(e=1);const t=this.readChars(e);return wr.decode(t)}writeBoolean(e){return this.writeUint8(e?255:0),this}writeInt8(e){return this.ensureAvailable(1),this._data.setInt8(this.offset++,e),this._updateLastWrittenByte(),this}writeUint8(e){return this.ensureAvailable(1),this._data.setUint8(this.offset++,e),this._updateLastWrittenByte(),this}writeByte(e){return this.writeUint8(e)}writeBytes(e){this.ensureAvailable(e.length);for(var t=0;t<e.length;t++)this._data.setUint8(this.offset++,e[t]);return this._updateLastWrittenByte(),this}writeInt16(e){return this.ensureAvailable(2),this._data.setInt16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(e){return this.ensureAvailable(2),this._data.setUint16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(e){return this.ensureAvailable(4),this._data.setInt32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(e){return this.ensureAvailable(4),this._data.setUint32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(e){return this.ensureAvailable(4),this._data.setFloat32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(e){return this.ensureAvailable(8),this._data.setFloat64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(e){return this.writeUint8(e.charCodeAt(0))}writeChars(e){for(var t=0;t<e.length;t++)this.writeUint8(e.charCodeAt(t));return this}writeUtf8(e){const t=wr.encode(e);return this.writeChars(t)}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this._lastWrittenByte)}getBuffer(){return'undefined'==typeof Buffer?this.toArray():Buffer.from(this.toArray())}_updateLastWrittenByte(){this.offset>this._lastWrittenByte&&(this._lastWrittenByte=this.offset)}},yr={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 vr=[];for(var Dr=0;8>=Dr;Dr++)vr.push(255<<Dr);var Sr=function(e){if(1!==e.bitDepth)throw new Error('Only bitDepth of 1 is supported');if(!e.height||!e.width)throw new Error('ImageData width and height are required');if(1!==e.components)throw new Error('Only 1 component is supported');if(1!==e.channels)throw new Error('Only 1 channel is supported');var t=new kr;t.skip(14),u(t,e),m(t,e);const i=t.offset;return g(t,e),t.rewind(),p(t,i),t.getBuffer()},Mr=h(function(e,t){function i(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var a='undefined'!=typeof Uint8Array&&'undefined'!=typeof Uint16Array&&'undefined'!=typeof Int32Array;t.assign=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var a=t.shift();if(a){if('object'!=typeof a)throw new TypeError(a+'must be non-object');for(var n in a)i(a,n)&&(e[n]=a[n])}}return e},t.shrinkBuf=function(e,t){return e.length===t?e:e.subarray?e.subarray(0,t):(e.length=t,e)};var n={arraySet:function(e,t,a,n,o){if(t.subarray&&e.subarray)return void e.set(t.subarray(a,a+n),o);for(var s=0;s<n;s++)e[o+s]=t[a+s]},flattenChunks:function(e){var t,a,n,o,s,r;for(n=0,t=0,a=e.length;t<a;t++)n+=e[t].length;for(r=new Uint8Array(n),o=0,(t=0,a=e.length);t<a;t++)s=e[t],r.set(s,o),o+=s.length;return r}},o={arraySet:function(e,t,a,n,o){for(var s=0;s<n;s++)e[o+s]=t[a+s]},flattenChunks:function(e){return[].concat.apply([],e)}};t.setTyped=function(e){e?(t.Buf8=Uint8Array,t.Buf16=Uint16Array,t.Buf32=Int32Array,t.assign(t,n)):(t.Buf8=Array,t.Buf16=Array,t.Buf32=Array,t.assign(t,o))},t.setTyped(a)}),jr=Mr.assign,Pr=Mr.shrinkBuf,Ir=Mr.setTyped,Br=Mr.Buf8,Cr=Mr.Buf16,Rr=Mr.Buf32,Ar=[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],zr=[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],Yr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],Lr=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Er=Array(576);f(Er);var Tr=Array(60);f(Tr);var Fr=Array(512);f(Fr);var Xr=Array(256);f(Xr);var Vr=Array(29);f(Vr);var Ur=Array(30);f(Ur);var Gr=!1,Or={_tr_init:X,_tr_stored_block:V,_tr_flush_block:function(e,t,i,a){var n=0,o,s;0<e.level?(e.strm.data_type===2&&(e.strm.data_type=F(e)),z(e,e.l_desc),z(e,e.d_desc),n=E(e),o=e.opt_len+3+7>>>3,s=e.static_len+3+7>>>3,s<=o&&(o=s)):o=s=i+5,i+4<=o&&-1!==t?V(e,t,i,a):e.strategy===4||s===o?(k(e,2+(a?1:0),3),A(e,Er,Tr)):(k(e,4+(a?1:0),3),T(e,e.l_desc.max_code+1,e.d_desc.max_code+1,n+1),A(e,e.dyn_ltree,e.dyn_dtree)),P(e),a&&I(e)},_tr_tally:function(e,t,i){return e.pending_buf[e.d_buf+2*e.last_lit]=255&t>>>8,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&i,e.last_lit++,0===t?e.dyn_ltree[2*i]++:(e.matches++,t--,e.dyn_ltree[2*(Xr[i]+256+1)]++,e.dyn_dtree[2*w(t)]++),e.last_lit===e.lit_bufsize-1},_tr_align:function(e){k(e,2,3),y(e,256,Er),D(e)}},Nr=function(e,t,i,a){for(var o=0|65535&e,s=0|65535&e>>>16,r=0;0!==i;){r=2e3<i?2e3:i,i-=r;do o=0|o+t[a++],s=0|s+o;while(--r);o%=65521,s%=65521}return 0|(o|s<<16)},Hr=U(),qr=G,Wr={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'},Zr,Kr,Jr,Qr;Qr=[new oe(0,0,0,0,function(e,t){var i=65535;for(i>e.pending_buf_size-5&&(i=e.pending_buf_size-5);;){if(1>=e.lookahead){if(ee(e),0===e.lookahead&&0===t)return 1;if(0===e.lookahead)break}e.strstart+=e.lookahead,e.lookahead=0;var a=e.block_start+i;if((0===e.strstart||e.strstart>=a)&&(e.lookahead=e.strstart-a,e.strstart=a,Z(e,!1),0===e.strm.avail_out))return 1;if(e.strstart-e.block_start>=e.w_size-262&&(Z(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,4===t?(Z(e,!0),0===e.strm.avail_out?3:4):e.strstart>e.block_start&&(Z(e,!1),0===e.strm.avail_out)?1:1}),new oe(4,4,8,4,te),new oe(4,5,16,8,te),new oe(4,6,32,32,te),new oe(4,4,16,16,ie),new oe(8,16,32,32,ie),new oe(8,16,128,128,ie),new oe(8,32,128,256,ie),new oe(32,128,258,1024,ie),new oe(32,258,258,4096,ie)];var $r={deflateInit:function(e,t){return he(e,t,8,15,8,0)},deflateInit2:he,deflateReset:de,deflateResetKeep:le,deflateSetHeader:function(e,t){return e&&e.state?2===e.state.wrap?(e.state.gzhead=t,0):-2:-2},deflate:ge,deflateEnd:function(e){var t;return e&&e.state?(t=e.state.status,42!==t&&69!==t&&73!==t&&91!==t&&103!==t&&113!==t&&666!==t)?O(e,-2):(e.state=null,113===t?O(e,-3):0):-2},deflateSetDictionary:function(e,t){var i=t.length,a,o,r,l,d,h,g,m;if(!e||!e.state)return -2;if(a=e.state,l=a.wrap,2===l||1===l&&42!==a.status||a.lookahead)return -2;for(1===l&&(e.adler=Nr(e.adler,t,i,0)),a.wrap=0,i>=a.w_size&&(0===l&&(H(a.head),a.strstart=0,a.block_start=0,a.insert=0),m=new Mr.Buf8(a.w_size),Mr.arraySet(m,t,i-a.w_size,a.w_size,0),t=m,i=a.w_size),d=e.avail_in,h=e.next_in,g=e.input,e.avail_in=i,e.next_in=0,e.input=t,ee(a);3<=a.lookahead;){o=a.strstart,r=a.lookahead-2;do a.ins_h=(a.ins_h<<a.hash_shift^a.window[o+3-1])&a.hash_mask,a.prev[o&a.w_mask]=a.head[a.ins_h],a.head[a.ins_h]=o,o++;while(--r);a.strstart=o,a.lookahead=2,ee(a)}return a.strstart+=a.lookahead,a.block_start=a.strstart,a.insert=a.lookahead,a.lookahead=0,a.match_length=a.prev_length=2,a.match_available=0,e.next_in=h,e.input=g,e.avail_in=d,a.wrap=l,0},deflateInfo:'pako deflate (from Nodeca project)'},el=!0,tl=!0;try{fr.apply(null,[0])}catch(e){el=!1}try{fr.apply(null,new Uint8Array(1))}catch(e){tl=!1}for(var il=new Mr.Buf8(256),al=0;256>al;al++)il[al]=252<=al?6:248<=al?5:240<=al?4:224<=al?3:192<=al?2:1;il[254]=il[254]=1;var nl=function(e){var t=e.length,a=0,n,o,s,r,l;for(r=0;r<t;r++)o=e.charCodeAt(r),55296==(64512&o)&&r+1<t&&(s=e.charCodeAt(r+1),56320==(64512&s)&&(o=65536+(o-55296<<10)+(s-56320),r++)),a+=128>o?1:2048>o?2:65536>o?3:4;for(n=new Mr.Buf8(a),l=0,r=0;l<a;r++)o=e.charCodeAt(r),55296==(64512&o)&&r+1<t&&(s=e.charCodeAt(r+1),56320==(64512&s)&&(o=65536+(o-55296<<10)+(s-56320),r++)),128>o?n[l++]=o:2048>o?(n[l++]=192|o>>>6,n[l++]=128|63&o):65536>o?(n[l++]=224|o>>>12,n[l++]=128|63&o>>>6,n[l++]=128|63&o):(n[l++]=240|o>>>18,n[l++]=128|63&o>>>12,n[l++]=128|63&o>>>6,n[l++]=128|63&o);return n},ol=function(e){for(var t=new Mr.Buf8(e.length),a=0,n=t.length;a<n;a++)t[a]=e.charCodeAt(a);return t},sl=function(e,t){var a=t||e.length,n=Array(2*a),o,s,r,l;for(s=0,o=0;o<a;){if(r=e[o++],128>r){n[s++]=r;continue}if(l=il[r],4<l){n[s++]=65533,o+=l-1;continue}for(r&=2===l?31:3===l?15:7;1<l&&o<a;)r=r<<6|63&e[o++],l--;if(1<l){n[s++]=65533;continue}65536>r?n[s++]=r:(r-=65536,n[s++]=55296|1023&r>>10,n[s++]=56320|1023&r)}return me(n,s)},rl={string2buf:nl,buf2binstring:function(e){return me(e,e.length)},binstring2buf:ol,buf2string:sl,utf8border:function(e,t){var i;for(t=t||e.length,t>e.length&&(t=e.length),i=t-1;0<=i&&128==(192&e[i]);)i--;return 0>i?t:0===i?t:i+il[e[i]]>t?i:t}},ll=function(){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},dl=Object.prototype.toString;ce.prototype.push=function(e,t){var i=this.strm,a=this.options.chunkSize,n,o;if(this.ended)return!1;o=t===~~t?t:!0===t?4:0,i.input='string'==typeof e?rl.string2buf(e):'[object ArrayBuffer]'===dl.call(e)?new Uint8Array(e):e,i.next_in=0,i.avail_in=i.input.length;do{if(0===i.avail_out&&(i.output=new Mr.Buf8(a),i.next_out=0,i.avail_out=a),n=$r.deflate(i,o),1!==n&&0!==n)return this.onEnd(n),this.ended=!0,!1;(0===i.avail_out||0===i.avail_in&&(4===o||2===o))&&('string'===this.options.to?this.onData(rl.buf2binstring(Mr.shrinkBuf(i.output,i.next_out))):this.onData(Mr.shrinkBuf(i.output,i.next_out)))}while((0<i.avail_in||0===i.avail_out)&&1!==n);return 4===o?(n=$r.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,0===n):2!==o||(this.onEnd(0),i.avail_out=0,!0)},ce.prototype.onData=function(e){this.chunks.push(e)},ce.prototype.onEnd=function(e){e===0&&('string'===this.options.to?this.result=this.chunks.join(''):this.result=Mr.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var hl=function(e,t){var i,a,n,o,s,r,l,d,h,g,m,c,p,u,f,b,_,w,x,k,y,v,D,S,M;i=e.state,a=e.next_in,S=e.input,n=a+(e.avail_in-5),o=e.next_out,M=e.output,s=o-(t-e.avail_out),r=o+(e.avail_out-257),l=i.dmax,d=i.wsize,h=i.whave,g=i.wnext,m=i.window,c=i.hold,p=i.bits,u=i.lencode,f=i.distcode,b=(1<<i.lenbits)-1,_=(1<<i.distbits)-1;top:do{15>p&&(c+=S[a++]<<p,p+=8,c+=S[a++]<<p,p+=8),w=u[c&b];dolen:for(;;){if(x=w>>>24,c>>>=x,p-=x,x=255&w>>>16,0===x)M[o++]=65535&w;else if(16&x){k=65535&w,x&=15,x&&(p<x&&(c+=S[a++]<<p,p+=8),k+=c&(1<<x)-1,c>>>=x,p-=x),15>p&&(c+=S[a++]<<p,p+=8,c+=S[a++]<<p,p+=8),w=f[c&_];dodist:for(;;){if(x=w>>>24,c>>>=x,p-=x,x=255&w>>>16,16&x){if(y=65535&w,x&=15,p<x&&(c+=S[a++]<<p,p+=8,p<x&&(c+=S[a++]<<p,p+=8)),y+=c&(1<<x)-1,y>l){e.msg='invalid distance too far back',i.mode=30;break top}if(c>>>=x,p-=x,x=o-s,y>x){if(x=y-x,x>h&&i.sane){e.msg='invalid distance too far back',i.mode=30;break top}if(v=0,D=m,0===g){if(v+=d-x,x<k){k-=x;do M[o++]=m[v++];while(--x);v=o-y,D=M}}else if(g<x){if(v+=d+g-x,x-=g,x<k){k-=x;do M[o++]=m[v++];while(--x);if(v=0,g<k){x=g,k-=x;do M[o++]=m[v++];while(--x);v=o-y,D=M}}}else if(v+=g-x,x<k){k-=x;do M[o++]=m[v++];while(--x);v=o-y,D=M}for(;2<k;)M[o++]=D[v++],M[o++]=D[v++],M[o++]=D[v++],k-=3;k&&(M[o++]=D[v++],1<k&&(M[o++]=D[v++]))}else{v=o-y;do M[o++]=M[v++],M[o++]=M[v++],M[o++]=M[v++],k-=3;while(2<k);k&&(M[o++]=M[v++],1<k&&(M[o++]=M[v++]))}}else if(0==(64&x)){w=f[(65535&w)+(c&(1<<x)-1)];continue dodist}else{e.msg='invalid distance code',i.mode=30;break top}break}}else if(0==(64&x)){w=u[(65535&w)+(c&(1<<x)-1)];continue dolen}else if(32&x){i.mode=12;break top}else{e.msg='invalid literal/length code',i.mode=30;break top}break}}while(a<n&&o<r);return k=p>>3,a-=k,p-=k<<3,c&=(1<<p)-1,e.next_in=a,e.next_out=o,e.avail_in=a<n?5+(n-a):5-(a-n),e.avail_out=o<r?257+(r-o):257-(o-r),i.hold=c,void(i.bits=p)},gl=[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],ml=[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],cl=[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],pl=[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],ul=function(e,t,i,a,n,o,s,r){var l=r.bits,d=0,h=0,g=0,m=0,c=0,p=0,u=0,f=0,b=0,_=0,w=null,x=0,k=new Mr.Buf16(16),y=new Mr.Buf16(16),v=null,D=0,S,M,j,P,I,B,C,R,A;for(d=0;15>=d;d++)k[d]=0;for(h=0;h<a;h++)k[t[i+h]]++;for(c=l,m=15;1<=m&&0===k[m];m--);if(c>m&&(c=m),0==m)return n[o++]=20971520,n[o++]=20971520,r.bits=1,0;for(g=1;g<m&&0===k[g];g++);for(c<g&&(c=g),f=1,d=1;15>=d;d++)if(f<<=1,f-=k[d],0>f)return-1;if(0<f&&(0===e||1!=m))return-1;for(y[1]=0,d=1;15>d;d++)y[d+1]=y[d]+k[d];for(h=0;h<a;h++)0!==t[i+h]&&(s[y[t[i+h]]++]=h);if(0===e?(w=v=s,B=19):1===e?(w=gl,x-=257,v=ml,D-=257,B=256):(w=cl,v=pl,B=-1),_=0,h=0,d=g,I=o,p=c,u=0,j=-1,b=1<<c,P=b-1,1===e&&852<b||2===e&&592<b)return 1;for(;;){C=d-u,s[h]<B?(R=0,A=s[h]):s[h]>B?(R=v[D+s[h]],A=w[x+s[h]]):(R=96,A=0),S=1<<d-u,M=1<<p,g=M;do M-=S,n[I+(_>>u)+M]=0|(C<<24|R<<16|A);while(0!==M);for(S=1<<d-1;_&S;)S>>=1;if(0===S?_=0:(_&=S-1,_+=S),h++,0==--k[d]){if(d===m)break;d=t[i+s[h]]}if(d>c&&(_&P)!==j){for(0==u&&(u=c),I+=g,p=d-u,f=1<<p;p+u<m&&(f-=k[p+u],!(0>=f));)p++,f<<=1;if(b+=1<<p,1===e&&852<b||2===e&&592<b)return 1;j=_&P,n[j]=0|(c<<24|p<<16|I-o)}}return 0!=_&&(n[I+_]=0|(4194304|d-u<<24)),r.bits=c,0},fl=!0,bl={inflateReset:_e,inflateReset2:we,inflateResetKeep:be,inflateInit:function(e){return xe(e,15)},inflateInit2:xe,inflate:function(e,t){var i=0,a=new Mr.Buf8(4),o=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],s,r,l,d,h,g,m,c,p,u,f,b,_,w,x,k,y,v,D,S,M,j,P,I;if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return -2;s=e.state,12===s.mode&&(s.mode=13),h=e.next_out,l=e.output,m=e.avail_out,d=e.next_in,r=e.input,g=e.avail_in,c=s.hold,p=s.bits,u=g,f=m,j=0;inf_leave:for(;;)switch(s.mode){case 1:if(0===s.wrap){s.mode=13;break}for(;16>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(2&s.wrap&&35615===c){s.check=0,a[0]=255&c,a[1]=255&c>>>8,s.check=qr(s.check,a,2,0),c=0,p=0,s.mode=2;break}if(s.flags=0,s.head&&(s.head.done=!1),!(1&s.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg='incorrect header check',s.mode=30;break}if(8!==(15&c)){e.msg='unknown compression method',s.mode=30;break}if(c>>>=4,p-=4,M=(15&c)+8,0===s.wbits)s.wbits=M;else if(M>s.wbits){e.msg='invalid window size',s.mode=30;break}s.dmax=1<<M,e.adler=s.check=1,s.mode=512&c?10:12,c=0,p=0;break;case 2:for(;16>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(s.flags=c,8!==(255&s.flags)){e.msg='unknown compression method',s.mode=30;break}if(57344&s.flags){e.msg='unknown header flags set',s.mode=30;break}s.head&&(s.head.text=1&c>>8),512&s.flags&&(a[0]=255&c,a[1]=255&c>>>8,s.check=qr(s.check,a,2,0)),c=0,p=0,s.mode=3;case 3:for(;32>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}s.head&&(s.head.time=c),512&s.flags&&(a[0]=255&c,a[1]=255&c>>>8,a[2]=255&c>>>16,a[3]=255&c>>>24,s.check=qr(s.check,a,4,0)),c=0,p=0,s.mode=4;case 4:for(;16>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}s.head&&(s.head.xflags=255&c,s.head.os=c>>8),512&s.flags&&(a[0]=255&c,a[1]=255&c>>>8,s.check=qr(s.check,a,2,0)),c=0,p=0,s.mode=5;case 5:if(1024&s.flags){for(;16>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}s.length=c,s.head&&(s.head.extra_len=c),512&s.flags&&(a[0]=255&c,a[1]=255&c>>>8,s.check=qr(s.check,a,2,0)),c=0,p=0}else s.head&&(s.head.extra=null);s.mode=6;case 6:if(1024&s.flags&&(b=s.length,b>g&&(b=g),b&&(s.head&&(M=s.head.extra_len-s.length,!s.head.extra&&(s.head.extra=Array(s.head.extra_len)),Mr.arraySet(s.head.extra,r,d,b,M)),512&s.flags&&(s.check=qr(s.check,r,b,d)),g-=b,d+=b,s.length-=b),s.length))break inf_leave;s.length=0,s.mode=7;case 7:if(2048&s.flags){if(0===g)break inf_leave;b=0;do M=r[d+b++],s.head&&M&&65536>s.length&&(s.head.name+=fr(M));while(M&&b<g);if(512&s.flags&&(s.check=qr(s.check,r,b,d)),g-=b,d+=b,M)break inf_leave}else s.head&&(s.head.name=null);s.length=0,s.mode=8;case 8:if(4096&s.flags){if(0===g)break inf_leave;b=0;do M=r[d+b++],s.head&&M&&65536>s.length&&(s.head.comment+=fr(M));while(M&&b<g);if(512&s.flags&&(s.check=qr(s.check,r,b,d)),g-=b,d+=b,M)break inf_leave}else s.head&&(s.head.comment=null);s.mode=9;case 9:if(512&s.flags){for(;16>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(c!==(65535&s.check)){e.msg='header crc mismatch',s.mode=30;break}c=0,p=0}s.head&&(s.head.hcrc=1&s.flags>>9,s.head.done=!0),e.adler=s.check=0,s.mode=12;break;case 10:for(;32>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}e.adler=s.check=ue(c),c=0,p=0,s.mode=11;case 11:if(0===s.havedict)return e.next_out=h,e.avail_out=m,e.next_in=d,e.avail_in=g,s.hold=c,s.bits=p,2;e.adler=s.check=1,s.mode=12;case 12:if(5===t||6===t)break inf_leave;case 13:if(s.last){c>>>=7&p,p-=7&p,s.mode=27;break}for(;3>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}switch(s.last=1&c,c>>>=1,p-=1,3&c){case 0:s.mode=14;break;case 1:if(ke(s),s.mode=20,6===t){c>>>=2,p-=2;break inf_leave}break;case 2:s.mode=17;break;case 3:e.msg='invalid block type',s.mode=30;}c>>>=2,p-=2;break;case 14:for(c>>>=7&p,p-=7&p;32>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if((65535&c)!=(65535^c>>>16)){e.msg='invalid stored block lengths',s.mode=30;break}if(s.length=65535&c,c=0,p=0,s.mode=15,6===t)break inf_leave;case 15:s.mode=16;case 16:if(b=s.length,b){if(b>g&&(b=g),b>m&&(b=m),0===b)break inf_leave;Mr.arraySet(l,r,d,b,h),g-=b,d+=b,m-=b,h+=b,s.length-=b;break}s.mode=12;break;case 17:for(;14>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(s.nlen=(31&c)+257,c>>>=5,p-=5,s.ndist=(31&c)+1,c>>>=5,p-=5,s.ncode=(15&c)+4,c>>>=4,p-=4,286<s.nlen||30<s.ndist){e.msg='too many length or distance symbols',s.mode=30;break}s.have=0,s.mode=18;case 18:for(;s.have<s.ncode;){for(;3>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}s.lens[o[s.have++]]=7&c,c>>>=3,p-=3}for(;19>s.have;)s.lens[o[s.have++]]=0;if(s.lencode=s.lendyn,s.lenbits=7,P={bits:s.lenbits},j=ul(0,s.lens,0,19,s.lencode,0,s.work,P),s.lenbits=P.bits,j){e.msg='invalid code lengths set',s.mode=30;break}s.have=0,s.mode=19;case 19:for(;s.have<s.nlen+s.ndist;){for(;;){if(i=s.lencode[c&(1<<s.lenbits)-1],x=i>>>24,k=255&i>>>16,y=65535&i,x<=p)break;if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(16>y)c>>>=x,p-=x,s.lens[s.have++]=y;else{if(16===y){for(I=x+2;p<I;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(c>>>=x,p-=x,0===s.have){e.msg='invalid bit length repeat',s.mode=30;break}M=s.lens[s.have-1],b=3+(3&c),c>>>=2,p-=2}else if(17===y){for(I=x+3;p<I;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}c>>>=x,p-=x,M=0,b=3+(7&c),c>>>=3,p-=3}else{for(I=x+7;p<I;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}c>>>=x,p-=x,M=0,b=11+(127&c),c>>>=7,p-=7}if(s.have+b>s.nlen+s.ndist){e.msg='invalid bit length repeat',s.mode=30;break}for(;b--;)s.lens[s.have++]=M}}if(30===s.mode)break;if(0===s.lens[256]){e.msg='invalid code -- missing end-of-block',s.mode=30;break}if(s.lenbits=9,P={bits:s.lenbits},j=ul(1,s.lens,0,s.nlen,s.lencode,0,s.work,P),s.lenbits=P.bits,j){e.msg='invalid literal/lengths set',s.mode=30;break}if(s.distbits=6,s.distcode=s.distdyn,P={bits:s.distbits},j=ul(2,s.lens,s.nlen,s.ndist,s.distcode,0,s.work,P),s.distbits=P.bits,j){e.msg='invalid distances set',s.mode=30;break}if(s.mode=20,6===t)break inf_leave;case 20:s.mode=21;case 21:if(6<=g&&258<=m){e.next_out=h,e.avail_out=m,e.next_in=d,e.avail_in=g,s.hold=c,s.bits=p,hl(e,f),h=e.next_out,l=e.output,m=e.avail_out,d=e.next_in,r=e.input,g=e.avail_in,c=s.hold,p=s.bits,12===s.mode&&(s.back=-1);break}for(s.back=0;;){if(i=s.lencode[c&(1<<s.lenbits)-1],x=i>>>24,k=255&i>>>16,y=65535&i,x<=p)break;if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(k&&0==(240&k)){for(v=x,D=k,S=y;;){if(i=s.lencode[S+((c&(1<<v+D)-1)>>v)],x=i>>>24,k=255&i>>>16,y=65535&i,v+x<=p)break;if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}c>>>=v,p-=v,s.back+=v}if(c>>>=x,p-=x,s.back+=x,s.length=y,0===k){s.mode=26;break}if(32&k){s.back=-1,s.mode=12;break}if(64&k){e.msg='invalid literal/length code',s.mode=30;break}s.extra=15&k,s.mode=22;case 22:if(s.extra){for(I=s.extra;p<I;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}s.length+=c&(1<<s.extra)-1,c>>>=s.extra,p-=s.extra,s.back+=s.extra}s.was=s.length,s.mode=23;case 23:for(;;){if(i=s.distcode[c&(1<<s.distbits)-1],x=i>>>24,k=255&i>>>16,y=65535&i,x<=p)break;if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(0==(240&k)){for(v=x,D=k,S=y;;){if(i=s.distcode[S+((c&(1<<v+D)-1)>>v)],x=i>>>24,k=255&i>>>16,y=65535&i,v+x<=p)break;if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}c>>>=v,p-=v,s.back+=v}if(c>>>=x,p-=x,s.back+=x,64&k){e.msg='invalid distance code',s.mode=30;break}s.offset=y,s.extra=15&k,s.mode=24;case 24:if(s.extra){for(I=s.extra;p<I;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}s.offset+=c&(1<<s.extra)-1,c>>>=s.extra,p-=s.extra,s.back+=s.extra}if(s.offset>s.dmax){e.msg='invalid distance too far back',s.mode=30;break}s.mode=25;case 25:if(0===m)break inf_leave;if(b=f-m,s.offset>b){if(b=s.offset-b,b>s.whave&&s.sane){e.msg='invalid distance too far back',s.mode=30;break}b>s.wnext?(b-=s.wnext,_=s.wsize-b):_=s.wnext-b,b>s.length&&(b=s.length),w=s.window}else w=l,_=h-s.offset,b=s.length;b>m&&(b=m),m-=b,s.length-=b;do l[h++]=w[_++];while(--b);0===s.length&&(s.mode=21);break;case 26:if(0===m)break inf_leave;l[h++]=s.length,m--,s.mode=21;break;case 27:if(s.wrap){for(;32>p;){if(0===g)break inf_leave;g--,c|=r[d++]<<p,p+=8}if(f-=m,e.total_out+=f,s.total+=f,f&&(e.adler=s.check=s.flags?qr(s.check,l,f,h-f):Nr(s.check,l,f,h-f)),f=m,(s.flags?c:ue(c))!==s.check){e.msg='incorrect data check',s.mode=30;break}c=0,p=0}s.mode=28;case 28:if(s.wrap&&s.flags){for(;32>p;){if(0===g)break inf_leave;g--,c+=r[d++]<<p,p+=8}if(c!==(4294967295&s.total)){e.msg='incorrect length check',s.mode=30;break}c=0,p=0}s.mode=29;case 29:j=1;break inf_leave;case 30:j=-3;break inf_leave;case 31:return -4;case 32:default:return -2;}if(e.next_out=h,e.avail_out=m,e.next_in=d,e.avail_in=g,s.hold=c,s.bits=p,(s.wsize||f!==e.avail_out&&30>s.mode&&(27>s.mode||4!==t))&&ye(e,e.output,e.next_out,f-e.avail_out));return u-=e.avail_in,f-=e.avail_out,e.total_in+=u,e.total_out+=f,s.total+=f,s.wrap&&f&&(e.adler=s.check=s.flags?qr(s.check,l,f,e.next_out-f):Nr(s.check,l,f,e.next_out-f)),e.data_type=s.bits+(s.last?64:0)+(12===s.mode?128:0)+(20===s.mode||15===s.mode?256:0),(0===u&&0===f||4===t)&&0===j&&(j=-5),j},inflateEnd:function(e){if(!e||!e.state)return -2;var t=e.state;return t.window&&(t.window=null),e.state=null,0},inflateGetHeader:function(e,t){var i;return e&&e.state?(i=e.state,0==(2&i.wrap))?-2:(i.head=t,t.done=!1,0):-2},inflateSetDictionary:function(e,t){var i=t.length,a,n,o;return e&&e.state?(a=e.state,0!==a.wrap&&11!==a.mode)?-2:11===a.mode&&(n=1,n=Nr(n,t,i,0),n!==a.check)?-3:(o=ye(e,t,i,i),o)?(a.mode=31,-4):(a.havedict=1,0):-2},inflateInfo:'pako inflate (from Nodeca project)'},_l={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},wl=function(){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},xl=Object.prototype.toString,kl,yl;ve.prototype.push=function(e,t){var i=this.strm,a=this.options.chunkSize,n=this.options.dictionary,o=!1,s,r,l,d,h,g;if(this.ended)return!1;r=t===~~t?t:!0===t?_l.Z_FINISH:_l.Z_NO_FLUSH,i.input='string'==typeof e?rl.binstring2buf(e):'[object ArrayBuffer]'===xl.call(e)?new Uint8Array(e):e,i.next_in=0,i.avail_in=i.input.length;do{if(0===i.avail_out&&(i.output=new Mr.Buf8(a),i.next_out=0,i.avail_out=a),s=bl.inflate(i,_l.Z_NO_FLUSH),s===_l.Z_NEED_DICT&&n&&(g='string'==typeof n?rl.string2buf(n):'[object ArrayBuffer]'===xl.call(n)?new Uint8Array(n):n,s=bl.inflateSetDictionary(this.strm,g)),s===_l.Z_BUF_ERROR&&!0==o&&(s=_l.Z_OK,o=!1),s!==_l.Z_STREAM_END&&s!==_l.Z_OK)return this.onEnd(s),this.ended=!0,!1;i.next_out&&(0===i.avail_out||s===_l.Z_STREAM_END||0===i.avail_in&&(r===_l.Z_FINISH||r===_l.Z_SYNC_FLUSH))&&('string'===this.options.to?(l=rl.utf8border(i.output,i.next_out),d=i.next_out-l,h=rl.buf2string(i.output,l),i.next_out=d,i.avail_out=a-d,d&&Mr.arraySet(i.output,i.output,l,d,0),this.onData(h)):this.onData(Mr.shrinkBuf(i.output,i.next_out))),0===i.avail_in&&0===i.avail_out&&(o=!0)}while((0<i.avail_in||0===i.avail_out)&&s!==_l.Z_STREAM_END);return s===_l.Z_STREAM_END&&(r=_l.Z_FINISH),r===_l.Z_FINISH?(s=bl.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,s===_l.Z_OK):r!==_l.Z_SYNC_FLUSH||(this.onEnd(_l.Z_OK),i.avail_out=0,!0)},ve.prototype.onData=function(e){this.chunks.push(e)},ve.prototype.onEnd=function(e){e===_l.Z_OK&&('string'===this.options.to?this.result=this.chunks.join(''):this.result=Mr.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var vl=Mr.assign,Dl={};vl(Dl,{Deflate:ce,deflate:pe,deflateRaw:function(e,t){return t=t||{},t.raw=!0,pe(e,t)},gzip:function(e,t){return t=t||{},t.gzip=!0,pe(e,t)}},{Inflate:ve,inflate:De,inflateRaw:function(e,t){return t=t||{},t.raw=!0,De(e,t)},ungzip:De},_l);var Sl=Dl,Ml=Sl.Inflate,jl=Sl.deflate;const Pl=[137,80,78,71,13,10,26,10],Il=[];for(let t=0;256>t;t++){var Bl=t;for(let e=0;8>e;e++)1&Bl?Bl=3988292384^Bl>>>1:Bl>>>=1;Il[t]=Bl}const Cl=4294967295,Rl=new Uint8Array(0),Al=new Uint16Array([255]),zl=new Uint8Array(Al.buffer),Yl=255===zl[0];class Ll extends kr{constructor(e,t){super(e);const{checkCrc:i=!1}=t;this._checkCrc=i,this._inflator=new Ml,this._png=null,this._end=!1,this.setBigEndian()}decode(){for(this._png={text:{}},this.decodeSignature();!this._end;)this.decodeChunk();return this.decodeImage(),this._png}decodeSignature(){for(var e=0;e<Pl.length;e++)if(this.readUint8()!==Pl[e])throw new Error(`wrong PNG signature. Byte at ${e} should be ${Pl[e]}.`)}decodeChunk(){const e=this.readUint32(),t=this.readChars(4),i=this.offset;switch(t){case'IHDR':this.decodeIHDR();break;case'PLTE':this.decodePLTE(e);break;case'IDAT':this.decodeIDAT(e);break;case'IEND':this._end=!0;break;case'tEXt':this.decodetEXt(e);break;case'pHYs':this.decodepHYs();break;default:this.skip(e);}if(this.offset-i!==e)throw new Error(`Length mismatch while decoding chunk ${t}`);if(this._checkCrc){const i=this.readUint32(),a=e+4,n=Me(new Uint8Array(this.buffer,this.byteOffset+this.offset-a-4,a),a);if(n!==i)throw new Error(`CRC mismatch for chunk ${t}. Expected ${i}, found ${n}`)}else this.skip(4)}decodeIHDR(){var e=this._png;if(e.width=this.readUint32(),e.height=this.readUint32(),e.bitDepth=this.readUint8(),e.colourType=this.readUint8(),e.compressionMethod=this.readUint8(),e.filterMethod=this.readUint8(),e.interlaceMethod=this.readUint8(),0!==this._png.compressionMethod)throw new Error('Unsupported compression method: '+e.compressionMethod)}decodePLTE(e){if(0!=e%3)throw new RangeError('PLTE field length must be a multiple of 3. Got '+e);var t=e/3;this._hasPalette=!0;for(var a=this._palette=Array(t),n=0;n<t;n++)a[n]=[this.readUint8(),this.readUint8(),this.readUint8()]}decodeIDAT(e){this._inflator.push(new Uint8Array(this.buffer,this.offset+this.byteOffset,e),!1),this.skip(e)}decodetEXt(e){for(var t='',i;(i=this.readChar())!=='\0';)t+=i;this._png.text[t]=this.readChars(e-t.length-1)}decodepHYs(){const e=this.readUint32(),t=this.readUint32(),i=this.readByte();this._png.resolution=[e,t],this._png.unitSpecifier=i}decodeImage(){if(this._inflator.push(Rl,!0),this._inflator.err)throw new Error('Error while decompressing the data: '+this._inflator.err);var e=this._inflator.result;if(this._inflator=null,0!==this._png.filterMethod)throw new Error('Filter method '+this._png.filterMethod+' not supported');if(0===this._png.interlaceMethod)this.decodeInterlaceNull(e);else throw new Error('Interlace method '+this._png.interlaceMethod+' not supported')}decodeInterlaceNull(e){var t;switch(this._png.colourType){case 0:t=1;break;case 2:t=3;break;case 3:if(!this._hasPalette)throw new Error('Missing palette');t=1;break;case 4:t=2;break;case 6:t=4;break;default:throw new Error('Unknown colour type: '+this._png.colourType);}const a=this._png.height,n=t*this._png.bitDepth/8,o=this._png.width*n,s=new Uint8Array(this._png.height*o);for(var r=Rl,l=0,d=0,h,g;d<a;d++){switch(h=e.subarray(l+1,l+1+o),g=s.subarray(d*o,(d+1)*o),e[l]){case 0:je(h,g,o);break;case 1:Pe(h,g,o,n);break;case 2:Ie(h,g,r,o);break;case 3:Be(h,g,r,o,n);break;case 4:Ce(h,g,r,o,n);break;default:throw new Error('Unsupported filter: '+e[l]);}r=g,l+=o+1}if(this._hasPalette&&(this._png.palette=this._palette),16===this._png.bitDepth){const e=new Uint16Array(s.buffer);if(Yl)for(var m=0;m<e.length;m++)e[m]=Ae(e[m]);this._png.data=e}else this._png.data=s}}const El={level:3};class Tl extends kr{constructor(e,t){super(),this._checkData(e),this._zlibOptions=Object.assign({},El,t.zlib),this.setBigEndian()}encode(){return this.encodeSignature(),this.encodeIHDR(),this.encodeData(),this.encodeIEND(),this.toArray()}encodeSignature(){this.writeBytes(Pl)}encodeIHDR(){this.writeUint32(13),this.writeChars('IHDR'),this.writeUint32(this._png.width),this.writeUint32(this._png.height),this.writeByte(this._png.bitDepth),this.writeByte(this._png.colourType),this.writeByte(0),this.writeByte(0),this.writeByte(0),this.writeCrc(17)}encodeIEND(){this.writeUint32(0),this.writeChars('IEND'),this.writeCrc(4)}encodeIDAT(e){this.writeUint32(e.length),this.writeChars('IDAT'),this.writeBytes(e),this.writeCrc(e.length+4)}encodeData(){const{width:e,height:t,channels:a,bitDepth:n,data:o}=this._png,s=a*e,r=new kr().setBigEndian();for(var l=0,d=0;d<t;d++)if(r.writeByte(0),8===n)l=Le(o,r,s,l);else if(16===n)l=Ee(o,r,s,l);else throw new Error('unreachable');const h=r.getBuffer(),g=jl(h,this._zlibOptions);this.encodeIDAT(g)}_checkData(e){this._png={width:ze(e.width,'width'),height:ze(e.height,'height'),data:e.data};const{colourType:t,channels:i,bitDepth:a}=Ye(e);this._png.colourType=t,this._png.channels=i,this._png.bitDepth=a;const n=this._png.width*this._png.height*i;if(this._png.data.length!==n)throw new RangeError(`wrong data size. Found ${this._png.data.length}, expected ${n}`)}writeCrc(e){this.writeUint32(Me(new Uint8Array(this.buffer,this.byteOffset+this.offset-e,e),e))}}for(var Fl=Fl||function(e){return new Buffer(e).toString('base64')},Xl=function(){function e(){}function t(e,t){for(var a=0,n=[],o=16,s,r;0<o&&!e[o-1];)o--;n.push({children:[],index:0});var l=n[0],d;for(s=0;s<o;s++){for(r=0;r<e[s];r++){for(l=n.pop(),l.children[l.index]=t[a];0<l.index;)l=n.pop();for(l.index++,n.push(l);n.length<=s;)n.push(d={children:[],index:0}),l.children[l.index]=d.children,l=d;a++}s+1<o&&(n.push(d={children:[],index:0}),l.children[l.index]=d.children,l=d)}return n[0].children}function a(e,t,a,o,s,l,d,r,g){function m(){if(0<z)return z--,1&A>>z;if(A=e[t++],255==A){var i=e[t++];if(i)throw new Error('unexpected marker: '+(A<<8|i).toString(16))}return z=7,A>>>7}function c(e){for(var t=e,i;null!==(i=m());){if(t=t[i],'number'==typeof t)return t;if('object'!=typeof t)throw new Error('invalid huffman sequence')}return null}function p(e){for(var t=0,i;0<e;){if(i=m(),null===i)return;t=t<<1|i,e--}return t}function u(e){var t=p(e);return t>=1<<e-1?t:t+(-1<<e)+1}function f(e,a){var n=c(e.huffmanTableDC),t=0===n?0:u(n);a[0]=e.pred+=t;for(var o=1;64>o;){var l=c(e.huffmanTableAC),d=15&l,s=l>>4;if(0==d){if(15>s)break;o+=16;continue}o+=s;var r=i[o];a[r]=u(d),o++}}function b(e,i){var a=c(e.huffmanTableDC),t=0===a?0:u(a)<<g;i[0]=e.pred+=t}function _(e,t){if(0<Y)return void Y--;for(var a=l;a<=d;){var n=c(e.huffmanTableAC),o=15&n,s=n>>4;if(0==o){if(15>s){Y=p(s)+(1<<s)-1;break}a+=16;continue}a+=s;var r=i[a];t[r]=u(o)*(1<<g),a++}}function w(e,t){for(var a=l,n=0;a<=d;){var o=i[a],h=0>t[o]?-1:1;switch(L){case 0:var f=c(e.huffmanTableAC),b=15&f,n=f>>4;if(0==b)15>n?(Y=p(n)+(1<<n),L=4):(n=16,L=1);else{if(1!=b)throw new Error('invalid ACn encoding');T=u(b),L=n?2:3}continue;case 1:case 2:t[o]?t[o]+=(m()<<g)*h:(n--,0==n&&(L=2==L?3:0));break;case 3:t[o]?t[o]+=(m()<<g)*h:(t[o]=T<<g,L=0);break;case 4:t[o]&&(t[o]+=(m()<<g)*h);}a++}4==L&&(Y--,0===Y&&(L=0))}function x(e,t,i,a,n){var o=(0|i/P)*e.v+a,s=i%P*e.h+n;t(e,e.blocks[o][s])}function y(e,t,i){var a=0|i/e.blocksPerLine,n=i%e.blocksPerLine;t(e,e.blocks[a][n])}var D=a.precision,S=a.samplesPerLine,M=a.scanLines,P=a.mcusPerLine,I=a.progressive,B=a.maxH,C=a.maxV,R=t,A=0,z=0,Y=0,L=0,E=o.length,T,F,X,V,U,G,O;O=I?0===l?0===r?b:function(e,t){t[0]|=m()<<g}:0===r?_:w:f;var N=0,H,q;q=1==E?o[0].blocksPerLine*o[0].blocksPerColumn:P*a.mcusPerColumn,s||(s=q);for(var W,Z;N<q;){for(X=0;X<E;X++)o[X].pred=0;if(Y=0,1==E)for(F=o[0],G=0;G<s;G++)y(F,O,N),N++;else for(G=0;G<s;G++){for(X=0;X<E;X++)for(F=o[X],W=F.h,Z=F.v,V=0;V<Z;V++)for(U=0;U<W;U++)x(F,O,N,V,U);if(N++,N===q)break}if(z=0,H=e[t]<<8|e[t+1],65280>H)throw new Error('marker was not found');if(65488<=H&&65495>=H)t+=2;else break}return t-R}function n(e,a){function t(e,n,o){var s=a.quantizationTable,r=o,l,d,h,g,m,c,p,u,f,b;for(b=0;64>b;b++)r[b]=e[b]*s[b];for(b=0;8>b;++b){var _=8*b;if(0==r[1+_]&&0==r[2+_]&&0==r[3+_]&&0==r[4+_]&&0==r[5+_]&&0==r[6+_]&&0==r[7+_]){f=5793*r[0+_]+512>>10,r[0+_]=f,r[1+_]=f,r[2+_]=f,r[3+_]=f,r[4+_]=f,r[5+_]=f,r[6+_]=f,r[7+_]=f;continue}l=5793*r[0+_]+128>>8,d=5793*r[4+_]+128>>8,h=r[2+_],g=r[6+_],m=2896*(r[1+_]-r[7+_])+128>>8,u=2896*(r[1+_]+r[7+_])+128>>8,c=r[3+_]<<4,p=r[5+_]<<4,f=l-d+1>>1,l=l+d+1>>1,d=f,f=3784*h+1567*g+128>>8,h=1567*h-3784*g+128>>8,g=f,f=m-p+1>>1,m=m+p+1>>1,p=f,f=u+c+1>>1,c=u-c+1>>1,u=f,f=l-g+1>>1,l=l+g+1>>1,g=f,f=d-h+1>>1,d=d+h+1>>1,h=f,f=2276*m+3406*u+2048>>12,m=3406*m-2276*u+2048>>12,u=f,f=799*c+4017*p+2048>>12,c=4017*c-799*p+2048>>12,p=f,r[0+_]=l+u,r[7+_]=l-u,r[1+_]=d+p,r[6+_]=d-p,r[2+_]=h+c,r[5+_]=h-c,r[3+_]=g+m,r[4+_]=g-m}for(b=0;8>b;++b){var w=b;if(0==r[8+w]&&0==r[16+w]&&0==r[24+w]&&0==r[32+w]&&0==r[40+w]&&0==r[48+w]&&0==r[56+w]){f=5793*o[b+0]+8192>>14,r[0+w]=f,r[8+w]=f,r[16+w]=f,r[24+w]=f,r[32+w]=f,r[40+w]=f,r[48+w]=f,r[56+w]=f;continue}l=5793*r[0+w]+2048>>12,d=5793*r[32+w]+2048>>12,h=r[16+w],g=r[48+w],m=2896*(r[8+w]-r[56+w])+2048>>12,u=2896*(r[8+w]+r[56+w])+2048>>12,c=r[24+w],p=r[40+w],f=l-d+1>>1,l=l+d+1>>1,d=f,f=3784*h+1567*g+2048>>12,h=1567*h-3784*g+2048>>12,g=f,f=m-p+1>>1,m=m+p+1>>1,p=f,f=u+c+1>>1,c=u-c+1>>1,u=f,f=l-g+1>>1,l=l+g+1>>1,g=f,f=d-h+1>>1,d=d+h+1>>1,h=f,f=2276*m+3406*u+2048>>12,m=3406*m-2276*u+2048>>12,u=f,f=799*c+4017*p+2048>>12,c=4017*c-799*p+2048>>12,p=f,r[0+w]=l+u,r[56+w]=l-u,r[8+w]=d+p,r[48+w]=d-p,r[16+w]=h+c,r[40+w]=h-c,r[24+w]=g+m,r[32+w]=g-m}for(b=0;64>b;++b){var x=128+(r[b]+8>>4);n[b]=0>x?0:255<x?255:x}}for(var n=[],o=a.blocksPerLine,s=a.blocksPerColumn,l=new Int32Array(64),d=new Uint8Array(64),r=0,h,g,m;r<s;r++){for(m=r<<3,h=0;8>h;h++)n.push(new Uint8Array(o<<3));for(var c=0;c<o;c++){t(a.blocks[r][c],d,l);var p=0,u=c<<3;for(g=0;8>g;g++){var f=n[m+g];for(h=0;8>h;h++)f[u+h]=d[p++]}}}return n}function o(e){return 0>e?0:255<e?255:e}var i=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]);return e.prototype={load:function(e){var t=new XMLHttpRequest;t.open('GET',e,!0),t.responseType='arraybuffer',t.onload=function(){var e=new Uint8Array(t.response||t.mozResponseArrayBuffer);this.parse(e),this.onload&&this.onload()}.bind(this),t.send(null)},parse:function(e){function o(){var t=e[l]<<8|e[l+1];return l+=2,t}function s(){var t=o(),i=e.subarray(l,l+t-2);return l+=i.length,i}function r(e){var t=0,a=0,n,o;for(o in e.components)e.components.hasOwnProperty(o)&&(n=e.components[o],t<n.h&&(t=n.h),a<n.v&&(a=n.v));var s=pr(e.samplesPerLine/8/t),r=pr(e.scanLines/8/a);for(o in e.components)if(e.components.hasOwnProperty(o)){n=e.components[o];for(var l=pr(pr(e.samplesPerLine/8)*n.h/t),d=pr(pr(e.scanLines/8)*n.v/a),h=s*n.h,g=r*n.v,m=[],c=0,p;c<g;c++){p=[];for(var u=0;u<h;u++)p.push(new Int32Array(64));m.push(p)}n.blocksPerLine=l,n.blocksPerColumn=d,n.blocks=m}e.maxH=t,e.maxV=a,e.mcusPerLine=s,e.mcusPerColumn=r}var l=0,d=e.length,g=null,m=null,c=[],p=[],u=[],f=[],b=o(),_,w;if(65496!=b)throw new Error('SOI not found');for(b=o();65497!=b;){var x,k;switch(b){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 y=s();65504===b&&74===y[0]&&70===y[1]&&73===y[2]&&70===y[3]&&0===y[4]&&(g={version:{major:y[5],minor:y[6]},densityUnits:y[7],xDensity:y[8]<<8|y[9],yDensity:y[10]<<8|y[11],thumbWidth:y[12],thumbHeight:y[13],thumbData:y.subarray(14,14+3*y[12]*y[13])}),65518===b&&65===y[0]&&100===y[1]&&111===y[2]&&98===y[3]&&101===y[4]&&0===y[5]&&(m={version:y[6],flags0:y[7]<<8|y[8],flags1:y[9]<<8|y[10],transformCode:y[11]});break;case 65499:for(var D=o(),S=D+l-2;l<S;){var M=e[l++],P=new Int32Array(64);if(0==M>>4)for(k=0;64>k;k++){var I=i[k];P[I]=e[l++]}else if(1==M>>4)for(k=0;64>k;k++){var I=i[k];P[I]=o()}else throw new Error('DQT: invalid table spec');c[15&M]=P}break;case 65472:case 65473:case 65474:o(),_={},_.extended=65473===b,_.progressive=65474===b,_.precision=e[l++],_.scanLines=o(),_.samplesPerLine=o(),_.components={},_.componentsOrder=[];var B=e[l++],C;for(x=0;x<B;x++){C=e[l];var R=e[l+1]>>4,h=15&e[l+1],v=e[l+2];_.componentsOrder.push(C),_.components[C]={h:R,v:h,quantizationIdx:v},l+=3}r(_),p.push(_);break;case 65476:var A=o();for(x=2;x<A;){var Y=e[l++],L=new Uint8Array(16),E=0;for(k=0;16>k;k++,l++)E+=L[k]=e[l];var T=new Uint8Array(E);for(k=0;k<E;k++,l++)T[k]=e[l];x+=17+E,(0==Y>>4?f:u)[15&Y]=t(L,T)}break;case 65501:o(),w=o();break;case 65498:var F=o(),X=e[l++],V=[],U;for(x=0;x<X;x++){U=_.components[e[l++]];var G=e[l++];U.huffmanTableDC=f[G>>4],U.huffmanTableAC=u[15&G],V.push(U)}var O=e[l++],N=e[l++],H=e[l++],q=a(e,l,_,V,w,O,N,H>>4,15&H);l+=q;break;case 65535:255!==e[l]&&l--;break;default:if(255==e[l-3]&&192<=e[l-2]&&254>=e[l-2]){l-=3;break}throw new Error('unknown JPEG marker '+b.toString(16));}b=o()}if(1!=p.length)throw new Error('only single frame JPEGs supported');for(var x=0,W;x<p.length;x++)for(var k in W=p[x].components,W)W[k].quantizationTable=c[W[k].quantizationIdx],delete W[k].quantizationIdx;this.width=_.samplesPerLine,this.height=_.scanLines,this.jfif=g,this.adobe=m,this.components=[];for(var x=0,U;x<_.componentsOrder.length;x++)U=_.components[_.componentsOrder[x]],this.components.push({lines:n(_,U),scaleX:U.h/_.maxH,scaleY:U.v/_.maxV})},getData:function(e,t){var i=this.width/e,a=this.height/t,n=0,s=e*t*this.components.length,r=new Uint8Array(s),l,d,h,g,m,c,p,u,f,b,_,w,k,v,D,S,j,P,I,A,z;switch(this.components.length){case 1:for(l=this.components[0],b=0;b<t;b++)for(m=l.lines[0|b*l.scaleY*a],f=0;f<e;f++)_=m[0|f*l.scaleX*i],r[n++]=_;break;case 2:for(l=this.components[0],d=this.components[1],b=0;b<t;b++)for(m=l.lines[0|b*l.scaleY*a],c=d.lines[0|b*d.scaleY*a],f=0;f<e;f++)_=m[0|f*l.scaleX*i],r[n++]=_,_=c[0|f*d.scaleX*i],r[n++]=_;break;case 3:for(z=!0,this.adobe&&this.adobe.transformCode?z=!0:'undefined'!=typeof this.colorTransform&&(z=!!this.colorTransform),l=this.components[0],d=this.components[1],h=this.components[2],b=0;b<t;b++)for(m=l.lines[0|b*l.scaleY*a],c=d.lines[0|b*d.scaleY*a],p=h.lines[0|b*h.scaleY*a],f=0;f<e;f++)z?(_=m[0|f*l.scaleX*i],w=c[0|f*d.scaleX*i],k=p[0|f*h.scaleX*i],P=o(_+1.402*(k-128)),I=o(_-.3441363*(w-128)-.71413636*(k-128)),A=o(_+1.772*(w-128))):(P=m[0|f*l.scaleX*i],I=c[0|f*d.scaleX*i],A=p[0|f*h.scaleX*i]),r[n++]=P,r[n++]=I,r[n++]=A;break;case 4:if(!this.adobe)throw'Unsupported color mode (4 components)';for(z=!1,this.adobe&&this.adobe.transformCode?z=!0:'undefined'!=typeof this.colorTransform&&(z=!!this.colorTransform),l=this.components[0],d=this.components[1],h=this.components[2],g=this.components[3],b=0;b<t;b++)for(m=l.lines[0|b*l.scaleY*a],c=d.lines[0|b*d.scaleY*a],p=h.lines[0|b*h.scaleY*a],u=g.lines[0|b*g.scaleY*a],f=0;f<e;f++)z?(_=m[0|f*l.scaleX*i],w=c[0|f*d.scaleX*i],k=p[0|f*h.scaleX*i],v=u[0|f*g.scaleX*i],D=255-o(_+1.402*(k-128)),S=255-o(_-.3441363*(w-128)-.71413636*(k-128)),j=255-o(_+1.772*(w-128))):(D=m[0|f*l.scaleX*i],S=c[0|f*d.scaleX*i],j=p[0|f*h.scaleX*i],v=u[0|f*g.scaleX*i]),r[n++]=255-D,r[n++]=255-S,r[n++]=255-j,r[n++]=255-v;break;default:throw'Unsupported color mode';}return r},copyToImageData:function(e){var t=e.width,a=e.height,n=e.data,s=this.getData(t,a),r=0,l=0,d,h,g,m,c,p,u,f,b;switch(this.components.length){case 1:for(h=0;h<a;h++)for(d=0;d<t;d++)g=s[r++],n[l++]=g,n[l++]=g,n[l++]=g,n[l++]=255;break;case 3:for(h=0;h<a;h++)for(d=0;d<t;d++)u=s[r++],f=s[r++],b=s[r++],n[l++]=u,n[l++]=f,n[l++]=b,n[l++]=255;break;case 4:for(h=0;h<a;h++)for(d=0;d<t;d++)c=s[r++],p=s[r++],g=s[r++],m=s[r++],u=255-o(c*(1-m/255)+m),f=255-o(p*(1-m/255)+m),b=255-o(g*(1-m/255)+m),n[l++]=u,n[l++]=f,n[l++]=b,n[l++]=255;break;default:throw'Unsupported color mode';}}},e}(),Vl={encode:Ve,decode:Ue},Ul=Vl.encode,Gl=Vl.decode,Ol=new Uint8Array(256),Nl=0;Nl<'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.length;Nl++)Ol['ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charCodeAt(Nl)]=Nl;var Hl=self.ImageData,ql=self.Image,Wl={save(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},i=t.useCanvas,a=i!==void 0&&i,n=t.encoder,o=n===void 0?void 0:n,s=t.format;if(!s){var r=/\.([a-zA-Z]+)$/.exec(e);r&&(s=r[1].toLowerCase())}if(!s)throw new Error('file format not provided');return new Promise((t,i)=>{var n,r;switch(s.toLowerCase()){case'png':{a?n=this.getCanvas().pngStream():r=Qe(this,o);break}case'jpg':case'jpeg':a?n=this.getCanvas().jpegStream():r=Je(this,o);break;case'bmp':r=Sr(this,o);break;default:throw new RangeError(`invalid output format: ${s}`);}if(n){var l=We(e);l.on('finish',t),l.on('error',i),n.pipe(l)}else r&&Ze(e,r,e=>e?void i(e):void t())})},toDataURL(){function e(e,i){var a=e(i,r);return Ne(a,t)}var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:'image/png',i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};'object'==typeof t&&(i=t,t='image/png');var a=i,n=a.useCanvas,o=void 0!==n&&n,s=a.encoder,r=void 0===s?void 0:s;return t=Ke(t),'image/bmp'===t?e(Sr,this):'image/png'!==t||o?'image/jpeg'!==t||o?this.getCanvas().toDataURL(t):e(Je,this):e(Qe,this)},toBuffer(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.format,i=t===void 0?'png':t,a=e.encoder,n=a===void 0?void 0:a;switch(i.toLowerCase()){case'png':return Qe(this,n);case'jpeg':case'jpg':return Je(this,n);case'bmp':return Sr(this,n);default:throw new RangeError(`invalid output format: ${i}`);}},toBase64(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:'image/png',t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};if(t.async)return this.toDataURL(e,t).then(function(e){return e.substring(e.indexOf(',')+1)});var i=this.toDataURL(e,t);return i.substring(i.indexOf(',')+1)},toBlob(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:'image/png',t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:.8;return r(this.getCanvas(),e,t)},getCanvas(){var e=new Hl(this.getRGBAData({clamped:!0}),this.width,this.height),t=He(this.width,this.height),i=t.getContext('2d');return i.putImageData(e,0,0),t}},Zl={},Kl={type:'version',registry:!0,raw:'has-own@1.0.0',name:'has-own',escapedName:'has-own',rawSpec:'1.0.0',saveSpec:null,fetchSpec:'1.0.0'},Jl=['#USER','/'],Ql={name:'Aaron Heckmann',email:'aaron.heckmann+github@gmail.com'},$l={url:'https://github.com/pebble/has-own/issues'},ed={mocha:'^1.21.0'},td={type:'git',url:'git://github.com/pebble/has-own.git'},id={test:'make test'},ad={_from:'has-own@1.0.0',_id:'has-own@1.0.0',_inBundle:!1,_integrity:'sha1-MGIkbjHP2Iepph7m04ylcok3jNE=',_location:'/has-own',_phantomChildren:Zl,_requested:Kl,_requiredBy:Jl,_resolved:'https://registry.npmjs.org/has-own/-/has-own-1.0.0.tgz',_shasum:'3062246e31cfd887a9a61ee6d38ca57289378cd1',_spec:'has-own@1.0.0',_where:'/Users/macbook/srv/vzor-image-js',author:Ql,bugs:$l,bundleDependencies:!1,deprecated:!1,description:'A safer .hasOwnProperty() - hasOwn(name, obj)',devDependencies:ed,homepage:'https://github.com/pebble/has-own/',license:'MIT',main:'index.js',name:'has-own',repository:td,scripts:id,version:'1.0.0'},nd=Object.freeze({_from:'has-own@1.0.0',_id:'has-own@1.0.0',_inBundle:!1,_integrity:'sha1-MGIkbjHP2Iepph7m04ylcok3jNE=',_location:'/has-own',_phantomChildren:Zl,_requested:Kl,_requiredBy:Jl,_resolved:'https://registry.npmjs.org/has-own/-/has-own-1.0.0.tgz',_shasum:'3062246e31cfd887a9a61ee6d38ca57289378cd1',_spec:'has-own@1.0.0',_where:'/Users/macbook/srv/vzor-image-js',author:Ql,bugs:$l,bundleDependencies:!1,deprecated:!1,description:'A safer .hasOwnProperty() - hasOwn(name, obj)',devDependencies:ed,homepage:'https://github.com/pebble/has-own/',license:'MIT',main:'index.js',name:'has-own',repository:td,scripts:id,version:'1.0.0',default:ad}),od=h(function(e,t){var i=Object.prototype.hasOwnProperty;e.exports=t=function(e,t){return i.call(t,e)},t.version=(nd&&ad||nd).version}),sd=od.version,rd={configurable:!0,enumerable:!1,get:void 0},ld=Object.freeze({GREY:'GREY',RGB:'RGB',HSL:'HSL',HSV:'HSV',CMYK:'CMYK'}),dd={};dd.BINARY={components:1,alpha:0,bitDepth:1,colorModel:'GREY'},dd.GREYA={components:1,alpha:1,bitDepth:8,colorModel:'GREY'},dd.GREY={components:1,alpha:0,bitDepth:8,colorModel:'GREY'},dd.RGBA={components:3,alpha:1,bitDepth:8,colorModel:'RGB'},dd.RGB={components:3,alpha:0,bitDepth:8,colorModel:'RGB'},dd.CMYK={components:4,alpha:0,bitDepth:8,colorModel:'CMYK'},dd.CMYKA={components:4,alpha:1,bitDepth:8,colorModel:'CMYK'};var hd=[1,8,16,32];const gd=8192,md=[];var cd=class{constructor(e,t){t=t||{},e===void 0&&(e=gd),'number'==typeof e&&(e=new ArrayBuffer(e));let i=e.byteLength;const a=t.offset?t.offset>>>0:0;e.buffer&&(i=e.byteLength-a,e=e.byteLength===e.buffer.byteLength?a?e.buffer.slice(a):e.buffer:e.buffer.slice(e.byteOffset+a,e.byteOffset+e.byteLength)),this.buffer=e,this.length=i,this.byteLength=i,this.byteOffset=0,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer),this._increment=i||gd,this._mark=0}available(e){return void 0===e&&(e=1),this.offset+e<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){this.littleEndian=!0}isBigEndian(){return!this.littleEndian}setBigEndian(){this.littleEndian=!1}skip(e){e===void 0&&(e=1),this.offset+=e}seek(e){this.offset=e}mark(){this._mark=this.offset}reset(){this.offset=this._mark}rewind(){this.offset=0}ensureAvailable(e){if(void 0===e&&(e=1),!this.available(e)){const e=this._increment+this._increment;this._increment=e;const t=this.length+e,i=new Uint8Array(t);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=t,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(e){e===void 0&&(e=1);for(var t=new Uint8Array(e),a=0;a<e;a++)t[a]=this.readByte();return t}readInt16(){var e=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}readUint16(){var e=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}readInt32(){var e=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}readUint32(){var e=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat32(){var e=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat64(){var e=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}readChar(){return fr(this.readInt8())}readChars(e){e===void 0&&(e=1),md.length=e;for(var t=0;t<e;t++)md[t]=this.readChar();return md.join('')}writeBoolean(e){this.writeUint8(e?255:0)}writeInt8(e){this.ensureAvailable(1),this._data.setInt8(this.offset++,e)}writeUint8(e){this.ensureAvailable(1),this._data.setUint8(this.offset++,e)}writeByte(e){this.writeUint8(e)}writeBytes(e){this.ensureAvailable(e.length);for(var t=0;t<e.length;t++)this._data.setUint8(this.offset++,e[t])}writeInt16(e){this.ensureAvailable(2),this._data.setInt16(this.offset,e,this.littleEndian),this.offset+=2}writeUint16(e){this.ensureAvailable(2),this._data.setUint16(this.offset,e,this.littleEndian),this.offset+=2}writeInt32(e){this.ensureAvailable(4),this._data.setInt32(this.offset,e,this.littleEndian),this.offset+=4}writeUint32(e){this.ensureAvailable(4),this._data.setUint32(this.offset,e,this.littleEndian),this.offset+=4}writeFloat32(e){this.ensureAvailable(4),this._data.setFloat32(this.offset,e,this.littleEndian),this.offset+=4}writeFloat64(e){this.ensureAvailable(8),this._data.setFloat64(this.offset,e,this.littleEndian),this.offset+=8}writeChar(e){this.writeUint8(e.charCodeAt(0))}writeChars(e){for(var t=0;t<e.length;t++)this.writeUint8(e.charCodeAt(t))}toArray(){return new Uint8Array(this.buffer,0,this.offset)}};const pd={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'},ud={};for(var fd in pd)ud[pd[fd]]=fd;const bd={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'},_d={};for(var wd in bd)_d[bd[wd]]=wd;const xd={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'},kd={};for(var yd in xd)kd[xd[yd]]=yd;const vd={standard:{tagsById:pd,tagsByName:ud},exif:{tagsById:bd,tagsByName:_d},gps:{tagsById:xd,tagsByName:kd}};class Dd{constructor(e){if(!e)throw new Error('missing kind');this.data=null,this.fields=new Map,this.kind=e,this._map=null}get(e){if('number'==typeof e)return this.fields.get(e);if('string'==typeof e)return this.fields.get(vd[this.kind].tagsByName[e]);throw new Error('expected a number or string')}get map(){if(!this._map){this._map={};const t=vd[this.kind].tagsById;for(var e of this.fields.keys())t[e]&&(this._map[t[e]]=this.fields.get(e))}return this._map}}var Sd=Dd;const Md=/^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;class jd extends Sd{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 e=new Date,t=Md.exec(this.dateTime);return e.setFullYear(t[1],t[2]-1,t[3]),e.setHours(t[4],t[5],t[6]),e}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 gt(this.get(273))}get orientation(){return this.get(274)}get samplesPerPixel(){return this.get(277)}get rowsPerStrip(){return this.get(278)}get stripByteCounts(){return gt(this.get(279))}get minSampleValue(){return this.get(280)||0}get maxSampleValue(){return this.get(281)||cr(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}}var Pd=new Map([[1,[1,mt]],[2,[1,ct]],[3,[2,pt]],[4,[4,ut]],[5,[8,ft]],[6,[1,bt]],[7,[1,mt]],[8,[2,_t]],[9,[4,wt]],[10,[8,xt]],[11,[4,kt]],[12,[8,yt]]]),Id={getByteLength:function(e,t){return Pd.get(e)[0]*t},readData:function(e,t,i){return Pd.get(t)[1](e,i)}};const Bd={ignoreImageData:!1,onlyFirst:!1};var Cd=class extends cd{constructor(e,t){super(e,t),this._nextIFD=0}decode(e){e=Object.assign({},Bd,e);const t=[];for(this.decodeHeader();this._nextIFD;)if(t.push(this.decodeIFD(e)),e.onlyFirst)return t[0];return t}decodeHeader(){let e=this.readUint16();if(18761===e)this.setLittleEndian();else if(19789===e)this.setBigEndian();else throw new Error('invalid byte order: 0x'+e.toString(16));if(e=this.readUint16(),42!==e)throw new Error('not a TIFF file');this._nextIFD=this.readUint32()}decodeIFD(e){this.seek(this._nextIFD);var t=e.kind?new Sd(e.kind):new jd;const a=this.readUint16();for(var n=0;n<a;n++)this.decodeIFDEntry(t);return e.ignoreImageData||this.decodeImageData(t),this._nextIFD=this.readUint32(),t}decodeIFDEntry(e){const t=this.offset,i=this.readUint16(),a=this.readUint16(),n=this.readUint32();if(1>a||12<a)return void this.skip(4);const o=Id.getByteLength(a,n);4<o&&this.seek(this.readUint32());const s=Id.readData(this,a,n);if(e.fields.set(i,s),34665===i||34853===i){let t=this.offset,a;34665===i?a='exif':34853===i&&(a='gps'),this._nextIFD=s,e[a]=this.decodeIFD({kind:a,ignoreImageData:!0}),this.offset=t}this.seek(t),this.skip(12)}decodeImageData(e){const t=e.orientation;switch(t&&1!==t&&jt('orientation',t),e.type){case 1:case 2:this.readStripData(e);break;default:jt('image type',e.type);}}readStripData(e){const t=e.width,a=e.height,n=Pt(e.bitsPerSample),o=e.sampleFormat;let s=t*a;const r=vt(s,1,n,o),l=e.compression,d=e.rowsPerStrip,h=d*t,g=e.stripOffsets,m=e.stripByteCounts;for(var c=0,p=0;p<g.length;p++){var u=this.getStripData(l,g[p],m[p]),f=s>h?h:s;s-=f,8===n?c=Dt(r,u,c,f):16===n?c=St(r,u,c,f,this.isLittleEndian()):32===n&&3===o?c=Mt(r,u,c,f,this.isLittleEndian()):jt('bitDepth',n)}e.data=r}getStripData(e,t,i){switch(e){case 1:return new DataView(this.buffer,t,i);case 2:case 32773:return jt('Compression',e);default:throw new Error('invalid compression: '+e);}}},Rd={decode:function(e,t){const i=new Cd(e,t);return i.decode(t)}},Ad=function(e){const t=new cd(e),i={};t.setBigEndian();const a=t.readUint16();if(65496!==a)throw new Error('SOI marker not found. Not a valid JPEG file');const n=t.readUint16();if(65505===n){const e=t.readUint16(),a=t.readBytes(6);if(69===a[0]&&120===a[1]&&105===a[2]&&102===a[3]&&0===a[4]&&0===a[5]){const e=Rd.decode(t,{onlyFirst:!0,ignoreImageData:!0,offset:t.offset});i.exif=e}}return i};const zd={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'},Yd={};for(var Ld in zd)Yd[zd[Ld]]=Ld;var Ed=Object.freeze({tagsById:zd,tagsByName:Yd});const Td={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'},Fd={};for(var Xd in Td)Fd[Td[Xd]]=Xd;var Vd=Object.freeze({tagsById:Td,tagsByName:Fd});const Ud={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'},Gd={};for(var Od in Ud)Gd[Ud[Od]]=Od;var Nd=Object.freeze({tagsById:Ud,tagsByName:Gd});const Hd={standard:Ed,exif:Vd,gps:Nd};class qd{constructor(e){if(!e)throw new Error('missing kind');this.data=null,this.fields=new Map,this.kind=e,this._map=null}get(e){if('number'==typeof e)return this.fields.get(e);if('string'==typeof e)return this.fields.get(Hd[this.kind].tagsByName[e]);throw new Error('expected a number or string')}get map(){if(!this._map){this._map={};const t=Hd[this.kind].tagsById;for(var e of this.fields.keys())t[e]&&(this._map[t[e]]=this.fields.get(e))}return this._map}}const Wd=/^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;class Zd extends qd{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 e=new Date,t=Wd.exec(this.dateTime);return e.setFullYear(t[1],t[2]-1,t[3]),e.setHours(t[4],t[5],t[6]),e}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 It(this.get(273))}get orientation(){return this.get(274)}get samplesPerPixel(){return this.get(277)}get rowsPerStrip(){return this.get(278)}get stripByteCounts(){return It(this.get(279))}get minSampleValue(){return this.get(280)||0}get maxSampleValue(){return this.get(281)||cr(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}}var Kd=new Map([[1,[1,Rt]],[2,[1,At]],[3,[2,zt]],[4,[4,Yt]],[5,[8,Lt]],[6,[1,Et]],[7,[1,Rt]],[8,[2,Tt]],[9,[4,Ft]],[10,[8,Xt]],[11,[4,Vt]],[12,[8,Ut]]]);const Jd={ignoreImageData:!1,onlyFirst:!1};class Qd extends kr{constructor(e,t){super(e,t),this._nextIFD=0}get isMultiPage(){let e=0;for(this.decodeHeader();this._nextIFD;)if(e++,this.decodeIFD({ignoreImageData:!0}),2==e)return!0;if(1==e)return!1;throw qt('ifdCount',e)}get pageCount(){let e=0;for(this.decodeHeader();this._nextIFD;)e++,this.decodeIFD({ignoreImageData:!0});if(0<e)return e;throw qt('ifdCount',e)}decode(e){e=Object.assign({},Jd,e);const t=[];for(this.decodeHeader();this._nextIFD;)if(t.push(this.decodeIFD(e)),e.onlyFirst)return t[0];return t}decodeHeader(){const e=this.readUint16();if(18761===e)this.setLittleEndian();else if(19789===e)this.setBigEndian();else throw new Error('invalid byte order: 0x'+e.toString(16));if(42!==this.readUint16())throw new Error('not a TIFF file');this._nextIFD=this.readUint32()}decodeIFD(e){this.seek(this._nextIFD);var t=e.kind?new qd(e.kind):new Zd;const a=this.readUint16();for(var n=0;n<a;n++)this.decodeIFDEntry(t);return e.ignoreImageData||this.decodeImageData(t),this._nextIFD=this.readUint32(),t}decodeIFDEntry(e){const t=this.offset,i=this.readUint16(),a=this.readUint16(),n=this.readUint32();if(1>a||12<a)return void this.skip(4);const o=Bt(a,n);4<o&&this.seek(this.readUint32());const s=Ct(this,a,n);if(e.fields.set(i,s),34665===i||34853===i){let t=this.offset,a;34665===i?a='exif':34853===i&&(a='gps'),this._nextIFD=s,e[a]=this.decodeIFD({kind:a,ignoreImageData:!0}),this.offset=t}this.seek(t),this.skip(12)}decodeImageData(e){const t=e.orientation;if(t&&1!==t)throw qt('orientation',t);switch(e.type){case 1:case 2:this.readStripData(e);break;default:throw qt('image type',e.type);}}readStripData(e){const t=e.width,a=e.height,n=Wt(e.bitsPerSample),o=e.sampleFormat,s=t*a,r=Gt(s,1,n,o),l=e.compression,d=e.rowsPerStrip,h=d*t,g=e.stripOffsets,m=e.stripByteCounts;for(var c=s,p=0,u=0;u<g.length;u++){var f=new DataView(this.buffer,g[u],m[u]),b=c>h?h:c;switch(c-=b,l){case 1:p=this.fillUncompressed(n,o,r,f,p,b);break;case 5:throw qt('lzw');case 2:case 32773:throw qt('Compression',l);default:throw new Error('invalid compression: '+l);}}e.data=r}fillUncompressed(e,t,i,a,n,o){if(8===e)return Ot(i,a,n,o);if(16===e)return Nt(i,a,n,o,this.isLittleEndian());if(32===e&&3===t)return Ht(i,a,n,o,this.isLittleEndian());throw qt('bitDepth',e)}}var $d=e=>{const t=new Uint8Array(e);if(!(t&&1<t.length))return null;const i=(e,a)=>{a=Object.assign({offset:0},a);for(let n=0;n<e.length;n++)if(e[n]!==t[n+a.offset])return!1;return!0};if(i([255,216,255]))return{ext:'jpg',mime:'image/jpeg'};if(i([137,80,78,71,13,10,26,10]))return{ext:'png',mime:'image/png'};if(i([71,73,70]))return{ext:'gif',mime:'image/gif'};if(i([87,69,66,80],{offset:8}))return{ext:'webp',mime:'image/webp'};if(i([70,76,73,70]))return{ext:'flif',mime:'image/flif'};if((i([73,73,42,0])||i([77,77,0,42]))&&i([67,82],{offset:8}))return{ext:'cr2',mime:'image/x-canon-cr2'};if(i([73,73,42,0])||i([77,77,0,42]))return{ext:'tif',mime:'image/tiff'};if(i([66,77]))return{ext:'bmp',mime:'image/bmp'};if(i([73,73,188]))return{ext:'jxr',mime:'image/vnd.ms-photo'};if(i([56,66,80,83]))return{ext:'psd',mime:'image/vnd.adobe.photoshop'};if(i([80,75,3,4])&&i([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(i([80,75,3,4])&&i([77,69,84,65,45,73,78,70,47,109,111,122,105,108,108,97,46,114,115,97],{offset:30}))return{ext:'xpi',mime:'application/x-xpinstall'};if(i([80,75])&&(3===t[2]||5===t[2]||7===t[2])&&(4===t[3]||6===t[3]||8===t[3]))return{ext:'zip',mime:'application/zip'};if(i([117,115,116,97,114],{offset:257}))return{ext:'tar',mime:'application/x-tar'};if(i([82,97,114,33,26,7])&&(0===t[6]||1===t[6]))return{ext:'rar',mime:'application/x-rar-compressed'};if(i([31,139,8]))return{ext:'gz',mime:'application/gzip'};if(i([66,90,104]))return{ext:'bz2',mime:'application/x-bzip2'};if(i([55,122,188,175,39,28]))return{ext:'7z',mime:'application/x-7z-compressed'};if(i([120,1]))return{ext:'dmg',mime:'application/x-apple-diskimage'};if(i([0,0,0])&&(24===t[3]||32===t[3])&&i([102,116,121,112],{offset:4})||i([51,103,112,53])||i([0,0,0,28,102,116,121,112,109,112,52,50])&&i([109,112,52,49,109,112,52,50,105,115,111,109],{offset:16})||i([0,0,0,28,102,116,121,112,105,115,111,109])||i([0,0,0,28,102,116,121,112,109,112,52,50,0,0,0,0]))return{ext:'mp4',mime:'video/mp4'};if(i([0,0,0,28,102,116,121,112,77,52,86]))return{ext:'m4v',mime:'video/x-m4v'};if(i([77,84,104,100]))return{ext:'mid',mime:'audio/midi'};if(i([26,69,223,163])){const e=t.subarray(4,4100),a=e.findIndex((e,t,i)=>66===i[t]&&130===i[t+1]);if(0<=a){const t=t=>Array.from(t).every((t,n)=>e[a+3+n]===t.charCodeAt(0));if(t('matroska'))return{ext:'mkv',mime:'video/x-matroska'};if(t('webm'))return{ext:'webm',mime:'video/webm'}}}return i([0,0,0,20,102,116,121,112,113,116,32,32])||i([102,114,101,101],{offset:4})||i([102,116,121,112,113,116,32,32],{offset:4})||i([109,100,97,116],{offset:4})||i([119,105,100,101],{offset:4})?{ext:'mov',mime:'video/quicktime'}:i([82,73,70,70])&&i([65,86,73],{offset:8})?{ext:'avi',mime:'video/x-msvideo'}:i([48,38,178,117,142,102,207,17,166,217])?{ext:'wmv',mime:'video/x-ms-wmv'}:i([0,0,1,186])?{ext:'mpg',mime:'video/mpeg'}:i([73,68,51])||i([255,251])?{ext:'mp3',mime:'audio/mpeg'}:i([102,116,121,112,77,52,65],{offset:4})||i([77,52,65,32])?{ext:'m4a',mime:'audio/m4a'}:i([79,112,117,115,72,101,97,100],{offset:28})?{ext:'opus',mime:'audio/opus'}:i([79,103,103,83])?{ext:'ogg',mime:'audio/ogg'}:i([102,76,97,67])?{ext:'flac',mime:'audio/x-flac'}:i([82,73,70,70])&&i([87,65,86,69],{offset:8})?{ext:'wav',mime:'audio/x-wav'}:i([35,33,65,77,82,10])?{ext:'amr',mime:'audio/amr'}:i([37,80,68,70])?{ext:'pdf',mime:'application/pdf'}:i([77,90])?{ext:'exe',mime:'application/x-msdownload'}:(67===t[0]||70===t[0])&&i([87,83],{offset:1})?{ext:'swf',mime:'application/x-shockwave-flash'}:i([123,92,114,116,102])?{ext:'rtf',mime:'application/rtf'}:i([0,97,115,109])?{ext:'wasm',mime:'application/wasm'}:i([119,79,70,70])&&(i([0,1,0,0],{offset:4})||i([79,84,84,79],{offset:4}))?{ext:'woff',mime:'application/font-woff'}:i([119,79,70,50])&&(i([0,1,0,0],{offset:4})||i([79,84,84,79],{offset:4}))?{ext:'woff2',mime:'application/font-woff'}:i([76,80],{offset:34})&&(i([0,0,1],{offset:8})||i([1,0,2],{offset:8})||i([2,0,2],{offset:8}))?{ext:'eot',mime:'application/octet-stream'}:i([0,1,0,0,0])?{ext:'ttf',mime:'application/font-sfnt'}:i([79,84,84,79,0])?{ext:'otf',mime:'application/font-sfnt'}:i([0,0,1,0])?{ext:'ico',mime:'image/x-icon'}:i([70,76,86,1])?{ext:'flv',mime:'video/x-flv'}:i([37,33])?{ext:'ps',mime:'application/postscript'}:i([253,55,122,88,90,0])?{ext:'xz',mime:'application/x-xz'}:i([83,81,76,105])?{ext:'sqlite',mime:'application/x-sqlite3'}:i([78,69,83,26])?{ext:'nes',mime:'application/x-nintendo-nes-rom'}:i([67,114,50,52])?{ext:'crx',mime:'application/x-google-chrome-extension'}:i([77,83,67,70])||i([73,83,99,40])?{ext:'cab',mime:'application/vnd.ms-cab-compressed'}:i([33,60,97,114,99,104,62,10,100,101,98,105,97,110,45,98,105,110,97,114,121])?{ext:'deb',mime:'application/x-deb'}:i([33,60,97,114,99,104,62])?{ext:'ar',mime:'application/x-unix-archive'}:i([237,171,238,219])?{ext:'rpm',mime:'application/x-rpm'}:i([31,160])||i([31,157])?{ext:'Z',mime:'application/x-compress'}:i([76,90,73,80])?{ext:'lz',mime:'application/x-lzip'}:i([208,207,17,224,161,177,26,225])?{ext:'msi',mime:'application/x-msi'}:i([6,14,43,52,2,5,1,1,13,1,2,1,1,2])?{ext:'mxf',mime:'application/mxf'}:i([66,76,69,78,68,69,82])?{ext:'blend',mime:'application/x-blender'}:null};const eh=new Set(['jpg','png','gif','webp','tif','bmp','jxr','psd']);var th=e=>{const t=$d(e);return eh.has(t&&t.ext)?t:null},ih={configurable:!0,enumerable:!1,get:void 0};class ah extends Array{constructor(e){if(Array.isArray(e)){super(e.length);for(var t=0;t<e.length;t++)this[t]=e[t]}else'number'==typeof e?super(e):super();this.computed=null}static load(e){return Promise.all(e.map(tc.load)).then(e=>new ah(e))}static extendMethod(e,t){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},a=i.inPlace,n=i.returnThis,o=i.partialArgs,s=void 0===o?[]:o;return ah.prototype[e]=void 0!==a&&a?function(){this.computed=null;for(var e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];var o=t.apply(this,[...s,...i]);return void 0===n||n?this:o}:function(){for(var e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];return t.apply(this,[...s,...i])},ah}static extendProperty(e,t){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},a=i.partialArgs,n=void 0===a?[]:a;return ih.get=function(){if(null===this.computed)this.computed={};else if(od(e,this.computed))return this.computed[e];var i=t.apply(this,n);return this.computed[e]=i,i},Object.defineProperty(ah.prototype,e,ih),ah}checkProcessable(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};if('string'!=typeof e)throw new TypeError('checkProcessable requires as first parameter the processName (a string)');if(0===this.size)throw new TypeError(`The process: ${e} can not be applied on an empty stack`);this[0].checkProcessable(e,t);for(var a=1;a<this.length;a++){if((t.sameSize===void 0||t.sameSize)&&this[0].width!==this[a].width)throw new TypeError(`The process: ${e} can not be applied if width is not identical in all images`);if((void 0===t.sameSize||t.sameSize)&&this[0].height!==this[a].height)throw new TypeError(`The process: ${e} can not be applied if height is not identical in all images`);if((void 0===t.sameAlpha||t.sameAlpha)&&this[0].alpha!==this[a].alpha)throw new TypeError(`The process: ${e} can not be applied if alpha is not identical in all images`);if((void 0===t.sameBitDepth||t.sameBitDepth)&&this[0].bitDepth!==this[a].bitDepth)throw new TypeError(`The process: ${e} can not be applied if bitDepth is not identical in all images`);if((void 0===t.sameColorModel||t.sameColorModel)&&this[0].colorModel!==this[a].colorModel)throw new TypeError(`The process: ${e} can not be applied if colorModel is not identical in all images`);if((void 0===t.sameNumberChannels||t.sameNumberChannels)&&this[0].channels!==this[a].channels)throw new TypeError(`The process: ${e} can not be applied if channels is not identical in all images`)}}}Array[Symbol.species]||(ah.prototype.map=function(e,t){if('function'!=typeof e)throw new TypeError(`${e} is not a function`);for(var a=new ah(this.length),n=0;n<this.length;n++)a[n]=e.call(t,this[n],n,this);return a}),function(e){e.extendMethod('matchAndCrop',Kt),e.extendMethod('getMin',Jt),e.extendMethod('getMax',Qt),e.extendMethod('getMedian',ti),e.extendMethod('getHistogram',ii),e.extendMethod('getHistograms',ai),e.extendMethod('getAverage',ni)}(ah);var nh=/^data:[a-z]+\/([a-z]+);base64,/,oh={getValueXY(e,t,i){return this.data[(t*this.width+e)*this.channels+i]},setValueXY(e,t,i,a){return this.data[(t*this.width+e)*this.channels+i]=a,this.computed=null,this},getValue(e,t){return this.data[e*this.channels+t]},setValue(e,t,i){return this.data[e*this.channels+t]=i,this.computed=null,this},getPixelXY(e,t){return this.getPixel(t*this.width+e)},setPixelXY(e,t,i){return this.setPixel(t*this.width+e,i)},getPixel(e){for(var t=Array(this.channels),a=e*this.channels,n=0;n<this.channels;n++)t[n]=this.data[a+n];return t},setPixel(e,t){for(var a=e*this.channels,n=0;n<t.length;n++)this.data[a+n]=t[n];return this.computed=null,this}},sh=lr||function(e){return e!==e},rh=function(e,t){return Mi(e),Mi(t),e-t},lh=[[-1,0,1],[-2,0,2],[-1,0,1]],dh=[[-1,-2,-1],[0,0,0],[1,2,1]],hh=[[3,0,-3],[10,0,-10],[3,0,-3]],gh=[[3,10,3],[0,0,0],[-3,-10,-3]],mh=h(function(e,t){(function(){var e=t;var a={release:'0.3.0',date:'2013-03'};e.toString=function(){return'version '+a.release+', released '+a.date};for(var o=0,n=null,r=null,s={init:function(e){if(0!==e&&0==(e&e-1))o=e,s._initArray(),s._makeBitReversalTable(),s._makeCosSinTable();else throw new Error('init: radix-2 required')},fft1d:function(e,t){s.fft(e,t,1)},ifft1d:function(e,t){var a=1/o;s.fft(e,t,-1);for(var n=0;n<o;n++)e[n]*=a,t[n]*=a},bt1d:function(e,t){s.fft(e,t,-1)},fft2d:function(e,t){for(var a=[],n=[],r=0,l=0;l<o;l++){r=l*o;for(var d=0;d<o;d++)a[d]=e[d+r],n[d]=t[d+r];s.fft1d(a,n);for(var h=0;h<o;h++)e[h+r]=a[h],t[h+r]=n[h]}for(var g=0;g<o;g++){for(var m=0;m<o;m++)r=g+m*o,a[m]=e[r],n[m]=t[r];s.fft1d(a,n);for(var c=0;c<o;c++)r=g+c*o,e[r]=a[c],t[r]=n[c]}},ifft2d:function(e,t){for(var a=[],n=[],r=0,l=0;l<o;l++){r=l*o;for(var d=0;d<o;d++)a[d]=e[d+r],n[d]=t[d+r];s.ifft1d(a,n);for(var h=0;h<o;h++)e[h+r]=a[h],t[h+r]=n[h]}for(var g=0;g<o;g++){for(var m=0;m<o;m++)r=g+m*o,a[m]=e[r],n[m]=t[r];s.ifft1d(a,n);for(var c=0;c<o;c++)r=g+c*o,e[r]=a[c],t[r]=n[c]}},fft:function(e,t,a){for(var s=o>>2,g=0,c,p,u,f,b,_,w,x,y;g<o;g++)f=n[g],g<f&&(b=e[g],e[g]=e[f],e[f]=b,b=t[g],t[g]=t[f],t[f]=b);for(var v=1;v<o;v<<=1){p=0,c=o/(v<<1);for(var D=0;D<v;D++){_=r[p+s],w=a*r[p];for(var S=D;S<o;S+=v<<1)u=S+v,x=_*e[u]+w*t[u],y=_*t[u]-w*e[u],e[u]=e[S]-x,e[S]+=x,t[u]=t[S]-y,t[S]+=y;p+=c}}},_initArray:function(){n='undefined'==typeof Uint32Array?[]:new Uint32Array(o),r='undefined'==typeof Float64Array?[]:new Float64Array(1.25*o)},_paddingZero:function(){},_makeBitReversalTable:function(){var e=0,t=0,a=0;for(n[0]=0;++e<o;){for(a=o>>1;a<=t;)t-=a,a>>=1;t+=a,n[e]=t}},_makeCosSinTable:function(){var e=o>>1,a=o>>2,n=o>>3,l=or(sr/o),d=2*l*l,h=nr(d*(2-d)),g=r[a]=1,m=r[0]=0;l=2*d;for(var p=1;p<n;p++)g-=d,d+=l*g,m+=h,h-=l*m,r[p]=m,r[a-p]=g;0!=n&&(r[n]=0.7071067811865476);for(var u=0;u<a;u++)r[e-u]=r[u];for(var f=0;f<e+a;f++)r[f+e]=-r[f]}},l=['init','fft1d','ifft1d','fft2d','ifft2d'],d=0;d<l.length;d++)e[l[d]]=s[l[d]];return e.bt=s.bt1d,e.fft=s.fft1d,e.ifft=s.ifft1d,e}).call(_r)}),ch={FFTUtils:{DEBUG:!1,ifft2DArray:function(e,t,i){var a=Array(t*i),n=t/2,o=2*(i-1);mh.init(n);for(var s={re:Array(n),im:Array(n)},r=0;r<i;r++){for(var l=n-1;0<=l;l--)s.re[l]=e[2*l*i+r],s.im[l]=e[(2*l+1)*i+r];mh.bt(s.re,s.im);for(var l=n-1;0<=l;l--)a[2*l*i+r]=s.re[l],a[(2*l+1)*i+r]=s.im[l]}var d=Array(n*o);mh.init(o);for(var h={re:Array(o),im:Array(o)},l=0;l<t;l+=2){h.re[0]=a[l*i],h.im[0]=a[(l+1)*i];for(var r=1;r<i;r++)h.re[r]=a[l*i+r],h.im[r]=a[(l+1)*i+r],h.re[o-r]=a[l*i+r],h.im[o-r]=-a[(l+1)*i+r];mh.bt(h.re,h.im);for(var g=l/2*o,r=o-1;0<=r;r--)d[g+r]=h.re[r]/(o*n)}return d},fft2DArray:function(e,t,i){var a=Object.assign({},{inplace:!0}),n=i/2+1,o=2*t,s=Array(o*n);mh.init(i);for(var r={re:Array(i),im:Array(i)},l={re:Array(i),im:Array(i)},d={re:Array(i),im:Array(i)},h=0,g,m,c,p,u;h<t/2;h++){g=2*h*i,r.re=e.slice(g,g+i),g=(2*h+1)*i,r.im=e.slice(g,g+i),mh.fft1d(r.re,r.im),this.reconstructTwoRealFFT(r,l,d),m=4*h*n,c=(4*h+1)*n,p=(4*h+2)*n,u=(4*h+3)*n;for(var f=n-1;0<=f;f--)s[m+f]=l.re[f],s[c+f]=l.im[f],s[p+f]=d.re[f],s[u+f]=d.im[f]}l=null,d=null;var b=Array(o*n);mh.init(t);for(var _={re:Array(t),im:Array(t)},w=n-1;0<=w;w--){for(var h=t-1;0<=h;h--)_.re[h]=s[2*h*n+w],_.im[h]=s[(2*h+1)*n+w],isNaN(_.re[h])&&(_.re[h]=0),isNaN(_.im[h])&&(_.im[h]=0);mh.fft1d(_.re,_.im);for(var h=t-1;0<=h;h--)b[2*h*n+w]=_.re[h],b[(2*h+1)*n+w]=_.im[h]}return b},reconstructTwoRealFFT:function(e,t,a){var n=e.re.length;t.re[0]=e.re[0],t.im[0]=0,a.re[0]=e.im[0],a.im[0]=0;for(var o=n/2,s,r,l,d,h;0<o;o--)h=n-o,s=.5*(e.re[o]-e.re[h]),r=.5*(e.re[o]+e.re[h]),l=.5*(e.im[o]-e.im[h]),d=.5*(e.im[o]+e.im[h]),t.re[o]=r,t.im[o]=l,t.re[h]=r,t.im[h]=-l,a.re[o]=d,a.im[o]=-s,a.re[h]=d,a.im[h]=s},convolute2DI:function(e,t,i,a){for(var n=0,o,s;n<i/2;n++)for(var r=0;r<a;r++)o=e[2*n*a+r]*t[2*n*a+r]-e[(2*n+1)*a+r]*t[(2*n+1)*a+r],s=e[2*n*a+r]*t[(2*n+1)*a+r]+e[(2*n+1)*a+r]*t[2*n*a+r],e[2*n*a+r]=o,e[(2*n+1)*a+r]=s},convolute:function(e,t,a,n){for(var o=Array(n*a),s=0;s<a*n;s++)o[s]=e[s];o=this.fft2DArray(o,a,n);for(var r=t.length,l=t[0].length,d=Array(n*a),s=0;s<n*a;s++)d[s]=0;for(var h=ur((r-1)/2),g=ur((l-1)/2),m=0,c,p;m<r;m++){c=(m-h+a)%a;for(var u=0;u<l;u++)p=(u-g+n)%n,d[c*n+p]=t[m][u]}d=this.fft2DArray(d,a,n);var f=2*a,b=n/2+1;return this.convolute2DI(o,d,f,b),this.ifft2DArray(o,f,b)},toRadix2:function(e,t,a){var n=a,o=t,s,r,l,d;if(0===a||0!=(a&a-1)){for(n=0;0!=a>>++n;);n=1<<n}if(0===t||0!=(t&t-1)){for(o=0;0!=t>>++o;);o=1<<o}if(o==t&&n==a)return{data:e,rows:t,cols:a};var h=Array(o*n),g=ur((o-t)/2)-t,m=ur((n-a)/2)-a;for(s=0;s<o;s++)for(l=s*n,d=(s-g)%t*a,r=0;r<n;r++)h[l+r]=e[d+(r-m)%a];return{data:h,rows:o,cols:n}},crop:function(e,t,a,n,o,s){if(t==n&&a==o)return e;var r=Object.assign({},s),l=Array(o*n),d=ur((t-n)/2),h=ur((a-o)/2),g,m,c,p;for(c=0;c<n;c++)for(g=c*o,m=(c+d)*a,p=0;p<o;p++)l[g+p]=e[m+(p+h)];return l}},FFT:mh}.FFTUtils,ph={fft:zi,direct:Yi,kernelFactory:{LoG:Li},matrix2Array:Ei},uh=ph.fft,fh=ph.direct,bh=Number.isFinite||function(e){return!('number'!=typeof e||sh(e)||e===1/0||e===-Infinity)},_h=gr||function(e){return'number'==typeof e&&bh(e)&&ur(e)===e};class wh{constructor(e){e=Ah.checkMatrix(e);var a=e.clone(),n=a.rows,o=a.columns,r=Array(n),l=1,d,h,g,m,c,u,f,b,_;for(d=0;d<n;d++)r[d]=d;for(b=Array(n),h=0;h<o;h++){for(d=0;d<n;d++)b[d]=a.get(d,h);for(d=0;d<n;d++){for(_=hr(d,h),c=0,g=0;g<_;g++)c+=a.get(d,g)*b[g];b[d]-=c,a.set(d,h,b[d])}for(m=h,d=h+1;d<n;d++)mr(b[d])>mr(b[m])&&(m=d);if(m!==h){for(g=0;g<o;g++)u=a.get(m,g),a.set(m,g,a.get(h,g)),a.set(h,g,u);f=r[m],r[m]=r[h],r[h]=f,l=-l}if(h<n&&0!==a.get(h,h))for(d=h+1;d<n;d++)a.set(d,h,a.get(d,h)/a.get(h,h))}this.LU=a,this.pivotVector=r,this.pivotSign=l}isSingular(){for(var e=this.LU,t=e.columns,i=0;i<t;i++)if(0===e[i][i])return!0;return!1}solve(e){e=Ch.checkMatrix(e);var t=this.LU,a=t.rows;if(a!==e.rows)throw new Error('Invalid matrix dimensions');if(this.isSingular())throw new Error('LU matrix is singular');var n=e.columns,o=e.subMatrixRow(this.pivotVector,0,n-1),s=t.columns,r,l,d;for(d=0;d<s;d++)for(r=d+1;r<s;r++)for(l=0;l<n;l++)o[r][l]-=o[d][l]*t[r][d];for(d=s-1;0<=d;d--){for(l=0;l<n;l++)o[d][l]/=t[d][d];for(r=0;r<d;r++)for(l=0;l<n;l++)o[r][l]-=o[d][l]*t[r][d]}return o}get determinant(){var e=this.LU;if(!e.isSquare())throw new Error('Matrix must be square');for(var t=this.pivotSign,i=e.columns,a=0;a<i;a++)t*=e[a][a];return t}get lowerTriangularMatrix(){for(var e=this.LU,t=e.rows,a=e.columns,n=new Ch(t,a),o=0;o<t;o++)for(var s=0;s<a;s++)n[o][s]=o>s?e[o][s]:o===s?1:0;return n}get upperTriangularMatrix(){for(var e=this.LU,t=e.rows,a=e.columns,n=new Ch(t,a),o=0;o<t;o++)for(var s=0;s<a;s++)n[o][s]=o<=s?e[o][s]:0;return n}get pivotPermutationVector(){return this.pivotVector.slice()}}class xh{constructor(t,i={}){t=Ah.checkMatrix(t);var o=t.rows,r=t.columns;const{computeLeftSingularVectors:l=!0,computeRightSingularVectors:d=!0,autoTranspose:h=!1}=i;var c=!!l,u=!!d,g=!1,f;if(!(o<r))f=t.clone();else if(!h)f=t.clone(),console.warn('Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose');else{f=t.transpose(),o=f.rows,r=f.columns,g=!0;var b=c;c=u,u=b}var _=hr(o,r),w=hr(o+1,r),x=Array(w),s=qi(o,_,0),y=qi(r,r,0),v=Array(r),e=Array(o),k=Array(w);for(let e=0;e<w;e++)k[e]=e;var D=hr(o-1,r),S=dr(0,hr(r-2,o)),M=dr(D,S);for(let a=0;a<M;a++){if(a<D){x[a]=0;for(let e=a;e<o;e++)x[a]=Hi(x[a],f[e][a]);if(0!==x[a]){0>f[a][a]&&(x[a]=-x[a]);for(let e=a;e<o;e++)f[e][a]/=x[a];f[a][a]+=1}x[a]=-x[a]}for(let e=a+1;e<r;e++){if(a<D&&0!==x[a]){let n=0;for(let t=a;t<o;t++)n+=f[t][a]*f[t][e];n=-n/f[a][a];for(let t=a;t<o;t++)f[t][e]+=n*f[t][a]}v[e]=f[a][e]}if(c&&a<D)for(let e=a;e<o;e++)s[e][a]=f[e][a];if(a<S){v[a]=0;for(let e=a+1;e<r;e++)v[a]=Hi(v[a],v[e]);if(0!==v[a]){0>v[a+1]&&(v[a]=0-v[a]);for(let e=a+1;e<r;e++)v[e]/=v[a];v[a+1]+=1}if(v[a]=-v[a],a+1<o&&0!==v[a]){for(let t=a+1;t<o;t++)e[t]=0;for(let t=a+1;t<o;t++)for(let i=a+1;i<r;i++)e[t]+=v[i]*f[t][i];for(let n=a+1,s;n<r;n++){s=-v[n]/v[a+1];for(let t=a+1;t<o;t++)f[t][n]+=s*e[t]}}if(u)for(let e=a+1;e<r;e++)y[e][a]=v[e]}}let P=hr(r,o+1);if(D<r&&(x[D]=f[D][D]),o<P&&(x[P-1]=0),S+1<P&&(v[S]=f[S][P-1]),v[P-1]=0,c){for(let e=D;e<_;e++){for(let t=0;t<o;t++)s[t][e]=0;s[e][e]=1}for(let e=D-1;0<=e;e--)if(0!==x[e]){for(let a=e+1,n;a<_;a++){n=0;for(let t=e;t<o;t++)n+=s[t][e]*s[t][a];n=-n/s[e][e];for(let t=e;t<o;t++)s[t][a]+=n*s[t][e]}for(let t=e;t<o;t++)s[t][e]=-s[t][e];s[e][e]=1+s[e][e];for(let t=0;t<e-1;t++)s[t][e]=0}else{for(let t=0;t<o;t++)s[t][e]=0;s[e][e]=1}}if(u)for(let e=r-1;0<=e;e--){if(e<S&&0!==v[e])for(let a=e+1,n;a<r;a++){n=0;for(let t=e+1;t<r;t++)n+=y[t][e]*y[t][a];n=-n/y[e+1][e];for(let t=e+1;t<r;t++)y[t][a]+=n*y[t][e]}for(let t=0;t<r;t++)y[t][e]=0;y[e][e]=1}for(var j=P-1,I=ir;0<P;){let e,t;for(e=P-2;-1<=e&&-1!==e;e--){const t=tr+I*mr(x[e]+mr(x[e+1]));if(mr(v[e])<=t||lr(v[e])){v[e]=0;break}}if(e===P-2)t=4;else{let i;for(i=P-1;i>=e&&i!==e;i--){let a=(i===P?0:mr(v[i]))+(i===e+1?0:mr(v[i-1]));if(mr(x[i])<=I*a){x[i]=0;break}}i===e?t=3:i===P-1?t=1:(t=2,e=i)}switch(e++,t){case 1:{let i=v[P-2];v[P-2]=0;for(let a=P-2;a>=e;a--){let n=Hi(x[a],i),t=x[a]/n,o=i/n;if(x[a]=n,a!==e&&(i=-o*v[a-1],v[a-1]=t*v[a-1]),u)for(let e=0;e<r;e++)n=t*y[e][a]+o*y[e][P-1],y[e][P-1]=-o*y[e][a]+t*y[e][P-1],y[e][a]=n}break}case 2:{let i=v[e-1];v[e-1]=0;for(let a=e;a<P;a++){let n=Hi(x[a],i),t=x[a]/n,r=i/n;if(x[a]=n,i=-r*v[a],v[a]=t*v[a],c)for(let l=0;l<o;l++)n=t*s[l][a]+r*s[l][e-1],s[l][e-1]=-r*s[l][a]+t*s[l][e-1],s[l][a]=n}break}case 3:{const t=dr(mr(x[P-1]),mr(x[P-2]),mr(v[P-2]),mr(x[e]),mr(v[e])),i=x[P-1]/t,a=x[P-2]/t,n=v[P-2]/t,l=x[e]/t,d=v[e]/t,h=((a+i)*(a-i)+n*n)/2,m=i*n*(i*n);let p=0;(0!=h||0!=m)&&(p=0>h?0-nr(h*h+m):nr(h*h+m),p=m/(h+p));let b=(l+i)*(l-i)+p,f=l*d;for(let a=e,n;a<P-1;a++){n=Hi(b,f),0===n&&(n=tr);let t=b/n,l=f/n;if(a!==e&&(v[a-1]=n),b=t*x[a]+l*v[a],v[a]=t*v[a]-l*x[a],f=l*x[a+1],x[a+1]=t*x[a+1],u)for(let e=0;e<r;e++)n=t*y[e][a]+l*y[e][a+1],y[e][a+1]=-l*y[e][a]+t*y[e][a+1],y[e][a]=n;if(n=Hi(b,f),0===n&&(n=tr),t=b/n,l=f/n,x[a]=n,b=t*v[a]+l*x[a+1],x[a+1]=-l*v[a]+t*x[a+1],f=l*v[a+1],v[a+1]=t*v[a+1],c&&a<o-1)for(let e=0;e<o;e++)n=t*s[e][a]+l*s[e][a+1],s[e][a+1]=-l*s[e][a]+t*s[e][a+1],s[e][a]=n}v[P-2]=b;break}case 4:{if(0>=x[e]&&(x[e]=0>x[e]?-x[e]:0,u))for(let t=0;t<=j;t++)y[t][e]=-y[t][e];for(;e<j&&!(x[e]>=x[e+1]);){let a=x[e];if(x[e]=x[e+1],x[e+1]=a,u&&e<r-1)for(let t=0;t<r;t++)a=y[t][e+1],y[t][e+1]=y[t][e],y[t][e]=a;if(c&&e<o-1)for(let t=0;t<o;t++)a=s[t][e+1],s[t][e+1]=s[t][e],s[t][e]=a;e++}P--;break}}}if(g){var B=y;y=s,s=B}this.m=o,this.n=r,this.s=x,this.U=s,this.V=y}solve(t){var a=this.threshold,e=this.s.length,n=Ch.zeros(e,e);for(let o=0;o<e;o++)n[o][o]=mr(this.s[o])<=a?0:1/this.s[o];var o=this.U,i=this.rightSingularVectors,s=i.mmul(n),r=i.rows,l=o.length,d=Ch.zeros(r,l);for(let a=0;a<r;a++)for(let t=0,i;t<l;t++){i=0;for(let n=0;n<e;n++)i+=s[a][n]*o[t][n];d[a][t]=i}return d.mmul(t)}solveForDiagonal(e){return this.solve(Ch.diag(e))}inverse(){var t=this.V,a=this.threshold,e=t.length,n=t[0].length,o=new Ch(e,this.s.length);for(let s=0;s<e;s++)for(let e=0;e<n;e++)o[s][e]=mr(this.s[e])>a?t[s][e]/this.s[e]:0;var s=this.U,r=s.length,l=s[0].length,d=new Ch(e,r);for(let t=0;t<e;t++)for(let e=0,i;e<r;e++){i=0;for(let a=0;a<l;a++)i+=o[t][a]*s[e][a];d[t][e]=i}return d}get condition(){return this.s[0]/this.s[hr(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){for(var e=dr(this.m,this.n)*this.s[0]*ir,t=0,a=this.s,n=0,o=a.length;n<o;n++)a[n]>e&&t++;return t}get diagonal(){return this.s}get threshold(){return ir/2*dr(this.m,this.n)*this.s[0]}get leftSingularVectors(){return Ch.isMatrix(this.U)||(this.U=new Ch(this.U)),this.U}get rightSingularVectors(){return Ch.isMatrix(this.V)||(this.V=new Ch(this.V)),this.V}get diagonalMatrix(){return Ch.diag(this.s)}}class kh extends sa(){constructor(e,t,i){super(),this.matrix=e,this.rows=t,this.columns=i}static get[Symbol.species](){return Ch}}class yh extends kh{constructor(e){super(e,e.columns,e.rows)}set(e,t,i){return this.matrix.set(t,e,i),this}get(e,t){return this.matrix.get(t,e)}}class vh extends kh{constructor(e,t){super(e,1,e.columns),this.row=t}set(e,t,i){return this.matrix.set(this.row,t,i),this}get(e,t){return this.matrix.get(this.row,t)}}class Dh extends kh{constructor(e,t,i,a,n){ta(e,t,i,a,n),super(e,i-t+1,n-a+1),this.startRow=t,this.startColumn=a}set(e,t,i){return this.matrix.set(this.startRow+e,this.startColumn+t,i),this}get(e,t){return this.matrix.get(this.startRow+e,this.startColumn+t)}}class Sh extends kh{constructor(e,t,i){var a=Qi(e,t,i);super(e,a.row.length,a.column.length),this.rowIndices=a.row,this.columnIndices=a.column}set(e,t,i){return this.matrix.set(this.rowIndices[e],this.columnIndices[t],i),this}get(e,t){return this.matrix.get(this.rowIndices[e],this.columnIndices[t])}}class Mh extends kh{constructor(e,t){t=$i(e,t),super(e,t.length,e.columns),this.rowIndices=t}set(e,t,i){return this.matrix.set(this.rowIndices[e],t,i),this}get(e,t){return this.matrix.get(this.rowIndices[e],t)}}class jh extends kh{constructor(e,t){t=ea(e,t),super(e,e.rows,t.length),this.columnIndices=t}set(e,t,i){return this.matrix.set(e,this.columnIndices[t],i),this}get(e,t){return this.matrix.get(e,this.columnIndices[t])}}class Ph extends kh{constructor(e,t){super(e,e.rows,1),this.column=t}set(e,t,i){return this.matrix.set(e,this.column,i),this}get(e){return this.matrix.get(e,this.column)}}class Ih extends kh{constructor(e){super(e,e.rows,e.columns)}set(e,t,i){return this.matrix.set(this.rows-e-1,t,i),this}get(e,t){return this.matrix.get(this.rows-e-1,t)}}class Bh extends kh{constructor(e){super(e,e.rows,e.columns)}set(e,t,i){return this.matrix.set(e,this.columns-t-1,i),this}get(e,t){return this.matrix.get(e,this.columns-t-1)}}class Ch extends sa(Array){constructor(e,t){var a;if(1===arguments.length&&'number'==typeof e)return Array(e);if(Ch.isMatrix(e))return e.clone();if(gr(e)&&0<e){if(super(e),gr(t)&&0<t)for(a=0;a<e;a++)this[a]=Array(t);else throw new TypeError('nColumns must be a positive integer');}else if(Array.isArray(e)){const i=e;if(e=i.length,t=i[0].length,'number'!=typeof t||0===t)throw new TypeError('Data must be a 2D array with at least one element');for(super(e),a=0;a<e;a++){if(i[a].length!==t)throw new RangeError('Inconsistent array dimensions');this[a]=[].concat(i[a])}}else throw new TypeError('First argument must be a positive number or an array');return this.rows=e,this.columns=t,this}set(e,t,i){return this[e][t]=i,this}get(e,t){return this[e][t]}removeRow(e){if(Wi(this,e),1===this.rows)throw new RangeError('A matrix cannot have less than one row');return this.splice(e,1),this.rows-=1,this}addRow(e,t){return void 0===t&&(t=e,e=this.rows),Wi(this,e,!0),t=Ki(this,t,!0),this.splice(e,0,t),this.rows+=1,this}removeColumn(e){if(Zi(this,e),1===this.columns)throw new RangeError('A matrix cannot have less than one column');for(var t=0;t<this.rows;t++)this[t].splice(e,1);return this.columns-=1,this}addColumn(e,t){'undefined'==typeof t&&(t=e,e=this.columns),Zi(this,e,!0),t=Ji(this,t);for(var a=0;a<this.rows;a++)this[a].splice(e,0,t[a]);return this.columns+=1,this}}class Rh extends sa(){constructor(e,t={}){const{rows:i=1}=t;if(0!=e.length%i)throw new Error('the data length is not divisible by the number of rows');super(),this.rows=i,this.columns=e.length/i,this.data=e}set(e,t,i){var a=this._calculateIndex(e,t);return this.data[a]=i,this}get(e,t){var i=this._calculateIndex(e,t);return this.data[i]}_calculateIndex(e,t){return e*this.columns+t}static get[Symbol.species](){return Ch}}class Ah extends sa(){constructor(e){super(),this.data=e,this.rows=e.length,this.columns=e[0].length}set(e,t,i){return this.data[e][t]=i,this}get(e,t){return this.data[e][t]}static get[Symbol.species](){return Ch}}class zh{constructor(e){e=Ah.checkMatrix(e);var t=e.clone(),a=e.rows,o=e.columns,n=Array(o),r,l,d,h;for(d=0;d<o;d++){var g=0;for(r=d;r<a;r++)g=Hi(g,t.get(r,d));if(0!==g){for(0>t.get(d,d)&&(g=-g),r=d;r<a;r++)t.set(r,d,t.get(r,d)/g);for(t.set(d,d,t.get(d,d)+1),l=d+1;l<o;l++){for(h=0,r=d;r<a;r++)h+=t.get(r,d)*t.get(r,l);for(h=-h/t.get(d,d),r=d;r<a;r++)t.set(r,l,t.get(r,l)+h*t.get(r,d))}}n[d]=-g}this.QR=t,this.Rdiag=n}solve(e){e=Ch.checkMatrix(e);var t=this.QR,a=t.rows;if(e.rows!==a)throw new Error('Matrix row dimensions must agree');if(!this.isFullRank())throw new Error('Matrix is rank deficient');var o=e.columns,r=e.clone(),l=t.columns,n,d,h,g;for(h=0;h<l;h++)for(d=0;d<o;d++){for(g=0,n=h;n<a;n++)g+=t[n][h]*r[n][d];for(g=-g/t[h][h],n=h;n<a;n++)r[n][d]+=g*t[n][h]}for(h=l-1;0<=h;h--){for(d=0;d<o;d++)r[h][d]/=this.Rdiag[h];for(n=0;n<h;n++)for(d=0;d<o;d++)r[n][d]-=r[h][d]*t[n][h]}return r.subMatrix(0,l-1,0,o-1)}isFullRank(){for(var e=this.QR.columns,t=0;t<e;t++)if(0===this.Rdiag[t])return!1;return!0}get upperTriangularMatrix(){var e=this.QR,t=e.columns,a=new Ch(t,t),n,o;for(n=0;n<t;n++)for(o=0;o<t;o++)a[n][o]=n<o?e[n][o]:n===o?this.Rdiag[n]:0;return a}get orthogonalMatrix(){var e=this.QR,t=e.rows,a=e.columns,n=new Ch(t,a),o,r,l,d;for(l=a-1;0<=l;l--){for(o=0;o<t;o++)n[o][l]=0;for(n[l][l]=1,r=l;r<a;r++)if(0!==e[l][l]){for(d=0,o=l;o<t;o++)d+=e[o][l]*n[o][r];for(d=-d/e[l][l],o=l;o<t;o++)n[o][r]+=d*e[o][l]}}return n}}class Yh{constructor(t,a={}){const{assumeSymmetric:o=!1}=a;if(t=Ah.checkMatrix(t),!t.isSquare())throw new Error('Matrix is not a square matrix');var s=t.columns,n=qi(s,s,0),r=Array(s),l=Array(s),e=t,d=!1,h,g;if(d=!!o||t.isSymmetric(),d){for(h=0;h<s;h++)for(g=0;g<s;g++)n[h][g]=e.get(h,g);ma(s,l,r,n),ca(s,l,r,n)}else{var m=qi(s,s,0),c=Array(s);for(g=0;g<s;g++)for(h=0;h<s;h++)m[h][g]=e.get(h,g);pa(s,m,c,n),ua(s,l,r,n,m)}this.n=s,this.e=l,this.d=r,this.V=n}get realEigenvalues(){return this.d}get imaginaryEigenvalues(){return this.e}get eigenvectorMatrix(){return Ch.isMatrix(this.V)||(this.V=new Ch(this.V)),this.V}get diagonalMatrix(){var t=this.n,a=this.e,e=this.d,n=new Ch(t,t),o,s;for(o=0;o<t;o++){for(s=0;s<t;s++)n[o][s]=0;n[o][o]=e[o],0<a[o]?n[o][o+1]=a[o]:0>a[o]&&(n[o][o-1]=a[o])}return n}}class Lh{constructor(e){if(e=Ah.checkMatrix(e),!e.isSymmetric())throw new Error('Matrix is not symmetric');var t=e,a=t.rows,n=new Ch(a,a),o=!0,r,l,h;for(l=0;l<a;l++){var g=n[l],m=0;for(h=0;h<l;h++){var c=n[h],p=0;for(r=0;r<h;r++)p+=c[r]*g[r];g[h]=p=(t.get(l,h)-p)/n[h][h],m+=p*p}for(m=t.get(l,l)-m,o&=0<m,n[l][l]=nr(dr(m,0)),h=l+1;h<a;h++)n[l][h]=0}if(!o)throw new Error('Matrix is not positive definite');this.L=n}solve(e){e=Ah.checkMatrix(e);var t=this.L,a=t.rows;if(e.rows!==a)throw new Error('Matrix dimensions do not match');var n=e.columns,o=e.clone(),s,r,l;for(l=0;l<a;l++)for(r=0;r<n;r++){for(s=0;s<l;s++)o[l][r]-=o[s][r]*t[l][s];o[l][r]/=t[l][l]}for(l=a-1;0<=l;l--)for(r=0;r<n;r++){for(s=l+1;s<a;s++)o[l][r]-=o[s][r]*t[s][l];o[l][r]/=t[l][l]}return o}get lowerTriangularMatrix(){return this.L}}var Eh=Object.freeze({default:Ch,Matrix:Ch,abstractMatrix:sa,wrap:function(e,t){if(Array.isArray(e))return e[0]&&Array.isArray(e[0])?new Ah(e):new Rh(e,t);throw new Error('the argument is not an array')},WrapperMatrix2D:Ah,WrapperMatrix1D:Rh,solve:la,inverse:ra,linearDependencies:ga,SingularValueDecomposition:xh,SVD:xh,EigenvalueDecomposition:Yh,EVD:Yh,CholeskyDecomposition:Lh,CHO:Lh,LuDecomposition:wh,LU:wh,QrDecomposition:zh,QR:zh}),Th=ya,Fh=Object.prototype.toString,Xh=function(e){return'Array'===Fh.call(e).substr(-6,5)};class Vh{constructor(){if(new.target===Vh)throw new Error('BaseRegression must be subclassed')}predict(e){if('number'==typeof e)return this._predict(e);if(Array.isArray(e)){const t=Array(e.length);for(let a=0;a<e.length;a++)t[a]=this._predict(e[a]);return t}throw new TypeError('x must be a number or array')}_predict(){throw new Error('_predict must be implemented')}train(){}toString(){return''}toLaTeX(){return''}score(e,t){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)throw new Error('x and y must be arrays of the same length');const a=e.length,n=Array(a);for(let o=0;o<a;o++)n[o]=this._predict(e[o]);let o=0,s=0,l=0,d=0,h=0,g=0,m=0;for(let r=0;r<a;r++)o+=n[r],s+=t[r],h+=n[r]*n[r],g+=t[r]*t[r],m+=n[r]*t[r],0!==t[r]&&(l+=(t[r]-n[r])*(t[r]-n[r])/t[r]),d=(t[r]-n[r])*(t[r]-n[r]);const i=(a*m-o*s)/nr((a*h-o*o)*(a*g-s*s));return{r:i,r2:i*i,chi2:l,rmsd:d*d/a}}}var Uh=Aa;Aa.squared=Ra;const Gh=Uh.squared,Oh={sigma:1};var Nh=class{constructor(e){e=Object.assign({},Oh,e),this.sigma=e.sigma,this.divisor=2*e.sigma*e.sigma}compute(e,t){const i=Gh(e,t);return rr(-i/this.divisor)}};const Hh={degree:1,constant:1,scale:1};var qh=class{constructor(e){e=Object.assign({},Hh,e),this.degree=e.degree,this.constant=e.constant,this.scale=e.scale}compute(e,t){for(var a=0,n=0;n<e.length;n++)a+=e[n]*t[n];return cr(this.scale*a+this.constant,this.degree)}};const Wh={sigma:1,degree:1};const Zh=Uh.squared,Kh={sigma:1};const Jh={sigma:1};var Qh=class{compute(e,t){for(var a=hr(e.length,t.length),n=0,o=0;o<a;++o)n+=hr(e[o],t[o]);return n}};const $h={sigma:1};const eg=Uh.squared,tg={constant:1};const ig=Uh.squared,ag={constant:1};const ng={alpha:.01,constant:-Math.E};var og=class{constructor(e){e=Object.assign({},ng,e),this.alpha=e.alpha,this.constant=e.constant}compute(e,t){for(var a=0,n=0;n<e.length;n++)a+=e[n]*t[n];return Math.tanh(this.alpha*a+this.constant)}};const sg=Eh.Matrix,rg={gaussian:Nh,rbf:Nh,polynomial:qh,poly:qh,anova:class{constructor(e){e=Object.assign({},Wh,e),this.sigma=e.sigma,this.degree=e.degree}compute(e,t){for(var a=0,n=hr(e.length,t.length),o=1;o<=n;++o)a+=cr(rr(-this.sigma*cr(cr(e[o-1],o)-cr(t[o-1],o),2)),this.degree);return a}},cauchy:class{constructor(e){e=Object.assign({},Kh,e),this.sigma=e.sigma}compute(e,t){return 1/(1+Zh(e,t)/(this.sigma*this.sigma))}},exponential:class{constructor(e){e=Object.assign({},Jh,e),this.sigma=e.sigma,this.divisor=2*e.sigma*e.sigma}compute(e,t){const i=Uh(e,t);return rr(-i/this.divisor)}},histogram:Qh,min:Qh,laplacian:class{constructor(e){e=Object.assign({},$h,e),this.sigma=e.sigma}compute(e,t){const i=Uh(e,t);return rr(-i/this.sigma)}},multiquadratic:class{constructor(e){e=Object.assign({},tg,e),this.constant=e.constant}compute(e,t){return nr(eg(e,t)+this.constant*this.constant)}},rational:class{constructor(e){e=Object.assign({},ag,e),this.constant=e.constant}compute(e,t){const i=ig(e,t);return 1-i/(i+this.constant)}},sigmoid:og,mlp:og};var lg=class{constructor(e,t){if(this.kernelType=e,'linear'!==e)if('string'==typeof e){e=e.toLowerCase();var i=rg[e];if(i)this.kernelFunction=new i(t);else throw new Error('unsupported kernel type: '+e)}else if('object'==typeof e&&'function'==typeof e.compute)this.kernelFunction=e;else throw new TypeError('first argument must be a valid kernel type or instance')}compute(e,t){if(void 0===t&&(t=e),'linear'===this.kernelType){var a=new sg(e);return a.mmul(new sg(t).transposeView())}const n=new sg(e.length,t.length);var o,s;if(e===t)for(o=0;o<e.length;o++)for(s=o;s<e.length;s++)n[o][s]=n[s][o]=this.kernelFunction.compute(e[o],e[s]);else for(o=0;o<e.length;o++)for(s=0;s<t.length;s++)n[o][s]=this.kernelFunction.compute(e[o],t[s]);return n}};const dg={lambda:.1,kernelType:'gaussian',kernelOptions:{},computeCoefficient:!1};class hg extends Vh{constructor(e,t,i){if(super(),!0===e)this.alpha=t.alpha,this.inputs=t.inputs,this.kernelType=t.kernelType,this.kernelOptions=t.kernelOptions,this.kernel=new lg(t.kernelType,t.kernelOptions);else{i=Object.assign({},dg,i);const a=new lg(i.kernelType,i.kernelOptions),o=a.compute(e),s=e.length;o.add(Ch.eye(s,s).mul(i.lambda)),this.alpha=la(o,t),this.inputs=e,this.kernelType=i.kernelType,this.kernelOptions=i.kernelOptions,this.kernel=a}}_predict(e){return this.kernel.compute([e],this.inputs).mmul(this.alpha)[0]}toJSON(){return{name:'kernelRidgeRegression',alpha:this.alpha,inputs:this.inputs,kernelType:this.kernelType,kernelOptions:this.kernelOptions}}static load(e){if('kernelRidgeRegression'!==e.name)throw new TypeError('not a KRR model');return new hg(!0,e)}}var gg=h(function(e,t){function a(e,t){return e-t}t.sum=function(e){for(var t=0,a=0;a<e.length;a++)t+=e[a];return t},t.max=function(e){for(var t=e[0],a=e.length,n=1;n<a;n++)e[n]>t&&(t=e[n]);return t},t.min=function(e){for(var t=e[0],a=e.length,n=1;n<a;n++)e[n]<t&&(t=e[n]);return t},t.minMax=function(e){for(var t=e[0],a=e[0],n=e.length,o=1;o<n;o++)e[o]<t&&(t=e[o]),e[o]>a&&(a=e[o]);return{min:t,max:a}},t.arithmeticMean=function(e){for(var t=0,a=e.length,n=0;n<a;n++)t+=e[n];return t/a},t.mean=t.arithmeticMean,t.geometricMean=function(e){for(var t=1,a=e.length,n=0;n<a;n++)t*=e[n];return cr(t,1/a)},t.logMean=function(e){for(var t=0,a=e.length,n=0;n<a;n++)t+=er(e[n]);return t/a},t.grandMean=function(e,t){for(var a=0,o=0,s=e.length,r=0;r<s;r++)a+=t[r]*e[r],o+=t[r];return a/o},t.truncatedMean=function(e,t,n){n===void 0&&(n=!1),n||(e=[].concat(e).sort(a));for(var o=e.length,s=ur(o*t),r=0,l=s;l<o-s;l++)r+=e[l];return r/(o-2*s)},t.harmonicMean=function(e){for(var t=0,a=e.length,n=0;n<a;n++){if(0===e[n])throw new RangeError('value at index '+n+'is zero');t+=1/e[n]}return a/t},t.contraHarmonicMean=function(e){for(var t=0,a=0,n=e.length,o=0;o<n;o++)t+=e[o]*e[o],a+=e[o];if(0>a)throw new RangeError('sum of values is negative');return t/a},t.median=function(e,t){t===void 0&&(t=!1),t||(e=[].concat(e).sort(a));var i=e.length,n=ur(i/2);return 0==i%2?.5*(e[n-1]+e[n]):e[n]},t.variance=function(e,a){a===void 0&&(a=!0);for(var n=t.mean(e),o=0,s=e.length,r=0,l;r<s;r++)l=e[r]-n,o+=l*l;return a?o/(s-1):o/s},t.standardDeviation=function(e,i){return nr(t.variance(e,i))},t.standardError=function(e){return t.standardDeviation(e)/nr(e.length)},t.robustMeanAndStdev=function(e){var t=0,n=0,o=e.length,s=0;for(s=0;s<o;s++)t+=e[s];t/=o;var r=Array(o);for(s=0;s<o;s++)r[s]=mr(e[s]-t);return r.sort(a),n=1==o%2?r[(o-1)/2]/.6745:.5*(r[o/2]+r[o/2-1])/.6745,{mean:t,stdev:n}},t.quartiles=function(e,i){'undefined'==typeof i&&(i=!1),i||(e=[].concat(e).sort(a));var n=e.length/4,o=e[pr(n)-1],s=t.median(e,!0),r=e[pr(3*n)-1];return{q1:o,q2:s,q3:r}},t.pooledStandardDeviation=function(e,i){return nr(t.pooledVariance(e,i))},t.pooledVariance=function(e,a){'undefined'==typeof a&&(a=!0);for(var n=0,o=0,s=e.length,r=0;r<s;r++){var l=e[r],d=t.variance(l);n+=(l.length-1)*d,o+=a?l.length-1:l.length}return n/o},t.mode=function(e){var t=e.length,a=Array(t),n;for(n=0;n<t;n++)a[n]=0;var o=Array(t),s=0;for(n=0;n<t;n++){var r=o.indexOf(e[n]);0<=r?a[r]++:(o[s]=e[n],a[s]=1,s++)}var l=0,d=0;for(n=0;n<s;n++)a[n]>l&&(l=a[n],d=n);return o[d]},t.covariance=function(e,a,n){'undefined'==typeof n&&(n=!0);var o=t.mean(e),s=t.mean(a);if(e.length!==a.length)throw'Vectors do not have the same dimensions';for(var r=0,d=e.length,l=0;l<d;l++){var h=e[l]-o,g=a[l]-s;r+=h*g}return n?r/(d-1):r/d},t.skewness=function(e,n){'undefined'==typeof n&&(n=!0);for(var o=t.mean(e),s=0,r=0,d=e.length,l=0,h;l<d;l++)h=e[l]-o,s+=h*h,r+=h*h*h;var m=s/d,c=r/d,p=c/cr(m,3/2);if(n){var g=nr(d*(d-1));return g/(d-2)*p}return p},t.kurtosis=function(e,a){'undefined'==typeof a&&(a=!0);for(var o=t.mean(e),s=e.length,n=0,r=0,l=0,d;l<s;l++)d=e[l]-o,n+=d*d,r+=d*d*d*d;var h=n/s,g=r/s;if(a){var m=n/(s-1),c=r/(m*m);return s*(s+1)/((s-1)*(s-2)*(s-3))*c-3*((s-1)*(s-1)/((s-2)*(s-3)))}return g/(h*h)-3},t.entropy=function(e,t){'undefined'==typeof t&&(t=0);for(var a=0,n=e.length,o=0;o<n;o++)a+=e[o]*er(e[o]+t);return-a},t.weightedMean=function(e,t){for(var a=0,n=e.length,o=0;o<n;o++)a+=e[o]*t[o];return a},t.weightedStandardDeviation=function(e,i){return nr(t.weightedVariance(e,i))},t.weightedVariance=function(e,n){for(var o=t.weightedMean(e,n),s=0,r=e.length,l=0,d=0,h=0;h<r;h++){var g=e[h]-o,m=n[h];s+=m*(g*g),d+=m,l+=m*m}return s*(d/(d*d-l))},t.center=function(e,a){'undefined'==typeof a&&(a=!1);var n=e;a||(n=[].concat(e));for(var o=t.mean(n),s=n.length,r=0;r<s;r++)n[r]-=o},t.standardize=function(e,a,n){'undefined'==typeof a&&(a=t.standardDeviation(e)),'undefined'==typeof n&&(n=!1);for(var o=e.length,s=n?e:Array(o),r=0;r<o;r++)s[r]=e[r]/a;return s},t.cumulativeSum=function(e){var t=e.length,a=Array(t);a[0]=e[0];for(var n=1;n<t;n++)a[n]=a[n-1]+e[n];return a}}),mg=gg.sum,cg=gg.max,pg=gg.min,ug=gg.minMax,fg=gg.arithmeticMean,bg=gg.mean,_g=gg.geometricMean,wg=gg.logMean,xg=gg.grandMean,kg=gg.truncatedMean,yg=gg.harmonicMean,vg=gg.contraHarmonicMean,Dg=gg.median,Sg=gg.variance,Mg=gg.standardDeviation,jg=gg.standardError,Pg=gg.robustMeanAndStdev,Ig=gg.quartiles,Bg=gg.pooledStandardDeviation,Cg=gg.pooledVariance,Rg=gg.mode,Ag=gg.covariance,zg=gg.skewness,Yg=gg.kurtosis,Lg=gg.entropy,Eg=gg.weightedMean,Tg=gg.weightedStandardDeviation,Fg=gg.weightedVariance,Xg=gg.center,Vg=gg.standardize,Ug=gg.cumulativeSum,Gg=h(function(e,t){function a(e,t){return e-t}t.max=function(e){for(var t=-Infinity,a=0;a<e.length;a++)for(var n=0;n<e[a].length;n++)e[a][n]>t&&(t=e[a][n]);return t},t.min=function(e){for(var t=1/0,a=0;a<e.length;a++)for(var n=0;n<e[a].length;n++)e[a][n]<t&&(t=e[a][n]);return t},t.minMax=function(e){for(var t=1/0,a=-Infinity,n=0;n<e.length;n++)for(var o=0;o<e[n].length;o++)e[n][o]<t&&(t=e[n][o]),e[n][o]>a&&(a=e[n][o]);return{min:t,max:a}},t.entropy=function(e,t){'undefined'==typeof t&&(t=0);for(var a=0,n=e.length,o=e[0].length,s=0;s<n;s++)for(var r=0;r<o;r++)a+=e[s][r]*er(e[s][r]+t);return-a},t.mean=function(e,t){'undefined'==typeof t&&(t=0);var a=e.length,n=e[0].length,o,s,r,l;if(-1===t){for(o=[0],s=a*n,r=0;r<a;r++)for(l=0;l<n;l++)o[0]+=e[r][l];o[0]/=s}else if(0===t)for(o=Array(n),s=a,l=0;l<n;l++){for(o[l]=0,r=0;r<a;r++)o[l]+=e[r][l];o[l]/=s}else if(1===t)for(o=Array(a),s=n,l=0;l<a;l++){for(o[l]=0,r=0;r<n;r++)o[l]+=e[l][r];o[l]/=s}else throw new Error('Invalid dimension');return o},t.sum=function(e,t){'undefined'==typeof t&&(t=0);var a=e.length,n=e[0].length,o,s,r;if(-1===t)for(o=[0],s=0;s<a;s++)for(r=0;r<n;r++)o[0]+=e[s][r];else if(0===t)for(o=Array(n),r=0;r<n;r++)for(o[r]=0,s=0;s<a;s++)o[r]+=e[s][r];else if(1===t)for(o=Array(a),r=0;r<a;r++)for(o[r]=0,s=0;s<n;s++)o[r]+=e[r][s];else throw new Error('Invalid dimension');return o},t.product=function(e,t){'undefined'==typeof t&&(t=0);var a=e.length,n=e[0].length,o,s,r;if(-1===t)for(o=[1],s=0;s<a;s++)for(r=0;r<n;r++)o[0]*=e[s][r];else if(0===t)for(o=Array(n),r=0;r<n;r++)for(o[r]=1,s=0;s<a;s++)o[r]*=e[s][r];else if(1===t)for(o=Array(a),r=0;r<a;r++)for(o[r]=1,s=0;s<n;s++)o[r]*=e[r][s];else throw new Error('Invalid dimension');return o},t.standardDeviation=function(e,a,n){for(var o=t.variance(e,a,n),s=o.length,r=0;r<s;r++)o[r]=nr(o[r]);return o},t.variance=function(e,a,n){'undefined'==typeof n&&(n=!0),a=a||t.mean(e);var o=e.length;if(0===o)return[];for(var s=e[0].length,r=Array(s),l=0;l<s;l++){for(var d=0,h=0,g=0,m=0;m<o;m++)g=e[m][l]-a[l],d+=g,h+=g*g;r[l]=n?(h-d*d/o)/(o-1):(h-d*d/o)/o}return r},t.median=function(e){for(var t=e.length,n=e[0].length,o=Array(n),s=0,r;s<n;s++){r=Array(t);for(var l=0;l<t;l++)r[l]=e[l][s];r.sort(a);var d=r.length;o[s]=0==d%2?.5*(r[d/2]+r[d/2-1]):r[ur(d/2)]}return o},t.mode=function(e){var t=e.length,a=e[0].length,n=Array(a),o,s;for(o=0;o<a;o++){for(var r=Array(t),l=0;l<t;l++)r[l]=0;var d=Array(t),h=0;for(s=0;s<t;s++){var g=d.indexOf(e[s][o]);0<=g?r[g]++:(d[h]=e[s][o],r[h]=1,h++)}var m=0,c=0;for(s=0;s<h;s++)r[s]>m&&(m=r[s],c=s);n[o]=d[c]}return n},t.skewness=function(e,o){'undefined'==typeof o&&(o=!0);for(var s=t.mean(e),r=e.length,n=s.length,l=Array(n),d=0;d<n;d++){for(var h=0,m=0,c=0,p;c<r;c++)p=e[c][d]-s[d],h+=p*p,m+=p*p*p;var u=h/r,f=m/r,b=f/cr(u,3/2);if(o){var g=nr(r*(r-1));l[d]=g/(r-2)*b}else l[d]=b}return l},t.kurtosis=function(e,a){'undefined'==typeof a&&(a=!0);for(var o=t.mean(e),s=e.length,n=e[0].length,r=Array(n),l=0;l<n;l++){for(var d=0,h=0,g=0,m;g<s;g++)m=e[g][l]-o[l],d+=m*m,h+=m*m*m*m;var c=d/s,p=h/s;if(a){var u=d/(s-1),f=h/(u*u);r[l]=s*(s+1)/((s-1)*(s-2)*(s-3))*f-3*((s-1)*(s-1)/((s-2)*(s-3)))}else r[l]=p/(c*c)-3}return r},t.standardError=function(e){for(var a=e.length,n=t.standardDeviation(e),o=n.length,s=Array(o),r=nr(a),l=0;l<o;l++)s[l]=n[l]/r;return s},t.covariance=function(e,i){return t.scatter(e,void 0,i)},t.scatter=function(e,a,n){'undefined'==typeof n&&(n=0),'undefined'==typeof a&&(0===n?a=e.length-1:1==n&&(a=e[0].length-1));var o=t.mean(e,n),r=e.length;if(0===r)return[[]];var l=e[0].length,d,h,g,m,c;if(0===n){for(d=Array(l),h=0;h<l;h++)d[h]=Array(l);for(h=0;h<l;h++)for(g=h;g<l;g++){for(m=0,c=0;c<r;c++)m+=(e[c][g]-o[g])*(e[c][h]-o[h]);m/=a,d[h][g]=m,d[g][h]=m}}else if(1===n){for(d=Array(r),h=0;h<r;h++)d[h]=Array(r);for(h=0;h<r;h++)for(g=h;g<r;g++){for(m=0,c=0;c<l;c++)m+=(e[g][c]-o[g])*(e[h][c]-o[h]);m/=a,d[h][g]=m,d[g][h]=m}}else throw new Error('Invalid dimension');return d},t.correlation=function(e){var a=t.mean(e),n=t.standardDeviation(e,!0,a),o=t.zScores(e,a,n),s=e.length,r=e[0].length,d=Array(r),h,g;for(h=0;h<r;h++)d[h]=Array(r);for(h=0;h<r;h++)for(g=h;g<r;g++){for(var m=0,p=0,u=o.length;p<u;p++)m+=o[p][g]*o[p][h];m/=s-1,d[h][g]=m,d[g][h]=m}return d},t.zScores=function(e,i,a){return i=i||t.mean(e),'undefined'==typeof a&&(a=t.standardDeviation(e,!0,i)),t.standardize(t.center(e,i,!1),a,!0)},t.center=function(e,a,n){a=a||t.mean(e);var o=e,s=e.length,r,l,d;if(!n)for(o=Array(s),r=0;r<s;r++)o[r]=Array(e[r].length);for(r=0;r<s;r++){var h=o[r];for(l=0,d=h.length;l<d;l++)h[l]=e[r][l]-a[l]}return o},t.standardize=function(e,a,n){'undefined'==typeof a&&(a=t.standardDeviation(e));var o=e,s=e.length,r,l,d;if(!n)for(o=Array(s),r=0;r<s;r++)o[r]=Array(e[r].length);for(r=0;r<s;r++){var h=o[r],g=e[r];for(l=0,d=h.length;l<d;l++)0===a[l]||isNaN(a[l])||(h[l]=g[l]/a[l])}return o},t.weightedVariance=function(e,n){var o=t.mean(e),s=e.length;if(0===s)return[];for(var r=e[0].length,l=Array(r),d=0;d<r;d++){for(var h=0,g=0,m=0,c=0;c<s;c++){var p=e[c][d]-o[d],u=n[c];h+=u*(p*p),m+=u,g+=u*u}l[d]=h*(m/(m*m-g))}return l},t.weightedMean=function(e,t,a){'undefined'==typeof a&&(a=0);var n=e.length;if(0===n)return[];var o=e[0].length,s,r,l,d,h,g;if(0===a){for(s=Array(o),r=0;r<o;r++)s[r]=0;for(r=0;r<n;r++)for(g=e[r],h=t[r],d=0;d<o;d++)s[d]+=g[d]*h}else if(1===a){for(s=Array(n),r=0;r<n;r++)s[r]=0;for(d=0;d<n;d++)for(g=e[d],h=t[d],r=0;r<o;r++)s[d]+=g[r]*h}else throw new Error('Invalid dimension');var m=gg.sum(t);if(0!==m)for(r=0,l=s.length;r<l;r++)s[r]/=m;return s},t.weightedCovariance=function(e,a,n,o){o=o||0,n=n||t.weightedMean(e,a,o);for(var s=0,r=0,l=0,d=a.length;l<d;l++)s+=a[l],r+=a[l]*a[l];var h=s/(s*s-r);return t.weightedScatter(e,a,n,h,o)},t.weightedScatter=function(e,a,n,o,r){r=r||0,n=n||t.weightedMean(e,a,r),'undefined'==typeof o&&(o=1);var l=e.length;if(0===l)return[[]];var d=e[0].length,h,g,m,c,p;if(0===r){for(h=Array(d),g=0;g<d;g++)h[g]=Array(d);for(g=0;g<d;g++)for(m=g;m<d;m++){for(p=0,c=0;c<l;c++)p+=a[c]*(e[c][m]-n[m])*(e[c][g]-n[g]);h[g][m]=p*o,h[m][g]=p*o}}else if(1===r){for(h=Array(l),g=0;g<l;g++)h[g]=Array(l);for(g=0;g<l;g++)for(m=g;m<l;m++){for(p=0,c=0;c<d;c++)p+=a[c]*(e[m][c]-n[m])*(e[g][c]-n[g]);h[g][m]=p*o,h[m][g]=p*o}}else throw new Error('Invalid dimension');return h}}),Og=Gg.max,Ng=Gg.min,Hg=Gg.minMax,qg=Gg.entropy,Wg=Gg.mean,Zg=Gg.sum,Kg=Gg.product,Jg=Gg.standardDeviation,Qg=Gg.variance,$g=Gg.median,em=Gg.mode,tm=Gg.skewness,im=Gg.kurtosis,am=Gg.standardError,nm=Gg.covariance,om=Gg.scatter,sm=Gg.correlation,rm=Gg.zScores,lm=Gg.center,dm=Gg.standardize,hm=Gg.weightedVariance,gm=Gg.weightedMean,mm=Gg.weightedCovariance,cm=Gg.weightedScatter;gg.median;var pm=function(){function e(e,t){var i=[],a=!0,n=!1,o=void 0;try{for(var s=e[Symbol.iterator](),r;!(a=(r=s.next()).done)&&(i.push(r.value),!(t&&i.length===t));a=!0);}catch(e){n=!0,o=e}finally{try{!a&&s['return']&&s['return']()}finally{if(n)throw o}}return i}return function(t,a){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,a);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}(),um={nearestneighbor:'nearestNeighbor',nearestneighbour:'nearestNeighbor',bilinear:'bilinear'},fm={luma709(e,t){return 6966*e[t]+23436*e[t+1]+2366*e[t+2]>>15},luma601(e,t){return 9798*e[t]+19235*e[t+1]+3735*e[t+2]>>15},maximum(e,t){return dr(e[t],e[t+1],e[t+2])},minimum(e,t){return hr(e[t],e[t+1],e[t+2])},average(e,t){return(e[t]+e[t+1]+e[t+2])/3>>0},minmax(e,t){return(dr(e[t],e[t+1],e[t+2])+hr(e[t],e[t+1],e[t+2]))/2},red(e,t){return e[t]},green(e,t){return e[t+1]},blue(e,t){return e[t+2]},cyan(e,t,i){var a=fm.black(e,t,i);return(i.maxValue-e[0]-a)/(1-a/i.maxValue)>>0},magenta(e,t,i){var a=fm.black(e,t,i);return(i.maxValue-e[1]-a)/(1-a/i.maxValue)>>0},yellow(e,t,i){var a=fm.black(e,t,i);return(i.maxValue-e[2]-a)/(1-a/i.maxValue)>>0},black(e,t,i){return hr(i.maxValue-e[t],i.maxValue-e[t+1],i.maxValue-e[t+2])},hue(e,t,i){var a=fm.min(e,t),n=fm.max(e,t);if(n===a)return 0;var o=0,s=n-a;switch(n){case e[t]:o=(e[t+1]-e[t+2])/s+(e[t+1]<e[t+2]?6:0);break;case e[t+1]:o=(e[t+2]-e[t])/s+2;break;case e[t+2]:o=(e[t]-e[t+1])/s+4;break;default:throw new Error('unreachable');}return o/6*i.maxValue>>0},saturation(e,t,i){var a=fm.min(e,t),n=fm.max(e,t);return 0===n?0:(n-a)/n*i.maxValue},lightness(e,t){var i=fm.min(e,t),a=fm.max(e,t);return(a+i)/2}};Object.defineProperty(fm,'luminosity',{enumerable:!1,value:fm.lightness}),Object.defineProperty(fm,'luminance',{enumerable:!1,value:fm.lightness}),Object.defineProperty(fm,'min',{enumerable:!1,value:fm.minimum}),Object.defineProperty(fm,'max',{enumerable:!1,value:fm.maximum}),Object.defineProperty(fm,'brightness',{enumerable:!1,value:fm.maximum});var bm={};Object.keys(fm).forEach(e=>{bm[e]=e});var _m={huang:function(e){for(var t=0,i=0;i<e.length;i++)if(0!==e[i]){t=i;break}for(var a=e.length-1,n=e.length-1;n>=t;n--)if(0!==e[n]){a=n;break}for(var o=1/(a-t),s=Array(e.length),r=0,l=0,d=t;d<e.length;d++)r+=d*e[d],l+=e[d],s[d]=r/l;var h=Array(e.length);r=l=0;for(var g=a;0<g;g--)r+=g*e[g],l+=e[g],h[g-1]=r/l;for(var m=-1,c=$s,p=0;p<e.length;p++){for(var u=0,f=void 0,b=0;b<=p;b++)f=1/(1+o*mr(b-s[p])),1e-6>f||.999999<f||(u+=e[b]*(-f*er(f)-(1-f)*er(1-f)));for(var _=p+1;_<e.length;_++)f=1/(1+o*mr(_-h[p])),1e-6>f||.999999<f||(u+=e[_]*(-f*er(f)-(1-f)*er(1-f)));u<c&&(c=u,m=p)}return m},intermodes:Dn,isodata:Mn,li:function(e,t){var i=void 0,a=void 0,n=void 0,o=void 0,s=void 0,r=void 0,l=void 0,d=void 0,h=void 0,g=void 0,m=void 0,c=void 0;m=.5,g=0;for(var p=0;p<e.length;p++)g+=p*e[p];g/=t,l=g;do{r=l,i=0|r+.5,a=0,o=0;for(var u=0;u<=i;u++)a+=u*e[u],o+=e[u];d=0===o?0:a/o,n=0,s=0;for(var f=i+1;f<e.length;f++)n+=f*e[f],s+=e[f];h=0===s?0:n/s,c=(d-h)/(er(d)-er(h)),l=c<-ir?0|c-.5:0|c+.5}while(mr(l-r)>m);return i},maxentropy:function(e,t){for(var i=Array(e.length),a=0;a<e.length;a++)i[a]=e[a]/t;var n=Array(e.length),o=Array(e.length);n[0]=i[0],o[0]=1-n[0];for(var s=1;s<e.length;s++)n[s]=n[s-1]+i[s],o[s]=1-n[s];for(var r=0,l=0;l<e.length;l++)if(mr(n[l])>=ir){r=l;break}for(var d=e.length-1,h=e.length-1;h>=r;h--)if(mr(o[h])>=ir){d=h;break}for(var g=-1,m=void 0,c=tr,p=void 0,u=void 0,f=r;f<=d;f++){p=0;for(var b=0;b<=f;b++)0!==e[b]&&(p-=i[b]/n[f]*er(i[b]/n[f]));u=0;for(var _=f+1;_<e.length;_++)0!==e[_]&&(u-=i[_]/o[f]*er(i[_]/o[f]));m=p+u,c<m&&(c=m,g=f)}return g},mean:jn,minerror:Pn,minimum:Rn,moments:Ln,otsu:En,percentile:Tn,renyientropy:function(e,t){for(var i=void 0,a=void 0,n=void 0,o=Array(e.length),s=Array(e.length),r=Array(e.length),l=0,d=0,h=0,g=0,m=0,c=0,p=0;p<e.length;p++)o[p]=e[p]/t;s[0]=o[0],r[0]=1-s[0];for(var u=1;u<e.length;u++)s[u]=s[u-1]+o[u],r[u]=1-s[u];a=0;for(var f=0;f<e.length;f++)if(mr(s[f])>=ir){a=f;break}n=e.length-1;for(var b=e.length-1;b>=a;b--)if(mr(r[b])>=ir){n=b;break}for(var _=a;_<=n;_++){for(var w=0,x=0,k=0,y=0;y<=_;y++)0!==e[y]&&(w-=o[y]/s[_]*er(o[y]/s[_])),x+=nr(o[y]/s[_]),k+=o[y]*o[y]/(s[_]*s[_]);for(var v=0,D=0,S=0,M=_+1;M<e.length;M++)0!==e[M]&&(v-=o[M]/r[_]*er(o[M]/r[_])),D+=nr(o[M]/r[_]),S+=o[M]*o[M]/(r[_]*r[_]);var j=w+v,P=2*(0<x*D?er(x*D):0),I=-1*(0<k*S?er(k*S):0);j>g&&(g=j,l=_),P>m&&(m=P,d=_),I>c&&(c=I,h=_)}var B=[l,d,h];B.sort(rh);var C=5>=mr(B[0]-B[1])?5>=mr(B[1]-B[2])?[1,2,1]:[0,1,3]:5>=mr(B[1]-B[2])?[3,1,0]:[1,2,1];var R=s[B[2]]-s[B[0]];return i=ar(B[0]*(s[B[0]]+.25*R*C[0])+.25*B[1]*R*C[1]+B[2]*(r[B[2]]+.25*R*C[2])),i},shanbhag:function(e,t){for(var i=Array(e.length),a=0;a<e.length;a++)i[a]=e[a]/t;var n=Array(e.length),o=Array(e.length);n[0]=i[0],o[0]=1-n[0];for(var s=1;s<e.length;s++)n[s]=n[s-1]+i[s],o[s]=1-n[s];for(var r=0,l=0;l<e.length;l++)if(mr(n[l])>=ir){r=l;break}for(var d=e.length-1,h=e.length-1;h>=r;h--)if(mr(o[h])>=ir){d=h;break}for(var g=-1,m=$s,c=void 0,p=void 0,u=void 0,f=void 0,b=r;b<=d;b++){u=0,c=.5/n[b];for(var _=1;_<=b;_++)u-=i[_]*er(1-c*n[_-1]);u*=c,f=0,c=.5/o[b];for(var w=b+1;w<e.length;w++)f-=i[w]*er(1-c*o[w]);f*=c,p=mr(u-f),p<m&&(m=p,g=b)}return g},triangle:Xn,yen:function(e,t){for(var i=Array(e.length),a=0;a<e.length;a++)i[a]=e[a]/t;var n=Array(e.length);n[0]=i[0];for(var o=1;o<e.length;o++)n[o]=n[o-1]+i[o];var s=Array(e.length);s[0]=i[0]*i[0];for(var r=1;r<e.length;r++)s[r]=s[r-1]+i[r]*i[r];var l=Array(e.length);l[e.length-1]=0;for(var d=e.length-2;0<=d;d--)l[d]=l[d+1]+i[d+1]*i[d+1];for(var h=-1,g=tr,m=void 0,c=0;c<e.length;c++)m=-1*(0<s[c]*l[c]?er(s[c]*l[c]):0)+2*(0<n[c]*(1-n[c])?er(n[c]*(1-n[c])):0),m>g&&(g=m,h=c);return h}},wm={};Object.keys(_m).forEach(e=>{wm[e]=e});lo.prototype.localMin=function(e,t){for(var a=this[e][t],n=[e,t],o=dr(0,e-1);o<hr(this.length,e+2);o++)for(var s=dr(0,t-1);s<hr(this[0].length,t+2);s++)this[o][s]<a&&(a=this[o][s],n=[o,s]);return{position:n,value:a}},lo.prototype.localMax=function(e,t){for(var a=this[e][t],n=[e,t],o=dr(0,e-1);o<hr(this.length,e+2);o++)for(var s=dr(0,t-1);s<hr(this[0].length,t+2);s++)this[o][s]>a&&(a=this[o][s],n=[o,s]);return{position:n,value:a}},lo.prototype.localSearch=function(e,t,a){for(var n=[],o=dr(0,e-1);o<hr(this.length,e+2);o++)for(var s=dr(0,t-1);s<hr(this[0].length,t+2);s++)this[o][s]===a&&n.push([o,s]);return n};const xm={lowThreshold:10,highThreshold:30,gaussianBlur:1.1},km=[[-1,0,1],[-2,0,2],[-1,0,1]],ym=[[-1,-2,-1],[0,0,0],[1,2,1]],vm={bitDepth:32,mode:'periodic'};var Dm=h(function(e){(function(){function t(e,t,i){this.next=i,i&&(i.prev=this),this.prev=t,t&&(t.next=this),this.data=e}function i(){return this instanceof i?void(this._head=null,this._tail=null,this.length=0):new i}i.prototype={push:function(e){this._tail=new t(e,this._tail,null),this._head||(this._head=this._tail),this.length++},pop:function(){if(0!==this.length){var e=this._tail;return this._tail=e.prev,e.prev&&(e.prev=this._tail.next=null),this.length--,1===this.length?this._head=this._tail:0===this.length&&(this._head=this._tail=null),e.data}},unshift:function(e){this._head=new t(e,null,this._head),this._tail||(this._tail=this._head),this.length++},shift:function(){if(0!==this.length){var e=this._head;return this._head=e.next,e.next&&(e.next=this._head.prev=null),this.length--,1===this.length?this._tail=this._head:0===this.length&&(this._head=this._tail=null),e.data}},item:function(e){0>e&&(e=this.length+e);for(var t=this._head;0<e--&&t;)t=t.next;return t?t.data:void 0},slice:function(e,t){if(e||(e=0),t||(t=this.length),0>t&&(t=this.length+t),0>e&&(e=this.length+e),t===e)return[];if(t<e)throw new Error('invalid offset: '+e+','+t+' (length='+this.length+')');for(var a=t-e,o=Array(a),s=0,r=this._head;0<e--&&r;)r=r.next;for(;s<a&&r;)o[s++]=r.data,r=r.next;return o},drop:function(){i.call(this)},forEach:function(e,t){for(var a=this._head,n=0,o=this.length;n<o&&a;)e.call(t||this,a.data,n,this),a=a.next,n++},map:function(e,t){var a=new i;return this.forEach(function(n,o,i){a.push(e.call(t||i,n,o,i))}),a},filter:function(e,t){var a=new i;return this.forEach(function(n,o,i){e.call(t||i,n,o,i)&&a.push(n)}),a},reduce:function(e,t,a){var n=0,o=this._head,s=this.length;for(t||(n=1,t=o&&o.data,o=o&&o.next);n<s&&o;)t=e.call(a||this,t,o.data,this),n++,o=o.next;return t}},e.exports=i})()}),Sm=function(e,t,i){var t=t/100,i=i/100,a=[],n=i*t,o=e/60,r=n*(1-mr(o%2-1)),l=i-n;switch(parseInt(o,10)){case 0:a=[n,r,0];break;case 1:a=[r,n,0];break;case 2:a=[0,n,r];break;case 3:a=[0,r,n];break;case 4:a=[r,0,n];break;case 5:a=[n,0,r];}return{r:ar(255*(a[0]+l)),g:ar(255*(a[1]+l)),b:ar(255*(a[2]+l))}},Mm=function(e,t,i){return[jo(e),jo(t),jo(i)].join('')},jm=function(e,t,i,n){return n/=100,{r:parseInt(255*(1-n)+n*e,10),g:parseInt(255*(1-n)+n*t,10),b:parseInt(255*(1-n)+n*i,10)}},Pm=function(e,t,i){return t*=(50>i?i:100-i)/100,{h:e,s:100*(2*t/(i+t)),v:i+t}},Im=function(e,t,i){var a=Pm(e,t,i);return Sm(a.h,a.s,a.v)},Bm={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]},Cm={hex2rgb:function(e){return('#'===e[0]&&(e=e.substr(1)),6===e.length)?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16)}:3===e.length?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16)}:void 0},hsv2hex:function(e,t,i){var a=Sm(e,t,i);return Mm(a.r,a.g,a.b)},hsv2rgb:Sm,rgb2hex:Mm,rgb2hsv:function(e,t,i){var a=dr(e,t,i),n=hr(e,t,i),o=a-n,r,l,d;return r=0==o?0:e===a?(t-i)/o%6:t===a?(i-e)/o+2:(e-t)/o+4,r=ar(60*r),0>r&&(r+=360),l=ar(100*(0===a?0:o/a)),d=ar(100*(a/255)),{h:r,s:l,v:d}},rgba:function(e,t,i,n){return'rgba('+[e,t,i,n/100].join(',')+')'},rgba2rgb:jm,rgba2hex:function(e,t,i,n){var a=jm(e,t,i,n);return Mm(a.r,a.g,a.b)},hsl2hsv:Pm,hsv2hsl:function(e,t,i){var a=(200-t)*i/100;return{h:e,s:t*i/(100>a?a:200-a),l:a/2}},hsl2rgb:Im,cssColor:function(e){return Bo(e)||zo(e)||Ao(e)||Co(e)||Ro(e)||Yo(e)||Lo(e)}}.cssColor,Rm=[[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]],Am=[[0,1,0],[1,1,1],[0,1,0]];class zm{constructor(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.kind,i=void 0===t?'cross':t,a=e.shape,n=e.size,o=e.width,s=e.height,r=e.filled,l=void 0===r||r;if(n&&(o=n,s=n),a)switch(a.toLowerCase()){case'square':case'rectangle':this.matrix=No(o,s,{filled:l});break;case'circle':case'ellipse':this.matrix=Ho(o,s,{filled:l});break;case'triangle':this.matrix=qo(o,s,{filled:l});break;default:throw new Error(`Shape: unexpected shape: ${a}`);}else if(i)switch(i.toLowerCase()){case'cross':this.matrix=Rm;break;case'smallcross':this.matrix=Am;break;default:throw new Error(`Shape: unexpected kind: ${i}`);}else throw new Error('Shape: expected a kind or a shape option');this.height=this.matrix.length,this.width=this.matrix[0].length,this.halfHeight=this.height/2>>0,this.halfWidth=this.width/2>>0}getPoints(){for(var e=this.matrix,t=[],i=0;i<e.length;i++)for(var a=0;a<e[0].length;a++)e[i][a]&&t.push([a-this.halfWidth,i-this.halfHeight]);return t}getMask(){for(var e=new tc(this.width,this.height,{kind:'BINARY'}),t=0;t<this.matrix.length;t++)for(var i=0;i<this.matrix[0].length;i++)this.matrix[t][i]&&e.setBitXY(i,t);return e}}class Ym{constructor(e,t){this.parent=e,this.width=e.width,this.height=e.height,this.data=t,this.negative=0,this.positive=0,this.computed={}}get total(){return this.negative+this.positive}get minMax(){if(!this.computed.minMax){for(var e=Number.MAX_SAFE_INTEGER,t=Number.MIN_SAFE_INTEGER,a=0;a<this.data.length;a++)this.data[a]<e&&(e=this.data[a]),this.data[a]>t&&(t=this.data[a]);this.computed.minMax={min:e,max:t}}return this.computed.minMax}get commonBorderLength(){return Ms(this)}mergeRoi(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{};return js.call(this,e)}rowsInfo(){for(var e=Array(this.height),t=0,a=0,n;a<this.data.length;a+=this.width){n={row:t,positivePixel:0,negativePixel:0,zeroPixel:0,positiveRoi:0,negativeRoi:0,medianChange:0},e[t++]=n;for(var o={},s={},r=[],l=this.data[a],d=0,h=a,g;h<a+this.width;h++)g=this.data[h],l!==g&&(l=g,r.push(d),d=0),d++,0<g?(n.positivePixel++,!o[g]&&(o[g]=!0)):0>g?(n.negativePixel++,!s[g]&&(s[g]=!0)):n.zeroPixel++;r.push(d),n.medianChange=r.sort((e,t)=>e-t)[ur(r.length/2)],n.positiveRoiIDs=Object.keys(o),n.negativeRoiIDs=Object.keys(s),n.positiveRoi=n.positiveRoiIDs.length,n.negativeRoi=n.negativeRoiIDs.length}return e}colsInfo(){for(var e=Array(this.width),t=0,a=0,n;a<this.width;a++){n={col:t,positivePixel:0,negativePixel:0,zeroPixel:0,positiveRoi:0,negativeRoi:0,medianChange:0},e[t++]=n;for(var o={},s={},r=[],l=this.data[a],d=0,h=a,g;h<a+this.data.length;h+=this.width)g=this.data[h],l!==g&&(l=g,r.push(d),d=0),d++,0<g?(n.positivePixel++,!o[g]&&(o[g]=!0)):0>g?(n.negativePixel++,!s[g]&&(s[g]=!0)):n.zeroPixel++;r.push(d),n.medianChange=r.sort((e,t)=>e-t)[ur(r.length/2)],n.positiveRoiIDs=Object.keys(o),n.negativeRoiIDs=Object.keys(s),n.positiveRoi=n.positiveRoiIDs.length,n.negativeRoi=n.negativeRoiIDs.length}return e}}var Lm=class{constructor(){this.nodes=new Map}add(e){var t=this.nodes.get(e);return t||(t=new Is(e),this.nodes.set(e,t)),t}union(e,t){const i=this.find(e),a=this.find(t);i===a||(i.rank<a.rank?i.parent=a:i.rank>a.rank?a.parent=i:(a.parent=i,i.rank++))}find(e){for(var t=e;null!==t.parent;)t=t.parent;for(var i=e;null!==i.parent;){var a=i;i=i.parent,a.parent=t}return t}connected(e,t){return this.find(e)===this.find(t)}},Em=[-1,0],Tm=[0,-1],Fm=[null,null],Xm=[-1,-1,0,1],Vm=[0,-1,-1,-1],Um=[null,null,null,null],Gm=h(function(e){(function(t){e.exports=t()})(function(){return function h(g,e,t){function a(i,o){if(!e[i]){if(!g[i]){var s='function'==typeof d&&d;if(!o&&s)return s(i,!0);if(n)return n(i,!0);var r=new Error('Cannot find module \''+i+'\'');throw r.code='MODULE_NOT_FOUND',r}var m=e[i]={exports:{}};g[i][0].call(m.exports,function(t){var e=g[i][1][t];return a(e?e:t)},m,m.exports,h,g,e,t)}return e[i].exports}for(var n='function'==typeof d&&d,i=0;i<t.length;i++)a(t[i]);return a}({1:[function(e,t){var i=function(e,t){function i(){this.constructor=e}for(var n in t)a.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e},a={}.hasOwnProperty,n,o,s,r,l;n=e('./PriorityQueue/AbstractPriorityQueue'),o=e('./PriorityQueue/ArrayStrategy'),r=e('./PriorityQueue/BinaryHeapStrategy'),s=e('./PriorityQueue/BHeapStrategy'),l=function(e){function t(e){e||(e={}),e.strategy||(e.strategy=r),e.comparator||(e.comparator=function(e,t){return(e||0)-(t||0)}),t.__super__.constructor.call(this,e)}return i(t,e),t}(n),l.ArrayStrategy=o,l.BinaryHeapStrategy=r,l.BHeapStrategy=s,t.exports=l},{"./PriorityQueue/AbstractPriorityQueue":2,"./PriorityQueue/ArrayStrategy":3,"./PriorityQueue/BHeapStrategy":4,"./PriorityQueue/BinaryHeapStrategy":5}],2:[function(e,t){var i;t.exports=i=function(){function e(e){var t;if(null==(null==e?void 0:e.strategy))throw'Must pass options.strategy, a strategy';if(null==(null==e?void 0:e.comparator))throw'Must pass options.comparator, a comparator';this.priv=new e.strategy(e),this.length=(null==e||null==(t=e.initialValues)?void 0:t.length)||0}return e.prototype.queue=function(e){return this.length++,void this.priv.queue(e)},e.prototype.dequeue=function(){if(!this.length)throw'Empty queue';return this.length--,this.priv.dequeue()},e.prototype.peek=function(){if(!this.length)throw'Empty queue';return this.priv.peek()},e.prototype.clear=function(){return this.length=0,this.priv.clear()},e}()},{}],3:[function(e,t){var i,a;a=function(e,t,i){var a,n,o;for(n=0,a=e.length;n<a;)o=n+a>>>1,0<=i(e[o],t)?n=o+1:a=o;return n},t.exports=i=function(){function e(e){var t;this.options=e,this.comparator=this.options.comparator,this.data=(null==(t=this.options.initialValues)?void 0:t.slice(0))||[],this.data.sort(this.comparator).reverse()}return e.prototype.queue=function(e){var t;return t=a(this.data,e,this.comparator),void this.data.splice(t,0,e)},e.prototype.dequeue=function(){return this.data.pop()},e.prototype.peek=function(){return this.data[this.data.length-1]},e.prototype.clear=function(){this.data.length=0},e}()},{}],4:[function(e,t){var i;t.exports=i=function(){function e(e){var t,a,n,o,s,r,l,d,h;for(this.comparator=(null==e?void 0:e.comparator)||function(e,t){return e-t},this.pageSize=(null==e?void 0:e.pageSize)||512,this.length=0,d=0;1<<d<this.pageSize;)d+=1;if(1<<d!==this.pageSize)throw'pageSize must be a power of two';for(this._shift=d,this._emptyMemoryPageTemplate=t=[],(a=n=0,r=this.pageSize);0<=r?n<r:n>r;a=0<=r?++n:--n)t.push(null);if(this._memory=[],this._mask=this.pageSize-1,e.initialValues)for(l=e.initialValues,o=0,s=l.length;o<s;o++)h=l[o],this.queue(h)}return e.prototype.queue=function(e){return this.length+=1,this._write(this.length,e),void this._bubbleUp(this.length,e)},e.prototype.dequeue=function(){var e,t;return e=this._read(1),t=this._read(this.length),this.length-=1,0<this.length&&(this._write(1,t),this._bubbleDown(1,t)),e},e.prototype.peek=function(){return this._read(1)},e.prototype.clear=function(){return this.length=0,void(this._memory.length=0)},e.prototype._write=function(e,t){var i;for(i=e>>this._shift;i>=this._memory.length;)this._memory.push(this._emptyMemoryPageTemplate.slice(0));return this._memory[i][e&this._mask]=t},e.prototype._read=function(e){return this._memory[e>>this._shift][e&this._mask]},e.prototype._bubbleUp=function(e,t){var i,a,n,o;for(i=this.comparator;1<e&&(a=e&this._mask,e<this.pageSize||3<a?n=e&~this._mask|a>>1:2>a?(n=e-this.pageSize>>this._shift,n+=n&~(this._mask>>1),n|=this.pageSize>>1):n=e-2,o=this._read(n),!(0>i(o,t)));)this._write(n,t),this._write(e,o),e=n},e.prototype._bubbleDown=function(e,t){var i,a,n,o,s;for(s=this.comparator;e<this.length;)if(e>this._mask&&!(e&this._mask-1)?i=a=e+2:e&this.pageSize>>1?(i=(e&~this._mask)>>1,i|=e&this._mask>>1,i=i+1<<this._shift,a=i+1):(i=e+(e&this._mask),a=i+1),i!=a&&a<=this.length){if(n=this._read(i),o=this._read(a),0>s(n,t)&&0>=s(n,o))this._write(i,t),this._write(e,n),e=i;else if(0>s(o,t))this._write(a,t),this._write(e,o),e=a;else break;}else if(!(i<=this.length))break;else if(n=this._read(i),0>s(n,t))this._write(i,t),this._write(e,n),e=i;else break},e}()},{}],5:[function(e,t){var i;t.exports=i=function(){function e(e){var t;this.comparator=(null==e?void 0:e.comparator)||function(e,t){return e-t},this.length=0,this.data=(null==(t=e.initialValues)?void 0:t.slice(0))||[],this._heapify()}return e.prototype._heapify=function(){var e,t,a;if(0<this.data.length)for(e=t=1,a=this.data.length;1<=a?t<a:t>a;e=1<=a?++t:--t)this._bubbleUp(e)},e.prototype.queue=function(e){return this.data.push(e),void this._bubbleUp(this.data.length-1)},e.prototype.dequeue=function(){var e,t;return t=this.data[0],e=this.data.pop(),0<this.data.length&&(this.data[0]=e,this._bubbleDown(0)),t},e.prototype.peek=function(){return this.data[0]},e.prototype.clear=function(){return this.length=0,void(this.data.length=0)},e.prototype._bubbleUp=function(e){for(var t,i;0<e&&(t=e-1>>>1,0>this.comparator(this.data[e],this.data[t]));)i=this.data[t],this.data[t]=this.data[e],this.data[e]=i,e=t},e.prototype._bubbleDown=function(e){var t,i,a,n,o;for(t=this.data.length-1;i=(e<<1)+1,n=i+1,a=e,i<=t&&0>this.comparator(this.data[i],this.data[a])&&(a=i),n<=t&&0>this.comparator(this.data[n],this.data[a])&&(a=n),a!==e;)o=this.data[a],this.data[a]=this.data[e],this.data[e]=o,e=a},e}()},{}]},{},[1])(1)})}),Om=[1,0,-1,0,1,1,-1,-1],Nm=[0,1,0,-1,1,-1,1,-1],Hm=zs,qm=function(t,e){var i=0|t.length,n=0|e.length;if(1==i&&1==n)return Ys(t[0],e[0]);var o=Array(i+n),s=0,r=0,l=0,d=mr,h=t[r],g=d(h),m=e[l],c=d(m),p,u;g<c?(u=h,r+=1,r<i&&(h=t[r],g=d(h))):(u=m,l+=1,l<n&&(m=e[l],c=d(m))),r<i&&g<c||l>=n?(p=h,r+=1,r<i&&(h=t[r],g=d(h))):(p=m,l+=1,l<n&&(m=e[l],c=d(m)));for(var f=p+u,_=f-p,w=u-_,k=w,v=f,D,S,M,j,P;r<i&&l<n;)g<c?(p=h,r+=1,r<i&&(h=t[r],g=d(h))):(p=m,l+=1,l<n&&(m=e[l],c=d(m))),u=k,f=p+u,_=f-p,w=u-_,w&&(o[s++]=w),D=v+f,S=D-v,M=D-S,j=f-S,P=v-M,k=P+j,v=D;for(;r<i;)p=h,u=k,f=p+u,_=f-p,w=u-_,w&&(o[s++]=w),D=v+f,S=D-v,M=D-S,j=f-S,P=v-M,k=P+j,v=D,r+=1,r<i&&(h=t[r]);for(;l<n;)p=m,u=k,f=p+u,_=f-p,w=u-_,w&&(o[s++]=w),D=v+f,S=D-v,M=D-S,j=f-S,P=v-M,k=P+j,v=D,l+=1,l<n&&(m=e[l]);return k&&(o[s++]=k),v&&(o[s++]=v),s||(o[s++]=0),o.length=s,o},Wm=function(e,t,i){var a=e+t,n=a-e,o=t-n,s=e-(a-n);return i?(i[0]=s+o,i[1]=a,i):[s+o,a]},Zm=function(t,e){var i=0|t.length,n=0|e.length;if(1==i&&1==n)return Es(t[0],-e[0]);var o=Array(i+n),s=0,r=0,l=0,d=mr,h=t[r],g=d(h),m=-e[l],c=d(m),p,u;g<c?(u=h,r+=1,r<i&&(h=t[r],g=d(h))):(u=m,l+=1,l<n&&(m=-e[l],c=d(m))),r<i&&g<c||l>=n?(p=h,r+=1,r<i&&(h=t[r],g=d(h))):(p=m,l+=1,l<n&&(m=-e[l],c=d(m)));for(var f=p+u,_=f-p,w=u-_,k=w,v=f,D,S,M,j,P;r<i&&l<n;)g<c?(p=h,r+=1,r<i&&(h=t[r],g=d(h))):(p=m,l+=1,l<n&&(m=-e[l],c=d(m))),u=k,f=p+u,_=f-p,w=u-_,w&&(o[s++]=w),D=v+f,S=D-v,M=D-S,j=f-S,P=v-M,k=P+j,v=D;for(;r<i;)p=h,u=k,f=p+u,_=f-p,w=u-_,w&&(o[s++]=w),D=v+f,S=D-v,M=D-S,j=f-S,P=v-M,k=P+j,v=D,r+=1,r<i&&(h=t[r]);for(;l<n;)p=m,u=k,f=p+u,_=f-p,w=u-_,w&&(o[s++]=w),D=v+f,S=D-v,M=D-S,j=f-S,P=v-M,k=P+j,v=D,l+=1,l<n&&(m=-e[l]);return k&&(o[s++]=k),v&&(o[s++]=v),s||(o[s++]=0),o.length=s,o},Km=h(function(e){function t(e,t){for(var a=Array(e.length-1),n=1,o;n<e.length;++n){o=a[n-1]=Array(e.length-1);for(var s=0,l=0;s<e.length;++s)s!==t&&(o[l++]=e[n][s])}return a}function a(e){for(var t=Array(e),a=0;a<e;++a){t[a]=Array(e);for(var n=0;n<e;++n)t[a][n]=['m',n,'[',e-a-1,']'].join('')}return t}function n(e){return 1&e?'-':''}function o(e){if(1===e.length)return e[0];if(2===e.length)return['sum(',e[0],',',e[1],')'].join('');var t=e.length>>1;return['sum(',o(e.slice(0,t)),',',o(e.slice(t)),')'].join('')}function s(e){if(2===e.length)return[['sum(prod(',e[0][0],',',e[1][1],'),prod(-',e[0][1],',',e[1][0],'))'].join('')];for(var a=[],r=0;r<e.length;++r)a.push(['scale(',o(s(t(e,r))),',',n(r),e[0][r],')'].join(''));return a}function i(e){for(var n=[],r=[],l=a(e),d=[],h=0;h<e;++h)0==(1&h)?n.push.apply(n,s(t(l,h))):r.push.apply(r,s(t(l,h))),d.push('m'+h);var g=o(n),m=o(r),c='orientation'+e+'Exact',p=['function ',c,'(',d.join(),'){var p=',g,',n=',m,',d=sub(p,n);return d[d.length-1];};return ',c].join(''),u=new Function('sum','prod','scale','sub',p);return u(qm,Hm,Ls,Zm)}function r(e){var t=m[e.length];return t||(t=m[e.length]=i(e.length)),t.apply(void 0,e)}function l(){for(;m.length<=5;)m.push(i(m.length));for(var t=[],a=['slow'],n=0;n<=5;++n)t.push('a'+n),a.push('o'+n);for(var o=['function getOrientation(',t.join(),'){switch(arguments.length){case 0:case 1:return 0;'],n=2;n<=5;++n)o.push('case ',n,':return o',n,'(',t.slice(0,n).join(),');');o.push('}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation'),a.push(o.join(''));var s=Function.apply(void 0,a);e.exports=s.apply(void 0,[r].concat(m));for(var n=0;n<=5;++n)e.exports[n]=m[n]}var h=11102230246251565e-32,d=i(3),g=i(4),m=[function(){return 0},function(){return 0},function(e,t){return t[0]-e[0]},function(e,t,i){var a=(e[1]-i[1])*(t[0]-i[0]),n=(e[0]-i[0])*(t[1]-i[1]),o=a-n,r;if(0<a){if(0>=n)return o;r=a+n}else if(0>a){if(0<=n)return o;r=-(a+n)}else return o;var l=(3+16*h)*h*r;return o>=l||o<=-l?o:d(e,t,i)},function(e,t,i,a){var n=e[0]-a[0],o=t[0]-a[0],s=i[0]-a[0],r=e[1]-a[1],l=t[1]-a[1],d=i[1]-a[1],m=e[2]-a[2],c=t[2]-a[2],p=i[2]-a[2],u=o*d,f=s*l,b=s*r,_=n*d,w=n*l,x=o*r,k=m*(u-f)+c*(b-_)+p*(w-x),y=(mr(u)+mr(f))*mr(m)+(mr(b)+mr(_))*mr(c)+(mr(w)+mr(x))*mr(p),v=(7+56*h)*h*y;return k>v||-k>v?k:g(e,t,i,a)}];l()});class Jm{constructor(e,t){var i=Number.NEGATIVE_INFINITY;this.map=e,this.id=t,this.minX=Ks,this.maxX=i,this.minY=Ks,this.maxY=i,this.meanX=0,this.meanY=0,this.surface=0,this.computed={}}getMask(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.scale,i=void 0===t?1:t,a=e.kind,n=void 0===a?'':a,o=void 0;return o='contour'===n?this.contourMask:'box'===n?this.boxMask:'filled'===n?this.filledMask:'center'===n?this.centerMask:'hull'===n?this.hullMask:this.mask,1>i&&(o=o.resize({factor:i}),o.parent=this.mask.parent,o.position[0]+=this.minX,o.position[1]+=this.minY),o}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(){var e=this.borderIDs,t=this.borderLengths;this.computed.externalIDs=[],this.computed.externalLengths=[];for(var a=this.internalIDs,n=0;n<e.length;n++)a.includes(e[n])||(this.computed.externalIDs.push(e[n]),this.computed.externalLengths.push(t[n]))}get externalIDs(){return this.computed.externalIDs?this.computed.externalIDs:(this._computExternalIDs(),this.computed.externalIDs)}get externalLengths(){return this.computed.externalLengths?this.computed.externalLengths:(this._computExternalIDs(),this.computed.externalLengths)}_computeBorderIDs(){var e=Fs(this);this.computed.borderIDs=e.ids,this.computed.borderLengths=e.lengths}get borderIDs(){return this.computed.borderIDs?this.computed.borderIDs:(this._computeBorderIDs(),this.computed.borderIDs)}get borderLengths(){return this.computed.borderLengths?this.computed.borderLengths:(this._computeBorderIDs(),this.computed.borderLengths)}get boxIDs(){return this.computed.boxIDs||(this.computed.boxIDs=Xs(this)),this.computed.boxIDs}get internalIDs(){return this.computed.internalIDs||(this.computed.internalIDs=Os(this)),this.computed.internalIDs}get box(){return this.computed.box||(this.computed.box=Vs(this)),this.computed.box}get external(){return this.computed.external||(this.computed.external=Gs(this)),this.computed.external}get border(){return this.computed.border||(this.computed.border=Us(this)),this.computed.border}get contourMask(){if(!this.computed.contourMask){for(var e=new tc(this.width,this.height,{kind:'BINARY',position:[this.minX,this.minY],parent:this.map.parent}),t=0;t<this.width;t++)for(var i=0;i<this.height;i++)this.map.data[t+this.minX+(i+this.minY)*this.map.width]===this.id&&(0<t&&t<this.width-1&&0<i&&i<this.height-1?(this.map.data[t-1+this.minX+(i+this.minY)*this.map.width]!==this.id||this.map.data[t+1+this.minX+(i+this.minY)*this.map.width]!==this.id||this.map.data[t+this.minX+(i-1+this.minY)*this.map.width]!==this.id||this.map.data[t+this.minX+(i+1+this.minY)*this.map.width]!==this.id)&&e.setBitXY(t,i):e.setBitXY(t,i));this.computed.contourMask=e}return this.computed.contourMask}get boxMask(){if(!this.computed.boxMask){for(var e=new tc(this.width,this.height,{kind:'BINARY',position:[this.minX,this.minY],parent:this.map.parent}),t=0;t<this.width;t++)e.setBitXY(t,0),e.setBitXY(t,this.height-1);for(var i=0;i<this.height;i++)e.setBitXY(0,i),e.setBitXY(this.width-1,i);this.computed.boxMask=e}return this.computed.boxMask}get mask(){if(!this.computed.mask){for(var e=new tc(this.width,this.height,{kind:'BINARY',position:[this.minX,this.minY],parent:this.map.parent}),t=0;t<this.width;t++)for(var i=0;i<this.height;i++)this.map.data[t+this.minX+(i+this.minY)*this.map.width]===this.id&&e.setBitXY(t,i);this.computed.mask=e}return this.computed.mask}get filledMask(){if(!this.computed.filledMask){for(var e=new tc(this.width,this.height,{kind:'BINARY',position:[this.minX,this.minY],parent:this.map.parent}),t=0;t<this.width;t++)for(var i=0,a;i<this.height;i++)a=t+this.minX+(i+this.minY)*this.map.width,this.internalIDs.includes(this.map.data[a])&&e.setBitXY(t,i);this.computed.filledMask=e}return this.computed.filledMask}get centerMask(){if(!this.computed.centerMask){var e=new zm({kind:'smallCross'}).getMask();e.parent=this.map.parent,e.position=[this.minX+this.center[0]-1,this.minY+this.center[1]-1],this.computed.centerMask=e}return this.computed.centerMask}get hullMask(){if(!this.computed.hullMask){for(var e=new tc(this.width,this.height,{kind:'BINARY',position:[this.minX,this.minY],parent:this.map.parent}),t=this.mask.monotoneChainConvexHull(),i=0;i<this.width;i++)for(var a=0;a<this.height;a++)1!==Ts(t,[i,a])&&e.setBitXY(i,a);this.computed.hullMask=e}return this.computed.hullMask}get points(){if(!this.computed.points){for(var e=[],t=0;t<this.height;t++)for(var i=0,a;i<this.width;i++)a=(t+this.minY)*this.map.width+i+this.minX,this.map.data[a]===this.id&&e.push([i,t]);this.computed.points=e}return this.computed.points}get maxLengthPoints(){if(!this.computed.maxLengthPoints){for(var e=0,t=void 0,a=this.points,n=0;n<a.length;n++)for(var o=n+1,s;o<a.length;o++)s=cr(a[n][0]-a[o][0],2)+cr(a[n][1]-a[o][1],2),s>=e&&(e=s,t=[a[n],a[o]]);this.computed.maxLengthPoints=t}return this.computed.maxLengthPoints}get maxLength(){if(!this.computed.maxLength){var e=nr(cr(this.maxLengthPoints[0][0]-this.maxLengthPoints[1][0],2)+cr(this.maxLengthPoints[0][1]-this.maxLengthPoints[1][1],2));this.computed.maxLength=e}return this.computed.maxLength}get angle(){if(!this.computed.angle){var e=this.maxLengthPoints,t=180*-Js(e[0][1]-e[1][1],e[0][0]-e[1][0])/sr;this.computed.angle=t}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}}}class Qm{constructor(e,t){this.roiMap=e,this.options=t,this.roi=this.createRoi()}createRoi(){var e=this.roiMap.data,t={};this.roiMap.positive=0,this.roiMap.negative=0;for(var a=0;a<e.length;a++)e[a]&&!t[e[a]]&&(t[e[a]]=!0,0<e[a]?this.roiMap.positive++:this.roiMap.negative++);var n={};for(var o in t)n[o]=new Jm(this.roiMap,1*o);for(var s=this.roiMap.width,r=this.roiMap.height,l=0;l<r;l++)for(var d=0,h;d<s;d++)if(h=l*s+d,0!==e[h]){var g=e[h],m=n[g];d<m.minX&&(m.minX=d),d>m.maxX&&(m.maxX=d),l<m.minY&&(m.minY=l),l>m.maxY&&(m.maxY=l),m.meanX+=d,m.meanY+=l,m.surface++}var c=[];for(var p in t)n[p].meanX/=n[p].surface,n[p].meanY/=n[p].surface,c.push(n[p]);return c}}class $m{constructor(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};this._image=e,this._options=t,this._options.label||(this._options.label='default'),this._layers={},this._painted=null}fromMaxima(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=Object.assign({},this._options,e),i=Cs.call(this._image,e);this._layers[t.label]=new Qm(i,t)}fromPoints(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=Object.assign({},this._options,t),a=As.call(this._image,e,t);return this._layers[i.label]=new Qm(a,i),this}putMap(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=new Ym(this._image,e),a=Object.assign({},this._options,t);return this._layers[a.label]=new Qm(i,a),this}fromWaterShed(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=Object.assign({},this._options,e),i=Rs.call(this._image,e);this._layers[t.label]=new Qm(i,t)}fromMask(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=Object.assign({},this._options,t),a=Ps.call(this._image,e,t);return this._layers[i.label]=new Qm(a,i),this}fromMaskConnectedComponentLabelingAlgorithm(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=Object.assign({},this._options,t),a=Bs.call(this._image,e,t);return this._layers[i.label]=new Qm(a,i),this}getMap(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=Object.assign({},this._options,e);return this._assertLayerWithLabel(t.label),this._layers[t.label].roiMap}rowsInfo(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{};return this.getMap(e).rowsInfo()}colsInfo(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{};return this.getMap(e).rowsInfo()}getRoiIds(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=this.getRois(e);if(t){for(var a=Array(t.length),n=0;n<t.length;n++)a[n]=t[n].id;return a}throw new Error('ROIs not found')}getRois(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.label,a=void 0===t?this._options.label:t,n=e.positive,o=e.negative,s=e.minSurface,r=void 0===s?0:s,l=e.maxSurface,d=void 0===l?Ks:l,h=e.minWidth,g=void 0===h?0:h,m=e.maxWidth,c=void 0===m?Ks:m,p=e.minHeight,u=void 0===p?0:p,f=e.maxHeight,b=void 0===f?Ks:f,_=e.minRatio,w=void 0===_?0:_,x=e.maxRatio,k=void 0===x?Ks:x;if(!this._layers[a])throw new Error(`getRoi: This Roi layer (${a}) does not exists.`);for(var y=this._layers[a].roi,v=Array(y.length),D=0,S=0,M;S<y.length;S++)M=y[S],(0>M.id&&(void 0===o||o)||0<M.id&&(void 0===n||n))&&M.surface>=r&&M.surface<=d&&M.width>=g&&M.width<=c&&M.height>=u&&M.height<=b&&M.ratio>=w&&M.ratio<=k&&(v[D++]=M);return v.length=D,v}getMasks(){for(var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=this.getRois(e),a=Array(t.length),n=0;n<t.length;n++)a[n]=t[n].getMask(e);return a}getData(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=Object.assign({},this._options,e);return this._assertLayerWithLabel(t.label),this._layers[t.label].roiMap.data}paint(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.labelProperty;this._painted||(this._painted=this._image.rgba8());var i=this.getMasks(e);if(t){var a=this.getRois(e);e.labels=a.map(e=>e[t]),e.labelsPosition=a.map(e=>[e.meanX,e.meanY])}return this._painted.paintMasks(i,e),this._painted}getMask(){for(var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=new tc(this._image.width,this._image.height,{kind:'BINARY'}),a=this.getMasks(e),n=0,o;n<a.length;n++){o=a[n];for(var s=0;s<o.width;s++)for(var r=0;r<o.height;r++)o.getBitXY(s,r)&&t.setBitXY(s+o.position[0],r+o.position[1])}return t}resetPainted(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},t=e.image;this._painted=t?this.image.rgba8():this._image.rgba8()}mergeRoi(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=this.getMap(e);return t.mergeRoi(e),this.putMap(t.data,e),this}findCorrespondingRoi(e){for(var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},a=this.getRois(t),n=[],o=0;o<a.length;o++){var s=a[o],r=s.minX,l=s.minY,d=s.points,h=Zs(s.id),g=Ns(r,l,d,e,h);n.push(g)}return n}_assertLayerWithLabel(e){if(!this._layers[e])throw new Error(`no layer with label ${e}`)}}var ec=Object.prototype.toString;class tc{constructor(e,t,i,a){if(1===arguments.length){a=e;var n=a;e=n.width,t=n.height,i=n.data}else if(i&&!i.length){a=i;var o=a;i=o.data}if(void 0===e&&(e=1),void 0===t&&(t=1),void 0===a&&(a={}),'object'!=typeof a||null===a)throw new TypeError('options must be an object');if(!gr(e)||0>=e)throw new RangeError('width must be a positive integer');if(!gr(t)||0>=t)throw new RangeError('height must be a positive integer');var s=a,r=s.kind,l=void 0===r?'RGBA':r;if('string'!=typeof l)throw new TypeError('kind must be a string');var d=rt(l),h=Object.assign({},a);for(var g in d)void 0===h[g]&&(h[g]=d[g]);lt(h);var m=h.components,c=h.bitDepth,p=h.colorModel,u=h.alpha+0,f=e*t,b=m+u,_=32===c?$s:cr(2,c)-1;if(void 0===i)i=ht(f,m,u,b,c,_);else{var w=dt(f,b,c);if(i.length!==w)throw new RangeError(`incorrect data size: ${i.length}. Should be ${w}`)}this.width=e,this.height=t,this.data=i,this.size=f,this.components=m,this.alpha=u,this.bitDepth=c,this.maxValue=_,this.colorModel=p,this.channels=b,this.meta=a.meta||{},Object.defineProperty(this,'parent',{enumerable:!1,writable:!0,configurable:!0,value:a.parent||null}),this.position=a.position||[0,0],this.computed=null,this.sizes=[this.width,this.height],this.multiplierX=this.channels,this.multiplierY=this.channels*this.width,this.isClamped=32>this.bitDepth,this.borderSizes=[0,0]}get[Symbol.toStringTag](){return'IJSImage'}static isImage(e){return'[object IJSImage]'===ec.call(e)}static fromCanvas(e){var t=e.getContext('2d'),i=t.getImageData(0,0,e.width,e.height);return new tc(i.width,i.height,i.data)}static createFrom(e,t){var i=pi(e);return Object.assign(i,{parent:e,position:[0,0]},t),new tc(i)}getRoiManager(e){return new $m(this,e)}clone(){var e=this.data.slice();return new tc(this.width,this.height,e,this)}apply(e){for(var t=0;t<this.height;t++)for(var i=0,a;i<this.width;i++)a=(t*this.width+i)*this.channels,e.call(this,a)}}ci(tc),n(tc),$e(tc),tc.prototype.checkProcessable=function(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},i=t.bitDepth,a=t.alpha,n=t.colorModel,o=t.components,s=t.channels;if('string'!=typeof e||0===e.length)throw new TypeError('processName must be a string');if(i&&(Array.isArray(i)||(i=[i]),!i.includes(this.bitDepth)))throw new TypeError(`The process: ${e} can only be applied if bit depth is in: ${i}`);if(a&&(Array.isArray(a)||(a=[a]),!a.includes(this.alpha)))throw new TypeError(`The process: ${e} can only be applied if alpha is in: ${a}`);if(n&&(Array.isArray(n)||(n=[n]),!n.includes(this.colorModel)))throw new TypeError(`The process: ${e} can only be applied if color model is in: ${n}`);if(o&&(Array.isArray(o)||(o=[o]),!o.includes(this.components))){var r=`The process: ${e} can only be applied if the number of components is in: ${o}`;if(1===o.length&&1===o[0])throw new TypeError(`${r}.\rYou should transform your image using "image.grey()" before applying the algorithm.`);else throw new TypeError(r)}if(s&&(Array.isArray(s)||(s=[s]),!s.includes(this.channels)))throw new TypeError(`The process: ${e} can only be applied if the number of channels is in: ${s}`)},tc.prototype.getRGBAData=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.clamped;this.checkProcessable('getRGBAData',{components:[1,3],bitDepth:[1,8,16,32]});var i=4*(this.width*this.height),a=t?new Uint8ClampedArray(i):new Uint8Array(i);return 1===this.bitDepth?et(this,a):32===this.bitDepth?(this.checkProcessable('getRGBAData',{alpha:0}),1===this.components?tt(this,a):3===this.components&&(this.checkProcessable('getRGBAData',{colorModel:['RGB']}),it(this,a))):1===this.components?at(this,a):3===this.components&&(this.checkProcessable('getRGBAData',{colorModel:['RGB']}),nt(this,a)),1===this.alpha?(this.checkProcessable('getRGBAData',{bitDepth:[8,16]}),ot(this,a)):st(this,a),a},tc.load=function(e,t){if('string'==typeof e)return si(e,t);if(e instanceof ArrayBuffer)return Promise.resolve(oi(new Uint8Array(e)));if(e.buffer)return Promise.resolve(oi(e));throw new Error('argument to "load" must be a string or buffer.')},tc.extendMethod=function(e,t){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},a=i.inPlace,n=i.returnThis,o=i.partialArgs,s=void 0===o?[]:o;return tc.prototype[e]=void 0!==a&&a?function(){this.computed=null;for(var e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];var o=t.apply(this,[...s,...i]);return void 0===n||n?this:o}:function(){for(var e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];return t.apply(this,[...s,...i])},tc},tc.extendProperty=function(e,t){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},a=i.partialArgs,n=void 0===a?[]:a;return rd.get=function(){if(null===this.computed)this.computed={};else if(od(e,this.computed))return this.computed[e];var i=t.apply(this,n);return this.computed[e]=i,i},Object.defineProperty(tc.prototype,e,rd),tc},function(e){var t={inPlace:!0};e.extendMethod('invert',xi),e.extendMethod('abs',bi),e.extendMethod('level',va,t),e.extendMethod('add',Ma,t),e.extendMethod('subtract',ja,t),e.extendMethod('subtractImage',Pa),e.extendMethod('multiply',Ba,t),e.extendMethod('divide',Ca,t),e.extendMethod('hypotenuse',Ia),e.extendMethod('background',za),e.extendMethod('flipX',vi),e.extendMethod('flipY',Di),e.extendMethod('blurFilter',Si),e.extendMethod('medianFilter',Ci),e.extendMethod('gaussianFilter',Ri),e.extendMethod('sobelFilter',xa),e.extendMethod('gradientFilter',wa),e.extendMethod('scharrFilter',ka),e.extendMethod('dilate',Ya),e.extendMethod('erode',Xa),e.extendMethod('open',Na),e.extendMethod('close',Ha),e.extendMethod('topHat',qa),e.extendMethod('blackHat',Wa),e.extendMethod('morphologicalGradient',Za),e.extendMethod('warpingFourPoints',an),e.extendMethod('crop',nn),e.extendMethod('cropAlpha',on),e.extendMethod('resize',_n).extendMethod('scale',_n),e.extendMethod('hsv',wn),e.extendMethod('hsl',xn),e.extendMethod('cmyk',kn),e.extendMethod('rgba8',yn),e.extendMethod('grey',vn).extendMethod('gray',vn),e.extendMethod('mask',Un),e.extendMethod('pad',On),e.extendMethod('colorDepth',Nn),e.extendMethod('setBorder',eo,t),e.extendMethod('rotate',Zn),e.extendMethod('rotateLeft',Kn),e.extendMethod('rotateRight',Jn),e.extendMethod('insert',$n),e.extendMethod('getRow',go),e.extendMethod('getColumn',mo),e.extendMethod('getMatrix',co),e.extendMethod('setMatrix',po),e.extendMethod('getPixelsArray',uo),e.extendMethod('getIntersection',fo),e.extendMethod('getClosestCommonParent',wo),e.extendMethod('getThreshold',Vn),e.extendMethod('split',to),e.extendMethod('getChannel',io),e.extendMethod('combineChannels',ao),e.extendMethod('setChannel',oo),e.extendMethod('getSimilarity',so),e.extendMethod('getPixelsGrid',ro),e.extendMethod('getBestMatch',ho),e.extendMethod('cannyEdge',vo),e.extendMethod('convolution',_a),e.extendMethod('extract',Do),e.extendMethod('floodFill',So),e.extendMethod('paintLabels',Go,t),e.extendMethod('paintMasks',Oo,t),e.extendMethod('paintPoints',Wo,t),e.extendMethod('paintPolyline',Zo,t),e.extendMethod('paintPolylines',Ko,t),e.extendMethod('paintPolygon',es,t),e.extendMethod('paintPolygons',ts,t),e.extendMethod('countAlphaPixels',fs),e.extendMethod('monotoneChainConvexHull',xs),e.extendMethod('minimalBoundingRectangle',Ds),e.extendMethod('getHistogram',is).extendProperty('histogram',is),e.extendMethod('getHistograms',as).extendProperty('histograms',as),e.extendMethod('getColorHistogram',os).extendProperty('colorHistogram',os),e.extendMethod('getMin',ss).extendProperty('min',ss),e.extendMethod('getMax',rs).extendProperty('max',rs),e.extendMethod('getSum',ls).extendProperty('sum',ls),e.extendMethod('getMoment',ds).extendProperty('moment',ds),e.extendMethod('getLocalMaxima',hs),e.extendMethod('getMedian',ms).extendProperty('median',ms),e.extendMethod('getMean',gs).extendProperty('mean',gs),e.extendMethod('getPoints',cs).extendProperty('points',cs),e.extendMethod('getRelativePosition',ps),e.extendMethod('getSvd',us).extendProperty('svd',us)}(tc);var ic=Object.freeze({laplacianOfGaussian:Hs,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:lh,SOBEL_Y:dh,SCHARR_X:hh,SCHARR_Y:gh,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]]}),ac=function(){function e(){this._listeners={}}self.window=self;e.prototype.on=function(e,t){if(this._listeners[e])throw new RangeError('there is already a listener for '+e);if('function'!=typeof t)throw new TypeError('callback argument must be a function');this._listeners[e]=t},e.prototype._send=function(e,t,i){i===void 0?i=[]:!Array.isArray(i)&&(i=[i]),self.postMessage({id:e,data:t},i)},e.prototype._trigger=function(e,t){if(!this._listeners[e])throw new Error('event '+e+' is not defined');this._listeners[e].apply(null,t)};var t=new e;self.onmessage=function(e){switch(e.data.action){case'exec':e.data.args.unshift(function(i,a){t._send(e.data.id,i,a)}),t._trigger(e.data.event,e.data.args);break;case'ping':t._send(e.data.id,'pong');break;default:throw new Error('unexpected action: '+e.data.action);}}}.toString().split('"CODE";'),nc={newWorkerURL:function(e,t){var i=new Blob(['(',ac[0],'importScripts.apply(self, '+JSON.stringify(t)+');\n','(',e,')();',ac[1],')();'],{type:'application/javascript'});return URL.createObjectURL(i)}},oc=navigator.hardwareConcurrency||1,sc=Function.prototype;qs.prototype._init=function(e){for(var t=nc.newWorkerURL(this._workerCode,e),a=0,n;a<this._numWorkers;a++)n=new Worker(t),n.onmessage=this._onmessage.bind(this,n),n.onerror=this._onerror.bind(this,n),n.running=!1,n.id=a,this._workers.set(n,null);URL.revokeObjectURL(t)},qs.prototype._onerror=function(e,t){if(!this._terminated){this._working--,e.running=!1;var i=this._workers.get(e);i&&i[1](t.message),this._workers.set(e,null),this._terminateOnError?this.terminate():this._exec()}},qs.prototype._onmessage=function(e,t){if(!this._terminated){this._working--,e.running=!1;var i=this._workers.get(e);i&&i[0](t.data.data),this._workers.set(e,null),this._exec()}},qs.prototype._exec=function(){for(var e of this._workers.keys()){if(this._working===this._numWorkers||0===this._waiting.length)return;if(!e.running)for(var t=0,a;t<this._waiting.length;t++)if(a=this._waiting[t],'number'!=typeof a[4]||a[4]===e.id){this._waiting.splice(t,1),e.postMessage({action:'exec',event:a[0],args:a[1]},a[2]),e.running=!0,e.time=Date.now(),this._workers.set(e,a[3]),this._working++;break}}},qs.prototype.terminate=function(){if(!this._terminated){for(var e of this._workers)e[0].terminate(),e[1]&&e[1][1](new Error('Terminated'));this._workers.clear(),this._waiting=[],this._working=0,this._terminated=!0}},qs.prototype.postAll=function(e,t){if(this._terminated)throw new Error('Cannot post (terminated)');var i=[];for(var a of this._workers.keys())i.push(this.post(e,t,[],a.id));return Promise.all(i)},qs.prototype.post=function(e,t,i,a){t===void 0&&(t=[]),i===void 0&&(i=[]),Array.isArray(t)||(t=[t]),Array.isArray(i)||(i=[i]);var n=this;return new Promise(function(o,s){if(n._terminated)throw new Error('Cannot post (terminated)');n._waiting.push([e,t,i,[o,s],a]),n._exec()})};var rc=qs,lc={regression:{kernelType:'polynomial',kernelOptions:{degree:2,constant:1}},threshold:.02,roi:{minSurface:100,positive:!1},sampling:20,include:[]},dc={run:function(e,t,i){t=Object.assign({},lc,t);var a=this.manager;return Array.isArray(e)?Promise.all(e.map(function(e){var n=Ws(a,e,t);return'function'==typeof i&&n.then(i),n})):Ws(a,e,t)},work:function(){worker.on('data',function(e,t,i){function a(e,t){i.include.includes(e)&&(n[e]=t,o.push(t.data.buffer))}t=new IJS(t);var n={},o=[],s=t.grey(),r=s.sobelFilter();a('sobel',r);var l=r.level().mask({threshold:i.threshold});a('mask',l);var d=r.getRoiManager();d.fromMask(l);var h=d.getMask(i.roi);a('realMask',h);var g=s.getPixelsGrid({sampling:i.sampling,mask:h}),m=t.getBackground(g.xyS,g.zS,i.regression);a('background',m);var c=t.subtract(m);n.result=c,o.push(c.data.buffer),e(n,o)})}};class hc{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(e){if('string'!=typeof e)throw new TypeError('worker URL must be a string');this._url=e,this._deps[0]=e}static extendMethod(e,t){function i(){a||(this.checkUrl(),n=this.url,a=new rc(t.work,{deps:n}),o.manager=a);for(var e=arguments.length,i=Array(e),s=0;s<e;s++)i[s]=arguments[s];return t.run.call(o,...i)}var a=void 0,n=void 0,o={};i.reset=function(){a&&(a.terminate(),a=new rc(t.work,{deps:n}),o.manager=a)},hc.prototype[e]=i}}(function(e){e.extendMethod('background',dc)})(hc);var gc=new hc;e.Kernel=ic,e.default=tc,e.Image=tc,e.Static={grey:bm,threshold:wm},e.Stack=ah,e.Shape=zm,e.Worker=gc,Object.defineProperty(e,'__esModule',{value:!0})});
  
  //# sourceMappingURL=image.min.js.map