import {m as m$1,q}from'../chunk-YQKSXMBN.mjs';import'../chunk-WGY6QKPW.mjs';import'../chunk-GLKEY6D3.mjs';import {b,h,i,f,g,l,d,a,c,k}from'../chunk-IOXRZECH.mjs';var w=c$1=>({l:a(c$1.l,0,100),c:Math.max(0,c$1.c),h:c(c$1.h),alpha:a(c$1.alpha,0,1),colorSpace:"lch"}),$=c=>{let o=m$1(c),l=Math.sqrt(o.a**2+o.b**2),r=Math.atan2(o.b,o.a)/Math.PI*180;return {l:o.l,c:l,h:l<.0015?0:r<0?r+360:r,alpha:o.alpha,colorSpace:"lch"}};var x=({l:c,c:o,h:l,alpha:r})=>q({l:c,a:o*Math.cos(l*Math.PI/180),b:o*Math.sin(l*Math.PI/180),alpha:r,colorSpace:"lab"}),m=c=>{if(!h(c)||c.colorSpace!=="lch"||!i(c,["l","c","h"]))return null;let{l:o,c:l,h:r,alpha:t=1}=c;return !f(o)||!f(l)||!f(r)||!f(t)?null:x(w({l:g(o),c:g(l),h:g(r),alpha:g(t)}))},y=new RegExp(`^lch\\(\\s*(?<l>${k})(?<lp>%?)\\s+(?<c>${k})(?<cp>%?)\\s+(?<h>${k})(?<hu>deg|rad|grad|turn)?\\s*(?:/\\s*(?<al>${k})(?<alp>%?)\\s*)?\\)$`,"i"),L=c=>{if(typeof c!="string")return null;let o=y.exec(c.trim())?.groups;if(!o)return null;let l$1=l(o.l),r=o.cp?l(o.c)*1.5:l(o.c),t=o.hu?.toLowerCase()??"deg",n=l(o.h)*(d[t]??1),h=o.al===void 0?1:l(o.al)/(o.alp?100:1);return x(w({l: l$1,c:r,h:n,alpha:h}))};var T=(c,o,l)=>{c.prototype.toLch=function(r=2){let{l:t,c:n,h,alpha:i}=$(this._rawRgb()),b$1=b(n,r);return {l:b(t,r),c:b$1,h:n<.0015?0:b(h,r),alpha:i,colorSpace:"lch"}},c.prototype.toLchString=function(r=2){let{l:t,c:n,h,alpha:i}=this.toLch(r),b=n===0?"none":h;return i<1?`lch(${t} ${n} ${b} / ${i})`:`lch(${t} ${n} ${b})`},o.push(m,L),l.push([m,"lch"],[L,"lch"]);},_=T;export{_ as default};//# sourceMappingURL=lch.mjs.map
//# sourceMappingURL=lch.mjs.map