@zag-js/color-picker 0.13.0 → 0.15.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.
package/dist/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { Orientation, PropTypes, RequiredBy, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
2
+ import { Orientation, RequiredBy, PropTypes, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
3
3
  import { ColorChannel, Color, ColorFormat, ColorAxes } from '@zag-js/color-utils';
4
4
  export { Color, ColorAxes, ColorChannel, ColorFormat, ColorType } from '@zag-js/color-utils';
5
5
  import * as _zag_js_core from '@zag-js/core';
6
6
  import { StateMachine } from '@zag-js/core';
7
7
 
8
- declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBg" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBg" | "content" | "label" | "eyeDropTrigger">;
8
+ declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBackground" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBackground" | "content" | "label" | "eyeDropperTrigger">;
9
9
 
10
10
  type ColorChannelProps = {
11
11
  channel: ColorChannel;
@@ -37,6 +37,7 @@ type ElementIds = Partial<{
37
37
  channelSliderTrack(id: ColorChannel): string;
38
38
  channelSliderThumb(id: ColorChannel): string;
39
39
  }>;
40
+
40
41
  type PublicContext = CommonProperties & {
41
42
  /**
42
43
  * The ids of the elements in the color picker. Useful for composition.
@@ -66,7 +67,46 @@ type PublicContext = CommonProperties & {
66
67
  * Handler that is called when the user stops dragging.
67
68
  */
68
69
  onChangeEnd?: (details: ChangeDetails) => void;
70
+ /**
71
+ * The name for the form input
72
+ */
73
+ name?: string;
69
74
  };
75
+ type PrivateContext = Context<{
76
+ /**
77
+ * The id of the thumb that is currently being dragged
78
+ */
79
+ activeId: string | null;
80
+ /**
81
+ * The channel that is currently being interacted with
82
+ */
83
+ activeChannel: Partial<ColorAxes> | null;
84
+ /**
85
+ * The orientation of the channel that is currently being interacted with
86
+ */
87
+ activeOrientation: Orientation | null;
88
+ }>;
89
+ type ComputedContext = Readonly<{
90
+ /**
91
+ * Whether the color picker is in RTL mode
92
+ */
93
+ isRtl: boolean;
94
+ /**
95
+ * Whether the color picker is interactive
96
+ */
97
+ isInteractive: boolean;
98
+ /**
99
+ * The color value as a Color object
100
+ */
101
+ valueAsColor: Color;
102
+ }>;
103
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
104
+ type MachineContext = PublicContext & PrivateContext & ComputedContext;
105
+ type MachineState = {
106
+ value: "idle" | "focused" | "dragging";
107
+ };
108
+ type State = StateMachine.State<MachineContext, MachineState>;
109
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
70
110
  type PublicApi<T extends PropTypes = PropTypes> = {
71
111
  /**
72
112
  * Whether the color picker is being dragged
@@ -80,6 +120,10 @@ type PublicApi<T extends PropTypes = PropTypes> = {
80
120
  * The current color value (as a Color object)
81
121
  */
82
122
  valueAsColor: Color;
123
+ /**
124
+ * The alpha value of the color
125
+ */
126
+ alpha: number;
83
127
  /**
84
128
  * The current color channels of the color
85
129
  */
@@ -96,7 +140,12 @@ type PublicApi<T extends PropTypes = PropTypes> = {
96
140
  * Function to set the color format
97
141
  */
98
142
  setFormat(format: ColorFormat): void;
143
+ /**
144
+ * Function to set the color alpha
145
+ */
146
+ setAlpha(value: number): void;
99
147
  contentProps: T["element"];
148
+ hiddenInputProps: T["input"];
100
149
  getAreaProps(props: ColorAreaProps): T["element"];
101
150
  getAreaGradientProps(props: ColorAreaProps): T["element"];
102
151
  getAreaThumbProps(props: ColorAreaProps): T["element"];
@@ -108,41 +157,6 @@ type PublicApi<T extends PropTypes = PropTypes> = {
108
157
  getSwatchBackgroundProps(props: ColorSwatchProps): T["element"];
109
158
  getSwatchProps(props: ColorSwatchProps): T["element"];
110
159
  };
111
- type PrivateContext = Context<{
112
- /**
113
- * The id of the thumb that is currently being dragged
114
- */
115
- activeId: string | null;
116
- /**
117
- * The channel that is currently being interacted with
118
- */
119
- activeChannel: Partial<ColorAxes> | null;
120
- /**
121
- * The orientation of the channel that is currently being interacted with
122
- */
123
- activeOrientation: Orientation | null;
124
- }>;
125
- type ComputedContext = Readonly<{
126
- /**
127
- * Whether the color picker is in RTL mode
128
- */
129
- isRtl: boolean;
130
- /**
131
- * Whether the color picker is interactive
132
- */
133
- isInteractive: boolean;
134
- /**
135
- * The color value as a Color object
136
- */
137
- valueAsColor: Color;
138
- }>;
139
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
140
- type MachineContext = PublicContext & PrivateContext & ComputedContext;
141
- type MachineState = {
142
- value: "idle" | "focused" | "dragging";
143
- };
144
- type State = StateMachine.State<MachineContext, MachineState>;
145
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
146
160
 
147
161
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): PublicApi<T>;
148
162
 
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { Orientation, PropTypes, RequiredBy, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
2
+ import { Orientation, RequiredBy, PropTypes, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
3
3
  import { ColorChannel, Color, ColorFormat, ColorAxes } from '@zag-js/color-utils';
4
4
  export { Color, ColorAxes, ColorChannel, ColorFormat, ColorType } from '@zag-js/color-utils';
5
5
  import * as _zag_js_core from '@zag-js/core';
6
6
  import { StateMachine } from '@zag-js/core';
7
7
 
8
- declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBg" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBg" | "content" | "label" | "eyeDropTrigger">;
8
+ declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "areaThumb" | "areaGradient" | "channelSliderTrack" | "channelSliderTrackBackground" | "channelSliderThumb" | "channelInput" | "swatch" | "swatchBackground" | "content" | "label" | "eyeDropperTrigger">;
9
9
 
10
10
  type ColorChannelProps = {
11
11
  channel: ColorChannel;
@@ -37,6 +37,7 @@ type ElementIds = Partial<{
37
37
  channelSliderTrack(id: ColorChannel): string;
38
38
  channelSliderThumb(id: ColorChannel): string;
39
39
  }>;
40
+
40
41
  type PublicContext = CommonProperties & {
41
42
  /**
42
43
  * The ids of the elements in the color picker. Useful for composition.
@@ -66,7 +67,46 @@ type PublicContext = CommonProperties & {
66
67
  * Handler that is called when the user stops dragging.
67
68
  */
68
69
  onChangeEnd?: (details: ChangeDetails) => void;
70
+ /**
71
+ * The name for the form input
72
+ */
73
+ name?: string;
69
74
  };
75
+ type PrivateContext = Context<{
76
+ /**
77
+ * The id of the thumb that is currently being dragged
78
+ */
79
+ activeId: string | null;
80
+ /**
81
+ * The channel that is currently being interacted with
82
+ */
83
+ activeChannel: Partial<ColorAxes> | null;
84
+ /**
85
+ * The orientation of the channel that is currently being interacted with
86
+ */
87
+ activeOrientation: Orientation | null;
88
+ }>;
89
+ type ComputedContext = Readonly<{
90
+ /**
91
+ * Whether the color picker is in RTL mode
92
+ */
93
+ isRtl: boolean;
94
+ /**
95
+ * Whether the color picker is interactive
96
+ */
97
+ isInteractive: boolean;
98
+ /**
99
+ * The color value as a Color object
100
+ */
101
+ valueAsColor: Color;
102
+ }>;
103
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
104
+ type MachineContext = PublicContext & PrivateContext & ComputedContext;
105
+ type MachineState = {
106
+ value: "idle" | "focused" | "dragging";
107
+ };
108
+ type State = StateMachine.State<MachineContext, MachineState>;
109
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
70
110
  type PublicApi<T extends PropTypes = PropTypes> = {
71
111
  /**
72
112
  * Whether the color picker is being dragged
@@ -80,6 +120,10 @@ type PublicApi<T extends PropTypes = PropTypes> = {
80
120
  * The current color value (as a Color object)
81
121
  */
82
122
  valueAsColor: Color;
123
+ /**
124
+ * The alpha value of the color
125
+ */
126
+ alpha: number;
83
127
  /**
84
128
  * The current color channels of the color
85
129
  */
@@ -96,7 +140,12 @@ type PublicApi<T extends PropTypes = PropTypes> = {
96
140
  * Function to set the color format
97
141
  */
98
142
  setFormat(format: ColorFormat): void;
143
+ /**
144
+ * Function to set the color alpha
145
+ */
146
+ setAlpha(value: number): void;
99
147
  contentProps: T["element"];
148
+ hiddenInputProps: T["input"];
100
149
  getAreaProps(props: ColorAreaProps): T["element"];
101
150
  getAreaGradientProps(props: ColorAreaProps): T["element"];
102
151
  getAreaThumbProps(props: ColorAreaProps): T["element"];
@@ -108,41 +157,6 @@ type PublicApi<T extends PropTypes = PropTypes> = {
108
157
  getSwatchBackgroundProps(props: ColorSwatchProps): T["element"];
109
158
  getSwatchProps(props: ColorSwatchProps): T["element"];
110
159
  };
111
- type PrivateContext = Context<{
112
- /**
113
- * The id of the thumb that is currently being dragged
114
- */
115
- activeId: string | null;
116
- /**
117
- * The channel that is currently being interacted with
118
- */
119
- activeChannel: Partial<ColorAxes> | null;
120
- /**
121
- * The orientation of the channel that is currently being interacted with
122
- */
123
- activeOrientation: Orientation | null;
124
- }>;
125
- type ComputedContext = Readonly<{
126
- /**
127
- * Whether the color picker is in RTL mode
128
- */
129
- isRtl: boolean;
130
- /**
131
- * Whether the color picker is interactive
132
- */
133
- isInteractive: boolean;
134
- /**
135
- * The color value as a Color object
136
- */
137
- valueAsColor: Color;
138
- }>;
139
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
140
- type MachineContext = PublicContext & PrivateContext & ComputedContext;
141
- type MachineState = {
142
- value: "idle" | "focused" | "dragging";
143
- };
144
- type State = StateMachine.State<MachineContext, MachineState>;
145
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
146
160
 
147
161
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): PublicApi<T>;
148
162
 
package/dist/index.js CHANGED
@@ -33,14 +33,14 @@ var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
33
33
  "areaThumb",
34
34
  "areaGradient",
35
35
  "channelSliderTrack",
36
- "channelSliderTrackBg",
36
+ "channelSliderTrackBackground",
37
37
  "channelSliderThumb",
38
38
  "channelInput",
39
39
  "swatch",
40
- "swatchBg",
40
+ "swatchBackground",
41
41
  "content",
42
42
  "label",
43
- "eyeDropTrigger"
43
+ "eyeDropperTrigger"
44
44
  ]);
45
45
  var parts = anatomy.build();
46
46
 
@@ -48,6 +48,7 @@ var parts = anatomy.build();
48
48
  var import_color_utils2 = require("@zag-js/color-utils");
49
49
  var import_dom_event2 = require("@zag-js/dom-event");
50
50
  var import_dom_query2 = require("@zag-js/dom-query");
51
+ var import_visually_hidden = require("@zag-js/visually-hidden");
51
52
 
52
53
  // src/color-picker.dom.ts
53
54
  var import_dom_event = require("@zag-js/dom-event");
@@ -60,20 +61,28 @@ var dom = (0, import_dom_query.createScope)({
60
61
  getChannelSliderTrackId: (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`,
61
62
  getChannelInputId: (ctx, channel) => ctx.ids?.channelInput?.(channel) ?? `color-picker:${ctx.id}:input:${channel}`,
62
63
  getChannelSliderThumbId: (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`,
63
- getContentEl: (ctx) => dom.queryById(ctx, dom.getContentId(ctx)),
64
- getAreaThumbEl: (ctx) => dom.queryById(ctx, dom.getAreaThumbId(ctx)),
65
- getChannelSliderThumbEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
66
- getChannelInputEl: (ctx, channel) => dom.queryById(ctx, dom.getChannelInputId(ctx, channel)),
67
- getAreaEl: (ctx) => dom.queryById(ctx, dom.getAreaId(ctx)),
64
+ getHiddenInputId: (ctx) => `color-picker:${ctx.id}:hidden-input`,
65
+ getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
66
+ getAreaThumbEl: (ctx) => dom.getById(ctx, dom.getAreaThumbId(ctx)),
67
+ getChannelSliderThumbEl: (ctx, channel) => dom.getById(ctx, dom.getChannelSliderThumbId(ctx, channel)),
68
+ getChannelInputEl: (ctx, channel) => dom.getById(ctx, dom.getChannelInputId(ctx, channel)),
69
+ getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
70
+ getAreaEl: (ctx) => dom.getById(ctx, dom.getAreaId(ctx)),
68
71
  getAreaValueFromPoint(ctx, point) {
69
- const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getAreaEl(ctx));
72
+ const areaEl = dom.getAreaEl(ctx);
73
+ if (!areaEl)
74
+ return;
75
+ const { percent } = (0, import_dom_event.getRelativePoint)(point, areaEl);
70
76
  return percent;
71
77
  },
72
78
  getChannelSliderTrackEl: (ctx, channel) => {
73
- return dom.queryById(ctx, dom.getChannelSliderTrackId(ctx, channel));
79
+ return dom.getById(ctx, dom.getChannelSliderTrackId(ctx, channel));
74
80
  },
75
81
  getChannelSliderValueFromPoint(ctx, point, channel) {
76
- const { percent } = (0, import_dom_event.getRelativePoint)(point, dom.getChannelSliderTrackEl(ctx, channel));
82
+ const trackEl = dom.getChannelSliderTrackEl(ctx, channel);
83
+ if (!trackEl)
84
+ return;
85
+ const { percent } = (0, import_dom_event.getRelativePoint)(point, trackEl);
77
86
  return percent;
78
87
  },
79
88
  getChannelInputEls: (ctx) => {
@@ -397,25 +406,31 @@ var getSliderBgImage = (ctx, props) => {
397
406
  // src/color-picker.connect.ts
398
407
  function connect(state, send, normalize) {
399
408
  const valueAsColor = state.context.valueAsColor;
409
+ const value = state.context.value;
400
410
  const isDisabled = state.context.disabled;
401
411
  const isInteractive = state.context.isInteractive;
402
412
  const isDragging = state.matches("dragging");
403
413
  const channels = valueAsColor.getColorChannels();
404
414
  return {
405
415
  isDragging,
406
- value: state.context.value,
416
+ value,
407
417
  valueAsColor,
418
+ alpha: valueAsColor.getChannelValue("alpha"),
408
419
  channels,
409
- setColor(value) {
410
- send({ type: "VALUE.SET", value: (0, import_color_utils2.normalizeColor)(value), src: "set-color" });
420
+ setColor(value2) {
421
+ send({ type: "VALUE.SET", value: (0, import_color_utils2.normalizeColor)(value2), src: "set-color" });
411
422
  },
412
- setChannelValue(channel, value) {
413
- const color = valueAsColor.withChannelValue(channel, value);
423
+ setChannelValue(channel, value2) {
424
+ const color = valueAsColor.withChannelValue(channel, value2);
414
425
  send({ type: "VALUE.SET", value: color, src: "set-channel" });
415
426
  },
416
427
  setFormat(format) {
417
- const value = valueAsColor.toFormat(format);
418
- send({ type: "VALUE.SET", value, src: "set-format" });
428
+ const value2 = valueAsColor.toFormat(format);
429
+ send({ type: "VALUE.SET", value: value2, src: "set-format" });
430
+ },
431
+ setAlpha(value2) {
432
+ const color = valueAsColor.withChannelValue("alpha", value2);
433
+ send({ type: "VALUE.SET", value: color, src: "set-alpha" });
419
434
  },
420
435
  contentProps: normalize.element({
421
436
  ...parts.content.attrs,
@@ -546,7 +561,7 @@ function connect(state, send, normalize) {
546
561
  getChannelSliderBackgroundProps(props) {
547
562
  const { orientation = "horizontal", channel } = props;
548
563
  return normalize.element({
549
- ...parts.channelSliderTrackBg.attrs,
564
+ ...parts.channelSliderTrackBackground.attrs,
550
565
  "data-orientation": orientation,
551
566
  "data-channel": channel,
552
567
  style: {
@@ -662,19 +677,19 @@ function connect(state, send, normalize) {
662
677
  onChange(event) {
663
678
  if (isTextField)
664
679
  return;
665
- const value = event.currentTarget.value;
666
- send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
680
+ const value2 = event.currentTarget.value;
681
+ send({ type: "CHANNEL_INPUT.CHANGE", channel, value: value2, isTextField });
667
682
  },
668
683
  onBlur(event) {
669
- const value = event.currentTarget.value;
670
- send({ type: "CHANNEL_INPUT.BLUR", channel, value, isTextField });
684
+ const value2 = event.currentTarget.value;
685
+ send({ type: "CHANNEL_INPUT.BLUR", channel, value: value2, isTextField });
671
686
  },
672
687
  onKeyDown(event) {
673
688
  if (!isTextField)
674
689
  return;
675
690
  if (event.key === "Enter") {
676
- const value = event.currentTarget.value;
677
- send({ type: "CHANNEL_INPUT.CHANGE", channel, value, isTextField });
691
+ const value2 = event.currentTarget.value;
692
+ send({ type: "CHANNEL_INPUT.CHANGE", channel, value: value2, isTextField });
678
693
  }
679
694
  },
680
695
  style: {
@@ -684,17 +699,34 @@ function connect(state, send, normalize) {
684
699
  }
685
700
  });
686
701
  },
702
+ hiddenInputProps: normalize.input({
703
+ type: "text",
704
+ disabled: isDisabled,
705
+ name: state.context.name,
706
+ id: dom.getHiddenInputId(state.context),
707
+ style: import_visually_hidden.visuallyHiddenStyle,
708
+ defaultValue: value,
709
+ onChange(event) {
710
+ const value2 = event.currentTarget.value;
711
+ send({ type: "VALUE.SET", value: value2, src: "input.change" });
712
+ }
713
+ }),
687
714
  eyeDropperTriggerProps: normalize.button({
688
- ...parts.eyeDropTrigger.attrs,
715
+ ...parts.eyeDropperTrigger.attrs,
716
+ disabled: isDisabled,
717
+ "data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
718
+ "aria-label": "Pick a color from the screen",
689
719
  onClick() {
720
+ if (!isInteractive)
721
+ return;
690
722
  send("EYEDROPPER.CLICK");
691
723
  }
692
724
  }),
693
725
  getSwatchBackgroundProps(props) {
694
- const { value } = props;
695
- const alpha = (0, import_color_utils2.normalizeColor)(value).getChannelValue("alpha");
726
+ const { value: value2 } = props;
727
+ const alpha = (0, import_color_utils2.normalizeColor)(value2).getChannelValue("alpha");
696
728
  return normalize.element({
697
- ...parts.swatchBg.attrs,
729
+ ...parts.swatchBackground.attrs,
698
730
  "data-alpha": alpha,
699
731
  style: {
700
732
  width: "100%",
@@ -715,12 +747,12 @@ function connect(state, send, normalize) {
715
747
  });
716
748
  },
717
749
  getSwatchProps(props) {
718
- const { value, readOnly } = props;
719
- const color = (0, import_color_utils2.normalizeColor)(value).toFormat(valueAsColor.getColorSpace());
750
+ const { value: value2, readOnly } = props;
751
+ const color = (0, import_color_utils2.normalizeColor)(value2).toFormat(valueAsColor.getColorSpace());
720
752
  return normalize.element({
721
753
  ...parts.swatch.attrs,
722
754
  onClick() {
723
- if (readOnly)
755
+ if (readOnly || !isInteractive)
724
756
  return;
725
757
  send({ type: "VALUE.SET", value: color });
726
758
  },
@@ -738,6 +770,7 @@ var import_color_utils3 = require("@zag-js/color-utils");
738
770
  var import_core = require("@zag-js/core");
739
771
  var import_dom_event3 = require("@zag-js/dom-event");
740
772
  var import_dom_query3 = require("@zag-js/dom-query");
773
+ var import_form_utils = require("@zag-js/form-utils");
741
774
  var import_numeric_range2 = require("@zag-js/numeric-range");
742
775
  var import_text_selection = require("@zag-js/text-selection");
743
776
  var import_utils = require("@zag-js/utils");
@@ -765,8 +798,9 @@ function machine(userContext) {
765
798
  actions: ["setValue"]
766
799
  }
767
800
  },
801
+ activities: ["trackFormControl"],
768
802
  watch: {
769
- value: ["syncChannelInputs", "invokeOnChange"]
803
+ value: ["syncInputElements", "invokeOnChange"]
770
804
  },
771
805
  states: {
772
806
  idle: {
@@ -900,6 +934,17 @@ function machine(userContext) {
900
934
  isTextField: (_ctx, evt) => !!evt.isTextField
901
935
  },
902
936
  activities: {
937
+ trackFormControl(ctx2, _evt, { send, initialContext }) {
938
+ const inputEl = dom.getHiddenInputEl(ctx2);
939
+ return (0, import_form_utils.trackFormControl)(inputEl, {
940
+ onFieldsetDisabled() {
941
+ ctx2.disabled = true;
942
+ },
943
+ onFormReset() {
944
+ send({ type: "VALUE.SET", value: initialContext.value, src: "form.reset" });
945
+ }
946
+ });
947
+ },
903
948
  trackPointerMove(ctx2, _evt, { send }) {
904
949
  return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
905
950
  onPointerMove({ point }) {
@@ -947,6 +992,8 @@ function machine(userContext) {
947
992
  setAreaColorFromPoint(ctx2, evt) {
948
993
  const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
949
994
  const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
995
+ if (!percent)
996
+ return;
950
997
  const { getColorFromPoint } = getChannelDetails(ctx2.valueAsColor, xChannel, yChannel);
951
998
  const color = getColorFromPoint(percent.x, percent.y);
952
999
  if (!color)
@@ -956,6 +1003,8 @@ function machine(userContext) {
956
1003
  setChannelColorFromPoint(ctx2, evt) {
957
1004
  const channel = evt.channel || ctx2.activeId;
958
1005
  const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
1006
+ if (!percent)
1007
+ return;
959
1008
  const { minValue, maxValue, step } = ctx2.valueAsColor.getChannelRange(channel);
960
1009
  const orientation = ctx2.activeOrientation || "horizontal";
961
1010
  const point = orientation === "horizontal" ? percent.x : percent.y;
@@ -967,15 +1016,18 @@ function machine(userContext) {
967
1016
  setValue(ctx2, evt) {
968
1017
  setColor(ctx2, evt.value);
969
1018
  },
970
- syncChannelInputs(ctx2) {
1019
+ syncInputElements(ctx2) {
971
1020
  const inputs = dom.getChannelInputEls(ctx2);
972
1021
  inputs.forEach((input) => {
973
1022
  const channel = input.dataset.channel;
974
1023
  if (!channel)
975
1024
  return;
976
- const value = getChannelInputValue(ctx2.valueAsColor, channel);
977
- input.value = value.toString();
1025
+ input.value = getChannelInputValue(ctx2.valueAsColor, channel);
978
1026
  });
1027
+ const hiddenInput = dom.getHiddenInputEl(ctx2);
1028
+ if (!hiddenInput)
1029
+ return;
1030
+ hiddenInput.value = ctx2.value;
979
1031
  },
980
1032
  setChannelColorFromInput(ctx2, evt) {
981
1033
  const { channel, isTextField, value } = evt;