motion 12.8.0 → 12.8.2

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.
package/dist/cjs/index.js CHANGED
@@ -3776,7 +3776,7 @@ class MotionValue {
3776
3776
  * This will be replaced by the build step with the latest version number.
3777
3777
  * When MotionValues are provided to motion components, warn if versions are mixed.
3778
3778
  */
3779
- this.version = "12.8.0";
3779
+ this.version = "12.8.1";
3780
3780
  /**
3781
3781
  * Tracks whether this value can output a velocity. Currently this is only true
3782
3782
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -3920,8 +3920,6 @@ class MotionValue {
3920
3920
  * @public
3921
3921
  */
3922
3922
  set(v, render = true) {
3923
- if (v === "none")
3924
- console.trace();
3925
3923
  if (!render || !this.passiveEffect) {
3926
3924
  this.updateAndNotify(v, render);
3927
3925
  }
@@ -5239,7 +5237,7 @@ function updateMotionValuesFromProps(element, next, prev) {
5239
5237
  * and warn against mismatches.
5240
5238
  */
5241
5239
  if (process.env.NODE_ENV === "development") {
5242
- warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
5240
+ warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
5243
5241
  }
5244
5242
  }
5245
5243
  else if (isMotionValue(prevValue)) {
@@ -5372,8 +5370,7 @@ class VisualElement {
5372
5370
  frame.render(this.render, false, true);
5373
5371
  }
5374
5372
  };
5375
- const { latestValues, renderState, onUpdate } = visualState;
5376
- this.onUpdate = onUpdate;
5373
+ const { latestValues, renderState } = visualState;
5377
5374
  this.latestValues = latestValues;
5378
5375
  this.baseTarget = { ...latestValues };
5379
5376
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -5575,7 +5572,6 @@ class VisualElement {
5575
5572
  if (this.handleChildMotionValue) {
5576
5573
  this.handleChildMotionValue();
5577
5574
  }
5578
- this.onUpdate && this.onUpdate(this);
5579
5575
  }
5580
5576
  getProps() {
5581
5577
  return this.props;
@@ -5917,25 +5913,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
5917
5913
  attrs[keys.array] = `${pathLength} ${pathSpacing}`;
5918
5914
  }
5919
5915
 
5920
- function calcOrigin(origin, offset, size) {
5921
- return typeof origin === "string"
5922
- ? origin
5923
- : px.transform(offset + size * origin);
5924
- }
5925
- /**
5926
- * The SVG transform origin defaults are different to CSS and is less intuitive,
5927
- * so we use the measured dimensions of the SVG to reconcile these.
5928
- */
5929
- function calcSVGTransformOrigin(dimensions, originX, originY) {
5930
- const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
5931
- const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
5932
- return `${pxOriginX} ${pxOriginY}`;
5933
- }
5934
-
5935
5916
  /**
5936
5917
  * Build SVG visual attrbutes, like cx and style.transform
5937
5918
  */
5938
- function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
5919
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
5939
5920
  // This is object creation, which we try to avoid per-frame.
5940
5921
  ...latest }, isSVGTag, transformTemplate) {
5941
5922
  buildHTMLStyles(state, latest, transformTemplate);
@@ -5951,20 +5932,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
5951
5932
  }
5952
5933
  state.attrs = state.style;
5953
5934
  state.style = {};
5954
- const { attrs, style, dimensions } = state;
5935
+ const { attrs, style } = state;
5955
5936
  /**
5956
- * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
5957
- * and copy it into style.
5937
+ * However, we apply transforms as CSS transforms.
5938
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
5958
5939
  */
5959
5940
  if (attrs.transform) {
5960
- if (dimensions)
5961
- style.transform = attrs.transform;
5941
+ style.transform = attrs.transform;
5962
5942
  delete attrs.transform;
5963
5943
  }
