@thednp/color-picker 1.0.0 → 2.0.0-alpha1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +199 -0
- package/.lgtm.yml +9 -0
- package/.prettierrc.json +15 -0
- package/.stylelintrc.json +236 -0
- package/LICENSE +0 -0
- package/README.md +63 -80
- package/compile.js +48 -0
- package/cypress/downloads/downloads.htm +0 -0
- package/cypress/e2e/color-palette.cy.ts +128 -0
- package/cypress/e2e/color-picker.cy.ts +920 -0
- package/cypress/fixtures/colorNamesFrench.js +3 -0
- package/cypress/fixtures/componentLabelsFrench.js +21 -0
- package/cypress/fixtures/format.js +3 -0
- package/cypress/fixtures/getCEMarkup.js +29 -0
- package/cypress/fixtures/getMarkup.js +28 -0
- package/cypress/fixtures/getRandomInt.js +6 -0
- package/cypress/fixtures/sampleWebcolors.js +18 -0
- package/cypress/fixtures/testSample.js +8 -0
- package/cypress/plugins/esbuild-istanbul.ts +50 -0
- package/cypress/plugins/tsCompile.ts +34 -0
- package/cypress/support/commands.ts +0 -0
- package/cypress/support/e2e.ts +21 -0
- package/cypress/test.html +23 -0
- package/cypress.config.ts +29 -0
- package/dist/css/color-picker.css +15 -39
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +15 -39
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-picker.cjs +8 -0
- package/dist/js/color-picker.cjs.map +1 -0
- package/dist/js/color-picker.d.ts +278 -0
- package/dist/js/color-picker.js +5 -3583
- package/dist/js/color-picker.js.map +1 -0
- package/dist/js/color-picker.mjs +2631 -0
- package/dist/js/color-picker.mjs.map +1 -0
- package/dts.config.ts +15 -0
- package/package.json +64 -74
- package/src/scss/_variables.scss +0 -1
- package/src/scss/color-picker.rtl.scss +4 -0
- package/src/scss/color-picker.scss +75 -39
- package/src/ts/colorPalette.ts +89 -0
- package/src/{js/color-picker.js → ts/index.ts} +492 -502
- package/src/ts/interface/colorPickerLabels.ts +20 -0
- package/src/ts/interface/colorPickerOptions.ts +11 -0
- package/src/ts/interface/paletteOptions.ts +6 -0
- package/src/ts/util/colorNames.ts +21 -0
- package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
- package/src/ts/util/getColorControls.ts +90 -0
- package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
- package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
- package/src/ts/util/isValidJSON.ts +19 -0
- package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +57 -48
- package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
- package/tsconfig.json +29 -0
- package/vite.config.ts +34 -0
- package/dist/js/color-esm.js +0 -1167
- package/dist/js/color-esm.min.js +0 -2
- package/dist/js/color-palette-esm.js +0 -1238
- package/dist/js/color-palette-esm.min.js +0 -2
- package/dist/js/color-palette.js +0 -1246
- package/dist/js/color-palette.min.js +0 -2
- package/dist/js/color-picker-element-esm.js +0 -3739
- package/dist/js/color-picker-element-esm.min.js +0 -2
- package/dist/js/color-picker-element.js +0 -3747
- package/dist/js/color-picker-element.min.js +0 -2
- package/dist/js/color-picker-esm.js +0 -3578
- package/dist/js/color-picker-esm.min.js +0 -2
- package/dist/js/color-picker.min.js +0 -2
- package/dist/js/color.js +0 -1175
- package/dist/js/color.min.js +0 -2
- package/src/js/color-palette.js +0 -75
- package/src/js/color-picker-element.js +0 -110
- package/src/js/color.js +0 -1107
- package/src/js/index.js +0 -3
- package/src/js/util/colorNames.js +0 -6
- package/src/js/util/getColorControls.js +0 -103
- package/src/js/util/isValidJSON.js +0 -13
- package/src/js/util/nonColors.js +0 -5
- package/src/js/util/roundPart.js +0 -9
- package/src/js/util/setCSSProperties.js +0 -12
- package/src/js/util/tabindex.js +0 -3
- package/src/js/util/toggleCEAttr.js +0 -70
- package/src/js/util/version.js +0 -6
- package/src/js/version.js +0 -6
- package/types/cp.d.ts +0 -544
- package/types/index.d.ts +0 -48
- package/types/source/source.ts +0 -5
- package/types/source/types.d.ts +0 -92
@@ -1,99 +1,100 @@
|
|
1
|
-
import { addListener, removeListener } from '@thednp/event-listener
|
2
|
-
|
3
|
-
import
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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 '
|
56
|
-
import
|
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
|
-
|
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}
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
118
|
-
const win = doc.defaultView;
|
116
|
+
const win = getWindow(doc);
|
119
117
|
|
120
|
-
fn(self.controls, pointerdownEvent, self.pointerDown);
|
121
|
-
self.controlKnobs.forEach(
|
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(
|
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
|
-
|
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
|
-
|
147
|
+
const removePosition = (element: HTMLElement) => {
|
155
148
|
/* istanbul ignore else */
|
156
149
|
if (element) {
|
157
|
-
['bottom', 'top'].forEach(
|
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
|
-
|
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,
|
181
|
+
setAttribute(self.input, tabindex, '0');
|
193
182
|
if (menuToggle) {
|
194
|
-
setAttribute(menuToggle,
|
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
|
214
|
-
* @param
|
242
|
+
* @param target the target `<input>` element
|
243
|
+
* @param config instance options
|
215
244
|
*/
|
216
|
-
constructor(target, config) {
|
217
|
-
const
|
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 (
|
224
|
-
|
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
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
-
|
246
|
-
|
247
|
-
|
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
|
-
|
255
|
-
|
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
|
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
|
-
|
287
|
+
this.colorLabels[c] = translatedColorLabels[i].trim();
|
268
288
|
});
|
269
289
|
|
270
290
|
// update and expose component labels
|
271
|
-
const tempComponentLabels =
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
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
|
285
|
-
|
286
|
-
} else if (
|
287
|
-
|
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
|
292
|
-
|
293
|
-
} else if (
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
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
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
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(
|
338
|
+
setMarkup(this);
|
320
339
|
|
321
340
|
const [colorPicker, colorMenu] = getElementsByClassName('color-dropdown', parent);
|
322
341
|
// set main elements
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
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
|
-
|
340
|
-
|
341
|
-
|
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
|
-
|
353
|
+
this.update();
|
354
|
+
// console.log(this)
|
348
355
|
|
349
356
|
// add main events listeners
|
350
|
-
toggleEvents(
|
357
|
+
toggleEvents(this, true);
|
351
358
|
|
352
359
|
// set component data
|
353
|
-
Data.set(input, colorPickerString,
|
360
|
+
Data.set(input, colorPickerString, this);
|
354
361
|
}
|
355
362
|
|
356
363
|
/** Returns the current colour value */
|
357
|
-
get 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) {
|
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() {
|
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() {
|
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() {
|
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() {
|
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() {
|
403
|
+
get rgb(): RGBA {
|
404
|
+
return this.color.toRgb();
|
405
|
+
}
|
388
406
|
|
389
407
|
/** Returns the current colour brightness. */
|
390
|
-
get brightness() {
|
408
|
+
get brightness(): number {
|
409
|
+
return this.color.brightness;
|
410
|
+
}
|
391
411
|
|
392
412
|
/** Returns the current colour luminance. */
|
393
|
-
get 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
|
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(
|
485
|
+
const roundA = roundPart(alpha * 100) / 100;
|
469
486
|
|
470
487
|
const fill = new Color({
|
471
|
-
h: hue,
|
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
|
-
*
|
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
|
-
*
|
524
|
+
*
|
525
|
+
* @param e
|
505
526
|
* @this {ColorPicker}
|
506
527
|
*/
|
507
|
-
handleDismiss({ code }) {
|
508
|
-
|
509
|
-
|
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
|
-
*
|
536
|
+
*
|
537
|
+
* @param e
|
517
538
|
* @this {ColorPicker}
|
518
539
|
*/
|
519
|
-
handleScroll(e) {
|
520
|
-
const
|
521
|
-
const { activeElement } = getDocument(self.input);
|
540
|
+
handleScroll(e: Event): void {
|
541
|
+
const { activeElement } = getDocument(this.input);
|
522
542
|
|
523
|
-
|
543
|
+
this.updateDropdownPosition();
|
524
544
|
|
525
545
|
/* istanbul ignore next */
|
526
|
-
if (
|
527
|
-
|
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
|
-
*
|
536
|
-
* @
|
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 =
|
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
|
-
|
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(
|
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
|
-
*
|
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 } =
|
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 =
|
592
|
-
newColor =
|
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(
|
599
|
-
r,
|
615
|
+
ObjectAssign(this.color, {
|
616
|
+
r,
|
617
|
+
g,
|
618
|
+
b,
|
619
|
+
a,
|
600
620
|
});
|
601
621
|
|
602
|
-
|
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
|
-
|
636
|
+
this.value = newOption;
|
617
637
|
}
|
618
|
-
firePickerChange(
|
638
|
+
firePickerChange(this);
|
619
639
|
}
|
620
640
|
}
|
621
641
|
|
622
642
|
/**
|
623
643
|
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
624
|
-
*
|
625
|
-
* @
|
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 } =
|
649
|
+
const { colorMenu, visuals, controlKnobs } = this;
|
632
650
|
const [v1, v2, v3] = visuals;
|
633
651
|
const [c1, c2, c3] = controlKnobs;
|
634
|
-
|
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
|
-
|
644
|
-
|
660
|
+
this.dragElement = visual;
|
661
|
+
this.changeControl1(offsetX, offsetY);
|
645
662
|
} else if (target === v2 || target === c2) {
|
646
|
-
|
647
|
-
|
663
|
+
this.dragElement = visual;
|
664
|
+
this.changeControl2(offsetY);
|
648
665
|
} else if (target === v3 || target === c3) {
|
649
|
-
|
650
|
-
|
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
|
-
*
|
666
|
-
* @
|
682
|
+
*
|
683
|
+
* @param e
|
684
|
+
* @this
|
667
685
|
*/
|
668
|
-
pointerUp({ target }) {
|
669
|
-
const
|
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 (!
|
676
|
-
|
677
|
-
self.hide(currentOpen);
|
692
|
+
if (!this.dragElement && (!selection || !selection.toString().length) && !parent.contains(target)) {
|
693
|
+
this.hide(currentOpen);
|
678
694
|
}
|
679
695
|
|
680
|
-
|
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
|
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
|
-
|
717
|
+
this.changeControl1(offsetX, offsetY);
|
702
718
|
}
|
703
719
|
|
704
720
|
if (dragElement === v2) {
|
705
|
-
|
721
|
+
this.changeControl2(offsetY);
|
706
722
|
}
|
707
723
|
|
708
724
|
if (dragElement === v3) {
|
709
|
-
|
725
|
+
this.changeAlpha(offsetY);
|
710
726
|
}
|
711
727
|
}
|
712
728
|
|
713
729
|
/**
|
714
730
|
* The `ColorPicker` *keydown* event listener for control knobs.
|
715
|
-
*
|
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 } =
|
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(
|
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
|
-
|
759
|
+
this.controlPositions.c1x += code === keyArrowRight ? xRatio : -xRatio;
|
744
760
|
} else if ([keyArrowUp, keyArrowDown].includes(code)) {
|
745
|
-
|
761
|
+
this.controlPositions.c1y += code === keyArrowDown ? yRatio : -yRatio;
|
746
762
|
}
|
747
763
|
|
748
|
-
offsetX =
|
749
|
-
offsetY =
|
750
|
-
|
764
|
+
offsetX = this.controlPositions.c1x;
|
765
|
+
offsetY = this.controlPositions.c1y;
|
766
|
+
this.changeControl1(offsetX, offsetY);
|
751
767
|
} else if (target === c2) {
|
752
|
-
|
753
|
-
? yRatio
|
754
|
-
: -yRatio;
|
768
|
+
this.controlPositions.c2y += [keyArrowDown, keyArrowRight].includes(code) ? yRatio : -yRatio;
|
755
769
|
|
756
|
-
offsetY =
|
757
|
-
|
770
|
+
offsetY = this.controlPositions.c2y;
|
771
|
+
this.changeControl2(offsetY);
|
758
772
|
} else if (target === c3) {
|
759
|
-
|
760
|
-
? yRatio
|
761
|
-
: -yRatio;
|
773
|
+
this.controlPositions.c3y += [keyArrowDown, keyArrowRight].includes(code) ? yRatio : -yRatio;
|
762
774
|
|
763
|
-
offsetY =
|
764
|
-
|
775
|
+
offsetY = this.controlPositions.c3y;
|
776
|
+
this.changeAlpha(offsetY);
|
765
777
|
}
|
766
|
-
|
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
|
781
|
-
const [v1, v2, v3, v4] =
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
const
|
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,
|
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,
|
815
|
+
h: v1,
|
816
|
+
w: v2,
|
817
|
+
b: v3,
|
818
|
+
a: alpha,
|
804
819
|
};
|
805
820
|
} else {
|
806
821
|
colorSource = {
|
807
|
-
r: v1,
|
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(
|
816
|
-
r,
|
831
|
+
ObjectAssign(this.color, {
|
832
|
+
r,
|
833
|
+
g,
|
834
|
+
b,
|
835
|
+
a,
|
817
836
|
});
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
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
|
-
|
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
|
837
|
-
* @param
|
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 } =
|
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
|
-
|
861
|
-
|
862
|
-
|
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(
|
866
|
-
r,
|
884
|
+
ObjectAssign(this.color, {
|
885
|
+
r,
|
886
|
+
g,
|
887
|
+
b,
|
888
|
+
a,
|
867
889
|
});
|
868
890
|
|
869
891
|
// new positions
|
870
|
-
|
871
|
-
|
892
|
+
this.controlPositions.c1x = offsetX;
|
893
|
+
this.controlPositions.c1y = offsetY;
|
872
894
|
|
873
895
|
// update color picker
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
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
|
907
|
+
* @param Y the Y offset
|
886
908
|
*/
|
887
|
-
changeControl2(Y) {
|
888
|
-
const
|
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
|
-
|
907
|
-
|
908
|
-
|
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(
|
912
|
-
r,
|
931
|
+
ObjectAssign(this.color, {
|
932
|
+
r,
|
933
|
+
g,
|
934
|
+
b,
|
935
|
+
a,
|
913
936
|
});
|
914
937
|
|
915
938
|
// new position
|
916
|
-
|
939
|
+
this.controlPositions.c2y = offsetY;
|
917
940
|
// update color picker
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
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
|
951
|
+
* @param Y
|
929
952
|
*/
|
930
|
-
changeAlpha(Y) {
|
931
|
-
const
|
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
|
-
|
963
|
+
this.color.setAlpha(alpha);
|
942
964
|
// update position
|
943
|
-
|
965
|
+
this.controlPositions.c3y = offsetY;
|
944
966
|
// update color picker
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
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
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
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
|
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
|
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
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
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
|
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 =
|
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 } =
|
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(
|
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 (!
|
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, {
|
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
|
-
*
|
1101
|
+
*
|
1102
|
+
* @param isPrevented when `true`, the component original event is prevented
|
1091
1103
|
*/
|
1092
|
-
updateInputs(isPrevented) {
|
1093
|
-
const
|
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 =
|
1105
|
-
i1.value =
|
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 =
|
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 } =
|
1124
|
+
const { w, b } = this.hwb;
|
1116
1125
|
const whiteness = roundPart(w * 100);
|
1117
1126
|
const blackness = roundPart(b * 100);
|
1118
1127
|
|
1119
|
-
newColor =
|
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 } =
|
1134
|
+
let { r, g, b } = this.rgb;
|
1126
1135
|
[r, g, b] = [r, g, b].map(roundPart);
|
1127
1136
|
|
1128
|
-
newColor =
|
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
|
-
|
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(
|
1149
|
+
firePickerChange(this);
|
1141
1150
|
}
|
1142
1151
|
}
|
1143
1152
|
|
1144
1153
|
/**
|
1145
1154
|
* Toggle the `ColorPicker` dropdown visibility.
|
1146
|
-
*
|
1147
|
-
* @
|
1155
|
+
*
|
1156
|
+
* @param e
|
1148
1157
|
*/
|
1149
|
-
togglePicker(e) {
|
1158
|
+
togglePicker(e?: Event) {
|
1150
1159
|
if (e) e.preventDefault();
|
1151
|
-
const
|
1152
|
-
const { colorPicker } = self;
|
1160
|
+
const { colorPicker } = this;
|
1153
1161
|
|
1154
|
-
if (
|
1155
|
-
|
1162
|
+
if (this.isOpen && hasClass(colorPicker, 'show')) {
|
1163
|
+
this.hide(true);
|
1156
1164
|
} else {
|
1157
|
-
showDropdown(
|
1165
|
+
showDropdown(this, colorPicker);
|
1158
1166
|
}
|
1159
1167
|
}
|
1160
1168
|
|
1161
1169
|
/** Shows the `ColorPicker` dropdown. */
|
1162
1170
|
showPicker() {
|
1163
|
-
const
|
1164
|
-
const { colorPicker } = self;
|
1171
|
+
const { colorPicker } = this;
|
1165
1172
|
|
1166
|
-
if (!['top', 'bottom'].some(
|
1167
|
-
showDropdown(
|
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
|
-
*
|
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
|
1179
|
-
const { colorMenu } = self;
|
1186
|
+
const { colorMenu } = this;
|
1180
1187
|
|
1181
|
-
if (
|
1182
|
-
|
1188
|
+
if (this.isOpen && hasClass(colorMenu, 'show')) {
|
1189
|
+
this.hide(true);
|
1183
1190
|
} else {
|
1184
|
-
showDropdown(
|
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
|
-
|
1194
|
-
|
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
|
-
|
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(
|
1215
|
-
|
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,
|
1228
|
+
setAttribute(input, tabindex, '-1');
|
1224
1229
|
if (relatedBtn === menuToggle) {
|
1225
|
-
setAttribute(menuToggle,
|
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
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
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,
|
1244
|
+
removeAttribute(input, tabindex);
|
1241
1245
|
setElementStyle(input, { backgroundColor: '' });
|
1242
1246
|
|
1243
|
-
['txt-light', 'txt-dark'].forEach(
|
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
|
-
});
|