@astryxdesign/core 0.7.8 → 0.7.9-canary.048476f

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 (213) hide show
  1. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  2. package/dist/BottomSheet/BottomSheet.js +5 -0
  3. package/dist/Calendar/styles.d.ts +1 -1
  4. package/dist/ClickableCard/ClickableCard.d.ts +1 -1
  5. package/dist/ClickableCard/ClickableCard.d.ts.map +1 -1
  6. package/dist/ClickableCard/ClickableCard.js +5 -1
  7. package/dist/DateInput/PickerWheel.d.ts.map +1 -1
  8. package/dist/DateInput/PickerWheel.js +7 -1
  9. package/dist/DateRangeInput/DateRangeInput.js +1 -1
  10. package/dist/Dialog/Dialog.d.ts +2 -1
  11. package/dist/Dialog/Dialog.d.ts.map +1 -1
  12. package/dist/Dialog/Dialog.js +12 -1
  13. package/dist/Drawer/useDrawerDialogPresence.d.ts +2 -1
  14. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
  15. package/dist/Drawer/useDrawerDialogPresence.js +11 -2
  16. package/dist/DropdownMenu/DropdownMenu.d.ts +9 -1
  17. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  18. package/dist/DropdownMenu/DropdownMenu.js +9 -4
  19. package/dist/DropdownMenu/DropdownMenuCheckboxItem.d.ts.map +1 -1
  20. package/dist/DropdownMenu/DropdownMenuCheckboxItem.js +3 -2
  21. package/dist/DropdownMenu/DropdownMenuItem.d.ts.map +1 -1
  22. package/dist/DropdownMenu/DropdownMenuItem.js +3 -2
  23. package/dist/DropdownMenu/DropdownMenuRadioItem.d.ts.map +1 -1
  24. package/dist/DropdownMenu/DropdownMenuRadioItem.js +3 -2
  25. package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts.map +1 -1
  26. package/dist/DropdownMenu/DropdownMenuSubMenu.js +3 -2
  27. package/dist/Field/inputDisabledFocus.d.ts +4 -4
  28. package/dist/Field/inputStyles.stylex.d.ts +1 -1
  29. package/dist/FileInput/FileInput.d.ts.map +1 -1
  30. package/dist/FileInput/FileInput.js +16 -2
  31. package/dist/Icon/Icon.d.ts +1 -1
  32. package/dist/InfoTip/InfoTip.d.ts +1 -0
  33. package/dist/InfoTip/InfoTip.d.ts.map +1 -1
  34. package/dist/InfoTip/InfoTip.js +1 -0
  35. package/dist/Item/Item.d.ts +2 -1
  36. package/dist/Item/Item.d.ts.map +1 -1
  37. package/dist/Item/Item.js +29 -6
  38. package/dist/Layer/holdEntranceInput.d.ts +24 -0
  39. package/dist/Layer/holdEntranceInput.d.ts.map +1 -0
  40. package/dist/Layer/holdEntranceInput.js +65 -0
  41. package/dist/Layer/inputHold.d.ts +49 -0
  42. package/dist/Layer/inputHold.d.ts.map +1 -0
  43. package/dist/Layer/inputHold.js +636 -0
  44. package/dist/Layer/preserveAnimations.d.ts +1 -5
  45. package/dist/Layer/preserveAnimations.d.ts.map +1 -1
  46. package/dist/Layer/preserveAnimations.js +12 -214
  47. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  48. package/dist/Lightbox/Lightbox.js +4 -0
  49. package/dist/MetadataList/MetadataList.js +1 -1
  50. package/dist/MobileNav/MobileNav.d.ts +11 -1
  51. package/dist/MobileNav/MobileNav.d.ts.map +1 -1
  52. package/dist/MobileNav/MobileNav.js +34 -1
  53. package/dist/MoreMenu/MoreMenu.d.ts +5 -3
  54. package/dist/MoreMenu/MoreMenu.d.ts.map +1 -1
  55. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  56. package/dist/RadioList/RadioListItem.js +4 -1
  57. package/dist/SelectableCard/SelectableCard.d.ts +1 -1
  58. package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
  59. package/dist/SelectableCard/SelectableCard.js +5 -1
  60. package/dist/Spinner/Spinner.d.ts.map +1 -1
  61. package/dist/Spinner/Spinner.js +12 -2
  62. package/dist/Table/plugins/sortable/useTableSortable.js +1 -1
  63. package/dist/Token/Token.d.ts.map +1 -1
  64. package/dist/Token/Token.js +9 -0
  65. package/dist/Token/TokenLink.d.ts +1 -1
  66. package/dist/Token/TokenLink.d.ts.map +1 -1
  67. package/dist/Token/TokenLink.js +4 -1
  68. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  69. package/dist/Tooltip/useTooltip.js +162 -59
  70. package/dist/TreeList/TreeListItem.d.ts +2 -1
  71. package/dist/TreeList/TreeListItem.d.ts.map +1 -1
  72. package/dist/TreeList/TreeListItem.js +27 -3
  73. package/dist/astryx.css +30 -7
  74. package/dist/gestures/GestureHost.d.ts +2 -2
  75. package/dist/gestures/GestureHost.d.ts.map +1 -1
  76. package/dist/gestures/GestureHost.js +21 -6
  77. package/dist/gestures/nativeScroll.d.ts +3 -6
  78. package/dist/gestures/nativeScroll.d.ts.map +1 -1
  79. package/dist/gestures/nativeScroll.js +7 -52
  80. package/dist/gestures/wheelSegmenter.d.ts +68 -1
  81. package/dist/gestures/wheelSegmenter.d.ts.map +1 -1
  82. package/dist/gestures/wheelSegmenter.js +199 -10
  83. package/dist/hooks/menuPressGesture.d.ts +133 -21
  84. package/dist/hooks/menuPressGesture.d.ts.map +1 -1
  85. package/dist/hooks/menuPressGesture.js +155 -30
  86. package/dist/hooks/menuPressValues.d.ts +16 -0
  87. package/dist/hooks/menuPressValues.d.ts.map +1 -0
  88. package/dist/hooks/menuPressValues.js +18 -0
  89. package/dist/hooks/useClickableContainer.d.ts +27 -5
  90. package/dist/hooks/useClickableContainer.d.ts.map +1 -1
  91. package/dist/hooks/useClickableContainer.js +41 -5
  92. package/dist/hooks/useFocusTrap.d.ts +10 -0
  93. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  94. package/dist/hooks/useFocusTrap.js +225 -132
  95. package/dist/hooks/useMenuPress.d.ts +34 -1
  96. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  97. package/dist/hooks/useMenuPress.js +93 -5
  98. package/dist/hooks/usePressFeedback.d.ts +6 -6
  99. package/dist/hooks/usePressFeedback.js +6 -6
  100. package/dist/motion/carryAnimations.d.ts +58 -0
  101. package/dist/motion/carryAnimations.d.ts.map +1 -0
  102. package/dist/motion/carryAnimations.js +305 -0
  103. package/dist/motion/transientCopy.d.ts +4 -2
  104. package/dist/motion/transientCopy.d.ts.map +1 -1
  105. package/dist/motion/transientCopy.js +34 -5
  106. package/dist/motion/uikit/gestures.d.ts +41 -0
  107. package/dist/motion/uikit/gestures.d.ts.map +1 -1
  108. package/dist/motion/uikit/gestures.js +25 -0
  109. package/dist/motion/uikit/index.d.ts +1 -1
  110. package/dist/motion/uikit/index.d.ts.map +1 -1
  111. package/dist/motion/uikit/index.js +1 -1
  112. package/dist/privateAttributes/menuPressLit.stylex.d.ts +52 -0
  113. package/dist/privateAttributes/menuPressLit.stylex.d.ts.map +1 -0
  114. package/dist/privateAttributes/menuPressLit.stylex.js +99 -0
  115. package/dist/privateAttributes/press.stylex.d.ts +139 -0
  116. package/dist/privateAttributes/press.stylex.d.ts.map +1 -0
  117. package/dist/privateAttributes/press.stylex.js +98 -0
  118. package/dist/theme/tokens.stylex.d.ts +2 -2
  119. package/dist/theme/tokens.stylex.js +1 -1
  120. package/dist/utils/flatTree.d.ts +6 -3
  121. package/dist/utils/flatTree.d.ts.map +1 -1
  122. package/dist/utils/flatTree.js +13 -3
  123. package/dist/utils/hitArea.d.ts.map +1 -1
  124. package/dist/utils/hitArea.js +82 -5
  125. package/dist/utils/inputStream.d.ts +14 -1
  126. package/dist/utils/inputStream.d.ts.map +1 -1
  127. package/dist/utils/inputStream.js +40 -9
  128. package/dist/utils/interactionOverlay.stylex.d.ts +2 -1
  129. package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
  130. package/dist/utils/interactionOverlay.stylex.js +7 -2
  131. package/dist/utils/pressFeedback.d.ts +7 -0
  132. package/dist/utils/pressFeedback.d.ts.map +1 -1
  133. package/dist/utils/pressFeedback.js +32 -7
  134. package/dist/utils/pressGesture.d.ts +6 -0
  135. package/dist/utils/pressGesture.d.ts.map +1 -1
  136. package/dist/utils/pressGesture.js +17 -0
  137. package/dist/utils/rowPressLayer.stylex.d.ts +14 -0
  138. package/dist/utils/rowPressLayer.stylex.d.ts.map +1 -0
  139. package/dist/utils/rowPressLayer.stylex.js +25 -0
  140. package/dist/utils/scrollView.d.ts +25 -0
  141. package/dist/utils/scrollView.d.ts.map +1 -0
  142. package/dist/utils/scrollView.js +108 -0
  143. package/dist/utils/selectionLock.d.ts.map +1 -1
  144. package/dist/utils/selectionLock.js +1 -10
  145. package/dist/utils/triggerFocus.d.ts +5 -0
  146. package/dist/utils/triggerFocus.d.ts.map +1 -1
  147. package/dist/utils/triggerFocus.js +9 -2
  148. package/package.json +5 -5
  149. package/src/BottomSheet/BottomSheet.tsx +5 -0
  150. package/src/ClickableCard/ClickableCard.tsx +8 -1
  151. package/src/DateInput/PickerWheel.tsx +7 -2
  152. package/src/DateRangeInput/DateRangeInput.tsx +1 -1
  153. package/src/Dialog/Dialog.doc.mjs +1 -1
  154. package/src/Dialog/Dialog.tsx +12 -1
  155. package/src/Drawer/Drawer.doc.mjs +1 -1
  156. package/src/Drawer/useDrawerDialogPresence.ts +9 -2
  157. package/src/DropdownMenu/DropdownMenu.doc.mjs +1 -2
  158. package/src/DropdownMenu/DropdownMenu.tsx +29 -5
  159. package/src/DropdownMenu/DropdownMenuCheckboxItem.tsx +5 -1
  160. package/src/DropdownMenu/DropdownMenuItem.tsx +8 -4
  161. package/src/DropdownMenu/DropdownMenuRadioItem.tsx +5 -1
  162. package/src/DropdownMenu/DropdownMenuSubMenu.tsx +5 -1
  163. package/src/FileInput/FileInput.tsx +16 -2
  164. package/src/InfoTip/InfoTip.doc.mjs +26 -2
  165. package/src/InfoTip/InfoTip.tsx +1 -0
  166. package/src/Item/Item.tsx +51 -9
  167. package/src/Layer/holdEntranceInput.ts +84 -0
  168. package/src/Layer/inputHold.ts +734 -0
  169. package/src/Layer/preserveAnimations.ts +12 -275
  170. package/src/Lightbox/Lightbox.tsx +4 -0
  171. package/src/MetadataList/MetadataList.tsx +1 -1
  172. package/src/MobileNav/MobileNav.doc.mjs +3 -3
  173. package/src/MobileNav/MobileNav.tsx +34 -1
  174. package/src/MoreMenu/MoreMenu.doc.mjs +2 -4
  175. package/src/MoreMenu/MoreMenu.tsx +5 -3
  176. package/src/RadioList/RadioListItem.tsx +4 -5
  177. package/src/SelectableCard/SelectableCard.tsx +8 -1
  178. package/src/Spinner/Spinner.tsx +13 -3
  179. package/src/Table/plugins/sortable/useTableSortable.tsx +1 -1
  180. package/src/Token/Token.tsx +18 -1
  181. package/src/Token/TokenLink.tsx +7 -1
  182. package/src/Tooltip/useTooltip.tsx +175 -79
  183. package/src/TreeList/TreeListItem.tsx +36 -2
  184. package/src/gestures/GestureHost.ts +21 -5
  185. package/src/gestures/README.md +12 -4
  186. package/src/gestures/nativeScroll.ts +12 -68
  187. package/src/gestures/wheelSegmenter.ts +243 -10
  188. package/src/hooks/menuPressGesture.ts +244 -38
  189. package/src/hooks/menuPressValues.ts +18 -0
  190. package/src/hooks/useClickableContainer.doc.mjs +8 -2
  191. package/src/hooks/useClickableContainer.ts +72 -6
  192. package/src/hooks/useFocusTrap.ts +268 -151
  193. package/src/hooks/useMenuPress.ts +118 -11
  194. package/src/hooks/usePressFeedback.doc.mjs +3 -3
  195. package/src/hooks/usePressFeedback.ts +6 -6
  196. package/src/motion/MEASUREMENTS.md +11 -0
  197. package/src/motion/carryAnimations.ts +389 -0
  198. package/src/motion/transientCopy.ts +45 -5
  199. package/src/motion/uikit/gestures.ts +22 -0
  200. package/src/motion/uikit/index.ts +1 -0
  201. package/src/privateAttributes/menuPressLit.stylex.ts +104 -0
  202. package/src/privateAttributes/press.stylex.ts +244 -0
  203. package/src/theme/tokens.stylex.ts +1 -1
  204. package/src/utils/flatTree.ts +15 -3
  205. package/src/utils/hitArea.ts +107 -5
  206. package/src/utils/inputStream.ts +47 -10
  207. package/src/utils/interactionOverlay.stylex.ts +7 -2
  208. package/src/utils/pressFeedback.ts +31 -6
  209. package/src/utils/pressGesture.ts +24 -1
  210. package/src/utils/rowPressLayer.stylex.ts +27 -0
  211. package/src/utils/scrollView.ts +135 -0
  212. package/src/utils/selectionLock.ts +5 -10
  213. package/src/utils/triggerFocus.ts +17 -4
