Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/solid-motion-experiments.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220import type { Context, For as solidFor, Owner, Show as solidShow, children as solidChildren, createMemo as solidCreateMemo, createSignal as solidCreateSignal, mergeProps as solidMergeProps, splitProps as solidSplitProps,} from "solid-js";
/** * Adapts Motion's lifecycle needs onto Solid's public runtime primitives. * * Solid does not rerun component bodies when reactive values change. Motion therefore * needs an adapter that separates three concerns clearly: * component setup, tracked reactive updates, and owner-scoped teardown. * * This contract keeps those boundaries explicit so the renderer can follow Solid's * actual lifecycle instead of borrowing React-style render assumptions. * * @example Solid 1 adapter mapping * ```ts * const adapter: SolidMotionAdapter = { * version: "solid1", * isServer, * createSignal, * createMemo, * children, * For, * Show, * splitProps, * mergeProps, * onClientMount: onMount, * onDispose: onCleanup, * createTrackedEffect: createEffect, * createRenderTrackedEffect: createRenderEffect, * batch, * untrack, * createOwnedRoot: createRoot, * getOwner, * runWithOwner, * createContext, * useContext, * }; * ``` * * @example Presence-oriented retained owner * ```ts * const owner = adapter.getOwner(); * const retained = adapter.createOwnedRoot((dispose) => ({ owner, dispose }), owner ?? undefined); * ``` */export interface SolidMotionAdapter { /** * Identifies the lifecycle contract this adapter implements. * * The renderer uses this as a capability marker so Solid 1 and Solid 2 support can * evolve behind separate adapters without changing the public Motion API shape. */ readonly version: "solid1";
/** * Exposes Solid's server/client split as a plain boolean. * * This matters because initial style serialization is allowed during server render, * while DOM access, layout measurement, and animation startup are not. */ readonly isServer: boolean;
/** * Creates local reactive state that the Motion bridge can own behind one versioned seam. * * Even when Solid 1 and Solid 2 keep the same runtime shape here, routing signal creation * through the adapter prevents shared runtime code from importing Solid primitives directly. */ createSignal: typeof solidCreateSignal;
/** * Creates a pure derived accessor with Solid's memoized update semantics. * * Motion uses this for local derived state such as retained child records, where repeated * reads should reuse one computed value and equality can suppress downstream churn. */ createMemo: typeof solidCreateMemo;
/** * Normalizes a child expression into Solid's stable child accessor shape. * * Retained rendering needs this helper because raw JSX payloads are not the same thing as * Solid's normalized child resolution contract. */ children: typeof solidChildren;
/** * Renders list-shaped control flow through the active Solid adapter. * * Shared runtime code can use this for retained-record rendering without depending on a * direct `solid-js` import at the call site. */ For: typeof solidFor;
/** * Renders conditional control flow through the active Solid adapter. * * Keeping `Show` here alongside `For` prevents the adapter boundary from splitting between * reactive primitives and a second ad hoc set of directly imported control-flow helpers. */ Show: typeof solidShow;
/** * Splits a reactive props object without freezing later property reads. * * Motion uses this to separate local controls and Motion-owned props from DOM props while * preserving Solid's lazy tracking behavior. */ splitProps: typeof solidSplitProps;
/** * Merges reactive prop sources without eagerly flattening them. * * This lets the bridge layer combine DOM props, SSR style fallbacks, and ref wiring while * keeping each source reactive until the rendered host actually reads it. */ mergeProps: typeof solidMergeProps;
/** * Runs once on the client after Solid has created the initial DOM and assigned refs. * * Motion uses this as the safe entry point for any work that needs a real element, * such as creating runtime state, attaching style effects, or starting animations. */ onClientMount(callback: () => void): void;
/** * Registers teardown work under the current Solid owner. * * Every subscription, animation handle, or DOM-side runtime effect created by Motion * must be paired with an owner-scoped disposer so retained state does not leak. */ onDispose(callback: () => void): void;
/** * Creates a normal tracked effect for reactive Motion props. * In solidjs 1 this is `createEffect`, in Solidjs 2 this is `createTrackedEffect`. * * This is the default path for observing Solid signals that describe animation intent, * for example `animate={() => ({ opacity: open() ? 1 : 0 })}`. */ createTrackedEffect(callback: () => void): void;
/** * Creates a render-phase tracked effect. * * This exists for Solid-specific timing work like dirty-marking layout state before * later measurement. It is intentionally separate because render-phase timing is not a * safe place to assume ref availability or DOM connectivity. */ createRenderTrackedEffect(callback: () => void): void;
/** * Coalesces several related reactive writes into one Solid update wave. * * This keeps Motion-side target resolution from fanning out into unnecessary effect * reruns when several values should change as one logical step. */ batch<T>(callback: () => T): T;
/** * Reads reactive values without subscribing the current computation. * * Motion needs this when it wants a one-time snapshot of config or defaults without * turning those reads into long-lived animation dependencies. */ untrack<T>(callback: () => T): T;
/** * Creates an owned reactive root with explicit disposal. * * Presence and retained-exit experiments need this because logical removal from Solid * control flow is not the same thing as physically disposing the runtime state that is * still responsible for an exit animation. */ createOwnedRoot<T>(callback: (dispose: () => void) => T, owner?: Owner): T;
/** * Returns the current Solid owner. * * This is used for advanced cases like retained children, where Motion needs to keep * context and cleanup behavior aligned with the original owning subtree. */ getOwner(): Owner | null;
/** * Runs work inside a specific Solid owner. * * Retained subtrees and context-sensitive features need this to keep behavior aligned * with the original ownership chain instead of creating detached state by accident. */ runWithOwner<T>(owner: Owner | null, callback: () => T): T | undefined;
/** * Creates a context that follows the current Solid adapter's ownership rules. * * Motion needs adapter-owned context so config, presence, and layout groups can share * state without assuming a specific Solid runtime version at the call site. */ createContext<T>(defaultValue?: T): Context<T | undefined>;
/** * Reads from an adapter-created context. * * This stays on the adapter so shared runtime code can access context through one * versioned surface instead of importing Solid primitives directly everywhere. */ useContext<T>(context: Context<T | undefined>): T | undefined;}