@zag-js/color-picker 0.55.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.js
CHANGED
|
@@ -91,8 +91,7 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
91
91
|
getAreaEl: (ctx) => dom.getById(ctx, dom.getAreaId(ctx)),
|
|
92
92
|
getAreaValueFromPoint(ctx, point) {
|
|
93
93
|
const areaEl = dom.getAreaEl(ctx);
|
|
94
|
-
if (!areaEl)
|
|
95
|
-
return;
|
|
94
|
+
if (!areaEl) return;
|
|
96
95
|
const { percent } = (0, import_dom_event.getRelativePoint)(point, areaEl);
|
|
97
96
|
return percent;
|
|
98
97
|
},
|
|
@@ -104,8 +103,7 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
104
103
|
},
|
|
105
104
|
getChannelSliderValueFromPoint(ctx, point, channel) {
|
|
106
105
|
const trackEl = dom.getChannelSliderTrackEl(ctx, channel);
|
|
107
|
-
if (!trackEl)
|
|
108
|
-
return;
|
|
106
|
+
if (!trackEl) return;
|
|
109
107
|
const { percent } = (0, import_dom_event.getRelativePoint)(point, trackEl);
|
|
110
108
|
return percent;
|
|
111
109
|
},
|
|
@@ -141,8 +139,7 @@ function getChannelDisplayColor(color, channel) {
|
|
|
141
139
|
// src/utils/get-channel-input-value.ts
|
|
142
140
|
var import_color_utils2 = require("@zag-js/color-utils");
|
|
143
141
|
function getChannelValue(color, channel) {
|
|
144
|
-
if (channel == null)
|
|
145
|
-
return "";
|
|
142
|
+
if (channel == null) return "";
|
|
146
143
|
if (channel === "hex") {
|
|
147
144
|
return color.toString("hex");
|
|
148
145
|
}
|
|
@@ -273,8 +270,7 @@ function connect(state, send, normalize) {
|
|
|
273
270
|
valueAsString,
|
|
274
271
|
value,
|
|
275
272
|
setOpen(nextOpen) {
|
|
276
|
-
if (nextOpen === open)
|
|
277
|
-
return;
|
|
273
|
+
if (nextOpen === open) return;
|
|
278
274
|
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
279
275
|
},
|
|
280
276
|
setValue(value2) {
|
|
@@ -353,13 +349,11 @@ function connect(state, send, normalize) {
|
|
|
353
349
|
"data-focus": (0, import_dom_query2.dataAttr)(focused),
|
|
354
350
|
type: "button",
|
|
355
351
|
onClick() {
|
|
356
|
-
if (!interactive)
|
|
357
|
-
return;
|
|
352
|
+
if (!interactive) return;
|
|
358
353
|
send({ type: "TRIGGER.CLICK" });
|
|
359
354
|
},
|
|
360
355
|
onBlur() {
|
|
361
|
-
if (!interactive)
|
|
362
|
-
return;
|
|
356
|
+
if (!interactive) return;
|
|
363
357
|
send({ type: "TRIGGER.BLUR" });
|
|
364
358
|
},
|
|
365
359
|
style: {
|
|
@@ -397,12 +391,9 @@ function connect(state, send, normalize) {
|
|
|
397
391
|
id: dom.getAreaId(state.context),
|
|
398
392
|
role: "group",
|
|
399
393
|
onPointerDown(event) {
|
|
400
|
-
if (!interactive)
|
|
401
|
-
|
|
402
|
-
if (
|
|
403
|
-
return;
|
|
404
|
-
if ((0, import_dom_event2.isModifierKey)(event))
|
|
405
|
-
return;
|
|
394
|
+
if (!interactive) return;
|
|
395
|
+
if (!(0, import_dom_event2.isLeftClick)(event)) return;
|
|
396
|
+
if ((0, import_dom_event2.isModifierKey)(event)) return;
|
|
406
397
|
const point = (0, import_dom_event2.getEventPoint)(event);
|
|
407
398
|
const channel = { xChannel, yChannel };
|
|
408
399
|
send({ type: "AREA.POINTER_DOWN", point, channel, id: "area" });
|
|
@@ -464,15 +455,12 @@ function connect(state, send, normalize) {
|
|
|
464
455
|
background: areaValue.withChannelValue("alpha", 1).toString("css")
|
|
465
456
|
},
|
|
466
457
|
onFocus() {
|
|
467
|
-
if (!interactive)
|
|
468
|
-
return;
|
|
458
|
+
if (!interactive) return;
|
|
469
459
|
send({ type: "AREA.FOCUS", id: "area", channel });
|
|
470
460
|
},
|
|
471
461
|
onKeyDown(event) {
|
|
472
|
-
if (event.defaultPrevented)
|
|
473
|
-
|
|
474
|
-
if (!interactive)
|
|
475
|
-
return;
|
|
462
|
+
if (event.defaultPrevented) return;
|
|
463
|
+
if (!interactive) return;
|
|
476
464
|
const step = (0, import_dom_event2.getEventStep)(event);
|
|
477
465
|
const keyMap = {
|
|
478
466
|
ArrowUp() {
|
|
@@ -531,12 +519,9 @@ function connect(state, send, normalize) {
|
|
|
531
519
|
"data-orientation": orientation,
|
|
532
520
|
role: "presentation",
|
|
533
521
|
onPointerDown(event) {
|
|
534
|
-
if (!interactive)
|
|
535
|
-
|
|
536
|
-
if (
|
|
537
|
-
return;
|
|
538
|
-
if ((0, import_dom_event2.isModifierKey)(event))
|
|
539
|
-
return;
|
|
522
|
+
if (!interactive) return;
|
|
523
|
+
if (!(0, import_dom_event2.isLeftClick)(event)) return;
|
|
524
|
+
if ((0, import_dom_event2.isModifierKey)(event)) return;
|
|
540
525
|
const point = (0, import_dom_event2.getEventPoint)(event);
|
|
541
526
|
send({ type: "CHANNEL_SLIDER.POINTER_DOWN", channel, point, id: channel, orientation });
|
|
542
527
|
event.preventDefault();
|
|
@@ -595,15 +580,12 @@ function connect(state, send, normalize) {
|
|
|
595
580
|
...placementStyles
|
|
596
581
|
},
|
|
597
582
|
onFocus() {
|
|
598
|
-
if (!interactive)
|
|
599
|
-
return;
|
|
583
|
+
if (!interactive) return;
|
|
600
584
|
send({ type: "CHANNEL_SLIDER.FOCUS", channel });
|
|
601
585
|
},
|
|
602
586
|
onKeyDown(event) {
|
|
603
|
-
if (event.defaultPrevented)
|
|
604
|
-
|
|
605
|
-
if (!interactive)
|
|
606
|
-
return;
|
|
587
|
+
if (event.defaultPrevented) return;
|
|
588
|
+
if (!interactive) return;
|
|
607
589
|
const step = (0, import_dom_event2.getEventStep)(event) * stepValue;
|
|
608
590
|
const keyMap = {
|
|
609
591
|
ArrowUp() {
|
|
@@ -662,30 +644,25 @@ function connect(state, send, normalize) {
|
|
|
662
644
|
max: range?.maxValue,
|
|
663
645
|
step: range?.step,
|
|
664
646
|
onBeforeInput(event) {
|
|
665
|
-
if (isTextField || !interactive)
|
|
666
|
-
return;
|
|
647
|
+
if (isTextField || !interactive) return;
|
|
667
648
|
const value2 = event.currentTarget.value;
|
|
668
649
|
if (value2.match(/[^0-9.]/g)) {
|
|
669
650
|
event.preventDefault();
|
|
670
651
|
}
|
|
671
652
|
},
|
|
672
653
|
onFocus(event) {
|
|
673
|
-
if (!interactive)
|
|
674
|
-
return;
|
|
654
|
+
if (!interactive) return;
|
|
675
655
|
send({ type: "CHANNEL_INPUT.FOCUS", channel });
|
|
676
656
|
event.target.select();
|
|
677
657
|
},
|
|
678
658
|
onBlur(event) {
|
|
679
|
-
if (!interactive)
|
|
680
|
-
return;
|
|
659
|
+
if (!interactive) return;
|
|
681
660
|
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
682
661
|
send({ type: "CHANNEL_INPUT.BLUR", channel, value: value2, isTextField });
|
|
683
662
|
},
|
|
684
663
|
onKeyDown(event) {
|
|
685
|
-
if (event.defaultPrevented)
|
|
686
|
-
|
|
687
|
-
if (!interactive)
|
|
688
|
-
return;
|
|
664
|
+
if (event.defaultPrevented) return;
|
|
665
|
+
if (!interactive) return;
|
|
689
666
|
if (event.key === "Enter") {
|
|
690
667
|
const value2 = isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber;
|
|
691
668
|
send({ type: "CHANNEL_INPUT.CHANGE", channel, value: value2, isTextField });
|
|
@@ -718,8 +695,7 @@ function connect(state, send, normalize) {
|
|
|
718
695
|
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
719
696
|
"aria-label": "Pick a color from the screen",
|
|
720
697
|
onClick() {
|
|
721
|
-
if (!interactive)
|
|
722
|
-
return;
|
|
698
|
+
if (!interactive) return;
|
|
723
699
|
send("EYEDROPPER.CLICK");
|
|
724
700
|
}
|
|
725
701
|
});
|
|
@@ -743,8 +719,7 @@ function connect(state, send, normalize) {
|
|
|
743
719
|
"data-value": swatchState.valueAsString,
|
|
744
720
|
"data-disabled": (0, import_dom_query2.dataAttr)(swatchState.disabled),
|
|
745
721
|
onClick() {
|
|
746
|
-
if (swatchState.disabled)
|
|
747
|
-
return;
|
|
722
|
+
if (swatchState.disabled) return;
|
|
748
723
|
send({ type: "SWATCH_TRIGGER.CLICK", value: swatchState.value });
|
|
749
724
|
},
|
|
750
725
|
style: {
|
|
@@ -781,8 +756,7 @@ function connect(state, send, normalize) {
|
|
|
781
756
|
type: "button",
|
|
782
757
|
"aria-label": `change color format to ${getNextFormat(state.context.format)}`,
|
|
783
758
|
onClick(event) {
|
|
784
|
-
if (event.currentTarget.disabled)
|
|
785
|
-
return;
|
|
759
|
+
if (event.currentTarget.disabled) return;
|
|
786
760
|
const nextFormat = getNextFormat(state.context.format);
|
|
787
761
|
send({ type: "FORMAT.SET", format: nextFormat, src: "format-trigger" });
|
|
788
762
|
}
|
|
@@ -810,8 +784,7 @@ function getNextFormat(format) {
|
|
|
810
784
|
return formats[index + 1] ?? formats[0];
|
|
811
785
|
}
|
|
812
786
|
function assertFormat(format) {
|
|
813
|
-
if (formatRegex.test(format))
|
|
814
|
-
return format;
|
|
787
|
+
if (formatRegex.test(format)) return format;
|
|
815
788
|
throw new Error(`Unsupported color format: ${format}`);
|
|
816
789
|
}
|
|
817
790
|
|
|
@@ -1168,8 +1141,7 @@ function machine(userContext) {
|
|
|
1168
1141
|
defer: true,
|
|
1169
1142
|
onInteractOutside(event) {
|
|
1170
1143
|
ctx2.onInteractOutside?.(event);
|
|
1171
|
-
if (event.defaultPrevented)
|
|
1172
|
-
return;
|
|
1144
|
+
if (event.defaultPrevented) return;
|
|
1173
1145
|
ctx2.restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
1174
1146
|
},
|
|
1175
1147
|
onPointerDownOutside: ctx2.onPointerDownOutside,
|
|
@@ -1209,8 +1181,7 @@ function machine(userContext) {
|
|
|
1209
1181
|
actions: {
|
|
1210
1182
|
openEyeDropper(ctx2) {
|
|
1211
1183
|
const isSupported = "EyeDropper" in dom.getWin(ctx2);
|
|
1212
|
-
if (!isSupported)
|
|
1213
|
-
return;
|
|
1184
|
+
if (!isSupported) return;
|
|
1214
1185
|
const win = dom.getWin(ctx2);
|
|
1215
1186
|
const picker = new win.EyeDropper();
|
|
1216
1187
|
picker.open().then(({ sRGBHex }) => {
|
|
@@ -1222,10 +1193,8 @@ function machine(userContext) {
|
|
|
1222
1193
|
},
|
|
1223
1194
|
setActiveChannel(ctx2, evt) {
|
|
1224
1195
|
ctx2.activeId = evt.id;
|
|
1225
|
-
if (evt.channel)
|
|
1226
|
-
|
|
1227
|
-
if (evt.orientation)
|
|
1228
|
-
ctx2.activeOrientation = evt.orientation;
|
|
1196
|
+
if (evt.channel) ctx2.activeChannel = evt.channel;
|
|
1197
|
+
if (evt.orientation) ctx2.activeOrientation = evt.orientation;
|
|
1229
1198
|
},
|
|
1230
1199
|
clearActiveChannel(ctx2) {
|
|
1231
1200
|
ctx2.activeChannel = null;
|
|
@@ -1235,8 +1204,7 @@ function machine(userContext) {
|
|
|
1235
1204
|
setAreaColorFromPoint(ctx2, evt) {
|
|
1236
1205
|
const { xChannel, yChannel } = evt.channel || ctx2.activeChannel;
|
|
1237
1206
|
const percent = dom.getAreaValueFromPoint(ctx2, evt.point);
|
|
1238
|
-
if (!percent)
|
|
1239
|
-
return;
|
|
1207
|
+
if (!percent) return;
|
|
1240
1208
|
const xValue = ctx2.areaValue.getChannelPercentValue(xChannel, percent.x);
|
|
1241
1209
|
const yValue = ctx2.areaValue.getChannelPercentValue(yChannel, 1 - percent.y);
|
|
1242
1210
|
const color = ctx2.areaValue.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
@@ -1245,8 +1213,7 @@ function machine(userContext) {
|
|
|
1245
1213
|
setChannelColorFromPoint(ctx2, evt) {
|
|
1246
1214
|
const channel = evt.channel || ctx2.activeId;
|
|
1247
1215
|
const percent = dom.getChannelSliderValueFromPoint(ctx2, evt.point, channel);
|
|
1248
|
-
if (!percent)
|
|
1249
|
-
return;
|
|
1216
|
+
if (!percent) return;
|
|
1250
1217
|
const orientation = ctx2.activeOrientation || "horizontal";
|
|
1251
1218
|
const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
|
|
1252
1219
|
const value = ctx2.areaValue.getChannelPercentValue(channel, channelPercent);
|
|
@@ -1408,14 +1375,12 @@ var invoke = {
|
|
|
1408
1375
|
};
|
|
1409
1376
|
var set = {
|
|
1410
1377
|
value(ctx, color) {
|
|
1411
|
-
if (!color || ctx.value.isEqual(color))
|
|
1412
|
-
return;
|
|
1378
|
+
if (!color || ctx.value.isEqual(color)) return;
|
|
1413
1379
|
ctx.value = color;
|
|
1414
1380
|
invoke.change(ctx);
|
|
1415
1381
|
},
|
|
1416
1382
|
format(ctx, format) {
|
|
1417
|
-
if (ctx.format === format)
|
|
1418
|
-
return;
|
|
1383
|
+
if (ctx.format === format) return;
|
|
1419
1384
|
ctx.format = format;
|
|
1420
1385
|
invoke.formatChange(ctx);
|
|
1421
1386
|
}
|