@cdx-ui/primitives 0.0.1-beta.114 → 0.0.1-beta.116

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 (85) hide show
  1. package/README.md +32 -30
  2. package/lib/commonjs/index.js +35 -0
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/overlay/useAnchorPosition.js +60 -11
  5. package/lib/commonjs/overlay/useAnchorPosition.js.map +1 -1
  6. package/lib/commonjs/slider/SliderRail.js +131 -0
  7. package/lib/commonjs/slider/SliderRail.js.map +1 -0
  8. package/lib/commonjs/slider/SliderRoot.js +186 -0
  9. package/lib/commonjs/slider/SliderRoot.js.map +1 -0
  10. package/lib/commonjs/slider/SliderThumb.js +228 -0
  11. package/lib/commonjs/slider/SliderThumb.js.map +1 -0
  12. package/lib/commonjs/slider/context.js +11 -0
  13. package/lib/commonjs/slider/context.js.map +1 -0
  14. package/lib/commonjs/slider/index.js +65 -0
  15. package/lib/commonjs/slider/index.js.map +1 -0
  16. package/lib/commonjs/slider/types.js +6 -0
  17. package/lib/commonjs/slider/types.js.map +1 -0
  18. package/lib/commonjs/slider/useSliderPointer.js +116 -0
  19. package/lib/commonjs/slider/useSliderPointer.js.map +1 -0
  20. package/lib/commonjs/slider/utils.js +155 -0
  21. package/lib/commonjs/slider/utils.js.map +1 -0
  22. package/lib/commonjs/utils/assignRef.js +16 -0
  23. package/lib/commonjs/utils/assignRef.js.map +1 -0
  24. package/lib/commonjs/utils/createPortal.js +3 -1
  25. package/lib/commonjs/utils/createPortal.js.map +1 -1
  26. package/lib/module/index.js +4 -0
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/overlay/useAnchorPosition.js +60 -11
  29. package/lib/module/overlay/useAnchorPosition.js.map +1 -1
  30. package/lib/module/slider/SliderRail.js +127 -0
  31. package/lib/module/slider/SliderRail.js.map +1 -0
  32. package/lib/module/slider/SliderRoot.js +182 -0
  33. package/lib/module/slider/SliderRoot.js.map +1 -0
  34. package/lib/module/slider/SliderThumb.js +224 -0
  35. package/lib/module/slider/SliderThumb.js.map +1 -0
  36. package/lib/module/slider/context.js +5 -0
  37. package/lib/module/slider/context.js.map +1 -0
  38. package/lib/module/slider/index.js +8 -0
  39. package/lib/module/slider/index.js.map +1 -0
  40. package/lib/module/slider/types.js +4 -0
  41. package/lib/module/slider/types.js.map +1 -0
  42. package/lib/module/slider/useSliderPointer.js +110 -0
  43. package/lib/module/slider/useSliderPointer.js.map +1 -0
  44. package/lib/module/slider/utils.js +138 -0
  45. package/lib/module/slider/utils.js.map +1 -0
  46. package/lib/module/utils/assignRef.js +12 -0
  47. package/lib/module/utils/assignRef.js.map +1 -0
  48. package/lib/module/utils/createPortal.js +3 -1
  49. package/lib/module/utils/createPortal.js.map +1 -1
  50. package/lib/typescript/index.d.ts +4 -0
  51. package/lib/typescript/index.d.ts.map +1 -1
  52. package/lib/typescript/overlay/useAnchorPosition.d.ts +7 -1
  53. package/lib/typescript/overlay/useAnchorPosition.d.ts.map +1 -1
  54. package/lib/typescript/slider/SliderRail.d.ts +6 -0
  55. package/lib/typescript/slider/SliderRail.d.ts.map +1 -0
  56. package/lib/typescript/slider/SliderRoot.d.ts +7 -0
  57. package/lib/typescript/slider/SliderRoot.d.ts.map +1 -0
  58. package/lib/typescript/slider/SliderThumb.d.ts +6 -0
  59. package/lib/typescript/slider/SliderThumb.d.ts.map +1 -0
  60. package/lib/typescript/slider/context.d.ts +37 -0
  61. package/lib/typescript/slider/context.d.ts.map +1 -0
  62. package/lib/typescript/slider/index.d.ts +8 -0
  63. package/lib/typescript/slider/index.d.ts.map +1 -0
  64. package/lib/typescript/slider/types.d.ts +37 -0
  65. package/lib/typescript/slider/types.d.ts.map +1 -0
  66. package/lib/typescript/slider/useSliderPointer.d.ts +23 -0
  67. package/lib/typescript/slider/useSliderPointer.d.ts.map +1 -0
  68. package/lib/typescript/slider/utils.d.ts +23 -0
  69. package/lib/typescript/slider/utils.d.ts.map +1 -0
  70. package/lib/typescript/utils/assignRef.d.ts +3 -0
  71. package/lib/typescript/utils/assignRef.d.ts.map +1 -0
  72. package/lib/typescript/utils/createPortal.d.ts.map +1 -1
  73. package/package.json +2 -2
  74. package/src/index.ts +4 -0
  75. package/src/overlay/useAnchorPosition.ts +79 -11
  76. package/src/slider/SliderRail.tsx +143 -0
  77. package/src/slider/SliderRoot.tsx +266 -0
  78. package/src/slider/SliderThumb.tsx +268 -0
  79. package/src/slider/context.tsx +38 -0
  80. package/src/slider/index.ts +19 -0
  81. package/src/slider/types.ts +44 -0
  82. package/src/slider/useSliderPointer.ts +157 -0
  83. package/src/slider/utils.ts +181 -0
  84. package/src/utils/assignRef.ts +11 -0
  85. package/src/utils/createPortal.ts +3 -1
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ function toPercentDimension(percent) {
4
+ return `${String(percent)}%`;
5
+ }
6
+ export const SLIDER_MARKER_SIZE = 3;
7
+ export function clamp(value, min, max) {
8
+ return Math.min(max, Math.max(min, value));
9
+ }
10
+ export function getThumbTravel(trackSize, _thumbSize) {
11
+ return Math.max(trackSize, 0);
12
+ }
13
+
14
+ /** Thumb leading-edge offset along the track axis (center-based). */
15
+ export function percentToThumbOffset(percent, trackSize, thumbSize) {
16
+ if (trackSize <= 0) return 0;
17
+ return clamp(percent, 0, 100) / 100 * trackSize - thumbSize / 2;
18
+ }
19
+
20
+ /** Filled track extent to the thumb center. */
21
+ export function percentToFillExtent(percent, trackSize, _thumbSize) {
22
+ if (trackSize <= 0) return 0;
23
+ return clamp(percent, 0, 100) / 100 * trackSize;
24
+ }
25
+
26
+ /** Map a pointer coordinate on the track axis to a 0–1 ratio. */
27
+ export function pointerCoordToRatio(pointerCoord, trackStart, trackSize, _thumbSize) {
28
+ if (trackSize <= 0) {
29
+ return 0;
30
+ }
31
+ return clamp((pointerCoord - trackStart) / trackSize, 0, 1);
32
+ }
33
+
34
+ /** Vertical slider: bottom = min (0), top = max (1). */
35
+ export function pointerCoordToVerticalRatio(pointerCoord, trackStart, trackSize, _thumbSize) {
36
+ if (trackSize <= 0) {
37
+ return 0;
38
+ }
39
+ return clamp((trackStart + trackSize - pointerCoord) / trackSize, 0, 1);
40
+ }
41
+ export function snapToStep(value, min, max, step) {
42
+ if (step <= 0) {
43
+ return clamp(value, min, max);
44
+ }
45
+ const stepped = min + Math.round((value - min) / step) * step;
46
+ return clamp(stepped, min, max);
47
+ }
48
+ export function valueToPercent(value, min, max) {
49
+ if (max <= min) {
50
+ return 0;
51
+ }
52
+ return (clamp(value, min, max) - min) / (max - min) * 100;
53
+ }
54
+ export function percentToValue(percent, min, max, step) {
55
+ const ratio = clamp(percent, 0, 100) / 100;
56
+ return snapToStep(min + ratio * (max - min), min, max, step);
57
+ }
58
+ export function formatSliderValue(value) {
59
+ return Number.isInteger(value) ? String(value) : value.toFixed(1);
60
+ }
61
+ export function getMarkerStepValues(min, max, step) {
62
+ if (step <= 0 || max <= min) {
63
+ return [];
64
+ }
65
+ const decimals = getDecimalPlaces(step);
66
+ const stepCount = Math.floor((max - min) / step);
67
+ const values = Array.from({
68
+ length: stepCount + 1
69
+ }, (_, index) => roundTo(min + index * step, decimals));
70
+ if (values[values.length - 1] < max) {
71
+ values.push(max);
72
+ }
73
+ return values;
74
+ }
75
+ function getDecimalPlaces(n) {
76
+ const str = String(n);
77
+ const dotIndex = str.indexOf('.');
78
+ return dotIndex === -1 ? 0 : str.length - dotIndex - 1;
79
+ }
80
+ function roundTo(value, decimals) {
81
+ const factor = 10 ** decimals;
82
+ return Math.round(value * factor) / factor;
83
+ }
84
+
85
+ /** Marker leading-edge offset (center-aligned to the thumb coordinate system). */
86
+ export function percentToMarkerCenterOffset(percent, trackSize, markerSize = SLIDER_MARKER_SIZE) {
87
+ if (trackSize <= 0) return 0;
88
+ return clamp(percent, 0, 100) / 100 * trackSize - markerSize / 2;
89
+ }
90
+ export function getMarkerPositionStyle(percent, orientation, trackLayout, _thumbSize, markerSize = SLIDER_MARKER_SIZE) {
91
+ const trackSize = trackLayout == null ? 0 : orientation === 'horizontal' ? trackLayout.width : trackLayout.height;
92
+ if (trackSize > 0) {
93
+ const offset = percentToMarkerCenterOffset(percent, trackSize, markerSize);
94
+ if (orientation === 'vertical') {
95
+ return {
96
+ position: 'absolute',
97
+ left: '50%',
98
+ bottom: offset,
99
+ width: markerSize,
100
+ height: markerSize,
101
+ marginLeft: -markerSize / 2
102
+ };
103
+ }
104
+ return {
105
+ position: 'absolute',
106
+ top: '50%',
107
+ left: offset,
108
+ width: markerSize,
109
+ height: markerSize,
110
+ marginTop: -markerSize / 2
111
+ };
112
+ }
113
+ if (orientation === 'vertical') {
114
+ return {
115
+ position: 'absolute',
116
+ left: '50%',
117
+ bottom: toPercentDimension(percent),
118
+ width: markerSize,
119
+ height: markerSize,
120
+ marginLeft: -markerSize / 2,
121
+ transform: [{
122
+ translateY: markerSize / 2
123
+ }]
124
+ };
125
+ }
126
+ return {
127
+ position: 'absolute',
128
+ top: '50%',
129
+ left: toPercentDimension(percent),
130
+ width: markerSize,
131
+ height: markerSize,
132
+ marginTop: -markerSize / 2,
133
+ transform: [{
134
+ translateX: -markerSize / 2
135
+ }]
136
+ };
137
+ }
138
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["toPercentDimension","percent","String","SLIDER_MARKER_SIZE","clamp","value","min","max","Math","getThumbTravel","trackSize","_thumbSize","percentToThumbOffset","thumbSize","percentToFillExtent","pointerCoordToRatio","pointerCoord","trackStart","pointerCoordToVerticalRatio","snapToStep","step","stepped","round","valueToPercent","percentToValue","ratio","formatSliderValue","Number","isInteger","toFixed","getMarkerStepValues","decimals","getDecimalPlaces","stepCount","floor","values","Array","from","length","_","index","roundTo","push","n","str","dotIndex","indexOf","factor","percentToMarkerCenterOffset","markerSize","getMarkerPositionStyle","orientation","trackLayout","width","height","offset","position","left","bottom","marginLeft","top","marginTop","transform","translateY","translateX"],"sourceRoot":"../../../src","sources":["slider/utils.ts"],"mappings":";;AAMA,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CAAC;MACnCoD,KAAK,EAAEJ,UAAU;MACjBK,MAAM,EAAEL,UAAU;MAClBU,UAAU,EAAE,CAACV,UAAU,GAAG,CAAC;MAC3Ba,SAAS,EAAE,CAAC;QAAEC,UAAU,EAAEd,UAAU,GAAG;MAAE,CAAC;IAC5C,CAAC;EACH;EAEA,OAAO;IACLO,QAAQ,EAAE,UAAU;IACpBI,GAAG,EAAE,KAAK;IACVH,IAAI,EAAEzD,kBAAkB,CAACC,OAAO,CAAC;IACjCoD,KAAK,EAAEJ,UAAU;IACjBK,MAAM,EAAEL,UAAU;IAClBY,SAAS,EAAE,CAACZ,UAAU,GAAG,CAAC;IAC1Ba,SAAS,EAAE,CAAC;MAAEE,UAAU,EAAE,CAACf,UAAU,GAAG;IAAE,CAAC;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ export function assignRef(ref, value) {
4
+ if (typeof ref === 'function') {
5
+ ref(value);
6
+ return;
7
+ }
8
+ if (ref) {
9
+ ref.current = value;
10
+ }
11
+ }
12
+ //# sourceMappingURL=assignRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["assignRef","ref","value","current"],"sourceRoot":"../../../src","sources":["utils/assignRef.ts"],"mappings":";;AAEA,OAAO,SAASA,SAASA,CAAIC,GAAoB,EAAEC,KAAe,EAAE;EAClE,IAAI,OAAOD,GAAG,KAAK,UAAU,EAAE;IAC7BA,GAAG,CAACC,KAAK,CAAC;IACV;EACF;EACA,IAAID,GAAG,EAAE;IACPA,GAAG,CAACE,OAAO,GAAGD,KAAK;EACrB;AACF","ignoreList":[]}
@@ -8,8 +8,10 @@ import { Platform } from 'react-native';
8
8
  * `react-dom`, which would cause a build error on native platforms.
