motion-dom 12.27.5 → 12.28.1-alpha.1
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 +229 -309
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/effects/svg/index.mjs +4 -7
- package/dist/es/effects/svg/index.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/DocumentProjectionNode.mjs +2 -2
- package/dist/es/projection/node/DocumentProjectionNode.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/render/svg/utils/path.mjs +8 -7
- package/dist/es/render/svg/utils/path.mjs.map +1 -1
- package/dist/index.d.ts +11 -13
- package/dist/motion-dom.dev.js +229 -309
- 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
|
@@ -4122,21 +4122,17 @@ const addStyleValue = (element, state, key, value) => {
|
|
|
4122
4122
|
const styleEffect = /*@__PURE__*/ createSelectorEffect(
|
|
4123
4123
|
/*@__PURE__*/ createEffect(addStyleValue));
|
|
4124
4124
|
|
|
4125
|
+
const toPx = px.transform;
|
|
4125
4126
|
function addSVGPathValue(element, state, key, value) {
|
|
4126
4127
|
frame.render(() => element.setAttribute("pathLength", "1"));
|
|
4127
4128
|
if (key === "pathOffset") {
|
|
4128
|
-
return state.set(key, value, () =>
|
|
4129
|
-
// Use unitless value to avoid Safari zoom bug
|
|
4130
|
-
const offset = state.latest[key];
|
|
4131
|
-
element.setAttribute("stroke-dashoffset", `${-offset}`);
|
|
4132
|
-
});
|
|
4129
|
+
return state.set(key, value, () => element.setAttribute("stroke-dashoffset", toPx(-state.latest[key])));
|
|
4133
4130
|
}
|
|
4134
4131
|
else {
|
|
4135
4132
|
if (!state.get("stroke-dasharray")) {
|
|
4136
4133
|
state.set("stroke-dasharray", new MotionValue("1 1"), () => {
|
|
4137
4134
|
const { pathLength = 1, pathSpacing } = state.latest;
|
|
4138
|
-
|
|
4139
|
-
element.setAttribute("stroke-dasharray", `${pathLength} ${pathSpacing ?? 1 - Number(pathLength)}`);
|
|
4135
|
+
element.setAttribute("stroke-dasharray", `${toPx(pathLength)} ${toPx(pathSpacing ?? 1 - Number(pathLength))}`);
|
|
4140
4136
|
});
|
|
4141
4137
|
}
|
|
4142
4138
|
return state.set(key, value, undefined, state.get("stroke-dasharray"));
|
|
@@ -6339,9 +6335,6 @@ const camelKeys = {
|
|
|
6339
6335
|
* and stroke-dasharray attributes.
|
|
6340
6336
|
*
|
|
6341
6337
|
* This function is mutative to reduce per-frame GC.
|
|
6342
|
-
*
|
|
6343
|
-
* Note: We use unitless values for stroke-dasharray and stroke-dashoffset
|
|
6344
|
-
* because Safari incorrectly scales px values when the page is zoomed.
|
|
6345
6338
|
*/
|
|
6346
6339
|
function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true) {
|
|
6347
6340
|
// Normalise path length by setting SVG attribute pathLength to 1
|
|
@@ -6349,10 +6342,12 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
6349
6342
|
// We use dash case when setting attributes directly to the DOM node and camel case
|
|
6350
6343
|
// when defining props on a React component.
|
|
6351
6344
|
const keys = useDashCase ? dashKeys : camelKeys;
|
|
6352
|
-
// Build the dash offset
|
|
6353
|
-
attrs[keys.offset] =
|
|
6354
|
-
// Build the dash array
|
|
6355
|
-
|
|
6345
|
+
// Build the dash offset
|
|
6346
|
+
attrs[keys.offset] = px.transform(-offset);
|
|
6347
|
+
// Build the dash array
|
|
6348
|
+
const pathLength = px.transform(length);
|
|
6349
|
+
const pathSpacing = px.transform(spacing);
|
|
6350
|
+
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
6356
6351
|
}
|
|
6357
6352
|
|
|
6358
6353
|
/**
|
|
@@ -7385,7 +7380,7 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7385
7380
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7386
7381
|
}
|
|
7387
7382
|
}
|
|
7388
|
-
function createProjectionNode
|
|
7383
|
+
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7389
7384
|
return class ProjectionNode {
|
|
7390
7385
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7391
7386
|
/**
|
|
@@ -8942,11 +8937,11 @@ function checkNodeWasScrollRoot(node) {
|
|
|
8942
8937
|
return node !== node.root && node.scroll?.wasRoot;
|
|
8943
8938
|
}
|
|
8944
8939
|
|
|
8945
|
-
const DocumentProjectionNode = createProjectionNode
|
|
8940
|
+
const DocumentProjectionNode = createProjectionNode({
|
|
8946
8941
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
8947
8942
|
measureScroll: () => ({
|
|
8948
|
-
x: document.documentElement.scrollLeft || document.body
|
|
8949
|
-
y: document.documentElement.scrollTop || document.body
|
|
8943
|
+
x: document.documentElement.scrollLeft || document.body.scrollLeft,
|
|
8944
|
+
y: document.documentElement.scrollTop || document.body.scrollTop,
|
|
8950
8945
|
}),
|
|
8951
8946
|
checkIsScrollRoot: () => true,
|
|
8952
8947
|
});
|
|
@@ -8977,7 +8972,7 @@ function nodeGroup() {
|
|
|
8977
8972
|
const rootProjectionNode = {
|
|
8978
8973
|
current: undefined,
|
|
8979
8974
|
};
|
|
8980
|
-
const HTMLProjectionNode = createProjectionNode
|
|
8975
|
+
const HTMLProjectionNode = createProjectionNode({
|
|
8981
8976
|
measureScroll: (instance) => ({
|
|
8982
8977
|
x: instance.scrollLeft,
|
|
8983
8978
|
y: instance.scrollTop,
|
|
@@ -8997,315 +8992,153 @@ const HTMLProjectionNode = createProjectionNode$1({
|
|
|
8997
8992
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
8998
8993
|
});
|
|
8999
8994
|
|
|
9000
|
-
const
|
|
9001
|
-
|
|
9002
|
-
|
|
9003
|
-
|
|
9004
|
-
if (
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
return element.getAttribute("data-layout-id");
|
|
9011
|
-
}
|
|
9012
|
-
function hasLayout(element) {
|
|
9013
|
-
return (element.hasAttribute("data-layout") ||
|
|
9014
|
-
element.hasAttribute("data-layout-id"));
|
|
9015
|
-
}
|
|
9016
|
-
|
|
9017
|
-
let scaleCorrectorAdded = false;
|
|
9018
|
-
/**
|
|
9019
|
-
* Track active projection nodes per element to handle animation interruption.
|
|
9020
|
-
* When a new animation starts on an element that already has an active animation,
|
|
9021
|
-
* we need to stop the old animation so the new one can start from the current
|
|
9022
|
-
* visual position.
|
|
9023
|
-
*/
|
|
9024
|
-
const activeProjectionNodes = new WeakMap();
|
|
9025
|
-
function ensureScaleCorrectors() {
|
|
9026
|
-
if (scaleCorrectorAdded)
|
|
9027
|
-
return;
|
|
9028
|
-
scaleCorrectorAdded = true;
|
|
9029
|
-
addScaleCorrector({
|
|
9030
|
-
borderRadius: {
|
|
9031
|
-
...correctBorderRadius,
|
|
9032
|
-
applyTo: [
|
|
9033
|
-
"borderTopLeftRadius",
|
|
9034
|
-
"borderTopRightRadius",
|
|
9035
|
-
"borderBottomLeftRadius",
|
|
9036
|
-
"borderBottomRightRadius",
|
|
9037
|
-
],
|
|
9038
|
-
},
|
|
9039
|
-
borderTopLeftRadius: correctBorderRadius,
|
|
9040
|
-
borderTopRightRadius: correctBorderRadius,
|
|
9041
|
-
borderBottomLeftRadius: correctBorderRadius,
|
|
9042
|
-
borderBottomRightRadius: correctBorderRadius,
|
|
9043
|
-
boxShadow: correctBoxShadow,
|
|
9044
|
-
});
|
|
9045
|
-
}
|
|
9046
|
-
/**
|
|
9047
|
-
* Get DOM depth of an element
|
|
9048
|
-
*/
|
|
9049
|
-
function getDepth(element) {
|
|
9050
|
-
let depth = 0;
|
|
9051
|
-
let current = element.parentElement;
|
|
9052
|
-
while (current) {
|
|
9053
|
-
depth++;
|
|
9054
|
-
current = current.parentElement;
|
|
9055
|
-
}
|
|
9056
|
-
return depth;
|
|
9057
|
-
}
|
|
9058
|
-
/**
|
|
9059
|
-
* Find the closest projection parent for an element
|
|
9060
|
-
*/
|
|
9061
|
-
function findProjectionParent(element, nodeCache) {
|
|
9062
|
-
let parent = element.parentElement;
|
|
9063
|
-
while (parent) {
|
|
9064
|
-
const node = nodeCache.get(parent);
|
|
9065
|
-
if (node)
|
|
9066
|
-
return node;
|
|
9067
|
-
parent = parent.parentElement;
|
|
9068
|
-
}
|
|
9069
|
-
return undefined;
|
|
9070
|
-
}
|
|
9071
|
-
/**
|
|
9072
|
-
* Create or reuse a projection node for an element
|
|
9073
|
-
*/
|
|
9074
|
-
function createProjectionNode(element, parent, options, transition) {
|
|
9075
|
-
// Check for existing active node - reuse it to preserve animation state
|
|
9076
|
-
const existingNode = activeProjectionNodes.get(element);
|
|
9077
|
-
if (existingNode) {
|
|
9078
|
-
const visualElement = existingNode.options.visualElement;
|
|
9079
|
-
// Update transition options for the new animation
|
|
9080
|
-
const nodeTransition = transition
|
|
9081
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9082
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9083
|
-
existingNode.setOptions({
|
|
9084
|
-
...existingNode.options,
|
|
9085
|
-
animate: true,
|
|
9086
|
-
transition: nodeTransition,
|
|
9087
|
-
...options,
|
|
9088
|
-
});
|
|
9089
|
-
// Re-mount the node if it was previously unmounted
|
|
9090
|
-
// This re-adds it to root.nodes so didUpdate() will process it
|
|
9091
|
-
if (!existingNode.instance) {
|
|
9092
|
-
existingNode.mount(element);
|
|
9093
|
-
}
|
|
9094
|
-
return { node: existingNode, visualElement };
|
|
9095
|
-
}
|
|
9096
|
-
// No existing node - create a new one
|
|
9097
|
-
const latestValues = {};
|
|
9098
|
-
const visualElement = new HTMLVisualElement({
|
|
9099
|
-
visualState: {
|
|
9100
|
-
latestValues,
|
|
9101
|
-
renderState: {
|
|
9102
|
-
transformOrigin: {},
|
|
9103
|
-
transform: {},
|
|
9104
|
-
style: {},
|
|
9105
|
-
vars: {},
|
|
9106
|
-
},
|
|
9107
|
-
},
|
|
9108
|
-
presenceContext: null,
|
|
9109
|
-
props: {},
|
|
9110
|
-
});
|
|
9111
|
-
const node = new HTMLProjectionNode(latestValues, parent);
|
|
9112
|
-
// Convert AnimationOptions to transition format for the projection system
|
|
9113
|
-
const nodeTransition = transition
|
|
9114
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9115
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9116
|
-
node.setOptions({
|
|
9117
|
-
visualElement,
|
|
9118
|
-
layout: true,
|
|
9119
|
-
animate: true,
|
|
9120
|
-
transition: nodeTransition,
|
|
9121
|
-
...options,
|
|
9122
|
-
});
|
|
9123
|
-
node.mount(element);
|
|
9124
|
-
visualElement.projection = node;
|
|
9125
|
-
// Track this node as the active one for this element
|
|
9126
|
-
activeProjectionNodes.set(element, node);
|
|
9127
|
-
return { node, visualElement };
|
|
9128
|
-
}
|
|
9129
|
-
/**
|
|
9130
|
-
* Build a projection tree from a list of elements
|
|
9131
|
-
*/
|
|
9132
|
-
function buildProjectionTree(elements, existingContext, options) {
|
|
9133
|
-
ensureScaleCorrectors();
|
|
9134
|
-
const nodes = existingContext?.nodes ?? new Map();
|
|
9135
|
-
const visualElements = existingContext?.visualElements ?? new Map();
|
|
9136
|
-
const group = existingContext?.group ?? nodeGroup();
|
|
9137
|
-
const defaultTransition = options?.defaultTransition;
|
|
9138
|
-
const sharedTransitions = options?.sharedTransitions;
|
|
9139
|
-
// Sort elements by DOM depth (parents before children)
|
|
9140
|
-
const sorted = [...elements].sort((a, b) => getDepth(a) - getDepth(b));
|
|
9141
|
-
let root = existingContext?.root;
|
|
9142
|
-
for (const element of sorted) {
|
|
9143
|
-
// Skip if already has a node
|
|
9144
|
-
if (nodes.has(element))
|
|
9145
|
-
continue;
|
|
9146
|
-
const parent = findProjectionParent(element, nodes);
|
|
9147
|
-
const layoutId = getLayoutId(element);
|
|
9148
|
-
const layoutMode = element.getAttribute("data-layout");
|
|
9149
|
-
const nodeOptions = {
|
|
9150
|
-
layoutId: layoutId ?? undefined,
|
|
9151
|
-
animationType: parseLayoutMode(layoutMode),
|
|
9152
|
-
};
|
|
9153
|
-
// Use layoutId-specific transition if available, otherwise use default
|
|
9154
|
-
const transition = layoutId && sharedTransitions?.get(layoutId)
|
|
9155
|
-
? sharedTransitions.get(layoutId)
|
|
9156
|
-
: defaultTransition;
|
|
9157
|
-
const { node, visualElement } = createProjectionNode(element, parent, nodeOptions, transition);
|
|
9158
|
-
nodes.set(element, node);
|
|
9159
|
-
visualElements.set(element, visualElement);
|
|
9160
|
-
group.add(node);
|
|
9161
|
-
if (!root) {
|
|
9162
|
-
root = node.root;
|
|
9163
|
-
}
|
|
9164
|
-
}
|
|
8995
|
+
const layoutSelector = "[data-layout], [data-layout-id]";
|
|
8996
|
+
const noop = () => { };
|
|
8997
|
+
function snapshotFromTarget(projection) {
|
|
8998
|
+
const target = projection.targetWithTransforms || projection.target;
|
|
8999
|
+
if (!target)
|
|
9000
|
+
return undefined;
|
|
9001
|
+
const measuredBox = createBox();
|
|
9002
|
+
const layoutBox = createBox();
|
|
9003
|
+
copyBoxInto(measuredBox, target);
|
|
9004
|
+
copyBoxInto(layoutBox, target);
|
|
9165
9005
|
return {
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9006
|
+
animationId: projection.root?.animationId ?? 0,
|
|
9007
|
+
measuredBox,
|
|
9008
|
+
layoutBox,
|
|
9009
|
+
latestValues: projection.animationValues || projection.latestValues || {},
|
|
9010
|
+
source: projection.id,
|
|
9170
9011
|
};
|
|
9171
9012
|
}
|
|
9172
|
-
/**
|
|
9173
|
-
* Parse the data-layout attribute value
|
|
9174
|
-
*/
|
|
9175
|
-
function parseLayoutMode(value) {
|
|
9176
|
-
if (value === "position")
|
|
9177
|
-
return "position";
|
|
9178
|
-
if (value === "size")
|
|
9179
|
-
return "size";
|
|
9180
|
-
if (value === "preserve-aspect")
|
|
9181
|
-
return "preserve-aspect";
|
|
9182
|
-
return "both";
|
|
9183
|
-
}
|
|
9184
|
-
/**
|
|
9185
|
-
* Clean up projection nodes for specific elements.
|
|
9186
|
-
* If elementsToCleanup is provided, only those elements are cleaned up.
|
|
9187
|
-
* If not provided, all nodes are cleaned up.
|
|
9188
|
-
*
|
|
9189
|
-
* This allows persisting elements to keep their nodes between animations,
|
|
9190
|
-
* matching React's behavior where nodes persist for elements that remain in the DOM.
|
|
9191
|
-
*/
|
|
9192
|
-
function cleanupProjectionTree(context, elementsToCleanup) {
|
|
9193
|
-
const elementsToProcess = elementsToCleanup
|
|
9194
|
-
? [...context.nodes.entries()].filter(([el]) => elementsToCleanup.has(el))
|
|
9195
|
-
: [...context.nodes.entries()];
|
|
9196
|
-
for (const [element, node] of elementsToProcess) {
|
|
9197
|
-
context.group.remove(node);
|
|
9198
|
-
node.unmount();
|
|
9199
|
-
// Only clear from activeProjectionNodes if this is still the active node.
|
|
9200
|
-
// A newer animation might have already taken over.
|
|
9201
|
-
if (activeProjectionNodes.get(element) === node) {
|
|
9202
|
-
activeProjectionNodes.delete(element);
|
|
9203
|
-
}
|
|
9204
|
-
context.nodes.delete(element);
|
|
9205
|
-
context.visualElements.delete(element);
|
|
9206
|
-
}
|
|
9207
|
-
}
|
|
9208
|
-
|
|
9209
9013
|
class LayoutAnimationBuilder {
|
|
9210
9014
|
constructor(scope, updateDom, defaultOptions) {
|
|
9211
9015
|
this.sharedTransitions = new Map();
|
|
9212
|
-
this.notifyReady =
|
|
9213
|
-
this.
|
|
9016
|
+
this.notifyReady = noop;
|
|
9017
|
+
this.rejectReady = noop;
|
|
9214
9018
|
this.scope = scope;
|
|
9215
9019
|
this.updateDom = updateDom;
|
|
9216
9020
|
this.defaultOptions = defaultOptions;
|
|
9217
|
-
this.readyPromise = new Promise((resolve) => {
|
|
9021
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
9218
9022
|
this.notifyReady = resolve;
|
|
9023
|
+
this.rejectReady = reject;
|
|
9024
|
+
});
|
|
9025
|
+
frame.postRender(() => {
|
|
9026
|
+
this.start().then(this.notifyReady).catch(this.rejectReady);
|
|
9219
9027
|
});
|
|
9220
|
-
// Queue execution on microtask to allow builder methods to be called
|
|
9221
|
-
queueMicrotask(() => this.execute());
|
|
9222
9028
|
}
|
|
9223
|
-
shared(id,
|
|
9224
|
-
this.sharedTransitions.set(id,
|
|
9029
|
+
shared(id, transition) {
|
|
9030
|
+
this.sharedTransitions.set(id, transition);
|
|
9225
9031
|
return this;
|
|
9226
9032
|
}
|
|
9227
|
-
then(
|
|
9228
|
-
return this.readyPromise.then(
|
|
9033
|
+
then(resolve, reject) {
|
|
9034
|
+
return this.readyPromise.then(resolve, reject);
|
|
9229
9035
|
}
|
|
9230
|
-
async
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
for (const node of context.nodes.values()) {
|
|
9241
|
-
node.isLayoutDirty = false;
|
|
9242
|
-
node.willUpdate();
|
|
9243
|
-
}
|
|
9244
|
-
}
|
|
9245
|
-
// Phase 2: Execute DOM update
|
|
9246
|
-
this.updateDom();
|
|
9247
|
-
// Phase 3: Post-mutation - Compare before/after elements
|
|
9248
|
-
const afterElements = getLayoutElements(this.scope);
|
|
9249
|
-
const beforeSet = new Set(beforeElements);
|
|
9250
|
-
const afterSet = new Set(afterElements);
|
|
9251
|
-
const entering = afterElements.filter((el) => !beforeSet.has(el));
|
|
9252
|
-
const exiting = beforeElements.filter((el) => !afterSet.has(el));
|
|
9253
|
-
// Build projection nodes for entering elements
|
|
9254
|
-
if (entering.length > 0) {
|
|
9255
|
-
context = buildProjectionTree(entering, context, this.getBuildOptions());
|
|
9256
|
-
}
|
|
9257
|
-
// No layout elements - return empty animation
|
|
9258
|
-
if (!context) {
|
|
9259
|
-
this.notifyReady(new GroupAnimation([]));
|
|
9260
|
-
return;
|
|
9261
|
-
}
|
|
9262
|
-
// Handle shared elements
|
|
9263
|
-
for (const element of exiting) {
|
|
9264
|
-
const node = context.nodes.get(element);
|
|
9265
|
-
node?.getStack()?.remove(node);
|
|
9266
|
-
}
|
|
9267
|
-
for (const element of entering) {
|
|
9268
|
-
context.nodes.get(element)?.promote();
|
|
9269
|
-
}
|
|
9270
|
-
// Phase 4: Animate
|
|
9271
|
-
context.root.didUpdate();
|
|
9272
|
-
await new Promise((resolve) => frame.postRender(() => resolve()));
|
|
9273
|
-
const animations = [];
|
|
9274
|
-
for (const node of context.nodes.values()) {
|
|
9275
|
-
if (node.currentAnimation) {
|
|
9276
|
-
animations.push(node.currentAnimation);
|
|
9277
|
-
}
|
|
9278
|
-
}
|
|
9279
|
-
const groupAnimation = new GroupAnimation(animations);
|
|
9280
|
-
groupAnimation.finished.then(() => {
|
|
9281
|
-
// Only clean up nodes for elements no longer in the document.
|
|
9282
|
-
// Elements still in DOM keep their nodes so subsequent animations
|
|
9283
|
-
// can use the stored position snapshots (A→B→A pattern).
|
|
9284
|
-
const elementsToCleanup = new Set();
|
|
9285
|
-
for (const element of context.nodes.keys()) {
|
|
9286
|
-
if (!document.contains(element)) {
|
|
9287
|
-
elementsToCleanup.add(element);
|
|
9036
|
+
async start() {
|
|
9037
|
+
const beforeElements = collectLayoutElements(this.scope);
|
|
9038
|
+
const beforeRecords = this.buildRecords(beforeElements);
|
|
9039
|
+
beforeRecords.forEach(({ projection }) => {
|
|
9040
|
+
const hasCurrentAnimation = Boolean(projection.currentAnimation);
|
|
9041
|
+
const isSharedLayout = Boolean(projection.options.layoutId);
|
|
9042
|
+
if (hasCurrentAnimation && isSharedLayout) {
|
|
9043
|
+
const snapshot = snapshotFromTarget(projection);
|
|
9044
|
+
if (snapshot) {
|
|
9045
|
+
projection.snapshot = snapshot;
|
|
9288
9046
|
}
|
|
9047
|
+
else if (projection.snapshot) {
|
|
9048
|
+
projection.snapshot = undefined;
|
|
9049
|
+
}
|
|
9050
|
+
}
|
|
9051
|
+
else if (projection.snapshot &&
|
|
9052
|
+
(projection.currentAnimation || projection.isProjecting())) {
|
|
9053
|
+
projection.snapshot = undefined;
|
|
9289
9054
|
}
|
|
9290
|
-
|
|
9055
|
+
projection.isPresent = true;
|
|
9056
|
+
projection.willUpdate();
|
|
9291
9057
|
});
|
|
9292
|
-
this.
|
|
9058
|
+
await this.updateDom();
|
|
9059
|
+
const afterElements = collectLayoutElements(this.scope);
|
|
9060
|
+
const afterRecords = this.buildRecords(afterElements);
|
|
9061
|
+
this.handleExitingElements(beforeRecords, afterRecords);
|
|
9062
|
+
afterRecords.forEach(({ projection }) => {
|
|
9063
|
+
const instance = projection.instance;
|
|
9064
|
+
const resumeFromInstance = projection.resumeFrom
|
|
9065
|
+
?.instance;
|
|
9066
|
+
if (!instance || !resumeFromInstance)
|
|
9067
|
+
return;
|
|
9068
|
+
if (!("style" in instance))
|
|
9069
|
+
return;
|
|
9070
|
+
const currentTransform = instance.style.transform;
|
|
9071
|
+
const resumeFromTransform = resumeFromInstance.style.transform;
|
|
9072
|
+
if (currentTransform &&
|
|
9073
|
+
resumeFromTransform &&
|
|
9074
|
+
currentTransform === resumeFromTransform) {
|
|
9075
|
+
instance.style.transform = "";
|
|
9076
|
+
instance.style.transformOrigin = "";
|
|
9077
|
+
}
|
|
9078
|
+
});
|
|
9079
|
+
afterRecords.forEach(({ projection }) => {
|
|
9080
|
+
projection.isPresent = true;
|
|
9081
|
+
});
|
|
9082
|
+
const root = getProjectionRoot(afterRecords, beforeRecords);
|
|
9083
|
+
root?.didUpdate();
|
|
9084
|
+
await new Promise((resolve) => {
|
|
9085
|
+
frame.postRender(() => resolve());
|
|
9086
|
+
});
|
|
9087
|
+
const animations = collectAnimations(afterRecords);
|
|
9088
|
+
const animation = new GroupAnimation(animations);
|
|
9089
|
+
return animation;
|
|
9293
9090
|
}
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
}
|
|
9300
|
-
|
|
9301
|
-
? this.sharedTransitions
|
|
9302
|
-
: undefined
|
|
9303
|
-
|
|
9091
|
+
buildRecords(elements) {
|
|
9092
|
+
const records = [];
|
|
9093
|
+
const recordMap = new Map();
|
|
9094
|
+
for (const element of elements) {
|
|
9095
|
+
const parentRecord = findParentRecord(element, recordMap, this.scope);
|
|
9096
|
+
const { layout, layoutId } = readLayoutAttributes(element);
|
|
9097
|
+
const override = layoutId
|
|
9098
|
+
? this.sharedTransitions.get(layoutId)
|
|
9099
|
+
: undefined;
|
|
9100
|
+
const transition = override || this.defaultOptions;
|
|
9101
|
+
const record = getOrCreateRecord(element, parentRecord?.projection, {
|
|
9102
|
+
layout,
|
|
9103
|
+
layoutId,
|
|
9104
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
9105
|
+
transition: transition,
|
|
9106
|
+
});
|
|
9107
|
+
recordMap.set(element, record);
|
|
9108
|
+
records.push(record);
|
|
9109
|
+
}
|
|
9110
|
+
return records;
|
|
9111
|
+
}
|
|
9112
|
+
handleExitingElements(beforeRecords, afterRecords) {
|
|
9113
|
+
const afterElementsSet = new Set(afterRecords.map((record) => record.element));
|
|
9114
|
+
beforeRecords.forEach((record) => {
|
|
9115
|
+
if (afterElementsSet.has(record.element))
|
|
9116
|
+
return;
|
|
9117
|
+
// For shared layout elements, relegate to set up resumeFrom
|
|
9118
|
+
// so the remaining element animates from this position
|
|
9119
|
+
if (record.projection.options.layoutId) {
|
|
9120
|
+
record.projection.isPresent = false;
|
|
9121
|
+
record.projection.relegate();
|
|
9122
|
+
}
|
|
9123
|
+
record.visualElement.unmount();
|
|
9124
|
+
visualElementStore.delete(record.element);
|
|
9125
|
+
});
|
|
9126
|
+
// Clear resumeFrom on EXISTING nodes that point to unmounted projections
|
|
9127
|
+
// This prevents crossfade animation when the source element was removed entirely
|
|
9128
|
+
// But preserve resumeFrom for NEW nodes so they can animate from the old position
|
|
9129
|
+
// Also preserve resumeFrom for lead nodes that were just promoted via relegate
|
|
9130
|
+
const beforeElementsSet = new Set(beforeRecords.map((record) => record.element));
|
|
9131
|
+
afterRecords.forEach(({ element, projection }) => {
|
|
9132
|
+
if (beforeElementsSet.has(element) &&
|
|
9133
|
+
projection.resumeFrom &&
|
|
9134
|
+
!projection.resumeFrom.instance &&
|
|
9135
|
+
!projection.isLead()) {
|
|
9136
|
+
projection.resumeFrom = undefined;
|
|
9137
|
+
projection.snapshot = undefined;
|
|
9138
|
+
}
|
|
9139
|
+
});
|
|
9304
9140
|
}
|
|
9305
9141
|
}
|
|
9306
|
-
/**
|
|
9307
|
-
* Parse arguments for animateLayout overloads
|
|
9308
|
-
*/
|
|
9309
9142
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
9310
9143
|
// animateLayout(updateDom)
|
|
9311
9144
|
if (typeof scopeOrUpdateDom === "function") {
|
|
@@ -9319,11 +9152,98 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
|
9319
9152
|
const elements = resolveElements(scopeOrUpdateDom);
|
|
9320
9153
|
const scope = elements[0] || document;
|
|
9321
9154
|
return {
|
|
9322
|
-
scope
|
|
9155
|
+
scope,
|
|
9323
9156
|
updateDom: updateDomOrOptions,
|
|
9324
9157
|
defaultOptions: options,
|
|
9325
9158
|
};
|
|
9326
9159
|
}
|
|
9160
|
+
function collectLayoutElements(scope) {
|
|
9161
|
+
const elements = Array.from(scope.querySelectorAll(layoutSelector));
|
|
9162
|
+
if (scope instanceof Element && scope.matches(layoutSelector)) {
|
|
9163
|
+
if (!elements.includes(scope)) {
|
|
9164
|
+
elements.unshift(scope);
|
|
9165
|
+
}
|
|
9166
|
+
}
|
|
9167
|
+
return elements;
|
|
9168
|
+
}
|
|
9169
|
+
function readLayoutAttributes(element) {
|
|
9170
|
+
const layoutId = element.getAttribute("data-layout-id") || undefined;
|
|
9171
|
+
const rawLayout = element.getAttribute("data-layout");
|
|
9172
|
+
let layout;
|
|
9173
|
+
if (rawLayout === "" || rawLayout === "true") {
|
|
9174
|
+
layout = true;
|
|
9175
|
+
}
|
|
9176
|
+
else if (rawLayout) {
|
|
9177
|
+
layout = rawLayout;
|
|
9178
|
+
}
|
|
9179
|
+
return {
|
|
9180
|
+
layout,
|
|
9181
|
+
layoutId,
|
|
9182
|
+
};
|
|
9183
|
+
}
|
|
9184
|
+
function createVisualState() {
|
|
9185
|
+
return {
|
|
9186
|
+
latestValues: {},
|
|
9187
|
+
renderState: {
|
|
9188
|
+
transform: {},
|
|
9189
|
+
transformOrigin: {},
|
|
9190
|
+
style: {},
|
|
9191
|
+
vars: {},
|
|
9192
|
+
},
|
|
9193
|
+
};
|
|
9194
|
+
}
|
|
9195
|
+
function getOrCreateRecord(element, parentProjection, projectionOptions) {
|
|
9196
|
+
const existing = visualElementStore.get(element);
|
|
9197
|
+
const visualElement = existing ??
|
|
9198
|
+
new HTMLVisualElement({
|
|
9199
|
+
props: {},
|
|
9200
|
+
presenceContext: null,
|
|
9201
|
+
visualState: createVisualState(),
|
|
9202
|
+
}, { allowProjection: true });
|
|
9203
|
+
if (!existing || !visualElement.projection) {
|
|
9204
|
+
visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
|
|
9205
|
+
}
|
|
9206
|
+
visualElement.projection.setOptions({
|
|
9207
|
+
...projectionOptions,
|
|
9208
|
+
visualElement,
|
|
9209
|
+
});
|
|
9210
|
+
if (!visualElement.current) {
|
|
9211
|
+
visualElement.mount(element);
|
|
9212
|
+
}
|
|
9213
|
+
if (!existing) {
|
|
9214
|
+
visualElementStore.set(element, visualElement);
|
|
9215
|
+
}
|
|
9216
|
+
return {
|
|
9217
|
+
element,
|
|
9218
|
+
visualElement,
|
|
9219
|
+
projection: visualElement.projection,
|
|
9220
|
+
};
|
|
9221
|
+
}
|
|
9222
|
+
function findParentRecord(element, recordMap, scope) {
|
|
9223
|
+
let parent = element.parentElement;
|
|
9224
|
+
while (parent) {
|
|
9225
|
+
const record = recordMap.get(parent);
|
|
9226
|
+
if (record)
|
|
9227
|
+
return record;
|
|
9228
|
+
if (parent === scope)
|
|
9229
|
+
break;
|
|
9230
|
+
parent = parent.parentElement;
|
|
9231
|
+
}
|
|
9232
|
+
return undefined;
|
|
9233
|
+
}
|
|
9234
|
+
function getProjectionRoot(afterRecords, beforeRecords) {
|
|
9235
|
+
const record = afterRecords[0] || beforeRecords[0];
|
|
9236
|
+
return record?.projection.root;
|
|
9237
|
+
}
|
|
9238
|
+
function collectAnimations(afterRecords) {
|
|
9239
|
+
const animations = new Set();
|
|
9240
|
+
afterRecords.forEach((record) => {
|
|
9241
|
+
const animation = record.projection.currentAnimation;
|
|
9242
|
+
if (animation)
|
|
9243
|
+
animations.add(animation);
|
|
9244
|
+
});
|
|
9245
|
+
return Array.from(animations);
|
|
9246
|
+
}
|
|
9327
9247
|
|
|
9328
9248
|
/**
|
|
9329
9249
|
* @deprecated
|
|
@@ -9434,7 +9354,7 @@ exports.createAxisDelta = createAxisDelta;
|
|
|
9434
9354
|
exports.createBox = createBox;
|
|
9435
9355
|
exports.createDelta = createDelta;
|
|
9436
9356
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
9437
|
-
exports.createProjectionNode = createProjectionNode
|
|
9357
|
+
exports.createProjectionNode = createProjectionNode;
|
|
9438
9358
|
exports.createRenderBatcher = createRenderBatcher;
|
|
9439
9359
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
9440
9360
|
exports.defaultEasing = defaultEasing;
|