Class Color

    • The Color class represents a color with various color space representations and manipulation methods.
    • The class supports multiple color spaces, including RGB, HSL, HSV, CMYK, LAB, LCH, XYZ, and YUV.
    • It also provides methods for converting between color spaces and generating harmony colors.
    • The class offers various color manipulation methods, such as adjusting lightness, saturation, hue, and alpha.
    • It also provides methods for converting colors to different string representations and retrieving information about the color.
    • The class also includes utility methods for determining the perceived brightness of the color and checking if it is light or dark.

Constructors

  • Creates a new Color instance.

    Parameters

    • color:
          | string
          | RGB
          | HSL
          | HSV
          | CMYK
          | LAB
          | LCH
          | XYZ
          | YUV

      The color value to initialize with. Can be a string (hex) or an object representing various color spaces.

    Returns Color

Accessors

  • get a(): undefined | number
  • Gets the alpha component of the color.

    Returns undefined | number

    The alpha value if set, otherwise undefined.

  • set a(value): void
  • Sets the alpha component of the color.

    Parameters

    • value: undefined | number

    Returns void

  • get b(): number
  • Gets the blue component of the color.

    Returns number

  • set b(value): void
  • Sets the blue component of the color.

    Parameters

    • value: number

    Returns void

  • get g(): number
  • Gets the green component of the color.

    Returns number

  • set g(value): void
  • Sets the green component of the color.

    Parameters

    • value: number

    Returns void

  • get r(): number
  • Gets the red component of the color.

    Returns number

  • set r(value): void
  • Sets the red component of the color.

    Parameters

    • value: number

    Returns void

Methods

  • Adjusts the alpha of the color.

    Parameters

    • amount: number

      The new alpha value, from 0 to 1.

    Returns Color

    A new Color instance with adjusted alpha.

  • Adjusts the hue of the color.

    Parameters

    • amount: number

      The amount to adjust by, in degrees.

    Returns Color

    A new Color instance with adjusted hue.

  • Adjusts the lightness of the color.

    Parameters

    • amount: number

      The amount to adjust by, from -100 to 100.

    Returns Color

    A new Color instance with adjusted lightness.

  • Adjusts the saturation of the color.

    Parameters

    • amount: number

      The amount to adjust by, from -100 to 100.

    Returns Color

    A new Color instance with adjusted saturation.

  • Checks if this color is equal to another color.

    Parameters

    • other: Color

      The color to compare with.

    Returns boolean

  • Calculates the perceived brightness of the color.

    Returns number

    A value between 0 (darkest) and 255 (lightest)

  • Asynchronously retrieves information about the color.

    Returns Promise<ColorInfo>

    A promise that resolves to the color information.

  • Asynchronously gets the name of the color.

    Returns Promise<string>

    The name of the color.

  • Determines if the color is perceived as "light" or "dark".

    Parameters

    • threshold: number = 128

      The brightness threshold (0-255). Default is 128.

    Returns boolean

    true if the color is light, false if it's dark

  • Mixes the color with another color.

    Parameters

    • color: Color

      The color to mix with.

    • amount: number

      The amount of the other color to mix in, from 0 to 1.

    Returns Color

    A new Color instance representing the mixed color.

  • Generates monochromatic colors.

    Parameters

    • Optionalcount: number

      The number of colors to generate.

    Returns Color[]

  • Generates shades of the color.

    Parameters

    • Optionalcount: number

      The number of shades to generate.

    Returns Color[]

  • Generates tints of the color.

    Parameters

    • Optionalcount: number

      The number of tints to generate.

    Returns Color[]

  • Converts the color to Hex format.

    Parameters

    • includeAlpha: boolean = false

      Whether to include the alpha channel in the hex string.

    Returns string

  • Returns a string representation of the color.

    Parameters

    • includeAlpha: boolean = false

      Whether to include the alpha channel in the string representation.

    Returns string

  • Generates tones of the color.

    Parameters

    • Optionalcount: number

      The number of tones to generate.

    Returns Color[]

  • Sets the precision for number rounding in the Color class.

    Parameters

    • precision: number

      The number of decimal places to round to.

    Returns void

""