framer-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.
@@ -4233,7 +4233,7 @@
4233
4233
  * This will be replaced by the build step with the latest version number.
4234
4234
  * When MotionValues are provided to motion components, warn if versions are mixed.
4235
4235
  */
4236
- this.version = "12.8.0";
4236
+ this.version = "12.8.1";
4237
4237
  /**
4238
4238
  * Tracks whether this value can output a velocity. Currently this is only true
4239
4239
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -4377,8 +4377,6 @@
4377
4377
  * @public
4378
4378
  */
4379
4379
  set(v, render = true) {
4380
- if (v === "none")
4381
- console.trace();
4382
4380
  if (!render || !this.passiveEffect) {
4383
4381
  this.updateAndNotify(v, render);
4384
4382
  }
@@ -7578,7 +7576,7 @@
7578
7576
  * and warn against mismatches.
7579
7577
  */
7580
7578
  {
7581
- warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
7579
+ warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
7582
7580
  }
7583
7581
  }
7584
7582
  else if (isMotionValue(prevValue)) {
@@ -7746,8 +7744,7 @@
7746
7744
  frame.render(this.render, false, true);
7747
7745
  }
7748
7746
  };
7749
- const { latestValues, renderState, onUpdate } = visualState;
7750
- this.onUpdate = onUpdate;
7747
+ const { latestValues, renderState } = visualState;
7751
7748
  this.latestValues = latestValues;
7752
7749
  this.baseTarget = { ...latestValues };
7753
7750
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -7949,7 +7946,6 @@
7949
7946
  if (this.handleChildMotionValue) {
7950
7947
  this.handleChildMotionValue();
7951
7948
  }
7952
- this.onUpdate && this.onUpdate(this);
7953
7949
  }
7954
7950
  getProps() {
7955
7951
  return this.props;
@@ -9541,7 +9537,7 @@
9541
9537
  * Calculate a transform origin relative to the source axis, between 0-1, that results
9542
9538
  * in an asthetically pleasing scale/transform needed to project from source to target.
9543
9539
  */
9544
- function calcOrigin$1(source, target) {
9540
+ function calcOrigin(source, target) {
9545
9541
  let origin = 0.5;
9546
9542
  const sourceLength = calcLength(source);
9547
9543
  const targetLength = calcLength(target);
@@ -9935,7 +9931,7 @@
9935
9931
  const axisValue = this.getAxisMotionValue(axis);
9936
9932
  if (axisValue && this.constraints !== false) {
9937
9933
  const latest = axisValue.get();
9938
- boxProgress[axis] = calcOrigin$1({ min: latest, max: latest }, this.constraints[axis]);
9934
+ boxProgress[axis] = calcOrigin({ min: latest, max: latest }, this.constraints[axis]);
9939
9935
  }
9940
9936
  });
9941
9937
  /**
@@ -10886,25 +10882,10 @@
10886
10882
  attrs[keys.array] = `${pathLength} ${pathSpacing}`;
10887
10883
  }
10888
10884
 
10889
- function calcOrigin(origin, offset, size) {
10890
- return typeof origin === "string"
10891
- ? origin
10892
- : px.transform(offset + size * origin);
10893
- }
10894
- /**
10895
- * The SVG transform origin defaults are different to CSS and is less intuitive,
10896
- * so we use the measured dimensions of the SVG to reconcile these.
10897
- */
10898
- function calcSVGTransformOrigin(dimensions, originX, originY) {
10899
- const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
10900
- const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
10901
- return `${pxOriginX} ${pxOriginY}`;
10902
- }
10903
-
10904
10885
  /**
10905
10886
  * Build SVG visual attrbutes, like cx and style.transform
10906
10887
  */
10907
- function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
10888
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
10908
10889
  // This is object creation, which we try to avoid per-frame.
10909
10890
  ...latest }, isSVGTag, transformTemplate) {
10910
10891
  buildHTMLStyles(state, latest, transformTemplate);
@@ -10920,20 +10901,26 @@
10920
10901
  }
10921
10902
  state.attrs = state.style;
10922
10903
  state.style = {};
10923
- const { attrs, style, dimensions } = state;
10904
+ const { attrs, style } = state;
10924
10905
  /**
10925
- * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
10926
- * and copy it into style.
10906
+ * However, we apply transforms as CSS transforms.
10907
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
10927
10908
  */
10928
10909
  if (attrs.transform) {
10929
- if (dimensions)
10930
- style.transform = attrs.transform;
10910
+ style.transform = attrs.transform;
10931
10911
  delete attrs.transform;
10932
10912
  }
10933
- // Parse transformOrigin
10934
- if (dimensions &&
10935
- (originX !== undefined || originY !== undefined || style.transform)) {
10936
- style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
10913
+ if (style.transform || attrs.transformOrigin) {
10914
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
10915
+ delete attrs.transformOrigin;
10916
+ }
10917
+ if (style.transform) {
10918
+ /**
10919
+ * SVG's element transform-origin uses its own median as a reference.
10920
+ * Therefore, transformBox becomes a fill-box
10921
+ */
10922
+ style.transformBox = "fill-box";
10923
+ delete attrs.transformBox;
10937
10924
  }
10938
10925
  // Render attrX/attrY/attrScale as attributes
10939
10926
  if (attrX !== undefined)
@@ -10997,20 +10984,11 @@
10997
10984
  return useRender;
10998
10985
  }
10999
10986
 
11000
- function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
10987
+ function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
11001
10988
  const state = {
11002
10989
  latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
11003
10990
  renderState: createRenderState(),
11004
10991
  };
11005
- if (onUpdate) {
11006
- /**
11007
- * onMount works without the VisualElement because it could be
11008
- * called before the VisualElement payload has been hydrated.
11009
- * (e.g. if someone is using m components <m.circle />)
11010
- */
11011
- state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
11012
- state.onUpdate = (visualElement) => onUpdate(visualElement);
11013
- }
11014
10992
  return state;
