framer-motion 6.4.3 → 7.0.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/README.md +14 -11
- package/dist/cjs/index.js +40 -126
- package/dist/es/context/MotionContext/create.mjs +1 -1
- package/dist/es/gestures/PanSession.mjs +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +2 -1
- package/dist/es/gestures/drag/utils/constraints.mjs +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/projection/animation/mix-values.mjs +2 -2
- package/dist/es/projection/node/create-projection-node.mjs +1 -1
- package/dist/es/render/dom/utils/unit-conversion.mjs +1 -1
- package/dist/es/render/html/visual-element.mjs +1 -1
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/utils/use-animation-frame.mjs +5 -7
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/value/scroll/use-element-scroll.mjs +5 -51
- package/dist/es/value/scroll/use-viewport-scroll.mjs +5 -47
- package/dist/es/value/use-on-change.mjs +3 -3
- package/dist/es/value/use-scroll.mjs +29 -0
- package/dist/framer-motion.dev.js +942 -354
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +44 -52
- package/dist/projection.dev.js +295 -118
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -2
- package/dist/size-webpack-m.js +0 -1
- package/package.json +13 -22
- package/dist/es/value/scroll/utils.mjs +0 -28
- package/dist/size-webpack-dom-max.js.LICENSE.txt +0 -14
- 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://
|
|
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
|
|
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
|
|
28
|
+
Framer Motion is an open source, production-ready library that’s 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
|
-
###
|
|
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
|
-
|
|
84
|
+
### ✨ Framer
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
- Design and publish sites that inspire. [Try Framer for free](https://www.framer.com/).
|
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 = "
|
|
2452
|
+
this.version = "7.0.0";
|
|
2453
2453
|
/**
|
|
2454
2454
|
* Duration, in milliseconds, since last updating frame.
|
|
2455
2455
|
*
|
|
@@ -3375,8 +3375,8 @@ var animations = {
|
|
|
3375
3375
|
*/
|
|
3376
3376
|
var PanSession = /** @class */ (function () {
|
|
3377
3377
|
function PanSession(event, handlers, _a) {
|
|
3378
|
-
var _this = this;
|
|
3379
3378
|
var _b = _a === void 0 ? {} : _a, transformPagePoint = _b.transformPagePoint;
|
|
3379
|
+
var _this = this;
|
|
3380
3380
|
/**
|
|
3381
3381
|
* @internal
|
|
3382
3382
|
*/
|
|
@@ -4247,7 +4247,7 @@ var VisualElementDragControls = /** @class */ (function () {
|
|
|
4247
4247
|
* If the element's layout changes, calculate the delta and apply that to
|
|
4248
4248
|
* the drag gesture's origin point.
|
|
4249
4249
|
*/
|
|
4250
|
-
projection.addEventListener("didUpdate", (function (_a) {
|
|
4250
|
+
var stopLayoutUpdateListener = projection.addEventListener("didUpdate", (function (_a) {
|
|
4251
4251
|
var delta = _a.delta, hasLayoutChanged = _a.hasLayoutChanged;
|
|
4252
4252
|
if (_this.isDragging && hasLayoutChanged) {
|
|
4253
4253
|
eachAxis(function (axis) {
|
|
@@ -4264,6 +4264,7 @@ var VisualElementDragControls = /** @class */ (function () {
|
|
|
4264
4264
|
stopResizeListener();
|
|
4265
4265
|
stopPointerListener();
|
|
4266
4266
|
stopMeasureLayoutListener();
|
|
4267
|
+
stopLayoutUpdateListener === null || stopLayoutUpdateListener === void 0 ? void 0 : stopLayoutUpdateListener();
|
|
4267
4268
|
};
|
|
4268
4269
|
};
|
|
4269
4270
|
VisualElementDragControls.prototype.getProps = function () {
|
|
@@ -4418,7 +4419,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4418
4419
|
* and warn against mismatches.
|
|
4419
4420
|
*/
|
|
4420
4421
|
if (process.env.NODE_ENV === "development") {
|
|
4421
|
-
warnOnce(nextValue.version === "
|
|
4422
|
+
warnOnce(nextValue.version === "7.0.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.0.0 may not work as expected."));
|
|
4422
4423
|
}
|
|
4423
4424
|
}
|
|
4424
4425
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5257,9 +5258,9 @@ var htmlConfig = {
|
|
|
5257
5258
|
* can be animated by Motion.
|
|
5258
5259
|
*/
|
|
5259
5260
|
makeTargetAnimatable: function (element, _a, _b, isMounted) {
|
|
5261
|
+
var transition = _a.transition, transitionEnd = _a.transitionEnd, target = tslib.__rest(_a, ["transition", "transitionEnd"]);
|
|
5260
5262
|
var transformValues = _b.transformValues;
|
|
5261
5263
|
if (isMounted === void 0) { isMounted = true; }
|
|
5262
|
-
var transition = _a.transition, transitionEnd = _a.transitionEnd, target = tslib.__rest(_a, ["transition", "transitionEnd"]);
|
|
5263
5264
|
var origin = getOrigin(target, transition || {}, element);
|
|
5264
5265
|
/**
|
|
5265
5266
|
* If Framer has provided a function to convert `Color` etc value types, convert them
|
|
@@ -5919,9 +5920,9 @@ function createProjectionNode(_a) {
|
|
|
5919
5920
|
var attachResizeListener = _a.attachResizeListener, defaultParent = _a.defaultParent, measureScroll = _a.measureScroll, checkIsScrollRoot = _a.checkIsScrollRoot, resetTransform = _a.resetTransform;
|
|
5920
5921
|
return /** @class */ (function () {
|
|
5921
5922
|
function ProjectionNode(id, latestValues, parent) {
|
|
5922
|
-
var _this = this;
|
|
5923
5923
|
if (latestValues === void 0) { latestValues = {}; }
|
|
5924
5924
|
if (parent === void 0) { parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent(); }
|
|
5925
|
+
var _this = this;
|
|
5925
5926
|
/**
|
|
5926
5927
|
* A Set containing all this component's children. This is used to iterate
|
|
5927
5928
|
* through the children.
|
|
@@ -7671,13 +7672,13 @@ function transform() {
|
|
|
7671
7672
|
}
|
|
7672
7673
|
|
|
7673
7674
|
function useOnChange(value, callback) {
|
|
7674
|
-
|
|
7675
|
+
useIsomorphicLayoutEffect(function () {
|
|
7675
7676
|
if (isMotionValue(value))
|
|
7676
7677
|
return value.onChange(callback);
|
|
7677
7678
|
}, [callback]);
|
|
7678
7679
|
}
|
|
7679
7680
|
function useMultiOnChange(values, handler) {
|
|
7680
|
-
|
|
7681
|
+
useIsomorphicLayoutEffect(function () {
|
|
7681
7682
|
var subscriptions = values.map(function (value) { return value.onChange(handler); });
|
|
7682
7683
|
return function () { return subscriptions.forEach(function (unsubscribe) { return unsubscribe(); }); };
|
|
7683
7684
|
});
|
|
@@ -7887,143 +7888,55 @@ function useVelocity(value) {
|
|
|
7887
7888
|
return velocity;
|
|
7888
7889
|
}
|
|
7889
7890
|
|
|
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) {
|
|
7891
|
+
var createScrollMotionValues = function () { return ({
|
|
7892
|
+
scrollX: motionValue(0),
|
|
7893
|
+
scrollY: motionValue(0),
|
|
7894
|
+
scrollXProgress: motionValue(0),
|
|
7895
|
+
scrollYProgress: motionValue(0),
|
|
7896
|
+
}); };
|
|
7897
|
+
function useScroll(_a) {
|
|
7898
|
+
if (_a === void 0) { _a = {}; }
|
|
7899
|
+
var container = _a.container, target = _a.target, options = tslib.__rest(_a, ["container", "target"]);
|
|
7949
7900
|
var values = useConstant(createScrollMotionValues);
|
|
7950
7901
|
useIsomorphicLayoutEffect(function () {
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
return function () {
|
|
7959
|
-
scrollListener && scrollListener();
|
|
7960
|
-
resizeListener && resizeListener();
|
|
7961
|
-
};
|
|
7902
|
+
return dom.scroll(function (_a) {
|
|
7903
|
+
var x = _a.x, y = _a.y;
|
|
7904
|
+
values.scrollX.set(x.current);
|
|
7905
|
+
values.scrollXProgress.set(x.progress);
|
|
7906
|
+
values.scrollY.set(y.current);
|
|
7907
|
+
values.scrollYProgress.set(y.progress);
|
|
7908
|
+
}, 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
7909
|
}, []);
|
|
7963
7910
|
return values;
|
|
7964
7911
|
}
|
|
7965
7912
|
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
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);
|
|
7913
|
+
/**
|
|
7914
|
+
* @deprecated useElementScroll is deprecated. Convert to useScroll({ container: ref })
|
|
7915
|
+
*/
|
|
7916
|
+
function useElementScroll(ref) {
|
|
7917
|
+
warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
|
|
7918
|
+
return useScroll({ container: ref });
|
|
7981
7919
|
}
|
|
7920
|
+
|
|
7982
7921
|
/**
|
|
7983
|
-
*
|
|
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
|
|
7922
|
+
* @deprecated useViewportScroll is deprecated. Convert to useScroll()
|
|
8001
7923
|
*/
|
|
8002
7924
|
function useViewportScroll() {
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
*/
|
|
8006
|
-
if (!viewportScrollValues) {
|
|
8007
|
-
viewportScrollValues = createScrollMotionValues();
|
|
8008
|
-
}
|
|
8009
|
-
useIsomorphicLayoutEffect(function () {
|
|
8010
|
-
!hasListeners && addEventListeners();
|
|
8011
|
-
}, []);
|
|
8012
|
-
return viewportScrollValues;
|
|
7925
|
+
warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
|
|
7926
|
+
return useScroll();
|
|
8013
7927
|
}
|
|
8014
7928
|
|
|
8015
|
-
var getCurrentTime = typeof performance !== "undefined"
|
|
8016
|
-
? function () { return performance.now(); }
|
|
8017
|
-
: function () { return Date.now(); };
|
|
8018
7929
|
function useAnimationFrame(callback) {
|
|
8019
|
-
var initialTimestamp =
|
|
7930
|
+
var initialTimestamp = React.useRef(0);
|
|
8020
7931
|
var isStatic = React.useContext(MotionConfigContext).isStatic;
|
|
8021
7932
|
React.useEffect(function () {
|
|
8022
7933
|
if (isStatic)
|
|
8023
7934
|
return;
|
|
8024
7935
|
var provideTimeSinceStart = function (_a) {
|
|
8025
7936
|
var timestamp = _a.timestamp;
|
|
8026
|
-
|
|
7937
|
+
if (!initialTimestamp.current)
|
|
7938
|
+
initialTimestamp.current = timestamp;
|
|
7939
|
+
callback(timestamp - initialTimestamp.current);
|
|
8027
7940
|
};
|
|
8028
7941
|
sync__default["default"].update(provideTimeSinceStart, true);
|
|
8029
7942
|
return function () { return sync.cancelSync.update(provideTimeSinceStart); };
|
|
@@ -8494,6 +8407,7 @@ exports.usePresence = usePresence;
|
|
|
8494
8407
|
exports.useReducedMotion = useReducedMotion;
|
|
8495
8408
|
exports.useReducedMotionConfig = useReducedMotionConfig;
|
|
8496
8409
|
exports.useResetProjection = useResetProjection;
|
|
8410
|
+
exports.useScroll = useScroll;
|
|
8497
8411
|
exports.useSpring = useSpring;
|
|
8498
8412
|
exports.useTime = useTime;
|
|
8499
8413
|
exports.useTransform = useTransform;
|
|
@@ -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 () {
|
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';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mix, progress,
|
|
2
|
-
import {
|
|
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 {
|
|
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 === "
|
|
21
|
+
warnOnce(nextValue.version === "7.0.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.0.0 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 =
|
|
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
|
-
|
|
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); };
|
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 = "
|
|
28
|
+
this.version = "7.0.0";
|
|
29
29
|
/**
|
|
30
30
|
* Duration, in milliseconds, since last updating frame.
|
|
31
31
|
*
|
|
@@ -1,58 +1,12 @@
|
|
|
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
4
|
/**
|
|
16
|
-
*
|
|
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
|
|
5
|
+
* @deprecated useElementScroll is deprecated. Convert to useScroll({ container: ref })
|
|
39
6
|
*/
|
|
40
7
|
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;
|
|
8
|
+
warnOnce(false, "useElementScroll is deprecated. Convert to useScroll({ container: ref }).");
|
|
9
|
+
return useScroll({ container: ref });
|
|
56
10
|
}
|
|
57
11
|
|
|
58
12
|
export { useElementScroll };
|
|
@@ -1,54 +1,12 @@
|
|
|
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
4
|
/**
|
|
22
|
-
*
|
|
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
|
|
5
|
+
* @deprecated useViewportScroll is deprecated. Convert to useScroll()
|
|
40
6
|
*/
|
|
41
7
|
function useViewportScroll() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*/
|
|
45
|
-
if (!viewportScrollValues) {
|
|
46
|
-
viewportScrollValues = createScrollMotionValues();
|
|
47
|
-
}
|
|
48
|
-
useIsomorphicLayoutEffect(function () {
|
|
49
|
-
!hasListeners && addEventListeners();
|
|
50
|
-
}, []);
|
|
51
|
-
return viewportScrollValues;
|
|
8
|
+
warnOnce(false, "useViewportScroll is deprecated. Convert to useScroll().");
|
|
9
|
+
return useScroll();
|
|
52
10
|
}
|
|
53
11
|
|
|
54
12
|
export { useViewportScroll };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
1
|
import { isMotionValue } from './utils/is-motion-value.mjs';
|
|
2
|
+
import { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';
|
|
3
3
|
|
|
4
4
|
function useOnChange(value, callback) {
|
|
5
|
-
|
|
5
|
+
useIsomorphicLayoutEffect(function () {
|
|
6
6
|
if (isMotionValue(value))
|
|
7
7
|
return value.onChange(callback);
|
|
8
8
|
}, [callback]);
|
|
9
9
|
}
|
|
10
10
|
function useMultiOnChange(values, handler) {
|
|
11
|
-
|
|
11
|
+
useIsomorphicLayoutEffect(function () {
|
|
12
12
|
var subscriptions = values.map(function (value) { return value.onChange(handler); });
|
|
13
13
|
return function () { return subscriptions.forEach(function (unsubscribe) { return unsubscribe(); }); };
|
|
14
14
|
});
|
|
@@ -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 };
|