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