framer-motion 5.3.0 → 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 (73) hide show
  1. package/dist/es/animation/utils/easing.mjs +1 -1
  2. package/dist/es/animation/utils/transitions.mjs +9 -3
  3. package/dist/es/components/AnimatePresence/index.mjs +1 -1
  4. package/dist/es/components/AnimatePresence/use-presence.mjs +1 -27
  5. package/dist/es/components/AnimateSharedLayout.mjs +1 -1
  6. package/dist/es/components/Reorder/Item.mjs +5 -4
  7. package/dist/es/context/MotionContext/index.mjs +1 -1
  8. package/dist/es/events/use-dom-event.mjs +2 -31
  9. package/dist/es/events/use-pointer-event.mjs +2 -5
  10. package/dist/es/gestures/use-hover-gesture.mjs +4 -1
  11. package/dist/es/gestures/use-tap-gesture.mjs +4 -1
  12. package/dist/es/gestures/utils/event-type.mjs +1 -8
  13. package/dist/es/index.mjs +1 -0
  14. package/dist/es/motion/features/viewport/use-viewport.mjs +2 -2
  15. package/dist/es/motion/index.mjs +1 -1
  16. package/dist/es/motion/utils/use-visual-state.mjs +29 -10
  17. package/dist/es/motion/utils/valid-prop.mjs +1 -0
  18. package/dist/es/projection/animation/mix-values.mjs +1 -1
  19. package/dist/es/projection/geometry/models.mjs +1 -11
  20. package/dist/es/projection/node/create-projection-node.mjs +4 -1167
  21. package/dist/es/projection/styles/scale-border-radius.mjs +1 -1
  22. package/dist/es/projection/styles/transform.mjs +5 -5
  23. package/dist/es/render/dom/motion-proxy.mjs +3 -0
  24. package/dist/es/render/dom/utils/css-variables-conversion.mjs +2 -2
  25. package/dist/es/render/dom/utils/filter-props.mjs +3 -1
  26. package/dist/es/render/dom/value-types/dimensions.mjs +1 -8
  27. package/dist/es/render/html/use-props.mjs +6 -4
  28. package/dist/es/render/html/utils/build-transform.mjs +2 -2
  29. package/dist/es/render/svg/utils/path.mjs +1 -1
  30. package/dist/es/render/svg/utils/transform-origin.mjs +1 -1
  31. package/dist/es/render/three/create-visual-element.mjs +42 -0
  32. package/dist/es/render/three/gestures/use-hover.mjs +22 -0
  33. package/dist/es/render/three/gestures/use-tap.mjs +56 -0
  34. package/dist/es/render/three/motion.mjs +30 -0
  35. package/dist/es/render/three/use-render.mjs +11 -0
  36. package/dist/es/render/three/utils/read-value.mjs +43 -0
  37. package/dist/es/render/three/utils/set-value.mjs +59 -0
  38. package/dist/es/render/utils/animation-state.mjs +5 -4
  39. package/dist/es/render/utils/animation.mjs +1 -4
  40. package/dist/es/render/utils/setters.mjs +3 -42
  41. package/dist/es/three-entry.mjs +1 -0
  42. package/dist/es/utils/array.mjs +2 -13
  43. package/dist/es/utils/use-force-update.mjs +13 -9
  44. package/dist/es/utils/use-instant-transition-state.mjs +5 -0
  45. package/dist/es/utils/use-instant-transition.mjs +28 -0
  46. package/dist/framer-motion-three.cjs.js +2995 -0
  47. package/dist/framer-motion.cjs.js +147 -84
  48. package/dist/framer-motion.dev.js +139 -76
  49. package/dist/framer-motion.js +1 -1
  50. package/dist/projection.dev.js +35 -23
  51. package/dist/size-rollup-dom-animation.js +1 -1
  52. package/dist/size-rollup-dom-max.js +1 -1
  53. package/dist/size-rollup-m.js +1 -1
  54. package/package.json +179 -158
  55. package/types/components/Reorder/Item.d.ts +1 -1
  56. package/types/index.d.ts +1 -0
  57. package/types/motion/features/types.d.ts +1 -1
  58. package/types/motion/features/viewport/types.d.ts +1 -1
  59. package/types/render/three/create-visual-element.d.ts +6 -0
  60. package/types/render/three/gestures/use-hover.d.ts +10 -0
  61. package/types/render/three/gestures/use-tap.d.ts +8 -0
  62. package/types/render/three/motion.d.ts +5 -0
  63. package/types/render/three/types.d.ts +24 -0
  64. package/types/render/three/use-render.d.ts +4 -0
  65. package/types/render/three/utils/read-value.d.ts +2 -0
  66. package/types/render/three/utils/set-value.d.ts +2 -0
  67. package/types/render/utils/animation-state.d.ts +1 -1
  68. package/types/render/utils/lifecycles.d.ts +8 -8
  69. package/types/render/utils/setters.d.ts +1 -0
  70. package/types/three-entry.d.ts +1 -0
  71. package/types/utils/use-instant-transition-state.d.ts +3 -0
  72. package/types/utils/use-instant-transition.d.ts +1 -0
  73. package/CHANGELOG.md +0 -1953
