framer-motion 7.2.0 → 7.3.1

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.
Files changed (96) hide show
  1. package/dist/cjs/index.js +762 -627
  2. package/dist/es/animation/use-animated-state.mjs +3 -5
  3. package/dist/es/animation/utils/default-transitions.mjs +1 -1
  4. package/dist/es/animation/utils/transitions.mjs +28 -26
  5. package/dist/es/components/AnimatePresence/PopChild.mjs +3 -2
  6. package/dist/es/components/AnimatePresence/PresenceChild.mjs +5 -2
  7. package/dist/es/components/AnimatePresence/use-presence.mjs +1 -1
  8. package/dist/es/components/LayoutGroup/index.mjs +4 -5
  9. package/dist/es/components/LazyMotion/index.mjs +3 -5
  10. package/dist/es/components/MotionConfig/index.mjs +2 -4
  11. package/dist/es/components/Reorder/Group.mjs +2 -4
  12. package/dist/es/components/Reorder/Item.mjs +6 -8
  13. package/dist/es/context/MotionContext/utils.mjs +3 -2
  14. package/dist/es/gestures/PanSession.mjs +2 -2
  15. package/dist/es/gestures/drag/VisualElementDragControls.mjs +16 -4
  16. package/dist/es/gestures/use-focus-gesture.mjs +3 -4
  17. package/dist/es/gestures/use-hover-gesture.mjs +4 -3
  18. package/dist/es/gestures/use-tap-gesture.mjs +9 -10
  19. package/dist/es/index.mjs +2 -1
  20. package/dist/es/motion/features/animations.mjs +8 -3
  21. package/dist/es/motion/features/definitions.mjs +1 -13
  22. package/dist/es/motion/features/layout/MeasureLayout.mjs +12 -6
  23. package/dist/es/motion/features/load-features.mjs +14 -0
  24. package/dist/es/motion/features/viewport/observers.mjs +4 -7
  25. package/dist/es/motion/features/viewport/use-viewport.mjs +8 -6
  26. package/dist/es/motion/index.mjs +23 -23
  27. package/dist/es/motion/utils/VisualElementHandler.mjs +2 -5
  28. package/dist/es/motion/utils/is-forced-motion-value.mjs +3 -3
  29. package/dist/es/motion/utils/use-motion-ref.mjs +1 -2
  30. package/dist/es/motion/utils/use-visual-element.mjs +14 -12
  31. package/dist/es/motion/utils/use-visual-state.mjs +19 -16
  32. package/dist/es/motion/utils/valid-prop.mjs +22 -17
  33. package/dist/es/projection/geometry/utils.mjs +10 -1
  34. package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
  35. package/dist/es/projection/node/create-projection-node.mjs +62 -20
  36. package/dist/es/projection/use-instant-layout-transition.mjs +2 -2
  37. package/dist/es/render/dom/features-animation.mjs +5 -1
  38. package/dist/es/render/dom/features-max.mjs +6 -1
  39. package/dist/es/render/dom/motion.mjs +6 -1
  40. package/dist/es/render/dom/use-render.mjs +5 -1
  41. package/dist/es/render/dom/utils/camel-to-dash.mjs +1 -3
  42. package/dist/es/render/dom/utils/create-config.mjs +7 -2
  43. package/dist/es/render/dom/utils/css-variables-conversion.mjs +5 -7
  44. package/dist/es/render/dom/utils/unit-conversion.mjs +4 -4
  45. package/dist/es/render/dom/value-types/defaults.mjs +15 -3
  46. package/dist/es/render/dom/value-types/type-int.mjs +4 -1
  47. package/dist/es/render/html/config-motion.mjs +1 -1
  48. package/dist/es/render/html/use-props.mjs +5 -9
  49. package/dist/es/render/html/utils/build-styles.mjs +17 -15
  50. package/dist/es/render/html/utils/build-transform.mjs +8 -18
  51. package/dist/es/render/html/utils/transform.mjs +21 -30
  52. package/dist/es/render/html/visual-element.mjs +8 -9
  53. package/dist/es/render/index.mjs +118 -40
  54. package/dist/es/render/svg/use-props.mjs +5 -2
  55. package/dist/es/render/svg/utils/build-attrs.mjs +3 -5
  56. package/dist/es/render/svg/utils/create-render-state.mjs +4 -1
  57. package/dist/es/render/svg/visual-element.mjs +8 -4
  58. package/dist/es/render/utils/animation-state.mjs +12 -9
  59. package/dist/es/render/utils/animation.mjs +14 -8
  60. package/dist/es/render/utils/is-controlling-variants.mjs +22 -0
  61. package/dist/es/render/utils/is-variant-label.mjs +8 -0
  62. package/dist/es/render/utils/motion-values.mjs +3 -3
  63. package/dist/es/render/utils/resolve-dynamic-variants.mjs +24 -0
  64. package/dist/es/render/utils/resolve-variants.mjs +26 -0
  65. package/dist/es/render/utils/setters.mjs +12 -9
  66. package/dist/es/utils/reduced-motion/index.mjs +19 -0
  67. package/dist/es/utils/reduced-motion/state.mjs +5 -0
  68. package/dist/es/utils/reduced-motion/use-reduced-motion-config.mjs +19 -0
  69. package/dist/es/utils/reduced-motion/use-reduced-motion.mjs +43 -0
  70. package/dist/es/utils/transform.mjs +4 -1
  71. package/dist/es/utils/use-in-view.mjs +1 -2
  72. package/dist/es/value/index.mjs +1 -1
  73. package/dist/es/value/use-scroll.mjs +6 -4
  74. package/dist/es/value/use-spring.mjs +7 -1
  75. package/dist/es/value/use-will-change/index.mjs +4 -4
  76. package/dist/es/value/utils/is-motion-value.mjs +1 -3
  77. package/dist/framer-motion.dev.js +806 -670
  78. package/dist/framer-motion.js +1 -1
  79. package/dist/index.d.ts +60 -54
  80. package/dist/projection.dev.js +402 -213
  81. package/dist/size-rollup-dom-animation-assets.js +1 -0
  82. package/dist/size-rollup-dom-animation-m.js +1 -0
  83. package/dist/size-rollup-dom-animation.js +1 -1
  84. package/dist/size-rollup-dom-max-assets.js +1 -0
  85. package/dist/size-rollup-dom-max.js +1 -1
  86. package/dist/size-rollup-m.js +1 -1
  87. package/dist/size-rollup-motion.js +1 -0
  88. package/dist/size-webpack-dom-animation.js +1 -1
  89. package/dist/size-webpack-dom-max.js +1 -1
  90. package/dist/size-webpack-m.js +1 -1
  91. package/dist/three-entry.d.ts +41 -22
  92. package/package.json +12 -8
  93. package/dist/es/motion/features/use-features.mjs +0 -40
  94. package/dist/es/motion/features/use-projection.mjs +0 -33
  95. package/dist/es/render/utils/variants.mjs +0 -73
  96. package/dist/es/utils/use-reduced-motion.mjs +0 -73
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Projection = {}));
5
- })(this, (function (exports) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Projection = {}, global.react));
5
+ })(this, (function (exports, react) { 'use strict';
6
6
 
7
7
  const defaultTimestep = (1 / 60) * 1000;
8
8
  const getCurrentTime = typeof performance !== "undefined"
@@ -1242,7 +1242,7 @@
1242
1242
  * This will be replaced by the build step with the latest version number.
1243
1243
  * When MotionValues are provided to motion components, warn if versions are mixed.
1244
1244
  */
1245
- this.version = "7.2.0";
1245
+ this.version = "7.3.1";
1246
1246
  /**
1247
1247
  * Duration, in milliseconds, since last updating frame.
1248
1248
  *
@@ -1520,9 +1520,7 @@
1520
1520
  return new MotionValue(init);
1521
1521
  }
1522
1522
 
1523
- const isMotionValue = (value) => {
1524
- return Boolean(value !== null && typeof value === "object" && value.getVelocity);
1525
- };
1523
+ const isMotionValue = (value) => value === undefined ? false : !!value.getVelocity;
1526
1524
 
1527
1525
  /**
1528
1526
  * Converts seconds to milliseconds
@@ -1644,10 +1642,13 @@
1644
1642
  transitionFactory =
1645
1643
  defaultTransitions[valueKey] || defaultTransitions.default;
1646
1644
  }
1647
- return Object.assign({ to }, transitionFactory(to));
1645
+ return { to, ...transitionFactory(to) };
1648
1646
  };
1649
1647
 
1650
- const int = Object.assign(Object.assign({}, number), { transform: Math.round });
1648
+ const int = {
1649
+ ...number,
1650
+ transform: Math.round,
1651
+ };
1651
1652
 
1652
1653
  const numberValueTypes = {
1653
1654
  // Border props
@@ -1719,11 +1720,23 @@
1719
1720
  /**
1720
1721
  * A map of default value types for common values
1721
1722
  */
1722
- const defaultValueTypes = Object.assign(Object.assign({}, numberValueTypes), {
1723
+ const defaultValueTypes = {
1724
+ ...numberValueTypes,
1723
1725
  // Color props
1724
- color, backgroundColor: color, outlineColor: color, fill: color, stroke: color,
1726
+ color,
1727
+ backgroundColor: color,
1728
+ outlineColor: color,
1729
+ fill: color,
1730
+ stroke: color,
1725
1731
  // Border props
1726
- borderColor: color, borderTopColor: color, borderRightColor: color, borderBottomColor: color, borderLeftColor: color, filter, WebkitFilter: filter });
1732
+ borderColor: color,
1733
+ borderTopColor: color,
1734
+ borderRightColor: color,
1735
+ borderBottomColor: color,
1736
+ borderLeftColor: color,
1737
+ filter,
1738
+ WebkitFilter: filter,
1739
+ };
1727
1740
  /**
1728
1741
  * Gets the default ValueType for the provided value key
1729
1742
  */
@@ -1755,17 +1768,15 @@
1755
1768
  * This filters out orchestration options and returns true
1756
1769
  * if any options are left.
1757
1770
  */
1758
- function isTransitionDefined(_a) {
1759
- var transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
1771
+ function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
1760
1772
  return !!Object.keys(transition).length;
1761
1773
  }
1762
1774
  let legacyRepeatWarning = false;
1763
1775
  /**
1764
1776
  * Convert Framer Motion's Transition type into Popmotion-compatible options.
1765
1777
  */
1766
- function convertTransitionToAnimationOptions(_a) {
1767
- var { ease, times, yoyo, flip, loop } = _a, transition = __rest(_a, ["ease", "times", "yoyo", "flip", "loop"]);
1768
- const options = Object.assign({}, transition);
1778
+ function convertTransitionToAnimationOptions({ ease, times, yoyo, flip, loop, ...transition }) {
1779
+ const options = { ...transition };
1769
1780
  if (times)
1770
1781
  options["offset"] = times;
1771
1782
  /**
@@ -1830,26 +1841,30 @@
1830
1841
  return options;
1831
1842
  }
1832
1843
  function getPopmotionAnimationOptions(transition, options, key) {
1833
- var _a;
1834
- if (Array.isArray(options.to)) {
1835
- (_a = transition.duration) !== null && _a !== void 0 ? _a : (transition.duration = 0.8);
1844
+ if (Array.isArray(options.to) && transition.duration === undefined) {
1845
+ transition.duration = 0.8;
1836
1846
  }
1837
1847
  hydrateKeyframes(options);
1838
1848
  /**
1839
1849
  * Get a default transition if none is determined to be defined.
1840
1850
  */
1841
1851
  if (!isTransitionDefined(transition)) {
1842
- transition = Object.assign(Object.assign({}, transition), getDefaultTransition(key, options.to));
1852
+ transition = {
1853
+ ...transition,
1854
+ ...getDefaultTransition(key, options.to),
1855
+ };
1843
1856
  }
1844
- return Object.assign(Object.assign({}, options), convertTransitionToAnimationOptions(transition));
1857
+ return {
1858
+ ...options,
1859
+ ...convertTransitionToAnimationOptions(transition),
1860
+ };
1845
1861
  }
1846
1862
  /**
1847
1863
  *
1848
1864
  */
1849
1865
  function getAnimation(key, value, target, transition, onComplete) {
1850
- var _a;
1851
- const valueTransition = getValueTransition(transition, key);
1852
- let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
1866
+ const valueTransition = getValueTransition(transition, key) || {};
1867
+ let origin = valueTransition.from !== undefined ? valueTransition.from : value.get();
1853
1868
  const isTargetAnimatable = isAnimatable(key, target);
1854
1869
  if (origin === "none" && isTargetAnimatable && typeof target === "string") {
1855
1870
  /**
@@ -1878,24 +1893,25 @@
1878
1893
  };
1879
1894
  return valueTransition.type === "inertia" ||
1880
1895
  valueTransition.type === "decay"
1881
- ? inertia(Object.assign(Object.assign({}, options), valueTransition))
1882
- : animate$1(Object.assign(Object.assign({}, getPopmotionAnimationOptions(valueTransition, options, key)), { onUpdate: (v) => {
1883
- var _a;
1896
+ ? inertia({ ...options, ...valueTransition })
1897
+ : animate$1({
1898
+ ...getPopmotionAnimationOptions(valueTransition, options, key),
1899
+ onUpdate: (v) => {
1884
1900
  options.onUpdate(v);
1885
- (_a = valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, v);
1886
- }, onComplete: () => {
1887
- var _a;
1901
+ valueTransition.onUpdate && valueTransition.onUpdate(v);
1902
+ },
1903
+ onComplete: () => {
1888
1904
  options.onComplete();
1889
- (_a = valueTransition.onComplete) === null || _a === void 0 ? void 0 : _a.call(valueTransition);
1890
- } }));
1905
+ valueTransition.onComplete && valueTransition.onComplete();
1906
+ },
1907
+ });
1891
1908
  }
1892
1909
  function set() {
1893
- var _a, _b;
1894
1910
  const finalTarget = resolveFinalValueInKeyframes(target);
1895
1911
  value.set(finalTarget);
1896
1912
  onComplete();
1897
- (_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, finalTarget);
1898
- (_b = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onComplete) === null || _b === void 0 ? void 0 : _b.call(valueTransition);
1913
+ valueTransition.onUpdate && valueTransition.onUpdate(finalTarget);
1914
+ valueTransition.onComplete && valueTransition.onComplete();
1899
1915
  return { stop: () => { } };
1900
1916
  }
1901
1917
  return !isOriginAnimatable ||
@@ -1940,7 +1956,7 @@
1940
1956
  }
1941
1957
  return () => {
1942
1958
  clearTimeout(delayTimer);
1943
- controls === null || controls === void 0 ? void 0 : controls.stop();
1959
+ controls && controls.stop();
1944
1960
  };
1945
1961
  });
1946
1962
  }
@@ -2320,6 +2336,12 @@
2320
2336
  a.y.min === b.y.min &&
2321
2337
  a.y.max === b.y.max);
2322
2338
  }
2339
+ function aspectRatio(box) {
2340
+ return calcLength(box.x) / calcLength(box.y);
2341
+ }
2342
+ function isCloseTo(a, b, max = 0.01) {
2343
+ return distance(a, b) <= max;
2344
+ }
2323
2345
 
2324
2346
  class NodeStack {
2325
2347
  constructor() {
@@ -2473,42 +2495,6 @@
2473
2495
  return [callback("x"), callback("y")];
2474
2496
  }
2475
2497
 
2476
- /**
2477
- * A list of all transformable axes. We'll use this list to generated a version
2478
- * of each axes for each transform.
2479
- */
2480
- const transformAxes = ["", "X", "Y", "Z"];
2481
- /**
2482
- * An ordered array of each transformable value. By default, transform values
2483
- * will be sorted to this order.
2484
- */
2485
- const order = ["translate", "scale", "rotate", "skew"];
2486
- /**
2487
- * Generate a list of every possible transform key.
2488
- */
2489
- const transformProps = ["transformPerspective", "x", "y", "z"];
2490
- order.forEach((operationKey) => transformAxes.forEach((axesKey) => transformProps.push(operationKey + axesKey)));
2491
- /**
2492
- * A function to use with Array.sort to sort transform keys by their default order.
2493
- */
2494
- function sortTransformProps(a, b) {
2495
- return transformProps.indexOf(a) - transformProps.indexOf(b);
2496
- }
2497
- /**
2498
- * A quick lookup for transform props.
2499
- */
2500
- const transformPropSet = new Set(transformProps);
2501
- function isTransformProp(key) {
2502
- return transformPropSet.has(key);
2503
- }
2504
- /**
2505
- * A quick lookup for transform origin props
2506
- */
2507
- const transformOriginProps = new Set(["originX", "originY", "originZ"]);
2508
- function isTransformOriginProp(key) {
2509
- return transformOriginProps.has(key);
2510
- }
2511
-
2512
2498
  const compareByDepth = (a, b) => a.depth - b.depth;
2513
2499
 
2514
2500
  class FlatTree {
@@ -2561,6 +2547,7 @@
2561
2547
  hasEverUpdated: false,
2562
2548
  };
2563
2549
 
2550
+ const transformAxes = ["", "X", "Y", "Z"];
2564
2551
  /**
2565
2552
  * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
2566
2553
  * which has a noticeable difference in spring animations
@@ -2752,7 +2739,11 @@
2752
2739
  this.resumingFrom.resumingFrom = undefined;
2753
2740
  }
2754
2741
  this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
2755
- const animationOptions = Object.assign(Object.assign({}, getValueTransition(layoutTransition, "layout")), { onPlay: onLayoutAnimationStart, onComplete: onLayoutAnimationComplete });
2742
+ const animationOptions = {
2743
+ ...getValueTransition(layoutTransition, "layout"),
2744
+ onPlay: onLayoutAnimationStart,
2745
+ onComplete: onLayoutAnimationComplete,
2746
+ };
2756
2747
  if (visualElement.shouldReduceMotion) {
2757
2748
  animationOptions.delay = 0;
2758
2749
  animationOptions.type = false;
@@ -3075,8 +3066,11 @@
3075
3066
  this.root.scheduleUpdateProjection();
3076
3067
  }
3077
3068
  setOptions(options) {
3078
- var _a;
3079
- this.options = Object.assign(Object.assign(Object.assign({}, this.options), options), { crossfade: (_a = options.crossfade) !== null && _a !== void 0 ? _a : true });
3069
+ this.options = {
3070
+ ...this.options,
3071
+ ...options,
3072
+ crossfade: options.crossfade !== undefined ? options.crossfade : true,
3073
+ };
3080
3074
  }
3081
3075
  clearMeasurements() {
3082
3076
  this.scroll = undefined;
@@ -3258,7 +3252,7 @@
3258
3252
  var _a;
3259
3253
  const snapshot = this.snapshot;
3260
3254
  const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
3261
- const mixedValues = Object.assign({}, this.latestValues);
3255
+ const mixedValues = { ...this.latestValues };
3262
3256
  const targetDelta = createDelta();
3263
3257
  this.relativeTarget = this.relativeTargetOrigin = undefined;
3264
3258
  this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
@@ -3311,15 +3305,19 @@
3311
3305
  */
3312
3306
  this.pendingAnimation = sync.update(() => {
3313
3307
  globalProjectionState.hasAnimatedSinceResize = true;
3314
- this.currentAnimation = animate(0, animationTarget, Object.assign(Object.assign({}, options), { onUpdate: (latest) => {
3308
+ this.currentAnimation = animate(0, animationTarget, {
3309
+ ...options,
3310
+ onUpdate: (latest) => {
3315
3311
  var _a;
3316
3312
  this.mixTargetDelta(latest);
3317
3313
  (_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
3318
- }, onComplete: () => {
3314
+ },
3315
+ onComplete: () => {
3319
3316
  var _a;
3320
3317
  (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
3321
3318
  this.completeAnimation();
3322
- } }));
3319
+ },
3320
+ });
3323
3321
  if (this.resumingFrom) {
3324
3322
  this.resumingFrom.currentAnimation = this.currentAnimation;
3325
3323
  }
@@ -3348,9 +3346,27 @@
3348
3346
  this.completeAnimation();
3349
3347
  }
3350
3348
  applyTransformsToTarget() {
3351
- const { targetWithTransforms, target, layout, latestValues } = this.getLead();
3349
+ const lead = this.getLead();
3350
+ let { targetWithTransforms, target, layout, latestValues } = lead;
3352
3351
  if (!targetWithTransforms || !target || !layout)
3353
3352
  return;
3353
+ /**
3354
+ * If we're only animating position, and this element isn't the lead element,
3355
+ * then instead of projecting into the lead box we instead want to calculate
3356
+ * a new target that aligns the two boxes but maintains the layout shape.
3357
+ */
3358
+ if (this !== lead &&
3359
+ this.layout &&
3360
+ layout &&
3361
+ shouldAnimatePositionOnly(this.options.animationType, this.layout.actual, layout.actual)) {
3362
+ target = this.target || createBox();
3363
+ const xLength = calcLength(this.layout.actual.x);
3364
+ target.x.min = lead.target.x.min;
3365
+ target.x.max = target.x.min + xLength;
3366
+ const yLength = calcLength(this.layout.actual.y);
3367
+ target.y.min = lead.target.y.min;
3368
+ target.y.max = target.y.min + yLength;
3369
+ }
3354
3370
  copyBoxInto(targetWithTransforms, target);
3355
3371
  /**
3356
3372
  * Apply the latest user-set transforms to the targetBox to produce the targetBoxFinal.
@@ -3454,7 +3470,7 @@
3454
3470
  visualElement.scheduleRender();
3455
3471
  }
3456
3472
  getProjectionStyles(styleProp = {}) {
3457
- var _a, _b, _c, _d, _e, _f;
3473
+ var _a, _b, _c;
3458
3474
  // TODO: Return lifecycle-persistent object
3459
3475
  const styles = {};
3460
3476
  if (!this.instance || this.isSVG)
@@ -3480,7 +3496,10 @@
3480
3496
  if (!this.projectionDelta || !this.layout || !lead.target) {
3481
3497
  const emptyStyles = {};
3482
3498
  if (this.options.layoutId) {
3483
- emptyStyles.opacity = (_b = this.latestValues.opacity) !== null && _b !== void 0 ? _b : 1;
3499
+ emptyStyles.opacity =
3500
+ this.latestValues.opacity !== undefined
3501
+ ? this.latestValues.opacity
3502
+ : 1;
3484
3503
  emptyStyles.pointerEvents =
3485
3504
  resolveMotionValue(styleProp.pointerEvents) || "";
3486
3505
  }
@@ -3507,7 +3526,7 @@
3507
3526
  */
3508
3527
  styles.opacity =
3509
3528
  lead === this
3510
- ? (_d = (_c = valuesToRender.opacity) !== null && _c !== void 0 ? _c : this.latestValues.opacity) !== null && _d !== void 0 ? _d : 1
3529
+ ? (_c = (_b = valuesToRender.opacity) !== null && _b !== void 0 ? _b : this.latestValues.opacity) !== null && _c !== void 0 ? _c : 1
3511
3530
  : this.preserveOpacity
3512
3531
  ? this.latestValues.opacity
3513
3532
  : valuesToRender.opacityExit;
@@ -3519,8 +3538,12 @@
3519
3538
  */
3520
3539
  styles.opacity =
3521
3540
  lead === this
3522
- ? (_e = valuesToRender.opacity) !== null && _e !== void 0 ? _e : ""
3523
- : (_f = valuesToRender.opacityExit) !== null && _f !== void 0 ? _f : 0;
3541
+ ? valuesToRender.opacity !== undefined
3542
+ ? valuesToRender.opacity
3543
+ : ""
3544
+ : valuesToRender.opacityExit !== undefined
3545
+ ? valuesToRender.opacityExit
3546
+ : 0;
3524
3547
  }
3525
3548
  /**
3526
3549
  * Apply scale correction
@@ -3568,16 +3591,17 @@
3568
3591
  node.updateLayout();
3569
3592
  }
3570
3593
  function notifyLayoutUpdate(node) {
3571
- var _a, _b, _c, _d;
3572
- const snapshot = (_b = (_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) !== null && _b !== void 0 ? _b : node.snapshot;
3594
+ var _a, _b, _c;
3595
+ const snapshot = ((_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) || node.snapshot;
3573
3596
  if (node.isLead() &&
3574
3597
  node.layout &&
3575
3598
  snapshot &&
3576
3599
  node.hasListeners("didUpdate")) {
3577
3600
  const { actual: layout, measured: measuredLayout } = node.layout;
3601
+ const { animationType } = node.options;
3578
3602
  // TODO Maybe we want to also resize the layout snapshot so we don't trigger
3579
3603
  // animations for instance if layout="size" and an element has only changed position
3580
- if (node.options.animationType === "size") {
3604
+ if (animationType === "size") {
3581
3605
  eachAxis((axis) => {
3582
3606
  const axisSnapshot = snapshot.isShared
3583
3607
  ? snapshot.measured[axis]
@@ -3587,7 +3611,7 @@
3587
3611
  axisSnapshot.max = axisSnapshot.min + length;
3588
3612
  });
3589
3613
  }
3590
- else if (node.options.animationType === "position") {
3614
+ else if (shouldAnimatePositionOnly(animationType, snapshot.layout, layout)) {
3591
3615
  eachAxis((axis) => {
3592
3616
  const axisSnapshot = snapshot.isShared
3593
3617
  ? snapshot.measured[axis]
@@ -3636,7 +3660,7 @@
3636
3660
  });
3637
3661
  }
3638
3662
  else if (node.isLead()) {
3639
- (_d = (_c = node.options).onExitComplete) === null || _d === void 0 ? void 0 : _d.call(_c);
3663
+ (_c = (_b = node.options).onExitComplete) === null || _c === void 0 ? void 0 : _c.call(_b);
3640
3664
  }
3641
3665
  /**
3642
3666
  * Clearing transition
@@ -3720,6 +3744,11 @@
3720
3744
  roundAxis(box.x);
3721
3745
  roundAxis(box.y);
3722
3746
  }
3747
+ function shouldAnimatePositionOnly(animationType, snapshot, layout) {
3748
+ return (animationType === "position" ||
3749
+ (animationType === "preserve-aspect" &&
3750
+ !isCloseTo(aspectRatio(snapshot), aspectRatio(layout))));
3751
+ }
3723
3752
 
3724
3753
  function addDomEvent(target, eventName, handler, options = { passive: true }) {
3725
3754
  target.addEventListener(eventName, handler, options);
@@ -3753,7 +3782,7 @@
3753
3782
  return rootProjectionNode.current;
3754
3783
  },
3755
3784
  resetTransform: (instance, value) => {
3756
- instance.style.transform = value !== null && value !== void 0 ? value : "none";
3785
+ instance.style.transform = value !== undefined ? value : "none";
3757
3786
  },
3758
3787
  checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
3759
3788
  });
@@ -3779,12 +3808,43 @@
3779
3808
  };
3780
3809
  }
3781
3810
 
3811
+ /**
3812
+ * Generate a list of every possible transform key.
3813
+ */
3814
+ const transformPropOrder = [
3815
+ "transformPerspective",
3816
+ "x",
3817
+ "y",
3818
+ "z",
3819
+ "translateX",
3820
+ "translateY",
3821
+ "translateZ",
3822
+ "scale",
3823
+ "scaleX",
3824
+ "scaleY",
3825
+ "rotate",
3826
+ "rotateX",
3827
+ "rotateY",
3828
+ "rotateZ",
3829
+ "skew",
3830
+ "skewX",
3831
+ "skewY",
3832
+ ];
3833
+ /**
3834
+ * A quick lookup for transform props.
3835
+ */
3836
+ const transformProps = new Set(transformPropOrder);
3837
+
3782
3838
  const translateAlias = {
3783
3839
  x: "translateX",
3784
3840
  y: "translateY",
3785
3841
  z: "translateZ",
3786
3842
  transformPerspective: "perspective",
3787
3843
  };
3844
+ /**
3845
+ * A function to use with Array.sort to sort transform keys by their default order.
3846
+ */
3847
+ const sortTransformProps = (a, b) => transformPropOrder.indexOf(a) - transformPropOrder.indexOf(b);
3788
3848
  /**
3789
3849
  * Build a CSS transform style from individual x/y/scale etc properties.
3790
3850
  *
@@ -3796,18 +3856,11 @@
3796
3856
  let transformString = "";
3797
3857
  // Transform keys into their default order - this will determine the output order.
3798
3858
  transformKeys.sort(sortTransformProps);
3799
- // Track whether the defined transform has a defined z so we don't add a
3800
- // second to enable hardware acceleration
3801
- let transformHasZ = false;
3802
3859
  // Loop over each transform and build them into transformString
3803
- const numTransformKeys = transformKeys.length;
3804
- for (let i = 0; i < numTransformKeys; i++) {
3805
- const key = transformKeys[i];
3860
+ for (const key of transformKeys) {
3806
3861
  transformString += `${translateAlias[key] || key}(${transform[key]}) `;
3807
- if (key === "z")
3808
- transformHasZ = true;
3809
3862
  }
3810
- if (!transformHasZ && enableHardwareAcceleration) {
3863
+ if (enableHardwareAcceleration && !transform.z) {
3811
3864
  transformString += "translateZ(0)";
3812
3865
  }
3813
3866
  transformString = transformString.trim();
@@ -3821,13 +3874,6 @@
3821
3874
  }
3822
3875
  return transformString;
3823
3876
  }
3824
- /**
3825
- * Build a transformOrigin style. Uses the same defaults as the browser for
3826
- * undefined origins.
3827
- */
3828
- function buildTransformOrigin({ originX = "50%", originY = "50%", originZ = 0, }) {
3829
- return `${originX} ${originY} ${originZ}`;
3830
- }
3831
3877
 
3832
3878
  function pixelsToPercent(pixels, axis) {
3833
3879
  if (axis.max === axis.min)
@@ -3912,16 +3958,14 @@
3912
3958
  *
3913
3959
  * @internal
3914
3960
  */
3915
- function resolveCSSVariables(visualElement, _a, transitionEnd) {
3916
- var _b;
3917
- var target = __rest(_a, []);
3961
+ function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
3918
3962
  const element = visualElement.getInstance();
3919
3963
  if (!(element instanceof Element))
3920
3964
  return { target, transitionEnd };
3921
3965
  // If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
3922
3966
  // only if they change but I think this reads clearer and this isn't a performance-critical path.
3923
3967
  if (transitionEnd) {
3924
- transitionEnd = Object.assign({}, transitionEnd);
3968
+ transitionEnd = { ...transitionEnd };
3925
3969
  }
3926
3970
  // Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
3927
3971
  visualElement.forEachValue((value) => {
@@ -3946,8 +3990,9 @@
3946
3990
  // If the user hasn't already set this key on `transitionEnd`, set it to the unresolved
3947
3991
  // CSS variable. This will ensure that after the animation the component will reflect
3948
3992
  // changes in the value of the CSS variable.
3949
- if (transitionEnd)
3950
- (_b = transitionEnd[key]) !== null && _b !== void 0 ? _b : (transitionEnd[key] = current);
3993
+ if (transitionEnd && transitionEnd[key] === undefined) {
3994
+ transitionEnd[key] = current;
3995
+ }
3951
3996
  }
3952
3997
  return { target, transitionEnd };
3953
3998
  }
@@ -4004,10 +4049,35 @@
4004
4049
  },
4005
4050
  };
4006
4051
 
4052
+ const isBrowser = typeof document !== "undefined";
4053
+
4054
+ // Does this device prefer reduced motion? Returns `null` server-side.
4055
+ const prefersReducedMotion = { current: null };
4056
+ const hasReducedMotionListener = { current: false };
4057
+
4058
+ function initPrefersReducedMotion() {
4059
+ hasReducedMotionListener.current = true;
4060
+ if (!isBrowser)
4061
+ return;
4062
+ if (window.matchMedia) {
4063
+ const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
4064
+ const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
4065
+ motionMediaQuery.addListener(setReducedMotionPreferences);
4066
+ setReducedMotionPreferences();
4067
+ }
4068
+ else {
4069
+ prefersReducedMotion.current = false;
4070
+ }
4071
+ }
4072
+
4007
4073
  function isWillChangeMotionValue(value) {
4008
4074
  return Boolean(isMotionValue(value) && value.add);
4009
4075
  }
4010
4076
 
4077
+ function isAnimationControls(v) {
4078
+ return typeof v === "object" && typeof v.start === "function";
4079
+ }
4080
+
4011
4081
  /**
4012
4082
  * Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
4013
4083
  */
@@ -4049,36 +4119,8 @@
4049
4119
  */
4050
4120
  const findValueType = (v) => valueTypes.find(testValueType(v));
4051
4121
 
4052
- /**
4053
- * Decides if the supplied variable is an array of variant labels
4054
- */
4055
- function isVariantLabels(v) {
4056
- return Array.isArray(v);
4057
- }
4058
- /**
4059
- * Decides if the supplied variable is variant label
4060
- */
4061
- function isVariantLabel(v) {
4062
- return typeof v === "string" || isVariantLabels(v);
4063
- }
4064
- function checkIfControllingVariants(props) {
4065
- var _a;
4066
- return (typeof ((_a = props.animate) === null || _a === void 0 ? void 0 : _a.start) === "function" ||
4067
- isVariantLabel(props.initial) ||
4068
- isVariantLabel(props.animate) ||
4069
- isVariantLabel(props.whileHover) ||
4070
- isVariantLabel(props.whileDrag) ||
4071
- isVariantLabel(props.whileTap) ||
4072
- isVariantLabel(props.whileFocus) ||
4073
- isVariantLabel(props.exit));
4074
- }
4075
- function checkIfVariantNode(props) {
4076
- return Boolean(checkIfControllingVariants(props) || props.variants);
4077
- }
4078
-
4079
4122
  function checkTargetForNewValues(visualElement, target, origin) {
4080
- var _a, _b, _c;
4081
- var _d;
4123
+ var _a, _b;
4082
4124
  const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
4083
4125
  const numNewValues = newValueKeys.length;
4084
4126
  if (!numNewValues)
@@ -4117,7 +4159,9 @@
4117
4159
  value = getAnimatableNone(key, targetValue);
4118
4160
  }
4119
4161
  visualElement.addValue(key, motionValue(value));
4120
- (_c = (_d = origin)[key]) !== null && _c !== void 0 ? _c : (_d[key] = value);
4162
+ if (origin[key] === undefined) {
4163
+ origin[key] = value;
4164
+ }
4121
4165
  visualElement.setBaseTarget(key, value);
4122
4166
  }
4123
4167
  }
@@ -4128,15 +4172,25 @@
4128
4172
  return valueTransition.from;
4129
4173
  }
4130
4174
  function getOrigin(target, transition, visualElement) {
4131
- var _a, _b;
4175
+ var _a;
4132
4176
  const origin = {};
4133
4177
  for (const key in target) {
4178
+ const transitionOrigin = getOriginFromTransition(key, transition);
4134
4179
  origin[key] =
4135
- (_a = getOriginFromTransition(key, transition)) !== null && _a !== void 0 ? _a : (_b = visualElement.getValue(key)) === null || _b === void 0 ? void 0 : _b.get();
4180
+ transitionOrigin !== undefined
4181
+ ? transitionOrigin
4182
+ : (_a = visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.get();
4136
4183
  }
4137
4184
  return origin;
4138
4185
  }
4139
4186
 
4187
+ /**
4188
+ * Decides if the supplied variable is variant label
4189
+ */
4190
+ function isVariantLabel(v) {
4191
+ return typeof v === "string" || Array.isArray(v);
4192
+ }
4193
+
4140
4194
  var AnimationType;
4141
4195
  (function (AnimationType) {
4142
4196
  AnimationType["Animate"] = "animate";
@@ -4209,7 +4263,6 @@
4209
4263
  }
4210
4264
 
4211
4265
  function updateMotionValuesFromProps(element, next, prev) {
4212
- var _a;
4213
4266
  const { willChange } = next;
4214
4267
  for (const key in next) {
4215
4268
  const nextValue = next[key];
@@ -4228,7 +4281,7 @@
4228
4281
  * and warn against mismatches.
4229
4282
  */
4230
4283
  {
4231
- warnOnce(nextValue.version === "7.2.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.2.0 may not work as expected.`);
4284
+ warnOnce(nextValue.version === "7.3.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.3.1 may not work as expected.`);
4232
4285
  }
4233
4286
  }
4234
4287
  else if (isMotionValue(prevValue)) {
@@ -4253,7 +4306,8 @@
4253
4306
  !existingValue.hasAnimated && existingValue.set(nextValue);
4254
4307
  }
4255
4308
  else {
4256
- element.addValue(key, motionValue((_a = element.getStaticValue(key)) !== null && _a !== void 0 ? _a : nextValue));
4309
+ const latestValue = element.getStaticValue(key);
4310
+ element.addValue(key, motionValue(latestValue !== undefined ? latestValue : nextValue));
4257
4311
  }
4258
4312
  }
4259
4313
  }
@@ -4265,7 +4319,73 @@
4265
4319
  return next;
4266
4320
  }
4267
4321
 
4268
- const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, shouldReduceMotion, }, options = {}) => {
4322
+ const variantProps$1 = [
4323
+ "initial",
4324
+ "animate",
4325
+ "exit",
4326
+ "whileHover",
4327
+ "whileDrag",
4328
+ "whileTap",
4329
+ "whileFocus",
4330
+ "whileInView",
4331
+ ];
4332
+ function isControllingVariants(props) {
4333
+ return (isAnimationControls(props.animate) ||
4334
+ variantProps$1.some((name) => isVariantLabel(props[name])));
4335
+ }
4336
+ function isVariantNode(props) {
4337
+ return Boolean(isControllingVariants(props) || props.variants);
4338
+ }
4339
+
4340
+ /**
4341
+ * Browser-safe usage of process
4342
+ */
4343
+ const defaultEnvironment = "production";
4344
+ const env = typeof process === "undefined" || process.env === undefined
4345
+ ? defaultEnvironment
4346
+ : "development" ;
4347
+
4348
+ const createDefinition = (propNames) => ({
4349
+ isEnabled: (props) => propNames.some((name) => !!props[name]),
4350
+ });
4351
+ const featureDefinitions = {
4352
+ measureLayout: createDefinition(["layout", "layoutId", "drag"]),
4353
+ animation: createDefinition([
4354
+ "animate",
4355
+ "exit",
4356
+ "variants",
4357
+ "whileHover",
4358
+ "whileTap",
4359
+ "whileFocus",
4360
+ "whileDrag",
4361
+ "whileInView",
4362
+ ]),
4363
+ exit: createDefinition(["exit"]),
4364
+ drag: createDefinition(["drag", "dragControls"]),
4365
+ focus: createDefinition(["whileFocus"]),
4366
+ hover: createDefinition(["whileHover", "onHoverStart", "onHoverEnd"]),
4367
+ tap: createDefinition(["whileTap", "onTap", "onTapStart", "onTapCancel"]),
4368
+ pan: createDefinition([
4369
+ "onPan",
4370
+ "onPanStart",
4371
+ "onPanSessionStart",
4372
+ "onPanEnd",
4373
+ ]),
4374
+ inView: createDefinition([
4375
+ "whileInView",
4376
+ "onViewportEnter",
4377
+ "onViewportLeave",
4378
+ ]),
4379
+ };
4380
+
4381
+ function isRefObject(ref) {
4382
+ return (typeof ref === "object" &&
4383
+ Object.prototype.hasOwnProperty.call(ref, "current"));
4384
+ }
4385
+
4386
+ const featureNames = Object.keys(featureDefinitions);
4387
+ const numFeatures = featureNames.length;
4388
+ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, reducedMotionConfig, }, options = {}) => {
4269
4389
  let isMounted = false;
4270
4390
  const { latestValues, renderState } = visualState;
4271
4391
  /**
@@ -4301,7 +4421,9 @@
4301
4421
  * When values are removed from all animation props we need to search
4302
4422
  * for a fallback value to animate to. These values are tracked in baseTarget.
4303
4423
  */
4304
- const baseTarget = Object.assign({}, latestValues);
4424
+ const baseTarget = {
4425
+ ...latestValues,
4426
+ };
4305
4427
  // Internal methods ========================
4306
4428
  /**
4307
4429
  * On mount, this will be hydrated with a callback to disconnect
@@ -4348,7 +4470,7 @@
4348
4470
  * Doing so will break some tests but this isn't neccessarily a breaking change,
4349
4471
  * more a reflection of the test.
4350
4472
  */
4351
- const _a = scrapeMotionValuesFromProps(props), { willChange } = _a, initialMotionValues = __rest(_a, ["willChange"]);
4473
+ const { willChange, ...initialMotionValues } = scrapeMotionValuesFromProps(props);
4352
4474
  for (const key in initialMotionValues) {
4353
4475
  const value = initialMotionValues[key];
4354
4476
  if (latestValues[key] !== undefined && isMotionValue(value)) {
@@ -4361,36 +4483,39 @@
4361
4483
  /**
4362
4484
  * Determine what role this visual element should take in the variant tree.
4363
4485
  */
4364
- const isControllingVariants = checkIfControllingVariants(props);
4365
- const isVariantNode = checkIfVariantNode(props);
4366
- const element = Object.assign(Object.assign({ treeType,
4486
+ const isControllingVariants$1 = isControllingVariants(props);
4487
+ const isVariantNode$1 = isVariantNode(props);
4488
+ const element = {
4489
+ treeType,
4367
4490
  /**
4368
4491
  * This is a mirror of the internal instance prop, which keeps
4369
4492
  * VisualElement type-compatible with React's RefObject.
4370
4493
  */
4371
- current: null,
4494
+ current: null,
4372
4495
  /**
4373
4496
  * The depth of this visual element within the visual element tree.
4374
4497
  */
4375
- depth: parent ? parent.depth + 1 : 0, parent, children: new Set(),
4498
+ depth: parent ? parent.depth + 1 : 0,
4499
+ parent,
4500
+ children: new Set(),
4376
4501
  /**
4377
4502
  *
4378
4503
  */
4379
4504
  presenceId,
4380
- shouldReduceMotion,
4505
+ shouldReduceMotion: null,
4381
4506
  /**
4382
4507
  * If this component is part of the variant tree, it should track
4383
4508
  * any children that are also part of the tree. This is essentially
4384
4509
  * a shadow tree to simplify logic around how to stagger over children.
4385
4510
  */
4386
- variantChildren: isVariantNode ? new Set() : undefined,
4511
+ variantChildren: isVariantNode$1 ? new Set() : undefined,
4387
4512
  /**
4388
4513
  * Whether this instance is visible. This can be changed imperatively
4389
4514
  * by the projection tree, is analogous to CSS's visibility in that
4390
4515
  * hidden elements should take up layout, and needs enacting by the configured
4391
4516
  * render function.
4392
4517
  */
4393
- isVisible: undefined,
4518
+ isVisible: undefined,
4394
4519
  /**
4395
4520
  * Normally, if a component is controlled by a parent's variants, it can
4396
4521
  * rely on that ancestor to trigger animations further down the tree.
@@ -4399,27 +4524,37 @@
4399
4524
  *
4400
4525
  * TODO: This might be better replaced with a method isParentMounted
4401
4526
  */
4402
- manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
4527
+ manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
4403
4528
  /**
4404
4529
  * This can be set by AnimatePresence to force components that mount
4405
4530
  * at the same time as it to mount as if they have initial={false} set.
4406
4531
  */
4407
- blockInitialAnimation,
4532
+ blockInitialAnimation,
4408
4533
  /**
4409
4534
  * Determine whether this component has mounted yet. This is mostly used
4410
4535
  * by variant children to determine whether they need to trigger their
4411
4536
  * own animations on mount.
4412
4537
  */
4413
- isMounted: () => Boolean(instance), mount(newInstance) {
4538
+ isMounted: () => Boolean(instance),
4539
+ mount(newInstance) {
4414
4540
  isMounted = true;
4415
4541
  instance = element.current = newInstance;
4416
4542
  if (element.projection) {
4417
4543
  element.projection.mount(newInstance);
4418
4544
  }
4419
- if (isVariantNode && parent && !isControllingVariants) {
4545
+ if (isVariantNode$1 && parent && !isControllingVariants$1) {
4420
4546
  removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
4421
4547
  }
4422
4548
  values.forEach((value, key) => bindToMotionValue(key, value));
4549
+ if (!hasReducedMotionListener.current) {
4550
+ initPrefersReducedMotion();
4551
+ }
4552
+ element.shouldReduceMotion =
4553
+ reducedMotionConfig === "never"
4554
+ ? false
4555
+ : reducedMotionConfig === "always"
4556
+ ? true
4557
+ : prefersReducedMotion.current;
4423
4558
  parent === null || parent === void 0 ? void 0 : parent.children.add(element);
4424
4559
  element.setProps(props);
4425
4560
  },
@@ -4438,6 +4573,55 @@
4438
4573
  instance = undefined;
4439
4574
  isMounted = false;
4440
4575
  },
4576
+ loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
4577
+ const features = [];
4578
+ /**
4579
+ * If we're in development mode, check to make sure we're not rendering a motion component
4580
+ * as a child of LazyMotion, as this will break the file-size benefits of using it.
4581
+ */
4582
+ if (env !== "production" && preloadedFeatures && isStrict) {
4583
+ invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
4584
+ }
4585
+ for (let i = 0; i < numFeatures; i++) {
4586
+ const name = featureNames[i];
4587
+ const { isEnabled, Component } = featureDefinitions[name];
4588
+ /**
4589
+ * It might be possible in the future to use this moment to
4590
+ * dynamically request functionality. In initial tests this
4591
+ * was producing a lot of duplication amongst bundles.
4592
+ */
4593
+ if (isEnabled(props) && Component) {
4594
+ features.push(react.createElement(Component, {
4595
+ key: name,
4596
+ ...renderedProps,
4597
+ visualElement: element,
4598
+ }));
4599
+ }
4600
+ }
4601
+ if (!element.projection && ProjectionNodeConstructor) {
4602
+ element.projection = new ProjectionNodeConstructor(projectionId, element.getLatestValues(), parent && parent.projection);
4603
+ const { layoutId, layout, drag, dragConstraints, layoutScroll, } = renderedProps;
4604
+ element.projection.setOptions({
4605
+ layoutId,
4606
+ layout,
4607
+ alwaysMeasureLayout: Boolean(drag) ||
4608
+ (dragConstraints && isRefObject(dragConstraints)),
4609
+ visualElement: element,
4610
+ scheduleRender: () => element.scheduleRender(),
4611
+ /**
4612
+ * TODO: Update options in an effect. This could be tricky as it'll be too late
4613
+ * to update by the time layout animations run.
4614
+ * We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
4615
+ * ensuring it gets called if there's no potential layout animations.
4616
+ *
4617
+ */
4618
+ animationType: typeof layout === "string" ? layout : "both",
4619
+ initialPromotionConfig: initialLayoutGroupConfig,
4620
+ layoutScroll,
4621
+ });
4622
+ }
4623
+ return features;
4624
+ },
4441
4625
  /**
4442
4626
  * Add a child visual element to our set of children.
4443
4627
  */
@@ -4456,30 +4640,31 @@
4456
4640
  if (!sortNodePosition || treeType !== other.treeType)
4457
4641
  return 0;
4458
4642
  return sortNodePosition(element.getInstance(), other.getInstance());
4459
- },
4643
+ },
4460
4644
  /**
4461
4645
  * Returns the closest variant node in the tree starting from
4462
4646
  * this visual element.
4463
4647
  */
4464
- getClosestVariantNode: () => isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
4648
+ getClosestVariantNode: () => isVariantNode$1 ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
4465
4649
  /**
4466
4650
  * Expose the latest layoutId prop.
4467
4651
  */
4468
- getLayoutId: () => props.layoutId,
4652
+ getLayoutId: () => props.layoutId,
4469
4653
  /**
4470
4654
  * Returns the current instance.
4471
4655
  */
4472
- getInstance: () => instance,
4656
+ getInstance: () => instance,
4473
4657
  /**
4474
4658
  * Get/set the latest static values.
4475
4659
  */
4476
- getStaticValue: (key) => latestValues[key], setStaticValue: (key, value) => (latestValues[key] = value),
4660
+ getStaticValue: (key) => latestValues[key],
4661
+ setStaticValue: (key, value) => (latestValues[key] = value),
4477
4662
  /**
4478
4663
  * Returns the latest motion value state. Currently only used to take
4479
4664
  * a snapshot of the visual element - perhaps this can return the whole
4480
4665
  * visual state
4481
4666
  */
4482
- getLatestValues: () => latestValues,
4667
+ getLatestValues: () => latestValues,
4483
4668
  /**
4484
4669
  * Set the visiblity of the visual element. If it's changed, schedule
4485
4670
  * a render to reflect these changes.
@@ -4530,11 +4715,11 @@
4530
4715
  valueSubscriptions.delete(key);
4531
4716
  delete latestValues[key];
4532
4717
  removeValueFromRenderState(key, renderState);
4533
- },
4718
+ },
4534
4719
  /**
4535
4720
  * Check whether we have a motion value for this key
4536
4721
  */
4537
- hasValue: (key) => values.has(key),
4722
+ hasValue: (key) => values.has(key),
4538
4723
  /**
4539
4724
  * Get a motion value for this key. If called with a default
4540
4725
  * value, we'll create one if none exists.
@@ -4546,20 +4731,19 @@
4546
4731
  element.addValue(key, value);
4547
4732
  }
4548
4733
  return value;
4549
- },
4734
+ },
4550
4735
  /**
4551
4736
  * Iterate over our motion values.
4552
4737
  */
4553
- forEachValue: (callback) => values.forEach(callback),
4738
+ forEachValue: (callback) => values.forEach(callback),
4554
4739
  /**
4555
4740
  * If we're trying to animate to a previously unencountered value,
4556
4741
  * we need to check for it in our state and as a last resort read it
4557
4742
  * directly from the instance (which might have performance implications).
4558
4743
  */
4559
- readValue: (key) => {
4560
- var _a;
4561
- return (_a = latestValues[key]) !== null && _a !== void 0 ? _a : readValueFromInstance(instance, key, options);
4562
- },
4744
+ readValue: (key) => latestValues[key] !== undefined
4745
+ ? latestValues[key]
4746
+ : readValueFromInstance(instance, key, options),
4563
4747
  /**
4564
4748
  * Set the base target to later animate back to. This is currently
4565
4749
  * only hydrated on creation and when we first read a value.
@@ -4578,7 +4762,9 @@
4578
4762
  return target;
4579
4763
  }
4580
4764
  return baseTarget[key];
4581
- } }, lifecycles), {
4765
+ },
4766
+ // Lifecyles ========================
4767
+ ...lifecycles,
4582
4768
  /**
4583
4769
  * Build the renderer state based on the latest visual state.
4584
4770
  */
@@ -4591,14 +4777,14 @@
4591
4777
  */
4592
4778
  scheduleRender() {
4593
4779
  sync.render(render, false, true);
4594
- },
4780
+ },
4595
4781
  /**
4596
4782
  * Synchronously fire render. It's prefered that we batch renders but
4597
4783
  * in many circumstances, like layout measurement, we need to run this
4598
4784
  * synchronously. However in those instances other measures should be taken
4599
4785
  * to batch reads/writes.
4600
4786
  */
4601
- syncRender: render,
4787
+ syncRender: render,
4602
4788
  /**
4603
4789
  * Update the provided props. Ensure any newly-added motion values are
4604
4790
  * added to our map, old ones removed, and listeners updated.
@@ -4610,25 +4796,27 @@
4610
4796
  props = newProps;
4611
4797
  lifecycles.updatePropListeners(newProps);
4612
4798
  prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
4613
- }, getProps: () => props,
4799
+ },
4800
+ getProps: () => props,
4614
4801
  // Variants ==============================
4615
4802
  /**
4616
4803
  * Returns the variant definition with a given name.
4617
4804
  */
4618
- getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
4805
+ getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
4619
4806
  /**
4620
4807
  * Returns the defined default transition on this component.
4621
4808
  */
4622
- getDefaultTransition: () => props.transition, getTransformPagePoint: () => {
4809
+ getDefaultTransition: () => props.transition,
4810
+ getTransformPagePoint: () => {
4623
4811
  return props.transformPagePoint;
4624
- },
4812
+ },
4625
4813
  /**
4626
4814
  * Used by child variant nodes to get the closest ancestor variant props.
4627
4815
  */
4628
4816
  getVariantContext(startAtParent = false) {
4629
4817
  if (startAtParent)
4630
4818
  return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
4631
- if (!isControllingVariants) {
4819
+ if (!isControllingVariants$1) {
4632
4820
  const context = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
4633
4821
  if (props.initial !== undefined) {
4634
4822
  context.initial = props.initial;
@@ -4644,7 +4832,8 @@
4644
4832
  }
4645
4833
  }
4646
4834
  return context;
4647
- } });
4835
+ },
4836
+ };
4648
4837
  return element;
4649
4838
  };
4650
4839
  const variantProps = ["initial", ...variantPriorityOrder];
@@ -4667,11 +4856,7 @@
4667
4856
  };
4668
4857
 
4669
4858
  function buildHTMLStyles(state, latestValues, options, transformTemplate) {
4670
- var _a;
4671
4859
  const { style, vars, transform, transformKeys, transformOrigin } = state;
4672
- // Empty the transformKeys array. As we're throwing out refs to its items
4673
- // this might not be as cheap as suspected. Maybe using the array as a buffer
4674
- // with a manual incrementation would be better.
4675
4860
  transformKeys.length = 0;
4676
4861
  // Track whether we encounter any transform or transformOrigin values.
4677
4862
  let hasTransform = false;
@@ -4696,7 +4881,7 @@
4696
4881
  // Convert the value to its default value type, ie 0 -> "0px"
4697
4882
  const valueType = numberValueTypes[key];
4698
4883
  const valueAsType = getValueAsType(value, valueType);
4699
- if (isTransformProp(key)) {
4884
+ if (transformProps.has(key)) {
4700
4885
  // If this is a transform, flag to enable further transform processing
4701
4886
  hasTransform = true;
4702
4887
  transform[key] = valueAsType;
@@ -4705,34 +4890,38 @@
4705
4890
  if (!transformIsNone)
4706
4891
  continue;
4707
4892
  // Otherwise check to see if this is a default transform
4708
- if (value !== ((_a = valueType.default) !== null && _a !== void 0 ? _a : 0))
4893
+ if (value !== (valueType.default || 0))
4709
4894
  transformIsNone = false;
4710
4895
  }
4711
- else if (isTransformOriginProp(key)) {
4712
- transformOrigin[key] = valueAsType;
4896
+ else if (key.startsWith("origin")) {
4713
4897
  // If this is a transform origin, flag and enable further transform-origin processing
4714
4898
  hasTransformOrigin = true;
4899
+ transformOrigin[key] = valueAsType;
4715
4900
  }
4716
4901
  else {
4717
4902
  style[key] = valueAsType;
4718
4903
  }
4719
4904
  }
4720
- if (hasTransform) {
4905
+ if (hasTransform || transformTemplate) {
4721
4906
  style.transform = buildTransform(state, options, transformIsNone, transformTemplate);
4722
4907
  }
4723
- else if (transformTemplate) {
4724
- style.transform = transformTemplate({}, "");
4725
- }
4726
4908
  else if (!latestValues.transform && style.transform) {
4909
+ /**
4910
+ * If we have previously created a transform but currently don't have any,
4911
+ * reset transform style to none.
4912
+ */
4727
4913
  style.transform = "none";
4728
4914
  }
4915
+ /**
4916
+ * Build a transformOrigin style. Uses the same defaults as the browser for
4917
+ * undefined origins.
4918
+ */
4729
4919
  if (hasTransformOrigin) {
4730
- style.transformOrigin = buildTransformOrigin(transformOrigin);
4920
+ const { originX = "50%", originY = "50%", originZ = 0, } = transformOrigin;
4921
+ style.transformOrigin = `${originX} ${originY} ${originZ}`;
4731
4922
  }
4732
4923
  }
4733
4924
 
4734
- const isBrowser = typeof document !== "undefined";
4735
-
4736
4925
  const positionalKeys = new Set([
4737
4926
  "width",
4738
4927
  "height",
@@ -4782,7 +4971,7 @@
4782
4971
  }
4783
4972
  };
4784
4973
  const transformKeys = new Set(["x", "y", "z"]);
4785
- const nonTranslationalTransformKeys = transformProps.filter((key) => !transformKeys.has(key));
4974
+ const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
4786
4975
  function removeNonTranslationalTransform(visualElement) {
4787
4976
  const removedTransforms = [];
4788
4977
  nonTranslationalTransformKeys.forEach((key) => {
@@ -4839,8 +5028,8 @@
4839
5028
  return target;
4840
5029
  };
4841
5030
  const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, transitionEnd = {}) => {
4842
- target = Object.assign({}, target);
4843
- transitionEnd = Object.assign({}, transitionEnd);
5031
+ target = { ...target };
5032
+ transitionEnd = { ...transitionEnd };
4844
5033
  const targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
4845
5034
  // We want to remove any transform values that could affect the element's bounding box before
4846
5035
  // it's measured. We'll reapply these later.
@@ -4970,8 +5159,8 @@
4970
5159
  };
4971
5160
 
4972
5161
  function isForcedMotionValue(key, { layout, layoutId }) {
4973
- return (isTransformProp(key) ||
4974
- isTransformOriginProp(key) ||
5162
+ return (transformProps.has(key) ||
5163
+ key.startsWith("origin") ||
4975
5164
  ((layout || layoutId !== undefined) &&
4976
5165
  (!!scaleCorrectors[key] || key === "opacity")));
4977
5166
  }
@@ -5034,7 +5223,7 @@
5034
5223
  const htmlConfig = {
5035
5224
  treeType: "dom",
5036
5225
  readValueFromInstance(domElement, key) {
5037
- if (isTransformProp(key)) {
5226
+ if (transformProps.has(key)) {
5038
5227
  const defaultType = getDefaultValueType(key);
5039
5228
  return defaultType ? defaultType.default || 0 : 0;
5040
5229
  }
@@ -5087,10 +5276,7 @@
5087
5276
  * Ensure that HTML and Framer-specific value types like `px`->`%` and `Color`
5088
5277
  * can be animated by Motion.
5089
5278
  */
5090
- makeTargetAnimatable(element, _a, _b, isMounted) {
5091
- var { transition, transitionEnd } = _a, target = __rest(_a, ["transition", "transitionEnd"]);
5092
- var transformValues = _b.transformValues;
5093
- if (isMounted === void 0) { isMounted = true; }
5279
+ makeTargetAnimatable(element, { transition, transitionEnd, ...target }, { transformValues }, isMounted = true) {
5094
5280
  let origin = getOrigin(target, transition || {}, element);
5095
5281
  /**
5096
5282
  * If Framer has provided a function to convert `Color` etc value types, convert them
@@ -5109,8 +5295,11 @@
5109
5295
  transitionEnd = parsed.transitionEnd;
5110
5296
  target = parsed.target;
5111
5297
  }
5112
- return Object.assign({ transition,
5113
- transitionEnd }, target);
5298
+ return {
5299
+ transition,
5300
+ transitionEnd,
5301
+ ...target,
5302
+ };
5114
5303
  },
5115
5304
  scrapeMotionValuesFromProps,
5116
5305
  build(element, renderState, latestValues, options, props) {