Optionala: numberAlpha channel, [0, 1]. Read-only; mutate via set (pass the fourth arg).
Blue channel, [0, 255]. Read-only; mutate via set or any chainable transform.
Green channel, [0, 255]. Read-only; mutate via set or any chainable transform.
Red channel, [0, 255]. Read-only; mutate via set or any chainable transform.
Multiply each channel by factor. factor < 1 darkens, factor > 1 brightens (clamped at 255). Mutates and returns this.
New Color with the same channels.
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.
Approximate equality (within approxEqual tolerance). Pass compareAlpha: false to ignore the alpha channel.
Desaturate via the standard luminance-preserving matrix. value in [0, 1]: 0 is a no-op, 1 is full grayscale. Mutates and returns this.
Rotate hue by radians (use Math.PI / 2 etc.). Unlike fromHSL, this takes radians, not degrees. Mutates and 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.
Linear blend toward other. amount in [0, 1]: 0 keeps this, 1 becomes other. Mixes alpha too. Mutates and returns this.
Round each RGB channel to the nearest integer. Alpha is untouched. Mutates and 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.
Sepia matrix. value in [0, 1]: 0 is unchanged, 1 is full sepia. Mutates and 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.
Optionala: numberTint or shade. percent in [-1, 1]: negative shades toward black, positive tints toward white, magnitude is the amount. Mutates and returns this.
CSS hex string. #rrggbb when alpha is exactly 1, #rrggbbaa otherwise. Channels are rounded.
CSS HSL string. hsl(h, s%, l%) when alpha is exactly 1, hsla(...) otherwise. Hue is in degrees.
CSS RGB string. rgb(r, g, b) when alpha is exactly 1, rgba(r, g, b, a) otherwise. Channels are rounded.
StaticfromParse #rgb, #rgba, #rrggbb, or #rrggbbaa (case-insensitive, # optional). Throws on any other shape or on non-hex characters.
Staticfrom
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.PIetc. for hueRotate.All
to*methods return CSS-compatible strings;toHSLObjectreturns the components as numbers if you need to mutate them.