@zag-js/slider 0.10.2 → 0.10.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.ts +5 -8
- package/dist/index.js +10 -674
- package/dist/index.mjs +4 -20
- package/dist/slider.anatomy.d.ts +3 -6
- package/dist/slider.anatomy.js +10 -33
- package/dist/slider.anatomy.mjs +17 -8
- package/dist/slider.connect.d.ts +3 -7
- package/dist/slider.connect.js +72 -261
- package/dist/slider.connect.mjs +251 -9
- package/dist/slider.dom.d.ts +26 -30
- package/dist/slider.dom.js +14 -149
- package/dist/slider.dom.mjs +39 -7
- package/dist/slider.machine.d.ts +3 -7
- package/dist/slider.machine.js +27 -225
- package/dist/slider.machine.mjs +203 -9
- package/dist/slider.style.d.ts +5 -8
- package/dist/slider.style.js +12 -34
- package/dist/slider.style.mjs +112 -5
- package/dist/slider.types.d.ts +10 -12
- package/dist/slider.utils.d.ts +5 -10
- package/dist/slider.utils.js +13 -42
- package/dist/slider.utils.mjs +26 -12
- package/package.json +11 -16
- package/dist/chunk-3Y7IIPR5.mjs +0 -20
- package/dist/chunk-IJAAAKZQ.mjs +0 -115
- package/dist/chunk-NYN3VIY4.mjs +0 -44
- package/dist/chunk-OCT2YBMN.mjs +0 -212
- package/dist/chunk-T6GXNUP7.mjs +0 -265
- package/dist/chunk-YGFSMEUO.mjs +0 -34
- package/dist/slider.types.js +0 -18
- package/dist/slider.types.mjs +0 -0
package/dist/slider.style.mjs
CHANGED
|
@@ -1,6 +1,113 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { getValuePercent, getValueTransformer } from '@zag-js/numeric-range';
|
|
2
|
+
|
|
3
|
+
function getVerticalThumbOffset(ctx) {
|
|
4
|
+
const { height = 0 } = ctx.thumbSize ?? {};
|
|
5
|
+
const getValue = getValueTransformer([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
6
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
7
|
+
}
|
|
8
|
+
function getHorizontalThumbOffset(ctx) {
|
|
9
|
+
const { width = 0 } = ctx.thumbSize ?? {};
|
|
10
|
+
if (ctx.isRtl) {
|
|
11
|
+
const getValue2 = getValueTransformer([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
12
|
+
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
13
|
+
}
|
|
14
|
+
const getValue = getValueTransformer([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
15
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
16
|
+
}
|
|
17
|
+
function getThumbOffset(ctx) {
|
|
18
|
+
const percent = getValuePercent(ctx.value, ctx.min, ctx.max) * 100;
|
|
19
|
+
if (ctx.thumbAlignment === "center") {
|
|
20
|
+
return `${percent}%`;
|
|
21
|
+
}
|
|
22
|
+
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
23
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
24
|
+
}
|
|
25
|
+
function getVisibility(ctx) {
|
|
26
|
+
let visibility = "visible";
|
|
27
|
+
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
28
|
+
visibility = "hidden";
|
|
29
|
+
}
|
|
30
|
+
return visibility;
|
|
31
|
+
}
|
|
32
|
+
function getThumbStyle(ctx) {
|
|
33
|
+
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
34
|
+
return {
|
|
35
|
+
visibility: getVisibility(ctx),
|
|
36
|
+
position: "absolute",
|
|
37
|
+
transform: "var(--slider-thumb-transform)",
|
|
38
|
+
[placementProp]: "var(--slider-thumb-offset)"
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function getRangeOffsets(ctx) {
|
|
42
|
+
let start = "0%";
|
|
43
|
+
let end = `${100 - ctx.valuePercent}%`;
|
|
44
|
+
if (ctx.origin === "center") {
|
|
45
|
+
const isNegative = ctx.valuePercent < 50;
|
|
46
|
+
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
47
|
+
end = isNegative ? "50%" : end;
|
|
48
|
+
}
|
|
49
|
+
return { start, end };
|
|
50
|
+
}
|
|
51
|
+
function getRangeStyle(ctx) {
|
|
52
|
+
if (ctx.isVertical) {
|
|
53
|
+
return {
|
|
54
|
+
position: "absolute",
|
|
55
|
+
bottom: "var(--slider-range-start)",
|
|
56
|
+
top: "var(--slider-range-end)"
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
position: "absolute",
|
|
61
|
+
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
62
|
+
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function getControlStyle() {
|
|
66
|
+
return {
|
|
67
|
+
touchAction: "none",
|
|
68
|
+
userSelect: "none",
|
|
69
|
+
position: "relative"
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function getRootStyle(ctx) {
|
|
73
|
+
const range = getRangeOffsets(ctx);
|
|
74
|
+
return {
|
|
75
|
+
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
76
|
+
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
77
|
+
"--slider-range-start": range.start,
|
|
78
|
+
"--slider-range-end": range.end
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function getMarkerStyle(ctx, percent) {
|
|
82
|
+
return {
|
|
83
|
+
position: "absolute",
|
|
84
|
+
pointerEvents: "none",
|
|
85
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function getLabelStyle() {
|
|
89
|
+
return { userSelect: "none" };
|
|
90
|
+
}
|
|
91
|
+
function getTrackStyle() {
|
|
92
|
+
return { position: "relative" };
|
|
93
|
+
}
|
|
94
|
+
function getMarkerGroupStyle() {
|
|
95
|
+
return {
|
|
96
|
+
userSelect: "none",
|
|
97
|
+
pointerEvents: "none",
|
|
98
|
+
position: "relative"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const styles = {
|
|
102
|
+
getThumbOffset,
|
|
103
|
+
getControlStyle,
|
|
104
|
+
getThumbStyle,
|
|
105
|
+
getRangeStyle,
|
|
106
|
+
getRootStyle,
|
|
107
|
+
getMarkerStyle,
|
|
108
|
+
getLabelStyle,
|
|
109
|
+
getTrackStyle,
|
|
110
|
+
getMarkerGroupStyle
|
|
6
111
|
};
|
|
112
|
+
|
|
113
|
+
export { styles };
|
package/dist/slider.types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { StateMachine } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { StateMachine as S } from "@zag-js/core";
|
|
2
|
+
import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
|
|
4
3
|
type ElementIds = Partial<{
|
|
5
4
|
root: string;
|
|
6
5
|
thumb: string;
|
|
@@ -102,7 +101,7 @@ type PublicContext = DirectionProperty & CommonProperties & {
|
|
|
102
101
|
*/
|
|
103
102
|
thumbAlignment?: "contain" | "center";
|
|
104
103
|
};
|
|
105
|
-
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
104
|
+
export type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
106
105
|
type ComputedContext = Readonly<{
|
|
107
106
|
/**
|
|
108
107
|
* @computed
|
|
@@ -136,13 +135,13 @@ type ComputedContext = Readonly<{
|
|
|
136
135
|
readonly valuePercent: number;
|
|
137
136
|
}>;
|
|
138
137
|
type PrivateContext = Context<{}>;
|
|
139
|
-
type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
140
|
-
type MachineState = {
|
|
138
|
+
export type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
139
|
+
export type MachineState = {
|
|
141
140
|
value: "idle" | "dragging" | "focus";
|
|
142
141
|
};
|
|
143
|
-
type State =
|
|
144
|
-
type Send =
|
|
145
|
-
type SharedContext = {
|
|
142
|
+
export type State = S.State<MachineContext, MachineState>;
|
|
143
|
+
export type Send = S.Send<S.AnyEventObject>;
|
|
144
|
+
export type SharedContext = {
|
|
146
145
|
min: number;
|
|
147
146
|
max: number;
|
|
148
147
|
step: number;
|
|
@@ -159,9 +158,8 @@ type SharedContext = {
|
|
|
159
158
|
orientation?: "horizontal" | "vertical";
|
|
160
159
|
readonly hasMeasuredThumbSize: boolean;
|
|
161
160
|
};
|
|
162
|
-
type Point = {
|
|
161
|
+
export type Point = {
|
|
163
162
|
x: number;
|
|
164
163
|
y: number;
|
|
165
164
|
};
|
|
166
|
-
|
|
167
|
-
export { MachineContext, MachineState, Point, Send, SharedContext, State, UserDefinedContext };
|
|
165
|
+
export {};
|
package/dist/slider.utils.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { MachineContext } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function
|
|
6
|
-
declare function constrainValue(ctx: MachineContext, value: number): number;
|
|
7
|
-
declare function decrement(ctx: MachineContext, step?: number): number;
|
|
8
|
-
declare function increment(ctx: MachineContext, step?: number): number;
|
|
9
|
-
|
|
10
|
-
export { clampPercent, constrainValue, decrement, increment };
|
|
1
|
+
import type { MachineContext as Ctx } from "./slider.types";
|
|
2
|
+
export declare function clampPercent(percent: number): number;
|
|
3
|
+
export declare function constrainValue(ctx: Ctx, value: number): number;
|
|
4
|
+
export declare function decrement(ctx: Ctx, step?: number): number;
|
|
5
|
+
export declare function increment(ctx: Ctx, step?: number): number;
|
package/dist/slider.utils.js
CHANGED
|
@@ -1,42 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const numericRange = require('@zag-js/numeric-range');
|
|
19
6
|
|
|
20
|
-
// src/slider.utils.ts
|
|
21
|
-
var slider_utils_exports = {};
|
|
22
|
-
__export(slider_utils_exports, {
|
|
23
|
-
clampPercent: () => clampPercent,
|
|
24
|
-
constrainValue: () => constrainValue,
|
|
25
|
-
decrement: () => decrement,
|
|
26
|
-
increment: () => increment
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(slider_utils_exports);
|
|
29
|
-
var import_numeric_range = require("@zag-js/numeric-range");
|
|
30
|
-
function clampPercent(percent) {
|
|
31
|
-
return (0, import_numeric_range.clampValue)(percent, 0, 1);
|
|
32
|
-
}
|
|
33
7
|
function constrainValue(ctx, value) {
|
|
34
|
-
const snapValue =
|
|
35
|
-
return
|
|
8
|
+
const snapValue = numericRange.snapValueToStep(value, ctx.min, ctx.max, ctx.step);
|
|
9
|
+
return numericRange.clampValue(snapValue, ctx.min, ctx.max);
|
|
36
10
|
}
|
|
37
11
|
function decrement(ctx, step) {
|
|
38
12
|
const index = 0;
|
|
39
|
-
const values =
|
|
13
|
+
const values = numericRange.getPreviousStepValue(index, {
|
|
40
14
|
...ctx,
|
|
41
15
|
step: step ?? ctx.step,
|
|
42
16
|
values: [ctx.value]
|
|
@@ -45,17 +19,14 @@ function decrement(ctx, step) {
|
|
|
45
19
|
}
|
|
46
20
|
function increment(ctx, step) {
|
|
47
21
|
const index = 0;
|
|
48
|
-
const values =
|
|
22
|
+
const values = numericRange.getNextStepValue(index, {
|
|
49
23
|
...ctx,
|
|
50
24
|
step: step ?? ctx.step,
|
|
51
25
|
values: [ctx.value]
|
|
52
26
|
});
|
|
53
27
|
return values[index];
|
|
54
28
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
decrement,
|
|
60
|
-
increment
|
|
61
|
-
});
|
|
29
|
+
|
|
30
|
+
exports.constrainValue = constrainValue;
|
|
31
|
+
exports.decrement = decrement;
|
|
32
|
+
exports.increment = increment;
|
package/dist/slider.utils.mjs
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { snapValueToStep, clampValue, getPreviousStepValue, getNextStepValue } from '@zag-js/numeric-range';
|
|
2
|
+
|
|
3
|
+
function constrainValue(ctx, value) {
|
|
4
|
+
const snapValue = snapValueToStep(value, ctx.min, ctx.max, ctx.step);
|
|
5
|
+
return clampValue(snapValue, ctx.min, ctx.max);
|
|
6
|
+
}
|
|
7
|
+
function decrement(ctx, step) {
|
|
8
|
+
const index = 0;
|
|
9
|
+
const values = getPreviousStepValue(index, {
|
|
10
|
+
...ctx,
|
|
11
|
+
step: step ?? ctx.step,
|
|
12
|
+
values: [ctx.value]
|
|
13
|
+
});
|
|
14
|
+
return values[index];
|
|
15
|
+
}
|
|
16
|
+
function increment(ctx, step) {
|
|
17
|
+
const index = 0;
|
|
18
|
+
const values = getNextStepValue(index, {
|
|
19
|
+
...ctx,
|
|
20
|
+
step: step ?? ctx.step,
|
|
21
|
+
values: [ctx.value]
|
|
22
|
+
});
|
|
23
|
+
return values[index];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { constrainValue, decrement, increment };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/slider",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Core logic for the slider widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/anatomy": "0.10.
|
|
31
|
-
"@zag-js/core": "0.10.
|
|
32
|
-
"@zag-js/dom-query": "0.10.
|
|
33
|
-
"@zag-js/dom-event": "0.10.
|
|
34
|
-
"@zag-js/form-utils": "0.10.
|
|
35
|
-
"@zag-js/utils": "0.10.
|
|
36
|
-
"@zag-js/element-size": "0.10.
|
|
37
|
-
"@zag-js/numeric-range": "0.10.
|
|
38
|
-
"@zag-js/types": "0.10.
|
|
30
|
+
"@zag-js/anatomy": "0.10.4",
|
|
31
|
+
"@zag-js/core": "0.10.4",
|
|
32
|
+
"@zag-js/dom-query": "0.10.4",
|
|
33
|
+
"@zag-js/dom-event": "0.10.4",
|
|
34
|
+
"@zag-js/form-utils": "0.10.4",
|
|
35
|
+
"@zag-js/utils": "0.10.4",
|
|
36
|
+
"@zag-js/element-size": "0.10.4",
|
|
37
|
+
"@zag-js/numeric-range": "0.10.4",
|
|
38
|
+
"@zag-js/types": "0.10.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"clean-package": "2.2.0"
|
|
@@ -53,13 +53,8 @@
|
|
|
53
53
|
"./package.json": "./package.json"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
|
-
"build
|
|
57
|
-
"start": "pnpm build --watch",
|
|
58
|
-
"build": "tsup src --dts",
|
|
59
|
-
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
56
|
+
"build": "vite build -c ../../../vite.config.ts",
|
|
60
57
|
"lint": "eslint src --ext .ts,.tsx",
|
|
61
|
-
"test-ci": "pnpm test --ci --runInBand",
|
|
62
|
-
"test-watch": "pnpm test --watch -u",
|
|
63
58
|
"typecheck": "tsc --noEmit"
|
|
64
59
|
}
|
|
65
60
|
}
|
package/dist/chunk-3Y7IIPR5.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// src/slider.anatomy.ts
|
|
2
|
-
import { createAnatomy } from "@zag-js/anatomy";
|
|
3
|
-
var anatomy = createAnatomy("slider").parts(
|
|
4
|
-
"root",
|
|
5
|
-
"label",
|
|
6
|
-
"thumb",
|
|
7
|
-
"hiddenInput",
|
|
8
|
-
"output",
|
|
9
|
-
"track",
|
|
10
|
-
"range",
|
|
11
|
-
"control",
|
|
12
|
-
"markerGroup",
|
|
13
|
-
"marker"
|
|
14
|
-
);
|
|
15
|
-
var parts = anatomy.build();
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
anatomy,
|
|
19
|
-
parts
|
|
20
|
-
};
|
package/dist/chunk-IJAAAKZQ.mjs
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// src/slider.style.ts
|
|
2
|
-
import { getValuePercent, getValueTransformer } from "@zag-js/numeric-range";
|
|
3
|
-
function getVerticalThumbOffset(ctx) {
|
|
4
|
-
const { height = 0 } = ctx.thumbSize ?? {};
|
|
5
|
-
const getValue = getValueTransformer([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
6
|
-
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
7
|
-
}
|
|
8
|
-
function getHorizontalThumbOffset(ctx) {
|
|
9
|
-
const { width = 0 } = ctx.thumbSize ?? {};
|
|
10
|
-
if (ctx.isRtl) {
|
|
11
|
-
const getValue2 = getValueTransformer([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
12
|
-
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
13
|
-
}
|
|
14
|
-
const getValue = getValueTransformer([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
15
|
-
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
16
|
-
}
|
|
17
|
-
function getThumbOffset(ctx) {
|
|
18
|
-
const percent = getValuePercent(ctx.value, ctx.min, ctx.max) * 100;
|
|
19
|
-
if (ctx.thumbAlignment === "center") {
|
|
20
|
-
return `${percent}%`;
|
|
21
|
-
}
|
|
22
|
-
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
23
|
-
return `calc(${percent}% - ${offset}px)`;
|
|
24
|
-
}
|
|
25
|
-
function getVisibility(ctx) {
|
|
26
|
-
let visibility = "visible";
|
|
27
|
-
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
28
|
-
visibility = "hidden";
|
|
29
|
-
}
|
|
30
|
-
return visibility;
|
|
31
|
-
}
|
|
32
|
-
function getThumbStyle(ctx) {
|
|
33
|
-
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
34
|
-
return {
|
|
35
|
-
visibility: getVisibility(ctx),
|
|
36
|
-
position: "absolute",
|
|
37
|
-
transform: "var(--slider-thumb-transform)",
|
|
38
|
-
[placementProp]: "var(--slider-thumb-offset)"
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function getRangeOffsets(ctx) {
|
|
42
|
-
let start = "0%";
|
|
43
|
-
let end = `${100 - ctx.valuePercent}%`;
|
|
44
|
-
if (ctx.origin === "center") {
|
|
45
|
-
const isNegative = ctx.valuePercent < 50;
|
|
46
|
-
start = isNegative ? `${ctx.valuePercent}%` : "50%";
|
|
47
|
-
end = isNegative ? "50%" : end;
|
|
48
|
-
}
|
|
49
|
-
return { start, end };
|
|
50
|
-
}
|
|
51
|
-
function getRangeStyle(ctx) {
|
|
52
|
-
if (ctx.isVertical) {
|
|
53
|
-
return {
|
|
54
|
-
position: "absolute",
|
|
55
|
-
bottom: "var(--slider-range-start)",
|
|
56
|
-
top: "var(--slider-range-end)"
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
position: "absolute",
|
|
61
|
-
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
62
|
-
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function getControlStyle() {
|
|
66
|
-
return {
|
|
67
|
-
touchAction: "none",
|
|
68
|
-
userSelect: "none",
|
|
69
|
-
position: "relative"
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function getRootStyle(ctx) {
|
|
73
|
-
const range = getRangeOffsets(ctx);
|
|
74
|
-
return {
|
|
75
|
-
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
76
|
-
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
77
|
-
"--slider-range-start": range.start,
|
|
78
|
-
"--slider-range-end": range.end
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function getMarkerStyle(ctx, percent) {
|
|
82
|
-
return {
|
|
83
|
-
position: "absolute",
|
|
84
|
-
pointerEvents: "none",
|
|
85
|
-
[ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function getLabelStyle() {
|
|
89
|
-
return { userSelect: "none" };
|
|
90
|
-
}
|
|
91
|
-
function getTrackStyle() {
|
|
92
|
-
return { position: "relative" };
|
|
93
|
-
}
|
|
94
|
-
function getMarkerGroupStyle() {
|
|
95
|
-
return {
|
|
96
|
-
userSelect: "none",
|
|
97
|
-
pointerEvents: "none",
|
|
98
|
-
position: "relative"
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
var styles = {
|
|
102
|
-
getThumbOffset,
|
|
103
|
-
getControlStyle,
|
|
104
|
-
getThumbStyle,
|
|
105
|
-
getRangeStyle,
|
|
106
|
-
getRootStyle,
|
|
107
|
-
getMarkerStyle,
|
|
108
|
-
getLabelStyle,
|
|
109
|
-
getTrackStyle,
|
|
110
|
-
getMarkerGroupStyle
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export {
|
|
114
|
-
styles
|
|
115
|
-
};
|
package/dist/chunk-NYN3VIY4.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
styles
|
|
3
|
-
} from "./chunk-IJAAAKZQ.mjs";
|
|
4
|
-
|
|
5
|
-
// src/slider.dom.ts
|
|
6
|
-
import { getRelativePoint } from "@zag-js/dom-event";
|
|
7
|
-
import { createScope } from "@zag-js/dom-query";
|
|
8
|
-
import { dispatchInputValueEvent } from "@zag-js/form-utils";
|
|
9
|
-
import { getPercentValue } from "@zag-js/numeric-range";
|
|
10
|
-
var dom = createScope({
|
|
11
|
-
...styles,
|
|
12
|
-
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
13
|
-
getThumbId: (ctx) => ctx.ids?.thumb ?? `slider:${ctx.id}:thumb`,
|
|
14
|
-
getControlId: (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`,
|
|
15
|
-
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `slider:${ctx.id}:input`,
|
|
16
|
-
getOutputId: (ctx) => ctx.ids?.output ?? `slider:${ctx.id}:output`,
|
|
17
|
-
getTrackId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}track`,
|
|
18
|
-
getRangeId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:range`,
|
|
19
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`,
|
|
20
|
-
getMarkerId: (ctx, value) => `slider:${ctx.id}:marker:${value}`,
|
|
21
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
22
|
-
getThumbEl: (ctx) => dom.getById(ctx, dom.getThumbId(ctx)),
|
|
23
|
-
getControlEl: (ctx) => dom.queryById(ctx, dom.getControlId(ctx)),
|
|
24
|
-
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx)),
|
|
25
|
-
getValueFromPoint(ctx, point) {
|
|
26
|
-
const relativePoint = getRelativePoint(point, dom.getControlEl(ctx));
|
|
27
|
-
const percent = relativePoint.getPercentValue({
|
|
28
|
-
orientation: ctx.orientation,
|
|
29
|
-
dir: ctx.dir,
|
|
30
|
-
inverted: { y: true }
|
|
31
|
-
});
|
|
32
|
-
return getPercentValue(percent, ctx.min, ctx.max, ctx.step);
|
|
33
|
-
},
|
|
34
|
-
dispatchChangeEvent(ctx) {
|
|
35
|
-
const input = dom.getHiddenInputEl(ctx);
|
|
36
|
-
if (!input)
|
|
37
|
-
return;
|
|
38
|
-
dispatchInputValueEvent(input, { value: ctx.value });
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
dom
|
|
44
|
-
};
|