@tamagui/slider 2.0.0-rc.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/cjs/Slider.cjs +450 -429
  2. package/dist/cjs/Slider.native.js +452 -458
  3. package/dist/cjs/Slider.native.js.map +1 -1
  4. package/dist/cjs/SliderImpl.cjs +127 -100
  5. package/dist/cjs/SliderImpl.native.js +147 -117
  6. package/dist/cjs/SliderImpl.native.js.map +1 -1
  7. package/dist/cjs/constants.cjs +39 -37
  8. package/dist/cjs/constants.native.js +40 -38
  9. package/dist/cjs/constants.native.js.map +1 -1
  10. package/dist/cjs/helpers.cjs +32 -20
  11. package/dist/cjs/helpers.native.js +34 -26
  12. package/dist/cjs/helpers.native.js.map +1 -1
  13. package/dist/cjs/index.cjs +15 -13
  14. package/dist/cjs/index.native.js +15 -13
  15. package/dist/cjs/index.native.js.map +1 -1
  16. package/dist/cjs/types.cjs +7 -5
  17. package/dist/cjs/types.native.js +7 -5
  18. package/dist/cjs/types.native.js.map +1 -1
  19. package/dist/esm/Slider.mjs +407 -395
  20. package/dist/esm/Slider.mjs.map +1 -1
  21. package/dist/esm/Slider.native.js +408 -423
  22. package/dist/esm/Slider.native.js.map +1 -1
  23. package/dist/esm/SliderImpl.mjs +95 -70
  24. package/dist/esm/SliderImpl.mjs.map +1 -1
  25. package/dist/esm/SliderImpl.native.js +115 -87
  26. package/dist/esm/SliderImpl.native.js.map +1 -1
  27. package/dist/esm/constants.mjs +27 -27
  28. package/dist/esm/constants.mjs.map +1 -1
  29. package/dist/esm/constants.native.js +27 -27
  30. package/dist/esm/constants.native.js.map +1 -1
  31. package/dist/esm/helpers.mjs +20 -10
  32. package/dist/esm/helpers.mjs.map +1 -1
  33. package/dist/esm/helpers.native.js +22 -16
  34. package/dist/esm/helpers.native.js.map +1 -1
  35. package/dist/esm/index.js +4 -7
  36. package/dist/esm/index.js.map +1 -6
  37. package/dist/jsx/Slider.mjs +407 -395
  38. package/dist/jsx/Slider.mjs.map +1 -1
  39. package/dist/jsx/Slider.native.js +452 -458
  40. package/dist/jsx/Slider.native.js.map +1 -1
  41. package/dist/jsx/SliderImpl.mjs +95 -70
  42. package/dist/jsx/SliderImpl.mjs.map +1 -1
  43. package/dist/jsx/SliderImpl.native.js +147 -117
  44. package/dist/jsx/SliderImpl.native.js.map +1 -1
  45. package/dist/jsx/constants.mjs +27 -27
  46. package/dist/jsx/constants.mjs.map +1 -1
  47. package/dist/jsx/constants.native.js +40 -38
  48. package/dist/jsx/constants.native.js.map +1 -1
  49. package/dist/jsx/helpers.mjs +20 -10
  50. package/dist/jsx/helpers.mjs.map +1 -1
  51. package/dist/jsx/helpers.native.js +34 -26
  52. package/dist/jsx/helpers.native.js.map +1 -1
  53. package/dist/jsx/index.js +4 -7
  54. package/dist/jsx/index.js.map +1 -6
  55. package/dist/jsx/index.native.js +15 -13
  56. package/dist/jsx/types.native.js +7 -5
  57. package/package.json +17 -21
  58. package/dist/cjs/Slider.js +0 -486
  59. package/dist/cjs/Slider.js.map +0 -6
  60. package/dist/cjs/SliderImpl.js +0 -115
  61. package/dist/cjs/SliderImpl.js.map +0 -6
  62. package/dist/cjs/constants.js +0 -47
  63. package/dist/cjs/constants.js.map +0 -6
  64. package/dist/cjs/helpers.js +0 -74
  65. package/dist/cjs/helpers.js.map +0 -6
  66. package/dist/cjs/index.js +0 -23
  67. package/dist/cjs/index.js.map +0 -6
  68. package/dist/cjs/types.js +0 -14
  69. package/dist/cjs/types.js.map +0 -6
  70. package/dist/esm/Slider.js +0 -499
  71. package/dist/esm/Slider.js.map +0 -6
  72. package/dist/esm/SliderImpl.js +0 -98
  73. package/dist/esm/SliderImpl.js.map +0 -6
  74. package/dist/esm/constants.js +0 -31
  75. package/dist/esm/constants.js.map +0 -6
  76. package/dist/esm/helpers.js +0 -58
  77. package/dist/esm/helpers.js.map +0 -6
  78. package/dist/esm/types.js +0 -1
  79. package/dist/esm/types.js.map +0 -6
  80. package/dist/jsx/Slider.js +0 -499
  81. package/dist/jsx/Slider.js.map +0 -6
  82. package/dist/jsx/SliderImpl.js +0 -98
  83. package/dist/jsx/SliderImpl.js.map +0 -6
  84. package/dist/jsx/constants.js +0 -31
  85. package/dist/jsx/constants.js.map +0 -6
  86. package/dist/jsx/helpers.js +0 -58
  87. package/dist/jsx/helpers.js.map +0 -6
  88. package/dist/jsx/types.js +0 -1
  89. package/dist/jsx/types.js.map +0 -6
