framer-motion 7.1.0 → 7.2.0-beta.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 CHANGED
@@ -2437,7 +2437,7 @@ var MotionValue = /** @class */ (function () {
2437
2437
  * This will be replaced by the build step with the latest version number.
2438
2438
  * When MotionValues are provided to motion components, warn if versions are mixed.
2439
2439
  */
2440
- this.version = "7.1.0";
2440
+ this.version = "7.2.0-beta.0";
2441
2441
  /**
2442
2442
  * Duration, in milliseconds, since last updating frame.
2443
2443
  *
@@ -4417,7 +4417,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4417
4417
  * and warn against mismatches.
4418
4418
  */
4419
4419
  if (process.env.NODE_ENV === "development") {
4420
- warnOnce(nextValue.version === "7.1.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.1.0 may not work as expected."));
4420
+ warnOnce(nextValue.version === "7.2.0-beta.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.2.0-beta.0 may not work as expected."));
4421
4421
  }
4422
4422
  }
4423
4423
  else if (isMotionValue(prevValue)) {
@@ -7192,8 +7192,85 @@ function useForceUpdate() {
7192
7192
  return [deferredForceRender, forcedRenderCount];
7193
7193
  }
7194
7194
 
7195
+ /**
7196
+ * Measurement functionality has to be within a separate component
7197
+ * to leverage snapshot lifecycle.
7198
+ */
7199
+ var PopChildMeasure = /** @class */ (function (_super) {
7200
+ tslib.__extends(PopChildMeasure, _super);
7201
+ function PopChildMeasure() {
7202
+ return _super !== null && _super.apply(this, arguments) || this;
7203
+ }
7204
+ PopChildMeasure.prototype.getSnapshotBeforeUpdate = function (prevProps) {
7205
+ var element = this.props.childRef.current;
7206
+ if (element && prevProps.isPresent && !this.props.isPresent) {
7207
+ var position = getComputedStyle(element).position;
7208
+ var size = this.props.sizeRef.current;
7209
+ size.height = element.offsetHeight || 0;
7210
+ size.width = element.offsetWidth || 0;
7211
+ size.top = size.left = "auto";
7212
+ /**
7213
+ * If this element is position: relative and the parent has
7214
+ * padding, we need to explicitly set a top and/or left.
7215
+ */
7216
+ if (position === "relative" && element.offsetParent) {
7217
+ var _a = getComputedStyle(element.offsetParent), paddingTop = _a.paddingTop, paddingLeft = _a.paddingLeft;
7218
+ if (parseFloat(paddingTop)) {
7219
+ size.top = "".concat(element.offsetTop, "px");
7220
+ }
7221
+ if (parseFloat(paddingLeft)) {
7222
+ size.left = "".concat(element.offsetLeft, "px");
7223
+ }
7224
+ }
7225
+ }
7226
+ return null;
7227
+ };
7228
+ /**
7229
+ * Required with getSnapshotBeforeUpdate to stop React complaining.
7230
+ */
7231
+ PopChildMeasure.prototype.componentDidUpdate = function () { };
7232
+ PopChildMeasure.prototype.render = function () {
7233
+ return this.props.children;
7234
+ };
7235
+ return PopChildMeasure;
7236
+ }(React__namespace.Component));
7237
+ function PopChild(_a) {
7238
+ var children = _a.children, isPresent = _a.isPresent;
7239
+ var id = React.useId();
7240
+ var ref = React.useRef(null);
7241
+ var size = React.useRef({
7242
+ width: 0,
7243
+ height: 0,
7244
+ top: "auto",
7245
+ left: "auto",
7246
+ });
7247
+ /**
7248
+ * We create and inject a style block so we can apply this explicit
7249
+ * sizing in a non-destructive manner by just deleting the style block.
7250
+ *
7251
+ * We can't apply size via render as the measurement happens
7252
+ * in getSnapshotBeforeUpdate (post-render), likewise if we apply the
7253
+ * styles directly on the DOM node, we might be overwriting
7254
+ * styles set via the style prop.
7255
+ */
7256
+ React.useInsertionEffect(function () {
7257
+ var _a;
7258
+ var _b = size.current, width = _b.width, height = _b.height, top = _b.top, left = _b.left;
7259
+ if (isPresent || !ref.current || !width || !height)
7260
+ return;
7261
+ ref.current.dataset.motionPopId = id;
7262
+ var style = document.createElement("style");
7263
+ document.head.appendChild(style);
7264
+ (_a = style.sheet) === null || _a === void 0 ? void 0 : _a.insertRule("\n [data-motion-pop-id=\"".concat(id, "\"] {\n position: absolute !important;\n width: ").concat(width, "px !important;\n height: ").concat(height, "px !important;\n top: ").concat(top, " !important;\n left: ").concat(left, " !important;\n }\n "));
7265
+ return function () {
7266
+ document.head.removeChild(style);
7267
+ };
7268
+ }, [isPresent]);
7269
+ return (React__namespace.createElement(PopChildMeasure, { isPresent: isPresent, childRef: ref, sizeRef: size }, React__namespace.cloneElement(children, { ref: ref })));
7270
+ }
7271
+
7195
7272
  var PresenceChild = function (_a) {
7196
- var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
7273
+ var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout, popLayout = _a.popLayout;
7197
7274
  var presenceChildren = useConstant(newChildrenMap);
7198
7275
  var id = React.useId();
7199
7276
  var context = React.useMemo(function () { return ({
@@ -7241,6 +7318,9 @@ var PresenceChild = function (_a) {
7241
7318
  React__namespace.useEffect(function () {
7242
7319
  !isPresent && !presenceChildren.size && (onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete());
7243
7320
  }, [isPresent]);
7321
+ if (popLayout) {
7322
+ children = React__namespace.createElement(PopChild, { isPresent: isPresent }, children);
7323
+ }
7244
7324
  return (React__namespace.createElement(PresenceContext.Provider, { value: context }, children));
7245
7325
  };
7246
7326
  function newChildrenMap() {
@@ -7297,10 +7377,10 @@ function onlyElements(children) {
7297
7377
  * @public
7298
7378
  */
7299
7379
  var AnimatePresence = function (_a) {
7300
- var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c;
7380
+ var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c, _d = _a.popLayout, popLayout = _d === void 0 ? false : _d;
7301
7381
  // We want to force a re-render once all exiting animations have finished. We
7302
7382
  // either use a local forceRender function, or one from a parent context if it exists.
7303
- var _d = tslib.__read(useForceUpdate(), 1), forceRender = _d[0];
7383
+ var _e = tslib.__read(useForceUpdate(), 1), forceRender = _e[0];
7304
7384
  var forceRenderLayoutGroup = React.useContext(LayoutGroupContext).forceRender;
7305
7385
  if (forceRenderLayoutGroup)
7306
7386
  forceRender = forceRenderLayoutGroup;
@@ -7328,7 +7408,7 @@ var AnimatePresence = function (_a) {
7328
7408
  exiting.clear();
7329
7409
  });
7330
7410
  if (isInitialRender.current) {
7331
- 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)); })));
7411
+ 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, popLayout: popLayout }, child)); })));
7332
7412
  }
