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