npm.nicfv.com

    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]

    red: number

    Red channel intensity [0, 255]

    Methods

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

      Returns Color

      Black or white

      const contrast = red.getContrastingColor();
      // Returns the color white (255, 255, 255)
    • Return a string representation of this color.

      Parameters

      • type: "rgb" | "rgba" | "hex" | "hex-transparency" = 'rgba'

      Returns string

      A valid CSS color code

      const css = red.toString(); // rgba(255,0,0,100%)
      
    • 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 (6 chars total)
      • String can optionally start with the character '#'
      • Alpha channel can be included for an additional 2 bits (8 chars total)

      Parameters

      • hex: string

        Hexadecimal string

      Returns Color

      A new color defined by the hexadecimal string

      const red = Color.from('#ff0000');
      
    MMNEPVFCICPMFPCPTTAAATR