@tamagui/slider 1.89.26 → 1.89.27-1708112217600

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