11015
10993
  }
11016
10994
  const makeUseVisualState = (config) => (props, isStatic) => {
@@ -11082,22 +11060,41 @@
11082
11060
  }),
11083
11061
  };
11084
11062
 
11085
- function updateSVGDimensions(instance, renderState) {
11086
- try {
11087
- renderState.dimensions =
11088
- typeof instance.getBBox === "function"
11089
- ? instance.getBBox()
11090
- : instance.getBoundingClientRect();
11063
+ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
11064
+ const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
11065
+ for (const key in props) {
11066
+ if (isMotionValue(props[key]) ||
11067
+ isMotionValue(prevProps[key])) {
11068
+ const targetKey = transformPropOrder.indexOf(key) !== -1
11069
+ ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
11070
+ : key;
11071
+ newValues[targetKey] = props[key];
11072
+ }
11091
11073
  }
11092
- catch (e) {
11093
- // Most likely trying to measure an unrendered element under Firefox
11094
- renderState.dimensions = {
11095
- x: 0,
11096
- y: 0,
11097
- width: 0,
11098
- height: 0,
11074
+ return newValues;
11075
+ }
11076
+
11077
+ const svgMotionConfig = {
11078
+ useVisualState: makeUseVisualState({
11079
+ scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
11080
+ createRenderState: createSvgRenderState,
11081
+ }),
11082
+ };
11083
+
11084
+ function createMotionComponentFactory(preloadedFeatures, createVisualElement) {
11085
+ return function createMotionComponent(Component, { forwardMotionProps } = { forwardMotionProps: false }) {
11086
+ const baseConfig = isSVGComponent(Component)
11087
+ ? svgMotionConfig
11088
+ : htmlMotionConfig;
11089
+ const config = {
11090
+ ...baseConfig,
11091
+ preloadedFeatures,
11092
+ useRender: createUseRender(forwardMotionProps),
11093
+ createVisualElement,
11094
+ Component,
11099
11095
  };
11100
- }
11096
+ return createRendererMotionComponent(config);
11097
+ };
11101
11098
  }
11102
11099
 
11103
11100
  /**
@@ -11136,93 +11133,12 @@
11136
11133
  }
11137
11134
  }
11138
11135
 
11139
- function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
11140
- const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
11141
- for (const key in props) {
11142
- if (isMotionValue(props[key]) ||
11143
- isMotionValue(prevProps[key])) {
11144
- const targetKey = transformPropOrder.indexOf(key) !== -1
11145
- ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
11146
- : key;
11147
- newValues[targetKey] = props[key];
11148
- }
11149
- }
11150
- return newValues;
11151
- }
11152
-
11153
- const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
11154
- const svgMotionConfig = {
11155
- useVisualState: makeUseVisualState({
11156
- scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
11157
- createRenderState: createSvgRenderState,
11158
- onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
11159
- if (!current)
11160
- return;
11161
- let hasTransform = !!props.drag;
11162
- if (!hasTransform) {
11163
- for (const key in latestValues) {
11164
- if (transformProps.has(key)) {
11165
- hasTransform = true;
11166
- break;
11167
- }
11168
- }
11169
- }
11170
- if (!hasTransform)
11171
- return;
11172
- let needsMeasure = !prevProps;
11173
- if (prevProps) {
11174
- /**
11175
- * Check the layout props for changes, if any are found we need to
11176
- * measure the element again.
11177
- */
11178
- for (let i = 0; i < layoutProps.length; i++) {
11179
- const key = layoutProps[i];
11180
- if (props[key] !==
11181
- prevProps[key]) {
11182
- needsMeasure = true;
11183
- }
11184
- }
11185
- }
11186
- if (!needsMeasure)
11187
- return;
11188
- frame.read(() => {
11189
- updateSVGDimensions(current, renderState);
11190
- frame.render(() => {
11191
- buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
11192
- renderSVG(current, renderState);
11193
- });
11194
- });
11195
- },
11196
- }),
11197
- };
11198
-
11199
- function createMotionComponentFactory(preloadedFeatures, createVisualElement) {
11200
- return function createMotionComponent(Component, { forwardMotionProps } = { forwardMotionProps: false }) {
11201
- const baseConfig = isSVGComponent(Component)
11202
- ? svgMotionConfig
11203
- : htmlMotionConfig;
11204
- const config = {
11205
- ...baseConfig,
11206
- preloadedFeatures,
11207
- useRender: createUseRender(forwardMotionProps),
11208
- createVisualElement,
11209
- Component,
11210
- };
11211
- return createRendererMotionComponent(config);
11212
- };
11213
- }
11214
-
11215
11136
  class SVGVisualElement extends DOMVisualElement {
11216
11137
  constructor() {
11217
11138
  super(...arguments);
11218
11139
  this.type = "svg";
11219
11140
  this.isSVGTag = false;
11220
11141
  this.measureInstanceViewportBox = createBox;
11221
- this.updateDimensions = () => {
11222
- if (this.current && !this.renderState.dimensions) {
11223
- updateSVGDimensions(this.current, this.renderState);
11224
- }
11225
- };
11226
11142
  }
11227
11143
  getBaseTargetFromProps(props, key) {
11228
11144
  return props[key];
@@ -11238,11 +11154,6 @@
11238
11154
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
11239
11155
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
11240
11156
  }
11241
- onBindTransform() {
11242
- if (this.current && !this.renderState.dimensions) {
11243
- frame.postRender(this.updateDimensions);
11244
- }
11245
- }
11246
11157
  build(renderState, latestValues, props) {
11247
11158
  buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
11248
11159
  }