x4js - v2.3.33
    Preparing search index...

    Class Color

    Index
    • Creates a new Color instance from a string.

      Parameters

      • value: string

        The color string (e.g. "#ff0000", "rgb(255,0,0)").

      Returns Color

    • Creates a new Color instance from RGB values.

      Parameters

      • r: number

        Red component (0-255).

      • g: number

        Green component (0-255).

      • b: number

        Blue component (0-255).

      • Optionala: number

        Alpha component (0-1).

      Returns Color

    • Gets the contrast ratio between the color and another one, as WCAG defines it.

      Parameters

      • other: Color

        The other color.

      Returns number

      The ratio (1 for the same luminance, 21 for black and white).

    • Darkens the color by a given percentage.

      Parameters

      • percent: number

        The percentage to darken (0-100).

      Returns this

      The current Color instance.

    • Gets the alpha (transparency) value of the color.

      Returns number

      The alpha value (0-1).

    • Checks if the color is invalid (e.g. failed parsing).

      Returns boolean

      True if the color is invalid, false otherwise.

    • Lightens the color by a given percentage.

      Parameters

      • percent: number

        The percentage to lighten (0-100).

      Returns this

      The current Color instance.

    • Gets the relative luminance of the color, as WCAG defines it. The alpha is not used.

      Returns number

      The luminance (0 for black, 1 for white).

    • Mixes the color with another one, alpha included.

      Parameters

      • other: Color

        The other color.

      • amount: number

        The part of the other color (0-1): 0 keeps this color, 1 gives the other one.

      Returns this

      The current Color instance.

    • Sets the alpha (transparency) value of the color.

      Parameters

      • a: number

        The new alpha value (0-1).

      Returns this

      The current Color instance.

    • Sets the color using HSV (Hue, Saturation, Value) components.

      Parameters

      • h: number

        Hue (0-1).

      • s: number

        Saturation (0-1).

      • v: number

        Value (0-1).

      • a: number = 1.0

        Alpha (0-1, default 1.0).

      Returns this

      The current Color instance.

    • Sets the color using RGB (Red, Green, Blue) components.

      Parameters

      • r: number

        Red component (0-255).

      • g: number

        Green component (0-255).

      • b: number

        Blue component (0-255).

      • a: number = 1.0

        Alpha component (0-1, default 1.0).

      Returns this

      The current Color instance.

    • accepts: #aaa #ababab #ababab55 rgb(a,b,c) rgba(a,b,c,d) var( --color-5 ) cyan transparent any other colour of css the browser knows: hsl( ), oklch( ), color-mix( )...

      Parameters

      • value: string

      Returns this

    • Gets, of two colors of text, the one that contrasts most with the color.

      Parameters

      • light: Color = WHITE

        The light text color (white by default).

      • dark: Color = BLACK

        The dark text color (black by default).

      Returns Color

      A copy of light or dark.

    • Returns the Hex string representation of the color.

      Returns string

      The hex color string (e.g. "#ff0000" or "#ff000080").

    • Converts the color to HSV representation.

      Returns Hsv

      An object containing hue, saturation, value, and alpha properties.

    • Returns the CSS string representation of the color.

      Parameters

      • withAlpha: boolean = false

        false (default): never the alpha; true: the alpha when the color is not opaque.

      Returns string

      The CSS color string (e.g. "rgb(255,0,0)" or "rgba(255,0,0,0.500)").