@zag-js/color-picker 1.34.1 → 1.35.0

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 (49) hide show
  1. package/dist/color-picker.anatomy.d.mts +6 -0
  2. package/dist/color-picker.anatomy.d.ts +6 -0
  3. package/dist/color-picker.anatomy.js +59 -0
  4. package/dist/color-picker.anatomy.mjs +33 -0
  5. package/dist/color-picker.connect.d.mts +10 -0
  6. package/dist/color-picker.connect.d.ts +10 -0
  7. package/dist/color-picker.connect.js +681 -0
  8. package/dist/color-picker.connect.mjs +646 -0
  9. package/dist/color-picker.dom.d.mts +39 -0
  10. package/dist/color-picker.dom.d.ts +39 -0
  11. package/dist/color-picker.dom.js +136 -0
  12. package/dist/color-picker.dom.mjs +85 -0
  13. package/dist/color-picker.machine.d.mts +10 -0
  14. package/dist/color-picker.machine.d.ts +10 -0
  15. package/dist/color-picker.machine.js +636 -0
  16. package/dist/color-picker.machine.mjs +609 -0
  17. package/dist/color-picker.parse.d.mts +5 -0
  18. package/dist/color-picker.parse.d.ts +5 -0
  19. package/dist/color-picker.parse.js +33 -0
  20. package/dist/color-picker.parse.mjs +8 -0
  21. package/dist/color-picker.props.d.mts +21 -0
  22. package/dist/color-picker.props.d.ts +21 -0
  23. package/dist/color-picker.props.js +94 -0
  24. package/dist/color-picker.props.mjs +58 -0
  25. package/dist/color-picker.types.d.mts +303 -0
  26. package/dist/color-picker.types.d.ts +303 -0
  27. package/dist/color-picker.types.js +18 -0
  28. package/dist/color-picker.types.mjs +0 -0
  29. package/dist/index.d.mts +9 -324
  30. package/dist/index.d.ts +9 -324
  31. package/dist/index.js +37 -1517
  32. package/dist/index.mjs +11 -1504
  33. package/dist/utils/get-channel-display-color.d.mts +5 -0
  34. package/dist/utils/get-channel-display-color.d.ts +5 -0
  35. package/dist/utils/get-channel-display-color.js +48 -0
  36. package/dist/utils/get-channel-display-color.mjs +23 -0
  37. package/dist/utils/get-channel-input-value.d.mts +11 -0
  38. package/dist/utils/get-channel-input-value.d.ts +11 -0
  39. package/dist/utils/get-channel-input-value.js +88 -0
  40. package/dist/utils/get-channel-input-value.mjs +62 -0
  41. package/dist/utils/get-slider-background.d.mts +14 -0
  42. package/dist/utils/get-slider-background.d.ts +14 -0
  43. package/dist/utils/get-slider-background.js +65 -0
  44. package/dist/utils/get-slider-background.mjs +40 -0
  45. package/dist/utils/is-valid-hex.d.mts +4 -0
  46. package/dist/utils/is-valid-hex.d.ts +4 -0
  47. package/dist/utils/is-valid-hex.js +40 -0
  48. package/dist/utils/is-valid-hex.mjs +14 -0
  49. package/package.json +20 -10
package/dist/index.d.ts CHANGED
@@ -1,327 +1,12 @@
1
- import { InteractOutsideHandlers } from '@zag-js/dismissable';
2
1
  export { FocusOutsideEvent, InteractOutsideEvent, PointerDownOutsideEvent } from '@zag-js/dismissable';
3
- import * as _zag_js_anatomy from '@zag-js/anatomy';
4
- import { PropTypes, Orientation, RequiredBy, CommonProperties, DirectionProperty, NormalizeProps } from '@zag-js/types';
5
- import { Color, ColorChannel, ColorFormat, ColorAxes } from '@zag-js/color-utils';
2
+ export { anatomy } from './color-picker.anatomy.js';
3
+ export { connect } from './color-picker.connect.js';
4
+ export { machine } from './color-picker.machine.js';
5
+ export { parse } from './color-picker.parse.js';
6
+ export { areaProps, channelProps, props, splitAreaProps, splitChannelProps, splitProps, splitSwatchProps, splitSwatchTriggerProps, splitTransparencyGridProps, swatchProps, swatchTriggerProps, transparencyGridProps } from './color-picker.props.js';
7
+ export { ColorPickerApi as Api, AreaProps, ChannelInputProps, ChannelProps, ChannelSliderProps, ElementIds, ExtendedColorChannel, FormatChangeDetails, ColorPickerMachine as Machine, OpenChangeDetails, ColorPickerProps as Props, ColorPickerService as Service, SwatchProps, SwatchTriggerProps, SwatchTriggerState, TransparencyGridProps, ValueChangeDetails } from './color-picker.types.js';
6
8
  export { Color, ColorAxes, ColorChannel, ColorFormat, ColorType } from '@zag-js/color-utils';
