framer-motion 7.10.0 → 7.10.2

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/README.md CHANGED
@@ -35,17 +35,18 @@ It looks like this:
35
35
 
36
36
  It does all this:
37
37
 
38
- - Springs
39
- - Keyframes
40
- - Layout animations
41
- - Shared layout animations
42
- - Gestures (drag/tap/hover)
43
- - SVG paths
44
- - Exit animations
38
+ - [Springs](https://www.framer.com/docs/transition/#spring)
39
+ - [Keyframes](https://www.framer.com/docs/animation/##keyframes)
40
+ - [Layout animations](https://www.framer.com/docs/layout-animations/)
41
+ - [Shared layout animations](https://www.framer.com/docs/layout-animations/#shared-layout-animations)
42
+ - [Gestures (drag/tap/hover)](https://www.framer.com/docs/gestures/)
43
+ - [Scroll animations](https://www.framer.com/docs/scroll-animations)
44
+ - [SVG paths](https://www.framer.com/docs/component/###svg-line-drawing)
45
+ - [Exit animations](https://www.framer.com/docs/animate-presence/)
45
46
  - Server-side rendering
46
- - Hardware-accelerated animations
47
- - Orchestrate animations across components
48
- - CSS variables
47
+ - [Hardware-accelerated animations](https://www.framer.com/docs/animation/#hardware-accelerated-animations)
48
+ - [Orchestrate animations across components](https://www.framer.com/docs/animation/##orchestration)
49
+ - [CSS variables](https://www.framer.com/docs/component/##css-variables)
49
50
 
50
51
  ...and a whole lot more.
51
52
 
package/dist/cjs/index.js CHANGED
@@ -2124,7 +2124,7 @@ class MotionValue {
2124
2124
  * This will be replaced by the build step with the latest version number.
2125
2125
  * When MotionValues are provided to motion components, warn if versions are mixed.
2126
2126
  */
2127
- this.version = "7.10.0";
2127
+ this.version = "7.10.2";
2128
2128
  /**
2129
2129
  * Duration, in milliseconds, since last updating frame.
2130
2130
  *
@@ -3154,18 +3154,11 @@ const circIn = (p) => 1 - Math.sin(Math.acos(p));
3154
3154
  const circOut = reverseEasing(circIn);
3155
3155
  const circInOut = mirrorEasing(circOut);
3156
3156
 
3157
- const createBackIn = (power = 1.525) => (p) => p * p * ((power + 1) * p - power);
3158
- const backIn = createBackIn();
3159
- const backOut = reverseEasing(backIn);
3157
+ const backOut = cubicBezier(0.33, 1.53, 0.69, 0.99);
3158
+ const backIn = reverseEasing(backOut);
3160
3159
  const backInOut = mirrorEasing(backIn);
3161
3160
 
3162
- const createAnticipate = (power) => {
3163
- const backEasing = createBackIn(power);
3164
- return (p) => (p *= 2) < 1
3165
- ? 0.5 * backEasing(p)
3166
- : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
3167
- };
3168
- const anticipate = createAnticipate();
3161
+ const anticipate = (p) => (p *= 2) < 1 ? 0.5 * backIn(p) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
3169
3162
 
3170
3163
  const easingLookup = {
3171
3164
  linear: noop,
@@ -3608,28 +3601,34 @@ function animate$1({ duration, driver = framesync, elapsed = 0, repeat: repeatMa
3608
3601
  driverControls.stop();
3609
3602
  },
3610
3603
  sample: (t) => {
3611
- return animation.next(Math.max(0, t)).value;
3604
+ return animation.next(Math.max(0, t));
3612
3605
  },
3613
3606
  };
3614
3607
  }
3615
3608
 
3616
- const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
3617
- const validWaapiEasing = new Set([
3618
- "linear",
3619
- "ease-in",
3620
- "ease-out",
3621
- "ease-in-out",
3622
- ]);
3623
- function mapEasingName(easingName) {
3624
- const name = camelToDash(easingName);
3625
- return validWaapiEasing.has(name) ? name : "ease";
3609
+ function isWaapiSupportedEasing(easing) {
3610
+ return (!easing || // Default easing
3611
+ Array.isArray(easing) || // Bezier curve
3612
+ (typeof easing === "string" && supportedWaapiEasing[easing]));
3626
3613
  }
3614
+ const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
3615
+ const supportedWaapiEasing = {
3616
+ linear: "linear",
3617
+ ease: "ease",
3618
+ easeIn: "ease-in",
3619
+ easeOut: "ease-out",
3620
+ easeInOut: "ease-in-out",
3621
+ circIn: cubicBezierAsString([0, 0.65, 0.55, 1]),
3622
+ circOut: cubicBezierAsString([0.55, 0, 1, 0.45]),
3623
+ backIn: cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
3624
+ backOut: cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
3625
+ };
3627
3626
  function mapEasingToNativeEasing(easing) {
3628
3627
  if (!easing)
3629
3628
  return undefined;
3630
3629
  return Array.isArray(easing)
3631
3630
  ? cubicBezierAsString(easing)
3632
- : mapEasingName(easing);
3631
+ : supportedWaapiEasing[easing];
3633
3632
  }
3634
3633
 
3635
3634
  function animateStyle(element, valueName, keyframes, { delay = 0, duration, repeat = 0, repeatType = "loop", ease, times, } = {}) {
@@ -3652,23 +3651,19 @@ const sampleDelta = 10; //ms
3652
3651
  function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ...options }) {
3653
3652
  let { keyframes, duration = 0.3, elapsed = 0, ease } = options;
3654
3653
  /**
3655
- * If this is a spring animation, pre-generate keyframes and
3656
- * record duration.
3657
- *
3658
- * TODO: When introducing support for values beyond opacity it
3659
- * might be better to use `animate.sample()`
3654
+ * If this animation needs pre-generated keyframes then generate.
3660
3655
  */
3661
- if (options.type === "spring") {
3662
- const springAnimation = spring(options);
3656
+ if (options.type === "spring" || !isWaapiSupportedEasing(options.ease)) {
3657
+ const sampleAnimation = animate$1(options);
3663
3658
  let state = { done: false, value: keyframes[0] };
3664
- const springKeyframes = [];
3659
+ const pregeneratedKeyframes = [];
3665
3660
  let t = 0;
3666
3661
  while (!state.done) {
3667
- state = springAnimation.next(t);
3668
- springKeyframes.push(state.value);
3662
+ state = sampleAnimation.sample(t);
3663
+ pregeneratedKeyframes.push(state.value);
3669
3664
  t += sampleDelta;
3670
3665
  }
3671
- keyframes = springKeyframes;
3666
+ keyframes = pregeneratedKeyframes;
3672
3667
  duration = t - sampleDelta;
3673
3668
  ease = "linear";
3674
3669
  }
@@ -3713,7 +3708,7 @@ function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ..
3713
3708
  const { currentTime } = animation;
3714
3709
  if (currentTime) {
3715
3710
  const sampleAnimation = animate$1(options);
3716
- value.setWithVelocity(sampleAnimation.sample(currentTime - sampleDelta), sampleAnimation.sample(currentTime), sampleDelta);
3711
+ value.setWithVelocity(sampleAnimation.sample(currentTime - sampleDelta).value, sampleAnimation.sample(currentTime).value, sampleDelta);
3717
3712
  }
3718
3713
  sync.update(() => animation.cancel());
3719
3714
  };
@@ -4069,7 +4064,6 @@ const createMotionValueAnimation = (valueName, value, target, transition = {}) =
4069
4064
  !options.repeatDelay &&
4070
4065
  options.repeatType !== "mirror" &&
4071
4066
  options.damping !== 0 &&
4072
- typeof options.ease !== "function" &&
4073
4067
  visualElement &&
4074
4068
  element instanceof HTMLElement &&
4075
4069
  !visualElement.getProps().onUpdate;
@@ -5938,7 +5932,7 @@ function updateMotionValuesFromProps(element, next, prev) {
5938
5932
  * and warn against mismatches.
5939
5933
  */
5940
5934
  if (process.env.NODE_ENV === "development") {
5941
- warnOnce(nextValue.version === "7.10.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.10.0 may not work as expected.`);
5935
+ warnOnce(nextValue.version === "7.10.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.10.2 may not work as expected.`);
5942
5936
  }
5943
5937
  }
5944
5938
  else if (isMotionValue(prevValue)) {
@@ -101,7 +101,6 @@ const createMotionValueAnimation = (valueName, value, target, transition = {}) =
101
101
  !options.repeatDelay &&
102
102
  options.repeatType !== "mirror" &&
103
103
  options.damping !== 0 &&
104
- typeof options.ease !== "function" &&
105
104
  visualElement &&
106
105
  element instanceof HTMLElement &&
107
106
  !visualElement.getProps().onUpdate;
@@ -106,7 +106,7 @@ function animate({ duration, driver = framesync, elapsed = 0, repeat: repeatMax
106
106
  driverControls.stop();
107
107
  },
108
108
  sample: (t) => {
109
- return animation.next(Math.max(0, t)).value;
109
+ return animation.next(Math.max(0, t));
110
110
  },
111
111
  };
112
112
  }
@@ -1,7 +1,7 @@
1
1
  import { sync } from '../../frameloop/index.mjs';
2
2
  import { animate } from '../legacy-popmotion/index.mjs';
3
- import { spring } from '../legacy-popmotion/spring.mjs';
4
3
  import { animateStyle } from './index.mjs';
4
+ import { isWaapiSupportedEasing } from './easing.mjs';
5
5
 
6
6
  /**
7
7
  * 10ms is chosen here as it strikes a balance between smooth
@@ -12,23 +12,19 @@ const sampleDelta = 10; //ms
12
12
  function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ...options }) {
13
13
  let { keyframes, duration = 0.3, elapsed = 0, ease } = options;
14
14
  /**
15
- * If this is a spring animation, pre-generate keyframes and
16
- * record duration.
17
- *
18
- * TODO: When introducing support for values beyond opacity it
19
- * might be better to use `animate.sample()`
15
+ * If this animation needs pre-generated keyframes then generate.
20
16
  */
21
- if (options.type === "spring") {
22
- const springAnimation = spring(options);
17
+ if (options.type === "spring" || !isWaapiSupportedEasing(options.ease)) {
18
+ const sampleAnimation = animate(options);
23
19
  let state = { done: false, value: keyframes[0] };
24
- const springKeyframes = [];
20
+ const pregeneratedKeyframes = [];
25
21
  let t = 0;
26
22
  while (!state.done) {
27
- state = springAnimation.next(t);
28
- springKeyframes.push(state.value);
23
+ state = sampleAnimation.sample(t);
24
+ pregeneratedKeyframes.push(state.value);
29
25
  t += sampleDelta;
30
26
  }
31
- keyframes = springKeyframes;
27
+ keyframes = pregeneratedKeyframes;
32
28
  duration = t - sampleDelta;
33
29
  ease = "linear";
34
30
  }
@@ -73,7 +69,7 @@ function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ..
73
69
  const { currentTime } = animation;
74
70
  if (currentTime) {
75
71
  const sampleAnimation = animate(options);
76
- value.setWithVelocity(sampleAnimation.sample(currentTime - sampleDelta), sampleAnimation.sample(currentTime), sampleDelta);
72
+ value.setWithVelocity(sampleAnimation.sample(currentTime - sampleDelta).value, sampleAnimation.sample(currentTime).value, sampleDelta);
77
73
  }
78
74
  sync.update(() => animation.cancel());
79
75
  };
@@ -1,22 +1,26 @@
1
- import { camelToDash } from '../../render/dom/utils/camel-to-dash.mjs';
2
-
3
- const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
4
- const validWaapiEasing = new Set([
5
- "linear",
6
- "ease-in",
7
- "ease-out",
8
- "ease-in-out",
9
- ]);
10
- function mapEasingName(easingName) {
11
- const name = camelToDash(easingName);
12
- return validWaapiEasing.has(name) ? name : "ease";
1
+ function isWaapiSupportedEasing(easing) {
2
+ return (!easing || // Default easing
3
+ Array.isArray(easing) || // Bezier curve
4
+ (typeof easing === "string" && supportedWaapiEasing[easing]));
13
5
  }
6
+ const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
7
+ const supportedWaapiEasing = {
8
+ linear: "linear",
9
+ ease: "ease",
10
+ easeIn: "ease-in",
11
+ easeOut: "ease-out",
12
+ easeInOut: "ease-in-out",
13
+ circIn: cubicBezierAsString([0, 0.65, 0.55, 1]),
14
+ circOut: cubicBezierAsString([0.55, 0, 1, 0.45]),
15
+ backIn: cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
16
+ backOut: cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
17
+ };
14
18
  function mapEasingToNativeEasing(easing) {
15
19
  if (!easing)
16
20
  return undefined;
17
21
  return Array.isArray(easing)
18
22
  ? cubicBezierAsString(easing)
19
- : mapEasingName(easing);
23
+ : supportedWaapiEasing[easing];
20
24
  }
21
25
 
22
- export { cubicBezierAsString, mapEasingName, mapEasingToNativeEasing };
26
+ export { cubicBezierAsString, isWaapiSupportedEasing, mapEasingToNativeEasing, supportedWaapiEasing };
@@ -1,11 +1,5 @@
1
- import { createBackIn } from './back.mjs';
1
+ import { backIn } from './back.mjs';
2
2
 
3
- const createAnticipate = (power) => {
4
- const backEasing = createBackIn(power);
5
- return (p) => (p *= 2) < 1
6
- ? 0.5 * backEasing(p)
7
- : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
8
- };
9
- const anticipate = createAnticipate();
3
+ const anticipate = (p) => (p *= 2) < 1 ? 0.5 * backIn(p) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
10
4
 
11
5
  export { anticipate };
@@ -1,9 +1,9 @@
1
+ import { cubicBezier } from './cubic-bezier.mjs';
1
2
  import { mirrorEasing } from './modifiers/mirror.mjs';
2
3
  import { reverseEasing } from './modifiers/reverse.mjs';
3
4
 
4
- const createBackIn = (power = 1.525) => (p) => p * p * ((power + 1) * p - power);
5
- const backIn = createBackIn();
6
- const backOut = reverseEasing(backIn);
5
+ const backOut = cubicBezier(0.33, 1.53, 0.69, 0.99);
6
+ const backIn = reverseEasing(backOut);
7
7
  const backInOut = mirrorEasing(backIn);
8
8
 
9
- export { backIn, backInOut, backOut, createBackIn };
9
+ export { backIn, backInOut, backOut };
@@ -22,7 +22,7 @@ function updateMotionValuesFromProps(element, next, prev) {
22
22
  * and warn against mismatches.
23
23
  */
24
24
  if (process.env.NODE_ENV === "development") {
25
- warnOnce(nextValue.version === "7.10.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.10.0 may not work as expected.`);
25
+ warnOnce(nextValue.version === "7.10.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.10.2 may not work as expected.`);
26
26
  }
27
27
  }
28
28
  else if (isMotionValue(prevValue)) {
@@ -25,7 +25,7 @@ class MotionValue {
25
25
  * This will be replaced by the build step with the latest version number.
26
26
  * When MotionValues are provided to motion components, warn if versions are mixed.
27
27
  */
28
- this.version = "7.10.0";
28
+ this.version = "7.10.2";
29
29
  /**
30
30
  * Duration, in milliseconds, since last updating frame.
31
31
  *
@@ -2122,7 +2122,7 @@
2122
2122
  * This will be replaced by the build step with the latest version number.
2123
2123
  * When MotionValues are provided to motion components, warn if versions are mixed.
2124
2124
  */
2125
- this.version = "7.10.0";
2125
+ this.version = "7.10.2";
2126
2126
  /**
2127
2127
  * Duration, in milliseconds, since last updating frame.
2128
2128
  *
@@ -3167,18 +3167,11 @@
3167
3167
  const circOut = reverseEasing(circIn);
3168
3168
  const circInOut = mirrorEasing(circOut);
3169
3169
 
3170
- const createBackIn = (power = 1.525) => (p) => p * p * ((power + 1) * p - power);
3171
- const backIn = createBackIn();
3172
- const backOut = reverseEasing(backIn);
3170
+ const backOut = cubicBezier(0.33, 1.53, 0.69, 0.99);
3171
+ const backIn = reverseEasing(backOut);
3173
3172
  const backInOut = mirrorEasing(backIn);
3174
3173
 
3175
- const createAnticipate = (power) => {
3176
- const backEasing = createBackIn(power);
3177
- return (p) => (p *= 2) < 1
3178
- ? 0.5 * backEasing(p)
3179
- : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
3180
- };
3181
- const anticipate = createAnticipate();
3174
+ const anticipate = (p) => (p *= 2) < 1 ? 0.5 * backIn(p) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
3182
3175
 
3183
3176
  const easingLookup = {
3184
3177
  linear: noop,
@@ -3621,28 +3614,34 @@
3621
3614
  driverControls.stop();
3622
3615
  },
3623
3616
  sample: (t) => {
3624
- return animation.next(Math.max(0, t)).value;
3617
+ return animation.next(Math.max(0, t));
3625
3618
  },
3626
3619
  };
3627
3620
  }
3628
3621
 
3629
- const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
3630
- const validWaapiEasing = new Set([
3631
- "linear",
3632
- "ease-in",
3633
- "ease-out",
3634
- "ease-in-out",
3635
- ]);
3636
- function mapEasingName(easingName) {
3637
- const name = camelToDash(easingName);
3638
- return validWaapiEasing.has(name) ? name : "ease";
3622
+ function isWaapiSupportedEasing(easing) {
3623
+ return (!easing || // Default easing
3624
+ Array.isArray(easing) || // Bezier curve
3625
+ (typeof easing === "string" && supportedWaapiEasing[easing]));
3639
3626
  }
3627
+ const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
3628
+ const supportedWaapiEasing = {
3629
+ linear: "linear",
3630
+ ease: "ease",
3631
+ easeIn: "ease-in",
3632
+ easeOut: "ease-out",
3633
+ easeInOut: "ease-in-out",
3634
+ circIn: cubicBezierAsString([0, 0.65, 0.55, 1]),
3635
+ circOut: cubicBezierAsString([0.55, 0, 1, 0.45]),
3636
+ backIn: cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
3637
+ backOut: cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
3638
+ };
3640
3639
  function mapEasingToNativeEasing(easing) {
3641
3640
  if (!easing)
3642
3641
  return undefined;
3643
3642
  return Array.isArray(easing)
3644
3643
  ? cubicBezierAsString(easing)
3645
- : mapEasingName(easing);
3644
+ : supportedWaapiEasing[easing];
3646
3645
  }
3647
3646
 
3648
3647
  function animateStyle(element, valueName, keyframes, { delay = 0, duration, repeat = 0, repeatType = "loop", ease, times, } = {}) {
@@ -3665,23 +3664,19 @@
3665
3664
  function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ...options }) {
3666
3665
  let { keyframes, duration = 0.3, elapsed = 0, ease } = options;
3667
3666
  /**
3668
- * If this is a spring animation, pre-generate keyframes and
3669
- * record duration.
3670
- *
3671
- * TODO: When introducing support for values beyond opacity it
3672
- * might be better to use `animate.sample()`
3667
+ * If this animation needs pre-generated keyframes then generate.
3673
3668
  */
3674
- if (options.type === "spring") {
3675
- const springAnimation = spring(options);
3669
+ if (options.type === "spring" || !isWaapiSupportedEasing(options.ease)) {
3670
+ const sampleAnimation = animate$1(options);
3676
3671
  let state = { done: false, value: keyframes[0] };
3677
- const springKeyframes = [];
3672
+ const pregeneratedKeyframes = [];
3678
3673
  let t = 0;
3679
3674
  while (!state.done) {
3680
- state = springAnimation.next(t);
3681
- springKeyframes.push(state.value);
3675
+ state = sampleAnimation.sample(t);
3676
+ pregeneratedKeyframes.push(state.value);
3682
3677
  t += sampleDelta;
3683
3678
  }
3684
- keyframes = springKeyframes;
3679
+ keyframes = pregeneratedKeyframes;
3685
3680
  duration = t - sampleDelta;
3686
3681
  ease = "linear";
3687
3682
  }
@@ -3726,7 +3721,7 @@
3726
3721
  const { currentTime } = animation;
3727
3722
  if (currentTime) {
3728
3723
  const sampleAnimation = animate$1(options);
3729
- value.setWithVelocity(sampleAnimation.sample(currentTime - sampleDelta), sampleAnimation.sample(currentTime), sampleDelta);
3724
+ value.setWithVelocity(sampleAnimation.sample(currentTime - sampleDelta).value, sampleAnimation.sample(currentTime).value, sampleDelta);
3730
3725
  }
3731
3726
  sync.update(() => animation.cancel());
3732
3727
  };
@@ -4082,7 +4077,6 @@
4082
4077
  !options.repeatDelay &&
4083
4078
  options.repeatType !== "mirror" &&
4084
4079
  options.damping !== 0 &&
4085
- typeof options.ease !== "function" &&
4086
4080
  visualElement &&
4087
4081
  element instanceof HTMLElement &&
4088
4082
  !visualElement.getProps().onUpdate;
@@ -5951,7 +5945,7 @@
5951
5945
  * and warn against mismatches.
5952
5946
  */
5953
5947
  {
5954
- warnOnce(nextValue.version === "7.10.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.10.0 may not work as expected.`);
5948
+ warnOnce(nextValue.version === "7.10.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.10.2 may not work as expected.`);
5955
5949
  }
5956
5950
  }
5957
5951
  else if (isMotionValue(prevValue)) {