framer-motion 11.16.7 → 11.17.1

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.
@@ -409,7 +409,7 @@ class MotionValue {
409
409
  * This will be replaced by the build step with the latest version number.
410
410
  * When MotionValues are provided to motion components, warn if versions are mixed.
411
411
  */
412
- this.version = "11.16.7";
412
+ this.version = "11.17.1";
413
413
  /**
414
414
  * Tracks whether this value can output a velocity. Currently this is only true
415
415
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -5201,7 +5201,7 @@ function updateMotionValuesFromProps(element, next, prev) {
5201
5201
  * and warn against mismatches.
5202
5202
  */
5203
5203
  if (process.env.NODE_ENV === "development") {
5204
- warnOnce(nextValue.version === "11.16.7", `Attempting to mix Motion versions ${nextValue.version} with 11.16.7 may not work as expected.`);
5204
+ warnOnce(nextValue.version === "11.17.1", `Attempting to mix Motion versions ${nextValue.version} with 11.17.1 may not work as expected.`);
5205
5205
  }
5206
5206
  }
5207
5207
  else if (isMotionValue(prevValue)) {
@@ -5334,7 +5334,8 @@ class VisualElement {
5334
5334
  frame.render(this.render, false, true);
5335
5335
  }
5336
5336
  };
5337
- const { latestValues, renderState } = visualState;
5337
+ const { latestValues, renderState, onUpdate } = visualState;
5338
+ this.onUpdate = onUpdate;
5338
5339
  this.latestValues = latestValues;
5339
5340
  this.baseTarget = { ...latestValues };
5340
5341
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -5534,6 +5535,7 @@ class VisualElement {
5534
5535
  if (this.handleChildMotionValue) {
5535
5536
  this.handleChildMotionValue();
5536
5537
  }
5538
+ this.onUpdate && this.onUpdate(this);
5537
5539
  }
