@thednp/color-picker 1.0.1 → 2.0.0-alpha10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/.eslintrc.cjs +199 -0
  2. package/.lgtm.yml +9 -0
  3. package/.prettierrc.json +15 -0
  4. package/.stylelintrc.json +236 -0
  5. package/README.md +55 -72
  6. package/compile.js +51 -0
  7. package/cypress/e2e/color-palette.cy.ts +128 -0
  8. package/cypress/e2e/color-picker.cy.ts +909 -0
  9. package/cypress/fixtures/colorNamesFrench.js +3 -0
  10. package/cypress/fixtures/componentLabelsFrench.js +21 -0
  11. package/cypress/fixtures/format.js +3 -0
  12. package/cypress/fixtures/getMarkup.js +35 -0
  13. package/cypress/fixtures/getRandomInt.js +6 -0
  14. package/cypress/fixtures/sampleWebcolors.js +18 -0
  15. package/cypress/fixtures/testSample.js +8 -0
  16. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  17. package/cypress/plugins/tsCompile.ts +34 -0
  18. package/cypress/support/commands.ts +0 -0
  19. package/cypress/support/e2e.ts +21 -0
  20. package/cypress/test.html +23 -0
  21. package/cypress.config.ts +29 -0
  22. package/dist/css/color-picker.css +25 -54
  23. package/dist/css/color-picker.min.css +2 -2
  24. package/dist/css/color-picker.rtl.css +25 -54
  25. package/dist/css/color-picker.rtl.min.css +2 -2
  26. package/dist/js/color-picker.cjs +8 -0
  27. package/dist/js/color-picker.cjs.map +1 -0
  28. package/dist/js/color-picker.d.ts +296 -0
  29. package/dist/js/color-picker.js +5 -3570
  30. package/dist/js/color-picker.js.map +1 -0
  31. package/dist/js/color-picker.mjs +2618 -0
  32. package/dist/js/color-picker.mjs.map +1 -0
  33. package/dts.config.ts +15 -0
  34. package/package.json +116 -108
  35. package/src/scss/_variables.scss +0 -1
  36. package/src/scss/color-picker.rtl.scss +4 -0
  37. package/src/scss/color-picker.scss +93 -51
  38. package/src/ts/colorPalette.ts +89 -0
  39. package/src/{js/color-picker.js → ts/index.ts} +498 -509
  40. package/src/ts/interface/ColorNames.ts +20 -0
  41. package/src/ts/interface/colorPickerLabels.ts +20 -0
  42. package/src/ts/interface/colorPickerOptions.ts +11 -0
  43. package/src/ts/interface/paletteOptions.ts +6 -0
  44. package/src/ts/util/colorNames.ts +21 -0
  45. package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
  46. package/src/ts/util/getColorControls.ts +90 -0
  47. package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
  48. package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
  49. package/src/ts/util/isValidJSON.ts +19 -0
  50. package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +61 -50
  51. package/tsconfig.json +29 -0
  52. package/vite.config.ts +34 -0
  53. package/dist/js/color-esm.js +0 -1164
  54. package/dist/js/color-esm.min.js +0 -2
  55. package/dist/js/color-palette-esm.js +0 -1235
  56. package/dist/js/color-palette-esm.min.js +0 -2
  57. package/dist/js/color-palette.js +0 -1243
  58. package/dist/js/color-palette.min.js +0 -2
  59. package/dist/js/color-picker-element-esm.js +0 -3718
  60. package/dist/js/color-picker-element-esm.min.js +0 -2
  61. package/dist/js/color-picker-element.js +0 -3726
  62. package/dist/js/color-picker-element.min.js +0 -2
  63. package/dist/js/color-picker-esm.js +0 -3565
  64. package/dist/js/color-picker-esm.min.js +0 -2
  65. package/dist/js/color-picker.min.js +0 -2
  66. package/dist/js/color.js +0 -1172
  67. package/dist/js/color.min.js +0 -2
  68. package/src/js/color-palette.js +0 -75
  69. package/src/js/color-picker-element.js +0 -107
  70. package/src/js/color.js +0 -1104
  71. package/src/js/index.js +0 -8
  72. package/src/js/util/colorNames.js +0 -6
  73. package/src/js/util/getColorControls.js +0 -103
  74. package/src/js/util/isValidJSON.js +0 -13
  75. package/src/js/util/nonColors.js +0 -5
  76. package/src/js/util/roundPart.js +0 -9
  77. package/src/js/util/setCSSProperties.js +0 -12
  78. package/src/js/util/tabindex.js +0 -3
  79. package/src/js/util/toggleCEAttr.js +0 -70
  80. package/src/js/util/version.js +0 -5
  81. package/src/js/version.js +0 -5
  82. package/types/cp.d.ts +0 -558
  83. package/types/index.d.ts +0 -44
  84. package/types/source/source.ts +0 -4
  85. package/types/source/types.d.ts +0 -92
  86. /package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
@@ -0,0 +1,296 @@
1
+ import Color from '@thednp/color';
2
+ import { ColorFormats, HSLA, HSVA, HWBA, RGBA } from '@thednp/color';
3
+
4
+ declare class ColorPalette {
5
+ static Color: typeof Color;
6
+ hue: number;
7
+ hueSteps: number;
8
+ lightSteps: number;
9
+ saturation: number;
10
+ colors: Color[];
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
+ export default class ColorPicker {
78
+ static Color: typeof Color;
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 | undefined) => 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;
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 as namespace ColorPicker;
295
+
296
+ export {};