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