class t{constructor(s){const r=t.parseColor(s);this._r=r.r,this._g=r.g,this._b=r.b,this._a=r.a}static clamp(t,s,r){return Math.min(Math.max(t,s),r)}static parseColor(s){if("object"==typeof s&&"r"in s&&"g"in s&&"b"in s)return{r:Math.round(t.clamp(s.r,0,255)),g:Math.round(t.clamp(s.g,0,255)),b:Math.round(t.clamp(s.b,0,255)),a:void 0!==s.a?t.clamp(s.a,0,1):1};if("string"!=typeof s)return{r:0,g:0,b:0,a:1};const r=s.trim().toLowerCase();return r.startsWith("#")?t.parseHex(r):r.startsWith("rgb")?t.parseRgbString(r):{r:0,g:0,b:0,a:1}}static parseHex(t){let s=t.slice(1);3===s.length&&(s=s.split("").map((t=>t+t)).join("")),4===s.length&&(s=s.split("").map((t=>t+t)).join(""));const r=parseInt(s.slice(0,2),16),e=parseInt(s.slice(2,4),16),i=parseInt(s.slice(4,6),16);let a=1;return 8===s.length&&(a=parseInt(s.slice(6,8),16)/255),{r:Number.isNaN(r)?0:r,g:Number.isNaN(e)?0:e,b:Number.isNaN(i)?0:i,a:Number.isNaN(a)?1:a}}static parseRgbString(s){const r=s.match(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+\.?\d*))?\s*\)/);return r?{r:t.clamp(parseInt(r[1],10),0,255),g:t.clamp(parseInt(r[2],10),0,255),b:t.clamp(parseInt(r[3],10),0,255),a:void 0!==r[4]?t.clamp(parseFloat(r[4]),0,1):1}:{r:0,g:0,b:0,a:1}}static rgbToHsl(t,s,r){t/=255,s/=255,r/=255;const e=Math.max(t,s,r),i=Math.min(t,s,r),a=(e+i)/2;let n=0,h=0;if(e!==i){const c=e-i;switch(h=a>.5?c/(2-e-i):c/(e+i),e){case t:n=((s-r)/c+(s<r?6:0))/6;break;case s:n=((r-t)/c+2)/6;break;case r:n=((t-s)/c+4)/6}}return{h:360*n,s:h,l:a}}static hslToRgb(t,s,r){let e,i,a;if(t/=360,0===s)e=i=a=r;else{const n=(t,s,r)=>(r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*(s-t)*r:r<.5?s:r<2/3?t+(s-t)*(2/3-r)*6:t),h=r<.5?r*(1+s):r+s-r*s,c=2*r-h;e=n(c,h,t+1/3),i=n(c,h,t),a=n(c,h,t-1/3)}return{r:Math.round(255*e),g:Math.round(255*i),b:Math.round(255*a)}}static getBrightness(t,s,r){return(299*t+587*s+114*r)/1e3}isDark(){return t.getBrightness(this._r,this._g,this._b)<128}isLight(){return!this.isDark()}clone(){return new t({r:this._r,g:this._g,b:this._b,a:this._a})}lighten(s=10){const r=t.rgbToHsl(this._r,this._g,this._b);r.l=t.clamp(r.l+s/100,0,1);const e=t.hslToRgb(r.h,r.s,r.l);return this._r=e.r,this._g=e.g,this._b=e.b,this}darken(t=10){return this.lighten(-t)}setAlpha(s){return this._a=t.clamp(s,0,1),this}toRgb(){return{r:this._r,g:this._g,b:this._b,a:this._a}}}function s(s){return new t(s)}export{t as T,s as t}