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