@tamagui/slider 2.7.7 → 3.0.0-beta.1093.1

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 (115) hide show
  1. package/dist/cjs/Slider.cjs +442 -511
  2. package/dist/cjs/Slider.native.cjs +462 -0
  3. package/dist/cjs/Slider.native.js +416 -497
  4. package/dist/cjs/Slider.native.js.map +1 -1
  5. package/dist/cjs/SliderImpl.cjs +101 -129
  6. package/dist/cjs/SliderImpl.native.cjs +128 -0
  7. package/dist/cjs/SliderImpl.native.js +104 -146
  8. package/dist/cjs/SliderImpl.native.js.map +1 -1
  9. package/dist/cjs/SliderResponder.cjs +51 -0
  10. package/dist/cjs/SliderResponder.native.cjs +52 -0
  11. package/dist/cjs/SliderResponder.native.js +54 -0
  12. package/dist/cjs/SliderResponder.native.js.map +1 -0
  13. package/dist/cjs/constants.cjs +58 -45
  14. package/dist/cjs/constants.native.cjs +78 -0
  15. package/dist/cjs/constants.native.js +58 -44
  16. package/dist/cjs/constants.native.js.map +1 -1
  17. package/dist/cjs/helpers.cjs +58 -60
  18. package/dist/cjs/helpers.native.cjs +98 -0
  19. package/dist/cjs/helpers.native.js +65 -68
  20. package/dist/cjs/helpers.native.js.map +1 -1
  21. package/dist/cjs/index.cjs +15 -17
  22. package/dist/cjs/index.native.cjs +32 -0
  23. package/dist/cjs/index.native.js +15 -16
  24. package/dist/cjs/index.native.js.map +1 -1
  25. package/dist/cjs/types.cjs +9 -11
  26. package/dist/cjs/types.native.cjs +18 -0
  27. package/dist/cjs/types.native.js +9 -10
  28. package/dist/cjs/types.native.js.map +1 -1
  29. package/dist/esm/Slider.mjs +415 -474
  30. package/dist/esm/Slider.mjs.map +1 -1
  31. package/dist/esm/Slider.native.js +389 -463
  32. package/dist/esm/Slider.native.js.map +1 -1
  33. package/dist/esm/SliderImpl.mjs +84 -104
  34. package/dist/esm/SliderImpl.mjs.map +1 -1
  35. package/dist/esm/SliderImpl.native.js +88 -123
  36. package/dist/esm/SliderImpl.native.js.map +1 -1
  37. package/dist/esm/SliderResponder.mjs +26 -0
  38. package/dist/esm/SliderResponder.mjs.map +1 -0
  39. package/dist/esm/SliderResponder.native.js +31 -0
  40. package/dist/esm/SliderResponder.native.js.map +1 -0
  41. package/dist/esm/constants.mjs +38 -21
  42. package/dist/esm/constants.mjs.map +1 -1
  43. package/dist/esm/constants.native.js +38 -21
  44. package/dist/esm/constants.native.js.map +1 -1
  45. package/dist/esm/helpers.mjs +37 -36
  46. package/dist/esm/helpers.mjs.map +1 -1
  47. package/dist/esm/helpers.native.js +44 -45
  48. package/dist/esm/helpers.native.js.map +1 -1
  49. package/dist/esm/index.js +4 -3
  50. package/dist/esm/index.mjs +4 -3
  51. package/dist/esm/index.native.js +4 -3
  52. package/dist/esm/types.mjs +0 -2
  53. package/dist/esm/types.native.js +0 -2
  54. package/dist/jsx/Slider.mjs +415 -474
  55. package/dist/jsx/Slider.mjs.map +1 -1
  56. package/dist/jsx/Slider.native.cjs +462 -0
  57. package/dist/jsx/Slider.native.js +416 -497
  58. package/dist/jsx/Slider.native.js.map +1 -1
  59. package/dist/jsx/SliderImpl.mjs +84 -104
  60. package/dist/jsx/SliderImpl.mjs.map +1 -1
  61. package/dist/jsx/SliderImpl.native.cjs +128 -0
  62. package/dist/jsx/SliderImpl.native.js +104 -146
  63. package/dist/jsx/SliderImpl.native.js.map +1 -1
  64. package/dist/jsx/SliderResponder.mjs +26 -0
  65. package/dist/jsx/SliderResponder.mjs.map +1 -0
  66. package/dist/jsx/SliderResponder.native.cjs +52 -0
  67. package/dist/jsx/SliderResponder.native.js +54 -0
  68. package/dist/jsx/SliderResponder.native.js.map +1 -0
  69. package/dist/jsx/constants.mjs +38 -21
  70. package/dist/jsx/constants.mjs.map +1 -1
  71. package/dist/jsx/constants.native.cjs +78 -0
  72. package/dist/jsx/constants.native.js +58 -44
  73. package/dist/jsx/constants.native.js.map +1 -1
  74. package/dist/jsx/helpers.mjs +37 -36
  75. package/dist/jsx/helpers.mjs.map +1 -1
  76. package/dist/jsx/helpers.native.cjs +98 -0
  77. package/dist/jsx/helpers.native.js +65 -68
  78. package/dist/jsx/helpers.native.js.map +1 -1
  79. package/dist/jsx/index.js +4 -3
  80. package/dist/jsx/index.mjs +4 -3
  81. package/dist/jsx/index.native.cjs +32 -0
  82. package/dist/jsx/index.native.js +15 -16
  83. package/dist/jsx/index.native.js.map +1 -1
  84. package/dist/jsx/types.mjs +0 -2
  85. package/dist/jsx/types.native.cjs +18 -0
  86. package/dist/jsx/types.native.js +9 -10
  87. package/dist/jsx/types.native.js.map +1 -1
  88. package/package.json +19 -15
  89. package/src/Slider.tsx +168 -189
  90. package/src/SliderImpl.tsx +25 -32
  91. package/src/SliderResponder.native.tsx +25 -0
  92. package/src/SliderResponder.tsx +37 -0
  93. package/src/constants.tsx +16 -6
  94. package/src/types.ts +13 -4
  95. package/types/Slider.d.ts +229 -212
  96. package/types/Slider.d.ts.map +1 -1
  97. package/types/SliderImpl.d.ts +3 -6
  98. package/types/SliderImpl.d.ts.map +1 -1
  99. package/types/SliderResponder.d.ts +10 -0
  100. package/types/SliderResponder.d.ts.map +1 -0
  101. package/types/SliderResponder.native.d.ts +3 -0
  102. package/types/SliderResponder.native.d.ts.map +1 -0
  103. package/types/constants.d.ts +10 -10
  104. package/types/constants.d.ts.map +1 -1
  105. package/types/helpers.d.ts.map +1 -1
  106. package/types/types.d.ts +12 -4
  107. package/types/types.d.ts.map +1 -1
  108. package/dist/esm/index.js.map +0 -1
  109. package/dist/esm/index.mjs.map +0 -1
  110. package/dist/esm/index.native.js.map +0 -1
  111. package/dist/esm/types.mjs.map +0 -1
  112. package/dist/esm/types.native.js.map +0 -1
  113. package/dist/jsx/index.js.map +0 -1
  114. package/dist/jsx/index.mjs.map +0 -1
  115. package/dist/jsx/types.mjs.map +0 -1
