@tamagui/slider 1.135.4 → 1.135.5

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,26 +1,36 @@
1
1
  "use strict";
2
+
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
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
- };
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
+ };
16
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
23
  // If the importer is in node compatibility mode or this is not an ESM
18
24
  // file that has been converted to a CommonJS file using a Babel-
19
25
  // compatible transform (i.e. "__esModule" has not been set), then set
20
26
  // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
22
- mod
23
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
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);
24
34
  var Slider_exports = {};
25
35
  __export(Slider_exports, {
26
36
  Range: () => Range,
@@ -35,99 +45,116 @@ __export(Slider_exports, {
35
45
  Track: () => Track
36
46
  });
37
47
  module.exports = __toCommonJS(Slider_exports);
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();
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();
39
63
  if (import_constants.isWeb && import_constants.isClient && !process.env.TAMAGUI_DISABLE_SLIDER_INTERVAL) {
40
64
  var _setInterval;
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
- );
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);
50
72
  }
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 ? [
73
+ var SliderHorizontal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
74
+ var {
63
75
  min,
64
- max
65
- ] : [
66
76
  max,
67
- min
68
- ], value = (0, import_helpers3.linearScale)(input, output);
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);
69
98
  return value(pointerPosition);
70
99
  }
71
- var measure = function() {
100
+ var measure = function () {
72
101
  var _sliderRef_current;
73
- (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function(_x, _y, width, _height, pageX, _pageY) {
102
+ (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function (_x, _y, width, _height, pageX, _pageY) {
74
103
  setState({
75
104
  size: width,
76
105
  offset: pageX
77
106
  });
78
107
  });
79
108
  };
80
- return import_constants.isClient && (useOnDebouncedWindowResize(measure), React.useEffect(function() {
109
+ return import_constants.isClient && (useOnDebouncedWindowResize(measure), React.useEffect(function () {
81
110
  var node = sliderRef.current;
82
111
  if (node) {
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() {
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 () {
100
127
  activeSliderMeasureListeners.delete(debouncedMeasure), io.disconnect();
101
128
  };
102
129
  }
103
- }, [])), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_constants2.SliderOrientationProvider, {
130
+ }, [])), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_constants2.SliderOrientationProvider, {
104
131
  scope: props.__scopeSlider,
105
132
  startEdge: isDirectionLTR ? "left" : "right",
106
133
  endEdge: isDirectionLTR ? "right" : "left",
107
134
  direction: isDirectionLTR ? 1 : -1,
108
135
  sizeProp: "width",
109
136
  size: state.size,
110
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SliderImpl.SliderImpl, {
137
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_SliderImpl.SliderImpl, {
111
138
  ref: (0, import_compose_refs.composeRefs)(forwardedRef, sliderRef),
112
139
  dir: direction,
113
140
  ...sliderProps,
114
141
  orientation: "horizontal",
115
142
  onLayout: measure,
116
- onSlideStart: function(event, target) {
143
+ onSlideStart: function (event, target) {
117
144
  var value = getValueFromPointer(event.nativeEvent.locationX);
118
- value && (onSlideStart == null || onSlideStart(value, target, event));
145
+ value && onSlideStart?.(value, target, event);
119
146
  },
120
- onSlideMove: function(event) {
147
+ onSlideMove: function (event) {
121
148
  var value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
122
- value && (onSlideMove == null || onSlideMove(value, event));
149
+ value && onSlideMove?.(value, event);
123
150
  },
124
- onSlideEnd: function(event) {
151
+ onSlideEnd: function (event) {
125
152
  var value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
126
- value && (onSlideEnd == null || onSlideEnd(event, value));
153
+ value && onSlideEnd?.(event, value);
127
154
  },
128
- onStepKeyDown: function(event) {
155
+ onStepKeyDown: function (event) {
129
156
  var isBackKey = import_constants2.BACK_KEYS[direction].includes(event.key);
130
- onStepKeyDown == null || onStepKeyDown({
157
+ onStepKeyDown?.({
131
158
  event,
132
159
  direction: isBackKey ? -1 : 1
133
160
  });
@@ -137,359 +164,410 @@ var SliderHorizontal = /* @__PURE__ */ React.forwardRef(function(props, forwarde
137
164
  });
138
165
  function useOnDebouncedWindowResize(callback) {
139
166
  var amt = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 200;
140
- React.useEffect(function() {
141
- var last, onResize = function() {
142
- clearTimeout(last), last = setTimeout(callback, amt);
143
- };
144
- return window.addEventListener("resize", onResize), function() {
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 () {
145
173
  clearTimeout(last), window.removeEventListener("resize", onResize);
146
174
  };
147
175
  }, []);
148
176
  }
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
154
- };
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
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
+ });
172
208
  });
209
+ };
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
+ })
173
242
  });
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"
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
+ }
219
257
  }
258
+ },
259
+ defaultVariants: {
260
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
220
261
  }
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
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
+ });
234
277
  });
235
- });
236
278
  SliderTrack.displayName = TRACK_NAME;
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
- }
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
+ });
267
318
  });
268
- });
269
319
  SliderTrackActive.displayName = RANGE_NAME;
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
285
- },
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
- }
296
- }
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
+ };
297
331
  },
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() {
309
- context.thumbs.delete(thumb);
310
- };
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"
323
- }
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]);
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
+ }
358
349
  },
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);
350
+ defaultVariants: {
351
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
384
352
  }
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);
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 () {
378
+ context.thumbs.delete(thumb);
394
379
  };
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
395
432
  }
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
- }
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);
407
463
  }
408
- } catch (err) {
409
- _didIteratorError = !0, _iteratorError = err;
410
- } finally {
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;
411
481
  try {
412
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
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;
413
491
  } finally {
414
- if (_didIteratorError)
415
- throw _iteratorError;
492
+ try {
493
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
494
+ } finally {
495
+ if (_didIteratorError) throw _iteratorError;
496
+ }
416
497
  }
417
498
  }
418
499
  }
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,
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,
449
517
  min,
450
518
  max,
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);
456
- }
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);
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
+ }
471
560
  }
472
- }
473
- })
561
+ })
562
+ });
563
+ }),
564
+ Slider = (0, import_helpers.withStaticProperties)(SliderComponent, {
565
+ Track: SliderTrack,
566
+ TrackActive: SliderTrackActive,
567
+ Thumb: SliderThumb
474
568
  });
475
- }), Slider = (0, import_helpers.withStaticProperties)(SliderComponent, {
476
- Track: SliderTrack,
477
- TrackActive: SliderTrackActive,
478
- Thumb: SliderThumb
479
- });
480
569
  Slider.displayName = import_constants2.SLIDER_NAME;
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
570
+ var Track = SliderTrack,
571
+ Range = SliderTrackActive,
572
+ Thumb = SliderThumb;
573
+ //# sourceMappingURL=Slider.native.js.map