framer-motion 5.3.3 → 5.4.0-beta

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 (39) hide show
  1. package/dist/es/components/AnimatePresence/use-presence.mjs +1 -27
  2. package/dist/es/context/MotionContext/index.mjs +1 -1
  3. package/dist/es/events/use-dom-event.mjs +2 -31
  4. package/dist/es/events/use-pointer-event.mjs +2 -5
  5. package/dist/es/gestures/utils/event-type.mjs +1 -8
  6. package/dist/es/motion/index.mjs +1 -1
  7. package/dist/es/projection/geometry/models.mjs +1 -11
  8. package/dist/es/projection/node/create-projection-node.mjs +4 -1167
  9. package/dist/es/render/dom/value-types/dimensions.mjs +1 -8
  10. package/dist/es/render/three/create-visual-element.mjs +42 -0
  11. package/dist/es/render/three/gestures/use-hover.mjs +22 -0
  12. package/dist/es/render/three/gestures/use-tap.mjs +56 -0
  13. package/dist/es/render/three/motion.mjs +30 -0
  14. package/dist/es/render/three/use-render.mjs +11 -0
  15. package/dist/es/render/three/utils/read-value.mjs +43 -0
  16. package/dist/es/render/three/utils/set-value.mjs +59 -0
  17. package/dist/es/render/utils/animation.mjs +1 -4
  18. package/dist/es/render/utils/setters.mjs +2 -39
  19. package/dist/es/three-entry.mjs +1 -0
  20. package/dist/es/utils/array.mjs +2 -13
  21. package/dist/framer-motion-three.cjs.js +2995 -0
  22. package/dist/framer-motion.cjs.js +19 -21
  23. package/dist/framer-motion.dev.js +8 -10
  24. package/dist/framer-motion.js +1 -1
  25. package/dist/projection.dev.js +2 -2
  26. package/dist/size-rollup-m.js +1 -1
  27. package/package.json +24 -3
  28. package/types/motion/features/types.d.ts +1 -1
  29. package/types/render/three/create-visual-element.d.ts +6 -0
  30. package/types/render/three/gestures/use-hover.d.ts +10 -0
  31. package/types/render/three/gestures/use-tap.d.ts +8 -0
  32. package/types/render/three/motion.d.ts +5 -0
  33. package/types/render/three/types.d.ts +24 -0
  34. package/types/render/three/use-render.d.ts +4 -0
  35. package/types/render/three/utils/read-value.d.ts +2 -0
  36. package/types/render/three/utils/set-value.d.ts +2 -0
  37. package/types/render/utils/lifecycles.d.ts +8 -8
  38. package/types/render/utils/setters.d.ts +1 -0
  39. package/types/three-entry.d.ts +1 -0
@@ -1,16 +1,9 @@
1
1
  import { number, px, percent, degrees, vw, vh } from 'style-value-types';
2
- import { testValueType } from './test.mjs';
3
2
  import { auto } from './type-auto.mjs';
4
3
 
5
4
  /**
6
5
  * A list of value types commonly used for dimensions
7
6
  */
8
7
  var dimensionValueTypes = [number, px, percent, degrees, vw, vh, auto];
9
- /**
10
- * Tests a dimensional value against the list of dimension ValueTypes
11
- */
12
- var findDimensionValueType = function (v) {
13
- return dimensionValueTypes.find(testValueType(v));
14
- };
15
8
 
