framer-motion 6.4.3 → 6.5.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 +25 -117
- package/dist/es/index.mjs +1 -0
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/value/scroll/use-element-scroll.mjs +4 -53
- package/dist/es/value/scroll/use-viewport-scroll.mjs +4 -49
- package/dist/es/value/use-scroll.mjs +29 -0
- package/dist/framer-motion.dev.js +694 -266
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +30 -54
- package/dist/projection.dev.js +2 -2
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/package.json +3 -7
- package/dist/es/value/scroll/utils.mjs +0 -28
package/dist/cjs/index.js
CHANGED
|
@@ -2449,7 +2449,7 @@ var MotionValue = /** @class */ (function () {
|
|
|
2449
2449
|
* This will be replaced by the build step with the latest version number.
|
|
2450
2450
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
2451
2451
|
*/
|
|
2452
|
-
this.version = "6.
|
|
2452
|
+
this.version = "6.5.0";
|
|
2453
2453
|
/**
|
|
2454
2454
|
* Duration, in milliseconds, since last updating frame.
|
|
2455
2455
|
*
|
|
@@ -4418,7 +4418,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4418
4418
|
* and warn against mismatches.
|
|
4419
4419
|
*/
|
|
4420
4420
|
if (process.env.NODE_ENV === "development") {
|
|
4421
|
-
warnOnce(nextValue.version === "6.
|
|
4421
|
+
warnOnce(nextValue.version === "6.5.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.5.0 may not work as expected."));
|
|
4422
4422
|
}
|
|
4423
4423
|
}
|
|
4424
4424
|
else if (isMotionValue(prevValue)) {
|
|
@@ -7887,129 +7887,36 @@ function useVelocity(value) {
|
|
|
7887
7887
|
return velocity;
|
|
7888
7888
|
}
|
|
7889
7889
|
|
|
7890
|
-
function
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
}
|
|
7898
|
-
|
|
7899
|
-
value.set(!offset || !maxOffset ? 0 : offset / maxOffset);
|
|
7900
|
-
}
|
|
7901
|
-
function createScrollUpdater(values, getOffsets) {
|
|
7902
|
-
var update = function () {
|
|
7903
|
-
var _a = getOffsets(), xOffset = _a.xOffset, yOffset = _a.yOffset, xMaxOffset = _a.xMaxOffset, yMaxOffset = _a.yMaxOffset;
|
|
7904
|
-
// Set absolute positions
|
|
7905
|
-
values.scrollX.set(xOffset);
|
|
7906
|
-
values.scrollY.set(yOffset);
|
|
7907
|
-
// Set 0-1 progress
|
|
7908
|
-
setProgress(xOffset, xMaxOffset, values.scrollXProgress);
|
|
7909
|
-
setProgress(yOffset, yMaxOffset, values.scrollYProgress);
|
|
7910
|
-
};
|
|
7911
|
-
update();
|
|
7912
|
-
return update;
|
|
7913
|
-
}
|
|
7914
|
-
|
|
7915
|
-
var getElementScrollOffsets = function (element) { return function () {
|
|
7916
|
-
return {
|
|
7917
|
-
xOffset: element.scrollLeft,
|
|
7918
|
-
yOffset: element.scrollTop,
|
|
7919
|
-
xMaxOffset: element.scrollWidth - element.offsetWidth,
|
|
7920
|
-
yMaxOffset: element.scrollHeight - element.offsetHeight,
|
|
7921
|
-
};
|
|
7922
|
-
}; };
|
|
7923
|
-
/**
|
|
7924
|
-
* Returns MotionValues that update when the provided element scrolls:
|
|
7925
|
-
*
|
|
7926
|
-
* - `scrollX` — Horizontal scroll distance in pixels.
|
|
7927
|
-
* - `scrollY` — Vertical scroll distance in pixels.
|
|
7928
|
-
* - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
|
|
7929
|
-
* - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
|
|
7930
|
-
*
|
|
7931
|
-
* This element must be set to `overflow: scroll` on either or both axes to report scroll offset.
|
|
7932
|
-
*
|
|
7933
|
-
* ```jsx
|
|
7934
|
-
* export const MyComponent = () => {
|
|
7935
|
-
* const ref = useRef()
|
|
7936
|
-
* const { scrollYProgress } = useElementScroll(ref)
|
|
7937
|
-
*
|
|
7938
|
-
* return (
|
|
7939
|
-
* <div ref={ref}>
|
|
7940
|
-
* <motion.div style={{ scaleX: scrollYProgress }} />
|
|
7941
|
-
* </div>
|
|
7942
|
-
* )
|
|
7943
|
-
* }
|
|
7944
|
-
* ```
|
|
7945
|
-
*
|
|
7946
|
-
* @public
|
|
7947
|
-
*/
|
|
7948
|
-
function useElementScroll(ref) {
|
|
7890
|
+
var createScrollMotionValues = function () { return ({
|
|
7891
|
+
scrollX: motionValue(0),
|
|
7892
|
+
scrollY: motionValue(0),
|
|
7893
|
+
scrollXProgress: motionValue(0),
|
|
7894
|
+
scrollYProgress: motionValue(0),
|
|
7895
|
+
}); };
|
|
7896
|
+
function useScroll(_a) {
|
|
7897
|
+
if (_a === void 0) { _a = {}; }
|
|
7898
|
+
var container = _a.container, target = _a.target, options = tslib.__rest(_a, ["container", "target"]);
|
|
7949
7899
|
var values = useConstant(createScrollMotionValues);
|
|
7950
7900
|
useIsomorphicLayoutEffect(function () {
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
return function () {
|
|
7959
|
-
scrollListener && scrollListener();
|
|
7960
|
-
resizeListener && resizeListener();
|
|
7961
|
-
};
|
|
7901
|
+
return dom.scroll(function (_a) {
|
|
7902
|
+
var x = _a.x, y = _a.y;
|
|
7903
|
+
values.scrollX.set(x.current);
|
|
7904
|
+
values.scrollXProgress.set(x.progress);
|
|
7905
|
+
values.scrollY.set(y.current);
|
|
7906
|
+
values.scrollYProgress.set(y.progress);
|
|
7907
|
+
}, tslib.__assign(tslib.__assign({}, options), { container: (container === null || container === void 0 ? void 0 : container.current) || undefined, target: (target === null || target === void 0 ? void 0 : target.current) || undefined }));
|
|
7962
7908
|
}, []);
|
|
7963
7909
|
return values;
|
|
7964
7910
|
}
|
|
7965
7911
|
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
return {
|
|
7969
|
-
xOffset: window.pageXOffset,
|
|
7970
|
-
yOffset: window.pageYOffset,
|
|
7971
|
-
xMaxOffset: document.body.clientWidth - window.innerWidth,
|
|
7972
|
-
yMaxOffset: document.body.clientHeight - window.innerHeight,
|
|
7973
|
-
};
|
|
7974
|
-
}
|
|
7975
|
-
var hasListeners = false;
|
|
7976
|
-
function addEventListeners() {
|
|
7977
|
-
hasListeners = true;
|
|
7978
|
-
var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
|
|
7979
|
-
addDomEvent(window, "scroll", updateScrollValues);
|
|
7980
|
-
addDomEvent(window, "resize", updateScrollValues);
|
|
7912
|
+
function useElementScroll(ref) {
|
|
7913
|
+
warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
|
|
7914
|
+
return useScroll({ container: ref });
|
|
7981
7915
|
}
|
|
7982
|
-
|
|
7983
|
-
* Returns MotionValues that update when the viewport scrolls:
|
|
7984
|
-
*
|
|
7985
|
-
* - `scrollX` — Horizontal scroll distance in pixels.
|
|
7986
|
-
* - `scrollY` — Vertical scroll distance in pixels.
|
|
7987
|
-
* - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
|
|
7988
|
-
* - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
|
|
7989
|
-
*
|
|
7990
|
-
* **Warning:** Setting `body` or `html` to `height: 100%` or similar will break the `Progress`
|
|
7991
|
-
* values as this breaks the browser's capability to accurately measure the page length.
|
|
7992
|
-
*
|
|
7993
|
-
* ```jsx
|
|
7994
|
-
* export const MyComponent = () => {
|
|
7995
|
-
* const { scrollYProgress } = useViewportScroll()
|
|
7996
|
-
* return <motion.div style={{ scaleX: scrollYProgress }} />
|
|
7997
|
-
* }
|
|
7998
|
-
* ```
|
|
7999
|
-
*
|
|
8000
|
-
* @public
|
|
8001
|
-
*/
|
|
7916
|
+
|
|
8002
7917
|
function useViewportScroll() {
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
*/
|
|
8006
|
-
if (!viewportScrollValues) {
|
|
8007
|
-
viewportScrollValues = createScrollMotionValues();
|
|
8008
|
-
}
|
|
8009
|
-
useIsomorphicLayoutEffect(function () {
|
|
8010
|
-
!hasListeners && addEventListeners();
|
|
8011
|
-
}, []);
|
|
8012
|
-
return viewportScrollValues;
|
|
7918
|
+
warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
|
|
7919
|
+
return useScroll();
|
|
8013
7920
|
}
|
|
8014
7921
|
|
|
8015
7922
|
var getCurrentTime = typeof performance !== "undefined"
|
|
@@ -8494,6 +8401,7 @@ exports.usePresence = usePresence;
|
|
|
8494
8401
|
exports.useReducedMotion = useReducedMotion;
|
|
8495
8402
|
exports.useReducedMotionConfig = useReducedMotionConfig;
|
|
8496
8403
|
exports.useResetProjection = useResetProjection;
|
|
8404
|
+
exports.useScroll = useScroll;
|
|
8497
8405
|
exports.useSpring = useSpring;
|
|
8498
8406
|
exports.useTime = useTime;
|
|
8499
8407
|
exports.useTransform = useTransform;
|
package/dist/es/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ export { resolveMotionValue } from './value/utils/resolve-motion-value.mjs';
|
|
|
15
15
|
export { useTransform } from './value/use-transform.mjs';
|
|
16
16
|
export { useSpring } from './value/use-spring.mjs';
|
|
17
17
|
export { useVelocity } from './value/use-velocity.mjs';
|
|
18
|
+
export { useScroll } from './value/use-scroll.mjs';
|
|
18
19
|
export { useElementScroll } from './value/scroll/use-element-scroll.mjs';
|
|
19
20
|
export { useViewportScroll } from './value/scroll/use-viewport-scroll.mjs';
|
|
20
21
|
export { useTime } from './value/use-time.mjs';
|
|
@@ -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.
|
|
21
|
+
warnOnce(nextValue.version === "6.5.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.5.0 may not work as expected."));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
else if (isMotionValue(prevValue)) {
|
package/dist/es/value/index.mjs
CHANGED
|
@@ -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.
|
|
28
|
+
this.version = "6.5.0";
|
|
29
29
|
/**
|
|
30
30
|
* Duration, in milliseconds, since last updating frame.
|
|
31
31
|
*
|
|
@@ -1,58 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { addDomEvent } from '../../events/use-dom-event.mjs';
|
|
4
|
-
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
|
|
5
|
-
import { invariant } from 'hey-listen';
|
|
1
|
+
import { warnOnce } from '../../utils/warn-once.mjs';
|
|
2
|
+
import { useScroll } from '../use-scroll.mjs';
|
|
6
3
|
|
|
7
|
-
var getElementScrollOffsets = function (element) { return function () {
|
|
8
|
-
return {
|
|
9
|
-
xOffset: element.scrollLeft,
|
|
10
|
-
yOffset: element.scrollTop,
|
|
11
|
-
xMaxOffset: element.scrollWidth - element.offsetWidth,
|
|
12
|
-
yMaxOffset: element.scrollHeight - element.offsetHeight,
|
|
13
|
-
};
|
|
14
|
-
}; };
|
|
15
|
-
/**
|
|
16
|
-
* Returns MotionValues that update when the provided element scrolls:
|
|
17
|
-
*
|
|
18
|
-
* - `scrollX` — Horizontal scroll distance in pixels.
|
|
19
|
-
* - `scrollY` — Vertical scroll distance in pixels.
|
|
20
|
-
* - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
|
|
21
|
-
* - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
|
|
22
|
-
*
|
|
23
|
-
* This element must be set to `overflow: scroll` on either or both axes to report scroll offset.
|
|
24
|
-
*
|
|
25
|
-
* ```jsx
|
|
26
|
-
* export const MyComponent = () => {
|
|
27
|
-
* const ref = useRef()
|
|
28
|
-
* const { scrollYProgress } = useElementScroll(ref)
|
|
29
|
-
*
|
|
30
|
-
* return (
|
|
31
|
-
* <div ref={ref}>
|
|
32
|
-
* <motion.div style={{ scaleX: scrollYProgress }} />
|
|
33
|
-
* </div>
|
|
34
|
-
* )
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @public
|
|
39
|
-
*/
|
|
40
4
|
function useElementScroll(ref) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var element = ref.current;
|
|
44
|
-
invariant(!!element, "ref provided to useScroll must be passed into a HTML element.");
|
|
45
|
-
if (!element)
|
|
46
|
-
return;
|
|
47
|
-
var updateScrollValues = createScrollUpdater(values, getElementScrollOffsets(element));
|
|
48
|
-
var scrollListener = addDomEvent(element, "scroll", updateScrollValues);
|
|
49
|
-
var resizeListener = addDomEvent(element, "resize", updateScrollValues);
|
|
50
|
-
return function () {
|
|
51
|
-
scrollListener && scrollListener();
|
|
52
|
-
resizeListener && resizeListener();
|
|
53
|
-
};
|
|
54
|
-
}, []);
|
|
55
|
-
return values;
|
|
5
|
+
warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
|
|
6
|
+
return useScroll({ container: ref });
|
|
56
7
|
}
|
|
57
8
|
|
|
58
9
|
export { useElementScroll };
|
|
@@ -1,54 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
|
|
1
|
+
import { warnOnce } from '../../utils/warn-once.mjs';
|
|
2
|
+
import { useScroll } from '../use-scroll.mjs';
|
|
4
3
|
|
|
5
|
-
var viewportScrollValues;
|
|
6
|
-
function getViewportScrollOffsets() {
|
|
7
|
-
return {
|
|
8
|
-
xOffset: window.pageXOffset,
|
|
9
|
-
yOffset: window.pageYOffset,
|
|
10
|
-
xMaxOffset: document.body.clientWidth - window.innerWidth,
|
|
11
|
-
yMaxOffset: document.body.clientHeight - window.innerHeight,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
var hasListeners = false;
|
|
15
|
-
function addEventListeners() {
|
|
16
|
-
hasListeners = true;
|
|
17
|
-
var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
|
|
18
|
-
addDomEvent(window, "scroll", updateScrollValues);
|
|
19
|
-
addDomEvent(window, "resize", updateScrollValues);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns MotionValues that update when the viewport scrolls:
|
|
23
|
-
*
|
|
24
|
-
* - `scrollX` — Horizontal scroll distance in pixels.
|
|
25
|
-
* - `scrollY` — Vertical scroll distance in pixels.
|
|
26
|
-
* - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
|
|
27
|
-
* - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
|
|
28
|
-
*
|
|
29
|
-
* **Warning:** Setting `body` or `html` to `height: 100%` or similar will break the `Progress`
|
|
30
|
-
* values as this breaks the browser's capability to accurately measure the page length.
|
|
31
|
-
*
|
|
32
|
-
* ```jsx
|
|
33
|
-
* export const MyComponent = () => {
|
|
34
|
-
* const { scrollYProgress } = useViewportScroll()
|
|
35
|
-
* return <motion.div style={{ scaleX: scrollYProgress }} />
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
4
|
function useViewportScroll() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*/
|
|
45
|
-
if (!viewportScrollValues) {
|
|
46
|
-
viewportScrollValues = createScrollMotionValues();
|
|
47
|
-
}
|
|
48
|
-
useIsomorphicLayoutEffect(function () {
|
|
49
|
-
!hasListeners && addEventListeners();
|
|
50
|
-
}, []);
|
|
51
|
-
return viewportScrollValues;
|
|
5
|
+
warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
|
|
6
|
+
return useScroll();
|
|
52
7
|
}
|
|
53
8
|
|
|
54
9
|
export { useViewportScroll };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import { scroll } from '@motionone/dom';
|
|
3
|
+
import { motionValue } from './index.mjs';
|
|
4
|
+
import { useConstant } from '../utils/use-constant.mjs';
|
|
5
|
+
import { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';
|
|
6
|
+
|
|
7
|
+
var createScrollMotionValues = function () { return ({
|
|
8
|
+
scrollX: motionValue(0),
|
|
9
|
+
scrollY: motionValue(0),
|
|
10
|
+
scrollXProgress: motionValue(0),
|
|
11
|
+
scrollYProgress: motionValue(0),
|
|
12
|
+
}); };
|
|
13
|
+
function useScroll(_a) {
|
|
14
|
+
if (_a === void 0) { _a = {}; }
|
|
15
|
+
var container = _a.container, target = _a.target, options = __rest(_a, ["container", "target"]);
|
|
16
|
+
var values = useConstant(createScrollMotionValues);
|
|
17
|
+
useIsomorphicLayoutEffect(function () {
|
|
18
|
+
return scroll(function (_a) {
|
|
19
|
+
var x = _a.x, y = _a.y;
|
|
20
|
+
values.scrollX.set(x.current);
|
|
21
|
+
values.scrollXProgress.set(x.progress);
|
|
22
|
+
values.scrollY.set(y.current);
|
|
23
|
+
values.scrollYProgress.set(y.progress);
|
|
24
|
+
}, __assign(__assign({}, options), { container: (container === null || container === void 0 ? void 0 : container.current) || undefined, target: (target === null || target === void 0 ? void 0 : target.current) || undefined }));
|
|
25
|
+
}, []);
|
|
26
|
+
return values;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { useScroll };
|