motion-dom 14.3.1 → 14.4.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanSession.mjs","sources":["../../../../src/gestures/pan/PanSession.ts"],"sourcesContent":["import { addPointerEvent } from \"../../events/add-pointer-event\"\nimport { extractEventInfo } from \"../../events/event-info\"\nimport { cancelFrame, frame } from \"../../frameloop/frame\"\nimport { frameData } from \"../../frameloop/frame-data\"\nimport { time } from \"../../frameloop/sync-time\"\nimport type { EventInfo } from \"../../node/types\"\nimport { distance2D } from \"../../utils/distance\"\nimport { isPrimaryPointer } from \"../utils/is-primary-pointer\"\nimport type { PanHandler } from \"./types\"\nimport {\n millisecondsToSeconds,\n pipe,\n Point,\n secondsToMilliseconds,\n TransformPoint,\n} from \"motion-utils\"\n\ninterface PanSessionHandlers {\n onSessionStart: PanHandler\n onStart: PanHandler\n onMove: PanHandler\n onEnd: PanHandler\n onSessionEnd: PanHandler\n resumeAnimation: () => void\n}\n\ninterface PanSessionOptions {\n transformPagePoint?: TransformPoint\n dragSnapToOrigin?: boolean | \"x\" | \"y\"\n distanceThreshold?: number\n contextWindow?: (Window & typeof globalThis) | null\n /**\n * Element being dragged. When provided, scroll events on its\n * ancestors and window are compensated so the gesture continues\n * smoothly during scroll.\n */\n element?: HTMLElement | null\n}\n\ninterface TimestampedPoint extends Point {\n timestamp: number\n}\n\nconst overflowStyles = /*#__PURE__*/ new Set([\"auto\", \"scroll\"])\n\nexport class PanSession {\n private history: TimestampedPoint[]\n\n private startEvent: PointerEvent | null = null\n\n private lastMoveEvent: PointerEvent | null = null\n\n private lastMoveEventInfo: EventInfo | null = null\n\n /**\n * Raw (untransformed) event info, re-transformed each frame\n * so transformPagePoint sees the current parent matrix.\n */\n private lastRawMoveEventInfo: EventInfo | null = null\n\n /**\n * Whether a pointermove has arrived since the last updatePoint.\n */\n private hasPendingMove?: boolean\n\n private transformPagePoint?: TransformPoint\n\n private handlers: Partial<PanSessionHandlers> = {}\n\n private removeListeners: Function\n\n /**\n * For determining if an animation should resume after it is interrupted\n */\n private dragSnapToOrigin: boolean | \"x\" | \"y\"\n\n /**\n * The distance after which panning should start.\n */\n private distanceThreshold: number\n\n private contextWindow: PanSessionOptions[\"contextWindow\"] = window\n\n /**\n * Scroll positions of scrollable ancestors and window.\n */\n private scrollPositions: Map<Element | Window, Point> = new Map()\n\n /**\n * Cleanup function for scroll listeners.\n */\n private removeScrollListeners: (() => void) | null = null\n\n constructor(\n event: PointerEvent,\n handlers: Partial<PanSessionHandlers>,\n {\n transformPagePoint,\n contextWindow = window,\n dragSnapToOrigin = false,\n distanceThreshold = 3,\n element,\n }: PanSessionOptions = {}\n ) {\n // If we have more than one touch, don't start detecting this gesture\n if (!isPrimaryPointer(event)) return\n\n this.dragSnapToOrigin = dragSnapToOrigin\n this.handlers = handlers\n this.transformPagePoint = transformPagePoint\n this.distanceThreshold = distanceThreshold\n this.contextWindow = contextWindow || window\n\n const info = extractEventInfo(event)\n const initialInfo = transformPoint(info, this.transformPagePoint)\n const { point } = initialInfo\n\n const { timestamp } = frameData\n\n this.history = [{ ...point, timestamp }]\n\n const { onSessionStart } = handlers\n onSessionStart &&\n onSessionStart(event, getPanInfo(initialInfo, this.history))\n\n // Listen in the capture phase so a descendant calling\n // stopPropagation() (e.g. in its own pointerup handler) can't\n // prevent the gesture from ending. See #2794.\n const eventOptions = { passive: true, capture: true }\n this.removeListeners = pipe(\n addPointerEvent(\n this.contextWindow,\n \"pointermove\",\n this.handlePointerMove,\n eventOptions\n ),\n addPointerEvent(\n this.contextWindow,\n \"pointerup\",\n this.handlePointerUp,\n eventOptions\n ),\n addPointerEvent(\n this.contextWindow,\n \"pointercancel\",\n this.handlePointerUp,\n eventOptions\n )\n )\n\n // Start scroll tracking if element provided\n if (element) {\n this.startScrollTracking(element)\n }\n }\n\n /**\n * Start tracking scroll on ancestors and window.\n */\n private startScrollTracking(element: HTMLElement): void {\n // Store initial scroll positions for scrollable ancestors\n let current = element.parentElement\n while (current) {\n const style = getComputedStyle(current)\n if (\n overflowStyles.has(style.overflowX) ||\n overflowStyles.has(style.overflowY)\n ) {\n this.scrollPositions.set(current, {\n x: current.scrollLeft,\n y: current.scrollTop,\n })\n }\n current = current.parentElement\n }\n\n // Track window scroll\n this.scrollPositions.set(window, {\n x: window.scrollX,\n y: window.scrollY,\n })\n\n // Capture listener catches element scroll events as they bubble\n window.addEventListener(\"scroll\", this.onElementScroll, {\n capture: true,\n })\n\n // Direct window scroll listener (window scroll doesn't bubble)\n window.addEventListener(\"scroll\", this.onWindowScroll)\n\n this.removeScrollListeners = () => {\n window.removeEventListener(\"scroll\", this.onElementScroll, {\n capture: true,\n })\n window.removeEventListener(\"scroll\", this.onWindowScroll)\n }\n }\n\n private onElementScroll = (event: Event): void => {\n this.handleScroll(event.target as Element)\n }\n\n private onWindowScroll = (): void => {\n this.handleScroll(window)\n }\n\n /**\n * Handle scroll compensation during drag.\n *\n * For element scroll: adjusts history origin since pageX/pageY doesn't change.\n * For window scroll: adjusts lastMoveEventInfo since pageX/pageY would change.\n */\n private handleScroll(target: Element | Window): void {\n const initial = this.scrollPositions.get(target)\n if (!initial) return\n\n const isWindow = target === window\n const current = isWindow\n ? { x: window.scrollX, y: window.scrollY }\n : {\n x: (target as Element).scrollLeft,\n y: (target as Element).scrollTop,\n }\n\n const delta = { x: current.x - initial.x, y: current.y - initial.y }\n if (delta.x === 0 && delta.y === 0) return\n\n if (isWindow) {\n // Window scroll: pageX/pageY changes, so update lastMoveEventInfo\n if (this.lastMoveEventInfo) {\n this.lastMoveEventInfo.point.x += delta.x\n this.lastMoveEventInfo.point.y += delta.y\n }\n } else {\n // Element scroll: pageX/pageY unchanged, so adjust history origin\n if (this.history.length > 0) {\n this.history[0].x -= delta.x\n this.history[0].y -= delta.y\n }\n }\n\n this.scrollPositions.set(target, current)\n frame.update(this.updatePoint, true)\n }\n\n private updatePoint = () => {\n if (!(this.lastMoveEvent && this.lastMoveEventInfo)) return\n this.hasPendingMove = false\n\n // Re-transform raw point through current transformPagePoint so\n // animated parent transforms (e.g. rotation) are picked up each frame\n if (this.lastRawMoveEventInfo) {\n this.lastMoveEventInfo = transformPoint(\n this.lastRawMoveEventInfo,\n this.transformPagePoint\n )\n }\n\n const info = getPanInfo(this.lastMoveEventInfo, this.history)\n const isPanStarted = this.startEvent !== null\n\n // Only start panning if the offset is larger than 3 pixels. If we make it\n // any larger than this we'll want to reset the pointer history\n // on the first update to avoid visual snapping to the cursor.\n const isDistancePastThreshold =\n distance2D(info.offset, { x: 0, y: 0 }) >= this.distanceThreshold\n\n if (!isPanStarted && !isDistancePastThreshold) return\n\n const { point } = info\n this.history.push({ ...point, timestamp: time.now() })\n\n const { onStart, onMove } = this.handlers\n\n if (!isPanStarted) {\n onStart && onStart(this.lastMoveEvent, info)\n this.startEvent = this.lastMoveEvent\n }\n\n onMove && onMove(this.lastMoveEvent, info)\n }\n\n private handlePointerMove = (event: PointerEvent, info: EventInfo) => {\n this.lastMoveEvent = event\n this.lastRawMoveEventInfo = info\n this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint)\n this.hasPendingMove = true\n\n // Throttle mouse move event to once per frame\n frame.update(this.updatePoint, true)\n }\n\n private handlePointerUp = (event: PointerEvent, info: EventInfo) => {\n // Browsers flush a coalesced pointermove immediately before\n // pointerup, so the final move can still be waiting for a frame.\n this.hasPendingMove && this.updatePoint()\n this.end()\n\n const { onEnd, onSessionEnd, resumeAnimation } = this.handlers\n\n // Resume animation if dragSnapToOrigin is set OR if no drag started (user just clicked)\n // This ensures constraint animations continue when interrupted by a click\n if (this.dragSnapToOrigin || !this.startEvent) {\n resumeAnimation && resumeAnimation()\n }\n if (!(this.lastMoveEvent && this.lastMoveEventInfo)) return\n\n const panInfo = getPanInfo(\n event.type === \"pointercancel\"\n ? this.lastMoveEventInfo\n : transformPoint(info, this.transformPagePoint),\n this.history\n )\n\n if (this.startEvent && onEnd) {\n onEnd(event, panInfo)\n }\n\n onSessionEnd && onSessionEnd(event, panInfo)\n }\n\n updateHandlers(handlers: Partial<PanSessionHandlers>) {\n this.handlers = handlers\n }\n\n end() {\n this.removeListeners && this.removeListeners()\n this.removeScrollListeners && this.removeScrollListeners()\n this.scrollPositions.clear()\n cancelFrame(this.updatePoint)\n }\n}\n\nfunction transformPoint(\n info: EventInfo,\n transformPagePoint?: (point: Point) => Point\n) {\n return transformPagePoint ? { point: transformPagePoint(info.point) } : info\n}\n\nfunction subtractPoint(a: Point, b: Point): Point {\n return { x: a.x - b.x, y: a.y - b.y }\n}\n\nfunction getPanInfo({ point }: EventInfo, history: TimestampedPoint[]) {\n return {\n point,\n delta: subtractPoint(point, lastDevicePoint(history)),\n offset: subtractPoint(point, startDevicePoint(history)),\n velocity: getVelocity(history, 0.1),\n }\n}\n\nfunction startDevicePoint(history: TimestampedPoint[]): TimestampedPoint {\n return history[0]\n}\n\nfunction lastDevicePoint(history: TimestampedPoint[]): TimestampedPoint {\n return history[history.length - 1]\n}\n\nfunction getVelocity(history: TimestampedPoint[], timeDelta: number): Point {\n if (history.length < 2) {\n return { x: 0, y: 0 }\n }\n\n let i = history.length - 1\n let timestampedPoint: TimestampedPoint | null = null\n const lastPoint = lastDevicePoint(history)\n while (i >= 0) {\n timestampedPoint = history[i]\n if (\n lastPoint.timestamp - timestampedPoint.timestamp >\n secondsToMilliseconds(timeDelta)\n ) {\n break\n }\n i--\n }\n\n if (!timestampedPoint) {\n return { x: 0, y: 0 }\n }\n\n /**\n * If the selected point is the pointer-down origin (history[0]),\n * there are better movement points available, and the time gap\n * is suspiciously large (>2x timeDelta), use the next point instead.\n * This prevents stale pointer-down points from diluting velocity\n * in hold-then-flick gestures.\n */\n if (\n timestampedPoint === history[0] &&\n history.length > 2 &&\n lastPoint.timestamp - timestampedPoint.timestamp >\n secondsToMilliseconds(timeDelta) * 2\n ) {\n timestampedPoint = history[1]\n }\n\n const seconds = millisecondsToSeconds(\n lastPoint.timestamp - timestampedPoint.timestamp\n )\n if (seconds === 0) {\n return { x: 0, y: 0 }\n }\n\n const currentVelocity = {\n x: (lastPoint.x - timestampedPoint.x) / seconds,\n y: (lastPoint.y - timestampedPoint.y) / seconds,\n }\n\n if (currentVelocity.x === Infinity) {\n currentVelocity.x = 0\n }\n if (currentVelocity.y === Infinity) {\n currentVelocity.y = 0\n }\n\n return currentVelocity\n}\n"],"names":[],"mappings":";;;;;;;;;AA2CA,MAAM,cAAc,iBAAiB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;MAEnD,UAAU,CAAA;IAgDnB,WAAA,CACI,KAAmB,EACnB,QAAqC,EACrC,EACI,kBAAkB,EAClB,aAAa,GAAG,MAAM,EACtB,gBAAgB,GAAG,KAAK,EACxB,iBAAiB,GAAG,CAAC,EACrB,OAAO,GAAA,GACY,EAAE,EAAA;QAtDrB,IAAA,CAAA,UAAU,GAAwB,IAAI;QAEtC,IAAA,CAAA,aAAa,GAAwB,IAAI;QAEzC,IAAA,CAAA,iBAAiB,GAAqB,IAAI;AAElD;;;AAGG;QACK,IAAA,CAAA,oBAAoB,GAAqB,IAAI;QAS7C,IAAA,CAAA,QAAQ,GAAgC,EAAE;QAc1C,IAAA,CAAA,aAAa,GAAuC,MAAM;AAElE;;AAEG;AACK,QAAA,IAAA,CAAA,eAAe,GAAiC,IAAI,GAAG,EAAE;AAEjE;;AAEG;QACK,IAAA,CAAA,qBAAqB,GAAwB,IAAI;AA2GjD,QAAA,IAAA,CAAA,eAAe,GAAG,CAAC,KAAY,KAAU;AAC7C,YAAA,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,MAAiB,CAAC;AAC9C,QAAA,CAAC;QAEO,IAAA,CAAA,cAAc,GAAG,MAAW;AAChC,YAAA,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;AAC7B,QAAA,CAAC;QAyCO,IAAA,CAAA,WAAW,GAAG,MAAK;YACvB,IAAI,EAAE,IAAI,CAAC,aAAa,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AAO,eAAe;AAC1B;;;;"}
package/dist/es/index.mjs CHANGED
@@ -56,9 +56,12 @@ export { createEffect } from './effects/utils/create-effect.mjs';
56
56
  export { createRenderBatcher } from './frameloop/batcher.mjs';