5538
5540
  getProps() {
5539
5541
  return this.props;
@@ -8204,7 +8206,7 @@ const PresenceContext = react.createContext(null);
8204
8206
  *
8205
8207
  * @public
8206
8208
  */
8207
- function usePresence() {
8209
+ function usePresence(subscribe = true) {
8208
8210
  const context = react.useContext(PresenceContext);
8209
8211
  if (context === null)
8210
8212
  return [true, null];
@@ -8212,8 +8214,11 @@ function usePresence() {
8212
8214
  // It's safe to call the following hooks conditionally (after an early return) because the context will always
8213
8215
  // either be null or non-null for the lifespan of the component.
8214
8216
  const id = react.useId();
8215
- react.useEffect(() => register(id), []);
8216
- const safeToRemove = react.useCallback(() => onExitComplete && onExitComplete(id), [id, onExitComplete]);
8217
+ react.useEffect(() => {
8218
+ if (subscribe)
8219
+ register(id);
8220
+ }, [subscribe]);
8221
+ const safeToRemove = react.useCallback(() => subscribe && onExitComplete && onExitComplete(id), [id, onExitComplete, subscribe]);
8217
8222
  return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
8218
8223
  }
8219
8224
 
@@ -8628,7 +8633,9 @@ const motionComponentSymbol = Symbol.for("motionComponentSymbol");
8628
8633
  */
8629
8634
  function useMotionRef(visualState, visualElement, externalRef) {
8630
8635
  return react.useCallback((instance) => {
8631
- instance && visualState.mount && visualState.mount(instance);
8636
+ if (instance) {
8637
+ visualState.onMount && visualState.onMount(instance);
8638
+ }
8632
8639
  if (visualElement) {
8633
8640
  if (instance) {
8634
8641
  visualElement.mount(instance);
@@ -8937,13 +8944,19 @@ function useConstant(init) {
8937
8944
  return ref.current;
8938
8945
  }
8939
8946
 
8940
- function makeState({ scrapeMotionValuesFromProps, createRenderState, onMount, }, props, context, presenceContext) {
8947
+ function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
8941
8948
  const state = {
8942
8949
  latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
8943
8950
  renderState: createRenderState(),
8944
8951
  };
8945
- if (onMount) {
8946
- state.mount = (instance) => onMount(props, instance, state);
8952
+ if (onUpdate) {
8953
+ /**
8954
+ * onMount works without the VisualElement because it could be
8955
+ * called before the VisualElement payload has been hydrated.
8956
+ * (e.g. if someone is using m components <m.circle />)
8957
+ */
8958
+ state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
8959
+ state.onUpdate = (visualElement) => onUpdate(visualElement);
8947
8960
  }
8948
8961
  return state;
8949
8962
  }
@@ -9021,32 +9034,62 @@ const createSvgRenderState = () => ({
9021
9034
  attrs: {},
9022
9035
  });
9023
9036
 
9037
+ function updateSVGDimensions(instance, renderState) {
9038
+ try {
9039
+ renderState.dimensions =
9040
+ typeof instance.getBBox === "function"
9041
+ ? instance.getBBox()
9042
+ : instance.getBoundingClientRect();
9043
+ }
9044
+ catch (e) {
9045
+ // Most likely trying to measure an unrendered element under Firefox
9046
+ renderState.dimensions = {
9047
+ x: 0,
9048
+ y: 0,
9049
+ width: 0,
9050
+ height: 0,
9051
+ };
9052
+ }
9053
+ }
9054
+ const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
9024
9055
  const svgMotionConfig = {
9025
9056
  useVisualState: makeUseVisualState({
9026
9057
  scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
9027
9058
  createRenderState: createSvgRenderState,
9028
- onMount: (props, instance, { renderState, latestValues }) => {
9029
- frame.read(() => {
9030
- try {
9031
- renderState.dimensions =
9032
- typeof instance.getBBox ===
9033
- "function"
9034
- ? instance.getBBox()
9035
- : instance.getBoundingClientRect();
9059
+ onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
9060
+ if (!current)
9061
+ return;
9062
+ let hasTransform = !!props.drag;
9063
+ if (!hasTransform) {
9064
+ for (const key in latestValues) {
9065
+ if (transformProps.has(key)) {
9066
+ hasTransform = true;
9067
+ break;
9068
+ }
9036
9069
  }
9037
- catch (e) {
9038
- // Most likely trying to measure an unrendered element under Firefox
9039
- renderState.dimensions = {
9040
- x: 0,
9041
- y: 0,
9042
- width: 0,
9043
- height: 0,
9044
- };
9070
+ }
9071
+ if (!hasTransform)
9072
+ return;
9073
+ let needsMeasure = !prevProps;
9074
+ if (prevProps) {
9075
+ /**
9076
+ * Check the layout props for changes, if any are found we need to
9077
+ * measure the element again.
9078
+ */
9079
+ for (let i = 0; i < layoutProps.length; i++) {
9080
+ const key = layoutProps[i];
9081
+ if (props[key] !==
9082
+ prevProps[key]) {
9083
+ needsMeasure = true;
9084
+ }
9045
9085
  }
9046
- });
9086
+ }
9087
+ if (!needsMeasure)
9088
+ return;
9089
+ frame.read(() => updateSVGDimensions(current, renderState));
9047
9090
  frame.render(() => {
9048
- buildSVGAttrs(renderState, latestValues, isSVGTag(instance.tagName), props.transformTemplate);
9049
- renderSVG(instance, renderState);
9091
+ buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
9092
+ renderSVG(current, renderState);
9050
9093
  });
9051
9094
  },
9052
9095
  }),
package/dist/cjs/dom.js CHANGED
@@ -994,7 +994,7 @@ class MotionValue {
994
994
  * This will be replaced by the build step with the latest version number.
995
995
  * When MotionValues are provided to motion components, warn if versions are mixed.
996
996
  */
997
- this.version = "11.16.7";
997
+ this.version = "11.17.1";
998
998
  /**
999
999
  * Tracks whether this value can output a velocity. Currently this is only true
1000
1000
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -3924,7 +3924,7 @@ function updateMotionValuesFromProps(element, next, prev) {
3924
3924
  * and warn against mismatches.
3925
3925
  */
3926
3926
  if (process.env.NODE_ENV === "development") {
3927
- warnOnce(nextValue.version === "11.16.7", `Attempting to mix Motion versions ${nextValue.version} with 11.16.7 may not work as expected.`);
3927
+ warnOnce(nextValue.version === "11.17.1", `Attempting to mix Motion versions ${nextValue.version} with 11.17.1 may not work as expected.`);
3928
3928
  }
3929
3929
  }
3930
3930
  else if (isMotionValue(prevValue)) {
@@ -4057,7 +4057,8 @@ class VisualElement {
4057
4057
  frame.render(this.render, false, true);
4058
4058
  }
4059
4059
  };
4060
- const { latestValues, renderState } = visualState;
4060
+ const { latestValues, renderState, onUpdate } = visualState;
4061
+ this.onUpdate = onUpdate;
4061
4062
  this.latestValues = latestValues;
4062
4063
  this.baseTarget = { ...latestValues };
4063
4064
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -4257,6 +4258,7 @@ class VisualElement {
4257
4258
  if (this.handleChildMotionValue) {
4258
4259
  this.handleChildMotionValue();
4259
4260
  }
4261
+ this.onUpdate && this.onUpdate(this);
4260
4262
  }
4261
4263
  getProps() {
4262
4264
  return this.props;