framer-motion 12.4.12 → 12.4.13

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-Da6xW2BP.js');
5
+ var create = require('./create-DkTZDHiS.js');
6
6
  require('motion-dom');
7
7
  require('motion-utils');
8
8
  require('react/jsx-runtime');
@@ -410,7 +410,7 @@ class MotionValue {
410
410
  * This will be replaced by the build step with the latest version number.
411
411
  * When MotionValues are provided to motion components, warn if versions are mixed.
412
412
  */
413
- this.version = "12.4.12";
413
+ this.version = "12.4.13";
414
414
  /**
415
415
  * Tracks whether this value can output a velocity. Currently this is only true
416
416
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1253,25 +1253,89 @@ function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, n
1253
1253
  }
1254
1254
  }
1255
1255
 
1256
- const isNumOrPxType = (v) => v === number || v === px;
1257
- const getPosFromMatrix = (matrix, pos) => parseFloat(matrix.split(", ")[pos]);
1258
- const getTranslateFromMatrix = (pos2, pos3) => (_bbox, { transform }) => {
1259
- if (transform === "none" || !transform)
1260
- return 0;
1261
- const matrix3d = transform.match(/^matrix3d\((.+)\)$/u);
1262
- if (matrix3d) {
1263
- return getPosFromMatrix(matrix3d[1], pos3);
1256
+ const radToDeg = (rad) => (rad * 180) / Math.PI;
1257
+ const rotate = (v) => {
1258
+ const angle = radToDeg(Math.atan2(v[1], v[0]));
1259
+ return rebaseAngle(angle);
1260
+ };
1261
+ const matrix2dParsers = {
1262
+ x: 4,
1263
+ y: 5,
1264
+ translateX: 4,
1265
+ translateY: 5,
1266
+ scaleX: 0,
1267
+ scaleY: 3,
1268
+ scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
1269
+ rotate,
1270
+ rotateZ: rotate,
1271
+ skewX: (v) => radToDeg(Math.atan(v[1])),
1272
+ skewY: (v) => radToDeg(Math.atan(v[2])),
1273
+ skew: (v) => (Math.abs(v[1]) + Math.abs(v[2])) / 2,
1274
+ };
1275
+ const rebaseAngle = (angle) => {
1276
+ angle = angle % 360;
1277
+ if (angle < 0)
1278
+ angle += 360;
1279
+ return angle;
1280
+ };
1281
+ const rotateZ = rotate;
1282
+ const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
1283
+ const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
1284
+ const matrix3dParsers = {
1285
+ x: 12,
1286
+ y: 13,
1287
+ z: 14,
1288
+ translateX: 12,
1289
+ translateY: 13,
1290
+ translateZ: 14,
1291
+ scaleX,
1292
+ scaleY,
1293
+ scale: (v) => (scaleX(v) + scaleY(v)) / 2,
1294
+ rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
1295
+ rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
1296
+ rotateZ,
1297
+ rotate: rotateZ,
1298
+ skewX: (v) => radToDeg(Math.atan(v[4])),
1299
+ skewY: (v) => radToDeg(Math.atan(v[1])),
1300
+ skew: (v) => (Math.abs(v[1]) + Math.abs(v[4])) / 2,
1301
+ };
1302
+ function defaultTransformValue(name) {
1303
+ return name.includes("scale") ? 1 : 0;
1304
+ }
1305
+ function parseValueFromTransform(transform, name) {
1306
+ if (!transform || transform === "none") {
1307
+ return defaultTransformValue(name);
1264
1308
  }
1265
- else {
1266
- const matrix = transform.match(/^matrix\((.+)\)$/u);
1267
- if (matrix) {
1268
- return getPosFromMatrix(matrix[1], pos2);
1269
- }
1270
- else {
1271
- return 0;
1272
- }
1309
+ const matrix3dMatch = transform.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);
1310
+ let parsers;
1311
+ let match;
1312
+ if (matrix3dMatch) {
1313
+ parsers = matrix3dParsers;
1314
+ match = matrix3dMatch;
1273
1315
  }
1316
+ else {
1317
+ const matrix2dMatch = transform.match(/^matrix\(([-\d.e\s,]+)\)$/u);
1318
+ parsers = matrix2dParsers;
1319
+ match = matrix2dMatch;
1320
+ }
1321
+ if (!match) {
1322
+ return defaultTransformValue(name);
1323
+ }
1324
+ const valueParser = parsers[name];
1325
+ const values = match[1].split(",").map(convertTransformToNumber);
1326
+ return typeof valueParser === "function"
1327
+ ? valueParser(values)
1328
+ : values[valueParser];
1329
+ }
1330
+ const readTransformValue = (instance, name) => {
1331
+ const { transform = "none" } = getComputedStyle(instance);
1332
+ return parseValueFromTransform(transform, name);
1274
1333
  };
1334
+ function convertTransformToNumber(value) {
1335
+ return parseFloat(value.trim());
1336
+ }
1337
+
1338
+ const isNumOrPxType = (v) => v === number || v === px;
1275
1339
  const transformKeys = new Set(["x", "y", "z"]);
1276
1340
  const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
1277
1341
  function removeNonTranslationalTransform(visualElement) {
@@ -1294,8 +1358,8 @@ const positionalValues = {
1294
1358
  bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
1295
1359
  right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
1296
1360
  // Transform
1297
- x: getTranslateFromMatrix(4, 13),
1298
- y: getTranslateFromMatrix(5, 14),
1361
+ x: (_bbox, { transform }) => parseValueFromTransform(transform, "x"),
1362
+ y: (_bbox, { transform }) => parseValueFromTransform(transform, "y"),
1299
1363
  };
1300
1364
  // Alias translate longform names
1301
1365
  positionalValues.translateX = positionalValues.x;
@@ -4577,7 +4641,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4577
4641
  * and warn against mismatches.
4578
4642
  */
4579
4643
  if (process.env.NODE_ENV === "development") {
4580
- warnOnce(nextValue.version === "12.4.12", `Attempting to mix Motion versions ${nextValue.version} with 12.4.12 may not work as expected.`);
4644
+ warnOnce(nextValue.version === "12.4.13", `Attempting to mix Motion versions ${nextValue.version} with 12.4.13 may not work as expected.`);
4581
4645
  }
4582
4646
  }
