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
@@ -20,14 +20,12 @@ function _interopNamespace(e) {
20
20
  var d = Object.getOwnPropertyDescriptor(e, k);
21
21
  Object.defineProperty(n, k, d.get ? d : {
22
22
  enumerable: true,
23
- get: function () {
24
- return e[k];
25
- }
23
+ get: function () { return e[k]; }
26
24
  });
27
25
  }
28
26
  });
29
27
  }
30
- n['default'] = e;
28
+ n["default"] = e;
31
29
  return Object.freeze(n);
32
30
  }
33
31
 
@@ -438,7 +436,7 @@ var MotionValue = /** @class */ (function () {
438
436
  if (_this.lastUpdated !== timestamp) {
439
437
  _this.timeDelta = delta;
440
438
  _this.lastUpdated = timestamp;
441
- sync__default['default'].postRender(_this.scheduleVelocityCheck);
439
+ sync__default["default"].postRender(_this.scheduleVelocityCheck);
442
440
  }
443
441
  // Update update subscribers
444
442
  if (_this.prev !== _this.current) {
@@ -461,7 +459,7 @@ var MotionValue = /** @class */ (function () {
461
459
  *
462
460
  * @internal
463
461
  */
464
- this.scheduleVelocityCheck = function () { return sync__default['default'].postRender(_this.velocityCheck); };
462
+ this.scheduleVelocityCheck = function () { return sync__default["default"].postRender(_this.velocityCheck); };
465
463
  /**
466
464
  * Updates `prev` with `current` if the value hasn't been updated this frame.
467
465
  * This ensures velocity calculations return `0`.
@@ -713,7 +711,7 @@ var easingDefinitionToFunction = function (definition) {
713
711
  }
714
712
  else if (typeof definition === "string") {
715
713
  // Else lookup from table
716
- heyListen.invariant(easingLookup[definition] !== undefined, "Invalid easing type '" + definition + "'");
714
+ heyListen.invariant(easingLookup[definition] !== undefined, "Invalid easing type '".concat(definition, "'"));
717
715
  return easingLookup[definition];
718
716
  }
719
717
  return definition;
@@ -896,6 +894,18 @@ function getAnimatableNone(key, value) {
896
894
  return (_a = defaultValueType.getAnimatableNone) === null || _a === void 0 ? void 0 : _a.call(defaultValueType, value);
897
895
  }
898
896
 
897
+ var instantAnimationState = {
898
+ current: false,
899
+ };
900
+
901
+ var isCustomValue = function (v) {
902
+ return Boolean(v && typeof v === "object" && v.mix && v.toValue);
903
+ };
904
+ var resolveFinalValueInKeyframes = function (v) {
905
+ // TODO maybe throw if v.length - 1 is placeholder token?
906
+ return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
907
+ };
908
+
899
909
  /**
900
910
  * Decide whether a transition is defined on a given Transition.
901
911
  * This filters out orchestration options and returns true
@@ -1013,7 +1023,7 @@ function getAnimation(key, value, target, transition, onComplete) {
1013
1023
  target = getZeroUnit(origin);
1014
1024
  }
1015
1025
  var isOriginAnimatable = isAnimatable(key, origin);
1016
- heyListen.warning(isOriginAnimatable === isTargetAnimatable, "You are trying to animate " + key + " from \"" + origin + "\" to \"" + target + "\". " + origin + " is not an animatable value - to enable this animation set " + origin + " to a value animatable to " + target + " via the `style` property.");
1026
+ heyListen.warning(isOriginAnimatable === isTargetAnimatable, "You are trying to animate ".concat(key, " from \"").concat(origin, "\" to \"").concat(target, "\". ").concat(origin, " is not an animatable value - to enable this animation set ").concat(origin, " to a value animatable to ").concat(target, " via the `style` property."));
1017
1027
  function start() {
1018
1028
  var options = {
1019
1029
  from: origin,
@@ -1037,9 +1047,10 @@ function getAnimation(key, value, target, transition, onComplete) {
1037
1047
  }
1038
1048
  function set() {
1039
1049
  var _a, _b;
1040
- value.set(target);
1050
+ var finalTarget = resolveFinalValueInKeyframes(target);
1051
+ value.set(finalTarget);
1041
1052
  onComplete();
1042
- (_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, target);
1053
+ (_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, finalTarget);
1043
1054
  (_b = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onComplete) === null || _b === void 0 ? void 0 : _b.call(valueTransition);
1044
1055
  return { stop: function () { } };
1045
1056
  }
@@ -1071,6 +1082,9 @@ function getValueTransition(transition, key) {
1071
1082
  */
1072
1083
  function startAnimation(key, value, target, transition) {
1073
1084
  if (transition === void 0) { transition = {}; }
1085
+ if (instantAnimationState.current) {
1086
+ transition = { type: false };
1087
+ }
1074
1088
  return value.start(function (onComplete) {
1075
1089
  var delayTimer;
1076
1090
  var controls;
@@ -1145,7 +1159,7 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
1145
1159
  * Mix border radius
1146
1160
  */
1147
1161
  for (var i = 0; i < numBorders; i++) {
1148
- var borderLabel = "border" + borders[i] + "Radius";
1162
+ var borderLabel = "border".concat(borders[i], "Radius");
1149
1163
  var followRadius = getRadius(follow, borderLabel);
1150
1164
  var leadRadius = getRadius(lead, borderLabel);
1151
1165
  if (followRadius === undefined && leadRadius === undefined)
@@ -1602,17 +1616,17 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
1602
1616
  */
1603
1617
  var xTranslate = delta.x.translate / treeScale.x;
1604
1618
  var yTranslate = delta.y.translate / treeScale.y;
1605
- var transform = "translate3d(" + xTranslate + "px, " + yTranslate + "px, 0) ";
1619
+ var transform = "translate3d(".concat(xTranslate, "px, ").concat(yTranslate, "px, 0) ");
1606
1620
  if (latestTransform) {
1607
1621
  var rotate = latestTransform.rotate, rotateX = latestTransform.rotateX, rotateY = latestTransform.rotateY;
1608
1622
  if (rotate)
1609
- transform += "rotate(" + rotate + "deg) ";
1623
+ transform += "rotate(".concat(rotate, "deg) ");
1610
1624
  if (rotateX)
1611
- transform += "rotateX(" + rotateX + "deg) ";
1625
+ transform += "rotateX(".concat(rotateX, "deg) ");
1612
1626
  if (rotateY)
1613
- transform += "rotateY(" + rotateY + "deg) ";
1627
+ transform += "rotateY(".concat(rotateY, "deg) ");
1614
1628
  }
1615
- transform += "scale(" + delta.x.scale + ", " + delta.y.scale + ")";
1629
+ transform += "scale(".concat(delta.x.scale, ", ").concat(delta.y.scale, ")");
1616
1630
  return transform === identityProjection ? "none" : transform;
1617
1631
  }
1618
1632
 
@@ -1685,14 +1699,6 @@ var FlatTree = /** @class */ (function () {
1685
1699
  return FlatTree;
1686
1700
  }());
1687
1701
 
1688
- var isCustomValue = function (v) {
1689
- return Boolean(v && typeof v === "object" && v.mix && v.toValue);
1690
- };
1691
- var resolveFinalValueInKeyframes = function (v) {
1692
- // TODO maybe throw if v.length - 1 is placeholder token?
1693
- return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
1694
- };
1695
-
1696
1702
  /**
1697
1703
  * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
1698
1704
  *
@@ -2051,7 +2057,7 @@ function createProjectionNode(_a) {
2051
2057
  this.sharedNodes.forEach(removeLeadSnapshots);
2052
2058
  };
2053
2059
  ProjectionNode.prototype.scheduleUpdateProjection = function () {
2054
- sync__default['default'].preRender(this.updateProjection, false, true);
2060
+ sync__default["default"].preRender(this.updateProjection, false, true);
2055
2061
  };
2056
2062
  ProjectionNode.prototype.scheduleCheckAfterUnmount = function () {
2057
2063
  var _this = this;
@@ -2060,7 +2066,7 @@ function createProjectionNode(_a) {
2060
2066
  * we manually call didUpdate to give a chance to the siblings to animate.
2061
2067
  * Otherwise, cleanup all snapshots to prevents future nodes from reusing them.
2062
2068
  */
2063
- sync__default['default'].postRender(function () {
2069
+ sync__default["default"].postRender(function () {
2064
2070
  if (_this.isLayoutDirty) {
2065
2071
  _this.root.didUpdate();
2066
2072
  }
@@ -2460,7 +2466,7 @@ function createProjectionNode(_a) {
2460
2466
  * where the target is the same as when the animation started, so we can
2461
2467
  * calculate the relative positions correctly for instant transitions.
2462
2468
  */
2463
- this.pendingAnimation = sync__default['default'].update(function () {
2469
+ this.pendingAnimation = sync__default["default"].update(function () {
2464
2470
  globalProjectionState.hasAnimatedSinceResize = true;
2465
2471
  _this.currentAnimation = animate(0, animationTarget, tslib.__assign(tslib.__assign({}, options), { onUpdate: function (latest) {
2466
2472
  var _a;
@@ -2651,7 +2657,7 @@ function createProjectionNode(_a) {
2651
2657
  styles.transform = transformTemplate(valuesToRender, styles.transform);
2652
2658
  }
2653
2659
  var _g = this.projectionDelta, x = _g.x, y = _g.y;
2654
- styles.transformOrigin = x.origin * 100 + "% " + y.origin * 100 + "% 0";
2660
+ styles.transformOrigin = "".concat(x.origin * 100, "% ").concat(y.origin * 100, "% 0");
2655
2661
  if (lead.animationValues) {
2656
2662
  /**
2657
2663
  * If the lead component is animating, assign this either the entering/leaving
@@ -2857,7 +2863,7 @@ function mountNodeEarly(node, id) {
2857
2863
  }
2858
2864
  }
2859
2865
  var searchElement = searchNode && searchNode !== node.root ? searchNode.instance : document;
2860
- var element = searchElement.querySelector("[data-projection-id=\"" + id + "\"]");
2866
+ var element = searchElement.querySelector("[data-projection-id=\"".concat(id, "\"]"));
2861
2867
  if (element)
2862
2868
  node.mount(element, true);
2863
2869
  }
@@ -2940,7 +2946,7 @@ var VisualElementHandler = /** @class */ (function (_super) {
2940
2946
  return this.props.children;
2941
2947
  };
2942
2948
  return VisualElementHandler;
2943
- }(React__default['default'].Component));
2949
+ }(React__default["default"].Component));
2944
2950
 
2945
2951
  /**
2946
2952
  * Create a `motion` component.
@@ -3006,7 +3012,7 @@ function createMotionComponent(_a) {
3006
3012
  */
3007
3013
  return (React__namespace.createElement(VisualElementHandler, { visualElement: context.visualElement, props: tslib.__assign(tslib.__assign({}, config), props) },
3008
3014
  features,
3009
- React__namespace.createElement(MotionContext.Provider, { value: context }, useRender(Component, props, projectionId, useMotionRef(visualState, context.visualElement, externalRef), visualState, config.isStatic))));
3015
+ React__namespace.createElement(MotionContext.Provider, { value: context }, useRender(Component, props, projectionId, useMotionRef(visualState, context.visualElement, externalRef), visualState, config.isStatic, context.visualElement))));
3010
3016
  }
3011
3017
  return React.forwardRef(MotionComponent);
3012
3018
  }
@@ -3038,6 +3044,9 @@ function createMotionProxy(createConfig) {
3038
3044
  if (customMotionComponentConfig === void 0) { customMotionComponentConfig = {}; }
3039
3045
  return createMotionComponent(createConfig(Component, customMotionComponentConfig));
3040
3046
  }
3047
+ if (typeof Proxy === "undefined") {
3048
+ return custom;
3049
+ }
3041
3050
  /**
3042
3051
  * A cache of generated `motion` components, e.g `motion.div`, `motion.input` etc.
3043
3052
  * Rather than generating them anew every render.
@@ -3154,7 +3163,7 @@ function buildTransform(_a, _b, transformIsDefault, transformTemplate) {
3154
3163
  var numTransformKeys = transformKeys.length;
3155
3164
  for (var i = 0; i < numTransformKeys; i++) {
3156
3165
  var key = transformKeys[i];
3157
- transformString += (translateAlias[key] || key) + "(" + transform[key] + ") ";
3166
+ transformString += "".concat(translateAlias[key] || key, "(").concat(transform[key], ") ");
3158
3167
  if (key === "z")
3159
3168
  transformHasZ = true;
3160
3169
  }
@@ -3180,7 +3189,7 @@ function buildTransform(_a, _b, transformIsDefault, transformTemplate) {
3180
3189
  */
3181
3190
  function buildTransformOrigin(_a) {
3182
3191
  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;
3183
- return originX + " " + originY + " " + originZ;
3192
+ return "".concat(originX, " ").concat(originY, " ").concat(originZ);
3184
3193
  }
3185
3194
 
3186
3195
  /**
@@ -3302,17 +3311,19 @@ function useHTMLProps(props, visualState, isStatic) {
3302
3311
  // The `any` isn't ideal but it is the type of createElement props argument
3303
3312
  var htmlProps = {};
3304
3313
  var style = useStyle(props, visualState, isStatic);
3305
- if (Boolean(props.drag)) {
3314
+ if (Boolean(props.drag) && props.dragListener !== false) {
3306
3315
  // Disable the ghost element when a user drags
3307
3316
  htmlProps.draggable = false;
3308
3317
  // Disable text selection
3309
- style.userSelect = style.WebkitUserSelect = style.WebkitTouchCallout =
3310
- "none";
3318
+ style.userSelect =
3319
+ style.WebkitUserSelect =
3320
+ style.WebkitTouchCallout =
3321
+ "none";
3311
3322
  // Disable scrolling on the draggable direction
3312
3323
  style.touchAction =
3313
3324
  props.drag === true
3314
3325
  ? "none"
3315
- : "pan-" + (props.drag === "x" ? "y" : "x");
3326
+ : "pan-".concat(props.drag === "x" ? "y" : "x");
3316
3327
  }
3317
3328
  htmlProps.style = style;
3318
3329
  return htmlProps;
@@ -3337,6 +3348,7 @@ var validMotionProps = new Set([
3337
3348
  "inherit",
3338
3349
  "layout",
3339
3350
  "layoutId",
3351
+ "layoutDependency",
3340
3352
  "onLayoutAnimationComplete",
3341
3353
  "onLayoutMeasure",
3342
3354
  "onBeforeLayoutMeasure",
@@ -3426,7 +3438,9 @@ function filterProps(props, isDom, forwardMotionProps) {
3426
3438
  for (var key in props) {
3427
3439
  if (shouldForward(key) ||
3428
3440
  (forwardMotionProps === true && isValidMotionProp(key)) ||
3429
- (!isDom && !isValidMotionProp(key))) {
3441
+ (!isDom && !isValidMotionProp(key)) ||
3442
+ // If trying to use native HTML drag events, forward drag listeners
3443
+ (props["draggable"] && key.startsWith("onDrag"))) {
3430
3444
  filteredProps[key] = props[key];
3431
3445
  }
3432
3446
  }
@@ -3445,7 +3459,7 @@ function calcOrigin$1(origin, offset, size) {
3445
3459
  function calcSVGTransformOrigin(dimensions, originX, originY) {
3446
3460
  var pxOriginX = calcOrigin$1(originX, dimensions.x, dimensions.width);
3447
3461
  var pxOriginY = calcOrigin$1(originY, dimensions.y, dimensions.height);
3448
- return pxOriginX + " " + pxOriginY;
3462
+ return "".concat(pxOriginX, " ").concat(pxOriginY);
3449
3463
  }
3450
3464
 
3451
3465
  var dashKeys = {
@@ -3477,7 +3491,7 @@ function buildSVGPath(attrs, length, spacing, offset, useDashCase) {
3477
3491
  // Build the dash array
3478
3492
  var pathLength = styleValueTypes.px.transform(length);
3479
3493
  var pathSpacing = styleValueTypes.px.transform(spacing);
3480
- attrs[keys.array] = pathLength + " " + pathSpacing;
3494
+ attrs[keys.array] = "".concat(pathLength, " ").concat(pathSpacing);
3481
3495
  }
3482
3496
 
3483
3497
  /**
@@ -3638,13 +3652,17 @@ function makeState(_a, props, context, presenceContext) {
3638
3652
  }
3639
3653
  return state;
3640
3654
  }
3641
- var makeUseVisualState = function (config) { return function (props, isStatic) {
3642
- var context = React.useContext(MotionContext);
3643
- var presenceContext = React.useContext(PresenceContext);
3644
- return isStatic
3645
- ? makeState(config, props, context, presenceContext)
3646
- : useConstant(function () { return makeState(config, props, context, presenceContext); });
3647
- }; };
3655
+ var makeUseVisualState = function (config) {
3656
+ return function (props, isStatic) {
3657
+ var context = React.useContext(MotionContext);
3658
+ var presenceContext = React.useContext(PresenceContext);
3659
+ return isStatic
3660
+ ? makeState(config, props, context, presenceContext)
3661
+ : useConstant(function () {
3662
+ return makeState(config, props, context, presenceContext);
3663
+ });
3664
+ };
3665
+ };
3648
3666
  function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
3649
3667
  var values = {};
3650
3668
  var blockInitialAnimation = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false;
@@ -3662,7 +3680,8 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
3662
3680
  initial !== null && initial !== void 0 ? initial : (initial = context.initial);
3663
3681
  animate !== null && animate !== void 0 ? animate : (animate = context.animate);
3664
3682
  }
3665
- var variantToSet = blockInitialAnimation || initial === false ? animate : initial;
3683
+ var initialAnimationIsBlocked = blockInitialAnimation || initial === false;
3684
+ var variantToSet = initialAnimationIsBlocked ? animate : initial;
3666
3685
  if (variantToSet &&
3667
3686
  typeof variantToSet !== "boolean" &&
3668
3687
  !isAnimationControls(variantToSet)) {
@@ -3672,8 +3691,22 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
3672
3691
  if (!resolved)
3673
3692
  return;
3674
3693
  var transitionEnd = resolved.transitionEnd; resolved.transition; var target = tslib.__rest(resolved, ["transitionEnd", "transition"]);
3675
- for (var key in target)
3676
- values[key] = target[key];
3694
+ for (var key in target) {
3695
+ var valueTarget = target[key];
3696
+ if (Array.isArray(valueTarget)) {
3697
+ /**
3698
+ * Take final keyframe if the initial animation is blocked because
3699
+ * we want to initialise at the end of that blocked animation.
3700
+ */
3701
+ var index = initialAnimationIsBlocked
3702
+ ? valueTarget.length - 1
3703
+ : 0;
3704
+ valueTarget = valueTarget[index];
3705
+ }
3706
+ if (valueTarget !== null) {
3707
+ values[key] = valueTarget;
3708
+ }
3709
+ }
3677
3710
  for (var key in transitionEnd)
3678
3711
  values[key] = transitionEnd[key];
3679
3712
  });
@@ -3954,8 +3987,11 @@ function createHoverEvent(visualElement, isActive, callback) {
3954
3987
  var _a;
3955
3988
  if (!isMouseEvent(event) || isDragActive())
3956
3989
  return;
3957
- callback === null || callback === void 0 ? void 0 : callback(event, info);
3990
+ /**
3991
+ * Ensure we trigger animations before firing event callback
3992
+ */
3958
3993
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Hover, isActive);
3994
+ callback === null || callback === void 0 ? void 0 : callback(event, info);
3959
3995
  };
3960
3996
  }
3961
3997
  function useHoverGesture(_a) {
@@ -4035,8 +4071,11 @@ function useTapGesture(_a) {
4035
4071
  return;
4036
4072
  isPressing.current = true;
4037
4073
  cancelPointerEndListeners.current = popmotion.pipe(addPointerEvent(window, "pointerup", onPointerUp), addPointerEvent(window, "pointercancel", onPointerCancel));
4038
- onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
4074
+ /**
4075
+ * Ensure we trigger animations before firing event callback
4076
+ */
4039
4077
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Tap, true);
4078
+ onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
4040
4079
  }
4041
4080
  usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined);
4042
4081
  useUnmountEffect(removePointerEndListener);
@@ -4157,7 +4196,7 @@ function useIntersectionObserver(shouldObserve, state, visualElement, _a) {
4157
4196
  var callback = isIntersecting
4158
4197
  ? props.onViewportEnter
4159
4198
  : props.onViewportLeave;
4160
- callback === null || callback === void 0 ? void 0 : callback();
4199
+ callback === null || callback === void 0 ? void 0 : callback(entry);
4161
4200
  };
4162
4201
  return observeIntersection(visualElement.getInstance(), options, intersectionCallback);
4163
4202
  }, [shouldObserve, root, rootMargin, amount]);
@@ -4186,7 +4225,7 @@ function useMissingIntersectionObserver(shouldObserve, state, visualElement) {
4186
4225
  var _a;
4187
4226
  state.hasEnteredView = true;
4188
4227
  var onViewportEnter = visualElement.getProps().onViewportEnter;
4189
- onViewportEnter === null || onViewportEnter === void 0 ? void 0 : onViewportEnter();
4228
+ onViewportEnter === null || onViewportEnter === void 0 ? void 0 : onViewportEnter(null);
4190
4229
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.InView, true);
4191
4230
  });
4192
4231
  }, [shouldObserve]);
@@ -4340,9 +4379,7 @@ function setMotionValue(visualElement, key, value) {
4340
4379
  }
4341
4380
  function setTarget(visualElement, definition) {
4342
4381
  var resolved = resolveVariant(visualElement, definition);
4343
- var _a = resolved
4344
- ? visualElement.makeTargetAnimatable(resolved, false)
4345
- : {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = tslib.__rest(_a, ["transitionEnd", "transition"]);
4382
+ var _a = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = tslib.__rest(_a, ["transitionEnd", "transition"]);
4346
4383
  target = tslib.__assign(tslib.__assign({}, target), transitionEnd);
4347
4384
  for (var key in target) {
4348
4385
  var value = resolveFinalValueInKeyframes(target[key]);
@@ -4696,7 +4733,8 @@ function createAnimationState(visualElement) {
4696
4733
  * a changed value or a value that was removed in a higher priority, we set
4697
4734
  * this to true and add this prop to the animation list.
4698
4735
  */
4699
- var shouldAnimateType = variantsHaveChanged(typeState.prevProp, prop) ||
4736
+ var variantDidChange = checkVariantsDidChange(typeState.prevProp, prop);
4737
+ var shouldAnimateType = variantDidChange ||
4700
4738
  // If we're making this variant active, we want to always make it active
4701
4739
  (type === changedActiveType &&
4702
4740
  typeState.isActive &&
@@ -4747,7 +4785,7 @@ function createAnimationState(visualElement) {
4747
4785
  * detect whether any value has changed. If it has, we animate it.
4748
4786
  */
4749
4787
  if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
4750
- if (!shallowCompare(next, prev)) {
4788
+ if (!shallowCompare(next, prev) || variantDidChange) {
4751
4789
  markToAnimate(key);
4752
4790
  }
4753
4791
  else {
@@ -4864,7 +4902,7 @@ function createAnimationState(visualElement) {
4864
4902
  getState: function () { return state; },
4865
4903
  };
4866
4904
  }
4867
- function variantsHaveChanged(prev, next) {
4905
+ function checkVariantsDidChange(prev, next) {
4868
4906
  if (typeof next === "string") {
4869
4907
  return next !== prev;
4870
4908
  }
@@ -4977,7 +5015,7 @@ var PanSession = /** @class */ (function () {
4977
5015
  return;
4978
5016
  }
4979
5017
  // Throttle mouse move event to once per frame
4980
- sync__default['default'].update(_this.updatePoint, true);
5018
+ sync__default["default"].update(_this.updatePoint, true);
4981
5019
  };
4982
5020
  this.handlePointerUp = function (event, info) {
4983
5021
  _this.end();
@@ -5882,7 +5920,7 @@ var visualElement = function (_a) {
5882
5920
  function bindToMotionValue(key, value) {
5883
5921
  var removeOnChange = value.onChange(function (latestValue) {
5884
5922
  latestValues[key] = latestValue;
5885
- props.onUpdate && sync__default['default'].update(update, false, true);
5923
+ props.onUpdate && sync__default["default"].update(update, false, true);
5886
5924
  });
5887
5925
  var removeOnRenderRequest = value.onRenderRequest(element.scheduleRender);
5888
5926
  valueSubscriptions.set(key, function () {
@@ -6141,7 +6179,7 @@ var visualElement = function (_a) {
6141
6179
  * Schedule a render on the next animation frame.
6142
6180
  */
6143
6181
  scheduleRender: function () {
6144
- sync__default['default'].render(render, false, true);
6182
+ sync__default["default"].render(render, false, true);
6145
6183
  },
6146
6184
  /**
6147
6185
  * Synchronously fire render. It's prefered that we batch renders but
@@ -6223,7 +6261,7 @@ function parseCSSVariable(current) {
6223
6261
  var maxDepth = 4;
6224
6262
  function getVariableValue(current, element, depth) {
6225
6263
  if (depth === void 0) { depth = 1; }
6226
- heyListen.invariant(depth <= maxDepth, "Max CSS variable fallback depth detected in property \"" + current + "\". This may indicate a circular fallback dependency.");
6264
+ heyListen.invariant(depth <= maxDepth, "Max CSS variable fallback depth detected in property \"".concat(current, "\". This may indicate a circular fallback dependency."));
6227
6265
  var _a = tslib.__read(parseCSSVariable(current), 2), token = _a[0], fallback = _a[1];
6228
6266
  // No CSS variable detected
6229
6267
  if (!token)
@@ -6250,7 +6288,7 @@ function resolveCSSVariables(visualElement, _a, transitionEnd) {
6250
6288
  var _b;
6251
6289
  var target = tslib.__rest(_a, []);
6252
6290
  var element = visualElement.getInstance();
6253
- if (!(element instanceof HTMLElement))
6291
+ if (!(element instanceof Element))
6254
6292
  return { target: target, transitionEnd: transitionEnd };
6255
6293
  // If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
6256
6294
  // only if they change but I think this reads clearer and this isn't a performance-critical path.
@@ -6697,7 +6735,7 @@ var correctBorderRadius = {
6697
6735
  */
6698
6736
  var x = pixelsToPercent(latest, node.target.x);
6699
6737
  var y = pixelsToPercent(latest, node.target.y);
6700
- return x + "% " + y + "%";
6738
+ return "".concat(x, "% ").concat(y, "%");
6701
6739
  },
6702
6740
  };
6703
6741
 
@@ -6815,7 +6853,7 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
6815
6853
  * it's in charge of the exit animation and therefore should
6816
6854
  * be in charge of the safe to remove. Otherwise we call it here.
6817
6855
  */
6818
- sync__default['default'].postRender(function () {
6856
+ sync__default["default"].postRender(function () {
6819
6857
  var _a;
6820
6858
  if (!((_a = projection.getStack()) === null || _a === void 0 ? void 0 : _a.members.length)) {
6821
6859
  _this.safeToRemove();
@@ -6853,11 +6891,11 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
6853
6891
  return null;
6854
6892
  };
6855
6893
  return MeasureLayoutWithContext;
6856
- }(React__default['default'].Component));
6894
+ }(React__default["default"].Component));
6857
6895
  function MeasureLayout(props) {
6858
6896
  var _a = tslib.__read(usePresence(), 2), isPresent = _a[0], safeToRemove = _a[1];
6859
6897
  var layoutGroup = React.useContext(LayoutGroupContext);
6860
- return (React__default['default'].createElement(MeasureLayoutWithContext, tslib.__assign({}, props, { layoutGroup: layoutGroup, switchLayoutGroup: React.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove })));
6898
+ return (React__default["default"].createElement(MeasureLayoutWithContext, tslib.__assign({}, props, { layoutGroup: layoutGroup, switchLayoutGroup: React.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove })));
6861
6899
  }
6862
6900
  var defaultScaleCorrectors = {
6863
6901
  borderRadius: tslib.__assign(tslib.__assign({}, correctBorderRadius), { applyTo: [
@@ -6945,15 +6983,18 @@ function createDomMotionComponent(key) {
6945
6983
  var m = createMotionProxy(createDomMotionConfig);
6946
6984
 
6947
6985
  function useForceUpdate() {
6948
- var unloadingRef = React.useRef(false);
6986
+ var isUnmountingRef = React.useRef(false);
6949
6987
  var _a = tslib.__read(React.useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
6950
- useUnmountEffect(function () { return (unloadingRef.current = true); });
6951
- return [
6952
- React.useCallback(function () {
6953
- !unloadingRef.current && setForcedRenderCount(forcedRenderCount + 1);
6954
- }, [forcedRenderCount]),
6955
- forcedRenderCount,
6956
- ];
6988
+ useUnmountEffect(function () { return (isUnmountingRef.current = true); });
6989
+ var forceRender = React.useCallback(function () {
6990
+ !isUnmountingRef.current && setForcedRenderCount(forcedRenderCount + 1);
6991
+ }, [forcedRenderCount]);
6992
+ /**
6993
+ * Defer this to the end of the next animation frame in case there are multiple
6994
+ * synchronous calls.
6995
+ */
6996
+ var deferredForceRender = React.useCallback(function () { return sync__default["default"].postRender(forceRender); }, [forceRender]);
6997
+ return [deferredForceRender, forcedRenderCount];
6957
6998
  }
6958
6999
 
6959
7000
  var presenceId = 0;
@@ -7026,7 +7067,7 @@ function updateChildLookup(children, allChildren) {
7026
7067
  var key = getChildKey(child);
7027
7068
  if (process.env.NODE_ENV !== "production" && seenChildren) {
7028
7069
  if (seenChildren.has(key)) {
7029
- console.warn("Children of AnimatePresence require unique keys. \"" + key + "\" is a duplicate.");
7070
+ console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
7030
7071
  }
7031
7072
  seenChildren.add(key);
7032
7073
  }
@@ -7227,7 +7268,7 @@ var LayoutGroup = function (_a) {
7227
7268
  var id = 0;
7228
7269
  var AnimateSharedLayout = function (_a) {
7229
7270
  var children = _a.children;
7230
- return (React__namespace.createElement(LayoutGroup, { id: useConstant(function () { return "asl-" + id++; }) }, children));
7271
+ return (React__namespace.createElement(LayoutGroup, { id: useConstant(function () { return "asl-".concat(id++); }) }, children));
7231
7272
  };
7232
7273
 
7233
7274
  /**
@@ -7486,7 +7527,7 @@ function useCombineMotionValues(values, combineValues) {
7486
7527
  * Subscribe to all motion values found within the template. Whenever any of them change,
7487
7528
  * schedule an update.
7488
7529
  */
7489
- useMultiOnChange(values, function () { return sync__default['default'].update(updateValue, false, true); });
7530
+ useMultiOnChange(values, function () { return sync__default["default"].update(updateValue, false, true); });
7490
7531
  return value;
7491
7532
  }
7492
7533
 
@@ -7518,7 +7559,7 @@ function useDefaultMotionValue(value, defaultValue) {
7518
7559
  return isMotionValue(value) ? value : useMotionValue(defaultValue);
7519
7560
  }
7520
7561
  function ReorderItem(_a, externalRef) {
7521
- var children = _a.children, style = _a.style, value = _a.value, _b = _a.as, as = _b === void 0 ? "li" : _b, props = tslib.__rest(_a, ["children", "style", "value", "as"]);
7562
+ var children = _a.children, style = _a.style, value = _a.value, _b = _a.as, as = _b === void 0 ? "li" : _b, onDrag = _a.onDrag, props = tslib.__rest(_a, ["children", "style", "value", "as", "onDrag"]);
7522
7563
  var Component = useConstant(function () { return motion(as); });
7523
7564
  var context = React.useContext(ReorderContext);
7524
7565
  var point = {
@@ -7527,7 +7568,7 @@ function ReorderItem(_a, externalRef) {
7527
7568
  };
7528
7569
  var zIndex = useTransform([point.x, point.y], function (_a) {
7529
7570
  var _b = tslib.__read(_a, 2), latestX = _b[0], latestY = _b[1];
7530
- return latestX || latestY ? 1 : 0;
7571
+ return latestX || latestY ? 1 : "unset";
7531
7572
  });
7532
7573
  var layout = React.useRef(null);
7533
7574
  heyListen.invariant(Boolean(context), "Reorder.Item must be a child of Reorder.Group");
@@ -7535,10 +7576,11 @@ function ReorderItem(_a, externalRef) {
7535
7576
  React.useEffect(function () {
7536
7577
  registerItem(value, layout.current);
7537
7578
  }, [context]);
7538
- return (React__namespace.createElement(Component, tslib.__assign({ drag: axis }, props, { dragSnapToOrigin: true, style: tslib.__assign(tslib.__assign({}, style), { x: point.x, y: point.y, zIndex: zIndex }), layout: true, onDrag: function (_event, _a) {
7539
- var velocity = _a.velocity;
7579
+ return (React__namespace.createElement(Component, tslib.__assign({ drag: axis }, props, { dragSnapToOrigin: true, style: tslib.__assign(tslib.__assign({}, style), { x: point.x, y: point.y, zIndex: zIndex }), layout: true, onDrag: function (event, gesturePoint) {
7580
+ var velocity = gesturePoint.velocity;
7540
7581
  velocity[axis] &&
7541
7582
  updateOrder(value, point[axis].get(), velocity[axis]);
7583
+ onDrag === null || onDrag === void 0 ? void 0 : onDrag(event, gesturePoint);
7542
7584
  }, onLayoutMeasure: function (measured) {
7543
7585
  layout.current = measured;
7544
7586
  }, ref: externalRef }), children));
@@ -8100,6 +8142,26 @@ function startTransition(cb) {
8100
8142
  cb === null || cb === void 0 ? void 0 : cb();
8101
8143
  }
8102
8144
 
8145
+ function useInstantTransition() {
8146
+ var _a = tslib.__read(useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
8147
+ var startInstantLayoutTransition = useInstantLayoutTransition();
8148
+ React.useEffect(function () {
8149
+ /**
8150
+ * Unblock after two animation frames, otherwise this will unblock too soon.
8151
+ */
8152
+ sync__default["default"].postRender(function () {
8153
+ return sync__default["default"].postRender(function () { return (instantAnimationState.current = false); });
8154
+ });
8155
+ }, [forcedRenderCount]);
8156
+ return function (callback) {
8157
+ startInstantLayoutTransition(function () {
8158
+ instantAnimationState.current = true;
8159
+ forceUpdate();
8160
+ callback();
8161
+ });
8162
+ };
8163
+ }
8164
+
8103
8165
  function useResetProjection() {
8104
8166
  var reset = React__namespace.useCallback(function () {
8105
8167
  var root = rootProjectionNode.current;
@@ -8243,6 +8305,7 @@ exports.useDomEvent = useDomEvent;
8243
8305
  exports.useDragControls = useDragControls;
8244
8306
  exports.useElementScroll = useElementScroll;
8245
8307
  exports.useInstantLayoutTransition = useInstantLayoutTransition;
8308
+ exports.useInstantTransition = useInstantTransition;
8246
8309
  exports.useIsPresent = useIsPresent;
8247
8310
  exports.useMotionTemplate = useMotionTemplate;
8248
8311
  exports.useMotionValue = useMotionValue;