framer-motion 5.2.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.
- package/dist/es/animation/utils/transitions.mjs +8 -2
- package/dist/es/components/Reorder/Item.mjs +4 -3
- package/dist/es/gestures/use-hover-gesture.mjs +4 -1
- package/dist/es/gestures/use-tap-gesture.mjs +4 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/features/definitions.mjs +6 -0
- package/dist/es/motion/features/gestures.mjs +2 -0
- package/dist/es/motion/features/viewport/observers.mjs +52 -0
- package/dist/es/motion/features/viewport/use-viewport.mjs +97 -0
- package/dist/es/motion/utils/use-visual-state.mjs +29 -10
- package/dist/es/motion/utils/valid-prop.mjs +5 -0
- package/dist/es/projection/node/create-projection-node.mjs +1 -1
- package/dist/es/render/dom/utils/unit-conversion.mjs +8 -1
- package/dist/es/render/utils/animation-state.mjs +7 -4
- package/dist/es/render/utils/setters.mjs +1 -3
- package/dist/es/render/utils/types.mjs +1 -0
- package/dist/es/utils/use-instant-transition-state.mjs +5 -0
- package/dist/es/utils/use-instant-transition.mjs +28 -0
- package/dist/es/utils/warn-once.mjs +11 -0
- package/dist/framer-motion.cjs.js +259 -33
- package/dist/framer-motion.dev.js +259 -33
- package/dist/framer-motion.js +1 -1
- package/dist/projection.dev.js +29 -8
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/package.json +11 -11
- package/types/components/Reorder/Item.d.ts +1 -1
- package/types/index.d.ts +1 -0
- package/types/motion/features/types.d.ts +2 -0
- package/types/motion/features/viewport/observers.d.ts +3 -0
- package/types/motion/features/viewport/types.d.ts +20 -0
- package/types/motion/features/viewport/use-viewport.d.ts +2 -0
- package/types/motion/types.d.ts +2 -1
- package/types/render/utils/animation-state.d.ts +1 -1
- package/types/render/utils/types.d.ts +1 -0
- package/types/utils/use-instant-transition-state.d.ts +3 -0
- package/types/utils/use-instant-transition.d.ts +1 -0
- package/types/utils/warn-once.d.ts +2 -0
|
@@ -48,6 +48,7 @@ var featureDefinitions = {
|
|
|
48
48
|
"whileTap",
|
|
49
49
|
"whileFocus",
|
|
50
50
|
"whileDrag",
|
|
51
|
+
"whileInView",
|
|
51
52
|
]),
|
|
52
53
|
exit: createDefinition(["exit"]),
|
|
53
54
|
drag: createDefinition(["drag", "dragControls"]),
|
|
@@ -60,6 +61,11 @@ var featureDefinitions = {
|
|
|
60
61
|
"onPanSessionStart",
|
|
61
62
|
"onPanEnd",
|
|
62
63
|
]),
|
|
64
|
+
inView: createDefinition([
|
|
65
|
+
"whileInView",
|
|
66
|
+
"onViewportEnter",
|
|
67
|
+
"onViewportLeave",
|
|
68
|
+
]),
|
|
63
69
|
};
|
|
64
70
|
function loadFeatures(features) {
|
|
65
71
|
for (var key in features) {
|
|
@@ -890,6 +896,18 @@ function getAnimatableNone(key, value) {
|
|
|
890
896
|
return (_a = defaultValueType.getAnimatableNone) === null || _a === void 0 ? void 0 : _a.call(defaultValueType, value);
|
|
891
897
|
}
|
|
892
898
|
|
|
899
|
+
var instantAnimationState = {
|
|
900
|
+
current: false,
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
var isCustomValue = function (v) {
|
|
904
|
+
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
905
|
+
};
|
|
906
|
+
var resolveFinalValueInKeyframes = function (v) {
|
|
907
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
908
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
909
|
+
};
|
|
910
|
+
|
|
893
911
|
/**
|
|
894
912
|
* Decide whether a transition is defined on a given Transition.
|
|
895
913
|
* This filters out orchestration options and returns true
|
|
@@ -1031,9 +1049,10 @@ function getAnimation(key, value, target, transition, onComplete) {
|
|
|
1031
1049
|
}
|
|
1032
1050
|
function set() {
|
|
1033
1051
|
var _a, _b;
|
|
1034
|
-
|
|
1052
|
+
var finalTarget = resolveFinalValueInKeyframes(target);
|
|
1053
|
+
value.set(finalTarget);
|
|
1035
1054
|
onComplete();
|
|
1036
|
-
(_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition,
|
|
1055
|
+
(_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, finalTarget);
|
|
1037
1056
|
(_b = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onComplete) === null || _b === void 0 ? void 0 : _b.call(valueTransition);
|
|
1038
1057
|
return { stop: function () { } };
|
|
1039
1058
|
}
|
|
@@ -1065,6 +1084,9 @@ function getValueTransition(transition, key) {
|
|
|
1065
1084
|
*/
|
|
1066
1085
|
function startAnimation(key, value, target, transition) {
|
|
1067
1086
|
if (transition === void 0) { transition = {}; }
|
|
1087
|
+
if (instantAnimationState.current) {
|
|
1088
|
+
transition = { type: false };
|
|
1089
|
+
}
|
|
1068
1090
|
return value.start(function (onComplete) {
|
|
1069
1091
|
var delayTimer;
|
|
1070
1092
|
var controls;
|
|
@@ -1679,14 +1701,6 @@ var FlatTree = /** @class */ (function () {
|
|
|
1679
1701
|
return FlatTree;
|
|
1680
1702
|
}());
|
|
1681
1703
|
|
|
1682
|
-
var isCustomValue = function (v) {
|
|
1683
|
-
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
1684
|
-
};
|
|
1685
|
-
var resolveFinalValueInKeyframes = function (v) {
|
|
1686
|
-
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
1687
|
-
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
1688
|
-
};
|
|
1689
|
-
|
|
1690
1704
|
/**
|
|
1691
1705
|
* If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
|
|
1692
1706
|
*
|
|
@@ -1988,7 +2002,7 @@ function createProjectionNode(_a) {
|
|
|
1988
2002
|
node.updateScroll();
|
|
1989
2003
|
}
|
|
1990
2004
|
var _d = this.options, layoutId = _d.layoutId, layout = _d.layout;
|
|
1991
|
-
if (
|
|
2005
|
+
if (layoutId === undefined && !layout)
|
|
1992
2006
|
return;
|
|
1993
2007
|
var transformTemplate = (_c = this.options.visualElement) === null || _c === void 0 ? void 0 : _c.getProps().transformTemplate;
|
|
1994
2008
|
this.prevTransformTemplateValue = transformTemplate === null || transformTemplate === void 0 ? void 0 : transformTemplate(this.latestValues, "");
|
|
@@ -3331,6 +3345,7 @@ var validMotionProps = new Set([
|
|
|
3331
3345
|
"inherit",
|
|
3332
3346
|
"layout",
|
|
3333
3347
|
"layoutId",
|
|
3348
|
+
"layoutDependency",
|
|
3334
3349
|
"onLayoutAnimationComplete",
|
|
3335
3350
|
"onLayoutMeasure",
|
|
3336
3351
|
"onBeforeLayoutMeasure",
|
|
@@ -3368,6 +3383,10 @@ var validMotionProps = new Set([
|
|
|
3368
3383
|
"whileFocus",
|
|
3369
3384
|
"whileTap",
|
|
3370
3385
|
"whileHover",
|
|
3386
|
+
"whileInView",
|
|
3387
|
+
"onViewportEnter",
|
|
3388
|
+
"onViewportLeave",
|
|
3389
|
+
"viewport",
|
|
3371
3390
|
"layoutScroll",
|
|
3372
3391
|
]);
|
|
3373
3392
|
/**
|
|
@@ -3628,13 +3647,17 @@ function makeState(_a, props, context, presenceContext) {
|
|
|
3628
3647
|
}
|
|
3629
3648
|
return state;
|
|
3630
3649
|
}
|
|
3631
|
-
var makeUseVisualState = function (config) {
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3650
|
+
var makeUseVisualState = function (config) {
|
|
3651
|
+
return function (props, isStatic) {
|
|
3652
|
+
var context = React.useContext(MotionContext);
|
|
3653
|
+
var presenceContext = React.useContext(PresenceContext);
|
|
3654
|
+
return isStatic
|
|
3655
|
+
? makeState(config, props, context, presenceContext)
|
|
3656
|
+
: useConstant(function () {
|
|
3657
|
+
return makeState(config, props, context, presenceContext);
|
|
3658
|
+
});
|
|
3659
|
+
};
|
|
3660
|
+
};
|
|
3638
3661
|
function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
3639
3662
|
var values = {};
|
|
3640
3663
|
var blockInitialAnimation = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false;
|
|
@@ -3652,7 +3675,8 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
3652
3675
|
initial !== null && initial !== void 0 ? initial : (initial = context.initial);
|
|
3653
3676
|
animate !== null && animate !== void 0 ? animate : (animate = context.animate);
|
|
3654
3677
|
}
|
|
3655
|
-
var
|
|
3678
|
+
var initialAnimationIsBlocked = blockInitialAnimation || initial === false;
|
|
3679
|
+
var variantToSet = initialAnimationIsBlocked ? animate : initial;
|
|
3656
3680
|
if (variantToSet &&
|
|
3657
3681
|
typeof variantToSet !== "boolean" &&
|
|
3658
3682
|
!isAnimationControls(variantToSet)) {
|
|
@@ -3662,8 +3686,22 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
3662
3686
|
if (!resolved)
|
|
3663
3687
|
return;
|
|
3664
3688
|
var transitionEnd = resolved.transitionEnd; resolved.transition; var target = tslib.__rest(resolved, ["transitionEnd", "transition"]);
|
|
3665
|
-
for (var key in target)
|
|
3666
|
-
|
|
3689
|
+
for (var key in target) {
|
|
3690
|
+
var valueTarget = target[key];
|
|
3691
|
+
if (Array.isArray(valueTarget)) {
|
|
3692
|
+
/**
|
|
3693
|
+
* Take final keyframe if the initial animation is blocked because
|
|
3694
|
+
* we want to initialise at the end of that blocked animation.
|
|
3695
|
+
*/
|
|
3696
|
+
var index = initialAnimationIsBlocked
|
|
3697
|
+
? valueTarget.length - 1
|
|
3698
|
+
: 0;
|
|
3699
|
+
valueTarget = valueTarget[index];
|
|
3700
|
+
}
|
|
3701
|
+
if (valueTarget !== null) {
|
|
3702
|
+
values[key] = valueTarget;
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3667
3705
|
for (var key in transitionEnd)
|
|
3668
3706
|
values[key] = transitionEnd[key];
|
|
3669
3707
|
});
|
|
@@ -3722,6 +3760,7 @@ var AnimationType;
|
|
|
3722
3760
|
AnimationType["Tap"] = "whileTap";
|
|
3723
3761
|
AnimationType["Drag"] = "whileDrag";
|
|
3724
3762
|
AnimationType["Focus"] = "whileFocus";
|
|
3763
|
+
AnimationType["InView"] = "whileInView";
|
|
3725
3764
|
AnimationType["Exit"] = "exit";
|
|
3726
3765
|
})(AnimationType || (AnimationType = {}));
|
|
3727
3766
|
|
|
@@ -3943,8 +3982,11 @@ function createHoverEvent(visualElement, isActive, callback) {
|
|
|
3943
3982
|
var _a;
|
|
3944
3983
|
if (!isMouseEvent(event) || isDragActive())
|
|
3945
3984
|
return;
|
|
3946
|
-
|
|
3985
|
+
/**
|
|
3986
|
+
* Ensure we trigger animations before firing event callback
|
|
3987
|
+
*/
|
|
3947
3988
|
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Hover, isActive);
|
|
3989
|
+
callback === null || callback === void 0 ? void 0 : callback(event, info);
|
|
3948
3990
|
};
|
|
3949
3991
|
}
|
|
3950
3992
|
function useHoverGesture(_a) {
|
|
@@ -4024,19 +4066,173 @@ function useTapGesture(_a) {
|
|
|
4024
4066
|
return;
|
|
4025
4067
|
isPressing.current = true;
|
|
4026
4068
|
cancelPointerEndListeners.current = popmotion.pipe(addPointerEvent(window, "pointerup", onPointerUp), addPointerEvent(window, "pointercancel", onPointerCancel));
|
|
4027
|
-
|
|
4069
|
+
/**
|
|
4070
|
+
* Ensure we trigger animations before firing event callback
|
|
4071
|
+
*/
|
|
4028
4072
|
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Tap, true);
|
|
4073
|
+
onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
|
|
4029
4074
|
}
|
|
4030
4075
|
usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined);
|
|
4031
4076
|
useUnmountEffect(removePointerEndListener);
|
|
4032
4077
|
}
|
|
4033
4078
|
|
|
4079
|
+
var warned = new Set();
|
|
4080
|
+
function warnOnce(condition, message, element) {
|
|
4081
|
+
if (condition || warned.has(message))
|
|
4082
|
+
return;
|
|
4083
|
+
console.warn(message);
|
|
4084
|
+
if (element)
|
|
4085
|
+
console.warn(element);
|
|
4086
|
+
warned.add(message);
|
|
4087
|
+
}
|
|
4088
|
+
|
|
4089
|
+
/**
|
|
4090
|
+
* Map an IntersectionHandler callback to an element. We only ever make one handler for one
|
|
4091
|
+
* element, so even though these handlers might all be triggered by different
|
|
4092
|
+
* observers, we can keep them in the same map.
|
|
4093
|
+
*/
|
|
4094
|
+
var observerCallbacks = new WeakMap();
|
|
4095
|
+
/**
|
|
4096
|
+
* Multiple observers can be created for multiple element/document roots. Each with
|
|
4097
|
+
* different settings. So here we store dictionaries of observers to each root,
|
|
4098
|
+
* using serialised settings (threshold/margin) as lookup keys.
|
|
4099
|
+
*/
|
|
4100
|
+
var observers = new WeakMap();
|
|
4101
|
+
var fireObserverCallback = function (entry) {
|
|
4102
|
+
var _a;
|
|
4103
|
+
(_a = observerCallbacks.get(entry.target)) === null || _a === void 0 ? void 0 : _a(entry);
|
|
4104
|
+
};
|
|
4105
|
+
var fireAllObserverCallbacks = function (entries) {
|
|
4106
|
+
entries.forEach(fireObserverCallback);
|
|
4107
|
+
};
|
|
4108
|
+
function initIntersectionObserver(_a) {
|
|
4109
|
+
var root = _a.root, options = tslib.__rest(_a, ["root"]);
|
|
4110
|
+
var lookupRoot = root || document;
|
|
4111
|
+
/**
|
|
4112
|
+
* If we don't have an observer lookup map for this root, create one.
|
|
4113
|
+
*/
|
|
4114
|
+
if (!observers.has(lookupRoot)) {
|
|
4115
|
+
observers.set(lookupRoot, {});
|
|
4116
|
+
}
|
|
4117
|
+
var rootObservers = observers.get(lookupRoot);
|
|
4118
|
+
var key = JSON.stringify(options);
|
|
4119
|
+
/**
|
|
4120
|
+
* If we don't have an observer for this combination of root and settings,
|
|
4121
|
+
* create one.
|
|
4122
|
+
*/
|
|
4123
|
+
if (!rootObservers[key]) {
|
|
4124
|
+
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks, tslib.__assign({ root: root }, options));
|
|
4125
|
+
}
|
|
4126
|
+
return rootObservers[key];
|
|
4127
|
+
}
|
|
4128
|
+
function observeIntersection(element, options, callback) {
|
|
4129
|
+
var rootInteresectionObserver = initIntersectionObserver(options);
|
|
4130
|
+
observerCallbacks.set(element, callback);
|
|
4131
|
+
rootInteresectionObserver.observe(element);
|
|
4132
|
+
return function () {
|
|
4133
|
+
observerCallbacks.delete(element);
|
|
4134
|
+
rootInteresectionObserver.unobserve(element);
|
|
4135
|
+
};
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4138
|
+
function useViewport(_a) {
|
|
4139
|
+
var visualElement = _a.visualElement, whileInView = _a.whileInView, onViewportEnter = _a.onViewportEnter, onViewportLeave = _a.onViewportLeave, _b = _a.viewport, viewport = _b === void 0 ? {} : _b;
|
|
4140
|
+
var state = React.useRef({
|
|
4141
|
+
hasEnteredView: false,
|
|
4142
|
+
isInView: false,
|
|
4143
|
+
});
|
|
4144
|
+
var shouldObserve = Boolean(whileInView || onViewportEnter || onViewportLeave);
|
|
4145
|
+
if (viewport.once && state.current.hasEnteredView)
|
|
4146
|
+
shouldObserve = false;
|
|
4147
|
+
var useObserver = typeof IntersectionObserver === "undefined"
|
|
4148
|
+
? useMissingIntersectionObserver
|
|
4149
|
+
: useIntersectionObserver;
|
|
4150
|
+
useObserver(shouldObserve, state.current, visualElement, viewport);
|
|
4151
|
+
}
|
|
4152
|
+
var thresholdNames = {
|
|
4153
|
+
some: 0,
|
|
4154
|
+
all: 1,
|
|
4155
|
+
};
|
|
4156
|
+
function useIntersectionObserver(shouldObserve, state, visualElement, _a) {
|
|
4157
|
+
var root = _a.root, rootMargin = _a.margin, _b = _a.amount, amount = _b === void 0 ? "some" : _b, once = _a.once;
|
|
4158
|
+
React.useEffect(function () {
|
|
4159
|
+
if (!shouldObserve)
|
|
4160
|
+
return;
|
|
4161
|
+
var options = {
|
|
4162
|
+
root: root === null || root === void 0 ? void 0 : root.current,
|
|
4163
|
+
rootMargin: rootMargin,
|
|
4164
|
+
threshold: typeof amount === "number" ? amount : thresholdNames[amount],
|
|
4165
|
+
};
|
|
4166
|
+
var intersectionCallback = function (entry) {
|
|
4167
|
+
var _a;
|
|
4168
|
+
var isIntersecting = entry.isIntersecting;
|
|
4169
|
+
/**
|
|
4170
|
+
* If there's been no change in the viewport state, early return.
|
|
4171
|
+
*/
|
|
4172
|
+
if (state.isInView === isIntersecting)
|
|
4173
|
+
return;
|
|
4174
|
+
state.isInView = isIntersecting;
|
|
4175
|
+
/**
|
|
4176
|
+
* Handle hasEnteredView. If this is only meant to run once, and
|
|
4177
|
+
* element isn't visible, early return. Otherwise set hasEnteredView to true.
|
|
4178
|
+
*/
|
|
4179
|
+
if (once && !isIntersecting && state.hasEnteredView) {
|
|
4180
|
+
return;
|
|
4181
|
+
}
|
|
4182
|
+
else if (isIntersecting) {
|
|
4183
|
+
state.hasEnteredView = true;
|
|
4184
|
+
}
|
|
4185
|
+
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.InView, isIntersecting);
|
|
4186
|
+
/**
|
|
4187
|
+
* Use the latest committed props rather than the ones in scope
|
|
4188
|
+
* when this observer is created
|
|
4189
|
+
*/
|
|
4190
|
+
var props = visualElement.getProps();
|
|
4191
|
+
var callback = isIntersecting
|
|
4192
|
+
? props.onViewportEnter
|
|
4193
|
+
: props.onViewportLeave;
|
|
4194
|
+
callback === null || callback === void 0 ? void 0 : callback();
|
|
4195
|
+
};
|
|
4196
|
+
return observeIntersection(visualElement.getInstance(), options, intersectionCallback);
|
|
4197
|
+
}, [shouldObserve, root, rootMargin, amount]);
|
|
4198
|
+
}
|
|
4199
|
+
/**
|
|
4200
|
+
* If IntersectionObserver is missing, we activate inView and fire onViewportEnter
|
|
4201
|
+
* on mount. This way, the page will be in the state the author expects users
|
|
4202
|
+
* to see it in for everyone.
|
|
4203
|
+
*/
|
|
4204
|
+
function useMissingIntersectionObserver(shouldObserve, state, visualElement) {
|
|
4205
|
+
React.useEffect(function () {
|
|
4206
|
+
if (!shouldObserve)
|
|
4207
|
+
return;
|
|
4208
|
+
if (process.env.NODE_ENV !== "production") {
|
|
4209
|
+
warnOnce(false, "IntersectionObserver not available on this device. whileInView animations will trigger on mount.");
|
|
4210
|
+
}
|
|
4211
|
+
/**
|
|
4212
|
+
* Fire this in an rAF because, at this point, the animation state
|
|
4213
|
+
* won't have flushed for the first time and there's certain logic in
|
|
4214
|
+
* there that behaves differently on the initial animation.
|
|
4215
|
+
*
|
|
4216
|
+
* This hook should be quite rarely called so setting this in an rAF
|
|
4217
|
+
* is preferred to changing the behaviour of the animation state.
|
|
4218
|
+
*/
|
|
4219
|
+
requestAnimationFrame(function () {
|
|
4220
|
+
var _a;
|
|
4221
|
+
state.hasEnteredView = true;
|
|
4222
|
+
var onViewportEnter = visualElement.getProps().onViewportEnter;
|
|
4223
|
+
onViewportEnter === null || onViewportEnter === void 0 ? void 0 : onViewportEnter();
|
|
4224
|
+
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.InView, true);
|
|
4225
|
+
});
|
|
4226
|
+
}, [shouldObserve]);
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4034
4229
|
var makeRenderlessComponent = function (hook) { return function (props) {
|
|
4035
4230
|
hook(props);
|
|
4036
4231
|
return null;
|
|
4037
4232
|
}; };
|
|
4038
4233
|
|
|
4039
4234
|
var gestureAnimations = {
|
|
4235
|
+
inView: makeRenderlessComponent(useViewport),
|
|
4040
4236
|
tap: makeRenderlessComponent(useTapGesture),
|
|
4041
4237
|
focus: makeRenderlessComponent(useFocusGesture),
|
|
4042
4238
|
hover: makeRenderlessComponent(useHoverGesture),
|
|
@@ -4178,9 +4374,7 @@ function setMotionValue(visualElement, key, value) {
|
|
|
4178
4374
|
}
|
|
4179
4375
|
function setTarget(visualElement, definition) {
|
|
4180
4376
|
var resolved = resolveVariant(visualElement, definition);
|
|
4181
|
-
var _a = resolved
|
|
4182
|
-
? visualElement.makeTargetAnimatable(resolved, false)
|
|
4183
|
-
: {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = tslib.__rest(_a, ["transitionEnd", "transition"]);
|
|
4377
|
+
var _a = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {}, _b = _a.transitionEnd, transitionEnd = _b === void 0 ? {} : _b; _a.transition; var target = tslib.__rest(_a, ["transitionEnd", "transition"]);
|
|
4184
4378
|
target = tslib.__assign(tslib.__assign({}, target), transitionEnd);
|
|
4185
4379
|
for (var key in target) {
|
|
4186
4380
|
var value = resolveFinalValueInKeyframes(target[key]);
|
|
@@ -4407,6 +4601,7 @@ function shouldBlockAnimation(_a, key) {
|
|
|
4407
4601
|
|
|
4408
4602
|
var variantPriorityOrder = [
|
|
4409
4603
|
AnimationType.Animate,
|
|
4604
|
+
AnimationType.InView,
|
|
4410
4605
|
AnimationType.Focus,
|
|
4411
4606
|
AnimationType.Hover,
|
|
4412
4607
|
AnimationType.Tap,
|
|
@@ -4533,7 +4728,8 @@ function createAnimationState(visualElement) {
|
|
|
4533
4728
|
* a changed value or a value that was removed in a higher priority, we set
|
|
4534
4729
|
* this to true and add this prop to the animation list.
|
|
4535
4730
|
*/
|
|
4536
|
-
var
|
|
4731
|
+
var variantDidChange = checkVariantsDidChange(typeState.prevProp, prop);
|
|
4732
|
+
var shouldAnimateType = variantDidChange ||
|
|
4537
4733
|
// If we're making this variant active, we want to always make it active
|
|
4538
4734
|
(type === changedActiveType &&
|
|
4539
4735
|
typeState.isActive &&
|
|
@@ -4584,7 +4780,7 @@ function createAnimationState(visualElement) {
|
|
|
4584
4780
|
* detect whether any value has changed. If it has, we animate it.
|
|
4585
4781
|
*/
|
|
4586
4782
|
if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
|
|
4587
|
-
if (!shallowCompare(next, prev)) {
|
|
4783
|
+
if (!shallowCompare(next, prev) || variantDidChange) {
|
|
4588
4784
|
markToAnimate(key);
|
|
4589
4785
|
}
|
|
4590
4786
|
else {
|
|
@@ -4701,7 +4897,7 @@ function createAnimationState(visualElement) {
|
|
|
4701
4897
|
getState: function () { return state; },
|
|
4702
4898
|
};
|
|
4703
4899
|
}
|
|
4704
|
-
function
|
|
4900
|
+
function checkVariantsDidChange(prev, next) {
|
|
4705
4901
|
if (typeof next === "string") {
|
|
4706
4902
|
return next !== prev;
|
|
4707
4903
|
}
|
|
@@ -4723,6 +4919,7 @@ function createState() {
|
|
|
4723
4919
|
var _a;
|
|
4724
4920
|
return _a = {},
|
|
4725
4921
|
_a[AnimationType.Animate] = createTypeState(true),
|
|
4922
|
+
_a[AnimationType.InView] = createTypeState(),
|
|
4726
4923
|
_a[AnimationType.Hover] = createTypeState(),
|
|
4727
4924
|
_a[AnimationType.Tap] = createTypeState(),
|
|
4728
4925
|
_a[AnimationType.Drag] = createTypeState(),
|
|
@@ -6232,11 +6429,18 @@ var convertChangedValueTypes = function (target, visualElement, changedKeys) {
|
|
|
6232
6429
|
var element = visualElement.getInstance();
|
|
6233
6430
|
var elementComputedStyle = getComputedStyle(element);
|
|
6234
6431
|
var display = elementComputedStyle.display;
|
|
6432
|
+
var origin = {};
|
|
6235
6433
|
// If the element is currently set to display: "none", make it visible before
|
|
6236
6434
|
// measuring the target bounding box
|
|
6237
6435
|
if (display === "none") {
|
|
6238
6436
|
visualElement.setStaticValue("display", target.display || "block");
|
|
6239
6437
|
}
|
|
6438
|
+
/**
|
|
6439
|
+
* Record origins before we render and update styles
|
|
6440
|
+
*/
|
|
6441
|
+
changedKeys.forEach(function (key) {
|
|
6442
|
+
origin[key] = positionalValues[key](originBbox, elementComputedStyle);
|
|
6443
|
+
});
|
|
6240
6444
|
// Apply the latest values (as set in checkAndConvertChangedValueTypes)
|
|
6241
6445
|
visualElement.syncRender();
|
|
6242
6446
|
var targetBbox = visualElement.measureViewportBox();
|
|
@@ -6244,7 +6448,7 @@ var convertChangedValueTypes = function (target, visualElement, changedKeys) {
|
|
|
6244
6448
|
// Restore styles to their **calculated computed style**, not their actual
|
|
6245
6449
|
// originally set style. This allows us to animate between equivalent pixel units.
|
|
6246
6450
|
var value = visualElement.getValue(key);
|
|
6247
|
-
setAndResetVelocity(value,
|
|
6451
|
+
setAndResetVelocity(value, origin[key]);
|
|
6248
6452
|
target[key] = positionalValues[key](targetBbox, elementComputedStyle);
|
|
6249
6453
|
});
|
|
6250
6454
|
return target;
|
|
@@ -7347,7 +7551,7 @@ function useDefaultMotionValue(value, defaultValue) {
|
|
|
7347
7551
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
7348
7552
|
}
|
|
7349
7553
|
function ReorderItem(_a, externalRef) {
|
|
7350
|
-
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"]);
|
|
7554
|
+
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"]);
|
|
7351
7555
|
var Component = useConstant(function () { return motion(as); });
|
|
7352
7556
|
var context = React.useContext(ReorderContext);
|
|
7353
7557
|
var point = {
|
|
@@ -7364,10 +7568,11 @@ function ReorderItem(_a, externalRef) {
|
|
|
7364
7568
|
React.useEffect(function () {
|
|
7365
7569
|
registerItem(value, layout.current);
|
|
7366
7570
|
}, [context]);
|
|
7367
|
-
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 (
|
|
7368
|
-
var velocity =
|
|
7571
|
+
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) {
|
|
7572
|
+
var velocity = gesturePoint.velocity;
|
|
7369
7573
|
velocity[axis] &&
|
|
7370
7574
|
updateOrder(value, point[axis].get(), velocity[axis]);
|
|
7575
|
+
onDrag === null || onDrag === void 0 ? void 0 : onDrag(event, gesturePoint);
|
|
7371
7576
|
}, onLayoutMeasure: function (measured) {
|
|
7372
7577
|
layout.current = measured;
|
|
7373
7578
|
}, ref: externalRef }), children));
|
|
@@ -7929,6 +8134,26 @@ function startTransition(cb) {
|
|
|
7929
8134
|
cb === null || cb === void 0 ? void 0 : cb();
|
|
7930
8135
|
}
|
|
7931
8136
|
|
|
8137
|
+
function useInstantTransition() {
|
|
8138
|
+
var _a = tslib.__read(useForceUpdate(), 2), forceUpdate = _a[0], forcedRenderCount = _a[1];
|
|
8139
|
+
var startInstantLayoutTransition = useInstantLayoutTransition();
|
|
8140
|
+
React.useEffect(function () {
|
|
8141
|
+
/**
|
|
8142
|
+
* Unblock after two animation frames, otherwise this will unblock too soon.
|
|
8143
|
+
*/
|
|
8144
|
+
sync__default['default'].postRender(function () {
|
|
8145
|
+
return sync__default['default'].postRender(function () { return (instantAnimationState.current = false); });
|
|
8146
|
+
});
|
|
8147
|
+
}, [forcedRenderCount]);
|
|
8148
|
+
return function (callback) {
|
|
8149
|
+
startInstantLayoutTransition(function () {
|
|
8150
|
+
instantAnimationState.current = true;
|
|
8151
|
+
forceUpdate();
|
|
8152
|
+
callback();
|
|
8153
|
+
});
|
|
8154
|
+
};
|
|
8155
|
+
}
|
|
8156
|
+
|
|
7932
8157
|
function useResetProjection() {
|
|
7933
8158
|
var reset = React__namespace.useCallback(function () {
|
|
7934
8159
|
var root = rootProjectionNode.current;
|
|
@@ -8072,6 +8297,7 @@ exports.useDomEvent = useDomEvent;
|
|
|
8072
8297
|
exports.useDragControls = useDragControls;
|
|
8073
8298
|
exports.useElementScroll = useElementScroll;
|
|
8074
8299
|
exports.useInstantLayoutTransition = useInstantLayoutTransition;
|
|
8300
|
+
exports.useInstantTransition = useInstantTransition;
|
|
8075
8301
|
exports.useIsPresent = useIsPresent;
|
|
8076
8302
|
exports.useMotionTemplate = useMotionTemplate;
|
|
8077
8303
|
exports.useMotionValue = useMotionValue;
|