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