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