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