@tamagui/slider 2.0.0-rc.9 → 2.0.0

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