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.0 to 0.6.1

6

CHANGELOG.md
# better-color-tools
## 0.6.1
### Patch Changes
- 7ecdf62: fix hex rounding error, color() fn parse error, improve perf
## 0.6.0

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

152

dist/css-names.d.ts

@@ -1,151 +0,3 @@

declare const names: {
black: number;
silver: number;
gray: number;
white: number;
maroon: number;
red: number;
purple: number;
fuchsia: number;
green: number;
lime: number;
olive: number;
yellow: number;
navy: number;
blue: number;
teal: number;
aqua: number;
orange: number;
aliceblue: number;
antiquewhite: number;
aquamarine: number;
azure: number;
beige: number;
bisque: number;
blanchedalmond: number;
blueviolet: number;
brown: number;
burlywood: number;
cadetblue: number;
chartreuse: number;
chocolate: number;
coral: number;
cornflowerblue: number;
cornsilk: number;
crimson: number;
cyan: number;
darkblue: number;
darkcyan: number;
darkgoldenrod: number;
darkgray: number;
darkgreen: number;
darkgrey: number;
darkkhaki: number;
darkmagenta: number;
darkolivegreen: number;
darkorange: number;
darkorchard: number;
darkred: number;
darksalmon: number;
darkseagreen: number;
darkslateblue: number;
darkslategray: number;
darkslategrey: number;
darkturquoise: number;
darkviolet: number;
deeppink: number;
deepskyblue: number;
dimgray: number;
dimgrey: number;
dodgerblue: number;
firebrick: number;
floralwhite: number;
forestgreen: number;
gainsboro: number;
ghostwhite: number;
gold: number;
goldenrod: number;
greenyellow: number;
grey: number;
honeydew: number;
hotpink: number;
indianred: number;
indigo: number;
ivory: number;
khaki: number;
lavendar: number;
lavenderblush: number;
lawngreen: number;
lemonchiffon: number;
lightblue: number;
lightcoral: number;
lightcyan: number;
lightgoldenrodyellow: number;
lightgray: number;
lightgreen: number;
lightgrey: number;
lightpink: number;
lightsalmon: number;
lightseagreen: number;
lightskyblue: number;
lightslategray: number;
lightslategrey: number;
lightsteelblue: number;
lightyellow: number;
limegreen: number;
linen: number;
magenta: number;
mediumaquamarine: number;
mediumblue: number;
mediumorchid: number;
mediumpurple: number;
mediumseagreen: number;
mediumslateblue: number;
mediumspringgreen: number;
mediumturquoise: number;
mediumvioletred: number;
midnightblue: number;
mintcream: number;
mistyrose: number;
moccasin: number;
navajowhite: number;
oldlace: number;
olivedrab: number;
orangered: number;
orchid: number;
palegoldenrod: number;
palegreen: number;
paleturquoise: number;
palevioletred: number;
papayawhip: number;
peachpuff: number;
peru: number;
pink: number;
plum: number;
powderblue: number;
rosybrown: number;
royalblue: number;
saddlebrown: number;
salmon: number;
sandybrown: number;
seagreen: number;
seashell: number;
sienna: number;
skyblue: number;
slateblue: number;
slategray: number;
slategrey: number;
snow: number;
springgreen: number;
steelblue: number;
tan: number;
thistle: number;
tomato: number;
turquoise: number;
violet: number;
wheat: number;
whitesmoke: number;
yellowgreen: number;
rebeccapurple: number;
};
import type { sRGB } from './colorspace';
declare const names: Record<string, sRGB>;
export default names;
const names = {
// CSS Level 1
black: 0x000000,
silver: 0xc0c0c0,
gray: 0x808080,
white: 0xffffff,
maroon: 0x800000,
red: 0xff0000,
purple: 0x800080,
fuchsia: 0xff00ff,
green: 0x008000,
lime: 0x00ff00,
olive: 0x808000,
yellow: 0xffff00,
navy: 0x000080,
blue: 0x0000ff,
teal: 0x008080,
aqua: 0x00ffff,
black: [0, 0, 0, 1],
silver: [0.75, 0.75, 0.75, 1],
gray: [0.5, 0.5, 0.5, 1],
white: [1, 1, 1, 1],
maroon: [0.5, 0, 0, 1],
red: [1, 0, 0, 1],
purple: [0.5, 0, 0.5, 1],
fuchsia: [1, 0, 1, 1],
green: [0, 0.5, 0, 1],
lime: [0, 1, 0, 1],
olive: [0.5, 0.5, 0, 1],
yellow: [1, 1, 0, 1],
navy: [0, 0, 0.5, 1],
blue: [0, 0, 1, 1],
teal: [0, 0.5, 0.5, 1],
aqua: [0, 1, 1, 1],
// CSS Level 2 (Revision 1)
orange: 0xffa500,
orange: [1, 0.6470588235294118, 0, 1],
// CSS Color Module Level 3
aliceblue: 0xf0f8ff,
antiquewhite: 0xfaebd7,
aquamarine: 0x7fffd4,
azure: 0xf0ffff,
beige: 0xf5f5dc,
bisque: 0xffe4c4,
blanchedalmond: 0xffebcd,
blueviolet: 0x8a2be2,
brown: 0xa52a2a,
burlywood: 0xdeb887,
cadetblue: 0x5f9ea0,
chartreuse: 0x7fff00,
chocolate: 0xd2691e,
coral: 0xff7f50,
cornflowerblue: 0x6495ed,
cornsilk: 0xfff8dc,
crimson: 0xdc143c,
cyan: 0x00ffff,
darkblue: 0x00008b,
darkcyan: 0x008b8b,
darkgoldenrod: 0xb8860b,
darkgray: 0xa9a9a9,
darkgreen: 0x006400,
darkgrey: 0xa9a9a9,
darkkhaki: 0xbdb76b,
darkmagenta: 0x8b008b,
darkolivegreen: 0x556b2f,
darkorange: 0xff8c00,
darkorchard: 0x9932cc,
darkred: 0x8b0000,
darksalmon: 0xe9967a,
darkseagreen: 0x8fbc8f,
darkslateblue: 0x483d8b,
darkslategray: 0x2f4f4f,
darkslategrey: 0x2f4f4f,
darkturquoise: 0x2f4f4f,
darkviolet: 0x9400d3,
deeppink: 0xff1493,
deepskyblue: 0x00bfff,
dimgray: 0x696969,
dimgrey: 0x696969,
dodgerblue: 0x1e90ff,
firebrick: 0xb22222,
floralwhite: 0xfffaf0,
forestgreen: 0x228b22,
gainsboro: 0xdcdcdc,
ghostwhite: 0xf8f8ff,
gold: 0xffd700,
goldenrod: 0xdaa520,
greenyellow: 0xadff2f,
grey: 0x808080,
honeydew: 0xf0fff0,
hotpink: 0xff69b4,
indianred: 0xcd5c5c,
indigo: 0x4b0082,
ivory: 0xfffff0,
khaki: 0xf0e68c,
lavendar: 0xe6e6fa,
lavenderblush: 0xfff0f5,
lawngreen: 0x7cfc00,
lemonchiffon: 0xfffacd,
lightblue: 0xadd8e6,
lightcoral: 0xf08080,
lightcyan: 0xe0ffff,
lightgoldenrodyellow: 0xfafad2,
lightgray: 0xd3d3d3,
lightgreen: 0x90ee90,
lightgrey: 0xd3d3d3,
lightpink: 0xffb6c1,
lightsalmon: 0xffa07a,
lightseagreen: 0x20b2aa,
lightskyblue: 0x87cefa,
lightslategray: 0x778899,
lightslategrey: 0x778899,
lightsteelblue: 0xb0c4de,
lightyellow: 0xffffe0,
limegreen: 0x32cd32,
linen: 0xfaf0e6,
magenta: 0xff00ff,
mediumaquamarine: 0x66cdaa,
mediumblue: 0x0000cd,
mediumorchid: 0xba55d3,
mediumpurple: 0x9370db,
mediumseagreen: 0x3cb371,
mediumslateblue: 0x7b68ee,
mediumspringgreen: 0x00fa9a,
mediumturquoise: 0x48d1cc,
mediumvioletred: 0xc71585,
midnightblue: 0x191970,
mintcream: 0xf5fffa,
mistyrose: 0xffe4e1,
moccasin: 0xffe4b5,
navajowhite: 0xffdead,
oldlace: 0xfdf5e6,
olivedrab: 0x6b8e23,
orangered: 0xff4500,
orchid: 0xda70d6,
palegoldenrod: 0xeee8aa,
palegreen: 0x98fb98,
paleturquoise: 0xafeeee,
palevioletred: 0xdb7093,
papayawhip: 0xffefd5,
peachpuff: 0xffdab9,
peru: 0xcd853f,
pink: 0xffc0cb,
plum: 0xdda0dd,
powderblue: 0xb0e0e6,
rosybrown: 0xbc8f8f,
royalblue: 0x4169e1,
saddlebrown: 0x8b4513,
salmon: 0xfa8072,
sandybrown: 0xf4a460,
seagreen: 0x2e8b57,
seashell: 0xfff5ee,
sienna: 0xa0522d,
skyblue: 0x87ceeb,
slateblue: 0x6a5acd,
slategray: 0x708090,
slategrey: 0x708090,
snow: 0xfffafa,
springgreen: 0x00ff7f,
steelblue: 0x4682b4,
tan: 0xd2b48c,
thistle: 0xd8bfd8,
tomato: 0xff6347,
turquoise: 0x40e0d0,
violet: 0xee82ee,
wheat: 0xf5deb3,
whitesmoke: 0xf5f5f5,
yellowgreen: 0x9acd32,
aliceblue: [0.9411764705882353, 0.9725490196078431, 1, 1],
antiquewhite: [0.9803921568627451, 0.9215686274509803, 0.8431372549019608, 1],
aquamarine: [0.4980392156862745, 1, 0.8313725490196079, 1],
azure: [0.9411764705882353, 1, 1, 1],
beige: [0.9607843137254902, 0.9607843137254902, 0.8627450980392157, 1],
bisque: [1, 0.8941176470588236, 0.7686274509803922, 1],
blanchedalmond: [1, 0.9215686274509803, 0.803921568627451, 1],
blueviolet: [0.5411764705882353, 0.16862745098039217, 0.8862745098039215, 1],
brown: [0.6470588235294118, 0.16470588235294117, 0.16470588235294117, 1],
burlywood: [0.8705882352941177, 0.7215686274509804, 0.5294117647058824, 1],
cadetblue: [0.37254901960784315, 0.6196078431372549, 0.6274509803921569, 1],
chartreuse: [0.4980392156862745, 1, 0, 1],
chocolate: [0.8235294117647058, 0.4117647058823529, 0.11764705882352941, 1],
coral: [1, 0.4980392156862745, 0.3137254901960784, 1],
cornflowerblue: [0.39215686274509803, 0.5843137254901961, 0.9294117647058824, 1],
cornsilk: [1, 0.9725490196078431, 0.8627450980392157, 1],
crimson: [0.8627450980392157, 0.0784313725490196, 0.23529411764705882, 1],
cyan: [0, 1, 1, 1],
darkblue: [0, 0, 0.5450980392156862, 1],
darkcyan: [0, 0.5450980392156862, 0.5450980392156862, 1],
darkgoldenrod: [0.7215686274509804, 0.5254901960784314, 0.043137254901960784, 1],
darkgray: [0.6627450980392157, 0.6627450980392157, 0.6627450980392157, 1],
darkgreen: [0, 0.39215686274509803, 0, 1],
darkgrey: [0.6627450980392157, 0.6627450980392157, 0.6627450980392157, 1],
darkkhaki: [0.7411764705882353, 0.7176470588235294, 0.4196078431372549, 1],
darkmagenta: [0.5450980392156862, 0, 0.5450980392156862, 1],
darkolivegreen: [0.3333333333333333, 0.4196078431372549, 0.1843137254901961, 1],
darkorange: [1, 0.5490196078431373, 0, 1],
darkorchard: [0.6, 0.19607843137254902, 0.8, 1],
darkred: [0.5450980392156862, 0, 0, 1],
darksalmon: [0.9137254901960784, 0.5882352941176471, 0.47843137254901963, 1],
darkseagreen: [0.5607843137254902, 0.7372549019607844, 0.5607843137254902, 1],
darkslateblue: [0.2823529411764706, 0.23921568627450981, 0.5450980392156862, 1],
darkslategray: [0.1843137254901961, 0.30980392156862746, 0.30980392156862746, 1],
darkslategrey: [0.1843137254901961, 0.30980392156862746, 0.30980392156862746, 1],
darkturquoise: [0.1843137254901961, 0.30980392156862746, 0.30980392156862746, 1],
darkviolet: [0.5803921568627451, 0, 0.8274509803921568, 1],
deeppink: [1, 0.0784313725490196, 0.5764705882352941, 1],
deepskyblue: [0, 0.7490196078431373, 1, 1],
dimgray: [0.4117647058823529, 0.4117647058823529, 0.4117647058823529, 1],
dimgrey: [0.4117647058823529, 0.4117647058823529, 0.4117647058823529, 1],
dodgerblue: [0.11764705882352941, 0.5647058823529412, 1, 1],
firebrick: [0.6980392156862745, 0.13333333333333333, 0.13333333333333333, 1],
floralwhite: [1, 0.9803921568627451, 0.9411764705882353, 1],
forestgreen: [0.13333333333333333, 0.5450980392156862, 0.13333333333333333, 1],
gainsboro: [0.8627450980392157, 0.8627450980392157, 0.8627450980392157, 1],
ghostwhite: [0.9725490196078431, 0.9725490196078431, 1, 1],
gold: [1, 0.8431372549019608, 0, 1],
goldenrod: [0.8549019607843137, 0.6470588235294118, 0.12549019607843137, 1],
greenyellow: [0.6784313725490196, 1, 0.1843137254901961, 1],
grey: [0.5019607843137255, 0.5019607843137255, 0.5019607843137255, 1],
honeydew: [0.9411764705882353, 1, 0.9411764705882353, 1],
hotpink: [1, 0.4117647058823529, 0.7058823529411765, 1],
indianred: [0.803921568627451, 0.3607843137254902, 0.3607843137254902, 1],
indigo: [0.29411764705882354, 0, 0.5098039215686274, 1],
ivory: [1, 1, 0.9411764705882353, 1],
khaki: [0.9411764705882353, 0.9019607843137255, 0.5490196078431373, 1],
lavendar: [0.9019607843137255, 0.9019607843137255, 0.9803921568627451, 1],
lavenderblush: [1, 0.9411764705882353, 0.9607843137254902, 1],
lawngreen: [0.48627450980392156, 0.9882352941176471, 0, 1],
lemonchiffon: [1, 0.9803921568627451, 0.803921568627451, 1],
lightblue: [0.6784313725490196, 0.8470588235294118, 0.9019607843137255, 1],
lightcoral: [0.9411764705882353, 0.5019607843137255, 0.5019607843137255, 1],
lightcyan: [0.8784313725490196, 1, 1, 1],
lightgoldenrodyellow: [0.9803921568627451, 0.9803921568627451, 0.8235294117647058, 1],
lightgray: [0.8274509803921568, 0.8274509803921568, 0.8274509803921568, 1],
lightgreen: [0.5647058823529412, 0.9333333333333333, 0.5647058823529412, 1],
lightgrey: [0.8274509803921568, 0.8274509803921568, 0.8274509803921568, 1],
lightpink: [1, 0.7137254901960784, 0.7568627450980392, 1],
lightsalmon: [1, 0.6274509803921569, 0.47843137254901963, 1],
lightseagreen: [0.12549019607843137, 0.6980392156862745, 0.6666666666666666, 1],
lightskyblue: [0.5294117647058824, 0.807843137254902, 0.9803921568627451, 1],
lightslategray: [0.4666666666666667, 0.5333333333333333, 0.6, 1],
lightslategrey: [0.4666666666666667, 0.5333333333333333, 0.6, 1],
lightsteelblue: [0.6901960784313725, 0.7686274509803922, 0.8705882352941177, 1],
lightyellow: [1, 1, 0.8784313725490196, 1],
limegreen: [0.19607843137254902, 0.803921568627451, 0.19607843137254902, 1],
linen: [0.9803921568627451, 0.9411764705882353, 0.9019607843137255, 1],
magenta: [1, 0, 1, 1],
mediumaquamarine: [0.4, 0.803921568627451, 0.6666666666666666, 1],
mediumblue: [0, 0, 0.803921568627451, 1],
mediumorchid: [0.7294117647058823, 0.3333333333333333, 0.8274509803921568, 1],
mediumpurple: [0.5764705882352941, 0.4392156862745098, 0.8588235294117647, 1],
mediumseagreen: [0.23529411764705882, 0.7019607843137254, 0.44313725490196076, 1],
mediumslateblue: [0.4823529411764706, 0.40784313725490196, 0.9333333333333333, 1],
mediumspringgreen: [0, 0.9803921568627451, 0.6039215686274509, 1],
mediumturquoise: [0.2823529411764706, 0.8196078431372549, 0.8, 1],
mediumvioletred: [0.7803921568627451, 0.08235294117647059, 0.5215686274509804, 1],
midnightblue: [0.09803921568627451, 0.09803921568627451, 0.4392156862745098, 1],
mintcream: [0.9607843137254902, 1, 0.9803921568627451, 1],
mistyrose: [1, 0.8941176470588236, 0.8823529411764706, 1],
moccasin: [1, 0.8941176470588236, 0.7098039215686275, 1],
navajowhite: [1, 0.8705882352941177, 0.6784313725490196, 1],
oldlace: [0.9921568627450981, 0.9607843137254902, 0.9019607843137255, 1],
olivedrab: [0.4196078431372549, 0.5568627450980392, 0.13725490196078433, 1],
orangered: [1, 0.27058823529411763, 0, 1],
orchid: [0.8549019607843137, 0.4392156862745098, 0.8392156862745098, 1],
palegoldenrod: [0.9333333333333333, 0.9098039215686274, 0.6666666666666666, 1],
palegreen: [0.596078431372549, 0.984313725490196, 0.596078431372549, 1],
paleturquoise: [0.6862745098039216, 0.9333333333333333, 0.9333333333333333, 1],
palevioletred: [0.8588235294117647, 0.4392156862745098, 0.5764705882352941, 1],
papayawhip: [1, 0.9372549019607843, 0.8352941176470589, 1],
peachpuff: [1, 0.8549019607843137, 0.7254901960784313, 1],
peru: [0.803921568627451, 0.5215686274509804, 0.24705882352941178, 1],
pink: [1, 0.7529411764705882, 0.796078431372549, 1],
plum: [0.8666666666666667, 0.6274509803921569, 0.8666666666666667, 1],
powderblue: [0.6901960784313725, 0.8784313725490196, 0.9019607843137255, 1],
rosybrown: [0.7372549019607844, 0.5607843137254902, 0.5607843137254902, 1],
royalblue: [0.2549019607843137, 0.4117647058823529, 0.8823529411764706, 1],
saddlebrown: [0.5450980392156862, 0.27058823529411763, 0.07450980392156863, 1],
salmon: [0.9803921568627451, 0.5019607843137255, 0.4470588235294118, 1],
sandybrown: [0.9568627450980393, 0.6431372549019608, 0.3764705882352941, 1],
seagreen: [0.1803921568627451, 0.5450980392156862, 0.3411764705882353, 1],
seashell: [1, 0.9607843137254902, 0.9333333333333333, 1],
sienna: [0.6274509803921569, 0.3215686274509804, 0.17647058823529413, 1],
skyblue: [0.5294117647058824, 0.807843137254902, 0.9215686274509803, 1],
slateblue: [0.41568627450980394, 0.35294117647058826, 0.803921568627451, 1],
slategray: [0.4392156862745098, 0.5019607843137255, 0.5647058823529412, 1],
slategrey: [0.4392156862745098, 0.5019607843137255, 0.5647058823529412, 1],
snow: [1, 0.9803921568627451, 0.9803921568627451, 1],
springgreen: [0, 1, 0.4980392156862745, 1],
steelblue: [0.27450980392156865, 0.5098039215686274, 0.7058823529411765, 1],
tan: [0.8235294117647058, 0.7058823529411765, 0.5490196078431373, 1],
thistle: [0.8470588235294118, 0.7490196078431373, 0.8470588235294118, 1],
tomato: [1, 0.38823529411764707, 0.2784313725490196, 1],
turquoise: [0.25098039215686274, 0.8784313725490196, 0.8156862745098039, 1],
violet: [0.9333333333333333, 0.5098039215686274, 0.9333333333333333, 1],
wheat: [0.9607843137254902, 0.8705882352941177, 0.7019607843137254, 1],
whitesmoke: [0.9607843137254902, 0.9607843137254902, 0.9607843137254902, 1],
yellowgreen: [0.6039215686274509, 0.803921568627451, 0.19607843137254902, 1],
// CSS Color Module Level 4
rebeccapurple: 0x663399,
rebeccapurple: [0.4, 0.2, 0.6, 1],
};
export default names;

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

