framer-motion 12.23.25 → 12.23.26

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.
@@ -6228,7 +6228,91 @@
6228
6228
  }
6229
6229
  }
6230
6230
 
6231
- const scaleCorrectors = {};
6231
+ function pixelsToPercent(pixels, axis) {
6232
+ if (axis.max === axis.min)
6233
+ return 0;
6234
+ return (pixels / (axis.max - axis.min)) * 100;
6235
+ }
6236
+ /**
6237
+ * We always correct borderRadius as a percentage rather than pixels to reduce paints.
6238
+ * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
6239
+ * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
6240
+ * borderRadius in both states. If we animate between the two in pixels that will trigger
6241
+ * a paint each time. If we animate between the two in percentage we'll avoid a paint.
6242
+ */
6243
+ const correctBorderRadius = {
6244
+ correct: (latest, node) => {
6245
+ if (!node.target)
6246
+ return latest;
6247
+ /**
6248
+ * If latest is a string, if it's a percentage we can return immediately as it's
6249
+ * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
6250
+ */
6251
+ if (typeof latest === "string") {
6252
+ if (px.test(latest)) {
6253
+ latest = parseFloat(latest);
6254
+ }
6255
+ else {
6256
+ return latest;
6257
+ }
6258
+ }
6259
+ /**
6260
+ * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
6261
+ * pixel value as a percentage of each axis
6262
+ */
6263
+ const x = pixelsToPercent(latest, node.target.x);
6264
+ const y = pixelsToPercent(latest, node.target.y);
6265
+ return `${x}% ${y}%`;
6266
+ },
6267
+ };
6268
+
6269
+ const correctBoxShadow = {
6270
+ correct: (latest, { treeScale, projectionDelta }) => {
6271
+ const original = latest;
6272
+ const shadow = complex.parse(latest);
6273
+ // TODO: Doesn't support multiple shadows
6274
+ if (shadow.length > 5)
6275
+ return original;
6276
+ const template = complex.createTransformer(latest);
6277
+ const offset = typeof shadow[0] !== "number" ? 1 : 0;
6278
+ // Calculate the overall context scale
6279
+ const xScale = projectionDelta.x.scale * treeScale.x;
6280
+ const yScale = projectionDelta.y.scale * treeScale.y;
6281
+ shadow[0 + offset] /= xScale;
6282
+ shadow[1 + offset] /= yScale;
6283
+ /**
6284
+ * Ideally we'd correct x and y scales individually, but because blur and
6285
+ * spread apply to both we have to take a scale average and apply that instead.
6286
+ * We could potentially improve the outcome of this by incorporating the ratio between
6287
+ * the two scales.
6288
+ */
6289
+ const averageScale = mixNumber$1(xScale, yScale, 0.5);
6290
+ // Blur
6291
+ if (typeof shadow[2 + offset] === "number")
6292
+ shadow[2 + offset] /= averageScale;
6293
+ // Spread
6294
+ if (typeof shadow[3 + offset] === "number")
6295
+ shadow[3 + offset] /= averageScale;
6296
+ return template(shadow);
6297
+ },
6298
+ };
6299
+
6300
+ const scaleCorrectors = {
6301
+ borderRadius: {
6302
+ ...correctBorderRadius,
6303
+ applyTo: [
6304
+ "borderTopLeftRadius",
6305
+ "borderTopRightRadius",
6306
+ "borderBottomLeftRadius",
6307
+ "borderBottomRightRadius",
6308
+ ],
6309
+ },
6310
+ borderTopLeftRadius: correctBorderRadius,
6311
+ borderTopRightRadius: correctBorderRadius,
6312
+ borderBottomLeftRadius: correctBorderRadius,
6313
+ borderBottomRightRadius: correctBorderRadius,
6314
+ boxShadow: correctBoxShadow,
6315
+ };
6232
6316
  function addScaleCorrector(correctors) {
6233
6317
  for (const key in correctors) {
6234
6318
  scaleCorrectors[key] = correctors[key];
@@ -7942,75 +8026,6 @@
7942
8026
  checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
7943
8027
  });
7944
8028
 
