@tamagui/animations-motion 2.0.0-rc.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/cjs/createAnimations.cjs +559 -299
  2. package/dist/cjs/createAnimations.native.js +653 -318
  3. package/dist/cjs/createAnimations.native.js.map +1 -1
  4. package/dist/cjs/index.cjs +7 -5
  5. package/dist/cjs/index.native.js +21 -13
  6. package/dist/cjs/index.native.js.map +1 -1
  7. package/dist/cjs/polyfill.cjs +3 -1
  8. package/dist/cjs/polyfill.native.js +3 -1
  9. package/dist/cjs/polyfill.native.js.map +1 -1
  10. package/dist/esm/createAnimations.mjs +529 -272
  11. package/dist/esm/createAnimations.mjs.map +1 -1
  12. package/dist/esm/createAnimations.native.js +623 -291
  13. package/dist/esm/createAnimations.native.js.map +1 -1
  14. package/dist/esm/index.js +1 -2
  15. package/dist/esm/index.js.map +1 -6
  16. package/dist/esm/index.mjs +0 -1
  17. package/dist/esm/index.mjs.map +1 -1
  18. package/dist/esm/index.native.js +9 -3
  19. package/dist/esm/index.native.js.map +1 -1
  20. package/dist/esm/polyfill.mjs +3 -1
  21. package/dist/esm/polyfill.mjs.map +1 -1
  22. package/dist/esm/polyfill.native.js +3 -1
  23. package/dist/esm/polyfill.native.js.map +1 -1
  24. package/package.json +9 -12
  25. package/src/createAnimations.tsx +469 -351
  26. package/types/createAnimations.d.ts +1 -0
  27. package/types/createAnimations.d.ts.map +4 -4
  28. package/types/index.d.ts.map +2 -2
  29. package/types/index.native.d.ts.map +2 -2
  30. package/types/polyfill.d.ts.map +2 -2
  31. package/dist/cjs/createAnimations.js +0 -412
  32. package/dist/cjs/createAnimations.js.map +0 -6
  33. package/dist/cjs/index.js +0 -16
  34. package/dist/cjs/index.js.map +0 -6
  35. package/dist/cjs/polyfill.js +0 -2
  36. package/dist/cjs/polyfill.js.map +0 -6
  37. package/dist/esm/createAnimations.js +0 -416
  38. package/dist/esm/createAnimations.js.map +0 -6
  39. package/dist/esm/polyfill.js +0 -2
  40. package/dist/esm/polyfill.js.map +0 -6
@@ -4,246 +4,383 @@ var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf,
8
- __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __getProtoOf = Object.getPrototypeOf;
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: !0
13
- });
14
- },
15
- __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
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, {
17
18
  get: () => from[key],
18
19
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
20
  });
20
- return to;
21
- };
21
+ }
22
+ return to;
23
+ };
22
24
  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: !0
30
- }) : target, mod)),
31
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: !0
33
- }), mod);
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
32
+ }) : target, mod));
33
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
+ value: true
35
+ }), mod);
34
36
  var createAnimations_exports = {};
35
37
  __export(createAnimations_exports, {
36
- createAnimations: () => createAnimations
38
+ createAnimations: () => createAnimations,
39
+ disableAnimationProps: () => disableAnimationProps
37
40
  });
38
41
  module.exports = __toCommonJS(createAnimations_exports);
39
- var import_jsx_runtime = require("react/jsx-runtime"),
40
- import_animation_helpers = require("@tamagui/animation-helpers"),
41
- import_use_presence = require("@tamagui/use-presence"),
42
- import_web = require("@tamagui/web"),
43
- import_react = require("motion/react"),
44
- import_react2 = __toESM(require("react"), 1);
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ var import_animation_helpers = require("@tamagui/animation-helpers");
44
+ var import_use_presence = require("@tamagui/use-presence");
45
+ var import_web = require("@tamagui/web");
46
+ var import_react = require("motion/react");
47
+ var import_react2 = __toESM(require("react"), 1);
45
48
  function _instanceof(left, right) {
46
- return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
49
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
50
+ return !!right[Symbol.hasInstance](left);
51
+ } else {
52
+ return left instanceof right;
53
+ }
47
54
  }
48
55
  function _type_of(obj) {
49
56
  "@swc/helpers - typeof";
50
57
 
51
- return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
58
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
59
+ }
60
+ var isServer = typeof window === "undefined";
61
+ function useAnimateSSRSafe() {
62
+ if (isServer) {
63
+ return [(0, import_react2.useRef)(null), function () {}];
64
+ }
65
+ return (0, import_react.useAnimate)();
66
+ }
67
+ var MotionValueStrategy = /* @__PURE__ */new WeakMap();
68
+ var PendingMotionOnFinish = /* @__PURE__ */new WeakMap();
69
+ function settlePendingMotionOnFinish(mv, controls) {
70
+ var onFinish = PendingMotionOnFinish.get(mv);
71
+ if (!onFinish) return;
72
+ PendingMotionOnFinish.delete(mv);
73
+ controls.then(function () {
74
+ return onFinish();
75
+ }).catch(function () {
76
+ return onFinish();
77
+ });
52
78
  }
