framer-motion 4.1.0-rc.1 → 4.1.3

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.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,25 @@
2
2
 
3
3
  Framer Motion adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
- ## [4.1.0] Unreleased
5
+ ## [4.1.3] 2021-04-07
6
+
7
+ ### Fixed
8
+
9
+ - Animating to/between `0rem` and other non-specifically handled unit types.
10
+
11
+ ## [4.1.2] 2021-04-01
12
+
13
+ ### Fixed
14
+
15
+ - Clamping `borderRadius` to `0` and above during crossfade.
16
+
17
+ ## [4.1.1] 2021-04-01
18
+
19
+ ### Fixed
20
+
21
+ - Animating from `undefined` to number (including units) now animates from `0`.
22
+
23
+ ## [4.1.0] 2021-03-31
6
24
 
7
25
  ### Added
8
26
 
package/README.md CHANGED
@@ -69,10 +69,14 @@ Check out [our documentation](https://framer.com/api/motion) for guides and a fu
69
69
 
70
70
  Or checkout [our examples](https://framer.com/motion) for inspiration.
71
71
 
72
- ## Contribute
72
+ ### Contribute
73
73
 
74
- Want to contribute to Motion? Our [contributing guide](https://github.com/framer/motion/blob/master/CONTRIBUTING.md) has you covered.
74
+ Want to contribute to Framer Motion? Our [contributing guide](https://github.com/framer/motion/blob/master/CONTRIBUTING.md) has you covered.
75
75
 
76
- ## License
76
+ ### License
77
77
 
78
- Motion is MIT licensed.
78
+ Framer Motion is MIT licensed.
79
+
80
+ ## Framer
81
+
82
+ Get on the same page as your designers before production. Get started with [design and prototyping in Framer](https://www.framer.com/).
@@ -108,13 +108,21 @@ function getAnimation(key, value, target, transition, onComplete) {
108
108
  var valueTransition = getValueTransition(transition, key);
109
109
  var origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
110
110
  var isTargetAnimatable = isAnimatable(key, target);
111
- /**
112
- * If we're trying to animate from "none", try and get an animatable version
113
- * of the target. This could be improved to work both ways.
114
- */
115
111
  if (origin === "none" && isTargetAnimatable && typeof target === "string") {
112
+ /**
113
+ * If we're trying to animate from "none", try and get an animatable version
114
+ * of the target. This could be improved to work both ways.
115
+ */
116
116
  origin = getAnimatableNone(key, target);
117
117
  }
118
+ else if (isZero(origin) && typeof target === "string") {
119
+ origin = getZeroUnit(target);
120
+ }
121
+ else if (!Array.isArray(target) &&
122
+ isZero(target) &&
123
+ typeof origin === "string") {
124
+ target = getZeroUnit(origin);
125
+ }
118
126
  var isOriginAnimatable = isAnimatable(key, origin);
119
127
  warning(isOriginAnimatable === isTargetAnimatable, "You are trying to animate " + key + " from \"" + origin + "\" to \"" + target + "\". " + origin + " is not an animatable value - to enable this animation set " + origin + " to a value animatable to " + target + " via the `style` property.");
120
128
  function start() {
@@ -151,6 +159,17 @@ function getAnimation(key, value, target, transition, onComplete) {
151
159
  ? set
152
160
  : start;
153
161
  }
162
+ function isZero(value) {
163
+ return (value === 0 ||
164
+ (typeof value === "string" &&
165
+ parseFloat(value) === 0 &&
166
+ value.indexOf(" ") === -1));
167
+ }
168
+ function getZeroUnit(potentialUnitType) {
169
+ return typeof potentialUnitType === "number"
170
+ ? 0
171
+ : getAnimatableNone("", potentialUnitType);
172
+ }
154
173
  function getValueTransition(transition, key) {
155
174
  return transition[key] || transition["default"] || transition;
156
175
  }
@@ -181,4 +200,4 @@ function startAnimation(key, value, target, transition) {
181
200
  });
182
201
  }
183
202
 
184
- export { convertTransitionToAnimationOptions, getDelayFromTransition, getPopmotionAnimationOptions, getValueTransition, hydrateKeyframes, isTransitionDefined, startAnimation };
203
+ export { convertTransitionToAnimationOptions, getDelayFromTransition, getPopmotionAnimationOptions, getValueTransition, getZeroUnit, hydrateKeyframes, isTransitionDefined, isZero, startAnimation };
@@ -191,7 +191,7 @@ function mixValues(leadState, followState, latestLeadValues, latestFollowValues,
191
191
  */
192
192
  if (typeof followRadius === "number" &&
193
193
  typeof leadRadius === "number") {
194
- var radius = mix(followRadius, leadRadius, p);
194
+ var radius = Math.max(mix(followRadius, leadRadius, p), 0);
195
195
  leadState[borderLabel] = followState[borderLabel] = radius;
196
196
  }
197
197
  }
@@ -73,7 +73,10 @@ function layoutStack() {
73
73
  prevValues: prevValues,
74
74
  crossfadeOpacity: (follow === null || follow === void 0 ? void 0 : follow.isPresenceRoot) || (lead === null || lead === void 0 ? void 0 : lead.isPresenceRoot),
75
75
  });
76
- if (state.lead !== prevState.follow &&
76
+ if (
77
+ // Don't crossfade if we've just animated back from lead and switched the
78
+ // old follow to the new lead.
79
+ state.lead !== prevState.follow &&
77
80
  (prevState.lead !== state.lead ||
78
81
  prevState.leadIsExiting !== state.leadIsExiting)) {
79
82
  needsCrossfadeAnimation = true;
@@ -72,10 +72,23 @@ var Animate = /** @class */ (function (_super) {
72
72
  if (projectionParent) {
73
73
  var prevParentViewportBox = projectionParent.prevViewportBox;
74
74
  var parentLayout = projectionParent.getLayoutState().layout;
75
+ /**
76
+ * If we're being provided a previous parent VisualElement by AnimateSharedLayout
77
+ */
75
78
  if (prevParent) {
79
+ /**
80
+ * If we've been provided an explicit target box it means we're animating back
81
+ * to this previous parent. So we can make a relative box by comparing to the previous
82
+ * parent's layout
83
+ */
76
84
  if (targetBox) {
77
85
  parentLayout = prevParent.getLayoutState().layout;
78
86
  }
87
+ /**
88
+ * Likewise if we've been provided an explicit origin box it means we're
89
+ * animating out from a different element. So we should figure out where that was
90
+ * on screen relative to the new parent element.
91
+ */
79
92
  if (originBox &&
80
93
  !checkIfParentHasChanged(prevParent, projectionParent) &&
81
94
  prevParent.prevViewportBox) {
@@ -1924,13 +1924,21 @@ function getAnimation(key, value, target, transition, onComplete) {
1924
1924
  var valueTransition = getValueTransition(transition, key);
1925
1925
  var origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
1926
1926
  var isTargetAnimatable = isAnimatable(key, target);
1927
- /**
1928
- * If we're trying to animate from "none", try and get an animatable version
1929
- * of the target. This could be improved to work both ways.
1930
- */
1931
1927
  if (origin === "none" && isTargetAnimatable && typeof target === "string") {
1928
+ /**
1929
+ * If we're trying to animate from "none", try and get an animatable version
1930
+ * of the target. This could be improved to work both ways.
1931
+ */
1932
1932
  origin = getAnimatableNone(key, target);
1933
1933
  }
1934
+ else if (isZero(origin) && typeof target === "string") {
1935
+ origin = getZeroUnit(target);
1936
+ }
1937
+ else if (!Array.isArray(target) &&
1938
+ isZero(target) &&
1939
+ typeof origin === "string") {
1940
+ target = getZeroUnit(origin);
1941
+ }
1934
1942
  var isOriginAnimatable = isAnimatable(key, origin);
1935
1943
  heyListen.warning(isOriginAnimatable === isTargetAnimatable, "You are trying to animate " + key + " from \"" + origin + "\" to \"" + target + "\". " + origin + " is not an animatable value - to enable this animation set " + origin + " to a value animatable to " + target + " via the `style` property.");
1936
1944
  function start() {
@@ -1967,6 +1975,17 @@ function getAnimation(key, value, target, transition, onComplete) {
1967
1975
  ? set
1968
1976
  : start;
1969
1977
  }
1978
+ function isZero(value) {
1979
+ return (value === 0 ||
1980
+ (typeof value === "string" &&
1981
+ parseFloat(value) === 0 &&
1982
+ value.indexOf(" ") === -1));
1983
+ }
1984
+ function getZeroUnit(potentialUnitType) {
1985
+ return typeof potentialUnitType === "number"
1986
+ ? 0
1987
+ : getAnimatableNone("", potentialUnitType);
1988
+ }
1970
1989
  function getValueTransition(transition, key) {
1971
1990
  return transition[key] || transition["default"] || transition;
1972
1991
  }
@@ -4293,10 +4312,23 @@ var Animate = /** @class */ (function (_super) {
4293
4312
  if (projectionParent) {
4294
4313
  var prevParentViewportBox = projectionParent.prevViewportBox;
4295
4314
  var parentLayout = projectionParent.getLayoutState().layout;
4315
+ /**
4316
+ * If we're being provided a previous parent VisualElement by AnimateSharedLayout
4317
+ */
4296
4318
  if (prevParent) {
4319
+ /**
4320
+ * If we've been provided an explicit target box it means we're animating back
4321
+ * to this previous parent. So we can make a relative box by comparing to the previous
4322
+ * parent's layout
4323
+ */
4297
4324
  if (targetBox) {
4298
4325
  parentLayout = prevParent.getLayoutState().layout;
4299
4326
  }
4327
+ /**
4328
+ * Likewise if we've been provided an explicit origin box it means we're
4329
+ * animating out from a different element. So we should figure out where that was
4330
+ * on screen relative to the new parent element.
4331
+ */
4300
4332
  if (originBox &&
4301
4333
  !checkIfParentHasChanged(prevParent, projectionParent) &&
4302
4334
  prevParent.prevViewportBox) {
@@ -6507,7 +6539,7 @@ function mixValues(leadState, followState, latestLeadValues, latestFollowValues,
6507
6539
  */
6508
6540
  if (typeof followRadius === "number" &&
6509
6541
  typeof leadRadius === "number") {
6510
- var radius = popmotion.mix(followRadius, leadRadius, p);
6542
+ var radius = Math.max(popmotion.mix(followRadius, leadRadius, p), 0);
6511
6543
  leadState[borderLabel] = followState[borderLabel] = radius;
6512
6544
  }
6513
6545
  }
@@ -6612,7 +6644,10 @@ function layoutStack() {
6612
6644
  prevValues: prevValues,
6613
6645
  crossfadeOpacity: (follow === null || follow === void 0 ? void 0 : follow.isPresenceRoot) || (lead === null || lead === void 0 ? void 0 : lead.isPresenceRoot),
6614
6646
  });
6615
- if (state.lead !== prevState.follow &&
6647
+ if (
6648
+ // Don't crossfade if we've just animated back from lead and switched the
6649
+ // old follow to the new lead.
6650
+ state.lead !== prevState.follow &&
6616
6651
  (prevState.lead !== state.lead ||
6617
6652
  prevState.leadIsExiting !== state.leadIsExiting)) {
6618
6653
  needsCrossfadeAnimation = true;
@@ -3146,13 +3146,21 @@
3146
3146
  var valueTransition = getValueTransition(transition, key);
3147
3147
  var origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
3148
3148
  var isTargetAnimatable = isAnimatable(key, target);
3149
- /**
3150
- * If we're trying to animate from "none", try and get an animatable version
3151
- * of the target. This could be improved to work both ways.
3152
- */
3153
3149
  if (origin === "none" && isTargetAnimatable && typeof target === "string") {
3150
+ /**
3151
+ * If we're trying to animate from "none", try and get an animatable version
3152
+ * of the target. This could be improved to work both ways.
3153
+ */
3154
3154
  origin = getAnimatableNone(key, target);
3155
3155
  }
3156
+ else if (isZero(origin) && typeof target === "string") {
3157
+ origin = getZeroUnit(target);
3158
+ }
3159
+ else if (!Array.isArray(target) &&
3160
+ isZero(target) &&
3161
+ typeof origin === "string") {
3162
+ target = getZeroUnit(origin);
3163
+ }
3156
3164
  var isOriginAnimatable = isAnimatable(key, origin);
3157
3165
  warning(isOriginAnimatable === isTargetAnimatable, "You are trying to animate " + key + " from \"" + origin + "\" to \"" + target + "\". " + origin + " is not an animatable value - to enable this animation set " + origin + " to a value animatable to " + target + " via the `style` property.");
3158
3166
  function start() {
@@ -3189,6 +3197,17 @@
3189
3197
  ? set
3190
3198
  : start;
3191
3199
  }
3200
+ function isZero(value) {
3201
+ return (value === 0 ||
3202
+ (typeof value === "string" &&
3203
+ parseFloat(value) === 0 &&
3204
+ value.indexOf(" ") === -1));
3205
+ }
3206
+ function getZeroUnit(potentialUnitType) {
3207
+ return typeof potentialUnitType === "number"
3208
+ ? 0
3209
+ : getAnimatableNone("", potentialUnitType);
3210
+ }
3192
3211
  function getValueTransition(transition, key) {
3193
3212
  return transition[key] || transition["default"] || transition;
3194
3213
  }
@@ -5515,10 +5534,23 @@
5515
5534
  if (projectionParent) {
5516
5535
  var prevParentViewportBox = projectionParent.prevViewportBox;
5517
5536
  var parentLayout = projectionParent.getLayoutState().layout;
5537
+ /**
5538
+ * If we're being provided a previous parent VisualElement by AnimateSharedLayout
5539
+ */
5518
5540
  if (prevParent) {
5541
+ /**
5542
+ * If we've been provided an explicit target box it means we're animating back
5543
+ * to this previous parent. So we can make a relative box by comparing to the previous
5544
+ * parent's layout
5545
+ */
5519
5546
  if (targetBox) {
5520
5547
  parentLayout = prevParent.getLayoutState().layout;
5521
5548
  }
5549
+ /**
5550
+ * Likewise if we've been provided an explicit origin box it means we're
5551
+ * animating out from a different element. So we should figure out where that was
5552
+ * on screen relative to the new parent element.
5553
+ */
5522
5554
  if (originBox &&
5523
5555
  !checkIfParentHasChanged(prevParent, projectionParent) &&
5524
5556
  prevParent.prevViewportBox) {
@@ -7728,7 +7760,7 @@
7728
7760
  */
7729
7761
  if (typeof followRadius === "number" &&
7730
7762
  typeof leadRadius === "number") {
7731
- var radius = mix(followRadius, leadRadius, p);
7763
+ var radius = Math.max(mix(followRadius, leadRadius, p), 0);
7732
7764
  leadState[borderLabel] = followState[borderLabel] = radius;
7733
7765
  }
7734
7766
  }
@@ -7833,7 +7865,10 @@
7833
7865
  prevValues: prevValues,
7834
7866
  crossfadeOpacity: (follow === null || follow === void 0 ? void 0 : follow.isPresenceRoot) || (lead === null || lead === void 0 ? void 0 : lead.isPresenceRoot),
7835
7867
  });
7836
- if (state.lead !== prevState.follow &&
7868
+ if (
7869
+ // Don't crossfade if we've just animated back from lead and switched the
7870
+ // old follow to the new lead.
7871
+ state.lead !== prevState.follow &&
7837
7872
  (prevState.lead !== state.lead ||
7838
7873
  prevState.leadIsExiting !== state.leadIsExiting)) {
7839
7874
  needsCrossfadeAnimation = true;