Gleam - v1.0.2
    Preparing search index...

    Class Color

    RGBA color with chainable mutators. Channels are stored clamped (r/g/b[0, 255], alpha[0, 1]) — every mutator routes through set, so direct field writes aren't possible and clamping/rounding is uniform.

    Hue unit gotcha: fromHSL takes hue in degrees (CSS convention), but hueRotate takes radians (codebase convention). Use Math.PI etc. for hueRotate.

    All to* methods return CSS-compatible strings; toHSLObject returns the components as numbers if you need to mutate them.

    Index

    Constructors

    • Parameters

      • r: number
      • g: number
      • b: number
      • Optionala: number

      Returns Color

    Accessors

    • get alpha(): number

      Alpha channel, [0, 1]. Read-only; mutate via set (pass the fourth arg).

      Returns number

    • get b(): number

      Blue channel, [0, 255]. Read-only; mutate via set or any chainable transform.

      Returns number

    • get g(): number

      Green channel, [0, 255]. Read-only; mutate via set or any chainable transform.

      Returns number

    • get r(): number

      Red channel, [0, 255]. Read-only; mutate via set or any chainable transform.

      Returns number

    Methods

    • Apply a 3×3 RGB color matrix in row-major order (m1..m9). Alpha is unchanged. Used by grayscale, hueRotate, saturate, sepia. Mutates and returns this.

      Parameters

      • m1: number
      • m2: number
      • m3: number
      • m4: number
      • m5: number
      • m6: number
      • m7: number
      • m8: number
      • m9: number

      Returns this

    • Multiply each channel by factor. factor < 1 darkens, factor > 1 brightens (clamped at 255). Mutates and returns this.

      Parameters

      • factor: number

      Returns this

    • Push each channel away from 127.5 (the midtone) by factor. factor < 1 flattens contrast, > 1 increases it, 0 collapses every channel to gray. Mutates and returns this.

      Parameters

      • factor: number

      Returns this

    • Approximate equality (within approxEqual tolerance). Pass compareAlpha: false to ignore the alpha channel.

      Parameters

      • other: Color
      • compareAlpha: boolean = true

      Returns boolean

    • Desaturate via the standard luminance-preserving matrix. value in [0, 1]: 0 is a no-op, 1 is full grayscale. Mutates and returns this.

      Parameters

      • value: number = 1

      Returns this

    • Rotate hue by radians (use Math.PI / 2 etc.). Unlike fromHSL, this takes radians, not degrees. Mutates and returns this.

      Parameters

      • radians: number

      Returns this

    • Interpolate each channel toward its inverse (255 - c). factor in [0, 1]: 0 is unchanged, 1 is fully inverted. Mutates and returns this.

      Parameters

      • factor: number = 1

      Returns this

    • Linear blend toward other. amount in [0, 1]: 0 keeps this, 1 becomes other. Mixes alpha too. Mutates and returns this.

      Parameters

      • other: Color
      • amount: number

      Returns this

    • Round each RGB channel to the nearest integer. Alpha is untouched. Mutates and returns this.

      Returns this

    • Saturation matrix. value typically in [0, 2]: 0 desaturates to grayscale (same as grayscale(1)), 1 is a no-op, > 1 oversaturates. Mutates and returns this.

      Parameters

      • value: number = 1

      Returns this

    • Sepia matrix. value in [0, 1]: 0 is unchanged, 1 is full sepia. Mutates and returns this.

      Parameters

      • value: number = 1

      Returns this

    • Primary mutator — every other transform on this class routes through it. Clamps r/g/b to [0, 255] and a to [0, 1]; alpha is snapped to exact 0 or 1 when within approxEqual tolerance so equality checks stay clean. Returns this for chaining.

      Parameters

      • r: number
      • g: number
      • b: number
      • Optionala: number

      Returns this

    • Tint or shade. percent in [-1, 1]: negative shades toward black, positive tints toward white, magnitude is the amount. Mutates and returns this.

      Parameters

      • percent: number

      Returns this

    • CSS hex string. #rrggbb when alpha is exactly 1, #rrggbbaa otherwise. Channels are rounded.

      Returns string

    • CSS HSL string. hsl(h, s%, l%) when alpha is exactly 1, hsla(...) otherwise. Hue is in degrees.

      Returns string

    • CSS RGB string. rgb(r, g, b) when alpha is exactly 1, rgba(r, g, b, a) otherwise. Channels are rounded.

      Returns string

    • Parse #rgb, #rgba, #rrggbb, or #rrggbbaa (case-insensitive, # optional). Throws on any other shape or on non-hex characters.

      Parameters

      • hex: string

      Returns Color

    • Build from HSL(A). h in degrees (wraps mod 360), s/l in percent [0, 100], a in [0, 1]. The degree convention matches CSS — note that hueRotate uses radians instead.

      Parameters

      • h: number
      • s: number
      • l: number
      • a: number = 1

      Returns Color