@astryxdesign/core 0.7.5 → 0.7.6-canary.0ef60dd

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 (559) hide show
  1. package/dist/AlertDialog/AlertDialog.d.ts +1 -1
  2. package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
  3. package/dist/AlertDialog/AlertDialog.js +5 -5
  4. package/dist/Avatar/Avatar.d.ts.map +1 -1
  5. package/dist/Avatar/Avatar.js +12 -3
  6. package/dist/Badge/Badge.d.ts.map +1 -1
  7. package/dist/Badge/Badge.js +7 -1
  8. package/dist/BottomSheet/BottomSheet.js +1 -1
  9. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  10. package/dist/BottomSheet/BottomSheetPanel.js +2 -1
  11. package/dist/BottomSheet/useSheetGestures.d.ts +12 -0
  12. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  13. package/dist/BottomSheet/useSheetGestures.js +30 -3
  14. package/dist/Button/Button.js +4 -4
  15. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  16. package/dist/CheckboxInput/CheckboxInput.js +6 -5
  17. package/dist/ClickableCard/ClickableCard.d.ts.map +1 -1
  18. package/dist/ClickableCard/ClickableCard.js +37 -4
  19. package/dist/DateInput/DateInput.d.ts.map +1 -1
  20. package/dist/DateInput/DateInput.js +12 -4
  21. package/dist/DateInput/MonthScroller.d.ts.map +1 -1
  22. package/dist/DateInput/MonthScroller.js +101 -15
  23. package/dist/DateInput/TouchDateField.d.ts.map +1 -1
  24. package/dist/DateInput/TouchDateField.js +8 -3
  25. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  26. package/dist/DateRangeInput/DateRangeInput.js +1 -1
  27. package/dist/DateTimeInput/DateTimeInput.d.ts +5 -2
  28. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  29. package/dist/DateTimeInput/DateTimeInput.js +23 -12
  30. package/dist/DateTimeInput/NativeTimeSegment.d.ts.map +1 -1
  31. package/dist/DateTimeInput/NativeTimeSegment.js +5 -4
  32. package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
  33. package/dist/DateTimeInput/TouchDateTimeField.js +4 -3
  34. package/dist/Dialog/Dialog.d.ts.map +1 -1
  35. package/dist/Dialog/Dialog.js +34 -9
  36. package/dist/Dialog/DialogHeader.d.ts.map +1 -1
  37. package/dist/Dialog/DialogHeader.js +5 -4
  38. package/dist/Divider/Divider.d.ts.map +1 -1
  39. package/dist/Divider/Divider.js +2 -1
  40. package/dist/Drawer/Drawer.d.ts +1 -0
  41. package/dist/Drawer/Drawer.d.ts.map +1 -1
  42. package/dist/Drawer/Drawer.js +7 -2
  43. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  44. package/dist/DropdownMenu/DropdownMenu.js +7 -3
  45. package/dist/DropdownMenu/MenuBottomSheetActionList.d.ts.map +1 -1
  46. package/dist/DropdownMenu/MenuBottomSheetActionList.js +6 -5
  47. package/dist/DropdownMenu/lazyMenuBottomSheet.d.ts +20 -2
  48. package/dist/DropdownMenu/lazyMenuBottomSheet.d.ts.map +1 -1
  49. package/dist/DropdownMenu/lazyMenuBottomSheet.js +31 -3
  50. package/dist/DropdownMenu/renderDropdownItems.d.ts.map +1 -1
  51. package/dist/DropdownMenu/renderDropdownItems.js +21 -16
  52. package/dist/EmptyState/EmptyState.d.ts.map +1 -1
  53. package/dist/EmptyState/EmptyState.js +2 -1
  54. package/dist/Field/FieldLabel.d.ts +1 -1
  55. package/dist/Field/FieldLabel.d.ts.map +1 -1
  56. package/dist/Field/FieldLabel.js +4 -4
  57. package/dist/Field/InputClearButton.js +3 -3
  58. package/dist/Field/PanelSearchInput.js +2 -2
  59. package/dist/FieldStatus/FieldStatus.js +2 -2
  60. package/dist/FileInput/FileInput.d.ts.map +1 -1
  61. package/dist/FileInput/FileInput.js +7 -1
  62. package/dist/Heading/Heading.js +1 -1
  63. package/dist/Icon/Icon.js +1 -1
  64. package/dist/Indicator/CheckIndicator.d.ts.map +1 -1
  65. package/dist/Indicator/CheckIndicator.js +2 -1
  66. package/dist/Indicator/CheckboxIndicator.d.ts.map +1 -1
  67. package/dist/Indicator/CheckboxIndicator.js +3 -1
  68. package/dist/Indicator/RadioIndicator.d.ts.map +1 -1
  69. package/dist/Indicator/RadioIndicator.js +3 -1
  70. package/dist/Item/Item.d.ts.map +1 -1
  71. package/dist/Item/Item.js +2 -1
  72. package/dist/Item/ItemSwipeLayer.js +1 -1
  73. package/dist/Layer/popoverOperations.d.ts +27 -0
  74. package/dist/Layer/popoverOperations.d.ts.map +1 -0
  75. package/dist/Layer/popoverOperations.js +159 -0
  76. package/dist/Layer/useLayer.d.ts +1 -1
  77. package/dist/Layer/useLayer.d.ts.map +1 -1
  78. package/dist/Layer/useLayer.js +93 -59
  79. package/dist/Layout/Layout.js +1 -1
  80. package/dist/Layout/LayoutContent.js +1 -1
  81. package/dist/Layout/LayoutFooter.js +1 -1
  82. package/dist/Layout/LayoutHeader.js +1 -1
  83. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  84. package/dist/Lightbox/Lightbox.js +5 -0
  85. package/dist/Lightbox/LightboxViewport.a11y.browser.spec.js +5 -4
  86. package/dist/List/List.js +1 -1
  87. package/dist/List/ListItem.js +3 -3
  88. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  89. package/dist/MobileNav/MobileNav.js +7 -2
  90. package/dist/MultiSelector/CreateRow.a11y.chromium.spec.js +7 -6
  91. package/dist/MultiSelector/MultiSelector.d.ts +1 -1
  92. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  93. package/dist/MultiSelector/MultiSelector.js +26 -10
  94. package/dist/NumberInput/NumberInput.d.ts +3 -1
  95. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  96. package/dist/NumberInput/NumberInput.js +3 -3
  97. package/dist/NumberInput/numberParser.d.ts +3 -0
  98. package/dist/NumberInput/numberParser.d.ts.map +1 -1
  99. package/dist/NumberInput/numberParser.js +7 -44
  100. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  101. package/dist/ProgressBar/ProgressBar.js +16 -12
  102. package/dist/Resizable/useResizable.d.ts.map +1 -1
  103. package/dist/Resizable/useResizable.js +28 -2
  104. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  105. package/dist/SegmentedControl/SegmentedControlItem.js +4 -1
  106. package/dist/Selector/useSelectorPresentation.d.ts +8 -1
  107. package/dist/Selector/useSelectorPresentation.d.ts.map +1 -1
  108. package/dist/Selector/useSelectorPresentation.js +20 -4
  109. package/dist/Skeleton/Skeleton.d.ts.map +1 -1
  110. package/dist/Skeleton/Skeleton.js +1 -1
  111. package/dist/Slider/Slider.d.ts.map +1 -1
  112. package/dist/Slider/Slider.js +10 -2
  113. package/dist/Spinner/Spinner.d.ts.map +1 -1
  114. package/dist/Spinner/Spinner.js +3 -3
  115. package/dist/Stack/Stack.js +1 -1
  116. package/dist/Stack/StackItem.js +1 -1
  117. package/dist/TabList/TabList.d.ts.map +1 -1
  118. package/dist/TabList/TabList.js +16 -1
  119. package/dist/Table/plugins/columnResize/useTableColumnResize.d.ts.map +1 -1
  120. package/dist/Table/plugins/columnResize/useTableColumnResize.js +9 -1
  121. package/dist/Text/Text.js +1 -1
  122. package/dist/Text/useTruncation.d.ts.map +1 -1
  123. package/dist/Text/useTruncation.js +23 -5
  124. package/dist/TextArea/TextArea.d.ts +1 -1
  125. package/dist/TextArea/TextArea.d.ts.map +1 -1
  126. package/dist/TextArea/TextArea.js +13 -2
  127. package/dist/TextInput/TextInput.d.ts.map +1 -1
  128. package/dist/TextInput/TextInput.js +3 -3
  129. package/dist/TimeInput/TimeInput.d.ts +6 -2
  130. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  131. package/dist/TimeInput/TimeInput.js +21 -14
  132. package/dist/TimeInput/TouchTimeField.d.ts.map +1 -1
  133. package/dist/TimeInput/TouchTimeField.js +5 -4
  134. package/dist/Timestamp/Timestamp.d.ts.map +1 -1
  135. package/dist/Timestamp/Timestamp.js +2 -2
  136. package/dist/Timestamp/TimestampHoverCard.js +4 -4
  137. package/dist/Toast/Toast.d.ts.map +1 -1
  138. package/dist/Toast/Toast.js +60 -20
  139. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  140. package/dist/Toast/ToastViewport.js +82 -51
  141. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  142. package/dist/Tokenizer/Tokenizer.js +13 -2
  143. package/dist/Tokenizer/TokenizerBottomSheet.js +3 -3
  144. package/dist/Toolbar/Toolbar.d.ts.map +1 -1
  145. package/dist/Toolbar/Toolbar.js +2 -1
  146. package/dist/TopNav/TopNavMegaMenu.d.ts.map +1 -1
  147. package/dist/TopNav/TopNavMegaMenu.js +3 -0
  148. package/dist/TopNav/TopNavMenu.d.ts.map +1 -1
  149. package/dist/TopNav/TopNavMenu.js +1 -0
  150. package/dist/Typeahead/Typeahead.d.ts +1 -1
  151. package/dist/Typeahead/Typeahead.d.ts.map +1 -1
  152. package/dist/Typeahead/Typeahead.js +9 -1
  153. package/dist/astryx.css +20 -4
  154. package/dist/gestures/GestureArena.d.ts +6 -0
  155. package/dist/gestures/GestureArena.d.ts.map +1 -1
  156. package/dist/gestures/GestureArena.js +39 -0
  157. package/dist/gestures/GestureHost.d.ts +352 -0
  158. package/dist/gestures/GestureHost.d.ts.map +1 -0
  159. package/dist/gestures/GestureHost.js +1773 -0
  160. package/dist/gestures/GestureRecognizer.d.ts +10 -0
  161. package/dist/gestures/GestureRecognizer.d.ts.map +1 -1
  162. package/dist/gestures/GestureRecognizer.js +16 -0
  163. package/dist/gestures/LongPressGestureRecognizer.d.ts +1 -0
  164. package/dist/gestures/LongPressGestureRecognizer.d.ts.map +1 -1
  165. package/dist/gestures/LongPressGestureRecognizer.js +3 -0
  166. package/dist/gestures/PanGestureRecognizer.d.ts +1 -0
  167. package/dist/gestures/PanGestureRecognizer.d.ts.map +1 -1
  168. package/dist/gestures/PanGestureRecognizer.js +3 -0
  169. package/dist/gestures/PinchGestureRecognizer.d.ts +31 -0
  170. package/dist/gestures/PinchGestureRecognizer.d.ts.map +1 -0
  171. package/dist/gestures/PinchGestureRecognizer.js +128 -0
  172. package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts +71 -0
  173. package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts.map +1 -0
  174. package/dist/gestures/ScreenEdgePanGestureRecognizer.js +223 -0
  175. package/dist/gestures/SwipeGestureRecognizer.d.ts +37 -0
  176. package/dist/gestures/SwipeGestureRecognizer.d.ts.map +1 -0
  177. package/dist/gestures/SwipeGestureRecognizer.js +148 -0
  178. package/dist/gestures/TapGestureRecognizer.d.ts +1 -0
  179. package/dist/gestures/TapGestureRecognizer.d.ts.map +1 -1
  180. package/dist/gestures/TapGestureRecognizer.js +3 -0
  181. package/dist/gestures/VelocityTracker.d.ts +6 -2
  182. package/dist/gestures/VelocityTracker.d.ts.map +1 -1
  183. package/dist/gestures/VelocityTracker.js +7 -3
  184. package/dist/gestures/haptics.d.ts +65 -0
  185. package/dist/gestures/haptics.d.ts.map +1 -0
  186. package/dist/gestures/haptics.js +182 -0
  187. package/dist/gestures/nativeScroll.d.ts +42 -0
  188. package/dist/gestures/nativeScroll.d.ts.map +1 -0
  189. package/dist/gestures/nativeScroll.js +228 -0
  190. package/dist/gestures/touchAction.d.ts +60 -0
  191. package/dist/gestures/touchAction.d.ts.map +1 -0
  192. package/dist/gestures/touchAction.js +157 -0
  193. package/dist/gestures/touchActionRule.d.ts +34 -0
  194. package/dist/gestures/touchActionRule.d.ts.map +1 -0
  195. package/dist/gestures/touchActionRule.js +140 -0
  196. package/dist/gestures/types.d.ts +18 -7
  197. package/dist/gestures/types.d.ts.map +1 -1
  198. package/dist/gestures/types.js +22 -2
  199. package/dist/hooks/index.d.ts +1 -1
  200. package/dist/hooks/index.d.ts.map +1 -1
  201. package/dist/hooks/modalAnnounce.d.ts.map +1 -1
  202. package/dist/hooks/modalAnnounce.js +107 -61
  203. package/dist/hooks/useAdaptivePresentation.d.ts.map +1 -1
  204. package/dist/hooks/useAdaptivePresentation.js +4 -1
  205. package/dist/hooks/useAnnounce.d.ts +101 -42
  206. package/dist/hooks/useAnnounce.d.ts.map +1 -1
  207. package/dist/hooks/useAnnounce.js +161 -75
  208. package/dist/hooks/useAnnounceRenderedText.d.ts +11 -3
  209. package/dist/hooks/useAnnounceRenderedText.d.ts.map +1 -1
  210. package/dist/hooks/useAnnounceRenderedText.js +5 -3
  211. package/dist/hooks/useBusyAnnouncement.d.ts.map +1 -1
  212. package/dist/hooks/useBusyAnnouncement.js +6 -12
  213. package/dist/hooks/useMenuHover.d.ts.map +1 -1
  214. package/dist/hooks/useMenuHover.js +12 -1
  215. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  216. package/dist/i18n/generated-locales/en.generated.js +5 -0
  217. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  218. package/dist/i18n/generated-locales/pseudo.generated.js +5 -0
  219. package/dist/motion/animator.d.ts +7 -1
  220. package/dist/motion/animator.d.ts.map +1 -1
  221. package/dist/motion/animator.js +119 -27
  222. package/dist/theme/defineTheme.d.ts +19 -5
  223. package/dist/theme/defineTheme.d.ts.map +1 -1
  224. package/dist/theme/defineTheme.js +64 -4
  225. package/dist/theme/domainTokens/domainTokenDefaults.d.ts +3 -0
  226. package/dist/theme/domainTokens/domainTokenDefaults.d.ts.map +1 -0
  227. package/dist/theme/domainTokens/domainTokenDefaults.js +19 -0
  228. package/dist/theme/domainTokens/index.d.ts +5 -4
  229. package/dist/theme/domainTokens/index.d.ts.map +1 -1
  230. package/dist/theme/domainTokens/index.js +5 -9
  231. package/dist/theme/index.d.ts +1 -0
  232. package/dist/theme/index.d.ts.map +1 -1
  233. package/dist/theme/motionKnobs.d.ts +56 -0
  234. package/dist/theme/motionKnobs.d.ts.map +1 -0
  235. package/dist/theme/motionKnobs.js +48 -0
  236. package/dist/theme/resolveThemeValues.d.ts +11 -4
  237. package/dist/theme/resolveThemeValues.d.ts.map +1 -1
  238. package/dist/theme/resolveThemeValues.js +40 -4
  239. package/dist/theme/themeAdaptations.d.ts +7 -3
  240. package/dist/theme/themeAdaptations.d.ts.map +1 -1
  241. package/dist/theme/themeAdaptations.js +36 -7
  242. package/dist/theme/themeMotion.d.ts +96 -0
  243. package/dist/theme/themeMotion.d.ts.map +1 -0
  244. package/dist/theme/themeMotion.js +177 -0
  245. package/dist/theme/tokenReferences.d.ts +31 -0
  246. package/dist/theme/tokenReferences.d.ts.map +1 -0
  247. package/dist/theme/tokenReferences.js +132 -0
  248. package/dist/theme/tokens.d.ts +1 -0
  249. package/dist/theme/tokens.d.ts.map +1 -1
  250. package/dist/theme/tokens.js +9 -129
  251. package/dist/theme/tokens.stylex.d.ts +12 -0
  252. package/dist/theme/tokens.stylex.d.ts.map +1 -1
  253. package/dist/theme/tokens.stylex.js +12 -0
  254. package/dist/utils/focusReturn.d.ts +17 -1
  255. package/dist/utils/focusReturn.d.ts.map +1 -1
  256. package/dist/utils/focusReturn.js +11 -4
  257. package/dist/utils/getNodeText.d.ts +8 -0
  258. package/dist/utils/getNodeText.d.ts.map +1 -0
  259. package/dist/utils/getNodeText.js +37 -0
  260. package/dist/utils/interactionModality.d.ts +11 -2
  261. package/dist/utils/interactionModality.d.ts.map +1 -1
  262. package/dist/utils/interactionModality.js +58 -5
  263. package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
  264. package/dist/utils/interactionOverlay.stylex.js +17 -8
  265. package/dist/utils/plainDate.d.ts +2 -0
  266. package/dist/utils/plainDate.d.ts.map +1 -1
  267. package/dist/utils/plainDate.js +46 -3
  268. package/dist/utils/presentation.d.ts +50 -0
  269. package/dist/utils/presentation.d.ts.map +1 -0
  270. package/dist/utils/presentation.js +125 -0
  271. package/dist/utils/pressFeedback.d.ts.map +1 -1
  272. package/dist/utils/pressFeedback.js +20 -1
  273. package/dist/utils/primaryClick.d.ts +11 -0
  274. package/dist/utils/primaryClick.d.ts.map +1 -0
  275. package/dist/utils/primaryClick.js +25 -0
  276. package/dist/utils/timeFormat.d.ts +47 -0
  277. package/dist/utils/timeFormat.d.ts.map +1 -0
  278. package/dist/utils/timeFormat.js +240 -0
  279. package/dist/utils/touchPresentation.d.ts.map +1 -1
  280. package/dist/utils/touchPresentation.js +5 -3
  281. package/dist/utils/touchPresentation.stylex.d.ts +15 -0
  282. package/dist/utils/touchPresentation.stylex.d.ts.map +1 -0
  283. package/dist/utils/touchPresentation.stylex.js +33 -0
  284. package/dist/utils/unicodeDigits.d.ts +20 -0
  285. package/dist/utils/unicodeDigits.d.ts.map +1 -0
  286. package/dist/utils/unicodeDigits.js +70 -0
  287. package/locales/en.json +23 -3
  288. package/locales/pseudo.json +15 -0
  289. package/package.json +5 -4
  290. package/src/AlertDialog/AlertDialog.tsx +6 -5
  291. package/src/AlertDialog/__tests__/AlertDialog.a11y.chromium.spec.ts +18 -6
  292. package/src/Avatar/Avatar.spec.md +22 -22
  293. package/src/Avatar/Avatar.tsx +18 -1
  294. package/src/Avatar/__tests__/AvatarForcedColors.a11y.chromium.spec.ts +126 -0
  295. package/src/Badge/Badge.doc.mjs +1 -1
  296. package/src/Badge/Badge.tsx +19 -2
  297. package/src/Badge/__tests__/BadgeLargerText.a11y.chromium.spec.ts +260 -0
  298. package/src/BottomSheet/BottomSheet.test.tsx +46 -0
  299. package/src/BottomSheet/BottomSheet.tsx +1 -1
  300. package/src/BottomSheet/BottomSheetPanel.tsx +2 -1
  301. package/src/BottomSheet/useSheetGestures.test.ts +52 -0
  302. package/src/BottomSheet/useSheetGestures.ts +37 -6
  303. package/src/Breadcrumbs/__tests__/Breadcrumbs.a11y.chromium.spec.ts +18 -6
  304. package/src/Button/Button.tsx +4 -4
  305. package/src/Calendar/Calendar.spec.md +87 -48
  306. package/src/Calendar/__tests__/Calendar.a11y.chromium.spec.ts +21 -7
  307. package/src/Carousel/__tests__/Carousel.a11y.chromium.spec.ts +21 -7
  308. package/src/CheckboxInput/CheckboxInput.tsx +6 -5
  309. package/src/ClickableCard/ClickableCard.test.tsx +96 -0
  310. package/src/ClickableCard/ClickableCard.tsx +48 -4
  311. package/src/Collapsible/Collapsible.spec.md +2 -0
  312. package/src/Collapsible/CollapsibleGroup.spec.md +57 -29
  313. package/src/Collapsible/__tests__/Collapsible.a11y.chromium.spec.ts +18 -7
  314. package/src/Collapsible/__tests__/CollapsibleGroupAccordion.a11y.chromium.spec.ts +18 -6
  315. package/src/ComplexSelector/ComplexSelector.test.tsx +37 -0
  316. package/src/ContextMenu/ContextMenu.test.tsx +35 -0
  317. package/src/DateInput/DateInput.test.tsx +115 -3
  318. package/src/DateInput/DateInput.tsx +29 -14
  319. package/src/DateInput/DateInputTouch.test.tsx +76 -0
  320. package/src/DateInput/MonthScroller.tsx +106 -20
  321. package/src/DateInput/MonthScrollerSettle.test.tsx +165 -0
  322. package/src/DateInput/TouchDateField.tsx +14 -3
  323. package/src/DateInput/__tests__/MonthScrollerSteps.interaction.browser.spec.ts +312 -0
  324. package/src/DateRangeInput/DateRangeInput.test.tsx +46 -3
  325. package/src/DateRangeInput/DateRangeInput.tsx +16 -12
  326. package/src/DateTimeInput/DateTimeInput.doc.mjs +10 -8
  327. package/src/DateTimeInput/DateTimeInput.spec.md +75 -51
  328. package/src/DateTimeInput/DateTimeInput.test.tsx +81 -0
  329. package/src/DateTimeInput/DateTimeInput.tsx +46 -24
  330. package/src/DateTimeInput/NativeTimeSegment.tsx +4 -6
  331. package/src/DateTimeInput/TouchDateTimeField.tsx +3 -7
  332. package/src/Dialog/Dialog.test.tsx +216 -2
  333. package/src/Dialog/Dialog.tsx +42 -9
  334. package/src/Dialog/DialogHeader.tsx +5 -4
  335. package/src/Dialog/__tests__/DialogSecondDocument.a11y.browser.spec.ts +202 -0
  336. package/src/Divider/Divider.tsx +2 -1
  337. package/src/Drawer/Drawer.spec.md +111 -80
  338. package/src/Drawer/Drawer.test.tsx +35 -0
  339. package/src/Drawer/Drawer.tsx +13 -2
  340. package/src/Drawer/DrawerHeader.spec.md +181 -0
  341. package/src/Drawer/__tests__/DrawerNonModalPageScroll.a11y.chromium.spec.ts +267 -0
  342. package/src/DropdownMenu/DropdownMenu.test.tsx +41 -0
  343. package/src/DropdownMenu/DropdownMenu.tsx +10 -3
  344. package/src/DropdownMenu/DropdownMenuSubMenu.test.tsx +34 -0
  345. package/src/DropdownMenu/MenuBottomSheetActionList.tsx +6 -5
  346. package/src/DropdownMenu/__tests__/Menu.a11y.chromium.spec.ts +19 -7
  347. package/src/DropdownMenu/__tests__/MenuButton.a11y.chromium.spec.ts +21 -9
  348. package/src/DropdownMenu/lazyMenuBottomSheet.test.ts +60 -0
  349. package/src/DropdownMenu/lazyMenuBottomSheet.ts +36 -7
  350. package/src/DropdownMenu/renderDropdownItems.tsx +24 -19
  351. package/src/EmptyState/EmptyState.tsx +2 -1
  352. package/src/Field/FieldLabel.tsx +5 -4
  353. package/src/Field/InputClearButton.tsx +3 -3
  354. package/src/Field/PanelSearchInput.tsx +2 -2
  355. package/src/FieldStatus/FieldStatus.tsx +2 -2
  356. package/src/FileInput/FileInput.test.tsx +21 -0
  357. package/src/FileInput/FileInput.tsx +4 -1
  358. package/src/FormLayout/FormLayout.spec.md +7 -8
  359. package/src/Heading/Heading.tsx +1 -1
  360. package/src/Icon/Icon.tsx +1 -1
  361. package/src/Indicator/CheckIndicator.spec.md +47 -42
  362. package/src/Indicator/CheckIndicator.tsx +2 -1
  363. package/src/Indicator/CheckboxIndicator.spec.md +40 -37
  364. package/src/Indicator/CheckboxIndicator.tsx +3 -1
  365. package/src/Indicator/Indicator.spec.md +188 -0
  366. package/src/Indicator/RadioIndicator.tsx +3 -1
  367. package/src/Item/Item.tsx +2 -1
  368. package/src/Item/ItemSwipeLayer.tsx +1 -1
  369. package/src/Kbd/Kbd.spec.md +81 -38
  370. package/src/Layer/__tests__/LayerBrowserHide.a11y.chromium.spec.ts +126 -0
  371. package/src/Layer/popoverOperations.test.ts +205 -0
  372. package/src/Layer/popoverOperations.ts +172 -0
  373. package/src/Layer/useLayer.test.tsx +348 -1
  374. package/src/Layer/useLayer.tsx +118 -71
  375. package/src/Layout/Layout.spec.md +127 -131
  376. package/src/Layout/Layout.tsx +1 -1
  377. package/src/Layout/LayoutContent.spec.md +205 -0
  378. package/src/Layout/LayoutContent.tsx +1 -1
  379. package/src/Layout/LayoutFooter.spec.md +190 -0
  380. package/src/Layout/LayoutFooter.tsx +1 -1
  381. package/src/Layout/LayoutHeader.spec.md +193 -0
  382. package/src/Layout/LayoutHeader.tsx +1 -1
  383. package/src/Layout/LayoutPanel.spec.md +194 -0
  384. package/src/Layout/__tests__/Layout.a11y.chromium.spec.ts +18 -6
  385. package/src/Lightbox/Lightbox.test.tsx +18 -0
  386. package/src/Lightbox/Lightbox.tsx +5 -0
  387. package/src/Lightbox/LightboxViewport.a11y.browser.spec.ts +8 -4
  388. package/src/Link/__tests__/Link.a11y.chromium.spec.ts +18 -8
  389. package/src/List/List.tsx +1 -1
  390. package/src/List/ListItem.spec.md +205 -0
  391. package/src/List/ListItem.tsx +3 -3
  392. package/src/MetadataList/MetadataList.spec.md +187 -0
  393. package/src/MetadataList/MetadataListItem.spec.md +165 -0
  394. package/src/MobileNav/MobileNav.test.tsx +15 -0
  395. package/src/MobileNav/MobileNav.tsx +9 -1
  396. package/src/MobileNav/__tests__/MobileNavHeader.a11y.chromium.spec.ts +89 -0
  397. package/src/MoreMenu/MoreMenu.test.tsx +11 -0
  398. package/src/MultiSelector/CreateRow.a11y.chromium.spec.ts +7 -8
  399. package/src/MultiSelector/MultiSelector.spec.md +7 -4
  400. package/src/MultiSelector/MultiSelector.test.tsx +270 -1
  401. package/src/MultiSelector/MultiSelector.tsx +25 -10
  402. package/src/MultiSelector/__tests__/MultiSelector.listbox.a11y.test.tsx +8 -1
  403. package/src/NavMenu/NavHeadingMenu.spec.md +1 -5
  404. package/src/NumberInput/NumberInput.doc.mjs +13 -7
  405. package/src/NumberInput/NumberInput.spec.md +59 -37
  406. package/src/NumberInput/NumberInput.tsx +13 -3
  407. package/src/NumberInput/__tests__/NumberInput.coarse-pointer.a11y.chromium.spec.ts +102 -0
  408. package/src/NumberInput/numberParser.ts +7 -45
  409. package/src/ProgressBar/ProgressBar.test.tsx +108 -32
  410. package/src/ProgressBar/ProgressBar.tsx +58 -10
  411. package/src/ProgressBar/__tests__/ProgressBar.a11y.chromium.spec.ts +21 -9
  412. package/src/ProgressBar/__tests__/ProgressBarMotion.a11y.chromium.spec.ts +831 -0
  413. package/src/Resizable/__tests__/ResizeHandle.a11y.chromium.spec.ts +21 -14
  414. package/src/Resizable/useResizable.test.ts +43 -0
  415. package/src/Resizable/useResizable.ts +32 -9
  416. package/src/SegmentedControl/SegmentedControl.test.tsx +84 -0
  417. package/src/SegmentedControl/SegmentedControlItem.tsx +11 -5
  418. package/src/Selector/Selector.test.tsx +90 -1
  419. package/src/Selector/__tests__/Selector.combobox.a11y.test.tsx +8 -1
  420. package/src/Selector/__tests__/Selector.listbox.a11y.test.tsx +8 -1
  421. package/src/Selector/useSelectorPresentation.ts +31 -3
  422. package/src/SideNav/SideNav.test.tsx +27 -0
  423. package/src/SideNav/__tests__/SideNavRailMotion.interaction.browser.spec.ts +176 -51
  424. package/src/Skeleton/Skeleton.tsx +3 -1
  425. package/src/Slider/Slider.test.tsx +31 -0
  426. package/src/Slider/Slider.tsx +8 -3
  427. package/src/Slider/__tests__/Slider.a11y.chromium.spec.ts +19 -7
  428. package/src/Spinner/Spinner.tsx +5 -3
  429. package/src/Stack/Stack.tsx +1 -1
  430. package/src/Stack/StackItem.tsx +1 -1
  431. package/src/TabList/TabList.test.tsx +58 -4
  432. package/src/TabList/TabList.tsx +16 -1
  433. package/src/TabList/__tests__/TabPressPointer.interaction.browser.spec.ts +163 -0
  434. package/src/Table/__tests__/Table.a11y.chromium.spec.ts +18 -6
  435. package/src/Table/plugins/columnResize/useTableColumnResize.test.tsx +22 -0
  436. package/src/Table/plugins/columnResize/useTableColumnResize.tsx +8 -4
  437. package/src/Text/Text.tsx +1 -1
  438. package/src/Text/useTruncation.test.tsx +128 -1
  439. package/src/Text/useTruncation.ts +23 -5
  440. package/src/TextArea/TextArea.spec.md +10 -13
  441. package/src/TextArea/TextArea.test.tsx +60 -0
  442. package/src/TextArea/TextArea.tsx +15 -1
  443. package/src/TextInput/TextInput.test.tsx +21 -0
  444. package/src/TextInput/TextInput.tsx +3 -1
  445. package/src/TimeInput/NativeTimeInput.test.tsx +17 -0
  446. package/src/TimeInput/Presentation.test.tsx +21 -0
  447. package/src/TimeInput/TimeInput.doc.mjs +8 -8
  448. package/src/TimeInput/TimeInput.spec.md +45 -48
  449. package/src/TimeInput/TimeInput.test.tsx +76 -0
  450. package/src/TimeInput/TimeInput.tsx +36 -18
  451. package/src/TimeInput/TouchTimeField.tsx +4 -6
  452. package/src/Timestamp/Timestamp.spec.md +6 -12
  453. package/src/Timestamp/Timestamp.test.tsx +30 -5
  454. package/src/Timestamp/Timestamp.tsx +6 -2
  455. package/src/Timestamp/TimestampHoverCard.tsx +4 -4
  456. package/src/Toast/Toast.spec.md +14 -20
  457. package/src/Toast/Toast.tsx +104 -36
  458. package/src/Toast/ToastViewport.test.tsx +719 -1
  459. package/src/Toast/ToastViewport.tsx +100 -50
  460. package/src/Tokenizer/Tokenizer.spec.md +5 -3
  461. package/src/Tokenizer/Tokenizer.test.tsx +68 -0
  462. package/src/Tokenizer/Tokenizer.tsx +14 -2
  463. package/src/Tokenizer/TokenizerBottomSheet.test.tsx +15 -4
  464. package/src/Tokenizer/TokenizerBottomSheet.tsx +3 -3
  465. package/src/Toolbar/Toolbar.spec.md +5 -6
  466. package/src/Toolbar/Toolbar.test.tsx +30 -0
  467. package/src/Toolbar/Toolbar.tsx +2 -1
  468. package/src/Toolbar/__tests__/Toolbar.a11y.chromium.spec.ts +18 -6
  469. package/src/Tooltip/__tests__/Tooltip.a11y.chromium.spec.ts +18 -7
  470. package/src/TopNav/TopNav.test.tsx +27 -0
  471. package/src/TopNav/TopNavMegaMenu.test.tsx +21 -0
  472. package/src/TopNav/TopNavMegaMenu.tsx +4 -1
  473. package/src/TopNav/TopNavMenu.test.tsx +17 -0
  474. package/src/TopNav/TopNavMenu.tsx +1 -0
  475. package/src/Typeahead/Typeahead.test.tsx +40 -0
  476. package/src/Typeahead/Typeahead.tsx +12 -1
  477. package/src/__tests__/pressState.ts +8 -4
  478. package/src/gestures/GestureArena.ts +35 -0
  479. package/src/gestures/GestureHost.ts +2065 -0
  480. package/src/gestures/GestureRecognizer.ts +18 -0
  481. package/src/gestures/LongPressGestureRecognizer.ts +4 -0
  482. package/src/gestures/PanGestureRecognizer.ts +4 -0
  483. package/src/gestures/PinchGestureRecognizer.ts +148 -0
  484. package/src/gestures/ScreenEdgePanGestureRecognizer.ts +256 -0
  485. package/src/gestures/SwipeGestureRecognizer.ts +197 -0
  486. package/src/gestures/TapGestureRecognizer.ts +4 -0
  487. package/src/gestures/VelocityTracker.ts +10 -3
  488. package/src/gestures/__tests__/GestureHost.test.ts +2087 -0
  489. package/src/gestures/__tests__/PanGestureRecognizer.test.ts +4 -4
  490. package/src/gestures/__tests__/PinchGestureRecognizer.test.ts +74 -0
  491. package/src/gestures/__tests__/ScreenEdgePanGestureRecognizer.test.ts +498 -0
  492. package/src/gestures/__tests__/SwipeGestureRecognizer.test.ts +108 -0
  493. package/src/gestures/__tests__/arena.test.ts +5 -0
  494. package/src/gestures/__tests__/arenaPinchSwipeEdge.test.ts +193 -0
  495. package/src/gestures/__tests__/browser/build-fixture.mjs +46 -0
  496. package/src/gestures/__tests__/browser/fixture.ts +307 -0
  497. package/src/gestures/__tests__/browser/gestures.interaction.browser.spec.ts +1137 -0
  498. package/src/gestures/__tests__/browserNegotiation.test.ts +293 -0
  499. package/src/gestures/__tests__/haptics.test.ts +187 -0
  500. package/src/gestures/__tests__/harness.ts +21 -2
  501. package/src/gestures/__tests__/recognizerKind.test.ts +78 -0
  502. package/src/gestures/__tests__/touchActionRule.test.ts +54 -0
  503. package/src/gestures/haptics.ts +203 -0
  504. package/src/gestures/nativeScroll.ts +277 -0
  505. package/src/gestures/touchAction.ts +191 -0
  506. package/src/gestures/touchActionRule.ts +157 -0
  507. package/src/gestures/types.ts +30 -9
  508. package/src/hooks/index.ts +5 -1
  509. package/src/hooks/modalAnnounce.ts +129 -72
  510. package/src/hooks/useAdaptivePresentation.ts +4 -1
  511. package/src/hooks/useAnnounce.doc.mjs +35 -3
  512. package/src/hooks/useAnnounce.replace.test.tsx +516 -0
  513. package/src/hooks/useAnnounce.ts +209 -102
  514. package/src/hooks/useAnnounceRenderedText.adopters.test.tsx +10 -1
  515. package/src/hooks/useAnnounceRenderedText.ts +17 -3
  516. package/src/hooks/useBusyAnnouncement.ts +7 -10
  517. package/src/hooks/useMenuHover.ts +15 -1
  518. package/src/i18n/generated-locales/en.generated.ts +6 -0
  519. package/src/i18n/generated-locales/pseudo.generated.ts +6 -0
  520. package/src/motion/README.md +11 -1
  521. package/src/motion/animator.test.ts +151 -3
  522. package/src/motion/animator.ts +149 -33
  523. package/src/theme/Theme.doc.mjs +1 -1
  524. package/src/theme/defineTheme.ts +117 -8
  525. package/src/theme/derivedVarRegistry.test.ts +4 -0
  526. package/src/theme/domainTokens/domainTokenDefaults.ts +19 -0
  527. package/src/theme/domainTokens/index.ts +6 -10
  528. package/src/theme/expandMotionScale.test.ts +1 -1
  529. package/src/theme/index.ts +5 -0
  530. package/src/theme/motionKnobs.ts +82 -0
  531. package/src/theme/resolveThemeValues.ts +68 -6
  532. package/src/theme/themeAdaptations.ts +52 -12
  533. package/src/theme/themeMotion.test.ts +620 -0
  534. package/src/theme/themeMotion.ts +221 -0
  535. package/src/theme/tokenReferences.ts +149 -0
  536. package/src/theme/tokens.stylex.ts +10 -0
  537. package/src/theme/tokens.ts +15 -158
  538. package/src/utils/focusReturn.ts +17 -6
  539. package/src/utils/getNodeText.test.ts +24 -0
  540. package/src/utils/getNodeText.ts +37 -0
  541. package/src/utils/interactionModality.test.ts +45 -1
  542. package/src/utils/interactionModality.ts +64 -5
  543. package/src/utils/interactionOverlay.stylex.ts +12 -3
  544. package/src/utils/plainDate.test.ts +90 -0
  545. package/src/utils/plainDate.ts +58 -3
  546. package/src/utils/presentation.test.ts +380 -0
  547. package/src/utils/presentation.ts +180 -0
  548. package/src/utils/pressFeedback.test.ts +138 -0
  549. package/src/utils/pressFeedback.ts +34 -11
  550. package/src/utils/pressPaintPriority.test.ts +80 -0
  551. package/src/utils/primaryClick.test.ts +38 -0
  552. package/src/utils/primaryClick.ts +28 -0
  553. package/src/utils/timeFormat.test.ts +204 -0
  554. package/src/utils/timeFormat.ts +314 -0
  555. package/src/utils/touchPresentation.stylex.ts +43 -0
  556. package/src/utils/touchPresentation.test.ts +140 -1
  557. package/src/utils/touchPresentation.ts +5 -3
  558. package/src/utils/unicodeDigits.test.ts +44 -0
  559. package/src/utils/unicodeDigits.ts +71 -0