5964
- // Parse transformOrigin
5965
- if (dimensions &&
5966
- (originX !== undefined || originY !== undefined || style.transform)) {
5967
- style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
5944
+ if (style.transform || attrs.transformOrigin) {
5945
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
5946
+ delete attrs.transformOrigin;
5947
+ }
5948
+ if (style.transform) {
5949
+ /**
5950
+ * SVG's element transform-origin uses its own median as a reference.
5951
+ * Therefore, transformBox becomes a fill-box
5952
+ */
5953
+ style.transformBox = "fill-box";
5954
+ delete attrs.transformBox;
5968
5955
  }
5969
5956
  // Render attrX/attrY/attrScale as attributes
5970
5957
  if (attrX !== undefined)
@@ -6010,24 +5997,6 @@ const camelCaseAttributes = new Set([
6010
5997
 
6011
5998
  const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
6012
5999
 
6013
- function updateSVGDimensions(instance, renderState) {
6014
- try {
6015
- renderState.dimensions =
6016
- typeof instance.getBBox === "function"
6017
- ? instance.getBBox()
6018
- : instance.getBoundingClientRect();
6019
- }
6020
- catch (e) {
6021
- // Most likely trying to measure an unrendered element under Firefox
6022
- renderState.dimensions = {
6023
- x: 0,
6024
- y: 0,
6025
- width: 0,
6026
- height: 0,
6027
- };
6028
- }
6029
- }
6030
-
6031
6000
  function renderHTML(element, { style, vars }, styleProp, projection) {
6032
6001
  Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
6033
6002
  // Loop over any CSS variables and assign those.
@@ -6087,11 +6056,6 @@ class SVGVisualElement extends DOMVisualElement {
6087
6056
  this.type = "svg";
6088
6057
  this.isSVGTag = false;
6089
6058
  this.measureInstanceViewportBox = createBox;
6090
- this.updateDimensions = () => {
6091
- if (this.current && !this.renderState.dimensions) {
6092
- updateSVGDimensions(this.current, this.renderState);
6093
- }
6094
- };
6095
6059
  }
6096
6060
  getBaseTargetFromProps(props, key) {
6097
6061
  return props[key];
@@ -6107,11 +6071,6 @@ class SVGVisualElement extends DOMVisualElement {
6107
6071
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
6108
6072
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
6109
6073
  }
6110
- onBindTransform() {
6111
- if (this.current && !this.renderState.dimensions) {
6112
- frame.postRender(this.updateDimensions);
6113
- }
6114
- }
6115
6074
  build(renderState, latestValues, props) {
6116
6075
  buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
6117
6076
  }
@@ -3449,7 +3449,7 @@ class MotionValue {
3449
3449
  * This will be replaced by the build step with the latest version number.
3450
3450
  * When MotionValues are provided to motion components, warn if versions are mixed.
3451
3451
  */
3452
- this.version = "12.8.0";
3452
+ this.version = "12.8.1";
3453
3453
  /**
3454
3454
  * Tracks whether this value can output a velocity. Currently this is only true
3455
3455
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -3593,8 +3593,6 @@ class MotionValue {
3593
3593
  * @public
3594
3594
  */
3595
3595
  set(v, render = true) {
3596
- if (v === "none")
3597
- console.trace();
3598
3596
  if (!render || !this.passiveEffect) {
3599
3597
  this.updateAndNotify(v, render);
3600
3598
  }
@@ -5085,7 +5083,7 @@ function calcViewportConstraints(layoutBox, constraintsBox) {
5085
5083
  * Calculate a transform origin relative to the source axis, between 0-1, that results
5086
5084
  * in an asthetically pleasing scale/transform needed to project from source to target.
5087
5085
  */
5088
- function calcOrigin$1(source, target) {
5086
+ function calcOrigin(source, target) {
5089
5087
  let origin = 0.5;
5090
5088
  const sourceLength = calcLength(source);
5091
5089
  const targetLength = calcLength(target);
@@ -5479,7 +5477,7 @@ class VisualElementDragControls {
5479
5477
  const axisValue = this.getAxisMotionValue(axis);
5480
5478
  if (axisValue && this.constraints !== false) {
5481
5479
  const latest = axisValue.get();
5482
- boxProgress[axis] = calcOrigin$1({ min: latest, max: latest }, this.constraints[axis]);
5480
+ boxProgress[axis] = calcOrigin({ min: latest, max: latest }, this.constraints[axis]);
5483
5481
  }
5484
5482
  });
5485
5483
  /**
@@ -8832,25 +8830,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
8832
8830
  attrs[keys.array] = `${pathLength} ${pathSpacing}`;
8833
8831
  }
8834
8832
 
8835
- function calcOrigin(origin, offset, size) {
8836
- return typeof origin === "string"
8837
- ? origin
8838
- : px.transform(offset + size * origin);
8839
- }
8840
- /**
8841
- * The SVG transform origin defaults are different to CSS and is less intuitive,
8842
- * so we use the measured dimensions of the SVG to reconcile these.
8843
- */
8844
- function calcSVGTransformOrigin(dimensions, originX, originY) {
8845
- const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
8846
- const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
8847
- return `${pxOriginX} ${pxOriginY}`;
8848
- }
8849
-
8850
8833
  /**
8851
8834
  * Build SVG visual attrbutes, like cx and style.transform
8852
8835
  */
8853
- function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
8836
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
8854
8837
  // This is object creation, which we try to avoid per-frame.
8855
8838
  ...latest }, isSVGTag, transformTemplate) {
8856
8839
  buildHTMLStyles(state, latest, transformTemplate);
@@ -8866,20 +8849,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
8866
8849
  }
8867
8850
  state.attrs = state.style;
8868
8851
  state.style = {};
8869
- const { attrs, style, dimensions } = state;
8852
+ const { attrs, style } = state;
8870
8853
  /**
8871
- * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
8872
- * and copy it into style.
8854
+ * However, we apply transforms as CSS transforms.
8855
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
8873
8856
  */
8874
8857
  if (attrs.transform) {
8875
- if (dimensions)
8876
- style.transform = attrs.transform;
8858
+ style.transform = attrs.transform;
8877
8859
  delete attrs.transform;
8878
8860
  }
8879
- // Parse transformOrigin
8880
- if (dimensions &&
8881
- (originX !== undefined || originY !== undefined || style.transform)) {
8882
- style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
8861
+ if (style.transform || attrs.transformOrigin) {
8862
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
8863
+ delete attrs.transformOrigin;
8864
+ }
8865
+ if (style.transform) {
8866
+ /**
8867
+ * SVG's element transform-origin uses its own median as a reference.
8868
+ * Therefore, transformBox becomes a fill-box
8869
+ */
8870
+ style.transformBox = "fill-box";
8871
+ delete attrs.transformBox;
8883
8872
  }
8884
8873
  // Render attrX/attrY/attrScale as attributes
8885
8874
  if (attrX !== undefined)
@@ -8958,20 +8947,11 @@ function useConstant(init) {
8958
8947
  return ref.current;
8959
8948
  }
8960
8949
 
8961
- function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
8950
+ function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
8962
8951
  const state = {
8963
8952
  latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
8964
8953
  renderState: createRenderState(),
8965
8954
  };
8966
- if (onUpdate) {
8967
- /**
8968
- * onMount works without the VisualElement because it could be
8969
- * called before the VisualElement payload has been hydrated.
8970
- * (e.g. if someone is using m components <m.circle />)
8971
- */
8972
- state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
8973
- state.onUpdate = (visualElement) => onUpdate(visualElement);
8974
- }
8975
8955
  return state;
8976
8956
  }
8977
8957
  const makeUseVisualState = (config) => (props, isStatic) => {
@@ -9058,68 +9038,6 @@ const htmlMotionConfig = {
9058
9038
  }),
9059
9039
  };
9060
9040
 
9061
- function updateSVGDimensions(instance, renderState) {
9062
- try {
9063
- renderState.dimensions =
9064
- typeof instance.getBBox === "function"
9065
- ? instance.getBBox()
9066
- : instance.getBoundingClientRect();
9067
- }
9068
- catch (e) {
9069
- // Most likely trying to measure an unrendered element under Firefox
9070
- renderState.dimensions = {
9071
- x: 0,
9072
- y: 0,
9073
- width: 0,
9074
- height: 0,
9075
- };
9076
- }
9077
- }
9078
-
9079
- function renderHTML(element, { style, vars }, styleProp, projection) {
9080
- Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
9081
- // Loop over any CSS variables and assign those.
9082
- for (const key in vars) {
9083
- element.style.setProperty(key, vars[key]);
9084
- }
9085
- }
9086
-
9087
- /**
9088
- * A set of attribute names that are always read/written as camel case.
9089
- */
9090
- const camelCaseAttributes = new Set([
9091
- "baseFrequency",
9092
- "diffuseConstant",
9093
- "kernelMatrix",
9094
- "kernelUnitLength",
9095
- "keySplines",
9096
- "keyTimes",
9097
- "limitingConeAngle",
9098
- "markerHeight",
9099
- "markerWidth",
9100
- "numOctaves",
9101
- "targetX",
9102
- "targetY",
9103
- "surfaceScale",
9104
- "specularConstant",
9105
- "specularExponent",
9106
- "stdDeviation",
9107
- "tableValues",
9108
- "viewBox",
9109
- "gradientTransform",
9110
- "pathLength",
9111
- "startOffset",
9112
- "textLength",
9113
- "lengthAdjust",
9114
- ]);
9115
-
9116
- function renderSVG(element, renderState, _styleProp, projection) {
9117
- renderHTML(element, renderState, undefined, projection);
9118
- for (const key in renderState.attrs) {
9119
- element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
9120
- }
9121
- }
9122
-
9123
9041
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
9124
9042
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
9125
9043
  for (const key in props) {
@@ -9134,49 +9052,10 @@ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
9134
9052
  return newValues;
9135
9053
  }
9136
9054
 
9137
- const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
9138
9055
  const svgMotionConfig = {
9139
9056
  useVisualState: makeUseVisualState({
9140
9057
  scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
9141
9058
  createRenderState: createSvgRenderState,
9142
- onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
9143
- if (!current)
9144
- return;
9145
- let hasTransform = !!props.drag;
9146
- if (!hasTransform) {
9147
- for (const key in latestValues) {
9148
- if (transformProps.has(key)) {
9149
- hasTransform = true;
9150
- break;
9151
- }
9152
- }
9153
- }
9154
- if (!hasTransform)
9155
- return;
9156
- let needsMeasure = !prevProps;
9157
- if (prevProps) {
9158
- /**
9159
- * Check the layout props for changes, if any are found we need to
9160
- * measure the element again.
9161
- */
9162
- for (let i = 0; i < layoutProps.length; i++) {
9163
- const key = layoutProps[i];
9164
- if (props[key] !==
9165
- prevProps[key]) {
9166
- needsMeasure = true;
9167
- }
9168
- }
9169
- }
9170
- if (!needsMeasure)
9171
- return;
9172
- frame.read(() => {
9173
- updateSVGDimensions(current, renderState);
9174
- frame.render(() => {
9175
- buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
9176
- renderSVG(current, renderState);
9177
- });
9178
- });
9179
- },
9180
9059
  }),
9181
9060
  };
9182
9061
 
@@ -9232,7 +9111,7 @@ function updateMotionValuesFromProps(element, next, prev) {
9232
9111
  * and warn against mismatches.
9233
9112
  */
9234
9113
  if (process.env.NODE_ENV === "development") {
9235
- warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
9114
+ warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
9236
9115
  }
9237
9116
  }
9238
9117
  else if (isMotionValue(prevValue)) {
@@ -9365,8 +9244,7 @@ class VisualElement {
9365
9244
  frame.render(this.render, false, true);
9366
9245
  }
9367
9246
  };
9368
- const { latestValues, renderState, onUpdate } = visualState;
9369
- this.onUpdate = onUpdate;
9247
+ const { latestValues, renderState } = visualState;
9370
9248
  this.latestValues = latestValues;
9371
9249
  this.baseTarget = { ...latestValues };
9372
9250
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -9568,7 +9446,6 @@ class VisualElement {
9568
9446
  if (this.handleChildMotionValue) {
9569
9447
  this.handleChildMotionValue();
9570
9448
  }
9571
- this.onUpdate && this.onUpdate(this);
9572
9449
  }
9573
9450
  getProps() {
9574
9451
  return this.props;
@@ -9766,6 +9643,14 @@ class DOMVisualElement extends VisualElement {
9766
9643
  }
9767
9644
  }
9768
9645
 
9646
+ function renderHTML(element, { style, vars }, styleProp, projection) {
9647
+ Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
9648
+ // Loop over any CSS variables and assign those.
9649
+ for (const key in vars) {
9650
+ element.style.setProperty(key, vars[key]);
9651
+ }
9652
+ }
9653
+
9769
9654
  function getComputedStyle$1(element) {
9770
9655
  return window.getComputedStyle(element);
9771
9656
  }
@@ -9798,17 +9683,48 @@ class HTMLVisualElement extends DOMVisualElement {
9798
9683
  }
9799
9684
  }
9800
9685
 
9686
+ /**
9687
+ * A set of attribute names that are always read/written as camel case.
9688
+ */
9689
+ const camelCaseAttributes = new Set([
9690
+ "baseFrequency",
9691
+ "diffuseConstant",
9692
+ "kernelMatrix",
9693
+ "kernelUnitLength",
9694
+ "keySplines",
9695
+ "keyTimes",
9696
+ "limitingConeAngle",
9697
+ "markerHeight",
9698
+ "markerWidth",
9699
+ "numOctaves",
9700
+ "targetX",
9701
+ "targetY",
9702
+ "surfaceScale",
9703
+ "specularConstant",
9704
+ "specularExponent",
9705
+ "stdDeviation",
9706
+ "tableValues",
9707
+ "viewBox",
9708
+ "gradientTransform",
9709
+ "pathLength",
9710
+ "startOffset",
9711
+ "textLength",
9712
+ "lengthAdjust",
9713
+ ]);
9714
+
9715
+ function renderSVG(element, renderState, _styleProp, projection) {
9716
+ renderHTML(element, renderState, undefined, projection);
9717
+ for (const key in renderState.attrs) {
9718
+ element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
9719
+ }
9720
+ }
9721
+
9801
9722
  class SVGVisualElement extends DOMVisualElement {
9802
9723
  constructor() {
9803
9724
  super(...arguments);
9804
9725
  this.type = "svg";
9805
9726
  this.isSVGTag = false;
9806
9727
  this.measureInstanceViewportBox = createBox;
9807
- this.updateDimensions = () => {
9808
- if (this.current && !this.renderState.dimensions) {
9809
- updateSVGDimensions(this.current, this.renderState);
9810
- }
9811
- };
9812
9728
  }
9813
9729
  getBaseTargetFromProps(props, key) {
9814
9730
  return props[key];
@@ -9824,11 +9740,6 @@ class SVGVisualElement extends DOMVisualElement {
9824
9740
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
9825
9741
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
9826
9742
  }
9827
- onBindTransform() {
9828
- if (this.current && !this.renderState.dimensions) {
9829
- frame.postRender(this.updateDimensions);
9830
- }
9831
- }
9832
9743
  build(renderState, latestValues, props) {
9833
9744
  buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
9834
9745
  }