@zag-js/color-picker 1.34.1 → 1.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/color-picker.anatomy.d.mts +6 -0
  2. package/dist/color-picker.anatomy.d.ts +6 -0
  3. package/dist/color-picker.anatomy.js +59 -0
  4. package/dist/color-picker.anatomy.mjs +33 -0
  5. package/dist/color-picker.connect.d.mts +10 -0
  6. package/dist/color-picker.connect.d.ts +10 -0
  7. package/dist/color-picker.connect.js +681 -0
  8. package/dist/color-picker.connect.mjs +646 -0
  9. package/dist/color-picker.dom.d.mts +39 -0
  10. package/dist/color-picker.dom.d.ts +39 -0
  11. package/dist/color-picker.dom.js +136 -0
  12. package/dist/color-picker.dom.mjs +85 -0
  13. package/dist/color-picker.machine.d.mts +10 -0
  14. package/dist/color-picker.machine.d.ts +10 -0
  15. package/dist/color-picker.machine.js +636 -0
  16. package/dist/color-picker.machine.mjs +609 -0
  17. package/dist/color-picker.parse.d.mts +5 -0
  18. package/dist/color-picker.parse.d.ts +5 -0
  19. package/dist/color-picker.parse.js +33 -0
  20. package/dist/color-picker.parse.mjs +8 -0
  21. package/dist/color-picker.props.d.mts +21 -0
  22. package/dist/color-picker.props.d.ts +21 -0
  23. package/dist/color-picker.props.js +94 -0
  24. package/dist/color-picker.props.mjs +58 -0
  25. package/dist/color-picker.types.d.mts +303 -0
  26. package/dist/color-picker.types.d.ts +303 -0
  27. package/dist/color-picker.types.js +18 -0
  28. package/dist/color-picker.types.mjs +0 -0
  29. package/dist/index.d.mts +9 -324
  30. package/dist/index.d.ts +9 -324
  31. package/dist/index.js +37 -1517
  32. package/dist/index.mjs +11 -1504
  33. package/dist/utils/get-channel-display-color.d.mts +5 -0
  34. package/dist/utils/get-channel-display-color.d.ts +5 -0
  35. package/dist/utils/get-channel-display-color.js +48 -0
  36. package/dist/utils/get-channel-display-color.mjs +23 -0
  37. package/dist/utils/get-channel-input-value.d.mts +11 -0
  38. package/dist/utils/get-channel-input-value.d.ts +11 -0
  39. package/dist/utils/get-channel-input-value.js +88 -0
  40. package/dist/utils/get-channel-input-value.mjs +62 -0
  41. package/dist/utils/get-slider-background.d.mts +14 -0
  42. package/dist/utils/get-slider-background.d.ts +14 -0
  43. package/dist/utils/get-slider-background.js +65 -0
  44. package/dist/utils/get-slider-background.mjs +40 -0
  45. package/dist/utils/is-valid-hex.d.mts +4 -0
  46. package/dist/utils/is-valid-hex.d.ts +4 -0
  47. package/dist/utils/is-valid-hex.js +40 -0
  48. package/dist/utils/is-valid-hex.mjs +14 -0
  49. package/package.json +20 -10
