if(!t)var t={map:function(t,n){var r={};return n?t.map(function(t,e){return r.index=e,n.call(r,t)}):t.slice()},naturalOrder:function(t,n){return tn?1:0},sum:function(t,n){var r={};return t.reduce(n?function(t,e,o){return r.index=o,t+n.call(r,e)}:function(t,n){return t+n},0)},max:function(n,r){return Math.max.apply(null,r?t.map(n,r):n)}};var n=function(){var n=5,r=8-n;function e(t,r,e){return(t<<2*n)+(r<h/2){for(o=r.copy(),a=r.copy(),i=(n=u-r[c])<=(e=r[f]-u)?Math.min(r[f]-1,~~(u+e/2)):Math.max(r[c],~~(u-1-n/2));!v[i];)i++;for(s=l[i];!s&&v[i-1];)s=l[--i];return o[f]=i,a[c]=o[f]+1,[o,a]}}(i==o?"r":i==a?"g":"b")}}return a.prototype={volume:function(t){var n=this;return n._volume&&!t||(n._volume=(n.r2-n.r1+1)*(n.g2-n.g1+1)*(n.b2-n.b1+1)),n._volume},count:function(t){var n=this,r=n.histo;if(!n._count_set||t){var o,a,i,u=0;for(o=n.r1;o<=n.r2;o++)for(a=n.g1;a<=n.g2;a++)for(i=n.b1;i<=n.b2;i++)u+=r[e(o,a,i)]||0;n._count=u,n._count_set=!0}return n._count},copy:function(){var t=this;return new a(t.r1,t.r2,t.g1,t.g2,t.b1,t.b2,t.histo)},avg:function(t){var r=this,o=r.histo;if(!r._avg||t){var a,i,u,c,f=0,s=1<<8-n,h=0,v=0,l=0;for(i=r.r1;i<=r.r2;i++)for(u=r.g1;u<=r.g2;u++)for(c=r.b1;c<=r.b2;c++)f+=a=o[e(i,u,c)]||0,h+=a*(i+.5)*s,v+=a*(u+.5)*s,l+=a*(c+.5)*s;r._avg=f?[~~(h/f),~~(v/f),~~(l/f)]:[~~(s*(r.r1+r.r2+1)/2),~~(s*(r.g1+r.g2+1)/2),~~(s*(r.b1+r.b2+1)/2)]}return r._avg},contains:function(t){var n=this,e=t[0]>>r;return gval=t[1]>>r,bval=t[2]>>r,e>=n.r1&&e<=n.r2&&gval>=n.g1&&gval<=n.g2&&bval>=n.b1&&bval<=n.b2}},i.prototype={push:function(t){this.vboxes.push({vbox:t,color:t.avg()})},palette:function(){return this.vboxes.map(function(t){return t.color})},size:function(){return this.vboxes.size()},map:function(t){for(var n=this.vboxes,r=0;r251&&o[1]>251&&o[2]>251&&(n[e].color=[255,255,255])}},{quantize:function(c,f){if(!c.length||f<2||f>256)return!1;var s=function(t){var o,a=new Array(1<<3*n);return t.forEach(function(t){o=e(t[0]>>r,t[1]>>r,t[2]>>r),a[o]=(a[o]||0)+1}),a}(c);s.forEach(function(){});var h=function(t,n){var e,o,i,u=1e6,c=0,f=1e6,s=0,h=1e6,v=0;return t.forEach(function(t){(e=t[0]>>r)c&&(c=e),(o=t[1]>>r)s&&(s=o),(i=t[2]>>r)v&&(v=i)}),new a(u,c,f,s,h,v,n)}(c,s),v=new o(function(n,r){return t.naturalOrder(n.count(),r.count())});function l(t,n){for(var r,e=t.size(),o=0;o<1e3;){if(e>=n)return;if(o++>1e3)return;if((r=t.pop()).count()){var a=u(s,r),i=a[0],c=a[1];if(!i)return;t.push(i),c&&(t.push(c),e++)}else t.push(r),o++}}v.push(h),l(v,.75*f);for(var g=new o(function(n,r){return t.naturalOrder(n.count()*n.volume(),r.count()*r.volume())});v.size();)g.push(v.pop());l(g,f);for(var m=new i;g.size();)m.push(g.pop());return m}}}().quantize,r=function(t){if(this.getImageData=function(){return this.context.getImageData(0,0,this.width,this.height)},t instanceof HTMLImageElement)this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.width=this.canvas.width=t.naturalWidth,this.height=this.canvas.height=t.naturalHeight,this.context.drawImage(t,0,0,this.width,this.height);else{if(!(t instanceof HTMLCanvasElement))throw new Error("One of the two constructor arguments needed");this.canvas=t,this.context=this.canvas.getContext("2d"),this.width=this.canvas.width,this.height=this.canvas.height}};module.exports=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.getColor=function(t,n){return void 0===n&&(n=10),this.getPalette(t,5,n)[0]},e.getPalette=function(t,e,o){void 0===o&&(o=10);var a=function(t){var n=t.colorCount,r=t.quality;if(void 0!==n&&Number.isInteger(n)){if(1===n)throw new Error("colorCount should be between 2 and 20. To get one color, call getColor() instead of getPalette()");n=Math.max(n,2),n=Math.min(n,20)}else n=10;return(void 0===r||!Number.isInteger(r)||r<1)&&(r=10),{colorCount:n,quality:r}}({colorCount:e,quality:o}),i=new r(t),u=function(t,n,r){for(var e=[],o=0;o=125)&&(i>250&&u>250&&c>250||e.push([i,u,c]))}return e}(i.getImageData().data,i.width*i.height,a.quality),c=n(u,a.colorCount);return c?c.palette():null},e.getColorFromUrl=function(t,n,r){var e=this;void 0===r&&(r=10);var o=document.createElement("img");o.addEventListener("load",function(){var a=e.getPalette(o,5,r);n(a[0],t)}),o.src=t},e.getImageData=function(t,n){fetch(t).then(function(t){200===t.status&&t.arrayBuffer().then(function(t){for(var r=new Uint8Array(t),e=new Array(r.length),o=0;o