16
- export { dimensionValueTypes, findDimensionValueType };
9
+ export { dimensionValueTypes };
@@ -0,0 +1,42 @@
1
+ import { visualElement } from '../index.mjs';
2
+ import { createBox } from '../../projection/geometry/models.mjs';
3
+ import { checkTargetForNewValues } from '../utils/setters.mjs';
4
+ import { setThreeValue } from './utils/set-value.mjs';
5
+ import { readThreeValue } from './utils/read-value.mjs';
6
+
7
+ var scrapeMotionValuesFromProps = function () { return ({}); };
8
+ var createRenderState = function () { return ({}); };
9
+ var threeVisualElement = visualElement({
10
+ treeType: "three",
11
+ readValueFromInstance: readThreeValue,
12
+ getBaseTarget: function (_props, _key) {
13
+ return 0;
14
+ },
15
+ sortNodePosition: function (_a, _b) {
16
+ return 0;
17
+ },
18
+ makeTargetAnimatable: function (element, target) {
19
+ checkTargetForNewValues(element, target, {});
20
+ return target;
21
+ },
22
+ restoreTransform: function () { },
23
+ resetTransform: function () { },
24
+ removeValueFromRenderState: function (_key, _renderState) { },
25
+ measureViewportBox: createBox,
26
+ scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
27
+ build: function (_element, state, latestValues) {
28
+ for (var key in latestValues) {
29
+ state[key] = latestValues[key];
30
+ }
31
+ },
32
+ render: function (instance, renderState) {
33
+ for (var key in renderState) {
34
+ setThreeValue(instance, key, renderState);
35
+ }
36
+ },
37
+ });
38
+ var createVisualElement = function (_, options) {
39
+ return threeVisualElement(options);
40
+ };
41
+
42
+ export { createRenderState, createVisualElement, scrapeMotionValuesFromProps, threeVisualElement };
@@ -0,0 +1,22 @@
1
+ import { AnimationType } from '../../utils/types.mjs';
2
+
3
+ function useHover(isStatic, _a, visualElement) {
4
+ var whileHover = _a.whileHover, onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, onPointerOver = _a.onPointerOver, onPointerOut = _a.onPointerOut;
5
+ var isHoverEnabled = whileHover || onHoverStart || onHoverEnd;
6
+ if (isStatic || !visualElement || !isHoverEnabled)
7
+ return {};
8
+ return {
9
+ onPointerOver: function (event) {
10
+ var _a;
11
+ (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Hover, true);
12
+ onPointerOver === null || onPointerOver === void 0 ? void 0 : onPointerOver(event);
13
+ },
14
+ onPointerOut: function (event) {
15
+ var _a;
16
+ (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Hover, false);
17
+ onPointerOut === null || onPointerOut === void 0 ? void 0 : onPointerOut(event);
18
+ },
19
+ };
20
+ }
21
+
22
+ export { useHover };
@@ -0,0 +1,56 @@
1
+ import { pipe } from 'popmotion';
2
+ import { useRef } from 'react';
3
+ import { wrapHandler } from '../../../events/event-info.mjs';
4
+ import { addPointerEvent } from '../../../events/use-pointer-event.mjs';
5
+ import { isDragActive } from '../../../gestures/drag/utils/lock.mjs';
6
+ import { AnimationType } from '../../utils/types.mjs';
7
+
8
+ function useTap(isStatic, _a, visualElement) {
9
+ var whileTap = _a.whileTap, onTapStart = _a.onTapStart, onTap = _a.onTap, onTapCancel = _a.onTapCancel, onPointerDown = _a.onPointerDown;
10
+ var isTapEnabled = onTap || onTapStart || onTapCancel || whileTap;
11
+ var isPressing = useRef(false);
12
+ var cancelPointerEndListeners = useRef(null);
13
+ if (isStatic || !visualElement || !isTapEnabled)
14
+ return {};
15
+ function removePointerEndListener() {
16
+ var _a;
17
+ (_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
18
+ cancelPointerEndListeners.current = null;
19
+ }
20
+ function checkPointerEnd() {
21
+ var _a;
22
+ removePointerEndListener();
23
+ isPressing.current = false;
24
+ (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Tap, false);
25
+ return !isDragActive();
26
+ }
27
+ function onPointerUp(event, info) {
28
+ if (!checkPointerEnd())
29
+ return;
30
+ /**
31
+ * We only count this as a tap gesture if the event.target is the same
32
+ * as, or a child of, this component's element
33
+ */
34
+ onTap === null || onTap === void 0 ? void 0 : onTap(event, info);
35
+ }
36
+ function onPointerCancel(event, info) {
37
+ if (!checkPointerEnd())
38
+ return;
39
+ onTapCancel === null || onTapCancel === void 0 ? void 0 : onTapCancel(event, info);
40
+ }
41
+ return {
42
+ onPointerDown: wrapHandler(function (event, info) {
43
+ var _a;
44
+ removePointerEndListener();
45
+ if (isPressing.current)
46
+ return;
47
+ isPressing.current = true;
48
+ cancelPointerEndListeners.current = pipe(addPointerEvent(window, "pointerup", onPointerUp), addPointerEvent(window, "pointercancel", onPointerCancel));
49
+ (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Tap, true);
50
+ onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown(event);
51
+ onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
52
+ }, true),
53
+ };
54
+ }
55
+
56
+ export { useTap };
@@ -0,0 +1,30 @@
1
+ import { __assign } from 'tslib';
2
+ import { createMotionComponent } from '../../motion/index.mjs';
3
+ import { animations } from '../../motion/features/animations.mjs';
4
+ import { makeUseVisualState } from '../../motion/utils/use-visual-state.mjs';
5
+ import { useRender } from './use-render.mjs';
6
+ import { scrapeMotionValuesFromProps, createRenderState, createVisualElement } from './create-visual-element.mjs';
7
+
8
+ var useVisualState = makeUseVisualState({
9
+ scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
10
+ createRenderState: createRenderState,
11
+ });
12
+ var preloadedFeatures = __assign({}, animations);
13
+ function custom(Component) {
14
+ return createMotionComponent({
15
+ Component: Component,
16
+ preloadedFeatures: preloadedFeatures,
17
+ useRender: useRender,
18
+ useVisualState: useVisualState,
19
+ createVisualElement: createVisualElement,
20
+ });
21
+ }
22
+ var componentCache = new Map();
23
+ var motion = new Proxy(custom, {
24
+ get: function (_, key) {
25
+ !componentCache.has(key) && componentCache.set(key, custom(key));
26
+ return componentCache.get(key);
27
+ },
28
+ });
29
+
30
+ export { motion };
@@ -0,0 +1,11 @@
1
+ import { __assign } from 'tslib';
2
+ import { createElement } from 'react';
3
+ import { filterProps } from '../dom/utils/filter-props.mjs';
4
+ import { useHover } from './gestures/use-hover.mjs';
5
+ import { useTap } from './gestures/use-tap.mjs';
6
+
7
+ var useRender = function (Component, props, _projectionId, ref, _state, isStatic, visualElement) {
8
+ return createElement(Component, __assign(__assign(__assign(__assign({ ref: ref }, filterProps(props, false, false)), { onUpdate: props.onInstanceUpdate }), useHover(isStatic, props, visualElement)), useTap(isStatic, props, visualElement)));
9
+ };
10
+
11
+ export { useRender };
@@ -0,0 +1,43 @@
1
+ import { Color } from 'three';
2
+
3
+ var readVector = function (name, defaultValue) {
4
+ return function (axis) {
5
+ return function (instance) {
6
+ var value = instance[name];
7
+ return value ? value[axis] : defaultValue;
8
+ };
9
+ };
10
+ };
11
+ var readPosition = readVector("position", 0);
12
+ var readScale = readVector("scale", 1);
13
+ var readRotation = readVector("rotation", 0);
14
+ var readers = {
15
+ x: readPosition("x"),
16
+ y: readPosition("y"),
17
+ z: readPosition("z"),
18
+ scale: readScale("x"),
19
+ scaleX: readScale("x"),
20
+ scaleY: readScale("y"),
21
+ scaleZ: readScale("z"),
22
+ rotateX: readRotation("x"),
23
+ rotateY: readRotation("y"),
24
+ rotateZ: readRotation("z"),
25
+ };
26
+ function readAnimatableValue(value) {
27
+ if (!value)
28
+ return;
29
+ if (value instanceof Color) {
30
+ return value.getStyle();
31
+ }
32
+ else {
33
+ return value;
34
+ }
35
+ }
36
+ function readThreeValue(instance, name) {
37
+ var _a;
38
+ return readers[name]
39
+ ? readers[name](instance)
40
+ : (_a = readAnimatableValue(instance[name])) !== null && _a !== void 0 ? _a : 0;
41
+ }
42
+
43
+ export { readThreeValue };
@@ -0,0 +1,59 @@
1
+ import { Vector3, Euler, Color } from 'three';
2
+
3
+ var setVector = function (name, defaultValue) {
4
+ return function (i) {
5
+ return function (instance, value) {
6
+ var _a;
7
+ (_a = instance[name]) !== null && _a !== void 0 ? _a : (instance[name] = new Vector3(defaultValue));
8
+ var vector = instance[name];
9
+ vector.setComponent(i, value);
10
+ };
11
+ };
12
+ };
13
+ var setEuler = function (name, defaultValue) {
14
+ return function (axis) {
15
+ return function (instance, value) {
16
+ var _a;
17
+ (_a = instance[name]) !== null && _a !== void 0 ? _a : (instance[name] = new Euler(defaultValue));
18
+ var euler = instance[name];
19
+ euler[axis] = value;
20
+ };
21
+ };
22
+ };
23
+ var setColor = function (name) { return function (instance, value) {
24
+ var _a;
25
+ (_a = instance[name]) !== null && _a !== void 0 ? _a : (instance[name] = new Color(value));
26
+ instance[name].set(value);
27
+ }; };
28
+ var setScale = setVector("scale", 1);
29
+ var setPosition = setVector("position", 0);
30
+ var setRotation = setEuler("rotation", 0);
31
+ var setters = {
32
+ x: setPosition(0),
33
+ y: setPosition(1),
34
+ z: setPosition(2),
35
+ scale: function (instance, value) {
36
+ var _a;
37
+ (_a = instance.scale) !== null && _a !== void 0 ? _a : (instance.scale = new Vector3(1));
38
+ var scale = instance.scale;
39
+ scale.set(value, value, value);
40
+ },
41
+ scaleX: setScale(0),
42
+ scaleY: setScale(1),
43
+ scaleZ: setScale(2),
44
+ rotateX: setRotation("x"),
45
+ rotateY: setRotation("y"),
46
+ rotateZ: setRotation("z"),
47
+ color: setColor("color"),
48
+ specular: setColor("specular"),
49
+ };
50
+ function setThreeValue(instance, key, values) {
51
+ if (setters[key]) {
52
+ setters[key](instance, values[key]);
53
+ }
54
+ else {
55
+ instance[key] = values[key];
56
+ }
57
+ }
58
+
59
+ export { setThreeValue };
@@ -119,9 +119,6 @@ function animateChildren(visualElement, variant, delayChildren, staggerChildren,
119
119
  });