@@ -6,7 +6,8 @@
6
6
  * @file useMenuPress.ts
7
7
  * @input The menu root, its trigger, the enabled-row selector, and callbacks
8
8
  * for opening, highlighting, activating and dismissing
9
- * @output useMenuPress, the marker attributes, and the activation mark
9
+ * @output useMenuPress, the marker attributes, the activation mark, and the
10
+ * internal useDropdownMenuPress entry with its touch model
10
11
  * @position Core hook for DropdownMenu, ContextMenu, DropdownMenuSubMenu,
11
12
  * Selector and MenuBottomSheetActionList. The transition table lives in
12
13
  * menuPressGesture.ts.
@@ -19,13 +20,14 @@
19
20
  */
20
21
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
21
22
  import { currentGesture } from "../Layer/gestureCounter.js";
22
- import { IDLE_MENU_PRESS, menuPressStep } from "./menuPressGesture.js";
23
+ import { IDLE_MENU_PRESS, menuPressTransition } from "./menuPressGesture.js";
23
24
  import { MENU_PRESS_MARKER } from "./menuPressMarker.js";
24
25
  import { useLongPressDetector } from "./useLongPress.js";
25
26
  import { edgeAutoscroll } from "../utils/edgeAutoscroll.js";
26
27
  import { focusForLastInput } from "../utils/focusReturn.js";
