e.exports=function(){"use strict";functione(e,t){for(varn=0;n<t.length;n++){varr=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"inr&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}functiont(e,t){returnfunction(e){if(Array.isArray(e))returne}(e)||function(e,t){varn=[],r=!0,o=!1,a=void0;try{for(varl,c=e[Symbol.iterator]();!(r=(l=c.next()).done)&&(n.push(l.value),!t||n.length!==t);r=!0);}catch(e){o=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(o)throwa}}returnn}(e,t)||function(){thrownewTypeError("Invalid attempt to destructure non-iterable instance")}()}returnfunction(){functionn(){!function(e,t){if(!(einstanceoft))thrownewTypeError("Cannot call a class as a function")}(this,n)}varr,o,a;returnr=n,(o=[{key:"getColorAsync",value:function(e,t,n){e.complete?t.call(e,this.getColor(e,n),n&&n.data):this._bindImageEvents(e,t,n)}},{key:"getColor",value:function(e,t){t=t||{};varn=this._getDefaultColor(t),r=this._getOriginalSize(e),o=this._prepareSizeAndPosition(r,t),a=null,l=n;if(!(o.srcWidth&&o.srcHeight&&o.destWidth&&o.destHeight))returnthis._prepareResult(n,newError("FastAverageColor: Incorrect sizes."));if(!this._ctx&&(this._canvas=this._makeCanvas(),this._ctx=this._canvas.getContext&&this._canvas.getContext("2d"),!this._ctx))returnthis._prepareResult(n,newError("FastAverageColor: Canvas Context 2D is not supported in this browser."));this._canvas.width=o.destWidth,this._canvas.height=o.destHeight;try{this._ctx.clearRect(0,0,o.destWidth,o.destHeight),this._ctx.drawImage(e,o.srcLeft,o.srcTop,o.srcWidth,o.srcHeight,0,0,o.destWidth,o.destHeight);varc=this._ctx.getImageData(0,0,o.destWidth,o.destHeight).data;l=this.getColorFromArray4(c,t)}catch(e){a=e}returnthis._prepareResult(l,a)}},{key:"getColorFromArray4",value:function(e,t){t=t||{};varn=e.length;if(n<4)returnthis._getDefaultColor(t);varr=n-n%4,o=4*(t.step||1),a="_"+(t.algorithm||"sqrt")+"Algorithm";if("function"!=typeofthis[a])thrownewError("FastAverageColor: ".concat(t.algorithm," is unknown algorithm."));returnthis[a](e,r,o)}},{key:"destroy",value:function(){deletethis._canvas,deletethis._ctx}},{key:"_getDefaultColor",value:function(e){returnthis._getOption(e,"defaultColor",[255,255,255,255])}},{key:"_getOption",value:function(e,t,n){returnvoid0===e[t]?n:e[t]}},{key:"_prepareSizeAndPosition",value:function(e,t){varn,r=this._getOption(t,"left",0),o=this._getOption(t,"top",0),a=this._getOption(t,"width",e.width),l=this._getOption(t,"height",e.height),c=a,i=l;return"precision"===t.mode||(a>l?(n=a/l,c=100,i=Math.round(c/n)):(n=l/a,i=100,c=Math.round(i/n)),(c>a||i>l||c<10||i<10)&&(c=a,i=l)),{srcLeft:r,srcTop:o,srcWidth:a,srcHeight:l,destWidth:c,destHeight:i}}},{key:"_simpleAlgorithm",value:function(e,t,n){for(varr=0,o=0,a=0,l=0,c=0,i=0;i<t;i+=n){vars=e[i+3];r+=e[i]*s,o+=e[i+1]*s,a+=e[i+2]*s,l+=s,c++}returnl?[Math.round(r/l),Math.round(o/l),Math.round(a/l),Math.round(l/c)]:[0,0,0,0]}},{key:"_sqrtAlgorithm",value:function(e,t,n){for(varr=0,o=0,a=0,l=0,c=0,i=0;i<t;i+=n){vars=e[i],u=e[i+1],m=e[i+2],d=e[i+3];r+=s*s*d,o+=u*u*d,a+=m*m*d,l+=d,c++}returnl?[Math.round(Math.sqrt(r/l)),Math.round(Math.sqrt(o/l)),Math.round(Math.sqrt(a/l)),Math.round(l/c)]:[0,0,0,0]}},{key:"_dominantAlgorithm",value:function(e,n,r){for(varo={},a=0;a<n;a+=r){varl=e[a],c=e[a+1],i=e[a+2],s=e[a+3],u=Math.round(l/24)+","+Math.round(c/24)+","+Math.round(i/24);o[u]?o[u]=[o[u][0]+l*s,o[u][1]+c*s,o[u][2]+i*s,o[u][3]+s,o[u][4]+1]:o[u]=[l*s,c*s,i*s,s,1]}varm=t(Object.keys(o).map((function(e){returno[e]})).sort((function(e,t){varn=e[4],r=t[4];returnn>r?-1:n===r?0:1}))[0],5),d=m[0],b=m[1],p=m[2],g=m[3],h=m[4];returng?[Math.round(d/g),Math.round(b/g),Math.round(p/g),Math.round(g/h)]:[0,0,0,0]}},{key:"_bindImageEvents",value:function(e,t,n){varr=this,o=(n=n||{})&&n.data,a=this._getDefaultColor(n),l=function(){s(),t.call(e,r.getColor(e,n),o)},c=function(){s(),t.call(e,r._prepareResult(a,newError("Image error")),o)},i=function(){s(),t.call(e,r._prepareResult(a,newError("Image abort")),o)},s=function(){e.removeEventListener("load",l),e.remo