@zag-js/slider 0.2.6 → 0.2.8
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/chunk-3Y7IIPR5.mjs +20 -0
- package/dist/chunk-6D4ETNPG.mjs +288 -0
- package/dist/chunk-A2ZK6G4F.mjs +475 -0
- package/dist/chunk-DRAPR6JV.mjs +34 -0
- package/dist/chunk-J5IGGBVE.mjs +159 -0
- package/dist/chunk-SGCWELVB.mjs +44 -0
- package/dist/chunk-YREEXXZP.mjs +117 -0
- package/dist/index.d.ts +8 -1085
- package/dist/index.js +123 -150
- package/dist/index.mjs +15 -1090
- package/dist/slider.anatomy.d.ts +6 -0
- package/dist/slider.anatomy.js +45 -0
- package/dist/slider.anatomy.mjs +8 -0
- package/dist/slider.connect.d.ts +30 -0
- package/dist/slider.connect.js +601 -0
- package/dist/slider.connect.mjs +10 -0
- package/dist/slider.dom.d.ts +48 -0
- package/dist/slider.dom.js +297 -0
- package/dist/slider.dom.mjs +7 -0
- package/dist/slider.machine.d.ts +7 -0
- package/dist/slider.machine.js +800 -0
- package/dist/slider.machine.mjs +10 -0
- package/dist/slider.style.d.ts +26 -0
- package/dist/slider.style.js +141 -0
- package/dist/slider.style.mjs +6 -0
- package/dist/slider.types.d.ts +166 -0
- package/dist/slider.types.js +18 -0
- package/dist/slider.types.mjs +0 -0
- package/dist/slider.utils.d.ts +10 -0
- package/dist/slider.utils.js +61 -0
- package/dist/slider.utils.mjs +12 -0
- package/package.json +24 -14
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/slider.style.ts
|
|
2
|
+
import { getValuePercent, getValueTransformer } from "@zag-js/numeric-range";
|
|
3
|
+
function getVerticalThumbOffset(ctx) {
|
|
4
|
+
var _a;
|
|
5
|
+
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
6
|
+
const getValue = getValueTransformer([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
7
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
8
|
+
}
|
|
9
|
+
function getHorizontalThumbOffset(ctx) {
|
|
10
|
+
var _a;
|
|
11
|
+
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
12
|
+
if (ctx.isRtl) {
|
|
13
|
+
const getValue2 = getValueTransformer([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
14
|
+
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
15
|
+
}
|
|
16
|
+
const getValue = getValueTransformer([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
17
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
18
|
+
}
|
|
19
|
+
function getThumbOffset(ctx) {
|
|
20
|
+
const percent = getValuePercent(ctx.value, ctx.min, ctx.max) * 100;
|
|
21
|
+
if (ctx.thumbAlignment === "center") {
|
|
22
|
+
return `${percent}%`;
|
|
23
|
+
}
|
|
24
|
+
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
25
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
26
|
+
}
|
|
27
|
+
function getVisibility(ctx) {
|
|
28
|
+
let visibility = "visible";
|
|
29
|
+
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
30
|
+
visibility = "hidden";
|
|
31
|
+
}
|
|
32
|
+
return visibility;
|
|
33
|
+
}
|
|
34
|
+
function getThumbStyle(ctx) {
|
|
35
|
+
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
36
|
+
return {
|
|
37
|
+
visibility: getVisibility(ctx),
|
|
38
|
+
position: "absolute",
|
|
39
|
+
transform: "var(--slider-thumb-transform)",
|
|
40
|
+
[placementProp]: "var(--slider-thumb-offset)"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getRangeOffsets(ctx) {
|
|
44
|
+
let start = "0%";
|
|
45
|
+
let end = `${100 - ctx.valuePercent}%`;
|
|
46
|
+
if (ctx.origin === "center") {
|
|
47
|
+
const isNegative = ctx.valuePercent < 50;
|
|
48
|
+
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
49
|
+
end = isNegative ? "50%" : end;
|
|
50
|
+
}
|
|
51
|
+
return { start, end };
|
|
52
|
+
}
|
|
53
|
+
function getRangeStyle(ctx) {
|
|
54
|
+
if (ctx.isVertical) {
|
|
55
|
+
return {
|
|
56
|
+
position: "absolute",
|
|
57
|
+
bottom: "var(--slider-range-start)",
|
|
58
|
+
top: "var(--slider-range-end)"
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
position: "absolute",
|
|
63
|
+
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
64
|
+
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getControlStyle() {
|
|
68
|
+
return {
|
|
69
|
+
touchAction: "none",
|
|
70
|
+
userSelect: "none",
|
|
71
|
+
position: "relative"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function getRootStyle(ctx) {
|
|
75
|
+
const range = getRangeOffsets(ctx);
|
|
76
|
+
return {
|
|
77
|
+
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
78
|
+
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
79
|
+
"--slider-range-start": range.start,
|
|
80
|
+
"--slider-range-end": range.end
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function getMarkerStyle(ctx, percent) {
|
|
84
|
+
return {
|
|
85
|
+
position: "absolute",
|
|
86
|
+
pointerEvents: "none",
|
|
87
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function getLabelStyle() {
|
|
91
|
+
return { userSelect: "none" };
|
|
92
|
+
}
|
|
93
|
+
function getTrackStyle() {
|
|
94
|
+
return { position: "relative" };
|
|
95
|
+
}
|
|
96
|
+
function getMarkerGroupStyle() {
|
|
97
|
+
return {
|
|
98
|
+
userSelect: "none",
|
|
99
|
+
pointerEvents: "none",
|
|
100
|
+
position: "relative"
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var styles = {
|
|
104
|
+
getThumbOffset,
|
|
105
|
+
getControlStyle,
|
|
106
|
+
getThumbStyle,
|
|
107
|
+
getRangeStyle,
|
|
108
|
+
getRootStyle,
|
|
109
|
+
getMarkerStyle,
|
|
110
|
+
getLabelStyle,
|
|
111
|
+
getTrackStyle,
|
|
112
|
+
getMarkerGroupStyle
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
styles
|
|
117
|
+
};
|