@zag-js/color-picker 1.21.9 → 1.22.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.js +22 -12
- package/dist/index.mjs +22 -12
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -56,21 +56,27 @@ var getChannelSliderThumbEl = (ctx, channel) => ctx.getById(getChannelSliderThum
|
|
|
56
56
|
var getFormatSelectEl = (ctx) => ctx.getById(getFormatSelectId(ctx));
|
|
57
57
|
var getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
|
|
58
58
|
var getAreaEl = (ctx) => ctx.getById(getAreaId(ctx));
|
|
59
|
-
var getAreaValueFromPoint = (ctx, point) => {
|
|
59
|
+
var getAreaValueFromPoint = (ctx, point, dir) => {
|
|
60
60
|
const areaEl = getAreaEl(ctx);
|
|
61
61
|
if (!areaEl) return;
|
|
62
|
-
const {
|
|
63
|
-
return
|
|
62
|
+
const { getPercentValue } = domQuery.getRelativePoint(point, areaEl);
|
|
63
|
+
return {
|
|
64
|
+
x: getPercentValue({ dir, orientation: "horizontal" }),
|
|
65
|
+
y: getPercentValue({ orientation: "vertical" })
|
|
66
|
+
};
|
|
64
67
|
};
|
|
65
68
|
var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
66
69
|
var getTriggerEl = (ctx) => ctx.getById(getTriggerId(ctx));
|
|
67
70
|
var getPositionerEl = (ctx) => ctx.getById(getPositionerId(ctx));
|
|
68
71
|
var getChannelSliderTrackEl = (ctx, channel) => ctx.getById(getChannelSliderTrackId(ctx, channel));
|
|
69
|
-
var getChannelSliderValueFromPoint = (ctx, point, channel) => {
|
|
72
|
+
var getChannelSliderValueFromPoint = (ctx, point, channel, dir) => {
|
|
70
73
|
const trackEl = getChannelSliderTrackEl(ctx, channel);
|
|
71
74
|
if (!trackEl) return;
|
|
72
|
-
const {
|
|
73
|
-
return
|
|
75
|
+
const { getPercentValue } = domQuery.getRelativePoint(point, trackEl);
|
|
76
|
+
return {
|
|
77
|
+
x: getPercentValue({ dir, orientation: "horizontal" }),
|
|
78
|
+
y: getPercentValue({ orientation: "vertical" })
|
|
79
|
+
};
|
|
74
80
|
};
|
|
75
81
|
var getChannelInputEls = (ctx) => {
|
|
76
82
|
return [
|
|
@@ -415,6 +421,8 @@ function connect(service, normalize) {
|
|
|
415
421
|
const channel = { xChannel, yChannel };
|
|
416
422
|
const xPercent = areaValue.getChannelValuePercent(xChannel);
|
|
417
423
|
const yPercent = 1 - areaValue.getChannelValuePercent(yChannel);
|
|
424
|
+
const isRtl = prop("dir") === "rtl";
|
|
425
|
+
const finalXPercent = isRtl ? 1 - xPercent : xPercent;
|
|
418
426
|
const xValue = areaValue.getChannelValue(xChannel);
|
|
419
427
|
const yValue = areaValue.getChannelValue(yChannel);
|
|
420
428
|
const color = areaValue.withChannelValue("alpha", 1).toString("css");
|
|
@@ -435,7 +443,7 @@ function connect(service, normalize) {
|
|
|
435
443
|
"aria-valuetext": `${xChannel} ${xValue}, ${yChannel} ${yValue}`,
|
|
436
444
|
style: {
|
|
437
445
|
position: "absolute",
|
|
438
|
-
left: `${
|
|
446
|
+
left: `${finalXPercent * 100}%`,
|
|
439
447
|
top: `${yPercent * 100}%`,
|
|
440
448
|
transform: "translate(-50%, -50%)",
|
|
441
449
|
touchAction: "none",
|
|
@@ -573,7 +581,9 @@ function connect(service, normalize) {
|
|
|
573
581
|
const channelRange = normalizedValue.getChannelRange(channel);
|
|
574
582
|
const channelValue = normalizedValue.getChannelValue(channel);
|
|
575
583
|
const offset = (channelValue - channelRange.minValue) / (channelRange.maxValue - channelRange.minValue);
|
|
576
|
-
const
|
|
584
|
+
const isRtl = prop("dir") === "rtl";
|
|
585
|
+
const finalOffset = orientation === "horizontal" && isRtl ? 1 - offset : offset;
|
|
586
|
+
const placementStyles = orientation === "horizontal" ? { left: `${finalOffset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
|
|
577
587
|
return normalize.element({
|
|
578
588
|
...parts.channelSliderThumb.attrs,
|
|
579
589
|
id: getChannelSliderThumbId(scope, channel),
|
|
@@ -1269,20 +1279,20 @@ var machine = core.createMachine({
|
|
|
1269
1279
|
context.set("activeId", null);
|
|
1270
1280
|
context.set("activeOrientation", null);
|
|
1271
1281
|
},
|
|
1272
|
-
setAreaColorFromPoint({ context, event, computed, scope }) {
|
|
1282
|
+
setAreaColorFromPoint({ context, event, computed, scope, prop }) {
|
|
1273
1283
|
const v = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
|
|
1274
1284
|
const { xChannel, yChannel } = event.channel || context.get("activeChannel");
|
|
1275
|
-
const percent = getAreaValueFromPoint(scope, event.point);
|
|
1285
|
+
const percent = getAreaValueFromPoint(scope, event.point, prop("dir"));
|
|
1276
1286
|
if (!percent) return;
|
|
1277
1287
|
const xValue = v.getChannelPercentValue(xChannel, percent.x);
|
|
1278
1288
|
const yValue = v.getChannelPercentValue(yChannel, 1 - percent.y);
|
|
1279
1289
|
const color = v.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
1280
1290
|
context.set("value", color);
|
|
1281
1291
|
},
|
|
1282
|
-
setChannelColorFromPoint({ context, event, computed, scope }) {
|
|
1292
|
+
setChannelColorFromPoint({ context, event, computed, scope, prop }) {
|
|
1283
1293
|
const channel = event.channel || context.get("activeId");
|
|
1284
1294
|
const normalizedValue = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
|
|
1285
|
-
const percent = getChannelSliderValueFromPoint(scope, event.point, channel);
|
|
1295
|
+
const percent = getChannelSliderValueFromPoint(scope, event.point, channel, prop("dir"));
|
|
1286
1296
|
if (!percent) return;
|
|
1287
1297
|
const orientation = context.get("activeOrientation") || "horizontal";
|
|
1288
1298
|
const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
|
package/dist/index.mjs
CHANGED
|
@@ -54,21 +54,27 @@ var getChannelSliderThumbEl = (ctx, channel) => ctx.getById(getChannelSliderThum
|
|
|
54
54
|
var getFormatSelectEl = (ctx) => ctx.getById(getFormatSelectId(ctx));
|
|
55
55
|
var getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
|
|
56
56
|
var getAreaEl = (ctx) => ctx.getById(getAreaId(ctx));
|
|
57
|
-
var getAreaValueFromPoint = (ctx, point) => {
|
|
57
|
+
var getAreaValueFromPoint = (ctx, point, dir) => {
|
|
58
58
|
const areaEl = getAreaEl(ctx);
|
|
59
59
|
if (!areaEl) return;
|
|
60
|
-
const {
|
|
61
|
-
return
|
|
60
|
+
const { getPercentValue } = getRelativePoint(point, areaEl);
|
|
61
|
+
return {
|
|
62
|
+
x: getPercentValue({ dir, orientation: "horizontal" }),
|
|
63
|
+
y: getPercentValue({ orientation: "vertical" })
|
|
64
|
+
};
|
|
62
65
|
};
|
|
63
66
|
var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
64
67
|
var getTriggerEl = (ctx) => ctx.getById(getTriggerId(ctx));
|
|
65
68
|
var getPositionerEl = (ctx) => ctx.getById(getPositionerId(ctx));
|
|
66
69
|
var getChannelSliderTrackEl = (ctx, channel) => ctx.getById(getChannelSliderTrackId(ctx, channel));
|
|
67
|
-
var getChannelSliderValueFromPoint = (ctx, point, channel) => {
|
|
70
|
+
var getChannelSliderValueFromPoint = (ctx, point, channel, dir) => {
|
|
68
71
|
const trackEl = getChannelSliderTrackEl(ctx, channel);
|
|
69
72
|
if (!trackEl) return;
|
|
70
|
-
const {
|
|
71
|
-
return
|
|
73
|
+
const { getPercentValue } = getRelativePoint(point, trackEl);
|
|
74
|
+
return {
|
|
75
|
+
x: getPercentValue({ dir, orientation: "horizontal" }),
|
|
76
|
+
y: getPercentValue({ orientation: "vertical" })
|
|
77
|
+
};
|
|
72
78
|
};
|
|
73
79
|
var getChannelInputEls = (ctx) => {
|
|
74
80
|
return [
|
|
@@ -413,6 +419,8 @@ function connect(service, normalize) {
|
|
|
413
419
|
const channel = { xChannel, yChannel };
|
|
414
420
|
const xPercent = areaValue.getChannelValuePercent(xChannel);
|
|
415
421
|
const yPercent = 1 - areaValue.getChannelValuePercent(yChannel);
|
|
422
|
+
const isRtl = prop("dir") === "rtl";
|
|
423
|
+
const finalXPercent = isRtl ? 1 - xPercent : xPercent;
|
|
416
424
|
const xValue = areaValue.getChannelValue(xChannel);
|
|
417
425
|
const yValue = areaValue.getChannelValue(yChannel);
|
|
418
426
|
const color = areaValue.withChannelValue("alpha", 1).toString("css");
|
|
@@ -433,7 +441,7 @@ function connect(service, normalize) {
|
|
|
433
441
|
"aria-valuetext": `${xChannel} ${xValue}, ${yChannel} ${yValue}`,
|
|
434
442
|
style: {
|
|
435
443
|
position: "absolute",
|
|
436
|
-
left: `${
|
|
444
|
+
left: `${finalXPercent * 100}%`,
|
|
437
445
|
top: `${yPercent * 100}%`,
|
|
438
446
|
transform: "translate(-50%, -50%)",
|
|
439
447
|
touchAction: "none",
|
|
@@ -571,7 +579,9 @@ function connect(service, normalize) {
|
|
|
571
579
|
const channelRange = normalizedValue.getChannelRange(channel);
|
|
572
580
|
const channelValue = normalizedValue.getChannelValue(channel);
|
|
573
581
|
const offset = (channelValue - channelRange.minValue) / (channelRange.maxValue - channelRange.minValue);
|
|
574
|
-
const
|
|
582
|
+
const isRtl = prop("dir") === "rtl";
|
|
583
|
+
const finalOffset = orientation === "horizontal" && isRtl ? 1 - offset : offset;
|
|
584
|
+
const placementStyles = orientation === "horizontal" ? { left: `${finalOffset * 100}%`, top: "50%" } : { top: `${offset * 100}%`, left: "50%" };
|
|
575
585
|
return normalize.element({
|
|
576
586
|
...parts.channelSliderThumb.attrs,
|
|
577
587
|
id: getChannelSliderThumbId(scope, channel),
|
|
@@ -1267,20 +1277,20 @@ var machine = createMachine({
|
|
|
1267
1277
|
context.set("activeId", null);
|
|
1268
1278
|
context.set("activeOrientation", null);
|
|
1269
1279
|
},
|
|
1270
|
-
setAreaColorFromPoint({ context, event, computed, scope }) {
|
|
1280
|
+
setAreaColorFromPoint({ context, event, computed, scope, prop }) {
|
|
1271
1281
|
const v = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
|
|
1272
1282
|
const { xChannel, yChannel } = event.channel || context.get("activeChannel");
|
|
1273
|
-
const percent = getAreaValueFromPoint(scope, event.point);
|
|
1283
|
+
const percent = getAreaValueFromPoint(scope, event.point, prop("dir"));
|
|
1274
1284
|
if (!percent) return;
|
|
1275
1285
|
const xValue = v.getChannelPercentValue(xChannel, percent.x);
|
|
1276
1286
|
const yValue = v.getChannelPercentValue(yChannel, 1 - percent.y);
|
|
1277
1287
|
const color = v.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
1278
1288
|
context.set("value", color);
|
|
1279
1289
|
},
|
|
1280
|
-
setChannelColorFromPoint({ context, event, computed, scope }) {
|
|
1290
|
+
setChannelColorFromPoint({ context, event, computed, scope, prop }) {
|
|
1281
1291
|
const channel = event.channel || context.get("activeId");
|
|
1282
1292
|
const normalizedValue = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
|
|
1283
|
-
const percent = getChannelSliderValueFromPoint(scope, event.point, channel);
|
|
1293
|
+
const percent = getChannelSliderValueFromPoint(scope, event.point, channel, prop("dir"));
|
|
1284
1294
|
if (!percent) return;
|
|
1285
1295
|
const orientation = context.get("activeOrientation") || "horizontal";
|
|
1286
1296
|
const channelPercent = orientation === "horizontal" ? percent.x : percent.y;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/color-picker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Core logic for the color-picker widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/core": "1.
|
|
31
|
-
"@zag-js/anatomy": "1.
|
|
32
|
-
"@zag-js/dom-query": "1.
|
|
33
|
-
"@zag-js/dismissable": "1.
|
|
34
|
-
"@zag-js/utils": "1.
|
|
35
|
-
"@zag-js/color-utils": "1.
|
|
36
|
-
"@zag-js/popper": "1.
|
|
37
|
-
"@zag-js/types": "1.
|
|
30
|
+
"@zag-js/core": "1.22.0",
|
|
31
|
+
"@zag-js/anatomy": "1.22.0",
|
|
32
|
+
"@zag-js/dom-query": "1.22.0",
|
|
33
|
+
"@zag-js/dismissable": "1.22.0",
|
|
34
|
+
"@zag-js/utils": "1.22.0",
|
|
35
|
+
"@zag-js/color-utils": "1.22.0",
|
|
36
|
+
"@zag-js/popper": "1.22.0",
|
|
37
|
+
"@zag-js/types": "1.22.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"clean-package": "2.2.0"
|