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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var featureBundle = require('./feature-bundle-DUrrFqHS.js');
5
+ var featureBundle = require('./feature-bundle-kvRbMDEA.js');
6
6
  require('react');
7
7
  require('motion-dom');
8
8
  require('motion-utils');
package/dist/cjs/dom.js CHANGED
@@ -1468,7 +1468,91 @@ function renderHTML(element, { style, vars }, styleProp, projection) {
1468
1468
  }
1469
1469
  }
1470
1470
 
1471
- const scaleCorrectors = {};
1471
+ function pixelsToPercent(pixels, axis) {
1472
+ if (axis.max === axis.min)
1473
+ return 0;
1474
+ return (pixels / (axis.max - axis.min)) * 100;
1475
+ }
1476
+ /**
1477
+ * We always correct borderRadius as a percentage rather than pixels to reduce paints.
1478
+ * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
1479
+ * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
1480
+ * borderRadius in both states. If we animate between the two in pixels that will trigger
1481
+ * a paint each time. If we animate between the two in percentage we'll avoid a paint.
1482
+ */
1483
+ const correctBorderRadius = {
1484
+ correct: (latest, node) => {
1485
+ if (!node.target)
1486
+ return latest;
1487
+ /**
1488
+ * If latest is a string, if it's a percentage we can return immediately as it's
1489
+ * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
1490
+ */
1491
+ if (typeof latest === "string") {
1492
+ if (motionDom.px.test(latest)) {
1493
+ latest = parseFloat(latest);
1494
+ }
1495
+ else {
1496
+ return latest;
1497
+ }
1498
+ }
1499
+ /**
1500
+ * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
1501
+ * pixel value as a percentage of each axis
1502
+ */
1503
+ const x = pixelsToPercent(latest, node.target.x);
1504
+ const y = pixelsToPercent(latest, node.target.y);
1505
+ return `${x}% ${y}%`;
1506
+ },
1507
+ };
1508
+
1509
+ const correctBoxShadow = {
1510
+ correct: (latest, { treeScale, projectionDelta }) => {
1511
+ const original = latest;
1512
+ const shadow = motionDom.complex.parse(latest);
1513
+ // TODO: Doesn't support multiple shadows
1514
+ if (shadow.length > 5)
1515
+ return original;
1516
+ const template = motionDom.complex.createTransformer(latest);
1517
+ const offset = typeof shadow[0] !== "number" ? 1 : 0;
1518
+ // Calculate the overall context scale
1519
+ const xScale = projectionDelta.x.scale * treeScale.x;
1520
+ const yScale = projectionDelta.y.scale * treeScale.y;
1521
+ shadow[0 + offset] /= xScale;
1522
+ shadow[1 + offset] /= yScale;
1523
+ /**
1524
+ * Ideally we'd correct x and y scales individually, but because blur and
1525
+ * spread apply to both we have to take a scale average and apply that instead.
1526
+ * We could potentially improve the outcome of this by incorporating the ratio between
1527
+ * the two scales.
1528
+ */
1529
+ const averageScale = motionDom.mixNumber(xScale, yScale, 0.5);
1530
+ // Blur
1531
+ if (typeof shadow[2 + offset] === "number")
1532
+ shadow[2 + offset] /= averageScale;
1533
+ // Spread
1534
+ if (typeof shadow[3 + offset] === "number")
1535
+ shadow[3 + offset] /= averageScale;
1536
+ return template(shadow);
1537
+ },
1538
+ };
1539
+
1540
+ const scaleCorrectors = {
1541
+ borderRadius: {
1542
+ ...correctBorderRadius,
1543
+ applyTo: [
1544
+ "borderTopLeftRadius",
1545
+ "borderTopRightRadius",
1546
+ "borderBottomLeftRadius",
1547
+ "borderBottomRightRadius",
1548
+ ],
1549
+ },
1550
+ borderTopLeftRadius: correctBorderRadius,
1551
+ borderTopRightRadius: correctBorderRadius,
1552
+ borderBottomLeftRadius: correctBorderRadius,
1553
+ borderBottomRightRadius: correctBorderRadius,
1554
+ boxShadow: correctBoxShadow,
1555
+ };
1472
1556
 
