Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-color-tools

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-color-tools - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

6

CHANGELOG.md
# better-color-tools
## 0.6.3
### Patch Changes
- 1f108f4: fix: bug in hexVal output
## 0.6.2

@@ -4,0 +10,0 @@

2

dist/index.min.js

@@ -1,1 +0,1 @@

function m(t,e=2){let n=t;for(;n.length<e;)n=`0${n}`;return n}function I(t){return t*(Math.PI/180)}function V(t){return t*(180/Math.PI)}function s(t,e,n){return Math.min(Math.max(t,e),n)}function G(t,e){return`color(${t} ${p(e[0],5)} ${p(e[1],5)} ${p(e[2],5)}${e[3]<1?`/${p(e[3],5)}`:""})`}function d(t,e){let n=[...t];for(let r=0;r<e.length;r++){let a=0;for(let o=0;o<e[0].length;o++)a+=t[o]*e[r][o];n[r]=a}return n}function p(t,e=2){let n=10**e;return Math.round(t*n)/n}function _(t){let e=`${Math.round(t[0]*255)}, ${Math.round(t[1]*255)}, ${Math.round(t[2]*255)}`;return t[3]!==1?`rgba(${e}, ${p(t[3],5)})`:`rgb(${e})`}var U=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],K=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]];var j=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],J=[[1,.3963377774,.2158037573],[1,-.1055613458,-.0638541728],[1,-.0894841775,-1.291485548]],Q=[[3.2406,-1.5372,-.4986],[-.9689,1.8758,.0415],[.0557,-.204,1.057]];function q(t){let[e,n,r,a]=t;e=Math.abs(e%360);let o=n*(1-Math.abs(2*r-1)),l=o*(1-Math.abs(e/60%2-1)),i=0,c=0,u=0;0<=e&&e<60?(i=o,c=l):60<=e&&e<120?(i=l,c=o):120<=e&&e<180?(c=o,u=l):180<=e&&e<240?(c=l,u=o):240<=e&&e<300?(i=l,u=o):300<=e&&e<360&&(i=o,u=l);let g=r-o/2;return[i+g,c+g,u+g,a]}function W(t){let[e,n,r,a]=t,o=n===0&&r===0?0:V(Math.atan2(r,n));return[e,Math.sqrt(n**2+r**2),o<0?o+360:o,a]}function C(t){let[e,n,r,a]=t,o=I(r);return[e,n*Math.cos(o),n*Math.sin(o),a]}function e0(t){let e=Math.cbrt(t[0]),n=Math.cbrt(t[1]),r=Math.cbrt(t[2]),a=t[3];return d([e,n,r,a],U)}function t0(t){let[e,n,r,a]=d(t,K);return[Math.max(0,e),Math.max(0,n),Math.max(0,r),Math.max(0,a)]}function b(t){return t.map((e,n)=>n===3?s(e,0,1):e<=.0031308?s(e*12.92,0,1):s(1.055*e**(1/2.4)-.055,0,1))}function r0(t){return d(t,j)}function n0(t){let[e,n,r,a]=t,o=[0,0,0,a],l=n/(13*e),i=r/(13*e);return o[1]=e<=8?e*(3/29)**3:((e+16)/116)**3,o[0]=o[1]*(9/4)*l,o[2]=o[1]*((12-3*l-20*i)/4*i),o}function S(t){return b(a0(n0(t)))}function o0(t){let e=d(t,J);return[e[0]**3,e[1]**3,e[2]**3,e[3]]}function T(t){return b(t0(o0(t)))}function v(t){return T(C(t))}function M(t){return t.map((e,n)=>n===3?e:e<=.04045?e/12.92:((e+.055)/1.055)**2.4)}function k(t){return e0(r0(M(t)))}function w(t){return W(k(t))}function a0(t){return d(t,Q)}var l0={black:[0,0,0,1],silver:[.75,.75,.75,1],gray:[.5,.5,.5,1],white:[1,1,1,1],maroon:[.5,0,0,1],red:[1,0,0,1],purple:[.5,0,.5,1],fuchsia:[1,0,1,1],green:[0,.5,0,1],lime:[0,1,0,1],olive:[.5,.5,0,1],yellow:[1,1,0,1],navy:[0,0,.5,1],blue:[0,0,1,1],teal:[0,.5,.5,1],aqua:[0,1,1,1],orange:[1,.6470588235294118,0,1],aliceblue:[.9411764705882353,.9725490196078431,1,1],antiquewhite:[.9803921568627451,.9215686274509803,.8431372549019608,1],aquamarine:[.4980392156862745,1,.8313725490196079,1],azure:[.9411764705882353,1,1,1],beige:[.9607843137254902,.9607843137254902,.8627450980392157,1],bisque:[1,.8941176470588236,.7686274509803922,1],blanchedalmond:[1,.9215686274509803,.803921568627451,1],blueviolet:[.5411764705882353,.16862745098039217,.8862745098039215,1],brown:[.6470588235294118,.16470588235294117,.16470588235294117,1],burlywood:[.8705882352941177,.7215686274509804,.5294117647058824,1],cadetblue:[.37254901960784315,.6196078431372549,.6274509803921569,1],chartreuse:[.4980392156862745,1,0,1],chocolate:[.8235294117647058,.4117647058823529,.11764705882352941,1],coral:[1,.4980392156862745,.3137254901960784,1],cornflowerblue:[.39215686274509803,.5843137254901961,.9294117647058824,1],cornsilk:[1,.9725490196078431,.8627450980392157,1],crimson:[.8627450980392157,.0784313725490196,.23529411764705882,1],cyan:[0,1,1,1],darkblue:[0,0,.5450980392156862,1],darkcyan:[0,.5450980392156862,.5450980392156862,1],darkgoldenrod:[.7215686274509804,.5254901960784314,.043137254901960784,1],darkgray:[.6627450980392157,.6627450980392157,.6627450980392157,1],darkgreen:[0,.39215686274509803,0,1],darkgrey:[.6627450980392157,.6627450980392157,.6627450980392157,1],darkkhaki:[.7411764705882353,.7176470588235294,.4196078431372549,1],darkmagenta:[.5450980392156862,0,.5450980392156862,1],darkolivegreen:[.3333333333333333,.4196078431372549,.1843137254901961,1],darkorange:[1,.5490196078431373,0,1],darkorchard:[.6,.19607843137254902,.8,1],darkred:[.5450980392156862,0,0,1],darksalmon:[.9137254901960784,.5882352941176471,.47843137254901963,1],darkseagreen:[.5607843137254902,.7372549019607844,.5607843137254902,1],darkslateblue:[.2823529411764706,.23921568627450981,.5450980392156862,1],darkslategray:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkslategrey:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkturquoise:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkviolet:[.5803921568627451,0,.8274509803921568,1],deeppink:[1,.0784313725490196,.5764705882352941,1],deepskyblue:[0,.7490196078431373,1,1],dimgray:[.4117647058823529,.4117647058823529,.4117647058823529,1],dimgrey:[.4117647058823529,.4117647058823529,.4117647058823529,1],dodgerblue:[.11764705882352941,.5647058823529412,1,1],firebrick:[.6980392156862745,.13333333333333333,.13333333333333333,1],floralwhite:[1,.9803921568627451,.9411764705882353,1],forestgreen:[.13333333333333333,.5450980392156862,.13333333333333333,1],gainsboro:[.8627450980392157,.8627450980392157,.8627450980392157,1],ghostwhite:[.9725490196078431,.9725490196078431,1,1],gold:[1,.8431372549019608,0,1],goldenrod:[.8549019607843137,.6470588235294118,.12549019607843137,1],greenyellow:[.6784313725490196,1,.1843137254901961,1],grey:[.5019607843137255,.5019607843137255,.5019607843137255,1],honeydew:[.9411764705882353,1,.9411764705882353,1],hotpink:[1,.4117647058823529,.7058823529411765,1],indianred:[.803921568627451,.3607843137254902,.3607843137254902,1],indigo:[.29411764705882354,0,.5098039215686274,1],ivory:[1,1,.9411764705882353,1],khaki:[.9411764705882353,.9019607843137255,.5490196078431373,1],lavendar:[.9019607843137255,.9019607843137255,.9803921568627451,1],lavenderblush:[1,.9411764705882353,.9607843137254902,1],lawngreen:[.48627450980392156,.9882352941176471,0,1],lemonchiffon:[1,.9803921568627451,.803921568627451,1],lightblue:[.6784313725490196,.8470588235294118,.9019607843137255,1],lightcoral:[.9411764705882353,.5019607843137255,.5019607843137255,1],lightcyan:[.8784313725490196,1,1,1],lightgoldenrodyellow:[.9803921568627451,.9803921568627451,.8235294117647058,1],lightgray:[.8274509803921568,.8274509803921568,.8274509803921568,1],lightgreen:[.5647058823529412,.9333333333333333,.5647058823529412,1],lightgrey:[.8274509803921568,.8274509803921568,.8274509803921568,1],lightpink:[1,.7137254901960784,.7568627450980392,1],lightsalmon:[1,.6274509803921569,.47843137254901963,1],lightseagreen:[.12549019607843137,.6980392156862745,.6666666666666666,1],lightskyblue:[.5294117647058824,.807843137254902,.9803921568627451,1],lightslategray:[.4666666666666667,.5333333333333333,.6,1],lightslategrey:[.4666666666666667,.5333333333333333,.6,1],lightsteelblue:[.6901960784313725,.7686274509803922,.8705882352941177,1],lightyellow:[1,1,.8784313725490196,1],limegreen:[.19607843137254902,.803921568627451,.19607843137254902,1],linen:[.9803921568627451,.9411764705882353,.9019607843137255,1],magenta:[1,0,1,1],mediumaquamarine:[.4,.803921568627451,.6666666666666666,1],mediumblue:[0,0,.803921568627451,1],mediumorchid:[.7294117647058823,.3333333333333333,.8274509803921568,1],mediumpurple:[.5764705882352941,.4392156862745098,.8588235294117647,1],mediumseagreen:[.23529411764705882,.7019607843137254,.44313725490196076,1],mediumslateblue:[.4823529411764706,.40784313725490196,.9333333333333333,1],mediumspringgreen:[0,.9803921568627451,.6039215686274509,1],mediumturquoise:[.2823529411764706,.8196078431372549,.8,1],mediumvioletred:[.7803921568627451,.08235294117647059,.5215686274509804,1],midnightblue:[.09803921568627451,.09803921568627451,.4392156862745098,1],mintcream:[.9607843137254902,1,.9803921568627451,1],mistyrose:[1,.8941176470588236,.8823529411764706,1],moccasin:[1,.8941176470588236,.7098039215686275,1],navajowhite:[1,.8705882352941177,.6784313725490196,1],oldlace:[.9921568627450981,.9607843137254902,.9019607843137255,1],olivedrab:[.4196078431372549,.5568627450980392,.13725490196078433,1],orangered:[1,.27058823529411763,0,1],orchid:[.8549019607843137,.4392156862745098,.8392156862745098,1],palegoldenrod:[.9333333333333333,.9098039215686274,.6666666666666666,1],palegreen:[.596078431372549,.984313725490196,.596078431372549,1],paleturquoise:[.6862745098039216,.9333333333333333,.9333333333333333,1],palevioletred:[.8588235294117647,.4392156862745098,.5764705882352941,1],papayawhip:[1,.9372549019607843,.8352941176470589,1],peachpuff:[1,.8549019607843137,.7254901960784313,1],peru:[.803921568627451,.5215686274509804,.24705882352941178,1],pink:[1,.7529411764705882,.796078431372549,1],plum:[.8666666666666667,.6274509803921569,.8666666666666667,1],powderblue:[.6901960784313725,.8784313725490196,.9019607843137255,1],rosybrown:[.7372549019607844,.5607843137254902,.5607843137254902,1],royalblue:[.2549019607843137,.4117647058823529,.8823529411764706,1],saddlebrown:[.5450980392156862,.27058823529411763,.07450980392156863,1],salmon:[.9803921568627451,.5019607843137255,.4470588235294118,1],sandybrown:[.9568627450980393,.6431372549019608,.3764705882352941,1],seagreen:[.1803921568627451,.5450980392156862,.3411764705882353,1],seashell:[1,.9607843137254902,.9333333333333333,1],sienna:[.6274509803921569,.3215686274509804,.17647058823529413,1],skyblue:[.5294117647058824,.807843137254902,.9215686274509803,1],slateblue:[.41568627450980394,.35294117647058826,.803921568627451,1],slategray:[.4392156862745098,.5019607843137255,.5647058823529412,1],slategrey:[.4392156862745098,.5019607843137255,.5647058823529412,1],snow:[1,.9803921568627451,.9803921568627451,1],springgreen:[0,1,.4980392156862745,1],steelblue:[.27450980392156865,.5098039215686274,.7058823529411765,1],tan:[.8235294117647058,.7058823529411765,.5490196078431373,1],thistle:[.8470588235294118,.7490196078431373,.8470588235294118,1],tomato:[1,.38823529411764707,.2784313725490196,1],turquoise:[.25098039215686274,.8784313725490196,.8156862745098039,1],violet:[.9333333333333333,.5098039215686274,.9333333333333333,1],wheat:[.9607843137254902,.8705882352941177,.7019607843137254,1],whitesmoke:[.9607843137254902,.9607843137254902,.9607843137254902,1],yellowgreen:[.6039215686274509,.803921568627451,.19607843137254902,1],rebeccapurple:[.4,.2,.6,1]},A=l0;var s0=/-?[0-9.]+%?/g,i0=/^#?[0-9a-f]{3,8}$/i,u0=16**6,N=16**4,z=16**2;function h(t){let e=h0(t),n={get hex(){let r="#";return r+=m(Math.round(e[0]*255).toString(16),2),r+=m(Math.round(e[1]*255).toString(16),2),r+=m(Math.round(e[2]*255).toString(16),2),e[3]<1&&(r+=m(Math.round(e[3]*255).toString(16),2)),r},get hexVal(){let r=Math.round(e[0]*255),a=Math.round(e[1]*255),o=Math.round(e[2]*255),l=Math.round(e[3]*255);return e[3]<1?r+256**3+a+256**2+o+256+l:r+256**2+a+256+o},get rgb(){return _(e)},rgbVal:e,get rgba(){return _(e)},rgbaVal:e,get linearRGB(){return M(e)},get p3(){return G("display-p3",e)},p3Val:e,get oklab(){return G("oklab",k(e))},get oklabVal(){return k(e)},get oklch(){return G("oklch",w(e))},get oklchVal(){return w(e)}};return n.toString=()=>n.hex,n}function c0(t){if(t>u0)throw new Error("better-color-tools can\u2019t parse hex numbers with alpha (0x0000000 is indistinguishable from 0x00000000). Please use hex string, or another color method");let e=t,n=Math.floor(e/N);e-=n*N;let r=Math.floor(e/z);e-=r*z;let a=e;return[n/255,r/255,a/255,1]}function f(t,e){let n=t.match(s0);if(!n)throw new Error(`Unexpected color format: ${t}`);let r=[0,0,0,1];return n.forEach((a,o)=>{a.includes("%")?r[o]=parseFloat(a)/100:e[o]===1/0?r[o]=parseFloat(a):r[o]=parseFloat(a)/(e[o]||1)}),r}function h0(t){if(Array.isArray(t)){if(t.some(e=>typeof e!="number"))throw new Error(`Color array must be numbers, received ${t}`);if(t.length<3||t.length>4)throw new Error(`Expected [R, G, B, A?], received ${t}`);return[s(t[0],0,1),s(t[1],0,1),s(t[2],0,1),typeof t[3]=="number"?s(t[3],0,1):1]}if(typeof t=="number")return c0(t);if(typeof t=="string"){let e=t.trim();if(!e)throw new Error("Expected color, received empty string");if(A[e.toLowerCase()])return A[e.toLowerCase()];if(i0.test(e)){let a=e.replace("#",""),o=[0,0,0,1];if(a.length>=6)for(let l=0;l<a.length/2;l++){let i=l*2,c=i+2,u=a.substring(i,c);o[l]=parseInt(u,16)/255}else for(let l=0;l<a.length;l++){let i=a.charAt(l);o[l]=parseInt(`${i}${i}`,16)/255}return o}let[n,r]=e.split("(");if(n==="color"){let a=r.indexOf(" ");n=r.substring(0,a),r=r.substring(a)}switch(n){case"rgb":case"rgba":case"srgb":{let[a,o,l,i]=f(r,[255,255,255,1]);return[s(a,0,1),s(o,0,1),s(l,0,1),s(i,0,1)]}case"srgb-linear":{let[a,o,l,i]=f(r,[255,255,255,1]);return b([s(a,0,1),s(o,0,1),s(l,0,1),s(i,0,1)])}case"hsl":{let[a,o,l,i]=f(r,[1/0,1,1,1]);return q([a,s(o,0,1),s(l,0,1),s(i,0,1)])}case"p3":case"display-p3":{let[a,o,l,i]=f(r,[1,1,1,1]);return[s(a,0,1),s(o,0,1),s(l,0,1),s(i,0,1)]}case"luv":return S(f(r,[1,1,1,1]));case"oklab":return T(f(r,[1,1,1,1]));case"oklch":return v(f(r,[1,1,1/0,1]))}}throw new Error(`Unable to parse color "${t}"`)}function F(t){return p(h(t).oklabVal[0],5)}function x(t,e,n=.5,r="oklab"){let a=s(n,0,1);if(n===0)return h(t);if(n===1)return h(e);let o=1-a,l=a,i={oklch:w,oklab:k,linearRGB:M,sRGB:E=>E},c={oklch:v,oklab:T,linearRGB:b,sRGB:E=>E},u=i[r],g=c[r];if(!u)throw new Error(`Unknown color space "${r}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let R=h(t).rgbVal,y=h(e).rgbVal;r==="oklch"&&(R[0]===R[1]&&R[1]===R[2]||y[0]===y[1]&&y[1]===y[2])&&(u=i.oklab,g=c.oklab);let[P,X,L,D]=u(R),[Y,Z,B,H]=u(y);return r==="oklch"&&Math.abs(B-L)>180&&(Math.max(L,B)===B?B-=360:L-=360),h(g([P*o+Y*l,X*o+Z*l,L*o+B*l,D*o+H*l]))}function $(t,e,n="oklab"){let r=s(e,-1,1);return r>=0?x(t,"black",r,n):O(t,-r)}function O(t,e,n="oklab"){let r=s(e,-1,1);return r>=0?x(t,"white",r,n):$(t,-r)}var $0={darken:$,from:h,lighten:O,lightness:F,mix:x};export{s as clamp,G as colorFn,$ as darken,$0 as default,h as from,m as leftPad,O as lighten,F as lightness,x as mix,_ as rgbFn,p as round};
function m(t,e=2){let n=t;for(;n.length<e;)n=`0${n}`;return n}function q(t){return t*(Math.PI/180)}function S(t){return t*(180/Math.PI)}function s(t,e,n){return Math.min(Math.max(t,e),n)}function G(t,e){return`color(${t} ${p(e[0],5)} ${p(e[1],5)} ${p(e[2],5)}${e[3]<1?`/${p(e[3],5)}`:""})`}function d(t,e){let n=[...t];for(let r=0;r<e.length;r++){let a=0;for(let o=0;o<e[0].length;o++)a+=t[o]*e[r][o];n[r]=a}return n}function p(t,e=2){let n=10**e;return Math.round(t*n)/n}function v(t){let e=`${Math.round(t[0]*255)}, ${Math.round(t[1]*255)}, ${Math.round(t[2]*255)}`;return t[3]!==1?`rgba(${e}, ${p(t[3],5)})`:`rgb(${e})`}var U=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],K=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]];var j=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],J=[[1,.3963377774,.2158037573],[1,-.1055613458,-.0638541728],[1,-.0894841775,-1.291485548]],Q=[[3.2406,-1.5372,-.4986],[-.9689,1.8758,.0415],[.0557,-.204,1.057]];function N(t){let[e,n,r,a]=t;e=Math.abs(e%360);let o=n*(1-Math.abs(2*r-1)),l=o*(1-Math.abs(e/60%2-1)),i=0,c=0,u=0;0<=e&&e<60?(i=o,c=l):60<=e&&e<120?(i=l,c=o):120<=e&&e<180?(c=o,u=l):180<=e&&e<240?(c=l,u=o):240<=e&&e<300?(i=l,u=o):300<=e&&e<360&&(i=o,u=l);let g=r-o/2;return[i+g,c+g,u+g,a]}function W(t){let[e,n,r,a]=t,o=n===0&&r===0?0:S(Math.atan2(r,n));return[e,Math.sqrt(n**2+r**2),o<0?o+360:o,a]}function C(t){let[e,n,r,a]=t,o=q(r);return[e,n*Math.cos(o),n*Math.sin(o),a]}function e0(t){let e=Math.cbrt(t[0]),n=Math.cbrt(t[1]),r=Math.cbrt(t[2]),a=t[3];return d([e,n,r,a],U)}function t0(t){let[e,n,r,a]=d(t,K);return[Math.max(0,e),Math.max(0,n),Math.max(0,r),Math.max(0,a)]}function b(t){return t.map((e,n)=>n===3?s(e,0,1):e<=.0031308?s(e*12.92,0,1):s(1.055*e**(1/2.4)-.055,0,1))}function r0(t){return d(t,j)}function n0(t){let[e,n,r,a]=t,o=[0,0,0,a],l=n/(13*e),i=r/(13*e);return o[1]=e<=8?e*(3/29)**3:((e+16)/116)**3,o[0]=o[1]*(9/4)*l,o[2]=o[1]*((12-3*l-20*i)/4*i),o}function z(t){return b(a0(n0(t)))}function o0(t){let e=d(t,J);return[e[0]**3,e[1]**3,e[2]**3,e[3]]}function T(t){return b(t0(o0(t)))}function _(t){return T(C(t))}function M(t){return t.map((e,n)=>n===3?e:e<=.04045?e/12.92:((e+.055)/1.055)**2.4)}function x(t){return e0(r0(M(t)))}function w(t){return W(x(t))}function a0(t){return d(t,Q)}var l0={black:[0,0,0,1],silver:[.75,.75,.75,1],gray:[.5,.5,.5,1],white:[1,1,1,1],maroon:[.5,0,0,1],red:[1,0,0,1],purple:[.5,0,.5,1],fuchsia:[1,0,1,1],green:[0,.5,0,1],lime:[0,1,0,1],olive:[.5,.5,0,1],yellow:[1,1,0,1],navy:[0,0,.5,1],blue:[0,0,1,1],teal:[0,.5,.5,1],aqua:[0,1,1,1],orange:[1,.6470588235294118,0,1],aliceblue:[.9411764705882353,.9725490196078431,1,1],antiquewhite:[.9803921568627451,.9215686274509803,.8431372549019608,1],aquamarine:[.4980392156862745,1,.8313725490196079,1],azure:[.9411764705882353,1,1,1],beige:[.9607843137254902,.9607843137254902,.8627450980392157,1],bisque:[1,.8941176470588236,.7686274509803922,1],blanchedalmond:[1,.9215686274509803,.803921568627451,1],blueviolet:[.5411764705882353,.16862745098039217,.8862745098039215,1],brown:[.6470588235294118,.16470588235294117,.16470588235294117,1],burlywood:[.8705882352941177,.7215686274509804,.5294117647058824,1],cadetblue:[.37254901960784315,.6196078431372549,.6274509803921569,1],chartreuse:[.4980392156862745,1,0,1],chocolate:[.8235294117647058,.4117647058823529,.11764705882352941,1],coral:[1,.4980392156862745,.3137254901960784,1],cornflowerblue:[.39215686274509803,.5843137254901961,.9294117647058824,1],cornsilk:[1,.9725490196078431,.8627450980392157,1],crimson:[.8627450980392157,.0784313725490196,.23529411764705882,1],cyan:[0,1,1,1],darkblue:[0,0,.5450980392156862,1],darkcyan:[0,.5450980392156862,.5450980392156862,1],darkgoldenrod:[.7215686274509804,.5254901960784314,.043137254901960784,1],darkgray:[.6627450980392157,.6627450980392157,.6627450980392157,1],darkgreen:[0,.39215686274509803,0,1],darkgrey:[.6627450980392157,.6627450980392157,.6627450980392157,1],darkkhaki:[.7411764705882353,.7176470588235294,.4196078431372549,1],darkmagenta:[.5450980392156862,0,.5450980392156862,1],darkolivegreen:[.3333333333333333,.4196078431372549,.1843137254901961,1],darkorange:[1,.5490196078431373,0,1],darkorchard:[.6,.19607843137254902,.8,1],darkred:[.5450980392156862,0,0,1],darksalmon:[.9137254901960784,.5882352941176471,.47843137254901963,1],darkseagreen:[.5607843137254902,.7372549019607844,.5607843137254902,1],darkslateblue:[.2823529411764706,.23921568627450981,.5450980392156862,1],darkslategray:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkslategrey:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkturquoise:[.1843137254901961,.30980392156862746,.30980392156862746,1],darkviolet:[.5803921568627451,0,.8274509803921568,1],deeppink:[1,.0784313725490196,.5764705882352941,1],deepskyblue:[0,.7490196078431373,1,1],dimgray:[.4117647058823529,.4117647058823529,.4117647058823529,1],dimgrey:[.4117647058823529,.4117647058823529,.4117647058823529,1],dodgerblue:[.11764705882352941,.5647058823529412,1,1],firebrick:[.6980392156862745,.13333333333333333,.13333333333333333,1],floralwhite:[1,.9803921568627451,.9411764705882353,1],forestgreen:[.13333333333333333,.5450980392156862,.13333333333333333,1],gainsboro:[.8627450980392157,.8627450980392157,.8627450980392157,1],ghostwhite:[.9725490196078431,.9725490196078431,1,1],gold:[1,.8431372549019608,0,1],goldenrod:[.8549019607843137,.6470588235294118,.12549019607843137,1],greenyellow:[.6784313725490196,1,.1843137254901961,1],grey:[.5019607843137255,.5019607843137255,.5019607843137255,1],honeydew:[.9411764705882353,1,.9411764705882353,1],hotpink:[1,.4117647058823529,.7058823529411765,1],indianred:[.803921568627451,.3607843137254902,.3607843137254902,1],indigo:[.29411764705882354,0,.5098039215686274,1],ivory:[1,1,.9411764705882353,1],khaki:[.9411764705882353,.9019607843137255,.5490196078431373,1],lavendar:[.9019607843137255,.9019607843137255,.9803921568627451,1],lavenderblush:[1,.9411764705882353,.9607843137254902,1],lawngreen:[.48627450980392156,.9882352941176471,0,1],lemonchiffon:[1,.9803921568627451,.803921568627451,1],lightblue:[.6784313725490196,.8470588235294118,.9019607843137255,1],lightcoral:[.9411764705882353,.5019607843137255,.5019607843137255,1],lightcyan:[.8784313725490196,1,1,1],lightgoldenrodyellow:[.9803921568627451,.9803921568627451,.8235294117647058,1],lightgray:[.8274509803921568,.8274509803921568,.8274509803921568,1],lightgreen:[.5647058823529412,.9333333333333333,.5647058823529412,1],lightgrey:[.8274509803921568,.8274509803921568,.8274509803921568,1],lightpink:[1,.7137254901960784,.7568627450980392,1],lightsalmon:[1,.6274509803921569,.47843137254901963,1],lightseagreen:[.12549019607843137,.6980392156862745,.6666666666666666,1],lightskyblue:[.5294117647058824,.807843137254902,.9803921568627451,1],lightslategray:[.4666666666666667,.5333333333333333,.6,1],lightslategrey:[.4666666666666667,.5333333333333333,.6,1],lightsteelblue:[.6901960784313725,.7686274509803922,.8705882352941177,1],lightyellow:[1,1,.8784313725490196,1],limegreen:[.19607843137254902,.803921568627451,.19607843137254902,1],linen:[.9803921568627451,.9411764705882353,.9019607843137255,1],magenta:[1,0,1,1],mediumaquamarine:[.4,.803921568627451,.6666666666666666,1],mediumblue:[0,0,.803921568627451,1],mediumorchid:[.7294117647058823,.3333333333333333,.8274509803921568,1],mediumpurple:[.5764705882352941,.4392156862745098,.8588235294117647,1],mediumseagreen:[.23529411764705882,.7019607843137254,.44313725490196076,1],mediumslateblue:[.4823529411764706,.40784313725490196,.9333333333333333,1],mediumspringgreen:[0,.9803921568627451,.6039215686274509,1],mediumturquoise:[.2823529411764706,.8196078431372549,.8,1],mediumvioletred:[.7803921568627451,.08235294117647059,.5215686274509804,1],midnightblue:[.09803921568627451,.09803921568627451,.4392156862745098,1],mintcream:[.9607843137254902,1,.9803921568627451,1],mistyrose:[1,.8941176470588236,.8823529411764706,1],moccasin:[1,.8941176470588236,.7098039215686275,1],navajowhite:[1,.8705882352941177,.6784313725490196,1],oldlace:[.9921568627450981,.9607843137254902,.9019607843137255,1],olivedrab:[.4196078431372549,.5568627450980392,.13725490196078433,1],orangered:[1,.27058823529411763,0,1],orchid:[.8549019607843137,.4392156862745098,.8392156862745098,1],palegoldenrod:[.9333333333333333,.9098039215686274,.6666666666666666,1],palegreen:[.596078431372549,.984313725490196,.596078431372549,1],paleturquoise:[.6862745098039216,.9333333333333333,.9333333333333333,1],palevioletred:[.8588235294117647,.4392156862745098,.5764705882352941,1],papayawhip:[1,.9372549019607843,.8352941176470589,1],peachpuff:[1,.8549019607843137,.7254901960784313,1],peru:[.803921568627451,.5215686274509804,.24705882352941178,1],pink:[1,.7529411764705882,.796078431372549,1],plum:[.8666666666666667,.6274509803921569,.8666666666666667,1],powderblue:[.6901960784313725,.8784313725490196,.9019607843137255,1],rosybrown:[.7372549019607844,.5607843137254902,.5607843137254902,1],royalblue:[.2549019607843137,.4117647058823529,.8823529411764706,1],saddlebrown:[.5450980392156862,.27058823529411763,.07450980392156863,1],salmon:[.9803921568627451,.5019607843137255,.4470588235294118,1],sandybrown:[.9568627450980393,.6431372549019608,.3764705882352941,1],seagreen:[.1803921568627451,.5450980392156862,.3411764705882353,1],seashell:[1,.9607843137254902,.9333333333333333,1],sienna:[.6274509803921569,.3215686274509804,.17647058823529413,1],skyblue:[.5294117647058824,.807843137254902,.9215686274509803,1],slateblue:[.41568627450980394,.35294117647058826,.803921568627451,1],slategray:[.4392156862745098,.5019607843137255,.5647058823529412,1],slategrey:[.4392156862745098,.5019607843137255,.5647058823529412,1],snow:[1,.9803921568627451,.9803921568627451,1],springgreen:[0,1,.4980392156862745,1],steelblue:[.27450980392156865,.5098039215686274,.7058823529411765,1],tan:[.8235294117647058,.7058823529411765,.5490196078431373,1],thistle:[.8470588235294118,.7490196078431373,.8470588235294118,1],tomato:[1,.38823529411764707,.2784313725490196,1],turquoise:[.25098039215686274,.8784313725490196,.8156862745098039,1],violet:[.9333333333333333,.5098039215686274,.9333333333333333,1],wheat:[.9607843137254902,.8705882352941177,.7019607843137254,1],whitesmoke:[.9607843137254902,.9607843137254902,.9607843137254902,1],yellowgreen:[.6039215686274509,.803921568627451,.19607843137254902,1],rebeccapurple:[.4,.2,.6,1]},A=l0;var s0=/-?[0-9.]+%?/g,i0=/^#?[0-9a-f]{3,8}$/i,u0=16**6,F=16**4,I=16**2;function h(t){let e=h0(t),n={get hex(){let r="#";return r+=m(Math.round(e[0]*255).toString(16),2),r+=m(Math.round(e[1]*255).toString(16),2),r+=m(Math.round(e[2]*255).toString(16),2),e[3]<1&&(r+=m(Math.round(e[3]*255).toString(16),2)),r},get hexVal(){e[3]<1&&console.warn(`hexVal converted a semi-transparent color (${e[3]*100}%) to fully opaque`);let r=Math.round(e[0]*255),a=Math.round(e[1]*255),o=Math.round(e[2]*255);return r*F+a*I+o},get rgb(){return v(e)},rgbVal:e,get rgba(){return v(e)},rgbaVal:e,get linearRGB(){return M(e)},get p3(){return G("display-p3",e)},p3Val:e,get oklab(){return G("oklab",x(e))},get oklabVal(){return x(e)},get oklch(){return G("oklch",w(e))},get oklchVal(){return w(e)}};return n.toString=()=>n.hex,n}function c0(t){if(t>u0)throw new Error("better-color-tools can\u2019t parse hex numbers with alpha (0x0000000 is indistinguishable from 0x00000000). Please use hex string, or another color method");let e=t,n=Math.floor(e/F);e-=n*F;let r=Math.floor(e/I);e-=r*I;let a=e;return[n/255,r/255,a/255,1]}function f(t,e){let n=t.match(s0);if(!n)throw new Error(`Unexpected color format: ${t}`);let r=[0,0,0,1];return n.forEach((a,o)=>{a.includes("%")?r[o]=parseFloat(a)/100:e[o]===1/0?r[o]=parseFloat(a):r[o]=parseFloat(a)/(e[o]||1)}),r}function h0(t){if(Array.isArray(t)){if(t.some(e=>typeof e!="number"))throw new Error(`Color array must be numbers, received ${t}`);if(t.length<3||t.length>4)throw new Error(`Expected [R, G, B, A?], received ${t}`);return[s(t[0],0,1),s(t[1],0,1),s(t[2],0,1),typeof t[3]=="number"?s(t[3],0,1):1]}if(typeof t=="number")return c0(t);if(typeof t=="string"){let e=t.trim();if(!e)throw new Error("Expected color, received empty string");if(A[e.toLowerCase()])return A[e.toLowerCase()];if(i0.test(e)){let a=e.replace("#",""),o=[0,0,0,1];if(a.length>=6)for(let l=0;l<a.length/2;l++){let i=l*2,c=i+2,u=a.substring(i,c);o[l]=parseInt(u,16)/255}else for(let l=0;l<a.length;l++){let i=a.charAt(l);o[l]=parseInt(`${i}${i}`,16)/255}return o}let[n,r]=e.split("(");if(n==="color"){let a=r.indexOf(" ");n=r.substring(0,a),r=r.substring(a)}switch(n){case"rgb":case"rgba":case"srgb":{let[a,o,l,i]=f(r,[255,255,255,1]);return[s(a,0,1),s(o,0,1),s(l,0,1),s(i,0,1)]}case"srgb-linear":{let[a,o,l,i]=f(r,[255,255,255,1]);return b([s(a,0,1),s(o,0,1),s(l,0,1),s(i,0,1)])}case"hsl":{let[a,o,l,i]=f(r,[1/0,1,1,1]);return N([a,s(o,0,1),s(l,0,1),s(i,0,1)])}case"p3":case"display-p3":{let[a,o,l,i]=f(r,[1,1,1,1]);return[s(a,0,1),s(o,0,1),s(l,0,1),s(i,0,1)]}case"luv":return z(f(r,[1,1,1,1]));case"oklab":return T(f(r,[1,1,1,1]));case"oklch":return _(f(r,[1,1,1/0,1]))}}throw new Error(`Unable to parse color "${t}"`)}function V(t){return p(h(t).oklabVal[0],5)}function k(t,e,n=.5,r="oklab"){let a=s(n,0,1);if(n===0)return h(t);if(n===1)return h(e);let o=1-a,l=a,i={oklch:w,oklab:x,linearRGB:M,sRGB:E=>E},c={oklch:_,oklab:T,linearRGB:b,sRGB:E=>E},u=i[r],g=c[r];if(!u)throw new Error(`Unknown color space "${r}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let R=h(t).rgbVal,y=h(e).rgbVal;r==="oklch"&&(R[0]===R[1]&&R[1]===R[2]||y[0]===y[1]&&y[1]===y[2])&&(u=i.oklab,g=c.oklab);let[P,X,L,D]=u(R),[Y,Z,B,H]=u(y);return r==="oklch"&&Math.abs(B-L)>180&&(Math.max(L,B)===B?B-=360:L-=360),h(g([P*o+Y*l,X*o+Z*l,L*o+B*l,D*o+H*l]))}function $(t,e,n="oklab"){let r=s(e,-1,1);return r>=0?k(t,"black",r,n):O(t,-r)}function O(t,e,n="oklab"){let r=s(e,-1,1);return r>=0?k(t,"white",r,n):$(t,-r)}var $0={darken:$,from:h,lighten:O,lightness:V,mix:k};export{s as clamp,G as colorFn,$ as darken,$0 as default,h as from,m as leftPad,O as lighten,V as lightness,k as mix,v as rgbFn,p as round};

