framer-motion 5.3.0 → 5.3.1

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.
@@ -2127,6 +2127,18 @@
2127
2127
  return (_a = defaultValueType.getAnimatableNone) === null || _a === void 0 ? void 0 : _a.call(defaultValueType, value);
2128
2128
  }
2129
2129
 
2130
+ var instantAnimationState = {
2131
+ current: false,
2132
+ };
2133
+
2134
+ var isCustomValue = function (v) {
2135
+ return Boolean(v && typeof v === "object" && v.mix && v.toValue);
2136
+ };
2137
+ var resolveFinalValueInKeyframes = function (v) {
2138
+ // TODO maybe throw if v.length - 1 is placeholder token?
2139
+ return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
2140
+ };
2141
+
2130
2142
  /**
2131
2143
  * Decide whether a transition is defined on a given Transition.
2132
2144
  * This filters out orchestration options and returns true
@@ -2268,9 +2280,10 @@
2268
2280
  }
2269
2281
  function set() {
2270
2282
  var _a, _b;
2271
- value.set(target);
2283
+ var finalTarget = resolveFinalValueInKeyframes(target);
2284
+ value.set(finalTarget);
2272
2285
  onComplete();
2273
- (_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, target);
2286
+ (_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, finalTarget);
2274
2287
  (_b = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onComplete) === null || _b === void 0 ? void 0 : _b.call(valueTransition);
2275
2288
  return { stop: function () { } };
2276
2289
  }
@@ -2302,6 +2315,9 @@
2302
2315
  */
2303
2316
  function startAnimation(key, value, target, transition) {
2304
2317
  if (transition === void 0) { transition = {}; }
2318
+ if (instantAnimationState.current) {
2319
+ transition = { type: false };
2320
+ }
2305
2321
  return value.start(function (onComplete) {
2306
2322
  var delayTimer;
2307
2323
  var controls;
@@ -2916,14 +2932,6 @@
2916
2932
  return FlatTree;
2917
2933
  }());
2918
2934
 
2919
- var isCustomValue = function (v) {
2920
- return Boolean(v && typeof v === "object" && v.mix && v.toValue);
2921
- };
2922
- var resolveFinalValueInKeyframes = function (v) {
2923
- // TODO maybe throw if v.length - 1 is placeholder token?
2924
- return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
2925
- };
2926
-
2927
2935
  /**
2928
2936
  * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
2929
2937
  *
@@ -4568,6 +4576,7 @@
4568
4576
  "inherit",
4569
4577
  "layout",
4570
4578
  "layoutId",
4579
+ "layoutDependency",
4571
4580
  "onLayoutAnimationComplete",
4572
4581
  "onLayoutMeasure",
4573
4582
  "onBeforeLayoutMeasure",
@@ -4869,13 +4878,17 @@
4869
4878
  }
4870
4879
  return state;
4871
4880
  }
4872
- var makeUseVisualState = function (config) { return function (props, isStatic) {
4873
- var context = React.useContext(MotionContext);
4874
- var presenceContext = React.useContext(PresenceContext);
4875
- return isStatic
4876
- ? makeState(config, props, context, presenceContext)
4877
- : useConstant(function () { return makeState(config, props, context, presenceContext); });
4878
- }; };
4881
+ var makeUseVisualState = function (config) {
4882
+ return function (props, isStatic) {
4883
+ var context = React.useContext(MotionContext);
4884
+ var presenceContext = React.useContext(PresenceContext);
4885
+ return isStatic
4886
+ ? makeState(config, props, context, presenceContext)
4887
+ : useConstant(function () {
4888
+ return makeState(config, props, context, presenceContext);
4889
+ });
4890
+ };
4891
+ };
4879
4892
  function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
4880
4893
  var values = {};
4881
4894
  var blockInitialAnimation = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false;
@@ -4893,7 +4906,8 @@
4893
4906
  initial !== null && initial !== void 0 ? initial : (initial = context.initial);
4894
4907
  animate !== null && animate !== void 0 ? animate : (animate = context.animate);
4895
4908
  }
4896
- var variantToSet = blockInitialAnimation || initial === false ? animate : initial;
4909
+ var initialAnimationIsBlocked = blockInitialAnimation || initial === false;
4910
+ var variantToSet = initialAnimationIsBlocked ? animate : initial;
4897
4911
  if (variantToSet &&
4898
4912
  typeof variantToSet !== "boolean" &&
4899
4913
  !isAnimationControls(variantToSet)) {
@@ -4903,8 +4917,22 @@
4903
4917
  if (!resolved)
4904
4918
  return;
4905
4919
  var transitionEnd = resolved.transitionEnd; resolved.transition; var target = __rest(resolved, ["transitionEnd", "transition"]);
4906
- for (var key in target)
4907
- values[key] = target[key];
4920
+ for (var key in target) {
4921
+ var valueTarget = target[key];
4922
+ if (Array.isArray(valueTarget)) {
4923
+ /**
4924
+ * Take final keyframe if the initial animation is blocked because
4925
+ * we want to initialise at the end of that blocked animation.
4926
+ */
4927
+ var index = initialAnimationIsBlocked
4928
+ ? valueTarget.length - 1
4929
+ : 0;
4930
+ valueTarget = valueTarget[index];
4931
+ }
4932
+ if (valueTarget !== null) {
4933
+ values[key] = valueTarget;
4934
+ }
4935
+ }
4908
4936
  for (var key in transitionEnd)
