framer-motion 6.5.1 → 7.0.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.
Files changed (31) hide show
  1. package/README.md +14 -11
  2. package/dist/cjs/index.js +19 -25
  3. package/dist/es/components/AnimatePresence/PresenceChild.mjs +1 -2
  4. package/dist/es/components/AnimatePresence/use-presence.mjs +1 -2
  5. package/dist/es/context/MotionContext/create.mjs +1 -1
  6. package/dist/es/gestures/PanSession.mjs +1 -1
  7. package/dist/es/gestures/drag/VisualElementDragControls.mjs +2 -1
  8. package/dist/es/gestures/drag/utils/constraints.mjs +1 -1
  9. package/dist/es/projection/animation/mix-values.mjs +2 -2
  10. package/dist/es/projection/node/create-projection-node.mjs +1 -1
  11. package/dist/es/render/dom/utils/unit-conversion.mjs +1 -1
  12. package/dist/es/render/html/visual-element.mjs +1 -1
  13. package/dist/es/render/utils/motion-values.mjs +1 -1
  14. package/dist/es/utils/use-animation-frame.mjs +5 -7
  15. package/dist/es/value/index.mjs +1 -1
  16. package/dist/es/value/scroll/use-element-scroll.mjs +3 -0
  17. package/dist/es/value/scroll/use-viewport-scroll.mjs +3 -0
  18. package/dist/framer-motion.dev.js +51 -80
  19. package/dist/framer-motion.js +1 -1
  20. package/dist/index.d.ts +23 -7
  21. package/dist/projection.dev.js +7 -7
  22. package/dist/size-rollup-dom-animation.js +1 -1
  23. package/dist/size-rollup-dom-max.js +1 -1
  24. package/dist/size-webpack-dom-animation.js +1 -1
  25. package/dist/size-webpack-dom-max.js +1 -2
  26. package/dist/size-webpack-m.js +0 -1
  27. package/dist/three-entry.d.ts +2 -2
  28. package/package.json +17 -24
  29. package/dist/es/utils/use-id.mjs +0 -15
  30. package/dist/size-webpack-dom-max.js.LICENSE.txt +0 -14
  31. package/dist/size-webpack-m.js.LICENSE.txt +0 -14
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  <p align="center">
2
- <img src="https://user-images.githubusercontent.com/22095598/123793419-f5528800-d8e1-11eb-8c5f-e2dad45a9c81.png" width="108" height="108" alt="Framer Motion" />
2
+ <img src="https://framerusercontent.com/images/48ha9ZR9oZQGQ6gZ8YUfElP3T0A.png" width="50" height="50" alt="Framer Motion Icon" />
3
3
  </p>
4
4
  <h1 align="center">Framer Motion</h1>
5
5
  <h3 align="center">
6
- An open source and production-ready motion<br>library for React on the web.
6
+ An open source motion library for React, <a href="https://www.framer.com">made by Framer</a>.
7
7
  </h3>
8
8
 
9
9
  <br>
@@ -25,7 +25,7 @@
25
25
 
26
26
  <br>
27
27
 
28
- Framer Motion is an open source, production-ready library that's designed for all creative developers.
28
+ Framer Motion is an open source, production-ready library thats designed for all creative developers.
29
29
 
30
30
  It looks like this:
31
31
 
@@ -52,10 +52,14 @@ It does all this:
52
52
 
53
53
  ### 🐇 Quick start
54
54
 
55
+ Install `framer-motion` with via your package manager:
56
+
55
57
  ```
56
58
  npm install framer-motion
57
59
  ```
58
60
 
