UNPKG

@ssgoi/core

Version:

Core animation engine for SSGOI - Native app-like page transitions with spring physics

75 lines 2.8 kB
import { MultiAnimationConfig } from '../types'; import { Animator } from '../animator/types'; export declare const TRANSITION_STRATEGY: unique symbol; export interface StrategyContext { currentAnimation: { controller: Animator; direction: "in" | "out"; } | null; } /** * Internal animation setup returned by strategy * Always uses MultiAnimationConfig (normalized from user's Single/Multi config) * @internal */ export interface InternalAnimationSetup { config?: MultiAnimationConfig; state: { position: number; velocity: number; }; from: number; to: number; direction: "forward" | "backward"; } /** * Internal transition configs passed to strategy * Uses Promise<MultiAnimationConfig> to allow lazy evaluation * @internal */ export interface InternalTransitionConfigs { in?: Promise<MultiAnimationConfig>; out?: Promise<MultiAnimationConfig>; } export interface TransitionStrategy { runIn: (configs: InternalTransitionConfigs) => Promise<InternalAnimationSetup>; runOut: (configs: InternalTransitionConfigs) => Promise<InternalAnimationSetup>; } /** * Creates a transition callback that can be used with framework-specific implementations * This is the core logic that frameworks can wrap with their own APIs * * UX Animation Behavior - 4 Main Scenarios: * * 1. No animation running + IN trigger: * - Start entrance animation (0 → 1) * - Return cleanup function for exit * * 2. No animation running + OUT trigger: * - Clone element, start exit animation (1 → 0) * - Remove clone when complete * * 3. IN animation running + OUT trigger: * - Stop current IN animation (DOM is disappearing) * - Clone element for exit animation * - Create REVERSED IN animation (not OUT animation) with current state * - This gives natural backward motion instead of jumping to OUT definition * * 4. OUT animation running + IN trigger: * - Stop current OUT animation (cleanup any cloned elements) * - Create REVERSED OUT animation (not IN animation) with current state * - This gives natural backward motion instead of jumping to IN definition * - Switch to entrance mode * * Closure Structure: * - Outer function: Returns entrance callback * - Inner function (entrance callback): Returns cleanup callback (exit) * - Cleanup callback: Handles exit transitions */ export declare const createDefaultStrategy: (context: StrategyContext) => TransitionStrategy; /** * Page transition strategy - Always starts fresh without checking current animations * This is used for page-level transitions where each transition should be independent */ export declare const createPageTransitionStrategy: () => TransitionStrategy; //# sourceMappingURL=transition-strategy.d.ts.map