text: !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):t.ColorThief=r()}(this,function(){var t=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)};t.prototype.getPixelCount=function(){return this.width*this.height},t.prototype.getImageData=function(){return this.context.getImageData(0,0,this.width,this.height)};var r=function(){};if(r.prototype.getColor=function(t,r){return this.getPalette(t,5,r)[0]},r.prototype.getPalette=function(r,n,o){(void 0===n||n<2||n>256)&&(n=10),(void 0===o||o<1)&&(o=10);for(var i,u,s,a,h=new t(r),c=h.getImageData().data,f=h.getPixelCount(),v=[],p=0;p<f;p+=o)u=c[0+(i=4*p)],s=c[i+1],a=c[i+2],c[i+3]>=125&&(u>250&&s>250&&a>250||v.push([u,s,a]));var g=e.quantize(v,n);return g?g.palette():null},r.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},r.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<t.length;e++)n[e]=String.fromCharCode(t[e]);var o=n.join(""),i=window.btoa(o);r("data:image/png;base64,"+i)}},n.send()},r.prototype.getColorAsync=function(t,r,n){var e=this;this.getImageData(t,function(t){var o=document.createElement("img");o.addEventListener("load",function(){var t=e.getPalette(o,5,n);r(t[0],this)}),o.src=t})},!n)var n={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 t<r?-1:t>r?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(t,r){return Math.max.apply(null,r?n.map(t,r):t)}};var e=function(){var t=5,r=8-t,e=1e3;function o(r,n,e){return(r<<2*t)+(n<<t)+e}function i(t){var r=[],n=!1;function e(){r.sort(t),n=!0}return{push:function(t){r.push(t),n=!1},peek:function(t){return n||e(),void 0===t&&(t=r.length-1),r[t]},pop:function(){return n||e(),r.pop()},size:function(){return r.length},map:function(t){return r.map(t)},debug:function(){return n||e(),r}}}function u(t,r,n,e,o,i,u){this.r1=t,this.r2=r,this.g1=n,this.g2=e,this.b1=o,this.b2=i,this.histo=u}function s(){this.vboxes=new i(function(t,r){return n.naturalOrder(t.vbox.count()*t.vbox.volume(),r.vbox.count()*r.vbox.volume())})}function a(t,r){if(r.count()){var e=r.r2-r.r1+1,i=r.g2-r.g1+1,u=n.max([e,i,r.b2-r.b1+1]);if(1==r.count())return[r.copy()];var s,a,h,c,f=0,v=[],p=[];if(u==e)for(s=r.r1;s<=r.r2;s++){for(c=0,a=r.g1;a<=r.g2;a++)for(h=r.b1;h<=r.b2;h++)c+=t[o(s,a,h)]||0;v[s]=f+=c}else if(u==i)for(s=r.g1;s<=r.g2;s++){for(c=0,a=r.r1;a<=r.r2;a++)for(h=r.b1;h<=r.b2;h++)c+=t[o(a,s,h)]||0;v[s]=f+=c}else for(s=r.b1;s<=r.b2;s++){for(c=0,a=r.r1;a<=r.r2;a++)for(h=r.g1;h<=r.g2;h++)c+=t[o(a,h,s)]||0;v[s]=f+=c}return v.forEach(function(t,r){p[r]=f-t}),function(t){var n,e,o,i,u,a=t+"1",h=t+"2",c=0;for(s=r[a];s<=r[h];s++)if(v[s]>f/2){for(o=r.copy(),i=r.copy(),u=(n=s-r[a])<=(e=r[h]-s)?Math.min(r[h]-1,~~(s+e/2)):Math.max(r[a],~~(s-1-n/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(r){var n=this.histo;if(!this._avg||r){var e,i,u,s,a=0,h=1<<8-t,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 n=t[0]>>r,e=t[1]>>r,o=t[2]>>r;return n>=this.r1&&n<=this.r2&&e>=this.g1&&e<=this.g2&&o>=this.b1&&o<=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;n<r.size();n++)if(r.peek(n).vbox.contains(t))return r.peek(n).color;return this.nearest(t)},nearest:function(t){for(var r,n,e,o=this.vboxes,i=0;i<o.size();i++)((n=Math.sqrt(Math.pow(t[0]-o.peek(i).color[0],2)+Math.pow(t[1]-o.peek(i).color[1],2)+Math.pow(t[2]-o.peek(i).color[2],2)))<r||void 0===r)&&(r=n,e=o.peek(i).color);return e},forcebw:function(){var t=this.vboxes;t.sort(function(t,r){return n.naturalOrder(n.sum(t.color),n.sum(r.color))});var r=t[0].color;r[0]<5&&r[1]<5&&r[2]<5&&(t[0].color=[0,0,0]);var e=t.length-1,o=t[e].color;o[0]>251&&o[1]>251&&o[2]>251&&(t[e].color=[255,255,255])}},{quantize:function(h,c){if(!h.length||c<2||c>256)return!1;var f=function(n){var e,i=new Array(1<<3*t);return n.forEach(function(t){e=o(t[0]>>r,t[1]>>r,t[2]>>r),i[e]=(i[e]||0)+1}),i}(h);f.forEach(function(){});var v=function(t,n){var e,o,i,s=1e6,a=0,h=1e6,c=0,f=1e6,v=0;return t.forEach(function(t){(e=t[0]>>r)<s?s=e:e>a&&(a=e),(o=t[1]>>r)<h?h=o:o>c&&(c=o),(i=t[2]>>r)<f?f=i:i>v&&(v=i)}),new u(s,a,h,c,f,v,n)}(h,f),p=new i(function(t,r){return n.naturalOrder(t.count(),r.count())});function g(t,r){for(var n,o=1,i=0;i<e;)if((n=t.pop()).count()){var u=a(f,n),s=u[0],h=u[1];if(!s)return;if(t.push(s),h&&(t.push(h),o++),o>=r)return;if(i++>e)return}else t.push(n),i++}p.push(v),g(p,.75*c);for(var l=new i(function(t,r){return n.naturalOrder(t.count()*t.volume(),r.count()*r.volume())});p.size();)l.push(p.pop());g(l,c-l.size());for(var d=new s;l.size();)d.push(l.pop());return d}}}();return r});
  //# sourceMappingURL=color-thief.umd.js.map
  