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