A color shade.

Properties

B: number

The shade's B value

G: number

The shade's G value

R: number

The shade's R value

hex: string

The shade's hex value

id: string = "unknown"

The id of the shade

index: number = -1

The index of the shade

onHex: string = ""

The onHex value for this shade

opacity: number = 1

The opacity of the shade

rgbArray: number[]

The shade's RGB array

BLACK: Shade = ...

The black shade

DARK_BLUE: Shade = ...

The dark blue shade

GRAY: Shade = ...

The gray shade

HALF_BLACK: Shade = ...

The half-black shade

HALF_WHITE: Shade = ...

The half-white shade

HALF_WHITE_DM: Shade = ...

The half-white dark mode shade

NEAR_BLACK: Shade = ...

The near black shade

OFF_BLACK: Shade = ...

The off-black shade

OFF_WHITE: Shade = ...

The off-white shade

WHITE: Shade = ...

The white shade

WHITE_DM: Shade = ...

The white dark mode shade

Methods

  • Build a dark mode shade for this shade

    Parameters

    • OptionalminRatio: number

      The minimum contrast ratio to white or black

    Returns Shade

    The new dark mode shade

  • Build a light mode shade for this shade which meets the min contrast ratio requirements

    Parameters

    • OptionalminRatio: number

      The minimum contrast ratio

    Returns Shade

    The adjusted shade meeting the contrast ratio requirements

  • Build a shade

    Parameters

    • lm: boolean

      True for light mode; false for dark mode

    • OptionalminRatio: number

      Optional minRatio for the contrast ratio comparison for the on text

    Returns Shade

  • Build light or dark mode shades for this shade.

    Parameters

    • lm: boolean

      True for light mode or false for dark mode

    Returns Shade[]

    Shades for this shade

  • Find a dark mode shade which meets the contrast ratio on these background shades

    Parameters

    • bgShades: Shade[]

      The background shades

    • ratio: number

      The required contrast ratio

    Returns Shade

    A dark mode shade meeting the contrast ratio requirement, or throws an exception if not found.

  • Find a light mode shade which meets the contrast ratio on this background shade

    Parameters

    • bgShades: Shade[]
    • ratio: number

      The required contrast ratio

    Returns Shade

    A light mode shade meeting the contrast ratio requirement, or throws an exception if not found.

  • Get the contrast of this shade to white or black.

    Returns number

    The contrast of this shade to white or black.

  • Calculate the contrast ratio between two shades.

    Parameters

    Returns number

  • Get the contrast of this shade to white or black.

    Parameters

    • lm: boolean

    Returns number

  • Get the corresponding dark mode shade (i.e. at the same index) for a light mode shade.

    Returns Shade

    The corresponding dark mode shade

  • Get a dark mode shade which meets the contrast ratio on these background shades

    Parameters

    • bgShades: Shade[]

      The background shades

    • ratio: number

      The required contrast ratio

    Returns undefined | Shade

    A dark mode shade meeting the contrast ratio requirements, or undefined if not found

  • Get the hex value if no opacity, or RGBA string if opacity is not 1.

    Returns string

  • Get a light mode shade which meets the contrast ratio on this background shade. Find the shade closest to this shade which meets the contrast ratio requirement against the background shade.

    Parameters

    • bgShades: Shade[]
    • ratio: number

      The required contrast ratio

    Returns undefined | Shade

    A light mode shade meeting the contrast ratio requirement, or undefined if not found

  • Get the lightness of this shade.

    Returns number

    The lightness of this shade.

  • Get the luminance of this shade.

    Returns number

    The luminance

  • Get the shade's mode

    Returns ColorMode

    The mode, or throws exception if node.

  • Get the perceived lightness of this shade.

    Returns number

    The perceived lightness of this shade.

  • Get the saturation of this shade.

    Returns number

    The saturation of this shade.

  • Find a shade which meets the contrast ratio requirements on this background shade.

    Parameters

    • lm: boolean

      true for light mode and false for dark mode.

    • bgShades: Shade[]
    • ratio: number

      The contrast ratio requirement

    Returns undefined | Shade

  • Return either this shade or the onShade based on contrast requirements to 'shade'.

    Parameters

    • shade: Shade

      The shade to compare to this one

    • lm: boolean
    • Optionalmultiplier: number

      Optional multiplier

    Returns Shade

    This shade or the onShade

  • Determine if the shade has a mode.

    Returns boolean

    True if it has a mode

  • Determine if this shade is a core shade.

    Returns boolean

    True if this is a core shade; false, otherwise.

  • Return true if the contrast ratio of this shade to all 'bgShades' meets or exceeds 'ratio'; otherwise, return false.

    Parameters

    • bgShades: Shade[]
    • ratio: number

    Returns boolean

  • Mix this shade with another shade to produce a third shade.

    Parameters

    • shade: Shade

      The other shade to mix with this shade

    • ratio: number

      The ratio; a value between 0 and 1 denoting how much of this shade verses the other shade in the resulting shade.

    Returns Shade

    A third shade which is the mixture of this shade and the 'shade'.

  • Create a shade object from it's hex value.

    Parameters

    • hex: string

      The hex value for the color shade.

    • OptionalcoreShadeName: string

      An optional core shade name for this object.

    Returns Shade

    The shade object

  • Create a shade object from it's R, G, and B values.

    Parameters

    • R: number

      Red value.

    • G: number

      Green value.

    • B: number

      Blue value.

    Returns Shade

    The shade object

  • Create a shade object from an [R,G,B] array.

    Parameters

    • rgbArray: number[]

      The [R,G,B] array.

    Returns Shade

    The shade object.

  • Get a core shade given the core shade name.

    Parameters

    • coreShadeName: string

      The core shade name.

    Returns undefined | Shade

    The core shade, or undefined if none found by this name.