4909
4937
  values[key] = transitionEnd[key];
4910
4938
  });
@@ -5185,8 +5213,11 @@
5185
5213
  var _a;
5186
5214
  if (!isMouseEvent(event) || isDragActive())
5187
5215
  return;
5188
- callback === null || callback === void 0 ? void 0 : callback(event, info);
5216
+ /**
5217
+ * Ensure we trigger animations before firing event callback
5218
+ */
5189
5219
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Hover, isActive);
5220
+ callback === null || callback === void 0 ? void 0 : callback(event, info);
5190
5221
  };
5191
5222
  }
5192
5223
  function useHoverGesture(_a) {
@@ -5266,8 +5297,11 @@
5266
5297
  return;
5267
5298
  isPressing.current = true;
5268
5299
  cancelPointerEndListeners.current = pipe(addPointerEvent(window, "pointerup", onPointerUp), addPointerEvent(window, "pointercancel", onPointerCancel));
5269
- onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
5300
+ /**
5301
+ * Ensure we trigger animations before firing event callback
5302
+ */
5270
5303
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Tap, true);
5304
+ onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
5271
5305
  }
5272
5306
  usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined);
5273
5307
  useUnmountEffect(removePointerEndListener);
@@ -5571,9 +5605,7 @@
5571
5605
  }
