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