motion 12.7.5 → 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.
Files changed (26) hide show
  1. package/dist/cjs/index.js +125 -89
  2. package/dist/cjs/react-client.js +72 -168
  3. package/dist/cjs/react-m.js +18 -150
  4. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-state.mjs +1 -10
  5. package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +1 -3
  6. package/dist/es/framer-motion/dist/es/render/svg/SVGVisualElement.mjs +0 -12
  7. package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +0 -45
  8. package/dist/es/framer-motion/dist/es/render/svg/utils/build-attrs.mjs +16 -11
  9. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
  10. package/dist/es/framer-motion/dist/es/render/utils/setters.mjs +5 -1
  11. package/dist/es/framer-motion/dist/es/value/use-transform.mjs +1 -1
  12. package/dist/es/framer-motion/dist/es/value/utils/resolve-motion-value.mjs +1 -5
  13. package/dist/es/motion/lib/index.mjs +3 -1
  14. package/dist/es/motion/lib/react.mjs +3 -1
  15. package/dist/es/{framer-motion → motion-dom}/dist/es/utils/transform.mjs +2 -9
  16. package/dist/es/motion-dom/dist/es/value/index.mjs +2 -3
  17. package/dist/es/motion-dom/dist/es/value/map-value.mjs +46 -0
  18. package/dist/es/motion-dom/dist/es/value/subscribe-value.mjs +13 -0
  19. package/dist/es/motion-dom/dist/es/value/transform-value.mjs +35 -0
  20. package/dist/es/motion-dom/dist/es/value/types/maps/number.mjs +0 -1
  21. package/dist/motion.dev.js +125 -89
  22. package/dist/motion.js +1 -1
  23. package/package.json +3 -3
  24. package/dist/es/framer-motion/dist/es/render/svg/utils/measure.mjs +0 -19
  25. package/dist/es/framer-motion/dist/es/render/svg/utils/transform-origin.mjs +0 -18
  26. package/dist/es/framer-motion/dist/es/utils/resolve-value.mjs +0 -11
@@ -892,7 +892,7 @@
892
892
  function mixNumber(a, b) {
893
893
  return (p) => mixNumber$1(a, b, p);
894
894
  }
