Used to add a badge (pill) to a given image, this can be used to update a favicon and more.

Inspired by Roko C. Buljan's answer on Stack Overflow. Reference

Hierarchy

Constructors

Properties

#canvas: HTMLCanvasElement = ...
#ctx: null | CanvasRenderingContext2D = ...
#image: HTMLImageElement = ...
#offset: {
    x: number;
    y: number;
} = ...

Type declaration

  • x: number
  • y: number
#options: Required<BadgerOptions> = Badger.DefaultOptions
#size: number = 0
#url: string
#value: number = 0
DefaultOptions: Required<BadgerOptions> = ...
Offsets: {
    bottom: {
        x: number;
        y: number;
    };
    bottomLeft: {
        x: number;
        y: number;
    };
    bottomRight: {
        x: number;
        y: number;
    };
    center: {
        x: number;
        y: number;
    };
    left: {
        x: number;
        y: number;
    };
    right: {
        x: number;
        y: number;
    };
    top: {
        x: number;
        y: number;
    };
    topLeft: {
        x: number;
        y: number;
    };
    topRight: {
        x: number;
        y: number;
    };
} = ...

Type declaration

  • bottom: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • bottomLeft: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • bottomRight: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • center: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • left: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • right: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • top: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • topLeft: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
  • topRight: {
        x: number;
        y: number;
    }
    • x: number
    • y: number
prefixed: string | boolean

Accessors

  • get backgroundColor(): string | CanvasGradient | CanvasPattern
  • The background color for the badge (pill).

    Returns string | CanvasGradient | CanvasPattern

  • set backgroundColor(value): void
  • Parameters

    • value: undefined | string | CanvasGradient | CanvasPattern

    Returns void

  • get color(): string | CanvasGradient | CanvasPattern
  • The text color for the badge (pill).

    Returns string | CanvasGradient | CanvasPattern

  • set color(value): void
  • Parameters

    • value: undefined | string | CanvasGradient | CanvasPattern

    Returns void

  • get position(): "top" | "right" | "bottom" | "left" | "topLeft" | "topRight" | "bottomRight" | "bottomLeft" | "center"
  • Where the badge should be positioned.

    Returns "top" | "right" | "bottom" | "left" | "topLeft" | "topRight" | "bottomRight" | "bottomLeft" | "center"

  • set position(value): void
  • Parameters

    • value: undefined | "top" | "right" | "bottom" | "left" | "topLeft" | "topRight" | "bottomRight" | "bottomLeft" | "center"

    Returns void

  • get radius(): number
  • The border radius for the badge (pill).

    Returns number

  • set radius(value): void
  • Parameters

    • value: undefined | number

    Returns void

  • get size(): number
  • A value between 0 and 1 representing the size of the badge.

    Returns number

  • set size(value): void
  • Parameters

    • value: undefined | number

    Returns void

  • get src(): string
  • The url to the image we want to draw the badge on.

    Returns string

  • set src(value): void
  • Parameters

    • value: undefined | string

    Returns void

  • get url(): string
  • The data url for the most recent draw call.

    Returns string

  • get value(): number
  • The number to render within the badge.

    Returns number

  • set value(value): void
  • Parameters

    • value: undefined | number

    Returns void

Methods

  • Type Parameters

    Parameters

    • event: T
    • fn: ((...args) => void)
    • Optional context: any

    Returns this

  • Calls each of the listeners registered for a given event.

    Type Parameters

    Parameters

    Returns boolean

  • Return an array listing the events for which the emitter has registered listeners.

    Returns (keyof BadgerEvents)[]

  • Return the number of listeners listening to a given event.

    Parameters

    Returns number

  • Return the listeners registered for a given event.

    Type Parameters

    Parameters

    • event: T

    Returns ((...args) => void)[]

  • Type Parameters

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
    • Optional context: any
    • Optional once: boolean

    Returns this

  • Add a listener for a given event.

    Type Parameters

    Parameters

    • event: T
    • fn: ((...args) => void)
    • Optional context: any

    Returns this

  • Add a one-time listener for a given event.

    Type Parameters

    Parameters

    • event: T
    • fn: ((...args) => void)
    • Optional context: any

    Returns this

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: keyof BadgerEvents

    Returns this

  • Remove the listeners of a given event.

    Type Parameters

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
    • Optional context: any
    • Optional once: boolean

    Returns this

Generated using TypeDoc