Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Color

Hierarchy

  • Color

Index

Constructors

constructor

  • new Color(r?: string | number | Rgb | Rgba, g?: number, b?: number, a?: number): Color
  • Creates a new black color instance of the Color object

    Parameters

    • r: string | number | Rgb | Rgba = 0
    • Optional g: number
    • Optional b: number
    • Optional a: number

    Returns Color

Properties

Private a

a: number = 1

The alpha color component. Stored as a number from 0 to 1

Private b

b: number = 0

The blue color component. Stored as a number from 0 to 255

Private g

g: number = 0

The green color component. Stored as a number from 0 to 255

Private r

r: number = 0

The red color component. Stored as a number from 0 to 255

Static Convertor

Convertor: { hslToRgb: any; numberOrPercentage: any; rgbToHsl: any } = ...

Type declaration

  • hslToRgb:function
    • Converts an hsl color to rgb

      Parameters

      • hsl: HSL

        The color to be converted

      Returns Rgb

  • numberOrPercentage:function
    • numberOrPercentage(value: string, range: number, isInt: boolean): number
    • Parses a string in numeric or percentage format

      Parameters

      • value: string

        Value to parse

      • range: number

        The maximum range value for the percentage (e.g.: 255, 360 or 100)

      • isInt: boolean

        When true, rounds the value to an integer

      Returns number

      The parsed value as a number

  • rgbToHsl:function
    • Converts an rgb color to hsl

      Parameters

      • rgb: Rgb

        The color to be converted

      Returns HSL

Static Validator

Validator: { checkHEX: (value: string) => void } = ...

Type declaration

  • checkHEX: (value: string) => void
      • (value: string): void
      • Check a hexa color (without #)

        Parameters

        • value: string

        Returns void

Accessors

alpha

  • get alpha(): number
  • set alpha(value: number): void
  • The alpha (transparency) as a number from 0 to 1

    Returns number

  • The alpha (transparency) as a number from 0 to 1

    Parameters

    • value: number

    Returns void

blue

  • get blue(): number
  • set blue(value: number): void
  • The blue channel as a number from 0 to 255

    Returns number

  • The blue channel as a number from 0 to 255

    Parameters

    • value: number

    Returns void

green

  • get green(): number
  • set green(value: number): void
  • The green channel as a number from 0 to 255

    Returns number

  • The green channel as a number from 0 to 255

    Parameters

    • value: number

    Returns void

hue

  • get hue(): number
  • set hue(value: number): void
  • The hue as a number from 0 to 360. This is a calculated value (use it wisely)

    Returns number

  • The hue as a number from 0 to 360. This is a calculated value (use it wisely)

    Parameters

    • value: number

    Returns void

red

  • get red(): number
  • set red(value: number): void
  • The red channel as a number from 0 to 255

    Returns number

  • The red channel as a number from 0 to 255

    Parameters

    • value: number

    Returns void

rgb

  • get rgb(): Rgb
  • set rgb(value: Rgb): void
  • The Color as an Rgb structure

    Returns Rgb

  • The Color as an Rgb structure

    Parameters

    Returns void

rgba

  • get rgba(): Rgba
  • set rgba(value: Rgba): void

rgbaByte

  • get rgbaByte(): Rgba
  • The Color as an Rgba structure where the alpha also ranges from 0 to 255

    Returns Rgba

Methods

clone

  • Copies the values into a new Color object

    Returns Color

    A new Color object

fromHsla

  • fromHsla(value: Hsla): void
  • Reads and convert the Hsla structure

    Parameters

    • value: Hsla

      The input Hsla structzure

    Returns void

getHashCode

  • getHashCode(): string
  • Returns a string uniquely identifying the color

    Returns string

    A string uniquely identifying the color (currently rgba)

parse

  • parse(str: string): void
  • Reads the value from an CSS color string

    Parameters

    • str: string

      String to parse. Accepted formats are Hex, Rgb or Hsl

    Returns void

Private parseHex

  • parseHex(value: string): void

Private parseHsla

  • parseHsla(str: string): void

Private parseRgba

  • parseRgba(str: string): void

sanitize

  • sanitize(): void
  • Make sure that the values are in the right range

    Returns void

Private sanitizeRgbValue

  • sanitizeRgbValue(value: number): number
  • Parameters

    • value: number

    Returns number

toHslString

  • toHslString(): string
  • Converts the color to an CSS hsl string

    Returns string

    The color as an hsl string

toHsla

toHslaString

  • toHslaString(): string
  • Converts the color to an CSS hsla string

    Returns string

    The color as an hsla string

toRgbString

  • toRgbString(): string
  • Converts the color to a CSS rgb string

    Returns string

    The color as an rgb string

toRgbaString

  • toRgbaString(): string
  • Converts the color to a CSS rgba string

    Returns string

    The color as an rgba string

toString

  • toString(): string
  • Returns the color as a HEX string

    Returns string

    Color in HEX format

tohexString

  • tohexString(): string
  • Returns the color as an Hex string (e.g. #FFFFFF)

    Returns string

    An Hex string

Static colorDistance

  • colorDistance(c1: Rgb, c2: Rgb, normalize?: boolean): number
  • Compares 2 colors and returns a value indicating the distance between them

    Parameters

    • c1: Rgb

      The first color to compare

    • c2: Rgb

      The second color to compare

    • normalize: boolean = false

      When true returns a value between 0 and 1

    Returns number

    A value indicating the distance between 2 colors

Static newHslColor

  • newHslColor(h: number | HSL | Hsla, s?: number, l?: number, a?: number): Color
  • Creates a new color object based on th Hsla structure

    Parameters

    • h: number | HSL | Hsla

      Hue (from 0 to 360) or Hsl or Hsla structure

    • Optional s: number

      Saturation (from 0 to 100)

    • Optional l: number

      Lightness (from 0 to 100)

    • Optional a: number

      Alpha (from 0 to 1)

    Returns Color

    A new instance of the Color object

Generated using TypeDoc