@tamagui/slider 1.0.1-beta.151 → 1.0.1-beta.154

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.
@@ -1,3 +1,4 @@
1
+ import { jsx } from "react/jsx-runtime";
1
2
  import { composeRefs, useComposedRefs } from "@tamagui/compose-refs";
2
3
  import {
3
4
  getSize,
@@ -33,109 +34,115 @@ import {
33
34
  roundValue
34
35
  } from "./helpers";
35
36
  import { SliderFrame, SliderImpl } from "./SliderImpl";
36
- const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
37
- const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
38
- const direction = useDirection(dir);
39
- const isDirectionLTR = direction === "ltr";
40
- const sliderRef = React.useRef(null);
41
- const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
42
- function getValueFromPointer(pointerPosition) {
43
- const input = [0, state.size];
44
- const output = isDirectionLTR ? [min, max] : [max, min];
45
- const value = linearScale(input, output);
46
- return value(pointerPosition);
47
- }
48
- return /* @__PURE__ */ React.createElement(SliderOrientationProvider, {
49
- scope: props.__scopeSlider,
50
- startEdge: isDirectionLTR ? "left" : "right",
51
- endEdge: isDirectionLTR ? "right" : "left",
52
- direction: isDirectionLTR ? 1 : -1,
53
- sizeProp: "width",
54
- size: state.size
55
- }, /* @__PURE__ */ React.createElement(SliderImpl, {
56
- ref: composeRefs(forwardedRef, sliderRef),
57
- dir: direction,
58
- ...sliderProps,
59
- orientation: "horizontal",
60
- onLayout: () => {
61
- var _a;
62
- (_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, width, _height, pageX, _pageY) => {
63
- setState({
64
- size: width,
65
- offset: pageX
66
- });
67
- });
68
- },
69
- onSlideStart: (event, target) => {
70
- const value = getValueFromPointer(event.nativeEvent.locationX);
71
- if (value) {
72
- onSlideStart == null ? void 0 : onSlideStart(value, target);
73
- }
74
- },
75
- onSlideMove: (event) => {
76
- const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
77
- if (value) {
78
- onSlideMove == null ? void 0 : onSlideMove(value);
79
- }
80
- },
81
- onSlideEnd: () => {
82
- },
83
- onStepKeyDown: (event) => {
84
- const isBackKey = BACK_KEYS[direction].includes(event.key);
85
- onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
37
+ const SliderHorizontal = React.forwardRef(
38
+ (props, forwardedRef) => {
39
+ const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
40
+ const direction = useDirection(dir);
41
+ const isDirectionLTR = direction === "ltr";
42
+ const sliderRef = React.useRef(null);
43
+ const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
44
+ function getValueFromPointer(pointerPosition) {
45
+ const input = [0, state.size];
46
+ const output = isDirectionLTR ? [min, max] : [max, min];
47
+ const value = linearScale(input, output);
48
+ return value(pointerPosition);
86
49
  }
87
- }));
88
- });
89
- const SliderVertical = React.forwardRef((props, forwardedRef) => {
90
- const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
91
- const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
92
- const sliderRef = React.useRef(null);
93
- function getValueFromPointer(pointerPosition) {
94
- const input = [0, state.size];
95
- const output = [max, min];
96
- const value = linearScale(input, output);
97
- return value(pointerPosition);
50
+ return /* @__PURE__ */ jsx(SliderOrientationProvider, {
51
+ scope: props.__scopeSlider,
52
+ startEdge: isDirectionLTR ? "left" : "right",
53
+ endEdge: isDirectionLTR ? "right" : "left",
54
+ direction: isDirectionLTR ? 1 : -1,
55
+ sizeProp: "width",
56
+ size: state.size,
57
+ children: /* @__PURE__ */ jsx(SliderImpl, {
58
+ ref: composeRefs(forwardedRef, sliderRef),
59
+ dir: direction,
60
+ ...sliderProps,
61
+ orientation: "horizontal",
62
+ onLayout: () => {
63
+ var _a;
64
+ (_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, width, _height, pageX, _pageY) => {
65
+ setState({
66
+ size: width,
67
+ offset: pageX
68
+ });
69
+ });
70
+ },
71
+ onSlideStart: (event, target) => {
72
+ const value = getValueFromPointer(event.nativeEvent.locationX);
73
+ if (value) {
74
+ onSlideStart == null ? void 0 : onSlideStart(value, target);
75
+ }
76
+ },
77
+ onSlideMove: (event) => {
78
+ const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
79
+ if (value) {
80
+ onSlideMove == null ? void 0 : onSlideMove(value);
81
+ }
82
+ },
83
+ onSlideEnd: () => {
84
+ },
85
+ onStepKeyDown: (event) => {
86
+ const isBackKey = BACK_KEYS[direction].includes(event.key);
87
+ onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
88
+ }
89
+ })
90
+ });
98
91
  }
99
- return /* @__PURE__ */ React.createElement(SliderOrientationProvider, {
100
- scope: props.__scopeSlider,
101
- startEdge: "bottom",
102
- endEdge: "top",
103
- sizeProp: "height",
104
- size: state.size,
105
- direction: 1
106
- }, /* @__PURE__ */ React.createElement(SliderImpl, {
107
- ref: composeRefs(forwardedRef, sliderRef),
108
- ...sliderProps,
109
- orientation: "vertical",
110
- onLayout: () => {
111
- var _a;
112
- (_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height, _pageX, pageY) => {
113
- setState({
114
- size: height,
115
- offset: pageY
116
- });
117
- });
118
- },
119
- onSlideStart: (event, target) => {
120
- const value = getValueFromPointer(event.nativeEvent.locationY);
121
- if (value) {
122
- onSlideStart == null ? void 0 : onSlideStart(value, target);
123
- }
124
- },
125
- onSlideMove: (event) => {
126
- const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
127
- if (value) {
128
- onSlideMove == null ? void 0 : onSlideMove(value);
129
- }
130
- },
131
- onSlideEnd: () => {
132
- },
133
- onStepKeyDown: (event) => {
134
- const isBackKey = BACK_KEYS.ltr.includes(event.key);
135
- onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
92
+ );
93
+ const SliderVertical = React.forwardRef(
94
+ (props, forwardedRef) => {
95
+ const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
96
+ const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
97
+ const sliderRef = React.useRef(null);
98
+ function getValueFromPointer(pointerPosition) {
99
+ const input = [0, state.size];
100
+ const output = [max, min];
101
+ const value = linearScale(input, output);
102
+ return value(pointerPosition);
136
103
  }
137
- }));
138
- });
104
+ return /* @__PURE__ */ jsx(SliderOrientationProvider, {
105
+ scope: props.__scopeSlider,
106
+ startEdge: "bottom",
107
+ endEdge: "top",
108
+ sizeProp: "height",
109
+ size: state.size,
110
+ direction: 1,
111
+ children: /* @__PURE__ */ jsx(SliderImpl, {
112
+ ref: composeRefs(forwardedRef, sliderRef),
113
+ ...sliderProps,
114
+ orientation: "vertical",
115
+ onLayout: () => {
116
+ var _a;
117
+ (_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height, _pageX, pageY) => {
118
+ setState({
119
+ size: height,
120
+ offset: pageY
121
+ });
122
+ });
123
+ },
124
+ onSlideStart: (event, target) => {
125
+ const value = getValueFromPointer(event.nativeEvent.locationY);
126
+ if (value) {
127
+ onSlideStart == null ? void 0 : onSlideStart(value, target);
128
+ }
129
+ },
130
+ onSlideMove: (event) => {
131
+ const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
132
+ if (value) {
133
+ onSlideMove == null ? void 0 : onSlideMove(value);
134
+ }
135
+ },
136
+ onSlideEnd: () => {
137
+ },
138
+ onStepKeyDown: (event) => {
139
+ const isBackKey = BACK_KEYS.ltr.includes(event.key);
140
+ onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
141
+ }
142
+ })
143
+ });
144
+ }
145
+ );
139
146
  const TRACK_NAME = "SliderTrack";