120
120
  return Promise.all(animations);
121
121
  }
122
- function stopAnimation(visualElement) {
123
- visualElement.forEachValue(function (value) { return value.stop(); });
124
- }
125
122
  function sortByTreeOrder(a, b) {
126
123
  return a.sortNodePosition(b);
127
124
  }
@@ -138,4 +135,4 @@ function shouldBlockAnimation(_a, key) {
138
135
  return shouldBlock;
139
136
  }
140
137
 
141
- export { animateVisualElement, sortByTreeOrder, stopAnimation };
138
+ export { animateVisualElement, sortByTreeOrder };
@@ -1,4 +1,4 @@
1
- import { __rest, __assign, __spreadArray, __read } from 'tslib';
1
+ import { __rest, __assign } from 'tslib';
2
2
  import { complex } from 'style-value-types';
3
3
  import { isNumericalString } from '../../utils/is-numerical-string.mjs';
4
4
  import { isZeroValueString } from '../../utils/is-zero-value-string.mjs';
@@ -29,28 +29,6 @@ function setTarget(visualElement, definition) {
29
29
  setMotionValue(visualElement, key, value);
30
30
  }
31
31
  }
32
- function setVariants(visualElement, variantLabels) {
33
- var reversedLabels = __spreadArray([], __read(variantLabels), false).reverse();
34
- reversedLabels.forEach(function (key) {
35
- var _a;
36
- var variant = visualElement.getVariant(key);
37
- variant && setTarget(visualElement, variant);
38
- (_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
39
- setVariants(child, variantLabels);
40
- });
41
- });
42
- }
43
- function setValues(visualElement, definition) {
44
- if (Array.isArray(definition)) {
45
- return setVariants(visualElement, definition);
46
- }
47
- else if (typeof definition === "string") {
48
- return setVariants(visualElement, [definition]);
49
- }
50
- else {
51
- setTarget(visualElement, definition);
52
- }
53
- }
54
32
  function checkTargetForNewValues(visualElement, target, origin) {
55
33
  var _a, _b, _c;
56
34
  var _d;
@@ -96,20 +74,5 @@ function checkTargetForNewValues(visualElement, target, origin) {
96
74
  visualElement.setBaseTarget(key, value);
97
75
  }
98
76
  }
