@astryxdesign/core 0.7.8-canary.fbb81c6 → 0.7.8
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 +132 -0
- package/dist/ClickableCard/ClickableCard.d.ts +1 -1
- package/dist/ClickableCard/ClickableCard.d.ts.map +1 -1
- package/dist/ClickableCard/ClickableCard.js +1 -5
- package/dist/DateInput/PickerWheel.d.ts.map +1 -1
- package/dist/DateInput/PickerWheel.js +1 -7
- package/dist/DropdownMenu/DropdownMenu.d.ts +1 -9
- package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenu.js +4 -9
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuCheckboxItem.js +2 -3
- package/dist/DropdownMenu/DropdownMenuItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuItem.js +2 -3
- package/dist/DropdownMenu/DropdownMenuRadioItem.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuRadioItem.js +2 -3
- package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuSubMenu.js +2 -3
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +1 -6
- package/dist/Layer/preserveAnimations.d.ts +5 -1
- package/dist/Layer/preserveAnimations.d.ts.map +1 -1
- package/dist/Layer/preserveAnimations.js +214 -12
- package/dist/MoreMenu/MoreMenu.d.ts +3 -5
- package/dist/MoreMenu/MoreMenu.d.ts.map +1 -1
- package/dist/SelectableCard/SelectableCard.d.ts +1 -1
- package/dist/SelectableCard/SelectableCard.d.ts.map +1 -1
- package/dist/SelectableCard/SelectableCard.js +1 -5
- package/dist/TreeList/TreeListItem.d.ts.map +1 -1
- package/dist/TreeList/TreeListItem.js +1 -3
- package/dist/astryx.css +2 -6
- package/dist/hooks/menuPressGesture.d.ts +21 -132
- package/dist/hooks/menuPressGesture.d.ts.map +1 -1
- package/dist/hooks/menuPressGesture.js +30 -155
- package/dist/hooks/useClickableContainer.d.ts +5 -19
- package/dist/hooks/useClickableContainer.d.ts.map +1 -1
- package/dist/hooks/useClickableContainer.js +5 -28
- package/dist/hooks/useMenuPress.d.ts +1 -34
- package/dist/hooks/useMenuPress.d.ts.map +1 -1
- package/dist/hooks/useMenuPress.js +5 -93
- package/dist/motion/transientCopy.d.ts +2 -4
- package/dist/motion/transientCopy.d.ts.map +1 -1
- package/dist/motion/transientCopy.js +5 -34
- package/dist/motion/uikit/gestures.d.ts +0 -41
- package/dist/motion/uikit/gestures.d.ts.map +1 -1
- package/dist/motion/uikit/gestures.js +0 -25
- package/dist/motion/uikit/index.d.ts +1 -1
- package/dist/motion/uikit/index.d.ts.map +1 -1
- package/dist/motion/uikit/index.js +1 -1
- package/dist/utils/pressFeedback.d.ts +0 -7
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +1 -16
- package/package.json +5 -5
- package/src/ClickableCard/ClickableCard.tsx +1 -8
- package/src/DateInput/PickerWheel.tsx +2 -7
- package/src/DropdownMenu/DropdownMenu.doc.mjs +2 -1
- package/src/DropdownMenu/DropdownMenu.tsx +5 -29
- package/src/DropdownMenu/DropdownMenuCheckboxItem.tsx +1 -5
- package/src/DropdownMenu/DropdownMenuItem.tsx +4 -8
- package/src/DropdownMenu/DropdownMenuRadioItem.tsx +1 -5
- package/src/DropdownMenu/DropdownMenuSubMenu.tsx +1 -5
- package/src/Item/Item.tsx +5 -15
- package/src/Layer/preserveAnimations.ts +275 -12
- package/src/MoreMenu/MoreMenu.doc.mjs +4 -2
- package/src/MoreMenu/MoreMenu.tsx +3 -5
- package/src/SelectableCard/SelectableCard.tsx +1 -8
- package/src/TreeList/TreeListItem.tsx +6 -8
- package/src/hooks/menuPressGesture.ts +38 -243
- package/src/hooks/useClickableContainer.doc.mjs +2 -8
- package/src/hooks/useClickableContainer.ts +6 -52
- package/src/hooks/useMenuPress.ts +11 -118
- package/src/motion/MEASUREMENTS.md +0 -11
- package/src/motion/transientCopy.ts +5 -45
- package/src/motion/uikit/gestures.ts +0 -22
- package/src/motion/uikit/index.ts +0 -1
- package/src/utils/pressFeedback.ts +1 -16
- package/dist/hooks/menuPressValues.d.ts +0 -16
- package/dist/hooks/menuPressValues.d.ts.map +0 -1
- package/dist/hooks/menuPressValues.js +0 -18
- package/dist/motion/carryAnimations.d.ts +0 -58
- package/dist/motion/carryAnimations.d.ts.map +0 -1
- package/dist/motion/carryAnimations.js +0 -305
- package/dist/privateAttributes/menuPressLit.stylex.d.ts +0 -52
- package/dist/privateAttributes/menuPressLit.stylex.d.ts.map +0 -1
- package/dist/privateAttributes/menuPressLit.stylex.js +0 -99
- package/src/hooks/menuPressValues.ts +0 -18
- package/src/motion/carryAnimations.ts +0 -389
- package/src/privateAttributes/menuPressLit.stylex.ts +0 -104
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file carryAnimations.ts
|
|
5
|
-
* @input The CSS animations and transitions of an element and its subtree,
|
|
6
|
-
* read before the browser starts them afresh
|
|
7
|
-
* @output Exports `saveAnimations` and `carryAnimations`, which carry them on
|
|
8
|
-
* in a clone of the element. Also `saveAnimation` and `restoreAnimations`,
|
|
9
|
-
* which put them back after a display reset
|
|
10
|
-
* @position Motion foundation; the transient copy (transientCopy.ts) and the
|
|
11
|
-
* layer runtime's re-placement (Layer/preserveAnimations.ts) use it
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Animation members written in a fixed order rather than generically: the
|
|
16
|
-
* timeline before the range that is measured on it, the rate before the
|
|
17
|
-
* time, and the start time (or, for a paused animation, the current time)
|
|
18
|
-
* last, once the play state is set. `effect` is not
|
|
19
|
-
* replaced, because a CSS animation whose effect script replaces leaves the
|
|
20
|
-
* stylesheet's control; its state is copied onto the new effect instead.
|
|
21
|
-
*/
|
|
22
|
-
const ORDERED = new Set([
|
|
23
|
-
'effect',
|
|
24
|
-
'timeline',
|
|
25
|
-
'rangeStart',
|
|
26
|
-
'rangeEnd',
|
|
27
|
-
'playbackRate',
|
|
28
|
-
'startTime',
|
|
29
|
-
'currentTime',
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
type Writable = Record<string, unknown>;
|
|
33
|
-
|
|
34
|
-
/** Every accessor with a setter on `object`'s prototype chain. */
|
|
35
|
-
function writableAccessors(object: object): string[] {
|
|
36
|
-
const names = new Set<string>();
|
|
37
|
-
for (
|
|
38
|
-
let proto: object | null = Object.getPrototypeOf(object);
|
|
39
|
-
proto != null && proto !== Object.prototype;
|
|
40
|
-
proto = Object.getPrototypeOf(proto)
|
|
41
|
-
) {
|
|
42
|
-
for (const [name, descriptor] of Object.entries(
|
|
43
|
-
Object.getOwnPropertyDescriptors(proto),
|
|
44
|
-
)) {
|
|
45
|
-
if (descriptor.set != null) {
|
|
46
|
-
names.add(name);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return [...names];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* A textual form of a value that is compared by content rather than by
|
|
55
|
-
* identity: a CSS numeric value (as in a timeline range offset) through its
|
|
56
|
-
* serialization, a plain object (a range) through its members. Anything else
|
|
57
|
-
* is compared by identity (`null`).
|
|
58
|
-
*/
|
|
59
|
-
function contentOf(value: unknown): string | null {
|
|
60
|
-
if (
|
|
61
|
-
typeof CSSNumericValue !== 'undefined' &&
|
|
62
|
-
value instanceof CSSNumericValue
|
|
63
|
-
) {
|
|
64
|
-
return value.toString();
|
|
65
|
-
}
|
|
66
|
-
if (
|
|
67
|
-
value != null &&
|
|
68
|
-
typeof value === 'object' &&
|
|
69
|
-
Object.getPrototypeOf(value) === Object.prototype
|
|
70
|
-
) {
|
|
71
|
-
return Object.entries(value)
|
|
72
|
-
.map(([key, inner]) => `${key}:${contentOf(inner) ?? String(inner)}`)
|
|
73
|
-
.join(';');
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function differs(a: unknown, b: unknown): boolean {
|
|
79
|
-
if (a === b) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
const textA = contentOf(a);
|
|
83
|
-
return textA == null || textA !== contentOf(b);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** One animation's state, read before the browser starts it afresh. */
|
|
87
|
-
export interface SavedAnimation {
|
|
88
|
-
animation: Animation;
|
|
89
|
-
name: string;
|
|
90
|
-
target: Element | null;
|
|
91
|
-
pseudoElement: string | null;
|
|
92
|
-
values: Writable;
|
|
93
|
-
effectValues: Writable;
|
|
94
|
-
timing: EffectTiming | null;
|
|
95
|
-
keyframes: ComputedKeyframe[] | null;
|
|
96
|
-
playState: AnimationPlayState;
|
|
97
|
-
replaceState: AnimationReplaceState;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Reads one animation's state generically, from what the platform exposes.
|
|
102
|
-
* That is every accessor with a setter on the animation's and its effect's
|
|
103
|
-
* prototype chains, every field of the effect's timing, and its keyframes. Only values
|
|
104
|
-
* that differ from the recreated animation's are written back, so a value the
|
|
105
|
-
* stylesheet controls stays under its control. A few members are not plain
|
|
106
|
-
* state and are written in their own step (`ORDERED`). The Animation and
|
|
107
|
-
* effect objects themselves cannot be carried over: the old ones keep their
|
|
108
|
-
* listeners and promises.
|
|
109
|
-
*/
|
|
110
|
-
export function saveAnimation(animation: Animation): SavedAnimation {
|
|
111
|
-
const effect = animation.effect as KeyframeEffect | null;
|
|
112
|
-
const values: Writable = {};
|
|
113
|
-
for (const name of writableAccessors(animation)) {
|
|
114
|
-
values[name] = (animation as unknown as Writable)[name];
|
|
115
|
-
}
|
|
116
|
-
const effectValues: Writable = {};
|
|
117
|
-
if (effect != null) {
|
|
118
|
-
for (const name of writableAccessors(effect)) {
|
|
119
|
-
effectValues[name] = (effect as unknown as Writable)[name];
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
animation,
|
|
124
|
-
name:
|
|
125
|
-
(animation as Animation & {animationName?: string}).animationName ?? '',
|
|
126
|
-
target: effect?.target ?? null,
|
|
127
|
-
pseudoElement: effect?.pseudoElement ?? null,
|
|
128
|
-
values,
|
|
129
|
-
effectValues,
|
|
130
|
-
timing: effect?.getTiming() ?? null,
|
|
131
|
-
keyframes: effect?.getKeyframes() ?? null,
|
|
132
|
-
playState: animation.playState,
|
|
133
|
-
replaceState: animation.replaceState,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function write(object: object, name: string, value: unknown): void {
|
|
138
|
-
(object as Writable)[name] = value;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** Give `next` the effect state `saved` had: every writable member. */
|
|
142
|
-
function restoreEffect(next: KeyframeEffect, saved: SavedAnimation): void {
|
|
143
|
-
for (const name of writableAccessors(next)) {
|
|
144
|
-
if (
|
|
145
|
-
name in saved.effectValues &&
|
|
146
|
-
differs(saved.effectValues[name], (next as unknown as Writable)[name])
|
|
147
|
-
) {
|
|
148
|
-
write(next, name, saved.effectValues[name]);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (saved.timing != null) {
|
|
152
|
-
const timing = next.getTiming() as unknown as Writable;
|
|
153
|
-
const changed: Writable = {};
|
|
154
|
-
for (const [field, value] of Object.entries(saved.timing)) {
|
|
155
|
-
if (differs(value, timing[field])) {
|
|
156
|
-
changed[field] = value;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (Object.keys(changed).length > 0) {
|
|
160
|
-
next.updateTiming(changed);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (
|
|
164
|
-
saved.keyframes != null &&
|
|
165
|
-
JSON.stringify(saved.keyframes) !== JSON.stringify(next.getKeyframes())
|
|
166
|
-
) {
|
|
167
|
-
next.setKeyframes(saved.keyframes);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** Give `next` the state `saved` had, member by member. */
|
|
172
|
-
function restore(next: Animation, saved: SavedAnimation): void {
|
|
173
|
-
const effect = next.effect as KeyframeEffect | null;
|
|
174
|
-
if (effect != null) {
|
|
175
|
-
restoreEffect(effect, saved);
|
|
176
|
-
}
|
|
177
|
-
const current = next as unknown as Writable;
|
|
178
|
-
for (const name of ['timeline', 'rangeStart', 'rangeEnd']) {
|
|
179
|
-
if (name in saved.values && differs(saved.values[name], current[name])) {
|
|
180
|
-
write(next, name, saved.values[name]);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
for (const name of writableAccessors(next)) {
|
|
184
|
-
if (
|
|
185
|
-
!ORDERED.has(name) &&
|
|
186
|
-
name in saved.values &&
|
|
187
|
-
differs(saved.values[name], current[name])
|
|
188
|
-
) {
|
|
189
|
-
write(next, name, saved.values[name]);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (saved.replaceState === 'persisted' && next.replaceState !== 'persisted') {
|
|
193
|
-
next.persist();
|
|
194
|
-
}
|
|
195
|
-
const rate = saved.values.playbackRate;
|
|
196
|
-
if (typeof rate === 'number' && rate !== next.playbackRate) {
|
|
197
|
-
next.playbackRate = rate;
|
|
198
|
-
}
|
|
199
|
-
if (saved.playState === 'paused' && next.playState !== 'paused') {
|
|
200
|
-
next.pause();
|
|
201
|
-
} else if (saved.playState !== 'paused' && next.playState === 'paused') {
|
|
202
|
-
next.play();
|
|
203
|
-
}
|
|
204
|
-
// A running animation is anchored to its timeline by its start time, which
|
|
205
|
-
// carries its current time on exactly. A paused one has none and keeps its
|
|
206
|
-
// current time. A finished one holds its end: finishing it again holds the
|
|
207
|
-
// same time, though its start time is then counted from now, since script
|
|
208
|
-
// cannot set a start time and a held time together.
|
|
209
|
-
const start = saved.values.startTime as CSSNumberish | null | undefined;
|
|
210
|
-
const time = saved.values.currentTime as CSSNumberish | null | undefined;
|
|
211
|
-
if (saved.playState === 'finished') {
|
|
212
|
-
next.finish();
|
|
213
|
-
} else if (start != null) {
|
|
214
|
-
next.startTime = start;
|
|
215
|
-
} else if (time != null) {
|
|
216
|
-
next.currentTime = time;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Resume a cancelled CSS transition with a script animation in its state. */
|
|
221
|
-
function resumeTransition(saved: SavedAnimation): void {
|
|
222
|
-
if (saved.target == null || saved.keyframes == null) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const replacement = saved.target.animate(saved.keyframes, {
|
|
226
|
-
pseudoElement: saved.pseudoElement ?? undefined,
|
|
227
|
-
});
|
|
228
|
-
restore(replacement, saved);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function isTransition(animation: Animation): boolean {
|
|
232
|
-
return (
|
|
233
|
-
typeof CSSTransition !== 'undefined' && animation instanceof CSSTransition
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function isCssAnimation(animation: Animation): animation is CSSAnimation {
|
|
238
|
-
return (
|
|
239
|
-
typeof CSSAnimation !== 'undefined' && animation instanceof CSSAnimation
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Finishes an animation that ends: an infinite one cannot be finished, and is
|
|
245
|
-
* left as it runs.
|
|
246
|
-
*/
|
|
247
|
-
function finishIfItEnds(animation: Animation): void {
|
|
248
|
-
const end = animation.effect?.getComputedTiming().endTime;
|
|
249
|
-
if (
|
|
250
|
-
end != null &&
|
|
251
|
-
Number.isFinite(Number(end)) &&
|
|
252
|
-
animation.playbackRate !== 0
|
|
253
|
-
) {
|
|
254
|
-
animation.finish();
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** The members a copy's animation does not take: its element's keep them. */
|
|
259
|
-
const IDENTITY_MEMBERS = new Set(['id', 'onfinish', 'oncancel', 'onremove']);
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* `saved` for an animation that carries on on the copy of its element:
|
|
263
|
-
* aimed at the copy, without the element's id and event handlers.
|
|
264
|
-
*/
|
|
265
|
-
function retarget(
|
|
266
|
-
saved: SavedAnimation,
|
|
267
|
-
copyOf: (element: Element) => Element | null,
|
|
268
|
-
): SavedAnimation | null {
|
|
269
|
-
const target = saved.target == null ? null : copyOf(saved.target);
|
|
270
|
-
if (target == null) {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
const values: Writable = Object.fromEntries(
|
|
274
|
-
Object.entries(saved.values).filter(
|
|
275
|
-
([name]) => !IDENTITY_MEMBERS.has(name),
|
|
276
|
-
),
|
|
277
|
-
);
|
|
278
|
-
const effectValues: Writable = {...saved.effectValues};
|
|
279
|
-
if ('target' in effectValues) {
|
|
280
|
-
effectValues.target = target;
|
|
281
|
-
}
|
|
282
|
-
return {...saved, target, values, effectValues};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Puts each state `saved` holds on the CSS animations and transitions of
|
|
287
|
-
* `root` and its subtree that are not among `survivors`. Each CSS animation
|
|
288
|
-
* the browser started afresh takes the state of the one it replaces. It is
|
|
289
|
-
* matched by element, pseudo-element and name, in order, and then by name
|
|
290
|
-
* alone (an effect script moved to another element or pseudo-element). Each
|
|
291
|
-
* transition whose animation no longer runs resumes as a script animation in
|
|
292
|
-
* its state. One started afresh that replaces none is finished: an entrance
|
|
293
|
-
* that had played and been dropped, or a transition from `@starting-style`.
|
|
294
|
-
* Script animations are left as they are.
|
|
295
|
-
*/
|
|
296
|
-
export function restoreAnimations(
|
|
297
|
-
root: Element,
|
|
298
|
-
saved: ReadonlyArray<SavedAnimation>,
|
|
299
|
-
survivors: ReadonlySet<Animation>,
|
|
300
|
-
): void {
|
|
301
|
-
const after = root.getAnimations({subtree: true});
|
|
302
|
-
const current = new Set(after);
|
|
303
|
-
const cancelled: SavedAnimation[] = [];
|
|
304
|
-
for (const state of saved) {
|
|
305
|
-
if (current.has(state.animation)) {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
if (isTransition(state.animation)) {
|
|
309
|
-
resumeTransition(state);
|
|
310
|
-
} else {
|
|
311
|
-
cancelled.push(state);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
const recreated = after.filter(
|
|
315
|
-
animation =>
|
|
316
|
-
(isCssAnimation(animation) || isTransition(animation)) &&
|
|
317
|
-
!survivors.has(animation),
|
|
318
|
-
);
|
|
319
|
-
const unmatched: Animation[] = [];
|
|
320
|
-
for (const animation of recreated) {
|
|
321
|
-
const effect = animation.effect as KeyframeEffect | null;
|
|
322
|
-
const name =
|
|
323
|
-
(animation as Animation & {animationName?: string}).animationName ?? '';
|
|
324
|
-
const index = cancelled.findIndex(
|
|
325
|
-
state =>
|
|
326
|
-
state.name === name &&
|
|
327
|
-
state.target === (effect?.target ?? null) &&
|
|
328
|
-
state.pseudoElement === (effect?.pseudoElement ?? null),
|
|
329
|
-
);
|
|
330
|
-
if (index === -1) {
|
|
331
|
-
unmatched.push(animation);
|
|
332
|
-
} else {
|
|
333
|
-
restore(animation, cancelled.splice(index, 1)[0]);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
for (const animation of unmatched) {
|
|
337
|
-
const name =
|
|
338
|
-
(animation as Animation & {animationName?: string}).animationName ?? '';
|
|
339
|
-
const index = cancelled.findIndex(state => state.name === name);
|
|
340
|
-
if (index === -1) {
|
|
341
|
-
finishIfItEnds(animation);
|
|
342
|
-
} else {
|
|
343
|
-
restore(animation, cancelled.splice(index, 1)[0]);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/** The CSS animations and transitions `saveAnimations` read. */
|
|
349
|
-
export type SavedAnimations = ReadonlyArray<SavedAnimation>;
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Reads the state of every CSS animation and transition of `root` and its
|
|
353
|
-
* subtree, for `carryAnimations` to give a copy of it.
|
|
354
|
-
*/
|
|
355
|
-
export function saveAnimations(root: Element): SavedAnimations {
|
|
356
|
-
if (typeof root.getAnimations !== 'function') {
|
|
357
|
-
return [];
|
|
358
|
-
}
|
|
359
|
-
return root
|
|
360
|
-
.getAnimations({subtree: true})
|
|
361
|
-
.filter(animation => isCssAnimation(animation) || isTransition(animation))
|
|
362
|
-
.map(saveAnimation);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Carries on in `copy`, a clone of the root `saved` was read from, now laid
|
|
367
|
-
* out, the CSS animations and transitions its element ran. A clone starts
|
|
368
|
-
* each CSS animation again and runs no transition but a `@starting-style`
|
|
369
|
-
* one. So each CSS animation the clone started takes the state of its
|
|
370
|
-
* element's, and each transition runs on as a script animation. One the
|
|
371
|
-
* clone started that its element no longer ran is finished: an entrance that
|
|
372
|
-
* had played, or a `@starting-style` transition. `copyOf` maps each element
|
|
373
|
-
* of the cloned subtree to its copy. The element's own animations keep
|
|
374
|
-
* running, so the copy's take no id or event handler.
|
|
375
|
-
*/
|
|
376
|
-
export function carryAnimations(
|
|
377
|
-
saved: SavedAnimations,
|
|
378
|
-
copy: Element,
|
|
379
|
-
copyOf: (element: Element) => Element | null,
|
|
380
|
-
): void {
|
|
381
|
-
if (typeof copy.getAnimations !== 'function') {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
restoreAnimations(
|
|
385
|
-
copy,
|
|
386
|
-
saved.flatMap(state => retarget(state, copyOf) ?? []),
|
|
387
|
-
new Set(),
|
|
388
|
-
);
|
|
389
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
/**
|
|
3
|
-
* @file privateAttributes/menuPressLit.stylex.ts
|
|
4
|
-
* @input The row that a held finger or pen lights in a menu
|
|
5
|
-
* @output markMenuPressLit and clearMenuPressLit, which mark that row,
|
|
6
|
-
* isMenuPressLit, which reads the mark, menuPressLitRowStyle, which
|
|
7
|
-
* paints the marked row, holdMenuPressPaint and releaseMenuPressPaint,
|
|
8
|
-
* which keep the other rows off their pressed paint, and
|
|
9
|
-
* isMenuPressPaintHeld, which reads that hold
|
|
10
|
-
* @position Owner module of the private menu-press-lit attribute: the only
|
|
11
|
-
* file that writes its name. The menu press model (hooks/useMenuPress.ts)
|
|
12
|
-
* marks the row; DropdownMenu's rows compose the styles. No package entry
|
|
13
|
-
* exports it.
|
|
14
|
-
*
|
|
15
|
-
* SYNC: Each row that composes menuPressLitRowStyle reads
|
|
16
|
-
* `--_menu-row-focus-paint` in its `:focus` background, and a row with an
|
|
17
|
-
* `:active` background reads `--_menu-row-active-paint` there:
|
|
18
|
-
* - /packages/core/src/DropdownMenu/DropdownMenuItem.tsx
|
|
19
|
-
* - /packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.tsx
|
|
20
|
-
* - /packages/core/src/DropdownMenu/DropdownMenuRadioItem.tsx
|
|
21
|
-
* - /packages/core/src/DropdownMenu/DropdownMenuSubMenu.tsx
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import * as stylex from '@stylexjs/stylex';
|
|
25
|
-
import type {StyleXStyles} from '@stylexjs/stylex';
|
|
26
|
-
import {colorVars} from '../theme/tokens.stylex';
|
|
27
|
-
|
|
28
|
-
const MENU_PRESS_LIT = 'data-astryx-menu-press-lit';
|
|
29
|
-
const ACTIVE_PAINT = '--_menu-row-active-paint';
|
|
30
|
-
|
|
31
|
-
/** Marks `row` as the row that a held finger or pen lights. */
|
|
32
|
-
export function markMenuPressLit(row: Element): void {
|
|
33
|
-
row.setAttribute(MENU_PRESS_LIT, '');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Removes the mark from `row`. */
|
|
37
|
-
export function clearMenuPressLit(row: Element): void {
|
|
38
|
-
row.removeAttribute(MENU_PRESS_LIT);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Whether a held finger or pen lights `row`. */
|
|
42
|
-
export function isMenuPressLit(row: Element): boolean {
|
|
43
|
-
return row.hasAttribute(MENU_PRESS_LIT);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Keeps `menu`'s rows off their `:active` paint while a held finger or pen
|
|
48
|
-
* presses in it. The row the press began on stays `:active` as the press
|
|
49
|
-
* moves on. The lit row keeps the pressed overlay through its own mark.
|
|
50
|
-
*/
|
|
51
|
-
export function holdMenuPressPaint(menu: HTMLElement): void {
|
|
52
|
-
menu.style.setProperty(ACTIVE_PAINT, 'transparent');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Gives `menu`'s rows their `:active` paint back. */
|
|
56
|
-
export function releaseMenuPressPaint(menu: HTMLElement): void {
|
|
57
|
-
menu.style.removeProperty(ACTIVE_PAINT);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Whether a held finger or pen keeps `menu`'s rows off their `:active` paint. */
|
|
61
|
-
export function isMenuPressPaintHeld(menu: HTMLElement): boolean {
|
|
62
|
-
return menu.style.getPropertyValue(ACTIVE_PAINT) !== '';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* A value for each attribute state. The index signature gives StyleX the value
|
|
67
|
-
* type, which it cannot read from a literal attribute key.
|
|
68
|
-
*/
|
|
69
|
-
type ByAttribute<Value> = Readonly<{
|
|
70
|
-
default: null;
|
|
71
|
-
[attribute: string]: Value | null;
|
|
72
|
-
}>;
|
|
73
|
-
|
|
74
|
-
const litRowPaint: Readonly<{
|
|
75
|
-
'--_menu-row-focus-paint': ByAttribute<string>;
|
|
76
|
-
'--_menu-row-active-paint': ByAttribute<string>;
|
|
77
|
-
}> = {
|
|
78
|
-
'--_menu-row-focus-paint': {
|
|
79
|
-
default: null,
|
|
80
|
-
'[data-astryx-menu-press-lit]': colorVars['--color-overlay-pressed'],
|
|
81
|
-
},
|
|
82
|
-
'--_menu-row-active-paint': {
|
|
83
|
-
default: null,
|
|
84
|
-
'[data-astryx-menu-press-lit]': colorVars['--color-overlay-pressed'],
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const styles = stylex.create({
|
|
89
|
-
row: {...litRowPaint},
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Compose on a menu row whose `:focus` background is
|
|
94
|
-
* `var(--_menu-row-focus-paint, <hover overlay>)`, and whose `:active`
|
|
95
|
-
* background, if any, is `var(--_menu-row-active-paint, <pressed overlay>)`.
|
|
96
|
-
* The row paints the hover overlay on focus, and the pressed overlay while a
|
|
97
|
-
* held finger or pen lights it.
|
|
98
|
-
* Under a finger, the hover overlay is too faint to follow. The variable has
|
|
99
|
-
* no default: a layered stylesheet emits a default unlayered, and it would
|
|
100
|
-
* beat the attribute arm. The value resolves on the row, so a theme set on any
|
|
101
|
-
* ancestor applies. The style sets only a custom property, which shares no
|
|
102
|
-
* key with StyleX's CSS property type, so TypeScript needs the wider type.
|
|
103
|
-
*/
|
|
104
|
-
export const menuPressLitRowStyle = styles.row as StyleXStyles;
|