framer-motion 5.4.1 → 5.4.4

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.
@@ -1,14 +1,68 @@
1
- import { __rest, __assign } from 'tslib';
1
+ import { __extends, __rest, __read, __assign } from 'tslib';
2
2
  import * as React from 'react';
3
- import { useContext } from 'react';
4
- import { Canvas } from '@react-three/fiber';
3
+ import { forwardRef, useContext } from 'react';
5
4
  import { MotionContext } from '../../context/MotionContext/index.mjs';
5
+ import mergeRefs from 'react-merge-refs';
6
+ import useMeasure from 'react-use-measure';
7
+ import { render, events, unmountComponentAtNode } from '@react-three/fiber';
8
+ import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
6
9
 
7
- function MotionCanvas(_a) {
8
- var children = _a.children, props = __rest(_a, ["children"]);
10
+ function Block(_a) {
11
+ var set = _a.set;
12
+ useIsomorphicLayoutEffect(function () {
13
+ set(new Promise(function () { return null; }));
14
+ return function () { return set(false); };
15
+ }, []);
16
+ return null;
17
+ }
18
+ var ErrorBoundary = /** @class */ (function (_super) {
19
+ __extends(ErrorBoundary, _super);
20
+ function ErrorBoundary() {
21
+ var _this = _super !== null && _super.apply(this, arguments) || this;
22
+ _this.state = { error: false };
23
+ return _this;
24
+ }
25
+ ErrorBoundary.prototype.componentDidCatch = function (error) {
26
+ this.props.set(error);
27
+ };
28
+ ErrorBoundary.prototype.render = function () {
29
+ return this.state.error ? null : this.props.children;
30
+ };
31
+ ErrorBoundary.getDerivedStateFromError = function () { return ({ error: true }); };
32
+ return ErrorBoundary;
33
+ }(React.Component));
34
+ /**
35
+ * A synchronously rendering version of R3F's Canvas component. We call render
36
+ * within the render function itself to ensure lifecycle events are called before
37
+ * parent reconcilers. This can be replaced with a simple MotionContext provider
38
+ * when R3F moves to the same model.
39
+ */
40
+ function SyncCanvasComponent(_a, forwardedRef) {
41
+ var children = _a.children, fallback = _a.fallback, tabIndex = _a.tabIndex, resize = _a.resize, id = _a.id, style = _a.style, className = _a.className, events$1 = _a.events, props = __rest(_a, ["children", "fallback", "tabIndex", "resize", "id", "style", "className", "events"]);
9
42
  var motionContext = useContext(MotionContext);
10
- return (React.createElement(Canvas, __assign({}, props),
11
- React.createElement(MotionContext.Provider, { value: motionContext }, children)));
43
+ var _b = __read(useMeasure(__assign({ scroll: true, debounce: { scroll: 50, resize: 0 } }, resize)), 2), containerRef = _b[0], _c = _b[1], width = _c.width, height = _c.height;
44
+ var canvasRef = React.useRef(null);
45
+ var _d = __read(React.useState(false), 2), block = _d[0], setBlock = _d[1];
46
+ var _e = __read(React.useState(false), 2), error = _e[0], setError = _e[1];
47
+ // Suspend this component if block is a promise (2nd run)
48
+ if (block)
49
+ throw block;
50
+ // Throw exception outwards if anything within canvas throws
51
+ if (error)
52
+ throw error;
53
+ // Execute JSX in the reconciler as a layout-effect
54
+ if (width > 0 && height > 0) {
55
+ render(React.createElement(ErrorBoundary, { set: setError },
56
+ React.createElement(React.Suspense, { fallback: React.createElement(Block, { set: setBlock }) },
57
+ React.createElement(MotionContext.Provider, { value: motionContext }, children))), canvasRef.current, __assign(__assign({}, props), { size: { width: width, height: height }, events: events$1 || events }));
58
+ }
59
+ useIsomorphicLayoutEffect(function () {
60
+ var container = canvasRef.current;
61
+ return function () { return unmountComponentAtNode(container); };
62
+ }, []);
63
+ return (React.createElement("div", { ref: containerRef, id: id, className: className, tabIndex: tabIndex, style: __assign({ position: "relative", width: "100%", height: "100%", overflow: "hidden" }, style) },
64
+ React.createElement("canvas", { ref: mergeRefs([canvasRef, forwardedRef]), style: { display: "block" } }, fallback)));
12
65
  }
66
+ var MotionCanvas = forwardRef(SyncCanvasComponent);
13
67
 
14
68
  export { MotionCanvas };
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "framer-motion",
3
- "version": "5.4.1",
3
+ "version": "5.4.4",
4
4
  "description": "A simple and powerful React animation library",
5
- "main": "dist/framer-motion.cjs.js",
5
+ "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.mjs",
7
7
  "exports": {
8
8
  ".": {
9
- "require": "./dist/framer-motion.cjs.js",
9
+ "require": "./dist/cjs/index.js",
10
10
  "import": "./dist/es/index.mjs",
11
- "default": "./dist/framer-motion.cjs.js"
11
+ "default": "./dist/cjs/index.js"
12
12
  },
13
13
  "./three": {
14
- "require": "./dist/framer-motion-three.cjs.js",
14
+ "require": "./dist/cjs/three-entry.js",
15
15
  "import": "./dist/es/three-entry.mjs",
16
- "default": "./dist/framer-motion-three.cjs.js"
16
+ "default": "./dist/cjs/three-entry.js"
17
17
  },
18
18
  "./package.json": "./package.json"
19
19
  },
@@ -135,6 +135,8 @@
135
135
  "framesync": "6.0.1",
136
136
  "hey-listen": "^1.0.8",
137
137
  "popmotion": "11.0.3",
138
+ "react-merge-refs": "^1.1.0",
139
+ "react-use-measure": "^2.1.1",
138
140
  "style-value-types": "5.0.0",
139
141
  "tslib": "^2.1.0"
140
142
  },
@@ -1,4 +1,5 @@
1
+ import * as React from "react";
1
2
  import { Props } from "@react-three/fiber";
2
- export interface MotionCanvasProps {
3
+ export interface MotionCanvasProps extends Props {
3
4
  }
4
- export declare function MotionCanvas({ children, ...props }: Props & MotionCanvasProps): JSX.Element;
5
+ export declare const MotionCanvas: React.ForwardRefExoticComponent<MotionCanvasProps & React.RefAttributes<HTMLCanvasElement>>;