99
- function getOriginFromTransition(key, transition) {
100
- if (!transition)
101
- return;
102
- var valueTransition = transition[key] || transition["default"] || transition;
103
- return valueTransition.from;
104
- }
105
- function getOrigin(target, transition, visualElement) {
106
- var _a, _b;
107
- var origin = {};
108
- for (var key in target) {
109
- origin[key] =
110
- (_a = getOriginFromTransition(key, transition)) !== null && _a !== void 0 ? _a : (_b = visualElement.getValue(key)) === null || _b === void 0 ? void 0 : _b.get();
111
- }
112
- return origin;
113
- }
114
77
 
115
- export { checkTargetForNewValues, getOrigin, getOriginFromTransition, setTarget, setValues };
78
+ export { checkTargetForNewValues, setTarget };
@@ -0,0 +1 @@
1
+ export { motion } from './render/three/motion.mjs';
@@ -1,4 +1,4 @@
1
- import { __read } from 'tslib';
1
+ import 'tslib';
2
2
 
3
3
  function addUniqueItem(arr, item) {
4
4
  arr.indexOf(item) === -1 && arr.push(item);
@@ -7,16 +7,5 @@ function removeItem(arr, item) {
7
7
  var index = arr.indexOf(item);
8
8
  index > -1 && arr.splice(index, 1);
9
9
  }
10
- // Adapted from array-move
11
- function moveItem(_a, fromIndex, toIndex) {
12
- var _b = __read(_a), arr = _b.slice(0);
13
- var startIndex = fromIndex < 0 ? arr.length + fromIndex : fromIndex;
14
- if (startIndex >= 0 && startIndex < arr.length) {
15
- var endIndex = toIndex < 0 ? arr.length + toIndex : toIndex;
16
- var _c = __read(arr.splice(fromIndex, 1), 1), item = _c[0];
17
- arr.splice(endIndex, 0, item);
18
- }
19
- return arr;
20
- }
21
10
 
22
- export { addUniqueItem, moveItem, removeItem };
11
+ export { addUniqueItem, removeItem };