framer-motion 12.20.4 → 12.20.5

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.
@@ -6200,7 +6200,6 @@
6200
6200
  calculatedProjections: 0,
6201
6201
  };
6202
6202
  const transformAxes = ["", "X", "Y", "Z"];
6203
- const hiddenVisibility = { visibility: "hidden" };
6204
6203
  /**
6205
6204
  * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
6206
6205
  * which has a noticeable difference in spring animations
@@ -6422,8 +6421,17 @@
6422
6421
  }
6423
6422
  if (attachResizeListener) {
6424
6423
  let cancelDelay;
6424
+ let innerWidth = 0;
6425
6425
  const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
6426
+ // Set initial innerWidth in a frame.read callback to batch the read
6427
+ frame.read(() => {
6428
+ innerWidth = window.innerWidth;
6429
+ });
6426
6430
  attachResizeListener(instance, () => {
6431
+ const newInnerWidth = window.innerWidth;
6432
+ if (newInnerWidth === innerWidth)
6433
+ return;
6434
+ innerWidth = newInnerWidth;
6427
6435
  this.root.updateBlockedByResize = true;
6428
6436
  cancelDelay && cancelDelay();
6429
6437
  cancelDelay = delay(resizeUnblockUpdate, 250);
@@ -7430,59 +7438,60 @@
7430
7438
  // see the element with the reset rotate value applied.
7431
7439
  visualElement.scheduleRender();
7432
7440
  }
7433
- getProjectionStyles(styleProp) {
7441
+ applyProjectionStyles(targetStyle, // CSSStyleDeclaration - doesn't allow numbers to be assigned to properties
7442
+ styleProp) {
7434
7443
  if (!this.instance || this.isSVG)
7435
- return undefined;
7444
+ return;
7436
7445
  if (!this.isVisible) {
7437
- return hiddenVisibility;
7446
+ targetStyle.visibility = "hidden";
7447
+ return;
7438
7448
  }
7439
- const styles = {
7440
- visibility: "",
7441
- };
7442
7449
  const transformTemplate = this.getTransformTemplate();
7443
7450
  if (this.needsReset) {
7444
7451
  this.needsReset = false;
7445
- styles.opacity = "";
7446
- styles.pointerEvents =
7452
+ targetStyle.visibility = "";
7453
+ targetStyle.opacity = "";
7454
+ targetStyle.pointerEvents =
7447
7455
  resolveMotionValue(styleProp?.pointerEvents) || "";
7448
- styles.transform = transformTemplate
7456
+ targetStyle.transform = transformTemplate
7449
7457
  ? transformTemplate(this.latestValues, "")
7450
7458
  : "none";
7451
- return styles;
7459
+ return;
7452
7460
  }
7453
7461
  const lead = this.getLead();
7454
7462
  if (!this.projectionDelta || !this.layout || !lead.target) {
7455
- const emptyStyles = {};
7456
7463
  if (this.options.layoutId) {
7457
- emptyStyles.opacity =
7464
+ targetStyle.opacity =
7458
7465
  this.latestValues.opacity !== undefined
7459
7466
  ? this.latestValues.opacity
7460
7467
  : 1;
7461
- emptyStyles.pointerEvents =
7468
+ targetStyle.pointerEvents =
7462
7469
  resolveMotionValue(styleProp?.pointerEvents) || "";
7463
7470
  }
7464
7471
  if (this.hasProjected && !hasTransform(this.latestValues)) {
7465
- emptyStyles.transform = transformTemplate
7472
+ targetStyle.transform = transformTemplate
7466
7473
  ? transformTemplate({}, "")
7467
7474
  : "none";
7468
7475
  this.hasProjected = false;
7469
7476
  }
7470
- return emptyStyles;
7477
+ return;
7471
7478
  }
7479
+ targetStyle.visibility = "";
7472
7480
  const valuesToRender = lead.animationValues || lead.latestValues;
7473
7481
  this.applyTransformsToTarget();
7474
- styles.transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
7482
+ let transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
7475
7483
  if (transformTemplate) {
7476
- styles.transform = transformTemplate(valuesToRender, styles.transform);
7484
+ transform = transformTemplate(valuesToRender, transform);
7477
7485
  }
7486
+ targetStyle.transform = transform;
7478
7487
  const { x, y } = this.projectionDelta;
7479
- styles.transformOrigin = `${x.origin * 100}% ${y.origin * 100}% 0`;
7488
+ targetStyle.transformOrigin = `${x.origin * 100}% ${y.origin * 100}% 0`;
7480
7489
  if (lead.animationValues) {
7481
7490
  /**
7482
7491
  * If the lead component is animating, assign this either the entering/leaving
7483
7492
  * opacity
7484
7493
  */
7485
- styles.opacity =
7494
+ targetStyle.opacity =
7486
7495
  lead === this
7487
7496
  ? valuesToRender.opacity ??
7488
7497
  this.latestValues.opacity ??
@@ -7496,7 +7505,7 @@
7496
7505
  * Or we're not animating at all, set the lead component to its layout
7497
7506
  * opacity and other components to hidden.
7498
7507
  */
7499
- styles.opacity =
7508
+ targetStyle.opacity =
7500
7509
  lead === this
7501
7510
  ? valuesToRender.opacity !== undefined
7502
7511
  ? valuesToRender.opacity
@@ -7518,13 +7527,13 @@
7518
7527
  * vulnerable to distortion if the element changes size without
7519
7528
  * a corresponding layout animation.
7520
7529
  */
7521
- const corrected = styles.transform === "none"
7530
+ const corrected = transform === "none"
7522
7531
  ? valuesToRender[key]
7523
7532
  : correct(valuesToRender[key], lead);
7524
7533
  if (applyTo) {
7525
7534
  const num = applyTo.length;
7526
7535
  for (let i = 0; i < num; i++) {
7527
- styles[applyTo[i]] = corrected;
7536
+ targetStyle[applyTo[i]] = corrected;
7528
7537
  }
7529
7538
  }
7530
7539
  else {
@@ -7535,7 +7544,7 @@
7535
7544
  this.options.visualElement.renderState.vars[key] = corrected;
7536
7545
  }
7537
7546
  else {
7538
- styles[key] = corrected;
7547
+ targetStyle[key] = corrected;
7539
7548
  }
7540
7549
  }
7541
7550
  }
@@ -7545,12 +7554,11 @@
7545
7554
  * pointer events on the lead.
7546
7555
  */
7547
7556
  if (this.options.layoutId) {
7548
- styles.pointerEvents =
7557
+ targetStyle.pointerEvents =
7549
7558
  lead === this
7550
7559
  ? resolveMotionValue(styleProp?.pointerEvents) || ""
7551
7560
  : "none";
7552
7561
  }
7553
- return styles;
7554
7562
  }
7555
7563
  clearSnapshot() {
7556
7564
  this.resumeFrom = this.snapshot = undefined;
@@ -8704,10 +8712,8 @@
8704
8712
  // CSSStyleDeclaration has [index: number]: string; in the types, so we use that as key type.
8705
8713
  elementStyle[key] = style[key];
8706
8714
  }
8707
- const projectionStyle = projection?.getProjectionStyles(styleProp);
8708
- for (key in projectionStyle) {
8709
- elementStyle[key] = projectionStyle[key];
8710
- }
8715
+ // Write projection styles directly to element style
8716
+ projection?.applyProjectionStyles(elementStyle, styleProp);
8711
8717
  for (key in vars) {
8712
8718
  // Loop over any CSS variables and assign those.
8713
8719
  // They can only be assigned using `setProperty`.