@versatiles/style
    Preparing search index...

    Interface RGB

    Represents an RGB color with optional alpha transparency.

    interface RGB {
        a: number;
        b: number;
        g: number;
        r: number;
        asArray(): [number, number, number, number];
        asHex(): string;
        asHSL(): HSL;
        asHSV(): HSV;
        asRGB(): RGB;
        asString(): string;
        blend(value: number, blendColor: Color): RGB;
        brightness(value: number): RGB;
        clone(): RGB;
        contrast(value: number): RGB;
        darken(ratio: number): RGB;
        fade(value: number): RGB;
        gamma(value: number): RGB;
        invert(): RGB;
        invertLuminosity(): HSL;
        lighten(ratio: number): RGB;
        rotateHue(offset: number): HSL;
        round(): RGB;
        saturate(ratio: number): HSL;
        setHue(value: number): HSV;
        tint(value: number, tintColor: Color): RGB;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Returns the RGB color as an array.

      Returns [number, number, number, number]

      An array containing the red, green, blue, and alpha components.

    • Returns the RGB color as a hexadecimal string.

      Returns string

      A string representation of the RGB color in hexadecimal format.

    • Returns the RGB color as a string.

      Returns string

      A string representation of the RGB color in either rgb or rgba format.

    • Linearly interpolates between this color and blendColor in RGB space.

      Parameters

      • value: number

        Blend ratio. Clamped to [0, 1] (null/undefined treated as 0). 0 returns this color; 1 returns blendColor.

      • blendColor: Color

        Target color to blend toward.

      Returns RGB

      A new RGB color, blended.

    • Linearly shifts each channel toward black (negative value) or white (positive value).

      Parameters

      • value: number

        Brightness shift. Clamped to [-1, 1]. 0 is identity; -1 yields pure black; +1 yields pure white.

      Returns RGB

      A new RGB color with adjusted brightness.

    • Scales each channel around the midpoint 127.5: c → (c − 127.5) · value + 127.5, clamped to [0, 255].

      Parameters

      • value: number

        Contrast multiplier. Clamped to [0, 1e6]. 1 is identity; 0 collapses the color to mid-gray (#808080); values >1 increase contrast; very large values push each channel to 0 or 255.

      Returns RGB

      A new RGB color with adjusted contrast.

    • Multiplies each channel by (1 − ratio). Mathematically equivalent to blend(ratio, black).

      Note: this operation is theme-absolute — under luminosity inversion it still moves toward black. For inversion-safe rules use blend(ratio, fg) where fg is your style's foreground/contrast reference.

      Parameters

      • ratio: number

        Darkening ratio. Range: [0, 1] (per-channel result is clamped to [0, 255]). 0 is identity; 1 yields pure black.

      Returns RGB

      A new RGB color, darkened.

    • Reduces the alpha proportionally: a → a · (1 − value).

      Parameters

      • value: number

        Fade amount. Range: [0, 1]. 0 is identity; 1 yields fully transparent.

      Returns RGB

      A new RGB color with reduced alpha.

    • Applies a per-channel gamma correction: c → 255 · (c/255)^value.

      Parameters

      • value: number

        Gamma exponent. Clamped to [1e-3, 1e3]. 1 is identity; <1 brightens midtones; >1 darkens midtones.

      Returns RGB

      A new RGB color with gamma correction applied.

    • Inverts each RGB channel: c → 255 − c. The hue is also flipped. For a hue-preserving "dark mode" inversion, use invertLuminosity instead.

      Returns RGB

      A new RGB color with all channels inverted.

    • Returns a new color with the HSL lightness flipped (L → 100 − L). Hue and saturation are preserved, so a light cream becomes a dark cream of the same hue. Useful for deriving a dark-theme palette from a light-theme palette.

      Returns HSL

      A new HSL color with the lightness inverted.

    • Blends each channel toward white. Mathematically equivalent to blend(ratio, white).

      Note: this operation is theme-absolute — under luminosity inversion it still moves toward white. For inversion-safe rules use blend(ratio, bg) where bg is your style's background reference.

      Parameters

      • ratio: number

        Lightening ratio. Range: [0, 1] (per-channel result is clamped to [0, 255]). 0 is identity; 1 yields pure white.

      Returns RGB

      A new RGB color, lightened.

    • Rotates the hue around the color wheel.

      Parameters

      • offset: number

        Rotation in degrees. Any number is accepted and reduced modulo 360. 0 leaves the hue unchanged; 180 yields the complementary hue.

      Returns HSL

      A new HSL color with the rotated hue.

    • Rounds the RGB color components to the nearest integer.

      Returns RGB

      A new RGB instance with rounded color values.

    • Scales the HSL saturation by (1 + ratio), then clamps to [0, 100].

      Parameters

      • ratio: number

        Saturation change ratio. Range: [-1, ∞). -1 fully desaturates (gray); 0 is identity; 1 doubles saturation; values that would push S past 100 are clamped.

      Returns HSL

      A new HSL color with adjusted saturation.

    • Replaces the hue, preserving saturation and value.

      Parameters

      • value: number

        Hue in degrees. Any number; reduced modulo 360.

      Returns HSV

      A new HSV color with the new hue.

    • Shifts the hue toward tintColor's hue, blending in RGB space. Internally: derives a version of this color carrying tintColor's hue, then linearly interpolates between this and that variant by value.

      Parameters

      • value: number

        Tint amount. Clamped to [0, 1]. 0 is identity; 1 yields this color's luminosity/saturation but with tintColor's hue.

      • tintColor: Color

        Color whose hue is used for tinting; only its hue matters.

      Returns RGB

      A new RGB color, tinted.

    Properties

    a: number

    Alpha component (0-1).

    b: number

    Blue component (0-255).

    g: number

    Green component (0-255).

    r: number

    Red component (0-255).