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
@@ -4,12 +4,10 @@ import { camelToDash } from '../dom/utils/camel-to-dash.mjs';
4
4
  import { buildSVGAttrs } from './utils/build-attrs.mjs';
5
5
  import { camelCaseAttributes } from './utils/camel-case-attrs.mjs';
6
6
  import { isSVGTag } from './utils/is-svg-tag.mjs';
7
- import { updateSVGDimensions } from './utils/measure.mjs';
8
7
  import { renderSVG } from './utils/render.mjs';
9
8
  import { scrapeMotionValuesFromProps } from './utils/scrape-motion-values.mjs';
10
9
  import { transformProps } from '../../../../../motion-dom/dist/es/render/utils/keys-transform.mjs';
11
10
  import { getDefaultValueType } from '../../../../../motion-dom/dist/es/value/types/maps/defaults.mjs';
12
- import { frame } from '../../../../../motion-dom/dist/es/frameloop/frame.mjs';
13
11
 
14
12
  class SVGVisualElement extends DOMVisualElement {
15
13
  constructor() {
@@ -17,11 +15,6 @@ class SVGVisualElement extends DOMVisualElement {
17
15
  this.type = "svg";
18
16
  this.isSVGTag = false;
19
17
  this.measureInstanceViewportBox = createBox;
20
- this.updateDimensions = () => {
21
- if (this.current && !this.renderState.dimensions) {
22
- updateSVGDimensions(this.current, this.renderState);
23
- }
24
- };
25
18
  }
26
19
  getBaseTargetFromProps(props, key) {
27
20
  return props[key];
@@ -37,11 +30,6 @@ class SVGVisualElement extends DOMVisualElement {
37
30
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
38
31
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
39
32
  }
40
- onBindTransform() {
41
- if (this.current && !this.renderState.dimensions) {
42
- frame.postRender(this.updateDimensions);
43
- }
44
- }
45
33
  build(renderState, latestValues, props) {
46
34
  buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
47
35
  }
@@ -1,56 +1,11 @@
1
1
  import { makeUseVisualState } from '../../motion/utils/use-visual-state.mjs';
2
- import { buildSVGAttrs } from './utils/build-attrs.mjs';
3
2
  import { createSvgRenderState } from './utils/create-render-state.mjs';
4
- import { isSVGTag } from './utils/is-svg-tag.mjs';
5
- import { updateSVGDimensions } from './utils/measure.mjs';
6
- import { renderSVG } from './utils/render.mjs';
7
3
  import { scrapeMotionValuesFromProps } from './utils/scrape-motion-values.mjs';
8
- import { transformProps } from '../../../../../motion-dom/dist/es/render/utils/keys-transform.mjs';
9
- import { frame } from '../../../../../motion-dom/dist/es/frameloop/frame.mjs';
10
4
 
11
- const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
12
5
  const svgMotionConfig = {
13
6
  useVisualState: makeUseVisualState({
14
7
  scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
15
8
  createRenderState: createSvgRenderState,
16
- onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
17
- if (!current)
18
- return;
19
- let hasTransform = !!props.drag;
20
- if (!hasTransform) {
21
- for (const key in latestValues) {
22
- if (transformProps.has(key)) {
23
- hasTransform = true;
24
- break;
25
- }
26
- }
27
- }
28
- if (!hasTransform)
29
- return;
30
- let needsMeasure = !prevProps;
31
- if (prevProps) {
32
- /**
33
- * Check the layout props for changes, if any are found we need to
34
- * measure the element again.
35
- */
36
- for (let i = 0; i < layoutProps.length; i++) {
37
- const key = layoutProps[i];
38
- if (props[key] !==
39
- prevProps[key]) {
40
- needsMeasure = true;
41
- }
42
- }
43
- }
44
- if (!needsMeasure)
45
- return;
46
- frame.read(() => {
47
- updateSVGDimensions(current, renderState);
48
- frame.render(() => {
49
- buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
50
- renderSVG(current, renderState);
51
- });
52
- });
53
- },
54
9
  }),
55
10
  };
56
11
 
@@ -1,11 +1,10 @@
1
1
  import { buildHTMLStyles } from '../../html/utils/build-styles.mjs';
2
2
  import { buildSVGPath } from './path.mjs';
3
- import { calcSVGTransformOrigin } from './transform-origin.mjs';
4
3
 
5
4
  /**
6
5
  * Build SVG visual attrbutes, like cx and style.transform
7
6
  */
8
- function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
7
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
9
8
  // This is object creation, which we try to avoid per-frame.
10
9
  ...latest }, isSVGTag, transformTemplate) {
11
10
  buildHTMLStyles(state, latest, transformTemplate);
@@ -21,20 +20,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
21
20
  }
22
21
  state.attrs = state.style;
