motion-dom 12.27.3-alpha.1 → 12.27.3-alpha.2

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,6 +7272,13 @@ 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
+ });
7275
7282
  this.prevLead = prevLead;
7276
7283
  this.lead = node;
7277
7284
  node.show();
@@ -8994,6 +9001,22 @@ const HTMLProjectionNode = createProjectionNode({
8994
9001
 
8995
9002
  const layoutSelector = "[data-layout], [data-layout-id]";
8996
9003
  const noop = () => { };
9004
+ function snapshotFromTarget(projection) {
9005
+ const target = projection.targetWithTransforms || projection.target;
9006
+ if (!target)
9007
+ return undefined;
9008
+ const measuredBox = createBox();
9009
+ const layoutBox = createBox();
9010
+ copyBoxInto(measuredBox, target);
9011
+ copyBoxInto(layoutBox, target);
9012
+ return {
9013
+ animationId: projection.root?.animationId ?? 0,
9014
+ measuredBox,
9015
+ layoutBox,
9016
+ latestValues: projection.animationValues || projection.latestValues || {},
9017
+ source: projection.id,
9018
+ };
9019
+ }
8997
9020
  class LayoutAnimationBuilder {
8998
9021
  constructor(scope, updateDom, defaultOptions) {
8999
9022
  this.sharedTransitions = new Map();
@@ -9006,7 +9029,7 @@ class LayoutAnimationBuilder {
9006
9029
  this.notifyReady = resolve;
9007
9030
  this.rejectReady = reject;
9008
9031
  });
9009
- microtask.read(() => {
9032
+ frame.postRender(() => {
9010
9033
  this.start().then(this.notifyReady).catch(this.rejectReady);
9011
9034
  });
9012
9035
  }
@@ -9022,7 +9045,21 @@ class LayoutAnimationBuilder {
9022
9045
  const beforeRecords = this.buildRecords(beforeElements);
9023
9046
  const exitCandidates = collectExitCandidates(beforeRecords);
9024
9047
  beforeRecords.forEach(({ projection }) => {
9025
- seedProjectionSnapshot(projection);
9048
+ const hasCurrentAnimation = Boolean(projection.currentAnimation);
9049
+ const isSharedLayout = Boolean(projection.options.layoutId);
9050
+ if (hasCurrentAnimation && isSharedLayout) {
9051
+ const snapshot = snapshotFromTarget(projection);
9052
+ if (snapshot) {
9053
+ projection.snapshot = snapshot;
9054
+ }
9055
+ else if (projection.snapshot) {
9056
+ projection.snapshot = undefined;
9057
+ }
9058
+ }
9059
+ else if (projection.snapshot &&
9060
+ (projection.currentAnimation || projection.isProjecting())) {
9061
+ projection.snapshot = undefined;
9062
+ }
9026
9063
  projection.isPresent = true;
9027
9064
  projection.willUpdate();
9028
9065
  });
@@ -9030,6 +9067,23 @@ class LayoutAnimationBuilder {
9030
9067
  const afterElements = collectLayoutElements(this.scope);
9031
9068
  const afterRecords = this.buildRecords(afterElements);
9032
9069
  const exitRecords = this.handleExitingElements(beforeRecords, afterRecords, exitCandidates);
9070
+ afterRecords.forEach(({ projection }) => {
9071
+ const instance = projection.instance;
9072
+ const resumeFromInstance = projection.resumeFrom
9073
+ ?.instance;
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
+ });
9033
9087
  afterRecords.forEach(({ projection }) => {
9034
9088
  projection.isPresent = true;
9035
9089
  });
@@ -9153,16 +9207,6 @@ function createVisualState() {
9153
9207
  },
9154
9208
  };
9155
9209
  }
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
9210
  function getOrCreateRecord(element, parentProjection, projectionOptions) {
9167
9211
  const existing = visualElementStore.get(element);
9168
9212
  const visualElement = existing ??