@zag-js/slider 0.2.6 → 0.2.7
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-3JMGYHB3.mjs +469 -0
- package/dist/chunk-3Y7IIPR5.mjs +20 -0
- package/dist/chunk-FUTBDWTA.mjs +33 -0
- package/dist/chunk-GBYBRQZL.mjs +56 -0
- package/dist/chunk-MR2MUD77.mjs +179 -0
- package/dist/chunk-MXJ3RGFD.mjs +125 -0
- package/dist/chunk-SGCWELVB.mjs +44 -0
- package/dist/chunk-YCRSV2RE.mjs +288 -0
- package/dist/index.d.ts +8 -1085
- package/dist/index.js +63 -36
- package/dist/index.mjs +16 -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 +29 -0
- package/dist/slider.connect.js +684 -0
- package/dist/slider.connect.mjs +12 -0
- package/dist/slider.dom.d.ts +52 -0
- package/dist/slider.dom.js +386 -0
- package/dist/slider.dom.mjs +9 -0
- package/dist/slider.machine.d.ts +7 -0
- package/dist/slider.machine.js +860 -0
- package/dist/slider.machine.mjs +11 -0
- package/dist/slider.style.d.ts +26 -0
- package/dist/slider.style.js +156 -0
- package/dist/slider.style.mjs +7 -0
- package/dist/slider.types.d.ts +161 -0
- package/dist/slider.types.js +18 -0
- package/dist/slider.types.mjs +0 -0
- package/dist/slider.utils.d.ts +13 -0
- package/dist/slider.utils.js +98 -0
- package/dist/slider.utils.mjs +7 -0
- package/package.json +24 -14
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Style } from '@zag-js/types';
|
|
2
|
+
import { SharedContext, MachineContext } from './slider.types.js';
|
|
3
|
+
import '@zag-js/core';
|
|
4
|
+
|
|
5
|
+
declare function getThumbOffset(ctx: SharedContext): string;
|
|
6
|
+
declare function getThumbStyle(ctx: SharedContext): Style;
|
|
7
|
+
declare function getRangeStyle(ctx: Pick<SharedContext, "isVertical" | "isRtl">): Style;
|
|
8
|
+
declare function getControlStyle(): Style;
|
|
9
|
+
declare function getRootStyle(ctx: MachineContext): Style;
|
|
10
|
+
declare function getMarkerStyle(ctx: Pick<SharedContext, "isHorizontal" | "isRtl">, percent: number): Style;
|
|
11
|
+
declare function getLabelStyle(): Style;
|
|
12
|
+
declare function getTrackStyle(): Style;
|
|
13
|
+
declare function getMarkerGroupStyle(): Style;
|
|
14
|
+
declare const styles: {
|
|
15
|
+
getThumbOffset: typeof getThumbOffset;
|
|
16
|
+
getControlStyle: typeof getControlStyle;
|
|
17
|
+
getThumbStyle: typeof getThumbStyle;
|
|
18
|
+
getRangeStyle: typeof getRangeStyle;
|
|
19
|
+
getRootStyle: typeof getRootStyle;
|
|
20
|
+
getMarkerStyle: typeof getMarkerStyle;
|
|
21
|
+
getLabelStyle: typeof getLabelStyle;
|
|
22
|
+
getTrackStyle: typeof getTrackStyle;
|
|
23
|
+
getMarkerGroupStyle: typeof getMarkerGroupStyle;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { styles };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/slider.style.ts
|
|
21
|
+
var slider_style_exports = {};
|
|
22
|
+
__export(slider_style_exports, {
|
|
23
|
+
styles: () => styles
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(slider_style_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/number/src/number.ts
|
|
28
|
+
var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
|
|
29
|
+
function valueOf(v) {
|
|
30
|
+
if (typeof v === "number")
|
|
31
|
+
return v;
|
|
32
|
+
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
33
|
+
return !Number.isNaN(num) ? num : 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../../utilities/number/src/transform.ts
|
|
37
|
+
var transform = (a, b) => {
|
|
38
|
+
const i = { min: a[0], max: a[1] };
|
|
39
|
+
const o = { min: b[0], max: b[1] };
|
|
40
|
+
return (v) => {
|
|
41
|
+
if (i.min === i.max || o.min === o.max)
|
|
42
|
+
return o.min;
|
|
43
|
+
const ratio = (o.max - o.min) / (i.max - i.min);
|
|
44
|
+
return o.min + ratio * (v - i.min);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/slider.style.ts
|
|
49
|
+
function getVerticalThumbOffset(ctx) {
|
|
50
|
+
var _a;
|
|
51
|
+
const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
52
|
+
const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
|
|
53
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
54
|
+
}
|
|
55
|
+
function getHorizontalThumbOffset(ctx) {
|
|
56
|
+
var _a;
|
|
57
|
+
const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
|
|
58
|
+
if (ctx.isRtl) {
|
|
59
|
+
const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
|
|
60
|
+
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
61
|
+
}
|
|
62
|
+
const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
63
|
+
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
64
|
+
}
|
|
65
|
+
function getThumbOffset(ctx) {
|
|
66
|
+
const percent = valueToPercent(ctx.value, ctx);
|
|
67
|
+
if (ctx.thumbAlignment === "center")
|
|
68
|
+
return `${percent}%`;
|
|
69
|
+
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
70
|
+
return `calc(${percent}% - ${offset}px)`;
|
|
71
|
+
}
|
|
72
|
+
function getThumbStyle(ctx) {
|
|
73
|
+
const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
|
|
74
|
+
return {
|
|
75
|
+
visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
|
|
76
|
+
position: "absolute",
|
|
77
|
+
transform: "var(--slider-thumb-transform)",
|
|
78
|
+
[placementProp]: "var(--slider-thumb-offset)"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function getRangeOffsets(ctx) {
|
|
82
|
+
const percent = valueToPercent(ctx.value, ctx);
|
|
83
|
+
let start = "0%";
|
|
84
|
+
let end = `${100 - percent}%`;
|
|
85
|
+
if (ctx.origin === "center") {
|
|
86
|
+
const isNegative = percent < 50;
|
|
87
|
+
start = isNegative ? `${percent}%` : "50%";
|
|
88
|
+
end = isNegative ? "50%" : end;
|
|
89
|
+
}
|
|
90
|
+
return { start, end };
|
|
91
|
+
}
|
|
92
|
+
function getRangeStyle(ctx) {
|
|
93
|
+
if (ctx.isVertical) {
|
|
94
|
+
return {
|
|
95
|
+
position: "absolute",
|
|
96
|
+
bottom: "var(--slider-range-start)",
|
|
97
|
+
top: "var(--slider-range-end)"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
position: "absolute",
|
|
102
|
+
[ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
103
|
+
[ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function getControlStyle() {
|
|
107
|
+
return {
|
|
108
|
+
touchAction: "none",
|
|
109
|
+
userSelect: "none",
|
|
110
|
+
position: "relative"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function getRootStyle(ctx) {
|
|
114
|
+
const range = getRangeOffsets(ctx);
|
|
115
|
+
return {
|
|
116
|
+
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
117
|
+
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
118
|
+
"--slider-range-start": range.start,
|
|
119
|
+
"--slider-range-end": range.end
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function getMarkerStyle(ctx, percent) {
|
|
123
|
+
return {
|
|
124
|
+
position: "absolute",
|
|
125
|
+
pointerEvents: "none",
|
|
126
|
+
[ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function getLabelStyle() {
|
|
130
|
+
return { userSelect: "none" };
|
|
131
|
+
}
|
|
132
|
+
function getTrackStyle() {
|
|
133
|
+
return { position: "relative" };
|
|
134
|
+
}
|
|
135
|
+
function getMarkerGroupStyle() {
|
|
136
|
+
return {
|
|
137
|
+
userSelect: "none",
|
|
138
|
+
pointerEvents: "none",
|
|
139
|
+
position: "relative"
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
var styles = {
|
|
143
|
+
getThumbOffset,
|
|
144
|
+
getControlStyle,
|
|
145
|
+
getThumbStyle,
|
|
146
|
+
getRangeStyle,
|
|
147
|
+
getRootStyle,
|
|
148
|
+
getMarkerStyle,
|
|
149
|
+
getLabelStyle,
|
|
150
|
+
getTrackStyle,
|
|
151
|
+
getMarkerGroupStyle
|
|
152
|
+
};
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
styles
|
|
156
|
+
});
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { StateMachine } from '@zag-js/core';
|
|
2
|
+
import { RequiredBy, DirectionProperty, CommonProperties, Context } from '@zag-js/types';
|
|
3
|
+
|
|
4
|
+
type ElementIds = Partial<{
|
|
5
|
+
root: string;
|
|
6
|
+
thumb: string;
|
|
7
|
+
control: string;
|
|
8
|
+
track: string;
|
|
9
|
+
range: string;
|
|
10
|
+
label: string;
|
|
11
|
+
output: string;
|
|
12
|
+
}>;
|
|
13
|
+
type PublicContext = DirectionProperty & CommonProperties & {
|
|
14
|
+
/**
|
|
15
|
+
* The ids of the elements in the slider. Useful for composition.
|
|
16
|
+
*/
|
|
17
|
+
ids?: ElementIds;
|
|
18
|
+
/**
|
|
19
|
+
* The value of the slider
|
|
20
|
+
*/
|
|
21
|
+
value: number;
|
|
22
|
+
/**
|
|
23
|
+
* The name associated with the slider (when used in a form)
|
|
24
|
+
*/
|
|
25
|
+
name?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The associate form of the underlying input element.
|
|
28
|
+
*/
|
|
29
|
+
form?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the slider is disabled
|
|
32
|
+
*/
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the slider is read-only
|
|
36
|
+
*/
|
|
37
|
+
readOnly?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the slider value is invalid
|
|
40
|
+
*/
|
|
41
|
+
invalid?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The minimum value of the slider
|
|
44
|
+
*/
|
|
45
|
+
min: number;
|
|
46
|
+
/**
|
|
47
|
+
* The maximum value of the slider
|
|
48
|
+
*/
|
|
49
|
+
max: number;
|
|
50
|
+
/**
|
|
51
|
+
* The step value of the slider
|
|
52
|
+
*/
|
|
53
|
+
step: number;
|
|
54
|
+
/**
|
|
55
|
+
* The orientation of the slider
|
|
56
|
+
*/
|
|
57
|
+
orientation?: "vertical" | "horizontal";
|
|
58
|
+
/**
|
|
59
|
+
* - "start": Useful when the value represents an absolute value
|
|
60
|
+
* - "center": Useful when the value represents an offset (relative)
|
|
61
|
+
*/
|
|
62
|
+
origin?: "start" | "center";
|
|
63
|
+
/**
|
|
64
|
+
* The aria-label of the slider. Useful for providing an accessible name to the slider
|
|
65
|
+
*/
|
|
66
|
+
"aria-label"?: string;
|
|
67
|
+
/**
|
|
68
|
+
* The `id` of the element that labels the slider. Useful for providing an accessible name to the slider
|
|
69
|
+
*/
|
|
70
|
+
"aria-labelledby"?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether to focus the slider thumb after interaction (scrub and keyboard)
|
|
73
|
+
*/
|
|
74
|
+
focusThumbOnChange?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Function that returns a human readable value for the slider
|
|
77
|
+
*/
|
|
78
|
+
getAriaValueText?(value: number): string;
|
|
79
|
+
/**
|
|
80
|
+
* Function invoked when the value of the slider changes
|
|
81
|
+
*/
|
|
82
|
+
onChange?(details: {
|
|
83
|
+
value: number;
|
|
84
|
+
}): void;
|
|
85
|
+
/**
|
|
86
|
+
* Function invoked when the slider value change is done
|
|
87
|
+
*/
|
|
88
|
+
onChangeEnd?(details: {
|
|
89
|
+
value: number;
|
|
90
|
+
}): void;
|
|
91
|
+
/**
|
|
92
|
+
* Function invoked when the slider value change is started
|
|
93
|
+
*/
|
|
94
|
+
onChangeStart?(details: {
|
|
95
|
+
value: number;
|
|
96
|
+
}): void;
|
|
97
|
+
/**
|
|
98
|
+
* The alignment of the slider thumb relative to the track
|
|
99
|
+
* - `center`: the thumb will extend beyond the bounds of the slider track.
|
|
100
|
+
* - `contain`: the thumb will be contained within the bounds of the track.
|
|
101
|
+
*/
|
|
102
|
+
thumbAlignment?: "contain" | "center";
|
|
103
|
+
};
|
|
104
|
+
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
105
|
+
type ComputedContext = Readonly<{
|
|
106
|
+
/**
|
|
107
|
+
* @computed
|
|
108
|
+
* Whether the slider is interactive
|
|
109
|
+
*/
|
|
110
|
+
readonly isInteractive: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* @computed
|
|
113
|
+
* Whether the thumb size has been measured
|
|
114
|
+
*/
|
|
115
|
+
readonly hasMeasuredThumbSize: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* @computed
|
|
118
|
+
* Whether the slider is horizontal
|
|
119
|
+
*/
|
|
120
|
+
readonly isHorizontal: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* @computed
|
|
123
|
+
* Whether the slider is vertical
|
|
124
|
+
*/
|
|
125
|
+
readonly isVertical: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* @computed
|
|
128
|
+
* Whether the slider is in RTL mode
|
|
129
|
+
*/
|
|
130
|
+
readonly isRtl: boolean;
|
|
131
|
+
}>;
|
|
132
|
+
type PrivateContext = Context<{}>;
|
|
133
|
+
type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
134
|
+
type MachineState = {
|
|
135
|
+
value: "unknown" | "idle" | "dragging" | "focus";
|
|
136
|
+
};
|
|
137
|
+
type State = StateMachine.State<MachineContext, MachineState>;
|
|
138
|
+
type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
139
|
+
type SharedContext = {
|
|
140
|
+
min: number;
|
|
141
|
+
max: number;
|
|
142
|
+
step: number;
|
|
143
|
+
dir?: "ltr" | "rtl";
|
|
144
|
+
isRtl: boolean;
|
|
145
|
+
isVertical: boolean;
|
|
146
|
+
isHorizontal: boolean;
|
|
147
|
+
value: number;
|
|
148
|
+
thumbSize: {
|
|
149
|
+
width: number;
|
|
150
|
+
height: number;
|
|
151
|
+
} | null;
|
|
152
|
+
thumbAlignment?: "contain" | "center";
|
|
153
|
+
orientation?: "horizontal" | "vertical";
|
|
154
|
+
readonly hasMeasuredThumbSize: boolean;
|
|
155
|
+
};
|
|
156
|
+
type Point = {
|
|
157
|
+
x: number;
|
|
158
|
+
y: number;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export { MachineContext, MachineState, Point, Send, SharedContext, State, UserDefinedContext };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/slider.types.ts
|
|
17
|
+
var slider_types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(slider_types_exports);
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MachineContext } from './slider.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const utils: {
|
|
6
|
+
fromPercent(ctx: MachineContext, percent: number): number;
|
|
7
|
+
clamp(ctx: MachineContext, value: number): number;
|
|
8
|
+
convert(ctx: MachineContext, value: number): number;
|
|
9
|
+
decrement(ctx: MachineContext, step?: number): number;
|
|
10
|
+
increment(ctx: MachineContext, step?: number): number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { utils };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/slider.utils.ts
|
|
21
|
+
var slider_utils_exports = {};
|
|
22
|
+
__export(slider_utils_exports, {
|
|
23
|
+
utils: () => utils
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(slider_utils_exports);
|
|
26
|
+
|
|
27
|
+
// ../../utilities/number/src/number.ts
|
|
28
|
+
function round(v, t) {
|
|
29
|
+
let num = valueOf(v);
|
|
30
|
+
const p = 10 ** (t != null ? t : 10);
|
|
31
|
+
num = Math.round(num * p) / p;
|
|
32
|
+
return t ? num.toFixed(t) : v.toString();
|
|
33
|
+
}
|
|
34
|
+
var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
|
|
35
|
+
function clamp(v, o) {
|
|
36
|
+
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
37
|
+
}
|
|
38
|
+
function countDecimals(value) {
|
|
39
|
+
if (!Number.isFinite(value))
|
|
40
|
+
return 0;
|
|
41
|
+
let e = 1, p = 0;
|
|
42
|
+
while (Math.round(value * e) / e !== value) {
|
|
43
|
+
e *= 10;
|
|
44
|
+
p += 1;
|
|
45
|
+
}
|
|
46
|
+
return p;
|
|
47
|
+
}
|
|
48
|
+
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
49
|
+
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
50
|
+
function snapToStep(value, step) {
|
|
51
|
+
const num = valueOf(value);
|
|
52
|
+
const p = countDecimals(step);
|
|
53
|
+
const v = Math.round(num / step) * step;
|
|
54
|
+
return round(v, p);
|
|
55
|
+
}
|
|
56
|
+
function valueOf(v) {
|
|
57
|
+
if (typeof v === "number")
|
|
58
|
+
return v;
|
|
59
|
+
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
60
|
+
return !Number.isNaN(num) ? num : 0;
|
|
61
|
+
}
|
|
62
|
+
function decimalOperation(a, op, b) {
|
|
63
|
+
let result = op === "+" ? a + b : a - b;
|
|
64
|
+
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
65
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
66
|
+
a = Math.round(a * multiplier);
|
|
67
|
+
b = Math.round(b * multiplier);
|
|
68
|
+
result = op === "+" ? a + b : a - b;
|
|
69
|
+
result /= multiplier;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/slider.utils.ts
|
|
75
|
+
var utils = {
|
|
76
|
+
fromPercent(ctx, percent) {
|
|
77
|
+
percent = clamp(percent, { min: 0, max: 1 });
|
|
78
|
+
return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
|
|
79
|
+
},
|
|
80
|
+
clamp(ctx, value) {
|
|
81
|
+
return clamp(value, ctx);
|
|
82
|
+
},
|
|
83
|
+
convert(ctx, value) {
|
|
84
|
+
return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
|
|
85
|
+
},
|
|
86
|
+
decrement(ctx, step) {
|
|
87
|
+
let value = decrement(ctx.value, step != null ? step : ctx.step);
|
|
88
|
+
return utils.convert(ctx, value);
|
|
89
|
+
},
|
|
90
|
+
increment(ctx, step) {
|
|
91
|
+
let value = increment(ctx.value, step != null ? step : ctx.step);
|
|
92
|
+
return utils.convert(ctx, value);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
utils
|
|
98
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/slider",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Core logic for the slider widget implemented as a state machine",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"js",
|
|
10
7
|
"machine",
|
|
@@ -29,21 +26,34 @@
|
|
|
29
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
27
|
},
|
|
31
28
|
"dependencies": {
|
|
32
|
-
"@zag-js/anatomy": "0.1.
|
|
33
|
-
"@zag-js/core": "0.2.
|
|
34
|
-
"@zag-js/element-size": "0.3.
|
|
35
|
-
"@zag-js/types": "0.3.
|
|
29
|
+
"@zag-js/anatomy": "0.1.3",
|
|
30
|
+
"@zag-js/core": "0.2.4",
|
|
31
|
+
"@zag-js/element-size": "0.3.1",
|
|
32
|
+
"@zag-js/types": "0.3.2"
|
|
36
33
|
},
|
|
37
34
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"@zag-js/
|
|
40
|
-
"@zag-js/utils": "0.3
|
|
41
|
-
"@zag-js/
|
|
35
|
+
"clean-package": "2.2.0",
|
|
36
|
+
"@zag-js/dom-utils": "0.2.2",
|
|
37
|
+
"@zag-js/form-utils": "0.2.3",
|
|
38
|
+
"@zag-js/utils": "0.3.2",
|
|
39
|
+
"@zag-js/number-utils": "0.2.2"
|
|
40
|
+
},
|
|
41
|
+
"clean-package": "../../../clean-package.config.json",
|
|
42
|
+
"main": "dist/index.js",
|
|
43
|
+
"module": "dist/index.mjs",
|
|
44
|
+
"types": "dist/index.d.ts",
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"types": "./dist/index.d.ts",
|
|
48
|
+
"import": "./dist/index.mjs",
|
|
49
|
+
"require": "./dist/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json"
|
|
42
52
|
},
|
|
43
53
|
"scripts": {
|
|
44
|
-
"build-fast": "tsup src
|
|
54
|
+
"build-fast": "tsup src",
|
|
45
55
|
"start": "pnpm build --watch",
|
|
46
|
-
"build": "tsup src
|
|
56
|
+
"build": "tsup src --dts",
|
|
47
57
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
48
58
|
"lint": "eslint src --ext .ts,.tsx",
|
|
49
59
|
"test-ci": "pnpm test --ci --runInBand",
|