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