Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/solid-motion-experiments.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301import type { MotionStyle, MotionNodeOptions, OnPressEndEvent, OnPressStartEvent, PressGestureInfo, TargetAndTransition, TargetResolver, VariantLabels, ViewportOptions,} from "motion-dom";
import { solid1Adapter } from "../adapter/solid1.ts";
import type { SolidMotionAdapter } from "../adapter/types.ts";import type { MaybeAccessor } from "./resolve-motion-prop.ts";
/** * Upstream Motion prop names that belong to `MotionNodeOptions` rather than to the host element. * * Solid prop objects stay reactive through property reads. If we separate * Motion props from DOM props with normal destructuring, we risk freezing access to values like * `animate`, `transition`, or `layoutDependency` too early. `splitProps` preserves those reads so * later effects can subscribe lazily. * * Keeping the upstream-owned slice separate makes the Solid-specific additions below easier to * audit. When the adapter gains more Motion features later, this list is the first place to check * whether a prop should be treated as part of the motion-dom contract or as Solid-local glue. * * @example Split animation props from DOM props * ```ts * const [motionProps, domProps] = splitProps(rawProps, MOTION_PROP_KEYS); * ``` * * @example Keep `class` reactive while reading `animate` lazily * ```ts * const [motionProps, domProps] = splitMotionProps(rawProps); * createEffect(() => updateTarget(resolveMaybeAccessor(motionProps.animate))); * ``` */export const MOTION_NODE_PROP_KEYS = [ "initial", "animate", "exit", "transition", "variants", "custom", "inherit", "transformTemplate", "layout", "layoutId", "layoutDependency", "layoutScroll", "layoutRoot", "layoutAnchor", "whileHover", "whileTap", "whileFocus", "whileDrag", "whileInView", "drag", "dragConstraints", "dragElastic", "dragMomentum", "dragSnapToOrigin", "dragDirectionLock", "dragPropagation", "dragTransition", "dragControls", "dragListener", "onUpdate", "onAnimationStart", "onAnimationComplete", "onLayoutAnimationStart", "onLayoutAnimationComplete", "onHoverStart", "onHoverEnd", "onPan", "onPanStart", "onPanEnd", "onDrag", "onDragStart", "onDragEnd", "onDirectionLock", "onViewportEnter", "onViewportLeave", "propagate",] as const satisfies readonly (keyof MotionNodeOptions)[];
/** * Solid-local prop names that the current adapter owns outside upstream `MotionNodeOptions`. * * These props still need to be stripped from the rendered host because they affect Motion's * wrapper/runtime boundary, not the underlying DOM element or custom component contract. */export const SOLID_MOTION_PROP_KEYS = [ "style", "presenceKey", "whilePress", "inViewOptions", "onPressStart", "onPress", "onPressCancel",] as const;
/** * Complete list of prop names that the Solid wrapper currently treats as Motion-owned. * * Exporting this list keeps the split boundary inspectable for callers and tests. It also * ensures the same prop vocabulary drives both `splitMotionProps()` and any future checks that * need to answer "does this prop belong to Motion or to the rendered element?". * * @example Reuse the shared split vocabulary * ```ts * const [motionProps, domProps] = splitProps(rawProps, MOTION_PROP_KEYS); * ``` * * @example Check whether one prop name is Motion-owned * ```ts * const isMotionProp = MOTION_PROP_KEYS.includes("animate"); * ``` */export const MOTION_PROP_KEYS = [ ...MOTION_NODE_PROP_KEYS, ...SOLID_MOTION_PROP_KEYS,] as const;
/** * Target definition forms that the current Solid adapter forwards into MotionState. */export type MotionAnimationDefinition = VariantLabels | TargetAndTransition | TargetResolver;
/** * Subset of upstream `MotionNodeOptions` that the current Solid adapter forwards as plain props. * * The adapter intentionally names this slice because the Solid runtime does not yet implement the * full upstream feature surface. Keeping the supported subset explicit makes that boundary honest. */export type SupportedMotionNodeOptions = Pick< MotionNodeOptions, | "inherit" | "transformTemplate" | "layout" | "layoutId" | "layoutDependency" | "layoutScroll" | "layoutRoot" | "layoutAnchor" | "drag" | "dragConstraints" | "dragElastic" | "dragMomentum" | "dragSnapToOrigin" | "dragDirectionLock" | "dragPropagation" | "dragTransition" | "dragControls" | "dragListener" | "onUpdate" | "onAnimationStart" | "onAnimationComplete" | "onLayoutAnimationStart" | "onLayoutAnimationComplete" | "onHoverStart" | "onHoverEnd" | "onPan" | "onPanStart" | "onPanEnd" | "onDrag" | "onDragStart" | "onDragEnd" | "onDirectionLock" | "onViewportEnter" | "onViewportLeave" | "propagate">;
/** * Motion props that stay accessor-friendly because callers often express them through signals. */export type MotionAccessorProps = { initial?: MaybeAccessor<false | MotionAnimationDefinition>; animate?: MaybeAccessor<MotionAnimationDefinition>; exit?: MaybeAccessor<MotionAnimationDefinition>; transition?: MaybeAccessor<NonNullable<MotionNodeOptions["transition"]>>; variants?: MaybeAccessor<NonNullable<MotionNodeOptions["variants"]>>; custom?: MaybeAccessor<MotionNodeOptions["custom"]>; whileHover?: MaybeAccessor<NonNullable<MotionNodeOptions["whileHover"]>>; whileTap?: MaybeAccessor<NonNullable<MotionNodeOptions["whileTap"]>>; whileFocus?: MaybeAccessor<NonNullable<MotionNodeOptions["whileFocus"]>>; whileDrag?: MaybeAccessor<NonNullable<MotionNodeOptions["whileDrag"]>>; whileInView?: MaybeAccessor<NonNullable<MotionNodeOptions["whileInView"]>>;};
/** * Solid-local additions that do not exist on upstream `MotionNodeOptions` in this exact shape. */export type SolidMotionProps = { /** * Base Motion style layer that sits under animated targets. */ style?: MaybeAccessor<MotionStyle>;
/** * Stable identity hint reserved for retained presence workflows. */ presenceKey?: string | number;
/** * Solid-local press target until the adapter grows Motion's full press feature layer. */ whilePress?: MaybeAccessor<MotionAnimationDefinition>;
/** * Temporary Solid-local alias for Motion's viewport options. */ inViewOptions?: MaybeAccessor<ViewportOptions>;
/** * Press start callback shape reused from Motion's exported press event types. */ onPressStart?: (event: OnPressStartEvent, info: PressGestureInfo) => void;
/** * Press success callback shape reused from Motion's exported press event types. */ onPress?: (event: OnPressEndEvent, info: PressGestureInfo) => void;
/** * Press cancel callback shape reused from Motion's exported press gesture payload. */ onPressCancel?: (event: PointerEvent, info: PressGestureInfo) => void;};
/** * Remaining supported upstream props that can pass through without Solid accessor wrapping. */export type StaticMotionProps = Omit<SupportedMotionNodeOptions, keyof MotionAccessorProps>;
/** * Combined Motion prop surface currently supported by the Solid adapter. * * This is deliberately narrower than `MotionNodeOptions`. The adapter already reuses * motion-dom's public target, variant, transition, and gesture types where the current * Solid runtime actually matches them, but it does not yet claim the full upstream * feature surface. * * Read the combined shape as three layers: * 1. plain supported upstream props that can pass through unchanged * 2. accessor-friendly animated props that Solid callers often express as signals * 3. Solid-local extensions such as `presenceKey`, `whilePress`, and `inViewOptions` * * @example Motion target props with Solid accessors * ```ts * const props: MotionProps = { * animate: () => ({ opacity: 1, x: 24 }), * whileHover: { scale: 1.05 }, * }; * ``` * * @example Solid-local presence and press props * ```ts * const props: MotionProps = { * presenceKey: "card-a", * whilePress: { scale: 0.96 }, * }; * ``` */export type MotionProps = StaticMotionProps & MotionAccessorProps & SolidMotionProps;
/** * Splits a Solid props object into Motion-owned props and DOM-owned props without * breaking reactive property access. * * This is a Solid-specific correctness helper. Motion needs to observe animation props * in tracked effects later, while still forwarding the remaining props directly to the * underlying DOM element. `splitProps` is the mechanism Solid provides for exactly that * shape. * * @example Split a div component's props * ```ts * const [motionProps, domProps] = splitMotionProps(rawProps); * ``` * * @example Read animation intent lazily * ```ts * createEffect(() => { * const next = motionProps.animate; * void next; * }); * ``` */export function splitMotionProps<T extends Record<string, unknown>>( rawProps: T, adapter: Pick<SolidMotionAdapter, "splitProps"> = solid1Adapter,) { // The returned objects are still reactive views over the original props bag. That lets the // wrapper forward DOM props immediately while Motion keeps reading animation props lazily later. return adapter.splitProps(rawProps, MOTION_PROP_KEYS);}