@@ -1,490 +1,416 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { composeRefs, useComposedRefs } from "@tamagui/compose-refs";
3
3
  import { isIos, isWeb } from "@tamagui/constants";
4
- import { getTokens, getVariableValue, styled, useConfiguration, useCreateShallowSetState } from "@tamagui/core";
5
- import { getSize } from "@tamagui/get-token";
4
+ import { createRefComponent, createStyledHOC, getVariableValue, resolveSize, styled, useConfiguration, useCreateShallowSetState } from "@tamagui/core";
6
5
  import { clamp, composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
7
- import { ThemeableStack } from "@tamagui/stacks";
6
+ import { YStack } from "@tamagui/stacks";
8
7
  import { useControllableState } from "@tamagui/use-controllable-state";
9
8
  import { useDirection } from "@tamagui/use-direction";
10
9
  import * as React from "react";
11
10
  import { ARROW_KEYS, BACK_KEYS, PAGE_KEYS, SLIDER_NAME, SliderOrientationProvider, SliderProvider, useSliderContext, useSliderOrientationContext } from "./constants.native.js";
12
11
  import { convertValueToPercentage, getClosestValueIndex, getDecimalCount, getLabel, getNextSortedValues, getThumbInBoundsOffset, hasMinStepsBetweenValues, linearScale, roundValue } from "./helpers.native.js";
13
12
  import { SliderFrame, SliderImpl } from "./SliderImpl.native.js";
14
- var SliderHorizontal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
15
- var {
16
- min,
17
- max,
18
- dir,
19
- onSlideStart,
20
- onSlideMove,
21
- onStepKeyDown,
22
- onSlideEnd,
23
- ...sliderProps
24
- } = props;
25
- var direction = useDirection(dir);
26
- var isDirectionLTR = direction === "ltr";
27
- var sliderRef = React.useRef(null);
28
- var [state, setState_] = React.useState(function () {
29
- return {
30
- size: 0,
31
- offset: 0
32
- };
33
- });
34
- var setState = useCreateShallowSetState(setState_);
35
- function getValueFromPointer(pointerPosition) {
36
- return linearScale([0, state.size], isDirectionLTR ? [min, max] : [max, min])(pointerPosition);
37
- }
38
- var measure = function () {
39
- var _sliderRef_current;
40
- (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function (_x, _y, width, _height, pageX, _pageY) {
41
- setState({
42
- size: width,
43
- offset: pageX
44
- });
45
- });
46
- };
47
- return /* @__PURE__ */jsx(SliderOrientationProvider, {
48
- scope: props.__scopeSlider,
49
- startEdge: isDirectionLTR ? "left" : "right",
50
- endEdge: isDirectionLTR ? "right" : "left",
51
- direction: isDirectionLTR ? 1 : -1,
52
- sizeProp: "width",
53
- size: state.size,
54
- children: /* @__PURE__ */jsx(SliderImpl, {
55
- ref: composeRefs(forwardedRef, sliderRef),
56
- dir: direction,
57
- ...sliderProps,
58
- orientation: "horizontal",
59
- onLayout: measure,
60
- onSlideStart: function (event, target) {
61
- var value = getValueFromPointer(event.nativeEvent.locationX);
62
- if (value) onSlideStart === null || onSlideStart === void 0 || onSlideStart(value, target, event);
63
- },
64
- onSlideMove: function (event) {
65
- var value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
66
- if (value) onSlideMove === null || onSlideMove === void 0 || onSlideMove(value, event);
67
- },
68
- onSlideEnd: function (event) {
69
- var value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
70
- if (value) onSlideEnd === null || onSlideEnd === void 0 || onSlideEnd(event, value);
71
- },
72
- onStepKeyDown: function (event) {
73
- var isBackKey = BACK_KEYS[direction].includes(event.key);
74
- onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
75
- event,
76
- direction: isBackKey ? -1 : 1
77
- });
78
- }
79
- })
80
- });
13
+
14
+ var getTrackPosition = function(event, offset, orientation) {
15
+ var { locationX, locationY, pageX, pageY } = event.nativeEvent;
16
+ if (isWeb) return orientation === "horizontal" ? locationX : locationY;
17
+ return (orientation === "horizontal" ? pageX : pageY) - offset;
18
+ };
19
+ var SliderHorizontal = createRefComponent(function(props, forwardedRef) {
20
+ var { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, onSlideEnd, ...sliderProps } = props;
21
+ var direction = useDirection(dir);
22
+ var isDirectionLTR = direction === "ltr";
23
+ var sliderRef = React.useRef(null);
24
+ var [state, setState_] = React.useState(function() {
25
+ return {
26
+ size: 0,
27
+ offset: 0
28
+ };
29
+ });
30
+ var setState = useCreateShallowSetState(setState_);
31
+ function getValueFromPointer(pointerPosition) {
32
+ return linearScale([0, state.size], isDirectionLTR ? [min, max] : [max, min])(pointerPosition);
33
+ }
34
+ var measure = function() {
35
+ var _sliderRef_current;
36
+ (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function(_x, _y, width, _height, pageX, _pageY) {
37
+ setState({
38
+ size: width,
39
+ offset: pageX
40
+ });
41
+ });
42
+ };
43
+ return /* @__PURE__ */ jsx(SliderOrientationProvider, {
44
+ scope: props.__scopeSlider,
45
+ startEdge: isDirectionLTR ? "left" : "right",
46
+ endEdge: isDirectionLTR ? "right" : "left",
47
+ direction: isDirectionLTR ? 1 : -1,
48
+ sizeProp: "width",
49
+ size: state.size,
50
+ children: /* @__PURE__ */ jsx(SliderImpl, {
51
+ ref: composeRefs(forwardedRef, sliderRef),
52
+ dir: direction,
53
+ ...sliderProps,
54
+ orientation: "horizontal",
55
+ onLayout: measure,
56
+ onSlideStart: function(event, target) {
57
+ var value = getValueFromPointer(event.nativeEvent.locationX);
58
+ if (value) onSlideStart === null || onSlideStart === void 0 || onSlideStart(value, target, event);
59
+ },
60
+ onSlideMove: function(event) {
61
+ var value = getValueFromPointer(getTrackPosition(event, state.offset, "horizontal"));
62
+ if (value) onSlideMove === null || onSlideMove === void 0 || onSlideMove(value, event);
63
+ },
64
+ onSlideEnd: function(event) {
65
+ var value = getValueFromPointer(getTrackPosition(event, state.offset, "horizontal"));
66
+ if (value) onSlideEnd === null || onSlideEnd === void 0 || onSlideEnd(event, value);
67
+ },
68
+ onStepKeyDown: function(event) {
69
+ var isBackKey = BACK_KEYS[direction].includes(event.key);
70
+ onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
71
+ event,
72
+ direction: isBackKey ? -1 : 1
73
+ });
74
+ }
75
+ })
76
+ });
81
77
  });