@@ -34,7 +34,7 @@ var correctBorderRadius = {
34
34
  */
35
35
  var x = pixelsToPercent(latest, node.target.x);
36
36
  var y = pixelsToPercent(latest, node.target.y);
37
- return x + "% " + y + "%";
37
+ return "".concat(x, "% ").concat(y, "%");
38
38
  },
39
39
  };
40
40
 
@@ -8,17 +8,17 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
8
8
  */
9
9
  var xTranslate = delta.x.translate / treeScale.x;
10
10
  var yTranslate = delta.y.translate / treeScale.y;
11
- var transform = "translate3d(" + xTranslate + "px, " + yTranslate + "px, 0) ";
11
+ var transform = "translate3d(".concat(xTranslate, "px, ").concat(yTranslate, "px, 0) ");
12
12
  if (latestTransform) {
13
13
  var rotate = latestTransform.rotate, rotateX = latestTransform.rotateX, rotateY = latestTransform.rotateY;
14
14
  if (rotate)
15
- transform += "rotate(" + rotate + "deg) ";
15
+ transform += "rotate(".concat(rotate, "deg) ");
16
16
  if (rotateX)
17
- transform += "rotateX(" + rotateX + "deg) ";
17
+ transform += "rotateX(".concat(rotateX, "deg) ");
18
18
  if (rotateY)
19
- transform += "rotateY(" + rotateY + "deg) ";
19
+ transform += "rotateY(".concat(rotateY, "deg) ");
20
20
  }
21
- transform += "scale(" + delta.x.scale + ", " + delta.y.scale + ")";
21
+ transform += "scale(".concat(delta.x.scale, ", ").concat(delta.y.scale, ")");
22
22
  return transform === identityProjection ? "none" : transform;
23
23
  }
24
24
 
@@ -19,6 +19,9 @@ function createMotionProxy(createConfig) {
19
19
  if (customMotionComponentConfig === void 0) { customMotionComponentConfig = {}; }
20
20
  return createMotionComponent(createConfig(Component, customMotionComponentConfig));
21
21
  }
