@zag-js/color-picker 1.34.1 → 1.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/color-picker.anatomy.d.mts +6 -0
  2. package/dist/color-picker.anatomy.d.ts +6 -0
  3. package/dist/color-picker.anatomy.js +59 -0
  4. package/dist/color-picker.anatomy.mjs +33 -0
  5. package/dist/color-picker.connect.d.mts +10 -0
  6. package/dist/color-picker.connect.d.ts +10 -0
  7. package/dist/color-picker.connect.js +681 -0
  8. package/dist/color-picker.connect.mjs +646 -0
  9. package/dist/color-picker.dom.d.mts +39 -0
  10. package/dist/color-picker.dom.d.ts +39 -0
  11. package/dist/color-picker.dom.js +136 -0
  12. package/dist/color-picker.dom.mjs +85 -0
  13. package/dist/color-picker.machine.d.mts +10 -0
  14. package/dist/color-picker.machine.d.ts +10 -0
  15. package/dist/color-picker.machine.js +637 -0
  16. package/dist/color-picker.machine.mjs +610 -0
  17. package/dist/color-picker.parse.d.mts +5 -0
  18. package/dist/color-picker.parse.d.ts +5 -0
  19. package/dist/color-picker.parse.js +33 -0
  20. package/dist/color-picker.parse.mjs +8 -0
  21. package/dist/color-picker.props.d.mts +21 -0
  22. package/dist/color-picker.props.d.ts +21 -0
  23. package/dist/color-picker.props.js +94 -0
  24. package/dist/color-picker.props.mjs +58 -0
  25. package/dist/color-picker.types.d.mts +303 -0
  26. package/dist/color-picker.types.d.ts +303 -0
  27. package/dist/color-picker.types.js +18 -0
  28. package/dist/color-picker.types.mjs +0 -0
  29. package/dist/index.d.mts +9 -324
  30. package/dist/index.d.ts +9 -324
  31. package/dist/index.js +37 -1517
  32. package/dist/index.mjs +11 -1504
  33. package/dist/utils/get-channel-display-color.d.mts +5 -0
  34. package/dist/utils/get-channel-display-color.d.ts +5 -0
  35. package/dist/utils/get-channel-display-color.js +48 -0
  36. package/dist/utils/get-channel-display-color.mjs +23 -0
  37. package/dist/utils/get-channel-input-value.d.mts +11 -0
  38. package/dist/utils/get-channel-input-value.d.ts +11 -0
  39. package/dist/utils/get-channel-input-value.js +88 -0
  40. package/dist/utils/get-channel-input-value.mjs +62 -0
  41. package/dist/utils/get-slider-background.d.mts +14 -0
  42. package/dist/utils/get-slider-background.d.ts +14 -0
  43. package/dist/utils/get-slider-background.js +65 -0
  44. package/dist/utils/get-slider-background.mjs +40 -0
  45. package/dist/utils/is-valid-hex.d.mts +4 -0
  46. package/dist/utils/is-valid-hex.d.ts +4 -0
  47. package/dist/utils/is-valid-hex.js +40 -0
  48. package/dist/utils/is-valid-hex.mjs +14 -0
  49. package/package.json +20 -10
