@likec4/core 1.19.1 → 1.20.0

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