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