140
147
  const SliderTrackFrame = styled(SliderFrame, {
141
148
  name: "SliderTrack",
@@ -146,18 +153,20 @@ const SliderTrackFrame = styled(SliderFrame, {
146
153
  borderRadius: 1e5,
147
154
  overflow: "hidden"
148
155
  });
149
- const SliderTrack = React.forwardRef((props, forwardedRef) => {
150
- const { __scopeSlider, ...trackProps } = props;
151
- const context = useSliderContext(TRACK_NAME, __scopeSlider);
152
- return /* @__PURE__ */ React.createElement(SliderTrackFrame, {
153
- "data-disabled": context.disabled ? "" : void 0,
154
- "data-orientation": context.orientation,
155
- orientation: context.orientation,
156
- size: context.size,
157
- ...trackProps,
158
- ref: forwardedRef
159
- });
160
- });
156
+ const SliderTrack = React.forwardRef(
157
+ (props, forwardedRef) => {
158
+ const { __scopeSlider, ...trackProps } = props;
159
+ const context = useSliderContext(TRACK_NAME, __scopeSlider);
160
+ return /* @__PURE__ */ jsx(SliderTrackFrame, {
161
+ "data-disabled": context.disabled ? "" : void 0,
162
+ "data-orientation": context.orientation,
163
+ orientation: context.orientation,
164
+ size: context.size,
165
+ ...trackProps,
166
+ ref: forwardedRef
167
+ });
168
+ }
169
+ );
161
170
  SliderTrack.displayName = TRACK_NAME;
162
171
  const RANGE_NAME = "SliderTrackActive";
163
172
  const SliderTrackActiveFrame = styled(SliderFrame, {
@@ -165,35 +174,39 @@ const SliderTrackActiveFrame = styled(SliderFrame, {
165
174
  backgroundColor: "$background",
166
175
  position: "absolute"
167
176
  });
168
- const SliderTrackActive = React.forwardRef((props, forwardedRef) => {
169
- const { __scopeSlider, ...rangeProps } = props;
170
- const context = useSliderContext(RANGE_NAME, __scopeSlider);
171
- const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider);
172
- const ref = React.useRef(null);
173
- const composedRefs = useComposedRefs(forwardedRef, ref);
174
- const valuesCount = context.values.length;
175
- const percentages = context.values.map((value) => convertValueToPercentage(value, context.min, context.max));
176
- const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
177
- const offsetEnd = 100 - Math.max(...percentages);
178
- return /* @__PURE__ */ React.createElement(SliderTrackActiveFrame, {
179
- orientation: context.orientation,
180
- "data-orientation": context.orientation,
181
- "data-disabled": context.disabled ? "" : void 0,
182
- size: context.size,
183
- ...rangeProps,
184
- ref: composedRefs,
185
- ...{
186
- [orientation.startEdge]: offsetStart + "%",
187
- [orientation.endEdge]: offsetEnd + "%"
188
- },
189
- ...orientation.sizeProp === "width" ? {
190
- height: "100%"
191
- } : {
192
- left: 0,
193
- right: 0
194
- }
195
- });
196
- });
177
+ const SliderTrackActive = React.forwardRef(
178
+ (props, forwardedRef) => {
179
+ const { __scopeSlider, ...rangeProps } = props;
180
+ const context = useSliderContext(RANGE_NAME, __scopeSlider);
181
+ const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider);
182
+ const ref = React.useRef(null);
183
+ const composedRefs = useComposedRefs(forwardedRef, ref);
184
+ const valuesCount = context.values.length;
185
+ const percentages = context.values.map(
186
+ (value) => convertValueToPercentage(value, context.min, context.max)
187
+ );
188
+ const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
189
+ const offsetEnd = 100 - Math.max(...percentages);
190
+ return /* @__PURE__ */ jsx(SliderTrackActiveFrame, {
191
+ orientation: context.orientation,
192
+ "data-orientation": context.orientation,
193
+ "data-disabled": context.disabled ? "" : void 0,
194
+ size: context.size,
195
+ ...rangeProps,
196
+ ref: composedRefs,
197
+ ...{
198
+ [orientation.startEdge]: offsetStart + "%",
199
+ [orientation.endEdge]: offsetEnd + "%"
200
+ },
201
+ ...orientation.sizeProp === "width" ? {
202
+ height: "100%"
203
+ } : {
204
+ left: 0,
205
+ right: 0
206
+ }
207
+ });
208
+ }
209
+ );
197
210
  SliderTrackActive.displayName = RANGE_NAME;
198
211
  const THUMB_NAME = "SliderThumb";
199
212
  const getThumbSize = (val) => {
@@ -220,178 +233,184 @@ const SliderThumbFrame = styled(ThemeableStack, {
220
233
  }
221
234
  }
222
235
  });
223
- const SliderThumb = React.forwardRef((props, forwardedRef) => {
224
- const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props;
225
- const context = useSliderContext(THUMB_NAME, __scopeSlider);
226
- const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider);
227
- const [thumb, setThumb] = React.useState(null);
228
- const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node));
229
- const value = context.values[index];
230
- const percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
231
- const label = getLabel(index, context.values.length);
232
- const [size, setSize] = React.useState(() => {
233
- const estimatedSize = getVariableValue(getThumbSize(sizeProp).width);
234
- return estimatedSize;
235
- });
236
- const thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
237
- React.useEffect(() => {
238
- if (thumb) {
239
- context.thumbs.add(thumb);
240
- return () => {
241
- context.thumbs.delete(thumb);
242
- };
243
- }
244
- }, [thumb, context.thumbs]);
245
- return /* @__PURE__ */ React.createElement(SliderThumbFrame, {
246
- ref: composedRefs,
247
- role: "slider",
248
- "aria-label": props["aria-label"] || label,
249
- "aria-valuemin": context.min,
250
- "aria-valuenow": value,
251
- "aria-valuemax": context.max,
252
- "aria-orientation": context.orientation,
253
- "data-orientation": context.orientation,
254
- "data-disabled": context.disabled ? "" : void 0,
255
- tabIndex: context.disabled ? void 0 : 0,
256
- ...thumbProps,
257
- ...context.orientation === "horizontal" ? {
258
- x: thumbInBoundsOffset - size / 2,
259
- y: -size / 2,
260
- top: "50%",
261
- ...size === 0 && {
262
- top: "auto",
263
- bottom: "auto"
264
- }
265
- } : {
266
- x: -size / 2,
267
- y: size / 2,
268
- left: "50%",
269
- ...size === 0 && {
270
- left: "auto",
271
- right: "auto"
272
- }
273
- },
274
- size: sizeProp ?? context.size ?? "$4",
275
- onLayout: (e) => {
276
- setSize(e.nativeEvent.layout[orientation.sizeProp]);
277
- },
278
- ...{
279
- [orientation.startEdge]: `${percent}%`
280
- },
281
- onFocus: composeEventHandlers(props.onFocus, () => {
282
- context.valueIndexToChangeRef.current = index;
283
- })
284
- });
285
- });
286
- SliderThumb.displayName = THUMB_NAME;
287
- const Slider = withStaticProperties(React.forwardRef((props, forwardedRef) => {
288
- const {
289
- name,
290
- min = 0,
291
- max = 100,
292
- step = 1,
293
- orientation = "horizontal",
294
- disabled = false,
295
- minStepsBetweenThumbs = 0,
296
- defaultValue = [min],
297
- value,
298
- onValueChange = () => {
299
- },
300
- size: sizeProp,
301
- ...sliderProps
302
- } = props;
303
- const sliderRef = React.useRef(null);
304
- const composedRefs = useComposedRefs(sliderRef, forwardedRef);
305
- const thumbRefs = React.useRef(/* @__PURE__ */ new Set());
306
- const valueIndexToChangeRef = React.useRef(0);
307
- const isHorizontal = orientation === "horizontal";
308
- const [values = [], setValues] = useControllableState({
309
- prop: value,
310
- defaultProp: defaultValue,
311
- onChange: (value2) => {
312
- var _a;
313
- if (isWeb) {
314
- const thumbs = [...thumbRefs.current];
315
- (_a = thumbs[valueIndexToChangeRef.current]) == null ? void 0 : _a.focus();
316
- }
317
- onValueChange(value2);
318
- }
319
- });
320
- if (isWeb) {
236
+ const SliderThumb = React.forwardRef(
237
+ (props, forwardedRef) => {
238
+ const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props;
239
+ const context = useSliderContext(THUMB_NAME, __scopeSlider);
240
+ const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider);
241
+ const [thumb, setThumb] = React.useState(null);
242
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node));
243
+ const value = context.values[index];
244
+ const percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
245
+ const label = getLabel(index, context.values.length);
246
+ const [size, setSize] = React.useState(() => {
247
+ const estimatedSize = getVariableValue(getThumbSize(sizeProp).width);
248
+ return estimatedSize;
249
+ });
250
+ const thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
321
251
  React.useEffect(() => {
322
- const node = sliderRef.current;
323
- if (!node)
324
- return;
325
- const preventDefault = (e) => {
326
- e.preventDefault();
327
- };
328
- node.addEventListener("touchstart", preventDefault);
329
- return () => {
330
- node.removeEventListener("touchstart", preventDefault);
331
- };
332
- }, []);
333
- }
334
- function handleSlideMove(value2) {
335
- updateValues(value2, valueIndexToChangeRef.current);
336
- }
337
- function updateValues(value2, atIndex) {
338
- const decimalCount = getDecimalCount(step);
339
- const snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount);
340
- const nextValue = clamp(snapToStep, [min, max]);
341
- setValues((prevValues = []) => {
342
- const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
343
- if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
344
- valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
345
- return String(nextValues) === String(prevValues) ? prevValues : nextValues;
346
- } else {
347
- return prevValues;
252
+ if (thumb) {
253
+ context.thumbs.add(thumb);
254
+ return () => {
255
+ context.thumbs.delete(thumb);
256
+ };
348
257
  }
258
+ }, [thumb, context.thumbs]);
259
+ return /* @__PURE__ */ jsx(SliderThumbFrame, {
260
+ ref: composedRefs,
261
+ role: "slider",
262
+ "aria-label": props["aria-label"] || label,
263
+ "aria-valuemin": context.min,
264
+ "aria-valuenow": value,
265
+ "aria-valuemax": context.max,
266
+ "aria-orientation": context.orientation,
267
+ "data-orientation": context.orientation,
268
+ "data-disabled": context.disabled ? "" : void 0,
269
+ tabIndex: context.disabled ? void 0 : 0,
270
+ ...thumbProps,
271
+ ...context.orientation === "horizontal" ? {
272
+ x: thumbInBoundsOffset - size / 2,
273
+ y: -size / 2,
274
+ top: "50%",
275
+ ...size === 0 && {
276
+ top: "auto",
277
+ bottom: "auto"
278
+ }
279
+ } : {
280
+ x: -size / 2,
281
+ y: size / 2,
282
+ left: "50%",
283
+ ...size === 0 && {
284
+ left: "auto",
285
+ right: "auto"
286
+ }
287
+ },
288
+ size: sizeProp ?? context.size ?? "$4",
289
+ onLayout: (e) => {
290
+ setSize(e.nativeEvent.layout[orientation.sizeProp]);
291
+ },
292
+ ...{
293
+ [orientation.startEdge]: `${percent}%`
294
+ },
295
+ onFocus: composeEventHandlers(props.onFocus, () => {
296
+ context.valueIndexToChangeRef.current = index;
297
+ })
349
298
  });
350
299
  }
351
- const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
352
- return /* @__PURE__ */ React.createElement(SliderProvider, {
353
- scope: props.__scopeSlider,
354
- disabled,
355
- min,
356
- max,
357
- valueIndexToChangeRef,
358
- thumbs: thumbRefs.current,
359
- values,
360
- orientation,
361
- size: sizeProp
362
- }, /* @__PURE__ */ React.createElement(SliderOriented, {
363
- "aria-disabled": disabled,
364
- "data-disabled": disabled ? "" : void 0,
365
- ...sliderProps,
366
- ref: composedRefs,
367
- min,
368
- max,
369
- onSlideStart: disabled ? void 0 : (value2, target) => {
370
- if (target !== "thumb") {
371
- const closestIndex = getClosestValueIndex(values, value2);
372
- updateValues(value2, closestIndex);
373
- }
374
- },
375
- onSlideMove: disabled ? void 0 : handleSlideMove,
376
- onHomeKeyDown: () => !disabled && updateValues(min, 0),
377
- onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
378
- onStepKeyDown: ({ event, direction: stepDirection }) => {
379
- if (!disabled) {
380
- const isPageKey = PAGE_KEYS.includes(event.key);
381
- const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key);
382
- const multiplier = isSkipKey ? 10 : 1;
383
- const atIndex = valueIndexToChangeRef.current;
384
- const value2 = values[atIndex];
385
- const stepInDirection = step * multiplier * stepDirection;
386
- updateValues(value2 + stepInDirection, atIndex);
300
+ );
301
+ SliderThumb.displayName = THUMB_NAME;
302
+ const Slider = withStaticProperties(
303
+ React.forwardRef((props, forwardedRef) => {
304
+ const {
305
+ name,
306
+ min = 0,
307
+ max = 100,
308
+ step = 1,
309
+ orientation = "horizontal",
310
+ disabled = false,
311
+ minStepsBetweenThumbs = 0,
312
+ defaultValue = [min],
313
+ value,
314
+ onValueChange = () => {
315
+ },
316
+ size: sizeProp,
317
+ ...sliderProps
318
+ } = props;
319
+ const sliderRef = React.useRef(null);
320
+ const composedRefs = useComposedRefs(sliderRef, forwardedRef);
321
+ const thumbRefs = React.useRef(/* @__PURE__ */ new Set());
322
+ const valueIndexToChangeRef = React.useRef(0);
323
+ const isHorizontal = orientation === "horizontal";
324
+ const [values = [], setValues] = useControllableState({
325
+ prop: value,
326
+ defaultProp: defaultValue,
327
+ onChange: (value2) => {
328
+ var _a;
329
+ if (isWeb) {
330
+ const thumbs = [...thumbRefs.current];
331
+ (_a = thumbs[valueIndexToChangeRef.current]) == null ? void 0 : _a.focus();
332
+ }
333
+ onValueChange(value2);
387
334
  }
335
+ });
336
+ if (isWeb) {
337
+ React.useEffect(() => {
338
+ const node = sliderRef.current;
339
+ if (!node)
340
+ return;
341
+ const preventDefault = (e) => {
342
+ e.preventDefault();
343
+ };
344
+ node.addEventListener("touchstart", preventDefault);
345
+ return () => {
346
+ node.removeEventListener("touchstart", preventDefault);
347
+ };
348
+ }, []);
388
349
  }
389
- }));
390
- }), {
391
- Track: SliderTrack,
392
- TrackActive: SliderTrackActive,
393
- Thumb: SliderThumb
394
- });
350
+ function handleSlideMove(value2) {
351
+ updateValues(value2, valueIndexToChangeRef.current);
352
+ }
353
+ function updateValues(value2, atIndex) {
354
+ const decimalCount = getDecimalCount(step);
355
+ const snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount);
356
+ const nextValue = clamp(snapToStep, [min, max]);
357
+ setValues((prevValues = []) => {
358
+ const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
359
+ if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
360
+ valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
361
+ return String(nextValues) === String(prevValues) ? prevValues : nextValues;
362
+ } else {
363
+ return prevValues;
364
+ }
365
+ });
366
+ }
367
+ const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
368
+ return /* @__PURE__ */ jsx(SliderProvider, {
369
+ scope: props.__scopeSlider,
370
+ disabled,
371
+ min,
372
+ max,
373
+ valueIndexToChangeRef,
374
+ thumbs: thumbRefs.current,
375
+ values,
376
+ orientation,
377
+ size: sizeProp,
378
+ children: /* @__PURE__ */ jsx(SliderOriented, {
379
+ "aria-disabled": disabled,
380
+ "data-disabled": disabled ? "" : void 0,
381
+ ...sliderProps,
382
+ ref: composedRefs,
383
+ min,
384
+ max,
385
+ onSlideStart: disabled ? void 0 : (value2, target) => {
386
+ if (target !== "thumb") {
387
+ const closestIndex = getClosestValueIndex(values, value2);
388
+ updateValues(value2, closestIndex);
389
+ }
390
+ },
391
+ onSlideMove: disabled ? void 0 : handleSlideMove,
392
+ onHomeKeyDown: () => !disabled && updateValues(min, 0),
393
+ onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
394
+ onStepKeyDown: ({ event, direction: stepDirection }) => {
395
+ if (!disabled) {
396
+ const isPageKey = PAGE_KEYS.includes(event.key);
397
+ const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key);
398
+ const multiplier = isSkipKey ? 10 : 1;
399
+ const atIndex = valueIndexToChangeRef.current;
400
+ const value2 = values[atIndex];
401
+ const stepInDirection = step * multiplier * stepDirection;
402
+ updateValues(value2 + stepInDirection, atIndex);
403
+ }
404
+ }
405
+ })
406
+ });
407
+ }),
408
+ {
409
+ Track: SliderTrack,
410
+ TrackActive: SliderTrackActive,
411
+ Thumb: SliderThumb
412
+ }
413
+ );
395
414
  Slider.displayName = SLIDER_NAME;
396
415
  const Track = SliderTrack;
397
416
  const Range = SliderTrackActive;