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

75 lines (74 loc) 2.91 kB
import { type ReducedMotionState } from './reducedMotion.svelte.js'; /** * Returns a copy of `keyframes` with transform-related keys * (`x`, `y`, `scale`, `rotate`, `skew`, `translate*`, etc.) removed * when `reduced` is `true`. Returns `keyframes` unchanged otherwise. * * The `transition` key is preserved so per-key transitions still flow * through to the animation engine; only the visual *targets* are * stripped, not the timing config. * * @template T Keyframes record (or `undefined`). * @param keyframes Source keyframes record — may be `undefined`, in * which case the same `undefined` is returned regardless of * `reduced`. * @param reduced When `true`, strip transform keys; when `false`, * return `keyframes` unchanged (by reference). * @returns The original `keyframes` when `reduced` is `false` (same * reference); otherwise a new record with transform keys filtered * out and other keys preserved. * * @example * ```ts * filterReducedMotionKeyframes( * { x: 100, scale: 1.2, opacity: 0.5 }, * true * ) * // → { opacity: 0.5 } * * filterReducedMotionKeyframes( * { x: 100, opacity: 0.5, transition: { duration: 0.3 } }, * true * ) * // → { opacity: 0.5, transition: { duration: 0.3 } } * ``` */ export declare const filterReducedMotionKeyframes: <T extends Record<string, unknown> | undefined>(keyframes: T, reduced: boolean) => T; /** * Returns a `{ current, subscribe }` object reflecting the resolved * reduced-motion policy for the current component subtree. * * Resolution combines the nearest `<MotionConfig reducedMotion>` ancestor * with the OS-level `prefers-reduced-motion` setting: * * - `'always'` → always `true` * - `'never'` (or no `<MotionConfig>` ancestor) → always `false` * - `'user'` → mirrors the OS preference, defaulting to `false` in SSR * * Both reactive read paths fire on **both** sources changing: * * - `.current` re-evaluates inside any reactive scope that reads it * (templates, `$derived`, `$effect`) when either the OS preference *or* * a parent `<MotionConfig reducedMotion={...}>` policy reassigns. * - `.subscribe(run)` callbacks are driven by both the OS path * (sync via `osReduced.subscribe`) and a `$effect` tracking the * `motionConfig.reducedMotion` prop. Legacy store consumers see policy * changes too — a fix vs. the prior `derived()`-based impl, which only * re-fired on OS changes. * * @returns A `ReducedMotionState` reflecting the merged policy + OS setting. * @see https://motion.dev/docs/react-reduced-motion * * @example * ```svelte * <script> * import { useReducedMotionConfig } from '@humanspeak/svelte-motion' * const reduced = useReducedMotionConfig() * </script> * * {#if !reduced.current} * <motion.div animate={{ x: 100 }} /> * {/if} * ``` */ export declare const useReducedMotionConfig: () => ReducedMotionState;