framer-motion 7.0.3 → 7.1.2
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/cjs/index.js +2090 -2304
- package/dist/es/animation/animate.mjs +4 -5
- package/dist/es/animation/animation-controls.mjs +22 -24
- package/dist/es/animation/use-animated-state.mjs +23 -25
- package/dist/es/animation/use-animation.mjs +2 -2
- package/dist/es/animation/utils/default-transitions.mjs +13 -14
- package/dist/es/animation/utils/easing.mjs +20 -21
- package/dist/es/animation/utils/is-animatable.mjs +1 -1
- package/dist/es/animation/utils/is-keyframes-target.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +30 -31
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +18 -31
- package/dist/es/components/AnimatePresence/index.mjs +33 -35
- package/dist/es/components/AnimatePresence/use-presence.mjs +5 -5
- package/dist/es/components/AnimateSharedLayout.mjs +4 -5
- package/dist/es/components/LayoutGroup/index.mjs +12 -16
- package/dist/es/components/LazyMotion/index.mjs +9 -10
- package/dist/es/components/MotionConfig/index.mjs +5 -5
- package/dist/es/components/Reorder/Group.mjs +16 -16
- package/dist/es/components/Reorder/Item.mjs +14 -18
- package/dist/es/components/Reorder/index.mjs +3 -3
- package/dist/es/components/Reorder/utils/check-reorder.mjs +6 -6
- package/dist/es/context/DeprecatedLayoutGroupContext.mjs +1 -1
- package/dist/es/context/LayoutGroupContext.mjs +1 -1
- package/dist/es/context/LazyContext.mjs +1 -1
- package/dist/es/context/MotionConfigContext.mjs +2 -2
- package/dist/es/context/MotionContext/create.mjs +2 -2
- package/dist/es/context/MotionContext/index.mjs +1 -1
- package/dist/es/context/MotionContext/utils.mjs +1 -1
- package/dist/es/context/PresenceContext.mjs +1 -1
- package/dist/es/context/ReorderContext.mjs +1 -1
- package/dist/es/context/SwitchLayoutGroupContext.mjs +1 -1
- package/dist/es/events/event-info.mjs +11 -17
- package/dist/es/events/use-dom-event.mjs +4 -5
- package/dist/es/events/use-pointer-event.mjs +2 -2
- package/dist/es/events/utils.mjs +3 -9
- package/dist/es/gestures/PanSession.mjs +42 -47
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +147 -157
- package/dist/es/gestures/drag/use-drag-controls.mjs +10 -12
- package/dist/es/gestures/drag/use-drag.mjs +4 -4
- package/dist/es/gestures/drag/utils/constraints.mjs +12 -17
- package/dist/es/gestures/drag/utils/lock.mjs +17 -17
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +2 -3
- package/dist/es/gestures/use-pan-gesture.mjs +9 -10
- package/dist/es/gestures/use-tap-gesture.mjs +5 -6
- package/dist/es/gestures/utils/event-type.mjs +1 -1
- package/dist/es/gestures/utils/is-node-or-child.mjs +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/features/animations.mjs +9 -11
- package/dist/es/motion/features/definitions.mjs +5 -5
- package/dist/es/motion/features/drag.mjs +1 -1
- package/dist/es/motion/features/gestures.mjs +1 -1
- package/dist/es/motion/features/layout/MeasureLayout.mjs +32 -40
- package/dist/es/motion/features/layout/index.mjs +1 -1
- package/dist/es/motion/features/use-features.mjs +8 -9
- package/dist/es/motion/features/use-projection.mjs +10 -11
- package/dist/es/motion/features/viewport/observers.mjs +12 -12
- package/dist/es/motion/features/viewport/use-viewport.mjs +17 -20
- package/dist/es/motion/index.mjs +13 -16
- package/dist/es/motion/utils/VisualElementHandler.mjs +10 -16
- package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -2
- package/dist/es/motion/utils/make-renderless-component.mjs +2 -2
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -1
- package/dist/es/motion/utils/use-visual-element.mjs +13 -13
- package/dist/es/motion/utils/use-visual-state.mjs +26 -31
- package/dist/es/motion/utils/valid-prop.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +12 -16
- package/dist/es/projection/geometry/conversion.mjs +4 -6
- package/dist/es/projection/geometry/delta-apply.mjs +14 -20
- package/dist/es/projection/geometry/delta-calc.mjs +2 -5
- package/dist/es/projection/geometry/delta-remove.mjs +6 -13
- package/dist/es/projection/geometry/models.mjs +7 -7
- package/dist/es/projection/node/DocumentProjectionNode.mjs +5 -5
- package/dist/es/projection/node/HTMLProjectionNode.mjs +8 -10
- package/dist/es/projection/node/create-projection-node.mjs +283 -307
- package/dist/es/projection/node/group.mjs +6 -8
- package/dist/es/projection/node/id.mjs +2 -2
- package/dist/es/projection/node/state.mjs +1 -1
- package/dist/es/projection/shared/stack.mjs +26 -27
- package/dist/es/projection/styles/scale-border-radius.mjs +5 -5
- package/dist/es/projection/styles/scale-box-shadow.mjs +18 -19
- package/dist/es/projection/styles/scale-correction.mjs +1 -1
- package/dist/es/projection/styles/transform.mjs +12 -12
- package/dist/es/projection/use-reset-projection.mjs +2 -2
- package/dist/es/projection/utils/has-transform.mjs +1 -2
- package/dist/es/projection/utils/measure.mjs +2 -2
- package/dist/es/render/dom/create-visual-element.mjs +1 -1
- package/dist/es/render/dom/features-animation.mjs +1 -2
- package/dist/es/render/dom/features-max.mjs +1 -2
- package/dist/es/render/dom/motion-minimal.mjs +1 -1
- package/dist/es/render/dom/motion-proxy.mjs +3 -4
- package/dist/es/render/dom/motion.mjs +2 -5
- package/dist/es/render/dom/use-render.mjs +6 -9
- package/dist/es/render/dom/utils/camel-to-dash.mjs +3 -5
- package/dist/es/render/dom/utils/create-config.mjs +5 -5
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +19 -20
- package/dist/es/render/dom/utils/filter-props.mjs +4 -6
- package/dist/es/render/dom/utils/parse-dom-variant.mjs +2 -2
- package/dist/es/render/dom/utils/unit-conversion.mjs +68 -99
- package/dist/es/render/dom/value-types/animatable-none.mjs +1 -1
- package/dist/es/render/dom/value-types/defaults.mjs +4 -5
- package/dist/es/render/dom/value-types/dimensions.mjs +2 -4
- package/dist/es/render/dom/value-types/find.mjs +2 -3
- package/dist/es/render/dom/value-types/get-as-type.mjs +1 -1
- package/dist/es/render/dom/value-types/number.mjs +2 -2
- package/dist/es/render/dom/value-types/test.mjs +1 -1
- package/dist/es/render/dom/value-types/type-auto.mjs +3 -3
- package/dist/es/render/dom/value-types/type-int.mjs +1 -2
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +11 -13
- package/dist/es/render/html/utils/build-styles.mjs +8 -8
- package/dist/es/render/html/utils/build-transform.mjs +11 -16
- package/dist/es/render/html/utils/create-render-state.mjs +2 -2
- package/dist/es/render/html/utils/render.mjs +2 -3
- package/dist/es/render/html/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/html/utils/transform.mjs +6 -10
- package/dist/es/render/html/visual-element.mjs +22 -23
- package/dist/es/render/index.mjs +359 -364
- package/dist/es/render/svg/config-motion.mjs +2 -3
- package/dist/es/render/svg/lowercase-elements.mjs +1 -1
- package/dist/es/render/svg/use-props.mjs +5 -6
- package/dist/es/render/svg/utils/build-attrs.mjs +2 -2
- package/dist/es/render/svg/utils/camel-case-attrs.mjs +1 -1
- package/dist/es/render/svg/utils/create-render-state.mjs +1 -2
- package/dist/es/render/svg/utils/path.mjs +7 -10
- package/dist/es/render/svg/utils/render.mjs +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/svg/utils/transform-origin.mjs +3 -3
- package/dist/es/render/svg/visual-element.mjs +6 -4
- package/dist/es/render/utils/animation-state.mjs +71 -87
- package/dist/es/render/utils/animation.mjs +48 -60
- package/dist/es/render/utils/compare-by-depth.mjs +1 -3
- package/dist/es/render/utils/flat-tree.mjs +9 -10
- package/dist/es/render/utils/lifecycles.mjs +12 -19
- package/dist/es/render/utils/motion-values.mjs +16 -8
- package/dist/es/render/utils/setters.mjs +19 -19
- package/dist/es/render/utils/variants.mjs +6 -8
- package/dist/es/utils/array.mjs +9 -10
- package/dist/es/utils/is-browser.mjs +1 -1
- package/dist/es/utils/is-numerical-string.mjs +1 -1
- package/dist/es/utils/is-zero-value-string.mjs +1 -1
- package/dist/es/utils/process.mjs +2 -2
- package/dist/es/utils/resolve-value.mjs +2 -2
- package/dist/es/utils/shallow-compare.mjs +2 -2
- package/dist/es/utils/subscription-manager.mjs +15 -17
- package/dist/es/utils/time-conversion.mjs +1 -1
- package/dist/es/utils/transform.mjs +10 -15
- package/dist/es/utils/use-animation-frame.mjs +5 -6
- package/dist/es/utils/use-constant.mjs +1 -1
- package/dist/es/utils/use-cycle.mjs +9 -10
- package/dist/es/utils/use-force-update.mjs +4 -5
- package/dist/es/utils/use-in-view.mjs +7 -9
- package/dist/es/utils/use-instant-transition-state.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +6 -9
- package/dist/es/utils/use-is-mounted.mjs +3 -3
- package/dist/es/utils/use-isomorphic-effect.mjs +1 -1
- package/dist/es/utils/use-reduced-motion.mjs +8 -11
- package/dist/es/utils/use-unmount-effect.mjs +1 -1
- package/dist/es/utils/warn-once.mjs +1 -1
- package/dist/es/value/index.mjs +53 -59
- package/dist/es/value/use-combine-values.mjs +3 -3
- package/dist/es/value/use-inverted-scale.mjs +9 -11
- package/dist/es/value/use-motion-template.mjs +5 -9
- package/dist/es/value/use-motion-value.mjs +4 -5
- package/dist/es/value/use-on-change.mjs +4 -4
- package/dist/es/value/use-scroll.mjs +9 -11
- package/dist/es/value/use-spring.mjs +8 -10
- package/dist/es/value/use-time.mjs +2 -2
- package/dist/es/value/use-transform.mjs +6 -10
- package/dist/es/value/use-velocity.mjs +3 -3
- package/dist/es/value/use-will-change/index.mjs +50 -0
- package/dist/es/value/use-will-change/is.mjs +7 -0
- package/dist/es/value/utils/is-motion-value.mjs +1 -1
- package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
- package/dist/framer-motion.dev.js +2134 -2414
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/projection.dev.js +1154 -1300
- 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/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +0 -1
- package/package.json +12 -12
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __spreadArray, __read, __assign } from 'tslib';
|
|
2
1
|
import sync, { cancelSync, flushSync } from 'framesync';
|
|
3
2
|
import { mix } from 'popmotion';
|
|
4
3
|
import { animate } from '../../animation/animate.mjs';
|
|
@@ -25,14 +24,10 @@ import { globalProjectionState } from './state.mjs';
|
|
|
25
24
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
26
25
|
* which has a noticeable difference in spring animations
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
|
-
function createProjectionNode(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function ProjectionNode(id, latestValues, parent) {
|
|
33
|
-
if (latestValues === void 0) { latestValues = {}; }
|
|
34
|
-
if (parent === void 0) { parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent(); }
|
|
35
|
-
var _this = this;
|
|
27
|
+
const animationTarget = 1000;
|
|
28
|
+
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
29
|
+
return class ProjectionNode {
|
|
30
|
+
constructor(id, latestValues = {}, parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent()) {
|
|
36
31
|
/**
|
|
37
32
|
* A Set containing all this component's children. This is used to iterate
|
|
38
33
|
* through the children.
|
|
@@ -97,15 +92,15 @@ function createProjectionNode(_a) {
|
|
|
97
92
|
this.eventHandlers = new Map();
|
|
98
93
|
// Note: Currently only running on root node
|
|
99
94
|
this.potentialNodes = new Map();
|
|
100
|
-
this.checkUpdateFailed =
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
this.checkUpdateFailed = () => {
|
|
96
|
+
if (this.isUpdating) {
|
|
97
|
+
this.isUpdating = false;
|
|
98
|
+
this.clearAllSnapshots();
|
|
104
99
|
}
|
|
105
100
|
};
|
|
106
|
-
this.updateProjection =
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
this.updateProjection = () => {
|
|
102
|
+
this.nodes.forEach(resolveTargetDelta);
|
|
103
|
+
this.nodes.forEach(calcProjection);
|
|
109
104
|
};
|
|
110
105
|
this.hasProjected = false;
|
|
111
106
|
this.isVisible = true;
|
|
@@ -118,49 +113,43 @@ function createProjectionNode(_a) {
|
|
|
118
113
|
this.id = id;
|
|
119
114
|
this.latestValues = latestValues;
|
|
120
115
|
this.root = parent ? parent.root || parent : this;
|
|
121
|
-
this.path = parent ?
|
|
116
|
+
this.path = parent ? [...parent.path, parent] : [];
|
|
122
117
|
this.parent = parent;
|
|
123
118
|
this.depth = parent ? parent.depth + 1 : 0;
|
|
124
119
|
id && this.root.registerPotentialNode(id, this);
|
|
125
|
-
for (
|
|
120
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
126
121
|
this.path[i].shouldResetTransform = true;
|
|
127
122
|
}
|
|
128
123
|
if (this.root === this)
|
|
129
124
|
this.nodes = new FlatTree();
|
|
130
125
|
}
|
|
131
|
-
|
|
126
|
+
addEventListener(name, handler) {
|
|
132
127
|
if (!this.eventHandlers.has(name)) {
|
|
133
128
|
this.eventHandlers.set(name, new SubscriptionManager());
|
|
134
129
|
}
|
|
135
130
|
return this.eventHandlers.get(name).add(handler);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var subscriptionManager = this.eventHandlers.get(name);
|
|
143
|
-
subscriptionManager === null || subscriptionManager === void 0 ? void 0 : subscriptionManager.notify.apply(subscriptionManager, __spreadArray([], __read(args), false));
|
|
144
|
-
};
|
|
145
|
-
ProjectionNode.prototype.hasListeners = function (name) {
|
|
131
|
+
}
|
|
132
|
+
notifyListeners(name, ...args) {
|
|
133
|
+
const subscriptionManager = this.eventHandlers.get(name);
|
|
134
|
+
subscriptionManager === null || subscriptionManager === void 0 ? void 0 : subscriptionManager.notify(...args);
|
|
135
|
+
}
|
|
136
|
+
hasListeners(name) {
|
|
146
137
|
return this.eventHandlers.has(name);
|
|
147
|
-
}
|
|
148
|
-
|
|
138
|
+
}
|
|
139
|
+
registerPotentialNode(id, node) {
|
|
149
140
|
this.potentialNodes.set(id, node);
|
|
150
|
-
}
|
|
141
|
+
}
|
|
151
142
|
/**
|
|
152
143
|
* Lifecycles
|
|
153
144
|
*/
|
|
154
|
-
|
|
155
|
-
var _this = this;
|
|
145
|
+
mount(instance, isLayoutDirty = false) {
|
|
156
146
|
var _a;
|
|
157
|
-
if (isLayoutDirty === void 0) { isLayoutDirty = false; }
|
|
158
147
|
if (this.instance)
|
|
159
148
|
return;
|
|
160
149
|
this.isSVG =
|
|
161
150
|
instance instanceof SVGElement && instance.tagName !== "svg";
|
|
162
151
|
this.instance = instance;
|
|
163
|
-
|
|
152
|
+
const { layoutId, layout, visualElement } = this.options;
|
|
164
153
|
if (visualElement && !visualElement.getInstance()) {
|
|
165
154
|
visualElement.mount(instance);
|
|
166
155
|
}
|
|
@@ -171,17 +160,15 @@ function createProjectionNode(_a) {
|
|
|
171
160
|
this.isLayoutDirty = true;
|
|
172
161
|
}
|
|
173
162
|
if (attachResizeListener) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
clearTimeout(unblockTimeout_1);
|
|
181
|
-
unblockTimeout_1 = window.setTimeout(resizeUnblockUpdate_1, 250);
|
|
163
|
+
let unblockTimeout;
|
|
164
|
+
const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
|
|
165
|
+
attachResizeListener(instance, () => {
|
|
166
|
+
this.root.updateBlockedByResize = true;
|
|
167
|
+
clearTimeout(unblockTimeout);
|
|
168
|
+
unblockTimeout = window.setTimeout(resizeUnblockUpdate, 250);
|
|
182
169
|
if (globalProjectionState.hasAnimatedSinceResize) {
|
|
183
170
|
globalProjectionState.hasAnimatedSinceResize = false;
|
|
184
|
-
|
|
171
|
+
this.nodes.forEach(finishAnimation);
|
|
185
172
|
}
|
|
186
173
|
});
|
|
187
174
|
}
|
|
@@ -192,45 +179,44 @@ function createProjectionNode(_a) {
|
|
|
192
179
|
if (this.options.animate !== false &&
|
|
193
180
|
visualElement &&
|
|
194
181
|
(layoutId || layout)) {
|
|
195
|
-
this.addEventListener("didUpdate",
|
|
196
|
-
var _b, _c, _d, _e
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
_this.relativeTarget = undefined;
|
|
182
|
+
this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeTargetChanged, layout: newLayout, }) => {
|
|
183
|
+
var _a, _b, _c, _d, _e;
|
|
184
|
+
if (this.isTreeAnimationBlocked()) {
|
|
185
|
+
this.target = undefined;
|
|
186
|
+
this.relativeTarget = undefined;
|
|
201
187
|
return;
|
|
202
188
|
}
|
|
203
189
|
// TODO: Check here if an animation exists
|
|
204
|
-
|
|
205
|
-
|
|
190
|
+
const layoutTransition = (_b = (_a = this.options.transition) !== null && _a !== void 0 ? _a : visualElement.getDefaultTransition()) !== null && _b !== void 0 ? _b : defaultLayoutTransition;
|
|
191
|
+
const { onLayoutAnimationStart, onLayoutAnimationComplete, } = visualElement.getProps();
|
|
206
192
|
/**
|
|
207
193
|
* The target layout of the element might stay the same,
|
|
208
194
|
* but its position relative to its parent has changed.
|
|
209
195
|
*/
|
|
210
|
-
|
|
211
|
-
!boxEquals(
|
|
196
|
+
const targetChanged = !this.targetLayout ||
|
|
197
|
+
!boxEquals(this.targetLayout, newLayout) ||
|
|
212
198
|
hasRelativeTargetChanged;
|
|
213
199
|
/**
|
|
214
200
|
* If the layout hasn't seemed to have changed, it might be that the
|
|
215
201
|
* element is visually in the same place in the document but its position
|
|
216
202
|
* relative to its parent has indeed changed. So here we check for that.
|
|
217
203
|
*/
|
|
218
|
-
|
|
219
|
-
if (((
|
|
204
|
+
const hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeTargetChanged;
|
|
205
|
+
if (((_c = this.resumeFrom) === null || _c === void 0 ? void 0 : _c.instance) ||
|
|
220
206
|
hasOnlyRelativeTargetChanged ||
|
|
221
207
|
(hasLayoutChanged &&
|
|
222
|
-
(targetChanged || !
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
208
|
+
(targetChanged || !this.currentAnimation))) {
|
|
209
|
+
if (this.resumeFrom) {
|
|
210
|
+
this.resumingFrom = this.resumeFrom;
|
|
211
|
+
this.resumingFrom.resumingFrom = undefined;
|
|
226
212
|
}
|
|
227
|
-
|
|
228
|
-
|
|
213
|
+
this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
214
|
+
const animationOptions = Object.assign(Object.assign({}, getValueTransition(layoutTransition, "layout")), { onPlay: onLayoutAnimationStart, onComplete: onLayoutAnimationComplete });
|
|
229
215
|
if (visualElement.shouldReduceMotion) {
|
|
230
216
|
animationOptions.delay = 0;
|
|
231
217
|
animationOptions.type = false;
|
|
232
218
|
}
|
|
233
|
-
|
|
219
|
+
this.startAnimation(animationOptions);
|
|
234
220
|
}
|
|
235
221
|
else {
|
|
236
222
|
/**
|
|
@@ -239,16 +225,16 @@ function createProjectionNode(_a) {
|
|
|
239
225
|
* that was probably never commited to screen and look like a jumpy box.
|
|
240
226
|
*/
|
|
241
227
|
if (!hasLayoutChanged &&
|
|
242
|
-
|
|
243
|
-
|
|
228
|
+
this.animationProgress === 0) {
|
|
229
|
+
this.finishAnimation();
|
|
244
230
|
}
|
|
245
|
-
|
|
231
|
+
this.isLead() && ((_e = (_d = this.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d));
|
|
246
232
|
}
|
|
247
|
-
|
|
233
|
+
this.targetLayout = newLayout;
|
|
248
234
|
});
|
|
249
235
|
}
|
|
250
|
-
}
|
|
251
|
-
|
|
236
|
+
}
|
|
237
|
+
unmount() {
|
|
252
238
|
var _a, _b;
|
|
253
239
|
this.options.layoutId && this.willUpdate();
|
|
254
240
|
this.root.nodes.remove(this);
|
|
@@ -256,34 +242,33 @@ function createProjectionNode(_a) {
|
|
|
256
242
|
(_b = this.parent) === null || _b === void 0 ? void 0 : _b.children.delete(this);
|
|
257
243
|
this.instance = undefined;
|
|
258
244
|
cancelSync.preRender(this.updateProjection);
|
|
259
|
-
}
|
|
245
|
+
}
|
|
260
246
|
// only on the root
|
|
261
|
-
|
|
247
|
+
blockUpdate() {
|
|
262
248
|
this.updateManuallyBlocked = true;
|
|
263
|
-
}
|
|
264
|
-
|
|
249
|
+
}
|
|
250
|
+
unblockUpdate() {
|
|
265
251
|
this.updateManuallyBlocked = false;
|
|
266
|
-
}
|
|
267
|
-
|
|
252
|
+
}
|
|
253
|
+
isUpdateBlocked() {
|
|
268
254
|
return this.updateManuallyBlocked || this.updateBlockedByResize;
|
|
269
|
-
}
|
|
270
|
-
|
|
255
|
+
}
|
|
256
|
+
isTreeAnimationBlocked() {
|
|
271
257
|
var _a;
|
|
272
258
|
return (this.isAnimationBlocked ||
|
|
273
259
|
((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isTreeAnimationBlocked()) ||
|
|
274
260
|
false);
|
|
275
|
-
}
|
|
261
|
+
}
|
|
276
262
|
// Note: currently only running on root node
|
|
277
|
-
|
|
263
|
+
startUpdate() {
|
|
278
264
|
var _a;
|
|
279
265
|
if (this.isUpdateBlocked())
|
|
280
266
|
return;
|
|
281
267
|
this.isUpdating = true;
|
|
282
268
|
(_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach(resetRotation);
|
|
283
|
-
}
|
|
284
|
-
|
|
269
|
+
}
|
|
270
|
+
willUpdate(shouldNotifyListeners = true) {
|
|
285
271
|
var _a, _b, _c;
|
|
286
|
-
if (shouldNotifyListeners === void 0) { shouldNotifyListeners = true; }
|
|
287
272
|
if (this.root.isUpdateBlocked()) {
|
|
288
273
|
(_b = (_a = this.options).onExitComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
289
274
|
return;
|
|
@@ -292,8 +277,8 @@ function createProjectionNode(_a) {
|
|
|
292
277
|
if (this.isLayoutDirty)
|
|
293
278
|
return;
|
|
294
279
|
this.isLayoutDirty = true;
|
|
295
|
-
for (
|
|
296
|
-
|
|
280
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
281
|
+
const node = this.path[i];
|
|
297
282
|
node.shouldResetTransform = true;
|
|
298
283
|
/**
|
|
299
284
|
* TODO: Check we haven't updated the scroll
|
|
@@ -301,17 +286,17 @@ function createProjectionNode(_a) {
|
|
|
301
286
|
*/
|
|
302
287
|
node.updateScroll();
|
|
303
288
|
}
|
|
304
|
-
|
|
289
|
+
const { layoutId, layout } = this.options;
|
|
305
290
|
if (layoutId === undefined && !layout)
|
|
306
291
|
return;
|
|
307
|
-
|
|
292
|
+
const transformTemplate = (_c = this.options.visualElement) === null || _c === void 0 ? void 0 : _c.getProps().transformTemplate;
|
|
308
293
|
this.prevTransformTemplateValue = transformTemplate === null || transformTemplate === void 0 ? void 0 : transformTemplate(this.latestValues, "");
|
|
309
294
|
this.updateSnapshot();
|
|
310
295
|
shouldNotifyListeners && this.notifyListeners("willUpdate");
|
|
311
|
-
}
|
|
296
|
+
}
|
|
312
297
|
// Note: Currently only running on root node
|
|
313
|
-
|
|
314
|
-
|
|
298
|
+
didUpdate() {
|
|
299
|
+
const updateWasBlocked = this.isUpdateBlocked();
|
|
315
300
|
// When doing an instant transition, we skip the layout update,
|
|
316
301
|
// but should still clean up the measurements so that the next
|
|
317
302
|
// snapshot could be taken correctly.
|
|
@@ -353,46 +338,45 @@ function createProjectionNode(_a) {
|
|
|
353
338
|
flushSync.update();
|
|
354
339
|
flushSync.preRender();
|
|
355
340
|
flushSync.render();
|
|
356
|
-
}
|
|
357
|
-
|
|
341
|
+
}
|
|
342
|
+
clearAllSnapshots() {
|
|
358
343
|
this.nodes.forEach(clearSnapshot);
|
|
359
344
|
this.sharedNodes.forEach(removeLeadSnapshots);
|
|
360
|
-
}
|
|
361
|
-
|
|
345
|
+
}
|
|
346
|
+
scheduleUpdateProjection() {
|
|
362
347
|
sync.preRender(this.updateProjection, false, true);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
var _this = this;
|
|
348
|
+
}
|
|
349
|
+
scheduleCheckAfterUnmount() {
|
|
366
350
|
/**
|
|
367
351
|
* If the unmounting node is in a layoutGroup and did trigger a willUpdate,
|
|
368
352
|
* we manually call didUpdate to give a chance to the siblings to animate.
|
|
369
353
|
* Otherwise, cleanup all snapshots to prevents future nodes from reusing them.
|
|
370
354
|
*/
|
|
371
|
-
sync.postRender(
|
|
372
|
-
if (
|
|
373
|
-
|
|
355
|
+
sync.postRender(() => {
|
|
356
|
+
if (this.isLayoutDirty) {
|
|
357
|
+
this.root.didUpdate();
|
|
374
358
|
}
|
|
375
359
|
else {
|
|
376
|
-
|
|
360
|
+
this.root.checkUpdateFailed();
|
|
377
361
|
}
|
|
378
362
|
});
|
|
379
|
-
}
|
|
363
|
+
}
|
|
380
364
|
/**
|
|
381
365
|
* Update measurements
|
|
382
366
|
*/
|
|
383
|
-
|
|
367
|
+
updateSnapshot() {
|
|
384
368
|
if (this.snapshot || !this.instance)
|
|
385
369
|
return;
|
|
386
|
-
|
|
387
|
-
|
|
370
|
+
const measured = this.measure();
|
|
371
|
+
const layout = this.removeTransform(this.removeElementScroll(measured));
|
|
388
372
|
roundBox(layout);
|
|
389
373
|
this.snapshot = {
|
|
390
|
-
measured
|
|
391
|
-
layout
|
|
374
|
+
measured,
|
|
375
|
+
layout,
|
|
392
376
|
latestValues: {},
|
|
393
377
|
};
|
|
394
|
-
}
|
|
395
|
-
|
|
378
|
+
}
|
|
379
|
+
updateLayout() {
|
|
396
380
|
var _a;
|
|
397
381
|
if (!this.instance)
|
|
398
382
|
return;
|
|
@@ -410,16 +394,16 @@ function createProjectionNode(_a) {
|
|
|
410
394
|
* up to date.
|
|
411
395
|
*/
|
|
412
396
|
if (this.resumeFrom && !this.resumeFrom.instance) {
|
|
413
|
-
for (
|
|
414
|
-
|
|
397
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
398
|
+
const node = this.path[i];
|
|
415
399
|
node.updateScroll();
|
|
416
400
|
}
|
|
417
401
|
}
|
|
418
|
-
|
|
402
|
+
const measured = this.measure();
|
|
419
403
|
roundBox(measured);
|
|
420
|
-
|
|
404
|
+
const prevLayout = this.layout;
|
|
421
405
|
this.layout = {
|
|
422
|
-
measured
|
|
406
|
+
measured,
|
|
423
407
|
actual: this.removeElementScroll(measured),
|
|
424
408
|
};
|
|
425
409
|
this.layoutCorrected = createBox();
|
|
@@ -427,22 +411,22 @@ function createProjectionNode(_a) {
|
|
|
427
411
|
this.projectionDelta = undefined;
|
|
428
412
|
this.notifyListeners("measure", this.layout.actual);
|
|
429
413
|
(_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.notifyLayoutMeasure(this.layout.actual, prevLayout === null || prevLayout === void 0 ? void 0 : prevLayout.actual);
|
|
430
|
-
}
|
|
431
|
-
|
|
414
|
+
}
|
|
415
|
+
updateScroll() {
|
|
432
416
|
if (this.options.layoutScroll && this.instance) {
|
|
433
417
|
this.isScrollRoot = checkIsScrollRoot(this.instance);
|
|
434
418
|
this.scroll = measureScroll(this.instance);
|
|
435
419
|
}
|
|
436
|
-
}
|
|
437
|
-
|
|
420
|
+
}
|
|
421
|
+
resetTransform() {
|
|
438
422
|
var _a;
|
|
439
423
|
if (!resetTransform)
|
|
440
424
|
return;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
425
|
+
const isResetRequested = this.isLayoutDirty || this.shouldResetTransform;
|
|
426
|
+
const hasProjection = this.projectionDelta && !isDeltaZero(this.projectionDelta);
|
|
427
|
+
const transformTemplate = (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.getProps().transformTemplate;
|
|
428
|
+
const transformTemplateValue = transformTemplate === null || transformTemplate === void 0 ? void 0 : transformTemplate(this.latestValues, "");
|
|
429
|
+
const transformTemplateHasChanged = transformTemplateValue !== this.prevTransformTemplateValue;
|
|
446
430
|
if (isResetRequested &&
|
|
447
431
|
(hasProjection ||
|
|
448
432
|
hasTransform(this.latestValues) ||
|
|
@@ -451,38 +435,38 @@ function createProjectionNode(_a) {
|
|
|
451
435
|
this.shouldResetTransform = false;
|
|
452
436
|
this.scheduleRender();
|
|
453
437
|
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
|
|
438
|
+
}
|
|
439
|
+
measure() {
|
|
440
|
+
const { visualElement } = this.options;
|
|
457
441
|
if (!visualElement)
|
|
458
442
|
return createBox();
|
|
459
|
-
|
|
443
|
+
const box = visualElement.measureViewportBox();
|
|
460
444
|
// Remove viewport scroll to give page-relative coordinates
|
|
461
|
-
|
|
445
|
+
const { scroll } = this.root;
|
|
462
446
|
if (scroll) {
|
|
463
447
|
translateAxis(box.x, scroll.x);
|
|
464
448
|
translateAxis(box.y, scroll.y);
|
|
465
449
|
}
|
|
466
450
|
return box;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
451
|
+
}
|
|
452
|
+
removeElementScroll(box) {
|
|
453
|
+
const boxWithoutScroll = createBox();
|
|
470
454
|
copyBoxInto(boxWithoutScroll, box);
|
|
471
455
|
/**
|
|
472
456
|
* Performance TODO: Keep a cumulative scroll offset down the tree
|
|
473
457
|
* rather than loop back up the path.
|
|
474
458
|
*/
|
|
475
|
-
for (
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (node !== this.root &&
|
|
459
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
460
|
+
const node = this.path[i];
|
|
461
|
+
const { scroll, options, isScrollRoot } = node;
|
|
462
|
+
if (node !== this.root && scroll && options.layoutScroll) {
|
|
479
463
|
/**
|
|
480
464
|
* If this is a new scroll root, we want to remove all previous scrolls
|
|
481
465
|
* from the viewport box.
|
|
482
466
|
*/
|
|
483
467
|
if (isScrollRoot) {
|
|
484
468
|
copyBoxInto(boxWithoutScroll, box);
|
|
485
|
-
|
|
469
|
+
const { scroll: rootScroll } = this.root;
|
|
486
470
|
/**
|
|
487
471
|
* Undo the application of page scroll that was originally added
|
|
488
472
|
* to the measured bounding box.
|
|
@@ -492,18 +476,17 @@ function createProjectionNode(_a) {
|
|
|
492
476
|
translateAxis(boxWithoutScroll.y, -rootScroll.y);
|
|
493
477
|
}
|
|
494
478
|
}
|
|
495
|
-
translateAxis(boxWithoutScroll.x,
|
|
496
|
-
translateAxis(boxWithoutScroll.y,
|
|
479
|
+
translateAxis(boxWithoutScroll.x, scroll.x);
|
|
480
|
+
translateAxis(boxWithoutScroll.y, scroll.y);
|
|
497
481
|
}
|
|
498
482
|
}
|
|
499
483
|
return boxWithoutScroll;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
var withTransforms = createBox();
|
|
484
|
+
}
|
|
485
|
+
applyTransform(box, transformOnly = false) {
|
|
486
|
+
const withTransforms = createBox();
|
|
504
487
|
copyBoxInto(withTransforms, box);
|
|
505
|
-
for (
|
|
506
|
-
|
|
488
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
489
|
+
const node = this.path[i];
|
|
507
490
|
if (!transformOnly &&
|
|
508
491
|
node.options.layoutScroll &&
|
|
509
492
|
node.scroll &&
|
|
@@ -521,20 +504,20 @@ function createProjectionNode(_a) {
|
|
|
521
504
|
transformBox(withTransforms, this.latestValues);
|
|
522
505
|
}
|
|
523
506
|
return withTransforms;
|
|
524
|
-
}
|
|
525
|
-
|
|
507
|
+
}
|
|
508
|
+
removeTransform(box) {
|
|
526
509
|
var _a;
|
|
527
|
-
|
|
510
|
+
const boxWithoutTransform = createBox();
|
|
528
511
|
copyBoxInto(boxWithoutTransform, box);
|
|
529
|
-
for (
|
|
530
|
-
|
|
512
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
513
|
+
const node = this.path[i];
|
|
531
514
|
if (!node.instance)
|
|
532
515
|
continue;
|
|
533
516
|
if (!hasTransform(node.latestValues))
|
|
534
517
|
continue;
|
|
535
518
|
hasScale(node.latestValues) && node.updateSnapshot();
|
|
536
|
-
|
|
537
|
-
|
|
519
|
+
const sourceBox = createBox();
|
|
520
|
+
const nodeBox = node.measure();
|
|
538
521
|
copyBoxInto(sourceBox, nodeBox);
|
|
539
522
|
removeBoxTransforms(boxWithoutTransform, node.latestValues, (_a = node.snapshot) === null || _a === void 0 ? void 0 : _a.layout, sourceBox);
|
|
540
523
|
}
|
|
@@ -542,19 +525,19 @@ function createProjectionNode(_a) {
|
|
|
542
525
|
removeBoxTransforms(boxWithoutTransform, this.latestValues);
|
|
543
526
|
}
|
|
544
527
|
return boxWithoutTransform;
|
|
545
|
-
}
|
|
528
|
+
}
|
|
546
529
|
/**
|
|
547
530
|
*
|
|
548
531
|
*/
|
|
549
|
-
|
|
532
|
+
setTargetDelta(delta) {
|
|
550
533
|
this.targetDelta = delta;
|
|
551
534
|
this.root.scheduleUpdateProjection();
|
|
552
|
-
}
|
|
553
|
-
|
|
535
|
+
}
|
|
536
|
+
setOptions(options) {
|
|
554
537
|
var _a;
|
|
555
|
-
this.options =
|
|
556
|
-
}
|
|
557
|
-
|
|
538
|
+
this.options = Object.assign(Object.assign(Object.assign({}, this.options), options), { crossfade: (_a = options.crossfade) !== null && _a !== void 0 ? _a : true });
|
|
539
|
+
}
|
|
540
|
+
clearMeasurements() {
|
|
558
541
|
this.scroll = undefined;
|
|
559
542
|
this.layout = undefined;
|
|
560
543
|
this.snapshot = undefined;
|
|
@@ -562,13 +545,13 @@ function createProjectionNode(_a) {
|
|
|
562
545
|
this.targetDelta = undefined;
|
|
563
546
|
this.target = undefined;
|
|
564
547
|
this.isLayoutDirty = false;
|
|
565
|
-
}
|
|
548
|
+
}
|
|
566
549
|
/**
|
|
567
550
|
* Frame calculations
|
|
568
551
|
*/
|
|
569
|
-
|
|
552
|
+
resolveTargetDelta() {
|
|
570
553
|
var _a;
|
|
571
|
-
|
|
554
|
+
const { layout, layoutId } = this.options;
|
|
572
555
|
/**
|
|
573
556
|
* If we have no layout, we can't perform projection, so early return
|
|
574
557
|
*/
|
|
@@ -647,8 +630,8 @@ function createProjectionNode(_a) {
|
|
|
647
630
|
copyBoxInto(this.relativeTarget, this.relativeTargetOrigin);
|
|
648
631
|
}
|
|
649
632
|
}
|
|
650
|
-
}
|
|
651
|
-
|
|
633
|
+
}
|
|
634
|
+
getClosestProjectingParent() {
|
|
652
635
|
if (!this.parent || hasTransform(this.parent.latestValues))
|
|
653
636
|
return undefined;
|
|
654
637
|
if ((this.parent.relativeTarget || this.parent.targetDelta) &&
|
|
@@ -658,10 +641,10 @@ function createProjectionNode(_a) {
|
|
|
658
641
|
else {
|
|
659
642
|
return this.parent.getClosestProjectingParent();
|
|
660
643
|
}
|
|
661
|
-
}
|
|
662
|
-
|
|
644
|
+
}
|
|
645
|
+
calcProjection() {
|
|
663
646
|
var _a;
|
|
664
|
-
|
|
647
|
+
const { layout, layoutId } = this.options;
|
|
665
648
|
/**
|
|
666
649
|
* If this section of the tree isn't animating we can
|
|
667
650
|
* delete our target sources for the following frame.
|
|
@@ -674,7 +657,7 @@ function createProjectionNode(_a) {
|
|
|
674
657
|
}
|
|
675
658
|
if (!this.layout || !(layout || layoutId))
|
|
676
659
|
return;
|
|
677
|
-
|
|
660
|
+
const lead = this.getLead();
|
|
678
661
|
/**
|
|
679
662
|
* Reset the corrected box with the latest values from box, as we're then going
|
|
680
663
|
* to perform mutative operations on it.
|
|
@@ -685,16 +668,16 @@ function createProjectionNode(_a) {
|
|
|
685
668
|
* is the layout box, as it will appear on screen as a result of the transforms of its parents.
|
|
686
669
|
*/
|
|
687
670
|
applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, Boolean(this.resumingFrom) || this !== lead);
|
|
688
|
-
|
|
671
|
+
const { target } = lead;
|
|
689
672
|
if (!target)
|
|
690
673
|
return;
|
|
691
674
|
if (!this.projectionDelta) {
|
|
692
675
|
this.projectionDelta = createDelta();
|
|
693
676
|
this.projectionDeltaWithTransform = createDelta();
|
|
694
677
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
678
|
+
const prevTreeScaleX = this.treeScale.x;
|
|
679
|
+
const prevTreeScaleY = this.treeScale.y;
|
|
680
|
+
const prevProjectionTransform = this.projectionTransform;
|
|
698
681
|
/**
|
|
699
682
|
* Update the delta between the corrected box and the target box before user-set transforms were applied.
|
|
700
683
|
* This will allow us to calculate the corrected borderRadius and boxShadow to compensate
|
|
@@ -713,67 +696,63 @@ function createProjectionNode(_a) {
|
|
|
713
696
|
this.scheduleRender();
|
|
714
697
|
this.notifyListeners("projectionUpdate", target);
|
|
715
698
|
}
|
|
716
|
-
}
|
|
717
|
-
|
|
699
|
+
}
|
|
700
|
+
hide() {
|
|
718
701
|
this.isVisible = false;
|
|
719
702
|
// TODO: Schedule render
|
|
720
|
-
}
|
|
721
|
-
|
|
703
|
+
}
|
|
704
|
+
show() {
|
|
722
705
|
this.isVisible = true;
|
|
723
706
|
// TODO: Schedule render
|
|
724
|
-
}
|
|
725
|
-
|
|
707
|
+
}
|
|
708
|
+
scheduleRender(notifyAll = true) {
|
|
726
709
|
var _a, _b, _c;
|
|
727
|
-
if (notifyAll === void 0) { notifyAll = true; }
|
|
728
710
|
(_b = (_a = this.options).scheduleRender) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
729
711
|
notifyAll && ((_c = this.getStack()) === null || _c === void 0 ? void 0 : _c.scheduleRender());
|
|
730
712
|
if (this.resumingFrom && !this.resumingFrom.instance) {
|
|
731
713
|
this.resumingFrom = undefined;
|
|
732
714
|
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
var _this = this;
|
|
715
|
+
}
|
|
716
|
+
setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false) {
|
|
736
717
|
var _a;
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
var targetDelta = createDelta();
|
|
718
|
+
const snapshot = this.snapshot;
|
|
719
|
+
const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
|
|
720
|
+
const mixedValues = Object.assign({}, this.latestValues);
|
|
721
|
+
const targetDelta = createDelta();
|
|
742
722
|
this.relativeTarget = this.relativeTargetOrigin = undefined;
|
|
743
723
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
724
|
+
const relativeLayout = createBox();
|
|
725
|
+
const isSharedLayoutAnimation = snapshot === null || snapshot === void 0 ? void 0 : snapshot.isShared;
|
|
726
|
+
const isOnlyMember = (((_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.members.length) || 0) <= 1;
|
|
727
|
+
const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
|
|
748
728
|
!isOnlyMember &&
|
|
749
729
|
this.options.crossfade === true &&
|
|
750
730
|
!this.path.some(hasOpacityCrossfade));
|
|
751
731
|
this.animationProgress = 0;
|
|
752
|
-
this.mixTargetDelta =
|
|
732
|
+
this.mixTargetDelta = (latest) => {
|
|
753
733
|
var _a;
|
|
754
|
-
|
|
734
|
+
const progress = latest / 1000;
|
|
755
735
|
mixAxisDelta(targetDelta.x, delta.x, progress);
|
|
756
736
|
mixAxisDelta(targetDelta.y, delta.y, progress);
|
|
757
|
-
|
|
758
|
-
if (
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
((_a =
|
|
762
|
-
calcRelativePosition(relativeLayout,
|
|
763
|
-
mixBox(
|
|
737
|
+
this.setTargetDelta(targetDelta);
|
|
738
|
+
if (this.relativeTarget &&
|
|
739
|
+
this.relativeTargetOrigin &&
|
|
740
|
+
this.layout &&
|
|
741
|
+
((_a = this.relativeParent) === null || _a === void 0 ? void 0 : _a.layout)) {
|
|
742
|
+
calcRelativePosition(relativeLayout, this.layout.actual, this.relativeParent.layout.actual);
|
|
743
|
+
mixBox(this.relativeTarget, this.relativeTargetOrigin, relativeLayout, progress);
|
|
764
744
|
}
|
|
765
745
|
if (isSharedLayoutAnimation) {
|
|
766
|
-
|
|
767
|
-
mixValues(mixedValues, snapshotLatestValues,
|
|
746
|
+
this.animationValues = mixedValues;
|
|
747
|
+
mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
|
|
768
748
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
749
|
+
this.root.scheduleUpdateProjection();
|
|
750
|
+
this.scheduleRender();
|
|
751
|
+
this.animationProgress = progress;
|
|
772
752
|
};
|
|
773
753
|
this.mixTargetDelta(0);
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
var _this = this;
|
|
754
|
+
}
|
|
755
|
+
startAnimation(options) {
|
|
777
756
|
var _a, _b;
|
|
778
757
|
this.notifyListeners("animationStart");
|
|
779
758
|
(_a = this.currentAnimation) === null || _a === void 0 ? void 0 : _a.stop();
|
|
@@ -789,24 +768,24 @@ function createProjectionNode(_a) {
|
|
|
789
768
|
* where the target is the same as when the animation started, so we can
|
|
790
769
|
* calculate the relative positions correctly for instant transitions.
|
|
791
770
|
*/
|
|
792
|
-
this.pendingAnimation = sync.update(
|
|
771
|
+
this.pendingAnimation = sync.update(() => {
|
|
793
772
|
globalProjectionState.hasAnimatedSinceResize = true;
|
|
794
|
-
|
|
773
|
+
this.currentAnimation = animate(0, animationTarget, Object.assign(Object.assign({}, options), { onUpdate: (latest) => {
|
|
795
774
|
var _a;
|
|
796
|
-
|
|
775
|
+
this.mixTargetDelta(latest);
|
|
797
776
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
|
|
798
|
-
}, onComplete:
|
|
777
|
+
}, onComplete: () => {
|
|
799
778
|
var _a;
|
|
800
779
|
(_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
801
|
-
|
|
780
|
+
this.completeAnimation();
|
|
802
781
|
} }));
|
|
803
|
-
if (
|
|
804
|
-
|
|
782
|
+
if (this.resumingFrom) {
|
|
783
|
+
this.resumingFrom.currentAnimation = this.currentAnimation;
|
|
805
784
|
}
|
|
806
|
-
|
|
785
|
+
this.pendingAnimation = undefined;
|
|
807
786
|
});
|
|
808
|
-
}
|
|
809
|
-
|
|
787
|
+
}
|
|
788
|
+
completeAnimation() {
|
|
810
789
|
var _a;
|
|
811
790
|
if (this.resumingFrom) {
|
|
812
791
|
this.resumingFrom.currentAnimation = undefined;
|
|
@@ -818,17 +797,17 @@ function createProjectionNode(_a) {
|
|
|
818
797
|
this.animationValues =
|
|
819
798
|
undefined;
|
|
820
799
|
this.notifyListeners("animationComplete");
|
|
821
|
-
}
|
|
822
|
-
|
|
800
|
+
}
|
|
801
|
+
finishAnimation() {
|
|
823
802
|
var _a;
|
|
824
803
|
if (this.currentAnimation) {
|
|
825
804
|
(_a = this.mixTargetDelta) === null || _a === void 0 ? void 0 : _a.call(this, animationTarget);
|
|
826
805
|
this.currentAnimation.stop();
|
|
827
806
|
}
|
|
828
807
|
this.completeAnimation();
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
|
|
808
|
+
}
|
|
809
|
+
applyTransformsToTarget() {
|
|
810
|
+
const { targetWithTransforms, target, layout, latestValues } = this.getLead();
|
|
832
811
|
if (!targetWithTransforms || !target || !layout)
|
|
833
812
|
return;
|
|
834
813
|
copyBoxInto(targetWithTransforms, target);
|
|
@@ -845,41 +824,40 @@ function createProjectionNode(_a) {
|
|
|
845
824
|
* into the desired bounding box.
|
|
846
825
|
*/
|
|
847
826
|
calcBoxDelta(this.projectionDeltaWithTransform, this.layoutCorrected, targetWithTransforms, latestValues);
|
|
848
|
-
}
|
|
849
|
-
|
|
827
|
+
}
|
|
828
|
+
registerSharedNode(layoutId, node) {
|
|
850
829
|
var _a, _b, _c;
|
|
851
830
|
if (!this.sharedNodes.has(layoutId)) {
|
|
852
831
|
this.sharedNodes.set(layoutId, new NodeStack());
|
|
853
832
|
}
|
|
854
|
-
|
|
833
|
+
const stack = this.sharedNodes.get(layoutId);
|
|
855
834
|
stack.add(node);
|
|
856
835
|
node.promote({
|
|
857
836
|
transition: (_a = node.options.initialPromotionConfig) === null || _a === void 0 ? void 0 : _a.transition,
|
|
858
837
|
preserveFollowOpacity: (_c = (_b = node.options.initialPromotionConfig) === null || _b === void 0 ? void 0 : _b.shouldPreserveFollowOpacity) === null || _c === void 0 ? void 0 : _c.call(_b, node),
|
|
859
838
|
});
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
|
|
839
|
+
}
|
|
840
|
+
isLead() {
|
|
841
|
+
const stack = this.getStack();
|
|
863
842
|
return stack ? stack.lead === this : true;
|
|
864
|
-
}
|
|
865
|
-
|
|
843
|
+
}
|
|
844
|
+
getLead() {
|
|
866
845
|
var _a;
|
|
867
|
-
|
|
846
|
+
const { layoutId } = this.options;
|
|
868
847
|
return layoutId ? ((_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.lead) || this : this;
|
|
869
|
-
}
|
|
870
|
-
|
|
848
|
+
}
|
|
849
|
+
getPrevLead() {
|
|
871
850
|
var _a;
|
|
872
|
-
|
|
851
|
+
const { layoutId } = this.options;
|
|
873
852
|
return layoutId ? (_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.prevLead : undefined;
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
|
|
853
|
+
}
|
|
854
|
+
getStack() {
|
|
855
|
+
const { layoutId } = this.options;
|
|
877
856
|
if (layoutId)
|
|
878
857
|
return this.root.sharedNodes.get(layoutId);
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
var stack = this.getStack();
|
|
858
|
+
}
|
|
859
|
+
promote({ needsReset, transition, preserveFollowOpacity, } = {}) {
|
|
860
|
+
const stack = this.getStack();
|
|
883
861
|
if (stack)
|
|
884
862
|
stack.promote(this, preserveFollowOpacity);
|
|
885
863
|
if (needsReset) {
|
|
@@ -887,29 +865,29 @@ function createProjectionNode(_a) {
|
|
|
887
865
|
this.needsReset = true;
|
|
888
866
|
}
|
|
889
867
|
if (transition)
|
|
890
|
-
this.setOptions({ transition
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
|
|
868
|
+
this.setOptions({ transition });
|
|
869
|
+
}
|
|
870
|
+
relegate() {
|
|
871
|
+
const stack = this.getStack();
|
|
894
872
|
if (stack) {
|
|
895
873
|
return stack.relegate(this);
|
|
896
874
|
}
|
|
897
875
|
else {
|
|
898
876
|
return false;
|
|
899
877
|
}
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
|
|
878
|
+
}
|
|
879
|
+
resetRotation() {
|
|
880
|
+
const { visualElement } = this.options;
|
|
903
881
|
if (!visualElement)
|
|
904
882
|
return;
|
|
905
883
|
// If there's no detected rotation values, we can early return without a forced render.
|
|
906
|
-
|
|
884
|
+
let hasRotate = false;
|
|
907
885
|
// Keep a record of all the values we've reset
|
|
908
|
-
|
|
886
|
+
const resetValues = {};
|
|
909
887
|
// Check the rotate value of all axes and reset to 0
|
|
910
|
-
for (
|
|
911
|
-
|
|
912
|
-
|
|
888
|
+
for (let i = 0; i < transformAxes.length; i++) {
|
|
889
|
+
const axis = transformAxes[i];
|
|
890
|
+
const key = "rotate" + axis;
|
|
913
891
|
// If this rotation doesn't exist as a motion value, then we don't
|
|
914
892
|
// need to reset it
|
|
915
893
|
if (!visualElement.getStaticValue(key)) {
|
|
@@ -927,18 +905,17 @@ function createProjectionNode(_a) {
|
|
|
927
905
|
// set to 0.
|
|
928
906
|
visualElement === null || visualElement === void 0 ? void 0 : visualElement.syncRender();
|
|
929
907
|
// Put back all the values we reset
|
|
930
|
-
for (
|
|
908
|
+
for (const key in resetValues) {
|
|
931
909
|
visualElement.setStaticValue(key, resetValues[key]);
|
|
932
910
|
}
|
|
933
911
|
// Schedule a render for the next frame. This ensures we won't visually
|
|
934
912
|
// see the element with the reset rotate value applied.
|
|
935
913
|
visualElement.scheduleRender();
|
|
936
|
-
}
|
|
937
|
-
|
|
914
|
+
}
|
|
915
|
+
getProjectionStyles(styleProp = {}) {
|
|
938
916
|
var _a, _b, _c, _d, _e, _f;
|
|
939
|
-
if (styleProp === void 0) { styleProp = {}; }
|
|
940
917
|
// TODO: Return lifecycle-persistent object
|
|
941
|
-
|
|
918
|
+
const styles = {};
|
|
942
919
|
if (!this.instance || this.isSVG)
|
|
943
920
|
return styles;
|
|
944
921
|
if (!this.isVisible) {
|
|
@@ -947,7 +924,7 @@ function createProjectionNode(_a) {
|
|
|
947
924
|
else {
|
|
948
925
|
styles.visibility = "";
|
|
949
926
|
}
|
|
950
|
-
|
|
927
|
+
const transformTemplate = (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.getProps().transformTemplate;
|
|
951
928
|
if (this.needsReset) {
|
|
952
929
|
this.needsReset = false;
|
|
953
930
|
styles.opacity = "";
|
|
@@ -958,9 +935,9 @@ function createProjectionNode(_a) {
|
|
|
958
935
|
: "none";
|
|
959
936
|
return styles;
|
|
960
937
|
}
|
|
961
|
-
|
|
938
|
+
const lead = this.getLead();
|
|
962
939
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
963
|
-
|
|
940
|
+
const emptyStyles = {};
|
|
964
941
|
if (this.options.layoutId) {
|
|
965
942
|
emptyStyles.opacity = (_b = this.latestValues.opacity) !== null && _b !== void 0 ? _b : 1;
|
|
966
943
|
emptyStyles.pointerEvents =
|
|
@@ -974,14 +951,14 @@ function createProjectionNode(_a) {
|
|
|
974
951
|
}
|
|
975
952
|
return emptyStyles;
|
|
976
953
|
}
|
|
977
|
-
|
|
954
|
+
const valuesToRender = lead.animationValues || lead.latestValues;
|
|
978
955
|
this.applyTransformsToTarget();
|
|
979
956
|
styles.transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
|
|
980
957
|
if (transformTemplate) {
|
|
981
958
|
styles.transform = transformTemplate(valuesToRender, styles.transform);
|
|
982
959
|
}
|
|
983
|
-
|
|
984
|
-
styles.transformOrigin =
|
|
960
|
+
const { x, y } = this.projectionDelta;
|
|
961
|
+
styles.transformOrigin = `${x.origin * 100}% ${y.origin * 100}% 0`;
|
|
985
962
|
if (lead.animationValues) {
|
|
986
963
|
/**
|
|
987
964
|
* If the lead component is animating, assign this either the entering/leaving
|
|
@@ -1007,14 +984,14 @@ function createProjectionNode(_a) {
|
|
|
1007
984
|
/**
|
|
1008
985
|
* Apply scale correction
|
|
1009
986
|
*/
|
|
1010
|
-
for (
|
|
987
|
+
for (const key in scaleCorrectors) {
|
|
1011
988
|
if (valuesToRender[key] === undefined)
|
|
1012
989
|
continue;
|
|
1013
|
-
|
|
1014
|
-
|
|
990
|
+
const { correct, applyTo } = scaleCorrectors[key];
|
|
991
|
+
const corrected = correct(valuesToRender[key], lead);
|
|
1015
992
|
if (applyTo) {
|
|
1016
|
-
|
|
1017
|
-
for (
|
|
993
|
+
const num = applyTo.length;
|
|
994
|
+
for (let i = 0; i < num; i++) {
|
|
1018
995
|
styles[applyTo[i]] = corrected;
|
|
1019
996
|
}
|
|
1020
997
|
}
|
|
@@ -1034,62 +1011,61 @@ function createProjectionNode(_a) {
|
|
|
1034
1011
|
: "none";
|
|
1035
1012
|
}
|
|
1036
1013
|
return styles;
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1014
|
+
}
|
|
1015
|
+
clearSnapshot() {
|
|
1039
1016
|
this.resumeFrom = this.snapshot = undefined;
|
|
1040
|
-
}
|
|
1017
|
+
}
|
|
1041
1018
|
// Only run on root
|
|
1042
|
-
|
|
1043
|
-
this.root.nodes.forEach(
|
|
1019
|
+
resetTree() {
|
|
1020
|
+
this.root.nodes.forEach((node) => { var _a; return (_a = node.currentAnimation) === null || _a === void 0 ? void 0 : _a.stop(); });
|
|
1044
1021
|
this.root.nodes.forEach(clearMeasurements);
|
|
1045
1022
|
this.root.sharedNodes.clear();
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
}());
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1049
1025
|
}
|
|
1050
1026
|
function updateLayout(node) {
|
|
1051
1027
|
node.updateLayout();
|
|
1052
1028
|
}
|
|
1053
1029
|
function notifyLayoutUpdate(node) {
|
|
1054
1030
|
var _a, _b, _c, _d;
|
|
1055
|
-
|
|
1031
|
+
const snapshot = (_b = (_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) !== null && _b !== void 0 ? _b : node.snapshot;
|
|
1056
1032
|
if (node.isLead() &&
|
|
1057
1033
|
node.layout &&
|
|
1058
1034
|
snapshot &&
|
|
1059
1035
|
node.hasListeners("didUpdate")) {
|
|
1060
|
-
|
|
1036
|
+
const { actual: layout, measured: measuredLayout } = node.layout;
|
|
1061
1037
|
// TODO Maybe we want to also resize the layout snapshot so we don't trigger
|
|
1062
1038
|
// animations for instance if layout="size" and an element has only changed position
|
|
1063
1039
|
if (node.options.animationType === "size") {
|
|
1064
|
-
eachAxis(
|
|
1065
|
-
|
|
1040
|
+
eachAxis((axis) => {
|
|
1041
|
+
const axisSnapshot = snapshot.isShared
|
|
1066
1042
|
? snapshot.measured[axis]
|
|
1067
1043
|
: snapshot.layout[axis];
|
|
1068
|
-
|
|
1069
|
-
axisSnapshot.min =
|
|
1044
|
+
const length = calcLength(axisSnapshot);
|
|
1045
|
+
axisSnapshot.min = layout[axis].min;
|
|
1070
1046
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
1071
1047
|
});
|
|
1072
1048
|
}
|
|
1073
1049
|
else if (node.options.animationType === "position") {
|
|
1074
|
-
eachAxis(
|
|
1075
|
-
|
|
1050
|
+
eachAxis((axis) => {
|
|
1051
|
+
const axisSnapshot = snapshot.isShared
|
|
1076
1052
|
? snapshot.measured[axis]
|
|
1077
1053
|
: snapshot.layout[axis];
|
|
1078
|
-
|
|
1054
|
+
const length = calcLength(layout[axis]);
|
|
1079
1055
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
1080
1056
|
});
|
|
1081
1057
|
}
|
|
1082
|
-
|
|
1083
|
-
calcBoxDelta(layoutDelta,
|
|
1084
|
-
|
|
1058
|
+
const layoutDelta = createDelta();
|
|
1059
|
+
calcBoxDelta(layoutDelta, layout, snapshot.layout);
|
|
1060
|
+
const visualDelta = createDelta();
|
|
1085
1061
|
if (snapshot.isShared) {
|
|
1086
1062
|
calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measured);
|
|
1087
1063
|
}
|
|
1088
1064
|
else {
|
|
1089
|
-
calcBoxDelta(visualDelta,
|
|
1065
|
+
calcBoxDelta(visualDelta, layout, snapshot.layout);
|
|
1090
1066
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1067
|
+
const hasLayoutChanged = !isDeltaZero(layoutDelta);
|
|
1068
|
+
let hasRelativeTargetChanged = false;
|
|
1093
1069
|
if (!node.resumeFrom) {
|
|
1094
1070
|
node.relativeParent = node.getClosestProjectingParent();
|
|
1095
1071
|
/**
|
|
@@ -1097,12 +1073,12 @@ function notifyLayoutUpdate(node) {
|
|
|
1097
1073
|
* the relative snapshot is not relavent
|
|
1098
1074
|
*/
|
|
1099
1075
|
if (node.relativeParent && !node.relativeParent.resumeFrom) {
|
|
1100
|
-
|
|
1076
|
+
const { snapshot: parentSnapshot, layout: parentLayout } = node.relativeParent;
|
|
1101
1077
|
if (parentSnapshot && parentLayout) {
|
|
1102
|
-
|
|
1078
|
+
const relativeSnapshot = createBox();
|
|
1103
1079
|
calcRelativePosition(relativeSnapshot, snapshot.layout, parentSnapshot.layout);
|
|
1104
|
-
|
|
1105
|
-
calcRelativePosition(relativeLayout,
|
|
1080
|
+
const relativeLayout = createBox();
|
|
1081
|
+
calcRelativePosition(relativeLayout, layout, parentLayout.actual);
|
|
1106
1082
|
if (!boxEquals(relativeSnapshot, relativeLayout)) {
|
|
1107
1083
|
hasRelativeTargetChanged = true;
|
|
1108
1084
|
}
|
|
@@ -1110,12 +1086,12 @@ function notifyLayoutUpdate(node) {
|
|
|
1110
1086
|
}
|
|
1111
1087
|
}
|
|
1112
1088
|
node.notifyListeners("didUpdate", {
|
|
1113
|
-
layout
|
|
1114
|
-
snapshot
|
|
1089
|
+
layout,
|
|
1090
|
+
snapshot,
|
|
1115
1091
|
delta: visualDelta,
|
|
1116
|
-
layoutDelta
|
|
1117
|
-
hasLayoutChanged
|
|
1118
|
-
hasRelativeTargetChanged
|
|
1092
|
+
layoutDelta,
|
|
1093
|
+
hasLayoutChanged,
|
|
1094
|
+
hasRelativeTargetChanged,
|
|
1119
1095
|
});
|
|
1120
1096
|
}
|
|
1121
1097
|
else if (node.isLead()) {
|
|
@@ -1135,7 +1111,7 @@ function clearMeasurements(node) {
|
|
|
1135
1111
|
node.clearMeasurements();
|
|
1136
1112
|
}
|
|
1137
1113
|
function resetTransformStyle(node) {
|
|
1138
|
-
|
|
1114
|
+
const { visualElement } = node.options;
|
|
1139
1115
|
if (visualElement === null || visualElement === void 0 ? void 0 : visualElement.getProps().onBeforeLayoutMeasure) {
|
|
1140
1116
|
visualElement.notifyBeforeLayoutMeasure();
|
|
1141
1117
|
}
|
|
@@ -1174,7 +1150,7 @@ function mixBox(output, from, to, p) {
|
|
|
1174
1150
|
function hasOpacityCrossfade(node) {
|
|
1175
1151
|
return (node.animationValues && node.animationValues.opacityExit !== undefined);
|
|
1176
1152
|
}
|
|
1177
|
-
|
|
1153
|
+
const defaultLayoutTransition = {
|
|
1178
1154
|
duration: 0.45,
|
|
1179
1155
|
ease: [0.4, 0, 0.1, 1],
|
|
1180
1156
|
};
|
|
@@ -1183,15 +1159,15 @@ function mountNodeEarly(node, id) {
|
|
|
1183
1159
|
* Rather than searching the DOM from document we can search the
|
|
1184
1160
|
* path for the deepest mounted ancestor and search from there
|
|
1185
1161
|
*/
|
|
1186
|
-
|
|
1187
|
-
for (
|
|
1162
|
+
let searchNode = node.root;
|
|
1163
|
+
for (let i = node.path.length - 1; i >= 0; i--) {
|
|
1188
1164
|
if (Boolean(node.path[i].instance)) {
|
|
1189
1165
|
searchNode = node.path[i];
|
|
1190
1166
|
break;
|
|
1191
1167
|
}
|
|
1192
1168
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1169
|
+
const searchElement = searchNode && searchNode !== node.root ? searchNode.instance : document;
|
|
1170
|
+
const element = searchElement.querySelector(`[data-projection-id="${id}"]`);
|
|
1195
1171
|
if (element)
|
|
1196
1172
|
node.mount(element, true);
|
|
1197
1173
|
}
|