@tamagui/slider 2.0.0-rc.4 → 2.0.0-rc.40

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