@@ -0,0 +1,1773 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file GestureHost.ts
5
+ * @input DOM touch, pointer, click, contextmenu, scroll and focus events of
6
+ * one document; elements with recognizers and consumers attached, and
7
+ * consumer types found by attribute
8
+ * @output Exports GestureHost (the DOM side of the gesture system),
9
+ * getGestureHost (one host per document) and the delegated consumer type
10
+ * @position Browser adapter of packages/core/src/gestures: turns real events
11
+ * into GestureArena input, and carries out what the arena decides
12
+ *
13
+ * FOR EVERY POINTER
14
+ *
15
+ * - Recognizers and press consumers attach for a mouse, a pen and a finger
16
+ * alike (`spec:AST-094` FR43, FR19). Where the primary pointer is coarse
17
+ * the host listens on the page while something enabled could take a
18
+ * touch. Where it is fine, each element with an enabled recognizer or
19
+ * consumer keeps one passive `pointerdown` listener and the page has none:
20
+ * a press on it (a mouse's primary button, a pen, or a finger, whose
21
+ * `pointerdown` comes before its `touchstart`) installs the host's page
22
+ * listeners, which go once that press's contacts end; the click listener
23
+ * alone stays through the swallower's window, for the click a claimed lift
24
+ * owes (FR21, FR24). An element whose recognizer claims a moving finger
25
+ * keeps its blocking `touchmove` under every pointer, a listener FR24
26
+ * counts apart.
27
+ * - A right click, a pen's barrel button and a ctrl-click on macOS start no
28
+ * press (primaryClick.ts).
29
+ * - The host follows the primary pointer (a tablet docking a mouse): turning
30
+ * fine with no press held removes the page listeners and cancels every
31
+ * touch in flight.
32
+ * - A delegated consumer type has no element to listen on: where the
33
+ * primary pointer is fine, the document keeps one passive `pointerdown`
34
+ * listener for every type, counted once per page (FR24).
35
+ *
36
+ * INPUT CHANNELS
37
+ *
38
+ * - Fingers begin and end with Touch Events: they are the only cancelable
39
+ * channel (a pointer event's preventDefault cannot stop a scroll or a
40
+ * click), they keep arriving after the browser takes a pan (which a scroll
41
+ * handoff needs), and every event lists all the fingers at once. A
42
+ * finger's movement comes from BOTH its `touchmove`s and its
43
+ * `pointermove`s (paired at touchstart by target and position), the echo
44
+ * of one in the other dropped: Chromium sends no `touchmove` until a
45
+ * finger has travelled about 16 px, while a tap fails and a pan begins at
46
+ * 10.
47
+ * - A finger's events go to the element it landed on even after that
48
+ * element leaves the document, and then never reach the document. Each
49
+ * tracked finger's target therefore gets its own listeners, and a finger
50
+ * the events say is no longer down is cancelled, so a re-rendered or
51
+ * removed target never strands a gesture.
52
+ * - Mice and pens come from Pointer Events, with coalesced samples for
53
+ * velocity. A pen on an iPad also produces `stylus` touches; those are left
54
+ * to the pointer path.
55
+ * - `pointercancel` on a finger is the browser saying it took that finger
56
+ * for its own pan or zoom; so is a `touchmove` that can no longer be
57
+ * cancelled where `touch-action` let the browser pan, and a scroll above
58
+ * the touch.
59
+ *
60
+ * WHAT THE BROWSER IS TOLD
61
+ *
62
+ * - Each element gets the `touch-action` its recognizers leave the browser
63
+ * (touchAction.ts), set inline when they attach and restored when they
64
+ * detach.
65
+ * - Each element with a recognizer that can claim a touch while it moves (a
66
+ * pan, a swipe, a long press that then drags, a pinch) gets a
67
+ * NON-passive `touchmove` listener that cancels the event only while a
68
+ * recognizer owns one of its touches (a pan claims when it begins, at
69
+ * UIKit's 10 pt, `spec:AST-094` FR17). Nothing else is ever cancelled, so a
70
+ * touch nobody claims scrolls exactly as it would without the system. The
71
+ * known cost: a scroll that BEGINS on such an element waits for a busy main
72
+ * thread (measured in iOS Safari; a passive listener would hand every
73
+ * diagonal to the scroll instead). Elements whose recognizers only claim
74
+ * at the lift (taps) and press consumers get no blocking listener, so a
75
+ * scroll starting on them never waits.
76
+ * - A lift whose click must not happen cancels its `touchend` (no click, no
77
+ * compatibility mouse events) and arms a one-shot swallower for the next
78
+ * trusted click; a click held for a recognizer that may still recognize is
79
+ * replayed if they all fail. Keyboard and assistive-technology clicks
80
+ * (`detail === 0`) always pass.
81
+ * - A `contextmenu` while a recognizer owns a touch is cancelled, so a long
82
+ * press never also opens the browser's menu.
83
+ *
84
+ * DELEGATED CONSUMERS. A consumer type registered with an attribute (a
85
+ * pressable row) is found at touch-down by walking up from the touch target,
86
+ * and an instance is created for that one touch: a list of a thousand rows
87
+ * costs nothing until a finger lands on one.
88
+ *
89
+ * SSR-safe: nothing touches `window` or `document` until something attaches.
90
+ *
91
+ * SYNC: When modified, update GestureHost.test.ts and README.md.
92
+ */
93
+
94
+ import { UIKIT_GESTURES } from "../motion/uikit/gestures.js";
95
+ import { browserClock, GestureArena } from "./GestureArena.js";
96
+ import { HAPTIC_SWITCH_ATTRIBUTE } from "./haptics.js";
97
+ import { isPrimaryClick } from "../utils/primaryClick.js";
98
+ import { createNativeScrollProbe, parentAcrossShadow } from "./nativeScroll.js";
99
+ import { gestureHostStyle, holdSelectionStyle, intersectTouchAction } from "./touchAction.js";
100
+ import { markTouchAction, TOUCH_ACTION_ATTRIBUTE, unmarkTouchAction } from "./touchActionRule.js";
101
+
102
+ /**
103
+ * A kind of view-level consumer found by attribute instead of attached to
104
+ * each element.
105
+ */
106
+
107
+ const STYLE_PROPERTIES = {
108
+ touchAction: 'touch-action',
109
+ WebkitTouchCallout: '-webkit-touch-callout',
110
+ WebkitUserSelect: '-webkit-user-select',
111
+ userSelect: 'user-select'
112
+ };
113
+
114
+ /**
115
+ * Whether a recognizer can take a touch while it moves, and so needs the
116
+ * blocking `touchmove` listener that stops the browser's pan. A tap claims
117
+ * only at the lift (it fails once the finger travels), so it needs none.
118
+ */
119
+ function claimsWhileMoving(recognizer) {
120
+ return recognizer.acceptsTouchInput && recognizer.kind !== 'tap';
121
+ }
122
+
123
+ /**
124
+ * Run `task` in the next frame, before it paints: a read there styles what
125
+ * the frame must style anyway, and its writes are what the frame shows.
126
+ */
127
+ /**
128
+ * A CSS-wide keyword, which names no touch-action of its own: the value in
129
+ * force resolves it (`initial` and `unset` to `auto`, `inherit` to the
130
+ * parent's).
131
+ */
132
+ function isCssWideKeyword(value) {
133
+ return CSS_WIDE_KEYWORDS.has(value.trim().toLowerCase());
134
+ }
135
+ const CSS_WIDE_KEYWORDS = new Set(['initial', 'inherit', 'unset', 'revert', 'revert-layer']);
136
+ function inNextFrame(view, task) {
137
+ if (view != null && typeof view.requestAnimationFrame === 'function') {
138
+ view.requestAnimationFrame(task);
139
+ } else {
140
+ setTimeout(task, 0);
141
+ }
142
+ }
143
+ const PASSIVE_CAPTURE = {
144
+ capture: true,
145
+ passive: true
146
+ };
147
+
148
+ /**
149
+ * A screen-edge pan, told apart by its kind (architecture:react-component-runtime
150
+ * INV13), so the host can report its layout changes without importing it.
151
+ */
152
+ function asScreenEdgePan(recognizer) {
153
+ return recognizer.kind === 'screenEdgePan' ? recognizer : null;
154
+ }
155
+
156
+ /** The inline properties a held press sets to none (holdSelectionStyle). */
157
+ const HOLD_SELECTION_PROPERTIES = ['-webkit-touch-callout', '-webkit-user-select', 'user-select'];
158
+
159
+ /** Elements a held press turned selection off on, and what to restore. */
160
+ const heldSelection = new WeakMap();
161
+ const ACTIVE_CAPTURE = {
162
+ capture: true,
163
+ passive: false
164
+ };
165
+ /** A touchstart and a pointerdown describe one finger: same target, same spot. */
166
+ function isSamePlace(a, b) {
167
+ return a.target === b.target && Math.abs(a.x - b.x) <= 1 && Math.abs(a.y - b.y) <= 1;
168
+ }
169
+ function isPointerKind(type) {
170
+ return type === 'touch' || type === 'mouse' || type === 'pen';
171
+ }
172
+
173
+ /**
174
+ * An event's time on the arena's clock (`performance.now()`). Some engines
175
+ * and DOM emulators stamp events in epoch milliseconds instead.
176
+ */
177
+ function eventTime(event) {
178
+ const time = event.timeStamp;
179
+ if (time > 1e12 && typeof performance !== 'undefined' && performance.timeOrigin > 0) {
180
+ return time - performance.timeOrigin;
181
+ }
182
+ return time;
183
+ }
184
+
185
+ /** A touch list as an array; a synthetic event may carry none. */
186
+ function touchesOf(list) {
187
+ return list == null ? [] : Array.from(list);
188
+ }
189
+ export class GestureHost {
190
+ registry = new Map();
191
+ delegated = new Set();
192
+ /** Touch.identifier → arena id, for live fingers. */
193
+ touchIds = new Map();
194
+ /** Touch.identifier → the element the finger landed on. */
195
+ touchTargets = new Map();
196
+ /** Finger targets with listeners of their own, and how many fingers each. */
197
+ /**
198
+ * Finger targets with listeners of their own: how many fingers each, and
199
+ * how many of those a recognizer could claim while they move (only those
200
+ * need the blocking `touchmove` listener).
201
+ */
202
+ watched = new Map();
203
+ /** Fingers whose target listener is the blocking one. */
204
+ blockingFingers = new Set();
205
+ /** Touch events already handled (the document's and the target's listeners both see one). */
206
+ processed = new WeakSet();
207
+ /** pointerId → arena id, for live mouse and pen contacts. */
208
+ pointerIds = new Map();
209
+ /** Elements whose caller touch-action waits for a read after paint. */
210
+ pendingCallerReads = new Set();
211
+ isCallerReadScheduled = false;
212
+ /**
213
+ * The boxes the host watches for screen-edge pans (syncLayoutWatch): each
214
+ * element with an enabled one, and the root for one whose band moves with
215
+ * the viewport (spec:AST-094 FR18, FR19, DEC-22), and the one observer
216
+ * that watches them.
217
+ */
218
+ layoutWatched = new Set();
219
+ layoutObserver = null;
220
+ /** Fingers whose first uncancelable `touchmove` was already judged. */
221
+ judgedUncancelable = new Set();
222
+ /**
223
+ * A finger's pointerId → its arena id, once its pointerdown and its
224
+ * touchstart are paired. Chromium sends no `touchmove` until a finger has
225
+ * travelled its slop (about 16 px), but sends every `pointermove`, so the
226
+ * finger's movement comes from both channels; and its `pointercancel` is
227
+ * the browser's claim of exactly that finger.
228
+ */
229
+ fingerPointers = new Map();
230
+ /** Finger pointerdowns still waiting for their touchstart. */
231
+ pendingPointers = new Map();
232
+ /**
233
+ * Under `inputMode: 'pointer-events'`, where claimed fingers lifted: the
234
+ * `touchend` that follows their `pointerup` is cancelled (FR21).
235
+ */
236
+ claimedLifts = [];
237
+ /** Fingers still waiting for their pointerdown, by arena id. */
238
+ unpairedTouches = new Map();
239
+ /** The last position fed per contact, so one channel's echo is dropped. */
240
+ /** The elements each held contact turned selection off on. */
241
+ heldSelectionBy = new Map();
242
+ isWatchingPointer = false;
243
+ onPointerKindChange = () => this.refreshAll();
244
+ lastFed = new Map();
245
+ /** When a finger was last down or lifted, and where it landed. */
246
+ lastTouch = null;
247
+ /** The last scroll a finger drove, and when. */
248
+ /** Scrollers a recognizer is scrolling itself this frame (ownScroll). */
249
+ ownedScrolls = new Set();
250
+ lastScroll = null;
251
+ nextId = 1;
252
+ isInstalled = false;
253
+ usesTouchEvents = true;
254
+ swallowDeadline = Number.NEGATIVE_INFINITY;
255
+ /**
256
+ * Where the primary pointer is fine: what listens for a press itself (the
257
+ * elements that use a gesture, and the document for delegated consumers),
258
+ * with its removal; whether a press one armed is held, the page's
259
+ * listeners lasting that long; and the pending removal of the click
260
+ * listener a released press kept (FR21, FR24).
261
+ */
262
+ armed = new Map();
263
+ isArmedPress = false;
264
+ clickRemoval = null;
265
+ constructor(doc, options = {}) {
266
+ this.doc = doc;
267
+ this.inputMode = options.inputMode ?? 'auto';
268
+ const environment = {
269
+ viewportSize: () => ({
270
+ width: doc.defaultView?.innerWidth ?? 0,
271
+ height: doc.defaultView?.innerHeight ?? 0
272
+ }),
273
+ isRtl: view => view instanceof Element && doc.defaultView?.getComputedStyle(view).direction === 'rtl',
274
+ // A screen-edge pan tells a view within its edge band from any other
275
+ // by its box (spec:AST-094 FR18).
276
+ viewRect: view => {
277
+ if (!(view instanceof Element)) {
278
+ return null;
279
+ }
280
+ const {
281
+ left,
282
+ top,
283
+ width,
284
+ height
285
+ } = view.getBoundingClientRect();
286
+ return {
287
+ left,
288
+ top,
289
+ width,
290
+ height
291
+ };
292
+ }
293
+ };
294
+ this.arena = new GestureArena({
295
+ clock: options.clock ?? browserClock,
296
+ environment,
297
+ onDeferredClick: (touch, allowed) => this.replayClick(touch, allowed),
298
+ onTransition: options.onTransition
299
+ });
300
+ const view = doc.defaultView;
301
+ const coarseQuery = options.isPrimaryPointerCoarse == null && typeof view?.matchMedia === 'function' ? view.matchMedia('(pointer: coarse)') : null;
302
+ this.isPrimaryPointerCoarse = options.isPrimaryPointerCoarse ?? (() => coarseQuery?.matches ?? false);
303
+ this.coarseQuery = coarseQuery;
304
+ }
305
+
306
+ /** Re-derive every element's styles and the host's listeners. */
307
+ refreshAll() {
308
+ for (const [element, registration] of this.registry) {
309
+ this.refresh(element, registration);
310
+ }
311
+ this.syncListeners();
312
+ }
313
+
314
+ // --- Attachment ------------------------------------------------------------
315
+
316
+ /** Attach a recognizer to an element. Returns the detach function. */
317
+ attach(element, recognizer, options = {}) {
318
+ const registration = this.registrationFor(element);
319
+ registration.manageStyle = options.manageStyle ?? registration.manageStyle;
320
+ registration.actionGroup = options.actionGroup ?? registration.actionGroup;
321
+ recognizer.view = element;
322
+ registration.recognizers.push(recognizer);
323
+ recognizer.onEnabledChange = () => {
324
+ this.refresh(element, registration);
325
+ this.syncListeners();
326
+ };
327
+ const edgePan = asScreenEdgePan(recognizer);
328
+ if (edgePan != null) {
329
+ // A new answer may also move the band the pan watches onto or off the
330
+ // right side, whose band moves with the viewport (an in-place switch
331
+ // of direction): the layout watch follows (FR18, FR24, DEC-22).
332
+ edgePan.onTouchBehaviorChange = () => {
333
+ this.refresh(element, registration);
334
+ this.syncLayoutWatch();
335
+ };
336
+ }
337
+ this.refresh(element, registration);
338
+ this.syncListeners();
339
+ return () => {
340
+ recognizer.onEnabledChange = null;
341
+ if (edgePan != null) {
342
+ edgePan.onTouchBehaviorChange = null;
343
+ }
344
+ const index = registration.recognizers.indexOf(recognizer);
345
+ if (index >= 0) {
346
+ registration.recognizers.splice(index, 1);
347
+ }
348
+ // A recognizer whose view goes away mid-gesture is cancelled, as in
349
+ // UIKit when a view leaves the window.
350
+ if (recognizer.state !== 'possible' || recognizer.isInvolved()) {
351
+ recognizer.cancel();
352
+ }
353
+ this.refresh(element, registration);
354
+ // Even when the element keeps other attachments: one left disabled
355
+ // keeps no listener or observer (FR24).
356
+ this.syncListeners();
357
+ this.cleanup(element, registration);
358
+ };
359
+ }
360
+
361
+ /**
362
+ * Watch the box of each element with an enabled screen-edge pan, and the
363
+ * root's for a pan that watches the right side, whose band moves with the
364
+ * viewport: a resize may move an element into or out of its edge band, and
365
+ * the pan then measures again and re-derives the element's touch-action
366
+ * (FR19). The host sets touch-action for every pointer (FR43), so it
367
+ * watches under any primary pointer. One ResizeObserver serves every
368
+ * element and goes with the last one, and no listener is added (FR24); an
369
+ * engine without ResizeObserver keeps each pan's first measurement.
370
+ */
371
+ syncLayoutWatch() {
372
+ const wanted = new Set();
373
+ let watchesViewport = false;
374
+ for (const [element, registration] of this.registry) {
375
+ for (const recognizer of registration.recognizers) {
376
+ const edgePan = asScreenEdgePan(recognizer);
377
+ if (edgePan != null && edgePan.isEnabled) {
378
+ wanted.add(element);
379
+ watchesViewport ||= edgePan.watchesViewport;
380
+ }
381
+ }
382
+ }
383
+ if (watchesViewport) {
384
+ wanted.add(this.doc.documentElement);
385
+ }
386
+ for (const element of [...this.layoutWatched]) {
387
+ if (!wanted.has(element)) {
388
+ this.layoutObserver?.unobserve(element);
389
+ this.layoutWatched.delete(element);
390
+ }
391
+ }
392
+ if (wanted.size === 0) {
393
+ this.layoutObserver?.disconnect();
394
+ this.layoutObserver = null;
395
+ return;
396
+ }
397
+ const view = this.doc.defaultView;
398
+ if (this.layoutObserver == null && view != null && typeof view.ResizeObserver === 'function') {
399
+ this.layoutObserver = new view.ResizeObserver(this.onLayoutChange);
400
+ for (const element of this.layoutWatched) {
401
+ this.layoutObserver.observe(element);
402
+ }
403
+ }
404
+ for (const element of wanted) {
405
+ if (!this.layoutWatched.has(element)) {
406
+ this.layoutObserver?.observe(element);
407
+ this.layoutWatched.add(element);
408
+ }
409
+ }
410
+ }
411
+
412
+ /** A watched box or the root resized: each enabled edge pan measures again. */
413
+ onLayoutChange = () => {
414
+ for (const registration of this.registry.values()) {
415
+ for (const recognizer of registration.recognizers) {
416
+ const edgePan = asScreenEdgePan(recognizer);
417
+ if (edgePan != null && edgePan.isEnabled) {
418
+ edgePan.layoutChanged();
419
+ }
420
+ }
421
+ }
422
+ };
423
+
424
+ /** Attach the view-level touch consumer of an element (a pressable control). */
425
+ attachConsumer(element, consumer) {
426
+ const registration = this.registrationFor(element);
427
+ registration.consumer = consumer;
428
+ this.syncListeners();
429
+ return () => {
430
+ if (registration.consumer === consumer) {
431
+ registration.consumer = null;
432
+ }
433
+ // Even when the element keeps a recognizer: one left disabled keeps
434
+ // no listener or observer (FR24).
435
+ this.syncListeners();
436
+ this.cleanup(element, registration);
437
+ };
438
+ }
439
+
440
+ /**
441
+ * Find consumers of a kind by attribute, one instance per contact. Returns
442
+ * the function that stops it.
443
+ */
444
+ addDelegatedConsumer(type) {
445
+ this.delegated.add(type);
446
+ this.syncListeners();
447
+ return () => {
448
+ this.delegated.delete(type);
449
+ this.syncListeners();
450
+ };
451
+ }
452
+
453
+ /**
454
+ * Re-derive an element's styles and the host's listeners after its
455
+ * recognizers' options or its consumer's enabled state changed.
456
+ */
457
+ update(element) {
458
+ const registration = this.registry.get(element);
459
+ if (registration != null) {
460
+ this.refresh(element, registration);
461
+ }
462
+ this.syncListeners();
463
+ }
464
+
465
+ /**
466
+ * The Pointer Events `pointerId` of a contact the arena tracks: a mouse's
467
+ * or a pen's own, and for a finger driven by touch events the pointer its
468
+ * touch was paired with (null before the pairing, or without Pointer
469
+ * Events). It hands a held finger to code that follows pointers, as a
470
+ * menu does when a long press turns into a press-drag selection.
471
+ */
472
+ pointerIdOf(touch) {
473
+ const id = typeof touch === 'number' ? touch : touch.id;
474
+ for (const [pointerId, arenaId] of this.fingerPointers) {
475
+ if (arenaId === id) {
476
+ return pointerId;
477
+ }
478
+ }
479
+ for (const [pointerId, arenaId] of this.pointerIds) {
480
+ if (arenaId === id) {
481
+ return pointerId;
482
+ }
483
+ }
484
+ return null;
485
+ }
486
+
487
+ /**
488
+ * Whether a finger set a scroller containing `node` moving within the last
489
+ * `window` ms. A touch there now brakes the scroll rather than pressing
490
+ * whatever is under it: a native list highlights nothing for one.
491
+ */
492
+ isScrollBraking(node, window = UIKIT_GESTURES.press.scrollBrake.value) {
493
+ const last = this.lastScroll;
494
+ return last != null && this.arena.now() - last.time < window && last.scroller.contains(node);
495
+ }
496
+ registrationFor(element) {
497
+ let registration = this.registry.get(element);
498
+ if (registration == null) {
499
+ registration = {
500
+ recognizers: [],
501
+ consumer: null,
502
+ touchMoveListener: null,
503
+ touchEndListener: null,
504
+ savedStyle: new Map(),
505
+ authorTouchAction: null,
506
+ manageStyle: true,
507
+ actionGroup: false
508
+ };
509
+ this.registry.set(element, registration);
510
+ }
511
+ return registration;
512
+ }
513
+ refresh(element, registration) {
514
+ if (registration.manageStyle && element instanceof HTMLElement) {
515
+ this.applyStyle(element, registration);
516
+ }
517
+ // For every pointer (FR43): a finger's claim cancels its moves here
518
+ // (FR19), a listener FR24 counts apart from the one an element keeps for
519
+ // its press.
520
+ const needsListener = registration.recognizers.some(r => r.isEnabled && claimsWhileMoving(r));
521
+ if (needsListener && registration.touchMoveListener == null) {
522
+ const listener = event => this.cancelIfClaimed(event);
523
+ registration.touchMoveListener = listener;
524
+ element.addEventListener('touchmove', listener, {
525
+ passive: false
526
+ });
527
+ } else if (!needsListener && registration.touchMoveListener != null) {
528
+ element.removeEventListener('touchmove', registration.touchMoveListener);
529
+ registration.touchMoveListener = null;
530
+ }
531
+ // Pointer Events only: a claimed finger's touchend is not the host's
532
+ // own document listener's to cancel, so the element cancels it.
533
+ const needsEndListener = this.inputMode === 'pointer-events' && registration.recognizers.some(r => r.isEnabled && r.acceptsTouchInput);
534
+ if (needsEndListener && registration.touchEndListener == null) {
535
+ const listener = event => this.cancelClaimedLift(event);
536
+ registration.touchEndListener = listener;
537
+ element.addEventListener('touchend', listener, {
538
+ passive: false
539
+ });
540
+ } else if (!needsEndListener && registration.touchEndListener != null) {
541
+ element.removeEventListener('touchend', registration.touchEndListener);
542
+ registration.touchEndListener = null;
543
+ }
544
+ }
545
+ applyStyle(element, registration) {
546
+ // Where no attached recognizer is enabled the host manages no style: the
547
+ // element keeps its own touch-action, and any value set before is
548
+ // restored (FR24). Every pointer gets it: a touchscreen laptop's finger
549
+ // as a phone's (spec:AST-094 FR43).
550
+ const enabled = registration.recognizers.filter(r => r.isEnabled);
551
+ const style = enabled.length > 0 ? gestureHostStyle(enabled) : {};
552
+ for (const key of Object.keys(STYLE_PROPERTIES)) {
553
+ const property = STYLE_PROPERTIES[key];
554
+ let value = style[key];
555
+ if (key === 'touchAction') {
556
+ value = this.touchActionToWrite(element, registration, value);
557
+ }
558
+ if (value != null) {
559
+ if (!registration.savedStyle.has(property)) {
560
+ registration.savedStyle.set(property, element.style.getPropertyValue(property));
561
+ }
562
+ element.style.setProperty(property, value);
563
+ } else if (registration.savedStyle.has(property)) {
564
+ const saved = registration.savedStyle.get(property) ?? '';
565
+ registration.savedStyle.delete(property);
566
+ if (saved === '') {
567
+ element.style.removeProperty(property);
568
+ } else {
569
+ element.style.setProperty(property, saved);
570
+ }
571
+ }
572
+ }
573
+ }
574
+
575
+ /**
576
+ * The touch-action to write inline, if any. The author's value (a
577
+ * trigger's own `touch-action: none`) stays in force and the host never
578
+ * allows more (spec:AST-094 FR18, DEC-8):
579
+ * - an inline value is the style's own, read with no recalc, and the host
580
+ * writes what both allow, inline; a CSS-wide keyword (`initial`,
581
+ * `inherit`, `unset`, `revert`, `revert-layer`) names no touch-action of
582
+ * its own, so it is read as an author rule is, as what it resolves to;
583
+ * - otherwise the element is marked with the derived value, under a rule
584
+ * any author rule outranks, as the recognizer attaches: a subtree that
585
+ * mounts with it is styled once, never restyled for it in a later frame.
586
+ * The next frame reads what is in force, styles clean, and the host
587
+ * writes inline only what both allow where that is narrower than an
588
+ * author rule's value.
589
+ */
590
+ touchActionToWrite(element, registration, derived) {
591
+ if (derived == null) {
592
+ unmarkTouchAction(element);
593
+ registration.authorTouchAction = null;
594
+ return undefined;
595
+ }
596
+ const property = STYLE_PROPERTIES.touchAction;
597
+ const inline = registration.savedStyle.has(property) ? registration.savedStyle.get(property) ?? '' : element.style.getPropertyValue(property);
598
+ if (inline !== '' && !isCssWideKeyword(inline)) {
599
+ unmarkTouchAction(element);
600
+ return intersectTouchAction(derived, inline);
601
+ }
602
+ if (!markTouchAction(element, derived)) {
603
+ // No document or shadow root to hold the rule (a detached element):
604
+ // nothing is styled there, and the next frame looks again.
605
+ this.readCallerTouchActionInNextFrame(element);
606
+ return undefined;
607
+ }
608
+ const read = registration.authorTouchAction;
609
+ if (read == null || read.derived !== derived) {
610
+ // The rule is in force until the read: the derived value, or the
611
+ // author's where the author sets one.
612
+ this.readCallerTouchActionInNextFrame(element);
613
+ return undefined;
614
+ }
615
+ if (read.author == null) {
616
+ return undefined;
617
+ }
618
+ const both = intersectTouchAction(derived, read.author);
619
+ return both === read.author ? undefined : both;
620
+ }
621
+
622
+ /**
623
+ * Read the touch-action in force on each marked element in the next frame,
624
+ * then apply its style again. Batched: one style read serves every pending
625
+ * element, and the writes follow the reads. The host has written no
626
+ * touch-action inline on them, so a value other than the mark is an author
627
+ * rule's.
628
+ */
629
+ readCallerTouchActionInNextFrame(element) {
630
+ this.pendingCallerReads.add(element);
631
+ if (this.isCallerReadScheduled) {
632
+ return;
633
+ }
634
+ this.isCallerReadScheduled = true;
635
+ inNextFrame(this.doc.defaultView, () => {
636
+ this.isCallerReadScheduled = false;
637
+ const pending = [];
638
+ for (const candidate of this.pendingCallerReads) {
639
+ const registration = this.registry.get(candidate);
640
+ if (registration != null) {
641
+ pending.push([candidate, registration]);
642
+ }
643
+ }
644
+ this.pendingCallerReads.clear();
645
+ const view = this.doc.defaultView;
646
+ for (const [candidate, registration] of pending) {
647
+ const derived = candidate.getAttribute(TOUCH_ACTION_ATTRIBUTE);
648
+ if (derived == null || view == null) {
649
+ continue;
650
+ }
651
+ const inForce = view.getComputedStyle(candidate).touchAction || 'auto';
652
+ registration.authorTouchAction = {
653
+ derived,
654
+ author: inForce === derived ? null : inForce
655
+ };
656
+ }
657
+ for (const [candidate, registration] of pending) {
658
+ this.applyStyle(candidate, registration);
659
+ }
660
+ });
661
+ }
662
+ cleanup(element, registration) {
663
+ if (registration.recognizers.length > 0 || registration.consumer != null) {
664
+ return;
665
+ }
666
+ if (registration.touchMoveListener != null) {
667
+ element.removeEventListener('touchmove', registration.touchMoveListener);
668
+ }
669
+ if (registration.touchEndListener != null) {
670
+ element.removeEventListener('touchend', registration.touchEndListener);
671
+ registration.touchEndListener = null;
672
+ }
673
+ this.registry.delete(element);
674
+ this.syncListeners();
675
+ }
676
+
677
+ /**
678
+ * Listen only while something could take a touch now (`spec:AST-094`
679
+ * FR24, FR43): where the primary pointer is coarse, while an enabled
680
+ * recognizer or consumer, or a delegated consumer, is attached; where it is
681
+ * fine, only during a press something armed (syncArmed). Otherwise no page
682
+ * listener is registered, so an idle page and a disabled control pay
683
+ * nothing.
684
+ */
685
+ syncListeners() {
686
+ this.syncLayoutWatch();
687
+ // The primary pointer can change (a tablet's keyboard attached or
688
+ // removed): while anything is attached, styles and listeners follow it.
689
+ // Nothing touch-related stays once the last attachment goes (FR24).
690
+ const hasAttachments = this.registry.size > 0 || this.delegated.size > 0;
691
+ if (hasAttachments && !this.isWatchingPointer) {
692
+ this.coarseQuery?.addEventListener?.('change', this.onPointerKindChange);
693
+ this.isWatchingPointer = true;
694
+ } else if (!hasAttachments && this.isWatchingPointer) {
695
+ this.coarseQuery?.removeEventListener?.('change', this.onPointerKindChange);
696
+ this.isWatchingPointer = false;
697
+ }
698
+ this.syncArmed();
699
+ if (this.shouldListen()) {
700
+ this.install();
701
+ } else if (this.isInstalled) {
702
+ this.uninstall();
703
+ }
704
+ }
705
+ shouldListen() {
706
+ if (!this.isPrimaryPointerCoarse()) {
707
+ return this.isArmedPress;
708
+ }
709
+ if (this.delegated.size > 0) {
710
+ return true;
711
+ }
712
+ for (const registration of this.registry.values()) {
713
+ if (isServed(registration)) {
714
+ return true;
715
+ }
716
+ }
717
+ return false;
718
+ }
719
+
720
+ /**
721
+ * Where the primary pointer is fine, each element with an enabled
722
+ * recognizer or press consumer listens for a press itself: one passive
723
+ * `pointerdown` listener, in the capture phase, so the outermost one hears
724
+ * a press first and serves every recognizer on its path. Delegated
725
+ * consumer types, which have no element, arm the document once. A press
726
+ * installs the host's page listeners for as long as its contacts last
727
+ * (`spec:AST-094` FR24, FR43). Where the primary pointer is coarse the
728
+ * page's listeners serve every press, and nothing is armed.
729
+ */
730
+ syncArmed() {
731
+ const wanted = new Set();
732
+ if (!this.isPrimaryPointerCoarse()) {
733
+ for (const [element, registration] of this.registry) {
734
+ if (isServed(registration)) {
735
+ wanted.add(element);
736
+ }
737
+ }
738
+ if (this.delegated.size > 0) {
739
+ wanted.add(this.doc);
740
+ }
741
+ }
742
+ for (const [target, disarm] of [...this.armed]) {
743
+ if (!wanted.has(target)) {
744
+ disarm();
745
+ this.armed.delete(target);
746
+ }
747
+ }
748
+ for (const target of wanted) {
749
+ if (this.armed.has(target)) {
750
+ continue;
751
+ }
752
+ target.addEventListener('pointerdown', this.onArmedPress, PASSIVE_CAPTURE);
753
+ this.armed.set(target, () => {
754
+ target.removeEventListener('pointerdown', this.onArmedPress, PASSIVE_CAPTURE);
755
+ });
756
+ }
757
+ }
758
+
759
+ /**
760
+ * A press on something armed, where the primary pointer is fine: a
761
+ * mouse's primary button, a pen, or a finger. The page's listeners come
762
+ * for this press, and the press goes on to them, its capture phase on the
763
+ * page being over.
764
+ */
765
+ onArmedPress = event => {
766
+ const press = event;
767
+ if (this.isInstalled || !isPointerKind(press.pointerType) || press.pointerType !== 'touch' && !isPrimaryClick(press)) {
768
+ return;
769
+ }
770
+ this.isArmedPress = true;
771
+ this.install();
772
+ this.onPointerDown(press);
773
+ // A mouse's or a pen's press that nothing took has nothing to wait for;
774
+ // a finger's contact begins at its touchstart, which comes next.
775
+ if (press.pointerType !== 'touch') {
776
+ this.releaseArmedPress();
777
+ }
778
+ };
779
+
780
+ /**
781
+ * After a contact ends: once no contact of the press that armed the page's
782
+ * listeners is down, they go (FR24). A recognizer still deciding after the
783
+ * lift needs no input; the click it may owe keeps its listener
784
+ * (releaseClickListener).
785
+ */
786
+ releaseArmedPress() {
787
+ if (this.isArmedPress && !this.arena.touches.some(touch => touch.phase !== 'ended' && touch.phase !== 'cancelled')) {
788
+ this.isArmedPress = false;
789
+ this.syncListeners();
790
+ }
791
+ }
792
+
793
+ /**
794
+ * The click listener outlives the page's others while the swallower is
795
+ * armed: a claimed lift's click comes after its pointerup or touchend
796
+ * (`spec:AST-094` FR21; FR24 counts it as press work). It goes when that
797
+ * window closes, unless the host listens again by then.
798
+ */
799
+ releaseClickListener() {
800
+ const view = this.doc.defaultView;
801
+ if (this.clickRemoval != null) {
802
+ clearTimeout(this.clickRemoval);
803
+ this.clickRemoval = null;
804
+ }
805
+ const remaining = this.swallowDeadline - browserClock.now();
806
+ if (view == null || remaining < 0) {
807
+ view?.removeEventListener('click', this.onClick, ACTIVE_CAPTURE);
808
+ return;
809
+ }
810
+ this.clickRemoval = setTimeout(() => {
811
+ this.clickRemoval = null;
812
+ if (!this.isInstalled) {
813
+ view.removeEventListener('click', this.onClick, ACTIVE_CAPTURE);
814
+ }
815
+ }, remaining + 1);
816
+ }
817
+
818
+ // --- Listeners -------------------------------------------------------------
819
+
820
+ install() {
821
+ if (this.isInstalled) {
822
+ return;
823
+ }
824
+ if (this.clickRemoval != null) {
825
+ clearTimeout(this.clickRemoval);
826
+ this.clickRemoval = null;
827
+ }
828
+ const view = this.doc.defaultView;
829
+ this.isInstalled = true;
830
+ this.usesTouchEvents = this.inputMode === 'auto' && view != null && 'ontouchstart' in view;
831
+ const doc = this.doc;
832
+ // Pointer Events only: a finger comes from its pointer events alone. A
833
+ // browser that has Touch Events still sends them for the same finger, and
834
+ // reading both would track it twice (a long press needs one touch).
835
+ if (this.inputMode === 'auto') {
836
+ doc.addEventListener('touchstart', this.onTouchStart, PASSIVE_CAPTURE);
837
+ doc.addEventListener('touchmove', this.onTouchMove, PASSIVE_CAPTURE);
838
+ doc.addEventListener('touchend', this.onTouchEnd, ACTIVE_CAPTURE);
839
+ doc.addEventListener('touchcancel', this.onTouchCancel, PASSIVE_CAPTURE);
840
+ }
841
+ doc.addEventListener('pointerdown', this.onPointerDown, PASSIVE_CAPTURE);
842
+ doc.addEventListener('pointermove', this.onPointerMove, PASSIVE_CAPTURE);
843
+ doc.addEventListener('pointerup', this.onPointerUp, PASSIVE_CAPTURE);
844
+ doc.addEventListener('pointercancel', this.onPointerCancel, PASSIVE_CAPTURE);
845
+ doc.addEventListener('contextmenu', this.onContextMenu, ACTIVE_CAPTURE);
846
+ doc.addEventListener('scroll', this.onScroll, PASSIVE_CAPTURE);
847
+ doc.addEventListener('visibilitychange', this.onVisibilityChange);
848
+ view?.addEventListener('click', this.onClick, ACTIVE_CAPTURE);
849
+ view?.addEventListener('blur', this.onBlur);
850
+ }
851
+ uninstall() {
852
+ if (!this.isInstalled) {
853
+ return;
854
+ }
855
+ this.isInstalled = false;
856
+ const doc = this.doc;
857
+ const view = doc.defaultView;
858
+ doc.removeEventListener('touchstart', this.onTouchStart, PASSIVE_CAPTURE);
859
+ doc.removeEventListener('touchmove', this.onTouchMove, PASSIVE_CAPTURE);
860
+ doc.removeEventListener('touchend', this.onTouchEnd, ACTIVE_CAPTURE);
861
+ doc.removeEventListener('touchcancel', this.onTouchCancel, PASSIVE_CAPTURE);
862
+ doc.removeEventListener('pointerdown', this.onPointerDown, PASSIVE_CAPTURE);
863
+ doc.removeEventListener('pointermove', this.onPointerMove, PASSIVE_CAPTURE);
864
+ doc.removeEventListener('pointerup', this.onPointerUp, PASSIVE_CAPTURE);
865
+ doc.removeEventListener('pointercancel', this.onPointerCancel, PASSIVE_CAPTURE);
866
+ doc.removeEventListener('contextmenu', this.onContextMenu, ACTIVE_CAPTURE);
867
+ doc.removeEventListener('scroll', this.onScroll, PASSIVE_CAPTURE);
868
+ doc.removeEventListener('visibilitychange', this.onVisibilityChange);
869
+ this.releaseClickListener();
870
+ view?.removeEventListener('blur', this.onBlur);
871
+ this.cancelEverything(this.arena.now());
872
+ this.lastTouch = null;
873
+ this.lastScroll = null;
874
+ }
875
+
876
+ // --- Hit path --------------------------------------------------------------
877
+
878
+ /**
879
+ * The recognizers on the path from `target` to the document, innermost
880
+ * first, and (for a contact) its consumer: the innermost element with an
881
+ * attached consumer or a delegated consumer type's attribute.
882
+ */
883
+ participantsAt(target, pointerType) {
884
+ const recognizers = [];
885
+ let consumer = null;
886
+ let hasConsumerOwner = pointerType == null;
887
+ for (let node = target instanceof Node ? target : null; node != null; node = parentAcrossShadow(node)) {
888
+ if (!(node instanceof Element)) {
889
+ continue;
890
+ }
891
+ const registration = this.registry.get(node);
892
+ if (registration != null) {
893
+ recognizers.push(...registration.recognizers);
894
+ }
895
+ if (hasConsumerOwner || pointerType == null) {
896
+ continue;
897
+ }
898
+ if (registration?.consumer != null) {
899
+ consumer = registration.consumer;
900
+ hasConsumerOwner = true;
901
+ continue;
902
+ }
903
+ for (const type of this.delegated) {
904
+ if (node.hasAttribute(type.attribute)) {
905
+ consumer = type.create(node, pointerType);
906
+ hasConsumerOwner = true;
907
+ break;
908
+ }
909
+ }
910
+ }
911
+ return {
912
+ recognizers,
913
+ consumer
914
+ };
915
+ }
916
+
917
+ // --- Touch events ----------------------------------------------------------
918
+
919
+ /** Whether this event is new to the host (and mark it handled). */
920
+ takeEvent(event) {
921
+ if (this.processed.has(event)) {
922
+ return false;
923
+ }
924
+ this.processed.add(event);
925
+ return true;
926
+ }
927
+ onTouchStart = event => {
928
+ if (!this.takeEvent(event)) {
929
+ return;
930
+ }
931
+ const time = eventTime(event);
932
+ const inputs = [];
933
+ const untracked = [];
934
+ const stale = [];
935
+ for (const touch of touchesOf(event.changedTouches)) {
936
+ if (touch.touchType === 'stylus') {
937
+ continue;
938
+ }
939
+ // A finger number still tracked here began again: the touch it named
940
+ // ended where no listener of ours could hear it.
941
+ const previous = this.forgetFinger(touch.identifier);
942
+ if (previous != null) {
943
+ stale.push(previous);
944
+ }
945
+ const target = touch.target instanceof Node ? touch.target : event.target;
946
+ const {
947
+ recognizers,
948
+ consumer
949
+ } = this.participantsAt(target, 'touch');
950
+ if (recognizers.length === 0 && consumer == null) {
951
+ // Nothing here takes part: the touch stays the page's, but a
952
+ // recognizer tracking another finger hears it began (a second
953
+ // finger beside an open menu ends its press, spec:AST-094 FR28).
954
+ untracked.push({
955
+ id: this.nextId++,
956
+ x: touch.clientX,
957
+ y: touch.clientY,
958
+ time,
959
+ pointerType: 'touch',
960
+ target
961
+ });
962
+ continue;
963
+ }
964
+ const id = this.nextId++;
965
+ this.touchIds.set(touch.identifier, id);
966
+ this.holdSelection(id, recognizers);
967
+ this.watchTarget(touch.identifier, target, recognizers.some(claimsWhileMoving));
968
+ this.lastFed.set(id, {
969
+ x: touch.clientX,
970
+ y: touch.clientY,
971
+ time
972
+ });
973
+ this.pairTouch(id, {
974
+ x: touch.clientX,
975
+ y: touch.clientY,
976
+ target
977
+ });
978
+ inputs.push({
979
+ id,
980
+ x: touch.clientX,
981
+ y: touch.clientY,
982
+ time,
983
+ pointerType: 'touch',
984
+ target,
985
+ scroll: createNativeScrollProbe(target),
986
+ recognizers,
987
+ consumer
988
+ });
989
+ }
990
+ if (stale.length > 0) {
991
+ this.arena.cancelled(stale, time);
992
+ }
993
+ this.arena.began(inputs);
994
+ for (const input of untracked) {
995
+ this.arena.untrackedBegan(input);
996
+ }
997
+ // Stamped after the consumers judged the touch: the brake asks whether
998
+ // an EARLIER finger is still driving a scroll.
999
+ if (event.target instanceof Node) {
1000
+ this.lastTouch = {
1001
+ target: event.target,
1002
+ time
1003
+ };
1004
+ }
1005
+ };
1006
+ onTouchMove = event => {
1007
+ if (!this.takeEvent(event)) {
1008
+ return;
1009
+ }
1010
+ this.dropFingersNotDown(event);
1011
+ const time = eventTime(event);
1012
+ const ids = [];
1013
+ const inputs = [];
1014
+ for (const touch of touchesOf(event.changedTouches)) {
1015
+ const id = this.touchIds.get(touch.identifier);
1016
+ if (id == null) {
1017
+ continue;
1018
+ }
1019
+ ids.push(id);
1020
+ inputs.push({
1021
+ id,
1022
+ x: touch.clientX,
1023
+ y: touch.clientY,
1024
+ time
1025
+ });
1026
+ }
1027
+ if (inputs.length === 0) {
1028
+ return;
1029
+ }
1030
+ if (!event.cancelable) {
1031
+ // The browser no longer asks the page about these fingers. WebKit
1032
+ // stops asking when it takes the touch to pan (its pointercancel comes
1033
+ // with it); Chromium also stops after one unconsumed touchmove, even
1034
+ // when `touch-action` keeps it from panning the way the finger went (a
1035
+ // horizontal drag under pan-y). So a finger's FIRST uncancelable move
1036
+ // counts as the browser's claim only if the browser could pan along
1037
+ // the finger's main axis since touch-down; later ones add nothing, and
1038
+ // pointercancel or a scroll still report any real pan.
1039
+ const placed = new Map(inputs.map(input => [input.id, input]));
1040
+ const taken = ids.filter(id => {
1041
+ const touch = this.arena.getTouch(id);
1042
+ if (touch == null || touch.takenByBrowser || this.arena.isClaimed(id) || touch.scroll?.allowsNativePan === false || this.judgedUncancelable.has(id)) {
1043
+ return false;
1044
+ }
1045
+ this.judgedUncancelable.add(id);
1046
+ const input = placed.get(id);
1047
+ if (input == null || touch.scroll == null) {
1048
+ return true;
1049
+ }
1050
+ const dx = input.x - touch.startX;
1051
+ const dy = input.y - touch.startY;
1052
+ return Math.abs(dx) >= Math.abs(dy) ? touch.scroll.canScroll(dx, 0) : touch.scroll.canScroll(0, dy);
1053
+ });
1054
+ if (taken.length > 0) {
1055
+ this.arena.browserTookOver(taken, time);
1056
+ }
1057
+ }
1058
+ this.feedMoves(inputs);
1059
+ };
1060
+
1061
+ /**
1062
+ * Under `inputMode: 'pointer-events'` a finger comes from its pointer
1063
+ * events, so its touches carry no id of ours: the live finger it is, the
1064
+ * nearest pointer-fed finger on the same target. Its touchmoves can then
1065
+ * be cancelled once a recognizer claims it (`spec:AST-094` FR19, FR21).
1066
+ */
1067
+ pointerFingerAt(touch) {
1068
+ let best = null;
1069
+ let bestDistance = Number.POSITIVE_INFINITY;
1070
+ for (const finger of this.arena.touches) {
1071
+ if (finger.pointerType !== 'touch' || finger.phase === 'ended' || finger.phase === 'cancelled' || !(finger.target instanceof Node) || !(touch.target instanceof Node) || !(finger.target === touch.target || finger.target.contains(touch.target) || touch.target.contains(finger.target))) {
1072
+ continue;
1073
+ }
1074
+ const d = Math.hypot(finger.x - touch.clientX, finger.y - touch.clientY);
1075
+ if (d < bestDistance) {
1076
+ best = finger;
1077
+ bestDistance = d;
1078
+ }
1079
+ }
1080
+ return best?.id;
1081
+ }
1082
+
1083
+ /**
1084
+ * Cancel the `touchend` of a finger a recognizer owned when it lifted
1085
+ * (`inputMode: 'pointer-events'`): its `pointerup` came first, at the same
1086
+ * place on the same target (`spec:AST-094` FR21).
1087
+ */
1088
+ cancelClaimedLift(event) {
1089
+ if (!event.cancelable || event.defaultPrevented) {
1090
+ return;
1091
+ }
1092
+ for (const touch of touchesOf(event.changedTouches)) {
1093
+ const index = this.claimedLifts.findIndex(lift => isSamePlace(lift, {
1094
+ x: touch.clientX,
1095
+ y: touch.clientY,
1096
+ target: touch.target
1097
+ }));
1098
+ if (index >= 0) {
1099
+ this.claimedLifts.splice(index, 1);
1100
+ event.preventDefault();
1101
+ return;
1102
+ }
1103
+ }
1104
+ }
1105
+
1106
+ /**
1107
+ * Cancel a `touchmove` while a recognizer owns one of its fingers. A touch
1108
+ * no recognizer owns keeps its moves (`spec:AST-094` FR19): nothing is
1109
+ * cancelled before a recognizer begins, or for a touch it does not track.
1110
+ */
1111
+ cancelIfClaimed(event) {
1112
+ if (!event.cancelable || event.defaultPrevented) {
1113
+ return;
1114
+ }
1115
+ // Only the touches this move reports: another finger a recognizer owns
1116
+ // does not make this one its own.
1117
+ const moved = touchesOf(event.changedTouches);
1118
+ for (const touch of moved) {
1119
+ const id = this.touchIds.get(touch.identifier) ?? (this.inputMode === 'pointer-events' ? this.pointerFingerAt(touch) : undefined);
1120
+ if (id != null && this.arena.isClaimed(id)) {
1121
+ event.preventDefault();
1122
+ return;
1123
+ }
1124
+ }
1125
+ if (moved.some(touch => touch.touchType === 'stylus')) {
1126
+ for (const id of this.pointerIds.values()) {
1127
+ if (this.arena.isClaimed(id)) {
1128
+ // A pen whose pointer a recognizer owns: its stylus touches too,
1129
+ // never a finger no recognizer owns.
1130
+ event.preventDefault();
1131
+ return;
1132
+ }
1133
+ }
1134
+ }
1135
+ }
1136
+ onTouchEnd = event => {
1137
+ if (!this.takeEvent(event)) {
1138
+ return;
1139
+ }
1140
+ this.dropFingersNotDown(event);
1141
+ const time = eventTime(event);
1142
+ const inputs = [];
1143
+ for (const touch of touchesOf(event.changedTouches)) {
1144
+ const id = this.forgetFinger(touch.identifier);
1145
+ if (id == null) {
1146
+ continue;
1147
+ }
1148
+ inputs.push({
1149
+ id,
1150
+ x: touch.clientX,
1151
+ y: touch.clientY,
1152
+ time
1153
+ });
1154
+ }
1155
+ // The lift is when momentum starts: the clock the brake wants most.
1156
+ if (event.target instanceof Node) {
1157
+ this.lastTouch = {
1158
+ target: event.target,
1159
+ time
1160
+ };
1161
+ }
1162
+ if (inputs.length === 0) {
1163
+ this.releaseArmedPress();
1164
+ return;
1165
+ }
1166
+ const dispositions = this.arena.ended(inputs);
1167
+ if (needsSuppression(dispositions)) {
1168
+ if (event.cancelable) {
1169
+ event.preventDefault();
1170
+ }
1171
+ this.armSwallower();
1172
+ }
1173
+ this.releaseArmedPress();
1174
+ };
1175
+ onTouchCancel = event => {
1176
+ if (!this.takeEvent(event)) {
1177
+ return;
1178
+ }
1179
+ const listed = touchesOf(event.changedTouches);
1180
+ // A cancel that names no finger is the system taking them all.
1181
+ const identifiers = listed.length > 0 ? listed.map(touch => touch.identifier) : [...this.touchIds.keys()];
1182
+ const ids = [];
1183
+ for (const identifier of identifiers) {
1184
+ const id = this.forgetFinger(identifier);
1185
+ if (id != null) {
1186
+ ids.push(id);
1187
+ }
1188
+ }
1189
+ if (ids.length > 0) {
1190
+ this.arena.cancelled(ids, eventTime(event));
1191
+ }
1192
+ this.releaseArmedPress();
1193
+ };
1194
+
1195
+ /** The target's own listeners, for a target that left the document. */
1196
+ onTargetTouchMove = event => {
1197
+ this.onTouchMove(event);
1198
+ this.cancelIfClaimed(event);
1199
+ };
1200
+
1201
+ /** The same for a finger nothing could claim while it moves: never blocks. */
1202
+ onTargetTouchMovePassive = event => {
1203
+ this.onTouchMove(event);
1204
+ };
1205
+ onTargetTouchEnd = event => {
1206
+ this.onTouchEnd(event);
1207
+ };
1208
+ onTargetTouchCancel = event => {
1209
+ this.onTouchCancel(event);
1210
+ };
1211
+
1212
+ /**
1213
+ * Cancel tracked fingers the event says are no longer down. `touches`
1214
+ * lists every finger on the screen; one missing from it (and not lifting
1215
+ * in this very event) ended where we could not see it.
1216
+ */
1217
+ dropFingersNotDown(event) {
1218
+ if (event.touches == null || this.touchIds.size === 0) {
1219
+ return;
1220
+ }
1221
+ const down = new Set();
1222
+ for (const touch of touchesOf(event.touches)) {
1223
+ down.add(touch.identifier);
1224
+ }
1225
+ for (const touch of touchesOf(event.changedTouches)) {
1226
+ down.add(touch.identifier);
1227
+ }
1228
+ const gone = [...this.touchIds.keys()].filter(identifier => !down.has(identifier));
1229
+ const ids = [];
1230
+ for (const identifier of gone) {
1231
+ const id = this.forgetFinger(identifier);
1232
+ if (id != null) {
1233
+ ids.push(id);
1234
+ }
1235
+ }
1236
+ if (ids.length > 0) {
1237
+ this.arena.cancelled(ids, eventTime(event));
1238
+ }
1239
+ }
1240
+ watchTarget(identifier, target, isBlocking) {
1241
+ if (target == null || typeof target.addEventListener !== 'function') {
1242
+ return;
1243
+ }
1244
+ this.touchTargets.set(identifier, target);
1245
+ const state = this.watched.get(target);
1246
+ if (state == null) {
1247
+ this.watched.set(target, {
1248
+ count: 1,
1249
+ blocking: isBlocking ? 1 : 0
1250
+ });
1251
+ if (isBlocking) {
1252
+ this.blockingFingers.add(identifier);
1253
+ }
1254
+ target.addEventListener('touchmove', isBlocking ? this.onTargetTouchMove : this.onTargetTouchMovePassive, {
1255
+ passive: !isBlocking
1256
+ });
1257
+ target.addEventListener('touchend', this.onTargetTouchEnd, {
1258
+ passive: false
1259
+ });
1260
+ target.addEventListener('touchcancel', this.onTargetTouchCancel, {
1261
+ passive: true
1262
+ });
1263
+ return;
1264
+ }
1265
+ const wasBlocking = state.blocking > 0;
1266
+ state.count += 1;
1267
+ if (isBlocking) {
1268
+ state.blocking += 1;
1269
+ this.blockingFingers.add(identifier);
1270
+ }
1271
+ this.swapTargetTouchMove(target, wasBlocking, state.blocking > 0);
1272
+ }
1273
+ unwatchTarget(identifier) {
1274
+ const target = this.touchTargets.get(identifier);
1275
+ if (target == null) {
1276
+ return;
1277
+ }
1278
+ this.touchTargets.delete(identifier);
1279
+ const state = this.watched.get(target);
1280
+ if (state == null) {
1281
+ return;
1282
+ }
1283
+ const wasBlocking = state.blocking > 0;
1284
+ state.count -= 1;
1285
+ if (this.blockingFingers.delete(identifier)) {
1286
+ state.blocking -= 1;
1287
+ }
1288
+ if (state.count > 0) {
1289
+ this.swapTargetTouchMove(target, wasBlocking, state.blocking > 0);
1290
+ return;
1291
+ }
1292
+ this.watched.delete(target);
1293
+ target.removeEventListener('touchmove', wasBlocking ? this.onTargetTouchMove : this.onTargetTouchMovePassive);
1294
+ target.removeEventListener('touchend', this.onTargetTouchEnd);
1295
+ target.removeEventListener('touchcancel', this.onTargetTouchCancel);
1296
+ }
1297
+
1298
+ /**
1299
+ * Keeps one `touchmove` listener on a watched target: the blocking one
1300
+ * while a finger on it could be claimed as it moves, a passive one
1301
+ * otherwise, so a scroll starting there never waits on the main thread
1302
+ * (`spec:AST-094` FR19).
1303
+ */
1304
+ swapTargetTouchMove(target, wasBlocking, isBlocking) {
1305
+ if (wasBlocking === isBlocking) {
1306
+ return;
1307
+ }
1308
+ target.removeEventListener('touchmove', wasBlocking ? this.onTargetTouchMove : this.onTargetTouchMovePassive);
1309
+ target.addEventListener('touchmove', isBlocking ? this.onTargetTouchMove : this.onTargetTouchMovePassive, {
1310
+ passive: !isBlocking
1311
+ });
1312
+ }
1313
+
1314
+ /** Stop tracking a finger by its Touch.identifier; returns its arena id. */
1315
+ forgetFinger(identifier) {
1316
+ const id = this.touchIds.get(identifier);
1317
+ this.touchIds.delete(identifier);
1318
+ this.unwatchTarget(identifier);
1319
+ if (id != null) {
1320
+ this.forgetContact(id);
1321
+ }
1322
+ return id;
1323
+ }
1324
+ pairTouch(id, place) {
1325
+ for (const [pointerId, pending] of this.pendingPointers) {
1326
+ if (isSamePlace(pending, place)) {
1327
+ this.pendingPointers.delete(pointerId);
1328
+ this.fingerPointers.set(pointerId, id);
1329
+ return;
1330
+ }
1331
+ }
1332
+ this.unpairedTouches.set(id, place);
1333
+ }
1334
+ pairPointer(pointerId, place) {
1335
+ for (const [id, unpaired] of this.unpairedTouches) {
1336
+ if (isSamePlace(unpaired, place)) {
1337
+ this.unpairedTouches.delete(id);
1338
+ this.fingerPointers.set(pointerId, id);
1339
+ return;
1340
+ }
1341
+ }
1342
+ this.pendingPointers.set(pointerId, place);
1343
+ }
1344
+
1345
+ /** Feed moves, dropping the echo of a move the other channel delivered. */
1346
+ feedMoves(inputs) {
1347
+ const fresh = inputs.filter(input => {
1348
+ const last = this.lastFed.get(input.id);
1349
+ if (last != null && (input.time < last.time || input.time === last.time && input.x === last.x && input.y === last.y)) {
1350
+ return false;
1351
+ }
1352
+ this.lastFed.set(input.id, {
1353
+ x: input.x,
1354
+ y: input.y,
1355
+ time: input.time
1356
+ });
1357
+ return true;
1358
+ });
1359
+ if (fresh.length > 0) {
1360
+ this.arena.moved(fresh);
1361
+ }
1362
+ }
1363
+
1364
+ /**
1365
+ * For one held press by a finger or a pen: text selection and the touch
1366
+ * callout off on the elements whose hold does something (a long press),
1367
+ * as `holdSelectionStyle` decides (`spec:AST-094` FR41, DEC-9).
1368
+ * Everything else keeps the browser's long-press selection. Restored when
1369
+ * the contact ends; refcounted across contacts on one element.
1370
+ */
1371
+ holdSelection(id, recognizers) {
1372
+ const elements = new Set();
1373
+ for (const recognizer of recognizers) {
1374
+ if (recognizer.view instanceof HTMLElement && recognizer.isEnabled &&
1375
+ // An element attached with manageStyle: false keeps its own styles.
1376
+ this.registry.get(recognizer.view)?.manageStyle !== false && holdSelectionStyle([recognizer]) != null) {
1377
+ elements.add(recognizer.view);
1378
+ }
1379
+ }
1380
+ if (elements.size === 0) {
1381
+ return;
1382
+ }
1383
+ const held = [...elements];
1384
+ for (const element of held) {
1385
+ const entry = heldSelection.get(element);
1386
+ if (entry != null) {
1387
+ entry.count += 1;
1388
+ continue;
1389
+ }
1390
+ const saved = HOLD_SELECTION_PROPERTIES.map(name => ({
1391
+ name,
1392
+ value: element.style.getPropertyValue(name),
1393
+ priority: element.style.getPropertyPriority(name)
1394
+ }));
1395
+ for (const name of HOLD_SELECTION_PROPERTIES) {
1396
+ element.style.setProperty(name, 'none');
1397
+ }
1398
+ heldSelection.set(element, {
1399
+ count: 1,
1400
+ saved
1401
+ });
1402
+ }
1403
+ this.heldSelectionBy.set(id, held);
1404
+ }
1405
+
1406
+ /** Undo `holdSelection` for a contact that ended; idempotent. */
1407
+ releaseSelection(id) {
1408
+ const held = this.heldSelectionBy.get(id);
1409
+ if (held == null) {
1410
+ return;
1411
+ }
1412
+ this.heldSelectionBy.delete(id);
1413
+ for (const element of held) {
1414
+ const entry = heldSelection.get(element);
1415
+ if (entry == null) {
1416
+ continue;
1417
+ }
1418
+ entry.count -= 1;
1419
+ if (entry.count > 0) {
1420
+ continue;
1421
+ }
1422
+ heldSelection.delete(element);
1423
+ for (const {
1424
+ name,
1425
+ value,
1426
+ priority
1427
+ } of entry.saved) {
1428
+ if (value === '') {
1429
+ element.style.removeProperty(name);
1430
+ } else {
1431
+ element.style.setProperty(name, value, priority);
1432
+ }
1433
+ }
1434
+ }
1435
+ }
1436
+
1437
+ /** Forget a contact's pairing and echo state. */
1438
+ forgetContact(id) {
1439
+ this.releaseSelection(id);
1440
+ this.lastFed.delete(id);
1441
+ this.judgedUncancelable.delete(id);
1442
+ this.unpairedTouches.delete(id);
1443
+ for (const [pointerId, paired] of this.fingerPointers) {
1444
+ if (paired === id) {
1445
+ this.fingerPointers.delete(pointerId);
1446
+ }
1447
+ }
1448
+ }
1449
+
1450
+ // --- Pointer events --------------------------------------------------------
1451
+
1452
+ onPointerDown = event => {
1453
+ // A new press: whatever click is still owed to the last one is not this.
1454
+ this.disarmSwallower();
1455
+ if (!isPointerKind(event.pointerType)) {
1456
+ return;
1457
+ }
1458
+ if (event.pointerType === 'touch' && this.usesTouchEvents) {
1459
+ this.pairPointer(event.pointerId, {
1460
+ x: event.clientX,
1461
+ y: event.clientY,
1462
+ target: event.target
1463
+ });
1464
+ return;
1465
+ }
1466
+ // A right click, a pen's barrel button and a ctrl-click on macOS start
1467
+ // no press (FR43).
1468
+ if (event.pointerType !== 'touch' && !isPrimaryClick(event)) {
1469
+ return;
1470
+ }
1471
+ const {
1472
+ recognizers,
1473
+ consumer
1474
+ } = this.participantsAt(event.target, event.pointerType);
1475
+ if (recognizers.length === 0 && consumer == null) {
1476
+ return;
1477
+ }
1478
+ const id = this.nextId++;
1479
+ this.pointerIds.set(event.pointerId, id);
1480
+ if (event.pointerType !== 'mouse') {
1481
+ this.holdSelection(id, recognizers);
1482
+ }
1483
+ this.arena.began([{
1484
+ id,
1485
+ x: event.clientX,
1486
+ y: event.clientY,
1487
+ time: eventTime(event),
1488
+ pointerType: event.pointerType,
1489
+ target: event.target,
1490
+ scroll: createNativeScrollProbe(event.target),
1491
+ recognizers,
1492
+ consumer
1493
+ }]);
1494
+ };
1495
+ onPointerMove = event => {
1496
+ if (event.pointerType === 'touch' && this.usesTouchEvents) {
1497
+ const id = this.fingerPointers.get(event.pointerId);
1498
+ if (id != null) {
1499
+ this.feedMoves([{
1500
+ id,
1501
+ x: event.clientX,
1502
+ y: event.clientY,
1503
+ time: eventTime(event),
1504
+ history: coalescedHistory(event)
1505
+ }]);
1506
+ }
1507
+ return;
1508
+ }
1509
+ const id = this.pointerIds.get(event.pointerId);
1510
+ if (id != null) {
1511
+ this.arena.moved([{
1512
+ id,
1513
+ x: event.clientX,
1514
+ y: event.clientY,
1515
+ time: eventTime(event),
1516
+ history: coalescedHistory(event)
1517
+ }]);
1518
+ return;
1519
+ }
1520
+ };
1521
+ onPointerUp = event => {
1522
+ if (event.pointerType === 'touch' && this.usesTouchEvents) {
1523
+ // The lift itself is the touchend's: it alone can cancel the click.
1524
+ this.fingerPointers.delete(event.pointerId);
1525
+ this.pendingPointers.delete(event.pointerId);
1526
+ return;
1527
+ }
1528
+ const id = this.pointerIds.get(event.pointerId);
1529
+ if (id == null) {
1530
+ this.releaseArmedPress();
1531
+ return;
1532
+ }
1533
+ this.pointerIds.delete(event.pointerId);
1534
+ this.releaseSelection(id);
1535
+ if (event.pointerType === 'touch' && this.arena.isClaimed(id)) {
1536
+ this.claimedLifts.push({
1537
+ x: event.clientX,
1538
+ y: event.clientY,
1539
+ target: event.target
1540
+ });
1541
+ if (this.claimedLifts.length > 8) {
1542
+ this.claimedLifts.shift();
1543
+ }
1544
+ }
1545
+ const dispositions = this.arena.ended([{
1546
+ id,
1547
+ x: event.clientX,
1548
+ y: event.clientY,
1549
+ time: eventTime(event)
1550
+ }]);
1551
+ if (needsSuppression(dispositions)) {
1552
+ this.armSwallower();
1553
+ }
1554
+ this.releaseArmedPress();
1555
+ };
1556
+ onPointerCancel = event => {
1557
+ if (event.pointerType === 'touch' && this.usesTouchEvents) {
1558
+ const id = this.fingerPointers.get(event.pointerId) ?? this.touchForCancelledPointer(event);
1559
+ this.fingerPointers.delete(event.pointerId);
1560
+ this.pendingPointers.delete(event.pointerId);
1561
+ if (id != null) {
1562
+ this.arena.browserTookOver([id], eventTime(event));
1563
+ }
1564
+ return;
1565
+ }
1566
+ const id = this.pointerIds.get(event.pointerId);
1567
+ if (id != null) {
1568
+ this.pointerIds.delete(event.pointerId);
1569
+ this.releaseSelection(id);
1570
+ this.arena.cancelled([id], eventTime(event));
1571
+ }
1572
+ this.releaseArmedPress();
1573
+ };
1574
+
1575
+ /**
1576
+ * Which live finger a touch `pointercancel` is about. The pointer keeps
1577
+ * the target the finger landed on (implicit capture), as the Touch does;
1578
+ * among fingers on that target, the nearest. WebKit also numbers the
1579
+ * pointer like the Touch, which settles what position cannot.
1580
+ */
1581
+ touchForCancelledPointer(event) {
1582
+ let best = null;
1583
+ let bestDistance = Number.POSITIVE_INFINITY;
1584
+ for (const touch of this.arena.touches) {
1585
+ if (touch.pointerType !== 'touch' || touch.phase === 'ended' || touch.phase === 'cancelled' || touch.target !== event.target) {
1586
+ continue;
1587
+ }
1588
+ const d = Math.hypot(touch.x - event.clientX, touch.y - event.clientY);
1589
+ if (d < bestDistance) {
1590
+ best = touch;
1591
+ bestDistance = d;
1592
+ }
1593
+ }
1594
+ if (best != null) {
1595
+ return best.id;
1596
+ }
1597
+ return this.touchIds.get(event.pointerId) ?? null;
1598
+ }
1599
+
1600
+ // --- Clicks, menus, scrolls, focus -----------------------------------------
1601
+
1602
+ armSwallower() {
1603
+ this.swallowDeadline = browserClock.now() + UIKIT_GESTURES.click.strayClickWindow.value;
1604
+ }
1605
+ disarmSwallower() {
1606
+ this.swallowDeadline = Number.NEGATIVE_INFINITY;
1607
+ }
1608
+ onClick = event => {
1609
+ if (browserClock.now() > this.swallowDeadline) {
1610
+ return;
1611
+ }
1612
+ if (!event.isTrusted || event.detail === 0) {
1613
+ return;
1614
+ }
1615
+ if (event.target instanceof Element && event.target.hasAttribute(HAPTIC_SWITCH_ATTRIBUTE)) {
1616
+ return;
1617
+ }
1618
+ this.disarmSwallower();
1619
+ event.preventDefault();
1620
+ event.stopImmediatePropagation();
1621
+ };
1622
+ replayClick(touch, allowed) {
1623
+ if (!allowed) {
1624
+ return;
1625
+ }
1626
+ // The browser's own click was swallowed while recognizers decided; they
1627
+ // all failed, so the click the touch earned is delivered now.
1628
+ this.disarmSwallower();
1629
+ const target = touch.target;
1630
+ const view = this.doc.defaultView;
1631
+ if (!(target instanceof Element) || !target.isConnected || view == null) {
1632
+ return;
1633
+ }
1634
+ target.dispatchEvent(new view.MouseEvent('click', {
1635
+ bubbles: true,
1636
+ cancelable: true,
1637
+ composed: true,
1638
+ detail: 1,
1639
+ clientX: touch.x,
1640
+ clientY: touch.y
1641
+ }));
1642
+ }
1643
+ onContextMenu = event => {
1644
+ for (const touch of this.arena.touches) {
1645
+ if (this.arena.isClaimed(touch.id)) {
1646
+ event.preventDefault();
1647
+ return;
1648
+ }
1649
+ }
1650
+ };
1651
+
1652
+ /**
1653
+ * A recognizer is about to scroll `scroller` itself (a menu's edge
1654
+ * autoscroll, spec:AST-094 FR30): the scroll that write fires is not a
1655
+ * finger's and not the browser taking one. It passes until the end of the
1656
+ * next frame, when that event has fired; a real pan in that window still
1657
+ * reports itself through pointercancel or touchcancel.
1658
+ */
1659
+ ownScroll(scroller) {
1660
+ this.ownedScrolls.add(scroller);
1661
+ const view = this.doc.defaultView;
1662
+ if (view == null) {
1663
+ return;
1664
+ }
1665
+ view.requestAnimationFrame(() => {
1666
+ view.requestAnimationFrame(() => {
1667
+ this.ownedScrolls.delete(scroller);
1668
+ });
1669
+ });
1670
+ }
1671
+ onScroll = event => {
1672
+ const time = eventTime(event);
1673
+ const scroller = event.target === this.doc ? this.doc : event.target;
1674
+ if (!(scroller instanceof Node) || this.ownedScrolls.has(scroller)) {
1675
+ return;
1676
+ }
1677
+ // A scroll is a finger's only if that finger was inside this scroller,
1678
+ // recently; anything else is the program moving something.
1679
+ const last = this.lastTouch;
1680
+ if (last != null && time - last.time < UIKIT_GESTURES.press.momentumMemory.value && scroller.contains(last.target)) {
1681
+ this.lastScroll = {
1682
+ scroller,
1683
+ time
1684
+ };
1685
+ }
1686
+ const taken = [];
1687
+ for (const touch of this.arena.touches) {
1688
+ if (touch.takenByBrowser || touch.phase === 'ended' || touch.phase === 'cancelled' || touch.pointerType !== 'touch' || this.arena.isClaimed(touch.id)) {
1689
+ continue;
1690
+ }
1691
+ if (touch.target instanceof Node && scroller.contains(touch.target) &&
1692
+ // Only a pan this finger drove takes the touch: the browser starts
1693
+ // one only once the finger has travelled the take distance
1694
+ // (spec:AST-094 FR20). A scroll under a finger that has not
1695
+ // (scrollIntoView, a transcript pinned to its end, scroll
1696
+ // anchoring) is the page's own: the touch, and the click it earns,
1697
+ // stay where they are.
1698
+ Math.hypot(touch.x - touch.startX, touch.y - touch.startY) >= UIKIT_GESTURES.press.slop.value) {
1699
+ taken.push(touch.id);
1700
+ }
1701
+ }
1702
+ if (taken.length > 0) {
1703
+ this.arena.browserTookOver(taken, time);
1704
+ }
1705
+ };
1706
+ onVisibilityChange = () => {
1707
+ if (this.doc.visibilityState === 'hidden') {
1708
+ this.cancelEverything(this.arena.now());
1709
+ this.releaseArmedPress();
1710
+ }
1711
+ };
1712
+ onBlur = () => {
1713
+ this.cancelEverything(this.arena.now());
1714
+ this.releaseArmedPress();
1715
+ };
1716
+
1717
+ /** The app lost focus: UIKit cancels every touch in flight. */
1718
+ cancelEverything(time) {
1719
+ const ids = [...this.pointerIds.values()];
1720
+ for (const id of ids) {
1721
+ this.releaseSelection(id);
1722
+ }
1723
+ for (const identifier of [...this.touchIds.keys()]) {
1724
+ const id = this.forgetFinger(identifier);
1725
+ if (id != null) {
1726
+ ids.push(id);
1727
+ }
1728
+ }
1729
+ this.pointerIds.clear();
1730
+ this.fingerPointers.clear();
1731
+ this.pendingPointers.clear();
1732
+ this.unpairedTouches.clear();
1733
+ this.lastFed.clear();
1734
+ if (ids.length > 0) {
1735
+ this.arena.cancelled(ids, time);
1736
+ }
1737
+ }
1738
+ }
1739
+
1740
+ /** Whether an attachment could take a press now: something on it is enabled. */
1741
+ function isServed(registration) {
1742
+ return registration.recognizers.some(r => r.isEnabled) || registration.consumer != null && registration.consumer.isEnabled?.() !== false;
1743
+ }
1744
+ function needsSuppression(dispositions) {
1745
+ for (const disposition of dispositions.values()) {
1746
+ if (disposition !== 'allow') {
1747
+ return true;
1748
+ }
1749
+ }
1750
+ return false;
1751
+ }
1752
+ function coalescedHistory(event) {
1753
+ if (typeof event.getCoalescedEvents !== 'function') {
1754
+ return [];
1755
+ }
1756
+ const coalesced = event.getCoalescedEvents();
1757
+ return coalesced.slice(0, -1).map(sample => ({
1758
+ x: sample.clientX,
1759
+ y: sample.clientY,
1760
+ time: eventTime(sample)
1761
+ }));
1762
+ }
1763
+ const hosts = new WeakMap();
1764
+
1765
+ /** The gesture host of a document, created on first use. */
1766
+ export function getGestureHost(doc) {
1767
+ let host = hosts.get(doc);
1768
+ if (host == null) {
1769
+ host = new GestureHost(doc);
1770
+ hosts.set(doc, host);
1771
+ }
1772
+ return host;
1773
+ }