7
- import * as _zag_js_core from '@zag-js/core';
8
- import { Machine, EventObject, Service } from '@zag-js/core';
9
- import { PositioningOptions } from '@zag-js/popper';
10
9
  export { PositioningOptions } from '@zag-js/popper';
11
-
12
- declare const anatomy: _zag_js_anatomy.Anatomy<"content" | "label" | "area" | "root" | "control" | "trigger" | "positioner" | "areaThumb" | "valueText" | "areaBackground" | "channelSlider" | "channelSliderLabel" | "channelSliderTrack" | "channelSliderThumb" | "channelSliderValueText" | "channelInput" | "transparencyGrid" | "swatchGroup" | "swatchTrigger" | "swatchIndicator" | "swatch" | "eyeDropperTrigger" | "formatTrigger" | "formatSelect">;
13
-
14
- type ExtendedColorChannel = ColorChannel | "hex" | "css";
15
- interface EyeDropper {
16
- new (): EyeDropper;
17
- open: (options?: {
18
- signal?: AbortSignal | undefined;
19
- }) => Promise<{
20
- sRGBHex: string;
21
- }>;
22
- [Symbol.toStringTag]: "EyeDropper";
23
- }
24
- declare global {
25
- interface Window {
26
- EyeDropper: EyeDropper;
27
- }
28
- }
29
- interface ValueChangeDetails {
30
- value: Color;
31
- valueAsString: string;
32
- }
33
- interface OpenChangeDetails {
34
- open: boolean;
35
- value: Color;
36
- }
37
- interface FormatChangeDetails {
38
- format: ColorFormat;
39
- }
40
- type ElementIds = Partial<{
41
- root: string;
42
- control: string;
43
- trigger: string;
44
- label: string;
45
- input: string;
46
- hiddenInput: string;
47
- content: string;
48
- area: string;
49
- areaGradient: string;
50
- positioner: string;
51
- formatSelect: string;
52
- areaThumb: string;
53
- channelInput: (id: string) => string;
54
- channelSliderTrack: (id: ColorChannel) => string;
55
- channelSliderThumb: (id: ColorChannel) => string;
56
- }>;
57
- interface ColorPickerProps extends CommonProperties, DirectionProperty, InteractOutsideHandlers {
58
- /**
59
- * The ids of the elements in the color picker. Useful for composition.
60
- */
61
- ids?: ElementIds | undefined;
62
- /**
63
- * The controlled color value of the color picker
64
- */
65
- value?: Color | undefined;
66
- /**
67
- * The initial color value when rendered.
68
- * Use when you don't need to control the color value of the color picker.
69
- * @default #000000
70
- */
71
- defaultValue?: Color | undefined;
72
- /**
73
- * Whether the color picker is disabled
74
- */
75
- disabled?: boolean | undefined;
76
- /**
77
- * Whether the color picker is read-only
78
- */
79
- readOnly?: boolean | undefined;
80
- /**
81
- * Whether the color picker is required
82
- */
83
- required?: boolean | undefined;
84
- /**
85
- * Whether the color picker is invalid
86
- */
87
- invalid?: boolean | undefined;
88
- /**
89
- * Handler that is called when the value changes, as the user drags.
90
- */
91
- onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
92
- /**
93
- * Handler that is called when the user stops dragging.
94
- */
95
- onValueChangeEnd?: ((details: ValueChangeDetails) => void) | undefined;
96
- /**
97
- * Handler that is called when the user opens or closes the color picker.
98
- */
99
- onOpenChange?: ((details: OpenChangeDetails) => void) | undefined;
100
- /**
101
- * The name for the form input
102
- */
103
- name?: string | undefined;
104
- /**
105
- * The positioning options for the color picker
106
- */
107
- positioning?: PositioningOptions | undefined;
108
- /**
109
- * The initial focus element when the color picker is opened.
110
- */
111
- initialFocusEl?: (() => HTMLElement | null) | undefined;
112
- /**
113
- * The controlled open state of the color picker
114
- */
115
- open?: boolean | undefined;
116
- /**
117
- * The initial open state of the color picker when rendered.
118
- * Use when you don't need to control the open state of the color picker.
119
- */
120
- defaultOpen?: boolean | undefined;
121
- /**
122
- * The controlled color format to use
123
- */
124
- format?: ColorFormat | undefined;
125
- /**
126
- * The initial color format when rendered.
127
- * Use when you don't need to control the color format of the color picker.
128
- * @default "rgba"
129
- */
130
- defaultFormat?: ColorFormat | undefined;
131
- /**
132
- * Function called when the color format changes
133
- */
134
- onFormatChange?: ((details: FormatChangeDetails) => void) | undefined;
135
- /**
136
- * Whether to close the color picker when a swatch is selected
137
- * @default false
138
- */
139
- closeOnSelect?: boolean | undefined;
140
- /**
141
- * Whether to auto focus the color picker when it is opened
142
- * @default true
143
- */
144
- openAutoFocus?: boolean | undefined;
145
- /**
146
- * Whether to render the color picker inline
147
- */
148
- inline?: boolean | undefined;
149
- }
150
- type PropsWithDefault = "defaultFormat" | "defaultValue" | "openAutoFocus" | "dir" | "positioning";
151
- type ColorPickerSchema = {
152
- tag: "open" | "closed" | "dragging" | "focused";
153
- state: "idle" | "focused" | "open" | "open:dragging";
154
- props: RequiredBy<ColorPickerProps, PropsWithDefault>;
155
- computed: {
156
- disabled: boolean;
157
- rtl: boolean;
158
- interactive: boolean;
159
- valueAsString: string;
160
- areaValue: Color;
161
- };
162
- context: {
163
- format: ColorFormat;
164
- value: Color;
165
- activeId: string | null;
166
- activeChannel: Partial<ColorAxes> | null;
167
- activeOrientation: Orientation | null;
168
- fieldsetDisabled: boolean;
169
- currentPlacement: PositioningOptions["placement"] | undefined;
170
- restoreFocus: boolean;
171
- };
172
- event: EventObject;
173
- action: string;
174
- effect: string;
175
- guard: string;
176
- };
177
- type ColorPickerService = Service<ColorPickerSchema>;
178
- type ColorPickerMachine = Machine<ColorPickerSchema>;
179
- interface ChannelProps {
180
- channel: ColorChannel;
181
- orientation?: Orientation | undefined;
182
- }
183
- interface ChannelSliderProps extends ChannelProps {
184
- format?: ColorFormat | undefined;
185
- }
186
- interface ChannelInputProps {
187
- channel: ExtendedColorChannel;
188
- orientation?: Orientation | undefined;
189
- }
190
- interface AreaProps {
191
- xChannel?: ColorChannel | undefined;
192
- yChannel?: ColorChannel | undefined;
193
- }
194
- interface SwatchTriggerProps {
195
- /**
196
- * The color value
197
- */
198
- value: string | Color;
199
- /**
200
- * Whether the swatch trigger is disabled
201
- */
202
- disabled?: boolean | undefined;
203
- }
204
- interface SwatchTriggerState {
205
- value: Color;
206
- valueAsString: string;
207
- checked: boolean;
208
- disabled: boolean;
209
- }
210
- interface SwatchProps {
211
- /**
212
- * The color value
213
- */
214
- value: string | Color;
215
- /**
216
- * Whether to include the alpha channel in the color
217
- */
218
- respectAlpha?: boolean | undefined;
219
- }
220
- interface TransparencyGridProps {
221
- size?: string | undefined;
222
- }
223
- interface ColorPickerApi<T extends PropTypes = PropTypes> {
224
- /**
225
- * Whether the color picker is being dragged
226
- */
227
- dragging: boolean;
228
- /**
229
- * Whether the color picker is open
230
- */
231
- open: boolean;
232
- /**
233
- * Whether the color picker is rendered inline
234
- */
235
- inline: boolean;
236
- /**
237
- * The current color value (as a string)
238
- */
239
- value: Color;
240
- /**
241
- * The current color value (as a Color object)
242
- */
243
- valueAsString: string;
244
- /**
245
- * Function to set the color value
246
- */
247
- setValue: (value: string | Color) => void;
248
- /**
249
- * Function to set the color value
250
- */
251
- getChannelValue: (channel: ColorChannel) => string;
252
- /**
253
- * Function to get the formatted and localized value of a specific channel
254
- */
255
- getChannelValueText: (channel: ColorChannel, locale: string) => string;
256
- /**
257
- * Function to set the color value of a specific channel
258
- */
259
- setChannelValue: (channel: ColorChannel, value: number) => void;
260
- /**
261
- * The current color format
262
- */
263
- format: ColorFormat;
264
- /**
265
- * Function to set the color format
266
- */
267
- setFormat: (format: ColorFormat) => void;
268
- /**
269
- * The alpha value of the color
270
- */
271
- alpha: number;
272
- /**
273
- * Function to set the color alpha
274
- */
275
- setAlpha: (value: number) => void;
276
- /**
277
- * Function to open or close the color picker
278
- */
279
- setOpen: (open: boolean) => void;
280
- getRootProps: () => T["element"];
281
- getLabelProps: () => T["element"];
282
- getControlProps: () => T["element"];
283
- getTriggerProps: () => T["button"];
284
- getPositionerProps: () => T["element"];
285
- getContentProps: () => T["element"];
286
- getHiddenInputProps: () => T["input"];
287
- getValueTextProps: () => T["element"];
288
- getAreaProps: (props?: AreaProps) => T["element"];
289
- getAreaBackgroundProps: (props?: AreaProps) => T["element"];
290
- getAreaThumbProps: (props?: AreaProps) => T["element"];
291
- getChannelInputProps: (props: ChannelInputProps) => T["input"];
292
- getChannelSliderProps: (props: ChannelSliderProps) => T["element"];
293
- getChannelSliderTrackProps: (props: ChannelSliderProps) => T["element"];
294
- getChannelSliderThumbProps: (props: ChannelSliderProps) => T["element"];
295
- getChannelSliderLabelProps: (props: ChannelProps) => T["element"];
296
- getChannelSliderValueTextProps: (props: ChannelProps) => T["element"];
297
- getTransparencyGridProps: (props?: TransparencyGridProps) => T["element"];
298
- getEyeDropperTriggerProps: () => T["button"];
299
- getSwatchGroupProps: () => T["element"];
300
- getSwatchTriggerProps: (props: SwatchTriggerProps) => T["button"];
301
- getSwatchTriggerState: (props: SwatchTriggerProps) => SwatchTriggerState;
302
- getSwatchProps: (props: SwatchProps) => T["element"];
303
- getSwatchIndicatorProps: (props: SwatchProps) => T["element"];
304
- getFormatSelectProps: () => T["select"];
305
- getFormatTriggerProps: () => T["button"];
306
- }
307
-
308
- declare function connect<T extends PropTypes>(service: ColorPickerService, normalize: NormalizeProps<T>): ColorPickerApi<T>;
309
-
310
- declare const machine: _zag_js_core.Machine<ColorPickerSchema>;
311
-
312
- declare const parse: (colorString: string) => Color;
313
-
314
- declare const props: (keyof ColorPickerProps)[];
315
- declare const splitProps: <Props extends Partial<ColorPickerProps>>(props: Props) => [Partial<ColorPickerProps>, Omit<Props, keyof ColorPickerProps>];
316
- declare const areaProps: (keyof AreaProps)[];
317
- declare const splitAreaProps: <Props extends AreaProps>(props: Props) => [AreaProps, Omit<Props, keyof AreaProps>];
318
- declare const channelProps: (keyof ChannelProps)[];
319
- declare const splitChannelProps: <Props extends ChannelProps>(props: Props) => [ChannelProps, Omit<Props, keyof ChannelProps>];
320
- declare const swatchTriggerProps: (keyof SwatchTriggerProps)[];
321
- declare const splitSwatchTriggerProps: <Props extends SwatchTriggerProps>(props: Props) => [SwatchTriggerProps, Omit<Props, keyof SwatchTriggerProps>];
322
- declare const swatchProps: (keyof SwatchProps)[];
323
- declare const splitSwatchProps: <Props extends SwatchProps>(props: Props) => [SwatchProps, Omit<Props, keyof SwatchProps>];
324
- declare const transparencyGridProps: "size"[];
325
- declare const splitTransparencyGridProps: <Props extends TransparencyGridProps>(props: Props) => [TransparencyGridProps, Omit<Props, "size">];
326
-
327
- export { type ColorPickerApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type ElementIds, type ExtendedColorChannel, type FormatChangeDetails, type ColorPickerMachine as Machine, type OpenChangeDetails, type ColorPickerProps as Props, type ColorPickerService as Service, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, areaProps, channelProps, connect, machine, parse, props, splitAreaProps, splitChannelProps, splitProps, splitSwatchProps, splitSwatchTriggerProps, splitTransparencyGridProps, swatchProps, swatchTriggerProps, transparencyGridProps };
10
+ import '@zag-js/anatomy';
11
+ import '@zag-js/types';
12
+ import '@zag-js/core';