1473
1557
  function isForcedMotionValue(key, { layout, layoutId }) {
1474
1558
  return (motionDom.transformProps.has(key) ||
@@ -825,7 +825,91 @@ class NodeStack {
825
825
  }
826
826
  }
827
827
 
828
- const scaleCorrectors = {};
828
+ function pixelsToPercent(pixels, axis) {
829
+ if (axis.max === axis.min)
830
+ return 0;
831
+ return (pixels / (axis.max - axis.min)) * 100;
832
+ }
833
+ /**
834
+ * We always correct borderRadius as a percentage rather than pixels to reduce paints.
835
+ * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
836
+ * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
837
+ * borderRadius in both states. If we animate between the two in pixels that will trigger
838
+ * a paint each time. If we animate between the two in percentage we'll avoid a paint.
839
+ */
840
+ const correctBorderRadius = {
841
+ correct: (latest, node) => {
842
+ if (!node.target)
843
+ return latest;
844
+ /**
845
+ * If latest is a string, if it's a percentage we can return immediately as it's
846
+ * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
847
+ */
848
+ if (typeof latest === "string") {
849
+ if (motionDom.px.test(latest)) {
850
+ latest = parseFloat(latest);
851
+ }
852
+ else {
853
+ return latest;
854
+ }
855
+ }
856
+ /**
857
+ * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
858
+ * pixel value as a percentage of each axis
859
+ */
860
+ const x = pixelsToPercent(latest, node.target.x);
861
+ const y = pixelsToPercent(latest, node.target.y);
862
+ return `${x}% ${y}%`;
863
+ },
864
+ };
865
+
866
+ const correctBoxShadow = {
867
+ correct: (latest, { treeScale, projectionDelta }) => {
868
+ const original = latest;
869
+ const shadow = motionDom.complex.parse(latest);
870
+ // TODO: Doesn't support multiple shadows
871
+ if (shadow.length > 5)
872
+ return original;
873
+ const template = motionDom.complex.createTransformer(latest);
874
+ const offset = typeof shadow[0] !== "number" ? 1 : 0;
875
+ // Calculate the overall context scale
876
+ const xScale = projectionDelta.x.scale * treeScale.x;
877
+ const yScale = projectionDelta.y.scale * treeScale.y;
878
+ shadow[0 + offset] /= xScale;
879
+ shadow[1 + offset] /= yScale;
880
+ /**
881
+ * Ideally we'd correct x and y scales individually, but because blur and
882
+ * spread apply to both we have to take a scale average and apply that instead.
883
+ * We could potentially improve the outcome of this by incorporating the ratio between
884
+ * the two scales.
885
+ */
886
+ const averageScale = motionDom.mixNumber(xScale, yScale, 0.5);
887
+ // Blur
888
+ if (typeof shadow[2 + offset] === "number")
889
+ shadow[2 + offset] /= averageScale;
890
+ // Spread
891
+ if (typeof shadow[3 + offset] === "number")
892
+ shadow[3 + offset] /= averageScale;
893
+ return template(shadow);
894
+ },
895
+ };
896
+
897
+ const scaleCorrectors = {
898
+ borderRadius: {
899
+ ...correctBorderRadius,
900
+ applyTo: [
901
+ "borderTopLeftRadius",
902
+ "borderTopRightRadius",
903
+ "borderBottomLeftRadius",
904
+ "borderBottomRightRadius",
905
+ ],
906
+ },
907
+ borderTopLeftRadius: correctBorderRadius,
908
+ borderTopRightRadius: correctBorderRadius,
909
+ borderBottomLeftRadius: correctBorderRadius,
910
+ borderBottomRightRadius: correctBorderRadius,
911
+ boxShadow: correctBoxShadow,
912
+ };
829
913
  function addScaleCorrector(correctors) {
830
914
  for (const key in correctors) {
831
915
  scaleCorrectors[key] = correctors[key];
@@ -2539,75 +2623,6 @@ const HTMLProjectionNode = createProjectionNode$1({
2539
2623
  checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
2540
2624
  });
2541
2625
 
2542
- function pixelsToPercent(pixels, axis) {
2543
- if (axis.max === axis.min)
2544
- return 0;
2545
- return (pixels / (axis.max - axis.min)) * 100;
2546
- }
2547
- /**
2548
- * We always correct borderRadius as a percentage rather than pixels to reduce paints.
2549
- * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
2550
- * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
2551
- * borderRadius in both states. If we animate between the two in pixels that will trigger
2552
- * a paint each time. If we animate between the two in percentage we'll avoid a paint.
2553
- */
2554
- const correctBorderRadius = {
2555
- correct: (latest, node) => {
2556
- if (!node.target)
2557
- return latest;
2558
- /**
2559
- * If latest is a string, if it's a percentage we can return immediately as it's
2560
- * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
2561
- */
2562
- if (typeof latest === "string") {
2563
- if (motionDom.px.test(latest)) {
2564
- latest = parseFloat(latest);
2565
- }
2566
- else {
2567
- return latest;
2568
- }
2569
- }
2570
- /**
2571
- * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
2572
- * pixel value as a percentage of each axis
2573
- */
2574
- const x = pixelsToPercent(latest, node.target.x);
2575
- const y = pixelsToPercent(latest, node.target.y);
2576
- return `${x}% ${y}%`;
2577
- },
2578
- };
2579
-
2580
- const correctBoxShadow = {
2581
- correct: (latest, { treeScale, projectionDelta }) => {
2582
- const original = latest;
2583
- const shadow = motionDom.complex.parse(latest);
2584
- // TODO: Doesn't support multiple shadows
2585
- if (shadow.length > 5)
2586
- return original;
2587
- const template = motionDom.complex.createTransformer(latest);
2588
- const offset = typeof shadow[0] !== "number" ? 1 : 0;
2589
- // Calculate the overall context scale
2590
- const xScale = projectionDelta.x.scale * treeScale.x;
2591
- const yScale = projectionDelta.y.scale * treeScale.y;
2592
- shadow[0 + offset] /= xScale;
2593
- shadow[1 + offset] /= yScale;
2594
- /**
2595
- * Ideally we'd correct x and y scales individually, but because blur and
2596
- * spread apply to both we have to take a scale average and apply that instead.
2597
- * We could potentially improve the outcome of this by incorporating the ratio between
2598
- * the two scales.
2599
- */
2600
- const averageScale = motionDom.mixNumber(xScale, yScale, 0.5);
2601
- // Blur
2602
- if (typeof shadow[2 + offset] === "number")
2603
- shadow[2 + offset] /= averageScale;
2604
- // Spread
2605
- if (typeof shadow[3 + offset] === "number")
2606
- shadow[3 + offset] /= averageScale;
2607
- return template(shadow);
2608
- },
2609
- };
2610
-
2611
2626
  /**
2612
2627
  * Bounding boxes tend to be defined as top, left, right, bottom. For various operations
2613
2628
  * it's easier to consider each axis individually. This function returns a bounding box
@@ -5879,7 +5894,6 @@ class MeasureLayoutWithContext extends React.Component {
5879
5894
  componentDidMount() {
5880
5895
  const { visualElement, layoutGroup, switchLayoutGroup, layoutId } = this.props;
5881
5896
  const { projection } = visualElement;
5882
- addScaleCorrector(defaultScaleCorrectors);
5883
5897
  if (projection) {
5884
5898
  if (layoutGroup.group)
5885
5899
  layoutGroup.group.add(projection);
@@ -5978,22 +5992,6 @@ function MeasureLayout(props) {
5978
5992
  const layoutGroup = React.useContext(LayoutGroupContext);
5979
5993
  return (jsxRuntime.jsx(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: React.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
5980
5994
  }
5981
- const defaultScaleCorrectors = {
5982
- borderRadius: {
5983
- ...correctBorderRadius,
5984
- applyTo: [
5985
- "borderTopLeftRadius",
5986
- "borderTopRightRadius",
5987
- "borderBottomLeftRadius",
5988
- "borderBottomRightRadius",
5989
- ],
5990
- },
5991
- borderTopLeftRadius: correctBorderRadius,
5992
- borderTopRightRadius: correctBorderRadius,
5993
- borderBottomLeftRadius: correctBorderRadius,
5994
- borderBottomRightRadius: correctBorderRadius,
5995
- boxShadow: correctBoxShadow,
5996
- };
5997
5995
 
5998
5996
  const drag = {
5999
5997
  pan: {
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 featureBundle = require('./feature-bundle-DUrrFqHS.js');
7
+ var featureBundle = require('./feature-bundle-kvRbMDEA.js');
8
8
  var motionDom = require('motion-dom');
9
9
  var motionUtils = require('motion-utils');
10
10
 
package/dist/cjs/m.js CHANGED
@@ -75,7 +75,91 @@ function variantLabelsAsDependency(prop) {
75
75
  return Array.isArray(prop) ? prop.join(" ") : prop;
76
76
  }
77
77
 
78
- const scaleCorrectors = {};
78
+ function pixelsToPercent(pixels, axis) {
79
+ if (axis.max === axis.min)
80
+ return 0;
81
+ return (pixels / (axis.max - axis.min)) * 100;
82
+ }
83
+ /**
84
+ * We always correct borderRadius as a percentage rather than pixels to reduce paints.
85
+ * For example, if you are projecting a box that is 100px wide with a 10px borderRadius
86
+ * into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
87
+ * borderRadius in both states. If we animate between the two in pixels that will trigger
88
+ * a paint each time. If we animate between the two in percentage we'll avoid a paint.
89
+ */
90
+ const correctBorderRadius = {
91
+ correct: (latest, node) => {
92
+ if (!node.target)
93
+ return latest;
94
+ /**
95
+ * If latest is a string, if it's a percentage we can return immediately as it's
96
+ * going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
97
+ */
98
+ if (typeof latest === "string") {
99
+ if (motionDom.px.test(latest)) {
100
+ latest = parseFloat(latest);
101
+ }
102
+ else {
103
+ return latest;
104
+ }
105
+ }
106
+ /**
107
+ * If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
108
+ * pixel value as a percentage of each axis
109
+ */
110
+ const x = pixelsToPercent(latest, node.target.x);
111
+ const y = pixelsToPercent(latest, node.target.y);
112
+ return `${x}% ${y}%`;
113
+ },
114
+ };
115
+
116
+ const correctBoxShadow = {
117
+ correct: (latest, { treeScale, projectionDelta }) => {
118
+ const original = latest;
119
+ const shadow = motionDom.complex.parse(latest);
120
+ // TODO: Doesn't support multiple shadows
121
+ if (shadow.length > 5)
122
+ return original;
123
+ const template = motionDom.complex.createTransformer(latest);
124
+ const offset = typeof shadow[0] !== "number" ? 1 : 0;
125
+ // Calculate the overall context scale
126
+ const xScale = projectionDelta.x.scale * treeScale.x;
127
+ const yScale = projectionDelta.y.scale * treeScale.y;
128
+ shadow[0 + offset] /= xScale;
129
+ shadow[1 + offset] /= yScale;
130
+ /**
131
+ * Ideally we'd correct x and y scales individually, but because blur and
132
+ * spread apply to both we have to take a scale average and apply that instead.
133
+ * We could potentially improve the outcome of this by incorporating the ratio between
134
+ * the two scales.
135
+ */
136
+ const averageScale = motionDom.mixNumber(xScale, yScale, 0.5);
137
+ // Blur
138
+ if (typeof shadow[2 + offset] === "number")
139
+ shadow[2 + offset] /= averageScale;
140
+ // Spread
141
+ if (typeof shadow[3 + offset] === "number")
142
+ shadow[3 + offset] /= averageScale;
143
+ return template(shadow);
144
+ },
145
+ };
146
+
147
+ const scaleCorrectors = {
148
+ borderRadius: {
149
+ ...correctBorderRadius,
150
+ applyTo: [
151
+ "borderTopLeftRadius",
152
+ "borderTopRightRadius",
153
+ "borderBottomLeftRadius",
154
+ "borderBottomRightRadius",
155
+ ],
156
+ },
157
+ borderTopLeftRadius: correctBorderRadius,
158
+ borderTopRightRadius: correctBorderRadius,
159
+ borderBottomLeftRadius: correctBorderRadius,
160
+ borderBottomRightRadius: correctBorderRadius,
161
+ boxShadow: correctBoxShadow,
162
+ };
79
163
 
80
164
  function isForcedMotionValue(key, { layout, layoutId }) {
81
165
  return (motionDom.transformProps.has(key) ||