23
22
  state.style = {};
24
- const { attrs, style, dimensions } = state;
23
+ const { attrs, style } = state;
25
24
  /**
26
- * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
27
- * and copy it into style.
25
+ * However, we apply transforms as CSS transforms.
26
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
28
27
  */
29
28
  if (attrs.transform) {
30
- if (dimensions)
31
- style.transform = attrs.transform;
29
+ style.transform = attrs.transform;
32
30
  delete attrs.transform;
33
31
  }
34
- // Parse transformOrigin
35
- if (dimensions &&
36
- (originX !== undefined || originY !== undefined || style.transform)) {
37
- style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
32
+ if (style.transform || attrs.transformOrigin) {
33
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
34
+ delete attrs.transformOrigin;
35
+ }
36
+ if (style.transform) {
37
+ /**
38
+ * SVG's element transform-origin uses its own median as a reference.
39
+ * Therefore, transformBox becomes a fill-box
40
+ */
41
+ style.transformBox = "fill-box";
42
+ delete attrs.transformBox;
38
43
  }
39
44
  // Render attrX/attrY/attrScale as attributes
40
45
  if (attrX !== undefined)
@@ -17,7 +17,7 @@ function updateMotionValuesFromProps(element, next, prev) {
17
17
  * and warn against mismatches.
18
18
  */
19
19
  if (process.env.NODE_ENV === "development") {
20
- warnOnce(nextValue.version === "12.7.5", `Attempting to mix Motion versions ${nextValue.version} with 12.7.5 may not work as expected.`);
20
+ warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
21
21
  }
22
22
  }
23
23
  else if (isMotionValue(prevValue)) {
@@ -1,4 +1,4 @@
1
- import { resolveFinalValueInKeyframes } from '../../utils/resolve-value.mjs';
1
+ import { isKeyframesTarget } from '../../animation/utils/is-keyframes-target.mjs';
2
2
  import { resolveVariant } from './resolve-dynamic-variants.mjs';
3
3
  import { motionValue } from '../../../../../motion-dom/dist/es/value/index.mjs';
4
4
 
@@ -14,6 +14,10 @@ function setMotionValue(visualElement, key, value) {
14
14
  visualElement.addValue(key, motionValue(value));
15
15
  }
16
16
  }
17
+ function resolveFinalValueInKeyframes(v) {
18
+ // TODO maybe throw if v.length - 1 is placeholder token?
19
+ return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
20
+ }
17
21
  function setTarget(visualElement, definition) {
18
22
  const resolved = resolveVariant(visualElement, definition);
19
23
  let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
@@ -1,7 +1,7 @@
1
- import { transform } from '../utils/transform.mjs';
2
1
  import { useConstant } from '../utils/use-constant.mjs';
3
2
  import { useCombineMotionValues } from './use-combine-values.mjs';
4
3
  import { useComputed } from './use-computed.mjs';
4
+ import { transform } from '../../../../motion-dom/dist/es/utils/transform.mjs';
5
5
 
6
6
  function useTransform(input, inputRangeOrTransformer, outputRange, options) {
7
7
  if (typeof input === "function") {
@@ -1,4 +1,3 @@
1
- import { isCustomValue } from '../../utils/resolve-value.mjs';
2
1
  import { isMotionValue } from './is-motion-value.mjs';
3
2
 
4
3
  /**
@@ -7,10 +6,7 @@ import { isMotionValue } from './is-motion-value.mjs';
7
6
  * TODO: Remove and move to library
8
7
  */
9
8
  function resolveMotionValue(value) {
10
- const unwrappedValue = isMotionValue(value) ? value.get() : value;
11
- return isCustomValue(unwrappedValue)
12
- ? unwrappedValue.toValue()
13
- : unwrappedValue;
9
+ return isMotionValue(value) ? value.get() : value;
14
10
  }
15
11
 
16
12
  export { resolveMotionValue };
@@ -6,7 +6,6 @@ export { inView } from '../../framer-motion/dist/es/render/dom/viewport/index.mj
6
6
  export { stagger } from '../../framer-motion/dist/es/animation/utils/stagger.mjs';
7
7
  export { delayInSeconds as delay } from '../../framer-motion/dist/es/utils/delay.mjs';
8
8
  export { distance, distance2D } from '../../framer-motion/dist/es/utils/distance.mjs';
9
- export { transform } from '../../framer-motion/dist/es/utils/transform.mjs';
10
9
  export { AsyncMotionValueAnimation } from '../../motion-dom/dist/es/animation/AsyncMotionValueAnimation.mjs';
11
10
  export { GroupAnimation } from '../../motion-dom/dist/es/animation/GroupAnimation.mjs';
12
11
  export { GroupAnimationWithThen } from '../../motion-dom/dist/es/animation/GroupAnimationWithThen.mjs';
@@ -69,7 +68,10 @@ export { resolveElements } from '../../motion-dom/dist/es/utils/resolve-elements
69
68
  export { supportsFlags } from '../../motion-dom/dist/es/utils/supports/flags.mjs';
70
69
  export { supportsLinearEasing } from '../../motion-dom/dist/es/utils/supports/linear-easing.mjs';
71
70
  export { supportsScrollTimeline } from '../../motion-dom/dist/es/utils/supports/scroll-timeline.mjs';
71
+ export { transform } from '../../motion-dom/dist/es/utils/transform.mjs';
72
72
  export { MotionValue, collectMotionValues, motionValue } from '../../motion-dom/dist/es/value/index.mjs';
73
+ export { mapValue } from '../../motion-dom/dist/es/value/map-value.mjs';
74
+ export { transformValue } from '../../motion-dom/dist/es/value/transform-value.mjs';
73
75
  export { color } from '../../motion-dom/dist/es/value/types/color/index.mjs';
74
76
  export { hex } from '../../motion-dom/dist/es/value/types/color/hex.mjs';
75
77
  export { hsla } from '../../motion-dom/dist/es/value/types/color/hsla.mjs';
@@ -78,7 +78,6 @@ export { scroll } from '../../framer-motion/dist/es/render/dom/scroll/index.mjs'
78
78
  export { scrollInfo } from '../../framer-motion/dist/es/render/dom/scroll/track.mjs';
79
79
  export { inView } from '../../framer-motion/dist/es/render/dom/viewport/index.mjs';
80
80
  export { stagger } from '../../framer-motion/dist/es/animation/utils/stagger.mjs';
81
- export { transform } from '../../framer-motion/dist/es/utils/transform.mjs';
82
81
  export { distance, distance2D } from '../../framer-motion/dist/es/utils/distance.mjs';
83
82
  export { addUniqueItem, moveItem, removeItem } from '../../motion-utils/dist/es/array.mjs';
84
83
  export { clamp } from '../../motion-utils/dist/es/clamp.mjs';
@@ -168,7 +167,10 @@ export { resolveElements } from '../../motion-dom/dist/es/utils/resolve-elements
168
167
  export { supportsFlags } from '../../motion-dom/dist/es/utils/supports/flags.mjs';
169
168
  export { supportsLinearEasing } from '../../motion-dom/dist/es/utils/supports/linear-easing.mjs';
170
169
  export { supportsScrollTimeline } from '../../motion-dom/dist/es/utils/supports/scroll-timeline.mjs';
170
+ export { transform } from '../../motion-dom/dist/es/utils/transform.mjs';
171
171
  export { MotionValue, collectMotionValues, motionValue } from '../../motion-dom/dist/es/value/index.mjs';
172
+ export { mapValue } from '../../motion-dom/dist/es/value/map-value.mjs';
173
+ export { transformValue } from '../../motion-dom/dist/es/value/transform-value.mjs';
172
174
  export { color } from '../../motion-dom/dist/es/value/types/color/index.mjs';
173
175
  export { hex } from '../../motion-dom/dist/es/value/types/color/hex.mjs';
174
176
  export { hsla } from '../../motion-dom/dist/es/value/types/color/hsla.mjs';
@@ -1,9 +1,5 @@
1
- import { interpolate } from '../../../../motion-dom/dist/es/utils/interpolate.mjs';
1
+ import { interpolate } from './interpolate.mjs';
2
2
 
3
- const isCustomValueType = (v) => {
4
- return v && typeof v === "object" && v.mix;
5
- };
6
- const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
7
3
  function transform(...args) {
8
4
  const useImmediate = !Array.isArray(args[0]);
9
5
  const argOffset = useImmediate ? 0 : -1;
@@ -11,10 +7,7 @@ function transform(...args) {
11
7
  const inputRange = args[1 + argOffset];
12
8
  const outputRange = args[2 + argOffset];
13
9
  const options = args[3 + argOffset];
14
- const interpolator = interpolate(inputRange, outputRange, {
15
- mixer: getMixer(outputRange[0]),
16
- ...options,
17
- });
10
+ const interpolator = interpolate(inputRange, outputRange, options);
18
11
  return useImmediate ? interpolator(inputValue) : interpolator;
19
12
  }
20
13
 
@@ -32,7 +32,7 @@ class MotionValue {
32
32
  * This will be replaced by the build step with the latest version number.
33
33
  * When MotionValues are provided to motion components, warn if versions are mixed.
34
34
  */
35
- this.version = "12.7.5";
35
+ this.version = "12.8.1";
36
36
  /**
37
37
  * Tracks whether this value can output a velocity. Currently this is only true
38
38
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -176,8 +176,6 @@ class MotionValue {
176
176
  * @public
177
177
  */
178
178
  set(v, render = true) {
179
- if (v === "none")
180
- console.trace();
181
179
  if (!render || !this.passiveEffect) {
182
180
  this.updateAndNotify(v, render);
183
181
  }
@@ -301,6 +299,7 @@ class MotionValue {
301
299
  * @public
302
300
  */
303
301
  destroy() {
302
+ this.events.destroy?.notify();
304
303
  this.clearListeners();
305
304
  this.stop();
306
305
  if (this.stopPassiveEffect) {
@@ -0,0 +1,46 @@
1
+ import { transform } from '../utils/transform.mjs';
2
+ import { transformValue } from './transform-value.mjs';
3
+
4
+ /**
5
+ * Create a `MotionValue` that maps the output of another `MotionValue` by
6
+ * mapping it from one range of values into another.
7
+ *
8
+ * @remarks
9
+ *
10
+ * Given an input range of `[-200, -100, 100, 200]` and an output range of
11
+ * `[0, 1, 1, 0]`, the returned `MotionValue` will:
12
+ *
13
+ * - When provided a value between `-200` and `-100`, will return a value between `0` and `1`.
14
+ * - When provided a value between `-100` and `100`, will return `1`.
15
+ * - When provided a value between `100` and `200`, will return a value between `1` and `0`
16
+ *
17
+ * The input range must be a linear series of numbers. The output range
18
+ * can be any value type supported by Motion: numbers, colors, shadows, etc.
19
+ *
20
+ * Every value in the output range must be of the same type and in the same format.
21
+ *
22
+ * ```jsx
23
+ * const x = motionValue(0)
24
+ * const xRange = [-200, -100, 100, 200]
25
+ * const opacityRange = [0, 1, 1, 0]
26
+ * const opacity = mapValue(x, xRange, opacityRange)
27
+ * ```
28
+ *
29
+ * @param inputValue - `MotionValue`
30
+ * @param inputRange - A linear series of numbers (either all increasing or decreasing)
31
+ * @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
32
+ * @param options -
33
+ *
34
+ * - clamp: boolean. Clamp values to within the given range. Defaults to `true`
35
+ * - 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.
36
+ *
37
+ * @returns `MotionValue`
38
+ *
39
+ * @public
40
+ */
41
+ function mapValue(inputValue, inputRange, outputRange, options) {
42
+ const map = transform(inputRange, outputRange, options);
43
+ return transformValue(() => map(inputValue.get()));
44
+ }
45
+
46
+ export { mapValue };
@@ -0,0 +1,13 @@
1
+ import { cancelFrame, frame } from '../frameloop/frame.mjs';
2
+
3
+ function subscribeValue(inputValues, outputValue, getLatest) {
4
+ const update = () => outputValue.set(getLatest());
5
+ const scheduleUpdate = () => frame.preRender(update, false, true);
6
+ const subscriptions = inputValues.map((v) => v.on("change", scheduleUpdate));
7
+ outputValue.on("destroy", () => {
8
+ subscriptions.forEach((unsubscribe) => unsubscribe());
9
+ cancelFrame(update);
10
+ });
11
+ }
12
+
13
+ export { subscribeValue };
@@ -0,0 +1,35 @@
1
+ import { collectMotionValues, motionValue } from './index.mjs';
2
+ import { subscribeValue } from './subscribe-value.mjs';
3
+
4
+ /**
5
+ * Create a `MotionValue` that transforms the output of other `MotionValue`s by
6
+ * passing their latest values through a transform function.
7
+ *
8
+ * Whenever a `MotionValue` referred to in the provided function is updated,
9
+ * it will be re-evaluated.
10
+ *
11
+ * ```jsx
12
+ * const x = motionValue(0)
13
+ * const y = transformValue(() => x.get() * 2) // double x
14
+ * ```
15
+ *
16
+ * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
17
+ * @returns `MotionValue`
18
+ *
19
+ * @public
20
+ */
21
+ function transformValue(transform) {
22
+ const collectedValues = [];
23
+ /**
24
+ * Open session of collectMotionValues. Any MotionValue that calls get()
25
+ * inside transform will be saved into this array.
26
+ */
27
+ collectMotionValues.current = collectedValues;
28
+ const initialValue = transform();
29
+ collectMotionValues.current = undefined;
30
+ const value = motionValue(initialValue);
31
+ subscribeValue(collectedValues, value, transform);
32
+ return value;
33
+ }
34
+
35
+ export { transformValue };
@@ -41,7 +41,6 @@ const numberValueTypes = {
41
41
  backgroundPositionY: px,
42
42
  ...transformValueTypes,
43
43
  zIndex: int,
44
- size: px,
45
44
  // SVG
46
45
  fillOpacity: alpha,
47
46
  strokeOpacity: alpha,