@react-aria/slider 3.8.4 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import {useSlider as $bcca50147b47f54d$export$56b2c08e277f365} from "./useSlider.mjs";
2
- import {useSliderThumb as $47b897dc8cdb026b$export$8d15029008292ae} from "./useSliderThumb.mjs";
1
+ import {useSlider as $a96314beb99c3ea7$re_export$useSlider, useSliderThumb as $a96314beb99c3ea7$re_export$useSliderThumb} from "react-aria/useSlider";
3
2
 
4
3
  /*
5
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -14,6 +13,5 @@ import {useSliderThumb as $47b897dc8cdb026b$export$8d15029008292ae} from "./useS
14
13
  */
15
14
 
16
15
 
17
-
18
- export {$bcca50147b47f54d$export$56b2c08e277f365 as useSlider, $47b897dc8cdb026b$export$8d15029008292ae as useSliderThumb};
16
+ export {$a96314beb99c3ea7$re_export$useSlider as useSlider, $a96314beb99c3ea7$re_export$useSliderThumb as useSliderThumb};
19
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,13 +1,12 @@
1
- var $481f97d830e3ede6$exports = require("./useSlider.main.js");
2
- var $5eb806b626475377$exports = require("./useSliderThumb.main.js");
1
+ var $i4gag$reactariauseSlider = require("react-aria/useSlider");
3
2
 
4
3
 
5
4
  function $parcel$export(e, n, v, s) {
6
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
6
  }
8
7
 
9
- $parcel$export(module.exports, "useSlider", () => $481f97d830e3ede6$exports.useSlider);
10
- $parcel$export(module.exports, "useSliderThumb", () => $5eb806b626475377$exports.useSliderThumb);
8
+ $parcel$export(module.exports, "useSlider", function () { return $i4gag$reactariauseSlider.useSlider; });
9
+ $parcel$export(module.exports, "useSliderThumb", function () { return $i4gag$reactariauseSlider.useSliderThumb; });
11
10
  /*
12
11
  * Copyright 2020 Adobe. All rights reserved.
13
12
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -21,5 +20,4 @@ $parcel$export(module.exports, "useSliderThumb", () => $5eb806b626475377$exports
21
20
  */
22
21
 
23
22
 
24
-
25
23
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/slider/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useSlider} from './useSlider';\nexport {useSliderThumb} from './useSliderThumb';\nexport type {AriaSliderProps} from '@react-types/slider';\nexport type {SliderAria} from './useSlider';\nexport type {AriaSliderThumbOptions, SliderThumbAria} from './useSliderThumb';\nexport type {AriaSliderThumbProps} from '@react-types/slider';\nexport type {Orientation} from '@react-types/shared';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/slider/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useSlider, useSliderThumb} from 'react-aria/useSlider';\n\nexport type {AriaSliderProps, SliderAria, SliderThumbProps, AriaSliderThumbProps, AriaSliderThumbOptions, SliderThumbAria} from 'react-aria/useSlider';\nexport type {Orientation} from '@react-types/shared';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,5 +1,4 @@
1
- import {useSlider as $bcca50147b47f54d$export$56b2c08e277f365} from "./useSlider.module.js";
2
- import {useSliderThumb as $47b897dc8cdb026b$export$8d15029008292ae} from "./useSliderThumb.module.js";
1
+ import {useSlider as $a96314beb99c3ea7$re_export$useSlider, useSliderThumb as $a96314beb99c3ea7$re_export$useSliderThumb} from "react-aria/useSlider";
3
2
 
4
3
  /*
5
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -14,6 +13,5 @@ import {useSliderThumb as $47b897dc8cdb026b$export$8d15029008292ae} from "./useS
14
13
  */
15
14
 
16
15
 
17
-
18
- export {$bcca50147b47f54d$export$56b2c08e277f365 as useSlider, $47b897dc8cdb026b$export$8d15029008292ae as useSliderThumb};
16
+ export {$a96314beb99c3ea7$re_export$useSlider as useSlider, $a96314beb99c3ea7$re_export$useSliderThumb as useSliderThumb};
19
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/slider/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useSlider} from './useSlider';\nexport {useSliderThumb} from './useSliderThumb';\nexport type {AriaSliderProps} from '@react-types/slider';\nexport type {SliderAria} from './useSlider';\nexport type {AriaSliderThumbOptions, SliderThumbAria} from './useSliderThumb';\nexport type {AriaSliderThumbProps} from '@react-types/slider';\nexport type {Orientation} from '@react-types/shared';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/slider/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useSlider, useSliderThumb} from 'react-aria/useSlider';\n\nexport type {AriaSliderProps, SliderAria, SliderThumbProps, AriaSliderThumbProps, AriaSliderThumbOptions, SliderThumbAria} from 'react-aria/useSlider';\nexport type {Orientation} from '@react-types/shared';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,3 @@
1
+ export { useSlider, useSliderThumb } from 'react-aria/useSlider';
2
+ export type { AriaSliderProps, SliderAria, SliderThumbProps, AriaSliderThumbProps, AriaSliderThumbOptions, SliderThumbAria } from 'react-aria/useSlider';
3
+ export type { Orientation } from '@react-types/shared';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-aria/slider",
3
- "version": "3.8.4",
3
+ "version": "3.9.0",
4
4
  "description": "Slider",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,14 +26,9 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/i18n": "^3.12.15",
