@thednp/color-picker 1.0.0 → 2.0.0-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/.eslintrc.cjs +199 -0
  2. package/.lgtm.yml +9 -0
  3. package/.prettierrc.json +15 -0
  4. package/.stylelintrc.json +236 -0
  5. package/LICENSE +0 -0
  6. package/README.md +63 -80
  7. package/compile.js +48 -0
  8. package/cypress/downloads/downloads.htm +0 -0
  9. package/cypress/e2e/color-palette.cy.ts +128 -0
  10. package/cypress/e2e/color-picker.cy.ts +920 -0
  11. package/cypress/fixtures/colorNamesFrench.js +3 -0
  12. package/cypress/fixtures/componentLabelsFrench.js +21 -0
  13. package/cypress/fixtures/format.js +3 -0
  14. package/cypress/fixtures/getCEMarkup.js +29 -0
  15. package/cypress/fixtures/getMarkup.js +28 -0
  16. package/cypress/fixtures/getRandomInt.js +6 -0
  17. package/cypress/fixtures/sampleWebcolors.js +18 -0
  18. package/cypress/fixtures/testSample.js +8 -0
  19. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  20. package/cypress/plugins/tsCompile.ts +34 -0
  21. package/cypress/support/commands.ts +0 -0
  22. package/cypress/support/e2e.ts +21 -0
  23. package/cypress/test.html +23 -0
  24. package/cypress.config.ts +29 -0
  25. package/dist/css/color-picker.css +15 -39
  26. package/dist/css/color-picker.min.css +2 -2
  27. package/dist/css/color-picker.rtl.css +15 -39
  28. package/dist/css/color-picker.rtl.min.css +2 -2
  29. package/dist/js/color-picker.cjs +8 -0
  30. package/dist/js/color-picker.cjs.map +1 -0
  31. package/dist/js/color-picker.d.ts +278 -0
  32. package/dist/js/color-picker.js +5 -3583
  33. package/dist/js/color-picker.js.map +1 -0
  34. package/dist/js/color-picker.mjs +2631 -0
  35. package/dist/js/color-picker.mjs.map +1 -0
  36. package/dts.config.ts +15 -0
  37. package/package.json +64 -74
  38. package/src/scss/_variables.scss +0 -1
  39. package/src/scss/color-picker.rtl.scss +4 -0
  40. package/src/scss/color-picker.scss +75 -39
  41. package/src/ts/colorPalette.ts +89 -0
  42. package/src/{js/color-picker.js → ts/index.ts} +492 -502
  43. package/src/ts/interface/colorPickerLabels.ts +20 -0
  44. package/src/ts/interface/colorPickerOptions.ts +11 -0
  45. package/src/ts/interface/paletteOptions.ts +6 -0
  46. package/src/ts/util/colorNames.ts +21 -0
  47. package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
  48. package/src/ts/util/getColorControls.ts +90 -0
  49. package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
  50. package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
  51. package/src/ts/util/isValidJSON.ts +19 -0
  52. package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +57 -48
  53. package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
  54. package/tsconfig.json +29 -0
  55. package/vite.config.ts +34 -0
  56. package/dist/js/color-esm.js +0 -1167
  57. package/dist/js/color-esm.min.js +0 -2
  58. package/dist/js/color-palette-esm.js +0 -1238
  59. package/dist/js/color-palette-esm.min.js +0 -2
  60. package/dist/js/color-palette.js +0 -1246
  61. package/dist/js/color-palette.min.js +0 -2
  62. package/dist/js/color-picker-element-esm.js +0 -3739
  63. package/dist/js/color-picker-element-esm.min.js +0 -2
  64. package/dist/js/color-picker-element.js +0 -3747
  65. package/dist/js/color-picker-element.min.js +0 -2
  66. package/dist/js/color-picker-esm.js +0 -3578
  67. package/dist/js/color-picker-esm.min.js +0 -2
  68. package/dist/js/color-picker.min.js +0 -2
  69. package/dist/js/color.js +0 -1175
  70. package/dist/js/color.min.js +0 -2
  71. package/src/js/color-palette.js +0 -75
  72. package/src/js/color-picker-element.js +0 -110
  73. package/src/js/color.js +0 -1107
  74. package/src/js/index.js +0 -3
  75. package/src/js/util/colorNames.js +0 -6
  76. package/src/js/util/getColorControls.js +0 -103
  77. package/src/js/util/isValidJSON.js +0 -13
  78. package/src/js/util/nonColors.js +0 -5
  79. package/src/js/util/roundPart.js +0 -9
  80. package/src/js/util/setCSSProperties.js +0 -12
  81. package/src/js/util/tabindex.js +0 -3
  82. package/src/js/util/toggleCEAttr.js +0 -70
  83. package/src/js/util/version.js +0 -6
  84. package/src/js/version.js +0 -6
  85. package/types/cp.d.ts +0 -544
  86. package/types/index.d.ts +0 -48
  87. package/types/source/source.ts +0 -5
  88. package/types/source/types.d.ts +0 -92
@@ -1,99 +1,100 @@
1
- import { addListener, removeListener } from '@thednp/event-listener/src/event-listener';
2
-
3
- import ariaDescription from 'shorter-js/src/strings/ariaDescription';
4
- import ariaSelected from 'shorter-js/src/strings/ariaSelected';
5
- import ariaExpanded from 'shorter-js/src/strings/ariaExpanded';
6
- import ariaValueText from 'shorter-js/src/strings/ariaValueText';
7
- import ariaValueNow from 'shorter-js/src/strings/ariaValueNow';
8
- import keyArrowDown from 'shorter-js/src/strings/keyArrowDown';
9
- import keyArrowUp from 'shorter-js/src/strings/keyArrowUp';
10
- import keyArrowLeft from 'shorter-js/src/strings/keyArrowLeft';
11
- import keyArrowRight from 'shorter-js/src/strings/keyArrowRight';
12
- import keyEnter from 'shorter-js/src/strings/keyEnter';
13
- import keySpace from 'shorter-js/src/strings/keySpace';
14
- import keyEscape from 'shorter-js/src/strings/keyEscape';
15
- import focusinEvent from 'shorter-js/src/strings/focusinEvent';
16
- import mouseclickEvent from 'shorter-js/src/strings/mouseclickEvent';
17
- import keydownEvent from 'shorter-js/src/strings/keydownEvent';
18
- import changeEvent from 'shorter-js/src/strings/changeEvent';
19
-
20
- import touchmoveEvent from 'shorter-js/src/strings/touchmoveEvent';
21
- import pointerdownEvent from 'shorter-js/src/strings/pointerdownEvent';
22
- import pointermoveEvent from 'shorter-js/src/strings/pointermoveEvent';
23
- import pointerupEvent from 'shorter-js/src/strings/pointerupEvent';
24
-
25
- import scrollEvent from 'shorter-js/src/strings/scrollEvent';
26
- import keyupEvent from 'shorter-js/src/strings/keyupEvent';
27
- import resizeEvent from 'shorter-js/src/strings/resizeEvent';
28
- import focusoutEvent from 'shorter-js/src/strings/focusoutEvent';
29
-
30
- import getDocument from 'shorter-js/src/get/getDocument';
31
- import getDocumentElement from 'shorter-js/src/get/getDocumentElement';
32
- import getElementStyle from 'shorter-js/src/get/getElementStyle';
33
- import getUID from 'shorter-js/src/get/getUID';
34
- import getBoundingClientRect from 'shorter-js/src/get/getBoundingClientRect';
35
- import getElementTransitionDuration from 'shorter-js/src/get/getElementTransitionDuration';
36
- import querySelector from 'shorter-js/src/selectors/querySelector';
37
- import closest from 'shorter-js/src/selectors/closest';
38
- import getElementsByClassName from 'shorter-js/src/selectors/getElementsByClassName';
39
- import dispatchEvent from 'shorter-js/src/misc/dispatchEvent';
40
- import ObjectAssign from 'shorter-js/src/misc/ObjectAssign';
41
- import Data, { getInstance } from 'shorter-js/src/misc/data';
42
- import setElementStyle from 'shorter-js/src/misc/setElementStyle';
43
- import normalizeOptions from 'shorter-js/src/misc/normalizeOptions';
44
- import reflow from 'shorter-js/src/misc/reflow';
45
- import focus from 'shorter-js/src/misc/focus';
46
- import hasClass from 'shorter-js/src/class/hasClass';
47
- import addClass from 'shorter-js/src/class/addClass';
48
- import removeClass from 'shorter-js/src/class/removeClass';
49
- import setAttribute from 'shorter-js/src/attr/setAttribute';
50
- import getAttribute from 'shorter-js/src/attr/getAttribute';
51
- import removeAttribute from 'shorter-js/src/attr/removeAttribute';
1
+ import { addListener, removeListener } from '@thednp/event-listener';
2
+
3
+ import {
4
+ ariaDescription,
5
+ ariaSelected,
6
+ ariaValueNow,
7
+ ariaValueText,
8
+ ariaExpanded,
9
+ keyArrowDown,
10
+ keyArrowUp,
11
+ keyArrowLeft,
12
+ keyArrowRight,
13
+ keyEnter,
14
+ keySpace,
15
+ keyEscape,
16
+ focusinEvent,
17
+ mouseclickEvent,
18
+ keydownEvent,
19
+ changeEvent,
20
+ touchmoveEvent,
21
+ pointerdownEvent,
22
+ pointermoveEvent,
23
+ pointerupEvent,
24
+ tabindex,
25
+ focusoutEvent,
26
+ resizeEvent,
27
+ keyupEvent,
28
+ scrollEvent,
29
+ dispatchEvent,
30
+ getElementsByClassName,
31
+ closest,
32
+ querySelector,
33
+ getElementTransitionDuration,
34
+ getBoundingClientRect,
35
+ getUID,
36
+ getElementStyle,
37
+ getDocumentElement,
38
+ getDocument,
39
+ ObjectAssign,
40
+ Data,
41
+ getInstance,
42
+ setElementStyle,
43
+ normalizeOptions,
44
+ reflow,
45
+ focus,
46
+ hasClass,
47
+ addClass,
48
+ removeClass,
49
+ setAttribute,
50
+ getAttribute,
51
+ removeAttribute,
52
+ isArray,
53
+ isString,
54
+ getWindow,
55
+ } from '@thednp/shorty';
52
56
 
