framer-motion 10.0.0 → 10.1.0-alpha.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.
package/dist/cjs/index.js CHANGED
@@ -37,9 +37,6 @@ const MotionConfigContext = React.createContext({
37
37
  });
38
38
 
39
39
  const MotionContext = React.createContext({});
40
- function useVisualElementContext() {
41
- return React.useContext(MotionContext).visualElement;
42
- }
43
40
 
44
41
  /**
45
42
  * @public
@@ -53,7 +50,7 @@ const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useE
53
50
  const LazyContext = React.createContext({ strict: false });
54
51
 
55
52
  function useVisualElement(Component, visualState, props, createVisualElement) {
56
- const parent = useVisualElementContext();
53
+ const { visualElement: parent } = React.useContext(MotionContext);
57
54
  const lazyContext = React.useContext(LazyContext);
58
55
  const presenceContext = React.useContext(PresenceContext);
59
56
  const reducedMotionConfig = React.useContext(MotionConfigContext).reducedMotion;
@@ -193,13 +190,13 @@ function variantLabelsAsDependency(prop) {
193
190
  const featureProps = {
194
191
  animation: [
195
192
  "animate",
196
- "exit",
197
193
  "variants",
198
194
  "whileHover",
199
195
  "whileTap",
196
+ "exit",
197
+ "whileInView",
200
198
  "whileFocus",
201
199
  "whileDrag",
202
- "whileInView",
203
200
  ],
204
201
  exit: ["exit"],
205
202
  drag: ["drag", "dragControls"],
@@ -1987,7 +1984,7 @@ class MotionValue {
1987
1984
  * This will be replaced by the build step with the latest version number.
1988
1985
  * When MotionValues are provided to motion components, warn if versions are mixed.
1989
1986
  */
1990
- this.version = "10.0.0";
1987
+ this.version = "10.1.0-alpha.0";
1991
1988
  /**
1992
1989
  * Duration, in milliseconds, since last updating frame.
1993
1990
  *
@@ -3519,9 +3516,19 @@ function animateValue({ duration, driver = framesync, elapsed = 0, repeat: repea
3519
3516
  * animate() can't yet be sampled for time, instead it
3520
3517
  * consumes time. So to sample it we have to run a low
3521
3518
  * temporal-resolution version.
3519
+ *
3520
+ * isControlled should be set to true if sample is being run within
3521
+ * a loop. This indicates that we're not arbitrarily sampling
3522
+ * the animation but running it one step after another. Therefore
3523
+ * we don't need to run a low-res version here. This is a stop-gap
3524
+ * until a rewrite can sample for time.
3522
3525
  */