30
- "@react-aria/interactions": "^3.27.0",
31
- "@react-aria/label": "^3.7.24",
32
- "@react-aria/utils": "^3.33.0",
33
- "@react-stately/slider": "^3.7.4",
34
- "@react-types/shared": "^3.33.0",
35
- "@react-types/slider": "^3.8.3",
36
- "@swc/helpers": "^0.5.0"
29
+ "@react-types/shared": "^3.34.0",
30
+ "@swc/helpers": "^0.5.0",
31
+ "react-aria": "3.48.0"
37
32
  },
38
33
  "peerDependencies": {
39
34
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
@@ -42,5 +37,8 @@
42
37
  "publishConfig": {
43
38
  "access": "public"
44
39
  },
45
- "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
40
+ "targets": {
41
+ "types": false
42
+ },
43
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
46
44
  }
package/src/index.ts CHANGED
@@ -9,10 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- export {useSlider} from './useSlider';
13
- export {useSliderThumb} from './useSliderThumb';
14
- export type {AriaSliderProps} from '@react-types/slider';
15
- export type {SliderAria} from './useSlider';
16
- export type {AriaSliderThumbOptions, SliderThumbAria} from './useSliderThumb';
17
- export type {AriaSliderThumbProps} from '@react-types/slider';
12
+ export {useSlider, useSliderThumb} from 'react-aria/useSlider';
13
+
14
+ export type {AriaSliderProps, SliderAria, SliderThumbProps, AriaSliderThumbProps, AriaSliderThumbOptions, SliderThumbAria} from 'react-aria/useSlider';
18
15
  export type {Orientation} from '@react-types/shared';
