motion-dom 12.27.3-alpha.2 → 12.27.4
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 +307 -268
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/effects/svg/index.mjs +7 -4
- package/dist/es/effects/svg/index.mjs.map +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +83 -253
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/es/layout/get-layout-elements.mjs +19 -0
- package/dist/es/layout/get-layout-elements.mjs.map +1 -0
- package/dist/es/layout/projection-tree.mjs +202 -0
- package/dist/es/layout/projection-tree.mjs.map +1 -0
- 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/projection/shared/stack.mjs +0 -7
- package/dist/es/projection/shared/stack.mjs.map +1 -1
- package/dist/es/render/svg/utils/path.mjs +7 -8
- package/dist/es/render/svg/utils/path.mjs.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/motion-dom.dev.js +307 -268
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -4122,17 +4122,21 @@ const addStyleValue = (element, state, key, value) => {
|
|
|
4122
4122
|
const styleEffect = /*@__PURE__*/ createSelectorEffect(
|
|
4123
4123
|
/*@__PURE__*/ createEffect(addStyleValue));
|
|
4124
4124
|
|
|
4125
|
-
const toPx = px.transform;
|
|
4126
4125
|
function addSVGPathValue(element, state, key, value) {
|
|
4127
4126
|
frame.render(() => element.setAttribute("pathLength", "1"));
|
|
4128
4127
|
if (key === "pathOffset") {
|
|
4129
|
-
return state.set(key, value, () =>
|
|
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
|
+
});
|
|
4130
4133
|
}
|
|
4131
4134
|
else {
|
|
4132
4135
|
if (!state.get("stroke-dasharray")) {
|
|
4133
4136
|
state.set("stroke-dasharray", new MotionValue("1 1"), () => {
|
|
4134
4137
|
const { pathLength = 1, pathSpacing } = state.latest;
|
|
4135
|
-
|
|
4138
|
+
// Use unitless values to avoid Safari zoom bug
|
|
4139
|
+
element.setAttribute("stroke-dasharray", `${pathLength} ${pathSpacing ?? 1 - Number(pathLength)}`);
|
|
4136
4140
|
});
|
|
4137
4141
|
}
|
|
4138
4142
|
return state.set(key, value, undefined, state.get("stroke-dasharray"));
|
|
@@ -6335,6 +6339,9 @@ const camelKeys = {
|
|
|
6335
6339
|
* and stroke-dasharray attributes.
|
|
6336
6340
|
*
|
|
6337
6341
|
* 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.
|
|
6338
6345
|
*/
|
|
6339
6346
|
function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true) {
|
|
6340
6347
|
// Normalise path length by setting SVG attribute pathLength to 1
|
|
@@ -6342,12 +6349,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
6342
6349
|
// We use dash case when setting attributes directly to the DOM node and camel case
|
|
6343
6350
|
// when defining props on a React component.
|
|
6344
6351
|
const keys = useDashCase ? dashKeys : camelKeys;
|
|
6345
|
-
// Build the dash offset
|
|
6346
|
-
attrs[keys.offset] =
|
|
6347
|
-
// Build the dash array
|
|
6348
|
-
|
|
6349
|
-
const pathSpacing = px.transform(spacing);
|
|
6350
|
-
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
6352
|
+
// Build the dash offset (unitless to avoid Safari zoom bug)
|
|
6353
|
+
attrs[keys.offset] = `${-offset}`;
|
|
6354
|
+
// Build the dash array (unitless to avoid Safari zoom bug)
|
|
6355
|
+
attrs[keys.array] = `${length} ${spacing}`;
|
|
6351
6356
|
}
|
|
6352
6357
|
|
|
6353
6358
|
/**
|
|
@@ -7272,13 +7277,6 @@ class NodeStack {
|
|
|
7272
7277
|
const prevLead = this.lead;
|
|
7273
7278
|
if (node === prevLead)
|
|
7274
7279
|
return;
|
|
7275
|
-
console.log("[projection] promote", {
|
|
7276
|
-
layoutId: node.options.layoutId,
|
|
7277
|
-
node: node.id,
|
|
7278
|
-
prevLead: prevLead?.id,
|
|
7279
|
-
prevLeadSnapshot: Boolean(prevLead?.snapshot),
|
|
7280
|
-
prevLeadResumeFrom: Boolean(prevLead?.resumeFrom),
|
|
7281
|
-
});
|
|
7282
7280
|
this.prevLead = prevLead;
|
|
7283
7281
|
this.lead = node;
|
|
7284
7282
|
node.show();
|
|
@@ -7387,7 +7385,7 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7387
7385
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7388
7386
|
}
|
|
7389
7387
|
}
|
|
7390
|
-
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7388
|
+
function createProjectionNode$1({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7391
7389
|
return class ProjectionNode {
|
|
7392
7390
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7393
7391
|
/**
|
|
@@ -8944,7 +8942,7 @@ function checkNodeWasScrollRoot(node) {
|
|
|
8944
8942
|
return node !== node.root && node.scroll?.wasRoot;
|
|
8945
8943
|
}
|
|
8946
8944
|
|
|
8947
|
-
const DocumentProjectionNode = createProjectionNode({
|
|
8945
|
+
const DocumentProjectionNode = createProjectionNode$1({
|
|
8948
8946
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
8949
8947
|
measureScroll: () => ({
|
|
8950
8948
|
x: document.documentElement.scrollLeft || document.body.scrollLeft,
|
|
@@ -8979,7 +8977,7 @@ function nodeGroup() {
|
|
|
8979
8977
|
const rootProjectionNode = {
|
|
8980
8978
|
current: undefined,
|
|
8981
8979
|
};
|
|
8982
|
-
const HTMLProjectionNode = createProjectionNode({
|
|
8980
|
+
const HTMLProjectionNode = createProjectionNode$1({
|
|
8983
8981
|
measureScroll: (instance) => ({
|
|
8984
8982
|
x: instance.scrollLeft,
|
|
8985
8983
|
y: instance.scrollTop,
|
|
@@ -8999,160 +8997,315 @@ const HTMLProjectionNode = createProjectionNode({
|
|
|
8999
8997
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
9000
8998
|
});
|
|
9001
8999
|
|
|
9002
|
-
const
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
|
|
9006
|
-
if (
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
9000
|
+
const LAYOUT_SELECTOR = "[data-layout], [data-layout-id]";
|
|
9001
|
+
function getLayoutElements(scope) {
|
|
9002
|
+
const elements = Array.from(scope.querySelectorAll(LAYOUT_SELECTOR));
|
|
9003
|
+
// Include scope itself if it's an Element (not Document) and has layout attributes
|
|
9004
|
+
if (scope instanceof Element && hasLayout(scope)) {
|
|
9005
|
+
elements.unshift(scope);
|
|
9006
|
+
}
|
|
9007
|
+
return elements;
|
|
9008
|
+
}
|
|
9009
|
+
function getLayoutId(element) {
|
|
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
|
+
}
|
|
9012
9165
|
return {
|
|
9013
|
-
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
|
|
9017
|
-
source: projection.id,
|
|
9166
|
+
nodes,
|
|
9167
|
+
visualElements,
|
|
9168
|
+
group,
|
|
9169
|
+
root: root,
|
|
9018
9170
|
};
|
|
9019
9171
|
}
|
|
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
|
+
|
|
9020
9209
|
class LayoutAnimationBuilder {
|
|
9021
9210
|
constructor(scope, updateDom, defaultOptions) {
|
|
9022
9211
|
this.sharedTransitions = new Map();
|
|
9023
|
-
this.notifyReady = noop;
|
|
9024
|
-
this.
|
|
9212
|
+
this.notifyReady = motionUtils.noop;
|
|
9213
|
+
this.executed = false;
|
|
9025
9214
|
this.scope = scope;
|
|
9026
9215
|
this.updateDom = updateDom;
|
|
9027
9216
|
this.defaultOptions = defaultOptions;
|
|
9028
|
-
this.readyPromise = new Promise((resolve
|
|
9217
|
+
this.readyPromise = new Promise((resolve) => {
|
|
9029
9218
|
this.notifyReady = resolve;
|
|
9030
|
-
this.rejectReady = reject;
|
|
9031
|
-
});
|
|
9032
|
-
frame.postRender(() => {
|
|
9033
|
-
this.start().then(this.notifyReady).catch(this.rejectReady);
|
|
9034
9219
|
});
|
|
9220
|
+
// Queue execution on microtask to allow builder methods to be called
|
|
9221
|
+
queueMicrotask(() => this.execute());
|
|
9035
9222
|
}
|
|
9036
|
-
shared(id,
|
|
9037
|
-
this.sharedTransitions.set(id,
|
|
9223
|
+
shared(id, options) {
|
|
9224
|
+
this.sharedTransitions.set(id, options);
|
|
9038
9225
|
return this;
|
|
9039
9226
|
}
|
|
9040
|
-
then(
|
|
9041
|
-
return this.readyPromise.then(
|
|
9227
|
+
then(onfulfilled, onrejected) {
|
|
9228
|
+
return this.readyPromise.then(onfulfilled, onrejected);
|
|
9042
9229
|
}
|
|
9043
|
-
async
|
|
9044
|
-
|
|
9045
|
-
|
|
9046
|
-
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
if (!instance || !resumeFromInstance)
|
|
9075
|
-
return;
|
|
9076
|
-
if (!("style" in instance))
|
|
9077
|
-
return;
|
|
9078
|
-
const currentTransform = instance.style.transform;
|
|
9079
|
-
const resumeFromTransform = resumeFromInstance.style.transform;
|
|
9080
|
-
if (currentTransform &&
|
|
9081
|
-
resumeFromTransform &&
|
|
9082
|
-
currentTransform === resumeFromTransform) {
|
|
9083
|
-
instance.style.transform = "";
|
|
9084
|
-
instance.style.transformOrigin = "";
|
|
9085
|
-
}
|
|
9086
|
-
});
|
|
9087
|
-
afterRecords.forEach(({ projection }) => {
|
|
9088
|
-
projection.isPresent = true;
|
|
9089
|
-
});
|
|
9090
|
-
const root = getProjectionRoot(afterRecords, beforeRecords);
|
|
9091
|
-
root?.didUpdate();
|
|
9092
|
-
await new Promise((resolve) => {
|
|
9093
|
-
frame.postRender(() => resolve());
|
|
9094
|
-
});
|
|
9095
|
-
const animations = collectAnimations(afterRecords, exitRecords);
|
|
9096
|
-
const animation = new GroupAnimation(animations);
|
|
9097
|
-
if (exitRecords.length) {
|
|
9098
|
-
const cleanup = () => {
|
|
9099
|
-
exitRecords.forEach(({ element, visualElement }) => {
|
|
9100
|
-
if (element.isConnected) {
|
|
9101
|
-
element.remove();
|
|
9102
|
-
}
|
|
9103
|
-
visualElement.unmount();
|
|
9104
|
-
visualElementStore.delete(element);
|
|
9105
|
-
});
|
|
9106
|
-
};
|
|
9107
|
-
animation.finished.then(cleanup, cleanup);
|
|
9230
|
+
async execute() {
|
|
9231
|
+
if (this.executed)
|
|
9232
|
+
return;
|
|
9233
|
+
this.executed = true;
|
|
9234
|
+
let context;
|
|
9235
|
+
// Phase 1: Pre-mutation - Build projection tree and take snapshots
|
|
9236
|
+
const beforeElements = getLayoutElements(this.scope);
|
|
9237
|
+
if (beforeElements.length > 0) {
|
|
9238
|
+
context = buildProjectionTree(beforeElements, undefined, this.getBuildOptions());
|
|
9239
|
+
context.root.startUpdate();
|
|
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;
|
|
9108
9261
|
}
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
const recordMap = new Map();
|
|
9114
|
-
for (const element of elements) {
|
|
9115
|
-
const parentRecord = findParentRecord(element, recordMap, this.scope);
|
|
9116
|
-
const { layout, layoutId } = readLayoutAttributes(element);
|
|
9117
|
-
const override = layoutId
|
|
9118
|
-
? this.sharedTransitions.get(layoutId)
|
|
9119
|
-
: undefined;
|
|
9120
|
-
const transition = override || this.defaultOptions;
|
|
9121
|
-
const record = getOrCreateRecord(element, parentRecord?.projection, {
|
|
9122
|
-
layout,
|
|
9123
|
-
layoutId,
|
|
9124
|
-
animationType: typeof layout === "string" ? layout : "both",
|
|
9125
|
-
transition: transition,
|
|
9126
|
-
});
|
|
9127
|
-
recordMap.set(element, record);
|
|
9128
|
-
records.push(record);
|
|
9262
|
+
// Handle shared elements
|
|
9263
|
+
for (const element of exiting) {
|
|
9264
|
+
const node = context.nodes.get(element);
|
|
9265
|
+
node?.getStack()?.remove(node);
|
|
9129
9266
|
}
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
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);
|
|
9288
|
+
}
|
|
9150
9289
|
}
|
|
9151
|
-
|
|
9290
|
+
cleanupProjectionTree(context, elementsToCleanup);
|
|
9152
9291
|
});
|
|
9153
|
-
|
|
9292
|
+
this.notifyReady(groupAnimation);
|
|
9293
|
+
}
|
|
9294
|
+
getBuildOptions() {
|
|
9295
|
+
return {
|
|
9296
|
+
defaultTransition: this.defaultOptions || {
|
|
9297
|
+
duration: 0.3,
|
|
9298
|
+
ease: "easeOut",
|
|
9299
|
+
},
|
|
9300
|
+
sharedTransitions: this.sharedTransitions.size > 0
|
|
9301
|
+
? this.sharedTransitions
|
|
9302
|
+
: undefined,
|
|
9303
|
+
};
|
|
9154
9304
|
}
|
|
9155
9305
|
}
|
|
9306
|
+
/**
|
|
9307
|
+
* Parse arguments for animateLayout overloads
|
|
9308
|
+
*/
|
|
9156
9309
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
9157
9310
|
// animateLayout(updateDom)
|
|
9158
9311
|
if (typeof scopeOrUpdateDom === "function") {
|
|
@@ -9166,125 +9319,11 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
|
9166
9319
|
const elements = resolveElements(scopeOrUpdateDom);
|
|
9167
9320
|
const scope = elements[0] || document;
|
|
9168
9321
|
return {
|
|
9169
|
-
scope,
|
|
9322
|
+
scope: scope instanceof Document ? scope : scope,
|
|
9170
9323
|
updateDom: updateDomOrOptions,
|
|
9171
9324
|
defaultOptions: options,
|
|
9172
9325
|
};
|
|
9173
9326
|
}
|
|
9174
|
-
function collectLayoutElements(scope) {
|
|
9175
|
-
const elements = Array.from(scope.querySelectorAll(layoutSelector));
|
|
9176
|
-
if (scope instanceof Element && scope.matches(layoutSelector)) {
|
|
9177
|
-
if (!elements.includes(scope)) {
|
|
9178
|
-
elements.unshift(scope);
|
|
9179
|
-
}
|
|
9180
|
-
}
|
|
9181
|
-
return elements;
|
|
9182
|
-
}
|
|
9183
|
-
function readLayoutAttributes(element) {
|
|
9184
|
-
const layoutId = element.getAttribute("data-layout-id") || undefined;
|
|
9185
|
-
const rawLayout = element.getAttribute("data-layout");
|
|
9186
|
-
let layout;
|
|
9187
|
-
if (rawLayout === "" || rawLayout === "true") {
|
|
9188
|
-
layout = true;
|
|
9189
|
-
}
|
|
9190
|
-
else if (rawLayout) {
|
|
9191
|
-
layout = rawLayout;
|
|
9192
|
-
}
|
|
9193
|
-
return {
|
|
9194
|
-
layout,
|
|
9195
|
-
layoutId,
|
|
9196
|
-
layoutExit: element.hasAttribute("data-layout-exit"),
|
|
9197
|
-
};
|
|
9198
|
-
}
|
|
9199
|
-
function createVisualState() {
|
|
9200
|
-
return {
|
|
9201
|
-
latestValues: {},
|
|
9202
|
-
renderState: {
|
|
9203
|
-
transform: {},
|
|
9204
|
-
transformOrigin: {},
|
|
9205
|
-
style: {},
|
|
9206
|
-
vars: {},
|
|
9207
|
-
},
|
|
9208
|
-
};
|
|
9209
|
-
}
|
|
9210
|
-
function getOrCreateRecord(element, parentProjection, projectionOptions) {
|
|
9211
|
-
const existing = visualElementStore.get(element);
|
|
9212
|
-
const visualElement = existing ??
|
|
9213
|
-
new HTMLVisualElement({
|
|
9214
|
-
props: {},
|
|
9215
|
-
presenceContext: null,
|
|
9216
|
-
visualState: createVisualState(),
|
|
9217
|
-
}, { allowProjection: true });
|
|
9218
|
-
if (!existing || !visualElement.projection) {
|
|
9219
|
-
visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
|
|
9220
|
-
}
|
|
9221
|
-
visualElement.projection.setOptions({
|
|
9222
|
-
...projectionOptions,
|
|
9223
|
-
visualElement,
|
|
9224
|
-
});
|
|
9225
|
-
if (!visualElement.current) {
|
|
9226
|
-
visualElement.mount(element);
|
|
9227
|
-
}
|
|
9228
|
-
if (!existing) {
|
|
9229
|
-
visualElementStore.set(element, visualElement);
|
|
9230
|
-
}
|
|
9231
|
-
return {
|
|
9232
|
-
element,
|
|
9233
|
-
visualElement,
|
|
9234
|
-
projection: visualElement.projection,
|
|
9235
|
-
};
|
|
9236
|
-
}
|
|
9237
|
-
function findParentRecord(element, recordMap, scope) {
|
|
9238
|
-
let parent = element.parentElement;
|
|
9239
|
-
while (parent) {
|
|
9240
|
-
const record = recordMap.get(parent);
|
|
9241
|
-
if (record)
|
|
9242
|
-
return record;
|
|
9243
|
-
if (parent === scope)
|
|
9244
|
-
break;
|
|
9245
|
-
parent = parent.parentElement;
|
|
9246
|
-
}
|
|
9247
|
-
return undefined;
|
|
9248
|
-
}
|
|
9249
|
-
function collectExitCandidates(records) {
|
|
9250
|
-
const exitCandidates = new Map();
|
|
9251
|
-
records.forEach((record) => {
|
|
9252
|
-
const { layoutExit } = readLayoutAttributes(record.element);
|
|
9253
|
-
if (!layoutExit)
|
|
9254
|
-
return;
|
|
9255
|
-
exitCandidates.set(record.element, {
|
|
9256
|
-
...record,
|
|
9257
|
-
parent: record.element.parentNode,
|
|
9258
|
-
nextSibling: record.element.nextSibling,
|
|
9259
|
-
});
|
|
9260
|
-
});
|
|
9261
|
-
return exitCandidates;
|
|
9262
|
-
}
|
|
9263
|
-
function reinstateExitElement(record) {
|
|
9264
|
-
if (!record.parent)
|
|
9265
|
-
return;
|
|
9266
|
-
if (record.nextSibling && record.nextSibling.parentNode === record.parent) {
|
|
9267
|
-
record.parent.insertBefore(record.element, record.nextSibling);
|
|
9268
|
-
}
|
|
9269
|
-
else {
|
|
9270
|
-
record.parent.appendChild(record.element);
|
|
9271
|
-
}
|
|
9272
|
-
}
|
|
9273
|
-
function getProjectionRoot(afterRecords, beforeRecords) {
|
|
9274
|
-
const record = afterRecords[0] || beforeRecords[0];
|
|
9275
|
-
return record?.projection.root;
|
|
9276
|
-
}
|
|
9277
|
-
function collectAnimations(afterRecords, exitRecords) {
|
|
9278
|
-
const animations = new Set();
|
|
9279
|
-
const addAnimation = (record) => {
|
|
9280
|
-
const animation = record.projection.currentAnimation;
|
|
9281
|
-
if (animation)
|
|
9282
|
-
animations.add(animation);
|
|
9283
|
-
};
|
|
9284
|
-
afterRecords.forEach(addAnimation);
|
|
9285
|
-
exitRecords.forEach(addAnimation);
|
|
9286
|
-
return Array.from(animations);
|
|
9287
|
-
}
|
|
9288
9327
|
|
|
9289
9328
|
/**
|
|
9290
9329
|
* @deprecated
|
|
@@ -9395,7 +9434,7 @@ exports.createAxisDelta = createAxisDelta;
|
|
|
9395
9434
|
exports.createBox = createBox;
|
|
9396
9435
|
exports.createDelta = createDelta;
|
|
9397
9436
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
9398
|
-
exports.createProjectionNode = createProjectionNode;
|
|
9437
|
+
exports.createProjectionNode = createProjectionNode$1;
|
|
9399
9438
|
exports.createRenderBatcher = createRenderBatcher;
|
|
9400
9439
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
9401
9440
|
exports.defaultEasing = defaultEasing;
|