/** * Animation - Individual animation unit * * Manages interpolation of properties over time with easing. * Pooled for performance. */ import type { AnimationTarget, StaggerVars } from '../types'; /** * Internal animation configuration (not exported from SDK) */ export interface InternalAnimationConfig { repeat?: number; repeatDelay?: number; yoyo?: boolean; stagger?: number | StaggerVars; onStart?: () => void; onUpdate?: (progress: number) => void; onComplete?: () => void; onRepeat?: (repeatCount: number) => void; onReverseComplete?: () => void; /** * When true, Engine skips the immediate render(0) for FROM animations. * Used by Timeline._addBuilder so it can capture initial values BEFORE * FROM values are applied to the DOM, then render FROM itself afterward. */ _skipInitialRender?: boolean; } import { PropTween } from './PropTween'; import { PropTweenPool } from '../memory/PropTweenPool'; export declare class Animation { private _id; private _targets; private _duration; private _delay; private _time; private _progress; private _timeScale; private _isActive; private _isReversed; private _propTweens; private _lastPropTween; private _easingFn; private _repeat; private _repeatDelay; private _yoyo; private _currentRepeat; private _onStart?; private _onUpdate?; private _onComplete?; private _onRepeat?; private _onReverseComplete?; private _startFired; private _completeFired; private _timelineChild; private _needsStartCapture; private _startCaptured; private _fitSetupFn; private _pendingFitSetup; private _fitCleanupFn; private _unregisterCallback; private _activationCallback; /** * Initialize the animation */ init(id: number, targets: AnimationTarget[], duration: number, delay: number, ease: string, config?: InternalAnimationConfig): this; /** * Update animation by delta time */ update(deltaTime: number): void; /** * Render animation at specific progress (0-1) */ render(progress: number, shouldRender?: (propTween: PropTween) => boolean): void; /** * Render animation at an absolute time position (seconds) * Handles repeat, repeatDelay, and yoyo for timeline-driven scrubbing. * When driven by a Timeline (_isActive = true), also fires lifecycle callbacks. */ renderAtTime(totalTime: number, shouldRender?: (propTween: PropTween) => boolean): void; /** * Apply easing function to progress */ private applyEasing; /** * Handle animation completion */ private handleComplete; /** * Play the animation * - If already playing forward, does nothing * - If paused, resumes from current position */ play(from?: number): this; /** * Pause the animation */ pause(atTime?: number): this; /** * Reverse the animation */ reverse(from?: number): this; /** * Restart the animation */ restart(includeDelay?: boolean): this; /** * Seek to specific position */ seek(position: number): this; /** * Get/set progress (0-1) */ progress(): number; progress(value: number): this; /** * Get/set time in seconds */ time(): number; time(value: number): this; /** * Get/set timeScale multiplier */ timeScale(): number; timeScale(value: number): this; /** * Get timeScale multiplier (typed getter) */ getTimeScale(): number; /** * Kill the animation */ kill(): void; /** * Check if animation is active */ isActive(): boolean; /** * Check if this animation is a child of a Timeline * When true, Engine won't update or auto-pool this animation */ isTimelineChild(): boolean; /** * Set whether this animation is a child of a Timeline * Timeline children are controlled by their parent timeline and * won't be auto-pooled until the timeline is killed */ setTimelineChild(isChild: boolean): void; /** * Enable lazy start value capture (for timeline chaining) * When enabled, start values are captured on first render instead of at creation */ setLazyStartCapture(enabled: boolean): void; /** * Register a Fit setup function to execute at play time. * Stores both a persistent copy (_fitSetupFn) for replay and an active * copy (_pendingFitSetup) that is consumed by captureStartValues(). */ setPendingFitSetup(fn: (pool: typeof PropTweenPool) => void): void; /** * Register a cleanup function that resets inline styles written by a Fit animation. * Called during resetForReplay() so chained fits start from a clean slate on replay. */ setFitCleanup(fn: () => void): void; /** * Reset for timeline replay * Resets callback state for clean replay but KEEPS captured start values * so TO-only animations replay from their original start position. * Fit animations re-enable their setup so geometry is re-captured on the * next play (picking up any intervening DOM changes). */ resetForReplay(): void; /** * Check if this animation needs lazy start capture but hasn't captured yet * Used by Timeline to trigger capture when animation starts */ needsStartCapture(): boolean; /** * Check if this animation uses lazy start capture (TO-only animation) * These animations should NEVER render before their start time, * even after values have been captured, to avoid overwriting earlier animations */ isLazyCapture(): boolean; /** * Fire the onReverseComplete callback and reset start/complete flags. * Called by Timeline when an active animation exits the start boundary (going in reverse). * Resetting flags allows onStart and onComplete to fire correctly on the next forward play. */ fireReverseComplete(): void; /** * Set callback for unregistering from Engine (called on kill) * This avoids circular dependency with Engine */ setUnregisterCallback(callback: () => void): void; /** * Set callback invoked whenever this animation becomes active. * Used by Engine to restart the global ticker after it idles. */ setActivationCallback(callback: () => void): void; /** * Capture current element values as start values for all PropTweens * This enables proper chaining in timelines */ captureStartValues(): void; /** * Get animation ID */ getId(): number; /** * Get animation targets */ getTargets(): AnimationTarget[]; /** * Get duration */ getDuration(): number; /** * Get delay (used by Timeline for stagger positioning) */ getDelay(): number; /** * Clear delay (used by Timeline after extracting delay for positioning) */ clearDelay(): void; /** * Get the head of the PropTween linked list. * @internal - Use only within sdk package for property inspection (e.g. captureStartValues). */ getFirstPropTween(): PropTween | null; /** * Mark motion-path geometry stale on every prop tween so the geometry-dependent * offsets re-resolve on the next render. Called after a layout-shifting event * (window.load / resize ScrollTrigger refresh) so paths aligned to an * asynchronously-sized target settle onto the correct position. */ invalidatePathGeometry(): void; /** * Add a property tween to the linked list */ addPropTween(propTween: PropTween): void; /** * Get animation duration (including delay and repeats) * Returns Infinity for infinitely repeating animations (_repeat === -1). */ totalDuration(): number; /** * Reset for object pooling */ reset(): void; }