@tamagui/slider 1.116.0 → 1.116.2

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