@zag-js/slider 1.47.0 → 1.48.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 +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +16 -38
- package/dist/index.mjs +2 -7
- package/dist/slider.anatomy.d.mts +2 -6
- package/dist/slider.anatomy.d.ts +2 -6
- package/dist/slider.anatomy.js +8 -44
- package/dist/slider.anatomy.mjs +4 -18
- package/dist/slider.connect.d.mts +3 -7
- package/dist/slider.connect.d.ts +3 -7
- package/dist/slider.connect.js +371 -351
- package/dist/slider.connect.mjs +366 -330
- package/dist/slider.dom.d.mts +27 -30
- package/dist/slider.dom.d.ts +27 -30
- package/dist/slider.dom.js +93 -137
- package/dist/slider.dom.mjs +70 -93
- package/dist/slider.machine.d.mts +2 -7
- package/dist/slider.machine.d.ts +2 -7
- package/dist/slider.machine.js +322 -367
- package/dist/slider.machine.mjs +318 -351
- package/dist/slider.props.d.mts +7 -12
- package/dist/slider.props.d.ts +7 -12
- package/dist/slider.props.js +45 -73
- package/dist/slider.props.mjs +36 -43
- package/dist/slider.style.d.mts +15 -17
- package/dist/slider.style.d.ts +15 -17
- package/dist/slider.style.js +126 -156
- package/dist/slider.style.mjs +114 -123
- package/dist/slider.types.d.mts +307 -309
- package/dist/slider.types.d.ts +307 -309
- package/dist/slider.types.js +4 -18
- package/dist/slider.types.mjs +1 -0
- package/dist/slider.utils.d.mts +18 -21
- package/dist/slider.utils.d.ts +18 -21
- package/dist/slider.utils.js +144 -168
- package/dist/slider.utils.mjs +132 -135
- package/package.json +8 -8
package/dist/slider.style.mjs
CHANGED
|
@@ -1,150 +1,141 @@
|
|
|
1
|
-
// src/slider.style.ts
|
|
2
1
|
import { getValuePercent, getValueTransformer, toPx } from "@zag-js/utils";
|
|
2
|
+
// src/slider.style.ts
|
|
3
3
|
function getBounds(value) {
|
|
4
|
-
|
|
5
|
-
const lastThumb = value[value.length - 1];
|
|
6
|
-
return [firstValue, lastThumb];
|
|
4
|
+
return [value[0], value[value.length - 1]];
|
|
7
5
|
}
|
|
8
6
|
function getRangeOffsets(params) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const { prop, computed } = params;
|
|
8
|
+
const valuePercent = computed("valuePercent");
|
|
9
|
+
const [firstPercent, lastPercent] = getBounds(valuePercent);
|
|
10
|
+
if (valuePercent.length === 1) {
|
|
11
|
+
if (prop("origin") === "center") {
|
|
12
|
+
const isNegative = valuePercent[0] < 50;
|
|
13
|
+
return {
|
|
14
|
+
start: isNegative ? `${valuePercent[0]}%` : "50%",
|
|
15
|
+
end: isNegative ? "50%" : `${100 - valuePercent[0]}%`
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (prop("origin") === "end") return {
|
|
19
|
+
start: `${lastPercent}%`,
|
|
20
|
+
end: "0%"
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
start: "0%",
|
|
24
|
+
end: `${100 - lastPercent}%`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
start: `${firstPercent}%`,
|
|
29
|
+
end: `${100 - lastPercent}%`
|
|
30
|
+
};
|
|
25
31
|
}
|
|
26
32
|
function getRangeStyle(params) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
[isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
41
|
-
};
|
|
33
|
+
const { computed } = params;
|
|
34
|
+
const isVertical = computed("isVertical");
|
|
35
|
+
const isRtl = computed("isRtl");
|
|
36
|
+
if (isVertical) return {
|
|
37
|
+
position: "absolute",
|
|
38
|
+
bottom: "var(--slider-range-start)",
|
|
39
|
+
top: "var(--slider-range-end)"
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
position: "absolute",
|
|
43
|
+
[isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
44
|
+
[isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
45
|
+
};
|
|
42
46
|
}
|
|
43
47
|
function getVerticalThumbOffset(params, value) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const { context, prop } = params;
|
|
49
|
+
const { height = 0 } = context.get("thumbSize") ?? {};
|
|
50
|
+
const getValue = getValueTransformer([prop("min"), prop("max")], [-height / 2, height / 2]);
|
|
51
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
48
52
|
}
|
|
49
53
|
function getHorizontalThumbOffset(params, value) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return parseFloat(getValue(value).toFixed(2));
|
|
54
|
+
const { computed, context, prop } = params;
|
|
55
|
+
const { width = 0 } = context.get("thumbSize") ?? {};
|
|
56
|
+
if (computed("isRtl")) {
|
|
57
|
+
const getValue = getValueTransformer([prop("max"), prop("min")], [-width / 2, width / 2]);
|
|
58
|
+
return -1 * parseFloat(getValue(value).toFixed(2));
|
|
59
|
+
}
|
|
60
|
+
const getValue = getValueTransformer([prop("min"), prop("max")], [-width / 2, width / 2]);
|
|
61
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
59
62
|
}
|
|
60
63
|
function getOffset(params, percent, value) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return `calc(${percent}% - ${offset}px)`;
|
|
64
|
+
const { computed, prop } = params;
|
|
65
|
+
if (prop("thumbAlignment") === "center") return `${percent}%`;
|
|
66
|
+
return `calc(${percent}% - ${computed("isVertical") ? getVerticalThumbOffset(params, value) : getHorizontalThumbOffset(params, value)}px)`;
|
|
65
67
|
}
|
|
66
68
|
function getThumbOffset(params, value) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return getOffset(params, percent, value);
|
|
69
|
+
const { prop } = params;
|
|
70
|
+
return getOffset(params, getValuePercent(value, prop("min"), prop("max")) * 100, value);
|
|
70
71
|
}
|
|
71
72
|
function getVisibility(params) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
return visibility;
|
|
73
|
+
const { computed, prop } = params;
|
|
74
|
+
let visibility = "visible";
|
|
75
|
+
if (prop("thumbAlignment") === "contain" && !computed("hasMeasuredThumbSize")) visibility = "hidden";
|
|
76
|
+
return visibility;
|
|
78
77
|
}
|
|
79
78
|
function getThumbStyle(params, index) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
const { computed, context } = params;
|
|
80
|
+
const placementProp = computed("isVertical") ? "bottom" : "insetInlineStart";
|
|
81
|
+
const focusedIndex = context.get("focusedIndex");
|
|
82
|
+
return {
|
|
83
|
+
visibility: getVisibility(params),
|
|
84
|
+
position: "absolute",
|
|
85
|
+
transform: "var(--slider-thumb-transform)",
|
|
86
|
+
[placementProp]: `var(--slider-thumb-offset-${index})`,
|
|
87
|
+
zIndex: focusedIndex === index ? 1 : void 0
|
|
88
|
+
};
|
|
90
89
|
}
|
|
91
90
|
function getControlStyle() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
return {
|
|
92
|
+
touchAction: "none",
|
|
93
|
+
userSelect: "none",
|
|
94
|
+
WebkitUserSelect: "none",
|
|
95
|
+
position: "relative"
|
|
96
|
+
};
|
|
98
97
|
}
|
|
99
98
|
function getRootStyle(params) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
const { context, computed } = params;
|
|
100
|
+
const isVertical = computed("isVertical");
|
|
101
|
+
const isRtl = computed("isRtl");
|
|
102
|
+
const range = getRangeOffsets(params);
|
|
103
|
+
const thumbSize = context.get("thumbSize");
|
|
104
|
+
return {
|
|
105
|
+
...context.get("value").reduce((styles, value, index) => {
|
|
106
|
+
const offset = getThumbOffset(params, value);
|
|
107
|
+
return {
|
|
108
|
+
...styles,
|
|
109
|
+
[`--slider-thumb-offset-${index}`]: offset
|
|
110
|
+
};
|
|
111
|
+
}, {}),
|
|
112
|
+
"--slider-thumb-width": toPx(thumbSize?.width),
|
|
113
|
+
"--slider-thumb-height": toPx(thumbSize?.height),
|
|
114
|
+
"--slider-thumb-transform": isVertical ? "translateY(50%)" : isRtl ? "translateX(50%)" : "translateX(-50%)",
|
|
115
|
+
"--slider-range-start": range.start,
|
|
116
|
+
"--slider-range-end": range.end
|
|
117
|
+
};
|
|
117
118
|
}
|
|
118
119
|
function getMarkerStyle(params, value) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
120
|
+
const { computed } = params;
|
|
121
|
+
const isHorizontal = computed("isHorizontal");
|
|
122
|
+
const isRtl = computed("isRtl");
|
|
123
|
+
return {
|
|
124
|
+
visibility: getVisibility(params),
|
|
125
|
+
position: "absolute",
|
|
126
|
+
pointerEvents: "none",
|
|
127
|
+
[isHorizontal ? "insetInlineStart" : "bottom"]: getThumbOffset(params, value),
|
|
128
|
+
translate: "var(--translate-x) var(--translate-y)",
|
|
129
|
+
"--translate-x": isHorizontal ? isRtl ? "50%" : "-50%" : "0%",
|
|
130
|
+
"--translate-y": !isHorizontal ? "50%" : "0%"
|
|
131
|
+
};
|
|
131
132
|
}
|
|
132
133
|
function getMarkerGroupStyle() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
return {
|
|
135
|
+
userSelect: "none",
|
|
136
|
+
WebkitUserSelect: "none",
|
|
137
|
+
pointerEvents: "none",
|
|
138
|
+
position: "relative"
|
|
139
|
+
};
|
|
139
140
|
}
|
|
140
|
-
export {
|
|
141
|
-
getControlStyle,
|
|
142
|
-
getMarkerGroupStyle,
|
|
143
|
-
getMarkerStyle,
|
|
144
|
-
getRangeOffsets,
|
|
145
|
-
getRangeStyle,
|
|
146
|
-
getRootStyle,
|
|
147
|
-
getThumbOffset,
|
|
148
|
-
getThumbStyle,
|
|
149
|
-
getVisibility
|
|
150
|
-
};
|
|
141
|
+
export { getControlStyle, getMarkerGroupStyle, getMarkerStyle, getRangeOffsets, getRangeStyle, getRootStyle, getThumbOffset, getThumbStyle, getVisibility };
|