@astryxdesign/core 0.7.6 → 0.7.7-canary.0eb44a2

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 (272) hide show
  1. package/dist/AppShell/AppShell.d.ts.map +1 -1
  2. package/dist/AppShell/AppShell.js +23 -3
  3. package/dist/Avatar/Avatar.d.ts.map +1 -1
  4. package/dist/Avatar/Avatar.js +1 -1
  5. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  6. package/dist/BottomSheet/BottomSheetPanel.js +16 -9
  7. package/dist/Breadcrumbs/BreadcrumbItem.d.ts.map +1 -1
  8. package/dist/Breadcrumbs/BreadcrumbItem.js +2 -1
  9. package/dist/Button/Button.d.ts.map +1 -1
  10. package/dist/Button/Button.js +3 -2
  11. package/dist/Chat/ChatComposerInput.d.ts +9 -0
  12. package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
  13. package/dist/Chat/ChatComposerInput.js +2 -0
  14. package/dist/Chat/ChatMessage.js +2 -2
  15. package/dist/Chat/chatMessage.vars.stylex.d.ts +8 -8
  16. package/dist/Chat/chatMessage.vars.stylex.js +8 -8
  17. package/dist/CommandPalette/CommandPaletteInput.d.ts.map +1 -1
  18. package/dist/CommandPalette/CommandPaletteInput.js +8 -1
  19. package/dist/DateInput/MonthScroller.d.ts.map +1 -1
  20. package/dist/DateInput/MonthScroller.js +72 -2
  21. package/dist/DateInput/Wheel.d.ts +17 -1
  22. package/dist/DateInput/Wheel.d.ts.map +1 -1
  23. package/dist/DateInput/Wheel.js +179 -19
  24. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  25. package/dist/DateRangeInput/DateRangeInput.js +63 -49
  26. package/dist/Dialog/Dialog.d.ts.map +1 -1
  27. package/dist/Dialog/Dialog.js +37 -1
  28. package/dist/Drawer/Drawer.d.ts.map +1 -1
  29. package/dist/Drawer/Drawer.js +6 -0
  30. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
  31. package/dist/Drawer/useDrawerDialogPresence.js +4 -0
  32. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  33. package/dist/DropdownMenu/DropdownMenu.js +20 -4
  34. package/dist/DropdownMenu/useMenuOverflow.d.ts +13 -3
  35. package/dist/DropdownMenu/useMenuOverflow.d.ts.map +1 -1
  36. package/dist/DropdownMenu/useMenuOverflow.js +31 -8
  37. package/dist/Field/PanelSearchInput.d.ts.map +1 -1
  38. package/dist/Field/PanelSearchInput.js +8 -1
  39. package/dist/Field/textEntryTraits.d.ts +6 -6
  40. package/dist/Field/textEntryTraits.js +6 -6
  41. package/dist/Layer/layerClickBoundary.d.ts +7 -1
  42. package/dist/Layer/layerClickBoundary.d.ts.map +1 -1
  43. package/dist/Layer/layerClickBoundary.js +2 -2
  44. package/dist/Layer/usePressPin.d.ts +95 -0
  45. package/dist/Layer/usePressPin.d.ts.map +1 -0
  46. package/dist/Layer/usePressPin.js +365 -0
  47. package/dist/Layer/useTouchTrigger.d.ts +23 -1
  48. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  49. package/dist/Layer/useTouchTrigger.js +45 -7
  50. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  51. package/dist/Lightbox/Lightbox.js +2 -1
  52. package/dist/Link/Link.d.ts.map +1 -1
  53. package/dist/Link/Link.js +1 -0
  54. package/dist/Popover/usePopover.d.ts.map +1 -1
  55. package/dist/Popover/usePopover.js +56 -7
  56. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  57. package/dist/PowerSearch/PowerSearch.js +38 -30
  58. package/dist/ProgressBar/ProgressBar.d.ts +1 -1
  59. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  60. package/dist/ProgressBar/ProgressBar.js +52 -14
  61. package/dist/ProgressBar/ProgressBarTouch.d.ts +29 -0
  62. package/dist/ProgressBar/ProgressBarTouch.d.ts.map +1 -0
  63. package/dist/ProgressBar/ProgressBarTouch.js +91 -0
  64. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  65. package/dist/SegmentedControl/SegmentedControlItem.js +2 -1
  66. package/dist/Selector/Selector.d.ts.map +1 -1
  67. package/dist/Selector/Selector.js +25 -13
  68. package/dist/Slider/Slider.d.ts.map +1 -1
  69. package/dist/Slider/Slider.js +404 -131
  70. package/dist/Slider/sliderTouchController.d.ts +189 -0
  71. package/dist/Slider/sliderTouchController.d.ts.map +1 -0
  72. package/dist/Slider/sliderTouchController.js +1017 -0
  73. package/dist/Slider/useSliderTouch.d.ts +22 -0
  74. package/dist/Slider/useSliderTouch.d.ts.map +1 -0
  75. package/dist/Slider/useSliderTouch.js +56 -0
  76. package/dist/Switch/Switch.d.ts +1 -1
  77. package/dist/Switch/Switch.d.ts.map +1 -1
  78. package/dist/Switch/Switch.js +200 -46
  79. package/dist/Switch/switchFill.d.ts +31 -0
  80. package/dist/Switch/switchFill.d.ts.map +1 -0
  81. package/dist/Switch/switchFill.js +88 -0
  82. package/dist/Switch/switchTouch.d.ts +81 -0
  83. package/dist/Switch/switchTouch.d.ts.map +1 -0
  84. package/dist/Switch/switchTouch.js +133 -0
  85. package/dist/Switch/useSwitchTouch.d.ts +285 -0
  86. package/dist/Switch/useSwitchTouch.d.ts.map +1 -0
  87. package/dist/Switch/useSwitchTouch.js +998 -0
  88. package/dist/TabList/Tab.d.ts.map +1 -1
  89. package/dist/TabList/Tab.js +4 -3
  90. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  91. package/dist/Tokenizer/Tokenizer.js +12 -5
  92. package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts +3 -0
  93. package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts.map +1 -0
  94. package/dist/Tokenizer/TokenizerItemRemovableContext.js +17 -0
  95. package/dist/Tooltip/Tooltip.d.ts +30 -6
  96. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  97. package/dist/Tooltip/Tooltip.js +5 -0
  98. package/dist/Tooltip/index.d.ts +1 -1
  99. package/dist/Tooltip/index.d.ts.map +1 -1
  100. package/dist/Tooltip/useTooltip.d.ts +31 -5
  101. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  102. package/dist/Tooltip/useTooltip.js +59 -18
  103. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  104. package/dist/Typeahead/BaseTypeahead.js +19 -9
  105. package/dist/Typeahead/Typeahead.d.ts.map +1 -1
  106. package/dist/Typeahead/Typeahead.js +26 -15
  107. package/dist/astryx.css +91 -8
  108. package/dist/gestures/GestureArena.d.ts +21 -2
  109. package/dist/gestures/GestureArena.d.ts.map +1 -1
  110. package/dist/gestures/GestureArena.js +23 -3
  111. package/dist/gestures/GestureHost.d.ts +123 -3
  112. package/dist/gestures/GestureHost.d.ts.map +1 -1
  113. package/dist/gestures/GestureHost.js +797 -15
  114. package/dist/gestures/GestureRecognizer.d.ts +15 -1
  115. package/dist/gestures/GestureRecognizer.d.ts.map +1 -1
  116. package/dist/gestures/GestureRecognizer.js +12 -0
  117. package/dist/gestures/PanGestureRecognizer.d.ts +8 -0
  118. package/dist/gestures/PanGestureRecognizer.d.ts.map +1 -1
  119. package/dist/gestures/PinchGestureRecognizer.d.ts +5 -1
  120. package/dist/gestures/PinchGestureRecognizer.d.ts.map +1 -1
  121. package/dist/gestures/PinchGestureRecognizer.js +10 -0
  122. package/dist/gestures/PressTracker.d.ts +6 -0
  123. package/dist/gestures/PressTracker.d.ts.map +1 -1
  124. package/dist/gestures/PressTracker.js +3 -0
  125. package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts +3 -3
  126. package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts.map +1 -1
  127. package/dist/gestures/ScreenEdgePanGestureRecognizer.js +7 -5
  128. package/dist/gestures/nativeScroll.d.ts +16 -2
  129. package/dist/gestures/nativeScroll.d.ts.map +1 -1
  130. package/dist/gestures/nativeScroll.js +39 -8
  131. package/dist/gestures/recognizerInternals.d.ts +4 -2
  132. package/dist/gestures/recognizerInternals.d.ts.map +1 -1
  133. package/dist/gestures/types.d.ts +17 -0
  134. package/dist/gestures/types.d.ts.map +1 -1
  135. package/dist/gestures/types.js +7 -0
  136. package/dist/gestures/usePressTracker.d.ts.map +1 -1
  137. package/dist/gestures/usePressTracker.js +1 -0
  138. package/dist/gestures/wheelSegmenter.d.ts +56 -0
  139. package/dist/gestures/wheelSegmenter.d.ts.map +1 -0
  140. package/dist/gestures/wheelSegmenter.js +122 -0
  141. package/dist/hooks/useAttachment.d.ts +16 -8
  142. package/dist/hooks/useAttachment.d.ts.map +1 -1
  143. package/dist/hooks/useAttachment.js +35 -15
  144. package/dist/hooks/useFocusTrap.d.ts +15 -0
  145. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  146. package/dist/hooks/useFocusTrap.js +13 -2
  147. package/dist/hooks/usePager.d.ts +261 -0
  148. package/dist/hooks/usePager.d.ts.map +1 -0
  149. package/dist/hooks/usePager.js +1169 -0
  150. package/dist/motion/animator.d.ts.map +1 -1
  151. package/dist/motion/animator.js +140 -19
  152. package/dist/motion/paging.d.ts +69 -0
  153. package/dist/motion/paging.d.ts.map +1 -0
  154. package/dist/motion/paging.js +148 -0
  155. package/dist/motion/uikit/index.d.ts +8 -4
  156. package/dist/motion/uikit/index.d.ts.map +1 -1
  157. package/dist/motion/uikit/index.js +8 -4
  158. package/dist/motion/uikit/paging.d.ts +171 -0
  159. package/dist/motion/uikit/paging.d.ts.map +1 -0
  160. package/dist/motion/uikit/paging.js +192 -0
  161. package/dist/motion/uikit/progressBar.d.ts +79 -0
  162. package/dist/motion/uikit/progressBar.d.ts.map +1 -0
  163. package/dist/motion/uikit/progressBar.js +102 -0
  164. package/dist/motion/uikit/scroll.d.ts +0 -19
  165. package/dist/motion/uikit/scroll.d.ts.map +1 -1
  166. package/dist/motion/uikit/scroll.js +2 -21
  167. package/dist/motion/uikit/slider.d.ts +97 -0
  168. package/dist/motion/uikit/slider.d.ts.map +1 -0
  169. package/dist/motion/uikit/slider.js +111 -0
  170. package/dist/motion/uikit/springs.d.ts +59 -30
  171. package/dist/motion/uikit/springs.d.ts.map +1 -1
  172. package/dist/motion/uikit/springs.js +64 -34
  173. package/dist/motion/uikit/switch.d.ts +166 -0
  174. package/dist/motion/uikit/switch.d.ts.map +1 -0
  175. package/dist/motion/uikit/switch.js +186 -0
  176. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts +18 -0
  177. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts.map +1 -0
  178. package/dist/privateAttributes/pressHoldsDrag.stylex.js +28 -0
  179. package/dist/utils/pressFeedback.d.ts.map +1 -1
  180. package/dist/utils/pressFeedback.js +5 -0
  181. package/dist/utils/selectionLock.d.ts +43 -0
  182. package/dist/utils/selectionLock.d.ts.map +1 -1
  183. package/dist/utils/selectionLock.js +394 -6
  184. package/package.json +5 -5
  185. package/src/AppShell/AppShell.doc.mjs +10 -0
  186. package/src/AppShell/AppShell.tsx +48 -2
  187. package/src/Avatar/Avatar.tsx +3 -1
  188. package/src/BottomSheet/BottomSheetPanel.tsx +16 -9
  189. package/src/Breadcrumbs/BreadcrumbItem.tsx +4 -1
  190. package/src/Button/Button.tsx +3 -2
  191. package/src/Chat/Chat.doc.mjs +1 -0
  192. package/src/Chat/ChatComposerInput.doc.mjs +11 -0
  193. package/src/Chat/ChatComposerInput.tsx +11 -0
  194. package/src/Chat/ChatMessage.tsx +2 -2
  195. package/src/Chat/chatMessage.vars.stylex.ts +8 -8
  196. package/src/CommandPalette/CommandPaletteInput.tsx +6 -0
  197. package/src/DateInput/MonthScroller.tsx +63 -5
  198. package/src/DateInput/Wheel.tsx +174 -14
  199. package/src/DateRangeInput/DateRangeInput.doc.mjs +3 -2
  200. package/src/DateRangeInput/DateRangeInput.tsx +117 -71
  201. package/src/Dialog/Dialog.tsx +37 -1
  202. package/src/Drawer/Drawer.tsx +6 -0
  203. package/src/Drawer/useDrawerDialogPresence.ts +4 -0
  204. package/src/DropdownMenu/DropdownMenu.tsx +28 -6
  205. package/src/DropdownMenu/useMenuOverflow.ts +44 -8
  206. package/src/Field/PanelSearchInput.tsx +6 -0
  207. package/src/Field/textEntryTraits.ts +6 -6
  208. package/src/Layer/layerClickBoundary.ts +2 -2
  209. package/src/Layer/usePressPin.ts +516 -0
  210. package/src/Layer/useTouchTrigger.ts +56 -6
  211. package/src/Lightbox/Lightbox.tsx +2 -1
  212. package/src/Link/Link.tsx +3 -0
  213. package/src/Popover/usePopover.tsx +71 -9
  214. package/src/PowerSearch/PowerSearch.tsx +38 -31
  215. package/src/ProgressBar/ProgressBar.doc.mjs +7 -5
  216. package/src/ProgressBar/ProgressBar.tsx +147 -16
  217. package/src/ProgressBar/ProgressBarTouch.ts +109 -0
  218. package/src/SegmentedControl/SegmentedControlItem.tsx +2 -1
  219. package/src/Selector/Selector.tsx +29 -2
  220. package/src/Slider/Slider.doc.mjs +11 -7
  221. package/src/Slider/Slider.tsx +539 -132
  222. package/src/Slider/sliderTouchController.ts +1209 -0
  223. package/src/Slider/useSliderTouch.ts +78 -0
  224. package/src/Switch/Switch.doc.mjs +3 -3
  225. package/src/Switch/Switch.tsx +412 -86
  226. package/src/Switch/switchFill.ts +106 -0
  227. package/src/Switch/switchTouch.ts +194 -0
  228. package/src/Switch/useSwitchTouch.ts +1121 -0
  229. package/src/TabList/Tab.tsx +5 -3
  230. package/src/Tokenizer/Tokenizer.tsx +15 -5
  231. package/src/Tokenizer/TokenizerItemRemovableContext.ts +22 -0
  232. package/src/Tooltip/Tooltip.doc.mjs +21 -6
  233. package/src/Tooltip/Tooltip.tsx +42 -5
  234. package/src/Tooltip/index.ts +1 -0
  235. package/src/Tooltip/useTooltip.doc.mjs +4 -2
  236. package/src/Tooltip/useTooltip.tsx +84 -21
  237. package/src/Typeahead/BaseTypeahead.tsx +16 -8
  238. package/src/Typeahead/Typeahead.tsx +29 -15
  239. package/src/gestures/GestureArena.ts +45 -4
  240. package/src/gestures/GestureHost.ts +958 -15
  241. package/src/gestures/GestureRecognizer.ts +28 -0
  242. package/src/gestures/PanGestureRecognizer.ts +8 -0
  243. package/src/gestures/PinchGestureRecognizer.ts +16 -1
  244. package/src/gestures/PressTracker.ts +10 -0
  245. package/src/gestures/README.md +82 -3
  246. package/src/gestures/ScreenEdgePanGestureRecognizer.ts +7 -5
  247. package/src/gestures/nativeScroll.ts +49 -9
  248. package/src/gestures/recognizerInternals.ts +9 -2
  249. package/src/gestures/types.ts +18 -0
  250. package/src/gestures/usePressTracker.ts +2 -0
  251. package/src/gestures/wheelSegmenter.ts +143 -0
  252. package/src/hooks/useAttachment.ts +56 -14
  253. package/src/hooks/useFocusTrap.ts +26 -2
  254. package/src/hooks/usePager.ts +1446 -0
  255. package/src/motion/MEASUREMENTS.md +36 -27
  256. package/src/motion/README.md +7 -3
  257. package/src/motion/animator.ts +193 -25
  258. package/src/motion/paging.ts +161 -0
  259. package/src/motion/uikit/index.ts +7 -4
  260. package/src/motion/uikit/paging.ts +193 -0
  261. package/src/motion/uikit/progressBar.ts +102 -0
  262. package/src/motion/uikit/scroll.ts +2 -18
  263. package/src/motion/uikit/slider.ts +105 -0
  264. package/src/motion/uikit/springs.ts +53 -32
  265. package/src/motion/uikit/switch.ts +174 -0
  266. package/src/privateAttributes/pressHoldsDrag.stylex.ts +28 -0
  267. package/src/utils/pressFeedback.ts +5 -0
  268. package/src/utils/selectionLock.ts +501 -6
  269. package/dist/motion/selectPage.d.ts +0 -26
  270. package/dist/motion/selectPage.d.ts.map +0 -1
  271. package/dist/motion/selectPage.js +0 -55
  272. package/src/motion/selectPage.ts +0 -55
