@ppg_pl/tinting 0.0.0 → 0.0.2

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.
Files changed (48) hide show
  1. package/README.md +0 -8
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/{modal-header_10.cjs.entry.js → modal-header_9.cjs.entry.js} +25 -34
  4. package/dist/cjs/modal-header_9.cjs.entry.js.map +1 -0
  5. package/dist/cjs/tinting.cjs.js +1 -1
  6. package/dist/collection/collection-manifest.json +0 -1
  7. package/dist/collection/components/modal/index.js +15 -11
  8. package/dist/collection/components/modal/index.js.map +1 -1
  9. package/dist/collection/components/select/index.css +5 -0
  10. package/dist/components/index10.js +3925 -9
  11. package/dist/components/index10.js.map +1 -1
  12. package/dist/components/index4.js +1 -1
  13. package/dist/components/index4.js.map +1 -1
  14. package/dist/components/my-component.js +9 -15
  15. package/dist/components/my-component.js.map +1 -1
  16. package/dist/components/my-modal.js +1 -1
  17. package/dist/esm/loader.js +1 -1
  18. package/dist/esm/{modal-header_10.entry.js → modal-header_9.entry.js} +26 -34
  19. package/dist/esm/modal-header_9.entry.js.map +1 -0
  20. package/dist/esm/tinting.js +1 -1
  21. package/dist/tinting/p-cd431d43.entry.js +15 -0
  22. package/dist/tinting/p-cd431d43.entry.js.map +1 -0
  23. package/dist/tinting/tinting.esm.js +1 -1
  24. package/dist/tinting/tinting.esm.js.map +1 -1
  25. package/dist/types/components.d.ts +0 -13
  26. package/package.json +1 -1
  27. package/www/build/p-cd431d43.entry.js +15 -0
  28. package/www/build/p-cd431d43.entry.js.map +1 -0
  29. package/www/build/tinting.esm.js +1 -1
  30. package/www/build/tinting.esm.js.map +1 -1
  31. package/www/index.html +1 -1
  32. package/dist/cjs/modal-header_10.cjs.entry.js.map +0 -1
  33. package/dist/collection/components/loader/index.css +0 -85
  34. package/dist/collection/components/loader/index.js +0 -19
  35. package/dist/collection/components/loader/index.js.map +0 -1
  36. package/dist/components/index11.js +0 -3949
  37. package/dist/components/index11.js.map +0 -1
  38. package/dist/components/my-loader.d.ts +0 -11
  39. package/dist/components/my-loader.js +0 -8
  40. package/dist/components/my-loader.js.map +0 -1
  41. package/dist/esm/modal-header_10.entry.js.map +0 -1
  42. package/dist/tinting/p-06cd865b.entry.js +0 -15
  43. package/dist/tinting/p-06cd865b.entry.js.map +0 -1
  44. package/dist/types/components/loader/index.d.ts +0 -3
  45. package/www/build/p-06cd865b.entry.js +0 -15
  46. package/www/build/p-06cd865b.entry.js.map +0 -1
  47. package/www/build/p-a4907f5e.css +0 -4
  48. package/www/build/p-e2322b6c.js +0 -163
@@ -1,31 +1,3947 @@
1
- import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
1
+ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
+ import { a as APIURL, b as accessToken } from './index5.js';
3
+ import { s as setDataLayer } from './gtmUtils.js';
4
+ import { u as updateFilters, f as fetchColors, l as limit$1, a as fetchProductData, d as defineCustomElement$6 } from './index2.js';
5
+ import { a as debounce, d as defineCustomElement$2 } from './index4.js';
6
+ import { d as defineCustomElement$5 } from './index7.js';
7
+ import { d as defineCustomElement$4 } from './index8.js';
8
+ import { d as defineCustomElement$3 } from './index3.js';
9
+ import { d as defineCustomElement$1 } from './index9.js';
2
10
 
3
- const indexCss = ".container.sc-my-loader{display:flex;justify-content:center;align-items:center;height:190px;overflow:hidden}.item.sc-my-loader{width:20px;height:20px;margin:3px;list-style-type:none;transition:0.5s all ease}.item.sc-my-loader:nth-child(1){animation:right-1 1s infinite alternate;background-color:#b8cf40;animation-delay:20ms}@keyframes right-1{0%{transform:translateY(-18px)}100%{transform:translateY(18px)}}.item.sc-my-loader:nth-child(2){animation:right-2 1s infinite alternate;background-color:#ee4b5e;animation-delay:40ms}@keyframes right-2{0%{transform:translateY(-21px)}100%{transform:translateY(21px)}}.item.sc-my-loader:nth-child(3){animation:right-3 1s infinite alternate;background-color:#ea0f47;animation-delay:60ms}@keyframes right-3{0%{transform:translateY(-24px)}100%{transform:translateY(24px)}}.item.sc-my-loader:nth-child(4){animation:right-4 1s infinite alternate;background-color:#d42840;animation-delay:80ms}@keyframes right-4{0%{transform:translateY(-27px)}100%{transform:translateY(27px)}}.item.sc-my-loader:nth-child(5){animation:right-5 1s infinite alternate;background-color:#8b2850;animation-delay:100ms}@keyframes right-5{0%{transform:translateY(-30px)}100%{transform:translateY(30px)}}";
11
+ const { min: min$4, max: max$4 } = Math;
4
12
 
