motion-dom 12.27.2 → 12.27.3-alpha.0
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 +207 -296
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/layout/LayoutAnimationBuilder.mjs +205 -84
- package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/motion-dom.dev.js +207 -296
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
- 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
|
@@ -7380,7 +7380,7 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
7380
7380
|
cancelTreeOptimisedTransformAnimations(parent);
|
|
7381
7381
|
}
|
|
7382
7382
|
}
|
|
7383
|
-
function createProjectionNode
|
|
7383
|
+
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
7384
7384
|
return class ProjectionNode {
|
|
7385
7385
|
constructor(latestValues = {}, parent = defaultParent?.()) {
|
|
7386
7386
|
/**
|
|
@@ -8937,7 +8937,7 @@ function checkNodeWasScrollRoot(node) {
|
|
|
8937
8937
|
return node !== node.root && node.scroll?.wasRoot;
|
|
8938
8938
|
}
|
|
8939
8939
|
|
|
8940
|
-
const DocumentProjectionNode = createProjectionNode
|
|
8940
|
+
const DocumentProjectionNode = createProjectionNode({
|
|
8941
8941
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
8942
8942
|
measureScroll: () => ({
|
|
8943
8943
|
x: document.documentElement.scrollLeft || document.body.scrollLeft,
|
|
@@ -8972,7 +8972,7 @@ function nodeGroup() {
|
|
|
8972
8972
|
const rootProjectionNode = {
|
|
8973
8973
|
current: undefined,
|
|
8974
8974
|
};
|
|
8975
|
-
const HTMLProjectionNode = createProjectionNode
|
|
8975
|
+
const HTMLProjectionNode = createProjectionNode({
|
|
8976
8976
|
measureScroll: (instance) => ({
|
|
8977
8977
|
x: instance.scrollLeft,
|
|
8978
8978
|
y: instance.scrollTop,
|
|
@@ -8992,315 +8992,112 @@ const HTMLProjectionNode = createProjectionNode$1({
|
|
|
8992
8992
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
8993
8993
|
});
|
|
8994
8994
|
|
|
8995
|
-
const
|
|
8996
|
-
|
|
8997
|
-
const elements = Array.from(scope.querySelectorAll(LAYOUT_SELECTOR));
|
|
8998
|
-
// Include scope itself if it's an Element (not Document) and has layout attributes
|
|
8999
|
-
if (scope instanceof Element && hasLayout(scope)) {
|
|
9000
|
-
elements.unshift(scope);
|
|
9001
|
-
}
|
|
9002
|
-
return elements;
|
|
9003
|
-
}
|
|
9004
|
-
function getLayoutId(element) {
|
|
9005
|
-
return element.getAttribute("data-layout-id");
|
|
9006
|
-
}
|
|
9007
|
-
function hasLayout(element) {
|
|
9008
|
-
return (element.hasAttribute("data-layout") ||
|
|
9009
|
-
element.hasAttribute("data-layout-id"));
|
|
9010
|
-
}
|
|
9011
|
-
|
|
9012
|
-
let scaleCorrectorAdded = false;
|
|
9013
|
-
/**
|
|
9014
|
-
* Track active projection nodes per element to handle animation interruption.
|
|
9015
|
-
* When a new animation starts on an element that already has an active animation,
|
|
9016
|
-
* we need to stop the old animation so the new one can start from the current
|
|
9017
|
-
* visual position.
|
|
9018
|
-
*/
|
|
9019
|
-
const activeProjectionNodes = new WeakMap();
|
|
9020
|
-
function ensureScaleCorrectors() {
|
|
9021
|
-
if (scaleCorrectorAdded)
|
|
9022
|
-
return;
|
|
9023
|
-
scaleCorrectorAdded = true;
|
|
9024
|
-
addScaleCorrector({
|
|
9025
|
-
borderRadius: {
|
|
9026
|
-
...correctBorderRadius,
|
|
9027
|
-
applyTo: [
|
|
9028
|
-
"borderTopLeftRadius",
|
|
9029
|
-
"borderTopRightRadius",
|
|
9030
|
-
"borderBottomLeftRadius",
|
|
9031
|
-
"borderBottomRightRadius",
|
|
9032
|
-
],
|
|
9033
|
-
},
|
|
9034
|
-
borderTopLeftRadius: correctBorderRadius,
|
|
9035
|
-
borderTopRightRadius: correctBorderRadius,
|
|
9036
|
-
borderBottomLeftRadius: correctBorderRadius,
|
|
9037
|
-
borderBottomRightRadius: correctBorderRadius,
|
|
9038
|
-
boxShadow: correctBoxShadow,
|
|
9039
|
-
});
|
|
9040
|
-
}
|
|
9041
|
-
/**
|
|
9042
|
-
* Get DOM depth of an element
|
|
9043
|
-
*/
|
|
9044
|
-
function getDepth(element) {
|
|
9045
|
-
let depth = 0;
|
|
9046
|
-
let current = element.parentElement;
|
|
9047
|
-
while (current) {
|
|
9048
|
-
depth++;
|
|
9049
|
-
current = current.parentElement;
|
|
9050
|
-
}
|
|
9051
|
-
return depth;
|
|
9052
|
-
}
|
|
9053
|
-
/**
|
|
9054
|
-
* Find the closest projection parent for an element
|
|
9055
|
-
*/
|
|
9056
|
-
function findProjectionParent(element, nodeCache) {
|
|
9057
|
-
let parent = element.parentElement;
|
|
9058
|
-
while (parent) {
|
|
9059
|
-
const node = nodeCache.get(parent);
|
|
9060
|
-
if (node)
|
|
9061
|
-
return node;
|
|
9062
|
-
parent = parent.parentElement;
|
|
9063
|
-
}
|
|
9064
|
-
return undefined;
|
|
9065
|
-
}
|
|
9066
|
-
/**
|
|
9067
|
-
* Create or reuse a projection node for an element
|
|
9068
|
-
*/
|
|
9069
|
-
function createProjectionNode(element, parent, options, transition) {
|
|
9070
|
-
// Check for existing active node - reuse it to preserve animation state
|
|
9071
|
-
const existingNode = activeProjectionNodes.get(element);
|
|
9072
|
-
if (existingNode) {
|
|
9073
|
-
const visualElement = existingNode.options.visualElement;
|
|
9074
|
-
// Update transition options for the new animation
|
|
9075
|
-
const nodeTransition = transition
|
|
9076
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9077
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9078
|
-
existingNode.setOptions({
|
|
9079
|
-
...existingNode.options,
|
|
9080
|
-
animate: true,
|
|
9081
|
-
transition: nodeTransition,
|
|
9082
|
-
...options,
|
|
9083
|
-
});
|
|
9084
|
-
// Re-mount the node if it was previously unmounted
|
|
9085
|
-
// This re-adds it to root.nodes so didUpdate() will process it
|
|
9086
|
-
if (!existingNode.instance) {
|
|
9087
|
-
existingNode.mount(element);
|
|
9088
|
-
}
|
|
9089
|
-
return { node: existingNode, visualElement };
|
|
9090
|
-
}
|
|
9091
|
-
// No existing node - create a new one
|
|
9092
|
-
const latestValues = {};
|
|
9093
|
-
const visualElement = new HTMLVisualElement({
|
|
9094
|
-
visualState: {
|
|
9095
|
-
latestValues,
|
|
9096
|
-
renderState: {
|
|
9097
|
-
transformOrigin: {},
|
|
9098
|
-
transform: {},
|
|
9099
|
-
style: {},
|
|
9100
|
-
vars: {},
|
|
9101
|
-
},
|
|
9102
|
-
},
|
|
9103
|
-
presenceContext: null,
|
|
9104
|
-
props: {},
|
|
9105
|
-
});
|
|
9106
|
-
const node = new HTMLProjectionNode(latestValues, parent);
|
|
9107
|
-
// Convert AnimationOptions to transition format for the projection system
|
|
9108
|
-
const nodeTransition = transition
|
|
9109
|
-
? { duration: transition.duration, ease: transition.ease }
|
|
9110
|
-
: { duration: 0.3, ease: "easeOut" };
|
|
9111
|
-
node.setOptions({
|
|
9112
|
-
visualElement,
|
|
9113
|
-
layout: true,
|
|
9114
|
-
animate: true,
|
|
9115
|
-
transition: nodeTransition,
|
|
9116
|
-
...options,
|
|
9117
|
-
});
|
|
9118
|
-
node.mount(element);
|
|
9119
|
-
visualElement.projection = node;
|
|
9120
|
-
// Track this node as the active one for this element
|
|
9121
|
-
activeProjectionNodes.set(element, node);
|
|
9122
|
-
return { node, visualElement };
|
|
9123
|
-
}
|
|
9124
|
-
/**
|
|
9125
|
-
* Build a projection tree from a list of elements
|
|
9126
|
-
*/
|
|
9127
|
-
function buildProjectionTree(elements, existingContext, options) {
|
|
9128
|
-
ensureScaleCorrectors();
|
|
9129
|
-
const nodes = existingContext?.nodes ?? new Map();
|
|
9130
|
-
const visualElements = existingContext?.visualElements ?? new Map();
|
|
9131
|
-
const group = existingContext?.group ?? nodeGroup();
|
|
9132
|
-
const defaultTransition = options?.defaultTransition;
|
|
9133
|
-
const sharedTransitions = options?.sharedTransitions;
|
|
9134
|
-
// Sort elements by DOM depth (parents before children)
|
|
9135
|
-
const sorted = [...elements].sort((a, b) => getDepth(a) - getDepth(b));
|
|
9136
|
-
let root = existingContext?.root;
|
|
9137
|
-
for (const element of sorted) {
|
|
9138
|
-
// Skip if already has a node
|
|
9139
|
-
if (nodes.has(element))
|
|
9140
|
-
continue;
|
|
9141
|
-
const parent = findProjectionParent(element, nodes);
|
|
9142
|
-
const layoutId = getLayoutId(element);
|
|
9143
|
-
const layoutMode = element.getAttribute("data-layout");
|
|
9144
|
-
const nodeOptions = {
|
|
9145
|
-
layoutId: layoutId ?? undefined,
|
|
9146
|
-
animationType: parseLayoutMode(layoutMode),
|
|
9147
|
-
};
|
|
9148
|
-
// Use layoutId-specific transition if available, otherwise use default
|
|
9149
|
-
const transition = layoutId && sharedTransitions?.get(layoutId)
|
|
9150
|
-
? sharedTransitions.get(layoutId)
|
|
9151
|
-
: defaultTransition;
|
|
9152
|
-
const { node, visualElement } = createProjectionNode(element, parent, nodeOptions, transition);
|
|
9153
|
-
nodes.set(element, node);
|
|
9154
|
-
visualElements.set(element, visualElement);
|
|
9155
|
-
group.add(node);
|
|
9156
|
-
if (!root) {
|
|
9157
|
-
root = node.root;
|
|
9158
|
-
}
|
|
9159
|
-
}
|
|
9160
|
-
return {
|
|
9161
|
-
nodes,
|
|
9162
|
-
visualElements,
|
|
9163
|
-
group,
|
|
9164
|
-
root: root,
|
|
9165
|
-
};
|
|
9166
|
-
}
|
|
9167
|
-
/**
|
|
9168
|
-
* Parse the data-layout attribute value
|
|
9169
|
-
*/
|
|
9170
|
-
function parseLayoutMode(value) {
|
|
9171
|
-
if (value === "position")
|
|
9172
|
-
return "position";
|
|
9173
|
-
if (value === "size")
|
|
9174
|
-
return "size";
|
|
9175
|
-
if (value === "preserve-aspect")
|
|
9176
|
-
return "preserve-aspect";
|
|
9177
|
-
return "both";
|
|
9178
|
-
}
|
|
9179
|
-
/**
|
|
9180
|
-
* Clean up projection nodes for specific elements.
|
|
9181
|
-
* If elementsToCleanup is provided, only those elements are cleaned up.
|
|
9182
|
-
* If not provided, all nodes are cleaned up.
|
|
9183
|
-
*
|
|
9184
|
-
* This allows persisting elements to keep their nodes between animations,
|
|
9185
|
-
* matching React's behavior where nodes persist for elements that remain in the DOM.
|
|
9186
|
-
*/
|
|
9187
|
-
function cleanupProjectionTree(context, elementsToCleanup) {
|
|
9188
|
-
const elementsToProcess = elementsToCleanup
|
|
9189
|
-
? [...context.nodes.entries()].filter(([el]) => elementsToCleanup.has(el))
|
|
9190
|
-
: [...context.nodes.entries()];
|
|
9191
|
-
for (const [element, node] of elementsToProcess) {
|
|
9192
|
-
context.group.remove(node);
|
|
9193
|
-
node.unmount();
|
|
9194
|
-
// Only clear from activeProjectionNodes if this is still the active node.
|
|
9195
|
-
// A newer animation might have already taken over.
|
|
9196
|
-
if (activeProjectionNodes.get(element) === node) {
|
|
9197
|
-
activeProjectionNodes.delete(element);
|
|
9198
|
-
}
|
|
9199
|
-
context.nodes.delete(element);
|
|
9200
|
-
context.visualElements.delete(element);
|
|
9201
|
-
}
|
|
9202
|
-
}
|
|
9203
|
-
|
|
8995
|
+
const layoutSelector = "[data-layout], [data-layout-id]";
|
|
8996
|
+
const noop = () => { };
|
|
9204
8997
|
class LayoutAnimationBuilder {
|
|
9205
8998
|
constructor(scope, updateDom, defaultOptions) {
|
|
9206
8999
|
this.sharedTransitions = new Map();
|
|
9207
|
-
this.notifyReady =
|
|
9208
|
-
this.
|
|
9000
|
+
this.notifyReady = noop;
|
|
9001
|
+
this.rejectReady = noop;
|
|
9209
9002
|
this.scope = scope;
|
|
9210
9003
|
this.updateDom = updateDom;
|
|
9211
9004
|
this.defaultOptions = defaultOptions;
|
|
9212
|
-
this.readyPromise = new Promise((resolve) => {
|
|
9005
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
9213
9006
|
this.notifyReady = resolve;
|
|
9007
|
+
this.rejectReady = reject;
|
|
9008
|
+
});
|
|
9009
|
+
microtask.read((_frameData) => {
|
|
9010
|
+
this.start().then(this.notifyReady).catch(this.rejectReady);
|
|
9214
9011
|
});
|
|
9215
|
-
// Queue execution on microtask to allow builder methods to be called
|
|
9216
|
-
queueMicrotask(() => this.execute());
|
|
9217
9012
|
}
|
|
9218
|
-
shared(id,
|
|
9219
|
-
this.sharedTransitions.set(id,
|
|
9013
|
+
shared(id, transition) {
|
|
9014
|
+
this.sharedTransitions.set(id, transition);
|
|
9220
9015
|
return this;
|
|
9221
9016
|
}
|
|
9222
|
-
then(
|
|
9223
|
-
return this.readyPromise.then(
|
|
9017
|
+
then(resolve, reject) {
|
|
9018
|
+
return this.readyPromise.then(resolve, reject);
|
|
9224
9019
|
}
|
|
9225
|
-
async
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
}
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
const
|
|
9246
|
-
const
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
for (const element of exiting) {
|
|
9259
|
-
const node = context.nodes.get(element);
|
|
9260
|
-
node?.getStack()?.remove(node);
|
|
9020
|
+
async start() {
|
|
9021
|
+
const beforeElements = collectLayoutElements(this.scope);
|
|
9022
|
+
const beforeRecords = this.buildRecords(beforeElements);
|
|
9023
|
+
const exitCandidates = collectExitCandidates(beforeRecords);
|
|
9024
|
+
beforeRecords.forEach(({ projection }) => {
|
|
9025
|
+
projection.isPresent = true;
|
|
9026
|
+
projection.willUpdate();
|
|
9027
|
+
});
|
|
9028
|
+
await this.updateDom();
|
|
9029
|
+
const afterElements = collectLayoutElements(this.scope);
|
|
9030
|
+
const afterRecords = this.buildRecords(afterElements);
|
|
9031
|
+
const exitRecords = this.handleExitingElements(beforeRecords, afterRecords, exitCandidates);
|
|
9032
|
+
afterRecords.forEach(({ projection }) => {
|
|
9033
|
+
projection.isPresent = true;
|
|
9034
|
+
});
|
|
9035
|
+
const root = getProjectionRoot(afterRecords, beforeRecords);
|
|
9036
|
+
root?.didUpdate();
|
|
9037
|
+
await new Promise((resolve) => {
|
|
9038
|
+
frame.postRender(() => resolve());
|
|
9039
|
+
});
|
|
9040
|
+
const animations = collectAnimations(afterRecords, exitRecords);
|
|
9041
|
+
const animation = new GroupAnimation(animations);
|
|
9042
|
+
if (exitRecords.length) {
|
|
9043
|
+
const cleanup = () => {
|
|
9044
|
+
exitRecords.forEach(({ element, visualElement }) => {
|
|
9045
|
+
if (element.isConnected) {
|
|
9046
|
+
element.remove();
|
|
9047
|
+
}
|
|
9048
|
+
visualElement.unmount();
|
|
9049
|
+
visualElementStore.delete(element);
|
|
9050
|
+
});
|
|
9051
|
+
};
|
|
9052
|
+
animation.finished.then(cleanup, cleanup);
|
|
9261
9053
|
}
|
|
9262
|
-
|
|
9263
|
-
|
|
9054
|
+
return animation;
|
|
9055
|
+
}
|
|
9056
|
+
buildRecords(elements) {
|
|
9057
|
+
const records = [];
|
|
9058
|
+
const recordMap = new Map();
|
|
9059
|
+
for (const element of elements) {
|
|
9060
|
+
const parentRecord = findParentRecord(element, recordMap, this.scope);
|
|
9061
|
+
const { layout, layoutId } = readLayoutAttributes(element);
|
|
9062
|
+
const override = layoutId
|
|
9063
|
+
? this.sharedTransitions.get(layoutId)
|
|
9064
|
+
: undefined;
|
|
9065
|
+
const transition = override || this.defaultOptions;
|
|
9066
|
+
const record = getOrCreateRecord(element, parentRecord?.projection, {
|
|
9067
|
+
layout,
|
|
9068
|
+
layoutId,
|
|
9069
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
9070
|
+
transition: transition,
|
|
9071
|
+
});
|
|
9072
|
+
recordMap.set(element, record);
|
|
9073
|
+
records.push(record);
|
|
9264
9074
|
}
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
const
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9075
|
+
return records;
|
|
9076
|
+
}
|
|
9077
|
+
handleExitingElements(beforeRecords, afterRecords, exitCandidates) {
|
|
9078
|
+
const afterElementsSet = new Set(afterRecords.map((record) => record.element));
|
|
9079
|
+
const exiting = [];
|
|
9080
|
+
beforeRecords.forEach((record) => {
|
|
9081
|
+
if (afterElementsSet.has(record.element))
|
|
9082
|
+
return;
|
|
9083
|
+
const exitRecord = exitCandidates.get(record.element);
|
|
9084
|
+
if (!exitRecord) {
|
|
9085
|
+
record.visualElement.unmount();
|
|
9086
|
+
visualElementStore.delete(record.element);
|
|
9087
|
+
return;
|
|
9088
|
+
}
|
|
9089
|
+
if (!exitRecord.element.isConnected) {
|
|
9090
|
+
reinstateExitElement(exitRecord);
|
|
9091
|
+
}
|
|
9092
|
+
record.projection.isPresent = false;
|
|
9093
|
+
if (record.projection.options.layoutId) {
|
|
9094
|
+
record.projection.relegate();
|
|
9284
9095
|
}
|
|
9285
|
-
|
|
9096
|
+
exiting.push(record);
|
|
9286
9097
|
});
|
|
9287
|
-
|
|
9288
|
-
}
|
|
9289
|
-
getBuildOptions() {
|
|
9290
|
-
return {
|
|
9291
|
-
defaultTransition: this.defaultOptions || {
|
|
9292
|
-
duration: 0.3,
|
|
9293
|
-
ease: "easeOut",
|
|
9294
|
-
},
|
|
9295
|
-
sharedTransitions: this.sharedTransitions.size > 0
|
|
9296
|
-
? this.sharedTransitions
|
|
9297
|
-
: undefined,
|
|
9298
|
-
};
|
|
9098
|
+
return exiting;
|
|
9299
9099
|
}
|
|
9300
9100
|
}
|
|
9301
|
-
/**
|
|
9302
|
-
* Parse arguments for animateLayout overloads
|
|
9303
|
-
*/
|
|
9304
9101
|
function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
9305
9102
|
// animateLayout(updateDom)
|
|
9306
9103
|
if (typeof scopeOrUpdateDom === "function") {
|
|
@@ -9314,11 +9111,125 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
|
9314
9111
|
const elements = resolveElements(scopeOrUpdateDom);
|
|
9315
9112
|
const scope = elements[0] || document;
|
|
9316
9113
|
return {
|
|
9317
|
-
scope
|
|
9114
|
+
scope,
|
|
9318
9115
|
updateDom: updateDomOrOptions,
|
|
9319
9116
|
defaultOptions: options,
|
|
9320
9117
|
};
|
|
9321
9118
|
}
|
|
9119
|
+
function collectLayoutElements(scope) {
|
|
9120
|
+
const elements = Array.from(scope.querySelectorAll(layoutSelector));
|
|
9121
|
+
if (scope instanceof Element && scope.matches(layoutSelector)) {
|
|
9122
|
+
if (!elements.includes(scope)) {
|
|
9123
|
+
elements.unshift(scope);
|
|
9124
|
+
}
|
|
9125
|
+
}
|
|
9126
|
+
return elements;
|
|
9127
|
+
}
|
|
9128
|
+
function readLayoutAttributes(element) {
|
|
9129
|
+
const layoutId = element.getAttribute("data-layout-id") || undefined;
|
|
9130
|
+
const rawLayout = element.getAttribute("data-layout");
|
|
9131
|
+
let layout;
|
|
9132
|
+
if (rawLayout === "" || rawLayout === "true") {
|
|
9133
|
+
layout = true;
|
|
9134
|
+
}
|
|
9135
|
+
else if (rawLayout) {
|
|
9136
|
+
layout = rawLayout;
|
|
9137
|
+
}
|
|
9138
|
+
return {
|
|
9139
|
+
layout,
|
|
9140
|
+
layoutId,
|
|
9141
|
+
layoutExit: element.hasAttribute("data-layout-exit"),
|
|
9142
|
+
};
|
|
9143
|
+
}
|
|
9144
|
+
function createVisualState() {
|
|
9145
|
+
return {
|
|
9146
|
+
latestValues: {},
|
|
9147
|
+
renderState: {
|
|
9148
|
+
transform: {},
|
|
9149
|
+
transformOrigin: {},
|
|
9150
|
+
style: {},
|
|
9151
|
+
vars: {},
|
|
9152
|
+
},
|
|
9153
|
+
};
|
|
9154
|
+
}
|
|
9155
|
+
function getOrCreateRecord(element, parentProjection, projectionOptions) {
|
|
9156
|
+
const existing = visualElementStore.get(element);
|
|
9157
|
+
const visualElement = existing ??
|
|
9158
|
+
new HTMLVisualElement({
|
|
9159
|
+
props: {},
|
|
9160
|
+
presenceContext: null,
|
|
9161
|
+
visualState: createVisualState(),
|
|
9162
|
+
}, { allowProjection: true });
|
|
9163
|
+
if (!existing || !visualElement.projection) {
|
|
9164
|
+
visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
|
|
9165
|
+
}
|
|
9166
|
+
visualElement.projection.setOptions({
|
|
9167
|
+
...projectionOptions,
|
|
9168
|
+
visualElement,
|
|
9169
|
+
});
|
|
9170
|
+
if (!visualElement.current) {
|
|
9171
|
+
visualElement.mount(element);
|
|
9172
|
+
}
|
|
9173
|
+
if (!existing) {
|
|
9174
|
+
visualElementStore.set(element, visualElement);
|
|
9175
|
+
}
|
|
9176
|
+
return {
|
|
9177
|
+
element,
|
|
9178
|
+
visualElement,
|
|
9179
|
+
projection: visualElement.projection,
|
|
9180
|
+
};
|
|
9181
|
+
}
|
|
9182
|
+
function findParentRecord(element, recordMap, scope) {
|
|
9183
|
+
let parent = element.parentElement;
|
|
9184
|
+
while (parent) {
|
|
9185
|
+
const record = recordMap.get(parent);
|
|
9186
|
+
if (record)
|
|
9187
|
+
return record;
|
|
9188
|
+
if (parent === scope)
|
|
9189
|
+
break;
|
|
9190
|
+
parent = parent.parentElement;
|
|
9191
|
+
}
|
|
9192
|
+
return undefined;
|
|
9193
|
+
}
|
|
9194
|
+
function collectExitCandidates(records) {
|
|
9195
|
+
const exitCandidates = new Map();
|
|
9196
|
+
records.forEach((record) => {
|
|
9197
|
+
const { layoutExit } = readLayoutAttributes(record.element);
|
|
9198
|
+
if (!layoutExit)
|
|
9199
|
+
return;
|
|
9200
|
+
exitCandidates.set(record.element, {
|
|
9201
|
+
...record,
|
|
9202
|
+
parent: record.element.parentNode,
|
|
9203
|
+
nextSibling: record.element.nextSibling,
|
|
9204
|
+
});
|
|
9205
|
+
});
|
|
9206
|
+
return exitCandidates;
|
|
9207
|
+
}
|
|
9208
|
+
function reinstateExitElement(record) {
|
|
9209
|
+
if (!record.parent)
|
|
9210
|
+
return;
|
|
9211
|
+
if (record.nextSibling && record.nextSibling.parentNode === record.parent) {
|
|
9212
|
+
record.parent.insertBefore(record.element, record.nextSibling);
|
|
9213
|
+
}
|
|
9214
|
+
else {
|
|
9215
|
+
record.parent.appendChild(record.element);
|
|
9216
|
+
}
|
|
9217
|
+
}
|
|
9218
|
+
function getProjectionRoot(afterRecords, beforeRecords) {
|
|
9219
|
+
const record = afterRecords[0] || beforeRecords[0];
|
|
9220
|
+
return record?.projection.root;
|
|
9221
|
+
}
|
|
9222
|
+
function collectAnimations(afterRecords, exitRecords) {
|
|
9223
|
+
const animations = new Set();
|
|
9224
|
+
const addAnimation = (record) => {
|
|
9225
|
+
const animation = record.projection.currentAnimation;
|
|
9226
|
+
if (animation)
|
|
9227
|
+
animations.add(animation);
|
|
9228
|
+
};
|
|
9229
|
+
afterRecords.forEach(addAnimation);
|
|
9230
|
+
exitRecords.forEach(addAnimation);
|
|
9231
|
+
return Array.from(animations);
|
|
9232
|
+
}
|
|
9322
9233
|
|
|
9323
9234
|
/**
|
|
9324
9235
|
* @deprecated
|
|
@@ -9429,7 +9340,7 @@ exports.createAxisDelta = createAxisDelta;
|
|
|
9429
9340
|
exports.createBox = createBox;
|
|
9430
9341
|
exports.createDelta = createDelta;
|
|
9431
9342
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
9432
|
-
exports.createProjectionNode = createProjectionNode
|
|
9343
|
+
exports.createProjectionNode = createProjectionNode;
|
|
9433
9344
|
exports.createRenderBatcher = createRenderBatcher;
|
|
9434
9345
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
9435
9346
|
exports.defaultEasing = defaultEasing;
|