7945
- function pixelsToPercent(pixels, axis) {
7946
- if (axis.max === axis.min)
7947
- return 0;
7948
- return (pixels / (axis.max - axis.min)) * 100;
7949
- }
7950
- /**
7951
- * We always correct borderRadius as a percentage rather than pixels to reduce paints.
7952
- * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
7953
- * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
7954
- * borderRadius in both states. If we animate between the two in pixels that will trigger
7955
- * a paint each time. If we animate between the two in percentage we'll avoid a paint.
7956
- */
7957
- const correctBorderRadius = {
7958
- correct: (latest, node) => {
7959
- if (!node.target)
7960
- return latest;
7961
- /**
7962
- * If latest is a string, if it's a percentage we can return immediately as it's
7963
- * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
7964
- */
7965
- if (typeof latest === "string") {
7966
- if (px.test(latest)) {
7967
- latest = parseFloat(latest);
7968
- }
7969
- else {
7970
- return latest;
7971
- }
7972
- }
7973
- /**
7974
- * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
7975
- * pixel value as a percentage of each axis
7976
- */
7977
- const x = pixelsToPercent(latest, node.target.x);
7978
- const y = pixelsToPercent(latest, node.target.y);
7979
- return `${x}% ${y}%`;
7980
- },
7981
- };
7982
-
7983
- const correctBoxShadow = {
7984
- correct: (latest, { treeScale, projectionDelta }) => {
7985
- const original = latest;
7986
- const shadow = complex.parse(latest);
7987
- // TODO: Doesn't support multiple shadows
7988
- if (shadow.length > 5)
7989
- return original;
7990
- const template = complex.createTransformer(latest);
7991
- const offset = typeof shadow[0] !== "number" ? 1 : 0;
7992
- // Calculate the overall context scale
7993
- const xScale = projectionDelta.x.scale * treeScale.x;
7994
- const yScale = projectionDelta.y.scale * treeScale.y;
7995
- shadow[0 + offset] /= xScale;
7996
- shadow[1 + offset] /= yScale;
7997
- /**
7998
- * Ideally we'd correct x and y scales individually, but because blur and
7999
- * spread apply to both we have to take a scale average and apply that instead.
8000
- * We could potentially improve the outcome of this by incorporating the ratio between
8001
- * the two scales.
8002
- */
8003
- const averageScale = mixNumber$1(xScale, yScale, 0.5);
8004
- // Blur
8005
- if (typeof shadow[2 + offset] === "number")
8006
- shadow[2 + offset] /= averageScale;
8007
- // Spread
8008
- if (typeof shadow[3 + offset] === "number")
8009
- shadow[3 + offset] /= averageScale;
8010
- return template(shadow);
8011
- },
8012
- };
8013
-
8014
8029
  /**
8015
8030
  * Bounding boxes tend to be defined as top, left, right, bottom. For various operations
8016
8031
  * it's easier to consider each axis individually. This function returns a bounding box
@@ -11473,7 +11488,6 @@
11473
11488
  componentDidMount() {
11474
11489
  const { visualElement, layoutGroup, switchLayoutGroup, layoutId } = this.props;
11475
11490
  const { projection } = visualElement;
11476
- addScaleCorrector(defaultScaleCorrectors);
11477
11491
  if (projection) {
11478
11492
  if (layoutGroup.group)
11479
11493
  layoutGroup.group.add(projection);
@@ -11572,22 +11586,6 @@
11572
11586
  const layoutGroup = React$1.useContext(LayoutGroupContext);
11573
11587
  return (jsx(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: React$1.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
11574
11588
  }
11575
- const defaultScaleCorrectors = {
11576
- borderRadius: {
11577
- ...correctBorderRadius,
11578
- applyTo: [
11579
- "borderTopLeftRadius",
11580
- "borderTopRightRadius",
11581
- "borderBottomLeftRadius",
11582
- "borderBottomRightRadius",
11583
- ],
11584
- },
11585
- borderTopLeftRadius: correctBorderRadius,
11586
- borderTopRightRadius: correctBorderRadius,
11587
- borderBottomLeftRadius: correctBorderRadius,
11588
- borderBottomRightRadius: correctBorderRadius,
11589
- boxShadow: correctBoxShadow,
11590
- };
11591
11589
 
11592
11590
  const drag = {
11593
11591
  pan: {