@thednp/color-picker 0.0.2-alpha1 → 0.0.2-alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/js/color-esm.js +94 -105
- package/dist/js/color-esm.min.js +2 -2
- package/dist/js/color-palette-esm.js +105 -119
- package/dist/js/color-palette-esm.min.js +2 -2
- package/dist/js/color-palette.js +105 -119
- package/dist/js/color-palette.min.js +2 -2
- package/dist/js/color-picker-element-esm.js +279 -375
- package/dist/js/color-picker-element-esm.min.js +2 -2
- package/dist/js/color-picker-element.js +279 -375
- package/dist/js/color-picker-element.min.js +2 -2
- package/dist/js/color-picker-esm.js +235 -323
- package/dist/js/color-picker-esm.min.js +2 -2
- package/dist/js/color-picker.js +235 -323
- package/dist/js/color-picker.min.js +2 -2
- package/dist/js/color.js +94 -105
- package/dist/js/color.min.js +2 -2
- package/package.json +7 -4
- package/src/js/color-palette.js +10 -13
- package/src/js/color-picker-element.js +46 -54
- package/src/js/color-picker.js +131 -206
- package/src/js/color.js +93 -106
- package/types/cp.d.ts +31 -29
- package/types/source/types.d.ts +1 -1
package/dist/js/color-palette.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* ColorPalette v0.0.
|
2
|
+
* ColorPalette v0.0.2alpha2 (http://thednp.github.io/color-picker)
|
3
3
|
* Copyright 2022 © thednp
|
4
4
|
* Licensed under MIT (https://github.com/thednp/color-picker/blob/master/LICENSE)
|
5
5
|
*/
|
@@ -147,6 +147,8 @@
|
|
147
147
|
if (nonColors.includes(color)
|
148
148
|
|| ['#', ...COLOR_FORMAT].some((f) => color.includes(f))) return false;
|
149
149
|
|
150
|
+
if (['black', 'white'].includes(color)) return true;
|
151
|
+
|
150
152
|
return ['rgb(255, 255, 255)', 'rgb(0, 0, 0)'].every((c) => {
|
151
153
|
setElementStyle(documentHead, { color });
|
152
154
|
const computedColor = getElementStyle(documentHead, 'color');
|
@@ -173,6 +175,11 @@
|
|
173
175
|
*/
|
174
176
|
function bound01(N, max) {
|
175
177
|
let n = N;
|
178
|
+
|
179
|
+
if (typeof N === 'number'
|
180
|
+
&& Math.min(N, 0) === 0 // round values to 6 decimals Math.round(N * (10 ** 6)) / 10 ** 6
|
181
|
+
&& Math.max(N, 1) === 1) return N;
|
182
|
+
|
176
183
|
if (isOnePointZero(N)) n = '100%';
|
177
184
|
|
178
185
|
const processPercent = isPercentage(n);
|
@@ -276,15 +283,12 @@
|
|
276
283
|
/**
|
277
284
|
* Converts an RGB colour value to HSL.
|
278
285
|
*
|
279
|
-
* @param {number}
|
280
|
-
* @param {number}
|
281
|
-
* @param {number}
|
286
|
+
* @param {number} r Red component [0, 1]
|
287
|
+
* @param {number} g Green component [0, 1]
|
288
|
+
* @param {number} b Blue component [0, 1]
|
282
289
|
* @returns {CP.HSL} {h,s,l} object with [0, 1] ranged values
|
283
290
|
*/
|
284
|
-
function rgbToHsl(
|
285
|
-
const r = R / 255;
|
286
|
-
const g = G / 255;
|
287
|
-
const b = B / 255;
|
291
|
+
function rgbToHsl(r, g, b) {
|
288
292
|
const max = Math.max(r, g, b);
|
289
293
|
const min = Math.min(r, g, b);
|
290
294
|
let h = 0;
|
@@ -296,17 +300,10 @@
|
|
296
300
|
} else {
|
297
301
|
const d = max - min;
|
298
302
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
case g:
|
304
|
-
h = (b - r) / d + 2;
|
305
|
-
break;
|
306
|
-
case b:
|
307
|
-
h = (r - g) / d + 4;
|
308
|
-
break;
|
309
|
-
}
|
303
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
304
|
+
if (max === g) h = (b - r) / d + 2;
|
305
|
+
if (max === b) h = (r - g) / d + 4;
|
306
|
+
|
310
307
|
h /= 6;
|
311
308
|
}
|
312
309
|
return { h, s, l };
|
@@ -335,7 +332,7 @@
|
|
335
332
|
* @param {number} h Hue Angle [0, 1]
|
336
333
|
* @param {number} s Saturation [0, 1]
|
337
334
|
* @param {number} l Lightness Angle [0, 1]
|
338
|
-
* @returns {CP.RGB} {r,g,b} object with [0,
|
335
|
+
* @returns {CP.RGB} {r,g,b} object with [0, 1] ranged values
|
339
336
|
*/
|
340
337
|
function hslToRgb(h, s, l) {
|
341
338
|
let r = 0;
|
@@ -354,7 +351,6 @@
|
|
354
351
|
g = hueToRgb(p, q, h);
|
355
352
|
b = hueToRgb(p, q, h - 1 / 3);
|
356
353
|
}
|
357
|
-
[r, g, b] = [r, g, b].map((x) => x * 255);
|
358
354
|
|
359
355
|
return { r, g, b };
|
360
356
|
}
|
@@ -364,16 +360,12 @@
|
|
364
360
|
* @link https://www.w3.org/TR/css-color-4/#hwb-to-rgb
|
365
361
|
* @link http://alvyray.com/Papers/CG/hwb2rgb.htm
|
366
362
|
*
|
367
|
-
* @param {number}
|
368
|
-
* @param {number}
|
369
|
-
* @param {number}
|
363
|
+
* @param {number} r Red component [0, 1]
|
364
|
+
* @param {number} g Green [0, 1]
|
365
|
+
* @param {number} b Blue [0, 1]
|
370
366
|
* @return {CP.HWB} {h,w,b} object with [0, 1] ranged values
|
371
367
|
*/
|
372
|
-
function rgbToHwb(
|
373
|
-
const r = R / 255;
|
374
|
-
const g = G / 255;
|
375
|
-
const b = B / 255;
|
376
|
-
|
368
|
+
function rgbToHwb(r, g, b) {
|
377
369
|
let f = 0;
|
378
370
|
let i = 0;
|
379
371
|
const whiteness = Math.min(r, g, b);
|
@@ -403,20 +395,18 @@
|
|
403
395
|
* @param {number} H Hue Angle [0, 1]
|
404
396
|
* @param {number} W Whiteness [0, 1]
|
405
397
|
* @param {number} B Blackness [0, 1]
|
406
|
-
* @return {CP.RGB} {r,g,b} object with [0,
|
398
|
+
* @return {CP.RGB} {r,g,b} object with [0, 1] ranged values
|
407
399
|
*
|
408
400
|
* @link https://www.w3.org/TR/css-color-4/#hwb-to-rgb
|
409
401
|
* @link http://alvyray.com/Papers/CG/hwb2rgb.htm
|
410
402
|
*/
|
411
403
|
function hwbToRgb(H, W, B) {
|
412
404
|
if (W + B >= 1) {
|
413
|
-
const gray =
|
405
|
+
const gray = W / (W + B);
|
414
406
|
return { r: gray, g: gray, b: gray };
|
415
407
|
}
|
416
408
|
let { r, g, b } = hslToRgb(H, 1, 0.5);
|
417
|
-
[r, g, b] = [r, g, b]
|
418
|
-
.map((v) => (v / 255) * (1 - W - B) + W)
|
419
|
-
.map((v) => v * 255);
|
409
|
+
[r, g, b] = [r, g, b].map((v) => v * (1 - W - B) + W);
|
420
410
|
|
421
411
|
return { r, g, b };
|
422
412
|
}
|
@@ -424,15 +414,12 @@
|
|
424
414
|
/**
|
425
415
|
* Converts an RGB colour value to HSV.
|
426
416
|
*
|
427
|
-
* @param {number}
|
428
|
-
* @param {number}
|
429
|
-
* @param {number}
|
417
|
+
* @param {number} r Red component [0, 1]
|
418
|
+
* @param {number} g Green [0, 1]
|
419
|
+
* @param {number} b Blue [0, 1]
|
430
420
|
* @returns {CP.HSV} {h,s,v} object with [0, 1] ranged values
|
431
421
|
*/
|
432
|
-
function rgbToHsv(
|
433
|
-
const r = R / 255;
|
434
|
-
const g = G / 255;
|
435
|
-
const b = B / 255;
|
422
|
+
function rgbToHsv(r, g, b) {
|
436
423
|
const max = Math.max(r, g, b);
|
437
424
|
const min = Math.min(r, g, b);
|
438
425
|
let h = 0;
|
@@ -442,17 +429,10 @@
|
|
442
429
|
if (max === min) {
|
443
430
|
h = 0; // achromatic
|
444
431
|
} else {
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
case g:
|
450
|
-
h = (b - r) / d + 2;
|
451
|
-
break;
|
452
|
-
case b:
|
453
|
-
h = (r - g) / d + 4;
|
454
|
-
break;
|
455
|
-
}
|
432
|
+
if (r === max) h = (g - b) / d + (g < b ? 6 : 0);
|
433
|
+
if (g === max) h = (b - r) / d + 2;
|
434
|
+
if (b === max) h = (r - g) / d + 4;
|
435
|
+
|
456
436
|
h /= 6;
|
457
437
|
}
|
458
438
|
return { h, s, v };
|
@@ -476,10 +456,9 @@
|
|
476
456
|
const q = v * (1 - f * s);
|
477
457
|
const t = v * (1 - (1 - f) * s);
|
478
458
|
const mod = i % 6;
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
[r, g, b] = [r, g, b].map((n) => n * 255);
|
459
|
+
const r = [v, q, p, p, t, v][mod];
|
460
|
+
const g = [t, v, v, q, p, p][mod];
|
461
|
+
const b = [p, p, t, v, v, q][mod];
|
483
462
|
return { r, g, b };
|
484
463
|
}
|
485
464
|
|
@@ -547,15 +526,15 @@
|
|
547
526
|
*/
|
548
527
|
function stringInputToObject(input) {
|
549
528
|
let color = toLowerCase(input.trim());
|
529
|
+
|
550
530
|
if (color.length === 0) {
|
551
531
|
return {
|
552
532
|
r: 0, g: 0, b: 0, a: 1,
|
553
533
|
};
|
554
534
|
}
|
555
|
-
|
535
|
+
|
556
536
|
if (isColorName(color)) {
|
557
537
|
color = getRGBFromName(color);
|
558
|
-
named = true;
|
559
538
|
} else if (nonColors.includes(color)) {
|
560
539
|
const a = color === 'transparent' ? 0 : 1;
|
561
540
|
return {
|
@@ -574,24 +553,28 @@
|
|
574
553
|
r: m1, g: m2, b: m3, a: m4 !== undefined ? m4 : 1, format: 'rgb',
|
575
554
|
};
|
576
555
|
}
|
556
|
+
|
577
557
|
[, m1, m2, m3, m4] = matchers.hsl.exec(color) || [];
|
578
558
|
if (m1 && m2 && m3/* && m4 */) {
|
579
559
|
return {
|
580
560
|
h: m1, s: m2, l: m3, a: m4 !== undefined ? m4 : 1, format: 'hsl',
|
581
561
|
};
|
582
562
|
}
|
563
|
+
|
583
564
|
[, m1, m2, m3, m4] = matchers.hsv.exec(color) || [];
|
584
565
|
if (m1 && m2 && m3/* && m4 */) {
|
585
566
|
return {
|
586
567
|
h: m1, s: m2, v: m3, a: m4 !== undefined ? m4 : 1, format: 'hsv',
|
587
568
|
};
|
588
569
|
}
|
570
|
+
|
589
571
|
[, m1, m2, m3, m4] = matchers.hwb.exec(color) || [];
|
590
572
|
if (m1 && m2 && m3) {
|
591
573
|
return {
|
592
574
|
h: m1, w: m2, b: m3, a: m4 !== undefined ? m4 : 1, format: 'hwb',
|
593
575
|
};
|
594
576
|
}
|
577
|
+
|
595
578
|
[, m1, m2, m3, m4] = matchers.hex8.exec(color) || [];
|
596
579
|
if (m1 && m2 && m3 && m4) {
|
597
580
|
return {
|
@@ -599,18 +582,20 @@
|
|
599
582
|
g: parseIntFromHex(m2),
|
600
583
|
b: parseIntFromHex(m3),
|
601
584
|
a: convertHexToDecimal(m4),
|
602
|
-
format:
|
585
|
+
format: 'hex',
|
603
586
|
};
|
604
587
|
}
|
588
|
+
|
605
589
|
[, m1, m2, m3] = matchers.hex6.exec(color) || [];
|
606
590
|
if (m1 && m2 && m3) {
|
607
591
|
return {
|
608
592
|
r: parseIntFromHex(m1),
|
609
593
|
g: parseIntFromHex(m2),
|
610
594
|
b: parseIntFromHex(m3),
|
611
|
-
format:
|
595
|
+
format: 'hex',
|
612
596
|
};
|
613
597
|
}
|
598
|
+
|
614
599
|
[, m1, m2, m3, m4] = matchers.hex4.exec(color) || [];
|
615
600
|
if (m1 && m2 && m3 && m4) {
|
616
601
|
return {
|
@@ -618,19 +603,20 @@
|
|
618
603
|
g: parseIntFromHex(m2 + m2),
|
619
604
|
b: parseIntFromHex(m3 + m3),
|
620
605
|
a: convertHexToDecimal(m4 + m4),
|
621
|
-
|
622
|
-
format: named ? 'rgb' : 'hex',
|
606
|
+
format: 'hex',
|
623
607
|
};
|
624
608
|
}
|
609
|
+
|
625
610
|
[, m1, m2, m3] = matchers.hex3.exec(color) || [];
|
626
611
|
if (m1 && m2 && m3) {
|
627
612
|
return {
|
628
613
|
r: parseIntFromHex(m1 + m1),
|
629
614
|
g: parseIntFromHex(m2 + m2),
|
630
615
|
b: parseIntFromHex(m3 + m3),
|
631
|
-
format:
|
616
|
+
format: 'hex',
|
632
617
|
};
|
633
618
|
}
|
619
|
+
|
634
620
|
return false;
|
635
621
|
}
|
636
622
|
|
@@ -661,6 +647,7 @@
|
|
661
647
|
*/
|
662
648
|
function inputToRGB(input) {
|
663
649
|
let rgb = { r: 0, g: 0, b: 0 };
|
650
|
+
/** @type {*} */
|
664
651
|
let color = input;
|
665
652
|
/** @type {string | number} */
|
666
653
|
let a = 1;
|
@@ -677,39 +664,41 @@
|
|
677
664
|
let format = inputFormat && COLOR_FORMAT.includes(inputFormat) ? inputFormat : 'rgb';
|
678
665
|
|
679
666
|
if (typeof input === 'string') {
|
680
|
-
// @ts-ignore -- this now is converted to object
|
681
667
|
color = stringInputToObject(input);
|
682
668
|
if (color) ok = true;
|
683
669
|
}
|
684
670
|
if (typeof color === 'object') {
|
685
671
|
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
686
672
|
({ r, g, b } = color);
|
687
|
-
// RGB values now are all in [0,
|
688
|
-
[r, g, b] = [r, g, b].map((n) => bound01(n, isPercentage(n) ? 100 : 255)
|
673
|
+
// RGB values now are all in [0, 1] range
|
674
|
+
[r, g, b] = [r, g, b].map((n) => bound01(n, isPercentage(n) ? 100 : 255));
|
689
675
|
rgb = { r, g, b };
|
690
676
|
ok = true;
|
691
|
-
format = 'rgb';
|
692
|
-
}
|
677
|
+
format = color.format || 'rgb';
|
678
|
+
}
|
679
|
+
if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
693
680
|
({ h, s, v } = color);
|
694
|
-
h =
|
695
|
-
s =
|
696
|
-
v =
|
681
|
+
h = bound01(h, 360); // hue can be `5deg` or a [0, 1] value
|
682
|
+
s = bound01(s, 100); // saturation can be `5%` or a [0, 1] value
|
683
|
+
v = bound01(v, 100); // brightness can be `5%` or a [0, 1] value
|
697
684
|
rgb = hsvToRgb(h, s, v);
|
698
685
|
ok = true;
|
699
686
|
format = 'hsv';
|
700
|
-
}
|
687
|
+
}
|
688
|
+
if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
701
689
|
({ h, s, l } = color);
|
702
|
-
h =
|
703
|
-
s =
|
704
|
-
l =
|
690
|
+
h = bound01(h, 360); // hue can be `5deg` or a [0, 1] value
|
691
|
+
s = bound01(s, 100); // saturation can be `5%` or a [0, 1] value
|
692
|
+
l = bound01(l, 100); // lightness can be `5%` or a [0, 1] value
|
705
693
|
rgb = hslToRgb(h, s, l);
|
706
694
|
ok = true;
|
707
695
|
format = 'hsl';
|
708
|
-
}
|
696
|
+
}
|
697
|
+
if (isValidCSSUnit(color.h) && isValidCSSUnit(color.w) && isValidCSSUnit(color.b)) {
|
709
698
|
({ h, w, b } = color);
|
710
|
-
h =
|
711
|
-
w =
|
712
|
-
b =
|
699
|
+
h = bound01(h, 360); // hue can be `5deg` or a [0, 1] value
|
700
|
+
w = bound01(w, 100); // whiteness can be `5%` or a [0, 1] value
|
701
|
+
b = bound01(b, 100); // blackness can be `5%` or a [0, 1] value
|
713
702
|
rgb = hwbToRgb(h, w, b);
|
714
703
|
ok = true;
|
715
704
|
format = 'hwb';
|
@@ -726,9 +715,12 @@
|
|
726
715
|
return {
|
727
716
|
ok,
|
728
717
|
format,
|
729
|
-
r: Math.min(255, Math.max(rgb.r, 0)),
|
730
|
-
g: Math.min(255, Math.max(rgb.g, 0)),
|
731
|
-
b: Math.min(255, Math.max(rgb.b, 0)),
|
718
|
+
// r: Math.min(255, Math.max(rgb.r, 0)),
|
719
|
+
// g: Math.min(255, Math.max(rgb.g, 0)),
|
720
|
+
// b: Math.min(255, Math.max(rgb.b, 0)),
|
721
|
+
r: rgb.r,
|
722
|
+
g: rgb.g,
|
723
|
+
b: rgb.b,
|
732
724
|
a: boundAlpha(a),
|
733
725
|
};
|
734
726
|
}
|
@@ -747,16 +739,13 @@
|
|
747
739
|
constructor(input, config) {
|
748
740
|
let color = input;
|
749
741
|
const configFormat = config && COLOR_FORMAT.includes(config)
|
750
|
-
? config : '
|
742
|
+
? config : '';
|
751
743
|
|
752
|
-
// If input is already a `Color`,
|
744
|
+
// If input is already a `Color`, clone its values
|
753
745
|
if (color instanceof Color) {
|
754
746
|
color = inputToRGB(color);
|
755
747
|
}
|
756
|
-
|
757
|
-
const len = `${color}`.length;
|
758
|
-
color = `#${(len === 2 ? '0' : '00')}${color}`;
|
759
|
-
}
|
748
|
+
|
760
749
|
const {
|
761
750
|
r, g, b, a, ok, format,
|
762
751
|
} = inputToRGB(color);
|
@@ -806,24 +795,21 @@
|
|
806
795
|
let R = 0;
|
807
796
|
let G = 0;
|
808
797
|
let B = 0;
|
809
|
-
const rp = r / 255;
|
810
|
-
const rg = g / 255;
|
811
|
-
const rb = b / 255;
|
812
798
|
|
813
|
-
if (
|
814
|
-
R =
|
799
|
+
if (r <= 0.03928) {
|
800
|
+
R = r / 12.92;
|
815
801
|
} else {
|
816
|
-
R = ((
|
802
|
+
R = ((r + 0.055) / 1.055) ** 2.4;
|
817
803
|
}
|
818
|
-
if (
|
819
|
-
G =
|
804
|
+
if (g <= 0.03928) {
|
805
|
+
G = g / 12.92;
|
820
806
|
} else {
|
821
|
-
G = ((
|
807
|
+
G = ((g + 0.055) / 1.055) ** 2.4;
|
822
808
|
}
|
823
|
-
if (
|
824
|
-
B =
|
809
|
+
if (b <= 0.03928) {
|
810
|
+
B = b / 12.92;
|
825
811
|
} else {
|
826
|
-
B = ((
|
812
|
+
B = ((b + 0.055) / 1.055) ** 2.4;
|
827
813
|
}
|
828
814
|
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
829
815
|
}
|
@@ -833,7 +819,7 @@
|
|
833
819
|
* @returns {number} a number in the [0, 255] range
|
834
820
|
*/
|
835
821
|
get brightness() {
|
836
|
-
const { r, g, b } = this;
|
822
|
+
const { r, g, b } = this.toRgb();
|
837
823
|
return (r * 299 + g * 587 + b * 114) / 1000;
|
838
824
|
}
|
839
825
|
|
@@ -842,12 +828,14 @@
|
|
842
828
|
* @returns {CP.RGBA} an {r,g,b,a} object with [0, 255] ranged values
|
843
829
|
*/
|
844
830
|
toRgb() {
|
845
|
-
|
831
|
+
let {
|
846
832
|
r, g, b, a,
|
847
833
|
} = this;
|
848
834
|
|
835
|
+
[r, g, b] = [r, g, b].map((n) => roundPart(n * 255 * 100) / 100);
|
836
|
+
a = roundPart(a * 100) / 100;
|
849
837
|
return {
|
850
|
-
r, g, b, a
|
838
|
+
r, g, b, a,
|
851
839
|
};
|
852
840
|
}
|
853
841
|
|
@@ -941,7 +929,7 @@
|
|
941
929
|
toHsv() {
|
942
930
|
const {
|
943
931
|
r, g, b, a,
|
944
|
-
} = this
|
932
|
+
} = this;
|
945
933
|
const { h, s, v } = rgbToHsv(r, g, b);
|
946
934
|
|
947
935
|
return {
|
@@ -956,7 +944,7 @@
|
|
956
944
|
toHsl() {
|
957
945
|
const {
|
958
946
|
r, g, b, a,
|
959
|
-
} = this
|
947
|
+
} = this;
|
960
948
|
const { h, s, l } = rgbToHsl(r, g, b);
|
961
949
|
|
962
950
|
return {
|
@@ -1041,6 +1029,7 @@
|
|
1041
1029
|
*/
|
1042
1030
|
setAlpha(alpha) {
|
1043
1031
|
const self = this;
|
1032
|
+
if (typeof alpha !== 'number') return self;
|
1044
1033
|
self.a = boundAlpha(alpha);
|
1045
1034
|
return self;
|
1046
1035
|
}
|
@@ -1207,26 +1196,23 @@
|
|
1207
1196
|
} else if (args.length === 2) {
|
1208
1197
|
[hueSteps, lightSteps] = args;
|
1209
1198
|
if ([hueSteps, lightSteps].some((n) => n < 1)) {
|
1210
|
-
throw TypeError('ColorPalette:
|
1199
|
+
throw TypeError('ColorPalette: both arguments must be higher than 0.');
|
1211
1200
|
}
|
1212
|
-
} else {
|
1213
|
-
throw TypeError('ColorPalette requires minimum 2 arguments');
|
1214
1201
|
}
|
1215
1202
|
|
1216
|
-
/** @type {
|
1203
|
+
/** @type {*} */
|
1217
1204
|
const colors = [];
|
1218
|
-
|
1219
1205
|
const hueStep = 360 / hueSteps;
|
1220
1206
|
const half = roundPart((lightSteps - (lightSteps % 2 ? 1 : 0)) / 2);
|
1221
|
-
const
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
lightStep
|
1226
|
-
|
1227
|
-
lightStep =
|
1228
|
-
|
1229
|
-
|
1207
|
+
const steps1To13 = [0.25, 0.2, 0.15, 0.11, 0.09, 0.075];
|
1208
|
+
const lightSets = [[1, 2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13]];
|
1209
|
+
const closestSet = lightSets.find((set) => set.includes(lightSteps));
|
1210
|
+
|
1211
|
+
// find a lightStep that won't go beyond black and white
|
1212
|
+
// something within the [10-90] range of lightness
|
1213
|
+
const lightStep = closestSet
|
1214
|
+
? steps1To13[lightSets.indexOf(closestSet)]
|
1215
|
+
: (100 / (lightSteps + (lightSteps % 2 ? 0 : 1)) / 100);
|
1230
1216
|
|
1231
1217
|
// light tints
|
1232
1218
|
for (let i = 1; i < half + 1; i += 1) {
|
@@ -1,2 +1,2 @@
|
|
1
|
-
// ColorPalette v0.0.
|
2
|
-
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).ColorPalette=r()}(this,(function(){"use strict";const t=(t,r)=>Object.assign(t,r);function r(t){const r=Math.floor(t);return t-r<.5?r:Math.round(t)}const{head:e}=document;function n(t,r){const e=getComputedStyle(t);return r in e?e[r]:""}const o=(r,e)=>{t(r.style,e)},s=["transparent","currentColor","inherit","revert","initial"],a=["rgb","hex","hsl","hsv","hwb"],i="[-\\+]?\\d*\\.?\\d+(?:deg|rad|grad|turn)?",h="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",u=`(?:${h})|(?:${i})`,c="(?:[,|\\s]+)",l=`(?:[\\s|\\(\\s|\\s\\(\\s]+)?(${u})${c}(${h})${c}(${h})(?:[,|\\/\\s]*)?(${h})?(?:[\\s|\\)\\s]+)?`,g={CSS_UNIT:new RegExp(u),hwb:new RegExp("hwb"+l),rgb:new RegExp("rgb(?:a)?"+l),hsl:new RegExp("hsl(?:a)?"+l),hsv:new RegExp("hsv(?:a)?"+l),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/};function b(t){return(""+t).includes(".")&&1===parseFloat(t)}function f(t){return(""+t).includes("%")}function m(t){return!s.includes(t)&&!["#",...a].some(r=>t.includes(r))&&["rgb(255, 255, 255)","rgb(0, 0, 0)"].every(r=>{o(e,{color:t});const s=n(e,"color");return o(e,{color:""}),s!==r})}function p(t){return Boolean(g.CSS_UNIT.exec(String(t)))}function d(t,r){let e=t;b(t)&&(e="100%");const n=f(e);return e=360===r?parseFloat(e):Math.min(r,Math.max(0,parseFloat(e))),n&&(e=e*r/100),Math.abs(e-r)<1e-6?1:(e=360===r?(e<0?e%r+r:e%r)/r:e%r/r,e)}function x(t){let r=parseFloat(""+t);return(Number.isNaN(r)||r<0||r>1)&&(r=1),r}function S(t){return Math.min(1,Math.max(0,t))}function $(t){o(e,{color:t});const r=n(e,"color");return o(e,{color:""}),r}function A(t){return r(255*t).toString(16)}function w(t){return y(t)/255}function y(t){return parseInt(t,16)}function H(t){return 1===t.length?"0"+t:String(t)}function v(t,r,e){const n=t/255,o=r/255,s=e/255,a=Math.max(n,o,s),i=Math.min(n,o,s);let h=0,u=0;const c=(a+i)/2;if(a===i)u=0,h=0;else{const t=a-i;switch(u=c>.5?t/(2-a-i):t/(a+i),a){case n:h=(o-s)/t+(o<s?6:0);break;case o:h=(s-n)/t+2;break;case s:h=(n-o)/t+4}h/=6}return{h:h,s:u,l:c}}function R(t,r,e){let n=e;return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*n*(r-t):n<.5?r:n<2/3?t+(r-t)*(2/3-n)*6:t}function M(t,r,e){let n=0,o=0,s=0;if(0===r)o=e,s=e,n=e;else{const a=e<.5?e*(1+r):e+r-e*r,i=2*e-a;n=R(i,a,t+1/3),o=R(i,a,t),s=R(i,a,t-1/3)}return[n,o,s]=[n,o,s].map(t=>255*t),{r:n,g:o,b:s}}function T(t,r,e){const n=t/255,o=r/255,s=e/255;let a=0,i=0;const h=Math.min(n,o,s),u=Math.max(n,o,s),c=1-u;if(u===h)return{h:0,w:h,b:c};n===h?(a=o-s,i=3):(a=o===h?s-n:n-o,i=o===h?5:1);const l=(i-a/(u-h))/6;return{h:1===l?0:l,w:h,b:c}}function F(t,r,e){if(r+e>=1){const t=r/(r+e)*255;return{r:t,g:t,b:t}}let{r:n,g:o,b:s}=M(t,1,.5);return[n,o,s]=[n,o,s].map(t=>t/255*(1-r-e)+r).map(t=>255*t),{r:n,g:o,b:s}}function C(t,r,e){const n=t/255,o=r/255,s=e/255,a=Math.max(n,o,s),i=Math.min(n,o,s);let h=0;const u=a,c=a-i,l=0===a?0:c/a;if(a===i)h=0;else{switch(a){case n:h=(o-s)/c+(o<s?6:0);break;case o:h=(s-n)/c+2;break;case s:h=(n-o)/c+4}h/=6}return{h:h,s:l,v:u}}function E(t,r,e){const n=6*t,o=r,s=e,a=Math.floor(n),i=n-a,h=s*(1-o),u=s*(1-i*o),c=s*(1-(1-i)*o),l=a%6;let g=[s,u,h,h,c,s][l],b=[c,s,s,u,h,h][l],f=[h,h,c,s,s,u][l];return[g,b,f]=[g,b,f].map(t=>255*t),{r:g,g:b,b:f}}function N(t,e,n,o){const s=[H(r(t).toString(16)),H(r(e).toString(16)),H(r(n).toString(16))];return o&&s[0].charAt(0)===s[0].charAt(1)&&s[1].charAt(0)===s[1].charAt(1)&&s[2].charAt(0)===s[2].charAt(1)?s[0].charAt(0)+s[1].charAt(0)+s[2].charAt(0):s.join("")}function k(t,e,n,o,s){const a=[H(r(t).toString(16)),H(r(e).toString(16)),H(r(n).toString(16)),H(A(o))];return s&&a[0].charAt(0)===a[0].charAt(1)&&a[1].charAt(0)===a[1].charAt(1)&&a[2].charAt(0)===a[2].charAt(1)&&a[3].charAt(0)===a[3].charAt(1)?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0):a.join("")}function I(t){let r=t.trim().toLowerCase();if(0===r.length)return{r:0,g:0,b:0,a:1};let e=!1;if(m(r))r=$(r),e=!0;else if(s.includes(r)){return{r:0,g:0,b:0,a:"transparent"===r?0:1,format:"rgb",ok:!0}}let[,n,o,a,i]=g.rgb.exec(r)||[];return n&&o&&a?{r:n,g:o,b:a,a:void 0!==i?i:1,format:"rgb"}:([,n,o,a,i]=g.hsl.exec(r)||[],n&&o&&a?{h:n,s:o,l:a,a:void 0!==i?i:1,format:"hsl"}:([,n,o,a,i]=g.hsv.exec(r)||[],n&&o&&a?{h:n,s:o,v:a,a:void 0!==i?i:1,format:"hsv"}:([,n,o,a,i]=g.hwb.exec(r)||[],n&&o&&a?{h:n,w:o,b:a,a:void 0!==i?i:1,format:"hwb"}:([,n,o,a,i]=g.hex8.exec(r)||[],n&&o&&a&&i?{r:y(n),g:y(o),b:y(a),a:w(i),format:e?"rgb":"hex"}:([,n,o,a]=g.hex6.exec(r)||[],n&&o&&a?{r:y(n),g:y(o),b:y(a),format:e?"rgb":"hex"}:([,n,o,a,i]=g.hex4.exec(r)||[],n&&o&&a&&i?{r:y(n+n),g:y(o+o),b:y(a+a),a:w(i+i),format:e?"rgb":"hex"}:([,n,o,a]=g.hex3.exec(r)||[],!!(n&&o&&a)&&{r:y(n+n),g:y(o+o),b:y(a+a),format:e?"rgb":"hex"})))))))}function j(t){let r={r:0,g:0,b:0},e=t,n=1,o=null,s=null,i=null,h=null,u=null,c=null,l=null,g=null,b=!1;const m="object"==typeof e&&e.format;let S=m&&a.includes(m)?m:"rgb";return"string"==typeof t&&(e=I(t),e&&(b=!0)),"object"==typeof e&&(p(e.r)&&p(e.g)&&p(e.b)?(({r:l,g:g,b:u}=e),[l,g,u]=[l,g,u].map(t=>255*d(t,f(t)?100:255)),r={r:l,g:g,b:u},b=!0,S="rgb"):p(e.h)&&p(e.s)&&p(e.v)?(({h:c,s:o,v:s}=e),c="number"==typeof c?c:d(c,360),o="number"==typeof o?o:d(o,100),s="number"==typeof s?s:d(s,100),r=E(c,o,s),b=!0,S="hsv"):p(e.h)&&p(e.s)&&p(e.l)?(({h:c,s:o,l:i}=e),c="number"==typeof c?c:d(c,360),o="number"==typeof o?o:d(o,100),i="number"==typeof i?i:d(i,100),r=M(c,o,i),b=!0,S="hsl"):p(e.h)&&p(e.w)&&p(e.b)&&(({h:c,w:h,b:u}=e),c="number"==typeof c?c:d(c,360),h="number"==typeof h?h:d(h,100),u="number"==typeof u?u:d(u,100),r=F(c,h,u),b=!0,S="hwb"),p(e.a)&&(n=e.a,n=f(""+n)||parseFloat(n)>1?d(n,100):n)),void 0===e&&(b=!0),{ok:b,format:S,r:Math.min(255,Math.max(r.r,0)),g:Math.min(255,Math.max(r.g,0)),b:Math.min(255,Math.max(r.b,0)),a:x(n)}}class _{constructor(t,r){let e=t;const n=r&&a.includes(r)?r:"rgb";if(e instanceof _&&(e=j(e)),"number"==typeof e){e=`#${2===(""+e).length?"0":"00"}${e}`}const{r:o,g:s,b:i,a:h,ok:u,format:c}=j(e);this.originalInput=t,this.r=o,this.g=s,this.b=i,this.a=h,this.ok=u,this.format=n||c}get isValid(){return this.ok}get isDark(){return this.brightness<120}get luminance(){const{r:t,g:r,b:e}=this;let n=0,o=0,s=0;const a=t/255,i=r/255,h=e/255;return n=a<=.03928?a/12.92:((a+.055)/1.055)**2.4,o=i<=.03928?i/12.92:((i+.055)/1.055)**2.4,s=h<=.03928?h/12.92:((h+.055)/1.055)**2.4,.2126*n+.7152*o+.0722*s}get brightness(){const{r:t,g:r,b:e}=this;return(299*t+587*r+114*e)/1e3}toRgb(){const{r:t,g:e,b:n,a:o}=this;return{r:t,g:e,b:n,a:r(100*o)/100}}toRgbString(){const{r:t,g:e,b:n,a:o}=this.toRgb(),[s,a,i]=[t,e,n].map(r);return 1===o?`rgb(${s}, ${a}, ${i})`:`rgba(${s}, ${a}, ${i}, ${o})`}toRgbCSS4String(){const{r:t,g:e,b:n,a:o}=this.toRgb(),[s,a,i]=[t,e,n].map(r);return`rgb(${s} ${a} ${i}${1===o?"":` / ${r(100*o)}%`})`}toHex(t){const{r:r,g:e,b:n,a:o}=this.toRgb();return 1===o?N(r,e,n,t):k(r,e,n,o,t)}toHexString(t){return"#"+this.toHex(t)}toHex8(t){const{r:r,g:e,b:n,a:o}=this.toRgb();return k(r,e,n,o,t)}toHex8String(t){return"#"+this.toHex8(t)}toHsv(){const{r:t,g:r,b:e,a:n}=this.toRgb(),{h:o,s:s,v:a}=C(t,r,e);return{h:o,s:s,v:a,a:n}}toHsl(){const{r:t,g:r,b:e,a:n}=this.toRgb(),{h:o,s:s,l:a}=v(t,r,e);return{h:o,s:s,l:a,a:n}}toHslString(){let{h:t,s:e,l:n,a:o}=this.toHsl();return t=r(360*t),e=r(100*e),n=r(100*n),o=r(100*o)/100,1===o?`hsl(${t}, ${e}%, ${n}%)`:`hsla(${t}, ${e}%, ${n}%, ${o})`}toHslCSS4String(){let{h:t,s:e,l:n,a:o}=this.toHsl();t=r(360*t),e=r(100*e),n=r(100*n),o=r(100*o);return`hsl(${t}deg ${e}% ${n}%${o<100?` / ${r(o)}%`:""})`}toHwb(){const{r:t,g:r,b:e,a:n}=this,{h:o,w:s,b:a}=T(t,r,e);return{h:o,w:s,b:a,a:n}}toHwbString(){let{h:t,w:e,b:n,a:o}=this.toHwb();t=r(360*t),e=r(100*e),n=r(100*n),o=r(100*o);return`hwb(${t}deg ${e}% ${n}%${o<100?` / ${r(o)}%`:""})`}setAlpha(t){return this.a=x(t),this}saturate(r){if("number"!=typeof r)return this;const{h:e,s:n,l:o}=this.toHsl(),{r:s,g:a,b:i}=M(e,S(n+r/100),o);return t(this,{r:s,g:a,b:i}),this}desaturate(t){return"number"==typeof t?this.saturate(-t):this}greyscale(){return this.saturate(-100)}lighten(r){if("number"!=typeof r)return this;const{h:e,s:n,l:o}=this.toHsl(),{r:s,g:a,b:i}=M(e,n,S(o+r/100));return t(this,{r:s,g:a,b:i}),this}darken(t){return"number"==typeof t?this.lighten(-t):this}spin(r){if("number"!=typeof r)return this;const{h:e,s:n,l:o}=this.toHsl(),{r:s,g:a,b:i}=M(S((360*e+r)%360/360),n,o);return t(this,{r:s,g:a,b:i}),this}clone(){return new _(this)}toString(t){const{format:r}=this;return"hex"===r?this.toHexString(t):"hsl"===r?this.toHslString():"hwb"===r?this.toHwbString():this.toRgbString()}}t(_,{ANGLES:"deg|rad|grad|turn",CSS_ANGLE:i,CSS_INTEGER:"[-\\+]?\\d+%?",CSS_NUMBER:"[-\\+]?\\d*\\.\\d+%?",CSS_UNIT:h,CSS_UNIT2:u,PERMISSIVE_MATCH:l,matchers:g,isOnePointZero:b,isPercentage:f,isValidCSSUnit:p,isColorName:m,pad2:H,clamp01:S,bound01:d,boundAlpha:x,getRGBFromName:$,convertHexToDecimal:w,convertDecimalToHex:A,rgbToHsl:v,rgbToHex:N,rgbToHsv:C,rgbToHwb:T,rgbaToHex:k,hslToRgb:M,hsvToRgb:E,hueToRgb:R,hwbToRgb:F,parseIntFromHex:y,stringInputToObject:I,inputToRGB:j,roundPart:r,getElementStyle:n,setElementStyle:o,ObjectAssign:t});class P{constructor(...t){let e=0,n=12,o=10,s=[.5];if(3===t.length)[e,n,o]=t;else{if(2!==t.length)throw TypeError("ColorPalette requires minimum 2 arguments");if([n,o]=t,[n,o].some(t=>t<1))throw TypeError("ColorPalette: when 2 arguments used, both must be larger than 0.")}const a=[],i=360/n,h=r((o-(o%2?1:0))/2),u=100/(o+(o%2?0:1))/100;let c=.25;c=[4,5].includes(o)?.2:c,c=[6,7].includes(o)?.15:c,c=[8,9].includes(o)?.11:c,c=[10,11].includes(o)?.09:c,c=[12,13].includes(o)?.075:c,c=o>13?u:c;for(let t=1;t<h+1;t+=1)s=[...s,.5+c*t];for(let t=1;t<o-h;t+=1)s=[.5-c*t,...s];for(let t=0;t<n;t+=1){const r=(e+t*i)%360/360;s.forEach(t=>{a.push(new _({h:r,s:1,l:t}))})}this.hue=e,this.hueSteps=n,this.lightSteps=o,this.colors=a}}return t(P,{Color:_}),P}));
|
1
|
+
// ColorPalette v0.0.2alpha2 | thednp © 2022 | MIT-License
|
2
|
+
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).ColorPalette=r()}(this,(function(){"use strict";const t=(t,r)=>Object.assign(t,r);function r(t){const r=Math.floor(t);return t-r<.5?r:Math.round(t)}const{head:e}=document;function n(t,r){const e=getComputedStyle(t);return r in e?e[r]:""}const o=(r,e)=>{t(r.style,e)},s=["transparent","currentColor","inherit","revert","initial"],h=["rgb","hex","hsl","hsv","hwb"],i="[-\\+]?\\d*\\.?\\d+(?:deg|rad|grad|turn)?",a="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",u=`(?:${a})|(?:${i})`,l="(?:[,|\\s]+)",c=`(?:[\\s|\\(\\s|\\s\\(\\s]+)?(${u})${l}(${a})${l}(${a})(?:[,|\\/\\s]*)?(${a})?(?:[\\s|\\)\\s]+)?`,g={CSS_UNIT:new RegExp(u),hwb:new RegExp("hwb"+c),rgb:new RegExp("rgb(?:a)?"+c),hsl:new RegExp("hsl(?:a)?"+c),hsv:new RegExp("hsv(?:a)?"+c),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/};function b(t){return(""+t).includes(".")&&1===parseFloat(t)}function f(t){return(""+t).includes("%")}function m(t){return!s.includes(t)&&!["#",...h].some(r=>t.includes(r))&&(!!["black","white"].includes(t)||["rgb(255, 255, 255)","rgb(0, 0, 0)"].every(r=>{o(e,{color:t});const s=n(e,"color");return o(e,{color:""}),s!==r}))}function d(t){return Boolean(g.CSS_UNIT.exec(String(t)))}function x(t,r){let e=t;if("number"==typeof t&&0===Math.min(t,0)&&1===Math.max(t,1))return t;b(t)&&(e="100%");const n=f(e);return e=360===r?parseFloat(e):Math.min(r,Math.max(0,parseFloat(e))),n&&(e=e*r/100),Math.abs(e-r)<1e-6?1:(e=360===r?(e<0?e%r+r:e%r)/r:e%r/r,e)}function S(t){let r=parseFloat(""+t);return(Number.isNaN(r)||r<0||r>1)&&(r=1),r}function p(t){return Math.min(1,Math.max(0,t))}function A(t){o(e,{color:t});const r=n(e,"color");return o(e,{color:""}),r}function $(t){return r(255*t).toString(16)}function w(t){return H(t)/255}function H(t){return parseInt(t,16)}function v(t){return 1===t.length?"0"+t:String(t)}function R(t,r,e){const n=Math.max(t,r,e),o=Math.min(t,r,e);let s=0,h=0;const i=(n+o)/2;if(n===o)h=0,s=0;else{const a=n-o;h=i>.5?a/(2-n-o):a/(n+o),n===t&&(s=(r-e)/a+(r<e?6:0)),n===r&&(s=(e-t)/a+2),n===e&&(s=(t-r)/a+4),s/=6}return{h:s,s:h,l:i}}function T(t,r,e){let n=e;return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*n*(r-t):n<.5?r:n<2/3?t+(r-t)*(2/3-n)*6:t}function y(t,r,e){let n=0,o=0,s=0;if(0===r)o=e,s=e,n=e;else{const h=e<.5?e*(1+r):e+r-e*r,i=2*e-h;n=T(i,h,t+1/3),o=T(i,h,t),s=T(i,h,t-1/3)}return{r:n,g:o,b:s}}function F(t,r,e){let n=0,o=0;const s=Math.min(t,r,e),h=Math.max(t,r,e),i=1-h;if(h===s)return{h:0,w:s,b:i};t===s?(n=r-e,o=3):(n=r===s?e-t:t-r,o=r===s?5:1);const a=(o-n/(h-s))/6;return{h:1===a?0:a,w:s,b:i}}function M(t,r,e){if(r+e>=1){const t=r/(r+e);return{r:t,g:t,b:t}}let{r:n,g:o,b:s}=y(t,1,.5);return[n,o,s]=[n,o,s].map(t=>t*(1-r-e)+r),{r:n,g:o,b:s}}function C(t,r,e){const n=Math.max(t,r,e),o=Math.min(t,r,e);let s=0;const h=n-o;return n===o?s=0:(t===n&&(s=(r-e)/h+(r<e?6:0)),r===n&&(s=(e-t)/h+2),e===n&&(s=(t-r)/h+4),s/=6),{h:s,s:0===n?0:h/n,v:n}}function E(t,r,e){const n=6*t,o=r,s=e,h=Math.floor(n),i=n-h,a=s*(1-o),u=s*(1-i*o),l=s*(1-(1-i)*o),c=h%6;return{r:[s,u,a,a,l,s][c],g:[l,s,s,u,a,a][c],b:[a,a,l,s,s,u][c]}}function N(t,e,n,o){const s=[v(r(t).toString(16)),v(r(e).toString(16)),v(r(n).toString(16))];return o&&s[0].charAt(0)===s[0].charAt(1)&&s[1].charAt(0)===s[1].charAt(1)&&s[2].charAt(0)===s[2].charAt(1)?s[0].charAt(0)+s[1].charAt(0)+s[2].charAt(0):s.join("")}function I(t,e,n,o,s){const h=[v(r(t).toString(16)),v(r(e).toString(16)),v(r(n).toString(16)),v($(o))];return s&&h[0].charAt(0)===h[0].charAt(1)&&h[1].charAt(0)===h[1].charAt(1)&&h[2].charAt(0)===h[2].charAt(1)&&h[3].charAt(0)===h[3].charAt(1)?h[0].charAt(0)+h[1].charAt(0)+h[2].charAt(0)+h[3].charAt(0):h.join("")}function j(t){let r=t.trim().toLowerCase();if(0===r.length)return{r:0,g:0,b:0,a:1};if(m(r))r=A(r);else if(s.includes(r)){return{r:0,g:0,b:0,a:"transparent"===r?0:1,format:"rgb",ok:!0}}let[,e,n,o,h]=g.rgb.exec(r)||[];return e&&n&&o?{r:e,g:n,b:o,a:void 0!==h?h:1,format:"rgb"}:([,e,n,o,h]=g.hsl.exec(r)||[],e&&n&&o?{h:e,s:n,l:o,a:void 0!==h?h:1,format:"hsl"}:([,e,n,o,h]=g.hsv.exec(r)||[],e&&n&&o?{h:e,s:n,v:o,a:void 0!==h?h:1,format:"hsv"}:([,e,n,o,h]=g.hwb.exec(r)||[],e&&n&&o?{h:e,w:n,b:o,a:void 0!==h?h:1,format:"hwb"}:([,e,n,o,h]=g.hex8.exec(r)||[],e&&n&&o&&h?{r:H(e),g:H(n),b:H(o),a:w(h),format:"hex"}:([,e,n,o]=g.hex6.exec(r)||[],e&&n&&o?{r:H(e),g:H(n),b:H(o),format:"hex"}:([,e,n,o,h]=g.hex4.exec(r)||[],e&&n&&o&&h?{r:H(e+e),g:H(n+n),b:H(o+o),a:w(h+h),format:"hex"}:([,e,n,o]=g.hex3.exec(r)||[],!!(e&&n&&o)&&{r:H(e+e),g:H(n+n),b:H(o+o),format:"hex"})))))))}function k(t){let r={r:0,g:0,b:0},e=t,n=1,o=null,s=null,i=null,a=null,u=null,l=null,c=null,g=null,b=!1;const m="object"==typeof e&&e.format;let p=m&&h.includes(m)?m:"rgb";return"string"==typeof t&&(e=j(t),e&&(b=!0)),"object"==typeof e&&(d(e.r)&&d(e.g)&&d(e.b)&&(({r:c,g:g,b:u}=e),[c,g,u]=[c,g,u].map(t=>x(t,f(t)?100:255)),r={r:c,g:g,b:u},b=!0,p=e.format||"rgb"),d(e.h)&&d(e.s)&&d(e.v)&&(({h:l,s:o,v:s}=e),l=x(l,360),o=x(o,100),s=x(s,100),r=E(l,o,s),b=!0,p="hsv"),d(e.h)&&d(e.s)&&d(e.l)&&(({h:l,s:o,l:i}=e),l=x(l,360),o=x(o,100),i=x(i,100),r=y(l,o,i),b=!0,p="hsl"),d(e.h)&&d(e.w)&&d(e.b)&&(({h:l,w:a,b:u}=e),l=x(l,360),a=x(a,100),u=x(u,100),r=M(l,a,u),b=!0,p="hwb"),d(e.a)&&(n=e.a,n=f(""+n)||parseFloat(n)>1?x(n,100):n)),void 0===e&&(b=!0),{ok:b,format:p,r:r.r,g:r.g,b:r.b,a:S(n)}}class _{constructor(t,r){let e=t;const n=r&&h.includes(r)?r:"";e instanceof _&&(e=k(e));const{r:o,g:s,b:i,a:a,ok:u,format:l}=k(e);this.originalInput=t,this.r=o,this.g=s,this.b=i,this.a=a,this.ok=u,this.format=n||l}get isValid(){return this.ok}get isDark(){return this.brightness<120}get luminance(){const{r:t,g:r,b:e}=this;let n=0,o=0,s=0;return n=t<=.03928?t/12.92:((t+.055)/1.055)**2.4,o=r<=.03928?r/12.92:((r+.055)/1.055)**2.4,s=e<=.03928?e/12.92:((e+.055)/1.055)**2.4,.2126*n+.7152*o+.0722*s}get brightness(){const{r:t,g:r,b:e}=this.toRgb();return(299*t+587*r+114*e)/1e3}toRgb(){let{r:t,g:e,b:n,a:o}=this;return[t,e,n]=[t,e,n].map(t=>r(255*t*100)/100),o=r(100*o)/100,{r:t,g:e,b:n,a:o}}toRgbString(){const{r:t,g:e,b:n,a:o}=this.toRgb(),[s,h,i]=[t,e,n].map(r);return 1===o?`rgb(${s}, ${h}, ${i})`:`rgba(${s}, ${h}, ${i}, ${o})`}toRgbCSS4String(){const{r:t,g:e,b:n,a:o}=this.toRgb(),[s,h,i]=[t,e,n].map(r);return`rgb(${s} ${h} ${i}${1===o?"":` / ${r(100*o)}%`})`}toHex(t){const{r:r,g:e,b:n,a:o}=this.toRgb();return 1===o?N(r,e,n,t):I(r,e,n,o,t)}toHexString(t){return"#"+this.toHex(t)}toHex8(t){const{r:r,g:e,b:n,a:o}=this.toRgb();return I(r,e,n,o,t)}toHex8String(t){return"#"+this.toHex8(t)}toHsv(){const{r:t,g:r,b:e,a:n}=this,{h:o,s:s,v:h}=C(t,r,e);return{h:o,s:s,v:h,a:n}}toHsl(){const{r:t,g:r,b:e,a:n}=this,{h:o,s:s,l:h}=R(t,r,e);return{h:o,s:s,l:h,a:n}}toHslString(){let{h:t,s:e,l:n,a:o}=this.toHsl();return t=r(360*t),e=r(100*e),n=r(100*n),o=r(100*o)/100,1===o?`hsl(${t}, ${e}%, ${n}%)`:`hsla(${t}, ${e}%, ${n}%, ${o})`}toHslCSS4String(){let{h:t,s:e,l:n,a:o}=this.toHsl();t=r(360*t),e=r(100*e),n=r(100*n),o=r(100*o);return`hsl(${t}deg ${e}% ${n}%${o<100?` / ${r(o)}%`:""})`}toHwb(){const{r:t,g:r,b:e,a:n}=this,{h:o,w:s,b:h}=F(t,r,e);return{h:o,w:s,b:h,a:n}}toHwbString(){let{h:t,w:e,b:n,a:o}=this.toHwb();t=r(360*t),e=r(100*e),n=r(100*n),o=r(100*o);return`hwb(${t}deg ${e}% ${n}%${o<100?` / ${r(o)}%`:""})`}setAlpha(t){return"number"!=typeof t||(this.a=S(t)),this}saturate(r){if("number"!=typeof r)return this;const{h:e,s:n,l:o}=this.toHsl(),{r:s,g:h,b:i}=y(e,p(n+r/100),o);return t(this,{r:s,g:h,b:i}),this}desaturate(t){return"number"==typeof t?this.saturate(-t):this}greyscale(){return this.saturate(-100)}lighten(r){if("number"!=typeof r)return this;const{h:e,s:n,l:o}=this.toHsl(),{r:s,g:h,b:i}=y(e,n,p(o+r/100));return t(this,{r:s,g:h,b:i}),this}darken(t){return"number"==typeof t?this.lighten(-t):this}spin(r){if("number"!=typeof r)return this;const{h:e,s:n,l:o}=this.toHsl(),{r:s,g:h,b:i}=y(p((360*e+r)%360/360),n,o);return t(this,{r:s,g:h,b:i}),this}clone(){return new _(this)}toString(t){const{format:r}=this;return"hex"===r?this.toHexString(t):"hsl"===r?this.toHslString():"hwb"===r?this.toHwbString():this.toRgbString()}}t(_,{ANGLES:"deg|rad|grad|turn",CSS_ANGLE:i,CSS_INTEGER:"[-\\+]?\\d+%?",CSS_NUMBER:"[-\\+]?\\d*\\.\\d+%?",CSS_UNIT:a,CSS_UNIT2:u,PERMISSIVE_MATCH:c,matchers:g,isOnePointZero:b,isPercentage:f,isValidCSSUnit:d,isColorName:m,pad2:v,clamp01:p,bound01:x,boundAlpha:S,getRGBFromName:A,convertHexToDecimal:w,convertDecimalToHex:$,rgbToHsl:R,rgbToHex:N,rgbToHsv:C,rgbToHwb:F,rgbaToHex:I,hslToRgb:y,hsvToRgb:E,hueToRgb:T,hwbToRgb:M,parseIntFromHex:H,stringInputToObject:j,inputToRGB:k,roundPart:r,getElementStyle:n,setElementStyle:o,ObjectAssign:t});class P{constructor(...t){let e=0,n=12,o=10,s=[.5];if(3===t.length)[e,n,o]=t;else if(2===t.length&&([n,o]=t,[n,o].some(t=>t<1)))throw TypeError("ColorPalette: both arguments must be higher than 0.");const h=[],i=360/n,a=r((o-(o%2?1:0))/2),u=[[1,2,3],[4,5],[6,7],[8,9],[10,11],[12,13]],l=u.find(t=>t.includes(o)),c=l?[.25,.2,.15,.11,.09,.075][u.indexOf(l)]:100/(o+(o%2?0:1))/100;for(let t=1;t<a+1;t+=1)s=[...s,.5+c*t];for(let t=1;t<o-a;t+=1)s=[.5-c*t,...s];for(let t=0;t<n;t+=1){const r=(e+t*i)%360/360;s.forEach(t=>{h.push(new _({h:r,s:1,l:t}))})}this.hue=e,this.hueSteps=n,this.lightSteps=o,this.colors=h}}return t(P,{Color:_}),P}));
|