better-color-tools
Advanced tools
Comparing version 0.12.2 to 0.12.3
# better-color-tools | ||
## 0.12.3 | ||
### Patch Changes | ||
- ce14b61: Fix package types | ||
## 0.12.2 | ||
@@ -4,0 +10,0 @@ |
@@ -6,3 +6,4 @@ export type { AdjustOptions } from './adjust.js'; | ||
export { default as adjust } from './adjust.js'; | ||
export { contrastRatio, darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
export { contrastRatio } from './contrast.js'; | ||
export { darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
export { mix } from './mix.js'; | ||
@@ -12,3 +13,4 @@ export { from } from './parse.js'; | ||
import adjust from './adjust.js'; | ||
import { contrastRatio, darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
import { contrastRatio } from './contrast.js'; | ||
import { darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
import { mix } from './mix.js'; | ||
@@ -15,0 +17,0 @@ import { from } from './parse.js'; |
export { default as adjust } from './adjust.js'; | ||
export { contrastRatio, darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
export { contrastRatio } from './contrast.js'; | ||
export { darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
export { mix } from './mix.js'; | ||
@@ -7,3 +8,4 @@ export { from } from './parse.js'; | ||
import adjust from './adjust.js'; | ||
import { contrastRatio, darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
import { contrastRatio } from './contrast.js'; | ||
import { darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
import { mix } from './mix.js'; | ||
@@ -10,0 +12,0 @@ import { from } from './parse.js'; |
@@ -1,1 +0,1 @@ | ||
function z(r,t=2){let e=r;for(;e.length<t;)e=`0${e}`;return e}function J(r){return r*(Math.PI/180)}function Q(r){return r*(180/Math.PI)}function i(r,t,e){return Math.min(Math.max(r,t),e)}function B(r,t){let[e,n,o,l]=t,a=l<1?`/${k(l,5)}`:"";switch(r){case"rgb":case"rgba":return l<1?`rgba(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)}, ${k(l,5)})`:`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`;case"oklab":case"oklch":return`${r}(${k(e*100,6)}% ${k(n,6)} ${k(o,6)}${a})`;default:return`color(${r} ${k(e,6)} ${k(n,6)} ${k(o,6)}${a})`}}function L(r,t){let e=[...r];for(let n=0;n<t.length;n++){let o=0;for(let l=0;l<t[n].length;l++)o+=r[l]*t[n][l];e[n]=o}return e}function k(r,t=2){let e=10**t;return Math.round(r*e)/e}var de=[[.4123907992659593,.357584339383878,.1804807884018343],[.2126390058715102,.715168678767756,.0721923153607337],[.0193308187155918,.119194779794626,.9505321522496607]],be=[[3.240969941904522,-1.537383177570094,-.4986107602930034],[-.9692436362808793,1.8759675015077202,.0415550574071756],[.0556300796969937,-.2039769588889766,1.0569715142428782]],ge=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],h=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]],me=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],pe=[[1,.39633779217376774,.2158037580607588],[1,-.10556134232365633,-.0638541747717059],[1,-.08948418209496574,-1.2914855378640917]];function Te(r,t){let e=[1/0,1/0,1/0,1/0,1/0],n=1/0,o=1/0,l=1/0;-1.88170328*r-.80936493*t>1?(e=[1.19086277,1.76576728,.59662641,.75515197,.56771245],n=4.0767416621,o=-3.3077115913,l=.2309699292):1.81444104*r-1.19445276*t>1?(e=[.73956515,-.45954404,.08285427,.1254107,.14503204],n=-1.2684380046,o=2.6097574011,l=-.3413193965):(e=[1.35733652,-.00915799,-1.1513021,-.50559606,.00692167],n=-.0041960863,o=-.7034186147,l=1.707614701);let a=e[0]+e[1]*r+e[2]*t+e[3]*r*r+e[4]*r*t,f=.3963377774*r+.2158037573*t,c=-.1055613458*r-.0638541728*t,s=-.0894841775*r-1.291485548*t;{let x=1+a*f,b=1+a*c,d=1+a*s,m=x**3,S=b**3,T=d**3,y=3*f*x**2,M=3*c*b**2,v=3*s*d**2,V=6*f**2*x,u=6*c**2*b,R=6*s**2*d,w=n*m+o*S+l*T,$=n*y+o*M+l*v,E=n*V+o*u+l*R;a=a-w*$/($*$-.5*w*E)}return a}function Me(r,t){let e=Te(r,t),[n,o,l]=N(P([1,e*r,e*t,1])),a=Math.cbrt(1/Math.max(n,o,l)),f=a*e;return{L:a,C:f}}function ke(r,t,e,n,o){let l=Me(r,t);if((e-o)*l.C-(l.L-o)*n<=0)return l.C*o/(n*l.L+l.C*(o-e));let a=l.C*(o-1)/(n*(l.L-1)+l.C*(o-e)),f=e-o,c=n,s=.3963377774*r+.2158037573*t,x=-.1055613458*r-.0638541728*t,b=-.0894841775*r-1.291485548*t,d=f+c*s,m=f+c*x,S=f+c*b,T=o*(1-a)+a*e,y=a*n,M=T+y*s,v=T+y*x,V=T+y*b,u=[[M**3,v**3,V**3],[3*d*M**2,3*m*v**2,3*S*V**2],[6*d**2*M,6*m**2*v,6*S**2*V]],R=h[0][0]*u[0][0]+h[0][1]*u[0][1]+h[0][2]*u[0][2]-1,w=h[0][0]*u[1][0]+h[0][1]*u[1][1]+h[0][2]*u[1][2],$=h[0][0]*u[2][0]+h[0][1]*u[2][1]+h[0][2]*u[2][2],E=w/(w*w-.5*R*$),I=E>=0?-R*E:1/0,Z=h[1][0]*u[0][0]+h[1][1]*u[0][1]+h[1][2]*u[0][2]-1,p=h[1][0]*u[1][0]+h[1][1]*u[1][1]+h[1][2]*u[1][2],Re=h[1][0]*u[2][0]+h[1][1]*u[2][1]+h[1][2]*u[2][2],ue=p/(p*p-.5*Z*Re),Be=ue>=0?-Z*ue:1/0,xe=h[2][0]*u[0][0]+h[2][1]*u[0][1]+h[2][2]*u[0][2]-1,U=h[2][0]*u[1][0]+h[2][1]*u[1][1]+h[2][2]*u[1][2],Ge=h[2][0]*u[2][0]+h[2][1]*u[2][1]+h[2][2]*u[2][2],he=U/(U*U-.5*xe*Ge),_e=he>=0?-xe*he:1/0;return a+Math.min(I,Be,_e)}function W(r){let t=Math.abs(r);return t<=.0031308?r*12.92:1.055*Math.pow(t,1/2.4)-.055}function ee(r){return Math.abs(r)<=.04045?r/12.92:((Math.abs(r)+.055)/1.055)**2.4}function C(r){let[t,e,n,o]=r;t=Math.abs(t%360);let l=e*(1-Math.abs(2*n-1)),a=l*(1-Math.abs(t/60%2-1)),f=0,c=0,s=0;0<=t&&t<60?(f=l,c=a):60<=t&&t<120?(f=a,c=l):120<=t&&t<180?(c=l,s=a):180<=t&&t<240?(c=a,s=l):240<=t&&t<300?(f=a,s=l):300<=t&&t<360&&(f=l,s=a);let x=n-l/2;return[f+x,c+x,s+x,o]}function te(r){let[t,e,n,o]=r;if(e+n>=1){let a=e/(e+n);return[a,a,a,o]}let l=C([t,100,50,o]);for(let a=0;a<3;a++)l[a]*=1-e-n,l[a]+=e;return l}function we(r,t=2e-4){let[e,n,o,l]=r,a=Math.abs(n)<t&&Math.abs(o)<t?0:Q(Math.atan2(o,n));for(;a<0;)a+=360;for(;a>=360;)a-=360;return[e,Math.sqrt(n**2+o**2),a,l]}function Le(r){let[t,e,n,o]=r;if(t===0)return[0,0,0,o];for(;n<0;)n+=360;for(;n>=360;)n-=360;let l=J(n);return[t,Math.cos(l)*e,Math.sin(l)*e,o]}function Oe(r){return L(r,ge)}function N(r){let[t,e,n,o]=r,[l,a,f]=L([t**3,e**3,n**3,o],h);return[l,a,f,o]}function G(r){let[t,e,n,o]=r;return[W(t),W(e),W(n),o]}function re(r){let[t,e,n,o]=L(r,me);return[Math.cbrt(t),Math.cbrt(e),Math.cbrt(n),o]}function ne(r){return L(r,de)}function P(r){return L(r,pe)}function q(r){let[t,e,n,o]=N(P(r));if(t>1.001||t<-.001||e>1.001||e<-.001||n>1.001||n<-.001){let[a,f,c]=r,s=Math.max(1e-5,Math.sqrt(f**2+c**2)),x=i(a,0,1),b=f/s,d=c/s,m=ke(b,d,a,s,x);return G(N(P([x*(1-m)+m*a,b*(m*s),d*(m*s),o])))}return G([t,e,n,o])}function A(r){return q(Le(r))}function _(r){let[t,e,n,o]=r;return[ee(t),ee(e),ee(n),o]}function F(r){return Oe(re(_(r)))}function D(r){return we(F(r))}function oe(r){return L(r,be)}function j(r,t){let[e,n,o,l]=D(r);return typeof t.lightness=="number"&&(t.mode==="relative"?e+=t.lightness:e=t.lightness),typeof t.chroma=="number"&&(t.mode==="relative"?n+=t.chroma:n=t.chroma),typeof t.hue=="number"&&(t.mode==="relative"?o+=t.hue:o=t.hue),typeof t.alpha=="number"&&(t.mode==="relative"?l+=t.alpha:l=t.alpha),A([e,n,o,l])}var ve={black:0,silver:12632256,gray:8421504,white:16777215,maroon:8388608,red:16711680,purple:8388736,fuchsia:16711935,green:32768,lime:65280,olive:8421376,yellow:16776960,navy:128,blue:255,teal:32896,aqua:65535,orange:16753920,aliceblue:15792383,antiquewhite:16444375,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,blanchedalmond:16772045,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,limegreen:3329330,linen:16445670,magenta:16711935,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,oldlace:16643558,olivedrab:7048739,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,whitesmoke:16119285,yellowgreen:10145074,rebeccapurple:6697881},ae=ve;var Ve=/-?[0-9.]+%?/g,$e=/^#[0-9a-f]{3,8}$/i,Ie=/^([^( ]+)\s*\(\s*([^)]+)\)$/,Ae=16**6,le=16**4,fe=16**2;function g(r){let t=De(r),e={},n={get hex(){if(e.hex)return e.hex;let[o,l,a,f]=t,c="#";return c+=z(Math.round(i(o*255,0,255)).toString(16),2),c+=z(Math.round(i(l*255,0,255)).toString(16),2),c+=z(Math.round(i(a*255,0,255)).toString(16),2),t[3]<1&&(c+=z(Math.round(f*255).toString(16),2)),e.hex=c,e.hex},get hexVal(){if(typeof e.hexVal=="number")return e.hexVal;let[o,l,a,f]=t;return f<1&&console.warn(`hexVal converted a semi-transparent color (${f*100}%) to fully opaque`),o=Math.round(i(o*255,0,255)),l=Math.round(i(l*255,0,255)),a=Math.round(i(a*255,0,255)),e.hexVal=o*le+l*fe+a,e.hexVal},get rgb(){return e.rgb||(e.rgb=B("rgb",t)),e.rgb},get rgba(){return e.rgb||(e.rgb=B("rgb",t)),e.rgb},rgbVal:t,rgbaVal:t,get linearRGB(){return e.linearRGB||(e.linearRGB=B("srgb-linear",_(t))),e.linearRGB},get linearRGBVal(){return e.linearRGBVal||(e.linearRGBVal=_(t)),e.linearRGBVal},get p3(){return e.p3||(e.p3=B("display-p3",t)),e.p3},p3Val:t,get oklab(){return e.oklab||(e.oklab=B("oklab",F(t))),e.oklab},get oklabVal(){return e.oklabVal||(e.oklabVal=F(t)),e.oklabVal},get oklch(){return e.oklch||(e.oklch=B("oklch",D(t))),e.oklch},get oklchVal(){return e.oklchVal||(e.oklchVal=D(t)),e.oklchVal},get xyz(){return e.xyz||(e.xyz=B("xyz-d65",ne(_(t)))),e.xyz},get xyzVal(){return e.xyzVal||(e.xyzVal=ne(_(t))),e.xyzVal},adjust(o){return g(j(t,o))}};return n.toString=()=>n.hex,n}function ye(r){if(r>Ae)throw new Error("8-digit hex values (with transparency) aren\u2019t supported");let t=r,e=Math.floor(t/le);t-=e*le;let n=Math.floor(t/fe);t-=n*fe;let o=t;return[e/255,n/255,o/255,1]}function O(r,t){let e=r.match(Ve);if(!e)throw new Error(`Unexpected color format: ${r}`);let n=[0,0,0,1];for(let o=0;o<e.length;o++)e[o]&&(e[o].includes("%")?n[o]=parseFloat(e[o])/100:!t||t[o]===1/0||t[o]===1?n[o]=parseFloat(e[o]):n[o]=parseFloat(e[o])/t[o]);return n}function De(r){let t=new Error(`Unable to parse color ${JSON.stringify(r)}`);if(r==null||r==null||typeof r=="boolean")throw t;if(Array.isArray(r)){if(r.some(a=>typeof a!="number"))throw new Error(`Color array must be numbers, received ${r}`);if(r.length<3||r.length>4)throw new Error(`Expected [R, G, B, A?], received ${r}`);let[e,n,o,l]=r;return[i(e,0,1),i(n,0,1),i(o,0,1),typeof l=="number"?i(l,0,1):1]}if(typeof r=="number")return ye(r);if(typeof r=="string"){let e=r.trim();if(!e)throw new Error("Expected color, received empty string");let n=e.toLowerCase();if(typeof ae[n]=="number")return ye(ae[n]);if($e.test(n)){let f=n.replace("#",""),c=[0,0,0,1];if(f.length===6||f.length===8)for(let s=0;s<f.length/2;s++){let x=s*2,b=x+2,d=f.substring(x,b);c[s]=parseInt(d,16)/255}else if(f.length===3||f.length===4)for(let s=0;s<f.length;s++){let x=f.charAt(s);c[s]=parseInt(`${x}${x}`,16)/255}else throw new Error(`Hex value "${n}" not a valid sRGB color`);return c}let o=e.match(Ie);if(!o)throw t;let[,l,a]=o;if(l==="color"){let f=a.indexOf(" ");l=a.substring(0,f),a=a.substring(f)}switch(l){case"rgb":case"rgba":case"srgb":{let[f,c,s,x]=O(a,[255,255,255,1]);return[i(f,0,1),i(c,0,1),i(s,0,1),i(x,0,1)]}case"linear-rgb":case"linear-srgb":case"rgb-linear":case"srgb-linear":{let f=O(a);return G(f)}case"hsl":case"hsla":{let[f,c,s,x]=O(a);return C([f,i(c,0,1),i(s,0,1),i(x,0,1)])}case"hwb":case"hwba":{let[f,c,s,x]=O(a);return te([f,i(c,0,1),i(s,0,1),i(x,0,1)])}case"p3":case"display-p3":{let[f,c,s,x]=O(a);return[i(f,0,1),i(c,0,1),i(s,0,1),i(x,0,1)]}case"lab":case"oklab":return q(O(a));case"lch":case"oklch":return A(O(a));case"xyz":case"xyz-d65":return G(oe(O(a)))}}if(typeof r=="object"){let e={...r},n=1;for(let o of Object.keys(e))o==="alpha"?n=i(e[o],0,1):e[o.toLowerCase()]=e[o];if("r"in e&&"g"in e&&"b"in e)return[i(e.r,0,1),i(e.g,0,1),i(e.b,0,1),n];if("h"in e&&"s"in e&&"l"in e)return C([e.h,i(e.s,0,1),i(e.l,0,1),n]);if("h"in e&&"w"in e&&"b"in e)return te([e.h,i(e.w,0,1),i(e.b,0,1),n]);if("l"in e&&"a"in e&&"b"in e)return q([e.l,e.a,e.b,n]);if("l"in e&&"c"in e&&"h"in e)return A([e.l,e.c,e.h,n]);if("x"in e&&"y"in e&&"z"in e)return G(oe([e.x,e.y,e.z,n]));throw t}throw t}function X(r,t,e=.5,n="oklab"){let o=i(e,0,1);if(e===0)return g(r);if(e===1)return g(t);let l=1-o,a=o,f={oklch:D,oklab:F,lms:p=>_(re(p)),linearRGB:_,sRGB:p=>p},c={oklch:A,oklab:q,lms:p=>N(G(p)),linearRGB:G,sRGB:p=>p},s=f[n],x=c[n];if(!s)throw new Error(`Unknown color space "${n}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let[b,d,m,S]=g(r).rgbVal,[T,y,M,v]=g(t).rgbVal;n==="oklch"&&(b===d&&d===m||T===y&&y===M)&&(s=f.oklab,x=c.oklab);let[V,u,R,w]=s([b,d,m,S]),[$,E,I,Z]=s([T,y,M,v]);return n==="oklch"&&Math.abs(I-R)>180&&(Math.max(R,I)===I?I-=360:R-=360),g(x([V*l+$*a,u*l+E*a,R*l+I*a,w*l+Z*a]))}function H(r,t,e="oklab"){let n=i(t,-1,1);return n>=0?X(r,"black",n,e):K(r,-n)}function K(r,t,e="oklab"){let n=i(t,-1,1);return n>=0?X(r,"white",n,e):H(r,-n)}function Y(r){return g(r).xyzVal[1]}function se(r){return k(g(r).oklabVal[0],5)}function ie(r){return Y(r)<.36?"dark":"light"}function ce(r,t){let e=Y(r),n=Y(t),o=Math.max(e,n),l=Math.min(e,n),a=(o+.05)/(l+.05);return{ratio:a,AA:a>=4.5,AAA:a>=7}}var i0={adjust:j,contrastRatio:ce,darken:H,from:g,lighten:K,lightness:se,lightOrDark:ie,luminance:Y,mix:X};export{j as adjust,i as clamp,B as colorFn,ce as contrastRatio,H as darken,i0 as default,J as degToRad,g as from,z as leftPad,ie as lightOrDark,K as lighten,se as lightness,Y as luminance,X as mix,L as multiplyColorMatrix,Q as radToDeg,k as round}; | ||
function N(r,t=2){let e=r;for(;e.length<t;)e=`0${e}`;return e}function J(r){return r*(Math.PI/180)}function Q(r){return r*(180/Math.PI)}function i(r,t,e){return Math.min(Math.max(r,t),e)}function B(r,t){let[e,n,o,l]=t,a=l<1?`/${k(l,5)}`:"";switch(r){case"rgb":case"rgba":return l<1?`rgba(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)}, ${k(l,5)})`:`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`;case"oklab":case"oklch":return`${r}(${k(e*100,6)}% ${k(n,6)} ${k(o,6)}${a})`;default:return`color(${r} ${k(e,6)} ${k(n,6)} ${k(o,6)}${a})`}}function L(r,t){let e=[...r];for(let n=0;n<t.length;n++){let o=0;for(let l=0;l<t[n].length;l++)o+=r[l]*t[n][l];e[n]=o}return e}function k(r,t=2){let e=10**t;return Math.round(r*e)/e}var de=[[.4123907992659593,.357584339383878,.1804807884018343],[.2126390058715102,.715168678767756,.0721923153607337],[.0193308187155918,.119194779794626,.9505321522496607]],be=[[3.240969941904522,-1.537383177570094,-.4986107602930034],[-.9692436362808793,1.8759675015077202,.0415550574071756],[.0556300796969937,-.2039769588889766,1.0569715142428782]],me=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],h=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]],ge=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],pe=[[1,.39633779217376774,.2158037580607588],[1,-.10556134232365633,-.0638541747717059],[1,-.08948418209496574,-1.2914855378640917]];function Te(r,t){let e=[1/0,1/0,1/0,1/0,1/0],n=1/0,o=1/0,l=1/0;-1.88170328*r-.80936493*t>1?(e=[1.19086277,1.76576728,.59662641,.75515197,.56771245],n=4.0767416621,o=-3.3077115913,l=.2309699292):1.81444104*r-1.19445276*t>1?(e=[.73956515,-.45954404,.08285427,.1254107,.14503204],n=-1.2684380046,o=2.6097574011,l=-.3413193965):(e=[1.35733652,-.00915799,-1.1513021,-.50559606,.00692167],n=-.0041960863,o=-.7034186147,l=1.707614701);let a=e[0]+e[1]*r+e[2]*t+e[3]*r*r+e[4]*r*t,f=.3963377774*r+.2158037573*t,c=-.1055613458*r-.0638541728*t,s=-.0894841775*r-1.291485548*t;{let x=1+a*f,b=1+a*c,d=1+a*s,g=x**3,E=b**3,T=d**3,y=3*f*x**2,M=3*c*b**2,v=3*s*d**2,V=6*f**2*x,u=6*c**2*b,R=6*s**2*d,w=n*g+o*E+l*T,$=n*y+o*M+l*v,z=n*V+o*u+l*R;a=a-w*$/($*$-.5*w*z)}return a}function Me(r,t){let e=Te(r,t),[n,o,l]=q(P([1,e*r,e*t,1])),a=Math.cbrt(1/Math.max(n,o,l)),f=a*e;return{L:a,C:f}}function ke(r,t,e,n,o){let l=Me(r,t);if((e-o)*l.C-(l.L-o)*n<=0)return l.C*o/(n*l.L+l.C*(o-e));let a=l.C*(o-1)/(n*(l.L-1)+l.C*(o-e)),f=e-o,c=n,s=.3963377774*r+.2158037573*t,x=-.1055613458*r-.0638541728*t,b=-.0894841775*r-1.291485548*t,d=f+c*s,g=f+c*x,E=f+c*b,T=o*(1-a)+a*e,y=a*n,M=T+y*s,v=T+y*x,V=T+y*b,u=[[M**3,v**3,V**3],[3*d*M**2,3*g*v**2,3*E*V**2],[6*d**2*M,6*g**2*v,6*E**2*V]],R=h[0][0]*u[0][0]+h[0][1]*u[0][1]+h[0][2]*u[0][2]-1,w=h[0][0]*u[1][0]+h[0][1]*u[1][1]+h[0][2]*u[1][2],$=h[0][0]*u[2][0]+h[0][1]*u[2][1]+h[0][2]*u[2][2],z=w/(w*w-.5*R*$),I=z>=0?-R*z:1/0,Z=h[1][0]*u[0][0]+h[1][1]*u[0][1]+h[1][2]*u[0][2]-1,p=h[1][0]*u[1][0]+h[1][1]*u[1][1]+h[1][2]*u[1][2],Re=h[1][0]*u[2][0]+h[1][1]*u[2][1]+h[1][2]*u[2][2],ue=p/(p*p-.5*Z*Re),Be=ue>=0?-Z*ue:1/0,xe=h[2][0]*u[0][0]+h[2][1]*u[0][1]+h[2][2]*u[0][2]-1,U=h[2][0]*u[1][0]+h[2][1]*u[1][1]+h[2][2]*u[1][2],Ge=h[2][0]*u[2][0]+h[2][1]*u[2][1]+h[2][2]*u[2][2],he=U/(U*U-.5*xe*Ge),_e=he>=0?-xe*he:1/0;return a+Math.min(I,Be,_e)}function W(r){let t=Math.abs(r);return t<=.0031308?r*12.92:1.055*Math.pow(t,1/2.4)-.055}function ee(r){return Math.abs(r)<=.04045?r/12.92:((Math.abs(r)+.055)/1.055)**2.4}function C(r){let[t,e,n,o]=r;t=Math.abs(t%360);let l=e*(1-Math.abs(2*n-1)),a=l*(1-Math.abs(t/60%2-1)),f=0,c=0,s=0;0<=t&&t<60?(f=l,c=a):60<=t&&t<120?(f=a,c=l):120<=t&&t<180?(c=l,s=a):180<=t&&t<240?(c=a,s=l):240<=t&&t<300?(f=a,s=l):300<=t&&t<360&&(f=l,s=a);let x=n-l/2;return[f+x,c+x,s+x,o]}function te(r){let[t,e,n,o]=r;if(e+n>=1){let a=e/(e+n);return[a,a,a,o]}let l=C([t,100,50,o]);for(let a=0;a<3;a++)l[a]*=1-e-n,l[a]+=e;return l}function we(r,t=2e-4){let[e,n,o,l]=r,a=Math.abs(n)<t&&Math.abs(o)<t?0:Q(Math.atan2(o,n));for(;a<0;)a+=360;for(;a>=360;)a-=360;return[e,Math.sqrt(n**2+o**2),a,l]}function Le(r){let[t,e,n,o]=r;if(t===0)return[0,0,0,o];for(;n<0;)n+=360;for(;n>=360;)n-=360;let l=J(n);return[t,Math.cos(l)*e,Math.sin(l)*e,o]}function Oe(r){return L(r,me)}function q(r){let[t,e,n,o]=r,[l,a,f]=L([t**3,e**3,n**3,o],h);return[l,a,f,o]}function G(r){let[t,e,n,o]=r;return[W(t),W(e),W(n),o]}function re(r){let[t,e,n,o]=L(r,ge);return[Math.cbrt(t),Math.cbrt(e),Math.cbrt(n),o]}function ne(r){return L(r,de)}function P(r){return L(r,pe)}function F(r){let[t,e,n,o]=q(P(r));if(t>1.001||t<-.001||e>1.001||e<-.001||n>1.001||n<-.001){let[a,f,c]=r,s=Math.max(1e-5,Math.sqrt(f**2+c**2)),x=i(a,0,1),b=f/s,d=c/s,g=ke(b,d,a,s,x);return G(q(P([x*(1-g)+g*a,b*(g*s),d*(g*s),o])))}return G([t,e,n,o])}function A(r){return F(Le(r))}function _(r){let[t,e,n,o]=r;return[ee(t),ee(e),ee(n),o]}function j(r){return Oe(re(_(r)))}function D(r){return we(j(r))}function oe(r){return L(r,be)}function X(r,t){let[e,n,o,l]=D(r);return typeof t.lightness=="number"&&(t.mode==="relative"?e+=t.lightness:e=t.lightness),typeof t.chroma=="number"&&(t.mode==="relative"?n+=t.chroma:n=t.chroma),typeof t.hue=="number"&&(t.mode==="relative"?o+=t.hue:o=t.hue),typeof t.alpha=="number"&&(t.mode==="relative"?l+=t.alpha:l=t.alpha),A([e,n,o,l])}var ve={black:0,silver:12632256,gray:8421504,white:16777215,maroon:8388608,red:16711680,purple:8388736,fuchsia:16711935,green:32768,lime:65280,olive:8421376,yellow:16776960,navy:128,blue:255,teal:32896,aqua:65535,orange:16753920,aliceblue:15792383,antiquewhite:16444375,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,blanchedalmond:16772045,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,limegreen:3329330,linen:16445670,magenta:16711935,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,oldlace:16643558,olivedrab:7048739,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,whitesmoke:16119285,yellowgreen:10145074,rebeccapurple:6697881},ae=ve;var Ve=/-?[0-9.]+%?/g,$e=/^#[0-9a-f]{3,8}$/i,Ie=/^([^( ]+)\s*\(\s*([^)]+)\)$/,Ae=16**6,le=16**4,fe=16**2;function m(r){let t=De(r),e={},n={get hex(){if(e.hex)return e.hex;let[o,l,a,f]=t,c="#";return c+=N(Math.round(i(o*255,0,255)).toString(16),2),c+=N(Math.round(i(l*255,0,255)).toString(16),2),c+=N(Math.round(i(a*255,0,255)).toString(16),2),t[3]<1&&(c+=N(Math.round(f*255).toString(16),2)),e.hex=c,e.hex},get hexVal(){if(typeof e.hexVal=="number")return e.hexVal;let[o,l,a,f]=t;return f<1&&console.warn(`hexVal converted a semi-transparent color (${f*100}%) to fully opaque`),o=Math.round(i(o*255,0,255)),l=Math.round(i(l*255,0,255)),a=Math.round(i(a*255,0,255)),e.hexVal=o*le+l*fe+a,e.hexVal},get rgb(){return e.rgb||(e.rgb=B("rgb",t)),e.rgb},get rgba(){return e.rgb||(e.rgb=B("rgb",t)),e.rgb},rgbVal:t,rgbaVal:t,get linearRGB(){return e.linearRGB||(e.linearRGB=B("srgb-linear",_(t))),e.linearRGB},get linearRGBVal(){return e.linearRGBVal||(e.linearRGBVal=_(t)),e.linearRGBVal},get p3(){return e.p3||(e.p3=B("display-p3",t)),e.p3},p3Val:t,get oklab(){return e.oklab||(e.oklab=B("oklab",j(t))),e.oklab},get oklabVal(){return e.oklabVal||(e.oklabVal=j(t)),e.oklabVal},get oklch(){return e.oklch||(e.oklch=B("oklch",D(t))),e.oklch},get oklchVal(){return e.oklchVal||(e.oklchVal=D(t)),e.oklchVal},get xyz(){return e.xyz||(e.xyz=B("xyz-d65",ne(_(t)))),e.xyz},get xyzVal(){return e.xyzVal||(e.xyzVal=ne(_(t))),e.xyzVal},adjust(o){return m(X(t,o))}};return n.toString=()=>n.hex,n}function ye(r){if(r>Ae)throw new Error("8-digit hex values (with transparency) aren\u2019t supported");let t=r,e=Math.floor(t/le);t-=e*le;let n=Math.floor(t/fe);t-=n*fe;let o=t;return[e/255,n/255,o/255,1]}function O(r,t){let e=r.match(Ve);if(!e)throw new Error(`Unexpected color format: ${r}`);let n=[0,0,0,1];for(let o=0;o<e.length;o++)e[o]&&(e[o].includes("%")?n[o]=parseFloat(e[o])/100:!t||t[o]===1/0||t[o]===1?n[o]=parseFloat(e[o]):n[o]=parseFloat(e[o])/t[o]);return n}function De(r){let t=new Error(`Unable to parse color ${JSON.stringify(r)}`);if(r==null||r==null||typeof r=="boolean")throw t;if(Array.isArray(r)){if(r.some(a=>typeof a!="number"))throw new Error(`Color array must be numbers, received ${r}`);if(r.length<3||r.length>4)throw new Error(`Expected [R, G, B, A?], received ${r}`);let[e,n,o,l]=r;return[i(e,0,1),i(n,0,1),i(o,0,1),typeof l=="number"?i(l,0,1):1]}if(typeof r=="number")return ye(r);if(typeof r=="string"){let e=r.trim();if(!e)throw new Error("Expected color, received empty string");let n=e.toLowerCase();if(typeof ae[n]=="number")return ye(ae[n]);if($e.test(n)){let f=n.replace("#",""),c=[0,0,0,1];if(f.length===6||f.length===8)for(let s=0;s<f.length/2;s++){let x=s*2,b=x+2,d=f.substring(x,b);c[s]=parseInt(d,16)/255}else if(f.length===3||f.length===4)for(let s=0;s<f.length;s++){let x=f.charAt(s);c[s]=parseInt(`${x}${x}`,16)/255}else throw new Error(`Hex value "${n}" not a valid sRGB color`);return c}let o=e.match(Ie);if(!o)throw t;let[,l,a]=o;if(l==="color"){let f=a.indexOf(" ");l=a.substring(0,f),a=a.substring(f)}switch(l){case"rgb":case"rgba":case"srgb":{let[f,c,s,x]=O(a,[255,255,255,1]);return[i(f,0,1),i(c,0,1),i(s,0,1),i(x,0,1)]}case"linear-rgb":case"linear-srgb":case"rgb-linear":case"srgb-linear":{let f=O(a);return G(f)}case"hsl":case"hsla":{let[f,c,s,x]=O(a);return C([f,i(c,0,1),i(s,0,1),i(x,0,1)])}case"hwb":case"hwba":{let[f,c,s,x]=O(a);return te([f,i(c,0,1),i(s,0,1),i(x,0,1)])}case"p3":case"display-p3":{let[f,c,s,x]=O(a);return[i(f,0,1),i(c,0,1),i(s,0,1),i(x,0,1)]}case"lab":case"oklab":return F(O(a));case"lch":case"oklch":return A(O(a));case"xyz":case"xyz-d65":return G(oe(O(a)))}}if(typeof r=="object"){let e={...r},n=1;for(let o of Object.keys(e))o==="alpha"?n=i(e[o],0,1):e[o.toLowerCase()]=e[o];if("r"in e&&"g"in e&&"b"in e)return[i(e.r,0,1),i(e.g,0,1),i(e.b,0,1),n];if("h"in e&&"s"in e&&"l"in e)return C([e.h,i(e.s,0,1),i(e.l,0,1),n]);if("h"in e&&"w"in e&&"b"in e)return te([e.h,i(e.w,0,1),i(e.b,0,1),n]);if("l"in e&&"a"in e&&"b"in e)return F([e.l,e.a,e.b,n]);if("l"in e&&"c"in e&&"h"in e)return A([e.l,e.c,e.h,n]);if("x"in e&&"y"in e&&"z"in e)return G(oe([e.x,e.y,e.z,n]));throw t}throw t}function Y(r,t,e=.5,n="oklab"){let o=i(e,0,1);if(e===0)return m(r);if(e===1)return m(t);let l=1-o,a=o,f={oklch:D,oklab:j,lms:p=>_(re(p)),linearRGB:_,sRGB:p=>p},c={oklch:A,oklab:F,lms:p=>q(G(p)),linearRGB:G,sRGB:p=>p},s=f[n],x=c[n];if(!s)throw new Error(`Unknown color space "${n}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let[b,d,g,E]=m(r).rgbVal,[T,y,M,v]=m(t).rgbVal;n==="oklch"&&(b===d&&d===g||T===y&&y===M)&&(s=f.oklab,x=c.oklab);let[V,u,R,w]=s([b,d,g,E]),[$,z,I,Z]=s([T,y,M,v]);return n==="oklch"&&Math.abs(I-R)>180&&(Math.max(R,I)===I?I-=360:R-=360),m(x([V*l+$*a,u*l+z*a,R*l+I*a,w*l+Z*a]))}function H(r,t,e="oklab"){let n=i(t,-1,1);return n>=0?Y(r,"black",n,e):K(r,-n)}function K(r,t,e="oklab"){let n=i(t,-1,1);return n>=0?Y(r,"white",n,e):H(r,-n)}function S(r){return m(r).xyzVal[1]}function se(r){return k(m(r).oklabVal[0],5)}function ie(r){return S(r)<.36?"dark":"light"}function ce(r,t){let e=S(r),n=S(t),o=Math.max(e,n),l=Math.min(e,n),a=(o+.05)/(l+.05);return{ratio:a,AA:a>=4.5,AAA:a>=7}}var x0={adjust:X,contrastRatio:ce,darken:H,from:m,lighten:K,lightness:se,lightOrDark:ie,luminance:S,mix:Y};export{X as adjust,i as clamp,B as colorFn,ce as contrastRatio,H as darken,x0 as default,J as degToRad,m as from,N as leftPad,ie as lightOrDark,K as lighten,se as lightness,S as luminance,Y as mix,L as multiplyColorMatrix,Q as radToDeg,k as round}; |
@@ -1,2 +0,2 @@ | ||
import type { ColorMatrix } from './index'; | ||
import type { ColorMatrix } from './index.js'; | ||
export declare const LINEAR_RGB_D65_TO_XYZ: ColorMatrix; | ||
@@ -3,0 +3,0 @@ export declare const XYZ_TO_LINEAR_RGB_D65: ColorMatrix; |
@@ -34,9 +34,1 @@ import type { Color } from './colorspace.js'; | ||
export declare function lightOrDark(color: Color): 'light' | 'dark'; | ||
/** | ||
* WCAG 2.1 Contrast Ratio | ||
*/ | ||
export declare function contrastRatio(c1: Color, c2: Color): { | ||
ratio: number; | ||
AA: boolean; | ||
AAA: boolean; | ||
}; |
@@ -56,16 +56,1 @@ import { mix } from './mix.js'; | ||
} | ||
/** | ||
* WCAG 2.1 Contrast Ratio | ||
*/ | ||
export function contrastRatio(c1, c2) { | ||
const l1 = luminance(c1); | ||
const l2 = luminance(c2); | ||
let lighter = Math.max(l1, l2); | ||
let darker = Math.min(l1, l2); | ||
const ratio = (lighter + 0.05) / (darker + 0.05); | ||
return { | ||
ratio, | ||
AA: ratio >= 4.5, | ||
AAA: ratio >= 7, | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { ColorMatrix, sRGB } from './index'; | ||
import type { ColorMatrix, sRGB } from './index.js'; | ||
/** you know it, you love it */ | ||
@@ -3,0 +3,0 @@ export declare function leftPad(input: string, min?: number): string; |
{ | ||
"name": "better-color-tools", | ||
"description": "Fast, minimal color conversion and tools for JS/Sass. Supports sRGB, Oklab, Oklch, Display P3, and more.", | ||
"version": "0.12.2", | ||
"description": "Fast, minimal color conversion and tools for JS and Sass. Supports sRGB, Oklab, Oklch, Display P3, and more.", | ||
"version": "0.12.3", | ||
"author": { | ||
@@ -14,8 +14,9 @@ "name": "Drew Powers", | ||
"keywords": [ | ||
"sass", | ||
"scss", | ||
"css", | ||
"color", | ||
"colour", | ||
"typescript" | ||
"typescript", | ||
"oklab", | ||
"oklch", | ||
"contrast", | ||
"rgb" | ||
], | ||
@@ -28,5 +29,4 @@ "homepage": "https://github.com/drwpow/better-color-tools", | ||
"main": "./dist/index.min.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "del dist && tsc && npm run bundle && cp dist/index.min.js www/src/lib/better.min.js", | ||
"build": "del dist && tsc && npm run bundle && cp dist/index.d.ts dist/index.min.d.ts && cp dist/index.min.js www/src/lib/better.min.js", | ||
"bundle": "esbuild dist/index.js --bundle --minify --outfile=dist/index.min.js --format=esm", | ||
@@ -41,19 +41,19 @@ "changeset": "changeset", | ||
"devDependencies": { | ||
"@changesets/cli": "^2.26.0", | ||
"@types/node": "^18.14.6", | ||
"@typescript-eslint/eslint-plugin": "^5.54.0", | ||
"@typescript-eslint/parser": "^5.54.0", | ||
"@changesets/cli": "^2.26.1", | ||
"@types/node": "^18.15.11", | ||
"@typescript-eslint/eslint-plugin": "^5.58.0", | ||
"@typescript-eslint/parser": "^5.58.0", | ||
"del-cli": "^4.0.1", | ||
"esbuild": "^0.17.11", | ||
"eslint": "^8.35.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"esbuild": "^0.17.16", | ||
"eslint": "^8.38.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"npm-run-all": "^4.1.5", | ||
"pnpm": "^7.28.0", | ||
"prettier": "^2.8.4", | ||
"sass": "^1.58.3", | ||
"typescript": "^4.9.5", | ||
"vite": "^4.1.4", | ||
"vitest": "^0.29.2" | ||
"pnpm": "^8.2.0", | ||
"prettier": "^2.8.7", | ||
"sass": "^1.62.0", | ||
"typescript": "^5.0.4", | ||
"vite": "^4.2.1", | ||
"vitest": "^0.30.1" | ||
} | ||
} |
@@ -17,2 +17,8 @@ # better-color-tools | ||
| Package | Size (min, gzip) | | ||
| :------------------------------------------------- | ---------------: | | ||
| **better-color-tools** | `5.9 kB` | | ||
| [culori](https://culorijs.org) (Oklab/Oklch only) | `19.2 kB` | | ||
| [Color.js](https://colorjs.io/) (Oklab/Oklch only) | `24.2 kB` | | ||
This library exists to provide performant and accurate access to the Oklab and Oklch colorspaces at minimum filesize and maximum performance. This is **not** a comprehensive colorspace tool like [Culori] or [Color.js][colorjs], rather, better-color-tools | ||
@@ -19,0 +25,0 @@ seeks to give you the best “bang for the buck” by providing maximum utility with minimal footprint. |
@@ -7,3 +7,4 @@ export type { AdjustOptions } from './adjust.js'; | ||
export { default as adjust } from './adjust.js'; | ||
export { contrastRatio, darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
export { contrastRatio } from './contrast.js'; | ||
export { darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
export { mix } from './mix.js'; | ||
@@ -14,3 +15,4 @@ export { from } from './parse.js'; | ||
import adjust from './adjust.js'; | ||
import { contrastRatio, darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
import { contrastRatio } from './contrast.js'; | ||
import { darken, lighten, lightOrDark, lightness, luminance } from './luminance.js'; | ||
import { mix } from './mix.js'; | ||
@@ -17,0 +19,0 @@ import { from } from './parse.js'; |
@@ -1,2 +0,2 @@ | ||
import type { ColorMatrix } from './index'; | ||
import type { ColorMatrix } from './index.js'; | ||
import { lmsToLinearRGBD65, oklabToLMS } from './colorspace.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -62,17 +62,1 @@ import type { Color } from './colorspace.js'; | ||
} | ||
/** | ||
* WCAG 2.1 Contrast Ratio | ||
*/ | ||
export function contrastRatio(c1: Color, c2: Color): { ratio: number; AA: boolean; AAA: boolean } { | ||
const l1 = luminance(c1); | ||
const l2 = luminance(c2); | ||
let lighter = Math.max(l1, l2); | ||
let darker = Math.min(l1, l2); | ||
const ratio = (lighter + 0.05) / (darker + 0.05); | ||
return { | ||
ratio, | ||
AA: ratio >= 4.5, | ||
AAA: ratio >= 7, | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
import type { ColorMatrix, sRGB } from './index'; | ||
import type { ColorMatrix, sRGB } from './index.js'; | ||
@@ -3,0 +3,0 @@ /** you know it, you love it */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
185122
44
4874
280