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