27
28
  import { useInteractionModalityTrackingFor } from "../utils/interactionModality.js";
28
29
  import { LONG_PRESS_DURATION_MS } from "../motion/uikit/longPress.js";
30
+ import { clearMenuPressLit, holdMenuPressPaint, markMenuPressLit, releaseMenuPressPaint } from "../privateAttributes/menuPressLit.stylex.js";
29
31
  import { __resetClickGuardForTest, armClickGuard, CLICK_GUARD_WINDOW_MS, withoutClickGuard } from "../utils/clickGuard.js";
30
32
  export { MENU_PRESS_MARKER };
31
33
  const MENU_PRESS_ROOT_SELECTOR = `[${MENU_PRESS_MARKER}]`;
@@ -124,6 +126,34 @@ function isInMenuTree(element, root) {
124
126
  const owner = element.closest(MENU_PRESS_ROOT_SELECTOR);
125
127
  return owner != null && getOutermostRoot(owner) === root;
126
128
  }
129
+
130
+ /**
131
+ * DropdownMenu's options for the press model: everything the public hook
132
+ * takes, plus its touch model. DropdownMenu reaches the touch model through
133
+ * its `presentation`, so the public hook has no such option.
134
+ *
135
+ * @internal
136
+ */
137
+
138
+ /**
139
+ * What core's own menus get from {@link useDropdownMenuPress}: the public
140
+ * return. Not exported from the hooks entry point.
141
+ *
142
+ * @internal
143
+ */
144
+
145
+ /**
146
+ * Where a pointer is, for a finger's handoff distance. Positions reach the
147
+ * machine only under `touchModel: 'uikit'`. Without them, it keeps the settle
148
+ * rule.
149
+ */
150
+ function handoffPosition(event, hasHandoff) {
151
+ return hasHandoff ? {
152
+ x: event.clientX,
153
+ y: event.clientY
154
+ } : {};
155
+ }
156
+
127
157
  /**
128
158
  * The press model for a menu: the row under the release acts, the highlight
129
159
  * follows a held pointer, and a mouse opens the menu on press.
@@ -160,6 +190,26 @@ function isInMenuTree(element, root) {
160
190
  * ```
161
191
  */
