@tempots/std 0.26.1 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/color-D7FAmkht.cjs +1 -0
- package/color-SZxckS9U.js +522 -0
- package/color-adjust.cjs +1 -0
- package/color-adjust.d.ts +148 -0
- package/color-adjust.js +47 -0
- package/color-contrast.cjs +1 -0
- package/color-contrast.d.ts +96 -0
- package/color-contrast.js +22 -0
- package/color-distance.cjs +1 -0
- package/color-distance.d.ts +41 -0
- package/color-distance.js +25 -0
- package/color-harmony.cjs +1 -0
- package/color-harmony.d.ts +81 -0
- package/color-harmony.js +35 -0
- package/color-hsl.cjs +1 -0
- package/color-hsl.d.ts +81 -0
- package/color-hsl.js +10 -0
- package/color-hsv.cjs +1 -0
- package/color-hsv.d.ts +116 -0
- package/color-hsv.js +12 -0
- package/color-hwb.cjs +1 -0
- package/color-hwb.d.ts +88 -0
- package/color-hwb.js +10 -0
- package/color-lab.cjs +1 -0
- package/color-lab.d.ts +161 -0
- package/color-lab.js +15 -0
- package/color-mix.cjs +1 -0
- package/color-mix.d.ts +50 -0
- package/color-mix.js +101 -0
- package/color-named.cjs +1 -0
- package/color-named.d.ts +8 -0
- package/color-named.js +153 -0
- package/color-oklab.cjs +1 -0
- package/color-oklab.d.ts +141 -0
- package/color-oklab.js +15 -0
- package/color-rgb.cjs +1 -0
- package/color-rgb.d.ts +119 -0
- package/color-rgb.js +14 -0
- package/color-utils.cjs +1 -0
- package/color-utils.d.ts +57 -0
- package/color-utils.js +54 -0
- package/color.cjs +1 -0
- package/color.d.ts +466 -0
- package/color.js +33 -0
- package/index.cjs +1 -1
- package/index.d.ts +14 -0
- package/index.js +370 -265
- package/number.cjs +1 -1
- package/number.d.ts +15 -0
- package/number.js +32 -31
- package/package.json +99 -1
package/color-named.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
aliceblue: [240, 248, 255],
|
|
3
|
+
antiquewhite: [250, 235, 215],
|
|
4
|
+
aqua: [0, 255, 255],
|
|
5
|
+
aquamarine: [127, 255, 212],
|
|
6
|
+
azure: [240, 255, 255],
|
|
7
|
+
beige: [245, 245, 220],
|
|
8
|
+
bisque: [255, 228, 196],
|
|
9
|
+
black: [0, 0, 0],
|
|
10
|
+
blanchedalmond: [255, 235, 205],
|
|
11
|
+
blue: [0, 0, 255],
|
|
12
|
+
blueviolet: [138, 43, 226],
|
|
13
|
+
brown: [165, 42, 42],
|
|
14
|
+
burlywood: [222, 184, 135],
|
|
15
|
+
cadetblue: [95, 158, 160],
|
|
16
|
+
chartreuse: [127, 255, 0],
|
|
17
|
+
chocolate: [210, 105, 30],
|
|
18
|
+
coral: [255, 127, 80],
|
|
19
|
+
cornflowerblue: [100, 149, 237],
|
|
20
|
+
cornsilk: [255, 248, 220],
|
|
21
|
+
crimson: [220, 20, 60],
|
|
22
|
+
cyan: [0, 255, 255],
|
|
23
|
+
darkblue: [0, 0, 139],
|
|
24
|
+
darkcyan: [0, 139, 139],
|
|
25
|
+
darkgoldenrod: [184, 134, 11],
|
|
26
|
+
darkgray: [169, 169, 169],
|
|
27
|
+
darkgreen: [0, 100, 0],
|
|
28
|
+
darkgrey: [169, 169, 169],
|
|
29
|
+
darkkhaki: [189, 183, 107],
|
|
30
|
+
darkmagenta: [139, 0, 139],
|
|
31
|
+
darkolivegreen: [85, 107, 47],
|
|
32
|
+
darkorange: [255, 140, 0],
|
|
33
|
+
darkorchid: [153, 50, 204],
|
|
34
|
+
darkred: [139, 0, 0],
|
|
35
|
+
darksalmon: [233, 150, 122],
|
|
36
|
+
darkseagreen: [143, 188, 143],
|
|
37
|
+
darkslateblue: [72, 61, 139],
|
|
38
|
+
darkslategray: [47, 79, 79],
|
|
39
|
+
darkslategrey: [47, 79, 79],
|
|
40
|
+
darkturquoise: [0, 206, 209],
|
|
41
|
+
darkviolet: [148, 0, 211],
|
|
42
|
+
deeppink: [255, 20, 147],
|
|
43
|
+
deepskyblue: [0, 191, 255],
|
|
44
|
+
dimgray: [105, 105, 105],
|
|
45
|
+
dimgrey: [105, 105, 105],
|
|
46
|
+
dodgerblue: [30, 144, 255],
|
|
47
|
+
firebrick: [178, 34, 34],
|
|
48
|
+
floralwhite: [255, 250, 240],
|
|
49
|
+
forestgreen: [34, 139, 34],
|
|
50
|
+
fuchsia: [255, 0, 255],
|
|
51
|
+
gainsboro: [220, 220, 220],
|
|
52
|
+
ghostwhite: [248, 248, 255],
|
|
53
|
+
gold: [255, 215, 0],
|
|
54
|
+
goldenrod: [218, 165, 32],
|
|
55
|
+
gray: [128, 128, 128],
|
|
56
|
+
green: [0, 128, 0],
|
|
57
|
+
greenyellow: [173, 255, 47],
|
|
58
|
+
grey: [128, 128, 128],
|
|
59
|
+
honeydew: [240, 255, 240],
|
|
60
|
+
hotpink: [255, 105, 180],
|
|
61
|
+
indianred: [205, 92, 92],
|
|
62
|
+
indigo: [75, 0, 130],
|
|
63
|
+
ivory: [255, 255, 240],
|
|
64
|
+
khaki: [240, 230, 140],
|
|
65
|
+
lavender: [230, 230, 250],
|
|
66
|
+
lavenderblush: [255, 240, 245],
|
|
67
|
+
lawngreen: [124, 252, 0],
|
|
68
|
+
lemonchiffon: [255, 250, 205],
|
|
69
|
+
lightblue: [173, 216, 230],
|
|
70
|
+
lightcoral: [240, 128, 128],
|
|
71
|
+
lightcyan: [224, 255, 255],
|
|
72
|
+
lightgoldenrodyellow: [250, 250, 210],
|
|
73
|
+
lightgray: [211, 211, 211],
|
|
74
|
+
lightgreen: [144, 238, 144],
|
|
75
|
+
lightgrey: [211, 211, 211],
|
|
76
|
+
lightpink: [255, 182, 193],
|
|
77
|
+
lightsalmon: [255, 160, 122],
|
|
78
|
+
lightseagreen: [32, 178, 170],
|
|
79
|
+
lightskyblue: [135, 206, 250],
|
|
80
|
+
lightslategray: [119, 136, 153],
|
|
81
|
+
lightslategrey: [119, 136, 153],
|
|
82
|
+
lightsteelblue: [176, 196, 222],
|
|
83
|
+
lightyellow: [255, 255, 224],
|
|
84
|
+
lime: [0, 255, 0],
|
|
85
|
+
limegreen: [50, 205, 50],
|
|
86
|
+
linen: [250, 240, 230],
|
|
87
|
+
magenta: [255, 0, 255],
|
|
88
|
+
maroon: [128, 0, 0],
|
|
89
|
+
mediumaquamarine: [102, 205, 170],
|
|
90
|
+
mediumblue: [0, 0, 205],
|
|
91
|
+
mediumorchid: [186, 85, 211],
|
|
92
|
+
mediumpurple: [147, 112, 219],
|
|
93
|
+
mediumseagreen: [60, 179, 113],
|
|
94
|
+
mediumslateblue: [123, 104, 238],
|
|
95
|
+
mediumspringgreen: [0, 250, 154],
|
|
96
|
+
mediumturquoise: [72, 209, 204],
|
|
97
|
+
mediumvioletred: [199, 21, 133],
|
|
98
|
+
midnightblue: [25, 25, 112],
|
|
99
|
+
mintcream: [245, 255, 250],
|
|
100
|
+
mistyrose: [255, 228, 225],
|
|
101
|
+
moccasin: [255, 228, 181],
|
|
102
|
+
navajowhite: [255, 222, 173],
|
|
103
|
+
navy: [0, 0, 128],
|
|
104
|
+
oldlace: [253, 245, 230],
|
|
105
|
+
olive: [128, 128, 0],
|
|
106
|
+
olivedrab: [107, 142, 35],
|
|
107
|
+
orange: [255, 165, 0],
|
|
108
|
+
orangered: [255, 69, 0],
|
|
109
|
+
orchid: [218, 112, 214],
|
|
110
|
+
palegoldenrod: [238, 232, 170],
|
|
111
|
+
palegreen: [152, 251, 152],
|
|
112
|
+
paleturquoise: [175, 238, 238],
|
|
113
|
+
palevioletred: [219, 112, 147],
|
|
114
|
+
papayawhip: [255, 239, 213],
|
|
115
|
+
peachpuff: [255, 218, 185],
|
|
116
|
+
peru: [205, 133, 63],
|
|
117
|
+
pink: [255, 192, 203],
|
|
118
|
+
plum: [221, 160, 221],
|
|
119
|
+
powderblue: [176, 224, 230],
|
|
120
|
+
purple: [128, 0, 128],
|
|
121
|
+
rebeccapurple: [102, 51, 153],
|
|
122
|
+
red: [255, 0, 0],
|
|
123
|
+
rosybrown: [188, 143, 143],
|
|
124
|
+
royalblue: [65, 105, 225],
|
|
125
|
+
saddlebrown: [139, 69, 19],
|
|
126
|
+
salmon: [250, 128, 114],
|
|
127
|
+
sandybrown: [244, 164, 96],
|
|
128
|
+
seagreen: [46, 139, 87],
|
|
129
|
+
seashell: [255, 245, 238],
|
|
130
|
+
sienna: [160, 82, 45],
|
|
131
|
+
silver: [192, 192, 192],
|
|
132
|
+
skyblue: [135, 206, 235],
|
|
133
|
+
slateblue: [106, 90, 205],
|
|
134
|
+
slategray: [112, 128, 144],
|
|
135
|
+
slategrey: [112, 128, 144],
|
|
136
|
+
snow: [255, 250, 250],
|
|
137
|
+
springgreen: [0, 255, 127],
|
|
138
|
+
steelblue: [70, 130, 180],
|
|
139
|
+
tan: [210, 180, 140],
|
|
140
|
+
teal: [0, 128, 128],
|
|
141
|
+
thistle: [216, 191, 216],
|
|
142
|
+
tomato: [255, 99, 71],
|
|
143
|
+
turquoise: [64, 224, 208],
|
|
144
|
+
violet: [238, 130, 238],
|
|
145
|
+
wheat: [245, 222, 179],
|
|
146
|
+
white: [255, 255, 255],
|
|
147
|
+
whitesmoke: [245, 245, 245],
|
|
148
|
+
yellow: [255, 255, 0],
|
|
149
|
+
yellowgreen: [154, 205, 50]
|
|
150
|
+
};
|
|
151
|
+
export {
|
|
152
|
+
e as NAMED_COLORS
|
|
153
|
+
};
|
package/color-oklab.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const a=require("./color-D7FAmkht.cjs");exports.canParseOklab=a.canParseOklab;exports.canParseOklch=a.canParseOklch;exports.oklabaToOklabString=a.oklabaToOklabString;exports.oklabaToRgb8a=a.oklabaToRgb8a;exports.oklchaToOklchString=a.oklchaToOklchString;exports.oklchaToRgb8a=a.oklchaToRgb8a;exports.parseOklab=a.parseOklab;exports.parseOklch=a.parseOklch;exports.rgb8aToOklaba=a.rgb8aToOklaba;exports.rgb8aToOklcha=a.rgb8aToOklcha;
|
package/color-oklab.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { RGB8A, OKLABA, OKLCHA } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the string can be parsed as an `oklab()` color.
|
|
4
|
+
*
|
|
5
|
+
* @param s - The string to test.
|
|
6
|
+
* @returns `true` if the string matches the `oklab()` format.
|
|
7
|
+
* @public
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* canParseOklab('oklab(0.5 -0.1 0.1)') // true
|
|
11
|
+
* canParseOklab('red') // false
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const canParseOklab: (s: string) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Parses an `oklab()` color string into an OKLABA color.
|
|
17
|
+
*
|
|
18
|
+
* L may be a percentage (0–100% mapped to 0–1) or a decimal (0–1). The `a`
|
|
19
|
+
* and `b` channels are decimals that may be negative.
|
|
20
|
+
*
|
|
21
|
+
* @param s - The string to parse.
|
|
22
|
+
* @returns An OKLABA color.
|
|
23
|
+
* @throws ParsingError if the string is not a valid OKLAB color.
|
|
24
|
+
* @public
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* parseOklab('oklab(0.5 -0.1 0.1)') // oklaba(0.5, -0.1, 0.1)
|
|
28
|
+
* parseOklab('oklab(50% -0.1 0.1 / 0.8)') // oklaba(0.5, -0.1, 0.1, 0.8)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const parseOklab: (s: string) => OKLABA;
|
|
32
|
+
/**
|
|
33
|
+
* Returns `true` if the string can be parsed as an `oklch()` color.
|
|
34
|
+
*
|
|
35
|
+
* @param s - The string to test.
|
|
36
|
+
* @returns `true` if the string matches the `oklch()` format.
|
|
37
|
+
* @public
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* canParseOklch('oklch(0.5 0.15 326)') // true
|
|
41
|
+
* canParseOklch('red') // false
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const canParseOklch: (s: string) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Parses an `oklch()` color string into an OKLCHA color.
|
|
47
|
+
*
|
|
48
|
+
* L may be a percentage (0–100% mapped to 0–1) or a decimal (0–1). C is a
|
|
49
|
+
* non-negative decimal and H is an angle in degrees.
|
|
50
|
+
*
|
|
51
|
+
* @param s - The string to parse.
|
|
52
|
+
* @returns An OKLCHA color.
|
|
53
|
+
* @throws ParsingError if the string is not a valid OKLCH color.
|
|
54
|
+
* @public
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* parseOklch('oklch(0.5 0.15 326)') // oklcha(0.5, 0.15, 326)
|
|
58
|
+
* parseOklch('oklch(50% 0.15 326 / 0.8)') // oklcha(0.5, 0.15, 326, 0.8)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const parseOklch: (s: string) => OKLCHA;
|
|
62
|
+
/**
|
|
63
|
+
* Converts an RGB8A color to an OKLABA color.
|
|
64
|
+
*
|
|
65
|
+
* @param c - The RGB8A color to convert.
|
|
66
|
+
* @returns The equivalent OKLABA color.
|
|
67
|
+
* @public
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* rgb8aToOklaba(rgb8a(255, 0, 0)) // oklaba(~0.628, ~0.225, ~0.126)
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const rgb8aToOklaba: (c: RGB8A) => OKLABA;
|
|
74
|
+
/**
|
|
75
|
+
* Converts an OKLABA color to an RGB8A color.
|
|
76
|
+
*
|
|
77
|
+
* @param c - The OKLABA color to convert.
|
|
78
|
+
* @returns The equivalent RGB8A color with channels clamped to 0–255.
|
|
79
|
+
* @public
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* oklabaToRgb8a(oklaba(0.628, 0.225, 0.126)) // rgb8a(~255, ~0, ~0)
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare const oklabaToRgb8a: (c: OKLABA) => RGB8A;
|
|
86
|
+
/**
|
|
87
|
+
* Converts an RGB8A color to an OKLCHA color.
|
|
88
|
+
*
|
|
89
|
+
* @param c - The RGB8A color to convert.
|
|
90
|
+
* @returns The equivalent OKLCHA color.
|
|
91
|
+
* @public
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* rgb8aToOklcha(rgb8a(255, 0, 0)) // oklcha(~0.628, ~0.258, ~29.2)
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare const rgb8aToOklcha: (c: RGB8A) => OKLCHA;
|
|
98
|
+
/**
|
|
99
|
+
* Converts an OKLCHA color to an RGB8A color.
|
|
100
|
+
*
|
|
101
|
+
* @param c - The OKLCHA color to convert.
|
|
102
|
+
* @returns The equivalent RGB8A color with channels clamped to 0–255.
|
|
103
|
+
* @public
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* oklchaToRgb8a(oklcha(0.628, 0.258, 29.2)) // rgb8a(~255, ~0, ~0)
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare const oklchaToRgb8a: (c: OKLCHA) => RGB8A;
|
|
110
|
+
/**
|
|
111
|
+
* Serializes an OKLABA color to a CSS `oklab()` string.
|
|
112
|
+
*
|
|
113
|
+
* Produces `oklab(L a b)` when alpha is 1, or `oklab(L a b / alpha)`
|
|
114
|
+
* otherwise. Values are rounded to 5 decimal places.
|
|
115
|
+
*
|
|
116
|
+
* @param c - The OKLABA color to serialize.
|
|
117
|
+
* @returns A CSS `oklab()` color string.
|
|
118
|
+
* @public
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* oklabaToOklabString(oklaba(0.5, -0.1, 0.1)) // 'oklab(0.5 -0.1 0.1)'
|
|
122
|
+
* oklabaToOklabString(oklaba(0.5, -0.1, 0.1, 0.8)) // 'oklab(0.5 -0.1 0.1 / 0.8)'
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare const oklabaToOklabString: (c: OKLABA) => string;
|
|
126
|
+
/**
|
|
127
|
+
* Serializes an OKLCHA color to a CSS `oklch()` string.
|
|
128
|
+
*
|
|
129
|
+
* Produces `oklch(L C H)` when alpha is 1, or `oklch(L C H / alpha)`
|
|
130
|
+
* otherwise. L and C are rounded to 5 decimal places, H to 2.
|
|
131
|
+
*
|
|
132
|
+
* @param c - The OKLCHA color to serialize.
|
|
133
|
+
* @returns A CSS `oklch()` color string.
|
|
134
|
+
* @public
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* oklchaToOklchString(oklcha(0.5, 0.15, 326)) // 'oklch(0.5 0.15 326)'
|
|
138
|
+
* oklchaToOklchString(oklcha(0.5, 0.15, 326, 0.8)) // 'oklch(0.5 0.15 326 / 0.8)'
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare const oklchaToOklchString: (c: OKLCHA) => string;
|
package/color-oklab.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "./error.js";
|
|
2
|
+
import "./number.js";
|
|
3
|
+
import { i as l, j as r, P as b, Q as c, S as O, T, a1 as g, a2 as h, ab as e, ac as i } from "./color-SZxckS9U.js";
|
|
4
|
+
export {
|
|
5
|
+
l as canParseOklab,
|
|
6
|
+
r as canParseOklch,
|
|
7
|
+
b as oklabaToOklabString,
|
|
8
|
+
c as oklabaToRgb8a,
|
|
9
|
+
O as oklchaToOklchString,
|
|
10
|
+
T as oklchaToRgb8a,
|
|
11
|
+
g as parseOklab,
|
|
12
|
+
h as parseOklch,
|
|
13
|
+
e as rgb8aToOklaba,
|
|
14
|
+
i as rgb8aToOklcha
|
|
15
|
+
};
|
package/color-rgb.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const e=require("./color-D7FAmkht.cjs");require("./color-named.cjs");exports.canParseHex=e.canParseHex;exports.canParseNamedColor=e.canParseNamedColor;exports.canParseRgb=e.canParseRgb;exports.parseHex=e.parseHex;exports.parseNamedColor=e.parseNamedColor;exports.parseRgb=e.parseRgb;exports.rgb8aToHexString=e.rgb8aToHexString;exports.rgb8aToRgbString=e.rgb8aToRgbString;
|
package/color-rgb.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { RGB8A } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the string can be parsed as a hex color.
|
|
4
|
+
*
|
|
5
|
+
* @param s - The string to test.
|
|
6
|
+
* @returns `true` if the string is a valid hex color.
|
|
7
|
+
* @public
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* canParseHex('#ff0000') // true
|
|
11
|
+
* canParseHex('#f00') // true
|
|
12
|
+
* canParseHex('red') // false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const canParseHex: (s: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a hex color string into an RGB8A color.
|
|
18
|
+
*
|
|
19
|
+
* Supports `#RGB`, `#RGBA`, `#RRGGBB`, and `#RRGGBBAA` formats.
|
|
20
|
+
*
|
|
21
|
+
* @param s - The hex string to parse.
|
|
22
|
+
* @returns An RGB8A color.
|
|
23
|
+
* @throws ParsingError if the string is not a valid hex color.
|
|
24
|
+
* @public
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* parseHex('#ff0000') // rgb8a(255, 0, 0)
|
|
28
|
+
* parseHex('#f00') // rgb8a(255, 0, 0)
|
|
29
|
+
* parseHex('#ff000080') // rgb8a(255, 0, 0, ~0.502)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const parseHex: (s: string) => RGB8A;
|
|
33
|
+
/**
|
|
34
|
+
* Returns `true` if the string can be parsed as an `rgb()` or `rgba()` color.
|
|
35
|
+
*
|
|
36
|
+
* @param s - The string to test.
|
|
37
|
+
* @returns `true` if the string is a valid RGB functional notation.
|
|
38
|
+
* @public
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* canParseRgb('rgb(255, 0, 0)') // true
|
|
42
|
+
* canParseRgb('rgb(255 0 0 / 0.5)') // true
|
|
43
|
+
* canParseRgb('#ff0000') // false
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const canParseRgb: (s: string) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Parses an `rgb()` or `rgba()` color string into an RGB8A color.
|
|
49
|
+
*
|
|
50
|
+
* Supports both legacy comma-separated and modern space-separated syntax.
|
|
51
|
+
*
|
|
52
|
+
* @param s - The string to parse.
|
|
53
|
+
* @returns An RGB8A color.
|
|
54
|
+
* @throws ParsingError if the string is not a valid RGB color.
|
|
55
|
+
* @public
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* parseRgb('rgb(255, 0, 0)') // rgb8a(255, 0, 0)
|
|
59
|
+
* parseRgb('rgba(255, 0, 0, 0.5)') // rgb8a(255, 0, 0, 0.5)
|
|
60
|
+
* parseRgb('rgb(255 0 0 / 50%)') // rgb8a(255, 0, 0, 0.5)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const parseRgb: (s: string) => RGB8A;
|
|
64
|
+
/**
|
|
65
|
+
* Returns `true` if the string is a recognized CSS named color.
|
|
66
|
+
*
|
|
67
|
+
* @param s - The string to test (case-insensitive).
|
|
68
|
+
* @returns `true` if the string is a named color.
|
|
69
|
+
* @public
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* canParseNamedColor('red') // true
|
|
73
|
+
* canParseNamedColor('Red') // true
|
|
74
|
+
* canParseNamedColor('notacolor') // false
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare const canParseNamedColor: (s: string) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Parses a CSS named color string into an RGB8A color.
|
|
80
|
+
*
|
|
81
|
+
* @param s - The named color string (case-insensitive).
|
|
82
|
+
* @returns An RGB8A color.
|
|
83
|
+
* @throws ParsingError if the string is not a recognized named color.
|
|
84
|
+
* @public
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* parseNamedColor('red') // rgb8a(255, 0, 0)
|
|
88
|
+
* parseNamedColor('cornflowerblue') // rgb8a(100, 149, 237)
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const parseNamedColor: (s: string) => RGB8A;
|
|
92
|
+
/**
|
|
93
|
+
* Serializes an RGB8A color to a hex string.
|
|
94
|
+
*
|
|
95
|
+
* Produces `#rrggbb` when alpha is 1, or `#rrggbbaa` otherwise.
|
|
96
|
+
*
|
|
97
|
+
* @param c - The RGB8A color to serialize.
|
|
98
|
+
* @returns A hex color string.
|
|
99
|
+
* @public
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* rgb8aToHexString(rgb8a(255, 0, 0)) // '#ff0000'
|
|
103
|
+
* rgb8aToHexString(rgb8a(255, 0, 0, 0.5)) // '#ff000080'
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare const rgb8aToHexString: (c: RGB8A) => string;
|
|
107
|
+
/**
|
|
108
|
+
* Serializes an RGB8A color to an `rgb()` or `rgba()` CSS string.
|
|
109
|
+
*
|
|
110
|
+
* @param c - The RGB8A color to serialize.
|
|
111
|
+
* @returns A CSS color string.
|
|
112
|
+
* @public
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* rgb8aToRgbString(rgb8a(255, 0, 0)) // 'rgb(255, 0, 0)'
|
|
116
|
+
* rgb8aToRgbString(rgb8a(255, 0, 0, 0.5)) // 'rgba(255, 0, 0, 0.5)'
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare const rgb8aToRgbString: (c: RGB8A) => string;
|
package/color-rgb.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./error.js";
|
|
2
|
+
import "./number.js";
|
|
3
|
+
import { a as g, h as p, k as m, W as t, a0 as b, a3 as i, a5 as n, ad as x } from "./color-SZxckS9U.js";
|
|
4
|
+
import "./color-named.js";
|
|
5
|
+
export {
|
|
6
|
+
g as canParseHex,
|
|
7
|
+
p as canParseNamedColor,
|
|
8
|
+
m as canParseRgb,
|
|
9
|
+
t as parseHex,
|
|
10
|
+
b as parseNamedColor,
|
|
11
|
+
i as parseRgb,
|
|
12
|
+
n as rgb8aToHexString,
|
|
13
|
+
x as rgb8aToRgbString
|
|
14
|
+
};
|
package/color-utils.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./number.cjs"),o=require("./random.cjs"),a=require("./color-D7FAmkht.cjs"),c=require("./color-named.cjs"),b=require("./color-distance.cjs"),i=(l,e,t=1)=>{const r=a.convertColor(l,"lab"),n=a.convertColor(e,"lab");return s.nearEqual(r.l,n.l,t)&&s.nearEqual(r.a,n.a,t)&&s.nearEqual(r.b,n.b,t)&&s.nearEqual(r.alpha,n.alpha,.01)},h=(l="rgb8")=>{switch(l){case"rgb":return a.rgba(o.randomFloat(0,1),o.randomFloat(0,1),o.randomFloat(0,1));case"rgb8":return a.rgb8a(Math.round(o.randomFloat(0,255)),Math.round(o.randomFloat(0,255)),Math.round(o.randomFloat(0,255)));case"hsl":return a.hsla(o.randomFloat(0,360),o.randomFloat(0,100),o.randomFloat(0,100));case"hsv":return a.hsva(o.randomFloat(0,360),o.randomFloat(0,100),o.randomFloat(0,100));case"hwb":return a.hwba(o.randomFloat(0,360),o.randomFloat(0,100),o.randomFloat(0,100));case"lab":return a.laba(o.randomFloat(0,100),o.randomFloat(-125,125),o.randomFloat(-125,125));case"lch":return a.lcha(o.randomFloat(0,100),o.randomFloat(0,150),o.randomFloat(0,360));case"oklab":return a.oklaba(o.randomFloat(0,1),o.randomFloat(-.4,.4),o.randomFloat(-.4,.4));case"oklch":return a.oklcha(o.randomFloat(0,1),o.randomFloat(0,.4),o.randomFloat(0,360))}},q=l=>{let e="",t=1/0;for(const r of Object.keys(c.NAMED_COLORS)){const[n,m,u]=c.NAMED_COLORS[r],F=a.rgb8a(n,m,u),d=b.colorDistanceSimple(l,F);d<t&&(t=d,e=r)}return e};exports.closestNamedColor=q;exports.equalColors=i;exports.randomColor=h;
|
package/color-utils.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Color, ColorSpace } from './color';
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether two colors are perceptually equal within
|
|
4
|
+
* a given tolerance, by comparing their CIELAB channels.
|
|
5
|
+
*
|
|
6
|
+
* Both colors are first converted to the LAB color space.
|
|
7
|
+
* The `l`, `a`, and `b` channels are compared using the
|
|
8
|
+
* supplied tolerance, while alpha is compared with a fixed
|
|
9
|
+
* tolerance of 0.01.
|
|
10
|
+
*
|
|
11
|
+
* @param a - The first color.
|
|
12
|
+
* @param b - The second color.
|
|
13
|
+
* @param tolerance - Maximum allowed difference per LAB
|
|
14
|
+
* channel. Defaults to 1.
|
|
15
|
+
* @returns `true` when every channel is within tolerance.
|
|
16
|
+
* @public
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { rgb8a } from './color'
|
|
20
|
+
* equalColors(rgb8a(255, 0, 0), rgb8a(254, 0, 0)) // true
|
|
21
|
+
* equalColors(rgb8a(255, 0, 0), rgb8a(0, 0, 255)) // false
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const equalColors: (a: Color, b: Color, tolerance?: number) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Generates a random color in the specified color space
|
|
27
|
+
* with fully opaque alpha.
|
|
28
|
+
*
|
|
29
|
+
* Each channel is randomised within its natural range for
|
|
30
|
+
* the target space. Alpha is always set to 1.
|
|
31
|
+
*
|
|
32
|
+
* @param space - The color space to generate in.
|
|
33
|
+
* Defaults to `'rgb8'`.
|
|
34
|
+
* @returns A random {@link Color} in the requested space.
|
|
35
|
+
* @public
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const c = randomColor('hsl')
|
|
39
|
+
* c.space // 'hsl'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const randomColor: (space?: ColorSpace) => Color;
|
|
43
|
+
/**
|
|
44
|
+
* Finds the CSS named color closest to the given color
|
|
45
|
+
* using CIE76 (simple Euclidean) distance in CIELAB space.
|
|
46
|
+
*
|
|
47
|
+
* @param c - The color to match against.
|
|
48
|
+
* @returns The lowercase CSS color name that is
|
|
49
|
+
* perceptually closest to `c`.
|
|
50
|
+
* @public
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { rgb8a } from './color'
|
|
54
|
+
* closestNamedColor(rgb8a(255, 0, 0)) // 'red'
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const closestNamedColor: (c: Color) => string;
|
package/color-utils.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { nearEqual as n } from "./number.js";
|
|
2
|
+
import { randomFloat as a } from "./random.js";
|
|
3
|
+
import { m as c, R as f, O as p, L as d, I as g, w as C, s as k, o as w, a4 as m, af as M } from "./color-SZxckS9U.js";
|
|
4
|
+
import { NAMED_COLORS as b } from "./color-named.js";
|
|
5
|
+
import { colorDistanceSimple as O } from "./color-distance.js";
|
|
6
|
+
const A = (t, e, o = 1) => {
|
|
7
|
+
const r = c(t, "lab"), s = c(e, "lab");
|
|
8
|
+
return n(r.l, s.l, o) && n(r.a, s.a, o) && n(r.b, s.b, o) && n(r.alpha, s.alpha, 0.01);
|
|
9
|
+
}, E = (t = "rgb8") => {
|
|
10
|
+
switch (t) {
|
|
11
|
+
case "rgb":
|
|
12
|
+
return M(a(0, 1), a(0, 1), a(0, 1));
|
|
13
|
+
case "rgb8":
|
|
14
|
+
return m(
|
|
15
|
+
Math.round(a(0, 255)),
|
|
16
|
+
Math.round(a(0, 255)),
|
|
17
|
+
Math.round(a(0, 255))
|
|
18
|
+
);
|
|
19
|
+
case "hsl":
|
|
20
|
+
return w(a(0, 360), a(0, 100), a(0, 100));
|
|
21
|
+
case "hsv":
|
|
22
|
+
return k(a(0, 360), a(0, 100), a(0, 100));
|
|
23
|
+
case "hwb":
|
|
24
|
+
return C(a(0, 360), a(0, 100), a(0, 100));
|
|
25
|
+
case "lab":
|
|
26
|
+
return g(
|
|
27
|
+
a(0, 100),
|
|
28
|
+
a(-125, 125),
|
|
29
|
+
a(-125, 125)
|
|
30
|
+
);
|
|
31
|
+
case "lch":
|
|
32
|
+
return d(a(0, 100), a(0, 150), a(0, 360));
|
|
33
|
+
case "oklab":
|
|
34
|
+
return p(
|
|
35
|
+
a(0, 1),
|
|
36
|
+
a(-0.4, 0.4),
|
|
37
|
+
a(-0.4, 0.4)
|
|
38
|
+
);
|
|
39
|
+
case "oklch":
|
|
40
|
+
return f(a(0, 1), a(0, 0.4), a(0, 360));
|
|
41
|
+
}
|
|
42
|
+
}, I = (t) => {
|
|
43
|
+
let e = "", o = 1 / 0;
|
|
44
|
+
for (const r of Object.keys(b)) {
|
|
45
|
+
const [s, h, u] = b[r], i = m(s, h, u), l = O(t, i);
|
|
46
|
+
l < o && (o = l, e = r);
|
|
47
|
+
}
|
|
48
|
+
return e;
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
I as closestNamedColor,
|
|
52
|
+
A as equalColors,
|
|
53
|
+
E as randomColor
|
|
54
|
+
};
|
package/color.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./number.cjs");require("./error.cjs");require("./color-named.cjs");const a=require("./color-D7FAmkht.cjs");exports.canParseColor=a.canParseColor;exports.colorToString=a.colorToString;exports.convertColor=a.convertColor;exports.detectColorSpace=a.detectColorSpace;exports.hsla=a.hsla;exports.hsva=a.hsva;exports.hwba=a.hwba;exports.isHsla=a.isHsla;exports.isHsva=a.isHsva;exports.isHwba=a.isHwba;exports.isLaba=a.isLaba;exports.isLcha=a.isLcha;exports.isOklaba=a.isOklaba;exports.isOklcha=a.isOklcha;exports.isRgb8a=a.isRgb8a;exports.isRgba=a.isRgba;exports.laba=a.laba;exports.lcha=a.lcha;exports.oklaba=a.oklaba;exports.oklcha=a.oklcha;exports.parseAlpha=a.parseAlpha;exports.parseColor=a.parseColor;exports.rgb8a=a.rgb8a;exports.rgb8aToHexString=a.rgb8aToHexString;exports.rgb8aToRgba=a.rgb8aToRgba;exports.rgba=a.rgba;exports.rgbaToRgb8a=a.rgbaToRgb8a;
|