@@ -0,0 +1,637 @@
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
+ id: "color-picker-focused",
181
+ tags: ["closed", "focused"],
182
+ on: {
183
+ "CONTROLLED.OPEN": {
184
+ target: "open",
185
+ actions: ["setInitialFocus"]
186
+ },
187
+ OPEN: [
188
+ {
189
+ guard: "isOpenControlled",
190
+ actions: ["invokeOnOpen"]
191
+ },
192
+ {
193
+ target: "open",
194
+ actions: ["invokeOnOpen", "setInitialFocus"]
195
+ }
196
+ ],
197
+ "TRIGGER.CLICK": [
198
+ {
199
+ guard: "isOpenControlled",
200
+ actions: ["invokeOnOpen"]
201
+ },
202
+ {
203
+ target: "open",
204
+ actions: ["invokeOnOpen", "setInitialFocus"]
205
+ }
206
+ ],
207
+ "CHANNEL_INPUT.FOCUS": {
208
+ actions: ["setActiveChannel"]
209
+ },
210
+ "CHANNEL_INPUT.BLUR": {
211
+ target: "idle",
212
+ actions: ["setChannelColorFromInput"]
213
+ },
214
+ "TRIGGER.BLUR": {
215
+ target: "idle"
216
+ }
217
+ }
218
+ },
219
+ open: {
220
+ tags: ["open"],
221
+ effects: ["trackPositioning", "trackDismissableElement"],
222
+ initial: "idle",
223
+ on: {
224
+ "CONTROLLED.CLOSE": [
225
+ {
226
+ guard: "shouldRestoreFocus",
227
+ target: "focused",
228
+ actions: ["setReturnFocus"]
229
+ },
230
+ {
231
+ target: "idle"
232
+ }
233
+ ],
234
+ INTERACT_OUTSIDE: [
235
+ {
236
+ guard: "isOpenControlled",
237
+ actions: ["invokeOnClose"]
238
+ },
239
+ {
240
+ guard: "shouldRestoreFocus",
241
+ target: "focused",
242
+ actions: ["invokeOnClose", "setReturnFocus"]
243
+ },
244
+ {
245
+ target: "idle",
246
+ actions: ["invokeOnClose"]
247
+ }
248
+ ],
249
+ CLOSE: [
250
+ {
251
+ guard: "isOpenControlled",
252
+ actions: ["invokeOnClose"]
253
+ },
254
+ {
255
+ target: "idle",
256
+ actions: ["invokeOnClose"]
257
+ }
258
+ ]
259
+ },
260
+ states: {
261
+ idle: {
262
+ on: {
263
+ "TRIGGER.CLICK": [
264
+ {
265
+ guard: "isOpenControlled",
266
+ actions: ["invokeOnClose"]
267
+ },
268
+ {
269
+ target: "#color-picker-focused",
270
+ actions: ["invokeOnClose"]
271
+ }
272
+ ],
273
+ "AREA.POINTER_DOWN": {
274
+ target: "dragging",
275
+ actions: ["setActiveChannel", "setAreaColorFromPoint", "focusAreaThumb"]
276
+ },
277
+ "AREA.FOCUS": {
278
+ actions: ["setActiveChannel"]
279
+ },
280
+ "CHANNEL_SLIDER.POINTER_DOWN": {
281
+ target: "dragging",
282
+ actions: ["setActiveChannel", "setChannelColorFromPoint", "focusChannelThumb"]
283
+ },
284
+ "CHANNEL_SLIDER.FOCUS": {
285
+ actions: ["setActiveChannel"]
286
+ },
287
+ "AREA.ARROW_LEFT": {
288
+ actions: ["decrementAreaXChannel"]
289
+ },
290
+ "AREA.ARROW_RIGHT": {
291
+ actions: ["incrementAreaXChannel"]
292
+ },
293
+ "AREA.ARROW_UP": {
294
+ actions: ["incrementAreaYChannel"]
295
+ },
296
+ "AREA.ARROW_DOWN": {
297
+ actions: ["decrementAreaYChannel"]
298
+ },
299
+ "AREA.PAGE_UP": {
300
+ actions: ["incrementAreaXChannel"]
301
+ },
302
+ "AREA.PAGE_DOWN": {
303
+ actions: ["decrementAreaXChannel"]
304
+ },
305
+ "CHANNEL_SLIDER.ARROW_LEFT": {
306
+ actions: ["decrementChannel"]
307
+ },
308
+ "CHANNEL_SLIDER.ARROW_RIGHT": {
309
+ actions: ["incrementChannel"]
310
+ },
311
+ "CHANNEL_SLIDER.ARROW_UP": {
312
+ actions: ["incrementChannel"]
313
+ },
314
+ "CHANNEL_SLIDER.ARROW_DOWN": {
315
+ actions: ["decrementChannel"]
316
+ },
317
+ "CHANNEL_SLIDER.PAGE_UP": {
318
+ actions: ["incrementChannel"]
319
+ },
320
+ "CHANNEL_SLIDER.PAGE_DOWN": {
321
+ actions: ["decrementChannel"]
322
+ },
323
+ "CHANNEL_SLIDER.HOME": {
324
+ actions: ["setChannelToMin"]
325
+ },
326
+ "CHANNEL_SLIDER.END": {
327
+ actions: ["setChannelToMax"]
328
+ },
329
+ "CHANNEL_INPUT.BLUR": {
330
+ actions: ["setChannelColorFromInput"]
331
+ },
332
+ "SWATCH_TRIGGER.CLICK": [
333
+ {
334
+ guard: and("isOpenControlled", "closeOnSelect"),
335
+ actions: ["setValue", "invokeOnClose"]
336
+ },
337
+ {
338
+ guard: "closeOnSelect",
339
+ target: "focused",
340
+ actions: ["setValue", "invokeOnClose", "setReturnFocus"]
341
+ },
342
+ {
343
+ actions: ["setValue"]
344
+ }
345
+ ]
346
+ }
347
+ },
348
+ dragging: {
349
+ tags: ["dragging"],
350
+ exit: ["clearActiveChannel"],
351
+ effects: ["trackPointerMove", "disableTextSelection"],
352
+ on: {
353
+ "AREA.POINTER_MOVE": {
354
+ actions: ["setAreaColorFromPoint", "focusAreaThumb"]
355
+ },
356
+ "AREA.POINTER_UP": {
357
+ target: "idle",
358
+ actions: ["invokeOnChangeEnd"]
359
+ },
360
+ "CHANNEL_SLIDER.POINTER_MOVE": {
361
+ actions: ["setChannelColorFromPoint", "focusChannelThumb"]
362
+ },
363
+ "CHANNEL_SLIDER.POINTER_UP": {
364
+ target: "idle",
365
+ actions: ["invokeOnChangeEnd"]
366
+ }
367
+ }
368
+ }
369
+ }
370
+ }
371
+ },
372
+ implementations: {
373
+ guards: {
374
+ closeOnSelect: ({ prop }) => !!prop("closeOnSelect"),
375
+ isOpenControlled: ({ prop }) => prop("open") != null || !!prop("inline"),
376
+ shouldRestoreFocus: ({ context }) => !!context.get("restoreFocus")
377
+ },
378
+ effects: {
379
+ trackPositioning({ context, prop, scope }) {
380
+ if (prop("inline")) return;
381
+ if (!context.get("currentPlacement")) {
382
+ context.set("currentPlacement", prop("positioning")?.placement);
383
+ }
384
+ const anchorEl = dom.getTriggerEl(scope);
385
+ const getPositionerEl2 = () => dom.getPositionerEl(scope);
386
+ return (0, import_popper.getPlacement)(anchorEl, getPositionerEl2, {
387
+ ...prop("positioning"),
388
+ defer: true,
389
+ onComplete(data) {
390
+ context.set("currentPlacement", data.placement);
391
+ }
392
+ });
393
+ },
394
+ trackDismissableElement({ context, scope, prop, send }) {
395
+ if (prop("inline")) return;
396
+ const getContentEl2 = () => dom.getContentEl(scope);
397
+ return (0, import_dismissable.trackDismissableElement)(getContentEl2, {
398
+ type: "popover",
399
+ exclude: dom.getTriggerEl(scope),
400
+ defer: true,
401
+ onInteractOutside(event) {
402
+ prop("onInteractOutside")?.(event);
403
+ if (event.defaultPrevented) return;
404
+ context.set("restoreFocus", !(event.detail.focusable || event.detail.contextmenu));
405
+ },
406
+ onPointerDownOutside: prop("onPointerDownOutside"),
407
+ onFocusOutside: prop("onFocusOutside"),
408
+ onDismiss() {
409
+ send({ type: "INTERACT_OUTSIDE" });
410
+ }
411
+ });
412
+ },
413
+ trackFormControl({ context, scope, send }) {
414
+ const inputEl = dom.getHiddenInputEl(scope);
415
+ return (0, import_dom_query.trackFormControl)(inputEl, {
416
+ onFieldsetDisabledChange(disabled) {
417
+ context.set("fieldsetDisabled", disabled);
418
+ },
419
+ onFormReset() {
420
+ send({ type: "VALUE.SET", value: context.initial("value"), src: "form.reset" });
421
+ }
422
+ });
423
+ },
424
+ trackPointerMove({ context, scope, event, send }) {
425
+ return (0, import_dom_query.trackPointerMove)(scope.getDoc(), {
426
+ onPointerMove({ point }) {
427
+ const type = context.get("activeId") === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
428
+ send({ type, point, format: event.format });
429
+ },
430
+ onPointerUp() {
431
+ const type = context.get("activeId") === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
432
+ send({ type });
433
+ }
434
+ });
435
+ },
436
+ disableTextSelection({ scope }) {
437
+ return (0, import_dom_query.disableTextSelection)({
438
+ doc: scope.getDoc(),
439
+ target: dom.getContentEl(scope)
440
+ });
441
+ }
442
+ },
443
+ actions: {
444
+ openEyeDropper({ scope, context }) {
445
+ const win = scope.getWin();
446
+ const isSupported = "EyeDropper" in win;
447
+ if (!isSupported) return;
448
+ const picker = new win.EyeDropper();
449
+ picker.open().then(({ sRGBHex }) => {
450
+ const format = context.get("value").getFormat();
451
+ const color = (0, import_color_utils.parseColor)(sRGBHex).toFormat(format);
452
+ context.set("value", color);
453
+ }).catch(() => void 0);
454
+ },
455
+ setActiveChannel({ context, event }) {
456
+ context.set("activeId", event.id);
457
+ if (event.channel) context.set("activeChannel", event.channel);
458
+ if (event.orientation) context.set("activeOrientation", event.orientation);
459
+ },
460
+ clearActiveChannel({ context }) {
461
+ context.set("activeChannel", null);
462
+ context.set("activeId", null);
463
+ context.set("activeOrientation", null);
464
+ },
465
+ setAreaColorFromPoint({ context, event, computed, scope, prop }) {
466
+ const v = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
467
+ const { xChannel, yChannel } = event.channel || context.get("activeChannel");
468
+ const percent = dom.getAreaValueFromPoint(scope, event.point, prop("dir"));
469
+ if (!percent) return;
470
+ const xValue = v.getChannelPercentValue(xChannel, percent.x);
471
+ const yValue = v.getChannelPercentValue(yChannel, 1 - percent.y);
472
+ const color = v.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
473
+ context.set("value", color);
474
+ },
475
+ setChannelColorFromPoint({ context, event, computed, scope, prop }) {
476
+ const channel = event.channel || context.get("activeId");
477
+ const normalizedValue = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
478
+ const percent = dom.getChannelSliderValueFromPoint(scope, event.point, channel, prop("dir"));
479
+ if (!percent) return;
480
+ const orientation = context.get("activeOrientation") || "horizontal";
481
+ const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
482
+ const value = normalizedValue.getChannelPercentValue(channel, channelPercent);
483
+ const color = normalizedValue.withChannelValue(channel, value);
484
+ context.set("value", color);
485
+ },
486
+ setValue({ context, event }) {
487
+ context.set("value", event.value);
488
+ },
489
+ setFormat({ context, event }) {
490
+ context.set("format", event.format);
491
+ },
492
+ dispatchChangeEvent({ scope, computed }) {
493
+ (0, import_dom_query.dispatchInputValueEvent)(dom.getHiddenInputEl(scope), { value: computed("valueAsString") });
494
+ },
495
+ syncInputElements({ context, scope }) {
496
+ syncChannelInputs(scope, context.get("value"));
497
+ },
498
+ invokeOnChangeEnd({ context, prop, computed }) {
499
+ prop("onValueChangeEnd")?.({
500
+ value: context.get("value"),
501
+ valueAsString: computed("valueAsString")
502
+ });
503
+ },
504
+ setChannelColorFromInput({ context, event, scope, prop }) {
505
+ const { channel, isTextField, value } = event;
506
+ const currentAlpha = context.get("value").getChannelValue("alpha");
507
+ let color;
508
+ if (channel === "alpha") {
509
+ let valueAsNumber = parseFloat(value);
510
+ valueAsNumber = Number.isNaN(valueAsNumber) ? currentAlpha : valueAsNumber;
511
+ color = context.get("value").withChannelValue("alpha", valueAsNumber);
512
+ } else if (isTextField) {
513
+ color = (0, import_utils.tryCatch)(
514
+ () => {
515
+ const parseValue = channel === "hex" ? (0, import_is_valid_hex.prefixHex)(value) : value;
516
+ return (0, import_color_picker.parse)(parseValue).withChannelValue("alpha", currentAlpha);
517
+ },
518
+ () => context.get("value")
519
+ );
520
+ } else {
521
+ const current = context.get("value").toFormat(context.get("format"));
522
+ const valueAsNumber = Number.isNaN(value) ? current.getChannelValue(channel) : value;
523
+ color = current.withChannelValue(channel, valueAsNumber);
524
+ }
525
+ syncChannelInputs(scope, context.get("value"), color);
526
+ context.set("value", color);
527
+ prop("onValueChangeEnd")?.({
528
+ value: color,
529
+ valueAsString: color.toString(context.get("format"))
530
+ });
531
+ },
532
+ incrementChannel({ context, event }) {
533
+ const color = context.get("value").incrementChannel(event.channel, event.step);
534
+ context.set("value", color);
535
+ },
536
+ decrementChannel({ context, event }) {
537
+ const color = context.get("value").decrementChannel(event.channel, event.step);
538
+ context.set("value", color);
539
+ },
540
+ incrementAreaXChannel({ context, event, computed }) {
541
+ const { xChannel } = event.channel;
542
+ const color = computed("areaValue").incrementChannel(xChannel, event.step);
543
+ context.set("value", color);
544
+ },
545
+ decrementAreaXChannel({ context, event, computed }) {
546
+ const { xChannel } = event.channel;
547
+ const color = computed("areaValue").decrementChannel(xChannel, event.step);
548
+ context.set("value", color);
549
+ },
550
+ incrementAreaYChannel({ context, event, computed }) {
551
+ const { yChannel } = event.channel;
552
+ const color = computed("areaValue").incrementChannel(yChannel, event.step);
553
+ context.set("value", color);
554
+ },
555
+ decrementAreaYChannel({ context, event, computed }) {
556
+ const { yChannel } = event.channel;
557
+ const color = computed("areaValue").decrementChannel(yChannel, event.step);
558
+ context.set("value", color);
559
+ },
560
+ setChannelToMax({ context, event }) {
561
+ const value = context.get("value");
562
+ const range = value.getChannelRange(event.channel);
563
+ const color = value.withChannelValue(event.channel, range.maxValue);
564
+ context.set("value", color);
565
+ },
566
+ setChannelToMin({ context, event }) {
567
+ const value = context.get("value");
568
+ const range = value.getChannelRange(event.channel);
569
+ const color = value.withChannelValue(event.channel, range.minValue);
570
+ context.set("value", color);
571
+ },
572
+ focusAreaThumb({ scope }) {
573
+ (0, import_dom_query.raf)(() => {
574
+ dom.getAreaThumbEl(scope)?.focus({ preventScroll: true });
575
+ });
576
+ },
577
+ focusChannelThumb({ event, scope }) {
578
+ (0, import_dom_query.raf)(() => {
579
+ dom.getChannelSliderThumbEl(scope, event.channel)?.focus({ preventScroll: true });
580
+ });
581
+ },
582
+ setInitialFocus({ prop, scope }) {
583
+ if (!prop("openAutoFocus")) return;
584
+ (0, import_dom_query.raf)(() => {
585
+ const element = (0, import_dom_query.getInitialFocus)({
586
+ root: dom.getContentEl(scope),
587
+ getInitialEl: prop("initialFocusEl")
588
+ });
589
+ element?.focus({ preventScroll: true });
590
+ });
591
+ },
592
+ setReturnFocus({ scope }) {
593
+ (0, import_dom_query.raf)(() => {
594
+ dom.getTriggerEl(scope)?.focus({ preventScroll: true });
595
+ });
596
+ },
597
+ syncFormatSelectElement({ context, scope }) {
598
+ syncFormatSelect(scope, context.get("format"));
599
+ },
600
+ syncValueWithFormat({ context }) {
601
+ const value = context.get("value");
602
+ const newValue = value.toFormat(context.get("format"));
603
+ if (newValue.isEqual(value)) return;
604
+ context.set("value", newValue);
605
+ },
606
+ invokeOnOpen({ prop, context }) {
607
+ if (prop("inline")) return;
608
+ prop("onOpenChange")?.({ open: true, value: context.get("value") });
609
+ },
610
+ invokeOnClose({ prop, context }) {
611
+ if (prop("inline")) return;
612
+ prop("onOpenChange")?.({ open: false, value: context.get("value") });
613
+ },
614
+ toggleVisibility({ prop, event, send }) {
615
+ send({ type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: event });
616
+ }
617
+ }
618
+ }
619
+ });
620
+ function syncChannelInputs(scope, currentValue, nextValue) {
621
+ const channelInputEls = dom.getChannelInputEls(scope);
622
+ (0, import_dom_query.raf)(() => {
623
+ channelInputEls.forEach((inputEl) => {
624
+ const channel = inputEl.dataset.channel;
625
+ (0, import_dom_query.setElementValue)(inputEl, (0, import_get_channel_input_value.getChannelValue)(nextValue || currentValue, channel));
626
+ });
627
+ });
628
+ }
629
+ function syncFormatSelect(scope, format) {
630
+ const selectEl = dom.getFormatSelectEl(scope);
631
+ if (!selectEl) return;
632
+ (0, import_dom_query.raf)(() => (0, import_dom_query.setElementValue)(selectEl, format));
633
+ }
634
+ // Annotate the CommonJS export names for ESM import in node:
635
+ 0 && (module.exports = {
636
+ machine
637
+ });