Class TextLayer

Hierarchy (view full)

Constructors

Accessors

  • get canvas(): HTMLCanvasElement
  • Get output canvas

    Returns HTMLCanvasElement

  • get outlineColor(): string
  • Current outline colour as a CSS hex string (e.g. '#FF0000').

    Returns string

  • get adjustDirection(): "both" | "shrink" | "expand"
  • Current adjustWidth direction mode.

    Returns "both" | "shrink" | "expand"

  • get adjustWidth(): boolean
  • Whether automatic font shrinking to fit the layer width is enabled.

    Returns boolean

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

  • 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.

  • 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

  • Set the outline width in pixels and redraw. Set to 0 to disable the outline.

    Parameters

    • width: number

    Returns void

  • Set the outline colour and redraw.

    Parameters

    • color: string

      CSS color string (e.g. '#FF0000')

    Returns void

  • Set the font family and redraw.

    Parameters

    • family: string

      CSS font-family string (e.g. 'Arial', 'monospace')

    Returns void

  • Set the font size and redraw.

    Parameters

    • size: number

      Font size value (interpreted according to the layer's fontUnit).

    Returns void

  • Reset the font size back to the value originally configured when this layer was created, undoing any setFontSize() calls and any adjustWidth shrink/grow memory, then redraw.

    Returns void

  • Set the text fill color and redraw the current text.

    Parameters

    • color: string

      CSS color string (e.g. '#FF0000' or a Colors value)

    Returns void

  • Enable or disable automatic font shrinking so the text fits the layer width, then redraw.

    Parameters

    • enabled: boolean

    Returns void

  • Set how the adjustWidth-computed font size can change across setText() calls, then redraw. See TextLayerOptions.adjustDirection for the meaning of each value. Resets any previously remembered shrink/grow size.

    Parameters

    • direction: "both" | "shrink" | "expand"

    Returns void