61
+ Then import the `motion` component:
62
+
59
63
  ```jsx
60
64
  import { motion } from "framer-motion"
61
65
 
@@ -66,18 +70,17 @@ export const MyComponent = ({ isVisible }) => (
66
70
 
67
71
  ### 📚 Docs
68
72
 
69
- Check out [our documentation](https://www.framer.com/docs/) for guides and a full API reference.
70
-
71
- Or checkout [our examples](https://www.framer.com/docs/examples/) for inspiration.
73
+ - Check out [our documentation](https://www.framer.com/docs/) for guides and a full API reference.
74
+ - Or see [our examples](https://www.framer.com/docs/examples/) for inspiration.
72
75
 
73
- ### 🛠 Contribute
76
+ ### 💎 Contribute
74
77
 
75
- Want to contribute to Framer Motion? Our [contributing guide](https://github.com/framer/motion/blob/master/CONTRIBUTING.md) has you covered.
78
+ - Want to contribute to Framer Motion? Our [contributing guide](https://github.com/framer/motion/blob/master/CONTRIBUTING.md) has you covered.
76
79
 
77
80
  ### 👩🏻‍⚖️ License
78
81
 
79
- Framer Motion is MIT licensed.
82
+ - Framer Motion is MIT licensed.
80
83
 
81
- ## Framer
84
+ ### Framer
82
85
 
83
- Get on the same page as your designers before production. Get started with [design and prototyping in Framer](https://www.framer.com/).
86
+ - Design and publish sites that inspire. [Try Framer for free](https://www.framer.com/).
package/dist/cjs/index.js CHANGED
@@ -1929,18 +1929,6 @@ var gestureAnimations = {
1929
1929
  hover: makeRenderlessComponent(useHoverGesture),
1930
1930
  };
1931
1931
 
1932
- var counter = 0;
1933
- var incrementId = function () { return counter++; };
1934
- var useId = function () { return useConstant(incrementId); };
1935
- /**
1936
- * Ideally we'd use the following code to support React 18 optionally.
1937
- * But this fairly fails in Webpack (otherwise treeshaking wouldn't work at all).
1938
- * Need to come up with a different way of figuring this out.
1939
- */
1940
- // export const useId = (React as any).useId
1941
- // ? (React as any).useId
1942
- // : () => useConstant(incrementId)
1943
-
1944
1932
  /**
1945
1933
  * When a component is the child of `AnimatePresence`, it can use `usePresence`
1946
1934
  * to access information about whether it's still present in the React tree.
@@ -1972,7 +1960,7 @@ function usePresence() {
1972
1960
  // It's safe to call the following hooks conditionally (after an early return) because the context will always
1973
1961
  // either be null or non-null for the lifespan of the component.
1974
1962
  // Replace with useId when released in React
1975
- var id = useId();
1963
+ var id = React.useId();
1976
1964
  React.useEffect(function () { return register(id); }, []);
1977
1965
  var safeToRemove = function () { return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id); };
1978
1966
  return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
@@ -2449,7 +2437,7 @@ var MotionValue = /** @class */ (function () {
2449
2437
  * This will be replaced by the build step with the latest version number.
2450
2438
  * When MotionValues are provided to motion components, warn if versions are mixed.
2451
2439
  */
2452
- this.version = "6.5.1";
2440
+ this.version = "7.0.2";
2453
2441
  /**
2454
2442
  * Duration, in milliseconds, since last updating frame.
2455
2443
  *
@@ -3375,8 +3363,8 @@ var animations = {
3375
3363
  */
3376
3364
  var PanSession = /** @class */ (function () {
3377
3365
  function PanSession(event, handlers, _a) {
3378
- var _this = this;
3379
3366
  var _b = _a === void 0 ? {} : _a, transformPagePoint = _b.transformPagePoint;
3367
+ var _this = this;
3380
3368
  /**
3381
3369
  * @internal
3382
3370
  */
@@ -4247,7 +4235,7 @@ var VisualElementDragControls = /** @class */ (function () {
4247
4235
  * If the element's layout changes, calculate the delta and apply that to
4248
4236
  * the drag gesture's origin point.
4249
4237
  */
4250
- projection.addEventListener("didUpdate", (function (_a) {
4238
+ var stopLayoutUpdateListener = projection.addEventListener("didUpdate", (function (_a) {
4251
4239
  var delta = _a.delta, hasLayoutChanged = _a.hasLayoutChanged;
4252
4240
  if (_this.isDragging && hasLayoutChanged) {
4253
4241
  eachAxis(function (axis) {
@@ -4264,6 +4252,7 @@ var VisualElementDragControls = /** @class */ (function () {
4264
4252
  stopResizeListener();
4265
4253
  stopPointerListener();
4266
4254
  stopMeasureLayoutListener();
4255
+ stopLayoutUpdateListener === null || stopLayoutUpdateListener === void 0 ? void 0 : stopLayoutUpdateListener();
4267
4256
  };
4268
4257
  };
4269
4258
  VisualElementDragControls.prototype.getProps = function () {
@@ -4418,7 +4407,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4418
4407
  * and warn against mismatches.
4419
4408
  */
4420
4409
  if (process.env.NODE_ENV === "development") {
4421
- warnOnce(nextValue.version === "6.5.1", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.5.1 may not work as expected."));
4410
+ warnOnce(nextValue.version === "7.0.2", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.0.2 may not work as expected."));
4422
4411
  }
4423
4412
  }
4424
4413
  else if (isMotionValue(prevValue)) {
@@ -5257,9 +5246,9 @@ var htmlConfig = {
5257
5246
  * can be animated by Motion.
5258
5247
  */
5259
5248
  makeTargetAnimatable: function (element, _a, _b, isMounted) {
5249
+ var transition = _a.transition, transitionEnd = _a.transitionEnd, target = tslib.__rest(_a, ["transition", "transitionEnd"]);
5260
5250
  var transformValues = _b.transformValues;
5261
5251
  if (isMounted === void 0) { isMounted = true; }
5262
- var transition = _a.transition, transitionEnd = _a.transitionEnd, target = tslib.__rest(_a, ["transition", "transitionEnd"]);
5263
5252
  var origin = getOrigin(target, transition || {}, element);
5264
5253
  /**
5265
5254
  * If Framer has provided a function to convert `Color` etc value types, convert them
@@ -5919,9 +5908,9 @@ function createProjectionNode(_a) {
5919
5908
  var attachResizeListener = _a.attachResizeListener, defaultParent = _a.defaultParent, measureScroll = _a.measureScroll, checkIsScrollRoot = _a.checkIsScrollRoot, resetTransform = _a.resetTransform;
5920
5909
  return /** @class */ (function () {
5921
5910
  function ProjectionNode(id, latestValues, parent) {
5922
- var _this = this;
5923
5911
  if (latestValues === void 0) { latestValues = {}; }
5924
5912
  if (parent === void 0) { parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent(); }
5913
+ var _this = this;
5925
5914
  /**
5926
5915
  * A Set containing all this component's children. This is used to iterate
5927
5916
  * through the children.
@@ -7189,7 +7178,7 @@ function useForceUpdate() {
7189
7178
  var PresenceChild = function (_a) {
7190
7179
  var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
7191
7180
  var presenceChildren = useConstant(newChildrenMap);
7192
- var id = useId();
7181
+ var id = React.useId();
7193
7182
  var context = React.useMemo(function () { return ({
7194
7183
  id: id,
7195
7184
  initial: initial,
@@ -7909,28 +7898,33 @@ function useScroll(_a) {
7909
7898
  return values;
7910
7899
  }
7911
7900
 
7901
+ /**
7902
+ * @deprecated useElementScroll is deprecated. Convert to useScroll({ container: ref })
7903
+ */
7912
7904
  function useElementScroll(ref) {
7913
7905
  warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
7914
7906
  return useScroll({ container: ref });
7915
7907
  }
7916
7908
 
7909
+ /**
7910
+ * @deprecated useViewportScroll is deprecated. Convert to useScroll()
7911
+ */
7917
7912
  function useViewportScroll() {
7918
7913
  warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
7919
7914
  return useScroll();
7920
7915
  }
7921
7916
 
7922
- var getCurrentTime = typeof performance !== "undefined"
7923
- ? function () { return performance.now(); }
7924
- : function () { return Date.now(); };
7925
7917
  function useAnimationFrame(callback) {
7926
- var initialTimestamp = useConstant(getCurrentTime);
7918
+ var initialTimestamp = React.useRef(0);
7927
7919
  var isStatic = React.useContext(MotionConfigContext).isStatic;
7928
7920
  React.useEffect(function () {
7929
7921
  if (isStatic)
7930
7922
  return;
7931
7923
  var provideTimeSinceStart = function (_a) {
7932
7924
  var timestamp = _a.timestamp;
7933
- callback(timestamp - initialTimestamp);
7925
+ if (!initialTimestamp.current)
7926
+ initialTimestamp.current = timestamp;
7927
+ callback(timestamp - initialTimestamp.current);
7934
7928
  };
7935
7929
  sync__default["default"].update(provideTimeSinceStart, true);
7936
7930
  return function () { return sync.cancelSync.update(provideTimeSinceStart); };
@@ -1,9 +1,8 @@
1
1
  import { __values } from 'tslib';
2
2
  import * as React from 'react';
3
- import { useMemo } from 'react';
3
+ import { useId, useMemo } from 'react';
4
4
  import { PresenceContext } from '../../context/PresenceContext.mjs';
5
5
  import { useConstant } from '../../utils/use-constant.mjs';
6
- import { useId } from '../../utils/use-id.mjs';
7
6
 
8
7
  var PresenceChild = function (_a) {
9
8
  var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
@@ -1,6 +1,5 @@
1
- import { useContext, useEffect } from 'react';
1
+ import { useContext, useId, useEffect } from 'react';
2
2
  import { PresenceContext } from '../../context/PresenceContext.mjs';
3
- import { useId } from '../../utils/use-id.mjs';
4
3
 
5
4
  /**
6
5
  * When a component is the child of `AnimatePresence`, it can use `usePresence`
@@ -1,4 +1,4 @@
1
- import { useMemo, useContext } from 'react';
1
+ import { useContext, useMemo } from 'react';
2
2
  import { MotionContext } from './index.mjs';
3
3
  import { getCurrentTreeVariants } from './utils.mjs';
4
4
 
@@ -11,8 +11,8 @@ import { distance, pipe } from 'popmotion';
11
11
  */
12
12
  var PanSession = /** @class */ (function () {
13
13
  function PanSession(event, handlers, _a) {
14
- var _this = this;
15
14
  var _b = _a === void 0 ? {} : _a, transformPagePoint = _b.transformPagePoint;
15
+ var _this = this;
16
16
  /**
17
17
  * @internal
18
18
  */
@@ -394,7 +394,7 @@ var VisualElementDragControls = /** @class */ (function () {
394
394
  * If the element's layout changes, calculate the delta and apply that to
395
395
  * the drag gesture's origin point.
396
396
  */
397
- projection.addEventListener("didUpdate", (function (_a) {
397
+ var stopLayoutUpdateListener = projection.addEventListener("didUpdate", (function (_a) {
398
398
  var delta = _a.delta, hasLayoutChanged = _a.hasLayoutChanged;
399
399
  if (_this.isDragging && hasLayoutChanged) {
400
400
  eachAxis(function (axis) {
@@ -411,6 +411,7 @@ var VisualElementDragControls = /** @class */ (function () {
411
411
  stopResizeListener();
412
412
  stopPointerListener();
413
413
  stopMeasureLayoutListener();
414
+ stopLayoutUpdateListener === null || stopLayoutUpdateListener === void 0 ? void 0 : stopLayoutUpdateListener();
414
415
  };
415
416
  };
416
417
  VisualElementDragControls.prototype.getProps = function () {
@@ -1,5 +1,5 @@
1
1
  import { __read } from 'tslib';
2
- import { clamp, mix, progress } from 'popmotion';
2
+ import { mix, progress, clamp } from 'popmotion';
3
3
  import { calcLength } from '../../../projection/geometry/delta-calc.mjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { mix, progress, linear, circOut } from 'popmotion';
2
- import { px, percent } from 'style-value-types';
1
+ import { mix, progress, circOut, linear } from 'popmotion';
2
+ import { percent, px } from 'style-value-types';
3
3
 
4
4
  var borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
5
5
  var numBorders = borders.length;
@@ -30,9 +30,9 @@ function createProjectionNode(_a) {
30
30
  var attachResizeListener = _a.attachResizeListener, defaultParent = _a.defaultParent, measureScroll = _a.measureScroll, checkIsScrollRoot = _a.checkIsScrollRoot, resetTransform = _a.resetTransform;
31
31
  return /** @class */ (function () {
32
32
  function ProjectionNode(id, latestValues, parent) {
33
- var _this = this;
34
33
  if (latestValues === void 0) { latestValues = {}; }
35
34
  if (parent === void 0) { parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent(); }
35
+ var _this = this;
36
36
  /**
37
37
  * A Set containing all this component's children. This is used to iterate
38
38
  * through the children.
@@ -1,5 +1,5 @@
1
1
  import { __assign, __read } from 'tslib';
2
- import { number, px } from 'style-value-types';
2
+ import { px, number } from 'style-value-types';
3
3
  import { isKeyframesTarget } from '../../../animation/utils/is-keyframes-target.mjs';
4
4
  import { invariant } from 'hey-listen';
5
5
  import { transformProps } from '../../html/utils/transform.mjs';
@@ -71,9 +71,9 @@ var htmlConfig = {
71
71
  * can be animated by Motion.
72
72
  */
73
73
  makeTargetAnimatable: function (element, _a, _b, isMounted) {
74
+ var transition = _a.transition, transitionEnd = _a.transitionEnd, target = __rest(_a, ["transition", "transitionEnd"]);
74
75
  var transformValues = _b.transformValues;
75
76
  if (isMounted === void 0) { isMounted = true; }
76
- var transition = _a.transition, transitionEnd = _a.transitionEnd, target = __rest(_a, ["transition", "transitionEnd"]);
77
77
  var origin = getOrigin(target, transition || {}, element);
78
78
  /**
79
79
  * If Framer has provided a function to convert `Color` etc value types, convert them
@@ -18,7 +18,7 @@ function updateMotionValuesFromProps(element, next, prev) {
18
18
  * and warn against mismatches.
19
19
  */
20
20
  if (process.env.NODE_ENV === "development") {
21
- warnOnce(nextValue.version === "6.5.1", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.5.1 may not work as expected."));
21
+ warnOnce(nextValue.version === "7.0.2", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.0.2 may not work as expected."));
22
22
  }
23
23
  }
24
24
  else if (isMotionValue(prevValue)) {
@@ -1,20 +1,18 @@
1
1
  import sync, { cancelSync } from 'framesync';
2
- import { useContext, useEffect } from 'react';
3
- import { useConstant } from './use-constant.mjs';
2
+ import { useRef, useContext, useEffect } from 'react';
4
3
  import { MotionConfigContext } from '../context/MotionConfigContext.mjs';
5
4
 
6
- var getCurrentTime = typeof performance !== "undefined"
7
- ? function () { return performance.now(); }
8
- : function () { return Date.now(); };
9
5
  function useAnimationFrame(callback) {
10
- var initialTimestamp = useConstant(getCurrentTime);
6
+ var initialTimestamp = useRef(0);
11
7
  var isStatic = useContext(MotionConfigContext).isStatic;
12
8
  useEffect(function () {
13
9
  if (isStatic)
14
10
  return;
15
11
  var provideTimeSinceStart = function (_a) {
16
12
  var timestamp = _a.timestamp;
17
- callback(timestamp - initialTimestamp);
13
+ if (!initialTimestamp.current)
14
+ initialTimestamp.current = timestamp;
15
+ callback(timestamp - initialTimestamp.current);
18
16
  };
19
17
  sync.update(provideTimeSinceStart, true);
20
18
  return function () { return cancelSync.update(provideTimeSinceStart); };
@@ -25,7 +25,7 @@ var MotionValue = /** @class */ (function () {
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 = "6.5.1";
28
+ this.version = "7.0.2";
29
29
  /**
30
30
  * Duration, in milliseconds, since last updating frame.
31
31
  *
@@ -1,6 +1,9 @@
1
1
  import { warnOnce } from '../../utils/warn-once.mjs';
2
2
  import { useScroll } from '../use-scroll.mjs';
3
3
 
4
+ /**
5
+ * @deprecated useElementScroll is deprecated. Convert to useScroll({ container: ref })
6
+ */
4
7
  function useElementScroll(ref) {
5
8
  warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
6
9
  return useScroll({ container: ref });
@@ -1,6 +1,9 @@
1
1
  import { warnOnce } from '../../utils/warn-once.mjs';
2
2
  import { useScroll } from '../use-scroll.mjs';
3
3
 
4
+ /**
5
+ * @deprecated useViewportScroll is deprecated. Convert to useScroll()
6
+ */
4
7
  function useViewportScroll() {
5
8
  warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
6
9
  return useScroll();