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

59 lines (58 loc) 2.42 kB
import { type AnimationOptions } from 'motion'; /** * Determine whether the current environment supports true hover. * * Uses `(hover: hover)` and `(pointer: fine)` media queries to avoid sticky * hover states on touch devices. * * @param win Window object (useful for testing/mocking). * @return Whether the device supports hover with a fine pointer. */ export declare const isHoverCapable: (win?: Window) => boolean; /** * Split a hover definition into keyframes and an optional nested transition. * * @param def While-hover record that may include a nested `transition`. * @return Object with `keyframes` (no `transition`) and optional `transition`. */ export declare const splitHoverDefinition: (def: Record<string, unknown>) => { keyframes: Record<string, unknown>; transition?: AnimationOptions; }; /** * Compute the baseline values to restore to on hover end. * * Preference order per key: `animate` → `initial` → neutral transform defaults * → computed style value if present. * * @param el Target element. * @param opts Source records for baseline computation. * @return Minimal baseline record to restore on hover end. */ export declare const computeHoverBaseline: (el: HTMLElement, opts: { initial?: Record<string, unknown>; animate?: Record<string, unknown>; whileHover?: Record<string, unknown>; }) => Record<string, unknown>; /** * Attach whileHover interactions to an element with capability gating. * * Uses motion-dom's hover function which filters out touch events and interoperates * with drag gestures. On pointer enter, animates to `whileHover` (using nested `transition` * if provided). On leave, restores changed keys to the baseline using the merged * root/component transition. * * @param el Target element. * @param whileHover While-hover definition. * @param mergedTransition Root/component merged transition. * @param callbacks Optional lifecycle callbacks for hover start/end. * @param baselineSources Optional sources used to compute baseline. * @return Cleanup function to remove hover listeners. */ export declare const attachWhileHover: (el: HTMLElement, whileHover: Record<string, unknown> | undefined, mergedTransition: AnimationOptions, callbacks?: { onStart?: () => void; onEnd?: () => void; }, baselineSources?: { initial?: Record<string, unknown>; animate?: Record<string, unknown>; }) => (() => void);