162
192
  export function useMenuPress(options) {
193
+ // The touch model is DropdownMenu's alone; an untyped caller's
194
+ // `touchModel` does not reach the model.
195
+ const {
196
+ touchModel: _touchModel,
197
+ ...publicOptions
198
+ } = options;
199
+ return useDropdownMenuPress({
200
+ ...publicOptions,
201
+ touchModel: 'pointer'
202
+ });
203
+ }
204
+
205
+ /**
206
+ * The press model with DropdownMenu's touch model
207
+ * ({@link DropdownMenuPressOptions.touchModel}). Not exported from the hooks
208
+ * entry point.
209
+ *
210
+ * @internal
211
+ */
212
+ export function useDropdownMenuPress(options) {
163
213
  const optionsRef = useRef(options);
164
214
  optionsRef.current = options;
165
215
  // The highlight, and the hover focus of the rows in this menu, follow the
@@ -247,8 +297,18 @@ export function useMenuPress(options) {
247
297
  autoscroll.stop();
248
298
  autoscrollRef.current = null;
249
299
  }, [autoscroll]);
300
+ const litRowRef = useRef(null);
301
+ const heldMenuRef = useRef(null);
250
302
  const endGesture = useCallback(() => {
251
303
  longPressApiRef.current?.cancel();
304
+ if (litRowRef.current != null) {
305
+ clearMenuPressLit(litRowRef.current);
306
+ litRowRef.current = null;
307
+ }
308
+ if (heldMenuRef.current != null) {
309
+ releaseMenuPressPaint(heldMenuRef.current);
310
+ heldMenuRef.current = null;
311
+ }
252
312
  touchMovePreventerRef.current?.();
253
313
  touchMovePreventerRef.current = null;
254
314
  stopAutoscroll();
@@ -259,10 +319,36 @@ export function useMenuPress(options) {
259
319
  gestureRef.current = IDLE_MENU_PRESS;
260
320
  }, [stopAutoscroll]);
261
321
  const highlight = useCallback(row => {
322
+ // A held finger or pen marks the row it lights, for the row's pressed
323
+ // paint. A held mouse keeps the hover tint, as on a desktop.
324
+ const gesture = gestureRef.current;
325
+ const isHeld = gesture.phase !== 'idle' && gesture.pointerType !== 'mouse';
326
+ const lit = isHeld ? row : null;
327
+ if (litRowRef.current !== lit) {
328
+ if (litRowRef.current != null) {
329
+ clearMenuPressLit(litRowRef.current);
330
+ }
331
+ litRowRef.current = lit;
332
+ if (lit != null) {
333
+ markMenuPressLit(lit);
334
+ }
335
+ }
262
336
  const {
263
337
  onHighlight,
264
338
  menuRef
265
339
  } = optionsRef.current;
340
+ // The row the press began on stays :active where a pointer hovers, so
341
+ // the menu holds every row but the lit one off that paint.
342
+ const held = isHeld ? menuRef.current : null;
343
+ if (heldMenuRef.current !== held) {
344
+ if (heldMenuRef.current != null) {
345
+ releaseMenuPressPaint(heldMenuRef.current);
346
+ }
347
+ heldMenuRef.current = held;
348
+ if (held != null) {
349
+ holdMenuPressPaint(held);
350
+ }
351
+ }
266
352
  if (onHighlight != null) {
267
353
  onHighlight(row);
268
354
  return;
@@ -369,7 +455,7 @@ export function useMenuPress(options) {
369
455
  }
370
456
  }, [activate, endGesture, getDocument, highlight]);
371
457
  const step = useCallback((event, native) => {
372
- const result = menuPressStep(gestureRef.current, event);
458
+ const result = menuPressTransition(gestureRef.current, event);
373
459
  gestureRef.current = result.gesture;
374
460
  applyEffect(result.effect, result.gesture, native);
375
461
  }, [applyEffect]);
@@ -466,7 +552,8 @@ export function useMenuPress(options) {
466
552
  type: 'move',
467
553
  row: point.row,
468
554
  isInMenu: point.isInMenu,
469
- time: Date.now()
555
+ time: Date.now(),
556
+ ...handoffPosition(event, optionsRef.current.touchModel === 'uikit')
470
557
  }, event);
471
558
  updateAutoscroll(event);
472
559
  };
