/** * Represents a value that can either be provided directly or through a zero-argument * Solid accessor. * * Motion props need this because Solid callers often express animation intent as a * tracked function, for example `animate={() => ({ opacity: open() ? 1 : 0 })}`. * Keeping that union explicit lets the renderer read those props lazily inside effects * instead of freezing them during component setup. * * @example Static target * ```ts * const animate: MaybeAccessor<{ opacity: number }> = { opacity: 1 }; * ``` * * @example Tracked target accessor * ```ts * const animate: MaybeAccessor<{ opacity: number }> = () => ({ opacity: open() ? 1 : 0 }); * ``` */ export type MaybeAccessor = T | (() => T); /** * Resolves a Motion prop that can be either a plain value or a Solid-style accessor. * * The helper itself stays deliberately small. The important behavior comes from where it * is called: if it runs inside a tracked Solid effect, accessor reads become animation * dependencies; if it runs inside `untrack`, Motion gets a one-time snapshot instead. * * @example Resolve a plain value * ```ts * const target = resolveMaybeAccessor({ opacity: 1 }); * ``` * * @example Resolve inside a tracked effect * ```ts * createEffect(() => { * const target = resolveMaybeAccessor(props.animate); * updateTarget(target); * }); * ``` */ export function resolveMaybeAccessor(value: MaybeAccessor): T { return typeof value === "function" ? (value as () => T)() : value; }