Class Preloader<C, S, M>

Page preloader — loading screen visibility and lifecycle.

Does not provide styling for the container.

Lifecycle

loaded → hide (auto or manual) → container fade → hidden

When hide is false, call hide manually after load. When container is null, only events fire — no DOM animation.

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Accessors

  • get isDestroyed(): boolean

    Indicates whether the instance has been destroyed.

    After destruction, destroy is a no-op.

    Returns boolean

  • get isHidden(): boolean

    Whether the hide animation has completed and hidden has fired.

    Returns boolean

  • get isHiding(): boolean

    Whether hide has started but hidden has not fired yet.

    Returns boolean

  • get isLoaded(): boolean

    Whether the load signal has fired and loaded was emitted.

    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 prefixed classes to an element and removes them on destroy.

    Skips classes that are already present on the element.

    Parameters

    • element: Element

      Target DOM element.

    • ...classes: string[]

      Unprefixed class name segments.

    Returns void

  • Builds one or more prefixed class names.

    Parameters

    • ...classes: string[]

      Unprefixed class name segments.

    Returns string

    Space-separated prefixed class string.

  • Internal method to handle the destruction of the module. It removes all callbacks, destroys properties, and cleans up event listeners and class names.

    Returns void

  • Emits a callback event with a fixed payload.

    Type Parameters

    • E extends string | number | symbol

    Parameters

    • event: E
    • arg: C[E]

    Returns void

  • Set default mutable props

    Returns TRequiredProps<M>

  • Get default static props

    Returns TRequiredProps<S>

  • Method that is called when the module's properties mutate. In most cases, used to handle callbacks.

    Parameters

    • diff: Partial<M>

    Returns void

  • Subscribes to the load signal.

    Default: initVevet().onLoad. ProgressPreloader overrides this to wait for resource progress.

    Parameters

    • callback: () => void

    Returns void

  • Destroys the instance and runs all registered cleanup actions.

    Safe to call multiple times; subsequent calls are ignored.

    Execution order:

    1. _destroy
    2. all onDestroy callbacks, in registration order
    3. isDestroyed is set to true

    Returns void

  • Hides the preloader with a fade on container.

    Works only after load and when not already hiding. The returned destructor cancels the optional callback only — the fade still runs.

    Parameters

    • duration: number
    • Optionalcallback: () => void

    Returns undefined | () => void

  • Adds a custom callback to the module.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    Returns () => void

  • Registers a function to run when the instance is destroyed.

    If the instance is already destroyed, action runs immediately.

    Parameters

    • action: () => void

      Cleanup function (for example remove listeners or DOM classes).

    Returns void

  • Registers a one-shot listener for hidden, or runs immediately if already hidden.

    Parameters

    • action: () => void

    Returns () => void

    A destructor that removes the listener.

  • Registers a one-shot listener for hide, or runs immediately if already hiding.

    Parameters

    • action: () => void

    Returns () => void

    A destructor that removes the listener.

  • Change module's mutable properties

    Parameters

    • props: Partial<M>

    Returns void