@@ -480,7 +567,8 @@ export function useMenuPress(options) {
480
567
  row: point.row,
481
568
  isInMenu: point.isInMenu,
482
569
  isOnTrigger: point.isOnTrigger,
483
- time: Date.now()
570
+ time: Date.now(),
571
+ ...handoffPosition(event, optionsRef.current.touchModel === 'uikit')
484
572
  }, event);
485
573
  };
486
574
  const onCancel = event => {
@@ -7,11 +7,11 @@ import { pressableProps } from '../utils/pressFeedback.js';
7
7
  * `interactionOverlayStyles` (from `@astryxdesign/core/utils`) on the same
8
8
  * element: `backgroundColor` or `backgroundImage` for a surface whose hover
9
9
  * and press are the system's overlays, `pressedBackgroundColor` for one
10
- * whose hover is its own. The controller writes its attribute on the element
11
- * while a touch press is believed (after the onset delay, cancelled by travel
12
- * or by a scroll) and for the release, and the composed style paints the
13
- * pressed token at the press's strength on the first frame and fades it over
14
- * the release, keeping `:active` for a mouse on a desktop. On a phone or
10
+ * whose hover is its own. Under a finger the controller tracks the press the
11
+ * way UIKit tracks a control and writes its
12
+ * attribute on the element while the press is held and for the release; the
13
+ * composed style paints the pressed token on the first frame and fades it
14
+ * over the release, keeping `:active` for a mouse on a desktop. On a phone or
15
15
  * tablet the stylesheet drops `:active` for every press, so the controller
16
16
  * also paints a mouse, trackpad or Space-key press there, at once. A press is
17
17
  * themed through `--color-overlay-pressed`, which the hold, the flash and the
@@ -27,7 +27,7 @@ import { pressableProps } from '../utils/pressFeedback.js';
27
27
  * @example
28
28
  * ```
29
29
  * const pressable = usePressFeedback();
30
- * return <div role="button" {...pressable} {...stylex.props(styles.row)} />;
30
+ * return <button {...pressable} {...stylex.props(styles.button)} />;
31
31
  * ```
32
32
  */
33
33
  export declare function usePressFeedback(): typeof pressableProps;
@@ -25,11 +25,11 @@ import { installPressFeedback, pressableProps } from "../utils/pressFeedback.js"
25
25
  * `interactionOverlayStyles` (from `@astryxdesign/core/utils`) on the same
26
26
  * element: `backgroundColor` or `backgroundImage` for a surface whose hover
27
27
  * and press are the system's overlays, `pressedBackgroundColor` for one
28
- * whose hover is its own. The controller writes its attribute on the element
29
- * while a touch press is believed (after the onset delay, cancelled by travel
30
- * or by a scroll) and for the release, and the composed style paints the
31
- * pressed token at the press's strength on the first frame and fades it over
32
- * the release, keeping `:active` for a mouse on a desktop. On a phone or
28
+ * whose hover is its own. Under a finger the controller tracks the press the
29
+ * way UIKit tracks a control and writes its
30
+ * attribute on the element while the press is held and for the release; the
31
+ * composed style paints the pressed token on the first frame and fades it
32
+ * over the release, keeping `:active` for a mouse on a desktop. On a phone or
33
33
  * tablet the stylesheet drops `:active` for every press, so the controller
34
34
  * also paints a mouse, trackpad or Space-key press there, at once. A press is
35
35
  * themed through `--color-overlay-pressed`, which the hold, the flash and the
@@ -45,7 +45,7 @@ import { installPressFeedback, pressableProps } from "../utils/pressFeedback.js"
45
45
  * @example
46
46
  * ```
47
47
  * const pressable = usePressFeedback();
48
- * return <div role="button" {...pressable} {...stylex.props(styles.row)} />;
48
+ * return <button {...pressable} {...stylex.props(styles.button)} />;
49
49
  * ```
50
50
  */
51
51
  export function usePressFeedback() {
@@ -0,0 +1,58 @@
1
+ type Writable = Record<string, unknown>;
2
+ /** One animation's state, read before the browser starts it afresh. */
3
+ export interface SavedAnimation {
4
+ animation: Animation;
5
+ name: string;
6
+ target: Element | null;
7
+ pseudoElement: string | null;
8
+ values: Writable;
9
+ effectValues: Writable;
10
+ timing: EffectTiming | null;
11
+ keyframes: ComputedKeyframe[] | null;
12
+ playState: AnimationPlayState;
13
+ replaceState: AnimationReplaceState;
14
+ }
15
+ /**
16
+ * Reads one animation's state generically, from what the platform exposes.
17
+ * That is every accessor with a setter on the animation's and its effect's
18
+ * prototype chains, every field of the effect's timing, and its keyframes. Only values
19
+ * that differ from the recreated animation's are written back, so a value the
20
+ * stylesheet controls stays under its control. A few members are not plain
21
+ * state and are written in their own step (`ORDERED`). The Animation and
22
+ * effect objects themselves cannot be carried over: the old ones keep their
23
+ * listeners and promises.
24
+ */
25
+ export declare function saveAnimation(animation: Animation): SavedAnimation;
26
+ /**
27
+ * Puts each state `saved` holds on the CSS animations and transitions of
28
+ * `root` and its subtree that are not among `survivors`. Each CSS animation
29
+ * the browser started afresh takes the state of the one it replaces. It is
30
+ * matched by element, pseudo-element and name, in order, and then by name
31
+ * alone (an effect script moved to another element or pseudo-element). Each
32
+ * transition whose animation no longer runs resumes as a script animation in
33
+ * its state. One started afresh that replaces none is finished: an entrance
34
+ * that had played and been dropped, or a transition from `@starting-style`.
35
+ * Script animations are left as they are.
36
+ */
37
+ export declare function restoreAnimations(root: Element, saved: ReadonlyArray<SavedAnimation>, survivors: ReadonlySet<Animation>): void;
38
+ /** The CSS animations and transitions `saveAnimations` read. */
39
+ export type SavedAnimations = ReadonlyArray<SavedAnimation>;
40
+ /**
41
+ * Reads the state of every CSS animation and transition of `root` and its
42
+ * subtree, for `carryAnimations` to give a copy of it.
43
+ */
44
+ export declare function saveAnimations(root: Element): SavedAnimations;
45
+ /**
46
+ * Carries on in `copy`, a clone of the root `saved` was read from, now laid
47
+ * out, the CSS animations and transitions its element ran. A clone starts
48
+ * each CSS animation again and runs no transition but a `@starting-style`
49
+ * one. So each CSS animation the clone started takes the state of its
50
+ * element's, and each transition runs on as a script animation. One the
51
+ * clone started that its element no longer ran is finished: an entrance that
52
+ * had played, or a `@starting-style` transition. `copyOf` maps each element
53
+ * of the cloned subtree to its copy. The element's own animations keep
54
+ * running, so the copy's take no id or event handler.
55
+ */
56
+ export declare function carryAnimations(saved: SavedAnimations, copy: Element, copyOf: (element: Element) => Element | null): void;
57
+ export {};
58
+ //# sourceMappingURL=carryAnimations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carryAnimations.d.ts","sourceRoot":"","sources":["../../src/motion/carryAnimations.ts"],"names":[],"mappings":"AA+BA,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAsDxC,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,QAAQ,CAAC;IACjB,YAAY,EAAE,QAAQ,CAAC;IACvB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACrC,SAAS,EAAE,kBAAkB,CAAC;IAC9B,YAAY,EAAE,qBAAqB,CAAC;CACrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,cAAc,CAyBlE;AAsJD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC,EACpC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,GAChC,IAAI,CA8CN;AAED,gEAAgE;AAChE,MAAM,MAAM,eAAe,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AAE5D;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,CAQ7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAG,IAAI,GAC3C,IAAI,CASN"}
@@ -0,0 +1,305 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file carryAnimations.ts
5
+ * @input The CSS animations and transitions of an element and its subtree,
6
+ * read before the browser starts them afresh
7
+ * @output Exports `saveAnimations` and `carryAnimations`, which carry them on
8
+ * in a clone of the element. Also `saveAnimation` and `restoreAnimations`,
9
+ * which put them back after a display reset
10
+ * @position Motion foundation; the transient copy (transientCopy.ts) and the
11
+ * layer runtime's re-placement (Layer/preserveAnimations.ts) use it
12
+ */
13
+
14
+ /**
15
+ * Animation members written in a fixed order rather than generically: the
16
+ * timeline before the range that is measured on it, the rate before the
17
+ * time, and the start time (or, for a paused animation, the current time)
18
+ * last, once the play state is set. `effect` is not
19
+ * replaced, because a CSS animation whose effect script replaces leaves the
20
+ * stylesheet's control; its state is copied onto the new effect instead.
21
+ */
22
+ const ORDERED = new Set(['effect', 'timeline', 'rangeStart', 'rangeEnd', 'playbackRate', 'startTime', 'currentTime']);
23
+ /** Every accessor with a setter on `object`'s prototype chain. */
24
+ function writableAccessors(object) {
25
+ const names = new Set();
26
+ for (let proto = Object.getPrototypeOf(object); proto != null && proto !== Object.prototype; proto = Object.getPrototypeOf(proto)) {
27
+ for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(proto))) {
28
+ if (descriptor.set != null) {
29
+ names.add(name);
30
+ }
31
+ }
32
+ }
33
+ return [...names];
34
+ }
35
+
36
+ /**
37
+ * A textual form of a value that is compared by content rather than by
38
+ * identity: a CSS numeric value (as in a timeline range offset) through its
39
+ * serialization, a plain object (a range) through its members. Anything else
40
+ * is compared by identity (`null`).
41
+ */
42
+ function contentOf(value) {
43
+ if (typeof CSSNumericValue !== 'undefined' && value instanceof CSSNumericValue) {
44
+ return value.toString();
45
+ }
46
+ if (value != null && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
47
+ return Object.entries(value).map(([key, inner]) => `${key}:${contentOf(inner) ?? String(inner)}`).join(';');
48
+ }
49
+ return null;
50
+ }
51
+ function differs(a, b) {
52
+ if (a === b) {
53
+ return false;
54
+ }
55
+ const textA = contentOf(a);
56
+ return textA == null || textA !== contentOf(b);
57
+ }
58
+
59
+ /** One animation's state, read before the browser starts it afresh. */
60
+
61
+ /**
62
+ * Reads one animation's state generically, from what the platform exposes.
63
+ * That is every accessor with a setter on the animation's and its effect's
64
+ * prototype chains, every field of the effect's timing, and its keyframes. Only values
65
+ * that differ from the recreated animation's are written back, so a value the
66
+ * stylesheet controls stays under its control. A few members are not plain
67
+ * state and are written in their own step (`ORDERED`). The Animation and
68
+ * effect objects themselves cannot be carried over: the old ones keep their
69
+ * listeners and promises.
70
+ */
71
+ export function saveAnimation(animation) {
72
+ const effect = animation.effect;
73
+ const values = {};
74
+ for (const name of writableAccessors(animation)) {
75
+ values[name] = animation[name];
76
+ }
77
+ const effectValues = {};
78
+ if (effect != null) {
79
+ for (const name of writableAccessors(effect)) {
80
+ effectValues[name] = effect[name];
81
+ }
82
+ }
83
+ return {
84
+ animation,
85
+ name: animation.animationName ?? '',
86
+ target: effect?.target ?? null,
87
+ pseudoElement: effect?.pseudoElement ?? null,
88
+ values,
89
+ effectValues,
90
+ timing: effect?.getTiming() ?? null,
91
+ keyframes: effect?.getKeyframes() ?? null,
92
+ playState: animation.playState,
93
+ replaceState: animation.replaceState
94
+ };
95
+ }
96
+ function write(object, name, value) {
97
+ object[name] = value;
98
+ }
99
+
100
+ /** Give `next` the effect state `saved` had: every writable member. */
101
+ function restoreEffect(next, saved) {
102
+ for (const name of writableAccessors(next)) {
103
+ if (name in saved.effectValues && differs(saved.effectValues[name], next[name])) {
104
+ write(next, name, saved.effectValues[name]);
105
+ }
106
+ }
107
+ if (saved.timing != null) {
108
+ const timing = next.getTiming();
109
+ const changed = {};
110
+ for (const [field, value] of Object.entries(saved.timing)) {
111
+ if (differs(value, timing[field])) {
112
+ changed[field] = value;
113
+ }
114
+ }
115
+ if (Object.keys(changed).length > 0) {
116
+ next.updateTiming(changed);
117
+ }
118
+ }
119
+ if (saved.keyframes != null && JSON.stringify(saved.keyframes) !== JSON.stringify(next.getKeyframes())) {
120
+ next.setKeyframes(saved.keyframes);
121
+ }
122
+ }
123
+
124
+ /** Give `next` the state `saved` had, member by member. */
125
+ function restore(next, saved) {
126
+ const effect = next.effect;
127
+ if (effect != null) {
128
+ restoreEffect(effect, saved);
129
+ }
130
+ const current = next;
131
+ for (const name of ['timeline', 'rangeStart', 'rangeEnd']) {
132
+ if (name in saved.values && differs(saved.values[name], current[name])) {
133
+ write(next, name, saved.values[name]);
134
+ }
135
+ }
136
+ for (const name of writableAccessors(next)) {
137
+ if (!ORDERED.has(name) && name in saved.values && differs(saved.values[name], current[name])) {
138
+ write(next, name, saved.values[name]);
139
+ }
140
+ }
141
+ if (saved.replaceState === 'persisted' && next.replaceState !== 'persisted') {
142
+ next.persist();
143
+ }
144
+ const rate = saved.values.playbackRate;
145
+ if (typeof rate === 'number' && rate !== next.playbackRate) {
146
+ next.playbackRate = rate;
147
+ }
148
+ if (saved.playState === 'paused' && next.playState !== 'paused') {
149
+ next.pause();
150
+ } else if (saved.playState !== 'paused' && next.playState === 'paused') {
151
+ next.play();
152
+ }
153
+ // A running animation is anchored to its timeline by its start time, which
154
+ // carries its current time on exactly. A paused one has none and keeps its
155
+ // current time. A finished one holds its end: finishing it again holds the
156
+ // same time, though its start time is then counted from now, since script
157
+ // cannot set a start time and a held time together.
158
+ const start = saved.values.startTime;
159
+ const time = saved.values.currentTime;
160
+ if (saved.playState === 'finished') {
161
+ next.finish();
162
+ } else if (start != null) {
163
+ next.startTime = start;
164
+ } else if (time != null) {
165
+ next.currentTime = time;
166
+ }
167
+ }
168
+
169
+ /** Resume a cancelled CSS transition with a script animation in its state. */
170
+ function resumeTransition(saved) {
171
+ if (saved.target == null || saved.keyframes == null) {
172
+ return;
173
+ }
174
+ const replacement = saved.target.animate(saved.keyframes, {
175
+ pseudoElement: saved.pseudoElement ?? undefined
176
+ });
177
+ restore(replacement, saved);
178
+ }
179
+ function isTransition(animation) {
180
+ return typeof CSSTransition !== 'undefined' && animation instanceof CSSTransition;
181
+ }
182
+ function isCssAnimation(animation) {
183
+ return typeof CSSAnimation !== 'undefined' && animation instanceof CSSAnimation;
184
+ }
185
+
186
+ /**
187
+ * Finishes an animation that ends: an infinite one cannot be finished, and is
188
+ * left as it runs.
189
+ */
190
+ function finishIfItEnds(animation) {
191
+ const end = animation.effect?.getComputedTiming().endTime;
192
+ if (end != null && Number.isFinite(Number(end)) && animation.playbackRate !== 0) {
193
+ animation.finish();
194
+ }
195
+ }
196
+
197
+ /** The members a copy's animation does not take: its element's keep them. */
198
+ const IDENTITY_MEMBERS = new Set(['id', 'onfinish', 'oncancel', 'onremove']);
199
+
200
+ /**
201
+ * `saved` for an animation that carries on on the copy of its element:
202
+ * aimed at the copy, without the element's id and event handlers.
203
+ */
204
+ function retarget(saved, copyOf) {
205
+ const target = saved.target == null ? null : copyOf(saved.target);
206
+ if (target == null) {
207
+ return null;
208
+ }
209
+ const values = Object.fromEntries(Object.entries(saved.values).filter(([name]) => !IDENTITY_MEMBERS.has(name)));
210
+ const effectValues = {
211
+ ...saved.effectValues
212
+ };
213
+ if ('target' in effectValues) {
214
+ effectValues.target = target;
215
+ }
216
+ return {
217
+ ...saved,
218
+ target,
219
+ values,
220
+ effectValues
221
+ };
222
+ }
223
+
224
+ /**
225
+ * Puts each state `saved` holds on the CSS animations and transitions of
226
+ * `root` and its subtree that are not among `survivors`. Each CSS animation
227
+ * the browser started afresh takes the state of the one it replaces. It is
228
+ * matched by element, pseudo-element and name, in order, and then by name
229
+ * alone (an effect script moved to another element or pseudo-element). Each
230
+ * transition whose animation no longer runs resumes as a script animation in
231
+ * its state. One started afresh that replaces none is finished: an entrance
232
+ * that had played and been dropped, or a transition from `@starting-style`.
233
+ * Script animations are left as they are.
234
+ */
235
+ export function restoreAnimations(root, saved, survivors) {
236
+ const after = root.getAnimations({
237
+ subtree: true
238
+ });
239
+ const current = new Set(after);
240
+ const cancelled = [];
241
+ for (const state of saved) {
242
+ if (current.has(state.animation)) {
243
+ continue;
244
+ }
245
+ if (isTransition(state.animation)) {
246
+ resumeTransition(state);
247
+ } else {
248
+ cancelled.push(state);
249
+ }
250
+ }
251
+ const recreated = after.filter(animation => (isCssAnimation(animation) || isTransition(animation)) && !survivors.has(animation));
252
+ const unmatched = [];
253
+ for (const animation of recreated) {
254
+ const effect = animation.effect;
255
+ const name = animation.animationName ?? '';
256
+ const index = cancelled.findIndex(state => state.name === name && state.target === (effect?.target ?? null) && state.pseudoElement === (effect?.pseudoElement ?? null));
257
+ if (index === -1) {
258
+ unmatched.push(animation);
259
+ } else {
260
+ restore(animation, cancelled.splice(index, 1)[0]);
261
+ }
262
+ }
263
+ for (const animation of unmatched) {
264
+ const name = animation.animationName ?? '';
265
+ const index = cancelled.findIndex(state => state.name === name);
266
+ if (index === -1) {
267
+ finishIfItEnds(animation);
268
+ } else {
269
+ restore(animation, cancelled.splice(index, 1)[0]);
270
+ }
271
+ }
272
+ }
273
+
274
+ /** The CSS animations and transitions `saveAnimations` read. */
275
+
276
+ /**
277
+ * Reads the state of every CSS animation and transition of `root` and its
278
+ * subtree, for `carryAnimations` to give a copy of it.
279
+ */
280
+ export function saveAnimations(root) {
281
+ if (typeof root.getAnimations !== 'function') {
282
+ return [];
283
+ }
284
+ return root.getAnimations({
285
+ subtree: true
286
+ }).filter(animation => isCssAnimation(animation) || isTransition(animation)).map(saveAnimation);
287
+ }
288
+
289
+ /**
290
+ * Carries on in `copy`, a clone of the root `saved` was read from, now laid
291
+ * out, the CSS animations and transitions its element ran. A clone starts
292
+ * each CSS animation again and runs no transition but a `@starting-style`
293
+ * one. So each CSS animation the clone started takes the state of its
294
+ * element's, and each transition runs on as a script animation. One the
295
+ * clone started that its element no longer ran is finished: an entrance that
296
+ * had played, or a `@starting-style` transition. `copyOf` maps each element
297
+ * of the cloned subtree to its copy. The element's own animations keep
298
+ * running, so the copy's take no id or event handler.
299
+ */
300
+ export function carryAnimations(saved, copy, copyOf) {
301
+ if (typeof copy.getAnimations !== 'function') {
302
+ return;
303
+ }
304
+ restoreAnimations(copy, saved.flatMap(state => retarget(state, copyOf) ?? []), new Set());
305
+ }
@@ -4,7 +4,8 @@ export declare function isCopyable(element: Element): boolean;
4
4
  * A copy that takes no part: no ids or test ids, no form or radio group (a
5
5
  * copied checked radio would uncheck the live one), no label for a live
