@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.
- package/README.md +21 -19
- package/dist/css/color-picker.css +82 -46
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +82 -46
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-esm.js +2 -5
- package/dist/js/color-esm.min.js +1 -1
- package/dist/js/color-palette-esm.js +2 -5
- package/dist/js/color-palette-esm.min.js +1 -1
- package/dist/js/color-palette.js +2 -5
- package/dist/js/color-palette.min.js +1 -1
- package/dist/js/color-picker-element-esm.js +184 -189
- package/dist/js/color-picker-element-esm.min.js +2 -2
- package/dist/js/color-picker-element.js +184 -189
- package/dist/js/color-picker-element.min.js +2 -2
- package/dist/js/color-picker-esm.js +77 -134
- package/dist/js/color-picker-esm.min.js +2 -2
- package/dist/js/color-picker.js +77 -134
- package/dist/js/color-picker.min.js +2 -2
- package/dist/js/color.js +2 -5
- package/dist/js/color.min.js +1 -1
- package/package.json +20 -19
- package/src/js/color-picker-element.js +45 -37
- package/src/js/color-picker.js +46 -60
- package/src/js/color.js +1 -4
- package/src/js/index.js +5 -0
- package/src/js/util/getColorMenu.js +7 -8
- package/src/js/util/setMarkup.js +4 -7
- package/src/js/util/toggleCEAttr.js +70 -0
- package/src/js/util/version.js +0 -1
- package/src/js/version.js +0 -1
- package/src/scss/_variables.scss +7 -0
- package/src/scss/color-picker.scss +86 -45
- package/types/cp.d.ts +31 -17
- package/types/index.d.ts +0 -4
- package/types/source/source.ts +0 -1
- package/types/source/types.d.ts +8 -6
package/dist/js/color-picker.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* ColorPicker
|
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
|
*/
|
@@ -15,27 +15,26 @@
|
|
15
15
|
/**
|
16
16
|
* The global event listener.
|
17
17
|
*
|
18
|
-
* @
|
19
|
-
* @
|
20
|
-
* @returns {void}
|
18
|
+
* @type {EventListener}
|
19
|
+
* @this {EventTarget}
|
21
20
|
*/
|
22
21
|
function globalListener(e) {
|
23
22
|
const that = this;
|
24
23
|
const { type } = e;
|
25
|
-
const oneEvMap = EventRegistry[type] ? [...EventRegistry[type]] : [];
|
26
24
|
|
27
|
-
|
25
|
+
[...EventRegistry[type]].forEach((elementsMap) => {
|
28
26
|
const [element, listenersMap] = elementsMap;
|
29
|
-
|
30
|
-
|
27
|
+
/* istanbul ignore else */
|
28
|
+
if (element === that) {
|
29
|
+
[...listenersMap].forEach((listenerMap) => {
|
31
30
|
const [listener, options] = listenerMap;
|
32
31
|
listener.apply(element, [e]);
|
33
32
|
|
34
33
|
if (options && options.once) {
|
35
34
|
removeListener(element, type, listener, options);
|
36
35
|
}
|
37
|
-
}
|
38
|
-
}
|
36
|
+
});
|
37
|
+
}
|
39
38
|
});
|
40
39
|
}
|
41
40
|
|
@@ -43,10 +42,7 @@
|
|
43
42
|
* Register a new listener with its options and attach the `globalListener`
|
44
43
|
* to the target if this is the first listener.
|
45
44
|
*
|
46
|
-
* @
|
47
|
-
* @param {string} eventType
|
48
|
-
* @param {EventListenerObject['handleEvent']} listener
|
49
|
-
* @param {AddEventListenerOptions=} options
|
45
|
+
* @type {Listener.ListenerAction<EventTarget>}
|
50
46
|
*/
|
51
47
|
const addListener = (element, eventType, listener, options) => {
|
52
48
|
// get element listeners first
|
@@ -64,9 +60,7 @@
|
|
64
60
|
const { size } = oneElementMap;
|
65
61
|
|
66
62
|
// register listener with its options
|
67
|
-
|
68
|
-
oneElementMap.set(listener, options);
|
69
|
-
}
|
63
|
+
oneElementMap.set(listener, options);
|
70
64
|
|
71
65
|
// add listener last
|
72
66
|
if (!size) {
|
@@ -78,10 +72,7 @@
|
|
78
72
|
* Remove a listener from registry and detach the `globalListener`
|
79
73
|
* if no listeners are found in the registry.
|
80
74
|
*
|
81
|
-
* @
|
82
|
-
* @param {string} eventType
|
83
|
-
* @param {EventListenerObject['handleEvent']} listener
|
84
|
-
* @param {AddEventListenerOptions=} options
|
75
|
+
* @type {Listener.ListenerAction<EventTarget>}
|
85
76
|
*/
|
86
77
|
const removeListener = (element, eventType, listener, options) => {
|
87
78
|
// get listener first
|
@@ -100,6 +91,7 @@
|
|
100
91
|
if (!oneEventMap || !oneEventMap.size) delete EventRegistry[eventType];
|
101
92
|
|
102
93
|
// remove listener last
|
94
|
+
/* istanbul ignore else */
|
103
95
|
if (!oneElementMap || !oneElementMap.size) {
|
104
96
|
element.removeEventListener(eventType, globalListener, eventOptions);
|
105
97
|
}
|
@@ -201,12 +193,6 @@
|
|
201
193
|
*/
|
202
194
|
const changeEvent = 'change';
|
203
195
|
|
204
|
-
/**
|
205
|
-
* A global namespace for `touchstart` event.
|
206
|
-
* @type {string}
|
207
|
-
*/
|
208
|
-
const touchstartEvent = 'touchstart';
|
209
|
-
|
210
196
|
/**
|
211
197
|
* A global namespace for `touchmove` event.
|
212
198
|
* @type {string}
|
@@ -214,28 +200,22 @@
|
|
214
200
|
const touchmoveEvent = 'touchmove';
|
215
201
|
|
216
202
|
/**
|
217
|
-
* A global namespace for `
|
203
|
+
* A global namespace for `pointerdown` event.
|
218
204
|
* @type {string}
|
219
205
|
*/
|
220
|
-
const
|
206
|
+
const pointerdownEvent = 'pointerdown';
|
221
207
|
|
222
208
|
/**
|
223
|
-
* A global namespace for `
|
209
|
+
* A global namespace for `pointermove` event.
|
224
210
|
* @type {string}
|
225
211
|
*/
|
226
|
-
const
|
212
|
+
const pointermoveEvent = 'pointermove';
|
227
213
|
|
228
214
|
/**
|
229
|
-
* A global namespace for `
|
215
|
+
* A global namespace for `pointerup` event.
|
230
216
|
* @type {string}
|
231
217
|
*/
|
232
|
-
const
|
233
|
-
|
234
|
-
/**
|
235
|
-
* A global namespace for `mouseup` event.
|
236
|
-
* @type {string}
|
237
|
-
*/
|
238
|
-
const mouseupEvent = 'mouseup';
|
218
|
+
const pointerupEvent = 'pointerup';
|
239
219
|
|
240
220
|
/**
|
241
221
|
* A global namespace for `scroll` event.
|
@@ -283,27 +263,6 @@
|
|
283
263
|
return getDocument(node).documentElement;
|
284
264
|
}
|
285
265
|
|
286
|
-
/**
|
287
|
-
* Returns the `Window` object of a target node.
|
288
|
-
* @see https://github.com/floating-ui/floating-ui
|
289
|
-
*
|
290
|
-
* @param {(Node | HTMLElement | Element | Window)=} node target node
|
291
|
-
* @returns {globalThis}
|
292
|
-
*/
|
293
|
-
function getWindow(node) {
|
294
|
-
if (node == null) {
|
295
|
-
return window;
|
296
|
-
}
|
297
|
-
|
298
|
-
if (!(node instanceof Window)) {
|
299
|
-
const { ownerDocument } = node;
|
300
|
-
return ownerDocument ? ownerDocument.defaultView || window : window;
|
301
|
-
}
|
302
|
-
|
303
|
-
// @ts-ignore
|
304
|
-
return node;
|
305
|
-
}
|
306
|
-
|
307
266
|
/**
|
308
267
|
* Shortcut for `window.getComputedStyle(element).propertyName`
|
309
268
|
* static method.
|
@@ -1400,7 +1359,7 @@
|
|
1400
1359
|
format = 'hwb';
|
1401
1360
|
}
|
1402
1361
|
if (isValidCSSUnit(color.a)) {
|
1403
|
-
a = color.a;
|
1362
|
+
a = color.a;
|
1404
1363
|
a = isPercentage(`${a}`) || parseFloat(a) > 1 ? bound01(a, 100) : a;
|
1405
1364
|
}
|
1406
1365
|
}
|
@@ -1411,9 +1370,6 @@
|
|
1411
1370
|
return {
|
1412
1371
|
ok,
|
1413
1372
|
format,
|
1414
|
-
// r: Math.min(255, Math.max(rgb.r, 0)),
|
1415
|
-
// g: Math.min(255, Math.max(rgb.g, 0)),
|
1416
|
-
// b: Math.min(255, Math.max(rgb.b, 0)),
|
1417
1373
|
r: rgb.r,
|
1418
1374
|
g: rgb.g,
|
1419
1375
|
b: rgb.b,
|
@@ -2252,17 +2208,16 @@
|
|
2252
2208
|
const isOptionsMenu = menuClass === 'color-options';
|
2253
2209
|
const isPalette = colorsSource instanceof ColorPalette;
|
2254
2210
|
const menuLabel = isOptionsMenu ? presetsLabel : defaultsLabel;
|
2255
|
-
|
2256
|
-
colorsArray = colorsArray instanceof Array ? colorsArray : [];
|
2211
|
+
const colorsArray = isPalette ? colorsSource.colors : colorsSource;
|
2257
2212
|
const colorsCount = colorsArray.length;
|
2258
2213
|
const { lightSteps } = isPalette ? colorsSource : { lightSteps: null };
|
2259
|
-
const fit = lightSteps || [9, 10].find((x) => colorsCount
|
2214
|
+
const fit = lightSteps || [9, 10].find((x) => colorsCount >= x * 2 && !(colorsCount % x)) || 5;
|
2260
2215
|
const isMultiLine = isOptionsMenu && colorsCount > fit;
|
2261
2216
|
let rowCountHover = 2;
|
2262
|
-
rowCountHover = isMultiLine && colorsCount
|
2263
|
-
rowCountHover = colorsCount
|
2264
|
-
rowCountHover = colorsCount
|
2265
|
-
const rowCount = rowCountHover - (colorsCount
|
2217
|
+
rowCountHover = isMultiLine && colorsCount > fit * 2 ? 3 : rowCountHover;
|
2218
|
+
rowCountHover = isMultiLine && colorsCount > fit * 3 ? 4 : rowCountHover;
|
2219
|
+
rowCountHover = isMultiLine && colorsCount > fit * 4 ? 5 : rowCountHover;
|
2220
|
+
const rowCount = rowCountHover - (colorsCount <= fit * 3 ? 1 : 2);
|
2266
2221
|
const isScrollable = isMultiLine && colorsCount > rowCount * fit;
|
2267
2222
|
let finalClass = menuClass;
|
2268
2223
|
finalClass += isScrollable ? ' scrollable' : '';
|
@@ -2270,7 +2225,7 @@
|
|
2270
2225
|
const gap = isMultiLine ? '1px' : '0.25rem';
|
2271
2226
|
let optionSize = isMultiLine ? 1.75 : 2;
|
2272
2227
|
optionSize = fit > 5 && isMultiLine ? 1.5 : optionSize;
|
2273
|
-
const menuHeight = `${
|
2228
|
+
const menuHeight = `${rowCount * optionSize}rem`;
|
2274
2229
|
const menuHeightHover = `calc(${rowCountHover} * ${optionSize}rem + ${rowCountHover - 1} * ${gap})`;
|
2275
2230
|
/** @type {HTMLUListElement} */
|
2276
2231
|
// @ts-ignore -- <UL> is an `HTMLElement`
|
@@ -2377,16 +2332,14 @@
|
|
2377
2332
|
});
|
2378
2333
|
|
2379
2334
|
// color presets
|
2380
|
-
if (
|
2381
|
-
|
2382
|
-
const presetsMenu = getColorMenu(self, colorPresets, 'color-options');
|
2383
|
-
presetsDropdown.append(presetsMenu);
|
2335
|
+
if (colorPresets) {
|
2336
|
+
presetsDropdown.append(getColorMenu(self, colorPresets, 'color-options'));
|
2384
2337
|
}
|
2385
2338
|
|
2386
2339
|
// explicit defaults [reset, initial, inherit, transparent, currentColor]
|
2340
|
+
// also custom defaults [default: #069, complementary: #930]
|
2387
2341
|
if (colorKeywords && colorKeywords.length) {
|
2388
|
-
|
2389
|
-
presetsDropdown.append(keywordsMenu);
|
2342
|
+
presetsDropdown.append(getColorMenu(self, colorKeywords, 'color-defaults'));
|
2390
2343
|
}
|
2391
2344
|
|
2392
2345
|
const presetsBtn = createElement({
|
@@ -2423,9 +2376,7 @@
|
|
2423
2376
|
setAttribute(input, tabIndex, '-1');
|
2424
2377
|
}
|
2425
2378
|
|
2426
|
-
var version = "
|
2427
|
-
|
2428
|
-
// @ts-ignore
|
2379
|
+
var version = "1.0.1";
|
2429
2380
|
|
2430
2381
|
const Version = version;
|
2431
2382
|
|
@@ -2445,7 +2396,7 @@
|
|
2445
2396
|
// ColorPicker Static Methods
|
2446
2397
|
// ==========================
|
2447
2398
|
|
2448
|
-
/** @type {CP.GetInstance<ColorPicker>} */
|
2399
|
+
/** @type {CP.GetInstance<ColorPicker, HTMLInputElement>} */
|
2449
2400
|
const getColorPickerInstance = (element) => getInstance(element, colorPickerString);
|
2450
2401
|
|
2451
2402
|
/** @type {CP.InitCallback<ColorPicker>} */
|
@@ -2480,17 +2431,12 @@
|
|
2480
2431
|
const fn = action ? addListener : removeListener;
|
2481
2432
|
const { input, colorMenu, parent } = self;
|
2482
2433
|
const doc = getDocument(input);
|
2483
|
-
const win =
|
2484
|
-
const pointerEvents = `on${touchstartEvent}` in doc
|
2485
|
-
? { down: touchstartEvent, move: touchmoveEvent, up: touchendEvent }
|
2486
|
-
: { down: mousedownEvent, move: mousemoveEvent, up: mouseupEvent };
|
2434
|
+
const win = doc.defaultView;
|
2487
2435
|
|
2488
|
-
fn(self.controls,
|
2436
|
+
fn(self.controls, pointerdownEvent, self.pointerDown);
|
2489
2437
|
self.controlKnobs.forEach((x) => fn(x, keydownEvent, self.handleKnobs));
|
2490
2438
|
|
2491
|
-
// @ts-ignore -- this is `Window`
|
2492
2439
|
fn(win, scrollEvent, self.handleScroll);
|
2493
|
-
// @ts-ignore -- this is `Window`
|
2494
2440
|
fn(win, resizeEvent, self.update);
|
2495
2441
|
|
2496
2442
|
[input, ...self.inputs].forEach((x) => fn(x, changeEvent, self.changeHandler));
|
@@ -2500,8 +2446,8 @@
|
|
2500
2446
|
fn(colorMenu, keydownEvent, self.menuKeyHandler);
|
2501
2447
|
}
|
2502
2448
|
|
2503
|
-
fn(doc,
|
2504
|
-
fn(doc,
|
2449
|
+
fn(doc, pointermoveEvent, self.pointerMove);
|
2450
|
+
fn(doc, pointerupEvent, self.pointerUp);
|
2505
2451
|
fn(parent, focusoutEvent, self.handleFocusOut);
|
2506
2452
|
fn(doc, keyupEvent, self.handleDismiss);
|
2507
2453
|
}
|
@@ -2520,6 +2466,7 @@
|
|
2520
2466
|
* @returns {void}
|
2521
2467
|
*/
|
2522
2468
|
function removePosition(element) {
|
2469
|
+
/* istanbul ignore else */
|
2523
2470
|
if (element) {
|
2524
2471
|
['bottom', 'top'].forEach((x) => removeClass(element, x));
|
2525
2472
|
}
|
@@ -2583,7 +2530,6 @@
|
|
2583
2530
|
constructor(target, config) {
|
2584
2531
|
const self = this;
|
2585
2532
|
/** @type {HTMLInputElement} */
|
2586
|
-
// @ts-ignore
|
2587
2533
|
const input = querySelector(target);
|
2588
2534
|
|
2589
2535
|
// invalidate
|
@@ -2594,7 +2540,6 @@
|
|
2594
2540
|
if (!parent) throw new TypeError('ColorPicker requires a specific markup to work.');
|
2595
2541
|
|
2596
2542
|
/** @type {HTMLElement} */
|
2597
|
-
// @ts-ignore
|
2598
2543
|
self.parent = parent;
|
2599
2544
|
|
2600
2545
|
/** @type {number} */
|
@@ -2622,6 +2567,7 @@
|
|
2622
2567
|
} = normalizeOptions(this.isCE ? parent : input, colorPickerDefaults, config || {});
|
2623
2568
|
|
2624
2569
|
let translatedColorLabels = colorNames;
|
2570
|
+
/* istanbul ignore else */
|
2625
2571
|
if (colorLabels instanceof Array && colorLabels.length === 17) {
|
2626
2572
|
translatedColorLabels = colorLabels;
|
2627
2573
|
} else if (colorLabels && colorLabels.split(',').length === 17) {
|
@@ -2638,7 +2584,7 @@
|
|
2638
2584
|
? JSON.parse(componentLabels) : componentLabels;
|
2639
2585
|
|
2640
2586
|
/** @type {Record<string, string>} */
|
2641
|
-
self.componentLabels = ObjectAssign(colorPickerLabels, tempComponentLabels);
|
2587
|
+
self.componentLabels = ObjectAssign({ ...colorPickerLabels }, tempComponentLabels);
|
2642
2588
|
|
2643
2589
|
/** @type {Color} */
|
2644
2590
|
self.color = new Color(input.value || '#fff', format);
|
@@ -2647,14 +2593,14 @@
|
|
2647
2593
|
self.format = format;
|
2648
2594
|
|
2649
2595
|
// set colour defaults
|
2650
|
-
if (colorKeywords instanceof Array) {
|
2596
|
+
if (colorKeywords instanceof Array && colorKeywords.length) {
|
2651
2597
|
self.colorKeywords = colorKeywords;
|
2652
2598
|
} else if (typeof colorKeywords === 'string' && colorKeywords.length) {
|
2653
2599
|
self.colorKeywords = colorKeywords.split(',').map((x) => x.trim());
|
2654
2600
|
}
|
2655
2601
|
|
2656
2602
|
// set colour presets
|
2657
|
-
if (colorPresets instanceof Array) {
|
2603
|
+
if (colorPresets instanceof Array && colorPresets.length) {
|
2658
2604
|
self.colorPresets = colorPresets;
|
2659
2605
|
} else if (typeof colorPresets === 'string' && colorPresets.length) {
|
2660
2606
|
if (isValidJSON(colorPresets)) {
|
@@ -2687,26 +2633,20 @@
|
|
2687
2633
|
const [colorPicker, colorMenu] = getElementsByClassName('color-dropdown', parent);
|
2688
2634
|
// set main elements
|
2689
2635
|
/** @type {HTMLElement} */
|
2690
|
-
// @ts-ignore
|
2691
2636
|
self.pickerToggle = querySelector('.picker-toggle', parent);
|
2692
2637
|
/** @type {HTMLElement} */
|
2693
|
-
// @ts-ignore
|
2694
2638
|
self.menuToggle = querySelector('.menu-toggle', parent);
|
2695
2639
|
/** @type {HTMLElement} */
|
2696
|
-
// @ts-ignore
|
2697
2640
|
self.colorPicker = colorPicker;
|
2698
2641
|
/** @type {HTMLElement} */
|
2699
|
-
// @ts-ignore
|
2700
2642
|
self.colorMenu = colorMenu;
|
2701
2643
|
/** @type {HTMLInputElement[]} */
|
2702
|
-
// @ts-ignore
|
2703
2644
|
self.inputs = [...getElementsByClassName('color-input', parent)];
|
2704
2645
|
const [controls] = getElementsByClassName('color-controls', parent);
|
2705
2646
|
self.controls = controls;
|
2706
2647
|
/** @type {(HTMLElement | Element)[]} */
|
2707
2648
|
self.controlKnobs = [...getElementsByClassName('knob', controls)];
|
2708
2649
|
/** @type {(HTMLElement)[]} */
|
2709
|
-
// @ts-ignore
|
2710
2650
|
self.visuals = [...getElementsByClassName('visual-control', controls)];
|
2711
2651
|
|
2712
2652
|
// update colour picker controls, inputs and visuals
|
@@ -2785,6 +2725,7 @@
|
|
2785
2725
|
let colorName;
|
2786
2726
|
|
2787
2727
|
// determine color appearance
|
2728
|
+
/* istanbul ignore else */
|
2788
2729
|
if (lightness === 100 && saturation === 0) {
|
2789
2730
|
colorName = colorLabels.white;
|
2790
2731
|
} else if (lightness === 0) {
|
@@ -2858,7 +2799,6 @@
|
|
2858
2799
|
* @this {ColorPicker}
|
2859
2800
|
*/
|
2860
2801
|
handleFocusOut({ relatedTarget }) {
|
2861
|
-
// @ts-ignore
|
2862
2802
|
if (relatedTarget && !this.parent.contains(relatedTarget)) {
|
2863
2803
|
this.hide(true);
|
2864
2804
|
}
|
@@ -2885,13 +2825,14 @@
|
|
2885
2825
|
const self = this;
|
2886
2826
|
const { activeElement } = getDocument(self.input);
|
2887
2827
|
|
2888
|
-
|
2828
|
+
self.updateDropdownPosition();
|
2829
|
+
|
2830
|
+
/* istanbul ignore next */
|
2831
|
+
if (([pointermoveEvent, touchmoveEvent].includes(e.type) && self.dragElement)
|
2889
2832
|
|| (activeElement && self.controlKnobs.includes(activeElement))) {
|
2890
2833
|
e.stopPropagation();
|
2891
2834
|
e.preventDefault();
|
2892
2835
|
}
|
2893
|
-
|
2894
|
-
self.updateDropdownPosition();
|
2895
2836
|
}
|
2896
2837
|
|
2897
2838
|
/**
|
@@ -2901,7 +2842,6 @@
|
|
2901
2842
|
*/
|
2902
2843
|
menuKeyHandler(e) {
|
2903
2844
|
const { target, code } = e;
|
2904
|
-
// @ts-ignore
|
2905
2845
|
const { previousElementSibling, nextElementSibling, parentElement } = target;
|
2906
2846
|
const isColorOptionsMenu = parentElement && hasClass(parentElement, 'color-options');
|
2907
2847
|
const allSiblings = [...parentElement.children];
|
@@ -2940,20 +2880,20 @@
|
|
2940
2880
|
|
2941
2881
|
/**
|
2942
2882
|
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
2943
|
-
* @param {
|
2883
|
+
* @param {Event} e
|
2944
2884
|
* @this {ColorPicker}
|
2945
2885
|
*/
|
2946
2886
|
menuClickHandler(e) {
|
2947
2887
|
const self = this;
|
2948
|
-
/** @type {*} */
|
2949
2888
|
const { target } = e;
|
2950
2889
|
const { colorMenu } = self;
|
2951
2890
|
const newOption = (getAttribute(target, 'data-value') || '').trim();
|
2952
2891
|
// invalidate for targets other than color options
|
2953
2892
|
if (!newOption.length) return;
|
2954
2893
|
const currentActive = querySelector('li.active', colorMenu);
|
2955
|
-
let newColor =
|
2956
|
-
newColor =
|
2894
|
+
let newColor = newOption;
|
2895
|
+
newColor = nonColors.includes(newColor) ? 'white' : newColor;
|
2896
|
+
newColor = newColor === 'transparent' ? 'rgba(0,0,0,0)' : newColor;
|
2957
2897
|
|
2958
2898
|
const {
|
2959
2899
|
r, g, b, a,
|
@@ -2965,7 +2905,9 @@
|
|
2965
2905
|
|
2966
2906
|
self.update();
|
2967
2907
|
|
2908
|
+
/* istanbul ignore else */
|
2968
2909
|
if (currentActive !== target) {
|
2910
|
+
/* istanbul ignore else */
|
2969
2911
|
if (currentActive) {
|
2970
2912
|
removeClass(currentActive, 'active');
|
2971
2913
|
removeAttribute(currentActive, ariaSelected);
|
@@ -2983,15 +2925,13 @@
|
|
2983
2925
|
|
2984
2926
|
/**
|
2985
2927
|
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
2986
|
-
* @param {
|
2928
|
+
* @param {PointerEvent} e
|
2987
2929
|
* @this {ColorPicker}
|
2988
2930
|
*/
|
2989
2931
|
pointerDown(e) {
|
2990
2932
|
const self = this;
|
2991
2933
|
/** @type {*} */
|
2992
|
-
const {
|
2993
|
-
type, target, touches, pageX, pageY,
|
2994
|
-
} = e;
|
2934
|
+
const { target, pageX, pageY } = e;
|
2995
2935
|
const { colorMenu, visuals, controlKnobs } = self;
|
2996
2936
|
const [v1, v2, v3] = visuals;
|
2997
2937
|
const [c1, c2, c3] = controlKnobs;
|
@@ -2999,11 +2939,10 @@
|
|
2999
2939
|
const visual = controlKnobs.includes(target) ? target.previousElementSibling : target;
|
3000
2940
|
const visualRect = getBoundingClientRect(visual);
|
3001
2941
|
const html = getDocumentElement(v1);
|
3002
|
-
const
|
3003
|
-
const
|
3004
|
-
const offsetX = X - html.scrollLeft - visualRect.left;
|
3005
|
-
const offsetY = Y - html.scrollTop - visualRect.top;
|
2942
|
+
const offsetX = pageX - html.scrollLeft - visualRect.left;
|
2943
|
+
const offsetY = pageY - html.scrollTop - visualRect.top;
|
3006
2944
|
|
2945
|
+
/* istanbul ignore else */
|
3007
2946
|
if (target === v1 || target === c1) {
|
3008
2947
|
self.dragElement = visual;
|
3009
2948
|
self.changeControl1(offsetX, offsetY);
|
@@ -3027,7 +2966,7 @@
|
|
3027
2966
|
|
3028
2967
|
/**
|
3029
2968
|
* The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
|
3030
|
-
* @param {
|
2969
|
+
* @param {PointerEvent} e
|
3031
2970
|
* @this {ColorPicker}
|
3032
2971
|
*/
|
3033
2972
|
pointerUp({ target }) {
|
@@ -3036,9 +2975,8 @@
|
|
3036
2975
|
const doc = getDocument(parent);
|
3037
2976
|
const currentOpen = querySelector(`${colorPickerParentSelector}.open`, doc) !== null;
|
3038
2977
|
const selection = doc.getSelection();
|
3039
|
-
|
2978
|
+
|
3040
2979
|
if (!self.dragElement && !selection.toString().length
|
3041
|
-
// @ts-ignore
|
3042
2980
|
&& !parent.contains(target)) {
|
3043
2981
|
self.hide(currentOpen);
|
3044
2982
|
}
|
@@ -3048,25 +2986,20 @@
|
|
3048
2986
|
|
3049
2987
|
/**
|
3050
2988
|
* The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
|
3051
|
-
* @param {
|
2989
|
+
* @param {PointerEvent} e
|
3052
2990
|
*/
|
3053
2991
|
pointerMove(e) {
|
3054
2992
|
const self = this;
|
3055
2993
|
const { dragElement, visuals } = self;
|
3056
2994
|
const [v1, v2, v3] = visuals;
|
3057
|
-
const {
|
3058
|
-
// @ts-ignore
|
3059
|
-
type, touches, pageX, pageY,
|
3060
|
-
} = e;
|
2995
|
+
const { pageX, pageY } = e;
|
3061
2996
|
|
3062
2997
|
if (!dragElement) return;
|
3063
2998
|
|
3064
2999
|
const controlRect = getBoundingClientRect(dragElement);
|
3065
3000
|
const win = getDocumentElement(v1);
|
3066
|
-
const
|
3067
|
-
const
|
3068
|
-
const offsetX = X - win.scrollLeft - controlRect.left;
|
3069
|
-
const offsetY = Y - win.scrollTop - controlRect.top;
|
3001
|
+
const offsetX = pageX - win.scrollLeft - controlRect.left;
|
3002
|
+
const offsetY = pageY - win.scrollTop - controlRect.top;
|
3070
3003
|
|
3071
3004
|
if (dragElement === v1) {
|
3072
3005
|
self.changeControl1(offsetX, offsetY);
|
@@ -3100,13 +3033,16 @@
|
|
3100
3033
|
const currentKnob = controlKnobs.find((x) => x === activeElement);
|
3101
3034
|
const yRatio = offsetHeight / 360;
|
3102
3035
|
|
3036
|
+
/* istanbul ignore else */
|
3103
3037
|
if (currentKnob) {
|
3104
3038
|
let offsetX = 0;
|
3105
3039
|
let offsetY = 0;
|
3106
3040
|
|
3041
|
+
/* istanbul ignore else */
|
3107
3042
|
if (target === c1) {
|
3108
3043
|
const xRatio = offsetWidth / 100;
|
3109
3044
|
|
3045
|
+
/* istanbul ignore else */
|
3110
3046
|
if ([keyArrowLeft, keyArrowRight].includes(code)) {
|
3111
3047
|
self.controlPositions.c1x += code === keyArrowRight ? xRatio : -xRatio;
|
3112
3048
|
} else if ([keyArrowUp, keyArrowDown].includes(code)) {
|
@@ -3152,6 +3088,7 @@
|
|
3152
3088
|
const isNonColorValue = self.hasNonColor && nonColors.includes(currentValue);
|
3153
3089
|
const alpha = i4 ? v4 : (1 - controlPositions.c3y / offsetHeight);
|
3154
3090
|
|
3091
|
+
/* istanbul ignore else */
|
3155
3092
|
if (activeElement === input || (activeElement && inputs.includes(activeElement))) {
|
3156
3093
|
if (activeElement === input) {
|
3157
3094
|
if (isNonColorValue) {
|
@@ -3466,6 +3403,7 @@
|
|
3466
3403
|
const hue = roundPart(hsl.h * 360);
|
3467
3404
|
let newColor;
|
3468
3405
|
|
3406
|
+
/* istanbul ignore else */
|
3469
3407
|
if (format === 'hex') {
|
3470
3408
|
newColor = self.color.toHexString(true);
|
3471
3409
|
i1.value = self.hex;
|
@@ -3566,15 +3504,15 @@
|
|
3566
3504
|
const relatedBtn = openPicker ? pickerToggle : menuToggle;
|
3567
3505
|
const animationDuration = openDropdown && getElementTransitionDuration(openDropdown);
|
3568
3506
|
|
3569
|
-
// if (!self.isValid) {
|
3570
3507
|
self.value = self.color.toString(true);
|
3571
|
-
// }
|
3572
3508
|
|
3509
|
+
/* istanbul ignore else */
|
3573
3510
|
if (openDropdown) {
|
3574
3511
|
removeClass(openDropdown, 'show');
|
3575
3512
|
setAttribute(relatedBtn, ariaExpanded, 'false');
|
3576
3513
|
setTimeout(() => {
|
3577
3514
|
removePosition(openDropdown);
|
3515
|
+
/* istanbul ignore else */
|
3578
3516
|
if (!querySelector('.show', parent)) {
|
3579
3517
|
removeClass(parent, 'open');
|
3580
3518
|
toggleEventsOnShown(self);
|
@@ -3587,7 +3525,7 @@
|
|
3587
3525
|
focus(pickerToggle);
|
3588
3526
|
}
|
3589
3527
|
setAttribute(input, tabIndex, '-1');
|
3590
|
-
if (menuToggle) {
|
3528
|
+
if (relatedBtn === menuToggle) {
|
3591
3529
|
setAttribute(menuToggle, tabIndex, '-1');
|
3592
3530
|
}
|
3593
3531
|
}
|
@@ -3625,6 +3563,11 @@
|
|
3625
3563
|
getBoundingClientRect,
|
3626
3564
|
});
|
3627
3565
|
|
3566
|
+
/**
|
3567
|
+
* A single import is required to add the `CP` namespace to `src` sources.
|
3568
|
+
* @typedef {import("../../types/index")}
|
3569
|
+
*/
|
3570
|
+
|
3628
3571
|
return ColorPicker;
|
3629
3572
|
|
3630
3573
|
}));
|