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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var create = require('./create-7q3QlJ1Z.js');
5
+ var create = require('./create-BOq2yHIj.js');
6
6
  require('motion-dom');
7
7
  require('motion-utils');
8
8
  require('react/jsx-runtime');
@@ -911,7 +911,6 @@ const metrics = {
911
911
  calculatedProjections: 0,
912
912
  };
913
913
  const transformAxes = ["", "X", "Y", "Z"];
914
- const hiddenVisibility = { visibility: "hidden" };
915
914
  /**
916
915
  * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
917
916
  * which has a noticeable difference in spring animations
@@ -1133,8 +1132,17 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
1133
1132
  }
1134
1133
  if (attachResizeListener) {
1135
1134
  let cancelDelay;
1135
+ let innerWidth = 0;
1136
1136
  const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
1137
+ // Set initial innerWidth in a frame.read callback to batch the read
1138
+ motionDom.frame.read(() => {
1139
+ innerWidth = window.innerWidth;
1140
+ });
1137
1141
  attachResizeListener(instance, () => {
1142
+ const newInnerWidth = window.innerWidth;
1143
+ if (newInnerWidth === innerWidth)
1144
+ return;
1145
+ innerWidth = newInnerWidth;
1138
1146
  this.root.updateBlockedByResize = true;
1139
1147
  cancelDelay && cancelDelay();
1140
1148
  cancelDelay = delay(resizeUnblockUpdate, 250);
@@ -2141,59 +2149,60 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
2141
2149
  // see the element with the reset rotate value applied.
2142
2150
  visualElement.scheduleRender();
2143
2151
  }
2144
- getProjectionStyles(styleProp) {
2152
+ applyProjectionStyles(targetStyle, // CSSStyleDeclaration - doesn't allow numbers to be assigned to properties
2153
+ styleProp) {
2145
2154
  if (!this.instance || this.isSVG)
2146
- return undefined;
2155
+ return;
2147
2156
  if (!this.isVisible) {
2148
- return hiddenVisibility;
2157
+ targetStyle.visibility = "hidden";
2158
+ return;
2149
2159
  }
2150
- const styles = {
2151
- visibility: "",
2152
- };
2153
2160
  const transformTemplate = this.getTransformTemplate();
2154
2161
  if (this.needsReset) {
2155
2162
  this.needsReset = false;
2156
- styles.opacity = "";
2157
- styles.pointerEvents =
2163
+ targetStyle.visibility = "";
2164
+ targetStyle.opacity = "";
2165
+ targetStyle.pointerEvents =
2158
2166
  resolveMotionValue(styleProp?.pointerEvents) || "";
2159
- styles.transform = transformTemplate
2167
+ targetStyle.transform = transformTemplate
2160
2168
  ? transformTemplate(this.latestValues, "")
2161
2169
  : "none";
2162
- return styles;
2170
+ return;
2163
2171
  }
2164
2172
  const lead = this.getLead();
2165
2173
  if (!this.projectionDelta || !this.layout || !lead.target) {
2166
- const emptyStyles = {};
2167
2174
  if (this.options.layoutId) {
2168
- emptyStyles.opacity =
2175
+ targetStyle.opacity =
2169
2176
  this.latestValues.opacity !== undefined
2170
2177
  ? this.latestValues.opacity
2171
2178
  : 1;
2172
- emptyStyles.pointerEvents =
2179
+ targetStyle.pointerEvents =
2173
2180
  resolveMotionValue(styleProp?.pointerEvents) || "";
2174
2181
  }
2175
2182
  if (this.hasProjected && !hasTransform(this.latestValues)) {
2176
- emptyStyles.transform = transformTemplate
2183
+ targetStyle.transform = transformTemplate
2177
2184
  ? transformTemplate({}, "")
2178
2185
  : "none";
2179
2186
  this.hasProjected = false;
2180
2187
  }
2181
- return emptyStyles;
2188
+ return;
2182
2189
  }
2190
+ targetStyle.visibility = "";
2183
2191
  const valuesToRender = lead.animationValues || lead.latestValues;
2184
2192
  this.applyTransformsToTarget();
2185
- styles.transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
2193
+ let transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
2186
2194
  if (transformTemplate) {
2187
- styles.transform = transformTemplate(valuesToRender, styles.transform);
2195
+ transform = transformTemplate(valuesToRender, transform);
2188
2196
  }
2197
+ targetStyle.transform = transform;
2189
2198
  const { x, y } = this.projectionDelta;
2190
- styles.transformOrigin = `${x.origin * 100}% ${y.origin * 100}% 0`;
2199
+ targetStyle.transformOrigin = `${x.origin * 100}% ${y.origin * 100}% 0`;
2191
2200
  if (lead.animationValues) {
2192
2201
  /**
2193
2202
  * If the lead component is animating, assign this either the entering/leaving
2194
2203
  * opacity
2195
2204
  */
