framer-motion 5.4.0-beta.1 → 5.4.0-beta.5
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/es/animation/utils/default-transitions.mjs +0 -2
- package/dist/es/components/MotionCanvas/index.mjs +14 -0
- package/dist/es/render/three/create-visual-element.mjs +6 -6
- package/dist/es/render/three/motion.mjs +2 -1
- package/dist/es/render/three/utils/scrape-motion-value.mjs +35 -0
- package/dist/es/render/three/utils/use-time.mjs +10 -0
- package/dist/es/three-entry.mjs +2 -0
- package/dist/es/value/utils/is-motion-value.mjs +1 -1
- package/dist/framer-motion-three.cjs.js +85 -8
- package/dist/framer-motion.cjs.js +1 -3
- package/dist/framer-motion.dev.js +4 -4
- package/dist/framer-motion.js +1 -1
- package/dist/projection.dev.js +4 -4
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/package.json +2 -2
- package/types/animation/utils/default-transitions.d.ts +0 -2
- package/types/components/MotionCanvas/index.d.ts +4 -0
- package/types/render/three/create-visual-element.d.ts +1 -2
- package/types/render/three/types.d.ts +16 -3
- package/types/render/three/utils/scrape-motion-value.d.ts +2 -0
- package/types/render/three/utils/use-time.d.ts +1 -0
- package/types/three-entry.d.ts +2 -0
|
@@ -5,14 +5,12 @@ var underDampedSpring = function () { return ({
|
|
|
5
5
|
type: "spring",
|
|
6
6
|
stiffness: 500,
|
|
7
7
|
damping: 25,
|
|
8
|
-
restDelta: 0.5,
|
|
9
8
|
restSpeed: 10,
|
|
10
9
|
}); };
|
|
11
10
|
var criticallyDampedSpring = function (to) { return ({
|
|
12
11
|
type: "spring",
|
|
13
12
|
stiffness: 550,
|
|
14
13
|
damping: to === 0 ? 2 * Math.sqrt(550) : 30,
|
|
15
|
-
restDelta: 0.01,
|
|
16
14
|
restSpeed: 10,
|
|
17
15
|
}); };
|
|
18
16
|
var linearTween = function () { return ({
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useContext } from 'react';
|
|
4
|
+
import { Canvas } from '@react-three/fiber';
|
|
5
|
+
import { MotionContext } from '../../context/MotionContext/index.mjs';
|
|
6
|
+
|
|
7
|
+
function MotionCanvas(_a) {
|
|
8
|
+
var children = _a.children, props = __rest(_a, ["children"]);
|
|
9
|
+
var motionContext = useContext(MotionContext);
|
|
10
|
+
return (React.createElement(Canvas, __assign({}, props),
|
|
11
|
+
React.createElement(MotionContext.Provider, { value: motionContext }, children)));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { MotionCanvas };
|
|
@@ -3,17 +3,17 @@ import { createBox } from '../../projection/geometry/models.mjs';
|
|
|
3
3
|
import { checkTargetForNewValues } from '../utils/setters.mjs';
|
|
4
4
|
import { setThreeValue } from './utils/set-value.mjs';
|
|
5
5
|
import { readThreeValue } from './utils/read-value.mjs';
|
|
6
|
+
import { scrapeMotionValuesFromProps } from './utils/scrape-motion-value.mjs';
|
|
6
7
|
|
|
7
|
-
var scrapeMotionValuesFromProps = function () { return ({}); };
|
|
8
8
|
var createRenderState = function () { return ({}); };
|
|
9
9
|
var threeVisualElement = visualElement({
|
|
10
10
|
treeType: "three",
|
|
11
11
|
readValueFromInstance: readThreeValue,
|
|
12
|
-
getBaseTarget: function (
|
|
13
|
-
return
|
|
12
|
+
getBaseTarget: function () {
|
|
13
|
+
return undefined;
|
|
14
14
|
},
|
|
15
|
-
sortNodePosition: function (
|
|
16
|
-
return
|
|
15
|
+
sortNodePosition: function (a, b) {
|
|
16
|
+
return a.id - b.id;
|
|
17
17
|
},
|
|
18
18
|
makeTargetAnimatable: function (element, target) {
|
|
19
19
|
checkTargetForNewValues(element, target, {});
|
|
@@ -39,4 +39,4 @@ var createVisualElement = function (_, options) {
|
|
|
39
39
|
return threeVisualElement(options);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export { createRenderState, createVisualElement,
|
|
42
|
+
export { createRenderState, createVisualElement, threeVisualElement };
|
|
@@ -3,7 +3,8 @@ import { createMotionComponent } from '../../motion/index.mjs';
|
|
|
3
3
|
import { animations } from '../../motion/features/animations.mjs';
|
|
4
4
|
import { makeUseVisualState } from '../../motion/utils/use-visual-state.mjs';
|
|
5
5
|
import { useRender } from './use-render.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { createRenderState, createVisualElement } from './create-visual-element.mjs';
|
|
7
|
+
import { scrapeMotionValuesFromProps } from './utils/scrape-motion-value.mjs';
|
|
7
8
|
|
|
8
9
|
var useVisualState = makeUseVisualState({
|
|
9
10
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isMotionValue } from '../../../value/utils/is-motion-value.mjs';
|
|
2
|
+
|
|
3
|
+
var axes = ["x", "y", "z"];
|
|
4
|
+
var valueMap = {
|
|
5
|
+
"position-x": "x",
|
|
6
|
+
"position-y": "y",
|
|
7
|
+
"position-z": "z",
|
|
8
|
+
"rotation-x": "rotateX",
|
|
9
|
+
"rotation-y": "rotateY",
|
|
10
|
+
"rotation-z": "rotateZ",
|
|
11
|
+
"scale-x": "scaleX",
|
|
12
|
+
"scale-y": "scaleY",
|
|
13
|
+
"scale-z": "scaleZ",
|
|
14
|
+
};
|
|
15
|
+
var scrapeMotionValuesFromProps = function (props) {
|
|
16
|
+
var motionValues = {};
|
|
17
|
+
for (var key in props) {
|
|
18
|
+
var prop = props[key];
|
|
19
|
+
if (isMotionValue(prop)) {
|
|
20
|
+
motionValues[valueMap[key] || key] = prop;
|
|
21
|
+
}
|
|
22
|
+
else if (Array.isArray(prop)) {
|
|
23
|
+
for (var i = 0; i < prop.length; i++) {
|
|
24
|
+
var value = prop[i];
|
|
25
|
+
if (isMotionValue(value)) {
|
|
26
|
+
var name_1 = valueMap[key + "-" + axes[i]];
|
|
27
|
+
motionValues[name_1] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return motionValues;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { scrapeMotionValuesFromProps };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useFrame } from '@react-three/fiber';
|
|
2
|
+
import { useMotionValue } from '../../../value/use-motion-value.mjs';
|
|
3
|
+
|
|
4
|
+
function useTime() {
|
|
5
|
+
var time = useMotionValue(0);
|
|
6
|
+
useFrame(function (state) { return time.set(state.clock.getElapsedTime()); });
|
|
7
|
+
return time;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { useTime };
|
package/dist/es/three-entry.mjs
CHANGED
|
@@ -9,6 +9,7 @@ var sync = require('framesync');
|
|
|
9
9
|
var popmotion = require('popmotion');
|
|
10
10
|
var styleValueTypes = require('style-value-types');
|
|
11
11
|
var three = require('three');
|
|
12
|
+
var fiber = require('@react-three/fiber');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
15
|
|
|
@@ -665,7 +666,7 @@ function motionValue(init) {
|
|
|
665
666
|
}
|
|
666
667
|
|
|
667
668
|
var isMotionValue = function (value) {
|
|
668
|
-
return value !== null && typeof value === "object" && value.getVelocity;
|
|
669
|
+
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
669
670
|
};
|
|
670
671
|
|
|
671
672
|
/**
|
|
@@ -745,14 +746,12 @@ var underDampedSpring = function () { return ({
|
|
|
745
746
|
type: "spring",
|
|
746
747
|
stiffness: 500,
|
|
747
748
|
damping: 25,
|
|
748
|
-
restDelta: 0.5,
|
|
749
749
|
restSpeed: 10,
|
|
750
750
|
}); };
|
|
751
751
|
var criticallyDampedSpring = function (to) { return ({
|
|
752
752
|
type: "spring",
|
|
753
753
|
stiffness: 550,
|
|
754
754
|
damping: to === 0 ? 2 * Math.sqrt(550) : 30,
|
|
755
|
-
restDelta: 0.01,
|
|
756
755
|
restSpeed: 10,
|
|
757
756
|
}); };
|
|
758
757
|
var linearTween = function () { return ({
|
|
@@ -2935,16 +2934,47 @@ function readThreeValue(instance, name) {
|
|
|
2935
2934
|
: (_a = readAnimatableValue(instance[name])) !== null && _a !== void 0 ? _a : 0;
|
|
2936
2935
|
}
|
|
2937
2936
|
|
|
2938
|
-
var
|
|
2937
|
+
var axes = ["x", "y", "z"];
|
|
2938
|
+
var valueMap = {
|
|
2939
|
+
"position-x": "x",
|
|
2940
|
+
"position-y": "y",
|
|
2941
|
+
"position-z": "z",
|
|
2942
|
+
"rotation-x": "rotateX",
|
|
2943
|
+
"rotation-y": "rotateY",
|
|
2944
|
+
"rotation-z": "rotateZ",
|
|
2945
|
+
"scale-x": "scaleX",
|
|
2946
|
+
"scale-y": "scaleY",
|
|
2947
|
+
"scale-z": "scaleZ",
|
|
2948
|
+
};
|
|
2949
|
+
var scrapeMotionValuesFromProps = function (props) {
|
|
2950
|
+
var motionValues = {};
|
|
2951
|
+
for (var key in props) {
|
|
2952
|
+
var prop = props[key];
|
|
2953
|
+
if (isMotionValue(prop)) {
|
|
2954
|
+
motionValues[valueMap[key] || key] = prop;
|
|
2955
|
+
}
|
|
2956
|
+
else if (Array.isArray(prop)) {
|
|
2957
|
+
for (var i = 0; i < prop.length; i++) {
|
|
2958
|
+
var value = prop[i];
|
|
2959
|
+
if (isMotionValue(value)) {
|
|
2960
|
+
var name_1 = valueMap[key + "-" + axes[i]];
|
|
2961
|
+
motionValues[name_1] = value;
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
return motionValues;
|
|
2967
|
+
};
|
|
2968
|
+
|
|
2939
2969
|
var createRenderState = function () { return ({}); };
|
|
2940
2970
|
var threeVisualElement = visualElement({
|
|
2941
2971
|
treeType: "three",
|
|
2942
2972
|
readValueFromInstance: readThreeValue,
|
|
2943
|
-
getBaseTarget: function (
|
|
2944
|
-
return
|
|
2973
|
+
getBaseTarget: function () {
|
|
2974
|
+
return undefined;
|
|
2945
2975
|
},
|
|
2946
|
-
sortNodePosition: function (
|
|
2947
|
-
return
|
|
2976
|
+
sortNodePosition: function (a, b) {
|
|
2977
|
+
return a.id - b.id;
|
|
2948
2978
|
},
|
|
2949
2979
|
makeTargetAnimatable: function (element, target) {
|
|
2950
2980
|
checkTargetForNewValues(element, target, {});
|
|
@@ -2992,4 +3022,51 @@ var motion = new Proxy(custom, {
|
|
|
2992
3022
|
},
|
|
2993
3023
|
});
|
|
2994
3024
|
|
|
3025
|
+
function MotionCanvas(_a) {
|
|
3026
|
+
var children = _a.children, props = tslib.__rest(_a, ["children"]);
|
|
3027
|
+
var motionContext = React.useContext(MotionContext);
|
|
3028
|
+
return (React__namespace.createElement(fiber.Canvas, tslib.__assign({}, props),
|
|
3029
|
+
React__namespace.createElement(MotionContext.Provider, { value: motionContext }, children)));
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
/**
|
|
3033
|
+
* Creates a `MotionValue` to track the state and velocity of a value.
|
|
3034
|
+
*
|
|
3035
|
+
* Usually, these are created automatically. For advanced use-cases, like use with `useTransform`, you can create `MotionValue`s externally and pass them into the animated component via the `style` prop.
|
|
3036
|
+
*
|
|
3037
|
+
* ```jsx
|
|
3038
|
+
* export const MyComponent = () => {
|
|
3039
|
+
* const scale = useMotionValue(1)
|
|
3040
|
+
*
|
|
3041
|
+
* return <motion.div style={{ scale }} />
|
|
3042
|
+
* }
|
|
3043
|
+
* ```
|
|
3044
|
+
*
|
|
3045
|
+
* @param initial - The initial state.
|
|
3046
|
+
*
|
|
3047
|
+
* @public
|
|
3048
|
+
*/
|
|
3049
|
+
function useMotionValue(initial) {
|
|
3050
|
+
var value = useConstant(function () { return motionValue(initial); });
|
|
3051
|
+
/**
|
|
3052
|
+
* If this motion value is being used in static mode, like on
|
|
3053
|
+
* the Framer canvas, force components to rerender when the motion
|
|
3054
|
+
* value is updated.
|
|
3055
|
+
*/
|
|
3056
|
+
var isStatic = React.useContext(MotionConfigContext).isStatic;
|
|
3057
|
+
if (isStatic) {
|
|
3058
|
+
var _a = tslib.__read(React.useState(initial), 2), setLatest_1 = _a[1];
|
|
3059
|
+
React.useEffect(function () { return value.onChange(setLatest_1); }, []);
|
|
3060
|
+
}
|
|
3061
|
+
return value;
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
function useTime() {
|
|
3065
|
+
var time = useMotionValue(0);
|
|
3066
|
+
fiber.useFrame(function (state) { return time.set(state.clock.getElapsedTime()); });
|
|
3067
|
+
return time;
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
exports.MotionCanvas = MotionCanvas;
|
|
2995
3071
|
exports.motion = motion;
|
|
3072
|
+
exports.useTime = useTime;
|
|
@@ -675,7 +675,7 @@ function motionValue(init) {
|
|
|
675
675
|
}
|
|
676
676
|
|
|
677
677
|
var isMotionValue = function (value) {
|
|
678
|
-
return value !== null && typeof value === "object" && value.getVelocity;
|
|
678
|
+
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
679
679
|
};
|
|
680
680
|
|
|
681
681
|
/**
|
|
@@ -755,14 +755,12 @@ var underDampedSpring = function () { return ({
|
|
|
755
755
|
type: "spring",
|
|
756
756
|
stiffness: 500,
|
|
757
757
|
damping: 25,
|
|
758
|
-
restDelta: 0.5,
|
|
759
758
|
restSpeed: 10,
|
|
760
759
|
}); };
|
|
761
760
|
var criticallyDampedSpring = function (to) { return ({
|
|
762
761
|
type: "spring",
|
|
763
762
|
stiffness: 550,
|
|
764
763
|
damping: to === 0 ? 2 * Math.sqrt(550) : 30,
|
|
765
|
-
restDelta: 0.01,
|
|
766
764
|
restSpeed: 10,
|
|
767
765
|
}); };
|
|
768
766
|
var linearTween = function () { return ({
|
|
@@ -638,7 +638,9 @@
|
|
|
638
638
|
const initialDelta = to - from;
|
|
639
639
|
const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
|
|
640
640
|
const undampedAngularFreq = Math.sqrt(stiffness / mass) / 1000;
|
|
641
|
-
|
|
641
|
+
if (restDelta === undefined) {
|
|
642
|
+
restDelta = Math.min(Math.abs(to - from) / 100, 0.4);
|
|
643
|
+
}
|
|
642
644
|
if (dampingRatio < 1) {
|
|
643
645
|
const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
|
|
644
646
|
resolveSpring = (t) => {
|
|
@@ -1906,7 +1908,7 @@
|
|
|
1906
1908
|
}
|
|
1907
1909
|
|
|
1908
1910
|
var isMotionValue = function (value) {
|
|
1909
|
-
return value !== null && typeof value === "object" && value.getVelocity;
|
|
1911
|
+
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
1910
1912
|
};
|
|
1911
1913
|
|
|
1912
1914
|
/**
|
|
@@ -1986,14 +1988,12 @@
|
|
|
1986
1988
|
type: "spring",
|
|
1987
1989
|
stiffness: 500,
|
|
1988
1990
|
damping: 25,
|
|
1989
|
-
restDelta: 0.5,
|
|
1990
1991
|
restSpeed: 10,
|
|
1991
1992
|
}); };
|
|
1992
1993
|
var criticallyDampedSpring = function (to) { return ({
|
|
1993
1994
|
type: "spring",
|
|
1994
1995
|
stiffness: 550,
|
|
1995
1996
|
damping: to === 0 ? 2 * Math.sqrt(550) : 30,
|
|
1996
|
-
restDelta: 0.01,
|
|
1997
1997
|
restSpeed: 10,
|
|
1998
1998
|
}); };
|
|
1999
1999
|
var linearTween = function () { return ({
|