UNPKG

@humanspeak/svelte-motion

Version:

Framer Motion for Svelte 5. Declarative motion.<tag> components with AnimatePresence exit animations, gestures (hover, tap, drag, focus, in-view), variants, FLIP layout animations, shared-layout transitions, spring physics, and scroll-linked motion values

33 lines (32 loc) 1.24 kB
import { getContext, setContext } from 'svelte'; const LAYOUT_SCROLL_CONTEXT_KEY = Symbol('layout-scroll-container'); /** * Publish the scroll-container chain for descendant motion components. * * Called on a `motion.*` component with `layoutScroll` enabled during * its init phase. The provided thunk should resolve to `[...ancestorChain, * ownElement]` — descendants get the full chain in one call. * * Mirrors framer-motion's `removeElementScroll`, which walks the path * and sums every `layoutScroll` ancestor's offset. * * @param ref Thunk returning the full ancestor chain (closest first). */ export const setLayoutScrollContainer = (ref) => { setContext(LAYOUT_SCROLL_CONTEXT_KEY, ref); }; /** * Capture the ancestor chain thunk at component init. * * Important: call this **before** the same component calls * `setLayoutScrollContainer(...)`. Otherwise the lookup returns the * component's own thunk (Svelte `setContext` shadows from the call site * down) and the chain collapses. * * Returns `undefined` when no ancestor has `layoutScroll`. * * @returns Ancestor chain thunk, or `undefined`. */ export const getLayoutScrollContainerRef = () => { return getContext(LAYOUT_SCROLL_CONTEXT_KEY); };