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