57
57
  export { cancelMicrotask, microtask } from './frameloop/microtask.mjs';
58
58
  export { time } from './frameloop/sync-time.mjs';
59
+ export { drag } from './gestures/drag/index.mjs';
59
60
  export { isDragActive, isDragging } from './gestures/drag/state/is-active.mjs';
60
61
  export { setDragLock } from './gestures/drag/state/set-active.mjs';
62
+ export { VisualElementDragControls, elementDragControls, expectsResolvedDragConstraints } from './gestures/drag/VisualElementDragControls.mjs';
61
63
  export { hover } from './gestures/hover.mjs';
64
+ export { PanSession } from './gestures/pan/PanSession.mjs';
62
65
  export { press } from './gestures/press/index.mjs';
63
66
  export { isElementKeyboardAccessible, isElementTextInput } from './gestures/press/utils/is-keyboard-accessible.mjs';
64
67
  export { isNodeOrChild } from './gestures/utils/is-node-or-child.mjs';
@@ -150,6 +153,9 @@ export { buildProjectionTransform } from './projection/styles/transform.mjs';
150
153
  export { mixValues } from './projection/animation/mix-values.mjs';
151
154
  export { animateSingleValue } from './animation/animate/single-value.mjs';
152
155
  export { addDomEvent } from './events/add-dom-event.mjs';
