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