3523
- sample: (t) => {
3526
+ sample: (t, isControlled = false) => {
3524
3527
  elapsed = initialElapsed;
3528
+ if (isControlled) {
3529
+ update(t);
3530
+ return state;
3531
+ }
3525
3532
  const sampleResolution = duration && typeof duration === "number"
3526
3533
  ? Math.max(duration * 0.5, 50)
3527
3534
  : 50;
@@ -3641,7 +3648,7 @@ function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ..
3641
3648
  */
3642
3649
  let t = 0;
3643
3650
  while (!state.done && t < 20000) {
3644
- state = sampleAnimation.sample(t);
3651
+ state = sampleAnimation.sample(t, true);
3645
3652
  pregeneratedKeyframes.push(state.value);
3646
3653
  t += sampleDelta;
3647
3654
  }
@@ -7830,7 +7837,7 @@ function updateMotionValuesFromProps(element, next, prev) {
7830
7837
  * and warn against mismatches.
7831
7838
  */
7832
7839
  if (process.env.NODE_ENV === "development") {
7833
- warnOnce(nextValue.version === "10.0.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.0.0 may not work as expected.`);
7840
+ warnOnce(nextValue.version === "10.1.0-alpha.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.1.0-alpha.0 may not work as expected.`);
7834
7841
  }
7835
7842
  }
7836
7843
  else if (isMotionValue(prevValue)) {
@@ -10639,7 +10646,7 @@ let hasWarned = false;
10639
10646
  function useInvertedScale(scale) {
10640
10647
  let parentScaleX = useMotionValue(1);
10641
10648
  let parentScaleY = useMotionValue(1);
10642
- const visualElement = useVisualElementContext();
10649
+ const { visualElement } = React.useContext(MotionContext);
10643
10650
  exports.invariant(!!(scale || visualElement), "If no scale values are provided, useInvertedScale must be used within a child of another motion component.");
10644
10651
  exports.warning(hasWarned, "useInvertedScale is deprecated and will be removed in 3.0. Use the layout prop instead.");
10645
10652
  hasWarned = true;
@@ -10766,6 +10773,5 @@ exports.useTransform = useTransform;
10766
10773
  exports.useUnmountEffect = useUnmountEffect;
10767
10774
  exports.useVelocity = useVelocity;
10768
10775
  exports.useViewportScroll = useViewportScroll;
10769
- exports.useVisualElementContext = useVisualElementContext;
10770
10776
  exports.useWillChange = useWillChange;
10771
10777
  exports.wrap = wrap;
@@ -132,9 +132,19 @@ function animateValue({ duration, driver = framesync, elapsed = 0, repeat: repea
132
132
  * animate() can't yet be sampled for time, instead it
133
133
  * consumes time. So to sample it we have to run a low
134
134
  * temporal-resolution version.
135
+ *
136
+ * isControlled should be set to true if sample is being run within
137
+ * a loop. This indicates that we're not arbitrarily sampling
138
+ * the animation but running it one step after another. Therefore
139
+ * we don't need to run a low-res version here. This is a stop-gap
140
+ * until a rewrite can sample for time.
135
141
  */
136
- sample: (t) => {
142
+ sample: (t, isControlled = false) => {
137
143
  elapsed = initialElapsed;
144
+ if (isControlled) {
145
+ update(t);
146
+ return state;
147
+ }
138
148
  const sampleResolution = duration && typeof duration === "number"
139
149
  ? Math.max(duration * 0.5, 50)
140
150
  : 50;
@@ -50,7 +50,7 @@ function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ..
50
50
  */
51
51
  let t = 0;
52
52
  while (!state.done && t < 20000) {
53
- state = sampleAnimation.sample(t);
53
+ state = sampleAnimation.sample(t, true);
54
54
  pregeneratedKeyframes.push(state.value);
55
55
  t += sampleDelta;
56
56
  }
@@ -1,8 +1,5 @@
1
- import { createContext, useContext } from 'react';
1
+ import { createContext } from 'react';
2
2
 
3
3
  const MotionContext = createContext({});
4
- function useVisualElementContext() {
5
- return useContext(MotionContext).visualElement;
6
- }
7
4
 
8
- export { MotionContext, useVisualElementContext };
5
+ export { MotionContext };
package/dist/es/index.mjs CHANGED
@@ -63,7 +63,7 @@ export { px } from './value/types/numbers/units.mjs';
63
63
  export { startOptimizedAppearAnimation } from './animation/optimized-appear/start.mjs';
64
64
  export { optimizedAppearDataAttribute } from './animation/optimized-appear/data-id.mjs';
65
65
  export { spring } from './animation/legacy-popmotion/spring.mjs';
66
- export { MotionContext, useVisualElementContext } from './context/MotionContext/index.mjs';
66
+ export { MotionContext } from './context/MotionContext/index.mjs';
67
67
  export { MotionConfigContext } from './context/MotionConfigContext.mjs';
68
68
  export { PresenceContext } from './context/PresenceContext.mjs';
69
69
  export { LayoutGroupContext } from './context/LayoutGroupContext.mjs';
@@ -1,13 +1,13 @@
1
1
  const featureProps = {
2
2
  animation: [
3
3
  "animate",
4
- "exit",
5
4
  "variants",
6
5
  "whileHover",
7
6
  "whileTap",
7
+ "exit",
8
+ "whileInView",
8
9
  "whileFocus",
9
10
  "whileDrag",
10
- "whileInView",
11
11
  ],
12
12
  exit: ["exit"],
13
13
  drag: ["drag", "dragControls"],
@@ -1,12 +1,12 @@
1
1
  import { useContext, useRef, useInsertionEffect, useEffect } from 'react';
2
2
  import { PresenceContext } from '../../context/PresenceContext.mjs';
3
- import { useVisualElementContext } from '../../context/MotionContext/index.mjs';
3
+ import { MotionContext } from '../../context/MotionContext/index.mjs';
4
4
  import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
5
5
  import { LazyContext } from '../../context/LazyContext.mjs';
6
6
  import { MotionConfigContext } from '../../context/MotionConfigContext.mjs';
7
7
 
8
8
  function useVisualElement(Component, visualState, props, createVisualElement) {
9
- const parent = useVisualElementContext();
9
+ const { visualElement: parent } = useContext(MotionContext);
10
10
  const lazyContext = useContext(LazyContext);
11
11
  const presenceContext = useContext(PresenceContext);
12
12
  const reducedMotionConfig = useContext(MotionConfigContext).reducedMotion;
@@ -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 === "10.0.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.0.0 may not work as expected.`);
25
+ warnOnce(nextValue.version === "10.1.0-alpha.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.1.0-alpha.0 may not work as expected.`);
26
26
  }
27
27
  }
28
28
  else if (isMotionValue(prevValue)) {
@@ -26,7 +26,7 @@ class MotionValue {
26
26
  * This will be replaced by the build step with the latest version number.
27
27
  * When MotionValues are provided to motion components, warn if versions are mixed.
28
28
  */
29
- this.version = "10.0.0";
29
+ this.version = "10.1.0-alpha.0";
30
30
  /**
31
31
  * Duration, in milliseconds, since last updating frame.
32
32
  *
@@ -1,7 +1,8 @@
1
1
  import { useTransform } from './use-transform.mjs';
2
2
  import { invariant, warning } from '../utils/errors.mjs';
3
3
  import { useMotionValue } from './use-motion-value.mjs';
4
- import { useVisualElementContext } from '../context/MotionContext/index.mjs';
4
+ import { MotionContext } from '../context/MotionContext/index.mjs';
5
+ import { useContext } from 'react';
5
6
 
6
7
  // Keep things reasonable and avoid scale: Infinity. In practise we might need
7
8
  // to add another value, opacity, that could interpolate scaleX/Y [0,0.01] => [0,1]
@@ -31,7 +32,7 @@ let hasWarned = false;
31
32
  function useInvertedScale(scale) {
32
33
  let parentScaleX = useMotionValue(1);
33
34
  let parentScaleY = useMotionValue(1);
34
- const visualElement = useVisualElementContext();
35
+ const { visualElement } = useContext(MotionContext);
35
36
  invariant(!!(scale || visualElement), "If no scale values are provided, useInvertedScale must be used within a child of another motion component.");
36
37
  warning(hasWarned, "useInvertedScale is deprecated and will be removed in 3.0. Use the layout prop instead.");
37
38
  hasWarned = true;
@@ -37,9 +37,6 @@
37
37
  });
38
38
 
39
39
  const MotionContext = React.createContext({});
40
- function useVisualElementContext() {
41
- return React.useContext(MotionContext).visualElement;
42
- }
43
40
 
44
41
  /**
45
42
  * @public
@@ -53,7 +50,7 @@
53
50
  const LazyContext = React.createContext({ strict: false });
54
51
 
55
52
  function useVisualElement(Component, visualState, props, createVisualElement) {
56
- const parent = useVisualElementContext();
53
+ const { visualElement: parent } = React.useContext(MotionContext);
57
54
  const lazyContext = React.useContext(LazyContext);
58
55
  const presenceContext = React.useContext(PresenceContext);
59
56
  const reducedMotionConfig = React.useContext(MotionConfigContext).reducedMotion;
@@ -193,13 +190,13 @@
193
190
  const featureProps = {
194
191
  animation: [
195
192
  "animate",
196
- "exit",
197
193
  "variants",
198
194
  "whileHover",
199
195
  "whileTap",
196
+ "exit",
197
+ "whileInView",
200
198
  "whileFocus",
201
199
  "whileDrag",
202
- "whileInView",
203
200
  ],
204
201
  exit: ["exit"],
205
202
  drag: ["drag", "dragControls"],
@@ -1987,7 +1984,7 @@
1987
1984
  * This will be replaced by the build step with the latest version number.
1988
1985
  * When MotionValues are provided to motion components, warn if versions are mixed.
1989
1986
  */
1990
- this.version = "10.0.0";
1987
+ this.version = "10.1.0-alpha.0";
1991
1988
  /**
1992
1989
  * Duration, in milliseconds, since last updating frame.
1993
1990
  *
@@ -3519,9 +3516,19 @@
3519
3516
  * animate() can't yet be sampled for time, instead it
3520
3517
  * consumes time. So to sample it we have to run a low
3521
3518
  * temporal-resolution version.
3519
+ *
3520
+ * isControlled should be set to true if sample is being run within
3521
+ * a loop. This indicates that we're not arbitrarily sampling
3522
+ * the animation but running it one step after another. Therefore
3523
+ * we don't need to run a low-res version here. This is a stop-gap
3524
+ * until a rewrite can sample for time.
3522
3525
  */
3523
- sample: (t) => {
3526
+ sample: (t, isControlled = false) => {
3524
3527
  elapsed = initialElapsed;
3528
+ if (isControlled) {
3529
+ update(t);
3530
+ return state;
3531
+ }
3525
3532
  const sampleResolution = duration && typeof duration === "number"
3526
3533
  ? Math.max(duration * 0.5, 50)
3527
3534
  : 50;
@@ -3641,7 +3648,7 @@
3641
3648
  */
3642
3649
  let t = 0;
3643
3650
  while (!state.done && t < 20000) {
3644
- state = sampleAnimation.sample(t);
3651
+ state = sampleAnimation.sample(t, true);
3645
3652
  pregeneratedKeyframes.push(state.value);
3646
3653
  t += sampleDelta;
3647
3654
  }
@@ -7830,7 +7837,7 @@
7830
7837
  * and warn against mismatches.
7831
7838
  */
7832
7839
  {
7833
- warnOnce(nextValue.version === "10.0.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.0.0 may not work as expected.`);
7840
+ warnOnce(nextValue.version === "10.1.0-alpha.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.1.0-alpha.0 may not work as expected.`);
7834
7841
  }
7835
7842
  }
7836
7843
  else if (isMotionValue(prevValue)) {
@@ -10637,7 +10644,7 @@
10637
10644
  function useInvertedScale(scale) {
10638
10645
  let parentScaleX = useMotionValue(1);
10639
10646
  let parentScaleY = useMotionValue(1);
10640
- const visualElement = useVisualElementContext();
10647
+ const { visualElement } = React.useContext(MotionContext);
10641
10648
  exports.invariant(!!(scale || visualElement), "If no scale values are provided, useInvertedScale must be used within a child of another motion component.");
10642
10649
  exports.warning(hasWarned, "useInvertedScale is deprecated and will be removed in 3.0. Use the layout prop instead.");
10643
10650
  hasWarned = true;
@@ -10764,7 +10771,6 @@
10764
10771
  exports.useUnmountEffect = useUnmountEffect;
10765
10772
  exports.useVelocity = useVelocity;
10766
10773
  exports.useViewportScroll = useViewportScroll;
10767
- exports.useVisualElementContext = useVisualElementContext;
10768
10774
  exports.useWillChange = useWillChange;
10769
10775
  exports.wrap = wrap;
10770
10776