@@ -37,9 +37,8 @@ import { hslTosRGB, linearRGBTosRGB, luvTosRGB, oklabTosRGB, oklchTosRGB, sRGBToLinearRGB, sRGBToOklab, sRGBToOklch } from './colorspace.js';

get hexVal() {
if (color[3] < 1)
console.warn(`hexVal converted a semi-transparent color (${color[3] * 100}%) to fully opaque`);
const r = Math.round(color[0] * 255);
const g = Math.round(color[1] * 255);
const b = Math.round(color[2] * 255);
const a = Math.round(color[3] * 255);
if (color[3] < 1)
return r + 256 ** 3 + g + 256 ** 2 + b + 256 + a;
return r + 256 ** 2 + g + 256 + b;
return r * R_FACTOR + g * G_FACTOR + b;
},

@@ -46,0 +45,0 @@ // get luv(): string {

{
"name": "better-color-tools",
"description": "Better color manipulation for Sass and JavaScript / TypeScript.",
"version": "0.6.2",
"version": "0.6.3",
"author": {

@@ -6,0 +6,0 @@ "name": "Drew Powers",

@@ -75,8 +75,7 @@ import type { Color, LinearRGB, Oklab, Oklch, sRGB } from './colorspace.js';

get hexVal(): number {
if (color[3] < 1) console.warn(`hexVal converted a semi-transparent color (${color[3] * 100}%) to fully opaque`);
const r = Math.round(color[0] * 255);
const g = Math.round(color[1] * 255);
const b = Math.round(color[2] * 255);
const a = Math.round(color[3] * 255);
if (color[3] < 1) return r + 256 ** 3 + g + 256 ** 2 + b + 256 + a;
return r + 256 ** 2 + g + 256 + b;
return r * R_FACTOR + g * G_FACTOR + b;
},

@@ -83,0 +82,0 @@ // get luv(): string {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc