@astryxdesign/core 0.7.7-canary.bf14580 → 0.7.7-canary.c19ca12
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/AlertDialog/AlertDialog.d.ts +4 -1
- package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/dist/AlertDialog/AlertDialog.js +36 -6
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +76 -6
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +23 -4
- package/dist/BottomSheet/bottomSheetStack.d.ts.map +1 -1
- package/dist/BottomSheet/bottomSheetStack.js +5 -4
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +3 -1
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +47 -3
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +13 -2
- package/dist/ComplexSelector/ComplexSelector.d.ts +4 -1
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +14 -4
- package/dist/ContextMenu/ContextMenu.js +2 -2
- package/dist/DateInput/MonthScroller.d.ts.map +1 -1
- package/dist/DateInput/MonthScroller.js +13 -27
- package/dist/DateInput/Wheel.d.ts.map +1 -1
- package/dist/DateInput/Wheel.js +22 -41
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +7 -31
- package/dist/Field/Field.js +2 -2
- package/dist/HoverCard/HoverCard.d.ts +4 -3
- package/dist/HoverCard/HoverCard.d.ts.map +1 -1
- package/dist/HoverCard/HoverCard.js +27 -2
- package/dist/HoverCard/useHoverCard.d.ts +5 -4
- package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
- package/dist/HoverCard/useHoverCard.js +17 -31
- package/dist/Icon/Icon.d.ts +5 -1
- package/dist/Icon/Icon.d.ts.map +1 -1
- package/dist/Icon/Icon.js +5 -2
- package/dist/Layer/layerAnimations.stylex.d.ts +7 -8
- package/dist/Layer/layerAnimations.stylex.d.ts.map +1 -1
- package/dist/Layer/layerAnimations.stylex.js +25 -20
- package/dist/Layer/usePressPin.d.ts +17 -5
- package/dist/Layer/usePressPin.d.ts.map +1 -1
- package/dist/Layer/usePressPin.js +62 -12
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +18 -0
- package/dist/PowerSearch/PowerSearch.d.ts +36 -3
- package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearch.js +522 -269
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +100 -0
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -0
- package/dist/PowerSearch/PowerSearchBottomSheet.js +1913 -0
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts +32 -1
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchEditPopover.js +17 -6
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts +38 -3
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchValueEditor.js +170 -61
- package/dist/PowerSearch/formatFilterValue.d.ts +7 -0
- package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
- package/dist/PowerSearch/formatFilterValue.js +11 -1
- package/dist/PowerSearch/formatTokenValue.d.ts +28 -0
- package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -0
- package/dist/PowerSearch/formatTokenValue.js +160 -0
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts +65 -0
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts.map +1 -0
- package/dist/PowerSearch/powerSearchSheetUtils.js +168 -0
- package/dist/RadioList/RadioList.d.ts.map +1 -1
- package/dist/RadioList/RadioList.js +3 -2
- package/dist/RadioList/RadioListItem.d.ts +1 -1
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +5 -3
- package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
- package/dist/SegmentedControl/useSegmentedSelectionMotion.js +3 -3
- package/dist/Slider/sliderTouchController.js +2 -2
- package/dist/Spinner/Spinner.d.ts +1 -1
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +60 -58
- package/dist/Switch/useSwitchTouch.js +4 -4
- package/dist/Table/BaseTable.d.ts.map +1 -1
- package/dist/Table/BaseTable.js +29 -8
- package/dist/TextInput/TextInput.d.ts +2 -2
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +10 -7
- package/dist/Toast/Toast.d.ts +11 -1
- package/dist/Toast/Toast.d.ts.map +1 -1
- package/dist/Toast/Toast.js +25 -15
- package/dist/Toast/ToastViewport.d.ts.map +1 -1
- package/dist/Toast/ToastViewport.js +94 -34
- package/dist/Toast/types.d.ts +9 -3
- package/dist/Toast/types.d.ts.map +1 -1
- package/dist/Token/Token.d.ts +2 -2
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +12 -4
- package/dist/Token/TokenNamingContext.d.ts +14 -0
- package/dist/Token/TokenNamingContext.d.ts.map +1 -0
- package/dist/Token/TokenNamingContext.js +23 -0
- package/dist/Tooltip/useTooltip.d.ts +19 -1
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +34 -53
- package/dist/Typeahead/TypeaheadItem.d.ts +2 -1
- package/dist/Typeahead/TypeaheadItem.d.ts.map +1 -1
- package/dist/animator/createAnimator.d.ts +98 -0
- package/dist/animator/createAnimator.d.ts.map +1 -0
- package/dist/animator/createAnimator.js +259 -0
- package/dist/astryx.css +22 -6
- package/dist/gestures/GestureHost.d.ts +27 -1
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +90 -8
- package/dist/gestures/PressTracker.d.ts.map +1 -1
- package/dist/gestures/PressTracker.js +4 -3
- package/dist/hooks/actionGroupTracker.d.ts +4 -1
- package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
- package/dist/hooks/actionGroupTracker.js +13 -3
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/pressGroupContext.d.ts +6 -0
- package/dist/hooks/pressGroupContext.d.ts.map +1 -0
- package/dist/hooks/pressGroupContext.js +20 -0
- package/dist/hooks/useActionGroupTracking.d.ts +53 -0
- package/dist/hooks/useActionGroupTracking.d.ts.map +1 -0
- package/dist/hooks/useActionGroupTracking.js +174 -0
- package/dist/hooks/useAnimator.d.ts +41 -0
- package/dist/hooks/useAnimator.d.ts.map +1 -0
- package/dist/hooks/useAnimator.js +70 -0
- package/dist/hooks/useAttachment.d.ts +1 -1
- package/dist/hooks/useAttachment.js +1 -1
- package/dist/hooks/useInputStatusIcon.d.ts +1 -1
- package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
- package/dist/hooks/useInputStatusIcon.js +2 -2
- package/dist/hooks/useLongPress.d.ts +6 -2
- package/dist/hooks/useLongPress.d.ts.map +1 -1
- package/dist/hooks/useLongPress.js +95 -15
- package/dist/hooks/useMenuPress.d.ts.map +1 -1
- package/dist/hooks/useMenuPress.js +4 -2
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts +8 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +42 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +6 -0
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts +8 -0
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.js +14 -0
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +30 -0
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +30 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/internal/indicatorPress.stylex.d.ts +20 -0
- package/dist/internal/indicatorPress.stylex.d.ts.map +1 -0
- package/dist/internal/indicatorPress.stylex.js +26 -0
- package/dist/motion/animator.d.ts +14 -14
- package/dist/motion/animator.d.ts.map +1 -1
- package/dist/motion/animator.js +41 -18
- package/dist/motion/reducedMotion.d.ts +24 -0
- package/dist/motion/reducedMotion.d.ts.map +1 -1
- package/dist/motion/reducedMotion.js +78 -1
- package/dist/motion/uikit/alert.d.ts +41 -0
- package/dist/motion/uikit/alert.d.ts.map +1 -0
- package/dist/motion/uikit/alert.js +43 -0
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts +15 -0
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/pressGroupItem.stylex.js +23 -0
- package/dist/utils/clickGuard.d.ts +8 -1
- package/dist/utils/clickGuard.d.ts.map +1 -1
- package/dist/utils/clickGuard.js +24 -1
- package/dist/utils/dateParser.d.ts.map +1 -1
- package/dist/utils/dateParser.js +12 -0
- package/dist/utils/focusReturn.d.ts +15 -0
- package/dist/utils/focusReturn.d.ts.map +1 -1
- package/dist/utils/focusReturn.js +28 -0
- package/dist/utils/interactionOverlay.stylex.d.ts +3 -2
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +3 -2
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +19 -6
- package/dist/utils/triggerFocus.d.ts +36 -0
- package/dist/utils/triggerFocus.d.ts.map +1 -0
- package/dist/utils/triggerFocus.js +65 -0
- package/locales/en.json +120 -0
- package/locales/pseudo.json +90 -0
- package/package.json +9 -4
- package/src/AlertDialog/AlertDialog.doc.mjs +2 -2
- package/src/AlertDialog/AlertDialog.tsx +37 -5
- package/src/BottomSheet/BottomSheet.tsx +85 -5
- package/src/BottomSheet/BottomSheetPanel.tsx +40 -5
- package/src/BottomSheet/bottomSheetStack.ts +8 -4
- package/src/BottomSheet/useSheetGestures.ts +3 -1
- package/src/Button/Button.tsx +63 -5
- package/src/CheckboxInput/CheckboxInput.doc.mjs +18 -0
- package/src/CheckboxInput/CheckboxInput.tsx +36 -9
- package/src/ComplexSelector/ComplexSelector.tsx +20 -5
- package/src/ContextMenu/ContextMenu.tsx +2 -2
- package/src/DateInput/MonthScroller.tsx +18 -22
- package/src/DateInput/Wheel.tsx +30 -32
- package/src/Dialog/Dialog.tsx +10 -31
- package/src/Field/Field.tsx +2 -2
- package/src/HoverCard/HoverCard.doc.mjs +4 -2
- package/src/HoverCard/HoverCard.tsx +35 -4
- package/src/HoverCard/useHoverCard.doc.mjs +178 -36
- package/src/HoverCard/useHoverCard.tsx +46 -52
- package/src/Icon/Icon.doc.mjs +49 -8
- package/src/Icon/Icon.tsx +15 -7
- package/src/Layer/layerAnimations.stylex.ts +24 -16
- package/src/Layer/usePressPin.ts +81 -15
- package/src/Lightbox/Lightbox.tsx +18 -0
- package/src/PowerSearch/PowerSearch.doc.mjs +54 -5
- package/src/PowerSearch/PowerSearch.tsx +734 -288
- package/src/PowerSearch/PowerSearchBottomSheet.tsx +2515 -0
- package/src/PowerSearch/PowerSearchEditPopover.tsx +28 -6
- package/src/PowerSearch/PowerSearchValueEditor.tsx +203 -38
- package/src/PowerSearch/formatFilterValue.ts +18 -1
- package/src/PowerSearch/formatTokenValue.ts +215 -0
- package/src/PowerSearch/powerSearchSheetUtils.ts +224 -0
- package/src/RadioList/RadioList.tsx +3 -2
- package/src/RadioList/RadioListItem.tsx +5 -3
- package/src/SegmentedControl/useSegmentedSelectionMotion.ts +6 -3
- package/src/Slider/sliderTouchController.ts +2 -2
- package/src/Spinner/Spinner.tsx +77 -63
- package/src/Switch/useSwitchTouch.ts +4 -4
- package/src/Table/BaseTable.tsx +46 -12
- package/src/TextInput/TextInput.tsx +11 -10
- package/src/Toast/Toast.doc.mjs +4 -3
- package/src/Toast/Toast.tsx +52 -32
- package/src/Toast/ToastViewport.tsx +121 -35
- package/src/Toast/types.ts +9 -3
- package/src/Token/Token.tsx +13 -4
- package/src/Token/TokenNamingContext.ts +28 -0
- package/src/Tooltip/useTooltip.doc.mjs +24 -0
- package/src/Tooltip/useTooltip.tsx +61 -56
- package/src/Typeahead/TypeaheadItem.doc.mjs +6 -3
- package/src/Typeahead/TypeaheadItem.tsx +2 -1
- package/src/animator/createAnimator.doc.mjs +153 -0
- package/src/animator/createAnimator.ts +324 -0
- package/src/gestures/GestureHost.ts +105 -10
- package/src/gestures/PressTracker.ts +4 -3
- package/src/gestures/README.md +7 -1
- package/src/hooks/actionGroupTracker.ts +20 -5
- package/src/hooks/index.ts +2 -0
- package/src/hooks/pressGroupContext.ts +21 -0
- package/src/hooks/useActionGroupTracking.ts +224 -0
- package/src/hooks/useAnimator.doc.mjs +109 -0
- package/src/hooks/useAnimator.ts +67 -0
- package/src/hooks/useAttachment.ts +1 -1
- package/src/hooks/useInputStatusIcon.tsx +3 -2
- package/src/hooks/useLongPress.doc.mjs +2 -2
- package/src/hooks/useLongPress.ts +136 -15
- package/src/hooks/useMenuPress.ts +8 -2
- package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +43 -0
- package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +6 -0
- package/src/i18n/generated-english/PowerSearch/formatTokenValue.generated.ts +15 -0
- package/src/i18n/generated-locales/en.generated.ts +41 -0
- package/src/i18n/generated-locales/pseudo.generated.ts +42 -0
- package/src/index.ts +13 -0
- package/src/internal/indicatorPress.stylex.ts +24 -0
- package/src/motion/README.md +8 -5
- package/src/motion/animator.ts +61 -29
- package/src/motion/reducedMotion.ts +79 -1
- package/src/motion/uikit/alert.ts +43 -0
- package/src/privateAttributes/pressGroupItem.stylex.ts +23 -0
- package/src/utils/clickGuard.ts +37 -1
- package/src/utils/dateParser.ts +16 -0
- package/src/utils/focusReturn.ts +30 -0
- package/src/utils/interactionOverlay.stylex.ts +3 -2
- package/src/utils/pressFeedback.ts +19 -6
- package/src/utils/triggerFocus.ts +80 -0
|
@@ -43,7 +43,8 @@ export const docs = {
|
|
|
43
43
|
{
|
|
44
44
|
name: 'group',
|
|
45
45
|
type: 'string',
|
|
46
|
-
description:
|
|
46
|
+
description:
|
|
47
|
+
'This prop has no effect. Set `item.auxiliaryData.group` on search-source items to group results in Typeahead or BaseTypeahead.',
|
|
47
48
|
},
|
|
48
49
|
],
|
|
49
50
|
};
|
|
@@ -79,7 +80,8 @@ export const docsZh = {
|
|
|
79
80
|
{
|
|
80
81
|
name: 'group',
|
|
81
82
|
type: 'string',
|
|
82
|
-
description:
|
|
83
|
+
description:
|
|
84
|
+
'此属性不影响渲染。要在 Typeahead 或 BaseTypeahead 中分组,请在搜索源返回的结果项上设置 `item.auxiliaryData.group`。',
|
|
83
85
|
},
|
|
84
86
|
],
|
|
85
87
|
};
|
|
@@ -94,6 +96,7 @@ export const docsDense = {
|
|
|
94
96
|
icon: 'Icon/avatar before label.',
|
|
95
97
|
description: 'Text below label.',
|
|
96
98
|
isDisabled: 'Visually disabled.',
|
|
97
|
-
group:
|
|
99
|
+
group:
|
|
100
|
+
'No effect. Group results via `item.auxiliaryData.group` in the search source.',
|
|
98
101
|
},
|
|
99
102
|
};
|
|
@@ -54,7 +54,8 @@ export interface TypeaheadItemProps<
|
|
|
54
54
|
isDisabled?: boolean;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* This prop has no effect. Set `item.auxiliaryData.group` on search-source
|
|
58
|
+
* items to group results in Typeahead or BaseTypeahead.
|
|
58
59
|
*/
|
|
59
60
|
group?: string;
|
|
60
61
|
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').HookDoc} */
|
|
4
|
+
export const docs = {
|
|
5
|
+
name: 'createAnimator',
|
|
6
|
+
displayName: 'createAnimator',
|
|
7
|
+
// A factory documented as a hook: listed with the utilities, beside its
|
|
8
|
+
// hook, not as a tile in the components gallery.
|
|
9
|
+
group: 'Utilities',
|
|
10
|
+
keywords: [
|
|
11
|
+
'animate',
|
|
12
|
+
'animation',
|
|
13
|
+
'animator',
|
|
14
|
+
'spring',
|
|
15
|
+
'decay',
|
|
16
|
+
'momentum',
|
|
17
|
+
'fling',
|
|
18
|
+
'motion',
|
|
19
|
+
'transform',
|
|
20
|
+
'opacity',
|
|
21
|
+
'vanilla',
|
|
22
|
+
'factory',
|
|
23
|
+
],
|
|
24
|
+
params: [
|
|
25
|
+
{
|
|
26
|
+
name: 'element',
|
|
27
|
+
type: 'HTMLElement',
|
|
28
|
+
description:
|
|
29
|
+
'The element to animate. The animator writes its `translate`, `scale`, `rotate` and `opacity`, and while it moves an inline `will-change` for them, merged with any it already has and restored 500 ms after its last motion; nothing else, so lay it out and style it as usual. Use one animator per element: two on one element overwrite each other.',
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
returns: [
|
|
34
|
+
{
|
|
35
|
+
name: 'animate',
|
|
36
|
+
type: '(target: {x?, y?, scale?, rotate?, opacity?}, options?: {velocity?}) => Promise<void>',
|
|
37
|
+
description:
|
|
38
|
+
"Springs the given channels to `target` from wherever they are on screen, on the state-change motion Astryx's components use, and resolves when they arrive (or as soon as a later call takes them over). `x` and `y` are px, `scale` is 1 at the element's size, `rotate` is degrees and `opacity` runs from 0 to 1. Pass `velocity` (units per second, such as a drag's release velocity) to start with it; without it a channel keeps the velocity it has on screen, so interrupting a motion never jumps.",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'decay',
|
|
42
|
+
type: '(velocity: {x?, y?, scale?, rotate?, opacity?}) => Promise<void>',
|
|
43
|
+
description:
|
|
44
|
+
"Coasts the given channels from a release velocity in their units per second, slowing as a scroll view's momentum does, and resolves when they stop (or as soon as a later call takes any of them over); opacity stops at 0 or 1. The distance follows from the velocity: use it to fling something away, then remove or reset it.",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'set',
|
|
48
|
+
type: '(values: {x?, y?, scale?, rotate?, opacity?}) => void',
|
|
49
|
+
description:
|
|
50
|
+
'Puts the given channels at these values at once, ending their motion: follow a finger with it, frame by frame.',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'get',
|
|
54
|
+
type: '() => {x, y, scale, rotate, opacity}',
|
|
55
|
+
description: "Every channel's value on screen now.",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'getVelocity',
|
|
59
|
+
type: '() => {x, y, scale, rotate, opacity}',
|
|
60
|
+
description:
|
|
61
|
+
"Every channel's velocity on screen now, in units per second.",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'stop',
|
|
65
|
+
type: '() => void',
|
|
66
|
+
description: 'Halts every channel where it is on screen.',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'destroy',
|
|
70
|
+
type: '() => void',
|
|
71
|
+
description:
|
|
72
|
+
'Stops every motion and lets the element go; the element keeps the values it shows. Call it when you remove the element or no longer animate it.',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
usage: {
|
|
76
|
+
description:
|
|
77
|
+
"Animates one element with the motion Astryx's own components use, without React. `animate` springs an element to new values on the state-change motion, `decay` flings it with the momentum of a released scroll view, and `set` moves it directly, so a card can follow a finger, snap back and be thrown away. Use the `useAnimator` hook in React. To animate an area's layout as its items change, use `useAnimatedLayout`; for what a component already animates, such as a sheet's detents or a carousel's snapping, use the component's own props.",
|
|
78
|
+
bestPractices: [
|
|
79
|
+
{
|
|
80
|
+
guidance: true,
|
|
81
|
+
description:
|
|
82
|
+
'Start every `animate` that follows a drag with the release velocity, so the element carries on as it was thrown.',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
guidance: true,
|
|
86
|
+
description:
|
|
87
|
+
'Reach every state an animation shows without the animation too: a key, a button or a menu item that calls the same code.',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
guidance: true,
|
|
91
|
+
description:
|
|
92
|
+
'`await` the promise before removing an element you animate out, and call `destroy` once it is gone.',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
guidance: false,
|
|
96
|
+
description:
|
|
97
|
+
'Read the element\u2019s position from layout while it moves: `get` gives the value on screen, wherever the motion runs.',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
accessibility: [
|
|
101
|
+
{
|
|
102
|
+
name: 'Keyboard and assistive technology',
|
|
103
|
+
category: 'Keyboard',
|
|
104
|
+
description:
|
|
105
|
+
'An animator moves an element; it adds no way to act. Give every action an animation stands for a control a keyboard and a screen reader can reach, such as a button that discards a card, and have it call `animate`, which Reduce Motion turns into a fade in place. Keep `decay` for a throw the person made: Reduce Motion keeps the momentum of a coast, as it continues that throw. Keep focus on an element that stays on screen: move it before you fling its element away.',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'Reduce Motion',
|
|
109
|
+
category: 'Content',
|
|
110
|
+
criterion: '2.3.3 Animation from Interactions',
|
|
111
|
+
description:
|
|
112
|
+
'When the person asks for reduced motion, every call is planned for them. On a touch screen a move or a scale becomes a short opacity cross-fade: the element fades out where it was and fades back in where it lands. With a mouse it lands at once. A decay of `x` and `y` keeps its momentum, as it continues the throw the person made; a decay of `scale`, `rotate` or `opacity` is planned like a move. No option turns this off.',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
relatedHooks: ['useAnimator', 'useAnimatedLayout'],
|
|
117
|
+
importPath: '@astryxdesign/core',
|
|
118
|
+
category: 'interaction',
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
|
|
122
|
+
export const docsDense = {
|
|
123
|
+
description:
|
|
124
|
+
"Animates one element (x, y, scale, rotate, opacity) with Astryx's motion, without React.",
|
|
125
|
+
paramDescriptions: {
|
|
126
|
+
element: 'The element to animate; one animator per element.',
|
|
127
|
+
},
|
|
128
|
+
returnDescriptions: {
|
|
129
|
+
animate:
|
|
130
|
+
'(target, {velocity?}) => Promise<void>; springs on the state-change motion.',
|
|
131
|
+
decay:
|
|
132
|
+
'({x?, y?, scale?, rotate?, opacity?}) => Promise<void>; coasts from a release velocity.',
|
|
133
|
+
set: '(values) => void; jumps, ending motion.',
|
|
134
|
+
get: '() => every value on screen.',
|
|
135
|
+
getVelocity: '() => every velocity on screen.',
|
|
136
|
+
stop: '() => void; halts where it is.',
|
|
137
|
+
destroy: '() => void; lets the element go.',
|
|
138
|
+
},
|
|
139
|
+
usage: {
|
|
140
|
+
description:
|
|
141
|
+
'Spring with animate, fling with decay, follow a finger with set. Reduce Motion: a cross-fade on touch, at once with a mouse; decay keeps its momentum.',
|
|
142
|
+
bestPractices: [
|
|
143
|
+
{
|
|
144
|
+
guidance: true,
|
|
145
|
+
description: 'Pass the release velocity to animate after a drag.',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
guidance: false,
|
|
149
|
+
description: 'Read layout for the position mid-motion; use get.',
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
};
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file createAnimator.ts
|
|
7
|
+
* @input An element; the internal motion animator (motion/animator.ts), the
|
|
8
|
+
* `springs.stateChange` motion role and the momentum coast (motion/coast.ts)
|
|
9
|
+
* @output The public animator: `createAnimator`, the `AnimatorHandle` it
|
|
10
|
+
* returns, and their value types
|
|
11
|
+
* @position Public entry point, re-exported from the package root. The
|
|
12
|
+
* `useAnimator` hook wraps it. Importing it does no DOM work.
|
|
13
|
+
*
|
|
14
|
+
* SYNC: When modified, update:
|
|
15
|
+
* - /packages/core/src/animator/createAnimator.test.ts
|
|
16
|
+
* - /packages/core/src/animator/createAnimator.doc.mjs
|
|
17
|
+
* - /packages/core/src/hooks/useAnimator.ts
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
createMotionAnimator,
|
|
22
|
+
SETTLE_THRESHOLD,
|
|
23
|
+
type Animator as MotionAnimator,
|
|
24
|
+
type MotionCurve,
|
|
25
|
+
type MotionProperty,
|
|
26
|
+
type MotionValues,
|
|
27
|
+
} from '../motion/animator';
|
|
28
|
+
import {coast} from '../motion/coast';
|
|
29
|
+
import {solveDecay} from '../motion/decay';
|
|
30
|
+
import {registerSpringsTable, springs} from '../motion/uikit/springs';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A channel the animator drives. `x` and `y` translate the element (px).
|
|
34
|
+
* `scale` scales it about its transform origin (1 is its size). `rotate`
|
|
35
|
+
* turns it (degrees, clockwise), and `opacity` fades it (0 to 1).
|
|
36
|
+
*/
|
|
37
|
+
export type AnimatorChannel = 'x' | 'y' | 'scale' | 'rotate' | 'opacity';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Values by channel. A velocity uses the same keys, in units per second:
|
|
41
|
+
* px/s, scale per second, deg/s, opacity per second.
|
|
42
|
+
*/
|
|
43
|
+
export type AnimatorValues = Partial<Record<AnimatorChannel, number>>;
|
|
44
|
+
|
|
45
|
+
/** Every channel's value (or velocity), as `get` and `getVelocity` read it. */
|
|
46
|
+
export type AnimatorSnapshot = Readonly<Record<AnimatorChannel, number>>;
|
|
47
|
+
|
|
48
|
+
/** Options of `AnimatorHandle.animate`. */
|
|
49
|
+
export interface AnimatorAnimateOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Each channel's velocity at the start, such as a drag's release velocity.
|
|
52
|
+
* A channel without one keeps the
|
|
53
|
+
* velocity it has on screen, so an `animate` that interrupts another
|
|
54
|
+
* carries on smoothly.
|
|
55
|
+
*/
|
|
56
|
+
velocity?: AnimatorValues;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A release velocity for `AnimatorHandle.decay`, per channel, in its units
|
|
61
|
+
* per second. That is px/s for `x` and `y`, and degrees per second for
|
|
62
|
+
* `rotate`. `scale` and `opacity` take their units per second.
|
|
63
|
+
*/
|
|
64
|
+
export type AnimatorDecayVelocity = AnimatorValues;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Animates one element. Each method acts on the channels it is given and
|
|
68
|
+
* leaves the others where they are.
|
|
69
|
+
*/
|
|
70
|
+
export interface AnimatorHandle {
|
|
71
|
+
/**
|
|
72
|
+
* Springs the given channels to `target` on the `springs.stateChange`
|
|
73
|
+
* motion role, from wherever they are on screen. The promise resolves when
|
|
74
|
+
* they arrive, or as soon as a later `animate`, `decay`, `set` or `stop`
|
|
75
|
+
* takes any of them over.
|
|
76
|
+
*/
|
|
77
|
+
animate(
|
|
78
|
+
target: AnimatorValues,
|
|
79
|
+
options?: AnimatorAnimateOptions,
|
|
80
|
+
): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Coasts the given channels from a release velocity, slowing as a scroll
|
|
83
|
+
* view's momentum does. It resolves when they stop, or when another call
|
|
84
|
+
* takes them over. The distance follows from the velocity alone: there are
|
|
85
|
+
* no bounds, except that opacity stops at 0 or 1.
|
|
86
|
+
*/
|
|
87
|
+
decay(velocity: AnimatorDecayVelocity): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Puts the given channels at these values at once, ending their motion:
|
|
90
|
+
* the per-frame write of a drag.
|
|
91
|
+
*/
|
|
92
|
+
set(values: AnimatorValues): void;
|
|
93
|
+
/** Every channel's value on screen now. */
|
|
94
|
+
get(): AnimatorSnapshot;
|
|
95
|
+
/** Every channel's velocity on screen now, in units per second. */
|
|
96
|
+
getVelocity(): AnimatorSnapshot;
|
|
97
|
+
/** Halts every channel where it is on screen. */
|
|
98
|
+
stop(): void;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What `createAnimator` returns: the handle, and `destroy`. */
|
|
102
|
+
export interface Animator extends AnimatorHandle {
|
|
103
|
+
/**
|
|
104
|
+
* Stops every motion and lets go of the element; the element keeps the
|
|
105
|
+
* values it shows. The animator does nothing after this.
|
|
106
|
+
*/
|
|
107
|
+
destroy(): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const CHANNELS: ReadonlyArray<AnimatorChannel> = [
|
|
111
|
+
'x',
|
|
112
|
+
'y',
|
|
113
|
+
'scale',
|
|
114
|
+
'rotate',
|
|
115
|
+
'opacity',
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
/** The values of the channels the public API names, and nothing else. */
|
|
119
|
+
function motionValues(values: AnimatorValues | undefined): MotionValues {
|
|
120
|
+
const out: MotionValues = {};
|
|
121
|
+
if (values == null) {
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
for (const channel of CHANNELS) {
|
|
125
|
+
const value = values[channel];
|
|
126
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
127
|
+
out[channel] = value;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A coast from `from` at `velocity` on the momentum decay a scroll view
|
|
135
|
+
* uses, ending at rest. The theme does not change this decay. An opacity
|
|
136
|
+
* coast stops at 0 or 1.
|
|
137
|
+
*/
|
|
138
|
+
function momentum(
|
|
139
|
+
from: number,
|
|
140
|
+
velocity: number,
|
|
141
|
+
threshold: number,
|
|
142
|
+
isUnit: boolean,
|
|
143
|
+
): MotionCurve {
|
|
144
|
+
const glide = solveDecay({from, velocity});
|
|
145
|
+
const edge = !isUnit ? null : glide.rest < 0 ? 0 : glide.rest > 1 ? 1 : null;
|
|
146
|
+
const hit = edge == null ? null : glide.timeToReach(edge);
|
|
147
|
+
const duration = hit ?? glide.settleTime(threshold);
|
|
148
|
+
const end = edge ?? glide.rest;
|
|
149
|
+
return {
|
|
150
|
+
duration,
|
|
151
|
+
at: t => (t >= duration ? end : glide.value(t)),
|
|
152
|
+
velocity: t => (t >= duration ? 0 : glide.velocity(t)),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function snapshot(
|
|
157
|
+
read: (channel: AnimatorChannel) => number,
|
|
158
|
+
): AnimatorSnapshot {
|
|
159
|
+
return {
|
|
160
|
+
x: read('x'),
|
|
161
|
+
y: read('y'),
|
|
162
|
+
scale: read('scale'),
|
|
163
|
+
rotate: read('rotate'),
|
|
164
|
+
opacity: read('opacity'),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Resolves once every motion of one call has finished, or as soon as any of
|
|
170
|
+
* them is interrupted (`finished` resolves `false`). A later call that takes
|
|
171
|
+
* over one channel ends the whole call where it stopped, as one `animate`
|
|
172
|
+
* does. The other channels move on.
|
|
173
|
+
*/
|
|
174
|
+
async function settledOrTakenOver(
|
|
175
|
+
moving: ReadonlyArray<Promise<boolean>>,
|
|
176
|
+
): Promise<void> {
|
|
177
|
+
if (moving.length === 0) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
await new Promise<void>(resolve => {
|
|
181
|
+
let left = moving.length;
|
|
182
|
+
for (const finished of moving) {
|
|
183
|
+
void finished.then(completed => {
|
|
184
|
+
left -= 1;
|
|
185
|
+
if (!completed || left === 0) {
|
|
186
|
+
resolve();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* An animator whose element is attached later, through `attach`. It is the
|
|
195
|
+
* one construction `createAnimator` and `useAnimator` share, so the hook has
|
|
196
|
+
* no behavior of its own. Not exported from the package.
|
|
197
|
+
*/
|
|
198
|
+
export function createAttachableAnimator(): {
|
|
199
|
+
readonly animator: Animator;
|
|
200
|
+
readonly attach: (element: HTMLElement | null) => void;
|
|
201
|
+
} {
|
|
202
|
+
const motion: MotionAnimator = createMotionAnimator(null);
|
|
203
|
+
// Calls do nothing while no element is attached, before the ref attaches
|
|
204
|
+
// or after it lets go. They also do nothing after destroy, and animate and
|
|
205
|
+
// decay then resolve at once.
|
|
206
|
+
let element: HTMLElement | null = null;
|
|
207
|
+
let destroyed = false;
|
|
208
|
+
const inactive = () => destroyed || element == null;
|
|
209
|
+
const animator: Animator = {
|
|
210
|
+
async animate(target, options) {
|
|
211
|
+
const to = motionValues(target);
|
|
212
|
+
if (inactive() || Object.keys(to).length === 0) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// The role registry is written on first use, never on import.
|
|
216
|
+
registerSpringsTable();
|
|
217
|
+
const velocity = motionValues(options?.velocity);
|
|
218
|
+
await motion.animate(to, {
|
|
219
|
+
spring: springs.stateChange,
|
|
220
|
+
...(Object.keys(velocity).length > 0 ? {velocity} : {}),
|
|
221
|
+
}).finished;
|
|
222
|
+
},
|
|
223
|
+
async decay(velocity) {
|
|
224
|
+
if (inactive()) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const given = motionValues(velocity);
|
|
228
|
+
// The translate axes coast as a throw, which Reduce Motion lets
|
|
229
|
+
// continue. The others coast as a transition, which it replaces.
|
|
230
|
+
const translate = coast(motion, {x: given.x, y: given.y});
|
|
231
|
+
const others: Partial<Record<MotionProperty | 'scale', MotionCurve>> = {};
|
|
232
|
+
for (const channel of ['scale', 'rotate', 'opacity'] as const) {
|
|
233
|
+
const v0 = given[channel];
|
|
234
|
+
if (v0 != null) {
|
|
235
|
+
const property = channel === 'scale' ? 'scaleX' : channel;
|
|
236
|
+
others[channel] = momentum(
|
|
237
|
+
motion.get(property),
|
|
238
|
+
v0,
|
|
239
|
+
SETTLE_THRESHOLD[property],
|
|
240
|
+
channel === 'opacity',
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const moving: Promise<boolean>[] = [];
|
|
245
|
+
if (Object.keys(translate).length > 0) {
|
|
246
|
+
moving.push(motion.decay(translate).finished);
|
|
247
|
+
}
|
|
248
|
+
if (Object.keys(others).length > 0) {
|
|
249
|
+
moving.push(motion.play(others).finished);
|
|
250
|
+
}
|
|
251
|
+
await settledOrTakenOver(moving);
|
|
252
|
+
},
|
|
253
|
+
set(values) {
|
|
254
|
+
if (!inactive()) {
|
|
255
|
+
motion.set(motionValues(values));
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
get() {
|
|
259
|
+
return snapshot(channel => motion.get(channel));
|
|
260
|
+
},
|
|
261
|
+
getVelocity() {
|
|
262
|
+
return snapshot(channel => motion.getVelocity(channel));
|
|
263
|
+
},
|
|
264
|
+
stop() {
|
|
265
|
+
if (!inactive()) {
|
|
266
|
+
motion.stop();
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
destroy() {
|
|
270
|
+
if (!destroyed) {
|
|
271
|
+
destroyed = true;
|
|
272
|
+
// Halts every channel where it shows, so the element keeps those
|
|
273
|
+
// values and nothing reads as moving, then lets go of it.
|
|
274
|
+
motion.stop();
|
|
275
|
+
motion.dispose();
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
return {
|
|
280
|
+
animator,
|
|
281
|
+
attach: next => {
|
|
282
|
+
if (destroyed || next === element) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (element != null) {
|
|
286
|
+
// The old node takes its values with it, so the next node, or a
|
|
287
|
+
// remount, starts at rest.
|
|
288
|
+
motion.attach(null);
|
|
289
|
+
motion.stop();
|
|
290
|
+
motion.set(motionValues(REST));
|
|
291
|
+
}
|
|
292
|
+
element = next;
|
|
293
|
+
motion.attach(next);
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** A new or remounted element starts from these values. */
|
|
299
|
+
const REST = {x: 0, y: 0, scale: 1, rotate: 0, opacity: 1} as const;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Animates `element` with the motion Core uses. `animate` springs channels to
|
|
303
|
+
* a target on the state-change motion, and `decay` coasts them from a release
|
|
304
|
+
* velocity. `set` jumps them, `get` and `getVelocity` read them, `stop` halts
|
|
305
|
+
* them, and `destroy` lets the element go. Under Reduce Motion every call is
|
|
306
|
+
* planned. A move becomes a short cross-fade on a touch screen, and it lands
|
|
307
|
+
* at once with a mouse.
|
|
308
|
+
*
|
|
309
|
+
* Use one animator per element: two on one element overwrite each other.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```
|
|
313
|
+
* const card = document.querySelector('.card');
|
|
314
|
+
* const animator = createAnimator(card);
|
|
315
|
+
* await animator.animate({x: 0, rotate: 0}, {velocity: {x: -900}});
|
|
316
|
+
* animator.decay({x: 2400});
|
|
317
|
+
* animator.destroy();
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export function createAnimator(element: HTMLElement): Animator {
|
|
321
|
+
const {animator, attach} = createAttachableAnimator();
|
|
322
|
+
attach(element);
|
|
323
|
+
return animator;
|
|
324
|
+
}
|