q-floodfill-hsl
Version:
Optimized, non-recursive flood fill using a scan line search
2 lines • 19.2 kB
JavaScript
(function t(e,r){if(typeof exports==="object"&&typeof module==="object")module.exports=r();else if(typeof define==="function"&&define.amd)define("q-floodfill",[],r);else if(typeof exports==="object")exports["q-floodfill"]=r();else e["q-floodfill"]=r()})(window,(function(){return function(t){var e={};function r(i){if(e[i]){return e[i].exports}var n=e[i]={i:i,l:false,exports:{}};t[i].call(n.exports,n,n.exports,r);n.l=true;return n.exports}r.m=t;r.c=e;r.d=function(t,e,i){if(!r.o(t,e)){Object.defineProperty(t,e,{enumerable:true,get:i})}};r.r=function(t){if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(t,"__esModule",{value:true})};r.t=function(t,e){if(e&1)t=r(t);if(e&8)return t;if(e&4&&typeof t==="object"&&t&&t.__esModule)return t;var i=Object.create(null);r.r(i);Object.defineProperty(i,"default",{enumerable:true,value:t});if(e&2&&typeof t!="string")for(var n in t)r.d(i,n,function(e){return t[e]}.bind(null,n));return i};r.n=function(t){var e=t&&t.__esModule?function e(){return t["default"]}:function e(){return t};r.d(e,"a",e);return e};r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};r.p="";return r(r.s=1)}([,function(t,e,r){"use strict";r.r(e);r.d(e,"isSameColor",(function(){return Dt}));r.d(e,"setColorAtPixel",(function(){return Ht}));r.d(e,"getColorAtPixel",(function(){return Rt}));r.d(e,"colorToRGBA",(function(){return $t}));r.d(e,"hex2RGBA",(function(){return At}));var i=function(t,e,r){t.prototype=e.prototype=r;r.constructor=t};function n(t,e){var r=Object.create(t.prototype);for(var i in e)r[i]=e[i];return r}function a(){}var o=.7;var h=1/o;var s="\\s*([+-]?\\d+)\\s*",l="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",u="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",c=/^#([0-9a-f]{3,8})$/,f=new RegExp("^rgb\\("+[s,s,s]+"\\)$"),d=new RegExp("^rgb\\("+[u,u,u]+"\\)$"),p=new RegExp("^rgba\\("+[s,s,s,l]+"\\)$"),g=new RegExp("^rgba\\("+[u,u,u,l]+"\\)$"),v=new RegExp("^hsl\\("+[l,u,u]+"\\)$"),b=new RegExp("^hsla\\("+[l,u,u,l]+"\\)$");var w={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};i(a,x,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:M,formatHex:M,formatHsl:y,formatRgb:m,toString:m});function M(){return this.rgb().formatHex()}function y(){return O(this).formatHsl()}function m(){return this.rgb().formatRgb()}function x(t){var e,r;t=(t+"").trim().toLowerCase();return(e=c.exec(t))?(r=e[1].length,e=parseInt(e[1],16),r===6?P(e):r===3?new q(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):r===8?N(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):r===4?N(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=f.exec(t))?new q(e[1],e[2],e[3],1):(e=d.exec(t))?new q(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=p.exec(t))?N(e[1],e[2],e[3],e[4]):(e=g.exec(t))?N(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=v.exec(t))?E(e[1],e[2]/100,e[3]/100,1):(e=b.exec(t))?E(e[1],e[2]/100,e[3]/100,e[4]):w.hasOwnProperty(t)?P(w[t]):t==="transparent"?new q(NaN,NaN,NaN,0):null}function P(t){return new q(t>>16&255,t>>8&255,t&255,1)}function N(t,e,r,i){if(i<=0)t=e=r=NaN;return new q(t,e,r,i)}function I(t){if(!(t instanceof a))t=x(t);if(!t)return new q;t=t.rgb();return new q(t.r,t.g,t.b,t.opacity)}function k(t,e,r,i){return arguments.length===1?I(t):new q(t,e,r,i==null?1:i)}function q(t,e,r,i){this.r=+t;this.g=+e;this.b=+r;this.opacity=+i}i(q,k,n(a,{brighter:function(t){t=t==null?h:Math.pow(h,t);return new q(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){t=t==null?o:Math.pow(o,t);return new q(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&(-.5<=this.g&&this.g<255.5)&&(-.5<=this.b&&this.b<255.5)&&(0<=this.opacity&&this.opacity<=1)},hex:_,formatHex:_,formatRgb:C,toString:C}));function _(){return"#"+S(this.r)+S(this.g)+S(this.b)}function C(){var t=this.opacity;t=isNaN(t)?1:Math.max(0,Math.min(1,t));return(t===1?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(t===1?")":", "+t+")")}function S(t){t=Math.max(0,Math.min(255,Math.round(t)||0));return(t<16?"0":"")+t.toString(16)}function E(t,e,r,i){if(i<=0)t=e=r=NaN;else if(r<=0||r>=1)t=e=NaN;else if(e<=0)t=NaN;return new T(t,e,r,i)}function O(t){if(t instanceof T)return new T(t.h,t.s,t.l,t.opacity);if(!(t instanceof a))t=x(t);if(!t)return new T;if(t instanceof T)return t;t=t.rgb();var e=t.r/255,r=t.g/255,i=t.b/255,n=Math.min(e,r,i),o=Math.max(e,r,i),h=NaN,s=o-n,l=(o+n)/2;if(s){if(e===o)h=(r-i)/s+(r<i)*6;else if(r===o)h=(i-e)/s+2;else h=(e-r)/s+4;s/=l<.5?o+n:2-o-n;h*=60}else{s=l>0&&l<1?0:h}return new T(h,s,l,t.opacity)}function j(t,e,r,i){return arguments.length===1?O(t):new T(t,e,r,i==null?1:i)}function T(t,e,r,i){this.h=+t;this.s=+e;this.l=+r;this.opacity=+i}i(T,j,n(a,{brighter:function(t){t=t==null?h:Math.pow(h,t);return new T(this.h,this.s,this.l*t,this.opacity)},darker:function(t){t=t==null?o:Math.pow(o,t);return new T(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+(this.h<0)*360,e=isNaN(t)||isNaN(this.s)?0:this.s,r=this.l,i=r+(r<.5?r:1-r)*e,n=2*r-i;return new q(Q(t>=240?t-240:t+120,n,i),Q(t,n,i),Q(t<120?t+240:t-120,n,i),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&(0<=this.l&&this.l<=1)&&(0<=this.opacity&&this.opacity<=1)},formatHsl:function(){var t=this.opacity;t=isNaN(t)?1:Math.max(0,Math.min(1,t));return(t===1?"hsl(":"hsla(")+(this.h||0)+", "+(this.s||0)*100+"%, "+(this.l||0)*100+"%"+(t===1?")":", "+t+")")}}));function Q(t,e,r){return(t<60?e+(r-e)*t/60:t<180?r:t<240?e+(r-e)*(240-t)/60:e)*255}var R=Math.PI/180;var H=180/Math.PI;var D=18,A=.96422,$=1,F=.82521,V=4/29,L=6/29,X=3*L*L,B=L*L*L;function G(t){if(t instanceof J)return new J(t.l,t.a,t.b,t.opacity);if(t instanceof it)return nt(t);if(!(t instanceof q))t=I(t);var e=Z(t.r),r=Z(t.g),i=Z(t.b),n=K((.2225045*e+.7168786*r+.0606169*i)/$),a,o;if(e===r&&r===i)a=o=n;else{a=K((.4360747*e+.3850649*r+.1430804*i)/A);o=K((.0139322*e+.0971045*r+.7141733*i)/F)}return new J(116*n-16,500*(a-n),200*(n-o),t.opacity)}function z(t,e){return new J(t,0,0,e==null?1:e)}function U(t,e,r,i){return arguments.length===1?G(t):new J(t,e,r,i==null?1:i)}function J(t,e,r,i){this.l=+t;this.a=+e;this.b=+r;this.opacity=+i}i(J,U,n(a,{brighter:function(t){return new J(this.l+D*(t==null?1:t),this.a,this.b,this.opacity)},darker:function(t){return new J(this.l-D*(t==null?1:t),this.a,this.b,this.opacity)},rgb:function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,r=isNaN(this.b)?t:t-this.b/200;e=A*W(e);t=$*W(t);r=F*W(r);return new q(Y(3.1338561*e-1.6168667*t-.4906146*r),Y(-.9787684*e+1.9161415*t+.033454*r),Y(.0719453*e-.2289914*t+1.4052427*r),this.opacity)}}));function K(t){return t>B?Math.pow(t,1/3):t/X+V}function W(t){return t>L?t*t*t:X*(t-V)}function Y(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function Z(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function tt(t){if(t instanceof it)return new it(t.h,t.c,t.l,t.opacity);if(!(t instanceof J))t=G(t);if(t.a===0&&t.b===0)return new it(NaN,0<t.l&&t.l<100?0:NaN,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*H;return new it(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function et(t,e,r,i){return arguments.length===1?tt(t):new it(r,e,t,i==null?1:i)}function rt(t,e,r,i){return arguments.length===1?tt(t):new it(t,e,r,i==null?1:i)}function it(t,e,r,i){this.h=+t;this.c=+e;this.l=+r;this.opacity=+i}function nt(t){if(isNaN(t.h))return new J(t.l,0,0,t.opacity);var e=t.h*R;return new J(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}i(it,rt,n(a,{brighter:function(t){return new it(this.h,this.c,this.l+D*(t==null?1:t),this.opacity)},darker:function(t){return new it(this.h,this.c,this.l-D*(t==null?1:t),this.opacity)},rgb:function(){return nt(this).rgb()}}));var at=-.14861,ot=+1.78277,ht=-.29227,st=-.90649,lt=+1.97294,ut=lt*st,ct=lt*ot,ft=ot*ht-st*at;function dt(t){if(t instanceof gt)return new gt(t.h,t.s,t.l,t.opacity);if(!(t instanceof q))t=I(t);var e=t.r/255,r=t.g/255,i=t.b/255,n=(ft*i+ut*e-ct*r)/(ft+ut-ct),a=i-n,o=(lt*(r-n)-ht*a)/st,h=Math.sqrt(o*o+a*a)/(lt*n*(1-n)),s=h?Math.atan2(o,a)*H-120:NaN;return new gt(s<0?s+360:s,h,n,t.opacity)}function pt(t,e,r,i){return arguments.length===1?dt(t):new gt(t,e,r,i==null?1:i)}function gt(t,e,r,i){this.h=+t;this.s=+e;this.l=+r;this.opacity=+i}i(gt,pt,n(a,{brighter:function(t){t=t==null?h:Math.pow(h,t);return new gt(this.h,this.s,this.l*t,this.opacity)},darker:function(t){t=t==null?o:Math.pow(o,t);return new gt(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=isNaN(this.h)?0:(this.h+120)*R,e=+this.l,r=isNaN(this.s)?0:this.s*e*(1-e),i=Math.cos(t),n=Math.sin(t);return new q(255*(e+r*(at*i+ot*n)),255*(e+r*(ht*i+st*n)),255*(e+r*(lt*i)),this.opacity)}}));function vt(t,e,r,i,n,a){return Math.sqrt(Math.pow(t-i,2)+Math.pow(e-n,2)+Math.pow(r-a,2))}function bt(t,e){t=k(t);e=k(e);return vt(t.r,t.g,t.b,e.r,e.g,e.b)}function wt(t,e){t=U(t);e=U(e);return vt(t.l,t.a,t.b,e.l,e.a,e.b)}function Mt(t,e){t=rt(t);e=rt(e);return vt(t.h,t.c,t.l,e.h,e.c,e.l)}function yt(t,e){t=j(t);e=j(e);return vt(t.h,t.s,t.l,e.h,e.s,e.l)}function mt(t,e){t=pt(t);e=pt(e);return vt(t.h,t.s,t.l,e.h,e.s,e.l)}function xt(t,e,r){t=t!==undefined?t:1;e=e!==undefined?e:.045;r=r!==undefined?r:.015;return function(i,n){var a=U(i);var o=U(n);var h=a.l;var s=a.a;var l=a.b;var u=Math.sqrt(s*s+l*l);var c=o.l;var f=o.a;var d=o.b;var p=Math.sqrt(f*f+d*d);var g=Math.pow(h-c,2);var v=Math.pow(u-p,2);var b=Math.pow(s-f,2)+Math.pow(l-d,2)-v;return Math.sqrt(g/Math.pow(t,2)+v/Math.pow(1+e*u,2)+b/Math.pow(1+r*u,2))}}var Pt=xt();function Nt(t,e,r){t=t!==undefined?t:1;e=e!==undefined?e:1;r=r!==undefined?r:1;return function(i,n){var a=U(i);var o=U(n);var h=a.l;var s=a.a;var l=a.b;var u=Math.sqrt(s*s+l*l);var c=o.l;var f=o.a;var d=o.b;var p=Math.sqrt(f*f+d*d);var g=(u+p)/2;var v=.5*(1-Math.sqrt(Math.pow(g,7)/(Math.pow(g,7)+Math.pow(25,7))));var b=s*(1+v);var w=f*(1+v);var M=Math.sqrt(b*b+l*l);var y=Math.sqrt(w*w+d*d);var m=Math.abs(b)+Math.abs(l)===0?0:Math.atan2(l,b);m+=(m<0)*2*Math.PI;var x=Math.abs(w)+Math.abs(d)===0?0:Math.atan2(d,w);x+=(x<0)*2*Math.PI;var P=c-h;var N=y-M;var I=M*y===0?0:x-m;I-=(I>Math.PI)*2*Math.PI;I+=(I<-Math.PI)*2*Math.PI;var k=2*Math.sqrt(M*y)*Math.sin(I/2);var q=(h+c)/2;var _=(M+y)/2;var C;if(M*y===0){C=m+x}else{C=(m+x)/2;C-=(Math.abs(m-x)>Math.PI)*Math.PI;C+=(C<0)*2*Math.PI}var S=Math.pow(q-50,2);var E=1-.17*Math.cos(C-Math.PI/6)+.24*Math.cos(2*C)+.32*Math.cos(3*C+Math.PI/30)-.2*Math.cos(4*C-63*Math.PI/180);var O=1+.015*S/Math.sqrt(20+S);var j=1+.045*_;var T=1+.015*_*E;var Q=30*Math.PI/180*Math.exp(-1*Math.pow((180/Math.PI*C-275)/25,2));var R=2*Math.sqrt(Math.pow(_,7)/(Math.pow(_,7)+Math.pow(25,7)));var H=-1*Math.sin(2*Q)*R;return Math.sqrt(Math.pow(P/(t*O),2)+Math.pow(N/(e*j),2)+Math.pow(k/(r*T),2)+H*N/(e*j)*k/(r*T))}}var It=Nt();function kt(t,e){t=t!==undefined?t:1;e=e!==undefined?e:1;return function(r,i){var n=U(r);var a=U(i);var o=n.l;var h=n.a;var s=n.b;var l=Math.sqrt(h*h+s*s);var u=Math.atan2(s,h);u=u+2*Math.PI*(u<0);var c=a.l;var f=a.a;var d=a.b;var p=Math.sqrt(f*f+d*d);var g=Math.pow(o-c,2);var v=Math.pow(l-p,2);var b=Math.pow(h-f,2)+Math.pow(s-d,2)-v;var w=Math.sqrt(Math.pow(l,4)/(Math.pow(l,4)+1900));var M=u>=164/180*Math.PI&&u<=345/180*Math.PI?.56+Math.abs(.2*Math.cos(u+168/180*Math.PI)):.36+Math.abs(.4*Math.cos(u+35/180*Math.PI));var y=o<16?.511:.040975*o/(1+.01765*o);var m=.0638*l/(1+.0131*l)+.638;var x=m*(w*M+1-w);return Math.sqrt(g/Math.pow(t*y,2),v/Math.pow(e*m,2),b/Math.pow(x,2))}}var qt=kt();var _t=26/180*Math.PI;var Ct=Math.cos(_t);var St=Math.sin(_t);var Et=100/Math.log(139/100);function Ot(t,e,r){var i=Et/r*Math.log(1+.0039*t.l);if(t.a===0&&t.b===0){return U(i,0,0)}var n=t.a*Ct+t.b*St;var a=.83*(t.b*Ct-t.a*St);var o=Math.sqrt(n*n+a*a);var h=Math.log(1+.075*o)/(.0435*e*r);var s=(Math.atan2(a,n)+_t)/Math.PI*180;return U(i,h*Math.cos(s/180*Math.PI),h*Math.sin(s/180*Math.PI))}function jt(t,e){t=t!==undefined?t:1;e=e!==undefined?e:1;return function(r,i){r=Ot(U(r),t,e);i=Ot(U(i),t,e);return vt(r.l,r.a,r.b,i.l,i.a,i.b)}}var Tt=jt();function Qt(t){var e=t.r,r=t.g,i=t.b;e=e.toString(16);r=r.toString(16);i=i.toString(16);if(e.length==1)e="0"+e;if(r.length==1)r="0"+r;if(i.length==1)i="0"+i;return"#"+e+r+i}function Rt(t,e,r){var i=t.width,n=t.data;var a=4*(r*i+e);if(n[a+3]===undefined){throw new Error("Invalid pixel coordinates: x="+e+"; y="+r)}return{r:n[a],g:n[a+1],b:n[a+2],a:n[a+3]}}function Ht(t,e,r,i){var n=t.width,a=t.data;var o=4*(i*n+r);if(a[o+3]===undefined){throw new Error("Invalid pixel coordinates. Cannot set color at: x="+r+"; y="+i)}a[o+0]=e.r&255;a[o+1]=e.g&255;a[o+2]=e.b&255;a[o+3]=e.a&255}function Dt(t,e,r){if(r===void 0){r=0}return wt(Qt(t),Qt(e))<r}function At(t,e){if(e===void 0){e=255}var r=t;if(t.indexOf("#")===0){r=t.slice(1)}if(r.length===3){r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]}if(r.length!==6){throw new Error("Invalid HEX color "+r+".")}var i=parseInt(r.slice(0,2),16);var n=parseInt(r.slice(2,4),16);var a=parseInt(r.slice(4,6),16);return{r:i,g:n,b:a,a:e}}function $t(t){if(t.indexOf("rgba")!==-1){var e=/rgba\(.*?([0-9]{1,3}).*?([0-9]{1,3}).*?([0-9]{1,3}).*?([0-9\.]{1,})/g.exec(t),r=e[0],i=e[1],n=e[2],a=e[3],o=e[4];return{r:parseInt(i),g:parseInt(n),b:parseInt(a),a:Math.ceil(parseFloat(o)*255)}}else if(t.indexOf("rgb")!==-1){var h=/rgb\(.*?([0-9]{1,3}).*?([0-9]{1,3}).*?([0-9]{1,3})/g.exec(t),r=h[0],i=h[1],n=h[2],a=h[3];return{r:parseInt(i),g:parseInt(n),b:parseInt(a),a:255}}else if(t.indexOf("#")!==-1){return At(t)}else{throw new Error("Unsupported color format. Please use CSS rgba, rgb, or HEX!")}}function Ft(t,e){if(e===void 0){e=2}var r=new Array(e).join("0");return(r+t).slice(-e)}function Vt(t){if(t.indexOf("#")===0){t=t.slice(1)}if(t.length===3){t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]}if(t.length!==6){throw new Error("Invalid HEX color.")}var e=(255-parseInt(t.slice(0,2),16)).toString(16),r=(255-parseInt(t.slice(2,4),16)).toString(16),i=(255-parseInt(t.slice(4,6),16)).toString(16);return"#"+Ft(e)+Ft(r)+Ft(i)}function Lt(t,e){return t.r===e.r&&t.g===e.g&&t.b===e.b&&t.a===e.a}var Xt=function(){function t(t){this.collectModifiedPixels=false;this.modifiedPixelsCount=0;this.modifiedPixels=new Set;this._tolerance=0;this._queue=[];this.imageData=t}t.prototype.fill=function(t,e,r,i){this._newColor=$t(t);this._replacedColor=Rt(this.imageData,e,r);this._tolerance=i;if(Dt(this._replacedColor,this._newColor,this._tolerance)){if(Lt(this._replacedColor,this._newColor)){return}this._newColor=$t(Vt(t));this.addToQueue([e,e,r,-1]);this.fillQueue();this._newColor=$t(t);this._replacedColor=Rt(this.imageData,e,r)}this.addToQueue([e,e,r,-1]);this.fillQueue()};t.prototype.addToQueue=function(t){this._queue.push(t)};t.prototype.popFromQueue=function(){if(!this._queue.length){return null}return this._queue.pop()};t.prototype.isValidTarget=function(t){if(t===null){return}var e=Rt(this.imageData,t.x,t.y);return Dt(this._replacedColor,e,this._tolerance)};t.prototype.fillLineAt=function(t,e){if(!this.isValidTarget({x:t,y:e})){return[-1,-1]}this.setPixelColor(this._newColor,{x:t,y:e});var r=t;var i=t;var n=this.getPixelNeighbour("left",r,e);while(n&&this.isValidTarget(n)){this.setPixelColor(this._newColor,n);r=n.x;n=this.getPixelNeighbour("left",r,e)}n=this.getPixelNeighbour("right",i,e);while(n&&this.isValidTarget(n)){this.setPixelColor(this._newColor,n);i=n.x;n=this.getPixelNeighbour("right",i,e)}return[r,i]};t.prototype.fillQueue=function(){var t=this.popFromQueue();while(t){var e=t[0],r=t[1],i=t[2],n=t[3];var a=e;while(a!==-1&&a<=r){var o=this.fillLineAt(a,i),h=o[0],s=o[1];if(h!==-1){if(h>=e&&s<=r&&n!==-1){if(n<i&&i+1<this.imageData.height){this.addToQueue([h,s,i+1,i])}if(n>i&&i>0){this.addToQueue([h,s,i-1,i])}}else{if(i>0){this.addToQueue([h,s,i-1,i])}if(i+1<this.imageData.height){this.addToQueue([h,s,i+1,i])}}}if(s===-1&&a<=r){a+=1}else{a=s+1}}t=this.popFromQueue()}};t.prototype.setPixelColor=function(t,e){Ht(this.imageData,t,e.x,e.y);this.modifiedPixelsCount++;this.collectModifiedPixels&&this.modifiedPixels.add(e.x+"|"+e.y)};t.prototype.getPixelNeighbour=function(t,e,r){e=e|0;r=r|0;var i;switch(t){case"right":i={x:e+1|0,y:r};break;case"left":i={x:e-1|0,y:r};break}if(i.x>=0&&i.x<this.imageData.width){return i}return null};return t}();var Bt=Xt;var Gt=e["default"]=Bt}])}));
//# sourceMappingURL=index.bundle.js.map