@astryxdesign/core 0.7.7-canary.fc68123 → 0.7.7
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/CHANGELOG.md +104 -0
- package/dist/AlertDialog/AlertDialog.d.ts +1 -4
- package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/dist/AlertDialog/AlertDialog.js +6 -36
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +4 -23
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +1 -3
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +1 -17
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +2 -13
- package/dist/ComplexSelector/ComplexSelector.d.ts +1 -4
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +4 -14
- package/dist/ContextMenu/ContextMenu.js +2 -2
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +31 -7
- package/dist/Field/Field.js +2 -2
- package/dist/HoverCard/HoverCard.d.ts +3 -4
- package/dist/HoverCard/HoverCard.d.ts.map +1 -1
- package/dist/HoverCard/HoverCard.js +2 -27
- package/dist/HoverCard/useHoverCard.d.ts +4 -5
- package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
- package/dist/HoverCard/useHoverCard.js +31 -17
- package/dist/Icon/Icon.d.ts +1 -5
- package/dist/Icon/Icon.d.ts.map +1 -1
- package/dist/Icon/Icon.js +2 -5
- package/dist/Layer/usePressPin.d.ts +5 -17
- package/dist/Layer/usePressPin.d.ts.map +1 -1
- package/dist/Layer/usePressPin.js +12 -62
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +0 -18
- package/dist/PowerSearch/PowerSearch.d.ts +3 -36
- package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearch.js +127 -433
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts +1 -32
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchEditPopover.js +6 -17
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts +3 -38
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchValueEditor.js +61 -170
- package/dist/PowerSearch/formatFilterValue.d.ts +0 -7
- package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
- package/dist/PowerSearch/formatFilterValue.js +1 -11
- package/dist/RadioList/RadioList.d.ts.map +1 -1
- package/dist/RadioList/RadioList.js +2 -3
- package/dist/RadioList/RadioListItem.d.ts +1 -1
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +3 -5
- package/dist/Resizable/ResizeHandle.d.ts +1 -2
- package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
- package/dist/Resizable/ResizeHandle.js +77 -99
- 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 +58 -60
- package/dist/Switch/useSwitchTouch.js +4 -4
- package/dist/Table/BaseTable.d.ts.map +1 -1
- package/dist/Table/BaseTable.js +8 -29
- package/dist/TextInput/TextInput.d.ts +2 -2
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +7 -10
- package/dist/Toast/Toast.d.ts +1 -11
- package/dist/Toast/Toast.d.ts.map +1 -1
- package/dist/Toast/Toast.js +15 -25
- package/dist/Toast/ToastViewport.d.ts.map +1 -1
- package/dist/Toast/ToastViewport.js +34 -94
- package/dist/Toast/types.d.ts +3 -9
- package/dist/Toast/types.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.d.ts +1 -19
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +53 -34
- package/dist/Typeahead/TypeaheadItem.d.ts +1 -2
- package/dist/Typeahead/TypeaheadItem.d.ts.map +1 -1
- package/dist/astryx.css +6 -35
- package/dist/gestures/PressTracker.d.ts.map +1 -1
- package/dist/gestures/PressTracker.js +3 -4
- package/dist/hooks/actionGroupTracker.d.ts +1 -4
- package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
- package/dist/hooks/actionGroupTracker.js +3 -13
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +0 -1
- 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 +2 -6
- package/dist/hooks/useLongPress.d.ts.map +1 -1
- package/dist/hooks/useLongPress.js +15 -95
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +0 -6
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +0 -30
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +0 -30
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/motion/animatedLayout.d.ts.map +1 -1
- package/dist/motion/animatedLayout.js +6 -5
- package/dist/motion/animator.d.ts +14 -14
- package/dist/motion/animator.d.ts.map +1 -1
- package/dist/motion/animator.js +18 -41
- package/dist/utils/dateParser.d.ts.map +1 -1
- package/dist/utils/dateParser.js +0 -12
- package/dist/utils/focusReturn.d.ts +0 -15
- package/dist/utils/focusReturn.d.ts.map +1 -1
- package/dist/utils/focusReturn.js +0 -28
- package/dist/utils/interactionOverlay.stylex.d.ts +2 -3
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +2 -3
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +6 -19
- package/locales/en.json +0 -120
- package/locales/pseudo.json +0 -90
- package/package.json +5 -10
- package/src/AlertDialog/AlertDialog.doc.mjs +2 -2
- package/src/AlertDialog/AlertDialog.tsx +5 -37
- package/src/BottomSheet/BottomSheetPanel.tsx +3 -37
- package/src/BottomSheet/useSheetGestures.ts +1 -3
- package/src/Button/Button.tsx +4 -26
- package/src/CheckboxInput/CheckboxInput.doc.mjs +0 -18
- package/src/CheckboxInput/CheckboxInput.tsx +9 -36
- package/src/ComplexSelector/ComplexSelector.tsx +5 -20
- package/src/ContextMenu/ContextMenu.tsx +2 -2
- package/src/Dialog/Dialog.tsx +31 -10
- package/src/Field/Field.tsx +2 -2
- package/src/HoverCard/HoverCard.doc.mjs +2 -4
- package/src/HoverCard/HoverCard.tsx +4 -35
- package/src/HoverCard/useHoverCard.doc.mjs +36 -178
- package/src/HoverCard/useHoverCard.tsx +52 -46
- package/src/Icon/Icon.doc.mjs +8 -49
- package/src/Icon/Icon.tsx +7 -15
- package/src/Layer/usePressPin.ts +15 -81
- package/src/Lightbox/Lightbox.tsx +0 -18
- package/src/PowerSearch/PowerSearch.doc.mjs +5 -54
- package/src/PowerSearch/PowerSearch.tsx +155 -609
- package/src/PowerSearch/PowerSearchEditPopover.tsx +6 -28
- package/src/PowerSearch/PowerSearchValueEditor.tsx +38 -203
- package/src/PowerSearch/formatFilterValue.ts +1 -18
- package/src/RadioList/RadioList.tsx +2 -3
- package/src/RadioList/RadioListItem.tsx +3 -5
- package/src/Resizable/Resizable.doc.mjs +4 -5
- package/src/Resizable/ResizeHandle.tsx +109 -167
- package/src/SegmentedControl/useSegmentedSelectionMotion.ts +3 -6
- package/src/Slider/sliderTouchController.ts +2 -2
- package/src/Spinner/Spinner.tsx +63 -77
- package/src/Switch/useSwitchTouch.ts +4 -4
- package/src/Table/BaseTable.tsx +12 -46
- package/src/TextInput/TextInput.tsx +10 -11
- package/src/Toast/Toast.doc.mjs +3 -4
- package/src/Toast/Toast.tsx +32 -52
- package/src/Toast/ToastViewport.tsx +35 -121
- package/src/Toast/types.ts +3 -9
- package/src/Tooltip/useTooltip.doc.mjs +0 -24
- package/src/Tooltip/useTooltip.tsx +56 -61
- package/src/Typeahead/TypeaheadItem.doc.mjs +3 -6
- package/src/Typeahead/TypeaheadItem.tsx +1 -2
- package/src/gestures/PressTracker.ts +3 -4
- package/src/gestures/README.md +1 -7
- package/src/hooks/actionGroupTracker.ts +5 -20
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useAttachment.ts +1 -1
- package/src/hooks/useInputStatusIcon.tsx +2 -3
- package/src/hooks/useLongPress.doc.mjs +2 -2
- package/src/hooks/useLongPress.ts +15 -136
- package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +0 -6
- package/src/i18n/generated-locales/en.generated.ts +0 -41
- package/src/i18n/generated-locales/pseudo.generated.ts +0 -42
- package/src/index.ts +0 -13
- package/src/motion/README.md +5 -9
- package/src/motion/animatedLayout.ts +4 -5
- package/src/motion/animator.ts +29 -61
- package/src/utils/dateParser.ts +0 -16
- package/src/utils/focusReturn.ts +0 -30
- package/src/utils/interactionOverlay.stylex.ts +2 -3
- package/src/utils/pressFeedback.ts +6 -19
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +0 -100
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +0 -1
- package/dist/PowerSearch/PowerSearchBottomSheet.js +0 -1913
- package/dist/PowerSearch/formatTokenValue.d.ts +0 -28
- package/dist/PowerSearch/formatTokenValue.d.ts.map +0 -1
- package/dist/PowerSearch/formatTokenValue.js +0 -160
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts +0 -65
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts.map +0 -1
- package/dist/PowerSearch/powerSearchSheetUtils.js +0 -168
- package/dist/animator/createAnimator.d.ts +0 -98
- package/dist/animator/createAnimator.d.ts.map +0 -1
- package/dist/animator/createAnimator.js +0 -259
- package/dist/hooks/pressGroupContext.d.ts +0 -6
- package/dist/hooks/pressGroupContext.d.ts.map +0 -1
- package/dist/hooks/pressGroupContext.js +0 -20
- package/dist/hooks/useActionGroupTracking.d.ts +0 -53
- package/dist/hooks/useActionGroupTracking.d.ts.map +0 -1
- package/dist/hooks/useActionGroupTracking.js +0 -174
- package/dist/hooks/useAnimator.d.ts +0 -41
- package/dist/hooks/useAnimator.d.ts.map +0 -1
- package/dist/hooks/useAnimator.js +0 -70
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts +0 -8
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +0 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +0 -42
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts +0 -8
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts.map +0 -1
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.js +0 -14
- package/dist/internal/indicatorPress.stylex.d.ts +0 -20
- package/dist/internal/indicatorPress.stylex.d.ts.map +0 -1
- package/dist/internal/indicatorPress.stylex.js +0 -26
- package/dist/motion/progress.d.ts +0 -88
- package/dist/motion/progress.d.ts.map +0 -1
- package/dist/motion/progress.js +0 -128
- package/dist/motion/uikit/alert.d.ts +0 -41
- package/dist/motion/uikit/alert.d.ts.map +0 -1
- package/dist/motion/uikit/alert.js +0 -43
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts +0 -15
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +0 -1
- package/dist/privateAttributes/pressGroupItem.stylex.js +0 -23
- package/dist/utils/triggerFocus.d.ts +0 -36
- package/dist/utils/triggerFocus.d.ts.map +0 -1
- package/dist/utils/triggerFocus.js +0 -65
- package/src/PowerSearch/PowerSearchBottomSheet.tsx +0 -2515
- package/src/PowerSearch/formatTokenValue.ts +0 -215
- package/src/PowerSearch/powerSearchSheetUtils.ts +0 -224
- package/src/animator/createAnimator.doc.mjs +0 -153
- package/src/animator/createAnimator.ts +0 -324
- package/src/hooks/pressGroupContext.ts +0 -21
- package/src/hooks/useActionGroupTracking.ts +0 -224
- package/src/hooks/useAnimator.doc.mjs +0 -109
- package/src/hooks/useAnimator.ts +0 -67
- package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +0 -43
- package/src/i18n/generated-english/PowerSearch/formatTokenValue.generated.ts +0 -15
- package/src/internal/indicatorPress.stylex.ts +0 -24
- package/src/motion/progress.ts +0 -155
- package/src/motion/uikit/alert.ts +0 -43
- package/src/privateAttributes/pressGroupItem.stylex.ts +0 -23
- package/src/utils/triggerFocus.ts +0 -80
|
@@ -1,324 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @file pressGroupContext.ts
|
|
7
|
-
* @input Nothing
|
|
8
|
-
* @output PressGroupContext: true inside a group whose own tracker paints
|
|
9
|
-
* its actions' press
|
|
10
|
-
* @position Internal; not exported from the hooks entry. AlertDialog
|
|
11
|
-
* provides it around its tracked actions, and Button reads it.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import {createContext} from 'react';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* True inside a group whose tracker paints a pointer's press on its actions.
|
|
18
|
-
* Those actions take no `:active` paint, so one press never lights two.
|
|
19
|
-
*/
|
|
20
|
-
export const PressGroupContext = createContext(false);
|
|
21
|
-
PressGroupContext.displayName = 'PressGroupContext';
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
'use client';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @file useActionGroupTracking.ts
|
|
7
|
-
* @input A ref to a group of sibling actions, the actions' selector, and the
|
|
8
|
-
* component's tracking constants
|
|
9
|
-
* @output Exports useActionGroupTracking and ActionGroupTrackingOptions
|
|
10
|
-
* @position Internal hook, not exported from the hooks entry. A long press
|
|
11
|
-
* drives the shared action-group tracker (hooks/actionGroupTracker.ts) for
|
|
12
|
-
* a group that a held pointer slides across. AlertDialog consumes it.
|
|
13
|
-
*
|
|
14
|
-
* SYNC: When modified, update useActionGroupTracking.test.tsx
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import {useEffect, useRef, useState, type RefObject} from 'react';
|
|
18
|
-
import {isActive} from '../gestures/GestureRecognizer';
|
|
19
|
-
import {LongPressGestureRecognizer} from '../gestures/LongPressGestureRecognizer';
|
|
20
|
-
import {lockSelection} from '../utils/selectionLock';
|
|
21
|
-
import type {GestureTouch, PointerKind} from '../gestures/types';
|
|
22
|
-
import {useGestureRecognizer} from '../gestures/useGestureRecognizer';
|
|
23
|
-
import {UIKIT_PRESS} from '../motion/uikit/gestures';
|
|
24
|
-
import {isIosWebKit} from '../utils/touchQueries';
|
|
25
|
-
import {createActionGroupTracker} from './actionGroupTracker';
|
|
26
|
-
import {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';
|
|
27
|
-
|
|
28
|
-
export interface ActionGroupTrackingOptions {
|
|
29
|
-
/** Selects the actions inside the tracked element. */
|
|
30
|
-
itemSelector: string;
|
|
31
|
-
/** How long after touch-down the touched action highlights, ms. */
|
|
32
|
-
highlightOnsetMs: number;
|
|
33
|
-
/**
|
|
34
|
-
* How far outside an action a finger keeps it highlighted, px. A mouse or a
|
|
35
|
-
* pen hit-tests the actions' exact rects.
|
|
36
|
-
*/
|
|
37
|
-
highlightExpansion: number;
|
|
38
|
-
/** Pointers that are tracked; others keep the browser's click. @default every pointer */
|
|
39
|
-
pointerTypes?: ReadonlyArray<PointerKind>;
|
|
40
|
-
/** A press whose target this rejects is not tracked. */
|
|
41
|
-
shouldTrack?: (target: unknown) => boolean;
|
|
42
|
-
/** Off, nothing is attached and nothing is tracked. @default true */
|
|
43
|
-
isEnabled?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Let the gesture host write the group's `touch-action` and refuse a text
|
|
46
|
-
* selection while a finger or a pen holds it.
|
|
47
|
-
* @default true
|
|
48
|
-
*/
|
|
49
|
-
manageStyle?: boolean;
|
|
50
|
-
/** Runs the action under the finger at the lift. @default its own click */
|
|
51
|
-
onActivate?: (item: HTMLElement) => void;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const PRESS = UIKIT_PRESS;
|
|
55
|
-
|
|
56
|
-
/** The ref handed to the recognizer while tracking is off: no element. */
|
|
57
|
-
const DETACHED: RefObject<Element | null> = {current: null};
|
|
58
|
-
|
|
59
|
-
const EVERY_POINTER: ReadonlyArray<PointerKind> = ['touch', 'pen', 'mouse'];
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The group's press: a long press that a second finger on the group ends with
|
|
63
|
-
* nothing acting. A plain long press ignores a second finger.
|
|
64
|
-
*/
|
|
65
|
-
class ActionGroupPress extends LongPressGestureRecognizer {
|
|
66
|
-
protected override acceptsTouch(touch: GestureTouch): boolean {
|
|
67
|
-
if (isActive(this.state)) {
|
|
68
|
-
this.setState('cancelled');
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
return super.acceptsTouch(touch);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Track a held pointer on the group behind `ref` across the actions inside
|
|
77
|
-
* it, through the shared action-group tracker.
|
|
78
|
-
*/
|
|
79
|
-
export function useActionGroupTracking(
|
|
80
|
-
ref: RefObject<HTMLElement | null>,
|
|
81
|
-
options: ActionGroupTrackingOptions,
|
|
82
|
-
): ActionGroupPress {
|
|
83
|
-
const optionsRef = useRef(options);
|
|
84
|
-
// Keeps the recognizer's delegate and the tracker, which run outside
|
|
85
|
-
// render, reading the latest options.
|
|
86
|
-
useIsomorphicLayoutEffect(() => {
|
|
87
|
-
optionsRef.current = options;
|
|
88
|
-
});
|
|
89
|
-
// The pointer that started the current press. Only a finger gets the hit
|
|
90
|
-
// expansion; a mouse or a pen hit-tests the actions' exact rects.
|
|
91
|
-
const pointerRef = useRef<PointerKind>('touch');
|
|
92
|
-
const landedRef = useRef<Node | null>(null);
|
|
93
|
-
const [tracker] = useState(() =>
|
|
94
|
-
createActionGroupTracker(() => ({
|
|
95
|
-
roots: () => [ref.current],
|
|
96
|
-
itemSelector: optionsRef.current.itemSelector,
|
|
97
|
-
highlightExpansion:
|
|
98
|
-
pointerRef.current === 'touch'
|
|
99
|
-
? optionsRef.current.highlightExpansion
|
|
100
|
-
: 0,
|
|
101
|
-
onActivate: optionsRef.current.onActivate,
|
|
102
|
-
// The browser's own click for a press the group ran is taken, so the
|
|
103
|
-
// action runs once. The gesture host swallows it for a press it claims.
|
|
104
|
-
// This covers one it does not claim, a mouse under a coarse pointer.
|
|
105
|
-
swallowsNativeClick: true,
|
|
106
|
-
})),
|
|
107
|
-
);
|
|
108
|
-
const isEnabled = options.isEnabled ?? true;
|
|
109
|
-
// Synchronizes the tracker with tracking on and mounted. Turning tracking
|
|
110
|
-
// off, or unmounting, drops a tracked press and ends its release fades.
|
|
111
|
-
// The host reports no cancellation to a disabled recognizer, and the lift
|
|
112
|
-
// that runs an action often closes the owner before its fade ends.
|
|
113
|
-
useEffect(
|
|
114
|
-
() => () => {
|
|
115
|
-
tracker.cancel();
|
|
116
|
-
tracker.dispose();
|
|
117
|
-
},
|
|
118
|
-
[tracker, isEnabled],
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
return useGestureRecognizer(
|
|
122
|
-
isEnabled ? ref : DETACHED,
|
|
123
|
-
() =>
|
|
124
|
-
new ActionGroupPress({
|
|
125
|
-
name: 'ActionGroupTracking',
|
|
126
|
-
minimumPressDuration: options.highlightOnsetMs,
|
|
127
|
-
allowableMovement: Number.POSITIVE_INFINITY,
|
|
128
|
-
allowedPointerTypes: options.pointerTypes ?? EVERY_POINTER,
|
|
129
|
-
delaysTouchesBegan: true,
|
|
130
|
-
// The hold picks an action, so a held finger or pen starts no text
|
|
131
|
-
// selection and opens no callout while down. A long press brings this
|
|
132
|
-
// lock by default; this hold has no minimum duration, so it names it.
|
|
133
|
-
selectionLock: lockSelection,
|
|
134
|
-
shouldReceiveTouch: (recognizer, touch) => {
|
|
135
|
-
if (recognizer.numberOfTouches === 0) {
|
|
136
|
-
pointerRef.current = touch.pointerType;
|
|
137
|
-
const target = touch.target as Node | null;
|
|
138
|
-
landedRef.current =
|
|
139
|
-
typeof target?.nodeType === 'number' ? target : null;
|
|
140
|
-
}
|
|
141
|
-
return receiveTouch(recognizer, touch, optionsRef.current);
|
|
142
|
-
},
|
|
143
|
-
}),
|
|
144
|
-
recognizer => {
|
|
145
|
-
switch (recognizer.state) {
|
|
146
|
-
case 'began': {
|
|
147
|
-
const {x, y} = recognizer.location();
|
|
148
|
-
tracker.begin(x, y, {landed: landedRef.current});
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
case 'changed': {
|
|
152
|
-
const {x, y} = recognizer.location();
|
|
153
|
-
tracker.move(x, y);
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
case 'ended': {
|
|
157
|
-
const doc = ref.current?.ownerDocument;
|
|
158
|
-
const focusedBefore = doc?.activeElement ?? null;
|
|
159
|
-
const beganOn = tracker.beganOn;
|
|
160
|
-
// Whether a click on the lifted action would focus it. A mouse's or
|
|
161
|
-
// a pen's pointerdown already gave the engine's answer, on the action
|
|
162
|
-
// it began on. A tap focuses on a later mousedown, which the claimed
|
|
163
|
-
// touch cancels, so the platform answers for a finger.
|
|
164
|
-
// iOS WebKit focuses no tapped button; Chromium and Firefox do.
|
|
165
|
-
const clickFocuses =
|
|
166
|
-
pointerRef.current === 'touch'
|
|
167
|
-
? !isIosWebKit(doc?.defaultView)
|
|
168
|
-
: beganOn != null && focusedBefore === beganOn;
|
|
169
|
-
const lifted = tracker.end();
|
|
170
|
-
// The lift runs the action's own click(), which moves no focus. So
|
|
171
|
-
// focus moves to the lifted action, unless its click moved focus.
|
|
172
|
-
if (
|
|
173
|
-
clickFocuses &&
|
|
174
|
-
lifted != null &&
|
|
175
|
-
lifted.isConnected &&
|
|
176
|
-
doc?.activeElement === focusedBefore &&
|
|
177
|
-
focusedBefore !== lifted
|
|
178
|
-
) {
|
|
179
|
-
lifted.focus({preventScroll: true, focusVisible: false});
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
case 'cancelled':
|
|
184
|
-
tracker.cancel();
|
|
185
|
-
break;
|
|
186
|
-
case 'possible':
|
|
187
|
-
case 'failed':
|
|
188
|
-
// Listeners are not called for these.
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
isEnabled,
|
|
194
|
-
manageStyle: options.manageStyle ?? true,
|
|
195
|
-
actionGroup: true,
|
|
196
|
-
},
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* The recognizer's should-receive delegate. It also picks the press's clock.
|
|
202
|
-
* Inside a scroller the press waits the content-touch delay and fails past
|
|
203
|
-
* the slop, so the scroller takes a flick. Elsewhere it begins at once, with
|
|
204
|
-
* no movement limit.
|
|
205
|
-
*/
|
|
206
|
-
function receiveTouch(
|
|
207
|
-
recognizer: LongPressGestureRecognizer,
|
|
208
|
-
touch: GestureTouch,
|
|
209
|
-
options: ActionGroupTrackingOptions,
|
|
210
|
-
): boolean {
|
|
211
|
-
if (options.shouldTrack?.(touch.target) === false) {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
if (recognizer.numberOfTouches === 0) {
|
|
215
|
-
const isInsideScroller = touch.scroll?.isInsideScroller === true;
|
|
216
|
-
recognizer.minimumPressDuration = isInsideScroller
|
|
217
|
-
? PRESS.contentTouchDelay.value
|
|
218
|
-
: options.highlightOnsetMs;
|
|
219
|
-
recognizer.allowableMovement = isInsideScroller
|
|
220
|
-
? PRESS.slop.value
|
|
221
|
-
: Number.POSITIVE_INFINITY;
|
|
222
|
-
}
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/** @type {import('@astryxdesign/cli/authoring').HookDoc} */
|
|
4
|
-
export const docs = {
|
|
5
|
-
name: 'useAnimator',
|
|
6
|
-
displayName: 'useAnimator',
|
|
7
|
-
keywords: [
|
|
8
|
-
'animate',
|
|
9
|
-
'animation',
|
|
10
|
-
'animator',
|
|
11
|
-
'spring',
|
|
12
|
-
'decay',
|
|
13
|
-
'momentum',
|
|
14
|
-
'fling',
|
|
15
|
-
'motion',
|
|
16
|
-
'transform',
|
|
17
|
-
'opacity',
|
|
18
|
-
'drag',
|
|
19
|
-
'card',
|
|
20
|
-
],
|
|
21
|
-
params: [
|
|
22
|
-
{
|
|
23
|
-
name: 'ref',
|
|
24
|
-
type: 'RefObject<HTMLElement | null>',
|
|
25
|
-
description:
|
|
26
|
-
'The ref of the one element to animate, the same ref you pass to the element: another hook, such as a gesture hook, can take it too, so a drag and an animation share one element. After every render the animator follows the element behind it. When the element unmounts its motion stops and its values return to rest, so a remount starts at rest, and so does a node that replaces it. Before the element mounts, and while it is unmounted, every call does nothing and `animate` and `decay` resolve at once.',
|
|
27
|
-
required: true,
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
returns: [
|
|
31
|
-
{
|
|
32
|
-
name: 'animator',
|
|
33
|
-
type: 'AnimatorHandle',
|
|
34
|
-
description:
|
|
35
|
-
"The element's animator, the same object on every render: `animate(target, {velocity?})` springs channels to a target on the state-change motion Astryx's components use, `decay(velocity)` coasts them from a release velocity, `set(values)` jumps them, `get()` and `getVelocity()` read them, and `stop()` halts them. The channels are `x` and `y` (px), `scale` (1 at the element's size), `rotate` (degrees) and `opacity` (0 to 1). `animate` and `decay` return a promise that resolves when the motion ends. Calling it never re-renders the component. Calls before the ref attaches do nothing and resolve at once.",
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
usage: {
|
|
39
|
-
description:
|
|
40
|
-
"Animates one element with the motion Astryx's own components use. Call `animator.animate` to spring an element to new values on the state-change motion, `animator.decay` to fling it with the momentum of a released scroll view, and `animator.set` to move it directly, so a card can follow a finger, snap back and be thrown away. 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. Outside React, use `createAnimator`.",
|
|
41
|
-
bestPractices: [
|
|
42
|
-
{
|
|
43
|
-
guidance: true,
|
|
44
|
-
description:
|
|
45
|
-
'Call the animator from event handlers and effects: it lives outside render, so animating never re-renders the component.',
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
guidance: true,
|
|
49
|
-
description:
|
|
50
|
-
'Start every `animate` that follows a drag with the release velocity, so the element carries on as it was thrown.',
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
guidance: true,
|
|
54
|
-
description:
|
|
55
|
-
'Reach every state an animation shows without the animation too: a key, a button or a menu item that calls the same code.',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
guidance: false,
|
|
59
|
-
description:
|
|
60
|
-
'Keep the animated values in React state: read them with `animator.get()` when you need them.',
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
accessibility: [
|
|
64
|
-
{
|
|
65
|
-
name: 'Keyboard and assistive technology',
|
|
66
|
-
category: 'Keyboard',
|
|
67
|
-
description:
|
|
68
|
-
'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.',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'Reduce Motion',
|
|
72
|
-
category: 'Content',
|
|
73
|
-
criterion: '2.3.3 Animation from Interactions',
|
|
74
|
-
description:
|
|
75
|
-
'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.',
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
relatedHooks: ['useAnimatedLayout'],
|
|
80
|
-
importPath: '@astryxdesign/core/hooks',
|
|
81
|
-
category: 'interaction',
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
|
|
85
|
-
export const docsDense = {
|
|
86
|
-
description:
|
|
87
|
-
"Animates the element behind ref (x, y, scale, rotate, opacity) with Astryx's motion; returns the animator.",
|
|
88
|
-
paramDescriptions: {
|
|
89
|
-
ref: 'The element ref; share it with a gesture hook to drag and animate one element.',
|
|
90
|
-
},
|
|
91
|
-
returnDescriptions: {
|
|
92
|
-
animator:
|
|
93
|
-
'animate(target, {velocity?}), decay(velocity), set, get, getVelocity, stop; stable, never re-renders.',
|
|
94
|
-
},
|
|
95
|
-
usage: {
|
|
96
|
-
description:
|
|
97
|
-
'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.',
|
|
98
|
-
bestPractices: [
|
|
99
|
-
{
|
|
100
|
-
guidance: true,
|
|
101
|
-
description: 'Pass the release velocity to animate after a drag.',
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
guidance: false,
|
|
105
|
-
description: 'Keep animated values in state; read animator.get().',
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
},
|
|
109
|
-
};
|