4583
4647
  else if (isMotionValue(prevValue)) {
@@ -5666,7 +5730,7 @@ function measurePageBox(element, rootProjectionNode, transformPagePoint) {
5666
5730
  return viewportBox;
5667
5731
  }
5668
5732
 
5669
- function getComputedStyle(element) {
5733
+ function getComputedStyle$1(element) {
5670
5734
  return window.getComputedStyle(element);
5671
5735
  }
5672
5736
  class HTMLVisualElement extends DOMVisualElement {
@@ -5677,11 +5741,10 @@ class HTMLVisualElement extends DOMVisualElement {
5677
5741
  }
5678
5742
  readValueFromInstance(instance, key) {
5679
5743
  if (transformProps.has(key)) {
5680
- const defaultType = getDefaultValueType(key);
5681
- return defaultType ? defaultType.default || 0 : 0;
5744
+ return readTransformValue(instance, key);
5682
5745
  }
5683
5746
  else {
5684
- const computedStyle = getComputedStyle(instance);
5747
+ const computedStyle = getComputedStyle$1(instance);
5685
5748
  const value = (isCSSVariableName(key)
5686
5749
  ? computedStyle.getPropertyValue(key)
5687
5750
  : computedStyle[key]) || 0;
package/dist/cjs/dom.js CHANGED
@@ -1011,7 +1011,7 @@ class MotionValue {
1011
1011
  * This will be replaced by the build step with the latest version number.
1012
1012
  * When MotionValues are provided to motion components, warn if versions are mixed.
1013
1013
  */
1014
- this.version = "12.4.12";
1014
+ this.version = "12.4.13";
1015
1015
  /**
1016
1016
  * Tracks whether this value can output a velocity. Currently this is only true
1017
1017
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1877,25 +1877,89 @@ function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, n
1877
1877
  }
1878
1878
  }
1879
1879
 
1880
- const isNumOrPxType = (v) => v === number || v === px;
1881
- const getPosFromMatrix = (matrix, pos) => parseFloat(matrix.split(", ")[pos]);
1882
- const getTranslateFromMatrix = (pos2, pos3) => (_bbox, { transform }) => {
1883
- if (transform === "none" || !transform)
1884
- return 0;
1885
- const matrix3d = transform.match(/^matrix3d\((.+)\)$/u);
1886
- if (matrix3d) {
1887
- return getPosFromMatrix(matrix3d[1], pos3);
1880
+ const radToDeg = (rad) => (rad * 180) / Math.PI;
1881
+ const rotate = (v) => {
1882
+ const angle = radToDeg(Math.atan2(v[1], v[0]));
1883
+ return rebaseAngle(angle);
1884
+ };
1885
+ const matrix2dParsers = {
1886
+ x: 4,
1887
+ y: 5,
1888
+ translateX: 4,
1889
+ translateY: 5,
1890
+ scaleX: 0,
1891
+ scaleY: 3,
1892
+ scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
1893
+ rotate,
1894
+ rotateZ: rotate,
1895
+ skewX: (v) => radToDeg(Math.atan(v[1])),
1896
+ skewY: (v) => radToDeg(Math.atan(v[2])),
1897
+ skew: (v) => (Math.abs(v[1]) + Math.abs(v[2])) / 2,
1898
+ };
1899
+ const rebaseAngle = (angle) => {
1900
+ angle = angle % 360;
1901
+ if (angle < 0)
1902
+ angle += 360;
1903
+ return angle;
1904
+ };
1905
+ const rotateZ = rotate;
1906
+ const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
1907
+ const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
1908
+ const matrix3dParsers = {
1909
+ x: 12,
1910
+ y: 13,
1911
+ z: 14,
1912
+ translateX: 12,
1913
+ translateY: 13,
1914
+ translateZ: 14,
1915
+ scaleX,
1916
+ scaleY,
1917
+ scale: (v) => (scaleX(v) + scaleY(v)) / 2,
1918
+ rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
1919
+ rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
1920
+ rotateZ,
1921
+ rotate: rotateZ,
1922
+ skewX: (v) => radToDeg(Math.atan(v[4])),
1923
+ skewY: (v) => radToDeg(Math.atan(v[1])),
1924
+ skew: (v) => (Math.abs(v[1]) + Math.abs(v[4])) / 2,
1925
+ };
1926
+ function defaultTransformValue(name) {
1927
+ return name.includes("scale") ? 1 : 0;
1928
+ }
1929
+ function parseValueFromTransform(transform, name) {
1930
+ if (!transform || transform === "none") {
1931
+ return defaultTransformValue(name);
1888
1932
  }
1889
- else {
1890
- const matrix = transform.match(/^matrix\((.+)\)$/u);
1891
- if (matrix) {
1892
- return getPosFromMatrix(matrix[1], pos2);
1893
- }
1894
- else {
1895
- return 0;
1896
- }
1933
+ const matrix3dMatch = transform.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);
1934
+ let parsers;
1935
+ let match;
1936
+ if (matrix3dMatch) {
1937
+ parsers = matrix3dParsers;
1938
+ match = matrix3dMatch;
1897
1939
  }
1940
+ else {
1941
+ const matrix2dMatch = transform.match(/^matrix\(([-\d.e\s,]+)\)$/u);
1942
+ parsers = matrix2dParsers;
1943
+ match = matrix2dMatch;
1944
+ }
1945
+ if (!match) {
1946
+ return defaultTransformValue(name);
1947
+ }
1948
+ const valueParser = parsers[name];
1949
+ const values = match[1].split(",").map(convertTransformToNumber);
1950
+ return typeof valueParser === "function"
1951
+ ? valueParser(values)
1952
+ : values[valueParser];
1953
+ }
1954
+ const readTransformValue = (instance, name) => {
1955
+ const { transform = "none" } = getComputedStyle(instance);
1956
+ return parseValueFromTransform(transform, name);
1898
1957
  };
1958
+ function convertTransformToNumber(value) {
1959
+ return parseFloat(value.trim());
1960
+ }
1961
+
1962
+ const isNumOrPxType = (v) => v === number || v === px;
1899
1963
  const transformKeys = new Set(["x", "y", "z"]);
1900
1964
  const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
1901
1965
  function removeNonTranslationalTransform(visualElement) {
@@ -1918,8 +1982,8 @@ const positionalValues = {
1918
1982
  bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
1919
1983
  right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
1920
1984
  // Transform
1921
- x: getTranslateFromMatrix(4, 13),
1922
- y: getTranslateFromMatrix(5, 14),
1985
+ x: (_bbox, { transform }) => parseValueFromTransform(transform, "x"),
1986
+ y: (_bbox, { transform }) => parseValueFromTransform(transform, "y"),
1923
1987
  };
1924
1988
  // Alias translate longform names
1925
1989
  positionalValues.translateX = positionalValues.x;
@@ -3954,7 +4018,7 @@ function updateMotionValuesFromProps(element, next, prev) {
3954
4018
  * and warn against mismatches.
3955
4019
  */
3956
4020
  if (process.env.NODE_ENV === "development") {
3957
- warnOnce(nextValue.version === "12.4.12", `Attempting to mix Motion versions ${nextValue.version} with 12.4.12 may not work as expected.`);
4021
+ warnOnce(nextValue.version === "12.4.13", `Attempting to mix Motion versions ${nextValue.version} with 12.4.13 may not work as expected.`);
3958
4022
  }
3959
4023
  }
3960
4024
  else if (isMotionValue(prevValue)) {
@@ -4894,8 +4958,7 @@ class HTMLVisualElement extends DOMVisualElement {
4894
4958
  }
4895
4959
  readValueFromInstance(instance, key) {
4896
4960
  if (transformProps.has(key)) {
4897
- const defaultType = getDefaultValueType(key);
4898
- return defaultType ? defaultType.default || 0 : 0;
4961
+ return readTransformValue(instance, key);
4899
4962
  }
4900
4963
  else {
4901
4964
  const computedStyle = getComputedStyle$1(instance);
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-Da6xW2BP.js');
7
+ var create = require('./create-DkTZDHiS.js');
8
8
  var motionUtils = require('motion-utils');
9
9
  var motionDom = require('motion-dom');
10
10