@tamagui/animations-css 2.0.0-rc.9 → 2.0.0
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/createAnimations.cjs +348 -88
- package/dist/cjs/createAnimations.native.js +447 -107
- package/dist/cjs/createAnimations.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/createAnimations.mjs +321 -63
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +420 -82
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/package.json +9 -8
- package/src/createAnimations.tsx +392 -26
- package/types/createAnimations.d.ts.map +4 -4
- package/types/index.d.ts.map +2 -2
- package/dist/cjs/createAnimations.js +0 -129
- package/dist/cjs/createAnimations.js.map +0 -6
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/index.js.map +0 -6
- package/dist/esm/createAnimations.js +0 -114
- package/dist/esm/createAnimations.js.map +0 -6
|
@@ -2,58 +2,130 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
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, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
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
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var createAnimations_exports = {};
|
|
33
35
|
__export(createAnimations_exports, {
|
|
34
36
|
createAnimations: () => createAnimations
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(createAnimations_exports);
|
|
37
|
-
var import_animation_helpers = require("@tamagui/animation-helpers")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const EXTRACT_MS_REGEX = /(\d+(?:\.\d+)?)\s*ms
|
|
43
|
-
|
|
39
|
+
var import_animation_helpers = require("@tamagui/animation-helpers");
|
|
40
|
+
var import_constants = require("@tamagui/constants");
|
|
41
|
+
var import_use_presence = require("@tamagui/use-presence");
|
|
42
|
+
var import_web = require("@tamagui/web");
|
|
43
|
+
var import_react = __toESM(require("react"), 1);
|
|
44
|
+
const EXTRACT_MS_REGEX = /(\d+(?:\.\d+)?)\s*ms/;
|
|
45
|
+
const EXTRACT_S_REGEX = /(\d+(?:\.\d+)?)\s*s/;
|
|
44
46
|
function extractDuration(animation) {
|
|
45
47
|
const msMatch = animation.match(EXTRACT_MS_REGEX);
|
|
46
|
-
if (msMatch)
|
|
48
|
+
if (msMatch) {
|
|
49
|
+
return Number.parseInt(msMatch[1], 10);
|
|
50
|
+
}
|
|
47
51
|
const sMatch = animation.match(EXTRACT_S_REGEX);
|
|
48
|
-
|
|
52
|
+
if (sMatch) {
|
|
53
|
+
return Math.round(Number.parseFloat(sMatch[1]) * 1e3);
|
|
54
|
+
}
|
|
55
|
+
return 300;
|
|
49
56
|
}
|
|
50
|
-
const MS_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*ms
|
|
51
|
-
|
|
57
|
+
const MS_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*ms/;
|
|
58
|
+
const S_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*s(?!tiffness)/;
|
|
52
59
|
function applyDurationOverride(animation, durationMs) {
|
|
53
60
|
const msReplaced = animation.replace(MS_DURATION_REGEX, `${durationMs}ms`);
|
|
54
|
-
if (msReplaced !== animation)
|
|
61
|
+
if (msReplaced !== animation) {
|
|
62
|
+
return msReplaced;
|
|
63
|
+
}
|
|
55
64
|
const sReplaced = animation.replace(S_DURATION_REGEX, `${durationMs}ms`);
|
|
56
|
-
|
|
65
|
+
if (sReplaced !== animation) {
|
|
66
|
+
return sReplaced;
|
|
67
|
+
}
|
|
68
|
+
return `${durationMs}ms ${animation}`;
|
|
69
|
+
}
|
|
70
|
+
const TRANSFORM_KEYS = ["x", "y", "scale", "scaleX", "scaleY", "rotate", "rotateX", "rotateY", "rotateZ", "skewX", "skewY"];
|
|
71
|
+
function buildTransformString(style) {
|
|
72
|
+
if (!style) return "";
|
|
73
|
+
const parts = [];
|
|
74
|
+
if (style.x !== void 0 || style.y !== void 0) {
|
|
75
|
+
const x = style.x ?? 0;
|
|
76
|
+
const y = style.y ?? 0;
|
|
77
|
+
parts.push(`translate(${x}px, ${y}px)`);
|
|
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(" ");
|
|
109
|
+
}
|
|
110
|
+
function applyStylesToNode(node, style) {
|
|
111
|
+
if (!style) return;
|
|
112
|
+
const transformStr = buildTransformString(style);
|
|
113
|
+
if (transformStr) {
|
|
114
|
+
node.style.transform = transformStr;
|
|
115
|
+
}
|
|
116
|
+
for (const [key, value] of Object.entries(style)) {
|
|
117
|
+
if (TRANSFORM_KEYS.includes(key)) continue;
|
|
118
|
+
if (value === void 0) continue;
|
|
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
|
+
}
|
|
57
129
|
}
|
|
58
130
|
function createAnimations(animations) {
|
|
59
131
|
const reactionListeners = /* @__PURE__ */new WeakMap();
|
|
@@ -61,28 +133,43 @@ function createAnimations(animations) {
|
|
|
61
133
|
animations,
|
|
62
134
|
usePresence: import_use_presence.usePresence,
|
|
63
135
|
ResetPresence: import_use_presence.ResetPresence,
|
|
64
|
-
supportsCSS: !0,
|
|
65
136
|
inputStyle: "css",
|
|
66
137
|
outputStyle: "css",
|
|
67
|
-
classNameAnimation: !0,
|
|
68
138
|
useAnimatedNumber(initial) {
|
|
69
|
-
const [val, setVal] = import_react.default.useState(initial)
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
onFinish && (onFinish?.(), setOnFinish(void 0));
|
|
73
|
-
}, [onFinish]), {
|
|
139
|
+
const [val, setVal] = import_react.default.useState(initial);
|
|
140
|
+
const finishTimerRef = import_react.default.useRef(null);
|
|
141
|
+
return {
|
|
74
142
|
getInstance() {
|
|
75
143
|
return setVal;
|
|
76
144
|
},
|
|
77
145
|
getValue() {
|
|
78
146
|
return val;
|
|
79
147
|
},
|
|
80
|
-
setValue(next, config,
|
|
81
|
-
setVal(next)
|
|
148
|
+
setValue(next, config, onFinish) {
|
|
149
|
+
setVal(next);
|
|
150
|
+
if (finishTimerRef.current) {
|
|
151
|
+
clearTimeout(finishTimerRef.current);
|
|
152
|
+
finishTimerRef.current = null;
|
|
153
|
+
}
|
|
154
|
+
if (onFinish) {
|
|
155
|
+
if (!config || config.type === "direct" || config.type === "timing" && config.duration === 0) {
|
|
156
|
+
onFinish();
|
|
157
|
+
} else {
|
|
158
|
+
const duration = config.type === "timing" ? config.duration : 300;
|
|
159
|
+
finishTimerRef.current = setTimeout(onFinish, duration);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
82
162
|
const listeners = reactionListeners.get(setVal);
|
|
83
|
-
|
|
163
|
+
if (listeners) {
|
|
164
|
+
listeners.forEach(listener => listener(next));
|
|
165
|
+
}
|
|
84
166
|
},
|
|
85
|
-
stop() {
|
|
167
|
+
stop() {
|
|
168
|
+
if (finishTimerRef.current) {
|
|
169
|
+
clearTimeout(finishTimerRef.current);
|
|
170
|
+
finishTimerRef.current = null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
86
173
|
};
|
|
87
174
|
},
|
|
88
175
|
useAnimatedNumberReaction({
|
|
@@ -93,9 +180,11 @@ function createAnimations(animations) {
|
|
|
93
180
|
let queue = reactionListeners.get(instance);
|
|
94
181
|
if (!queue) {
|
|
95
182
|
const next = /* @__PURE__ */new Set();
|
|
96
|
-
reactionListeners.set(instance, next)
|
|
183
|
+
reactionListeners.set(instance, next);
|
|
184
|
+
queue = next;
|
|
97
185
|
}
|
|
98
|
-
|
|
186
|
+
queue.add(onValue);
|
|
187
|
+
return () => {
|
|
99
188
|
queue?.delete(onValue);
|
|
100
189
|
};
|
|
101
190
|
}, []);
|
|
@@ -103,61 +192,232 @@ function createAnimations(animations) {
|
|
|
103
192
|
useAnimatedNumberStyle(val, getStyle) {
|
|
104
193
|
return getStyle(val.getValue());
|
|
105
194
|
},
|
|
195
|
+
useAnimatedNumbersStyle(vals, getStyle) {
|
|
196
|
+
return getStyle(...vals.map(v => v.getValue()));
|
|
197
|
+
},
|
|
198
|
+
// @ts-ignore - styleState is added by createComponent
|
|
106
199
|
useAnimations: ({
|
|
107
200
|
props,
|
|
108
201
|
presence,
|
|
109
202
|
style,
|
|
110
203
|
componentState,
|
|
111
|
-
stateRef
|
|
204
|
+
stateRef,
|
|
205
|
+
styleState
|
|
112
206
|
}) => {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
207
|
+
const isHydrating = componentState.unmounted === true;
|
|
208
|
+
const isEntering = !!componentState.unmounted;
|
|
209
|
+
const isExiting = presence?.[0] === false;
|
|
210
|
+
const sendExitComplete = presence?.[1];
|
|
211
|
+
const wasEnteringRef = import_react.default.useRef(isEntering);
|
|
212
|
+
const justFinishedEntering = wasEnteringRef.current && !isEntering;
|
|
118
213
|
import_react.default.useEffect(() => {
|
|
119
214
|
wasEnteringRef.current = isEntering;
|
|
120
215
|
});
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
216
|
+
const exitCycleIdRef = import_react.default.useRef(0);
|
|
217
|
+
const exitCompletedRef = import_react.default.useRef(false);
|
|
218
|
+
const wasExitingRef = import_react.default.useRef(false);
|
|
219
|
+
const exitInterruptedRef = import_react.default.useRef(false);
|
|
220
|
+
const justStartedExiting = isExiting && !wasExitingRef.current;
|
|
221
|
+
const justStoppedExiting = !isExiting && wasExitingRef.current;
|
|
222
|
+
if (justStartedExiting) {
|
|
223
|
+
exitCycleIdRef.current++;
|
|
224
|
+
exitCompletedRef.current = false;
|
|
225
|
+
}
|
|
226
|
+
if (justStoppedExiting) {
|
|
227
|
+
exitCycleIdRef.current++;
|
|
228
|
+
exitInterruptedRef.current = true;
|
|
229
|
+
}
|
|
230
|
+
import_react.default.useEffect(() => {
|
|
231
|
+
wasExitingRef.current = isExiting;
|
|
232
|
+
});
|
|
233
|
+
const effectiveTransition = styleState?.effectiveTransition ?? props.transition;
|
|
234
|
+
const normalized = (0, import_animation_helpers.normalizeTransition)(effectiveTransition);
|
|
235
|
+
const animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default";
|
|
236
|
+
const effectiveAnimationKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
|
|
237
|
+
const defaultAnimation = effectiveAnimationKey ? animations[effectiveAnimationKey] : null;
|
|
238
|
+
const animatedProperties = (0, import_animation_helpers.getAnimatedProperties)(normalized);
|
|
239
|
+
const hasDefault = normalized.default !== null || normalized.enter !== null || normalized.exit !== null;
|
|
240
|
+
const hasPerPropertyConfigs = animatedProperties.length > 0;
|
|
127
241
|
let keys;
|
|
128
|
-
if (props.animateOnly
|
|
242
|
+
if (props.animateOnly) {
|
|
243
|
+
keys = props.animateOnly;
|
|
244
|
+
} else if (hasPerPropertyConfigs && !hasDefault) {
|
|
245
|
+
keys = animatedProperties;
|
|
246
|
+
} else if (hasPerPropertyConfigs && hasDefault) {
|
|
247
|
+
keys = ["all", ...animatedProperties];
|
|
248
|
+
} else {
|
|
249
|
+
keys = ["all"];
|
|
250
|
+
}
|
|
251
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
129
252
|
const host = stateRef.current.host;
|
|
130
253
|
if (!sendExitComplete || !isExiting || !host) return;
|
|
131
|
-
const node = host
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
onFinishAnimation = () => {
|
|
139
|
-
clearTimeout(timeoutId), sendExitComplete?.();
|
|
140
|
-
};
|
|
141
|
-
return node.addEventListener("transitionend", onFinishAnimation), node.addEventListener("transitioncancel", onFinishAnimation), () => {
|
|
142
|
-
clearTimeout(timeoutId), node.removeEventListener("transitionend", onFinishAnimation), node.removeEventListener("transitioncancel", onFinishAnimation);
|
|
254
|
+
const node = host;
|
|
255
|
+
const cycleId = exitCycleIdRef.current;
|
|
256
|
+
const completeExit = () => {
|
|
257
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
258
|
+
if (exitCompletedRef.current) return;
|
|
259
|
+
exitCompletedRef.current = true;
|
|
260
|
+
sendExitComplete();
|
|
143
261
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
262
|
+
if (keys.length === 0) {
|
|
263
|
+
completeExit();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
let rafId;
|
|
267
|
+
const wasInterrupted = exitInterruptedRef.current;
|
|
268
|
+
let ignoreCancelEvents = wasInterrupted;
|
|
269
|
+
const enterStyle = props.enterStyle;
|
|
270
|
+
const exitStyle = props.exitStyle;
|
|
271
|
+
const delayStr2 = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
272
|
+
const durationOverride2 = normalized.config?.duration;
|
|
273
|
+
const exitTransitionString = keys.map(key => {
|
|
274
|
+
const propAnimation = normalized.properties[key];
|
|
275
|
+
let animationValue = null;
|
|
276
|
+
if (typeof propAnimation === "string") {
|
|
277
|
+
animationValue = animations[propAnimation];
|
|
278
|
+
} else if (propAnimation && typeof propAnimation === "object" && propAnimation.type) {
|
|
279
|
+
animationValue = animations[propAnimation.type];
|
|
280
|
+
} else if (defaultAnimation) {
|
|
281
|
+
animationValue = defaultAnimation;
|
|
282
|
+
}
|
|
283
|
+
if (animationValue && durationOverride2) {
|
|
284
|
+
animationValue = applyDurationOverride(animationValue, durationOverride2);
|
|
285
|
+
}
|
|
286
|
+
return animationValue ? `${key} ${animationValue}${delayStr2}` : null;
|
|
287
|
+
}).filter(Boolean).join(", ");
|
|
288
|
+
if (wasInterrupted) {
|
|
289
|
+
exitInterruptedRef.current = false;
|
|
290
|
+
node.style.transition = "none";
|
|
291
|
+
if (exitStyle) {
|
|
292
|
+
const resetStyle = {};
|
|
293
|
+
for (const key of Object.keys(exitStyle)) {
|
|
294
|
+
if (key === "opacity") {
|
|
295
|
+
resetStyle[key] = 1;
|
|
296
|
+
} else if (TRANSFORM_KEYS.includes(key)) {
|
|
297
|
+
resetStyle[key] = key === "scale" || key === "scaleX" || key === "scaleY" ? 1 : 0;
|
|
298
|
+
} else if (enterStyle?.[key] !== void 0) {
|
|
299
|
+
resetStyle[key] = enterStyle[key];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
applyStylesToNode(node, resetStyle);
|
|
303
|
+
} else {
|
|
304
|
+
node.style.opacity = "1";
|
|
305
|
+
node.style.transform = "none";
|
|
306
|
+
}
|
|
307
|
+
void node.offsetHeight;
|
|
308
|
+
} else if (exitStyle) {
|
|
309
|
+
ignoreCancelEvents = true;
|
|
310
|
+
node.style.transition = "none";
|
|
311
|
+
const resetStyle = {};
|
|
312
|
+
for (const key of Object.keys(exitStyle)) {
|
|
313
|
+
if (key === "opacity") {
|
|
314
|
+
resetStyle[key] = 1;
|
|
315
|
+
} else if (TRANSFORM_KEYS.includes(key)) {
|
|
316
|
+
resetStyle[key] = key === "scale" || key === "scaleX" || key === "scaleY" ? 1 : 0;
|
|
317
|
+
} else if (enterStyle?.[key] !== void 0) {
|
|
318
|
+
resetStyle[key] = enterStyle[key];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
applyStylesToNode(node, resetStyle);
|
|
322
|
+
void node.offsetHeight;
|
|
323
|
+
rafId = requestAnimationFrame(() => {
|
|
324
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
325
|
+
node.style.transition = exitTransitionString;
|
|
326
|
+
void node.offsetHeight;
|
|
327
|
+
applyStylesToNode(node, exitStyle);
|
|
328
|
+
ignoreCancelEvents = false;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
let maxDuration = defaultAnimation ? extractDuration(defaultAnimation) : 200;
|
|
332
|
+
const animationConfigs = (0, import_animation_helpers.getAnimationConfigsForKeys)(normalized, animations, keys, defaultAnimation);
|
|
333
|
+
for (const animationValue of animationConfigs.values()) {
|
|
334
|
+
if (animationValue) {
|
|
335
|
+
const duration = extractDuration(animationValue);
|
|
336
|
+
if (duration > maxDuration) {
|
|
337
|
+
maxDuration = duration;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const delay = normalized.delay ?? 0;
|
|
342
|
+
const fallbackTimeout = maxDuration + delay;
|
|
343
|
+
const timeoutId = setTimeout(() => {
|
|
344
|
+
completeExit();
|
|
345
|
+
}, fallbackTimeout);
|
|
346
|
+
const transitioningProps = new Set(keys);
|
|
347
|
+
let completedCount = 0;
|
|
348
|
+
const onFinishAnimation = event => {
|
|
349
|
+
if (event.target !== node) return;
|
|
350
|
+
const eventProp = event.propertyName;
|
|
351
|
+
if (transitioningProps.has(eventProp) || eventProp === "all") {
|
|
352
|
+
completedCount++;
|
|
353
|
+
if (completedCount >= transitioningProps.size) {
|
|
354
|
+
clearTimeout(timeoutId);
|
|
355
|
+
completeExit();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const onCancelAnimation = () => {
|
|
360
|
+
if (ignoreCancelEvents) return;
|
|
361
|
+
clearTimeout(timeoutId);
|
|
362
|
+
completeExit();
|
|
363
|
+
};
|
|
364
|
+
node.addEventListener("transitionend", onFinishAnimation);
|
|
365
|
+
node.addEventListener("transitioncancel", onCancelAnimation);
|
|
366
|
+
if (wasInterrupted) {
|
|
367
|
+
rafId = requestAnimationFrame(() => {
|
|
368
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
369
|
+
node.style.transition = exitTransitionString;
|
|
370
|
+
void node.offsetHeight;
|
|
371
|
+
applyStylesToNode(node, exitStyle);
|
|
372
|
+
ignoreCancelEvents = false;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
return () => {
|
|
376
|
+
clearTimeout(timeoutId);
|
|
377
|
+
if (rafId !== void 0) cancelAnimationFrame(rafId);
|
|
378
|
+
node.removeEventListener("transitionend", onFinishAnimation);
|
|
379
|
+
node.removeEventListener("transitioncancel", onCancelAnimation);
|
|
380
|
+
node.style.transition = "";
|
|
381
|
+
};
|
|
382
|
+
}, [sendExitComplete, isExiting, stateRef, keys, normalized, defaultAnimation, props.enterStyle, props.exitStyle]);
|
|
383
|
+
if (isHydrating) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
if (!(0, import_animation_helpers.hasAnimation)(normalized)) {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
if (Array.isArray(style.transform)) {
|
|
390
|
+
style.transform = (0, import_web.transformsToString)(style.transform);
|
|
391
|
+
}
|
|
392
|
+
const delayStr = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
393
|
+
const durationOverride = normalized.config?.duration;
|
|
394
|
+
style.transition = keys.map(key => {
|
|
149
395
|
const propAnimation = normalized.properties[key];
|
|
150
396
|
let animationValue = null;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
397
|
+
if (typeof propAnimation === "string") {
|
|
398
|
+
animationValue = animations[propAnimation];
|
|
399
|
+
} else if (propAnimation && typeof propAnimation === "object" && propAnimation.type) {
|
|
400
|
+
animationValue = animations[propAnimation.type];
|
|
401
|
+
} else if (defaultAnimation) {
|
|
402
|
+
animationValue = defaultAnimation;
|
|
403
|
+
}
|
|
404
|
+
if (animationValue && durationOverride) {
|
|
405
|
+
animationValue = applyDurationOverride(animationValue, durationOverride);
|
|
406
|
+
}
|
|
407
|
+
return animationValue ? `${key} ${animationValue}${delayStr}` : null;
|
|
408
|
+
}).filter(Boolean).join(", ");
|
|
409
|
+
if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
|
|
410
|
+
console.info("CSS animation", {
|
|
411
|
+
props,
|
|
412
|
+
animations,
|
|
413
|
+
normalized,
|
|
414
|
+
defaultAnimation,
|
|
415
|
+
style,
|
|
416
|
+
isEntering,
|
|
417
|
+
isExiting
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
161
421
|
style,
|
|
162
422
|
className: isEntering ? "t_unmounted" : ""
|
|
163
423
|
};
|