@@ -0,0 +1,636 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/color-picker.machine.ts
31
+ var color_picker_machine_exports = {};
32
+ __export(color_picker_machine_exports, {
33
+ machine: () => machine
34
+ });
35
+ module.exports = __toCommonJS(color_picker_machine_exports);
36
+ var import_color_utils = require("@zag-js/color-utils");
37
+ var import_core = require("@zag-js/core");
38
+ var import_dismissable = require("@zag-js/dismissable");
39
+ var import_dom_query = require("@zag-js/dom-query");
40
+ var import_popper = require("@zag-js/popper");
41
+ var import_utils = require("@zag-js/utils");
42
+ var dom = __toESM(require("./color-picker.dom.cjs"));
43
+ var import_color_picker = require("./color-picker.parse.cjs");
44
+ var import_get_channel_input_value = require("./utils/get-channel-input-value.cjs");
45
+ var import_is_valid_hex = require("./utils/is-valid-hex.cjs");
46
+ var { and } = (0, import_core.createGuards)();
47
+ var hashObject = (obj) => {
48
+ let hash = "";
49
+ for (const key in obj) hash += `${key}:${obj[key] ?? ""};`;
50
+ return hash;
51
+ };
52
+ var DEFAULT_COLOR = (0, import_color_picker.parse)("#000000");
53
+ var machine = (0, import_core.createMachine)({
54
+ props({ props }) {
55
+ const color = props.value ?? props.defaultValue ?? DEFAULT_COLOR;
56
+ return {
57
+ dir: "ltr",
58
+ defaultValue: DEFAULT_COLOR,
59
+ defaultFormat: color.getFormat(),
60
+ openAutoFocus: true,
61
+ ...props,
62
+ positioning: {
63
+ placement: "bottom",
64
+ ...props.positioning
65
+ }
66
+ };
67
+ },
68
+ initialState({ prop }) {
69
+ const open = prop("open") || prop("defaultOpen") || prop("inline");
70
+ return open ? "open" : "idle";
71
+ },
72
+ context({ prop, bindable, getContext }) {
73
+ return {
74
+ value: bindable(() => ({
75
+ defaultValue: prop("defaultValue"),
76
+ value: prop("value"),
77
+ isEqual(a, b) {
78
+ return b != null && a.isEqual(b);
79
+ },
80
+ hash(a) {
81
+ return hashObject(a.toJSON());
82
+ },
83
+ onChange(value) {
84
+ const ctx = getContext();
85
+ const format = ctx.get("format");
86
+ prop("onValueChange")?.({ value, valueAsString: value.toString(format) });
87
+ }
88
+ })),
89
+ format: bindable(() => ({
90
+ defaultValue: prop("defaultFormat"),
91
+ value: prop("format"),
92
+ onChange(format) {
93
+ prop("onFormatChange")?.({ format });
94
+ }
95
+ })),
96
+ activeId: bindable(() => ({ defaultValue: null })),
97
+ activeChannel: bindable(() => ({ defaultValue: null })),
98
+ activeOrientation: bindable(() => ({ defaultValue: null })),
99
+ fieldsetDisabled: bindable(() => ({ defaultValue: false })),
100
+ restoreFocus: bindable(() => ({ defaultValue: true })),
101
+ currentPlacement: bindable(() => ({
102
+ defaultValue: void 0
103
+ }))
104
+ };
105
+ },
106
+ computed: {
107
+ rtl: ({ prop }) => prop("dir") === "rtl",
108
+ disabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
109
+ interactive: ({ prop }) => !(prop("disabled") || prop("readOnly")),
110
+ valueAsString: ({ context }) => context.get("value").toString(context.get("format")),
111
+ areaValue: ({ context }) => {
112
+ const format = context.get("format").startsWith("hsl") ? "hsla" : "hsba";
113
+ return context.get("value").toFormat(format);
114
+ }
115
+ },
116
+ effects: ["trackFormControl"],
117
+ watch({ prop, context, action, track }) {
118
+ track([() => context.hash("value")], () => {
119
+ action(["syncInputElements", "dispatchChangeEvent"]);
120
+ });
121
+ track([() => context.get("format")], () => {
122
+ action(["syncFormatSelectElement", "syncValueWithFormat"]);
123
+ });
124
+ track([() => prop("open")], () => {
125
+ action(["toggleVisibility"]);
126
+ });
127
+ },
128
+ on: {
129
+ "VALUE.SET": {
130
+ actions: ["setValue"]
131
+ },
132
+ "FORMAT.SET": {
133
+ actions: ["setFormat"]
134
+ },
135
+ "CHANNEL_INPUT.CHANGE": {
136
+ actions: ["setChannelColorFromInput"]
137
+ },
138
+ "EYEDROPPER.CLICK": {
139
+ actions: ["openEyeDropper"]
140
+ },
141
+ "SWATCH_TRIGGER.CLICK": {
142
+ actions: ["setValue"]
143
+ }
144
+ },
145
+ states: {
146
+ idle: {
147
+ tags: ["closed"],
148
+ on: {
149
+ "CONTROLLED.OPEN": {
150
+ target: "open",
151
+ actions: ["setInitialFocus"]
152
+ },
153
+ OPEN: [
154
+ {
155
+ guard: "isOpenControlled",
156
+ actions: ["invokeOnOpen"]
157
+ },
158
+ {
159
+ target: "open",
160
+ actions: ["invokeOnOpen", "setInitialFocus"]
161
+ }
162
+ ],
163
+ "TRIGGER.CLICK": [
164
+ {
165
+ guard: "isOpenControlled",
166
+ actions: ["invokeOnOpen"]
167
+ },
168
+ {
169
+ target: "open",
170
+ actions: ["invokeOnOpen", "setInitialFocus"]
171
+ }
172
+ ],
173
+ "CHANNEL_INPUT.FOCUS": {
174
+ target: "focused",
175
+ actions: ["setActiveChannel"]
176
+ }
177
+ }
178
+ },
179
+ focused: {
180
+ tags: ["closed", "focused"],
181
+ on: {
182
+ "CONTROLLED.OPEN": {
183
+ target: "open",
184
+ actions: ["setInitialFocus"]
185
+ },
186
+ OPEN: [
187
+ {
188
+ guard: "isOpenControlled",
189
+ actions: ["invokeOnOpen"]
190
+ },
191
+ {
192
+ target: "open",
193
+ actions: ["invokeOnOpen", "setInitialFocus"]
194
+ }
195
+ ],
196
+ "TRIGGER.CLICK": [
197
+ {
198
+ guard: "isOpenControlled",
199
+ actions: ["invokeOnOpen"]
200
+ },
201
+ {
202
+ target: "open",
203
+ actions: ["invokeOnOpen", "setInitialFocus"]
204
+ }
205
+ ],
206
+ "CHANNEL_INPUT.FOCUS": {
207
+ actions: ["setActiveChannel"]
208
+ },
209
+ "CHANNEL_INPUT.BLUR": {
210
+ target: "idle",
211
+ actions: ["setChannelColorFromInput"]
212
+ },
213
+ "TRIGGER.BLUR": {
214
+ target: "idle"
215
+ }
216
+ }
217
+ },
218
+ open: {
219
+ tags: ["open"],
220
+ effects: ["trackPositioning", "trackDismissableElement"],
221
+ initial: "idle",
222
+ on: {
223
+ "CONTROLLED.CLOSE": [
224
+ {
225
+ guard: "shouldRestoreFocus",
226
+ target: "focused",
227
+ actions: ["setReturnFocus"]
228
+ },
229
+ {
230
+ target: "idle"
231
+ }
232
+ ],
233
+ INTERACT_OUTSIDE: [
234
+ {
235
+ guard: "isOpenControlled",
236
+ actions: ["invokeOnClose"]
237
+ },
238
+ {
239
+ guard: "shouldRestoreFocus",
240
+ target: "focused",
241
+ actions: ["invokeOnClose", "setReturnFocus"]
242
+ },
243
+ {
244
+ target: "idle",
245
+ actions: ["invokeOnClose"]
246
+ }
247
+ ],
248
+ CLOSE: [
249
+ {
250
+ guard: "isOpenControlled",
251
+ actions: ["invokeOnClose"]
252
+ },
253
+ {
254
+ target: "idle",
255
+ actions: ["invokeOnClose"]
256
+ }
257
+ ]
258
+ },
259
+ states: {
260
+ idle: {
261
+ on: {
262
+ "TRIGGER.CLICK": [
263
+ {
264
+ guard: "isOpenControlled",
265
+ actions: ["invokeOnClose"]
266
+ },
267
+ {
268
+ target: "idle",
269
+ actions: ["invokeOnClose"]
270
+ }
271
+ ],
272
+ "AREA.POINTER_DOWN": {
273
+ target: "dragging",
274
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
275
+ },
276
+ "AREA.FOCUS": {
277
+ actions: ["setActiveChannel"]
278
+ },
279
+ "CHANNEL_SLIDER.POINTER_DOWN": {
280
+ target: "dragging",
281
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
282
+ },
283
+ "CHANNEL_SLIDER.FOCUS": {
284
+ actions: ["setActiveChannel"]
285
+ },
286
+ "AREA.ARROW_LEFT": {
287
+ actions: ["decrementAreaXChannel"]
288
+ },
289
+ "AREA.ARROW_RIGHT": {
290
+ actions: ["incrementAreaXChannel"]
291
+ },
292
+ "AREA.ARROW_UP": {
293
+ actions: ["incrementAreaYChannel"]
294
+ },
295
+ "AREA.ARROW_DOWN": {
296
+ actions: ["decrementAreaYChannel"]
297
+ },
298
+ "AREA.PAGE_UP": {
299
+ actions: ["incrementAreaXChannel"]
300
+ },
301
+ "AREA.PAGE_DOWN": {
302
+ actions: ["decrementAreaXChannel"]
303
+ },
304
+ "CHANNEL_SLIDER.ARROW_LEFT": {
305
+ actions: ["decrementChannel"]
306
+ },
307
+ "CHANNEL_SLIDER.ARROW_RIGHT": {
308
+ actions: ["incrementChannel"]
309
+ },
310
+ "CHANNEL_SLIDER.ARROW_UP": {
311
+ actions: ["incrementChannel"]
312
+ },
313
+ "CHANNEL_SLIDER.ARROW_DOWN": {
314
+ actions: ["decrementChannel"]
315
+ },
316
+ "CHANNEL_SLIDER.PAGE_UP": {
317
+ actions: ["incrementChannel"]
318
+ },
319
+ "CHANNEL_SLIDER.PAGE_DOWN": {
320
+ actions: ["decrementChannel"]
321
+ },
322
+ "CHANNEL_SLIDER.HOME": {
323
+ actions: ["setChannelToMin"]
324
+ },
325
+ "CHANNEL_SLIDER.END": {
326
+ actions: ["setChannelToMax"]
327
+ },
328
+ "CHANNEL_INPUT.BLUR": {
329
+ actions: ["setChannelColorFromInput"]
330
+ },
331
+ "SWATCH_TRIGGER.CLICK": [
332
+ {
333
+ guard: and("isOpenControlled", "closeOnSelect"),
334
+ actions: ["setValue", "invokeOnClose"]
335
+ },
336
+ {
337
+ guard: "closeOnSelect",
338
+ target: "focused",
339
+ actions: ["setValue", "invokeOnClose", "setReturnFocus"]
340
+ },
341
+ {
342
+ actions: ["setValue"]
343
+ }
344
+ ]
345
+ }
346
+ },
347
+ dragging: {
348
+ tags: ["dragging"],
349
+ exit: ["clearActiveChannel"],
350
+ effects: ["trackPointerMove", "disableTextSelection"],
351
+ on: {
352
+ "AREA.POINTER_MOVE": {
353
+ actions: ["setAreaColorFromPoint", "focusAreaThumb"]
354
+ },
355
+ "AREA.POINTER_UP": {
356
+ target: "idle",
357
+ actions: ["invokeOnChangeEnd"]
358
+ },
359
+ "CHANNEL_SLIDER.POINTER_MOVE": {
360
+ actions: ["setChannelColorFromPoint", "focusChannelThumb"]
361
+ },
362
+ "CHANNEL_SLIDER.POINTER_UP": {
363
+ target: "idle",
364
+ actions: ["invokeOnChangeEnd"]
365
+ }
366
+ }
367
+ }
368
+ }
369
+ }
370
+ },
371
+ implementations: {
372
+ guards: {
373
+ closeOnSelect: ({ prop }) => !!prop("closeOnSelect"),
374
+ isOpenControlled: ({ prop }) => prop("open") != null || !!prop("inline"),
375
+ shouldRestoreFocus: ({ context }) => !!context.get("restoreFocus")
376
+ },
377
+ effects: {
378
+ trackPositioning({ context, prop, scope }) {
379
+ if (prop("inline")) return;
380
+ if (!context.get("currentPlacement")) {
381
+ context.set("currentPlacement", prop("positioning")?.placement);
382
+ }
383
+ const anchorEl = dom.getTriggerEl(scope);
384
+ const getPositionerEl2 = () => dom.getPositionerEl(scope);
385
+ return (0, import_popper.getPlacement)(anchorEl, getPositionerEl2, {
386
+ ...prop("positioning"),
387
+ defer: true,
388
+ onComplete(data) {
389
+ context.set("currentPlacement", data.placement);
390
+ }
391
+ });
392
+ },
393
+ trackDismissableElement({ context, scope, prop, send }) {
394
+ if (prop("inline")) return;
395
+ const getContentEl2 = () => dom.getContentEl(scope);
396
+ return (0, import_dismissable.trackDismissableElement)(getContentEl2, {
397
+ type: "popover",
398
+ exclude: dom.getTriggerEl(scope),
399
+ defer: true,
400
+ onInteractOutside(event) {
401
+ prop("onInteractOutside")?.(event);
402
+ if (event.defaultPrevented) return;
403
+ context.set("restoreFocus", !(event.detail.focusable || event.detail.contextmenu));
404
+ },
405
+ onPointerDownOutside: prop("onPointerDownOutside"),
406
+ onFocusOutside: prop("onFocusOutside"),
407
+ onDismiss() {
408
+ send({ type: "INTERACT_OUTSIDE" });
409
+ }
410
+ });
411
+ },
412
+ trackFormControl({ context, scope, send }) {
413
+ const inputEl = dom.getHiddenInputEl(scope);
414
+ return (0, import_dom_query.trackFormControl)(inputEl, {
415
+ onFieldsetDisabledChange(disabled) {
416
+ context.set("fieldsetDisabled", disabled);
417
+ },
418
+ onFormReset() {
419
+ send({ type: "VALUE.SET", value: context.initial("value"), src: "form.reset" });
420
+ }
421
+ });
422
+ },
423
+ trackPointerMove({ context, scope, event, send }) {
424
+ return (0, import_dom_query.trackPointerMove)(scope.getDoc(), {
425
+ onPointerMove({ point }) {
426
+ const type = context.get("activeId") === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
427
+ send({ type, point, format: event.format });
428
+ },
429
+ onPointerUp() {
430
+ const type = context.get("activeId") === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
431
+ send({ type });
432
+ }
433
+ });
434
+ },
435
+ disableTextSelection({ scope }) {
436
+ return (0, import_dom_query.disableTextSelection)({
437
+ doc: scope.getDoc(),
438
+ target: dom.getContentEl(scope)
439
+ });
440
+ }
441
+ },
442
+ actions: {
443
+ openEyeDropper({ scope, context }) {
444
+ const win = scope.getWin();
445
+ const isSupported = "EyeDropper" in win;
446
+ if (!isSupported) return;
447
+ const picker = new win.EyeDropper();
448
+ picker.open().then(({ sRGBHex }) => {
449
+ const format = context.get("value").getFormat();
450
+ const color = (0, import_color_utils.parseColor)(sRGBHex).toFormat(format);
451
+ context.set("value", color);
452
+ }).catch(() => void 0);
453
+ },
454
+ setActiveChannel({ context, event }) {
455
+ context.set("activeId", event.id);
456
+ if (event.channel) context.set("activeChannel", event.channel);
457
+ if (event.orientation) context.set("activeOrientation", event.orientation);
458
+ },
459
+ clearActiveChannel({ context }) {
460
+ context.set("activeChannel", null);
461
+ context.set("activeId", null);
462
+ context.set("activeOrientation", null);
463
+ },
464
+ setAreaColorFromPoint({ context, event, computed, scope, prop }) {
465
+ const v = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
466
+ const { xChannel, yChannel } = event.channel || context.get("activeChannel");
467
+ const percent = dom.getAreaValueFromPoint(scope, event.point, prop("dir"));
468
+ if (!percent) return;
469
+ const xValue = v.getChannelPercentValue(xChannel, percent.x);
470
+ const yValue = v.getChannelPercentValue(yChannel, 1 - percent.y);
471
+ const color = v.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
472
+ context.set("value", color);
473
+ },
474
+ setChannelColorFromPoint({ context, event, computed, scope, prop }) {
475
+ const channel = event.channel || context.get("activeId");
476
+ const normalizedValue = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
477
+ const percent = dom.getChannelSliderValueFromPoint(scope, event.point, channel, prop("dir"));
478
+ if (!percent) return;
479
+ const orientation = context.get("activeOrientation") || "horizontal";
480
+ const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
481
+ const value = normalizedValue.getChannelPercentValue(channel, channelPercent);
482
+ const color = normalizedValue.withChannelValue(channel, value);
483
+ context.set("value", color);
484
+ },
485
+ setValue({ context, event }) {
486
+ context.set("value", event.value);
487
+ },
488
+ setFormat({ context, event }) {
489
+ context.set("format", event.format);
490
+ },
491
+ dispatchChangeEvent({ scope, computed }) {
492
+ (0, import_dom_query.dispatchInputValueEvent)(dom.getHiddenInputEl(scope), { value: computed("valueAsString") });
493
+ },
494
+ syncInputElements({ context, scope }) {
495
+ syncChannelInputs(scope, context.get("value"));
496
+ },
497
+ invokeOnChangeEnd({ context, prop, computed }) {
498
+ prop("onValueChangeEnd")?.({
499
+ value: context.get("value"),
500
+ valueAsString: computed("valueAsString")
501
+ });
502
+ },
503
+ setChannelColorFromInput({ context, event, scope, prop }) {
504
+ const { channel, isTextField, value } = event;
505
+ const currentAlpha = context.get("value").getChannelValue("alpha");
506
+ let color;
507
+ if (channel === "alpha") {
508
+ let valueAsNumber = parseFloat(value);
509
+ valueAsNumber = Number.isNaN(valueAsNumber) ? currentAlpha : valueAsNumber;
510
+ color = context.get("value").withChannelValue("alpha", valueAsNumber);
511
+ } else if (isTextField) {
512
+ color = (0, import_utils.tryCatch)(
513
+ () => {
514
+ const parseValue = channel === "hex" ? (0, import_is_valid_hex.prefixHex)(value) : value;
515
+ return (0, import_color_picker.parse)(parseValue).withChannelValue("alpha", currentAlpha);
516
+ },
517
+ () => context.get("value")
518
+ );
519
+ } else {
520
+ const current = context.get("value").toFormat(context.get("format"));
521
+ const valueAsNumber = Number.isNaN(value) ? current.getChannelValue(channel) : value;
522
+ color = current.withChannelValue(channel, valueAsNumber);
523
+ }
524
+ syncChannelInputs(scope, context.get("value"), color);
525
+ context.set("value", color);
526
+ prop("onValueChangeEnd")?.({
527
+ value: color,
528
+ valueAsString: color.toString(context.get("format"))
529
+ });
530
+ },
531
+ incrementChannel({ context, event }) {
532
+ const color = context.get("value").incrementChannel(event.channel, event.step);
533
+ context.set("value", color);
534
+ },
535
+ decrementChannel({ context, event }) {
536
+ const color = context.get("value").decrementChannel(event.channel, event.step);
537
+ context.set("value", color);
538
+ },
539
+ incrementAreaXChannel({ context, event, computed }) {
540
+ const { xChannel } = event.channel;
541
+ const color = computed("areaValue").incrementChannel(xChannel, event.step);
542
+ context.set("value", color);
543
+ },
544
+ decrementAreaXChannel({ context, event, computed }) {
545
+ const { xChannel } = event.channel;
546
+ const color = computed("areaValue").decrementChannel(xChannel, event.step);
547
+ context.set("value", color);
548
+ },
549
+ incrementAreaYChannel({ context, event, computed }) {
550
+ const { yChannel } = event.channel;
551
+ const color = computed("areaValue").incrementChannel(yChannel, event.step);
552
+ context.set("value", color);
553
+ },
554
+ decrementAreaYChannel({ context, event, computed }) {
555
+ const { yChannel } = event.channel;
556
+ const color = computed("areaValue").decrementChannel(yChannel, event.step);
557
+ context.set("value", color);
558
+ },
559
+ setChannelToMax({ context, event }) {
560
+ const value = context.get("value");
561
+ const range = value.getChannelRange(event.channel);
562
+ const color = value.withChannelValue(event.channel, range.maxValue);
563
+ context.set("value", color);
564
+ },
565
+ setChannelToMin({ context, event }) {
566
+ const value = context.get("value");
567
+ const range = value.getChannelRange(event.channel);
568
+ const color = value.withChannelValue(event.channel, range.minValue);
569
+ context.set("value", color);
570
+ },
571
+ focusAreaThumb({ scope }) {
572
+ (0, import_dom_query.raf)(() => {
573
+ dom.getAreaThumbEl(scope)?.focus({ preventScroll: true });
574
+ });
575
+ },
576
+ focusChannelThumb({ event, scope }) {
577
+ (0, import_dom_query.raf)(() => {
578
+ dom.getChannelSliderThumbEl(scope, event.channel)?.focus({ preventScroll: true });
579
+ });
580
+ },
581
+ setInitialFocus({ prop, scope }) {
582
+ if (!prop("openAutoFocus")) return;
583
+ (0, import_dom_query.raf)(() => {
584
+ const element = (0, import_dom_query.getInitialFocus)({
585
+ root: dom.getContentEl(scope),
586
+ getInitialEl: prop("initialFocusEl")
587
+ });
588
+ element?.focus({ preventScroll: true });
589
+ });
590
+ },
591
+ setReturnFocus({ scope }) {
592
+ (0, import_dom_query.raf)(() => {
593
+ dom.getTriggerEl(scope)?.focus({ preventScroll: true });
594
+ });
595
+ },
596
+ syncFormatSelectElement({ context, scope }) {
597
+ syncFormatSelect(scope, context.get("format"));
598
+ },
599
+ syncValueWithFormat({ context }) {
600
+ const value = context.get("value");
601
+ const newValue = value.toFormat(context.get("format"));
602
+ if (newValue.isEqual(value)) return;
603
+ context.set("value", newValue);
604
+ },
605
+ invokeOnOpen({ prop, context }) {
606
+ if (prop("inline")) return;
607
+ prop("onOpenChange")?.({ open: true, value: context.get("value") });
608
+ },
609
+ invokeOnClose({ prop, context }) {
610
+ if (prop("inline")) return;
611
+ prop("onOpenChange")?.({ open: false, value: context.get("value") });
612
+ },
613
+ toggleVisibility({ prop, event, send }) {
614
+ send({ type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: event });
615
+ }
616
+ }
617
+ }
618
+ });
619
+ function syncChannelInputs(scope, currentValue, nextValue) {
620
+ const channelInputEls = dom.getChannelInputEls(scope);
621
+ (0, import_dom_query.raf)(() => {
622
+ channelInputEls.forEach((inputEl) => {
623
+ const channel = inputEl.dataset.channel;
624
+ (0, import_dom_query.setElementValue)(inputEl, (0, import_get_channel_input_value.getChannelValue)(nextValue || currentValue, channel));
625
+ });
626
+ });
627
+ }
628
+ function syncFormatSelect(scope, format) {
629
+ const selectEl = dom.getFormatSelectEl(scope);
630
+ if (!selectEl) return;
631
+ (0, import_dom_query.raf)(() => (0, import_dom_query.setElementValue)(selectEl, format));
632
+ }
633
+ // Annotate the CommonJS export names for ESM import in node:
634
+ 0 && (module.exports = {
635
+ machine
636
+ });