@tamagui/slider 1.135.4-1761748186554 → 1.135.4

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