@astryxdesign/core 0.7.8 → 0.7.9-canary.0a64fdb
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/AppShell/observeMainOverflow.d.ts.map +1 -1
- package/dist/AppShell/observeMainOverflow.js +9 -6
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +5 -0
- package/dist/Calendar/styles.d.ts +1 -1
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +54 -11
- 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 +12 -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/InputGroup/InputGroup.d.ts +4 -3
- package/dist/InputGroup/InputGroup.d.ts.map +1 -1
- package/dist/InputGroup/InputGroup.js +2 -2
- package/dist/InputGroup/groupStyles.d.ts +1 -1
- package/dist/InputGroup/groupStyles.d.ts.map +1 -1
- package/dist/InputGroup/groupStyles.js +1 -1
- 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/Layout/LayoutContent.d.ts +3 -1
- package/dist/Layout/LayoutContent.d.ts.map +1 -1
- package/dist/Layout/LayoutContent.js +12 -4
- package/dist/Layout/LayoutPanel.d.ts +4 -1
- package/dist/Layout/LayoutPanel.d.ts.map +1 -1
- package/dist/Layout/LayoutPanel.js +13 -4
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +4 -0
- 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 +39 -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 +22 -4
- 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/Stack/StackItem.d.ts +8 -4
- package/dist/Stack/StackItem.d.ts.map +1 -1
- package/dist/Stack/StackItem.js +17 -4
- 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 +35 -8
- 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/PanGestureRecognizer.d.ts +11 -1
- package/dist/gestures/PanGestureRecognizer.d.ts.map +1 -1
- package/dist/gestures/PanGestureRecognizer.js +15 -1
- package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts +6 -1
- package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts.map +1 -1
- 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/StackItemScrollRegion.d.ts +31 -0
- package/dist/hooks/StackItemScrollRegion.d.ts.map +1 -0
- package/dist/hooks/StackItemScrollRegion.js +40 -0
- 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/useFocusTrap.d.ts +10 -0
- package/dist/hooks/useFocusTrap.d.ts.map +1 -1
- package/dist/hooks/useFocusTrap.js +225 -132
- 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/hooks/useScrollRegionProps.d.ts +35 -0
- package/dist/hooks/useScrollRegionProps.d.ts.map +1 -0
- package/dist/hooks/useScrollRegionProps.js +51 -0
- package/dist/i18n/generated-english/hooks/useScrollRegionProps.generated.d.ts +8 -0
- package/dist/i18n/generated-english/hooks/useScrollRegionProps.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/hooks/useScrollRegionProps.generated.js +12 -0
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +1 -0
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +1 -0
- 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/touchHitArea.stylex.d.ts +35 -0
- package/dist/utils/touchHitArea.stylex.d.ts.map +1 -0
- package/dist/utils/touchHitArea.stylex.js +32 -0
- 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/locales/en.json +4 -0
- package/locales/pseudo.json +3 -0
- package/package.json +5 -5
- package/src/AppShell/observeMainOverflow.ts +9 -6
- package/src/BottomSheet/BottomSheet.tsx +5 -0
- package/src/CheckboxInput/CheckboxInput.doc.mjs +3 -2
- package/src/CheckboxInput/CheckboxInput.tsx +71 -9
- 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 +12 -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/InputGroup/InputGroup.doc.mjs +4 -3
- package/src/InputGroup/InputGroup.tsx +4 -3
- package/src/InputGroup/groupStyles.ts +3 -1
- 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/Layout/LayoutContent.doc.mjs +6 -3
- package/src/Layout/LayoutContent.tsx +10 -4
- package/src/Layout/LayoutPanel.doc.mjs +6 -3
- package/src/Layout/LayoutPanel.tsx +11 -4
- package/src/Lightbox/Lightbox.tsx +4 -0
- package/src/MetadataList/MetadataList.tsx +1 -1
- package/src/MobileNav/MobileNav.doc.mjs +3 -3
- package/src/MobileNav/MobileNav.tsx +39 -1
- package/src/MoreMenu/MoreMenu.doc.mjs +2 -4
- package/src/MoreMenu/MoreMenu.tsx +5 -3
- package/src/RadioList/RadioListItem.doc.mjs +3 -2
- package/src/RadioList/RadioListItem.tsx +25 -7
- package/src/SelectableCard/SelectableCard.tsx +8 -1
- package/src/Spinner/Spinner.tsx +13 -3
- package/src/Stack/Stack.doc.mjs +1 -1
- package/src/Stack/StackItem.tsx +27 -13
- 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/PanGestureRecognizer.ts +19 -2
- package/src/gestures/README.md +14 -5
- package/src/gestures/ScreenEdgePanGestureRecognizer.ts +6 -1
- package/src/gestures/nativeScroll.ts +12 -68
- package/src/gestures/wheelSegmenter.ts +243 -10
- package/src/hooks/StackItemScrollRegion.tsx +57 -0
- 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/useFocusTrap.ts +268 -151
- package/src/hooks/useMenuPress.ts +118 -11
- package/src/hooks/usePressFeedback.doc.mjs +3 -3
- package/src/hooks/usePressFeedback.ts +6 -6
- package/src/hooks/useScrollRegionProps.ts +76 -0
- package/src/i18n/generated-english/hooks/useScrollRegionProps.generated.ts +13 -0
- package/src/i18n/generated-locales/en.generated.ts +1 -0
- package/src/i18n/generated-locales/pseudo.generated.ts +1 -0
- 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/touchHitArea.stylex.ts +41 -0
- package/src/utils/triggerFocus.ts +17 -4
|
@@ -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 {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file useScrollRegionProps.ts
|
|
7
|
+
* @input Whether a region may scroll, and the caller's role and label
|
|
8
|
+
* @output useScrollRegionProps: a ref for the region, and the role and
|
|
9
|
+
* accessible name that the region carries while its content overflows
|
|
10
|
+
* @position Internal hook for LayoutContent, LayoutPanel and StackItem.
|
|
11
|
+
*
|
|
12
|
+
* SYNC: When modified, update:
|
|
13
|
+
* - /packages/core/src/hooks/useScrollRegionProps.test.tsx
|
|
14
|
+
* - /packages/core/src/AppShell/observeMainOverflow.ts
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {useCallback, useState, type AriaRole, type RefCallback} from 'react';
|
|
18
|
+
import {
|
|
19
|
+
registerEnglishFallback,
|
|
20
|
+
useComponentTranslator,
|
|
21
|
+
} from '../i18n/useComponentTranslator';
|
|
22
|
+
import english from '../i18n/generated-english/hooks/useScrollRegionProps.generated';
|
|
23
|
+
import {observeMainOverflow} from '../AppShell/observeMainOverflow';
|
|
24
|
+
|
|
25
|
+
registerEnglishFallback(english);
|
|
26
|
+
|
|
27
|
+
export interface ScrollRegionOptions {
|
|
28
|
+
/** Whether the region may scroll at all (`overflow: auto`). */
|
|
29
|
+
isScrollable: boolean;
|
|
30
|
+
/** The caller's role. It always wins, and takes no default name. */
|
|
31
|
+
role?: AriaRole;
|
|
32
|
+
/** The caller's accessible name. It always wins. */
|
|
33
|
+
label?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ScrollRegionProps {
|
|
37
|
+
ref: RefCallback<HTMLElement>;
|
|
38
|
+
role: AriaRole | undefined;
|
|
39
|
+
'aria-label': string | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The region's ref, role and accessible name. While the region may scroll
|
|
44
|
+
* and its content overflows, it is a group named by the caller's `label`, or
|
|
45
|
+
* by the translated "Content". A caller's `role` is kept with only the
|
|
46
|
+
* caller's `label`: a single main landmark relies on its role alone. When
|
|
47
|
+
* the region does not scroll, the caller's own `role` and `label` pass
|
|
48
|
+
* through unchanged.
|
|
49
|
+
*/
|
|
50
|
+
export function useScrollRegionProps({
|
|
51
|
+
isScrollable,
|
|
52
|
+
role,
|
|
53
|
+
label,
|
|
54
|
+
}: ScrollRegionOptions): ScrollRegionProps {
|
|
55
|
+
const t = useComponentTranslator();
|
|
56
|
+
const [overflows, setOverflows] = useState(false);
|
|
57
|
+
// A caller's role takes no default name, so its region is not observed.
|
|
58
|
+
const hasRole = role != null;
|
|
59
|
+
const ref = useCallback(
|
|
60
|
+
(element: HTMLElement | null) => {
|
|
61
|
+
if (element == null || !isScrollable || hasRole) {
|
|
62
|
+
setOverflows(false);
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return observeMainOverflow(element, setOverflows);
|
|
66
|
+
},
|
|
67
|
+
[hasRole, isScrollable],
|
|
68
|
+
);
|
|
69
|
+
const isGroup = !hasRole && isScrollable && overflows;
|
|
70
|
+
return {
|
|
71
|
+
ref,
|
|
72
|
+
role: role ?? (isGroup ? 'group' : undefined),
|
|
73
|
+
'aria-label':
|
|
74
|
+
label ?? (isGroup ? t('@astryx.scrollRegion.label') : undefined),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @generated by scripts/generate-i18n-runtime.mjs from packages/core/locales/en.json,
|
|
5
|
+
* holding the English for the catalog keys named in packages/core/src/hooks/useScrollRegionProps.ts.
|
|
6
|
+
* Do not edit by hand. Run `pnpm generate:i18n-runtime` instead.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const english: Readonly<Record<string, string>> = {
|
|
10
|
+
"@astryx.scrollRegion.label": "Content"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default english;
|
|
@@ -375,6 +375,7 @@ const runtimeCatalog: Readonly<Record<string, string>> = {
|
|
|
375
375
|
'@astryx.banner.expand': 'Expand',
|
|
376
376
|
'@astryx.button.loading': 'Loading',
|
|
377
377
|
'@astryx.spinner.loading': 'Loading',
|
|
378
|
+
'@astryx.scrollRegion.label': 'Content',
|
|
378
379
|
'@astryx.chatComposerDrawer.expand': 'Expand {label}',
|
|
379
380
|
'@astryx.chatComposerDrawer.collapse': 'Collapse {label}',
|
|
380
381
|
'@astryx.chatDictationButton.startDictation': 'Start dictation',
|
|
@@ -383,6 +383,7 @@ const runtimeCatalog: Readonly<Record<string, string>> = {
|
|
|
383
383
|
'@astryx.banner.expand': '⟦Éẋþàñð⟧',
|
|
384
384
|
'@astryx.button.loading': '⟦Łóàðíñĝ⟧',
|
|
385
385
|
'@astryx.spinner.loading': '⟦Łóàðíñĝ⟧',
|
|
386
|
+
'@astryx.scrollRegion.label': '⟦Çóñţéñţ⟧',
|
|
386
387
|
'@astryx.chatComposerDrawer.expand': '⟦Éẋþàñð {label}⟧',
|
|
387
388
|
'@astryx.chatComposerDrawer.collapse': '⟦Çółłàþšé {label}⟧',
|
|
388
389
|
'@astryx.chatDictationButton.startDictation': '⟦Šţàřţ ðíçţàţíóñ⟧',
|
|
@@ -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
|
+
}
|
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
* technology, carries no ids or test ids, joins no form or radio group (a
|
|
16
16
|
* copied checked radio would uncheck the live one), and its frames and media
|
|
17
17
|
* load nothing. Laying it out changes no ancestor's position, and a scaled
|
|
18
|
-
* host draws it at the old size.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* host draws it at the old size. A clone restarts each CSS animation and runs
|
|
19
|
+
* no transition but a `@starting-style` one; the copy carries on its
|
|
20
|
+
* element's from where they were.
|
|
21
|
+
* Laid in a host outside the element's own ancestors, it keeps what it
|
|
22
|
+
* inherited from them: its inherited properties and custom properties that
|
|
23
|
+
* differ from the host's are written on it.
|
|
21
24
|
* Limits: a rule keyed on a removed `id`, or matched through an ancestor
|
|
22
25
|
* between the host and the element (`.collapsed .label`), does not style the
|
|
23
26
|
* copy as it styled the element; and content holding a canvas whose pixels read back
|
|
@@ -28,6 +31,12 @@
|
|
|
28
31
|
* SYNC: When modified, update /packages/core/src/motion/animatedLayout.ts
|
|
29
32
|
*/
|
|
30
33
|
|
|
34
|
+
import {
|
|
35
|
+
carryAnimations,
|
|
36
|
+
saveAnimations,
|
|
37
|
+
type SavedAnimations,
|
|
38
|
+
} from './carryAnimations';
|
|
39
|
+
|
|
31
40
|
/** Above this many elements, old content is not copied: the new one enters. */
|
|
32
41
|
const MAX_COPIED_ELEMENTS = 1500;
|
|
33
42
|
|
|
@@ -151,11 +160,22 @@ const scrollOffsets = new WeakMap<
|
|
|
151
160
|
ReadonlyArray<readonly [Element, number, number]>
|
|
152
161
|
>();
|
|
153
162
|
|
|
163
|
+
/**
|
|
164
|
+
* The CSS animations and transitions a copy's element ran, and the copy of
|
|
165
|
+
* each element in the copied subtree. The copy carries them on once laid out
|
|
166
|
+
* (`placeOver`).
|
|
167
|
+
*/
|
|
168
|
+
const carriedMotion = new WeakMap<
|
|
169
|
+
HTMLElement,
|
|
170
|
+
{saved: SavedAnimations; copyOf: ReadonlyMap<Element, Element>}
|
|
171
|
+
>();
|
|
172
|
+
|
|
154
173
|
/**
|
|
155
174
|
* A copy that takes no part: no ids or test ids, no form or radio group (a
|
|
156
175
|
* copied checked radio would uncheck the live one), no label for a live
|
|
157
176
|
* control, and copied frames and media load nothing. Scrolled descendants
|
|
158
|
-
* keep their offsets
|
|
177
|
+
* keep their offsets. The CSS animations and transitions running in it carry
|
|
178
|
+
* on from where they were, once the copy is laid out (`placeOver`).
|
|
159
179
|
*/
|
|
160
180
|
export function inertCopy(element: HTMLElement): HTMLElement | null {
|
|
161
181
|
const copy = element.cloneNode(true) as HTMLElement;
|
|
@@ -169,6 +189,10 @@ export function inertCopy(element: HTMLElement): HTMLElement | null {
|
|
|
169
189
|
});
|
|
170
190
|
scrollOffsets.set(copy, offsets);
|
|
171
191
|
inheritedValues.set(copy, readInherited(element));
|
|
192
|
+
carriedMotion.set(copy, {
|
|
193
|
+
saved: saveAnimations(element),
|
|
194
|
+
copyOf: new Map(sourceNodes.map((node, index) => [node, copyNodes[index]])),
|
|
195
|
+
});
|
|
172
196
|
for (const node of copyNodes) {
|
|
173
197
|
for (const name of [
|
|
174
198
|
'id',
|
|
@@ -215,7 +239,8 @@ export function paintedBackground(element: Element): string {
|
|
|
215
239
|
/**
|
|
216
240
|
* Lay `element` over `rect` (viewport coordinates), absolutely, as the last
|
|
217
241
|
* child of `host`, wherever its containing block is: no ancestor's position
|
|
218
|
-
* changes.
|
|
242
|
+
* changes. A copy's scrolled descendants then restore their offsets, and the
|
|
243
|
+
* CSS animations and transitions its element ran carry on in it.
|
|
219
244
|
*/
|
|
220
245
|
export function placeOver(
|
|
221
246
|
element: HTMLElement,
|
|
@@ -277,6 +302,15 @@ export function placeOver(
|
|
|
277
302
|
node.scrollLeft = left;
|
|
278
303
|
}
|
|
279
304
|
}
|
|
305
|
+
const carried = carriedMotion.get(element);
|
|
306
|
+
if (carried != null) {
|
|
307
|
+
carriedMotion.delete(element);
|
|
308
|
+
carryAnimations(
|
|
309
|
+
carried.saved,
|
|
310
|
+
element,
|
|
311
|
+
node => carried.copyOf.get(node) ?? null,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
280
314
|
}
|
|
281
315
|
|
|
282
316
|
/**
|
|
@@ -323,6 +357,12 @@ export function visiblePartCopy(element: HTMLElement): {
|
|
|
323
357
|
if (values != null) {
|
|
324
358
|
inheritedValues.set(holder, values);
|
|
325
359
|
}
|
|
360
|
+
// The content's CSS motion carries on when the holder is laid out.
|
|
361
|
+
const carried = carriedMotion.get(content);
|
|
362
|
+
if (carried != null) {
|
|
363
|
+
carriedMotion.set(holder, carried);
|
|
364
|
+
carriedMotion.delete(content);
|
|
365
|
+
}
|
|
326
366
|
const box = element.getBoundingClientRect();
|
|
327
367
|
return {
|
|
328
368
|
copy: holder,
|