@tamagui/slider 1.113.0 → 1.113.2

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.
@@ -9,103 +9,100 @@ import { ThemeableStack } from "@tamagui/stacks";
9
9
  import { useControllableState } from "@tamagui/use-controllable-state";
10
10
  import { useDirection } from "@tamagui/use-direction";
11
11
  import * as React from "react";
12
- import { ARROW_KEYS, BACK_KEYS, PAGE_KEYS, SLIDER_NAME, SliderOrientationProvider, SliderProvider, useSliderContext, useSliderOrientationContext } from "./constants.native.js";
13
- import { convertValueToPercentage, getClosestValueIndex, getDecimalCount, getLabel, getNextSortedValues, getThumbInBoundsOffset, hasMinStepsBetweenValues, linearScale, roundValue } from "./helpers.native.js";
14
- import { SliderFrame, SliderImpl } from "./SliderImpl.native.js";
15
- var activeSliderMeasureListeners = /* @__PURE__ */new Set();
12
+ import { ARROW_KEYS, BACK_KEYS, PAGE_KEYS, SLIDER_NAME, SliderOrientationProvider, SliderProvider, useSliderContext, useSliderOrientationContext } from "./constants";
13
+ import { convertValueToPercentage, getClosestValueIndex, getDecimalCount, getLabel, getNextSortedValues, getThumbInBoundsOffset, hasMinStepsBetweenValues, linearScale, roundValue } from "./helpers";
14
+ import { SliderFrame, SliderImpl } from "./SliderImpl";
15
+ var activeSliderMeasureListeners = /* @__PURE__ */ new Set();
16
16
  if (isWeb && isClient && !process.env.TAMAGUI_DISABLE_SLIDER_INTERVAL) {
17
17
  var _setInterval;
18
- (_setInterval = setInterval) === null || _setInterval === void 0 || _setInterval(function () {
19
- activeSliderMeasureListeners.forEach(function (cb) {
20
- return cb();
21
- });
22
- },
23
- // really doesn't need to be super often
24
- 1e3);
18
+ (_setInterval = setInterval) === null || _setInterval === void 0 || _setInterval(
19
+ function() {
20
+ activeSliderMeasureListeners.forEach(function(cb) {
21
+ return cb();
22
+ });
23
+ },
24
+ // really doesn't need to be super often
25
+ 1e3
26
+ );
25
27
  }
