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