motion-dom 14.7.1 → 14.8.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.
Files changed (52) hide show
  1. package/dist/cjs/index.js +370 -147
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/JSAnimation.mjs +7 -1
  4. package/dist/es/animation/JSAnimation.mjs.map +1 -1
  5. package/dist/es/animation/generators/keyframes.mjs +12 -3
  6. package/dist/es/animation/generators/keyframes.mjs.map +1 -1
  7. package/dist/es/animation/utils/is-transition-defined.mjs +1 -0
  8. package/dist/es/animation/utils/is-transition-defined.mjs.map +1 -1
  9. package/dist/es/animation/waapi/supports/waapi.mjs +3 -1
  10. package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
  11. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +31 -35
  12. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
  13. package/dist/es/animation/waapi/utils/needs-mixer.mjs +11 -0
  14. package/dist/es/animation/waapi/utils/needs-mixer.mjs.map +1 -0
  15. package/dist/es/effects/svg/index.mjs +14 -0
  16. package/dist/es/effects/svg/index.mjs.map +1 -1
  17. package/dist/es/gestures/drag/index.mjs +4 -3
  18. package/dist/es/gestures/drag/index.mjs.map +1 -1
  19. package/dist/es/gestures/drag/projection.mjs +85 -0
  20. package/dist/es/gestures/drag/projection.mjs.map +1 -0
  21. package/dist/es/index.mjs +1 -1
  22. package/dist/es/layout/LayoutAnimationBuilder.mjs +34 -51
  23. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  24. package/dist/es/layout/visual-element.mjs +48 -0
  25. package/dist/es/layout/visual-element.mjs.map +1 -0
  26. package/dist/es/projection/geometry/round.mjs +25 -0
  27. package/dist/es/projection/geometry/round.mjs.map +1 -0
  28. package/dist/es/projection/node/DocumentProjectionNode.mjs +2 -8
  29. package/dist/es/projection/node/DocumentProjectionNode.mjs.map +1 -1
  30. package/dist/es/projection/node/create-projection-node.mjs +68 -48
  31. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  32. package/dist/es/projection/utils/measure.mjs +5 -1
  33. package/dist/es/projection/utils/measure.mjs.map +1 -1
  34. package/dist/es/stats/buffer.mjs +1 -0
  35. package/dist/es/stats/buffer.mjs.map +1 -1
  36. package/dist/es/stats/index.mjs +31 -0
  37. package/dist/es/stats/index.mjs.map +1 -1
  38. package/dist/es/utils/interpolate.mjs +3 -2
  39. package/dist/es/utils/interpolate.mjs.map +1 -1
  40. package/dist/es/utils/is-ref-object.mjs +8 -0
  41. package/dist/es/utils/is-ref-object.mjs.map +1 -0
  42. package/dist/es/utils/transform.mjs.map +1 -1
  43. package/dist/es/value/index.mjs +10 -1
  44. package/dist/es/value/index.mjs.map +1 -1
  45. package/dist/index.d.ts +298 -232
  46. package/dist/motion-dom.dev.js +370 -147
  47. package/dist/motion-dom.js +1 -1
  48. package/dist/size-rollup-motion-value.js +1 -1
  49. package/dist/size-rollup-motion-value.js.map +1 -1
  50. package/dist/size-rollup-style-effect.js +1 -1
  51. package/dist/size-rollup-style-effect.js.map +1 -1
  52. package/package.json +2 -2
@@ -1,14 +1,13 @@
1
1
  import { activeScope } from '../scope/active.mjs';
2
2
  import { clamp } from 'motion-utils';
3
- import { handOffElementState } from '../animation/animate/element.mjs';
4
3
  import { GroupAnimation } from '../animation/GroupAnimation.mjs';
5
4
  import { microtask } from '../frameloop/microtask.mjs';
6
5
  import { time } from '../frameloop/sync-time.mjs';
7
6
  import { HTMLProjectionNode } from '../projection/node/HTMLProjectionNode.mjs';
8
- import { HTMLVisualElement } from '../render/html/HTMLVisualElement.mjs';
9
7
  import { visualElementStore } from '../render/store.mjs';
10
- import { hasTransform } from '../projection/utils/has-transform.mjs';
8
+ import { resolveVisualElement } from './visual-element.mjs';
11
9
  import { resolveElements } from '../utils/resolve-elements.mjs';
10
+ import { layoutProjection } from '../gestures/drag/projection.mjs';
12
11
  import { frameData } from '../frameloop/frame-data.mjs';
13
12
  import { frameSteps } from '../frameloop/frame.mjs';
14
13
 
@@ -64,21 +63,6 @@ function getProjectionParent(element) {
64
63
  }
65
64
  return undefined;
66
65
  }
