@thednp/color-picker 2.0.0-alpha1 → 2.0.0-alpha10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/.eslintrc.cjs +1 -1
  2. package/.lgtm.yml +0 -0
  3. package/.prettierrc.json +0 -0
  4. package/.stylelintrc.json +0 -0
  5. package/LICENSE +0 -0
  6. package/README.md +8 -7
  7. package/compile.js +6 -3
  8. package/cypress/e2e/color-palette.cy.ts +0 -0
  9. package/cypress/e2e/color-picker.cy.ts +58 -69
  10. package/cypress/fixtures/colorNamesFrench.js +0 -0
  11. package/cypress/fixtures/componentLabelsFrench.js +0 -0
  12. package/cypress/fixtures/format.js +0 -0
  13. package/cypress/fixtures/getMarkup.js +8 -1
  14. package/cypress/fixtures/getRandomInt.js +0 -0
  15. package/cypress/fixtures/sampleWebcolors.js +0 -0
  16. package/cypress/fixtures/testSample.js +0 -0
  17. package/cypress/plugins/esbuild-istanbul.ts +0 -0
  18. package/cypress/plugins/tsCompile.ts +0 -0
  19. package/cypress/support/commands.ts +0 -0
  20. package/cypress/support/e2e.ts +0 -0
  21. package/cypress/test.html +0 -0
  22. package/cypress.config.ts +0 -0
  23. package/dist/css/color-picker.css +13 -18
  24. package/dist/css/color-picker.min.css +2 -2
  25. package/dist/css/color-picker.rtl.css +13 -18
  26. package/dist/css/color-picker.rtl.min.css +2 -2
  27. package/dist/js/color-picker.cjs +3 -3
  28. package/dist/js/color-picker.cjs.map +1 -1
  29. package/dist/js/color-picker.d.ts +42 -24
  30. package/dist/js/color-picker.js +3 -3
  31. package/dist/js/color-picker.js.map +1 -1
  32. package/dist/js/color-picker.mjs +408 -421
  33. package/dist/js/color-picker.mjs.map +1 -1
  34. package/dts.config.ts +0 -0
  35. package/package.json +116 -98
  36. package/src/scss/_variables.scss +0 -0
  37. package/src/scss/color-picker.rtl.scss +0 -0
  38. package/src/scss/color-picker.scss +20 -14
  39. package/src/ts/colorPalette.ts +0 -0
  40. package/src/ts/index.ts +40 -54
  41. package/src/ts/interface/ColorNames.ts +20 -0
  42. package/src/ts/interface/colorPickerLabels.ts +0 -0
  43. package/src/ts/interface/colorPickerOptions.ts +0 -0
  44. package/src/ts/interface/paletteOptions.ts +0 -0
  45. package/src/ts/util/colorNames.ts +0 -0
  46. package/src/ts/util/colorPickerLabels.ts +0 -0
  47. package/src/ts/util/getColorControls.ts +0 -0
  48. package/src/ts/util/getColorForm.ts +0 -0
  49. package/src/ts/util/getColorMenu.ts +0 -0
  50. package/src/ts/util/isValidJSON.ts +0 -0
  51. package/src/ts/util/setMarkup.ts +6 -4
  52. package/src/ts/util/vHidden.ts +0 -0
  53. package/tsconfig.json +1 -1
  54. package/vite.config.ts +0 -0
  55. package/cypress/downloads/downloads.htm +0 -0
  56. package/cypress/fixtures/getCEMarkup.js +0 -29