function b(r,e=2){let n=r;for(;n.length<e;)n=`0${n}`;return n}function A(r){return r*(Math.PI/180)}function V(r){return r*(180/Math.PI)}function l(r,e,n){return Math.min(Math.max(r,e),n)}function B(r,e){return`color(${r} ${d(e[0],5)} ${d(e[1],5)} ${d(e[2],5)}${e[3]<1?`/${d(e[3],5)}`:""})`}function h(r,e){let n=[...r];for(let t=0;t<e.length;t++){let f=0;for(let o=0;o<e[0].length;o++)f+=r[o]*e[t][o];n[t]=f}return n}function d(r,e=2){let n=10**e;return Math.round(r*n)/n}function L(r){let e=`${Math.round(r[0]*255)}, ${Math.round(r[1]*255)}, ${Math.round(r[2]*255)}`;return r[3]<1?`rgba(${e}, ${d(r[3],5)})`:`rgb(${e})`}var D=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],Y=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]];var Z=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],U=[[1,.3963377774,.2158037573],[1,-.1055613458,-.0638541728],[1,-.0894841775,-1.291485548]],K=[[3.2406,-1.5372,-.4986],[-.9689,1.8758,.0415],[.0557,-.204,1.057]];function S(r){let[e,n,t,f]=r;e=Math.abs(e%360);let o=n*(1-Math.abs(2*t-1)),a=o*(1-Math.abs(e/60%2-1)),i=0,s=0,x=0;0<=e&&e<60?(i=o,s=a):60<=e&&e<120?(i=a,s=o):120<=e&&e<180?(s=o,x=a):180<=e&&e<240?(s=a,x=o):240<=e&&e<300?(i=a,x=o):300<=e&&e<360&&(i=o,x=a);let u=t-o/2;return[i+u,s+u,x+u,f]}function j(r){let[e,n,t,f]=r,o=n===0&&t===0?0:V(Math.atan2(t,n));return[e,Math.sqrt(n**2+t**2),o<0?o+360:o,f]}function J(r){let[e,n,t,f]=r,o=A(t);return[e,n*Math.cos(o),n*Math.sin(o),f]}function Q(r){let e=Math.cbrt(r[0]),n=Math.cbrt(r[1]),t=Math.cbrt(r[2]),f=r[3];return h([e,n,t,f],D)}function W(r){let[e,n,t,f]=h(r,Y);return[Math.max(0,e),Math.max(0,n),Math.max(0,t),Math.max(0,f)]}function p(r){return r.map((e,n)=>n===3?l(e,0,1):e<=.0031308?l(e*12.92,0,1):l(1.055*e**(1/2.4)-.055,0,1))}function C(r){return h(r,Z)}function ee(r){let[e,n,t,f]=r,o=[0,0,0,f],a=n/(13*e),i=t/(13*e);return o[1]=e<=8?e*(3/29)**3:((e+16)/116)**3,o[0]=o[1]*(9/4)*a,o[2]=o[1]*((12-3*a-20*i)/4*i),o}function q(r){return p(te(ee(r)))}function re(r){let e=h(r,U);return[e[0]**3,e[1]**3,e[2]**3,e[3]]}function G(r){return p(W(re(r)))}function _(r){return G(J(r))}function T(r){return r.map((e,n)=>n===3?e:e<=.04045?e/12.92:((e+.055)/1.055)**2.4)}function g(r){return Q(C(T(r)))}function M(r){return j(g(r))}function te(r){return h(r,K)}var ne={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,darkorchard:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:3100495,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,lavendar: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},O=ne;var oe=/[0-9.-]+%?/g,ae=/^#?[0-9a-f]{3,8}$/i;function c(r){let e=fe(r),n={get hex(){let t="#";return t+=b(Math.round(e[0]*255).toString(16),2),t+=b(Math.round(e[1]*255).toString(16),2),t+=b(Math.round(e[2]*255).toString(16),2),e[3]<1&&(t+=b(Math.round(e[3]*255).toString(16),2)),t},get hexVal(){let t=Math.round(e[0]*255),f=Math.round(e[1]*255),o=Math.round(e[2]*255),a=Math.round(e[3]*255);return e[3]<1?t+256**3+f+256**2+o+256+a:t+256**2+f+256+o},get rgb(){return L(e)},rgbVal:e,get rgba(){return L(e)},rgbaVal:e,get linearRGB(){return T(e)},get p3(){return B("display-p3",e)},p3Val:e,get oklab(){return B("oklab",g(e))},get oklabVal(){return g(e)},get oklch(){return B("oklch",M(e))},get oklchVal(){return M(e)}};return n.toString=()=>n.hex,n}function fe(r){function e(t){let f=b(l(t,0,4294967295).toString(16),6);return[parseInt(f.substring(0,2),16)/255,parseInt(f.substring(2,4),16)/255,parseInt(f.substring(4,6),16)/255,parseInt(f.substring(6,8)||"ff",16)/255]}function n(t,f){let o=t.match(oe);if(!o)throw new Error(`Unexpected color format: ${t}`);let a=[0,0,0,1];return o.forEach((i,s)=>{i.includes("%")?a[s]=parseFloat(i)/100:f[s]===1/0?a[s]=parseFloat(i):a[s]=parseFloat(i)/f[s]}),a}if(Array.isArray(r)){if(r.some(t=>typeof t!="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}`);return[l(r[0],0,1),l(r[1],0,1),l(r[2],0,1),typeof r[3]=="number"?l(r[3],0,1):1]}if(typeof r=="number")return e(r);if(typeof r=="string"){let t=r.trim();if(!t)throw new Error("Expected color, received empty string");if(typeof O[t.toLowerCase()]=="number")return e(O[t]);if(ae.test(t)){let a=t.replace("#",""),i=0;if(a.length<6){let s="";for(let x=0;x<a.length;x++){let u=a.substring(x,x+1);s+=u,s+=u}i=parseInt(s,16)}else i=parseInt(a,16);return e(i)}let[f,o]=t.split("(");switch(f==="color"&&(f=o.split(" ")[0]),f){case"rgb":case"rgba":case"srgb":{let[a,i,s,x]=n(o,[255,255,255]);return[l(a,0,1),l(i,0,1),l(s,0,1),l(x,0,1)]}case"srgb-linear":{let[a,i,s,x]=n(o,[255,255,255]);return p([l(a,0,1),l(i,0,1),l(s,0,1),l(x,0,1)])}case"hsl":{let[a,i,s,x]=n(o,[1/0,1,1]);return S([a,l(i,0,1),l(s,0,1),l(x,0,1)])}case"p3":case"display-p3":{let[a,i,s,x]=n(o,[1,1,1]);return[l(a,0,1),l(i,0,1),l(s,0,1),l(x,0,1)]}case"luv":return q(n(o,[1,1,1]));case"oklab":return G(n(o,[1,1,1]));case"oklch":return _(n(o,[1,1,1/0]))}}throw new Error(`Unable to parse color "${r}"`)}function I(r){return d(c(r).oklabVal[0],5)}function m(r,e,n=.5,t="oklab"){let f=l(n,0,1);if(n===0)return c(r);if(n===1)return c(e);let o=1-f,a=f,i={oklch:M,oklab:g,linearRGB:T,sRGB:E=>E},s={oklch:_,oklab:G,linearRGB:p,sRGB:E=>E},x=i[t],u=s[t];if(!x)throw new Error(`Unknown color space "${t}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let k=c(r).rgbVal,y=c(e).rgbVal;t==="oklch"&&(k[0]===k[1]&&k[1]===k[2]||y[0]===y[1]&&y[1]===y[2])&&(x=i.oklab,u=s.oklab);let[F,z,w,N]=x(k),[X,H,R,P]=x(y);return t==="oklch"&&Math.abs(R-w)>180&&(Math.max(w,R)===R?R-=360:w-=360),c(u([F*o+X*a,z*o+H*a,w*o+R*a,N*o+P*a]))}function v(r,e,n="oklab"){let t=l(e,-1,1);return t>=0?m(r,"black",t,n):$(r,-t)}function $(r,e,n="oklab"){let t=l(e,-1,1);return t>=0?m(r,"white",t,n):v(r,-t)}var Me={darken:v,from:c,lighten:$,lightness:I,mix:m};export{l as clamp,B as colorFn,v as darken,Me as default,c as from,b as leftPad,$ as lighten,I as lightness,m as mix,L as rgbFn,d as round};
function m(t,e=2){let o=t;for(;o.length<e;)o=`0${o}`;return o}function I(t){return t*(Math.PI/180)}function V(t){return t*(180/Math.PI)}function s(t,e,o){return Math.min(Math.max(t,e),o)}function B(t,e){return`color(${t} ${f(e[0],5)} ${f(e[1],5)} ${f(e[2],5)}${e[3]<1?`/${f(e[3],5)}`:""})`}function d(t,e){let o=[...t];for(let r=0;r<e.length;r++){let i=0;for(let n=0;n<e[0].length;n++)i+=t[n]*e[r][n];o[r]=i}return o}function f(t,e=2){let o=10**e;return Math.round(t*o)/o}function L(t){let e=`${Math.round(t[0]*255)}, ${Math.round(t[1]*255)}, ${Math.round(t[2]*255)}`;return t[3]!==1?`rgba(${e}, ${f(t[3],5)})`:`rgb(${e})`}var Y=[[.2104542553,.793617785,-.0040720468],[1.9779984951,-2.428592205,.4505937099],[.0259040371,.7827717662,-.808675766]],Z=[[4.0767416621,-3.3077115913,.2309699292],[-1.2684380046,2.6097574011,-.3413193965],[-.0041960863,-.7034186147,1.707614701]];var H=[[.4122214708,.5363325363,.0514459929],[.2119034982,.6806995451,.1073969566],[.0883024619,.2817188376,.6299787005]],U=[[1,.3963377774,.2158037573],[1,-.1055613458,-.0638541728],[1,-.0894841775,-1.291485548]],K=[[3.2406,-1.5372,-.4986],[-.9689,1.8758,.0415],[.0557,-.204,1.057]];function q(t){let[e,o,r,i]=t;e=Math.abs(e%360);let n=o*(1-Math.abs(2*r-1)),a=n*(1-Math.abs(e/60%2-1)),u=0,l=0,c=0;0<=e&&e<60?(u=n,l=a):60<=e&&e<120?(u=a,l=n):120<=e&&e<180?(l=n,c=a):180<=e&&e<240?(l=a,c=n):240<=e&&e<300?(u=a,c=n):300<=e&&e<360&&(u=n,c=a);let p=r-n/2;return[u+p,l+p,c+p,i]}function j(t){let[e,o,r,i]=t,n=o===0&&r===0?0:V(Math.atan2(r,o));return[e,Math.sqrt(o**2+r**2),n<0?n+360:n,i]}function J(t){let[e,o,r,i]=t,n=I(r);return[e,o*Math.cos(n),o*Math.sin(n),i]}function Q(t){let e=Math.cbrt(t[0]),o=Math.cbrt(t[1]),r=Math.cbrt(t[2]),i=t[3];return d([e,o,r,i],Y)}function W(t){let[e,o,r,i]=d(t,Z);return[Math.max(0,e),Math.max(0,o),Math.max(0,r),Math.max(0,i)]}function b(t){return t.map((e,o)=>o===3?s(e,0,1):e<=.0031308?s(e*12.92,0,1):s(1.055*e**(1/2.4)-.055,0,1))}function C(t){return d(t,H)}function e0(t){let[e,o,r,i]=t,n=[0,0,0,i],a=o/(13*e),u=r/(13*e);return n[1]=e<=8?e*(3/29)**3:((e+16)/116)**3,n[0]=n[1]*(9/4)*a,n[2]=n[1]*((12-3*a-20*u)/4*u),n}function F(t){return b(r0(e0(t)))}function t0(t){let e=d(t,U);return[e[0]**3,e[1]**3,e[2]**3,e[3]]}function G(t){return b(W(t0(t)))}function _(t){return G(J(t))}function T(t){return t.map((e,o)=>o===3?e:e<=.04045?e/12.92:((e+.055)/1.055)**2.4)}function k(t){return Q(C(T(t)))}function M(t){return j(k(t))}function r0(t){return d(t,K)}var n0={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]},O=n0;var o0=/-?[0-9.]+%?/g,a0=/^#?[0-9a-f]{3,8}$/i,l0=256**2,s0=256,i0=0;function h(t){let e=u0(t),o={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),i=Math.round(e[1]*255),n=Math.round(e[2]*255),a=Math.round(e[3]*255);return e[3]<1?r+256**3+i+256**2+n+256+a:r+256**2+i+256+n},get rgb(){return L(e)},rgbVal:e,get rgba(){return L(e)},rgbaVal:e,get linearRGB(){return T(e)},get p3(){return B("display-p3",e)},p3Val:e,get oklab(){return B("oklab",k(e))},get oklabVal(){return k(e)},get oklch(){return B("oklch",M(e))},get oklchVal(){return M(e)}};return o.toString=()=>o.hex,o}function u0(t){function e(r){let i=Math.max(r-l0,0)/256,n=Math.max(r-s0,0)/256,a=Math.max(r-i0,0)/256;return[i,n,a,1]}function o(r,i){let n=r.match(o0);if(!n)throw new Error(`Unexpected color format: ${r}`);let a=[0,0,0,1];return n.forEach((u,l)=>{u.includes("%")?a[l]=parseFloat(u)/100:i[l]===1/0?a[l]=parseFloat(u):a[l]=parseFloat(u)/(i[l]||1)}),a}if(Array.isArray(t)){if(t.some(r=>typeof r!="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 e(t);if(typeof t=="string"){let r=t.trim();if(!r)throw new Error("Expected color, received empty string");if(O[r.toLowerCase()])return O[r.toLowerCase()];if(a0.test(r)){let a=r.replace("#",""),u=[0,0,0,1];if(a.length>=6)for(let l=0;l<a.length/2;l++){let c=l*2,p=c+2,g=a.substring(c,p);u[l]=parseInt(g,16)/255}else for(let l=0;l<a.length;l++){let c=a.charAt(l);u[l]=parseInt(`${c}${c}`,16)/255}return u}let[i,n]=r.split("(");if(i==="color"){let a=n.indexOf(" ");i=n.substring(0,a),n=n.substring(a)}switch(i){case"rgb":case"rgba":case"srgb":{let[a,u,l,c]=o(n,[255,255,255,1]);return[s(a,0,1),s(u,0,1),s(l,0,1),s(c,0,1)]}case"srgb-linear":{let[a,u,l,c]=o(n,[255,255,255,1]);return b([s(a,0,1),s(u,0,1),s(l,0,1),s(c,0,1)])}case"hsl":{let[a,u,l,c]=o(n,[1/0,1,1,1]);return q([a,s(u,0,1),s(l,0,1),s(c,0,1)])}case"p3":case"display-p3":{let[a,u,l,c]=o(n,[1,1,1,1]);return[s(a,0,1),s(u,0,1),s(l,0,1),s(c,0,1)]}case"luv":return F(o(n,[1,1,1,1]));case"oklab":return G(o(n,[1,1,1,1]));case"oklch":return _(o(n,[1,1,1/0,1]))}}throw new Error(`Unable to parse color "${t}"`)}function A(t){return f(h(t).oklabVal[0],5)}function x(t,e,o=.5,r="oklab"){let i=s(o,0,1);if(o===0)return h(t);if(o===1)return h(e);let n=1-i,a=i,u={oklch:M,oklab:k,linearRGB:T,sRGB:E=>E},l={oklch:_,oklab:G,linearRGB:b,sRGB:E=>E},c=u[r],p=l[r];if(!c)throw new Error(`Unknown color space "${r}", try "oklab", "oklch", "linearRGB", or "sRGB"`);let g=h(t).rgbVal,R=h(e).rgbVal;r==="oklch"&&(g[0]===g[1]&&g[1]===g[2]||R[0]===R[1]&&R[1]===R[2])&&(c=u.oklab,p=l.oklab);let[S,N,w,z]=c(g),[X,P,y,D]=c(R);return r==="oklch"&&Math.abs(y-w)>180&&(Math.max(w,y)===y?y-=360:w-=360),h(p([S*n+X*a,N*n+P*a,w*n+y*a,z*n+D*a]))}function v(t,e,o="oklab"){let r=s(e,-1,1);return r>=0?x(t,"black",r,o):$(t,-r)}function $(t,e,o="oklab"){let r=s(e,-1,1);return r>=0?x(t,"white",r,o):v(t,-r)}var _0={darken:v,from:h,lighten:$,lightness:A,mix:x};export{s as clamp,B as colorFn,v as darken,_0 as default,h as from,m as leftPad,$ as lighten,A as lightness,x as mix,L as rgbFn,f as round};

