@tamagui/animations-css 2.7.7 → 3.0.0-beta.643.1
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/cjs/animated-number.cjs +195 -0
- package/dist/cjs/animated-number.native.cjs +292 -0
- package/dist/cjs/animated-number.native.js +294 -0
- package/dist/cjs/animated-number.native.js.map +1 -0
- package/dist/cjs/createAnimations.cjs +359 -416
- package/dist/cjs/createAnimations.native.cjs +472 -0
- package/dist/cjs/createAnimations.native.js +446 -510
- package/dist/cjs/createAnimations.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/animated-number.mjs +164 -0
- package/dist/esm/animated-number.mjs.map +1 -0
- package/dist/esm/animated-number.native.js +259 -0
- package/dist/esm/animated-number.native.js.map +1 -0
- package/dist/esm/createAnimations.mjs +344 -391
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +430 -485
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/package.json +16 -7
- package/src/animated-number.tsx +262 -0
- package/src/createAnimations.tsx +305 -501
- package/types/animated-number.d.ts +19 -0
- package/types/animated-number.d.ts.map +11 -0
- package/types/createAnimations.d.ts.map +2 -2
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
|
@@ -1,404 +1,357 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAnimatedProperties, getEffectiveAnimation, hasAnimation, normalizeTransition } from "@tamagui/animation-helpers";
|
|
2
2
|
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
3
3
|
import { ResetPresence, usePresence } from "@tamagui/use-presence";
|
|
4
4
|
import { transformsToString } from "@tamagui/web";
|
|
5
5
|
import React from "react";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
import { useAnimatedNumber, useAnimatedNumberReaction, useAnimatedNumberStyle, useAnimatedNumbersStyle } from "./animated-number.mjs";
|
|
7
|
+
|
|
8
|
+
const hasRAF = typeof requestAnimationFrame !== "undefined";
|
|
9
|
+
function waitForAnimations(node) {
|
|
10
|
+
if (typeof node.getAnimations !== "function") {
|
|
11
|
+
return Promise.resolve(true);
|
|
12
|
+
}
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const check = () => {
|
|
15
|
+
const animations = node.getAnimations();
|
|
16
|
+
if (animations.length === 0) {
|
|
17
|
+
resolve(true);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
Promise.all(animations.map((a) => a.finished)).then(() => resolve(true)).catch(() => {
|
|
21
|
+
const remaining = node.getAnimations();
|
|
22
|
+
if (remaining.some((a) => a.playState === "running" || a.pending)) {
|
|
23
|
+
check();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
resolve(false);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
if (hasRAF) {
|
|
30
|
+
requestAnimationFrame(check);
|
|
31
|
+
} else {
|
|
32
|
+
check();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
18
35
|
}
|
|
19
|
-
const
|
|
20
|
-
const S_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*s(?!tiffness)/;
|
|
36
|
+
const DURATION_REGEX = /(\d+(?:\.\d+)?)\s*(?:ms|s(?!tiffness))/;
|
|
21
37
|
function applyDurationOverride(animation, durationMs) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return msReplaced;
|
|
25
|
-
}
|
|
26
|
-
const sReplaced = animation.replace(S_DURATION_REGEX, `${durationMs}ms`);
|
|
27
|
-
if (sReplaced !== animation) {
|
|
28
|
-
return sReplaced;
|
|
29
|
-
}
|
|
30
|
-
return `${durationMs}ms ${animation}`;
|
|
38
|
+
const replaced = animation.replace(DURATION_REGEX, `${durationMs}ms`);
|
|
39
|
+
return replaced === animation ? `${durationMs}ms ${animation}` : replaced;
|
|
31
40
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
parts.push(`rotateY(${style.rotateY}deg)`);
|
|
60
|
-
}
|
|
61
|
-
if (style.rotateZ !== void 0) {
|
|
62
|
-
parts.push(`rotateZ(${style.rotateZ}deg)`);
|
|
63
|
-
}
|
|
64
|
-
if (style.skewX !== void 0) {
|
|
65
|
-
parts.push(`skewX(${style.skewX}deg)`);
|
|
66
|
-
}
|
|
67
|
-
if (style.skewY !== void 0) {
|
|
68
|
-
parts.push(`skewY(${style.skewY}deg)`);
|
|
69
|
-
}
|
|
70
|
-
return parts.join(" ");
|
|
41
|
+
const CSS_TRANSFORM_PROPERTIES = {
|
|
42
|
+
transform: [
|
|
43
|
+
"translate",
|
|
44
|
+
"scale",
|
|
45
|
+
"rotate",
|
|
46
|
+
"transform"
|
|
47
|
+
],
|
|
48
|
+
x: ["translate"],
|
|
49
|
+
y: ["translate"],
|
|
50
|
+
scale: ["scale"],
|
|
51
|
+
scaleX: ["scale"],
|
|
52
|
+
scaleY: ["scale"],
|
|
53
|
+
rotate: ["rotate"],
|
|
54
|
+
rotateX: ["transform"],
|
|
55
|
+
rotateY: ["transform"],
|
|
56
|
+
rotateZ: ["transform"],
|
|
57
|
+
skewX: ["transform"],
|
|
58
|
+
skewY: ["transform"]
|
|
59
|
+
};
|
|
60
|
+
const getCSSProperties = (key) => {
|
|
61
|
+
return CSS_TRANSFORM_PROPERTIES[key] || [key];
|
|
62
|
+
};
|
|
63
|
+
const hyphenatedPropertyCache = {};
|
|
64
|
+
const emptyProperties = [];
|
|
65
|
+
function hyphenateProperty(property) {
|
|
66
|
+
if (property.startsWith("--")) return property;
|
|
67
|
+
return hyphenatedPropertyCache[property] ||= property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
71
68
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
function getLifecycleCSSProperties(keys) {
|
|
70
|
+
if (!keys?.size) return emptyProperties;
|
|
71
|
+
const properties = /* @__PURE__ */ new Set();
|
|
72
|
+
for (const key of keys) {
|
|
73
|
+
for (const property of getCSSProperties(key)) {
|
|
74
|
+
properties.add(hyphenateProperty(property));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return [...properties].sort();
|
|
78
|
+
}
|
|
79
|
+
function readComputedProperties(node, properties) {
|
|
80
|
+
const computed = getComputedStyle(node);
|
|
81
|
+
const values = {};
|
|
82
|
+
for (const property of properties) {
|
|
83
|
+
const value = computed.getPropertyValue(property);
|
|
84
|
+
if (value) values[property] = value;
|
|
85
|
+
}
|
|
86
|
+
return values;
|
|
87
|
+
}
|
|
88
|
+
function applyCSSProperties(node, values) {
|
|
89
|
+
for (const property in values) {
|
|
90
|
+
node.style.setProperty(property, values[property]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function clearCSSProperties(node, properties) {
|
|
94
|
+
for (const property of properties) {
|
|
95
|
+
node.style.removeProperty(property);
|
|
96
|
+
}
|
|
91
97
|
}
|
|
92
98
|
function createAnimations(animations) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
ignoreCancelEvents = false;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
return () => {
|
|
352
|
-
clearTimeout(timeoutId);
|
|
353
|
-
if (rafId !== void 0) cancelAnimationFrame(rafId);
|
|
354
|
-
node.removeEventListener("transitionend", onFinishAnimation);
|
|
355
|
-
node.removeEventListener("transitioncancel", onCancelAnimation);
|
|
356
|
-
node.style.transition = "";
|
|
357
|
-
};
|
|
358
|
-
}, [isExiting]);
|
|
359
|
-
if (isHydrating) {
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
if (!hasNormalizedAnimation(normalized)) {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
if (Array.isArray(style.transform)) {
|
|
366
|
-
style.transform = transformsToString(style.transform);
|
|
367
|
-
}
|
|
368
|
-
const delayStr = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
369
|
-
const durationOverride = normalized.config?.duration;
|
|
370
|
-
style.transition = keys.map(key => {
|
|
371
|
-
const propAnimation = normalized.properties[key];
|
|
372
|
-
let animationValue = null;
|
|
373
|
-
if (typeof propAnimation === "string") {
|
|
374
|
-
animationValue = animations[propAnimation];
|
|
375
|
-
} else if (propAnimation && typeof propAnimation === "object" && propAnimation.type) {
|
|
376
|
-
animationValue = animations[propAnimation.type];
|
|
377
|
-
} else if (defaultAnimation) {
|
|
378
|
-
animationValue = defaultAnimation;
|
|
379
|
-
}
|
|
380
|
-
if (animationValue && durationOverride) {
|
|
381
|
-
animationValue = applyDurationOverride(animationValue, durationOverride);
|
|
382
|
-
}
|
|
383
|
-
return animationValue ? `${key} ${animationValue}${delayStr}` : null;
|
|
384
|
-
}).filter(Boolean).join(", ");
|
|
385
|
-
if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
|
|
386
|
-
console.info("CSS animation", {
|
|
387
|
-
props,
|
|
388
|
-
animations,
|
|
389
|
-
normalized,
|
|
390
|
-
defaultAnimation,
|
|
391
|
-
style,
|
|
392
|
-
isEntering,
|
|
393
|
-
isExiting
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
return {
|
|
397
|
-
style,
|
|
398
|
-
className: isEntering ? "t_unmounted" : ""
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
};
|
|
99
|
+
return {
|
|
100
|
+
animations,
|
|
101
|
+
usePresence,
|
|
102
|
+
ResetPresence,
|
|
103
|
+
inputStyle: "css",
|
|
104
|
+
outputStyle: "css",
|
|
105
|
+
useAnimatedNumber,
|
|
106
|
+
useAnimatedNumberReaction,
|
|
107
|
+
useAnimatedNumberStyle,
|
|
108
|
+
useAnimatedNumbersStyle,
|
|
109
|
+
useAnimations: ({ props, presence, style, componentState, stateRef, styleState, onTransition }) => {
|
|
110
|
+
const isHydrating = componentState.unmounted === true;
|
|
111
|
+
const isEntering = !!componentState.unmounted;
|
|
112
|
+
const isExiting = presence?.[0] === false;
|
|
113
|
+
const sendExitComplete = presence?.[1];
|
|
114
|
+
const onTransitionRef = React.useRef(onTransition);
|
|
115
|
+
onTransitionRef.current = onTransition;
|
|
116
|
+
const emit = (phase, cause, finished) => {
|
|
117
|
+
onTransitionRef.current?.(phase === "end" ? {
|
|
118
|
+
phase,
|
|
119
|
+
cause,
|
|
120
|
+
finished
|
|
121
|
+
} : {
|
|
122
|
+
phase,
|
|
123
|
+
cause
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const wasEnteringRef = React.useRef(isEntering);
|
|
127
|
+
const justFinishedEntering = wasEnteringRef.current && !isEntering;
|
|
128
|
+
React.useEffect(() => {
|
|
129
|
+
wasEnteringRef.current = isEntering;
|
|
130
|
+
});
|
|
131
|
+
const exitCycleIdRef = React.useRef(0);
|
|
132
|
+
const exitCompletedRef = React.useRef(false);
|
|
133
|
+
const wasExitingRef = React.useRef(false);
|
|
134
|
+
const sendExitCompleteRef = React.useRef(sendExitComplete);
|
|
135
|
+
const lastMountedStyleRef = React.useRef({});
|
|
136
|
+
sendExitCompleteRef.current = sendExitComplete;
|
|
137
|
+
const exitCSSProperties = getLifecycleCSSProperties(styleState?.programLifecycleStyleKeys?.exit);
|
|
138
|
+
const exitCSSPropertiesSignature = exitCSSProperties.join("\0");
|
|
139
|
+
const enterCycleIdRef = React.useRef(0);
|
|
140
|
+
const enterStartedRef = React.useRef(false);
|
|
141
|
+
const updateCycleIdRef = React.useRef(0);
|
|
142
|
+
const updateInFlightRef = React.useRef(false);
|
|
143
|
+
const prevUpdateSigRef = React.useRef(null);
|
|
144
|
+
const exitStartedRef = React.useRef(false);
|
|
145
|
+
const justStartedExiting = isExiting && !wasExitingRef.current;
|
|
146
|
+
const justStoppedExiting = !isExiting && wasExitingRef.current;
|
|
147
|
+
if (justStartedExiting) {
|
|
148
|
+
exitCycleIdRef.current++;
|
|
149
|
+
exitCompletedRef.current = false;
|
|
150
|
+
}
|
|
151
|
+
if (justStoppedExiting) {
|
|
152
|
+
exitCycleIdRef.current++;
|
|
153
|
+
}
|
|
154
|
+
React.useEffect(() => {
|
|
155
|
+
wasExitingRef.current = isExiting;
|
|
156
|
+
});
|
|
157
|
+
useIsomorphicLayoutEffect(() => {
|
|
158
|
+
if (isExiting) return;
|
|
159
|
+
const host = stateRef.current.host;
|
|
160
|
+
if (!host || !exitCSSProperties.length) {
|
|
161
|
+
lastMountedStyleRef.current = {};
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const node = host;
|
|
165
|
+
const capture = () => {
|
|
166
|
+
if (stateRef.current.host !== node || wasExitingRef.current) return;
|
|
167
|
+
lastMountedStyleRef.current = readComputedProperties(node, exitCSSProperties);
|
|
168
|
+
};
|
|
169
|
+
if (justFinishedEntering) {
|
|
170
|
+
void waitForAnimations(node).then(capture);
|
|
171
|
+
} else {
|
|
172
|
+
capture();
|
|
173
|
+
}
|
|
174
|
+
}, [
|
|
175
|
+
isExiting,
|
|
176
|
+
justFinishedEntering,
|
|
177
|
+
exitCSSPropertiesSignature
|
|
178
|
+
]);
|
|
179
|
+
const effectiveTransition = styleState?.effectiveTransition ?? props.transition;
|
|
180
|
+
const normalized = normalizeTransition(effectiveTransition);
|
|
181
|
+
const animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default";
|
|
182
|
+
const effectiveAnimationKey = getEffectiveAnimation(normalized, animationState);
|
|
183
|
+
const defaultAnimation = effectiveAnimationKey ? animations[effectiveAnimationKey] : null;
|
|
184
|
+
const animatedProperties = getAnimatedProperties(normalized);
|
|
185
|
+
const hasDefault = normalized.default !== null || normalized.enter !== null || normalized.exit !== null;
|
|
186
|
+
const hasPerPropertyConfigs = animatedProperties.length > 0;
|
|
187
|
+
let keys;
|
|
188
|
+
if (props.animateOnly) {
|
|
189
|
+
keys = props.animateOnly;
|
|
190
|
+
} else if (hasPerPropertyConfigs && !hasDefault) {
|
|
191
|
+
keys = animatedProperties;
|
|
192
|
+
} else if (hasPerPropertyConfigs && hasDefault) {
|
|
193
|
+
keys = ["all", ...animatedProperties];
|
|
194
|
+
} else {
|
|
195
|
+
keys = ["all"];
|
|
196
|
+
}
|
|
197
|
+
let transition;
|
|
198
|
+
const getTransition = () => {
|
|
199
|
+
if (transition !== void 0) return transition;
|
|
200
|
+
const delay = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
201
|
+
const duration = normalized.config?.duration;
|
|
202
|
+
transition = keys.flatMap((key) => {
|
|
203
|
+
const propertyAnimation = normalized.properties[key];
|
|
204
|
+
let animation = defaultAnimation;
|
|
205
|
+
if (typeof propertyAnimation === "string") {
|
|
206
|
+
animation = animations[propertyAnimation];
|
|
207
|
+
} else if (propertyAnimation?.type) {
|
|
208
|
+
animation = animations[propertyAnimation.type];
|
|
209
|
+
}
|
|
210
|
+
if (animation && duration) {
|
|
211
|
+
animation = applyDurationOverride(animation, duration);
|
|
212
|
+
}
|
|
213
|
+
return animation ? getCSSProperties(key).map((property) => `${property} ${animation}${delay}`) : [];
|
|
214
|
+
}).join(", ");
|
|
215
|
+
return transition;
|
|
216
|
+
};
|
|
217
|
+
useIsomorphicLayoutEffect(() => {
|
|
218
|
+
const host = stateRef.current.host;
|
|
219
|
+
if (!sendExitComplete || !isExiting || !host) return;
|
|
220
|
+
const node = host;
|
|
221
|
+
const cycleId = exitCycleIdRef.current;
|
|
222
|
+
if (!exitStartedRef.current) {
|
|
223
|
+
exitStartedRef.current = true;
|
|
224
|
+
emit("start", "exit");
|
|
225
|
+
}
|
|
226
|
+
const completeExit = (finished = true) => {
|
|
227
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
228
|
+
if (exitCompletedRef.current) return;
|
|
229
|
+
exitCompletedRef.current = true;
|
|
230
|
+
if (exitStartedRef.current) {
|
|
231
|
+
exitStartedRef.current = false;
|
|
232
|
+
emit("end", "exit", finished);
|
|
233
|
+
}
|
|
234
|
+
sendExitCompleteRef.current?.();
|
|
235
|
+
};
|
|
236
|
+
if (keys.length === 0) {
|
|
237
|
+
completeExit();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
let rafId;
|
|
241
|
+
let disposed = false;
|
|
242
|
+
const mountedStyle = lastMountedStyleRef.current;
|
|
243
|
+
const canRestart = exitCSSProperties.length > 0 && Object.keys(mountedStyle).length > 0;
|
|
244
|
+
let exitTarget;
|
|
245
|
+
if (canRestart) {
|
|
246
|
+
node.style.transition = "none";
|
|
247
|
+
exitTarget = readComputedProperties(node, exitCSSProperties);
|
|
248
|
+
applyCSSProperties(node, mountedStyle);
|
|
249
|
+
void node.offsetHeight;
|
|
250
|
+
rafId = requestAnimationFrame(() => {
|
|
251
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
252
|
+
node.style.transition = getTransition();
|
|
253
|
+
void node.offsetHeight;
|
|
254
|
+
applyCSSProperties(node, exitTarget);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
void waitForAnimations(node).then((finished) => {
|
|
258
|
+
if (!disposed) completeExit(finished);
|
|
259
|
+
});
|
|
260
|
+
return () => {
|
|
261
|
+
disposed = true;
|
|
262
|
+
if (rafId !== void 0) cancelAnimationFrame(rafId);
|
|
263
|
+
clearCSSProperties(node, exitCSSProperties);
|
|
264
|
+
node.style.transition = "";
|
|
265
|
+
};
|
|
266
|
+
}, [isExiting, exitCSSPropertiesSignature]);
|
|
267
|
+
const styleSignature = onTransition ? (() => {
|
|
268
|
+
const { transition: _t, ...rest } = style;
|
|
269
|
+
return `${JSON.stringify(styleState?.classNames ?? null)}|${JSON.stringify(rest)}`;
|
|
270
|
+
})() : "";
|
|
271
|
+
useIsomorphicLayoutEffect(() => {
|
|
272
|
+
const host = stateRef.current.host;
|
|
273
|
+
if (!onTransitionRef.current || isExiting || !justFinishedEntering || !host) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const node = host;
|
|
277
|
+
const cycleId = ++enterCycleIdRef.current;
|
|
278
|
+
enterStartedRef.current = true;
|
|
279
|
+
emit("start", "enter");
|
|
280
|
+
void waitForAnimations(node).then((finished) => {
|
|
281
|
+
if (cycleId !== enterCycleIdRef.current || !enterStartedRef.current) return;
|
|
282
|
+
enterStartedRef.current = false;
|
|
283
|
+
emit("end", "enter", finished);
|
|
284
|
+
});
|
|
285
|
+
}, [justFinishedEntering, isExiting]);
|
|
286
|
+
useIsomorphicLayoutEffect(() => {
|
|
287
|
+
const host = stateRef.current.host;
|
|
288
|
+
if (!onTransitionRef.current || isEntering || justFinishedEntering || isExiting || !host) {
|
|
289
|
+
prevUpdateSigRef.current = styleSignature;
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (prevUpdateSigRef.current === null) {
|
|
293
|
+
prevUpdateSigRef.current = styleSignature;
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (styleSignature === prevUpdateSigRef.current) return;
|
|
297
|
+
prevUpdateSigRef.current = styleSignature;
|
|
298
|
+
const node = host;
|
|
299
|
+
if (updateInFlightRef.current) {
|
|
300
|
+
emit("end", "update", false);
|
|
301
|
+
}
|
|
302
|
+
updateInFlightRef.current = true;
|
|
303
|
+
const cycleId = ++updateCycleIdRef.current;
|
|
304
|
+
emit("start", "update");
|
|
305
|
+
void waitForAnimations(node).then((finished) => {
|
|
306
|
+
if (cycleId !== updateCycleIdRef.current) return;
|
|
307
|
+
updateInFlightRef.current = false;
|
|
308
|
+
emit("end", "update", finished);
|
|
309
|
+
});
|
|
310
|
+
}, [
|
|
311
|
+
styleSignature,
|
|
312
|
+
isEntering,
|
|
313
|
+
justFinishedEntering,
|
|
314
|
+
isExiting
|
|
315
|
+
]);
|
|
316
|
+
useIsomorphicLayoutEffect(() => {
|
|
317
|
+
if (justStartedExiting && enterStartedRef.current) {
|
|
318
|
+
enterCycleIdRef.current++;
|
|
319
|
+
enterStartedRef.current = false;
|
|
320
|
+
emit("end", "enter", false);
|
|
321
|
+
}
|
|
322
|
+
if (justStoppedExiting && exitStartedRef.current && !exitCompletedRef.current) {
|
|
323
|
+
exitStartedRef.current = false;
|
|
324
|
+
emit("end", "exit", false);
|
|
325
|
+
}
|
|
326
|
+
}, [justStartedExiting, justStoppedExiting]);
|
|
327
|
+
if (isHydrating) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
if (!hasAnimation(normalized)) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
if (Array.isArray(style.transform)) {
|
|
334
|
+
style.transform = transformsToString(style.transform);
|
|
335
|
+
}
|
|
336
|
+
style.transition = getTransition();
|
|
337
|
+
if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
|
|
338
|
+
console.info("CSS animation", {
|
|
339
|
+
props,
|
|
340
|
+
animations,
|
|
341
|
+
normalized,
|
|
342
|
+
defaultAnimation,
|
|
343
|
+
style,
|
|
344
|
+
isEntering,
|
|
345
|
+
isExiting
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
style,
|
|
350
|
+
className: isEntering ? "t_unmounted" : ""
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
};
|
|
402
354
|
}
|
|
355
|
+
|
|
403
356
|
export { createAnimations };
|
|
404
357
|
//# sourceMappingURL=createAnimations.mjs.map
|