22
+ if (typeof Proxy === "undefined") {
23
+ return custom;
24
+ }
22
25
  /**
23
26
  * A cache of generated `motion` components, e.g `motion.div`, `motion.input` etc.
24
27
  * Rather than generating them anew every render.
@@ -24,7 +24,7 @@ function parseCSSVariable(current) {
24
24
  var maxDepth = 4;
25
25
  function getVariableValue(current, element, depth) {
26
26
  if (depth === void 0) { depth = 1; }
27
- invariant(depth <= maxDepth, "Max CSS variable fallback depth detected in property \"" + current + "\". This may indicate a circular fallback dependency.");
27
+ invariant(depth <= maxDepth, "Max CSS variable fallback depth detected in property \"".concat(current, "\". This may indicate a circular fallback dependency."));
28
28
  var _a = __read(parseCSSVariable(current), 2), token = _a[0], fallback = _a[1];
29
29
  // No CSS variable detected
30
30
  if (!token)
@@ -51,7 +51,7 @@ function resolveCSSVariables(visualElement, _a, transitionEnd) {
51
51
  var _b;
52
52
  var target = __rest(_a, []);
53
53
  var element = visualElement.getInstance();
54
- if (!(element instanceof HTMLElement))
54
+ if (!(element instanceof Element))
55
55
  return { target: target, transitionEnd: transitionEnd };
56
56
  // If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
57
57
  // only if they change but I think this reads clearer and this isn't a performance-critical path.
@@ -34,7 +34,9 @@ function filterProps(props, isDom, forwardMotionProps) {
34
34
  for (var key in props) {
35
35
  if (shouldForward(key) ||
36
36
  (forwardMotionProps === true && isValidMotionProp(key)) ||
37
- (!isDom && !isValidMotionProp(key))) {
37
+ (!isDom && !isValidMotionProp(key)) ||
38
+ // If trying to use native HTML drag events, forward drag listeners
39
+ (props["draggable"] && key.startsWith("onDrag"))) {
38
40
  filteredProps[key] = props[key];
39
41
  }
40
42
  }
@@ -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 };
@@ -38,17 +38,19 @@ function useHTMLProps(props, visualState, isStatic) {
38
38
  // The `any` isn't ideal but it is the type of createElement props argument
39
39
  var htmlProps = {};
40
40
  var style = useStyle(props, visualState, isStatic);
41
- if (Boolean(props.drag)) {
41
+ if (Boolean(props.drag) && props.dragListener !== false) {
42
42
  // Disable the ghost element when a user drags
43
43
  htmlProps.draggable = false;
44
44
  // Disable text selection
45
- style.userSelect = style.WebkitUserSelect = style.WebkitTouchCallout =
46
- "none";
45
+ style.userSelect =
46
+ style.WebkitUserSelect =
47
+ style.WebkitTouchCallout =
48
+ "none";
47
49
  // Disable scrolling on the draggable direction
48
50
  style.touchAction =
49
51
  props.drag === true
50
52
  ? "none"
51
- : "pan-" + (props.drag === "x" ? "y" : "x");
53
+ : "pan-".concat(props.drag === "x" ? "y" : "x");
52
54
  }
53
55
  htmlProps.style = style;
54
56
  return htmlProps;
@@ -26,7 +26,7 @@ function buildTransform(_a, _b, transformIsDefault, transformTemplate) {
26
26
  var numTransformKeys = transformKeys.length;
27
27
  for (var i = 0; i < numTransformKeys; i++) {
28
28
  var key = transformKeys[i];
29
- transformString += (translateAlias[key] || key) + "(" + transform[key] + ") ";
29
+ transformString += "".concat(translateAlias[key] || key, "(").concat(transform[key], ") ");
30
30
  if (key === "z")
31
31
  transformHasZ = true;
32
32
  }
@@ -52,7 +52,7 @@ function buildTransform(_a, _b, transformIsDefault, transformTemplate) {
52
52
  */
53
53
  function buildTransformOrigin(_a) {
54
54
  var _b = _a.originX, originX = _b === void 0 ? "50%" : _b, _c = _a.originY, originY = _c === void 0 ? "50%" : _c, _d = _a.originZ, originZ = _d === void 0 ? 0 : _d;
55
- return originX + " " + originY + " " + originZ;
55
+ return "".concat(originX, " ").concat(originY, " ").concat(originZ);
56
56
  }
57
57
 
58
58
  export { buildTransform, buildTransformOrigin };
