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