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