@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,14 @@
1
+ import {
2
+ connect
3
+ } from "./chunk-J3XCPS5T.mjs";
4
+ import "./chunk-JNBNPPMF.mjs";
5
+ import "./chunk-KO4TBUXB.mjs";
6
+ import "./chunk-3XH465XT.mjs";
7
+ import "./chunk-75JXJMB5.mjs";
8
+ import "./chunk-2ERX54SV.mjs";
9
+ import "./chunk-ACSV4TXB.mjs";
10
+ import "./chunk-OY3B7NXA.mjs";
11
+ import "./chunk-KLLIOTK6.mjs";
12
+ export {
13
+ connect
14
+ };
@@ -0,0 +1,62 @@
1
+ import { ColorChannel } from '@zag-js/color-utils';
2
+ import { MachineContext } from './color-picker.types.js';
3
+ import '@zag-js/core';
4
+ import '@zag-js/types';
5
+
6
+ type Point = {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ declare const dom: {
11
+ getRootNode: (ctx: {
12
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
13
+ }) => ShadowRoot | Document;
14
+ getDoc: (ctx: {
15
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
16
+ }) => Document;
17
+ getWin: (ctx: {
18
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
19
+ }) => Window & typeof globalThis;
20
+ getActiveElement: (ctx: {
21
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
22
+ }) => HTMLElement | null;
23
+ getById: <T extends HTMLElement = HTMLElement>(ctx: {
24
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
25
+ }, id: string) => T | null;
26
+ queryById: <T_1 extends HTMLElement = HTMLElement>(ctx: {
27
+ getRootNode?: (() => Node | ShadowRoot | Document) | undefined;
28
+ }, id: string) => T_1;
29
+ } & {
30
+ getAreaId: (ctx: MachineContext) => string;
31
+ getAreaGradientId: (ctx: MachineContext) => string;
32
+ getAreaThumbId: (ctx: MachineContext) => string;
33
+ getChannelSliderTrackId: (ctx: MachineContext, channel: ColorChannel) => string;
34
+ getChannelInputId: (ctx: MachineContext, channel: string) => string;
35
+ getContentId: (ctx: MachineContext) => string;
36
+ getChannelSliderThumbId: (ctx: MachineContext, channel: ColorChannel) => string;
37
+ getContentEl: (ctx: MachineContext) => HTMLElement;
38
+ getAreaThumbEl: (ctx: MachineContext) => HTMLElement;
39
+ getChannelSliderThumbEl: (ctx: MachineContext, channel: ColorChannel) => HTMLElement;
40
+ getChannelInputEl: (ctx: MachineContext, channel: string) => HTMLInputElement;
41
+ getAreaEl: (ctx: MachineContext) => HTMLElement;
42
+ getAreaValueFromPoint(ctx: MachineContext, point: Point): {
43
+ x: number;
44
+ y: number;
45
+ normalize(options?: {
46
+ dir?: "ltr" | "rtl" | undefined;
47
+ orientation?: "horizontal" | "vertical" | undefined;
48
+ }): number;
49
+ };
50
+ getChannelSliderTrackEl: (ctx: MachineContext, channel: ColorChannel) => HTMLElement;
51
+ getChannelSliderValueFromPoint(ctx: MachineContext, point: Point, channel: ColorChannel): {
52
+ x: number;
53
+ y: number;
54
+ normalize(options?: {
55
+ dir?: "ltr" | "rtl" | undefined;
56
+ orientation?: "horizontal" | "vertical" | undefined;
57
+ }): number;
58
+ };
59
+ getChannelInputEls: (ctx: MachineContext) => HTMLInputElement[];
60
+ };
61
+
62
+ export { dom };
@@ -0,0 +1,59 @@
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.dom.ts
21
+ var color_picker_dom_exports = {};
22
+ __export(color_picker_dom_exports, {
23
+ dom: () => dom
24
+ });
25
+ module.exports = __toCommonJS(color_picker_dom_exports);
26
+ var import_dom_event = require("@zag-js/dom-event");
27
+ var import_dom_query = require("@zag-js/dom-query");
28
+ var dom = (0, import_dom_query.createScope)({
29
+ getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
30
+ getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
31
+ getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
32
+ getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
33
+ getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
34
+ getContentId: (ctx) => `color-picker:${ctx.id}:content`,
35
+ getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
36
+ getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
37
+ getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
38
+ getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
39
+ getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
40
+ getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
41
+ getAreaValueFromPoint(ctx, point) {
42
+ const areaEl = dom.getAreaEl(ctx);
43
+ return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
44
+ },
45
+ getChannelSliderTrackEl: (ctx, channel) => {
46
+ return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
47
+ },
48
+ getChannelSliderValueFromPoint(ctx, point, channel) {
49
+ const areaEl = dom.getChannelSliderTrackEl(ctx, channel);
50
+ return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
51
+ },
52
+ getChannelInputEls: (ctx) => {
53
+ return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
54
+ }
55
+ });
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ dom
59
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ dom
3
+ } from "./chunk-ACSV4TXB.mjs";
4
+ export {
5
+ dom
6
+ };
@@ -0,0 +1,8 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { UserDefinedContext, MachineContext, MachineState } from './color-picker.types.js';
3
+ import '@zag-js/color-utils';
4
+ import '@zag-js/types';
5
+
6
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
7
+
8
+ export { machine };
@@ -0,0 +1,456 @@
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.machine.ts
21
+ var color_picker_machine_exports = {};
22
+ __export(color_picker_machine_exports, {
23
+ machine: () => machine
24
+ });
25
+ module.exports = __toCommonJS(color_picker_machine_exports);
26
+ var import_color_utils = require("@zag-js/color-utils");
27
+ var import_core = require("@zag-js/core");
28
+ var import_dom_event2 = require("@zag-js/dom-event");
29
+ var import_dom_query2 = require("@zag-js/dom-query");
30
+ var import_numeric_range2 = require("@zag-js/numeric-range");
31
+ var import_text_selection = require("@zag-js/text-selection");
32
+ var import_utils = require("@zag-js/utils");
33
+
34
+ // src/color-picker.dom.ts
35
+ var import_dom_event = require("@zag-js/dom-event");
36
+ var import_dom_query = require("@zag-js/dom-query");
37
+ var dom = (0, import_dom_query.createScope)({
38
+ getAreaId: (ctx) => `color-picker:${ctx.id}:area`,
39
+ getAreaGradientId: (ctx) => `color-picker:${ctx.id}:area-gradient`,
40
+ getAreaThumbId: (ctx) => `color-picker:${ctx.id}:area-thumb`,
41
+ getChannelSliderTrackId: (ctx, channel) => `color-picker:${ctx.id}:slider-track:${channel}`,
42
+ getChannelInputId: (ctx, channel) => `color-picker:${ctx.id}:input:${channel}`,
43
+ getContentId: (ctx) => `color-picker:${ctx.id}:content`,
44
+ getChannelSliderThumbId: (ctx, channel) => `color-picker:${ctx.id}:thumb:${channel}`,
45
+ getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
46
+ getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
47
+ getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
48
+ getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
49
+ getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
50
+ getAreaValueFromPoint(ctx, point) {
51
+ const areaEl = dom.getAreaEl(ctx);
52
+ return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
53
+ },
54
+ getChannelSliderTrackEl: (ctx, channel) => {
55
+ return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
56
+ },
57
+ getChannelSliderValueFromPoint(ctx, point, channel) {
58
+ const areaEl = dom.getChannelSliderTrackEl(ctx, channel);
59
+ return (0, import_dom_event.getRelativePointPercent)(point, areaEl);
60
+ },
61
+ getChannelInputEls: (ctx) => {
62
+ return (0, import_dom_query.queryAll)(dom.getContentEl(ctx), "input[data-channel]");
63
+ }
64
+ });
65
+
66
+ // src/utils/get-channel-details.ts
67
+ var import_numeric_range = require("@zag-js/numeric-range");
68
+ function getChannelDetails(color, xChannel, yChannel) {
69
+ const channels = color.getColorSpaceAxes({ xChannel, yChannel });
70
+ const xChannelRange = color.getChannelRange(channels.xChannel);
71
+ const yChannelRange = color.getChannelRange(channels.yChannel);
72
+ const { minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX } = xChannelRange;
73
+ const { minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY } = yChannelRange;
74
+ const xValue = color.getChannelValue(channels.xChannel);
75
+ const yValue = color.getChannelValue(channels.yChannel);
76
+ return {
77
+ channels,
78
+ xChannelStep: stepX,
79
+ yChannelStep: stepY,
80
+ xChannelPageStep: pageSizeX,
81
+ yChannelPageStep: pageSizeY,
82
+ xValue,
83
+ yValue,
84
+ getThumbPosition() {
85
+ let x = (xValue - minValueX) / (maxValueX - minValueX);
86
+ let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);
87
+ return { x, y };
88
+ },
89
+ incrementX(stepSize) {
90
+ return xValue + stepSize > maxValueX ? maxValueX : (0, import_numeric_range.snapValueToStep)(xValue + stepSize, minValueX, maxValueX, stepX);
91
+ },
92
+ incrementY(stepSize) {
93
+ return yValue + stepSize > maxValueY ? maxValueY : (0, import_numeric_range.snapValueToStep)(yValue + stepSize, minValueY, maxValueY, stepY);
94
+ },
95
+ decrementX(stepSize) {
96
+ return (0, import_numeric_range.snapValueToStep)(xValue - stepSize, minValueX, maxValueX, stepX);
97
+ },
98
+ decrementY(stepSize) {
99
+ return (0, import_numeric_range.snapValueToStep)(yValue - stepSize, minValueY, maxValueY, stepY);
100
+ },
101
+ getColorFromPoint(x, y) {
102
+ let newXValue = (0, import_numeric_range.getPercentValue)(x, minValueX, maxValueX, stepX);
103
+ let newYValue = (0, import_numeric_range.getPercentValue)(1 - y, minValueY, maxValueY, stepY);
104
+ let newColor;
105
+ if (newXValue !== xValue) {
106
+ newXValue = (0, import_numeric_range.snapValueToStep)(newXValue, minValueX, maxValueX, stepX);
107
+ newColor = color.withChannelValue(channels.xChannel, newXValue);
108
+ }
109
+ if (newYValue !== yValue) {
110
+ newYValue = (0, import_numeric_range.snapValueToStep)(newYValue, minValueY, maxValueY, stepY);
111
+ newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);
112
+ }
113
+ return newColor;
114
+ }
115
+ };
116
+ }
117
+
118
+ // src/utils/get-channel-input-value.ts
119
+ function getChannelInputValue(color, channel) {
120
+ switch (channel) {
121
+ case "hex":
122
+ return color.toString("hex");
123
+ case "css":
124
+ return color.toString("css");
125
+ default:
126
+ return color.getChannelValue(channel).toString();
127
+ }
128
+ }
129
+
130
+ // src/color-picker.machine.ts
131
+ function machine(userContext) {
132
+ const ctx = (0, import_utils.compact)(userContext);
133
+ return (0, import_core.createMachine)(
134
+ {
135
+ id: "color-picker",
136
+ initial: "idle",
137
+ context: {
138
+ dir: "ltr",
139
+ activeId: null,
140
+ activeChannel: null,
141
+ activeOrientation: null,
142
+ value: "#D9D9D9",
143
+ ...ctx,
144
+ valueAsColor: (0, import_color_utils.parseColor)(ctx.value || "#D9D9D9")
145
+ },
146
+ computed: {
147
+ isRtl: (ctx2) => ctx2.dir === "rtl",
148
+ isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly)
149
+ },
150
+ on: {
151
+ "VALUE.SET": {
152
+ actions: ["setValue"]
153
+ }
154
+ },
155
+ watch: {
156
+ value: ["setValueAsColor", "syncChannelInputs", "invokeOnChange"]
157
+ },
158
+ states: {
159
+ idle: {
160
+ on: {
161
+ "EYEDROPPER.CLICK": {
162
+ actions: ["openEyeDropper"]
163
+ },
164
+ "AREA.POINTER_DOWN": {
165
+ target: "dragging",
166
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
167
+ },
168
+ "CHANNEL_SLIDER.POINTER_DOWN": {
169
+ target: "dragging",
170
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
171
+ },
172
+ "CHANNEL_INPUT.FOCUS": {
173
+ target: "focused",
174
+ actions: ["setActiveChannel"]
175
+ },
176
+ "CHANNEL_INPUT.CHANGE": {
177
+ actions: ["setChannelColorFromInput"]
178
+ }
179
+ }
180
+ },
181
+ focused: {
182
+ on: {
183
+ "AREA.POINTER_DOWN": {
184
+ target: "dragging",
185
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
186
+ },
187
+ "CHANNEL_SLIDER.POINTER_DOWN": {
188
+ target: "dragging",
189
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
190
+ },
191
+ "AREA.ARROW_LEFT": {
192
+ actions: ["decrementXChannel"]
193
+ },
194
+ "AREA.ARROW_RIGHT": {
195
+ actions: ["incrementXChannel"]
196
+ },
197
+ "AREA.ARROW_UP": {
198
+ actions: ["incrementYChannel"]
199
+ },
200
+ "AREA.ARROW_DOWN": {
201
+ actions: ["decrementYChannel"]
202
+ },
203
+ "AREA.PAGE_UP": {
204
+ actions: ["incrementXChannel"]
205
+ },
206
+ "AREA.PAGE_DOWN": {
207
+ actions: ["decrementXChannel"]
208
+ },
209
+ "CHANNEL_SLIDER.ARROW_LEFT": {
210
+ actions: ["decrementChannel"]
211
+ },
212
+ "CHANNEL_SLIDER.ARROW_RIGHT": {
213
+ actions: ["incrementChannel"]
214
+ },
215
+ "CHANNEL_SLIDER.ARROW_UP": {
216
+ actions: ["incrementChannel"]
217
+ },
218
+ "CHANNEL_SLIDER.ARROW_DOWN": {
219
+ actions: ["decrementChannel"]
220
+ },
221
+ "CHANNEL_SLIDER.PAGE_UP": {
222
+ actions: ["incrementChannel"]
223
+ },
224
+ "CHANNEL_SLIDER.PAGE_DOWN": {
225
+ actions: ["decrementChannel"]
226
+ },
227
+ "CHANNEL_SLIDER.HOME": {
228
+ actions: ["setChannelToMin"]
229
+ },
230
+ "CHANNEL_SLIDER.END": {
231
+ actions: ["setChannelToMax"]
232
+ },
233
+ "CHANNEL_INPUT.FOCUS": {
234
+ actions: ["setActiveChannel"]
235
+ },
236
+ "CHANNEL_INPUT.CHANGE": {
237
+ actions: ["setChannelColorFromInput"]
238
+ },
239
+ "CHANNEL_INPUT.BLUR": [
240
+ {
241
+ guard: "isTextField",
242
+ target: "idle",
243
+ actions: ["setChannelColorFromInput"]
244
+ },
245
+ { target: "idle" }
246
+ ],
247
+ "CHANNEL_SLIDER.BLUR": {
248
+ target: "idle"
249
+ },
250
+ "AREA.BLUR": {
251
+ target: "idle"
252
+ }
253
+ }
254
+ },
255
+ dragging: {
256
+ exit: ["clearActiveChannel"],
257
+ activities: ["trackPointerMove", "disableTextSelection"],
258
+ on: {
259
+ "AREA.POINTER_MOVE": {
260
+ actions: ["setAreaColorFromPoint"]
261
+ },
262
+ "AREA.POINTER_UP": {
263
+ target: "focused",
264
+ actions: ["invokeOnChangeEnd"]
265
+ },
266
+ "CHANNEL_SLIDER.POINTER_MOVE": {
267
+ actions: ["setChannelColorFromPoint"]
268
+ },
269
+ "CHANNEL_SLIDER.POINTER_UP": {
270
+ target: "focused",
271
+ actions: ["invokeOnChangeEnd"]
272
+ }
273
+ }
274
+ }
275
+ }
276
+ },
277
+ {
278
+ guards: {
279
+ isTextField: (_ctx, evt) => !!evt.isTextField
280
+ },
281
+ activities: {
282
+ trackPointerMove(ctx2, _evt, { send }) {
283
+ return (0, import_dom_event2.trackPointerMove)(dom.getDoc(ctx2), {
284
+ onPointerMove({ point }) {
285
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
286
+ send({ type, point });
287
+ },
288
+ onPointerUp() {
289
+ const type = ctx2.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
290
+ send({ type });
291
+ }
292
+ });
293
+ },
294
+ disableTextSelection(ctx2) {
295
+ return (0, import_text_selection.disableTextSelection)({ doc: dom.getDoc(ctx2), target: dom.getContentEl(ctx2) });
296
+ }
297
+ },
298
+ actions: {
299
+ openEyeDropper(ctx2) {
300
+ const isSupported = "EyeDropper" in dom.getWin(ctx2);
301
+ if (!isSupported)
302
+ return;
303
+ const win = dom.getWin(ctx2);
304
+ const picker = new win.EyeDropper();
305
+ picker.open().then(({ sRGBHex }) => {
306
+ const format = ctx2.valueAsColor.getColorSpace();
307
+ const color = (0, import_color_utils.parseColor)(sRGBHex).toFormat(format);
308
+ setColor(ctx2, color);
309
+ ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: color });
310
+ }).catch(() => void 0);
311
+ },
312
+ setActiveChannel(ctx2, evt) {
313
+ ctx2.activeId = evt.id;
314
+ if (evt.channel) {
315
+ ctx2.activeChannel = evt.channel;
316
+ }
317
+ if (evt.orientation) {
318
+ ctx2.activeOrientation = evt.orientation;
319
+ }
320
+ },
321
+ clearActiveChannel(ctx2) {
322
+ ctx2.activeChannel = null;
323
+ ctx2.activeId = null;
324
+ ctx2.activeOrientation = null;
325
+ },
326
+ setAreaColorFromPoint(ctx2, evt) {
327
+ const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
328
+ const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
329
+ const { getColorFromPoint } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
330
+ const color = getColorFromPoint(percent.x, percent.y);
331
+ if (!color)
332
+ return;
333
+ setColor(ctx2, color);
334
+ },
335
+ setChannelColorFromPoint(ctx2, evt) {
336
+ const channel = evt.channel || ctx2.activeId;
337
+ const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
338
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
339
+ const position = ctx2.activeOrientation || "horizontal";
340
+ const point = position === "horizontal" ? percent.x : percent.y;
341
+ const channelValue = (0, import_numeric_range2.getPercentValue)(point, minValue, maxValue, step);
342
+ const value = (0, import_numeric_range2.snapValueToStep)(channelValue - step, minValue, maxValue, step);
343
+ const newColor = ctx2.valueAsColor.withChannelValue(channel, value);
344
+ setColor(ctx2, newColor);
345
+ },
346
+ setValue(ctx2, evt) {
347
+ setColor(ctx2, evt.value);
348
+ },
349
+ setValueAsColor(ctx2) {
350
+ try {
351
+ const color = (0, import_color_utils.parseColor)(ctx2.value);
352
+ if (color.isEqual(ctx2.valueAsColor))
353
+ return;
354
+ ctx2.valueAsColor = color;
355
+ } catch {
356
+ }
357
+ },
358
+ syncChannelInputs(ctx2) {
359
+ const inputs = dom.getChannelInputEls(ctx2);
360
+ inputs.forEach((input) => {
361
+ const channel = input.getAttribute("data-channel");
362
+ if (!channel)
363
+ return;
364
+ const value = getChannelInputValue(ctx2.valueAsColor, channel);
365
+ input.value = value.toString();
366
+ });
367
+ },
368
+ setChannelColorFromInput(ctx2, evt) {
369
+ const { channel, isTextField, value } = evt;
370
+ try {
371
+ const format = ctx2.valueAsColor.getColorSpace();
372
+ const newColor = isTextField ? (0, import_color_utils.parseColor)(value).toFormat(format) : ctx2.valueAsColor.withChannelValue(channel, value);
373
+ setColor(ctx2, newColor);
374
+ } catch {
375
+ const input = dom.getChannelInputEl(ctx2, channel);
376
+ if (!input)
377
+ return;
378
+ input.value = getChannelInputValue(ctx2.valueAsColor, channel);
379
+ }
380
+ },
381
+ incrementChannel(ctx2, evt) {
382
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
383
+ const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
384
+ const value = (0, import_numeric_range2.snapValueToStep)(channelValue + evt.step, minValue, maxValue, step);
385
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, (0, import_numeric_range2.clampValue)(value, minValue, maxValue));
386
+ setColor(ctx2, newColor);
387
+ },
388
+ decrementChannel(ctx2, evt) {
389
+ const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(evt.channel);
390
+ const channelValue = ctx2.valueAsColor.getChannelValue(evt.channel);
391
+ const value = (0, import_numeric_range2.snapValueToStep)(channelValue - evt.step, minValue, maxValue, step);
392
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, (0, import_numeric_range2.clampValue)(value, minValue, maxValue));
393
+ setColor(ctx2, newColor);
394
+ },
395
+ incrementXChannel(ctx2, evt) {
396
+ const { xChannel, yChannel } = evt.channel;
397
+ const { incrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
398
+ const newColor = ctx2.valueAsColor.withChannelValue(xChannel, incrementX(evt.step));
399
+ setColor(ctx2, newColor);
400
+ },
401
+ decrementXChannel(ctx2, evt) {
402
+ const { xChannel, yChannel } = evt.channel;
403
+ const { decrementX } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
404
+ const newColor = ctx2.valueAsColor.withChannelValue(xChannel, decrementX(evt.step));
405
+ setColor(ctx2, newColor);
406
+ },
407
+ incrementYChannel(ctx2, evt) {
408
+ const { xChannel, yChannel } = evt.channel;
409
+ const { incrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
410
+ const newColor = ctx2.valueAsColor.withChannelValue(yChannel, incrementY(evt.step));
411
+ setColor(ctx2, newColor);
412
+ },
413
+ decrementYChannel(ctx2, evt) {
414
+ const { xChannel, yChannel } = evt.channel;
415
+ const { decrementY } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
416
+ const newColor = ctx2.valueAsColor.withChannelValue(yChannel, decrementY(evt.step));
417
+ setColor(ctx2, newColor);
418
+ },
419
+ setChannelToMax(ctx2, evt) {
420
+ const { maxValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
421
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, maxValue);
422
+ setColor(ctx2, newColor);
423
+ },
424
+ setChannelToMin(ctx2, evt) {
425
+ const { minValue } = ctx2.valueAsColor.getChannelRange(evt.channel);
426
+ const newColor = ctx2.valueAsColor.withChannelValue(evt.channel, minValue);
427
+ setColor(ctx2, newColor);
428
+ },
429
+ invokeOnChangeEnd(ctx2) {
430
+ ctx2.onChangeEnd?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
431
+ },
432
+ invokeOnChange(ctx2) {
433
+ ctx2.onChange?.({ value: ctx2.value, valueAsColor: ctx2.valueAsColor });
434
+ },
435
+ focusAreaThumb(ctx2) {
436
+ (0, import_dom_query2.raf)(() => {
437
+ dom.getAreaThumbEl(ctx2)?.focus({ preventScroll: true });
438
+ });
439
+ },
440
+ focusChannelThumb(ctx2, evt) {
441
+ (0, import_dom_query2.raf)(() => {
442
+ dom.getChannelSliderThumbEl(ctx2, evt.channel)?.focus({ preventScroll: true });
443
+ });
444
+ }
445
+ }
446
+ }
447
+ );
448
+ }
449
+ var setColor = (ctx, color) => {
450
+ ctx.value = color.toString("css");
451
+ ctx.valueAsColor = color;
452
+ };
453
+ // Annotate the CommonJS export names for ESM import in node:
454
+ 0 && (module.exports = {
455
+ machine
456
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ machine
3
+ } from "./chunk-ZBNUATFY.mjs";
4
+ import "./chunk-2ERX54SV.mjs";
5
+ import "./chunk-ACSV4TXB.mjs";
6
+ import "./chunk-KLLIOTK6.mjs";
7
+ export {
8
+ machine
9
+ };