@thednp/color-picker 2.0.1 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +25 -14
- package/dist/css/color-picker.css +3 -6
- package/dist/css/color-picker.css.map +1 -0
- package/dist/css/color-picker.min.css +1 -2
- package/dist/css/color-picker.min.css.map +1 -0
- package/dist/css/color-picker.rtl.css +3 -6
- package/dist/css/color-picker.rtl.css.map +1 -0
- package/dist/css/color-picker.rtl.min.css +1 -2
- package/dist/css/color-picker.rtl.min.css.map +1 -0
- package/dist/js/color-picker.cjs +2 -2
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.d.ts +307 -300
- package/dist/js/color-picker.js +2 -2
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +423 -382
- package/dist/js/color-picker.mjs.map +1 -1
- package/package.json +39 -50
- package/.eslintrc.cjs +0 -199
- package/.lgtm.yml +0 -9
- package/.prettierrc.json +0 -15
- package/.stylelintrc.json +0 -236
- package/compile.cjs +0 -51
- package/cypress/e2e/color-palette.cy.ts +0 -128
- package/cypress/e2e/color-picker.cy.ts +0 -909
- package/cypress/fixtures/colorNamesFrench.js +0 -3
- package/cypress/fixtures/componentLabelsFrench.js +0 -21
- package/cypress/fixtures/format.js +0 -3
- package/cypress/fixtures/getMarkup.js +0 -35
- package/cypress/fixtures/getRandomInt.js +0 -6
- package/cypress/fixtures/sampleWebcolors.js +0 -18
- package/cypress/fixtures/testSample.js +0 -8
- package/cypress/plugins/esbuild-istanbul.ts +0 -50
- package/cypress/plugins/tsCompile.ts +0 -34
- package/cypress/support/commands.ts +0 -0
- package/cypress/support/e2e.ts +0 -21
- package/cypress/test.html +0 -23
- package/cypress.config.ts +0 -30
- package/dts.config.ts +0 -15
- package/src/scss/_variables.scss +0 -6
- package/src/scss/color-picker.rtl.scss +0 -27
- package/src/scss/color-picker.scss +0 -536
- package/src/ts/colorPalette.ts +0 -89
- package/src/ts/index.ts +0 -1236
- package/src/ts/interface/ColorNames.ts +0 -20
- package/src/ts/interface/colorPickerLabels.ts +0 -20
- package/src/ts/interface/colorPickerOptions.ts +0 -11
- package/src/ts/interface/paletteOptions.ts +0 -6
- package/src/ts/util/colorNames.ts +0 -21
- package/src/ts/util/colorPickerLabels.ts +0 -24
- package/src/ts/util/getColorControls.ts +0 -90
- package/src/ts/util/getColorForm.ts +0 -75
- package/src/ts/util/getColorMenu.ts +0 -83
- package/src/ts/util/isValidJSON.ts +0 -19
- package/src/ts/util/setMarkup.ts +0 -130
- package/src/ts/util/vHidden.ts +0 -2
- package/tsconfig.json +0 -29
- package/vite.config.mts +0 -35
@@ -1,300 +1,307 @@
|
|
1
|
-
import
|
2
|
-
import { ColorFormats
|
3
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
1
|
+
import { BoundingClientRect } from '@thednp/shorty';
|
2
|
+
import { ColorFormats } from '@thednp/color';
|
3
|
+
import { CSS4Declaration } from '@thednp/shorty';
|
4
|
+
import { default as default_2 } from '@thednp/color';
|
5
|
+
import { HSLA } from '@thednp/color';
|
6
|
+
import { HSVA } from '@thednp/color';
|
7
|
+
import { HWBA } from '@thednp/color';
|
8
|
+
import { RGBA } from '@thednp/color';
|
9
|
+
|
10
|
+
declare interface ColorNames {
|
11
|
+
white: string;
|
12
|
+
black: string;
|
13
|
+
grey: string;
|
14
|
+
red: string;
|
15
|
+
orange: string;
|
16
|
+
brown: string;
|
17
|
+
gold: string;
|
18
|
+
olive: string;
|
19
|
+
yellow: string;
|
20
|
+
lime: string;
|
21
|
+
green: string;
|
22
|
+
teal: string;
|
23
|
+
cyan: string;
|
24
|
+
blue: string;
|
25
|
+
violet: string;
|
26
|
+
magenta: string;
|
27
|
+
pink: string;
|
28
|
+
[key: string]: string;
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Returns a color palette with a given set of parameters.
|
33
|
+
*
|
34
|
+
* @example
|
35
|
+
* new ColorPalette(0, 12, 10, 80);
|
36
|
+
* // => { hue: 0, hueSteps: 12, lightSteps: 10, saturation: 80, colors: Array<Color> }
|
37
|
+
*/
|
38
|
+
declare class ColorPalette {
|
39
|
+
static Color: typeof default_2;
|
40
|
+
hue: number;
|
41
|
+
hueSteps: number;
|
42
|
+
lightSteps: number;
|
43
|
+
saturation: number;
|
44
|
+
colors: default_2[];
|
45
|
+
/**
|
46
|
+
* The `hue` parameter is optional, which would be set to 0.
|
47
|
+
* * `args.hue` the starting Hue [0, 360]
|
48
|
+
* * `args.hueSteps` Hue Steps Count [5, 24]
|
49
|
+
* * `args.lightSteps` Lightness Steps Count [5, 12]
|
50
|
+
* * `args.saturation` Saturation [0, 100]
|
51
|
+
*/
|
52
|
+
constructor(...args: [number?, number?, number?, number?]);
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Color Picker Web Component
|
57
|
+
*
|
58
|
+
* @see http://thednp.github.io/color-picker
|
59
|
+
*/
|
60
|
+
declare class ColorPicker {
|
61
|
+
static Color: typeof default_2;
|
62
|
+
static ColorPalette: typeof ColorPalette;
|
63
|
+
static getInstance: (element: Element) => ColorPicker | null;
|
64
|
+
static init: (element: Element) => ColorPicker;
|
65
|
+
static selector: string;
|
66
|
+
static roundPart: (v: number) => number;
|
67
|
+
static setElementStyle: (element: Element, styles: Partial<CSS4Declaration>) => void;
|
68
|
+
static setAttribute: (element: Element, att: string, value: string) => void;
|
69
|
+
static getBoundingClientRect: (element: Element, includeScale?: boolean) => BoundingClientRect;
|
70
|
+
static version: string;
|
71
|
+
static colorNames: string[];
|
72
|
+
static colorPickerLabels: ColorPickerLabels;
|
73
|
+
id: number;
|
74
|
+
input: HTMLInputElement;
|
75
|
+
color: default_2;
|
76
|
+
format: string;
|
77
|
+
parent: HTMLElement;
|
78
|
+
dragElement: HTMLElement | undefined;
|
79
|
+
isOpen: boolean;
|
80
|
+
controlPositions: {
|
81
|
+
c1x: number;
|
82
|
+
c1y: number;
|
83
|
+
c2y: number;
|
84
|
+
c3y: number;
|
85
|
+
};
|
86
|
+
colorLabels: ColorNames;
|
87
|
+
colorKeywords: string[] | false;
|
88
|
+
colorPresets: ColorPalette | string[] | false;
|
89
|
+
componentLabels: ColorPickerLabels;
|
90
|
+
pickerToggle: HTMLElement;
|
91
|
+
menuToggle: HTMLElement;
|
92
|
+
colorPicker: HTMLElement;
|
93
|
+
colorMenu: HTMLElement;
|
94
|
+
controls: HTMLElement;
|
95
|
+
inputs: HTMLInputElement[];
|
96
|
+
controlKnobs: HTMLElement[];
|
97
|
+
visuals: HTMLElement[];
|
98
|
+
/**
|
99
|
+
* Returns a new `ColorPicker` instance. The target of this constructor
|
100
|
+
* must be an `HTMLInputElement`.
|
101
|
+
*
|
102
|
+
* @param target the target `<input>` element
|
103
|
+
* @param config instance options
|
104
|
+
*/
|
105
|
+
constructor(target: Element | string, config?: Partial<ColorPickerOptions>);
|
106
|
+
/** Returns the current colour value */
|
107
|
+
get value(): string;
|
108
|
+
/**
|
109
|
+
* Sets a new colour value.
|
110
|
+
*
|
111
|
+
* @param {string} v new colour value
|
112
|
+
*/
|
113
|
+
set value(v: string);
|
114
|
+
/** Check if the colour presets include any non-colour. */
|
115
|
+
get hasNonColor(): boolean;
|
116
|
+
/** Returns hexadecimal value of the current colour. */
|
117
|
+
get hex(): string;
|
118
|
+
/** Returns the current colour value in {h,s,v,a} object format. */
|
119
|
+
get hsv(): HSVA;
|
120
|
+
/** Returns the current colour value in {h,s,l,a} object format. */
|
121
|
+
get hsl(): HSLA;
|
122
|
+
/** Returns the current colour value in {h,w,b,a} object format. */
|
123
|
+
get hwb(): HWBA;
|
124
|
+
/** Returns the current colour value in {r,g,b,a} object format. */
|
125
|
+
get rgb(): RGBA;
|
126
|
+
/** Returns the current colour brightness. */
|
127
|
+
get brightness(): number;
|
128
|
+
/** Returns the current colour luminance. */
|
129
|
+
get luminance(): number;
|
130
|
+
/** Checks if the current colour requires a light text colour. */
|
131
|
+
get isDark(): boolean;
|
132
|
+
/** Checks if the current input value is a valid colour. */
|
133
|
+
get isValid(): boolean;
|
134
|
+
/** Returns the colour appearance, usually the closest colour name for the current value. */
|
135
|
+
get appearance(): string;
|
136
|
+
/** Updates `ColorPicker` visuals. */
|
137
|
+
updateVisuals(): void;
|
138
|
+
/**
|
139
|
+
* The `ColorPicker` *focusout* event listener when open.
|
140
|
+
*
|
141
|
+
* @param e
|
142
|
+
* @this {ColorPicker}
|
143
|
+
*/
|
144
|
+
handleFocusOut: ({ relatedTarget }: FocusEvent & {
|
145
|
+
relatedTarget: HTMLElement;
|
146
|
+
}) => void;
|
147
|
+
/**
|
148
|
+
* The `ColorPicker` *keyup* event listener when open.
|
149
|
+
*
|
150
|
+
* @param e
|
151
|
+
* @this {ColorPicker}
|
152
|
+
*/
|
153
|
+
handleDismiss: ({ code }: KeyboardEvent) => void;
|
154
|
+
/**
|
155
|
+
* The `ColorPicker` *scroll* event listener when open.
|
156
|
+
*
|
157
|
+
* @param e
|
158
|
+
*/
|
159
|
+
handleScroll: (e: Event) => void;
|
160
|
+
/**
|
161
|
+
* The `ColorPicker` keyboard event listener for menu navigation.
|
162
|
+
*
|
163
|
+
* @param e
|
164
|
+
*/
|
165
|
+
menuKeyHandler: (e: KeyboardEvent & {
|
166
|
+
target: HTMLElement;
|
167
|
+
}) => void;
|
168
|
+
/**
|
169
|
+
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
170
|
+
*
|
171
|
+
* @param e
|
172
|
+
* @this {ColorPicker}
|
173
|
+
*/
|
174
|
+
menuClickHandler: (e: Event) => void;
|
175
|
+
/**
|
176
|
+
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
177
|
+
*
|
178
|
+
* @param e
|
179
|
+
*/
|
180
|
+
pointerDown: (e: PointerEvent & {
|
181
|
+
target: HTMLElement;
|
182
|
+
}) => void;
|
183
|
+
/**
|
184
|
+
* The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
|
185
|
+
*
|
186
|
+
* @param e
|
187
|
+
* @this
|
188
|
+
*/
|
189
|
+
pointerUp: ({ target }: PointerEvent & {
|
190
|
+
target: HTMLElement;
|
191
|
+
}) => void;
|
192
|
+
/**
|
193
|
+
* The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
|
194
|
+
*
|
195
|
+
* @param {PointerEvent} e
|
196
|
+
*/
|
197
|
+
pointerMove: (e: PointerEvent) => void;
|
198
|
+
/**
|
199
|
+
* The `ColorPicker` *keydown* event listener for control knobs.
|
200
|
+
*
|
201
|
+
* @param e
|
202
|
+
*/
|
203
|
+
handleKnobs: (e: Event & {
|
204
|
+
code: string;
|
205
|
+
}) => void;
|
206
|
+
/** The event listener of the colour form inputs. */
|
207
|
+
changeHandler: () => void;
|
208
|
+
/**
|
209
|
+
* Updates `ColorPicker` first control:
|
210
|
+
* * `lightness` and `saturation` for HEX/RGB;
|
211
|
+
* * `lightness` and `hue` for HSL.
|
212
|
+
*
|
213
|
+
* @param X the X component of the offset
|
214
|
+
* @param Y the Y component of the offset
|
215
|
+
*/
|
216
|
+
changeControl1(X: number, Y: number): void;
|
217
|
+
/**
|
218
|
+
* Updates `ColorPicker` second control:
|
219
|
+
* * `hue` for HEX/RGB/HWB;
|
220
|
+
* * `saturation` for HSL.
|
221
|
+
*
|
222
|
+
* @param Y the Y offset
|
223
|
+
*/
|
224
|
+
changeControl2(Y: number): void;
|
225
|
+
/**
|
226
|
+
* Updates `ColorPicker` last control,
|
227
|
+
* the `alpha` channel.
|
228
|
+
*
|
229
|
+
* @param Y
|
230
|
+
*/
|
231
|
+
changeAlpha(Y: number): void;
|
232
|
+
/**
|
233
|
+
* Updates `ColorPicker` control positions on:
|
234
|
+
* * initialization
|
235
|
+
* * window resize
|
236
|
+
*/
|
237
|
+
update: () => void;
|
238
|
+
/** Updates the open dropdown position on *scroll* event. */
|
239
|
+
updateDropdownPosition(): void;
|
240
|
+
/** Updates control knobs' positions. */
|
241
|
+
setControlPositions(): void;
|
242
|
+
/** Update the visual appearance label and control knob labels. */
|
243
|
+
updateAppearance(): void;
|
244
|
+
/** Updates the control knobs actual positions. */
|
245
|
+
updateControls(): void;
|
246
|
+
/**
|
247
|
+
* Updates all color form inputs.
|
248
|
+
*
|
249
|
+
* @param isPrevented when `true`, the component original event is prevented
|
250
|
+
*/
|
251
|
+
updateInputs(isPrevented?: boolean): void;
|
252
|
+
/**
|
253
|
+
* Toggle the `ColorPicker` dropdown visibility.
|
254
|
+
*
|
255
|
+
* @param e
|
256
|
+
*/
|
257
|
+
togglePicker: (e?: Event) => void;
|
258
|
+
/** Shows the `ColorPicker` dropdown. */
|
259
|
+
showPicker: () => void;
|
260
|
+
/**
|
261
|
+
* Toggles the visibility of the `ColorPicker` presets menu.
|
262
|
+
*
|
263
|
+
* @param e
|
264
|
+
* @this {ColorPicker}
|
265
|
+
*/
|
266
|
+
toggleMenu: (e?: Event) => void;
|
267
|
+
/**
|
268
|
+
* Hides the currently open `ColorPicker` dropdown.
|
269
|
+
*
|
270
|
+
* @param {boolean=} focusPrevented
|
271
|
+
*/
|
272
|
+
hide(focusPrevented?: boolean): void;
|
273
|
+
/** Removes `ColorPicker` from target `<input>`. */
|
274
|
+
dispose(): void;
|
275
|
+
}
|
276
|
+
export default ColorPicker;
|
277
|
+
|
278
|
+
declare interface ColorPickerLabels {
|
279
|
+
pickerLabel: string;
|
280
|
+
appearanceLabel: string;
|
281
|
+
valueLabel: string;
|
282
|
+
toggleLabel: string;
|
283
|
+
presetsLabel: string;
|
284
|
+
defaultsLabel: string;
|
285
|
+
formatLabel: string;
|
286
|
+
alphaLabel: string;
|
287
|
+
hexLabel: string;
|
288
|
+
hueLabel: string;
|
289
|
+
whitenessLabel: string;
|
290
|
+
blacknessLabel: string;
|
291
|
+
saturationLabel: string;
|
292
|
+
lightnessLabel: string;
|
293
|
+
redLabel: string;
|
294
|
+
greenLabel: string;
|
295
|
+
blueLabel: string;
|
296
|
+
[key: string]: string;
|
297
|
+
}
|
298
|
+
|
299
|
+
declare type ColorPickerOptions = {
|
300
|
+
colorLabels: string | string[];
|
301
|
+
componentLabels: ColorPickerLabels;
|
302
|
+
format: ColorFormats;
|
303
|
+
colorPresets: string | string[] | ColorPalette | false;
|
304
|
+
colorKeywords: string | string[] | false;
|
305
|
+
};
|
306
|
+
|
307
|
+
export { }
|