@hanzogui/animations-css 3.0.6 → 4.3.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/createAnimations.cjs +305 -130
- package/dist/cjs/createAnimations.native.js +402 -217
- 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 +276 -103
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +373 -190
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/package.json +1 -1
- package/src/createAnimations.tsx +4 -0
- package/types/createAnimations.d.ts.map +1 -1
|
@@ -6,61 +6,111 @@ import React from "react";
|
|
|
6
6
|
function _type_of(obj) {
|
|
7
7
|
"@swc/helpers - typeof";
|
|
8
8
|
|
|
9
|
-
return obj && typeof Symbol
|
|
9
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
10
10
|
}
|
|
11
|
-
var EXTRACT_MS_REGEX = /(\d+(?:\.\d+)?)\s*ms
|
|
12
|
-
|
|
11
|
+
var EXTRACT_MS_REGEX = /(\d+(?:\.\d+)?)\s*ms/;
|
|
12
|
+
var EXTRACT_S_REGEX = /(\d+(?:\.\d+)?)\s*s/;
|
|
13
13
|
function extractDuration(animation) {
|
|
14
14
|
var msMatch = animation.match(EXTRACT_MS_REGEX);
|
|
15
|
-
if (msMatch)
|
|
15
|
+
if (msMatch) {
|
|
16
|
+
return Number.parseInt(msMatch[1], 10);
|
|
17
|
+
}
|
|
16
18
|
var sMatch = animation.match(EXTRACT_S_REGEX);
|
|
17
|
-
|
|
19
|
+
if (sMatch) {
|
|
20
|
+
return Math.round(Number.parseFloat(sMatch[1]) * 1e3);
|
|
21
|
+
}
|
|
22
|
+
return 300;
|
|
18
23
|
}
|
|
19
|
-
var MS_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*ms
|
|
20
|
-
|
|
24
|
+
var MS_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*ms/;
|
|
25
|
+
var S_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*s(?!tiffness)/;
|
|
21
26
|
function applyDurationOverride(animation, durationMs) {
|
|
22
27
|
var msReplaced = animation.replace(MS_DURATION_REGEX, `${durationMs}ms`);
|
|
23
|
-
if (msReplaced !== animation)
|
|
28
|
+
if (msReplaced !== animation) {
|
|
29
|
+
return msReplaced;
|
|
30
|
+
}
|
|
24
31
|
var sReplaced = animation.replace(S_DURATION_REGEX, `${durationMs}ms`);
|
|
25
|
-
|
|
32
|
+
if (sReplaced !== animation) {
|
|
33
|
+
return sReplaced;
|
|
34
|
+
}
|
|
35
|
+
return `${durationMs}ms ${animation}`;
|
|
26
36
|
}
|
|
27
37
|
var TRANSFORM_KEYS = ["x", "y", "scale", "scaleX", "scaleY", "rotate", "rotateX", "rotateY", "rotateZ", "skewX", "skewY"];
|
|
28
38
|
function buildTransformString(style) {
|
|
29
39
|
if (!style) return "";
|
|
30
40
|
var parts = [];
|
|
31
41
|
if (style.x !== void 0 || style.y !== void 0) {
|
|
32
|
-
var _style_x
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
var _style_x;
|
|
43
|
+
var x = (_style_x = style.x) !== null && _style_x !== void 0 ? _style_x : 0;
|
|
44
|
+
var _style_y;
|
|
45
|
+
var y = (_style_y = style.y) !== null && _style_y !== void 0 ? _style_y : 0;
|
|
36
46
|
parts.push(`translate(${x}px, ${y}px)`);
|
|
37
47
|
}
|
|
38
|
-
if (style.scale !== void 0
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
if (style.scale !== void 0) {
|
|
49
|
+
parts.push(`scale(${style.scale})`);
|
|
50
|
+
}
|
|
51
|
+
if (style.scaleX !== void 0) {
|
|
52
|
+
parts.push(`scaleX(${style.scaleX})`);
|
|
53
|
+
}
|
|
54
|
+
if (style.scaleY !== void 0) {
|
|
55
|
+
parts.push(`scaleY(${style.scaleY})`);
|
|
56
|
+
}
|
|
57
|
+
if (style.rotate !== void 0) {
|
|
58
|
+
var val = style.rotate;
|
|
59
|
+
var unit = typeof val === "string" && val.includes("deg") ? "" : "deg";
|
|
41
60
|
parts.push(`rotate(${val}${unit})`);
|
|
42
61
|
}
|
|
43
|
-
|
|
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(" ");
|
|
44
78
|
}
|
|
45
79
|
function applyStylesToNode(node, style) {
|
|
46
|
-
if (style)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
80
|
+
if (!style) return;
|
|
81
|
+
var transformStr = buildTransformString(style);
|
|
82
|
+
if (transformStr) {
|
|
83
|
+
node.style.transform = transformStr;
|
|
84
|
+
}
|
|
85
|
+
var _iteratorNormalCompletion = true,
|
|
86
|
+
_didIteratorError = false,
|
|
87
|
+
_iteratorError = void 0;
|
|
88
|
+
try {
|
|
89
|
+
for (var _iterator = Object.entries(style)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
90
|
+
var [key, value] = _step.value;
|
|
91
|
+
if (TRANSFORM_KEYS.includes(key)) continue;
|
|
92
|
+
if (value === void 0) continue;
|
|
93
|
+
if (key === "opacity") {
|
|
94
|
+
node.style.opacity = String(value);
|
|
95
|
+
} else if (key === "backgroundColor") {
|
|
96
|
+
node.style.backgroundColor = String(value);
|
|
97
|
+
} else if (key === "color") {
|
|
98
|
+
node.style.color = String(value);
|
|
99
|
+
} else {
|
|
100
|
+
node.style[key] = typeof value === "number" ? `${value}px` : String(value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
_didIteratorError = true;
|
|
105
|
+
_iteratorError = err;
|
|
106
|
+
} finally {
|
|
52
107
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
TRANSFORM_KEYS.includes(key) || value !== void 0 && (key === "opacity" ? node.style.opacity = String(value) : key === "backgroundColor" ? node.style.backgroundColor = String(value) : key === "color" ? node.style.color = String(value) : node.style[key] = typeof value == "number" ? `${value}px` : String(value));
|
|
108
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
109
|
+
_iterator.return();
|
|
56
110
|
}
|
|
57
|
-
} catch (err) {
|
|
58
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
59
111
|
} finally {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} finally {
|
|
63
|
-
if (_didIteratorError) throw _iteratorError;
|
|
112
|
+
if (_didIteratorError) {
|
|
113
|
+
throw _iteratorError;
|
|
64
114
|
}
|
|
65
115
|
}
|
|
66
116
|
}
|
|
@@ -74,8 +124,8 @@ function createAnimations(animations) {
|
|
|
74
124
|
inputStyle: "css",
|
|
75
125
|
outputStyle: "css",
|
|
76
126
|
useAnimatedNumber(initial) {
|
|
77
|
-
var [val, setVal] = React.useState(initial)
|
|
78
|
-
|
|
127
|
+
var [val, setVal] = React.useState(initial);
|
|
128
|
+
var finishTimerRef = React.useRef(null);
|
|
79
129
|
return {
|
|
80
130
|
getInstance() {
|
|
81
131
|
return setVal;
|
|
@@ -84,17 +134,31 @@ function createAnimations(animations) {
|
|
|
84
134
|
return val;
|
|
85
135
|
},
|
|
86
136
|
setValue(next, config, onFinish) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
finishTimerRef.current
|
|
137
|
+
setVal(next);
|
|
138
|
+
if (finishTimerRef.current) {
|
|
139
|
+
clearTimeout(finishTimerRef.current);
|
|
140
|
+
finishTimerRef.current = null;
|
|
141
|
+
}
|
|
142
|
+
if (onFinish) {
|
|
143
|
+
if (!config || config.type === "direct" || config.type === "timing" && config.duration === 0) {
|
|
144
|
+
onFinish();
|
|
145
|
+
} else {
|
|
146
|
+
var duration = config.type === "timing" ? config.duration : 300;
|
|
147
|
+
finishTimerRef.current = setTimeout(onFinish, duration);
|
|
148
|
+
}
|
|
90
149
|
}
|
|
91
150
|
var listeners = reactionListeners.get(setVal);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
151
|
+
if (listeners) {
|
|
152
|
+
listeners.forEach(function (listener) {
|
|
153
|
+
return listener(next);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
95
156
|
},
|
|
96
157
|
stop() {
|
|
97
|
-
|
|
158
|
+
if (finishTimerRef.current) {
|
|
159
|
+
clearTimeout(finishTimerRef.current);
|
|
160
|
+
finishTimerRef.current = null;
|
|
161
|
+
}
|
|
98
162
|
}
|
|
99
163
|
};
|
|
100
164
|
},
|
|
@@ -103,193 +167,312 @@ function createAnimations(animations) {
|
|
|
103
167
|
value
|
|
104
168
|
} = param;
|
|
105
169
|
React.useEffect(function () {
|
|
106
|
-
var instance = value.getInstance()
|
|
107
|
-
|
|
170
|
+
var instance = value.getInstance();
|
|
171
|
+
var queue = reactionListeners.get(instance);
|
|
108
172
|
if (!queue) {
|
|
109
173
|
var next = /* @__PURE__ */new Set();
|
|
110
|
-
reactionListeners.set(instance, next)
|
|
174
|
+
reactionListeners.set(instance, next);
|
|
175
|
+
queue = next;
|
|
111
176
|
}
|
|
112
|
-
|
|
113
|
-
|
|
177
|
+
queue.add(onValue);
|
|
178
|
+
return function () {
|
|
179
|
+
queue === null || queue === void 0 ? void 0 : queue.delete(onValue);
|
|
114
180
|
};
|
|
115
181
|
}, []);
|
|
116
182
|
},
|
|
117
183
|
useAnimatedNumberStyle(val, getStyle) {
|
|
118
184
|
return getStyle(val.getValue());
|
|
119
185
|
},
|
|
186
|
+
useAnimatedNumbersStyle(vals, getStyle) {
|
|
187
|
+
return getStyle(...vals.map(function (v) {
|
|
188
|
+
return v.getValue();
|
|
189
|
+
}));
|
|
190
|
+
},
|
|
120
191
|
// @ts-ignore - styleState is added by createComponent
|
|
121
192
|
useAnimations: function (param) {
|
|
122
193
|
var {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
194
|
+
props,
|
|
195
|
+
presence,
|
|
196
|
+
style,
|
|
197
|
+
componentState,
|
|
198
|
+
stateRef,
|
|
199
|
+
styleState
|
|
200
|
+
} = param;
|
|
201
|
+
var _normalized_config;
|
|
202
|
+
var isHydrating = componentState.unmounted === true;
|
|
203
|
+
var isEntering = !!componentState.unmounted;
|
|
204
|
+
var isExiting = (presence === null || presence === void 0 ? void 0 : presence[0]) === false;
|
|
205
|
+
var sendExitComplete = presence === null || presence === void 0 ? void 0 : presence[1];
|
|
206
|
+
var wasEnteringRef = React.useRef(isEntering);
|
|
207
|
+
var justFinishedEntering = wasEnteringRef.current && !isEntering;
|
|
137
208
|
React.useEffect(function () {
|
|
138
209
|
wasEnteringRef.current = isEntering;
|
|
139
210
|
});
|
|
140
|
-
var exitCycleIdRef = React.useRef(0)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
211
|
+
var exitCycleIdRef = React.useRef(0);
|
|
212
|
+
var exitCompletedRef = React.useRef(false);
|
|
213
|
+
var wasExitingRef = React.useRef(false);
|
|
214
|
+
var exitInterruptedRef = React.useRef(false);
|
|
215
|
+
var justStartedExiting = isExiting && !wasExitingRef.current;
|
|
216
|
+
var justStoppedExiting = !isExiting && wasExitingRef.current;
|
|
217
|
+
if (justStartedExiting) {
|
|
218
|
+
exitCycleIdRef.current++;
|
|
219
|
+
exitCompletedRef.current = false;
|
|
220
|
+
}
|
|
221
|
+
if (justStoppedExiting) {
|
|
222
|
+
exitCycleIdRef.current++;
|
|
223
|
+
exitInterruptedRef.current = true;
|
|
224
|
+
}
|
|
225
|
+
React.useEffect(function () {
|
|
147
226
|
wasExitingRef.current = isExiting;
|
|
148
227
|
});
|
|
149
|
-
var _styleState_effectiveTransition
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (props.animateOnly
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
228
|
+
var _styleState_effectiveTransition;
|
|
229
|
+
var effectiveTransition = (_styleState_effectiveTransition = styleState === null || styleState === void 0 ? void 0 : styleState.effectiveTransition) !== null && _styleState_effectiveTransition !== void 0 ? _styleState_effectiveTransition : props.transition;
|
|
230
|
+
var normalized = normalizeTransition(effectiveTransition);
|
|
231
|
+
var animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default";
|
|
232
|
+
var effectiveAnimationKey = getEffectiveAnimation(normalized, animationState);
|
|
233
|
+
var defaultAnimation = effectiveAnimationKey ? animations[effectiveAnimationKey] : null;
|
|
234
|
+
var animatedProperties = getAnimatedProperties(normalized);
|
|
235
|
+
var hasDefault = normalized.default !== null || normalized.enter !== null || normalized.exit !== null;
|
|
236
|
+
var hasPerPropertyConfigs = animatedProperties.length > 0;
|
|
237
|
+
var keys;
|
|
238
|
+
if (props.animateOnly) {
|
|
239
|
+
keys = props.animateOnly;
|
|
240
|
+
} else if (hasPerPropertyConfigs && !hasDefault) {
|
|
241
|
+
keys = animatedProperties;
|
|
242
|
+
} else if (hasPerPropertyConfigs && hasDefault) {
|
|
243
|
+
keys = ["all", ...animatedProperties];
|
|
244
|
+
} else {
|
|
245
|
+
keys = ["all"];
|
|
246
|
+
}
|
|
247
|
+
useIsomorphicLayoutEffect(function () {
|
|
248
|
+
var _normalized_config2;
|
|
249
|
+
var host = stateRef.current.host;
|
|
250
|
+
if (!sendExitComplete || !isExiting || !host) return;
|
|
251
|
+
var node = host;
|
|
252
|
+
var cycleId = exitCycleIdRef.current;
|
|
253
|
+
var completeExit = function () {
|
|
254
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
255
|
+
if (exitCompletedRef.current) return;
|
|
256
|
+
exitCompletedRef.current = true;
|
|
257
|
+
sendExitComplete();
|
|
258
|
+
};
|
|
259
|
+
if (keys.length === 0) {
|
|
260
|
+
completeExit();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
var rafId;
|
|
264
|
+
var wasInterrupted = exitInterruptedRef.current;
|
|
265
|
+
var ignoreCancelEvents = wasInterrupted;
|
|
266
|
+
var enterStyle = props.enterStyle;
|
|
267
|
+
var exitStyle = props.exitStyle;
|
|
268
|
+
var delayStr2 = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
269
|
+
var durationOverride2 = (_normalized_config2 = normalized.config) === null || _normalized_config2 === void 0 ? void 0 : _normalized_config2.duration;
|
|
270
|
+
var exitTransitionString = keys.map(function (key2) {
|
|
271
|
+
var propAnimation = normalized.properties[key2];
|
|
272
|
+
var animationValue2 = null;
|
|
273
|
+
if (typeof propAnimation === "string") {
|
|
274
|
+
animationValue2 = animations[propAnimation];
|
|
275
|
+
} else if (propAnimation && (typeof propAnimation === "undefined" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type) {
|
|
276
|
+
animationValue2 = animations[propAnimation.type];
|
|
277
|
+
} else if (defaultAnimation) {
|
|
278
|
+
animationValue2 = defaultAnimation;
|
|
171
279
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (exitInterruptedRef.current = !1, node.style.transition = "none", exitStyle) {
|
|
186
|
-
var resetStyle = {},
|
|
187
|
-
_iteratorNormalCompletion = !0,
|
|
188
|
-
_didIteratorError = !1,
|
|
189
|
-
_iteratorError = void 0;
|
|
190
|
-
try {
|
|
191
|
-
for (var _iterator = Object.keys(exitStyle)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
192
|
-
var key = _step.value;
|
|
193
|
-
key === "opacity" ? resetStyle[key] = 1 : TRANSFORM_KEYS.includes(key) ? resetStyle[key] = key === "scale" || key === "scaleX" || key === "scaleY" ? 1 : 0 : enterStyle?.[key] !== void 0 && (resetStyle[key] = enterStyle[key]);
|
|
194
|
-
}
|
|
195
|
-
} catch (err) {
|
|
196
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
197
|
-
} finally {
|
|
198
|
-
try {
|
|
199
|
-
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
200
|
-
} finally {
|
|
201
|
-
if (_didIteratorError) throw _iteratorError;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
applyStylesToNode(node, resetStyle);
|
|
205
|
-
} else node.style.opacity = "1", node.style.transform = "none";
|
|
206
|
-
node.offsetHeight;
|
|
207
|
-
} else if (exitStyle) {
|
|
208
|
-
ignoreCancelEvents = !0, node.style.transition = "none";
|
|
209
|
-
var resetStyle1 = {},
|
|
210
|
-
_iteratorNormalCompletion1 = !0,
|
|
211
|
-
_didIteratorError1 = !1,
|
|
212
|
-
_iteratorError1 = void 0;
|
|
280
|
+
if (animationValue2 && durationOverride2) {
|
|
281
|
+
animationValue2 = applyDurationOverride(animationValue2, durationOverride2);
|
|
282
|
+
}
|
|
283
|
+
return animationValue2 ? `${key2} ${animationValue2}${delayStr2}` : null;
|
|
284
|
+
}).filter(Boolean).join(", ");
|
|
285
|
+
if (wasInterrupted) {
|
|
286
|
+
exitInterruptedRef.current = false;
|
|
287
|
+
node.style.transition = "none";
|
|
288
|
+
if (exitStyle) {
|
|
289
|
+
var resetStyle = {};
|
|
290
|
+
var _iteratorNormalCompletion = true,
|
|
291
|
+
_didIteratorError = false,
|
|
292
|
+
_iteratorError = void 0;
|
|
213
293
|
try {
|
|
214
|
-
for (var
|
|
215
|
-
var
|
|
216
|
-
|
|
294
|
+
for (var _iterator = Object.keys(exitStyle)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
295
|
+
var key = _step.value;
|
|
296
|
+
if (key === "opacity") {
|
|
297
|
+
resetStyle[key] = 1;
|
|
298
|
+
} else if (TRANSFORM_KEYS.includes(key)) {
|
|
299
|
+
resetStyle[key] = key === "scale" || key === "scaleX" || key === "scaleY" ? 1 : 0;
|
|
300
|
+
} else if ((enterStyle === null || enterStyle === void 0 ? void 0 : enterStyle[key]) !== void 0) {
|
|
301
|
+
resetStyle[key] = enterStyle[key];
|
|
302
|
+
}
|
|
217
303
|
}
|
|
218
304
|
} catch (err) {
|
|
219
|
-
|
|
305
|
+
_didIteratorError = true;
|
|
306
|
+
_iteratorError = err;
|
|
220
307
|
} finally {
|
|
221
308
|
try {
|
|
222
|
-
!
|
|
309
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
310
|
+
_iterator.return();
|
|
311
|
+
}
|
|
223
312
|
} finally {
|
|
224
|
-
if (
|
|
313
|
+
if (_didIteratorError) {
|
|
314
|
+
throw _iteratorError;
|
|
315
|
+
}
|
|
225
316
|
}
|
|
226
317
|
}
|
|
227
|
-
applyStylesToNode(node,
|
|
228
|
-
|
|
229
|
-
|
|
318
|
+
applyStylesToNode(node, resetStyle);
|
|
319
|
+
} else {
|
|
320
|
+
node.style.opacity = "1";
|
|
321
|
+
node.style.transform = "none";
|
|
230
322
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
323
|
+
void node.offsetHeight;
|
|
324
|
+
} else if (exitStyle) {
|
|
325
|
+
ignoreCancelEvents = true;
|
|
326
|
+
node.style.transition = "none";
|
|
327
|
+
var resetStyle1 = {};
|
|
328
|
+
var _iteratorNormalCompletion1 = true,
|
|
329
|
+
_didIteratorError1 = false,
|
|
330
|
+
_iteratorError1 = void 0;
|
|
236
331
|
try {
|
|
237
|
-
for (var
|
|
238
|
-
var
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
|
|
332
|
+
for (var _iterator1 = Object.keys(exitStyle)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
333
|
+
var key1 = _step1.value;
|
|
334
|
+
if (key1 === "opacity") {
|
|
335
|
+
resetStyle1[key1] = 1;
|
|
336
|
+
} else if (TRANSFORM_KEYS.includes(key1)) {
|
|
337
|
+
resetStyle1[key1] = key1 === "scale" || key1 === "scaleX" || key1 === "scaleY" ? 1 : 0;
|
|
338
|
+
} else if ((enterStyle === null || enterStyle === void 0 ? void 0 : enterStyle[key1]) !== void 0) {
|
|
339
|
+
resetStyle1[key1] = enterStyle[key1];
|
|
242
340
|
}
|
|
243
341
|
}
|
|
244
342
|
} catch (err) {
|
|
245
|
-
|
|
343
|
+
_didIteratorError1 = true;
|
|
344
|
+
_iteratorError1 = err;
|
|
246
345
|
} finally {
|
|
247
346
|
try {
|
|
248
|
-
!
|
|
347
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
348
|
+
_iterator1.return();
|
|
349
|
+
}
|
|
249
350
|
} finally {
|
|
250
|
-
if (
|
|
351
|
+
if (_didIteratorError1) {
|
|
352
|
+
throw _iteratorError1;
|
|
353
|
+
}
|
|
251
354
|
}
|
|
252
355
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
356
|
+
applyStylesToNode(node, resetStyle1);
|
|
357
|
+
void node.offsetHeight;
|
|
358
|
+
rafId = requestAnimationFrame(function () {
|
|
359
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
360
|
+
node.style.transition = exitTransitionString;
|
|
361
|
+
void node.offsetHeight;
|
|
362
|
+
applyStylesToNode(node, exitStyle);
|
|
363
|
+
ignoreCancelEvents = false;
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
var maxDuration = defaultAnimation ? extractDuration(defaultAnimation) : 200;
|
|
367
|
+
var animationConfigs = getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation);
|
|
368
|
+
var _iteratorNormalCompletion2 = true,
|
|
369
|
+
_didIteratorError2 = false,
|
|
370
|
+
_iteratorError2 = void 0;
|
|
371
|
+
try {
|
|
372
|
+
for (var _iterator2 = animationConfigs.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
373
|
+
var animationValue = _step2.value;
|
|
374
|
+
if (animationValue) {
|
|
375
|
+
var duration = extractDuration(animationValue);
|
|
376
|
+
if (duration > maxDuration) {
|
|
377
|
+
maxDuration = duration;
|
|
265
378
|
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
} catch (err) {
|
|
382
|
+
_didIteratorError2 = true;
|
|
383
|
+
_iteratorError2 = err;
|
|
384
|
+
} finally {
|
|
385
|
+
try {
|
|
386
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
387
|
+
_iterator2.return();
|
|
388
|
+
}
|
|
389
|
+
} finally {
|
|
390
|
+
if (_didIteratorError2) {
|
|
391
|
+
throw _iteratorError2;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
275
394
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
395
|
+
var _normalized_delay;
|
|
396
|
+
var delay = (_normalized_delay = normalized.delay) !== null && _normalized_delay !== void 0 ? _normalized_delay : 0;
|
|
397
|
+
var fallbackTimeout = maxDuration + delay;
|
|
398
|
+
var timeoutId = setTimeout(function () {
|
|
399
|
+
completeExit();
|
|
400
|
+
}, fallbackTimeout);
|
|
401
|
+
var transitioningProps = new Set(keys);
|
|
402
|
+
var completedCount = 0;
|
|
403
|
+
var onFinishAnimation = function (event) {
|
|
404
|
+
if (event.target !== node) return;
|
|
405
|
+
var eventProp = event.propertyName;
|
|
406
|
+
if (transitioningProps.has(eventProp) || eventProp === "all") {
|
|
407
|
+
completedCount++;
|
|
408
|
+
if (completedCount >= transitioningProps.size) {
|
|
409
|
+
clearTimeout(timeoutId);
|
|
410
|
+
completeExit();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
var onCancelAnimation = function () {
|
|
415
|
+
if (ignoreCancelEvents) return;
|
|
416
|
+
clearTimeout(timeoutId);
|
|
417
|
+
completeExit();
|
|
418
|
+
};
|
|
419
|
+
node.addEventListener("transitionend", onFinishAnimation);
|
|
420
|
+
node.addEventListener("transitioncancel", onCancelAnimation);
|
|
421
|
+
if (wasInterrupted) {
|
|
422
|
+
rafId = requestAnimationFrame(function () {
|
|
423
|
+
if (cycleId !== exitCycleIdRef.current) return;
|
|
424
|
+
node.style.transition = exitTransitionString;
|
|
425
|
+
void node.offsetHeight;
|
|
426
|
+
applyStylesToNode(node, exitStyle);
|
|
427
|
+
ignoreCancelEvents = false;
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
return function () {
|
|
431
|
+
clearTimeout(timeoutId);
|
|
432
|
+
if (rafId !== void 0) cancelAnimationFrame(rafId);
|
|
433
|
+
node.removeEventListener("transitionend", onFinishAnimation);
|
|
434
|
+
node.removeEventListener("transitioncancel", onCancelAnimation);
|
|
435
|
+
node.style.transition = "";
|
|
436
|
+
};
|
|
437
|
+
}, [sendExitComplete, isExiting, stateRef, keys, normalized, defaultAnimation, props.enterStyle, props.exitStyle]);
|
|
438
|
+
if (isHydrating) {
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
if (!hasNormalizedAnimation(normalized)) {
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
if (Array.isArray(style.transform)) {
|
|
445
|
+
style.transform = transformsToString(style.transform);
|
|
446
|
+
}
|
|
447
|
+
var delayStr = normalized.delay ? ` ${normalized.delay}ms` : "";
|
|
448
|
+
var durationOverride = (_normalized_config = normalized.config) === null || _normalized_config === void 0 ? void 0 : _normalized_config.duration;
|
|
449
|
+
style.transition = keys.map(function (key) {
|
|
450
|
+
var propAnimation = normalized.properties[key];
|
|
451
|
+
var animationValue = null;
|
|
452
|
+
if (typeof propAnimation === "string") {
|
|
453
|
+
animationValue = animations[propAnimation];
|
|
454
|
+
} else if (propAnimation && (typeof propAnimation === "undefined" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type) {
|
|
455
|
+
animationValue = animations[propAnimation.type];
|
|
456
|
+
} else if (defaultAnimation) {
|
|
457
|
+
animationValue = defaultAnimation;
|
|
458
|
+
}
|
|
459
|
+
if (animationValue && durationOverride) {
|
|
460
|
+
animationValue = applyDurationOverride(animationValue, durationOverride);
|
|
461
|
+
}
|
|
462
|
+
return animationValue ? `${key} ${animationValue}${delayStr}` : null;
|
|
463
|
+
}).filter(Boolean).join(", ");
|
|
464
|
+
if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
|
|
465
|
+
console.info("CSS animation", {
|
|
466
|
+
props,
|
|
467
|
+
animations,
|
|
468
|
+
normalized,
|
|
469
|
+
defaultAnimation,
|
|
470
|
+
style,
|
|
471
|
+
isEntering,
|
|
472
|
+
isExiting
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
293
476
|
style,
|
|
294
477
|
className: isEntering ? "t_unmounted" : ""
|
|
295
478
|
};
|