package/dist/types.d.ts DELETED
@@ -1,57 +0,0 @@
1
- import { AriaSliderProps, AriaSliderThumbProps } from "@react-types/slider";
2
- import { DOMAttributes, RefObject } from "@react-types/shared";
3
- import { LabelHTMLAttributes, OutputHTMLAttributes, InputHTMLAttributes } from "react";
4
- import { SliderState } from "@react-stately/slider";
5
- export interface SliderAria {
6
- /** Props for the label element. */
7
- labelProps: LabelHTMLAttributes<HTMLLabelElement>;
8
- /** Props for the root element of the slider component; groups slider inputs. */
9
- groupProps: DOMAttributes;
10
- /** Props for the track element. */
11
- trackProps: DOMAttributes;
12
- /** Props for the output element, displaying the value of the slider thumbs. */
13
- outputProps: OutputHTMLAttributes<HTMLOutputElement>;
14
- }
15
- /**
16
- * Provides the behavior and accessibility implementation for a slider component representing one or more values.
17
- *
18
- * @param props Props for the slider.
19
- * @param state State for the slider, as returned by `useSliderState`.
20
- * @param trackRef Ref for the "track" element. The width of this element provides the "length"
21
- * of the track -- the span of one dimensional space that the slider thumb can be. It also
22
- * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
23
- * the track.
24
- */
25
- export function useSlider<T extends number | number[]>(props: AriaSliderProps<T>, state: SliderState, trackRef: RefObject<Element | null>): SliderAria;
26
- export interface SliderThumbAria {
27
- /** Props for the root thumb element; handles the dragging motion. */
28
- thumbProps: DOMAttributes;
29
- /** Props for the visually hidden range input element. */
30
- inputProps: InputHTMLAttributes<HTMLInputElement>;
31
- /** Props for the label element for this thumb (optional). */
32
- labelProps: LabelHTMLAttributes<HTMLLabelElement>;
33
- /** Whether this thumb is currently being dragged. */
34
- isDragging: boolean;
35
- /** Whether the thumb is currently focused. */
36
- isFocused: boolean;
37
- /** Whether the thumb is disabled. */
38
- isDisabled: boolean;
39
- }
40
- export interface AriaSliderThumbOptions extends AriaSliderThumbProps {
41
- /** A ref to the track element. */
42
- trackRef: RefObject<Element | null>;
43
- /** A ref to the thumb input element. */
44
- inputRef: RefObject<HTMLInputElement | null>;
45
- }
46
- /**
47
- * Provides behavior and accessibility for a thumb of a slider component.
48
- *
49
- * @param opts Options for this Slider thumb.
50
- * @param state Slider state, created via `useSliderState`.
51
- */
52
- export function useSliderThumb(opts: AriaSliderThumbOptions, state: SliderState): SliderThumbAria;
53
- export type { AriaSliderProps } from '@react-types/slider';
54
- export type { AriaSliderThumbProps } from '@react-types/slider';
55
- export type { Orientation } from '@react-types/shared';
56
-
57
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;ACsBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAElD,gFAAgF;IAChF,UAAU,EAAE,aAAa,CAAC;IAE1B,mCAAmC;IACnC,UAAU,EAAE,aAAa,CAAC;IAE1B,+EAA+E;IAC/E,WAAW,EAAE,qBAAqB,iBAAiB,CAAC,CAAA;CACrD;AAED;;;;;;;;;GASG;AACH,0BAA0B,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EACnD,KAAK,EAAE,gBAAgB,CAAC,CAAC,EACzB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,GAClC,UAAU,CA+KZ;ACvND;IACE,qEAAqE;IACrE,UAAU,EAAE,aAAa,CAAC;IAE1B,yDAAyD;IACzD,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAElD,6DAA6D;IAC7D,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAElD,qDAAqD;IACrD,UAAU,EAAE,OAAO,CAAC;IACpB,8CAA8C;IAC9C,SAAS,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,uCAAwC,SAAQ,oBAAoB;IAClE,kCAAkC;IAClC,QAAQ,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,CAAC;IACpC,wCAAwC;IACxC,QAAQ,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,CAAA;CAC7C;AAED;;;;;GAKG;AACH,+BACE,IAAI,EAAE,sBAAsB,EAC5B,KAAK,EAAE,WAAW,GACjB,eAAe,CAsOjB;ACrQD,YAAY,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAGzD,YAAY,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAC9D,YAAY,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/slider/src/packages/@react-aria/slider/src/utils.ts","packages/@react-aria/slider/src/packages/@react-aria/slider/src/useSlider.ts","packages/@react-aria/slider/src/packages/@react-aria/slider/src/useSliderThumb.ts","packages/@react-aria/slider/src/packages/@react-aria/slider/src/index.ts","packages/@react-aria/slider/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useSlider} from './useSlider';\nexport {useSliderThumb} from './useSliderThumb';\nexport type {AriaSliderProps} from '@react-types/slider';\nexport type {SliderAria} from './useSlider';\nexport type {AriaSliderThumbOptions, SliderThumbAria} from './useSliderThumb';\nexport type {AriaSliderThumbProps} from '@react-types/slider';\nexport type {Orientation} from '@react-types/shared';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,175 +0,0 @@
1
- var $28db8d634be2fa58$exports = require("./utils.main.js");
2
- var $eVqG0$reactariautils = require("@react-aria/utils");
3
- var $eVqG0$react = require("react");
4
- var $eVqG0$reactariainteractions = require("@react-aria/interactions");
5
- var $eVqG0$reactarialabel = require("@react-aria/label");
6
- var $eVqG0$reactariai18n = require("@react-aria/i18n");
7
-
8
-
9
- function $parcel$export(e, n, v, s) {
10
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
11
- }
12
-
13
- $parcel$export(module.exports, "useSlider", () => $481f97d830e3ede6$export$56b2c08e277f365);
14
- /*
15
- * Copyright 2020 Adobe. All rights reserved.
16
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
- * you may not use this file except in compliance with the License. You may obtain a copy
18
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software distributed under
21
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22
- * OF ANY KIND, either express or implied. See the License for the specific language
23
- * governing permissions and limitations under the License.
24
- */
25
-
26
-
27
-
28
-
29
-
30
- function $481f97d830e3ede6$export$56b2c08e277f365(props, state, trackRef) {
31
- let { labelProps: labelProps, fieldProps: fieldProps } = (0, $eVqG0$reactarialabel.useLabel)(props);
32
- let isVertical = props.orientation === 'vertical';
33
- var _labelProps_id;
34
- // Attach id of the label to the state so it can be accessed by useSliderThumb.
35
- (0, $28db8d634be2fa58$exports.sliderData).set(state, {
36
- id: (_labelProps_id = labelProps.id) !== null && _labelProps_id !== void 0 ? _labelProps_id : fieldProps.id,
37
- 'aria-describedby': props['aria-describedby'],
38
- 'aria-details': props['aria-details']
39
- });
40
- let { direction: direction } = (0, $eVqG0$reactariai18n.useLocale)();
41
- let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $eVqG0$reactariautils.useGlobalListeners)();
42
- // When the user clicks or drags the track, we want the motion to set and drag the
43
- // closest thumb. Hence we also need to install useMove() on the track element.
44
- // Here, we keep track of which index is the "closest" to the drag start point.
45
- // It is set onMouseDown/onTouchDown; see trackProps below.
46
- const realTimeTrackDraggingIndex = (0, $eVqG0$react.useRef)(null);
47
- const reverseX = direction === 'rtl';
48
- const currentPosition = (0, $eVqG0$react.useRef)(null);
49
- const { moveProps: moveProps } = (0, $eVqG0$reactariainteractions.useMove)({
50
- onMoveStart () {
51
- currentPosition.current = null;
52
- },
53
- onMove ({ deltaX: deltaX, deltaY: deltaY }) {
54
- if (!trackRef.current) return;
55
- let { height: height, width: width } = trackRef.current.getBoundingClientRect();
56
- let size = isVertical ? height : width;
57
- if (currentPosition.current == null && realTimeTrackDraggingIndex.current != null) currentPosition.current = state.getThumbPercent(realTimeTrackDraggingIndex.current) * size;
58
- let delta = isVertical ? deltaY : deltaX;
59
- if (isVertical || reverseX) delta = -delta;
60
- currentPosition.current += delta;
61
- if (realTimeTrackDraggingIndex.current != null && trackRef.current) {
62
- const percent = (0, $eVqG0$reactariautils.clamp)(currentPosition.current / size, 0, 1);
63
- state.setThumbPercent(realTimeTrackDraggingIndex.current, percent);
64
- }
65
- },
66
- onMoveEnd () {
67
- if (realTimeTrackDraggingIndex.current != null) {
68
- state.setThumbDragging(realTimeTrackDraggingIndex.current, false);
69
- realTimeTrackDraggingIndex.current = null;
70
- }
71
- }
72
- });
73
- let currentPointer = (0, $eVqG0$react.useRef)(undefined);
74
- let onDownTrack = (e, id, clientX, clientY)=>{
75
- // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.
76
- if (trackRef.current && !props.isDisabled && state.values.every((_, i)=>!state.isThumbDragging(i))) {
77
- let { height: height, width: width, top: top, left: left } = trackRef.current.getBoundingClientRect();
78
- let size = isVertical ? height : width;
79
- // Find the closest thumb
80
- const trackPosition = isVertical ? top : left;
81
- const clickPosition = isVertical ? clientY : clientX;
82
- const offset = clickPosition - trackPosition;
83
- let percent = offset / size;
84
- if (direction === 'rtl' || isVertical) percent = 1 - percent;
85
- let value = state.getPercentValue(percent);
86
- // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
87
- let closestThumb;
88
- let split = state.values.findIndex((v)=>value - v < 0);
89
- if (split === 0) closestThumb = split;
90
- else if (split === -1) closestThumb = state.values.length - 1;
91
- else {
92
- let lastLeft = state.values[split - 1];
93
- let firstRight = state.values[split];
94
- // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one
95
- if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) closestThumb = split - 1;
96
- else closestThumb = split;
97
- }
98
- // Confirm that the found closest thumb is editable, not disabled, and move it
99
- if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {
100
- // Don't unfocus anything
101
- e.preventDefault();
102
- realTimeTrackDraggingIndex.current = closestThumb;
103
- state.setFocusedThumb(closestThumb);
104
- currentPointer.current = id;
105
- state.setThumbDragging(realTimeTrackDraggingIndex.current, true);
106
- state.setThumbValue(closestThumb, value);
107
- addGlobalListener(window, 'mouseup', onUpTrack, false);
108
- addGlobalListener(window, 'touchend', onUpTrack, false);
109
- addGlobalListener(window, 'pointerup', onUpTrack, false);
110
- } else realTimeTrackDraggingIndex.current = null;
111
- }
112
- };
113
- let onUpTrack = (e)=>{
114
- var _e_changedTouches;
115
- var _e_pointerId;
116
- let id = (_e_pointerId = e.pointerId) !== null && _e_pointerId !== void 0 ? _e_pointerId : (_e_changedTouches = e.changedTouches) === null || _e_changedTouches === void 0 ? void 0 : _e_changedTouches[0].identifier;
117
- if (id === currentPointer.current) {
118
- if (realTimeTrackDraggingIndex.current != null) {
119
- state.setThumbDragging(realTimeTrackDraggingIndex.current, false);
120
- realTimeTrackDraggingIndex.current = null;
121
- }
122
- removeGlobalListener(window, 'mouseup', onUpTrack, false);
123
- removeGlobalListener(window, 'touchend', onUpTrack, false);
124
- removeGlobalListener(window, 'pointerup', onUpTrack, false);
125
- }
126
- };
127
- if ('htmlFor' in labelProps && labelProps.htmlFor) {
128
- // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS
129
- // causes this to override the `aria-labelledby` on the thumb. This causes the first
130
- // thumb to only be announced as the slider label rather than its individual name as well.
131
- // See https://bugs.webkit.org/show_bug.cgi?id=172464.
132
- delete labelProps.htmlFor;
133
- labelProps.onClick = ()=>{
134
- var // Safari does not focus <input type="range"> elements when clicking on an associated <label>,
135
- // so do it manually. In addition, make sure we show the focus ring.
136
- _document_getElementById;
137
- (_document_getElementById = document.getElementById((0, $28db8d634be2fa58$exports.getSliderThumbId)(state, 0))) === null || _document_getElementById === void 0 ? void 0 : _document_getElementById.focus();
138
- (0, $eVqG0$reactariainteractions.setInteractionModality)('keyboard');
139
- };
140
- }
141
- return {
142
- labelProps: labelProps,
143
- // The root element of the Slider will have role="group" to group together
144
- // all the thumb inputs in the Slider. The label of the Slider will
145
- // be used to label the group.
146
- groupProps: {
147
- role: 'group',
148
- ...fieldProps
149
- },
150
- trackProps: (0, $eVqG0$reactariautils.mergeProps)({
151
- onMouseDown (e) {
152
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
153
- onDownTrack(e, undefined, e.clientX, e.clientY);
154
- },
155
- onPointerDown (e) {
156
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
157
- onDownTrack(e, e.pointerId, e.clientX, e.clientY);
158
- },
159
- onTouchStart (e) {
160
- onDownTrack(e, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
161
- },
162
- style: {
163
- position: 'relative',
164
- touchAction: 'none'
165
- }
166
- }, moveProps),
167
- outputProps: {
168
- htmlFor: state.values.map((_, index)=>(0, $28db8d634be2fa58$exports.getSliderThumbId)(state, index)).join(' '),
169
- 'aria-live': 'off'
170
- }
171
- };
172
- }
173
-
174
-
175
- //# sourceMappingURL=useSlider.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAoCM,SAAS,yCACd,KAAyB,EACzB,KAAkB,EAClB,QAAmC;IAEnC,IAAI,cAAC,UAAU,cAAE,UAAU,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;IAExC,IAAI,aAAa,MAAM,WAAW,KAAK;QAIhC;IAFP,+EAA+E;IAC/E,CAAA,GAAA,oCAAS,EAAE,GAAG,CAAC,OAAO;QACpB,IAAK,CAAA,iBAAA,WAAW,EAAE,cAAb,4BAAA,iBAAiB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,OAAO,EAAE,EAAE,OAAO;YAChD;YACA,eAAc,CAAqB;gBACjC,IAAI,EAAE,WAAW,KAAK,WAAY,CAAA,EAAE,MAAM,KAAK,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,IAAI,EAAE,OAAO,AAAD,GACnF;gBAEF,YAAY,GAAG,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO;YAClD;YACA,cAAa,CAAmB;gBAAI,YAAY,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC,EAAE,CAAC,OAAO;YAAG;YAC9I,OAAO;gBACL,UAAU;gBACV,aAAa;YACf;QACF,GAAG;QACH,aAAa;YACX,SAAS,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,QAAU,CAAA,GAAA,0CAAe,EAAE,OAAO,QAAQ,IAAI,CAAC;YAC7E,aAAa;QACf;IACF;AACF","sources":["packages/@react-aria/slider/src/useSlider.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaSliderProps} from '@react-types/slider';\nimport {clamp, mergeProps, useGlobalListeners} from '@react-aria/utils';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {getSliderThumbId, sliderData} from './utils';\nimport React, {LabelHTMLAttributes, OutputHTMLAttributes, useRef} from 'react';\nimport {setInteractionModality, useMove} from '@react-aria/interactions';\nimport {SliderState} from '@react-stately/slider';\nimport {useLabel} from '@react-aria/label';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface SliderAria {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: DOMAttributes,\n\n /** Props for the track element. */\n trackProps: DOMAttributes,\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: OutputHTMLAttributes<HTMLOutputElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a slider component representing one or more values.\n *\n * @param props Props for the slider.\n * @param state State for the slider, as returned by `useSliderState`.\n * @param trackRef Ref for the \"track\" element. The width of this element provides the \"length\"\n * of the track -- the span of one dimensional space that the slider thumb can be. It also\n * accepts click and drag motions, so that the closest thumb will follow clicks and drags on\n * the track.\n */\nexport function useSlider<T extends number | number[]>(\n props: AriaSliderProps<T>,\n state: SliderState,\n trackRef: RefObject<Element | null>\n): SliderAria {\n let {labelProps, fieldProps} = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n // Attach id of the label to the state so it can be accessed by useSliderThumb.\n sliderData.set(state, {\n id: (labelProps.id ?? fieldProps.id)!,\n 'aria-describedby': props['aria-describedby'],\n 'aria-details': props['aria-details']\n });\n\n let {direction} = useLocale();\n\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n // When the user clicks or drags the track, we want the motion to set and drag the\n // closest thumb. Hence we also need to install useMove() on the track element.\n // Here, we keep track of which index is the \"closest\" to the drag start point.\n // It is set onMouseDown/onTouchDown; see trackProps below.\n const realTimeTrackDraggingIndex = useRef<number | null>(null);\n\n const reverseX = direction === 'rtl';\n const currentPosition = useRef<number | null>(null);\n const {moveProps} = useMove({\n onMoveStart() {\n currentPosition.current = null;\n },\n onMove({deltaX, deltaY}) {\n if (!trackRef.current) {\n return;\n }\n let {height, width} = trackRef.current.getBoundingClientRect();\n let size = isVertical ? height : width;\n\n if (currentPosition.current == null && realTimeTrackDraggingIndex.current != null) {\n currentPosition.current = state.getThumbPercent(realTimeTrackDraggingIndex.current) * size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (isVertical || reverseX) {\n delta = -delta;\n }\n\n currentPosition.current! += delta;\n\n if (realTimeTrackDraggingIndex.current != null && trackRef.current) {\n const percent = clamp(currentPosition.current! / size, 0, 1);\n state.setThumbPercent(realTimeTrackDraggingIndex.current, percent);\n }\n },\n onMoveEnd() {\n if (realTimeTrackDraggingIndex.current != null) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, false);\n realTimeTrackDraggingIndex.current = null;\n }\n }\n });\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let onDownTrack = (e: React.UIEvent, id: number | undefined, clientX: number, clientY: number) => {\n // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.\n if (trackRef.current && !props.isDisabled && state.values.every((_, i) => !state.isThumbDragging(i))) {\n let {height, width, top, left} = trackRef.current.getBoundingClientRect();\n let size = isVertical ? height : width;\n // Find the closest thumb\n const trackPosition = isVertical ? top : left;\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (direction === 'rtl' || isVertical) {\n percent = 1 - percent;\n }\n let value = state.getPercentValue(percent);\n\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex(v => value - v < 0);\n if (split === 0) { // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) { // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n\n realTimeTrackDraggingIndex.current = closestThumb;\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n\n state.setThumbDragging(realTimeTrackDraggingIndex.current!, true);\n state.setThumbValue(closestThumb, value);\n\n addGlobalListener(window, 'mouseup', onUpTrack, false);\n addGlobalListener(window, 'touchend', onUpTrack, false);\n addGlobalListener(window, 'pointerup', onUpTrack, false);\n } else {\n realTimeTrackDraggingIndex.current = null;\n }\n }\n };\n\n let onUpTrack = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n if (realTimeTrackDraggingIndex.current != null) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, false);\n realTimeTrackDraggingIndex.current = null;\n }\n\n removeGlobalListener(window, 'mouseup', onUpTrack, false);\n removeGlobalListener(window, 'touchend', onUpTrack, false);\n removeGlobalListener(window, 'pointerup', onUpTrack, false);\n }\n };\n\n if ('htmlFor' in labelProps && labelProps.htmlFor) {\n // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS\n // causes this to override the `aria-labelledby` on the thumb. This causes the first\n // thumb to only be announced as the slider label rather than its individual name as well.\n // See https://bugs.webkit.org/show_bug.cgi?id=172464.\n delete labelProps.htmlFor;\n labelProps.onClick = () => {\n // Safari does not focus <input type=\"range\"> elements when clicking on an associated <label>,\n // so do it manually. In addition, make sure we show the focus ring.\n document.getElementById(getSliderThumbId(state, 0))?.focus();\n setInteractionModality('keyboard');\n };\n }\n\n return {\n labelProps,\n // The root element of the Slider will have role=\"group\" to group together\n // all the thumb inputs in the Slider. The label of the Slider will\n // be used to label the group.\n groupProps: {\n role: 'group',\n ...fieldProps\n },\n trackProps: mergeProps({\n onMouseDown(e: React.MouseEvent) {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDownTrack(e, undefined, e.clientX, e.clientY);\n },\n onPointerDown(e: React.PointerEvent) {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onDownTrack(e, e.pointerId, e.clientX, e.clientY);\n },\n onTouchStart(e: React.TouchEvent) { onDownTrack(e, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY); },\n style: {\n position: 'relative',\n touchAction: 'none'\n }\n }, moveProps),\n outputProps: {\n htmlFor: state.values.map((_, index) => getSliderThumbId(state, index)).join(' '),\n 'aria-live': 'off'\n }\n };\n}\n"],"names":[],"version":3,"file":"useSlider.main.js.map"}
@@ -1,170 +0,0 @@
1
- import {getSliderThumbId as $aa519ee6cf463259$export$68e648cbec363a18, sliderData as $aa519ee6cf463259$export$d6c8d9636a3dc49c} from "./utils.mjs";
2
- import {useGlobalListeners as $468t2$useGlobalListeners, clamp as $468t2$clamp, mergeProps as $468t2$mergeProps} from "@react-aria/utils";
3
- import {useRef as $468t2$useRef} from "react";
4
- import {useMove as $468t2$useMove, setInteractionModality as $468t2$setInteractionModality} from "@react-aria/interactions";
5
- import {useLabel as $468t2$useLabel} from "@react-aria/label";
6
- import {useLocale as $468t2$useLocale} from "@react-aria/i18n";
7
-
8
- /*
9
- * Copyright 2020 Adobe. All rights reserved.
10
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License. You may obtain a copy
12
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software distributed under
15
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
- * OF ANY KIND, either express or implied. See the License for the specific language
17
- * governing permissions and limitations under the License.
18
- */
19
-
20
-
21
-
22
-
23
-
24
- function $bcca50147b47f54d$export$56b2c08e277f365(props, state, trackRef) {
25
- let { labelProps: labelProps, fieldProps: fieldProps } = (0, $468t2$useLabel)(props);
26
- let isVertical = props.orientation === 'vertical';
27
- var _labelProps_id;
28
- // Attach id of the label to the state so it can be accessed by useSliderThumb.
29
- (0, $aa519ee6cf463259$export$d6c8d9636a3dc49c).set(state, {
30
- id: (_labelProps_id = labelProps.id) !== null && _labelProps_id !== void 0 ? _labelProps_id : fieldProps.id,
31
- 'aria-describedby': props['aria-describedby'],
32
- 'aria-details': props['aria-details']
33
- });
34
- let { direction: direction } = (0, $468t2$useLocale)();
35
- let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $468t2$useGlobalListeners)();
36
- // When the user clicks or drags the track, we want the motion to set and drag the
37
- // closest thumb. Hence we also need to install useMove() on the track element.
38
- // Here, we keep track of which index is the "closest" to the drag start point.
39
- // It is set onMouseDown/onTouchDown; see trackProps below.
40
- const realTimeTrackDraggingIndex = (0, $468t2$useRef)(null);
41
- const reverseX = direction === 'rtl';
42
- const currentPosition = (0, $468t2$useRef)(null);
43
- const { moveProps: moveProps } = (0, $468t2$useMove)({
44
- onMoveStart () {
45
- currentPosition.current = null;
46
- },
47
- onMove ({ deltaX: deltaX, deltaY: deltaY }) {
48
- if (!trackRef.current) return;
49
- let { height: height, width: width } = trackRef.current.getBoundingClientRect();
50
- let size = isVertical ? height : width;
51
- if (currentPosition.current == null && realTimeTrackDraggingIndex.current != null) currentPosition.current = state.getThumbPercent(realTimeTrackDraggingIndex.current) * size;
52
- let delta = isVertical ? deltaY : deltaX;
53
- if (isVertical || reverseX) delta = -delta;
54
- currentPosition.current += delta;
55
- if (realTimeTrackDraggingIndex.current != null && trackRef.current) {
56
- const percent = (0, $468t2$clamp)(currentPosition.current / size, 0, 1);
57
- state.setThumbPercent(realTimeTrackDraggingIndex.current, percent);
58
- }
59
- },
60
- onMoveEnd () {
61
- if (realTimeTrackDraggingIndex.current != null) {
62
- state.setThumbDragging(realTimeTrackDraggingIndex.current, false);
63
- realTimeTrackDraggingIndex.current = null;
64
- }
65
- }
66
- });
67
- let currentPointer = (0, $468t2$useRef)(undefined);
68
- let onDownTrack = (e, id, clientX, clientY)=>{
69
- // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.
70
- if (trackRef.current && !props.isDisabled && state.values.every((_, i)=>!state.isThumbDragging(i))) {
71
- let { height: height, width: width, top: top, left: left } = trackRef.current.getBoundingClientRect();
72
- let size = isVertical ? height : width;
73
- // Find the closest thumb
74
- const trackPosition = isVertical ? top : left;
75
- const clickPosition = isVertical ? clientY : clientX;
76
- const offset = clickPosition - trackPosition;
77
- let percent = offset / size;
78
- if (direction === 'rtl' || isVertical) percent = 1 - percent;
79
- let value = state.getPercentValue(percent);
80
- // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
81
- let closestThumb;
82
- let split = state.values.findIndex((v)=>value - v < 0);
83
- if (split === 0) closestThumb = split;
84
- else if (split === -1) closestThumb = state.values.length - 1;
85
- else {
86
- let lastLeft = state.values[split - 1];
87
- let firstRight = state.values[split];
88
- // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one
89
- if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) closestThumb = split - 1;
90
- else closestThumb = split;
91
- }
92
- // Confirm that the found closest thumb is editable, not disabled, and move it
93
- if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {
94
- // Don't unfocus anything
95
- e.preventDefault();
96
- realTimeTrackDraggingIndex.current = closestThumb;
97
- state.setFocusedThumb(closestThumb);
98
- currentPointer.current = id;
99
- state.setThumbDragging(realTimeTrackDraggingIndex.current, true);
100
- state.setThumbValue(closestThumb, value);
101
- addGlobalListener(window, 'mouseup', onUpTrack, false);
102
- addGlobalListener(window, 'touchend', onUpTrack, false);
103
- addGlobalListener(window, 'pointerup', onUpTrack, false);
104
- } else realTimeTrackDraggingIndex.current = null;
105
- }
106
- };
107
- let onUpTrack = (e)=>{
108
- var _e_changedTouches;
109
- var _e_pointerId;
110
- let id = (_e_pointerId = e.pointerId) !== null && _e_pointerId !== void 0 ? _e_pointerId : (_e_changedTouches = e.changedTouches) === null || _e_changedTouches === void 0 ? void 0 : _e_changedTouches[0].identifier;
111
- if (id === currentPointer.current) {
112
- if (realTimeTrackDraggingIndex.current != null) {
113
- state.setThumbDragging(realTimeTrackDraggingIndex.current, false);
114
- realTimeTrackDraggingIndex.current = null;
115
- }
116
- removeGlobalListener(window, 'mouseup', onUpTrack, false);
117
- removeGlobalListener(window, 'touchend', onUpTrack, false);
118
- removeGlobalListener(window, 'pointerup', onUpTrack, false);
119
- }
120
- };
121
- if ('htmlFor' in labelProps && labelProps.htmlFor) {
122
- // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS
123
- // causes this to override the `aria-labelledby` on the thumb. This causes the first
124
- // thumb to only be announced as the slider label rather than its individual name as well.
125
- // See https://bugs.webkit.org/show_bug.cgi?id=172464.
126
- delete labelProps.htmlFor;
127
- labelProps.onClick = ()=>{
128
- var // Safari does not focus <input type="range"> elements when clicking on an associated <label>,
129
- // so do it manually. In addition, make sure we show the focus ring.
130
- _document_getElementById;
131
- (_document_getElementById = document.getElementById((0, $aa519ee6cf463259$export$68e648cbec363a18)(state, 0))) === null || _document_getElementById === void 0 ? void 0 : _document_getElementById.focus();
132
- (0, $468t2$setInteractionModality)('keyboard');
133
- };
134
- }
135
- return {
136
- labelProps: labelProps,
137
- // The root element of the Slider will have role="group" to group together
138
- // all the thumb inputs in the Slider. The label of the Slider will
139
- // be used to label the group.
140
- groupProps: {
141
- role: 'group',
142
- ...fieldProps
143
- },
144
- trackProps: (0, $468t2$mergeProps)({
145
- onMouseDown (e) {
146
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
147
- onDownTrack(e, undefined, e.clientX, e.clientY);
148
- },
149
- onPointerDown (e) {
150
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
151
- onDownTrack(e, e.pointerId, e.clientX, e.clientY);
152
- },
153
- onTouchStart (e) {
154
- onDownTrack(e, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
155
- },
156
- style: {
157
- position: 'relative',
158
- touchAction: 'none'
159
- }
160
- }, moveProps),
161
- outputProps: {
162
- htmlFor: state.values.map((_, index)=>(0, $aa519ee6cf463259$export$68e648cbec363a18)(state, index)).join(' '),
163
- 'aria-live': 'off'
164
- }
165
- };
166
- }
167
-
168
-
169
- export {$bcca50147b47f54d$export$56b2c08e277f365 as useSlider};
170
- //# sourceMappingURL=useSlider.module.js.map