npm.nicfv.com
    Preparing search index...

    Class Color

    Structure for storing colors based on RGBa values.

    Index

    Constructors

    • Define a new color from RGBa values.

      Parameters

      • red: number

        Red channel intensity [0, 255]

      • green: number

        Green channel intensity [0, 255]

      • blue: number

        Blue channel intensity [0, 255]

      • alpha: number = 100

        Alpha channel transparency [0, 100]

      Returns Color

      const red = new Color(255, 0, 0);
      

    Properties

    alpha: number = 100

    Alpha channel transparency [0, 100]

    blue: number

    Blue channel intensity [0, 255]

    green: number

    Green channel intensity [0, 255]

    hue: number

    Color hue, in degrees [0, 360)

    lightness: number

    Lightness percent [0, 100]

    red: number

    Red channel intensity [0, 255]

    saturation: number

    Saturation percent [0, 100]

    Methods

    • Return the most contrasting color for text on a background of this color.

      Returns Color

      Black or white

      const contrast = red.getContrastingColor(); // #FFFFFF
      
    • Return a string representation of this color.

      Parameters

      • type: "rgb" | "hsl" | "hex" = 'hex'

        The color encoding to use

      Returns string

      A valid CSS color code

      const css = red.toString(); // #FF0000
      
    • Create a new color given a hexadecimal string. Will throw an error if the string is invalid.

      • Expects 2 bits [0-F] for red, green, blue channels each
      • String can optionally start with the character '#'
      • Alpha channel can be included in the final 2 bits

      Parameters

      • hex: string

        Hexadecimal string

      Returns Color

      A new color defined by the hexadecimal string

      const red = Color.hex('#ff0000');
      
    • Parameters

      • hue: number

        The color hue, in degrees [0, 360)

      • saturation: number

        The saturation percent [0, 100]

      • lightness: number

        The lightness percent [0, 100]

      • alpha: number = 100

        Alpha channel intensity [0, 100]

      Returns Color

      A new color defined by hue, sautration, and lightness

      const red = Color.hsl(0, 100, 50); // #FF0000
      
    • Define a new color from RGBa values. Alias for new Color(...)

      Parameters

      • red: number

        Red channel intensity [0, 255]

      • green: number

        Green channel intensity [0, 255]

      • blue: number

        Blue channel intensity [0, 255]

      • alpha: number = 100

        Alpha channel transparency [0, 100]

      Returns Color

      A new color defined by color channel intensity values

      const red = Color.rgb(255, 0, 0); // #FF0000