@@ -0,0 +1,22 @@
1
+ import { type SliderTouchModel, type SliderTouchParts } from './sliderTouchController.js';
2
+ export type { SliderTouchModel, SliderTouchParts } from './sliderTouchController.js';
3
+ export interface UseSliderTouchOptions {
4
+ /** The slider is enabled: its gestures attach for every pointer. */
5
+ readonly isEnabled: boolean;
6
+ readonly model: SliderTouchModel;
7
+ readonly getParts: () => SliderTouchParts | null;
8
+ /** Re-attaches when the thumbs or the orientation change. */
9
+ readonly thumbCount: number;
10
+ /**
11
+ * Whether each thumb renders inside its value tooltip: changing it mounts
12
+ * new thumbs. So the gestures re-attach.
13
+ */
14
+ readonly thumbsWrapped: boolean;
15
+ }
16
+ /**
17
+ * Wires UISlider's tracking to a rendered Slider for every pointer, while it
18
+ * is enabled. Slider's own pointer handlers then take only a mouse press on
19
+ * the track.
20
+ */
21
+ export declare function useSliderTouch({ isEnabled, model, getParts, thumbCount, thumbsWrapped, }: UseSliderTouchOptions): void;
22
+ //# sourceMappingURL=useSliderTouch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSliderTouch.d.ts","sourceRoot":"","sources":["../../src/Slider/useSliderTouch.ts"],"names":[],"mappings":"AAoBA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EAAC,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,yBAAyB,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACpC,oEAAoE;IACpE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,gBAAgB,GAAG,IAAI,CAAC;IACjD,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAC7B,SAAS,EACT,KAAK,EACL,QAAQ,EACR,UAAU,EACV,aAAa,GACd,EAAE,qBAAqB,GAAG,IAAI,CAwB9B"}
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file useSliderTouch.ts
7
+ * @input Slider's value model and parts, and sliderTouchController.ts
8
+ * @output Exports `useSliderTouch` (the React wiring) and the
9
+ * `SliderTouchModel` and `SliderTouchParts` types
10
+ * @position Internal to Slider. It is the touch layer's one import site, so
11
+ * a desktop build can swap that module whole.
12
+ *
13
+ * SYNC: When modified, update:
14
+ * - /packages/core/src/Slider/sliderTouchController.ts
15
+ * - /packages/core/src/Slider/Slider.tsx (the model and the parts)
16
+ * - /packages/core/src/Slider/useSliderTouch.test.tsx
17
+ */
18
+ import { useEffect, useState } from 'react';
19
+ import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect.js";
20
+ import { SliderTouchController } from "./sliderTouchController.js";
21
+ /**
22
+ * Wires UISlider's tracking to a rendered Slider for every pointer, while it
23
+ * is enabled. Slider's own pointer handlers then take only a mouse press on
24
+ * the track.
25
+ */
26
+ export function useSliderTouch({
27
+ isEnabled,
28
+ model,
29
+ getParts,
30
+ thumbCount,
31
+ thumbsWrapped
32
+ }) {
33
+ // The parts getter reads only refs. So the first one stays current.
34
+ const [controller] = useState(() => new SliderTouchController(model, getParts));
35
+ // Hands the controller this render's model: the values and callbacks it
36
+ // reads from gesture callbacks outside React's render.
37
+ useIsomorphicLayoutEffect(() => {
38
+ controller.setModel(model);
39
+ });
40
+ const {
41
+ isHorizontal
42
+ } = model;
43
+ // Synchronizes the thumbs with the document's gesture host. Their
44
+ // PressTrackers and pans attach while the slider is enabled. They detach,
45
+ // ending any interaction silently, when it is disabled or the thumbs
46
+ // change.
47
+ useEffect(() => {
48
+ if (!isEnabled) {
49
+ return undefined;
50
+ }
51
+ return controller.attach();
52
+ }, [controller, isEnabled, thumbCount, isHorizontal, thumbsWrapped]);
53
+ // Releases the controller's animators and gesture host listeners on
54
+ // unmount.
55
+ useEffect(() => () => controller.dispose(), [controller]);
56
+ }
@@ -135,7 +135,7 @@ export interface SwitchProps extends Omit<BaseProps, 'onChange'> {
135
135
  status?: InputStatus;
136
136
  /**
137
137
  * Size variant controlling track and thumb dimensions.
138
- * - 'sm': 34x20px (matches sm checkbox/radio vertical rhythm)
138
+ * - 'sm': 32x20px (matches sm checkbox/radio vertical rhythm)
139
139
  * - 'md': 40x24px (default, matches md checkbox/radio vertical rhythm)
140
140
  * @default 'md'
141
141
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../src/Switch/Switch.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAcf,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAMhD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AA0V9C,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,KAAK,CAAC;AAElD,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAElD,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;IAC9D,wCAAwC;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAClC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACxE;;OAEG;IACH,YAAY,CAAC,EAAE,CACb,OAAO,EAAE,OAAO,EAChB,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAC7B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,O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MAAM,EACN,IAAW,EACX,KAAK,EACL,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,kBAAkB,EAAE,mBAAmB,EACvC,iBAAiB,EAAE,kBAAkB,EACrC,GAAG,IAAI,EACR,EAAE,WAAW,+BA+Rb;yBA5Te,MAAM"}
@@ -15,10 +15,10 @@
15
15
  * - /apps/storybook/stories/Switch.stories.tsx (storybook stories)
16
16
  * - /packages/cli/assets/templates/blocks/components/Switch/ (showcase blocks)
17
17
  */
18
- import { useId, useOptimistic, useTransition, useEffect, useRef } from 'react';
18
+ import { Fragment, useId, useMemo, useOptimistic, useTransition, useEffect, useRef } from 'react';
19
19
  import * as stylex from '@stylexjs/stylex';
20
20
  import "../theme/tokens.stylex.js";
21
- import { colorVars, spacingVars, radiusVars, durationVars, easeVars, typographyVars, typeScaleVars, focusVars } from "../theme/tokens.stylex.js";
21
+ import { colorVars, spacingVars, radiusVars, durationVars, easeVars, typographyVars, typeScaleVars, focusVars, shadowVars } from "../theme/tokens.stylex.js";
22
22
  import { FieldLabel } from "../Field/FieldLabel.js";
23
23
  import { FieldStatus } from "../FieldStatus/FieldStatus.js";
24
24
  import { Spinner } from "../Spinner/index.js";
@@ -26,7 +26,6 @@ import { useTooltip } from "../Tooltip/index.js";
26
26
  import { mergeProps, rtlStyles } from "../utils/index.js";
27
27
  import "./switch.markers.stylex.js";
28
28
  import { switchFocusInput, switchScope } from "./switch.markers.stylex.js";
29
- import { interactionOverlayStyles } from "../utils/interactionOverlay.stylex.js";
30
29
  import { themeProps } from "../utils/themeProps.js";
31
30
  import { useAnnounce } from "../hooks/useAnnounce.js";
32
31
  import { useResolvedRequired } from "../hooks/useResolvedRequired.js";
@@ -34,21 +33,54 @@ import { useMergedRefs } from "../hooks/useMergedRefs.js";
34
33
  import { usePressFeedback } from "../hooks/usePressFeedback.js";
35
34
  import { registerEnglishFallback, useComponentTranslator } from "../i18n/useComponentTranslator.js";
36
35
  import english from "../i18n/generated-english/Switch/Switch.generated.js";
37
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
38
36
  registerEnglishFallback(english);
39
- const wrapperSizeStyles = {
40
- sm: {
41
- kzqmXN: "x1td3qas",
42
- kZKoxP: "x1qx5ct2",
43
- $$css: true
44
- },
45
- md: {
46
- kzqmXN: "x100vrsf",
47
- kZKoxP: "xxk0z11",
48
- $$css: true
49
- }
37
+ import "../utils/interactionOverlay.stylex.js";
38
+ import { interactionOverlayStyles, pressConsts, pressVars } from "../utils/interactionOverlay.stylex.js";
39
+ import { pressHoldsDragProps } from "../privateAttributes/pressHoldsDrag.stylex.js";
40
+ import { useSwitchTouch } from "./useSwitchTouch.js";
41
+ import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect.js";
42
+ import { watchHitArea, writeHitInsets } from "../utils/hitArea.js";
43
+
44
+ /**
45
+ * The track box of each size, px (width × height), for the touch
46
+ * presentation's thumb geometry.
47
+ * SYNC: wrapperSizeStyles and trackSizeStyles below.
48
+ */
49
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
50
+ const TRACK_SIZE = {
51
+ sm: [32, 20],
52
+ md: [40, 24]
50
53
  };
51
- const inputSizeStyles = {
54
+
55
+ /**
56
+ * A finger: utils/touchPresentation.ts's TOUCH_QUERY. The touch presentation
57
+ * is one model on every touch device: the lift, tracking, flip rule and
58
+ * springs sit under it alone.
59
+ * SYNC: utils/touchPresentation.ts TOUCH_QUERY.
60
+ */
61
+ const TOUCH = '@media (pointer: coarse)';
62
+
63
+ /** The press controller's two states on the row it writes to. */
64
+ const PRESS_ON = '[data-astryx-press="on"]';
65
+ const PRESS_FADING = '[data-astryx-press="fading"]';
66
+
67
+ /**
68
+ * The shared press release, for the press layers the switch fades on the
69
+ * compositor. The clock scales by the theme's tempo, and the curve is the
70
+ * controller's own. Switch.test.tsx compares the two.
71
+ * SYNC: utils/interactionOverlay.stylex.ts PRESS_RELEASE_DURATION,
72
+ * PRESS_RELEASE_DURATION_REDUCED and RELEASE_EASE.
73
+ */
74
+ const PRESS_RELEASE_DURATION = `calc(${pressConsts.releaseMs}ms * min(var(--_astryx-motion-tempo, 1), 1.5))`;
75
+ const PRESS_RELEASE_DURATION_REDUCED = `min(${pressConsts.releaseMs}ms, calc(${pressConsts.releaseMs}ms * var(--_astryx-motion-tempo, 1)))`;
76
+ const PRESS_RELEASE_EASE = 'cubic-bezier(0, 0, 0.2, 1)';
77
+
78
+ // The measured hit insets (utils/hitArea), 0 until measured.
79
+ const HIT_TOP = 'var(--astryx-hit-inset-top, 0px)';
80
+ const HIT_RIGHT = 'var(--astryx-hit-inset-right, 0px)';
81
+ const HIT_BOTTOM = 'var(--astryx-hit-inset-bottom, 0px)';
82
+ const HIT_LEFT = 'var(--astryx-hit-inset-left, 0px)';
83
+ const wrapperSizeStyles = {
52
84
  sm: {
53
85
  kzqmXN: "x1td3qas",
54
86
  kZKoxP: "x1qx5ct2",
@@ -60,6 +92,10 @@ const inputSizeStyles = {
60
92
  $$css: true
61
93
  }
62
94
  };
95
+
96
+ // Every touch value sits in the same property as the mouse value, as a
97
+ // nested condition, never in a later style. A later style that names a
98
+ // property replaces all of it, mouse value included.
63
99
  const trackSizeStyles = {
64
100
  sm: {
65
101
  kzqmXN: "x1td3qas",
@@ -74,17 +110,24 @@ const trackSizeStyles = {
74
110
  $$css: true
75
111
  }
76
112
  };
113
+
114
+ // The thumb is one circle under any pointer, at each state's size. Under a
115
+ // finger it rests by insets instead of a transform, centered in the track's
116
+ // height at each end. So the compositor moves and lifts it with translate and
117
+ // scale alone; useSwitchTouch measures the box it renders.
77
118
  const thumbOffSizeStyles = {
78
119
  sm: {
79
120
  kzqmXN: "x6jxa94",
80
121
  kZKoxP: "x1v9usgg",
81
- k3aq6I: "xbryuvx",
122
+ kLqNvP: "x13kxlb5",
123
+ k3aq6I: "xbryuvx xhyyqqw",
82
124
  $$css: true
83
125
  },
84
126
  md: {
85
127
  kzqmXN: "x1kky2od",
86
128
  kZKoxP: "xlup9mm",
87
- k3aq6I: "xbryuvx",
129
+ kLqNvP: "xsprn4g",
130
+ k3aq6I: "xbryuvx xhyyqqw",
88
131
  $$css: true
89
132
  }
90
133
  };
@@ -92,13 +135,17 @@ const thumbOnSizeStyles = {
92
135
  sm: {
93
136
  kzqmXN: "x1kky2od",
94
137
  kZKoxP: "xlup9mm",
95
- k3aq6I: "xv5t66b xi9aj42",
138
+ kLqNvP: "xskqmzm",
139
+ kt4wiu: "x1syr3z6",
140
+ k3aq6I: "xv5t66b xi9aj42 x1pxz8w1 xhyyqqw",
96
141
  $$css: true
97
142
  },
98
143
  md: {
99
144
  kzqmXN: "xw4jnvo",
100
145
  kZKoxP: "x1qx5ct2",
101
- k3aq6I: "x15481yp x12xz5k6",
146
+ kLqNvP: "xskqmzm",
147
+ kt4wiu: "x1syr3z6",
148
+ k3aq6I: "x15481yp x12xz5k6 x1pxz8w1 xhyyqqw",
102
149
  $$css: true
103
150
  }
104
151
  };
@@ -111,11 +158,22 @@ const thumbOnSizeStyles = {
111
158
  // hover tint already is: pressing the input, the track or the label all
112
159
  // activate the row.
113
160
  const pressedImage = `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`;
114
- // The touch press's paint, declared by the shared overlay styles on the
115
- // element the controller writes to (`pressedAlpha`) at the press's strength,
116
- // 1 while on and 1 → 0 over the release, and inherited resolved by the layer
117
- // that paints it. See interactionOverlay.stylex.ts.
118
- const pressedOverlayImage = 'var(--_press-paint-image)';
161
+
162
+ /** The touch press's release on the press layer: opacity 1 → 0. */
163
+ const pressLayerRelease = "x1jn504y-B";
164
+ const PRESS_ALPHA = pressVars['--astryx-press-alpha'];
165
+
166
+ /**
167
+ * The shared strength's release, restated so a fine pointer keeps it: the
168
+ * same keyframes, so the same animation.
169
+ */
170
+ const pressStrengthRelease = "x10jkm1t-B";
171
+ const pressOwnerStyles = {
172
+ pressedAlphaLayered: {
173
+ kKVMdj: "x14e4jsf xxsp3er x6su2wr",
174
+ $$css: true
175
+ }
176
+ };
119
177
  const labelWrapperSizeStyles = {
120
178
  sm: {
121
179
  kAzted: "xisnujt",
@@ -154,6 +212,10 @@ const styles = {
154
212
  kHBbk8: "xc8icb0",
155
213
  $$css: true
156
214
  },
215
+ switchWrapperInteractive: {
216
+ kFalU9: "xge0x1e",
217
+ $$css: true
218
+ },
157
219
  input: {
158
220
  kVAEAm: "x10l6tqk",
159
221
  k87sOh: "xwa60dl",
@@ -165,8 +227,9 @@ const styles = {
165
227
  $$css: true
166
228
  },
167
229
  inputCoarse: {
168
- kjFi6P: "xkagaj0",
169
- kHzOjL: "x80b3aj",
230
+ kzqmXN: "xh8yej3 x1uj43hb",
231
+ kZKoxP: "x5yr21d xgjkl26",
232
+ k3aq6I: "x11lhmoz x1xdvw9q",
170
233
  $$css: true
171
234
  },
172
235
  inputDisabled: {
@@ -180,15 +243,39 @@ const styles = {
180
243
  track: {
181
244
  k1xSpc: "x78zum5",
182
245
  kGNEyG: "x6s0dn4",
246
+ kVAEAm: "xrxqdxo",
247
+ kHBbk8: "xsmms64",
183
248
  kaIpWk: "xjspbzw",
184
249
  k1ekBW: "x15406qy",
185
- kIyJzY: "xuedmi6 x12w9bfk",
250
+ kIyJzY: "xuedmi6 xouc37c xzwa1y6 xuh6ohu",
186
251
  kAMwcw: "xlr8y92",
187
252
  kB7OPa: "x9f619",
188
253
  kMzoRj: "xc342km x13rsnn2",
189
254
  ksu8eU: "xng3xce xx61lck",
190
255
  kVAM5u: "x1w1tqly",
191
- kKwaWg: "x1xm682w xowtp19 xphwcek x1p4304o",
256
+ kKwaWg: "x1xm682w xowtp19",
257
+ kgeoSG: "xpxppvc x15cra4q",
258
+ kEoFBp: "x1hmns74",
259
+ kFcpXp: "xxx281p",
260
+ kxmVGU: "x12maryy",
261
+ kPB484: "xxyica1",
262
+ km8f2m: "xkk1bqk",
263
+ kLkRvE: "x1my3e5g",
264
+ k5QlbN: "x2huugr x1ccaw7f",
265
+ k7EzDT: "xxhzo2e",
266
+ kQZAMR: "xvym4rz xigdn9b",
267
+ kZiNAr: "xgq6fxe",
268
+ k8Tatv: "xq2jpp1",
269
+ k5JduY: "x1s928wv",
270
+ kc3QkE: "x1h1zc6f x1ep27e9",
271
+ kwXMNM: "x1j6awrg",
272
+ kv0HGH: "xarstr8",
273
+ kDVEDD: "x1r0yslu",
274
+ kUfP38: "x1k48kgn",
275
+ kloYau: "x2q1x1w",
276
+ kypkao: "xmf22ne",
277
+ ks3ayO: "x1uc2128",
278
+ kWkaDd: "xqycr0j",
192
279
  $$css: true
193
280
  },
194
281
  trackFocus: {
@@ -218,10 +305,35 @@ const styles = {
218
305
  kGNEyG: "x6s0dn4",
219
306
  kjj79g: "xl56j7k",
220
307
  kaIpWk: "xjspbzw",
221
- k1ekBW: "xh3q6i0",
222
- kIyJzY: "xuedmi6 x12w9bfk",
308
+ kVAEAm: "x8imsj1",
309
+ kYYq5F: "x1s6gw0t",
310
+ kqGvvJ: "xfmjvo4",
311
+ kY2c9j: "x1e8ofxz",
312
+ kfzvcC: "x1bjav06",
313
+ k1ekBW: "xh3q6i0 xiz4dsw",
314
+ kIyJzY: "xuedmi6 xzwa1y6 xuh6ohu",
223
315
  kAMwcw: "xlr8y92",
224
- kKwaWg: "x1xm682w xowtp19 xphwcek x1p4304o",
316
+ kgeoSG: "xpxppvc x15cra4q",
317
+ kEoFBp: "x1hmns74",
318
+ kFcpXp: "xxx281p",
319
+ kPB484: "xxyica1",
320
+ km8f2m: "xkk1bqk",
321
+ kLkRvE: "x1my3e5g",
322
+ k5QlbN: "x2huugr x1ccaw7f",
323
+ k7EzDT: "xxhzo2e",
324
+ kQZAMR: "xvym4rz xigdn9b",
325
+ kZiNAr: "xgq6fxe",
326
+ k8Tatv: "xq2jpp1",
327
+ k5JduY: "x1s928wv",
328
+ kc3QkE: "x1h1zc6f x1ep27e9",
329
+ kwXMNM: "x1j6awrg",
330
+ kv0HGH: "xarstr8",
331
+ kUfP38: "x1k48kgn",
332
+ kloYau: "x2q1x1w",
333
+ kypkao: "xmf22ne",
334
+ kbMawA: "xoca22b",
335
+ kWkaDd: "xqycr0j",
336
+ kKwaWg: "x1xm682w xowtp19",
225
337
  $$css: true
226
338
  },
227
339
  thumbOff: {
@@ -365,10 +477,49 @@ export function Switch({
365
477
  describedByParts.push(disabledMessageTooltip.describedBy);
366
478
  }
367
479
  const ariaDescribedBy = describedByParts.length > 0 ? describedByParts.join(' ') : undefined;
480
+
481
+ // The touch presentation (coarse pointer): its parts are always rendered;
482
+ // CSS shows them under a finger and the hook animates and listens there.
483
+ const surfaceRef = useRef(null);
484
+ const inputRef = useRef(null);
485
+ const thumbRef = useRef(null);
486
+ const trackRef = useRef(null);
487
+ const touchParts = useMemo(() => ({
488
+ surface: surfaceRef,
489
+ input: inputRef,
490
+ thumb: thumbRef,
491
+ track: trackRef
492
+ }), []);
493
+ // The track in a state: its theme target and fill. The other state's, for
494
+ // the fade layer's colour (switchFill.ts).
495
+ const trackPropsFor = on => mergeProps(themeProps('switch', {
496
+ checked: on ? 'checked' : null,
497
+ disabled: isDisabled ? 'disabled' : null,
498
+ size
499
+ }), stylex.props(styles.track, trackSizeStyles[size], on ? styles.trackOn : styles.trackOff, styles.trackFocus, isDisabled && styles.trackDisabled, isDisabled && !on && styles.trackDisabledOff));
500
+ // Syncs the hit area's insets with the layout around the switch, through
501
+ // utils/hitArea's observers. Under a coarse pointer they grow toward 44 px,
502
+ // stopping at half the gap to each neighbouring target. A disabled switch
503
+ // watches nothing.
504
+ useIsomorphicLayoutEffect(() => {
505
+ const surface = surfaceRef.current;
506
+ if (surface == null || isDisabled) {
507
+ return;
508
+ }
509
+ return watchHitArea(surface, insets => writeHitInsets(surface, insets));
510
+ }, [isDisabled]);
511
+ useSwitchTouch(touchParts, {
512
+ isOn,
513
+ isInteractive: !isDisabled && !isBusy,
514
+ isDisabled,
515
+ trackSize: TRACK_SIZE[size],
516
+ otherTrackProps: trackPropsFor(!isOn)
517
+ });
368
518
  const switchElement = /*#__PURE__*/_jsxs("div", {
369
- ...stylex.props(styles.switchWrapper, wrapperSizeStyles[size]),
519
+ ref: surfaceRef,
520
+ ...stylex.props(styles.switchWrapper, wrapperSizeStyles[size], !isDisabled && !isBusy && styles.switchWrapperInteractive),
370
521
  children: [/*#__PURE__*/_jsx("input", {
371
- ref: useMergedRefs(ref, disabledMessageTooltip.positionRef),
522
+ ref: useMergedRefs(ref, disabledMessageTooltip.positionRef, inputRef),
372
523
  id: id,
373
524
  type: "checkbox",
374
525
  role: "switch"
@@ -409,15 +560,13 @@ export function Switch({
409
560
  ,
410
561
  "aria-invalid": status?.type === 'error' ? true : isRequired ? false : undefined,
411
562
  "aria-busy": isBusy || undefined,
412
- ...stylex.props(styles.input, rtlStyles.centerInline('-50%'), styles.inputCoarse, inputSizeStyles[size], isDisabled && styles.inputDisabled, isBusy && styles.inputBusy, switchFocusInput)
563
+ ...stylex.props(styles.input, rtlStyles.centerInline('-50%'), styles.inputCoarse, isDisabled && styles.inputDisabled, isBusy && styles.inputBusy, switchFocusInput)
413
564
  }), /*#__PURE__*/_jsx("div", {
565
+ ref: trackRef,
414
566
  "aria-hidden": "true",
415
- ...mergeProps(themeProps('switch', {
416
- checked: isOn ? 'checked' : null,
417
- disabled: isDisabled ? 'disabled' : null,
418
- size
419
- }), stylex.props(styles.track, trackSizeStyles[size], isOn ? styles.trackOn : styles.trackOff, styles.trackFocus, isDisabled && styles.trackDisabled, isDisabled && !isOn && styles.trackDisabledOff)),
567
+ ...trackPropsFor(isOn),
420
568
  children: /*#__PURE__*/_jsx("div", {
569
+ ref: thumbRef,
421
570
  ...mergeProps(themeProps('switch-thumb', {
422
571
  checked: isOn ? 'checked' : null,
423
572
  size
@@ -470,15 +619,20 @@ export function Switch({
470
619
  disabledMessageTooltip.interactionRef(el);
471
620
  },
472
621
  ...(isDisabled ? undefined : pressable),
622
+ ...pressHoldsDragProps(!isDisabled),
473
623
  ...stylex.props(styles.container, isLabelHidden && styles.containerLabelHidden, labelSpacing === 'spread' && styles.containerSpread, !isDisabled && switchScope,
474
624
  // The touch press's strength and release live on the row the
475
625
  // controller writes to; the track and thumb inherit and paint it.
476
- !isDisabled && interactionOverlayStyles.pressedAlpha),
477
- children: [' ', labelPosition === 'start' ? /*#__PURE__*/_jsxs(_Fragment, {
478
- children: [labelElement, switchElement]
479
- }) : /*#__PURE__*/_jsxs(_Fragment, {
480
- children: [switchElement, labelElement]
481
- })]
626
+ !isDisabled && interactionOverlayStyles.pressedAlpha, !isDisabled && pressOwnerStyles.pressedAlphaLayered),
627
+ children: [' ', labelPosition === 'start' ? [/*#__PURE__*/_jsx(Fragment, {
628
+ children: labelElement
629
+ }, "label"), /*#__PURE__*/_jsx(Fragment, {
630
+ children: switchElement
631
+ }, "switch")] : [/*#__PURE__*/_jsx(Fragment, {
632
+ children: switchElement
633
+ }, "switch"), /*#__PURE__*/_jsx(Fragment, {
634
+ children: labelElement
635
+ }, "label")]]
482
636
  }), status?.message && /*#__PURE__*/_jsx(FieldStatus, {
483
637
  type: status.type,
484
638
  message: status.message,
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file switchFill.ts
3
+ * @input Switch's track element and the props its other state renders with
4
+ * @output Exports TrackState, sameTrackState, trackStateOf, readInState and
5
+ * readFillOf: an element read in its other state, in place
6
+ * @position Shared by Switch.tsx and useSwitchTouch.ts for the colour fade
7
+ * under a finger
8
+ *
9
+ * The colour fade needs the track's fill in its other state, as the theme
10
+ * paints it. readFillOf swaps the track's class and attributes, reads the
11
+ * colour and swaps back in the same task, so nothing paints in between.
12
+ *
13
+ * SYNC: When modified, update Switch.tsx and useSwitchTouch.ts.
14
+ */
15
+ /** A track state: its class name and its data attributes. */
16
+ export interface TrackState {
17
+ readonly className: string;
18
+ readonly attributes: Readonly<Record<string, string>>;
19
+ }
20
+ /** Whether two track states render alike: the same class and attributes. */
21
+ export declare function sameTrackState(a: TrackState | null, b: TrackState | null): boolean;
22
+ /** The track state of rendered props (`className` and `data-*` props). */
23
+ export declare function trackStateOf(props: object): TrackState;
24
+ /**
25
+ * Reads `element` as it renders in `state` (its class and data attributes),
26
+ * swapping them in and back in the same task, so nothing paints between.
27
+ */
28
+ export declare function readInState<T>(element: HTMLElement, state: TrackState, read: (element: HTMLElement) => T): T;
29
+ /** The track's computed fill in `state`, read without a paint. */
30
+ export declare function readFillOf(track: HTMLElement, state: TrackState): string;
31
+ //# sourceMappingURL=switchFill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchFill.d.ts","sourceRoot":"","sources":["../../src/Switch/switchFill.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAC5B,CAAC,EAAE,UAAU,GAAG,IAAI,EACpB,CAAC,EAAE,UAAU,GAAG,IAAI,GACnB,OAAO,CAYT;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAYtD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,GAChC,CAAC,CAgCH;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAMxE"}
@@ -0,0 +1,88 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file switchFill.ts
5
+ * @input Switch's track element and the props its other state renders with
6
+ * @output Exports TrackState, sameTrackState, trackStateOf, readInState and
7
+ * readFillOf: an element read in its other state, in place
8
+ * @position Shared by Switch.tsx and useSwitchTouch.ts for the colour fade
9
+ * under a finger
10
+ *
11
+ * The colour fade needs the track's fill in its other state, as the theme
12
+ * paints it. readFillOf swaps the track's class and attributes, reads the
13
+ * colour and swaps back in the same task, so nothing paints in between.
14
+ *
15
+ * SYNC: When modified, update Switch.tsx and useSwitchTouch.ts.
16
+ */
17
+
18
+ /** A track state: its class name and its data attributes. */
19
+
20
+ /** Whether two track states render alike: the same class and attributes. */
21
+ export function sameTrackState(a, b) {
22
+ if (a === b) {
23
+ return true;
24
+ }
25
+ if (a == null || b == null || a.className !== b.className) {
26
+ return false;
27
+ }
28
+ const names = Object.keys(a.attributes);
29
+ return names.length === Object.keys(b.attributes).length && names.every(name => a.attributes[name] === b.attributes[name]);
30
+ }
31
+
32
+ /** The track state of rendered props (`className` and `data-*` props). */
33
+ export function trackStateOf(props) {
34
+ const attributes = {};
35
+ let className = '';
36
+ for (const [name, value] of Object.entries(props)) {
37
+ if (name === 'className' && typeof value === 'string') {
38
+ className = value;
39
+ } else if (name.startsWith('data-') && value != null) {
40
+ // As React writes a data attribute: every value but null or undefined.
41
+ attributes[name] = String(value);
42
+ }
43
+ }
44
+ return {
45
+ className,
46
+ attributes
47
+ };
48
+ }
49
+
50
+ /**
51
+ * Reads `element` as it renders in `state` (its class and data attributes),
52
+ * swapping them in and back in the same task, so nothing paints between.
53
+ */
54
+ export function readInState(element, state, read) {
55
+ const names = new Set(Object.keys(state.attributes));
56
+ for (const attribute of Array.from(element.attributes)) {
57
+ if (attribute.name.startsWith('data-')) {
58
+ names.add(attribute.name);
59
+ }
60
+ }
61
+ const savedClass = element.className;
62
+ const saved = new Map();
63
+ for (const name of names) {
64
+ saved.set(name, element.getAttribute(name));
65
+ }
66
+ const apply = (className, valueOf) => {
67
+ element.className = className;
68
+ for (const name of names) {
69
+ const value = valueOf(name);
70
+ if (value == null) {
71
+ element.removeAttribute(name);
72
+ } else {
73
+ element.setAttribute(name, value);
74
+ }
75
+ }
76
+ };
77
+ apply(state.className, name => state.attributes[name] ?? null);
78
+ try {
79
+ return read(element);
80
+ } finally {
81
+ apply(savedClass, name => saved.get(name) ?? null);
82
+ }
83
+ }
84
+
85
+ /** The track's computed fill in `state`, read without a paint. */
86
+ export function readFillOf(track, state) {
87
+ return readInState(track, state, element => getComputedStyle(element).backgroundColor);
88
+ }