motion-dom 12.29.1-alpha.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 +220 -328
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +0 -24
- package/dist/es/animation/JSAnimation.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/es/value/follow-value.mjs +2 -12
- package/dist/es/value/follow-value.mjs.map +1 -1
- package/dist/index.d.ts +11 -25
- package/dist/motion-dom.dev.js +220 -328
- 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
|
@@ -1618,30 +1618,6 @@ class JSAnimation extends WithPromise {
|
|
|
1618
1618
|
this.startTime = 0;
|
|
1619
1619
|
return this.tick(sampleTime, true);
|
|
1620
1620
|
}
|
|
1621
|
-
/**
|
|
1622
|
-
* Returns whether this animation can provide accurate velocity sampling.
|
|
1623
|
-
* This is false for animations using mixKeyframes (non-numeric values)
|
|
1624
|
-
* or animations that aren't currently running.
|
|
1625
|
-
*/
|
|
1626
|
-
get canSampleVelocity() {
|
|
1627
|
-
return (this.state === "running" &&
|
|
1628
|
-
!this.isStopped &&
|
|
1629
|
-
!this.mixKeyframes &&
|
|
1630
|
-
!!this.generator);
|
|
1631
|
-
}
|
|
1632
|
-
/**
|
|
1633
|
-
* Sample the animation's value at a specific time in milliseconds.
|
|
1634
|
-
* Used for velocity calculations via finite differencing.
|
|
1635
|
-
*/
|
|
1636
|
-
sampleAt(t) {
|
|
1637
|
-
return this.generator.next(t).value;
|
|
1638
|
-
}
|
|
1639
|
-
/**
|
|
1640
|
-
* The current elapsed time of the animation in milliseconds.
|
|
1641
|
-
*/
|
|
1642
|
-
get elapsed() {
|
|
1643
|
-
return this.currentTime;
|
|
1644
|
-
}
|
|
1645
1621
|
attachTimeline(timeline) {
|
|
1646
1622
|
if (this.options.allowFlatten) {
|
|
1647
1623
|
this.options.type = "keyframes";
|
|
@@ -4760,25 +4736,16 @@ function attachFollow(value, source, options = {}) {
|
|
|
4760
4736
|
}
|
|
4761
4737
|
};
|
|
4762
4738
|
const startAnimation = () => {
|
|
4739
|
+
stopAnimation();
|
|
4763
4740
|
const currentValue = asNumber$1(value.get());
|
|
4764
4741
|
const targetValue = asNumber$1(latestValue);
|
|
4765
4742
|
// Don't animate if we're already at the target
|
|
4766
4743
|
if (currentValue === targetValue) {
|
|
4767
|
-
stopAnimation();
|
|
4768
4744
|
return;
|
|
4769
4745
|
}
|
|
4770
|
-
// Get velocity from the running animation before stopping it.
|
|
4771
|
-
// This provides the instantaneous velocity from the spring physics,
|
|
4772
|
-
// which is more accurate than the motion value's finite difference.
|
|
4773
|
-
let velocity = value.getVelocity();
|
|
4774
|
-
if (activeAnimation?.canSampleVelocity) {
|
|
4775
|
-
const elapsed = activeAnimation.elapsed;
|
|
4776
|
-
velocity = calcGeneratorVelocity((t) => activeAnimation.sampleAt(t), elapsed, activeAnimation.sampleAt(elapsed));
|
|
4777
|
-
}
|
|
4778
|
-
stopAnimation();
|
|
4779
4746
|
activeAnimation = new JSAnimation({
|
|
4780
4747
|
keyframes: [currentValue, targetValue],
|
|
4781
|
-
velocity,
|
|
4748
|
+
velocity: value.getVelocity(),
|
|
4782
4749
|
// Default to spring if no type specified (matches useSpring behavior)
|
|
4783
4750
|
type: "spring",
|
|
4784
4751
|
restDelta: 0.001,
|
|
@@ -7490,7 +7457,7 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7490
7457
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7491
7458
|
}
|
|
7492
7459
|
}
|
|
7493
|
-
function createProjectionNode
|
|
7460
|
+
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7494
7461
|
return class ProjectionNode {
|
|
7495
7462
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7496
7463
|
/**
|
|
@@ -9047,7 +9014,7 @@ function checkNodeWasScrollRoot(node) {
|
|
|
9047
9014
|
return node !== node.root && node.scroll?.wasRoot;
|
|
9048
9015
|
}
|
|
9049
9016
|
|
|
9050
|
-
const DocumentProjectionNode = createProjectionNode
|
|
9017
|
+
const DocumentProjectionNode = createProjectionNode({
|
|
9051
9018
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
9052
9019
|
measureScroll: () => ({
|
|
9053
9020
|
x: document.documentElement.scrollLeft || document.body?.scrollLeft || 0,
|
|
@@ -9082,7 +9049,7 @@ function nodeGroup() {
|
|
|
9082
9049
|
const rootProjectionNode = {
|
|
9083
9050
|
current: undefined,
|
|
9084
9051
|
};
|
|
9085
|
-
const HTMLProjectionNode = createProjectionNode
|
|
9052
|
+
const HTMLProjectionNode = createProjectionNode({
|
|
9086
9053
|
measureScroll: (instance) => ({
|
|
9087
9054
|
x: instance.scrollLeft,
|
|
9088
9055
|
y: instance.scrollTop,
|
|
@@ -9102,315 +9069,153 @@ const HTMLProjectionNode = createProjectionNode$1({
|
|
|
9102
9069
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
9103
9070
|
});
|
|
9104
9071
|
|
|
9105
|
-
const
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
if (
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
return element.getAttribute("data-layout-id");
|
|
9116
|
-
}
|
|
9117
|
-
function hasLayout(element) {
|
|
9118
|
-
return (element.hasAttribute("data-layout") ||
|
|
9119
|
-
element.hasAttribute("data-layout-id"));
|
|
9120
|
-
}
|
|
9121
|
-
|
|
9122
|
-
let scaleCorrectorAdded = false;
|
|
9123
|
-
/**
|
|
9124
|
-
* Track active projection nodes per element to handle animation interruption.
|
|
9125
|
-
* When a new animation starts on an element that already has an active animation,
|
|
9126
|
-
* we need to stop the old animation so the new one can start from the current
|
|
9127
|
-
* visual position.
|
|
9128
|
-
*/
|
|
9129
|
-
const activeProjectionNodes = new WeakMap();
|
|
9130
|
-
function ensureScaleCorrectors() {
|
|
9131
|
-
if (scaleCorrectorAdded)
|
|
9132
|
-
return;
|
|
9133
|
-
scaleCorrectorAdded = true;
|
|
9134
|
-
addScaleCorrector({
|
|
9135
|
-
borderRadius: {
|
|
9136
|
-
...correctBorderRadius,
|
|
9137
|
-
applyTo: [
|
|
9138
|
-
"borderTopLeftRadius",
|
|
9139
|
-
"borderTopRightRadius",
|
|
9140
|
-
"borderBottomLeftRadius",
|
|
9141
|
-
"borderBottomRightRadius",
|
|
9142
|
-
],
|
|
9143
|
-
},
|
|
9144
|
-
borderTopLeftRadius: correctBorderRadius,
|
|
9145
|
-
borderTopRightRadius: correctBorderRadius,
|
|
9146
|
-
borderBottomLeftRadius: correctBorderRadius,
|
|
9147
|
-
borderBottomRightRadius: correctBorderRadius,
|
|
9148
|
-
boxShadow: correctBoxShadow,
|
|
9149
|
-
});
|
|
9150
|
-
}
|
|
9151
|
-
/**
|
|
9152
|
-
* Get DOM depth of an element
|
|
9153
|
-
*/
|
|
9154
|
-
function getDepth(element) {
|
|
9155
|
-
let depth = 0;
|
|
9156
|
-
let current = element.parentElement;
|
|
9157
|
-
while (current) {
|
|
9158
|
-
depth++;
|
|
9159
|
-
current = current.parentElement;
|
|
9160
|
-
}
|
|
9161
|
-
return depth;
|
|
9162
|
-
}
|
|
9163
|
-
/**
|
|
9164
|
-
* Find the closest projection parent for an element
|
|
9165
|
-
*/
|
|
9166
|
-
function findProjectionParent(element, nodeCache) {
|
|
9167
|
-
let parent = element.parentElement;
|
|
9168
|
-
while (parent) {
|
|
9169
|
-
const node = nodeCache.get(parent);
|
|
9170
|
-
if (node)
|
|
9171
|
-
return node;
|
|
9172
|
-
parent = parent.parentElement;
|
|
9173
|
-
}
|
|
9174
|
-
return undefined;
|
|
9175
|
-
}
|
|
9176
|
-
/**
|
|
9177
|
-
* Create or reuse a projection node for an element
|
|
9178
|
-
*/
|
|
9179
|
-
function createProjectionNode(element, parent, options, transition) {
|
|
9180
|
-
// Check for existing active node - reuse it to preserve animation state
|
|
9181
|
-
const existingNode = activeProjectionNodes.get(element);
|
|
9182
|
-
if (existingNode) {
|
|
9183
|
-
const visualElement = existingNode.options.visualElement;
|
|
9184
|
-
// Update transition options for the new animation
|
|
9185
|
-
const nodeTransition = transition
|
|
9186
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9187
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9188
|
-
existingNode.setOptions({
|
|
9189
|
-
...existingNode.options,
|
|
9190
|
-
animate: true,
|
|
9191
|
-
transition: nodeTransition,
|
|
9192
|
-
...options,
|
|
9193
|
-
});
|
|
9194
|
-
// Re-mount the node if it was previously unmounted
|
|
9195
|
-
// This re-adds it to root.nodes so didUpdate() will process it
|
|
9196
|
-
if (!existingNode.instance) {
|
|
9197
|
-
existingNode.mount(element);
|
|
9198
|
-
}
|
|
9199
|
-
return { node: existingNode, visualElement };
|
|
9200
|
-
}
|
|
9201
|
-
// No existing node - create a new one
|
|
9202
|
-
const latestValues = {};
|
|
9203
|
-
const visualElement = new HTMLVisualElement({
|
|
9204
|
-
visualState: {
|
|
9205
|
-
latestValues,
|
|
9206
|
-
renderState: {
|
|
9207
|
-
transformOrigin: {},
|
|
9208
|
-
transform: {},
|
|
9209
|
-
style: {},
|
|
9210
|
-
vars: {},
|
|
9211
|
-
},
|
|
9212
|
-
},
|
|
9213
|
-
presenceContext: null,
|
|
9214
|
-
props: {},
|
|
9215
|
-
});
|
|
9216
|
-
const node = new HTMLProjectionNode(latestValues, parent);
|
|
9217
|
-
// Convert AnimationOptions to transition format for the projection system
|
|
9218
|
-
const nodeTransition = transition
|
|
9219
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9220
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9221
|
-
node.setOptions({
|
|
9222
|
-
visualElement,
|
|
9223
|
-
layout: true,
|
|
9224
|
-
animate: true,
|
|
9225
|
-
transition: nodeTransition,
|
|
9226
|
-
...options,
|
|
9227
|
-
});
|
|
9228
|
-
node.mount(element);
|
|
9229
|
-
visualElement.projection = node;
|
|
9230
|
-
// Track this node as the active one for this element
|
|
9231
|
-
activeProjectionNodes.set(element, node);
|
|
9232
|
-
return { node, visualElement };
|
|
9233
|
-
}
|
|
9234
|
-
/**
|
|
9235
|
-
* Build a projection tree from a list of elements
|
|
9236
|
-
*/
|
|
9237
|
-
function buildProjectionTree(elements, existingContext, options) {
|
|
9238
|
-
ensureScaleCorrectors();
|
|
9239
|
-
const nodes = existingContext?.nodes ?? new Map();
|
|
9240
|
-
const visualElements = existingContext?.visualElements ?? new Map();
|
|
9241
|
-
const group = existingContext?.group ?? nodeGroup();
|
|
9242
|
-
const defaultTransition = options?.defaultTransition;
|
|
9243
|
-
const sharedTransitions = options?.sharedTransitions;
|
|
9244
|
-
// Sort elements by DOM depth (parents before children)
|
|
9245
|
-
const sorted = [...elements].sort((a, b) => getDepth(a) - getDepth(b));
|
|
9246
|
-
let root = existingContext?.root;
|
|
9247
|
-
for (const element of sorted) {
|
|
9248
|
-
// Skip if already has a node
|
|
9249
|
-
if (nodes.has(element))
|
|
9250
|
-
continue;
|
|
9251
|
-
const parent = findProjectionParent(element, nodes);
|
|
9252
|
-
const layoutId = getLayoutId(element);
|
|
9253
|
-
const layoutMode = element.getAttribute("data-layout");
|
|
9254
|
-
const nodeOptions = {
|
|
9255
|
-
layoutId: layoutId ?? undefined,
|
|
9256
|
-
animationType: parseLayoutMode(layoutMode),
|
|
9257
|
-
};
|
|
9258
|
-
// Use layoutId-specific transition if available, otherwise use default
|
|
9259
|
-
const transition = layoutId && sharedTransitions?.get(layoutId)
|
|
9260
|
-
? sharedTransitions.get(layoutId)
|
|
9261
|
-
: defaultTransition;
|
|
9262
|
-
const { node, visualElement } = createProjectionNode(element, parent, nodeOptions, transition);
|
|
9263
|
-
nodes.set(element, node);
|
|
9264
|
-
visualElements.set(element, visualElement);
|
|
9265
|
-
group.add(node);
|
|
9266
|
-
if (!root) {
|
|
9267
|
-
root = node.root;
|
|
9268
|
-
}
|
|
9269
|
-
}
|
|
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);
|
|
9270
9082
|
return {
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9083
|
+
animationId: projection.root?.animationId ?? 0,
|
|
9084
|
+
measuredBox,
|
|
9085
|
+
layoutBox,
|
|
9086
|
+
latestValues: projection.animationValues || projection.latestValues || {},
|
|
9087
|
+
source: projection.id,
|
|
9275
9088
|
};
|
|
9276
9089
|
}
|
|
9277
|
-
/**
|
|
9278
|
-
* Parse the data-layout attribute value
|
|
9279
|
-
*/
|
|
9280
|
-
function parseLayoutMode(value) {
|
|
9281
|
-
if (value === "position")
|
|
9282
|
-
return "position";
|
|
9283
|
-
if (value === "size")
|
|
9284
|
-
return "size";
|
|
9285
|
-
if (value === "preserve-aspect")
|
|
9286
|
-
return "preserve-aspect";
|
|
9287
|
-
return "both";
|
|
9288
|
-
}
|
|
9289
|
-
/**
|
|
9290
|
-
* Clean up projection nodes for specific elements.
|
|
9291
|
-
* If elementsToCleanup is provided, only those elements are cleaned up.
|
|
9292
|
-
* If not provided, all nodes are cleaned up.
|
|
9293
|
-
*
|
|
9294
|
-
* This allows persisting elements to keep their nodes between animations,
|
|
9295
|
-
* matching React's behavior where nodes persist for elements that remain in the DOM.
|
|
9296
|
-
*/
|
|
9297
|
-
function cleanupProjectionTree(context, elementsToCleanup) {
|
|
9298
|
-
const elementsToProcess = elementsToCleanup
|
|
9299
|
-
? [...context.nodes.entries()].filter(([el]) => elementsToCleanup.has(el))
|
|
9300
|
-
: [...context.nodes.entries()];
|
|
9301
|
-
for (const [element, node] of elementsToProcess) {
|
|
9302
|
-
context.group.remove(node);
|
|
9303
|
-
node.unmount();
|
|
9304
|
-
// Only clear from activeProjectionNodes if this is still the active node.
|
|
9305
|
-
// A newer animation might have already taken over.
|
|
9306
|
-
if (activeProjectionNodes.get(element) === node) {
|
|
9307
|
-
activeProjectionNodes.delete(element);
|
|
9308
|
-
}
|
|
9309
|
-
context.nodes.delete(element);
|
|
9310
|
-
context.visualElements.delete(element);
|
|
9311
|
-
}
|
|
9312
|
-
}
|
|
9313
|
-
|
|
9314
9090
|
class LayoutAnimationBuilder {
|
|
9315
9091
|
constructor(scope, updateDom, defaultOptions) {
|
|
9316
9092
|
this.sharedTransitions = new Map();
|
|
9317
|
-
this.notifyReady =
|
|
9318
|
-
this.
|
|
9093
|
+
this.notifyReady = noop;
|
|
9094
|
+
this.rejectReady = noop;
|
|
9319
9095
|
this.scope = scope;
|
|
9320
9096
|
this.updateDom = updateDom;
|
|
9321
9097
|
this.defaultOptions = defaultOptions;
|
|
9322
|
-
this.readyPromise = new Promise((resolve) => {
|
|
9098
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
9323
9099
|
this.notifyReady = resolve;
|
|
9100
|
+
this.rejectReady = reject;
|
|
9101
|
+
});
|
|
9102
|
+
frame.postRender(() => {
|
|
9103
|
+
this.start().then(this.notifyReady).catch(this.rejectReady);
|
|
9324
9104
|
});
|
|
9325
|
-
// Queue execution on microtask to allow builder methods to be called
|
|
9326
|
-
queueMicrotask(() => this.execute());
|
|
9327
9105
|
}
|
|
9328
|
-
shared(id,
|
|
9329
|
-
this.sharedTransitions.set(id,
|
|
9106
|
+
shared(id, transition) {
|
|
9107
|
+
this.sharedTransitions.set(id, transition);
|
|
9330
9108
|
return this;
|
|
9331
9109
|
}
|
|
9332
|
-
then(
|
|
9333
|
-
return this.readyPromise.then(
|
|
9110
|
+
then(resolve, reject) {
|
|
9111
|
+
return this.readyPromise.then(resolve, reject);
|
|
9334
9112
|
}
|
|
9335
|
-
async
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
}
|
|
9349
|
-
}
|
|
9350
|
-
// Phase 2: Execute DOM update
|
|
9351
|
-
this.updateDom();
|
|
9352
|
-
// Phase 3: Post-mutation - Compare before/after elements
|
|
9353
|
-
const afterElements = getLayoutElements(this.scope);
|
|
9354
|
-
const beforeSet = new Set(beforeElements);
|
|
9355
|
-
const afterSet = new Set(afterElements);
|
|
9356
|
-
const entering = afterElements.filter((el) => !beforeSet.has(el));
|
|
9357
|
-
const exiting = beforeElements.filter((el) => !afterSet.has(el));
|
|
9358
|
-
// Build projection nodes for entering elements
|
|
9359
|
-
if (entering.length > 0) {
|
|
9360
|
-
context = buildProjectionTree(entering, context, this.getBuildOptions());
|
|
9361
|
-
}
|
|
9362
|
-
// No layout elements - return empty animation
|
|
9363
|
-
if (!context) {
|
|
9364
|
-
this.notifyReady(new GroupAnimation([]));
|
|
9365
|
-
return;
|
|
9366
|
-
}
|
|
9367
|
-
// Handle shared elements
|
|
9368
|
-
for (const element of exiting) {
|
|
9369
|
-
const node = context.nodes.get(element);
|
|
9370
|
-
node?.getStack()?.remove(node);
|
|
9371
|
-
}
|
|
9372
|
-
for (const element of entering) {
|
|
9373
|
-
context.nodes.get(element)?.promote();
|
|
9374
|
-
}
|
|
9375
|
-
// Phase 4: Animate
|
|
9376
|
-
context.root.didUpdate();
|
|
9377
|
-
await new Promise((resolve) => frame.postRender(() => resolve()));
|
|
9378
|
-
const animations = [];
|
|
9379
|
-
for (const node of context.nodes.values()) {
|
|
9380
|
-
if (node.currentAnimation) {
|
|
9381
|
-
animations.push(node.currentAnimation);
|
|
9382
|
-
}
|
|
9383
|
-
}
|
|
9384
|
-
const groupAnimation = new GroupAnimation(animations);
|
|
9385
|
-
groupAnimation.finished.then(() => {
|
|
9386
|
-
// Only clean up nodes for elements no longer in the document.
|
|
9387
|
-
// Elements still in DOM keep their nodes so subsequent animations
|
|
9388
|
-
// can use the stored position snapshots (A→B→A pattern).
|
|
9389
|
-
const elementsToCleanup = new Set();
|
|
9390
|
-
for (const element of context.nodes.keys()) {
|
|
9391
|
-
if (!document.contains(element)) {
|
|
9392
|
-
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;
|
|
9393
9126
|
}
|
|
9394
9127
|
}
|
|
9395
|
-
|
|
9128
|
+
else if (projection.snapshot &&
|
|
9129
|
+
(projection.currentAnimation || projection.isProjecting())) {
|
|
9130
|
+
projection.snapshot = undefined;
|
|
9131
|
+
}
|
|
9132
|
+
projection.isPresent = true;
|
|
9133
|
+
projection.willUpdate();
|
|
9134
|
+
});
|
|
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;
|
|
9396
9158
|
});
|
|
9397
|
-
|
|
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;
|
|
9398
9167
|
}
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
}
|
|
9405
|
-
|
|
9406
|
-
? this.sharedTransitions
|
|
9407
|
-
: undefined
|
|
9408
|
-
|
|
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
|
+
});
|
|
9409
9217
|
}
|
|
9410
9218
|
}
|
|
9411
|
-
/**
|
|
9412
|
-
* Parse arguments for animateLayout overloads
|
|
9413
|
-
*/
|
|
9414
9219
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
9415
9220
|
// animateLayout(updateDom)
|
|
9416
9221
|
if (typeof scopeOrUpdateDom === "function") {
|
|
@@ -9424,11 +9229,98 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
|
9424
9229
|
const elements = resolveElements(scopeOrUpdateDom);
|
|
9425
9230
|
const scope = elements[0] || document;
|
|
9426
9231
|
return {
|
|
9427
|
-
scope
|
|
9232
|
+
scope,
|
|
9428
9233
|
updateDom: updateDomOrOptions,
|
|
9429
9234
|
defaultOptions: options,
|
|
9430
9235
|
};
|
|
9431
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
|
+
}
|
|
9432
9324
|
|
|
9433
9325
|
/**
|
|
9434
9326
|
* @deprecated
|
|
@@ -9540,7 +9432,7 @@ exports.createAxisDelta = createAxisDelta;
|
|
|
9540
9432
|
exports.createBox = createBox;
|
|
9541
9433
|
exports.createDelta = createDelta;
|
|
9542
9434
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
9543
|
-
exports.createProjectionNode = createProjectionNode
|
|
9435
|
+
exports.createProjectionNode = createProjectionNode;
|
|
9544
9436
|
exports.createRenderBatcher = createRenderBatcher;
|
|
9545
9437
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
9546
9438
|
exports.defaultEasing = defaultEasing;
|