@astryxdesign/core 0.7.7-canary.550ff21 → 0.7.7-canary.58c5b8a

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 (504) hide show
  1. package/dist/AlertDialog/AlertDialog.d.ts +4 -1
  2. package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
  3. package/dist/AlertDialog/AlertDialog.js +36 -6
  4. package/dist/AppShell/useCloseMobileDrawerOnActivate.d.ts +13 -0
  5. package/dist/AppShell/useCloseMobileDrawerOnActivate.d.ts.map +1 -0
  6. package/dist/AppShell/useCloseMobileDrawerOnActivate.js +45 -0
  7. package/dist/Avatar/Avatar.d.ts.map +1 -1
  8. package/dist/Avatar/Avatar.js +1 -1
  9. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  10. package/dist/BottomSheet/BottomSheet.js +79 -9
  11. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  12. package/dist/BottomSheet/BottomSheetPanel.js +23 -4
  13. package/dist/BottomSheet/bottomSheetStack.d.ts.map +1 -1
  14. package/dist/BottomSheet/bottomSheetStack.js +5 -4
  15. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  16. package/dist/BottomSheet/useSheetGestures.js +3 -1
  17. package/dist/Breadcrumbs/BreadcrumbItem.d.ts +2 -1
  18. package/dist/Breadcrumbs/BreadcrumbItem.d.ts.map +1 -1
  19. package/dist/Breadcrumbs/BreadcrumbItem.js +9 -4
  20. package/dist/Button/Button.d.ts.map +1 -1
  21. package/dist/Button/Button.js +50 -5
  22. package/dist/CheckboxList/CheckboxList.d.ts.map +1 -1
  23. package/dist/CheckboxList/CheckboxList.js +7 -1
  24. package/dist/CheckboxList/CheckboxListContext.d.ts +6 -0
  25. package/dist/CheckboxList/CheckboxListContext.d.ts.map +1 -1
  26. package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
  27. package/dist/CheckboxList/CheckboxListItem.js +10 -2
  28. package/dist/ComplexSelector/ComplexSelector.d.ts +4 -1
  29. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  30. package/dist/ComplexSelector/ComplexSelector.js +14 -4
  31. package/dist/DateInput/DateInput.d.ts.map +1 -1
  32. package/dist/DateInput/DateInput.js +5 -2
  33. package/dist/DateInput/MonthScroller.d.ts.map +1 -1
  34. package/dist/DateInput/MonthScroller.js +13 -27
  35. package/dist/DateInput/Wheel.d.ts +17 -1
  36. package/dist/DateInput/Wheel.d.ts.map +1 -1
  37. package/dist/DateInput/Wheel.js +161 -20
  38. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  39. package/dist/DateRangeInput/DateRangeInput.js +63 -49
  40. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  41. package/dist/DateTimeInput/DateTimeInput.js +5 -2
  42. package/dist/Dialog/Dialog.d.ts.map +1 -1
  43. package/dist/Dialog/Dialog.js +53 -15
  44. package/dist/Drawer/Drawer.d.ts.map +1 -1
  45. package/dist/Drawer/Drawer.js +15 -11
  46. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
  47. package/dist/Drawer/useDrawerDialogPresence.js +9 -1
  48. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  49. package/dist/DropdownMenu/DropdownMenu.js +20 -4
  50. package/dist/Field/Field.js +2 -2
  51. package/dist/Field/PanelSearchInput.d.ts +9 -1
  52. package/dist/Field/PanelSearchInput.d.ts.map +1 -1
  53. package/dist/Field/PanelSearchInput.js +3 -1
  54. package/dist/HoverCard/HoverCard.d.ts.map +1 -1
  55. package/dist/HoverCard/HoverCard.js +27 -2
  56. package/dist/Icon/Icon.d.ts +5 -1
  57. package/dist/Icon/Icon.d.ts.map +1 -1
  58. package/dist/Icon/Icon.js +5 -2
  59. package/dist/InfoTip/InfoTip.d.ts +63 -0
  60. package/dist/InfoTip/InfoTip.d.ts.map +1 -0
  61. package/dist/InfoTip/InfoTip.js +126 -0
  62. package/dist/InfoTip/index.d.ts +10 -0
  63. package/dist/InfoTip/index.d.ts.map +1 -0
  64. package/dist/InfoTip/index.js +12 -0
  65. package/dist/Layer/layerAnimations.stylex.d.ts +7 -8
  66. package/dist/Layer/layerAnimations.stylex.d.ts.map +1 -1
  67. package/dist/Layer/layerAnimations.stylex.js +25 -20
  68. package/dist/Layer/layerClickBoundary.d.ts +7 -1
  69. package/dist/Layer/layerClickBoundary.d.ts.map +1 -1
  70. package/dist/Layer/layerClickBoundary.js +2 -2
  71. package/dist/Layer/useBackdropPress.d.ts +27 -0
  72. package/dist/Layer/useBackdropPress.d.ts.map +1 -0
  73. package/dist/Layer/useBackdropPress.js +53 -0
  74. package/dist/Layer/usePressPin.d.ts +105 -0
  75. package/dist/Layer/usePressPin.d.ts.map +1 -0
  76. package/dist/Layer/usePressPin.js +413 -0
  77. package/dist/Layer/useTouchTrigger.d.ts +23 -1
  78. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  79. package/dist/Layer/useTouchTrigger.js +45 -7
  80. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  81. package/dist/Lightbox/Lightbox.js +2 -1
  82. package/dist/MobileNav/MobileNav.js +0 -1
  83. package/dist/MultiSelector/hooks.d.ts.map +1 -1
  84. package/dist/MultiSelector/hooks.js +2 -4
  85. package/dist/Outline/Outline.d.ts +2 -4
  86. package/dist/Outline/Outline.d.ts.map +1 -1
  87. package/dist/Outline/Outline.js +4 -52
  88. package/dist/Outline/useOutlineFromMarkdown.d.ts.map +1 -1
  89. package/dist/Outline/useOutlineFromMarkdown.js +1 -0
  90. package/dist/Outline/useScrollSpy.js +3 -3
  91. package/dist/Popover/usePopover.d.ts.map +1 -1
  92. package/dist/Popover/usePopover.js +56 -7
  93. package/dist/PowerSearch/PowerSearch.d.ts +36 -3
  94. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  95. package/dist/PowerSearch/PowerSearch.js +571 -302
  96. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +100 -0
  97. package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -0
  98. package/dist/PowerSearch/PowerSearchBottomSheet.js +1913 -0
  99. package/dist/PowerSearch/PowerSearchEditPopover.d.ts +32 -1
  100. package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
  101. package/dist/PowerSearch/PowerSearchEditPopover.js +17 -6
  102. package/dist/PowerSearch/PowerSearchValueEditor.d.ts +38 -3
  103. package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
  104. package/dist/PowerSearch/PowerSearchValueEditor.js +170 -61
  105. package/dist/PowerSearch/formatFilterValue.d.ts +7 -0
  106. package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
  107. package/dist/PowerSearch/formatFilterValue.js +11 -1
  108. package/dist/PowerSearch/formatTokenValue.d.ts +28 -0
  109. package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -0
  110. package/dist/PowerSearch/formatTokenValue.js +160 -0
  111. package/dist/PowerSearch/powerSearchSheetUtils.d.ts +65 -0
  112. package/dist/PowerSearch/powerSearchSheetUtils.d.ts.map +1 -0
  113. package/dist/PowerSearch/powerSearchSheetUtils.js +168 -0
  114. package/dist/ProgressBar/ProgressBar.d.ts +1 -1
  115. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  116. package/dist/ProgressBar/ProgressBar.js +33 -6
  117. package/dist/RadioList/RadioList.d.ts.map +1 -1
  118. package/dist/RadioList/RadioList.js +8 -2
  119. package/dist/RadioList/RadioListItem.d.ts +1 -1
  120. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  121. package/dist/RadioList/RadioListItem.js +5 -3
  122. package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
  123. package/dist/Resizable/ResizeHandle.js +118 -260
  124. package/dist/Resizable/resizeGesture.d.ts +91 -0
  125. package/dist/Resizable/resizeGesture.d.ts.map +1 -0
  126. package/dist/Resizable/resizeGesture.js +251 -0
  127. package/dist/SegmentedControl/SegmentedControl.d.ts +3 -1
  128. package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  129. package/dist/SegmentedControl/SegmentedControl.js +115 -8
  130. package/dist/SegmentedControl/SegmentedControlContext.d.ts +6 -0
  131. package/dist/SegmentedControl/SegmentedControlContext.d.ts.map +1 -1
  132. package/dist/SegmentedControl/SegmentedControlItem.d.ts +1 -0
  133. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  134. package/dist/SegmentedControl/SegmentedControlItem.js +10 -2
  135. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts +357 -0
  136. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -0
  137. package/dist/SegmentedControl/useSegmentedSelectionMotion.js +1349 -0
  138. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts +70 -0
  139. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts.map +1 -0
  140. package/dist/SegmentedControl/useSegmentedTouchTracking.js +264 -0
  141. package/dist/Selector/Selector.d.ts.map +1 -1
  142. package/dist/Selector/Selector.js +96 -67
  143. package/dist/Selector/optionShape.d.ts +24 -0
  144. package/dist/Selector/optionShape.d.ts.map +1 -0
  145. package/dist/Selector/optionShape.js +48 -0
  146. package/dist/Selector/selectableOptionEntries.d.ts +20 -0
  147. package/dist/Selector/selectableOptionEntries.d.ts.map +1 -0
  148. package/dist/Selector/selectableOptionEntries.js +38 -0
  149. package/dist/Selector/utils.d.ts +2 -17
  150. package/dist/Selector/utils.d.ts.map +1 -1
  151. package/dist/Selector/utils.js +3 -51
  152. package/dist/SideNav/SideNavItem.d.ts.map +1 -1
  153. package/dist/SideNav/SideNavItem.js +3 -9
  154. package/dist/Slider/sliderTouchController.js +2 -2
  155. package/dist/Switch/Switch.d.ts +1 -1
  156. package/dist/Switch/Switch.d.ts.map +1 -1
  157. package/dist/Switch/Switch.js +200 -46
  158. package/dist/Switch/switchFill.d.ts +31 -0
  159. package/dist/Switch/switchFill.d.ts.map +1 -0
  160. package/dist/Switch/switchFill.js +88 -0
  161. package/dist/Switch/switchTouch.d.ts +74 -0
  162. package/dist/Switch/switchTouch.d.ts.map +1 -0
  163. package/dist/Switch/switchTouch.js +125 -0
  164. package/dist/Switch/useSwitchTouch.d.ts +276 -0
  165. package/dist/Switch/useSwitchTouch.d.ts.map +1 -0
  166. package/dist/Switch/useSwitchTouch.js +939 -0
  167. package/dist/TabList/Tab.d.ts.map +1 -1
  168. package/dist/TabList/Tab.js +4 -3
  169. package/dist/Table/BaseTable.d.ts.map +1 -1
  170. package/dist/Table/BaseTable.js +29 -8
  171. package/dist/TextInput/TextInput.d.ts +2 -2
  172. package/dist/TextInput/TextInput.d.ts.map +1 -1
  173. package/dist/TextInput/TextInput.js +10 -7
  174. package/dist/Toast/Toast.d.ts.map +1 -1
  175. package/dist/Toast/Toast.js +5 -0
  176. package/dist/Token/Token.d.ts +2 -2
  177. package/dist/Token/Token.d.ts.map +1 -1
  178. package/dist/Token/Token.js +13 -4
  179. package/dist/Token/TokenNamingContext.d.ts +14 -0
  180. package/dist/Token/TokenNamingContext.d.ts.map +1 -0
  181. package/dist/Token/TokenNamingContext.js +23 -0
  182. package/dist/Tokenizer/Tokenizer.d.ts +46 -59
  183. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  184. package/dist/Tokenizer/Tokenizer.js +44 -60
  185. package/dist/Tokenizer/TokenizerBottomSheet.d.ts +25 -28
  186. package/dist/Tokenizer/TokenizerBottomSheet.d.ts.map +1 -1
  187. package/dist/Tokenizer/TokenizerBottomSheet.js +157 -54
  188. package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts +3 -0
  189. package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts.map +1 -0
  190. package/dist/Tokenizer/TokenizerItemRemovableContext.js +19 -0
  191. package/dist/Tooltip/Tooltip.d.ts +24 -5
  192. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  193. package/dist/Tooltip/Tooltip.js +29 -5
  194. package/dist/Tooltip/useTooltip.d.ts +48 -5
  195. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  196. package/dist/Tooltip/useTooltip.js +90 -20
  197. package/dist/TopNav/TopNavItem.d.ts.map +1 -1
  198. package/dist/TopNav/TopNavItem.js +4 -7
  199. package/dist/TopNav/TopNavMegaMenuItem.d.ts.map +1 -1
  200. package/dist/TopNav/TopNavMegaMenuItem.js +4 -7
  201. package/dist/TopNav/TopNavMenu.d.ts.map +1 -1
  202. package/dist/TopNav/TopNavMenu.js +4 -7
  203. package/dist/Typeahead/Typeahead.d.ts.map +1 -1
  204. package/dist/Typeahead/Typeahead.js +26 -15
  205. package/dist/animator/createAnimator.d.ts +98 -0
  206. package/dist/animator/createAnimator.d.ts.map +1 -0
  207. package/dist/animator/createAnimator.js +259 -0
  208. package/dist/astryx.css +142 -7
  209. package/dist/gestures/GestureHost.d.ts +27 -1
  210. package/dist/gestures/GestureHost.d.ts.map +1 -1
  211. package/dist/gestures/GestureHost.js +161 -22
  212. package/dist/gestures/PressTracker.d.ts +6 -0
  213. package/dist/gestures/PressTracker.d.ts.map +1 -1
  214. package/dist/gestures/PressTracker.js +3 -0
  215. package/dist/gestures/types.d.ts +6 -0
  216. package/dist/gestures/types.d.ts.map +1 -1
  217. package/dist/gestures/usePressTracker.d.ts.map +1 -1
  218. package/dist/gestures/usePressTracker.js +1 -0
  219. package/dist/gestures/wheelSegmenter.d.ts +14 -3
  220. package/dist/gestures/wheelSegmenter.d.ts.map +1 -1
  221. package/dist/gestures/wheelSegmenter.js +32 -8
  222. package/dist/hooks/actionGroupTracker.d.ts +7 -4
  223. package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
  224. package/dist/hooks/actionGroupTracker.js +19 -56
  225. package/dist/hooks/index.d.ts +1 -0
  226. package/dist/hooks/index.d.ts.map +1 -1
  227. package/dist/hooks/index.js +1 -0
  228. package/dist/hooks/pressGroupContext.d.ts +6 -0
  229. package/dist/hooks/pressGroupContext.d.ts.map +1 -0
  230. package/dist/hooks/pressGroupContext.js +20 -0
  231. package/dist/hooks/useActionGroupTracking.d.ts +53 -0
  232. package/dist/hooks/useActionGroupTracking.d.ts.map +1 -0
  233. package/dist/hooks/useActionGroupTracking.js +174 -0
  234. package/dist/hooks/useAnimator.d.ts +41 -0
  235. package/dist/hooks/useAnimator.d.ts.map +1 -0
  236. package/dist/hooks/useAnimator.js +70 -0
  237. package/dist/hooks/useAttachment.d.ts +16 -8
  238. package/dist/hooks/useAttachment.d.ts.map +1 -1
  239. package/dist/hooks/useAttachment.js +35 -15
  240. package/dist/hooks/useFocusTrap.d.ts +15 -0
  241. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  242. package/dist/hooks/useFocusTrap.js +13 -2
  243. package/dist/hooks/useHighlightedOptionScroll.d.ts +11 -1
  244. package/dist/hooks/useHighlightedOptionScroll.d.ts.map +1 -1
  245. package/dist/hooks/useHighlightedOptionScroll.js +112 -11
  246. package/dist/hooks/useInputStatusIcon.d.ts +1 -1
  247. package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
  248. package/dist/hooks/useInputStatusIcon.js +2 -2
  249. package/dist/hooks/useMediaQuery.d.ts +2 -1
  250. package/dist/hooks/useMediaQuery.d.ts.map +1 -1
  251. package/dist/hooks/useMediaQuery.js +7 -4
  252. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  253. package/dist/hooks/useMenuPress.js +4 -2
  254. package/dist/hooks/usePager.d.ts +261 -0
  255. package/dist/hooks/usePager.d.ts.map +1 -0
  256. package/dist/hooks/usePager.js +1169 -0
  257. package/dist/i18n/generated-english/InfoTip/InfoTip.generated.d.ts +8 -0
  258. package/dist/i18n/generated-english/InfoTip/InfoTip.generated.d.ts.map +1 -0
  259. package/dist/i18n/generated-english/InfoTip/InfoTip.generated.js +12 -0
  260. package/dist/i18n/generated-english/PowerSearch/PowerSearch.generated.d.ts.map +1 -1
  261. package/dist/i18n/generated-english/PowerSearch/PowerSearch.generated.js +1 -0
  262. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts +8 -0
  263. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +1 -0
  264. package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +42 -0
  265. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
  266. package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +6 -0
  267. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts +8 -0
  268. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts.map +1 -0
  269. package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.js +14 -0
  270. package/dist/i18n/generated-english/Tokenizer/TokenizerBottomSheet.generated.d.ts.map +1 -1
  271. package/dist/i18n/generated-english/Tokenizer/TokenizerBottomSheet.generated.js +7 -1
  272. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  273. package/dist/i18n/generated-locales/en.generated.js +33 -1
  274. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  275. package/dist/i18n/generated-locales/pseudo.generated.js +33 -1
  276. package/dist/index.d.ts +2 -0
  277. package/dist/index.d.ts.map +1 -1
  278. package/dist/index.js +5 -0
  279. package/dist/internal/SheetConfirmation.d.ts +11 -0
  280. package/dist/internal/SheetConfirmation.d.ts.map +1 -0
  281. package/dist/internal/SheetConfirmation.js +92 -0
  282. package/dist/internal/sheetDraft.d.ts +35 -0
  283. package/dist/internal/sheetDraft.d.ts.map +1 -0
  284. package/dist/internal/sheetDraft.js +65 -0
  285. package/dist/internal/touch-sheet.d.ts +21 -0
  286. package/dist/internal/touch-sheet.d.ts.map +1 -0
  287. package/dist/internal/touch-sheet.js +19 -0
  288. package/dist/internal/useDismissSearchOnTouchDrag.d.ts +24 -0
  289. package/dist/internal/useDismissSearchOnTouchDrag.d.ts.map +1 -0
  290. package/dist/internal/useDismissSearchOnTouchDrag.js +56 -0
  291. package/dist/motion/animator.d.ts +14 -14
  292. package/dist/motion/animator.d.ts.map +1 -1
  293. package/dist/motion/animator.js +41 -18
  294. package/dist/motion/paging.d.ts +16 -5
  295. package/dist/motion/paging.d.ts.map +1 -1
  296. package/dist/motion/paging.js +34 -14
  297. package/dist/motion/reducedMotion.d.ts +24 -0
  298. package/dist/motion/reducedMotion.d.ts.map +1 -1
  299. package/dist/motion/reducedMotion.js +78 -1
  300. package/dist/motion/roles.d.ts +7 -1
  301. package/dist/motion/roles.d.ts.map +1 -1
  302. package/dist/motion/roles.js +20 -1
  303. package/dist/motion/uikit/alert.d.ts +41 -0
  304. package/dist/motion/uikit/alert.d.ts.map +1 -0
  305. package/dist/motion/uikit/alert.js +43 -0
  306. package/dist/motion/uikit/index.d.ts +7 -4
  307. package/dist/motion/uikit/index.d.ts.map +1 -1
  308. package/dist/motion/uikit/index.js +7 -4
  309. package/dist/motion/uikit/paging.d.ts +31 -20
  310. package/dist/motion/uikit/paging.d.ts.map +1 -1
  311. package/dist/motion/uikit/paging.js +41 -11
  312. package/dist/motion/uikit/progressBar.d.ts +27 -7
  313. package/dist/motion/uikit/progressBar.d.ts.map +1 -1
  314. package/dist/motion/uikit/progressBar.js +31 -11
  315. package/dist/motion/uikit/segmented.d.ts +55 -0
  316. package/dist/motion/uikit/segmented.d.ts.map +1 -0
  317. package/dist/motion/uikit/segmented.js +77 -0
  318. package/dist/motion/uikit/springs.d.ts +8 -42
  319. package/dist/motion/uikit/springs.d.ts.map +1 -1
  320. package/dist/motion/uikit/springs.js +12 -42
  321. package/dist/motion/uikit/switch.d.ts +166 -0
  322. package/dist/motion/uikit/switch.d.ts.map +1 -0
  323. package/dist/motion/uikit/switch.js +186 -0
  324. package/dist/privateAttributes/pressGroupItem.stylex.d.ts +15 -0
  325. package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +1 -0
  326. package/dist/privateAttributes/pressGroupItem.stylex.js +23 -0
  327. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts +18 -0
  328. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts.map +1 -0
  329. package/dist/privateAttributes/pressHoldsDrag.stylex.js +28 -0
  330. package/dist/privateAttributes/segmentTitle.stylex.d.ts +5 -0
  331. package/dist/privateAttributes/segmentTitle.stylex.d.ts.map +1 -0
  332. package/dist/privateAttributes/segmentTitle.stylex.js +22 -0
  333. package/dist/utils/browserClickWait.d.ts +35 -0
  334. package/dist/utils/browserClickWait.d.ts.map +1 -0
  335. package/dist/utils/browserClickWait.js +123 -0
  336. package/dist/utils/clickGuard.d.ts +14 -1
  337. package/dist/utils/clickGuard.d.ts.map +1 -1
  338. package/dist/utils/clickGuard.js +46 -1
  339. package/dist/utils/dateParser.d.ts.map +1 -1
  340. package/dist/utils/dateParser.js +12 -0
  341. package/dist/utils/interactionOverlay.stylex.d.ts +3 -2
  342. package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
  343. package/dist/utils/interactionOverlay.stylex.js +3 -2
  344. package/dist/utils/pressFeedback.d.ts.map +1 -1
  345. package/dist/utils/pressFeedback.js +24 -6
  346. package/locales/en.json +128 -0
  347. package/locales/pseudo.json +96 -0
  348. package/package.json +13 -8
  349. package/src/AlertDialog/AlertDialog.doc.mjs +2 -2
  350. package/src/AlertDialog/AlertDialog.tsx +37 -5
  351. package/src/AppShell/useCloseMobileDrawerOnActivate.ts +52 -0
  352. package/src/Avatar/Avatar.tsx +3 -1
  353. package/src/BottomSheet/BottomSheet.tsx +95 -10
  354. package/src/BottomSheet/BottomSheetPanel.tsx +40 -5
  355. package/src/BottomSheet/bottomSheetStack.ts +8 -4
  356. package/src/BottomSheet/useSheetGestures.ts +3 -1
  357. package/src/Breadcrumbs/BreadcrumbItem.tsx +17 -4
  358. package/src/Button/Button.tsx +66 -7
  359. package/src/CheckboxList/CheckboxList.doc.mjs +4 -2
  360. package/src/CheckboxList/CheckboxList.tsx +6 -0
  361. package/src/CheckboxList/CheckboxListContext.tsx +6 -0
  362. package/src/CheckboxList/CheckboxListItem.tsx +11 -2
  363. package/src/ComplexSelector/ComplexSelector.tsx +20 -5
  364. package/src/DateInput/DateInput.tsx +8 -2
  365. package/src/DateInput/MonthScroller.tsx +18 -22
  366. package/src/DateInput/Wheel.tsx +172 -14
  367. package/src/DateRangeInput/DateRangeInput.doc.mjs +3 -2
  368. package/src/DateRangeInput/DateRangeInput.tsx +117 -71
  369. package/src/DateTimeInput/DateTimeInput.tsx +8 -2
  370. package/src/Dialog/Dialog.tsx +81 -15
  371. package/src/Drawer/Drawer.tsx +28 -11
  372. package/src/Drawer/useDrawerDialogPresence.ts +9 -1
  373. package/src/DropdownMenu/DropdownMenu.tsx +28 -6
  374. package/src/Field/Field.tsx +2 -2
  375. package/src/Field/PanelSearchInput.tsx +11 -0
  376. package/src/HoverCard/HoverCard.tsx +31 -1
  377. package/src/Icon/Icon.doc.mjs +49 -8
  378. package/src/Icon/Icon.tsx +15 -7
  379. package/src/InfoTip/InfoTip.doc.mjs +192 -0
  380. package/src/InfoTip/InfoTip.tsx +186 -0
  381. package/src/InfoTip/index.ts +14 -0
  382. package/src/Layer/layerAnimations.stylex.ts +24 -16
  383. package/src/Layer/layerClickBoundary.ts +2 -2
  384. package/src/Layer/useBackdropPress.ts +81 -0
  385. package/src/Layer/usePressPin.ts +576 -0
  386. package/src/Layer/useTouchTrigger.ts +56 -6
  387. package/src/Lightbox/Lightbox.tsx +2 -1
  388. package/src/MobileNav/MobileNav.tsx +1 -1
  389. package/src/MultiSelector/hooks.ts +2 -4
  390. package/src/Outline/Outline.doc.mjs +177 -51
  391. package/src/Outline/Outline.tsx +5 -57
  392. package/src/Outline/useOutlineFromMarkdown.doc.mjs +157 -0
  393. package/src/Outline/useOutlineFromMarkdown.ts +1 -0
  394. package/src/Outline/useScrollSpy.ts +3 -3
  395. package/src/Popover/usePopover.tsx +71 -9
  396. package/src/PowerSearch/PowerSearch.doc.mjs +55 -6
  397. package/src/PowerSearch/PowerSearch.tsx +798 -324
  398. package/src/PowerSearch/PowerSearchBottomSheet.tsx +2515 -0
  399. package/src/PowerSearch/PowerSearchEditPopover.tsx +28 -6
  400. package/src/PowerSearch/PowerSearchValueEditor.tsx +203 -38
  401. package/src/PowerSearch/formatFilterValue.ts +18 -1
  402. package/src/PowerSearch/formatTokenValue.ts +215 -0
  403. package/src/PowerSearch/powerSearchSheetUtils.ts +224 -0
  404. package/src/ProgressBar/ProgressBar.doc.mjs +4 -2
  405. package/src/ProgressBar/ProgressBar.tsx +67 -7
  406. package/src/RadioList/RadioList.doc.mjs +4 -2
  407. package/src/RadioList/RadioList.tsx +7 -2
  408. package/src/RadioList/RadioListItem.tsx +5 -3
  409. package/src/Resizable/ResizeHandle.tsx +133 -328
  410. package/src/Resizable/resizeGesture.ts +368 -0
  411. package/src/SegmentedControl/SegmentedControl.doc.mjs +3 -3
  412. package/src/SegmentedControl/SegmentedControl.tsx +179 -5
  413. package/src/SegmentedControl/SegmentedControlContext.ts +6 -0
  414. package/src/SegmentedControl/SegmentedControlItem.tsx +14 -2
  415. package/src/SegmentedControl/useSegmentedSelectionMotion.ts +1640 -0
  416. package/src/SegmentedControl/useSegmentedTouchTracking.ts +308 -0
  417. package/src/Selector/Selector.tsx +136 -89
  418. package/src/Selector/optionShape.ts +64 -0
  419. package/src/Selector/selectableOptionEntries.ts +39 -0
  420. package/src/Selector/utils.ts +9 -68
  421. package/src/SideNav/SideNavItem.tsx +3 -7
  422. package/src/Slider/sliderTouchController.ts +2 -2
  423. package/src/Switch/Switch.doc.mjs +3 -3
  424. package/src/Switch/Switch.tsx +412 -86
  425. package/src/Switch/switchFill.ts +106 -0
  426. package/src/Switch/switchTouch.ts +186 -0
  427. package/src/Switch/useSwitchTouch.ts +1051 -0
  428. package/src/TabList/Tab.tsx +5 -3
  429. package/src/Table/BaseTable.tsx +46 -12
  430. package/src/TextInput/TextInput.tsx +11 -10
  431. package/src/Toast/Toast.tsx +5 -0
  432. package/src/Token/Token.tsx +15 -4
  433. package/src/Token/TokenNamingContext.ts +28 -0
  434. package/src/Tokenizer/Tokenizer.doc.mjs +16 -0
  435. package/src/Tokenizer/Tokenizer.tsx +93 -88
  436. package/src/Tokenizer/TokenizerBottomSheet.tsx +219 -93
  437. package/src/Tokenizer/TokenizerItemRemovableContext.ts +24 -0
  438. package/src/Tooltip/Tooltip.doc.mjs +123 -39
  439. package/src/Tooltip/Tooltip.tsx +43 -9
  440. package/src/Tooltip/useTooltip.doc.mjs +171 -31
  441. package/src/Tooltip/useTooltip.tsx +137 -22
  442. package/src/TopNav/TopNavItem.tsx +6 -5
  443. package/src/TopNav/TopNavMegaMenuItem.tsx +6 -5
  444. package/src/TopNav/TopNavMenu.tsx +6 -5
  445. package/src/Typeahead/Typeahead.tsx +29 -15
  446. package/src/animator/createAnimator.doc.mjs +153 -0
  447. package/src/animator/createAnimator.ts +324 -0
  448. package/src/gestures/GestureHost.ts +205 -21
  449. package/src/gestures/PressTracker.ts +10 -0
  450. package/src/gestures/types.ts +6 -0
  451. package/src/gestures/usePressTracker.ts +2 -0
  452. package/src/gestures/wheelSegmenter.ts +36 -7
  453. package/src/hooks/actionGroupTracker.ts +32 -61
  454. package/src/hooks/index.ts +2 -0
  455. package/src/hooks/pressGroupContext.ts +21 -0
  456. package/src/hooks/useActionGroupTracking.ts +224 -0
  457. package/src/hooks/useAnimator.doc.mjs +109 -0
  458. package/src/hooks/useAnimator.ts +67 -0
  459. package/src/hooks/useAttachment.ts +56 -14
  460. package/src/hooks/useFocusTrap.ts +26 -2
  461. package/src/hooks/useHighlightedOptionScroll.ts +123 -15
  462. package/src/hooks/useInputStatusIcon.tsx +3 -2
  463. package/src/hooks/useMediaQuery.doc.mjs +2 -2
  464. package/src/hooks/useMediaQuery.ts +13 -4
  465. package/src/hooks/useMenuPress.ts +8 -2
  466. package/src/hooks/usePager.ts +1446 -0
  467. package/src/i18n/generated-english/InfoTip/InfoTip.generated.ts +13 -0
  468. package/src/i18n/generated-english/PowerSearch/PowerSearch.generated.ts +1 -0
  469. package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +43 -0
  470. package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +6 -0
  471. package/src/i18n/generated-english/PowerSearch/formatTokenValue.generated.ts +15 -0
  472. package/src/i18n/generated-english/Tokenizer/TokenizerBottomSheet.generated.ts +7 -1
  473. package/src/i18n/generated-locales/en.generated.ts +43 -0
  474. package/src/i18n/generated-locales/pseudo.generated.ts +44 -0
  475. package/src/index.ts +14 -0
  476. package/src/internal/SheetConfirmation.tsx +101 -0
  477. package/src/internal/sheetDraft.ts +80 -0
  478. package/src/internal/touch-sheet.ts +21 -0
  479. package/src/internal/useDismissSearchOnTouchDrag.ts +69 -0
  480. package/src/motion/MEASUREMENTS.md +36 -27
  481. package/src/motion/README.md +11 -6
  482. package/src/motion/animator.ts +61 -29
  483. package/src/motion/paging.ts +37 -14
  484. package/src/motion/reducedMotion.ts +79 -1
  485. package/src/motion/roles.ts +20 -1
  486. package/src/motion/uikit/alert.ts +43 -0
  487. package/src/motion/uikit/index.ts +6 -5
  488. package/src/motion/uikit/paging.ts +41 -10
  489. package/src/motion/uikit/progressBar.ts +31 -11
  490. package/src/motion/uikit/segmented.ts +74 -0
  491. package/src/motion/uikit/springs.ts +12 -42
  492. package/src/motion/uikit/switch.ts +174 -0
  493. package/src/privateAttributes/pressGroupItem.stylex.ts +23 -0
  494. package/src/privateAttributes/pressHoldsDrag.stylex.ts +28 -0
  495. package/src/privateAttributes/segmentTitle.stylex.ts +22 -0
  496. package/src/utils/browserClickWait.ts +133 -0
  497. package/src/utils/clickGuard.ts +64 -1
  498. package/src/utils/dateParser.ts +16 -0
  499. package/src/utils/interactionOverlay.stylex.ts +3 -2
  500. package/src/utils/pressFeedback.ts +24 -6
  501. package/dist/internal/tokenizer-presentation.d.ts +0 -21
  502. package/dist/internal/tokenizer-presentation.d.ts.map +0 -1
  503. package/dist/internal/tokenizer-presentation.js +0 -21
  504. package/src/internal/tokenizer-presentation.ts +0 -25
