motion-dom 12.29.0 → 12.29.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 +221 -294
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +3 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +220 -84
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +16 -16
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/index.d.ts +22 -11
- package/dist/motion-dom.dev.js +221 -294
- package/dist/motion-dom.js +1 -1
- package/package.json +3 -3
- package/dist/es/layout/get-layout-elements.mjs +0 -19
- package/dist/es/layout/get-layout-elements.mjs.map +0 -1
- package/dist/es/layout/projection-tree.mjs +0 -202
- package/dist/es/layout/projection-tree.mjs.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -3309,6 +3309,7 @@ function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
|
|
|
3309
3309
|
}
|
|
3310
3310
|
function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
|
|
3311
3311
|
let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
|
|
3312
|
+
const reduceMotion = transition?.reduceMotion;
|
|
3312
3313
|
if (transitionOverride)
|
|
3313
3314
|
transition = transitionOverride;
|
|
3314
3315
|
const animations = [];
|
|
@@ -3354,7 +3355,8 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
3354
3355
|
}
|
|
3355
3356
|
}
|
|
3356
3357
|
addValueToWillChange(visualElement, key);
|
|
3357
|
-
|
|
3358
|
+
const shouldReduceMotion = reduceMotion ?? visualElement.shouldReduceMotion;
|
|
3359
|
+
value.start(animateMotionValue(key, value, valueTarget, shouldReduceMotion && positionalKeys.has(key)
|
|
3358
3360
|
? { type: false }
|
|
3359
3361
|
: valueTransition, visualElement, isHandoff));
|
|
3360
3362
|
const animation = value.animation;
|
|
@@ -7455,7 +7457,7 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7455
7457
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7456
7458
|
}
|
|
7457
7459
|
}
|
|
7458
|
-
function createProjectionNode
|
|
7460
|
+
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7459
7461
|
return class ProjectionNode {
|
|
7460
7462
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7461
7463
|
/**
|
|
@@ -9012,7 +9014,7 @@ function checkNodeWasScrollRoot(node) {
|
|
|
9012
9014
|
return node !== node.root && node.scroll?.wasRoot;
|
|
9013
9015
|
}
|
|
9014
9016
|
|
|
9015
|
-
const DocumentProjectionNode = createProjectionNode
|
|
9017
|
+
const DocumentProjectionNode = createProjectionNode({
|
|
9016
9018
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
9017
9019
|
measureScroll: () => ({
|
|
9018
9020
|
x: document.documentElement.scrollLeft || document.body?.scrollLeft || 0,
|
|
@@ -9047,7 +9049,7 @@ function nodeGroup() {
|
|
|
9047
9049
|
const rootProjectionNode = {
|
|
9048
9050
|
current: undefined,
|
|
9049
9051
|
};
|
|
9050
|
-
const HTMLProjectionNode = createProjectionNode
|
|
9052
|
+
const HTMLProjectionNode = createProjectionNode({
|
|
9051
9053
|
measureScroll: (instance) => ({
|
|
9052
9054
|
x: instance.scrollLeft,
|
|
9053
9055
|
y: instance.scrollTop,
|
|
@@ -9067,315 +9069,153 @@ const HTMLProjectionNode = createProjectionNode$1({
|
|
|
9067
9069
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
9068
9070
|
});
|
|
9069
9071
|
|
|
9070
|
-
const
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
if (
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
return element.getAttribute("data-layout-id");
|
|
9081
|
-
}
|
|
9082
|
-
function hasLayout(element) {
|
|
9083
|
-
return (element.hasAttribute("data-layout") ||
|
|
9084
|
-
element.hasAttribute("data-layout-id"));
|
|
9085
|
-
}
|
|
9086
|
-
|
|
9087
|
-
let scaleCorrectorAdded = false;
|
|
9088
|
-
/**
|
|
9089
|
-
* Track active projection nodes per element to handle animation interruption.
|
|
9090
|
-
* When a new animation starts on an element that already has an active animation,
|
|
9091
|
-
* we need to stop the old animation so the new one can start from the current
|
|
9092
|
-
* visual position.
|
|
9093
|
-
*/
|
|
9094
|
-
const activeProjectionNodes = new WeakMap();
|
|
9095
|
-
function ensureScaleCorrectors() {
|
|
9096
|
-
if (scaleCorrectorAdded)
|
|
9097
|
-
return;
|
|
9098
|
-
scaleCorrectorAdded = true;
|
|
9099
|
-
addScaleCorrector({
|
|
9100
|
-
borderRadius: {
|
|
9101
|
-
...correctBorderRadius,
|
|
9102
|
-
applyTo: [
|
|
9103
|
-
"borderTopLeftRadius",
|
|
9104
|
-
"borderTopRightRadius",
|
|
9105
|
-
"borderBottomLeftRadius",
|
|
9106
|
-
"borderBottomRightRadius",
|
|
9107
|
-
],
|
|
9108
|
-
},
|
|
9109
|
-
borderTopLeftRadius: correctBorderRadius,
|
|
9110
|
-
borderTopRightRadius: correctBorderRadius,
|
|
9111
|
-
borderBottomLeftRadius: correctBorderRadius,
|
|
9112
|
-
borderBottomRightRadius: correctBorderRadius,
|
|
9113
|
-
boxShadow: correctBoxShadow,
|
|
9114
|
-
});
|
|
9115
|
-
}
|
|
9116
|
-
/**
|
|
9117
|
-
* Get DOM depth of an element
|
|
9118
|
-
*/
|
|
9119
|
-
function getDepth(element) {
|
|
9120
|
-
let depth = 0;
|
|
9121
|
-
let current = element.parentElement;
|
|
9122
|
-
while (current) {
|
|
9123
|
-
depth++;
|
|
9124
|
-
current = current.parentElement;
|
|
9125
|
-
}
|
|
9126
|
-
return depth;
|
|
9127
|
-
}
|
|
9128
|
-
/**
|
|
9129
|
-
* Find the closest projection parent for an element
|
|
9130
|
-
*/
|
|
9131
|
-
function findProjectionParent(element, nodeCache) {
|
|
9132
|
-
let parent = element.parentElement;
|
|
9133
|
-
while (parent) {
|
|
9134
|
-
const node = nodeCache.get(parent);
|
|
9135
|
-
if (node)
|
|
9136
|
-
return node;
|
|
9137
|
-
parent = parent.parentElement;
|
|
9138
|
-
}
|
|
9139
|
-
return undefined;
|
|
9140
|
-
}
|
|
9141
|
-
/**
|
|
9142
|
-
* Create or reuse a projection node for an element
|
|
9143
|
-
*/
|
|
9144
|
-
function createProjectionNode(element, parent, options, transition) {
|
|
9145
|
-
// Check for existing active node - reuse it to preserve animation state
|
|
9146
|
-
const existingNode = activeProjectionNodes.get(element);
|
|
9147
|
-
if (existingNode) {
|
|
9148
|
-
const visualElement = existingNode.options.visualElement;
|
|
9149
|
-
// Update transition options for the new animation
|
|
9150
|
-
const nodeTransition = transition
|
|
9151
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9152
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9153
|
-
existingNode.setOptions({
|
|
9154
|
-
...existingNode.options,
|
|
9155
|
-
animate: true,
|
|
9156
|
-
transition: nodeTransition,
|
|
9157
|
-
...options,
|
|
9158
|
-
});
|
|
9159
|
-
// Re-mount the node if it was previously unmounted
|
|
9160
|
-
// This re-adds it to root.nodes so didUpdate() will process it
|
|
9161
|
-
if (!existingNode.instance) {
|
|
9162
|
-
existingNode.mount(element);
|
|
9163
|
-
}
|
|
9164
|
-
return { node: existingNode, visualElement };
|
|
9165
|
-
}
|
|
9166
|
-
// No existing node - create a new one
|
|
9167
|
-
const latestValues = {};
|
|
9168
|
-
const visualElement = new HTMLVisualElement({
|
|
9169
|
-
visualState: {
|
|
9170
|
-
latestValues,
|
|
9171
|
-
renderState: {
|
|
9172
|
-
transformOrigin: {},
|
|
9173
|
-
transform: {},
|
|
9174
|
-
style: {},
|
|
9175
|
-
vars: {},
|
|
9176
|
-
},
|
|
9177
|
-
},
|
|
9178
|
-
presenceContext: null,
|
|
9179
|
-
props: {},
|
|
9180
|
-
});
|
|
9181
|
-
const node = new HTMLProjectionNode(latestValues, parent);
|
|
9182
|
-
// Convert AnimationOptions to transition format for the projection system
|
|
9183
|
-
const nodeTransition = transition
|
|
9184
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9185
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9186
|
-
node.setOptions({
|
|
9187
|
-
visualElement,
|
|
9188
|
-
layout: true,
|
|
9189
|
-
animate: true,
|
|
9190
|
-
transition: nodeTransition,
|
|
9191
|
-
...options,
|
|
9192
|
-
});
|
|
9193
|
-
node.mount(element);
|
|
9194
|
-
visualElement.projection = node;
|
|
9195
|
-
// Track this node as the active one for this element
|
|
9196
|
-
activeProjectionNodes.set(element, node);
|
|
9197
|
-
return { node, visualElement };
|
|
9198
|
-
}
|
|
9199
|
-
/**
|
|
9200
|
-
* Build a projection tree from a list of elements
|
|
9201
|
-
*/
|
|
9202
|
-
function buildProjectionTree(elements, existingContext, options) {
|
|
9203
|
-
ensureScaleCorrectors();
|
|
9204
|
-
const nodes = existingContext?.nodes ?? new Map();
|
|
9205
|
-
const visualElements = existingContext?.visualElements ?? new Map();
|
|
9206
|
-
const group = existingContext?.group ?? nodeGroup();
|
|
9207
|
-
const defaultTransition = options?.defaultTransition;
|
|
9208
|
-
const sharedTransitions = options?.sharedTransitions;
|
|
9209
|
-
// Sort elements by DOM depth (parents before children)
|
|
9210
|
-
const sorted = [...elements].sort((a, b) => getDepth(a) - getDepth(b));
|
|
9211
|
-
let root = existingContext?.root;
|
|
9212
|
-
for (const element of sorted) {
|
|
9213
|
-
// Skip if already has a node
|
|
9214
|
-
if (nodes.has(element))
|
|
9215
|
-
continue;
|
|
9216
|
-
const parent = findProjectionParent(element, nodes);
|
|
9217
|
-
const layoutId = getLayoutId(element);
|
|
9218
|
-
const layoutMode = element.getAttribute("data-layout");
|
|
9219
|
-
const nodeOptions = {
|
|
9220
|
-
layoutId: layoutId ?? undefined,
|
|
9221
|
-
animationType: parseLayoutMode(layoutMode),
|
|
9222
|
-
};
|
|
9223
|
-
// Use layoutId-specific transition if available, otherwise use default
|
|
9224
|
-
const transition = layoutId && sharedTransitions?.get(layoutId)
|
|
9225
|
-
? sharedTransitions.get(layoutId)
|
|
9226
|
-
: defaultTransition;
|
|
9227
|
-
const { node, visualElement } = createProjectionNode(element, parent, nodeOptions, transition);
|
|
9228
|
-
nodes.set(element, node);
|
|
9229
|
-
visualElements.set(element, visualElement);
|
|
9230
|
-
group.add(node);
|
|
9231
|
-
if (!root) {
|
|
9232
|
-
root = node.root;
|
|
9233
|
-
}
|
|
9234
|
-
}
|
|
9072
|
+
const layoutSelector = "[data-layout], [data-layout-id]";
|
|
9073
|
+
const noop = () => { };
|
|
9074
|
+
function snapshotFromTarget(projection) {
|
|
9075
|
+
const target = projection.targetWithTransforms || projection.target;
|
|
9076
|
+
if (!target)
|
|
9077
|
+
return undefined;
|
|
9078
|
+
const measuredBox = createBox();
|
|
9079
|
+
const layoutBox = createBox();
|
|
9080
|
+
copyBoxInto(measuredBox, target);
|
|
9081
|
+
copyBoxInto(layoutBox, target);
|
|
9235
9082
|
return {
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9083
|
+
animationId: projection.root?.animationId ?? 0,
|
|
9084
|
+
measuredBox,
|
|
9085
|
+
layoutBox,
|
|
9086
|
+
latestValues: projection.animationValues || projection.latestValues || {},
|
|
9087
|
+
source: projection.id,
|
|
9240
9088
|
};
|
|
9241
9089
|
}
|
|
9242
|
-
/**
|
|
9243
|
-
* Parse the data-layout attribute value
|
|
9244
|
-
*/
|
|
9245
|
-
function parseLayoutMode(value) {
|
|
9246
|
-
if (value === "position")
|
|
9247
|
-
return "position";
|
|
9248
|
-
if (value === "size")
|
|
9249
|
-
return "size";
|
|
9250
|
-
if (value === "preserve-aspect")
|
|
9251
|
-
return "preserve-aspect";
|
|
9252
|
-
return "both";
|
|
9253
|
-
}
|
|
9254
|
-
/**
|
|
9255
|
-
* Clean up projection nodes for specific elements.
|
|
9256
|
-
* If elementsToCleanup is provided, only those elements are cleaned up.
|
|
9257
|
-
* If not provided, all nodes are cleaned up.
|
|
9258
|
-
*
|
|
9259
|
-
* This allows persisting elements to keep their nodes between animations,
|
|
9260
|
-
* matching React's behavior where nodes persist for elements that remain in the DOM.
|
|
9261
|
-
*/
|
|
9262
|
-
function cleanupProjectionTree(context, elementsToCleanup) {
|
|
9263
|
-
const elementsToProcess = elementsToCleanup
|
|
9264
|
-
? [...context.nodes.entries()].filter(([el]) => elementsToCleanup.has(el))
|
|
9265
|
-
: [...context.nodes.entries()];
|
|
9266
|
-
for (const [element, node] of elementsToProcess) {
|
|
9267
|
-
context.group.remove(node);
|
|
9268
|
-
node.unmount();
|
|
9269
|
-
// Only clear from activeProjectionNodes if this is still the active node.
|
|
9270
|
-
// A newer animation might have already taken over.
|
|
9271
|
-
if (activeProjectionNodes.get(element) === node) {
|
|
9272
|
-
activeProjectionNodes.delete(element);
|
|
9273
|
-
}
|
|
9274
|
-
context.nodes.delete(element);
|
|
9275
|
-
context.visualElements.delete(element);
|
|
9276
|
-
}
|
|
9277
|
-
}
|
|
9278
|
-
|
|
9279
9090
|
class LayoutAnimationBuilder {
|
|
9280
9091
|
constructor(scope, updateDom, defaultOptions) {
|
|
9281
9092
|
this.sharedTransitions = new Map();
|
|
9282
|
-
this.notifyReady =
|
|
9283
|
-
this.
|
|
9093
|
+
this.notifyReady = noop;
|
|
9094
|
+
this.rejectReady = noop;
|
|
9284
9095
|
this.scope = scope;
|
|
9285
9096
|
this.updateDom = updateDom;
|
|
9286
9097
|
this.defaultOptions = defaultOptions;
|
|
9287
|
-
this.readyPromise = new Promise((resolve) => {
|
|
9098
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
9288
9099
|
this.notifyReady = resolve;
|
|
9100
|
+
this.rejectReady = reject;
|
|
9101
|
+
});
|
|
9102
|
+
frame.postRender(() => {
|
|
9103
|
+
this.start().then(this.notifyReady).catch(this.rejectReady);
|
|
9289
9104
|
});
|
|
9290
|
-
// Queue execution on microtask to allow builder methods to be called
|
|
9291
|
-
queueMicrotask(() => this.execute());
|
|
9292
9105
|
}
|
|
9293
|
-
shared(id,
|
|
9294
|
-
this.sharedTransitions.set(id,
|
|
9106
|
+
shared(id, transition) {
|
|
9107
|
+
this.sharedTransitions.set(id, transition);
|
|
9295
9108
|
return this;
|
|
9296
9109
|
}
|
|
9297
|
-
then(
|
|
9298
|
-
return this.readyPromise.then(
|
|
9110
|
+
then(resolve, reject) {
|
|
9111
|
+
return this.readyPromise.then(resolve, reject);
|
|
9299
9112
|
}
|
|
9300
|
-
async
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9307
|
-
|
|
9308
|
-
|
|
9309
|
-
|
|
9310
|
-
|
|
9311
|
-
|
|
9312
|
-
|
|
9313
|
-
}
|
|
9314
|
-
}
|
|
9315
|
-
// Phase 2: Execute DOM update
|
|
9316
|
-
this.updateDom();
|
|
9317
|
-
// Phase 3: Post-mutation - Compare before/after elements
|
|
9318
|
-
const afterElements = getLayoutElements(this.scope);
|
|
9319
|
-
const beforeSet = new Set(beforeElements);
|
|
9320
|
-
const afterSet = new Set(afterElements);
|
|
9321
|
-
const entering = afterElements.filter((el) => !beforeSet.has(el));
|
|
9322
|
-
const exiting = beforeElements.filter((el) => !afterSet.has(el));
|
|
9323
|
-
// Build projection nodes for entering elements
|
|
9324
|
-
if (entering.length > 0) {
|
|
9325
|
-
context = buildProjectionTree(entering, context, this.getBuildOptions());
|
|
9326
|
-
}
|
|
9327
|
-
// No layout elements - return empty animation
|
|
9328
|
-
if (!context) {
|
|
9329
|
-
this.notifyReady(new GroupAnimation([]));
|
|
9330
|
-
return;
|
|
9331
|
-
}
|
|
9332
|
-
// Handle shared elements
|
|
9333
|
-
for (const element of exiting) {
|
|
9334
|
-
const node = context.nodes.get(element);
|
|
9335
|
-
node?.getStack()?.remove(node);
|
|
9336
|
-
}
|
|
9337
|
-
for (const element of entering) {
|
|
9338
|
-
context.nodes.get(element)?.promote();
|
|
9339
|
-
}
|
|
9340
|
-
// Phase 4: Animate
|
|
9341
|
-
context.root.didUpdate();
|
|
9342
|
-
await new Promise((resolve) => frame.postRender(() => resolve()));
|
|
9343
|
-
const animations = [];
|
|
9344
|
-
for (const node of context.nodes.values()) {
|
|
9345
|
-
if (node.currentAnimation) {
|
|
9346
|
-
animations.push(node.currentAnimation);
|
|
9347
|
-
}
|
|
9348
|
-
}
|
|
9349
|
-
const groupAnimation = new GroupAnimation(animations);
|
|
9350
|
-
groupAnimation.finished.then(() => {
|
|
9351
|
-
// Only clean up nodes for elements no longer in the document.
|
|
9352
|
-
// Elements still in DOM keep their nodes so subsequent animations
|
|
9353
|
-
// can use the stored position snapshots (A→B→A pattern).
|
|
9354
|
-
const elementsToCleanup = new Set();
|
|
9355
|
-
for (const element of context.nodes.keys()) {
|
|
9356
|
-
if (!document.contains(element)) {
|
|
9357
|
-
elementsToCleanup.add(element);
|
|
9113
|
+
async start() {
|
|
9114
|
+
const beforeElements = collectLayoutElements(this.scope);
|
|
9115
|
+
const beforeRecords = this.buildRecords(beforeElements);
|
|
9116
|
+
beforeRecords.forEach(({ projection }) => {
|
|
9117
|
+
const hasCurrentAnimation = Boolean(projection.currentAnimation);
|
|
9118
|
+
const isSharedLayout = Boolean(projection.options.layoutId);
|
|
9119
|
+
if (hasCurrentAnimation && isSharedLayout) {
|
|
9120
|
+
const snapshot = snapshotFromTarget(projection);
|
|
9121
|
+
if (snapshot) {
|
|
9122
|
+
projection.snapshot = snapshot;
|
|
9123
|
+
}
|
|
9124
|
+
else if (projection.snapshot) {
|
|
9125
|
+
projection.snapshot = undefined;
|
|
9358
9126
|
}
|
|
9359
9127
|
}
|
|
9360
|
-
|
|
9128
|
+
else if (projection.snapshot &&
|
|
9129
|
+
(projection.currentAnimation || projection.isProjecting())) {
|
|
9130
|
+
projection.snapshot = undefined;
|
|
9131
|
+
}
|
|
9132
|
+
projection.isPresent = true;
|
|
9133
|
+
projection.willUpdate();
|
|
9361
9134
|
});
|
|
9362
|
-
this.
|
|
9135
|
+
await this.updateDom();
|
|
9136
|
+
const afterElements = collectLayoutElements(this.scope);
|
|
9137
|
+
const afterRecords = this.buildRecords(afterElements);
|
|
9138
|
+
this.handleExitingElements(beforeRecords, afterRecords);
|
|
9139
|
+
afterRecords.forEach(({ projection }) => {
|
|
9140
|
+
const instance = projection.instance;
|
|
9141
|
+
const resumeFromInstance = projection.resumeFrom
|
|
9142
|
+
?.instance;
|
|
9143
|
+
if (!instance || !resumeFromInstance)
|
|
9144
|
+
return;
|
|
9145
|
+
if (!("style" in instance))
|
|
9146
|
+
return;
|
|
9147
|
+
const currentTransform = instance.style.transform;
|
|
9148
|
+
const resumeFromTransform = resumeFromInstance.style.transform;
|
|
9149
|
+
if (currentTransform &&
|
|
9150
|
+
resumeFromTransform &&
|
|
9151
|
+
currentTransform === resumeFromTransform) {
|
|
9152
|
+
instance.style.transform = "";
|
|
9153
|
+
instance.style.transformOrigin = "";
|
|
9154
|
+
}
|
|
9155
|
+
});
|
|
9156
|
+
afterRecords.forEach(({ projection }) => {
|
|
9157
|
+
projection.isPresent = true;
|
|
9158
|
+
});
|
|
9159
|
+
const root = getProjectionRoot(afterRecords, beforeRecords);
|
|
9160
|
+
root?.didUpdate();
|
|
9161
|
+
await new Promise((resolve) => {
|
|
9162
|
+
frame.postRender(() => resolve());
|
|
9163
|
+
});
|
|
9164
|
+
const animations = collectAnimations(afterRecords);
|
|
9165
|
+
const animation = new GroupAnimation(animations);
|
|
9166
|
+
return animation;
|
|
9363
9167
|
}
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
}
|
|
9370
|
-
|
|
9371
|
-
? this.sharedTransitions
|
|
9372
|
-
: undefined
|
|
9373
|
-
|
|
9168
|
+
buildRecords(elements) {
|
|
9169
|
+
const records = [];
|
|
9170
|
+
const recordMap = new Map();
|
|
9171
|
+
for (const element of elements) {
|
|
9172
|
+
const parentRecord = findParentRecord(element, recordMap, this.scope);
|
|
9173
|
+
const { layout, layoutId } = readLayoutAttributes(element);
|
|
9174
|
+
const override = layoutId
|
|
9175
|
+
? this.sharedTransitions.get(layoutId)
|
|
9176
|
+
: undefined;
|
|
9177
|
+
const transition = override || this.defaultOptions;
|
|
9178
|
+
const record = getOrCreateRecord(element, parentRecord?.projection, {
|
|
9179
|
+
layout,
|
|
9180
|
+
layoutId,
|
|
9181
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
9182
|
+
transition: transition,
|
|
9183
|
+
});
|
|
9184
|
+
recordMap.set(element, record);
|
|
9185
|
+
records.push(record);
|
|
9186
|
+
}
|
|
9187
|
+
return records;
|
|
9188
|
+
}
|
|
9189
|
+
handleExitingElements(beforeRecords, afterRecords) {
|
|
9190
|
+
const afterElementsSet = new Set(afterRecords.map((record) => record.element));
|
|
9191
|
+
beforeRecords.forEach((record) => {
|
|
9192
|
+
if (afterElementsSet.has(record.element))
|
|
9193
|
+
return;
|
|
9194
|
+
// For shared layout elements, relegate to set up resumeFrom
|
|
9195
|
+
// so the remaining element animates from this position
|
|
9196
|
+
if (record.projection.options.layoutId) {
|
|
9197
|
+
record.projection.isPresent = false;
|
|
9198
|
+
record.projection.relegate();
|
|
9199
|
+
}
|
|
9200
|
+
record.visualElement.unmount();
|
|
9201
|
+
visualElementStore.delete(record.element);
|
|
9202
|
+
});
|
|
9203
|
+
// Clear resumeFrom on EXISTING nodes that point to unmounted projections
|
|
9204
|
+
// This prevents crossfade animation when the source element was removed entirely
|
|
9205
|
+
// But preserve resumeFrom for NEW nodes so they can animate from the old position
|
|
9206
|
+
// Also preserve resumeFrom for lead nodes that were just promoted via relegate
|
|
9207
|
+
const beforeElementsSet = new Set(beforeRecords.map((record) => record.element));
|
|
9208
|
+
afterRecords.forEach(({ element, projection }) => {
|
|
9209
|
+
if (beforeElementsSet.has(element) &&
|
|
9210
|
+
projection.resumeFrom &&
|
|
9211
|
+
!projection.resumeFrom.instance &&
|
|
9212
|
+
!projection.isLead()) {
|
|
9213
|
+
projection.resumeFrom = undefined;
|
|
9214
|
+
projection.snapshot = undefined;
|
|
9215
|
+
}
|
|
9216
|
+
});
|
|
9374
9217
|
}
|
|
9375
9218
|
}
|
|
9376
|
-
/**
|
|
9377
|
-
* Parse arguments for animateLayout overloads
|
|
9378
|
-
*/
|
|
9379
9219
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
9380
9220
|
// animateLayout(updateDom)
|
|
9381
9221
|
if (typeof scopeOrUpdateDom === "function") {
|
|
@@ -9389,11 +9229,98 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
|
9389
9229
|
const elements = resolveElements(scopeOrUpdateDom);
|
|
9390
9230
|
const scope = elements[0] || document;
|
|
9391
9231
|
return {
|
|
9392
|
-
scope
|
|
9232
|
+
scope,
|
|
9393
9233
|
updateDom: updateDomOrOptions,
|
|
9394
9234
|
defaultOptions: options,
|
|
9395
9235
|
};
|
|
9396
9236
|
}
|
|
9237
|
+
function collectLayoutElements(scope) {
|
|
9238
|
+
const elements = Array.from(scope.querySelectorAll(layoutSelector));
|
|
9239
|
+
if (scope instanceof Element && scope.matches(layoutSelector)) {
|
|
9240
|
+
if (!elements.includes(scope)) {
|
|
9241
|
+
elements.unshift(scope);
|
|
9242
|
+
}
|
|
9243
|
+
}
|
|
9244
|
+
return elements;
|
|
9245
|
+
}
|
|
9246
|
+
function readLayoutAttributes(element) {
|
|
9247
|
+
const layoutId = element.getAttribute("data-layout-id") || undefined;
|
|
9248
|
+
const rawLayout = element.getAttribute("data-layout");
|
|
9249
|
+
let layout;
|
|
9250
|
+
if (rawLayout === "" || rawLayout === "true") {
|
|
9251
|
+
layout = true;
|
|
9252
|
+
}
|
|
9253
|
+
else if (rawLayout) {
|
|
9254
|
+
layout = rawLayout;
|
|
9255
|
+
}
|
|
9256
|
+
return {
|
|
9257
|
+
layout,
|
|
9258
|
+
layoutId,
|
|
9259
|
+
};
|
|
9260
|
+
}
|
|
9261
|
+
function createVisualState() {
|
|
9262
|
+
return {
|
|
9263
|
+
latestValues: {},
|
|
9264
|
+
renderState: {
|
|
9265
|
+
transform: {},
|
|
9266
|
+
transformOrigin: {},
|
|
9267
|
+
style: {},
|
|
9268
|
+
vars: {},
|
|
9269
|
+
},
|
|
9270
|
+
};
|
|
9271
|
+
}
|
|
9272
|
+
function getOrCreateRecord(element, parentProjection, projectionOptions) {
|
|
9273
|
+
const existing = visualElementStore.get(element);
|
|
9274
|
+
const visualElement = existing ??
|
|
9275
|
+
new HTMLVisualElement({
|
|
9276
|
+
props: {},
|
|
9277
|
+
presenceContext: null,
|
|
9278
|
+
visualState: createVisualState(),
|
|
9279
|
+
}, { allowProjection: true });
|
|
9280
|
+
if (!existing || !visualElement.projection) {
|
|
9281
|
+
visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
|
|
9282
|
+
}
|
|
9283
|
+
visualElement.projection.setOptions({
|
|
9284
|
+
...projectionOptions,
|
|
9285
|
+
visualElement,
|
|
9286
|
+
});
|
|
9287
|
+
if (!visualElement.current) {
|
|
9288
|
+
visualElement.mount(element);
|
|
9289
|
+
}
|
|
9290
|
+
if (!existing) {
|
|
9291
|
+
visualElementStore.set(element, visualElement);
|
|
9292
|
+
}
|
|
9293
|
+
return {
|
|
9294
|
+
element,
|
|
9295
|
+
visualElement,
|
|
9296
|
+
projection: visualElement.projection,
|
|
9297
|
+
};
|
|
9298
|
+
}
|
|
9299
|
+
function findParentRecord(element, recordMap, scope) {
|
|
9300
|
+
let parent = element.parentElement;
|
|
9301
|
+
while (parent) {
|
|
9302
|
+
const record = recordMap.get(parent);
|
|
9303
|
+
if (record)
|
|
9304
|
+
return record;
|
|
9305
|
+
if (parent === scope)
|
|
9306
|
+
break;
|
|
9307
|
+
parent = parent.parentElement;
|
|
9308
|
+
}
|
|
9309
|
+
return undefined;
|
|
9310
|
+
}
|
|
9311
|
+
function getProjectionRoot(afterRecords, beforeRecords) {
|
|
9312
|
+
const record = afterRecords[0] || beforeRecords[0];
|
|
9313
|
+
return record?.projection.root;
|
|
9314
|
+
}
|
|
9315
|
+
function collectAnimations(afterRecords) {
|
|
9316
|
+
const animations = new Set();
|
|
9317
|
+
afterRecords.forEach((record) => {
|
|
9318
|
+
const animation = record.projection.currentAnimation;
|
|
9319
|
+
if (animation)
|
|
9320
|
+
animations.add(animation);
|
|
9321
|
+
});
|
|
9322
|
+
return Array.from(animations);
|
|
9323
|
+
}
|
|
9397
9324
|
|
|
9398
9325
|
/**
|
|
9399
9326
|
* @deprecated
|
|
@@ -9505,7 +9432,7 @@ exports.createAxisDelta = createAxisDelta;
|
|
|
9505
9432
|
exports.createBox = createBox;
|
|
9506
9433
|
exports.createDelta = createDelta;
|
|
9507
9434
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
9508
|
-
exports.createProjectionNode = createProjectionNode
|
|
9435
|
+
exports.createProjectionNode = createProjectionNode;
|
|
9509
9436
|
exports.createRenderBatcher = createRenderBatcher;
|
|
9510
9437
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
9511
9438
|
exports.defaultEasing = defaultEasing;
|