@astryxdesign/core 0.7.8 → 0.7.9-canary.7400c1f
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.
- package/dist/Calendar/styles.d.ts +1 -1
- package/dist/ClickableCard/ClickableCard.d.ts +1 -1
- package/dist/ClickableCard/ClickableCard.d.ts.map +1 -1
- package/dist/ClickableCard/ClickableCard.js +5 -1
- package/dist/DateInput/PickerWheel.d.ts.map +1 -1
- package/dist/DateInput/PickerWheel.js +7 -1
- package/dist/DateRangeInput/DateRangeInput.js +1 -1
- package/dist/Dialog/Dialog.d.ts +2 -1
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +8 -1
- package/dist/Drawer/useDrawerDialogPresence.d.ts +2 -1
- package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
- package/dist/Drawer/useDrawerDialogPresence.js +11 -2
- package/dist/DropdownMenu/DropdownMenu.d.ts +9 -1
- package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenu.js +9 -4
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.js +3 -2
- package/dist/DropdownMenu/DropdownMenuItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuItem.js +3 -2
- package/dist/DropdownMenu/DropdownMenuRadioItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuRadioItem.js +3 -2
- package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuSubMenu.js +3 -2
- package/dist/Field/inputDisabledFocus.d.ts +4 -4
- package/dist/Field/inputStyles.stylex.d.ts +1 -1
- package/dist/FileInput/FileInput.d.ts.map +1 -1
- package/dist/FileInput/FileInput.js +16 -2
- package/dist/Icon/Icon.d.ts +1 -1
- package/dist/InfoTip/InfoTip.d.ts +1 -0
- package/dist/InfoTip/InfoTip.d.ts.map +1 -1
- package/dist/InfoTip/InfoTip.js +1 -0
- package/dist/Item/Item.d.ts +2 -1
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +29 -6
- package/dist/Layer/holdEntranceInput.d.ts +24 -0
- package/dist/Layer/holdEntranceInput.d.ts.map +1 -0
- package/dist/Layer/holdEntranceInput.js +65 -0
- package/dist/Layer/inputHold.d.ts +49 -0
- package/dist/Layer/inputHold.d.ts.map +1 -0
- package/dist/Layer/inputHold.js +636 -0
- package/dist/Layer/preserveAnimations.d.ts +1 -5
- package/dist/Layer/preserveAnimations.d.ts.map +1 -1
- package/dist/Layer/preserveAnimations.js +12 -214
- package/dist/MetadataList/MetadataList.js +1 -1
- package/dist/MobileNav/MobileNav.d.ts +11 -1
- package/dist/MobileNav/MobileNav.d.ts.map +1 -1
- package/dist/MobileNav/MobileNav.js +34 -1
- package/dist/MoreMenu/MoreMenu.d.ts +5 -3
- package/dist/MoreMenu/MoreMenu.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +4 -1
- package/dist/SelectableCard/SelectableCard.d.ts +1 -1
- package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
- package/dist/SelectableCard/SelectableCard.js +5 -1
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +12 -2
- package/dist/Table/plugins/sortable/useTableSortable.js +1 -1
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +9 -0
- package/dist/Token/TokenLink.d.ts +1 -1
- package/dist/Token/TokenLink.d.ts.map +1 -1
- package/dist/Token/TokenLink.js +4 -1
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +162 -59
- package/dist/TreeList/TreeListItem.d.ts +2 -1
- package/dist/TreeList/TreeListItem.d.ts.map +1 -1
- package/dist/TreeList/TreeListItem.js +27 -3
- package/dist/astryx.css +30 -7
- package/dist/gestures/GestureHost.d.ts +2 -2
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +21 -6
- package/dist/gestures/nativeScroll.d.ts +3 -6
- package/dist/gestures/nativeScroll.d.ts.map +1 -1
- package/dist/gestures/nativeScroll.js +7 -52
- package/dist/gestures/wheelSegmenter.d.ts +68 -1
- package/dist/gestures/wheelSegmenter.d.ts.map +1 -1
- package/dist/gestures/wheelSegmenter.js +199 -10
- package/dist/hooks/menuPressGesture.d.ts +133 -21
- package/dist/hooks/menuPressGesture.d.ts.map +1 -1
- package/dist/hooks/menuPressGesture.js +155 -30
- package/dist/hooks/menuPressValues.d.ts +16 -0
- package/dist/hooks/menuPressValues.d.ts.map +1 -0
- package/dist/hooks/menuPressValues.js +18 -0
- package/dist/hooks/useClickableContainer.d.ts +27 -5
- package/dist/hooks/useClickableContainer.d.ts.map +1 -1
- package/dist/hooks/useClickableContainer.js +41 -5
- package/dist/hooks/useMenuPress.d.ts +34 -1
- package/dist/hooks/useMenuPress.d.ts.map +1 -1
- package/dist/hooks/useMenuPress.js +93 -5
- package/dist/hooks/usePressFeedback.d.ts +6 -6
- package/dist/hooks/usePressFeedback.js +6 -6
- package/dist/motion/carryAnimations.d.ts +58 -0
- package/dist/motion/carryAnimations.d.ts.map +1 -0
- package/dist/motion/carryAnimations.js +305 -0
- package/dist/motion/transientCopy.d.ts +4 -2
- package/dist/motion/transientCopy.d.ts.map +1 -1
- package/dist/motion/transientCopy.js +34 -5
- package/dist/motion/uikit/gestures.d.ts +41 -0
- package/dist/motion/uikit/gestures.d.ts.map +1 -1
- package/dist/motion/uikit/gestures.js +25 -0
- package/dist/motion/uikit/index.d.ts +1 -1
- package/dist/motion/uikit/index.d.ts.map +1 -1
- package/dist/motion/uikit/index.js +1 -1
- package/dist/privateAttributes/menuPressLit.stylex.d.ts +52 -0
- package/dist/privateAttributes/menuPressLit.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/menuPressLit.stylex.js +99 -0
- package/dist/privateAttributes/press.stylex.d.ts +139 -0
- package/dist/privateAttributes/press.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/press.stylex.js +98 -0
- package/dist/theme/tokens.stylex.d.ts +2 -2
- package/dist/theme/tokens.stylex.js +1 -1
- package/dist/utils/flatTree.d.ts +6 -3
- package/dist/utils/flatTree.d.ts.map +1 -1
- package/dist/utils/flatTree.js +13 -3
- package/dist/utils/hitArea.d.ts.map +1 -1
- package/dist/utils/hitArea.js +82 -5
- package/dist/utils/inputStream.d.ts +14 -1
- package/dist/utils/inputStream.d.ts.map +1 -1
- package/dist/utils/inputStream.js +40 -9
- package/dist/utils/interactionOverlay.stylex.d.ts +2 -1
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +7 -2
- package/dist/utils/pressFeedback.d.ts +7 -0
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +32 -7
- package/dist/utils/pressGesture.d.ts +6 -0
- package/dist/utils/pressGesture.d.ts.map +1 -1
- package/dist/utils/pressGesture.js +17 -0
- package/dist/utils/rowPressLayer.stylex.d.ts +14 -0
- package/dist/utils/rowPressLayer.stylex.d.ts.map +1 -0
- package/dist/utils/rowPressLayer.stylex.js +25 -0
- package/dist/utils/scrollView.d.ts +25 -0
- package/dist/utils/scrollView.d.ts.map +1 -0
- package/dist/utils/scrollView.js +108 -0
- package/dist/utils/selectionLock.d.ts.map +1 -1
- package/dist/utils/selectionLock.js +1 -10
- package/dist/utils/triggerFocus.d.ts +5 -0
- package/dist/utils/triggerFocus.d.ts.map +1 -1
- package/dist/utils/triggerFocus.js +9 -2
- package/package.json +5 -5
- package/src/ClickableCard/ClickableCard.tsx +8 -1
- package/src/DateInput/PickerWheel.tsx +7 -2
- package/src/DateRangeInput/DateRangeInput.tsx +1 -1
- package/src/Dialog/Dialog.doc.mjs +1 -1
- package/src/Dialog/Dialog.tsx +8 -1
- package/src/Drawer/Drawer.doc.mjs +1 -1
- package/src/Drawer/useDrawerDialogPresence.ts +9 -2
- package/src/DropdownMenu/DropdownMenu.doc.mjs +1 -2
- package/src/DropdownMenu/DropdownMenu.tsx +29 -5
- package/src/DropdownMenu/DropdownMenuCheckboxItem.tsx +5 -1
- package/src/DropdownMenu/DropdownMenuItem.tsx +8 -4
- package/src/DropdownMenu/DropdownMenuRadioItem.tsx +5 -1
- package/src/DropdownMenu/DropdownMenuSubMenu.tsx +5 -1
- package/src/FileInput/FileInput.tsx +16 -2
- package/src/InfoTip/InfoTip.doc.mjs +26 -2
- package/src/InfoTip/InfoTip.tsx +1 -0
- package/src/Item/Item.tsx +51 -9
- package/src/Layer/holdEntranceInput.ts +84 -0
- package/src/Layer/inputHold.ts +734 -0
- package/src/Layer/preserveAnimations.ts +12 -275
- package/src/MetadataList/MetadataList.tsx +1 -1
- package/src/MobileNav/MobileNav.doc.mjs +3 -3
- package/src/MobileNav/MobileNav.tsx +34 -1
- package/src/MoreMenu/MoreMenu.doc.mjs +2 -4
- package/src/MoreMenu/MoreMenu.tsx +5 -3
- package/src/RadioList/RadioListItem.tsx +4 -5
- package/src/SelectableCard/SelectableCard.tsx +8 -1
- package/src/Spinner/Spinner.tsx +13 -3
- package/src/Table/plugins/sortable/useTableSortable.tsx +1 -1
- package/src/Token/Token.tsx +18 -1
- package/src/Token/TokenLink.tsx +7 -1
- package/src/Tooltip/useTooltip.tsx +175 -79
- package/src/TreeList/TreeListItem.tsx +36 -2
- package/src/gestures/GestureHost.ts +21 -5
- package/src/gestures/README.md +12 -4
- package/src/gestures/nativeScroll.ts +12 -68
- package/src/gestures/wheelSegmenter.ts +243 -10
- package/src/hooks/menuPressGesture.ts +244 -38
- package/src/hooks/menuPressValues.ts +18 -0
- package/src/hooks/useClickableContainer.doc.mjs +8 -2
- package/src/hooks/useClickableContainer.ts +72 -6
- package/src/hooks/useMenuPress.ts +118 -11
- package/src/hooks/usePressFeedback.doc.mjs +3 -3
- package/src/hooks/usePressFeedback.ts +6 -6
- package/src/motion/MEASUREMENTS.md +11 -0
- package/src/motion/carryAnimations.ts +389 -0
- package/src/motion/transientCopy.ts +45 -5
- package/src/motion/uikit/gestures.ts +22 -0
- package/src/motion/uikit/index.ts +1 -0
- package/src/privateAttributes/menuPressLit.stylex.ts +104 -0
- package/src/privateAttributes/press.stylex.ts +244 -0
- package/src/theme/tokens.stylex.ts +1 -1
- package/src/utils/flatTree.ts +15 -3
- package/src/utils/hitArea.ts +107 -5
- package/src/utils/inputStream.ts +47 -10
- package/src/utils/interactionOverlay.stylex.ts +7 -2
- package/src/utils/pressFeedback.ts +31 -6
- package/src/utils/pressGesture.ts +24 -1
- package/src/utils/rowPressLayer.stylex.ts +27 -0
- package/src/utils/scrollView.ts +135 -0
- package/src/utils/selectionLock.ts +5 -10
- 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,
|
|
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.
|
|
@@ -29,10 +30,10 @@ import {
|
|
|
29
30
|
import {currentGesture} from '../Layer/gestureCounter';
|
|
30
31
|
import {
|
|
31
32
|
IDLE_MENU_PRESS,
|
|
32
|
-
|
|
33
|
-
type
|
|
34
|
-
type
|
|
35
|
-
type
|
|
33
|
+
menuPressTransition,
|
|
34
|
+
type MenuPressOutcome,
|
|
35
|
+
type MenuPressInput,
|
|
36
|
+
type MenuPressState,
|
|
36
37
|
type MenuPressPointerType,
|
|
37
38
|
} from './menuPressGesture';
|
|
38
39
|
import {MENU_PRESS_MARKER} from './menuPressMarker';
|
|
@@ -45,6 +46,12 @@ import {edgeAutoscroll} from '../utils/edgeAutoscroll';
|
|
|
45
46
|
import {focusForLastInput} from '../utils/focusReturn';
|
|
46
47
|
import {useInteractionModalityTrackingFor} from '../utils/interactionModality';
|
|
47
48
|
import {LONG_PRESS_DURATION_MS} from '../motion/uikit/longPress';
|
|
49
|
+
import {
|
|
50
|
+
clearMenuPressLit,
|
|
51
|
+
holdMenuPressPaint,
|
|
52
|
+
markMenuPressLit,
|
|
53
|
+
releaseMenuPressPaint,
|
|
54
|
+
} from '../privateAttributes/menuPressLit.stylex';
|
|
48
55
|
import {
|
|
49
56
|
__resetClickGuardForTest,
|
|
50
57
|
armClickGuard,
|
|
@@ -235,6 +242,44 @@ interface ResolvedPoint {
|
|
|
235
242
|
isOnTrigger: boolean;
|
|
236
243
|
}
|
|
237
244
|
|
|
245
|
+
/**
|
|
246
|
+
* DropdownMenu's options for the press model: everything the public hook
|
|
247
|
+
* takes, plus its touch model. DropdownMenu reaches the touch model through
|
|
248
|
+
* its `presentation`, so the public hook has no such option.
|
|
249
|
+
*
|
|
250
|
+
* @internal
|
|
251
|
+
*/
|
|
252
|
+
export interface DropdownMenuPressOptions extends UseMenuPressOptions {
|
|
253
|
+
/**
|
|
254
|
+
* How the finger that opened the menu from the trigger picks.
|
|
255
|
+
* `'pointer'`: its opening press follows the settle rule. `'uikit'`: it
|
|
256
|
+
* picks only after UIMenu's handoff distance, so the row that appeared
|
|
257
|
+
* under it never acts on a still lift. A mouse is unaffected.
|
|
258
|
+
* @default 'pointer'
|
|
259
|
+
*/
|
|
260
|
+
touchModel?: 'pointer' | 'uikit';
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* What core's own menus get from {@link useDropdownMenuPress}: the public
|
|
265
|
+
* return. Not exported from the hooks entry point.
|
|
266
|
+
*
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
269
|
+
export type DropdownMenuPressReturn = UseMenuPressReturn;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Where a pointer is, for a finger's handoff distance. Positions reach the
|
|
273
|
+
* machine only under `touchModel: 'uikit'`. Without them, it keeps the settle
|
|
274
|
+
* rule.
|
|
275
|
+
*/
|
|
276
|
+
function handoffPosition(
|
|
277
|
+
event: PointerEvent,
|
|
278
|
+
hasHandoff: boolean,
|
|
279
|
+
): {x?: number; y?: number} {
|
|
280
|
+
return hasHandoff ? {x: event.clientX, y: event.clientY} : {};
|
|
281
|
+
}
|
|
282
|
+
|
|
238
283
|
/**
|
|
239
284
|
* The press model for a menu: the row under the release acts, the highlight
|
|
240
285
|
* follows a held pointer, and a mouse opens the menu on press.
|
|
@@ -271,13 +316,30 @@ interface ResolvedPoint {
|
|
|
271
316
|
* ```
|
|
272
317
|
*/
|
|
273
318
|
export function useMenuPress(options: UseMenuPressOptions): UseMenuPressReturn {
|
|
319
|
+
// The touch model is DropdownMenu's alone; an untyped caller's
|
|
320
|
+
// `touchModel` does not reach the model.
|
|
321
|
+
const {touchModel: _touchModel, ...publicOptions} =
|
|
322
|
+
options as DropdownMenuPressOptions;
|
|
323
|
+
return useDropdownMenuPress({...publicOptions, touchModel: 'pointer'});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The press model with DropdownMenu's touch model
|
|
328
|
+
* ({@link DropdownMenuPressOptions.touchModel}). Not exported from the hooks
|
|
329
|
+
* entry point.
|
|
330
|
+
*
|
|
331
|
+
* @internal
|
|
332
|
+
*/
|
|
333
|
+
export function useDropdownMenuPress(
|
|
334
|
+
options: DropdownMenuPressOptions,
|
|
335
|
+
): DropdownMenuPressReturn {
|
|
274
336
|
const optionsRef = useRef(options);
|
|
275
337
|
optionsRef.current = options;
|
|
276
338
|
// The highlight, and the hover focus of the rows in this menu, follow the
|
|
277
339
|
// last input, which this tracks for the menu's own document.
|
|
278
340
|
useInteractionModalityTrackingFor(options.menuRef);
|
|
279
341
|
|
|
280
|
-
const gestureRef = useRef<
|
|
342
|
+
const gestureRef = useRef<MenuPressState<HTMLElement>>(IDLE_MENU_PRESS);
|
|
281
343
|
const pointerIdRef = useRef<number | null>(null);
|
|
282
344
|
const detachRef = useRef<(() => void) | null>(null);
|
|
283
345
|
// `useLongPress` detects the held finger, as in ContextMenu, so the hold
|
|
@@ -374,8 +436,18 @@ export function useMenuPress(options: UseMenuPressOptions): UseMenuPressReturn {
|
|
|
374
436
|
autoscrollRef.current = null;
|
|
375
437
|
}, [autoscroll]);
|
|
376
438
|
|
|
439
|
+
const litRowRef = useRef<HTMLElement | null>(null);
|
|
440
|
+
const heldMenuRef = useRef<HTMLElement | null>(null);
|
|
377
441
|
const endGesture = useCallback(() => {
|
|
378
442
|
longPressApiRef.current?.cancel();
|
|
443
|
+
if (litRowRef.current != null) {
|
|
444
|
+
clearMenuPressLit(litRowRef.current);
|
|
445
|
+
litRowRef.current = null;
|
|
446
|
+
}
|
|
447
|
+
if (heldMenuRef.current != null) {
|
|
448
|
+
releaseMenuPressPaint(heldMenuRef.current);
|
|
449
|
+
heldMenuRef.current = null;
|
|
450
|
+
}
|
|
379
451
|
touchMovePreventerRef.current?.();
|
|
380
452
|
touchMovePreventerRef.current = null;
|
|
381
453
|
stopAutoscroll();
|
|
@@ -388,7 +460,34 @@ export function useMenuPress(options: UseMenuPressOptions): UseMenuPressReturn {
|
|
|
388
460
|
|
|
389
461
|
const highlight = useCallback(
|
|
390
462
|
(row: HTMLElement | null) => {
|
|
463
|
+
// A held finger or pen marks the row it lights, for the row's pressed
|
|
464
|
+
// paint. A held mouse keeps the hover tint, as on a desktop.
|
|
465
|
+
const gesture = gestureRef.current;
|
|
466
|
+
const isHeld =
|
|
467
|
+
gesture.phase !== 'idle' && gesture.pointerType !== 'mouse';
|
|
468
|
+
const lit = isHeld ? row : null;
|
|
469
|
+
if (litRowRef.current !== lit) {
|
|
470
|
+
if (litRowRef.current != null) {
|
|
471
|
+
clearMenuPressLit(litRowRef.current);
|
|
472
|
+
}
|
|
473
|
+
litRowRef.current = lit;
|
|
474
|
+
if (lit != null) {
|
|
475
|
+
markMenuPressLit(lit);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
391
478
|
const {onHighlight, menuRef} = optionsRef.current;
|
|
479
|
+
// The row the press began on stays :active where a pointer hovers, so
|
|
480
|
+
// the menu holds every row but the lit one off that paint.
|
|
481
|
+
const held = isHeld ? menuRef.current : null;
|
|
482
|
+
if (heldMenuRef.current !== held) {
|
|
483
|
+
if (heldMenuRef.current != null) {
|
|
484
|
+
releaseMenuPressPaint(heldMenuRef.current);
|
|
485
|
+
}
|
|
486
|
+
heldMenuRef.current = held;
|
|
487
|
+
if (held != null) {
|
|
488
|
+
holdMenuPressPaint(held);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
392
491
|
if (onHighlight != null) {
|
|
393
492
|
onHighlight(row);
|
|
394
493
|
return;
|
|
@@ -449,13 +548,13 @@ export function useMenuPress(options: UseMenuPressOptions): UseMenuPressReturn {
|
|
|
449
548
|
|
|
450
549
|
// Declared before `step` so the mutual recursion through refs type-checks.
|
|
451
550
|
const stepRef = useRef<
|
|
452
|
-
(event:
|
|
551
|
+
(event: MenuPressInput<HTMLElement>, native?: PointerEvent) => void
|
|
453
552
|
>(() => {});
|
|
454
553
|
|
|
455
554
|
const applyEffect = useCallback(
|
|
456
555
|
(
|
|
457
|
-
effect:
|
|
458
|
-
gesture:
|
|
556
|
+
effect: MenuPressOutcome<HTMLElement>,
|
|
557
|
+
gesture: MenuPressState<HTMLElement>,
|
|
459
558
|
native: PointerEvent | undefined,
|
|
460
559
|
) => {
|
|
461
560
|
const doc = getDocument();
|
|
@@ -511,8 +610,8 @@ export function useMenuPress(options: UseMenuPressOptions): UseMenuPressReturn {
|
|
|
511
610
|
);
|
|
512
611
|
|
|
513
612
|
const step = useCallback(
|
|
514
|
-
(event:
|
|
515
|
-
const result =
|
|
613
|
+
(event: MenuPressInput<HTMLElement>, native?: PointerEvent) => {
|
|
614
|
+
const result = menuPressTransition(gestureRef.current, event);
|
|
516
615
|
gestureRef.current = result.gesture;
|
|
517
616
|
applyEffect(result.effect, result.gesture, native);
|
|
518
617
|
},
|
|
@@ -619,6 +718,10 @@ export function useMenuPress(options: UseMenuPressOptions): UseMenuPressReturn {
|
|
|
619
718
|
row: point.row,
|
|
620
719
|
isInMenu: point.isInMenu,
|
|
621
720
|
time: Date.now(),
|
|
721
|
+
...handoffPosition(
|
|
722
|
+
event,
|
|
723
|
+
optionsRef.current.touchModel === 'uikit',
|
|
724
|
+
),
|
|
622
725
|
},
|
|
623
726
|
event,
|
|
624
727
|
);
|
|
@@ -636,6 +739,10 @@ export function useMenuPress(options: UseMenuPressOptions): UseMenuPressReturn {
|
|
|
636
739
|
isInMenu: point.isInMenu,
|
|
637
740
|
isOnTrigger: point.isOnTrigger,
|
|
638
741
|
time: Date.now(),
|
|
742
|
+
...handoffPosition(
|
|
743
|
+
event,
|
|
744
|
+
optionsRef.current.touchModel === 'uikit',
|
|
745
|
+
),
|
|
639
746
|
},
|
|
640
747
|
event,
|
|
641
748
|
);
|
|
@@ -20,12 +20,12 @@ export const docs = {
|
|
|
20
20
|
name: 'pressableProps',
|
|
21
21
|
type: "{'data-astryx-pressable': ''}",
|
|
22
22
|
description:
|
|
23
|
-
"The marker attribute to spread on the element that paints the press. Compose one of `interactionOverlayStyles` (from `@astryxdesign/core/utils`) on the same element — `backgroundColor` or `backgroundImage` for a surface whose hover and press are the system's overlays, `pressedBackgroundColor` for one whose hover is its own — and it paints the pressed token
|
|
23
|
+
"The marker attribute to spread on the element that paints the press. Compose one of `interactionOverlayStyles` (from `@astryxdesign/core/utils`) on the same element — `backgroundColor` or `backgroundImage` for a surface whose hover and press are the system's overlays, `pressedBackgroundColor` for one whose hover is its own — and it paints the pressed token on the first frame of a press and fades it over the release, keeping `:active` for a mouse on a desktop. On a phone or tablet, where the stylesheet drops `:active`, the controller also paints a mouse, trackpad or Space-key press: at once, held while the button or key is down, faded at the release. A press is themed through `--color-overlay-pressed`.",
|
|
24
24
|
},
|
|
25
25
|
],
|
|
26
26
|
usage: {
|
|
27
27
|
description:
|
|
28
|
-
'The touch press model every Astryx pressable uses, for a local component that paints its own press. Under a finger, CSS `:active` paints on the touch itself and can outlive the start of a scroll; the press model instead
|
|
28
|
+
'The touch press model every Astryx pressable uses, for a local component that paints its own press. Under a finger, CSS `:active` paints on the touch itself and can outlive the start of a scroll; the press model instead tracks the touch the way UIKit tracks a control: it highlights as the finger lands (after the content-touch delay inside a scroller, where a flick paints nothing), a quick tap answers at the lift, and a scroll that takes the touch cancels it with no fade. One document-level controller does this for every marked element (installed by the first pressable to mount, removed by the last to unmount), so calling the hook adds no listener or state to your element. On a desktop a mouse press is still your `:active` rule: keep it, and drop it under `@media (pointer: coarse)` the way the built-in components do. That query reads the primary pointer, so on a phone or tablet it also drops `:active` for a connected mouse, trackpad or keyboard; the controller paints those presses there (at once, faded at the release), so nothing goes unanswered.',
|
|
29
29
|
bestPractices: [
|
|
30
30
|
{
|
|
31
31
|
guidance: true,
|
|
@@ -58,7 +58,7 @@ export const docs = {
|
|
|
58
58
|
/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
|
|
59
59
|
export const docsDense = {
|
|
60
60
|
description:
|
|
61
|
-
'Marks an element as a pressable surface of the touch press model
|
|
61
|
+
'Marks an element as a pressable surface of the touch press model, tracked like a UIKit control (highlight as the finger lands, 150 ms inside a scroller, fade at the lift), and installs the shared document controller; on a coarse primary pointer it also paints mouse, trackpad and Space-key presses at once. Returns the data-astryx-pressable marker to spread; compose one of interactionOverlayStyles on the same element to paint.',
|
|
62
62
|
paramDescriptions: {},
|
|
63
63
|
returnDescriptions: {
|
|
64
64
|
pressableProps:
|
|
@@ -26,11 +26,11 @@ import {installPressFeedback, pressableProps} from '../utils/pressFeedback';
|
|
|
26
26
|
* `interactionOverlayStyles` (from `@astryxdesign/core/utils`) on the same
|
|
27
27
|
* element: `backgroundColor` or `backgroundImage` for a surface whose hover
|
|
28
28
|
* and press are the system's overlays, `pressedBackgroundColor` for one
|
|
29
|
-
* whose hover is its own.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* the release, keeping `:active` for a mouse on a desktop. On a phone or
|
|
29
|
+
* whose hover is its own. Under a finger the controller tracks the press the
|
|
30
|
+
* way UIKit tracks a control and writes its
|
|
31
|
+
* attribute on the element while the press is held and for the release; the
|
|
32
|
+
* composed style paints the pressed token on the first frame and fades it
|
|
33
|
+
* over the release, keeping `:active` for a mouse on a desktop. On a phone or
|
|
34
34
|
* tablet the stylesheet drops `:active` for every press, so the controller
|
|
35
35
|
* also paints a mouse, trackpad or Space-key press there, at once. A press is
|
|
36
36
|
* themed through `--color-overlay-pressed`, which the hold, the flash and the
|
|
@@ -46,7 +46,7 @@ import {installPressFeedback, pressableProps} from '../utils/pressFeedback';
|
|
|
46
46
|
* @example
|
|
47
47
|
* ```
|
|
48
48
|
* const pressable = usePressFeedback();
|
|
49
|
-
* return <
|
|
49
|
+
* return <button {...pressable} {...stylex.props(styles.button)} />;
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
export function usePressFeedback(): typeof pressableProps {
|
|
@@ -314,3 +314,14 @@ scroll view coasts with 0.25 × the pan's velocity plus 0.75 × its value one
|
|
|
314
314
|
event earlier (four HID releases; `velocity.scrollReleaseWeight`, which a
|
|
315
315
|
pan's `scrollVelocity()` reads). On UIKit, Reduce Motion with Prefer Cross-Fade changes
|
|
316
316
|
nothing on a picker; the Wheel follows design:reduced-motion instead.
|
|
317
|
+
|
|
318
|
+
## Menus (UIMenu)
|
|
319
|
+
|
|
320
|
+
Probe: the UIKit lab host app with a UIButton whose `UIMenu` is its primary
|
|
321
|
+
action (`showsMenuAsPrimaryAction`), three to twelve items, on a plain view
|
|
322
|
+
and inside a UIScrollView; the gesture-state, presentation-modifier,
|
|
323
|
+
display-link and feedback hooks; real HID touches.
|
|
324
|
+
|
|
325
|
+
| ID | Scene | Gesture | Extract | Method |
|
|
326
|
+
| ----- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------ |
|
|
327
|
+
| M-MN2 | button on a plain view | hold until the menu is open, then lift still; move 8 pt down, 8 pt right, 12 pt down, (7, 7), (8, 8) and lift; move 6 pt before the open and 6 pt after | row picked or not; handoff and list-selection recognizer states; highlighted row per frame: threshold, metric, where it is counted from | C |
|
|
@@ -0,0 +1,389 @@
|
|
|
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([
|
|
23
|
+
'effect',
|
|
24
|
+
'timeline',
|
|
25
|
+
'rangeStart',
|
|
26
|
+
'rangeEnd',
|
|
27
|
+
'playbackRate',
|
|
28
|
+
'startTime',
|
|
29
|
+
'currentTime',
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
type Writable = Record<string, unknown>;
|
|
33
|
+
|
|
34
|
+
/** Every accessor with a setter on `object`'s prototype chain. */
|
|
35
|
+
function writableAccessors(object: object): string[] {
|
|
36
|
+
const names = new Set<string>();
|
|
37
|
+
for (
|
|
38
|
+
let proto: object | null = Object.getPrototypeOf(object);
|
|
39
|
+
proto != null && proto !== Object.prototype;
|
|
40
|
+
proto = Object.getPrototypeOf(proto)
|
|
41
|
+
) {
|
|
42
|
+
for (const [name, descriptor] of Object.entries(
|
|
43
|
+
Object.getOwnPropertyDescriptors(proto),
|
|
44
|
+
)) {
|
|
45
|
+
if (descriptor.set != null) {
|
|
46
|
+
names.add(name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return [...names];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A textual form of a value that is compared by content rather than by
|
|
55
|
+
* identity: a CSS numeric value (as in a timeline range offset) through its
|
|
56
|
+
* serialization, a plain object (a range) through its members. Anything else
|
|
57
|
+
* is compared by identity (`null`).
|
|
58
|
+
*/
|
|
59
|
+
function contentOf(value: unknown): string | null {
|
|
60
|
+
if (
|
|
61
|
+
typeof CSSNumericValue !== 'undefined' &&
|
|
62
|
+
value instanceof CSSNumericValue
|
|
63
|
+
) {
|
|
64
|
+
return value.toString();
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
value != null &&
|
|
68
|
+
typeof value === 'object' &&
|
|
69
|
+
Object.getPrototypeOf(value) === Object.prototype
|
|
70
|
+
) {
|
|
71
|
+
return Object.entries(value)
|
|
72
|
+
.map(([key, inner]) => `${key}:${contentOf(inner) ?? String(inner)}`)
|
|
73
|
+
.join(';');
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function differs(a: unknown, b: unknown): boolean {
|
|
79
|
+
if (a === b) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const textA = contentOf(a);
|
|
83
|
+
return textA == null || textA !== contentOf(b);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** One animation's state, read before the browser starts it afresh. */
|
|
87
|
+
export interface SavedAnimation {
|
|
88
|
+
animation: Animation;
|
|
89
|
+
name: string;
|
|
90
|
+
target: Element | null;
|
|
91
|
+
pseudoElement: string | null;
|
|
92
|
+
values: Writable;
|
|
93
|
+
effectValues: Writable;
|
|
94
|
+
timing: EffectTiming | null;
|
|
95
|
+
keyframes: ComputedKeyframe[] | null;
|
|
96
|
+
playState: AnimationPlayState;
|
|
97
|
+
replaceState: AnimationReplaceState;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Reads one animation's state generically, from what the platform exposes.
|
|
102
|
+
* That is every accessor with a setter on the animation's and its effect's
|
|
103
|
+
* prototype chains, every field of the effect's timing, and its keyframes. Only values
|
|
104
|
+
* that differ from the recreated animation's are written back, so a value the
|
|
105
|
+
* stylesheet controls stays under its control. A few members are not plain
|
|
106
|
+
* state and are written in their own step (`ORDERED`). The Animation and
|
|
107
|
+
* effect objects themselves cannot be carried over: the old ones keep their
|
|
108
|
+
* listeners and promises.
|
|
109
|
+
*/
|
|
110
|
+
export function saveAnimation(animation: Animation): SavedAnimation {
|
|
111
|
+
const effect = animation.effect as KeyframeEffect | null;
|
|
112
|
+
const values: Writable = {};
|
|
113
|
+
for (const name of writableAccessors(animation)) {
|
|
114
|
+
values[name] = (animation as unknown as Writable)[name];
|
|
115
|
+
}
|
|
116
|
+
const effectValues: Writable = {};
|
|
117
|
+
if (effect != null) {
|
|
118
|
+
for (const name of writableAccessors(effect)) {
|
|
119
|
+
effectValues[name] = (effect as unknown as Writable)[name];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
animation,
|
|
124
|
+
name:
|
|
125
|
+
(animation as Animation & {animationName?: string}).animationName ?? '',
|
|
126
|
+
target: effect?.target ?? null,
|
|
127
|
+
pseudoElement: effect?.pseudoElement ?? null,
|
|
128
|
+
values,
|
|
129
|
+
effectValues,
|
|
130
|
+
timing: effect?.getTiming() ?? null,
|
|
131
|
+
keyframes: effect?.getKeyframes() ?? null,
|
|
132
|
+
playState: animation.playState,
|
|
133
|
+
replaceState: animation.replaceState,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function write(object: object, name: string, value: unknown): void {
|
|
138
|
+
(object as Writable)[name] = value;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Give `next` the effect state `saved` had: every writable member. */
|
|
142
|
+
function restoreEffect(next: KeyframeEffect, saved: SavedAnimation): void {
|
|
143
|
+
for (const name of writableAccessors(next)) {
|
|
144
|
+
if (
|
|
145
|
+
name in saved.effectValues &&
|
|
146
|
+
differs(saved.effectValues[name], (next as unknown as Writable)[name])
|
|
147
|
+
) {
|
|
148
|
+
write(next, name, saved.effectValues[name]);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (saved.timing != null) {
|
|
152
|
+
const timing = next.getTiming() as unknown as Writable;
|
|
153
|
+
const changed: Writable = {};
|
|
154
|
+
for (const [field, value] of Object.entries(saved.timing)) {
|
|
155
|
+
if (differs(value, timing[field])) {
|
|
156
|
+
changed[field] = value;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (Object.keys(changed).length > 0) {
|
|
160
|
+
next.updateTiming(changed);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (
|
|
164
|
+
saved.keyframes != null &&
|
|
165
|
+
JSON.stringify(saved.keyframes) !== JSON.stringify(next.getKeyframes())
|
|
166
|
+
) {
|
|
167
|
+
next.setKeyframes(saved.keyframes);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Give `next` the state `saved` had, member by member. */
|
|
172
|
+
function restore(next: Animation, saved: SavedAnimation): void {
|
|
173
|
+
const effect = next.effect as KeyframeEffect | null;
|
|
174
|
+
if (effect != null) {
|
|
175
|
+
restoreEffect(effect, saved);
|
|
176
|
+
}
|
|
177
|
+
const current = next as unknown as Writable;
|
|
178
|
+
for (const name of ['timeline', 'rangeStart', 'rangeEnd']) {
|
|
179
|
+
if (name in saved.values && differs(saved.values[name], current[name])) {
|
|
180
|
+
write(next, name, saved.values[name]);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for (const name of writableAccessors(next)) {
|
|
184
|
+
if (
|
|
185
|
+
!ORDERED.has(name) &&
|
|
186
|
+
name in saved.values &&
|
|
187
|
+
differs(saved.values[name], current[name])
|
|
188
|
+
) {
|
|
189
|
+
write(next, name, saved.values[name]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (saved.replaceState === 'persisted' && next.replaceState !== 'persisted') {
|
|
193
|
+
next.persist();
|
|
194
|
+
}
|
|
195
|
+
const rate = saved.values.playbackRate;
|
|
196
|
+
if (typeof rate === 'number' && rate !== next.playbackRate) {
|
|
197
|
+
next.playbackRate = rate;
|
|
198
|
+
}
|
|
199
|
+
if (saved.playState === 'paused' && next.playState !== 'paused') {
|
|
200
|
+
next.pause();
|
|
201
|
+
} else if (saved.playState !== 'paused' && next.playState === 'paused') {
|
|
202
|
+
next.play();
|
|
203
|
+
}
|
|
204
|
+
// A running animation is anchored to its timeline by its start time, which
|
|
205
|
+
// carries its current time on exactly. A paused one has none and keeps its
|
|
206
|
+
// current time. A finished one holds its end: finishing it again holds the
|
|
207
|
+
// same time, though its start time is then counted from now, since script
|
|
208
|
+
// cannot set a start time and a held time together.
|
|
209
|
+
const start = saved.values.startTime as CSSNumberish | null | undefined;
|
|
210
|
+
const time = saved.values.currentTime as CSSNumberish | null | undefined;
|
|
211
|
+
if (saved.playState === 'finished') {
|
|
212
|
+
next.finish();
|
|
213
|
+
} else if (start != null) {
|
|
214
|
+
next.startTime = start;
|
|
215
|
+
} else if (time != null) {
|
|
216
|
+
next.currentTime = time;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Resume a cancelled CSS transition with a script animation in its state. */
|
|
221
|
+
function resumeTransition(saved: SavedAnimation): void {
|
|
222
|
+
if (saved.target == null || saved.keyframes == null) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const replacement = saved.target.animate(saved.keyframes, {
|
|
226
|
+
pseudoElement: saved.pseudoElement ?? undefined,
|
|
227
|
+
});
|
|
228
|
+
restore(replacement, saved);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function isTransition(animation: Animation): boolean {
|
|
232
|
+
return (
|
|
233
|
+
typeof CSSTransition !== 'undefined' && animation instanceof CSSTransition
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function isCssAnimation(animation: Animation): animation is CSSAnimation {
|
|
238
|
+
return (
|
|
239
|
+
typeof CSSAnimation !== 'undefined' && animation instanceof CSSAnimation
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Finishes an animation that ends: an infinite one cannot be finished, and is
|
|
245
|
+
* left as it runs.
|
|
246
|
+
*/
|
|
247
|
+
function finishIfItEnds(animation: Animation): void {
|
|
248
|
+
const end = animation.effect?.getComputedTiming().endTime;
|
|
249
|
+
if (
|
|
250
|
+
end != null &&
|
|
251
|
+
Number.isFinite(Number(end)) &&
|
|
252
|
+
animation.playbackRate !== 0
|
|
253
|
+
) {
|
|
254
|
+
animation.finish();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** The members a copy's animation does not take: its element's keep them. */
|
|
259
|
+
const IDENTITY_MEMBERS = new Set(['id', 'onfinish', 'oncancel', 'onremove']);
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* `saved` for an animation that carries on on the copy of its element:
|
|
263
|
+
* aimed at the copy, without the element's id and event handlers.
|
|
264
|
+
*/
|
|
265
|
+
function retarget(
|
|
266
|
+
saved: SavedAnimation,
|
|
267
|
+
copyOf: (element: Element) => Element | null,
|
|
268
|
+
): SavedAnimation | null {
|
|
269
|
+
const target = saved.target == null ? null : copyOf(saved.target);
|
|
270
|
+
if (target == null) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const values: Writable = Object.fromEntries(
|
|
274
|
+
Object.entries(saved.values).filter(
|
|
275
|
+
([name]) => !IDENTITY_MEMBERS.has(name),
|
|
276
|
+
),
|
|
277
|
+
);
|
|
278
|
+
const effectValues: Writable = {...saved.effectValues};
|
|
279
|
+
if ('target' in effectValues) {
|
|
280
|
+
effectValues.target = target;
|
|
281
|
+
}
|
|
282
|
+
return {...saved, target, values, effectValues};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Puts each state `saved` holds on the CSS animations and transitions of
|
|
287
|
+
* `root` and its subtree that are not among `survivors`. Each CSS animation
|
|
288
|
+
* the browser started afresh takes the state of the one it replaces. It is
|
|
289
|
+
* matched by element, pseudo-element and name, in order, and then by name
|
|
290
|
+
* alone (an effect script moved to another element or pseudo-element). Each
|
|
291
|
+
* transition whose animation no longer runs resumes as a script animation in
|
|
292
|
+
* its state. One started afresh that replaces none is finished: an entrance
|
|
293
|
+
* that had played and been dropped, or a transition from `@starting-style`.
|
|
294
|
+
* Script animations are left as they are.
|
|
295
|
+
*/
|
|
296
|
+
export function restoreAnimations(
|
|
297
|
+
root: Element,
|
|
298
|
+
saved: ReadonlyArray<SavedAnimation>,
|
|
299
|
+
survivors: ReadonlySet<Animation>,
|
|
300
|
+
): void {
|
|
301
|
+
const after = root.getAnimations({subtree: true});
|
|
302
|
+
const current = new Set(after);
|
|
303
|
+
const cancelled: SavedAnimation[] = [];
|
|
304
|
+
for (const state of saved) {
|
|
305
|
+
if (current.has(state.animation)) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (isTransition(state.animation)) {
|
|
309
|
+
resumeTransition(state);
|
|
310
|
+
} else {
|
|
311
|
+
cancelled.push(state);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const recreated = after.filter(
|
|
315
|
+
animation =>
|
|
316
|
+
(isCssAnimation(animation) || isTransition(animation)) &&
|
|
317
|
+
!survivors.has(animation),
|
|
318
|
+
);
|
|
319
|
+
const unmatched: Animation[] = [];
|
|
320
|
+
for (const animation of recreated) {
|
|
321
|
+
const effect = animation.effect as KeyframeEffect | null;
|
|
322
|
+
const name =
|
|
323
|
+
(animation as Animation & {animationName?: string}).animationName ?? '';
|
|
324
|
+
const index = cancelled.findIndex(
|
|
325
|
+
state =>
|
|
326
|
+
state.name === name &&
|
|
327
|
+
state.target === (effect?.target ?? null) &&
|
|
328
|
+
state.pseudoElement === (effect?.pseudoElement ?? null),
|
|
329
|
+
);
|
|
330
|
+
if (index === -1) {
|
|
331
|
+
unmatched.push(animation);
|
|
332
|
+
} else {
|
|
333
|
+
restore(animation, cancelled.splice(index, 1)[0]);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
for (const animation of unmatched) {
|
|
337
|
+
const name =
|
|
338
|
+
(animation as Animation & {animationName?: string}).animationName ?? '';
|
|
339
|
+
const index = cancelled.findIndex(state => state.name === name);
|
|
340
|
+
if (index === -1) {
|
|
341
|
+
finishIfItEnds(animation);
|
|
342
|
+
} else {
|
|
343
|
+
restore(animation, cancelled.splice(index, 1)[0]);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** The CSS animations and transitions `saveAnimations` read. */
|
|
349
|
+
export type SavedAnimations = ReadonlyArray<SavedAnimation>;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Reads the state of every CSS animation and transition of `root` and its
|
|
353
|
+
* subtree, for `carryAnimations` to give a copy of it.
|
|
354
|
+
*/
|
|
355
|
+
export function saveAnimations(root: Element): SavedAnimations {
|
|
356
|
+
if (typeof root.getAnimations !== 'function') {
|
|
357
|
+
return [];
|
|
358
|
+
}
|
|
359
|
+
return root
|
|
360
|
+
.getAnimations({subtree: true})
|
|
361
|
+
.filter(animation => isCssAnimation(animation) || isTransition(animation))
|
|
362
|
+
.map(saveAnimation);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Carries on in `copy`, a clone of the root `saved` was read from, now laid
|
|
367
|
+
* out, the CSS animations and transitions its element ran. A clone starts
|
|
368
|
+
* each CSS animation again and runs no transition but a `@starting-style`
|
|
369
|
+
* one. So each CSS animation the clone started takes the state of its
|
|
370
|
+
* element's, and each transition runs on as a script animation. One the
|
|
371
|
+
* clone started that its element no longer ran is finished: an entrance that
|
|
372
|
+
* had played, or a `@starting-style` transition. `copyOf` maps each element
|
|
373
|
+
* of the cloned subtree to its copy. The element's own animations keep
|
|
374
|
+
* running, so the copy's take no id or event handler.
|
|
375
|
+
*/
|
|
376
|
+
export function carryAnimations(
|
|
377
|
+
saved: SavedAnimations,
|
|
378
|
+
copy: Element,
|
|
379
|
+
copyOf: (element: Element) => Element | null,
|
|
380
|
+
): void {
|
|
381
|
+
if (typeof copy.getAnimations !== 'function') {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
restoreAnimations(
|
|
385
|
+
copy,
|
|
386
|
+
saved.flatMap(state => retarget(state, copyOf) ?? []),
|
|
387
|
+
new Set(),
|
|
388
|
+
);
|
|
389
|
+
}
|