156
+ export { addPointerEvent } from './events/add-pointer-event.mjs';
157
+ export { addPointerInfo, extractEventInfo } from './events/event-info.mjs';
158
+ export { distance, distance2D } from './utils/distance.mjs';
153
159
  export { compareByDepth } from './projection/utils/compare-by-depth.mjs';
154
160
  export { FlatTree } from './projection/utils/flat-tree.mjs';
155
161
  export { delay, delayInSeconds } from './utils/delay.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -132,6 +132,26 @@ function prepareNode(element, transition) {
132
132
  }
133
133
  return node;
134
134
  }
135
+ /**
136
+ * Get a projection node for an element, so imperative gestures like
137
+ * drag() can measure its layout. Reuses a node owned by a `motion`
138
+ * component or animateLayout(), otherwise creates one in the shared
139
+ * imperative tree. Returns the node and a function that releases it.
140
+ */
141
+ function acquireProjectionNode(element) {
142
+ const owned = layoutNodes.get(element) || visualElementStore.get(element)?.projection;
143
+ /**
144
+ * A VisualElement can outlive a node we released (e.g. a stopped
145
+ * drag()), so only reuse a node that's still mounted.
146
+ */
147
+ if (owned?.instance)
148
+ return [owned, () => { }];
149
+ const node = prepareNode(element);
150
+ return [
151
+ node,
152
+ () => layoutNodes.get(element) === node && dropNode(element, node),
153
+ ];
154
+ }
135
155
  function sortDocumentOrder(elements) {
136
156
  return [...elements].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
137
157
  }
