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