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