@thednp/color-picker 2.0.2 → 2.0.4

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