@@ -0,0 +1,939 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file useSwitchTouch.ts
7
+ * @input Switch's parts (gesture surface, input, thumb and track), its value,
8
+ * whether it is interactive, the track's other state (switchFill.ts) and
9
+ * the thumb geometry (switchTouch.ts)
10
+ * @output Exports useSwitchTouch: Switch's gestures for a mouse, a pen and a
11
+ * finger, and its touch presentation under a coarse primary pointer
12
+ * @position DOM half of Switch's touch presentation, on the gesture system
13
+ * (../gestures) and the compositor animator (../motion/animator)
14
+ *
15
+ * SYNC: When modified, update switchTouch.ts, Switch.tsx
16
+ * and __tests__/Switch.interaction.browser.spec.ts.
17
+ */
18
+ import { useMemo, useState } from 'react';
19
+ import { getGestureHost } from "../gestures/GestureHost.js";
20
+ import { createPressTracker } from "../gestures/PressTracker.js";
21
+ import { isRtlElement } from "../hooks/isRtlElement.js";
22
+ import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect.js";
23
+ import { createMotionAnimator } from "../motion/animator.js";
24
+ import { solveSpring, toSpring } from "../motion/spring.js";
25
+ import { UIKIT_GESTURES } from "../motion/uikit/gestures.js";
26
+ import { registerSwitchTable, switchControl } from "../motion/uikit/switch.js";
27
+ import { useTouchPresentation } from "../utils/touchPresentation.js";
28
+ import { awaitBrowserClick, clickForLift } from "../utils/browserClickWait.js";
29
+ import { armClickGuard } from "../utils/clickGuard.js";
30
+ import { commitOnRelease, dragTarget, settleTime, startFlip, stepFlip, switchTouchGeometry } from "./switchTouch.js";
31
+ import { readFillOf, sameTrackState, trackStateOf } from "./switchFill.js";
32
+ /** The fade layer's colour, set on the track for its ::after (Switch.tsx). */
33
+ const FADE_FILL = '--_switch-fade-fill';
34
+ /** The track's own fill while a change is held (inline, over its CSS). */
35
+ const BASE_FILL = 'background-color';
36
+ const TRAVEL = switchControl.travel;
37
+ const TRACKING = switchControl.tracking;
38
+ /**
39
+ * Horizontal travel at which the press begins if it has not (a pan
40
+ * begins here), px.
41
+ */
42
+ const PAN_HYSTERESIS = UIKIT_GESTURES.pan.hysteresis.value;
43
+ function now() {
44
+ return typeof performance === 'undefined' ? Date.now() : performance.now();
45
+ }
46
+
47
+ /**
48
+ * The lift spring until `holdSeconds`, then the settle spring from where the
49
+ * lift got to. It is one curve, so the settle starts on the compositor's
50
+ * clock.
51
+ */
52
+ function liftThenSettle({
53
+ from,
54
+ velocity,
55
+ lifted,
56
+ rest,
57
+ holdSeconds,
58
+ threshold,
59
+ lift,
60
+ settle
61
+ }) {
62
+ const hold = Math.max(0, holdSeconds);
63
+ const first = solveSpring(toSpring(lift), {
64
+ from,
65
+ to: lifted,
66
+ velocity
67
+ });
68
+ const second = solveSpring(toSpring(settle), {
69
+ from: first.value(hold),
70
+ to: rest,
71
+ velocity: first.velocity(hold)
72
+ });
73
+ return {
74
+ duration: hold + second.settleTime(threshold),
75
+ at: t => t < hold ? first.value(t) : second.value(t - hold),
76
+ velocity: t => t < hold ? first.velocity(t) : second.velocity(t - hold)
77
+ };
78
+ }
79
+
80
+ /**
81
+ * The switch's presentation: the touch presentation under a coarse primary
82
+ * pointer, or its own under a fine one.
83
+ */
84
+
85
+ /**
86
+ * The touch presentation of one switch: animators, recognizers and the
87
+ * gesture state. No React state: a gesture never renders. UISwitch on iOS
88
+ * 26.2 is the reference; every number is in motion/uikit/switch.ts.
89
+ *
90
+ * - The thumb's resting place is CSS (its inline-start inset). So the steady
91
+ * state needs no script and mirrors under RTL by itself. The animator only
92
+ * moves the thumb by a delta from that place (`translate`). When the value
93
+ * moves the CSS place, the delta is rebased in the same layout effect.
94
+ * Nothing moves on screen, and the velocity is kept.
95
+ * - Touches go to a press tracker, which never blocks a scroll. No
96
+ * recognizer claims the touch. `touch-action: pan-y` (Switch.tsx) keeps
97
+ * horizontal moves for the switch: a drag follows and flips it, and the
98
+ * release commits. A vertical drag is the page's scroll, and the switch
99
+ * yields.
100
+ * - A tap, a hold or a short drag activates through the browser's own click.
101
+ * The browser sends no click for a finger's hold, so the switch clicks its
102
+ * input once the click window passes. A mouse or a pen gets a click when
103
+ * it is released on the input. A drag that flipped the switch gets no
104
+ * click, so the switch clicks its input, and the shared click guard
105
+ * swallows the browser's late click. A finger's press slid off and lifted
106
+ * outside toggles too, as UISwitch's does. Forms, `onChange` and the
107
+ * keyboard stay the native checkbox's.
108
+ * - The drag never renders: each move retargets the thumb's tracking spring
109
+ * and steps the flip rule on the finger's travel.
110
+ * - The thumb lifts while a finger presses, into half of the gap around it,
111
+ * and its shadow fades in. At the release it settles back, no sooner than
112
+ * the minimum lift time. The lift and the settle are one curve, built at
113
+ * the release, so the settle starts on time on the compositor.
114
+ * - The track keeps its own fill in both states. A fade layer over it,
115
+ * painted with the track's other fill, fades the colour on the compositor.
116
+ * When the value changes, the layer swaps to the other fill and to the
117
+ * complement of its opacity. So nothing changes on screen. A change the
118
+ * fade already heads to swaps nothing: the track holds its previous fill
119
+ * inline until the fade lands. WebKit plays a curve built in a held frame
120
+ * only once the long task ends, so a swap there stepped the colour back.
121
+ * The layer is composited from the start (`will-change`, Switch.tsx), or
122
+ * iOS Safari runs its fade on the main thread.
123
+ * - Under reduced motion nothing travels or springs: a change plays the
124
+ * animator's Reduce Motion cross-fade. A dragging finger still moves the
125
+ * thumb: that is direct manipulation.
126
+ * - Under a fine primary pointer the switch keeps its own look. The same
127
+ * tracking, flip rule and release decide the value, with no animator, and
128
+ * the thumb moves when the value does. Only its press listens at rest. Its
129
+ * click listener comes with a press.
130
+ */
131
+ export class SwitchTouchController {
132
+ elements = null;
133
+ isInteractive = true;
134
+ /** The side the visuals show or head to. */
135
+
136
+ /** +1 left-to-right, −1 right-to-left. */
137
+ direction = 1;
138
+ thumb = null;
139
+ /** The fade layer: its opacity is how far the visuals are from the value. */
140
+ fade = null;
141
+ /** The lifted shadow: the thumb's `::after`, faded in with the lift. */
142
+ shadow = null;
143
+ /** When the thumb lifted (document timeline, ms); null while at rest. */
144
+ liftTime = null;
145
+ /** When the running settle leaves the lift (settleTime), ms. */
146
+ settleAt = null;
147
+ otherTrack = null;
148
+ /**
149
+ * A change landed mid-fade, and the fade already heads to it. The track's
150
+ * own fill stays the previous value's (inline) until the fade lands. So the
151
+ * change's frame builds no curve and repaints nothing. `baseHold` counts
152
+ * holds, so a settled one ignores its late landing.
153
+ */
154
+ baseHeld = false;
155
+ baseHold = 0;
156
+ detachers = [];
157
+ /** When the press began (document timeline, ms); null with no press. */
158
+ pressTime = null;
159
+ /** The thumb's offset when the current finger landed. */
160
+ downOffset = 0;
161
+ drag = null;
162
+ /** The finger's last travel along x, for a lift that reports none. */
163
+ lastTravel = 0;
164
+ /**
165
+ * The press and the pan both report every touch event; the first report
166
+ * takes the step and this skips the second (cleared after the event).
167
+ */
168
+ isStepping = false;
169
+ /** The current touch already ended in a release. */
170
+ released = false;
171
+ /**
172
+ * Reduced motion: a release changed the value. The thumb's travel waits for
173
+ * the value to commit, so its one cross-fade lands in the new frame.
174
+ */
175
+ pendingTravel = false;
176
+ /** Passive: a finger is down on the switch. */
177
+ isTracking = false;
178
+ /** Which presentation the switch has: the touch one, or its own. */
179
+ presentation = 'touch';
180
+ /** Passive: a lift is waiting for the browser's own click; this ends it. */
181
+ endBrowserClickWait = null;
182
+ reconcileTimer = null;
183
+ constructor(isOn, geometry) {
184
+ this.isOn = isOn;
185
+ this.isVisuallyOn = isOn;
186
+ this.geometry = geometry;
187
+ }
188
+ get isAttached() {
189
+ return this.elements != null;
190
+ }
191
+ attach(elements, presentation) {
192
+ this.detach();
193
+ this.elements = elements;
194
+ this.presentation = presentation;
195
+ this.measureGeometry();
196
+ this.direction = isRtlElement(elements.surface) ? -1 : 1;
197
+ this.isVisuallyOn = this.isOn;
198
+ const host = getGestureHost(elements.surface.ownerDocument);
199
+ if (presentation === 'pointer') {
200
+ // The switch's own look: the gestures decide the value and the CSS
201
+ // shows it.
202
+ this.detachers = this.attachPassive(host, elements);
203
+ return;
204
+ }
205
+ registerSwitchTable();
206
+ this.thumb = createMotionAnimator(elements.thumb);
207
+ // The layer rests clear (its class's opacity 0) while the visuals show
208
+ // the value; from here its opacity is the animator's.
209
+ this.fade = createMotionAnimator(elements.track, {
210
+ pseudoElement: '::after',
211
+ initial: {
212
+ opacity: 0
213
+ }
214
+ });
215
+ this.fade.set({
216
+ opacity: 0
217
+ });
218
+ this.shadow = createMotionAnimator(elements.thumb, {
219
+ pseudoElement: '::after',
220
+ initial: {
221
+ opacity: 0
222
+ }
223
+ });
224
+ this.shadow.set({
225
+ opacity: 0
226
+ });
227
+ this.paintFade();
228
+ this.detachers = this.attachPassive(host, elements);
229
+ }
230
+
231
+ /**
232
+ * Passive: UIControl's tracking, which never blocks a scroll. The press
233
+ * begins with the touch, or with the first horizontal move a pan would
234
+ * begin on. Inside a scroller the touch waits for the content delay. Every
235
+ * move steps the flip rule, and the release commits. A touch the browser
236
+ * takes for its scroll yields with no toggle.
237
+ */
238
+ attachPassive(host, elements) {
239
+ const {
240
+ surface
241
+ } = elements;
242
+ const tracker = createPressTracker({
243
+ view: surface,
244
+ getBounds: () => surface.getBoundingClientRect(),
245
+ isEnabled: () => this.isInteractive,
246
+ isBraking: () => host.isScrollBraking(surface),
247
+ // A held switch opens no menu (UISwitch shows none).
248
+ holdsContextMenu: () => this.pressTime != null,
249
+ onControlEvent: (event, touch) => this.onControlEvent(event, touch),
250
+ onHighlightChange: isHighlighted => {
251
+ if (isHighlighted && this.isTracking && this.pressTime == null) {
252
+ this.pressBegan(now());
253
+ }
254
+ }
255
+ });
256
+ return [host.attachConsumer(surface, tracker), () => tracker.dispose()];
257
+ }
258
+
259
+ /** Undo everything: listeners, timers, animations and inline styles. */
260
+ detach() {
261
+ for (const detach of this.detachers) {
262
+ detach();
263
+ }
264
+ this.detachers = [];
265
+ this.clearTimers();
266
+ for (const animator of [this.thumb, this.fade, this.shadow]) {
267
+ const element = animator?.element;
268
+ animator?.dispose();
269
+ if (element != null) {
270
+ for (const property of ['translate', 'scale', 'opacity']) {
271
+ element.style.removeProperty(property);
272
+ }
273
+ }
274
+ }
275
+ this.elements?.track.style.removeProperty(FADE_FILL);
276
+ this.elements?.track.style.removeProperty(BASE_FILL);
277
+ this.baseHeld = false;
278
+ this.baseHold++;
279
+ this.thumb = this.fade = this.shadow = null;
280
+ this.liftTime = null;
281
+ this.elements = null;
282
+ this.pressTime = null;
283
+ this.drag = null;
284
+ this.isTracking = false;
285
+ }
286
+ setInteractive(isInteractive) {
287
+ this.isInteractive = isInteractive;
288
+ if (!isInteractive && this.pressTime != null) {
289
+ this.abandon(now());
290
+ }
291
+ }
292
+
293
+ /** The track's other state, re-rendered with each value. */
294
+ setOtherTrack(otherTrack) {
295
+ const previous = this.otherTrack;
296
+ this.otherTrack = otherTrack;
297
+ // A held fill was read from the previous other state; a re-render that
298
+ // keeps it keeps the hold.
299
+ if (this.baseHeld && !sameTrackState(previous, otherTrack)) {
300
+ this.landBase(now());
301
+ }
302
+ }
303
+ setGeometry(geometry) {
304
+ this.geometry = geometry;
305
+ this.measureGeometry();
306
+ this.thumb?.set({
307
+ x: 0,
308
+ scaleX: 1,
309
+ scaleY: 1
310
+ });
311
+ }
312
+
313
+ /**
314
+ * The thumb geometry from the rendered boxes. The track's box lets a theme
315
+ * resize the track. The thumb's box is the circle of the current value. It
316
+ * rests by insets from the track's padding box, so padding does not move it.
317
+ */
318
+ measureGeometry() {
319
+ const track = this.elements?.track;
320
+ const thumb = this.elements?.thumb;
321
+ if (track == null) {
322
+ return;
323
+ }
324
+ // Fractional boxes: the track's border box less its border (it has no
325
+ // transform). The thumb's used size comes from its computed style, which
326
+ // its scale does not change.
327
+ const box = track.getBoundingClientRect();
328
+ const trackWidth = box.width - 2 * track.clientLeft;
329
+ const trackHeight = box.height - 2 * track.clientTop;
330
+ if (trackWidth <= 0 || trackHeight <= 0) {
331
+ return;
332
+ }
333
+ const style = thumb == null ? null : getComputedStyle(thumb);
334
+ const thumbWidth = style == null ? NaN : parseFloat(style.width);
335
+ const thumbHeight = style == null ? NaN : parseFloat(style.height);
336
+ this.geometry = switchTouchGeometry(trackWidth, trackHeight, thumbWidth > 0 && thumbHeight > 0 ? {
337
+ width: thumbWidth,
338
+ height: thumbHeight
339
+ } : undefined);
340
+ }
341
+
342
+ /**
343
+ * The rendered value changed. The CSS has already moved the thumb's
344
+ * resting place. So the thumb's delta is rebased first, and nothing moves on
345
+ * screen. Then the visuals head for the new value.
346
+ */
347
+ setValue(isOn) {
348
+ if (isOn === this.isOn) {
349
+ return;
350
+ }
351
+ const previous = this.isOn;
352
+ this.isOn = isOn;
353
+ const thumb = this.thumb;
354
+ if (thumb == null) {
355
+ this.isVisuallyOn = isOn;
356
+ return;
357
+ }
358
+ const time = now();
359
+ // The thumb's CSS rest moved with the value: shift it back by as much,
360
+ // so nothing moves on screen. A spring keeps its target through the shift
361
+ // and is sent to the new rest below. A reduced-motion dip shifts whole,
362
+ // its end included, and keeps going.
363
+ const springs = thumb.reducedMotion() === 'off';
364
+ thumb.rebase({
365
+ x: this.direction * (this.rest(previous) - this.rest(isOn))
366
+ });
367
+ // Each state has its own thumb size, the circle a mouse sees. The box the
368
+ // CSS now renders is the new value's. Its scale takes the old size over
369
+ // and grows or shrinks it from there.
370
+ const before = this.geometry;
371
+ this.measureGeometry();
372
+ if (springs) {
373
+ this.rescaleThumb(before, this.geometry, time);
374
+ }
375
+ // The track now shows the new value's fill. The fade layer swaps to the
376
+ // other fill and to the complement of its opacity. Nothing changes on
377
+ // screen, and the fade keeps heading where the visuals head.
378
+ const fade = this.fade;
379
+ if (fade != null) {
380
+ this.landBase(time);
381
+ // Already heading here (a release, a drag that flipped). The running
382
+ // fade carries the change over the previous fill, held as the track's
383
+ // own until it lands. WebKit plays a curve built in a held frame only
384
+ // once the long task ends. A swap here would step the colour back.
385
+ if (this.isVisuallyOn !== isOn || !this.holdBase()) {
386
+ this.swapFade(time);
387
+ }
388
+ }
389
+ const wasDragging = this.drag != null && !this.released;
390
+ if (wasDragging) {
391
+ // The app changed the value mid-gesture: the value wins and the
392
+ // gesture ends without committing.
393
+ this.drag = null;
394
+ this.released = true;
395
+ this.pressEnded();
396
+ }
397
+ // A release already sent the visuals here. Any other change, the app's or
398
+ // one mid-gesture, sends them now, and a spring heads for the new rest.
399
+ if (springs || wasDragging || this.pendingTravel || this.isVisuallyOn !== isOn) {
400
+ const touchRelease = this.pendingTravel;
401
+ this.pendingTravel = false;
402
+ this.showSide(isOn, time, thumb.getVelocity('x', time), touchRelease);
403
+ }
404
+ }
405
+
406
+ // --- Touches ---------------------------------------------------------------
407
+
408
+ touchDown(time) {
409
+ this.landBase(time);
410
+ this.released = false;
411
+ this.pendingTravel = false;
412
+ this.drag = null;
413
+ this.lastTravel = 0;
414
+ this.downOffset = this.offsetAt(time);
415
+ }
416
+
417
+ /** Passive: a mouse, a pen or a finger on the switch, UIControl's events. */
418
+ onControlEvent(event, touch) {
419
+ const travel = touch.x - touch.startX;
420
+ // The switch reads the thumb when it handles the event. Its motion has no
421
+ // start of its own. A call that continues motion starts then, from the
422
+ // curve on screen. A call from rest starts at the frame that shows it, as
423
+ // Core Animation starts an animation at its commit. A busy main thread
424
+ // hands the switch an event late and commits its frame late. The motion
425
+ // is delayed, never stepped back or skipped into. The event's own time is
426
+ // the recognizers'.
427
+ const time = now();
428
+ switch (event) {
429
+ case 'touchDown':
430
+ this.isTracking = true;
431
+ this.touchDown(time);
432
+ return;
433
+ case 'touchDragInside':
434
+ case 'touchDragOutside':
435
+ if (this.released || !this.isInteractive) {
436
+ return;
437
+ }
438
+ if (this.pressTime == null) {
439
+ if (Math.abs(travel) < PAN_HYSTERESIS) {
440
+ return;
441
+ }
442
+ // A pan would begin here: the switch takes the horizontal drag.
443
+ this.pressBegan(time);
444
+ }
445
+ this.move(time, travel);
446
+ return;
447
+ case 'touchUpInside':
448
+ case 'touchUpOutside':
449
+ this.isTracking = false;
450
+ if (this.released || !this.isInteractive) {
451
+ return;
452
+ }
453
+ // The finger's lift is a step of its own: a flip armed by the last
454
+ // move happens here (a fast swipe flips on the lift).
455
+ this.move(time, travel);
456
+ if (this.drag?.flip.didFlip !== true && event === 'touchUpInside') {
457
+ // A tap, a hold or a short drag: the browser's click activates it.
458
+ // Only a finger's lift can come with no click (a hold). A mouse or a
459
+ // pen gets one whenever it is released on the input. With no click,
460
+ // it was released off the input, inside the tracking slop. The
461
+ // switch is then left alone, as the native checkbox is.
462
+ this.release(time, {
463
+ byBrowserClick: true,
464
+ clicksIfNoBrowserClick: touch.pointerType === 'touch'
465
+ });
466
+ return;
467
+ }
468
+ if (touch.pointerType !== 'touch' && (event === 'touchUpOutside' || this.drag?.flip.didFlip !== true)) {
469
+ // A mouse or a pen released outside the tracking bounds, flipped or
470
+ // not, leaves the switch alone, as the native checkbox does. So the
471
+ // press can be taken back (WCAG 2.5.2). Only a finger's press slid
472
+ // off toggles.
473
+ this.released = true;
474
+ this.abandon(time);
475
+ return;
476
+ }
477
+ // A drag that flipped, or a press slid off and lifted outside, which
478
+ // toggles as UISwitch's does. The switch decides this lift itself, so
479
+ // the shared click guard swallows the browser's click, if one comes.
480
+ // A drag back past the press commits nothing, and its click must not
481
+ // toggle either.
482
+ if (this.elements != null) {
483
+ armClickGuard(this.elements.input.ownerDocument);
484
+ }
485
+ this.release(time);
486
+ return;
487
+ case 'touchCancel':
488
+ // The browser took the touch for its scroll, or a recognizer above
489
+ // took it: the switch yields.
490
+ this.isTracking = false;
491
+ if (!this.released) {
492
+ this.released = true;
493
+ this.abandon(time);
494
+ }
495
+ return;
496
+ case 'touchDragEnter':
497
+ case 'touchDragExit':
498
+ return;
499
+ }
500
+ }
501
+
502
+ /**
503
+ * One touch event of a held or dragged switch. It retargets the thumb at the
504
+ * finger (one style write) and steps the flip rule.
505
+ */
506
+ move(time, travel) {
507
+ const thumb = this.thumb;
508
+ if (this.isStepping) {
509
+ return;
510
+ }
511
+ this.isStepping = true;
512
+ queueMicrotask(() => {
513
+ this.isStepping = false;
514
+ });
515
+ const x = this.direction * (travel ?? this.lastTravel);
516
+ this.lastTravel = travel ?? this.lastTravel;
517
+ const drag = this.drag ??= {
518
+ start: this.downOffset,
519
+ flip: startFlip(this.isOn)
520
+ };
521
+ // The thumb under the finger is direct manipulation, which reduced
522
+ // motion leaves alone. Under it the thumb is placed at once: the animator
523
+ // would cross-fade a move. Under a fine pointer nothing follows the
524
+ // pointer. The switch keeps its own look, and the value moves the thumb.
525
+ if (thumb != null) {
526
+ const target = this.toX(dragTarget(drag.start, x, this.geometry));
527
+ if (thumb.reducedMotion() === 'off') {
528
+ thumb.animate({
529
+ x: target
530
+ }, {
531
+ spring: TRACKING
532
+ });
533
+ } else {
534
+ thumb.set({
535
+ x: target
536
+ });
537
+ }
538
+ }
539
+ drag.flip = stepFlip(drag.flip, x, this.geometry);
540
+ if (drag.flip.isVisuallyOn !== this.isVisuallyOn) {
541
+ this.showWell(drag.flip.isVisuallyOn, time);
542
+ }
543
+ }
544
+
545
+ /**
546
+ * The finger lifted after a tap, a hold or a drag. `byBrowserClick`: the
547
+ * browser's own click activates the input, and the switch clicks it only
548
+ * if that click never comes.
549
+ */
550
+ release(time, {
551
+ byBrowserClick = false,
552
+ clicksIfNoBrowserClick = true
553
+ } = {}) {
554
+ if (this.released) {
555
+ return;
556
+ }
557
+ this.released = true;
558
+ this.clearTimers();
559
+ const commit = commitOnRelease(this.drag?.flip ?? null, this.isOn);
560
+ this.drag = null;
561
+ if (this.pressTime == null) {
562
+ // A tap quicker than a scroller's content delay: the press begins now.
563
+ this.pressBegan(time);
564
+ }
565
+ if (commit !== this.isOn && this.thumb != null && this.thumb.reducedMotion({
566
+ touchRelease: true
567
+ }) !== 'off') {
568
+ // Under reduced motion the travel is one cross-fade, played when the
569
+ // value commits (setValue). It lands in the new value's frame. The
570
+ // colour starts now.
571
+ this.pendingTravel = true;
572
+ this.showWell(commit, time, true);
573
+ } else {
574
+ this.showSide(commit, time, undefined, true);
575
+ }
576
+ this.pressEnded(time, true);
577
+ const surface = this.elements?.surface;
578
+ if (byBrowserClick && surface != null) {
579
+ // The lift's own click activates the input natively: the switch then
580
+ // clicks nothing itself.
581
+ this.endBrowserClickWait = awaitBrowserClick(surface, {
582
+ onClicked: () => {
583
+ this.endBrowserClickWait = null;
584
+ this.scheduleReconcile();
585
+ },
586
+ onNoClick: () => {
587
+ this.endBrowserClickWait = null;
588
+ if (clicksIfNoBrowserClick && commit !== this.isOn) {
589
+ this.clickInput();
590
+ }
591
+ this.scheduleReconcile();
592
+ }
593
+ });
594
+ return;
595
+ }
596
+ if (commit !== this.isOn) {
597
+ // No click comes from the browser for this lift; the input's own click
598
+ // keeps every native path (form value, onChange, the label).
599
+ this.clickInput();
600
+ }
601
+ this.scheduleReconcile();
602
+ }
603
+
604
+ /**
605
+ * The switch's own click on its input. The shared click guard then swallows
606
+ * the browser's late click for the same lift, so the switch toggles once.
607
+ */
608
+ clickInput() {
609
+ const input = this.elements?.input;
610
+ if (input != null) {
611
+ clickForLift(input);
612
+ }
613
+ }
614
+
615
+ /** If the owner kept the old value, the visuals go back to it. */
616
+ scheduleReconcile() {
617
+ if (this.reconcileTimer != null) {
618
+ clearTimeout(this.reconcileTimer);
619
+ }
620
+ this.reconcileTimer = setTimeout(() => {
621
+ this.reconcileTimer = null;
622
+ if (this.drag == null && this.isVisuallyOn !== this.isOn) {
623
+ this.pendingTravel = false;
624
+ this.showSide(this.isOn, now(), undefined, true);
625
+ }
626
+ }, 0);
627
+ }
628
+
629
+ /** The touch ended without a release (cancelled, or the switch turned off). */
630
+ abandon(time) {
631
+ this.drag = null;
632
+ this.showSide(this.isOn, time, undefined, true);
633
+ this.pressEnded(time, true);
634
+ }
635
+
636
+ // --- Visuals ---------------------------------------------------------------
637
+
638
+ rest(isOn) {
639
+ return isOn ? this.geometry.travel : 0;
640
+ }
641
+
642
+ /** The animator's x for a thumb offset, relative to its CSS place. */
643
+ toX(offset) {
644
+ return this.direction * (offset - this.rest(this.isOn));
645
+ }
646
+
647
+ /** The thumb's offset on screen at `time`, from the curve. */
648
+ offsetAt(time) {
649
+ const x = this.thumb?.get('x', time) ?? 0;
650
+ return this.rest(this.isOn) + this.direction * x;
651
+ }
652
+ showWell(isOn, time, touchRelease = false) {
653
+ this.isVisuallyOn = isOn;
654
+ this.paintFade();
655
+ this.animateFade(time, undefined, touchRelease);
656
+ }
657
+
658
+ /**
659
+ * The fade layer heads for the visuals, on UIKit's well springs (on:
660
+ * 0.68 s, off: 0.40 s). It is clear when they show the value. It is opaque,
661
+ * the other fill, when they show the other side.
662
+ */
663
+ animateFade(time, velocity, touchRelease = false) {
664
+ // Under reduced motion the animator plays this as its cross-fade.
665
+ this.fade?.animate({
666
+ opacity: this.isVisuallyOn === this.isOn ? 0 : 1
667
+ }, {
668
+ spring: this.isVisuallyOn ? switchControl.wellOn : switchControl.wellOff,
669
+ velocity: velocity == null ? undefined : {
670
+ opacity: velocity
671
+ }
672
+ }, {
673
+ touchRelease
674
+ });
675
+ }
676
+
677
+ /**
678
+ * The track now shows the new value's fill. The fade layer swaps to the
679
+ * other fill and to the complement of its opacity, so nothing changes on
680
+ * screen. It keeps heading where the visuals head, on the running clock.
681
+ */
682
+ swapFade(time) {
683
+ const fade = this.fade;
684
+ if (fade == null) {
685
+ return;
686
+ }
687
+ const opacity = fade.get('opacity', time);
688
+ const fadeVelocity = fade.getVelocity('opacity', time);
689
+ this.paintFade();
690
+ fade.rebase({
691
+ opacity: 1 - 2 * opacity
692
+ });
693
+ this.animateFade(time, -fadeVelocity);
694
+ }
695
+
696
+ /**
697
+ * Holds the track's own fill at the previous value's (the other state's,
698
+ * now) until the fade lands. False when there is nothing to read it from.
699
+ */
700
+ holdBase() {
701
+ const track = this.elements?.track;
702
+ const fade = this.fade;
703
+ if (track == null || fade == null || this.otherTrack == null) {
704
+ return false;
705
+ }
706
+ track.style.setProperty(BASE_FILL, readFillOf(track, this.otherTrack));
707
+ this.baseHeld = true;
708
+ const hold = ++this.baseHold;
709
+ void fade.atRest(['opacity']).then(() => {
710
+ if (hold === this.baseHold) {
711
+ this.landBase(now());
712
+ }
713
+ });
714
+ return true;
715
+ }
716
+
717
+ /**
718
+ * Ends a held fill: the track shows its value's fill again and the fade
719
+ * layer swaps under it. Once the fade has landed, the layer is opaque and
720
+ * nothing changes on screen. Called early, by a new touch, value or other
721
+ * state, the swap keeps the picture where it is.
722
+ */
723
+ landBase(time) {
724
+ if (!this.baseHeld) {
725
+ return;
726
+ }
727
+ this.baseHeld = false;
728
+ this.baseHold++;
729
+ this.elements?.track.style.removeProperty(BASE_FILL);
730
+ this.swapFade(time);
731
+ }
732
+
733
+ /** The fade layer's colour: the track's fill in its other state. */
734
+ paintFade() {
735
+ const track = this.elements?.track;
736
+ if (track == null || this.fade == null || this.otherTrack == null) {
737
+ return;
738
+ }
739
+ track.style.setProperty(FADE_FILL, readFillOf(track, this.otherTrack));
740
+ }
741
+
742
+ /** Track color and thumb head for one side. */
743
+ showSide(isOn, time, velocity, touchRelease = false) {
744
+ if (isOn !== this.isVisuallyOn) {
745
+ this.showWell(isOn, time, touchRelease);
746
+ }
747
+ // Under reduced motion the animator cross-fades this travel: the thumb
748
+ // fades out where it is and back in at its rest.
749
+ this.thumb?.animate({
750
+ x: this.toX(this.rest(isOn))
751
+ }, {
752
+ spring: TRAVEL,
753
+ velocity: velocity == null ? undefined : {
754
+ x: velocity
755
+ }
756
+ }, {
757
+ touchRelease
758
+ });
759
+ }
760
+
761
+ /** The press began: the switch holds the touch and the thumb lifts. */
762
+ pressBegan(time) {
763
+ this.pressTime = time;
764
+ this.lift(time);
765
+ }
766
+
767
+ /** The press ended (a release, a cancel or the switch turning off). */
768
+ pressEnded(time = now(), touchRelease = false) {
769
+ this.pressTime = null;
770
+ this.settle(time, touchRelease);
771
+ }
772
+
773
+ /**
774
+ * The thumb grows about its center into half the gap around it, and its
775
+ * lifted shadow fades in. Under reduced motion nothing lifts: the lift is
776
+ * feedback with no fade of its own.
777
+ */
778
+ lift(time) {
779
+ if (this.thumb == null || this.thumb.reducedMotion() !== 'off') {
780
+ return;
781
+ }
782
+ this.liftTime = time;
783
+ const lift = this.thumb.animate({
784
+ scaleX: this.geometry.liftScaleX,
785
+ scaleY: this.geometry.liftScaleY
786
+ }, {
787
+ spring: switchControl.lift
788
+ });
789
+ this.shadow?.animate({
790
+ opacity: 1
791
+ }, {
792
+ spring: switchControl.lift
793
+ });
794
+ // A lift from rest starts at the frame that shows it: the minimum lift
795
+ // counts from there.
796
+ void lift.started.then(start => {
797
+ if (this.liftTime === time) {
798
+ this.liftTime = start;
799
+ }
800
+ });
801
+ }
802
+
803
+ /**
804
+ * The thumb settles back after the press, no sooner than the minimum lift
805
+ * time after it lifted. One curve per property, built now, starts the
806
+ * settle on the compositor's clock.
807
+ */
808
+ settle(time, touchRelease) {
809
+ const liftTime = this.liftTime;
810
+ if (liftTime == null) {
811
+ return;
812
+ }
813
+ this.liftTime = null;
814
+ const lift = switchControl.lift;
815
+ const settle = switchControl.settle;
816
+ this.settleAt = settleTime(time, liftTime);
817
+ const hold = (this.settleAt - time) / 1000;
818
+ const play = (animator, property, lifted, rest, threshold) => {
819
+ if (animator == null) {
820
+ return;
821
+ }
822
+ animator.play({
823
+ [property]: liftThenSettle({
824
+ from: animator.get(property, time),
825
+ velocity: animator.getVelocity(property, time),
826
+ lifted,
827
+ rest,
828
+ holdSeconds: hold,
829
+ threshold,
830
+ lift,
831
+ settle
832
+ })
833
+ }, {
834
+ touchRelease
835
+ });
836
+ };
837
+ play(this.thumb, 'scaleX', this.geometry.liftScaleX, 1, 1e-4);
838
+ play(this.thumb, 'scaleY', this.geometry.liftScaleY, 1, 1e-4);
839
+ play(this.shadow, 'opacity', 1, 0, 1e-3);
840
+ }
841
+
842
+ /**
843
+ * The thumb's box changed size with the value: the on circle is larger.
844
+ * Its scale carries the size it showed, so nothing jumps. Then it heads for
845
+ * the new box through the settle, or to the lift a held press keeps.
846
+ */
847
+ rescaleThumb(before, after, time) {
848
+ const thumb = this.thumb;
849
+ if (thumb == null || !(before.thumbWidth > 0 && before.thumbHeight > 0) || !(after.thumbWidth > 0 && after.thumbHeight > 0) || before.thumbWidth === after.thumbWidth && before.thumbHeight === after.thumbHeight) {
850
+ return;
851
+ }
852
+ const held = this.liftTime != null;
853
+ const hold = this.settleAt == null ? 0 : Math.max(0, this.settleAt - time) / 1000;
854
+ for (const [property, factor, lifted] of [['scaleX', before.thumbWidth / after.thumbWidth, before.liftScaleX], ['scaleY', before.thumbHeight / after.thumbHeight, before.liftScaleY]]) {
855
+ const keep = lifted * factor;
856
+ thumb.play({
857
+ [property]: liftThenSettle({
858
+ from: thumb.get(property, time) * factor,
859
+ velocity: thumb.getVelocity(property, time) * factor,
860
+ lifted: keep,
861
+ rest: held ? keep : 1,
862
+ holdSeconds: held ? 0 : hold,
863
+ threshold: 1e-4,
864
+ lift: switchControl.lift,
865
+ settle: switchControl.settle
866
+ })
867
+ });
868
+ }
869
+ }
870
+ clearTimers() {
871
+ this.endBrowserClickWait?.();
872
+ this.endBrowserClickWait = null;
873
+ if (this.reconcileTimer != null) {
874
+ clearTimeout(this.reconcileTimer);
875
+ this.reconcileTimer = null;
876
+ }
877
+ }
878
+ }
879
+
880
+ /**
881
+ * Switch's gestures, attached for every pointer, with the touch
882
+ * presentation under a coarse primary pointer. Its parts
883
+ * must be rendered (and styled for it) whether or not it is active; it only
884
+ * animates and listens.
885
+ */
886
+ export function useSwitchTouch(parts, {
887
+ isOn,
888
+ isInteractive,
889
+ isDisabled,
890
+ trackSize,
891
+ otherTrackProps
892
+ }) {
893
+ const {
894
+ isTouch
895
+ } = useTouchPresentation();
896
+ const [trackWidth, trackHeight] = trackSize;
897
+ const geometry = useMemo(() => switchTouchGeometry(trackWidth, trackHeight), [trackWidth, trackHeight]);
898
+ const otherTrack = trackStateOf(otherTrackProps);
899
+ const [controller] = useState(() => new SwitchTouchController(isOn, geometry));
900
+
901
+ // Syncs the touch controller's animators with the value. It runs first: the
902
+ // thumb's CSS place and the track's fill have just changed with the value.
903
+ useIsomorphicLayoutEffect(() => {
904
+ controller.setOtherTrack(otherTrack);
905
+ controller.setValue(isOn);
906
+ });
907
+
908
+ // Syncs the controller's thumb geometry with the track's size.
909
+ useIsomorphicLayoutEffect(() => {
910
+ controller.setGeometry(geometry);
911
+ }, [controller, geometry]);
912
+
913
+ // Syncs whether the controller's gestures take a press.
914
+ useIsomorphicLayoutEffect(() => {
915
+ controller.setInteractive(isInteractive);
916
+ }, [controller, isInteractive]);
917
+
918
+ // Attaches the controller's DOM listeners and animators to the switch's
919
+ // parts, and detaches them on cleanup.
920
+ useIsomorphicLayoutEffect(() => {
921
+ const surface = parts.surface.current;
922
+ const input = parts.input.current;
923
+ const thumb = parts.thumb.current;
924
+ const track = parts.track.current;
925
+ // A disabled switch takes no press: no listener is active. A busy one
926
+ // stays attached (setInteractive ignores its presses),
927
+ // so the change that made it busy keeps its motion.
928
+ if (isDisabled || surface == null || input == null || thumb == null || track == null) {
929
+ return undefined;
930
+ }
931
+ controller.attach({
932
+ surface,
933
+ input,
934
+ thumb,
935
+ track
936
+ }, isTouch ? 'touch' : 'pointer');
937
+ return () => controller.detach();
938
+ }, [controller, isTouch, isDisabled, parts]);
939
+ }