@thednp/color-picker 2.0.0-alpha1 → 2.0.0-alpha3
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +1 -1
- package/README.md +7 -6
- package/dist/css/color-picker.css +3 -3
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +3 -3
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-picker.cjs +3 -3
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.d.ts +21 -19
- package/dist/js/color-picker.js +3 -3
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +395 -393
- package/dist/js/color-picker.mjs.map +1 -1
- package/package.json +19 -19
- package/src/scss/color-picker.scss +7 -3
- package/src/ts/index.ts +30 -44
- package/cypress/downloads/downloads.htm +0 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thednp/color-picker",
|
3
|
-
"version": "2.0.0-
|
3
|
+
"version": "2.0.0-alpha3",
|
4
4
|
"author": "thednp",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "🎨 Modern Color Picker Component",
|
@@ -63,20 +63,20 @@
|
|
63
63
|
"typescript"
|
64
64
|
],
|
65
65
|
"dependencies": {
|
66
|
-
"@thednp/color": "^1.0.
|
67
|
-
"@thednp/event-listener": "^2.0.
|
68
|
-
"@thednp/shorty": "^2.0.0-
|
66
|
+
"@thednp/color": "^1.0.7",
|
67
|
+
"@thednp/event-listener": "^2.0.1",
|
68
|
+
"@thednp/shorty": "^2.0.0-alpha15"
|
69
69
|
},
|
70
70
|
"devDependencies": {
|
71
71
|
"@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
|
72
|
-
"@cypress/code-coverage": "^3.10.
|
72
|
+
"@cypress/code-coverage": "^3.10.7",
|
73
73
|
"@types/istanbul-lib-instrument": "^1.7.4",
|
74
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
75
|
-
"@typescript-eslint/parser": "^5.
|
76
|
-
"cypress": "^12.
|
77
|
-
"dts-bundle-generator": "^8.0.
|
78
|
-
"eslint": "^8.
|
79
|
-
"eslint-plugin-jsdoc": "^
|
74
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
75
|
+
"@typescript-eslint/parser": "^5.59.9",
|
76
|
+
"cypress": "^12.14.0",
|
77
|
+
"dts-bundle-generator": "^8.0.1",
|
78
|
+
"eslint": "^8.42.0",
|
79
|
+
"eslint-plugin-jsdoc": "^46.2.6",
|
80
80
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
81
81
|
"eslint-plugin-prettier": "^4.2.1",
|
82
82
|
"istanbul-lib-coverage": "^3.2.0",
|
@@ -84,15 +84,15 @@
|
|
84
84
|
"ncp": "^2.0.0",
|
85
85
|
"npm-run-all": "^4.1.5",
|
86
86
|
"nyc": "^15.1.0",
|
87
|
-
"prettier": "^2.8.
|
88
|
-
"rimraf": "^
|
89
|
-
"sass": "^1.
|
90
|
-
"stylelint": "^15.
|
91
|
-
"stylelint-config-standard": "^
|
92
|
-
"stylelint-config-standard-scss": "^
|
87
|
+
"prettier": "^2.8.8",
|
88
|
+
"rimraf": "^5.0.1",
|
89
|
+
"sass": "^1.63.3",
|
90
|
+
"stylelint": "^15.7.0",
|
91
|
+
"stylelint-config-standard": "^33.0.0",
|
92
|
+
"stylelint-config-standard-scss": "^9.0.0",
|
93
93
|
"stylelint-order": "^6.0.3",
|
94
|
-
"stylelint-scss": "^
|
95
|
-
"typescript": "^5.
|
94
|
+
"stylelint-scss": "^5.0.1",
|
95
|
+
"typescript": "^5.1.3",
|
96
96
|
"vite": "^4.3.9"
|
97
97
|
}
|
98
98
|
}
|
@@ -64,7 +64,11 @@
|
|
64
64
|
}
|
65
65
|
|
66
66
|
.color-dropdown.picker { left: 0; }
|
67
|
-
|
67
|
+
|
68
|
+
.color-dropdown.menu {
|
69
|
+
right: 0;
|
70
|
+
max-height: 230px;
|
71
|
+
}
|
68
72
|
|
69
73
|
.open .color-dropdown.top {
|
70
74
|
top: auto;
|
@@ -427,12 +431,12 @@
|
|
427
431
|
cursor: ns-resize;
|
428
432
|
}
|
429
433
|
|
430
|
-
@media (
|
434
|
+
@media (width >= 578px) {
|
431
435
|
.visual-control { height: 230px; }
|
432
436
|
.visual-control1 { width: 230px; }
|
433
437
|
}
|
434
438
|
|
435
|
-
@media (
|
439
|
+
@media (width >= 1200px) {
|
436
440
|
.visual-control { height: 300px; }
|
437
441
|
.visual-control1 { width: 300px; }
|
438
442
|
}
|
package/src/ts/index.ts
CHANGED
@@ -208,6 +208,8 @@ export default class ColorPicker {
|
|
208
208
|
public static setAttribute = setAttribute;
|
209
209
|
public static getBoundingClientRect = getBoundingClientRect;
|
210
210
|
public static version = version;
|
211
|
+
public static colorNames = colorNames;
|
212
|
+
public static colorPickerLabels = colorPickerLabels;
|
211
213
|
|
212
214
|
id: number;
|
213
215
|
input: HTMLInputElement;
|
@@ -318,22 +320,6 @@ export default class ColorPicker {
|
|
318
320
|
this.colorPresets = colorPresets.split(',').map((x: string) => x.trim());
|
319
321
|
}
|
320
322
|
|
321
|
-
// bind events
|
322
|
-
this.showPicker = this.showPicker.bind(this);
|
323
|
-
this.togglePicker = this.togglePicker.bind(this);
|
324
|
-
this.toggleMenu = this.toggleMenu.bind(this);
|
325
|
-
this.menuClickHandler = this.menuClickHandler.bind(this);
|
326
|
-
this.menuKeyHandler = this.menuKeyHandler.bind(this);
|
327
|
-
this.pointerDown = this.pointerDown.bind(this);
|
328
|
-
this.pointerMove = this.pointerMove.bind(this);
|
329
|
-
this.pointerUp = this.pointerUp.bind(this);
|
330
|
-
this.update = this.update.bind(this);
|
331
|
-
this.handleScroll = this.handleScroll.bind(this);
|
332
|
-
this.handleFocusOut = this.handleFocusOut.bind(this);
|
333
|
-
this.changeHandler = this.changeHandler.bind(this);
|
334
|
-
this.handleDismiss = this.handleDismiss.bind(this);
|
335
|
-
this.handleKnobs = this.handleKnobs.bind(this);
|
336
|
-
|
337
323
|
// generate markup
|
338
324
|
setMarkup(this);
|
339
325
|
|
@@ -513,11 +499,11 @@ export default class ColorPicker {
|
|
513
499
|
* @param e
|
514
500
|
* @this {ColorPicker}
|
515
501
|
*/
|
516
|
-
handleFocusOut({ relatedTarget }: FocusEvent & { relatedTarget: HTMLElement }): void {
|
502
|
+
handleFocusOut = ({ relatedTarget }: FocusEvent & { relatedTarget: HTMLElement }): void => {
|
517
503
|
if (relatedTarget && !this.parent.contains(relatedTarget)) {
|
518
504
|
this.hide(true);
|
519
505
|
}
|
520
|
-
}
|
506
|
+
};
|
521
507
|
|
522
508
|
/**
|
523
509
|
* The `ColorPicker` *keyup* event listener when open.
|
@@ -525,11 +511,11 @@ export default class ColorPicker {
|
|
525
511
|
* @param e
|
526
512
|
* @this {ColorPicker}
|
527
513
|
*/
|
528
|
-
handleDismiss({ code }: KeyboardEvent): void {
|
514
|
+
handleDismiss = ({ code }: KeyboardEvent): void => {
|
529
515
|
if (this.isOpen && code === keyEscape) {
|
530
516
|
this.hide();
|
531
517
|
}
|
532
|
-
}
|
518
|
+
};
|
533
519
|
|
534
520
|
/**
|
535
521
|
* The `ColorPicker` *scroll* event listener when open.
|
@@ -537,7 +523,7 @@ export default class ColorPicker {
|
|
537
523
|
* @param e
|
538
524
|
* @this {ColorPicker}
|
539
525
|
*/
|
540
|
-
handleScroll(e: Event): void {
|
526
|
+
handleScroll = (e: Event): void => {
|
541
527
|
const { activeElement } = getDocument(this.input);
|
542
528
|
|
543
529
|
this.updateDropdownPosition();
|
@@ -550,14 +536,14 @@ export default class ColorPicker {
|
|
550
536
|
e.stopPropagation();
|
551
537
|
e.preventDefault();
|
552
538
|
}
|
553
|
-
}
|
539
|
+
};
|
554
540
|
|
555
541
|
/**
|
556
542
|
* The `ColorPicker` keyboard event listener for menu navigation.
|
557
543
|
*
|
558
544
|
* @param e
|
559
545
|
*/
|
560
|
-
menuKeyHandler(e: Event & { target: HTMLElement; code: string }) {
|
546
|
+
menuKeyHandler = (e: Event & { target: HTMLElement; code: string }) => {
|
561
547
|
const { target, code } = e;
|
562
548
|
const { previousElementSibling, nextElementSibling, parentElement } = target;
|
563
549
|
const isColorOptionsMenu = parentElement && hasClass(parentElement, 'color-options');
|
@@ -591,7 +577,7 @@ export default class ColorPicker {
|
|
591
577
|
if ([keyEnter, keySpace].includes(code)) {
|
592
578
|
this.menuClickHandler(e);
|
593
579
|
}
|
594
|
-
}
|
580
|
+
};
|
595
581
|
|
596
582
|
/**
|
597
583
|
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
@@ -599,7 +585,7 @@ export default class ColorPicker {
|
|
599
585
|
* @param e
|
600
586
|
* @this {ColorPicker}
|
601
587
|
*/
|
602
|
-
menuClickHandler(e: Event): void {
|
588
|
+
menuClickHandler = (e: Event): void => {
|
603
589
|
const { target } = e;
|
604
590
|
const { colorMenu } = this;
|
605
591
|
const newOption = (getAttribute(target as HTMLElement, 'data-value') || '').trim();
|
@@ -637,14 +623,14 @@ export default class ColorPicker {
|
|
637
623
|
}
|
638
624
|
firePickerChange(this);
|
639
625
|
}
|
640
|
-
}
|
626
|
+
};
|
641
627
|
|
642
628
|
/**
|
643
629
|
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
644
630
|
*
|
645
631
|
* @param e
|
646
632
|
*/
|
647
|
-
pointerDown(e: Event & { target: HTMLElement; pageX: number; pageY: number }) {
|
633
|
+
pointerDown = (e: Event & { target: HTMLElement; pageX: number; pageY: number }) => {
|
648
634
|
const { target, pageX, pageY } = e;
|
649
635
|
const { colorMenu, visuals, controlKnobs } = this;
|
650
636
|
const [v1, v2, v3] = visuals;
|
@@ -675,7 +661,7 @@ export default class ColorPicker {
|
|
675
661
|
}
|
676
662
|
}
|
677
663
|
e.preventDefault();
|
678
|
-
}
|
664
|
+
};
|
679
665
|
|
680
666
|
/**
|
681
667
|
* The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
|
@@ -683,7 +669,7 @@ export default class ColorPicker {
|
|
683
669
|
* @param e
|
684
670
|
* @this
|
685
671
|
*/
|
686
|
-
pointerUp({ target }: PointerEvent & { target: HTMLElement }) {
|
672
|
+
pointerUp = ({ target }: PointerEvent & { target: HTMLElement }) => {
|
687
673
|
const { parent } = this;
|
688
674
|
const doc = getDocument(parent);
|
689
675
|
const currentOpen = querySelector(`${colorPickerParentSelector}.open`, doc) !== null;
|
@@ -694,14 +680,14 @@ export default class ColorPicker {
|
|
694
680
|
}
|
695
681
|
|
696
682
|
this.dragElement = undefined;
|
697
|
-
}
|
683
|
+
};
|
698
684
|
|
699
685
|
/**
|
700
686
|
* The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
|
701
687
|
*
|
702
688
|
* @param {PointerEvent} e
|
703
689
|
*/
|
704
|
-
pointerMove(e: PointerEvent): void {
|
690
|
+
pointerMove = (e: PointerEvent): void => {
|
705
691
|
const { dragElement, visuals } = this;
|
706
692
|
const [v1, v2, v3] = visuals;
|
707
693
|
const { pageX, pageY } = e;
|
@@ -724,14 +710,14 @@ export default class ColorPicker {
|
|
724
710
|
if (dragElement === v3) {
|
725
711
|
this.changeAlpha(offsetY);
|
726
712
|
}
|
727
|
-
}
|
713
|
+
};
|
728
714
|
|
729
715
|
/**
|
730
716
|
* The `ColorPicker` *keydown* event listener for control knobs.
|
731
717
|
*
|
732
718
|
* @param e
|
733
719
|
*/
|
734
|
-
handleKnobs(e: Event & { code: string }) {
|
720
|
+
handleKnobs = (e: Event & { code: string }) => {
|
735
721
|
const { target, code } = e;
|
736
722
|
|
737
723
|
// only react to arrow buttons
|
@@ -777,10 +763,10 @@ export default class ColorPicker {
|
|
777
763
|
}
|
778
764
|
this.handleScroll(e);
|
779
765
|
}
|
780
|
-
}
|
766
|
+
};
|
781
767
|
|
782
768
|
/** The event listener of the colour form inputs. */
|
783
|
-
changeHandler(): void {
|
769
|
+
changeHandler = (): void => {
|
784
770
|
let colorSource;
|
785
771
|
const { inputs, format, value: currentValue, input, controlPositions, visuals } = this;
|
786
772
|
const { activeElement } = getDocument(input);
|
@@ -845,7 +831,7 @@ export default class ColorPicker {
|
|
845
831
|
this.value = currentValue;
|
846
832
|
}
|
847
833
|
}
|
848
|
-
}
|
834
|
+
};
|
849
835
|
|
850
836
|
/**
|
851
837
|
* Updates `ColorPicker` first control:
|
@@ -975,14 +961,14 @@ export default class ColorPicker {
|
|
975
961
|
* * initialization
|
976
962
|
* * window resize
|
977
963
|
*/
|
978
|
-
update() {
|
964
|
+
update = () => {
|
979
965
|
this.updateDropdownPosition();
|
980
966
|
this.updateAppearance();
|
981
967
|
this.setControlPositions();
|
982
968
|
this.updateInputs(true);
|
983
969
|
this.updateControls();
|
984
970
|
this.updateVisuals();
|
985
|
-
}
|
971
|
+
};
|
986
972
|
|
987
973
|
/** Updates the open dropdown position on *scroll* event. */
|
988
974
|
updateDropdownPosition() {
|
@@ -1155,7 +1141,7 @@ export default class ColorPicker {
|
|
1155
1141
|
*
|
1156
1142
|
* @param e
|
1157
1143
|
*/
|
1158
|
-
togglePicker(e?: Event) {
|
1144
|
+
togglePicker = (e?: Event) => {
|
1159
1145
|
if (e) e.preventDefault();
|
1160
1146
|
const { colorPicker } = this;
|
1161
1147
|
|
@@ -1164,16 +1150,16 @@ export default class ColorPicker {
|
|
1164
1150
|
} else {
|
1165
1151
|
showDropdown(this, colorPicker);
|
1166
1152
|
}
|
1167
|
-
}
|
1153
|
+
};
|
1168
1154
|
|
1169
1155
|
/** Shows the `ColorPicker` dropdown. */
|
1170
|
-
showPicker() {
|
1156
|
+
showPicker = () => {
|
1171
1157
|
const { colorPicker } = this;
|
1172
1158
|
|
1173
1159
|
if (!['top', 'bottom'].some(c => hasClass(colorPicker, c))) {
|
1174
1160
|
showDropdown(this, colorPicker);
|
1175
1161
|
}
|
1176
|
-
}
|
1162
|
+
};
|
1177
1163
|
|
1178
1164
|
/**
|
1179
1165
|
* Toggles the visibility of the `ColorPicker` presets menu.
|
@@ -1181,7 +1167,7 @@ export default class ColorPicker {
|
|
1181
1167
|
* @param e
|
1182
1168
|
* @this {ColorPicker}
|
1183
1169
|
*/
|
1184
|
-
toggleMenu(e?: Event) {
|
1170
|
+
toggleMenu = (e?: Event) => {
|
1185
1171
|
if (e) e.preventDefault();
|
1186
1172
|
const { colorMenu } = this;
|
1187
1173
|
|
@@ -1190,7 +1176,7 @@ export default class ColorPicker {
|
|
1190
1176
|
} else {
|
1191
1177
|
showDropdown(this, colorMenu);
|
1192
1178
|
}
|
1193
|
-
}
|
1179
|
+
};
|
1194
1180
|
|
1195
1181
|
/**
|
1196
1182
|
* Hides the currently open `ColorPicker` dropdown.
|
Binary file
|