@@ -5,4 +5,7 @@ import { hslTosRGB, linearRGBTosRGB, luvTosRGB, oklabTosRGB, oklchTosRGB, sRGBToLinearRGB, sRGBToOklab, sRGBToOklch } from './colorspace.js';

// constants
const FLOAT_RE = /[0-9.-]+%?/g;
const FLOAT_RE = /-?[0-9.]+%?/g;
const HEX_RE = /^#?[0-9a-f]{3,8}$/i;
const R_RANGE = 256 ** 2;
const G_RANGE = 256;
const B_RANGE = 0;
/**

@@ -82,11 +85,8 @@ * Parse any valid CSS color color string and convert to:

function parse(rawColor) {
/** Convert 0xff0000 to RGBA array */
function parseHexVal(hexVal) {
const hexStr = leftPad(clamp(hexVal, 0, 0xffffffff).toString(16), 6); // note: 0x000001 will convert to '1'
return [
parseInt(hexStr.substring(0, 2), 16) / 255,
parseInt(hexStr.substring(2, 4), 16) / 255,
parseInt(hexStr.substring(4, 6), 16) / 255,
parseInt(hexStr.substring(6, 8) || 'ff', 16) / 255, // a
];
/** hex num to sRGB (note: doesn’t support alpha!) */
function hexNumTosRGB(hex) {
const r = Math.max(hex - R_RANGE, 0) / 256;
const g = Math.max(hex - G_RANGE, 0) / 256;
const b = Math.max(hex - B_RANGE, 0) / 256;
return [r, g, b, 1];
}

@@ -108,3 +108,3 @@ /** only grabs numbers from a color string (ignores spaces, commas, slashes, etc.) */

else
values[n] = parseFloat(value) / normalize[n];
values[n] = parseFloat(value) / (normalize[n] || 1);
});