5
- const MyLoader = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
13
+ const limit = (x, low = 0, high = 1) => {
14
+ return min$4(max$4(low, x), high);
15
+ };
16
+
17
+ const clip_rgb = (rgb) => {
18
+ rgb._clipped = false;
19
+ rgb._unclipped = rgb.slice(0);
20
+ for (let i = 0; i <= 3; i++) {
21
+ if (i < 3) {
22
+ if (rgb[i] < 0 || rgb[i] > 255) rgb._clipped = true;
23
+ rgb[i] = limit(rgb[i], 0, 255);
24
+ } else if (i === 3) {
25
+ rgb[i] = limit(rgb[i], 0, 1);
26
+ }
27
+ }
28
+ return rgb;
29
+ };
30
+
31
+ // ported from jQuery's $.type
32
+ const classToType = {};
33
+ for (let name of [
34
+ 'Boolean',
35
+ 'Number',
36
+ 'String',
37
+ 'Function',
38
+ 'Array',
39
+ 'Date',
40
+ 'RegExp',
41
+ 'Undefined',
42
+ 'Null'
43
+ ]) {
44
+ classToType[`[object ${name}]`] = name.toLowerCase();
45
+ }
46
+ function type (obj) {
47
+ return classToType[Object.prototype.toString.call(obj)] || 'object';
48
+ }
49
+
50
+ const unpack = (args, keyOrder = null) => {
51
+ // if called with more than 3 arguments, we return the arguments
52
+ if (args.length >= 3) return Array.prototype.slice.call(args);
53
+ // with less than 3 args we check if first arg is object
54
+ // and use the keyOrder string to extract and sort properties
55
+ if (type(args[0]) == 'object' && keyOrder) {
56
+ return keyOrder
57
+ .split('')
58
+ .filter((k) => args[0][k] !== undefined)
59
+ .map((k) => args[0][k]);
60
+ }
61
+ // otherwise we just return the first argument
62
+ // (which we suppose is an array of args)
63
+ return args[0].slice(0);
64
+ };
65
+
66
+ const last = (args) => {
67
+ if (args.length < 2) return null;
68
+ const l = args.length - 1;
69
+ if (type(args[l]) == 'string') return args[l].toLowerCase();
70
+ return null;
71
+ };
72
+
73
+ const { PI: PI$2, min: min$3, max: max$3 } = Math;
74
+
75
+ const rnd2 = (a) => Math.round(a * 100) / 100;
76
+ const rnd3 = (a) => Math.round(a * 100) / 100;
77
+
78
+ const TWOPI = PI$2 * 2;
79
+ const PITHIRD = PI$2 / 3;
80
+ const DEG2RAD = PI$2 / 180;
81
+ const RAD2DEG = 180 / PI$2;
82
+
83
+ /**
84
+ * Reverse the first three elements of an array
85
+ *
86
+ * @param {any[]} arr
87
+ * @returns {any[]}
88
+ */
89
+ function reverse3(arr) {
90
+ return [...arr.slice(0, 3).reverse(), ...arr.slice(3)];
91
+ }
92
+
93
+ const input = {
94
+ format: {},
95
+ autodetect: []
96
+ };
97
+
98
+ class Color {
99
+ constructor(...args) {
100
+ const me = this;
101
+ if (
102
+ type(args[0]) === 'object' &&
103
+ args[0].constructor &&
104
+ args[0].constructor === this.constructor
105
+ ) {
106
+ // the argument is already a Color instance
107
+ return args[0];
108
+ }
109
+ // last argument could be the mode
110
+ let mode = last(args);
111
+ let autodetect = false;
112
+ if (!mode) {
113
+ autodetect = true;
114
+
115
+ if (!input.sorted) {
116
+ input.autodetect = input.autodetect.sort((a, b) => b.p - a.p);
117
+ input.sorted = true;
118
+ }
119
+
120
+ // auto-detect format
121
+ for (let chk of input.autodetect) {
122
+ mode = chk.test(...args);
123
+ if (mode) break;
124
+ }
125
+ }
126
+ if (input.format[mode]) {
127
+ const rgb = input.format[mode].apply(
128
+ null,
129
+ autodetect ? args : args.slice(0, -1)
130
+ );
131
+ me._rgb = clip_rgb(rgb);
132
+ } else {
133
+ throw new Error('unknown format: ' + args);
134
+ }
135
+ // add alpha channel
136
+ if (me._rgb.length === 3) me._rgb.push(1);
137
+ }
138
+ toString() {
139
+ if (type(this.hex) == 'function') return this.hex();
140
+ return `[${this._rgb.join(',')}]`;
141
+ }
142
+ }
143
+
144
+ // this gets updated automatically
145
+ const version = '3.1.2';
146
+
147
+ const chroma = (...args) => {
148
+ return new Color(...args);
149
+ };
150
+
151
+ chroma.version = version;
152
+
153
+ /**
154
+ X11 color names
155
+
156
+ http://www.w3.org/TR/css3-color/#svg-color
157
+ */
158
+
159
+ const w3cx11 = {
160
+ aliceblue: '#f0f8ff',
161
+ antiquewhite: '#faebd7',
162
+ aqua: '#00ffff',
163
+ aquamarine: '#7fffd4',
164
+ azure: '#f0ffff',
165
+ beige: '#f5f5dc',
166
+ bisque: '#ffe4c4',
167
+ black: '#000000',
168
+ blanchedalmond: '#ffebcd',
169
+ blue: '#0000ff',
170
+ blueviolet: '#8a2be2',
171
+ brown: '#a52a2a',
172
+ burlywood: '#deb887',
173
+ cadetblue: '#5f9ea0',
174
+ chartreuse: '#7fff00',
175
+ chocolate: '#d2691e',
176
+ coral: '#ff7f50',
177
+ cornflowerblue: '#6495ed',
178
+ cornsilk: '#fff8dc',
179
+ crimson: '#dc143c',
180
+ cyan: '#00ffff',
181
+ darkblue: '#00008b',
182
+ darkcyan: '#008b8b',
183
+ darkgoldenrod: '#b8860b',
184
+ darkgray: '#a9a9a9',
185
+ darkgreen: '#006400',
186
+ darkgrey: '#a9a9a9',
187
+ darkkhaki: '#bdb76b',
188
+ darkmagenta: '#8b008b',
189
+ darkolivegreen: '#556b2f',
190
+ darkorange: '#ff8c00',
191
+ darkorchid: '#9932cc',
192
+ darkred: '#8b0000',
193
+ darksalmon: '#e9967a',
194
+ darkseagreen: '#8fbc8f',
195
+ darkslateblue: '#483d8b',
196
+ darkslategray: '#2f4f4f',
197
+ darkslategrey: '#2f4f4f',
198
+ darkturquoise: '#00ced1',
199
+ darkviolet: '#9400d3',
200
+ deeppink: '#ff1493',
201
+ deepskyblue: '#00bfff',
202
+ dimgray: '#696969',
203
+ dimgrey: '#696969',
204
+ dodgerblue: '#1e90ff',
205
+ firebrick: '#b22222',
206
+ floralwhite: '#fffaf0',
207
+ forestgreen: '#228b22',
208
+ fuchsia: '#ff00ff',
209
+ gainsboro: '#dcdcdc',
210
+ ghostwhite: '#f8f8ff',
211
+ gold: '#ffd700',
212
+ goldenrod: '#daa520',
213
+ gray: '#808080',
214
+ green: '#008000',
215
+ greenyellow: '#adff2f',
216
+ grey: '#808080',
217
+ honeydew: '#f0fff0',
218
+ hotpink: '#ff69b4',
219
+ indianred: '#cd5c5c',
220
+ indigo: '#4b0082',
221
+ ivory: '#fffff0',
222
+ khaki: '#f0e68c',
223
+ laserlemon: '#ffff54',
224
+ lavender: '#e6e6fa',
225
+ lavenderblush: '#fff0f5',
226
+ lawngreen: '#7cfc00',
227
+ lemonchiffon: '#fffacd',
228
+ lightblue: '#add8e6',
229
+ lightcoral: '#f08080',
230
+ lightcyan: '#e0ffff',
231
+ lightgoldenrod: '#fafad2',
232
+ lightgoldenrodyellow: '#fafad2',
233
+ lightgray: '#d3d3d3',
234
+ lightgreen: '#90ee90',
235
+ lightgrey: '#d3d3d3',
236
+ lightpink: '#ffb6c1',
237
+ lightsalmon: '#ffa07a',
238
+ lightseagreen: '#20b2aa',
239
+ lightskyblue: '#87cefa',
240
+ lightslategray: '#778899',
241
+ lightslategrey: '#778899',
242
+ lightsteelblue: '#b0c4de',
243
+ lightyellow: '#ffffe0',
244
+ lime: '#00ff00',
245
+ limegreen: '#32cd32',
246
+ linen: '#faf0e6',
247
+ magenta: '#ff00ff',
248
+ maroon: '#800000',
249
+ maroon2: '#7f0000',
250
+ maroon3: '#b03060',
251
+ mediumaquamarine: '#66cdaa',
252
+ mediumblue: '#0000cd',
253
+ mediumorchid: '#ba55d3',
254
+ mediumpurple: '#9370db',
255
+ mediumseagreen: '#3cb371',
256
+ mediumslateblue: '#7b68ee',
257
+ mediumspringgreen: '#00fa9a',
258
+ mediumturquoise: '#48d1cc',
259
+ mediumvioletred: '#c71585',
260
+ midnightblue: '#191970',
261
+ mintcream: '#f5fffa',
262
+ mistyrose: '#ffe4e1',
263
+ moccasin: '#ffe4b5',
264
+ navajowhite: '#ffdead',
265
+ navy: '#000080',
266
+ oldlace: '#fdf5e6',
267
+ olive: '#808000',
268
+ olivedrab: '#6b8e23',
269
+ orange: '#ffa500',
270
+ orangered: '#ff4500',
271
+ orchid: '#da70d6',
272
+ palegoldenrod: '#eee8aa',
273
+ palegreen: '#98fb98',
274
+ paleturquoise: '#afeeee',
275
+ palevioletred: '#db7093',
276
+ papayawhip: '#ffefd5',
277
+ peachpuff: '#ffdab9',
278
+ peru: '#cd853f',
279
+ pink: '#ffc0cb',
280
+ plum: '#dda0dd',
281
+ powderblue: '#b0e0e6',
282
+ purple: '#800080',
283
+ purple2: '#7f007f',
284
+ purple3: '#a020f0',
285
+ rebeccapurple: '#663399',
286
+ red: '#ff0000',
287
+ rosybrown: '#bc8f8f',
288
+ royalblue: '#4169e1',
289
+ saddlebrown: '#8b4513',
290
+ salmon: '#fa8072',
291
+ sandybrown: '#f4a460',
292
+ seagreen: '#2e8b57',
293
+ seashell: '#fff5ee',
294
+ sienna: '#a0522d',
295
+ silver: '#c0c0c0',
296
+ skyblue: '#87ceeb',
297
+ slateblue: '#6a5acd',
298
+ slategray: '#708090',
299
+ slategrey: '#708090',
300
+ snow: '#fffafa',
301
+ springgreen: '#00ff7f',
302
+ steelblue: '#4682b4',
303
+ tan: '#d2b48c',
304
+ teal: '#008080',
305
+ thistle: '#d8bfd8',
306
+ tomato: '#ff6347',
307
+ turquoise: '#40e0d0',
308
+ violet: '#ee82ee',
309
+ wheat: '#f5deb3',
310
+ white: '#ffffff',
311
+ whitesmoke: '#f5f5f5',
312
+ yellow: '#ffff00',
313
+ yellowgreen: '#9acd32'
314
+ };
315
+
316
+ const RE_HEX = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
317
+ const RE_HEXA = /^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/;
318
+
319
+ const hex2rgb = (hex) => {
320
+ if (hex.match(RE_HEX)) {
321
+ // remove optional leading #
322
+ if (hex.length === 4 || hex.length === 7) {
323
+ hex = hex.substr(1);
324
+ }
325
+ // expand short-notation to full six-digit
326
+ if (hex.length === 3) {
327
+ hex = hex.split('');
328
+ hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
329
+ }
330
+ const u = parseInt(hex, 16);
331
+ const r = u >> 16;
332
+ const g = (u >> 8) & 0xff;
333
+ const b = u & 0xff;
334
+ return [r, g, b, 1];
335
+ }
336
+
337
+ // match rgba hex format, eg #FF000077
338
+ if (hex.match(RE_HEXA)) {
339
+ if (hex.length === 5 || hex.length === 9) {
340
+ // remove optional leading #
341
+ hex = hex.substr(1);
342
+ }
343
+ // expand short-notation to full eight-digit
344
+ if (hex.length === 4) {
345
+ hex = hex.split('');
346
+ hex =
347
+ hex[0] +
348
+ hex[0] +
349
+ hex[1] +
350
+ hex[1] +
351
+ hex[2] +
352
+ hex[2] +
353
+ hex[3] +
354
+ hex[3];
355
+ }
356
+ const u = parseInt(hex, 16);
357
+ const r = (u >> 24) & 0xff;
358
+ const g = (u >> 16) & 0xff;
359
+ const b = (u >> 8) & 0xff;
360
+ const a = Math.round(((u & 0xff) / 0xff) * 100) / 100;
361
+ return [r, g, b, a];
362
+ }
363
+
364
+ // we used to check for css colors here
365
+ // if _input.css? and rgb = _input.css hex
366
+ // return rgb
367
+
368
+ throw new Error(`unknown hex color: ${hex}`);
369
+ };
370
+
371
+ const { round: round$5 } = Math;
372
+
373
+ const rgb2hex = (...args) => {
374
+ let [r, g, b, a] = unpack(args, 'rgba');
375
+ let mode = last(args) || 'auto';
376
+ if (a === undefined) a = 1;
377
+ if (mode === 'auto') {
378
+ mode = a < 1 ? 'rgba' : 'rgb';
379
+ }
380
+ r = round$5(r);
381
+ g = round$5(g);
382
+ b = round$5(b);
383
+ const u = (r << 16) | (g << 8) | b;
384
+ let str = '000000' + u.toString(16); //#.toUpperCase();
385
+ str = str.substr(str.length - 6);
386
+ let hxa = '0' + round$5(a * 255).toString(16);
387
+ hxa = hxa.substr(hxa.length - 2);
388
+ switch (mode.toLowerCase()) {
389
+ case 'rgba':
390
+ return `#${str}${hxa}`;
391
+ case 'argb':
392
+ return `#${hxa}${str}`;
393
+ default:
394
+ return `#${str}`;
395
+ }
396
+ };
397
+
398
+ Color.prototype.name = function () {
399
+ const hex = rgb2hex(this._rgb, 'rgb');
400
+ for (let n of Object.keys(w3cx11)) {
401
+ if (w3cx11[n] === hex) return n.toLowerCase();
402
+ }
403
+ return hex;
404
+ };
405
+
406
+ input.format.named = (name) => {
407
+ name = name.toLowerCase();
408
+ if (w3cx11[name]) return hex2rgb(w3cx11[name]);
409
+ throw new Error('unknown color name: ' + name);
410
+ };
411
+
412
+ input.autodetect.push({
413
+ p: 5,
414
+ test: (h, ...rest) => {
415
+ if (!rest.length && type(h) === 'string' && w3cx11[h.toLowerCase()]) {
416
+ return 'named';
417
+ }
418
+ }
419
+ });
420
+
421
+ Color.prototype.alpha = function (a, mutate = false) {
422
+ if (a !== undefined && type(a) === 'number') {
423
+ if (mutate) {
424
+ this._rgb[3] = a;
425
+ return this;
426
+ }
427
+ return new Color([this._rgb[0], this._rgb[1], this._rgb[2], a], 'rgb');
428
+ }
429
+ return this._rgb[3];
430
+ };
431
+
432
+ Color.prototype.clipped = function () {
433
+ return this._rgb._clipped || false;
434
+ };
435
+
436
+ const labConstants = {
437
+ // Corresponds roughly to RGB brighter/darker
438
+ Kn: 18,
439
+
440
+ // D65 standard referent
441
+ labWhitePoint: 'd65',
442
+ Xn: 0.95047,
443
+ Yn: 1,
444
+ Zn: 1.08883,
445
+
446
+ t0: 0.137931034, // 4 / 29
447
+ t1: 0.206896552, // 6 / 29
448
+ t2: 0.12841855, // 3 * t1 * t1
449
+ t3: 0.008856452, // t1 * t1 * t1,
450
+
451
+ kE: 216.0 / 24389.0,
452
+ kKE: 8.0,
453
+ kK: 24389.0 / 27.0,
454
+
455
+ RefWhiteRGB: {
456
+ // sRGB
457
+ X: 0.95047,
458
+ Y: 1,
459
+ Z: 1.08883
460
+ },
461
+
462
+ MtxRGB2XYZ: {
463
+ m00: 0.4124564390896922,
464
+ m01: 0.21267285140562253,
465
+ m02: 0.0193338955823293,
466
+ m10: 0.357576077643909,
467
+ m11: 0.715152155287818,
468
+ m12: 0.11919202588130297,
469
+ m20: 0.18043748326639894,
470
+ m21: 0.07217499330655958,
471
+ m22: 0.9503040785363679
472
+ },
473
+
474
+ MtxXYZ2RGB: {
475
+ m00: 3.2404541621141045,
476
+ m01: -0.9692660305051868,
477
+ m02: 0.055643430959114726,
478
+ m10: -1.5371385127977166,
479
+ m11: 1.8760108454466942,
480
+ m12: -0.2040259135167538,
481
+ m20: -0.498531409556016,
482
+ m21: 0.041556017530349834,
483
+ m22: 1.0572251882231791
484
+ },
485
+
486
+ // used in rgb2xyz
487
+ As: 0.9414285350000001,
488
+ Bs: 1.040417467,
489
+ Cs: 1.089532651,
490
+
491
+ MtxAdaptMa: {
492
+ m00: 0.8951,
493
+ m01: -0.7502,
494
+ m02: 0.0389,
495
+ m10: 0.2664,
496
+ m11: 1.7135,
497
+ m12: -0.0685,
498
+ m20: -0.1614,
499
+ m21: 0.0367,
500
+ m22: 1.0296
501
+ },
502
+
503
+ MtxAdaptMaI: {
504
+ m00: 0.9869929054667123,
505
+ m01: 0.43230526972339456,
506
+ m02: -0.008528664575177328,
507
+ m10: -0.14705425642099013,
508
+ m11: 0.5183602715367776,
509
+ m12: 0.04004282165408487,
510
+ m20: 0.15996265166373125,
511
+ m21: 0.0492912282128556,
512
+ m22: 0.9684866957875502
513
+ }
514
+ };
515
+
516
+ // taken from https://de.mathworks.com/help/images/ref/whitepoint.html
517
+ const ILLUMINANTS = new Map([
518
+ // ASTM E308-01
519
+ ['a', [1.0985, 0.35585]],
520
+ // Wyszecki & Stiles, p. 769
521
+ ['b', [1.0985, 0.35585]],
522
+ // C ASTM E308-01
523
+ ['c', [0.98074, 1.18232]],
524
+ // D50 (ASTM E308-01)
525
+ ['d50', [0.96422, 0.82521]],
526
+ // D55 (ASTM E308-01)
527
+ ['d55', [0.95682, 0.92149]],
528
+ // D65 (ASTM E308-01)
529
+ ['d65', [0.95047, 1.08883]],
530
+ // E (ASTM E308-01)
531
+ ['e', [1, 1, 1]],
532
+ // F2 (ASTM E308-01)
533
+ ['f2', [0.99186, 0.67393]],
534
+ // F7 (ASTM E308-01)
535
+ ['f7', [0.95041, 1.08747]],
536
+ // F11 (ASTM E308-01)
537
+ ['f11', [1.00962, 0.6435]],
538
+ ['icc', [0.96422, 0.82521]]
539
+ ]);
540
+
541
+ function setLabWhitePoint(name) {
542
+ const ill = ILLUMINANTS.get(String(name).toLowerCase());
543
+ if (!ill) {
544
+ throw new Error('unknown Lab illuminant ' + name);
545
+ }
546
+ labConstants.labWhitePoint = name;
547
+ labConstants.Xn = ill[0];
548
+ labConstants.Zn = ill[1];
549
+ }
550
+
551
+ function getLabWhitePoint() {
552
+ return labConstants.labWhitePoint;
553
+ }
554
+
555
+ /*
556
+ * L* [0..100]
557
+ * a [-100..100]
558
+ * b [-100..100]
559
+ */
560
+ const lab2rgb = (...args) => {
561
+ args = unpack(args, 'lab');
562
+ const [L, a, b] = args;
563
+ const [x, y, z] = lab2xyz(L, a, b);
564
+ const [r, g, b_] = xyz2rgb(x, y, z);
565
+ return [r, g, b_, args.length > 3 ? args[3] : 1];
566
+ };
567
+
568
+ const lab2xyz = (L, a, b) => {
569
+ const { kE, kK, kKE, Xn, Yn, Zn } = labConstants;
570
+
571
+ const fy = (L + 16.0) / 116.0;
572
+ const fx = 0.002 * a + fy;
573
+ const fz = fy - 0.005 * b;
574
+
575
+ const fx3 = fx * fx * fx;
576
+ const fz3 = fz * fz * fz;
577
+
578
+ const xr = fx3 > kE ? fx3 : (116.0 * fx - 16.0) / kK;
579
+ const yr = L > kKE ? Math.pow((L + 16.0) / 116.0, 3.0) : L / kK;
580
+ const zr = fz3 > kE ? fz3 : (116.0 * fz - 16.0) / kK;
581
+
582
+ const x = xr * Xn;
583
+ const y = yr * Yn;
584
+ const z = zr * Zn;
585
+
586
+ return [x, y, z];
587
+ };
588
+
589
+ const compand = (linear) => {
590
+ /* sRGB */
591
+ const sign = Math.sign(linear);
592
+ linear = Math.abs(linear);
593
+ return (
594
+ (linear <= 0.0031308
595
+ ? linear * 12.92
596
+ : 1.055 * Math.pow(linear, 1.0 / 2.4) - 0.055) * sign
597
+ );
598
+ };
599
+
600
+ const xyz2rgb = (x, y, z) => {
601
+ const { MtxAdaptMa, MtxAdaptMaI, MtxXYZ2RGB, RefWhiteRGB, Xn, Yn, Zn } =
602
+ labConstants;
603
+
604
+ const As = Xn * MtxAdaptMa.m00 + Yn * MtxAdaptMa.m10 + Zn * MtxAdaptMa.m20;
605
+ const Bs = Xn * MtxAdaptMa.m01 + Yn * MtxAdaptMa.m11 + Zn * MtxAdaptMa.m21;
606
+ const Cs = Xn * MtxAdaptMa.m02 + Yn * MtxAdaptMa.m12 + Zn * MtxAdaptMa.m22;
607
+
608
+ const Ad =
609
+ RefWhiteRGB.X * MtxAdaptMa.m00 +
610
+ RefWhiteRGB.Y * MtxAdaptMa.m10 +
611
+ RefWhiteRGB.Z * MtxAdaptMa.m20;
612
+ const Bd =
613
+ RefWhiteRGB.X * MtxAdaptMa.m01 +
614
+ RefWhiteRGB.Y * MtxAdaptMa.m11 +
615
+ RefWhiteRGB.Z * MtxAdaptMa.m21;
616
+ const Cd =
617
+ RefWhiteRGB.X * MtxAdaptMa.m02 +
618
+ RefWhiteRGB.Y * MtxAdaptMa.m12 +
619
+ RefWhiteRGB.Z * MtxAdaptMa.m22;
620
+
621
+ const X1 =
622
+ (x * MtxAdaptMa.m00 + y * MtxAdaptMa.m10 + z * MtxAdaptMa.m20) *
623
+ (Ad / As);
624
+ const Y1 =
625
+ (x * MtxAdaptMa.m01 + y * MtxAdaptMa.m11 + z * MtxAdaptMa.m21) *
626
+ (Bd / Bs);
627
+ const Z1 =
628
+ (x * MtxAdaptMa.m02 + y * MtxAdaptMa.m12 + z * MtxAdaptMa.m22) *
629
+ (Cd / Cs);
630
+
631
+ const X2 =
632
+ X1 * MtxAdaptMaI.m00 + Y1 * MtxAdaptMaI.m10 + Z1 * MtxAdaptMaI.m20;
633
+ const Y2 =
634
+ X1 * MtxAdaptMaI.m01 + Y1 * MtxAdaptMaI.m11 + Z1 * MtxAdaptMaI.m21;
635
+ const Z2 =
636
+ X1 * MtxAdaptMaI.m02 + Y1 * MtxAdaptMaI.m12 + Z1 * MtxAdaptMaI.m22;
637
+
638
+ const r = compand(
639
+ X2 * MtxXYZ2RGB.m00 + Y2 * MtxXYZ2RGB.m10 + Z2 * MtxXYZ2RGB.m20
640
+ );
641
+ const g = compand(
642
+ X2 * MtxXYZ2RGB.m01 + Y2 * MtxXYZ2RGB.m11 + Z2 * MtxXYZ2RGB.m21
643
+ );
644
+ const b = compand(
645
+ X2 * MtxXYZ2RGB.m02 + Y2 * MtxXYZ2RGB.m12 + Z2 * MtxXYZ2RGB.m22
646
+ );
647
+
648
+ return [r * 255, g * 255, b * 255];
649
+ };
650
+
651
+ const rgb2lab = (...args) => {
652
+ const [r, g, b, ...rest] = unpack(args, 'rgb');
653
+ const [x, y, z] = rgb2xyz(r, g, b);
654
+ const [L, a, b_] = xyz2lab(x, y, z);
655
+ return [L, a, b_, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
656
+ };
657
+
658
+ function xyz2lab(x, y, z) {
659
+ const { Xn, Yn, Zn, kE, kK } = labConstants;
660
+ const xr = x / Xn;
661
+ const yr = y / Yn;
662
+ const zr = z / Zn;
663
+
664
+ const fx = xr > kE ? Math.pow(xr, 1.0 / 3.0) : (kK * xr + 16.0) / 116.0;
665
+ const fy = yr > kE ? Math.pow(yr, 1.0 / 3.0) : (kK * yr + 16.0) / 116.0;
666
+ const fz = zr > kE ? Math.pow(zr, 1.0 / 3.0) : (kK * zr + 16.0) / 116.0;
667
+
668
+ return [116.0 * fy - 16.0, 500.0 * (fx - fy), 200.0 * (fy - fz)];
669
+ }
670
+
671
+ function gammaAdjustSRGB(companded) {
672
+ const sign = Math.sign(companded);
673
+ companded = Math.abs(companded);
674
+ const linear =
675
+ companded <= 0.04045
676
+ ? companded / 12.92
677
+ : Math.pow((companded + 0.055) / 1.055, 2.4);
678
+ return linear * sign;
679
+ }
680
+
681
+ const rgb2xyz = (r, g, b) => {
682
+ // normalize and gamma adjust
683
+ r = gammaAdjustSRGB(r / 255);
684
+ g = gammaAdjustSRGB(g / 255);
685
+ b = gammaAdjustSRGB(b / 255);
686
+
687
+ const { MtxRGB2XYZ, MtxAdaptMa, MtxAdaptMaI, Xn, Yn, Zn, As, Bs, Cs } =
688
+ labConstants;
689
+
690
+ let x = r * MtxRGB2XYZ.m00 + g * MtxRGB2XYZ.m10 + b * MtxRGB2XYZ.m20;
691
+ let y = r * MtxRGB2XYZ.m01 + g * MtxRGB2XYZ.m11 + b * MtxRGB2XYZ.m21;
692
+ let z = r * MtxRGB2XYZ.m02 + g * MtxRGB2XYZ.m12 + b * MtxRGB2XYZ.m22;
693
+
694
+ const Ad = Xn * MtxAdaptMa.m00 + Yn * MtxAdaptMa.m10 + Zn * MtxAdaptMa.m20;
695
+ const Bd = Xn * MtxAdaptMa.m01 + Yn * MtxAdaptMa.m11 + Zn * MtxAdaptMa.m21;
696
+ const Cd = Xn * MtxAdaptMa.m02 + Yn * MtxAdaptMa.m12 + Zn * MtxAdaptMa.m22;
697
+
698
+ let X = x * MtxAdaptMa.m00 + y * MtxAdaptMa.m10 + z * MtxAdaptMa.m20;
699
+ let Y = x * MtxAdaptMa.m01 + y * MtxAdaptMa.m11 + z * MtxAdaptMa.m21;
700
+ let Z = x * MtxAdaptMa.m02 + y * MtxAdaptMa.m12 + z * MtxAdaptMa.m22;
701
+
702
+ X *= Ad / As;
703
+ Y *= Bd / Bs;
704
+ Z *= Cd / Cs;
705
+
706
+ x = X * MtxAdaptMaI.m00 + Y * MtxAdaptMaI.m10 + Z * MtxAdaptMaI.m20;
707
+ y = X * MtxAdaptMaI.m01 + Y * MtxAdaptMaI.m11 + Z * MtxAdaptMaI.m21;
708
+ z = X * MtxAdaptMaI.m02 + Y * MtxAdaptMaI.m12 + Z * MtxAdaptMaI.m22;
709
+
710
+ return [x, y, z];
711
+ };
712
+
713
+ Color.prototype.lab = function () {
714
+ return rgb2lab(this._rgb);
715
+ };
716
+
717
+ const lab$1 = (...args) => new Color(...args, 'lab');
718
+ Object.assign(chroma, { lab: lab$1, getLabWhitePoint, setLabWhitePoint });
719
+
720
+ input.format.lab = lab2rgb;
721
+
722
+ input.autodetect.push({
723
+ p: 2,
724
+ test: (...args) => {
725
+ args = unpack(args, 'lab');
726
+ if (type(args) === 'array' && args.length === 3) {
727
+ return 'lab';
728
+ }
729
+ }
730
+ });
731
+
732
+ Color.prototype.darken = function (amount = 1) {
733
+ const me = this;
734
+ const lab = me.lab();
735
+ lab[0] -= labConstants.Kn * amount;
736
+ return new Color(lab, 'lab').alpha(me.alpha(), true);
737
+ };
738
+
739
+ Color.prototype.brighten = function (amount = 1) {
740
+ return this.darken(-amount);
741
+ };
742
+
743
+ Color.prototype.darker = Color.prototype.darken;
744
+ Color.prototype.brighter = Color.prototype.brighten;
745
+
746
+ Color.prototype.get = function (mc) {
747
+ const [mode, channel] = mc.split('.');
748
+ const src = this[mode]();
749
+ if (channel) {
750
+ const i = mode.indexOf(channel) - (mode.substr(0, 2) === 'ok' ? 2 : 0);
751
+ if (i > -1) return src[i];
752
+ throw new Error(`unknown channel ${channel} in mode ${mode}`);
753
+ } else {
754
+ return src;
755
+ }
756
+ };
757
+
758
+ const { pow: pow$6 } = Math;
759
+
760
+ const EPS = 1e-7;
761
+ const MAX_ITER = 20;
762
+
763
+ Color.prototype.luminance = function (lum, mode = 'rgb') {
764
+ if (lum !== undefined && type(lum) === 'number') {
765
+ if (lum === 0) {
766
+ // return pure black
767
+ return new Color([0, 0, 0, this._rgb[3]], 'rgb');
768
+ }
769
+ if (lum === 1) {
770
+ // return pure white
771
+ return new Color([255, 255, 255, this._rgb[3]], 'rgb');
772
+ }
773
+ // compute new color using...
774
+ let cur_lum = this.luminance();
775
+ let max_iter = MAX_ITER;
776
+
777
+ const test = (low, high) => {
778
+ const mid = low.interpolate(high, 0.5, mode);
779
+ const lm = mid.luminance();
780
+ if (Math.abs(lum - lm) < EPS || !max_iter--) {
781
+ // close enough
782
+ return mid;
783
+ }
784
+ return lm > lum ? test(low, mid) : test(mid, high);
785
+ };
786
+
787
+ const rgb = (
788
+ cur_lum > lum
789
+ ? test(new Color([0, 0, 0]), this)
790
+ : test(this, new Color([255, 255, 255]))
791
+ ).rgb();
792
+ return new Color([...rgb, this._rgb[3]]);
793
+ }
794
+ return rgb2luminance(...this._rgb.slice(0, 3));
795
+ };
796
+
797
+ const rgb2luminance = (r, g, b) => {
798
+ // relative luminance
799
+ // see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
800
+ r = luminance_x(r);
801
+ g = luminance_x(g);
802
+ b = luminance_x(b);
803
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
804
+ };
805
+
806
+ const luminance_x = (x) => {
807
+ x /= 255;
808
+ return x <= 0.03928 ? x / 12.92 : pow$6((x + 0.055) / 1.055, 2.4);
809
+ };
810
+
811
+ const index = {};
812
+
813
+ const mix = (col1, col2, f = 0.5, ...rest) => {
814
+ let mode = rest[0] || 'lrgb';
815
+ if (!index[mode] && !rest.length) {
816
+ // fall back to the first supported mode
817
+ mode = Object.keys(index)[0];
818
+ }
819
+ if (!index[mode]) {
820
+ throw new Error(`interpolation mode ${mode} is not defined`);
821
+ }
822
+ if (type(col1) !== 'object') col1 = new Color(col1);
823
+ if (type(col2) !== 'object') col2 = new Color(col2);
824
+ return index[mode](col1, col2, f).alpha(
825
+ col1.alpha() + f * (col2.alpha() - col1.alpha())
826
+ );
827
+ };
828
+
829
+ Color.prototype.mix = Color.prototype.interpolate = function (
830
+ col2,
831
+ f = 0.5,
832
+ ...rest
833
+ ) {
834
+ return mix(this, col2, f, ...rest);
835
+ };
836
+
837
+ Color.prototype.premultiply = function (mutate = false) {
838
+ const rgb = this._rgb;
839
+ const a = rgb[3];
840
+ if (mutate) {
841
+ this._rgb = [rgb[0] * a, rgb[1] * a, rgb[2] * a, a];
842
+ return this;
843
+ } else {
844
+ return new Color([rgb[0] * a, rgb[1] * a, rgb[2] * a, a], 'rgb');
845
+ }
846
+ };
847
+
848
+ const { sin: sin$3, cos: cos$4 } = Math;
849
+
850
+ const lch2lab = (...args) => {
851
+ /*
852
+ Convert from a qualitative parameter h and a quantitative parameter l to a 24-bit pixel.
853
+ These formulas were invented by David Dalrymple to obtain maximum contrast without going
854
+ out of gamut if the parameters are in the range 0-1.
855
+
856
+ A saturation multiplier was added by Gregor Aisch
857
+ */
858
+ let [l, c, h] = unpack(args, 'lch');
859
+ if (isNaN(h)) h = 0;
860
+ h = h * DEG2RAD;
861
+ return [l, cos$4(h) * c, sin$3(h) * c];
862
+ };
863
+
864
+ const lch2rgb = (...args) => {
865
+ args = unpack(args, 'lch');
866
+ const [l, c, h] = args;
867
+ const [L, a, b_] = lch2lab(l, c, h);
868
+ const [r, g, b] = lab2rgb(L, a, b_);
869
+ return [r, g, b, args.length > 3 ? args[3] : 1];
870
+ };
871
+
872
+ const hcl2rgb = (...args) => {
873
+ const hcl = reverse3(unpack(args, 'hcl'));
874
+ return lch2rgb(...hcl);
875
+ };
876
+
877
+ const { sqrt: sqrt$4, atan2: atan2$2, round: round$4 } = Math;
878
+
879
+ const lab2lch = (...args) => {
880
+ const [l, a, b] = unpack(args, 'lab');
881
+ const c = sqrt$4(a * a + b * b);
882
+ let h = (atan2$2(b, a) * RAD2DEG + 360) % 360;
883
+ if (round$4(c * 10000) === 0) h = Number.NaN;
884
+ return [l, c, h];
885
+ };
886
+
887
+ const rgb2lch = (...args) => {
888
+ const [r, g, b, ...rest] = unpack(args, 'rgb');
889
+ const [l, a, b_] = rgb2lab(r, g, b);
890
+ const [L, c, h] = lab2lch(l, a, b_);
891
+ return [L, c, h, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
892
+ };
893
+
894
+ Color.prototype.lch = function () {
895
+ return rgb2lch(this._rgb);
896
+ };
897
+ Color.prototype.hcl = function () {
898
+ return reverse3(rgb2lch(this._rgb));
899
+ };
900
+
901
+ const lch$1 = (...args) => new Color(...args, 'lch');
902
+ const hcl = (...args) => new Color(...args, 'hcl');
903
+
904
+ Object.assign(chroma, { lch: lch$1, hcl });
905
+
906
+ input.format.lch = lch2rgb;
907
+ input.format.hcl = hcl2rgb;
908
+ ['lch', 'hcl'].forEach((m) =>
909
+ input.autodetect.push({
910
+ p: 2,
911
+ test: (...args) => {
912
+ args = unpack(args, m);
913
+ if (type(args) === 'array' && args.length === 3) {
914
+ return m;
915
+ }
916
+ }
917
+ })
918
+ );
919
+
920
+ Color.prototype.saturate = function (amount = 1) {
921
+ const me = this;
922
+ const lch = me.lch();
923
+ lch[1] += labConstants.Kn * amount;
924
+ if (lch[1] < 0) lch[1] = 0;
925
+ return new Color(lch, 'lch').alpha(me.alpha(), true);
926
+ };
927
+
928
+ Color.prototype.desaturate = function (amount = 1) {
929
+ return this.saturate(-amount);
930
+ };
931
+
932
+ Color.prototype.set = function (mc, value, mutate = false) {
933
+ const [mode, channel] = mc.split('.');
934
+ const src = this[mode]();
935
+ if (channel) {
936
+ const i = mode.indexOf(channel) - (mode.substr(0, 2) === 'ok' ? 2 : 0);
937
+ if (i > -1) {
938
+ if (type(value) == 'string') {
939
+ switch (value.charAt(0)) {
940
+ case '+':
941
+ src[i] += +value;
942
+ break;
943
+ case '-':
944
+ src[i] += +value;
945
+ break;
946
+ case '*':
947
+ src[i] *= +value.substr(1);
948
+ break;
949
+ case '/':
950
+ src[i] /= +value.substr(1);
951
+ break;
952
+ default:
953
+ src[i] = +value;
954
+ }
955
+ } else if (type(value) === 'number') {
956
+ src[i] = value;
957
+ } else {
958
+ throw new Error(`unsupported value for Color.set`);
959
+ }
960
+ const out = new Color(src, mode);
961
+ if (mutate) {
962
+ this._rgb = out._rgb;
963
+ return this;
964
+ }
965
+ return out;
966
+ }
967
+ throw new Error(`unknown channel ${channel} in mode ${mode}`);
968
+ } else {
969
+ return src;
970
+ }
971
+ };
972
+
973
+ Color.prototype.tint = function (f = 0.5, ...rest) {
974
+ return mix(this, 'white', f, ...rest);
975
+ };
976
+
977
+ Color.prototype.shade = function (f = 0.5, ...rest) {
978
+ return mix(this, 'black', f, ...rest);
979
+ };
980
+
981
+ const rgb$1 = (col1, col2, f) => {
982
+ const xyz0 = col1._rgb;
983
+ const xyz1 = col2._rgb;
984
+ return new Color(
985
+ xyz0[0] + f * (xyz1[0] - xyz0[0]),
986
+ xyz0[1] + f * (xyz1[1] - xyz0[1]),
987
+ xyz0[2] + f * (xyz1[2] - xyz0[2]),
988
+ 'rgb'
989
+ );
990
+ };
991
+
992
+ // register interpolator
993
+ index.rgb = rgb$1;
994
+
995
+ const { sqrt: sqrt$3, pow: pow$5 } = Math;
996
+
997
+ const lrgb = (col1, col2, f) => {
998
+ const [x1, y1, z1] = col1._rgb;
999
+ const [x2, y2, z2] = col2._rgb;
1000
+ return new Color(
1001
+ sqrt$3(pow$5(x1, 2) * (1 - f) + pow$5(x2, 2) * f),
1002
+ sqrt$3(pow$5(y1, 2) * (1 - f) + pow$5(y2, 2) * f),
1003
+ sqrt$3(pow$5(z1, 2) * (1 - f) + pow$5(z2, 2) * f),
1004
+ 'rgb'
1005
+ );
1006
+ };
1007
+
1008
+ // register interpolator
1009
+ index.lrgb = lrgb;
1010
+
1011
+ const lab = (col1, col2, f) => {
1012
+ const xyz0 = col1.lab();
1013
+ const xyz1 = col2.lab();
1014
+ return new Color(
1015
+ xyz0[0] + f * (xyz1[0] - xyz0[0]),
1016
+ xyz0[1] + f * (xyz1[1] - xyz0[1]),
1017
+ xyz0[2] + f * (xyz1[2] - xyz0[2]),
1018
+ 'lab'
1019
+ );
1020
+ };
1021
+
1022
+ // register interpolator
1023
+ index.lab = lab;
1024
+
1025
+ const interpolate_hsx = (col1, col2, f, m) => {
1026
+ let xyz0, xyz1;
1027
+ if (m === 'hsl') {
1028
+ xyz0 = col1.hsl();
1029
+ xyz1 = col2.hsl();
1030
+ } else if (m === 'hsv') {
1031
+ xyz0 = col1.hsv();
1032
+ xyz1 = col2.hsv();
1033
+ } else if (m === 'hcg') {
1034
+ xyz0 = col1.hcg();
1035
+ xyz1 = col2.hcg();
1036
+ } else if (m === 'hsi') {
1037
+ xyz0 = col1.hsi();
1038
+ xyz1 = col2.hsi();
1039
+ } else if (m === 'lch' || m === 'hcl') {
1040
+ m = 'hcl';
1041
+ xyz0 = col1.hcl();
1042
+ xyz1 = col2.hcl();
1043
+ } else if (m === 'oklch') {
1044
+ xyz0 = col1.oklch().reverse();
1045
+ xyz1 = col2.oklch().reverse();
1046
+ }
1047
+
1048
+ let hue0, hue1, sat0, sat1, lbv0, lbv1;
1049
+ if (m.substr(0, 1) === 'h' || m === 'oklch') {
1050
+ [hue0, sat0, lbv0] = xyz0;
1051
+ [hue1, sat1, lbv1] = xyz1;
1052
+ }
1053
+
1054
+ let sat, hue, lbv, dh;
1055
+
1056
+ if (!isNaN(hue0) && !isNaN(hue1)) {
1057
+ // both colors have hue
1058
+ if (hue1 > hue0 && hue1 - hue0 > 180) {
1059
+ dh = hue1 - (hue0 + 360);
1060
+ } else if (hue1 < hue0 && hue0 - hue1 > 180) {
1061
+ dh = hue1 + 360 - hue0;
1062
+ } else {
1063
+ dh = hue1 - hue0;
1064
+ }
1065
+ hue = hue0 + f * dh;
1066
+ } else if (!isNaN(hue0)) {
1067
+ hue = hue0;
1068
+ if ((lbv1 == 1 || lbv1 == 0) && m != 'hsv') sat = sat0;
1069
+ } else if (!isNaN(hue1)) {
1070
+ hue = hue1;
1071
+ if ((lbv0 == 1 || lbv0 == 0) && m != 'hsv') sat = sat1;
1072
+ } else {
1073
+ hue = Number.NaN;
1074
+ }
1075
+
1076
+ if (sat === undefined) sat = sat0 + f * (sat1 - sat0);
1077
+ lbv = lbv0 + f * (lbv1 - lbv0);
1078
+ return m === 'oklch'
1079
+ ? new Color([lbv, sat, hue], m)
1080
+ : new Color([hue, sat, lbv], m);
1081
+ };
1082
+
1083
+ const lch = (col1, col2, f) => {
1084
+ return interpolate_hsx(col1, col2, f, 'lch');
1085
+ };
1086
+
1087
+ // register interpolator
1088
+ index.lch = lch;
1089
+ index.hcl = lch;
1090
+
1091
+ const num2rgb = (num) => {
1092
+ if (type(num) == 'number' && num >= 0 && num <= 0xffffff) {
1093
+ const r = num >> 16;
1094
+ const g = (num >> 8) & 0xff;
1095
+ const b = num & 0xff;
1096
+ return [r, g, b, 1];
1097
+ }
1098
+ throw new Error('unknown num color: ' + num);
1099
+ };
1100
+
1101
+ const rgb2num = (...args) => {
1102
+ const [r, g, b] = unpack(args, 'rgb');
1103
+ return (r << 16) + (g << 8) + b;
1104
+ };
1105
+
1106
+ Color.prototype.num = function () {
1107
+ return rgb2num(this._rgb);
1108
+ };
1109
+
1110
+ const num$1 = (...args) => new Color(...args, 'num');
1111
+
1112
+ Object.assign(chroma, { num: num$1 });
1113
+
1114
+ input.format.num = num2rgb;
1115
+
1116
+ input.autodetect.push({
1117
+ p: 5,
1118
+ test: (...args) => {
1119
+ if (
1120
+ args.length === 1 &&
1121
+ type(args[0]) === 'number' &&
1122
+ args[0] >= 0 &&
1123
+ args[0] <= 0xffffff
1124
+ ) {
1125
+ return 'num';
1126
+ }
1127
+ }
1128
+ });
1129
+
1130
+ const num = (col1, col2, f) => {
1131
+ const c1 = col1.num();
1132
+ const c2 = col2.num();
1133
+ return new Color(c1 + f * (c2 - c1), 'num');
1134
+ };
1135
+
1136
+ // register interpolator
1137
+ index.num = num;
1138
+
1139
+ const { floor: floor$3 } = Math;
1140
+
1141
+ /*
1142
+ * this is basically just HSV with some minor tweaks
1143
+ *
1144
+ * hue.. [0..360]
1145
+ * chroma .. [0..1]
1146
+ * grayness .. [0..1]
1147
+ */
1148
+
1149
+ const hcg2rgb = (...args) => {
1150
+ args = unpack(args, 'hcg');
1151
+ let [h, c, _g] = args;
1152
+ let r, g, b;
1153
+ _g = _g * 255;
1154
+ const _c = c * 255;
1155
+ if (c === 0) {
1156
+ r = g = b = _g;
1157
+ } else {
1158
+ if (h === 360) h = 0;
1159
+ if (h > 360) h -= 360;
1160
+ if (h < 0) h += 360;
1161
+ h /= 60;
1162
+ const i = floor$3(h);
1163
+ const f = h - i;
1164
+ const p = _g * (1 - c);
1165
+ const q = p + _c * (1 - f);
1166
+ const t = p + _c * f;
1167
+ const v = p + _c;
1168
+ switch (i) {
1169
+ case 0:
1170
+ [r, g, b] = [v, t, p];
1171
+ break;
1172
+ case 1:
1173
+ [r, g, b] = [q, v, p];
1174
+ break;
1175
+ case 2:
1176
+ [r, g, b] = [p, v, t];
1177
+ break;
1178
+ case 3:
1179
+ [r, g, b] = [p, q, v];
1180
+ break;
1181
+ case 4:
1182
+ [r, g, b] = [t, p, v];
1183
+ break;
1184
+ case 5:
1185
+ [r, g, b] = [v, p, q];
1186
+ break;
1187
+ }
1188
+ }
1189
+ return [r, g, b, args.length > 3 ? args[3] : 1];
1190
+ };
1191
+
1192
+ const rgb2hcg = (...args) => {
1193
+ const [r, g, b] = unpack(args, 'rgb');
1194
+ const minRgb = min$3(r, g, b);
1195
+ const maxRgb = max$3(r, g, b);
1196
+ const delta = maxRgb - minRgb;
1197
+ const c = (delta * 100) / 255;
1198
+ const _g = (minRgb / (255 - delta)) * 100;
1199
+ let h;
1200
+ if (delta === 0) {
1201
+ h = Number.NaN;
1202
+ } else {
1203
+ if (r === maxRgb) h = (g - b) / delta;
1204
+ if (g === maxRgb) h = 2 + (b - r) / delta;
1205
+ if (b === maxRgb) h = 4 + (r - g) / delta;
1206
+ h *= 60;
1207
+ if (h < 0) h += 360;
1208
+ }
1209
+ return [h, c, _g];
1210
+ };
1211
+
1212
+ Color.prototype.hcg = function () {
1213
+ return rgb2hcg(this._rgb);
1214
+ };
1215
+
1216
+ const hcg$1 = (...args) => new Color(...args, 'hcg');
1217
+ chroma.hcg = hcg$1;
1218
+
1219
+ input.format.hcg = hcg2rgb;
1220
+
1221
+ input.autodetect.push({
1222
+ p: 1,
1223
+ test: (...args) => {
1224
+ args = unpack(args, 'hcg');
1225
+ if (type(args) === 'array' && args.length === 3) {
1226
+ return 'hcg';
1227
+ }
1228
+ }
1229
+ });
1230
+
1231
+ const hcg = (col1, col2, f) => {
1232
+ return interpolate_hsx(col1, col2, f, 'hcg');
1233
+ };
1234
+
1235
+ // register interpolator
1236
+ index.hcg = hcg;
1237
+
1238
+ const { cos: cos$3 } = Math;
1239
+
1240
+ /*
1241
+ * hue [0..360]
1242
+ * saturation [0..1]
1243
+ * intensity [0..1]
1244
+ */
1245
+ const hsi2rgb = (...args) => {
1246
+ /*
1247
+ borrowed from here:
1248
+ http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/hsi2rgb.cpp
1249
+ */
1250
+ args = unpack(args, 'hsi');
1251
+ let [h, s, i] = args;
1252
+ let r, g, b;
1253
+
1254
+ if (isNaN(h)) h = 0;
1255
+ if (isNaN(s)) s = 0;
1256
+ // normalize hue
1257
+ if (h > 360) h -= 360;
1258
+ if (h < 0) h += 360;
1259
+ h /= 360;
1260
+ if (h < 1 / 3) {
1261
+ b = (1 - s) / 3;
1262
+ r = (1 + (s * cos$3(TWOPI * h)) / cos$3(PITHIRD - TWOPI * h)) / 3;
1263
+ g = 1 - (b + r);
1264
+ } else if (h < 2 / 3) {
1265
+ h -= 1 / 3;
1266
+ r = (1 - s) / 3;
1267
+ g = (1 + (s * cos$3(TWOPI * h)) / cos$3(PITHIRD - TWOPI * h)) / 3;
1268
+ b = 1 - (r + g);
1269
+ } else {
1270
+ h -= 2 / 3;
1271
+ g = (1 - s) / 3;
1272
+ b = (1 + (s * cos$3(TWOPI * h)) / cos$3(PITHIRD - TWOPI * h)) / 3;
1273
+ r = 1 - (g + b);
1274
+ }
1275
+ r = limit(i * r * 3);
1276
+ g = limit(i * g * 3);
1277
+ b = limit(i * b * 3);
1278
+ return [r * 255, g * 255, b * 255, args.length > 3 ? args[3] : 1];
1279
+ };
1280
+
1281
+ const { min: min$2, sqrt: sqrt$2, acos } = Math;
1282
+
1283
+ const rgb2hsi = (...args) => {
1284
+ /*
1285
+ borrowed from here:
1286
+ http://hummer.stanford.edu/museinfo/doc/examples/humdrum/keyscape2/rgb2hsi.cpp
1287
+ */
1288
+ let [r, g, b] = unpack(args, 'rgb');
1289
+ r /= 255;
1290
+ g /= 255;
1291
+ b /= 255;
1292
+ let h;
1293
+ const min_ = min$2(r, g, b);
1294
+ const i = (r + g + b) / 3;
1295
+ const s = i > 0 ? 1 - min_ / i : 0;
1296
+ if (s === 0) {
1297
+ h = NaN;
1298
+ } else {
1299
+ h = (r - g + (r - b)) / 2;
1300
+ h /= sqrt$2((r - g) * (r - g) + (r - b) * (g - b));
1301
+ h = acos(h);
1302
+ if (b > g) {
1303
+ h = TWOPI - h;
1304
+ }
1305
+ h /= TWOPI;
1306
+ }
1307
+ return [h * 360, s, i];
1308
+ };
1309
+
1310
+ Color.prototype.hsi = function () {
1311
+ return rgb2hsi(this._rgb);
1312
+ };
1313
+
1314
+ const hsi$1 = (...args) => new Color(...args, 'hsi');
1315
+ chroma.hsi = hsi$1;
1316
+
1317
+ input.format.hsi = hsi2rgb;
1318
+
1319
+ input.autodetect.push({
1320
+ p: 2,
1321
+ test: (...args) => {
1322
+ args = unpack(args, 'hsi');
1323
+ if (type(args) === 'array' && args.length === 3) {
1324
+ return 'hsi';
1325
+ }
1326
+ }
1327
+ });
1328
+
1329
+ const hsi = (col1, col2, f) => {
1330
+ return interpolate_hsx(col1, col2, f, 'hsi');
1331
+ };
1332
+
1333
+ // register interpolator
1334
+ index.hsi = hsi;
1335
+
1336
+ const hsl2rgb = (...args) => {
1337
+ args = unpack(args, 'hsl');
1338
+ const [h, s, l] = args;
1339
+ let r, g, b;
1340
+ if (s === 0) {
1341
+ r = g = b = l * 255;
1342
+ } else {
1343
+ const t3 = [0, 0, 0];
1344
+ const c = [0, 0, 0];
1345
+ const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
1346
+ const t1 = 2 * l - t2;
1347
+ const h_ = h / 360;
1348
+ t3[0] = h_ + 1 / 3;
1349
+ t3[1] = h_;
1350
+ t3[2] = h_ - 1 / 3;
1351
+ for (let i = 0; i < 3; i++) {
1352
+ if (t3[i] < 0) t3[i] += 1;
1353
+ if (t3[i] > 1) t3[i] -= 1;
1354
+ if (6 * t3[i] < 1) c[i] = t1 + (t2 - t1) * 6 * t3[i];
1355
+ else if (2 * t3[i] < 1) c[i] = t2;
1356
+ else if (3 * t3[i] < 2) c[i] = t1 + (t2 - t1) * (2 / 3 - t3[i]) * 6;
1357
+ else c[i] = t1;
1358
+ }
1359
+ [r, g, b] = [c[0] * 255, c[1] * 255, c[2] * 255];
1360
+ }
1361
+ if (args.length > 3) {
1362
+ // keep alpha channel
1363
+ return [r, g, b, args[3]];
1364
+ }
1365
+ return [r, g, b, 1];
1366
+ };
1367
+
1368
+ /*
1369
+ * supported arguments:
1370
+ * - rgb2hsl(r,g,b)
1371
+ * - rgb2hsl(r,g,b,a)
1372
+ * - rgb2hsl([r,g,b])
1373
+ * - rgb2hsl([r,g,b,a])
1374
+ * - rgb2hsl({r,g,b,a})
1375
+ */
1376
+ const rgb2hsl$1 = (...args) => {
1377
+ args = unpack(args, 'rgba');
1378
+ let [r, g, b] = args;
1379
+
1380
+ r /= 255;
1381
+ g /= 255;
1382
+ b /= 255;
1383
+
1384
+ const minRgb = min$3(r, g, b);
1385
+ const maxRgb = max$3(r, g, b);
1386
+
1387
+ const l = (maxRgb + minRgb) / 2;
1388
+ let s, h;
1389
+
1390
+ if (maxRgb === minRgb) {
1391
+ s = 0;
1392
+ h = Number.NaN;
1393
+ } else {
1394
+ s =
1395
+ l < 0.5
1396
+ ? (maxRgb - minRgb) / (maxRgb + minRgb)
1397
+ : (maxRgb - minRgb) / (2 - maxRgb - minRgb);
1398
+ }
1399
+
1400
+ if (r == maxRgb) h = (g - b) / (maxRgb - minRgb);
1401
+ else if (g == maxRgb) h = 2 + (b - r) / (maxRgb - minRgb);
1402
+ else if (b == maxRgb) h = 4 + (r - g) / (maxRgb - minRgb);
1403
+
1404
+ h *= 60;
1405
+ if (h < 0) h += 360;
1406
+ if (args.length > 3 && args[3] !== undefined) return [h, s, l, args[3]];
1407
+ return [h, s, l];
1408
+ };
1409
+
1410
+ Color.prototype.hsl = function () {
1411
+ return rgb2hsl$1(this._rgb);
1412
+ };
1413
+
1414
+ const hsl$1 = (...args) => new Color(...args, 'hsl');
1415
+ chroma.hsl = hsl$1;
1416
+
1417
+ input.format.hsl = hsl2rgb;
1418
+
1419
+ input.autodetect.push({
1420
+ p: 2,
1421
+ test: (...args) => {
1422
+ args = unpack(args, 'hsl');
1423
+ if (type(args) === 'array' && args.length === 3) {
1424
+ return 'hsl';
1425
+ }
1426
+ }
1427
+ });
1428
+
1429
+ const hsl = (col1, col2, f) => {
1430
+ return interpolate_hsx(col1, col2, f, 'hsl');
1431
+ };
1432
+
1433
+ // register interpolator
1434
+ index.hsl = hsl;
1435
+
1436
+ const { floor: floor$2 } = Math;
1437
+
1438
+ const hsv2rgb = (...args) => {
1439
+ args = unpack(args, 'hsv');
1440
+ let [h, s, v] = args;
1441
+ let r, g, b;
1442
+ v *= 255;
1443
+ if (s === 0) {
1444
+ r = g = b = v;
1445
+ } else {
1446
+ if (h === 360) h = 0;
1447
+ if (h > 360) h -= 360;
1448
+ if (h < 0) h += 360;
1449
+ h /= 60;
1450
+
1451
+ const i = floor$2(h);
1452
+ const f = h - i;
1453
+ const p = v * (1 - s);
1454
+ const q = v * (1 - s * f);
1455
+ const t = v * (1 - s * (1 - f));
1456
+
1457
+ switch (i) {
1458
+ case 0:
1459
+ [r, g, b] = [v, t, p];
1460
+ break;
1461
+ case 1:
1462
+ [r, g, b] = [q, v, p];
1463
+ break;
1464
+ case 2:
1465
+ [r, g, b] = [p, v, t];
1466
+ break;
1467
+ case 3:
1468
+ [r, g, b] = [p, q, v];
1469
+ break;
1470
+ case 4:
1471
+ [r, g, b] = [t, p, v];
1472
+ break;
1473
+ case 5:
1474
+ [r, g, b] = [v, p, q];
1475
+ break;
1476
+ }
1477
+ }
1478
+ return [r, g, b, args.length > 3 ? args[3] : 1];
1479
+ };
1480
+
1481
+ const { min: min$1, max: max$2 } = Math;
1482
+
1483
+ /*
1484
+ * supported arguments:
1485
+ * - rgb2hsv(r,g,b)
1486
+ * - rgb2hsv([r,g,b])
1487
+ * - rgb2hsv({r,g,b})
1488
+ */
1489
+ const rgb2hsl = (...args) => {
1490
+ args = unpack(args, 'rgb');
1491
+ let [r, g, b] = args;
1492
+ const min_ = min$1(r, g, b);
1493
+ const max_ = max$2(r, g, b);
1494
+ const delta = max_ - min_;
1495
+ let h, s, v;
1496
+ v = max_ / 255.0;
1497
+ if (max_ === 0) {
1498
+ h = Number.NaN;
1499
+ s = 0;
1500
+ } else {
1501
+ s = delta / max_;
1502
+ if (r === max_) h = (g - b) / delta;
1503
+ if (g === max_) h = 2 + (b - r) / delta;
1504
+ if (b === max_) h = 4 + (r - g) / delta;
1505
+ h *= 60;
1506
+ if (h < 0) h += 360;
1507
+ }
1508
+ return [h, s, v];
1509
+ };
1510
+
1511
+ Color.prototype.hsv = function () {
1512
+ return rgb2hsl(this._rgb);
1513
+ };
1514
+
1515
+ const hsv$1 = (...args) => new Color(...args, 'hsv');
1516
+ chroma.hsv = hsv$1;
1517
+
1518
+ input.format.hsv = hsv2rgb;
1519
+
1520
+ input.autodetect.push({
1521
+ p: 2,
1522
+ test: (...args) => {
1523
+ args = unpack(args, 'hsv');
1524
+ if (type(args) === 'array' && args.length === 3) {
1525
+ return 'hsv';
1526
+ }
1527
+ }
1528
+ });
1529
+
1530
+ const hsv = (col1, col2, f) => {
1531
+ return interpolate_hsx(col1, col2, f, 'hsv');
1532
+ };
1533
+
1534
+ // register interpolator
1535
+ index.hsv = hsv;
1536
+
1537
+ // from https://www.w3.org/TR/css-color-4/multiply-matrices.js
1538
+ function multiplyMatrices(A, B) {
1539
+ let m = A.length;
1540
+
1541
+ if (!Array.isArray(A[0])) {
1542
+ // A is vector, convert to [[a, b, c, ...]]
1543
+ A = [A];
1544
+ }
1545
+
1546
+ if (!Array.isArray(B[0])) {
1547
+ // B is vector, convert to [[a], [b], [c], ...]]
1548
+ B = B.map((x) => [x]);
1549
+ }
1550
+
1551
+ let p = B[0].length;
1552
+ let B_cols = B[0].map((_, i) => B.map((x) => x[i])); // transpose B
1553
+ let product = A.map((row) =>
1554
+ B_cols.map((col) => {
1555
+ if (!Array.isArray(row)) {
1556
+ return col.reduce((a, c) => a + c * row, 0);
1557
+ }
1558
+
1559
+ return row.reduce((a, c, i) => a + c * (col[i] || 0), 0);
1560
+ })
1561
+ );
1562
+
1563
+ if (m === 1) {
1564
+ product = product[0]; // Avoid [[a, b, c, ...]]
1565
+ }
1566
+
1567
+ if (p === 1) {
1568
+ return product.map((x) => x[0]); // Avoid [[a], [b], [c], ...]]
1569
+ }
1570
+
1571
+ return product;
1572
+ }
1573
+
1574
+ const oklab2rgb = (...args) => {
1575
+ args = unpack(args, 'lab');
1576
+ const [L, a, b, ...rest] = args;
1577
+ const [X, Y, Z] = OKLab_to_XYZ([L, a, b]);
1578
+ const [r, g, b_] = xyz2rgb(X, Y, Z);
1579
+ return [r, g, b_, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
1580
+ };
1581
+
1582
+ // from https://www.w3.org/TR/css-color-4/#color-conversion-code
1583
+ function OKLab_to_XYZ(OKLab) {
1584
+ // Given OKLab, convert to XYZ relative to D65
1585
+ var LMStoXYZ = [
1586
+ [1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
1587
+ [-0.0405757452148008, 1.112286803280317, -0.0717110580655164],
1588
+ [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
1589
+ ];
1590
+ var OKLabtoLMS = [
1591
+ [1.0, 0.3963377773761749, 0.2158037573099136],
1592
+ [1.0, -0.1055613458156586, -0.0638541728258133],
1593
+ [1.0, -0.0894841775298119, -1.2914855480194092]
1594
+ ];
1595
+
1596
+ var LMSnl = multiplyMatrices(OKLabtoLMS, OKLab);
1597
+ return multiplyMatrices(
1598
+ LMStoXYZ,
1599
+ LMSnl.map((c) => c ** 3)
1600
+ );
1601
+ }
1602
+
1603
+ const rgb2oklab = (...args) => {
1604
+ const [r, g, b, ...rest] = unpack(args, 'rgb');
1605
+ const xyz = rgb2xyz(r, g, b);
1606
+ const oklab = XYZ_to_OKLab(xyz);
1607
+ return [...oklab, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
1608
+ };
1609
+
1610
+ // from https://www.w3.org/TR/css-color-4/#color-conversion-code
1611
+ function XYZ_to_OKLab(XYZ) {
1612
+ // Given XYZ relative to D65, convert to OKLab
1613
+ const XYZtoLMS = [
1614
+ [0.819022437996703, 0.3619062600528904, -0.1288737815209879],
1615
+ [0.0329836539323885, 0.9292868615863434, 0.0361446663506424],
1616
+ [0.0481771893596242, 0.2642395317527308, 0.6335478284694309]
1617
+ ];
1618
+ const LMStoOKLab = [
1619
+ [0.210454268309314, 0.7936177747023054, -0.0040720430116193],
1620
+ [1.9779985324311684, -2.4285922420485799, 0.450593709617411],
1621
+ [0.0259040424655478, 0.7827717124575296, -0.8086757549230774]
1622
+ ];
1623
+
1624
+ const LMS = multiplyMatrices(XYZtoLMS, XYZ);
1625
+ // JavaScript Math.cbrt returns a sign-matched cube root
1626
+ // beware if porting to other languages
1627
+ // especially if tempted to use a general power function
1628
+ return multiplyMatrices(
1629
+ LMStoOKLab,
1630
+ LMS.map((c) => Math.cbrt(c))
1631
+ );
1632
+ // L in range [0,1]. For use in CSS, multiply by 100 and add a percent
1633
+ }
1634
+
1635
+ Color.prototype.oklab = function () {
1636
+ return rgb2oklab(this._rgb);
1637
+ };
1638
+
1639
+ const oklab$1 = (...args) => new Color(...args, 'oklab');
1640
+ Object.assign(chroma, { oklab: oklab$1 });
1641
+
1642
+ input.format.oklab = oklab2rgb;
1643
+
1644
+ input.autodetect.push({
1645
+ p: 2,
1646
+ test: (...args) => {
1647
+ args = unpack(args, 'oklab');
1648
+ if (type(args) === 'array' && args.length === 3) {
1649
+ return 'oklab';
1650
+ }
1651
+ }
1652
+ });
1653
+
1654
+ const oklab = (col1, col2, f) => {
1655
+ const xyz0 = col1.oklab();
1656
+ const xyz1 = col2.oklab();
1657
+ return new Color(
1658
+ xyz0[0] + f * (xyz1[0] - xyz0[0]),
1659
+ xyz0[1] + f * (xyz1[1] - xyz0[1]),
1660
+ xyz0[2] + f * (xyz1[2] - xyz0[2]),
1661
+ 'oklab'
1662
+ );
1663
+ };
1664
+
1665
+ // register interpolator
1666
+ index.oklab = oklab;
1667
+
1668
+ const oklch$1 = (col1, col2, f) => {
1669
+ return interpolate_hsx(col1, col2, f, 'oklch');
1670
+ };
1671
+
1672
+ // register interpolator
1673
+ index.oklch = oklch$1;
1674
+
1675
+ const { pow: pow$4, sqrt: sqrt$1, PI: PI$1, cos: cos$2, sin: sin$2, atan2: atan2$1 } = Math;
1676
+
1677
+ const average = (colors, mode = 'lrgb', weights = null) => {
1678
+ const l = colors.length;
1679
+ if (!weights) weights = Array.from(new Array(l)).map(() => 1);
1680
+ // normalize weights
1681
+ const k =
1682
+ l /
1683
+ weights.reduce(function (a, b) {
1684
+ return a + b;
1685
+ });
1686
+ weights.forEach((w, i) => {
1687
+ weights[i] *= k;
1688
+ });
1689
+ // convert colors to Color objects
1690
+ colors = colors.map((c) => new Color(c));
1691
+ if (mode === 'lrgb') {
1692
+ return _average_lrgb(colors, weights);
1693
+ }
1694
+ const first = colors.shift();
1695
+ const xyz = first.get(mode);
1696
+ const cnt = [];
1697
+ let dx = 0;
1698
+ let dy = 0;
1699
+ // initial color
1700
+ for (let i = 0; i < xyz.length; i++) {
1701
+ xyz[i] = (xyz[i] || 0) * weights[0];
1702
+ cnt.push(isNaN(xyz[i]) ? 0 : weights[0]);
1703
+ if (mode.charAt(i) === 'h' && !isNaN(xyz[i])) {
1704
+ const A = (xyz[i] / 180) * PI$1;
1705
+ dx += cos$2(A) * weights[0];
1706
+ dy += sin$2(A) * weights[0];
1707
+ }
1708
+ }
1709
+
1710
+ let alpha = first.alpha() * weights[0];
1711
+ colors.forEach((c, ci) => {
1712
+ const xyz2 = c.get(mode);
1713
+ alpha += c.alpha() * weights[ci + 1];
1714
+ for (let i = 0; i < xyz.length; i++) {
1715
+ if (!isNaN(xyz2[i])) {
1716
+ cnt[i] += weights[ci + 1];
1717
+ if (mode.charAt(i) === 'h') {
1718
+ const A = (xyz2[i] / 180) * PI$1;
1719
+ dx += cos$2(A) * weights[ci + 1];
1720
+ dy += sin$2(A) * weights[ci + 1];
1721
+ } else {
1722
+ xyz[i] += xyz2[i] * weights[ci + 1];
1723
+ }
1724
+ }
1725
+ }
1726
+ });
1727
+
1728
+ for (let i = 0; i < xyz.length; i++) {
1729
+ if (mode.charAt(i) === 'h') {
1730
+ let A = (atan2$1(dy / cnt[i], dx / cnt[i]) / PI$1) * 180;
1731
+ while (A < 0) A += 360;
1732
+ while (A >= 360) A -= 360;
1733
+ xyz[i] = A;
1734
+ } else {
1735
+ xyz[i] = xyz[i] / cnt[i];
1736
+ }
1737
+ }
1738
+ alpha /= l;
1739
+ return new Color(xyz, mode).alpha(alpha > 0.99999 ? 1 : alpha, true);
1740
+ };
1741
+
1742
+ const _average_lrgb = (colors, weights) => {
1743
+ const l = colors.length;
1744
+ const xyz = [0, 0, 0, 0];
1745
+ for (let i = 0; i < colors.length; i++) {
1746
+ const col = colors[i];
1747
+ const f = weights[i] / l;
1748
+ const rgb = col._rgb;
1749
+ xyz[0] += pow$4(rgb[0], 2) * f;
1750
+ xyz[1] += pow$4(rgb[1], 2) * f;
1751
+ xyz[2] += pow$4(rgb[2], 2) * f;
1752
+ xyz[3] += rgb[3] * f;
1753
+ }
1754
+ xyz[0] = sqrt$1(xyz[0]);
1755
+ xyz[1] = sqrt$1(xyz[1]);
1756
+ xyz[2] = sqrt$1(xyz[2]);
1757
+ if (xyz[3] > 0.9999999) xyz[3] = 1;
1758
+ return new Color(clip_rgb(xyz));
1759
+ };
1760
+
1761
+ // minimal multi-purpose interface
1762
+
1763
+ const { pow: pow$3 } = Math;
1764
+
1765
+ function scale (colors) {
1766
+ // constructor
1767
+ let _mode = 'rgb';
1768
+ let _nacol = chroma('#ccc');
1769
+ let _spread = 0;
1770
+ // const _fixed = false;
1771
+ let _domain = [0, 1];
1772
+ let _pos = [];
1773
+ let _padding = [0, 0];
1774
+ let _classes = false;
1775
+ let _colors = [];
1776
+ let _out = false;
1777
+ let _min = 0;
1778
+ let _max = 1;
1779
+ let _correctLightness = false;
1780
+ let _colorCache = {};
1781
+ let _useCache = true;
1782
+ let _gamma = 1;
1783
+
1784
+ // private methods
1785
+
1786
+ const setColors = function (colors) {
1787
+ colors = colors || ['#fff', '#000'];
1788
+ if (
1789
+ colors &&
1790
+ type(colors) === 'string' &&
1791
+ chroma.brewer &&
1792
+ chroma.brewer[colors.toLowerCase()]
1793
+ ) {
1794
+ colors = chroma.brewer[colors.toLowerCase()];
1795
+ }
1796
+ if (type(colors) === 'array') {
1797
+ // handle single color
1798
+ if (colors.length === 1) {
1799
+ colors = [colors[0], colors[0]];
1800
+ }
1801
+ // make a copy of the colors
1802
+ colors = colors.slice(0);
1803
+ // convert to chroma classes
1804
+ for (let c = 0; c < colors.length; c++) {
1805
+ colors[c] = chroma(colors[c]);
1806
+ }
1807
+ // auto-fill color position
1808
+ _pos.length = 0;
1809
+ for (let c = 0; c < colors.length; c++) {
1810
+ _pos.push(c / (colors.length - 1));
1811
+ }
1812
+ }
1813
+ resetCache();
1814
+ return (_colors = colors);
1815
+ };
1816
+
1817
+ const getClass = function (value) {
1818
+ if (_classes != null) {
1819
+ const n = _classes.length - 1;
1820
+ let i = 0;
1821
+ while (i < n && value >= _classes[i]) {
1822
+ i++;
1823
+ }
1824
+ return i - 1;
1825
+ }
1826
+ return 0;
1827
+ };
1828
+
1829
+ let tMapLightness = (t) => t;
1830
+ let tMapDomain = (t) => t;
1831
+
1832
+ // const classifyValue = function(value) {
1833
+ // let val = value;
1834
+ // if (_classes.length > 2) {
1835
+ // const n = _classes.length-1;
1836
+ // const i = getClass(value);
1837
+ // const minc = _classes[0] + ((_classes[1]-_classes[0]) * (0 + (_spread * 0.5))); // center of 1st class
1838
+ // const maxc = _classes[n-1] + ((_classes[n]-_classes[n-1]) * (1 - (_spread * 0.5))); // center of last class
1839
+ // val = _min + ((((_classes[i] + ((_classes[i+1] - _classes[i]) * 0.5)) - minc) / (maxc-minc)) * (_max - _min));
1840
+ // }
1841
+ // return val;
1842
+ // };
1843
+
1844
+ const getColor = function (val, bypassMap) {
1845
+ let col, t;
1846
+ if (bypassMap == null) {
1847
+ bypassMap = false;
1848
+ }
1849
+ if (isNaN(val) || val === null) {
1850
+ return _nacol;
1851
+ }
1852
+ if (!bypassMap) {
1853
+ if (_classes && _classes.length > 2) {
1854
+ // find the class
1855
+ const c = getClass(val);
1856
+ t = c / (_classes.length - 2);
1857
+ } else if (_max !== _min) {
1858
+ // just interpolate between min/max
1859
+ t = (val - _min) / (_max - _min);
1860
+ } else {
1861
+ t = 1;
1862
+ }
1863
+ } else {
1864
+ t = val;
1865
+ }
1866
+
1867
+ // domain map
1868
+ t = tMapDomain(t);
1869
+
1870
+ if (!bypassMap) {
1871
+ t = tMapLightness(t); // lightness correction
1872
+ }
1873
+
1874
+ if (_gamma !== 1) {
1875
+ t = pow$3(t, _gamma);
1876
+ }
1877
+
1878
+ t = _padding[0] + t * (1 - _padding[0] - _padding[1]);
1879
+
1880
+ t = limit(t, 0, 1);
1881
+
1882
+ const k = Math.floor(t * 10000);
1883
+
1884
+ if (_useCache && _colorCache[k]) {
1885
+ col = _colorCache[k];
1886
+ } else {
1887
+ if (type(_colors) === 'array') {
1888
+ //for i in [0.._pos.length-1]
1889
+ for (let i = 0; i < _pos.length; i++) {
1890
+ const p = _pos[i];
1891
+ if (t <= p) {
1892
+ col = _colors[i];
1893
+ break;
1894
+ }
1895
+ if (t >= p && i === _pos.length - 1) {
1896
+ col = _colors[i];
1897
+ break;
1898
+ }
1899
+ if (t > p && t < _pos[i + 1]) {
1900
+ t = (t - p) / (_pos[i + 1] - p);
1901
+ col = chroma.interpolate(
1902
+ _colors[i],
1903
+ _colors[i + 1],
1904
+ t,
1905
+ _mode
1906
+ );
1907
+ break;
1908
+ }
1909
+ }
1910
+ } else if (type(_colors) === 'function') {
1911
+ col = _colors(t);
1912
+ }
1913
+ if (_useCache) {
1914
+ _colorCache[k] = col;
1915
+ }
1916
+ }
1917
+ return col;
1918
+ };
1919
+
1920
+ var resetCache = () => (_colorCache = {});
1921
+
1922
+ setColors(colors);
1923
+
1924
+ // public interface
1925
+
1926
+ const f = function (v) {
1927
+ const c = chroma(getColor(v));
1928
+ if (_out && c[_out]) {
1929
+ return c[_out]();
1930
+ } else {
1931
+ return c;
1932
+ }
1933
+ };
1934
+
1935
+ f.classes = function (classes) {
1936
+ if (classes != null) {
1937
+ if (type(classes) === 'array') {
1938
+ _classes = classes;
1939
+ _domain = [classes[0], classes[classes.length - 1]];
1940
+ } else {
1941
+ const d = chroma.analyze(_domain);
1942
+ if (classes === 0) {
1943
+ _classes = [d.min, d.max];
1944
+ } else {
1945
+ _classes = chroma.limits(d, 'e', classes);
1946
+ }
1947
+ }
1948
+ return f;
1949
+ }
1950
+ return _classes;
1951
+ };
1952
+
1953
+ f.domain = function (domain) {
1954
+ if (!arguments.length) {
1955
+ return _domain;
1956
+ }
1957
+ _min = domain[0];
1958
+ _max = domain[domain.length - 1];
1959
+ _pos = [];
1960
+ const k = _colors.length;
1961
+ if (domain.length === k && _min !== _max) {
1962
+ // update positions
1963
+ for (let d of Array.from(domain)) {
1964
+ _pos.push((d - _min) / (_max - _min));
1965
+ }
1966
+ } else {
1967
+ for (let c = 0; c < k; c++) {
1968
+ _pos.push(c / (k - 1));
1969
+ }
1970
+ if (domain.length > 2) {
1971
+ // set domain map
1972
+ const tOut = domain.map((d, i) => i / (domain.length - 1));
1973
+ const tBreaks = domain.map((d) => (d - _min) / (_max - _min));
1974
+ if (!tBreaks.every((val, i) => tOut[i] === val)) {
1975
+ tMapDomain = (t) => {
1976
+ if (t <= 0 || t >= 1) return t;
1977
+ let i = 0;
1978
+ while (t >= tBreaks[i + 1]) i++;
1979
+ const f =
1980
+ (t - tBreaks[i]) / (tBreaks[i + 1] - tBreaks[i]);
1981
+ const out = tOut[i] + f * (tOut[i + 1] - tOut[i]);
1982
+ return out;
1983
+ };
1984
+ }
1985
+ }
1986
+ }
1987
+ _domain = [_min, _max];
1988
+ return f;
1989
+ };
1990
+
1991
+ f.mode = function (_m) {
1992
+ if (!arguments.length) {
1993
+ return _mode;
1994
+ }
1995
+ _mode = _m;
1996
+ resetCache();
1997
+ return f;
1998
+ };
1999
+
2000
+ f.range = function (colors, _pos) {
2001
+ setColors(colors);
2002
+ return f;
2003
+ };
2004
+
2005
+ f.out = function (_o) {
2006
+ _out = _o;
2007
+ return f;
2008
+ };
2009
+
2010
+ f.spread = function (val) {
2011
+ if (!arguments.length) {
2012
+ return _spread;
2013
+ }
2014
+ _spread = val;
2015
+ return f;
2016
+ };
2017
+
2018
+ f.correctLightness = function (v) {
2019
+ if (v == null) {
2020
+ v = true;
2021
+ }
2022
+ _correctLightness = v;
2023
+ resetCache();
2024
+ if (_correctLightness) {
2025
+ tMapLightness = function (t) {
2026
+ const L0 = getColor(0, true).lab()[0];
2027
+ const L1 = getColor(1, true).lab()[0];
2028
+ const pol = L0 > L1;
2029
+ let L_actual = getColor(t, true).lab()[0];
2030
+ const L_ideal = L0 + (L1 - L0) * t;
2031
+ let L_diff = L_actual - L_ideal;
2032
+ let t0 = 0;
2033
+ let t1 = 1;
2034
+ let max_iter = 20;
2035
+ while (Math.abs(L_diff) > 1e-2 && max_iter-- > 0) {
2036
+ (function () {
2037
+ if (pol) {
2038
+ L_diff *= -1;
2039
+ }
2040
+ if (L_diff < 0) {
2041
+ t0 = t;
2042
+ t += (t1 - t) * 0.5;
2043
+ } else {
2044
+ t1 = t;
2045
+ t += (t0 - t) * 0.5;
2046
+ }
2047
+ L_actual = getColor(t, true).lab()[0];
2048
+ return (L_diff = L_actual - L_ideal);
2049
+ })();
2050
+ }
2051
+ return t;
2052
+ };
2053
+ } else {
2054
+ tMapLightness = (t) => t;
2055
+ }
2056
+ return f;
2057
+ };
2058
+
2059
+ f.padding = function (p) {
2060
+ if (p != null) {
2061
+ if (type(p) === 'number') {
2062
+ p = [p, p];
2063
+ }
2064
+ _padding = p;
2065
+ return f;
2066
+ } else {
2067
+ return _padding;
2068
+ }
2069
+ };
2070
+
2071
+ f.colors = function (numColors, out) {
2072
+ // If no arguments are given, return the original colors that were provided
2073
+ if (arguments.length < 2) {
2074
+ out = 'hex';
2075
+ }
2076
+ let result = [];
2077
+
2078
+ if (arguments.length === 0) {
2079
+ result = _colors.slice(0);
2080
+ } else if (numColors === 1) {
2081
+ result = [f(0.5)];
2082
+ } else if (numColors > 1) {
2083
+ const dm = _domain[0];
2084
+ const dd = _domain[1] - dm;
2085
+ result = __range__(0, numColors, false).map((i) =>
2086
+ f(dm + (i / (numColors - 1)) * dd)
2087
+ );
2088
+ } else {
2089
+ // returns all colors based on the defined classes
2090
+ colors = [];
2091
+ let samples = [];
2092
+ if (_classes && _classes.length > 2) {
2093
+ for (
2094
+ let i = 1, end = _classes.length, asc = 1 <= end;
2095
+ asc ? i < end : i > end;
2096
+ asc ? i++ : i--
2097
+ ) {
2098
+ samples.push((_classes[i - 1] + _classes[i]) * 0.5);
2099
+ }
2100
+ } else {
2101
+ samples = _domain;
2102
+ }
2103
+ result = samples.map((v) => f(v));
2104
+ }
2105
+
2106
+ if (chroma[out]) {
2107
+ result = result.map((c) => c[out]());
2108
+ }
2109
+ return result;
2110
+ };
2111
+
2112
+ f.cache = function (c) {
2113
+ if (c != null) {
2114
+ _useCache = c;
2115
+ return f;
2116
+ } else {
2117
+ return _useCache;
2118
+ }
2119
+ };
2120
+
2121
+ f.gamma = function (g) {
2122
+ if (g != null) {
2123
+ _gamma = g;
2124
+ return f;
2125
+ } else {
2126
+ return _gamma;
2127
+ }
2128
+ };
2129
+
2130
+ f.nodata = function (d) {
2131
+ if (d != null) {
2132
+ _nacol = chroma(d);
2133
+ return f;
2134
+ } else {
2135
+ return _nacol;
2136
+ }
2137
+ };
2138
+
2139
+ return f;
2140
+ }
2141
+
2142
+ function __range__(left, right, inclusive) {
2143
+ let range = [];
2144
+ let ascending = left < right;
2145
+ let end = !inclusive ? right : ascending ? right + 1 : right - 1;
2146
+ for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
2147
+ range.push(i);
2148
+ }
2149
+ return range;
2150
+ }
2151
+
2152
+ //
2153
+
2154
+ // nth row of the pascal triangle
2155
+ const binom_row = function (n) {
2156
+ let row = [1, 1];
2157
+ for (let i = 1; i < n; i++) {
2158
+ let newrow = [1];
2159
+ for (let j = 1; j <= row.length; j++) {
2160
+ newrow[j] = (row[j] || 0) + row[j - 1];
2161
+ }
2162
+ row = newrow;
2163
+ }
2164
+ return row;
2165
+ };
2166
+
2167
+ const bezier = function (colors) {
2168
+ let I, lab0, lab1, lab2;
2169
+ colors = colors.map((c) => new Color(c));
2170
+ if (colors.length === 2) {
2171
+ // linear interpolation
2172
+ [lab0, lab1] = colors.map((c) => c.lab());
2173
+ I = function (t) {
2174
+ const lab = [0, 1, 2].map((i) => lab0[i] + t * (lab1[i] - lab0[i]));
2175
+ return new Color(lab, 'lab');
2176
+ };
2177
+ } else if (colors.length === 3) {
2178
+ // quadratic bezier interpolation
2179
+ [lab0, lab1, lab2] = colors.map((c) => c.lab());
2180
+ I = function (t) {
2181
+ const lab = [0, 1, 2].map(
2182
+ (i) =>
2183
+ (1 - t) * (1 - t) * lab0[i] +
2184
+ 2 * (1 - t) * t * lab1[i] +
2185
+ t * t * lab2[i]
2186
+ );
2187
+ return new Color(lab, 'lab');
2188
+ };
2189
+ } else if (colors.length === 4) {
2190
+ // cubic bezier interpolation
2191
+ let lab3;
2192
+ [lab0, lab1, lab2, lab3] = colors.map((c) => c.lab());
2193
+ I = function (t) {
2194
+ const lab = [0, 1, 2].map(
2195
+ (i) =>
2196
+ (1 - t) * (1 - t) * (1 - t) * lab0[i] +
2197
+ 3 * (1 - t) * (1 - t) * t * lab1[i] +
2198
+ 3 * (1 - t) * t * t * lab2[i] +
2199
+ t * t * t * lab3[i]
2200
+ );
2201
+ return new Color(lab, 'lab');
2202
+ };
2203
+ } else if (colors.length >= 5) {
2204
+ // general case (degree n bezier)
2205
+ let labs, row, n;
2206
+ labs = colors.map((c) => c.lab());
2207
+ n = colors.length - 1;
2208
+ row = binom_row(n);
2209
+ I = function (t) {
2210
+ const u = 1 - t;
2211
+ const lab = [0, 1, 2].map((i) =>
2212
+ labs.reduce(
2213
+ (sum, el, j) =>
2214
+ sum + row[j] * u ** (n - j) * t ** j * el[i],
2215
+ 0
2216
+ )
2217
+ );
2218
+ return new Color(lab, 'lab');
2219
+ };
2220
+ } else {
2221
+ throw new RangeError('No point in running bezier with only one color.');
2222
+ }
2223
+ return I;
2224
+ };
2225
+
2226
+ const bezier$1 = (colors) => {
2227
+ const f = bezier(colors);
2228
+ f.scale = () => scale(f);
2229
+ return f;
2230
+ };
2231
+
2232
+ const { round: round$3 } = Math;
2233
+
2234
+ Color.prototype.rgb = function (rnd = true) {
2235
+ if (rnd === false) return this._rgb.slice(0, 3);
2236
+ return this._rgb.slice(0, 3).map(round$3);
2237
+ };
2238
+
2239
+ Color.prototype.rgba = function (rnd = true) {
2240
+ return this._rgb.slice(0, 4).map((v, i) => {
2241
+ return i < 3 ? (rnd === false ? v : round$3(v)) : v;
2242
+ });
2243
+ };
2244
+
2245
+ const rgb = (...args) => new Color(...args, 'rgb');
2246
+ Object.assign(chroma, { rgb });
2247
+
2248
+ input.format.rgb = (...args) => {
2249
+ const rgba = unpack(args, 'rgba');
2250
+ if (rgba[3] === undefined) rgba[3] = 1;
2251
+ return rgba;
2252
+ };
2253
+
2254
+ input.autodetect.push({
2255
+ p: 3,
2256
+ test: (...args) => {
2257
+ args = unpack(args, 'rgba');
2258
+ if (
2259
+ type(args) === 'array' &&
2260
+ (args.length === 3 ||
2261
+ (args.length === 4 &&
2262
+ type(args[3]) == 'number' &&
2263
+ args[3] >= 0 &&
2264
+ args[3] <= 1))
2265
+ ) {
2266
+ return 'rgb';
2267
+ }
2268
+ }
2269
+ });
2270
+
2271
+ /*
2272
+ * interpolates between a set of colors uzing a bezier spline
2273
+ * blend mode formulas taken from https://web.archive.org/web/20180110014946/http://www.venture-ware.com/kevin/coding/lets-learn-math-photoshop-blend-modes/
2274
+ */
2275
+
2276
+ const blend = (bottom, top, mode) => {
2277
+ if (!blend[mode]) {
2278
+ throw new Error('unknown blend mode ' + mode);
2279
+ }
2280
+ return blend[mode](bottom, top);
2281
+ };
2282
+
2283
+ const blend_f = (f) => (bottom, top) => {
2284
+ const c0 = chroma(top).rgb();
2285
+ const c1 = chroma(bottom).rgb();
2286
+ return chroma.rgb(f(c0, c1));
2287
+ };
2288
+
2289
+ const each = (f) => (c0, c1) => {
2290
+ const out = [];
2291
+ out[0] = f(c0[0], c1[0]);
2292
+ out[1] = f(c0[1], c1[1]);
2293
+ out[2] = f(c0[2], c1[2]);
2294
+ return out;
2295
+ };
2296
+
2297
+ const normal = (a) => a;
2298
+ const multiply = (a, b) => (a * b) / 255;
2299
+ const darken = (a, b) => (a > b ? b : a);
2300
+ const lighten = (a, b) => (a > b ? a : b);
2301
+ const screen = (a, b) => 255 * (1 - (1 - a / 255) * (1 - b / 255));
2302
+ const overlay = (a, b) =>
2303
+ b < 128 ? (2 * a * b) / 255 : 255 * (1 - 2 * (1 - a / 255) * (1 - b / 255));
2304
+ const burn = (a, b) => 255 * (1 - (1 - b / 255) / (a / 255));
2305
+ const dodge = (a, b) => {
2306
+ if (a === 255) return 255;
2307
+ a = (255 * (b / 255)) / (1 - a / 255);
2308
+ return a > 255 ? 255 : a;
2309
+ };
2310
+
2311
+ // # add = (a,b) ->
2312
+ // # if (a + b > 255) then 255 else a + b
2313
+
2314
+ blend.normal = blend_f(each(normal));
2315
+ blend.multiply = blend_f(each(multiply));
2316
+ blend.screen = blend_f(each(screen));
2317
+ blend.overlay = blend_f(each(overlay));
2318
+ blend.darken = blend_f(each(darken));
2319
+ blend.lighten = blend_f(each(lighten));
2320
+ blend.dodge = blend_f(each(dodge));
2321
+ blend.burn = blend_f(each(burn));
2322
+
2323
+ // cubehelix interpolation
2324
+ const { pow: pow$2, sin: sin$1, cos: cos$1 } = Math;
2325
+
2326
+ function cubehelix (
2327
+ start = 300,
2328
+ rotations = -1.5,
2329
+ hue = 1,
2330
+ gamma = 1,
2331
+ lightness = [0, 1]
2332
+ ) {
2333
+ let dh = 0,
2334
+ dl;
2335
+ if (type(lightness) === 'array') {
2336
+ dl = lightness[1] - lightness[0];
2337
+ } else {
2338
+ dl = 0;
2339
+ lightness = [lightness, lightness];
2340
+ }
2341
+ const f = function (fract) {
2342
+ const a = TWOPI * ((start + 120) / 360 + rotations * fract);
2343
+ const l = pow$2(lightness[0] + dl * fract, gamma);
2344
+ const h = dh !== 0 ? hue[0] + fract * dh : hue;
2345
+ const amp = (h * l * (1 - l)) / 2;
2346
+ const cos_a = cos$1(a);
2347
+ const sin_a = sin$1(a);
2348
+ const r = l + amp * (-0.14861 * cos_a + 1.78277 * sin_a);
2349
+ const g = l + amp * (-0.29227 * cos_a - 0.90649 * sin_a);
2350
+ const b = l + amp * (+1.97294 * cos_a);
2351
+ return chroma(clip_rgb([r * 255, g * 255, b * 255, 1]));
2352
+ };
2353
+ f.start = function (s) {
2354
+ if (s == null) {
2355
+ return start;
2356
+ }
2357
+ start = s;
2358
+ return f;
2359
+ };
2360
+ f.rotations = function (r) {
2361
+ if (r == null) {
2362
+ return rotations;
2363
+ }
2364
+ rotations = r;
2365
+ return f;
2366
+ };
2367
+ f.gamma = function (g) {
2368
+ if (g == null) {
2369
+ return gamma;
2370
+ }
2371
+ gamma = g;
2372
+ return f;
2373
+ };
2374
+ f.hue = function (h) {
2375
+ if (h == null) {
2376
+ return hue;
2377
+ }
2378
+ hue = h;
2379
+ if (type(hue) === 'array') {
2380
+ dh = hue[1] - hue[0];
2381
+ if (dh === 0) {
2382
+ hue = hue[1];
2383
+ }
2384
+ } else {
2385
+ dh = 0;
2386
+ }
2387
+ return f;
2388
+ };
2389
+ f.lightness = function (h) {
2390
+ if (h == null) {
2391
+ return lightness;
2392
+ }
2393
+ if (type(h) === 'array') {
2394
+ lightness = h;
2395
+ dl = h[1] - h[0];
2396
+ } else {
2397
+ lightness = [h, h];
2398
+ dl = 0;
2399
+ }
2400
+ return f;
2401
+ };
2402
+ f.scale = () => chroma.scale(f);
2403
+ f.hue(hue);
2404
+ return f;
2405
+ }
2406
+
2407
+ const digits = '0123456789abcdef';
2408
+
2409
+ const { floor: floor$1, random } = Math;
2410
+
2411
+ const random$1 = () => {
2412
+ let code = '#';
2413
+ for (let i = 0; i < 6; i++) {
2414
+ code += digits.charAt(floor$1(random() * 16));
2415
+ }
2416
+ return new Color(code, 'hex');
2417
+ };
2418
+
2419
+ const { log: log$1, pow: pow$1, floor, abs: abs$1 } = Math;
2420
+
2421
+ function analyze(data, key = null) {
2422
+ const r = {
2423
+ min: Number.MAX_VALUE,
2424
+ max: Number.MAX_VALUE * -1,
2425
+ sum: 0,
2426
+ values: [],
2427
+ count: 0
2428
+ };
2429
+ if (type(data) === 'object') {
2430
+ data = Object.values(data);
2431
+ }
2432
+ data.forEach((val) => {
2433
+ if (key && type(val) === 'object') val = val[key];
2434
+ if (val !== undefined && val !== null && !isNaN(val)) {
2435
+ r.values.push(val);
2436
+ r.sum += val;
2437
+ if (val < r.min) r.min = val;
2438
+ if (val > r.max) r.max = val;
2439
+ r.count += 1;
2440
+ }
2441
+ });
2442
+
2443
+ r.domain = [r.min, r.max];
2444
+
2445
+ r.limits = (mode, num) => limits(r, mode, num);
2446
+
2447
+ return r;
2448
+ }
2449
+
2450
+ function limits(data, mode = 'equal', num = 7) {
2451
+ if (type(data) == 'array') {
2452
+ data = analyze(data);
2453
+ }
2454
+ const { min, max } = data;
2455
+ const values = data.values.sort((a, b) => a - b);
2456
+
2457
+ if (num === 1) {
2458
+ return [min, max];
2459
+ }
2460
+
2461
+ const limits = [];
2462
+
2463
+ if (mode.substr(0, 1) === 'c') {
2464
+ // continuous
2465
+ limits.push(min);
2466
+ limits.push(max);
2467
+ }
2468
+
2469
+ if (mode.substr(0, 1) === 'e') {
2470
+ // equal interval
2471
+ limits.push(min);
2472
+ for (let i = 1; i < num; i++) {
2473
+ limits.push(min + (i / num) * (max - min));
2474
+ }
2475
+ limits.push(max);
2476
+ } else if (mode.substr(0, 1) === 'l') {
2477
+ // log scale
2478
+ if (min <= 0) {
2479
+ throw new Error(
2480
+ 'Logarithmic scales are only possible for values > 0'
2481
+ );
2482
+ }
2483
+ const min_log = Math.LOG10E * log$1(min);
2484
+ const max_log = Math.LOG10E * log$1(max);
2485
+ limits.push(min);
2486
+ for (let i = 1; i < num; i++) {
2487
+ limits.push(pow$1(10, min_log + (i / num) * (max_log - min_log)));
2488
+ }
2489
+ limits.push(max);
2490
+ } else if (mode.substr(0, 1) === 'q') {
2491
+ // quantile scale
2492
+ limits.push(min);
2493
+ for (let i = 1; i < num; i++) {
2494
+ const p = ((values.length - 1) * i) / num;
2495
+ const pb = floor(p);
2496
+ if (pb === p) {
2497
+ limits.push(values[pb]);
2498
+ } else {
2499
+ // p > pb
2500
+ const pr = p - pb;
2501
+ limits.push(values[pb] * (1 - pr) + values[pb + 1] * pr);
2502
+ }
2503
+ }
2504
+ limits.push(max);
2505
+ } else if (mode.substr(0, 1) === 'k') {
2506
+ // k-means clustering
2507
+ /*
2508
+ implementation based on
2509
+ http://code.google.com/p/figue/source/browse/trunk/figue.js#336
2510
+ simplified for 1-d input values
2511
+ */
2512
+ let cluster;
2513
+ const n = values.length;
2514
+ const assignments = new Array(n);
2515
+ const clusterSizes = new Array(num);
2516
+ let repeat = true;
2517
+ let nb_iters = 0;
2518
+ let centroids = null;
2519
+
2520
+ // get seed values
2521
+ centroids = [];
2522
+ centroids.push(min);
2523
+ for (let i = 1; i < num; i++) {
2524
+ centroids.push(min + (i / num) * (max - min));
2525
+ }
2526
+ centroids.push(max);
2527
+
2528
+ while (repeat) {
2529
+ // assignment step
2530
+ for (let j = 0; j < num; j++) {
2531
+ clusterSizes[j] = 0;
2532
+ }
2533
+ for (let i = 0; i < n; i++) {
2534
+ const value = values[i];
2535
+ let mindist = Number.MAX_VALUE;
2536
+ let best;
2537
+ for (let j = 0; j < num; j++) {
2538
+ const dist = abs$1(centroids[j] - value);
2539
+ if (dist < mindist) {
2540
+ mindist = dist;
2541
+ best = j;
2542
+ }
2543
+ clusterSizes[best]++;
2544
+ assignments[i] = best;
2545
+ }
2546
+ }
2547
+
2548
+ // update centroids step
2549
+ const newCentroids = new Array(num);
2550
+ for (let j = 0; j < num; j++) {
2551
+ newCentroids[j] = null;
2552
+ }
2553
+ for (let i = 0; i < n; i++) {
2554
+ cluster = assignments[i];
2555
+ if (newCentroids[cluster] === null) {
2556
+ newCentroids[cluster] = values[i];
2557
+ } else {
2558
+ newCentroids[cluster] += values[i];
2559
+ }
2560
+ }
2561
+ for (let j = 0; j < num; j++) {
2562
+ newCentroids[j] *= 1 / clusterSizes[j];
2563
+ }
2564
+
2565
+ // check convergence
2566
+ repeat = false;
2567
+ for (let j = 0; j < num; j++) {
2568
+ if (newCentroids[j] !== centroids[j]) {
2569
+ repeat = true;
2570
+ break;
2571
+ }
2572
+ }
2573
+
2574
+ centroids = newCentroids;
2575
+ nb_iters++;
2576
+
2577
+ if (nb_iters > 200) {
2578
+ repeat = false;
2579
+ }
2580
+ }
2581
+
2582
+ // finished k-means clustering
2583
+ // the next part is borrowed from gabrielflor.it
2584
+ const kClusters = {};
2585
+ for (let j = 0; j < num; j++) {
2586
+ kClusters[j] = [];
2587
+ }
2588
+ for (let i = 0; i < n; i++) {
2589
+ cluster = assignments[i];
2590
+ kClusters[cluster].push(values[i]);
2591
+ }
2592
+ let tmpKMeansBreaks = [];
2593
+ for (let j = 0; j < num; j++) {
2594
+ tmpKMeansBreaks.push(kClusters[j][0]);
2595
+ tmpKMeansBreaks.push(kClusters[j][kClusters[j].length - 1]);
2596
+ }
2597
+ tmpKMeansBreaks = tmpKMeansBreaks.sort((a, b) => a - b);
2598
+ limits.push(tmpKMeansBreaks[0]);
2599
+ for (let i = 1; i < tmpKMeansBreaks.length; i += 2) {
2600
+ const v = tmpKMeansBreaks[i];
2601
+ if (!isNaN(v) && limits.indexOf(v) === -1) {
2602
+ limits.push(v);
2603
+ }
2604
+ }
2605
+ }
2606
+ return limits;
2607
+ }
2608
+
2609
+ const contrast = (a, b) => {
2610
+ // WCAG contrast ratio
2611
+ // see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
2612
+ a = new Color(a);
2613
+ b = new Color(b);
2614
+ const l1 = a.luminance();
2615
+ const l2 = b.luminance();
2616
+ return l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05);
2617
+ };
2618
+
2619
+ /**
2620
+ * @license
2621
+ *
2622
+ * The APCA contrast prediction algorithm is based of the formulas published
2623
+ * in the APCA-1.0.98G specification by Myndex. The specification is available at:
2624
+ * https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAw3_0.1.17_APCA0.0.98G.svg
2625
+ *
2626
+ * Note that the APCA implementation is still beta, so please update to
2627
+ * future versions of chroma.js when they become available.
2628
+ *
2629
+ * You can read more about the APCA Readability Criterion at
2630
+ * https://readtech.org/ARC/
2631
+ */
2632
+
2633
+ // constants
2634
+ const W_offset = 0.027;
2635
+ const P_in = 0.0005;
2636
+ const P_out = 0.1;
2637
+ const R_scale = 1.14;
2638
+ const B_threshold = 0.022;
2639
+ const B_exp = 1.414;
2640
+
2641
+ const contrastAPCA = (text, bg) => {
2642
+ // parse input colors
2643
+ text = new Color(text);
2644
+ bg = new Color(bg);
2645
+ // if text color has alpha, blend against background
2646
+ if (text.alpha() < 1) {
2647
+ text = mix(bg, text, text.alpha(), 'rgb');
2648
+ }
2649
+ const l_text = lum(...text.rgb());
2650
+ const l_bg = lum(...bg.rgb());
2651
+
2652
+ // soft clamp black levels
2653
+ const Y_text =
2654
+ l_text >= B_threshold
2655
+ ? l_text
2656
+ : l_text + Math.pow(B_threshold - l_text, B_exp);
2657
+ const Y_bg =
2658
+ l_bg >= B_threshold ? l_bg : l_bg + Math.pow(B_threshold - l_bg, B_exp);
2659
+
2660
+ // normal polarity (dark text on light background)
2661
+ const S_norm = Math.pow(Y_bg, 0.56) - Math.pow(Y_text, 0.57);
2662
+ // reverse polarity (light text on dark background)
2663
+ const S_rev = Math.pow(Y_bg, 0.65) - Math.pow(Y_text, 0.62);
2664
+ // clamp noise then scale
2665
+ const C =
2666
+ Math.abs(Y_bg - Y_text) < P_in
2667
+ ? 0
2668
+ : Y_text < Y_bg
2669
+ ? S_norm * R_scale
2670
+ : S_rev * R_scale;
2671
+ // clamp minimum contrast then offset
2672
+ const S_apc = Math.abs(C) < P_out ? 0 : C > 0 ? C - W_offset : C + W_offset;
2673
+ // scale to 100
2674
+ return S_apc * 100;
2675
+ };
2676
+
2677
+ function lum(r, g, b) {
2678
+ return (
2679
+ 0.2126729 * Math.pow(r / 255, 2.4) +
2680
+ 0.7151522 * Math.pow(g / 255, 2.4) +
2681
+ 0.072175 * Math.pow(b / 255, 2.4)
2682
+ );
2683
+ }
2684
+
2685
+ const { sqrt, pow, min, max: max$1, atan2, abs, cos, sin, exp, PI } = Math;
2686
+
2687
+ function deltaE (a, b, Kl = 1, Kc = 1, Kh = 1) {
2688
+ // Delta E (CIE 2000)
2689
+ // see http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CIE2000.html
2690
+ var rad2deg = function (rad) {
2691
+ return (360 * rad) / (2 * PI);
2692
+ };
2693
+ var deg2rad = function (deg) {
2694
+ return (2 * PI * deg) / 360;
2695
+ };
2696
+ a = new Color(a);
2697
+ b = new Color(b);
2698
+ const [L1, a1, b1] = Array.from(a.lab());
2699
+ const [L2, a2, b2] = Array.from(b.lab());
2700
+ const avgL = (L1 + L2) / 2;
2701
+ const C1 = sqrt(pow(a1, 2) + pow(b1, 2));
2702
+ const C2 = sqrt(pow(a2, 2) + pow(b2, 2));
2703
+ const avgC = (C1 + C2) / 2;
2704
+ const G = 0.5 * (1 - sqrt(pow(avgC, 7) / (pow(avgC, 7) + pow(25, 7))));
2705
+ const a1p = a1 * (1 + G);
2706
+ const a2p = a2 * (1 + G);
2707
+ const C1p = sqrt(pow(a1p, 2) + pow(b1, 2));
2708
+ const C2p = sqrt(pow(a2p, 2) + pow(b2, 2));
2709
+ const avgCp = (C1p + C2p) / 2;
2710
+ const arctan1 = rad2deg(atan2(b1, a1p));
2711
+ const arctan2 = rad2deg(atan2(b2, a2p));
2712
+ const h1p = arctan1 >= 0 ? arctan1 : arctan1 + 360;
2713
+ const h2p = arctan2 >= 0 ? arctan2 : arctan2 + 360;
2714
+ const avgHp =
2715
+ abs(h1p - h2p) > 180 ? (h1p + h2p + 360) / 2 : (h1p + h2p) / 2;
2716
+ const T =
2717
+ 1 -
2718
+ 0.17 * cos(deg2rad(avgHp - 30)) +
2719
+ 0.24 * cos(deg2rad(2 * avgHp)) +
2720
+ 0.32 * cos(deg2rad(3 * avgHp + 6)) -
2721
+ 0.2 * cos(deg2rad(4 * avgHp - 63));
2722
+ let deltaHp = h2p - h1p;
2723
+ deltaHp =
2724
+ abs(deltaHp) <= 180
2725
+ ? deltaHp
2726
+ : h2p <= h1p
2727
+ ? deltaHp + 360
2728
+ : deltaHp - 360;
2729
+ deltaHp = 2 * sqrt(C1p * C2p) * sin(deg2rad(deltaHp) / 2);
2730
+ const deltaL = L2 - L1;
2731
+ const deltaCp = C2p - C1p;
2732
+ const sl = 1 + (0.015 * pow(avgL - 50, 2)) / sqrt(20 + pow(avgL - 50, 2));
2733
+ const sc = 1 + 0.045 * avgCp;
2734
+ const sh = 1 + 0.015 * avgCp * T;
2735
+ const deltaTheta = 30 * exp(-pow((avgHp - 275) / 25, 2));
2736
+ const Rc = 2 * sqrt(pow(avgCp, 7) / (pow(avgCp, 7) + pow(25, 7)));
2737
+ const Rt = -Rc * sin(2 * deg2rad(deltaTheta));
2738
+ const result = sqrt(
2739
+ pow(deltaL / (Kl * sl), 2) +
2740
+ pow(deltaCp / (Kc * sc), 2) +
2741
+ pow(deltaHp / (Kh * sh), 2) +
2742
+ Rt * (deltaCp / (Kc * sc)) * (deltaHp / (Kh * sh))
2743
+ );
2744
+ return max$1(0, min(100, result));
2745
+ }
2746
+
2747
+ // simple Euclidean distance
2748
+ function distance (a, b, mode = 'lab') {
2749
+ // Delta E (CIE 1976)
2750
+ // see http://www.brucelindbloom.com/index.html?Equations.html
2751
+ a = new Color(a);
2752
+ b = new Color(b);
2753
+ const l1 = a.get(mode);
2754
+ const l2 = b.get(mode);
2755
+ let sum_sq = 0;
2756
+ for (let i in l1) {
2757
+ const d = (l1[i] || 0) - (l2[i] || 0);
2758
+ sum_sq += d * d;
2759
+ }
2760
+ return Math.sqrt(sum_sq);
2761
+ }
2762
+
2763
+ const valid = (...args) => {
2764
+ try {
2765
+ new Color(...args);
2766
+ return true;
2767
+ // eslint-disable-next-line
2768
+ } catch (e) {
2769
+ return false;
2770
+ }
2771
+ };
2772
+
2773
+ // some pre-defined color scales:
2774
+
2775
+ const scales = {
2776
+ cool() {
2777
+ return scale([chroma.hsl(180, 1, 0.9), chroma.hsl(250, 0.7, 0.4)]);
2778
+ },
2779
+ hot() {
2780
+ return scale(['#000', '#f00', '#ff0', '#fff']).mode(
2781
+ 'rgb'
2782
+ );
2783
+ }
2784
+ };
2785
+
2786
+ /**
2787
+ ColorBrewer colors for chroma.js
2788
+
2789
+ Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The
2790
+ Pennsylvania State University.
2791
+
2792
+ Licensed under the Apache License, Version 2.0 (the "License");
2793
+ you may not use this file except in compliance with the License.
2794
+ You may obtain a copy of the License at
2795
+ http://www.apache.org/licenses/LICENSE-2.0
2796
+
2797
+ Unless required by applicable law or agreed to in writing, software distributed
2798
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
2799
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
2800
+ specific language governing permissions and limitations under the License.
2801
+ */
2802
+
2803
+ const colorbrewer = {
2804
+ // sequential
2805
+ OrRd: ['#fff7ec', '#fee8c8', '#fdd49e', '#fdbb84', '#fc8d59', '#ef6548', '#d7301f', '#b30000', '#7f0000'],
2806
+ PuBu: ['#fff7fb', '#ece7f2', '#d0d1e6', '#a6bddb', '#74a9cf', '#3690c0', '#0570b0', '#045a8d', '#023858'],
2807
+ BuPu: ['#f7fcfd', '#e0ecf4', '#bfd3e6', '#9ebcda', '#8c96c6', '#8c6bb1', '#88419d', '#810f7c', '#4d004b'],
2808
+ Oranges: ['#fff5eb', '#fee6ce', '#fdd0a2', '#fdae6b', '#fd8d3c', '#f16913', '#d94801', '#a63603', '#7f2704'],
2809
+ BuGn: ['#f7fcfd', '#e5f5f9', '#ccece6', '#99d8c9', '#66c2a4', '#41ae76', '#238b45', '#006d2c', '#00441b'],
2810
+ YlOrBr: ['#ffffe5', '#fff7bc', '#fee391', '#fec44f', '#fe9929', '#ec7014', '#cc4c02', '#993404', '#662506'],
2811
+ YlGn: ['#ffffe5', '#f7fcb9', '#d9f0a3', '#addd8e', '#78c679', '#41ab5d', '#238443', '#006837', '#004529'],
2812
+ Reds: ['#fff5f0', '#fee0d2', '#fcbba1', '#fc9272', '#fb6a4a', '#ef3b2c', '#cb181d', '#a50f15', '#67000d'],
2813
+ RdPu: ['#fff7f3', '#fde0dd', '#fcc5c0', '#fa9fb5', '#f768a1', '#dd3497', '#ae017e', '#7a0177', '#49006a'],
2814
+ Greens: ['#f7fcf5', '#e5f5e0', '#c7e9c0', '#a1d99b', '#74c476', '#41ab5d', '#238b45', '#006d2c', '#00441b'],
2815
+ YlGnBu: ['#ffffd9', '#edf8b1', '#c7e9b4', '#7fcdbb', '#41b6c4', '#1d91c0', '#225ea8', '#253494', '#081d58'],
2816
+ Purples: ['#fcfbfd', '#efedf5', '#dadaeb', '#bcbddc', '#9e9ac8', '#807dba', '#6a51a3', '#54278f', '#3f007d'],
2817
+ GnBu: ['#f7fcf0', '#e0f3db', '#ccebc5', '#a8ddb5', '#7bccc4', '#4eb3d3', '#2b8cbe', '#0868ac', '#084081'],
2818
+ Greys: ['#ffffff', '#f0f0f0', '#d9d9d9', '#bdbdbd', '#969696', '#737373', '#525252', '#252525', '#000000'],
2819
+ YlOrRd: ['#ffffcc', '#ffeda0', '#fed976', '#feb24c', '#fd8d3c', '#fc4e2a', '#e31a1c', '#bd0026', '#800026'],
2820
+ PuRd: ['#f7f4f9', '#e7e1ef', '#d4b9da', '#c994c7', '#df65b0', '#e7298a', '#ce1256', '#980043', '#67001f'],
2821
+ Blues: ['#f7fbff', '#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#08519c', '#08306b'],
2822
+ PuBuGn: ['#fff7fb', '#ece2f0', '#d0d1e6', '#a6bddb', '#67a9cf', '#3690c0', '#02818a', '#016c59', '#014636'],
2823
+ Viridis: ['#440154', '#482777', '#3f4a8a', '#31678e', '#26838f', '#1f9d8a', '#6cce5a', '#b6de2b', '#fee825'],
2824
+
2825
+ // diverging
2826
+ Spectral: ['#9e0142', '#d53e4f', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#e6f598', '#abdda4', '#66c2a5', '#3288bd', '#5e4fa2'],
2827
+ RdYlGn: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850', '#006837'],
2828
+ RdBu: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#f7f7f7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac', '#053061'],
2829
+ PiYG: ['#8e0152', '#c51b7d', '#de77ae', '#f1b6da', '#fde0ef', '#f7f7f7', '#e6f5d0', '#b8e186', '#7fbc41', '#4d9221', '#276419'],
2830
+ PRGn: ['#40004b', '#762a83', '#9970ab', '#c2a5cf', '#e7d4e8', '#f7f7f7', '#d9f0d3', '#a6dba0', '#5aae61', '#1b7837', '#00441b'],
2831
+ RdYlBu: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee090', '#ffffbf', '#e0f3f8', '#abd9e9', '#74add1', '#4575b4', '#313695'],
2832
+ BrBG: ['#543005', '#8c510a', '#bf812d', '#dfc27d', '#f6e8c3', '#f5f5f5', '#c7eae5', '#80cdc1', '#35978f', '#01665e', '#003c30'],
2833
+ RdGy: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#ffffff', '#e0e0e0', '#bababa', '#878787', '#4d4d4d', '#1a1a1a'],
2834
+ PuOr: ['#7f3b08', '#b35806', '#e08214', '#fdb863', '#fee0b6', '#f7f7f7', '#d8daeb', '#b2abd2', '#8073ac', '#542788', '#2d004b'],
2835
+
2836
+ // qualitative
2837
+ Set2: ['#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', '#e5c494', '#b3b3b3'],
2838
+ Accent: ['#7fc97f', '#beaed4', '#fdc086', '#ffff99', '#386cb0', '#f0027f', '#bf5b17', '#666666'],
2839
+ Set1: ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'],
2840
+ Set3: ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f'],
2841
+ Dark2: ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02', '#a6761d', '#666666'],
2842
+ Paired: ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928'],
2843
+ Pastel2: ['#b3e2cd', '#fdcdac', '#cbd5e8', '#f4cae4', '#e6f5c9', '#fff2ae', '#f1e2cc', '#cccccc'],
2844
+ Pastel1: ['#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4', '#fed9a6', '#ffffcc', '#e5d8bd', '#fddaec', '#f2f2f2']
2845
+ };
2846
+
2847
+ const colorbrewerTypes = Object.keys(colorbrewer);
2848
+ const typeMap = new Map(colorbrewerTypes.map((key) => [key.toLowerCase(), key]));
2849
+
2850
+ // use Proxy to allow case-insensitive access to palettes
2851
+ const colorbrewerProxy =
2852
+ typeof Proxy === 'function'
2853
+ ? new Proxy(colorbrewer, {
2854
+ get(target, prop) {
2855
+ const lower = prop.toLowerCase();
2856
+ if (typeMap.has(lower)) {
2857
+ return target[typeMap.get(lower)];
2858
+ }
2859
+ },
2860
+ getOwnPropertyNames() {
2861
+ return Object.getOwnPropertyNames(colorbrewerTypes);
2862
+ }
2863
+ })
2864
+ : colorbrewer;
2865
+
2866
+ const cmyk2rgb = (...args) => {
2867
+ args = unpack(args, 'cmyk');
2868
+ const [c, m, y, k] = args;
2869
+ const alpha = args.length > 4 ? args[4] : 1;
2870
+ if (k === 1) return [0, 0, 0, alpha];
2871
+ return [
2872
+ c >= 1 ? 0 : 255 * (1 - c) * (1 - k), // r
2873
+ m >= 1 ? 0 : 255 * (1 - m) * (1 - k), // g
2874
+ y >= 1 ? 0 : 255 * (1 - y) * (1 - k), // b
2875
+ alpha
2876
+ ];
2877
+ };
2878
+
2879
+ const { max } = Math;
2880
+
2881
+ const rgb2cmyk = (...args) => {
2882
+ let [r, g, b] = unpack(args, 'rgb');
2883
+ r = r / 255;
2884
+ g = g / 255;
2885
+ b = b / 255;
2886
+ const k = 1 - max(r, max(g, b));
2887
+ const f = k < 1 ? 1 / (1 - k) : 0;
2888
+ const c = (1 - r - k) * f;
2889
+ const m = (1 - g - k) * f;
2890
+ const y = (1 - b - k) * f;
2891
+ return [c, m, y, k];
2892
+ };
2893
+
2894
+ Color.prototype.cmyk = function () {
2895
+ return rgb2cmyk(this._rgb);
2896
+ };
2897
+
2898
+ const cmyk = (...args) => new Color(...args, 'cmyk');
2899
+ Object.assign(chroma, { cmyk });
2900
+
2901
+ input.format.cmyk = cmyk2rgb;
2902
+
2903
+ input.autodetect.push({
2904
+ p: 2,
2905
+ test: (...args) => {
2906
+ args = unpack(args, 'cmyk');
2907
+ if (type(args) === 'array' && args.length === 4) {
2908
+ return 'cmyk';
2909
+ }
2910
+ }
2911
+ });
2912
+
2913
+ /*
2914
+ * supported arguments:
2915
+ * - hsl2css(h,s,l)
2916
+ * - hsl2css(h,s,l,a)
2917
+ * - hsl2css([h,s,l], mode)
2918
+ * - hsl2css([h,s,l,a], mode)
2919
+ * - hsl2css({h,s,l,a}, mode)
2920
+ */
2921
+ const hsl2css = (...args) => {
2922
+ const hsla = unpack(args, 'hsla');
2923
+ let mode = last(args) || 'lsa';
2924
+ hsla[0] = rnd2(hsla[0] || 0) + 'deg';
2925
+ hsla[1] = rnd2(hsla[1] * 100) + '%';
2926
+ hsla[2] = rnd2(hsla[2] * 100) + '%';
2927
+ if (mode === 'hsla' || (hsla.length > 3 && hsla[3] < 1)) {
2928
+ hsla[3] = '/ ' + (hsla.length > 3 ? hsla[3] : 1);
2929
+ mode = 'hsla';
2930
+ } else {
2931
+ hsla.length = 3;
2932
+ }
2933
+ return `${mode.substr(0, 3)}(${hsla.join(' ')})`;
2934
+ };
2935
+
2936
+ /*
2937
+ * supported arguments:
2938
+ * - lab2css(l,a,b)
2939
+ * - lab2css(l,a,b,alpha)
2940
+ * - lab2css([l,a,b], mode)
2941
+ * - lab2css([l,a,b,alpha], mode)
2942
+ */
2943
+ const lab2css = (...args) => {
2944
+ const laba = unpack(args, 'lab');
2945
+ let mode = last(args) || 'lab';
2946
+ laba[0] = rnd2(laba[0]) + '%';
2947
+ laba[1] = rnd2(laba[1]);
2948
+ laba[2] = rnd2(laba[2]);
2949
+ if (mode === 'laba' || (laba.length > 3 && laba[3] < 1)) {
2950
+ laba[3] = '/ ' + (laba.length > 3 ? laba[3] : 1);
2951
+ } else {
2952
+ laba.length = 3;
2953
+ }
2954
+ return `lab(${laba.join(' ')})`;
2955
+ };
2956
+
2957
+ /*
2958
+ * supported arguments:
2959
+ * - lab2css(l,a,b)
2960
+ * - lab2css(l,a,b,alpha)
2961
+ * - lab2css([l,a,b], mode)
2962
+ * - lab2css([l,a,b,alpha], mode)
2963
+ */
2964
+ const lch2css = (...args) => {
2965
+ const lcha = unpack(args, 'lch');
2966
+ let mode = last(args) || 'lab';
2967
+ lcha[0] = rnd2(lcha[0]) + '%';
2968
+ lcha[1] = rnd2(lcha[1]);
2969
+ lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
2970
+ if (mode === 'lcha' || (lcha.length > 3 && lcha[3] < 1)) {
2971
+ lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
2972
+ } else {
2973
+ lcha.length = 3;
2974
+ }
2975
+ return `lch(${lcha.join(' ')})`;
2976
+ };
2977
+
2978
+ const oklab2css = (...args) => {
2979
+ const laba = unpack(args, 'lab');
2980
+ laba[0] = rnd2(laba[0] * 100) + '%';
2981
+ laba[1] = rnd3(laba[1]);
2982
+ laba[2] = rnd3(laba[2]);
2983
+ if (laba.length > 3 && laba[3] < 1) {
2984
+ laba[3] = '/ ' + (laba.length > 3 ? laba[3] : 1);
2985
+ } else {
2986
+ laba.length = 3;
2987
+ }
2988
+ return `oklab(${laba.join(' ')})`;
2989
+ };
2990
+
2991
+ const rgb2oklch = (...args) => {
2992
+ const [r, g, b, ...rest] = unpack(args, 'rgb');
2993
+ const [l, a, b_] = rgb2oklab(r, g, b);
2994
+ const [L, c, h] = lab2lch(l, a, b_);
2995
+ return [L, c, h, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
2996
+ };
2997
+
2998
+ const oklch2css = (...args) => {
2999
+ const lcha = unpack(args, 'lch');
3000
+ lcha[0] = rnd2(lcha[0] * 100) + '%';
3001
+ lcha[1] = rnd3(lcha[1]);
3002
+ lcha[2] = isNaN(lcha[2]) ? 'none' : rnd2(lcha[2]) + 'deg'; // add deg unit to hue
3003
+ if (lcha.length > 3 && lcha[3] < 1) {
3004
+ lcha[3] = '/ ' + (lcha.length > 3 ? lcha[3] : 1);
3005
+ } else {
3006
+ lcha.length = 3;
3007
+ }
3008
+ return `oklch(${lcha.join(' ')})`;
3009
+ };
3010
+
3011
+ const { round: round$2 } = Math;
3012
+
3013
+ /*
3014
+ * supported arguments:
3015
+ * - rgb2css(r,g,b)
3016
+ * - rgb2css(r,g,b,a)
3017
+ * - rgb2css([r,g,b], mode)
3018
+ * - rgb2css([r,g,b,a], mode)
3019
+ * - rgb2css({r,g,b,a}, mode)
3020
+ */
3021
+ const rgb2css = (...args) => {
3022
+ const rgba = unpack(args, 'rgba');
3023
+ let mode = last(args) || 'rgb';
3024
+ if (mode.substr(0, 3) === 'hsl') {
3025
+ return hsl2css(rgb2hsl$1(rgba), mode);
3026
+ }
3027
+ if (mode.substr(0, 3) === 'lab') {
3028
+ // change to D50 lab whitepoint since this is what W3C is using for CSS Lab colors
3029
+ const prevWhitePoint = getLabWhitePoint();
3030
+ setLabWhitePoint('d50');
3031
+ const cssColor = lab2css(rgb2lab(rgba), mode);
3032
+ setLabWhitePoint(prevWhitePoint);
3033
+ return cssColor;
3034
+ }
3035
+ if (mode.substr(0, 3) === 'lch') {
3036
+ // change to D50 lab whitepoint since this is what W3C is using for CSS Lab colors
3037
+ const prevWhitePoint = getLabWhitePoint();
3038
+ setLabWhitePoint('d50');
3039
+ const cssColor = lch2css(rgb2lch(rgba), mode);
3040
+ setLabWhitePoint(prevWhitePoint);
3041
+ return cssColor;
3042
+ }
3043
+ if (mode.substr(0, 5) === 'oklab') {
3044
+ return oklab2css(rgb2oklab(rgba));
3045
+ }
3046
+ if (mode.substr(0, 5) === 'oklch') {
3047
+ return oklch2css(rgb2oklch(rgba));
3048
+ }
3049
+ rgba[0] = round$2(rgba[0]);
3050
+ rgba[1] = round$2(rgba[1]);
3051
+ rgba[2] = round$2(rgba[2]);
3052
+ if (mode === 'rgba' || (rgba.length > 3 && rgba[3] < 1)) {
3053
+ rgba[3] = '/ ' + (rgba.length > 3 ? rgba[3] : 1);
3054
+ mode = 'rgba';
3055
+ }
3056
+ return `${mode.substr(0, 3)}(${rgba.slice(0, mode === 'rgb' ? 3 : 4).join(' ')})`;
3057
+ };
3058
+
3059
+ const oklch2rgb = (...args) => {
3060
+ args = unpack(args, 'lch');
3061
+ const [l, c, h, ...rest] = args;
3062
+ const [L, a, b_] = lch2lab(l, c, h);
3063
+ const [r, g, b] = oklab2rgb(L, a, b_);
3064
+ return [r, g, b, ...(rest.length > 0 && rest[0] < 1 ? [rest[0]] : [])];
3065
+ };
3066
+
3067
+ const INT_OR_PCT = /((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source;
3068
+ const FLOAT_OR_PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source;
3069
+ const PCT = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source;
3070
+ const RE_S = /\s*/.source;
3071
+ const SEP = /\s+/.source;
3072
+ const COMMA = /\s*,\s*/.source;
3073
+ const ANLGE = /((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source;
3074
+ const ALPHA = /\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source;
3075
+
3076
+ // e.g. rgb(250 20 0), rgb(100% 50% 20%), rgb(100% 50% 20% / 0.5)
3077
+ const RE_RGB = new RegExp(
3078
+ '^rgba?\\(' +
3079
+ RE_S +
3080
+ [INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(SEP) +
3081
+ ALPHA +
3082
+ '\\)$'
3083
+ );
3084
+ const RE_RGB_LEGACY = new RegExp(
3085
+ '^rgb\\(' +
3086
+ RE_S +
3087
+ [INT_OR_PCT, INT_OR_PCT, INT_OR_PCT].join(COMMA) +
3088
+ RE_S +
3089
+ '\\)$'
3090
+ );
3091
+ const RE_RGBA_LEGACY = new RegExp(
3092
+ '^rgba\\(' +
3093
+ RE_S +
3094
+ [INT_OR_PCT, INT_OR_PCT, INT_OR_PCT, FLOAT_OR_PCT].join(COMMA) +
3095
+ RE_S +
3096
+ '\\)$'
3097
+ );
3098
+
3099
+ const RE_HSL = new RegExp(
3100
+ '^hsla?\\(' + RE_S + [ANLGE, PCT, PCT].join(SEP) + ALPHA + '\\)$'
3101
+ );
3102
+ const RE_HSL_LEGACY = new RegExp(
3103
+ '^hsl?\\(' + RE_S + [ANLGE, PCT, PCT].join(COMMA) + RE_S + '\\)$'
3104
+ );
3105
+ const RE_HSLA_LEGACY =
3106
+ /^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/;
3107
+
3108
+ const RE_LAB = new RegExp(
3109
+ '^lab\\(' +
3110
+ RE_S +
3111
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
3112
+ ALPHA +
3113
+ '\\)$'
3114
+ );
3115
+ const RE_LCH = new RegExp(
3116
+ '^lch\\(' +
3117
+ RE_S +
3118
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
3119
+ ALPHA +
3120
+ '\\)$'
3121
+ );
3122
+ const RE_OKLAB = new RegExp(
3123
+ '^oklab\\(' +
3124
+ RE_S +
3125
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, FLOAT_OR_PCT].join(SEP) +
3126
+ ALPHA +
3127
+ '\\)$'
3128
+ );
3129
+ const RE_OKLCH = new RegExp(
3130
+ '^oklch\\(' +
3131
+ RE_S +
3132
+ [FLOAT_OR_PCT, FLOAT_OR_PCT, ANLGE].join(SEP) +
3133
+ ALPHA +
3134
+ '\\)$'
3135
+ );
3136
+
3137
+ const { round: round$1 } = Math;
3138
+
3139
+ const roundRGB = (rgb) => {
3140
+ return rgb.map((v, i) => (i <= 2 ? limit(round$1(v), 0, 255) : v));
3141
+ };
3142
+
3143
+ const percentToAbsolute = (pct, min = 0, max = 100, signed = false) => {
3144
+ if (typeof pct === 'string' && pct.endsWith('%')) {
3145
+ pct = parseFloat(pct.substring(0, pct.length - 1)) / 100;
3146
+ if (signed) {
3147
+ // signed percentages are in the range -100% to 100%
3148
+ pct = min + (pct + 1) * 0.5 * (max - min);
3149
+ } else {
3150
+ pct = min + pct * (max - min);
3151
+ }
3152
+ }
3153
+ return +pct;
3154
+ };
3155
+
3156
+ const noneToValue = (v, noneValue) => {
3157
+ return v === 'none' ? noneValue : v;
3158
+ };
3159
+
3160
+ const css2rgb = (css) => {
3161
+ css = css.toLowerCase().trim();
3162
+
3163
+ if (css === 'transparent') {
3164
+ return [0, 0, 0, 0];
3165
+ }
3166
+
3167
+ let m;
3168
+
3169
+ if (input.format.named) {
3170
+ try {
3171
+ return input.format.named(css);
3172
+ // eslint-disable-next-line
3173
+ } catch (e) {}
3174
+ }
3175
+
3176
+ // rgb(250 20 0) or rgb(250,20,0)
3177
+ if ((m = css.match(RE_RGB)) || (m = css.match(RE_RGB_LEGACY))) {
3178
+ let rgb = m.slice(1, 4);
3179
+ for (let i = 0; i < 3; i++) {
3180
+ rgb[i] = +percentToAbsolute(noneToValue(rgb[i], 0), 0, 255);
3181
+ }
3182
+ rgb = roundRGB(rgb);
3183
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3184
+ rgb[3] = alpha; // default alpha
3185
+ return rgb;
3186
+ }
3187
+
3188
+ // rgba(250,20,0,0.4)
3189
+ if ((m = css.match(RE_RGBA_LEGACY))) {
3190
+ const rgb = m.slice(1, 5);
3191
+ for (let i = 0; i < 4; i++) {
3192
+ rgb[i] = +percentToAbsolute(rgb[i], 0, 255);
3193
+ }
3194
+ return rgb;
3195
+ }
3196
+
3197
+ // hsl(0,100%,50%)
3198
+ if ((m = css.match(RE_HSL)) || (m = css.match(RE_HSL_LEGACY))) {
3199
+ const hsl = m.slice(1, 4);
3200
+ hsl[0] = +noneToValue(hsl[0].replace('deg', ''), 0);
3201
+ hsl[1] = +percentToAbsolute(noneToValue(hsl[1], 0), 0, 100) * 0.01;
3202
+ hsl[2] = +percentToAbsolute(noneToValue(hsl[2], 0), 0, 100) * 0.01;
3203
+ const rgb = roundRGB(hsl2rgb(hsl));
3204
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3205
+ rgb[3] = alpha;
3206
+ return rgb;
3207
+ }
3208
+
3209
+ // hsla(0,100%,50%,0.5)
3210
+ if ((m = css.match(RE_HSLA_LEGACY))) {
3211
+ const hsl = m.slice(1, 4);
3212
+ hsl[1] *= 0.01;
3213
+ hsl[2] *= 0.01;
3214
+ const rgb = hsl2rgb(hsl);
3215
+ for (let i = 0; i < 3; i++) {
3216
+ rgb[i] = round$1(rgb[i]);
3217
+ }
3218
+ rgb[3] = +m[4]; // default alpha = 1
3219
+ return rgb;
3220
+ }
3221
+
3222
+ if ((m = css.match(RE_LAB))) {
3223
+ const lab = m.slice(1, 4);
3224
+ lab[0] = percentToAbsolute(noneToValue(lab[0], 0), 0, 100);
3225
+ lab[1] = percentToAbsolute(noneToValue(lab[1], 0), -125, 125, true);
3226
+ lab[2] = percentToAbsolute(noneToValue(lab[2], 0), -125, 125, true);
3227
+ // convert to D50 Lab whitepoint
3228
+ const wp = getLabWhitePoint();
3229
+ setLabWhitePoint('d50');
3230
+ const rgb = roundRGB(lab2rgb(lab));
3231
+ // convert back to original Lab whitepoint
3232
+ setLabWhitePoint(wp);
3233
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3234
+ rgb[3] = alpha;
3235
+ return rgb;
3236
+ }
3237
+
3238
+ if ((m = css.match(RE_LCH))) {
3239
+ const lch = m.slice(1, 4);
3240
+ lch[0] = percentToAbsolute(lch[0], 0, 100);
3241
+ lch[1] = percentToAbsolute(noneToValue(lch[1], 0), 0, 150, false);
3242
+ lch[2] = +noneToValue(lch[2].replace('deg', ''), 0);
3243
+ // convert to D50 Lab whitepoint
3244
+ const wp = getLabWhitePoint();
3245
+ setLabWhitePoint('d50');
3246
+ const rgb = roundRGB(lch2rgb(lch));
3247
+ // convert back to original Lab whitepoint
3248
+ setLabWhitePoint(wp);
3249
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3250
+ rgb[3] = alpha;
3251
+ return rgb;
3252
+ }
3253
+
3254
+ if ((m = css.match(RE_OKLAB))) {
3255
+ const oklab = m.slice(1, 4);
3256
+ oklab[0] = percentToAbsolute(noneToValue(oklab[0], 0), 0, 1);
3257
+ oklab[1] = percentToAbsolute(noneToValue(oklab[1], 0), -0.4, 0.4, true);
3258
+ oklab[2] = percentToAbsolute(noneToValue(oklab[2], 0), -0.4, 0.4, true);
3259
+ const rgb = roundRGB(oklab2rgb(oklab));
3260
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3261
+ rgb[3] = alpha;
3262
+ return rgb;
3263
+ }
3264
+
3265
+ if ((m = css.match(RE_OKLCH))) {
3266
+ const oklch = m.slice(1, 4);
3267
+ oklch[0] = percentToAbsolute(noneToValue(oklch[0], 0), 0, 1);
3268
+ oklch[1] = percentToAbsolute(noneToValue(oklch[1], 0), 0, 0.4, false);
3269
+ oklch[2] = +noneToValue(oklch[2].replace('deg', ''), 0);
3270
+ const rgb = roundRGB(oklch2rgb(oklch));
3271
+ const alpha = m[4] !== undefined ? +percentToAbsolute(m[4], 0, 1) : 1;
3272
+ rgb[3] = alpha;
3273
+ return rgb;
3274
+ }
3275
+ };
3276
+
3277
+ css2rgb.test = (s) => {
3278
+ return (
3279
+ // modern
3280
+ RE_RGB.test(s) ||
3281
+ RE_HSL.test(s) ||
3282
+ RE_LAB.test(s) ||
3283
+ RE_LCH.test(s) ||
3284
+ RE_OKLAB.test(s) ||
3285
+ RE_OKLCH.test(s) ||
3286
+ // legacy
3287
+ RE_RGB_LEGACY.test(s) ||
3288
+ RE_RGBA_LEGACY.test(s) ||
3289
+ RE_HSL_LEGACY.test(s) ||
3290
+ RE_HSLA_LEGACY.test(s) ||
3291
+ s === 'transparent'
3292
+ );
3293
+ };
3294
+
3295
+ Color.prototype.css = function (mode) {
3296
+ return rgb2css(this._rgb, mode);
3297
+ };
3298
+
3299
+ const css = (...args) => new Color(...args, 'css');
3300
+ chroma.css = css;
3301
+
3302
+ input.format.css = css2rgb;
3303
+
3304
+ input.autodetect.push({
3305
+ p: 5,
3306
+ test: (h, ...rest) => {
3307
+ if (!rest.length && type(h) === 'string' && css2rgb.test(h)) {
3308
+ return 'css';
3309
+ }
3310
+ }
3311
+ });
3312
+
3313
+ input.format.gl = (...args) => {
3314
+ const rgb = unpack(args, 'rgba');
3315
+ rgb[0] *= 255;
3316
+ rgb[1] *= 255;
3317
+ rgb[2] *= 255;
3318
+ return rgb;
3319
+ };
3320
+
3321
+ const gl = (...args) => new Color(...args, 'gl');
3322
+ chroma.gl = gl;
3323
+
3324
+ Color.prototype.gl = function () {
3325
+ const rgb = this._rgb;
3326
+ return [rgb[0] / 255, rgb[1] / 255, rgb[2] / 255, rgb[3]];
3327
+ };
3328
+
3329
+ Color.prototype.hex = function (mode) {
3330
+ return rgb2hex(this._rgb, mode);
3331
+ };
3332
+
3333
+ const hex = (...args) => new Color(...args, 'hex');
3334
+ chroma.hex = hex;
3335
+
3336
+ input.format.hex = hex2rgb;
3337
+ input.autodetect.push({
3338
+ p: 4,
3339
+ test: (h, ...rest) => {
3340
+ if (
3341
+ !rest.length &&
3342
+ type(h) === 'string' &&
3343
+ [3, 4, 5, 6, 7, 8, 9].indexOf(h.length) >= 0
3344
+ ) {
3345
+ return 'hex';
3346
+ }
3347
+ }
3348
+ });
3349
+
3350
+ /*
3351
+ * Based on implementation by Neil Bartlett
3352
+ * https://github.com/neilbartlett/color-temperature
3353
+ */
3354
+
3355
+ const { log } = Math;
3356
+
3357
+ const temperature2rgb = (kelvin) => {
3358
+ const temp = kelvin / 100;
3359
+ let r, g, b;
3360
+ if (temp < 66) {
3361
+ r = 255;
3362
+ g =
3363
+ temp < 6
3364
+ ? 0
3365
+ : -155.25485562709179 -
3366
+ 0.44596950469579133 * (g = temp - 2) +
3367
+ 104.49216199393888 * log(g);
3368
+ b =
3369
+ temp < 20
3370
+ ? 0
3371
+ : -254.76935184120902 +
3372
+ 0.8274096064007395 * (b = temp - 10) +
3373
+ 115.67994401066147 * log(b);
3374
+ } else {
3375
+ r =
3376
+ 351.97690566805693 +
3377
+ 0.114206453784165 * (r = temp - 55) -
3378
+ 40.25366309332127 * log(r);
3379
+ g =
3380
+ 325.4494125711974 +
3381
+ 0.07943456536662342 * (g = temp - 50) -
3382
+ 28.0852963507957 * log(g);
3383
+ b = 255;
3384
+ }
3385
+ return [r, g, b, 1];
3386
+ };
3387
+
3388
+ /*
3389
+ * Based on implementation by Neil Bartlett
3390
+ * https://github.com/neilbartlett/color-temperature
3391
+ **/
3392
+ const { round } = Math;
3393
+
3394
+ const rgb2temperature = (...args) => {
3395
+ const rgb = unpack(args, 'rgb');
3396
+ const r = rgb[0],
3397
+ b = rgb[2];
3398
+ let minTemp = 1000;
3399
+ let maxTemp = 40000;
3400
+ const eps = 0.4;
3401
+ let temp;
3402
+ while (maxTemp - minTemp > eps) {
3403
+ temp = (maxTemp + minTemp) * 0.5;
3404
+ const rgb = temperature2rgb(temp);
3405
+ if (rgb[2] / rgb[0] >= b / r) {
3406
+ maxTemp = temp;
3407
+ } else {
3408
+ minTemp = temp;
3409
+ }
3410
+ }
3411
+ return round(temp);
3412
+ };
3413
+
3414
+ Color.prototype.temp =
3415
+ Color.prototype.kelvin =
3416
+ Color.prototype.temperature =
3417
+ function () {
3418
+ return rgb2temperature(this._rgb);
3419
+ };
3420
+
3421
+ const temp = (...args) => new Color(...args, 'temp');
3422
+ Object.assign(chroma, { temp, kelvin: temp, temperature: temp });
3423
+
3424
+ input.format.temp =
3425
+ input.format.kelvin =
3426
+ input.format.temperature =
3427
+ temperature2rgb;
3428
+
3429
+ Color.prototype.oklch = function () {
3430
+ return rgb2oklch(this._rgb);
3431
+ };
3432
+
3433
+ const oklch = (...args) => new Color(...args, 'oklch');
3434
+ Object.assign(chroma, { oklch });
3435
+
3436
+ input.format.oklch = oklch2rgb;
3437
+
3438
+ input.autodetect.push({
3439
+ p: 2,
3440
+ test: (...args) => {
3441
+ args = unpack(args, 'oklch');
3442
+ if (type(args) === 'array' && args.length === 3) {
3443
+ return 'oklch';
3444
+ }
3445
+ }
3446
+ });
3447
+
3448
+ // feel free to comment out anything to rollup
3449
+
3450
+ Object.assign(chroma, {
3451
+ analyze,
3452
+ average,
3453
+ bezier: bezier$1,
3454
+ blend,
3455
+ brewer: colorbrewerProxy,
3456
+ Color,
3457
+ colors: w3cx11,
3458
+ contrast,
3459
+ contrastAPCA,
3460
+ cubehelix,
3461
+ deltaE,
3462
+ distance,
3463
+ input,
3464
+ interpolate: mix,
3465
+ limits,
3466
+ mix,
3467
+ random: random$1,
3468
+ scale,
3469
+ scales,
3470
+ valid
3471
+ });
3472
+
3473
+ const indexCss = "@import url(\"https://fonts.googleapis.com/css2?family=Figtree:ital,wght@0,300..900;1,300..900&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap\"); .tinting-wrapper *{font-family:\"Poppins\", sans-serif}.my-modal{box-shadow:1px 1px 1px #ccc;background-color:#fff;position:fixed;top:20px;left:50%;transform:translateX(-50%);max-width:1555px;width:90%;z-index:1000;text-align:center;padding:60px 40px;max-height:calc(100vh - 100px);overflow-y:auto;min-height:50vh}@media (max-width: 1024px){.my-modal{padding:40px 20px 20px}}.my-modal::-webkit-scrollbar{display:none}.my-modal .loader{display:flex;flex-direction:column;align-items:center;justify-content:center;height:300px}.my-modal__see-more{font-size:16px;display:flex;justify-content:left;align-items:center;font-weight:300;color:#575757;margin-top:12px;margin-bottom:0px}@media (max-width: 1024px){.my-modal__see-more{font-size:18px}}.my-modal__see-more img{width:45px;height:45px}@media (max-width: 1024px){.my-modal__see-more img{display:none}}.my-modal__see-more.big{font-size:20px;margin-bottom:8px}.my-modal__wrapper{display:flex;flex-direction:column;position:relative}.my-modal__wrapper .not-found{padding:100px 0px}.my-modal__wrapper .boxes{display:flex;flex-direction:column;flex-wrap:wrap}.my-modal__wrapper .boxes__list{display:flex;flex-wrap:wrap;gap:5px 5px}@media (max-width: 1024px){.my-modal__wrapper .boxes__list{justify-content:center}}.my-modal__wrapper .boxes__box-content{width:100%;margin-bottom:5px;height:500px;text-align:left;display:flex;flex-direction:row;justify-content:space-between;position:relative}.my-modal__wrapper .boxes__box-content .closebtn{position:absolute;right:10px;top:10px;width:53px;height:53px;cursor:pointer;object-fit:cover;z-index:9999}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content{flex-direction:column-reverse;height:auto}}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content{margin:0 auto}}.my-modal__wrapper .boxes__box-content__info{width:40%;padding:50px 40px;position:relative}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__info{width:100%;padding:15px;min-height:100px}}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info{min-height:auto}}.my-modal__wrapper .boxes__box-content__info h2{font-size:35px;font-weight:normal;margin-bottom:30px;color:#232323}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info h2{font-size:16px;text-align:center;margin-bottom:15px;margin-top:5px}}.my-modal__wrapper .boxes__box-content__info h4{margin-top:0px;margin-bottom:15px;font-size:16px;color:#4c4c4c}.my-modal__wrapper .boxes__box-content__info .divider{border:1px solid #4c4c4c;opacity:0.2;margin-bottom:20px}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info .divider{margin:10px 0px;display:none}}.my-modal__wrapper .boxes__box-content__info__value{display:flex;flex-direction:row;justify-content:flex-start}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__info__value{justify-content:flex-start}}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info__value{flex-direction:column}}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info__value-image{margin:0 auto;margin-bottom:10px}}.my-modal__wrapper .boxes__box-content__info__value-image img{width:114px;object-fit:cover}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__info__value-image img{width:75px}}.my-modal__wrapper .boxes__box-content__info__value-product{color:#232323;margin-left:10px}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__info__value-product h2{font-size:26px;margin:0;margin-right:10px}}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info__value-product h2{font-size:16px}}.my-modal__wrapper .boxes__box-content__info__value-product p{font-size:20px;margin-top:0px;margin-bottom:0px}.my-modal__wrapper .boxes__box-content__info__value-product p:last-of-type{margin-bottom:20px}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__info__value-product p:last-of-type{margin-bottom:0}}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info__value-product p{font-size:10px}}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__info__value-product>div{display:flex;justify-content:flex-start;align-items:center}}@media (max-width: 768px){.my-modal__wrapper .boxes__box-content__info__value-product>div{flex-direction:column}}.my-modal__wrapper .boxes__box-content__slider{width:60%;min-width:60%;max-width:60%;position:relative}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__slider{width:100%;display:block;min-width:100%;max-width:100%}}.my-modal__wrapper .boxes__box-content__slider .color-big-image{width:100%;height:100%;object-fit:cover}@media (max-width: 1024px){.my-modal__wrapper .boxes__box-content__slider .color-big-image{height:300px}}.my-modal__wrapper .boxes__box-content__white *{color:#fff}.my-modal__wrapper .boxes__box-content__white h2{color:#fff}.my-modal__wrapper .pagination{margin:10px 0px;font-size:16px;display:flex;flex-direction:row;align-items:center;justify-content:center}.my-modal__wrapper .pagination>span{margin:0 3px;cursor:pointer;min-width:20px;padding:5px;box-shadow:1px 1px 1px #ccc}.my-modal__wrapper .pagination .current{background-color:wheat}.my-modal .categories{padding-bottom:20px;margin-bottom:20px;border-bottom:1px solid #dfdfdf;display:flex;flex-direction:column;align-items:flex-start}.my-modal .categories__container{display:flex;flex-wrap:nowrap;gap:5px 5px;overflow-x:auto;width:100%}@media (max-width: 1024px){.my-modal .categories__container{padding-bottom:5px}}.my-modal .categories__slide-information{display:flex;flex-direction:row;align-items:center;justify-content:space-between}.my-modal .categories__slide-information span{color:#4c4c4c;font-size:16px;font-weight:normal}.my-modal .categories__slide-information span:first-of-type{margin-left:7px}.my-modal .categories__slide-information span:last-of-type{margin-right:7px}.my-modal .button,.my-modal a{background-color:#fff;font-size:16px;box-shadow:0px 10px 20px rgba(0, 0, 0, 0.1);border-radius:22px;padding:10px 35px;color:#232323;text-decoration:none;display:block;text-align:center;transition:all 0.7s ease-in-out;border:none;cursor:pointer}.my-modal .button:hover,.my-modal a:hover{color:#fff;background-color:#232323}.my-modal .button.brown,.my-modal a.brown{background-color:#3c2114;color:#fff}.my-modal .button.brown:hover,.my-modal a.brown:hover{color:#fff;background-color:#232323}.my-modal .button.inverse,.my-modal a.inverse{background-color:#232323;color:#fff}.my-modal .button.inverse:hover,.my-modal a.inverse:hover{color:#232323;background-color:#fff}@media (max-width: 1024px){.my-modal .button,.my-modal a{max-width:150px;font-size:13px;padding:12px 25px}}@media (max-width: 768px){.my-modal .button,.my-modal a{margin:0 auto}}.my-modal>.button{margin:10px auto}";
3474
+
3475
+ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
6
3476
  constructor() {
7
3477
  super();
8
3478
  this.__registerHost();
3479
+ this.onSelectedColorEmit = createEvent(this, "onSelectedColorEmit", 7);
3480
+ this.clearSearchText = createEvent(this, "clearSearchText", 7);
3481
+ this.close = createEvent(this, "close", 7);
3482
+ this.readyToCLose = createEvent(this, "readyToCLose", 7);
3483
+ this.boxDesktopWidth = 130;
3484
+ this.boxMobileWidth = 70;
3485
+ this.desktopPadding = 75;
3486
+ this.mobilePadding = 35;
3487
+ this.mediumBreakpoint = 1024;
3488
+ this.clearInterval = () => {
3489
+ this.colorTimerInterval && clearInterval(this.colorTimerInterval);
3490
+ this.colorTimerInterval = undefined;
3491
+ };
3492
+ this.colorTimer = () => {
3493
+ if (this.currentColor && this.currentColor.id) {
3494
+ this.colorTimerInterval = setInterval(() => {
3495
+ var _a, _b;
3496
+ ((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.name) &&
3497
+ setDataLayer({
3498
+ event: 'ColorTimer',
3499
+ shop: this.shop,
3500
+ product: this.product,
3501
+ color: (_b = this.currentColor) === null || _b === void 0 ? void 0 : _b.name,
3502
+ timer: '10',
3503
+ });
3504
+ }, 10000);
3505
+ }
3506
+ else {
3507
+ this.clearInterval();
3508
+ }
3509
+ };
3510
+ this.chunks = (xs, y = []) => {
3511
+ return (xs === null || xs === void 0 ? void 0 : xs.length) === 0 ? y : this.chunks(xs === null || xs === void 0 ? void 0 : xs.slice(this.chunksNum), y.concat([xs === null || xs === void 0 ? void 0 : xs.slice(0, this.chunksNum)]));
3512
+ };
3513
+ this.calculateBoxCount = () => {
3514
+ var _a;
3515
+ const modalWidth = this.modalEl.children && this.modalEl.children[0] && ((_a = this.modalEl.children[0]) === null || _a === void 0 ? void 0 : _a.clientWidth) - this.padding;
3516
+ const boxWidth = this.boxWidth;
3517
+ const calc = Math.floor(modalWidth / boxWidth);
3518
+ const boxesCount = calc;
3519
+ if (!this.preloader)
3520
+ this.chunksNum = boxesCount;
3521
+ };
3522
+ this.displayForMobile = () => {
3523
+ if (window.innerWidth < this.mediumBreakpoint) {
3524
+ this.boxWidth = this.boxMobileWidth;
3525
+ this.padding = this.mobilePadding;
3526
+ this.isMobile = true;
3527
+ }
3528
+ else {
3529
+ this.isMobile = false;
3530
+ this.boxWidth = this.boxDesktopWidth;
3531
+ this.padding = this.desktopPadding;
3532
+ }
3533
+ };
3534
+ this.handleSampleSelect = (selectedSample) => {
3535
+ this.currentColor = null;
3536
+ this.selectedCategory = selectedSample.value;
3537
+ this.updateFilterAndFetch({ sampleId: selectedSample.value, colorFamily: '' });
3538
+ };
3539
+ this.shop = undefined;
3540
+ this.product = undefined;
3541
+ this.baselink = undefined;
3542
+ this.selectedcolor = undefined;
3543
+ this.arrowDown = 'arrow_down.png';
3544
+ this.chunksNum = 12;
3545
+ this.data = null;
3546
+ this.preloader = false;
3547
+ this.loading = false;
3548
+ this.currentColor = null;
3549
+ this.currentIndex = null;
3550
+ this.infoBoxWidth = null;
3551
+ this.boxWidth = this.boxDesktopWidth;
3552
+ this.padding = this.desktopPadding;
3553
+ this.isMobile = false;
3554
+ this.showRange = false;
3555
+ this.colorCategories = null;
3556
+ this.selectedCategory = null;
3557
+ this.page = 1;
3558
+ this.colorIsSelected = false;
3559
+ this.colorsList = [];
3560
+ this.hasMore = true;
3561
+ this.filters = {
3562
+ type: 'product',
3563
+ id: '',
3564
+ productId: '',
3565
+ page: 1,
3566
+ colorNumber: '',
3567
+ colorName: '',
3568
+ };
3569
+ this.debouncedSearchColorsHandler = debounce(this.searchColor.bind(this), 300);
3570
+ }
3571
+ setInfoBoxWidth(newValue) {
3572
+ this.infoBoxWidth = newValue * this.boxWidth;
3573
+ }
3574
+ watchPropHandler(newValue) {
3575
+ if (newValue) {
3576
+ this.filters = updateFilters(this.filters, { id: newValue.id, type: 'product' });
3577
+ this.fetchColorsData();
3578
+ }
3579
+ }
3580
+ async open() {
3581
+ this.modalEl.style.display = 'block';
3582
+ }
3583
+ closeModalHandler() {
3584
+ this.close.emit();
3585
+ }
3586
+ handleReadyToClose(value) {
3587
+ this.readyToCLose.emit({ observable: value });
3588
+ }
3589
+ closeInfoBoxHandler() {
3590
+ this.currentColor = null;
3591
+ this.currentIndex = null;
3592
+ }
3593
+ handleEmitColor(event) {
3594
+ this.onSelectedColorEmit.emit(event.detail);
3595
+ }
3596
+ handleResize() {
3597
+ this.calculateBoxCount();
3598
+ this.displayForMobile();
3599
+ }
3600
+ sortColorsBySimilarity(colors) {
3601
+ if ((colors === null || colors === void 0 ? void 0 : colors.length) <= 1)
3602
+ return colors;
3603
+ const sortedColors = [];
3604
+ const remainingColors = [...colors];
3605
+ // Start with the first color
3606
+ sortedColors.push(remainingColors.shift());
3607
+ while ((remainingColors === null || remainingColors === void 0 ? void 0 : remainingColors.length) > 0) {
3608
+ // Find the most similar color to the last color in sortedColors
3609
+ const lastColor = sortedColors[(sortedColors === null || sortedColors === void 0 ? void 0 : sortedColors.length) - 1];
3610
+ let mostSimilarIndex = 0;
3611
+ let minDistance = Infinity;
3612
+ remainingColors.forEach((color, index) => {
3613
+ const distance = chroma.distance(lastColor.hex, color.hex, 'lab');
3614
+ if (distance < minDistance) {
3615
+ minDistance = distance;
3616
+ mostSimilarIndex = index;
3617
+ }
3618
+ });
3619
+ // Move the most similar color to sortedColors
3620
+ sortedColors.push(remainingColors.splice(mostSimilarIndex, 1)[0]);
3621
+ }
3622
+ return sortedColors;
3623
+ }
3624
+ getColorHueGroup(hex) {
3625
+ if (!hex || !chroma.valid(hex))
3626
+ return 'other';
3627
+ const color = chroma(hex);
3628
+ const hue = color.get('hsl.h');
3629
+ const saturation = color.get('hsl.s');
3630
+ const lightness = color.get('hsl.l');
3631
+ // Handle grayscale colors
3632
+ if (saturation < 0.1) {
3633
+ if (lightness < 0.2)
3634
+ return 'black';
3635
+ if (lightness > 0.8)
3636
+ return 'white';
3637
+ return 'gray';
3638
+ }
3639
+ // Group colors by hue ranges
3640
+ if (hue >= 330 || hue < 30)
3641
+ return 'red';
3642
+ if (hue >= 30 && hue < 90)
3643
+ return 'yellow';
3644
+ if (hue >= 90 && hue < 150)
3645
+ return 'green';
3646
+ if (hue >= 150 && hue < 210)
3647
+ return 'cyan';
3648
+ if (hue >= 210 && hue < 270)
3649
+ return 'blue';
3650
+ if (hue >= 270 && hue < 330)
3651
+ return 'magenta';
3652
+ return 'other';
3653
+ }
3654
+ sortColorsByHueAndSimilarity(colors) {
3655
+ if ((colors === null || colors === void 0 ? void 0 : colors.length) <= 1)
3656
+ return colors;
3657
+ // Separate valid and invalid hex colors
3658
+ const validColors = colors.filter(c => typeof c.hex === 'string' && c.hex && chroma.valid(c.hex));
3659
+ const invalidColors = colors.filter(c => !c.hex || !chroma.valid(c.hex));
3660
+ // Group valid colors by their hue family
3661
+ const colorGroups = {
3662
+ red: [],
3663
+ yellow: [],
3664
+ green: [],
3665
+ cyan: [],
3666
+ blue: [],
3667
+ magenta: [],
3668
+ gray: [],
3669
+ black: [],
3670
+ white: [],
3671
+ other: [],
3672
+ };
3673
+ validColors.forEach(color => {
3674
+ const group = this.getColorHueGroup(color.hex);
3675
+ colorGroups[group].push(color);
3676
+ });
3677
+ // Sort each group by similarity
3678
+ const sortedGroups = [];
3679
+ const groupOrder = ['red', 'magenta', 'blue', 'cyan', 'green', 'yellow', 'gray', 'black', 'white', 'other'];
3680
+ groupOrder.forEach(groupName => {
3681
+ if (colorGroups[groupName].length > 0) {
3682
+ sortedGroups.push(this.sortColorsBySimilarity(colorGroups[groupName]));
3683
+ }
3684
+ });
3685
+ // Combine all sorted groups, then append invalid colors at the end
3686
+ return [...sortedGroups.flat(), ...invalidColors];
3687
+ }
3688
+ async fetchColorsData({ reset = false } = {}) {
3689
+ if (this.loading)
3690
+ return;
3691
+ this.loading = true;
3692
+ try {
3693
+ const colors = await fetchColors(this.filters);
3694
+ if (reset) {
3695
+ // For new searches, sort all colors by hue and similarity
3696
+ this.colorsList = this.sortColorsByHueAndSimilarity(colors);
3697
+ }
3698
+ else {
3699
+ // For pagination, combine and sort all colors
3700
+ this.colorsList = this.sortColorsByHueAndSimilarity([...this.colorsList, ...colors]);
3701
+ }
3702
+ this.hasMore = colors.length >= limit$1;
3703
+ }
3704
+ catch (error) {
3705
+ console.error('Error fetching colors:', error);
3706
+ }
3707
+ finally {
3708
+ this.loading = false;
3709
+ }
3710
+ }
3711
+ async loadProductData() {
3712
+ this.preloader = true;
3713
+ const product = await fetchProductData({ shopName: this.shop, productName: this.product });
3714
+ if (product) {
3715
+ this.data = product;
3716
+ this.filters = updateFilters(this.filters, { type: 'product', id: product.id });
3717
+ // Fetch initial colors
3718
+ await this.fetchColorsData();
3719
+ }
3720
+ this.preloader = false;
3721
+ }
3722
+ async loadMoreColors() {
3723
+ if (this.loading || !this.hasMore)
3724
+ return; // Prevent spam loading
3725
+ this.filters = Object.assign(Object.assign({}, this.filters), { page: this.filters.page + 1 }); // Increase page for lazy loading
3726
+ await this.fetchColorsData({ reset: false }); // Append results
3727
+ }
3728
+ updateFilterAndFetch(newFilters) {
3729
+ var _a;
3730
+ if (!((_a = this.data) === null || _a === void 0 ? void 0 : _a.id))
3731
+ return;
3732
+ this.loading = true;
3733
+ this.filters = updateFilters(this.filters, Object.assign(Object.assign({ id: this.data.id, sampleId: this.filters.sampleId, colorName: this.filters.colorName }, newFilters), { page: 1 }));
3734
+ this.fetchColorsData({ reset: true }).finally(() => {
3735
+ this.loading = false;
3736
+ });
3737
+ }
3738
+ async searchColor(event) {
3739
+ var _a;
3740
+ const query = (_a = event.detail) === null || _a === void 0 ? void 0 : _a.trim();
3741
+ this.updateFilterAndFetch({ colorName: query });
3742
+ }
3743
+ handleColorFamilySelected(event) {
3744
+ this.currentColor = null;
3745
+ if (event.detail === this.filters.colorFamily) {
3746
+ this.filters = updateFilters(this.filters, { colorFamily: '' });
3747
+ this.updateFilterAndFetch({ colorFamily: '' });
3748
+ }
3749
+ else {
3750
+ this.filters = updateFilters(this.filters, { colorFamily: event.detail });
3751
+ this.updateFilterAndFetch({ colorFamily: event.detail });
3752
+ }
3753
+ }
3754
+ searchColorsHandler(event) {
3755
+ this.loading = true;
3756
+ this.currentColor = null;
3757
+ this.debouncedSearchColorsHandler(event);
3758
+ }
3759
+ handleScroll(_event, modalContent) {
3760
+ if (this.loading || !this.hasMore)
3761
+ return;
3762
+ const scrollTop = modalContent.scrollTop;
3763
+ const scrollHeight = modalContent.scrollHeight;
3764
+ const clientHeight = modalContent.clientHeight;
3765
+ // Check if user scrolled to the bottom of the modal
3766
+ if (scrollTop + clientHeight >= scrollHeight - 50) {
3767
+ this.loadMoreColors();
3768
+ }
3769
+ }
3770
+ openSeletedColor() {
3771
+ var _a, _b;
3772
+ if (!this.colorsList || !this.selectedcolor)
3773
+ return;
3774
+ if (!this.colorIsSelected) {
3775
+ const result = this.chunks(this.colorsList)
3776
+ .map((innerArray, arrayIndex) => {
3777
+ const foundColor = innerArray.find(color => { var _a, _b, _c; return ((_a = color.name.trim()) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === ((_c = (_b = this.selectedcolor) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.toUpperCase()); });
3778
+ return foundColor ? { color: foundColor, index: arrayIndex } : null;
3779
+ })
3780
+ .filter(item => item !== null);
3781
+ this.currentColor = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.color;
3782
+ this.currentIndex = (_b = result[0]) === null || _b === void 0 ? void 0 : _b.index;
3783
+ this.colorIsSelected = true;
3784
+ }
3785
+ }
3786
+ componentWillLoad() {
3787
+ this.preloader = true;
3788
+ setDataLayer({
3789
+ shop: this.shop,
3790
+ product: this.product,
3791
+ });
3792
+ this.loadProductData();
3793
+ }
3794
+ componentWillRender() {
3795
+ this.displayForMobile();
3796
+ this.calculateBoxCount();
3797
+ this.colorTimer();
3798
+ this.openSeletedColor();
3799
+ const modalContent = this.modalEl.querySelector('.my-modal');
3800
+ if (modalContent) {
3801
+ modalContent.addEventListener('scroll', event => this.handleScroll(event, modalContent));
3802
+ }
3803
+ }
3804
+ resetColors() {
3805
+ this.currentColor = null;
3806
+ this.currentIndex = null;
3807
+ this.colorIsSelected = false;
3808
+ }
3809
+ resetAllFilters() {
3810
+ var _a;
3811
+ // Reset current color selection
3812
+ this.resetColors();
3813
+ // Reset filters to initial state
3814
+ this.filters = {
3815
+ type: 'product',
3816
+ id: ((_a = this.data) === null || _a === void 0 ? void 0 : _a.id) || '',
3817
+ productId: '',
3818
+ page: 1,
3819
+ colorNumber: '',
3820
+ colorName: '',
3821
+ colorFamily: '',
3822
+ sampleId: '',
3823
+ };
3824
+ // Reset selected category
3825
+ this.selectedCategory = null;
3826
+ // Clear search text
3827
+ this.clearSearchText.emit();
3828
+ // Fetch colors with reset filters
3829
+ this.fetchColorsData({ reset: true });
3830
+ }
3831
+ resetSelectedCategory() {
3832
+ this.resetColors();
3833
+ this.colorIsSelected = false;
3834
+ this.selectedCategory = null;
3835
+ this.filters = updateFilters(this.filters, { sampleId: '' });
3836
+ this.fetchColorsData({ reset: true });
9
3837
  }
10
3838
  render() {
11
- return (h("div", { class: "container" }, h("div", { class: "item" }), h("div", { class: "item" }), h("div", { class: "item" }), h("div", { class: "item" }), h("div", { class: "item" })));
3839
+ var _a;
3840
+ return (h("div", { class: `my-modal`, onMouseEnter: () => this.handleReadyToClose(false), onMouseLeave: () => this.handleReadyToClose(true) }, this.preloader && (h("div", { class: 'loader' }, h("my-loader", null))), !this.preloader && this.data && (h("modal-header", { modalName: this.data.modalName, modalLogo: this.data.modalLogo ? `${APIURL}/assets/${this.data.modalLogo}?access_token=${accessToken}` : null, modalDescription: this.data.modalDescription, shop: this.shop, productName: this.data.name, productSamples: this.data.productSamples, selectedColorFamily: this.filters.colorFamily, isMobile: this.isMobile, onCloseModal: () => this.closeModalHandler(), onSampleSelected: event => this.handleSampleSelect(event.detail), onOnLogoClick: () => this.resetAllFilters(), onOnResetCategory: () => this.resetSelectedCategory() })), h("div", { class: 'my-modal__wrapper' }, !this.preloader && (h("div", { class: 'container_boxes' }, !this.loading && this.colorsList.length === 0 && (h("div", { class: "not-found" }, h("p", null, "Nie zaleziono wynik\u00F3w wyszukiwania pod danym has\u0142em."), h("p", null, " Wpisz inn\u0105 nazw\u0119 b\u0105d\u017A numer koloru lub skorzystaj z kolekcji kolorystycznych."))), ((_a = this.colorsList) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
3841
+ this.chunks(this.colorsList).map((color, index) => {
3842
+ var _a;
3843
+ return (h("div", { key: index, class: "boxes" }, h("div", { class: "boxes__list" }, color.map((c) => {
3844
+ var _a;
3845
+ return (h("my-colorbox", { key: c.id, onClick: () => {
3846
+ var _a;
3847
+ if (((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.id) === c.id) {
3848
+ this.currentColor = null;
3849
+ }
3850
+ else {
3851
+ this.currentColor = c;
3852
+ }
3853
+ this.currentIndex = index;
3854
+ setDataLayer({
3855
+ event: 'ColorClick',
3856
+ shop: this.shop,
3857
+ product: this.product,
3858
+ color: c.name,
3859
+ });
3860
+ this.clearInterval();
3861
+ }, color: c.hex, name: c.name, isActive: ((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.id) === c.id, shop: this.shop, product: this.product, isImageInsteadHex: {
3862
+ isImageInsteadHex: c.imageInsteadHex,
3863
+ bigImage: c.bigImage,
3864
+ } }));
3865
+ })), ((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.id) && index === this.currentIndex && (h("my-colorinfo", { currentColor: this.currentColor, shop: this.shop, product: this.product, data: this.data, isMobile: this.isMobile, infoBoxWidth: this.infoBoxWidth, baselink: this.baselink }))));
3866
+ }))), this.loading && h("my-loader", null)), !this.preloader && this.isMobile && (h("button", { class: "button", onClick: () => this.closeModalHandler() }, "Zamknij"))));
12
3867
  }
3868
+ static get assetsDirs() { return ["assets"]; }
3869
+ get modalEl() { return this; }
3870
+ static get watchers() { return {
3871
+ "chunksNum": ["setInfoBoxWidth"],
3872
+ "data": ["watchPropHandler"]
3873
+ }; }
13
3874
  static get style() { return indexCss; }
14
- }, [2, "my-loader"]);
3875
+ }, [0, "my-modal", {
3876
+ "shop": [1],
3877
+ "product": [1],
3878
+ "baselink": [1],
3879
+ "selectedcolor": [1],
3880
+ "arrowDown": [1, "arrow-down"],
3881
+ "chunksNum": [32],
3882
+ "data": [32],
3883
+ "preloader": [32],
3884
+ "loading": [32],
3885
+ "currentColor": [32],
3886
+ "currentIndex": [32],
3887
+ "infoBoxWidth": [32],
3888
+ "boxWidth": [32],
3889
+ "padding": [32],
3890
+ "isMobile": [32],
3891
+ "showRange": [32],
3892
+ "colorCategories": [32],
3893
+ "selectedCategory": [32],
3894
+ "page": [32],
3895
+ "colorIsSelected": [32],
3896
+ "colorsList": [32],
3897
+ "hasMore": [32],
3898
+ "filters": [32],
3899
+ "open": [64]
3900
+ }, [[0, "closeInfoBox", "closeInfoBoxHandler"], [0, "onCurrentColor", "handleEmitColor"], [9, "resize", "handleResize"], [0, "colorFamilySelected", "handleColorFamilySelected"], [0, "searchColors", "searchColorsHandler"]]]);
15
3901
  function defineCustomElement() {
16
3902
  if (typeof customElements === "undefined") {
17
3903
  return;
18
3904
  }
19
- const components = ["my-loader"];
3905
+ const components = ["my-modal", "modal-header", "my-colorbox", "my-colorinfo", "my-search", "my-select", "my-slider"];
20
3906
  components.forEach(tagName => { switch (tagName) {
21
- case "my-loader":
3907
+ case "my-modal":
3908
+ if (!customElements.get(tagName)) {
3909
+ customElements.define(tagName, Modal);
3910
+ }
3911
+ break;
3912
+ case "modal-header":
3913
+ if (!customElements.get(tagName)) {
3914
+ defineCustomElement$6();
3915
+ }
3916
+ break;
3917
+ case "my-colorbox":
3918
+ if (!customElements.get(tagName)) {
3919
+ defineCustomElement$5();
3920
+ }
3921
+ break;
3922
+ case "my-colorinfo":
3923
+ if (!customElements.get(tagName)) {
3924
+ defineCustomElement$4();
3925
+ }
3926
+ break;
3927
+ case "my-search":
3928
+ if (!customElements.get(tagName)) {
3929
+ defineCustomElement$3();
3930
+ }
3931
+ break;
3932
+ case "my-select":
3933
+ if (!customElements.get(tagName)) {
3934
+ defineCustomElement$2();
3935
+ }
3936
+ break;
3937
+ case "my-slider":
22
3938
  if (!customElements.get(tagName)) {
23
- customElements.define(tagName, MyLoader);
3939
+ defineCustomElement$1();
24
3940
  }
25
3941
  break;
26
3942
  } });
27
3943
  }
28
3944
 
29
- export { MyLoader as M, defineCustomElement as d };
3945
+ export { Modal as M, defineCustomElement as d };
30
3946
 
31
3947
  //# sourceMappingURL=index10.js.map