framer-motion 6.2.1 → 6.2.6
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 +75 -50
- package/dist/es/animation/use-animated-state.mjs +6 -4
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +2 -7
- package/dist/es/components/AnimatePresence/index.mjs +27 -28
- package/dist/es/components/AnimatePresence/use-presence.mjs +3 -6
- package/dist/es/index.mjs +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +15 -3
- package/dist/es/render/index.mjs +1 -0
- package/dist/es/render/utils/lifecycles.mjs +1 -1
- package/dist/es/utils/use-force-update.mjs +4 -5
- package/dist/es/utils/use-id.mjs +15 -0
- package/dist/es/utils/use-is-mounted.mjs +14 -0
- package/dist/framer-motion.dev.js +73 -49
- package/dist/framer-motion.js +1 -1
- package/dist/projection.dev.js +17 -4
- 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 -1
- package/package.json +9 -5
- package/types/index.d.ts +1 -1
- package/types/projection/node/DocumentProjectionNode.d.ts +1 -1
- package/types/projection/node/HTMLProjectionNode.d.ts +1 -1
- package/types/projection/node/create-projection-node.d.ts +1 -1
- package/types/projection/node/types.d.ts +1 -1
- package/types/render/utils/lifecycles.d.ts +1 -1
- package/types/utils/use-id.d.ts +6 -0
- package/types/utils/use-is-mounted.d.ts +2 -0
|
@@ -3130,9 +3130,6 @@
|
|
|
3130
3130
|
};
|
|
3131
3131
|
this.hasProjected = false;
|
|
3132
3132
|
this.isVisible = true;
|
|
3133
|
-
/**
|
|
3134
|
-
* Animation
|
|
3135
|
-
*/
|
|
3136
3133
|
this.animationProgress = 0;
|
|
3137
3134
|
/**
|
|
3138
3135
|
* Shared layout
|
|
@@ -3257,6 +3254,15 @@
|
|
|
3257
3254
|
_this.startAnimation(animationOptions);
|
|
3258
3255
|
}
|
|
3259
3256
|
else {
|
|
3257
|
+
/**
|
|
3258
|
+
* If the layout hasn't changed and we have an animation that hasn't started yet,
|
|
3259
|
+
* finish it immediately. Otherwise it will be animating from a location
|
|
3260
|
+
* that was probably never commited to screen and look like a jumpy box.
|
|
3261
|
+
*/
|
|
3262
|
+
if (!hasLayoutChanged &&
|
|
3263
|
+
_this.animationProgress === 0) {
|
|
3264
|
+
_this.finishAnimation();
|
|
3265
|
+
}
|
|
3260
3266
|
_this.isLead() && ((_f = (_e = _this.options).onExitComplete) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
3261
3267
|
}
|
|
3262
3268
|
_this.targetLayout = newLayout;
|
|
@@ -3746,6 +3752,7 @@
|
|
|
3746
3752
|
!isOnlyMember &&
|
|
3747
3753
|
this.options.crossfade === true &&
|
|
3748
3754
|
!this.path.some(hasOpacityCrossfade));
|
|
3755
|
+
this.animationProgress = 0;
|
|
3749
3756
|
this.mixTargetDelta = function (latest) {
|
|
3750
3757
|
var _a;
|
|
3751
3758
|
var progress = latest / 1000;
|
|
@@ -3765,6 +3772,7 @@
|
|
|
3765
3772
|
}
|
|
3766
3773
|
_this.root.scheduleUpdateProjection();
|
|
3767
3774
|
_this.scheduleRender();
|
|
3775
|
+
_this.animationProgress = progress;
|
|
3768
3776
|
};
|
|
3769
3777
|
this.mixTargetDelta(0);
|
|
3770
3778
|
};
|
|
@@ -4130,6 +4138,10 @@
|
|
|
4130
4138
|
node.clearMeasurements();
|
|
4131
4139
|
}
|
|
4132
4140
|
function resetTransformStyle(node) {
|
|
4141
|
+
var visualElement = node.options.visualElement;
|
|
4142
|
+
if (visualElement === null || visualElement === void 0 ? void 0 : visualElement.getProps().onBeforeLayoutMeasure) {
|
|
4143
|
+
visualElement.notifyBeforeLayoutMeasure();
|
|
4144
|
+
}
|
|
4133
4145
|
node.resetTransform();
|
|
4134
4146
|
}
|
|
4135
4147
|
function finishAnimation(node) {
|
|
@@ -5570,6 +5582,18 @@
|
|
|
5570
5582
|
hover: makeRenderlessComponent(useHoverGesture),
|
|
5571
5583
|
};
|
|
5572
5584
|
|
|
5585
|
+
var counter = 0;
|
|
5586
|
+
var incrementId = function () { return counter++; };
|
|
5587
|
+
var useId = function () { return useConstant(incrementId); };
|
|
5588
|
+
/**
|
|
5589
|
+
* Ideally we'd use the following code to support React 18 optionally.
|
|
5590
|
+
* But this fairly fails in Webpack (otherwise treeshaking wouldn't work at all).
|
|
5591
|
+
* Need to come up with a different way of figuring this out.
|
|
5592
|
+
*/
|
|
5593
|
+
// export const useId = (React as any).useId
|
|
5594
|
+
// ? (React as any).useId
|
|
5595
|
+
// : () => useConstant(incrementId)
|
|
5596
|
+
|
|
5573
5597
|
/**
|
|
5574
5598
|
* When a component is the child of `AnimatePresence`, it can use `usePresence`
|
|
5575
5599
|
* to access information about whether it's still present in the React tree.
|
|
@@ -5600,8 +5624,8 @@
|
|
|
5600
5624
|
var isPresent = context.isPresent, onExitComplete = context.onExitComplete, register = context.register;
|
|
5601
5625
|
// It's safe to call the following hooks conditionally (after an early return) because the context will always
|
|
5602
5626
|
// either be null or non-null for the lifespan of the component.
|
|
5603
|
-
// Replace with
|
|
5604
|
-
var id =
|
|
5627
|
+
// Replace with useId when released in React
|
|
5628
|
+
var id = useId();
|
|
5605
5629
|
React.useEffect(function () { return register(id); }, []);
|
|
5606
5630
|
var safeToRemove = function () { return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id); };
|
|
5607
5631
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
@@ -5632,9 +5656,6 @@
|
|
|
5632
5656
|
function isPresent(context) {
|
|
5633
5657
|
return context === null ? true : context.isPresent;
|
|
5634
5658
|
}
|
|
5635
|
-
var counter = 0;
|
|
5636
|
-
var incrementId = function () { return counter++; };
|
|
5637
|
-
var useUniqueId = function () { return useConstant(incrementId); };
|
|
5638
5659
|
|
|
5639
5660
|
function shallowCompare(next, prev) {
|
|
5640
5661
|
if (!Array.isArray(prev))
|
|
@@ -7136,7 +7157,7 @@
|
|
|
7136
7157
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
7137
7158
|
args[_i] = arguments[_i];
|
|
7138
7159
|
}
|
|
7139
|
-
manager.notify.apply(manager, __spreadArray([], __read(args), false));
|
|
7160
|
+
return manager.notify.apply(manager, __spreadArray([], __read(args), false));
|
|
7140
7161
|
};
|
|
7141
7162
|
});
|
|
7142
7163
|
return lifecycles;
|
|
@@ -7339,6 +7360,7 @@
|
|
|
7339
7360
|
if (isVariantNode && parent && !isControllingVariants) {
|
|
7340
7361
|
removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
|
|
7341
7362
|
}
|
|
7363
|
+
values.forEach(function (value, key) { return bindToMotionValue(key, value); });
|
|
7342
7364
|
parent === null || parent === void 0 ? void 0 : parent.children.add(element);
|
|
7343
7365
|
element.setProps(props);
|
|
7344
7366
|
},
|
|
@@ -8319,12 +8341,22 @@
|
|
|
8319
8341
|
*/
|
|
8320
8342
|
var m = createMotionProxy(createDomMotionConfig);
|
|
8321
8343
|
|
|
8344
|
+
function useIsMounted() {
|
|
8345
|
+
var isMounted = React.useRef(false);
|
|
8346
|
+
React.useLayoutEffect(function () {
|
|
8347
|
+
isMounted.current = true;
|
|
8348
|
+
return function () {
|
|
8349
|
+
isMounted.current = false;
|
|
8350
|
+
};
|
|
8351
|
+
}, []);
|
|
8352
|
+
return isMounted;
|
|
8353
|
+
}
|
|
8354
|
+
|
|
8322
8355
|
function useForceUpdate() {
|
|
8323
|
-
var
|
|
8356
|
+
var isMounted = useIsMounted();
|
|
8324
8357
|
var _a = __read(React.useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
|
|
8325
|
-
useUnmountEffect(function () { return (isUnmountingRef.current = true); });
|
|
8326
8358
|
var forceRender = React.useCallback(function () {
|
|
8327
|
-
|
|
8359
|
+
isMounted.current && setForcedRenderCount(forcedRenderCount + 1);
|
|
8328
8360
|
}, [forcedRenderCount]);
|
|
8329
8361
|
/**
|
|
8330
8362
|
* Defer this to the end of the next animation frame in case there are multiple
|
|
@@ -8334,16 +8366,10 @@
|
|
|
8334
8366
|
return [deferredForceRender, forcedRenderCount];
|
|
8335
8367
|
}
|
|
8336
8368
|
|
|
8337
|
-
var presenceId = 0;
|
|
8338
|
-
function getPresenceId() {
|
|
8339
|
-
var id = presenceId;
|
|
8340
|
-
presenceId++;
|
|
8341
|
-
return id;
|
|
8342
|
-
}
|
|
8343
8369
|
var PresenceChild = function (_a) {
|
|
8344
8370
|
var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
|
|
8345
8371
|
var presenceChildren = useConstant(newChildrenMap);
|
|
8346
|
-
var id =
|
|
8372
|
+
var id = useId();
|
|
8347
8373
|
var context = React.useMemo(function () { return ({
|
|
8348
8374
|
id: id,
|
|
8349
8375
|
initial: initial,
|
|
@@ -8395,17 +8421,13 @@
|
|
|
8395
8421
|
return new Map();
|
|
8396
8422
|
}
|
|
8397
8423
|
|
|
8398
|
-
function
|
|
8399
|
-
return child.key || "";
|
|
8400
|
-
}
|
|
8424
|
+
var getChildKey = function (child) { return child.key || ""; };
|
|
8401
8425
|
function updateChildLookup(children, allChildren) {
|
|
8402
8426
|
var seenChildren = new Set() ;
|
|
8403
8427
|
children.forEach(function (child) {
|
|
8404
8428
|
var key = getChildKey(child);
|
|
8405
|
-
if (seenChildren) {
|
|
8406
|
-
|
|
8407
|
-
console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
|
|
8408
|
-
}
|
|
8429
|
+
if (seenChildren && seenChildren.has(key)) {
|
|
8430
|
+
console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
|
|
8409
8431
|
seenChildren.add(key);
|
|
8410
8432
|
}
|
|
8411
8433
|
allChildren.set(key, child);
|
|
@@ -8461,29 +8483,34 @@
|
|
|
8461
8483
|
var forceRenderLayoutGroup = React.useContext(LayoutGroupContext).forceRender;
|
|
8462
8484
|
if (forceRenderLayoutGroup)
|
|
8463
8485
|
forceRender = forceRenderLayoutGroup;
|
|
8464
|
-
var
|
|
8465
|
-
var isMounted = React.useRef(true);
|
|
8466
|
-
React.useEffect(function () { return function () {
|
|
8467
|
-
isMounted.current = false;
|
|
8468
|
-
}; }, []);
|
|
8486
|
+
var isMounted = useIsMounted();
|
|
8469
8487
|
// Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key
|
|
8470
8488
|
var filteredChildren = onlyElements(children);
|
|
8489
|
+
var childrenToRender = filteredChildren;
|
|
8490
|
+
var exiting = new Set();
|
|
8471
8491
|
// Keep a living record of the children we're actually rendering so we
|
|
8472
8492
|
// can diff to figure out which are entering and exiting
|
|
8473
|
-
var presentChildren = React.useRef(
|
|
8493
|
+
var presentChildren = React.useRef(childrenToRender);
|
|
8474
8494
|
// A lookup table to quickly reference components by key
|
|
8475
8495
|
var allChildren = React.useRef(new Map()).current;
|
|
8476
|
-
// A living record of all currently exiting components.
|
|
8477
|
-
var exiting = React.useRef(new Set()).current;
|
|
8478
|
-
updateChildLookup(filteredChildren, allChildren);
|
|
8479
8496
|
// If this is the initial component render, just deal with logic surrounding whether
|
|
8480
8497
|
// we play onMount animations or not.
|
|
8481
|
-
|
|
8498
|
+
var isInitialRender = React.useRef(true);
|
|
8499
|
+
useIsomorphicLayoutEffect(function () {
|
|
8482
8500
|
isInitialRender.current = false;
|
|
8483
|
-
|
|
8501
|
+
updateChildLookup(filteredChildren, allChildren);
|
|
8502
|
+
presentChildren.current = childrenToRender;
|
|
8503
|
+
});
|
|
8504
|
+
useUnmountEffect(function () {
|
|
8505
|
+
isInitialRender.current = true;
|
|
8506
|
+
allChildren.clear();
|
|
8507
|
+
exiting.clear();
|
|
8508
|
+
});
|
|
8509
|
+
if (isInitialRender.current) {
|
|
8510
|
+
return (React__namespace.createElement(React__namespace.Fragment, null, childrenToRender.map(function (child) { return (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
|
|
8484
8511
|
}
|
|
8485
8512
|
// If this is a subsequent render, deal with entering and exiting children
|
|
8486
|
-
|
|
8513
|
+
childrenToRender = __spreadArray([], __read(childrenToRender), false);
|
|
8487
8514
|
// Diff the keys of the currently-present and target children to update our
|
|
8488
8515
|
// exiting list.
|
|
8489
8516
|
var presentKeys = presentChildren.current.map(getChildKey);
|
|
@@ -8495,10 +8522,6 @@
|
|
|
8495
8522
|
if (targetKeys.indexOf(key) === -1) {
|
|
8496
8523
|
exiting.add(key);
|
|
8497
8524
|
}
|
|
8498
|
-
else {
|
|
8499
|
-
// In case this key has re-entered, remove from the exiting list
|
|
8500
|
-
exiting.delete(key);
|
|
8501
|
-
}
|
|
8502
8525
|
}
|
|
8503
8526
|
// If we currently have exiting children, and we're deferring rendering incoming children
|
|
8504
8527
|
// until after all current children have exiting, empty the childrenToRender array
|
|
@@ -8524,9 +8547,8 @@
|
|
|
8524
8547
|
// Defer re-rendering until all exiting children have indeed left
|
|
8525
8548
|
if (!exiting.size) {
|
|
8526
8549
|
presentChildren.current = filteredChildren;
|
|
8527
|
-
if (isMounted.current === false)
|
|
8550
|
+
if (isMounted.current === false)
|
|
8528
8551
|
return;
|
|
8529
|
-
}
|
|
8530
8552
|
forceRender();
|
|
8531
8553
|
onExitComplete && onExitComplete();
|
|
8532
8554
|
}
|
|
@@ -8539,7 +8561,6 @@
|
|
|
8539
8561
|
var key = child.key;
|
|
8540
8562
|
return exiting.has(key) ? (child) : (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
|
|
8541
8563
|
});
|
|
8542
|
-
presentChildren.current = childrenToRender;
|
|
8543
8564
|
if (exitBeforeEnter &&
|
|
8544
8565
|
childrenToRender.length > 1) {
|
|
8545
8566
|
console.warn("You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.");
|
|
@@ -9509,13 +9530,15 @@
|
|
|
9509
9530
|
});
|
|
9510
9531
|
React.useEffect(function () {
|
|
9511
9532
|
element.mount({});
|
|
9512
|
-
return element.unmount
|
|
9513
|
-
}, []);
|
|
9533
|
+
return element.unmount;
|
|
9534
|
+
}, [element]);
|
|
9514
9535
|
React.useEffect(function () {
|
|
9515
9536
|
element.setProps({
|
|
9516
|
-
onUpdate: function (v) {
|
|
9537
|
+
onUpdate: function (v) {
|
|
9538
|
+
setAnimationState(__assign({}, v));
|
|
9539
|
+
},
|
|
9517
9540
|
});
|
|
9518
|
-
});
|
|
9541
|
+
}, [setAnimationState, element]);
|
|
9519
9542
|
var startAnimation = useConstant(function () { return function (animationDefinition) {
|
|
9520
9543
|
return animateVisualElement(element, animationDefinition);
|
|
9521
9544
|
}; });
|
|
@@ -9626,6 +9649,7 @@
|
|
|
9626
9649
|
exports.useMotionValue = useMotionValue;
|
|
9627
9650
|
exports.usePresence = usePresence;
|
|
9628
9651
|
exports.useReducedMotion = useReducedMotion;
|
|
9652
|
+
exports.useReducedMotionConfig = useReducedMotionConfig;
|
|
9629
9653
|
exports.useResetProjection = useResetProjection;
|
|
9630
9654
|
exports.useSpring = useSpring;
|
|
9631
9655
|
exports.useTime = useTime;
|