package/dts.config.ts CHANGED
File without changes
package/package.json CHANGED
@@ -1,98 +1,116 @@
1
- {
2
- "name": "@thednp/color-picker",
3
- "version": "2.0.0-alpha1",
4
- "author": "thednp",
5
- "license": "MIT",
6
- "description": "🎨 Modern Color Picker Component",
7
- "homepage": "http://thednp.github.io/color-picker",
8
- "source": "./src/ts/index.ts",
9
- "main": "./dist/js/color-picker.js",
10
- "module": "./dist/js/color-picker.mjs",
11
- "types": "./dist/js/color-picker.d.ts",
12
- "style": "./dist/css/color-picker.css",
13
- "sass": "./src/scss/color-picker.scss",
14
- "exports": {
15
- ".": {
16
- "require": "./dist/color-picker.cjs",
17
- "import": "./dist/color-picker.mjs"
18
- }
19
- },
20
- "scripts": {
21
- "pre-test": "npm run clean-coverage",
22
- "test": "npm run pre-test && cypress run",
23
- "cypress": "npm run pre-test && npx cypress open",
24
- "clean-coverage": "rimraf coverage .nyc_output",
25
- "coverage:report": "nyc report --reporter=lcov --reporter=json --reporter=text --reporter=json-summary",
26
- "format": "prettier --write \"src/**/*.ts\"",
27
- "fix:ts": "eslint src --config .eslintrc.cjs --fix",
28
- "lint:ts": "eslint src --config .eslintrc.cjs",
29
- "fix:css": "stylelint --config .stylelintrc.json --fix scss \"src/scss/*.scss\"",
30
- "lint:css": "stylelint --config .stylelintrc.json scss \"src/scss/*.scss\"",
31
- "build": "npm run lint:ts && npm run build-vite && npm run dts",
32
- "build-vite": "vite build && npm run docs",
33
- "dev": "vite --open ./docs/index.html --port 8577",
34
- "dts": "dts-bundle-generator --config ./dts.config.ts",
35
- "docs": "ncp dist/js/color-picker.js docs/js/color-picker.js && ncp dist/js/color-picker.js.map docs/js/color-picker.js.map",
36
- "copy": "npm-run-all --parallel copy-*",
37
- "copy-css-cp": "ncp dist/css/color-picker.css docs/css/color-picker.css",
38
- "copy-css-rtl": "ncp dist/css/color-picker.rtl.css docs/css/color-picker.rtl.css",
39
- "compile": "npm run lint:css && npm-run-all --parallel compile-* && npm run copy",
40
- "compile-scss": "node compile.js",
41
- "compile-scss-min": "node compile.js MIN:true",
42
- "compile-scss-rtl": "node compile.js MIN:false,DIR:rtl",
43
- "compile-scss-rtl-min": "node compile.js MIN:true,DIR:rtl"
44
- },
45
- "bugs": {
46
- "url": "https://github.com/thednp/color-picker/issues"
47
- },
48
- "publishConfig": {
49
- "access": "public",
50
- "registry": "https://registry.npmjs.org/"
51
- },
52
- "repository": {
53
- "type": "git",
54
- "url": "git+https://github.com/thednp/color-picker.git"
55
- },
56
- "keywords": [
57
- "color",
58
- "picker",
59
- "color-picker",
60
- "colorpicker",
61
- "palette",
62
- "color-palette",
63
- "typescript"
64
- ],
65
- "dependencies": {
66
- "@thednp/color": "^1.0.6",
67
- "@thednp/event-listener": "^2.0.0",
68
- "@thednp/shorty": "^2.0.0-alpha14"
69
- },
70
- "devDependencies": {
71
- "@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
72
- "@cypress/code-coverage": "^3.10.3",
73
- "@types/istanbul-lib-instrument": "^1.7.4",
74
- "@typescript-eslint/eslint-plugin": "^5.57.1",
75
- "@typescript-eslint/parser": "^5.57.1",
76
- "cypress": "^12.9.0",
77
- "dts-bundle-generator": "^8.0.0",
78
- "eslint": "^8.37.0",
79
- "eslint-plugin-jsdoc": "^40.1.1",
80
- "eslint-plugin-prefer-arrow": "^1.2.3",
81
- "eslint-plugin-prettier": "^4.2.1",
82
- "istanbul-lib-coverage": "^3.2.0",
83
- "istanbul-lib-instrument": "^5.2.1",
84
- "ncp": "^2.0.0",
85
- "npm-run-all": "^4.1.5",
86
- "nyc": "^15.1.0",
87
- "prettier": "^2.8.7",
88
- "rimraf": "^4.4.1",
89
- "sass": "^1.60.0",
90
- "stylelint": "^15.4.0",
91
- "stylelint-config-standard": "^32.0.0",
92
- "stylelint-config-standard-scss": "^7.0.1",
93
- "stylelint-order": "^6.0.3",
94
- "stylelint-scss": "^4.6.0",
95
- "typescript": "^5.0.3",
96
- "vite": "^4.3.9"
97
- }
98
- }
1
+ {
2
+ "name": "@thednp/color-picker",
3
+ "version": "2.0.0-alpha10",
4
+ "author": "thednp",
5
+ "license": "MIT",
6
+ "description": "🎨 Modern Color Picker Component",
7
+ "homepage": "http://thednp.github.io/color-picker",
8
+ "source": "./src/ts/index.ts",
9
+ "main": "./dist/js/color-picker.js",
10
+ "module": "./dist/js/color-picker.mjs",
11
+ "style": "./dist/css/color-picker.css",
12
+ "sass": "./src/scss/color-picker.scss",
13
+ "exports": {
14
+ ".": {
15
+ "require": "./dist/js/color-picker.cjs",
16
+ "import": "./dist/js/color-picker.mjs",
17
+ "types": "./dist/js/color-picker.d.ts"
18
+ },
19
+ "./dist/css/color-picker.css": {
20
+ "import": "./dist/css/color-picker.css",
21
+ "require": "./dist/css/color-picker.css"
22
+ },
23
+ "./dist/css/color-picker.rtl.css": {
24
+ "import": "./dist/css/color-picker.rtl.css",
25
+ "require": "./dist/css/color-picker.rtl.css"
26
+ },
27
+ "./src/scss/color-picker.scss": {
28
+ "import": "./src/scss/color-picker.scss",
29
+ "require": "./src/scss/color-picker.scss"
30
+ },
31
+ "./src/scss/color-picker.rtl.scss": {
32
+ "import": "./src/scss/color-picker.rtl.scss",
33
+ "require": "./src/scss/color-picker.rtl.scss"
34
+ }
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/thednp/color-picker/issues"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "registry": "https://registry.npmjs.org/"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/thednp/color-picker.git"
46
+ },
47
+ "keywords": [
48
+ "color",
49
+ "picker",
50
+ "color-picker",
51
+ "colorpicker",
52
+ "palette",
53
+ "color-palette",
54
+ "typescript"
55
+ ],
56
+ "dependencies": {
57
+ "@thednp/color": "^1.0.8",
58
+ "@thednp/shorty": "2.0.0-alpha22"
59
+ },
60
+ "devDependencies": {
61
+ "@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
62
+ "@cypress/code-coverage": "^3.12.0",
63
+ "@types/istanbul-lib-instrument": "^1.7.4",
64
+ "@typescript-eslint/eslint-plugin": "^6.6.0",
65
+ "@typescript-eslint/parser": "^6.6.0",
66
+ "cypress": "^13.1.0",
67
+ "dts-bundle-generator": "^8.0.1",
68
+ "eslint": "^8.49.0",
69
+ "eslint-plugin-jsdoc": "^46.5.1",
70
+ "eslint-plugin-prefer-arrow": "^1.2.3",
71
+ "eslint-plugin-prettier": "^5.0.0",
72
+ "istanbul-lib-coverage": "^3.2.0",
73
+ "istanbul-lib-instrument": "^6.0.0",
74
+ "ncp": "^2.0.0",
75
+ "npm-run-all": "^4.1.5",
76
+ "nyc": "^15.1.0",
77
+ "prettier": "^3.0.3",
78
+ "rimraf": "^5.0.1",
79
+ "sass": "^1.66.1",
80
+ "stylelint": "^15.10.3",
81
+ "stylelint-config-standard": "^34.0.0",
82
+ "stylelint-config-standard-scss": "^11.0.0",
83
+ "stylelint-order": "^6.0.3",
84
+ "stylelint-scss": "^5.1.0",
85
+ "typescript": "^5.2.2",
86
+ "vite": "^4.4.9"
87
+ },
88
+ "packageManager": "pnpm@8.6.12",
89
+ "scripts": {
90
+ "pre-test": "npm run clean-coverage",
91
+ "test": "npm run pre-test && cypress run",
92
+ "cypress": "npm run pre-test && npx cypress open",
93
+ "clean-coverage": "rimraf coverage .nyc_output",
94
+ "coverage:report": "nyc report --reporter=lcov --reporter=json --reporter=text --reporter=json-summary",
95
+ "format": "prettier --write \"src/**/*.ts\"",
96
+ "lint": "npm run lint:ts && npm run check:ts && npm run lint:css",
97
+ "fix:ts": "eslint src --config .eslintrc.cjs --fix",
98
+ "lint:ts": "eslint src --config .eslintrc.cjs",
99
+ "check:ts": "tsc --noEmit",
100
+ "fix:css": "stylelint --config .stylelintrc.json --fix scss \"src/scss/*.scss\"",
101
+ "lint:css": "stylelint --config .stylelintrc.json scss \"src/scss/*.scss\"",
102
+ "build": "npm run lint && npm run build-vite && npm run dts",
103
+ "build-vite": "vite build && npm run docs",
104
+ "dev": "vite --open ./docs/dev.html --port 8577",
105
+ "dts": "dts-bundle-generator --config ./dts.config.ts",
106
+ "docs": "ncp dist/js/color-picker.js docs/js/color-picker.js && ncp dist/js/color-picker.js.map docs/js/color-picker.js.map",
107
+ "copy": "npm-run-all --parallel copy-*",
108
+ "copy-css-cp": "ncp dist/css/color-picker.css docs/css/color-picker.css",
109
+ "copy-css-rtl": "ncp dist/css/color-picker.rtl.css docs/css/color-picker.rtl.css",
110
+ "compile": "npm run lint:css && npm-run-all --parallel compile-* && npm run copy",
111
+ "compile-scss": "node compile.js",
112
+ "compile-scss-min": "node compile.js MIN:true",
113
+ "compile-scss-rtl": "node compile.js MIN:false,DIR:rtl",
114
+ "compile-scss-rtl-min": "node compile.js MIN:true,DIR:rtl"
115
+ }
116
+ }
File without changes
File without changes
@@ -5,6 +5,10 @@
5
5
  position: relative;