2196
- styles.opacity =
2205
+ targetStyle.opacity =
2197
2206
  lead === this
2198
2207
  ? valuesToRender.opacity ??
2199
2208
  this.latestValues.opacity ??
@@ -2207,7 +2216,7 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
2207
2216
  * Or we're not animating at all, set the lead component to its layout
2208
2217
  * opacity and other components to hidden.
2209
2218
  */
2210
- styles.opacity =
2219
+ targetStyle.opacity =
2211
2220
  lead === this
2212
2221
  ? valuesToRender.opacity !== undefined
2213
2222
  ? valuesToRender.opacity
@@ -2229,13 +2238,13 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
2229
2238
  * vulnerable to distortion if the element changes size without
2230
2239
  * a corresponding layout animation.
2231
2240
  */
2232
- const corrected = styles.transform === "none"
2241
+ const corrected = transform === "none"
2233
2242
  ? valuesToRender[key]
2234
2243
  : correct(valuesToRender[key], lead);
2235
2244
  if (applyTo) {
2236
2245
  const num = applyTo.length;
2237
2246
  for (let i = 0; i < num; i++) {
2238
- styles[applyTo[i]] = corrected;
2247
+ targetStyle[applyTo[i]] = corrected;
2239
2248
  }
2240
2249
  }
2241
2250
  else {
@@ -2246,7 +2255,7 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
2246
2255
  this.options.visualElement.renderState.vars[key] = corrected;
2247
2256
  }
2248
2257
  else {
2249
- styles[key] = corrected;
2258
+ targetStyle[key] = corrected;
2250
2259
  }
2251
2260
  }
2252
2261
  }
@@ -2256,12 +2265,11 @@ function createProjectionNode$1({ attachResizeListener, defaultParent, measureSc
2256
2265
  * pointer events on the lead.
2257
2266
  */
2258
2267
  if (this.options.layoutId) {
2259
- styles.pointerEvents =
2268
+ targetStyle.pointerEvents =
2260
2269
  lead === this
2261
2270
  ? resolveMotionValue(styleProp?.pointerEvents) || ""
2262
2271
  : "none";
2263
2272
  }
2264
- return styles;
2265
2273
  }
2266
2274
  clearSnapshot() {
2267
2275
  this.resumeFrom = this.snapshot = undefined;
@@ -3415,10 +3423,8 @@ function renderHTML(element, { style, vars }, styleProp, projection) {
3415
3423
  // CSSStyleDeclaration has [index: number]: string; in the types, so we use that as key type.
3416
3424
  elementStyle[key] = style[key];
3417
3425
  }
3418
- const projectionStyle = projection?.getProjectionStyles(styleProp);
3419
- for (key in projectionStyle) {
3420
- elementStyle[key] = projectionStyle[key];
3421
- }
3426
+ // Write projection styles directly to element style
3427
+ projection?.applyProjectionStyles(elementStyle, styleProp);
3422
3428
  for (key in vars) {
3423
3429
  // Loop over any CSS variables and assign those.
3424
3430
  // They can only be assigned using `setProperty`.
package/dist/cjs/dom.js CHANGED
@@ -1449,10 +1449,8 @@ function renderHTML(element, { style, vars }, styleProp, projection) {
1449
1449
  // CSSStyleDeclaration has [index: number]: string; in the types, so we use that as key type.
1450
1450
  elementStyle[key] = style[key];
1451
1451
  }
1452
- const projectionStyle = projection?.getProjectionStyles(styleProp);
1453
- for (key in projectionStyle) {
1454
- elementStyle[key] = projectionStyle[key];
1455
- }
1452
+ // Write projection styles directly to element style
1453
+ projection?.applyProjectionStyles(elementStyle, styleProp);
1456
1454
  for (key in vars) {
1457
1455
  // Loop over any CSS variables and assign those.
1458
1456
  // They can only be assigned using `setProperty`.
package/dist/cjs/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
- var create = require('./create-7q3QlJ1Z.js');
7
+ var create = require('./create-BOq2yHIj.js');
8
8
  var motionDom = require('motion-dom');
9
9
  var motionUtils = require('motion-utils');
10
10