@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
57 lines (56 loc) • 2.27 kB
TypeScript
/**
* @fileoverview DOM utilities.
* @module utils/dom
*/
/**
* Type guard for DOM elements that is resilient across realms/iframes.
*
* Avoids relying on `instanceof HTMLElement`, which can fail when elements
* originate from a different realm (e.g., an iframe). Instead, checks for
* the presence of a callable `getBoundingClientRect`, which is available on
* all `Element` nodes.
*
* @param v Unknown value to test.
* @return Whether the value is a DOM `Element`.
*/
export declare const isDomElement: (v: unknown) => v is Element;
/**
* An element reference - either an element directly or a getter function
* that returns one. Getters defer resolution past mount, which is useful
* with Svelte's `bind:this` where the element isn't available synchronously.
*
* Both `null` and `undefined` returns from the getter are normalised to
* `undefined` by `resolveElement`, so either nullable shape works.
*/
export type ElementOrGetter = HTMLElement | (() => HTMLElement | null | undefined);
/**
* Resolves an `ElementOrGetter` to an `HTMLElement`, or `undefined` if not
* yet available (e.g. a getter is supplied but the bound element hasn't
* mounted).
*
* Coerces a `null` getter result to `undefined` so the common
* `let el: HTMLElement | null = null` `bind:this` pattern lines up with the
* declared return type.
*
* @param ref Element or getter to resolve.
* @returns The resolved element, or `undefined` when not yet available.
* @example
* ```ts
* let node: HTMLElement | null = null
* resolveElement(() => node) // => undefined until bind:this fires
* ```
*/
export declare const resolveElement: (ref?: ElementOrGetter) => HTMLElement | undefined;
/**
* Tests whether an `ElementOrGetter` is currently unresolved — defined as a
* getter that returns falsy. Direct element refs are never "pending" (they
* were already resolved at call time) and absent refs are not "pending"
* either (they're just absent).
*
* Lets microtask-defer / rAF-defer loops wait for refs to hydrate after
* `bind:this` settles on mount.
*
* @param ref Element or getter to check.
* @returns `true` only when `ref` is a getter and the getter currently returns falsy.
*/
export declare const isRefPending: (ref?: ElementOrGetter) => boolean;