@zag-js/color-picker 0.0.0-dev-20230414151834

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/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/chunk-2ERX54SV.mjs +25 -0
  4. package/dist/chunk-3XH465XT.mjs +42 -0
  5. package/dist/chunk-75JXJMB5.mjs +22 -0
  6. package/dist/chunk-ACSV4TXB.mjs +35 -0
  7. package/dist/chunk-J3XCPS5T.mjs +365 -0
  8. package/dist/chunk-JNBNPPMF.mjs +24 -0
  9. package/dist/chunk-KLLIOTK6.mjs +55 -0
  10. package/dist/chunk-KO4TBUXB.mjs +74 -0
  11. package/dist/chunk-OY3B7NXA.mjs +132 -0
  12. package/dist/chunk-ZBNUATFY.mjs +344 -0
  13. package/dist/color-picker.anatomy.d.ts +6 -0
  14. package/dist/color-picker.anatomy.js +47 -0
  15. package/dist/color-picker.anatomy.mjs +8 -0
  16. package/dist/color-picker.connect.d.ts +27 -0
  17. package/dist/color-picker.connect.js +731 -0
  18. package/dist/color-picker.connect.mjs +14 -0
  19. package/dist/color-picker.dom.d.ts +62 -0
  20. package/dist/color-picker.dom.js +59 -0
  21. package/dist/color-picker.dom.mjs +6 -0
  22. package/dist/color-picker.machine.d.ts +8 -0
  23. package/dist/color-picker.machine.js +456 -0
  24. package/dist/color-picker.machine.mjs +9 -0
  25. package/dist/color-picker.types.d.ts +88 -0
  26. package/dist/color-picker.types.js +18 -0
  27. package/dist/color-picker.types.mjs +0 -0
  28. package/dist/index.d.ts +6 -0
  29. package/dist/index.js +1066 -0
  30. package/dist/index.mjs +18 -0
  31. package/dist/utils/generate-format-background.d.ts +68 -0
  32. package/dist/utils/generate-format-background.js +164 -0
  33. package/dist/utils/generate-format-background.mjs +22 -0
  34. package/dist/utils/get-channel-details.d.ts +23 -0
  35. package/dist/utils/get-channel-details.js +79 -0
  36. package/dist/utils/get-channel-details.mjs +6 -0
  37. package/dist/utils/get-channel-display-color.d.ts +5 -0
  38. package/dist/utils/get-channel-display-color.js +48 -0
  39. package/dist/utils/get-channel-display-color.mjs +6 -0
  40. package/dist/utils/get-channel-input-value.d.ts +10 -0
  41. package/dist/utils/get-channel-input-value.js +50 -0
  42. package/dist/utils/get-channel-input-value.mjs +8 -0
  43. package/dist/utils/get-color-area-gradient.d.ts +11 -0
  44. package/dist/utils/get-color-area-gradient.js +209 -0
  45. package/dist/utils/get-color-area-gradient.mjs +7 -0
  46. package/dist/utils/get-slider-background.d.ts +8 -0
  47. package/dist/utils/get-slider-background.js +66 -0
  48. package/dist/utils/get-slider-background.mjs +6 -0
  49. package/package.json +65 -0
