@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,499 +1,444 @@
|
|
|
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
|
-
"@swc/helpers - typeof";
|
|
6
|
+
import { useAnimatedNumber, useAnimatedNumberReaction, useAnimatedNumberStyle, useAnimatedNumbersStyle } from "./animated-number.native.js";
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
var hasRAF = typeof requestAnimationFrame !== "undefined";
|
|
9
|
+
function waitForAnimations(node) {
|
|
10
|
+
if (typeof node.getAnimations !== "function") {
|
|
11
|
+
return Promise.resolve(true);
|
|
12
|
+
}
|
|
13
|
+
return new Promise(function(resolve) {
|
|
14
|
+
var check = function() {
|
|
15
|
+
var animations = node.getAnimations();
|
|
16
|
+
if (animations.length === 0) {
|
|
17
|
+
resolve(true);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
Promise.all(animations.map(function(a) {
|
|
21
|
+
return a.finished;
|
|
22
|
+
})).then(function() {
|
|
23
|
+
return resolve(true);
|
|
24
|
+
}).catch(function() {
|
|
25
|
+
var remaining = node.getAnimations();
|
|
26
|
+
if (remaining.some(function(a) {
|
|
27
|
+
return a.playState === "running" || a.pending;
|
|
28
|
+
})) {
|
|
29
|
+
check();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
resolve(false);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
if (hasRAF) {
|
|
36
|
+
requestAnimationFrame(check);
|
|
37
|
+
} else {
|
|
38
|
+
check();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
10
41
|
}
|
|
11
|
-
var
|
|
12
|
-
var EXTRACT_S_REGEX = /(\d+(?:\.\d+)?)\s*s/;
|
|
13
|
-
function extractDuration(animation) {
|
|
14
|
-
var msMatch = animation.match(EXTRACT_MS_REGEX);
|
|
15
|
-
if (msMatch) {
|
|
16
|
-
return Number.parseInt(msMatch[1], 10);
|
|
17
|
-
}
|
|
18
|
-
var sMatch = animation.match(EXTRACT_S_REGEX);
|
|
19
|
-
if (sMatch) {
|
|
20
|
-
return Math.round(Number.parseFloat(sMatch[1]) * 1e3);
|
|
21
|
-
}
|
|
22
|
-
return 300;
|
|
23
|
-
}
|
|
24
|
-
var MS_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*ms/;
|
|
25
|
-
var S_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*s(?!tiffness)/;
|
|
42
|
+
var DURATION_REGEX = /(\d+(?:\.\d+)?)\s*(?:ms|s(?!tiffness))/;
|
|
26
43
|
function applyDurationOverride(animation, durationMs) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
var replaced = animation.replace(DURATION_REGEX, `${durationMs}ms`);
|
|
45
|
+
return replaced === animation ? `${durationMs}ms ${animation}` : replaced;
|
|
46
|
+
}
|
|
47
|
+
var CSS_TRANSFORM_PROPERTIES = {
|
|
48
|
+
transform: [
|
|
49
|
+
"translate",
|
|
50
|
+
"scale",
|
|
51
|
+
"rotate",
|
|
52
|
+
"transform"
|
|
53
|
+
],
|
|
54
|
+
x: ["translate"],
|
|
55
|
+
y: ["translate"],
|
|
56
|
+
scale: ["scale"],
|
|
57
|
+
scaleX: ["scale"],
|
|
58
|
+
scaleY: ["scale"],
|
|
59
|
+
rotate: ["rotate"],
|
|
60
|
+
rotateX: ["transform"],
|
|
61
|
+
rotateY: ["transform"],
|
|
62
|
+
rotateZ: ["transform"],
|
|
63
|
+
skewX: ["transform"],
|
|
64
|
+
skewY: ["transform"]
|
|
65
|
+
};
|
|
66
|
+
var getCSSProperties = function(key) {
|
|
67
|
+
return CSS_TRANSFORM_PROPERTIES[key] || [key];
|
|
68
|
+
};
|
|
69
|
+
var hyphenatedPropertyCache = {};
|
|
70
|
+
var emptyProperties = [];
|
|
71
|
+
function hyphenateProperty(property) {
|
|
72
|
+
var _hyphenatedPropertyCache, _property;
|
|
73
|
+
if (property.startsWith("--")) return property;
|
|
74
|
+
return (_hyphenatedPropertyCache = hyphenatedPropertyCache)[_property = property] || (_hyphenatedPropertyCache[_property] = property.replace(/[A-Z]/g, function(letter) {
|
|
75
|
+
return `-${letter.toLowerCase()}`;
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
function getLifecycleCSSProperties(keys) {
|
|
79
|
+
if (!(keys === null || keys === void 0 ? void 0 : keys.size)) return emptyProperties;
|
|
80
|
+
var properties = /* @__PURE__ */ new Set();
|
|
81
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
82
|
+
try {
|
|
83
|
+
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
84
|
+
var key = _step.value;
|
|
85
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
86
|
+
try {
|
|
87
|
+
for (var _iterator1 = getCSSProperties(key)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
88
|
+
var property = _step1.value;
|
|
89
|
+
properties.add(hyphenateProperty(property));
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
_didIteratorError1 = true;
|
|
93
|
+
_iteratorError1 = err;
|
|
94
|
+
} finally {
|
|
95
|
+
try {
|
|
96
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
97
|
+
_iterator1.return();
|
|
98
|
+
}
|
|
99
|
+
} finally {
|
|
100
|
+
if (_didIteratorError1) {
|
|
101
|
+
throw _iteratorError1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
_didIteratorError = true;
|
|
108
|
+
_iteratorError = err;
|
|
109
|
+
} finally {
|
|
110
|
+
try {
|
|
111
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
112
|
+
_iterator.return();
|
|
113
|
+
}
|
|
114
|
+
} finally {
|
|
115
|
+
if (_didIteratorError) {
|
|
116
|
+
throw _iteratorError;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return [...properties].sort();
|
|
36
121
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (style.rotateX !== void 0) {
|
|
63
|
-
parts.push(`rotateX(${style.rotateX}deg)`);
|
|
64
|
-
}
|
|
65
|
-
if (style.rotateY !== void 0) {
|
|
66
|
-
parts.push(`rotateY(${style.rotateY}deg)`);
|
|
67
|
-
}
|
|
68
|
-
if (style.rotateZ !== void 0) {
|
|
69
|
-
parts.push(`rotateZ(${style.rotateZ}deg)`);
|
|
70
|
-
}
|
|
71
|
-
if (style.skewX !== void 0) {
|
|
72
|
-
parts.push(`skewX(${style.skewX}deg)`);
|
|
73
|
-
}
|
|
74
|
-
if (style.skewY !== void 0) {
|
|
75
|
-
parts.push(`skewY(${style.skewY}deg)`);
|
|
76
|
-
}
|
|
77
|
-
return parts.join(" ");
|
|
122
|
+
function readComputedProperties(node, properties) {
|
|
123
|
+
var computed = getComputedStyle(node);
|
|
124
|
+
var values = {};
|
|
125
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
126
|
+
try {
|
|
127
|
+
for (var _iterator = properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
128
|
+
var property = _step.value;
|
|
129
|
+
var value = computed.getPropertyValue(property);
|
|
130
|
+
if (value) values[property] = value;
|
|
131
|
+
}
|
|
132
|
+
} catch (err) {
|
|
133
|
+
_didIteratorError = true;
|
|
134
|
+
_iteratorError = err;
|
|
135
|
+
} finally {
|
|
136
|
+
try {
|
|
137
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
138
|
+
_iterator.return();
|
|
139
|
+
}
|
|
140
|
+
} finally {
|
|
141
|
+
if (_didIteratorError) {
|
|
142
|
+
throw _iteratorError;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return values;
|
|
78
147
|
}
|
|
79
|
-
function
|
|
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
|
-
_iteratorError = err;
|
|
106
|
-
} finally {
|
|
107
|
-
try {
|
|
108
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
109
|
-
_iterator.return();
|
|
110
|
-
}
|
|
111
|
-
} finally {
|
|
112
|
-
if (_didIteratorError) {
|
|
113
|
-
throw _iteratorError;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
148
|
+
function applyCSSProperties(node, values) {
|
|
149
|
+
for (var property in values) {
|
|
150
|
+
node.style.setProperty(property, values[property]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function clearCSSProperties(node, properties) {
|
|
154
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
155
|
+
try {
|
|
156
|
+
for (var _iterator = properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
157
|
+
var property = _step.value;
|
|
158
|
+
node.style.removeProperty(property);
|
|
159
|
+
}
|
|
160
|
+
} catch (err) {
|
|
161
|
+
_didIteratorError = true;
|
|
162
|
+
_iteratorError = err;
|
|
163
|
+
} finally {
|
|
164
|
+
try {
|
|
165
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
166
|
+
_iterator.return();
|
|
167
|
+
}
|
|
168
|
+
} finally {
|
|
169
|
+
if (_didIteratorError) {
|
|
170
|
+
throw _iteratorError;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
117
174
|
}
|
|
118
175
|
function createAnimations(animations) {
|
|
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
|
-
|
|
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
|
-
var _iteratorNormalCompletion2 = true,
|
|
385
|
-
_didIteratorError2 = false,
|
|
386
|
-
_iteratorError2 = void 0;
|
|
387
|
-
try {
|
|
388
|
-
for (var _iterator2 = animationConfigs.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
389
|
-
var animationValue = _step2.value;
|
|
390
|
-
if (animationValue) {
|
|
391
|
-
var duration = extractDuration(animationValue);
|
|
392
|
-
if (duration > maxDuration) {
|
|
393
|
-
maxDuration = duration;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
} catch (err) {
|
|
398
|
-
_didIteratorError2 = true;
|
|
399
|
-
_iteratorError2 = err;
|
|
400
|
-
} finally {
|
|
401
|
-
try {
|
|
402
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
403
|
-
_iterator2.return();
|
|
404
|
-
}
|
|
405
|
-
} finally {
|
|
406
|
-
if (_didIteratorError2) {
|
|
407
|
-
throw _iteratorError2;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
var _normalized_delay;
|
|
412
|
-
var delay = (_normalized_delay = normalized.delay) !== null && _normalized_delay !== void 0 ? _normalized_delay : 0;
|
|
413
|
-
var fallbackTimeout = maxDuration + delay;
|
|
414
|
-
var timeoutId = setTimeout(function () {
|
|
415
|
-
completeExit();
|
|
416
|
-
}, fallbackTimeout);
|
|
417
|
-
var transitioningProps = new Set(keys);
|
|
418
|
-
var completedCount = 0;
|
|
419
|
-
var onFinishAnimation = function (event) {
|
|
420
|
-
if (event.target !== node) return;
|
|
421
|
-
var eventProp = event.propertyName;
|
|
422
|
-
if (transitioningProps.has(eventProp) || eventProp === "all") {
|
|
423
|
-
completedCount++;
|
|
424
|
-
if (completedCount >= transitioningProps.size) {
|
|
425
|
-
clearTimeout(timeoutId);
|
|
426
|
-
completeExit();
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
var onCancelAnimation = function () {
|
|
431
|
-
if (ignoreCancelEvents) return;
|
|
432
|
-
clearTimeout(timeoutId);
|
|
433
|
-
completeExit();
|
|
434
|
-
};
|
|
435
|
-
node.addEventListener("transitionend", onFinishAnimation);
|
|
436
|
-
node.addEventListener("transitioncancel", onCancelAnimation);
|
|
437
|
-
if (wasInterrupted) {
|
|
438
|
-
rafId = requestAnimationFrame(function () {
|
|
439
|
-
if (cycleId !== exitCycleIdRef.current) return;
|
|
440
|
-
node.style.transition = exitTransitionString;
|
|
441
|
-
void node.offsetHeight;
|
|
442
|
-
applyStylesToNode(node, exitStyle);
|
|
443
|
-
ignoreCancelEvents = false;
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
return function () {
|
|
447
|
-
clearTimeout(timeoutId);
|
|
448
|
-
if (rafId !== void 0) cancelAnimationFrame(rafId);
|
|
449
|
-
node.removeEventListener("transitionend", onFinishAnimation);
|
|
450
|
-
node.removeEventListener("transitioncancel", onCancelAnimation);
|
|
451
|
-
node.style.transition = "";
|
|
452
|
-
};
|
|
453
|
-
}, [isExiting]);
|
|
454
|
-
if (isHydrating) {
|
|
455
|
-
return null;
|
|
456
|
-
}
|
|
457
|
-
if (!hasNormalizedAnimation(normalized)) {
|
|
458
|
-
return null;
|
|
459
|
-
}
|
|
460
|
-
if (Array.isArray(style.transform)) {
|
|
461
|
-
style.transform = transformsToString(style.transform);
|
|
462
|
-
}
|
|
463
|
-
var delayStr = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
464
|
-
var durationOverride = (_normalized_config = normalized.config) === null || _normalized_config === void 0 ? void 0 : _normalized_config.duration;
|
|
465
|
-
style.transition = keys.map(function (key) {
|
|
466
|
-
var propAnimation = normalized.properties[key];
|
|
467
|
-
var animationValue = null;
|
|
468
|
-
if (typeof propAnimation === "string") {
|
|
469
|
-
animationValue = animations[propAnimation];
|
|
470
|
-
} else if (propAnimation && (typeof propAnimation === "undefined" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type) {
|
|
471
|
-
animationValue = animations[propAnimation.type];
|
|
472
|
-
} else if (defaultAnimation) {
|
|
473
|
-
animationValue = defaultAnimation;
|
|
474
|
-
}
|
|
475
|
-
if (animationValue && durationOverride) {
|
|
476
|
-
animationValue = applyDurationOverride(animationValue, durationOverride);
|
|
477
|
-
}
|
|
478
|
-
return animationValue ? `${key} ${animationValue}${delayStr}` : null;
|
|
479
|
-
}).filter(Boolean).join(", ");
|
|
480
|
-
if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
|
|
481
|
-
console.info("CSS animation", {
|
|
482
|
-
props,
|
|
483
|
-
animations,
|
|
484
|
-
normalized,
|
|
485
|
-
defaultAnimation,
|
|
486
|
-
style,
|
|
487
|
-
isEntering,
|
|
488
|
-
isExiting
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
return {
|
|
492
|
-
style,
|
|
493
|
-
className: isEntering ? "t_unmounted" : ""
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
};
|
|
176
|
+
return {
|
|
177
|
+
animations,
|
|
178
|
+
usePresence,
|
|
179
|
+
ResetPresence,
|
|
180
|
+
inputStyle: "css",
|
|
181
|
+
outputStyle: "css",
|
|
182
|
+
useAnimatedNumber,
|
|
183
|
+
useAnimatedNumberReaction,
|
|
184
|
+
useAnimatedNumberStyle,
|
|
185
|
+
useAnimatedNumbersStyle,
|
|
186
|
+
useAnimations: function(param) {
|
|
187
|
+
var { props, presence, style, componentState, stateRef, styleState, onTransition } = param;
|
|
188
|
+
var _styleState_programLifecycleStyleKeys;
|
|
189
|
+
var isHydrating = componentState.unmounted === true;
|
|
190
|
+
var isEntering = !!componentState.unmounted;
|
|
191
|
+
var isExiting = (presence === null || presence === void 0 ? void 0 : presence[0]) === false;
|
|
192
|
+
var sendExitComplete = presence === null || presence === void 0 ? void 0 : presence[1];
|
|
193
|
+
var onTransitionRef = React.useRef(onTransition);
|
|
194
|
+
onTransitionRef.current = onTransition;
|
|
195
|
+
var emit = function(phase, cause, finished) {
|
|
196
|
+
var _onTransitionRef_current;
|
|
197
|
+
(_onTransitionRef_current = onTransitionRef.current) === null || _onTransitionRef_current === void 0 ? void 0 : _onTransitionRef_current.call(onTransitionRef, phase === "end" ? {
|
|
198
|
+
phase,
|
|
199
|
+
cause,
|
|
200
|
+
finished
|
|
201
|
+
} : {
|
|
202
|
+
phase,
|
|
203
|
+
cause
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
var wasEnteringRef = React.useRef(isEntering);
|
|
207
|
+
var justFinishedEntering = wasEnteringRef.current && !isEntering;
|
|
208
|
+
React.useEffect(function() {
|
|
209
|
+
wasEnteringRef.current = isEntering;
|
|
210
|
+
});
|
|
211
|
+
var exitCycleIdRef = React.useRef(0);
|
|
212
|
+
var exitCompletedRef = React.useRef(false);
|
|
213
|
+
var wasExitingRef = React.useRef(false);
|
|
214
|
+
var sendExitCompleteRef = React.useRef(sendExitComplete);
|
|
215
|
+
var lastMountedStyleRef = React.useRef({});
|
|
216
|
+
sendExitCompleteRef.current = sendExitComplete;
|
|
217
|
+
var exitCSSProperties = getLifecycleCSSProperties(styleState === null || styleState === void 0 ? void 0 : (_styleState_programLifecycleStyleKeys = styleState.programLifecycleStyleKeys) === null || _styleState_programLifecycleStyleKeys === void 0 ? void 0 : _styleState_programLifecycleStyleKeys.exit);
|
|
218
|
+
var exitCSSPropertiesSignature = exitCSSProperties.join("\0");
|
|
219
|
+
var enterCycleIdRef = React.useRef(0);
|
|
220
|
+
var enterStartedRef = React.useRef(false);
|
|
221
|
+
var updateCycleIdRef = React.useRef(0);
|
|
222
|
+
var updateInFlightRef = React.useRef(false);
|
|
223
|
+
var prevUpdateSigRef = React.useRef(null);
|
|
224
|
+
var exitStartedRef = React.useRef(false);
|
|
225
|
+
var justStartedExiting = isExiting && !wasExitingRef.current;
|
|
226
|
+
var justStoppedExiting = !isExiting && wasExitingRef.current;
|
|
227
|
+
if (justStartedExiting) {
|
|
228
|
+
exitCycleIdRef.current++;
|
|
229
|
+
exitCompletedRef.current = false;
|
|
230
|
+
}
|
|
231
|
+
if (justStoppedExiting) {
|
|
232
|
+
exitCycleIdRef.current++;
|
|
233
|
+
}
|
|
234
|
+
React.useEffect(function() {
|
|
235
|
+
wasExitingRef.current = isExiting;
|
|
236
|
+
});
|
|
237
|
+
useIsomorphicLayoutEffect(function() {
|
|
238
|
+
if (isExiting) return;
|
|
239
|
+
var host = stateRef.current.host;
|
|
240
|
+
if (!host || !exitCSSProperties.length) {
|
|
241
|
+
lastMountedStyleRef.current = {};
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
var node = host;
|
|
245
|
+
var capture = function() {
|
|
246
|
+
if (stateRef.current.host !== node || wasExitingRef.current) return;
|
|
247
|
+
lastMountedStyleRef.current = readComputedProperties(node, exitCSSProperties);
|
|
248
|
+
};
|
|
249
|
+
if (justFinishedEntering) {
|
|
250
|
+
void waitForAnimations(node).then(capture);
|
|
251
|
+
} else {
|
|
252
|
+
capture();
|
|
253
|
+
}
|
|
254
|
+
}, [
|
|
255
|
+
isExiting,
|
|
256
|
+
justFinishedEntering,
|
|
257
|
+
exitCSSPropertiesSignature
|
|
258
|
+
]);
|
|
259
|
+
var _styleState_effectiveTransition;
|
|
260
|
+
var effectiveTransition = (_styleState_effectiveTransition = styleState === null || styleState === void 0 ? void 0 : styleState.effectiveTransition) !== null && _styleState_effectiveTransition !== void 0 ? _styleState_effectiveTransition : props.transition;
|
|
261
|
+
var normalized = normalizeTransition(effectiveTransition);
|
|
262
|
+
var animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default";
|
|
263
|
+
var effectiveAnimationKey = getEffectiveAnimation(normalized, animationState);
|
|
264
|
+
var defaultAnimation = effectiveAnimationKey ? animations[effectiveAnimationKey] : null;
|
|
265
|
+
var animatedProperties = getAnimatedProperties(normalized);
|
|
266
|
+
var hasDefault = normalized.default !== null || normalized.enter !== null || normalized.exit !== null;
|
|
267
|
+
var hasPerPropertyConfigs = animatedProperties.length > 0;
|
|
268
|
+
var keys;
|
|
269
|
+
if (props.animateOnly) {
|
|
270
|
+
keys = props.animateOnly;
|
|
271
|
+
} else if (hasPerPropertyConfigs && !hasDefault) {
|
|
272
|
+
keys = animatedProperties;
|
|
273
|
+
} else if (hasPerPropertyConfigs && hasDefault) {
|
|
274
|
+
keys = ["all", ...animatedProperties];
|
|
275
|
+
} else {
|
|
276
|
+
keys = ["all"];
|
|
277
|
+
}
|
|
278
|
+
var transition;
|
|
279
|
+
var getTransition = function() {
|
|
280
|
+
var _normalized_config;
|
|
281
|
+
if (transition !== void 0) return transition;
|
|
282
|
+
var delay = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
283
|
+
var duration = (_normalized_config = normalized.config) === null || _normalized_config === void 0 ? void 0 : _normalized_config.duration;
|
|
284
|
+
transition = keys.flatMap(function(key) {
|
|
285
|
+
var propertyAnimation = normalized.properties[key];
|
|
286
|
+
var animation = defaultAnimation;
|
|
287
|
+
if (typeof propertyAnimation === "string") {
|
|
288
|
+
animation = animations[propertyAnimation];
|
|
289
|
+
} else if (propertyAnimation === null || propertyAnimation === void 0 ? void 0 : propertyAnimation.type) {
|
|
290
|
+
animation = animations[propertyAnimation.type];
|
|
291
|
+
}
|
|
292
|
+
if (animation && duration) {
|
|
293
|
+
animation = applyDurationOverride(animation, duration);
|
|
294
|
+
}
|
|
295
|
+
return animation ? getCSSProperties(key).map(function(property) {
|
|
296
|
+
return `${property} ${animation}${delay}`;
|
|
297
|
+
}) : [];
|
|
298
|
+
}).join(", ");
|
|
299
|
+
return transition;
|
|
300
|
+
};
|
|
301
|
+
useIsomorphicLayoutEffect(function() {
|
|
302
|
+
var host = stateRef.current.host;
|
|
303
|
+
if (!sendExitComplete || !isExiting || !host) return;
|
|
304
|
+
var node = host;
|
|
305
|
+
var cycleId = exitCycleIdRef.current;
|
|
306
|
+
if (!exitStartedRef.current) {
|
|
307
|
+
exitStartedRef.current = true;
|
|
308
|
+
emit("start", "exit");
|
|
309
|
+
}
|
|
310
|
+
var completeExit = function() {
|
|
311
|
+
var finished = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
312
|
+
var _sendExitCompleteRef_current;
|
|
313
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
314
|
+
if (exitCompletedRef.current) return;
|
|
315
|
+
exitCompletedRef.current = true;
|
|
316
|
+
if (exitStartedRef.current) {
|
|
317
|
+
exitStartedRef.current = false;
|
|
318
|
+
emit("end", "exit", finished);
|
|
319
|
+
}
|
|
320
|
+
(_sendExitCompleteRef_current = sendExitCompleteRef.current) === null || _sendExitCompleteRef_current === void 0 ? void 0 : _sendExitCompleteRef_current.call(sendExitCompleteRef);
|
|
321
|
+
};
|
|
322
|
+
if (keys.length === 0) {
|
|
323
|
+
completeExit();
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
var rafId;
|
|
327
|
+
var disposed = false;
|
|
328
|
+
var mountedStyle = lastMountedStyleRef.current;
|
|
329
|
+
var canRestart = exitCSSProperties.length > 0 && Object.keys(mountedStyle).length > 0;
|
|
330
|
+
var exitTarget;
|
|
331
|
+
if (canRestart) {
|
|
332
|
+
node.style.transition = "none";
|
|
333
|
+
exitTarget = readComputedProperties(node, exitCSSProperties);
|
|
334
|
+
applyCSSProperties(node, mountedStyle);
|
|
335
|
+
void node.offsetHeight;
|
|
336
|
+
rafId = requestAnimationFrame(function() {
|
|
337
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
338
|
+
node.style.transition = getTransition();
|
|
339
|
+
void node.offsetHeight;
|
|
340
|
+
applyCSSProperties(node, exitTarget);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
void waitForAnimations(node).then(function(finished) {
|
|
344
|
+
if (!disposed) completeExit(finished);
|
|
345
|
+
});
|
|
346
|
+
return function() {
|
|
347
|
+
disposed = true;
|
|
348
|
+
if (rafId !== void 0) cancelAnimationFrame(rafId);
|
|
349
|
+
clearCSSProperties(node, exitCSSProperties);
|
|
350
|
+
node.style.transition = "";
|
|
351
|
+
};
|
|
352
|
+
}, [isExiting, exitCSSPropertiesSignature]);
|
|
353
|
+
var styleSignature = onTransition ? (function() {
|
|
354
|
+
var { transition: _t, ...rest } = style;
|
|
355
|
+
var _styleState_classNames;
|
|
356
|
+
return `${JSON.stringify((_styleState_classNames = styleState === null || styleState === void 0 ? void 0 : styleState.classNames) !== null && _styleState_classNames !== void 0 ? _styleState_classNames : null)}|${JSON.stringify(rest)}`;
|
|
357
|
+
})() : "";
|
|
358
|
+
useIsomorphicLayoutEffect(function() {
|
|
359
|
+
var host = stateRef.current.host;
|
|
360
|
+
if (!onTransitionRef.current || isExiting || !justFinishedEntering || !host) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
var node = host;
|
|
364
|
+
var cycleId = ++enterCycleIdRef.current;
|
|
365
|
+
enterStartedRef.current = true;
|
|
366
|
+
emit("start", "enter");
|
|
367
|
+
void waitForAnimations(node).then(function(finished) {
|
|
368
|
+
if (cycleId !== enterCycleIdRef.current || !enterStartedRef.current) return;
|
|
369
|
+
enterStartedRef.current = false;
|
|
370
|
+
emit("end", "enter", finished);
|
|
371
|
+
});
|
|
372
|
+
}, [justFinishedEntering, isExiting]);
|
|
373
|
+
useIsomorphicLayoutEffect(function() {
|
|
374
|
+
var host = stateRef.current.host;
|
|
375
|
+
if (!onTransitionRef.current || isEntering || justFinishedEntering || isExiting || !host) {
|
|
376
|
+
prevUpdateSigRef.current = styleSignature;
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (prevUpdateSigRef.current === null) {
|
|
380
|
+
prevUpdateSigRef.current = styleSignature;
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (styleSignature === prevUpdateSigRef.current) return;
|
|
384
|
+
prevUpdateSigRef.current = styleSignature;
|
|
385
|
+
var node = host;
|
|
386
|
+
if (updateInFlightRef.current) {
|
|
387
|
+
emit("end", "update", false);
|
|
388
|
+
}
|
|
389
|
+
updateInFlightRef.current = true;
|
|
390
|
+
var cycleId = ++updateCycleIdRef.current;
|
|
391
|
+
emit("start", "update");
|
|
392
|
+
void waitForAnimations(node).then(function(finished) {
|
|
393
|
+
if (cycleId !== updateCycleIdRef.current) return;
|
|
394
|
+
updateInFlightRef.current = false;
|
|
395
|
+
emit("end", "update", finished);
|
|
396
|
+
});
|
|
397
|
+
}, [
|
|
398
|
+
styleSignature,
|
|
399
|
+
isEntering,
|
|
400
|
+
justFinishedEntering,
|
|
401
|
+
isExiting
|
|
402
|
+
]);
|
|
403
|
+
useIsomorphicLayoutEffect(function() {
|
|
404
|
+
if (justStartedExiting && enterStartedRef.current) {
|
|
405
|
+
enterCycleIdRef.current++;
|
|
406
|
+
enterStartedRef.current = false;
|
|
407
|
+
emit("end", "enter", false);
|
|
408
|
+
}
|
|
409
|
+
if (justStoppedExiting && exitStartedRef.current && !exitCompletedRef.current) {
|
|
410
|
+
exitStartedRef.current = false;
|
|
411
|
+
emit("end", "exit", false);
|
|
412
|
+
}
|
|
413
|
+
}, [justStartedExiting, justStoppedExiting]);
|
|
414
|
+
if (isHydrating) {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
if (!hasAnimation(normalized)) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
if (Array.isArray(style.transform)) {
|
|
421
|
+
style.transform = transformsToString(style.transform);
|
|
422
|
+
}
|
|
423
|
+
style.transition = getTransition();
|
|
424
|
+
if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
|
|
425
|
+
console.info("CSS animation", {
|
|
426
|
+
props,
|
|
427
|
+
animations,
|
|
428
|
+
normalized,
|
|
429
|
+
defaultAnimation,
|
|
430
|
+
style,
|
|
431
|
+
isEntering,
|
|
432
|
+
isExiting
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
style,
|
|
437
|
+
className: isEntering ? "t_unmounted" : ""
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
};
|
|
497
441
|
}
|
|
442
|
+
|
|
498
443
|
export { createAnimations };
|
|
499
444
|
//# sourceMappingURL=createAnimations.native.js.map
|