26
- var SliderHorizontal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
27
- var {
28
+ var SliderHorizontal = /* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
29
+ var { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, onSlideEnd, ...sliderProps } = props, direction = useDirection(dir), isDirectionLTR = direction === "ltr", sliderRef = React.useRef(null), [state, setState_] = React.useState(function() {
30
+ return {
31
+ size: 0,
32
+ offset: 0
33
+ };
34
+ }), setState = createShallowSetState(setState_);
35
+ function getValueFromPointer(pointerPosition) {
36
+ var input = [
37
+ 0,
38
+ state.size
39
+ ], output = isDirectionLTR ? [
28
40
  min,
41
+ max
42
+ ] : [
29
43
  max,
30
- dir,
31
- onSlideStart,
32
- onSlideMove,
33
- onStepKeyDown,
34
- onSlideEnd,
35
- ...sliderProps
36
- } = props,
37
- direction = useDirection(dir),
38
- isDirectionLTR = direction === "ltr",
39
- sliderRef = React.useRef(null),
40
- [state, setState_] = React.useState(function () {
41
- return {
42
- size: 0,
43
- offset: 0
44
- };
45
- }),
46
- setState = createShallowSetState(setState_);
47
- function getValueFromPointer(pointerPosition) {
48
- var input = [0, state.size],
49
- output = isDirectionLTR ? [min, max] : [max, min],
50
- value = linearScale(input, output);
44
+ min
45
+ ], value = linearScale(input, output);
51
46
  return value(pointerPosition);
52
47
  }
53
- var measure = function () {
48
+ var measure = function() {
54
49
  var _sliderRef_current;
55
- (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function (_x, _y, width, _height, pageX, _pageY) {
50
+ (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function(_x, _y, width, _height, pageX, _pageY) {
56
51
  setState({
57
52
  size: width,
58
53
  offset: pageX
59
54
  });
60
55
  });
61
56
  };
62
- return isClient && (useOnDebouncedWindowResize(measure), React.useEffect(function () {
57
+ return isClient && (useOnDebouncedWindowResize(measure), React.useEffect(function() {
63
58
  var node = sliderRef.current;
64
59
  if (node) {
65
- var measureTm,
66
- debouncedMeasure = function () {
67
- clearTimeout(measureTm), measureTm = setTimeout(function () {
68
- measure();
69
- }, 200);
70
- },
71
- io = new IntersectionObserver(function (entries) {
72
- debouncedMeasure(), entries?.[0].isIntersecting ? activeSliderMeasureListeners.add(debouncedMeasure) : activeSliderMeasureListeners.delete(debouncedMeasure);
73
- }, {
74
- root: null,
75
- // Use the viewport as the container.
76
- rootMargin: "0px",
77
- threshold: [0, 0.5, 1]
78
- });
79
- return io.observe(node), function () {
60
+ var measureTm, debouncedMeasure = function() {
61
+ clearTimeout(measureTm), measureTm = setTimeout(function() {
62
+ measure();
63
+ }, 200);
64
+ }, io = new IntersectionObserver(function(entries) {
65
+ debouncedMeasure(), entries?.[0].isIntersecting ? activeSliderMeasureListeners.add(debouncedMeasure) : activeSliderMeasureListeners.delete(debouncedMeasure);
66
+ }, {
67
+ root: null,
68
+ // Use the viewport as the container.
69
+ rootMargin: "0px",
70
+ threshold: [
71
+ 0,
72
+ 0.5,
73
+ 1
74
+ ]
75
+ });
76
+ return io.observe(node), function() {
80
77
  activeSliderMeasureListeners.delete(debouncedMeasure), io.disconnect();
81
78
  };
82
79
  }
83
- }, [])), /* @__PURE__ */_jsx(SliderOrientationProvider, {
80
+ }, [])), /* @__PURE__ */ _jsx(SliderOrientationProvider, {
84
81
  scope: props.__scopeSlider,
85
82
  startEdge: isDirectionLTR ? "left" : "right",
86
83
  endEdge: isDirectionLTR ? "right" : "left",
87
84
  direction: isDirectionLTR ? 1 : -1,
88
85
  sizeProp: "width",
89
86
  size: state.size,
90
- children: /* @__PURE__ */_jsx(SliderImpl, {
87
+ children: /* @__PURE__ */ _jsx(SliderImpl, {
91
88
  ref: composeRefs(forwardedRef, sliderRef),
92
89
  dir: direction,
93
90
  ...sliderProps,
94
91
  orientation: "horizontal",
95
92
  onLayout: measure,
96
- onSlideStart: function (event, target) {
93
+ onSlideStart: function(event, target) {
97
94
  var value = getValueFromPointer(event.nativeEvent.locationX);
98
95
  value && onSlideStart?.(value, target, event);
99
96
  },
100
- onSlideMove: function (event) {
97
+ onSlideMove: function(event) {
101
98
  var value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
102
99
  value && onSlideMove?.(value, event);
103
100
  },
104
- onSlideEnd: function (event) {
101
+ onSlideEnd: function(event) {
105
102
  var value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
106
103
  value && onSlideEnd?.(event, value);
107
104
  },
108
- onStepKeyDown: function (event) {
105
+ onStepKeyDown: function(event) {
109
106
  var isBackKey = BACK_KEYS[direction].includes(event.key);
110
107
  onStepKeyDown?.({
111
108
  event,
@@ -117,405 +114,352 @@ var SliderHorizontal = /* @__PURE__ */React.forwardRef(function (props, forwarde
117
114
  });
118
115
  function useOnDebouncedWindowResize(callback) {
119
116
  var amt = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 200;
120
- React.useEffect(function () {
121
- var last,
122
- onResize = function () {
123
- clearTimeout(last), last = setTimeout(callback, amt);
124
- };
125
- return window.addEventListener("resize", onResize), function () {
117
+ React.useEffect(function() {
118
+ var last, onResize = function() {
119
+ clearTimeout(last), last = setTimeout(callback, amt);
120
+ };
121
+ return window.addEventListener("resize", onResize), function() {
126
122
  clearTimeout(last), window.removeEventListener("resize", onResize);
127
123
  };
128
124
  }, []);
129
125
  }
130
- var SliderVertical = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
131
- var {
132
- min,
133
- max,
134
- onSlideStart,
135
- onSlideMove,
136
- onStepKeyDown,
137
- onSlideEnd,
138
- ...sliderProps
139
- } = props,
140
- [state, setState_] = React.useState(function () {
141
- return {
142
- size: 0,
143
- offset: 0
144
- };
145
- }),
146
- setState = createShallowSetState(setState_),
147
- sliderRef = React.useRef(null);
148
- function getValueFromPointer(pointerPosition) {
149
- var input = [0, state.size],
150
- output = [max, min],
151
- value = linearScale(input, output);
152
- return value(pointerPosition);
153
- }
154
- var measure = function () {
155
- var _sliderRef_current;
156
- (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function (_x, _y, _width, height, _pageX, pageY) {
157
- setState({
158
- size: height,
159
- offset: pageY
160
- });
161
- });
126
+ var SliderVertical = /* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
127
+ var { min, max, onSlideStart, onSlideMove, onStepKeyDown, onSlideEnd, ...sliderProps } = props, [state, setState_] = React.useState(function() {
128
+ return {
129
+ size: 0,
130
+ offset: 0
162
131
  };
163
- return isClient && useOnDebouncedWindowResize(measure), /* @__PURE__ */_jsx(SliderOrientationProvider, {
164
- scope: props.__scopeSlider,
165
- startEdge: "bottom",
166
- endEdge: "top",
167
- sizeProp: "height",
168
- size: state.size,
169
- direction: 1,
170
- children: /* @__PURE__ */_jsx(SliderImpl, {
171
- ref: composeRefs(forwardedRef, sliderRef),
172
- ...sliderProps,
173
- orientation: "vertical",
174
- onLayout: measure,
175
- onSlideStart: function (event, target) {
176
- var value = getValueFromPointer(event.nativeEvent.locationY);
177
- value && onSlideStart?.(value, target, event);
178
- },
179
- onSlideMove: function (event) {
180
- var value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
181
- value && onSlideMove?.(value, event);
182
- },
183
- onSlideEnd: function (event) {
184
- var value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
185
- onSlideEnd?.(event, value);
186
- },
187
- onStepKeyDown: function (event) {
188
- var isBackKey = BACK_KEYS.ltr.includes(event.key);
189
- onStepKeyDown?.({
190
- event,
191
- direction: isBackKey ? -1 : 1
192
- });
193
- }
194
- })
132
+ }), setState = createShallowSetState(setState_), sliderRef = React.useRef(null);
133
+ function getValueFromPointer(pointerPosition) {
134
+ var input = [
135
+ 0,
136
+ state.size
137
+ ], output = [
138
+ max,
139
+ min
140
+ ], value = linearScale(input, output);
141
+ return value(pointerPosition);
142
+ }
143
+ var measure = function() {
144
+ var _sliderRef_current;
145
+ (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function(_x, _y, _width, height, _pageX, pageY) {
146
+ setState({
147
+ size: height,
148
+ offset: pageY
149
+ });
195
150
  });
196
- }),
197
- TRACK_NAME = "SliderTrack",
198
- SliderTrackFrame = styled(SliderFrame, {
199
- name: "SliderTrack",
200
- variants: {
201
- unstyled: {
202
- false: {
203
- height: "100%",
204
- width: "100%",
205
- backgroundColor: "$background",
206
- position: "relative",
207
- borderRadius: 1e5,
208
- overflow: "hidden"
209
- }
151
+ };
152
+ return isClient && useOnDebouncedWindowResize(measure), /* @__PURE__ */ _jsx(SliderOrientationProvider, {
153
+ scope: props.__scopeSlider,
154
+ startEdge: "bottom",
155
+ endEdge: "top",
156
+ sizeProp: "height",
157
+ size: state.size,
158
+ direction: 1,
159
+ children: /* @__PURE__ */ _jsx(SliderImpl, {
160
+ ref: composeRefs(forwardedRef, sliderRef),
161
+ ...sliderProps,
162
+ orientation: "vertical",
163
+ onLayout: measure,
164
+ onSlideStart: function(event, target) {
165
+ var value = getValueFromPointer(event.nativeEvent.locationY);
166
+ value && onSlideStart?.(value, target, event);
167
+ },
168
+ onSlideMove: function(event) {
169
+ var value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
170
+ value && onSlideMove?.(value, event);
171
+ },
172
+ onSlideEnd: function(event) {
173
+ var value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
174
+ onSlideEnd?.(event, value);
175
+ },
176
+ onStepKeyDown: function(event) {
177
+ var isBackKey = BACK_KEYS.ltr.includes(event.key);
178
+ onStepKeyDown?.({
179
+ event,
180
+ direction: isBackKey ? -1 : 1
181
+ });
182
+ }
183
+ })
184
+ });
185
+ }), TRACK_NAME = "SliderTrack", SliderTrackFrame = styled(SliderFrame, {
186
+ name: "SliderTrack",
187
+ variants: {
188
+ unstyled: {
189
+ false: {
190
+ height: "100%",
191
+ width: "100%",
192
+ backgroundColor: "$background",
193
+ position: "relative",
194
+ borderRadius: 1e5,
195
+ overflow: "hidden"
210
196
  }
211
- },
212
- defaultVariants: {
213
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
214
197
  }
215
- }),
216
- SliderTrack = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
217
- var {
218
- __scopeSlider,
219
- ...trackProps
220
- } = props,
221
- context = useSliderContext(TRACK_NAME, __scopeSlider);
222
- return /* @__PURE__ */_jsx(SliderTrackFrame, {
223
- "data-disabled": context.disabled ? "" : void 0,
224
- "data-orientation": context.orientation,
225
- orientation: context.orientation,
226
- size: context.size,
227
- ...trackProps,
228
- ref: forwardedRef
229
- });
198
+ },
199
+ defaultVariants: {
200
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
201
+ }
202
+ }), SliderTrack = /* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
203
+ var { __scopeSlider, ...trackProps } = props, context = useSliderContext(TRACK_NAME, __scopeSlider);
204
+ return /* @__PURE__ */ _jsx(SliderTrackFrame, {
205
+ "data-disabled": context.disabled ? "" : void 0,
206
+ "data-orientation": context.orientation,
207
+ orientation: context.orientation,
208
+ size: context.size,
209
+ ...trackProps,
210
+ ref: forwardedRef
230
211
  });
212
+ });
231
213
  SliderTrack.displayName = TRACK_NAME;
232
- var RANGE_NAME = "SliderTrackActive",
233
- SliderTrackActiveFrame = styled(SliderFrame, {
234
- name: "SliderTrackActive",
235
- backgroundColor: "$background",
236
- position: "absolute"
237
- }),
238
- SliderTrackActive = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
239
- var {
240
- __scopeSlider,
241
- ...rangeProps
242
- } = props,
243
- context = useSliderContext(RANGE_NAME, __scopeSlider),
244
- orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider),
245
- ref = React.useRef(null),
246
- composedRefs = useComposedRefs(forwardedRef, ref),
247
- valuesCount = context.values.length,
248
- percentages = context.values.map(function (value) {
249
- return convertValueToPercentage(value, context.min, context.max);
250
- }),
251
- offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0,
252
- offsetEnd = 100 - Math.max(...percentages);
253
- return /* @__PURE__ */_jsx(SliderTrackActiveFrame, {
254
- orientation: context.orientation,
255
- "data-orientation": context.orientation,
256
- "data-disabled": context.disabled ? "" : void 0,
257
- size: context.size,
258
- animateOnly: ["left", "top", "right", "bottom"],
259
- ...rangeProps,
260
- ref: composedRefs,
261
- [orientation.startEdge]: `${offsetStart}%`,
262
- [orientation.endEdge]: `${offsetEnd}%`,
263
- ...(orientation.sizeProp === "width" ? {
264
- height: "100%"
265
- } : {
266
- left: 0,
267
- right: 0
268
- })
269
- });
214
+ var RANGE_NAME = "SliderTrackActive", SliderTrackActiveFrame = styled(SliderFrame, {
215
+ name: "SliderTrackActive",
216
+ backgroundColor: "$background",
217
+ position: "absolute"
218
+ }), SliderTrackActive = /* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
219
+ var { __scopeSlider, ...rangeProps } = props, context = useSliderContext(RANGE_NAME, __scopeSlider), orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider), ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, ref), valuesCount = context.values.length, percentages = context.values.map(function(value) {
220
+ return convertValueToPercentage(value, context.min, context.max);
221
+ }), offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0, offsetEnd = 100 - Math.max(...percentages);
222
+ return /* @__PURE__ */ _jsx(SliderTrackActiveFrame, {
223
+ orientation: context.orientation,
224
+ "data-orientation": context.orientation,
225
+ "data-disabled": context.disabled ? "" : void 0,
226
+ size: context.size,
227
+ animateOnly: [
228
+ "left",
229
+ "top",
230
+ "right",
231
+ "bottom"
232
+ ],
233
+ ...rangeProps,
234
+ ref: composedRefs,
235
+ [orientation.startEdge]: `${offsetStart}%`,
236
+ [orientation.endEdge]: `${offsetEnd}%`,
237
+ ...orientation.sizeProp === "width" ? {
238
+ height: "100%"
239
+ } : {
240
+ left: 0,
241
+ right: 0
242
+ }
270
243
  });
244
+ });
271
245
  SliderTrackActive.displayName = RANGE_NAME;
272
- var THUMB_NAME = "SliderThumb",
273
- getThumbSize = function (val) {
274
- var tokens = getTokens(),
275
- size = typeof val == "number" ? val : getSize(tokens.size[val], {
276
- shift: -1
277
- });
278
- return {
279
- width: size,
280
- height: size,
281
- minWidth: size,
282
- minHeight: size
283
- };
284
- },
285
- SliderThumbFrame = styled(ThemeableStack, {
286
- name: "SliderThumb",
287
- variants: {
288
- size: {
289
- "...size": getThumbSize
290
- },
291
- unstyled: {
292
- false: {
293
- position: "absolute",
294
- bordered: 2,
295
- borderWidth: 2,
296
- backgrounded: !0,
297
- pressTheme: isWeb,
298
- focusTheme: isWeb,
299
- hoverTheme: isWeb
300
- }
301
- }
246
+ var THUMB_NAME = "SliderThumb", getThumbSize = function(val) {
247
+ var tokens = getTokens(), size = typeof val == "number" ? val : getSize(tokens.size[val], {
248
+ shift: -1
249
+ });
250
+ return {
251
+ width: size,
252
+ height: size,
253
+ minWidth: size,
254
+ minHeight: size
255
+ };
256
+ }, SliderThumbFrame = styled(ThemeableStack, {
257
+ name: "SliderThumb",
258
+ variants: {
259
+ size: {
260
+ "...size": getThumbSize
302
261
  },
303
- defaultVariants: {
304
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
262
+ unstyled: {
263
+ false: {
264
+ position: "absolute",
265
+ bordered: 2,
266
+ borderWidth: 2,
267
+ backgrounded: !0,
268
+ pressTheme: isWeb,
269
+ focusTheme: isWeb,
270
+ hoverTheme: isWeb
271
+ }
305
272
  }
306
- }),
307
- SliderThumb = /* @__PURE__ */React.memo(SliderThumbFrame.styleable(function (props, forwardedRef) {
308
- var {
309
- __scopeSlider,
310
- index,
311
- size: sizeProp,
312
- ...thumbProps
313
- } = props,
314
- context = useSliderContext(THUMB_NAME, __scopeSlider),
315
- orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider),
316
- [thumb, setThumb] = React.useState(null),
317
- composedRefs = useComposedRefs(forwardedRef, setThumb),
318
- value = context.values[index],
319
- percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max),
320
- label = getLabel(index, context.values.length),
321
- _ref,
322
- sizeIn = (_ref = sizeProp ?? context.size) !== null && _ref !== void 0 ? _ref : "$true",
323
- [size, setSize] = React.useState(function () {
324
- var estimatedSize = getVariableValue(getThumbSize(sizeIn).width);
325
- return estimatedSize;
326
- }),
327
- thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
328
- React.useEffect(function () {
329
- if (thumb) return context.thumbs.set(thumb, index), function () {
273
+ },
274
+ defaultVariants: {
275
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
276
+ }
277
+ }), SliderThumb = /* @__PURE__ */ React.memo(SliderThumbFrame.styleable(function(props, forwardedRef) {
278
+ var { __scopeSlider, index, size: sizeProp, ...thumbProps } = props, context = useSliderContext(THUMB_NAME, __scopeSlider), orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider), [thumb, setThumb] = React.useState(null), composedRefs = useComposedRefs(forwardedRef, setThumb), value = context.values[index], percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max), label = getLabel(index, context.values.length), _ref, sizeIn = (_ref = sizeProp ?? context.size) !== null && _ref !== void 0 ? _ref : "$true", [size, setSize] = React.useState(function() {
279
+ var estimatedSize = getVariableValue(getThumbSize(sizeIn).width);
280
+ return estimatedSize;
281
+ }), thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
282
+ React.useEffect(function() {
283
+ if (thumb)
284
+ return context.thumbs.set(thumb, index), function() {
330
285
  context.thumbs.delete(thumb);
331
286
  };
332
- }, [thumb, context.thumbs, index]);
333
- var positionalStyles = context.orientation === "horizontal" ? {
334
- x: thumbInBoundsOffset - size / 2,
335
- y: -size / 2,
336
- top: "50%",
337
- ...(size === 0 && {
338
- top: "auto",
339
- bottom: "auto"
340
- })
341
- } : {
342
- x: -size / 2,
343
- y: size / 2,
344
- left: "50%",
345
- ...(size === 0 && {
346
- left: "auto",
347
- right: "auto"
348
- })
349
- };
350
- return /* @__PURE__ */_jsx(SliderThumbFrame, {
351
- ref: composedRefs,
352
- role: "slider",
353
- "aria-label": props["aria-label"] || label,
354
- "aria-valuemin": context.min,
355
- "aria-valuenow": value,
356
- "aria-valuemax": context.max,
357
- "aria-orientation": context.orientation,
358
- "data-orientation": context.orientation,
359
- "data-disabled": context.disabled ? "" : void 0,
360
- tabIndex: context.disabled ? void 0 : 0,
361
- animateOnly: ["transform", "left", "top", "right", "bottom"],
362
- ...positionalStyles,
363
- [orientation.startEdge]: `${percent}%`,
364
- size: sizeIn,
365
- ...thumbProps,
366
- onLayout: function (e) {
367
- setSize(e.nativeEvent.layout[orientation.sizeProp]);
368
- },
369
- /**
370
- * There will be no value on initial render while we work out the index so we hide thumbs
371
- * without a value, otherwise SSR will render them in the wrong position before they
372
- * snap into the correct position during hydration which would be visually jarring for
373
- * slower connections.
374
- */
375
- // style={value === undefined ? { display: 'none' } : props.style}
376
- onFocus: composeEventHandlers(props.onFocus, function () {
377
- context.valueIndexToChangeRef.current = index;
378
- })
379
- });
380
- })),
381
- SliderComponent = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
382
- var {
383
- name,
384
- min = 0,
385
- max = 100,
386
- step = 1,
387
- orientation = "horizontal",
388
- disabled = !1,
389
- minStepsBetweenThumbs = 0,
390
- defaultValue = [min],
391
- value,
392
- onValueChange = function () {},
393
- size: sizeProp,
394
- onSlideEnd,
395
- onSlideMove,
396
- onSlideStart,
397
- ...sliderProps
398
- } = props,
399
- sliderRef = React.useRef(null),
400
- composedRefs = useComposedRefs(sliderRef, forwardedRef),
401
- thumbRefs = React.useRef(/* @__PURE__ */new Map()),
402
- valueIndexToChangeRef = React.useRef(0),
403
- isHorizontal = orientation === "horizontal",
404
- [values = [], setValues] = useControllableState({
405
- prop: value,
406
- defaultProp: defaultValue,
407
- transition: !0,
408
- onChange: function (value2) {
409
- updateThumbFocus(valueIndexToChangeRef.current), onValueChange(value2);
287
+ }, [
288
+ thumb,
289
+ context.thumbs,
290
+ index
291
+ ]);
292
+ var positionalStyles = context.orientation === "horizontal" ? {
293
+ x: thumbInBoundsOffset - size / 2,
294
+ y: -size / 2,
295
+ top: "50%",
296
+ ...size === 0 && {
297
+ top: "auto",
298
+ bottom: "auto"
299
+ }
300
+ } : {
301
+ x: -size / 2,
302
+ y: size / 2,
303
+ left: "50%",
304
+ ...size === 0 && {
305
+ left: "auto",
306
+ right: "auto"
307
+ }
308
+ };
309
+ return /* @__PURE__ */ _jsx(SliderThumbFrame, {
310
+ ref: composedRefs,
311
+ role: "slider",
312
+ "aria-label": props["aria-label"] || label,
313
+ "aria-valuemin": context.min,
314
+ "aria-valuenow": value,
315
+ "aria-valuemax": context.max,
316
+ "aria-orientation": context.orientation,
317
+ "data-orientation": context.orientation,
318
+ "data-disabled": context.disabled ? "" : void 0,
319
+ tabIndex: context.disabled ? void 0 : 0,
320
+ animateOnly: [
321
+ "transform",
322
+ "left",
323
+ "top",
324
+ "right",
325
+ "bottom"
326
+ ],
327
+ ...positionalStyles,
328
+ [orientation.startEdge]: `${percent}%`,
329
+ size: sizeIn,
330
+ ...thumbProps,
331
+ onLayout: function(e) {
332
+ setSize(e.nativeEvent.layout[orientation.sizeProp]);
333
+ },
334
+ /**
335
+ * There will be no value on initial render while we work out the index so we hide thumbs
336
+ * without a value, otherwise SSR will render them in the wrong position before they
337
+ * snap into the correct position during hydration which would be visually jarring for
338
+ * slower connections.
339
+ */
340
+ // style={value === undefined ? { display: 'none' } : props.style}
341
+ onFocus: composeEventHandlers(props.onFocus, function() {
342
+ context.valueIndexToChangeRef.current = index;
343
+ })
344
+ });
345
+ })), SliderComponent = /* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
346
+ var { name, min = 0, max = 100, step = 1, orientation = "horizontal", disabled = !1, minStepsBetweenThumbs = 0, defaultValue = [
347
+ min
348
+ ], value, onValueChange = function() {
349
+ }, size: sizeProp, onSlideEnd, onSlideMove, onSlideStart, ...sliderProps } = props, sliderRef = React.useRef(null), composedRefs = useComposedRefs(sliderRef, forwardedRef), thumbRefs = React.useRef(/* @__PURE__ */ new Map()), valueIndexToChangeRef = React.useRef(0), isHorizontal = orientation === "horizontal", [values = [], setValues] = useControllableState({
350
+ prop: value,
351
+ defaultProp: defaultValue,
352
+ transition: !0,
353
+ onChange: function(value2) {
354
+ updateThumbFocus(valueIndexToChangeRef.current), onValueChange(value2);
355
+ }
356
+ });
357
+ isWeb && React.useEffect(function() {
358
+ var node = sliderRef.current;
359
+ if (node) {
360
+ var preventDefault = function(e) {
361
+ e.preventDefault();
362
+ };
363
+ return node.addEventListener("touchstart", preventDefault), function() {
364
+ node.removeEventListener("touchstart", preventDefault);
365
+ };
366
+ }
367
+ }, []);
368
+ function updateThumbFocus(focusIndex) {
369
+ if (isWeb) {
370
+ var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
371
+ try {
372
+ for (var _iterator = thumbRefs.current.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
373
+ var [node, index] = _step.value;
374
+ if (index === focusIndex) {
375
+ node.focus();
376
+ return;
377
+ }
410
378
  }
411
- });
412
- isWeb && React.useEffect(function () {
413
- var node = sliderRef.current;
414
- if (node) {
415
- var preventDefault = function (e) {
416
- e.preventDefault();
417
- };
418
- return node.addEventListener("touchstart", preventDefault), function () {
419
- node.removeEventListener("touchstart", preventDefault);
420
- };
421
- }
422
- }, []);
423
- function updateThumbFocus(focusIndex) {
424
- if (isWeb) {
425
- var _iteratorNormalCompletion = !0,
426
- _didIteratorError = !1,
427
- _iteratorError = void 0;
379
+ } catch (err) {
380
+ _didIteratorError = !0, _iteratorError = err;
381
+ } finally {
428
382
  try {
429
- for (var _iterator = thumbRefs.current.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
430
- var [node, index] = _step.value;
431
- if (index === focusIndex) {
432
- node.focus();
433
- return;
434
- }
435
- }
436
- } catch (err) {
437
- _didIteratorError = !0, _iteratorError = err;
383
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
438
384
  } finally {
439
- try {
440
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
441
- } finally {
442
- if (_didIteratorError) throw _iteratorError;
443
- }
385
+ if (_didIteratorError)
386
+ throw _iteratorError;
444
387
  }
445
388
  }
446
389
  }
447
- function handleSlideMove(value2, event) {
448
- updateValues(value2, valueIndexToChangeRef.current), onSlideMove?.(event, value2);
449
- }
450
- function updateValues(value2, atIndex) {
451
- var decimalCount = getDecimalCount(step),
452
- snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount),
453
- nextValue = clamp(snapToStep, [min, max]);
454
- setValues(function () {
455
- var prevValues = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [],
456
- nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
457
- return hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step) ? (valueIndexToChangeRef.current = nextValues.indexOf(nextValue), String(nextValues) === String(prevValues) ? prevValues : nextValues) : prevValues;
458
- });
459
- }
460
- var SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
461
- return /* @__PURE__ */_jsx(SliderProvider, {
462
- scope: props.__scopeSlider,
463
- disabled,
390
+ }
391
+ function handleSlideMove(value2, event) {
392
+ updateValues(value2, valueIndexToChangeRef.current), onSlideMove?.(event, value2);
393
+ }
394
+ function updateValues(value2, atIndex) {
395
+ var decimalCount = getDecimalCount(step), snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount), nextValue = clamp(snapToStep, [
396
+ min,
397
+ max
398
+ ]);
399
+ setValues(function() {
400
+ var prevValues = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
401
+ return hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step) ? (valueIndexToChangeRef.current = nextValues.indexOf(nextValue), String(nextValues) === String(prevValues) ? prevValues : nextValues) : prevValues;
402
+ });
403
+ }
404
+ var SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
405
+ return /* @__PURE__ */ _jsx(SliderProvider, {
406
+ scope: props.__scopeSlider,
407
+ disabled,
408
+ min,
409
+ max,
410
+ valueIndexToChangeRef,
411
+ thumbs: thumbRefs.current,
412
+ values,
413
+ orientation,
414
+ size: sizeProp,
415
+ children: /* @__PURE__ */ _jsx(SliderOriented, {
416
+ "aria-disabled": disabled,
417
+ "data-disabled": disabled ? "" : void 0,
418
+ ...sliderProps,
419
+ ref: composedRefs,
464
420
  min,
465
421
  max,
466
- valueIndexToChangeRef,
467
- thumbs: thumbRefs.current,
468
- values,
469
- orientation,
470
- size: sizeProp,
471
- children: /* @__PURE__ */_jsx(SliderOriented, {
472
- "aria-disabled": disabled,
473
- "data-disabled": disabled ? "" : void 0,
474
- ...sliderProps,
475
- ref: composedRefs,
476
- min,
477
- max,
478
- onSlideEnd,
479
- onSlideStart: disabled ? void 0 : function (value2, target, event) {
480
- if (target !== "thumb") {
481
- var closestIndex = getClosestValueIndex(values, value2);
482
- updateValues(value2, closestIndex);
483
- }
484
- onSlideStart?.(event, value2, target);
485
- },
486
- onSlideMove: disabled ? void 0 : handleSlideMove,
487
- onHomeKeyDown: function () {
488
- return !disabled && updateValues(min, 0);
489
- },
490
- onEndKeyDown: function () {
491
- return !disabled && updateValues(max, values.length - 1);
492
- },
493
- onStepKeyDown: function (param) {
494
- var {
495
- event,
496
- direction: stepDirection
497
- } = param;
498
- if (!disabled) {
499
- var isPageKey = PAGE_KEYS.includes(event.key),
500
- isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key),
501
- multiplier = isSkipKey ? 10 : 1,
502
- atIndex = valueIndexToChangeRef.current,
503
- value2 = values[atIndex],
504
- stepInDirection = step * multiplier * stepDirection;
505
- updateValues(value2 + stepInDirection, atIndex);
506
- }
422
+ onSlideEnd,
423
+ onSlideStart: disabled ? void 0 : function(value2, target, event) {
424
+ if (target !== "thumb") {
425
+ var closestIndex = getClosestValueIndex(values, value2);
426
+ updateValues(value2, closestIndex);
507
427
  }
508
- })
509
- });
510
- }),
511
- Slider = withStaticProperties(SliderComponent, {
512
- Track: SliderTrack,
513
- TrackActive: SliderTrackActive,
514
- Thumb: SliderThumb
428
+ onSlideStart?.(event, value2, target);
429
+ },
430
+ onSlideMove: disabled ? void 0 : handleSlideMove,
431
+ onHomeKeyDown: function() {
432
+ return !disabled && updateValues(min, 0);
433
+ },
434
+ onEndKeyDown: function() {
435
+ return !disabled && updateValues(max, values.length - 1);
436
+ },
437
+ onStepKeyDown: function(param) {
438
+ var { event, direction: stepDirection } = param;
439
+ if (!disabled) {
440
+ var isPageKey = PAGE_KEYS.includes(event.key), isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key), multiplier = isSkipKey ? 10 : 1, atIndex = valueIndexToChangeRef.current, value2 = values[atIndex], stepInDirection = step * multiplier * stepDirection;
441
+ updateValues(value2 + stepInDirection, atIndex);
442
+ }
443
+ }
444
+ })
515
445
  });
446
+ }), Slider = withStaticProperties(SliderComponent, {
447
+ Track: SliderTrack,
448
+ TrackActive: SliderTrackActive,
449
+ Thumb: SliderThumb
450
+ });
516
451
  Slider.displayName = SLIDER_NAME;
517
- var Track = SliderTrack,
518
- Range = SliderTrackActive,
519
- Thumb = SliderThumb;
520
- export { Range, Slider, SliderThumb, SliderThumbFrame, SliderTrack, SliderTrackActive, SliderTrackActiveFrame, SliderTrackFrame, Thumb, Track };
521
- //# sourceMappingURL=Slider.native.js.map
452
+ var Track = SliderTrack, Range = SliderTrackActive, Thumb = SliderThumb;
453
+ export {
454
+ Range,
455
+ Slider,
456
+ SliderThumb,
457
+ SliderThumbFrame,
458
+ SliderTrack,
459
+ SliderTrackActive,
460
+ SliderTrackActiveFrame,
461
+ SliderTrackFrame,
462
+ Thumb,
463
+ Track
464
+ };
465
+ //# sourceMappingURL=Slider.js.map