82
- var SliderVertical = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
83
- var {
84
- min,
85
- max,
86
- onSlideStart,
87
- onSlideMove,
88
- onStepKeyDown,
89
- onSlideEnd,
90
- ...sliderProps
91
- } = props;
92
- var [state, setState_] = React.useState(function () {
93
- return {
94
- size: 0,
95
- offset: 0
96
- };
97
- });
98
- var setState = useCreateShallowSetState(setState_);
99
- var sliderRef = React.useRef(null);
100
- var configuration = useConfiguration();
101
- var insets = isIos && configuration.insets ? configuration.insets : {
102
- top: 0,
103
- bottom: 0
104
- };
105
- function getValueFromPointer(pointerPosition) {
106
- return linearScale([0, state.size], [max, min])(pointerPosition);
107
- }
108
- var measure = function () {
109
- var _sliderRef_current;
110
- (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function (_x, _y, _width, height, _pageX, pageY) {
111
- setState({
112
- size: height,
113
- offset: pageY + (isIos ? insets.top : 0)
114
- });
115
- });
116
- };
117
- return /* @__PURE__ */jsx(SliderOrientationProvider, {
118
- scope: props.__scopeSlider,
119
- startEdge: "bottom",
120
- endEdge: "top",
121
- sizeProp: "height",
122
- size: state.size,
123
- direction: 1,
124
- children: /* @__PURE__ */jsx(SliderImpl, {
125
- ref: composeRefs(forwardedRef, sliderRef),
126
- ...sliderProps,
127
- orientation: "vertical",
128
- onLayout: measure,
129
- onSlideStart: function (event, target) {
130
- var value = getValueFromPointer(event.nativeEvent.locationY);
131
- if (value) onSlideStart === null || onSlideStart === void 0 || onSlideStart(value, target, event);
132
- },
133
- onSlideMove: function (event) {
134
- var value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
135
- if (value) onSlideMove === null || onSlideMove === void 0 || onSlideMove(value, event);
136
- },
137
- onSlideEnd: function (event) {
138
- var value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
139
- onSlideEnd === null || onSlideEnd === void 0 || onSlideEnd(event, value);
140
- },
141
- onStepKeyDown: function (event) {
142
- var isBackKey = BACK_KEYS.ltr.includes(event.key);
143
- onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
144
- event,
145
- direction: isBackKey ? -1 : 1
146
- });
147
- }
148
- })
149
- });
78
+ var SliderVertical = createRefComponent(function(props, forwardedRef) {
79
+ var { min, max, onSlideStart, onSlideMove, onStepKeyDown, onSlideEnd, ...sliderProps } = props;
80
+ var [state, setState_] = React.useState(function() {
81
+ return {
82
+ size: 0,
83
+ offset: 0
84
+ };
85
+ });
86
+ var setState = useCreateShallowSetState(setState_);
87
+ var sliderRef = React.useRef(null);
88
+ var configuration = useConfiguration();
89
+ var insets = isIos && configuration.insets ? configuration.insets : {
90
+ top: 0,
91
+ bottom: 0
92
+ };
93
+ function getValueFromPointer(pointerPosition) {
94
+ return linearScale([0, state.size], [max, min])(pointerPosition);
95
+ }
96
+ var measure = function() {
97
+ var _sliderRef_current;
98
+ (_sliderRef_current = sliderRef.current) === null || _sliderRef_current === void 0 || _sliderRef_current.measure(function(_x, _y, _width, height, _pageX, pageY) {
99
+ setState({
100
+ size: height,
101
+ offset: pageY + (isIos ? insets.top : 0)
102
+ });
103
+ });
104
+ };
105
+ return /* @__PURE__ */ jsx(SliderOrientationProvider, {
106
+ scope: props.__scopeSlider,
107
+ startEdge: "bottom",
108
+ endEdge: "top",
109
+ sizeProp: "height",
110
+ size: state.size,
111
+ direction: 1,
112
+ children: /* @__PURE__ */ jsx(SliderImpl, {
113
+ ref: composeRefs(forwardedRef, sliderRef),
114
+ ...sliderProps,
115
+ orientation: "vertical",
116
+ onLayout: measure,
117
+ onSlideStart: function(event, target) {
118
+ var value = getValueFromPointer(event.nativeEvent.locationY);
119
+ if (value) onSlideStart === null || onSlideStart === void 0 || onSlideStart(value, target, event);
120
+ },
121
+ onSlideMove: function(event) {
122
+ var value = getValueFromPointer(getTrackPosition(event, state.offset, "vertical"));
123
+ if (value) onSlideMove === null || onSlideMove === void 0 || onSlideMove(value, event);
124
+ },
125
+ onSlideEnd: function(event) {
126
+ var value = getValueFromPointer(getTrackPosition(event, state.offset, "vertical"));
127
+ onSlideEnd === null || onSlideEnd === void 0 || onSlideEnd(event, value);
128
+ },
129
+ onStepKeyDown: function(event) {
130
+ var isBackKey = BACK_KEYS.ltr.includes(event.key);
131
+ onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
132
+ event,
133
+ direction: isBackKey ? -1 : 1
134
+ });
135
+ }
136
+ })
137
+ });
150
138
  });
