motion-dom 12.27.3-alpha.1 → 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 +310 -227
- 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 +84 -216
- 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/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 +310 -227
- 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
|
/**
|
|
@@ -7380,7 +7385,7 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7380
7385
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7381
7386
|
}
|
|
7382
7387
|
}
|
|
7383
|
-
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7388
|
+
function createProjectionNode$1({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7384
7389
|
return class ProjectionNode {
|
|
7385
7390
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7386
7391
|
/**
|
|
@@ -8937,7 +8942,7 @@ function checkNodeWasScrollRoot(node) {
|
|
|
8937
8942
|
return node !== node.root && node.scroll?.wasRoot;
|
|
8938
8943
|
}
|
|
8939
8944
|
|
|
8940
|
-
const DocumentProjectionNode = createProjectionNode({
|
|
8945
|
+
const DocumentProjectionNode = createProjectionNode$1({
|
|
8941
8946
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
8942
8947
|
measureScroll: () => ({
|
|
8943
8948
|
x: document.documentElement.scrollLeft || document.body.scrollLeft,
|
|
@@ -8972,7 +8977,7 @@ function nodeGroup() {
|
|
|
8972
8977
|
const rootProjectionNode = {
|
|
8973
8978
|
current: undefined,
|
|
8974
8979
|
};
|
|
8975
|
-
const HTMLProjectionNode = createProjectionNode({
|
|
8980
|
+
const HTMLProjectionNode = createProjectionNode$1({
|
|
8976
8981
|
measureScroll: (instance) => ({
|
|
8977
8982
|
x: instance.scrollLeft,
|
|
8978
8983
|
y: instance.scrollTop,
|
|
@@ -8992,113 +8997,315 @@ const HTMLProjectionNode = createProjectionNode({
|
|
|
8992
8997
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
8993
8998
|
});
|
|
8994
8999
|
|
|
8995
|
-
const
|
|
8996
|
-
|
|
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
|
+
}
|
|
9165
|
+
return {
|
|
9166
|
+
nodes,
|
|
9167
|
+
visualElements,
|
|
9168
|
+
group,
|
|
9169
|
+
root: root,
|
|
9170
|
+
};
|
|
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
|
+
|
|
8997
9209
|
class LayoutAnimationBuilder {
|
|
8998
9210
|
constructor(scope, updateDom, defaultOptions) {
|
|
8999
9211
|
this.sharedTransitions = new Map();
|
|
9000
|
-
this.notifyReady = noop;
|
|
9001
|
-
this.
|
|
9212
|
+
this.notifyReady = motionUtils.noop;
|
|
9213
|
+
this.executed = false;
|
|
9002
9214
|
this.scope = scope;
|
|
9003
9215
|
this.updateDom = updateDom;
|
|
9004
9216
|
this.defaultOptions = defaultOptions;
|
|
9005
|
-
this.readyPromise = new Promise((resolve
|
|
9217
|
+
this.readyPromise = new Promise((resolve) => {
|
|
9006
9218
|
this.notifyReady = resolve;
|
|
9007
|
-
this.rejectReady = reject;
|
|
9008
|
-
});
|
|
9009
|
-
microtask.read(() => {
|
|
9010
|
-
this.start().then(this.notifyReady).catch(this.rejectReady);
|
|
9011
9219
|
});
|
|
9220
|
+
// Queue execution on microtask to allow builder methods to be called
|
|
9221
|
+
queueMicrotask(() => this.execute());
|
|
9012
9222
|
}
|
|
9013
|
-
shared(id,
|
|
9014
|
-
this.sharedTransitions.set(id,
|
|
9223
|
+
shared(id, options) {
|
|
9224
|
+
this.sharedTransitions.set(id, options);
|
|
9015
9225
|
return this;
|
|
9016
9226
|
}
|
|
9017
|
-
then(
|
|
9018
|
-
return this.readyPromise.then(
|
|
9227
|
+
then(onfulfilled, onrejected) {
|
|
9228
|
+
return this.readyPromise.then(onfulfilled, onrejected);
|
|
9019
9229
|
}
|
|
9020
|
-
async
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9037
|
-
|
|
9038
|
-
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
const
|
|
9042
|
-
const
|
|
9043
|
-
|
|
9044
|
-
|
|
9045
|
-
|
|
9046
|
-
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
});
|
|
9052
|
-
};
|
|
9053
|
-
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;
|
|
9054
9261
|
}
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
const recordMap = new Map();
|
|
9060
|
-
for (const element of elements) {
|
|
9061
|
-
const parentRecord = findParentRecord(element, recordMap, this.scope);
|
|
9062
|
-
const { layout, layoutId } = readLayoutAttributes(element);
|
|
9063
|
-
const override = layoutId
|
|
9064
|
-
? this.sharedTransitions.get(layoutId)
|
|
9065
|
-
: undefined;
|
|
9066
|
-
const transition = override || this.defaultOptions;
|
|
9067
|
-
const record = getOrCreateRecord(element, parentRecord?.projection, {
|
|
9068
|
-
layout,
|
|
9069
|
-
layoutId,
|
|
9070
|
-
animationType: typeof layout === "string" ? layout : "both",
|
|
9071
|
-
transition: transition,
|
|
9072
|
-
});
|
|
9073
|
-
recordMap.set(element, record);
|
|
9074
|
-
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);
|
|
9075
9266
|
}
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
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
|
+
}
|
|
9096
9289
|
}
|
|
9097
|
-
|
|
9290
|
+
cleanupProjectionTree(context, elementsToCleanup);
|
|
9098
9291
|
});
|
|
9099
|
-
|
|
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
|
+
};
|
|
9100
9304
|
}
|
|
9101
9305
|
}
|
|
9306
|
+
/**
|
|
9307
|
+
* Parse arguments for animateLayout overloads
|
|
9308
|
+
*/
|
|
9102
9309
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
9103
9310
|
// animateLayout(updateDom)
|
|
9104
9311
|
if (typeof scopeOrUpdateDom === "function") {
|
|
@@ -9112,135 +9319,11 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
|
9112
9319
|
const elements = resolveElements(scopeOrUpdateDom);
|
|
9113
9320
|
const scope = elements[0] || document;
|
|
9114
9321
|
return {
|
|
9115
|
-
scope,
|
|
9322
|
+
scope: scope instanceof Document ? scope : scope,
|
|
9116
9323
|
updateDom: updateDomOrOptions,
|
|
9117
9324
|
defaultOptions: options,
|
|
9118
9325
|
};
|
|
9119
9326
|
}
|
|
9120
|
-
function collectLayoutElements(scope) {
|
|
9121
|
-
const elements = Array.from(scope.querySelectorAll(layoutSelector));
|
|
9122
|
-
if (scope instanceof Element && scope.matches(layoutSelector)) {
|
|
9123
|
-
if (!elements.includes(scope)) {
|
|
9124
|
-
elements.unshift(scope);
|
|
9125
|
-
}
|
|
9126
|
-
}
|
|
9127
|
-
return elements;
|
|
9128
|
-
}
|
|
9129
|
-
function readLayoutAttributes(element) {
|
|
9130
|
-
const layoutId = element.getAttribute("data-layout-id") || undefined;
|
|
9131
|
-
const rawLayout = element.getAttribute("data-layout");
|
|
9132
|
-
let layout;
|
|
9133
|
-
if (rawLayout === "" || rawLayout === "true") {
|
|
9134
|
-
layout = true;
|
|
9135
|
-
}
|
|
9136
|
-
else if (rawLayout) {
|
|
9137
|
-
layout = rawLayout;
|
|
9138
|
-
}
|
|
9139
|
-
return {
|
|
9140
|
-
layout,
|
|
9141
|
-
layoutId,
|
|
9142
|
-
layoutExit: element.hasAttribute("data-layout-exit"),
|
|
9143
|
-
};
|
|
9144
|
-
}
|
|
9145
|
-
function createVisualState() {
|
|
9146
|
-
return {
|
|
9147
|
-
latestValues: {},
|
|
9148
|
-
renderState: {
|
|
9149
|
-
transform: {},
|
|
9150
|
-
transformOrigin: {},
|
|
9151
|
-
style: {},
|
|
9152
|
-
vars: {},
|
|
9153
|
-
},
|
|
9154
|
-
};
|
|
9155
|
-
}
|
|
9156
|
-
function seedProjectionSnapshot(projection) {
|
|
9157
|
-
const projectionNode = projection;
|
|
9158
|
-
if (!projectionNode.currentAnimation && !projectionNode.pendingAnimation) {
|
|
9159
|
-
return;
|
|
9160
|
-
}
|
|
9161
|
-
const snapshot = projection.measure(false);
|
|
9162
|
-
snapshot.latestValues =
|
|
9163
|
-
projectionNode.animationValues || projection.latestValues;
|
|
9164
|
-
projection.snapshot = snapshot;
|
|
9165
|
-
}
|
|
9166
|
-
function getOrCreateRecord(element, parentProjection, projectionOptions) {
|
|
9167
|
-
const existing = visualElementStore.get(element);
|
|
9168
|
-
const visualElement = existing ??
|
|
9169
|
-
new HTMLVisualElement({
|
|
9170
|
-
props: {},
|
|
9171
|
-
presenceContext: null,
|
|
9172
|
-
visualState: createVisualState(),
|
|
9173
|
-
}, { allowProjection: true });
|
|
9174
|
-
if (!existing || !visualElement.projection) {
|
|
9175
|
-
visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
|
|
9176
|
-
}
|
|
9177
|
-
visualElement.projection.setOptions({
|
|
9178
|
-
...projectionOptions,
|
|
9179
|
-
visualElement,
|
|
9180
|
-
});
|
|
9181
|
-
if (!visualElement.current) {
|
|
9182
|
-
visualElement.mount(element);
|
|
9183
|
-
}
|
|
9184
|
-
if (!existing) {
|
|
9185
|
-
visualElementStore.set(element, visualElement);
|
|
9186
|
-
}
|
|
9187
|
-
return {
|
|
9188
|
-
element,
|
|
9189
|
-
visualElement,
|
|
9190
|
-
projection: visualElement.projection,
|
|
9191
|
-
};
|
|
9192
|
-
}
|
|
9193
|
-
function findParentRecord(element, recordMap, scope) {
|
|
9194
|
-
let parent = element.parentElement;
|
|
9195
|
-
while (parent) {
|
|
9196
|
-
const record = recordMap.get(parent);
|
|
9197
|
-
if (record)
|
|
9198
|
-
return record;
|
|
9199
|
-
if (parent === scope)
|
|
9200
|
-
break;
|
|
9201
|
-
parent = parent.parentElement;
|
|
9202
|
-
}
|
|
9203
|
-
return undefined;
|
|
9204
|
-
}
|
|
9205
|
-
function collectExitCandidates(records) {
|
|
9206
|
-
const exitCandidates = new Map();
|
|
9207
|
-
records.forEach((record) => {
|
|
9208
|
-
const { layoutExit } = readLayoutAttributes(record.element);
|
|
9209
|
-
if (!layoutExit)
|
|
9210
|
-
return;
|
|
9211
|
-
exitCandidates.set(record.element, {
|
|
9212
|
-
...record,
|
|
9213
|
-
parent: record.element.parentNode,
|
|
9214
|
-
nextSibling: record.element.nextSibling,
|
|
9215
|
-
});
|
|
9216
|
-
});
|
|
9217
|
-
return exitCandidates;
|
|
9218
|
-
}
|
|
9219
|
-
function reinstateExitElement(record) {
|
|
9220
|
-
if (!record.parent)
|
|
9221
|
-
return;
|
|
9222
|
-
if (record.nextSibling && record.nextSibling.parentNode === record.parent) {
|
|
9223
|
-
record.parent.insertBefore(record.element, record.nextSibling);
|
|
9224
|
-
}
|
|
9225
|
-
else {
|
|
9226
|
-
record.parent.appendChild(record.element);
|
|
9227
|
-
}
|
|
9228
|
-
}
|
|
9229
|
-
function getProjectionRoot(afterRecords, beforeRecords) {
|
|
9230
|
-
const record = afterRecords[0] || beforeRecords[0];
|
|
9231
|
-
return record?.projection.root;
|
|
9232
|
-
}
|
|
9233
|
-
function collectAnimations(afterRecords, exitRecords) {
|
|
9234
|
-
const animations = new Set();
|
|
9235
|
-
const addAnimation = (record) => {
|
|
9236
|
-
const animation = record.projection.currentAnimation;
|
|
9237
|
-
if (animation)
|
|
9238
|
-
animations.add(animation);
|
|
9239
|
-
};
|
|
9240
|
-
afterRecords.forEach(addAnimation);
|
|
9241
|
-
exitRecords.forEach(addAnimation);
|
|
9242
|
-
return Array.from(animations);
|
|
9243
|
-
}
|
|
9244
9327
|
|
|
9245
9328
|
/**
|
|
9246
9329
|
* @deprecated
|
|
@@ -9351,7 +9434,7 @@ exports.createAxisDelta = createAxisDelta;
|
|
|
9351
9434
|
exports.createBox = createBox;
|
|
9352
9435
|
exports.createDelta = createDelta;
|
|
9353
9436
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
9354
|
-
exports.createProjectionNode = createProjectionNode;
|
|
9437
|
+
exports.createProjectionNode = createProjectionNode$1;
|
|
9355
9438
|
exports.createRenderBatcher = createRenderBatcher;
|
|
9356
9439
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
9357
9440
|
exports.defaultEasing = defaultEasing;
|