@@ -1,47 +0,0 @@
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
- SliderContext: () => SliderContext,
22
- SliderOrientationProvider: () => SliderOrientationProvider,
23
- SliderProvider: () => SliderProvider,
24
- useSliderContext: () => useSliderContext,
25
- useSliderOrientationContext: () => useSliderOrientationContext
26
- });
27
- module.exports = __toCommonJS(constants_exports);
28
- var import_core = require("@tamagui/core");
29
- const SLIDER_NAME = "Slider", SliderContext = (0, import_core.createStyledContext)({
30
- size: "$true",
31
- min: 0,
32
- max: 100,
33
- orientation: "horizontal"
34
- }), { Provider: SliderProvider, useStyledContext: useSliderContext } = SliderContext, {
35
- Provider: SliderOrientationProvider,
36
- useStyledContext: useSliderOrientationContext
37
- } = (0, import_core.createStyledContext)({
38
- startEdge: "left",
39
- endEdge: "right",
40
- sizeProp: "width",
41
- size: 0,
42
- direction: 1
43
- }), PAGE_KEYS = ["PageUp", "PageDown"], ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], BACK_KEYS = {
44
- ltr: ["ArrowDown", "Home", "ArrowLeft", "PageDown"],
45
- rtl: ["ArrowDown", "Home", "ArrowRight", "PageDown"]
46
- };
47
- //# sourceMappingURL=constants.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/constants.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD;AAI9C,MAAM,cAAc,UAEd,oBAAgB,iCAAwC;AAAA,EACnE,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,aAAa;AACf,CAAuB,GAEV,EAAE,UAAU,gBAAgB,kBAAkB,iBAAiB,IAC1E,eAEW;AAAA,EACX,UAAU;AAAA,EACV,kBAAkB;AACpB,QAAI,iCAMD;AAAA,EACD,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,WAAW;AACb,CAAC,GAEY,YAAY,CAAC,UAAU,UAAU,GACjC,aAAa,CAAC,WAAW,aAAa,aAAa,YAAY,GAC/D,YAAyC;AAAA,EACpD,KAAK,CAAC,aAAa,QAAQ,aAAa,UAAU;AAAA,EAClD,KAAK,CAAC,aAAa,QAAQ,cAAc,UAAU;AACrD;",
5
- "names": []
6
- }
@@ -1,74 +0,0 @@
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;
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
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/helpers.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,oBACd,aAAuB,CAAC,GACxB,WACA,SACA;AACA,QAAM,aAAa,CAAC,GAAG,UAAU;AACjC,oBAAW,OAAO,IAAI,WACf,WAAW,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AACxC;AAEO,SAAS,yBAAyB,OAAe,KAAa,KAAa;AAGhF,SADuB,OADN,MAAM,QAEE,QAAQ;AACnC;AAKO,SAAS,SAAS,OAAe,aAAqB;AAC3D,MAAI,cAAc;AAChB,WAAO,SAAS,QAAQ,CAAC,OAAO,WAAW;AAE7C,MAAI,gBAAgB;AAClB,WAAO,CAAC,WAAW,SAAS,EAAE,KAAK;AAGvC;AAUO,SAAS,qBAAqB,QAAkB,WAAmB;AACxE,MAAI,OAAO,WAAW,EAAG,QAAO;AAChC,QAAM,YAAY,OAAO,IAAI,CAAC,UAAU,KAAK,IAAI,QAAQ,SAAS,CAAC,GAC7D,kBAAkB,KAAK,IAAI,GAAG,SAAS;AAC7C,SAAO,UAAU,QAAQ,eAAe;AAC1C;AAMO,SAAS,uBAAuB,OAAe,MAAc,WAAmB;AACrF,QAAM,eAAe,QAAQ,GAEvB,SAAS,YAAY,CAAC,GADR,EACsB,GAAG,CAAC,GAAG,YAAY,CAAC;AAC9D,UAAQ,eAAe,OAAO,IAAI,KAAK;AACzC;AASA,SAAS,sBAAsB,QAAkB;AAC/C,SAAO,OAAO,MAAM,GAAG,EAAE,EAAE,IAAI,CAAC,OAAO,UAAU,OAAO,QAAQ,CAAC,IAAI,KAAK;AAC5E;AAcO,SAAS,yBACd,QACA,uBACA;AACA,MAAI,wBAAwB,GAAG;AAC7B,UAAM,qBAAqB,sBAAsB,MAAM;AAEvD,WADoC,KAAK,IAAI,GAAG,kBAAkB,KAC5B;AAAA,EACxC;AACA,SAAO;AACT;AAGO,SAAS,YACd,OACA,QACA;AACA,SAAO,CAAC,UAAkB;AACxB,QAAI,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,OAAO,CAAC,EAAG,QAAO,OAAO,CAAC;AACrE,UAAM,SAAS,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,MAAM,CAAC,IAAI,MAAM,CAAC;AAC3D,WAAO,OAAO,CAAC,IAAI,SAAS,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;AAEO,SAAS,gBAAgB,OAAe;AAC7C,UAAQ,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI;AAC7C;AAEO,SAAS,WAAW,OAAe,cAAsB;AAC9D,QAAM,UAAU,MAAM;AACtB,SAAO,KAAK,MAAM,QAAQ,OAAO,IAAI;AACvC;",
5
- "names": []
6
- }
package/dist/cjs/index.js DELETED
@@ -1,23 +0,0 @@
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 index_exports = {};
16
- __export(index_exports, {
17
- SliderContext: () => import_constants.SliderContext,
18
- SliderFrame: () => import_SliderImpl.SliderFrame
19
- });
20
- module.exports = __toCommonJS(index_exports);
21
- __reExport(index_exports, require("./Slider"), module.exports);
22
- var import_constants = require("./constants"), import_SliderImpl = require("./SliderImpl");
23
- //# sourceMappingURL=index.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,qBAAd;AACA,uBAA8B,wBAE9B,oBAA4B;",
5
- "names": []
6
- }
package/dist/cjs/types.js DELETED
@@ -1,14 +0,0 @@
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
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/types.ts"],
4
- "mappings": ";;;;;;;;;;;AAAA;AAAA;",
5
- "names": []
6
- }
@@ -1,499 +0,0 @@
1
- import { composeRefs, useComposedRefs } from "@tamagui/compose-refs";
2
- import { isIos, isWeb } from "@tamagui/constants";
3
- import {
4
- getTokens,
5
- getVariableValue,
6
- styled,
7
- useConfiguration,
8
- useCreateShallowSetState
9
- } from "@tamagui/core";
10
- import { getSize } from "@tamagui/get-token";
11
- import { clamp, composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
12
- import { ThemeableStack } from "@tamagui/stacks";
13
- import { useControllableState } from "@tamagui/use-controllable-state";
14
- import { useDirection } from "@tamagui/use-direction";
15
- import * as React from "react";
16
- import {
17
- ARROW_KEYS,
18
- BACK_KEYS,
19
- PAGE_KEYS,
20
- SLIDER_NAME,
21
- SliderOrientationProvider,
22
- SliderProvider,
23
- useSliderContext,
24
- useSliderOrientationContext
25
- } from "./constants";
26
- import {
27
- convertValueToPercentage,
28
- getClosestValueIndex,
29
- getDecimalCount,
30
- getLabel,
31
- getNextSortedValues,
32
- getThumbInBoundsOffset,
33
- hasMinStepsBetweenValues,
34
- linearScale,
35
- roundValue
36
- } from "./helpers";
37
- import { SliderFrame, SliderImpl } from "./SliderImpl";
38
- import { jsx } from "react/jsx-runtime";
39
- const activeSliderMeasureListeners = /* @__PURE__ */ new Set();
40
- process.env.TAMAGUI_DISABLE_SLIDER_INTERVAL || setInterval?.(
41
- () => {
42
- activeSliderMeasureListeners.forEach((cb) => cb());
43
- },
44
- // really doesn't need to be super often
45
- 1e3
46
- );
47
- const SliderHorizontal = React.forwardRef(
48
- (props, forwardedRef) => {
49
- const {
50
- min,
51
- max,
52
- dir,
53
- onSlideStart,
54
- onSlideMove,
55
- onStepKeyDown,
56
- onSlideEnd,
57
- ...sliderProps
58
- } = props, direction = useDirection(dir), isDirectionLTR = direction === "ltr", sliderRef = React.useRef(null), [state, setState_] = React.useState(() => ({ size: 0, offset: 0 })), setState = useCreateShallowSetState(setState_);
59
- function getValueFromPointer(pointerPosition) {
60
- const input = [0, state.size];
61
- return linearScale(input, isDirectionLTR ? [min, max] : [max, min])(pointerPosition);
62
- }
63
- const measure = () => {
64
- sliderRef.current?.measure((_x, _y, width, _height, pageX, _pageY) => {
65
- setState({
66
- size: width,
67
- offset: pageX
68
- });
69
- });
70
- };
71
- return useSliderMeasure(sliderRef, measure), /* @__PURE__ */ jsx(
72
- SliderOrientationProvider,
73
- {
74
- scope: props.__scopeSlider,
75
- startEdge: isDirectionLTR ? "left" : "right",
76
- endEdge: isDirectionLTR ? "right" : "left",
77
- direction: isDirectionLTR ? 1 : -1,
78
- sizeProp: "width",
79
- size: state.size,
80
- children: /* @__PURE__ */ jsx(
81
- SliderImpl,
82
- {
83
- ref: composeRefs(forwardedRef, sliderRef),
84
- dir: direction,
85
- ...sliderProps,
86
- orientation: "horizontal",
87
- onLayout: measure,
88
- onSlideStart: (event, target) => {
89
- const value = getValueFromPointer(event.nativeEvent.locationX);
90
- value && onSlideStart?.(value, target, event);
91
- },
92
- onSlideMove: (event) => {
93
- const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
94
- value && onSlideMove?.(value, event);
95
- },
96
- onSlideEnd: (event) => {
97
- const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
98
- value && onSlideEnd?.(event, value);
99
- },
100
- onStepKeyDown: (event) => {
101
- const isBackKey = BACK_KEYS[direction].includes(event.key);
102
- onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 });
103
- }
104
- }
105
- )
106
- }
107
- );
108
- }
109
- );
110
- function useOnDebouncedWindowResize(callback, amt = 200) {
111
- React.useEffect(() => {
112
- let last;
113
- const onResize = () => {
114
- clearTimeout(last), last = setTimeout(callback, amt);
115
- };
116
- return window.addEventListener("resize", onResize), () => {
117
- clearTimeout(last), window.removeEventListener("resize", onResize);
118
- };
119
- }, []);
120
- }
121
- function useSliderMeasure(sliderRef, measure) {
122
- useOnDebouncedWindowResize(measure), React.useEffect(() => {
123
- const node = sliderRef.current;
124
- if (!node) return;
125
- let measureTm;
126
- const debouncedMeasure = () => {
127
- clearTimeout(measureTm), measureTm = setTimeout(() => {
128
- measure();
129
- }, 200);
130
- }, io = new IntersectionObserver(
131
- (entries) => {
132
- debouncedMeasure(), entries?.[0].isIntersecting ? activeSliderMeasureListeners.add(debouncedMeasure) : activeSliderMeasureListeners.delete(debouncedMeasure);
133
- },
134
- {
135
- root: null,
136
- rootMargin: "0px",
137
- threshold: [0, 0.5, 1]
138
- }
139
- );
140
- return io.observe(node), () => {
141
- activeSliderMeasureListeners.delete(debouncedMeasure), io.disconnect();
142
- };
143
- }, []);
144
- }
145
- const SliderVertical = React.forwardRef(
146
- (props, forwardedRef) => {
147
- const {
148
- min,
149
- max,
150
- onSlideStart,
151
- onSlideMove,
152
- onStepKeyDown,
153
- onSlideEnd,
154
- ...sliderProps
155
- } = props, [state, setState_] = React.useState(() => ({ size: 0, offset: 0 })), setState = useCreateShallowSetState(setState_), sliderRef = React.useRef(null), configuration = useConfiguration(), insets = isIos && configuration.insets ? configuration.insets : { top: 0, bottom: 0 };
156
- function getValueFromPointer(pointerPosition) {
157
- const input = [0, state.size];
158
- return linearScale(input, [max, min])(pointerPosition);
159
- }
160
- const measure = () => {
161
- sliderRef.current?.measure((_x, _y, _width, height, _pageX, pageY) => {
162
- setState({
163
- size: height,
164
- offset: pageY + (isIos ? insets.top : 0)
165
- });
166
- });
167
- };
168
- return useSliderMeasure(sliderRef, measure), /* @__PURE__ */ jsx(
169
- SliderOrientationProvider,
170
- {
171
- scope: props.__scopeSlider,
172
- startEdge: "bottom",
173
- endEdge: "top",
174
- sizeProp: "height",
175
- size: state.size,
176
- direction: 1,
177
- children: /* @__PURE__ */ jsx(
178
- SliderImpl,
179
- {
180
- ref: composeRefs(forwardedRef, sliderRef),
181
- ...sliderProps,
182
- orientation: "vertical",
183
- onLayout: measure,
184
- onSlideStart: (event, target) => {
185
- const value = getValueFromPointer(event.nativeEvent.locationY);
186
- value && onSlideStart?.(value, target, event);
187
- },
188
- onSlideMove: (event) => {
189
- const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
190
- value && onSlideMove?.(value, event);
191
- },
192
- onSlideEnd: (event) => {
193
- const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
194
- onSlideEnd?.(event, value);
195
- },
196
- onStepKeyDown: (event) => {
197
- const isBackKey = BACK_KEYS.ltr.includes(event.key);
198
- onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 });
199
- }
200
- }
201
- )
202
- }
203
- );
204
- }
205
- ), SliderTrackFrame = styled(SliderFrame, {
206
- name: "Slider",
207
- variants: {
208
- unstyled: {
209
- false: {
210
- height: "100%",
211
- width: "100%",
212
- backgroundColor: "$background",
213
- position: "relative",
214
- borderRadius: 1e5,
215
- overflow: "hidden"
216
- }
217
- }
218
- },
219
- defaultVariants: {
220
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
221
- }
222
- }), SliderTrack = React.forwardRef(
223
- function(props, forwardedRef) {
224
- const { __scopeSlider, ...trackProps } = props, context = useSliderContext(__scopeSlider);
225
- return /* @__PURE__ */ jsx(
226
- SliderTrackFrame,
227
- {
228
- "data-disabled": context.disabled ? "" : void 0,
229
- "data-orientation": context.orientation,
230
- orientation: context.orientation,
231
- size: context.size,
232
- ...trackProps,
233
- ref: forwardedRef
234
- }
235
- );
236
- }
237
- ), SliderActiveFrame = styled(SliderFrame, {
238
- name: "SliderActive",
239
- position: "absolute",
240
- pointerEvents: "box-none",
241
- variants: {
242
- unstyled: {
243
- false: {
244
- backgroundColor: "$background",
245
- borderRadius: 1e5
246
- }
247
- }
248
- },
249
- defaultVariants: {
250
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
251
- }
252
- }), SliderActive = React.forwardRef(function(props, forwardedRef) {
253
- const { __scopeSlider, ...rangeProps } = props, context = useSliderContext(__scopeSlider), orientation = useSliderOrientationContext(__scopeSlider), ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, ref), valuesCount = context.values.length, percentages = context.values.map(
254
- (value) => convertValueToPercentage(value, context.min, context.max)
255
- ), offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0, offsetEnd = 100 - Math.max(...percentages);
256
- return /* @__PURE__ */ jsx(
257
- SliderActiveFrame,
258
- {
259
- orientation: context.orientation,
260
- "data-orientation": context.orientation,
261
- "data-disabled": context.disabled ? "" : void 0,
262
- size: context.size,
263
- animateOnly: ["left", "top", "right", "bottom"],
264
- ...rangeProps,
265
- ref: composedRefs,
266
- [orientation.startEdge]: `${offsetStart}%`,
267
- [orientation.endEdge]: `${offsetEnd}%`,
268
- ...orientation.sizeProp === "width" ? {
269
- height: "100%"
270
- } : {
271
- left: 0,
272
- right: 0
273
- }
274
- }
275
- );
276
- }), getThumbSize = (val) => {
277
- const tokens = getTokens(), size = typeof val == "number" ? val : getSize(tokens.size[val], {
278
- shift: -1
279
- });
280
- return {
281
- width: size,
282
- height: size,
283
- minWidth: size,
284
- minHeight: size
285
- };
286
- }, SliderThumbFrame = styled(ThemeableStack, {
287
- name: "SliderThumb",
288
- variants: {
289
- size: {
290
- "...size": getThumbSize,
291
- ":number": getThumbSize
292
- },
293
- unstyled: {
294
- false: {
295
- position: "absolute",
296
- borderWidth: 2,
297
- borderColor: "$borderColor",
298
- backgroundColor: "$background",
299
- pressStyle: {
300
- backgroundColor: "$backgroundPress",
301
- borderColor: "$borderColorPress"
302
- },
303
- hoverStyle: {
304
- backgroundColor: "$backgroundHover",
305
- borderColor: "$borderColorHover"
306
- },
307
- focusVisibleStyle: {
308
- outlineStyle: "solid",
309
- outlineWidth: 2,
310
- outlineColor: "$outlineColor"
311
- }
312
- }
313
- }
314
- },
315
- defaultVariants: {
316
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
317
- }
318
- }), SliderThumb = SliderThumbFrame.styleable(
319
- function(props, forwardedRef) {
320
- const { __scopeSlider, index = 0, circular, size: sizeProp, ...thumbProps } = props, context = useSliderContext(__scopeSlider), orientation = useSliderOrientationContext(__scopeSlider), [thumb, setThumb] = React.useState(null), composedRefs = useComposedRefs(forwardedRef, setThumb), value = context.values[index], percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max), label = getLabel(index, context.values.length), sizeIn = sizeProp ?? context.size ?? "$true", [size, setSize] = React.useState(() => getVariableValue(getThumbSize(sizeIn).width)), thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
321
- React.useEffect(() => {
322
- if (thumb)
323
- return context.thumbs.set(thumb, index), () => {
324
- context.thumbs.delete(thumb);
325
- };
326
- }, [thumb, context.thumbs, index]);
327
- const positionalStyles = context.orientation === "horizontal" ? {
328
- x: (thumbInBoundsOffset - size / 2) * orientation.direction,
329
- y: -size / 2,
330
- top: "50%",
331
- ...size === 0 && {
332
- top: "auto",
333
- bottom: "auto"
334
- }
335
- } : {
336
- x: -size / 2,
337
- y: size / 2,
338
- left: "50%",
339
- ...size === 0 && {
340
- left: "auto",
341
- right: "auto"
342
- }
343
- };
344
- return /* @__PURE__ */ jsx(
345
- SliderThumbFrame,
346
- {
347
- ref: composedRefs,
348
- role: "slider",
349
- "aria-label": props["aria-label"] || label,
350
- "aria-valuemin": context.min,
351
- "aria-valuenow": value,
352
- "aria-valuemax": context.max,
353
- "aria-orientation": context.orientation,
354
- "data-orientation": context.orientation,
355
- "data-disabled": context.disabled ? "" : void 0,
356
- tabIndex: context.disabled ? void 0 : 0,
357
- animateOnly: ["transform", "left", "top", "right", "bottom"],
358
- ...positionalStyles,
359
- [orientation.startEdge]: `${percent}%`,
360
- size: sizeIn,
361
- circular,
362
- ...thumbProps,
363
- onLayout: (e) => {
364
- setSize(e.nativeEvent.layout[orientation.sizeProp]);
365
- },
366
- onFocus: composeEventHandlers(props.onFocus, () => {
367
- context.valueIndexToChangeRef.current = index;
368
- })
369
- }
370
- );
371
- },
372
- {
373
- staticConfig: {
374
- memo: !0
375
- }
376
- }
377
- ), SliderComponent = React.forwardRef(
378
- (props, forwardedRef) => {
379
- const {
380
- name,
381
- min = 0,
382
- max = 100,
383
- step = 1,
384
- orientation = "horizontal",
385
- disabled = !1,
386
- minStepsBetweenThumbs = 0,
387
- defaultValue = [min],
388
- value,
389
- onValueChange = () => {
390
- },
391
- size: sizeProp,
392
- onSlideEnd,
393
- onSlideMove,
394
- onSlideStart,
395
- ...sliderProps
396
- } = props, sliderRef = React.useRef(null), composedRefs = useComposedRefs(sliderRef, forwardedRef), thumbRefs = React.useRef(/* @__PURE__ */ new Map()), valueIndexToChangeRef = React.useRef(0), isHorizontal = orientation === "horizontal", [values = [], setValues] = useControllableState({
397
- prop: value,
398
- defaultProp: defaultValue,
399
- transition: !0,
400
- onChange: (value2) => {
401
- updateThumbFocus(valueIndexToChangeRef.current), onValueChange(value2);
402
- }
403
- });
404
- isWeb && React.useEffect(() => {
405
- const node = sliderRef.current;
406
- if (!node) return;
407
- const preventDefault = (e) => {
408
- e.preventDefault();
409
- };
410
- return node.addEventListener("touchstart", preventDefault), () => {
411
- node.removeEventListener("touchstart", preventDefault);
412
- };
413
- }, []);
414
- function updateThumbFocus(focusIndex) {
415
- if (isWeb) {
416
- for (const [node, index] of thumbRefs.current.entries())
417
- if (index === focusIndex) {
418
- node.focus();
419
- return;
420
- }
421
- }
422
- }
423
- function handleSlideMove(value2, event) {
424
- updateValues(value2, valueIndexToChangeRef.current), onSlideMove?.(event, value2);
425
- }
426
- function updateValues(value2, atIndex) {
427
- const decimalCount = getDecimalCount(step), snapToStep = roundValue(
428
- Math.round((value2 - min) / step) * step + min,
429
- decimalCount
430
- ), nextValue = clamp(snapToStep, [min, max]);
431
- setValues((prevValues = []) => {
432
- const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
433
- return hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step) ? (valueIndexToChangeRef.current = nextValues.indexOf(nextValue), String(nextValues) === String(prevValues) ? prevValues : nextValues) : prevValues;
434
- });
435
- }
436
- const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
437
- return /* @__PURE__ */ jsx(
438
- SliderProvider,
439
- {
440
- scope: props.__scopeSlider,
441
- disabled,
442
- min,
443
- max,
444
- valueIndexToChangeRef,
445
- thumbs: thumbRefs.current,
446
- values,
447
- orientation,
448
- size: sizeProp,
449
- children: /* @__PURE__ */ jsx(
450
- SliderOriented,
451
- {
452
- "aria-disabled": disabled,
453
- "data-disabled": disabled ? "" : void 0,
454
- ...sliderProps,
455
- ref: composedRefs,
456
- min,
457
- max,
458
- onSlideEnd,
459
- onSlideStart: disabled ? void 0 : (value2, target, event) => {
460
- if (target !== "thumb") {
461
- const closestIndex = getClosestValueIndex(values, value2);
462
- updateValues(value2, closestIndex);
463
- }
464
- onSlideStart?.(event, value2, target);
465
- },
466
- onSlideMove: disabled ? void 0 : handleSlideMove,
467
- onHomeKeyDown: () => !disabled && updateValues(min, 0),
468
- onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
469
- onStepKeyDown: ({ event, direction: stepDirection }) => {
470
- if (!disabled) {
471
- const multiplier = PAGE_KEYS.includes(event.key) || event.shiftKey && ARROW_KEYS.includes(event.key) ? 10 : 1, atIndex = valueIndexToChangeRef.current, value2 = values[atIndex], stepInDirection = step * multiplier * stepDirection;
472
- updateValues(value2 + stepInDirection, atIndex);
473
- }
474
- }
475
- }
476
- )
477
- }
478
- );
479
- }
480
- ), Slider = withStaticProperties(SliderComponent, {
481
- Track: SliderTrack,
482
- TrackActive: SliderActive,
483
- Thumb: SliderThumb
484
- });
485
- Slider.displayName = SLIDER_NAME;
486
- const Track = SliderTrack, Range = SliderActive, Thumb = SliderThumb;
487
- export {
488
- Range,
489
- Slider,
490
- SliderActive,
491
- SliderActiveFrame,
492
- SliderThumb,
493
- SliderThumbFrame,
494
- SliderTrack,
495
- SliderTrackFrame,
496
- Thumb,
497
- Track
498
- };
499
- //# sourceMappingURL=Slider.js.map