151
139
  var SliderTrackFrame = styled(SliderFrame, {
152
- name: "Slider",
153
- variants: {
154
- unstyled: {
155
- false: {
156
- height: "100%",
157
- width: "100%",
158
- backgroundColor: "$background",
159
- position: "relative",
160
- borderRadius: 1e5,
161
- overflow: "hidden"
162
- }
163
- }
164
- },
165
- defaultVariants: {
166
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
167
- }
140
+ displayName: "Slider",
141
+ height: "100%",
142
+ width: "100%",
143
+ position: "relative",
144
+ overflow: "hidden"
168
145
  });
169
- var SliderTrack = /* @__PURE__ */React.forwardRef(function SliderTrack2(props, forwardedRef) {
170
- var {
171
- __scopeSlider,
172
- ...trackProps
173
- } = props;
174
- var context = useSliderContext(__scopeSlider);
175
- return /* @__PURE__ */jsx(SliderTrackFrame, {
176
- "data-disabled": context.disabled ? "" : void 0,
177
- "data-orientation": context.orientation,
178
- orientation: context.orientation,
179
- size: context.size,
180
- ...trackProps,
181
- ref: forwardedRef
182
- });
146
+ var SliderTrack = createStyledHOC(SliderTrackFrame, function SliderTrack2(props, forwardedRef) {
147
+ var { __scopeSlider, ...trackProps } = props;
148
+ var context = useSliderContext(__scopeSlider);
149
+ var _context_size;
150
+ return /* @__PURE__ */ jsx(SliderTrackFrame, {
151
+ "data-disabled": context.disabled ? "" : void 0,
152
+ "data-orientation": context.orientation,
153
+ orientation: context.orientation,
154
+ size: (_context_size = context.size) !== null && _context_size !== void 0 ? _context_size : void 0,
155
+ ...trackProps,
156
+ ref: forwardedRef
157
+ });
183
158
  });
184
159
  var SliderActiveFrame = styled(SliderFrame, {
185
- name: "SliderActive",
186
- position: "absolute",
187
- pointerEvents: "box-none",
188
- variants: {
189
- unstyled: {
190
- false: {
191
- backgroundColor: "$background",
192
- borderRadius: 1e5
193
- }
194
- }
195
- },
196
- defaultVariants: {
197
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
198
- }
160
+ displayName: "SliderActive",
161
+ position: "absolute",
162
+ pointerEvents: "box-none"
199
163
  });
200
- var SliderActive = /* @__PURE__ */React.forwardRef(function SliderActive2(props, forwardedRef) {
201
- var {
202
- __scopeSlider,
203
- ...rangeProps
204
- } = props;
205
- var context = useSliderContext(__scopeSlider);
206
- var orientation = useSliderOrientationContext(__scopeSlider);
207
- var composedRefs = useComposedRefs(forwardedRef, React.useRef(null));
208
- var valuesCount = context.values.length;
209
- var percentages = context.values.map(function (value) {
210
- return convertValueToPercentage(value, context.min, context.max);
211
- });
212
- var offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
213
- var offsetEnd = 100 - Math.max(...percentages);
214
- return /* @__PURE__ */jsx(SliderActiveFrame, {
215
- orientation: context.orientation,
216
- "data-orientation": context.orientation,
217
- "data-disabled": context.disabled ? "" : void 0,
218
- size: context.size,
219
- animateOnly: ["left", "top", "right", "bottom"],
220
- ...rangeProps,
221
- ref: composedRefs,
222
- [orientation.startEdge]: `${offsetStart}%`,
223
- [orientation.endEdge]: `${offsetEnd}%`,
224
- ...(orientation.sizeProp === "width" ? {
225
- height: "100%"
226
- } : {
227
- left: 0,
228
- right: 0
229
- })
230
- });
164
+ var SliderActive = createStyledHOC(SliderActiveFrame, function SliderActive2(props, forwardedRef) {
165
+ var { __scopeSlider, ...rangeProps } = props;
166
+ var context = useSliderContext(__scopeSlider);
167
+ var orientation = useSliderOrientationContext(__scopeSlider);
168
+ var composedRefs = useComposedRefs(forwardedRef, React.useRef(null));
169
+ var valuesCount = context.values.length;
170
+ var percentages = context.values.map(function(value) {
171
+ return convertValueToPercentage(value, context.min, context.max);
172
+ });
173
+ var offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
174
+ var offsetEnd = 100 - Math.max(...percentages);
175
+ var _context_size;
176
+ return /* @__PURE__ */ jsx(SliderActiveFrame, {
177
+ orientation: context.orientation,
178
+ "data-orientation": context.orientation,
179
+ "data-disabled": context.disabled ? "" : void 0,
180
+ size: (_context_size = context.size) !== null && _context_size !== void 0 ? _context_size : void 0,
181
+ ...rangeProps,
182
+ ref: composedRefs,
183
+ [orientation.startEdge]: `${offsetStart}%`,
184
+ [orientation.endEdge]: `${offsetEnd}%`,
185
+ ...orientation.sizeProp === "width" ? { height: "100%" } : {
186
+ left: 0,
187
+ right: 0
188
+ }
189
+ });
231
190
  });
232
- var getThumbSize = function (val) {
233
- var tokens = getTokens();
234
- var size = typeof val === "number" ? val : getSize(tokens.size[val], {
235
- shift: -1
236
- });
237
- return {
238
- width: size,
239
- height: size,
240
- minWidth: size,
241
- minHeight: size
242
- };
191
+ var thumbSize = function(val, env) {
192
+ if (typeof val === "number") return val;
193
+ var { text } = resolveSize(val, env);
194
+ var _text_lineHeight;
195
+ return getVariableValue((_text_lineHeight = text.lineHeight) !== null && _text_lineHeight !== void 0 ? _text_lineHeight : text.fontSize);
243
196
  };
244
- var SliderThumbFrame = styled(ThemeableStack, {
245
- name: "SliderThumb",
246
- variants: {
247
- size: {
248
- "...size": getThumbSize,
249
- ":number": getThumbSize
250
- },
251
- unstyled: {
252
- false: {
253
- position: "absolute",
254
- borderWidth: 2,
255
- borderColor: "$borderColor",
256
- backgroundColor: "$background",
257
- pressStyle: {
258
- backgroundColor: "$backgroundPress",
259
- borderColor: "$borderColorPress"
260
- },
261
- hoverStyle: {
262
- backgroundColor: "$backgroundHover",
263
- borderColor: "$borderColorHover"
264
- },
265
- focusVisibleStyle: {
266
- outlineStyle: "solid",
267
- outlineWidth: 2,
268
- outlineColor: "$outlineColor"
269
- }
270
- }
271
- }
272
- },
273
- defaultVariants: {
274
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
275
- }
276
- });
277
- var SliderThumb = SliderThumbFrame.styleable(function SliderThumb2(props, forwardedRef) {
278
- var {
279
- __scopeSlider,
280
- index = 0,
281
- circular,
282
- size: sizeProp,
283
- ...thumbProps
284
- } = props;
285
- var context = useSliderContext(__scopeSlider);
286
- var orientation = useSliderOrientationContext(__scopeSlider);
287
- var [thumb, setThumb] = React.useState(null);
288
- var composedRefs = useComposedRefs(forwardedRef, setThumb);
289
- var value = context.values[index];
290
- var percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
291
- var label = getLabel(index, context.values.length);
292
- var _ref;
293
- var sizeIn = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : context.size) !== null && _ref !== void 0 ? _ref : "$true";
294
- var [size, setSize] = React.useState(function () {
295
- return getVariableValue(getThumbSize(sizeIn).width);
296
- });
297
- var thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
298
- React.useEffect(function () {
299
- if (thumb) {
300
- context.thumbs.set(thumb, index);
301
- return function () {
302
- context.thumbs.delete(thumb);
303
- };
304
- }
305
- }, [thumb, context.thumbs, index]);
306
- var positionalStyles = context.orientation === "horizontal" ? {
307
- x: (thumbInBoundsOffset - size / 2) * orientation.direction,
308
- y: -size / 2,
309
- top: "50%",
310
- ...(size === 0 && {
311
- top: "auto",
312
- bottom: "auto"
313
- })
314
- } : {
315
- x: -size / 2,
316
- y: size / 2,
317
- left: "50%",
318
- ...(size === 0 && {
319
- left: "auto",
320
- right: "auto"
321
- })
322
- };
323
- return /* @__PURE__ */jsx(SliderThumbFrame, {
324
- ref: composedRefs,
325
- role: "slider",
326
- "aria-label": props["aria-label"] || label,
327
- "aria-valuemin": context.min,
328
- "aria-valuenow": value,
329
- "aria-valuemax": context.max,
330
- "aria-orientation": context.orientation,
331
- "data-orientation": context.orientation,
332
- "data-disabled": context.disabled ? "" : void 0,
333
- tabIndex: context.disabled ? void 0 : 0,
334
- animateOnly: ["transform", "left", "top", "right", "bottom"],
335
- ...positionalStyles,
336
- [orientation.startEdge]: `${percent}%`,
337
- size: sizeIn,
338
- circular,
339
- ...thumbProps,
340
- onLayout: function (e) {
341
- setSize(e.nativeEvent.layout[orientation.sizeProp]);
342
- },
343
- onFocus: composeEventHandlers(props.onFocus, function () {
344
- context.valueIndexToChangeRef.current = index;
345
- })
346
- });
347
- }, {
348
- staticConfig: {
349
- memo: true
350
- }
197
+ var SliderThumbFrame = styled(YStack, {
198
+ displayName: "SliderThumb",
199
+ position: "absolute",
200
+ variants: {
201
+ size: styled.dynamic(function(val, env) {
202
+ var size = thumbSize(val, env);
203
+ return {
204
+ width: size,
205
+ height: size,
206
+ minWidth: size,
207
+ minHeight: size
208
+ };
209
+ }),
210
+ circular: { true: {
211
+ borderRadius: 1e5,
212
+ padding: 0
213
+ } },
214
+ elevate: { true: {
215
+ shadowColor: "shadow-color",
216
+ shadowRadius: 4,
217
+ shadowOffset: {
218
+ width: 0,
219
+ height: 2
220
+ }
221
+ } }
222
+ }
351
223
  });
352
- var Slider = withStaticProperties(/* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
353
- var {
354
- name,
355
- min = 0,
356
- max = 100,
357
- step = 1,
358
- orientation = "horizontal",
359
- disabled = false,
360
- minStepsBetweenThumbs = 0,
361
- defaultValue = [min],
362
- value,
363
- onValueChange = function () {},
364
- size: sizeProp,
365
- onSlideEnd,
366
- onSlideMove,
367
- onSlideStart,
368
- ...sliderProps
369
- } = props;
370
- var sliderRef = React.useRef(null);
371
- var composedRefs = useComposedRefs(sliderRef, forwardedRef);
372
- var thumbRefs = React.useRef(/* @__PURE__ */new Map());
373
- var valueIndexToChangeRef = React.useRef(0);
374
- var isHorizontal = orientation === "horizontal";
375
- var [values = [], setValues] = useControllableState({
376
- prop: value,
377
- defaultProp: defaultValue,
378
- transition: true,
379
- onChange: function (value2) {
380
- updateThumbFocus(valueIndexToChangeRef.current);
381
- onValueChange(value2);
382
- }
383
- });
384
- if (isWeb) React.useEffect(function () {
385
- var node = sliderRef.current;
386
- if (!node) return;
387
- var preventDefault = function (e) {
388
- e.preventDefault();
389
- };
390
- node.addEventListener("touchstart", preventDefault);
391
- return function () {
392
- node.removeEventListener("touchstart", preventDefault);
393
- };
394
- }, []);
395
- function updateThumbFocus(focusIndex) {
396
- if (!isWeb) return;
397
- var _iteratorNormalCompletion = true,
398
- _didIteratorError = false,
399
- _iteratorError = void 0;
400
- try {
401
- for (var _iterator = thumbRefs.current.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
402
- var [node, index] = _step.value;
403
- if (index === focusIndex) {
404
- node.focus();
405
- return;
406
- }
407
- }
408
- } catch (err) {
409
- _didIteratorError = true;
410
- _iteratorError = err;
411
- } finally {
412
- try {
413
- if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
414
- } finally {
415
- if (_didIteratorError) throw _iteratorError;
416
- }
417
- }
418
- }
419
- function handleSlideMove(value2, event) {
420
- updateValues(value2, valueIndexToChangeRef.current);
421
- onSlideMove === null || onSlideMove === void 0 || onSlideMove(event, value2);
422
- }
423
- function updateValues(value2, atIndex) {
424
- var decimalCount = getDecimalCount(step);
425
- var nextValue = clamp(roundValue(Math.round((value2 - min) / step) * step + min, decimalCount), [min, max]);
426
- setValues(function () {
427
- var prevValues = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
428
- var nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
429
- if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
430
- valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
431
- return String(nextValues) === String(prevValues) ? prevValues : nextValues;
432
- }
433
- return prevValues;
434
- });
435
- }
436
- var SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
437
- return /* @__PURE__ */jsx(SliderProvider, {
438
- scope: props.__scopeSlider,
439
- disabled,
440
- min,
441
- max,
442
- valueIndexToChangeRef,
443
- thumbs: thumbRefs.current,
444
- values,
445
- orientation,
446
- size: sizeProp,
447
- children: /* @__PURE__ */jsx(SliderOriented, {
448
- "aria-disabled": disabled,
449
- "data-disabled": disabled ? "" : void 0,
450
- ...sliderProps,
451
- ref: composedRefs,
452
- min,
453
- max,
454
- onSlideEnd,
455
- onSlideStart: disabled ? void 0 : function (value2, target, event) {
456
- if (target !== "thumb") updateValues(value2, getClosestValueIndex(values, value2));
457
- onSlideStart === null || onSlideStart === void 0 || onSlideStart(event, value2, target);
458
- },
459
- onSlideMove: disabled ? void 0 : handleSlideMove,
460
- onHomeKeyDown: function () {
461
- return !disabled && updateValues(min, 0);
462
- },
463
- onEndKeyDown: function () {
464
- return !disabled && updateValues(max, values.length - 1);
465
- },
466
- onStepKeyDown: function (param) {
467
- var {
468
- event,
469
- direction: stepDirection
470
- } = param;
471
- if (!disabled) {
472
- var multiplier = PAGE_KEYS.includes(event.key) || event.shiftKey && ARROW_KEYS.includes(event.key) ? 10 : 1;
473
- var atIndex = valueIndexToChangeRef.current;
474
- var value2 = values[atIndex];
475
- updateValues(value2 + step * multiplier * stepDirection, atIndex);
476
- }
477
- }
478
- })
479
- });
224
+ var SliderThumb = createStyledHOC(SliderThumbFrame, function SliderThumb2(props, forwardedRef) {
225
+ var { __scopeSlider, index = 0, circular, size: sizeProp, ...thumbProps } = props;
226
+ var context = useSliderContext(__scopeSlider);
227
+ var orientation = useSliderOrientationContext(__scopeSlider);
228
+ var [thumb, setThumb] = React.useState(null);
229
+ var composedRefs = useComposedRefs(forwardedRef, setThumb);
230
+ var value = context.values[index];
231
+ var percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
232
+ var label = getLabel(index, context.values.length);
233
+ var _ref;
234
+ var sizeIn = (_ref = sizeProp !== null && sizeProp !== void 0 ? sizeProp : context.size) !== null && _ref !== void 0 ? _ref : true;
235
+ var [size, setSize] = React.useState(function() {
236
+ return thumbSize(sizeIn);
237
+ });
238
+ var thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
239
+ React.useEffect(function() {
240
+ if (thumb) {
241
+ context.thumbs.set(thumb, index);
242
+ return function() {
243
+ context.thumbs.delete(thumb);
244
+ };
245
+ }
246
+ }, [
247
+ thumb,
248
+ context.thumbs,
249
+ index
250
+ ]);
251
+ var positionalStyles = context.orientation === "horizontal" ? {
252
+ x: (thumbInBoundsOffset - size / 2) * orientation.direction,
253
+ y: -size / 2,
254
+ top: "50%",
255
+ ...size === 0 && {
256
+ top: "auto",
257
+ bottom: "auto"
258
+ }
259
+ } : {
260
+ x: -size / 2,
261
+ y: size / 2,
262
+ left: "50%",
263
+ ...size === 0 && {
264
+ left: "auto",
265
+ right: "auto"
266
+ }
267
+ };
268
+ return /* @__PURE__ */ jsx(SliderThumbFrame, {
269
+ ref: composedRefs,
270
+ role: "slider",
271
+ "aria-label": props["aria-label"] || label,
272
+ "aria-valuemin": context.min,
273
+ "aria-valuenow": value,
274
+ "aria-valuemax": context.max,
275
+ "aria-orientation": context.orientation,
276
+ "data-orientation": context.orientation,
277
+ "data-disabled": context.disabled ? "" : void 0,
278
+ tabIndex: context.disabled ? void 0 : 0,
279
+ ...positionalStyles,
280
+ [orientation.startEdge]: `${percent}%`,
281
+ size: sizeIn,
282
+ circular,
283
+ ...thumbProps,
284
+ onLayout: function(e) {
285
+ setSize(e.nativeEvent.layout[orientation.sizeProp]);
286
+ },
287
+ onFocus: composeEventHandlers(props.onFocus, function() {
288
+ context.valueIndexToChangeRef.current = index;
289
+ })
290
+ });
291
+ }, { staticConfig: { memo: true } });
292
+ var Slider = withStaticProperties(createRefComponent(function(props, forwardedRef) {
293
+ var { name, min = 0, max = 100, step = 1, orientation = "horizontal", disabled = false, minStepsBetweenThumbs = 0, defaultValue = [min], value, onValueChange = function() {}, size: sizeProp, onSlideEnd, onSlideMove, onSlideStart, ...sliderProps } = props;
294
+ var sliderRef = React.useRef(null);
295
+ var composedRefs = useComposedRefs(sliderRef, forwardedRef);
296
+ var thumbRefs = React.useRef(/* @__PURE__ */ new Map());
297
+ var valueIndexToChangeRef = React.useRef(0);
298
+ var isHorizontal = orientation === "horizontal";
299
+ var [values = [], setValues] = useControllableState({
300
+ prop: value,
301
+ defaultProp: defaultValue,
302
+ transition: true,
303
+ onChange: function(value2) {
304
+ updateThumbFocus(valueIndexToChangeRef.current);
305
+ onValueChange(value2);
306
+ }
307
+ });
308
+ if (isWeb) React.useEffect(function() {
309
+ var node = sliderRef.current;
310
+ if (!node) return;
311
+ var preventDefault = function(e) {
312
+ e.preventDefault();
313
+ };
314
+ node.addEventListener("touchstart", preventDefault);
315
+ return function() {
316
+ node.removeEventListener("touchstart", preventDefault);
317
+ };
318
+ }, []);
319
+ function updateThumbFocus(focusIndex) {
320
+ if (!isWeb) return;
321
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
322
+ try {
323
+ for (var _iterator = thumbRefs.current.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
324
+ var [node, index] = _step.value;
325
+ if (index === focusIndex) {
326
+ node.focus();
327
+ return;
328
+ }
329
+ }
330
+ } catch (err) {
331
+ _didIteratorError = true;
332
+ _iteratorError = err;
333
+ } finally {
334
+ try {
335
+ if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
336
+ } finally {
337
+ if (_didIteratorError) throw _iteratorError;
338
+ }
339
+ }
340
+ }
341
+ function handleSlideMove(value2, event) {
342
+ updateValues(value2, valueIndexToChangeRef.current);
343
+ onSlideMove === null || onSlideMove === void 0 || onSlideMove(event, value2);
344
+ }
345
+ function updateValues(value2, atIndex) {
346
+ var decimalCount = getDecimalCount(step);
347
+ var nextValue = clamp(roundValue(Math.round((value2 - min) / step) * step + min, decimalCount), [min, max]);
348
+ setValues(function() {
349
+ var prevValues = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
350
+ var nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
351
+ if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
352
+ valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
353
+ return String(nextValues) === String(prevValues) ? prevValues : nextValues;
354
+ }
355
+ return prevValues;
356
+ });
357
+ }
358
+ var SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
359
+ return /* @__PURE__ */ jsxs(SliderProvider, {
360
+ scope: props.__scopeSlider,
361
+ disabled,
362
+ min,
363
+ max,
364
+ valueIndexToChangeRef,
365
+ thumbs: thumbRefs.current,
366
+ values,
367
+ orientation,
368
+ size: sizeProp,
369
+ children: [/* @__PURE__ */ jsx(SliderOriented, {
370
+ "aria-disabled": disabled,
371
+ "data-disabled": disabled ? "" : void 0,
372
+ ...sliderProps,
373
+ ref: composedRefs,
374
+ min,
375
+ max,
376
+ onSlideEnd,
377
+ onSlideStart: disabled ? void 0 : function(value2, target, event) {
378
+ if (target !== "thumb") updateValues(value2, getClosestValueIndex(values, value2));
379
+ onSlideStart === null || onSlideStart === void 0 || onSlideStart(event, value2, target);
380
+ },
381
+ onSlideMove: disabled ? void 0 : handleSlideMove,
382
+ onHomeKeyDown: function() {
383
+ return !disabled && updateValues(min, 0);
384
+ },
385
+ onEndKeyDown: function() {
386
+ return !disabled && updateValues(max, values.length - 1);
387
+ },
388
+ onStepKeyDown: function(param) {
389
+ var { event, direction: stepDirection } = param;
390
+ if (!disabled) {
391
+ var multiplier = PAGE_KEYS.includes(event.key) || event.shiftKey && ARROW_KEYS.includes(event.key) ? 10 : 1;
392
+ var atIndex = valueIndexToChangeRef.current;
393
+ var value2 = values[atIndex];
394
+ updateValues(value2 + step * multiplier * stepDirection, atIndex);
395
+ }
396
+ }
397
+ }), isWeb && name && values.map(function(value2, index) {
398
+ return /* @__PURE__ */ jsx("input", {
399
+ type: "hidden",
400
+ name,
401
+ value: value2
402
+ }, index);
403
+ })]
404
+ });
480
405
  }), {
481
- Track: SliderTrack,
482
- TrackActive: SliderActive,
483
- Thumb: SliderThumb
406
+ Track: SliderTrack,
407
+ TrackActive: SliderActive,
408
+ Thumb: SliderThumb
484
409
  });
485
410
  Slider.displayName = SLIDER_NAME;
486
411
  var Track = SliderTrack;
487
412
  var Range = SliderActive;
488
413
  var Thumb = SliderThumb;
414
+
489
415
  export { Range, Slider, SliderActive, SliderActiveFrame, SliderThumb, SliderThumbFrame, SliderTrack, SliderTrackFrame, Thumb, Track };
490
416
  //# sourceMappingURL=Slider.native.js.map