@thednp/color-picker 1.0.1 → 2.0.0-alpha2

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