framer-motion 5.3.2 → 5.4.0-beta.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.
Files changed (58) hide show
  1. package/dist/es/animation/utils/easing.mjs +1 -1
  2. package/dist/es/animation/utils/transitions.mjs +1 -1
  3. package/dist/es/components/AnimatePresence/index.mjs +1 -1
  4. package/dist/es/components/AnimatePresence/use-presence.mjs +1 -27
  5. package/dist/es/components/AnimateSharedLayout.mjs +1 -1
  6. package/dist/es/components/MotionCanvas/index.mjs +14 -0
  7. package/dist/es/components/Reorder/Item.mjs +1 -1
  8. package/dist/es/context/MotionContext/index.mjs +1 -1
  9. package/dist/es/events/use-dom-event.mjs +2 -31
  10. package/dist/es/events/use-pointer-event.mjs +2 -5
  11. package/dist/es/gestures/utils/event-type.mjs +1 -8
  12. package/dist/es/motion/index.mjs +1 -1
  13. package/dist/es/projection/animation/mix-values.mjs +1 -1
  14. package/dist/es/projection/geometry/models.mjs +1 -11
  15. package/dist/es/projection/node/create-projection-node.mjs +4 -1167
  16. package/dist/es/projection/styles/scale-border-radius.mjs +1 -1
  17. package/dist/es/projection/styles/transform.mjs +5 -5
  18. package/dist/es/render/dom/motion-proxy.mjs +3 -0
  19. package/dist/es/render/dom/utils/css-variables-conversion.mjs +2 -2
  20. package/dist/es/render/dom/utils/filter-props.mjs +3 -1
  21. package/dist/es/render/dom/value-types/dimensions.mjs +1 -8
  22. package/dist/es/render/html/use-props.mjs +1 -1
  23. package/dist/es/render/html/utils/build-transform.mjs +2 -2
  24. package/dist/es/render/svg/utils/path.mjs +1 -1
  25. package/dist/es/render/svg/utils/transform-origin.mjs +1 -1
  26. package/dist/es/render/three/create-visual-element.mjs +42 -0
  27. package/dist/es/render/three/gestures/use-hover.mjs +22 -0
  28. package/dist/es/render/three/gestures/use-tap.mjs +56 -0
  29. package/dist/es/render/three/motion.mjs +30 -0
  30. package/dist/es/render/three/use-render.mjs +11 -0
  31. package/dist/es/render/three/utils/read-value.mjs +43 -0
  32. package/dist/es/render/three/utils/set-value.mjs +59 -0
  33. package/dist/es/render/utils/animation.mjs +1 -4
  34. package/dist/es/render/utils/setters.mjs +2 -39
  35. package/dist/es/three-entry.mjs +2 -0
  36. package/dist/es/utils/array.mjs +2 -13
  37. package/dist/framer-motion-three.cjs.js +3004 -0
  38. package/dist/framer-motion.cjs.js +46 -43
  39. package/dist/framer-motion.dev.js +35 -32
  40. package/dist/framer-motion.js +1 -1
  41. package/dist/projection.dev.js +17 -17
  42. package/dist/size-rollup-dom-animation.js +1 -1
  43. package/dist/size-rollup-dom-max.js +1 -1
  44. package/dist/size-rollup-m.js +1 -1
  45. package/package.json +27 -6
  46. package/types/components/MotionCanvas/index.d.ts +4 -0
  47. package/types/motion/features/types.d.ts +1 -1
  48. package/types/render/three/create-visual-element.d.ts +6 -0
  49. package/types/render/three/gestures/use-hover.d.ts +10 -0
  50. package/types/render/three/gestures/use-tap.d.ts +8 -0
  51. package/types/render/three/motion.d.ts +5 -0
  52. package/types/render/three/types.d.ts +24 -0
  53. package/types/render/three/use-render.d.ts +4 -0
  54. package/types/render/three/utils/read-value.d.ts +2 -0
  55. package/types/render/three/utils/set-value.d.ts +2 -0
  56. package/types/render/utils/lifecycles.d.ts +8 -8
  57. package/types/render/utils/setters.d.ts +1 -0
  58. package/types/three-entry.d.ts +2 -0
@@ -1,30 +1,7 @@
1
- import { __spreadArray, __read, __assign } from 'tslib';
2
- import sync, { cancelSync, flushSync } from 'framesync';
3
- import { mix } from 'popmotion';
4
- import { animate } from '../../animation/animate.mjs';
5
- import { SubscriptionManager } from '../../utils/subscription-manager.mjs';
6
- import { mixValues } from '../animation/mix-values.mjs';
7
- import { copyBoxInto } from '../geometry/copy.mjs';
8
- import { translateAxis, transformBox, applyBoxDelta, applyTreeDeltas } from '../geometry/delta-apply.mjs';
9
- import { calcRelativePosition, calcRelativeBox, calcBoxDelta, calcLength } from '../geometry/delta-calc.mjs';
10
- import { removeBoxTransforms } from '../geometry/delta-remove.mjs';
11
- import { createBox, createDelta } from '../geometry/models.mjs';
12
- import { getValueTransition } from '../../animation/utils/transitions.mjs';
13
- import { boxEquals, isDeltaZero } from '../geometry/utils.mjs';
14
- import { NodeStack } from '../shared/stack.mjs';
15
- import { scaleCorrectors } from '../styles/scale-correction.mjs';
16
- import { buildProjectionTransform } from '../styles/transform.mjs';
17
- import { eachAxis } from '../utils/each-axis.mjs';
18
- import { hasTransform, hasScale } from '../utils/has-transform.mjs';
19
- import { transformAxes } from '../../render/html/utils/transform.mjs';
20
- import { FlatTree } from '../../render/utils/flat-tree.mjs';
21
- import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
1
+ import 'tslib';
2
+ import 'framesync';
3
+ import 'popmotion';
22
4
 
23
- /**
24
- * We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
25
- * which has a noticeable difference in spring animations
26
- */
27
- var animationTarget = 1000;
28
5
  /**
29
6
  * This should only ever be modified on the client otherwise it'll
30
7
  * persist through server requests. If we need instanced states we
@@ -42,1145 +19,5 @@ var globalProjectionState = {
42
19
  */
43
20
  hasEverUpdated: false,
44
21
  };
