@thednp/color-picker 0.0.2-alpha1 → 0.0.2-alpha4
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/src/js/color.js
CHANGED
@@ -83,6 +83,8 @@ function isColorName(color) {
|
|
83
83
|
if (nonColors.includes(color)
|
84
84
|
|| ['#', ...COLOR_FORMAT].some((f) => color.includes(f))) return false;
|
85
85
|
|
86
|
+
if (['black', 'white'].includes(color)) return true;
|
87
|
+
|
86
88
|
return ['rgb(255, 255, 255)', 'rgb(0, 0, 0)'].every((c) => {
|
87
89
|
setElementStyle(documentHead, { color });
|
88
90
|
const computedColor = getElementStyle(documentHead, 'color');
|
@@ -109,6 +111,11 @@ function isValidCSSUnit(color) {
|
|
109
111
|
*/
|
110
112
|
function bound01(N, max) {
|
111
113
|
let n = N;
|
114
|
+
|
115
|
+
if (typeof N === 'number'
|
116
|
+
&& Math.min(N, 0) === 0 // round values to 6 decimals Math.round(N * (10 ** 6)) / 10 ** 6
|
117
|
+
&& Math.max(N, 1) === 1) return N;
|
118
|
+
|
112
119
|
if (isOnePointZero(N)) n = '100%';
|
113
120
|
|
114
121
|
const processPercent = isPercentage(n);
|
@@ -212,15 +219,12 @@ function pad2(c) {
|
|
212
219
|
/**
|
213
220
|
* Converts an RGB colour value to HSL.
|
214
221
|
*
|
215
|
-
* @param {number}
|
216
|
-
* @param {number}
|
217
|
-
* @param {number}
|
222
|
+
* @param {number} r Red component [0, 1]
|
223
|
+
* @param {number} g Green component [0, 1]
|
224
|
+
* @param {number} b Blue component [0, 1]
|
218
225
|
* @returns {CP.HSL} {h,s,l} object with [0, 1] ranged values
|
219
226
|
*/
|
220
|
-
function rgbToHsl(
|
221
|
-
const r = R / 255;
|
222
|
-
const g = G / 255;
|
223
|
-
const b = B / 255;
|
227
|
+
function rgbToHsl(r, g, b) {
|
224
228
|
const max = Math.max(r, g, b);
|
225
229
|
const min = Math.min(r, g, b);
|
226
230
|
let h = 0;
|
@@ -232,18 +236,10 @@ function rgbToHsl(R, G, B) {
|
|
232
236
|
} else {
|
233
237
|
const d = max - min;
|
234
238
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
case g:
|
240
|
-
h = (b - r) / d + 2;
|
241
|
-
break;
|
242
|
-
case b:
|
243
|
-
h = (r - g) / d + 4;
|
244
|
-
break;
|
245
|
-
default:
|
246
|
-
}
|
239
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
240
|
+
if (max === g) h = (b - r) / d + 2;
|
241
|
+
if (max === b) h = (r - g) / d + 4;
|
242
|
+
|
247
243
|
h /= 6;
|
248
244
|
}
|
249
245
|
return { h, s, l };
|
@@ -272,7 +268,7 @@ function hueToRgb(p, q, t) {
|
|
272
268
|
* @param {number} h Hue Angle [0, 1]
|
273
269
|
* @param {number} s Saturation [0, 1]
|
274
270
|
* @param {number} l Lightness Angle [0, 1]
|
275
|
-
* @returns {CP.RGB} {r,g,b} object with [0,
|
271
|
+
* @returns {CP.RGB} {r,g,b} object with [0, 1] ranged values
|
276
272
|
*/
|
277
273
|
function hslToRgb(h, s, l) {
|
278
274
|
let r = 0;
|
@@ -291,7 +287,6 @@ function hslToRgb(h, s, l) {
|
|
291
287
|
g = hueToRgb(p, q, h);
|
292
288
|
b = hueToRgb(p, q, h - 1 / 3);
|
293
289
|
}
|
294
|
-
[r, g, b] = [r, g, b].map((x) => x * 255);
|
295
290
|
|
296
291
|
return { r, g, b };
|
297
292
|
}
|
@@ -301,16 +296,12 @@ function hslToRgb(h, s, l) {
|
|
301
296
|
* @link https://www.w3.org/TR/css-color-4/#hwb-to-rgb
|
302
297
|
* @link http://alvyray.com/Papers/CG/hwb2rgb.htm
|
303
298
|
*
|
304
|
-
* @param {number}
|
305
|
-
* @param {number}
|
306
|
-
* @param {number}
|
299
|
+
* @param {number} r Red component [0, 1]
|
300
|
+
* @param {number} g Green [0, 1]
|
301
|
+
* @param {number} b Blue [0, 1]
|
307
302
|
* @return {CP.HWB} {h,w,b} object with [0, 1] ranged values
|
308
303
|
*/
|
309
|
-
function rgbToHwb(
|
310
|
-
const r = R / 255;
|
311
|
-
const g = G / 255;
|
312
|
-
const b = B / 255;
|
313
|
-
|
304
|
+
function rgbToHwb(r, g, b) {
|
314
305
|
let f = 0;
|
315
306
|
let i = 0;
|
316
307
|
const whiteness = Math.min(r, g, b);
|
@@ -340,20 +331,18 @@ function rgbToHwb(R, G, B) {
|
|
340
331
|
* @param {number} H Hue Angle [0, 1]
|
341
332
|
* @param {number} W Whiteness [0, 1]
|
342
333
|
* @param {number} B Blackness [0, 1]
|
343
|
-
* @return {CP.RGB} {r,g,b} object with [0,
|
334
|
+
* @return {CP.RGB} {r,g,b} object with [0, 1] ranged values
|
344
335
|
*
|
345
336
|
* @link https://www.w3.org/TR/css-color-4/#hwb-to-rgb
|
346
337
|
* @link http://alvyray.com/Papers/CG/hwb2rgb.htm
|
347
338
|
*/
|
348
339
|
function hwbToRgb(H, W, B) {
|
349
340
|
if (W + B >= 1) {
|
350
|
-
const gray =
|
341
|
+
const gray = W / (W + B);
|
351
342
|
return { r: gray, g: gray, b: gray };
|
352
343
|
}
|
353
344
|
let { r, g, b } = hslToRgb(H, 1, 0.5);
|
354
|
-
[r, g, b] = [r, g, b]
|
355
|
-
.map((v) => (v / 255) * (1 - W - B) + W)
|
356
|
-
.map((v) => v * 255);
|
345
|
+
[r, g, b] = [r, g, b].map((v) => v * (1 - W - B) + W);
|
357
346
|
|
358
347
|
return { r, g, b };
|
359
348
|
}
|
@@ -361,15 +350,12 @@ function hwbToRgb(H, W, B) {
|
|
361
350
|
/**
|
362
351
|
* Converts an RGB colour value to HSV.
|
363
352
|
*
|
364
|
-
* @param {number}
|
365
|
-
* @param {number}
|
366
|
-
* @param {number}
|
353
|
+
* @param {number} r Red component [0, 1]
|
354
|
+
* @param {number} g Green [0, 1]
|
355
|
+
* @param {number} b Blue [0, 1]
|
367
356
|
* @returns {CP.HSV} {h,s,v} object with [0, 1] ranged values
|
368
357
|
*/
|
369
|
-
function rgbToHsv(
|
370
|
-
const r = R / 255;
|
371
|
-
const g = G / 255;
|
372
|
-
const b = B / 255;
|
358
|
+
function rgbToHsv(r, g, b) {
|
373
359
|
const max = Math.max(r, g, b);
|
374
360
|
const min = Math.min(r, g, b);
|
375
361
|
let h = 0;
|
@@ -379,18 +365,10 @@ function rgbToHsv(R, G, B) {
|
|
379
365
|
if (max === min) {
|
380
366
|
h = 0; // achromatic
|
381
367
|
} else {
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
case g:
|
387
|
-
h = (b - r) / d + 2;
|
388
|
-
break;
|
389
|
-
case b:
|
390
|
-
h = (r - g) / d + 4;
|
391
|
-
break;
|
392
|
-
default:
|
393
|
-
}
|
368
|
+
if (r === max) h = (g - b) / d + (g < b ? 6 : 0);
|
369
|
+
if (g === max) h = (b - r) / d + 2;
|
370
|
+
if (b === max) h = (r - g) / d + 4;
|
371
|
+
|
394
372
|
h /= 6;
|
395
373
|
}
|
396
374
|
return { h, s, v };
|
@@ -414,10 +392,9 @@ function hsvToRgb(H, S, V) {
|
|
414
392
|
const q = v * (1 - f * s);
|
415
393
|
const t = v * (1 - (1 - f) * s);
|
416
394
|
const mod = i % 6;
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
[r, g, b] = [r, g, b].map((n) => n * 255);
|
395
|
+
const r = [v, q, p, p, t, v][mod];
|
396
|
+
const g = [t, v, v, q, p, p][mod];
|
397
|
+
const b = [p, p, t, v, v, q][mod];
|
421
398
|
return { r, g, b };
|
422
399
|
}
|
423
400
|
|
@@ -485,15 +462,15 @@ function rgbaToHex(r, g, b, a, allow4Char) {
|
|
485
462
|
*/
|
486
463
|
function stringInputToObject(input) {
|
487
464
|
let color = toLowerCase(input.trim());
|
465
|
+
|
488
466
|
if (color.length === 0) {
|
489
467
|
return {
|
490
468
|
r: 0, g: 0, b: 0, a: 1,
|
491
469
|
};
|
492
470
|
}
|
493
|
-
|
471
|
+
|
494
472
|
if (isColorName(color)) {
|
495
473
|
color = getRGBFromName(color);
|
496
|
-
named = true;
|
497
474
|
} else if (nonColors.includes(color)) {
|
498
475
|
const a = color === 'transparent' ? 0 : 1;
|
499
476
|
return {
|
@@ -512,24 +489,28 @@ function stringInputToObject(input) {
|
|
512
489
|
r: m1, g: m2, b: m3, a: m4 !== undefined ? m4 : 1, format: 'rgb',
|
513
490
|
};
|
514
491
|
}
|
492
|
+
|
515
493
|
[, m1, m2, m3, m4] = matchers.hsl.exec(color) || [];
|
516
494
|
if (m1 && m2 && m3/* && m4 */) {
|
517
495
|
return {
|
518
496
|
h: m1, s: m2, l: m3, a: m4 !== undefined ? m4 : 1, format: 'hsl',
|
519
497
|
};
|
520
498
|
}
|
499
|
+
|
521
500
|
[, m1, m2, m3, m4] = matchers.hsv.exec(color) || [];
|
522
501
|
if (m1 && m2 && m3/* && m4 */) {
|
523
502
|
return {
|
524
503
|
h: m1, s: m2, v: m3, a: m4 !== undefined ? m4 : 1, format: 'hsv',
|
525
504
|
};
|
526
505
|
}
|
506
|
+
|
527
507
|
[, m1, m2, m3, m4] = matchers.hwb.exec(color) || [];
|
528
508
|
if (m1 && m2 && m3) {
|
529
509
|
return {
|
530
510
|
h: m1, w: m2, b: m3, a: m4 !== undefined ? m4 : 1, format: 'hwb',
|
531
511
|
};
|
532
512
|
}
|
513
|
+
|
533
514
|
[, m1, m2, m3, m4] = matchers.hex8.exec(color) || [];
|
534
515
|
if (m1 && m2 && m3 && m4) {
|
535
516
|
return {
|
@@ -537,18 +518,20 @@ function stringInputToObject(input) {
|
|
537
518
|
g: parseIntFromHex(m2),
|
538
519
|
b: parseIntFromHex(m3),
|
539
520
|
a: convertHexToDecimal(m4),
|
540
|
-
format:
|
521
|
+
format: 'hex',
|
541
522
|
};
|
542
523
|
}
|
524
|
+
|
543
525
|
[, m1, m2, m3] = matchers.hex6.exec(color) || [];
|
544
526
|
if (m1 && m2 && m3) {
|
545
527
|
return {
|
546
528
|
r: parseIntFromHex(m1),
|
547
529
|
g: parseIntFromHex(m2),
|
548
530
|
b: parseIntFromHex(m3),
|
549
|
-
format:
|
531
|
+
format: 'hex',
|
550
532
|
};
|
551
533
|
}
|
534
|
+
|
552
535
|
[, m1, m2, m3, m4] = matchers.hex4.exec(color) || [];
|
553
536
|
if (m1 && m2 && m3 && m4) {
|
554
537
|
return {
|
@@ -556,19 +539,20 @@ function stringInputToObject(input) {
|
|
556
539
|
g: parseIntFromHex(m2 + m2),
|
557
540
|
b: parseIntFromHex(m3 + m3),
|
558
541
|
a: convertHexToDecimal(m4 + m4),
|
559
|
-
|
560
|
-
format: named ? 'rgb' : 'hex',
|
542
|
+
format: 'hex',
|
561
543
|
};
|
562
544
|
}
|
545
|
+
|
563
546
|
[, m1, m2, m3] = matchers.hex3.exec(color) || [];
|
564
547
|
if (m1 && m2 && m3) {
|
565
548
|
return {
|
566
549
|
r: parseIntFromHex(m1 + m1),
|
567
550
|
g: parseIntFromHex(m2 + m2),
|
568
551
|
b: parseIntFromHex(m3 + m3),
|
569
|
-
format:
|
552
|
+
format: 'hex',
|
570
553
|
};
|
571
554
|
}
|
555
|
+
|
572
556
|
return false;
|
573
557
|
}
|
574
558
|
|
@@ -599,6 +583,7 @@ function stringInputToObject(input) {
|
|
599
583
|
*/
|
600
584
|
function inputToRGB(input) {
|
601
585
|
let rgb = { r: 0, g: 0, b: 0 };
|
586
|
+
/** @type {*} */
|
602
587
|
let color = input;
|
603
588
|
/** @type {string | number} */
|
604
589
|
let a = 1;
|
@@ -615,39 +600,41 @@ function inputToRGB(input) {
|
|
615
600
|
let format = inputFormat && COLOR_FORMAT.includes(inputFormat) ? inputFormat : 'rgb';
|
616
601
|
|
617
602
|
if (typeof input === 'string') {
|
618
|
-
// @ts-ignore -- this now is converted to object
|
619
603
|
color = stringInputToObject(input);
|
620
604
|
if (color) ok = true;
|
621
605
|
}
|
622
606
|
if (typeof color === 'object') {
|
623
607
|
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
624
608
|
({ r, g, b } = color);
|
625
|
-
// RGB values now are all in [0,
|
626
|
-
[r, g, b] = [r, g, b].map((n) => bound01(n, isPercentage(n) ? 100 : 255)
|
609
|
+
// RGB values now are all in [0, 1] range
|
610
|
+
[r, g, b] = [r, g, b].map((n) => bound01(n, isPercentage(n) ? 100 : 255));
|
627
611
|
rgb = { r, g, b };
|
628
612
|
ok = true;
|
629
|
-
format = 'rgb';
|
630
|
-
}
|
613
|
+
format = color.format || 'rgb';
|
614
|
+
}
|
615
|
+
if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
631
616
|
({ h, s, v } = color);
|
632
|
-
h =
|
633
|
-
s =
|
634
|
-
v =
|
617
|
+
h = bound01(h, 360); // hue can be `5deg` or a [0, 1] value
|
618
|
+
s = bound01(s, 100); // saturation can be `5%` or a [0, 1] value
|
619
|
+
v = bound01(v, 100); // brightness can be `5%` or a [0, 1] value
|
635
620
|
rgb = hsvToRgb(h, s, v);
|
636
621
|
ok = true;
|
637
622
|
format = 'hsv';
|
638
|
-
}
|
623
|
+
}
|
624
|
+
if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
639
625
|
({ h, s, l } = color);
|
640
|
-
h =
|
641
|
-
s =
|
642
|
-
l =
|
626
|
+
h = bound01(h, 360); // hue can be `5deg` or a [0, 1] value
|
627
|
+
s = bound01(s, 100); // saturation can be `5%` or a [0, 1] value
|
628
|
+
l = bound01(l, 100); // lightness can be `5%` or a [0, 1] value
|
643
629
|
rgb = hslToRgb(h, s, l);
|
644
630
|
ok = true;
|
645
631
|
format = 'hsl';
|
646
|
-
}
|
632
|
+
}
|
633
|
+
if (isValidCSSUnit(color.h) && isValidCSSUnit(color.w) && isValidCSSUnit(color.b)) {
|
647
634
|
({ h, w, b } = color);
|
648
|
-
h =
|
649
|
-
w =
|
650
|
-
b =
|
635
|
+
h = bound01(h, 360); // hue can be `5deg` or a [0, 1] value
|
636
|
+
w = bound01(w, 100); // whiteness can be `5%` or a [0, 1] value
|
637
|
+
b = bound01(b, 100); // blackness can be `5%` or a [0, 1] value
|
651
638
|
rgb = hwbToRgb(h, w, b);
|
652
639
|
ok = true;
|
653
640
|
format = 'hwb';
|
@@ -664,9 +651,12 @@ function inputToRGB(input) {
|
|
664
651
|
return {
|
665
652
|
ok,
|
666
653
|
format,
|
667
|
-
r: Math.min(255, Math.max(rgb.r, 0)),
|
668
|
-
g: Math.min(255, Math.max(rgb.g, 0)),
|
669
|
-
b: Math.min(255, Math.max(rgb.b, 0)),
|
654
|
+
// r: Math.min(255, Math.max(rgb.r, 0)),
|
655
|
+
// g: Math.min(255, Math.max(rgb.g, 0)),
|
656
|
+
// b: Math.min(255, Math.max(rgb.b, 0)),
|
657
|
+
r: rgb.r,
|
658
|
+
g: rgb.g,
|
659
|
+
b: rgb.b,
|
670
660
|
a: boundAlpha(a),
|
671
661
|
};
|
672
662
|
}
|
@@ -685,16 +675,13 @@ export default class Color {
|
|
685
675
|
constructor(input, config) {
|
686
676
|
let color = input;
|
687
677
|
const configFormat = config && COLOR_FORMAT.includes(config)
|
688
|
-
? config : '
|
678
|
+
? config : '';
|
689
679
|
|
690
|
-
// If input is already a `Color`,
|
680
|
+
// If input is already a `Color`, clone its values
|
691
681
|
if (color instanceof Color) {
|
692
682
|
color = inputToRGB(color);
|
693
683
|
}
|
694
|
-
|
695
|
-
const len = `${color}`.length;
|
696
|
-
color = `#${(len === 2 ? '0' : '00')}${color}`;
|
697
|
-
}
|
684
|
+
|
698
685
|
const {
|
699
686
|
r, g, b, a, ok, format,
|
700
687
|
} = inputToRGB(color);
|
@@ -744,24 +731,21 @@ export default class Color {
|
|
744
731
|
let R = 0;
|
745
732
|
let G = 0;
|
746
733
|
let B = 0;
|
747
|
-
const rp = r / 255;
|
748
|
-
const rg = g / 255;
|
749
|
-
const rb = b / 255;
|
750
734
|
|
751
|
-
if (
|
752
|
-
R =
|
735
|
+
if (r <= 0.03928) {
|
736
|
+
R = r / 12.92;
|
753
737
|
} else {
|
754
|
-
R = ((
|
738
|
+
R = ((r + 0.055) / 1.055) ** 2.4;
|
755
739
|
}
|
756
|
-
if (
|
757
|
-
G =
|
740
|
+
if (g <= 0.03928) {
|
741
|
+
G = g / 12.92;
|
758
742
|
} else {
|
759
|
-
G = ((
|
743
|
+
G = ((g + 0.055) / 1.055) ** 2.4;
|
760
744
|
}
|
761
|
-
if (
|
762
|
-
B =
|
745
|
+
if (b <= 0.03928) {
|
746
|
+
B = b / 12.92;
|
763
747
|
} else {
|
764
|
-
B = ((
|
748
|
+
B = ((b + 0.055) / 1.055) ** 2.4;
|
765
749
|
}
|
766
750
|
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
767
751
|
}
|
@@ -771,7 +755,7 @@ export default class Color {
|
|
771
755
|
* @returns {number} a number in the [0, 255] range
|
772
756
|
*/
|
773
757
|
get brightness() {
|
774
|
-
const { r, g, b } = this;
|
758
|
+
const { r, g, b } = this.toRgb();
|
775
759
|
return (r * 299 + g * 587 + b * 114) / 1000;
|
776
760
|
}
|
777
761
|
|
@@ -780,12 +764,14 @@ export default class Color {
|
|
780
764
|
* @returns {CP.RGBA} an {r,g,b,a} object with [0, 255] ranged values
|
781
765
|
*/
|
782
766
|
toRgb() {
|
783
|
-
|
767
|
+
let {
|
784
768
|
r, g, b, a,
|
785
769
|
} = this;
|
786
770
|
|
771
|
+
[r, g, b] = [r, g, b].map((n) => roundPart(n * 255 * 100) / 100);
|
772
|
+
a = roundPart(a * 100) / 100;
|
787
773
|
return {
|
788
|
-
r, g, b, a
|
774
|
+
r, g, b, a,
|
789
775
|
};
|
790
776
|
}
|
791
777
|
|
@@ -879,7 +865,7 @@ export default class Color {
|
|
879
865
|
toHsv() {
|
880
866
|
const {
|
881
867
|
r, g, b, a,
|
882
|
-
} = this
|
868
|
+
} = this;
|
883
869
|
const { h, s, v } = rgbToHsv(r, g, b);
|
884
870
|
|
885
871
|
return {
|
@@ -894,7 +880,7 @@ export default class Color {
|
|
894
880
|
toHsl() {
|
895
881
|
const {
|
896
882
|
r, g, b, a,
|
897
|
-
} = this
|
883
|
+
} = this;
|
898
884
|
const { h, s, l } = rgbToHsl(r, g, b);
|
899
885
|
|
900
886
|
return {
|
@@ -979,6 +965,7 @@ export default class Color {
|
|
979
965
|
*/
|
980
966
|
setAlpha(alpha) {
|
981
967
|
const self = this;
|
968
|
+
if (typeof alpha !== 'number') return self;
|
982
969
|
self.a = boundAlpha(alpha);
|
983
970
|
return self;
|
984
971
|
}
|
package/types/cp.d.ts
CHANGED
@@ -202,7 +202,7 @@ declare module "color-picker/src/js/color-palette" {
|
|
202
202
|
* Returns a color palette with a given set of parameters.
|
203
203
|
* @example
|
204
204
|
* new ColorPalette(0, 12, 10);
|
205
|
-
* // => { hue: 0, hueSteps: 12, lightSteps: 10, colors:
|
205
|
+
* // => { hue: 0, hueSteps: 12, lightSteps: 10, colors: Array<Color> }
|
206
206
|
*/
|
207
207
|
export default class ColorPalette {
|
208
208
|
/**
|
@@ -216,9 +216,8 @@ declare module "color-picker/src/js/color-palette" {
|
|
216
216
|
hue: number;
|
217
217
|
hueSteps: number;
|
218
218
|
lightSteps: number;
|
219
|
-
colors:
|
219
|
+
colors: any;
|
220
220
|
}
|
221
|
-
import Color from "color-picker/src/js/color";
|
222
221
|
}
|
223
222
|
declare module "color-picker/src/js/util/colorPickerLabels" {
|
224
223
|
export default colorPickerLabels;
|
@@ -245,10 +244,6 @@ declare module "color-picker/src/js/util/isValidJSON" {
|
|
245
244
|
*/
|
246
245
|
export default function isValidJSON(str: string): boolean;
|
247
246
|
}
|
248
|
-
declare module "color-picker/src/js/version" {
|
249
|
-
export default Version;
|
250
|
-
const Version: string;
|
251
|
-
}
|
252
247
|
declare module "color-picker/src/js/util/vHidden" {
|
253
248
|
export default vHidden;
|
254
249
|
const vHidden: "v-hidden";
|
@@ -296,9 +291,11 @@ declare module "color-picker/src/js/util/setMarkup" {
|
|
296
291
|
*/
|
297
292
|
export default function setMarkup(self: CP.ColorPicker): void;
|
298
293
|
}
|
294
|
+
declare module "color-picker/src/js/util/version" {
|
295
|
+
export default Version;
|
296
|
+
const Version: string;
|
297
|
+
}
|
299
298
|
declare module "color-picker/src/js/color-picker" {
|
300
|
-
/** @type {CP.GetInstance<ColorPicker>} */
|
301
|
-
export const getColorPickerInstance: CP.GetInstance<ColorPicker>;
|
302
299
|
/**
|
303
300
|
* Color Picker Web Component
|
304
301
|
* @see http://thednp.github.io/color-picker
|
@@ -337,14 +334,24 @@ declare module "color-picker/src/js/color-picker" {
|
|
337
334
|
format: CP.ColorFormats;
|
338
335
|
/** Shows the `ColorPicker` dropdown. */
|
339
336
|
showPicker(): void;
|
337
|
+
/**
|
338
|
+
* The `Space` & `Enter` keys specific event listener.
|
339
|
+
* Toggle visibility of the `ColorPicker` / the presets menu, showing one will hide the other.
|
340
|
+
* @param {KeyboardEvent} e
|
341
|
+
* @this {ColorPicker}
|
342
|
+
*/
|
340
343
|
/**
|
341
344
|
* Toggle the `ColorPicker` dropdown visibility.
|
342
|
-
* @param {Event} e
|
345
|
+
* @param {Event=} e
|
346
|
+
* @this {ColorPicker}
|
347
|
+
*/
|
348
|
+
togglePicker(this: ColorPicker, e?: Event | undefined): void;
|
349
|
+
/**
|
350
|
+
* Toggles the visibility of the `ColorPicker` presets menu.
|
351
|
+
* @param {Event=} e
|
343
352
|
* @this {ColorPicker}
|
344
353
|
*/
|
345
|
-
|
346
|
-
/** Toggles the visibility of the `ColorPicker` presets menu. */
|
347
|
-
toggleMenu(): void;
|
354
|
+
toggleMenu(this: ColorPicker, e?: Event | undefined): void;
|
348
355
|
/**
|
349
356
|
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
350
357
|
* @param {Partial<Event>} e
|
@@ -400,13 +407,6 @@ declare module "color-picker/src/js/color-picker" {
|
|
400
407
|
* @this {ColorPicker}
|
401
408
|
*/
|
402
409
|
handleDismiss(this: ColorPicker, { code }: KeyboardEvent): void;
|
403
|
-
/**
|
404
|
-
* The `Space` & `Enter` keys specific event listener.
|
405
|
-
* Toggle visibility of the `ColorPicker` / the presets menu, showing one will hide the other.
|
406
|
-
* @param {KeyboardEvent} e
|
407
|
-
* @this {ColorPicker}
|
408
|
-
*/
|
409
|
-
keyToggle(this: ColorPicker, e: KeyboardEvent): void;
|
410
410
|
/**
|
411
411
|
* The `ColorPicker` *keydown* event listener for control knobs.
|
412
412
|
* @param {KeyboardEvent} e
|
@@ -456,6 +456,8 @@ declare module "color-picker/src/js/color-picker" {
|
|
456
456
|
get isDark(): boolean;
|
457
457
|
/** Checks if the current input value is a valid colour. */
|
458
458
|
get isValid(): boolean;
|
459
|
+
/** Returns the colour appearance, usually the closest colour name for the current value. */
|
460
|
+
get appearance(): string | undefined;
|
459
461
|
/** Updates `ColorPicker` visuals. */
|
460
462
|
updateVisuals(): void;
|
461
463
|
/**
|
@@ -512,27 +514,27 @@ declare module "color-picker/src/js/color-picker-element" {
|
|
512
514
|
* `ColorPickerElement` Web Component.
|
513
515
|
* @example
|
514
516
|
* <label for="UNIQUE_ID">Label</label>
|
515
|
-
* <color-picker
|
516
|
-
* <input id="UNIQUE_ID"
|
517
|
+
* <color-picker>
|
518
|
+
* <input id="UNIQUE_ID" value="red" format="hex" class="color-preview btn-appearance">
|
517
519
|
* </color-picker>
|
520
|
+
* // or
|
521
|
+
* <label for="UNIQUE_ID">Label</label>
|
522
|
+
* <color-picker data-id="UNIQUE_ID" data-value="red" data-format="hex"></color-picker>
|
518
523
|
*/
|
519
524
|
class ColorPickerElement extends HTMLElement {
|
520
|
-
/** @type {boolean} */
|
521
|
-
isDisconnected: boolean;
|
522
525
|
/**
|
523
526
|
* Returns the current color value.
|
524
|
-
* @returns {string
|
527
|
+
* @returns {string | undefined}
|
525
528
|
*/
|
526
|
-
get value(): string |
|
529
|
+
get value(): string | undefined;
|
527
530
|
connectedCallback(): void;
|
528
531
|
/** @type {HTMLInputElement} */
|
529
532
|
input: HTMLInputElement | undefined;
|
530
533
|
colorPicker: ColorPicker | undefined;
|
531
|
-
|
532
|
-
disconnectedCallback(): void;
|
534
|
+
/** @this {ColorPickerElement} */
|
535
|
+
disconnectedCallback(this: ColorPickerElement): void;
|
533
536
|
}
|
534
537
|
import ColorPicker from "color-picker/src/js/color-picker";
|
535
|
-
import Color from "color-picker/src/js/color";
|
536
538
|
}
|
537
539
|
declare module "color-picker/types/source/source" {
|
538
540
|
export { default as Color } from "color-picker/src/js/color";
|
package/types/source/types.d.ts
CHANGED
@@ -83,7 +83,7 @@ export interface ColorPickerOptions {
|
|
83
83
|
colorKeywords?: string[];
|
84
84
|
}
|
85
85
|
|
86
|
-
export type ColorInput = string |
|
86
|
+
export type ColorInput = string | RGB | RGBA | HSL | HSLA | HSV | HSVA | HWB | ColorObject;
|
87
87
|
export type ColorFormats = string | 'rgb' | 'hex' | 'hex3' | 'hex4' | 'hex6' | 'hex8' | 'hsl' | 'hsv' | 'hwb';
|
88
88
|
|
89
89
|
export type GetInstance<T> = (element: string | HTMLInputElement) => T | null;
|