53
57
  // ColorPicker Util
54
58
  // ================
55
- import Color from './color';
56
- import ColorPalette from './color-palette';
59
+ import Color from '@thednp/color';
60
+ import type { RGBA, HWBA, HSLA, HSVA } from '@thednp/color';
61
+
62
+ import ColorPalette from './colorPalette';
57
63
  import colorPickerLabels from './util/colorPickerLabels';
58
64
  import colorNames from './util/colorNames';
59
- import nonColors from './util/nonColors';
60
- import tabIndex from './util/tabindex';
61
65
  import isValidJSON from './util/isValidJSON';
62
- import roundPart from './util/roundPart';
63
66
  import setMarkup from './util/setMarkup';
64
- import Version from './util/version';
67
+
68
+ import ColorPickerOptions from './interface/colorPickerOptions';
69
+ import ColorPickerLabels from './interface/colorPickerLabels';
70
+ import { version } from '../../package.json';
65
71
 
66
72
  // ColorPicker GC
67
73
  // ==============
68
74
  const colorPickerString = 'color-picker';
69
75
  const colorPickerSelector = `[data-function="${colorPickerString}"]`;
70
- const colorPickerParentSelector = `.${colorPickerString},${colorPickerString}`;
71
- const colorPickerDefaults = {
76
+ const colorPickerParentSelector = `.${colorPickerString}`;
77
+ const colorPickerDefaults: ColorPickerOptions = {
72
78
  componentLabels: colorPickerLabels,
73
79
  colorLabels: colorNames,
74
80
  format: 'rgb',
75
81
  colorPresets: false,
76
82
  colorKeywords: false,
77
83
  };
84
+ const { roundPart, nonColors } = Color;
78
85
 
79
86
  // ColorPicker Static Methods
80
87
  // ==========================
81
-
82
- /** @type {CP.GetInstance<ColorPicker, HTMLInputElement>} */
83
- const getColorPickerInstance = (element) => getInstance(element, colorPickerString);
84
-
85
- /** @type {CP.InitCallback<ColorPicker>} */
86
- const initColorPicker = (element) => new ColorPicker(element);
88
+ const getColorPickerInstance = (element: HTMLInputElement) => getInstance<ColorPicker>(element, colorPickerString);
89
+ const initColorPicker = (element: HTMLInputElement) => new ColorPicker(element);
87
90
 
88
91
  // ColorPicker Private Methods
89
92
  // ===========================
90
93
 
91
94
  /**
92
95
  * Add / remove `ColorPicker` main event listeners.
93
- * @param {ColorPicker} self
94
- * @param {boolean=} action
95
96
  */
96
- function toggleEvents(self, action) {
97
+ const toggleEvents = (self: ColorPicker, action?: boolean) => {
97
98
  const fn = action ? addListener : removeListener;
98
99
  const { input, pickerToggle, menuToggle } = self;
99
100
 
@@ -103,70 +104,58 @@ function toggleEvents(self, action) {
103
104
  if (menuToggle) {
104
105
  fn(menuToggle, mouseclickEvent, self.toggleMenu);
105
106
  }
106
- }
107
+ };
107
108
 
108
109
  /**
109
110
  * Add / remove `ColorPicker` event listeners active only when open.
110
- * @param {ColorPicker} self
111
- * @param {boolean=} action
112
111
  */
113
- function toggleEventsOnShown(self, action) {
112
+ const toggleEventsOnShown = (self: ColorPicker, action?: boolean) => {
114
113
  const fn = action ? addListener : removeListener;
115
114
  const { input, colorMenu, parent } = self;
116
115
  const doc = getDocument(input);
117
- // const win = getWindow(input);
118
- const win = doc.defaultView;
116
+ const win = getWindow(doc);
119
117
 
120
- fn(self.controls, pointerdownEvent, self.pointerDown);
121
- self.controlKnobs.forEach((x) => fn(x, keydownEvent, self.handleKnobs));
118
+ fn(self.controls, pointerdownEvent, self.pointerDown as EventListener);
119
+ self.controlKnobs.forEach(x => fn(x, keydownEvent, self.handleKnobs as EventListener));
122
120
 
123
- // @ts-ignore -- this is `Window`
124
121
  fn(win, scrollEvent, self.handleScroll);
125
- // @ts-ignore -- this is `Window`
126
122
  fn(win, resizeEvent, self.update);
127
123
 
128
- [input, ...self.inputs].forEach((x) => fn(x, changeEvent, self.changeHandler));
124
+ [input, ...self.inputs].forEach(x => fn(x, changeEvent, self.changeHandler));
129
125
 
130
126
  if (colorMenu) {
131
127
  fn(colorMenu, mouseclickEvent, self.menuClickHandler);
132
- fn(colorMenu, keydownEvent, self.menuKeyHandler);
128
+ fn(colorMenu, keydownEvent, self.menuKeyHandler as EventListener);
133
129
  }
134
130
 
135
- fn(doc, pointermoveEvent, self.pointerMove);
136
- fn(doc, pointerupEvent, self.pointerUp);
137
- fn(parent, focusoutEvent, self.handleFocusOut);
138
- fn(doc, keyupEvent, self.handleDismiss);
139
- }
131
+ fn(doc, pointermoveEvent, self.pointerMove as EventListener);
132
+ fn(doc, pointerupEvent, self.pointerUp as EventListener);
133
+ fn(parent, focusoutEvent, self.handleFocusOut as EventListener);
134
+ fn(doc, keyupEvent, self.handleDismiss as EventListener);
135
+ };
140
136
 
141
137
  /**
142
138
  * Triggers the `ColorPicker` original event.
143
- * @param {ColorPicker} self
144
139
  */
145
- function firePickerChange(self) {
140
+ const firePickerChange = (self: ColorPicker) => {
146
141
  dispatchEvent(self.input, new CustomEvent('colorpicker.change'));
147
- }
142
+ };
148
143
 
149
144
  /**
150
145
  * Hides a visible dropdown.
151
- * @param {HTMLElement} element
152
- * @returns {void}
153
146
  */
154
- function removePosition(element) {
147
+ const removePosition = (element: HTMLElement) => {
155
148
  /* istanbul ignore else */
156
149
  if (element) {
157
- ['bottom', 'top'].forEach((x) => removeClass(element, x));
150
+ ['bottom', 'top'].forEach(x => removeClass(element, x));
158
151
  }
159
- }
152
+ };
160
153
 
161
154
  /**
162
155
  * Shows a `ColorPicker` dropdown and close the curent open dropdown.
163
- * @param {ColorPicker} self
164
- * @param {HTMLElement | Element} dropdown
165
156
  */
166
- function showDropdown(self, dropdown) {
167
- const {
168
- colorPicker, colorMenu, menuToggle, pickerToggle, parent,
169
- } = self;
157
+ const showDropdown = (self: ColorPicker, dropdown: HTMLElement) => {
158
+ const { colorPicker, colorMenu, menuToggle, pickerToggle, parent } = self;
170
159
  const isPicker = dropdown === colorPicker;
171
160
  const openDropdown = isPicker ? colorMenu : colorPicker;
172
161
  const activeBtn = isPicker ? menuToggle : pickerToggle;
@@ -189,9 +178,9 @@ function showDropdown(self, dropdown) {
189
178
  toggleEventsOnShown(self, true);
190
179
  self.updateDropdownPosition();
191
180
  self.isOpen = true;
192
- setAttribute(self.input, tabIndex, '0');
181
+ setAttribute(self.input, tabindex, '0');
193
182
  if (menuToggle) {
194
- setAttribute(menuToggle, tabIndex, '0');
183
+ setAttribute(menuToggle, tabindex, '0');
195
184
  }
196
185
  }
197
186
 
@@ -199,216 +188,247 @@ function showDropdown(self, dropdown) {
199
188
  if (activeBtn) {
200
189
  setAttribute(activeBtn, ariaExpanded, 'false');
201
190
  }
202
- }
191
+ };
203
192
 
204
193
  /**
205
194
  * Color Picker Web Component
195
+ *
206
196
  * @see http://thednp.github.io/color-picker
207
197
  */
208
198
  export default class ColorPicker {
199
+ // bring utils to staic
200
+ public static Color = Color;
201
+ public static ColorPalette = ColorPalette;
202
+ public static getInstance = getColorPickerInstance;
203
+ public static init = initColorPicker;
204
+ public static selector = colorPickerSelector;
205
+ // utils important for render
206
+ public static roundPart = roundPart;
207
+ public static setElementStyle = setElementStyle;
208
+ public static setAttribute = setAttribute;
209
+ public static getBoundingClientRect = getBoundingClientRect;
210
+ public static version = version;
211
+
212
+ id: number;
213
+ input: HTMLInputElement;
214
+ color: Color;
215
+ format = 'rgb';
216
+ parent: HTMLElement;
217
+ dragElement: HTMLElement | undefined;
218
+ isOpen = false;
219
+ controlPositions: {
220
+ c1x: number;
221
+ c1y: number;
222
+ c2y: number;
223
+ c3y: number;
224
+ };
225
+ colorLabels: Record<string, string> = {};
226
+ colorKeywords: string[] | false;
227
+ colorPresets: ColorPalette | string[] | false;
228
+ componentLabels: ColorPickerLabels;
229
+ pickerToggle: HTMLElement;
230
+ menuToggle: HTMLElement;
231
+ colorPicker: HTMLElement;
232
+ colorMenu: HTMLElement;
233
+ controls: HTMLElement;
234
+ inputs: HTMLInputElement[];
235
+ controlKnobs: HTMLElement[];
236
+ visuals: HTMLElement[];
237
+
209
238
  /**
210
239
  * Returns a new `ColorPicker` instance. The target of this constructor
211
240
  * must be an `HTMLInputElement`.
212
241
  *
213
- * @param {HTMLInputElement | string} target the target `<input>` element
214
- * @param {CP.ColorPickerOptions=} config instance options
242
+ * @param target the target `<input>` element
243
+ * @param config instance options
215
244
  */
216
- constructor(target, config) {
217
- const self = this;
218
- /** @type {HTMLInputElement} */
219
- // @ts-ignore
220
- const input = querySelector(target);
245
+ constructor(target: (HTMLElement & HTMLInputElement) | string, config?: Partial<ColorPickerOptions>) {
246
+ const input = querySelector(target) as HTMLInputElement;
221
247
 
222
248
  // invalidate
223
- if (!input) throw new TypeError(`ColorPicker target "${target}" cannot be found.`);
224
- self.input = input;
249
+ if (typeof target === 'undefined') throw new TypeError(`ColorPicker target not specified.`);
250
+ if (isString(target) && !input) throw new TypeError(`ColorPicker target "${target}" cannot be found.`);
251
+ this.input = input;
225
252
 
226
253
  const parent = closest(input, colorPickerParentSelector);
227
254
  if (!parent) throw new TypeError('ColorPicker requires a specific markup to work.');
228
255
 
229
- /** @type {HTMLElement} */
230
- // @ts-ignore
231
- self.parent = parent;
232
-
233
- /** @type {number} */
234
- self.id = getUID(input, colorPickerString);
235
-
236
- // set initial state
237
- /** @type {HTMLElement?} */
238
- self.dragElement = null;
239
- /** @type {boolean} */
240
- self.isOpen = false;
241
- /** @type {Record<string, number>} */
242
- self.controlPositions = {
243
- c1x: 0, c1y: 0, c2y: 0, c3y: 0,
256
+ this.parent = parent;
257
+ this.id = getUID(input, colorPickerString);
258
+ this.dragElement = undefined;
259
+ this.isOpen = false;
260
+ this.controlPositions = {
261
+ c1x: 0,
262
+ c1y: 0,
263
+ c2y: 0,
264
+ c3y: 0,
244
265
  };
245
- /** @type {Record<string, string>} */
246
- self.colorLabels = {};
247
- /** @type {string[]=} */
248
- self.colorKeywords = undefined;
249
- /** @type {(ColorPalette | string[])=} */
250
- self.colorPresets = undefined;
266
+ this.colorLabels = {};
267
+ this.colorKeywords = false;
268
+ this.colorPresets = false;
251
269
 
252
270
  // process options
253
- const {
254
- format, componentLabels, colorLabels, colorKeywords, colorPresets,
255
- } = normalizeOptions(this.isCE ? parent : input, colorPickerDefaults, config || {});
271
+ const { format, componentLabels, colorLabels, colorKeywords, colorPresets } = normalizeOptions(
272
+ input,
273
+ colorPickerDefaults,
274
+ config || {},
275
+ );
256
276
 
257
277
  let translatedColorLabels = colorNames;
258
278
  /* istanbul ignore else */
259
- if (colorLabels instanceof Array && colorLabels.length === 17) {
279
+ if (isArray(colorLabels) && colorLabels.length === 17) {
260
280
  translatedColorLabels = colorLabels;
261
- } else if (colorLabels && colorLabels.split(',').length === 17) {
281
+ } else if (isString(colorLabels) && colorLabels.split(',').length === 17) {
262
282
  translatedColorLabels = colorLabels.split(',');
263
283
  }
264
284
 
265
285
  // expose colour labels to all methods
266
286
  colorNames.forEach((c, i) => {
267
- self.colorLabels[c] = translatedColorLabels[i].trim();
287
+ this.colorLabels[c] = translatedColorLabels[i].trim();
268
288
  });
269
289
 
270
290
  // update and expose component labels
271
- const tempComponentLabels = componentLabels && isValidJSON(componentLabels)
272
- ? JSON.parse(componentLabels) : componentLabels;
273
-
274
- /** @type {Record<string, string>} */
275
- self.componentLabels = ObjectAssign({ ...colorPickerLabels }, tempComponentLabels);
276
-
277
- /** @type {Color} */
278
- self.color = new Color(input.value || '#fff', format);
279
-
280
- /** @type {CP.ColorFormats} */
281
- self.format = format;
291
+ const tempComponentLabels =
292
+ isString(componentLabels) && isValidJSON(componentLabels)
293
+ ? (JSON.parse(componentLabels) as ColorPickerLabels)
294
+ : componentLabels;
295
+ this.componentLabels = ObjectAssign({ ...colorPickerLabels }, tempComponentLabels);
296
+ this.color = new Color(input.value || '#fff', format);
297
+ this.format = format;
282
298
 
283
299
  // set colour defaults
284
- if (colorKeywords instanceof Array && colorKeywords.length) {
285
- self.colorKeywords = colorKeywords;
286
- } else if (typeof colorKeywords === 'string' && colorKeywords.length) {
287
- self.colorKeywords = colorKeywords.split(',').map((x) => x.trim());
300
+ if (isArray(colorKeywords) && colorKeywords.length) {
301
+ this.colorKeywords = colorKeywords;
302
+ } else if (isString(colorKeywords) && colorKeywords.length) {
303
+ this.colorKeywords = colorKeywords.split(',').map(x => x.trim());
288
304
  }
289
305
 
290
306
  // set colour presets
291
- if (colorPresets instanceof Array && colorPresets.length) {
292
- self.colorPresets = colorPresets;
293
- } else if (typeof colorPresets === 'string' && colorPresets.length) {
294
- if (isValidJSON(colorPresets)) {
295
- const { hue, hueSteps, lightSteps } = JSON.parse(colorPresets);
296
- self.colorPresets = new ColorPalette(hue, hueSteps, lightSteps);
297
- } else {
298
- self.colorPresets = colorPresets.split(',').map((x) => x.trim());
299
- }
307
+ if (isArray(colorPresets) && colorPresets.length) {
308
+ this.colorPresets = colorPresets;
309
+ } else if (colorPresets && isValidJSON(colorPresets)) {
310
+ const { hue, hueSteps, lightSteps, saturation } = JSON.parse(colorPresets) as {
311
+ hue: number;
312
+ hueSteps: number;
313
+ lightSteps: number;
314
+ saturation: number;
315
+ };
316
+ this.colorPresets = new ColorPalette(hue, hueSteps, lightSteps, saturation);
317
+ } else if (isString(colorPresets)) {
318
+ this.colorPresets = colorPresets.split(',').map((x: string) => x.trim());
300
319
  }
301
320
 
302
321
  // bind events
303
- self.showPicker = self.showPicker.bind(self);
304
- self.togglePicker = self.togglePicker.bind(self);
305
- self.toggleMenu = self.toggleMenu.bind(self);
306
- self.menuClickHandler = self.menuClickHandler.bind(self);
307
- self.menuKeyHandler = self.menuKeyHandler.bind(self);
308
- self.pointerDown = self.pointerDown.bind(self);
309
- self.pointerMove = self.pointerMove.bind(self);
310
- self.pointerUp = self.pointerUp.bind(self);
311
- self.update = self.update.bind(self);
312
- self.handleScroll = self.handleScroll.bind(self);
313
- self.handleFocusOut = self.handleFocusOut.bind(self);
314
- self.changeHandler = self.changeHandler.bind(self);
315
- self.handleDismiss = self.handleDismiss.bind(self);
316
- self.handleKnobs = self.handleKnobs.bind(self);
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);
317
336
 
318
337
  // generate markup
319
- setMarkup(self);
338
+ setMarkup(this);
320
339
 
321
340
  const [colorPicker, colorMenu] = getElementsByClassName('color-dropdown', parent);
322
341
  // set main elements
323
- /** @type {HTMLElement} */
324
- // @ts-ignore
325
- self.pickerToggle = querySelector('.picker-toggle', parent);
326
- /** @type {HTMLElement} */
327
- // @ts-ignore
328
- self.menuToggle = querySelector('.menu-toggle', parent);
329
- /** @type {HTMLElement} */
330
- // @ts-ignore
331
- self.colorPicker = colorPicker;
332
- /** @type {HTMLElement} */
333
- // @ts-ignore
334
- self.colorMenu = colorMenu;
335
- /** @type {HTMLInputElement[]} */
336
- // @ts-ignore
337
- self.inputs = [...getElementsByClassName('color-input', parent)];
342
+ this.pickerToggle = querySelector('.picker-toggle', parent) as HTMLElement;
343
+ this.menuToggle = querySelector('.menu-toggle', parent) as HTMLElement;
344
+ this.colorPicker = colorPicker;
345
+ this.colorMenu = colorMenu;
346
+ this.inputs = [...getElementsByClassName('color-input', parent)] as HTMLInputElement[];
338
347
  const [controls] = getElementsByClassName('color-controls', parent);
339
- self.controls = controls;
340
- /** @type {(HTMLElement | Element)[]} */
341
- self.controlKnobs = [...getElementsByClassName('knob', controls)];
342
- /** @type {(HTMLElement)[]} */
343
- // @ts-ignore
344
- self.visuals = [...getElementsByClassName('visual-control', controls)];
348
+ this.controls = controls;
349
+ this.controlKnobs = [...getElementsByClassName('knob', controls)];
350
+ this.visuals = [...getElementsByClassName('visual-control', controls)];
345
351
 
346
352
  // update colour picker controls, inputs and visuals
347
- self.update();
353
+ this.update();
354
+ // console.log(this)
348
355
 
349
356
  // add main events listeners
350
- toggleEvents(self, true);
357
+ toggleEvents(this, true);
351
358
 
352
359
  // set component data
353
- Data.set(input, colorPickerString, self);
360
+ Data.set(input, colorPickerString, this);
354
361
  }
355
362
 
356
363
  /** Returns the current colour value */
357
- get value() { return this.input.value; }
364
+ get value(): string {
365
+ return this.input.value;
366
+ }
358
367
 
359
368
  /**
360
369
  * Sets a new colour value.
370
+ *
361
371
  * @param {string} v new colour value
362
372
  */
363
- set value(v) { this.input.value = v; }
373
+ set value(v: string) {
374
+ this.input.value = v;
375
+ }
364
376
 
365
377
  /** Check if the colour presets include any non-colour. */
366
- get hasNonColor() {
367
- return this.colorKeywords instanceof Array
368
- && this.colorKeywords.some((x) => nonColors.includes(x));
378
+ get hasNonColor(): boolean {
379
+ return this.colorKeywords instanceof Array && this.colorKeywords.some(x => nonColors.includes(x));
369
380
  }
370
381
 
371
- /** Check if the parent of the target is a `ColorPickerElement` instance. */
372
- get isCE() { return this.parent.localName === colorPickerString; }
373
-
374
382
  /** Returns hexadecimal value of the current colour. */
375
- get hex() { return this.color.toHex(true); }
383
+ get hex(): string {
384
+ return this.color.toHex(true);
385
+ }
376
386
 
377
387
  /** Returns the current colour value in {h,s,v,a} object format. */
378
- get hsv() { return this.color.toHsv(); }
388
+ get hsv(): HSVA {
389
+ return this.color.toHsv();
390
+ }
379
391
 
380
392
  /** Returns the current colour value in {h,s,l,a} object format. */
381
- get hsl() { return this.color.toHsl(); }
393
+ get hsl(): HSLA {
394
+ return this.color.toHsl();
395
+ }
382
396
 
383
397
  /** Returns the current colour value in {h,w,b,a} object format. */
384
- get hwb() { return this.color.toHwb(); }
398
+ get hwb(): HWBA {
399
+ return this.color.toHwb();
400
+ }
385
401
 
386
402
  /** Returns the current colour value in {r,g,b,a} object format. */
387
- get rgb() { return this.color.toRgb(); }
403
+ get rgb(): RGBA {
404
+ return this.color.toRgb();
405
+ }
388
406
 
389
407
  /** Returns the current colour brightness. */
390
- get brightness() { return this.color.brightness; }
408
+ get brightness(): number {
409
+ return this.color.brightness;
410
+ }
391
411
 
392
412
  /** Returns the current colour luminance. */
393
- get luminance() { return this.color.luminance; }
413
+ get luminance(): number {
414
+ return this.color.luminance;
415
+ }
394
416
 
395
417
  /** Checks if the current colour requires a light text colour. */
396
- get isDark() {
418
+ get isDark(): boolean {
397
419
  const { color, brightness } = this;
398
420
  return brightness < 120 && color.a > 0.33;
399
421
  }
400
422
 
401
423
  /** Checks if the current input value is a valid colour. */
402
- get isValid() {
424
+ get isValid(): boolean {
403
425
  const inputValue = this.input.value;
404
426
  return inputValue !== '' && new Color(inputValue).isValid;
405
427
  }
406
428
 
407
429
  /** Returns the colour appearance, usually the closest colour name for the current value. */
408
- get appearance() {
409
- const {
410
- colorLabels, hsl, hsv, format,
411
- } = this;
430
+ get appearance(): string {
431
+ const { colorLabels, hsl, hsv, format } = this;
412
432
 
413
433
  const hue = roundPart(hsl.h * 360);
414
434
  const saturationSource = format === 'hsl' ? hsl.s : hsv.s;
@@ -416,7 +436,7 @@ export default class ColorPicker {
416
436
  const lightness = roundPart(hsl.l * 100);
417
437
  const hsvl = hsv.v * 100;
418
438
 
419
- let colorName;
439
+ let colorName = 'black';
420
440
 
421
441
  // determine color appearance
422
442
  /* istanbul ignore else */
@@ -454,21 +474,21 @@ export default class ColorPicker {
454
474
  }
455
475
 
456
476
  /** Updates `ColorPicker` visuals. */
457
- updateVisuals() {
458
- const self = this;
459
- const {
460
- controlPositions, visuals,
461
- } = self;
477
+ updateVisuals(): void {
478
+ const { controlPositions, visuals } = this;
462
479
  const [v1, v2, v3] = visuals;
463
480
  const { offsetHeight } = v1;
464
481
  const hue = controlPositions.c2y / offsetHeight;
465
482
  const { r, g, b } = new Color({ h: hue, s: 1, l: 0.5 }).toRgb();
466
483
  const whiteGrad = 'linear-gradient(rgb(255,255,255) 0%, rgb(255,255,255) 100%)';
467
484
  const alpha = 1 - controlPositions.c3y / offsetHeight;
468
- const roundA = roundPart((alpha * 100)) / 100;
485
+ const roundA = roundPart(alpha * 100) / 100;
469
486
 
470
487
  const fill = new Color({
471
- h: hue, s: 1, l: 0.5, a: alpha,
488
+ h: hue,
489
+ s: 1,
490
+ l: 0.5,
491
+ a: alpha,
472
492
  }).toRgbString();
473
493
  const hueGradient = `linear-gradient(
474
494
  rgb(255,0,0) 0%, rgb(255,255,0) 16.67%,
@@ -489,11 +509,11 @@ export default class ColorPicker {
489
509
 
490
510
  /**
491
511
  * The `ColorPicker` *focusout* event listener when open.
492
- * @param {FocusEvent} e
512
+ *
513
+ * @param e
493
514
  * @this {ColorPicker}
494
515
  */
495
- handleFocusOut({ relatedTarget }) {
496
- // @ts-ignore
516
+ handleFocusOut({ relatedTarget }: FocusEvent & { relatedTarget: HTMLElement }): void {
497
517
  if (relatedTarget && !this.parent.contains(relatedTarget)) {
498
518
  this.hide(true);
499
519
  }
@@ -501,30 +521,32 @@ export default class ColorPicker {
501
521
 
502
522
  /**
503
523
  * The `ColorPicker` *keyup* event listener when open.
504
- * @param {KeyboardEvent} e
524
+ *
525
+ * @param e
505
526
  * @this {ColorPicker}
506
527
  */
507
- handleDismiss({ code }) {
508
- const self = this;
509
- if (self.isOpen && code === keyEscape) {
510
- self.hide();
528
+ handleDismiss({ code }: KeyboardEvent): void {
529
+ if (this.isOpen && code === keyEscape) {
530
+ this.hide();
511
531
  }
512
532
  }
513
533
 
514
534
  /**
515
535
  * The `ColorPicker` *scroll* event listener when open.
516
- * @param {Event} e
536
+ *
537
+ * @param e
517
538
  * @this {ColorPicker}
518
539
  */
519
- handleScroll(e) {
520
- const self = this;
521
- const { activeElement } = getDocument(self.input);
540
+ handleScroll(e: Event): void {
541
+ const { activeElement } = getDocument(this.input);
522
542
 
523
- self.updateDropdownPosition();
543
+ this.updateDropdownPosition();
524
544
 
525
545
  /* istanbul ignore next */
526
- if (([pointermoveEvent, touchmoveEvent].includes(e.type) && self.dragElement)
527
- || (activeElement && self.controlKnobs.includes(activeElement))) {
546
+ if (
547
+ ([pointermoveEvent, touchmoveEvent].includes(e.type) && this.dragElement) ||
548
+ (activeElement && this.controlKnobs.includes(activeElement as HTMLElement))
549
+ ) {
528
550
  e.stopPropagation();
529
551
  e.preventDefault();
530
552
  }
@@ -532,22 +554,19 @@ export default class ColorPicker {
532
554
 
533
555
  /**
534
556
  * The `ColorPicker` keyboard event listener for menu navigation.
535
- * @param {KeyboardEvent} e
536
- * @this {ColorPicker}
557
+ *
558
+ * @param e
537
559
  */
538
- menuKeyHandler(e) {
560
+ menuKeyHandler(e: Event & { target: HTMLElement; code: string }) {
539
561
  const { target, code } = e;
540
- // @ts-ignore
541
562
  const { previousElementSibling, nextElementSibling, parentElement } = target;
542
563
  const isColorOptionsMenu = parentElement && hasClass(parentElement, 'color-options');
543
- const allSiblings = [...parentElement.children];
544
- const columnsCount = isColorOptionsMenu
545
- && getElementStyle(parentElement, 'grid-template-columns').split(' ').length;
564
+ const allSiblings = parentElement ? [...parentElement.children] : [];
565
+ const columnsCount =
566
+ isColorOptionsMenu && getElementStyle(parentElement, 'grid-template-columns').split(' ').length;
546
567
  const currentIndex = allSiblings.indexOf(target);
547
- const previousElement = currentIndex > -1
548
- && columnsCount && allSiblings[currentIndex - columnsCount];
549
- const nextElement = currentIndex > -1
550
- && columnsCount && allSiblings[currentIndex + columnsCount];
568
+ const previousElement = currentIndex > -1 && columnsCount && allSiblings[currentIndex - columnsCount];
569
+ const nextElement = currentIndex > -1 && columnsCount && allSiblings[currentIndex + columnsCount];
551
570
 
552
571
  if ([keyArrowDown, keyArrowUp, keySpace].includes(code)) {
553
572
  // prevent scroll when navigating the menu via arrow keys / Space
@@ -555,51 +574,52 @@ export default class ColorPicker {
555
574
  }
556
575
  if (isColorOptionsMenu) {
557
576
  if (previousElement && code === keyArrowUp) {
558
- focus(previousElement);
577
+ focus(previousElement as HTMLElement);
559
578
  } else if (nextElement && code === keyArrowDown) {
560
- focus(nextElement);
579
+ focus(nextElement as HTMLElement);
561
580
  } else if (previousElementSibling && code === keyArrowLeft) {
562
- focus(previousElementSibling);
581
+ focus(previousElementSibling as HTMLElement);
563
582
  } else if (nextElementSibling && code === keyArrowRight) {
564
- focus(nextElementSibling);
583
+ focus(nextElementSibling as HTMLElement);
565
584
  }
566
585
  } else if (previousElementSibling && [keyArrowLeft, keyArrowUp].includes(code)) {
567
- focus(previousElementSibling);
586
+ focus(previousElementSibling as HTMLElement);
568
587
  } else if (nextElementSibling && [keyArrowRight, keyArrowDown].includes(code)) {
569
- focus(nextElementSibling);
588
+ focus(nextElementSibling as HTMLElement);
570
589
  }
571
590
 
572
591
  if ([keyEnter, keySpace].includes(code)) {
573
- this.menuClickHandler({ target });
592
+ this.menuClickHandler(e);
574
593
  }
575
594
  }
576
595
 
577
596
  /**
578
597
  * The `ColorPicker` click event listener for the colour menu presets / defaults.
579
- * @param {Partial<Event>} e
598
+ *
599
+ * @param e
580
600
  * @this {ColorPicker}
581
601
  */
582
- menuClickHandler(e) {
583
- const self = this;
584
- /** @type {*} */
602
+ menuClickHandler(e: Event): void {
585
603
  const { target } = e;
586
- const { colorMenu } = self;
587
- const newOption = (getAttribute(target, 'data-value') || '').trim();
604
+ const { colorMenu } = this;
605
+ const newOption = (getAttribute(target as HTMLElement, 'data-value') || '').trim();
588
606
  // invalidate for targets other than color options
589
607
  if (!newOption.length) return;
590
608
  const currentActive = querySelector('li.active', colorMenu);
591
- let newColor = nonColors.includes(newOption) ? 'white' : newOption;
592
- newColor = newOption === 'transparent' ? 'rgba(0,0,0,0)' : newOption;
609
+ let newColor = newOption;
610
+ newColor = nonColors.includes(newColor) ? 'white' : newColor;
611
+ newColor = newColor === 'transparent' ? 'rgba(0,0,0,0)' : newColor;
593
612
 
594
- const {
595
- r, g, b, a,
596
- } = new Color(newColor);
613
+ const { r, g, b, a } = new Color(newColor);
597
614
 
598
- ObjectAssign(self.color, {
599
- r, g, b, a,
615
+ ObjectAssign(this.color, {
616
+ r,
617
+ g,
618
+ b,
619
+ a,
600
620
  });
601
621
 
602
- self.update();
622
+ this.update();
603
623
 
604
624
  /* istanbul ignore else */
605
625
  if (currentActive !== target) {
@@ -609,30 +629,27 @@ export default class ColorPicker {
609
629
  removeAttribute(currentActive, ariaSelected);
610
630
  }
611
631
 
612
- addClass(target, 'active');
613
- setAttribute(target, ariaSelected, 'true');
632
+ addClass(target as HTMLElement, 'active');
633
+ setAttribute(target as HTMLElement, ariaSelected, 'true');
614
634
 
615
635
  if (nonColors.includes(newOption)) {
616
- self.value = newOption;
636
+ this.value = newOption;
617
637
  }
618
- firePickerChange(self);
638
+ firePickerChange(this);
619
639
  }
620
640
  }
621
641
 
622
642
  /**
623
643
  * The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
624
- * @param {PointerEvent} e
625
- * @this {ColorPicker}
644
+ *
645
+ * @param e
626
646
  */
627
- pointerDown(e) {
628
- const self = this;
629
- /** @type {*} */
647
+ pointerDown(e: Event & { target: HTMLElement; pageX: number; pageY: number }) {
630
648
  const { target, pageX, pageY } = e;
631
- const { colorMenu, visuals, controlKnobs } = self;
649
+ const { colorMenu, visuals, controlKnobs } = this;
632
650
  const [v1, v2, v3] = visuals;
633
651
  const [c1, c2, c3] = controlKnobs;
634
- /** @type {HTMLElement} */
635
- const visual = controlKnobs.includes(target) ? target.previousElementSibling : target;
652
+ const visual = controlKnobs.includes(target) ? (target.previousElementSibling as HTMLElement) : target;
636
653
  const visualRect = getBoundingClientRect(visual);
637
654
  const html = getDocumentElement(v1);
638
655
  const offsetX = pageX - html.scrollLeft - visualRect.left;
@@ -640,14 +657,14 @@ export default class ColorPicker {
640
657
 
641
658
  /* istanbul ignore else */
642
659
  if (target === v1 || target === c1) {
643
- self.dragElement = visual;
644
- self.changeControl1(offsetX, offsetY);
660
+ this.dragElement = visual;
661
+ this.changeControl1(offsetX, offsetY);
645
662
  } else if (target === v2 || target === c2) {
646
- self.dragElement = visual;
647
- self.changeControl2(offsetY);
663
+ this.dragElement = visual;
664
+ this.changeControl2(offsetY);
648
665
  } else if (target === v3 || target === c3) {
649
- self.dragElement = visual;
650
- self.changeAlpha(offsetY);
666
+ this.dragElement = visual;
667
+ this.changeAlpha(offsetY);
651
668
  }
652
669
 
653
670
  if (colorMenu) {
@@ -662,31 +679,30 @@ export default class ColorPicker {
662
679
 
663
680
  /**
664
681
  * The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
665
- * @param {PointerEvent} e
666
- * @this {ColorPicker}
682
+ *
683
+ * @param e
684
+ * @this
667
685
  */
668
- pointerUp({ target }) {
669
- const self = this;
670
- const { parent } = self;
686
+ pointerUp({ target }: PointerEvent & { target: HTMLElement }) {
687
+ const { parent } = this;
671
688
  const doc = getDocument(parent);
672
689
  const currentOpen = querySelector(`${colorPickerParentSelector}.open`, doc) !== null;
673
690
  const selection = doc.getSelection();
674
691
 
675
- if (!self.dragElement && !selection.toString().length
676
- && !parent.contains(target)) {
677
- self.hide(currentOpen);
692
+ if (!this.dragElement && (!selection || !selection.toString().length) && !parent.contains(target)) {
693
+ this.hide(currentOpen);
678
694
  }
679
695
 
680
- self.dragElement = null;
696
+ this.dragElement = undefined;
681
697
  }
682
698
 
683
699
  /**
684
700
  * The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
701
+ *
685
702
  * @param {PointerEvent} e
686
703
  */
687
- pointerMove(e) {
688
- const self = this;
689
- const { dragElement, visuals } = self;
704
+ pointerMove(e: PointerEvent): void {
705
+ const { dragElement, visuals } = this;
690
706
  const [v1, v2, v3] = visuals;
691
707
  const { pageX, pageY } = e;
692
708
 
@@ -698,35 +714,35 @@ export default class ColorPicker {
698
714
  const offsetY = pageY - win.scrollTop - controlRect.top;
699
715
 
700
716
  if (dragElement === v1) {
701
- self.changeControl1(offsetX, offsetY);
717
+ this.changeControl1(offsetX, offsetY);
702
718
  }
703
719
 
704
720
  if (dragElement === v2) {
705
- self.changeControl2(offsetY);
721
+ this.changeControl2(offsetY);
706
722
  }
707
723
 
708
724
  if (dragElement === v3) {
709
- self.changeAlpha(offsetY);
725
+ this.changeAlpha(offsetY);
710
726
  }
711
727
  }
712
728
 
713
729
  /**
714
730
  * The `ColorPicker` *keydown* event listener for control knobs.
715
- * @param {KeyboardEvent} e
731
+ *
732
+ * @param e
716
733
  */
717
- handleKnobs(e) {
734
+ handleKnobs(e: Event & { code: string }) {
718
735
  const { target, code } = e;
719
- const self = this;
720
736
 
721
737
  // only react to arrow buttons
722
738
  if (![keyArrowUp, keyArrowDown, keyArrowLeft, keyArrowRight].includes(code)) return;
723
739
  e.preventDefault();
724
740
 
725
- const { controlKnobs, visuals } = self;
741
+ const { controlKnobs, visuals } = this;
726
742
  const { offsetWidth, offsetHeight } = visuals[0];
727
743
  const [c1, c2, c3] = controlKnobs;
728
744
  const { activeElement } = getDocument(c1);
729
- const currentKnob = controlKnobs.find((x) => x === activeElement);
745
+ const currentKnob = controlKnobs.find(x => x === activeElement);
730
746
  const yRatio = offsetHeight / 360;
731
747
 
732
748
  /* istanbul ignore else */
@@ -740,52 +756,45 @@ export default class ColorPicker {
740
756
 
741
757
  /* istanbul ignore else */
742
758
  if ([keyArrowLeft, keyArrowRight].includes(code)) {
743
- self.controlPositions.c1x += code === keyArrowRight ? xRatio : -xRatio;
759
+ this.controlPositions.c1x += code === keyArrowRight ? xRatio : -xRatio;
744
760
  } else if ([keyArrowUp, keyArrowDown].includes(code)) {
745
- self.controlPositions.c1y += code === keyArrowDown ? yRatio : -yRatio;
761
+ this.controlPositions.c1y += code === keyArrowDown ? yRatio : -yRatio;
746
762
  }
747
763
 
748
- offsetX = self.controlPositions.c1x;
749
- offsetY = self.controlPositions.c1y;
750
- self.changeControl1(offsetX, offsetY);
764
+ offsetX = this.controlPositions.c1x;
765
+ offsetY = this.controlPositions.c1y;
766
+ this.changeControl1(offsetX, offsetY);
751
767
  } else if (target === c2) {
752
- self.controlPositions.c2y += [keyArrowDown, keyArrowRight].includes(code)
753
- ? yRatio
754
- : -yRatio;
768
+ this.controlPositions.c2y += [keyArrowDown, keyArrowRight].includes(code) ? yRatio : -yRatio;
755
769
 
756
- offsetY = self.controlPositions.c2y;
757
- self.changeControl2(offsetY);
770
+ offsetY = this.controlPositions.c2y;
771
+ this.changeControl2(offsetY);
758
772
  } else if (target === c3) {
759
- self.controlPositions.c3y += [keyArrowDown, keyArrowRight].includes(code)
760
- ? yRatio
761
- : -yRatio;
773
+ this.controlPositions.c3y += [keyArrowDown, keyArrowRight].includes(code) ? yRatio : -yRatio;
762
774
 
763
- offsetY = self.controlPositions.c3y;
764
- self.changeAlpha(offsetY);
775
+ offsetY = this.controlPositions.c3y;
776
+ this.changeAlpha(offsetY);
765
777
  }
766
- self.handleScroll(e);
778
+ this.handleScroll(e);
767
779
  }
768
780
  }
769
781
 
770
782
  /** The event listener of the colour form inputs. */
771
- changeHandler() {
772
- const self = this;
783
+ changeHandler(): void {
773
784
  let colorSource;
774
- const {
775
- inputs, format, value: currentValue, input, controlPositions, visuals,
776
- } = self;
777
- /** @type {*} */
785
+ const { inputs, format, value: currentValue, input, controlPositions, visuals } = this;
778
786
  const { activeElement } = getDocument(input);
779
787
  const { offsetHeight } = visuals[0];
780
- const [i1,,, i4] = inputs;
781
- const [v1, v2, v3, v4] = format === 'rgb'
782
- ? inputs.map((i) => parseFloat(i.value) / (i === i4 ? 100 : 1))
783
- : inputs.map((i) => parseFloat(i.value) / (i !== i1 ? 100 : 360));
784
- const isNonColorValue = self.hasNonColor && nonColors.includes(currentValue);
785
- const alpha = i4 ? v4 : (1 - controlPositions.c3y / offsetHeight);
788
+ const [i1, , , i4] = inputs;
789
+ const [v1, v2, v3, v4] =
790
+ format === 'rgb'
791
+ ? inputs.map(i => parseFloat(i.value) / (i === i4 ? 100 : 1))
792
+ : inputs.map(i => parseFloat(i.value) / (i !== i1 ? 100 : 360));
793
+ const isNonColorValue = this.hasNonColor && nonColors.includes(currentValue);
794
+ const alpha = i4 ? v4 : 1 - controlPositions.c3y / offsetHeight;
786
795
 
787
796
  /* istanbul ignore else */
788
- if (activeElement === input || (activeElement && inputs.includes(activeElement))) {
797
+ if (activeElement === input || (activeElement && inputs.includes(activeElement as HTMLInputElement))) {
789
798
  if (activeElement === input) {
790
799
  if (isNonColorValue) {
791
800
  colorSource = currentValue === 'transparent' ? 'rgba(0,0,0,0)' : 'rgb(0,0,0)';
@@ -796,34 +805,44 @@ export default class ColorPicker {
796
805
  colorSource = i1.value;
797
806
  } else if (format === 'hsl') {
798
807
  colorSource = {
799
- h: v1, s: v2, l: v3, a: alpha,
808
+ h: v1,
809
+ s: v2,
810
+ l: v3,
811
+ a: alpha,
800
812
  };
801
813
  } else if (format === 'hwb') {
802
814
  colorSource = {
803
- h: v1, w: v2, b: v3, a: alpha,
815
+ h: v1,
816
+ w: v2,
817
+ b: v3,
818
+ a: alpha,
804
819
  };
805
820
  } else {
806
821
  colorSource = {
807
- r: v1, g: v2, b: v3, a: alpha,
822
+ r: v1,
823
+ g: v2,
824
+ b: v3,
825
+ a: alpha,
808
826
  };
809
827
  }
810
828
 
811
- const {
812
- r, g, b, a,
813
- } = new Color(colorSource);
829
+ const { r, g, b, a } = new Color(colorSource);
814
830
 
815
- ObjectAssign(self.color, {
816
- r, g, b, a,
831
+ ObjectAssign(this.color, {
832
+ r,
833
+ g,
834
+ b,
835
+ a,
817
836
  });
818
- self.setControlPositions();
819
- self.updateAppearance();
820
- self.updateInputs();
821
- self.updateControls();
822
- self.updateVisuals();
837
+ this.setControlPositions();
838
+ this.updateAppearance();
839
+ this.updateInputs();
840
+ this.updateControls();
841
+ this.updateVisuals();
823
842
 
824
843
  // set non-color keyword
825
844
  if (activeElement === input && isNonColorValue) {
826
- self.value = currentValue;
845
+ this.value = currentValue;
827
846
  }
828
847
  }
829
848
  }
@@ -833,13 +852,12 @@ export default class ColorPicker {
833
852
  * * `lightness` and `saturation` for HEX/RGB;
834
853
  * * `lightness` and `hue` for HSL.
835
854
  *
836
- * @param {number} X the X component of the offset
837
- * @param {number} Y the Y component of the offset
855
+ * @param X the X component of the offset
856
+ * @param Y the Y component of the offset
838
857
  */
839
- changeControl1(X, Y) {
840
- const self = this;
858
+ changeControl1(X: number, Y: number): void {
841
859
  let [offsetX, offsetY] = [0, 0];
842
- const { controlPositions, visuals } = self;
860
+ const { controlPositions, visuals } = this;
843
861
  const { offsetHeight, offsetWidth } = visuals[0];
844
862
 
845
863
  if (X > offsetWidth) offsetX = offsetWidth;
@@ -856,25 +874,29 @@ export default class ColorPicker {
856
874
  const alpha = 1 - controlPositions.c3y / offsetHeight;
857
875
 
858
876
  // new color
859
- const {
860
- r, g, b, a,
861
- } = new Color({
862
- h: hue, s: saturation, v: lightness, a: alpha,
877
+ const { r, g, b, a } = new Color({
878
+ h: hue,
879
+ s: saturation,
880
+ v: lightness,
881
+ a: alpha,
863
882
  });
864
883
 
865
- ObjectAssign(self.color, {
866
- r, g, b, a,
884
+ ObjectAssign(this.color, {
885
+ r,
886
+ g,
887
+ b,
888
+ a,
867
889
  });
868
890
 
869
891
  // new positions
870
- self.controlPositions.c1x = offsetX;
871
- self.controlPositions.c1y = offsetY;
892
+ this.controlPositions.c1x = offsetX;
893
+ this.controlPositions.c1y = offsetY;
872
894
 
873
895
  // update color picker
874
- self.updateAppearance();
875
- self.updateInputs();
876
- self.updateControls();
877
- self.updateVisuals();
896
+ this.updateAppearance();
897
+ this.updateInputs();
898
+ this.updateControls();
899
+ this.updateVisuals();
878
900
  }
879
901
 
880
902
  /**
@@ -882,13 +904,10 @@ export default class ColorPicker {
882
904
  * * `hue` for HEX/RGB/HWB;
883
905
  * * `saturation` for HSL.
884
906
  *
885
- * @param {number} Y the Y offset
907
+ * @param Y the Y offset
886
908
  */
887
- changeControl2(Y) {
888
- const self = this;
889
- const {
890
- controlPositions, visuals,
891
- } = self;
909
+ changeControl2(Y: number) {
910
+ const { controlPositions, visuals } = this;
892
911
  const { offsetHeight, offsetWidth } = visuals[0];
893
912
 
894
913
  let offsetY = 0;
@@ -902,34 +921,37 @@ export default class ColorPicker {
902
921
  const alpha = 1 - controlPositions.c3y / offsetHeight;
903
922
 
904
923
  // new color
905
- const {
906
- r, g, b, a,
907
- } = new Color({
908
- h: hue, s: saturation, v: lightness, a: alpha,
924
+ const { r, g, b, a } = new Color({
925
+ h: hue,
926
+ s: saturation,
927
+ v: lightness,
928
+ a: alpha,
909
929
  });
910
930
 
911
- ObjectAssign(self.color, {
912
- r, g, b, a,
931
+ ObjectAssign(this.color, {
932
+ r,
933
+ g,
934
+ b,
935
+ a,
913
936
  });
914
937
 
915
938
  // new position
916
- self.controlPositions.c2y = offsetY;
939
+ this.controlPositions.c2y = offsetY;
917
940
  // update color picker
918
- self.updateAppearance();
919
- self.updateInputs();
920
- self.updateControls();
921
- self.updateVisuals();
941
+ this.updateAppearance();
942
+ this.updateInputs();
943
+ this.updateControls();
944
+ this.updateVisuals();
922
945
  }
923
946
 
924
947
  /**
925
948
  * Updates `ColorPicker` last control,
926
949
  * the `alpha` channel.
927
950
  *
928
- * @param {number} Y
951
+ * @param Y
929
952
  */
930
- changeAlpha(Y) {
931
- const self = this;
932
- const { visuals } = self;
953
+ changeAlpha(Y: number) {
954
+ const { visuals } = this;
933
955
  const { offsetHeight } = visuals[0];
934
956
  let offsetY = 0;
935
957
 
@@ -938,14 +960,14 @@ export default class ColorPicker {
938
960
 
939
961
  // update color alpha
940
962
  const alpha = 1 - offsetY / offsetHeight;
941
- self.color.setAlpha(alpha);
963
+ this.color.setAlpha(alpha);
942
964
  // update position
943
- self.controlPositions.c3y = offsetY;
965
+ this.controlPositions.c3y = offsetY;
944
966
  // update color picker
945
- self.updateAppearance();
946
- self.updateInputs();
947
- self.updateControls();
948
- self.updateVisuals();
967
+ this.updateAppearance();
968
+ this.updateInputs();
969
+ this.updateControls();
970
+ this.updateVisuals();
949
971
  }
950
972
 
951
973
  /**
@@ -954,19 +976,17 @@ export default class ColorPicker {
954
976
  * * window resize
955
977
  */
956
978
  update() {
957
- const self = this;
958
- self.updateDropdownPosition();
959
- self.updateAppearance();
960
- self.setControlPositions();
961
- self.updateInputs(true);
962
- self.updateControls();
963
- self.updateVisuals();
979
+ this.updateDropdownPosition();
980
+ this.updateAppearance();
981
+ this.setControlPositions();
982
+ this.updateInputs(true);
983
+ this.updateControls();
984
+ this.updateVisuals();
964
985
  }
965
986
 
966
987
  /** Updates the open dropdown position on *scroll* event. */
967
988
  updateDropdownPosition() {
968
- const self = this;
969
- const { input, colorPicker, colorMenu } = self;
989
+ const { input, colorPicker, colorMenu } = this;
970
990
  const elRect = getBoundingClientRect(input);
971
991
  const { top, bottom } = elRect;
972
992
  const { offsetHeight: elHeight } = input;
@@ -991,10 +1011,7 @@ export default class ColorPicker {
991
1011
 
992
1012
  /** Updates control knobs' positions. */
993
1013
  setControlPositions() {
994
- const self = this;
995
- const {
996
- visuals, color, hsv,
997
- } = self;
1014
+ const { visuals, color, hsv } = this;
998
1015
  const { offsetHeight, offsetWidth } = visuals[0];
999
1016
  const alpha = color.a;
1000
1017
  const hue = hsv.h;
@@ -1002,34 +1019,28 @@ export default class ColorPicker {
1002
1019
  const saturation = hsv.s;
1003
1020
  const lightness = hsv.v;
1004
1021
 
1005
- self.controlPositions.c1x = saturation * offsetWidth;
1006
- self.controlPositions.c1y = (1 - lightness) * offsetHeight;
1007
- self.controlPositions.c2y = hue * offsetHeight;
1008
- self.controlPositions.c3y = (1 - alpha) * offsetHeight;
1022
+ this.controlPositions.c1x = saturation * offsetWidth;
1023
+ this.controlPositions.c1y = (1 - lightness) * offsetHeight;
1024
+ this.controlPositions.c2y = hue * offsetHeight;
1025
+ this.controlPositions.c3y = (1 - alpha) * offsetHeight;
1009
1026
  }
1010
1027
 
1011
1028
  /** Update the visual appearance label and control knob labels. */
1012
1029
  updateAppearance() {
1013
- const self = this;
1014
- const {
1015
- componentLabels, color, parent,
1016
- hsv, hex, format, controlKnobs,
1017
- } = self;
1018
- const {
1019
- appearanceLabel, hexLabel, valueLabel,
1020
- } = componentLabels;
1030
+ const { componentLabels, color, parent, hsv, hex, format, controlKnobs } = this;
1031
+ const { appearanceLabel, hexLabel, valueLabel } = componentLabels;
1021
1032
  let { r, g, b } = color.toRgb();
1022
1033
  const [knob1, knob2, knob3] = controlKnobs;
1023
1034
  const hue = roundPart(hsv.h * 360);
1024
1035
  const alpha = color.a;
1025
1036
  const saturation = roundPart(hsv.s * 100);
1026
1037
  const lightness = roundPart(hsv.v * 100);
1027
- const colorName = self.appearance;
1038
+ const colorName = this.appearance;
1028
1039
 
1029
1040
  let colorLabel = `${hexLabel} ${hex.split('').join(' ')}`;
1030
1041
 
1031
1042
  if (format === 'hwb') {
1032
- const { hwb } = self;
1043
+ const { hwb } = this;
1033
1044
  const whiteness = roundPart(hwb.w * 100);
1034
1045
  const blackness = roundPart(hwb.b * 100);
1035
1046
  colorLabel = `HWB: ${hue}°, ${whiteness}%, ${blackness}%`;
@@ -1056,12 +1067,12 @@ export default class ColorPicker {
1056
1067
 
1057
1068
  // update the input backgroundColor
1058
1069
  const newColor = color.toString();
1059
- setElementStyle(self.input, { backgroundColor: newColor });
1070
+ setElementStyle(this.input, { backgroundColor: newColor });
1060
1071
 
1061
1072
  // toggle dark/light classes will also style the placeholder
1062
1073
  // dark sets color white, light sets color black
1063
1074
  // isDark ? '#000' : '#fff'
1064
- if (!self.isDark) {
1075
+ if (!this.isDark) {
1065
1076
  if (hasClass(parent, 'txt-dark')) removeClass(parent, 'txt-dark');
1066
1077
  if (!hasClass(parent, 'txt-light')) addClass(parent, 'txt-light');
1067
1078
  } else {
@@ -1073,59 +1084,57 @@ export default class ColorPicker {
1073
1084
  /** Updates the control knobs actual positions. */
1074
1085
  updateControls() {
1075
1086
  const { controlKnobs, controlPositions } = this;
1076
- let {
1077
- c1x, c1y, c2y, c3y,
1078
- } = controlPositions;
1087
+ let { c1x, c1y, c2y, c3y } = controlPositions;
1079
1088
  const [control1, control2, control3] = controlKnobs;
1080
1089
  // round control positions
1081
1090
  [c1x, c1y, c2y, c3y] = [c1x, c1y, c2y, c3y].map(roundPart);
1082
1091
 
1083
- setElementStyle(control1, { transform: `translate3d(${c1x - 4}px,${c1y - 4}px,0)` });
1092
+ setElementStyle(control1, {
1093
+ transform: `translate3d(${c1x - 4}px,${c1y - 4}px,0)`,
1094
+ });
1084
1095
  setElementStyle(control2, { transform: `translate3d(0,${c2y - 4}px,0)` });
1085
1096
  setElementStyle(control3, { transform: `translate3d(0,${c3y - 4}px,0)` });
1086
1097
  }
1087
1098
 
1088
1099
  /**
1089
1100
  * Updates all color form inputs.
1090
- * @param {boolean=} isPrevented when `true`, the component original event is prevented
1101
+ *
1102
+ * @param isPrevented when `true`, the component original event is prevented
1091
1103
  */
1092
- updateInputs(isPrevented) {
1093
- const self = this;
1094
- const {
1095
- value: oldColor, format, inputs, color, hsl,
1096
- } = self;
1104
+ updateInputs(isPrevented?: boolean) {
1105
+ const { value: oldColor, format, inputs, color, hsl } = this;
1097
1106
  const [i1, i2, i3, i4] = inputs;
1098
1107
  const alpha = roundPart(color.a * 100);
1099
1108
  const hue = roundPart(hsl.h * 360);
1100
- let newColor;
1109
+ let newColor = color.toString();
1101
1110
 
1102
1111
  /* istanbul ignore else */
1103
1112
  if (format === 'hex') {
1104
- newColor = self.color.toHexString(true);
1105
- i1.value = self.hex;
1113
+ newColor = this.color.toHexString(true);
1114
+ i1.value = this.hex;
1106
1115
  } else if (format === 'hsl') {
1107
1116
  const lightness = roundPart(hsl.l * 100);
1108
1117
  const saturation = roundPart(hsl.s * 100);
1109
- newColor = self.color.toHslString();
1118
+ newColor = this.color.toHslString();
1110
1119
  i1.value = `${hue}`;
1111
1120
  i2.value = `${saturation}`;
1112
1121
  i3.value = `${lightness}`;
1113
1122
  i4.value = `${alpha}`;
1114
1123
  } else if (format === 'hwb') {
1115
- const { w, b } = self.hwb;
1124
+ const { w, b } = this.hwb;
1116
1125
  const whiteness = roundPart(w * 100);
1117
1126
  const blackness = roundPart(b * 100);
1118
1127
 
1119
- newColor = self.color.toHwbString();
1128
+ newColor = this.color.toHwbString();
1120
1129
  i1.value = `${hue}`;
1121
1130
  i2.value = `${whiteness}`;
1122
1131
  i3.value = `${blackness}`;
1123
1132
  i4.value = `${alpha}`;
1124
1133
  } else if (format === 'rgb') {
1125
- let { r, g, b } = self.rgb;
1134
+ let { r, g, b } = this.rgb;
1126
1135
  [r, g, b] = [r, g, b].map(roundPart);
1127
1136
 
1128
- newColor = self.color.toRgbString();
1137
+ newColor = this.color.toRgbString();
1129
1138
  i1.value = `${r}`;
1130
1139
  i2.value = `${g}`;
1131
1140
  i3.value = `${b}`;
@@ -1133,74 +1142,70 @@ export default class ColorPicker {
1133
1142
  }
1134
1143
 
1135
1144
  // update the color value
1136
- self.value = `${newColor}`;
1145
+ this.value = newColor;
1137
1146
 
1138
1147
  // don't trigger the custom event unless it's really changed
1139
1148
  if (!isPrevented && newColor !== oldColor) {
1140
- firePickerChange(self);
1149
+ firePickerChange(this);
1141
1150
  }
1142
1151
  }
1143
1152
 
1144
1153
  /**
1145
1154
  * Toggle the `ColorPicker` dropdown visibility.
1146
- * @param {Event=} e
1147
- * @this {ColorPicker}
1155
+ *
1156
+ * @param e
1148
1157
  */
1149
- togglePicker(e) {
1158
+ togglePicker(e?: Event) {
1150
1159
  if (e) e.preventDefault();
1151
- const self = this;
1152
- const { colorPicker } = self;
1160
+ const { colorPicker } = this;
1153
1161
 
1154
- if (self.isOpen && hasClass(colorPicker, 'show')) {
1155
- self.hide(true);
1162
+ if (this.isOpen && hasClass(colorPicker, 'show')) {
1163
+ this.hide(true);
1156
1164
  } else {
1157
- showDropdown(self, colorPicker);
1165
+ showDropdown(this, colorPicker);
1158
1166
  }
1159
1167
  }
1160
1168
 
1161
1169
  /** Shows the `ColorPicker` dropdown. */
1162
1170
  showPicker() {
1163
- const self = this;
1164
- const { colorPicker } = self;
1171
+ const { colorPicker } = this;
1165
1172
 
1166
- if (!['top', 'bottom'].some((c) => hasClass(colorPicker, c))) {
1167
- showDropdown(self, colorPicker);
1173
+ if (!['top', 'bottom'].some(c => hasClass(colorPicker, c))) {
1174
+ showDropdown(this, colorPicker);
1168
1175
  }
1169
1176
  }
1170
1177
 
1171
1178
  /**
1172
1179
  * Toggles the visibility of the `ColorPicker` presets menu.
1173
- * @param {Event=} e
1180
+ *
1181
+ * @param e
1174
1182
  * @this {ColorPicker}
1175
1183
  */
1176
- toggleMenu(e) {
1184
+ toggleMenu(e?: Event) {
1177
1185
  if (e) e.preventDefault();
1178
- const self = this;
1179
- const { colorMenu } = self;
1186
+ const { colorMenu } = this;
1180
1187
 
1181
- if (self.isOpen && hasClass(colorMenu, 'show')) {
1182
- self.hide(true);
1188
+ if (this.isOpen && hasClass(colorMenu, 'show')) {
1189
+ this.hide(true);
1183
1190
  } else {
1184
- showDropdown(self, colorMenu);
1191
+ showDropdown(this, colorMenu);
1185
1192
  }
1186
1193
  }
1187
1194
 
1188
1195
  /**
1189
1196
  * Hides the currently open `ColorPicker` dropdown.
1197
+ *
1190
1198
  * @param {boolean=} focusPrevented
1191
1199
  */
1192
- hide(focusPrevented) {
1193
- const self = this;
1194
- if (self.isOpen) {
1195
- const {
1196
- pickerToggle, menuToggle, colorPicker, colorMenu, parent, input,
1197
- } = self;
1200
+ hide(focusPrevented?: boolean) {
1201
+ if (this.isOpen) {
1202
+ const { pickerToggle, menuToggle, colorPicker, colorMenu, parent, input } = this;
1198
1203
  const openPicker = hasClass(colorPicker, 'show');
1199
1204
  const openDropdown = openPicker ? colorPicker : colorMenu;
1200
1205
  const relatedBtn = openPicker ? pickerToggle : menuToggle;
1201
1206
  const animationDuration = openDropdown && getElementTransitionDuration(openDropdown);
1202
1207
 
1203
- self.value = self.color.toString(true);
1208
+ this.value = this.color.toString(true);
1204
1209
 
1205
1210
  /* istanbul ignore else */
1206
1211
  if (openDropdown) {
@@ -1211,8 +1216,8 @@ export default class ColorPicker {
1211
1216
  /* istanbul ignore else */
1212
1217
  if (!querySelector('.show', parent)) {
1213
1218
  removeClass(parent, 'open');
1214
- toggleEventsOnShown(self);
1215
- self.isOpen = false;
1219
+ toggleEventsOnShown(this);
1220
+ this.isOpen = false;
1216
1221
  }
1217
1222
  }, animationDuration);
1218
1223
  }
@@ -1220,41 +1225,26 @@ export default class ColorPicker {
1220
1225
  if (!focusPrevented) {
1221
1226
  focus(pickerToggle);
1222
1227
  }
1223
- setAttribute(input, tabIndex, '-1');
1228
+ setAttribute(input, tabindex, '-1');
1224
1229
  if (relatedBtn === menuToggle) {
1225
- setAttribute(menuToggle, tabIndex, '-1');
1230
+ setAttribute(menuToggle, tabindex, '-1');
1226
1231
  }
1227
1232
  }
1228
1233
  }
1229
1234
 
1230
1235
  /** Removes `ColorPicker` from target `<input>`. */
1231
1236
  dispose() {
1232
- const self = this;
1233
- const { input, parent } = self;
1234
- self.hide(true);
1235
- toggleEvents(self);
1236
- [...parent.children].forEach((el) => {
1237
+ const { input, parent } = this;
1238
+ this.hide(true);
1239
+ toggleEvents(this);
1240
+ [...parent.children].forEach(el => {
1237
1241
  if (el !== input) el.remove();
1238
1242
  });
1239
1243
 
1240
- removeAttribute(input, tabIndex);
1244
+ removeAttribute(input, tabindex);
1241
1245
  setElementStyle(input, { backgroundColor: '' });
1242
1246
 
1243
- ['txt-light', 'txt-dark'].forEach((c) => removeClass(parent, c));
1247
+ ['txt-light', 'txt-dark'].forEach(c => removeClass(parent, c));
1244
1248
  Data.remove(input, colorPickerString);
1245
1249
  }
1246
1250
  }
1247
-
1248
- ObjectAssign(ColorPicker, {
1249
- Color,
1250
- ColorPalette,
1251
- Version,
1252
- getInstance: getColorPickerInstance,
1253
- init: initColorPicker,
1254
- selector: colorPickerSelector,
1255
- // utils important for render
1256
- roundPart,
1257
- setElementStyle,
1258
- setAttribute,
1259
- getBoundingClientRect,
1260
- });