framer-motion 6.3.16 → 6.4.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 -2
- package/dist/es/index.mjs +1 -0
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/utils/use-in-view.mjs +26 -0
- package/dist/es/value/index.mjs +1 -1
- package/dist/framer-motion.dev.js +93 -2
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +9 -1
- 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 +4 -3
package/dist/cjs/index.js
CHANGED
|
@@ -8,6 +8,7 @@ var heyListen = require('hey-listen');
|
|
|
8
8
|
var sync = require('framesync');
|
|
9
9
|
var popmotion = require('popmotion');
|
|
10
10
|
var styleValueTypes = require('style-value-types');
|
|
11
|
+
var dom = require('@motionone/dom');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
@@ -472,7 +473,7 @@ var MotionValue = /** @class */ (function () {
|
|
|
472
473
|
* This will be replaced by the build step with the latest version number.
|
|
473
474
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
474
475
|
*/
|
|
475
|
-
this.version = "6.
|
|
476
|
+
this.version = "6.4.0";
|
|
476
477
|
/**
|
|
477
478
|
* Duration, in milliseconds, since last updating frame.
|
|
478
479
|
*
|
|
@@ -5983,7 +5984,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
5983
5984
|
* and warn against mismatches.
|
|
5984
5985
|
*/
|
|
5985
5986
|
if (process.env.NODE_ENV === "development") {
|
|
5986
|
-
warnOnce(nextValue.version === "6.
|
|
5987
|
+
warnOnce(nextValue.version === "6.4.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.0 may not work as expected."));
|
|
5987
5988
|
}
|
|
5988
5989
|
}
|
|
5989
5990
|
else if (isMotionValue(prevValue)) {
|
|
@@ -8185,6 +8186,27 @@ function useCycle() {
|
|
|
8185
8186
|
return [item, runCycle];
|
|
8186
8187
|
}
|
|
8187
8188
|
|
|
8189
|
+
function useInView(ref, _a) {
|
|
8190
|
+
var _b = _a === void 0 ? {} : _a, root = _b.root, margin = _b.margin, amount = _b.amount, _c = _b.once, once = _c === void 0 ? false : _c;
|
|
8191
|
+
var _d = tslib.__read(React.useState(false), 2), isInView = _d[0], setInView = _d[1];
|
|
8192
|
+
React.useEffect(function () {
|
|
8193
|
+
var _a;
|
|
8194
|
+
if (!ref.current || (once && isInView))
|
|
8195
|
+
return;
|
|
8196
|
+
var onEnter = function () {
|
|
8197
|
+
setInView(true);
|
|
8198
|
+
return once ? undefined : function () { return setInView(false); };
|
|
8199
|
+
};
|
|
8200
|
+
var options = {
|
|
8201
|
+
root: (_a = root === null || root === void 0 ? void 0 : root.current) !== null && _a !== void 0 ? _a : undefined,
|
|
8202
|
+
margin: margin,
|
|
8203
|
+
amount: amount === "some" ? "any" : amount,
|
|
8204
|
+
};
|
|
8205
|
+
return dom.inView(ref.current, onEnter, options);
|
|
8206
|
+
}, [root, ref, margin, once]);
|
|
8207
|
+
return isInView;
|
|
8208
|
+
}
|
|
8209
|
+
|
|
8188
8210
|
/**
|
|
8189
8211
|
* Can manually trigger a drag gesture on one or more `drag`-enabled `motion` components.
|
|
8190
8212
|
*
|
|
@@ -8458,6 +8480,7 @@ exports.useDomEvent = useDomEvent;
|
|
|
8458
8480
|
exports.useDragControls = useDragControls;
|
|
8459
8481
|
exports.useElementScroll = useElementScroll;
|
|
8460
8482
|
exports.useForceUpdate = useForceUpdate;
|
|
8483
|
+
exports.useInView = useInView;
|
|
8461
8484
|
exports.useInstantLayoutTransition = useInstantLayoutTransition;
|
|
8462
8485
|
exports.useInstantTransition = useInstantTransition;
|
|
8463
8486
|
exports.useIsPresent = useIsPresent;
|
package/dist/es/index.mjs
CHANGED
|
@@ -28,6 +28,7 @@ export { useCycle } from './utils/use-cycle.mjs';
|
|
|
28
28
|
export { transform } from './utils/transform.mjs';
|
|
29
29
|
export { isValidMotionProp } from './motion/utils/valid-prop.mjs';
|
|
30
30
|
export { useIsPresent, usePresence } from './components/AnimatePresence/use-presence.mjs';
|
|
31
|
+
export { useInView } from './utils/use-in-view.mjs';
|
|
31
32
|
export { DragControls, useDragControls } from './gestures/drag/use-drag-controls.mjs';
|
|
32
33
|
export { useDomEvent } from './events/use-dom-event.mjs';
|
|
33
34
|
export { createMotionComponent } from './motion/index.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.4.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.0 may not work as expected."));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
else if (isMotionValue(prevValue)) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { __read } from 'tslib';
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { inView } from '@motionone/dom';
|
|
4
|
+
|
|
5
|
+
function useInView(ref, _a) {
|
|
6
|
+
var _b = _a === void 0 ? {} : _a, root = _b.root, margin = _b.margin, amount = _b.amount, _c = _b.once, once = _c === void 0 ? false : _c;
|
|
7
|
+
var _d = __read(useState(false), 2), isInView = _d[0], setInView = _d[1];
|
|
8
|
+
useEffect(function () {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!ref.current || (once && isInView))
|
|
11
|
+
return;
|
|
12
|
+
var onEnter = function () {
|
|
13
|
+
setInView(true);
|
|
14
|
+
return once ? undefined : function () { return setInView(false); };
|
|
15
|
+
};
|
|
16
|
+
var options = {
|
|
17
|
+
root: (_a = root === null || root === void 0 ? void 0 : root.current) !== null && _a !== void 0 ? _a : undefined,
|
|
18
|
+
margin: margin,
|
|
19
|
+
amount: amount === "some" ? "any" : amount,
|
|
20
|
+
};
|
|
21
|
+
return inView(ref.current, onEnter, options);
|
|
22
|
+
}, [root, ref, margin, once]);
|
|
23
|
+
return isInView;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { useInView };
|
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.4.0";
|
|
29
29
|
/**
|
|
30
30
|
* Duration, in milliseconds, since last updating frame.
|
|
31
31
|
*
|
|
@@ -1706,7 +1706,7 @@
|
|
|
1706
1706
|
* This will be replaced by the build step with the latest version number.
|
|
1707
1707
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
1708
1708
|
*/
|
|
1709
|
-
this.version = "6.
|
|
1709
|
+
this.version = "6.4.0";
|
|
1710
1710
|
/**
|
|
1711
1711
|
* Duration, in milliseconds, since last updating frame.
|
|
1712
1712
|
*
|
|
@@ -7217,7 +7217,7 @@
|
|
|
7217
7217
|
* and warn against mismatches.
|
|
7218
7218
|
*/
|
|
7219
7219
|
{
|
|
7220
|
-
warnOnce(nextValue.version === "6.
|
|
7220
|
+
warnOnce(nextValue.version === "6.4.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.0 may not work as expected."));
|
|
7221
7221
|
}
|
|
7222
7222
|
}
|
|
7223
7223
|
else if (isMotionValue(prevValue)) {
|
|
@@ -9419,6 +9419,96 @@
|
|
|
9419
9419
|
return [item, runCycle];
|
|
9420
9420
|
}
|
|
9421
9421
|
|
|
9422
|
+
function resolveElements(elements, selectorCache) {
|
|
9423
|
+
var _a;
|
|
9424
|
+
if (typeof elements === "string") {
|
|
9425
|
+
if (selectorCache) {
|
|
9426
|
+
(_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = document.querySelectorAll(elements));
|
|
9427
|
+
elements = selectorCache[elements];
|
|
9428
|
+
}
|
|
9429
|
+
else {
|
|
9430
|
+
elements = document.querySelectorAll(elements);
|
|
9431
|
+
}
|
|
9432
|
+
}
|
|
9433
|
+
else if (elements instanceof Element) {
|
|
9434
|
+
elements = [elements];
|
|
9435
|
+
}
|
|
9436
|
+
/**
|
|
9437
|
+
* Return an empty array
|
|
9438
|
+
*/
|
|
9439
|
+
return Array.from(elements || []);
|
|
9440
|
+
}
|
|
9441
|
+
|
|
9442
|
+
const thresholds = {
|
|
9443
|
+
any: 0,
|
|
9444
|
+
all: 1,
|
|
9445
|
+
};
|
|
9446
|
+
function inView(elements, onStart, { root, margin: rootMargin, amount = "any" } = {}) {
|
|
9447
|
+
/**
|
|
9448
|
+
* If this browser doesn't support IntersectionObserver, return a dummy stop function.
|
|
9449
|
+
* Default triggering of onStart is tricky - it could be used for starting/stopping
|
|
9450
|
+
* videos, lazy loading content etc. We could provide an option to enable a fallback, or
|
|
9451
|
+
* provide a fallback callback option.
|
|
9452
|
+
*/
|
|
9453
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
9454
|
+
return () => { };
|
|
9455
|
+
}
|
|
9456
|
+
const resolvedElements = resolveElements(elements);
|
|
9457
|
+
const activeIntersections = new WeakMap();
|
|
9458
|
+
const onIntersectionChange = (entries) => {
|
|
9459
|
+
entries.forEach((entry) => {
|
|
9460
|
+
const onEnd = activeIntersections.get(entry.target);
|
|
9461
|
+
/**
|
|
9462
|
+
* If there's no change to the intersection, we don't need to
|
|
9463
|
+
* do anything here.
|
|
9464
|
+
*/
|
|
9465
|
+
if (entry.isIntersecting === Boolean(onEnd))
|
|
9466
|
+
return;
|
|
9467
|
+
if (entry.isIntersecting) {
|
|
9468
|
+
const newOnEnd = onStart(entry);
|
|
9469
|
+
if (typeof newOnEnd === "function") {
|
|
9470
|
+
activeIntersections.set(entry.target, newOnEnd);
|
|
9471
|
+
}
|
|
9472
|
+
else {
|
|
9473
|
+
observer.unobserve(entry.target);
|
|
9474
|
+
}
|
|
9475
|
+
}
|
|
9476
|
+
else if (onEnd) {
|
|
9477
|
+
onEnd(entry);
|
|
9478
|
+
activeIntersections.delete(entry.target);
|
|
9479
|
+
}
|
|
9480
|
+
});
|
|
9481
|
+
};
|
|
9482
|
+
const observer = new IntersectionObserver(onIntersectionChange, {
|
|
9483
|
+
root,
|
|
9484
|
+
rootMargin,
|
|
9485
|
+
threshold: typeof amount === "number" ? amount : thresholds[amount],
|
|
9486
|
+
});
|
|
9487
|
+
resolvedElements.forEach((element) => observer.observe(element));
|
|
9488
|
+
return () => observer.disconnect();
|
|
9489
|
+
}
|
|
9490
|
+
|
|
9491
|
+
function useInView(ref, _a) {
|
|
9492
|
+
var _b = _a === void 0 ? {} : _a, root = _b.root, margin = _b.margin, amount = _b.amount, _c = _b.once, once = _c === void 0 ? false : _c;
|
|
9493
|
+
var _d = __read(React.useState(false), 2), isInView = _d[0], setInView = _d[1];
|
|
9494
|
+
React.useEffect(function () {
|
|
9495
|
+
var _a;
|
|
9496
|
+
if (!ref.current || (once && isInView))
|
|
9497
|
+
return;
|
|
9498
|
+
var onEnter = function () {
|
|
9499
|
+
setInView(true);
|
|
9500
|
+
return once ? undefined : function () { return setInView(false); };
|
|
9501
|
+
};
|
|
9502
|
+
var options = {
|
|
9503
|
+
root: (_a = root === null || root === void 0 ? void 0 : root.current) !== null && _a !== void 0 ? _a : undefined,
|
|
9504
|
+
margin: margin,
|
|
9505
|
+
amount: amount === "some" ? "any" : amount,
|
|
9506
|
+
};
|
|
9507
|
+
return inView(ref.current, onEnter, options);
|
|
9508
|
+
}, [root, ref, margin, once]);
|
|
9509
|
+
return isInView;
|
|
9510
|
+
}
|
|
9511
|
+
|
|
9422
9512
|
/**
|
|
9423
9513
|
* Can manually trigger a drag gesture on one or more `drag`-enabled `motion` components.
|
|
9424
9514
|
*
|
|
@@ -9692,6 +9782,7 @@
|
|
|
9692
9782
|
exports.useDragControls = useDragControls;
|
|
9693
9783
|
exports.useElementScroll = useElementScroll;
|
|
9694
9784
|
exports.useForceUpdate = useForceUpdate;
|
|
9785
|
+
exports.useInView = useInView;
|
|
9695
9786
|
exports.useInstantLayoutTransition = useInstantLayoutTransition;
|
|
9696
9787
|
exports.useInstantTransition = useInstantTransition;
|
|
9697
9788
|
exports.useIsPresent = useIsPresent;
|