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