@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
package/dist/index.js ADDED
@@ -0,0 +1,1066 @@
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/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ connect: () => connect,
24
+ machine: () => machine
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/color-picker.connect.ts
29
+ var import_color_utils2 = require("@zag-js/color-utils");
30
+ var import_dom_event2 = require("@zag-js/dom-event");
31
+ var import_dom_query2 = require("@zag-js/dom-query");
32
+
33
+ // src/color-picker.anatomy.ts
34
+ var import_anatomy = require("@zag-js/anatomy");
35
+ var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
36
+ "area",
37
+ "areaThumb",
38
+ "areaGradient",
39
+ "channelSliderTrack",
40
+ "channelSliderTrackBg",
41
+ "channelSliderThumb",
42
+ "channelInput",
43
+ "swatch",
44
+ "swatchBg",
45
+ "content",
46
+ "label",
47
+ "eyeDropTrigger"
48
+ ]);
49
+ var parts = anatomy.build();
50
+
51
+ // src/color-picker.dom.ts
52
+ var import_dom_event = require("@zag-js/dom-event");
53
+ var import_dom_query = require("@zag-js/dom-query");
54
+ var dom = (0, import_dom_query.createScope)({
55
+ getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
56
+ getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
57
+ getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
58
+ getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
59
+ getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
60
+ getContentId: (ctx) => `color-picker:${ctx.id}:content`,
61
+ getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
62
+ getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
63
+ getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
64
+ getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
65
+ getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
66
+ getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
67
+ getAreaValueFromPoint(ctx, point) {
68
+ const areaEl = dom.getAreaEl(ctx);
69
+ return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
70
+ },
71
+ getChannelSliderTrackEl: (ctx, channel) => {
72
+ return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
73
+ },
74
+ getChannelSliderValueFromPoint(ctx, point, channel) {
75
+ const areaEl = dom.getChannelSliderTrackEl(ctx, channel);
76
+ return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
77
+ },
78
+ getChannelInputEls: (ctx) => {
79
+ return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
80
+ }
81
+ });
82
+
83
+ // src/utils/get-channel-details.ts
84
+ var import_numeric_range = require("@zag-js/numeric-range");
85
+ function getChannelDetails(color, xChannel, yChannel) {
86
+ const channels = color.getColorSpaceAxes({ xChannel, yChannel });
87
+ const xChannelRange = color.getChannelRange(channels.xChannel);
88
+ const yChannelRange = color.getChannelRange(channels.yChannel);
89
+ const { minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX } = xChannelRange;
90
+ const { minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY } = yChannelRange;
91
+ const xValue = color.getChannelValue(channels.xChannel);
92
+ const yValue = color.getChannelValue(channels.yChannel);
93
+ return {
94
+ channels,
95
+ xChannelStep: stepX,
96
+ yChannelStep: stepY,
97
+ xChannelPageStep: pageSizeX,
98
+ yChannelPageStep: pageSizeY,
99
+ xValue,
100
+ yValue,
101
+ getThumbPosition() {
102
+ let x = (xValue - minValueX) / (maxValueX - minValueX);
103
+ let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
104
+ return { x, y };
105
+ },
106
+ incrementX(stepSize) {
107
+ return xValue + stepSize > maxValueX ? maxValueX : (0, import_numeric_range.snapValueToStep)(xValue + stepSize, minValueX, maxValueX, stepX);
108
+ },
109
+ incrementY(stepSize) {
110
+ return yValue + stepSize > maxValueY ? maxValueY : (0, import_numeric_range.snapValueToStep)(yValue + stepSize, minValueY, maxValueY, stepY);
111
+ },
112
+ decrementX(stepSize) {
113
+ return (0, import_numeric_range.snapValueToStep)(xValue - stepSize, minValueX, maxValueX, stepX);
114
+ },
115
+ decrementY(stepSize) {
116
+ return (0, import_numeric_range.snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY);
117
+ },
118
+ getColorFromPoint(x, y) {
119
+ let newXValue = (0, import_numeric_range.getPercentValue)(x, minValueX, maxValueX, stepX);
120
+ let newYValue = (0, import_numeric_range.getPercentValue)(1 - y, minValueY, maxValueY, stepY);
121
+ let newColor;
122
+ if (newXValue !== xValue) {
123
+ newXValue = (0, import_numeric_range.snapValueToStep)(newXValue, minValueX, maxValueX, stepX);
124
+ newColor = color.withChannelValue(channels.xChannel, newXValue);
125
+ }
126
+ if (newYValue !== yValue) {
127
+ newYValue = (0, import_numeric_range.snapValueToStep)(newYValue, minValueY, maxValueY, stepY);
128
+ newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
129
+ }
130
+ return newColor;
131
+ }
132
+ };
133
+ }
134
+
135
+ // src/utils/get-channel-display-color.ts
136
+ var import_color_utils = require("@zag-js/color-utils");
137
+ function getChannelDisplayColor(color, channel) {
138
+ switch (channel) {
139
+ case "hue":
140
+ return (0, import_color_utils.parseColor)(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
141
+ case "lightness":
142
+ case "brightness":
143
+ case "saturation":
144
+ case "red":
145
+ case "green":
146
+ case "blue":
147
+ return color.withChannelValue("alpha", 1);
148
+ case "alpha": {
149
+ return color;
150
+ }
151
+ default:
152
+ throw new Error("Unknown color channel: " + channel);
153
+ }
154
+ }
155
+
156
+ // src/utils/get-channel-input-value.ts
157
+ function getChannelInputValue(color, channel) {
158
+ switch (channel) {
159
+ case "hex":
160
+ return color.toString("hex");
161
+ case "css":
162
+ return color.toString("css");
163
+ default:
164
+ return color.getChannelValue(channel).toString();
165
+ }
166
+ }
167
+ function getChannelInputRange(color, channel) {
168
+ switch (channel) {
169
+ case "hex":
170
+ case "css":
171
+ return void 0;
172
+ default:
173
+ return color.getChannelRange(channel);
174
+ }
175
+ }
176
+
177
+ // src/utils/generate-format-background.ts
178
+ var generateRGB_R = (orientation, dir, zValue) => {
179
+ const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
180
+ const result = {
181
+ areaStyles: {
182
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`
183
+ },
184
+ areaGradientStyles: {
185
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
186
+ WebkitMaskImage: maskImage,
187
+ maskImage
188
+ }
189
+ };
190
+ return result;
191
+ };
192
+ var generateRGB_G = (orientation, dir, zValue) => {
193
+ const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
194
+ const result = {
195
+ areaStyles: {
196
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`
197
+ },
198
+ areaGradientStyles: {
199
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
200
+ WebkitMaskImage: maskImage,
201
+ maskImage
202
+ }
203
+ };
204
+ return result;
205
+ };
206
+ var generateRGB_B = (orientation, dir, zValue) => {
207
+ const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
208
+ const result = {
209
+ areaStyles: {
210
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`
211
+ },
212
+ areaGradientStyles: {
213
+ backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
214
+ WebkitMaskImage: maskImage,
215
+ maskImage
216
+ }
217
+ };
218
+ return result;
219
+ };
220
+ var generateHSL_H = (orientation, dir, zValue) => {
221
+ const result = {
222
+ areaStyles: {},
223
+ areaGradientStyles: {
224
+ background: [
225
+ `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%)`,
226
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
227
+ `hsl(${zValue}, 100%, 50%)`
228
+ ].join(",")
229
+ }
230
+ };
231
+ return result;
232
+ };
233
+ var generateHSL_S = (orientation, dir, alphaValue) => {
234
+ const result = {
235
+ areaStyles: {},
236
+ areaGradientStyles: {
237
+ background: [
238
+ `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%)`,
239
+ `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}))`,
240
+ "hsl(0, 0%, 50%)"
241
+ ].join(",")
242
+ }
243
+ };
244
+ return result;
245
+ };
246
+ var generateHSL_L = (orientation, dir, zValue) => {
247
+ const result = {
248
+ areaStyles: {},
249
+ areaGradientStyles: {
250
+ backgroundImage: [
251
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
252
+ `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}%))`
253
+ ].join(",")
254
+ }
255
+ };
256
+ return result;
257
+ };
258
+ var generateHSB_H = (orientation, dir, zValue) => {
259
+ const result = {
260
+ areaStyles: {},
261
+ areaGradientStyles: {
262
+ background: [
263
+ `linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
264
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
265
+ `hsl(${zValue}, 100%, 50%)`
266
+ ].join(",")
267
+ }
268
+ };
269
+ return result;
270
+ };
271
+ var generateHSB_S = (orientation, dir, alphaValue) => {
272
+ const result = {
273
+ areaStyles: {},
274
+ areaGradientStyles: {
275
+ background: [
276
+ `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
277
+ `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}))`,
278
+ `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
279
+ ].join(",")
280
+ }
281
+ };
282
+ return result;
283
+ };
284
+ var generateHSB_B = (orientation, dir, alphaValue) => {
285
+ const result = {
286
+ areaStyles: {},
287
+ areaGradientStyles: {
288
+ background: [
289
+ `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
290
+ `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}))`,
291
+ "#000"
292
+ ].join(",")
293
+ }
294
+ };
295
+ return result;
296
+ };
297
+
298
+ // src/utils/get-color-area-gradient.ts
299
+ function getColorAreaGradient(ctx, xChannel, yChannel) {
300
+ const value = ctx.valueAsColor;
301
+ const { zChannel } = value.getColorSpaceAxes({ xChannel, yChannel });
302
+ const zValue = value.getChannelValue(zChannel);
303
+ const { minValue: zMin, maxValue: zMax } = value.getChannelRange(zChannel);
304
+ const orientation = ["top", ctx.dir === "rtl" ? "left" : "right"];
305
+ let dir = false;
306
+ let background = { areaStyles: {}, areaGradientStyles: {} };
307
+ let alphaValue = (zValue - zMin) / (zMax - zMin);
308
+ let isHSL = value.getColorSpace() === "hsl";
309
+ switch (zChannel) {
310
+ case "red": {
311
+ dir = xChannel === "green";
312
+ background = generateRGB_R(orientation, dir, zValue);
313
+ break;
314
+ }
315
+ case "green": {
316
+ dir = xChannel === "red";
317
+ background = generateRGB_G(orientation, dir, zValue);
318
+ break;
319
+ }
320
+ case "blue": {
321
+ dir = xChannel === "red";
322
+ background = generateRGB_B(orientation, dir, zValue);
323
+ break;
324
+ }
325
+ case "hue": {
326
+ dir = xChannel !== "saturation";
327
+ if (isHSL) {
328
+ background = generateHSL_H(orientation, dir, zValue);
329
+ } else {
330
+ background = generateHSB_H(orientation, dir, zValue);
331
+ }
332
+ break;
333
+ }
334
+ case "saturation": {
335
+ dir = xChannel === "hue";
336
+ if (isHSL) {
337
+ background = generateHSL_S(orientation, dir, alphaValue);
338
+ } else {
339
+ background = generateHSB_S(orientation, dir, alphaValue);
340
+ }
341
+ break;
342
+ }
343
+ case "brightness": {
344
+ dir = xChannel === "hue";
345
+ background = generateHSB_B(orientation, dir, alphaValue);
346
+ break;
347
+ }
348
+ case "lightness": {
349
+ dir = xChannel === "hue";
350
+ background = generateHSL_L(orientation, dir, zValue);
351
+ break;
352
+ }
353
+ }
354
+ return background;
355
+ }
356
+
357
+ // src/utils/get-slider-background.ts
358
+ function getSliderBgDirection(orientation, dir) {
359
+ if (orientation === "vertical") {
360
+ return "top";
361
+ } else if (dir === "ltr") {
362
+ return "right";
363
+ } else {
364
+ return "left";
365
+ }
366
+ }
367
+ var getSliderBgImage = (ctx, props) => {
368
+ const { channel } = props;
369
+ const dir = getSliderBgDirection(props.orientation, ctx.dir);
370
+ const value = ctx.valueAsColor;
371
+ const { minValue, maxValue } = ctx.valueAsColor.getChannelRange(channel);
372
+ switch (channel) {
373
+ case "hue":
374
+ return `linear-gradient(to ${dir}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
375
+ case "lightness": {
376
+ let start = ctx.valueAsColor.withChannelValue(channel, minValue).toString("css");
377
+ let middle = value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css");
378
+ let end = value.withChannelValue(channel, maxValue).toString("css");
379
+ return `linear-gradient(to ${dir}, ${start}, ${middle}, ${end})`;
380
+ }
381
+ case "saturation":
382
+ case "brightness":
383
+ case "red":
384
+ case "green":
385
+ case "blue":
386
+ case "alpha": {
387
+ let start = value.withChannelValue(channel, minValue).toString("css");
388
+ let end = value.withChannelValue(channel, maxValue).toString("css");
389
+ return `linear-gradient(to ${dir}, ${start}, ${end})`;
390
+ }
391
+ default:
392
+ throw new Error("Unknown color channel: " + channel);
393
+ }
394
+ };
395
+
396
+ // src/color-picker.connect.ts
397
+ function connect(state, send, normalize) {
398
+ const valueAsColor = state.context.valueAsColor;
399
+ const isDisabled = state.context.disabled;
400
+ const isInteractive = state.context.isInteractive;
401
+ const isDragging = state.matches("dragging");
402
+ const channels = valueAsColor.getColorChannels();
403
+ return {
404
+ isDragging,
405
+ value: state.context.value,
406
+ valueAsColor,
407
+ channels,
408
+ setColor(value) {
409
+ send({ type: "VALUE.SET", value: (0, import_color_utils2.normalizeColor)(value), src: "set-color" });
410
+ },
411
+ setChannelValue(channel, value) {
412
+ const color = valueAsColor.withChannelValue(channel, value);
413
+ send({ type: "VALUE.SET", value: color, src: "set-channel" });
414
+ },
415
+ setFormat(format) {
416
+ const value = valueAsColor.toFormat(format);
417
+ send({ type: "VALUE.SET", value, src: "set-format" });
418
+ },
419
+ contentProps: normalize.element({
420
+ ...parts.content.attrs,
421
+ id: dom.getContentId(state.context)
422
+ }),
423
+ getAreaProps(props) {
424
+ const { xChannel, yChannel } = props;
425
+ const { areaStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
426
+ return normalize.element({
427
+ ...parts.area.attrs,
428
+ id: dom.getAreaId(state.context),
429
+ role: "group",
430
+ onPointerDown(event) {
431
+ if (!isInteractive)
432
+ return;
433
+ const evt = (0, import_dom_event2.getNativeEvent)(event);
434
+ if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
435
+ return;
436
+ const point = { x: evt.clientX, y: evt.clientY };
437
+ const channel = { xChannel, yChannel };
438
+ send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
439
+ },
440
+ style: {
441
+ position: "relative",
442
+ touchAction: "none",
443
+ forcedColorAdjust: "none",
444
+ ...areaStyles
445
+ }
446
+ });
447
+ },
448
+ getAreaGradientProps(props) {
449
+ const { xChannel, yChannel } = props;
450
+ const { areaGradientStyles } = getColorAreaGradient(state.context, xChannel, yChannel);
451
+ return normalize.element({
452
+ ...parts.areaGradient.attrs,
453
+ id: dom.getAreaGradientId(state.context),
454
+ style: {
455
+ position: "relative",
456
+ touchAction: "none",
457
+ forcedColorAdjust: "none",
458
+ ...areaGradientStyles
459
+ }
460
+ });
461
+ },
462
+ getAreaThumbProps(props) {
463
+ const { xChannel, yChannel } = props;
464
+ const { getThumbPosition } = getChannelDetails(valueAsColor, xChannel, yChannel);
465
+ const { x, y } = getThumbPosition();
466
+ const channel = { xChannel, yChannel };
467
+ return normalize.element({
468
+ ...parts.areaThumb.attrs,
469
+ id: dom.getAreaThumbId(state.context),
470
+ tabIndex: isDisabled ? void 0 : 0,
471
+ "data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
472
+ role: "presentation",
473
+ style: {
474
+ position: "absolute",
475
+ left: `${x * 100}%`,
476
+ top: `${y * 100}%`,
477
+ transform: "translate(-50%, -50%)",
478
+ touchAction: "none",
479
+ forcedColorAdjust: "none",
480
+ background: valueAsColor.withChannelValue("alpha", 1).toString("css")
481
+ },
482
+ onBlur() {
483
+ send("AREA.BLUR");
484
+ },
485
+ onKeyDown(event) {
486
+ if (!isInteractive)
487
+ return;
488
+ const step = (0, import_dom_event2.getEventStep)(event);
489
+ const keyMap = {
490
+ ArrowUp() {
491
+ send({ type: "AREA.ARROW_UP", channel, step });
492
+ },
493
+ ArrowDown() {
494
+ send({ type: "AREA.ARROW_DOWN", channel, step });
495
+ },
496
+ ArrowLeft() {
497
+ send({ type: "AREA.ARROW_LEFT", channel, step });
498
+ },
499
+ ArrowRight() {
500
+ send({ type: "AREA.ARROW_RIGHT", channel, step });
501
+ },
502
+ PageUp() {
503
+ send({ type: "AREA.PAGE_UP", channel, step });
504
+ },
505
+ PageDown() {
506
+ send({ type: "AREA.PAGE_DOWN", channel, step });
507
+ }
508
+ };
509
+ const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
510
+ if (exec) {
511
+ exec(event);
512
+ event.preventDefault();
513
+ }
514
+ }
515
+ });
516
+ },
517
+ getChannelSliderTrackProps(props) {
518
+ const { orientation = "horizontal", channel } = props;
519
+ return normalize.element({
520
+ ...parts.channelSliderTrack.attrs,
521
+ id: dom.getChannelSliderTrackId(state.context, channel),
522
+ role: "group",
523
+ "data-channel": channel,
524
+ "data-orientation": orientation,
525
+ onPointerDown(event) {
526
+ if (!isInteractive)
527
+ return;
528
+ const evt = (0, import_dom_event2.getNativeEvent)(event);
529
+ if (!(0, import_dom_event2.isLeftClick)(evt) || (0, import_dom_event2.isModifiedEvent)(evt))
530
+ return;
531
+ const point = { x: evt.clientX, y: evt.clientY };
532
+ send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
533
+ },
534
+ style: {
535
+ position: "relative",
536
+ touchAction: "none",
537
+ forcedColorAdjust: "none",
538
+ backgroundImage: getSliderBgImage(state.context, { orientation, channel })
539
+ }
540
+ });
541
+ },
542
+ getChannelSliderBackgroundProps(props) {
543
+ const { orientation = "horizontal", channel } = props;
544
+ return normalize.element({
545
+ ...parts.channelSliderTrackBg.attrs,
546
+ "data-orientation": orientation,
547
+ "data-channel": channel,
548
+ style: {
549
+ position: "absolute",
550
+ backgroundColor: "#fff",
551
+ backgroundImage: [
552
+ "linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
553
+ "linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
554
+ "linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
555
+ "linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
556
+ ].join(","),
557
+ backgroundSize: "16px 16px",
558
+ backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
559
+ inset: 0,
560
+ zIndex: -1
561
+ }
562
+ });
563
+ },
564
+ getChannelSliderThumbProps(props) {
565
+ const { orientation = "horizontal", channel } = props;
566
+ const { minValue, maxValue, step: stepValue } = valueAsColor.getChannelRange(channel);
567
+ const channelValue = valueAsColor.getChannelValue(channel);
568
+ const offset = (channelValue - minValue) / (maxValue - minValue);
569
+ const placementStyles = orientation === "horizontal" ? { left: `${offset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
570
+ return normalize.element({
571
+ ...parts.channelSliderThumb.attrs,
572
+ id: dom.getChannelSliderThumbId(state.context, channel),
573
+ role: "slider",
574
+ "aria-label": channel,
575
+ tabIndex: isDisabled ? void 0 : 0,
576
+ "data-channel": channel,
577
+ "data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
578
+ "data-orientation": orientation,
579
+ "aria-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
580
+ "aria-orientation": orientation,
581
+ "aria-valuemax": maxValue,
582
+ "aria-valuemin": minValue,
583
+ "aria-valuenow": channelValue,
584
+ style: {
585
+ forcedColorAdjust: "none",
586
+ position: "absolute",
587
+ background: getChannelDisplayColor(valueAsColor, channel).toString("css"),
588
+ ...placementStyles
589
+ },
590
+ onFocus() {
591
+ if (!isInteractive)
592
+ return;
593
+ send({ type: "CHANNEL_SLIDER.FOCUS", channel });
594
+ },
595
+ onBlur() {
596
+ if (!isInteractive)
597
+ return;
598
+ send({ type: "CHANNEL_SLIDER.BLUR", channel });
599
+ },
600
+ onKeyDown(event) {
601
+ if (!isInteractive)
602
+ return;
603
+ const step = (0, import_dom_event2.getEventStep)(event) * stepValue;
604
+ const keyMap = {
605
+ ArrowUp() {
606
+ send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
607
+ },
608
+ ArrowDown() {
609
+ send({ type: "CHANNEL_SLIDER.ARROW_DOWN", channel, step });
610
+ },
611
+ ArrowLeft() {
612
+ send({ type: "CHANNEL_SLIDER.ARROW_LEFT", channel, step });
613
+ },
614
+ ArrowRight() {
615
+ send({ type: "CHANNEL_SLIDER.ARROW_RIGHT", channel, step });
616
+ },
617
+ PageUp() {
618
+ send({ type: "CHANNEL_SLIDER.PAGE_UP", channel });
619
+ },
620
+ PageDown() {
621
+ send({ type: "CHANNEL_SLIDER.PAGE_DOWN", channel });
622
+ },
623
+ Home() {
624
+ send({ type: "CHANNEL_SLIDER.HOME", channel });
625
+ },
626
+ End() {
627
+ send({ type: "CHANNEL_SLIDER.END", channel });
628
+ }
629
+ };
630
+ const exec = keyMap[(0, import_dom_event2.getEventKey)(event, state.context)];
631
+ if (exec) {
632
+ exec(event);
633
+ event.preventDefault();
634
+ }
635
+ }
636
+ });
637
+ },
638
+ getChannelInputProps(props) {
639
+ const { channel } = props;
640
+ const isTextField = channel === "hex" || channel === "css";
641
+ const range = getChannelInputRange(valueAsColor, channel);
642
+ return normalize.input({
643
+ ...parts.channelInput.attrs,
644
+ type: isTextField ? "text" : "number",
645
+ "data-channel": channel,
646
+ "aria-label": channel,
647
+ disabled: isDisabled,
648
+ "data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
649
+ readOnly: state.context.readOnly,
650
+ id: dom.getChannelInputId(state.context, channel),
651
+ defaultValue: getChannelInputValue(valueAsColor, channel),
652
+ min: range?.minValue,
653
+ max: range?.maxValue,
654
+ step: range?.step,
655
+ onFocus() {
656
+ send({ type: "CHANNEL_INPUT.FOCUS", channel });
657
+ },
658
+ onChange(event) {
659
+ if (isTextField)
660
+ return;
661
+ const value = event.currentTarget.value;
662
+ send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
663
+ },
664
+ onBlur(event) {
665
+ const value = event.currentTarget.value;
666
+ send({ type: "CHANNEL_INPUT.BLUR", channel, value, isTextField });
667
+ },
668
+ onKeyDown(event) {
669
+ if (!isTextField)
670
+ return;
671
+ if (event.key === "Enter") {
672
+ const value = event.currentTarget.value;
673
+ send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
674
+ }
675
+ },
676
+ style: {
677
+ appearance: "none",
678
+ WebkitAppearance: "none",
679
+ MozAppearance: "textfield"
680
+ }
681
+ });
682
+ },
683
+ eyeDropperTriggerProps: normalize.button({
684
+ ...parts.eyeDropTrigger.attrs,
685
+ onClick() {
686
+ send("EYEDROPPER.CLICK");
687
+ }
688
+ }),
689
+ getSwatchBackgroundProps(props) {
690
+ const { value } = props;
691
+ const alpha = (0, import_color_utils2.normalizeColor)(value).getChannelValue("alpha");
692
+ return normalize.element({
693
+ ...parts.swatchBg.attrs,
694
+ "data-alpha": alpha,
695
+ style: {
696
+ width: "100%",
697
+ height: "100%",
698
+ background: "#fff",
699
+ backgroundImage: [
700
+ "linear-gradient(-45deg,#0000 75.5%,#bcbcbc 75.5%)",
701
+ "linear-gradient(45deg,#0000 75.5%,#bcbcbc 75.5%)",
702
+ "linear-gradient(-45deg,#bcbcbc 25.5%,#0000 25.5%)",
703
+ "linear-gradient(45deg,#bcbcbc 25.5%,#0000 25.5%)"
704
+ ].join(","),
705
+ backgroundPosition: "-2px -2px,-2px 6px,6px -10px,-10px -2px",
706
+ backgroundSize: "16px 16px",
707
+ position: "absolute",
708
+ inset: "0px",
709
+ zIndex: -1
710
+ }
711
+ });
712
+ },
713
+ getSwatchProps(props) {
714
+ const { value, readOnly } = props;
715
+ const color = (0, import_color_utils2.normalizeColor)(value).toFormat(valueAsColor.getColorSpace());
716
+ return normalize.element({
717
+ ...parts.swatch.attrs,
718
+ onClick() {
719
+ if (readOnly)
720
+ return;
721
+ send({ type: "VALUE.SET", value: color });
722
+ },
723
+ style: {
724
+ position: "relative",
725
+ background: color.toString("css")
726
+ }
727
+ });
728
+ }
729
+ };
730
+ }
731
+
732
+ // src/color-picker.machine.ts
733
+ var import_color_utils3 = require("@zag-js/color-utils");
734
+ var import_core = require("@zag-js/core");
735
+ var import_dom_event3 = require("@zag-js/dom-event");
736
+ var import_dom_query3 = require("@zag-js/dom-query");
737
+ var import_numeric_range2 = require("@zag-js/numeric-range");
738
+ var import_text_selection = require("@zag-js/text-selection");
739
+ var import_utils = require("@zag-js/utils");
740
+ function machine(userContext) {
741
+ const ctx = (0, import_utils.compact)(userContext);
742
+ return (0, import_core.createMachine)(
743
+ {
744
+ id: "color-picker",
745
+ initial: "idle",
746
+ context: {
747
+ dir: "ltr",
748
+ activeId: null,
749
+ activeChannel: null,
750
+ activeOrientation: null,
751
+ value: "#D9D9D9",
752
+ ...ctx,
753
+ valueAsColor: (0, import_color_utils3.parseColor)(ctx.value || "#D9D9D9")
754
+ },
755
+ computed: {
756
+ isRtl: (ctx2) => ctx2.dir === "rtl",
757
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly)
758
+ },
759
+ on: {
760
+ "VALUE.SET": {
761
+ actions: ["setValue"]
762
+ }
763
+ },
764
+ watch: {
765
+ value: ["setValueAsColor", "syncChannelInputs", "invokeOnChange"]
766
+ },
767
+ states: {
768
+ idle: {
769
+ on: {
770
+ "EYEDROPPER.CLICK": {
771
+ actions: ["openEyeDropper"]
772
+ },
773
+ "AREA.POINTER_DOWN": {
774
+ target: "dragging",
775
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
776
+ },
777
+ "CHANNEL_SLIDER.POINTER_DOWN": {
778
+ target: "dragging",
779
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
780
+ },
781
+ "CHANNEL_INPUT.FOCUS": {
782
+ target: "focused",
783
+ actions: ["setActiveChannel"]
784
+ },
785
+ "CHANNEL_INPUT.CHANGE": {
786
+ actions: ["setChannelColorFromInput"]
787
+ }
788
+ }
789
+ },
790
+ focused: {
791
+ on: {
792
+ "AREA.POINTER_DOWN": {
793
+ target: "dragging",
794
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
795
+ },
796
+ "CHANNEL_SLIDER.POINTER_DOWN": {
797
+ target: "dragging",
798
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
799
+ },
800
+ "AREA.ARROW_LEFT": {
801
+ actions: ["decrementXChannel"]
802
+ },
803
+ "AREA.ARROW_RIGHT": {
804
+ actions: ["incrementXChannel"]
805
+ },
806
+ "AREA.ARROW_UP": {
807
+ actions: ["incrementYChannel"]
808
+ },
809
+ "AREA.ARROW_DOWN": {
810
+ actions: ["decrementYChannel"]
811
+ },
812
+ "AREA.PAGE_UP": {
813
+ actions: ["incrementXChannel"]
814
+ },
815
+ "AREA.PAGE_DOWN": {
816
+ actions: ["decrementXChannel"]
817
+ },
818
+ "CHANNEL_SLIDER.ARROW_LEFT": {
819
+ actions: ["decrementChannel"]
820
+ },
821
+ "CHANNEL_SLIDER.ARROW_RIGHT": {
822
+ actions: ["incrementChannel"]
823
+ },
824
+ "CHANNEL_SLIDER.ARROW_UP": {
825
+ actions: ["incrementChannel"]
826
+ },
827
+ "CHANNEL_SLIDER.ARROW_DOWN": {
828
+ actions: ["decrementChannel"]
829
+ },
830
+ "CHANNEL_SLIDER.PAGE_UP": {
831
+ actions: ["incrementChannel"]
832
+ },
833
+ "CHANNEL_SLIDER.PAGE_DOWN": {
834
+ actions: ["decrementChannel"]
835
+ },
836
+ "CHANNEL_SLIDER.HOME": {
837
+ actions: ["setChannelToMin"]
838
+ },
839
+ "CHANNEL_SLIDER.END": {
840
+ actions: ["setChannelToMax"]
841
+ },
842
+ "CHANNEL_INPUT.FOCUS": {
843
+ actions: ["setActiveChannel"]
844
+ },
845
+ "CHANNEL_INPUT.CHANGE": {
846
+ actions: ["setChannelColorFromInput"]
847
+ },
848
+ "CHANNEL_INPUT.BLUR": [
849
+ {
850
+ guard: "isTextField",
851
+ target: "idle",
852
+ actions: ["setChannelColorFromInput"]
853
+ },
854
+ { target: "idle" }
855
+ ],
856
+ "CHANNEL_SLIDER.BLUR": {
857
+ target: "idle"
858
+ },
859
+ "AREA.BLUR": {
860
+ target: "idle"
861
+ }
862
+ }
863
+ },
864
+ dragging: {
865
+ exit: ["clearActiveChannel"],
866
+ activities: ["trackPointerMove", "disableTextSelection"],
867
+ on: {
868
+ "AREA.POINTER_MOVE": {
869
+ actions: ["setAreaColorFromPoint"]
870
+ },
871
+ "AREA.POINTER_UP": {
872
+ target: "focused",
873
+ actions: ["invokeOnChangeEnd"]
874
+ },
875
+ "CHANNEL_SLIDER.POINTER_MOVE": {
876
+ actions: ["setChannelColorFromPoint"]
877
+ },
878
+ "CHANNEL_SLIDER.POINTER_UP": {
879
+ target: "focused",
880
+ actions: ["invokeOnChangeEnd"]
881
+ }
882
+ }
883
+ }
884
+ }
885
+ },
886
+ {
887
+ guards: {
888
+ isTextField: (_ctx, evt) => !!evt.isTextField
889
+ },
890
+ activities: {
891
+ trackPointerMove(ctx2, _evt, { send }) {
892
+ return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
893
+ onPointerMove({ point }) {
894
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
895
+ send({ type, point });
896
+ },
897
+ onPointerUp() {
898
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
899
+ send({ type });
900
+ }
901
+ });
902
+ },
903
+ disableTextSelection(ctx2) {
904
+ return (0, import_text_selection.disableTextSelection)({ doc: dom.getDoc(ctx2), target: dom.getContentEl(ctx2) });
905
+ }
906
+ },
907
+ actions: {
908
+ openEyeDropper(ctx2) {
909
+ const isSupported = "EyeDropper" in dom.getWin(ctx2);
910
+ if (!isSupported)
911
+ return;
912
+ const win = dom.getWin(ctx2);
913
+ const picker = new win.EyeDropper();
914
+ picker.open().then(({ sRGBHex }) => {
915
+ const format = ctx2.valueAsColor.getColorSpace();
916
+ const color = (0, import_color_utils3.parseColor)(sRGBHex).toFormat(format);
917
+ setColor(ctx2, color);
918
+ ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: color });
919
+ }).catch(() => void 0);
920
+ },
921
+ setActiveChannel(ctx2, evt) {
922
+ ctx2.activeId = evt.id;
923
+ if (evt.channel) {
924
+ ctx2.activeChannel = evt.channel;
925
+ }
926
+ if (evt.orientation) {
927
+ ctx2.activeOrientation = evt.orientation;
928
+ }
929
+ },
930
+ clearActiveChannel(ctx2) {
931
+ ctx2.activeChannel = null;
932
+ ctx2.activeId = null;
933
+ ctx2.activeOrientation = null;
934
+ },
935
+ setAreaColorFromPoint(ctx2, evt) {
936
+ const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
937
+ const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
938
+ const { getColorFromPoint } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
939
+ const color = getColorFromPoint(percent.x, percent.y);
940
+ if (!color)
941
+ return;
942
+ setColor(ctx2, color);
943
+ },
944
+ setChannelColorFromPoint(ctx2, evt) {
945
+ const channel = evt.channel || ctx2.activeId;
946
+ const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
947
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
948
+ const position = ctx2.activeOrientation || "horizontal";
949
+ const point = position === "horizontal" ? percent.x : percent.y;
950
+ const channelValue = (0, import_numeric_range2.getPercentValue)(point, minValue, maxValue, step);
951
+ const value = (0, import_numeric_range2.snapValueToStep)(channelValue - step, minValue, maxValue, step);
952
+ const newColor = ctx2.valueAsColor.withChannelValue(channel, value);
953
+ setColor(ctx2, newColor);
954
+ },
955
+ setValue(ctx2, evt) {
956
+ setColor(ctx2, evt.value);
957
+ },
958
+ setValueAsColor(ctx2) {
959
+ try {
960
+ const color = (0, import_color_utils3.parseColor)(ctx2.value);
961
+ if (color.isEqual(ctx2.valueAsColor))
962
+ return;
963
+ ctx2.valueAsColor = color;
964
+ } catch {
965
+ }
966
+ },
967
+ syncChannelInputs(ctx2) {
968
+ const inputs = dom.getChannelInputEls(ctx2);
969
+ inputs.forEach((input) => {
970
+ const channel = input.getAttribute("data-channel");
971
+ if (!channel)
972
+ return;
973
+ const value = getChannelInputValue(ctx2.valueAsColor, channel);
974
+ input.value = value.toString();
975
+ });
976
+ },
977
+ setChannelColorFromInput(ctx2, evt) {
978
+ const { channel, isTextField, value } = evt;
979
+ try {
980
+ const format = ctx2.valueAsColor.getColorSpace();
981
+ const newColor = isTextField ? (0, import_color_utils3.parseColor)(value).toFormat(format) : ctx2.valueAsColor.withChannelValue(channel, value);
982
+ setColor(ctx2, newColor);
983
+ } catch {
984
+ const input = dom.getChannelInputEl(ctx2, channel);
985
+ if (!input)
986
+ return;
987
+ input.value = getChannelInputValue(ctx2.valueAsColor, channel);
988
+ }
989
+ },
990
+ incrementChannel(ctx2, evt) {
991
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
992
+ const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
993
+ const value = (0, import_numeric_range2.snapValueToStep)(channelValue + evt.step, minValue, maxValue, step);
994
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, (0, import_numeric_range2.clampValue)(value, minValue, maxValue));
995
+ setColor(ctx2, newColor);
996
+ },
997
+ decrementChannel(ctx2, evt) {
998
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
999
+ const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
1000
+ const value = (0, import_numeric_range2.snapValueToStep)(channelValue - evt.step, minValue, maxValue, step);
1001
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, (0, import_numeric_range2.clampValue)(value, minValue, maxValue));
1002
+ setColor(ctx2, newColor);
1003
+ },
1004
+ incrementXChannel(ctx2, evt) {
1005
+ const { xChannel, yChannel } = evt.channel;
1006
+ const { incrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
1007
+ const newColor = ctx2.valueAsColor.withChannelValue(xChannel, incrementX(evt.step));
1008
+ setColor(ctx2, newColor);
1009
+ },
1010
+ decrementXChannel(ctx2, evt) {
1011
+ const { xChannel, yChannel } = evt.channel;
1012
+ const { decrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
1013
+ const newColor = ctx2.valueAsColor.withChannelValue(xChannel, decrementX(evt.step));
1014
+ setColor(ctx2, newColor);
1015
+ },
1016
+ incrementYChannel(ctx2, evt) {
1017
+ const { xChannel, yChannel } = evt.channel;
1018
+ const { incrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
1019
+ const newColor = ctx2.valueAsColor.withChannelValue(yChannel, incrementY(evt.step));
1020
+ setColor(ctx2, newColor);
1021
+ },
1022
+ decrementYChannel(ctx2, evt) {
1023
+ const { xChannel, yChannel } = evt.channel;
1024
+ const { decrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
1025
+ const newColor = ctx2.valueAsColor.withChannelValue(yChannel, decrementY(evt.step));
1026
+ setColor(ctx2, newColor);
1027
+ },
1028
+ setChannelToMax(ctx2, evt) {
1029
+ const { maxValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
1030
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, maxValue);
1031
+ setColor(ctx2, newColor);
1032
+ },
1033
+ setChannelToMin(ctx2, evt) {
1034
+ const { minValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
1035
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, minValue);
1036
+ setColor(ctx2, newColor);
1037
+ },
1038
+ invokeOnChangeEnd(ctx2) {
1039
+ ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
1040
+ },
1041
+ invokeOnChange(ctx2) {
1042
+ ctx2.onChange?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
1043
+ },
1044
+ focusAreaThumb(ctx2) {
1045
+ (0, import_dom_query3.raf)(() => {
1046
+ dom.getAreaThumbEl(ctx2)?.focus({ preventScroll: true });
1047
+ });
1048
+ },
1049
+ focusChannelThumb(ctx2, evt) {
1050
+ (0, import_dom_query3.raf)(() => {
1051
+ dom.getChannelSliderThumbEl(ctx2, evt.channel)?.focus({ preventScroll: true });
1052
+ });
1053
+ }
1054
+ }
1055
+ }
1056
+ );
1057
+ }
1058
+ var setColor = (ctx, color) => {
1059
+ ctx.value = color.toString("css");
1060
+ ctx.valueAsColor = color;
1061
+ };
1062
+ // Annotate the CommonJS export names for ESM import in node:
1063
+ 0 && (module.exports = {
1064
+ connect,
1065
+ machine
1066
+ });