@zag-js/color-picker 0.56.0 → 0.57.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 +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +99 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -102
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/color-picker.anatomy.ts +2 -0
- package/src/color-picker.connect.ts +47 -15
- package/src/color-picker.machine.ts +19 -17
- package/src/color-picker.types.ts +14 -3
- package/src/index.ts +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ import { StateMachine } from '@zag-js/core';
|
|
|
9
9
|
import { PositioningOptions } from '@zag-js/popper';
|
|
10
10
|
export { PositioningOptions } from '@zag-js/popper';
|
|
11
11
|
|
|
12
|
-
declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "label" | "root" | "content" | "control" | "trigger" | "positioner" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderTrack" | "channelSliderThumb" | "channelInput" | "transparencyGrid" | "swatchGroup" | "swatchTrigger" | "swatchIndicator" | "swatch" | "eyeDropperTrigger" | "formatTrigger" | "formatSelect">;
|
|
12
|
+
declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "label" | "root" | "content" | "control" | "trigger" | "positioner" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderLabel" | "channelSliderTrack" | "channelSliderThumb" | "channelSliderValueText" | "channelInput" | "transparencyGrid" | "swatchGroup" | "swatchTrigger" | "swatchIndicator" | "swatch" | "eyeDropperTrigger" | "formatTrigger" | "formatSelect">;
|
|
13
13
|
|
|
14
14
|
type ExtendedColorChannel = ColorChannel | "hex" | "css";
|
|
15
15
|
interface EyeDropper {
|
|
@@ -157,6 +157,9 @@ interface ChannelProps {
|
|
|
157
157
|
channel: ColorChannel;
|
|
158
158
|
orientation?: Orientation;
|
|
159
159
|
}
|
|
160
|
+
interface ChannelSliderProps extends ChannelProps {
|
|
161
|
+
format?: ColorFormat;
|
|
162
|
+
}
|
|
160
163
|
interface ChannelInputProps {
|
|
161
164
|
channel: ExtendedColorChannel;
|
|
162
165
|
orientation?: Orientation;
|
|
@@ -219,6 +222,10 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
219
222
|
* Function to set the color value
|
|
220
223
|
*/
|
|
221
224
|
getChannelValue(channel: ColorChannel): string;
|
|
225
|
+
/**
|
|
226
|
+
* Function to get the formatted and localized value of a specific channel
|
|
227
|
+
*/
|
|
228
|
+
getChannelValueText(channel: ColorChannel, locale: string): string;
|
|
222
229
|
/**
|
|
223
230
|
* Function to set the color value of a specific channel
|
|
224
231
|
*/
|
|
@@ -253,10 +260,12 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
253
260
|
getAreaProps(props?: AreaProps): T["element"];
|
|
254
261
|
getAreaBackgroundProps(props?: AreaProps): T["element"];
|
|
255
262
|
getAreaThumbProps(props?: AreaProps): T["element"];
|
|
256
|
-
getChannelSliderProps(props: ChannelProps): T["element"];
|
|
257
|
-
getChannelSliderTrackProps(props: ChannelProps): T["element"];
|
|
258
|
-
getChannelSliderThumbProps(props: ChannelProps): T["element"];
|
|
259
263
|
getChannelInputProps(props: ChannelInputProps): T["input"];
|
|
264
|
+
getChannelSliderProps(props: ChannelSliderProps): T["element"];
|
|
265
|
+
getChannelSliderTrackProps(props: ChannelSliderProps): T["element"];
|
|
266
|
+
getChannelSliderThumbProps(props: ChannelSliderProps): T["element"];
|
|
267
|
+
getChannelSliderLabelProps(props: ChannelProps): T["element"];
|
|
268
|
+
getChannelSliderValueTextProps(props: ChannelProps): T["element"];
|
|
260
269
|
getTransparencyGridProps(props?: TransparencyGridProps): T["element"];
|
|
261
270
|
getEyeDropperTriggerProps(): T["button"];
|
|
262
271
|
getSwatchGroupProps(): T["element"];
|
|
@@ -274,4 +283,4 @@ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<
|
|
|
274
283
|
|
|
275
284
|
declare const parse: (colorString: string) => Color;
|
|
276
285
|
|
|
277
|
-
export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type UserDefinedContext as Context, type ElementIds, type FormatChangeDetails, type OpenChangeDetails, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
|
|
286
|
+
export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type UserDefinedContext as Context, type ElementIds, type FormatChangeDetails, type OpenChangeDetails, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { StateMachine } from '@zag-js/core';
|
|
|
9
9
|
import { PositioningOptions } from '@zag-js/popper';
|
|
10
10
|
export { PositioningOptions } from '@zag-js/popper';
|
|
11
11
|
|
|
12
|
-
declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "label" | "root" | "content" | "control" | "trigger" | "positioner" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderTrack" | "channelSliderThumb" | "channelInput" | "transparencyGrid" | "swatchGroup" | "swatchTrigger" | "swatchIndicator" | "swatch" | "eyeDropperTrigger" | "formatTrigger" | "formatSelect">;
|
|
12
|
+
declare const anatomy: _zag_js_anatomy.Anatomy<"area" | "label" | "root" | "content" | "control" | "trigger" | "positioner" | "areaThumb" | "areaBackground" | "channelSlider" | "channelSliderLabel" | "channelSliderTrack" | "channelSliderThumb" | "channelSliderValueText" | "channelInput" | "transparencyGrid" | "swatchGroup" | "swatchTrigger" | "swatchIndicator" | "swatch" | "eyeDropperTrigger" | "formatTrigger" | "formatSelect">;
|
|
13
13
|
|
|
14
14
|
type ExtendedColorChannel = ColorChannel | "hex" | "css";
|
|
15
15
|
interface EyeDropper {
|
|
@@ -157,6 +157,9 @@ interface ChannelProps {
|
|
|
157
157
|
channel: ColorChannel;
|
|
158
158
|
orientation?: Orientation;
|
|
159
159
|
}
|
|
160
|
+
interface ChannelSliderProps extends ChannelProps {
|
|
161
|
+
format?: ColorFormat;
|
|
162
|
+
}
|
|
160
163
|
interface ChannelInputProps {
|
|
161
164
|
channel: ExtendedColorChannel;
|
|
162
165
|
orientation?: Orientation;
|
|
@@ -219,6 +222,10 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
219
222
|
* Function to set the color value
|
|
220
223
|
*/
|
|
221
224
|
getChannelValue(channel: ColorChannel): string;
|
|
225
|
+
/**
|
|
226
|
+
* Function to get the formatted and localized value of a specific channel
|
|
227
|
+
*/
|
|
228
|
+
getChannelValueText(channel: ColorChannel, locale: string): string;
|
|
222
229
|
/**
|
|
223
230
|
* Function to set the color value of a specific channel
|
|
224
231
|
*/
|
|
@@ -253,10 +260,12 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
253
260
|
getAreaProps(props?: AreaProps): T["element"];
|
|
254
261
|
getAreaBackgroundProps(props?: AreaProps): T["element"];
|
|
255
262
|
getAreaThumbProps(props?: AreaProps): T["element"];
|
|
256
|
-
getChannelSliderProps(props: ChannelProps): T["element"];
|
|
257
|
-
getChannelSliderTrackProps(props: ChannelProps): T["element"];
|
|
258
|
-
getChannelSliderThumbProps(props: ChannelProps): T["element"];
|
|
259
263
|
getChannelInputProps(props: ChannelInputProps): T["input"];
|
|
264
|
+
getChannelSliderProps(props: ChannelSliderProps): T["element"];
|
|
265
|
+
getChannelSliderTrackProps(props: ChannelSliderProps): T["element"];
|
|
266
|
+
getChannelSliderThumbProps(props: ChannelSliderProps): T["element"];
|
|
267
|
+
getChannelSliderLabelProps(props: ChannelProps): T["element"];
|
|
268
|
+
getChannelSliderValueTextProps(props: ChannelProps): T["element"];
|
|
260
269
|
getTransparencyGridProps(props?: TransparencyGridProps): T["element"];
|
|
261
270
|
getEyeDropperTriggerProps(): T["button"];
|
|
262
271
|
getSwatchGroupProps(): T["element"];
|
|
@@ -274,4 +283,4 @@ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<
|
|
|
274
283
|
|
|
275
284
|
declare const parse: (colorString: string) => Color;
|
|
276
285
|
|
|
277
|
-
export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type UserDefinedContext as Context, type ElementIds, type FormatChangeDetails, type OpenChangeDetails, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
|
|
286
|
+
export { type MachineApi as Api, type AreaProps, type ChannelInputProps, type ChannelProps, type ChannelSliderProps, type UserDefinedContext as Context, type ElementIds, type FormatChangeDetails, type OpenChangeDetails, type SwatchProps, type SwatchTriggerProps, type SwatchTriggerState, type TransparencyGridProps, type ValueChangeDetails, anatomy, connect, machine, parse };
|
package/dist/index.js
CHANGED
|
@@ -40,8 +40,10 @@ var anatomy = (0, import_anatomy.createAnatomy)("color-picker", [
|
|
|
40
40
|
"areaThumb",
|
|
41
41
|
"areaBackground",
|
|
42
42
|
"channelSlider",
|
|
43
|
+
"channelSliderLabel",
|
|
43
44
|
"channelSliderTrack",
|
|
44
45
|
"channelSliderThumb",
|
|
46
|
+
"channelSliderValueText",
|
|
45
47
|
"channelInput",
|
|
46
48
|
"transparencyGrid",
|
|
47
49
|
"swatchGroup",
|
|
@@ -91,8 +93,7 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
91
93
|
getAreaEl: (ctx) => dom.getById(ctx, dom.getAreaId(ctx)),
|
|
92
94
|
getAreaValueFromPoint(ctx, point) {
|
|
93
95
|
const areaEl = dom.getAreaEl(ctx);
|
|
94
|
-
if (!areaEl)
|
|
95
|
-
return;
|
|
96
|
+
if (!areaEl) return;
|
|
96
97
|
const { percent } = (0, import_dom_event.getRelativePoint)(point, areaEl);
|
|
97
98
|
return percent;
|
|
98
99
|
},
|
|
@@ -104,8 +105,7 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
104
105
|
},
|
|
105
106
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
106
107
|
const trackEl = dom.getChannelSliderTrackEl(ctx, channel);
|
|
107
|
-
if (!trackEl)
|
|
108
|
-
return;
|
|
108
|
+
if (!trackEl) return;
|
|
109
109
|
const { percent } = (0, import_dom_event.getRelativePoint)(point, trackEl);
|
|
110
110
|
return percent;
|
|
111
111
|
},
|
|
@@ -141,8 +141,7 @@ function getChannelDisplayColor(color, channel) {
|
|
|
141
141
|
// src/utils/get-channel-input-value.ts
|
|
142
142
|
var import_color_utils2 = require("@zag-js/color-utils");
|
|
143
143
|
function getChannelValue(color, channel) {
|
|
144
|
-
if (channel == null)
|
|
145
|
-
return "";
|
|
144
|
+
if (channel == null) return "";
|
|
146
145
|
if (channel === "hex") {
|
|
147
146
|
return color.toString("hex");
|
|
148
147
|
}
|
|
@@ -273,8 +272,7 @@ function connect(state, send, normalize) {
|
|
|
273
272
|
valueAsString,
|
|
274
273
|
value,
|
|
275
274
|
setOpen(nextOpen) {
|
|
276
|
-
if (nextOpen === open)
|
|
277
|
-
return;
|
|
275
|
+
if (nextOpen === open) return;
|
|
278
276
|
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
279
277
|
},
|
|
280
278
|
setValue(value2) {
|
|
@@ -283,6 +281,9 @@ function connect(state, send, normalize) {
|
|
|
283
281
|
getChannelValue(channel) {
|
|
284
282
|
return getChannelValue(value, channel);
|
|
285
283
|
},
|
|
284
|
+
getChannelValueText(channel, locale) {
|
|
285
|
+
return value.formatChannelValue(channel, locale);
|
|
286
|
+
},
|
|
286
287
|
setChannelValue(channel, channelValue) {
|
|
287
288
|
const color = value.withChannelValue(channel, channelValue);
|
|
288
289
|
send({ type: "VALUE.SET", value: color, src: "set-channel" });
|
|
@@ -353,13 +354,11 @@ function connect(state, send, normalize) {
|
|
|
353
354
|
"data-focus": (0, import_dom_query2.dataAttr)(focused),
|
|
354
355
|
type: "button",
|
|
355
356
|
onClick() {
|
|
356
|
-
if (!interactive)
|
|
357
|
-
return;
|
|
357
|
+
if (!interactive) return;
|
|
358
358
|
send({ type: "TRIGGER.CLICK" });
|
|
359
359
|
},
|
|
360
360
|
onBlur() {
|
|
361
|
-
if (!interactive)
|
|
362
|
-
return;
|
|
361
|
+
if (!interactive) return;
|
|
363
362
|
send({ type: "TRIGGER.BLUR" });
|
|
364
363
|
},
|
|
365
364
|
style: {
|
|
@@ -397,12 +396,9 @@ function connect(state, send, normalize) {
|
|
|
397
396
|
id: dom.getAreaId(state.context),
|
|
398
397
|
role: "group",
|
|
399
398
|
onPointerDown(event) {
|
|
400
|
-
if (!interactive)
|
|
401
|
-
|
|
402
|
-
if (
|
|
403
|
-
return;
|
|
404
|
-
if ((0, import_dom_event2.isModifierKey)(event))
|
|
405
|
-
return;
|
|
399
|
+
if (!interactive) return;
|
|
400
|
+
if (!(0, import_dom_event2.isLeftClick)(event)) return;
|
|
401
|
+
if ((0, import_dom_event2.isModifierKey)(event)) return;
|
|
406
402
|
const point = (0, import_dom_event2.getEventPoint)(event);
|
|
407
403
|
const channel = { xChannel, yChannel };
|
|
408
404
|
send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
|
|
@@ -464,15 +460,12 @@ function connect(state, send, normalize) {
|
|
|
464
460
|
background: areaValue.withChannelValue("alpha", 1).toString("css")
|
|
465
461
|
},
|
|
466
462
|
onFocus() {
|
|
467
|
-
if (!interactive)
|
|
468
|
-
return;
|
|
463
|
+
if (!interactive) return;
|
|
469
464
|
send({ type: "AREA.FOCUS", id: "area", channel });
|
|
470
465
|
},
|
|
471
466
|
onKeyDown(event) {
|
|
472
|
-
if (event.defaultPrevented)
|
|
473
|
-
|
|
474
|
-
if (!interactive)
|
|
475
|
-
return;
|
|
467
|
+
if (event.defaultPrevented) return;
|
|
468
|
+
if (!interactive) return;
|
|
476
469
|
const step = (0, import_dom_event2.getEventStep)(event);
|
|
477
470
|
const keyMap = {
|
|
478
471
|
ArrowUp() {
|
|
@@ -524,21 +517,18 @@ function connect(state, send, normalize) {
|
|
|
524
517
|
});
|
|
525
518
|
},
|
|
526
519
|
getChannelSliderProps(props) {
|
|
527
|
-
const { orientation = "horizontal", channel } = props;
|
|
520
|
+
const { orientation = "horizontal", channel, format } = props;
|
|
528
521
|
return normalize.element({
|
|
529
522
|
...parts.channelSlider.attrs,
|
|
530
523
|
"data-channel": channel,
|
|
531
524
|
"data-orientation": orientation,
|
|
532
525
|
role: "presentation",
|
|
533
526
|
onPointerDown(event) {
|
|
534
|
-
if (!interactive)
|
|
535
|
-
|
|
536
|
-
if (
|
|
537
|
-
return;
|
|
538
|
-
if ((0, import_dom_event2.isModifierKey)(event))
|
|
539
|
-
return;
|
|
527
|
+
if (!interactive) return;
|
|
528
|
+
if (!(0, import_dom_event2.isLeftClick)(event)) return;
|
|
529
|
+
if ((0, import_dom_event2.isModifierKey)(event)) return;
|
|
540
530
|
const point = (0, import_dom_event2.getEventPoint)(event);
|
|
541
|
-
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
|
|
531
|
+
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, format, point, id: channel, orientation });
|
|
542
532
|
event.preventDefault();
|
|
543
533
|
},
|
|
544
534
|
style: {
|
|
@@ -548,7 +538,8 @@ function connect(state, send, normalize) {
|
|
|
548
538
|
});
|
|
549
539
|
},
|
|
550
540
|
getChannelSliderTrackProps(props) {
|
|
551
|
-
const { orientation = "horizontal", channel } = props;
|
|
541
|
+
const { orientation = "horizontal", channel, format } = props;
|
|
542
|
+
const normalizedValue = format ? value.toFormat(format) : areaValue;
|
|
552
543
|
return normalize.element({
|
|
553
544
|
...parts.channelSliderTrack.attrs,
|
|
554
545
|
id: dom.getChannelSliderId(state.context, channel),
|
|
@@ -562,16 +553,40 @@ function connect(state, send, normalize) {
|
|
|
562
553
|
orientation,
|
|
563
554
|
channel,
|
|
564
555
|
dir: state.context.dir,
|
|
565
|
-
value:
|
|
556
|
+
value: normalizedValue
|
|
566
557
|
})
|
|
567
558
|
}
|
|
568
559
|
});
|
|
569
560
|
},
|
|
561
|
+
getChannelSliderLabelProps(props) {
|
|
562
|
+
const { channel } = props;
|
|
563
|
+
return normalize.element({
|
|
564
|
+
...parts.channelSliderLabel.attrs,
|
|
565
|
+
"data-channel": channel,
|
|
566
|
+
onClick(event) {
|
|
567
|
+
if (!interactive) return;
|
|
568
|
+
event.preventDefault();
|
|
569
|
+
const thumbId = dom.getChannelSliderThumbId(state.context, channel);
|
|
570
|
+
dom.getById(state.context, thumbId)?.focus({ preventScroll: true });
|
|
571
|
+
},
|
|
572
|
+
style: {
|
|
573
|
+
userSelect: "none",
|
|
574
|
+
WebkitUserSelect: "none"
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
},
|
|
578
|
+
getChannelSliderValueTextProps(props) {
|
|
579
|
+
return normalize.element({
|
|
580
|
+
...parts.channelSliderValueText.attrs,
|
|
581
|
+
"data-channel": props.channel
|
|
582
|
+
});
|
|
583
|
+
},
|
|
570
584
|
getChannelSliderThumbProps(props) {
|
|
571
|
-
const { orientation = "horizontal", channel } = props;
|
|
572
|
-
const
|
|
573
|
-
const
|
|
574
|
-
const
|
|
585
|
+
const { orientation = "horizontal", channel, format } = props;
|
|
586
|
+
const normalizedValue = format ? value.toFormat(format) : areaValue;
|
|
587
|
+
const channelRange = normalizedValue.getChannelRange(channel);
|
|
588
|
+
const channelValue = normalizedValue.getChannelValue(channel);
|
|
589
|
+
const offset = (channelValue - channelRange.minValue) / (channelRange.maxValue - channelRange.minValue);
|
|
575
590
|
const placementStyles = orientation === "horizontal" ? { left: `${offset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
|
|
576
591
|
return normalize.element({
|
|
577
592
|
...parts.channelSliderThumb.attrs,
|
|
@@ -584,8 +599,8 @@ function connect(state, send, normalize) {
|
|
|
584
599
|
"data-orientation": orientation,
|
|
585
600
|
"aria-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
586
601
|
"aria-orientation": orientation,
|
|
587
|
-
"aria-valuemax": maxValue,
|
|
588
|
-
"aria-valuemin": minValue,
|
|
602
|
+
"aria-valuemax": channelRange.maxValue,
|
|
603
|
+
"aria-valuemin": channelRange.minValue,
|
|
589
604
|
"aria-valuenow": channelValue,
|
|
590
605
|
"aria-valuetext": `${channel} ${channelValue}`,
|
|
591
606
|
style: {
|
|
@@ -595,16 +610,13 @@ function connect(state, send, normalize) {
|
|
|
595
610
|
...placementStyles
|
|
596
611
|
},
|
|
597
612
|
onFocus() {
|
|
598
|
-
if (!interactive)
|
|
599
|
-
return;
|
|
613
|
+
if (!interactive) return;
|
|
600
614
|
send({ type: "CHANNEL_SLIDER.FOCUS", channel });
|
|
601
615
|
},
|
|
602
616
|
onKeyDown(event) {
|
|
603
|
-
if (event.defaultPrevented)
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
return;
|
|
607
|
-
const step = (0, import_dom_event2.getEventStep)(event) * stepValue;
|
|
617
|
+
if (event.defaultPrevented) return;
|
|
618
|
+
if (!interactive) return;
|
|
619
|
+
const step = (0, import_dom_event2.getEventStep)(event) * channelRange.step;
|
|
608
620
|
const keyMap = {
|
|
609
621
|
ArrowUp() {
|
|
610
622
|
send({ type: "CHANNEL_SLIDER.ARROW_UP", channel, step });
|
|
@@ -645,7 +657,7 @@ function connect(state, send, normalize) {
|
|
|
645
657
|
getChannelInputProps(props) {
|
|
646
658
|
const { channel } = props;
|
|
647
659
|
const isTextField = channel === "hex" || channel === "css";
|
|
648
|
-
const
|
|
660
|
+
const channelRange = getChannelRange(value, channel);
|
|
649
661
|
return normalize.input({
|
|
650
662
|
...parts.channelInput.attrs,
|
|
651
663
|
dir: state.context.dir,
|
|
@@ -658,34 +670,29 @@ function connect(state, send, normalize) {
|
|
|
658
670
|
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
659
671
|
readOnly: state.context.readOnly,
|
|
660
672
|
defaultValue: getChannelValue(value, channel),
|
|
661
|
-
min:
|
|
662
|
-
max:
|
|
663
|
-
step:
|
|
673
|
+
min: channelRange?.minValue,
|
|
674
|
+
max: channelRange?.maxValue,
|
|
675
|
+
step: channelRange?.step,
|
|
664
676
|
onBeforeInput(event) {
|
|
665
|
-
if (isTextField || !interactive)
|
|
666
|
-
return;
|
|
677
|
+
if (isTextField || !interactive) return;
|
|
667
678
|
const value2 = event.currentTarget.value;
|
|
668
679
|
if (value2.match(/[^0-9.]/g)) {
|
|
669
680
|
event.preventDefault();
|
|
670
681
|
}
|
|
671
682
|
},
|
|
672
683
|
onFocus(event) {
|
|
673
|
-
if (!interactive)
|
|
674
|
-
return;
|
|
684
|
+
if (!interactive) return;
|
|
675
685
|
send({ type: "CHANNEL_INPUT.FOCUS", channel });
|
|
676
686
|
event.target.select();
|
|
677
687
|
},
|
|
678
688
|
onBlur(event) {
|
|
679
|
-
if (!interactive)
|
|
680
|
-
return;
|
|
689
|
+
if (!interactive) return;
|
|
681
690
|
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
682
691
|
send({ type: "CHANNEL_INPUT.BLUR", channel, value: value2, isTextField });
|
|
683
692
|
},
|
|
684
693
|
onKeyDown(event) {
|
|
685
|
-
if (event.defaultPrevented)
|
|
686
|
-
|
|
687
|
-
if (!interactive)
|
|
688
|
-
return;
|
|
694
|
+
if (event.defaultPrevented) return;
|
|
695
|
+
if (!interactive) return;
|
|
689
696
|
if (event.key === "Enter") {
|
|
690
697
|
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
691
698
|
send({ type: "CHANNEL_INPUT.CHANGE", channel, value: value2, isTextField });
|
|
@@ -718,8 +725,7 @@ function connect(state, send, normalize) {
|
|
|
718
725
|
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
719
726
|
"aria-label": "Pick a color from the screen",
|
|
720
727
|
onClick() {
|
|
721
|
-
if (!interactive)
|
|
722
|
-
return;
|
|
728
|
+
if (!interactive) return;
|
|
723
729
|
send("EYEDROPPER.CLICK");
|
|
724
730
|
}
|
|
725
731
|
});
|
|
@@ -743,8 +749,7 @@ function connect(state, send, normalize) {
|
|
|
743
749
|
"data-value": swatchState.valueAsString,
|
|
744
750
|
"data-disabled": (0, import_dom_query2.dataAttr)(swatchState.disabled),
|
|
745
751
|
onClick() {
|
|
746
|
-
if (swatchState.disabled)
|
|
747
|
-
return;
|
|
752
|
+
if (swatchState.disabled) return;
|
|
748
753
|
send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value });
|
|
749
754
|
},
|
|
750
755
|
style: {
|
|
@@ -781,8 +786,7 @@ function connect(state, send, normalize) {
|
|
|
781
786
|
type: "button",
|
|
782
787
|
"aria-label": `change color format to ${getNextFormat(state.context.format)}`,
|
|
783
788
|
onClick(event) {
|
|
784
|
-
if (event.currentTarget.disabled)
|
|
785
|
-
return;
|
|
789
|
+
if (event.currentTarget.disabled) return;
|
|
786
790
|
const nextFormat = getNextFormat(state.context.format);
|
|
787
791
|
send({ type: "FORMAT.SET", format: nextFormat, src: "format-trigger" });
|
|
788
792
|
}
|
|
@@ -810,8 +814,7 @@ function getNextFormat(format) {
|
|
|
810
814
|
return formats[index + 1] ?? formats[0];
|
|
811
815
|
}
|
|
812
816
|
function assertFormat(format) {
|
|
813
|
-
if (formatRegex.test(format))
|
|
814
|
-
return format;
|
|
817
|
+
if (formatRegex.test(format)) return format;
|
|
815
818
|
throw new Error(`Unsupported color format: ${format}`);
|
|
816
819
|
}
|
|
817
820
|
|
|
@@ -999,22 +1002,22 @@ function machine(userContext) {
|
|
|
999
1002
|
actions: ["setActiveChannel"]
|
|
1000
1003
|
},
|
|
1001
1004
|
"AREA.ARROW_LEFT": {
|
|
1002
|
-
actions: ["
|
|
1005
|
+
actions: ["decrementAreaXChannel"]
|
|
1003
1006
|
},
|
|
1004
1007
|
"AREA.ARROW_RIGHT": {
|
|
1005
|
-
actions: ["
|
|
1008
|
+
actions: ["incrementAreaXChannel"]
|
|
1006
1009
|
},
|
|
1007
1010
|
"AREA.ARROW_UP": {
|
|
1008
|
-
actions: ["
|
|
1011
|
+
actions: ["incrementAreaYChannel"]
|
|
1009
1012
|
},
|
|
1010
1013
|
"AREA.ARROW_DOWN": {
|
|
1011
|
-
actions: ["
|
|
1014
|
+
actions: ["decrementAreaYChannel"]
|
|
1012
1015
|
},
|
|
1013
1016
|
"AREA.PAGE_UP": {
|
|
1014
|
-
actions: ["
|
|
1017
|
+
actions: ["incrementAreaXChannel"]
|
|
1015
1018
|
},
|
|
1016
1019
|
"AREA.PAGE_DOWN": {
|
|
1017
|
-
actions: ["
|
|
1020
|
+
actions: ["decrementAreaXChannel"]
|
|
1018
1021
|
},
|
|
1019
1022
|
"CHANNEL_SLIDER.ARROW_LEFT": {
|
|
1020
1023
|
actions: ["decrementChannel"]
|
|
@@ -1168,8 +1171,7 @@ function machine(userContext) {
|
|
|
1168
1171
|
defer: true,
|
|
1169
1172
|
onInteractOutside(event) {
|
|
1170
1173
|
ctx2.onInteractOutside?.(event);
|
|
1171
|
-
if (event.defaultPrevented)
|
|
1172
|
-
return;
|
|
1174
|
+
if (event.defaultPrevented) return;
|
|
1173
1175
|
ctx2.restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
1174
1176
|
},
|
|
1175
1177
|
onPointerDownOutside: ctx2.onPointerDownOutside,
|
|
@@ -1190,11 +1192,11 @@ function machine(userContext) {
|
|
|
1190
1192
|
}
|
|
1191
1193
|
});
|
|
1192
1194
|
},
|
|
1193
|
-
trackPointerMove(ctx2,
|
|
1195
|
+
trackPointerMove(ctx2, evt, { send }) {
|
|
1194
1196
|
return (0, import_dom_event3.trackPointerMove)(dom.getDoc(ctx2), {
|
|
1195
1197
|
onPointerMove({ point }) {
|
|
1196
1198
|
const type = ctx2.activeId === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE";
|
|
1197
|
-
send({ type, point });
|
|
1199
|
+
send({ type, point, format: evt.format });
|
|
1198
1200
|
},
|
|
1199
1201
|
onPointerUp() {
|
|
1200
1202
|
const type = ctx2.activeId === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP";
|
|
@@ -1209,8 +1211,7 @@ function machine(userContext) {
|
|
|
1209
1211
|
actions: {
|
|
1210
1212
|
openEyeDropper(ctx2) {
|
|
1211
1213
|
const isSupported = "EyeDropper" in dom.getWin(ctx2);
|
|
1212
|
-
if (!isSupported)
|
|
1213
|
-
return;
|
|
1214
|
+
if (!isSupported) return;
|
|
1214
1215
|
const win = dom.getWin(ctx2);
|
|
1215
1216
|
const picker = new win.EyeDropper();
|
|
1216
1217
|
picker.open().then(({ sRGBHex }) => {
|
|
@@ -1222,10 +1223,8 @@ function machine(userContext) {
|
|
|
1222
1223
|
},
|
|
1223
1224
|
setActiveChannel(ctx2, evt) {
|
|
1224
1225
|
ctx2.activeId = evt.id;
|
|
1225
|
-
if (evt.channel)
|
|
1226
|
-
|
|
1227
|
-
if (evt.orientation)
|
|
1228
|
-
ctx2.activeOrientation = evt.orientation;
|
|
1226
|
+
if (evt.channel) ctx2.activeChannel = evt.channel;
|
|
1227
|
+
if (evt.orientation) ctx2.activeOrientation = evt.orientation;
|
|
1229
1228
|
},
|
|
1230
1229
|
clearActiveChannel(ctx2) {
|
|
1231
1230
|
ctx2.activeChannel = null;
|
|
@@ -1233,24 +1232,24 @@ function machine(userContext) {
|
|
|
1233
1232
|
ctx2.activeOrientation = null;
|
|
1234
1233
|
},
|
|
1235
1234
|
setAreaColorFromPoint(ctx2, evt) {
|
|
1235
|
+
const normalizedValue = evt.format ? ctx2.value.toFormat(evt.format) : ctx2.areaValue;
|
|
1236
1236
|
const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
|
|
1237
1237
|
const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
|
|
1238
|
-
if (!percent)
|
|
1239
|
-
|
|
1240
|
-
const
|
|
1241
|
-
const
|
|
1242
|
-
const color = ctx2.areaValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
1238
|
+
if (!percent) return;
|
|
1239
|
+
const xValue = normalizedValue.getChannelPercentValue(xChannel, percent.x);
|
|
1240
|
+
const yValue = normalizedValue.getChannelPercentValue(yChannel, 1 - percent.y);
|
|
1241
|
+
const color = normalizedValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
1243
1242
|
set.value(ctx2, color);
|
|
1244
1243
|
},
|
|
1245
1244
|
setChannelColorFromPoint(ctx2, evt) {
|
|
1246
1245
|
const channel = evt.channel || ctx2.activeId;
|
|
1246
|
+
const normalizedValue = evt.format ? ctx2.value.toFormat(evt.format) : ctx2.areaValue;
|
|
1247
1247
|
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
1248
|
-
if (!percent)
|
|
1249
|
-
return;
|
|
1248
|
+
if (!percent) return;
|
|
1250
1249
|
const orientation = ctx2.activeOrientation || "horizontal";
|
|
1251
1250
|
const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
|
|
1252
|
-
const value =
|
|
1253
|
-
const color =
|
|
1251
|
+
const value = normalizedValue.getChannelPercentValue(channel, channelPercent);
|
|
1252
|
+
const color = normalizedValue.withChannelValue(channel, value);
|
|
1254
1253
|
set.value(ctx2, color);
|
|
1255
1254
|
},
|
|
1256
1255
|
setValue(ctx2, evt) {
|
|
@@ -1294,22 +1293,22 @@ function machine(userContext) {
|
|
|
1294
1293
|
const color = ctx2.value.decrementChannel(evt.channel, evt.step);
|
|
1295
1294
|
set.value(ctx2, color);
|
|
1296
1295
|
},
|
|
1297
|
-
|
|
1296
|
+
incrementAreaXChannel(ctx2, evt) {
|
|
1298
1297
|
const { xChannel } = evt.channel;
|
|
1299
1298
|
const color = ctx2.areaValue.incrementChannel(xChannel, evt.step);
|
|
1300
1299
|
set.value(ctx2, color);
|
|
1301
1300
|
},
|
|
1302
|
-
|
|
1301
|
+
decrementAreaXChannel(ctx2, evt) {
|
|
1303
1302
|
const { xChannel } = evt.channel;
|
|
1304
1303
|
const color = ctx2.areaValue.decrementChannel(xChannel, evt.step);
|
|
1305
1304
|
set.value(ctx2, color);
|
|
1306
1305
|
},
|
|
1307
|
-
|
|
1306
|
+
incrementAreaYChannel(ctx2, evt) {
|
|
1308
1307
|
const { yChannel } = evt.channel;
|
|
1309
1308
|
const color = ctx2.areaValue.incrementChannel(yChannel, evt.step);
|
|
1310
1309
|
set.value(ctx2, color);
|
|
1311
1310
|
},
|
|
1312
|
-
|
|
1311
|
+
decrementAreaYChannel(ctx2, evt) {
|
|
1313
1312
|
const { yChannel } = evt.channel;
|
|
1314
1313
|
const color = ctx2.areaValue.decrementChannel(yChannel, evt.step);
|
|
1315
1314
|
set.value(ctx2, color);
|
|
@@ -1408,14 +1407,12 @@ var invoke = {
|
|
|
1408
1407
|
};
|
|
1409
1408
|
var set = {
|
|
1410
1409
|
value(ctx, color) {
|
|
1411
|
-
if (!color || ctx.value.isEqual(color))
|
|
1412
|
-
return;
|
|
1410
|
+
if (!color || ctx.value.isEqual(color)) return;
|
|
1413
1411
|
ctx.value = color;
|
|
1414
1412
|
invoke.change(ctx);
|
|
1415
1413
|
},
|
|
1416
1414
|
format(ctx, format) {
|
|
1417
|
-
if (ctx.format === format)
|
|
1418
|
-
return;
|
|
1415
|
+
if (ctx.format === format) return;
|
|
1419
1416
|
ctx.format = format;
|
|
1420
1417
|
invoke.formatChange(ctx);
|
|
1421
1418
|
}
|