@zag-js/color-picker 1.34.1 → 1.35.1

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