53
- var MotionValueStrategy = /* @__PURE__ */new WeakMap(),
54
- nonPositionTransformRe = /scale|rotate|skew|matrix|perspective/;
55
79
  function createAnimations(animations) {
56
- var isHydratingGlobal,
57
- hydratingComponents = /* @__PURE__ */new Set();
80
+ var isHydratingGlobal;
81
+ var hydratingComponents = /* @__PURE__ */new Set();
58
82
  return {
59
- // this is only used by Sheet basically for now to pass result of useAnimatedStyle to
60
83
  View: MotionView,
61
84
  Text: MotionText,
62
- isReactNative: !1,
63
- supportsCSS: !0,
85
+ isReactNative: false,
64
86
  inputStyle: "css",
65
87
  outputStyle: "inline",
66
- needsWebStyles: !0,
67
- avoidReRenders: !0,
88
+ avoidReRenders: true,
68
89
  animations,
69
90
  usePresence: import_use_presence.usePresence,
70
91
  ResetPresence: import_use_presence.ResetPresence,
71
92
  onMount() {
72
- isHydratingGlobal = !1, hydratingComponents.forEach(function (cb) {
93
+ isHydratingGlobal = false;
94
+ hydratingComponents.forEach(function (cb) {
73
95
  return cb();
74
96
  });
75
97
  },
76
98
  useAnimations: function (animationProps) {
77
- isHydratingGlobal === void 0 && !(0, import_web.getConfig)().settings.disableSSR && (isHydratingGlobal = !0);
99
+ if (isHydratingGlobal === void 0 && !(0, import_web.getConfig)().settings.disableSSR) {
100
+ isHydratingGlobal = true;
101
+ }
78
102
  var {
79
- props,
80
- style,
81
- componentState,
82
- stateRef,
83
- useStyleEmitter,
84
- presence
85
- } = animationProps,
86
- animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition,
87
- isComponentHydrating = componentState.unmounted === !0,
88
- isMounting = componentState.unmounted === "should-enter",
89
- isEntering = !!componentState.unmounted,
90
- isExiting = presence?.[0] === !1,
91
- sendExitComplete = presence?.[1],
92
- wasEnteringRef = (0, import_react2.useRef)(isEntering),
93
- justFinishedEntering = wasEnteringRef.current && !isEntering;
103
+ props,
104
+ style,
105
+ componentState,
106
+ stateRef,
107
+ useStyleEmitter,
108
+ presence
109
+ } = animationProps;
110
+ var animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition;
111
+ var isComponentHydrating = componentState.unmounted === true;
112
+ var isMounting = componentState.unmounted === "should-enter";
113
+ var isEntering = !!componentState.unmounted;
114
+ var isExiting = (presence === null || presence === void 0 ? void 0 : presence[0]) === false;
115
+ var sendExitComplete = presence === null || presence === void 0 ? void 0 : presence[1];
116
+ var refs = (0, import_react2.useRef)(null);
117
+ if (!refs.current) {
118
+ refs.current = {
119
+ isFirstRender: true,
120
+ lastDoAnimate: null,
121
+ lastDontAnimate: null,
122
+ controls: null,
123
+ lastAnimateAt: 0,
124
+ disposed: false,
125
+ wasExiting: false,
126
+ isExiting: false,
127
+ sendExitComplete: void 0,
128
+ animationState: "default",
129
+ frozenExitTarget: null,
130
+ exitCompleteScheduled: false,
131
+ wasEntering: false,
132
+ wasDisabled: false
133
+ };
134
+ }
135
+ var justFinishedEntering = refs.current.wasEntering && !isEntering;
94
136
  (0, import_react2.useEffect)(function () {
95
- wasEnteringRef.current = isEntering;
137
+ refs.current.wasEntering = isEntering;
96
138
  });
97
- var animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default",
98
- disableAnimation = isComponentHydrating || isMounting || !animationKey,
99
- isFirstRender = (0, import_react2.useRef)(!0),
100
- [scope, animate] = (0, import_react.useAnimate)(),
101
- lastDoAnimate = (0, import_react2.useRef)(null),
102
- controls = (0, import_react2.useRef)(null),
103
- styleKey = JSON.stringify(style),
104
- shouldDebug =
105
- // process.env.NODE_ENV === 'development' &&
106
- props.debug && props.debug !== "profile",
107
- {
108
- dontAnimate = {},
109
- doAnimate,
110
- animationOptions
111
- } = (0, import_react2.useMemo)(function () {
112
- var motionAnimationState = getMotionAnimatedProps(props, style, disableAnimation, animationState);
113
- return motionAnimationState;
114
- }, [isExiting, animationKey, styleKey, animationState, disableAnimation]),
115
- id = (0, import_react2.useId)(),
116
- debugId = process.env.NODE_ENV === "development" ? id : "",
117
- lastAnimateAt = (0, import_react2.useRef)(0),
118
- disposed = (0, import_react2.useRef)(!1),
119
- [firstRenderStyle] = (0, import_react2.useState)(style),
120
- lastDontAnimate = (0, import_react2.useRef)(firstRenderStyle),
121
- [isHydrating, setIsHydrating] = (0, import_react2.useState)(isHydratingGlobal);
139
+ var animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default";
140
+ var disableAnimation = isComponentHydrating || isMounting || !animationKey;
141
+ var [scope, animate] = useAnimateSSRSafe();
142
+ refs.current.isExiting = isExiting;
143
+ refs.current.sendExitComplete = sendExitComplete;
144
+ refs.current.animationState = animationState;
145
+ var justStartedExiting = isExiting && !refs.current.wasExiting;
146
+ var justStoppedExiting = !isExiting && refs.current.wasExiting;
147
+ if (justStartedExiting || justStoppedExiting) {
148
+ refs.current.frozenExitTarget = null;
149
+ refs.current.exitCompleteScheduled = false;
150
+ }
151
+ (0, import_react2.useEffect)(function () {
152
+ refs.current.wasExiting = isExiting;
153
+ });
154
+ var {
155
+ dontAnimate = {},
156
+ doAnimate,
157
+ animationOptions
158
+ } = getMotionAnimatedProps(props, style, disableAnimation, animationState);
159
+ var [firstRenderStyle] = (0, import_react2.useState)(style);
160
+ if (refs.current.isFirstRender) {
161
+ refs.current.lastDontAnimate = firstRenderStyle;
162
+ }
163
+ var [isHydrating, setIsHydrating] = (0, import_react2.useState)(isHydratingGlobal);
122
164
  (0, import_react2.useLayoutEffect)(function () {
123
- return isHydratingGlobal && hydratingComponents.add(function () {
124
- setIsHydrating(!1);
125
- }), function () {
126
- disposed.current = !0;
165
+ if (isHydratingGlobal) {
166
+ hydratingComponents.add(function () {
167
+ setIsHydrating(false);
168
+ });
169
+ }
170
+ return function () {
171
+ refs.current.disposed = true;
127
172
  };
128
173
  }, []);
129
174
  var flushAnimation = function (param) {
130
175
  var {
131
- doAnimate: doAnimate2 = {},
132
- animationOptions: animationOptions2 = {},
176
+ doAnimate: doAnimateRaw = {},
177
+ animationOptions: passedOptions = {},
133
178
  dontAnimate: dontAnimate2
134
179
  } = param;
180
+ var startedControls = null;
181
+ var isCurrentlyExiting = refs.current.isExiting;
182
+ var currentSendExitComplete = refs.current.sendExitComplete;
183
+ var doAnimate2 = doAnimateRaw;
184
+ if (isCurrentlyExiting && refs.current.frozenExitTarget) {
185
+ doAnimate2 = refs.current.frozenExitTarget;
186
+ }
187
+ var _props_transition;
188
+ var animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions((_props_transition = props.transition) !== null && _props_transition !== void 0 ? _props_transition : null, "exit") : passedOptions;
135
189
  try {
136
190
  var node = stateRef.current.host;
137
- if (isFirstRender.current && (lastDontAnimate.current = null, lastDoAnimate.current = null), shouldDebug && (console.groupCollapsed(`[motion] ${debugId} \u{1F30A} animate (${JSON.stringify(getDiff(lastDoAnimate.current, doAnimate2), null, 2)})`), console.info({
138
- props,
139
- componentState,
140
- doAnimate: doAnimate2,
141
- dontAnimate: dontAnimate2,
142
- animationOptions: animationOptions2,
143
- animationProps,
144
- lastDoAnimate: {
145
- ...lastDoAnimate.current
146
- },
147
- lastDontAnimate: {
148
- ...lastDontAnimate.current
149
- },
150
- isExiting,
151
- style,
152
- node
153
- }), console.groupCollapsed("trace >"), console.trace(), console.groupEnd(), console.groupEnd()), !_instanceof(node, HTMLElement)) return;
154
- var prevDont = lastDontAnimate.current;
155
- if (dontAnimate2) if (prevDont) {
156
- removeRemovedStyles(prevDont, dontAnimate2, node, doAnimate2);
157
- var changed = getDiff(prevDont, dontAnimate2);
158
- changed && Object.assign(node.style, changed);
159
- } else Object.assign(node.style, dontAnimate2);
191
+ if (refs.current.isFirstRender) {
192
+ refs.current.lastDontAnimate = null;
193
+ refs.current.lastDoAnimate = null;
194
+ }
195
+ if (process.env.NODE_ENV === "development") {
196
+ if (props["debug"] && props["debug"] !== "profile") {
197
+ console.groupCollapsed(`[motion] animate (${JSON.stringify(getDiff(refs.current.lastDoAnimate, doAnimate2), null, 2)})`);
198
+ console.info({
199
+ props,
200
+ componentState,
201
+ doAnimate: doAnimate2,
202
+ dontAnimate: dontAnimate2,
203
+ animationOptions: animationOptions2,
204
+ animationProps,
205
+ lastDoAnimate: {
206
+ ...refs.current.lastDoAnimate
207
+ },
208
+ lastDontAnimate: {
209
+ ...refs.current.lastDontAnimate
210
+ },
211
+ isExiting,
212
+ style,
213
+ node
214
+ });
215
+ console.groupCollapsed(`trace >`);
216
+ console.trace();
217
+ console.groupEnd();
218
+ console.groupEnd();
219
+ }
220
+ }
221
+ if (!_instanceof(node, HTMLElement)) {
222
+ return;
223
+ }
224
+ var prevDont = refs.current.lastDontAnimate;
225
+ if (dontAnimate2) {
226
+ if (prevDont) {
227
+ removeRemovedStyles(prevDont, dontAnimate2, node, doAnimate2);
228
+ var changed = getDiff(prevDont, dontAnimate2);
229
+ if (changed) {
230
+ Object.assign(node.style, changed);
231
+ }
232
+ } else {
233
+ Object.assign(node.style, dontAnimate2);
234
+ }
235
+ }
160
236
  if (doAnimate2) {
161
237
  if (prevDont) {
162
- var movedToAnimate = {};
163
- for (var key in prevDont) key in doAnimate2 && (node.style[key] = prevDont[key], movedToAnimate[key] = prevDont[key], lastDoAnimate.current && (lastDoAnimate.current[key] = prevDont[key]));
164
- Object.keys(movedToAnimate).length > 0 && animate(scope.current, {
165
- ...movedToAnimate
166
- }, {
167
- duration: 0
168
- });
238
+ for (var key in prevDont) {
239
+ if (key in doAnimate2) {
240
+ node.style[key] = prevDont[key];
241
+ if (refs.current.lastDoAnimate) {
242
+ refs.current.lastDoAnimate[key] = prevDont[key];
243
+ }
244
+ }
245
+ }
246
+ }
247
+ var lastAnimated = refs.current.lastDoAnimate;
248
+ if (lastAnimated) {
249
+ removeRemovedStyles(lastAnimated, doAnimate2, node, dontAnimate2);
169
250
  }
170
- var lastAnimated = lastDoAnimate.current;
171
- lastAnimated && removeRemovedStyles(lastAnimated, doAnimate2, node, dontAnimate2);
172
- var diff = getDiff(lastDoAnimate.current, doAnimate2);
251
+ var diff = getDiff(refs.current.lastDoAnimate, doAnimate2);
173
252
  if (diff) {
174
- var _controls_current_animations,
175
- _controls_current,
176
- _controls_current1,
177
- isRunning = ((_controls_current = controls.current) === null || _controls_current === void 0 || (_controls_current_animations = _controls_current.animations) === null || _controls_current_animations === void 0 ? void 0 : _controls_current_animations.length) === 0 ? !1 : ((_controls_current1 = controls.current) === null || _controls_current1 === void 0 ? void 0 : _controls_current1.state) === "running",
178
- targetTransform = typeof diff.transform == "string" ? diff.transform : null,
179
- isPositionOnlyTransform = targetTransform && targetTransform.includes("translate") && !nonPositionTransformRe.test(targetTransform),
180
- isPopperElement = node.hasAttribute("data-popper-animate-position"),
181
- isEnteringPresenceChild = presence && justFinishedEntering;
182
- if (isRunning && controls.current && isPositionOnlyTransform && (isPopperElement || isEnteringPresenceChild)) {
183
- var currentTransform = getComputedStyle(node).transform;
184
- if (currentTransform && currentTransform !== "none") {
185
- var matrixMatch = currentTransform.match(/matrix\([^,]+,\s*[^,]+,\s*[^,]+,\s*[^,]+,\s*([^,]+),\s*([^)]+)\)/);
186
- if (matrixMatch) {
187
- controls.current.stop(), node.style.transform = currentTransform;
188
- var currentX = Number.parseFloat(matrixMatch[1]),
189
- currentY = Number.parseFloat(matrixMatch[2]),
190
- keyframeDiff = {
191
- ...diff,
192
- transform: [`translateX(${currentX}px) translateY(${currentY}px)`, targetTransform]
193
- };
194
- controls.current = animate(scope.current, keyframeDiff, animationOptions2), lastAnimateAt.current = Date.now(), lastDontAnimate.current = dontAnimate2 ? {
195
- ...dontAnimate2
196
- } : {}, lastDoAnimate.current = doAnimate2 ? {
197
- ...doAnimate2
198
- } : {};
199
- return;
253
+ if (isCurrentlyExiting && !refs.current.frozenExitTarget) {
254
+ refs.current.frozenExitTarget = {
255
+ ...doAnimate2
256
+ };
257
+ }
258
+ var isPopperPosition = node.hasAttribute("data-popper-animate-position");
259
+ var midFlightValues = null;
260
+ if (refs.current.controls) {
261
+ try {
262
+ var computed = getComputedStyle(node);
263
+ midFlightValues = {};
264
+ for (var key1 in diff) {
265
+ var val = computed[key1];
266
+ if (val !== void 0 && val !== "") {
267
+ midFlightValues[key1] = val;
268
+ }
200
269
  }
270
+ } catch (e) {}
271
+ if (isCurrentlyExiting) {
272
+ refs.current.controls.stop();
201
273
  }
274
+ if (midFlightValues) {
275
+ for (var key2 in midFlightValues) {
276
+ ;
277
+ node.style[key2] = midFlightValues[key2];
278
+ }
279
+ }
280
+ if (isPopperPosition) {
281
+ var anims = node.getAnimations();
282
+ var _iteratorNormalCompletion = true,
283
+ _didIteratorError = false,
284
+ _iteratorError = void 0;
285
+ try {
286
+ for (var _iterator = anims[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
287
+ var anim = _step.value;
288
+ anim.cancel();
289
+ }
290
+ } catch (err) {
291
+ _didIteratorError = true;
292
+ _iteratorError = err;
293
+ } finally {
294
+ try {
295
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
296
+ _iterator.return();
297
+ }
298
+ } finally {
299
+ if (_didIteratorError) {
300
+ throw _iteratorError;
301
+ }
302
+ }
303
+ }
304
+ }
305
+ }
306
+ var fixedDiff = fixTransparentColors(diff, refs.current.lastDoAnimate, doAnimate2);
307
+ if ((midFlightValues === null || midFlightValues === void 0 ? void 0 : midFlightValues.transform) && fixedDiff.transform) {
308
+ fixedDiff.transform = [midFlightValues.transform, fixedDiff.transform];
202
309
  }
203
- var fixedDiff = fixTransparentColors({
204
- ...diff
205
- }, lastDoAnimate.current);
206
- controls.current = animate(scope.current, fixedDiff, animationOptions2), lastAnimateAt.current = Date.now();
310
+ startedControls = animate(scope.current, fixedDiff, animationOptions2);
311
+ refs.current.controls = startedControls;
312
+ refs.current.lastAnimateAt = Date.now();
207
313
  }
208
314
  }
209
- lastDontAnimate.current = dontAnimate2 ? {
315
+ refs.current.lastDontAnimate = dontAnimate2 ? {
210
316
  ...dontAnimate2
211
- } : {}, lastDoAnimate.current = doAnimate2 ? {
317
+ } : {};
318
+ refs.current.lastDoAnimate = doAnimate2 ? {
212
319
  ...doAnimate2
213
320
  } : {};
214
321
  } finally {
215
- isExiting && (controls.current ? controls.current.finished.then(function () {
216
- sendExitComplete?.();
217
- }) : sendExitComplete?.());
322
+ if (isCurrentlyExiting && currentSendExitComplete) {
323
+ if (startedControls) {
324
+ refs.current.exitCompleteScheduled = true;
325
+ startedControls.finished.then(function () {
326
+ if (refs.current.isExiting) {
327
+ currentSendExitComplete();
328
+ }
329
+ }).catch(function () {
330
+ if (refs.current.isExiting) {
331
+ currentSendExitComplete();
332
+ }
333
+ });
334
+ } else if (!refs.current.exitCompleteScheduled) {
335
+ currentSendExitComplete();
336
+ }
337
+ }
218
338
  }
219
339
  };
220
- return useStyleEmitter?.(function (nextStyle) {
221
- var _$animationProps = getMotionAnimatedProps(props, nextStyle, disableAnimation, animationState);
340
+ useStyleEmitter === null || useStyleEmitter === void 0 ? void 0 : useStyleEmitter(function (nextStyle, effectiveTransition) {
341
+ var _$animationProps = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, effectiveTransition);
222
342
  flushAnimation(_$animationProps);
223
- }), (0, import_web.useIsomorphicLayoutEffect)(function () {
224
- if (isFirstRender.current) {
225
- if (isFirstRender.current = !1, isHydrating) {
226
- var node = stateRef.current.host;
227
- _instanceof(node, HTMLElement) && (dontAnimate && (Object.assign(node.style, dontAnimate), animate(scope.current, {
228
- ...dontAnimate
229
- }, {
230
- duration: 0
231
- })), doAnimate && Object.keys(doAnimate).length > 0 ? (lastDoAnimate.current = {
232
- ...doAnimate
233
- }, animate(scope.current, {
234
- ...doAnimate
235
- }, {
236
- duration: 0
237
- })) : lastDoAnimate.current = dontAnimate ? {
238
- ...dontAnimate
239
- } : {}), lastDontAnimate.current = dontAnimate ? {
343
+ });
344
+ (0, import_web.useIsomorphicLayoutEffect)(function () {
345
+ if (refs.current.isFirstRender) {
346
+ refs.current.isFirstRender = false;
347
+ refs.current.wasDisabled = disableAnimation;
348
+ if (isHydrating) {
349
+ if (doAnimate && Object.keys(doAnimate).length > 0) {
350
+ refs.current.lastDoAnimate = {
351
+ ...doAnimate
352
+ };
353
+ } else {
354
+ refs.current.lastDoAnimate = dontAnimate ? {
355
+ ...dontAnimate
356
+ } : {};
357
+ }
358
+ refs.current.lastDontAnimate = dontAnimate ? {
240
359
  ...dontAnimate
241
- } : {}, lastAnimateAt.current = Date.now();
360
+ } : {};
361
+ refs.current.lastAnimateAt = Date.now();
242
362
  return;
243
363
  }
244
- lastDontAnimate.current = dontAnimate ? {
364
+ refs.current.lastDontAnimate = dontAnimate ? {
365
+ ...dontAnimate
366
+ } : {};
367
+ refs.current.lastDoAnimate = doAnimate ? {
368
+ ...doAnimate
369
+ } : {};
370
+ return;
371
+ }
372
+ var justEnabled = refs.current.wasDisabled && !disableAnimation;
373
+ refs.current.wasDisabled = disableAnimation;
374
+ if (justEnabled && animationState !== "enter") {
375
+ var node = stateRef.current.host;
376
+ if (_instanceof(node, HTMLElement)) {
377
+ if (dontAnimate) Object.assign(node.style, dontAnimate);
378
+ if (doAnimate) Object.assign(node.style, doAnimate);
379
+ }
380
+ refs.current.lastDontAnimate = dontAnimate ? {
245
381
  ...dontAnimate
246
- } : {}, lastDoAnimate.current = doAnimate ? {
382
+ } : {};
383
+ refs.current.lastDoAnimate = doAnimate ? {
247
384
  ...doAnimate
248
385
  } : {};
249
386
  return;
@@ -253,18 +390,24 @@ function createAnimations(animations) {
253
390
  dontAnimate,
254
391
  animationOptions
255
392
  });
256
- }, [styleKey, isExiting, disableAnimation]), shouldDebug && (console.groupCollapsed("[motion] \u{1F30A} render"), console.info({
257
- style,
258
- doAnimate,
259
- dontAnimate,
260
- styleKey,
261
- scope,
262
- animationOptions,
263
- isExiting,
264
- isFirstRender: isFirstRender.current,
265
- animationProps
266
- }), console.groupEnd()), {
267
- // we never change this, after first render on
393
+ }, [style, isExiting, disableAnimation]);
394
+ if (process.env.NODE_ENV === "development") {
395
+ if (props["debug"] && props["debug"] !== "profile") {
396
+ console.groupCollapsed(`[motion] render`);
397
+ console.info({
398
+ style,
399
+ doAnimate,
400
+ dontAnimate,
401
+ scope,
402
+ animationOptions,
403
+ isExiting,
404
+ isFirstRender: refs.current.isFirstRender,
405
+ animationProps
406
+ });
407
+ console.groupEnd();
408
+ }
409
+ }
410
+ return {
268
411
  style: firstRenderStyle,
269
412
  ref: scope,
270
413
  render: "div"
@@ -285,16 +428,25 @@ function createAnimations(animations) {
285
428
  type: "spring"
286
429
  },
287
430
  onFinish = arguments.length > 2 ? arguments[2] : void 0;
288
- if (config.type === "direct") MotionValueStrategy.set(motionValue, {
289
- type: "direct"
290
- }), motionValue.set(next), onFinish?.();else {
291
- if (MotionValueStrategy.set(motionValue, config), onFinish) var unsubscribe = motionValue.on("change", function (value) {
292
- Math.abs(value - next) < 0.01 && (unsubscribe(), onFinish());
431
+ if (config.type === "direct") {
432
+ MotionValueStrategy.set(motionValue, {
433
+ type: "direct"
293
434
  });
294
435
  motionValue.set(next);
436
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish();
437
+ return;
438
+ }
439
+ MotionValueStrategy.set(motionValue, config);
440
+ if (onFinish) {
441
+ var prior = PendingMotionOnFinish.get(motionValue);
442
+ if (prior) {
443
+ PendingMotionOnFinish.delete(motionValue);
444
+ prior();
445
+ }
446
+ PendingMotionOnFinish.set(motionValue, onFinish);
295
447
  }
448
+ motionValue.set(next);
296
449
  },
297
- // Motion doesn't have a direct onFinish callback, so we simulate it
298
450
  stop() {
299
451
  motionValue.stop();
300
452
  }
@@ -303,15 +455,16 @@ function createAnimations(animations) {
303
455
  },
304
456
  useAnimatedNumberReaction(param, onValue) {
305
457
  var {
306
- value
307
- } = param,
308
- instance = value.getInstance();
458
+ value
459
+ } = param;
460
+ var instance = value.getInstance();
309
461
  (0, import_react.useMotionValueEvent)(instance, "change", onValue);
310
462
  },
311
463
  useAnimatedNumberStyle(val, getStyleProp) {
312
- var motionValue = val.getInstance(),
313
- getStyleRef = (0, import_react2.useRef)(getStyleProp);
314
- return getStyleRef.current = getStyleProp, (0, import_react2.useMemo)(function () {
464
+ var motionValue = val.getInstance();
465
+ var getStyleRef = (0, import_react2.useRef)(getStyleProp);
466
+ getStyleRef.current = getStyleProp;
467
+ return (0, import_react2.useMemo)(function () {
315
468
  return {
316
469
  getStyle: function (cur) {
317
470
  return getStyleRef.current(cur);
@@ -319,20 +472,48 @@ function createAnimations(animations) {
319
472
  motionValue
320
473
  };
321
474
  }, []);
475
+ },
476
+ useAnimatedNumbersStyle(vals, getStyleProp) {
477
+ var motionValues = vals.map(function (v) {
478
+ return v.getInstance();
479
+ });
480
+ var getStyleRef = (0, import_react2.useRef)(getStyleProp);
481
+ getStyleRef.current = getStyleProp;
482
+ return (0, import_react2.useMemo)(function () {
483
+ return {
484
+ getStyle: function () {
485
+ for (var _len = arguments.length, currentValues = new Array(_len), _key = 0; _key < _len; _key++) {
486
+ currentValues[_key] = arguments[_key];
487
+ }
488
+ return getStyleRef.current(...currentValues);
489
+ },
490
+ motionValues
491
+ };
492
+ }, []);
322
493
  }
323
494
  };
324
495
  function getMotionAnimatedProps(props, style, disable) {
325
- var animationState = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "default";
326
- if (disable) return {
327
- dontAnimate: style
328
- };
329
- var animationOptions = getAnimationOptions(props.transition, animationState),
330
- dontAnimate,
331
- doAnimate,
332
- animateOnly = props.animateOnly;
496
+ var animationState = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "default",
497
+ transitionOverride = arguments.length > 4 ? arguments[4] : void 0;
498
+ if (disable) {
499
+ return {
500
+ dontAnimate: style
501
+ };
502
+ }
503
+ var _ref;
504
+ var animationOptions = getAnimationOptions((_ref = transitionOverride !== null && transitionOverride !== void 0 ? transitionOverride : props.transition) !== null && _ref !== void 0 ? _ref : null, animationState);
505
+ var dontAnimate;
506
+ var doAnimate;
507
+ var animateOnly = props.animateOnly;
333
508
  for (var key in style) {
334
509
  var value = style[key];
335
- disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key) ? (dontAnimate || (dontAnimate = {}), dontAnimate[key] = value) : (doAnimate || (doAnimate = {}), doAnimate[key] = value);
510
+ if (disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key)) {
511
+ dontAnimate || (dontAnimate = {});
512
+ dontAnimate[key] = value;
513
+ } else {
514
+ doAnimate || (doAnimate = {});
515
+ doAnimate[key] = value;
516
+ }
336
517
  }
337
518
  return {
338
519
  dontAnimate,
@@ -341,31 +522,51 @@ function createAnimations(animations) {
341
522
  };
342
523
  }
343
524
  function getAnimationOptions(transitionProp) {
344
- var animationState = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "default",
345
- normalized = (0, import_animation_helpers.normalizeTransition)(transitionProp),
346
- effectiveKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
347
- if (!effectiveKey && Object.keys(normalized.properties).length === 0) return {};
348
- var defaultConfig = effectiveKey ? withInferredType(animations[effectiveKey]) : null,
349
- delay = typeof normalized.delay == "number" ? normalized.delay / 1e3 : void 0,
350
- globalConfigOverride;
351
- normalized.config && (globalConfigOverride = {
525
+ var animationState = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "default";
526
+ var normalized = (0, import_animation_helpers.normalizeTransition)(transitionProp);
527
+ var effectiveKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
528
+ if (!effectiveKey && animationState === "default") {
529
+ effectiveKey = normalized.enter || normalized.exit || null;
530
+ }
531
+ var globalConfigOverride = normalized.config ? {
352
532
  ...normalized.config
353
- }, typeof normalized.config.duration == "number" && (globalConfigOverride.duration = normalized.config.duration / 1e3));
533
+ } : void 0;
534
+ if (!effectiveKey && Object.keys(normalized.properties).length === 0 && !globalConfigOverride) {
535
+ return {};
536
+ }
537
+ var defaultConfig = effectiveKey ? withInferredType(animations[effectiveKey]) : null;
538
+ var delay = normalized.delay;
354
539
  var result = {};
355
- defaultConfig && Object.assign(result, defaultConfig), globalConfigOverride && Object.assign(result, globalConfigOverride), delay && (result.delay = delay), (defaultConfig || globalConfigOverride || delay) && (result.default = {
356
- ...defaultConfig,
357
- ...globalConfigOverride,
358
- ...(delay ? {
359
- delay
360
- } : null)
361
- });
362
- var _iteratorNormalCompletion = !0,
363
- _didIteratorError = !1,
540
+ if (defaultConfig) {
541
+ Object.assign(result, defaultConfig);
542
+ }
543
+ if (globalConfigOverride) {
544
+ Object.assign(result, globalConfigOverride);
545
+ if (result.type === void 0 && result.duration !== void 0 && result.damping === void 0 && result.stiffness === void 0 && result.mass === void 0) {
546
+ result.type = "tween";
547
+ }
548
+ }
549
+ if (delay) {
550
+ result.delay = delay;
551
+ }
552
+ if (defaultConfig || globalConfigOverride || delay) {
553
+ result.default = {
554
+ ...defaultConfig,
555
+ ...globalConfigOverride,
556
+ ...(delay ? {
557
+ delay
558
+ } : null)
559
+ };
560
+ }
561
+ var _iteratorNormalCompletion = true,
562
+ _didIteratorError = false,
364
563
  _iteratorError = void 0;
365
564
  try {
366
- for (var _iterator = Object.entries(normalized.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
565
+ for (var _iterator = Object.entries(normalized.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
367
566
  var [propName, animationNameOrConfig] = _step.value;
368
- if (typeof animationNameOrConfig == "string") result[propName] = withInferredType(animations[animationNameOrConfig]);else if (animationNameOrConfig && (typeof animationNameOrConfig > "u" ? "undefined" : _type_of(animationNameOrConfig)) === "object") {
567
+ if (typeof animationNameOrConfig === "string") {
568
+ result[propName] = withInferredType(animations[animationNameOrConfig]);
569
+ } else if (animationNameOrConfig && (typeof animationNameOrConfig === "undefined" ? "undefined" : _type_of(animationNameOrConfig)) === "object") {
369
570
  var baseConfig = animationNameOrConfig.type ? withInferredType(animations[animationNameOrConfig.type]) : defaultConfig;
370
571
  result[propName] = {
371
572
  ...baseConfig,
@@ -374,20 +575,35 @@ function createAnimations(animations) {
374
575
  }
375
576
  }
376
577
  } catch (err) {
377
- _didIteratorError = !0, _iteratorError = err;
578
+ _didIteratorError = true;
579
+ _iteratorError = err;
378
580
  } finally {
379
581
  try {
380
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
582
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
583
+ _iterator.return();
584
+ }
381
585
  } finally {
382
- if (_didIteratorError) throw _iteratorError;
586
+ if (_didIteratorError) {
587
+ throw _iteratorError;
588
+ }
383
589
  }
384
590
  }
591
+ convertMsToS(result);
385
592
  convertMsToS(result.default);
386
- for (var key in result) key !== "default" && convertMsToS(result[key]);
593
+ for (var key in result) {
594
+ if (key !== "default" && _type_of(result[key]) === "object") {
595
+ convertMsToS(result[key]);
596
+ }
597
+ }
387
598
  return result;
388
599
  }
389
600
  }
390
601
  function withInferredType(config) {
602
+ if (!config) {
603
+ return {
604
+ type: "spring"
605
+ };
606
+ }
391
607
  var isTimingBased = config.duration !== void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
392
608
  return {
393
609
  type: isTimingBased ? "tween" : "spring",
@@ -395,110 +611,229 @@ function withInferredType(config) {
395
611
  };
396
612
  }
397
613
  function convertMsToS(config) {
398
- !config || config.type !== "tween" || (typeof config.duration == "number" && (config.duration = config.duration / 1e3), typeof config.delay == "number" && (config.delay = config.delay / 1e3));
614
+ if (!config) return;
615
+ if (typeof config.delay === "number") config.delay = config.delay / 1e3;
616
+ if (typeof config.duration === "number") {
617
+ var isTimingBased = config.type === "tween" || config.type === void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
618
+ if (isTimingBased) {
619
+ config.duration = config.duration / 1e3;
620
+ }
621
+ }
399
622
  }
400
623
  function removeRemovedStyles(prev, next, node, dontClearIfIn) {
401
- for (var key in prev) if (!(key in next)) {
402
- if (dontClearIfIn && key in dontClearIfIn) continue;
403
- node.style[key] = "";
624
+ for (var key in prev) {
625
+ if (!(key in next)) {
626
+ if (dontClearIfIn && key in dontClearIfIn) {
627
+ continue;
628
+ }
629
+ node.style[key] = "";
630
+ }
404
631
  }
405
632
  }
406
- var disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "aspectRatio", "backdropFilter", "boxSizing", "contain", "containerType", "display", "flexBasis", "flexDirection", "flexGrow", "flexShrink", "fontFamily", "justifyContent", "marginBottom", "marginLeft", "marginRight", "marginTop", "maxHeight", "maxWidth", "minHeight", "minWidth", "overflow", "overflowX", "overflowY", "pointerEvents", "position", "textWrap", "transformOrigin", "userSelect", "WebkitBackdropFilter", "zIndex"]),
407
- MotionView = createMotionView("div"),
408
- MotionText = createMotionView("span");
633
+ var disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "boxSizing", "contain", "containerType", "display", "flexBasis", "flexDirection", "fontFamily", "justifyContent", "overflow", "overflowX", "overflowY", "pointerEvents", "position", "textWrap", "userSelect"]);
634
+ var MotionView = createMotionView("div");
635
+ var MotionText = createMotionView("span");
409
636
  function createMotionView(defaultTag) {
410
- var isText = defaultTag === "span",
411
- Component = /* @__PURE__ */(0, import_react2.forwardRef)(function (propsIn, ref) {
412
- var _hooks_usePropsTransform,
413
- {
414
- forwardedRef,
415
- animation,
416
- render = defaultTag,
417
- style,
418
- ...propsRest
419
- } = propsIn,
420
- [scope, animate] = (0, import_react.useAnimate)(),
421
- hostRef = (0, import_react2.useRef)(null),
422
- composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref, hostRef, scope),
423
- stateRef = (0, import_react2.useRef)(null);
424
- stateRef.current || (stateRef.current = {
637
+ var isText = defaultTag === "span";
638
+ var Component = /* @__PURE__ */(0, import_react2.forwardRef)(function (propsIn, ref) {
639
+ var _hooks_usePropsTransform;
640
+ var {
641
+ forwardedRef,
642
+ animation,
643
+ render = defaultTag,
644
+ style,
645
+ ...propsRest
646
+ } = propsIn;
647
+ var [scope, animate] = useAnimateSSRSafe();
648
+ var hostRef = (0, import_react2.useRef)(null);
649
+ var composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref, hostRef, scope);
650
+ var stateRef = (0, import_react2.useRef)(null);
651
+ if (!stateRef.current) {
652
+ stateRef.current = {
425
653
  get host() {
426
654
  return hostRef.current;
427
655
  }
656
+ };
657
+ }
658
+ var [_, state] = (0, import_web.useThemeWithState)({});
659
+ var styles = Array.isArray(style) ? style : [style];
660
+ var [animatedStyle, nonAnimatedStyles] = function () {
661
+ var animatedStyle2;
662
+ var nonAnimatedStyles2 = [];
663
+ var _iteratorNormalCompletion = true,
664
+ _didIteratorError = false,
665
+ _iteratorError = void 0;
666
+ try {
667
+ for (var _iterator = styles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
668
+ var style2 = _step.value;
669
+ if (style2.getStyle) {
670
+ animatedStyle2 = style2;
671
+ } else {
672
+ nonAnimatedStyles2.push(style2);
673
+ }
674
+ }
675
+ } catch (err) {
676
+ _didIteratorError = true;
677
+ _iteratorError = err;
678
+ } finally {
679
+ try {
680
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
681
+ _iterator.return();
682
+ }
683
+ } finally {
684
+ if (_didIteratorError) {
685
+ throw _iteratorError;
686
+ }
687
+ }
688
+ }
689
+ return [animatedStyle2, nonAnimatedStyles2];
690
+ }();
691
+ function getProps(props2) {
692
+ var out = (0, import_web.getSplitStyles)(props2, isText ? import_web.Text.staticConfig : import_web.View.staticConfig, state === null || state === void 0 ? void 0 : state.theme, state === null || state === void 0 ? void 0 : state.name, {
693
+ unmounted: false
694
+ }, {
695
+ isAnimated: false,
696
+ noClass: true,
697
+ resolveValues: "auto"
428
698
  });
429
- var [_, state] = (0, import_web.useThemeWithState)({}),
430
- styles = Array.isArray(style) ? style : [style],
431
- [animatedStyle, nonAnimatedStyles] = function () {
432
- return [styles.find(function (x) {
433
- return x.getStyle;
434
- }), styles.filter(function (x) {
435
- return !x.getStyle;
436
- })];
437
- }();
438
- function getProps(props2) {
439
- var out = (0, import_web.getSplitStyles)(props2, isText ? import_web.Text.staticConfig : import_web.View.staticConfig, state?.theme, state?.name, {
440
- unmounted: !1
441
- }, {
442
- isAnimated: !1,
443
- noClass: !0,
444
- // noMergeStyle: true,
445
- resolveValues: "auto"
446
- });
447
- return out ? (out.viewProps.style && ((0, import_web.fixStyles)(out.viewProps.style), (0, import_web.styleToCSS)(out.viewProps.style)), out.viewProps) : {};
699
+ if (!out) {
700
+ return {};
701
+ }
702
+ if (out.viewProps.style) {
703
+ (0, import_web.fixStyles)(out.viewProps.style);
704
+ (0, import_web.styleToCSS)(out.viewProps.style);
448
705
  }
449
- var props = getProps({
450
- ...propsRest,
451
- style: nonAnimatedStyles
452
- }),
453
- Element = render || "div",
454
- transformedProps = (_hooks_usePropsTransform = import_web.hooks.usePropsTransform) === null || _hooks_usePropsTransform === void 0 ? void 0 : _hooks_usePropsTransform.call(import_web.hooks, render, props, stateRef, !1);
455
- return (0, import_react2.useEffect)(function () {
456
- if (animatedStyle) return animatedStyle.motionValue.on("change", function (value) {
457
- var nextStyle = animatedStyle.getStyle(value),
458
- animationConfig = MotionValueStrategy.get(animatedStyle.motionValue),
459
- node = hostRef.current,
460
- webStyle = getProps({
706
+ return out.viewProps;
707
+ }
708
+ var props = getProps({
709
+ ...propsRest,
710
+ style: nonAnimatedStyles
711
+ });
712
+ var Element = render || "div";
713
+ var transformedProps = (_hooks_usePropsTransform = import_web.hooks.usePropsTransform) === null || _hooks_usePropsTransform === void 0 ? void 0 : _hooks_usePropsTransform.call(import_web.hooks, render, props, stateRef, false);
714
+ (0, import_react2.useEffect)(function () {
715
+ if (!animatedStyle) return;
716
+ if (animatedStyle.motionValues) {
717
+ var mvs = animatedStyle.motionValues;
718
+ var unsubs = mvs.map(function (mv) {
719
+ return mv.on("change", function () {
720
+ var currentValues = mvs.map(function (v) {
721
+ return v.get();
722
+ });
723
+ var nextStyle = animatedStyle.getStyle(...currentValues);
724
+ var animationConfig = MotionValueStrategy.get(mv);
725
+ var node = hostRef.current;
726
+ var webStyle = getProps({
461
727
  style: nextStyle
462
728
  }).style;
463
- if (webStyle && _instanceof(node, HTMLElement)) {
464
- var motionAnimationConfig = animationConfig?.type === "timing" ? {
465
- type: "tween",
466
- duration: (animationConfig?.duration || 0) / 1e3
467
- } : animationConfig?.type === "direct" ? {
468
- type: "tween",
469
- duration: 0
470
- } : {
471
- type: "spring",
472
- ...animationConfig
473
- };
474
- animate(node, webStyle, motionAnimationConfig);
475
- }
729
+ if (webStyle && _instanceof(node, HTMLElement)) {
730
+ var motionAnimationConfig = (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "timing" ? {
731
+ type: "tween",
732
+ duration: ((animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.duration) || 0) / 1e3
733
+ } : (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "direct" ? {
734
+ type: "tween",
735
+ duration: 0
736
+ } : {
737
+ type: "spring",
738
+ ...animationConfig
739
+ };
740
+ var controls = animate(node, webStyle, motionAnimationConfig);
741
+ settlePendingMotionOnFinish(mv, controls);
742
+ }
743
+ });
476
744
  });
477
- }, [animatedStyle]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(Element, {
478
- ...transformedProps,
479
- ref: composedRefs
745
+ return function () {
746
+ return unsubs.forEach(function (fn) {
747
+ return fn();
748
+ });
749
+ };
750
+ }
751
+ if (!animatedStyle.motionValue) return;
752
+ return animatedStyle.motionValue.on("change", function (value) {
753
+ var nextStyle = animatedStyle.getStyle(value);
754
+ var animationConfig = MotionValueStrategy.get(animatedStyle.motionValue);
755
+ var node = hostRef.current;
756
+ var webStyle = getProps({
757
+ style: nextStyle
758
+ }).style;
759
+ if (webStyle && _instanceof(node, HTMLElement)) {
760
+ var motionAnimationConfig = (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "timing" ? {
761
+ type: "tween",
762
+ duration: ((animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.duration) || 0) / 1e3
763
+ } : (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "direct" ? {
764
+ type: "tween",
765
+ duration: 0
766
+ } : {
767
+ type: "spring",
768
+ ...animationConfig
769
+ };
770
+ var controls = animate(node, webStyle, motionAnimationConfig);
771
+ settlePendingMotionOnFinish(animatedStyle.motionValue, controls);
772
+ }
480
773
  });
774
+ }, [animatedStyle]);
775
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Element, {
776
+ ...transformedProps,
777
+ ref: composedRefs
481
778
  });
482
- return Component.acceptTagProp = !0, Component;
779
+ });
780
+ Component["acceptRenderProp"] = true;
781
+ return Component;
483
782
  }
484
783
  function getDiff(previous, next) {
485
- if (!previous) return next;
784
+ if (!previous) {
785
+ return next;
786
+ }
486
787
  var diff = null;
487
- for (var key in next) next[key] !== previous[key] && (diff || (diff = {}), diff[key] = next[key]);
788
+ for (var key in next) {
789
+ if (next[key] !== previous[key]) {
790
+ diff || (diff = {});
791
+ diff[key] = next[key];
792
+ }
793
+ }
488
794
  return diff;
489
795
  }
490
- function fixTransparentColors(diff, previous) {
796
+ function fixTransparentColors(diff, previous, next) {
491
797
  var result = diff;
492
- for (var key in diff) if (diff[key] === "transparent") {
493
- var prev = previous?.[key],
494
- fixed = "rgba(0, 0, 0, 0)";
495
- if (typeof prev == "string") {
496
- var rgbaMatch = prev.match(/^rgba?\(([^,]+),\s*([^,]+),\s*([^,)]+)/);
497
- rgbaMatch && (fixed = `rgba(${rgbaMatch[1]}, ${rgbaMatch[2]}, ${rgbaMatch[3]}, 0)`);
798
+ for (var key in diff) {
799
+ if (diff[key] === "transparent") {
800
+ var fixed = "rgba(0, 0, 0, 0)";
801
+ var candidates = [previous === null || previous === void 0 ? void 0 : previous[key], next === null || next === void 0 ? void 0 : next[key]];
802
+ var _iteratorNormalCompletion = true,
803
+ _didIteratorError = false,
804
+ _iteratorError = void 0;
805
+ try {
806
+ for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
807
+ var candidate = _step.value;
808
+ if (typeof candidate === "string" && candidate !== "transparent") {
809
+ var rgbaMatch = candidate.match(/^rgba?\(([^,]+),\s*([^,]+),\s*([^,)]+)/);
810
+ if (rgbaMatch) {
811
+ fixed = `rgba(${rgbaMatch[1]}, ${rgbaMatch[2]}, ${rgbaMatch[3]}, 0)`;
812
+ break;
813
+ }
814
+ }
815
+ }
816
+ } catch (err) {
817
+ _didIteratorError = true;
818
+ _iteratorError = err;
819
+ } finally {
820
+ try {
821
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
822
+ _iterator.return();
823
+ }
824
+ } finally {
825
+ if (_didIteratorError) {
826
+ throw _iteratorError;
827
+ }
828
+ }
829
+ }
830
+ if (result === diff) {
831
+ result = {
832
+ ...diff
833
+ };
834
+ }
835
+ result[key] = fixed;
498
836
  }
499
- result === diff && (result = {
500
- ...diff
501
- }), result[key] = fixed;
502
837
  }
503
838
  return result;
504
839
  }