@kurkle/color 0.3.4 → 0.5.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/README.md +13 -1
- package/dist/byte.d.ts +35 -0
- package/dist/color.cjs +460 -328
- package/dist/color.cjs.map +7 -0
- package/dist/color.d.ts +55 -155
- package/dist/color.esm.js +431 -295
- package/dist/color.esm.js.map +7 -0
- package/dist/color.min.js +3 -3
- package/dist/color.min.js.map +7 -1
- package/dist/hex.d.ts +16 -0
- package/dist/hue.d.ts +53 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.esm.d.ts +18 -0
- package/dist/names.d.ts +11 -0
- package/dist/packed.d.ts +9 -0
- package/dist/rgb.d.ts +16 -0
- package/dist/srgb.d.ts +12 -0
- package/package.json +26 -35
package/dist/color.esm.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @kurkle/color v0.
|
|
2
|
+
* @kurkle/color v0.0.0-development
|
|
3
3
|
* https://github.com/kurkle/color#readme
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2026 Jukka Kurkela
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
*/
|
|
7
|
+
|
|
8
|
+
// src/byte.ts
|
|
7
9
|
function round(v) {
|
|
8
10
|
return v + 0.5 | 0;
|
|
9
11
|
}
|
|
10
|
-
|
|
12
|
+
var lim = (v, l, h) => Math.max(Math.min(v, h), l);
|
|
11
13
|
function p2b(v) {
|
|
12
14
|
return lim(round(v * 2.55), 0, 255);
|
|
13
15
|
}
|
|
@@ -24,43 +26,66 @@ function n2p(v) {
|
|
|
24
26
|
return lim(round(v * 100), 0, 100);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
// src/hex.ts
|
|
30
|
+
var map = {
|
|
31
|
+
0: 0,
|
|
32
|
+
1: 1,
|
|
33
|
+
2: 2,
|
|
34
|
+
3: 3,
|
|
35
|
+
4: 4,
|
|
36
|
+
5: 5,
|
|
37
|
+
6: 6,
|
|
38
|
+
7: 7,
|
|
39
|
+
8: 8,
|
|
40
|
+
9: 9,
|
|
41
|
+
A: 10,
|
|
42
|
+
a: 10,
|
|
43
|
+
B: 11,
|
|
44
|
+
b: 11,
|
|
45
|
+
C: 12,
|
|
46
|
+
c: 12,
|
|
47
|
+
D: 13,
|
|
48
|
+
d: 13,
|
|
49
|
+
E: 14,
|
|
50
|
+
e: 14,
|
|
51
|
+
F: 15,
|
|
52
|
+
f: 15
|
|
53
|
+
};
|
|
54
|
+
var hex = [..."0123456789ABCDEF"];
|
|
55
|
+
var h1 = (b) => hex[b & 15];
|
|
56
|
+
var h2 = (b) => hex[(b & 240) >> 4] + hex[b & 15];
|
|
57
|
+
var eq = (b) => (b & 240) >> 4 === (b & 15);
|
|
58
|
+
var isShort = (v) => eq(v.r) && eq(v.g) && eq(v.b) && eq(v.a);
|
|
33
59
|
function hexParse(str) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (str[0] === '#') {
|
|
37
|
-
if (len === 4 || len === 5) {
|
|
38
|
-
ret = {
|
|
39
|
-
r: 255 & map$1[str[1]] * 17,
|
|
40
|
-
g: 255 & map$1[str[2]] * 17,
|
|
41
|
-
b: 255 & map$1[str[3]] * 17,
|
|
42
|
-
a: len === 5 ? map$1[str[4]] * 17 : 255
|
|
43
|
-
};
|
|
44
|
-
} else if (len === 7 || len === 9) {
|
|
45
|
-
ret = {
|
|
46
|
-
r: map$1[str[1]] << 4 | map$1[str[2]],
|
|
47
|
-
g: map$1[str[3]] << 4 | map$1[str[4]],
|
|
48
|
-
b: map$1[str[5]] << 4 | map$1[str[6]],
|
|
49
|
-
a: len === 9 ? (map$1[str[7]] << 4 | map$1[str[8]]) : 255
|
|
50
|
-
};
|
|
51
|
-
}
|
|
60
|
+
if (str[0] !== "#") {
|
|
61
|
+
return;
|
|
52
62
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
const len = str.length;
|
|
64
|
+
if (len === 4 || len === 5) {
|
|
65
|
+
return {
|
|
66
|
+
a: len === 5 ? map[str[4]] << 4 | map[str[4]] : 255,
|
|
67
|
+
b: map[str[3]] << 4 | map[str[3]],
|
|
68
|
+
g: map[str[2]] << 4 | map[str[2]],
|
|
69
|
+
r: map[str[1]] << 4 | map[str[1]]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (len === 7 || len === 9) {
|
|
73
|
+
return {
|
|
74
|
+
a: len === 9 ? map[str[7]] << 4 | map[str[8]] : 255,
|
|
75
|
+
b: map[str[5]] << 4 | map[str[6]],
|
|
76
|
+
g: map[str[3]] << 4 | map[str[4]],
|
|
77
|
+
r: map[str[1]] << 4 | map[str[2]]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
var alpha = (a, f) => a < 255 ? f(a) : "";
|
|
56
82
|
function hexString(v) {
|
|
57
|
-
|
|
58
|
-
return v
|
|
59
|
-
? '#' + f(v.r) + f(v.g) + f(v.b) + alpha(v.a, f)
|
|
60
|
-
: undefined;
|
|
83
|
+
const f = v && isShort(v) ? h1 : h2;
|
|
84
|
+
return v ? `#${f(v.r)}${f(v.g)}${f(v.b)}${alpha(v.a, f)}` : void 0;
|
|
61
85
|
}
|
|
62
86
|
|
|
63
|
-
|
|
87
|
+
// src/hue.ts
|
|
88
|
+
var HUE_RE = /^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;
|
|
64
89
|
function hsl2rgbn(h, s, l) {
|
|
65
90
|
const a = s * Math.min(l, 1 - l);
|
|
66
91
|
const f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
@@ -86,7 +111,7 @@ function hwb2rgbn(h, w, b) {
|
|
|
86
111
|
}
|
|
87
112
|
function hueValue(r, g, b, d, max) {
|
|
88
113
|
if (r === max) {
|
|
89
|
-
return (
|
|
114
|
+
return (g - b) / d + (g < b ? 6 : 0);
|
|
90
115
|
}
|
|
91
116
|
if (g === max) {
|
|
92
117
|
return (b - r) / d + 2;
|
|
@@ -101,7 +126,9 @@ function rgb2hsl(v) {
|
|
|
101
126
|
const max = Math.max(r, g, b);
|
|
102
127
|
const min = Math.min(r, g, b);
|
|
103
128
|
const l = (max + min) / 2;
|
|
104
|
-
let h
|
|
129
|
+
let h = 0;
|
|
130
|
+
let s = 0;
|
|
131
|
+
let d;
|
|
105
132
|
if (max !== min) {
|
|
106
133
|
d = max - min;
|
|
107
134
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
@@ -111,11 +138,7 @@ function rgb2hsl(v) {
|
|
|
111
138
|
return [h | 0, s || 0, l];
|
|
112
139
|
}
|
|
113
140
|
function calln(f, a, b, c) {
|
|
114
|
-
return (
|
|
115
|
-
Array.isArray(a)
|
|
116
|
-
? f(a[0], a[1], a[2])
|
|
117
|
-
: f(a, b, c)
|
|
118
|
-
).map(n2b);
|
|
141
|
+
return (Array.isArray(a) ? f(a[0], a[1], a[2]) : f(a, b, c)).map(n2b);
|
|
119
142
|
}
|
|
120
143
|
function hsl2rgb(h, s, l) {
|
|
121
144
|
return calln(hsl2rgbn, h, s, l);
|
|
@@ -134,269 +157,270 @@ function hueParse(str) {
|
|
|
134
157
|
let a = 255;
|
|
135
158
|
let v;
|
|
136
159
|
if (!m) {
|
|
137
|
-
return;
|
|
160
|
+
return void 0;
|
|
138
161
|
}
|
|
139
|
-
if (m[5] !==
|
|
162
|
+
if (m[5] !== void 0) {
|
|
140
163
|
a = m[6] ? p2b(+m[5]) : n2b(+m[5]);
|
|
141
164
|
}
|
|
142
165
|
const h = hue(+m[2]);
|
|
143
166
|
const p1 = +m[3] / 100;
|
|
144
167
|
const p2 = +m[4] / 100;
|
|
145
|
-
if (m[1] ===
|
|
168
|
+
if (m[1] === "hwb") {
|
|
146
169
|
v = hwb2rgb(h, p1, p2);
|
|
147
|
-
} else if (m[1] ===
|
|
170
|
+
} else if (m[1] === "hsv") {
|
|
148
171
|
v = hsv2rgb(h, p1, p2);
|
|
149
172
|
} else {
|
|
150
173
|
v = hsl2rgb(h, p1, p2);
|
|
151
174
|
}
|
|
152
175
|
return {
|
|
153
|
-
|
|
154
|
-
g: v[1],
|
|
176
|
+
a,
|
|
155
177
|
b: v[2],
|
|
156
|
-
|
|
178
|
+
g: v[1],
|
|
179
|
+
r: v[0]
|
|
157
180
|
};
|
|
158
181
|
}
|
|
159
182
|
function rotate(v, deg) {
|
|
160
|
-
|
|
183
|
+
const h = rgb2hsl(v);
|
|
161
184
|
h[0] = hue(h[0] + deg);
|
|
162
|
-
|
|
163
|
-
v.r =
|
|
164
|
-
v.g =
|
|
165
|
-
v.b =
|
|
185
|
+
const rgb = hsl2rgb(h);
|
|
186
|
+
v.r = rgb[0];
|
|
187
|
+
v.g = rgb[1];
|
|
188
|
+
v.b = rgb[2];
|
|
166
189
|
}
|
|
167
190
|
function hslString(v) {
|
|
168
191
|
if (!v) {
|
|
169
|
-
return;
|
|
192
|
+
return void 0;
|
|
170
193
|
}
|
|
171
194
|
const a = rgb2hsl(v);
|
|
172
195
|
const h = a[0];
|
|
173
196
|
const s = n2p(a[1]);
|
|
174
197
|
const l = n2p(a[2]);
|
|
175
|
-
return v.a < 255
|
|
176
|
-
? `hsla(${h}, ${s}%, ${l}%, ${b2n(v.a)})`
|
|
177
|
-
: `hsl(${h}, ${s}%, ${l}%)`;
|
|
198
|
+
return v.a < 255 ? `hsla(${h}, ${s}%, ${l}%, ${b2n(v.a)})` : `hsl(${h}, ${s}%, ${l}%)`;
|
|
178
199
|
}
|
|
179
200
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
201
|
+
// src/packed.ts
|
|
202
|
+
var map2 = {
|
|
203
|
+
x: "dark",
|
|
204
|
+
Z: "light",
|
|
205
|
+
Y: "re",
|
|
206
|
+
X: "blu",
|
|
207
|
+
W: "gr",
|
|
208
|
+
V: "medium",
|
|
209
|
+
U: "slate",
|
|
210
|
+
A: "ee",
|
|
211
|
+
T: "ol",
|
|
212
|
+
S: "or",
|
|
213
|
+
B: "ra",
|
|
214
|
+
C: "lateg",
|
|
215
|
+
D: "ights",
|
|
216
|
+
R: "in",
|
|
217
|
+
Q: "turquois",
|
|
218
|
+
E: "hi",
|
|
219
|
+
P: "ro",
|
|
220
|
+
O: "al",
|
|
221
|
+
N: "le",
|
|
222
|
+
M: "de",
|
|
223
|
+
L: "yello",
|
|
224
|
+
F: "en",
|
|
225
|
+
K: "ch",
|
|
226
|
+
G: "arks",
|
|
227
|
+
H: "ea",
|
|
228
|
+
I: "ightg",
|
|
229
|
+
J: "wh"
|
|
208
230
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
231
|
+
var names = {
|
|
232
|
+
OiceXe: "f0f8ff",
|
|
233
|
+
antiquewEte: "faebd7",
|
|
234
|
+
aqua: "ffff",
|
|
235
|
+
aquamarRe: "7fffd4",
|
|
236
|
+
azuY: "f0ffff",
|
|
237
|
+
beige: "f5f5dc",
|
|
238
|
+
bisque: "ffe4c4",
|
|
239
|
+
black: "0",
|
|
240
|
+
blanKedOmond: "ffebcd",
|
|
241
|
+
Xe: "ff",
|
|
242
|
+
XeviTet: "8a2be2",
|
|
243
|
+
bPwn: "a52a2a",
|
|
244
|
+
burlywood: "deb887",
|
|
245
|
+
caMtXe: "5f9ea0",
|
|
246
|
+
KartYuse: "7fff00",
|
|
247
|
+
KocTate: "d2691e",
|
|
248
|
+
cSO: "ff7f50",
|
|
249
|
+
cSnflowerXe: "6495ed",
|
|
250
|
+
cSnsilk: "fff8dc",
|
|
251
|
+
crimson: "dc143c",
|
|
252
|
+
cyan: "ffff",
|
|
253
|
+
xXe: "8b",
|
|
254
|
+
xcyan: "8b8b",
|
|
255
|
+
xgTMnPd: "b8860b",
|
|
256
|
+
xWay: "a9a9a9",
|
|
257
|
+
xgYF: "6400",
|
|
258
|
+
xgYy: "a9a9a9",
|
|
259
|
+
xkhaki: "bdb76b",
|
|
260
|
+
xmagFta: "8b008b",
|
|
261
|
+
xTivegYF: "556b2f",
|
|
262
|
+
xSange: "ff8c00",
|
|
263
|
+
xScEd: "9932cc",
|
|
264
|
+
xYd: "8b0000",
|
|
265
|
+
xsOmon: "e9967a",
|
|
266
|
+
xsHgYF: "8fbc8f",
|
|
267
|
+
xUXe: "483d8b",
|
|
268
|
+
xUWay: "2f4f4f",
|
|
269
|
+
xUgYy: "2f4f4f",
|
|
270
|
+
xQe: "ced1",
|
|
271
|
+
xviTet: "9400d3",
|
|
272
|
+
dAppRk: "ff1493",
|
|
273
|
+
dApskyXe: "bfff",
|
|
274
|
+
dimWay: "696969",
|
|
275
|
+
dimgYy: "696969",
|
|
276
|
+
dodgerXe: "1e90ff",
|
|
277
|
+
fiYbrick: "b22222",
|
|
278
|
+
flSOwEte: "fffaf0",
|
|
279
|
+
foYstWAn: "228b22",
|
|
280
|
+
fuKsia: "ff00ff",
|
|
281
|
+
gaRsbSo: "dcdcdc",
|
|
282
|
+
ghostwEte: "f8f8ff",
|
|
283
|
+
gTd: "ffd700",
|
|
284
|
+
gTMnPd: "daa520",
|
|
285
|
+
Way: "808080",
|
|
286
|
+
gYF: "8000",
|
|
287
|
+
gYFLw: "adff2f",
|
|
288
|
+
gYy: "808080",
|
|
289
|
+
honeyMw: "f0fff0",
|
|
290
|
+
hotpRk: "ff69b4",
|
|
291
|
+
RdianYd: "cd5c5c",
|
|
292
|
+
Rdigo: "4b0082",
|
|
293
|
+
ivSy: "fffff0",
|
|
294
|
+
khaki: "f0e68c",
|
|
295
|
+
lavFMr: "e6e6fa",
|
|
296
|
+
lavFMrXsh: "fff0f5",
|
|
297
|
+
lawngYF: "7cfc00",
|
|
298
|
+
NmoncEffon: "fffacd",
|
|
299
|
+
ZXe: "add8e6",
|
|
300
|
+
ZcSO: "f08080",
|
|
301
|
+
Zcyan: "e0ffff",
|
|
302
|
+
ZgTMnPdLw: "fafad2",
|
|
303
|
+
ZWay: "d3d3d3",
|
|
304
|
+
ZgYF: "90ee90",
|
|
305
|
+
ZgYy: "d3d3d3",
|
|
306
|
+
ZpRk: "ffb6c1",
|
|
307
|
+
ZsOmon: "ffa07a",
|
|
308
|
+
ZsHgYF: "20b2aa",
|
|
309
|
+
ZskyXe: "87cefa",
|
|
310
|
+
ZUWay: "778899",
|
|
311
|
+
ZUgYy: "778899",
|
|
312
|
+
ZstAlXe: "b0c4de",
|
|
313
|
+
ZLw: "ffffe0",
|
|
314
|
+
lime: "ff00",
|
|
315
|
+
limegYF: "32cd32",
|
|
316
|
+
lRF: "faf0e6",
|
|
317
|
+
magFta: "ff00ff",
|
|
318
|
+
maPon: "800000",
|
|
319
|
+
VaquamarRe: "66cdaa",
|
|
320
|
+
VXe: "cd",
|
|
321
|
+
VScEd: "ba55d3",
|
|
322
|
+
VpurpN: "9370db",
|
|
323
|
+
VsHgYF: "3cb371",
|
|
324
|
+
VUXe: "7b68ee",
|
|
325
|
+
VsprRggYF: "fa9a",
|
|
326
|
+
VQe: "48d1cc",
|
|
327
|
+
VviTetYd: "c71585",
|
|
328
|
+
midnightXe: "191970",
|
|
329
|
+
mRtcYam: "f5fffa",
|
|
330
|
+
mistyPse: "ffe4e1",
|
|
331
|
+
moccasR: "ffe4b5",
|
|
332
|
+
navajowEte: "ffdead",
|
|
333
|
+
navy: "80",
|
|
334
|
+
Tdlace: "fdf5e6",
|
|
335
|
+
Tive: "808000",
|
|
336
|
+
TivedBb: "6b8e23",
|
|
337
|
+
Sange: "ffa500",
|
|
338
|
+
SangeYd: "ff4500",
|
|
339
|
+
ScEd: "da70d6",
|
|
340
|
+
pOegTMnPd: "eee8aa",
|
|
341
|
+
pOegYF: "98fb98",
|
|
342
|
+
pOeQe: "afeeee",
|
|
343
|
+
pOeviTetYd: "db7093",
|
|
344
|
+
papayawEp: "ffefd5",
|
|
345
|
+
pHKpuff: "ffdab9",
|
|
346
|
+
peru: "cd853f",
|
|
347
|
+
pRk: "ffc0cb",
|
|
348
|
+
plum: "dda0dd",
|
|
349
|
+
powMrXe: "b0e0e6",
|
|
350
|
+
purpN: "800080",
|
|
351
|
+
YbeccapurpN: "663399",
|
|
352
|
+
Yd: "ff0000",
|
|
353
|
+
Psybrown: "bc8f8f",
|
|
354
|
+
PyOXe: "4169e1",
|
|
355
|
+
saddNbPwn: "8b4513",
|
|
356
|
+
sOmon: "fa8072",
|
|
357
|
+
sandybPwn: "f4a460",
|
|
358
|
+
sHgYF: "2e8b57",
|
|
359
|
+
sHshell: "fff5ee",
|
|
360
|
+
siFna: "a0522d",
|
|
361
|
+
silver: "c0c0c0",
|
|
362
|
+
skyXe: "87ceeb",
|
|
363
|
+
UXe: "6a5acd",
|
|
364
|
+
UWay: "708090",
|
|
365
|
+
UgYy: "708090",
|
|
366
|
+
snow: "fffafa",
|
|
367
|
+
sprRggYF: "ff7f",
|
|
368
|
+
stAlXe: "4682b4",
|
|
369
|
+
tan: "d2b48c",
|
|
370
|
+
teO: "8080",
|
|
371
|
+
tEstN: "d8bfd8",
|
|
372
|
+
tomato: "ff6347",
|
|
373
|
+
Qe: "40e0d0",
|
|
374
|
+
viTet: "ee82ee",
|
|
375
|
+
JHt: "f5deb3",
|
|
376
|
+
wEte: "ffffff",
|
|
377
|
+
wEtesmoke: "f5f5f5",
|
|
378
|
+
Lw: "ffff00",
|
|
379
|
+
LwgYF: "9acd32"
|
|
358
380
|
};
|
|
359
381
|
function unpack() {
|
|
360
382
|
const unpacked = {};
|
|
361
|
-
const keys = Object.keys(names
|
|
362
|
-
const tkeys = Object.keys(
|
|
383
|
+
const keys = Object.keys(names);
|
|
384
|
+
const tkeys = Object.keys(map2);
|
|
363
385
|
let i, j, k, ok, nk;
|
|
364
386
|
for (i = 0; i < keys.length; i++) {
|
|
365
387
|
ok = nk = keys[i];
|
|
366
388
|
for (j = 0; j < tkeys.length; j++) {
|
|
367
389
|
k = tkeys[j];
|
|
368
|
-
nk = nk.replace(k,
|
|
390
|
+
nk = nk.replace(k, map2[k]);
|
|
369
391
|
}
|
|
370
|
-
k = parseInt(names
|
|
371
|
-
unpacked[nk] = [k >> 16 &
|
|
392
|
+
k = parseInt(names[ok], 16);
|
|
393
|
+
unpacked[nk] = [k >> 16 & 255, k >> 8 & 255, k & 255];
|
|
372
394
|
}
|
|
373
395
|
return unpacked;
|
|
374
396
|
}
|
|
375
397
|
|
|
376
|
-
|
|
398
|
+
// src/names.ts
|
|
399
|
+
var names2;
|
|
377
400
|
function nameParse(str) {
|
|
378
|
-
if (!
|
|
379
|
-
|
|
380
|
-
|
|
401
|
+
if (!names2) {
|
|
402
|
+
names2 = unpack();
|
|
403
|
+
names2.transparent = [0, 0, 0, 0];
|
|
381
404
|
}
|
|
382
|
-
const a =
|
|
405
|
+
const a = names2[str.toLowerCase()];
|
|
383
406
|
return a && {
|
|
384
|
-
|
|
385
|
-
g: a[1],
|
|
407
|
+
a: a.length === 4 ? a[3] : 255,
|
|
386
408
|
b: a[2],
|
|
387
|
-
|
|
409
|
+
g: a[1],
|
|
410
|
+
r: a[0]
|
|
388
411
|
};
|
|
389
412
|
}
|
|
390
413
|
|
|
391
|
-
|
|
414
|
+
// src/rgb.ts
|
|
415
|
+
var RGB_RE = /^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;
|
|
392
416
|
function rgbParse(str) {
|
|
393
417
|
const m = RGB_RE.exec(str);
|
|
394
418
|
let a = 255;
|
|
395
419
|
let r, g, b;
|
|
396
420
|
if (!m) {
|
|
397
|
-
return;
|
|
421
|
+
return void 0;
|
|
398
422
|
}
|
|
399
|
-
if (m[7] !==
|
|
423
|
+
if (m[7] !== void 0) {
|
|
400
424
|
const v = +m[7];
|
|
401
425
|
a = m[8] ? p2b(v) : lim(v * 255, 0, 255);
|
|
402
426
|
}
|
|
@@ -407,34 +431,33 @@ function rgbParse(str) {
|
|
|
407
431
|
g = 255 & (m[4] ? p2b(g) : lim(g, 0, 255));
|
|
408
432
|
b = 255 & (m[6] ? p2b(b) : lim(b, 0, 255));
|
|
409
433
|
return {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
434
|
+
a,
|
|
435
|
+
b,
|
|
436
|
+
g,
|
|
437
|
+
r
|
|
414
438
|
};
|
|
415
439
|
}
|
|
416
440
|
function rgbString(v) {
|
|
417
|
-
return v && (
|
|
418
|
-
v.a < 255
|
|
419
|
-
? `rgba(${v.r}, ${v.g}, ${v.b}, ${b2n(v.a)})`
|
|
420
|
-
: `rgb(${v.r}, ${v.g}, ${v.b})`
|
|
421
|
-
);
|
|
441
|
+
return v && (v.a < 255 ? `rgba(${v.r}, ${v.g}, ${v.b}, ${b2n(v.a)})` : `rgb(${v.r}, ${v.g}, ${v.b})`);
|
|
422
442
|
}
|
|
423
443
|
|
|
424
|
-
|
|
425
|
-
|
|
444
|
+
// src/srgb.ts
|
|
445
|
+
var to = (v) => v <= 31308e-7 ? v * 12.92 : v ** (1 / 2.4) * 1.055 - 0.055;
|
|
446
|
+
var from = (v) => v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
426
447
|
function interpolate(rgb1, rgb2, t) {
|
|
427
448
|
const r = from(b2n(rgb1.r));
|
|
428
449
|
const g = from(b2n(rgb1.g));
|
|
429
450
|
const b = from(b2n(rgb1.b));
|
|
430
451
|
return {
|
|
431
|
-
|
|
432
|
-
g: n2b(to(g + t * (from(b2n(rgb2.g)) - g))),
|
|
452
|
+
a: rgb1.a + t * (rgb2.a - rgb1.a),
|
|
433
453
|
b: n2b(to(b + t * (from(b2n(rgb2.b)) - b))),
|
|
434
|
-
|
|
454
|
+
g: n2b(to(g + t * (from(b2n(rgb2.g)) - g))),
|
|
455
|
+
r: n2b(to(r + t * (from(b2n(rgb2.r)) - r)))
|
|
435
456
|
};
|
|
436
457
|
}
|
|
437
458
|
|
|
459
|
+
// src/color.ts
|
|
460
|
+
var COMMENT_REGEXP = /\/\*[\s\S]*?\*\//g;
|
|
438
461
|
function modHSL(v, i, ratio) {
|
|
439
462
|
if (v) {
|
|
440
463
|
let tmp = rgb2hsl(v);
|
|
@@ -449,110 +472,174 @@ function clone(v, proto) {
|
|
|
449
472
|
return v ? Object.assign(proto || {}, v) : v;
|
|
450
473
|
}
|
|
451
474
|
function fromObject(input) {
|
|
452
|
-
|
|
475
|
+
let v = { a: 255, b: 0, g: 0, r: 0 };
|
|
453
476
|
if (Array.isArray(input)) {
|
|
454
477
|
if (input.length >= 3) {
|
|
455
|
-
v = {
|
|
478
|
+
v = { a: 255, b: input[2], g: input[1], r: input[0] };
|
|
456
479
|
if (input.length > 3) {
|
|
457
480
|
v.a = n2b(input[3]);
|
|
458
481
|
}
|
|
459
482
|
}
|
|
460
483
|
} else {
|
|
461
|
-
v = clone(input, {
|
|
484
|
+
v = clone(input, { a: 1, b: 0, g: 0, r: 0 });
|
|
462
485
|
v.a = n2b(v.a);
|
|
463
486
|
}
|
|
464
487
|
return v;
|
|
465
488
|
}
|
|
466
489
|
function functionParse(str) {
|
|
467
|
-
|
|
468
|
-
|
|
490
|
+
const clean = str.replace(COMMENT_REGEXP, "").trim();
|
|
491
|
+
if (clean.charAt(0) === "r") {
|
|
492
|
+
return rgbParse(clean);
|
|
469
493
|
}
|
|
470
|
-
return hueParse(
|
|
494
|
+
return hueParse(clean);
|
|
471
495
|
}
|
|
472
|
-
|
|
496
|
+
var Color = class _Color {
|
|
497
|
+
/**
|
|
498
|
+
* constructor
|
|
499
|
+
* @param input
|
|
500
|
+
*/
|
|
473
501
|
constructor(input) {
|
|
474
|
-
if (input instanceof
|
|
502
|
+
if (input instanceof _Color) {
|
|
475
503
|
return input;
|
|
476
504
|
}
|
|
477
505
|
const type = typeof input;
|
|
478
506
|
let v;
|
|
479
|
-
if (type ===
|
|
507
|
+
if (type === "object") {
|
|
480
508
|
v = fromObject(input);
|
|
481
|
-
} else if (type ===
|
|
509
|
+
} else if (type === "string") {
|
|
482
510
|
v = hexParse(input) || nameParse(input) || functionParse(input);
|
|
483
511
|
}
|
|
484
512
|
this._rgb = v;
|
|
485
513
|
this._valid = !!v;
|
|
486
514
|
}
|
|
515
|
+
/**
|
|
516
|
+
* `true` if this is a valid color
|
|
517
|
+
* @returns {boolean}
|
|
518
|
+
*/
|
|
487
519
|
get valid() {
|
|
488
520
|
return this._valid;
|
|
489
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* @returns {RGBA} - the color
|
|
524
|
+
*/
|
|
490
525
|
get rgb() {
|
|
491
|
-
|
|
526
|
+
const v = clone(this._rgb);
|
|
492
527
|
if (v) {
|
|
493
528
|
v.a = b2n(v.a);
|
|
494
529
|
}
|
|
495
530
|
return v;
|
|
496
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* @param obj - the color
|
|
534
|
+
*/
|
|
497
535
|
set rgb(obj) {
|
|
498
536
|
this._rgb = fromObject(obj);
|
|
499
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* rgb(a) string
|
|
540
|
+
* @return {string|undefined}
|
|
541
|
+
*/
|
|
500
542
|
rgbString() {
|
|
501
|
-
return this._valid ? rgbString(this._rgb) :
|
|
543
|
+
return this._valid ? rgbString(this._rgb) : void 0;
|
|
502
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* hex string
|
|
547
|
+
* @return {string|undefined}
|
|
548
|
+
*/
|
|
503
549
|
hexString() {
|
|
504
|
-
return this._valid ? hexString(this._rgb) :
|
|
550
|
+
return this._valid ? hexString(this._rgb) : void 0;
|
|
505
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* hsl(a) string
|
|
554
|
+
* @return {string|undefined}
|
|
555
|
+
*/
|
|
506
556
|
hslString() {
|
|
507
|
-
return this._valid ? hslString(this._rgb) :
|
|
508
|
-
}
|
|
509
|
-
|
|
557
|
+
return this._valid ? hslString(this._rgb) : void 0;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Mix another color to this color.
|
|
561
|
+
* @param color - Color to mix in
|
|
562
|
+
* @param weight - 0..1
|
|
563
|
+
* @returns {Color}
|
|
564
|
+
*/
|
|
565
|
+
mix(color, weight = 0.5) {
|
|
510
566
|
if (color) {
|
|
511
567
|
const c1 = this.rgb;
|
|
512
568
|
const c2 = color.rgb;
|
|
513
|
-
|
|
514
|
-
const p = weight === w2 ? 0.5 : weight;
|
|
515
|
-
const w = 2 * p - 1;
|
|
569
|
+
const w = 2 * weight - 1;
|
|
516
570
|
const a = c1.a - c2.a;
|
|
517
|
-
const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2
|
|
518
|
-
w2 = 1 - w1;
|
|
519
|
-
c1.r =
|
|
520
|
-
c1.g =
|
|
521
|
-
c1.b =
|
|
522
|
-
c1.a =
|
|
571
|
+
const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
|
|
572
|
+
const w2 = 1 - w1;
|
|
573
|
+
c1.r = 255 & w1 * c1.r + w2 * c2.r + 0.5;
|
|
574
|
+
c1.g = 255 & w1 * c1.g + w2 * c2.g + 0.5;
|
|
575
|
+
c1.b = 255 & w1 * c1.b + w2 * c2.b + 0.5;
|
|
576
|
+
c1.a = weight * c1.a + (1 - weight) * c2.a;
|
|
523
577
|
this.rgb = c1;
|
|
524
578
|
}
|
|
525
579
|
return this;
|
|
526
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* Interpolate a color value between this and `color`
|
|
583
|
+
* @param color
|
|
584
|
+
* @param t - 0..1
|
|
585
|
+
* @returns {Color}
|
|
586
|
+
*/
|
|
527
587
|
interpolate(color, t) {
|
|
528
588
|
if (color) {
|
|
529
589
|
this._rgb = interpolate(this._rgb, color._rgb, t);
|
|
530
590
|
}
|
|
531
591
|
return this;
|
|
532
592
|
}
|
|
593
|
+
/**
|
|
594
|
+
* Clone
|
|
595
|
+
* @returns {Color}
|
|
596
|
+
*/
|
|
533
597
|
clone() {
|
|
534
|
-
return new
|
|
598
|
+
return new _Color(this.rgb);
|
|
535
599
|
}
|
|
600
|
+
/**
|
|
601
|
+
* Set alpha
|
|
602
|
+
* @param a - the alpha [0..1]
|
|
603
|
+
* @returns {Color}
|
|
604
|
+
*/
|
|
536
605
|
alpha(a) {
|
|
537
606
|
this._rgb.a = n2b(a);
|
|
538
607
|
return this;
|
|
539
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* Make clearer
|
|
611
|
+
* @param ratio - ratio [0..1]
|
|
612
|
+
* @returns {Color}
|
|
613
|
+
*/
|
|
540
614
|
clearer(ratio) {
|
|
541
615
|
const rgb = this._rgb;
|
|
542
616
|
rgb.a *= 1 - ratio;
|
|
543
617
|
return this;
|
|
544
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Convert to grayscale
|
|
621
|
+
* @returns {Color}
|
|
622
|
+
*/
|
|
545
623
|
greyscale() {
|
|
546
624
|
const rgb = this._rgb;
|
|
547
625
|
const val = round(rgb.r * 0.3 + rgb.g * 0.59 + rgb.b * 0.11);
|
|
548
626
|
rgb.r = rgb.g = rgb.b = val;
|
|
549
627
|
return this;
|
|
550
628
|
}
|
|
629
|
+
/**
|
|
630
|
+
* Opaquer
|
|
631
|
+
* @param ratio - ratio [0..1]
|
|
632
|
+
* @returns {Color}
|
|
633
|
+
*/
|
|
551
634
|
opaquer(ratio) {
|
|
552
635
|
const rgb = this._rgb;
|
|
553
636
|
rgb.a *= 1 + ratio;
|
|
554
637
|
return this;
|
|
555
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* Negates the rgb value
|
|
641
|
+
* @returns {Color}
|
|
642
|
+
*/
|
|
556
643
|
negate() {
|
|
557
644
|
const v = this._rgb;
|
|
558
645
|
v.r = 255 - v.r;
|
|
@@ -560,30 +647,79 @@ class Color {
|
|
|
560
647
|
v.b = 255 - v.b;
|
|
561
648
|
return this;
|
|
562
649
|
}
|
|
650
|
+
/**
|
|
651
|
+
* Lighten
|
|
652
|
+
* @param ratio - ratio [0..1]
|
|
653
|
+
* @returns {Color}
|
|
654
|
+
*/
|
|
563
655
|
lighten(ratio) {
|
|
564
656
|
modHSL(this._rgb, 2, ratio);
|
|
565
657
|
return this;
|
|
566
658
|
}
|
|
659
|
+
/**
|
|
660
|
+
* Darken
|
|
661
|
+
* @param ratio - ratio [0..1]
|
|
662
|
+
* @returns {Color}
|
|
663
|
+
*/
|
|
567
664
|
darken(ratio) {
|
|
568
665
|
modHSL(this._rgb, 2, -ratio);
|
|
569
666
|
return this;
|
|
570
667
|
}
|
|
668
|
+
/**
|
|
669
|
+
* Saturate
|
|
670
|
+
* @param ratio - ratio [0..1]
|
|
671
|
+
* @returns {Color}
|
|
672
|
+
*/
|
|
571
673
|
saturate(ratio) {
|
|
572
674
|
modHSL(this._rgb, 1, ratio);
|
|
573
675
|
return this;
|
|
574
676
|
}
|
|
677
|
+
/**
|
|
678
|
+
* Desaturate
|
|
679
|
+
* @param ratio - ratio [0..1]
|
|
680
|
+
* @returns {Color}
|
|
681
|
+
*/
|
|
575
682
|
desaturate(ratio) {
|
|
576
683
|
modHSL(this._rgb, 1, -ratio);
|
|
577
684
|
return this;
|
|
578
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Rotate
|
|
688
|
+
* @param deg - degrees to rotate
|
|
689
|
+
* @returns {Color}
|
|
690
|
+
*/
|
|
579
691
|
rotate(deg) {
|
|
580
692
|
rotate(this._rgb, deg);
|
|
581
693
|
return this;
|
|
582
694
|
}
|
|
583
|
-
}
|
|
695
|
+
};
|
|
584
696
|
|
|
585
|
-
|
|
697
|
+
// src/index.esm.ts
|
|
698
|
+
function index_esm_default(input) {
|
|
586
699
|
return new Color(input);
|
|
587
700
|
}
|
|
588
|
-
|
|
589
|
-
|
|
701
|
+
export {
|
|
702
|
+
Color,
|
|
703
|
+
b2n,
|
|
704
|
+
b2p,
|
|
705
|
+
index_esm_default as default,
|
|
706
|
+
hexParse,
|
|
707
|
+
hexString,
|
|
708
|
+
hsl2rgb,
|
|
709
|
+
hslString,
|
|
710
|
+
hsv2rgb,
|
|
711
|
+
hueParse,
|
|
712
|
+
hwb2rgb,
|
|
713
|
+
interpolate,
|
|
714
|
+
lim,
|
|
715
|
+
n2b,
|
|
716
|
+
n2p,
|
|
717
|
+
nameParse,
|
|
718
|
+
p2b,
|
|
719
|
+
rgb2hsl,
|
|
720
|
+
rgbParse,
|
|
721
|
+
rgbString,
|
|
722
|
+
rotate,
|
|
723
|
+
round
|
|
724
|
+
};
|
|
725
|
+
//# sourceMappingURL=color.esm.js.map
|