framer-motion 12.23.10 → 12.23.11

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.
@@ -8286,8 +8286,7 @@
8286
8286
  {
8287
8287
  warnOnce(this.shouldReduceMotion !== true, "You have Reduced Motion enabled on your device. Animations may not appear as expected.", "reduced-motion-disabled");
8288
8288
  }
8289
- if (this.parent)
8290
- this.parent.children.add(this);
8289
+ this.parent?.addChild(this);
8291
8290
  this.update(this.props, this.presenceContext);
8292
8291
  }
8293
8292
  unmount() {
@@ -8297,7 +8296,7 @@
8297
8296
  this.valueSubscriptions.forEach((remove) => remove());
8298
8297
  this.valueSubscriptions.clear();
8299
8298
  this.removeFromVariantTree && this.removeFromVariantTree();
8300
- this.parent && this.parent.children.delete(this);
8299
+ this.parent?.removeChild(this);
8301
8300
  for (const key in this.events) {
8302
8301
  this.events[key].clear();
8303
8302
  }
@@ -8310,6 +8309,15 @@
8310
8309
  }
8311
8310
  this.current = null;
8312
8311
  }
8312
+ addChild(child) {
8313
+ this.children.add(child);
8314
+ this.enteringChildren ?? (this.enteringChildren = new Set());
8315
+ this.enteringChildren.add(child);
8316
+ }
8317
+ removeChild(child) {
8318
+ this.children.delete(child);
8319
+ this.enteringChildren && this.enteringChildren.delete(child);
8320
+ }
8313
8321
  bindToMotionValue(key, value) {
8314
8322
  if (this.valueSubscriptions.has(key)) {
8315
8323
  this.valueSubscriptions.get(key)();
@@ -9660,6 +9668,11 @@
9660
9668
  });
9661
9669
  wantsHandoff.current = false;
9662
9670
  }
9671
+ /**
9672
+ * Now we've finished triggering animations for this element we
9673
+ * can wipe the enteringChildren set for the next render.
9674
+ */
9675
+ visualElement.enteringChildren = undefined;
9663
9676
  });
9664
9677
  return visualElement;
9665
9678
  }
@@ -9953,6 +9966,20 @@
9953
9966
  return animations;
9954
9967
  }
9955
9968
 
9969
+ function calcChildStagger(children, child, delayChildren, staggerChildren = 0, staggerDirection = 1) {
9970
+ const index = Array.from(children)
9971
+ .sort((a, b) => a.sortNodePosition(b))
9972
+ .indexOf(child);
9973
+ const numChildren = children.size;
9974
+ const maxStaggerDuration = (numChildren - 1) * staggerChildren;
9975
+ const delayIsFunction = typeof delayChildren === "function";
9976
+ return delayIsFunction
9977
+ ? delayChildren(index, numChildren)
9978
+ : staggerDirection === 1
9979
+ ? index * staggerChildren
9980
+ : maxStaggerDuration - index * staggerChildren;
9981
+ }
9982
+
9956
9983
  function animateVariant(visualElement, variant, options = {}) {
9957
9984
  const resolved = resolveVariant(visualElement, variant, options.type === "exit"
9958
9985
  ? visualElement.presenceContext?.custom
@@ -9995,31 +10022,17 @@
9995
10022
  }
9996
10023
  function animateChildren(visualElement, variant, delay = 0, delayChildren = 0, staggerChildren = 0, staggerDirection = 1, options) {
9997
10024
  const animations = [];
9998
- const numChildren = visualElement.variantChildren.size;
9999
- const maxStaggerDuration = (numChildren - 1) * staggerChildren;
10000
- const delayIsFunction = typeof delayChildren === "function";
10001
- const generateStaggerDuration = delayIsFunction
10002
- ? (i) => delayChildren(i, numChildren)
10003
- : // Support deprecated staggerChildren
10004
- staggerDirection === 1
10005
- ? (i = 0) => i * staggerChildren
10006
- : (i = 0) => maxStaggerDuration - i * staggerChildren;
10007
- Array.from(visualElement.variantChildren)
10008
- .sort(sortByTreeOrder)
10009
- .forEach((child, i) => {
10025
+ for (const child of visualElement.variantChildren) {
10010
10026
  child.notify("AnimationStart", variant);
10011
10027
  animations.push(animateVariant(child, variant, {
10012
10028
  ...options,
10013
10029
  delay: delay +
10014
- (delayIsFunction ? 0 : delayChildren) +
10015
- generateStaggerDuration(i),
10030
+ (typeof delayChildren === "function" ? 0 : delayChildren) +
10031
+ calcChildStagger(visualElement.variantChildren, child, delayChildren, staggerChildren, staggerDirection),
10016
10032
  }).then(() => child.notify("AnimationComplete", variant)));
10017
- });
10033
+ }
10018
10034
  return Promise.all(animations);
10019
10035
  }
10020
- function sortByTreeOrder(a, b) {
10021
- return a.sortNodePosition(b);
10022
- }
10023
10036
 
10024
10037
  function animateVisualElement(visualElement, definition, options = {}) {
10025
10038
  visualElement.notify("AnimationStart", definition);
@@ -10172,9 +10185,6 @@
10172
10185
  let isInherited = prop === context[type] &&
10173
10186
  prop !== props[type] &&
10174
10187
  propIsVariant;
10175
- /**
10176
- *
10177
- */
10178
10188
  if (isInherited &&
10179
10189
  isInitialRender &&
10180
10190
  visualElement.manuallyAnimateOnMount) {
@@ -10295,9 +10305,6 @@
10295
10305
  */
10296
10306
  typeState.prevProp = prop;
10297
10307
  typeState.prevResolvedValues = resolvedValues;
10298
- /**
10299
- *
10300
- */
10301
10308
  if (typeState.isActive) {
10302
10309
  encounteredKeys = { ...encounteredKeys, ...resolvedValues };
10303
10310
  }
@@ -10311,10 +10318,30 @@
10311
10318
  const willAnimateViaParent = isInherited && variantDidChange;
10312
10319
  const needsAnimating = !willAnimateViaParent || handledRemovedValues;
10313
10320
  if (shouldAnimateType && needsAnimating) {
10314
- animations.push(...definitionList.map((animation) => ({
10315
- animation: animation,
10316
- options: { type },
10317
- })));
10321
+ animations.push(...definitionList.map((animation) => {
10322
+ const options = { type };
10323
+ /**
10324
+ * If we're performing the initial animation, but we're not
10325
+ * rendering at the same time as the variant-controlling parent,
10326
+ * we want to use the parent's transition to calculate the stagger.
10327
+ */
10328
+ if (typeof animation === "string" &&
10329
+ isInitialRender &&
10330
+ !willAnimateViaParent &&
10331
+ visualElement.manuallyAnimateOnMount &&
10332
+ visualElement.parent) {
10333
+ const { parent } = visualElement;
10334
+ const parentVariant = resolveVariant(parent, animation);
10335
+ if (parent.enteringChildren && parentVariant) {
10336
+ const { delayChildren } = parentVariant.transition || {};
10337
+ options.delay = calcChildStagger(parent.enteringChildren, visualElement, delayChildren);
10338
+ }
10339
+ }
10340
+ return {
10341
+ animation: animation,
10342
+ options,
10343
+ };
10344
+ }));
10318
10345
  }
10319
10346
  }
10320
10347
  /**