@@ -29,7 +29,7 @@ function buildSVGPath(attrs, length, spacing, offset, useDashCase) {
29
29
  // Build the dash array
30
30
  var pathLength = px.transform(length);
31
31
  var pathSpacing = px.transform(spacing);
32
- attrs[keys.array] = pathLength + " " + pathSpacing;
32
+ attrs[keys.array] = "".concat(pathLength, " ").concat(pathSpacing);
33
33
  }
34
34
 
35
35
  export { buildSVGPath };
@@ -12,7 +12,7 @@ function calcOrigin(origin, offset, size) {
12
12
  function calcSVGTransformOrigin(dimensions, originX, originY) {
13
13
  var pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
14
14
  var pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
15
- return pxOriginX + " " + pxOriginY;
15
+ return "".concat(pxOriginX, " ").concat(pxOriginY);
16
16
  }
17
17
 
18
18
  export { calcSVGTransformOrigin };
@@ -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 };
@@ -135,7 +135,8 @@ function createAnimationState(visualElement) {
135
135
  * a changed value or a value that was removed in a higher priority, we set
136
136
  * this to true and add this prop to the animation list.
137
137
  */
138
- var shouldAnimateType = variantsHaveChanged(typeState.prevProp, prop) ||
138
+ var variantDidChange = checkVariantsDidChange(typeState.prevProp, prop);
139
+ var shouldAnimateType = variantDidChange ||
139
140
  // If we're making this variant active, we want to always make it active
140
141
  (type === changedActiveType &&
141
142
  typeState.isActive &&
@@ -186,7 +187,7 @@ function createAnimationState(visualElement) {
186
187
  * detect whether any value has changed. If it has, we animate it.
187
188
  */
188
189
  if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
189
- if (!shallowCompare(next, prev)) {
190
+ if (!shallowCompare(next, prev) || variantDidChange) {
190
191
  markToAnimate(key);
191
192
  }
192
193
  else {
@@ -303,7 +304,7 @@ function createAnimationState(visualElement) {
303
304
  getState: function () { return state; },
304
305
  };
305
306
  }
306
- function variantsHaveChanged(prev, next) {
307
+ function checkVariantsDidChange(prev, next) {
307
308
  if (typeof next === "string") {
308
309
  return next !== prev;
309
310
  }
@@ -334,4 +335,4 @@ function createState() {
334
335
  _a;
335
336
  }
336
337
 
337
- export { createAnimationState, variantPriorityOrder, variantsHaveChanged };
338
+ export { checkVariantsDidChange, createAnimationState, variantPriorityOrder };
@@ -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';
@@ -22,37 +22,13 @@ function setMotionValue(visualElement, key, value) {
22
22
  }
23
23
  function setTarget(visualElement, definition) {
24
24
  var resolved = resolveVariant(visualElement, definition);
25
- var _a = resolved
26
- ? visualElement.makeTargetAnimatable(resolved, false)
27
- : {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = __rest(_a, ["transitionEnd", "transition"]);
25
+ var _a = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = __rest(_a, ["transitionEnd", "transition"]);
28
26
  target = __assign(__assign({}, target), transitionEnd);
29
27
  for (var key in target) {
30
28
  var value = resolveFinalValueInKeyframes(target[key]);
31
29
  setMotionValue(visualElement, key, value);
32
30
  }
33
31
  }
34
- function setVariants(visualElement, variantLabels) {
35
- var reversedLabels = __spreadArray([], __read(variantLabels), false).reverse();
36
- reversedLabels.forEach(function (key) {
37
- var _a;
38
- var variant = visualElement.getVariant(key);
39
- variant && setTarget(visualElement, variant);
40
- (_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
41
- setVariants(child, variantLabels);
42
- });
43
- });
44
- }
45
- function setValues(visualElement, definition) {
46
- if (Array.isArray(definition)) {
47
- return setVariants(visualElement, definition);
48
- }
49
- else if (typeof definition === "string") {
50
- return setVariants(visualElement, [definition]);
51
- }
52
- else {
53
- setTarget(visualElement, definition);
54
- }
55
- }
56
32
  function checkTargetForNewValues(visualElement, target, origin) {
57
33
  var _a, _b, _c;
58
34
  var _d;
@@ -98,20 +74,5 @@ function checkTargetForNewValues(visualElement, target, origin) {
98
74
  visualElement.setBaseTarget(key, value);
99
75
  }
100
76
  }
101
- function getOriginFromTransition(key, transition) {
102
- if (!transition)
103
- return;
104
- var valueTransition = transition[key] || transition["default"] || transition;
105
- return valueTransition.from;
106
- }
107
- function getOrigin(target, transition, visualElement) {
108
- var _a, _b;
109
- var origin = {};
110
- for (var key in target) {
111
- origin[key] =
112
- (_a = getOriginFromTransition(key, transition)) !== null && _a !== void 0 ? _a : (_b = visualElement.getValue(key)) === null || _b === void 0 ? void 0 : _b.get();
113
- }
114
- return origin;
115
- }
116
77
 
117
- 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 };
@@ -1,17 +1,21 @@
1
1
  import { __read } from 'tslib';
2
- import { useCallback, useRef, useState } from 'react';
2
+ import sync from 'framesync';
3
+ import { useRef, useState, useCallback } from 'react';
3
4
  import { useUnmountEffect } from './use-unmount-effect.mjs';
4
5
 
5
6
  function useForceUpdate() {
6
- var unloadingRef = useRef(false);
7
+ var isUnmountingRef = useRef(false);
7
8
  var _a = __read(useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
8
- useUnmountEffect(function () { return (unloadingRef.current = true); });
9
- return [
10
- useCallback(function () {
11
- !unloadingRef.current && setForcedRenderCount(forcedRenderCount + 1);
12
- }, [forcedRenderCount]),
13
- forcedRenderCount,
14
- ];
9
+ useUnmountEffect(function () { return (isUnmountingRef.current = true); });
10
+ var forceRender = useCallback(function () {
11
+ !isUnmountingRef.current && setForcedRenderCount(forcedRenderCount + 1);
12
+ }, [forcedRenderCount]);
13
+ /**
14
+ * Defer this to the end of the next animation frame in case there are multiple
15
+ * synchronous calls.
16
+ */
17
+ var deferredForceRender = useCallback(function () { return sync.postRender(forceRender); }, [forceRender]);
18
+ return [deferredForceRender, forcedRenderCount];
15
19
  }
16
20
 
17
21
  export { useForceUpdate };
@@ -0,0 +1,5 @@
1
+ var instantAnimationState = {
2
+ current: false,
3
+ };
4
+
5
+ export { instantAnimationState };
@@ -0,0 +1,28 @@
1
+ import { __read } from 'tslib';
2
+ import sync from 'framesync';
3
+ import { useEffect } from 'react';
4
+ import { useInstantLayoutTransition } from '../projection/use-instant-layout-transition.mjs';
5
+ import { useForceUpdate } from './use-force-update.mjs';
6
+ import { instantAnimationState } from './use-instant-transition-state.mjs';
7
+
8
+ function useInstantTransition() {
9
+ var _a = __read(useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
10
+ var startInstantLayoutTransition = useInstantLayoutTransition();
11
+ useEffect(function () {
12
+ /**
13
+ * Unblock after two animation frames, otherwise this will unblock too soon.
14
+ */
15
+ sync.postRender(function () {
16
+ return sync.postRender(function () { return (instantAnimationState.current = false); });
17
+ });
18
+ }, [forcedRenderCount]);
19
+ return function (callback) {
20
+ startInstantLayoutTransition(function () {
21
+ instantAnimationState.current = true;
22
+ forceUpdate();
23
+ callback();
24
+ });
25
+ };
26
+ }
27
+
28
+ export { useInstantTransition };