if(!t)var t={map:function(t,r){var n={};return r?t.map(function(t,e){return n.index=e,r.call(n,t)}):t.slice()},naturalOrder:function(t,r){return tr?1:0},sum:function(t,r){var n={};return t.reduce(r?function(t,e,o){return n.index=o,t+r.call(n,e)}:function(t,r){return t+r},0)},max:function(r,n){return Math.max.apply(null,n?t.map(r,n):r)}};var r=function(){var r=5,n=8-r;function e(t,n,e){return(t<<2*r)+(n<h/2){for(o=n.copy(),a=n.copy(),u=(r=i-n[c])<=(e=n[s]-i)?Math.min(n[s]-1,~~(i+e/2)):Math.max(n[c],~~(i-1-r/2));!l[u];)u++;for(f=g[u];!f&&l[u-1];)f=g[--u];return o[s]=u,a[c]=o[s]+1,[o,a]}}(u==o?"r":u==a?"g":"b")}}return a.prototype={volume:function(t){var r=this;return r._volume&&!t||(r._volume=(r.r2-r.r1+1)*(r.g2-r.g1+1)*(r.b2-r.b1+1)),r._volume},count:function(t){var r=this,n=r.histo;if(!r._count_set||t){var o,a,u,i=0;for(o=r.r1;o<=r.r2;o++)for(a=r.g1;a<=r.g2;a++)for(u=r.b1;u<=r.b2;u++)i+=n[e(o,a,u)]||0;r._count=i,r._count_set=!0}return r._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 n=this,o=n.histo;if(!n._avg||t){var a,u,i,c,s=0,f=1<<8-r,h=0,l=0,g=0;for(u=n.r1;u<=n.r2;u++)for(i=n.g1;i<=n.g2;i++)for(c=n.b1;c<=n.b2;c++)s+=a=o[e(u,i,c)]||0,h+=a*(u+.5)*f,l+=a*(i+.5)*f,g+=a*(c+.5)*f;n._avg=s?[~~(h/s),~~(l/s),~~(g/s)]:[~~(f*(n.r1+n.r2+1)/2),~~(f*(n.g1+n.g2+1)/2),~~(f*(n.b1+n.b2+1)/2)]}return n._avg},contains:function(t){var r=this,e=t[0]>>n;return gval=t[1]>>n,bval=t[2]>>n,e>=r.r1&&e<=r.r2&&gval>=r.g1&&gval<=r.g2&&bval>=r.b1&&bval<=r.b2}},u.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 r=this.vboxes,n=0;n251&&o[1]>251&&o[2]>251&&(r[e].color=[255,255,255])}},{quantize:function(c,s){if(!c.length||s<2||s>256)return!1;var f=function(t){var o,a=new Array(1<<3*r);return t.forEach(function(t){o=e(t[0]>>n,t[1]>>n,t[2]>>n),a[o]=(a[o]||0)+1}),a}(c);f.forEach(function(){});var h=function(t,r){var e,o,u,i=1e6,c=0,s=1e6,f=0,h=1e6,l=0;return t.forEach(function(t){(e=t[0]>>n)c&&(c=e),(o=t[1]>>n)f&&(f=o),(u=t[2]>>n)l&&(l=u)}),new a(i,c,s,f,h,l,r)}(c,f),l=new o(function(r,n){return t.naturalOrder(r.count(),n.count())});function g(t,r){for(var n,e=t.size(),o=0;o<1e3;){if(e>=r)return;if(o++>1e3)return;if((n=t.pop()).count()){var a=i(f,n),u=a[0],c=a[1];if(!u)return;t.push(u),c&&(t.push(c),e++)}else t.push(n),o++}}l.push(h),g(l,.75*s);for(var v=new o(function(r,n){return t.naturalOrder(r.count()*r.volume(),n.count()*n.volume())});l.size();)v.push(l.pop());g(v,s);for(var m=new u;v.size();)m.push(v.pop());return m}}}().quantize;class n{constructor(t){this.getImageData=function(){return this.context.getImageData(0,0,this.width,this.height)},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)}}class e{constructor(){this.getColorAsync=(t,r,n)=>{const e=this;this.getImageDataFromURL(t).then(t=>{const o=document.createElement("img");o.addEventListener("load",()=>{const t=e.getPalette(o,5,n);r(t[0],o)}),o.src=t})},this.getColorPromise=(t,r)=>new Promise((n,e)=>{const o=this;this.getImageDataFromURL(t).then(t=>{const e=document.createElement("img");e.addEventListener("load",()=>{const t=o.getPalette(e,5,r);n({color:t[0],img:e})}),e.src=t}).catch(t=>{e(t)})})}getColor(t,r=10){return this.getPalette(t,5,r)[0]}getPalette(t,e,o=10){const a=(t=>{let r=t.colorCount,n=t.quality;if(void 0!==r&&Number.isInteger(r)){if(1===r)throw new Error("colorCount should be between 2 and 20. To get one color, call getColor() instead of getPalette()");r=Math.max(r,2),r=Math.min(r,20)}else r=10;return(void 0===n||!Number.isInteger(n)||n<1)&&(n=10),{colorCount:r,quality:n}})({colorCount:e,quality:o}),u=new n(t),i=((t,r,n)=>{const e=[];for(let o=0;o=125)&&(n>250&&a>250&&u>250||e.push([n,a,u]))}return e})(u.getImageData().data,u.width*u.height,a.quality),c=r(i,a.colorCount);return c?c.palette():null}getColorFromUrl(t,r,n=10){const e=document.createElement("img");e.addEventListener("load",()=>{const o=this.getPalette(e,5,n);r(o[0],t)}),e.src=t}getImageData(t,r){fetch(t).then(t=>{200===t.status&&t.arrayBuffer().then(t=>{const n=new Uint8Array(t),e=new Array(n.length);for(let t=0;t{fetch(t).then(t=>{200===t.status?t.arrayBuffer().then(t=>{const n=new Uint8Array(t),e=new Array(n.length);for(let t=0;t