@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
61 lines (60 loc) • 1.99 kB
TypeScript
/**
* Motion values that can be rendered as live text children.
*
* Mirrors upstream Motion's DOM child support, where a `MotionValue<number |
* string>` passed as `children` renders its current value and writes later
* changes to `textContent`.
*/
export type MotionValueChild<T extends number | string = number | string> = {
/** Read the latest child value. */
get(): T;
/** Subscribe to future child value changes. */
on(event: 'change', callback: (latest: T) => void): () => void;
};
/**
* Checks whether a value is a renderable MotionValue child.
*
* @param value Value to inspect.
* @returns Whether the value is a `MotionValue<number | string>`.
*
* @example
* ```ts
* const count = motionValue(0)
* isMotionValueChild(count) // true
* isMotionValueChild('0') // false
* ```
*/
export declare const isMotionValueChild: (value: unknown) => value is MotionValueChild;
/**
* Reads the initial text for a MotionValue child.
*
* @param child MotionValue child to sample.
* @returns String form of the child's current value.
*
* @example
* ```ts
* const status = motionValue('ready')
* renderMotionValueChild(status) // 'ready'
* ```
*/
export declare const renderMotionValueChild: <T extends number | string>(child: MotionValueChild<T>) => string;
/**
* Subscribes a DOM element's text to a MotionValue child.
*
* @param child MotionValue child to observe.
* @param element Element whose `textContent` should mirror the child.
* @param onRender Optional callback fired with every rendered text value.
* @returns Unsubscribe callback.
*
* @example
* ```ts
* const count = motionValue(0)
* const element = document.createElement('span')
* const unsubscribe = bindMotionValueChild(count, element)
*
* count.set(1)
* element.textContent // '1'
* unsubscribe()
* ```
*/
export declare const bindMotionValueChild: (child: MotionValueChild, element: HTMLElement | SVGElement, onRender?: (value: string) => void) => (() => void);