if(!t)var t={map:function(t,n){var r={};return n?t.map(function(t,o){return r.index=o,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,o,e){return r.index=e,t+n.call(r,o)}: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,o=1e3;function e(t,r,o){return(t<<2*n)+(r<l/2){for(e=r.copy(),u=r.copy(),i=(n=a-r[c])<=(o=r[s]-a)?Math.min(r[s]-1,~~(a+o/2)):Math.max(r[c],~~(a-1-n/2));!h[i];)i++;for(f=v[i];!f&&h[i-1];)f=v[--i];return e[s]=i,u[c]=e[s]+1,[e,u]}}(i==o?"r":i==u?"g":"b")}}return i.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,u,i,a=0;for(o=n.r1;o<=n.r2;o++)for(u=n.g1;u<=n.g2;u++)for(i=n.b1;i<=n.b2;i++)a+=r[e(o,u,i)]||0;n._count=a,n._count_set=!0}return n._count},copy:function(){var t=this;return new i(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 u,i,a,c,s=0,f=1<<8-n,l=0,h=0,v=0;for(i=r.r1;i<=r.r2;i++)for(a=r.g1;a<=r.g2;a++)for(c=r.b1;c<=r.b2;c++)s+=u=o[e(i,a,c)]||0,l+=u*(i+.5)*f,h+=u*(a+.5)*f,v+=u*(c+.5)*f;r._avg=s?[~~(l/s),~~(h/s),~~(v/s)]:[~~(f*(r.r1+r.r2+1)/2),~~(f*(r.g1+r.g2+1)/2),~~(f*(r.b1+r.b2+1)/2)]}return r._avg},contains:function(t){var n=this,o=t[0]>>r;return gval=t[1]>>r,bval=t[2]>>r,o>=n.r1&&o<=n.r2&&gval>=n.g1&&gval<=n.g2&&bval>=n.b1&&bval<=n.b2}},a.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&&e[1]>251&&e[2]>251&&(n[o].color=[255,255,255])}},{quantize:function(s,f){if(!s.length||f<2||f>256)return!1;var l=function(t){var o,u=new Array(1<<3*n);return t.forEach(function(t){o=e(t[0]>>r,t[1]>>r,t[2]>>r),u[o]=(u[o]||0)+1}),u}(s);l.forEach(function(){});var h=function(t,n){var o,e,u,a=1e6,c=0,s=1e6,f=0,l=1e6,h=0;return t.forEach(function(t){(o=t[0]>>r)c&&(c=o),(e=t[1]>>r)f&&(f=e),(u=t[2]>>r)h&&(h=u)}),new i(a,c,s,f,l,h,n)}(s,l),v=new u(function(n,r){return t.naturalOrder(n.count(),r.count())});function g(t,n){for(var r,e=t.size(),u=0;u=n)return;if(u++>o)return;if((r=t.pop()).count()){var i=c(l,r),a=i[0],s=i[1];if(!a)return;t.push(a),s&&(t.push(s),e++)}else t.push(r),u++}}v.push(h),g(v,.75*f);for(var p=new u(function(n,r){return t.naturalOrder(n.count()*n.volume(),r.count()*r.volume())});v.size();)p.push(v.pop());g(p,f);for(var b=new a;p.size();)b.push(p.pop());return b}}}().quantize;const r=function(t){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)};r.prototype.getImageData=function(){return this.context.getImageData(0,0,this.width,this.height)};var o=function(){};o.prototype.getColor=function(t,n=10){return this.getPalette(t,5,n)[0]},o.prototype.getPalette=function(t,o,e){const u=function(t){let{colorCount:n,quality:r}=t;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:o,quality:e}),i=new r(t),a=function(t,n,r){const o=t,e=[];for(let t,u,i,a,c,s=0;s=125)&&(u>250&&i>250&&a>250||e.push([u,i,a]));return e}(i.getImageData().data,i.width*i.height,u.quality),c=n(a,u.colorCount);return c?c.palette():null},o.prototype.getColorFromUrl=function(t,n,r){const o=document.createElement("img");o.addEventListener("load",()=>{const e=this.getPalette(o,5,r);n(e[0],t)}),o.src=t},o.prototype.getImageData=function(t,n){let r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.onload=function(){if(200==this.status){let t=new Uint8Array(this.response);i=t.length;let r=new Array(i);for(let n=0;n