@zag-js/color-picker 0.56.0 → 0.56.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.
- package/dist/index.js +35 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -70
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
package/dist/index.mjs
CHANGED
|
@@ -68,8 +68,7 @@ var dom = createScope({
|
|
|
68
68
|
getAreaEl: (ctx) => dom.getById(ctx, dom.getAreaId(ctx)),
|
|
69
69
|
getAreaValueFromPoint(ctx, point) {
|
|
70
70
|
const areaEl = dom.getAreaEl(ctx);
|
|
71
|
-
if (!areaEl)
|
|
72
|
-
return;
|
|
71
|
+
if (!areaEl) return;
|
|
73
72
|
const { percent } = getRelativePoint(point, areaEl);
|
|
74
73
|
return percent;
|
|
75
74
|
},
|
|
@@ -81,8 +80,7 @@ var dom = createScope({
|
|
|
81
80
|
},
|
|
82
81
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
83
82
|
const trackEl = dom.getChannelSliderTrackEl(ctx, channel);
|
|
84
|
-
if (!trackEl)
|
|
85
|
-
return;
|
|
83
|
+
if (!trackEl) return;
|
|
86
84
|
const { percent } = getRelativePoint(point, trackEl);
|
|
87
85
|
return percent;
|
|
88
86
|
},
|
|
@@ -118,8 +116,7 @@ function getChannelDisplayColor(color, channel) {
|
|
|
118
116
|
// src/utils/get-channel-input-value.ts
|
|
119
117
|
import { parseColor as parseColor2 } from "@zag-js/color-utils";
|
|
120
118
|
function getChannelValue(color, channel) {
|
|
121
|
-
if (channel == null)
|
|
122
|
-
return "";
|
|
119
|
+
if (channel == null) return "";
|
|
123
120
|
if (channel === "hex") {
|
|
124
121
|
return color.toString("hex");
|
|
125
122
|
}
|
|
@@ -250,8 +247,7 @@ function connect(state, send, normalize) {
|
|
|
250
247
|
valueAsString,
|
|
251
248
|
value,
|
|
252
249
|
setOpen(nextOpen) {
|
|
253
|
-
if (nextOpen === open)
|
|
254
|
-
return;
|
|
250
|
+
if (nextOpen === open) return;
|
|
255
251
|
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
256
252
|
},
|
|
257
253
|
setValue(value2) {
|
|
@@ -330,13 +326,11 @@ function connect(state, send, normalize) {
|
|
|
330
326
|
"data-focus": dataAttr(focused),
|
|
331
327
|
type: "button",
|
|
332
328
|
onClick() {
|
|
333
|
-
if (!interactive)
|
|
334
|
-
return;
|
|
329
|
+
if (!interactive) return;
|
|
335
330
|
send({ type: "TRIGGER.CLICK" });
|
|
336
331
|
},
|
|
337
332
|
onBlur() {
|
|
338
|
-
if (!interactive)
|
|
339
|
-
return;
|
|
333
|
+
if (!interactive) return;
|
|
340
334
|
send({ type: "TRIGGER.BLUR" });
|
|
341
335
|
},
|
|
342
336
|
style: {
|
|
@@ -374,12 +368,9 @@ function connect(state, send, normalize) {
|
|
|
374
368
|
id: dom.getAreaId(state.context),
|
|
375
369
|
role: "group",
|
|
376
370
|
onPointerDown(event) {
|
|
377
|
-
if (!interactive)
|
|
378
|
-
|
|
379
|
-
if (
|
|
380
|
-
return;
|
|
381
|
-
if (isModifierKey(event))
|
|
382
|
-
return;
|
|
371
|
+
if (!interactive) return;
|
|
372
|
+
if (!isLeftClick(event)) return;
|
|
373
|
+
if (isModifierKey(event)) return;
|
|
383
374
|
const point = getEventPoint(event);
|
|
384
375
|
const channel = { xChannel, yChannel };
|
|
385
376
|
send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
|
|
@@ -441,15 +432,12 @@ function connect(state, send, normalize) {
|
|
|
441
432
|
background: areaValue.withChannelValue("alpha", 1).toString("css")
|
|
442
433
|
},
|
|
443
434
|
onFocus() {
|
|
444
|
-
if (!interactive)
|
|
445
|
-
return;
|
|
435
|
+
if (!interactive) return;
|
|
446
436
|
send({ type: "AREA.FOCUS", id: "area", channel });
|
|
447
437
|
},
|
|
448
438
|
onKeyDown(event) {
|
|
449
|
-
if (event.defaultPrevented)
|
|
450
|
-
|
|
451
|
-
if (!interactive)
|
|
452
|
-
return;
|
|
439
|
+
if (event.defaultPrevented) return;
|
|
440
|
+
if (!interactive) return;
|
|
453
441
|
const step = getEventStep(event);
|
|
454
442
|
const keyMap = {
|
|
455
443
|
ArrowUp() {
|
|
@@ -508,12 +496,9 @@ function connect(state, send, normalize) {
|
|
|
508
496
|
"data-orientation": orientation,
|
|
509
497
|
role: "presentation",
|
|
510
498
|
onPointerDown(event) {
|
|
511
|
-
if (!interactive)
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
return;
|
|
515
|
-
if (isModifierKey(event))
|
|
516
|
-
return;
|
|
499
|
+
if (!interactive) return;
|
|
500
|
+
if (!isLeftClick(event)) return;
|
|
501
|
+
if (isModifierKey(event)) return;
|
|
517
502
|
const point = getEventPoint(event);
|
|
518
503
|
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
|
|
519
504
|
event.preventDefault();
|
|
@@ -572,15 +557,12 @@ function connect(state, send, normalize) {
|
|
|
572
557
|
...placementStyles
|
|
573
558
|
},
|
|
574
559
|
onFocus() {
|
|
575
|
-
if (!interactive)
|
|
576
|
-
return;
|
|
560
|
+
if (!interactive) return;
|
|
577
561
|
send({ type: "CHANNEL_SLIDER.FOCUS", channel });
|
|
578
562
|
},
|
|
579
563
|
onKeyDown(event) {
|
|
580
|
-
if (event.defaultPrevented)
|
|
581
|
-
|
|
582
|
-
if (!interactive)
|
|
583
|
-
return;
|
|
564
|
+
if (event.defaultPrevented) return;
|
|
565
|
+
if (!interactive) return;
|
|
584
566
|
const step = getEventStep(event) * stepValue;
|
|
585
567
|
const keyMap = {
|
|
586
568
|
ArrowUp() {
|
|
@@ -639,30 +621,25 @@ function connect(state, send, normalize) {
|
|
|
639
621
|
max: range?.maxValue,
|
|
640
622
|
step: range?.step,
|
|
641
623
|
onBeforeInput(event) {
|
|
642
|
-
if (isTextField || !interactive)
|
|
643
|
-
return;
|
|
624
|
+
if (isTextField || !interactive) return;
|
|
644
625
|
const value2 = event.currentTarget.value;
|
|
645
626
|
if (value2.match(/[^0-9.]/g)) {
|
|
646
627
|
event.preventDefault();
|
|
647
628
|
}
|
|
648
629
|
},
|
|
649
630
|
onFocus(event) {
|
|
650
|
-
if (!interactive)
|
|
651
|
-
return;
|
|
631
|
+
if (!interactive) return;
|
|
652
632
|
send({ type: "CHANNEL_INPUT.FOCUS", channel });
|
|
653
633
|
event.target.select();
|
|
654
634
|
},
|
|
655
635
|
onBlur(event) {
|
|
656
|
-
if (!interactive)
|
|
657
|
-
return;
|
|
636
|
+
if (!interactive) return;
|
|
658
637
|
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
659
638
|
send({ type: "CHANNEL_INPUT.BLUR", channel, value: value2, isTextField });
|
|
660
639
|
},
|
|
661
640
|
onKeyDown(event) {
|
|
662
|
-
if (event.defaultPrevented)
|
|
663
|
-
|
|
664
|
-
if (!interactive)
|
|
665
|
-
return;
|
|
641
|
+
if (event.defaultPrevented) return;
|
|
642
|
+
if (!interactive) return;
|
|
666
643
|
if (event.key === "Enter") {
|
|
667
644
|
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
668
645
|
send({ type: "CHANNEL_INPUT.CHANGE", channel, value: value2, isTextField });
|
|
@@ -695,8 +672,7 @@ function connect(state, send, normalize) {
|
|
|
695
672
|
"data-disabled": dataAttr(disabled),
|
|
696
673
|
"aria-label": "Pick a color from the screen",
|
|
697
674
|
onClick() {
|
|
698
|
-
if (!interactive)
|
|
699
|
-
return;
|
|
675
|
+
if (!interactive) return;
|
|
700
676
|
send("EYEDROPPER.CLICK");
|
|
701
677
|
}
|
|
702
678
|
});
|
|
@@ -720,8 +696,7 @@ function connect(state, send, normalize) {
|
|
|
720
696
|
"data-value": swatchState.valueAsString,
|
|
721
697
|
"data-disabled": dataAttr(swatchState.disabled),
|
|
722
698
|
onClick() {
|
|
723
|
-
if (swatchState.disabled)
|
|
724
|
-
return;
|
|
699
|
+
if (swatchState.disabled) return;
|
|
725
700
|
send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value });
|
|
726
701
|
},
|
|
727
702
|
style: {
|
|
@@ -758,8 +733,7 @@ function connect(state, send, normalize) {
|
|
|
758
733
|
type: "button",
|
|
759
734
|
"aria-label": `change color format to ${getNextFormat(state.context.format)}`,
|
|
760
735
|
onClick(event) {
|
|
761
|
-
if (event.currentTarget.disabled)
|
|
762
|
-
return;
|
|
736
|
+
if (event.currentTarget.disabled) return;
|
|
763
737
|
const nextFormat = getNextFormat(state.context.format);
|
|
764
738
|
send({ type: "FORMAT.SET", format: nextFormat, src: "format-trigger" });
|
|
765
739
|
}
|
|
@@ -787,8 +761,7 @@ function getNextFormat(format) {
|
|
|
787
761
|
return formats[index + 1] ?? formats[0];
|
|
788
762
|
}
|
|
789
763
|
function assertFormat(format) {
|
|
790
|
-
if (formatRegex.test(format))
|
|
791
|
-
return format;
|
|
764
|
+
if (formatRegex.test(format)) return format;
|
|
792
765
|
throw new Error(`Unsupported color format: ${format}`);
|
|
793
766
|
}
|
|
794
767
|
|
|
@@ -1145,8 +1118,7 @@ function machine(userContext) {
|
|
|
1145
1118
|
defer: true,
|
|
1146
1119
|
onInteractOutside(event) {
|
|
1147
1120
|
ctx2.onInteractOutside?.(event);
|
|
1148
|
-
if (event.defaultPrevented)
|
|
1149
|
-
return;
|
|
1121
|
+
if (event.defaultPrevented) return;
|
|
1150
1122
|
ctx2.restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
1151
1123
|
},
|
|
1152
1124
|
onPointerDownOutside: ctx2.onPointerDownOutside,
|
|
@@ -1186,8 +1158,7 @@ function machine(userContext) {
|
|
|
1186
1158
|
actions: {
|
|
1187
1159
|
openEyeDropper(ctx2) {
|
|
1188
1160
|
const isSupported = "EyeDropper" in dom.getWin(ctx2);
|
|
1189
|
-
if (!isSupported)
|
|
1190
|
-
return;
|
|
1161
|
+
if (!isSupported) return;
|
|
1191
1162
|
const win = dom.getWin(ctx2);
|
|
1192
1163
|
const picker = new win.EyeDropper();
|
|
1193
1164
|
picker.open().then(({ sRGBHex }) => {
|
|
@@ -1199,10 +1170,8 @@ function machine(userContext) {
|
|
|
1199
1170
|
},
|
|
1200
1171
|
setActiveChannel(ctx2, evt) {
|
|
1201
1172
|
ctx2.activeId = evt.id;
|
|
1202
|
-
if (evt.channel)
|
|
1203
|
-
|
|
1204
|
-
if (evt.orientation)
|
|
1205
|
-
ctx2.activeOrientation = evt.orientation;
|
|
1173
|
+
if (evt.channel) ctx2.activeChannel = evt.channel;
|
|
1174
|
+
if (evt.orientation) ctx2.activeOrientation = evt.orientation;
|
|
1206
1175
|
},
|
|
1207
1176
|
clearActiveChannel(ctx2) {
|
|
1208
1177
|
ctx2.activeChannel = null;
|
|
@@ -1212,8 +1181,7 @@ function machine(userContext) {
|
|
|
1212
1181
|
setAreaColorFromPoint(ctx2, evt) {
|
|
1213
1182
|
const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
|
|
1214
1183
|
const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
|
|
1215
|
-
if (!percent)
|
|
1216
|
-
return;
|
|
1184
|
+
if (!percent) return;
|
|
1217
1185
|
const xValue = ctx2.areaValue.getChannelPercentValue(xChannel, percent.x);
|
|
1218
1186
|
const yValue = ctx2.areaValue.getChannelPercentValue(yChannel, 1 - percent.y);
|
|
1219
1187
|
const color = ctx2.areaValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
@@ -1222,8 +1190,7 @@ function machine(userContext) {
|
|
|
1222
1190
|
setChannelColorFromPoint(ctx2, evt) {
|
|
1223
1191
|
const channel = evt.channel || ctx2.activeId;
|
|
1224
1192
|
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
1225
|
-
if (!percent)
|
|
1226
|
-
return;
|
|
1193
|
+
if (!percent) return;
|
|
1227
1194
|
const orientation = ctx2.activeOrientation || "horizontal";
|
|
1228
1195
|
const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
|
|
1229
1196
|
const value = ctx2.areaValue.getChannelPercentValue(channel, channelPercent);
|
|
@@ -1385,14 +1352,12 @@ var invoke = {
|
|
|
1385
1352
|
};
|
|
1386
1353
|
var set = {
|
|
1387
1354
|
value(ctx, color) {
|
|
1388
|
-
if (!color || ctx.value.isEqual(color))
|
|
1389
|
-
return;
|
|
1355
|
+
if (!color || ctx.value.isEqual(color)) return;
|
|
1390
1356
|
ctx.value = color;
|
|
1391
1357
|
invoke.change(ctx);
|
|
1392
1358
|
},
|
|
1393
1359
|
format(ctx, format) {
|
|
1394
|
-
if (ctx.format === format)
|
|
1395
|
-
return;
|
|
1360
|
+
if (ctx.format === format) return;
|
|
1396
1361
|
ctx.format = format;
|
|
1397
1362
|
invoke.formatChange(ctx);
|
|
1398
1363
|
}
|