text: function clamp(r,t){return Math.min(Math.max(r,0),t)}function toHex(r){return"#"+r.map(function(r){return r=clamp(Math.round(r),255),(r<16?"0":"")+r.toString(16)}).join("")}var Node=require("./node"),colors=require("../data/colors"),Color=function(r,t,o){Array.isArray(r)?this.rgb=r:6==r.length?this.rgb=r.match(/.{2}/g).map(function(r){return parseInt(r,16)}):this.rgb=r.split("").map(function(r){return parseInt(r+r,16)}),this.alpha="number"==typeof t?t:1,void 0!==o&&(this.value=o)};Color.prototype=new Node,Color.prototype.type="Color",Color.prototype.luma=function(){var r=this.rgb[0]/255,t=this.rgb[1]/255,o=this.rgb[2]/255;return r=r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4),t=t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4),o=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4),.2126*r+.7152*t+.0722*o},Color.prototype.genCSS=function(r,t){t.add(this.toCSS(r))},Color.prototype.toCSS=function(r,t){var o,a,e=r&&r.compress&&!t;if(this.value)return this.value;if((a=this.fround(r,this.alpha))<1)return"rgba("+this.rgb.map(function(r){return clamp(Math.round(r),255)}).concat(clamp(a,1)).join(","+(e?"":" "))+")";if(o=this.toRGB(),e){var n=o.split("");n[1]===n[2]&&n[3]===n[4]&&n[5]===n[6]&&(o="#"+n[1]+n[3]+n[5])}return o},Color.prototype.operate=function(r,t,o){for(var a=[],e=this.alpha*(1-o.alpha)+o.alpha,n=0;n<3;n++)a[n]=this._operate(r,t,this.rgb[n],o.rgb[n]);return new Color(a,e)},Color.prototype.toRGB=function(){return toHex(this.rgb)},Color.prototype.toHSL=function(){var r,t,o=this.rgb[0]/255,a=this.rgb[1]/255,e=this.rgb[2]/255,n=this.alpha,i=Math.max(o,a,e),h=Math.min(o,a,e),s=(i+h)/2,p=i-h;if(i===h)r=t=0;else{switch(t=s>.5?p/(2-i-h):p/(i+h),i){case o:r=(a-e)/p+(a<e?6:0);break;case a:r=(e-o)/p+2;break;case e:r=(o-a)/p+4}r/=6}return{h:360*r,s:t,l:s,a:n}},Color.prototype.toHSV=function(){var r,t,o=this.rgb[0]/255,a=this.rgb[1]/255,e=this.rgb[2]/255,n=this.alpha,i=Math.max(o,a,e),h=Math.min(o,a,e),s=i,p=i-h;if(t=0===i?0:p/i,i===h)r=0;else{switch(i){case o:r=(a-e)/p+(a<e?6:0);break;case a:r=(e-o)/p+2;break;case e:r=(o-a)/p+4}r/=6}return{h:360*r,s:t,v:s,a:n}},Color.prototype.toARGB=function(){return toHex([255*this.alpha].concat(this.rgb))},Color.prototype.compare=function(r){return r.rgb&&r.rgb[0]===this.rgb[0]&&r.rgb[1]===this.rgb[1]&&r.rgb[2]===this.rgb[2]&&r.alpha===this.alpha?0:void 0},Color.fromKeyword=function(r){var t,o=r.toLowerCase();if(colors.hasOwnProperty(o)?t=new Color(colors[o].slice(1)):"transparent"===o&&(t=new Color([0,0,0],0)),t)return t.value=r,t},module.exports=Color;
  