@thednp/color-picker 0.0.2-alpha5 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/README.md +21 -19
  2. package/dist/css/color-picker.css +82 -46
  3. package/dist/css/color-picker.min.css +2 -2
  4. package/dist/css/color-picker.rtl.css +82 -46
  5. package/dist/css/color-picker.rtl.min.css +2 -2
  6. package/dist/js/color-esm.js +2 -5
  7. package/dist/js/color-esm.min.js +1 -1
  8. package/dist/js/color-palette-esm.js +2 -5
  9. package/dist/js/color-palette-esm.min.js +1 -1
  10. package/dist/js/color-palette.js +2 -5
  11. package/dist/js/color-palette.min.js +1 -1
  12. package/dist/js/color-picker-element-esm.js +184 -189
  13. package/dist/js/color-picker-element-esm.min.js +2 -2
  14. package/dist/js/color-picker-element.js +184 -189
  15. package/dist/js/color-picker-element.min.js +2 -2
  16. package/dist/js/color-picker-esm.js +77 -134
  17. package/dist/js/color-picker-esm.min.js +2 -2
  18. package/dist/js/color-picker.js +77 -134
  19. package/dist/js/color-picker.min.js +2 -2
  20. package/dist/js/color.js +2 -5
  21. package/dist/js/color.min.js +1 -1
  22. package/package.json +20 -19
  23. package/src/js/color-picker-element.js +45 -37
  24. package/src/js/color-picker.js +46 -60
  25. package/src/js/color.js +1 -4
  26. package/src/js/index.js +5 -0
  27. package/src/js/util/getColorMenu.js +7 -8
  28. package/src/js/util/setMarkup.js +4 -7
  29. package/src/js/util/toggleCEAttr.js +70 -0
  30. package/src/js/util/version.js +0 -1
  31. package/src/js/version.js +0 -1
  32. package/src/scss/_variables.scss +7 -0
  33. package/src/scss/color-picker.scss +86 -45
  34. package/types/cp.d.ts +31 -17
  35. package/types/index.d.ts +0 -4
  36. package/types/source/source.ts +0 -1
  37. package/types/source/types.d.ts +8 -6
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ColorPicker v0.0.2alpha5 (http://thednp.github.io/color-picker)
2
+ * ColorPicker v1.0.1 (http://thednp.github.io/color-picker)
3
3
  * Copyright 2022 © thednp
4
4
  * Licensed under MIT (https://github.com/thednp/color-picker/blob/master/LICENSE)
5
5
  */
@@ -9,27 +9,26 @@ const EventRegistry = {};
9
9
  /**
10
10
  * The global event listener.
11
11
  *
12
- * @this {Element | HTMLElement | Window | Document}
13
- * @param {Event} e
14
- * @returns {void}
12
+ * @type {EventListener}
13
+ * @this {EventTarget}
15
14
  */
16
15
  function globalListener(e) {
17
16
  const that = this;
18
17
  const { type } = e;
19
- const oneEvMap = EventRegistry[type] ? [...EventRegistry[type]] : [];
20
18
 
21
- oneEvMap.forEach((elementsMap) => {
19
+ [...EventRegistry[type]].forEach((elementsMap) => {
22
20
  const [element, listenersMap] = elementsMap;
23
- [...listenersMap].forEach((listenerMap) => {
24
- if (element === that) {
21
+ /* istanbul ignore else */
22
+ if (element === that) {
23
+ [...listenersMap].forEach((listenerMap) => {
25
24
  const [listener, options] = listenerMap;
26
25
  listener.apply(element, [e]);
27
26
 
28
27
  if (options && options.once) {
29
28
  removeListener(element, type, listener, options);
30
29
  }
31
- }
32
- });
30
+ });
31
+ }
33
32
  });
34
33
  }
35
34
 
@@ -37,10 +36,7 @@ function globalListener(e) {
37
36
  * Register a new listener with its options and attach the `globalListener`
38
37
  * to the target if this is the first listener.
39
38
  *
40
- * @param {Element | HTMLElement | Window | Document} element
41
- * @param {string} eventType
42
- * @param {EventListenerObject['handleEvent']} listener
43
- * @param {AddEventListenerOptions=} options
39
+ * @type {Listener.ListenerAction<EventTarget>}
44
40
  */
45
41
  const addListener = (element, eventType, listener, options) => {
46
42
  // get element listeners first
@@ -58,9 +54,7 @@ const addListener = (element, eventType, listener, options) => {
58
54
  const { size } = oneElementMap;
59
55
 
60
56
  // register listener with its options
61
- if (oneElementMap) {
62
- oneElementMap.set(listener, options);
63
- }
57
+ oneElementMap.set(listener, options);
64
58
 
65
59
  // add listener last
66
60
  if (!size) {
@@ -72,10 +66,7 @@ const addListener = (element, eventType, listener, options) => {
72
66
  * Remove a listener from registry and detach the `globalListener`
73
67
  * if no listeners are found in the registry.
74
68
  *
75
- * @param {Element | HTMLElement | Window | Document} element
76
- * @param {string} eventType
77
- * @param {EventListenerObject['handleEvent']} listener
78
- * @param {AddEventListenerOptions=} options
69
+ * @type {Listener.ListenerAction<EventTarget>}
79
70
  */
80
71
  const removeListener = (element, eventType, listener, options) => {
81
72
  // get listener first
@@ -94,6 +85,7 @@ const removeListener = (element, eventType, listener, options) => {
94
85
  if (!oneEventMap || !oneEventMap.size) delete EventRegistry[eventType];
95
86
 
96
87
  // remove listener last
88
+ /* istanbul ignore else */
97
89
  if (!oneElementMap || !oneElementMap.size) {
98
90
  element.removeEventListener(eventType, globalListener, eventOptions);
99
91
  }
@@ -195,12 +187,6 @@ const keydownEvent = 'keydown';
195
187
  */
196
188
  const changeEvent = 'change';
197
189
 
198
- /**
199
- * A global namespace for `touchstart` event.
200
- * @type {string}
201
- */
202
- const touchstartEvent = 'touchstart';
203
-
204
190
  /**
205
191
  * A global namespace for `touchmove` event.
206
192
  * @type {string}
@@ -208,28 +194,22 @@ const touchstartEvent = 'touchstart';
208
194
  const touchmoveEvent = 'touchmove';
209
195
 
210
196
  /**
211
- * A global namespace for `touchend` event.
197
+ * A global namespace for `pointerdown` event.
212
198
  * @type {string}
213
199
  */
214
- const touchendEvent = 'touchend';
200
+ const pointerdownEvent = 'pointerdown';
215
201
 
216
202
  /**
217
- * A global namespace for `mousedown` event.
203
+ * A global namespace for `pointermove` event.
218
204
  * @type {string}
219
205
  */
220
- const mousedownEvent = 'mousedown';
206
+ const pointermoveEvent = 'pointermove';
221
207
 
222
208
  /**
223
- * A global namespace for `mousemove` event.
209
+ * A global namespace for `pointerup` event.
224
210
  * @type {string}
225
211
  */
226
- const mousemoveEvent = 'mousemove';
227
-
228
- /**
229
- * A global namespace for `mouseup` event.
230
- * @type {string}
231
- */
232
- const mouseupEvent = 'mouseup';
212
+ const pointerupEvent = 'pointerup';
233
213
 
234
214
  /**
235
215
  * A global namespace for `scroll` event.
@@ -277,27 +257,6 @@ function getDocumentElement(node) {
277
257
  return getDocument(node).documentElement;
278
258
  }
279
259
 
280
- /**
281
- * Returns the `Window` object of a target node.
282
- * @see https://github.com/floating-ui/floating-ui
283
- *
284
- * @param {(Node | HTMLElement | Element | Window)=} node target node
285
- * @returns {globalThis}
286
- */
287
- function getWindow(node) {
288
- if (node == null) {
289
- return window;
290
- }
291
-
292
- if (!(node instanceof Window)) {
293
- const { ownerDocument } = node;
294
- return ownerDocument ? ownerDocument.defaultView || window : window;
295
- }
296
-
297
- // @ts-ignore
298
- return node;
299
- }
300
-
301
260
  /**
302
261
  * Shortcut for `window.getComputedStyle(element).propertyName`
303
262
  * static method.
@@ -1394,7 +1353,7 @@ function inputToRGB(input) {
1394
1353
  format = 'hwb';
1395
1354
  }
1396
1355
  if (isValidCSSUnit(color.a)) {
1397
- a = color.a; // @ts-ignore -- `parseFloat` works with numbers too
1356
+ a = color.a;
1398
1357
  a = isPercentage(`${a}`) || parseFloat(a) > 1 ? bound01(a, 100) : a;
1399
1358
  }
1400
1359
  }
@@ -1405,9 +1364,6 @@ function inputToRGB(input) {
1405
1364
  return {
1406
1365
  ok,
1407
1366
  format,
1408
- // r: Math.min(255, Math.max(rgb.r, 0)),
1409
- // g: Math.min(255, Math.max(rgb.g, 0)),
1410
- // b: Math.min(255, Math.max(rgb.b, 0)),
1411
1367
  r: rgb.r,
1412
1368
  g: rgb.g,
1413
1369
  b: rgb.b,
@@ -2246,17 +2202,16 @@ function getColorMenu(self, colorsSource, menuClass) {
2246
2202
  const isOptionsMenu = menuClass === 'color-options';
2247
2203
  const isPalette = colorsSource instanceof ColorPalette;
2248
2204
  const menuLabel = isOptionsMenu ? presetsLabel : defaultsLabel;
2249
- let colorsArray = isPalette ? colorsSource.colors : colorsSource;
2250
- colorsArray = colorsArray instanceof Array ? colorsArray : [];
2205
+ const colorsArray = isPalette ? colorsSource.colors : colorsSource;
2251
2206
  const colorsCount = colorsArray.length;
2252
2207
  const { lightSteps } = isPalette ? colorsSource : { lightSteps: null };
2253
- const fit = lightSteps || [9, 10].find((x) => colorsCount > x * 2 && !(colorsCount % x)) || 5;
2208
+ const fit = lightSteps || [9, 10].find((x) => colorsCount >= x * 2 && !(colorsCount % x)) || 5;
2254
2209
  const isMultiLine = isOptionsMenu && colorsCount > fit;
2255
2210
  let rowCountHover = 2;
2256
- rowCountHover = isMultiLine && colorsCount >= fit * 2 ? 3 : rowCountHover;
2257
- rowCountHover = colorsCount >= fit * 3 ? 4 : rowCountHover;
2258
- rowCountHover = colorsCount >= fit * 4 ? 5 : rowCountHover;
2259
- const rowCount = rowCountHover - (colorsCount < fit * 3 ? 1 : 2);
2211
+ rowCountHover = isMultiLine && colorsCount > fit * 2 ? 3 : rowCountHover;
2212
+ rowCountHover = isMultiLine && colorsCount > fit * 3 ? 4 : rowCountHover;
2213
+ rowCountHover = isMultiLine && colorsCount > fit * 4 ? 5 : rowCountHover;
2214
+ const rowCount = rowCountHover - (colorsCount <= fit * 3 ? 1 : 2);
2260
2215
  const isScrollable = isMultiLine && colorsCount > rowCount * fit;
2261
2216
  let finalClass = menuClass;
2262
2217
  finalClass += isScrollable ? ' scrollable' : '';
@@ -2264,7 +2219,7 @@ function getColorMenu(self, colorsSource, menuClass) {
2264
2219
  const gap = isMultiLine ? '1px' : '0.25rem';
2265
2220
  let optionSize = isMultiLine ? 1.75 : 2;
2266
2221
  optionSize = fit > 5 && isMultiLine ? 1.5 : optionSize;
2267
- const menuHeight = `${(rowCount || 1) * optionSize}rem`;
2222
+ const menuHeight = `${rowCount * optionSize}rem`;
2268
2223
  const menuHeightHover = `calc(${rowCountHover} * ${optionSize}rem + ${rowCountHover - 1} * ${gap})`;
2269
2224
  /** @type {HTMLUListElement} */
2270
2225
  // @ts-ignore -- <UL> is an `HTMLElement`
@@ -2371,16 +2326,14 @@ function setMarkup(self) {
2371
2326
  });
2372
2327
 
2373
2328
  // color presets
2374
- if ((colorPresets instanceof Array && colorPresets.length)
2375
- || (colorPresets instanceof ColorPalette && colorPresets.colors)) {
2376
- const presetsMenu = getColorMenu(self, colorPresets, 'color-options');
2377
- presetsDropdown.append(presetsMenu);
2329
+ if (colorPresets) {
2330
+ presetsDropdown.append(getColorMenu(self, colorPresets, 'color-options'));
2378
2331
  }
2379
2332
 
2380
2333
  // explicit defaults [reset, initial, inherit, transparent, currentColor]
2334
+ // also custom defaults [default: #069, complementary: #930]
2381
2335
  if (colorKeywords && colorKeywords.length) {
2382
- const keywordsMenu = getColorMenu(self, colorKeywords, 'color-defaults');
2383
- presetsDropdown.append(keywordsMenu);
2336
+ presetsDropdown.append(getColorMenu(self, colorKeywords, 'color-defaults'));
2384
2337
  }
2385
2338
 
2386
2339
  const presetsBtn = createElement({
@@ -2417,9 +2370,7 @@ function setMarkup(self) {
2417
2370
  setAttribute(input, tabIndex, '-1');
2418
2371
  }
2419
2372
 
2420
- var version = "0.0.2alpha5";
2421
-
2422
- // @ts-ignore
2373
+ var version = "1.0.1";
2423
2374
 
2424
2375
  const Version = version;
2425
2376
 
@@ -2439,7 +2390,7 @@ const colorPickerDefaults = {
2439
2390
  // ColorPicker Static Methods
2440
2391
  // ==========================
2441
2392
 
2442
- /** @type {CP.GetInstance<ColorPicker>} */
2393
+ /** @type {CP.GetInstance<ColorPicker, HTMLInputElement>} */
2443
2394
  const getColorPickerInstance = (element) => getInstance(element, colorPickerString);
2444
2395
 
2445
2396
  /** @type {CP.InitCallback<ColorPicker>} */
@@ -2474,17 +2425,12 @@ function toggleEventsOnShown(self, action) {
2474
2425
  const fn = action ? addListener : removeListener;
2475
2426
  const { input, colorMenu, parent } = self;
2476
2427
  const doc = getDocument(input);
2477
- const win = getWindow(input);
2478
- const pointerEvents = `on${touchstartEvent}` in doc
2479
- ? { down: touchstartEvent, move: touchmoveEvent, up: touchendEvent }
2480
- : { down: mousedownEvent, move: mousemoveEvent, up: mouseupEvent };
2428
+ const win = doc.defaultView;
2481
2429
 
2482
- fn(self.controls, pointerEvents.down, self.pointerDown);
2430
+ fn(self.controls, pointerdownEvent, self.pointerDown);
2483
2431
  self.controlKnobs.forEach((x) => fn(x, keydownEvent, self.handleKnobs));
2484
2432
 
2485
- // @ts-ignore -- this is `Window`
2486
2433
  fn(win, scrollEvent, self.handleScroll);
2487
- // @ts-ignore -- this is `Window`
2488
2434
  fn(win, resizeEvent, self.update);
2489
2435
 
2490
2436
  [input, ...self.inputs].forEach((x) => fn(x, changeEvent, self.changeHandler));
@@ -2494,8 +2440,8 @@ function toggleEventsOnShown(self, action) {
2494
2440
  fn(colorMenu, keydownEvent, self.menuKeyHandler);
2495
2441
  }
2496
2442
 
2497
- fn(doc, pointerEvents.move, self.pointerMove);
2498
- fn(doc, pointerEvents.up, self.pointerUp);
2443
+ fn(doc, pointermoveEvent, self.pointerMove);
2444
+ fn(doc, pointerupEvent, self.pointerUp);
2499
2445
  fn(parent, focusoutEvent, self.handleFocusOut);
2500
2446
  fn(doc, keyupEvent, self.handleDismiss);
2501
2447
  }
@@ -2514,6 +2460,7 @@ function firePickerChange(self) {
2514
2460
  * @returns {void}
2515
2461
  */
2516
2462
  function removePosition(element) {
2463
+ /* istanbul ignore else */
2517
2464
  if (element) {
2518
2465
  ['bottom', 'top'].forEach((x) => removeClass(element, x));
2519
2466
  }
@@ -2577,7 +2524,6 @@ class ColorPicker {
2577
2524
  constructor(target, config) {
2578
2525
  const self = this;
2579
2526
  /** @type {HTMLInputElement} */
2580
- // @ts-ignore
2581
2527
  const input = querySelector(target);
2582
2528
 
2583
2529
  // invalidate
@@ -2588,7 +2534,6 @@ class ColorPicker {
2588
2534
  if (!parent) throw new TypeError('ColorPicker requires a specific markup to work.');
2589
2535
 
2590
2536
  /** @type {HTMLElement} */
2591
- // @ts-ignore
2592
2537
  self.parent = parent;
2593
2538
 
2594
2539
  /** @type {number} */
@@ -2616,6 +2561,7 @@ class ColorPicker {
2616
2561
  } = normalizeOptions(this.isCE ? parent : input, colorPickerDefaults, config || {});
2617
2562
 
2618
2563
  let translatedColorLabels = colorNames;
2564
+ /* istanbul ignore else */
2619
2565
  if (colorLabels instanceof Array && colorLabels.length === 17) {
2620
2566
  translatedColorLabels = colorLabels;
2621
2567
  } else if (colorLabels && colorLabels.split(',').length === 17) {
@@ -2632,7 +2578,7 @@ class ColorPicker {
2632
2578
  ? JSON.parse(componentLabels) : componentLabels;
2633
2579
 
2634
2580
  /** @type {Record<string, string>} */
2635
- self.componentLabels = ObjectAssign(colorPickerLabels, tempComponentLabels);
2581
+ self.componentLabels = ObjectAssign({ ...colorPickerLabels }, tempComponentLabels);
2636
2582
 
2637
2583
  /** @type {Color} */
2638
2584
  self.color = new Color(input.value || '#fff', format);
@@ -2641,14 +2587,14 @@ class ColorPicker {
2641
2587
  self.format = format;
2642
2588
 
2643
2589
  // set colour defaults
2644
- if (colorKeywords instanceof Array) {
2590
+ if (colorKeywords instanceof Array && colorKeywords.length) {
2645
2591
  self.colorKeywords = colorKeywords;
2646
2592
  } else if (typeof colorKeywords === 'string' && colorKeywords.length) {
2647
2593
  self.colorKeywords = colorKeywords.split(',').map((x) => x.trim());
2648
2594
  }
2649
2595
 
2650
2596
  // set colour presets
2651
- if (colorPresets instanceof Array) {
2597
+ if (colorPresets instanceof Array && colorPresets.length) {
2652
2598
  self.colorPresets = colorPresets;
2653
2599
  } else if (typeof colorPresets === 'string' && colorPresets.length) {
2654
2600
  if (isValidJSON(colorPresets)) {
@@ -2681,26 +2627,20 @@ class ColorPicker {
2681
2627
  const [colorPicker, colorMenu] = getElementsByClassName('color-dropdown', parent);
2682
2628
  // set main elements
2683
2629
  /** @type {HTMLElement} */
2684
- // @ts-ignore
2685
2630
  self.pickerToggle = querySelector('.picker-toggle', parent);
2686
2631
  /** @type {HTMLElement} */
2687
- // @ts-ignore
2688
2632
  self.menuToggle = querySelector('.menu-toggle', parent);
2689
2633
  /** @type {HTMLElement} */
2690
- // @ts-ignore
2691
2634
  self.colorPicker = colorPicker;
2692
2635
  /** @type {HTMLElement} */
2693
- // @ts-ignore
2694
2636
  self.colorMenu = colorMenu;
2695
2637
  /** @type {HTMLInputElement[]} */
2696
- // @ts-ignore
2697
2638
  self.inputs = [...getElementsByClassName('color-input', parent)];
2698
2639
  const [controls] = getElementsByClassName('color-controls', parent);
2699
2640
  self.controls = controls;
2700
2641
  /** @type {(HTMLElement | Element)[]} */
2701
2642
  self.controlKnobs = [...getElementsByClassName('knob', controls)];
2702
2643
  /** @type {(HTMLElement)[]} */
2703
- // @ts-ignore
2704
2644
  self.visuals = [...getElementsByClassName('visual-control', controls)];
2705
2645
 
2706
2646
  // update colour picker controls, inputs and visuals
@@ -2779,6 +2719,7 @@ class ColorPicker {
2779
2719
  let colorName;
2780
2720
 
2781
2721
  // determine color appearance
2722
+ /* istanbul ignore else */
2782
2723
  if (lightness === 100 && saturation === 0) {
2783
2724
  colorName = colorLabels.white;
2784
2725
  } else if (lightness === 0) {
@@ -2852,7 +2793,6 @@ class ColorPicker {
2852
2793
  * @this {ColorPicker}
2853
2794
  */
2854
2795
  handleFocusOut({ relatedTarget }) {
2855
- // @ts-ignore
2856
2796
  if (relatedTarget && !this.parent.contains(relatedTarget)) {
2857
2797
  this.hide(true);
2858
2798
  }
@@ -2879,13 +2819,14 @@ class ColorPicker {
2879
2819
  const self = this;
2880
2820
  const { activeElement } = getDocument(self.input);
2881
2821
 
2882
- if ((e.type === touchmoveEvent && self.dragElement)
2822
+ self.updateDropdownPosition();
2823
+
2824
+ /* istanbul ignore next */
2825
+ if (([pointermoveEvent, touchmoveEvent].includes(e.type) && self.dragElement)
2883
2826
  || (activeElement && self.controlKnobs.includes(activeElement))) {
2884
2827
  e.stopPropagation();
2885
2828
  e.preventDefault();
2886
2829
  }
2887
-
2888
- self.updateDropdownPosition();
2889
2830
  }
2890
2831
 
2891
2832
  /**
@@ -2895,7 +2836,6 @@ class ColorPicker {
2895
2836
  */
2896
2837
  menuKeyHandler(e) {
2897
2838
  const { target, code } = e;
2898
- // @ts-ignore
2899
2839
  const { previousElementSibling, nextElementSibling, parentElement } = target;
2900
2840
  const isColorOptionsMenu = parentElement && hasClass(parentElement, 'color-options');
2901
2841
  const allSiblings = [...parentElement.children];
@@ -2934,20 +2874,20 @@ class ColorPicker {
2934
2874
 
2935
2875
  /**
2936
2876
  * The `ColorPicker` click event listener for the colour menu presets / defaults.
2937
- * @param {Partial<Event>} e
2877
+ * @param {Event} e
2938
2878
  * @this {ColorPicker}
2939
2879
  */
2940
2880
  menuClickHandler(e) {
2941
2881
  const self = this;
2942
- /** @type {*} */
2943
2882
  const { target } = e;
2944
2883
  const { colorMenu } = self;
2945
2884
  const newOption = (getAttribute(target, 'data-value') || '').trim();
2946
2885
  // invalidate for targets other than color options
2947
2886
  if (!newOption.length) return;
2948
2887
  const currentActive = querySelector('li.active', colorMenu);
2949
- let newColor = nonColors.includes(newOption) ? 'white' : newOption;
2950
- newColor = newOption === 'transparent' ? 'rgba(0,0,0,0)' : newOption;
2888
+ let newColor = newOption;
2889
+ newColor = nonColors.includes(newColor) ? 'white' : newColor;
2890
+ newColor = newColor === 'transparent' ? 'rgba(0,0,0,0)' : newColor;
2951
2891
 
2952
2892
  const {
2953
2893
  r, g, b, a,
@@ -2959,7 +2899,9 @@ class ColorPicker {
2959
2899
 
2960
2900
  self.update();
2961
2901
 
2902
+ /* istanbul ignore else */
2962
2903
  if (currentActive !== target) {
2904
+ /* istanbul ignore else */
2963
2905
  if (currentActive) {
2964
2906
  removeClass(currentActive, 'active');
2965
2907
  removeAttribute(currentActive, ariaSelected);
@@ -2977,15 +2919,13 @@ class ColorPicker {
2977
2919
 
2978
2920
  /**
2979
2921
  * The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
2980
- * @param {TouchEvent} e
2922
+ * @param {PointerEvent} e
2981
2923
  * @this {ColorPicker}
2982
2924
  */
2983
2925
  pointerDown(e) {
2984
2926
  const self = this;
2985
2927
  /** @type {*} */
2986
- const {
2987
- type, target, touches, pageX, pageY,
2988
- } = e;
2928
+ const { target, pageX, pageY } = e;
2989
2929
  const { colorMenu, visuals, controlKnobs } = self;
2990
2930
  const [v1, v2, v3] = visuals;
2991
2931
  const [c1, c2, c3] = controlKnobs;
@@ -2993,11 +2933,10 @@ class ColorPicker {
2993
2933
  const visual = controlKnobs.includes(target) ? target.previousElementSibling : target;
2994
2934
  const visualRect = getBoundingClientRect(visual);
2995
2935
  const html = getDocumentElement(v1);
2996
- const X = type === 'touchstart' ? touches[0].pageX : pageX;
2997
- const Y = type === 'touchstart' ? touches[0].pageY : pageY;
2998
- const offsetX = X - html.scrollLeft - visualRect.left;
2999
- const offsetY = Y - html.scrollTop - visualRect.top;
2936
+ const offsetX = pageX - html.scrollLeft - visualRect.left;
2937
+ const offsetY = pageY - html.scrollTop - visualRect.top;
3000
2938
 
2939
+ /* istanbul ignore else */
3001
2940
  if (target === v1 || target === c1) {
3002
2941
  self.dragElement = visual;
3003
2942
  self.changeControl1(offsetX, offsetY);
@@ -3021,7 +2960,7 @@ class ColorPicker {
3021
2960
 
3022
2961
  /**
3023
2962
  * The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
3024
- * @param {TouchEvent} e
2963
+ * @param {PointerEvent} e
3025
2964
  * @this {ColorPicker}
3026
2965
  */
3027
2966
  pointerUp({ target }) {
@@ -3030,9 +2969,8 @@ class ColorPicker {
3030
2969
  const doc = getDocument(parent);
3031
2970
  const currentOpen = querySelector(`${colorPickerParentSelector}.open`, doc) !== null;
3032
2971
  const selection = doc.getSelection();
3033
- // @ts-ignore
2972
+
3034
2973
  if (!self.dragElement && !selection.toString().length
3035
- // @ts-ignore
3036
2974
  && !parent.contains(target)) {
3037
2975
  self.hide(currentOpen);
3038
2976
  }
@@ -3042,25 +2980,20 @@ class ColorPicker {
3042
2980
 
3043
2981
  /**
3044
2982
  * The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
3045
- * @param {TouchEvent} e
2983
+ * @param {PointerEvent} e
3046
2984
  */
3047
2985
  pointerMove(e) {
3048
2986
  const self = this;
3049
2987
  const { dragElement, visuals } = self;
3050
2988
  const [v1, v2, v3] = visuals;
3051
- const {
3052
- // @ts-ignore
3053
- type, touches, pageX, pageY,
3054
- } = e;
2989
+ const { pageX, pageY } = e;
3055
2990
 
3056
2991
  if (!dragElement) return;
3057
2992
 
3058
2993
  const controlRect = getBoundingClientRect(dragElement);
3059
2994
  const win = getDocumentElement(v1);
3060
- const X = type === touchmoveEvent ? touches[0].pageX : pageX;
3061
- const Y = type === touchmoveEvent ? touches[0].pageY : pageY;
3062
- const offsetX = X - win.scrollLeft - controlRect.left;
3063
- const offsetY = Y - win.scrollTop - controlRect.top;
2995
+ const offsetX = pageX - win.scrollLeft - controlRect.left;
2996
+ const offsetY = pageY - win.scrollTop - controlRect.top;
3064
2997
 
3065
2998
  if (dragElement === v1) {
3066
2999
  self.changeControl1(offsetX, offsetY);
@@ -3094,13 +3027,16 @@ class ColorPicker {
3094
3027
  const currentKnob = controlKnobs.find((x) => x === activeElement);
3095
3028
  const yRatio = offsetHeight / 360;
3096
3029
 
3030
+ /* istanbul ignore else */
3097
3031
  if (currentKnob) {
3098
3032
  let offsetX = 0;
3099
3033
  let offsetY = 0;
3100
3034
 
3035
+ /* istanbul ignore else */
3101
3036
  if (target === c1) {
3102
3037
  const xRatio = offsetWidth / 100;
3103
3038
 
3039
+ /* istanbul ignore else */
3104
3040
  if ([keyArrowLeft, keyArrowRight].includes(code)) {
3105
3041
  self.controlPositions.c1x += code === keyArrowRight ? xRatio : -xRatio;
3106
3042
  } else if ([keyArrowUp, keyArrowDown].includes(code)) {
@@ -3146,6 +3082,7 @@ class ColorPicker {
3146
3082
  const isNonColorValue = self.hasNonColor && nonColors.includes(currentValue);
3147
3083
  const alpha = i4 ? v4 : (1 - controlPositions.c3y / offsetHeight);
3148
3084
 
3085
+ /* istanbul ignore else */
3149
3086
  if (activeElement === input || (activeElement && inputs.includes(activeElement))) {
3150
3087
  if (activeElement === input) {
3151
3088
  if (isNonColorValue) {
@@ -3460,6 +3397,7 @@ class ColorPicker {
3460
3397
  const hue = roundPart(hsl.h * 360);
3461
3398
  let newColor;
3462
3399
 
3400
+ /* istanbul ignore else */
3463
3401
  if (format === 'hex') {
3464
3402
  newColor = self.color.toHexString(true);
3465
3403
  i1.value = self.hex;
@@ -3560,15 +3498,15 @@ class ColorPicker {
3560
3498
  const relatedBtn = openPicker ? pickerToggle : menuToggle;
3561
3499
  const animationDuration = openDropdown && getElementTransitionDuration(openDropdown);
3562
3500
 
3563
- // if (!self.isValid) {
3564
3501
  self.value = self.color.toString(true);
3565
- // }
3566
3502
 
3503
+ /* istanbul ignore else */
3567
3504
  if (openDropdown) {
3568
3505
  removeClass(openDropdown, 'show');
3569
3506
  setAttribute(relatedBtn, ariaExpanded, 'false');
3570
3507
  setTimeout(() => {
3571
3508
  removePosition(openDropdown);
3509
+ /* istanbul ignore else */
3572
3510
  if (!querySelector('.show', parent)) {
3573
3511
  removeClass(parent, 'open');
3574
3512
  toggleEventsOnShown(self);
@@ -3581,7 +3519,7 @@ class ColorPicker {
3581
3519
  focus(pickerToggle);
3582
3520
  }
3583
3521
  setAttribute(input, tabIndex, '-1');
3584
- if (menuToggle) {
3522
+ if (relatedBtn === menuToggle) {
3585
3523
  setAttribute(menuToggle, tabIndex, '-1');
3586
3524
  }
3587
3525
  }
@@ -3619,4 +3557,9 @@ ObjectAssign(ColorPicker, {
3619
3557
  getBoundingClientRect,
3620
3558
  });
3621
3559
 
3560
+ /**
3561
+ * A single import is required to add the `CP` namespace to `src` sources.
3562
+ * @typedef {import("../../types/index")}
3563
+ */
3564
+
3622
3565
  export { ColorPicker as default };