framer-motion 11.3.7 → 11.3.9

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.
@@ -27,8 +27,8 @@ function createRenderStep(runNextFrame) {
27
27
  */
28
28
  const toKeepAlive = new WeakSet();
29
29
  let latestFrameData = {
30
- delta: 0,
31
- timestamp: 0,
30
+ delta: 0.0,
31
+ timestamp: 0.0,
32
32
  isProcessing: false,
33
33
  };
34
34
  function triggerCallback(callback) {
@@ -101,8 +101,8 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
101
101
  let runNextFrame = false;
102
102
  let useDefaultElapsed = true;
103
103
  const state = {
104
- delta: 0,
105
- timestamp: 0,
104
+ delta: 0.0,
105
+ timestamp: 0.0,
106
106
  isProcessing: false,
107
107
  };
108
108
  const flagRunNextFrame = () => (runNextFrame = true);
@@ -279,7 +279,7 @@ class MotionValue {
279
279
  * This will be replaced by the build step with the latest version number.
280
280
  * When MotionValues are provided to motion components, warn if versions are mixed.
281
281
  */
282
- this.version = "11.3.7";
282
+ this.version = "11.3.9";
283
283
  /**
284
284
  * Tracks whether this value can output a velocity. Currently this is only true
285
285
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -3684,12 +3684,6 @@ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
3684
3684
  return newValues;
3685
3685
  }
3686
3686
 
3687
- const createAxis = () => ({ min: 0, max: 0 });
3688
- const createBox = () => ({
3689
- x: createAxis(),
3690
- y: createAxis(),
3691
- });
3692
-
3693
3687
  const isBrowser = typeof document !== "undefined";
3694
3688
 
3695
3689
  // Does this device prefer reduced motion? Returns `null` server-side.
@@ -3758,7 +3752,7 @@ function updateMotionValuesFromProps(element, next, prev) {
3758
3752
  * and warn against mismatches.
3759
3753
  */
3760
3754
  if (process.env.NODE_ENV === "development") {
3761
- warnOnce(nextValue.version === "11.3.7", `Attempting to mix Framer Motion versions ${nextValue.version} with 11.3.7 may not work as expected.`);
3755
+ warnOnce(nextValue.version === "11.3.9", `Attempting to mix Framer Motion versions ${nextValue.version} with 11.3.9 may not work as expected.`);
3762
3756
  }
3763
3757
  }
3764
3758
  else if (isMotionValue(prevValue)) {
@@ -3833,6 +3827,12 @@ const valueTypes = [...dimensionValueTypes, color, complex];
3833
3827
  */
3834
3828
  const findValueType = (v) => valueTypes.find(testValueType(v));
3835
3829
 
3830
+ const createAxis = () => ({ min: 0, max: 0 });
3831
+ const createBox = () => ({
3832
+ x: createAxis(),
3833
+ y: createAxis(),
3834
+ });
3835
+
3836
3836
  const propEventHandlers = [
3837
3837
  "AnimationStart",
3838
3838
  "AnimationComplete",
@@ -4594,6 +4594,7 @@ class SVGVisualElement extends DOMVisualElement {
4594
4594
  super(...arguments);
4595
4595
  this.type = "svg";
4596
4596
  this.isSVGTag = false;
4597
+ this.measureInstanceViewportBox = createBox;
4597
4598
  }
4598
4599
  getBaseTargetFromProps(props, key) {
4599
4600
  return props[key];
@@ -4606,9 +4607,6 @@ class SVGVisualElement extends DOMVisualElement {
4606
4607
  key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
4607
4608
  return instance.getAttribute(key);
4608
4609
  }
4609
- measureInstanceViewportBox() {
4610
- return createBox();
4611
- }
4612
4610
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
4613
4611
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
4614
4612
  }
package/dist/cjs/index.js CHANGED
@@ -77,8 +77,8 @@ function createRenderStep(runNextFrame) {
77
77
  */
78
78
  const toKeepAlive = new WeakSet();
79
79
  let latestFrameData = {
80
- delta: 0,
81
- timestamp: 0,
80
+ delta: 0.0,
81
+ timestamp: 0.0,
82
82
  isProcessing: false,
83
83
  };
84
84
  function triggerCallback(callback) {
@@ -151,8 +151,8 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
151
151
  let runNextFrame = false;
152
152
  let useDefaultElapsed = true;
153
153
  const state = {
154
- delta: 0,
155
- timestamp: 0,
154
+ delta: 0.0,
155
+ timestamp: 0.0,
156
156
  isProcessing: false,
157
157
  };
158
158
  const flagRunNextFrame = () => (runNextFrame = true);
@@ -314,7 +314,6 @@ function createProjectionNode$1(visualElement, props, ProjectionNodeConstructor,
314
314
  layout,
315
315
  alwaysMeasureLayout: Boolean(drag) || (dragConstraints && isRefObject(dragConstraints)),
316
316
  visualElement,
317
- scheduleRender: () => visualElement.scheduleRender(),
318
317
  /**
319
318
  * TODO: Update options in an effect. This could be tricky as it'll be too late
320
319
  * to update by the time layout animations run.
@@ -4814,7 +4813,7 @@ class MotionValue {
4814
4813
  * This will be replaced by the build step with the latest version number.
4815
4814
  * When MotionValues are provided to motion components, warn if versions are mixed.
4816
4815
  */
4817
- this.version = "11.3.7";
4816
+ this.version = "11.3.9";
4818
4817
  /**
4819
4818
  * Tracks whether this value can output a velocity. Currently this is only true
4820
4819
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -5911,12 +5910,12 @@ function calcAxisDelta(delta, source, target, origin = 0.5) {
5911
5910
  mixNumber$1(target.min, target.max, delta.origin) - delta.originPoint;
5912
5911
  if ((delta.scale >= SCALE_MIN && delta.scale <= SCALE_MAX) ||
5913
5912
  isNaN(delta.scale)) {
5914
- delta.scale = 1;
5913
+ delta.scale = 1.0;
5915
5914
  }
5916
5915
  if ((delta.translate >= TRANSLATE_MIN &&
5917
5916
  delta.translate <= TRANSLATE_MAX) ||
5918
5917
  isNaN(delta.translate)) {
5919
- delta.translate = 0;
5918
+ delta.translate = 0.0;
5920
5919
  }
5921
5920
  }
5922
5921
  function calcBoxDelta(delta, source, target, origin) {
@@ -6171,6 +6170,8 @@ function applyBoxDelta(box, { x, y }) {
6171
6170
  applyAxisDelta(box.x, x.translate, x.scale, x.originPoint);
6172
6171
  applyAxisDelta(box.y, y.translate, y.scale, y.originPoint);
6173
6172
  }
6173
+ const TREE_SCALE_SNAP_MIN = 0.999999999999;
6174
+ const TREE_SCALE_SNAP_MAX = 1.0000000000001;
6174
6175
  /**
6175
6176
  * Apply a tree of deltas to a box. We do this to calculate the effect of all the transforms
6176
6177
  * in a tree upon our box before then calculating how to project it into our desired viewport-relative box
@@ -6222,13 +6223,14 @@ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
6222
6223
  * Snap tree scale back to 1 if it's within a non-perceivable threshold.
6223
6224
  * This will help reduce useless scales getting rendered.
6224
6225
  */
6225
- treeScale.x = snapToDefault(treeScale.x);
6226
- treeScale.y = snapToDefault(treeScale.y);
6227
- }
6228
- function snapToDefault(scale) {
6229
- if (Number.isInteger(scale))
6230
- return scale;
6231
- return scale > 1.0000000000001 || scale < 0.999999999999 ? scale : 1;
6226
+ if (treeScale.x < TREE_SCALE_SNAP_MAX &&
6227
+ treeScale.x > TREE_SCALE_SNAP_MIN) {
6228
+ treeScale.x = 1.0;
6229
+ }
6230
+ if (treeScale.y < TREE_SCALE_SNAP_MAX &&
6231
+ treeScale.y > TREE_SCALE_SNAP_MIN) {
6232
+ treeScale.y = 1.0;
6233
+ }
6232
6234
  }
6233
6235
  function translateAxis(axis, distance) {
6234
6236
  axis.min = axis.min + distance;
@@ -6907,6 +6909,17 @@ function copyBoxInto(box, originBox) {
6907
6909
  copyAxisInto(box.x, originBox.x);
6908
6910
  copyAxisInto(box.y, originBox.y);
6909
6911
  }
6912
+ /**
6913
+ * Reset a delta to the provided origin box.
6914
+ *
6915
+ * This is a mutative operation.
6916
+ */
6917
+ function copyAxisDeltaInto(delta, originDelta) {
6918
+ delta.translate = originDelta.translate;
6919
+ delta.scale = originDelta.scale;
6920
+ delta.originPoint = originDelta.originPoint;
6921
+ delta.origin = originDelta.origin;
6922
+ }
6910
6923
 
6911
6924
  /**
6912
6925
  * Remove a delta from a point. This is essentially the steps of applyPointDelta in reverse
@@ -6963,21 +6976,27 @@ function isAxisDeltaZero(delta) {
6963
6976
  function isDeltaZero(delta) {
6964
6977
  return isAxisDeltaZero(delta.x) && isAxisDeltaZero(delta.y);
6965
6978
  }
6979
+ function axisEquals(a, b) {
6980
+ return a.min === b.min && a.max === b.max;
6981
+ }
6966
6982
  function boxEquals(a, b) {
6967
- return (a.x.min === b.x.min &&
6968
- a.x.max === b.x.max &&
6969
- a.y.min === b.y.min &&
6970
- a.y.max === b.y.max);
6983
+ return axisEquals(a.x, b.x) && axisEquals(a.y, b.y);
6984
+ }
6985
+ function axisEqualsRounded(a, b) {
6986
+ return (Math.round(a.min) === Math.round(b.min) &&
6987
+ Math.round(a.max) === Math.round(b.max));
6971
6988
  }
6972
6989
  function boxEqualsRounded(a, b) {
6973
- return (Math.round(a.x.min) === Math.round(b.x.min) &&
6974
- Math.round(a.x.max) === Math.round(b.x.max) &&
6975
- Math.round(a.y.min) === Math.round(b.y.min) &&
6976
- Math.round(a.y.max) === Math.round(b.y.max));
6990
+ return axisEqualsRounded(a.x, b.x) && axisEqualsRounded(a.y, b.y);
6977
6991
  }
6978
6992
  function aspectRatio(box) {
6979
6993
  return calcLength(box.x) / calcLength(box.y);
6980
6994
  }
6995
+ function axisDeltaEquals(a, b) {
6996
+ return (a.translate === b.translate &&
6997
+ a.scale === b.scale &&
6998
+ a.originPoint === b.originPoint);
6999
+ }
6981
7000
 
6982
7001
  class NodeStack {
6983
7002
  constructor() {
@@ -7192,12 +7211,6 @@ function delay(callback, timeout) {
7192
7211
  return () => cancelFrame(checkElapsed);
7193
7212
  }
7194
7213
 
7195
- function record(data) {
7196
- if (window.MotionDebug) {
7197
- window.MotionDebug.record(data);
7198
- }
7199
- }
7200
-
7201
7214
  function resolveElements(elements, scope, selectorCache) {
7202
7215
  var _a;
7203
7216
  if (typeof elements === "string") {
@@ -7267,7 +7280,7 @@ function updateMotionValuesFromProps(element, next, prev) {
7267
7280
  * and warn against mismatches.
7268
7281
  */
7269
7282
  if (process.env.NODE_ENV === "development") {
7270
- warnOnce(nextValue.version === "11.3.7", `Attempting to mix Framer Motion versions ${nextValue.version} with 11.3.7 may not work as expected.`);
7283
+ warnOnce(nextValue.version === "11.3.9", `Attempting to mix Framer Motion versions ${nextValue.version} with 11.3.9 may not work as expected.`);
7271
7284
  }
7272
7285
  }
7273
7286
  else if (isMotionValue(prevValue)) {
@@ -7824,6 +7837,7 @@ class SVGVisualElement extends DOMVisualElement {
7824
7837
  super(...arguments);
7825
7838
  this.type = "svg";
7826
7839
  this.isSVGTag = false;
7840
+ this.measureInstanceViewportBox = createBox;
7827
7841
  }
7828
7842
  getBaseTargetFromProps(props, key) {
7829
7843
  return props[key];
@@ -7836,9 +7850,6 @@ class SVGVisualElement extends DOMVisualElement {
7836
7850
  key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
7837
7851
  return instance.getAttribute(key);
7838
7852
  }
7839
- measureInstanceViewportBox() {
7840
- return createBox();
7841
- }
7842
7853
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
7843
7854
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
7844
7855
  }
@@ -8885,6 +8896,13 @@ const cancelSync = stepsOrder.reduce((acc, key) => {
8885
8896
  return acc;
8886
8897
  }, {});
8887
8898
 
8899
+ const metrics = {
8900
+ type: "projectionFrame",
8901
+ totalNodes: 0,
8902
+ resolvedTargetDeltas: 0,
8903
+ recalculatedProjection: 0,
8904
+ };
8905
+ const isDebug = typeof window !== "undefined" && window.MotionDebug !== undefined;
8888
8906
  const transformAxes = ["", "X", "Y", "Z"];
8889
8907
  const hiddenVisibility = { visibility: "hidden" };
8890
8908
  /**
@@ -8893,16 +8911,6 @@ const hiddenVisibility = { visibility: "hidden" };
8893
8911
  */
8894
8912
  const animationTarget = 1000;
8895
8913
  let id$1 = 0;
8896
- /**
8897
- * Use a mutable data object for debug data so as to not create a new
8898
- * object every frame.
8899
- */
8900
- const projectionFrameData = {
8901
- type: "projectionFrame",
8902
- totalNodes: 0,
8903
- resolvedTargetDeltas: 0,
8904
- recalculatedProjection: 0,
8905
- };
8906
8914
  function resetDistortingTransform(key, visualElement, values, sharedAnimationValues) {
8907
8915
  const { latestValues } = visualElement;
8908
8916
  // Record the distorting transform and then temporarily set it to 0
@@ -9050,16 +9058,24 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9050
9058
  * Reset debug counts. Manually resetting rather than creating a new
9051
9059
  * object each frame.
9052
9060
  */
9053
- projectionFrameData.totalNodes =
9054
- projectionFrameData.resolvedTargetDeltas =
9055
- projectionFrameData.recalculatedProjection =
9056
- 0;
9061
+ if (isDebug) {
9062
+ metrics.totalNodes =
9063
+ metrics.resolvedTargetDeltas =
9064
+ metrics.recalculatedProjection =
9065
+ 0;
9066
+ }
9057
9067
  this.nodes.forEach(propagateDirtyNodes);
9058
9068
  this.nodes.forEach(resolveTargetDelta);
9059
9069
  this.nodes.forEach(calcProjection);
9060
9070
  this.nodes.forEach(cleanDirtyNodes);
9061
- record(projectionFrameData);
9071
+ if (isDebug) {
9072
+ window.MotionDebug.record(metrics);
9073
+ }
9062
9074
  };
9075
+ /**
9076
+ * Frame calculations
9077
+ */
9078
+ this.resolvedRelativeTargetAt = 0.0;
9063
9079
  this.hasProjected = false;
9064
9080
  this.isVisible = true;
9065
9081
  this.animationProgress = 0;
@@ -9589,7 +9605,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9589
9605
  (isShared && this.isSharedProjectionDirty) ||
9590
9606
  this.isProjectionDirty ||
9591
9607
  ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isProjectionDirty) ||
9592
- this.attemptToResolveRelativeTarget);
9608
+ this.attemptToResolveRelativeTarget ||
9609
+ this.root.updateBlockedByResize);
9593
9610
  if (canSkip)
9594
9611
  return;
9595
9612
  const { layout, layoutId } = this.options;
@@ -9688,7 +9705,9 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9688
9705
  /**
9689
9706
  * Increase debug counter for resolved target deltas
9690
9707
  */
9691
- projectionFrameData.resolvedTargetDeltas++;
9708
+ if (isDebug) {
9709
+ metrics.resolvedTargetDeltas++;
9710
+ }
9692
9711
  }
9693
9712
  getClosestProjectingParent() {
9694
9713
  if (!this.parent ||
@@ -9783,18 +9802,19 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9783
9802
  * projecting, we want to remove the stored transform and schedule
9784
9803
  * a render to ensure the elements reflect the removed transform.
9785
9804
  */
9786
- if (this.projectionTransform) {
9787
- this.projectionDelta = createDelta();
9788
- this.projectionTransform = "none";
9805
+ if (this.prevProjectionDelta) {
9806
+ this.createProjectionDeltas();
9789
9807
  this.scheduleRender();
9790
9808
  }
9791
9809
  return;
9792
9810
  }
9793
- if (!this.projectionDelta) {
9794
- this.projectionDelta = createDelta();
9795
- this.projectionDeltaWithTransform = createDelta();
9811
+ if (!this.projectionDelta || !this.prevProjectionDelta) {
9812
+ this.createProjectionDeltas();
9813
+ }
9814
+ else {
9815
+ copyAxisDeltaInto(this.prevProjectionDelta.x, this.projectionDelta.x);
9816
+ copyAxisDeltaInto(this.prevProjectionDelta.y, this.projectionDelta.y);
9796
9817
  }
9797
- const prevProjectionTransform = this.projectionTransform;
9798
9818
  /**
9799
9819
  * Update the delta between the corrected box and the target box before user-set transforms were applied.
9800
9820
  * This will allow us to calculate the corrected borderRadius and boxShadow to compensate
@@ -9805,10 +9825,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9805
9825
  * layout reprojection or the final bounding box.
9806
9826
  */
9807
9827
  calcBoxDelta(this.projectionDelta, this.layoutCorrected, target, this.latestValues);
9808
- this.projectionTransform = buildProjectionTransform(this.projectionDelta, this.treeScale);
9809
- if (this.projectionTransform !== prevProjectionTransform ||
9810
- this.treeScale.x !== prevTreeScaleX ||
9811
- this.treeScale.y !== prevTreeScaleY) {
9828
+ if (this.treeScale.x !== prevTreeScaleX ||
9829
+ this.treeScale.y !== prevTreeScaleY ||
9830
+ !axisDeltaEquals(this.projectionDelta.x, this.prevProjectionDelta.x) ||
9831
+ !axisDeltaEquals(this.projectionDelta.y, this.prevProjectionDelta.y)) {
9812
9832
  this.hasProjected = true;
9813
9833
  this.scheduleRender();
9814
9834
  this.notifyListeners("projectionUpdate", target);
@@ -9816,7 +9836,9 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9816
9836
  /**
9817
9837
  * Increase debug counter for recalculated projections
9818
9838
  */
9819
- projectionFrameData.recalculatedProjection++;
9839
+ if (isDebug) {
9840
+ metrics.recalculatedProjection++;
9841
+ }
9820
9842
  }
9821
9843
  hide() {
9822
9844
  this.isVisible = false;
@@ -9827,7 +9849,8 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9827
9849
  // TODO: Schedule render
9828
9850
  }
9829
9851
  scheduleRender(notifyAll = true) {
9830
- this.options.scheduleRender && this.options.scheduleRender();
9852
+ var _a;
9853
+ (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.scheduleRender();
9831
9854
  if (notifyAll) {
9832
9855
  const stack = this.getStack();
9833
9856
  stack && stack.scheduleRender();
@@ -9836,6 +9859,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9836
9859
  this.resumingFrom = undefined;
9837
9860
  }
9838
9861
  }
9862
+ createProjectionDeltas() {
9863
+ this.prevProjectionDelta = createDelta();
9864
+ this.projectionDelta = createDelta();
9865
+ this.projectionDeltaWithTransform = createDelta();
9866
+ }
9839
9867
  setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false) {
9840
9868
  const snapshot = this.snapshot;
9841
9869
  const snapshotLatestValues = snapshot
@@ -10309,7 +10337,9 @@ function propagateDirtyNodes(node) {
10309
10337
  /**
10310
10338
  * Increase debug counter for nodes encountered this frame
10311
10339
  */
10312
- projectionFrameData.totalNodes++;
10340
+ if (isDebug) {
10341
+ metrics.totalNodes++;
10342
+ }
10313
10343
  if (!node.parent)
10314
10344
  return;
10315
10345
  /**
@@ -12244,10 +12274,11 @@ function startOptimizedAppearAnimation(element, name, keyframes, options, onRead
12244
12274
 
12245
12275
  const createObject = () => ({});
12246
12276
  class StateVisualElement extends VisualElement {
12247
- build() { }
12248
- measureInstanceViewportBox() {
12249
- return createBox();
12277
+ constructor() {
12278
+ super(...arguments);
12279
+ this.measureInstanceViewportBox = createBox;
12250
12280
  }
12281
+ build() { }
12251
12282
  resetTransform() { }
12252
12283
  restoreTransform() { }
12253
12284
  removeValueFromRenderState() { }