@@ -127,4 +127,5 @@ return values;

// 0xff0000 (number)
// !note: doesn’t support alpha
if (typeof rawColor == 'number') {
return parseHexVal(rawColor);
return hexNumTosRGB(rawColor);
}

@@ -138,5 +139,4 @@ // '#ff0000' / 'red' / 'rgb(255, 0, 0)' / 'hsl(0, 1, 1)'

// console.log({ val: strVal, name: (cssNames as any)[strVal] });
// note: 0 (black) is a valid color! so don’t check for “truthy” here
if (typeof cssNames[strVal.toLowerCase()] === 'number') {
return parseHexVal(cssNames[strVal]);
if (cssNames[strVal.toLowerCase()]) {
return cssNames[strVal.toLowerCase()];
}

@@ -146,22 +146,28 @@ // hex

const hex = strVal.replace('#', '');
let hexNum = 0;
const rgb = [0, 0, 0, 1];
if (hex.length >= 6) {
for (let n = 0; n < hex.length / 2; n++) {
const start = n * 2;
const end = start + 2;
const value = hex.substring(start, end);
rgb[n] = parseInt(value, 16) / 255;
}
}
// according to spec, any shortened hex should have characters doubled
if (hex.length < 6) {
let expandedHex = '';
else {
for (let n = 0; n < hex.length; n++) {
let c = hex.substring(n, n + 1);
expandedHex += c;
expandedHex += c;
const value = hex.charAt(n);
rgb[n] = parseInt(`${value}${value}`, 16) / 255;
}
hexNum = parseInt(expandedHex, 16);
}
else {
hexNum = parseInt(hex, 16);
}
return parseHexVal(hexNum);
return rgb;
}
// color functions
let [colorspace, rest] = strVal.split('(');
if (colorspace === 'color')
colorspace = rest.split(' ')[0];
let [colorspace, valueStr] = strVal.split('(');
if (colorspace === 'color') {
// if color() function, then split string by first occurrence of space
const spaceI = valueStr.indexOf(' ');
colorspace = valueStr.substring(0, spaceI);
valueStr = valueStr.substring(spaceI);
}
switch (colorspace) {

@@ -171,11 +177,11 @@ case 'rgb':

case 'srgb': {
const [r, g, b, a] = parseValueStr(rest, [255, 255, 255]);
const [r, g, b, a] = parseValueStr(valueStr, [255, 255, 255, 1]);
return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];
}
case 'srgb-linear': {
const [r, g, b, a] = parseValueStr(rest, [255, 255, 255]);
const [r, g, b, a] = parseValueStr(valueStr, [255, 255, 255, 1]);
return linearRGBTosRGB([clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)]);
}
case 'hsl': {
const [h, s, l, a] = parseValueStr(rest, [Infinity, 1, 1]);
const [h, s, l, a] = parseValueStr(valueStr, [Infinity, 1, 1, 1]);
return hslTosRGB([h, clamp(s, 0, 1), clamp(l, 0, 1), clamp(a, 0, 1)]);

@@ -185,13 +191,13 @@ }

