framer-motion 5.4.3 → 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.
package/dist/cjs/three-entry.js
CHANGED
|
@@ -7,11 +7,15 @@ var useMotionValue = require('./use-motion-value-73ed7c77.js');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var popmotion = require('popmotion');
|
|
9
9
|
var three = require('three');
|
|
10
|
+
var mergeRefs = require('react-merge-refs');
|
|
11
|
+
var useMeasure = require('react-use-measure');
|
|
10
12
|
var fiber = require('@react-three/fiber');
|
|
11
13
|
require('hey-listen');
|
|
12
14
|
require('framesync');
|
|
13
15
|
require('style-value-types');
|
|
14
16
|
|
|
17
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
|
+
|
|
15
19
|
function _interopNamespace(e) {
|
|
16
20
|
if (e && e.__esModule) return e;
|
|
17
21
|
var n = Object.create(null);
|
|
@@ -31,6 +35,8 @@ function _interopNamespace(e) {
|
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
38
|
+
var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
|
|
39
|
+
var useMeasure__default = /*#__PURE__*/_interopDefaultLegacy(useMeasure);
|
|
34
40
|
|
|
35
41
|
function useHover(isStatic, _a, visualElement) {
|
|
36
42
|
var whileHover = _a.whileHover, onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, onPointerOver = _a.onPointerOver, onPointerOut = _a.onPointerOut;
|
|
@@ -287,12 +293,63 @@ var motion = new Proxy(custom, {
|
|
|
287
293
|
},
|
|
288
294
|
});
|
|
289
295
|
|
|
290
|
-
function
|
|
291
|
-
var
|
|
296
|
+
function Block(_a) {
|
|
297
|
+
var set = _a.set;
|
|
298
|
+
useMotionValue.useIsomorphicLayoutEffect(function () {
|
|
299
|
+
set(new Promise(function () { return null; }));
|
|
300
|
+
return function () { return set(false); };
|
|
301
|
+
}, []);
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
var ErrorBoundary = /** @class */ (function (_super) {
|
|
305
|
+
tslib.__extends(ErrorBoundary, _super);
|
|
306
|
+
function ErrorBoundary() {
|
|
307
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
308
|
+
_this.state = { error: false };
|
|
309
|
+
return _this;
|
|
310
|
+
}
|
|
311
|
+
ErrorBoundary.prototype.componentDidCatch = function (error) {
|
|
312
|
+
this.props.set(error);
|
|
313
|
+
};
|
|
314
|
+
ErrorBoundary.prototype.render = function () {
|
|
315
|
+
return this.state.error ? null : this.props.children;
|
|
316
|
+
};
|
|
317
|
+
ErrorBoundary.getDerivedStateFromError = function () { return ({ error: true }); };
|
|
318
|
+
return ErrorBoundary;
|
|
319
|
+
}(React__namespace.Component));
|
|
320
|
+
/**
|
|
321
|
+
* A synchronously rendering version of R3F's Canvas component. We call render
|
|
322
|
+
* within the render function itself to ensure lifecycle events are called before
|
|
323
|
+
* parent reconcilers. This can be replaced with a simple MotionContext provider
|
|
324
|
+
* when R3F moves to the same model.
|
|
325
|
+
*/
|
|
326
|
+
function SyncCanvasComponent(_a, forwardedRef) {
|
|
327
|
+
var children = _a.children, fallback = _a.fallback, tabIndex = _a.tabIndex, resize = _a.resize, id = _a.id, style = _a.style, className = _a.className, events = _a.events, props = tslib.__rest(_a, ["children", "fallback", "tabIndex", "resize", "id", "style", "className", "events"]);
|
|
292
328
|
var motionContext = React.useContext(useMotionValue.MotionContext);
|
|
293
|
-
|
|
294
|
-
|
|
329
|
+
var _b = tslib.__read(useMeasure__default["default"](tslib.__assign({ scroll: true, debounce: { scroll: 50, resize: 0 } }, resize)), 2), containerRef = _b[0], _c = _b[1], width = _c.width, height = _c.height;
|
|
330
|
+
var canvasRef = React__namespace.useRef(null);
|
|
331
|
+
var _d = tslib.__read(React__namespace.useState(false), 2), block = _d[0], setBlock = _d[1];
|
|
332
|
+
var _e = tslib.__read(React__namespace.useState(false), 2), error = _e[0], setError = _e[1];
|
|
333
|
+
// Suspend this component if block is a promise (2nd run)
|
|
334
|
+
if (block)
|
|
335
|
+
throw block;
|
|
336
|
+
// Throw exception outwards if anything within canvas throws
|
|
337
|
+
if (error)
|
|
338
|
+
throw error;
|
|
339
|
+
// Execute JSX in the reconciler as a layout-effect
|
|
340
|
+
if (width > 0 && height > 0) {
|
|
341
|
+
fiber.render(React__namespace.createElement(ErrorBoundary, { set: setError },
|
|
342
|
+
React__namespace.createElement(React__namespace.Suspense, { fallback: React__namespace.createElement(Block, { set: setBlock }) },
|
|
343
|
+
React__namespace.createElement(useMotionValue.MotionContext.Provider, { value: motionContext }, children))), canvasRef.current, tslib.__assign(tslib.__assign({}, props), { size: { width: width, height: height }, events: events || fiber.events }));
|
|
344
|
+
}
|
|
345
|
+
useMotionValue.useIsomorphicLayoutEffect(function () {
|
|
346
|
+
var container = canvasRef.current;
|
|
347
|
+
return function () { return fiber.unmountComponentAtNode(container); };
|
|
348
|
+
}, []);
|
|
349
|
+
return (React__namespace.createElement("div", { ref: containerRef, id: id, className: className, tabIndex: tabIndex, style: tslib.__assign({ position: "relative", width: "100%", height: "100%", overflow: "hidden" }, style) },
|
|
350
|
+
React__namespace.createElement("canvas", { ref: mergeRefs__default["default"]([canvasRef, forwardedRef]), style: { display: "block" } }, fallback)));
|
|
295
351
|
}
|
|
352
|
+
var MotionCanvas = React.forwardRef(SyncCanvasComponent);
|
|
296
353
|
|
|
297
354
|
function useTime() {
|
|
298
355
|
var time = useMotionValue.useMotionValue(0);
|
|
@@ -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
|
|
8
|
-
var
|
|
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
|
-
|
|
11
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "framer-motion",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.4",
|
|
4
4
|
"description": "A simple and powerful React animation library",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/es/index.mjs",
|
|
@@ -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
|
|
5
|
+
export declare const MotionCanvas: React.ForwardRefExoticComponent<MotionCanvasProps & React.RefAttributes<HTMLCanvasElement>>;
|