@zag-js/slider 0.15.0 → 0.17.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 +77 -62
- package/dist/index.d.ts +77 -62
- package/dist/index.js +71 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
- package/src/index.ts +1 -1
- package/src/slider.connect.ts +10 -9
- package/src/slider.machine.ts +47 -27
- package/src/slider.style.ts +21 -13
- package/src/slider.types.ts +72 -67
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
2
|
import * as _zag_js_types from '@zag-js/types';
|
|
3
|
-
import {
|
|
3
|
+
import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
|
|
4
4
|
import * as _zag_js_core from '@zag-js/core';
|
|
5
5
|
import { StateMachine } from '@zag-js/core';
|
|
6
6
|
|
|
@@ -106,60 +106,13 @@ type PublicContext = DirectionProperty & CommonProperties & {
|
|
|
106
106
|
* - `contain`: the thumb will be contained within the bounds of the track.
|
|
107
107
|
*/
|
|
108
108
|
thumbAlignment?: "contain" | "center";
|
|
109
|
-
};
|
|
110
|
-
type PublicApi<T extends PropTypes = PropTypes> = {
|
|
111
|
-
/**
|
|
112
|
-
* Whether the slider is focused.
|
|
113
|
-
*/
|
|
114
|
-
isFocused: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Whether the slider is being dragged.
|
|
117
|
-
*/
|
|
118
|
-
isDragging: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* The value of the slider.
|
|
121
|
-
*/
|
|
122
|
-
value: number;
|
|
123
|
-
/**
|
|
124
|
-
* The value of the slider as a percent.
|
|
125
|
-
*/
|
|
126
|
-
percent: number;
|
|
127
|
-
/**
|
|
128
|
-
* Function to set the value of the slider.
|
|
129
|
-
*/
|
|
130
|
-
setValue(value: number): void;
|
|
131
|
-
/**
|
|
132
|
-
* Returns the value of the slider at the given percent.
|
|
133
|
-
*/
|
|
134
|
-
getPercentValue: (percent: number) => number;
|
|
135
|
-
/**
|
|
136
|
-
* Returns the percent of the slider at the given value.
|
|
137
|
-
*/
|
|
138
|
-
getValuePercent: (value: number) => number;
|
|
139
109
|
/**
|
|
140
|
-
*
|
|
141
|
-
*/
|
|
142
|
-
focus(): void;
|
|
143
|
-
/**
|
|
144
|
-
* Function to increment the value of the slider by the step.
|
|
110
|
+
* The slider thumb dimensions.If not provided, the thumb size will be measured automatically.
|
|
145
111
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
decrement(): void;
|
|
151
|
-
rootProps: T["element"];
|
|
152
|
-
labelProps: T["label"];
|
|
153
|
-
thumbProps: T["element"];
|
|
154
|
-
hiddenInputProps: T["input"];
|
|
155
|
-
outputProps: T["output"];
|
|
156
|
-
trackProps: T["element"];
|
|
157
|
-
rangeProps: T["element"];
|
|
158
|
-
controlProps: T["element"];
|
|
159
|
-
markerGroupProps: T["element"];
|
|
160
|
-
getMarkerProps({ value }: {
|
|
161
|
-
value: number;
|
|
162
|
-
}): T["element"];
|
|
112
|
+
thumbSize: {
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
} | null;
|
|
163
116
|
};
|
|
164
117
|
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
165
118
|
type ComputedContext = Readonly<{
|
|
@@ -167,32 +120,37 @@ type ComputedContext = Readonly<{
|
|
|
167
120
|
* @computed
|
|
168
121
|
* Whether the slider is interactive
|
|
169
122
|
*/
|
|
170
|
-
|
|
123
|
+
isInteractive: boolean;
|
|
171
124
|
/**
|
|
172
125
|
* @computed
|
|
173
126
|
* Whether the thumb size has been measured
|
|
174
127
|
*/
|
|
175
|
-
|
|
128
|
+
hasMeasuredThumbSize: boolean;
|
|
176
129
|
/**
|
|
177
130
|
* @computed
|
|
178
131
|
* Whether the slider is horizontal
|
|
179
132
|
*/
|
|
180
|
-
|
|
133
|
+
isHorizontal: boolean;
|
|
181
134
|
/**
|
|
182
135
|
* @computed
|
|
183
136
|
* Whether the slider is vertical
|
|
184
137
|
*/
|
|
185
|
-
|
|
138
|
+
isVertical: boolean;
|
|
186
139
|
/**
|
|
187
140
|
* @computed
|
|
188
141
|
* Whether the slider is in RTL mode
|
|
189
142
|
*/
|
|
190
|
-
|
|
143
|
+
isRtl: boolean;
|
|
191
144
|
/**
|
|
192
145
|
* @computed
|
|
193
146
|
* The value of the slider as a percentage
|
|
194
147
|
*/
|
|
195
|
-
|
|
148
|
+
valuePercent: number;
|
|
149
|
+
/**
|
|
150
|
+
* @computed
|
|
151
|
+
* Whether the slider is disabled
|
|
152
|
+
*/
|
|
153
|
+
isDisabled: boolean;
|
|
196
154
|
}>;
|
|
197
155
|
type PrivateContext = Context<{}>;
|
|
198
156
|
type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
@@ -222,8 +180,62 @@ type Point = {
|
|
|
222
180
|
x: number;
|
|
223
181
|
y: number;
|
|
224
182
|
};
|
|
183
|
+
type MachineApi<T extends PropTypes = PropTypes> = {
|
|
184
|
+
/**
|
|
185
|
+
* Whether the slider is focused.
|
|
186
|
+
*/
|
|
187
|
+
isFocused: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Whether the slider is being dragged.
|
|
190
|
+
*/
|
|
191
|
+
isDragging: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* The value of the slider.
|
|
194
|
+
*/
|
|
195
|
+
value: number;
|
|
196
|
+
/**
|
|
197
|
+
* The value of the slider as a percent.
|
|
198
|
+
*/
|
|
199
|
+
percent: number;
|
|
200
|
+
/**
|
|
201
|
+
* Function to set the value of the slider.
|
|
202
|
+
*/
|
|
203
|
+
setValue(value: number): void;
|
|
204
|
+
/**
|
|
205
|
+
* Returns the value of the slider at the given percent.
|
|
206
|
+
*/
|
|
207
|
+
getPercentValue: (percent: number) => number;
|
|
208
|
+
/**
|
|
209
|
+
* Returns the percent of the slider at the given value.
|
|
210
|
+
*/
|
|
211
|
+
getValuePercent: (value: number) => number;
|
|
212
|
+
/**
|
|
213
|
+
* Function to focus the slider.
|
|
214
|
+
*/
|
|
215
|
+
focus(): void;
|
|
216
|
+
/**
|
|
217
|
+
* Function to increment the value of the slider by the step.
|
|
218
|
+
*/
|
|
219
|
+
increment(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Function to decrement the value of the slider by the step.
|
|
222
|
+
*/
|
|
223
|
+
decrement(): void;
|
|
224
|
+
rootProps: T["element"];
|
|
225
|
+
labelProps: T["label"];
|
|
226
|
+
thumbProps: T["element"];
|
|
227
|
+
hiddenInputProps: T["input"];
|
|
228
|
+
outputProps: T["output"];
|
|
229
|
+
trackProps: T["element"];
|
|
230
|
+
rangeProps: T["element"];
|
|
231
|
+
controlProps: T["element"];
|
|
232
|
+
markerGroupProps: T["element"];
|
|
233
|
+
getMarkerProps({ value }: {
|
|
234
|
+
value: number;
|
|
235
|
+
}): T["element"];
|
|
236
|
+
};
|
|
225
237
|
|
|
226
|
-
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>):
|
|
238
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
227
239
|
|
|
228
240
|
declare const dom: {
|
|
229
241
|
getRootNode: (ctx: {
|
|
@@ -241,6 +253,9 @@ declare const dom: {
|
|
|
241
253
|
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
242
254
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
243
255
|
}, id: string) => T | null;
|
|
256
|
+
setValue: <T_1 extends {
|
|
257
|
+
value: string;
|
|
258
|
+
}>(elem: T_1 | null, value: string | number | null | undefined) => void;
|
|
244
259
|
} & {
|
|
245
260
|
getRootId: (ctx: MachineContext) => string;
|
|
246
261
|
getThumbId: (ctx: MachineContext) => string;
|
|
@@ -262,7 +277,7 @@ declare const dom: {
|
|
|
262
277
|
getThumbStyle: (ctx: SharedContext) => _zag_js_types.JSX.CSSProperties;
|
|
263
278
|
getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) => _zag_js_types.JSX.CSSProperties;
|
|
264
279
|
getRootStyle: (ctx: MachineContext) => _zag_js_types.JSX.CSSProperties;
|
|
265
|
-
getMarkerStyle: (ctx: Pick<SharedContext, "isHorizontal" | "isRtl">,
|
|
280
|
+
getMarkerStyle: (ctx: Pick<SharedContext, "thumbAlignment" | "hasMeasuredThumbSize" | "isHorizontal" | "isRtl">, value: number) => _zag_js_types.JSX.CSSProperties;
|
|
266
281
|
getLabelStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
267
282
|
getTrackStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
268
283
|
getMarkerGroupStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
@@ -270,4 +285,4 @@ declare const dom: {
|
|
|
270
285
|
|
|
271
286
|
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
272
287
|
|
|
273
|
-
export { UserDefinedContext as Context,
|
|
288
|
+
export { MachineApi as Api, UserDefinedContext as Context, anatomy, connect, machine, dom as unstable__dom };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
2
|
import * as _zag_js_types from '@zag-js/types';
|
|
3
|
-
import {
|
|
3
|
+
import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
|
|
4
4
|
import * as _zag_js_core from '@zag-js/core';
|
|
5
5
|
import { StateMachine } from '@zag-js/core';
|
|
6
6
|
|
|
@@ -106,60 +106,13 @@ type PublicContext = DirectionProperty & CommonProperties & {
|
|
|
106
106
|
* - `contain`: the thumb will be contained within the bounds of the track.
|
|
107
107
|
*/
|
|
108
108
|
thumbAlignment?: "contain" | "center";
|
|
109
|
-
};
|
|
110
|
-
type PublicApi<T extends PropTypes = PropTypes> = {
|
|
111
|
-
/**
|
|
112
|
-
* Whether the slider is focused.
|
|
113
|
-
*/
|
|
114
|
-
isFocused: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Whether the slider is being dragged.
|
|
117
|
-
*/
|
|
118
|
-
isDragging: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* The value of the slider.
|
|
121
|
-
*/
|
|
122
|
-
value: number;
|
|
123
|
-
/**
|
|
124
|
-
* The value of the slider as a percent.
|
|
125
|
-
*/
|
|
126
|
-
percent: number;
|
|
127
|
-
/**
|
|
128
|
-
* Function to set the value of the slider.
|
|
129
|
-
*/
|
|
130
|
-
setValue(value: number): void;
|
|
131
|
-
/**
|
|
132
|
-
* Returns the value of the slider at the given percent.
|
|
133
|
-
*/
|
|
134
|
-
getPercentValue: (percent: number) => number;
|
|
135
|
-
/**
|
|
136
|
-
* Returns the percent of the slider at the given value.
|
|
137
|
-
*/
|
|
138
|
-
getValuePercent: (value: number) => number;
|
|
139
109
|
/**
|
|
140
|
-
*
|
|
141
|
-
*/
|
|
142
|
-
focus(): void;
|
|
143
|
-
/**
|
|
144
|
-
* Function to increment the value of the slider by the step.
|
|
110
|
+
* The slider thumb dimensions.If not provided, the thumb size will be measured automatically.
|
|
145
111
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
decrement(): void;
|
|
151
|
-
rootProps: T["element"];
|
|
152
|
-
labelProps: T["label"];
|
|
153
|
-
thumbProps: T["element"];
|
|
154
|
-
hiddenInputProps: T["input"];
|
|
155
|
-
outputProps: T["output"];
|
|
156
|
-
trackProps: T["element"];
|
|
157
|
-
rangeProps: T["element"];
|
|
158
|
-
controlProps: T["element"];
|
|
159
|
-
markerGroupProps: T["element"];
|
|
160
|
-
getMarkerProps({ value }: {
|
|
161
|
-
value: number;
|
|
162
|
-
}): T["element"];
|
|
112
|
+
thumbSize: {
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
} | null;
|
|
163
116
|
};
|
|
164
117
|
type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
165
118
|
type ComputedContext = Readonly<{
|
|
@@ -167,32 +120,37 @@ type ComputedContext = Readonly<{
|
|
|
167
120
|
* @computed
|
|
168
121
|
* Whether the slider is interactive
|
|
169
122
|
*/
|
|
170
|
-
|
|
123
|
+
isInteractive: boolean;
|
|
171
124
|
/**
|
|
172
125
|
* @computed
|
|
173
126
|
* Whether the thumb size has been measured
|
|
174
127
|
*/
|
|
175
|
-
|
|
128
|
+
hasMeasuredThumbSize: boolean;
|
|
176
129
|
/**
|
|
177
130
|
* @computed
|
|
178
131
|
* Whether the slider is horizontal
|
|
179
132
|
*/
|
|
180
|
-
|
|
133
|
+
isHorizontal: boolean;
|
|
181
134
|
/**
|
|
182
135
|
* @computed
|
|
183
136
|
* Whether the slider is vertical
|
|
184
137
|
*/
|
|
185
|
-
|
|
138
|
+
isVertical: boolean;
|
|
186
139
|
/**
|
|
187
140
|
* @computed
|
|
188
141
|
* Whether the slider is in RTL mode
|
|
189
142
|
*/
|
|
190
|
-
|
|
143
|
+
isRtl: boolean;
|
|
191
144
|
/**
|
|
192
145
|
* @computed
|
|
193
146
|
* The value of the slider as a percentage
|
|
194
147
|
*/
|
|
195
|
-
|
|
148
|
+
valuePercent: number;
|
|
149
|
+
/**
|
|
150
|
+
* @computed
|
|
151
|
+
* Whether the slider is disabled
|
|
152
|
+
*/
|
|
153
|
+
isDisabled: boolean;
|
|
196
154
|
}>;
|
|
197
155
|
type PrivateContext = Context<{}>;
|
|
198
156
|
type MachineContext = PublicContext & ComputedContext & PrivateContext;
|
|
@@ -222,8 +180,62 @@ type Point = {
|
|
|
222
180
|
x: number;
|
|
223
181
|
y: number;
|
|
224
182
|
};
|
|
183
|
+
type MachineApi<T extends PropTypes = PropTypes> = {
|
|
184
|
+
/**
|
|
185
|
+
* Whether the slider is focused.
|
|
186
|
+
*/
|
|
187
|
+
isFocused: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Whether the slider is being dragged.
|
|
190
|
+
*/
|
|
191
|
+
isDragging: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* The value of the slider.
|
|
194
|
+
*/
|
|
195
|
+
value: number;
|
|
196
|
+
/**
|
|
197
|
+
* The value of the slider as a percent.
|
|
198
|
+
*/
|
|
199
|
+
percent: number;
|
|
200
|
+
/**
|
|
201
|
+
* Function to set the value of the slider.
|
|
202
|
+
*/
|
|
203
|
+
setValue(value: number): void;
|
|
204
|
+
/**
|
|
205
|
+
* Returns the value of the slider at the given percent.
|
|
206
|
+
*/
|
|
207
|
+
getPercentValue: (percent: number) => number;
|
|
208
|
+
/**
|
|
209
|
+
* Returns the percent of the slider at the given value.
|
|
210
|
+
*/
|
|
211
|
+
getValuePercent: (value: number) => number;
|
|
212
|
+
/**
|
|
213
|
+
* Function to focus the slider.
|
|
214
|
+
*/
|
|
215
|
+
focus(): void;
|
|
216
|
+
/**
|
|
217
|
+
* Function to increment the value of the slider by the step.
|
|
218
|
+
*/
|
|
219
|
+
increment(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Function to decrement the value of the slider by the step.
|
|
222
|
+
*/
|
|
223
|
+
decrement(): void;
|
|
224
|
+
rootProps: T["element"];
|
|
225
|
+
labelProps: T["label"];
|
|
226
|
+
thumbProps: T["element"];
|
|
227
|
+
hiddenInputProps: T["input"];
|
|
228
|
+
outputProps: T["output"];
|
|
229
|
+
trackProps: T["element"];
|
|
230
|
+
rangeProps: T["element"];
|
|
231
|
+
controlProps: T["element"];
|
|
232
|
+
markerGroupProps: T["element"];
|
|
233
|
+
getMarkerProps({ value }: {
|
|
234
|
+
value: number;
|
|
235
|
+
}): T["element"];
|
|
236
|
+
};
|
|
225
237
|
|
|
226
|
-
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>):
|
|
238
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
227
239
|
|
|
228
240
|
declare const dom: {
|
|
229
241
|
getRootNode: (ctx: {
|
|
@@ -241,6 +253,9 @@ declare const dom: {
|
|
|
241
253
|
getById: <T extends HTMLElement = HTMLElement>(ctx: {
|
|
242
254
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
243
255
|
}, id: string) => T | null;
|
|
256
|
+
setValue: <T_1 extends {
|
|
257
|
+
value: string;
|
|
258
|
+
}>(elem: T_1 | null, value: string | number | null | undefined) => void;
|
|
244
259
|
} & {
|
|
245
260
|
getRootId: (ctx: MachineContext) => string;
|
|
246
261
|
getThumbId: (ctx: MachineContext) => string;
|
|
@@ -262,7 +277,7 @@ declare const dom: {
|
|
|
262
277
|
getThumbStyle: (ctx: SharedContext) => _zag_js_types.JSX.CSSProperties;
|
|
263
278
|
getRangeStyle: (ctx: Pick<SharedContext, "isVertical" | "isRtl">) => _zag_js_types.JSX.CSSProperties;
|
|
264
279
|
getRootStyle: (ctx: MachineContext) => _zag_js_types.JSX.CSSProperties;
|
|
265
|
-
getMarkerStyle: (ctx: Pick<SharedContext, "isHorizontal" | "isRtl">,
|
|
280
|
+
getMarkerStyle: (ctx: Pick<SharedContext, "thumbAlignment" | "hasMeasuredThumbSize" | "isHorizontal" | "isRtl">, value: number) => _zag_js_types.JSX.CSSProperties;
|
|
266
281
|
getLabelStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
267
282
|
getTrackStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
268
283
|
getMarkerGroupStyle: () => _zag_js_types.JSX.CSSProperties;
|
|
@@ -270,4 +285,4 @@ declare const dom: {
|
|
|
270
285
|
|
|
271
286
|
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
272
287
|
|
|
273
|
-
export { UserDefinedContext as Context,
|
|
288
|
+
export { MachineApi as Api, UserDefinedContext as Context, anatomy, connect, machine, dom as unstable__dom };
|
package/dist/index.js
CHANGED
|
@@ -63,20 +63,22 @@ function getVerticalThumbOffset(ctx) {
|
|
|
63
63
|
function getHorizontalThumbOffset(ctx) {
|
|
64
64
|
const { width = 0 } = ctx.thumbSize ?? {};
|
|
65
65
|
if (ctx.isRtl) {
|
|
66
|
-
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width
|
|
66
|
+
const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width / 2, width / 2]);
|
|
67
67
|
return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
|
|
68
68
|
}
|
|
69
69
|
const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
|
|
70
70
|
return parseFloat(getValue(ctx.value).toFixed(2));
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
if (ctx.thumbAlignment === "center") {
|
|
72
|
+
function getOffset(ctx, percent) {
|
|
73
|
+
if (ctx.thumbAlignment === "center")
|
|
75
74
|
return `${percent}%`;
|
|
76
|
-
}
|
|
77
75
|
const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
|
|
78
76
|
return `calc(${percent}% - ${offset}px)`;
|
|
79
77
|
}
|
|
78
|
+
function getThumbOffset(ctx) {
|
|
79
|
+
let percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
|
|
80
|
+
return getOffset(ctx, percent);
|
|
81
|
+
}
|
|
80
82
|
function getVisibility(ctx) {
|
|
81
83
|
let visibility = "visible";
|
|
82
84
|
if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
|
|
@@ -85,7 +87,7 @@ function getVisibility(ctx) {
|
|
|
85
87
|
return visibility;
|
|
86
88
|
}
|
|
87
89
|
function getThumbStyle(ctx) {
|
|
88
|
-
const placementProp = ctx.isVertical ? "bottom" :
|
|
90
|
+
const placementProp = ctx.isVertical ? "bottom" : "insetInlineStart";
|
|
89
91
|
return {
|
|
90
92
|
visibility: getVisibility(ctx),
|
|
91
93
|
position: "absolute",
|
|
@@ -127,17 +129,22 @@ function getControlStyle() {
|
|
|
127
129
|
function getRootStyle(ctx) {
|
|
128
130
|
const range = getRangeOffsets(ctx);
|
|
129
131
|
return {
|
|
130
|
-
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
|
|
132
|
+
"--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : ctx.isRtl ? "translateX(50%)" : "translateX(-50%)",
|
|
131
133
|
"--slider-thumb-offset": getThumbOffset(ctx),
|
|
132
134
|
"--slider-range-start": range.start,
|
|
133
135
|
"--slider-range-end": range.end
|
|
134
136
|
};
|
|
135
137
|
}
|
|
136
|
-
function getMarkerStyle(ctx,
|
|
138
|
+
function getMarkerStyle(ctx, value) {
|
|
137
139
|
return {
|
|
140
|
+
visibility: getVisibility(ctx),
|
|
138
141
|
position: "absolute",
|
|
139
142
|
pointerEvents: "none",
|
|
140
|
-
|
|
143
|
+
// @ts-expect-error
|
|
144
|
+
[ctx.isHorizontal ? "insetInlineStart" : "bottom"]: getThumbOffset({ ...ctx, value }),
|
|
145
|
+
translate: "var(--tx) var(--ty)",
|
|
146
|
+
"--tx": ctx.isHorizontal ? ctx.isRtl ? "50%" : "-50%" : "0%",
|
|
147
|
+
"--ty": !ctx.isHorizontal ? "50%" : "0%"
|
|
141
148
|
};
|
|
142
149
|
}
|
|
143
150
|
function getLabelStyle() {
|
|
@@ -208,7 +215,7 @@ function connect(state, send, normalize) {
|
|
|
208
215
|
const ariaValueText = state.context.getAriaValueText?.(state.context.value);
|
|
209
216
|
const isFocused = state.matches("focus");
|
|
210
217
|
const isDragging = state.matches("dragging");
|
|
211
|
-
const isDisabled = state.context.
|
|
218
|
+
const isDisabled = state.context.isDisabled;
|
|
212
219
|
const isInteractive = state.context.isInteractive;
|
|
213
220
|
const isInvalid = state.context.invalid;
|
|
214
221
|
function getPercentValueFn(percent) {
|
|
@@ -283,6 +290,10 @@ function connect(state, send, normalize) {
|
|
|
283
290
|
"aria-valuetext": ariaValueText,
|
|
284
291
|
role: "slider",
|
|
285
292
|
tabIndex: isDisabled ? void 0 : 0,
|
|
293
|
+
onPointerDown(event) {
|
|
294
|
+
send({ type: "THUMB_POINTER_DOWN" });
|
|
295
|
+
event.stopPropagation();
|
|
296
|
+
},
|
|
286
297
|
onBlur() {
|
|
287
298
|
if (!isInteractive)
|
|
288
299
|
return;
|
|
@@ -340,7 +351,6 @@ function connect(state, send, normalize) {
|
|
|
340
351
|
style: dom.getThumbStyle(state.context)
|
|
341
352
|
}),
|
|
342
353
|
hiddenInputProps: normalize.input({
|
|
343
|
-
type: "text",
|
|
344
354
|
defaultValue: state.context.value,
|
|
345
355
|
name: state.context.name,
|
|
346
356
|
form: state.context.form,
|
|
@@ -402,11 +412,11 @@ function connect(state, send, normalize) {
|
|
|
402
412
|
style: dom.getMarkerGroupStyle()
|
|
403
413
|
}),
|
|
404
414
|
getMarkerProps({ value }) {
|
|
405
|
-
const
|
|
406
|
-
const
|
|
407
|
-
const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
|
|
415
|
+
const style = dom.getMarkerStyle(state.context, value);
|
|
416
|
+
const markerState = value > state.context.value ? "over-value" : value === state.context.value ? "at-value" : "under-value";
|
|
408
417
|
return normalize.element({
|
|
409
418
|
...parts.marker.attrs,
|
|
419
|
+
dir: state.context.dir,
|
|
410
420
|
id: dom.getMarkerId(state.context, value),
|
|
411
421
|
role: "presentation",
|
|
412
422
|
"data-orientation": state.context.orientation,
|
|
@@ -463,28 +473,29 @@ function machine(userContext) {
|
|
|
463
473
|
context: {
|
|
464
474
|
thumbSize: null,
|
|
465
475
|
thumbAlignment: "contain",
|
|
466
|
-
disabled: false,
|
|
467
476
|
threshold: 5,
|
|
468
477
|
dir: "ltr",
|
|
469
478
|
origin: "start",
|
|
470
479
|
orientation: "horizontal",
|
|
471
|
-
initialValue: null,
|
|
472
480
|
value: 0,
|
|
473
481
|
step: 1,
|
|
474
482
|
min: 0,
|
|
475
483
|
max: 100,
|
|
476
|
-
|
|
484
|
+
disabled: false,
|
|
485
|
+
...ctx,
|
|
486
|
+
fieldsetDisabled: false
|
|
477
487
|
},
|
|
478
488
|
computed: {
|
|
479
489
|
isHorizontal: (ctx2) => ctx2.orientation === "horizontal",
|
|
480
490
|
isVertical: (ctx2) => ctx2.orientation === "vertical",
|
|
481
491
|
isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
|
|
482
|
-
|
|
492
|
+
isDisabled: (ctx2) => ctx2.disabled || ctx2.fieldsetDisabled,
|
|
493
|
+
isInteractive: (ctx2) => !(ctx2.isDisabled || ctx2.readOnly),
|
|
483
494
|
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
|
|
484
495
|
valuePercent: (ctx2) => 100 * (0, import_numeric_range5.getValuePercent)(ctx2.value, ctx2.min, ctx2.max)
|
|
485
496
|
},
|
|
486
497
|
watch: {
|
|
487
|
-
value: ["
|
|
498
|
+
value: ["syncInputElement"]
|
|
488
499
|
},
|
|
489
500
|
activities: ["trackFormControlState", "trackThumbSize"],
|
|
490
501
|
on: {
|
|
@@ -506,7 +517,11 @@ function machine(userContext) {
|
|
|
506
517
|
target: "dragging",
|
|
507
518
|
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
508
519
|
},
|
|
509
|
-
FOCUS: "focus"
|
|
520
|
+
FOCUS: "focus",
|
|
521
|
+
THUMB_POINTER_DOWN: {
|
|
522
|
+
target: "dragging",
|
|
523
|
+
actions: ["invokeOnChangeStart", "focusThumb"]
|
|
524
|
+
}
|
|
510
525
|
}
|
|
511
526
|
},
|
|
512
527
|
focus: {
|
|
@@ -516,6 +531,10 @@ function machine(userContext) {
|
|
|
516
531
|
target: "dragging",
|
|
517
532
|
actions: ["setPointerValue", "invokeOnChangeStart", "focusThumb"]
|
|
518
533
|
},
|
|
534
|
+
THUMB_POINTER_DOWN: {
|
|
535
|
+
target: "dragging",
|
|
536
|
+
actions: ["invokeOnChangeStart", "focusThumb"]
|
|
537
|
+
},
|
|
519
538
|
ARROW_LEFT: {
|
|
520
539
|
guard: "isHorizontal",
|
|
521
540
|
actions: "decrement"
|
|
@@ -568,15 +587,13 @@ function machine(userContext) {
|
|
|
568
587
|
isVertical: (ctx2) => ctx2.isVertical
|
|
569
588
|
},
|
|
570
589
|
activities: {
|
|
571
|
-
trackFormControlState(ctx2) {
|
|
590
|
+
trackFormControlState(ctx2, _evt, { initialContext }) {
|
|
572
591
|
return (0, import_form_utils2.trackFormControl)(dom.getHiddenInputEl(ctx2), {
|
|
573
|
-
|
|
574
|
-
ctx2.
|
|
592
|
+
onFieldsetDisabledChange(disabled) {
|
|
593
|
+
ctx2.fieldsetDisabled = disabled;
|
|
575
594
|
},
|
|
576
595
|
onFormReset() {
|
|
577
|
-
|
|
578
|
-
ctx2.value = ctx2.initialValue;
|
|
579
|
-
}
|
|
596
|
+
set.value(ctx2, initialContext.value);
|
|
580
597
|
}
|
|
581
598
|
});
|
|
582
599
|
},
|
|
@@ -591,7 +608,7 @@ function machine(userContext) {
|
|
|
591
608
|
});
|
|
592
609
|
},
|
|
593
610
|
trackThumbSize(ctx2, _evt) {
|
|
594
|
-
if (ctx2.thumbAlignment !== "contain")
|
|
611
|
+
if (ctx2.thumbAlignment !== "contain" || ctx2.thumbSize)
|
|
595
612
|
return;
|
|
596
613
|
return (0, import_element_size.trackElementSize)(dom.getThumbEl(ctx2), (size) => {
|
|
597
614
|
if (size)
|
|
@@ -601,9 +618,7 @@ function machine(userContext) {
|
|
|
601
618
|
},
|
|
602
619
|
actions: {
|
|
603
620
|
checkValue(ctx2) {
|
|
604
|
-
|
|
605
|
-
ctx2.value = value;
|
|
606
|
-
ctx2.initialValue = value;
|
|
621
|
+
ctx2.value = constrainValue(ctx2, ctx2.value);
|
|
607
622
|
},
|
|
608
623
|
invokeOnChangeStart(ctx2) {
|
|
609
624
|
ctx2.onChangeStart?.({ value: ctx2.value });
|
|
@@ -611,40 +626,53 @@ function machine(userContext) {
|
|
|
611
626
|
invokeOnChangeEnd(ctx2) {
|
|
612
627
|
ctx2.onChangeEnd?.({ value: ctx2.value });
|
|
613
628
|
},
|
|
614
|
-
invokeOnChange(ctx2) {
|
|
615
|
-
ctx2.onChange?.({ value: ctx2.value });
|
|
616
|
-
},
|
|
617
|
-
dispatchChangeEvent(ctx2) {
|
|
618
|
-
dom.dispatchChangeEvent(ctx2);
|
|
619
|
-
},
|
|
620
629
|
setPointerValue(ctx2, evt) {
|
|
621
630
|
const value = dom.getValueFromPoint(ctx2, evt.point);
|
|
622
631
|
if (value == null)
|
|
623
632
|
return;
|
|
624
|
-
|
|
633
|
+
set.value(ctx2, (0, import_numeric_range5.clampValue)(value, ctx2.min, ctx2.max));
|
|
625
634
|
},
|
|
626
635
|
focusThumb(ctx2) {
|
|
627
|
-
(0, import_dom_query3.raf)(() => dom.getThumbEl(ctx2)?.focus());
|
|
636
|
+
(0, import_dom_query3.raf)(() => dom.getThumbEl(ctx2)?.focus({ preventScroll: true }));
|
|
628
637
|
},
|
|
629
638
|
decrement(ctx2, evt) {
|
|
630
|
-
|
|
639
|
+
const value = decrement(ctx2, evt.step);
|
|
640
|
+
set.value(ctx2, value);
|
|
631
641
|
},
|
|
632
642
|
increment(ctx2, evt) {
|
|
633
|
-
|
|
643
|
+
const value = increment(ctx2, evt.step);
|
|
644
|
+
set.value(ctx2, value);
|
|
634
645
|
},
|
|
635
646
|
setToMin(ctx2) {
|
|
636
|
-
|
|
647
|
+
set.value(ctx2, ctx2.min);
|
|
637
648
|
},
|
|
638
649
|
setToMax(ctx2) {
|
|
639
|
-
|
|
650
|
+
set.value(ctx2, ctx2.max);
|
|
640
651
|
},
|
|
641
652
|
setValue(ctx2, evt) {
|
|
642
|
-
|
|
653
|
+
const value = constrainValue(ctx2, evt.value);
|
|
654
|
+
set.value(ctx2, value);
|
|
655
|
+
},
|
|
656
|
+
syncInputElement(ctx2) {
|
|
657
|
+
const inputEl = dom.getHiddenInputEl(ctx2);
|
|
658
|
+
dom.setValue(inputEl, ctx2.value);
|
|
643
659
|
}
|
|
644
660
|
}
|
|
645
661
|
}
|
|
646
662
|
);
|
|
647
663
|
}
|
|
664
|
+
var invoke = {
|
|
665
|
+
change: (ctx) => {
|
|
666
|
+
ctx.onChange?.({ value: ctx.value });
|
|
667
|
+
dom.dispatchChangeEvent(ctx);
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
var set = {
|
|
671
|
+
value: (ctx, value) => {
|
|
672
|
+
ctx.value = value;
|
|
673
|
+
invoke.change(ctx);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
648
676
|
// Annotate the CommonJS export names for ESM import in node:
|
|
649
677
|
0 && (module.exports = {
|
|
650
678
|
anatomy,
|