5572
5606
  function setTarget(visualElement, definition) {
5573
5607
  var resolved = resolveVariant(visualElement, definition);
5574
- var _a = resolved
5575
- ? visualElement.makeTargetAnimatable(resolved, false)
5576
- : {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = __rest(_a, ["transitionEnd", "transition"]);
5608
+ var _a = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = __rest(_a, ["transitionEnd", "transition"]);
5577
5609
  target = __assign(__assign({}, target), transitionEnd);
5578
5610
  for (var key in target) {
5579
5611
  var value = resolveFinalValueInKeyframes(target[key]);
@@ -5927,7 +5959,8 @@
5927
5959
  * a changed value or a value that was removed in a higher priority, we set
5928
5960
  * this to true and add this prop to the animation list.
5929
5961
  */
5930
- var shouldAnimateType = variantsHaveChanged(typeState.prevProp, prop) ||
5962
+ var variantDidChange = checkVariantsDidChange(typeState.prevProp, prop);
5963
+ var shouldAnimateType = variantDidChange ||
5931
5964
  // If we're making this variant active, we want to always make it active
5932
5965
  (type === changedActiveType &&
5933
5966
  typeState.isActive &&
@@ -5978,7 +6011,7 @@
5978
6011
  * detect whether any value has changed. If it has, we animate it.
5979
6012
  */
5980
6013
  if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
5981
- if (!shallowCompare(next, prev)) {
6014
+ if (!shallowCompare(next, prev) || variantDidChange) {
5982
6015
  markToAnimate(key);
5983
6016
  }
5984
6017
  else {
@@ -6095,7 +6128,7 @@
6095
6128
  getState: function () { return state; },
6096
6129
  };
6097
6130
  }
6098
- function variantsHaveChanged(prev, next) {
6131
+ function checkVariantsDidChange(prev, next) {
6099
6132
  if (typeof next === "string") {
6100
6133
  return next !== prev;
6101
6134
  }
@@ -8748,7 +8781,7 @@
8748
8781
  return isMotionValue(value) ? value : useMotionValue(defaultValue);
8749
8782
  }
8750
8783
  function ReorderItem(_a, externalRef) {
8751
- var children = _a.children, style = _a.style, value = _a.value, _b = _a.as, as = _b === void 0 ? "li" : _b, props = __rest(_a, ["children", "style", "value", "as"]);
8784
+ var children = _a.children, style = _a.style, value = _a.value, _b = _a.as, as = _b === void 0 ? "li" : _b, onDrag = _a.onDrag, props = __rest(_a, ["children", "style", "value", "as", "onDrag"]);
8752
8785
  var Component = useConstant(function () { return motion(as); });
8753
8786
  var context = React.useContext(ReorderContext);
8754
8787
  var point = {
@@ -8765,10 +8798,11 @@
8765
8798
  React.useEffect(function () {
8766
8799
  registerItem(value, layout.current);
8767
8800
  }, [context]);
8768
- return (React__namespace.createElement(Component, __assign({ drag: axis }, props, { dragSnapToOrigin: true, style: __assign(__assign({}, style), { x: point.x, y: point.y, zIndex: zIndex }), layout: true, onDrag: function (_event, _a) {
8769
- var velocity = _a.velocity;
8801
+ return (React__namespace.createElement(Component, __assign({ drag: axis }, props, { dragSnapToOrigin: true, style: __assign(__assign({}, style), { x: point.x, y: point.y, zIndex: zIndex }), layout: true, onDrag: function (event, gesturePoint) {
8802
+ var velocity = gesturePoint.velocity;
8770
8803
  velocity[axis] &&
8771
8804
  updateOrder(value, point[axis].get(), velocity[axis]);
8805
+ onDrag === null || onDrag === void 0 ? void 0 : onDrag(event, gesturePoint);
8772
8806
  }, onLayoutMeasure: function (measured) {
8773
8807
  layout.current = measured;
8774
8808
  }, ref: externalRef }), children));
@@ -9330,6 +9364,26 @@
9330
9364
  cb === null || cb === void 0 ? void 0 : cb();
9331
9365
  }
9332
9366
 
9367
+ function useInstantTransition() {
9368
+ var _a = __read(useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
9369
+ var startInstantLayoutTransition = useInstantLayoutTransition();
9370
+ React.useEffect(function () {
9371
+ /**
9372
+ * Unblock after two animation frames, otherwise this will unblock too soon.
9373
+ */
9374
+ sync.postRender(function () {
9375
+ return sync.postRender(function () { return (instantAnimationState.current = false); });
9376
+ });
9377
+ }, [forcedRenderCount]);
9378
+ return function (callback) {
9379
+ startInstantLayoutTransition(function () {
9380
+ instantAnimationState.current = true;
9381
+ forceUpdate();
9382
+ callback();
9383
+ });
9384
+ };
9385
+ }
9386
+
9333
9387
  function useResetProjection() {
9334
9388
  var reset = React__namespace.useCallback(function () {
9335
9389
  var root = rootProjectionNode.current;
@@ -9473,6 +9527,7 @@
9473
9527
  exports.useDragControls = useDragControls;
9474
9528
  exports.useElementScroll = useElementScroll;
9475
9529
  exports.useInstantLayoutTransition = useInstantLayoutTransition;
9530
+ exports.useInstantTransition = useInstantTransition;
9476
9531
  exports.useIsPresent = useIsPresent;
9477
9532
  exports.useMotionTemplate = useMotionTemplate;
9478
9533
  exports.useMotionValue = useMotionValue;