Class Raf<CallbacksMap, StaticProps, MutableProps>

Manages an animation frame loop with configurable FPS and playback controls.

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_callbacks: Callbacks<CallbacksMap>

Callbacks instance

_destroyable: () => void[] = []

Stores actions that need to be executed when the module is destroyed

_duration: number = 0

Duration of the last frame in ms

_fps: number = 60

Real-time FPS

_index: number = 0

Current frame index

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_isPlaying: boolean = false

Indicates if the animation frame is currently running

_lastTimestamp: null | number = null

Timestamp of the last frame

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

_raf: null | number = null

Active requestAnimationFrame ID, or null if not running

_timestamp: null | number = null

Timestamp of the current frame

Accessors

  • get isDestroyed(): boolean

    Checks if the module has been destroyed.

    Returns boolean

  • get name(): string

    The name of the module, derived from the class name

    Returns string

  • get prefix(): string

    Optional prefix for classnames used by the module

    Returns string

Methods

  • Adds a class name on an element, and keeps track of it for removal when the module is destroyed.

    Parameters

    • element: Element

      The target DOM element.

    • className: string

      The class name to toggle.

    Returns void

  • Helper function to generate classnames with the module's prefix.

    Parameters

    • ...classNames: string[]

      The class names to generate.

    Returns string

    A string of class names with the module's prefix applied.

  • Calculate linear interpolation factor to make animations run the same regardless of FPS

    Parameters

    • ease: number

    Returns number

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void