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