motion-dom 12.28.1-alpha.0 → 12.28.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -7272,13 +7272,6 @@ class NodeStack {
7272
7272
  const prevLead = this.lead;
7273
7273
  if (node === prevLead)
7274
7274
  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
7275
  this.prevLead = prevLead;
7283
7276
  this.lead = node;
7284
7277
  node.show();
@@ -9043,7 +9036,6 @@ class LayoutAnimationBuilder {
9043
9036
  async start() {
9044
9037
  const beforeElements = collectLayoutElements(this.scope);
9045
9038
  const beforeRecords = this.buildRecords(beforeElements);
9046
- const exitCandidates = collectExitCandidates(beforeRecords);
9047
9039
  beforeRecords.forEach(({ projection }) => {
9048
9040
  const hasCurrentAnimation = Boolean(projection.currentAnimation);
9049
9041
  const isSharedLayout = Boolean(projection.options.layoutId);
@@ -9066,7 +9058,7 @@ class LayoutAnimationBuilder {
9066
9058
  await this.updateDom();
9067
9059
  const afterElements = collectLayoutElements(this.scope);
9068
9060
  const afterRecords = this.buildRecords(afterElements);
9069
- const exitRecords = this.handleExitingElements(beforeRecords, afterRecords, exitCandidates);
9061
+ this.handleExitingElements(beforeRecords, afterRecords);
9070
9062
  afterRecords.forEach(({ projection }) => {
9071
9063
  const instance = projection.instance;
9072
9064
  const resumeFromInstance = projection.resumeFrom
@@ -9092,20 +9084,8 @@ class LayoutAnimationBuilder {
9092
9084
  await new Promise((resolve) => {
9093
9085
  frame.postRender(() => resolve());
9094
9086
  });
9095
- const animations = collectAnimations(afterRecords, exitRecords);
9087
+ const animations = collectAnimations(afterRecords);
9096
9088
  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);
9108
- }
9109
9089
  return animation;
9110
9090
  }
9111
9091
  buildRecords(elements) {
@@ -9129,28 +9109,34 @@ class LayoutAnimationBuilder {
9129
9109
  }
9130
9110
  return records;
9131
9111
  }
9132
- handleExitingElements(beforeRecords, afterRecords, exitCandidates) {
9112
+ handleExitingElements(beforeRecords, afterRecords) {
9133
9113
  const afterElementsSet = new Set(afterRecords.map((record) => record.element));
9134
- const exiting = [];
9135
9114
  beforeRecords.forEach((record) => {
9136
9115
  if (afterElementsSet.has(record.element))
9137
9116
  return;
9138
- const exitRecord = exitCandidates.get(record.element);
9139
- if (!exitRecord) {
9140
- record.visualElement.unmount();
9141
- visualElementStore.delete(record.element);
9142
- return;
9143
- }
9144
- if (!exitRecord.element.isConnected) {
9145
- reinstateExitElement(exitRecord);
9146
- }
9147
- record.projection.isPresent = false;
9117
+ // For shared layout elements, relegate to set up resumeFrom
9118
+ // so the remaining element animates from this position
9148
9119
  if (record.projection.options.layoutId) {
9120
+ record.projection.isPresent = false;
9149
9121
  record.projection.relegate();
9150
9122
  }
9151
- exiting.push(record);
9123
+ record.visualElement.unmount();
9124
+ visualElementStore.delete(record.element);
9125
+ });
9126
+ // Clear resumeFrom on EXISTING nodes that point to unmounted projections
9127
+ // This prevents crossfade animation when the source element was removed entirely
9128
+ // But preserve resumeFrom for NEW nodes so they can animate from the old position
9129
+ // Also preserve resumeFrom for lead nodes that were just promoted via relegate
9130
+ const beforeElementsSet = new Set(beforeRecords.map((record) => record.element));
9131
+ afterRecords.forEach(({ element, projection }) => {
9132
+ if (beforeElementsSet.has(element) &&
9133
+ projection.resumeFrom &&
9134
+ !projection.resumeFrom.instance &&
9135
+ !projection.isLead()) {
9136
+ projection.resumeFrom = undefined;
9137
+ projection.snapshot = undefined;
9138
+ }
9152
9139
  });
9153
- return exiting;
9154
9140
  }
9155
9141
  }
9156
9142
  function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
@@ -9193,7 +9179,6 @@ function readLayoutAttributes(element) {
9193
9179
  return {
9194
9180
  layout,
9195
9181
  layoutId,
9196
- layoutExit: element.hasAttribute("data-layout-exit"),
9197
9182
  };
9198
9183
  }
9199
9184
  function createVisualState() {
@@ -9246,43 +9231,17 @@ function findParentRecord(element, recordMap, scope) {
9246
9231
  }
9247
9232
  return undefined;
9248
9233
  }
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
9234
  function getProjectionRoot(afterRecords, beforeRecords) {
9274
9235
  const record = afterRecords[0] || beforeRecords[0];
9275
9236
  return record?.projection.root;
9276
9237
  }
9277
- function collectAnimations(afterRecords, exitRecords) {
9238
+ function collectAnimations(afterRecords) {
9278
9239
  const animations = new Set();
9279
- const addAnimation = (record) => {
9240
+ afterRecords.forEach((record) => {
9280
9241
  const animation = record.projection.currentAnimation;
9281
9242
  if (animation)
9282
9243
  animations.add(animation);
9283
- };
9284
- afterRecords.forEach(addAnimation);
9285
- exitRecords.forEach(addAnimation);
9244
+ });
9286
9245
  return Array.from(animations);
9287
9246
  }
9288
9247