45
- function createProjectionNode(_a) {
46
- var attachResizeListener = _a.attachResizeListener, defaultParent = _a.defaultParent, measureScroll = _a.measureScroll, resetTransform = _a.resetTransform;
47
- return /** @class */ (function () {
48
- function ProjectionNode(id, latestValues, parent) {
49
- var _this = this;
50
- if (latestValues === void 0) { latestValues = {}; }
51
- if (parent === void 0) { parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent(); }
52
- /**
53
- * A Set containing all this component's children. This is used to iterate
54
- * through the children.
55
- *
56
- * TODO: This could be faster to iterate as a flat array stored on the root node.
57
- */
58
- this.children = new Set();
59
- /**
60
- * Options for the node. We use this to configure what kind of layout animations
61
- * we should perform (if any).
62
- */
63
- this.options = {};
64
- /**
65
- * We use this to detect when its safe to shut down part of a projection tree.
66
- * We have to keep projecting children for scale correction and relative projection
67
- * until all their parents stop performing layout animations.
68
- */
69
- this.isTreeAnimating = false;
70
- this.isAnimationBlocked = false;
71
- /**
72
- * Flag to true if we think this layout has been changed. We can't always know this,
73
- * currently we set it to true every time a component renders, or if it has a layoutDependency
74
- * if that has changed between renders. Additionally, components can be grouped by LayoutGroup
75
- * and if one node is dirtied, they all are.
76
- */
77
- this.isLayoutDirty = false;
78
- /**
79
- * Block layout updates for instant layout transitions throughout the tree.
80
- */
81
- this.updateManuallyBlocked = false;
82
- this.updateBlockedByResize = false;
83
- /**
84
- * Set to true between the start of the first `willUpdate` call and the end of the `didUpdate`
85
- * call.
86
- */
87
- this.isUpdating = false;
88
- /**
89
- * If this is an SVG element we currently disable projection transforms
90
- */
91
- this.isSVG = false;
92
- /**
93
- * Flag to true (during promotion) if a node doing an instant layout transition needs to reset
94
- * its projection styles.
95
- */
96
- this.needsReset = false;
97
- /**
98
- * Flags whether this node should have its transform reset prior to measuring.
99
- */
100
- this.shouldResetTransform = false;
101
- /**
102
- * An object representing the calculated contextual/accumulated/tree scale.
103
- * This will be used to scale calculcated projection transforms, as these are
104
- * calculated in screen-space but need to be scaled for elements to actually
105
- * make it to their calculated destinations.
106
- *
107
- * TODO: Lazy-init
108
- */
109
- this.treeScale = { x: 1, y: 1 };
110
- /**
111
- *
112
- */
113
- this.eventHandlers = new Map();
114
- // Note: Currently only running on root node
115
- this.potentialNodes = new Map();
116
- this.checkUpdateFailed = function () {
117
- if (_this.isUpdating) {
118
- _this.isUpdating = false;
119
- _this.clearAllSnapshots();
120
- }
121
- };
122
- this.updateProjection = function () {
123
- _this.nodes.forEach(resolveTargetDelta);
124
- _this.nodes.forEach(calcProjection);
125
- };
126
- this.hasProjected = false;
127
- this.isVisible = true;
128
- /**
129
- * Animation
130
- */
131
- this.animationProgress = 0;
132
- /**
133
- * Shared layout
134
- */
135
- // TODO Only running on root node
136
- this.sharedNodes = new Map();
137
- this.id = id;
138
- this.latestValues = latestValues;
139
- this.root = parent ? parent.root || parent : this;
140
- this.path = parent ? __spreadArray(__spreadArray([], __read(parent.path), false), [parent], false) : [];
141
- this.parent = parent;
142
- this.depth = parent ? parent.depth + 1 : 0;
143
- id && this.root.registerPotentialNode(id, this);
144
- for (var i = 0; i < this.path.length; i++) {
145
- this.path[i].shouldResetTransform = true;
146
- }
147
- if (this.root === this)
148
- this.nodes = new FlatTree();
149
- }
150
- ProjectionNode.prototype.addEventListener = function (name, handler) {
151
- if (!this.eventHandlers.has(name)) {
152
- this.eventHandlers.set(name, new SubscriptionManager());
153
- }
154
- return this.eventHandlers.get(name).add(handler);
155
- };
156
- ProjectionNode.prototype.notifyListeners = function (name) {
157
- var args = [];
158
- for (var _i = 1; _i < arguments.length; _i++) {
159
- args[_i - 1] = arguments[_i];
160
- }
161
- var subscriptionManager = this.eventHandlers.get(name);
162
- subscriptionManager === null || subscriptionManager === void 0 ? void 0 : subscriptionManager.notify.apply(subscriptionManager, __spreadArray([], __read(args), false));
163
- };
164
- ProjectionNode.prototype.hasListeners = function (name) {
165
- return this.eventHandlers.has(name);
166
- };
167
- ProjectionNode.prototype.registerPotentialNode = function (id, node) {
168
- this.potentialNodes.set(id, node);
169
- };
170
- /**
171
- * Lifecycles
172
- */
173
- ProjectionNode.prototype.mount = function (instance, isLayoutDirty) {
174
- var _this = this;
175
- var _a;
176
- if (isLayoutDirty === void 0) { isLayoutDirty = false; }
177
- if (this.instance)
178
- return;
179
- this.isSVG =
180
- instance instanceof SVGElement && instance.tagName !== "svg";
181
- this.instance = instance;
182
- var _b = this.options, layoutId = _b.layoutId, layout = _b.layout, visualElement = _b.visualElement;
183
- if (visualElement && !visualElement.getInstance()) {
184
- visualElement.mount(instance);
185
- }
186
- this.root.nodes.add(this);
187
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.children.add(this);
188
- this.id && this.root.potentialNodes.delete(this.id);
189
- if (isLayoutDirty && (layout || layoutId)) {
190
- this.isLayoutDirty = true;
191
- }
192
- if (attachResizeListener) {
193
- var unblockTimeout_1;
194
- var resizeUnblockUpdate_1 = function () {
195
- return (_this.root.updateBlockedByResize = false);
196
- };
197
- attachResizeListener(instance, function () {
198
- _this.root.updateBlockedByResize = true;
199
- clearTimeout(unblockTimeout_1);
200
- unblockTimeout_1 = setTimeout(resizeUnblockUpdate_1, 250);
201
- if (globalProjectionState.hasAnimatedSinceResize) {
202
- globalProjectionState.hasAnimatedSinceResize = false;
203
- _this.nodes.forEach(finishAnimation);
204
- }
205
- });
206
- }
207
- if (layoutId) {
208
- this.root.registerSharedNode(layoutId, this);
209
- }
210
- // Only register the handler if it requires layout animation
211
- if (this.options.animate !== false &&
212
- visualElement &&
213
- (layoutId || layout)) {
214
- this.addEventListener("didUpdate", function (_a) {
215
- var _b, _c, _d, _e, _f;
216
- var delta = _a.delta, hasLayoutChanged = _a.hasLayoutChanged, hasRelativeTargetChanged = _a.hasRelativeTargetChanged, newLayout = _a.layout;
217
- if (_this.isTreeAnimationBlocked()) {
218
- _this.target = undefined;
219
- _this.relativeTarget = undefined;
220
- return;
221
- }
222
- // TODO: Check here if an animation exists
223
- var layoutTransition = (_c = (_b = _this.options.transition) !== null && _b !== void 0 ? _b : visualElement.getDefaultTransition()) !== null && _c !== void 0 ? _c : defaultLayoutTransition;
224
- var onLayoutAnimationComplete = visualElement.getProps().onLayoutAnimationComplete;
225
- /**
226
- * The target layout of the element might stay the same,
227
- * but its position relative to its parent has changed.
228
- */
229
- var targetChanged = !_this.targetLayout ||
230
- !boxEquals(_this.targetLayout, newLayout) ||
231
- hasRelativeTargetChanged;
232
- /**
233
- * If the layout hasn't seemed to have changed, it might be that the
234
- * element is visually in the same place in the document but its position
235
- * relative to its parent has indeed changed. So here we check for that.
236
- */
237
- var hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeTargetChanged;
238
- if (((_d = _this.resumeFrom) === null || _d === void 0 ? void 0 : _d.instance) ||
239
- hasOnlyRelativeTargetChanged ||
240
- (hasLayoutChanged &&
241
- (targetChanged || !_this.currentAnimation))) {
242
- if (_this.resumeFrom) {
243
- _this.resumingFrom = _this.resumeFrom;
244
- _this.resumingFrom.resumingFrom = undefined;
245
- }
246
- _this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
247
- _this.startAnimation(__assign(__assign({}, getValueTransition(layoutTransition, "layout")), { onComplete: onLayoutAnimationComplete }));
248
- }
249
- else {
250
- _this.isLead() && ((_f = (_e = _this.options).onExitComplete) === null || _f === void 0 ? void 0 : _f.call(_e));
251
- }
252
- _this.targetLayout = newLayout;
253
- });
254
- }
255
- };
256
- ProjectionNode.prototype.unmount = function () {
257
- var _a, _b;
258
- this.options.layoutId && this.willUpdate();
259
- this.root.nodes.remove(this);
260
- (_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.remove(this);
261
- (_b = this.parent) === null || _b === void 0 ? void 0 : _b.children.delete(this);
262
- this.instance = undefined;
263
- cancelSync.preRender(this.updateProjection);
264
- };
265
- // only on the root
266
- ProjectionNode.prototype.blockUpdate = function () {
267
- this.updateManuallyBlocked = true;
268
- };
269
- ProjectionNode.prototype.unblockUpdate = function () {
270
- this.updateManuallyBlocked = false;
271
- };
272
- ProjectionNode.prototype.isUpdateBlocked = function () {
273
- return this.updateManuallyBlocked || this.updateBlockedByResize;
274
- };
275
- ProjectionNode.prototype.isTreeAnimationBlocked = function () {
276
- var _a;
277
- return (this.isAnimationBlocked ||
278
- ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isTreeAnimationBlocked()) ||
279
- false);
280
- };
281
- // Note: currently only running on root node
282
- ProjectionNode.prototype.startUpdate = function () {
283
- var _a;
284
- if (this.isUpdateBlocked())
285
- return;
286
- this.isUpdating = true;
287
- (_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach(resetRotation);
288
- };
289
- ProjectionNode.prototype.willUpdate = function (shouldNotifyListeners) {
290
- var _a, _b, _c;
291
- if (shouldNotifyListeners === void 0) { shouldNotifyListeners = true; }
292
- if (this.root.isUpdateBlocked()) {
293
- (_b = (_a = this.options).onExitComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
294
- return;
295
- }
296
- !this.root.isUpdating && this.root.startUpdate();
297
- if (this.isLayoutDirty)
298
- return;
299
- this.isLayoutDirty = true;
300
- for (var i = 0; i < this.path.length; i++) {
301
- var node = this.path[i];
302
- node.shouldResetTransform = true;
303
- /**
304
- * TODO: Check we haven't updated the scroll
305
- * since the last didUpdate
306
- */
307
- node.updateScroll();
308
- }
309
- var _d = this.options, layoutId = _d.layoutId, layout = _d.layout;
310
- if (layoutId === undefined && !layout)
311
- return;
312
- var transformTemplate = (_c = this.options.visualElement) === null || _c === void 0 ? void 0 : _c.getProps().transformTemplate;
313
- this.prevTransformTemplateValue = transformTemplate === null || transformTemplate === void 0 ? void 0 : transformTemplate(this.latestValues, "");
314
- this.updateSnapshot();
315
- shouldNotifyListeners && this.notifyListeners("willUpdate");
316
- };
317
- // Note: Currently only running on root node
318
- ProjectionNode.prototype.didUpdate = function () {
319
- var updateWasBlocked = this.isUpdateBlocked();
320
- // When doing an instant transition, we skip the layout update,
321
- // but should still clean up the measurements so that the next
322
- // snapshot could be taken correctly.
323
- if (updateWasBlocked) {
324
- this.unblockUpdate();
325
- this.clearAllSnapshots();
326
- this.nodes.forEach(clearMeasurements);
327
- return;
328
- }
329
- if (!this.isUpdating)
330
- return;
331
- this.isUpdating = false;
332
- /**
333
- * Search for and mount newly-added projection elements.
334
- *
335
- * TODO: Every time a new component is rendered we could search up the tree for
336
- * the closest mounted node and query from there rather than document.
337
- */
338
- if (this.potentialNodes.size) {
339
- this.potentialNodes.forEach(mountNodeEarly);
340
- this.potentialNodes.clear();
341
- }
342
- /**
343
- * Write
344
- */
345
- this.nodes.forEach(resetTransformStyle);
346
- /**
347
- * Read ==================
348
- */
349
- // Update layout measurements of updated children
350
- this.nodes.forEach(updateLayout);
351
- /**
352
- * Write
353
- */
354
- // Notify listeners that the layout is updated
355
- this.nodes.forEach(notifyLayoutUpdate);
356
- this.clearAllSnapshots();
357
- // Flush any scheduled updates
358
- flushSync.update();
359
- flushSync.preRender();
360
- flushSync.render();
361
- };
362
- ProjectionNode.prototype.clearAllSnapshots = function () {
363
- this.nodes.forEach(clearSnapshot);
364
- this.sharedNodes.forEach(removeLeadSnapshots);
365
- };
366
- ProjectionNode.prototype.scheduleUpdateProjection = function () {
367
- sync.preRender(this.updateProjection, false, true);
368
- };
369
- ProjectionNode.prototype.scheduleCheckAfterUnmount = function () {
370
- var _this = this;
371
- /**
372
- * If the unmounting node is in a layoutGroup and did trigger a willUpdate,
373
- * we manually call didUpdate to give a chance to the siblings to animate.
374
- * Otherwise, cleanup all snapshots to prevents future nodes from reusing them.
375
- */
376
- sync.postRender(function () {
377
- if (_this.isLayoutDirty) {
378
- _this.root.didUpdate();
379
- }
380
- else {
381
- _this.root.checkUpdateFailed();
382
- }
383
- });
384
- };
385
- /**
386
- * Update measurements
387
- */
388
- ProjectionNode.prototype.updateSnapshot = function () {
389
- if (this.snapshot || !this.instance)
390
- return;
391
- var measured = this.measure();
392
- var layout = this.removeTransform(this.removeElementScroll(measured));
393
- roundBox(layout);
394
- this.snapshot = {
395
- measured: measured,
396
- layout: layout,
397
- latestValues: {},
398
- };
399
- };
400
- ProjectionNode.prototype.updateLayout = function () {
401
- var _a;
402
- if (!this.instance)
403
- return;
404
- // TODO: Incorporate into a forwarded scroll offset
405
- this.updateScroll();
406
- if (!(this.options.alwaysMeasureLayout && this.isLead()) &&
407
- !this.isLayoutDirty) {
408
- return;
409
- }
410
- /**
411
- * When a node is mounted, it simply resumes from the prevLead's
412
- * snapshot instead of taking a new one, but the ancestors scroll
413
- * might have updated while the prevLead is unmounted. We need to
414
- * update the scroll again to make sure the layout we measure is
415
- * up to date.
416
- */
417
- if (this.resumeFrom && !this.resumeFrom.instance) {
418
- for (var i = 0; i < this.path.length; i++) {
419
- var node = this.path[i];
420
- node.updateScroll();
421
- }
422
- }
423
- var measured = this.measure();
424
- roundBox(measured);
425
- var prevLayout = this.layout;
426
- this.layout = {
427
- measured: measured,
428
- actual: this.removeElementScroll(measured),
429
- };
430
- this.layoutCorrected = createBox();
431
- this.isLayoutDirty = false;
432
- this.projectionDelta = undefined;
433
- this.notifyListeners("measure");
434
- (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.notifyLayoutMeasure(this.layout.actual, prevLayout === null || prevLayout === void 0 ? void 0 : prevLayout.actual);
435
- };
436
- ProjectionNode.prototype.updateScroll = function () {
437
- if (this.options.layoutScroll && this.instance) {
438
- this.scroll = measureScroll(this.instance);
439
- }
440
- };
441
- ProjectionNode.prototype.resetTransform = function () {
442
- var _a;
443
- if (!resetTransform)
444
- return;
445
- var isResetRequested = this.isLayoutDirty || this.shouldResetTransform;
446
- var hasProjection = this.projectionDelta && !isDeltaZero(this.projectionDelta);
447
- var transformTemplate = (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.getProps().transformTemplate;
448
- var transformTemplateValue = transformTemplate === null || transformTemplate === void 0 ? void 0 : transformTemplate(this.latestValues, "");
449
- var transformTemplateHasChanged = transformTemplateValue !== this.prevTransformTemplateValue;
450
- if (isResetRequested &&
451
- (hasProjection ||
452
- hasTransform(this.latestValues) ||
453
- transformTemplateHasChanged)) {
454
- resetTransform(this.instance, transformTemplateValue);
455
- this.shouldResetTransform = false;
456
- this.scheduleRender();
457
- }
458
- };
459
- ProjectionNode.prototype.measure = function () {
460
- var visualElement = this.options.visualElement;
461
- if (!visualElement)
462
- return createBox();
463
- var box = visualElement.measureViewportBox();
464
- // Remove viewport scroll to give page-relative coordinates
465
- var scroll = this.root.scroll;
466
- if (scroll) {
467
- translateAxis(box.x, scroll.x);
468
- translateAxis(box.y, scroll.y);
469
- }
470
- return box;
471
- };
472
- ProjectionNode.prototype.removeElementScroll = function (box) {
473
- var boxWithoutScroll = createBox();
474
- copyBoxInto(boxWithoutScroll, box);
475
- /**
476
- * Performance TODO: Keep a cumulative scroll offset down the tree
477
- * rather than loop back up the path.
478
- */
479
- for (var i = 0; i < this.path.length; i++) {
480
- var node = this.path[i];
481
- var scroll_1 = node.scroll, options = node.options;
482
- if (node !== this.root && scroll_1 && options.layoutScroll) {
483
- translateAxis(boxWithoutScroll.x, scroll_1.x);
484
- translateAxis(boxWithoutScroll.y, scroll_1.y);
485
- }
486
- }
487
- return boxWithoutScroll;
488
- };
489
- ProjectionNode.prototype.applyTransform = function (box, transformOnly) {
490
- if (transformOnly === void 0) { transformOnly = false; }
491
- var withTransforms = createBox();
492
- copyBoxInto(withTransforms, box);
493
- for (var i = 0; i < this.path.length; i++) {
494
- var node = this.path[i];
495
- if (!transformOnly &&
496
- node.options.layoutScroll &&
497
- node.scroll &&
498
- node !== node.root) {
499
- transformBox(withTransforms, {
500
- x: -node.scroll.x,
501
- y: -node.scroll.y,
502
- });
503
- }
504
- if (!hasTransform(node.latestValues))
505
- continue;
506
- transformBox(withTransforms, node.latestValues);
507
- }
508
- if (hasTransform(this.latestValues)) {
509
- transformBox(withTransforms, this.latestValues);
510
- }
511
- return withTransforms;
512
- };
513
- ProjectionNode.prototype.removeTransform = function (box) {
514
- var _a;
515
- var boxWithoutTransform = createBox();
516
- copyBoxInto(boxWithoutTransform, box);
517
- for (var i = 0; i < this.path.length; i++) {
518
- var node = this.path[i];
519
- if (!node.instance)
520
- continue;
521
- if (!hasTransform(node.latestValues))
522
- continue;
523
- hasScale(node.latestValues) && node.updateSnapshot();
524
- var sourceBox = createBox();
525
- var nodeBox = node.measure();
526
- copyBoxInto(sourceBox, nodeBox);
527
- removeBoxTransforms(boxWithoutTransform, node.latestValues, (_a = node.snapshot) === null || _a === void 0 ? void 0 : _a.layout, sourceBox);
528
- }
529
- if (hasTransform(this.latestValues)) {
530
- removeBoxTransforms(boxWithoutTransform, this.latestValues);
531
- }
532
- return boxWithoutTransform;
533
- };
534
- /**
535
- *
536
- */
537
- ProjectionNode.prototype.setTargetDelta = function (delta) {
538
- this.targetDelta = delta;
539
- this.root.scheduleUpdateProjection();
540
- };
541
- ProjectionNode.prototype.setOptions = function (options) {
542
- var _a;
543
- this.options = __assign(__assign(__assign({}, this.options), options), { crossfade: (_a = options.crossfade) !== null && _a !== void 0 ? _a : true });
544
- };
545
- ProjectionNode.prototype.clearMeasurements = function () {
546
- this.scroll = undefined;
547
- this.layout = undefined;
548
- this.snapshot = undefined;
549
- this.prevTransformTemplateValue = undefined;
550
- this.targetDelta = undefined;
551
- this.target = undefined;
552
- this.isLayoutDirty = false;
553
- };
554
- /**
555
- * Frame calculations
556
- */
557
- ProjectionNode.prototype.resolveTargetDelta = function () {
558
- var _a;
559
- var _b = this.options, layout = _b.layout, layoutId = _b.layoutId;
560
- /**
561
- * If we have no layout, we can't perform projection, so early return
562
- */
563
- if (!this.layout || !(layout || layoutId))
564
- return;
565
- /**
566
- * If we don't have a targetDelta but do have a layout, we can attempt to resolve
567
- * a relativeParent. This will allow a component to perform scale correction
568
- * even if no animation has started.
569
- */
570
- // TODO If this is unsuccessful this currently happens every frame
571
- if (!this.targetDelta && !this.relativeTarget) {
572
- // TODO: This is a semi-repetition of further down this function, make DRY
573
- this.relativeParent = this.getClosestProjectingParent();
574
- if (this.relativeParent && this.relativeParent.layout) {
575
- this.relativeTarget = createBox();
576
- this.relativeTargetOrigin = createBox();
577
- calcRelativePosition(this.relativeTargetOrigin, this.layout.actual, this.relativeParent.layout.actual);
578
- copyBoxInto(this.relativeTarget, this.relativeTargetOrigin);
579
- }
580
- }
581
- /**
582
- * If we have no relative target or no target delta our target isn't valid
583
- * for this frame.
584
- */
585
- if (!this.relativeTarget && !this.targetDelta)
586
- return;
587
- /**
588
- * Lazy-init target data structure
589
- */
590
- if (!this.target) {
591
- this.target = createBox();
592
- this.targetWithTransforms = createBox();
593
- }
594
- /**
595
- * If we've got a relative box for this component, resolve it into a target relative to the parent.
596
- */
597
- if (this.relativeTarget &&
598
- this.relativeTargetOrigin &&
599
- ((_a = this.relativeParent) === null || _a === void 0 ? void 0 : _a.target)) {
600
- calcRelativeBox(this.target, this.relativeTarget, this.relativeParent.target);
601
- /**
602
- * If we've only got a targetDelta, resolve it into a target
603
- */
604
- }
605
- else if (this.targetDelta) {
606
- if (Boolean(this.resumingFrom)) {
607
- // TODO: This is creating a new object every frame
608
- this.target = this.applyTransform(this.layout.actual);
609
- }
610
- else {
611
- copyBoxInto(this.target, this.layout.actual);
612
- }
613
- applyBoxDelta(this.target, this.targetDelta);
614
- }
615
- else {
616
- /**
617
- * If no target, use own layout as target
618
- */
619
- copyBoxInto(this.target, this.layout.actual);
620
- }
621
- /**
622
- * If we've been told to attempt to resolve a relative target, do so.
623
- */
624
- if (this.attemptToResolveRelativeTarget) {
625
- this.attemptToResolveRelativeTarget = false;
626
- this.relativeParent = this.getClosestProjectingParent();
627
- if (this.relativeParent &&
628
- Boolean(this.relativeParent.resumingFrom) ===
629
- Boolean(this.resumingFrom) &&
630
- !this.relativeParent.options.layoutScroll &&
631
- this.relativeParent.target) {
632
- this.relativeTarget = createBox();
633
- this.relativeTargetOrigin = createBox();
634
- calcRelativePosition(this.relativeTargetOrigin, this.target, this.relativeParent.target);
635
- copyBoxInto(this.relativeTarget, this.relativeTargetOrigin);
636
- }
637
- }
638
- };
639
- ProjectionNode.prototype.getClosestProjectingParent = function () {
640
- if (!this.parent || hasTransform(this.parent.latestValues))
641
- return undefined;
642
- if ((this.parent.relativeTarget || this.parent.targetDelta) &&
643
- this.parent.layout) {
644
- return this.parent;
645
- }
646
- else {
647
- return this.parent.getClosestProjectingParent();
648
- }
649
- };
650
- ProjectionNode.prototype.calcProjection = function () {
651
- var _a;
652
- var _b = this.options, layout = _b.layout, layoutId = _b.layoutId;
653
- /**
654
- * If this section of the tree isn't animating we can
655
- * delete our target sources for the following frame.
656
- */
657
- this.isTreeAnimating = Boolean(((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isTreeAnimating) ||
658
- this.currentAnimation ||
659
- this.pendingAnimation);
660
- if (!this.isTreeAnimating) {
661
- this.targetDelta = this.relativeTarget = undefined;
662
- }
663
- if (!this.layout || !(layout || layoutId))
664
- return;
665
- var lead = this.getLead();
666
- /**
667
- * Reset the corrected box with the latest values from box, as we're then going
668
- * to perform mutative operations on it.
669
- */
670
- copyBoxInto(this.layoutCorrected, this.layout.actual);
671
- /**
672
- * Apply all the parent deltas to this box to produce the corrected box. This
673
- * is the layout box, as it will appear on screen as a result of the transforms of its parents.
674
- */
675
- applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, Boolean(this.resumingFrom) || this !== lead);
676
- var target = lead.target;
677
- if (!target)
678
- return;
679
- if (!this.projectionDelta) {
680
- this.projectionDelta = createDelta();
681
- this.projectionDeltaWithTransform = createDelta();
682
- }
683
- var prevTreeScaleX = this.treeScale.x;
684
- var prevTreeScaleY = this.treeScale.y;
685
- var prevProjectionTransform = this.projectionTransform;
686
- /**
687
- * Update the delta between the corrected box and the target box before user-set transforms were applied.
688
- * This will allow us to calculate the corrected borderRadius and boxShadow to compensate
689
- * for our layout reprojection, but still allow them to be scaled correctly by the user.
690
- * It might be that to simplify this we may want to accept that user-set scale is also corrected
691
- * and we wouldn't have to keep and calc both deltas, OR we could support a user setting
692
- * to allow people to choose whether these styles are corrected based on just the
693
- * layout reprojection or the final bounding box.
694
- */
695
- calcBoxDelta(this.projectionDelta, this.layoutCorrected, target, this.latestValues);
696
- this.projectionTransform = buildProjectionTransform(this.projectionDelta, this.treeScale);
697
- if (this.projectionTransform !== prevProjectionTransform ||
698
- this.treeScale.x !== prevTreeScaleX ||
699
- this.treeScale.y !== prevTreeScaleY) {
700
- this.hasProjected = true;
701
- this.scheduleRender();
702
- }
703
- };
704
- ProjectionNode.prototype.hide = function () {
705
- this.isVisible = false;
706
- // TODO: Schedule render
707
- };
708
- ProjectionNode.prototype.show = function () {
709
- this.isVisible = true;
710
- // TODO: Schedule render
711
- };
712
- ProjectionNode.prototype.scheduleRender = function (notifyAll) {
713
- var _a, _b, _c;
714
- if (notifyAll === void 0) { notifyAll = true; }
715
- (_b = (_a = this.options).scheduleRender) === null || _b === void 0 ? void 0 : _b.call(_a);
716
- notifyAll && ((_c = this.getStack()) === null || _c === void 0 ? void 0 : _c.scheduleRender());
717
- if (this.resumingFrom && !this.resumingFrom.instance) {
718
- this.resumingFrom = undefined;
719
- }
720
- };
721
- ProjectionNode.prototype.setAnimationOrigin = function (delta, hasOnlyRelativeTargetChanged) {
722
- var _this = this;
723
- var _a;
724
- if (hasOnlyRelativeTargetChanged === void 0) { hasOnlyRelativeTargetChanged = false; }
725
- var snapshot = this.snapshot;
726
- var snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
727
- var mixedValues = __assign({}, this.latestValues);
728
- var targetDelta = createDelta();
729
- this.relativeTarget = this.relativeTargetOrigin = undefined;
730
- this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
731
- var relativeLayout = createBox();
732
- var isSharedLayoutAnimation = snapshot === null || snapshot === void 0 ? void 0 : snapshot.isShared;
733
- var isOnlyMember = (((_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.members.length) || 0) <= 1;
734
- var shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
735
- !isOnlyMember &&
736
- this.options.crossfade === true &&
737
- !this.path.some(hasOpacityCrossfade));
738
- this.mixTargetDelta = function (latest) {
739
- var _a;
740
- var progress = latest / 1000;
741
- mixAxisDelta(targetDelta.x, delta.x, progress);
742
- mixAxisDelta(targetDelta.y, delta.y, progress);
743
- _this.setTargetDelta(targetDelta);
744
- if (_this.relativeTarget &&
745
- _this.relativeTargetOrigin &&
746
- _this.layout &&
747
- ((_a = _this.relativeParent) === null || _a === void 0 ? void 0 : _a.layout)) {
748
- calcRelativePosition(relativeLayout, _this.layout.actual, _this.relativeParent.layout.actual);
749
- mixBox(_this.relativeTarget, _this.relativeTargetOrigin, relativeLayout, progress);
750
- }
751
- if (isSharedLayoutAnimation) {
752
- _this.animationValues = mixedValues;
753
- mixValues(mixedValues, snapshotLatestValues, _this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
754
- }
755
- _this.root.scheduleUpdateProjection();
756
- _this.scheduleRender();
757
- };
758
- this.mixTargetDelta(0);
759
- };
760
- ProjectionNode.prototype.startAnimation = function (options) {
761
- var _this = this;
762
- var _a, _b;
763
- (_a = this.currentAnimation) === null || _a === void 0 ? void 0 : _a.stop();
764
- if (this.resumingFrom) {
765
- (_b = this.resumingFrom.currentAnimation) === null || _b === void 0 ? void 0 : _b.stop();
766
- }
767
- if (this.pendingAnimation) {
768
- cancelSync.update(this.pendingAnimation);
769
- this.pendingAnimation = undefined;
770
- }
771
- /**
772
- * Start the animation in the next frame to have a frame with progress 0,
773
- * where the target is the same as when the animation started, so we can
774
- * calculate the relative positions correctly for instant transitions.
775
- */
776
- this.pendingAnimation = sync.update(function () {
777
- globalProjectionState.hasAnimatedSinceResize = true;
778
- _this.currentAnimation = animate(0, animationTarget, __assign(__assign({}, options), { onUpdate: function (latest) {
779
- var _a;
780
- _this.mixTargetDelta(latest);
781
- (_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
782
- }, onComplete: function () {
783
- var _a;
784
- (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
785
- _this.completeAnimation();
786
- } }));
787
- if (_this.resumingFrom) {
788
- _this.resumingFrom.currentAnimation = _this.currentAnimation;
789
- }
790
- _this.pendingAnimation = undefined;
791
- });
792
- };
793
- ProjectionNode.prototype.completeAnimation = function () {
794
- var _a;
795
- if (this.resumingFrom) {
796
- this.resumingFrom.currentAnimation = undefined;
797
- this.resumingFrom.preserveOpacity = undefined;
798
- }
799
- (_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.exitAnimationComplete();
800
- this.resumingFrom =
801
- this.currentAnimation =
802
- this.animationValues =
803
- undefined;
804
- };
805
- ProjectionNode.prototype.finishAnimation = function () {
806
- var _a;
807
- if (this.currentAnimation) {
808
- (_a = this.mixTargetDelta) === null || _a === void 0 ? void 0 : _a.call(this, animationTarget);
809
- this.currentAnimation.stop();
810
- }
811
- this.completeAnimation();
812
- };
813
- ProjectionNode.prototype.applyTransformsToTarget = function () {
814
- var _a = this.getLead(), targetWithTransforms = _a.targetWithTransforms, target = _a.target, layout = _a.layout, latestValues = _a.latestValues;
815
- if (!targetWithTransforms || !target || !layout)
816
- return;
817
- copyBoxInto(targetWithTransforms, target);
818
- /**
819
- * Apply the latest user-set transforms to the targetBox to produce the targetBoxFinal.
820
- * This is the final box that we will then project into by calculating a transform delta and
821
- * applying it to the corrected box.
822
- */
823
- transformBox(targetWithTransforms, latestValues);
824
- /**
825
- * Update the delta between the corrected box and the final target box, after
826
- * user-set transforms are applied to it. This will be used by the renderer to
827
- * create a transform style that will reproject the element from its actual layout
828
- * into the desired bounding box.
829
- */
830
- calcBoxDelta(this.projectionDeltaWithTransform, this.layoutCorrected, targetWithTransforms, latestValues);
831
- };
832
- ProjectionNode.prototype.registerSharedNode = function (layoutId, node) {
833
- var _a, _b, _c;
834
- if (!this.sharedNodes.has(layoutId)) {
835
- this.sharedNodes.set(layoutId, new NodeStack());
836
- }
837
- var stack = this.sharedNodes.get(layoutId);
838
- stack.add(node);
839
- node.promote({
840
- transition: (_a = node.options.initialPromotionConfig) === null || _a === void 0 ? void 0 : _a.transition,
841
- preserveFollowOpacity: (_c = (_b = node.options.initialPromotionConfig) === null || _b === void 0 ? void 0 : _b.shouldPreserveFollowOpacity) === null || _c === void 0 ? void 0 : _c.call(_b, node),
842
- });
843
- };
844
- ProjectionNode.prototype.isLead = function () {
845
- var stack = this.getStack();
846
- return stack ? stack.lead === this : true;
847
- };
848
- ProjectionNode.prototype.getLead = function () {
849
- var _a;
850
- var layoutId = this.options.layoutId;
851
- return layoutId ? ((_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.lead) || this : this;
852
- };
853
- ProjectionNode.prototype.getPrevLead = function () {
854
- var _a;
855
- var layoutId = this.options.layoutId;
856
- return layoutId ? (_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.prevLead : undefined;
857
- };
858
- ProjectionNode.prototype.getStack = function () {
859
- var layoutId = this.options.layoutId;
860
- if (layoutId)
861
- return this.root.sharedNodes.get(layoutId);
862
- };
863
- ProjectionNode.prototype.promote = function (_a) {
864
- var _b = _a === void 0 ? {} : _a, needsReset = _b.needsReset, transition = _b.transition, preserveFollowOpacity = _b.preserveFollowOpacity;
865
- var stack = this.getStack();
866
- if (stack)
867
- stack.promote(this, preserveFollowOpacity);
868
- if (needsReset) {
869
- this.projectionDelta = undefined;
870
- this.needsReset = true;
871
- }
872
- if (transition)
873
- this.setOptions({ transition: transition });
874
- };
875
- ProjectionNode.prototype.relegate = function () {
876
- var stack = this.getStack();
877
- if (stack) {
878
- return stack.relegate(this);
879
- }
880
- else {
881
- return false;
882
- }
883
- };
884
- ProjectionNode.prototype.resetRotation = function () {
885
- var visualElement = this.options.visualElement;
886
- if (!visualElement)
887
- return;
888
- // If there's no detected rotation values, we can early return without a forced render.
889
- var hasRotate = false;
890
- // Keep a record of all the values we've reset
891
- var resetValues = {};
892
- // Check the rotate value of all axes and reset to 0
893
- for (var i = 0; i < transformAxes.length; i++) {
894
- var axis = transformAxes[i];
895
- var key = "rotate" + axis;
896
- // If this rotation doesn't exist as a motion value, then we don't
897
- // need to reset it
898
- if (!visualElement.getStaticValue(key)) {
899
- continue;
900
- }
901
- hasRotate = true;
902
- // Record the rotation and then temporarily set it to 0
903
- resetValues[key] = visualElement.getStaticValue(key);
904
- visualElement.setStaticValue(key, 0);
905
- }
906
- // If there's no rotation values, we don't need to do any more.
907
- if (!hasRotate)
908
- return;
909
- // Force a render of this element to apply the transform with all rotations
910
- // set to 0.
911
- visualElement === null || visualElement === void 0 ? void 0 : visualElement.syncRender();
912
- // Put back all the values we reset
913
- for (var key in resetValues) {
914
- visualElement.setStaticValue(key, resetValues[key]);
915
- }
916
- // Schedule a render for the next frame. This ensures we won't visually
917
- // see the element with the reset rotate value applied.
918
- visualElement.scheduleRender();
919
- };
920
- ProjectionNode.prototype.getProjectionStyles = function (styleProp) {
921
- var _a, _b, _c, _d, _e, _f;
922
- if (styleProp === void 0) { styleProp = {}; }
923
- // TODO: Return lifecycle-persistent object
924
- var styles = {};
925
- if (!this.instance || this.isSVG)
926
- return styles;
927
- if (!this.isVisible) {
928
- return { visibility: "hidden" };
929
- }
930
- else {
931
- styles.visibility = "";
932
- }
933
- var transformTemplate = (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.getProps().transformTemplate;
934
- if (this.needsReset) {
935
- this.needsReset = false;
936
- styles.opacity = "";
937
- styles.pointerEvents =
938
- resolveMotionValue(styleProp.pointerEvents) || "";
939
- styles.transform = transformTemplate
940
- ? transformTemplate(this.latestValues, "")
941
- : "none";
942
- return styles;
943
- }
944
- var lead = this.getLead();
945
- if (!this.projectionDelta || !this.layout || !lead.target) {
946
- var emptyStyles = {};
947
- if (this.options.layoutId) {
948
- emptyStyles.opacity = (_b = this.latestValues.opacity) !== null && _b !== void 0 ? _b : 1;
949
- emptyStyles.pointerEvents =
950
- resolveMotionValue(styleProp.pointerEvents) || "";
951
- }
952
- if (this.hasProjected && !hasTransform(this.latestValues)) {
953
- emptyStyles.transform = transformTemplate
954
- ? transformTemplate({}, "")
955
- : "none";
956
- this.hasProjected = false;
957
- }
958
- return emptyStyles;
959
- }
960
- var valuesToRender = lead.animationValues || lead.latestValues;
961
- this.applyTransformsToTarget();
962
- styles.transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
963
- if (transformTemplate) {
964
- styles.transform = transformTemplate(valuesToRender, styles.transform);
965
- }
966
- var _g = this.projectionDelta, x = _g.x, y = _g.y;
967
- styles.transformOrigin = x.origin * 100 + "% " + y.origin * 100 + "% 0";
968
- if (lead.animationValues) {
969
- /**
970
- * If the lead component is animating, assign this either the entering/leaving
971
- * opacity
972
- */
973
- styles.opacity =
974
- lead === this
975
- ? (_d = (_c = valuesToRender.opacity) !== null && _c !== void 0 ? _c : this.latestValues.opacity) !== null && _d !== void 0 ? _d : 1
976
- : this.preserveOpacity
977
- ? this.latestValues.opacity
978
- : valuesToRender.opacityExit;
979
- }
980
- else {
981
- /**
982
- * Or we're not animating at all, set the lead component to its actual
983
- * opacity and other components to hidden.
984
- */
985
- styles.opacity =
986
- lead === this
987
- ? (_e = valuesToRender.opacity) !== null && _e !== void 0 ? _e : ""
988
- : (_f = valuesToRender.opacityExit) !== null && _f !== void 0 ? _f : 0;
989
- }
990
- /**
991
- * Apply scale correction
992
- */
993
- for (var key in scaleCorrectors) {
994
- if (valuesToRender[key] === undefined)
995
- continue;
996
- var _h = scaleCorrectors[key], correct = _h.correct, applyTo = _h.applyTo;
997
- var corrected = correct(valuesToRender[key], lead);
998
- if (applyTo) {
999
- var num = applyTo.length;
1000
- for (var i = 0; i < num; i++) {
1001
- styles[applyTo[i]] = corrected;
1002
- }
1003
- }
1004
- else {
1005
- styles[key] = corrected;
1006
- }
1007
- }
1008
- /**
1009
- * Disable pointer events on follow components. This is to ensure
1010
- * that if a follow component covers a lead component it doesn't block
1011
- * pointer events on the lead.
1012
- */
1013
- if (this.options.layoutId) {
1014
- styles.pointerEvents =
1015
- lead === this
1016
- ? resolveMotionValue(styleProp.pointerEvents) || ""
1017
- : "none";
1018
- }
1019
- return styles;
1020
- };
1021
- ProjectionNode.prototype.clearSnapshot = function () {
1022
- this.resumeFrom = this.snapshot = undefined;
1023
- };
1024
- // Only run on root
1025
- ProjectionNode.prototype.resetTree = function () {
1026
- this.root.nodes.forEach(function (node) { var _a; return (_a = node.currentAnimation) === null || _a === void 0 ? void 0 : _a.stop(); });
1027
- this.root.nodes.forEach(clearMeasurements);
1028
- this.root.sharedNodes.clear();
1029
- };
1030
- return ProjectionNode;
1031
- }());
1032
- }
1033
- function updateLayout(node) {
1034
- node.updateLayout();
1035
- }
1036
- function notifyLayoutUpdate(node) {
1037
- var _a, _b, _c, _d;
1038
- var snapshot = (_b = (_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) !== null && _b !== void 0 ? _b : node.snapshot;
1039
- if (node.isLead() &&
1040
- node.layout &&
1041
- snapshot &&
1042
- node.hasListeners("didUpdate")) {
1043
- var _e = node.layout, layout_1 = _e.actual, measuredLayout = _e.measured;
1044
- // TODO Maybe we want to also resize the layout snapshot so we don't trigger
1045
- // animations for instance if layout="size" and an element has only changed position
1046
- if (node.options.animationType === "size") {
1047
- eachAxis(function (axis) {
1048
- var axisSnapshot = snapshot.isShared
1049
- ? snapshot.measured[axis]
1050
- : snapshot.layout[axis];
1051
- var length = calcLength(axisSnapshot);
1052
- axisSnapshot.min = layout_1[axis].min;
1053
- axisSnapshot.max = axisSnapshot.min + length;
1054
- });
1055
- }
1056
- else if (node.options.animationType === "position") {
1057
- eachAxis(function (axis) {
1058
- var axisSnapshot = snapshot.isShared
1059
- ? snapshot.measured[axis]
1060
- : snapshot.layout[axis];
1061
- var length = calcLength(layout_1[axis]);
1062
- axisSnapshot.max = axisSnapshot.min + length;
1063
- });
1064
- }
1065
- var layoutDelta = createDelta();
1066
- calcBoxDelta(layoutDelta, layout_1, snapshot.layout);
1067
- var visualDelta = createDelta();
1068
- if (snapshot.isShared) {
1069
- calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measured);
1070
- }
1071
- else {
1072
- calcBoxDelta(visualDelta, layout_1, snapshot.layout);
1073
- }
1074
- var hasLayoutChanged = !isDeltaZero(layoutDelta);
1075
- var hasRelativeTargetChanged = false;
1076
- if (!node.resumeFrom) {
1077
- node.relativeParent = node.getClosestProjectingParent();
1078
- /**
1079
- * If the relativeParent is itself resuming from a different element then
1080
- * the relative snapshot is not relavent
1081
- */
1082
- if (node.relativeParent && !node.relativeParent.resumeFrom) {
1083
- var _f = node.relativeParent, parentSnapshot = _f.snapshot, parentLayout = _f.layout;
1084
- if (parentSnapshot && parentLayout) {
1085
- var relativeSnapshot = createBox();
1086
- calcRelativePosition(relativeSnapshot, snapshot.layout, parentSnapshot.layout);
1087
- var relativeLayout = createBox();
1088
- calcRelativePosition(relativeLayout, layout_1, parentLayout.actual);
1089
- if (!boxEquals(relativeSnapshot, relativeLayout)) {
1090
- hasRelativeTargetChanged = true;
1091
- }
1092
- }
1093
- }
1094
- }
1095
- node.notifyListeners("didUpdate", {
1096
- layout: layout_1,
1097
- snapshot: snapshot,
1098
- delta: visualDelta,
1099
- layoutDelta: layoutDelta,
1100
- hasLayoutChanged: hasLayoutChanged,
1101
- hasRelativeTargetChanged: hasRelativeTargetChanged,
1102
- });
1103
- }
1104
- else if (node.isLead()) {
1105
- (_d = (_c = node.options).onExitComplete) === null || _d === void 0 ? void 0 : _d.call(_c);
1106
- }
1107
- /**
1108
- * Clearing transition
1109
- * TODO: Investigate why this transition is being passed in as {type: false } from Framer
1110
- * and why we need it at all
1111
- */
1112
- node.options.transition = undefined;
1113
- }
1114
- function clearSnapshot(node) {
1115
- node.clearSnapshot();
1116
- }
1117
- function clearMeasurements(node) {
1118
- node.clearMeasurements();
1119
- }
1120
- function resetTransformStyle(node) {
1121
- node.resetTransform();
1122
- }
1123
- function finishAnimation(node) {
1124
- node.finishAnimation();
1125
- node.targetDelta = node.relativeTarget = node.target = undefined;
1126
- }
1127
- function resolveTargetDelta(node) {
1128
- node.resolveTargetDelta();
1129
- }
1130
- function calcProjection(node) {
1131
- node.calcProjection();
1132
- }
1133
- function resetRotation(node) {
1134
- node.resetRotation();
1135
- }
1136
- function removeLeadSnapshots(stack) {
1137
- stack.removeLeadSnapshot();
1138
- }
1139
- function mixAxisDelta(output, delta, p) {
1140
- output.translate = mix(delta.translate, 0, p);
1141
- output.scale = mix(delta.scale, 1, p);
1142
- output.origin = delta.origin;
1143
- output.originPoint = delta.originPoint;
1144
- }
1145
- function mixAxis(output, from, to, p) {
1146
- output.min = mix(from.min, to.min, p);
1147
- output.max = mix(from.max, to.max, p);
1148
- }
1149
- function mixBox(output, from, to, p) {
1150
- mixAxis(output.x, from.x, to.x, p);
1151
- mixAxis(output.y, from.y, to.y, p);
1152
- }
1153
- function hasOpacityCrossfade(node) {
1154
- return (node.animationValues && node.animationValues.opacityExit !== undefined);
1155
- }
1156
- var defaultLayoutTransition = {
1157
- duration: 0.45,
1158
- ease: [0.4, 0, 0.1, 1],
1159
- };
1160
- function mountNodeEarly(node, id) {
1161
- /**
1162
- * Rather than searching the DOM from document we can search the
1163
- * path for the deepest mounted ancestor and search from there
1164
- */
1165
- var searchNode = node.root;
1166
- for (var i = node.path.length - 1; i >= 0; i--) {
1167
- if (Boolean(node.path[i].instance)) {
1168
- searchNode = node.path[i];
1169
- break;
1170
- }
1171
- }
1172
- var searchElement = searchNode && searchNode !== node.root ? searchNode.instance : document;
1173
- var element = searchElement.querySelector("[data-projection-id=\"" + id + "\"]");
1174
- if (element)
1175
- node.mount(element, true);
1176
- }
1177
- function roundAxis(axis) {
1178
- axis.min = Math.round(axis.min);
1179
- axis.max = Math.round(axis.max);
1180
- }
1181
- function roundBox(box) {
1182
- roundAxis(box.x);
1183
- roundAxis(box.y);
1184
- }
1185
22
 
1186
- export { createProjectionNode, globalProjectionState, mixAxis, mixAxisDelta, mixBox };
23
+ export { globalProjectionState };