895
- function getMixer$1(a) {
895
+ function getMixer(a) {
896
896
  if (typeof a === "number") {
897
897
  return mixNumber;
898
898
  }
@@ -914,7 +914,7 @@
914
914
  function mixArray(a, b) {
915
915
  const output = [...a];
916
916
  const numValues = output.length;
917
- const blendValue = a.map((v, i) => getMixer$1(v)(v, b[i]));
917
+ const blendValue = a.map((v, i) => getMixer(v)(v, b[i]));
918
918
  return (p) => {
919
919
  for (let i = 0; i < numValues; i++) {
920
920
  output[i] = blendValue[i](p);
@@ -927,7 +927,7 @@
927
927
  const blendValue = {};
928
928
  for (const key in output) {
929
929
  if (a[key] !== undefined && b[key] !== undefined) {
930
- blendValue[key] = getMixer$1(a[key])(a[key], b[key]);
930
+ blendValue[key] = getMixer(a[key])(a[key], b[key]);
931
931
  }
932
932
  }
933
933
  return (v) => {
@@ -977,7 +977,7 @@
977
977
  typeof p === "number") {
978
978
  return mixNumber$1(from, to, p);
979
979
  }
980
- const mixer = getMixer$1(from);
980
+ const mixer = getMixer(from);
981
981
  return mixer(from, to);
982
982
  }
983
983
 
@@ -3085,7 +3085,6 @@
3085
3085
  backgroundPositionY: px,
3086
3086
  ...transformValueTypes,
3087
3087
  zIndex: int,
3088
- size: px,
3089
3088
  // SVG
3090
3089
  fillOpacity: alpha,
3091
3090
  strokeOpacity: alpha,
@@ -3739,6 +3738,17 @@
3739
3738
  return reportStats;
3740
3739
  }
3741
3740
 
3741
+ function transform(...args) {
3742
+ const useImmediate = !Array.isArray(args[0]);
3743
+ const argOffset = useImmediate ? 0 : -1;
3744
+ const inputValue = args[0 + argOffset];
3745
+ const inputRange = args[1 + argOffset];
3746
+ const outputRange = args[2 + argOffset];
3747
+ const options = args[3 + argOffset];
3748
+ const interpolator = interpolate(inputRange, outputRange, options);
3749
+ return useImmediate ? interpolator(inputValue) : interpolator;
3750
+ }
3751
+
3742
3752
  /**
3743
3753
  * Maximum time between the value of two frames, beyond which we
3744
3754
  * assume the velocity has since been 0.
@@ -3767,7 +3777,7 @@
3767
3777
  * This will be replaced by the build step with the latest version number.
3768
3778
  * When MotionValues are provided to motion components, warn if versions are mixed.
3769
3779
  */
3770
- this.version = "12.7.5";
3780
+ this.version = "12.8.1";
3771
3781
  /**
3772
3782
  * Tracks whether this value can output a velocity. Currently this is only true
3773
3783
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -3911,8 +3921,6 @@
3911
3921
  * @public
3912
3922
  */
3913
3923
  set(v, render = true) {
3914
- if (v === "none")
3915
- console.trace();
3916
3924
  if (!render || !this.passiveEffect) {
3917
3925
  this.updateAndNotify(v, render);
3918
3926
  }
@@ -4036,6 +4044,7 @@
4036
4044
  * @public
4037
4045
  */
4038
4046
  destroy() {
4047
+ this.events.destroy?.notify();
4039
4048
  this.clearListeners();
4040
4049
  this.stop();
4041
4050
  if (this.stopPassiveEffect) {
@@ -4047,6 +4056,89 @@
4047
4056
  return new MotionValue(init, options);
4048
4057
  }
4049
4058
 
4059
+ function subscribeValue(inputValues, outputValue, getLatest) {
4060
+ const update = () => outputValue.set(getLatest());
4061
+ const scheduleUpdate = () => frame.preRender(update, false, true);
4062
+ const subscriptions = inputValues.map((v) => v.on("change", scheduleUpdate));
4063
+ outputValue.on("destroy", () => {
4064
+ subscriptions.forEach((unsubscribe) => unsubscribe());
4065
+ cancelFrame(update);
4066
+ });
4067
+ }
4068
+
4069
+ /**
4070
+ * Create a `MotionValue` that transforms the output of other `MotionValue`s by
4071
+ * passing their latest values through a transform function.
4072
+ *
4073
+ * Whenever a `MotionValue` referred to in the provided function is updated,
4074
+ * it will be re-evaluated.
4075
+ *
4076
+ * ```jsx
4077
+ * const x = motionValue(0)
4078
+ * const y = transformValue(() => x.get() * 2) // double x
4079
+ * ```
4080
+ *
4081
+ * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
4082
+ * @returns `MotionValue`
4083
+ *
4084
+ * @public
4085
+ */
4086
+ function transformValue(transform) {
4087
+ const collectedValues = [];
4088
+ /**
4089
+ * Open session of collectMotionValues. Any MotionValue that calls get()
4090
+ * inside transform will be saved into this array.
4091
+ */
4092
+ collectMotionValues.current = collectedValues;
4093
+ const initialValue = transform();
4094
+ collectMotionValues.current = undefined;
4095
+ const value = motionValue(initialValue);
4096
+ subscribeValue(collectedValues, value, transform);
4097
+ return value;
4098
+ }
4099
+
4100
+ /**
4101
+ * Create a `MotionValue` that maps the output of another `MotionValue` by
4102
+ * mapping it from one range of values into another.
4103
+ *
4104
+ * @remarks
4105
+ *
4106
+ * Given an input range of `[-200, -100, 100, 200]` and an output range of
4107
+ * `[0, 1, 1, 0]`, the returned `MotionValue` will:
4108
+ *
4109
+ * - When provided a value between `-200` and `-100`, will return a value between `0` and `1`.
4110
+ * - When provided a value between `-100` and `100`, will return `1`.
4111
+ * - When provided a value between `100` and `200`, will return a value between `1` and `0`
4112
+ *
4113
+ * The input range must be a linear series of numbers. The output range
4114
+ * can be any value type supported by Motion: numbers, colors, shadows, etc.
4115
+ *
4116
+ * Every value in the output range must be of the same type and in the same format.
4117
+ *
4118
+ * ```jsx
4119
+ * const x = motionValue(0)
4120
+ * const xRange = [-200, -100, 100, 200]
4121
+ * const opacityRange = [0, 1, 1, 0]
4122
+ * const opacity = mapValue(x, xRange, opacityRange)
4123
+ * ```
4124
+ *
4125
+ * @param inputValue - `MotionValue`
4126
+ * @param inputRange - A linear series of numbers (either all increasing or decreasing)
4127
+ * @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
4128
+ * @param options -
4129
+ *
4130
+ * - clamp: boolean. Clamp values to within the given range. Defaults to `true`
4131
+ * - ease: EasingFunction[]. Easing functions to use on the interpolations between each value in the input and output ranges. If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition between each.
4132
+ *
4133
+ * @returns `MotionValue`
4134
+ *
4135
+ * @public
4136
+ */
4137
+ function mapValue(inputValue, inputRange, outputRange, options) {
4138
+ const map = transform(inputRange, outputRange, options);
4139
+ return transformValue(() => map(inputValue.get()));
4140
+ }
4141
+
4050
4142
  /**
4051
4143
  * A list of all ValueTypes
4052
4144
  */
@@ -4732,11 +4824,6 @@
4732
4824
  return Array.isArray(v);
4733
4825
  };
4734
4826
 
4735
- const resolveFinalValueInKeyframes = (v) => {
4736
- // TODO maybe throw if v.length - 1 is placeholder token?
4737
- return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
4738
- };
4739
-
4740
4827
  function getValueState(visualElement) {
4741
4828
  const state = [{}, {}];
4742
4829
  visualElement?.values.forEach((value, key) => {
@@ -4789,6 +4876,10 @@
4789
4876
  visualElement.addValue(key, motionValue(value));
4790
4877
  }
4791
4878
  }
4879
+ function resolveFinalValueInKeyframes(v) {
4880
+ // TODO maybe throw if v.length - 1 is placeholder token?
4881
+ return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
4882
+ }
4792
4883
  function setTarget(visualElement, definition) {
4793
4884
  const resolved = resolveVariant(visualElement, definition);
4794
4885
  let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
@@ -5147,7 +5238,7 @@
5147
5238
  * and warn against mismatches.
5148
5239
  */
5149
5240
  {
5150
- warnOnce(nextValue.version === "12.7.5", `Attempting to mix Motion versions ${nextValue.version} with 12.7.5 may not work as expected.`);
5241
+ warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
5151
5242
  }
5152
5243
  }
5153
5244
  else if (isMotionValue(prevValue)) {
@@ -5280,8 +5371,7 @@
5280
5371
  frame.render(this.render, false, true);
5281
5372
  }
5282
5373
  };
5283
- const { latestValues, renderState, onUpdate } = visualState;
5284
- this.onUpdate = onUpdate;
5374
+ const { latestValues, renderState } = visualState;
5285
5375
  this.latestValues = latestValues;
5286
5376
  this.baseTarget = { ...latestValues };
5287
5377
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -5483,7 +5573,6 @@
5483
5573
  if (this.handleChildMotionValue) {
5484
5574
  this.handleChildMotionValue();
5485
5575
  }
5486
- this.onUpdate && this.onUpdate(this);
5487
5576
  }
5488
5577
  getProps() {
5489
5578
  return this.props;
@@ -5825,25 +5914,10 @@
5825
5914
  attrs[keys.array] = `${pathLength} ${pathSpacing}`;
5826
5915
  }
5827
5916
 
5828
- function calcOrigin(origin, offset, size) {
5829
- return typeof origin === "string"
5830
- ? origin
5831
- : px.transform(offset + size * origin);
5832
- }
5833
- /**
5834
- * The SVG transform origin defaults are different to CSS and is less intuitive,
5835
- * so we use the measured dimensions of the SVG to reconcile these.
5836
- */
5837
- function calcSVGTransformOrigin(dimensions, originX, originY) {
5838
- const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
5839
- const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
5840
- return `${pxOriginX} ${pxOriginY}`;
5841
- }
5842
-
5843
5917
  /**
5844
5918
  * Build SVG visual attrbutes, like cx and style.transform
5845
5919
  */
5846
- function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
5920
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
5847
5921
  // This is object creation, which we try to avoid per-frame.
5848
5922
  ...latest }, isSVGTag, transformTemplate) {
5849
5923
  buildHTMLStyles(state, latest, transformTemplate);
@@ -5859,20 +5933,26 @@
5859
5933
  }
5860
5934
  state.attrs = state.style;
5861
5935
  state.style = {};
5862
- const { attrs, style, dimensions } = state;
5936
+ const { attrs, style } = state;
5863
5937
  /**
5864
- * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
5865
- * and copy it into style.
5938
+ * However, we apply transforms as CSS transforms.
5939
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
5866
5940
  */
5867
5941
  if (attrs.transform) {
5868
- if (dimensions)
5869
- style.transform = attrs.transform;
5942
+ style.transform = attrs.transform;
5870
5943
  delete attrs.transform;
5871
5944
  }
5872
- // Parse transformOrigin
5873
- if (dimensions &&
5874
- (originX !== undefined || originY !== undefined || style.transform)) {
5875
- style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
5945
+ if (style.transform || attrs.transformOrigin) {
5946
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
5947
+ delete attrs.transformOrigin;
5948
+ }
5949
+ if (style.transform) {
5950
+ /**
5951
+ * SVG's element transform-origin uses its own median as a reference.
5952
+ * Therefore, transformBox becomes a fill-box
5953
+ */
5954
+ style.transformBox = "fill-box";
5955
+ delete attrs.transformBox;
5876
5956
  }
5877
5957
  // Render attrX/attrY/attrScale as attributes
5878
5958
  if (attrX !== undefined)
@@ -5918,24 +5998,6 @@
5918
5998
 
5919
5999
  const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
5920
6000
 
5921
- function updateSVGDimensions(instance, renderState) {
5922
- try {
5923
- renderState.dimensions =
5924
- typeof instance.getBBox === "function"
5925
- ? instance.getBBox()
5926
- : instance.getBoundingClientRect();
5927
- }
5928
- catch (e) {
5929
- // Most likely trying to measure an unrendered element under Firefox
5930
- renderState.dimensions = {
5931
- x: 0,
5932
- y: 0,
5933
- width: 0,
5934
- height: 0,
5935
- };
5936
- }
5937
- }
5938
-
5939
6001
  function renderHTML(element, { style, vars }, styleProp, projection) {
5940
6002
  Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
5941
6003
  // Loop over any CSS variables and assign those.
@@ -5995,11 +6057,6 @@
5995
6057
  this.type = "svg";
5996
6058
  this.isSVGTag = false;
5997
6059
  this.measureInstanceViewportBox = createBox;
5998
- this.updateDimensions = () => {
5999
- if (this.current && !this.renderState.dimensions) {
6000
- updateSVGDimensions(this.current, this.renderState);
6001
- }
6002
- };
6003
6060
  }
6004
6061
  getBaseTargetFromProps(props, key) {
6005
6062
  return props[key];
@@ -6015,11 +6072,6 @@
6015
6072
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
6016
6073
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
6017
6074
  }
6018
- onBindTransform() {
6019
- if (this.current && !this.renderState.dimensions) {
6020
- frame.postRender(this.updateDimensions);
6021
- }
6022
- }
6023
6075
  build(renderState, latestValues, props) {
6024
6076
  buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
6025
6077
  }
@@ -6976,24 +7028,6 @@
6976
7028
  return Math.sqrt(xDelta ** 2 + yDelta ** 2);
6977
7029
  }
6978
7030
 
6979
- const isCustomValueType = (v) => {
6980
- return v && typeof v === "object" && v.mix;
6981
- };
6982
- const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
6983
- function transform(...args) {
6984
- const useImmediate = !Array.isArray(args[0]);
6985
- const argOffset = useImmediate ? 0 : -1;
6986
- const inputValue = args[0 + argOffset];
6987
- const inputRange = args[1 + argOffset];
6988
- const outputRange = args[2 + argOffset];
6989
- const options = args[3 + argOffset];
6990
- const interpolator = interpolate(inputRange, outputRange, {
6991
- mixer: getMixer(outputRange[0]),
6992
- ...options,
6993
- });
6994
- return useImmediate ? interpolator(inputValue) : interpolator;
6995
- }
6996
-
6997
7031
  exports.AsyncMotionValueAnimation = AsyncMotionValueAnimation;
6998
7032
  exports.DOMKeyframesResolver = DOMKeyframesResolver;
6999
7033
  exports.GroupAnimation = GroupAnimation;
@@ -7065,7 +7099,7 @@
7065
7099
  exports.getComputedStyle = getComputedStyle$2;
7066
7100
  exports.getDefaultValueType = getDefaultValueType;
7067
7101
  exports.getEasingForSegment = getEasingForSegment;
7068
- exports.getMixer = getMixer$1;
7102
+ exports.getMixer = getMixer;
7069
7103
  exports.getValueAsType = getValueAsType;
7070
7104
  exports.getValueTransition = getValueTransition$1;
7071
7105
  exports.getVariableValue = getVariableValue;
@@ -7092,6 +7126,7 @@
7092
7126
  exports.isZeroValueString = isZeroValueString;
7093
7127
  exports.keyframes = keyframes;
7094
7128
  exports.mapEasingToNativeEasing = mapEasingToNativeEasing;
7129
+ exports.mapValue = mapValue;
7095
7130
  exports.maxGeneratorDuration = maxGeneratorDuration;
7096
7131
  exports.memo = memo;
7097
7132
  exports.microtask = microtask;
@@ -7151,6 +7186,7 @@
7151
7186
  exports.transform = transform;
7152
7187
  exports.transformPropOrder = transformPropOrder;
7153
7188
  exports.transformProps = transformProps;
7189
+ exports.transformValue = transformValue;
7154
7190
  exports.transformValueTypes = transformValueTypes;
7155
7191
  exports.velocityPerSecond = velocityPerSecond;
7156
7192
  exports.vh = vh;