@hanzogui/animations-css 3.0.6 → 4.4.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.
@@ -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 < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
9
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
10
10
  }
11
- var EXTRACT_MS_REGEX = /(\d+(?:\.\d+)?)\s*ms/,
12
- EXTRACT_S_REGEX = /(\d+(?:\.\d+)?)\s*s/;
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) return Number.parseInt(msMatch[1], 10);
15
+ if (msMatch) {
16
+ return Number.parseInt(msMatch[1], 10);
17
+ }
16
18
  var sMatch = animation.match(EXTRACT_S_REGEX);
17
- return sMatch ? Math.round(Number.parseFloat(sMatch[1]) * 1e3) : 300;
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
- S_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*s(?!tiffness)/;
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) return msReplaced;
28
+ if (msReplaced !== animation) {
29
+ return msReplaced;
30
+ }
24
31
  var sReplaced = animation.replace(S_DURATION_REGEX, `${durationMs}ms`);
25
- return sReplaced !== animation ? sReplaced : `${durationMs}ms ${animation}`;
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
- x = (_style_x = style.x) !== null && _style_x !== void 0 ? _style_x : 0,
34
- _style_y,
35
- y = (_style_y = style.y) !== null && _style_y !== void 0 ? _style_y : 0;
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 && parts.push(`scale(${style.scale})`), style.scaleX !== void 0 && parts.push(`scaleX(${style.scaleX})`), style.scaleY !== void 0 && parts.push(`scaleY(${style.scaleY})`), style.rotate !== void 0) {
39
- var val = style.rotate,
40
- unit = typeof val == "string" && val.includes("deg") ? "" : "deg";
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
- return style.rotateX !== void 0 && parts.push(`rotateX(${style.rotateX}deg)`), style.rotateY !== void 0 && parts.push(`rotateY(${style.rotateY}deg)`), style.rotateZ !== void 0 && parts.push(`rotateZ(${style.rotateZ}deg)`), style.skewX !== void 0 && parts.push(`skewX(${style.skewX}deg)`), style.skewY !== void 0 && parts.push(`skewY(${style.skewY}deg)`), parts.join(" ");
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
- var transformStr = buildTransformString(style);
48
- transformStr && (node.style.transform = transformStr);
49
- var _iteratorNormalCompletion = !0,
50
- _didIteratorError = !1,
51
- _iteratorError = void 0;
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
- for (var _iterator = Object.entries(style)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
54
- var [key, value] = _step.value;
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
- try {
61
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
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
- finishTimerRef = React.useRef(null);
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
- if (setVal(next), finishTimerRef.current && (clearTimeout(finishTimerRef.current), finishTimerRef.current = null), onFinish) if (!config || config.type === "direct" || config.type === "timing" && config.duration === 0) onFinish();else {
88
- var duration = config.type === "timing" ? config.duration : 300;
89
- finishTimerRef.current = setTimeout(onFinish, duration);
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
- listeners && listeners.forEach(function (listener) {
93
- return listener(next);
94
- });
151
+ if (listeners) {
152
+ listeners.forEach(function (listener) {
153
+ return listener(next);
154
+ });
155
+ }
95
156
  },
96
157
  stop() {
97
- finishTimerRef.current && (clearTimeout(finishTimerRef.current), finishTimerRef.current = null);
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
- queue = reactionListeners.get(instance);
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), queue = next;
174
+ reactionListeners.set(instance, next);
175
+ queue = next;
111
176
  }
112
- return queue.add(onValue), function () {
113
- queue?.delete(onValue);
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
- props,
124
- presence,
125
- style,
126
- componentState,
127
- stateRef,
128
- styleState
129
- } = param,
130
- _normalized_config,
131
- isHydrating = componentState.unmounted === !0,
132
- isEntering = !!componentState.unmounted,
133
- isExiting = presence?.[0] === !1,
134
- sendExitComplete = presence?.[1],
135
- wasEnteringRef = React.useRef(isEntering),
136
- justFinishedEntering = wasEnteringRef.current && !isEntering;
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
- exitCompletedRef = React.useRef(!1),
142
- wasExitingRef = React.useRef(!1),
143
- exitInterruptedRef = React.useRef(!1),
144
- justStartedExiting = isExiting && !wasExitingRef.current,
145
- justStoppedExiting = !isExiting && wasExitingRef.current;
146
- justStartedExiting && (exitCycleIdRef.current++, exitCompletedRef.current = !1), justStoppedExiting && (exitCycleIdRef.current++, exitInterruptedRef.current = !0), React.useEffect(function () {
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
- effectiveTransition = (_styleState_effectiveTransition = styleState?.effectiveTransition) !== null && _styleState_effectiveTransition !== void 0 ? _styleState_effectiveTransition : props.transition,
151
- normalized = normalizeTransition(effectiveTransition),
152
- animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default",
153
- effectiveAnimationKey = getEffectiveAnimation(normalized, animationState),
154
- defaultAnimation = effectiveAnimationKey ? animations[effectiveAnimationKey] : null,
155
- animatedProperties = getAnimatedProperties(normalized),
156
- hasDefault = normalized.default !== null || normalized.enter !== null || normalized.exit !== null,
157
- hasPerPropertyConfigs = animatedProperties.length > 0,
158
- keys;
159
- if (props.animateOnly ? keys = props.animateOnly : hasPerPropertyConfigs && !hasDefault ? keys = animatedProperties : hasPerPropertyConfigs && hasDefault ? keys = ["all", ...animatedProperties] : keys = ["all"], useIsomorphicLayoutEffect(function () {
160
- var _normalized_config2,
161
- host = stateRef.current.host;
162
- if (!(!sendExitComplete || !isExiting || !host)) {
163
- var node = host,
164
- cycleId = exitCycleIdRef.current,
165
- completeExit = function () {
166
- cycleId === exitCycleIdRef.current && (exitCompletedRef.current || (exitCompletedRef.current = !0, sendExitComplete()));
167
- };
168
- if (keys.length === 0) {
169
- completeExit();
170
- return;
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
- var rafId,
173
- wasInterrupted = exitInterruptedRef.current,
174
- ignoreCancelEvents = wasInterrupted,
175
- enterStyle = props.enterStyle,
176
- exitStyle = props.exitStyle,
177
- delayStr2 = normalized.delay ? ` ${normalized.delay}ms` : "",
178
- durationOverride2 = (_normalized_config2 = normalized.config) === null || _normalized_config2 === void 0 ? void 0 : _normalized_config2.duration,
179
- exitTransitionString = keys.map(function (key2) {
180
- var propAnimation = normalized.properties[key2],
181
- animationValue2 = null;
182
- return typeof propAnimation == "string" ? animationValue2 = animations[propAnimation] : propAnimation && (typeof propAnimation > "u" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type ? animationValue2 = animations[propAnimation.type] : defaultAnimation && (animationValue2 = defaultAnimation), animationValue2 && durationOverride2 && (animationValue2 = applyDurationOverride(animationValue2, durationOverride2)), animationValue2 ? `${key2} ${animationValue2}${delayStr2}` : null;
183
- }).filter(Boolean).join(", ");
184
- if (wasInterrupted) {
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 _iterator1 = Object.keys(exitStyle)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
215
- var key1 = _step1.value;
216
- key1 === "opacity" ? resetStyle1[key1] = 1 : TRANSFORM_KEYS.includes(key1) ? resetStyle1[key1] = key1 === "scale" || key1 === "scaleX" || key1 === "scaleY" ? 1 : 0 : enterStyle?.[key1] !== void 0 && (resetStyle1[key1] = enterStyle[key1]);
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
- _didIteratorError1 = !0, _iteratorError1 = err;
305
+ _didIteratorError = true;
306
+ _iteratorError = err;
220
307
  } finally {
221
308
  try {
222
- !_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
309
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
310
+ _iterator.return();
311
+ }
223
312
  } finally {
224
- if (_didIteratorError1) throw _iteratorError1;
313
+ if (_didIteratorError) {
314
+ throw _iteratorError;
315
+ }
225
316
  }
226
317
  }
227
- applyStylesToNode(node, resetStyle1), node.offsetHeight, rafId = requestAnimationFrame(function () {
228
- cycleId === exitCycleIdRef.current && (node.style.transition = exitTransitionString, node.offsetHeight, applyStylesToNode(node, exitStyle), ignoreCancelEvents = !1);
229
- });
318
+ applyStylesToNode(node, resetStyle);
319
+ } else {
320
+ node.style.opacity = "1";
321
+ node.style.transform = "none";
230
322
  }
231
- var maxDuration = defaultAnimation ? extractDuration(defaultAnimation) : 200,
232
- animationConfigs = getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation),
233
- _iteratorNormalCompletion2 = !0,
234
- _didIteratorError2 = !1,
235
- _iteratorError2 = void 0;
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 _iterator2 = animationConfigs.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
238
- var animationValue = _step2.value;
239
- if (animationValue) {
240
- var duration = extractDuration(animationValue);
241
- duration > maxDuration && (maxDuration = duration);
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
- _didIteratorError2 = !0, _iteratorError2 = err;
343
+ _didIteratorError1 = true;
344
+ _iteratorError1 = err;
246
345
  } finally {
247
346
  try {
248
- !_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
347
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
348
+ _iterator1.return();
349
+ }
249
350
  } finally {
250
- if (_didIteratorError2) throw _iteratorError2;
351
+ if (_didIteratorError1) {
352
+ throw _iteratorError1;
353
+ }
251
354
  }
252
355
  }
253
- var _normalized_delay,
254
- delay = (_normalized_delay = normalized.delay) !== null && _normalized_delay !== void 0 ? _normalized_delay : 0,
255
- fallbackTimeout = maxDuration + delay,
256
- timeoutId = setTimeout(function () {
257
- completeExit();
258
- }, fallbackTimeout),
259
- transitioningProps = new Set(keys),
260
- completedCount = 0,
261
- onFinishAnimation = function (event) {
262
- if (event.target === node) {
263
- var eventProp = event.propertyName;
264
- (transitioningProps.has(eventProp) || eventProp === "all") && (completedCount++, completedCount >= transitioningProps.size && (clearTimeout(timeoutId), completeExit()));
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
- onCancelAnimation = function () {
268
- ignoreCancelEvents || (clearTimeout(timeoutId), completeExit());
269
- };
270
- return node.addEventListener("transitionend", onFinishAnimation), node.addEventListener("transitioncancel", onCancelAnimation), wasInterrupted && (rafId = requestAnimationFrame(function () {
271
- cycleId === exitCycleIdRef.current && (node.style.transition = exitTransitionString, node.offsetHeight, applyStylesToNode(node, exitStyle), ignoreCancelEvents = !1);
272
- })), function () {
273
- clearTimeout(timeoutId), rafId !== void 0 && cancelAnimationFrame(rafId), node.removeEventListener("transitionend", onFinishAnimation), node.removeEventListener("transitioncancel", onCancelAnimation), node.style.transition = "";
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
- }, [sendExitComplete, isExiting, stateRef, keys, normalized, defaultAnimation, props.enterStyle, props.exitStyle]), isHydrating || !hasNormalizedAnimation(normalized)) return null;
277
- Array.isArray(style.transform) && (style.transform = transformsToString(style.transform));
278
- var delayStr = normalized.delay ? ` ${normalized.delay}ms` : "",
279
- durationOverride = (_normalized_config = normalized.config) === null || _normalized_config === void 0 ? void 0 : _normalized_config.duration;
280
- return style.transition = keys.map(function (key) {
281
- var propAnimation = normalized.properties[key],
282
- animationValue = null;
283
- return typeof propAnimation == "string" ? animationValue = animations[propAnimation] : propAnimation && (typeof propAnimation > "u" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type ? animationValue = animations[propAnimation.type] : defaultAnimation && (animationValue = defaultAnimation), animationValue && durationOverride && (animationValue = applyDurationOverride(animationValue, durationOverride)), animationValue ? `${key} ${animationValue}${delayStr}` : null;
284
- }).filter(Boolean).join(", "), process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info("CSS animation", {
285
- props,
286
- animations,
287
- normalized,
288
- defaultAnimation,
289
- style,
290
- isEntering,
291
- isExiting
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
  };