case 'display-p3': {
const [r, g, b, a] = parseValueStr(rest, [1, 1, 1]);
const [r, g, b, a] = parseValueStr(valueStr, [1, 1, 1, 1]);
return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];
}
case 'luv': {
return luvTosRGB(parseValueStr(rest, [1, 1, 1]));
return luvTosRGB(parseValueStr(valueStr, [1, 1, 1, 1]));
}
case 'oklab': {
return oklabTosRGB(parseValueStr(rest, [1, 1, 1]));
return oklabTosRGB(parseValueStr(valueStr, [1, 1, 1, 1]));
}
case 'oklch': {
return oklchTosRGB(parseValueStr(rest, [1, 1, Infinity]));
return oklchTosRGB(parseValueStr(valueStr, [1, 1, Infinity, 1]));
}

@@ -198,0 +204,0 @@ }

@@ -40,3 +40,3 @@ /** you know it, you love it */

const channels = `${Math.round(rgb[0] * 255)}, ${Math.round(rgb[1] * 255)}, ${Math.round(rgb[2] * 255)}`;
if (rgb[3] < 1) {
if (rgb[3] !== 1) {
return `rgba(${channels}, ${round(rgb[3], 5)})`;

@@ -43,0 +43,0 @@ }

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

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

@@ -1,159 +0,161 @@

const names = {
import type { sRGB } from './colorspace';
const names: Record<string, sRGB> = {
// CSS Level 1
black: 0x000000,
silver: 0xc0c0c0,
gray: 0x808080,
white: 0xffffff,
maroon: 0x800000,
red: 0xff0000,
purple: 0x800080,
fuchsia: 0xff00ff,
green: 0x008000,
lime: 0x00ff00,
olive: 0x808000,
yellow: 0xffff00,
navy: 0x000080,
blue: 0x0000ff,
teal: 0x008080,
aqua: 0x00ffff,
black: [0, 0, 0, 1],
silver: [0.75, 0.75, 0.75, 1],
gray: [0.5, 0.5, 0.5, 1],
white: [1, 1, 1, 1],
maroon: [0.5, 0, 0, 1],
red: [1, 0, 0, 1],
purple: [0.5, 0, 0.5, 1],
fuchsia: [1, 0, 1, 1],
green: [0, 0.5, 0, 1],
lime: [0, 1, 0, 1],
olive: [0.5, 0.5, 0, 1],
yellow: [1, 1, 0, 1],
navy: [0, 0, 0.5, 1],
blue: [0, 0, 1, 1],
teal: [0, 0.5, 0.5, 1],
aqua: [0, 1, 1, 1],
// CSS Level 2 (Revision 1)
orange: 0xffa500,
orange: [1, 0.6470588235294118, 0, 1],
// CSS Color Module Level 3
aliceblue: 0xf0f8ff,
antiquewhite: 0xfaebd7,
aquamarine: 0x7fffd4,
azure: 0xf0ffff,
beige: 0xf5f5dc,
bisque: 0xffe4c4,
blanchedalmond: 0xffebcd,
blueviolet: 0x8a2be2,
brown: 0xa52a2a,
burlywood: 0xdeb887,
cadetblue: 0x5f9ea0,
chartreuse: 0x7fff00,
chocolate: 0xd2691e,
coral: 0xff7f50,
cornflowerblue: 0x6495ed,
cornsilk: 0xfff8dc,
crimson: 0xdc143c,
cyan: 0x00ffff, // alias of "aqua"
darkblue: 0x00008b,
darkcyan: 0x008b8b,
darkgoldenrod: 0xb8860b,
darkgray: 0xa9a9a9,
darkgreen: 0x006400,
darkgrey: 0xa9a9a9,
darkkhaki: 0xbdb76b,
darkmagenta: 0x8b008b,
darkolivegreen: 0x556b2f,
darkorange: 0xff8c00,
darkorchard: 0x9932cc,
darkred: 0x8b0000,
darksalmon: 0xe9967a,
darkseagreen: 0x8fbc8f,
darkslateblue: 0x483d8b,
darkslategray: 0x2f4f4f,
darkslategrey: 0x2f4f4f,
darkturquoise: 0x2f4f4f,
darkviolet: 0x9400d3,
deeppink: 0xff1493,
deepskyblue: 0x00bfff,
dimgray: 0x696969,
dimgrey: 0x696969,
dodgerblue: 0x1e90ff,
firebrick: 0xb22222,
floralwhite: 0xfffaf0,
forestgreen: 0x228b22,
gainsboro: 0xdcdcdc,
ghostwhite: 0xf8f8ff,
gold: 0xffd700,
goldenrod: 0xdaa520,
greenyellow: 0xadff2f,
grey: 0x808080,
honeydew: 0xf0fff0,
hotpink: 0xff69b4,
indianred: 0xcd5c5c,
indigo: 0x4b0082,
ivory: 0xfffff0,
khaki: 0xf0e68c,
lavendar: 0xe6e6fa,
lavenderblush: 0xfff0f5,
lawngreen: 0x7cfc00,
lemonchiffon: 0xfffacd,
lightblue: 0xadd8e6,
lightcoral: 0xf08080,
lightcyan: 0xe0ffff,
lightgoldenrodyellow: 0xfafad2,
lightgray: 0xd3d3d3,
lightgreen: 0x90ee90,
lightgrey: 0xd3d3d3,
lightpink: 0xffb6c1,
lightsalmon: 0xffa07a,
lightseagreen: 0x20b2aa,
lightskyblue: 0x87cefa,
lightslategray: 0x778899,
lightslategrey: 0x778899,
lightsteelblue: 0xb0c4de,
lightyellow: 0xffffe0,
limegreen: 0x32cd32,
linen: 0xfaf0e6,
magenta: 0xff00ff, // alias of "fuchsia"
mediumaquamarine: 0x66cdaa,
mediumblue: 0x0000cd,
mediumorchid: 0xba55d3,
mediumpurple: 0x9370db,
mediumseagreen: 0x3cb371,
mediumslateblue: 0x7b68ee,
mediumspringgreen: 0x00fa9a,
mediumturquoise: 0x48d1cc,
mediumvioletred: 0xc71585,
midnightblue: 0x191970,
mintcream: 0xf5fffa,
mistyrose: 0xffe4e1,
moccasin: 0xffe4b5,
navajowhite: 0xffdead,
oldlace: 0xfdf5e6,
olivedrab: 0x6b8e23,
orangered: 0xff4500,
orchid: 0xda70d6,
palegoldenrod: 0xeee8aa,
palegreen: 0x98fb98,
paleturquoise: 0xafeeee,
palevioletred: 0xdb7093,
papayawhip: 0xffefd5,
peachpuff: 0xffdab9,
peru: 0xcd853f,
pink: 0xffc0cb,
plum: 0xdda0dd,
powderblue: 0xb0e0e6,
rosybrown: 0xbc8f8f,
royalblue: 0x4169e1,
saddlebrown: 0x8b4513,
salmon: 0xfa8072,
sandybrown: 0xf4a460,
seagreen: 0x2e8b57,
seashell: 0xfff5ee,
sienna: 0xa0522d,
skyblue: 0x87ceeb,
slateblue: 0x6a5acd,
slategray: 0x708090,
slategrey: 0x708090,
snow: 0xfffafa,
springgreen: 0x00ff7f,
steelblue: 0x4682b4,
tan: 0xd2b48c,
thistle: 0xd8bfd8,
tomato: 0xff6347,
turquoise: 0x40e0d0,
violet: 0xee82ee,
wheat: 0xf5deb3,
whitesmoke: 0xf5f5f5,
yellowgreen: 0x9acd32,
aliceblue: [0.9411764705882353, 0.9725490196078431, 1, 1],
antiquewhite: [0.9803921568627451, 0.9215686274509803, 0.8431372549019608, 1],
aquamarine: [0.4980392156862745, 1, 0.8313725490196079, 1],
azure: [0.9411764705882353, 1, 1, 1],
beige: [0.9607843137254902, 0.9607843137254902, 0.8627450980392157, 1],
bisque: [1, 0.8941176470588236, 0.7686274509803922, 1],
blanchedalmond: [1, 0.9215686274509803, 0.803921568627451, 1],
blueviolet: [0.5411764705882353, 0.16862745098039217, 0.8862745098039215, 1],
brown: [0.6470588235294118, 0.16470588235294117, 0.16470588235294117, 1],
burlywood: [0.8705882352941177, 0.7215686274509804, 0.5294117647058824, 1],
cadetblue: [0.37254901960784315, 0.6196078431372549, 0.6274509803921569, 1],
chartreuse: [0.4980392156862745, 1, 0, 1],
chocolate: [0.8235294117647058, 0.4117647058823529, 0.11764705882352941, 1],
coral: [1, 0.4980392156862745, 0.3137254901960784, 1],
cornflowerblue: [0.39215686274509803, 0.5843137254901961, 0.9294117647058824, 1],
cornsilk: [1, 0.9725490196078431, 0.8627450980392157, 1],
crimson: [0.8627450980392157, 0.0784313725490196, 0.23529411764705882, 1],
cyan: [0, 1, 1, 1],
darkblue: [0, 0, 0.5450980392156862, 1],
darkcyan: [0, 0.5450980392156862, 0.5450980392156862, 1],
darkgoldenrod: [0.7215686274509804, 0.5254901960784314, 0.043137254901960784, 1],
darkgray: [0.6627450980392157, 0.6627450980392157, 0.6627450980392157, 1],
darkgreen: [0, 0.39215686274509803, 0, 1],
darkgrey: [0.6627450980392157, 0.6627450980392157, 0.6627450980392157, 1],
darkkhaki: [0.7411764705882353, 0.7176470588235294, 0.4196078431372549, 1],
darkmagenta: [0.5450980392156862, 0, 0.5450980392156862, 1],
darkolivegreen: [0.3333333333333333, 0.4196078431372549, 0.1843137254901961, 1],
darkorange: [1, 0.5490196078431373, 0, 1],
darkorchard: [0.6, 0.19607843137254902, 0.8, 1],
darkred: [0.5450980392156862, 0, 0, 1],
darksalmon: [0.9137254901960784, 0.5882352941176471, 0.47843137254901963, 1],
darkseagreen: [0.5607843137254902, 0.7372549019607844, 0.5607843137254902, 1],
darkslateblue: [0.2823529411764706, 0.23921568627450981, 0.5450980392156862, 1],
darkslategray: [0.1843137254901961, 0.30980392156862746, 0.30980392156862746, 1],
darkslategrey: [0.1843137254901961, 0.30980392156862746, 0.30980392156862746, 1],
darkturquoise: [0.1843137254901961, 0.30980392156862746, 0.30980392156862746, 1],
darkviolet: [0.5803921568627451, 0, 0.8274509803921568, 1],
deeppink: [1, 0.0784313725490196, 0.5764705882352941, 1],
deepskyblue: [0, 0.7490196078431373, 1, 1],
dimgray: [0.4117647058823529, 0.4117647058823529, 0.4117647058823529, 1],
dimgrey: [0.4117647058823529, 0.4117647058823529, 0.4117647058823529, 1],
dodgerblue: [0.11764705882352941, 0.5647058823529412, 1, 1],
firebrick: [0.6980392156862745, 0.13333333333333333, 0.13333333333333333, 1],
floralwhite: [1, 0.9803921568627451, 0.9411764705882353, 1],
forestgreen: [0.13333333333333333, 0.5450980392156862, 0.13333333333333333, 1],
gainsboro: [0.8627450980392157, 0.8627450980392157, 0.8627450980392157, 1],
ghostwhite: [0.9725490196078431, 0.9725490196078431, 1, 1],
gold: [1, 0.8431372549019608, 0, 1],
goldenrod: [0.8549019607843137, 0.6470588235294118, 0.12549019607843137, 1],
greenyellow: [0.6784313725490196, 1, 0.1843137254901961, 1],
grey: [0.5019607843137255, 0.5019607843137255, 0.5019607843137255, 1],
honeydew: [0.9411764705882353, 1, 0.9411764705882353, 1],
hotpink: [1, 0.4117647058823529, 0.7058823529411765, 1],
indianred: [0.803921568627451, 0.3607843137254902, 0.3607843137254902, 1],
indigo: [0.29411764705882354, 0, 0.5098039215686274, 1],
ivory: [1, 1, 0.9411764705882353, 1],
khaki: [0.9411764705882353, 0.9019607843137255, 0.5490196078431373, 1],
lavendar: [0.9019607843137255, 0.9019607843137255, 0.9803921568627451, 1],
lavenderblush: [1, 0.9411764705882353, 0.9607843137254902, 1],
lawngreen: [0.48627450980392156, 0.9882352941176471, 0, 1],
lemonchiffon: [1, 0.9803921568627451, 0.803921568627451, 1],
lightblue: [0.6784313725490196, 0.8470588235294118, 0.9019607843137255, 1],
lightcoral: [0.9411764705882353, 0.5019607843137255, 0.5019607843137255, 1],
lightcyan: [0.8784313725490196, 1, 1, 1],
lightgoldenrodyellow: [0.9803921568627451, 0.9803921568627451, 0.8235294117647058, 1],
lightgray: [0.8274509803921568, 0.8274509803921568, 0.8274509803921568, 1],
lightgreen: [0.5647058823529412, 0.9333333333333333, 0.5647058823529412, 1],
lightgrey: [0.8274509803921568, 0.8274509803921568, 0.8274509803921568, 1],
lightpink: [1, 0.7137254901960784, 0.7568627450980392, 1],
lightsalmon: [1, 0.6274509803921569, 0.47843137254901963, 1],
lightseagreen: [0.12549019607843137, 0.6980392156862745, 0.6666666666666666, 1],
lightskyblue: [0.5294117647058824, 0.807843137254902, 0.9803921568627451, 1],
lightslategray: [0.4666666666666667, 0.5333333333333333, 0.6, 1],
lightslategrey: [0.4666666666666667, 0.5333333333333333, 0.6, 1],
lightsteelblue: [0.6901960784313725, 0.7686274509803922, 0.8705882352941177, 1],
lightyellow: [1, 1, 0.8784313725490196, 1],
limegreen: [0.19607843137254902, 0.803921568627451, 0.19607843137254902, 1],
linen: [0.9803921568627451, 0.9411764705882353, 0.9019607843137255, 1],
magenta: [1, 0, 1, 1],
mediumaquamarine: [0.4, 0.803921568627451, 0.6666666666666666, 1],
mediumblue: [0, 0, 0.803921568627451, 1],
mediumorchid: [0.7294117647058823, 0.3333333333333333, 0.8274509803921568, 1],
mediumpurple: [0.5764705882352941, 0.4392156862745098, 0.8588235294117647, 1],
mediumseagreen: [0.23529411764705882, 0.7019607843137254, 0.44313725490196076, 1],
mediumslateblue: [0.4823529411764706, 0.40784313725490196, 0.9333333333333333, 1],
mediumspringgreen: [0, 0.9803921568627451, 0.6039215686274509, 1],
mediumturquoise: [0.2823529411764706, 0.8196078431372549, 0.8, 1],
mediumvioletred: [0.7803921568627451, 0.08235294117647059, 0.5215686274509804, 1],
midnightblue: [0.09803921568627451, 0.09803921568627451, 0.4392156862745098, 1],
mintcream: [0.9607843137254902, 1, 0.9803921568627451, 1],
mistyrose: [1, 0.8941176470588236, 0.8823529411764706, 1],
moccasin: [1, 0.8941176470588236, 0.7098039215686275, 1],
navajowhite: [1, 0.8705882352941177, 0.6784313725490196, 1],
oldlace: [0.9921568627450981, 0.9607843137254902, 0.9019607843137255, 1],
olivedrab: [0.4196078431372549, 0.5568627450980392, 0.13725490196078433, 1],
orangered: [1, 0.27058823529411763, 0, 1],
orchid: [0.8549019607843137, 0.4392156862745098, 0.8392156862745098, 1],
palegoldenrod: [0.9333333333333333, 0.9098039215686274, 0.6666666666666666, 1],
palegreen: [0.596078431372549, 0.984313725490196, 0.596078431372549, 1],
paleturquoise: [0.6862745098039216, 0.9333333333333333, 0.9333333333333333, 1],
palevioletred: [0.8588235294117647, 0.4392156862745098, 0.5764705882352941, 1],
papayawhip: [1, 0.9372549019607843, 0.8352941176470589, 1],
peachpuff: [1, 0.8549019607843137, 0.7254901960784313, 1],
peru: [0.803921568627451, 0.5215686274509804, 0.24705882352941178, 1],
pink: [1, 0.7529411764705882, 0.796078431372549, 1],
plum: [0.8666666666666667, 0.6274509803921569, 0.8666666666666667, 1],
powderblue: [0.6901960784313725, 0.8784313725490196, 0.9019607843137255, 1],
rosybrown: [0.7372549019607844, 0.5607843137254902, 0.5607843137254902, 1],
royalblue: [0.2549019607843137, 0.4117647058823529, 0.8823529411764706, 1],
saddlebrown: [0.5450980392156862, 0.27058823529411763, 0.07450980392156863, 1],
salmon: [0.9803921568627451, 0.5019607843137255, 0.4470588235294118, 1],
sandybrown: [0.9568627450980393, 0.6431372549019608, 0.3764705882352941, 1],
seagreen: [0.1803921568627451, 0.5450980392156862, 0.3411764705882353, 1],
seashell: [1, 0.9607843137254902, 0.9333333333333333, 1],
sienna: [0.6274509803921569, 0.3215686274509804, 0.17647058823529413, 1],
skyblue: [0.5294117647058824, 0.807843137254902, 0.9215686274509803, 1],
slateblue: [0.41568627450980394, 0.35294117647058826, 0.803921568627451, 1],
slategray: [0.4392156862745098, 0.5019607843137255, 0.5647058823529412, 1],
slategrey: [0.4392156862745098, 0.5019607843137255, 0.5647058823529412, 1],
snow: [1, 0.9803921568627451, 0.9803921568627451, 1],
springgreen: [0, 1, 0.4980392156862745, 1],
steelblue: [0.27450980392156865, 0.5098039215686274, 0.7058823529411765, 1],
tan: [0.8235294117647058, 0.7058823529411765, 0.5490196078431373, 1],
thistle: [0.8470588235294118, 0.7490196078431373, 0.8470588235294118, 1],
tomato: [1, 0.38823529411764707, 0.2784313725490196, 1],
turquoise: [0.25098039215686274, 0.8784313725490196, 0.8156862745098039, 1],
violet: [0.9333333333333333, 0.5098039215686274, 0.9333333333333333, 1],
wheat: [0.9607843137254902, 0.8705882352941177, 0.7019607843137254, 1],
whitesmoke: [0.9607843137254902, 0.9607843137254902, 0.9607843137254902, 1],
yellowgreen: [0.6039215686274509, 0.803921568627451, 0.19607843137254902, 1],
// CSS Color Module Level 4
rebeccapurple: 0x663399,
rebeccapurple: [0.4, 0.2, 0.6, 1],
};
export default names;

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

// constants
const FLOAT_RE = /[0-9.-]+%?/g;
const FLOAT_RE = /-?[0-9.]+%?/g;
const HEX_RE = /^#?[0-9a-f]{3,8}$/i;
const R_RANGE = 256 ** 2;
const G_RANGE = 256;
const B_RANGE = 0;

@@ -122,11 +125,8 @@ /**

function parse(rawColor: Color): sRGB {
/** Convert 0xff0000 to RGBA array */
function parseHexVal(hexVal: number): sRGB {
const hexStr = leftPad(clamp(hexVal, 0, 0xffffffff).toString(16), 6); // note: 0x000001 will convert to '1'
return [
parseInt(hexStr.substring(0, 2), 16) / 255, // r
parseInt(hexStr.substring(2, 4), 16) / 255, // g
parseInt(hexStr.substring(4, 6), 16) / 255, // b
parseInt(hexStr.substring(6, 8) || 'ff', 16) / 255, // a
];
/** hex num to sRGB (note: doesn’t support alpha!) */
function hexNumTosRGB(hex: number): sRGB {
const r = Math.max(hex - R_RANGE, 0) / 256;
const g = Math.max(hex - G_RANGE, 0) / 256;
const b = Math.max(hex - B_RANGE, 0) / 256;
return [r, g, b, 1];
}

@@ -145,3 +145,3 @@

// bounded
else values[n] = parseFloat(value) / normalize[n];
else values[n] = parseFloat(value) / (normalize[n] || 1);
});

@@ -164,4 +164,5 @@ return values;

// 0xff0000 (number)
// !note: doesn’t support alpha
if (typeof rawColor == 'number') {
return parseHexVal(rawColor);
return hexNumTosRGB(rawColor);
}

@@ -176,28 +177,36 @@

// console.log({ val: strVal, name: (cssNames as any)[strVal] });
// note: 0 (black) is a valid color! so don’t check for “truthy” here
if (typeof cssNames[strVal.toLowerCase() as keyof typeof cssNames] === 'number') {
return parseHexVal(cssNames[strVal as keyof typeof cssNames] as number);
if (cssNames[strVal.toLowerCase()]) {
return cssNames[strVal.toLowerCase()];
}
// hex
if (HEX_RE.test(strVal)) {
const hex = strVal.replace('#', '');
let hexNum = 0;
const rgb: sRGB = [0, 0, 0, 1];
if (hex.length >= 6) {
for (let n = 0; n < hex.length / 2; n++) {
const start = n * 2;
const end = start + 2;
const value = hex.substring(start, end);
rgb[n] = parseInt(value, 16) / 255;
}
}
// according to spec, any shortened hex should have characters doubled
if (hex.length < 6) {
let expandedHex = '';
else {
for (let n = 0; n < hex.length; n++) {
let c = hex.substring(n, n + 1);
expandedHex += c;
expandedHex += c;
const value = hex.charAt(n);
rgb[n] = parseInt(`${value}${value}`, 16) / 255;
}
hexNum = parseInt(expandedHex, 16);
} else {
hexNum = parseInt(hex, 16);
}
return parseHexVal(hexNum);
return rgb;
}
// color functions
let [colorspace, rest] = strVal.split('(');
if (colorspace === 'color') colorspace = rest.split(' ')[0];
let [colorspace, valueStr] = strVal.split('(');
if (colorspace === 'color') {
// if color() function, then split string by first occurrence of space
const spaceI = valueStr.indexOf(' ');
colorspace = valueStr.substring(0, spaceI);
valueStr = valueStr.substring(spaceI);
}
switch (colorspace) {

@@ -207,11 +216,11 @@ case 'rgb':

case 'srgb': {
const [r, g, b, a] = parseValueStr(rest, [255, 255, 255]);
const [r, g, b, a] = parseValueStr(valueStr, [255, 255, 255, 1]);
return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];
}
case 'srgb-linear': {
const [r, g, b, a] = parseValueStr(rest, [255, 255, 255]);
const [r, g, b, a] = parseValueStr(valueStr, [255, 255, 255, 1]);
return linearRGBTosRGB([clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)]);
}
case 'hsl': {
const [h, s, l, a] = parseValueStr(rest, [Infinity, 1, 1]);
const [h, s, l, a] = parseValueStr(valueStr, [Infinity, 1, 1, 1]);
return hslTosRGB([h, clamp(s, 0, 1), clamp(l, 0, 1), clamp(a, 0, 1)]);

@@ -221,13 +230,13 @@ }

case 'display-p3': {
const [r, g, b, a] = parseValueStr(rest, [1, 1, 1]);
const [r, g, b, a] = parseValueStr(valueStr, [1, 1, 1, 1]);
return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];
}
case 'luv': {
return luvTosRGB(parseValueStr(rest, [1, 1, 1]));
return luvTosRGB(parseValueStr(valueStr, [1, 1, 1, 1]));
}
case 'oklab': {
return oklabTosRGB(parseValueStr(rest, [1, 1, 1]));
return oklabTosRGB(parseValueStr(valueStr, [1, 1, 1, 1]));
}
case 'oklch': {
return oklchTosRGB(parseValueStr(rest, [1, 1, Infinity]));
return oklchTosRGB(parseValueStr(valueStr, [1, 1, Infinity, 1]));
}

@@ -234,0 +243,0 @@ }

@@ -49,3 +49,3 @@ import type { sRGB } from './index';

const channels = `${Math.round(rgb[0] * 255)}, ${Math.round(rgb[1] * 255)}, ${Math.round(rgb[2] * 255)}`;
if (rgb[3] < 1) {
if (rgb[3] !== 1) {
return `rgba(${channels}, ${round(rgb[3], 5)})`;

@@ -52,0 +52,0 @@ }

Sorry, the diff of this file is not supported yet

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