6
6
  * control, and copied frames and media load nothing. Scrolled descendants
7
- * keep their offsets once the copy is laid out (`placeOver`).
7
+ * keep their offsets. The CSS animations and transitions running in it carry
8
+ * on from where they were, once the copy is laid out (`placeOver`).
8
9
  */
9
10
  export declare function inertCopy(element: HTMLElement): HTMLElement | null;
10
11
  /** The background `element` shows: its own, or the nearest ancestor's. */
@@ -12,7 +13,8 @@ export declare function paintedBackground(element: Element): string;
12
13
  /**
13
14
  * Lay `element` over `rect` (viewport coordinates), absolutely, as the last
14
15
  * child of `host`, wherever its containing block is: no ancestor's position
15
- * changes.
16
+ * changes. A copy's scrolled descendants then restore their offsets, and the
17
+ * CSS animations and transitions its element ran carry on in it.
16
18
  */
17
19
  export declare function placeOver(element: HTMLElement, host: Element, rect: DOMRect): void;
18
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"transientCopy.d.ts","sourceRoot":"","sources":["../../src/motion/transientCopy.ts"],"names":[],"mappings":"AAiCA,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEpD;AAqHD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CA0ClE;AAED,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAQ1D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,OAAO,GACZ,IAAI,CAwDN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG;IACrD,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,IAAI,CA8CP;AAID;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,EAAE,CA6BrD"}
1
+ {"version":3,"file":"transientCopy.d.ts","sourceRoot":"","sources":["../../src/motion/transientCopy.ts"],"names":[],"mappings":"AA0CA,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEpD;AA+HD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CA8ClE;AAED,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAQ1D;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,OAAO,GACZ,IAAI,CAiEN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG;IACrD,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,IAAI,CAoDP;AAID;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,EAAE,CA6BrD"}