7333
7413
  // If this is a subsequent render, deal with entering and exiting children
7334
7414
  childrenToRender = tslib.__spreadArray([], tslib.__read(childrenToRender), false);
@@ -7374,13 +7454,13 @@ var AnimatePresence = function (_a) {
7374
7454
  onExitComplete && onExitComplete();
7375
7455
  }
7376
7456
  };
7377
- childrenToRender.splice(insertionIndex, 0, React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: false, onExitComplete: onExit, custom: custom, presenceAffectsLayout: presenceAffectsLayout }, child));
7457
+ childrenToRender.splice(insertionIndex, 0, React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: false, onExitComplete: onExit, custom: custom, presenceAffectsLayout: presenceAffectsLayout, popLayout: popLayout }, child));
7378
7458
  });
7379
7459
  // Add `MotionContext` even to children that don't need it to ensure we're rendering
7380
7460
  // the same tree between renders
7381
7461
  childrenToRender = childrenToRender.map(function (child) {
7382
7462
  var key = child.key;
7383
- return exiting.has(key) ? (child) : (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
7463
+ return exiting.has(key) ? (child) : (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout, popLayout: popLayout }, child));
7384
7464
  });
7385
7465
  if (env !== "production" &&
7386
7466
  exitBeforeEnter &&
@@ -0,0 +1,82 @@
1
+ import { __extends } from 'tslib';
2
+ import * as React from 'react';
3
+ import { useId, useRef, useInsertionEffect } from 'react';
4
+
5
+ /**
6
+ * Measurement functionality has to be within a separate component
7
+ * to leverage snapshot lifecycle.
8
+ */
9
+ var PopChildMeasure = /** @class */ (function (_super) {
10
+ __extends(PopChildMeasure, _super);
11
+ function PopChildMeasure() {
12
+ return _super !== null && _super.apply(this, arguments) || this;
13
+ }
14
+ PopChildMeasure.prototype.getSnapshotBeforeUpdate = function (prevProps) {
15
+ var element = this.props.childRef.current;
16
+ if (element && prevProps.isPresent && !this.props.isPresent) {
17
+ var position = getComputedStyle(element).position;
18
+ var size = this.props.sizeRef.current;
19
+ size.height = element.offsetHeight || 0;
20
+ size.width = element.offsetWidth || 0;
21
+ size.top = size.left = "auto";
22
+ /**
23
+ * If this element is position: relative and the parent has
24
+ * padding, we need to explicitly set a top and/or left.
25
+ */
26
+ if (position === "relative" && element.offsetParent) {
27
+ var _a = getComputedStyle(element.offsetParent), paddingTop = _a.paddingTop, paddingLeft = _a.paddingLeft;
28
+ if (parseFloat(paddingTop)) {
29
+ size.top = "".concat(element.offsetTop, "px");
30
+ }
31
+ if (parseFloat(paddingLeft)) {
32
+ size.left = "".concat(element.offsetLeft, "px");
33
+ }
34
+ }
35
+ }
36
+ return null;
37
+ };
38
+ /**
39
+ * Required with getSnapshotBeforeUpdate to stop React complaining.
40
+ */
41
+ PopChildMeasure.prototype.componentDidUpdate = function () { };
42
+ PopChildMeasure.prototype.render = function () {
43
+ return this.props.children;
44
+ };
45
+ return PopChildMeasure;
46
+ }(React.Component));
47
+ function PopChild(_a) {
48
+ var children = _a.children, isPresent = _a.isPresent;
49
+ var id = useId();
50
+ var ref = useRef(null);
51
+ var size = useRef({
52
+ width: 0,
53
+ height: 0,
54
+ top: "auto",
55
+ left: "auto",
56
+ });
57
+ /**
58
+ * We create and inject a style block so we can apply this explicit
59
+ * sizing in a non-destructive manner by just deleting the style block.
60
+ *
61
+ * We can't apply size via render as the measurement happens
62
+ * in getSnapshotBeforeUpdate (post-render), likewise if we apply the
63
+ * styles directly on the DOM node, we might be overwriting
64
+ * styles set via the style prop.
65
+ */
66
+ useInsertionEffect(function () {
67
+ var _a;
68
+ var _b = size.current, width = _b.width, height = _b.height, top = _b.top, left = _b.left;
69
+ if (isPresent || !ref.current || !width || !height)
70
+ return;
71
+ ref.current.dataset.motionPopId = id;
72
+ var style = document.createElement("style");
73
+ document.head.appendChild(style);
74
+ (_a = style.sheet) === null || _a === void 0 ? void 0 : _a.insertRule("\n [data-motion-pop-id=\"".concat(id, "\"] {\n position: absolute !important;\n width: ").concat(width, "px !important;\n height: ").concat(height, "px !important;\n top: ").concat(top, " !important;\n left: ").concat(left, " !important;\n }\n "));
75
+ return function () {
76
+ document.head.removeChild(style);
77
+ };
78
+ }, [isPresent]);
79
+ return (React.createElement(PopChildMeasure, { isPresent: isPresent, childRef: ref, sizeRef: size }, React.cloneElement(children, { ref: ref })));
80
+ }
81
+
82
+ export { PopChild };
@@ -3,9 +3,10 @@ import * as React from 'react';
3
3
  import { useId, useMemo } from 'react';
4
4
  import { PresenceContext } from '../../context/PresenceContext.mjs';
5
5
  import { useConstant } from '../../utils/use-constant.mjs';
6
+ import { PopChild } from './PopChild.mjs';
6
7
 
7
8
  var PresenceChild = function (_a) {
8
- var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
9
+ var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout, popLayout = _a.popLayout;
9
10
  var presenceChildren = useConstant(newChildrenMap);
10
11
  var id = useId();
11
12
  var context = useMemo(function () { return ({
@@ -53,6 +54,9 @@ var PresenceChild = function (_a) {
53
54
  React.useEffect(function () {
54
55
  !isPresent && !presenceChildren.size && (onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete());
55
56
  }, [isPresent]);
57
+ if (popLayout) {
58
+ children = React.createElement(PopChild, { isPresent: isPresent }, children);
59
+ }
56
60
  return (React.createElement(PresenceContext.Provider, { value: context }, children));
57
61
  };
58
62
  function newChildrenMap() {
@@ -59,10 +59,10 @@ function onlyElements(children) {
59
59
  * @public
60
60
  */
61
61
  var AnimatePresence = function (_a) {
62
- var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c;
62
+ var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c, _d = _a.popLayout, popLayout = _d === void 0 ? false : _d;
63
63
  // We want to force a re-render once all exiting animations have finished. We
64
64
  // either use a local forceRender function, or one from a parent context if it exists.
65
- var _d = __read(useForceUpdate(), 1), forceRender = _d[0];
65
+ var _e = __read(useForceUpdate(), 1), forceRender = _e[0];
66
66
  var forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
67
67
  if (forceRenderLayoutGroup)
68
68
  forceRender = forceRenderLayoutGroup;
@@ -90,7 +90,7 @@ var AnimatePresence = function (_a) {
90
90
  exiting.clear();
91
91
  });
92
92
  if (isInitialRender.current) {
93
- return (React.createElement(React.Fragment, null, childrenToRender.map(function (child) { return (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
93
+ return (React.createElement(React.Fragment, null, childrenToRender.map(function (child) { return (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout, popLayout: popLayout }, child)); })));
94
94
  }
95
95
  // If this is a subsequent render, deal with entering and exiting children
96
96
  childrenToRender = __spreadArray([], __read(childrenToRender), false);
@@ -136,13 +136,13 @@ var AnimatePresence = function (_a) {
136
136
  onExitComplete && onExitComplete();
137
137
  }
138
138
  };
139
- childrenToRender.splice(insertionIndex, 0, React.createElement(PresenceChild, { key: getChildKey(child), isPresent: false, onExitComplete: onExit, custom: custom, presenceAffectsLayout: presenceAffectsLayout }, child));
139
+ childrenToRender.splice(insertionIndex, 0, React.createElement(PresenceChild, { key: getChildKey(child), isPresent: false, onExitComplete: onExit, custom: custom, presenceAffectsLayout: presenceAffectsLayout, popLayout: popLayout }, child));
140
140
  });
141
141
  // Add `MotionContext` even to children that don't need it to ensure we're rendering
142
142
  // the same tree between renders
143
143
  childrenToRender = childrenToRender.map(function (child) {
144
144
  var key = child.key;
145
- return exiting.has(key) ? (child) : (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
145
+ return exiting.has(key) ? (child) : (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout, popLayout: popLayout }, child));
146
146
  });
147
147
  if (env !== "production" &&
148
148
  exitBeforeEnter &&
@@ -23,7 +23,7 @@ function updateMotionValuesFromProps(element, next, prev) {
23
23
  * and warn against mismatches.
24
24
  */
25
25
  if (process.env.NODE_ENV === "development") {
26
- warnOnce(nextValue.version === "7.1.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.1.0 may not work as expected."));
26
+ warnOnce(nextValue.version === "7.2.0-beta.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.2.0-beta.0 may not work as expected."));
27
27
  }
28
28
  }
29
29
  else if (isMotionValue(prevValue)) {
@@ -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 = "7.1.0";
28
+ this.version = "7.2.0-beta.0";
29
29
  /**
30
30
  * Duration, in milliseconds, since last updating frame.
31
31
  *
@@ -3670,7 +3670,7 @@
3670
3670
  * This will be replaced by the build step with the latest version number.
3671
3671
  * When MotionValues are provided to motion components, warn if versions are mixed.
3672
3672
  */
3673
- this.version = "7.1.0";
3673
+ this.version = "7.2.0-beta.0";
3674
3674
  /**
3675
3675
  * Duration, in milliseconds, since last updating frame.
3676
3676
  *
@@ -5650,7 +5650,7 @@
5650
5650
  * and warn against mismatches.
5651
5651
  */
5652
5652
  {
5653
- warnOnce(nextValue.version === "7.1.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.1.0 may not work as expected."));
5653
+ warnOnce(nextValue.version === "7.2.0-beta.0", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 7.2.0-beta.0 may not work as expected."));
5654
5654
  }
5655
5655
  }
5656
5656
  else if (isMotionValue(prevValue)) {
@@ -8425,8 +8425,85 @@
8425
8425
  return [deferredForceRender, forcedRenderCount];
8426
8426
  }
8427
8427
 
8428
+ /**
8429
+ * Measurement functionality has to be within a separate component
8430
+ * to leverage snapshot lifecycle.
8431
+ */
8432
+ var PopChildMeasure = /** @class */ (function (_super) {
8433
+ __extends(PopChildMeasure, _super);
8434
+ function PopChildMeasure() {
8435
+ return _super !== null && _super.apply(this, arguments) || this;
8436
+ }
8437
+ PopChildMeasure.prototype.getSnapshotBeforeUpdate = function (prevProps) {
8438
+ var element = this.props.childRef.current;
8439
+ if (element && prevProps.isPresent && !this.props.isPresent) {
8440
+ var position = getComputedStyle(element).position;
8441
+ var size = this.props.sizeRef.current;
8442
+ size.height = element.offsetHeight || 0;
8443
+ size.width = element.offsetWidth || 0;
8444
+ size.top = size.left = "auto";
8445
+ /**
8446
+ * If this element is position: relative and the parent has
8447
+ * padding, we need to explicitly set a top and/or left.
8448
+ */
8449
+ if (position === "relative" && element.offsetParent) {
8450
+ var _a = getComputedStyle(element.offsetParent), paddingTop = _a.paddingTop, paddingLeft = _a.paddingLeft;
8451
+ if (parseFloat(paddingTop)) {
8452
+ size.top = "".concat(element.offsetTop, "px");
8453
+ }
8454
+ if (parseFloat(paddingLeft)) {
8455
+ size.left = "".concat(element.offsetLeft, "px");
8456
+ }
8457
+ }
8458
+ }
8459
+ return null;
8460
+ };
8461
+ /**
8462
+ * Required with getSnapshotBeforeUpdate to stop React complaining.
8463
+ */
8464
+ PopChildMeasure.prototype.componentDidUpdate = function () { };
8465
+ PopChildMeasure.prototype.render = function () {
8466
+ return this.props.children;
8467
+ };
8468
+ return PopChildMeasure;
8469
+ }(React__namespace.Component));
8470
+ function PopChild(_a) {
8471
+ var children = _a.children, isPresent = _a.isPresent;
8472
+ var id = React.useId();
8473
+ var ref = React.useRef(null);
8474
+ var size = React.useRef({
8475
+ width: 0,
8476
+ height: 0,
8477
+ top: "auto",
8478
+ left: "auto",
8479
+ });
8480
+ /**
8481
+ * We create and inject a style block so we can apply this explicit
8482
+ * sizing in a non-destructive manner by just deleting the style block.
8483
+ *
8484
+ * We can't apply size via render as the measurement happens
8485
+ * in getSnapshotBeforeUpdate (post-render), likewise if we apply the
8486
+ * styles directly on the DOM node, we might be overwriting
8487
+ * styles set via the style prop.
8488
+ */
8489
+ React.useInsertionEffect(function () {
8490
+ var _a;
8491
+ var _b = size.current, width = _b.width, height = _b.height, top = _b.top, left = _b.left;
8492
+ if (isPresent || !ref.current || !width || !height)
8493
+ return;
8494
+ ref.current.dataset.motionPopId = id;
8495
+ var style = document.createElement("style");
8496
+ document.head.appendChild(style);
8497
+ (_a = style.sheet) === null || _a === void 0 ? void 0 : _a.insertRule("\n [data-motion-pop-id=\"".concat(id, "\"] {\n position: absolute !important;\n width: ").concat(width, "px !important;\n height: ").concat(height, "px !important;\n top: ").concat(top, " !important;\n left: ").concat(left, " !important;\n }\n "));
8498
+ return function () {
8499
+ document.head.removeChild(style);
8500
+ };
8501
+ }, [isPresent]);
8502
+ return (React__namespace.createElement(PopChildMeasure, { isPresent: isPresent, childRef: ref, sizeRef: size }, React__namespace.cloneElement(children, { ref: ref })));
8503
+ }
8504
+
8428
8505
  var PresenceChild = function (_a) {
8429
- var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
8506
+ var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout, popLayout = _a.popLayout;
8430
8507
  var presenceChildren = useConstant(newChildrenMap);
8431
8508
  var id = React.useId();
8432
8509
  var context = React.useMemo(function () { return ({
@@ -8474,6 +8551,9 @@
8474
8551
  React__namespace.useEffect(function () {
8475
8552
  !isPresent && !presenceChildren.size && (onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete());
8476
8553
  }, [isPresent]);
8554
+ if (popLayout) {
8555
+ children = React__namespace.createElement(PopChild, { isPresent: isPresent }, children);
8556
+ }
8477
8557
  return (React__namespace.createElement(PresenceContext.Provider, { value: context }, children));
8478
8558
  };
8479
8559
  function newChildrenMap() {
@@ -8530,10 +8610,10 @@
8530
8610
  * @public
8531
8611
  */
8532
8612
  var AnimatePresence = function (_a) {
8533
- var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c;
8613
+ var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c, _d = _a.popLayout, popLayout = _d === void 0 ? false : _d;
8534
8614
  // We want to force a re-render once all exiting animations have finished. We
8535
8615
  // either use a local forceRender function, or one from a parent context if it exists.
8536
- var _d = __read(useForceUpdate(), 1), forceRender = _d[0];
8616
+ var _e = __read(useForceUpdate(), 1), forceRender = _e[0];
8537
8617
  var forceRenderLayoutGroup = React.useContext(LayoutGroupContext).forceRender;
8538
8618
  if (forceRenderLayoutGroup)
8539
8619
  forceRender = forceRenderLayoutGroup;
@@ -8561,7 +8641,7 @@
8561
8641
  exiting.clear();
8562
8642
  });
8563
8643
  if (isInitialRender.current) {
8564
- 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)); })));
8644
+ 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, popLayout: popLayout }, child)); })));
8565
8645
  }
8566
8646
  // If this is a subsequent render, deal with entering and exiting children
8567
8647
  childrenToRender = __spreadArray([], __read(childrenToRender), false);
@@ -8607,13 +8687,13 @@
8607
8687
  onExitComplete && onExitComplete();
8608
8688
  }
8609
8689
  };
8610
- childrenToRender.splice(insertionIndex, 0, React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: false, onExitComplete: onExit, custom: custom, presenceAffectsLayout: presenceAffectsLayout }, child));
8690
+ childrenToRender.splice(insertionIndex, 0, React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: false, onExitComplete: onExit, custom: custom, presenceAffectsLayout: presenceAffectsLayout, popLayout: popLayout }, child));
8611
8691
  });
8612
8692
  // Add `MotionContext` even to children that don't need it to ensure we're rendering
8613
8693
  // the same tree between renders
8614
8694
  childrenToRender = childrenToRender.map(function (child) {
8615
8695
  var key = child.key;
8616
- return exiting.has(key) ? (child) : (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
8696
+ return exiting.has(key) ? (child) : (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout, popLayout: popLayout }, child));
8617
8697
  });
8618
8698
  if (env !== "production" &&
8619
8699
  exitBeforeEnter &&