saturon 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -7
- package/README.md +121 -119
- package/dist/Color.d.ts +20 -11
- package/dist/Color.js +127 -97
- package/dist/converters.d.ts +4 -4
- package/dist/converters.js +14 -20
- package/dist/index.umd.js +163 -149
- package/dist/index.umd.min.js +1 -1
- package/dist/math.d.ts +1 -0
- package/dist/math.js +11 -10
- package/dist/temp.d.ts +1 -0
- package/dist/temp.js +3 -0
- package/dist/types.d.ts +4 -4
- package/dist/utils.js +26 -30
- package/package.json +127 -127
package/dist/index.umd.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Saturon=(()=>{var Ce=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var Qe=(e,t)=>{for(var r in t)Ce(e,r,{get:t[r],enumerable:!0})},et=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of We(t))!Je.call(e,o)&&o!==r&&Ce(e,o,{get:()=>t[o],enumerable:!(n=Ue(t,o))||n.enumerable});return e};var tt=e=>et(Ce({},"__esModule",{value:!0}),e);var rt={};Qe(rt,{Color:()=>P});var Oe={AccentColor:[[0,120,215],[10,132,255]],AccentColorText:[[255,255,255],[255,255,255]],ActiveText:[[255,0,0],[255,100,100]],ButtonBorder:[[169,169,169],[90,90,90]],ButtonFace:[[240,240,240],[60,60,60]],ButtonText:[[0,0,0],[255,255,255]],Canvas:[[255,255,255],[30,30,30]],CanvasText:[[0,0,0],[255,255,255]],Field:[[255,255,255],[45,45,45]],FieldText:[[0,0,0],[255,255,255]],GrayText:[[128,128,128],[169,169,169]],Highlight:[[0,120,215],[80,80,80]],HighlightText:[[255,255,255],[0,0,0]],LinkText:[[0,0,255],[0,128,255]],Mark:[[255,255,0],[255,200,0]],MarkText:[[0,0,0],[0,0,0]],SelectedItem:[[0,120,215],[0,120,215]],SelectedItemText:[[255,255,255],[255,255,255]],VisitedText:[[128,0,128],[200,120,255]]},ee={theme:"light",systemColors:Oe,defaults:{fit:"clip"}};var me=new Map;function ce(e,t){let r=Array.isArray(e[0])?e.length:1,n=Array.isArray(e[0])?e:[e],o=Array.isArray(t[0])?t:t.map(i=>[i]),a=o[0].length,s=o[0].map((i,d)=>o.map(u=>u[d])),c=n.map(i=>s.map(d=>i.reduce((u,f,h)=>u+f*(d[h]||0),0)));return r===1?c[0]:a===1?c.map(i=>i[0]):c}function xe(e){return e.trim().replace(/\s+/g," ").replace(/\( /g,"(").replace(/ \)/g,")").replace(/\s*,\s*/g,", ").replace(/ ,/g,",").replace(/calc\(NaN\)/g,"0").replace(/[A-Z]/g,t=>String.fromCharCode(t.charCodeAt(0)+32))}function oe(e,t){let r=t,n="",o=0;if(e[r]!=="(")for(;r<e.length&&/[a-zA-Z0-9-%#]/.test(e[r]);)n+=e[r],r++;if(e[r]==="("){for(n+="(",r++,o=1;r<e.length&&o>0;){let a=e[r];a==="("?o++:a===")"&&o--,o>0&&(n+=a),r++}n+=")"}return{expression:n,end:r}}function le(e,t,r={}){let{method:n=ee.defaults.fit,precision:o}=r,{components:a}=Z[t],s=Object.values(a).reduce((i,d)=>(i[d.index]=d,i),[]),c;if(n==="none")c=e;else if(n==="clip")c=e.slice(0,3).map((i,d)=>{let u=s[d];if(!u)throw new Error(`Missing component properties for index ${d}.`);if(u.value==="angle")return(i%360+360)%360;let[f,h]=Array.isArray(u.value)?u.value:[0,100];return Math.min(h,Math.max(f,i))});else{let i=Ae[n];if(!i)throw new Error(`Invalid gamut clipping method: must be ${Object.keys(Ae).join(", ")} or "none".`);c=i(e,t)}return c.slice(0,3).map((i,d)=>{let u;if(typeof o=="number"||o===null)u=o;else if(typeof o>"u")u=s[d]?.precision??3;else throw new TypeError(`Invalid precision value: ${o}.`);return u===null?i:Number(i.toFixed(u))})}function je(e,t){let r=(l,v,p={},G=!1,N=!1)=>{let y=(B,x,U)=>{let ne=parseFloat(B);if(isNaN(ne))throw new Error(`Invalid percentage value: '${B}'.`);return v==="percentage"?ne:x<0&&U>0?ne/100*(U-x)/2:ne/100*(U-x)+x},D=B=>{let x=parseFloat(B);if(isNaN(x))throw new Error(`Invalid angle value: '${B}'.`);return B.slice(-3)==="deg"?x:B.slice(-3)==="rad"?x*(180/m):B.slice(-4)==="grad"?x*.9:B.slice(-4)==="turn"?x*360:x},k=(B,x,U)=>{let ne=M=>{let R=[];for(let g=0;g<M.length;){let T=M[g];if(/\s/.test(T)){g++;continue}if(M.slice(g,g+2)==="**"){R.push({type:"operator",value:"**"}),g+=2;continue}if(/[0-9]/.test(T)||T==="."&&/[0-9]/.test(M[g+1]||"")){let se="";for(;g<M.length&&/[0-9.]/.test(M[g]);)se+=M[g++];if(g<M.length&&/[eE]/.test(M[g]))for(se+=M[g++],/[+-]/.test(M[g])&&(se+=M[g++]);g<M.length&&/[0-9]/.test(M[g]);)se+=M[g++];R.push({type:"number",value:parseFloat(se)});continue}if(/[a-zA-Z_]/.test(T)){let se="";for(;g<M.length&&/[a-zA-Z0-9_]/.test(M[g]);)se+=M[g++];R.push({type:"identifier",value:se});continue}if("+-*/%(),".includes(T)){R.push({type:"operator",value:T}),g++;continue}throw new Error(`Unexpected character: ${T}`)}return R},J=M=>{let R=0,g=()=>R<M.length?M[R]:null,T=()=>{if(R>=M.length)throw new Error("Unexpected end of input");return M[R++]},se=Y=>{let re=g();if(!re||re.value!==Y)throw new Error(`Expected "${Y}" but got "${re?re.value:"end of input"}`);T()},Ve=()=>{let Y=g();if(!Y)throw new Error("Unexpected end of input");if(Y.type==="number")return T(),{type:"number",value:Y.value};if(Y.type==="identifier"){if(T(),g()&&g().value==="("){T();let re=[];if(g()&&g().value!==")")for(re.push(be());g()&&g().value===",";)T(),re.push(be());return se(")"),{type:"call",func:Y.value,args:re}}return{type:"var",name:Y.value}}if(Y.value==="("){T();let re=be();return se(")"),re}throw new Error(`Unexpected token: ${Y.value}`)},Be=()=>g()&&(g().value==="+"||g().value==="-")?{type:"unary",op:T().value,arg:Be()}:Ve(),Le=()=>{let Y=Be();for(;g()&&g().value==="**";)Y={type:"binary",op:T().value,left:Y,right:Be()};return Y},Se=()=>{let Y=Le();for(;g()&&["*","/","%"].includes(String(g().value));)Y={type:"binary",op:T().value,left:Y,right:Le()};return Y},be=()=>{let Y=Se();for(;g()&&(g().value==="+"||g().value==="-");)Y={type:"binary",op:T().value,left:Y,right:Se()};return Y},Ke=be();if(R<M.length)throw new Error(`Extra tokens after expression: ${M.slice(R).map(Y=>Y.value).join(" ")}`);return Ke},Q=(M,R)=>{switch(M.type){case"number":return M.value;case"var":{let g=R[M.name];if(g===void 0)throw new Error(`Unknown variable: ${M.name}`);if(typeof g=="function")throw new Error(`Expected variable but found function: ${M.name}`);return g}case"binary":{let g=Q(M.left,R),T=Q(M.right,R);switch(M.op){case"+":return g+T;case"-":return g-T;case"*":return g*T;case"/":return g/T;case"%":return g%T;case"**":return g**T;default:throw new Error(`Unknown binary operator: ${M.op}`)}}case"unary":{let g=Q(M.arg,R);switch(M.op){case"+":return+g;case"-":return-g;default:throw new Error(`Unknown unary operator: ${M.op}`)}}case"call":{let g=R[M.func];if(typeof g!="function")throw new Error(`Unknown function: ${M.func}`);return g(...M.args.map(T=>Q(T,R)))}default:throw new Error(`Unknown AST node type: ${M.type}`)}},F=B.slice(5,-1).trim();if(F==="infinity")return U;if(F==="-infinity")return x;if(F==="NaN")return 0;F=F.replace(/(\d+(\.\d+)?)%/g,M=>{if(N===!0)throw new Error("<angle> and <percentage> values are converted to <number> in relative syntax.");let R=y(M,x,U);return R!==void 0?String(R):"0"}),F=F.replace(/(\d+(\.\d+)?)(deg|rad|grad|turn)/g,(M,R,g,T)=>{if(N===!0)throw new Error("<angle> and <percentage> values are converted to <number> in relative syntax.");return String(D(`${parseFloat(R)}${T}`))});let Ee={...p,pi:m,e:w,tau:m*2,pow:$,sqrt:L,sin:q,cos:C,tan:b,asin:E,acos:S,atan:_,atan2:W,exp:O,log:A,log10:z,log2:j,abs:I,min:V,max:he,hypot:fe,round:ge,ceil:de,floor:ie,sign:ye,trunc:ve,random:we};try{let M=ne(F),R=J(M);return Q(R,Ee)}catch(M){throw new Error(`Evaluation error: ${M}`)}},X=()=>{if(/^-?(?:\d+|\d*\.\d+)(?:deg|rad|grad|turn)$/.test(l))return D(l);if(/^-?(?:\d+|\d*\.\d+)$/.test(l))return parseFloat(l);let[B,x]=[0,360];if(l[l.length-1]==="%"){if(G&&h===!0)throw new Error("The legacy color syntax does not allow percentages for <angle> components.");if(N===!0)throw new Error("The relative color syntax doesn't allow percentages for <angle> components.");return y(l,B,x)}if(l.slice(0,5)==="calc(")return k(l,B,x);throw new Error(`Invalid angle value: '${l}'. Must be a number, a number with a unit (deg, rad, grad, turn), or a percentage.`)},te=()=>{if(/^-?(?:\d+|\d*\.\d+)$/.test(l)){if(G&&h===!0)throw new Error("The legacy color syntax does not allow numbers for <percentage> components.");return parseFloat(l)}let[B,x]=[0,100];if(l[l.length-1]==="%")return y(l,B,x);if(l.slice(0,5)==="calc(")return k(l,B,x);throw new Error(`Invalid percentage value: '${l}'. Must be a percentage or a number.`)},K=()=>{if(/^-?(?:\d+|\d*\.\d+)$/.test(l))return parseFloat(l);let[B,x]=v;if(l[l.length-1]==="%")return y(l,B,x);if(l.slice(0,5)==="calc(")return k(l,B,x);throw new Error(`Invalid number value: '${l}'. Must be a number${N===!1?" or a percentage":""}.`)};if(l==="none")return 0;if(l in p)return p[l];if(v==="angle")return X();if(v==="percentage")return te();if(Array.isArray(v))return K();throw new Error(`Unable to parse component token: ${l}`)},n=l=>{let{fn:v,space:p,fromOrigin:G,c1:N,c2:y,c3:D,alpha:k,commaSeparated:X}=l,{components:te,supportsLegacy:K}=t;if(te.alpha={index:3,value:[0,1],precision:3},X&&K!==!0)throw new Error(`<${v}()> does not support comma-separated syntax.`);let B=Object.entries(te).sort((x,U)=>x[1].index-U[1].index);if(G){let x;if(v==="color")x=p;else if(v in Z)x=v;else for(let J in Z)if(Z[J].alphaVariant===v){x=J;break}let U=P.from(G).in(x).toObject({fit:"none",precision:null});return[N,y,D,k].map((J,Q)=>{let[,F]=B[Q];return r(J,F.value,U,X,!0)}).slice(0,4)}else{let x=[],U=[],ne=[N,y,D,k];for(let J=0;J<B.length;J++){let[,Q]=B[J],F=ne[J];if(X&&F==="none")throw new Error(`${v}() cannot use "none" in comma-separated syntax.`);if(Q.index!==3&&Q.value!=="angle"&&Q.value!=="percentage"&&F.slice(0,5)!=="calc("&&U.push(F.trim()[F.length-1]==="%"),F){let Ee=r(F,Q.value,{},X);x[Q.index]=Ee}}if(X&&U.length>1){let J=U.every(Boolean),Q=U.every(F=>!F);if(!J&&!Q)throw new Error(`${v}()'s <number> components must all be numbers or all percentages.`)}return x.slice(0,4)}},o=l=>{let v=(B,x="/")=>{if(l[B]!==void 0){if(l[B]===x)return{value:l[B+1],hasAlpha:!0};throw new Error("Invalid alpha separator")}return{value:"1",hasAlpha:!1}},p,G,N,y,D,k,X,te=!1,K;if(l[0]==="color")if(p="color",l[1]==="from"){G=l[3],N=l[2],y=l[4],D=l[5],k=l[6];let{value:B,hasAlpha:x}=v(7);K=x?9:7,X=B}else{G=l[1],N=null,y=l[2],D=l[3],k=l[4];let{value:B,hasAlpha:x}=v(5);K=x?7:5,X=B}else if(p=l[0],G=null,l[1]==="from"){N=l[2],y=l[3],D=l[4],k=l[5];let{value:B,hasAlpha:x}=v(6);K=x?8:6,X=B}else if(N=null,y=l[1],l[2]===","&&l[4]===","){te=!0,D=l[3],k=l[5];let{value:B,hasAlpha:x}=v(6,",");if(K=x?8:6,x&&l[6]!==",")throw new Error("Comma optional syntax requires no commas at all.");X=B}else{D=l[2],k=l[3];let{value:B,hasAlpha:x}=v(4);K=x?6:4,X=B}if(l.length!==K)throw new Error(`Invalid number of tokens for ${p}(): expected ${K} but got ${l.length}.`);return{fn:p,space:G,fromOrigin:N,c1:y,c2:D,c3:k,alpha:X,commaSeparated:te}},a=l=>{let v=[],p=0,G="";for(;p<l.length&&l[p]!=="(";)G+=l[p],p++;G=G.trim(),v.push(G);let N=l.indexOf("(")+1,y=l.slice(N,-1).trim();if(p=0,y.slice(0,5)==="from "){for(v.push("from"),p+=5;p<y.length&&y[p]===" ";)p++;let D=p;for(;p<y.length&&y[p]!==" ";)p++;let k=y.slice(D,p);if(k.includes("(")){let{expression:X,end:te}=oe(y,D);v.push(X),p=te}else v.push(k);for(;p<y.length&&y[p]===" ";)p++}if(v[0]==="color"&&p<y.length){let D=p;for(;p<y.length&&y[p]!==" ";)p++;for(v.push(y.slice(D,p));p<y.length&&y[p]===" ";)p++}for(;p<y.length;){let D=y[p];if(D===",")v.push(","),p++,y[p]===" "&&p++;else if(D==="/")v.push("/"),p++,y[p]===" "&&p++;else if(D===" ")p++;else if(/[a-zA-Z#]/.test(D)){let k=p,X="";for(;p<y.length&&/[a-zA-Z0-9-%#]/.test(y[p]);)X+=y[p],p++;if(p<y.length&&y[p]==="("){let{expression:te,end:K}=oe(y,k);v.push(te),p=K}else v.push(X)}else if(/[\d.-]/.test(D)){let k="";for(;p<y.length&&/[\d.eE+-]/.test(y[p]);)k+=y[p],p++;if(p<y.length&&y[p]==="%")k+="%",p++,v.push(k);else if(p<y.length&&/[a-zA-Z]/.test(y[p])){let X="";for(;p<y.length&&/[a-zA-Z]/.test(y[p]);)X+=y[p],p++;v.push(k+X)}else v.push(k)}else throw new Error(`Unexpected character: ${D}`)}return v},s=(l,v)=>{let p="color(from ";if(l.slice(0,11)!==p||l[l.length-1]!==")")return!1;let G=l.slice(p.length,-1).trim(),{expression:N,end:y}=oe(G,0);if(!N)return!1;let k=G.slice(y).trim().split(/\s+/);return k.length<1?!1:k[0]===v},{components:c,bridge:i,fromBridge:d,toBridge:u,alphaVariant:f,supportsLegacy:h}=t,{PI:m,E:w,pow:$,sqrt:L,sin:q,cos:C,tan:b,asin:E,acos:S,atan:_,atan2:W,exp:O,log:A,log10:z,log2:j,abs:I,min:V,max:he,hypot:fe,round:ge,ceil:de,floor:ie,sign:ye,trunc:ve,random:we}=Math;return{isValid:l=>{let{alphaVariant:v=e}=t;if(e in pe){let p=l.slice(0,`color(${e} `.length)===`color(${e} `,G=l.slice(0,10)==="color(from"&&s(l,e);return(p||G)&&l[l.length-1]===")"}return(l.slice(0,`${e}(`.length)===`${e}(`||l.slice(0,`${v}(`.length)===`${v}(`)&&l[l.length-1]===")"},bridge:i,toBridge:l=>[...u(l.slice(0,3)),l[3]??1],parse:l=>{let v=a(l),p=o(v),G=n(p);return[...G.slice(0,3),G[3]??1]},fromBridge:l=>[...d(l),l[3]??1],format:([l,v,p,G=1],N={})=>{let{legacy:y=!1,fit:D=ee.defaults.fit,precision:k,units:X=!1}=N,te=le([l,v,p],e,{method:D,precision:k}),K=Number(V(he(G,0),1).toFixed(3)).toString(),B=te.map((x,U)=>{if((X||y)&&c){let ne=Object.values(c).find(J=>J.index===U);if(ne?.value==="percentage")return`${x}%`;if(ne?.value==="angle"&&X)return`${x}deg`}return x.toString()});return e in pe?`color(${e} ${B.join(" ")}${G!==1?` / ${K}`:""})`:y&&h?G===1?`${e}(${B.join(", ")})`:`${f||e}(${B.join(", ")}, ${K})`:`${e}(${B.join(" ")}${G!==1?` / ${K}`:""})`}}}function ae(e,t){let{fromLinear:r=s=>s,toLinear:n=s=>s,toBridgeMatrix:o,fromBridgeMatrix:a}=t;return{supportsLegacy:!1,targetGamut:t.targetGamut===null?null:e,components:Object.fromEntries(t.components.map((s,c)=>[s,{index:c,value:[0,1],precision:5}])),bridge:t.bridge,toBridge:s=>ce(o,s.map(c=>n(c))),fromBridge:s=>ce(a,s).map(c=>r(c))}}var H={D50_to_D65:[[.955473421488075,-.02309845494876471,.06325924320057072],[-.0283697093338637,1.0099953980813041,.021041441191917323],[.012314014864481998,-.020507649298898964,1.330365926242124]],D65_to_d50:[[1.0479297925449969,.022946870601609652,-.05019226628920524],[.02962780877005599,.9904344267538799,-.017073799063418826],[-.009243040646204504,.015055191490298152,.7518742814281371]],SRGB_to_XYZD65:[[506752/1228815,87881/245763,12673/70218],[87098/409605,175762/245763,12673/175545],[7918/409605,87881/737289,1001167/1053270]],XYZD65_to_SRGB:[[12831/3959,-329/214,-1974/3959],[-851781/878810,1648619/878810,36519/878810],[705/12673,-2585/12673,705/667]],P3_to_XYZD65:[[608311/1250200,189793/714400,198249/1000160],[35783/156275,247089/357200,198249/2500400],[0/1,32229/714400,5220557/5000800]],XYZD65_to_P3:[[446124/178915,-333277/357830,-72051/178915],[-14852/17905,63121/35810,423/17905],[11844/330415,-50337/660830,316169/330415]],REC2020_to_XYZD65:[[63426534/99577255,20160776/139408157,47086771/278816314],[26158966/99577255,472592308/697040785,8267143/139408157],[0/1,19567812/697040785,295819943/278816314]],XYZD65_to_REC2020:[[30757411/17917100,-6372589/17917100,-4539589/17917100],[-19765991/29648200,47925759/29648200,467509/29648200],[792561/44930125,-1921689/44930125,42328811/44930125]],A98_to_XYZD65:[[573536/994567,263643/1420810,187206/994567],[591459/1989134,6239551/9945670,374412/4972835],[53769/1989134,351524/4972835,4929758/4972835]],ProPhoto_to_XYZD50:[[.7977666449006423,.13518129740053308,.0313477341283922],[.2880748288194013,.711835234241873,8993693872564e-17],[0,0,.8251046025104602]],XYZD50_to_ProPhoto:[[1.3457868816471583,-.25557208737979464,-.05110186497554526],[-.5446307051249019,1.5082477428451468,.02052744743642139],[0,0,1.2119675456389452]],XYZD65_to_A98:[[1829569/896150,-506331/896150,-308931/896150],[-851781/878810,1648619/878810,36519/878810],[16779/1248040,-147721/1248040,1266979/1248040]],LMS_to_XYZD65:[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],XYZD65_to_LMS:[[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],LMS_to_OKLAB:[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],OKLAB_to_LMS:[[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]]},ke={linear:e=>e,"ease-in":e=>e*e,"ease-out":e=>e*(2-e),"ease-in-out":e=>e<.5?2*e*e:-1+(4-2*e)*e,"ease-in-cubic":e=>e*e*e,"ease-out-cubic":e=>--e*e*e+1,"ease-in-out-cubic":e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2},Ae={"chroma-reduction":(e,t)=>{let r=new P(t,e),{targetGamut:n}=Z[t];if(n===null||(n===void 0&&(n="srgb"),r.inGamut(n,1e-5)))return e;let[o,,a]=r.in("oklch").toArray({fit:"none",precision:null}),s=Math.min(1,Math.max(0,o)),c=0,i=1,d=1e-6,u=[];for(;i-c>d;){let h=(c+i)/2,m=new P("oklch",[s,h,a]);if(m.inGamut(n,1e-5))c=h;else{let w=le(m.toArray({fit:"none",precision:null}).slice(0,3),t,{method:"clip"}),$=new P(t,w);if(m.deltaEOK($)<2)return u=w,u;i=h}}return u=new P("oklch",[s,c,a]).in(t).toArray({fit:"none",precision:null}),u},"css-gamut-map":(e,t)=>{let{targetGamut:r}=Z[t];if(r===null)return e;r===void 0&&(r="srgb");let n=new P(t,e),[o,a,s]=n.in("oklch").toArray({fit:"none",precision:null});if(o>=1)return new P("oklab",[1,0,0]).in(t).toArray({fit:"none",precision:null});if(o<=0)return new P("oklab",[0,0,0]).in(t).toArray({fit:"none",precision:null});if(n.inGamut(r,1e-5))return e;let c=.02,i=1e-4,d=new P("oklch",[o,a,s]),u=le(d.in(t).toArray({fit:"none",precision:null}).slice(0,3),t,{method:"clip"}),f=new P(t,u);if(d.deltaEOK(f)<c)return u;let m=0,w=a,$=!0;for(;w-m>i;){let L=(m+w)/2,q=new P("oklch",[o,L,s]);if($&&q.inGamut(r,1e-5))m=L;else{let C=le(q.in(t).toArray({fit:"none",precision:null}).slice(0,3),t,{method:"clip"});u=C;let b=new P(t,C),E=q.deltaEOK(b);if(E<c){if(c-E<i)return u;$=!1,m=L}else w=L}}return u}};function Te(e){let t=e.map(r=>{let n=r/255,o=n<0?-1:1,a=Math.abs(n);return a<=.04045?n/12.92:o*((a+.055)/1.055)**2.4});return ce(H.SRGB_to_XYZD65,t)}function Ze(e){return ce(H.XYZD65_to_SRGB,e).map(n=>{let o=n<0?-1:1,a=Math.abs(n);return a>.0031308?o*(1.055*a**(1/2.4)-.055):12.92*n}).map(n=>n*255)}function $e([e,t,r]){t/=100,r/=100;let n=o=>{let a=(o+e/30)%12,s=t*Math.min(r,1-r);return r-s*Math.max(-1,Math.min(a-3,9-a,1))};return[n(0)*255,n(8)*255,n(4)*255]}function De(e){let[t,r,n]=e.map(u=>u/255),o=Math.max(t,r,n),a=Math.min(t,r,n),s=(o+a)/2,c=0,i=0,d=o-a;return d!==0&&(i=d/(1-Math.abs(2*s-1)),c=o===t?(r-n)/d+(r<n?6:0):o===r?(n-t)/d+2:(t-r)/d+4,c*=60),[c%360,i*100,s*100]}function ze([e,t,r]){if(t/=100,r/=100,t+r>=1){let o=t/(t+r)*255;return[o,o,o]}return $e([e,100,50]).map(o=>o/255).map(o=>(o*(1-t-r)+t)*255)}function Ie(e){let[t,r,n]=e.map(i=>i/255),o=Math.max(t,r,n),a=Math.min(t,r,n),s=0,c=o-a;return c===0?s=0:(s=o===t?(r-n)/c+(r<n?6:0):o===r?(n-t)/c+2:(t-r)/c+4,s=s*60%360),[s,a*100,(1-o)*100]}function Xe([e,t,r]){let n=[.9642956764295677,1,.8251046025104602],o=24389/27,a=216/24389,s=(e+16)/116,c=t/500+s,i=s-r/200;return[c**3>a?c**3:(116*c-16)/o,e>o*a?s**3:e/o,i**3>a?i**3:(116*i-16)/o].map((u,f)=>u*n[f])}function Re(e){let t=[.9642956764295677,1,.8251046025104602],r=24389/27,n=216/24389,o=e.map((i,d)=>i/t[d]),[a,s,c]=o.map(i=>i>n?Math.cbrt(i):(r*i+16)/116);return[116*s-16,500*(a-s),200*(s-c)]}function Ye([e,t,r]){return[e,t*Math.cos(r*Math.PI/180),t*Math.sin(r*Math.PI/180)]}function Pe([e,t,r]){let n=Math.hypot(t,r),o=Math.atan2(r,t)*180/Math.PI;return o<0&&(o+=360),[e,n,o]}function qe(e){let{LMS_to_XYZD65:t,OKLAB_to_LMS:r}=H,n=ce(r,e);return ce(t,n.map(o=>o**3))}function Ne(e){let{XYZD65_to_LMS:t,LMS_to_OKLAB:r}=H,n=ce(t,e);return ce(r,n.map(Math.cbrt))}function Fe([e,t,r]){return[e,t*Math.cos(r*Math.PI/180),t*Math.sin(r*Math.PI/180)]}function He([e,t,r]){let n=Math.hypot(t,r),o=Math.atan2(r,t)*180/Math.PI;return o<0&&(o+=360),[e,n,o]}var Me={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},pe={srgb:ae("srgb",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r<=.04045?t*(r/12.92):t*Math.pow((r+.055)/1.055,2.4)},fromLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r>.0031308?t*(1.055*Math.pow(r,1/2.4)-.055):t*(12.92*r)},toBridgeMatrix:H.SRGB_to_XYZD65,fromBridgeMatrix:H.XYZD65_to_SRGB}),"srgb-linear":ae("srgb-linear",{components:["r","g","b"],bridge:"xyz-d65",toBridgeMatrix:H.SRGB_to_XYZD65,fromBridgeMatrix:H.XYZD65_to_SRGB}),"display-p3":ae("display-p3",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r<=.04045?t*(r/12.92):t*Math.pow((r+.055)/1.055,2.4)},fromLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r>.0031308?t*(1.055*Math.pow(r,1/2.4)-.055):t*(12.92*r)},toBridgeMatrix:H.P3_to_XYZD65,fromBridgeMatrix:H.XYZD65_to_P3}),rec2020:ae("rec2020",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=1.09929682680944,r=.018053968510807,n=e<0?-1:1,o=Math.abs(e);return o<r*4.5?n*(o/4.5):n*Math.pow((o+t-1)/t,1/.45)},fromLinear:e=>{let t=1.09929682680944,r=.018053968510807,n=e<0?-1:1,o=Math.abs(e);return o>r?n*(t*Math.pow(o,.45)-(t-1)):n*(4.5*o)},toBridgeMatrix:H.REC2020_to_XYZD65,fromBridgeMatrix:H.XYZD65_to_REC2020}),"a98-rgb":ae("a98-rgb",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return t*Math.pow(r,563/256)},fromLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return t*Math.pow(r,256/563)},toBridgeMatrix:H.A98_to_XYZD65,fromBridgeMatrix:H.XYZD65_to_A98}),"prophoto-rgb":ae("prophoto-rgb",{components:["r","g","b"],bridge:"xyz-d50",toLinear:e=>{let r=e<0?-1:1,n=Math.abs(e);return n<=.03125?r*(n/16):r*Math.pow(n,1.8)},fromLinear:e=>{let t=.001953125,r=e<0?-1:1,n=Math.abs(e);return n>=t?r*Math.pow(n,1/1.8):r*(16*n)},toBridgeMatrix:H.ProPhoto_to_XYZD50,fromBridgeMatrix:H.XYZD50_to_ProPhoto}),"xyz-d65":ae("xyz-d65",{targetGamut:null,components:["x","y","z"],bridge:"xyz-d65",toBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]],fromBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]]}),"xyz-d50":ae("xyz-d50",{targetGamut:null,components:["x","y","z"],bridge:"xyz-d65",toBridgeMatrix:H.D50_to_D65,fromBridgeMatrix:H.D65_to_d50}),xyz:ae("xyz",{targetGamut:null,components:["x","y","z"],bridge:"xyz-d65",toBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]],fromBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]]})},Z={rgb:{supportsLegacy:!0,alphaVariant:"rgba",components:{r:{index:0,value:[0,255],precision:0},g:{index:1,value:[0,255],precision:0},b:{index:2,value:[0,255],precision:0}},bridge:"xyz-d65",toBridge:Te,fromBridge:Ze},hsl:{supportsLegacy:!0,alphaVariant:"hsla",components:{h:{index:0,value:"angle",precision:0},s:{index:1,value:"percentage",precision:0},l:{index:2,value:"percentage",precision:0}},bridge:"rgb",toBridge:$e,fromBridge:De},hwb:{components:{h:{index:0,value:"angle",precision:0},w:{index:1,value:"percentage",precision:0},b:{index:2,value:"percentage",precision:0}},bridge:"rgb",toBridge:ze,fromBridge:Ie},lab:{targetGamut:null,components:{l:{index:0,value:"percentage",precision:5},a:{index:1,value:[-125,125],precision:5},b:{index:2,value:[-125,125],precision:5}},bridge:"xyz-d50",toBridge:Xe,fromBridge:Re},lch:{targetGamut:null,components:{l:{index:0,value:"percentage",precision:5},c:{index:1,value:[0,150],precision:5},h:{index:2,value:"angle",precision:5}},bridge:"lab",toBridge:Ye,fromBridge:Pe},oklab:{targetGamut:null,components:{l:{index:0,value:[0,1],precision:5},a:{index:1,value:[-.4,.4],precision:5},b:{index:2,value:[-.4,.4],precision:5}},bridge:"xyz-d65",toBridge:qe,fromBridge:Ne},oklch:{targetGamut:null,components:{l:{index:0,value:[0,1],precision:5},c:{index:1,value:[0,.4],precision:5},h:{index:2,value:"angle",precision:5}},bridge:"oklab",toBridge:Fe,fromBridge:He},...pe},_e=Object.fromEntries(Object.entries(Z).map(([e,t])=>[e,je(e,t)])),Ge={"hex-color":{isValid:e=>e[0]==="#",bridge:"rgb",toBridge:e=>e,parse:e=>{let t=e.slice(1);if(![3,4,6,8].includes(t.length))throw new Error("Invalid hex color length.");for(let c of t){let i=c.charCodeAt(0),d=i>=48&&i<=57,u=i>=97&&i<=102,f=i>=65&&i<=70;if(!(d||u||f))throw new Error("Invalid hex color character.")}let r=c=>parseInt(c.length===1?c+c:c,16),[n,o,a,s=255]=t.length<=4?t.split("").map(r):[t.slice(0,2),t.slice(2,4),t.slice(4,6),t.slice(6,8)].map(c=>parseInt(c||"ff",16));return[n,o,a,s/255]},fromBridge:e=>e,format:([e,t,r,n=1])=>{let o=s=>s.toString(16).padStart(2,"0");return`#${[e,t,r].map(s=>o(Math.round(Math.max(0,Math.min(255,s))))).join("")}${n<1?o(Math.round(n*255)):""}`}},..._e,"named-color":{isValid:e=>Object.keys(Me).some(t=>t===e),bridge:"rgb",toBridge:e=>e,parse:e=>{let t=Me[e];if(!t)throw new Error(`Invalid named-color: ${e}.`);return[...t,1]},fromBridge:e=>e,format:e=>{let[t,r,n]=e.map((o,a)=>a<3?Math.round(Math.min(255,Math.max(0,o))):o);for(let[o,[a,s,c]]of Object.entries(Me))if(t===a&&r===s&&n===c)return o}},"color-mix":{isValid:e=>e.slice(0,10)==="color-mix("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t=b=>{let E=b.trim(),S,_=E,W=_.match(/^(\d+)%\s+/);if(W){let j=parseInt(W[1],10);S=Math.min(1,Math.max(0,j/100)),_=_.slice(W[0].length).trim()}let O="",A="";if(/^[a-z]/i.test(_)){let{expression:j,end:I}=oe(_,0);if(j)O=j,A=_.slice(I).trim();else{let V=_.match(/^([^\s]+)(.*)$/);O=V?V[1]:_,A=V?V[2].trim():""}}else{let j=_.match(/^([^\s]+)(.*)$/);O=j?j[1]:_,A=j?j[2].trim():""}if(S===void 0){let j=A.match(/^(-?(?:\d+\.?\d*|\.\d+))%/);if(j){if(S=parseInt(j[1],10)/100,A=A.slice(j[0].length).trim(),S<0)throw new Error("Percentages less than 0 are not valid.");if(S>1)throw new Error("Percentages greater than 100 are not valid.")}else if(A.slice(0,5)==="calc("){let{expression:I,end:V}=oe(A,0);if(!I)throw new Error("Malformed calc() weight expression.");A=A.slice(V).trim()}}if(A.length>0)throw new Error(`Unexpected extra tokens after color: '${A}'.`);return{color:P.from(O),weight:S}},r=(b,E)=>{if(b===void 0&&typeof E=="number")b=1-E;else if(typeof b=="number"&&E===void 0)E=1-b;else if(b===void 0&&E===void 0)b=E=.5;else if(b=b,E=E,b+E<=0)throw new Error("Sum of percengates cannot be 0%.");let S=b+E,_;return S>1?(b/=S,E/=S):(b/=S,E/=S,_=S),{amount:E,alphaMultiplier:_}},n="color-mix",{expression:o}=oe(e,n.length);if(!o)throw new Error("Malformed color-mix expression.");let a=o.slice(1,-1).trim(),s=[],c=0,i="";for(;c<a.length;){let b=a[c];if(b===","){s.push(i.trim()),i="",c++;continue}if(b==="("||/[a-zA-Z]/.test(b)){let{expression:E,end:S}=oe(a,c);if(E){i+=E,c=S;continue}}i+=b,c++}if(s.push(i.trim()),s.length!==3)throw new Error("color-mix must have three comma-separated parts.");let u=s[0].match(/^in\s+([a-z0-9-]+)(?:\s+(shorter|longer|increasing|decreasing)\s+hue)?$/);if(!u)throw new Error("Invalid model and hue format.");let f=u[1],h=u[2];if(f==="rgb")throw new Error('RGB model is not allowed in color-mix(). Use "srgb" instead.');if(h){let b=Z[f].components;if(!b)throw new Error(`Unknown color model: ${f}.`);if(!Object.values(b).some(S=>S.value==="angle"))throw new Error(`Hue interpolation not supported in ${f} space.`)}else h="shorter";let{color:m,weight:w}=t(s[1]),{color:$,weight:L}=t(s[2]),{amount:q,alphaMultiplier:C=1}=r(w,L);return m.with({alpha:b=>b*C}).in(f).mix($.with({alpha:b=>b*C}),{amount:q,hue:h}).in("rgb").toArray({fit:"none",precision:null})}},transparent:{isValid:e=>e==="transparent",bridge:"rgb",toBridge:e=>e,parse:e=>[0,0,0,0]}},ue={...Ge,currentColor:{isValid:e=>e==="currentcolor",bridge:"rgb",toBridge:e=>e,parse:e=>[0,0,0,1]},"system-color":{isValid:e=>Object.keys(ee.systemColors).some(t=>t.toLowerCase()===e),bridge:"rgb",toBridge:e=>e,parse:e=>{let{systemColors:t}=ee,r=Object.keys(t).find(o=>o.toLowerCase()===e);return[...t[r][ee.theme==="light"?0:1],1]}},"contrast-color":{isValid:e=>e.slice(0,15)==="contrast-color("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t=e.slice(15,-1),[,r]=P.from(t).in("xyz-d65").toArray({fit:"none",precision:null});return r>.5?[0,0,0,1]:[255,255,255,1]}},"device-cmyk":{isValid:e=>e.slice(0,12)==="device-cmyk("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t="device-cmyk",r=e.indexOf(t);if(r===-1)throw new Error("Invalid device-cmyk syntax");let{expression:n}=oe(e,r+t.length);if(!n)throw new Error("Malformed device-cmyk expression");let o=n.slice(1,-1).trim(),a=[],s=0;for(;s<o.length;){let C=o[s];if(C===" "){s++;continue}if(C==="("||/[a-zA-Z-]/.test(C)){let{expression:b,end:E}=oe(o,s);if(b){a.push(b),s=E;continue}}if(/[\d.+-]/.test(C)){let b="";for(;s<o.length&&/[\d.eE+-]/.test(o[s]);)b+=o[s],s++;if(s<o.length&&o[s]==="%")b+="%",s++;else if(s<o.length&&/[a-zA-Z]/.test(o[s]))for(;s<o.length&&/[a-zA-Z]/.test(o[s]);)b+=o[s],s++;a.push(b);continue}if(C===","||C==="/"){a.push(C),s++;continue}throw new Error(`Unexpected character: ${C}`)}let c=C=>C[C.length-1]==="%"?parseFloat(C)/100:parseFloat(C);if(a.length>=2&&a[1]===","){let C=a.filter(b=>b!==",");if(C.length===4||C.length===5){let[b,E,S,_,W=1]=C.map(c),O=1-Math.min(1,b*(1-_)+_),A=1-Math.min(1,E*(1-_)+_),z=1-Math.min(1,S*(1-_)+_);return[O*255,A*255,z*255,W]}throw new Error("Invalid number of components for comma-separated device-cmyk")}let i=0,d=[];for(;i<a.length&&d.length<4&&a[i]!=="/"&&a[i]!==",";)d.push(a[i]),i++;if(d.length!==4)throw new Error("Invalid number of components for space-separated device-cmyk");let[u,f,h,m]=d.map(c),w=1;if(i<a.length&&a[i]==="/"){if(i++,i>=a.length)throw new Error("Missing alpha value");w=c(a[i]),i++}if(i<a.length&&a[i]===","){i++;let C=a.slice(i).join(" ");return P.from(C).in("rgb").toArray({fit:"none",precision:null})}let $=1-Math.min(1,u*(1-m)+m),L=1-Math.min(1,f*(1-m)+m),q=1-Math.min(1,h*(1-m)+m);return[$*255,L*255,q*255,w]},fromBridge:e=>e,format:([e,t,r,n=1],o={})=>{let{legacy:a=!1,precision:s=3,fit:c=ee.defaults.fit}=o,[i,d,u]=le([e,t,r],"rgb",{method:c}),f=i/255,h=d/255,m=u/255,w=1-Math.max(f,h,m),$=_=>Number(s===null?_:_.toFixed(s)).toString(),L=$(w===1?0:(1-f-w)/(1-w)),q=$(w===1?0:(1-h-w)/(1-w)),C=$(w===1?0:(1-m-w)/(1-w)),b=$(w),E=Number(n.toFixed(3)).toString();if(a)return`device-cmyk(${L}, ${q}, ${C}, ${b}${n<1?`, ${E}`:""})`;let S=_e.rgb.format?.([i,d,u,n],o);return`device-cmyk(${L} ${q} ${C} ${b}${n<1?` / ${E}`:""}, ${S})`}},"light-dark":{isValid:e=>e.slice(0,11)==="light-dark("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t="light-dark",r=e.indexOf(t);if(r===-1)throw new Error("Not a <light-dark()> expression");let{expression:n}=oe(e,r+t.length);if(!n)throw new Error("Malformed <light-dark()> expression");let o=n.slice(1,-1).trim(),a=[],s="",c=0;for(;c<o.length;){let f=o[c];if(f===","){a.push(s.trim()),s="",c++;continue}if(f==="("||/[a-zA-Z]/.test(f)){let{expression:h,end:m}=oe(o,c);if(h){s+=h,c=m;continue}}s+=f,c++}if(a.push(s.trim()),a.length!==2)throw new Error("Invalid light-dark format");let[i,d]=a,{theme:u}=ee;return P.from(u==="light"?i:d).toArray({fit:"none",precision:null})}}};var P=class e{model;coords;constructor(t,r=[0,0,0,0]){if(!(t in Z))throw new Error(`Unsupported color model: '${t}'`);if([3,4].includes(r.length)===!1)throw new Error("Coordinates array must have 3 or 4 elements.");let n=r.slice();n.length===3&&n.push(1),this.model=t,this.coords=n}static from(t){let r=xe(t);for(let n in ue){let o=n,{parse:a,bridge:s,toBridge:c,isValid:i}=ue[o];if(!i(r))continue;let d=a(r),u=o in Z?d:c(d),f=o in Z?o:s;return new e(f,u)}throw new Error(`Unsupported or invalid color format: '${t}'.`)}static type(t,r=!1){let n=xe(t);for(let o in ue){let a=o,{isValid:s,bridge:c,parse:i,toBridge:d}=ue[a];if(s(n)){if(!r)return a;try{let u=i(n),f=a in Z?u:d(u),h=o in Z?o:c;return typeof new e(h,f)=="object"?a:void 0}catch{return}}}}static isValid(t,r){try{if(r){let n=r?.trim().toLowerCase(),o=xe(t),{isValid:a,bridge:s,parse:c,toBridge:i}=ue[n];if(!a(o))return!1;let d=c(o),u=n in Z?d:i(d),f=n in Z?n:s;return!!new e(f,u)}return!!e.from(t)}catch{return!1}}static random(t={}){let r=Object.keys(Z),n=t.model??r[Math.floor(Math.random()*r.length)],{components:o}=Z[n],a=new Set([...Object.keys(o),"alpha"]);for(let c of["limits","bias","base","deviation"]){let i=t[c];if(i){for(let d of Object.keys(i))if(!a.has(d))throw new Error(`Invalid component "${d}" for model "${n}". Valid components: ${[...a].join(", ")}`)}}let s=[];for(let[c,i]of Object.entries(o)){let d=t.base?.[c],u=t.deviation?.[c],f;if(d!=null&&u!=null){let h=Math.random()||1e-9,m=Math.random()||1e-9;f=d+Math.sqrt(-2*Math.log(h))*Math.cos(2*Math.PI*m)*u}else{let[h,m]=i.value==="angle"?[0,360]:i.value==="percentage"?[0,100]:i.value,w=t.limits?.[c];if(w){let[q,C]=w;h=Math.max(h,q),m=Math.min(m,C)}let $=Math.random(),L=t.bias?.[c];L&&($=L($)),f=h+$*(m-h)}if(i.value==="angle")f=(f%360+360)%360;else if(i.value==="percentage")f=Math.min(100,Math.max(0,f));else if(Array.isArray(i.value)){let[h,m]=i.value;f=Math.min(m,Math.max(h,f))}else throw new Error(`Invalid component value definition for "${c}".`);s[i.index]=f}return new e(n,s)}to(t,r={}){let n=t.toLowerCase(),{legacy:o=!1,fit:a=ee.defaults.fit,precision:s,units:c=!1}=r,i=ue[n];if(!i)throw new Error(`Unsupported color type: '${n}'.`);let{fromBridge:d,bridge:u,format:f}=i;if(!d||!f)throw new Error(`Invalid output type: '${n}'.`);let h=m=>f(m,{legacy:o,fit:a,precision:s,units:c});return n===this.model?h(this.coords):n in Z?h(this.in(n).toArray({fit:"none",precision:null})):h(d(this.in(u).toArray({fit:"none",precision:null})))}in(t){let r=this.model,n=t.trim().toLowerCase();if(n===r)return new e(n,[...this.coords]);let o=me.get("graph"),a=me.get("paths");if(!o){o={};for(let[u,f]of Object.entries(Z)){let{bridge:h}=f;o[u]=[...o[u]||[],h],o[h]=[...o[h]||[],u]}me.set("graph",o)}a||(a=new Map,me.set("paths",a));let s=`${r}-${n}`,c=this.coords.slice(0,3);if(!a.has(s)){let u=[r],f={[r]:null};for(let m=0;m<u.length;m++){let w=u[m];if(w===n)break;for(let $ of o[w]||[])$ in f||(f[$]=w,u.push($))}let h=[];for(let m=n;m;m=f[m])h.push(m);if(h.reverse(),!h.length||h[0]!==r)throw new Error(`Cannot convert from ${r} to ${n}. No path found.`);a.set(s,h)}let i=[...c],d=a.get(s);for(let u=0;u<d.length-1;u++){let f=d[u],h=d[u+1],m=Z[f],w=Z[h];if(m.toBridge&&m.bridge===h)i=m.toBridge(i);else if(w.fromBridge&&w.bridge===f)i=w.fromBridge(i);else throw new Error(`No conversion found between ${f} and ${h}.`)}return new e(n,[...i.slice(0,3),this.coords[3]??1])}toString(t={}){let{format:r}=ue[this.model],{legacy:n=!1,fit:o=ee.defaults.fit,precision:a,units:s=!1}=t;return r?.(this.coords,{legacy:n,fit:o,precision:a,units:s})}toObject(t={}){let r=this.toArray(t),{components:n}=Z[this.model];if(!n)throw new Error(`Model ${this.model} does not have defined components.`);let o={...n,alpha:{index:3,value:[0,1],precision:3}},a={};for(let[s,{index:c}]of Object.entries(o))a[s]=r[c];return a}toArray(t={}){let{fit:r=ee.defaults.fit,precision:n}=t,{model:o,coords:a}=this,{components:s}=Z[o];if(!s)throw new Error(`Model ${o} does not have defined components.`);let c={...s,alpha:{index:3,value:[0,1],precision:3}},i=(f,h)=>{let m=Object.values(c)[h]?.value,[w,$]=Array.isArray(m)?m:m==="angle"?[0,360]:[0,100];return Number.isNaN(f)?0:f===1/0?$:f===-1/0?w:typeof f=="number"?f:0},d=a.slice(0,3).map(i);return[...le(d,o,{method:r,precision:n}).slice(0,3),a[3]]}with(t){let{model:r}=this,n=this.toArray({fit:"none",precision:null}),{components:o}=Z[r];if(!o)throw new Error(`Model ${r} does not have defined components.`);let a={...o,alpha:{index:3,value:[0,1],precision:3}},s=Object.keys(a),c;if(typeof t=="function"?c=t(Object.fromEntries(s.map(u=>[u,n[a[u].index]]))):c=t,Array.isArray(c)){let d=n.map((u,f)=>{let h=c[f],{value:m}=Object.values(a).find(L=>L.index===f);if(typeof h!="number")return u;let[w,$]=Array.isArray(m)?m:m==="angle"?[0,360]:[0,100];return Number.isNaN(h)?0:h===1/0?$:h===-1/0?w:h});return new e(r,[...d.slice(0,3),n[3]])}let i=[...n];for(let d of s){if(!(d in c))continue;let{index:u,value:f}=a[d],h=n[u],m=c[d],w=typeof m=="function"?m(h):m;if(typeof w=="number"){let[$,L]=Array.isArray(f)?f:f==="angle"?[0,360]:[0,100];Number.isNaN(w)?w=0:w===1/0?w=L:w===-1/0&&(w=$)}i[u]=w}return new e(r,[...i.slice(0,3),i[3]??n[3]])}mix(t,r={}){let{model:n}=this,o=this.toArray({fit:"none",precision:null}),{components:a}=Z[n];if(!a)throw new Error(`Model ${n} does not have defined components.`);let{hue:s="shorter",amount:c=.5,easing:i="linear",gamma:d=1}=r,u={...a,alpha:{index:3,value:[0,1],precision:3}},f=(O,A)=>{let z=((A-O)%360+360)%360;return z>180?z-360:z},h=(O,A)=>f(O,A)>=0?f(O,A)-360:f(O,A)+360,m=(O,A,z,j)=>{let I=V=>(V%360+360)%360;switch(j){case"shorter":return I(O+z*f(O,A));case"longer":return I(O+z*h(O,A));case"increasing":return I(O*(1-z)+(A<O?A+360:A)*z);case"decreasing":return I(O*(1-z)+(A>O?A-360:A)*z);default:throw new Error(`Invalid hue interpolation method: ${j}`)}},w=Math.max(0,Math.min(1,c)),$=typeof i=="function"?i:ke[i],L=Math.pow($(w),1/d),q=typeof t=="string"?e.from(t):t,C=o.slice(0,3),b=q.in(n).toArray({fit:"none",precision:null}).slice(0,3),E=o[3],S=q.coords[3],_=Object.entries(u).find(([O])=>O==="h")?.[1].index;if(w===0)return new e(n,[...C,E]);if(w===1)return new e(n,[...b,S]);if(E<1||S<1){let O=C.map((j,I)=>{let V=b[I];if(I===_)return m(j,V,L,s);let he=j*E,fe=V*S;return he*(1-L)+fe*L}),A=E*(1-L)+S*L,z=A>0?O.map((j,I)=>I===_?j:j/A):C.map((j,I)=>I===_?O[I]:0);return new e(n,[...z,A])}let W=C.map((O,A)=>{let z=Object.values(u).find(I=>I.index===A);if(!z)return O;let j=b[A];return z.value==="angle"?m(O,j,L,s):O+(j-O)*L});return new e(n,[...W,1])}within(t,r=ee.defaults.fit){let n=t.trim().toLowerCase();if(!(n in pe))throw new Error(`Unsupported color gamut: '${n}'.`);let o=this.in(n).toArray({fit:r,precision:null});return new e(n,o).in(this.model)}contrast(t){let r=typeof t=="string"?e.from(t):t,[,n]=this.in("xyz-d65").toArray({fit:"none",precision:null}),[,o]=r.in("xyz-d65").toArray({fit:"none",precision:null});return(Math.max(n,o)+.05)/(Math.min(n,o)+.05)}deltaEOK(t){let r={fit:"none",precision:null},[n,o,a]=this.in("oklab").toArray(r),[s,c,i]=(typeof t=="string"?e.from(t):t).in("oklab").toArray(r),d=n-s,u=o-c,f=a-i;return Math.sqrt(d**2+u**2+f**2)*100}deltaE76(t){let r={fit:"none",precision:null},[n,o,a]=this.in("lab").toArray(r),[s,c,i]=(typeof t=="string"?e.from(t):t).in("lab").toArray(r),d=n-s,u=o-c,f=a-i;return Math.hypot(d,u,f)}deltaE94(t){let r={fit:"none",precision:null},[n,o,a]=this.in("lab").toArray(r),[s,c,i]=(typeof t=="string"?e.from(t):t).in("lab").toArray(r),d=n-s,u=o-c,f=a-i,h=Math.sqrt(o*o+a*a),m=Math.sqrt(c*c+i*i),w=h-m,$=Math.sqrt(Math.max(0,u*u+f*f-w*w)),L=1,q=1,C=1,b=.045,E=.015,S=1+b*h,_=1+E*h;return Math.sqrt((d/L)**2+(w/(q*S))**2+($/(C*_))**2)}deltaE2000(t){let r={fit:"none",precision:null},[n,o,a]=this.in("lab").toArray(r),[s,c,i]=(typeof t=="string"?e.from(t):t).in("lab").toArray(r),d=Math.PI,u=d/180,f=180/d,h=Math.sqrt(o**2+a**2),m=Math.sqrt(c**2+i**2),w=(h+m)/2,$=Math.pow(25,7),L=Math.pow(w,7),q=.5*(1-Math.sqrt(L/(L+$))),C=(1+q)*o,b=(1+q)*c,E=Math.sqrt(C**2+a**2),S=Math.sqrt(b**2+i**2),_=Math.atan2(a,C),W=Math.atan2(i,b);_<0&&(_+=2*d),W<0&&(W+=2*d),_*=f,W*=f;let O=s-n,A=S-E,z=W-_,j=Math.abs(z),I=0;E*S!==0&&(j<=180?I=z:z>180?I=z-360:I=z+360);let V=2*Math.sqrt(E*S)*Math.sin(I*u/2),he=(n+s)/2,fe=(E+S)/2,ge=Math.pow(fe,7),de=_+W,ie=0;E===0&&S===0?ie=de:j<=180?ie=de/2:de<360?ie=(de+360)/2:ie=(de-360)/2;let ye=(he-50)**2,ve=1+.015*ye/Math.sqrt(20+ye),we=1+.045*fe,l=1;l-=.17*Math.cos((ie-30)*u),l+=.24*Math.cos(2*ie*u),l+=.32*Math.cos((3*ie+6)*u),l-=.2*Math.cos((4*ie-63)*u);let v=1+.015*fe*l,p=30*Math.exp(-1*((ie-275)/25)**2),G=2*Math.sqrt(ge/(ge+$)),N=-1*Math.sin(2*p*u)*G,y=(O/ve)**2;return y+=(A/we)**2,y+=(V/v)**2,y+=N*(A/we)*(V/v),Math.sqrt(y)}equals(t,r=1e-5){let n=typeof t=="string"?e.from(t):t;if(n.model===this.model)return this.coords.every((s,c)=>Math.abs(s-n.coords[c])<=r);let o=this.in("xyz-d65").toArray({fit:"none",precision:null}),a=n.in("xyz-d65").toArray({fit:"none",precision:null});return o.every((s,c)=>Math.abs(s-a[c])<=r)}inGamut(t,r=1e-5){let n=t.trim().toLowerCase();if(!(n in pe))throw new Error(`Unsupported color gamut: '${n}'.`);let{components:o,targetGamut:a}=Z[n];if(!a)return!0;let s=this.in(n).toArray({fit:"none",precision:null});return Object.values(o).every(({index:c,value:i})=>{let d=s[c],[u,f]=Array.isArray(i)?i:i==="angle"?[0,360]:[0,100];return d>=u-r&&d<=f+r})}};return tt(rt);})();
|
|
1
|
+
"use strict";var Saturon=(()=>{var Ae=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var Qe=Object.prototype.hasOwnProperty;var et=(e,t)=>{for(var r in t)Ae(e,r,{get:t[r],enumerable:!0})},tt=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Je(t))!Qe.call(e,n)&&n!==r&&Ae(e,n,{get:()=>t[n],enumerable:!(o=We(t,n))||o.enumerable});return e};var rt=e=>tt(Ae({},"__esModule",{value:!0}),e);var nt={};et(nt,{Color:()=>Y});var Oe={AccentColor:[[0,120,215],[10,132,255]],AccentColorText:[[255,255,255],[255,255,255]],ActiveText:[[255,0,0],[255,100,100]],ButtonBorder:[[169,169,169],[90,90,90]],ButtonFace:[[240,240,240],[60,60,60]],ButtonText:[[0,0,0],[255,255,255]],Canvas:[[255,255,255],[30,30,30]],CanvasText:[[0,0,0],[255,255,255]],Field:[[255,255,255],[45,45,45]],FieldText:[[0,0,0],[255,255,255]],GrayText:[[128,128,128],[169,169,169]],Highlight:[[0,120,215],[80,80,80]],HighlightText:[[255,255,255],[0,0,0]],LinkText:[[0,0,255],[0,128,255]],Mark:[[255,255,0],[255,200,0]],MarkText:[[0,0,0],[0,0,0]],SelectedItem:[[0,120,215],[0,120,215]],SelectedItemText:[[255,255,255],[255,255,255]],VisitedText:[[128,0,128],[200,120,255]]},te={theme:"light",systemColors:Oe,defaults:{fit:"clip"}};var we=new Map;function de(e,t){let r=Array.isArray(e[0])?e.length:1,o=Array.isArray(e[0])?e:[e],n=Array.isArray(t[0])?t:t.map(c=>[c]),i=n[0].length,s=n[0].map((c,f)=>n.map(d=>d[f])),a=o.map(c=>s.map(f=>c.reduce((d,l,h)=>d+l*(f[h]||0),0)));return r===1?a[0]:i===1?a.map(c=>c[0]):a}function Me(e){return e.trim().replace(/\s+/g," ").replace(/\( /g,"(").replace(/ \)/g,")").replace(/\s*,\s*/g,", ").replace(/ ,/g,",").replace(/calc\(NaN\)/g,"0").replace(/[A-Z]/g,t=>String.fromCharCode(t.charCodeAt(0)+32))}function le(e,t){let r=t,o="",n=0;if(e[r]!=="(")for(;r<e.length&&/[a-zA-Z0-9-%#]/.test(e[r]);)o+=e[r],r++;if(e[r]==="("){for(o+="(",r++,n=1;r<e.length&&n>0;){let i=e[r];i==="("?n++:i===")"&&n--,n>0&&(o+=i),r++}o+=")"}return{expression:o,end:r}}function pe(e,t,r={}){let{method:o=te.defaults.fit,precision:n}=r,{components:i}=T[t],s=Object.values(i).reduce((c,f)=>(c[f.index]=f,c),[]),a;if(o==="none")a=e;else if(o==="clip")a=e.map((c,f)=>{let d=s[f];if(!d)throw new Error(`Missing component properties for index ${f}.`);if(d.value==="hue")return(c%360+360)%360;let[l,h]=Array.isArray(d.value)?d.value:[0,100];return Math.min(h,Math.max(l,c))});else{let c=_e[o];if(!c)throw new Error(`Invalid gamut clipping method: must be ${Object.keys(_e).join(", ")} or "none".`);a=c(e,t)}return a.map((c,f)=>{let d;if(typeof n=="number"||n===null)d=n;else if(typeof n>"u")d=s[f]?.precision??3;else throw new TypeError(`Invalid precision value: ${n}.`);return d===null?c:Number(c.toFixed(d))})}function je(e,t){let r=(u,B,p={},k=!1,H=!1)=>{let w=(A,v,J)=>{let ce=parseFloat(A);if(isNaN(ce))throw new Error(`Invalid percentage value: '${A}'.`);return B==="percentage"?ce:v<0&&J>0?ce/100*(J-v)/2:ce/100*(J-v)+v},Z=A=>{let v=parseFloat(A);if(isNaN(v))throw new Error(`Invalid hue value: '${A}'.`);return A.slice(-3)==="deg"?v:A.slice(-3)==="rad"?v*(180/m):A.slice(-4)==="grad"?v*.9:A.slice(-4)==="turn"?v*360:v},G=(A,v,J)=>{let ce=E=>{let D=[];for(let g=0;g<E.length;){let I=E[g];if(/\s/.test(I)){g++;continue}if(E.slice(g,g+2)==="**"){D.push({type:"operator",value:"**"}),g+=2;continue}if(/[0-9]/.test(I)||I==="."&&/[0-9]/.test(E[g+1]||"")){let ue="";for(;g<E.length&&/[0-9.]/.test(E[g]);)ue+=E[g++];if(g<E.length&&/[eE]/.test(E[g]))for(ue+=E[g++],/[+-]/.test(E[g])&&(ue+=E[g++]);g<E.length&&/[0-9]/.test(E[g]);)ue+=E[g++];D.push({type:"number",value:parseFloat(ue)});continue}if(/[a-zA-Z_]/.test(I)){let ue="";for(;g<E.length&&/[a-zA-Z0-9_]/.test(E[g]);)ue+=E[g++];D.push({type:"identifier",value:ue});continue}if("+-*/%(),".includes(I)){D.push({type:"operator",value:I}),g++;continue}throw new Error(`Unexpected character: ${I}`)}return D},Q=E=>{let D=0,g=()=>D<E.length?E[D]:null,I=()=>{if(D>=E.length)throw new Error("Unexpected end of input");return E[D++]},ue=R=>{let ie=g();if(!ie||ie.value!==R)throw new Error(`Expected "${R}" but got "${ie?ie.value:"end of input"}`);I()},Ke=()=>{let R=g();if(!R)throw new Error("Unexpected end of input");if(R.type==="number")return I(),{type:"number",value:R.value};if(R.type==="identifier"){if(I(),g()&&g().value==="("){I();let ie=[];if(g()&&g().value!==")")for(ie.push(xe());g()&&g().value===",";)I(),ie.push(xe());return ue(")"),{type:"call",func:R.value,args:ie}}return{type:"var",name:R.value}}if(R.value==="("){I();let ie=xe();return ue(")"),ie}throw new Error(`Unexpected token: ${R.value}`)},Ce=()=>g()&&(g().value==="+"||g().value==="-")?{type:"unary",op:I().value,arg:Ce()}:Ke(),Se=()=>{let R=Ce();for(;g()&&g().value==="**";)R={type:"binary",op:I().value,left:R,right:Ce()};return R},Ne=()=>{let R=Se();for(;g()&&["*","/","%"].includes(String(g().value));)R={type:"binary",op:I().value,left:R,right:Se()};return R},xe=()=>{let R=Ne();for(;g()&&(g().value==="+"||g().value==="-");)R={type:"binary",op:I().value,left:R,right:Ne()};return R},Ue=xe();if(D<E.length)throw new Error(`Extra tokens after expression: ${E.slice(D).map(R=>R.value).join(" ")}`);return Ue},ee=(E,D)=>{switch(E.type){case"number":return E.value;case"var":{let g=D[E.name];if(g===void 0)throw new Error(`Unknown variable: ${E.name}`);if(typeof g=="function")throw new Error(`Expected variable but found function: ${E.name}`);return g}case"binary":{let g=ee(E.left,D),I=ee(E.right,D);switch(E.op){case"+":return g+I;case"-":return g-I;case"*":return g*I;case"/":return g/I;case"%":return g%I;case"**":return g**I;default:throw new Error(`Unknown binary operator: ${E.op}`)}}case"unary":{let g=ee(E.arg,D);switch(E.op){case"+":return+g;case"-":return-g;default:throw new Error(`Unknown unary operator: ${E.op}`)}}case"call":{let g=D[E.func];if(typeof g!="function")throw new Error(`Unknown function: ${E.func}`);return g(...E.args.map(I=>ee(I,D)))}default:throw new Error(`Unknown AST node type: ${E.type}`)}},q=A.slice(5,-1).trim();if(q==="infinity")return 1/0;if(q==="-infinity")return-1/0;if(q==="NaN")return NaN;q=q.replace(/(\d+(\.\d+)?)%/g,E=>{if(H===!0)throw new Error("<hue> and <percentage> values are converted to <number> in relative syntax.");let D=w(E,v,J);return D!==void 0?String(D):"0"}),q=q.replace(/(\d+(\.\d+)?)(deg|rad|grad|turn)/g,(E,D,g,I)=>{if(H===!0)throw new Error("<hue> and <percentage> values are converted to <number> in relative syntax.");return String(Z(`${parseFloat(D)}${I}`))});let Be={...p,pi:m,e:x,tau:m*2,pow:S,sqrt:N,sin:j,cos:C,tan:y,asin:_,acos:L,atan:$,atan2:K,exp:re,log:X,log10:se,log2:b,abs:M,min:O,max:P,hypot:U,round:ae,ceil:ne,floor:V,sign:me,trunc:Ee,random:be};try{let E=ce(q),D=Q(E);return ee(D,Be)}catch(E){throw new Error(`Evaluation error: ${E}`)}},z=()=>{if(/^-?(?:\d+|\d*\.\d+)(?:deg|rad|grad|turn)$/.test(u))return Z(u);if(/^-?(?:\d+|\d*\.\d+)$/.test(u))return parseFloat(u);let[A,v]=[0,360];if(u.slice(0,5)==="calc(")return G(u,A,v);throw new Error(`Invalid hue value: '${u}'. Must be a number, or a number with a unit (deg, rad, grad, turn).`)},oe=()=>{if(/^-?(?:\d+|\d*\.\d+)$/.test(u)){if(k&&h===!0)throw new Error("The legacy color syntax does not allow numbers for <percentage> components.");return parseFloat(u)}let[A,v]=[0,100];if(u[u.length-1]==="%")return w(u,A,v);if(u.slice(0,5)==="calc(")return G(u,A,v);throw new Error(`Invalid percentage value: '${u}'. Must be a percentage or a number.`)},W=()=>{if(/^-?(?:\d+|\d*\.\d+)$/.test(u))return parseFloat(u);let[A,v]=B;if(u[u.length-1]==="%")return w(u,A,v);if(u.slice(0,5)==="calc(")return G(u,A,v);throw new Error(`Invalid number value: '${u}'. Must be a number${H===!1?" or a percentage":""}.`)};if(u==="none")return NaN;if(u in p)return p[u];if(B==="hue")return z();if(B==="percentage")return oe();if(Array.isArray(B))return W();throw new Error(`Unable to parse component token: ${u}`)},o=u=>{let{fn:B,space:p,fromOrigin:k,c1:H,c2:w,c3:Z,alpha:G,commaSeparated:z}=u,{components:oe,supportsLegacy:W}=t;if(oe.alpha={index:3,value:[0,1],precision:3},z&&W!==!0)throw new Error(`<${B}()> does not support comma-separated syntax.`);let A=Object.entries(oe).sort((v,J)=>v[1].index-J[1].index);if(k){let v;if(B==="color")v=p;else if(B in T)v=B;else for(let Q in T)if(T[Q].alphaVariant===B){v=Q;break}let J=Y.from(k).in(v).toObject({fit:"none",precision:null});return[H,w,Z,G].map((Q,ee)=>{let[,q]=A[ee];return r(Q,q.value,J,z,!0)}).slice(0,4)}else{let v=[],J=[],ce=[H,w,Z,G];for(let Q=0;Q<A.length;Q++){let[,ee]=A[Q],q=ce[Q];if(z&&q==="none")throw new Error(`${B}() cannot use "none" in comma-separated syntax.`);if(ee.index!==3&&ee.value!=="hue"&&ee.value!=="percentage"&&q.slice(0,5)!=="calc("&&J.push(q.trim()[q.length-1]==="%"),q){let Be=r(q,ee.value,{},z);v[ee.index]=Be}}if(z&&J.length>1){let Q=J.every(Boolean),ee=J.every(q=>!q);if(!Q&&!ee)throw new Error(`${B}()'s <number> components must all be numbers or all percentages.`)}return v.slice(0,4)}},n=u=>{let B=(A,v="/")=>{if(u[A]!==void 0){if(u[A]===v)return{value:u[A+1],hasAlpha:!0};throw new Error("Invalid alpha separator")}return{value:"1",hasAlpha:!1}},p,k,H,w,Z,G,z,oe=!1,W;if(u[0]==="color")if(p="color",u[1]==="from"){k=u[3],H=u[2],w=u[4],Z=u[5],G=u[6];let{value:A,hasAlpha:v}=B(7);W=v?9:7,z=A}else{k=u[1],H=null,w=u[2],Z=u[3],G=u[4];let{value:A,hasAlpha:v}=B(5);W=v?7:5,z=A}else if(p=u[0],k=null,u[1]==="from"){H=u[2],w=u[3],Z=u[4],G=u[5];let{value:A,hasAlpha:v}=B(6);W=v?8:6,z=A}else if(H=null,w=u[1],u[2]===","&&u[4]===","){oe=!0,Z=u[3],G=u[5];let{value:A,hasAlpha:v}=B(6,",");if(W=v?8:6,v&&u[6]!==",")throw new Error("Comma optional syntax requires no commas at all.");z=A}else{Z=u[2],G=u[3];let{value:A,hasAlpha:v}=B(4);W=v?6:4,z=A}if(u.length!==W)throw new Error(`Invalid number of tokens for ${p}(): expected ${W} but got ${u.length}.`);return{fn:p,space:k,fromOrigin:H,c1:w,c2:Z,c3:G,alpha:z,commaSeparated:oe}},i=u=>{let B=[],p=0,k="";for(;p<u.length&&u[p]!=="(";)k+=u[p],p++;k=k.trim(),B.push(k);let H=u.indexOf("(")+1,w=u.slice(H,-1).trim();if(p=0,w.slice(0,5)==="from "){for(B.push("from"),p+=5;p<w.length&&w[p]===" ";)p++;let Z=p;for(;p<w.length&&w[p]!==" ";)p++;let G=w.slice(Z,p);if(G.includes("(")){let{expression:z,end:oe}=le(w,Z);B.push(z),p=oe}else B.push(G);for(;p<w.length&&w[p]===" ";)p++}if(B[0]==="color"&&p<w.length){let Z=p;for(;p<w.length&&w[p]!==" ";)p++;for(B.push(w.slice(Z,p));p<w.length&&w[p]===" ";)p++}for(;p<w.length;){let Z=w[p];if(Z===",")B.push(","),p++,w[p]===" "&&p++;else if(Z==="/")B.push("/"),p++,w[p]===" "&&p++;else if(Z===" ")p++;else if(/[a-zA-Z#]/.test(Z)){let G=p,z="";for(;p<w.length&&/[a-zA-Z0-9-%#]/.test(w[p]);)z+=w[p],p++;if(p<w.length&&w[p]==="("){let{expression:oe,end:W}=le(w,G);B.push(oe),p=W}else B.push(z)}else if(/[\d.-]/.test(Z)){let G="";for(;p<w.length&&/[\d.eE+-]/.test(w[p]);)G+=w[p],p++;if(p<w.length&&w[p]==="%")G+="%",p++,B.push(G);else if(p<w.length&&/[a-zA-Z]/.test(w[p])){let z="";for(;p<w.length&&/[a-zA-Z]/.test(w[p]);)z+=w[p],p++;B.push(G+z)}else B.push(G)}else throw new Error(`Unexpected character: ${Z}`)}return B},s=(u,B)=>{let p="color(from ";if(u.slice(0,11)!==p||u[u.length-1]!==")")return!1;let k=u.slice(p.length,-1).trim(),{expression:H,end:w}=le(k,0);if(!H)return!1;let G=k.slice(w).trim().split(/\s+/);return G.length<1?!1:G[0]===B},{components:a,bridge:c,fromBridge:f,toBridge:d,alphaVariant:l,supportsLegacy:h}=t,{PI:m,E:x,pow:S,sqrt:N,sin:j,cos:C,tan:y,asin:_,acos:L,atan:$,atan2:K,exp:re,log:X,log10:se,log2:b,abs:M,min:O,max:P,hypot:U,round:ae,ceil:ne,floor:V,sign:me,trunc:Ee,random:be}=Math;return{isValid:u=>{let{alphaVariant:B=e}=t;if(e in ge){let p=u.slice(0,`color(${e} `.length)===`color(${e} `,k=u.slice(0,10)==="color(from"&&s(u,e);return(p||k)&&u[u.length-1]===")"}return(u.slice(0,`${e}(`.length)===`${e}(`||u.slice(0,`${B}(`.length)===`${B}(`)&&u[u.length-1]===")"},bridge:c,toBridge:u=>[...d(u.slice(0,3)),u[3]??1],parse:u=>{let B=i(u),p=n(B),k=o(p);return[...k.slice(0,3),k[3]??1]},fromBridge:u=>[...f(u),u[3]??1],format:([u,B,p,k=1],H={})=>{let{legacy:w=!1,fit:Z=te.defaults.fit,precision:G,units:z=!1}=H,oe=pe([u,B,p],e,{method:Z,precision:G}),W=Number(O(P(k,0),1).toFixed(3)).toString(),A=oe.map((v,J)=>{if(v=isNaN(v)?0:v,(z||w)&&a){let ce=Object.values(a).find(Q=>Q.index===J);if(ce?.value==="percentage")return`${v}%`;if(ce?.value==="hue"&&z)return`${v}deg`}return v.toString()});return e in ge?`color(${e} ${A.join(" ")}${k!==1?` / ${W}`:""})`:w&&h?k===1?`${e}(${A.join(", ")})`:`${l||e}(${A.join(", ")}, ${W})`:`${e}(${A.join(" ")}${k!==1?` / ${W}`:""})`}}}function fe(e,t){let{fromLinear:r=s=>s,toLinear:o=s=>s,toBridgeMatrix:n,fromBridgeMatrix:i}=t;return{supportsLegacy:!1,targetGamut:t.targetGamut===null?null:e,components:Object.fromEntries(t.components.map((s,a)=>[s,{index:a,value:[0,1],precision:5}])),bridge:t.bridge,toBridge:s=>de(n,s.map(a=>o(a))),fromBridge:s=>de(i,s).map(a=>r(a))}}var ye=1e-5,F={D50_to_D65:[[.955473421488075,-.02309845494876471,.06325924320057072],[-.0283697093338637,1.0099953980813041,.021041441191917323],[.012314014864481998,-.020507649298898964,1.330365926242124]],D65_to_d50:[[1.0479297925449969,.022946870601609652,-.05019226628920524],[.02962780877005599,.9904344267538799,-.017073799063418826],[-.009243040646204504,.015055191490298152,.7518742814281371]],SRGB_to_XYZD65:[[506752/1228815,87881/245763,12673/70218],[87098/409605,175762/245763,12673/175545],[7918/409605,87881/737289,1001167/1053270]],XYZD65_to_SRGB:[[12831/3959,-329/214,-1974/3959],[-851781/878810,1648619/878810,36519/878810],[705/12673,-2585/12673,705/667]],P3_to_XYZD65:[[608311/1250200,189793/714400,198249/1000160],[35783/156275,247089/357200,198249/2500400],[0/1,32229/714400,5220557/5000800]],XYZD65_to_P3:[[446124/178915,-333277/357830,-72051/178915],[-14852/17905,63121/35810,423/17905],[11844/330415,-50337/660830,316169/330415]],REC2020_to_XYZD65:[[63426534/99577255,20160776/139408157,47086771/278816314],[26158966/99577255,472592308/697040785,8267143/139408157],[0/1,19567812/697040785,295819943/278816314]],XYZD65_to_REC2020:[[30757411/17917100,-6372589/17917100,-4539589/17917100],[-19765991/29648200,47925759/29648200,467509/29648200],[792561/44930125,-1921689/44930125,42328811/44930125]],A98_to_XYZD65:[[573536/994567,263643/1420810,187206/994567],[591459/1989134,6239551/9945670,374412/4972835],[53769/1989134,351524/4972835,4929758/4972835]],ProPhoto_to_XYZD50:[[.7977666449006423,.13518129740053308,.0313477341283922],[.2880748288194013,.711835234241873,8993693872564e-17],[0,0,.8251046025104602]],XYZD50_to_ProPhoto:[[1.3457868816471583,-.25557208737979464,-.05110186497554526],[-.5446307051249019,1.5082477428451468,.02052744743642139],[0,0,1.2119675456389452]],XYZD65_to_A98:[[1829569/896150,-506331/896150,-308931/896150],[-851781/878810,1648619/878810,36519/878810],[16779/1248040,-147721/1248040,1266979/1248040]],LMS_to_XYZD65:[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],XYZD65_to_LMS:[[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],LMS_to_OKLAB:[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],OKLAB_to_LMS:[[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]]},Ge={linear:e=>e,"ease-in":e=>e*e,"ease-out":e=>e*(2-e),"ease-in-out":e=>e<.5?2*e*e:-1+(4-2*e)*e,"ease-in-cubic":e=>e*e*e,"ease-out-cubic":e=>--e*e*e+1,"ease-in-out-cubic":e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2},_e={"chroma-reduction":(e,t)=>{let r=new Y(t,e),{targetGamut:o}=T[t];if(o===null||(o===void 0&&(o="srgb"),r.inGamut(o,1e-5)))return e;let[n,,i]=r.in("oklch").toArray({fit:"none",precision:null}),s=Math.min(1,Math.max(0,n)),a=0,c=1,f=1e-6,d=[];for(;c-a>f;){let h=(a+c)/2,m=new Y("oklch",[s,h,i]);if(m.inGamut(o,1e-5))a=h;else{let x=pe(m.toArray({fit:"none",precision:null}).slice(0,3),t,{method:"clip"}),S=new Y(t,x);if(m.deltaEOK(S)<2)return d=x,d;c=h}}return d=new Y("oklch",[s,a,i]).in(t).toArray({fit:"none",precision:null}),d},"css-gamut-map":(e,t)=>{let{targetGamut:r}=T[t];if(r===null)return e;r===void 0&&(r="srgb");let o=new Y(t,e),[n,i,s]=o.in("oklch").toArray({fit:"none",precision:null});if(n>=1)return new Y("oklab",[1,0,0]).in(t).toArray({fit:"none",precision:null});if(n<=0)return new Y("oklab",[0,0,0]).in(t).toArray({fit:"none",precision:null});if(o.inGamut(r,1e-5))return e;let a=.02,c=1e-4,f=new Y("oklch",[n,i,s]),d=pe(f.in(t).toArray({fit:"none",precision:null}).slice(0,3),t,{method:"clip"}),l=new Y(t,d);if(f.deltaEOK(l)<a)return d;let m=0,x=i,S=!0;for(;x-m>c;){let N=(m+x)/2,j=new Y("oklch",[n,N,s]);if(S&&j.inGamut(r,1e-5))m=N;else{let C=pe(j.in(t).toArray({fit:"none",precision:null}).slice(0,3),t,{method:"clip"});d=C;let y=new Y(t,C),_=j.deltaEOK(y);if(_<a){if(a-_<c)return d;S=!1,m=N}else x=N}}return d}};function Ie(e){let t=e.map(r=>{let o=r/255,n=o<0?-1:1,i=Math.abs(o);return i<=.04045?o/12.92:n*((i+.055)/1.055)**2.4});return de(F.SRGB_to_XYZD65,t)}function Te(e){return de(F.XYZD65_to_SRGB,e).map(o=>{let n=o<0?-1:1,i=Math.abs(o);return i>.0031308?n*(1.055*i**(1/2.4)-.055):12.92*o}).map(o=>o*255)}function Le([e,t,r]){t/=100,r/=100;let o=n=>{let i=(n+e/30)%12,s=t*Math.min(r,1-r);return r-s*Math.max(-1,Math.min(i-3,9-i,1))};return[o(0)*255,o(8)*255,o(4)*255]}function Ze(e){let[t,r,o]=e.map(m=>m/255),n=Math.max(t,r,o),i=Math.min(t,r,o),s=(n+i)/2,a=n-i,c=NaN,f=0;a>0&&(f=a/(1-Math.abs(2*s-1)),c=n===t?(r-o)/a+(r<o?6:0):n===r?(o-t)/a+2:(t-r)/a+4,c=c*60%360);let d=f*100,l=s*100;return[l<=ye||100-l<=ye||d<=ye?NaN:c,d,l]}function ze([e,t,r]){if(t/=100,r/=100,t+r>=1){let n=t/(t+r)*255;return[n,n,n]}return Le([e,100,50]).map(n=>n/255).map(n=>(n*(1-t-r)+t)*255)}function De(e){let[t,r,o]=e.map(c=>c/255),n=Math.max(t,r,o),i=Math.min(t,r,o),s=n-i,a=NaN;return s>ye&&(a=n===t?(r-o)/s+(r<o?6:0):n===r?(o-t)/s+2:(t-r)/s+4,a=a*60%360),[a,i*100,(1-n)*100]}function Re([e,t,r]){let o=[.9642956764295677,1,.8251046025104602],n=24389/27,i=216/24389,s=(e+16)/116,a=t/500+s,c=s-r/200;return[a**3>i?a**3:(116*a-16)/n,e>n*i?s**3:e/n,c**3>i?c**3:(116*c-16)/n].map((d,l)=>d*o[l])}function Xe(e){let t=[.9642956764295677,1,.8251046025104602],r=24389/27,o=216/24389,n=e.map((c,f)=>c/t[f]),[i,s,a]=n.map(c=>c>o?Math.cbrt(c):(r*c+16)/116);return[116*s-16,500*(i-s),200*(s-a)]}function Ye([e,t,r]){return[e,t*Math.cos(r*Math.PI/180),t*Math.sin(r*Math.PI/180)]}function Pe([e,t,r]){let o=Math.hypot(t,r),n=Math.atan2(r,t)*180/Math.PI;return n<0&&(n+=360),[e,o,o<=ye?NaN:n]}function He(e){let{LMS_to_XYZD65:t,OKLAB_to_LMS:r}=F,o=de(r,e);return de(t,o.map(n=>n**3))}function qe(e){let{XYZD65_to_LMS:t,LMS_to_OKLAB:r}=F,o=de(t,e);return de(r,o.map(Math.cbrt))}function Fe([e,t,r]){return[e,t*Math.cos(r*Math.PI/180),t*Math.sin(r*Math.PI/180)]}function Ve([e,t,r]){let o=Math.hypot(t,r),n=Math.atan2(r,t)*180/Math.PI;return n<0&&(n+=360),[e,o,o<=ye?NaN:n]}var ve={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},ge={srgb:fe("srgb",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r<=.04045?t*(r/12.92):t*Math.pow((r+.055)/1.055,2.4)},fromLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r>.0031308?t*(1.055*Math.pow(r,1/2.4)-.055):t*(12.92*r)},toBridgeMatrix:F.SRGB_to_XYZD65,fromBridgeMatrix:F.XYZD65_to_SRGB}),"srgb-linear":fe("srgb-linear",{components:["r","g","b"],bridge:"xyz-d65",toBridgeMatrix:F.SRGB_to_XYZD65,fromBridgeMatrix:F.XYZD65_to_SRGB}),"display-p3":fe("display-p3",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r<=.04045?t*(r/12.92):t*Math.pow((r+.055)/1.055,2.4)},fromLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return r>.0031308?t*(1.055*Math.pow(r,1/2.4)-.055):t*(12.92*r)},toBridgeMatrix:F.P3_to_XYZD65,fromBridgeMatrix:F.XYZD65_to_P3}),rec2020:fe("rec2020",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=1.09929682680944,r=.018053968510807,o=e<0?-1:1,n=Math.abs(e);return n<r*4.5?o*(n/4.5):o*Math.pow((n+t-1)/t,1/.45)},fromLinear:e=>{let t=1.09929682680944,r=.018053968510807,o=e<0?-1:1,n=Math.abs(e);return n>r?o*(t*Math.pow(n,.45)-(t-1)):o*(4.5*n)},toBridgeMatrix:F.REC2020_to_XYZD65,fromBridgeMatrix:F.XYZD65_to_REC2020}),"a98-rgb":fe("a98-rgb",{components:["r","g","b"],bridge:"xyz-d65",toLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return t*Math.pow(r,563/256)},fromLinear:e=>{let t=e<0?-1:1,r=Math.abs(e);return t*Math.pow(r,256/563)},toBridgeMatrix:F.A98_to_XYZD65,fromBridgeMatrix:F.XYZD65_to_A98}),"prophoto-rgb":fe("prophoto-rgb",{components:["r","g","b"],bridge:"xyz-d50",toLinear:e=>{let r=e<0?-1:1,o=Math.abs(e);return o<=.03125?r*(o/16):r*Math.pow(o,1.8)},fromLinear:e=>{let t=.001953125,r=e<0?-1:1,o=Math.abs(e);return o>=t?r*Math.pow(o,1/1.8):r*(16*o)},toBridgeMatrix:F.ProPhoto_to_XYZD50,fromBridgeMatrix:F.XYZD50_to_ProPhoto}),"xyz-d65":fe("xyz-d65",{targetGamut:null,components:["x","y","z"],bridge:"xyz-d65",toBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]],fromBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]]}),"xyz-d50":fe("xyz-d50",{targetGamut:null,components:["x","y","z"],bridge:"xyz-d65",toBridgeMatrix:F.D50_to_D65,fromBridgeMatrix:F.D65_to_d50}),xyz:fe("xyz",{targetGamut:null,components:["x","y","z"],bridge:"xyz-d65",toBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]],fromBridgeMatrix:[[1,0,0],[0,1,0],[0,0,1]]})},T={rgb:{supportsLegacy:!0,alphaVariant:"rgba",components:{r:{index:0,value:[0,255],precision:0},g:{index:1,value:[0,255],precision:0},b:{index:2,value:[0,255],precision:0}},bridge:"xyz-d65",toBridge:Ie,fromBridge:Te},hsl:{supportsLegacy:!0,alphaVariant:"hsla",components:{h:{index:0,value:"hue",precision:0},s:{index:1,value:"percentage",precision:0},l:{index:2,value:"percentage",precision:0}},bridge:"rgb",toBridge:Le,fromBridge:Ze},hwb:{components:{h:{index:0,value:"hue",precision:0},w:{index:1,value:"percentage",precision:0},b:{index:2,value:"percentage",precision:0}},bridge:"rgb",toBridge:ze,fromBridge:De},lab:{targetGamut:null,components:{l:{index:0,value:"percentage",precision:5},a:{index:1,value:[-125,125],precision:5},b:{index:2,value:[-125,125],precision:5}},bridge:"xyz-d50",toBridge:Re,fromBridge:Xe},lch:{targetGamut:null,components:{l:{index:0,value:"percentage",precision:5},c:{index:1,value:[0,150],precision:5},h:{index:2,value:"hue",precision:5}},bridge:"lab",toBridge:Ye,fromBridge:Pe},oklab:{targetGamut:null,components:{l:{index:0,value:[0,1],precision:5},a:{index:1,value:[-.4,.4],precision:5},b:{index:2,value:[-.4,.4],precision:5}},bridge:"xyz-d65",toBridge:He,fromBridge:qe},oklch:{targetGamut:null,components:{l:{index:0,value:[0,1],precision:5},c:{index:1,value:[0,.4],precision:5},h:{index:2,value:"hue",precision:5}},bridge:"oklab",toBridge:Fe,fromBridge:Ve},...ge},$e=Object.fromEntries(Object.entries(T).map(([e,t])=>[e,je(e,t)])),ke={"hex-color":{isValid:e=>e[0]==="#",bridge:"rgb",toBridge:e=>e,parse:e=>{let t=e.slice(1);if(![3,4,6,8].includes(t.length))throw new Error("Invalid hex color length.");for(let a of t)if(!/^[0-9a-fA-F]$/.test(a))throw new Error("Invalid hex color character.");let r=a=>parseInt(a.length===1?a+a:a,16),[o,n,i,s=255]=t.length<=4?t.split("").map(r):[t.slice(0,2),t.slice(2,4),t.slice(4,6),t.slice(6,8)].map(a=>parseInt(a||"ff",16));return[o,n,i,s/255]},fromBridge:e=>e,format:([e,t,r,o=1])=>{let n=s=>s.toString(16).padStart(2,"0");return`#${[e,t,r].map(s=>n(Math.round(Math.max(0,Math.min(255,s))))).join("")}${o<1?n(Math.round(o*255)):""}`}},...$e,"named-color":{isValid:e=>Object.keys(ve).some(t=>t===e),bridge:"rgb",toBridge:e=>e,parse:e=>{let t=ve[e];if(!t)throw new Error(`Invalid named-color: ${e}.`);return[...t,1]},fromBridge:e=>e,format:e=>{let[t,r,o]=e.map((n,i)=>i<3?Math.round(Math.min(255,Math.max(0,n))):n);for(let[n,[i,s,a]]of Object.entries(ve))if(t===i&&r===s&&o===a)return n}},"color-mix":{isValid:e=>e.slice(0,10)==="color-mix("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t=y=>{let _=y.trim(),L,$=_,K=$.match(/^(\d+)%\s+/);if(K){let b=parseInt(K[1],10);L=Math.min(1,Math.max(0,b/100)),$=$.slice(K[0].length).trim()}let re="",X="";if(/^[a-z]/i.test($)){let{expression:b,end:M}=le($,0);if(b)re=b,X=$.slice(M).trim();else{let O=$.match(/^([^\s]+)(.*)$/);re=O?O[1]:$,X=O?O[2].trim():""}}else{let b=$.match(/^([^\s]+)(.*)$/);re=b?b[1]:$,X=b?b[2].trim():""}if(L===void 0){let b=X.match(/^(-?(?:\d+\.?\d*|\.\d+))%/);if(b){if(L=parseInt(b[1],10)/100,X=X.slice(b[0].length).trim(),L<0)throw new Error("Percentages less than 0 are not valid.");if(L>1)throw new Error("Percentages greater than 100 are not valid.")}else if(X.slice(0,5)==="calc("){let{expression:M,end:O}=le(X,0);if(!M)throw new Error("Malformed calc() weight expression.");X=X.slice(O).trim()}}if(X.length>0)throw new Error(`Unexpected extra tokens after color: '${X}'.`);return{color:Y.from(re),weight:L}},r=(y,_)=>{if(y===void 0&&typeof _=="number")y=1-_;else if(typeof y=="number"&&_===void 0)_=1-y;else if(y===void 0&&_===void 0)y=_=.5;else if(y=y,_=_,y+_<=0)throw new Error("Sum of percengates cannot be 0%.");let L=y+_,$;return L>1?(y/=L,_/=L):(y/=L,_/=L,$=L),{amount:_,alphaMultiplier:$}},o="color-mix",{expression:n}=le(e,o.length);if(!n)throw new Error("Malformed color-mix expression.");let i=n.slice(1,-1).trim(),s=[],a=0,c="";for(;a<i.length;){let y=i[a];if(y===","){s.push(c.trim()),c="",a++;continue}if(y==="("||/[a-zA-Z]/.test(y)){let{expression:_,end:L}=le(i,a);if(_){c+=_,a=L;continue}}c+=y,a++}if(s.push(c.trim()),s.length!==3)throw new Error("color-mix must have three comma-separated parts.");let d=s[0].match(/^in\s+([a-z0-9-]+)(?:\s+(shorter|longer|increasing|decreasing)\s+hue)?$/);if(!d)throw new Error("Invalid model and hue format.");let l=d[1],h=d[2];if(l==="rgb")throw new Error('RGB model is not allowed in color-mix(). Use "srgb" instead.');if(h){let y=T[l].components;if(!y)throw new Error(`Unknown color model: ${l}.`);if(!Object.values(y).some(L=>L.value==="hue"))throw new Error(`Hue interpolation not supported in ${l} space.`)}else h="shorter";let{color:m,weight:x}=t(s[1]),{color:S,weight:N}=t(s[2]),{amount:j,alphaMultiplier:C=1}=r(x,N);return m.with({alpha:y=>isNaN(y)?y:y*C},!1).in(l).mix(S.with({alpha:y=>isNaN(y)?y:y*C},!1),{amount:j,hue:h}).in("rgb").coords}},transparent:{isValid:e=>e==="transparent",bridge:"rgb",toBridge:e=>e,parse:e=>[NaN,NaN,NaN,0]}},he={...ke,currentColor:{isValid:e=>e==="currentcolor",bridge:"rgb",toBridge:e=>e,parse:e=>[0,0,0,1]},"system-color":{isValid:e=>Object.keys(te.systemColors).some(t=>t.toLowerCase()===e),bridge:"rgb",toBridge:e=>e,parse:e=>{let{systemColors:t}=te,r=Object.keys(t).find(n=>n.toLowerCase()===e);return[...t[r][te.theme==="light"?0:1],1]}},"contrast-color":{isValid:e=>e.slice(0,15)==="contrast-color("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t=e.slice(15,-1),[,r]=Y.from(t).in("xyz-d65").coords;return r>.5?[0,0,0,1]:[255,255,255,1]}},"device-cmyk":{isValid:e=>e.slice(0,12)==="device-cmyk("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t="device-cmyk",r=e.indexOf(t);if(r===-1)throw new Error("Invalid device-cmyk syntax");let{expression:o}=le(e,r+t.length);if(!o)throw new Error("Malformed device-cmyk expression");let n=o.slice(1,-1).trim(),i=[],s=0;for(;s<n.length;){let C=n[s];if(C===" "){s++;continue}if(C==="("||/[a-zA-Z-]/.test(C)){let{expression:y,end:_}=le(n,s);if(y){i.push(y),s=_;continue}}if(/[\d.+-]/.test(C)){let y="";for(;s<n.length&&/[\d.eE+-]/.test(n[s]);)y+=n[s],s++;if(s<n.length&&n[s]==="%")y+="%",s++;else if(s<n.length&&/[a-zA-Z]/.test(n[s]))for(;s<n.length&&/[a-zA-Z]/.test(n[s]);)y+=n[s],s++;i.push(y);continue}if(C===","||C==="/"){i.push(C),s++;continue}throw new Error(`Unexpected character: ${C}`)}let a=C=>C[C.length-1]==="%"?parseFloat(C)/100:parseFloat(C);if(i.length>=2&&i[1]===","){let C=i.filter(y=>y!==",");if(C.length===4||C.length===5){let[y,_,L,$,K=1]=C.map(a),re=1-Math.min(1,y*(1-$)+$),X=1-Math.min(1,_*(1-$)+$),se=1-Math.min(1,L*(1-$)+$);return[re*255,X*255,se*255,K]}throw new Error("Invalid number of components for comma-separated device-cmyk")}let c=0,f=[];for(;c<i.length&&f.length<4&&i[c]!=="/"&&i[c]!==",";)f.push(i[c]),c++;if(f.length!==4)throw new Error("Invalid number of components for space-separated device-cmyk");let[d,l,h,m]=f.map(a),x=1;if(c<i.length&&i[c]==="/"){if(c++,c>=i.length)throw new Error("Missing alpha value");x=a(i[c]),c++}if(c<i.length&&i[c]===","){c++;let C=i.slice(c).join(" ");return Y.from(C).in("rgb").coords}let S=1-Math.min(1,d*(1-m)+m),N=1-Math.min(1,l*(1-m)+m),j=1-Math.min(1,h*(1-m)+m);return[S*255,N*255,j*255,x]},fromBridge:e=>e,format:([e,t,r,o=1],n={})=>{let{legacy:i=!1,precision:s=3,fit:a=te.defaults.fit}=n,[c,f,d]=pe([e,t,r],"rgb",{method:a}),l=c/255,h=f/255,m=d/255,x=1-Math.max(l,h,m),S=$=>Number(s===null?$:$.toFixed(s)).toString(),N=S(x===1?0:(1-l-x)/(1-x)),j=S(x===1?0:(1-h-x)/(1-x)),C=S(x===1?0:(1-m-x)/(1-x)),y=S(x),_=Number(o.toFixed(3)).toString();if(i)return`device-cmyk(${N}, ${j}, ${C}, ${y}${o<1?`, ${_}`:""})`;let L=$e.rgb.format?.([c,f,d,o],n);return`device-cmyk(${N} ${j} ${C} ${y}${o<1?` / ${_}`:""}, ${L})`}},"light-dark":{isValid:e=>e.slice(0,11)==="light-dark("&&e[e.length-1]===")",bridge:"rgb",toBridge:e=>e,parse:e=>{let t="light-dark",r=e.indexOf(t);if(r===-1)throw new Error("Not a <light-dark()> expression");let{expression:o}=le(e,r+t.length);if(!o)throw new Error("Malformed <light-dark()> expression");let n=o.slice(1,-1).trim(),i=[],s="",a=0;for(;a<n.length;){let l=n[a];if(l===","){i.push(s.trim()),s="",a++;continue}if(l==="("||/[a-zA-Z]/.test(l)){let{expression:h,end:m}=le(n,a);if(h){s+=h,a=m;continue}}s+=l,a++}if(i.push(s.trim()),i.length!==2)throw new Error("Invalid light-dark format");let[c,f]=i,{theme:d}=te;return Y.from(d==="light"?c:f).coords}}};var Y=class e{model;coords;constructor(t,r=[0,0,0,0]){if(!(t in T))throw new Error(`Unsupported color model: '${t}'`);if([3,4].includes(r.length)===!1)throw new Error("Coordinates array must have 3 or 4 elements.");let o=r.slice();o.length===3&&o.push(1),this.model=t,this.coords=o}static from(t){let r=Me(t);for(let o in he){let n=o,{parse:i,bridge:s,toBridge:a,isValid:c}=he[n];if(!c(r))continue;let f=i(r),d=n in T?f:a(f),l=n in T?n:s;return new e(l,d)}throw new Error(`Unsupported or invalid color format: '${t}'.`)}static type(t,r=!1){let o=Me(t);for(let n in he){let i=n,{isValid:s,bridge:a,parse:c,toBridge:f}=he[i];if(s(o)){if(!r)return i;try{let d=c(o),l=i in T?d:f(d),h=n in T?n:a;return typeof new e(h,l)=="object"?i:void 0}catch{return}}}}static isValid(t,r){try{if(r){let o=r?.trim().toLowerCase(),n=Me(t),{isValid:i,bridge:s,parse:a,toBridge:c}=he[o];if(!i(n))return!1;let f=a(n),d=o in T?f:c(f),l=o in T?o:s;return!!new e(l,d)}return!!e.from(t)}catch{return!1}}static random(t={}){let r=Object.keys(T),o=t.model??r[Math.floor(Math.random()*r.length)],{components:n}=T[o],i=new Set([...Object.keys(n),"alpha"]);for(let a of["limits","bias","base","deviation"]){let c=t[a];if(c){for(let f of Object.keys(c))if(!i.has(f))throw new Error(`Invalid component "${f}" for model "${o}". Valid components: ${[...i].join(", ")}`)}}let s=[];for(let[a,c]of Object.entries(n)){let f=t.base?.[a],d=t.deviation?.[a],l;if(f!=null&&d!=null){let h=Math.random()||1e-9,m=Math.random()||1e-9;l=f+Math.sqrt(-2*Math.log(h))*Math.cos(2*Math.PI*m)*d}else{let[h,m]=c.value==="hue"?[0,360]:c.value==="percentage"?[0,100]:c.value,x=t.limits?.[a];if(x){let[j,C]=x;h=Math.max(h,j),m=Math.min(m,C)}let S=Math.random(),N=t.bias?.[a];N&&(S=N(S)),l=h+S*(m-h)}if(c.value==="hue")l=(l%360+360)%360;else if(c.value==="percentage")l=Math.min(100,Math.max(0,l));else if(Array.isArray(c.value)){let[h,m]=c.value;l=Math.min(m,Math.max(h,l))}else throw new Error(`Invalid component value definition for "${a}".`);s[c.index]=l}return new e(o,s)}to(t,r={}){let o=t.toLowerCase(),{legacy:n=!1,fit:i=te.defaults.fit,precision:s,units:a=!1}=r,c=he[o];if(!c)throw new Error(`Unsupported color type: '${o}'.`);let{fromBridge:f,bridge:d,format:l}=c;if(!f||!l)throw new Error(`Invalid output type: '${o}'.`);let h=m=>l(m,{legacy:n,fit:i,precision:s,units:a});return o===this.model?h(this.coords):o in T?h(this.in(o).toArray({fit:"none",precision:null})):h(f(this.in(d).toArray({fit:"none",precision:null})))}in(t){let r=this.model,o=t.trim().toLowerCase();if(o===r)return new e(o,[...this.coords]);let n=we.get("graph"),i=we.get("paths");if(!n){n={};for(let[f,d]of Object.entries(T)){let{bridge:l}=d;n[f]=[...n[f]||[],l],n[l]=[...n[l]||[],f]}we.set("graph",n)}i||(i=new Map,we.set("paths",i));let s=`${r}-${o}`;if(!i.has(s)){let f=[r],d={[r]:null};for(let h=0;h<f.length;h++){let m=f[h];if(m===o)break;for(let x of n[m]||[])x in d||(d[x]=m,f.push(x))}let l=[];for(let h=o;h;h=d[h])l.push(h);if(l.reverse(),!l.length||l[0]!==r)throw new Error(`Cannot convert from ${r} to ${o}. No path found.`);i.set(s,l)}let a=[...this.coords.map(f=>isNaN(f)?0:f)],c=i.get(s);for(let f=0;f<c.length-1;f++){let d=c[f],l=c[f+1],h=T[d],m=T[l];if(h.toBridge&&h.bridge===l)a=h.toBridge(a);else if(m.fromBridge&&m.bridge===d)a=m.fromBridge(a);else throw new Error(`No conversion found between ${d} and ${l}.`)}return new e(o,[...a.slice(0,3),this.coords[3]??1])}toString(t={}){let{format:r}=he[this.model],{legacy:o=!1,fit:n=te.defaults.fit,precision:i,units:s=!1}=t;return r?.(this.coords,{legacy:o,fit:n,precision:i,units:s})}toObject(t={}){let r=this.toArray(t),{components:o}=T[this.model];if(!o)throw new Error(`Model ${this.model} does not have defined components.`);let n={...o,alpha:{index:3,value:[0,1],precision:3}},i={};for(let[s,{index:a}]of Object.entries(n))i[s]=r[a];return i}toArray(t={}){let{fit:r=te.defaults.fit,precision:o}=t,{model:n,coords:i}=this,{components:s}=T[n];if(!s)throw new Error(`Model ${n} does not have defined components.`);let a={...s,alpha:{index:3,value:[0,1],precision:3}},c=(l,h)=>{let m=Object.values(a)[h]?.value,[x,S]=Array.isArray(m)?m:m==="hue"?[0,360]:[0,100];return Number.isNaN(l)?0:l===1/0?S:l===-1/0?x:typeof l=="number"?l:0},f=i.slice(0,3).map(c);return[...pe(f,n,{method:r,precision:o}),i[3]]}with(t,r=!0){let o=l=>Array.isArray(l)?l:l==="hue"?[0,360]:[0,100],n=(l,h)=>{if(r===!1)return l;let[m,x]=o(h);return Number.isNaN(l)?0:l===1/0?x:l===-1/0?m:l},{model:i}=this,s=this.coords.slice(),a={...T[i].components,alpha:{index:3,value:[0,1],precision:3}},c=Object.keys(a),f=typeof t=="function"?t(Object.fromEntries(c.map(l=>{let h=a[l];return[l,n(s[h.index],h.value)]}))):t;if(Array.isArray(f)){let l=s.map((h,m)=>{let x=f[m];if(typeof x!="number")return h;let S=Object.values(a).find(N=>N.index===m);return n(x,S.value)});return new e(i,[...l.slice(0,3),s[3]??1])}let d=[...s];for(let l of c){if(!(l in f))continue;let{index:h,value:m}=a[l],x=f[l],S=n(s[h],m),N=typeof x=="function"?n(x(S),m):typeof x=="number"?n(x,m):s[h];d[h]=N}return new e(i,[...d.slice(0,3),d[3]??s[3]])}mix(t,r={}){let{model:o}=this,n=this.coords.slice(),i=(typeof t=="string"?e.from(t):t).in(o).coords.slice(),{components:s}=T[o];if(!s)throw new Error(`Model ${o} does not have defined components.`);let a={...s,alpha:{index:3,value:[0,1],precision:3}},c=b=>Array.isArray(b)?b:b==="hue"?[0,360]:[0,100],f=(b,M,O)=>{let[P,U]=c(O),ae=me=>me===1/0?U:me===-1/0?P:me;b=ae(b),M=ae(M);let ne=Number.isNaN(b),V=Number.isNaN(M);return ne&&V?{a:0,b:0}:ne?{a:M,b:M}:V?{a:b,b}:{a:b,b:M,ok:!0}},d=a.h?.index??-1;for(let b in a){let{index:M,value:O}=a[b];if(M>3)continue;let P=f(n[M],i[M],O);if(P.ok){let[U,ae]=c(O),ne=V=>V===1/0?ae:V===-1/0?U:V;n[M]=ne(n[M]),i[M]=ne(i[M])}else n[M]=P.a,i[M]=P.b}let{hue:l="shorter",amount:h=.5,easing:m="linear",gamma:x=1}=r,N=(typeof m=="function"?m:Ge[m])(Math.min(1,Math.max(0,h))),j=Math.pow(N,1/x),C=b=>(b%360+360)%360,y=(b,M)=>{let O=C(M-b);return O>180?O-360:O},_=(b,M)=>y(b,M)>=0?y(b,M)-360:y(b,M)+360,L=(b,M,O,P)=>{switch(P){case"shorter":return C(b+O*y(b,M));case"longer":return C(b+O*_(b,M));case"increasing":return C(b*(1-O)+(M<b?M+360:M)*O);case"decreasing":return C(b*(1-O)+(M>b?M-360:M)*O)}throw new Error(`Invalid hue interpolation: ${P}`)};if(j===0)return new e(o,[...n]);if(j===1)return new e(o,[...i]);let $=n[3],K=i[3],re=n.slice(0,3),X=i.slice(0,3);if($<1||K<1){let b=re.map((P,U)=>{let ae=X[U];return U===d?L(P,ae,j,l):P*$*(1-j)+ae*K*j}),M=$*(1-j)+K*j,O=M>0?b.map((P,U)=>U===d?P:P/M):re.map((P,U)=>U===d?b[U]:0);return new e(o,[...O,M])}let se=re.map((b,M)=>M===d?L(b,X[M],j,l):b+(X[M]-b)*j);return new e(o,[...se,1])}within(t,r=te.defaults.fit){let o=t.trim().toLowerCase();if(!(o in ge))throw new Error(`Unsupported color gamut: '${o}'.`);let n=this.in(o).toArray({fit:r,precision:null});return new e(o,n).in(this.model)}fit(t={}){let{fit:r=te.defaults.fit,precision:o}=t,n=this.toArray({fit:r,precision:o});return new e(this.model,n)}contrast(t){let r=typeof t=="string"?e.from(t):t,[,o]=this.in("xyz-d65").toArray({fit:"none",precision:null}),[,n]=r.in("xyz-d65").toArray({fit:"none",precision:null});return(Math.max(o,n)+.05)/(Math.min(o,n)+.05)}deltaEOK(t){let r={fit:"none",precision:null},[o,n,i]=this.in("oklab").toArray(r),[s,a,c]=(typeof t=="string"?e.from(t):t).in("oklab").toArray(r),f=o-s,d=n-a,l=i-c;return Math.sqrt(f**2+d**2+l**2)*100}deltaE76(t){let r={fit:"none",precision:null},[o,n,i]=this.in("lab").toArray(r),[s,a,c]=(typeof t=="string"?e.from(t):t).in("lab").toArray(r),f=o-s,d=n-a,l=i-c;return Math.hypot(f,d,l)}deltaE94(t){let r={fit:"none",precision:null},[o,n,i]=this.in("lab").toArray(r),[s,a,c]=(typeof t=="string"?e.from(t):t).in("lab").toArray(r),f=o-s,d=n-a,l=i-c,h=Math.sqrt(n*n+i*i),m=Math.sqrt(a*a+c*c),x=h-m,S=Math.sqrt(Math.max(0,d*d+l*l-x*x)),N=1,j=1,C=1,y=.045,_=.015,L=1+y*h,$=1+_*h;return Math.sqrt((f/N)**2+(x/(j*L))**2+(S/(C*$))**2)}deltaE2000(t){let r={fit:"none",precision:null},[o,n,i]=this.in("lab").toArray(r),[s,a,c]=(typeof t=="string"?e.from(t):t).in("lab").toArray(r),f=Math.PI,d=f/180,l=180/f,h=Math.sqrt(n**2+i**2),m=Math.sqrt(a**2+c**2),x=(h+m)/2,S=Math.pow(25,7),N=Math.pow(x,7),j=.5*(1-Math.sqrt(N/(N+S))),C=(1+j)*n,y=(1+j)*a,_=Math.sqrt(C**2+i**2),L=Math.sqrt(y**2+c**2),$=Math.atan2(i,C),K=Math.atan2(c,y);$<0&&($+=2*f),K<0&&(K+=2*f),$*=l,K*=l;let re=s-o,X=L-_,se=K-$,b=Math.abs(se),M=0;_*L!==0&&(b<=180?M=se:se>180?M=se-360:M=se+360);let O=2*Math.sqrt(_*L)*Math.sin(M*d/2),P=(o+s)/2,U=(_+L)/2,ae=Math.pow(U,7),ne=$+K,V=0;_===0&&L===0?V=ne:b<=180?V=ne/2:ne<360?V=(ne+360)/2:V=(ne-360)/2;let me=(P-50)**2,Ee=1+.015*me/Math.sqrt(20+me),be=1+.045*U,u=1;u-=.17*Math.cos((V-30)*d),u+=.24*Math.cos(2*V*d),u+=.32*Math.cos((3*V+6)*d),u-=.2*Math.cos((4*V-63)*d);let B=1+.015*U*u,p=30*Math.exp(-1*((V-275)/25)**2),k=2*Math.sqrt(ae/(ae+S)),H=-1*Math.sin(2*p*d)*k,w=(re/Ee)**2;return w+=(X/be)**2,w+=(O/B)**2,w+=H*(X/be)*(O/B),Math.sqrt(w)}equals(t,r=1e-5){let o=typeof t=="string"?e.from(t):t,n=this.toArray({fit:"none",precision:null}),i=o.toArray({fit:"none",precision:null});if(o.model===this.model)return n.every((c,f)=>Math.abs(c-i[f])<=r);let s=this.in("xyz-d65").toArray({fit:"none",precision:null}),a=o.in("xyz-d65").toArray({fit:"none",precision:null});return s.every((c,f)=>Math.abs(c-a[f])<=r)}inGamut(t,r=1e-5){let o=t.trim().toLowerCase();if(!(o in ge))throw new Error(`Unsupported color gamut: '${o}'.`);let{components:n,targetGamut:i}=T[o];if(!i)return!0;let s=this.in(o).toArray({fit:"none",precision:null});return Object.values(n).every(({index:a,value:c})=>{let f=s[a],[d,l]=Array.isArray(c)?c:c==="hue"?[0,360]:[0,100];return f>=d-r&&f<=l+r})}};return rt(nt);})();
|
package/dist/math.d.ts
CHANGED
package/dist/math.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Color } from "./Color.js";
|
|
2
2
|
import { colorModels } from "./converters.js";
|
|
3
3
|
import { multiplyMatrices, fit } from "./utils.js";
|
|
4
|
+
export const EPSILON = 1e-5;
|
|
4
5
|
/**
|
|
5
6
|
* A collection of commonly used color space conversion matrices.
|
|
6
7
|
*
|
|
@@ -256,14 +257,16 @@ export function RGB_to_HSL(rgb) {
|
|
|
256
257
|
const [r, g, b] = rgb.map((v) => v / 255);
|
|
257
258
|
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
258
259
|
const L = (max + min) / 2;
|
|
259
|
-
let H = 0, S = 0;
|
|
260
260
|
const d = max - min;
|
|
261
|
-
|
|
261
|
+
let H = NaN, S = 0;
|
|
262
|
+
if (d > 0) {
|
|
262
263
|
S = d / (1 - Math.abs(2 * L - 1));
|
|
263
264
|
H = max === r ? (g - b) / d + (g < b ? 6 : 0) : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
|
|
264
|
-
H
|
|
265
|
+
H = (H * 60) % 360;
|
|
265
266
|
}
|
|
266
|
-
|
|
267
|
+
const S_out = S * 100, L_out = L * 100;
|
|
268
|
+
const invalid = L_out <= EPSILON || 100 - L_out <= EPSILON || S_out <= EPSILON;
|
|
269
|
+
return [invalid ? NaN : H, S_out, L_out];
|
|
267
270
|
}
|
|
268
271
|
/**
|
|
269
272
|
* Converts HWB to RGB.
|
|
@@ -290,11 +293,9 @@ export function HWB_to_RGB([h, w, b]) {
|
|
|
290
293
|
export function RGB_to_HWB(rgb) {
|
|
291
294
|
const [r, g, b] = rgb.map((v) => v / 255);
|
|
292
295
|
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
293
|
-
let H = 0;
|
|
294
296
|
const d = max - min;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
else {
|
|
297
|
+
let H = NaN;
|
|
298
|
+
if (d > EPSILON) {
|
|
298
299
|
H = max === r ? (g - b) / d + (g < b ? 6 : 0) : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
|
|
299
300
|
H = (H * 60) % 360;
|
|
300
301
|
}
|
|
@@ -350,7 +351,7 @@ export function LAB_to_LCH([L, a, b]) {
|
|
|
350
351
|
let H = (Math.atan2(b, a) * 180) / Math.PI;
|
|
351
352
|
if (H < 0)
|
|
352
353
|
H += 360;
|
|
353
|
-
return [L, C, H];
|
|
354
|
+
return [L, C, C <= EPSILON ? NaN : H];
|
|
354
355
|
}
|
|
355
356
|
/**
|
|
356
357
|
* Converts OKLab to XYZ (D65).
|
|
@@ -394,5 +395,5 @@ export function OKLAB_to_OKLCH([L, a, b]) {
|
|
|
394
395
|
let H = (Math.atan2(b, a) * 180) / Math.PI;
|
|
395
396
|
if (H < 0)
|
|
396
397
|
H += 360;
|
|
397
|
-
return [L, C, H];
|
|
398
|
+
return [L, C, C <= EPSILON ? NaN : H];
|
|
398
399
|
}
|
package/dist/temp.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/temp.js
ADDED
package/dist/types.d.ts
CHANGED
|
@@ -142,8 +142,8 @@ export type ColorSpaceConverter = {
|
|
|
142
142
|
export type ComponentDefinition = {
|
|
143
143
|
/** Position of the component in the color array */
|
|
144
144
|
index: number;
|
|
145
|
-
/** The value type for the component, which can be a tuple of two numbers representing a range, or a string indicating a special type ("
|
|
146
|
-
value: number[] | "
|
|
145
|
+
/** The value type for the component, which can be a tuple of two numbers representing a range, or a string indicating a special type ("hue" or "percentage"). */
|
|
146
|
+
value: number[] | "hue" | "percentage";
|
|
147
147
|
/** Precision for rounding the component value, or `null` to disable rounding. Defaults to 3 if left undefined. */
|
|
148
148
|
precision?: number | null;
|
|
149
149
|
};
|
|
@@ -162,14 +162,14 @@ export type FitFunction = (coords: number[], model: ColorFunction) => number[];
|
|
|
162
162
|
/** Describes the available methods for fitting the color into the target gamut. */
|
|
163
163
|
export type FitMethod = keyof typeof fitMethods | "clip" | "none";
|
|
164
164
|
/** Represents options for retrieving the coordinates. */
|
|
165
|
-
export type
|
|
165
|
+
export type ComponentOptions = {
|
|
166
166
|
/** Method for fitting the color into the target gamut. Defaults to `config.defaults.fit`. */
|
|
167
167
|
fit?: FitMethod;
|
|
168
168
|
/** Overrides the auto precision of the output color components, or `null` to disable rounding. */
|
|
169
169
|
precision?: number | null;
|
|
170
170
|
};
|
|
171
171
|
/** Options for formatting color output. */
|
|
172
|
-
export type FormattingOptions =
|
|
172
|
+
export type FormattingOptions = ComponentOptions & {
|
|
173
173
|
/** Use legacy syntax (e.g., `"rgba(255, 0, 0, 0.5)"`). */
|
|
174
174
|
legacy?: boolean;
|
|
175
175
|
/** Output components with optional unit suffixes (e.g., `"hsl(250deg 74% 54%)"`). */
|
package/dist/utils.js
CHANGED
|
@@ -168,6 +168,7 @@ export function registerColorType(name, converter) {
|
|
|
168
168
|
}
|
|
169
169
|
types[n] = converter;
|
|
170
170
|
cache.delete("graph");
|
|
171
|
+
cache.delete("paths");
|
|
171
172
|
}
|
|
172
173
|
/**
|
|
173
174
|
* Registers a new `<color-base>` converter under the specified name.
|
|
@@ -214,6 +215,7 @@ export function registerColorBase(name, converter) {
|
|
|
214
215
|
bases[n] = converter;
|
|
215
216
|
types[n] = converter;
|
|
216
217
|
cache.delete("graph");
|
|
218
|
+
cache.delete("paths");
|
|
217
219
|
}
|
|
218
220
|
/**
|
|
219
221
|
* Registers a new `<color-function>` converter under the specified name.
|
|
@@ -279,6 +281,7 @@ export function registerColorFunction(name, converter) {
|
|
|
279
281
|
functions[n] = colorConv;
|
|
280
282
|
types[n] = colorConv;
|
|
281
283
|
cache.delete("graph");
|
|
284
|
+
cache.delete("paths");
|
|
282
285
|
}
|
|
283
286
|
/**
|
|
284
287
|
* Registers a new color space converter for `<color()>` function under the specified name.
|
|
@@ -335,6 +338,7 @@ export function registerColorSpace(name, converter) {
|
|
|
335
338
|
functions[n] = colorConv;
|
|
336
339
|
types[n] = colorConv;
|
|
337
340
|
cache.delete("graph");
|
|
341
|
+
cache.delete("paths");
|
|
338
342
|
}
|
|
339
343
|
/**
|
|
340
344
|
* Registers a new `<named-color>` with the specified RGB value.
|
|
@@ -463,11 +467,11 @@ export function fit(coords, model, options = {}) {
|
|
|
463
467
|
clipped = coords;
|
|
464
468
|
}
|
|
465
469
|
else if (method === "clip") {
|
|
466
|
-
clipped = coords.
|
|
470
|
+
clipped = coords.map((v, i) => {
|
|
467
471
|
const prop = componentProps[i];
|
|
468
472
|
if (!prop)
|
|
469
473
|
throw new Error(`Missing component properties for index ${i}.`);
|
|
470
|
-
if (prop.value === "
|
|
474
|
+
if (prop.value === "hue")
|
|
471
475
|
return ((v % 360) + 360) % 360;
|
|
472
476
|
const [min, max] = Array.isArray(prop.value) ? prop.value : [0, 100];
|
|
473
477
|
return Math.min(max, Math.max(min, v));
|
|
@@ -480,7 +484,7 @@ export function fit(coords, model, options = {}) {
|
|
|
480
484
|
}
|
|
481
485
|
clipped = fn(coords, model);
|
|
482
486
|
}
|
|
483
|
-
return clipped.
|
|
487
|
+
return clipped.map((v, i) => {
|
|
484
488
|
let p;
|
|
485
489
|
if (typeof precision === "number" || precision === null)
|
|
486
490
|
p = precision;
|
|
@@ -510,10 +514,10 @@ export function modelConverterToColorConverter(name, converter) {
|
|
|
510
514
|
return ((percent / 100) * (max - min)) / 2;
|
|
511
515
|
return (percent / 100) * (max - min) + min;
|
|
512
516
|
};
|
|
513
|
-
const
|
|
517
|
+
const parseHue = (token) => {
|
|
514
518
|
const value = parseFloat(token);
|
|
515
519
|
if (isNaN(value))
|
|
516
|
-
throw new Error(`Invalid
|
|
520
|
+
throw new Error(`Invalid hue value: '${token}'.`);
|
|
517
521
|
if (token.slice(-3) === "deg")
|
|
518
522
|
return value;
|
|
519
523
|
if (token.slice(-3) === "rad")
|
|
@@ -710,21 +714,21 @@ export function modelConverterToColorConverter(name, converter) {
|
|
|
710
714
|
};
|
|
711
715
|
let inner = token.slice(5, -1).trim();
|
|
712
716
|
if (inner === "infinity")
|
|
713
|
-
return
|
|
717
|
+
return Infinity;
|
|
714
718
|
if (inner === "-infinity")
|
|
715
|
-
return
|
|
719
|
+
return -Infinity;
|
|
716
720
|
if (inner === "NaN")
|
|
717
|
-
return
|
|
721
|
+
return NaN;
|
|
718
722
|
inner = inner.replace(/(\d+(\.\d+)?)%/g, (m) => {
|
|
719
723
|
if (relative === true)
|
|
720
|
-
throw new Error("<
|
|
724
|
+
throw new Error("<hue> and <percentage> values are converted to <number> in relative syntax.");
|
|
721
725
|
const r = parsePercent(m, _min, _max);
|
|
722
726
|
return r !== undefined ? String(r) : "0";
|
|
723
727
|
});
|
|
724
728
|
inner = inner.replace(/(\d+(\.\d+)?)(deg|rad|grad|turn)/g, (_, num, __, unit) => {
|
|
725
729
|
if (relative === true)
|
|
726
|
-
throw new Error("<
|
|
727
|
-
return String(
|
|
730
|
+
throw new Error("<hue> and <percentage> values are converted to <number> in relative syntax.");
|
|
731
|
+
return String(parseHue(`${parseFloat(num)}${unit}`));
|
|
728
732
|
});
|
|
729
733
|
const caclEnv = {
|
|
730
734
|
...base,
|
|
@@ -765,27 +769,18 @@ export function modelConverterToColorConverter(name, converter) {
|
|
|
765
769
|
throw new Error(`Evaluation error: ${err}`);
|
|
766
770
|
}
|
|
767
771
|
};
|
|
768
|
-
const
|
|
772
|
+
const evaluateHue = () => {
|
|
769
773
|
if (/^-?(?:\d+|\d*\.\d+)(?:deg|rad|grad|turn)$/.test(token)) {
|
|
770
|
-
return
|
|
774
|
+
return parseHue(token);
|
|
771
775
|
}
|
|
772
776
|
if (/^-?(?:\d+|\d*\.\d+)$/.test(token)) {
|
|
773
777
|
return parseFloat(token);
|
|
774
778
|
}
|
|
775
779
|
const [min, max] = [0, 360];
|
|
776
|
-
if (token[token.length - 1] === "%") {
|
|
777
|
-
if (commaSeparated && supportsLegacy === true) {
|
|
778
|
-
throw new Error("The legacy color syntax does not allow percentages for <angle> components.");
|
|
779
|
-
}
|
|
780
|
-
if (relative === true) {
|
|
781
|
-
throw new Error("The relative color syntax doesn't allow percentages for <angle> components.");
|
|
782
|
-
}
|
|
783
|
-
return parsePercent(token, min, max);
|
|
784
|
-
}
|
|
785
780
|
if (token.slice(0, 5) === "calc(") {
|
|
786
781
|
return parseCalc(token, min, max);
|
|
787
782
|
}
|
|
788
|
-
throw new Error(`Invalid
|
|
783
|
+
throw new Error(`Invalid hue value: '${token}'. Must be a number, or a number with a unit (deg, rad, grad, turn).`);
|
|
789
784
|
};
|
|
790
785
|
const evaluatePercent = () => {
|
|
791
786
|
if (/^-?(?:\d+|\d*\.\d+)$/.test(token)) {
|
|
@@ -817,11 +812,11 @@ export function modelConverterToColorConverter(name, converter) {
|
|
|
817
812
|
throw new Error(`Invalid number value: '${token}'. Must be a number${relative === false ? " or a percentage" : ""}.`);
|
|
818
813
|
};
|
|
819
814
|
if (token === "none")
|
|
820
|
-
return
|
|
815
|
+
return NaN;
|
|
821
816
|
if (token in base)
|
|
822
817
|
return base[token];
|
|
823
|
-
if (value === "
|
|
824
|
-
return
|
|
818
|
+
if (value === "hue")
|
|
819
|
+
return evaluateHue();
|
|
825
820
|
if (value === "percentage")
|
|
826
821
|
return evaluatePercent();
|
|
827
822
|
if (Array.isArray(value))
|
|
@@ -872,7 +867,7 @@ export function modelConverterToColorConverter(name, converter) {
|
|
|
872
867
|
throw new Error(`${fn}() cannot use "none" in comma-separated syntax.`);
|
|
873
868
|
}
|
|
874
869
|
if (meta.index !== 3 &&
|
|
875
|
-
meta.value !== "
|
|
870
|
+
meta.value !== "hue" &&
|
|
876
871
|
meta.value !== "percentage" &&
|
|
877
872
|
token.slice(0, 5) !== "calc(") {
|
|
878
873
|
percentFlags.push(token.trim()[token.length - 1] === "%");
|
|
@@ -1144,8 +1139,8 @@ export function modelConverterToColorConverter(name, converter) {
|
|
|
1144
1139
|
parse: (str) => {
|
|
1145
1140
|
const tokens = tokenize(str);
|
|
1146
1141
|
const ast = getAST(tokens);
|
|
1147
|
-
const
|
|
1148
|
-
return [...
|
|
1142
|
+
const coords = parseAST(ast);
|
|
1143
|
+
return [...coords.slice(0, 3), coords[3] ?? 1];
|
|
1149
1144
|
},
|
|
1150
1145
|
fromBridge: (coords) => [...fromBridge(coords), coords[3] ?? 1],
|
|
1151
1146
|
format: ([c1, c2, c3, a = 1], options = {}) => {
|
|
@@ -1153,11 +1148,12 @@ export function modelConverterToColorConverter(name, converter) {
|
|
|
1153
1148
|
const clipped = fit([c1, c2, c3], name, { method: fitMethod, precision });
|
|
1154
1149
|
const alpha = Number(min(max(a, 0), 1).toFixed(3)).toString();
|
|
1155
1150
|
const formatted = clipped.map((v, index) => {
|
|
1151
|
+
v = isNaN(v) ? 0 : v;
|
|
1156
1152
|
if ((units || legacy) && components) {
|
|
1157
1153
|
const def = Object.values(components).find((comp) => comp.index === index);
|
|
1158
1154
|
if (def?.value === "percentage")
|
|
1159
1155
|
return `${v}%`;
|
|
1160
|
-
if (def?.value === "
|
|
1156
|
+
if (def?.value === "hue" && units)
|
|
1161
1157
|
return `${v}deg`;
|
|
1162
1158
|
}
|
|
1163
1159
|
return v.toString();
|