Class ProgressPreloader<CallbacksMap, StaticProps, MutableProps>

Page preloader for calculating and displaying the loading progress of resources (images, videos, custom elements). Provides smooth progress transitions.

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

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_isHidden: boolean = false

Indicates if the preloader has already been hidden.

_isLoaded: boolean = false

Indicates if the page is fully loaded.

_progress: number = 0

Current interpolated progress value for smooth transitions.

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

_raf: Raf

Animation frame instance for managing smooth progress updates.

_resources: IProgressPreloaderResource[] = ...

List of custom resources to preload based on selectors.

_shouldHide: boolean = false

Indicates if the preloader is in the process of being hidden.

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.

  • Handles updates to the preloader's progress, triggering events and animations as needed.

    Parameters

    • newProgress: number

      The updated progress value.

    Returns void

  • Adds a custom resource

    Parameters

    • id: string | Element

      The custom resource element or identifier to preload.

    • weight: number = 1

      The resource weight

    Returns void

  • Hides the preloader with a custom animation duration.

    Parameters

    • duration: number

      The duration of the hide animation (in milliseconds). Applies only when the container is used.

    • Optionalcallback: () => void

      The callback to execute when the hide animation is complete.

    Returns undefined | () => void

    Returns an action destructor.

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void

  • Registers a callback for when the preloader is fully hidden.

    Parameters

    • action: () => void

      The callback function to execute.

    Returns () => void

    A destructor.

  • Registers a callback for when the preloader starts hiding.

    Parameters

    • action: () => void

      The callback function to execute.

    Returns () => void

    A destructor.

  • Emits a resource load event and updates the count of loaded resources.

    Parameters

    • id: string | Element

      The resource element or identifier being loaded.

    • OptionalloadedWeight: number

    Returns void