6
6
  display: flex;
7
7
 
8
+ *, *::before, *::after {
9
+ box-sizing: border-box;
10
+ }
11
+
8
12
  @each $name in "white", "black" {
9
13
  @each $lvl in $transparency-levels {
10
14
  @if type-of($name) == "string" and type-of($lvl) == "number" {
@@ -64,7 +68,11 @@
64
68
  }
65
69
 
66
70
  .color-dropdown.picker { left: 0; }
67
- .color-dropdown.menu { right: 0; max-height: 230px; }
71
+
72
+ .color-dropdown.menu {
73
+ right: 0;
74
+ max-height: 230px;
75
+ }
68
76
 
69
77
  .open .color-dropdown.top {
70
78
  top: auto;
@@ -94,7 +102,8 @@
94
102
  /* btn-appearance */
95
103
  .btn-appearance {
96
104
  width: 100%;
97
- height: 1.5rem;
105
+
106
+ // height: 1.5rem;
98
107
  padding: .6rem 1rem;
99
108
  font-size: 1rem;
100
109
  line-height: 1.5;
@@ -147,10 +156,10 @@
147
156
  /* picker-toggle */
148
157
  .picker-toggle {
149
158
  position: absolute;
150
- top: 0;
151
- left: 0;
159
+ inset: 0;
152
160
  width: 100%;
153
161
  height: 100%;
162
+ cursor: pointer;
154
163
  background: transparent;
155
164
  border: 0;
156
165
  }
@@ -290,7 +299,8 @@
290
299
  transition: var(--options-transition);
291
300
  }
292
301
 
293
- .color-options.scrollable:hover {
302
+ // .color-options.scrollable:hover {
303
+ .color-dropdown.menu:hover .scrollable {
294
304
  height: var(--grid-hover-height);
295
305
  }
296
306
 
@@ -312,7 +322,7 @@
312
322
  width: var(--grid-item-size);
313
323
  height: var(--grid-item-size);
314
324
  overflow: hidden;
315
- text-indent: 2.1rem;
325
+ color: rgba(0,0,0,0%);
316
326
 
317
327
  &:active, &:focus {
318
328
  outline: none;
@@ -410,7 +420,7 @@
410
420
 
411
421
  /* visual control */
412
422
  .visual-control {
413
- height: 150px;
423
+ height: 230px;
414
424
 
415
425
  /* important for mobile devices */
416
426
  touch-action: none;
@@ -418,7 +428,7 @@
418
428
  }
419
429
 
420
430
  .visual-control1 {
421
- width: 150px;
431
+ width: 230px;
422
432
  }
423
433
 
424
434
  .visual-control2,
@@ -427,12 +437,7 @@
427
437
  cursor: ns-resize;
428
438
  }
429
439
 
430
- @media (min-width: 578px) {
431
- .visual-control { height: 230px; }
432
- .visual-control1 { width: 230px; }
433
- }
434
-
435
- @media (min-width: 1200px) {
440
+ @media (width >= 980px) {
436
441
  .visual-control { height: 300px; }
437
442
  .visual-control1 { width: 300px; }
438
443
  }
@@ -457,6 +462,7 @@
457
462
  position: absolute;
458
463
  top: 0;
459
464
  left: 0;
465
+ width: 100%;
460
466
  height: 7px;
461
467
 
462
468
  /* important for mobile devices */
File without changes
package/src/ts/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { addListener, removeListener } from '@thednp/event-listener';
2
-
3
1
  import {
4
2
  ariaDescription,
5
3
  ariaSelected,
@@ -37,6 +35,7 @@ import {
37
35
  getDocumentElement,
38
36
  getDocument,
39
37
  ObjectAssign,
38
+ ObjectFromEntries,
40
39
  Data,
41
40
  getInstance,
42
41
  setElementStyle,
@@ -52,6 +51,8 @@ import {
52
51
  isArray,
53
52
  isString,
54
53
  getWindow,
54
+ on,
55
+ off,
55
56
  } from '@thednp/shorty';
56
57
 
57
58
  // ColorPicker Util
@@ -67,6 +68,7 @@ import setMarkup from './util/setMarkup';
67
68
 
68
69
  import ColorPickerOptions from './interface/colorPickerOptions';
69
70
  import ColorPickerLabels from './interface/colorPickerLabels';
71
+ import type ColorNames from './interface/ColorNames';
70
72
  import { version } from '../../package.json';
71
73
 
72
74
  // ColorPicker GC
@@ -95,7 +97,7 @@ const initColorPicker = (element: HTMLInputElement) => new ColorPicker(element);
95
97
  * Add / remove `ColorPicker` main event listeners.
96
98
  */
97
99
  const toggleEvents = (self: ColorPicker, action?: boolean) => {
98
- const fn = action ? addListener : removeListener;
100
+ const fn = action ? on : off;
99
101
  const { input, pickerToggle, menuToggle } = self;
100
102
 
101
103
  fn(input, focusinEvent, self.showPicker);
@@ -110,7 +112,7 @@ const toggleEvents = (self: ColorPicker, action?: boolean) => {
110
112
  * Add / remove `ColorPicker` event listeners active only when open.
111
113
  */
112
114
  const toggleEventsOnShown = (self: ColorPicker, action?: boolean) => {
113
- const fn = action ? addListener : removeListener;
115
+ const fn = action ? on : off;
114
116
  const { input, colorMenu, parent } = self;
115
117
  const doc = getDocument(input);
116
118
  const win = getWindow(doc);
@@ -208,6 +210,8 @@ export default class ColorPicker {
208
210
  public static setAttribute = setAttribute;
209
211
  public static getBoundingClientRect = getBoundingClientRect;
210
212
  public static version = version;
213
+ public static colorNames = colorNames;
214
+ public static colorPickerLabels = colorPickerLabels;
211
215
 
212
216
  id: number;
213
217
  input: HTMLInputElement;
@@ -222,7 +226,7 @@ export default class ColorPicker {
222
226
  c2y: number;
223
227
  c3y: number;
224
228
  };
225
- colorLabels: Record<string, string> = {};
229
+ colorLabels: ColorNames = ObjectFromEntries(colorNames.map(c => [c, c])) as ColorNames;
226
230
  colorKeywords: string[] | false;
227
231
  colorPresets: ColorPalette | string[] | false;
228
232
  componentLabels: ColorPickerLabels;
@@ -263,7 +267,7 @@ export default class ColorPicker {
263
267
  c2y: 0,
264
268
  c3y: 0,
265
269
  };
266
- this.colorLabels = {};
270
+ // this.colorLabels = {};
267
271
  this.colorKeywords = false;
268
272
  this.colorPresets = false;
269
273
 
@@ -283,9 +287,7 @@ export default class ColorPicker {
283
287
  }
284
288
 
285
289
  // expose colour labels to all methods
286
- colorNames.forEach((c, i) => {
287
- this.colorLabels[c] = translatedColorLabels[i].trim();
288
- });
290
+ ObjectAssign(this.colorLabels, ObjectFromEntries(translatedColorLabels.map((c, i) => [colorNames[i], c])));
289
291
 
290
292
  // update and expose component labels
291
293
  const tempComponentLabels =
@@ -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,19 +511,18 @@ 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.
536
522
  *
537
523
  * @param e
538
- * @this {ColorPicker}
539
524
  */
540
- handleScroll(e: Event): void {
525
+ handleScroll = (e: Event) => {
541
526
  const { activeElement } = getDocument(this.input);
542
527
 
543
528
  this.updateDropdownPosition();
@@ -550,14 +535,14 @@ export default class ColorPicker {
550
535
  e.stopPropagation();
551
536
  e.preventDefault();
552
537
  }
553
- }
538
+ };
554
539
 
555
540
  /**
556
541
  * The `ColorPicker` keyboard event listener for menu navigation.
557
542
  *
558
543
  * @param e
559
544
  */
560
- menuKeyHandler(e: Event & { target: HTMLElement; code: string }) {
545
+ menuKeyHandler = (e: KeyboardEvent & { target: HTMLElement }) => {
561
546
  const { target, code } = e;
562
547
  const { previousElementSibling, nextElementSibling, parentElement } = target;
563
548
  const isColorOptionsMenu = parentElement && hasClass(parentElement, 'color-options');
@@ -591,7 +576,7 @@ export default class ColorPicker {
591
576
  if ([keyEnter, keySpace].includes(code)) {
592
577
  this.menuClickHandler(e);
593
578
  }
594
- }
579
+ };
595
580
 
596
581
  /**
597
582
  * The `ColorPicker` click event listener for the colour menu presets / defaults.
@@ -599,7 +584,7 @@ export default class ColorPicker {
599
584
  * @param e
600
585
  * @this {ColorPicker}
601
586
  */
602
- menuClickHandler(e: Event): void {
587
+ menuClickHandler = (e: Event) => {
603
588
  const { target } = e;
604
589
  const { colorMenu } = this;
605
590
  const newOption = (getAttribute(target as HTMLElement, 'data-value') || '').trim();
@@ -637,14 +622,15 @@ export default class ColorPicker {
637
622
  }
638
623
  firePickerChange(this);
639
624
  }
640
- }
625
+ };
641
626
 
642
627
  /**
643
628
  * The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
644
629
  *
645
630
  * @param e
646
631
  */
647
- pointerDown(e: Event & { target: HTMLElement; pageX: number; pageY: number }) {
632
+ pointerDown = (e: PointerEvent & { target: HTMLElement }) => {
633
+ if (e.button !== 0) return;
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) => {
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.