framer-motion 12.4.11 → 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-6TyswOY8.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.11";
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.11", `Attempting to mix Motion versions ${nextValue.version} with 12.4.11 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;
@@ -7767,6 +7830,11 @@ function loadFeatures(features) {
7767
7830
  }
7768
7831
  }
7769
7832
 
7833
+ // Fixes https://github.com/motiondivision/motion/issues/2270
7834
+ const getContextWindow = ({ current }) => {
7835
+ return current ? current.ownerDocument.defaultView : null;
7836
+ };
7837
+
7770
7838
  function isRefObject(ref) {
7771
7839
  return (ref &&
7772
7840
  typeof ref === "object" &&
@@ -7777,7 +7845,7 @@ function isRefObject(ref) {
7777
7845
  * @internal
7778
7846
  */
7779
7847
  class PanSession {
7780
- constructor(event, handlers, { transformPagePoint, dragSnapToOrigin = false } = {}) {
7848
+ constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
7781
7849
  /**
7782
7850
  * @internal
7783
7851
  */
@@ -7794,6 +7862,10 @@ class PanSession {
7794
7862
  * @internal
7795
7863
  */
7796
7864
  this.handlers = {};
7865
+ /**
7866
+ * @internal
7867
+ */
7868
+ this.contextWindow = window;
7797
7869
  this.updatePoint = () => {
7798
7870
  if (!(this.lastMoveEvent && this.lastMoveEventInfo))
7799
7871
  return;
@@ -7816,32 +7888,19 @@ class PanSession {
7816
7888
  onMove && onMove(this.lastMoveEvent, info);
7817
7889
  };
7818
7890
  this.handlePointerMove = (event, info) => {
7819
- this.index = getElementIndex(event.currentTarget);
7820
- if (event.target instanceof Element &&
7821
- event.target.hasPointerCapture &&
7822
- event.pointerId !== undefined) {
7823
- try {
7824
- if (!event.target.hasPointerCapture(event.pointerId)) {
7825
- return;
7826
- }
7827
- }
7828
- catch (e) { }
7829
- }
7830
7891
  this.lastMoveEvent = event;
7831
7892
  this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
7832
7893
  // Throttle mouse move event to once per frame
7833
7894
  frame.update(this.updatePoint, true);
7834
7895
  };
7835
7896
  this.handlePointerUp = (event, info) => {
7836
- motionDom.capturePointer(event, "release");
7837
7897
  this.end();
7838
7898
  const { onEnd, onSessionEnd, resumeAnimation } = this.handlers;
7839
7899
  if (this.dragSnapToOrigin)
7840
7900
  resumeAnimation && resumeAnimation();
7841
7901
  if (!(this.lastMoveEvent && this.lastMoveEventInfo))
7842
7902
  return;
7843
- const panInfo = getPanInfo(event.type === "pointercancel" ||
7844
- event.type === "lostpointercapture"
7903
+ const panInfo = getPanInfo(event.type === "pointercancel"
7845
7904
  ? this.lastMoveEventInfo
7846
7905
  : transformPoint(info, this.transformPagePoint), this.history);
7847
7906
  if (this.startEvent && onEnd) {
@@ -7855,6 +7914,7 @@ class PanSession {
7855
7914
  this.dragSnapToOrigin = dragSnapToOrigin;
7856
7915
  this.handlers = handlers;
7857
7916
  this.transformPagePoint = transformPagePoint;
7917
+ this.contextWindow = contextWindow || window;
7858
7918
  const info = extractEventInfo(event);
7859
7919
  const initialInfo = transformPoint(info, this.transformPagePoint);
7860
7920
  const { point } = initialInfo;
@@ -7863,20 +7923,7 @@ class PanSession {
7863
7923
  const { onSessionStart } = handlers;
7864
7924
  onSessionStart &&
7865
7925
  onSessionStart(event, getPanInfo(initialInfo, this.history));
7866
- motionDom.capturePointer(event, "set");
7867
- this.removeListeners = pipe(addPointerEvent(event.currentTarget, "pointermove", this.handlePointerMove), addPointerEvent(event.currentTarget, "pointerup", this.handlePointerUp), addPointerEvent(event.currentTarget, "pointercancel", this.handlePointerUp), addPointerEvent(event.currentTarget, "lostpointercapture", (lostPointerEvent, lostPointerInfo) => {
7868
- const index = getElementIndex(lostPointerEvent.currentTarget);
7869
- /**
7870
- * If the pointer has lost capture because it's moved in the DOM
7871
- * then we need to re-capture it.
7872
- */
7873
- if (index !== this.index) {
7874
- motionDom.capturePointer(lostPointerEvent, "set");
7875
- }
7876
- else {
7877
- this.handlePointerUp(lostPointerEvent, lostPointerInfo);
7878
- }
7879
- }));
7926
+ this.removeListeners = pipe(addPointerEvent(this.contextWindow, "pointermove", this.handlePointerMove), addPointerEvent(this.contextWindow, "pointerup", this.handlePointerUp), addPointerEvent(this.contextWindow, "pointercancel", this.handlePointerUp));
7880
7927
  }
7881
7928
  updateHandlers(handlers) {
7882
7929
  this.handlers = handlers;
@@ -7940,11 +7987,6 @@ function getVelocity(history, timeDelta) {
7940
7987
  }
7941
7988
  return currentVelocity;
7942
7989
  }
7943
- function getElementIndex(element) {
7944
- if (!element.parentNode)
7945
- return -1;
7946
- return Array.from(element.parentNode.children).indexOf(element);
7947
- }
7948
7990
 
7949
7991
  /**
7950
7992
  * Apply constraints to a point. These constraints are both physical along an
@@ -8201,6 +8243,7 @@ class VisualElementDragControls {
8201
8243
  }, {
8202
8244
  transformPagePoint: this.visualElement.getTransformPagePoint(),
8203
8245
  dragSnapToOrigin,
8246
+ contextWindow: getContextWindow(this.visualElement),
8204
8247
  });
8205
8248
  }
8206
8249
  stop(event, info) {
@@ -8566,6 +8609,7 @@ class PanGesture extends Feature {
8566
8609
  onPointerDown(pointerDownEvent) {
8567
8610
  this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), {
8568
8611
  transformPagePoint: this.node.getTransformPagePoint(),
8612
+ contextWindow: getContextWindow(this.node),
8569
8613
  });
8570
8614
  }
8571
8615
  createPanHandlers() {
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.11";
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.11", `Attempting to mix Motion versions ${nextValue.version} with 12.4.11 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-6TyswOY8.js');
7
+ var create = require('./create-DkTZDHiS.js');
8
8
  var motionUtils = require('motion-utils');
9
9
  var motionDom = require('motion-dom');
10
10