framer-motion 6.3.16 → 6.4.2
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 +28 -3
- package/dist/es/animation/use-animation.mjs +3 -2
- package/dist/es/index.mjs +2 -1
- 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 +111 -3
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +11 -2
- 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.2";
|
|
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.2", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.2 may not work as expected."));
|
|
5987
5988
|
}
|
|
5988
5989
|
}
|
|
5989
5990
|
else if (isMotionValue(prevValue)) {
|
|
@@ -8136,11 +8137,12 @@ function animationControls() {
|
|
|
8136
8137
|
*
|
|
8137
8138
|
* @public
|
|
8138
8139
|
*/
|
|
8139
|
-
function
|
|
8140
|
+
function useAnimationControls() {
|
|
8140
8141
|
var controls = useConstant(animationControls);
|
|
8141
8142
|
React.useEffect(controls.mount, []);
|
|
8142
8143
|
return controls;
|
|
8143
8144
|
}
|
|
8145
|
+
var useAnimation = useAnimationControls;
|
|
8144
8146
|
|
|
8145
8147
|
/**
|
|
8146
8148
|
* Cycles through a series of visual properties. Can be used to toggle between or cycle through animations. It works similar to `useState` in React. It is provided an initial array of possible states, and returns an array of two arguments.
|
|
@@ -8185,6 +8187,27 @@ function useCycle() {
|
|
|
8185
8187
|
return [item, runCycle];
|
|
8186
8188
|
}
|
|
8187
8189
|
|
|
8190
|
+
function useInView(ref, _a) {
|
|
8191
|
+
var _b = _a === void 0 ? {} : _a, root = _b.root, margin = _b.margin, amount = _b.amount, _c = _b.once, once = _c === void 0 ? false : _c;
|
|
8192
|
+
var _d = tslib.__read(React.useState(false), 2), isInView = _d[0], setInView = _d[1];
|
|
8193
|
+
React.useEffect(function () {
|
|
8194
|
+
var _a;
|
|
8195
|
+
if (!ref.current || (once && isInView))
|
|
8196
|
+
return;
|
|
8197
|
+
var onEnter = function () {
|
|
8198
|
+
setInView(true);
|
|
8199
|
+
return once ? undefined : function () { return setInView(false); };
|
|
8200
|
+
};
|
|
8201
|
+
var options = {
|
|
8202
|
+
root: (_a = root === null || root === void 0 ? void 0 : root.current) !== null && _a !== void 0 ? _a : undefined,
|
|
8203
|
+
margin: margin,
|
|
8204
|
+
amount: amount === "some" ? "any" : amount,
|
|
8205
|
+
};
|
|
8206
|
+
return dom.inView(ref.current, onEnter, options);
|
|
8207
|
+
}, [root, ref, margin, once]);
|
|
8208
|
+
return isInView;
|
|
8209
|
+
}
|
|
8210
|
+
|
|
8188
8211
|
/**
|
|
8189
8212
|
* Can manually trigger a drag gesture on one or more `drag`-enabled `motion` components.
|
|
8190
8213
|
*
|
|
@@ -8450,6 +8473,7 @@ exports.motionValue = motionValue;
|
|
|
8450
8473
|
exports.resolveMotionValue = resolveMotionValue;
|
|
8451
8474
|
exports.transform = transform;
|
|
8452
8475
|
exports.useAnimation = useAnimation;
|
|
8476
|
+
exports.useAnimationControls = useAnimationControls;
|
|
8453
8477
|
exports.useAnimationFrame = useAnimationFrame;
|
|
8454
8478
|
exports.useCycle = useCycle;
|
|
8455
8479
|
exports.useDeprecatedAnimatedState = useAnimatedState;
|
|
@@ -8458,6 +8482,7 @@ exports.useDomEvent = useDomEvent;
|
|
|
8458
8482
|
exports.useDragControls = useDragControls;
|
|
8459
8483
|
exports.useElementScroll = useElementScroll;
|
|
8460
8484
|
exports.useForceUpdate = useForceUpdate;
|
|
8485
|
+
exports.useInView = useInView;
|
|
8461
8486
|
exports.useInstantLayoutTransition = useInstantLayoutTransition;
|
|
8462
8487
|
exports.useInstantTransition = useInstantTransition;
|
|
8463
8488
|
exports.useIsPresent = useIsPresent;
|
|
@@ -31,10 +31,11 @@ import { useConstant } from '../utils/use-constant.mjs';
|
|
|
31
31
|
*
|
|
32
32
|
* @public
|
|
33
33
|
*/
|
|
34
|
-
function
|
|
34
|
+
function useAnimationControls() {
|
|
35
35
|
var controls = useConstant(animationControls);
|
|
36
36
|
useEffect(controls.mount, []);
|
|
37
37
|
return controls;
|
|
38
38
|
}
|
|
39
|
+
var useAnimation = useAnimationControls;
|
|
39
40
|
|
|
40
|
-
export { useAnimation };
|
|
41
|
+
export { useAnimation, useAnimationControls };
|
package/dist/es/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ export { useViewportScroll } from './value/scroll/use-viewport-scroll.mjs';
|
|
|
20
20
|
export { useTime } from './value/use-time.mjs';
|
|
21
21
|
export { useReducedMotion, useReducedMotionConfig } from './utils/use-reduced-motion.mjs';
|
|
22
22
|
export { animationControls } from './animation/animation-controls.mjs';
|
|
23
|
-
export { useAnimation } from './animation/use-animation.mjs';
|
|
23
|
+
export { useAnimation, useAnimationControls } from './animation/use-animation.mjs';
|
|
24
24
|
export { useAnimationFrame } from './utils/use-animation-frame.mjs';
|
|
25
25
|
export { animate } from './animation/animate.mjs';
|
|
26
26
|
export { animateVisualElement } from './render/utils/animation.mjs';
|
|
@@ -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.2", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.2 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.2";
|
|
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.2";
|
|
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.2", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.4.2 may not work as expected."));
|
|
7221
7221
|
}
|
|
7222
7222
|
}
|
|
7223
7223
|
else if (isMotionValue(prevValue)) {
|
|
@@ -9370,11 +9370,12 @@
|
|
|
9370
9370
|
*
|
|
9371
9371
|
* @public
|
|
9372
9372
|
*/
|
|
9373
|
-
function
|
|
9373
|
+
function useAnimationControls() {
|
|
9374
9374
|
var controls = useConstant(animationControls);
|
|
9375
9375
|
React.useEffect(controls.mount, []);
|
|
9376
9376
|
return controls;
|
|
9377
9377
|
}
|
|
9378
|
+
var useAnimation = useAnimationControls;
|
|
9378
9379
|
|
|
9379
9380
|
/**
|
|
9380
9381
|
* Cycles through a series of visual properties. Can be used to toggle between or cycle through animations. It works similar to `useState` in React. It is provided an initial array of possible states, and returns an array of two arguments.
|
|
@@ -9419,6 +9420,111 @@
|
|
|
9419
9420
|
return [item, runCycle];
|
|
9420
9421
|
}
|
|
9421
9422
|
|
|
9423
|
+
const noop = () => { };
|
|
9424
|
+
|
|
9425
|
+
function resolveElements(elements, selectorCache) {
|
|
9426
|
+
var _a;
|
|
9427
|
+
if (typeof elements === "string") {
|
|
9428
|
+
if (selectorCache) {
|
|
9429
|
+
(_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = document.querySelectorAll(elements));
|
|
9430
|
+
elements = selectorCache[elements];
|
|
9431
|
+
}
|
|
9432
|
+
else {
|
|
9433
|
+
elements = document.querySelectorAll(elements);
|
|
9434
|
+
}
|
|
9435
|
+
}
|
|
9436
|
+
else if (elements instanceof Element) {
|
|
9437
|
+
elements = [elements];
|
|
9438
|
+
}
|
|
9439
|
+
/**
|
|
9440
|
+
* Return an empty array
|
|
9441
|
+
*/
|
|
9442
|
+
return Array.from(elements || []);
|
|
9443
|
+
}
|
|
9444
|
+
|
|
9445
|
+
let supportsDocumentRoot;
|
|
9446
|
+
function getDefaultRoot() {
|
|
9447
|
+
if (supportsDocumentRoot === undefined) {
|
|
9448
|
+
try {
|
|
9449
|
+
new IntersectionObserver(noop, { root: document });
|
|
9450
|
+
supportsDocumentRoot = true;
|
|
9451
|
+
}
|
|
9452
|
+
catch (e) {
|
|
9453
|
+
supportsDocumentRoot = false;
|
|
9454
|
+
}
|
|
9455
|
+
}
|
|
9456
|
+
return supportsDocumentRoot ? document : undefined;
|
|
9457
|
+
}
|
|
9458
|
+
const thresholds = {
|
|
9459
|
+
any: 0,
|
|
9460
|
+
all: 1,
|
|
9461
|
+
};
|
|
9462
|
+
function inView(elements, onStart, { root, margin: rootMargin, amount = "any" } = {}) {
|
|
9463
|
+
/**
|
|
9464
|
+
* If this browser doesn't support IntersectionObserver, return a dummy stop function.
|
|
9465
|
+
* Default triggering of onStart is tricky - it could be used for starting/stopping
|
|
9466
|
+
* videos, lazy loading content etc. We could provide an option to enable a fallback, or
|
|
9467
|
+
* provide a fallback callback option.
|
|
9468
|
+
*/
|
|
9469
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
9470
|
+
return () => { };
|
|
9471
|
+
}
|
|
9472
|
+
const resolvedElements = resolveElements(elements);
|
|
9473
|
+
const activeIntersections = new WeakMap();
|
|
9474
|
+
const onIntersectionChange = (entries) => {
|
|
9475
|
+
entries.forEach((entry) => {
|
|
9476
|
+
const onEnd = activeIntersections.get(entry.target);
|
|
9477
|
+
/**
|
|
9478
|
+
* If there's no change to the intersection, we don't need to
|
|
9479
|
+
* do anything here.
|
|
9480
|
+
*/
|
|
9481
|
+
if (entry.isIntersecting === Boolean(onEnd))
|
|
9482
|
+
return;
|
|
9483
|
+
if (entry.isIntersecting) {
|
|
9484
|
+
const newOnEnd = onStart(entry);
|
|
9485
|
+
if (typeof newOnEnd === "function") {
|
|
9486
|
+
activeIntersections.set(entry.target, newOnEnd);
|
|
9487
|
+
}
|
|
9488
|
+
else {
|
|
9489
|
+
observer.unobserve(entry.target);
|
|
9490
|
+
}
|
|
9491
|
+
}
|
|
9492
|
+
else if (onEnd) {
|
|
9493
|
+
onEnd(entry);
|
|
9494
|
+
activeIntersections.delete(entry.target);
|
|
9495
|
+
}
|
|
9496
|
+
});
|
|
9497
|
+
};
|
|
9498
|
+
const observer = new IntersectionObserver(onIntersectionChange, {
|
|
9499
|
+
root: root || getDefaultRoot(),
|
|
9500
|
+
rootMargin,
|
|
9501
|
+
threshold: typeof amount === "number" ? amount : thresholds[amount],
|
|
9502
|
+
});
|
|
9503
|
+
resolvedElements.forEach((element) => observer.observe(element));
|
|
9504
|
+
return () => observer.disconnect();
|
|
9505
|
+
}
|
|
9506
|
+
|
|
9507
|
+
function useInView(ref, _a) {
|
|
9508
|
+
var _b = _a === void 0 ? {} : _a, root = _b.root, margin = _b.margin, amount = _b.amount, _c = _b.once, once = _c === void 0 ? false : _c;
|
|
9509
|
+
var _d = __read(React.useState(false), 2), isInView = _d[0], setInView = _d[1];
|
|
9510
|
+
React.useEffect(function () {
|
|
9511
|
+
var _a;
|
|
9512
|
+
if (!ref.current || (once && isInView))
|
|
9513
|
+
return;
|
|
9514
|
+
var onEnter = function () {
|
|
9515
|
+
setInView(true);
|
|
9516
|
+
return once ? undefined : function () { return setInView(false); };
|
|
9517
|
+
};
|
|
9518
|
+
var options = {
|
|
9519
|
+
root: (_a = root === null || root === void 0 ? void 0 : root.current) !== null && _a !== void 0 ? _a : undefined,
|
|
9520
|
+
margin: margin,
|
|
9521
|
+
amount: amount === "some" ? "any" : amount,
|
|
9522
|
+
};
|
|
9523
|
+
return inView(ref.current, onEnter, options);
|
|
9524
|
+
}, [root, ref, margin, once]);
|
|
9525
|
+
return isInView;
|
|
9526
|
+
}
|
|
9527
|
+
|
|
9422
9528
|
/**
|
|
9423
9529
|
* Can manually trigger a drag gesture on one or more `drag`-enabled `motion` components.
|
|
9424
9530
|
*
|
|
@@ -9684,6 +9790,7 @@
|
|
|
9684
9790
|
exports.resolveMotionValue = resolveMotionValue;
|
|
9685
9791
|
exports.transform = transform;
|
|
9686
9792
|
exports.useAnimation = useAnimation;
|
|
9793
|
+
exports.useAnimationControls = useAnimationControls;
|
|
9687
9794
|
exports.useAnimationFrame = useAnimationFrame;
|
|
9688
9795
|
exports.useCycle = useCycle;
|
|
9689
9796
|
exports.useDeprecatedAnimatedState = useAnimatedState;
|
|
@@ -9692,6 +9799,7 @@
|
|
|
9692
9799
|
exports.useDragControls = useDragControls;
|
|
9693
9800
|
exports.useElementScroll = useElementScroll;
|
|
9694
9801
|
exports.useForceUpdate = useForceUpdate;
|
|
9802
|
+
exports.useInView = useInView;
|
|
9695
9803
|
exports.useInstantLayoutTransition = useInstantLayoutTransition;
|
|
9696
9804
|
exports.useInstantTransition = useInstantTransition;
|
|
9697
9805
|
exports.useIsPresent = useIsPresent;
|