motion-dom 12.40.0 → 12.41.0
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 +1023 -458
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +0 -3
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/waapi/start-waapi-animation.mjs +1 -12
- package/dist/es/animation/waapi/start-waapi-animation.mjs.map +1 -1
- package/dist/es/events/add-dom-event.mjs +1 -1
- package/dist/es/events/add-dom-event.mjs.map +1 -1
- package/dist/es/frameloop/batcher.mjs +1 -1
- package/dist/es/frameloop/batcher.mjs.map +1 -1
- package/dist/es/frameloop/render-step.mjs +1 -12
- package/dist/es/frameloop/render-step.mjs.map +1 -1
- package/dist/es/gestures/press/index.mjs +11 -4
- package/dist/es/gestures/press/index.mjs.map +1 -1
- package/dist/es/index.mjs +0 -1
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +299 -214
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +0 -6
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/stats/buffer.mjs.map +1 -1
- package/dist/es/stats/index.mjs +4 -93
- package/dist/es/stats/index.mjs.map +1 -1
- package/dist/es/view/index.mjs +90 -13
- package/dist/es/view/index.mjs.map +1 -1
- package/dist/es/view/queue.mjs +9 -3
- package/dist/es/view/queue.mjs.map +1 -1
- package/dist/es/view/start.mjs +484 -83
- package/dist/es/view/start.mjs.map +1 -1
- package/dist/es/view/utils/assign-names.mjs +118 -0
- package/dist/es/view/utils/assign-names.mjs.map +1 -0
- package/dist/es/view/utils/choose-layer-type.mjs +1 -3
- package/dist/es/view/utils/choose-layer-type.mjs.map +1 -1
- package/dist/es/view/utils/get-layer-info.mjs +3 -1
- package/dist/es/view/utils/get-layer-info.mjs.map +1 -1
- package/dist/es/view/utils/get-view-animations.mjs +6 -8
- package/dist/es/view/utils/get-view-animations.mjs.map +1 -1
- package/dist/index.d.ts +105 -52
- package/dist/motion-dom.dev.js +1023 -458
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
- package/dist/es/stats/animation-count.mjs +0 -8
- package/dist/es/stats/animation-count.mjs.map +0 -1
|
@@ -1,45 +1,229 @@
|
|
|
1
|
+
import { clamp } from 'motion-utils';
|
|
1
2
|
import { GroupAnimation } from '../animation/GroupAnimation.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { microtask } from '../frameloop/microtask.mjs';
|
|
4
|
+
import { time } from '../frameloop/sync-time.mjs';
|
|
4
5
|
import { HTMLProjectionNode } from '../projection/node/HTMLProjectionNode.mjs';
|
|
5
6
|
import { HTMLVisualElement } from '../render/html/HTMLVisualElement.mjs';
|
|
6
7
|
import { visualElementStore } from '../render/store.mjs';
|
|
8
|
+
import { hasTransform } from '../projection/utils/has-transform.mjs';
|
|
7
9
|
import { resolveElements } from '../utils/resolve-elements.mjs';
|
|
8
|
-
import {
|
|
10
|
+
import { frameData, frameSteps } from '../frameloop/frame.mjs';
|
|
9
11
|
|
|
10
|
-
const layoutSelector = "[data-layout],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const layoutSelector = "[data-layout],[data-layout-id]";
|
|
13
|
+
/**
|
|
14
|
+
* All imperatively-created projection nodes live in one persistent tree,
|
|
15
|
+
* shared across animateLayout() calls (and with any React-created nodes,
|
|
16
|
+
* via the singleton document root). Keyed by element for reuse.
|
|
17
|
+
*/
|
|
18
|
+
const layoutNodes = new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
* Builders created within the same synchronous tick are flushed together
|
|
21
|
+
* as a single "commit": every node is snapshotted before any updateDom
|
|
22
|
+
* runs, mirroring React batching renders from different parts of the tree.
|
|
23
|
+
*/
|
|
24
|
+
let pendingBuilders;
|
|
25
|
+
function collectLayoutElements(scope) {
|
|
26
|
+
const elements = [];
|
|
27
|
+
if (scope instanceof HTMLElement && scope.matches(layoutSelector)) {
|
|
28
|
+
elements.push(scope);
|
|
29
|
+
}
|
|
30
|
+
scope.querySelectorAll(layoutSelector).forEach((element) => {
|
|
31
|
+
if (element instanceof HTMLElement)
|
|
32
|
+
elements.push(element);
|
|
33
|
+
});
|
|
34
|
+
return elements;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Process any work scheduled on the frameloop now. A previous animation
|
|
38
|
+
* may have been seeked while paused (controls.time = x) without a frame
|
|
39
|
+
* having rendered it - we must materialise that state into the DOM
|
|
40
|
+
* before taking snapshots.
|
|
41
|
+
*/
|
|
42
|
+
function flushPendingFrame() {
|
|
43
|
+
if (frameData.isProcessing)
|
|
44
|
+
return;
|
|
45
|
+
const now = time.now();
|
|
46
|
+
frameData.delta = clamp(0, 1000 / 60, now - frameData.timestamp);
|
|
47
|
+
frameData.timestamp = now;
|
|
48
|
+
frameData.isProcessing = true;
|
|
49
|
+
frameSteps.update.process(frameData);
|
|
50
|
+
frameSteps.preRender.process(frameData);
|
|
51
|
+
frameSteps.render.process(frameData);
|
|
52
|
+
frameData.isProcessing = false;
|
|
53
|
+
}
|
|
54
|
+
function getProjectionParent(element) {
|
|
55
|
+
let ancestor = element.parentElement;
|
|
56
|
+
while (ancestor) {
|
|
57
|
+
const node = layoutNodes.get(ancestor);
|
|
58
|
+
if (node && node.instance)
|
|
59
|
+
return node;
|
|
60
|
+
ancestor = ancestor.parentElement;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
function createVisualElement() {
|
|
65
|
+
return new HTMLVisualElement({
|
|
66
|
+
props: {},
|
|
67
|
+
presenceContext: null,
|
|
68
|
+
visualState: {
|
|
69
|
+
latestValues: {},
|
|
70
|
+
renderState: {
|
|
71
|
+
transform: {},
|
|
72
|
+
transformOrigin: {},
|
|
73
|
+
style: {},
|
|
74
|
+
vars: {},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
}, { allowProjection: true });
|
|
78
|
+
}
|
|
79
|
+
function readNodeOptions(element, transition) {
|
|
80
|
+
const layoutAttr = element.getAttribute("data-layout");
|
|
81
|
+
const layoutId = element.getAttribute("data-layout-id") ?? undefined;
|
|
20
82
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
83
|
+
layoutId,
|
|
84
|
+
layout: layoutAttr !== null ? true : undefined,
|
|
85
|
+
animationType: (!layoutAttr || layoutAttr === "true"
|
|
86
|
+
? "both"
|
|
87
|
+
: layoutAttr),
|
|
88
|
+
transition,
|
|
26
89
|
};
|
|
27
90
|
}
|
|
91
|
+
function prepareNode(element, transition) {
|
|
92
|
+
let node = layoutNodes.get(element);
|
|
93
|
+
if (!node) {
|
|
94
|
+
let visualElement = visualElementStore.get(element);
|
|
95
|
+
if (!visualElement)
|
|
96
|
+
visualElement = createVisualElement();
|
|
97
|
+
/**
|
|
98
|
+
* A first-time element may carry a projection transform in its
|
|
99
|
+
* inline style (e.g. it was cloned from an element mid-animation).
|
|
100
|
+
* That transform isn't tracked in latestValues so the engine can't
|
|
101
|
+
* reset it before measuring - clear it now so the first layout
|
|
102
|
+
* measurement isn't inflated.
|
|
103
|
+
*/
|
|
104
|
+
if (element.style.transform &&
|
|
105
|
+
!hasTransform(visualElement.latestValues)) {
|
|
106
|
+
element.style.transform = "";
|
|
107
|
+
}
|
|
108
|
+
node = new HTMLProjectionNode(visualElement.latestValues, getProjectionParent(element));
|
|
109
|
+
visualElement.projection = node;
|
|
110
|
+
node.setOptions({
|
|
111
|
+
...readNodeOptions(element, transition),
|
|
112
|
+
visualElement,
|
|
113
|
+
});
|
|
114
|
+
node.mount(element);
|
|
115
|
+
layoutNodes.set(element, node);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
node.setOptions(readNodeOptions(element, transition));
|
|
119
|
+
}
|
|
120
|
+
node.isPresent = true;
|
|
121
|
+
if (node.options.onExitComplete) {
|
|
122
|
+
node.setOptions({ onExitComplete: undefined });
|
|
123
|
+
}
|
|
124
|
+
return node;
|
|
125
|
+
}
|
|
126
|
+
function sortDocumentOrder(elements) {
|
|
127
|
+
return [...elements].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
128
|
+
}
|
|
129
|
+
function dropNode(element, node) {
|
|
130
|
+
node.setOptions({ onExitComplete: undefined });
|
|
131
|
+
/**
|
|
132
|
+
* Stop any lingering animation so it can't leak into future updates.
|
|
133
|
+
* A follow node can share its currentAnimation with a surviving lead
|
|
134
|
+
* (via resumingFrom), in which case it isn't ours to stop.
|
|
135
|
+
*/
|
|
136
|
+
const stack = node.getStack();
|
|
137
|
+
if (!stack || node.isLead())
|
|
138
|
+
node.currentAnimation?.stop();
|
|
139
|
+
node.unmount();
|
|
140
|
+
layoutNodes.delete(element);
|
|
141
|
+
}
|
|
142
|
+
function flushPendingBuilders() {
|
|
143
|
+
const builders = pendingBuilders;
|
|
144
|
+
pendingBuilders = undefined;
|
|
145
|
+
flushPendingFrame();
|
|
146
|
+
/**
|
|
147
|
+
* Discover and mount every node across all builders before snapshotting
|
|
148
|
+
* any of them. Mounting during an active update flags isLayoutDirty,
|
|
149
|
+
* which would make that node's own willUpdate skip its snapshot.
|
|
150
|
+
* Document order guarantees ancestors mount before descendants, even
|
|
151
|
+
* when they're discovered by different builders.
|
|
152
|
+
*/
|
|
153
|
+
const targets = new Map();
|
|
154
|
+
for (const builder of builders) {
|
|
155
|
+
for (const element of builder.collectTargets()) {
|
|
156
|
+
const owners = targets.get(element);
|
|
157
|
+
owners ? owners.push(builder) : targets.set(element, [builder]);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const union = new Map();
|
|
161
|
+
for (const element of sortDocumentOrder(targets.keys())) {
|
|
162
|
+
const owners = targets.get(element);
|
|
163
|
+
const node = prepareNode(element, owners[owners.length - 1].transitionFor(element));
|
|
164
|
+
for (const owner of owners)
|
|
165
|
+
owner.adopt(element, node);
|
|
166
|
+
union.set(element, node);
|
|
167
|
+
}
|
|
168
|
+
union.forEach((node) => {
|
|
169
|
+
node.isLayoutDirty = false;
|
|
170
|
+
node.willUpdate();
|
|
171
|
+
});
|
|
172
|
+
const updatePromises = [];
|
|
173
|
+
for (const builder of builders) {
|
|
174
|
+
const result = builder.runUpdate();
|
|
175
|
+
if (result)
|
|
176
|
+
updatePromises.push(result);
|
|
177
|
+
}
|
|
178
|
+
const commit = () => {
|
|
179
|
+
/**
|
|
180
|
+
* Process all additions before any removals so that, even across
|
|
181
|
+
* builders, a removed member knows whether a replacement with the
|
|
182
|
+
* same layoutId was added in this commit.
|
|
183
|
+
*/
|
|
184
|
+
const newMemberIds = new Set();
|
|
185
|
+
for (const builder of builders) {
|
|
186
|
+
builder.reconcileAdditions(newMemberIds);
|
|
187
|
+
}
|
|
188
|
+
for (const builder of builders) {
|
|
189
|
+
builder.reconcileRemovals(newMemberIds);
|
|
190
|
+
}
|
|
191
|
+
let root;
|
|
192
|
+
union.forEach((node) => (root || (root = node.root)));
|
|
193
|
+
for (const builder of builders)
|
|
194
|
+
root || (root = builder.getRoot());
|
|
195
|
+
root?.didUpdate();
|
|
196
|
+
/**
|
|
197
|
+
* The root flushes the update on a microtask, synchronously
|
|
198
|
+
* processing the frame that creates the layout animations. Collect
|
|
199
|
+
* them in a later microtask step of the same pass.
|
|
200
|
+
*/
|
|
201
|
+
microtask.render(() => {
|
|
202
|
+
for (const builder of builders)
|
|
203
|
+
builder.finalize();
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
updatePromises.length ? Promise.all(updatePromises).then(commit) : commit();
|
|
207
|
+
}
|
|
28
208
|
class LayoutAnimationBuilder {
|
|
29
209
|
constructor(scope, updateDom, defaultOptions) {
|
|
30
|
-
this.sharedTransitions = new Map();
|
|
31
|
-
this.notifyReady = noop;
|
|
32
|
-
this.rejectReady = noop;
|
|
33
210
|
this.scope = scope;
|
|
34
211
|
this.updateDom = updateDom;
|
|
35
212
|
this.defaultOptions = defaultOptions;
|
|
213
|
+
this.sharedTransitions = new Map();
|
|
214
|
+
this.notifyReady = () => { };
|
|
215
|
+
this.rejectReady = () => { };
|
|
216
|
+
this.tracked = new Map();
|
|
217
|
+
this.restorePoints = new Map();
|
|
36
218
|
this.readyPromise = new Promise((resolve, reject) => {
|
|
37
219
|
this.notifyReady = resolve;
|
|
38
220
|
this.rejectReady = reject;
|
|
39
221
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
222
|
+
if (!pendingBuilders) {
|
|
223
|
+
pendingBuilders = [];
|
|
224
|
+
queueMicrotask(flushPendingBuilders);
|
|
225
|
+
}
|
|
226
|
+
pendingBuilders.push(this);
|
|
43
227
|
}
|
|
44
228
|
shared(id, transition) {
|
|
45
229
|
this.sharedTransitions.set(id, transition);
|
|
@@ -48,114 +232,107 @@ class LayoutAnimationBuilder {
|
|
|
48
232
|
then(resolve, reject) {
|
|
49
233
|
return this.readyPromise.then(resolve, reject);
|
|
50
234
|
}
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
else if (projection.snapshot) {
|
|
63
|
-
projection.snapshot = undefined;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else if (projection.snapshot &&
|
|
67
|
-
(projection.currentAnimation || projection.isProjecting())) {
|
|
68
|
-
projection.snapshot = undefined;
|
|
69
|
-
}
|
|
70
|
-
projection.isPresent = true;
|
|
71
|
-
projection.willUpdate();
|
|
235
|
+
transitionFor(element) {
|
|
236
|
+
const layoutId = element.getAttribute("data-layout-id");
|
|
237
|
+
return ((layoutId && this.sharedTransitions.get(layoutId)) ||
|
|
238
|
+
this.defaultOptions);
|
|
239
|
+
}
|
|
240
|
+
adopt(element, node) {
|
|
241
|
+
this.tracked.set(element, node);
|
|
242
|
+
this.restorePoints.set(element, {
|
|
243
|
+
parent: element.parentElement,
|
|
244
|
+
next: element.nextSibling,
|
|
72
245
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return;
|
|
85
|
-
const currentTransform = instance.style.transform;
|
|
86
|
-
const resumeFromTransform = resumeFromInstance.style.transform;
|
|
87
|
-
if (currentTransform &&
|
|
88
|
-
resumeFromTransform &&
|
|
89
|
-
currentTransform === resumeFromTransform) {
|
|
90
|
-
instance.style.transform = "";
|
|
91
|
-
instance.style.transformOrigin = "";
|
|
246
|
+
}
|
|
247
|
+
collectTargets() {
|
|
248
|
+
return collectLayoutElements(this.scope);
|
|
249
|
+
}
|
|
250
|
+
runUpdate() {
|
|
251
|
+
try {
|
|
252
|
+
const result = this.updateDom();
|
|
253
|
+
if (result && typeof result.then === "function") {
|
|
254
|
+
return result.then(undefined, (error) => {
|
|
255
|
+
this.updateError = error;
|
|
256
|
+
});
|
|
92
257
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
root?.didUpdate();
|
|
99
|
-
await new Promise((resolve) => {
|
|
100
|
-
frame.postRender(() => resolve());
|
|
101
|
-
});
|
|
102
|
-
const animations = collectAnimations(afterRecords);
|
|
103
|
-
const animation = new GroupAnimation(animations);
|
|
104
|
-
return animation;
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
this.updateError = error;
|
|
261
|
+
}
|
|
262
|
+
return undefined;
|
|
105
263
|
}
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
? this.sharedTransitions.get(layoutId)
|
|
114
|
-
: undefined;
|
|
115
|
-
const transition = override || this.defaultOptions;
|
|
116
|
-
const record = getOrCreateRecord(element, parentRecord?.projection, {
|
|
117
|
-
layout,
|
|
118
|
-
layoutId,
|
|
119
|
-
animationType: typeof layout === "string" ? layout : "both",
|
|
120
|
-
transition: transition,
|
|
121
|
-
});
|
|
122
|
-
recordMap.set(element, record);
|
|
123
|
-
records.push(record);
|
|
264
|
+
reconcileAdditions(newMemberIds) {
|
|
265
|
+
for (const element of collectLayoutElements(this.scope)) {
|
|
266
|
+
if (this.tracked.has(element))
|
|
267
|
+
continue;
|
|
268
|
+
const node = prepareNode(element, this.transitionFor(element));
|
|
269
|
+
this.adopt(element, node);
|
|
270
|
+
node.options.layoutId && newMemberIds.add(node.options.layoutId);
|
|
124
271
|
}
|
|
125
|
-
return records;
|
|
126
272
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (afterElementsSet.has(record.element))
|
|
273
|
+
reconcileRemovals(newMemberIds) {
|
|
274
|
+
this.tracked.forEach((node, element) => {
|
|
275
|
+
if (element.isConnected)
|
|
131
276
|
return;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
277
|
+
const restore = this.restorePoints.get(element);
|
|
278
|
+
this.restorePoints.delete(element);
|
|
279
|
+
const { layoutId } = node.options;
|
|
280
|
+
const stack = node.getStack();
|
|
281
|
+
const hasSurvivor = stack &&
|
|
282
|
+
stack.members.some((member) => member !== node &&
|
|
283
|
+
member.instance
|
|
284
|
+
?.isConnected);
|
|
285
|
+
/**
|
|
286
|
+
* A removed lead with a surviving stack member - and no
|
|
287
|
+
* replacement member added this commit - runs an exit
|
|
288
|
+
* crossfade: restore the element to its old position in the
|
|
289
|
+
* DOM, relegate it and let the survivor take over. It's
|
|
290
|
+
* removed again once the animation completes.
|
|
291
|
+
*/
|
|
292
|
+
if (layoutId &&
|
|
293
|
+
node.isLead() &&
|
|
294
|
+
hasSurvivor &&
|
|
295
|
+
!newMemberIds.has(layoutId)) {
|
|
296
|
+
if (restore && restore.parent.isConnected) {
|
|
297
|
+
restore.parent.insertBefore(element, restore.next && restore.next.parentNode === restore.parent
|
|
298
|
+
? restore.next
|
|
299
|
+
: null);
|
|
300
|
+
node.isPresent = false;
|
|
301
|
+
node.setOptions({
|
|
302
|
+
onExitComplete: () => {
|
|
303
|
+
element.remove();
|
|
304
|
+
dropNode(element, node);
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
if (node.relegate())
|
|
308
|
+
return;
|
|
309
|
+
element.remove();
|
|
310
|
+
}
|
|
137
311
|
}
|
|
138
|
-
|
|
139
|
-
|
|
312
|
+
dropNode(element, node);
|
|
313
|
+
this.tracked.delete(element);
|
|
140
314
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
315
|
+
}
|
|
316
|
+
getRoot() {
|
|
317
|
+
let root;
|
|
318
|
+
this.tracked.forEach((node) => (root || (root = node.root)));
|
|
319
|
+
return root;
|
|
320
|
+
}
|
|
321
|
+
finalize() {
|
|
322
|
+
if (this.updateError) {
|
|
323
|
+
this.rejectReady(this.updateError);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const animations = new Set();
|
|
327
|
+
this.tracked.forEach((node) => {
|
|
328
|
+
if (node.instance && node.currentAnimation) {
|
|
329
|
+
animations.add(node.currentAnimation);
|
|
153
330
|
}
|
|
154
331
|
});
|
|
332
|
+
this.notifyReady(new GroupAnimation([...animations]));
|
|
155
333
|
}
|
|
156
334
|
}
|
|
157
335
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
158
|
-
// animateLayout(updateDom)
|
|
159
336
|
if (typeof scopeOrUpdateDom === "function") {
|
|
160
337
|
return {
|
|
161
338
|
scope: document,
|
|
@@ -163,107 +340,15 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
|
163
340
|
defaultOptions: updateDomOrOptions,
|
|
164
341
|
};
|
|
165
342
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
343
|
+
const scope = scopeOrUpdateDom instanceof Document
|
|
344
|
+
? scopeOrUpdateDom
|
|
345
|
+
: resolveElements(scopeOrUpdateDom)[0] ?? document;
|
|
169
346
|
return {
|
|
170
347
|
scope,
|
|
171
348
|
updateDom: updateDomOrOptions,
|
|
172
349
|
defaultOptions: options,
|
|
173
350
|
};
|
|
174
351
|
}
|
|
175
|
-
function collectLayoutElements(scope) {
|
|
176
|
-
const elements = Array.from(scope.querySelectorAll(layoutSelector));
|
|
177
|
-
if (scope instanceof Element && scope.matches(layoutSelector)) {
|
|
178
|
-
if (!elements.includes(scope)) {
|
|
179
|
-
elements.unshift(scope);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return elements;
|
|
183
|
-
}
|
|
184
|
-
function readLayoutAttributes(element) {
|
|
185
|
-
const layoutId = element.getAttribute("data-layout-id") || undefined;
|
|
186
|
-
const rawLayout = element.getAttribute("data-layout");
|
|
187
|
-
let layout;
|
|
188
|
-
if (rawLayout === "" || rawLayout === "true") {
|
|
189
|
-
layout = true;
|
|
190
|
-
}
|
|
191
|
-
else if (rawLayout) {
|
|
192
|
-
layout = rawLayout;
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
layout,
|
|
196
|
-
layoutId,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function createVisualState() {
|
|
200
|
-
return {
|
|
201
|
-
latestValues: {},
|
|
202
|
-
renderState: {
|
|
203
|
-
transform: {},
|
|
204
|
-
transformOrigin: {},
|
|
205
|
-
style: {},
|
|
206
|
-
vars: {},
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function getOrCreateRecord(element, parentProjection, projectionOptions) {
|
|
211
|
-
const existing = visualElementStore.get(element);
|
|
212
|
-
const visualElement = existing ??
|
|
213
|
-
new HTMLVisualElement({
|
|
214
|
-
props: {},
|
|
215
|
-
presenceContext: null,
|
|
216
|
-
visualState: createVisualState(),
|
|
217
|
-
}, { allowProjection: true });
|
|
218
|
-
if (!existing || !visualElement.projection) {
|
|
219
|
-
visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
|
|
220
|
-
}
|
|
221
|
-
visualElement.projection.setOptions({
|
|
222
|
-
...projectionOptions,
|
|
223
|
-
visualElement,
|
|
224
|
-
});
|
|
225
|
-
if (!visualElement.current) {
|
|
226
|
-
visualElement.mount(element);
|
|
227
|
-
}
|
|
228
|
-
else if (!visualElement.projection.instance) {
|
|
229
|
-
// Mount projection if VisualElement is already mounted but projection isn't
|
|
230
|
-
// This happens when animate() was called before animateLayout()
|
|
231
|
-
visualElement.projection.mount(element);
|
|
232
|
-
}
|
|
233
|
-
if (!existing) {
|
|
234
|
-
visualElementStore.set(element, visualElement);
|
|
235
|
-
}
|
|
236
|
-
return {
|
|
237
|
-
element,
|
|
238
|
-
visualElement,
|
|
239
|
-
projection: visualElement.projection,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function findParentRecord(element, recordMap, scope) {
|
|
243
|
-
let parent = element.parentElement;
|
|
244
|
-
while (parent) {
|
|
245
|
-
const record = recordMap.get(parent);
|
|
246
|
-
if (record)
|
|
247
|
-
return record;
|
|
248
|
-
if (parent === scope)
|
|
249
|
-
break;
|
|
250
|
-
parent = parent.parentElement;
|
|
251
|
-
}
|
|
252
|
-
return undefined;
|
|
253
|
-
}
|
|
254
|
-
function getProjectionRoot(afterRecords, beforeRecords) {
|
|
255
|
-
const record = afterRecords[0] || beforeRecords[0];
|
|
256
|
-
return record?.projection.root;
|
|
257
|
-
}
|
|
258
|
-
function collectAnimations(afterRecords) {
|
|
259
|
-
const animations = new Set();
|
|
260
|
-
afterRecords.forEach((record) => {
|
|
261
|
-
const animation = record.projection.currentAnimation;
|
|
262
|
-
if (animation)
|
|
263
|
-
animations.add(animation);
|
|
264
|
-
});
|
|
265
|
-
return Array.from(animations);
|
|
266
|
-
}
|
|
267
352
|
|
|
268
353
|
export { LayoutAnimationBuilder, parseAnimateLayoutArgs };
|
|
269
354
|
//# sourceMappingURL=LayoutAnimationBuilder.mjs.map
|