motion-dom 12.29.0 → 12.29.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.
@@ -19,6 +19,7 @@ function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
19
19
  }
20
20
  function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
21
21
  let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
22
+ const reduceMotion = transition?.reduceMotion;
22
23
  if (transitionOverride)
23
24
  transition = transitionOverride;
24
25
  const animations = [];
@@ -64,7 +65,8 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
64
65
  }
65
66
  }
66
67
  addValueToWillChange(visualElement, key);
67
- value.start(animateMotionValue(key, value, valueTarget, visualElement.shouldReduceMotion && positionalKeys.has(key)
68
+ const shouldReduceMotion = reduceMotion ?? visualElement.shouldReduceMotion;
69
+ value.start(animateMotionValue(key, value, valueTarget, shouldReduceMotion && positionalKeys.has(key)
68
70
  ? { type: false }
69
71
  : valueTransition, visualElement, isHandoff));
70
72
  const animation = value.animation;
@@ -1 +1 @@
1
- {"version":3,"file":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock =\n protectedKeys.hasOwnProperty(key) && needsAnimating[key] !== true\n\n needsAnimating[key] = false\n return shouldBlock\n}\n\nexport function animateTarget(\n visualElement: VisualElement,\n targetAndTransition: TargetAndTransition,\n { delay = 0, transitionOverride, type }: VisualElementAnimationOptions = {}\n): AnimationPlaybackControlsWithThen[] {\n let {\n transition = visualElement.getDefaultTransition(),\n transitionEnd,\n ...target\n } = targetAndTransition\n\n if (transitionOverride) transition = transitionOverride\n\n const animations: AnimationPlaybackControlsWithThen[] = []\n\n const animationTypeState =\n type &&\n visualElement.animationState &&\n visualElement.animationState.getState()[type]\n\n for (const key in target) {\n const value = visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? null\n )\n const valueTarget = target[key as keyof typeof target]\n\n if (\n valueTarget === undefined ||\n (animationTypeState &&\n shouldBlockAnimation(animationTypeState, key))\n ) {\n continue\n }\n\n const valueTransition = {\n delay,\n ...getValueTransition(transition || {}, key),\n }\n\n /**\n * If the value is already at the defined target, skip the animation.\n */\n const currentValue = value.get()\n if (\n currentValue !== undefined &&\n !value.isAnimating &&\n !Array.isArray(valueTarget) &&\n valueTarget === currentValue &&\n !valueTransition.velocity\n ) {\n continue\n }\n\n /**\n * If this is the first time a value is being animated, check\n * to see if we're handling off from an existing animation.\n */\n let isHandoff = false\n if (window.MotionHandoffAnimation) {\n const appearId = getOptimisedAppearId(visualElement)\n\n if (appearId) {\n const startTime = window.MotionHandoffAnimation(\n appearId,\n key,\n frame\n )\n\n if (startTime !== null) {\n valueTransition.startTime = startTime\n isHandoff = true\n }\n }\n }\n\n addValueToWillChange(visualElement, key)\n\n value.start(\n animateMotionValue(\n key,\n value,\n valueTarget,\n visualElement.shouldReduceMotion && positionalKeys.has(key)\n ? { type: false }\n : valueTransition,\n visualElement,\n isHandoff\n )\n )\n\n const animation = value.animation\n\n if (animation) {\n animations.push(animation)\n }\n }\n\n if (transitionEnd) {\n Promise.all(animations).then(() => {\n frame.update(() => {\n transitionEnd && setTarget(visualElement, transitionEnd)\n })\n })\n }\n\n return animations\n}\n"],"names":[],"mappings":";;;;;;;;AAaA;;;;;AAKG;AACH,SAAS,oBAAoB,CACzB,EAAE,aAAa,EAAE,cAAc,EAAsB,EACrD,GAAW,EAAA;AAEX,IAAA,MAAM,WAAW,GACb,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,IAAI,CAAA;AAErE,IAAA,cAAc,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAC3B,IAAA,OAAO,WAAW,CAAA;AACtB,CAAC;SAEe,aAAa,CACzB,aAA4B,EAC5B,mBAAwC,EACxC,EAAE,KAAK,GAAG,CAAC,EAAE,kBAAkB,EAAE,IAAI,KAAoC,EAAE,EAAA;AAE3E,IAAA,IAAI,EACA,UAAU,GAAG,aAAa,CAAC,oBAAoB,EAAE,EACjD,aAAa,EACb,GAAG,MAAM,EACZ,GAAG,mBAAmB,CAAA;AAEvB,IAAA,IAAI,kBAAkB;QAAE,UAAU,GAAG,kBAAkB,CAAA;IAEvD,MAAM,UAAU,GAAwC,EAAE,CAAA;IAE1D,MAAM,kBAAkB,GACpB,IAAI;AACJ,QAAA,aAAa,CAAC,cAAc;QAC5B,aAAa,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAA;AAEjD,IAAA,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;AACtB,QAAA,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAChC,GAAG,EACH,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,IAAI,CAC1C,CAAA;AACD,QAAA,MAAM,WAAW,GAAG,MAAM,CAAC,GAA0B,CAAC,CAAA;QAEtD,IACI,WAAW,KAAK,SAAS;AACzB,aAAC,k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K,CAAC,SAAS,CAAA;QAEjC,IAAI,SAAS,EAAE;AACX,YAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;SAC7B;KACJ;IAED,IAAI,aAAa,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,MAAK;AAC9B,YAAA,KAAK,CAAC,MAAM,CAAC,MAAK;AACd,gBAAA,aAAa,IAAI,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,CAAA;AAC5D,aAAC,CAAC,CAAA;AACN,SAAC,CAAC,CAAA;KACL;AAED,IAAA,OAAO,UAAU,CAAA;AACrB;;;;"}
1
+ {"version":3,"file":"visual-element-target.mjs","sources":["../../../../src/animation/interfaces/visual-element-target.ts"],"sourcesContent":["import { frame } from \"../../frameloop\"\nimport { getValueTransition } from \"../utils/get-value-transition\"\nimport { positionalKeys } from \"../../render/utils/keys-position\"\nimport { setTarget } from \"../../render/utils/setters\"\nimport { addValueToWillChange } from \"../../value/will-change/add-will-change\"\nimport { getOptimisedAppearId } from \"../optimized-appear/get-appear-id\"\nimport { animateMotionValue } from \"./motion-value\"\nimport type { VisualElementAnimationOptions } from \"./types\"\nimport type { AnimationPlaybackControlsWithThen } from \"../types\"\nimport type { TargetAndTransition } from \"../../node/types\"\nimport type { AnimationTypeState } from \"../../render/utils/animation-state\"\nimport type { VisualElement } from \"../../render/VisualElement\"\n\n/**\n * Decide whether we should block this animation. Previously, we achieved this\n * just by checking whether the key was listed in protectedKeys, but this\n * posed problems if an animation was triggered by afterChildren and protectedKeys\n * had been set to true in the meantime.\n */\nfunction shouldBlockAnimation(\n { protectedKeys, needsAnimating }: AnimationTypeState,\n key: string\n) {\n const shouldBlock =\n protectedKeys.hasOwnProperty(key) && needsAnimating[key] !== true\n\n needsAnimating[key] = false\n return shouldBlock\n}\n\nexport function animateTarget(\n visualElement: VisualElement,\n targetAndTransition: TargetAndTransition,\n { delay = 0, transitionOverride, type }: VisualElementAnimationOptions = {}\n): AnimationPlaybackControlsWithThen[] {\n let {\n transition = visualElement.getDefaultTransition(),\n transitionEnd,\n ...target\n } = targetAndTransition\n\n const reduceMotion = (transition as { reduceMotion?: boolean })?.reduceMotion\n\n if (transitionOverride) transition = transitionOverride\n\n const animations: AnimationPlaybackControlsWithThen[] = []\n\n const animationTypeState =\n type &&\n visualElement.animationState &&\n visualElement.animationState.getState()[type]\n\n for (const key in target) {\n const value = visualElement.getValue(\n key,\n visualElement.latestValues[key] ?? null\n )\n const valueTarget = target[key as keyof typeof target]\n\n if (\n valueTarget === undefined ||\n (animationTypeState &&\n shouldBlockAnimation(animationTypeState, key))\n ) {\n continue\n }\n\n const valueTransition = {\n delay,\n ...getValueTransition(transition || {}, key),\n }\n\n /**\n * If the value is already at the defined target, skip the animation.\n */\n const currentValue = value.get()\n if (\n currentValue !== undefined &&\n !value.isAnimating &&\n !Array.isArray(valueTarget) &&\n valueTarget === currentValue &&\n !valueTransition.velocity\n ) {\n continue\n }\n\n /**\n * If this is the first time a value is being animated, check\n * to see if we're handling off from an existing animation.\n */\n let isHandoff = false\n if (window.MotionHandoffAnimation) {\n const appearId = getOptimisedAppearId(visualElement)\n\n if (appearId) {\n const startTime = window.MotionHandoffAnimation(\n appearId,\n key,\n frame\n )\n\n if (startTime !== null) {\n valueTransition.startTime = startTime\n isHandoff = true\n }\n }\n }\n\n addValueToWillChange(visualElement, key)\n\n const shouldReduceMotion =\n reduceMotion ?? visualElement.shouldReduceMotion\n\n value.start(\n animateMotionValue(\n key,\n value,\n valueTarget,\n shouldReduceMotion && positionalKeys.has(key)\n ? { type: false }\n : valueTransition,\n visualElement,\n isHandoff\n )\n )\n\n const animation = value.animation\n\n if (animation) {\n animations.push(animation)\n }\n }\n\n if (transitionEnd) {\n Promise.all(animations).then(() => {\n frame.update(() => {\n transitionEnd && setTarget(visualElement, transitionEnd)\n })\n })\n }\n\n return animations\n}\n"],"names":[],"mappings":";;;;;;;;AAaA;;;;;AAKG;AACH,SAAS,oBAAoB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A;SAC7B;KACJ;IAED,IAAI,aAAa,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,MAAK;AAC9B,YAAA,KAAK,CAAC,MAAM,CAAC,MAAK;AACd,gBAAA,aAAa,IAAI,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,CAAA;AAC5D,aAAC,CAAC,CAAA;AACN,SAAC,CAAC,CAAA;KACL;AAED,IAAA,OAAO,UAAU,CAAA;AACrB;;;;"}
@@ -1,110 +1,159 @@
1
- import { noop } from 'motion-utils';
2
1
  import { GroupAnimation } from '../animation/GroupAnimation.mjs';
3
- import { getLayoutElements } from './get-layout-elements.mjs';
4
- import { buildProjectionTree, cleanupProjectionTree } from './projection-tree.mjs';
2
+ import { copyBoxInto } from '../projection/geometry/copy.mjs';
3
+ import { createBox } from '../projection/geometry/models.mjs';
4
+ import { HTMLProjectionNode } from '../projection/node/HTMLProjectionNode.mjs';
5
+ import { HTMLVisualElement } from '../render/html/HTMLVisualElement.mjs';
6
+ import { visualElementStore } from '../render/store.mjs';
5
7
  import { resolveElements } from '../utils/resolve-elements.mjs';
6
8
  import { frame } from '../frameloop/frame.mjs';
7
9
 
10
+ const layoutSelector = "[data-layout], [data-layout-id]";
11
+ const noop = () => { };
12
+ function snapshotFromTarget(projection) {
13
+ const target = projection.targetWithTransforms || projection.target;
14
+ if (!target)
15
+ return undefined;
16
+ const measuredBox = createBox();
17
+ const layoutBox = createBox();
18
+ copyBoxInto(measuredBox, target);
19
+ copyBoxInto(layoutBox, target);
20
+ return {
21
+ animationId: projection.root?.animationId ?? 0,
22
+ measuredBox,
23
+ layoutBox,
24
+ latestValues: projection.animationValues || projection.latestValues || {},
25
+ source: projection.id,
26
+ };
27
+ }
8
28
  class LayoutAnimationBuilder {
9
29
  constructor(scope, updateDom, defaultOptions) {
10
30
  this.sharedTransitions = new Map();
11
31
  this.notifyReady = noop;
12
- this.executed = false;
32
+ this.rejectReady = noop;
13
33
  this.scope = scope;
14
34
  this.updateDom = updateDom;
15
35
  this.defaultOptions = defaultOptions;
16
- this.readyPromise = new Promise((resolve) => {
36
+ this.readyPromise = new Promise((resolve, reject) => {
17
37
  this.notifyReady = resolve;
38
+ this.rejectReady = reject;
39
+ });
40
+ frame.postRender(() => {
41
+ this.start().then(this.notifyReady).catch(this.rejectReady);
18
42
  });
19
- // Queue execution on microtask to allow builder methods to be called
20
- queueMicrotask(() => this.execute());
21
43
  }
22
- shared(id, options) {
23
- this.sharedTransitions.set(id, options);
44
+ shared(id, transition) {
45
+ this.sharedTransitions.set(id, transition);
24
46
  return this;
25
47
  }
26
- then(onfulfilled, onrejected) {
27
- return this.readyPromise.then(onfulfilled, onrejected);
48
+ then(resolve, reject) {
49
+ return this.readyPromise.then(resolve, reject);
28
50
  }
29
- async execute() {
30
- if (this.executed)
31
- return;
32
- this.executed = true;
33
- let context;
34
- // Phase 1: Pre-mutation - Build projection tree and take snapshots
35
- const beforeElements = getLayoutElements(this.scope);
36
- if (beforeElements.length > 0) {
37
- context = buildProjectionTree(beforeElements, undefined, this.getBuildOptions());
38
- context.root.startUpdate();
39
- for (const node of context.nodes.values()) {
40
- node.isLayoutDirty = false;
41
- node.willUpdate();
51
+ async start() {
52
+ const beforeElements = collectLayoutElements(this.scope);
53
+ const beforeRecords = this.buildRecords(beforeElements);
54
+ beforeRecords.forEach(({ projection }) => {
55
+ const hasCurrentAnimation = Boolean(projection.currentAnimation);
56
+ const isSharedLayout = Boolean(projection.options.layoutId);
57
+ if (hasCurrentAnimation && isSharedLayout) {
58
+ const snapshot = snapshotFromTarget(projection);
59
+ if (snapshot) {
60
+ projection.snapshot = snapshot;
61
+ }
62
+ else if (projection.snapshot) {
63
+ projection.snapshot = undefined;
64
+ }
42
65
  }
43
- }
44
- // Phase 2: Execute DOM update
45
- this.updateDom();
46
- // Phase 3: Post-mutation - Compare before/after elements
47
- const afterElements = getLayoutElements(this.scope);
48
- const beforeSet = new Set(beforeElements);
49
- const afterSet = new Set(afterElements);
50
- const entering = afterElements.filter((el) => !beforeSet.has(el));
51
- const exiting = beforeElements.filter((el) => !afterSet.has(el));
52
- // Build projection nodes for entering elements
53
- if (entering.length > 0) {
54
- context = buildProjectionTree(entering, context, this.getBuildOptions());
55
- }
56
- // No layout elements - return empty animation
57
- if (!context) {
58
- this.notifyReady(new GroupAnimation([]));
59
- return;
60
- }
61
- // Handle shared elements
62
- for (const element of exiting) {
63
- const node = context.nodes.get(element);
64
- node?.getStack()?.remove(node);
65
- }
66
- for (const element of entering) {
67
- context.nodes.get(element)?.promote();
68
- }
69
- // Phase 4: Animate
70
- context.root.didUpdate();
71
- await new Promise((resolve) => frame.postRender(() => resolve()));
72
- const animations = [];
73
- for (const node of context.nodes.values()) {
74
- if (node.currentAnimation) {
75
- animations.push(node.currentAnimation);
66
+ else if (projection.snapshot &&
67
+ (projection.currentAnimation || projection.isProjecting())) {
68
+ projection.snapshot = undefined;
76
69
  }
77
- }
78
- const groupAnimation = new GroupAnimation(animations);
79
- groupAnimation.finished.then(() => {
80
- // Only clean up nodes for elements no longer in the document.
81
- // Elements still in DOM keep their nodes so subsequent animations
82
- // can use the stored position snapshots (A→B→A pattern).
83
- const elementsToCleanup = new Set();
84
- for (const element of context.nodes.keys()) {
85
- if (!document.contains(element)) {
86
- elementsToCleanup.add(element);
87
- }
70
+ projection.isPresent = true;
71
+ projection.willUpdate();
72
+ });
73
+ await this.updateDom();
74
+ const afterElements = collectLayoutElements(this.scope);
75
+ const afterRecords = this.buildRecords(afterElements);
76
+ this.handleExitingElements(beforeRecords, afterRecords);
77
+ afterRecords.forEach(({ projection }) => {
78
+ const instance = projection.instance;
79
+ const resumeFromInstance = projection.resumeFrom
80
+ ?.instance;
81
+ if (!instance || !resumeFromInstance)
82
+ return;
83
+ if (!("style" in instance))
84
+ return;
85
+ const currentTransform = instance.style.transform;
86
+ const resumeFromTransform = resumeFromInstance.style.transform;
87
+ if (currentTransform &&
88
+ resumeFromTransform &&
89
+ currentTransform === resumeFromTransform) {
90
+ instance.style.transform = "";
91
+ instance.style.transformOrigin = "";
88
92
  }
89
- cleanupProjectionTree(context, elementsToCleanup);
90
93
  });
91
- this.notifyReady(groupAnimation);
94
+ afterRecords.forEach(({ projection }) => {
95
+ projection.isPresent = true;
96
+ });
97
+ const root = getProjectionRoot(afterRecords, beforeRecords);
98
+ root?.didUpdate();
99
+ await new Promise((resolve) => {
100
+ frame.postRender(() => resolve());
101
+ });
102
+ const animations = collectAnimations(afterRecords);
103
+ const animation = new GroupAnimation(animations);
104
+ return animation;
92
105
  }
93
- getBuildOptions() {
94
- return {
95
- defaultTransition: this.defaultOptions || {
96
- duration: 0.3,
97
- ease: "easeOut",
98
- },
99
- sharedTransitions: this.sharedTransitions.size > 0
100
- ? this.sharedTransitions
101
- : undefined,
102
- };
106
+ buildRecords(elements) {
107
+ const records = [];
108
+ const recordMap = new Map();
109
+ for (const element of elements) {
110
+ const parentRecord = findParentRecord(element, recordMap, this.scope);
111
+ const { layout, layoutId } = readLayoutAttributes(element);
112
+ const override = layoutId
113
+ ? this.sharedTransitions.get(layoutId)
114
+ : undefined;
115
+ const transition = override || this.defaultOptions;
116
+ const record = getOrCreateRecord(element, parentRecord?.projection, {
117
+ layout,
118
+ layoutId,
119
+ animationType: typeof layout === "string" ? layout : "both",
120
+ transition: transition,
121
+ });
122
+ recordMap.set(element, record);
123
+ records.push(record);
124
+ }
125
+ return records;
126
+ }
127
+ handleExitingElements(beforeRecords, afterRecords) {
128
+ const afterElementsSet = new Set(afterRecords.map((record) => record.element));
129
+ beforeRecords.forEach((record) => {
130
+ if (afterElementsSet.has(record.element))
131
+ return;
132
+ // For shared layout elements, relegate to set up resumeFrom
133
+ // so the remaining element animates from this position
134
+ if (record.projection.options.layoutId) {
135
+ record.projection.isPresent = false;
136
+ record.projection.relegate();
137
+ }
138
+ record.visualElement.unmount();
139
+ visualElementStore.delete(record.element);
140
+ });
141
+ // Clear resumeFrom on EXISTING nodes that point to unmounted projections
142
+ // This prevents crossfade animation when the source element was removed entirely
143
+ // But preserve resumeFrom for NEW nodes so they can animate from the old position
144
+ // Also preserve resumeFrom for lead nodes that were just promoted via relegate
145
+ const beforeElementsSet = new Set(beforeRecords.map((record) => record.element));
146
+ afterRecords.forEach(({ element, projection }) => {
147
+ if (beforeElementsSet.has(element) &&
148
+ projection.resumeFrom &&
149
+ !projection.resumeFrom.instance &&
150
+ !projection.isLead()) {
151
+ projection.resumeFrom = undefined;
152
+ projection.snapshot = undefined;
153
+ }
154
+ });
103
155
  }
104
156
  }
105
- /**
106
- * Parse arguments for animateLayout overloads
107
- */
108
157
  function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
109
158
  // animateLayout(updateDom)
110
159
  if (typeof scopeOrUpdateDom === "function") {
@@ -118,11 +167,98 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
118
167
  const elements = resolveElements(scopeOrUpdateDom);
119
168
  const scope = elements[0] || document;
120
169
  return {
121
- scope: scope instanceof Document ? scope : scope,
170
+ scope,
122
171
  updateDom: updateDomOrOptions,
123
172
  defaultOptions: options,
124
173
  };
125
174
  }
175
+ function collectLayoutElements(scope) {
176
+ const elements = Array.from(scope.querySelectorAll(layoutSelector));
177
+ if (scope instanceof Element && scope.matches(layoutSelector)) {
178
+ if (!elements.includes(scope)) {
179
+ elements.unshift(scope);
180
+ }
181
+ }
182
+ return elements;
183
+ }
184
+ function readLayoutAttributes(element) {
185
+ const layoutId = element.getAttribute("data-layout-id") || undefined;
186
+ const rawLayout = element.getAttribute("data-layout");
187
+ let layout;
188
+ if (rawLayout === "" || rawLayout === "true") {
189
+ layout = true;
190
+ }
191
+ else if (rawLayout) {
192
+ layout = rawLayout;
193
+ }
194
+ return {
195
+ layout,
196
+ layoutId,
197
+ };
198
+ }
199
+ function createVisualState() {
200
+ return {
201
+ latestValues: {},
202
+ renderState: {
203
+ transform: {},
204
+ transformOrigin: {},
205
+ style: {},
206
+ vars: {},
207
+ },
208
+ };
209
+ }
210
+ function getOrCreateRecord(element, parentProjection, projectionOptions) {
211
+ const existing = visualElementStore.get(element);
212
+ const visualElement = existing ??
213
+ new HTMLVisualElement({
214
+ props: {},
215
+ presenceContext: null,
216
+ visualState: createVisualState(),
217
+ }, { allowProjection: true });
218
+ if (!existing || !visualElement.projection) {
219
+ visualElement.projection = new HTMLProjectionNode(visualElement.latestValues, parentProjection);
220
+ }
221
+ visualElement.projection.setOptions({
222
+ ...projectionOptions,
223
+ visualElement,
224
+ });
225
+ if (!visualElement.current) {
226
+ visualElement.mount(element);
227
+ }
228
+ if (!existing) {
229
+ visualElementStore.set(element, visualElement);
230
+ }
231
+ return {
232
+ element,
233
+ visualElement,
234
+ projection: visualElement.projection,
235
+ };
236
+ }
237
+ function findParentRecord(element, recordMap, scope) {
238
+ let parent = element.parentElement;
239
+ while (parent) {
240
+ const record = recordMap.get(parent);
241
+ if (record)
242
+ return record;
243
+ if (parent === scope)
244
+ break;
245
+ parent = parent.parentElement;
246
+ }
247
+ return undefined;
248
+ }
249
+ function getProjectionRoot(afterRecords, beforeRecords) {
250
+ const record = afterRecords[0] || beforeRecords[0];
251
+ return record?.projection.root;
252
+ }
253
+ function collectAnimations(afterRecords) {
254
+ const animations = new Set();
255
+ afterRecords.forEach((record) => {
256
+ const animation = record.projection.currentAnimation;
257
+ if (animation)
258
+ animations.add(animation);
259
+ });
260
+ return Array.from(animations);
261
+ }
126
262
 
127
263
  export { LayoutAnimationBuilder, parseAnimateLayoutArgs };
128
264
  //# sourceMappingURL=LayoutAnimationBuilder.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"LayoutAnimationBuilder.mjs","sources":["../../../src/layout/LayoutAnimationBuilder.ts"],"sourcesContent":["import { noop } from \"motion-utils\"\nimport type { AnimationOptions } from \"../animation/types\"\nimport { GroupAnimation, type AcceptedAnimations } from \"../animation/GroupAnimation\"\nimport { getLayoutElements } from \"./get-layout-elements\"\nimport {\n buildProjectionTree,\n cleanupProjectionTree,\n type ProjectionContext,\n type BuildProjectionTreeOptions,\n} from \"./projection-tree\"\nimport { resolveElements, type ElementOrSelector } from \"../utils/resolve-elements\"\nimport { frame } from \"../frameloop\"\n\nexport class LayoutAnimationBuilder implements PromiseLike<GroupAnimation> {\n private scope: Element | Document\n private updateDom: () => void\n private defaultOptions?: AnimationOptions\n\n private sharedTransitions = new Map<string, AnimationOptions>()\n\n private notifyReady: (value: GroupAnimation) => void = noop\n private readyPromise: Promise<GroupAnimation>\n private executed = false\n\n constructor(\n scope: Element | Document,\n updateDom: () => void,\n defaultOptions?: AnimationOptions\n ) {\n this.scope = scope\n this.updateDom = updateDom\n this.defaultOptions = defaultOptions\n\n this.readyPromise = new Promise<GroupAnimation>((resolve) => {\n this.notifyReady = resolve\n })\n\n // Queue execution on microtask to allow builder methods to be called\n queueMicrotask(() => this.execute())\n }\n\n shared(id: string, options: AnimationOptions): this {\n this.sharedTransitions.set(id, options)\n return this\n }\n\n then<TResult1 = GroupAnimation, TResult2 = never>(\n onfulfilled?:\n | ((value: GroupAnimation) => TResult1 | PromiseLike<TResult1>)\n | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n return this.readyPromise.then(onfulfilled, onrejected)\n }\n\n private async execute() {\n if (this.executed) return\n this.executed = true\n\n let context: ProjectionContext | undefined\n\n // Phase 1: Pre-mutation - Build projection tree and take snapshots\n const beforeElements = getLayoutElements(this.scope)\n\n if (beforeElements.length > 0) {\n context = buildProjectionTree(\n beforeElements,\n undefined,\n this.getBuildOptions()\n )\n\n context.root.startUpdate()\n\n for (const node of context.nodes.values()) {\n node.isLayoutDirty = false\n node.willUpdate()\n }\n }\n\n // Phase 2: Execute DOM update\n this.updateDom()\n\n // Phase 3: Post-mutation - Compare before/after elements\n const afterElements = getLayoutElements(this.scope)\n const beforeSet = new Set(beforeElements)\n const afterSet = new Set(afterElements)\n\n const entering = afterElements.filter((el) => !beforeSet.has(el))\n const exiting = beforeElements.filter((el) => !afterSet.has(el))\n\n // Build projection nodes for entering elements\n if (entering.length > 0) {\n context = buildProjectionTree(\n entering,\n context,\n this.getBuildOptions()\n )\n }\n\n // No layout elements - return empty animation\n if (!context) {\n this.notifyReady(new GroupAnimation([]))\n return\n }\n\n // Handle shared elements\n for (const element of exiting) {\n const node = context.nodes.get(element)\n node?.getStack()?.remove(node)\n }\n\n for (const element of entering) {\n context.nodes.get(element)?.promote()\n }\n\n // Phase 4: Animate\n context.root.didUpdate()\n\n await new Promise<void>((resolve) =>\n frame.postRender(() => resolve())\n )\n\n const animations: AcceptedAnimations[] = []\n for (const node of context.nodes.values()) {\n if (node.currentAnimation) {\n animations.push(node.currentAnimation)\n }\n }\n\n const groupAnimation = new GroupAnimation(animations)\n\n groupAnimation.finished.then(() => {\n // Only clean up nodes for elements no longer in the document.\n // Elements still in DOM keep their nodes so subsequent animations\n // can use the stored position snapshots (A→B→A pattern).\n const elementsToCleanup = new Set<HTMLElement>()\n for (const element of context!.nodes.keys()) {\n if (!document.contains(element)) {\n elementsToCleanup.add(element)\n }\n }\n cleanupProjectionTree(context!, elementsToCleanup)\n })\n\n this.notifyReady(groupAnimation)\n }\n\n private getBuildOptions(): BuildProjectionTreeOptions {\n return {\n defaultTransition: this.defaultOptions || {\n duration: 0.3,\n ease: \"easeOut\",\n },\n sharedTransitions:\n this.sharedTransitions.size > 0\n ? this.sharedTransitions\n : undefined,\n }\n }\n\n}\n\n/**\n * Parse arguments for animateLayout overloads\n */\nexport function parseAnimateLayoutArgs(\n scopeOrUpdateDom: ElementOrSelector | (() => void),\n updateDomOrOptions?: (() => void) | AnimationOptions,\n options?: AnimationOptions\n): {\n scope: Element | Document\n updateDom: () => void\n defaultOptions?: AnimationOptions\n} {\n // animateLayout(updateDom)\n if (typeof scopeOrUpdateDom === \"function\") {\n return {\n scope: document,\n updateDom: scopeOrUpdateDom,\n defaultOptions: updateDomOrOptions as AnimationOptions | undefined,\n }\n }\n\n // animateLayout(scope, updateDom, options?)\n const elements = resolveElements(scopeOrUpdateDom)\n const scope = elements[0] || document\n\n return {\n scope: scope instanceof Document ? scope : scope,\n updateDom: updateDomOrOptions as () => void,\n defaultOptions: options,\n }\n}\n"],"names":[],"mappings":";;;;;;;MAaa,sBAAsB,CAAA;AAW/B,IAAA,WAAA,CACI,KAAyB,EACzB,SAAqB,EACrB,cAAiC,EAAA;AAT7B,QAAA,IAAA,CAAA,iBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAA;QAEvD,IAAW,CAAA,WAAA,GAAoC,IAAI,CAAA;QAEnD,IAAQ,CAAA,QAAA,GAAG,KAAK,CAAA;AAOpB,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;AAClB,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;AAC1B,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QAEpC,IAAI,CAAC,YAAY,GAAG,IAAI,OAAO,CAAiB,CAAC,OAAO,KAAI;AACxD,YAAA,IAAI,CAAC,WAAW,GAAG,OAAO,CAAA;AAC9B,SAAC,CAAC,CAAA;;QAGF,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;KACvC;IAED,MAAM,CAAC,EAAU,EAAE,OAAyB,EAAA;QACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;AACvC,QAAA,OAAO,IAAI,CAAA;KACd;IAED,IAAI,CACA,WAEU,EACV,UAAuE,EAAA;QAEvE,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;KACzD;AAEO,IAAA,MAAM,OAAO,GAAA;QACjB,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAM;AACzB,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;AAEpB,QAAA,IAAI,OAAsC,CAAA;;QAG1C,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,KAAK,CA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nB,OAAO;AACH,YAAA,iBAAiB,EAAE,IAAI,CAAC,cAAc,IAAI;AACtC,gBAAA,QAAQ,EAAE,GAAG;AACb,gBAAA,IAAI,EAAE,SAAS;AAClB,aAAA;AACD,YAAA,iBAAiB,EACb,IAAI,CAAC,iBAAiB,CAAC,IAAI,GAAG,CAAC;kBACzB,IAAI,CAAC,iBAAiB;AACxB,kBAAE,SAAS;SACtB,CAAA;KACJ;AAEJ,CAAA;AAED;;AAEG;SACa,sBAAsB,CAClC,gBAAkD,EAClD,kBAAoD,EACpD,OAA0B,EAAA;;AAO1B,IAAA,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE;QACxC,OAAO;AACH,YAAA,KAAK,EAAE,QAAQ;AACf,YAAA,SAAS,EAAE,gBAAgB;AAC3B,YAAA,cAAc,EAAE,kBAAkD;SACrE,CAAA;KACJ;;AAGD,IAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAA;IAClD,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAA;IAErC,OAAO;QACH,KAAK,EAAE,KAAK,YAAY,QAAQ,GAAG,KAAK,GAAG,KAAK;AAChD,QAAA,SAAS,EAAE,kBAAgC;AAC3C,QAAA,cAAc,EAAE,OAAO;KAC1B,CAAA;AACL;;;;"}
1
+ {"version":3,"file":"LayoutAnimationBuilder.mjs","sources":["../../../src/layout/LayoutAnimationBuilder.ts"],"sourcesContent":["import type { Box } from \"motion-utils\"\nimport { GroupAnimation } from \"../animation/GroupAnimation\"\nimport type {\n AnimationOptions,\n AnimationPlaybackControls,\n Transition,\n} from \"../animation/types\"\nimport { frame } from \"../frameloop\"\nimport { copyBoxInto } from \"../projection/geometry/copy\"\nimport { createBox } from \"../projection/geometry/models\"\nimport { HTMLProjectionNode } from \"../projection/node/HTMLProjectionNode\"\nimport type { IProjectionNode } from \"../projection/node/types\"\nimport { HTMLVisualElement } from \"../render/html/HTMLVisualElement\"\nimport { visualElementStore } from \"../render/store\"\nimport type { VisualElement } from \"../render/VisualElement\"\nimport { resolveElements, type ElementOrSelector } from \"../utils/resolve-elements\"\n\ntype LayoutAnimationScope = Element | Document\n\ninterface LayoutElementRecord {\n element: Element\n visualElement: VisualElement\n projection: IProjectionNode\n}\n\ninterface LayoutAttributes {\n layout?: boolean | \"position\" | \"size\" | \"preserve-aspect\"\n layoutId?: string\n}\n\ntype LayoutBuilderResolve = (animation: GroupAnimation) => void\ntype LayoutBuilderReject = (error: unknown) => void\n\ninterface ProjectionOptions {\n layout?: boolean | \"position\" | \"size\" | \"preserve-aspect\"\n layoutId?: string\n animationType?: \"size\" | \"position\" | \"both\" | \"preserve-aspect\"\n transition?: Transition\n crossfade?: boolean\n}\n\nconst layoutSelector = \"[data-layout], [data-layout-id]\"\nconst noop = () => {}\nfunction snapshotFromTarget(projection: IProjectionNode): LayoutElementRecord[\"projection\"][\"snapshot\"] {\n const target = projection.targetWithTransforms || projection.target\n if (!target) return undefined\n\n const measuredBox = createBox()\n const layoutBox = createBox()\n copyBoxInto(measuredBox, target as Box)\n copyBoxInto(layoutBox, target as Box)\n\n return {\n animationId: projection.root?.animationId ?? 0,\n measuredBox,\n layoutBox,\n latestValues: projection.animationValues || projection.latestValues || {},\n source: projection.id,\n }\n}\n\nexport class LayoutAnimationBuilder {\n private scope: LayoutAnimationScope\n private updateDom: () => void | Promise<void>\n private defaultOptions?: AnimationOptions\n private sharedTransitions = new Map<string, AnimationOptions>()\n private notifyReady: LayoutBuilderResolve = noop\n private rejectReady: LayoutBuilderReject = noop\n private readyPromise: Promise<GroupAnimation>\n\n constructor(\n scope: LayoutAnimationScope,\n updateDom: () => void | Promise<void>,\n defaultOptions?: AnimationOptions\n ) {\n this.scope = scope\n this.updateDom = updateDom\n this.defaultOptions = defaultOptions\n\n this.readyPromise = new Promise<GroupAnimation>((resolve, reject) => {\n this.notifyReady = resolve\n this.rejectReady = reject\n })\n\n frame.postRender(() => {\n this.start().then(this.notifyReady).catch(this.rejectReady)\n })\n }\n\n shared(id: string, transition: AnimationOptions): this {\n this.sharedTransitions.set(id, transition)\n return this\n }\n\n then(\n resolve: LayoutBuilderResolve,\n reject?: LayoutBuilderReject\n ): Promise<void> {\n return this.readyPromise.then(resolve, reject)\n }\n\n private async start(): Promise<GroupAnimation> {\n const beforeElements = collectLayoutElements(this.scope)\n const beforeRecords = this.buildRecords(beforeElements)\n\n beforeRecords.forEach(({ projection }) => {\n const hasCurrentAnimation = Boolean(projection.currentAnimation)\n const isSharedLayout = Boolean(projection.options.layoutId)\n if (hasCurrentAnimation && isSharedLayout) {\n const snapshot = snapshotFromTarget(projection)\n if (snapshot) {\n projection.snapshot = snapshot\n } else if (projection.snapshot) {\n projection.snapshot = undefined\n }\n } else if (\n projection.snapshot &&\n (projection.currentAnimation || projection.isProjecting())\n ) {\n projection.snapshot = undefined\n }\n projection.isPresent = true\n projection.willUpdate()\n })\n\n await this.updateDom()\n\n const afterElements = collectLayoutElements(this.scope)\n const afterRecords = this.buildRecords(afterElements)\n this.handleExitingElements(beforeRecords, afterRecords)\n\n afterRecords.forEach(({ projection }) => {\n const instance = projection.instance as HTMLElement | undefined\n const resumeFromInstance = projection.resumeFrom\n ?.instance as HTMLElement | undefined\n if (!instance || !resumeFromInstance) return\n if (!(\"style\" in instance)) return\n\n const currentTransform = instance.style.transform\n const resumeFromTransform = resumeFromInstance.style.transform\n\n if (\n currentTransform &&\n resumeFromTransform &&\n currentTransform === resumeFromTransform\n ) {\n instance.style.transform = \"\"\n instance.style.transformOrigin = \"\"\n }\n })\n\n afterRecords.forEach(({ projection }) => {\n projection.isPresent = true\n })\n\n const root = getProjectionRoot(afterRecords, beforeRecords)\n root?.didUpdate()\n\n await new Promise<void>((resolve) => {\n frame.postRender(() => resolve())\n })\n\n const animations = collectAnimations(afterRecords)\n const animation = new GroupAnimation(animations)\n\n return animation\n }\n\n private buildRecords(elements: Element[]): LayoutElementRecord[] {\n const records: LayoutElementRecord[] = []\n const recordMap = new Map<Element, LayoutElementRecord>()\n\n for (const element of elements) {\n const parentRecord = findParentRecord(element, recordMap, this.scope)\n const { layout, layoutId } = readLayoutAttributes(element)\n const override = layoutId\n ? this.sharedTransitions.get(layoutId)\n : undefined\n const transition = override || this.defaultOptions\n const record = getOrCreateRecord(element, parentRecord?.projection, {\n layout,\n layoutId,\n animationType: typeof layout === \"string\" ? layout : \"both\",\n transition: transition as Transition,\n })\n recordMap.set(element, record)\n records.push(record)\n }\n\n return records\n }\n\n private handleExitingElements(\n beforeRecords: LayoutElementRecord[],\n afterRecords: LayoutElementRecord[]\n ): void {\n const afterElementsSet = new Set(afterRecords.map((record) => record.element))\n\n beforeRecords.forEach((record) => {\n if (afterElementsSet.has(record.element)) return\n\n // For shared layout elements, relegate to set up resumeFrom\n // so the remaining element animates from this position\n if (record.projection.options.layoutId) {\n record.projection.isPresent = false\n record.projection.relegate()\n }\n\n record.visualElement.unmount()\n visualElementStore.delete(record.element)\n })\n\n // Clear resumeFrom on EXISTING nodes that point to unmounted projections\n // This prevents crossfade animation when the source element was removed entirely\n // But preserve resumeFrom for NEW nodes so they can animate from the old position\n // Also preserve resumeFrom for lead nodes that were just promoted via relegate\n const beforeElementsSet = new Set(beforeRecords.map((record) => record.element))\n afterRecords.forEach(({ element, projection }) => {\n if (\n beforeElementsSet.has(element) &&\n projection.resumeFrom &&\n !projection.resumeFrom.instance &&\n !projection.isLead()\n ) {\n projection.resumeFrom = undefined\n projection.snapshot = undefined\n }\n })\n }\n}\n\nexport function parseAnimateLayoutArgs(\n scopeOrUpdateDom: ElementOrSelector | (() => void),\n updateDomOrOptions?: (() => void) | AnimationOptions,\n options?: AnimationOptions\n): {\n scope: Element | Document\n updateDom: () => void\n defaultOptions?: AnimationOptions\n} {\n // animateLayout(updateDom)\n if (typeof scopeOrUpdateDom === \"function\") {\n return {\n scope: document,\n updateDom: scopeOrUpdateDom,\n defaultOptions: updateDomOrOptions as AnimationOptions | undefined,\n }\n }\n\n // animateLayout(scope, updateDom, options?)\n const elements = resolveElements(scopeOrUpdateDom)\n const scope = elements[0] || document\n\n return {\n scope,\n updateDom: updateDomOrOptions as () => void,\n defaultOptions: options,\n }\n}\n\nfunction collectLayoutElements(scope: LayoutAnimationScope): Element[] {\n const elements = Array.from(scope.querySelectorAll(layoutSelector))\n\n if (scope instanceof Element && scope.matches(layoutSelector)) {\n if (!elements.includes(scope)) {\n elements.unshift(scope)\n }\n }\n\n return elements\n}\n\nfunction readLayoutAttributes(element: Element): LayoutAttributes {\n const layoutId = element.getAttribute(\"data-layout-id\") || undefined\n const rawLayout = element.getAttribute(\"data-layout\")\n let layout: LayoutAttributes[\"layout\"]\n\n if (rawLayout === \"\" || rawLayout === \"true\") {\n layout = true\n } else if (rawLayout) {\n layout = rawLayout as LayoutAttributes[\"layout\"]\n }\n\n return {\n layout,\n layoutId,\n }\n}\n\nfunction createVisualState() {\n return {\n latestValues: {},\n renderState: {\n transform: {},\n transformOrigin: {},\n style: {},\n vars: {},\n },\n }\n}\n\nfunction getOrCreateRecord(\n element: Element,\n parentProjection?: IProjectionNode,\n projectionOptions?: ProjectionOptions\n): LayoutElementRecord {\n const existing = visualElementStore.get(element) as VisualElement | undefined\n const visualElement =\n existing ??\n new HTMLVisualElement(\n {\n props: {},\n presenceContext: null,\n visualState: createVisualState(),\n },\n { allowProjection: true }\n )\n\n if (!existing || !visualElement.projection) {\n visualElement.projection = new HTMLProjectionNode(\n visualElement.latestValues,\n parentProjection\n )\n }\n\n visualElement.projection.setOptions({\n ...projectionOptions,\n visualElement,\n })\n\n if (!visualElement.current) {\n visualElement.mount(element as HTMLElement)\n }\n\n if (!existing) {\n visualElementStore.set(element, visualElement)\n }\n\n return {\n element,\n visualElement,\n projection: visualElement.projection as IProjectionNode,\n }\n}\n\nfunction findParentRecord(\n element: Element,\n recordMap: Map<Element, LayoutElementRecord>,\n scope: LayoutAnimationScope\n) {\n let parent = element.parentElement\n\n while (parent) {\n const record = recordMap.get(parent)\n if (record) return record\n\n if (parent === scope) break\n parent = parent.parentElement\n }\n\n return undefined\n}\n\nfunction getProjectionRoot(\n afterRecords: LayoutElementRecord[],\n beforeRecords: LayoutElementRecord[]\n) {\n const record = afterRecords[0] || beforeRecords[0]\n return record?.projection.root\n}\n\nfunction collectAnimations(afterRecords: LayoutElementRecord[]) {\n const animations = new Set<AnimationPlaybackControls>()\n\n afterRecords.forEach((record) => {\n const animation = record.projection.currentAnimation\n if (animation) animations.add(animation)\n })\n\n return Array.from(animations)\n}\n"],"names":[],"mappings":";;;;;;;;;AAyCA,MAAM,cAAc,GAAG,iCAAiC,CAAA;AACxD,MAAM,IAAI,GAAG,MAAK,GAAG,CAAA;AACrB,SAAS,kBAAkB,CAAC,UAA2B,EAAA;IACnD,MAAM,MAAM,GAAG,UAAU,CAAC,oBAAoB,IAAI,UAAU,CAAC,MAAM,CAAA;AACnE,IAAA,IAAI,CAAC,MAAM;AAAE,QAAA,OAAO,SAAS,CAAA;AAE7B,IAAA,MAAM,WAAW,GAAG,SAAS,EAAE,CAAA;AAC/B,IAAA,MAAM,SAAS,GAAG,SAAS,EAAE,CAAA;AAC7B,IAAA,WAAW,CAAC,WAAW,EAAE,MAAa,CAAC,CAAA;AACvC,IAAA,WAAW,CAAC,SAAS,EAAE,MAAa,CAAC,CAAA;IAErC,OAAO;AACH,QAAA,WAAW,EAAE,UAAU,CAAC,IAAI,EAAE,WAAW,IAAI,CAAC;QAC9C,WAAW;QACX,SAAS;QACT,YAAY,EAAE,UAAU,CAAC,eAAe,IAAI,UAAU,CAAC,YAAY,IAAI,EAAE;QACzE,MAAM,EAAE,UAAU,CAAC,EAAE;KACxB,CAAA;AACL,CAAC;MAEY,sBAAsB,CAAA;AAS/B,IAAA,WAAA,CACI,KAA2B,EAC3B,SAAqC,EACrC,cAAiC,EAAA;AAR7B,QAAA,IAAA,CAAA,iBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAA;QACvD,IAAW,CAAA,WAAA,GAAyB,IAAI,CAAA;QACxC,IAAW,CAAA,W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AAA;AAEvD,IAAA,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,KAAI;AAC5B,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,gBAAgB,CAAA;AACpD,QAAA,IAAI,SAAS;AAAE,YAAA,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AAC5C,KAAC,CAAC,CAAA;AAEF,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AACjC;;;;"}
@@ -1,30 +1,30 @@
1
- import { activeAnimations } from '../../stats/animation-count.mjs';
1
+ import { SubscriptionManager, clamp, noop } from 'motion-utils';
2
+ import { animateSingleValue } from '../../animation/animate/single-value.mjs';
3
+ import { getOptimisedAppearId } from '../../animation/optimized-appear/get-appear-id.mjs';
2
4
  import { getValueTransition } from '../../animation/utils/get-value-transition.mjs';
3
5
  import { microtask } from '../../frameloop/microtask.mjs';
4
6
  import { time } from '../../frameloop/sync-time.mjs';
7
+ import { scaleCorrectors } from '../styles/scale-correction.mjs';
8
+ import { activeAnimations } from '../../stats/animation-count.mjs';
9
+ import { statsBuffer } from '../../stats/buffer.mjs';
10
+ import { delay } from '../../utils/delay.mjs';
11
+ import { isSVGElement } from '../../utils/is-svg-element.mjs';
12
+ import { isSVGSVGElement } from '../../utils/is-svg-svg-element.mjs';
13
+ import { mixNumber } from '../../utils/mix/number.mjs';
14
+ import { motionValue } from '../../value/index.mjs';
15
+ import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
16
+ import { mixValues } from '../animation/mix-values.mjs';
17
+ import { copyBoxInto, copyAxisDeltaInto } from '../geometry/copy.mjs';
5
18
  import { translateAxis, transformBox, applyBoxDelta, applyTreeDeltas } from '../geometry/delta-apply.mjs';
6
19
  import { calcLength, calcRelativeBox, calcRelativePosition, calcBoxDelta, isNear } from '../geometry/delta-calc.mjs';
7
20
  import { removeBoxTransforms } from '../geometry/delta-remove.mjs';
8
- import { copyBoxInto, copyAxisDeltaInto } from '../geometry/copy.mjs';
9
21
  import { createBox, createDelta } from '../geometry/models.mjs';
10
22
  import { boxEqualsRounded, isDeltaZero, axisDeltaEquals, aspectRatio, boxEquals } from '../geometry/utils.mjs';
23
+ import { NodeStack } from '../shared/stack.mjs';
11
24
  import { buildProjectionTransform } from '../styles/transform.mjs';
12
25
  import { eachAxis } from '../utils/each-axis.mjs';
13
- import { hasTransform, hasScale, has2DTranslate } from '../utils/has-transform.mjs';
14
- import { mixValues } from '../animation/mix-values.mjs';
15
- import { isSVGElement } from '../../utils/is-svg-element.mjs';
16
- import { isSVGSVGElement } from '../../utils/is-svg-svg-element.mjs';
17
- import { mixNumber } from '../../utils/mix/number.mjs';
18
- import { motionValue } from '../../value/index.mjs';
19
- import { scaleCorrectors } from '../styles/scale-correction.mjs';
20
- import { statsBuffer } from '../../stats/buffer.mjs';
21
- import { SubscriptionManager, clamp, noop } from 'motion-utils';
22
- import { animateSingleValue } from '../../animation/animate/single-value.mjs';
23
- import { getOptimisedAppearId } from '../../animation/optimized-appear/get-appear-id.mjs';
24
26
  import { FlatTree } from '../utils/flat-tree.mjs';
25
- import { delay } from '../../utils/delay.mjs';
26
- import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
27
- import { NodeStack } from '../shared/stack.mjs';
27
+ import { hasTransform, hasScale, has2DTranslate } from '../utils/has-transform.mjs';
28
28
  import { globalProjectionState } from './state.mjs';
29
29
  import { frame, cancelFrame, frameData, frameSteps } from '../../frameloop/frame.mjs';
30
30