Class BaseLayerAbstract

Hierarchy (view full)

Constructors

  • Parameters

    • id: string
    • width: number
    • height: number
    • Optional options: Options<OptionsObject>
    • Optional loadedListener: ((layer) => void | Promise<void>)
        • (layer): void | Promise<void>
        • Parameters

          Returns void | Promise<void>

    • Optional updatedListener: ((layer) => void | Promise<void>)
        • (layer): void | Promise<void>
        • Parameters

          Returns void | Promise<void>

    Returns BaseLayer

Accessors

Methods

  • Add a renderer to this layer. It's constructed with the layer's own width/height, so callers pass only the class and its config - never dimensions.

    Type Parameters

    Parameters

    • id: string

      unique id for this renderer within the layer

    • rendererClass: (new (width, height, params?) => T)

      the renderer class (not an instance)

        • new (width, height, params?): T
        • Parameters

          • width: number
          • height: number
          • Optional params: P

          Returns T

    • Optional params: P

      optional config forwarded to the renderer constructor

    • active: boolean = true

      if true (default) the renderer is added to the render queue

    Returns Promise<T>

    the constructed, initialised renderer instance

    Example

    const shaky = await layer.addRenderer('shaky', ShakyRenderer, { mode: 'decay' })
    shaky.triggerShake()
  • Remove a renderer from this layer. If it was in the render queue, it will be removed from there too.

    Parameters

    • id: string

      Renderer id to remove. If not found, this is a no-op.

    Returns void

  • Pause a renderer without destroying it. The instance is kept and can be re-enabled with activateRenderer. Order in the queue is preserved.

    Parameters

    • id: string

      Renderer id to deactivate. No-op if not found or already inactive.

    Returns void

  • Re-enable a previously deactivated renderer, restoring it at its original position in the queue. The renderer must have been registered via the constructor renderers dict or addRenderer.

    Parameters

    • id: string

      Renderer id to activate.

    Returns void

    Throws

    if the renderer is not registered on this layer.

  • Returns true if the renderer is registered and currently active.

    Parameters

    • id: string

    Returns boolean

  • Set the background fill color for this layer and trigger a redraw. Pass undefined to clear.

    Parameters

    • color: string

    Returns void

  • Set the background fill opacity (0–1) and trigger a redraw.

    Parameters

    • opacity: number

    Returns void

  • Set the border stroke color and trigger a redraw.

    Parameters

    • color: string

    Returns void

  • Set the border stroke width in pixels and trigger a redraw.

    Parameters

    • width: number

    Returns void

  • Set the layer opacity.

    Parameters

    • opacity: number

      value between 0 (transparent) and 1 (opaque)

    Returns void

  • Animate layer opacity from its current value to 1 (fully opaque).

    Parameters

    • duration: number

      fade duration in ms

    • easing: EasingFunction = Easing.easeOutSine

      easing function (defaults to easeOutSine)

    Returns Promise<void>

    resolves when the fade completes

  • Animate layer opacity from its current value to 0 (fully transparent).

    Parameters

    • duration: number

      fade duration in ms

    • easing: EasingFunction = Easing.easeOutSine

      easing function (defaults to easeOutSine)

    Returns Promise<void>

    resolves when the fade completes