@@ -0,0 +1,132 @@
1
+ // src/utils/generate-format-background.ts
2
+ var generateRGB_R = (orientation, dir, zValue) => {
3
+ const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
4
+ const result = {
5
+ areaStyles: {
6
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`
7
+ },
8
+ areaGradientStyles: {
9
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
10
+ WebkitMaskImage: maskImage,
11
+ maskImage
12
+ }
13
+ };
14
+ return result;
15
+ };
16
+ var generateRGB_G = (orientation, dir, zValue) => {
17
+ const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
18
+ const result = {
19
+ areaStyles: {
20
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`
21
+ },
22
+ areaGradientStyles: {
23
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
24
+ WebkitMaskImage: maskImage,
25
+ maskImage
26
+ }
27
+ };
28
+ return result;
29
+ };
30
+ var generateRGB_B = (orientation, dir, zValue) => {
31
+ const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
32
+ const result = {
33
+ areaStyles: {
34
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`
35
+ },
36
+ areaGradientStyles: {
37
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
38
+ WebkitMaskImage: maskImage,
39
+ maskImage
40
+ }
41
+ };
42
+ return result;
43
+ };
44
+ var generateHSL_H = (orientation, dir, zValue) => {
45
+ const result = {
46
+ areaStyles: {},
47
+ areaGradientStyles: {
48
+ background: [
49
+ `linear-gradient(to ${orientation[Number(dir)]}, hsla(0,0%,0%,1) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,1) 100%)`,
50
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
51
+ `hsl(${zValue}, 100%, 50%)`
52
+ ].join(",")
53
+ }
54
+ };
55
+ return result;
56
+ };
57
+ var generateHSL_S = (orientation, dir, alphaValue) => {
58
+ const result = {
59
+ areaStyles: {},
60
+ areaGradientStyles: {
61
+ background: [
62
+ `linear-gradient(to ${orientation[Number(!dir)]}, hsla(0,0%,0%,${alphaValue}) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,${alphaValue}) 100%)`,
63
+ `linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
64
+ "hsl(0, 0%, 50%)"
65
+ ].join(",")
66
+ }
67
+ };
68
+ return result;
69
+ };
70
+ var generateHSL_L = (orientation, dir, zValue) => {
71
+ const result = {
72
+ areaStyles: {},
73
+ areaGradientStyles: {
74
+ backgroundImage: [
75
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
76
+ `linear-gradient(to ${orientation[Number(dir)]},hsl(0,100%,${zValue}%),hsl(60,100%,${zValue}%),hsl(120,100%,${zValue}%),hsl(180,100%,${zValue}%),hsl(240,100%,${zValue}%),hsl(300,100%,${zValue}%),hsl(360,100%,${zValue}%))`
77
+ ].join(",")
78
+ }
79
+ };
80
+ return result;
81
+ };
82
+ var generateHSB_H = (orientation, dir, zValue) => {
83
+ const result = {
84
+ areaStyles: {},
85
+ areaGradientStyles: {
86
+ background: [
87
+ `linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
88
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
89
+ `hsl(${zValue}, 100%, 50%)`
90
+ ].join(",")
91
+ }
92
+ };
93
+ return result;
94
+ };
95
+ var generateHSB_S = (orientation, dir, alphaValue) => {
96
+ const result = {
97
+ areaStyles: {},
98
+ areaGradientStyles: {
99
+ background: [
100
+ `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
101
+ `linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
102
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
103
+ ].join(",")
104
+ }
105
+ };
106
+ return result;
107
+ };
108
+ var generateHSB_B = (orientation, dir, alphaValue) => {
109
+ const result = {
110
+ areaStyles: {},
111
+ areaGradientStyles: {
112
+ background: [
113
+ `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
114
+ `linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
115
+ "#000"
116
+ ].join(",")
117
+ }
118
+ };
119
+ return result;
120
+ };
121
+
122
+ export {
123
+ generateRGB_R,
124
+ generateRGB_G,
125
+ generateRGB_B,
126
+ generateHSL_H,
127
+ generateHSL_S,
128
+ generateHSL_L,
129
+ generateHSB_H,
130
+ generateHSB_S,
131
+ generateHSB_B
132
+ };
@@ -0,0 +1,344 @@
1
+ import {
2
+ getChannelInputValue
3
+ } from "./chunk-2ERX54SV.mjs";
4
+ import {
5
+ dom
6
+ } from "./chunk-ACSV4TXB.mjs";
7
+ import {
8
+ getChannelDetails
9
+ } from "./chunk-KLLIOTK6.mjs";
10
+
11
+ // src/color-picker.machine.ts
12
+ import { parseColor } from "@zag-js/color-utils";
13
+ import { createMachine } from "@zag-js/core";
14
+ import { trackPointerMove } from "@zag-js/dom-event";
15
+ import { raf } from "@zag-js/dom-query";
16
+ import { clampValue, getPercentValue, snapValueToStep } from "@zag-js/numeric-range";
17
+ import { disableTextSelection } from "@zag-js/text-selection";
18
+ import { compact } from "@zag-js/utils";
19
+ function machine(userContext) {
20
+ const ctx = compact(userContext);
21
+ return createMachine(
22
+ {
23
+ id: "color-picker",
24
+ initial: "idle",
25
+ context: {
26
+ dir: "ltr",
27
+ activeId: null,
28
+ activeChannel: null,
29
+ activeOrientation: null,
30
+ value: "#D9D9D9",
31
+ ...ctx,
32
+ valueAsColor: parseColor(ctx.value || "#D9D9D9")
33
+ },
34
+ computed: {
35
+ isRtl: (ctx2) => ctx2.dir === "rtl",
36
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly)
37
+ },
38
+ on: {
39
+ "VALUE.SET": {
40
+ actions: ["setValue"]
41
+ }
42
+ },
43
+ watch: {
44
+ value: ["setValueAsColor", "syncChannelInputs", "invokeOnChange"]
45
+ },
46
+ states: {
47
+ idle: {
48
+ on: {
49
+ "EYEDROPPER.CLICK": {
50
+ actions: ["openEyeDropper"]
51
+ },
52
+ "AREA.POINTER_DOWN": {
53
+ target: "dragging",
54
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
55
+ },
56
+ "CHANNEL_SLIDER.POINTER_DOWN": {
57
+ target: "dragging",
58
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
59
+ },
60
+ "CHANNEL_INPUT.FOCUS": {
61
+ target: "focused",
62
+ actions: ["setActiveChannel"]
63
+ },
64
+ "CHANNEL_INPUT.CHANGE": {
65
+ actions: ["setChannelColorFromInput"]
66
+ }
67
+ }
68
+ },
69
+ focused: {
70
+ on: {
71
+ "AREA.POINTER_DOWN": {
72
+ target: "dragging",
73
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
74
+ },
75
+ "CHANNEL_SLIDER.POINTER_DOWN": {
76
+ target: "dragging",
77
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
78
+ },
79
+ "AREA.ARROW_LEFT": {
80
+ actions: ["decrementXChannel"]
81
+ },
82
+ "AREA.ARROW_RIGHT": {
83
+ actions: ["incrementXChannel"]
84
+ },
85
+ "AREA.ARROW_UP": {
86
+ actions: ["incrementYChannel"]
87
+ },
88
+ "AREA.ARROW_DOWN": {
89
+ actions: ["decrementYChannel"]
90
+ },
91
+ "AREA.PAGE_UP": {
92
+ actions: ["incrementXChannel"]
93
+ },
94
+ "AREA.PAGE_DOWN": {
95
+ actions: ["decrementXChannel"]
96
+ },
97
+ "CHANNEL_SLIDER.ARROW_LEFT": {
98
+ actions: ["decrementChannel"]
99
+ },
100
+ "CHANNEL_SLIDER.ARROW_RIGHT": {
101
+ actions: ["incrementChannel"]
102
+ },
103
+ "CHANNEL_SLIDER.ARROW_UP": {
104
+ actions: ["incrementChannel"]
105
+ },
106
+ "CHANNEL_SLIDER.ARROW_DOWN": {
107
+ actions: ["decrementChannel"]
108
+ },
109
+ "CHANNEL_SLIDER.PAGE_UP": {
110
+ actions: ["incrementChannel"]
111
+ },
112
+ "CHANNEL_SLIDER.PAGE_DOWN": {
113
+ actions: ["decrementChannel"]
114
+ },
115
+ "CHANNEL_SLIDER.HOME": {
116
+ actions: ["setChannelToMin"]
117
+ },
118
+ "CHANNEL_SLIDER.END": {
119
+ actions: ["setChannelToMax"]
120
+ },
121
+ "CHANNEL_INPUT.FOCUS": {
122
+ actions: ["setActiveChannel"]
123
+ },
124
+ "CHANNEL_INPUT.CHANGE": {
125
+ actions: ["setChannelColorFromInput"]
126
+ },
127
+ "CHANNEL_INPUT.BLUR": [
128
+ {
129
+ guard: "isTextField",
130
+ target: "idle",
131
+ actions: ["setChannelColorFromInput"]
132
+ },
133
+ { target: "idle" }
134
+ ],
135
+ "CHANNEL_SLIDER.BLUR": {
136
+ target: "idle"
137
+ },
138
+ "AREA.BLUR": {
139
+ target: "idle"
140
+ }
141
+ }
142
+ },
143
+ dragging: {
144
+ exit: ["clearActiveChannel"],
145
+ activities: ["trackPointerMove", "disableTextSelection"],
146
+ on: {
147
+ "AREA.POINTER_MOVE": {
148
+ actions: ["setAreaColorFromPoint"]
149
+ },
150
+ "AREA.POINTER_UP": {
151
+ target: "focused",
152
+ actions: ["invokeOnChangeEnd"]
153
+ },
154
+ "CHANNEL_SLIDER.POINTER_MOVE": {
155
+ actions: ["setChannelColorFromPoint"]
156
+ },
157
+ "CHANNEL_SLIDER.POINTER_UP": {
158
+ target: "focused",
159
+ actions: ["invokeOnChangeEnd"]
160
+ }
161
+ }
162
+ }
163
+ }
164
+ },
165
+ {
166
+ guards: {
167
+ isTextField: (_ctx, evt) => !!evt.isTextField
168
+ },
169
+ activities: {
170
+ trackPointerMove(ctx2, _evt, { send }) {
171
+ return trackPointerMove(dom.getDoc(ctx2), {
172
+ onPointerMove({ point }) {
173
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
174
+ send({ type, point });
175
+ },
176
+ onPointerUp() {
177
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
178
+ send({ type });
179
+ }
180
+ });
181
+ },
182
+ disableTextSelection(ctx2) {
183
+ return disableTextSelection({ doc: dom.getDoc(ctx2), target: dom.getContentEl(ctx2) });
184
+ }
185
+ },
186
+ actions: {
187
+ openEyeDropper(ctx2) {
188
+ const isSupported = "EyeDropper" in dom.getWin(ctx2);
189
+ if (!isSupported)
190
+ return;
191
+ const win = dom.getWin(ctx2);
192
+ const picker = new win.EyeDropper();
193
+ picker.open().then(({ sRGBHex }) => {
194
+ const format = ctx2.valueAsColor.getColorSpace();
195
+ const color = parseColor(sRGBHex).toFormat(format);
196
+ setColor(ctx2, color);
197
+ ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: color });
198
+ }).catch(() => void 0);
199
+ },
200
+ setActiveChannel(ctx2, evt) {
201
+ ctx2.activeId = evt.id;
202
+ if (evt.channel) {
203
+ ctx2.activeChannel = evt.channel;
204
+ }
205
+ if (evt.orientation) {
206
+ ctx2.activeOrientation = evt.orientation;
207
+ }
208
+ },
209
+ clearActiveChannel(ctx2) {
210
+ ctx2.activeChannel = null;
211
+ ctx2.activeId = null;
212
+ ctx2.activeOrientation = null;
213
+ },
214
+ setAreaColorFromPoint(ctx2, evt) {
215
+ const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
216
+ const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
217
+ const { getColorFromPoint } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
218
+ const color = getColorFromPoint(percent.x, percent.y);
219
+ if (!color)
220
+ return;
221
+ setColor(ctx2, color);
222
+ },
223
+ setChannelColorFromPoint(ctx2, evt) {
224
+ const channel = evt.channel || ctx2.activeId;
225
+ const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
226
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
227
+ const position = ctx2.activeOrientation || "horizontal";
228
+ const point = position === "horizontal" ? percent.x : percent.y;
229
+ const channelValue = getPercentValue(point, minValue, maxValue, step);
230
+ const value = snapValueToStep(channelValue - step, minValue, maxValue, step);
231
+ const newColor = ctx2.valueAsColor.withChannelValue(channel, value);
232
+ setColor(ctx2, newColor);
233
+ },
234
+ setValue(ctx2, evt) {
235
+ setColor(ctx2, evt.value);
236
+ },
237
+ setValueAsColor(ctx2) {
238
+ try {
239
+ const color = parseColor(ctx2.value);
240
+ if (color.isEqual(ctx2.valueAsColor))
241
+ return;
242
+ ctx2.valueAsColor = color;
243
+ } catch {
244
+ }
245
+ },
246
+ syncChannelInputs(ctx2) {
247
+ const inputs = dom.getChannelInputEls(ctx2);
248
+ inputs.forEach((input) => {
249
+ const channel = input.getAttribute("data-channel");
250
+ if (!channel)
251
+ return;
252
+ const value = getChannelInputValue(ctx2.valueAsColor, channel);
253
+ input.value = value.toString();
254
+ });
255
+ },
256
+ setChannelColorFromInput(ctx2, evt) {
257
+ const { channel, isTextField, value } = evt;
258
+ try {
259
+ const format = ctx2.valueAsColor.getColorSpace();
260
+ const newColor = isTextField ? parseColor(value).toFormat(format) : ctx2.valueAsColor.withChannelValue(channel, value);
261
+ setColor(ctx2, newColor);
262
+ } catch {
263
+ const input = dom.getChannelInputEl(ctx2, channel);
264
+ if (!input)
265
+ return;
266
+ input.value = getChannelInputValue(ctx2.valueAsColor, channel);
267
+ }
268
+ },
269
+ incrementChannel(ctx2, evt) {
270
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
271
+ const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
272
+ const value = snapValueToStep(channelValue + evt.step, minValue, maxValue, step);
273
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, clampValue(value, minValue, maxValue));
274
+ setColor(ctx2, newColor);
275
+ },
276
+ decrementChannel(ctx2, evt) {
277
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
278
+ const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
279
+ const value = snapValueToStep(channelValue - evt.step, minValue, maxValue, step);
280
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, clampValue(value, minValue, maxValue));
281
+ setColor(ctx2, newColor);
282
+ },
283
+ incrementXChannel(ctx2, evt) {
284
+ const { xChannel, yChannel } = evt.channel;
285
+ const { incrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
286
+ const newColor = ctx2.valueAsColor.withChannelValue(xChannel, incrementX(evt.step));
287
+ setColor(ctx2, newColor);
288
+ },
289
+ decrementXChannel(ctx2, evt) {
290
+ const { xChannel, yChannel } = evt.channel;
291
+ const { decrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
292
+ const newColor = ctx2.valueAsColor.withChannelValue(xChannel, decrementX(evt.step));
293
+ setColor(ctx2, newColor);
294
+ },
295
+ incrementYChannel(ctx2, evt) {
296
+ const { xChannel, yChannel } = evt.channel;
297
+ const { incrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
298
+ const newColor = ctx2.valueAsColor.withChannelValue(yChannel, incrementY(evt.step));
299
+ setColor(ctx2, newColor);
300
+ },
301
+ decrementYChannel(ctx2, evt) {
302
+ const { xChannel, yChannel } = evt.channel;
303
+ const { decrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
304
+ const newColor = ctx2.valueAsColor.withChannelValue(yChannel, decrementY(evt.step));
305
+ setColor(ctx2, newColor);
306
+ },
307
+ setChannelToMax(ctx2, evt) {
308
+ const { maxValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
309
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, maxValue);
310
+ setColor(ctx2, newColor);
311
+ },
312
+ setChannelToMin(ctx2, evt) {
313
+ const { minValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
314
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, minValue);
315
+ setColor(ctx2, newColor);
316
+ },
317
+ invokeOnChangeEnd(ctx2) {
318
+ ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
319
+ },
320
+ invokeOnChange(ctx2) {
321
+ ctx2.onChange?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
322
+ },
323
+ focusAreaThumb(ctx2) {
324
+ raf(() => {
325
+ dom.getAreaThumbEl(ctx2)?.focus({ preventScroll: true });
326
+ });
327
+ },
328
+ focusChannelThumb(ctx2, evt) {
329
+ raf(() => {
330
+ dom.getChannelSliderThumbEl(ctx2, evt.channel)?.focus({ preventScroll: true });
331
+ });
332
+ }
333
+ }
334
+ }
335
+ );
336
+ }
337
+ var setColor = (ctx, color) => {
338
+ ctx.value = color.toString("css");
339
+ ctx.valueAsColor = color;
340
+ };
341
+
342
+ export {
343
+ machine
344
+ };
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBg" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBg" | "content" | "label" | "eyeDropTrigger">;
4
+ declare const parts: Record<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBg" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBg" | "content" | "label" | "eyeDropTrigger", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,47 @@
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.anatomy.ts
21
+ var color_picker_anatomy_exports = {};
22
+ __export(color_picker_anatomy_exports, {
23
+ anatomy: () => anatomy,
24
+ parts: () => parts
25
+ });
26
+ module.exports = __toCommonJS(color_picker_anatomy_exports);
27
+ var import_anatomy = require("@zag-js/anatomy");
28
+ var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
29
+ "area",
30
+ "areaThumb",
31
+ "areaGradient",
32
+ "channelSliderTrack",
33
+ "channelSliderTrackBg",
34
+ "channelSliderThumb",
35
+ "channelInput",
36
+ "swatch",
37
+ "swatchBg",
38
+ "content",
39
+ "label",
40
+ "eyeDropTrigger"
41
+ ]);
42
+ var parts = anatomy.build();
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ anatomy,
46
+ parts
47
+ });
@@ -0,0 +1,8 @@
1
+ import {
2
+ anatomy,
3
+ parts
4
+ } from "./chunk-75JXJMB5.mjs";
5
+ export {
6
+ anatomy,
7
+ parts
8
+ };
@@ -0,0 +1,27 @@
1
+ import { Color, ColorChannel, ColorFormat } from '@zag-js/color-utils';
2
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import { State, Send, AreaProps, ChannelProps, ChannelInputProps, SwatchProps } from './color-picker.types.js';
4
+ import '@zag-js/core';
5
+
6
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
7
+ isDragging: boolean;
8
+ value: string;
9
+ valueAsColor: Color;
10
+ channels: [ColorChannel, ColorChannel, ColorChannel];
11
+ setColor(value: string | Color): void;
12
+ setChannelValue(channel: ColorChannel, value: number): void;
13
+ setFormat(format: ColorFormat): void;
14
+ contentProps: T["element"];
15
+ getAreaProps(props: AreaProps): T["element"];
16
+ getAreaGradientProps(props: AreaProps): T["element"];
17
+ getAreaThumbProps(props: AreaProps): T["element"];
18
+ getChannelSliderTrackProps(props: ChannelProps): T["element"];
19
+ getChannelSliderBackgroundProps(props: ChannelProps): T["element"];
20
+ getChannelSliderThumbProps(props: ChannelProps): T["element"];
21
+ getChannelInputProps(props: ChannelInputProps): T["input"];
22
+ eyeDropperTriggerProps: T["button"];
23
+ getSwatchBackgroundProps(props: SwatchProps): T["element"];
24
+ getSwatchProps(props: SwatchProps): T["element"];
25
+ };
26
+
27
+ export { connect };