@kurkle/color 0.1.8 → 0.2.1

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,563 +1,589 @@
1
1
  /*!
2
- * @kurkle/color v0.1.8
2
+ * @kurkle/color v0.2.1
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
- var 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'
208
+ };
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'
237
358
  };
238
- function unpack(obj) {
239
- var unpacked = {};
240
- var keys = Object.keys(obj);
241
- var tkeys = Object.keys(map$1);
242
- var i, j, k, ok, nk;
243
- for (i = 0; i < keys.length; i++) {
244
- ok = nk = keys[i];
245
- for (j = 0; j < tkeys.length; j++) {
246
- k = tkeys[j];
247
- nk = nk.replace(k, map$1[k]);
248
- }
249
- k = parseInt(obj[ok], 16);
250
- unpacked[nk] = [k >> 16 & 0xFF, k >> 8 & 0xFF, k & 0xFF];
251
- }
252
- return unpacked;
253
- }
254
- const names = unpack({
255
- OiceXe: 'f0f8ff',
256
- antiquewEte: 'faebd7',
257
- aqua: 'ffff',
258
- aquamarRe: '7fffd4',
259
- azuY: 'f0ffff',
260
- beige: 'f5f5dc',
261
- bisque: 'ffe4c4',
262
- black: '0',
263
- blanKedOmond: 'ffebcd',
264
- Xe: 'ff',
265
- XeviTet: '8a2be2',
266
- bPwn: 'a52a2a',
267
- burlywood: 'deb887',
268
- caMtXe: '5f9ea0',
269
- KartYuse: '7fff00',
270
- KocTate: 'd2691e',
271
- cSO: 'ff7f50',
272
- cSnflowerXe: '6495ed',
273
- cSnsilk: 'fff8dc',
274
- crimson: 'dc143c',
275
- cyan: 'ffff',
276
- xXe: '8b',
277
- xcyan: '8b8b',
278
- xgTMnPd: 'b8860b',
279
- xWay: 'a9a9a9',
280
- xgYF: '6400',
281
- xgYy: 'a9a9a9',
282
- xkhaki: 'bdb76b',
283
- xmagFta: '8b008b',
284
- xTivegYF: '556b2f',
285
- xSange: 'ff8c00',
286
- xScEd: '9932cc',
287
- xYd: '8b0000',
288
- xsOmon: 'e9967a',
289
- xsHgYF: '8fbc8f',
290
- xUXe: '483d8b',
291
- xUWay: '2f4f4f',
292
- xUgYy: '2f4f4f',
293
- xQe: 'ced1',
294
- xviTet: '9400d3',
295
- dAppRk: 'ff1493',
296
- dApskyXe: 'bfff',
297
- dimWay: '696969',
298
- dimgYy: '696969',
299
- dodgerXe: '1e90ff',
300
- fiYbrick: 'b22222',
301
- flSOwEte: 'fffaf0',
302
- foYstWAn: '228b22',
303
- fuKsia: 'ff00ff',
304
- gaRsbSo: 'dcdcdc',
305
- ghostwEte: 'f8f8ff',
306
- gTd: 'ffd700',
307
- gTMnPd: 'daa520',
308
- Way: '808080',
309
- gYF: '8000',
310
- gYFLw: 'adff2f',
311
- gYy: '808080',
312
- honeyMw: 'f0fff0',
313
- hotpRk: 'ff69b4',
314
- RdianYd: 'cd5c5c',
315
- Rdigo: '4b0082',
316
- ivSy: 'fffff0',
317
- khaki: 'f0e68c',
318
- lavFMr: 'e6e6fa',
319
- lavFMrXsh: 'fff0f5',
320
- lawngYF: '7cfc00',
321
- NmoncEffon: 'fffacd',
322
- ZXe: 'add8e6',
323
- ZcSO: 'f08080',
324
- Zcyan: 'e0ffff',
325
- ZgTMnPdLw: 'fafad2',
326
- ZWay: 'd3d3d3',
327
- ZgYF: '90ee90',
328
- ZgYy: 'd3d3d3',
329
- ZpRk: 'ffb6c1',
330
- ZsOmon: 'ffa07a',
331
- ZsHgYF: '20b2aa',
332
- ZskyXe: '87cefa',
333
- ZUWay: '778899',
334
- ZUgYy: '778899',
335
- ZstAlXe: 'b0c4de',
336
- ZLw: 'ffffe0',
337
- lime: 'ff00',
338
- limegYF: '32cd32',
339
- lRF: 'faf0e6',
340
- magFta: 'ff00ff',
341
- maPon: '800000',
342
- VaquamarRe: '66cdaa',
343
- VXe: 'cd',
344
- VScEd: 'ba55d3',
345
- VpurpN: '9370db',
346
- VsHgYF: '3cb371',
347
- VUXe: '7b68ee',
348
- VsprRggYF: 'fa9a',
349
- VQe: '48d1cc',
350
- VviTetYd: 'c71585',
351
- midnightXe: '191970',
352
- mRtcYam: 'f5fffa',
353
- mistyPse: 'ffe4e1',
354
- moccasR: 'ffe4b5',
355
- navajowEte: 'ffdead',
356
- navy: '80',
357
- Tdlace: 'fdf5e6',
358
- Tive: '808000',
359
- TivedBb: '6b8e23',
360
- Sange: 'ffa500',
361
- SangeYd: 'ff4500',
362
- ScEd: 'da70d6',
363
- pOegTMnPd: 'eee8aa',
364
- pOegYF: '98fb98',
365
- pOeQe: 'afeeee',
366
- pOeviTetYd: 'db7093',
367
- papayawEp: 'ffefd5',
368
- pHKpuff: 'ffdab9',
369
- peru: 'cd853f',
370
- pRk: 'ffc0cb',
371
- plum: 'dda0dd',
372
- powMrXe: 'b0e0e6',
373
- purpN: '800080',
374
- YbeccapurpN: '663399',
375
- Yd: 'ff0000',
376
- Psybrown: 'bc8f8f',
377
- PyOXe: '4169e1',
378
- saddNbPwn: '8b4513',
379
- sOmon: 'fa8072',
380
- sandybPwn: 'f4a460',
381
- sHgYF: '2e8b57',
382
- sHshell: 'fff5ee',
383
- siFna: 'a0522d',
384
- silver: 'c0c0c0',
385
- skyXe: '87ceeb',
386
- UXe: '6a5acd',
387
- UWay: '708090',
388
- UgYy: '708090',
389
- snow: 'fffafa',
390
- sprRggYF: 'ff7f',
391
- stAlXe: '4682b4',
392
- tan: 'd2b48c',
393
- teO: '8080',
394
- tEstN: 'd8bfd8',
395
- tomato: 'ff6347',
396
- Qe: '40e0d0',
397
- viTet: 'ee82ee',
398
- JHt: 'f5deb3',
399
- wEte: 'ffffff',
400
- wEtesmoke: 'f5f5f5',
401
- Lw: 'ffff00',
402
- LwgYF: '9acd32'
403
- });
359
+ function unpack() {
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;
374
+ }
404
375
 
405
- names.transparent = [0, 0, 0, 0];
376
+ let names;
406
377
  function nameParse(str) {
407
- var a = names[str.toLowerCase()];
408
- return a && {
409
- r: a[0],
410
- g: a[1],
411
- b: a[2],
412
- a: a.length === 4 ? a[3] : 255
413
- };
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
+
424
+ const to = v => v <= 0.0031308 ? v * 12.92 : Math.pow(v, 1.0 / 2.4) * 1.055 - 0.055;
425
+ const from = v => v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
426
+ function interpolate(rgb1, rgb2, t) {
427
+ const r = from(b2n(rgb1.r));
428
+ const g = from(b2n(rgb1.g));
429
+ const b = from(b2n(rgb1.b));
430
+ return {
431
+ r: n2b(to(r + t * (from(b2n(rgb2.r)) - r))),
432
+ g: n2b(to(g + t * (from(b2n(rgb2.g)) - g))),
433
+ b: n2b(to(b + t * (from(b2n(rgb2.b)) - b))),
434
+ a: rgb1.a + t * (rgb2.a - rgb1.a)
435
+ };
414
436
  }
415
437
 
416
438
  function modHSL(v, i, ratio) {
417
- if (v) {
418
- let tmp = rgb2hsl(v);
419
- tmp[i] = Math.max(0, Math.min(tmp[i] + tmp[i] * ratio, i === 0 ? 360 : 1));
420
- tmp = hsl2rgb(tmp);
421
- v.r = tmp[0];
422
- v.g = tmp[1];
423
- v.b = tmp[2];
424
- }
439
+ if (v) {
440
+ let tmp = rgb2hsl(v);
441
+ tmp[i] = Math.max(0, Math.min(tmp[i] + tmp[i] * ratio, i === 0 ? 360 : 1));
442
+ tmp = hsl2rgb(tmp);
443
+ v.r = tmp[0];
444
+ v.g = tmp[1];
445
+ v.b = tmp[2];
446
+ }
425
447
  }
426
448
  function clone(v, proto) {
427
- return v ? Object.assign(proto || {}, v) : v;
449
+ return v ? Object.assign(proto || {}, v) : v;
428
450
  }
429
451
  function fromObject(input) {
430
- var v = {r: 0, g: 0, b: 0, a: 255};
431
- if (Array.isArray(input)) {
432
- if (input.length >= 3) {
433
- v = {r: input[0], g: input[1], b: input[2], a: 255};
434
- if (input.length > 3) {
435
- v.a = n2b(input[3]);
436
- }
437
- }
438
- } else {
439
- v = clone(input, {r: 0, g: 0, b: 0, a: 1});
440
- v.a = n2b(v.a);
441
- }
442
- return v;
452
+ var v = {r: 0, g: 0, b: 0, a: 255};
453
+ if (Array.isArray(input)) {
454
+ if (input.length >= 3) {
455
+ v = {r: input[0], g: input[1], b: input[2], a: 255};
456
+ if (input.length > 3) {
457
+ v.a = n2b(input[3]);
458
+ }
459
+ }
460
+ } else {
461
+ v = clone(input, {r: 0, g: 0, b: 0, a: 1});
462
+ v.a = n2b(v.a);
463
+ }
464
+ return v;
443
465
  }
444
466
  function functionParse(str) {
445
- if (str.charAt(0) === 'r') {
446
- return rgbParse(str);
447
- }
448
- return hueParse(str);
467
+ if (str.charAt(0) === 'r') {
468
+ return rgbParse(str);
469
+ }
470
+ return hueParse(str);
449
471
  }
450
472
  class Color {
451
- constructor(input) {
452
- if (input instanceof Color) {
453
- return input;
454
- }
455
- const type = typeof input;
456
- let v;
457
- if (type === 'object') {
458
- v = fromObject(input);
459
- } else if (type === 'string') {
460
- v = hexParse(input) || nameParse(input) || functionParse(input);
461
- }
462
- this._rgb = v;
463
- this._valid = !!v;
464
- }
465
- get valid() {
466
- return this._valid;
467
- }
468
- get rgb() {
469
- var v = clone(this._rgb);
470
- if (v) {
471
- v.a = b2n(v.a);
472
- }
473
- return v;
474
- }
475
- set rgb(obj) {
476
- this._rgb = fromObject(obj);
477
- }
478
- rgbString() {
479
- return this._valid ? rgbString(this._rgb) : this._rgb;
480
- }
481
- hexString() {
482
- return this._valid ? hexString(this._rgb) : this._rgb;
483
- }
484
- hslString() {
485
- return this._valid ? hslString(this._rgb) : this._rgb;
486
- }
487
- mix(color, weight) {
488
- const me = this;
489
- if (color) {
490
- const c1 = me.rgb;
491
- const c2 = color.rgb;
492
- let w2;
493
- const p = weight === w2 ? 0.5 : weight;
494
- const w = 2 * p - 1;
495
- const a = c1.a - c2.a;
496
- const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
497
- w2 = 1 - w1;
498
- c1.r = 0xFF & w1 * c1.r + w2 * c2.r + 0.5;
499
- c1.g = 0xFF & w1 * c1.g + w2 * c2.g + 0.5;
500
- c1.b = 0xFF & w1 * c1.b + w2 * c2.b + 0.5;
501
- c1.a = p * c1.a + (1 - p) * c2.a;
502
- me.rgb = c1;
503
- }
504
- return me;
505
- }
506
- clone() {
507
- return new Color(this.rgb);
508
- }
509
- alpha(a) {
510
- this._rgb.a = n2b(a);
511
- return this;
512
- }
513
- clearer(ratio) {
514
- const rgb = this._rgb;
515
- rgb.a *= 1 - ratio;
516
- return this;
517
- }
518
- greyscale() {
519
- const rgb = this._rgb;
520
- const val = round(rgb.r * 0.3 + rgb.g * 0.59 + rgb.b * 0.11);
521
- rgb.r = rgb.g = rgb.b = val;
522
- return this;
523
- }
524
- opaquer(ratio) {
525
- const rgb = this._rgb;
526
- rgb.a *= 1 + ratio;
527
- return this;
528
- }
529
- negate() {
530
- const v = this._rgb;
531
- v.r = 255 - v.r;
532
- v.g = 255 - v.g;
533
- v.b = 255 - v.b;
534
- return this;
535
- }
536
- lighten(ratio) {
537
- modHSL(this._rgb, 2, ratio);
538
- return this;
539
- }
540
- darken(ratio) {
541
- modHSL(this._rgb, 2, -ratio);
542
- return this;
543
- }
544
- saturate(ratio) {
545
- modHSL(this._rgb, 1, ratio);
546
- return this;
547
- }
548
- desaturate(ratio) {
549
- modHSL(this._rgb, 1, -ratio);
550
- return this;
551
- }
552
- rotate(deg) {
553
- rotate(this._rgb, deg);
554
- return this;
555
- }
473
+ constructor(input) {
474
+ if (input instanceof Color) {
475
+ return input;
476
+ }
477
+ const type = typeof input;
478
+ let v;
479
+ if (type === 'object') {
480
+ v = fromObject(input);
481
+ } else if (type === 'string') {
482
+ v = hexParse(input) || nameParse(input) || functionParse(input);
483
+ }
484
+ this._rgb = v;
485
+ this._valid = !!v;
486
+ }
487
+ get valid() {
488
+ return this._valid;
489
+ }
490
+ get rgb() {
491
+ var v = clone(this._rgb);
492
+ if (v) {
493
+ v.a = b2n(v.a);
494
+ }
495
+ return v;
496
+ }
497
+ set rgb(obj) {
498
+ this._rgb = fromObject(obj);
499
+ }
500
+ rgbString() {
501
+ return this._valid ? rgbString(this._rgb) : undefined;
502
+ }
503
+ hexString() {
504
+ return this._valid ? hexString(this._rgb) : undefined;
505
+ }
506
+ hslString() {
507
+ return this._valid ? hslString(this._rgb) : undefined;
508
+ }
509
+ mix(color, weight) {
510
+ if (color) {
511
+ const c1 = this.rgb;
512
+ const c2 = color.rgb;
513
+ let w2;
514
+ const p = weight === w2 ? 0.5 : weight;
515
+ const w = 2 * p - 1;
516
+ const a = c1.a - c2.a;
517
+ const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
518
+ w2 = 1 - w1;
519
+ c1.r = 0xFF & w1 * c1.r + w2 * c2.r + 0.5;
520
+ c1.g = 0xFF & w1 * c1.g + w2 * c2.g + 0.5;
521
+ c1.b = 0xFF & w1 * c1.b + w2 * c2.b + 0.5;
522
+ c1.a = p * c1.a + (1 - p) * c2.a;
523
+ this.rgb = c1;
524
+ }
525
+ return this;
526
+ }
527
+ interpolate(color, t) {
528
+ if (color) {
529
+ this._rgb = interpolate(this._rgb, color._rgb, t);
530
+ }
531
+ return this;
532
+ }
533
+ clone() {
534
+ return new Color(this.rgb);
535
+ }
536
+ alpha(a) {
537
+ this._rgb.a = n2b(a);
538
+ return this;
539
+ }
540
+ clearer(ratio) {
541
+ const rgb = this._rgb;
542
+ rgb.a *= 1 - ratio;
543
+ return this;
544
+ }
545
+ greyscale() {
546
+ const rgb = this._rgb;
547
+ const val = round(rgb.r * 0.3 + rgb.g * 0.59 + rgb.b * 0.11);
548
+ rgb.r = rgb.g = rgb.b = val;
549
+ return this;
550
+ }
551
+ opaquer(ratio) {
552
+ const rgb = this._rgb;
553
+ rgb.a *= 1 + ratio;
554
+ return this;
555
+ }
556
+ negate() {
557
+ const v = this._rgb;
558
+ v.r = 255 - v.r;
559
+ v.g = 255 - v.g;
560
+ v.b = 255 - v.b;
561
+ return this;
562
+ }
563
+ lighten(ratio) {
564
+ modHSL(this._rgb, 2, ratio);
565
+ return this;
566
+ }
567
+ darken(ratio) {
568
+ modHSL(this._rgb, 2, -ratio);
569
+ return this;
570
+ }
571
+ saturate(ratio) {
572
+ modHSL(this._rgb, 1, ratio);
573
+ return this;
574
+ }
575
+ desaturate(ratio) {
576
+ modHSL(this._rgb, 1, -ratio);
577
+ return this;
578
+ }
579
+ rotate(deg) {
580
+ rotate(this._rgb, deg);
581
+ return this;
582
+ }
556
583
  }
557
584
 
558
585
  function index_esm(input) {
559
- return new Color(input);
586
+ return new Color(input);
560
587
  }
561
588
 
562
- export default index_esm;
563
- export { Color, b2n, b2p, hexParse, hexString, hsl2rgb, hslString, hsv2rgb, hueParse, hwb2rgb, n2b, n2p, nameParse, p2b, rgb2hsl, rgbParse, rgbString, rotate, round };
589
+ export { Color, b2n, b2p, index_esm as default, hexParse, hexString, hsl2rgb, hslString, hsv2rgb, hueParse, hwb2rgb, lim, n2b, n2p, nameParse, p2b, rgb2hsl, rgbParse, rgbString, rotate, round };