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