9
9
  */
10
10
  export const createPortalFn = (() => {
11
- if (Platform.OS !== 'web') return undefined;
12
11
  try {
12
+ if (Platform.OS !== 'web') {
13
+ return undefined;
14
+ }
13
15
  // eslint-disable-next-line @typescript-eslint/no-require-imports
14
16
  return require('react-dom').createPortal;
15
17
  } catch {
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","createPortalFn","OS","undefined","require","createPortal"],"sourceRoot":"../../../src","sources":["utils/createPortal.ts"],"mappings":";;AACA,SAASA,QAAQ,QAAQ,cAAc;AAIvC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAA0C,GAAG,CAAC,MAAM;EAC/D,IAAID,QAAQ,CAACE,EAAE,KAAK,KAAK,EAAE,OAAOC,SAAS;EAC3C,IAAI;IACF;IACA,OAAQC,OAAO,CAAC,WAAW,CAAC,CAAsCC,YAAY;EAChF,CAAC,CAAC,MAAM;IACN,OAAOF,SAAS;EAClB;AACF,CAAC,EAAE,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Platform","createPortalFn","OS","undefined","require","createPortal"],"sourceRoot":"../../../src","sources":["utils/createPortal.ts"],"mappings":";;AACA,SAASA,QAAQ,QAAQ,cAAc;AAIvC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAA0C,GAAG,CAAC,MAAM;EAC/D,IAAI;IACF,IAAID,QAAQ,CAACE,EAAE,KAAK,KAAK,EAAE;MACzB,OAAOC,SAAS;IAClB;IACA;IACA,OAAQC,OAAO,CAAC,WAAW,CAAC,CAAsCC,YAAY;EAChF,CAAC,CAAC,MAAM;IACN,OAAOF,SAAS;EAClB;AACF,CAAC,EAAE,CAAC","ignoreList":[]}
@@ -11,6 +11,7 @@ export * from './otp-input';
11
11
  export * from './link';
12
12
  export * from './list-item';
13
13
  export { type EdgeInsets, OverlayInsetsProvider } from './overlay';
14
+ export { useAnchorPosition, type AnchorLayout } from './overlay';
14
15
  export * from './select';
15
16
  export * from './switch';
16
17
  export * from './tile';
@@ -18,9 +19,12 @@ export * from './toast';
18
19
  export * from './portal';
19
20
  export * from './progress-bar';
20
21
  export * from './radio';
22
+ export * from './slider';
21
23
  export type { InteractionState } from './types';
22
24
  export { FormControlContext, useFormControlContext } from '@cdx-ui/utils';
23
25
  export { dataAttributes, mergeDataAttributes } from './utils/dataAttributes';
24
26
  export { domDataAttributes, mergeDomDataAttributes, type DomDataAttributeValue, } from './utils/domDataAttributes';
27
+ export { assignRef } from './utils/assignRef';
28
+ export { createPortalFn } from './utils/createPortal';
25
29
  export { Slot } from './slot';
26
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACjE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
@@ -5,11 +5,17 @@ export interface AnchorLayout {
5
5
  width: number;
6
6
  height: number;
7
7
  }
8
+ export interface UseAnchorPositionOptions {
9
+ /** Re-run layout measurement when this value changes (e.g. slider value percent). */
10
+ remeasureKey?: unknown;
11
+ /** Poll anchor position each animation frame while open (for anchors that move). */
12
+ trackWhileOpen?: boolean;
13
+ }
8
14
  /**
9
15
  * Measures an anchor element's position and size, re-measuring on scroll/resize
10
16
  * (web) so a positioned overlay can track its anchor across layout changes.
11
17
  *
12
18
  * Returns `null` until the first measurement completes.
13
19
  */
14
- export declare function useAnchorPosition(anchorRef: RefObject<any>, open: boolean): AnchorLayout | null;
20
+ export declare function useAnchorPosition(anchorRef: RefObject<any>, open: boolean, options?: UseAnchorPositionOptions): AnchorLayout | null;
15
21
  //# sourceMappingURL=useAnchorPosition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAnchorPosition.d.ts","sourceRoot":"","sources":["../../../src/overlay/useAnchorPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC,MAAM,WAAW,YAAY;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAOD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI,CA+C/F"}
1
+ {"version":3,"file":"useAnchorPosition.d.ts","sourceRoot":"","sources":["../../../src/overlay/useAnchorPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC,MAAM,WAAW,YAAY;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAwBD,MAAM,WAAW,wBAAwB;IACvC,qFAAqF;IACrF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,oFAAoF;IACpF,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,EACzB,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,wBAAwB,GACjC,YAAY,GAAG,IAAI,CAuFrB"}
@@ -0,0 +1,6 @@
1
+ import { View } from 'react-native';
2
+ import type { InterfaceSliderRailProps } from './types';
3
+ export interface SliderRailProps extends InterfaceSliderRailProps {
4
+ }
5
+ export declare const SliderRail: import("react").ForwardRefExoticComponent<SliderRailProps & import("react").RefAttributes<View>>;
6
+ //# sourceMappingURL=SliderRail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SliderRail.d.ts","sourceRoot":"","sources":["../../../src/slider/SliderRail.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,IAAI,EAIL,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGxD,MAAM,WAAW,eAAgB,SAAQ,wBAAwB;CAAG;AAEpE,eAAO,MAAM,UAAU,kGAiHtB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { View } from 'react-native';
2
+ import type { InterfaceSliderProps } from './types';
3
+ export interface SliderRootProps extends InterfaceSliderProps {
4
+ readonly asChild?: boolean;
5
+ }
6
+ export declare const SliderRoot: import("react").ForwardRefExoticComponent<SliderRootProps & import("react").RefAttributes<View>>;
7
+ //# sourceMappingURL=SliderRoot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SliderRoot.d.ts","sourceRoot":"","sources":["../../../src/slider/SliderRoot.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,IAAI,EAIL,MAAM,cAAc,CAAC;AAMtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAKpD,MAAM,WAAW,eAAgB,SAAQ,oBAAoB;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,eAAO,MAAM,UAAU,kGAiPtB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { View } from 'react-native';
2
+ import type { InterfaceSliderThumbProps } from './types';
3
+ export interface SliderThumbProps extends InterfaceSliderThumbProps {
4
+ }
5
+ export declare const SliderThumb: import("react").ForwardRefExoticComponent<SliderThumbProps & import("react").RefAttributes<View>>;
6
+ //# sourceMappingURL=SliderThumb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SliderThumb.d.ts","sourceRoot":"","sources":["../../../src/slider/SliderThumb.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,IAAI,EAKL,MAAM,cAAc,CAAC;AAQtB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAIzD,MAAM,WAAW,gBAAiB,SAAQ,yBAAyB;CAAG;AAEtE,eAAO,MAAM,WAAW,mGAiPvB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { RefObject } from 'react';
2
+ import type { View } from 'react-native';
3
+ import type { SliderOrientation } from './types';
4
+ export interface SliderTrackLayout {
5
+ readonly width: number;
6
+ readonly height: number;
7
+ readonly x: number;
8
+ readonly y: number;
9
+ }
10
+ export interface SliderContextValue {
11
+ readonly value: number;
12
+ readonly min: number;
13
+ readonly max: number;
14
+ readonly step: number;
15
+ readonly percent: number;
16
+ readonly orientation: SliderOrientation;
17
+ readonly isDisabled: boolean;
18
+ readonly isDragging: boolean;
19
+ readonly isHovered: boolean;
20
+ readonly isFocused: boolean;
21
+ readonly trackLayout: SliderTrackLayout | null;
22
+ readonly thumbSize: number;
23
+ readonly setValue: (value: number, complete?: boolean) => void;
24
+ readonly setValueFromRatio: (ratio: number, complete?: boolean) => void;
25
+ readonly setTrackLayout: (layout: SliderTrackLayout) => void;
26
+ readonly setThumbSize: (size: number) => void;
27
+ readonly setIsDragging: (dragging: boolean) => void;
28
+ readonly setIsHovered: (hovered: boolean) => void;
29
+ readonly setIsFocused: (focused: boolean) => void;
30
+ readonly getValueLabel: () => string;
31
+ readonly thumbRef: RefObject<View | null>;
32
+ }
33
+ export declare const SliderProvider: import("react").FunctionComponent<{
34
+ children: import("react").ReactNode;
35
+ value: SliderContextValue;
36
+ }>, useSliderContext: () => SliderContextValue;
37
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/slider/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACxE,QAAQ,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC7D,QAAQ,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,aAAa,EAAE,MAAM,MAAM,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;CAC3C;AAED,eAAO,MAAO,cAAc;;;IAAE,gBAAgB,0BACM,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type { ISliderProps, ISliderRailProps, ISliderThumbProps, SliderAccessibilityValue, SliderOrientation, } from './types';
2
+ export type { SliderContextValue, SliderTrackLayout } from './context';
3
+ export { useSliderContext } from './context';
4
+ export { SliderRoot, type SliderRootProps } from './SliderRoot';
5
+ export { SliderRail, type SliderRailProps } from './SliderRail';
6
+ export { SliderThumb, type SliderThumbProps } from './SliderThumb';
7
+ export { getMarkerPositionStyle, getMarkerStepValues, percentToFillExtent, SLIDER_MARKER_SIZE, valueToPercent, } from './utils';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/slider/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,SAAS,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { PressableProps, ViewProps } from 'react-native';
3
+ export type SliderOrientation = 'horizontal' | 'vertical';
4
+ export type SliderAccessibilityValue = NonNullable<ViewProps['accessibilityValue']>;
5
+ export interface InterfaceSliderProps extends Omit<ViewProps, 'children' | 'accessibilityValue'> {
6
+ readonly value?: number;
7
+ readonly defaultValue?: number;
8
+ readonly onChange?: (value: number) => void;
9
+ readonly onChangeComplete?: (value: number) => void;
10
+ readonly min?: number;
11
+ readonly max?: number;
12
+ readonly step?: number;
13
+ readonly isDisabled?: boolean;
14
+ readonly orientation?: SliderOrientation;
15
+ /**
16
+ * Screen reader label when there is no visible label.
17
+ */
18
+ readonly accessibilityLabel?: string;
19
+ /**
20
+ * Screen reader value for the slider. Merged with derived `min`, `max`, `now`, and formatted
21
+ * `text` when fields are omitted. `text` overrides the numeric announcement when set.
22
+ */
23
+ readonly accessibilityValue?: SliderAccessibilityValue;
24
+ readonly children?: ReactNode;
25
+ }
26
+ export type ISliderProps = InterfaceSliderProps;
27
+ export interface InterfaceSliderRailProps extends ViewProps {
28
+ readonly asChild?: boolean;
29
+ readonly children?: ReactNode;
30
+ }
31
+ export type ISliderRailProps = InterfaceSliderRailProps;
32
+ export interface InterfaceSliderThumbProps extends PressableProps {
33
+ readonly asChild?: boolean;
34
+ readonly children?: ReactNode;
35
+ }
36
+ export type ISliderThumbProps = InterfaceSliderThumbProps;
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/slider/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,UAAU,CAAC;AAE1D,MAAM,MAAM,wBAAwB,GAAG,WAAW,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAEpF,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,GAAG,oBAAoB,CAAC;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IACzC;;OAEG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,wBAAwB,CAAC;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B;AAED,MAAM,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAEhD,MAAM,WAAW,wBAAyB,SAAQ,SAAS;IACzD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B;AAED,MAAM,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAExD,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B;AAED,MAAM,MAAM,iBAAiB,GAAG,yBAAyB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { SliderTrackLayout } from './context';
2
+ import type { SliderOrientation } from './types';
3
+ export declare function getPointerCoords(nativeEvent: {
4
+ pageX?: number;
5
+ pageY?: number;
6
+ clientX?: number;
7
+ clientY?: number;
8
+ }): {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ export declare function getRatioFromPagePoint(pageX: number, pageY: number, trackLayout: SliderTrackLayout | null, orientation: SliderOrientation, thumbSize: number): number;
13
+ export declare function useWebSliderDrag({ isDisabled, setIsDragging, setValueFromRatio, trackLayout, orientation, thumbSize, }: {
14
+ isDisabled: boolean;
15
+ setIsDragging: (dragging: boolean) => void;
16
+ setValueFromRatio: (ratio: number, complete?: boolean) => void;
17
+ trackLayout: SliderTrackLayout | null;
18
+ orientation: SliderOrientation;
19
+ thumbSize: number;
20
+ }): {
21
+ startDrag: (pageX: number, pageY: number, anchorRatio?: number, trackLayoutOverride?: SliderTrackLayout) => void;
22
+ };
23
+ //# sourceMappingURL=useSliderPointer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSliderPointer.d.ts","sourceRoot":"","sources":["../../../src/slider/useSliderPointer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGjD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAS3B;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,iBAAiB,GAAG,IAAI,EACrC,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,MAAM,GAChB,MAAM,CAUR;AAQD,wBAAgB,gBAAgB,CAAC,EAC/B,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,SAAS,GACV,EAAE;IACD,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/D,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACtC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB;uBAyBY,MAAM,SACN,MAAM,gBACC,MAAM,wBACE,iBAAiB;EAoE5C"}
@@ -0,0 +1,23 @@
1
+ import type { ViewStyle } from 'react-native';
2
+ import type { SliderTrackLayout } from './context';
3
+ import type { SliderOrientation } from './types';
4
+ export declare const SLIDER_MARKER_SIZE = 3;
5
+ export declare function clamp(value: number, min: number, max: number): number;
6
+ export declare function getThumbTravel(trackSize: number, _thumbSize: number): number;
7
+ /** Thumb leading-edge offset along the track axis (center-based). */
8
+ export declare function percentToThumbOffset(percent: number, trackSize: number, thumbSize: number): number;
9
+ /** Filled track extent to the thumb center. */
10
+ export declare function percentToFillExtent(percent: number, trackSize: number, _thumbSize: number): number;
11
+ /** Map a pointer coordinate on the track axis to a 0–1 ratio. */
12
+ export declare function pointerCoordToRatio(pointerCoord: number, trackStart: number, trackSize: number, _thumbSize: number): number;
13
+ /** Vertical slider: bottom = min (0), top = max (1). */
14
+ export declare function pointerCoordToVerticalRatio(pointerCoord: number, trackStart: number, trackSize: number, _thumbSize: number): number;
15
+ export declare function snapToStep(value: number, min: number, max: number, step: number): number;
16
+ export declare function valueToPercent(value: number, min: number, max: number): number;
17
+ export declare function percentToValue(percent: number, min: number, max: number, step: number): number;
18
+ export declare function formatSliderValue(value: number): string;
19
+ export declare function getMarkerStepValues(min: number, max: number, step: number): number[];
20
+ /** Marker leading-edge offset (center-aligned to the thumb coordinate system). */
21
+ export declare function percentToMarkerCenterOffset(percent: number, trackSize: number, markerSize?: number): number;
22
+ export declare function getMarkerPositionStyle(percent: number, orientation: SliderOrientation, trackLayout: SliderTrackLayout | null, _thumbSize: number, markerSize?: number): ViewStyle;
23
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/slider/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAQjD,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM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,EAAE,MAAM,EACjB,UAAU,SAAqB,GAC9B,MAAM,CAGR;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,iBAAiB,EAC9B,WAAW,EAAE,iBAAiB,GAAG,IAAI,EACrC,UAAU,EAAE,MAAM,EAClB,UAAU,SAAqB,GAC9B,SAAS,CA+CX"}
@@ -0,0 +1,3 @@
1
+ import type { ForwardedRef } from 'react';
2
+ export declare function assignRef<T>(ref: ForwardedRef<T>, value: T | null): void;
3
+ //# sourceMappingURL=assignRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignRef.d.ts","sourceRoot":"","sources":["../../../src/utils/assignRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,QAQjE"}
@@ -1 +1 @@
1
- {"version":3,"file":"createPortal.d.ts","sourceRoot":"","sources":["../../../src/utils/createPortal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,KAAK,KAAK,CAAC,WAAW,CAAC;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,cAAc,GAAG,SAQ1C,CAAC"}
1
+ {"version":3,"file":"createPortal.d.ts","sourceRoot":"","sources":["../../../src/utils/createPortal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,KAAK,KAAK,CAAC,WAAW,CAAC;AAE3F;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,cAAc,GAAG,SAU1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdx-ui/primitives",
3
- "version": "0.0.1-beta.114",
3
+ "version": "0.0.1-beta.116",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "module": "lib/module/index.js",
6
6
  "react-native": "src/index.ts",
@@ -60,7 +60,7 @@
60
60
  "@react-stately/checkbox": "3.7.4",
61
61
  "@react-stately/radio": "3.12.0",
62
62
  "@react-stately/toggle": "3.9.4",
63
- "@cdx-ui/utils": "0.0.1-beta.114"
63
+ "@cdx-ui/utils": "0.0.1-beta.116"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/react": "19.1.17",
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export * from './otp-input';
11
11
  export * from './link';
12
12
  export * from './list-item';
13
13
  export { type EdgeInsets, OverlayInsetsProvider } from './overlay';
14
+ export { useAnchorPosition, type AnchorLayout } from './overlay';
14
15
  export * from './select';
15
16
  export * from './switch';
16
17
  export * from './tile';
@@ -18,6 +19,7 @@ export * from './toast';
18
19
  export * from './portal';
19
20
  export * from './progress-bar';
20
21
  export * from './radio';
22
+ export * from './slider';
21
23
  export type { InteractionState } from './types';
22
24
  export { FormControlContext, useFormControlContext } from '@cdx-ui/utils';
23
25
  export { dataAttributes, mergeDataAttributes } from './utils/dataAttributes';
@@ -26,4 +28,6 @@ export {
26
28
  mergeDomDataAttributes,
27
29
  type DomDataAttributeValue,
28
30
  } from './utils/domDataAttributes';
31
+ export { assignRef } from './utils/assignRef';
32
+ export { createPortalFn } from './utils/createPortal';
29
33
  export { Slot } from './slot';
@@ -16,32 +16,79 @@ function measureWeb(element: any): AnchorLayout {
16
16
  return { x: rect.left, y: rect.top, width: rect.width, height: rect.height };
17
17
  }
18
18
 
19
+ function setLayoutIfChanged(
20
+ setLayout: React.Dispatch<React.SetStateAction<AnchorLayout | null>>,
21
+ next: AnchorLayout,
22
+ ) {
23
+ setLayout((prev) => {
24
+ if (
25
+ prev?.x === next.x &&
26
+ prev.y === next.y &&
27
+ prev.width === next.width &&
28
+ prev.height === next.height
29
+ ) {
30
+ return prev;
31
+ }
32
+ return next;
33
+ });
34
+ }
35
+
36
+ export interface UseAnchorPositionOptions {
37
+ /** Re-run layout measurement when this value changes (e.g. slider value percent). */
38
+ remeasureKey?: unknown;
39
+ /** Poll anchor position each animation frame while open (for anchors that move). */
40
+ trackWhileOpen?: boolean;
41
+ }
42
+
19
43
  /**
20
44
  * Measures an anchor element's position and size, re-measuring on scroll/resize
21
45
  * (web) so a positioned overlay can track its anchor across layout changes.
22
46
  *
23
47
  * Returns `null` until the first measurement completes.
24
48
  */
25
- export function useAnchorPosition(anchorRef: RefObject<any>, open: boolean): AnchorLayout | null {
49
+ export function useAnchorPosition(
50
+ anchorRef: RefObject<any>,
51
+ open: boolean,
52
+ options?: UseAnchorPositionOptions,
53
+ ): AnchorLayout | null {
54
+ const { remeasureKey, trackWhileOpen = false } = options ?? {};
26
55
  const [layout, setLayout] = useState<AnchorLayout | null>(null);
27
56
 
57
+ const measureAnchor = () => {
58
+ const anchor = anchorRef.current;
59
+ if (!anchor) {
60
+ return;
61
+ }
62
+
63
+ if (Platform.OS === 'web') {
64
+ setLayoutIfChanged(setLayout, measureWeb(anchor));
65
+ return;
66
+ }
67
+
68
+ anchor.measureInWindow((x: number, y: number, width: number, height: number) => {
69
+ setLayoutIfChanged(setLayout, { x, y, width, height });
70
+ });
71
+ };
72
+
28
73
  useIsomorphicLayoutEffect(() => {
29
74
  if (!open) {
30
75
  setLayout(null);
31
76
  return;
32
77
  }
33
78
 
34
- const anchor = anchorRef.current;
35
- if (!anchor) return;
36
-
37
79
  let cancelled = false;
38
80
 
39
81
  if (Platform.OS === 'web') {
40
- setLayout(measureWeb(anchor));
82
+ measureAnchor();
41
83
  } else {
84
+ const anchor = anchorRef.current;
85
+ if (!anchor) {
86
+ return;
87
+ }
88
+
42
89
  anchor.measureInWindow((x: number, y: number, width: number, height: number) => {
43
90
  if (!cancelled) {
44
- setLayout({ x, y, width, height });
91
+ setLayoutIfChanged(setLayout, { x, y, width, height });
45
92
  }
46
93
  });
47
94
  }
@@ -49,15 +96,36 @@ export function useAnchorPosition(anchorRef: RefObject<any>, open: boolean): Anc
49
96
  return () => {
50
97
  cancelled = true;
51
98
  };
52
- }, [open, anchorRef]);
99
+ }, [open, anchorRef, remeasureKey]);
53
100
 
54
101
  useEffect(() => {
55
- if (!open || Platform.OS !== 'web') return;
102
+ if (!open || !trackWhileOpen) {
103
+ return;
104
+ }
105
+
106
+ let frameId = 0;
107
+ const tick = () => {
108
+ measureAnchor();
109
+ frameId = requestAnimationFrame(tick);
110
+ };
111
+ frameId = requestAnimationFrame(tick);
112
+
113
+ return () => {
114
+ cancelAnimationFrame(frameId);
115
+ };
116
+ }, [open, anchorRef, remeasureKey, trackWhileOpen]);
117
+
118
+ useEffect(() => {
119
+ if (!open || Platform.OS !== 'web' || trackWhileOpen) {
120
+ return;
121
+ }
56
122
 
57
123
  const anchor = anchorRef.current;
58
- if (!anchor) return;
124
+ if (!anchor) {
125
+ return;
126
+ }
59
127
 
60
- const update = () => setLayout(measureWeb(anchor));
128
+ const update = () => setLayoutIfChanged(setLayout, measureWeb(anchor));
61
129
 
62
130
  window.addEventListener('scroll', update, true);
63
131
  window.addEventListener('resize', update);
@@ -66,7 +134,7 @@ export function useAnchorPosition(anchorRef: RefObject<any>, open: boolean): Anc
66
134
  window.removeEventListener('scroll', update, true);
67
135
  window.removeEventListener('resize', update);
68
136
  };
69
- }, [open, anchorRef]);
137
+ }, [open, anchorRef, remeasureKey, trackWhileOpen]);
70
138
 
71
139
  return layout;
72
140
  }