@astryxdesign/core 0.7.7-canary.ae97fa8 → 0.7.7-canary.b377b21
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/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +22 -3
- 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 +17 -1
- 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/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/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/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 +433 -127
- 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/Resizable/ResizeHandle.d.ts +2 -1
- package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
- package/dist/Resizable/ResizeHandle.js +99 -77
- 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/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 +35 -6
- 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/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/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/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/BottomSheetPanel.tsx +33 -3
- package/src/BottomSheet/useSheetGestures.ts +3 -1
- package/src/Button/Button.tsx +26 -4
- 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/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 +4 -3
- 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/usePressPin.ts +81 -15
- package/src/Lightbox/Lightbox.tsx +18 -0
- package/src/PowerSearch/PowerSearch.doc.mjs +54 -5
- package/src/PowerSearch/PowerSearch.tsx +609 -155
- 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/Resizable/Resizable.doc.mjs +5 -4
- package/src/Resizable/ResizeHandle.tsx +167 -109
- 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/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/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/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/uikit/alert.ts +43 -0
- package/src/privateAttributes/pressGroupItem.stylex.ts +23 -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
|
@@ -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
|
+
}
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
49
|
import {UIKIT_CONTROL, UIKIT_PAN, UIKIT_PRESS} from '../motion/uikit/gestures';
|
|
50
|
-
|
|
50
|
+
// Importing the whole table bundles its curves into each press-tracking control.
|
|
51
|
+
import {press as pressClocks} from '../motion/uikit/timing';
|
|
51
52
|
import {travel} from './geometry';
|
|
52
53
|
import type {GestureRecognizer, SelectionLock} from './GestureRecognizer';
|
|
53
54
|
import type {TapGestureRecognizer} from './TapGestureRecognizer';
|
|
@@ -154,7 +155,7 @@ export const PRESS_PROFILES = {
|
|
|
154
155
|
// The shared press styles release every surface on the deselect clock
|
|
155
156
|
// until a control runs its own release (UIButton's 250 ms), so a
|
|
156
157
|
// painter's `fading` never outlasts the fade it shows.
|
|
157
|
-
releaseMs:
|
|
158
|
+
releaseMs: pressClocks.highlightOutMs,
|
|
158
159
|
},
|
|
159
160
|
/**
|
|
160
161
|
* A table or collection cell: inside a scroll view it highlights after the
|
|
@@ -165,7 +166,7 @@ export const PRESS_PROFILES = {
|
|
|
165
166
|
highlightDelay: 'inScrollers',
|
|
166
167
|
cancelTravel: UIKIT_PAN.hysteresis.value,
|
|
167
168
|
quickTapFlash: 0,
|
|
168
|
-
releaseMs:
|
|
169
|
+
releaseMs: pressClocks.highlightOutMs,
|
|
169
170
|
},
|
|
170
171
|
} as const satisfies Record<string, PressProfile>;
|
|
171
172
|
|
package/src/gestures/README.md
CHANGED
|
@@ -96,6 +96,10 @@ Once a drag has claimed its finger, a second finger never breaks it.
|
|
|
96
96
|
| `PinchGestureRecognizer` | `UIPinchGestureRecognizer` | continuous | `scale` (settable, to re-base it), `velocity` in scale per second, `focalPoint()` |
|
|
97
97
|
| `ScreenEdgePanGestureRecognizer` | `UIScreenEdgePanGestureRecognizer` | continuous | `edges`: `leading` / `trailing`, resolved against the view's writing direction; attached to an edge zone the view lies within; fails as soon as the touch lands outside every requested edge band; a finger's only |
|
|
98
98
|
|
|
99
|
+
Each recognizer reports what it is in `kind` (`'tap'`, `'longPress'`,
|
|
100
|
+
`'pan'`, `'screenEdgePan'`, `'swipe'`, `'pinch'`): code tells the family apart by it, never by `instanceof`
|
|
101
|
+
(`architecture:react-component-runtime` INV13).
|
|
102
|
+
|
|
99
103
|
A recognizer created with `claimsTouches: false` is a watcher (a tab bar
|
|
100
104
|
that minimizes while the page scrolls): it never claims, so its element gets
|
|
101
105
|
only passive listeners and a scroll never waits for it; it prevents no other
|
|
@@ -174,7 +178,9 @@ innerPan.requireToFail(edgePan);
|
|
|
174
178
|
## Touches in the view: `createPressTracker`
|
|
175
179
|
|
|
176
180
|
A pressable control's view-level touch handling, with `UIControl`
|
|
177
|
-
semantics
|
|
181
|
+
semantics, built by `createPressTracker(options)`: a factory, as
|
|
182
|
+
`architecture:react-component-runtime` INV13 asks of the touch modules outside
|
|
183
|
+
the recognizer family (`VelocityTracker` is still a class, its one listed gap):
|
|
178
184
|
|
|
179
185
|
- `touchDown`, `touchDragInside` / `touchDragOutside`, `touchDragEnter` /
|
|
180
186
|
`touchDragExit`, `touchUpInside` / `touchUpOutside`, `touchCancel`.
|
|
@@ -57,7 +57,8 @@ export interface ActionGroupTrackerOptions {
|
|
|
57
57
|
* target past the group's ends commits the lift there wherever the finger
|
|
58
58
|
* lifts.
|
|
59
59
|
* @default the target whose rect, grown by `highlightExpansion`, holds the
|
|
60
|
-
* point; none between or
|
|
60
|
+
* point, the one the press landed on where several do; none between or
|
|
61
|
+
* outside them
|
|
61
62
|
*/
|
|
62
63
|
resolveTarget?: (
|
|
63
64
|
x: number,
|
|
@@ -83,8 +84,13 @@ export interface ActionGroupTracker {
|
|
|
83
84
|
/**
|
|
84
85
|
* A press began at viewport (x, y): read the actions' rects once and
|
|
85
86
|
* highlight the one under it. An inert press is taken but tracks nothing.
|
|
87
|
+
* `landed` is the node the press landed on.
|
|
86
88
|
*/
|
|
87
|
-
begin(
|
|
89
|
+
begin(
|
|
90
|
+
x: number,
|
|
91
|
+
y: number,
|
|
92
|
+
options?: {inert?: boolean; landed?: Node | null},
|
|
93
|
+
): void;
|
|
88
94
|
/** The finger moved to viewport (x, y). */
|
|
89
95
|
move(x: number, y: number): void;
|
|
90
96
|
/**
|
|
@@ -150,6 +156,7 @@ export function createActionGroupTracker(
|
|
|
150
156
|
let actions: TrackedAction[] = [];
|
|
151
157
|
let highlighted: HTMLElement | null = null;
|
|
152
158
|
let beganOn: HTMLElement | null = null;
|
|
159
|
+
let landedOn: Node | null = null;
|
|
153
160
|
let isTracking = false;
|
|
154
161
|
let isInert = false;
|
|
155
162
|
// The finger's last position: `remeasure` resolves it again.
|
|
@@ -241,6 +248,9 @@ export function createActionGroupTracker(
|
|
|
241
248
|
if (resolveTarget != null) {
|
|
242
249
|
return actions.length === 0 ? null : resolveTarget(x, y, actions);
|
|
243
250
|
}
|
|
251
|
+
// Rects that share an edge, or that have no layout (a test renderer), can
|
|
252
|
+
// both hold the point: the one the press landed on wins.
|
|
253
|
+
let first: HTMLElement | null = null;
|
|
244
254
|
for (const action of actions) {
|
|
245
255
|
if (
|
|
246
256
|
x >= action.left - margin &&
|
|
@@ -248,22 +258,26 @@ export function createActionGroupTracker(
|
|
|
248
258
|
y >= action.top - margin &&
|
|
249
259
|
y <= action.bottom + margin
|
|
250
260
|
) {
|
|
251
|
-
|
|
261
|
+
if (landedOn != null && action.element.contains(landedOn)) {
|
|
262
|
+
return action.element;
|
|
263
|
+
}
|
|
264
|
+
first ??= action.element;
|
|
252
265
|
}
|
|
253
266
|
}
|
|
254
|
-
return
|
|
267
|
+
return first;
|
|
255
268
|
};
|
|
256
269
|
|
|
257
270
|
const reset = () => {
|
|
258
271
|
actions = [];
|
|
259
272
|
highlighted = null;
|
|
260
273
|
beganOn = null;
|
|
274
|
+
landedOn = null;
|
|
261
275
|
isTracking = false;
|
|
262
276
|
isInert = false;
|
|
263
277
|
};
|
|
264
278
|
|
|
265
279
|
return {
|
|
266
|
-
begin(x, y, {inert = false} = {}) {
|
|
280
|
+
begin(x, y, {inert = false, landed = null} = {}) {
|
|
267
281
|
// A press can begin while another is tracked, when a second recognizer
|
|
268
282
|
// takes over the finger (a trigger's held press, then the menu's): the
|
|
269
283
|
// action the first one lit loses its paint.
|
|
@@ -276,6 +290,7 @@ export function createActionGroupTracker(
|
|
|
276
290
|
highlighted = null;
|
|
277
291
|
isTracking = true;
|
|
278
292
|
isInert = inert;
|
|
293
|
+
landedOn = landed;
|
|
279
294
|
lastX = x;
|
|
280
295
|
lastY = y;
|
|
281
296
|
getOptions().onMove?.(x, y);
|
package/src/hooks/index.ts
CHANGED
|
@@ -133,6 +133,8 @@ export type {
|
|
|
133
133
|
UseInteractiveRoleOptions,
|
|
134
134
|
} from './useInteractiveRole';
|
|
135
135
|
|
|
136
|
+
export {useAnimator} from './useAnimator';
|
|
137
|
+
|
|
136
138
|
export {useLongPress} from './useLongPress';
|
|
137
139
|
export type {UseLongPressOptions, UseLongPressHandlers} from './useLongPress';
|
|
138
140
|
|
|
@@ -0,0 +1,21 @@
|
|
|
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';
|