@@ -359,5 +379,5 @@ function parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options) {
359
379
  };
360
380
  }
361
381
 
362
- export { LayoutAnimationBuilder, parseAnimateLayoutArgs };
382
+ export { LayoutAnimationBuilder, acquireProjectionNode, parseAnimateLayoutArgs };
363
383
  //# sourceMappingURL=LayoutAnimationBuilder.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"LayoutAnimationBuilder.mjs","sources":["../../../src/layout/LayoutAnimationBuilder.ts"],"sourcesContent":["import { 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 && 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\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 && 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: 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,CA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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,QAAQ;AACf,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 { 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 && 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 && 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: 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;A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EA,QAAQ,GAAA;AACJ,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;AAClB,YAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC;YAClC;QACJ;AAEA,QAAA,MAAM,UAAU,GAAG,IAAI,GAAG,EAAwC;QAClE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;YAC1B,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,gBAAgB,EAAE;AACxC,gBAAA,UAAU,CAAC,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,QAAQ;AACf,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,10 @@
1
+ const distance = (a, b) => Math.abs(a - b);
2
+ function distance2D(a, b) {
3
+ // Multi-dimensional
4
+ const xDelta = distance(a.x, b.x);
5
+ const yDelta = distance(a.y, b.y);
6
+ return Math.sqrt(xDelta ** 2 + yDelta ** 2);
7
+ }
8
+
9
+ export { distance, distance2D };
10
+ //# sourceMappingURL=distance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distance.mjs","sources":["../../../src/utils/distance.ts"],"sourcesContent":["import { Point } from \"motion-utils\"\n\nexport const distance = (a: number, b: number) => Math.abs(a - b)\n\nexport function distance2D(a: Point, b: Point): number {\n // Multi-dimensional\n const xDelta = distance(a.x, b.x)\n const yDelta = distance(a.y, b.y)\n return Math.sqrt(xDelta ** 2 + yDelta ** 2)\n}\n"],"names":[],"mappings":"AAEO,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,CAAS,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;AAE1D,SAAU,UAAU,CAAC,CAAQ,EAAE,CAAQ,EAAA;;AAEzC,IAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACjC,IAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACjC,IAAA,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,CAAC;AAC/C;;;;"}
package/dist/index.d.ts CHANGED
@@ -640,7 +640,7 @@ interface MotionNodeDraggableOptions {
640
640
  *
641
641
  * Alternatively, it can accept a `ref` to another component created with React's `useRef` hook.
642
642
  * This `ref` should be passed both to the draggable component's `dragConstraints` prop, and the `ref`
643
- * of the component you want to use as constraints.
643
+ * of the component you want to use as constraints. The element itself can also be passed.
644
644
  *
645
645
  * ```jsx
646
646
  * // In pixels
@@ -661,7 +661,7 @@ interface MotionNodeDraggableOptions {
661
661
  * }
662
662
  * ```
663
663
  */
664
- dragConstraints?: false | Partial<BoundingBox> | {
664
+ dragConstraints?: false | Partial<BoundingBox> | Element | {
665
665
  current: Element | null;
666
666
  };
667
667
  /**
@@ -3540,6 +3540,73 @@ declare const time: {
3540
3540
  set: (newTime: number) => void;
3541
3541
  };
3542
3542
 
3543
+ /**
3544
+ * @public
3545
+ */
3546
+ interface DragOptions {
3547
+ /**
3548
+ * Restrict dragging to a single axis. By default an element can be
3549
+ * dragged on both axes.
3550
+ */
3551
+ axis?: "x" | "y";
3552
+ /**
3553
+ * The permitted draggable area. Either `top`/`left`/`right`/`bottom`
3554
+ * distances in pixels, relative to the element's origin, or an element
3555
+ * the draggable element must stay within.
3556
+ */
3557
+ constraints?: Partial<BoundingBox> | Element;
3558
+ /**
3559
+ * How far, from `0` to `1`, the element can move outside its
3560
+ * constraints. Can be set per edge. Defaults to `0.35`.
3561
+ */
3562
+ elastic?: DragElastic;
3563
+ /**
3564
+ * Whether to carry the gesture's velocity into an inertia animation
3565
+ * on release. Defaults to `true`.
3566
+ */
3567
+ momentum?: boolean;
3568
+ /**
3569
+ * Options for the inertia animation that runs on release.
3570
+ */
3571
+ transition?: InertiaOptions;
3572
+ /**
3573
+ * Animate back to the origin on release.
3574
+ */
3575
+ snapToOrigin?: boolean | "x" | "y";
3576
+ /**
3577
+ * Lock dragging to the first axis the pointer moves along.
3578
+ */
3579
+ directionLock?: boolean;
3580
+ /**
3581
+ * Allow drag gestures to start on parent elements that are also
3582
+ * draggable. By default, only the innermost draggable element moves.
3583
+ */
3584
+ propagation?: boolean;
3585
+ onStart?: DragHandler;
3586
+ onMove?: DragHandler;
3587
+ onEnd?: DragHandler;
3588
+ onDirectionLock?: (axis: "x" | "y") => void;
3589
+ onTransitionEnd?: () => void;
3590
+ /**
3591
+ * Called when element constraints are measured. Return a new
3592
+ * `BoundingBox` to override them.
3593
+ */
3594
+ onMeasureConstraints?: (constraints: BoundingBox) => BoundingBox | void;
3595
+ }
3596
+ /**
3597
+ * Make elements draggable. Returns a function that removes the gesture.
3598
+ *
3599
+ * ```javascript
3600
+ * const stop = drag("#box", { axis: "x", constraints: { left: 0, right: 300 } })
3601
+ * ```
3602
+ *
3603
+ * The element's `x` and `y` are motion values shared with `animate()`
3604
+ * and `animateLayout()`, so these can animate the element after a drag.
3605
+ *
3606
+ * @public
3607
+ */
3608
+ declare function drag(elementOrSelector: ElementOrSelector, options?: DragOptions): VoidFunction;
3609
+
3543
3610
  declare const isDragging: {
3544
3611
  x: boolean;
3545
3612
  y: boolean;
@@ -3548,6 +3615,90 @@ declare function isDragActive(): boolean;
3548
3615
 
3549
3616
  declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
3550
3617
 
3618
+ declare const elementDragControls: WeakMap<VisualElement<unknown, unknown, {}>, VisualElementDragControls>;
3619
+ interface DragControlOptions {
3620
+ /**
3621
+ * This distance after which dragging starts and a direction is locked in.
3622
+ *
3623
+ * @public
3624
+ */
3625
+ distanceThreshold?: number;
3626
+ /**
3627
+ * Whether to immediately snap to the cursor when dragging starts.
3628
+ *
3629
+ * @public
3630
+ */
3631
+ snapToCursor?: boolean;
3632
+ }
3633
+ declare class VisualElementDragControls {
3634
+ private visualElement;
3635
+ private panSession?;
3636
+ private openDragLock;
3637
+ isDragging: boolean;
3638
+ private currentDirection;
3639
+ private originPoint;
3640
+ /**
3641
+ * The permitted boundaries of travel, in pixels.
3642
+ */
3643
+ private constraints;
3644
+ private hasMutatedConstraints;
3645
+ /**
3646
+ * The per-axis resolved elastic values.
3647
+ */
3648
+ private elastic;
3649
+ /**
3650
+ * The latest pointer event. Used as fallback when the `cancel` and `stop` functions are called without arguments.
3651
+ */
3652
+ private latestPointerEvent;
3653
+ /**
3654
+ * The latest pan info. Used as fallback when the `cancel` and `stop` functions are called without arguments.
3655
+ */
3656
+ private latestPanInfo;
3657
+ /**
3658
+ * Where drag options are read from. By default these are the
3659
+ * VisualElement's props (as with a React `motion` component), but the
3660
+ * vanilla `drag()` API provides its own.
3661
+ */
3662
+ private readProps;
3663
+ constructor(visualElement: VisualElement<HTMLElement>, readProps?: () => MotionNodeOptions);
3664
+ start(originEvent: PointerEvent, { snapToCursor, distanceThreshold }?: DragControlOptions): void;
3665
+ stop(event?: PointerEvent, panInfo?: PanInfo): void;
3666
+ cancel(): void;
3667
+ /**
3668
+ * Clean up the pan session without modifying other drag state.
3669
+ * This is used during unmount to ensure event listeners are removed
3670
+ * without affecting projection animations or drag locks.
3671
+ */
3672
+ endPanSession(): void;
3673
+ private updateAxis;
3674
+ private resolveConstraints;
3675
+ private resolveRefConstraints;
3676
+ private startAnimation;
3677
+ private startAxisValueAnimation;
3678
+ private stopAnimation;
3679
+ /**
3680
+ * Drag works differently depending on which props are provided.
3681
+ *
3682
+ * - If _dragX and _dragY are provided, we output the gesture delta directly to those motion values.
3683
+ * - Otherwise, we apply the delta to the x/y motion values.
3684
+ */
3685
+ private getAxisMotionValue;
3686
+ /**
3687
+ * Measure the live box - projection.layout may or may not include the
3688
+ * drag transform, depending on when it was measured.
3689
+ */
3690
+ private snapToCursor;
3691
+ /**
3692
+ * When the viewport resizes we want to check if the measured constraints
3693
+ * have changed and, if so, reposition the element within those new constraints
3694
+ * relative to where it was before the resize.
3695
+ */
3696
+ scalePositionWithinConstraints(): void;
3697
+ addListeners(): (() => void) | undefined;
3698
+ getProps(): MotionNodeOptions;
3699
+ }
3700
+ declare function expectsResolvedDragConstraints({ dragConstraints, onMeasureDragConstraints, }: MotionNodeOptions): boolean;
3701
+
3551
3702
  /**
3552
3703
  * Options for event listeners.
3553
3704
  *
@@ -3593,6 +3744,81 @@ type OnHoverEndEvent = (event: PointerEvent) => void;
3593
3744
  */
3594
3745
  declare function hover(elementOrSelector: ElementOrSelector, onHoverStart: OnHoverStartEvent, options?: EventOptions): VoidFunction;
3595
3746
 
3747
+ interface PanSessionHandlers {
3748
+ onSessionStart: PanHandler;
3749
+ onStart: PanHandler;
3750
+ onMove: PanHandler;
3751
+ onEnd: PanHandler;
3752
+ onSessionEnd: PanHandler;
3753
+ resumeAnimation: () => void;
3754
+ }
3755
+ interface PanSessionOptions {
3756
+ transformPagePoint?: TransformPoint;
3757
+ dragSnapToOrigin?: boolean | "x" | "y";
3758
+ distanceThreshold?: number;
3759
+ contextWindow?: (Window & typeof globalThis) | null;
3760
+ /**
3761
+ * Element being dragged. When provided, scroll events on its
3762
+ * ancestors and window are compensated so the gesture continues
3763
+ * smoothly during scroll.
3764
+ */
3765
+ element?: HTMLElement | null;
3766
+ }
3767
+ declare class PanSession {
3768
+ private history;
3769
+ private startEvent;
3770
+ private lastMoveEvent;
3771
+ private lastMoveEventInfo;
3772
+ /**
3773
+ * Raw (untransformed) event info, re-transformed each frame
3774
+ * so transformPagePoint sees the current parent matrix.
3775
+ */
3776
+ private lastRawMoveEventInfo;
3777
+ /**
3778
+ * Whether a pointermove has arrived since the last updatePoint.
3779
+ */
3780
+ private hasPendingMove?;
3781
+ private transformPagePoint?;
3782
+ private handlers;
3783
+ private removeListeners;
3784
+ /**
3785
+ * For determining if an animation should resume after it is interrupted
3786
+ */
3787
+ private dragSnapToOrigin;
3788
+ /**
3789
+ * The distance after which panning should start.
3790
+ */
3791
+ private distanceThreshold;
3792
+ private contextWindow;
3793
+ /**
3794
+ * Scroll positions of scrollable ancestors and window.
3795
+ */
3796
+ private scrollPositions;
3797
+ /**
3798
+ * Cleanup function for scroll listeners.
3799
+ */
3800
+ private removeScrollListeners;
3801
+ constructor(event: PointerEvent, handlers: Partial<PanSessionHandlers>, { transformPagePoint, contextWindow, dragSnapToOrigin, distanceThreshold, element, }?: PanSessionOptions);
3802
+ /**
3803
+ * Start tracking scroll on ancestors and window.
3804
+ */
3805
+ private startScrollTracking;
3806
+ private onElementScroll;
3807
+ private onWindowScroll;
3808
+ /**
3809
+ * Handle scroll compensation during drag.
3810
+ *
3811
+ * For element scroll: adjusts history origin since pageX/pageY doesn't change.
3812
+ * For window scroll: adjusts lastMoveEventInfo since pageX/pageY would change.
3813
+ */
3814
+ private handleScroll;
3815
+ private updatePoint;
3816
+ private handlePointerMove;
3817
+ private handlePointerUp;
3818
+ updateHandlers(handlers: Partial<PanSessionHandlers>): void;
3819
+ end(): void;
3820
+ }
3821
+
3596
3822
  interface PressGestureInfo {
3597
3823
  success: boolean;
3598
3824
  }
@@ -4743,6 +4969,15 @@ declare function animateSingleValue<V extends AnyResolvedKeyframe>(value: Motion
4743
4969
 
4744
4970
  declare function addDomEvent(target: EventTarget, eventName: string, handler: EventListener, options?: AddEventListenerOptions): () => void;
4745
4971
 
4972
+ type EventListenerWithPointInfo = (e: PointerEvent, info: EventInfo) => void;
4973
+ declare function extractEventInfo(event: PointerEvent): EventInfo;
4974
+ declare const addPointerInfo: (handler: EventListenerWithPointInfo) => EventListener;
4975
+
4976
+ declare function addPointerEvent(target: EventTarget, eventName: string, handler: EventListenerWithPointInfo, options?: AddEventListenerOptions): () => void;
4977
+
4978
+ declare const distance: (a: number, b: number) => number;
4979
+ declare function distance2D(a: Point, b: Point): number;
4980
+
4746
4981
  interface WithDepth {
4747
4982
  depth: number;
4748
4983
  }
@@ -5681,4 +5916,4 @@ declare const sync: Batcher;
5681
5916
  */
5682
5917
  declare const cancelSync: Record<string, (process: Process) => void>;
5683
5918
 
5684
- export { type AccelerateConfig, type AcceptedAnimations, type ActiveStatsBuffer, type AddEffectValue, type AnimateEffect, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState$1 as AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, type ArcOptions, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragElastic, type DragHandler, type DraggableProps, type DurationSpringOptions, type DynamicOption, type Effect, type EffectKeyframes, type EffectOptions, type EffectRead, type EffectTest, type EffectTransition, type ElementOrSelector, type EventInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FollowValueOptions, type FrameData, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutProjectionMetrics, type LayoutProjectionStats, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionPath, type MotionStyle, MotionValue, type MotionValueAnimation, type MotionValueEventCallbacks, type MotionValueOptions, MotionValueState, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type PathInterpolator, type PathState, type Phase, type Point2D, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type PropagateOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type StatsRecording, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleSubject, type StyleTransitions, type Subscriber, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, addAttrValue, addDomEvent, addEffect, addSVGValue, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateEffectSubject, animateElement, animateLayout, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateValues, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, arc, aspectRatio, attachFollow, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createEffect, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, eachAxis, fillOffset, fillWildcards, findDimensionValueType, findEffect, findValueType, flushKeyframeResolvers, followValue, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, handOffElementState, has2DTranslate, hasComplexValues, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isElementTextInput, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, optimizedAppearDataAttribute, optimizedAppearDataId, originProps, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readSVGValue, readStyleValue, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removeEffect, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveTransition, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, round, sampleDelta, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, styleSubjectEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, supportsViewTimeline, supportsWaapi, svgEffect, svgSubjectEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };
5919
+ export { type AccelerateConfig, type AcceptedAnimations, type ActiveStatsBuffer, type AddEffectValue, type AnimateEffect, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState$1 as AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, type ArcOptions, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragControlOptions, type DragElastic, type DragHandler, type DragOptions, type DraggableProps, type DurationSpringOptions, type DynamicOption, type Effect, type EffectKeyframes, type EffectOptions, type EffectRead, type EffectTest, type EffectTransition, type ElementOrSelector, type EventInfo, type EventListenerWithPointInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FollowValueOptions, type FrameData, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutProjectionMetrics, type LayoutProjectionStats, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionPath, type MotionStyle, MotionValue, type MotionValueAnimation, type MotionValueEventCallbacks, type MotionValueOptions, MotionValueState, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, PanSession, type PassiveEffect, type PathInterpolator, type PathState, type Phase, type Point2D, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type PropagateOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type StatsRecording, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleSubject, type StyleTransitions, type Subscriber, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, VisualElementDragControls, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, addAttrValue, addDomEvent, addEffect, addPointerEvent, addPointerInfo, addSVGValue, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateEffectSubject, animateElement, animateLayout, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateValues, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, arc, aspectRatio, attachFollow, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createEffect, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, distance, distance2D, drag, eachAxis, elementDragControls, expectsResolvedDragConstraints, extractEventInfo, fillOffset, fillWildcards, findDimensionValueType, findEffect, findValueType, flushKeyframeResolvers, followValue, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, handOffElementState, has2DTranslate, hasComplexValues, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isElementTextInput, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, optimizedAppearDataAttribute, optimizedAppearDataId, originProps, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readSVGValue, readStyleValue, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removeEffect, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveTransition, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, round, sampleDelta, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, styleSubjectEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, supportsViewTimeline, supportsWaapi, svgEffect, svgSubjectEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };