@omicrxn/mercury
Version:
Mercury is a Svelte animation library powered by Motion. It simplifies complex animations with Svelte actions, provides layout and exit animations, and integrates seamlessly with Svelte features.
45 lines (44 loc) • 2.16 kB
TypeScript
import type { PresenceAnimation } from './animation-interface.js';
type PresenceDirection = 'in' | 'out' | 'both';
type PlayDirection = 'in' | 'out';
interface PresenceTransitionConfig {
delay?: number;
duration?: number;
tick?: (t: number, u: number) => void;
}
/**
* Svelte supports deferred transitions (the mechanism behind `crossfade`): returning a
* function instead of a config makes Svelte call it in a microtask with the *actual* play
* direction. This is what lets a single `transition:presence` behave like AnimatePresence —
* we build the enter or exit animation only once we know which one is playing, and can
* report the real (e.g. spring-resolved) exit duration to Svelte.
*/
type PresenceResult = PresenceTransitionConfig | ((opts?: {
direction: PlayDirection;
}) => PresenceTransitionConfig);
/**
* Cancels any in-flight presence animation on the element and restores any inline
* styles that were mutated (e.g. by popLayout). Called when a new presence/mercury
* lifecycle starts on the same node so a reversed exit doesn't leave it stranded.
*/
export declare const clearPresence: (element: HTMLElement) => void;
/**
* Svelte-native AnimatePresence.
*
* Used as a transition directive, so Svelte's semantics map directly onto motion/react's:
*
* - `transition:presence={{ initial, exit, mode, transition }}` — like a child of
* `<AnimatePresence>`: on enter the element animates from `initial` to its settled
* CSS styles, on removal it animates to `exit`.
* - Local transitions don't run when an ancestor block mounts, which is exactly
* `<AnimatePresence initial={false}>`. Use `transition:presence|global` to opt in.
* - `mode: 'sync' | 'wait' | 'popLayout'` matches AnimatePresence's `mode`.
* - Flat params (`out:presence={{ opacity: 0 }}`) describe the hidden state for both
* directions: enters animate from it, exits animate to it.
*
* In `initial`, array values are treated as full keyframes (`opacity: [0, 0.5, 1]`).
*/
export declare const presence: (element: HTMLElement, params: PresenceAnimation, options: {
direction: PresenceDirection;
}) => PresenceResult;
export {};