67
- function createVisualElement() {
68
- return new HTMLVisualElement({
69
- props: {},
70
- presenceContext: null,
71
- visualState: {
72
- latestValues: {},
73
- renderState: {
74
- transform: {},
75
- transformOrigin: {},
76
- style: {},
77
- vars: {},
78
- },
79
- },
80
- }, { allowProjection: true });
81
- }
82
66
  function readNodeOptions(element, transition) {
83
67
  const layoutAttr = element.getAttribute("data-layout");
84
68
  const layoutId = element.getAttribute("data-layout-id") ?? undefined;
@@ -94,27 +78,7 @@ function readNodeOptions(element, transition) {
94
78
  function prepareNode(element, transition) {
95
79
  let node = layoutNodes.get(element);
96
80
  if (!node) {
97
- let visualElement = visualElementStore.get(element);
98
- if (!visualElement) {
99
- visualElement = createVisualElement();
100
- /**
101
- * Values animate() has been rendering on this element move to
102
- * the VisualElement, so the layout animation composes with
103
- * them instead of overwriting them.
104
- */
105
- handOffElementState(element, visualElement);
106
- }
107
- /**
108
- * A first-time element may carry a projection transform in its
109
- * inline style (e.g. it was cloned from an element mid-animation).
110
- * That transform isn't tracked in latestValues so the engine can't
111
- * reset it before measuring - clear it now so the first layout
112
- * measurement isn't inflated.
113
- */
114
- if (element.style.transform &&
115
- !hasTransform(visualElement.latestValues)) {
116
- element.style.transform = "";
117
- }
81
+ const visualElement = resolveVisualElement(element);
118
82
  node = new HTMLProjectionNode(visualElement.latestValues, getProjectionParent(element));
119
83
  visualElement.projection = node;
120
84
  node.setOptions({
@@ -134,10 +98,26 @@ function prepareNode(element, transition) {
134
98
  return node;
135
99
  }
136
100
  /**
137
- * Get a projection node for an element, so imperative gestures like
138
- * drag() can measure its layout. Reuses a node owned by a `motion`
139
- * component or animateLayout(), otherwise creates one in the shared
140
- * imperative tree. Returns the node and a function that releases it.
101
+ * Create a node for an element in the shared imperative tree. Returns the
102
+ * node and a function that releases it.
103
+ */
104
+ function createLayoutNode(element) {
105
+ const node = prepareNode(element);
106
+ return [
107
+ node,
108
+ () => layoutNodes.get(element) === node && dropNode(element, node),
109
+ ];
110
+ }
111
+ /**
112
+ * Let drag() create its nodes in the shared imperative tree, so drag
113
+ * gestures and layout animations work together.
114
+ */
115
+ layoutProjection.create = createLayoutNode;
116
+ /**
117
+ * Get a projection node for an element, so motion/remix can measure and
118
+ * animate its layout. Reuses a node owned by a `motion` component or
119
+ * animateLayout(), otherwise creates one in the shared imperative tree.
120
+ * Returns the node and a function that releases it.
141
121
  */
142
122
  function acquireProjectionNode(element) {
143
123
  const owned = layoutNodes.get(element) || visualElementStore.get(element)?.projection;
@@ -145,13 +125,7 @@ function acquireProjectionNode(element) {
145
125
  * A VisualElement can outlive a node we released (e.g. a stopped
146
126
  * drag()), so only reuse a node that's still mounted.
147
127
  */
148
- if (owned?.instance)
149
- return [owned, () => { }];
150
- const node = prepareNode(element);
151
- return [
152
- node,
153
- () => layoutNodes.get(element) === node && dropNode(element, node),
154
- ];
128
+ return owned?.instance ? [owned, () => { }] : createLayoutNode(element);
155
129
  }
156
130
  function sortDocumentOrder(elements) {
157
131
  return [...elements].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
@@ -171,6 +145,8 @@ function dropNode(element, node) {
171
145
  }
172
146
  function flushPendingBuilders() {
173
147
  const builders = pendingBuilders;
148
+ if (!builders)
149
+ return;
174
150
  pendingBuilders = undefined;
175
151
  flushPendingFrame();
176
152
  /**
@@ -235,6 +211,13 @@ function flushPendingBuilders() {
235
211
  };
236
212
  updatePromises.length ? Promise.all(updatePromises).then(commit) : commit();
237
213
  }
214
+ /**
215
+ * Snapshot every pending animateLayout() now, rather than on the next
216
+ * microtask. For renderers that tell us a DOM update is about to happen
217
+ * and then make it synchronously (e.g. a beforeUpdate/commit pair), with
218
+ * updateDom returning a promise that resolves on commit.
219
+ */
220
+ const flushLayoutSnapshots = flushPendingBuilders;
238
221
  class LayoutAnimationBuilder {
239
222
  constructor(scope, updateDom, defaultOptions) {
240
223
  this.scope = scope;
@@ -380,5 +363,5 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
380
363
  };
381
364
  }
382
365
 
383
- export { LayoutAnimationBuilder, acquireProjectionNode, parseAnimateLayoutArgs };
366
+ export { LayoutAnimationBuilder, acquireProjectionNode, flushLayoutSnapshots, parseAnimateLayoutArgs };
384
367
  //# sourceMappingURL=LayoutAnimationBuilder.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"LayoutAnimationBuilder.mjs","sources":["../../../src/layout/LayoutAnimationBuilder.ts"],"sourcesContent":["import { activeScope } from \"../scope/active\"\nimport { clamp } from \"motion-utils\"\nimport { handOffElementState } from \"../animation/animate/element\"\nimport { GroupAnimation } from \"../animation/GroupAnimation\"\nimport type { AnimationOptions, Transition } from \"../animation/types\"\nimport { frameData, frameSteps } from \"../frameloop\"\nimport { microtask } from \"../frameloop/microtask\"\nimport { time } from \"../frameloop/sync-time\"\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 { hasTransform } from \"../projection/utils/has-transform\"\nimport {\n resolveElements,\n type ElementOrSelector,\n} from \"../utils/resolve-elements\"\n\ntype LayoutAnimationScope = Element | Document\ntype LayoutBuilderResolve = (animation: GroupAnimation) => void\ntype LayoutBuilderReject = (error: unknown) => void\n\ninterface RestorePoint {\n parent: Element\n next: ChildNode | null\n}\n\nconst layoutSelector = \"[data-layout],[data-layout-id]\"\n\n/**\n * All imperatively-created projection nodes live in one persistent tree,\n * shared across animateLayout() calls (and with any React-created nodes,\n * via the singleton document root). Keyed by element for reuse.\n */\nconst layoutNodes = new WeakMap<Element, IProjectionNode>()\n\n/**\n * Builders created within the same synchronous tick are flushed together\n * as a single \"commit\": every node is snapshotted before any updateDom\n * runs, mirroring React batching renders from different parts of the tree.\n */\nlet pendingBuilders: LayoutAnimationBuilder[] | undefined\n\nfunction collectLayoutElements(scope: LayoutAnimationScope): HTMLElement[] {\n const elements: HTMLElement[] = []\n\n if (scope instanceof HTMLElement && scope.matches(layoutSelector)) {\n elements.push(scope)\n }\n\n scope.querySelectorAll(layoutSelector).forEach((element) => {\n if (element instanceof HTMLElement) elements.push(element)\n })\n\n return elements\n}\n\n/**\n * Process any work scheduled on the frameloop now. A previous animation\n * may have been seeked while paused (controls.time = x) without a frame\n * having rendered it - we must materialise that state into the DOM\n * before taking snapshots.\n */\nfunction flushPendingFrame() {\n if (frameData.isProcessing) return\n\n const now = time.now()\n frameData.delta = clamp(0, 1000 / 60, now - frameData.timestamp)\n frameData.timestamp = now\n frameData.isProcessing = true\n frameSteps.update.process(frameData)\n frameSteps.preRender.process(frameData)\n frameSteps.render.process(frameData)\n frameData.isProcessing = false\n}\n\nfunction getProjectionParent(element: Element): IProjectionNode | undefined {\n let ancestor = element.parentElement\n while (ancestor) {\n const node = layoutNodes.get(ancestor)\n if (node?.instance) return node\n ancestor = ancestor.parentElement\n }\n return undefined\n}\n\nfunction createVisualElement() {\n return new HTMLVisualElement(\n {\n props: {},\n presenceContext: null,\n visualState: {\n latestValues: {},\n renderState: {\n transform: {},\n transformOrigin: {},\n style: {},\n vars: {},\n },\n },\n },\n { allowProjection: true }\n )\n}\n\nfunction readNodeOptions(element: HTMLElement, transition?: Transition) {\n const layoutAttr = element.getAttribute(\"data-layout\")\n const layoutId = element.getAttribute(\"data-layout-id\") ?? undefined\n\n return {\n layoutId,\n layout: layoutAttr !== null ? true : undefined,\n animationType: (!layoutAttr || layoutAttr === \"true\"\n ? \"both\"\n : layoutAttr) as \"both\",\n transition,\n }\n}\n\nfunction prepareNode(\n element: HTMLElement,\n transition?: Transition\n): IProjectionNode {\n let node = layoutNodes.get(element)\n\n if (!node) {\n let visualElement = visualElementStore.get(element) as\n | HTMLVisualElement\n | undefined\n\n if (!visualElement) {\n visualElement = createVisualElement()\n\n /**\n * Values animate() has been rendering on this element move to\n * the VisualElement, so the layout animation composes with\n * them instead of overwriting them.\n */\n handOffElementState(element, visualElement)\n }\n\n /**\n * A first-time element may carry a projection transform in its\n * inline style (e.g. it was cloned from an element mid-animation).\n * That transform isn't tracked in latestValues so the engine can't\n * reset it before measuring - clear it now so the first layout\n * measurement isn't inflated.\n */\n if (\n element.style.transform &&\n !hasTransform(visualElement.latestValues)\n ) {\n element.style.transform = \"\"\n }\n\n node = new HTMLProjectionNode(\n visualElement.latestValues,\n getProjectionParent(element)\n )\n visualElement.projection = node\n\n node.setOptions({\n ...readNodeOptions(element, transition),\n visualElement,\n })\n node.mount(element)\n layoutNodes.set(element, node)\n } else {\n node.setOptions(readNodeOptions(element, transition))\n }\n\n node.isPresent = true\n if (node.options.onExitComplete) {\n node.setOptions({ onExitComplete: undefined })\n }\n\n return node\n}\n\n/**\n * Get a projection node for an element, so imperative gestures like\n * drag() can measure its layout. Reuses a node owned by a `motion`\n * component or animateLayout(), otherwise creates one in the shared\n * imperative tree. Returns the node and a function that releases it.\n */\nexport function acquireProjectionNode(\n element: HTMLElement\n): [IProjectionNode, VoidFunction] {\n const owned =\n layoutNodes.get(element) || visualElementStore.get(element)?.projection\n\n /**\n * A VisualElement can outlive a node we released (e.g. a stopped\n * drag()), so only reuse a node that's still mounted.\n */\n if (owned?.instance) return [owned, () => {}]\n\n const node = prepareNode(element)\n\n return [\n node,\n () => layoutNodes.get(element) === node && dropNode(element, node),\n ]\n}\n\nfunction sortDocumentOrder(elements: Iterable<HTMLElement>) {\n return [...elements].sort((a, b) =>\n a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1\n )\n}\n\nfunction dropNode(element: Element, node: IProjectionNode) {\n node.setOptions({ onExitComplete: undefined })\n\n /**\n * Stop any lingering animation so it can't leak into future updates.\n * A follow node can share its currentAnimation with a surviving lead\n * (via resumingFrom), in which case it isn't ours to stop.\n */\n const stack = node.getStack()\n if (!stack || node.isLead()) node.currentAnimation?.stop()\n\n node.unmount()\n layoutNodes.delete(element)\n}\n\nfunction flushPendingBuilders() {\n const builders = pendingBuilders!\n pendingBuilders = undefined\n\n flushPendingFrame()\n\n /**\n * Discover and mount every node across all builders before snapshotting\n * any of them. Mounting during an active update flags isLayoutDirty,\n * which would make that node's own willUpdate skip its snapshot.\n * Document order guarantees ancestors mount before descendants, even\n * when they're discovered by different builders.\n */\n const targets = new Map<HTMLElement, LayoutAnimationBuilder[]>()\n for (const builder of builders) {\n for (const element of builder.collectTargets()) {\n const owners = targets.get(element)\n owners ? owners.push(builder) : targets.set(element, [builder])\n }\n }\n\n const union = new Map<HTMLElement, IProjectionNode>()\n for (const element of sortDocumentOrder(targets.keys())) {\n const owners = targets.get(element)!\n const node = prepareNode(\n element,\n owners[owners.length - 1].transitionFor(element)\n )\n for (const owner of owners) owner.adopt(element, node)\n union.set(element, node)\n }\n\n union.forEach((node) => {\n node.isLayoutDirty = false\n node.willUpdate()\n })\n\n const updatePromises: Promise<void>[] = []\n for (const builder of builders) {\n const result = builder.runUpdate()\n if (result) updatePromises.push(result)\n }\n\n const commit = () => {\n /**\n * Process all additions before any removals so that, even across\n * builders, a removed member knows whether a replacement with the\n * same layoutId was added in this commit.\n */\n const newMemberIds = new Set<string>()\n for (const builder of builders) {\n builder.reconcileAdditions(newMemberIds)\n }\n for (const builder of builders) {\n builder.reconcileRemovals(newMemberIds)\n }\n\n let root: IProjectionNode | undefined\n union.forEach((node) => (root ||= node.root))\n for (const builder of builders) root ||= builder.getRoot()\n\n root?.didUpdate()\n\n /**\n * The root flushes the update on a microtask, synchronously\n * processing the frame that creates the layout animations. Collect\n * them in a later microtask step of the same pass.\n */\n microtask.render(() => {\n for (const builder of builders) builder.finalize()\n })\n }\n\n updatePromises.length ? Promise.all(updatePromises).then(commit) : commit()\n}\n\nexport class LayoutAnimationBuilder {\n private sharedTransitions = new Map<string, AnimationOptions>()\n\n private notifyReady: LayoutBuilderResolve = () => {}\n private rejectReady: LayoutBuilderReject = () => {}\n private readyPromise: Promise<GroupAnimation>\n\n private tracked = new Map<HTMLElement, IProjectionNode>()\n private restorePoints = new Map<HTMLElement, RestorePoint>()\n private updateError: unknown\n\n constructor(\n private scope: LayoutAnimationScope,\n private updateDom: () => void | Promise<void>,\n private defaultOptions?: AnimationOptions\n ) {\n this.readyPromise = new Promise<GroupAnimation>((resolve, reject) => {\n this.notifyReady = resolve\n this.rejectReady = reject\n })\n\n if (!pendingBuilders) {\n pendingBuilders = []\n queueMicrotask(flushPendingBuilders)\n }\n pendingBuilders.push(this)\n }\n\n shared(id: string, transition: AnimationOptions): this {\n this.sharedTransitions.set(id, transition)\n return this\n }\n\n then(resolve: LayoutBuilderResolve, reject?: LayoutBuilderReject) {\n return this.readyPromise.then(resolve, reject)\n }\n\n transitionFor(element: HTMLElement): Transition | undefined {\n const layoutId = element.getAttribute(\"data-layout-id\")\n return ((layoutId && this.sharedTransitions.get(layoutId)) ||\n this.defaultOptions) as Transition | undefined\n }\n\n adopt(element: HTMLElement, node: IProjectionNode) {\n this.tracked.set(element, node)\n this.restorePoints.set(element, {\n parent: element.parentElement!,\n next: element.nextSibling,\n })\n }\n\n collectTargets() {\n return collectLayoutElements(this.scope)\n }\n\n runUpdate(): Promise<void> | undefined {\n try {\n const result = this.updateDom()\n if (result && typeof result.then === \"function\") {\n return result.then(undefined, (error: unknown) => {\n this.updateError = error\n })\n }\n } catch (error) {\n this.updateError = error\n }\n return undefined\n }\n\n reconcileAdditions(newMemberIds: Set<string>) {\n for (const element of collectLayoutElements(this.scope)) {\n if (this.tracked.has(element)) continue\n const node = prepareNode(element, this.transitionFor(element))\n this.adopt(element, node)\n node.options.layoutId && newMemberIds.add(node.options.layoutId)\n }\n }\n\n reconcileRemovals(newMemberIds: Set<string>) {\n this.tracked.forEach((node, element) => {\n if (element.isConnected) return\n\n const restore = this.restorePoints.get(element)\n this.restorePoints.delete(element)\n\n const { layoutId } = node.options\n const stack = node.getStack()\n const hasSurvivor =\n stack &&\n stack.members.some(\n (member) =>\n member !== node &&\n (member.instance as HTMLElement | undefined)\n ?.isConnected\n )\n\n /**\n * A removed lead with a surviving stack member - and no\n * replacement member added this commit - runs an exit\n * crossfade: restore the element to its old position in the\n * DOM, relegate it and let the survivor take over. It's\n * removed again once the animation completes.\n */\n if (\n layoutId &&\n node.isLead() &&\n hasSurvivor &&\n !newMemberIds.has(layoutId)\n ) {\n if (restore && restore.parent.isConnected) {\n restore.parent.insertBefore(\n element,\n restore.next?.parentNode === restore.parent\n ? restore.next\n : null\n )\n node.isPresent = false\n node.setOptions({\n onExitComplete: () => {\n element.remove()\n dropNode(element, node)\n },\n })\n if (node.relegate()) return\n\n element.remove()\n }\n }\n\n dropNode(element, node)\n this.tracked.delete(element)\n })\n }\n\n getRoot(): IProjectionNode | undefined {\n let root: IProjectionNode | undefined\n this.tracked.forEach((node) => (root ||= node.root))\n return root\n }\n\n finalize() {\n if (this.updateError) {\n this.rejectReady(this.updateError)\n return\n }\n\n const animations = new Set<GroupAnimation[\"animations\"][number]>()\n this.tracked.forEach((node) => {\n if (node.instance && node.currentAnimation) {\n animations.add(node.currentAnimation)\n }\n })\n\n this.notifyReady(new GroupAnimation([...animations]))\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 if (typeof scopeOrUpdateDom === \"function\") {\n return {\n scope: activeScope.current?.root || document,\n updateDom: scopeOrUpdateDom,\n defaultOptions: updateDomOrOptions as AnimationOptions | undefined,\n }\n }\n\n const scope =\n scopeOrUpdateDom instanceof Document\n ? scopeOrUpdateDom\n : resolveElements(scopeOrUpdateDom)[0] ?? document\n\n return {\n scope,\n updateDom: updateDomOrOptions as () => void,\n defaultOptions: options,\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA2BA,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AC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACzC;AACJ,QAAA,CAAC,CAAC;AAEF,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,cAAc,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IACzD;AACH;SAEe,sBAAsB,CAClC,gBAAkD,EAClD,kBAAoD,EACpD,OAA0B,EAAA;AAM1B,IAAA,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE;QACxC,OAAO;AACH,YAAA,KAAK,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,IAAI,QAAQ;AAC5C,YAAA,SAAS,EAAE,gBAAgB;AAC3B,YAAA,cAAc,EAAE,kBAAkD;SACrE;IACL;AAEA,IAAA,MAAM,KAAK,GACP,gBAAgB,YAAY;AACxB,UAAE;UACA,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ;IAE1D,OAAO;QACH,KAAK;AACL,QAAA,SAAS,EAAE,kBAAgC;AAC3C,QAAA,cAAc,EAAE,OAAO;KAC1B;AACL;;;;"}
1
+ {"version":3,"file":"LayoutAnimationBuilder.mjs","sources":["../../../src/layout/LayoutAnimationBuilder.ts"],"sourcesContent":["import { activeScope } from \"../scope/active\"\nimport { clamp } from \"motion-utils\"\nimport { GroupAnimation } from \"../animation/GroupAnimation\"\nimport type { AnimationOptions, Transition } from \"../animation/types\"\nimport { frameData, frameSteps } from \"../frameloop\"\nimport { microtask } from \"../frameloop/microtask\"\nimport { time } from \"../frameloop/sync-time\"\nimport { HTMLProjectionNode } from \"../projection/node/HTMLProjectionNode\"\nimport type { IProjectionNode } from \"../projection/node/types\"\nimport { visualElementStore } from \"../render/store\"\nimport { resolveVisualElement } from \"./visual-element\"\nimport {\n resolveElements,\n type ElementOrSelector,\n} from \"../utils/resolve-elements\"\nimport { layoutProjection } from \"../gestures/drag/projection\"\n\ntype LayoutAnimationScope = Element | Document\ntype LayoutBuilderResolve = (animation: GroupAnimation) => void\ntype LayoutBuilderReject = (error: unknown) => void\n\ninterface RestorePoint {\n parent: Element\n next: ChildNode | null\n}\n\nconst layoutSelector = \"[data-layout],[data-layout-id]\"\n\n/**\n * All imperatively-created projection nodes live in one persistent tree,\n * shared across animateLayout() calls (and with any React-created nodes,\n * via the singleton document root). Keyed by element for reuse.\n */\nconst layoutNodes = new WeakMap<Element, IProjectionNode>()\n\n/**\n * Builders created within the same synchronous tick are flushed together\n * as a single \"commit\": every node is snapshotted before any updateDom\n * runs, mirroring React batching renders from different parts of the tree.\n */\nlet pendingBuilders: LayoutAnimationBuilder[] | undefined\n\nfunction collectLayoutElements(scope: LayoutAnimationScope): HTMLElement[] {\n const elements: HTMLElement[] = []\n\n if (scope instanceof HTMLElement && scope.matches(layoutSelector)) {\n elements.push(scope)\n }\n\n scope.querySelectorAll(layoutSelector).forEach((element) => {\n if (element instanceof HTMLElement) elements.push(element)\n })\n\n return elements\n}\n\n/**\n * Process any work scheduled on the frameloop now. A previous animation\n * may have been seeked while paused (controls.time = x) without a frame\n * having rendered it - we must materialise that state into the DOM\n * before taking snapshots.\n */\nfunction flushPendingFrame() {\n if (frameData.isProcessing) return\n\n const now = time.now()\n frameData.delta = clamp(0, 1000 / 60, now - frameData.timestamp)\n frameData.timestamp = now\n frameData.isProcessing = true\n frameSteps.update.process(frameData)\n frameSteps.preRender.process(frameData)\n frameSteps.render.process(frameData)\n frameData.isProcessing = false\n}\n\nfunction getProjectionParent(element: Element): IProjectionNode | undefined {\n let ancestor = element.parentElement\n while (ancestor) {\n const node = layoutNodes.get(ancestor)\n if (node?.instance) return node\n ancestor = ancestor.parentElement\n }\n return undefined\n}\n\nfunction readNodeOptions(element: HTMLElement, transition?: Transition) {\n const layoutAttr = element.getAttribute(\"data-layout\")\n const layoutId = element.getAttribute(\"data-layout-id\") ?? undefined\n\n return {\n layoutId,\n layout: layoutAttr !== null ? true : undefined,\n animationType: (!layoutAttr || layoutAttr === \"true\"\n ? \"both\"\n : layoutAttr) as \"both\",\n transition,\n }\n}\n\nfunction prepareNode(\n element: HTMLElement,\n transition?: Transition\n): IProjectionNode {\n let node = layoutNodes.get(element)\n\n if (!node) {\n const visualElement = resolveVisualElement(element)\n\n node = new HTMLProjectionNode(\n visualElement.latestValues,\n getProjectionParent(element)\n )\n visualElement.projection = node\n\n node.setOptions({\n ...readNodeOptions(element, transition),\n visualElement,\n })\n node.mount(element)\n layoutNodes.set(element, node)\n } else {\n node.setOptions(readNodeOptions(element, transition))\n }\n\n node.isPresent = true\n if (node.options.onExitComplete) {\n node.setOptions({ onExitComplete: undefined })\n }\n\n return node\n}\n\n/**\n * Create a node for an element in the shared imperative tree. Returns the\n * node and a function that releases it.\n */\nfunction createLayoutNode(element: HTMLElement): [IProjectionNode, VoidFunction] {\n const node = prepareNode(element)\n\n return [\n node,\n () => layoutNodes.get(element) === node && dropNode(element, node),\n ]\n}\n\n/**\n * Let drag() create its nodes in the shared imperative tree, so drag\n * gestures and layout animations work together.\n */\nlayoutProjection.create = createLayoutNode\n\n/**\n * Get a projection node for an element, so motion/remix can measure and\n * animate its layout. Reuses a node owned by a `motion` component or\n * animateLayout(), otherwise creates one in the shared imperative tree.\n * Returns the node and a function that releases it.\n */\nexport function acquireProjectionNode(\n element: HTMLElement\n): [IProjectionNode, VoidFunction] {\n const owned =\n layoutNodes.get(element) || visualElementStore.get(element)?.projection\n\n /**\n * A VisualElement can outlive a node we released (e.g. a stopped\n * drag()), so only reuse a node that's still mounted.\n */\n return owned?.instance ? [owned, () => {}] : createLayoutNode(element)\n}\n\nfunction sortDocumentOrder(elements: Iterable<HTMLElement>) {\n return [...elements].sort((a, b) =>\n a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1\n )\n}\n\nfunction dropNode(element: Element, node: IProjectionNode) {\n node.setOptions({ onExitComplete: undefined })\n\n /**\n * Stop any lingering animation so it can't leak into future updates.\n * A follow node can share its currentAnimation with a surviving lead\n * (via resumingFrom), in which case it isn't ours to stop.\n */\n const stack = node.getStack()\n if (!stack || node.isLead()) node.currentAnimation?.stop()\n\n node.unmount()\n layoutNodes.delete(element)\n}\n\nfunction flushPendingBuilders() {\n const builders = pendingBuilders\n if (!builders) return\n pendingBuilders = undefined\n\n flushPendingFrame()\n\n /**\n * Discover and mount every node across all builders before snapshotting\n * any of them. Mounting during an active update flags isLayoutDirty,\n * which would make that node's own willUpdate skip its snapshot.\n * Document order guarantees ancestors mount before descendants, even\n * when they're discovered by different builders.\n */\n const targets = new Map<HTMLElement, LayoutAnimationBuilder[]>()\n for (const builder of builders) {\n for (const element of builder.collectTargets()) {\n const owners = targets.get(element)\n owners ? owners.push(builder) : targets.set(element, [builder])\n }\n }\n\n const union = new Map<HTMLElement, IProjectionNode>()\n for (const element of sortDocumentOrder(targets.keys())) {\n const owners = targets.get(element)!\n const node = prepareNode(\n element,\n owners[owners.length - 1].transitionFor(element)\n )\n for (const owner of owners) owner.adopt(element, node)\n union.set(element, node)\n }\n\n union.forEach((node) => {\n node.isLayoutDirty = false\n node.willUpdate()\n })\n\n const updatePromises: Promise<void>[] = []\n for (const builder of builders) {\n const result = builder.runUpdate()\n if (result) updatePromises.push(result)\n }\n\n const commit = () => {\n /**\n * Process all additions before any removals so that, even across\n * builders, a removed member knows whether a replacement with the\n * same layoutId was added in this commit.\n */\n const newMemberIds = new Set<string>()\n for (const builder of builders) {\n builder.reconcileAdditions(newMemberIds)\n }\n for (const builder of builders) {\n builder.reconcileRemovals(newMemberIds)\n }\n\n let root: IProjectionNode | undefined\n union.forEach((node) => (root ||= node.root))\n for (const builder of builders) root ||= builder.getRoot()\n\n root?.didUpdate()\n\n /**\n * The root flushes the update on a microtask, synchronously\n * processing the frame that creates the layout animations. Collect\n * them in a later microtask step of the same pass.\n */\n microtask.render(() => {\n for (const builder of builders) builder.finalize()\n })\n }\n\n updatePromises.length ? Promise.all(updatePromises).then(commit) : commit()\n}\n\n/**\n * Snapshot every pending animateLayout() now, rather than on the next\n * microtask. For renderers that tell us a DOM update is about to happen\n * and then make it synchronously (e.g. a beforeUpdate/commit pair), with\n * updateDom returning a promise that resolves on commit.\n */\nexport const flushLayoutSnapshots = flushPendingBuilders\n\nexport class LayoutAnimationBuilder {\n private sharedTransitions = new Map<string, AnimationOptions>()\n\n private notifyReady: LayoutBuilderResolve = () => {}\n private rejectReady: LayoutBuilderReject = () => {}\n private readyPromise: Promise<GroupAnimation>\n\n private tracked = new Map<HTMLElement, IProjectionNode>()\n private restorePoints = new Map<HTMLElement, RestorePoint>()\n private updateError: unknown\n\n constructor(\n private scope: LayoutAnimationScope,\n private updateDom: () => void | Promise<void>,\n private defaultOptions?: AnimationOptions\n ) {\n this.readyPromise = new Promise<GroupAnimation>((resolve, reject) => {\n this.notifyReady = resolve\n this.rejectReady = reject\n })\n\n if (!pendingBuilders) {\n pendingBuilders = []\n queueMicrotask(flushPendingBuilders)\n }\n pendingBuilders.push(this)\n }\n\n shared(id: string, transition: AnimationOptions): this {\n this.sharedTransitions.set(id, transition)\n return this\n }\n\n then(resolve: LayoutBuilderResolve, reject?: LayoutBuilderReject) {\n return this.readyPromise.then(resolve, reject)\n }\n\n transitionFor(element: HTMLElement): Transition | undefined {\n const layoutId = element.getAttribute(\"data-layout-id\")\n return ((layoutId && this.sharedTransitions.get(layoutId)) ||\n this.defaultOptions) as Transition | undefined\n }\n\n adopt(element: HTMLElement, node: IProjectionNode) {\n this.tracked.set(element, node)\n this.restorePoints.set(element, {\n parent: element.parentElement!,\n next: element.nextSibling,\n })\n }\n\n collectTargets() {\n return collectLayoutElements(this.scope)\n }\n\n runUpdate(): Promise<void> | undefined {\n try {\n const result = this.updateDom()\n if (result && typeof result.then === \"function\") {\n return result.then(undefined, (error: unknown) => {\n this.updateError = error\n })\n }\n } catch (error) {\n this.updateError = error\n }\n return undefined\n }\n\n reconcileAdditions(newMemberIds: Set<string>) {\n for (const element of collectLayoutElements(this.scope)) {\n if (this.tracked.has(element)) continue\n const node = prepareNode(element, this.transitionFor(element))\n this.adopt(element, node)\n node.options.layoutId && newMemberIds.add(node.options.layoutId)\n }\n }\n\n reconcileRemovals(newMemberIds: Set<string>) {\n this.tracked.forEach((node, element) => {\n if (element.isConnected) return\n\n const restore = this.restorePoints.get(element)\n this.restorePoints.delete(element)\n\n const { layoutId } = node.options\n const stack = node.getStack()\n const hasSurvivor =\n stack &&\n stack.members.some(\n (member) =>\n member !== node &&\n (member.instance as HTMLElement | undefined)\n ?.isConnected\n )\n\n /**\n * A removed lead with a surviving stack member - and no\n * replacement member added this commit - runs an exit\n * crossfade: restore the element to its old position in the\n * DOM, relegate it and let the survivor take over. It's\n * removed again once the animation completes.\n */\n if (\n layoutId &&\n node.isLead() &&\n hasSurvivor &&\n !newMemberIds.has(layoutId)\n ) {\n if (restore && restore.parent.isConnected) {\n restore.parent.insertBefore(\n element,\n restore.next?.parentNode === restore.parent\n ? restore.next\n : null\n )\n node.isPresent = false\n node.setOptions({\n onExitComplete: () => {\n element.remove()\n dropNode(element, node)\n },\n })\n if (node.relegate()) return\n\n element.remove()\n }\n }\n\n dropNode(element, node)\n this.tracked.delete(element)\n })\n }\n\n getRoot(): IProjectionNode | undefined {\n let root: IProjectionNode | undefined\n this.tracked.forEach((node) => (root ||= node.root))\n return root\n }\n\n finalize() {\n if (this.updateError) {\n this.rejectReady(this.updateError)\n return\n }\n\n const animations = new Set<GroupAnimation[\"animations\"][number]>()\n this.tracked.forEach((node) => {\n if (node.instance && node.currentAnimation) {\n animations.add(node.currentAnimation)\n }\n })\n\n this.notifyReady(new GroupAnimation([...animations]))\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 if (typeof scopeOrUpdateDom === \"function\") {\n return {\n scope: activeScope.current?.root || document,\n updateDom: scopeOrUpdateDom,\n defaultOptions: updateDomOrOptions as AnimationOptions | undefined,\n }\n }\n\n const scope =\n scopeOrUpdateDom instanceof Document\n ? scopeOrUpdateDom\n : resolveElements(scopeOrUpdateDom)[0] ?? document\n\n return {\n scope,\n updateDom: updateDomOrOptions as () => void,\n defaultOptions: options,\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA0BA,MAAM,cAAc,GAAG,gCAAgC;AAEvD;;;;AAIG;AACH,MAAM,WAAW,GAAG,IAAI,OAAO,EAA4B;AAE3D;;;;AAIG;AACH,IAAI,eAAqD;AAEzD,SAAS,qBAAqB,CAAC,KAA2B,EAAA;IACtD,MAAM,QAAQ,GAAkB,EAAE;IAElC,IAAI,KAAK,YAAY,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;AAC/D,QAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;IACxB;IAEA,KAAK,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,KAAI;QACvD,IAAI,OAAO,YAAY,WAAW;AAAE,YAAA,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;AAC9D,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,QAAQ;AACnB;AAEA;;;;;AAKG;AACH,SAAS,iBAAiB,GAAA;IACtB,IAAI,SAAS,CAAC,YAAY;QAAE;AAE5B,IAAA,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;AACtB,IAAA,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC;AAChE,IAAA,SAAS,CAAC,SAAS,GAAG,GAAG;AACzB,IAAA,SAAS,CAAC,YAAY,GAAG,IAAI;AAC7B,IAAA,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;AACpC,IAAA,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;AACvC,IAAA,UAAU,CAAC,MAAM,CAAC,OAAO,CAA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E,WAAW,CAAC,OAAO,EAAE,IAAI,IAAI,QAAQ;AAC5C,YAAA,SAAS,EAAE,gBAAgB;AAC3B,YAAA,cAAc,EAAE,kBAAkD;SACrE;IACL;AAEA,IAAA,MAAM,KAAK,GACP,gBAAgB,YAAY;AACxB,UAAE;UACA,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ;IAE1D,OAAO;QACH,KAAK;AACL,QAAA,SAAS,EAAE,kBAAgC;AAC3C,QAAA,cAAc,EAAE,OAAO;KAC1B;AACL;;;;"}
@@ -0,0 +1,48 @@
1
+ import { handOffElementState } from '../animation/animate/element.mjs';
2
+ import { hasTransform } from '../projection/utils/has-transform.mjs';
3
+ import { HTMLVisualElement } from '../render/html/HTMLVisualElement.mjs';
4
+ import { visualElementStore } from '../render/store.mjs';
5
+
6
+ /**
7
+ * Get the VisualElement that imperative APIs like animateLayout() and
8
+ * drag() render an element with, creating one if it has none, ready for
9
+ * a projection node to be attached.
10
+ */
11
+ function resolveVisualElement(element) {
12
+ let visualElement = visualElementStore.get(element);
13
+ if (!visualElement) {
14
+ visualElement = new HTMLVisualElement({
15
+ props: {},
16
+ presenceContext: null,
17
+ visualState: {
18
+ latestValues: {},
19
+ renderState: {
20
+ transform: {},
21
+ transformOrigin: {},
22
+ style: {},
23
+ vars: {},
24
+ },
25
+ },
26
+ }, { allowProjection: true });
27
+ /**
28
+ * Values animate() has been rendering on this element move to
29
+ * the VisualElement, so the layout animation composes with
30
+ * them instead of overwriting them.
31
+ */
32
+ handOffElementState(element, visualElement);
33
+ }
34
+ /**
35
+ * A first-time element may carry a projection transform in its
36
+ * inline style (e.g. it was cloned from an element mid-animation).
37
+ * That transform isn't tracked in latestValues so the engine can't
38
+ * reset it before measuring - clear it now so the first layout
39
+ * measurement isn't inflated.
40
+ */
41
+ if (element.style.transform && !hasTransform(visualElement.latestValues)) {
42
+ element.style.transform = "";
43
+ }
44
+ return visualElement;
45
+ }
46
+
47
+ export { resolveVisualElement };
48
+ //# sourceMappingURL=visual-element.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visual-element.mjs","sources":["../../../src/layout/visual-element.ts"],"sourcesContent":["import { handOffElementState } from \"../animation/animate/element\"\nimport { hasTransform } from \"../projection/utils/has-transform\"\nimport { HTMLVisualElement } from \"../render/html/HTMLVisualElement\"\nimport { visualElementStore } from \"../render/store\"\n\n/**\n * Get the VisualElement that imperative APIs like animateLayout() and\n * drag() render an element with, creating one if it has none, ready for\n * a projection node to be attached.\n */\nexport function resolveVisualElement(element: HTMLElement): HTMLVisualElement {\n let visualElement = visualElementStore.get(element) as\n | HTMLVisualElement\n | undefined\n\n if (!visualElement) {\n visualElement = new HTMLVisualElement(\n {\n props: {},\n presenceContext: null,\n visualState: {\n latestValues: {},\n renderState: {\n transform: {},\n transformOrigin: {},\n style: {},\n vars: {},\n },\n },\n },\n { allowProjection: true }\n )\n\n /**\n * Values animate() has been rendering on this element move to\n * the VisualElement, so the layout animation composes with\n * them instead of overwriting them.\n */\n handOffElementState(element, visualElement)\n }\n\n /**\n * A first-time element may carry a projection transform in its\n * inline style (e.g. it was cloned from an element mid-animation).\n * That transform isn't tracked in latestValues so the engine can't\n * reset it before measuring - clear it now so the first layout\n * measurement isn't inflated.\n */\n if (element.style.transform && !hasTransform(visualElement.latestValues)) {\n element.style.transform = \"\"\n }\n\n return visualElement\n}\n"],"names":[],"mappings":";;;;;AAKA;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,OAAoB,EAAA;IACrD,IAAI,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAEnC;IAEf,IAAI,CAAC,aAAa,EAAE;QAChB,aAAa,GAAG,IAAI,iBAAiB,CACjC;AACI,YAAA,KAAK,EAAE,EAAE;AACT,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,WAAW,EAAE;AACT,gBAAA,YAAY,EAAE,EAAE;AAChB,gBAAA,WAAW,EAAE;AACT,oBAAA,SAAS,EAAE,EAAE;AACb,oBAAA,eAAe,EAAE,EAAE;AACnB,oBAAA,KAAK,EAAE,EAAE;AACT,oBAAA,IAAI,EAAE,EAAE;AACX,iBAAA;AACJ,aAAA;AACJ,SAAA,EACD,EAAE,eAAe,EAAE,IAAI,EAAE,CAC5B;AAED;;;;AAIG;AACH,QAAA,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC;IAC/C;AAEA;;;;;;AAMG;AACH,IAAA,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE;AACtE,QAAA,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE;IAChC;AAEA,IAAA,OAAO,aAAa;AACxB;;;;"}
@@ -0,0 +1,25 @@
1
+ import { noop } from 'motion-utils';
2
+
3
+ const userAgentContains = (string) => typeof navigator !== "undefined" &&
4
+ navigator.userAgent &&
5
+ navigator.userAgent.toLowerCase().includes(string);
6
+ /**
7
+ * Measured bounding boxes must be rounded in Safari and
8
+ * left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
9
+ * can appear to jump.
10
+ */
11
+ const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
12
+ ? Math.round
13
+ : noop;
14
+ function roundAxis(axis) {
15
+ // Round to the nearest .5 pixels to support subpixel layouts
16
+ axis.min = roundPoint(axis.min);
17
+ axis.max = roundPoint(axis.max);
18
+ }
19
+ function roundBox(box) {
20
+ roundAxis(box.x);
21
+ roundAxis(box.y);
22
+ }
23
+
24
+ export { roundBox };
25
+ //# sourceMappingURL=round.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"round.mjs","sources":["../../../../src/projection/geometry/round.ts"],"sourcesContent":["import type { Axis, Box } from \"motion-utils\"\nimport { noop } from \"motion-utils\"\n\nconst userAgentContains = (string: string) =>\n typeof navigator !== \"undefined\" &&\n navigator.userAgent &&\n navigator.userAgent.toLowerCase().includes(string)\n\n/**\n * Measured bounding boxes must be rounded in Safari and\n * left untouched in Chrome, otherwise non-integer layouts within scaled-up elements\n * can appear to jump.\n */\nconst roundPoint =\n userAgentContains(\"applewebkit/\") && !userAgentContains(\"chrome/\")\n ? Math.round\n : noop\n\nfunction roundAxis(axis: Axis): void {\n // Round to the nearest .5 pixels to support subpixel layouts\n axis.min = roundPoint(axis.min)\n axis.max = roundPoint(axis.max)\n}\n\nexport function roundBox(box: Box): void {\n roundAxis(box.x)\n roundAxis(box.y)\n}\n"],"names":[],"mappings":";;AAGA,MAAM,iBAAiB,GAAG,CAAC,MAAc,KACrC,OAAO,SAAS,KAAK,WAAW;AAChC,IAAA,SAAS,CAAC,SAAS;IACnB,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;AAEtD;;;;AAIG;AACH,MAAM,UAAU,GACZ,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,iBAAiB,CAAC,SAAS;MAC3D,IAAI,CAAC;MACL,IAAI;AAEd,SAAS,SAAS,CAAC,IAAU,EAAA;;IAEzB,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;IAC/B,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;AACnC;AAEM,SAAU,QAAQ,CAAC,GAAQ,EAAA;AAC7B,IAAA,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AAChB,IAAA,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AACpB;;;;"}
@@ -1,17 +1,11 @@
1
1
  import { addDomEvent } from '../../events/add-dom-event.mjs';
2
+ import { measureDocumentScroll } from '../utils/measure.mjs';
2
3
  import { createProjectionNode } from './create-projection-node.mjs';
3
4
 
4
5
  const DocumentProjectionNode =
5
6
  /* @__PURE__ */ createProjectionNode({
6
7
  attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
7
- measureScroll: () => ({
8
- x: document.documentElement.scrollLeft ||
9
- document.body?.scrollLeft ||
10
- 0,
11
- y: document.documentElement.scrollTop ||
12
- document.body?.scrollTop ||
13
- 0,
14
- }),
8
+ measureScroll: measureDocumentScroll,
15
9
  checkIsScrollRoot: () => true,
16
10
  });
17
11
 
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentProjectionNode.mjs","sources":["../../../../src/projection/node/DocumentProjectionNode.ts"],"sourcesContent":["import { addDomEvent } from \"../../events/add-dom-event\"\nimport { createProjectionNode } from \"./create-projection-node\"\n\nexport const DocumentProjectionNode =\n /* @__PURE__ */ createProjectionNode<Window>({\n attachResizeListener: (\n ref: Window | Element,\n notify: VoidFunction\n ): VoidFunction => addDomEvent(ref, \"resize\", notify),\n measureScroll: () => ({\n x:\n document.documentElement.scrollLeft ||\n document.body?.scrollLeft ||\n 0,\n y:\n document.documentElement.scrollTop ||\n document.body?.scrollTop ||\n 0,\n }),\n checkIsScrollRoot: () => true,\n })\n"],"names":[],"mappings":";;;MAGa,sBAAsB;AAC/B,gBAAgB,oBAAoB,CAAS;AACzC,IAAA,oBAAoB,EAAE,CAClB,GAAqB,EACrB,MAAoB,KACL,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC;AACrD,IAAA,aAAa,EAAE,OAAO;AAClB,QAAA,CAAC,EACG,QAAQ,CAAC,eAAe,CAAC,UAAU;YACnC,QAAQ,CAAC,IAAI,EAAE,UAAU;YACzB,CAAC;AACL,QAAA,CAAC,EACG,QAAQ,CAAC,eAAe,CAAC,SAAS;YAClC,QAAQ,CAAC,IAAI,EAAE,SAAS;YACxB,CAAC;KACR,CAAC;AACF,IAAA,iBAAiB,EAAE,MAAM,IAAI;AAChC,CAAA;;;;"}
1
+ {"version":3,"file":"DocumentProjectionNode.mjs","sources":["../../../../src/projection/node/DocumentProjectionNode.ts"],"sourcesContent":["import { addDomEvent } from \"../../events/add-dom-event\"\nimport { measureDocumentScroll } from \"../utils/measure\"\nimport { createProjectionNode } from \"./create-projection-node\"\n\nexport const DocumentProjectionNode =\n /* @__PURE__ */ createProjectionNode<Window>({\n attachResizeListener: (\n ref: Window | Element,\n notify: VoidFunction\n ): VoidFunction => addDomEvent(ref, \"resize\", notify),\n measureScroll: measureDocumentScroll,\n checkIsScrollRoot: () => true,\n })\n"],"names":[],"mappings":";;;;MAIa,sBAAsB;AAC/B,gBAAgB,oBAAoB,CAAS;AACzC,IAAA,oBAAoB,EAAE,CAClB,GAAqB,EACrB,MAAoB,KACL,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC;AACrD,IAAA,aAAa,EAAE,qBAAqB;AACpC,IAAA,iBAAiB,EAAE,MAAM,IAAI;AAChC,CAAA;;;;"}
@@ -1,4 +1,4 @@
1
- import { SubscriptionManager, clamp, noop } from 'motion-utils';
1
+ import { SubscriptionManager, clamp } from 'motion-utils';
2
2
  import { animateSingleValue } from '../../animation/animate/single-value.mjs';
3
3
  import { notifyLayoutAnimationStart } from '../../animation/utils/notify-inspector.mjs';
4
4
  import { getOptimisedAppearId } from '../../animation/optimized-appear/get-appear-id.mjs';
@@ -8,6 +8,7 @@ import { time } from '../../frameloop/sync-time.mjs';
8
8
  import { scaleCorrectors } from '../styles/scale-correction.mjs';
9
9
  import { statsBuffer } from '../../stats/buffer.mjs';
10
10
  import { delay } from '../../utils/delay.mjs';
11
+ import { isRefObject } from '../../utils/is-ref-object.mjs';
11
12
  import { isSVGElement } from '../../utils/is-svg-element.mjs';
12
13
  import { isSVGSVGElement } from '../../utils/is-svg-svg-element.mjs';
13
14
  import { mixNumber } from '../../utils/mix/number.mjs';
@@ -19,6 +20,7 @@ import { copyBoxInto, copyAxisDeltaInto, copyAxisInto } from '../geometry/copy.m
19
20
  import { translateAxis, transformBox, applyBoxDelta, applyTreeDeltas } from '../geometry/delta-apply.mjs';
20
21
  import { calcLength, calcRelativeBox, calcRelativePosition, calcBoxDelta, isNear } from '../geometry/delta-calc.mjs';
21
22
  import { removeBoxTransforms } from '../geometry/delta-remove.mjs';
23
+ import { roundBox } from '../geometry/round.mjs';
22
24
  import { createBox, createDelta } from '../geometry/models.mjs';
23
25
  import { boxEqualsRounded, isDeltaZero, axisDeltaEquals, boxEquals, aspectRatio } from '../geometry/utils.mjs';
24
26
  import { NodeStack } from '../shared/stack.mjs';
@@ -31,11 +33,6 @@ import { globalProjectionState } from './state.mjs';
31
33
  import { frame, cancelFrame, frameSteps } from '../../frameloop/frame.mjs';
32
34
  import { frameData } from '../../frameloop/frame-data.mjs';
33
35
 
34
- const metrics = {
35
- nodes: 0,
36
- calculatedTargetDeltas: 0,
37
- calculatedProjections: 0,
38
- };
39
36
  /**
40
37
  * Transforms that distort an element's layout, so must be reset before measuring.
41
38
  */
@@ -83,6 +80,13 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
83
80
  cancelTreeOptimisedTransformAnimations(parent);
84
81
  }
85
82
  }
83
+ function getClosestProjectingNode(visualElement) {
84
+ if (!visualElement)
85
+ return undefined;
86
+ return visualElement.options.allowProjection !== false
87
+ ? visualElement.projection
88
+ : getClosestProjectingNode(visualElement.parent);
89
+ }
86
90
  function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
87
91
  /**
88
92
  * Correctors registered via addScaleCorrector before projection loaded
@@ -95,6 +99,57 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
95
99
  ...scaleCorrectors,
96
100
  });
97
101
  return class ProjectionNode {
102
+ /**
103
+ * Create the projection node of a `motion` component's VisualElement,
104
+ * from its props. This runs while the component renders, before its
105
+ * children. It's here rather than in the component so React
106
+ * bundles only include it with the features that supply a
107
+ * ProjectionNode. Vanilla bundles that use the projection node
108
+ * (drag(), animateLayout()) include it too, as a class static
109
+ * can't be tree-shaken.
110
+ */
111
+ static create(visualElement, props, initialPromotionConfig) {
112
+ const { layoutId, layout, drag, dragConstraints, layoutScroll, layoutRoot, layoutAnchor, layoutCrossfade, } = props;
113
+ const projection = (visualElement.projection = new this(visualElement.latestValues, props["data-framer-portal-id"]
114
+ ? undefined
115
+ : getClosestProjectingNode(visualElement.parent)));
116
+ projection.setOptions({
117
+ layoutId,
118
+ layout,
119
+ alwaysMeasureLayout: Boolean(drag) ||
120
+ (dragConstraints && isRefObject(dragConstraints)),
121
+ visualElement,
122
+ /**
123
+ * TODO: Update options in an effect. This could be tricky as it'll be too late
124
+ * to update by the time layout animations run.
125
+ * We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
126
+ * ensuring it gets called if there's no potential layout animations.
127
+ *
128
+ */
129
+ animationType: typeof layout === "string" ? layout : "both",
130
+ initialPromotionConfig,
131
+ crossfade: layoutCrossfade,
132
+ layoutScroll,
133
+ layoutRoot,
134
+ layoutAnchor,
135
+ });
136
+ /**
137
+ * This node will take over from its layoutId's current lead, so snapshot
138
+ * the lead now, while rendering. By the time the lead unmounts (or this
139
+ * node mounts) React may already have committed DOM changes that come
140
+ * before it in the tree, like a sibling changing height, and a snapshot
141
+ * taken then starts the animation from a position never seen on screen.
142
+ *
143
+ * If React discards this render (e.g. it suspends), nothing else
144
+ * completes the update, so check it after the next frame as an
145
+ * unmounting node does.
146
+ */
147
+ const lead = projection.getStack()?.lead;
148
+ if (lead && !projection.root.isUpdateBlocked()) {
149
+ lead.willUpdate();
150
+ lead.scheduleCheckAfterUnmount();
151
+ }
152
+ }
98
153
  constructor(latestValues = {}, parent = defaultParent?.()) {
99
154
  /**
100
155
  * A unique ID generated for every projection node.
@@ -207,23 +262,14 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
207
262
  */
208
263
  this.updateProjection = () => {
209
264
  this.projectionUpdateScheduled = false;
210
- /**
211
- * Reset debug counts. Manually resetting rather than creating a new
212
- * object each frame.
213
- */
214
- if (statsBuffer.value) {
215
- metrics.nodes =
216
- metrics.calculatedTargetDeltas =
217
- metrics.calculatedProjections =
218
- 0;
219
- }
220
265
  this.nodes.forEach(propagateDirtyNodes);
221
266
  this.nodes.forEach(resolveTargetDelta);
222
267
  this.nodes.forEach(calcProjection);
223
268
  this.nodes.forEach(cleanDirtyNodes);
224
- if (statsBuffer.addProjectionMetrics) {
225
- statsBuffer.addProjectionMetrics(metrics);
226
- }
269
+ /**
270
+ * Record this frame's debug counts, if recordStats() is running.
271
+ */
272
+ statsBuffer.countProjection?.();
227
273
  };
228
274
  /**
229
275
  * Frame calculations
@@ -939,9 +985,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
939
985
  /**
940
986
  * Increase debug counter for resolved target deltas
941
987
  */
942
- if (statsBuffer.value) {
943
- metrics.calculatedTargetDeltas++;
944
- }
988
+ statsBuffer.countProjection?.(1); // calculatedTargetDeltas
945
989
  }
946
990
  getClosestProjectingParent() {
947
991
  if (!this.parent ||
@@ -1089,9 +1133,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1089
1133
  /**
1090
1134
  * Increase debug counter for recalculated projections
1091
1135
  */
1092
- if (statsBuffer.value) {
1093
- metrics.calculatedProjections++;
1094
- }
1136
+ statsBuffer.countProjection?.(2); // calculatedProjections
1095
1137
  }
1096
1138
  hide() {
1097
1139
  this.isVisible = false;
@@ -1618,9 +1660,7 @@ function propagateDirtyNodes(node) {
1618
1660
  /**
1619
1661
  * Increase debug counter for nodes encountered this frame
1620
1662
  */
1621
- if (statsBuffer.value) {
1622
- metrics.nodes++;
1623
- }
1663
+ statsBuffer.countProjection?.(0); // nodes
1624
1664
  if (!node.parent)
1625
1665
  return;
1626
1666
  /**
@@ -1751,26 +1791,6 @@ const defaultLayoutTransition = {
1751
1791
  duration: 0.45,
1752
1792
  ease: [0.4, 0, 0.1, 1],
1753
1793
  };
1754
- const userAgentContains = (string) => typeof navigator !== "undefined" &&
1755
- navigator.userAgent &&
1756
- navigator.userAgent.toLowerCase().includes(string);
1757
- /**
1758
- * Measured bounding boxes must be rounded in Safari and
1759
- * left untouched in Chrome, otherwise non-integer layouts within scaled-up elements
1760
- * can appear to jump.
1761
- */
1762
- const roundPoint = userAgentContains("applewebkit/") && !userAgentContains("chrome/")
1763
- ? Math.round
1764
- : noop;
1765
- function roundAxis(axis) {
1766
- // Round to the nearest .5 pixels to support subpixel layouts
1767
- axis.min = roundPoint(axis.min);
1768
- axis.max = roundPoint(axis.max);
1769
- }
1770
- function roundBox(box) {
1771
- roundAxis(box.x);
1772
- roundAxis(box.y);
1773
- }
1774
1794
  /**
1775
1795
  * Align an axis to the start of another, keeping the length of a layout axis.
1776
1796
  * The length is read first, as output can be the layout axis itself.