@tamagui/animations-css 2.7.7 → 3.0.0-beta.643.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,404 +1,357 @@
1
- import { normalizeTransition, getAnimatedProperties, hasAnimation as hasNormalizedAnimation, getEffectiveAnimation, getAnimationConfigsForKeys } from "@tamagui/animation-helpers";
1
+ import { getAnimatedProperties, getEffectiveAnimation, hasAnimation, normalizeTransition } from "@tamagui/animation-helpers";
2
2
  import { useIsomorphicLayoutEffect } from "@tamagui/constants";
3
3
  import { ResetPresence, usePresence } from "@tamagui/use-presence";
4
4
  import { transformsToString } from "@tamagui/web";
5
5
  import React from "react";
6
- const EXTRACT_MS_REGEX = /(\d+(?:\.\d+)?)\s*ms/;
7
- const EXTRACT_S_REGEX = /(\d+(?:\.\d+)?)\s*s/;
8
- function extractDuration(animation) {
9
- const msMatch = animation.match(EXTRACT_MS_REGEX);
10
- if (msMatch) {
11
- return Number.parseInt(msMatch[1], 10);
12
- }
13
- const sMatch = animation.match(EXTRACT_S_REGEX);
14
- if (sMatch) {
15
- return Math.round(Number.parseFloat(sMatch[1]) * 1e3);
16
- }
17
- return 300;
6
+ import { useAnimatedNumber, useAnimatedNumberReaction, useAnimatedNumberStyle, useAnimatedNumbersStyle } from "./animated-number.mjs";
7
+
8
+ const hasRAF = typeof requestAnimationFrame !== "undefined";
9
+ function waitForAnimations(node) {
10
+ if (typeof node.getAnimations !== "function") {
11
+ return Promise.resolve(true);
12
+ }
13
+ return new Promise((resolve) => {
14
+ const check = () => {
15
+ const animations = node.getAnimations();
16
+ if (animations.length === 0) {
17
+ resolve(true);
18
+ return;
19
+ }
20
+ Promise.all(animations.map((a) => a.finished)).then(() => resolve(true)).catch(() => {
21
+ const remaining = node.getAnimations();
22
+ if (remaining.some((a) => a.playState === "running" || a.pending)) {
23
+ check();
24
+ return;
25
+ }
26
+ resolve(false);
27
+ });
28
+ };
29
+ if (hasRAF) {
30
+ requestAnimationFrame(check);
31
+ } else {
32
+ check();
33
+ }
34
+ });
18
35
  }
19
- const MS_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*ms/;
20
- const S_DURATION_REGEX = /(\d+(?:\.\d+)?)\s*s(?!tiffness)/;
36
+ const DURATION_REGEX = /(\d+(?:\.\d+)?)\s*(?:ms|s(?!tiffness))/;
21
37
  function applyDurationOverride(animation, durationMs) {
22
- const msReplaced = animation.replace(MS_DURATION_REGEX, `${durationMs}ms`);
23
- if (msReplaced !== animation) {
24
- return msReplaced;
25
- }
26
- const sReplaced = animation.replace(S_DURATION_REGEX, `${durationMs}ms`);
27
- if (sReplaced !== animation) {
28
- return sReplaced;
29
- }
30
- return `${durationMs}ms ${animation}`;
38
+ const replaced = animation.replace(DURATION_REGEX, `${durationMs}ms`);
39
+ return replaced === animation ? `${durationMs}ms ${animation}` : replaced;
31
40
  }
32
- const TRANSFORM_KEYS = ["x", "y", "scale", "scaleX", "scaleY", "rotate", "rotateX", "rotateY", "rotateZ", "skewX", "skewY"];
33
- function buildTransformString(style) {
34
- if (!style) return "";
35
- const parts = [];
36
- if (style.x !== void 0 || style.y !== void 0) {
37
- const x = style.x ?? 0;
38
- const y = style.y ?? 0;
39
- parts.push(`translate(${x}px, ${y}px)`);
40
- }
41
- if (style.scale !== void 0) {
42
- parts.push(`scale(${style.scale})`);
43
- }
44
- if (style.scaleX !== void 0) {
45
- parts.push(`scaleX(${style.scaleX})`);
46
- }
47
- if (style.scaleY !== void 0) {
48
- parts.push(`scaleY(${style.scaleY})`);
49
- }
50
- if (style.rotate !== void 0) {
51
- const val = style.rotate;
52
- const unit = typeof val === "string" && val.includes("deg") ? "" : "deg";
53
- parts.push(`rotate(${val}${unit})`);
54
- }
55
- if (style.rotateX !== void 0) {
56
- parts.push(`rotateX(${style.rotateX}deg)`);
57
- }
58
- if (style.rotateY !== void 0) {
59
- parts.push(`rotateY(${style.rotateY}deg)`);
60
- }
61
- if (style.rotateZ !== void 0) {
62
- parts.push(`rotateZ(${style.rotateZ}deg)`);
63
- }
64
- if (style.skewX !== void 0) {
65
- parts.push(`skewX(${style.skewX}deg)`);
66
- }
67
- if (style.skewY !== void 0) {
68
- parts.push(`skewY(${style.skewY}deg)`);
69
- }
70
- return parts.join(" ");
41
+ const CSS_TRANSFORM_PROPERTIES = {
42
+ transform: [
43
+ "translate",
44
+ "scale",
45
+ "rotate",
46
+ "transform"
47
+ ],
48
+ x: ["translate"],
49
+ y: ["translate"],
50
+ scale: ["scale"],
51
+ scaleX: ["scale"],
52
+ scaleY: ["scale"],
53
+ rotate: ["rotate"],
54
+ rotateX: ["transform"],
55
+ rotateY: ["transform"],
56
+ rotateZ: ["transform"],
57
+ skewX: ["transform"],
58
+ skewY: ["transform"]
59
+ };
60
+ const getCSSProperties = (key) => {
61
+ return CSS_TRANSFORM_PROPERTIES[key] || [key];
62
+ };
63
+ const hyphenatedPropertyCache = {};
64
+ const emptyProperties = [];
65
+ function hyphenateProperty(property) {
66
+ if (property.startsWith("--")) return property;
67
+ return hyphenatedPropertyCache[property] ||= property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
71
68
  }
72
- function applyStylesToNode(node, style) {
73
- if (!style) return;
74
- const transformStr = buildTransformString(style);
75
- if (transformStr) {
76
- node.style.transform = transformStr;
77
- }
78
- for (const [key, value] of Object.entries(style)) {
79
- if (TRANSFORM_KEYS.includes(key)) continue;
80
- if (value === void 0) continue;
81
- if (key === "opacity") {
82
- node.style.opacity = String(value);
83
- } else if (key === "backgroundColor") {
84
- node.style.backgroundColor = String(value);
85
- } else if (key === "color") {
86
- node.style.color = String(value);
87
- } else {
88
- node.style[key] = typeof value === "number" ? `${value}px` : String(value);
89
- }
90
- }
69
+ function getLifecycleCSSProperties(keys) {
70
+ if (!keys?.size) return emptyProperties;
71
+ const properties = /* @__PURE__ */ new Set();
72
+ for (const key of keys) {
73
+ for (const property of getCSSProperties(key)) {
74
+ properties.add(hyphenateProperty(property));
75
+ }
76
+ }
77
+ return [...properties].sort();
78
+ }
79
+ function readComputedProperties(node, properties) {
80
+ const computed = getComputedStyle(node);
81
+ const values = {};
82
+ for (const property of properties) {
83
+ const value = computed.getPropertyValue(property);
84
+ if (value) values[property] = value;
85
+ }
86
+ return values;
87
+ }
88
+ function applyCSSProperties(node, values) {
89
+ for (const property in values) {
90
+ node.style.setProperty(property, values[property]);
91
+ }
92
+ }
93
+ function clearCSSProperties(node, properties) {
94
+ for (const property of properties) {
95
+ node.style.removeProperty(property);
96
+ }
91
97
  }
92
98
  function createAnimations(animations) {
93
- const reactionListeners = /* @__PURE__ */new WeakMap();
94
- return {
95
- animations,
96
- usePresence,
97
- ResetPresence,
98
- inputStyle: "css",
99
- outputStyle: "css",
100
- useAnimatedNumber(initial) {
101
- const [val, setVal] = React.useState(initial);
102
- const finishTimerRef = React.useRef(null);
103
- return {
104
- getInstance() {
105
- return setVal;
106
- },
107
- getValue() {
108
- return val;
109
- },
110
- setValue(next, config, onFinish) {
111
- setVal(next);
112
- if (finishTimerRef.current) {
113
- clearTimeout(finishTimerRef.current);
114
- finishTimerRef.current = null;
115
- }
116
- if (onFinish) {
117
- if (!config || config.type === "direct" || config.type === "timing" && config.duration === 0) {
118
- onFinish();
119
- } else {
120
- const duration = config.type === "timing" ? config.duration : 300;
121
- finishTimerRef.current = setTimeout(onFinish, duration);
122
- }
123
- }
124
- const listeners = reactionListeners.get(setVal);
125
- if (listeners) {
126
- listeners.forEach(listener => listener(next));
127
- }
128
- },
129
- stop() {
130
- if (finishTimerRef.current) {
131
- clearTimeout(finishTimerRef.current);
132
- finishTimerRef.current = null;
133
- }
134
- }
135
- };
136
- },
137
- useAnimatedNumberReaction({
138
- value
139
- }, onValue) {
140
- React.useEffect(() => {
141
- const instance = value.getInstance();
142
- let queue = reactionListeners.get(instance);
143
- if (!queue) {
144
- const next = /* @__PURE__ */new Set();
145
- reactionListeners.set(instance, next);
146
- queue = next;
147
- }
148
- queue.add(onValue);
149
- return () => {
150
- queue?.delete(onValue);
151
- };
152
- }, []);
153
- },
154
- useAnimatedNumberStyle(val, getStyle) {
155
- return getStyle(val.getValue());
156
- },
157
- useAnimatedNumbersStyle(vals, getStyle) {
158
- return getStyle(...vals.map(v => v.getValue()));
159
- },
160
- // @ts-ignore - styleState is added by createComponent
161
- useAnimations: ({
162
- props,
163
- presence,
164
- style,
165
- componentState,
166
- stateRef,
167
- styleState
168
- }) => {
169
- const isHydrating = componentState.unmounted === true;
170
- const isEntering = !!componentState.unmounted;
171
- const isExiting = presence?.[0] === false;
172
- const sendExitComplete = presence?.[1];
173
- const wasEnteringRef = React.useRef(isEntering);
174
- const justFinishedEntering = wasEnteringRef.current && !isEntering;
175
- React.useEffect(() => {
176
- wasEnteringRef.current = isEntering;
177
- });
178
- const exitCycleIdRef = React.useRef(0);
179
- const exitCompletedRef = React.useRef(false);
180
- const wasExitingRef = React.useRef(false);
181
- const exitInterruptedRef = React.useRef(false);
182
- const sendExitCompleteRef = React.useRef(sendExitComplete);
183
- const lastNonExitingStyleRef = React.useRef({});
184
- sendExitCompleteRef.current = sendExitComplete;
185
- const justStartedExiting = isExiting && !wasExitingRef.current;
186
- const justStoppedExiting = !isExiting && wasExitingRef.current;
187
- if (justStartedExiting) {
188
- exitCycleIdRef.current++;
189
- exitCompletedRef.current = false;
190
- }
191
- if (justStoppedExiting) {
192
- exitCycleIdRef.current++;
193
- exitInterruptedRef.current = true;
194
- }
195
- React.useEffect(() => {
196
- wasExitingRef.current = isExiting;
197
- });
198
- useIsomorphicLayoutEffect(() => {
199
- const host = stateRef.current.host;
200
- if (isExiting || !host) return;
201
- const computedStyle = getComputedStyle(host);
202
- lastNonExitingStyleRef.current = {
203
- opacity: computedStyle.opacity
204
- };
205
- });
206
- const effectiveTransition = styleState?.effectiveTransition ?? props.transition;
207
- const normalized = normalizeTransition(effectiveTransition);
208
- const animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default";
209
- const effectiveAnimationKey = getEffectiveAnimation(normalized, animationState);
210
- const defaultAnimation = effectiveAnimationKey ? animations[effectiveAnimationKey] : null;
211
- const animatedProperties = getAnimatedProperties(normalized);
212
- const hasDefault = normalized.default !== null || normalized.enter !== null || normalized.exit !== null;
213
- const hasPerPropertyConfigs = animatedProperties.length > 0;
214
- let keys;
215
- if (props.animateOnly) {
216
- keys = props.animateOnly;
217
- } else if (hasPerPropertyConfigs && !hasDefault) {
218
- keys = animatedProperties;
219
- } else if (hasPerPropertyConfigs && hasDefault) {
220
- keys = ["all", ...animatedProperties];
221
- } else {
222
- keys = ["all"];
223
- }
224
- useIsomorphicLayoutEffect(() => {
225
- const host = stateRef.current.host;
226
- if (!sendExitComplete || !isExiting || !host) return;
227
- const node = host;
228
- const cycleId = exitCycleIdRef.current;
229
- const completeExit = () => {
230
- if (cycleId !== exitCycleIdRef.current) return;
231
- if (exitCompletedRef.current) return;
232
- exitCompletedRef.current = true;
233
- sendExitCompleteRef.current?.();
234
- };
235
- if (keys.length === 0) {
236
- completeExit();
237
- return;
238
- }
239
- let rafId;
240
- const wasInterrupted = exitInterruptedRef.current;
241
- let ignoreCancelEvents = wasInterrupted;
242
- const enterStyle = props.enterStyle;
243
- const exitStyle = props.exitStyle;
244
- const delayStr2 = normalized.delay ? ` ${normalized.delay}ms` : "";
245
- const durationOverride2 = normalized.config?.duration;
246
- const exitTransitionString = keys.map(key => {
247
- const propAnimation = normalized.properties[key];
248
- let animationValue = null;
249
- if (typeof propAnimation === "string") {
250
- animationValue = animations[propAnimation];
251
- } else if (propAnimation && typeof propAnimation === "object" && propAnimation.type) {
252
- animationValue = animations[propAnimation.type];
253
- } else if (defaultAnimation) {
254
- animationValue = defaultAnimation;
255
- }
256
- if (animationValue && durationOverride2) {
257
- animationValue = applyDurationOverride(animationValue, durationOverride2);
258
- }
259
- return animationValue ? `${key} ${animationValue}${delayStr2}` : null;
260
- }).filter(Boolean).join(", ");
261
- const getResetValue = key => {
262
- if (key === "opacity") {
263
- return style?.opacity ?? props.opacity ?? lastNonExitingStyleRef.current.opacity ?? 1;
264
- }
265
- if (TRANSFORM_KEYS.includes(key)) {
266
- return key === "scale" || key === "scaleX" || key === "scaleY" ? 1 : 0;
267
- }
268
- return enterStyle?.[key];
269
- };
270
- if (wasInterrupted) {
271
- exitInterruptedRef.current = false;
272
- node.style.transition = "none";
273
- if (exitStyle) {
274
- const resetStyle = {};
275
- for (const key of Object.keys(exitStyle)) {
276
- const resetValue = getResetValue(key);
277
- if (resetValue !== void 0) {
278
- resetStyle[key] = resetValue;
279
- }
280
- }
281
- applyStylesToNode(node, resetStyle);
282
- } else {
283
- node.style.opacity = "1";
284
- node.style.transform = "none";
285
- }
286
- void node.offsetHeight;
287
- } else if (exitStyle) {
288
- ignoreCancelEvents = true;
289
- node.style.transition = "none";
290
- const resetStyle = {};
291
- for (const key of Object.keys(exitStyle)) {
292
- const resetValue = getResetValue(key);
293
- if (resetValue !== void 0) {
294
- resetStyle[key] = resetValue;
295
- }
296
- }
297
- applyStylesToNode(node, resetStyle);
298
- void node.offsetHeight;
299
- rafId = requestAnimationFrame(() => {
300
- if (cycleId !== exitCycleIdRef.current) return;
301
- node.style.transition = exitTransitionString;
302
- void node.offsetHeight;
303
- applyStylesToNode(node, exitStyle);
304
- ignoreCancelEvents = false;
305
- });
306
- }
307
- let maxDuration = defaultAnimation ? extractDuration(defaultAnimation) : 200;
308
- const animationConfigs = getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation);
309
- for (const animationValue of animationConfigs.values()) {
310
- if (animationValue) {
311
- const duration = extractDuration(animationValue);
312
- if (duration > maxDuration) {
313
- maxDuration = duration;
314
- }
315
- }
316
- }
317
- const delay = normalized.delay ?? 0;
318
- const fallbackTimeout = maxDuration + delay;
319
- const timeoutId = setTimeout(() => {
320
- completeExit();
321
- }, fallbackTimeout);
322
- const transitioningProps = new Set(keys);
323
- let completedCount = 0;
324
- const onFinishAnimation = event => {
325
- if (event.target !== node) return;
326
- const eventProp = event.propertyName;
327
- if (transitioningProps.has(eventProp) || eventProp === "all") {
328
- completedCount++;
329
- if (completedCount >= transitioningProps.size) {
330
- clearTimeout(timeoutId);
331
- completeExit();
332
- }
333
- }
334
- };
335
- const onCancelAnimation = () => {
336
- if (ignoreCancelEvents) return;
337
- clearTimeout(timeoutId);
338
- completeExit();
339
- };
340
- node.addEventListener("transitionend", onFinishAnimation);
341
- node.addEventListener("transitioncancel", onCancelAnimation);
342
- if (wasInterrupted) {
343
- rafId = requestAnimationFrame(() => {
344
- if (cycleId !== exitCycleIdRef.current) return;
345
- node.style.transition = exitTransitionString;
346
- void node.offsetHeight;
347
- applyStylesToNode(node, exitStyle);
348
- ignoreCancelEvents = false;
349
- });
350
- }
351
- return () => {
352
- clearTimeout(timeoutId);
353
- if (rafId !== void 0) cancelAnimationFrame(rafId);
354
- node.removeEventListener("transitionend", onFinishAnimation);
355
- node.removeEventListener("transitioncancel", onCancelAnimation);
356
- node.style.transition = "";
357
- };
358
- }, [isExiting]);
359
- if (isHydrating) {
360
- return null;
361
- }
362
- if (!hasNormalizedAnimation(normalized)) {
363
- return null;
364
- }
365
- if (Array.isArray(style.transform)) {
366
- style.transform = transformsToString(style.transform);
367
- }
368
- const delayStr = normalized.delay ? ` ${normalized.delay}ms` : "";
369
- const durationOverride = normalized.config?.duration;
370
- style.transition = keys.map(key => {
371
- const propAnimation = normalized.properties[key];
372
- let animationValue = null;
373
- if (typeof propAnimation === "string") {
374
- animationValue = animations[propAnimation];
375
- } else if (propAnimation && typeof propAnimation === "object" && propAnimation.type) {
376
- animationValue = animations[propAnimation.type];
377
- } else if (defaultAnimation) {
378
- animationValue = defaultAnimation;
379
- }
380
- if (animationValue && durationOverride) {
381
- animationValue = applyDurationOverride(animationValue, durationOverride);
382
- }
383
- return animationValue ? `${key} ${animationValue}${delayStr}` : null;
384
- }).filter(Boolean).join(", ");
385
- if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
386
- console.info("CSS animation", {
387
- props,
388
- animations,
389
- normalized,
390
- defaultAnimation,
391
- style,
392
- isEntering,
393
- isExiting
394
- });
395
- }
396
- return {
397
- style,
398
- className: isEntering ? "t_unmounted" : ""
399
- };
400
- }
401
- };
99
+ return {
100
+ animations,
101
+ usePresence,
102
+ ResetPresence,
103
+ inputStyle: "css",
104
+ outputStyle: "css",
105
+ useAnimatedNumber,
106
+ useAnimatedNumberReaction,
107
+ useAnimatedNumberStyle,
108
+ useAnimatedNumbersStyle,
109
+ useAnimations: ({ props, presence, style, componentState, stateRef, styleState, onTransition }) => {
110
+ const isHydrating = componentState.unmounted === true;
111
+ const isEntering = !!componentState.unmounted;
112
+ const isExiting = presence?.[0] === false;
113
+ const sendExitComplete = presence?.[1];
114
+ const onTransitionRef = React.useRef(onTransition);
115
+ onTransitionRef.current = onTransition;
116
+ const emit = (phase, cause, finished) => {
117
+ onTransitionRef.current?.(phase === "end" ? {
118
+ phase,
119
+ cause,
120
+ finished
121
+ } : {
122
+ phase,
123
+ cause
124
+ });
125
+ };
126
+ const wasEnteringRef = React.useRef(isEntering);
127
+ const justFinishedEntering = wasEnteringRef.current && !isEntering;
128
+ React.useEffect(() => {
129
+ wasEnteringRef.current = isEntering;
130
+ });
131
+ const exitCycleIdRef = React.useRef(0);
132
+ const exitCompletedRef = React.useRef(false);
133
+ const wasExitingRef = React.useRef(false);
134
+ const sendExitCompleteRef = React.useRef(sendExitComplete);
135
+ const lastMountedStyleRef = React.useRef({});
136
+ sendExitCompleteRef.current = sendExitComplete;
137
+ const exitCSSProperties = getLifecycleCSSProperties(styleState?.programLifecycleStyleKeys?.exit);
138
+ const exitCSSPropertiesSignature = exitCSSProperties.join("\0");
139
+ const enterCycleIdRef = React.useRef(0);
140
+ const enterStartedRef = React.useRef(false);
141
+ const updateCycleIdRef = React.useRef(0);
142
+ const updateInFlightRef = React.useRef(false);
143
+ const prevUpdateSigRef = React.useRef(null);
144
+ const exitStartedRef = React.useRef(false);
145
+ const justStartedExiting = isExiting && !wasExitingRef.current;
146
+ const justStoppedExiting = !isExiting && wasExitingRef.current;
147
+ if (justStartedExiting) {
148
+ exitCycleIdRef.current++;
149
+ exitCompletedRef.current = false;
150
+ }
151
+ if (justStoppedExiting) {
152
+ exitCycleIdRef.current++;
153
+ }
154
+ React.useEffect(() => {
155
+ wasExitingRef.current = isExiting;
156
+ });
157
+ useIsomorphicLayoutEffect(() => {
158
+ if (isExiting) return;
159
+ const host = stateRef.current.host;
160
+ if (!host || !exitCSSProperties.length) {
161
+ lastMountedStyleRef.current = {};
162
+ return;
163
+ }
164
+ const node = host;
165
+ const capture = () => {
166
+ if (stateRef.current.host !== node || wasExitingRef.current) return;
167
+ lastMountedStyleRef.current = readComputedProperties(node, exitCSSProperties);
168
+ };
169
+ if (justFinishedEntering) {
170
+ void waitForAnimations(node).then(capture);
171
+ } else {
172
+ capture();
173
+ }
174
+ }, [
175
+ isExiting,
176
+ justFinishedEntering,
177
+ exitCSSPropertiesSignature
178
+ ]);
179
+ const effectiveTransition = styleState?.effectiveTransition ?? props.transition;
180
+ const normalized = normalizeTransition(effectiveTransition);
181
+ const animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default";
182
+ const effectiveAnimationKey = getEffectiveAnimation(normalized, animationState);
183
+ const defaultAnimation = effectiveAnimationKey ? animations[effectiveAnimationKey] : null;
184
+ const animatedProperties = getAnimatedProperties(normalized);
185
+ const hasDefault = normalized.default !== null || normalized.enter !== null || normalized.exit !== null;
186
+ const hasPerPropertyConfigs = animatedProperties.length > 0;
187
+ let keys;
188
+ if (props.animateOnly) {
189
+ keys = props.animateOnly;
190
+ } else if (hasPerPropertyConfigs && !hasDefault) {
191
+ keys = animatedProperties;
192
+ } else if (hasPerPropertyConfigs && hasDefault) {
193
+ keys = ["all", ...animatedProperties];
194
+ } else {
195
+ keys = ["all"];
196
+ }
197
+ let transition;
198
+ const getTransition = () => {
199
+ if (transition !== void 0) return transition;
200
+ const delay = normalized.delay ? ` ${normalized.delay}ms` : "";
201
+ const duration = normalized.config?.duration;
202
+ transition = keys.flatMap((key) => {
203
+ const propertyAnimation = normalized.properties[key];
204
+ let animation = defaultAnimation;
205
+ if (typeof propertyAnimation === "string") {
206
+ animation = animations[propertyAnimation];
207
+ } else if (propertyAnimation?.type) {
208
+ animation = animations[propertyAnimation.type];
209
+ }
210
+ if (animation && duration) {
211
+ animation = applyDurationOverride(animation, duration);
212
+ }
213
+ return animation ? getCSSProperties(key).map((property) => `${property} ${animation}${delay}`) : [];
214
+ }).join(", ");
215
+ return transition;
216
+ };
217
+ useIsomorphicLayoutEffect(() => {
218
+ const host = stateRef.current.host;
219
+ if (!sendExitComplete || !isExiting || !host) return;
220
+ const node = host;
221
+ const cycleId = exitCycleIdRef.current;
222
+ if (!exitStartedRef.current) {
223
+ exitStartedRef.current = true;
224
+ emit("start", "exit");
225
+ }
226
+ const completeExit = (finished = true) => {
227
+ if (cycleId !== exitCycleIdRef.current) return;
228
+ if (exitCompletedRef.current) return;
229
+ exitCompletedRef.current = true;
230
+ if (exitStartedRef.current) {
231
+ exitStartedRef.current = false;
232
+ emit("end", "exit", finished);
233
+ }
234
+ sendExitCompleteRef.current?.();
235
+ };
236
+ if (keys.length === 0) {
237
+ completeExit();
238
+ return;
239
+ }
240
+ let rafId;
241
+ let disposed = false;
242
+ const mountedStyle = lastMountedStyleRef.current;
243
+ const canRestart = exitCSSProperties.length > 0 && Object.keys(mountedStyle).length > 0;
244
+ let exitTarget;
245
+ if (canRestart) {
246
+ node.style.transition = "none";
247
+ exitTarget = readComputedProperties(node, exitCSSProperties);
248
+ applyCSSProperties(node, mountedStyle);
249
+ void node.offsetHeight;
250
+ rafId = requestAnimationFrame(() => {
251
+ if (cycleId !== exitCycleIdRef.current) return;
252
+ node.style.transition = getTransition();
253
+ void node.offsetHeight;
254
+ applyCSSProperties(node, exitTarget);
255
+ });
256
+ }
257
+ void waitForAnimations(node).then((finished) => {
258
+ if (!disposed) completeExit(finished);
259
+ });
260
+ return () => {
261
+ disposed = true;
262
+ if (rafId !== void 0) cancelAnimationFrame(rafId);
263
+ clearCSSProperties(node, exitCSSProperties);
264
+ node.style.transition = "";
265
+ };
266
+ }, [isExiting, exitCSSPropertiesSignature]);
267
+ const styleSignature = onTransition ? (() => {
268
+ const { transition: _t, ...rest } = style;
269
+ return `${JSON.stringify(styleState?.classNames ?? null)}|${JSON.stringify(rest)}`;
270
+ })() : "";
271
+ useIsomorphicLayoutEffect(() => {
272
+ const host = stateRef.current.host;
273
+ if (!onTransitionRef.current || isExiting || !justFinishedEntering || !host) {
274
+ return;
275
+ }
276
+ const node = host;
277
+ const cycleId = ++enterCycleIdRef.current;
278
+ enterStartedRef.current = true;
279
+ emit("start", "enter");
280
+ void waitForAnimations(node).then((finished) => {
281
+ if (cycleId !== enterCycleIdRef.current || !enterStartedRef.current) return;
282
+ enterStartedRef.current = false;
283
+ emit("end", "enter", finished);
284
+ });
285
+ }, [justFinishedEntering, isExiting]);
286
+ useIsomorphicLayoutEffect(() => {
287
+ const host = stateRef.current.host;
288
+ if (!onTransitionRef.current || isEntering || justFinishedEntering || isExiting || !host) {
289
+ prevUpdateSigRef.current = styleSignature;
290
+ return;
291
+ }
292
+ if (prevUpdateSigRef.current === null) {
293
+ prevUpdateSigRef.current = styleSignature;
294
+ return;
295
+ }
296
+ if (styleSignature === prevUpdateSigRef.current) return;
297
+ prevUpdateSigRef.current = styleSignature;
298
+ const node = host;
299
+ if (updateInFlightRef.current) {
300
+ emit("end", "update", false);
301
+ }
302
+ updateInFlightRef.current = true;
303
+ const cycleId = ++updateCycleIdRef.current;
304
+ emit("start", "update");
305
+ void waitForAnimations(node).then((finished) => {
306
+ if (cycleId !== updateCycleIdRef.current) return;
307
+ updateInFlightRef.current = false;
308
+ emit("end", "update", finished);
309
+ });
310
+ }, [
311
+ styleSignature,
312
+ isEntering,
313
+ justFinishedEntering,
314
+ isExiting
315
+ ]);
316
+ useIsomorphicLayoutEffect(() => {
317
+ if (justStartedExiting && enterStartedRef.current) {
318
+ enterCycleIdRef.current++;
319
+ enterStartedRef.current = false;
320
+ emit("end", "enter", false);
321
+ }
322
+ if (justStoppedExiting && exitStartedRef.current && !exitCompletedRef.current) {
323
+ exitStartedRef.current = false;
324
+ emit("end", "exit", false);
325
+ }
326
+ }, [justStartedExiting, justStoppedExiting]);
327
+ if (isHydrating) {
328
+ return null;
329
+ }
330
+ if (!hasAnimation(normalized)) {
331
+ return null;
332
+ }
333
+ if (Array.isArray(style.transform)) {
334
+ style.transform = transformsToString(style.transform);
335
+ }
336
+ style.transition = getTransition();
337
+ if (process.env.NODE_ENV === "development" && props["debug"] === "verbose") {
338
+ console.info("CSS animation", {
339
+ props,
340
+ animations,
341
+ normalized,
342
+ defaultAnimation,
343
+ style,
344
+ isEntering,
345
+ isExiting
346
+ });
347
+ }
348
+ return {
349
+ style,
350
+ className: isEntering ? "t_unmounted" : ""
351
+ };
352
+ }
353
+ };
402
354
  }
355
+
403
356
  export { createAnimations };
404
357
  //# sourceMappingURL=createAnimations.mjs.map