Class Canvas<CallbacksMap, StaticProps, MutableProps>

A class for managing an HTML5 Canvas element and its 2D context.

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_callbacks: Callbacks<CallbacksMap>

Callbacks instance

_canvas: HTMLCanvasElement

The canvas element created for rendering

_ctx: CanvasRenderingContext2D

The 2D rendering context.

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

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

_dpr: number

The current device pixel ratio (DPR)

_height: number

The current height of the canvas, considering the device pixel ratio (DPR)

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

_width: number

The current width of the canvas, considering the device pixel ratio (DPR)

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.

  • 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

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void