Skip to main content

mix

Mixes two colors together.
a
Color
required
The first color
b
Color
required
The second color
weight
number
default:"0.5"
The weight of the first color in the range [0, 1]
return
Color
The mixed color

Example

import { fromRgb, mix } from "@temelj/color";

const red = fromRgb(255, 0, 0);
const blue = fromRgb(0, 0, 255);

// 50/50 mix
const purple = mix(red, blue);
console.log(purple); // { red: 127.5, green: 0, blue: 127.5 }

// 75% red, 25% blue
const reddish = mix(red, blue, 0.75);
console.log(reddish); // { red: 191.25, green: 0, blue: 63.75 }

lighten

Lightens a color by increasing its lightness.
color
Color
required
The color to lighten
amount
number
required
The amount to lighten by in the range [0, 1]
return
Color
The lightened color

Example

import { fromRgb, lighten } from "@temelj/color";

const blue = fromRgb(0, 0, 200);
const lightBlue = lighten(blue, 0.2);

console.log(lightBlue);
// Color is 20% lighter

darken

Darkens a color by decreasing its lightness.
color
Color
required
The color to darken
amount
number
required
The amount to darken by in the range [0, 1]
return
Color
The darkened color

Example

import { fromRgb, darken } from "@temelj/color";

const yellow = fromRgb(255, 255, 0);
const darkYellow = darken(yellow, 0.3);

console.log(darkYellow);
// Color is 30% darker

saturate

Saturates a color by increasing its saturation.
color
Color
required
The color to saturate
amount
number
required
The amount to saturate by in the range [0, 1]
return
Color
The saturated color

Example

import { fromRgb, saturate } from "@temelj/color";

const paleBlue = fromRgb(150, 180, 200);
const vibrantBlue = saturate(paleBlue, 0.4);

console.log(vibrantBlue);
// Color is more vibrant/saturated

desaturate

Desaturates a color by decreasing its saturation.
color
Color
required
The color to desaturate
amount
number
required
The amount to desaturate by in the range [0, 1]
return
Color
The desaturated color

Example

import { fromRgb, desaturate } from "@temelj/color";

const vibrantRed = fromRgb(255, 0, 0);
const mutedRed = desaturate(vibrantRed, 0.5);

console.log(mutedRed);
// Color is more muted/less saturated

grayscale

Converts a color to grayscale by removing all saturation.
color
Color
required
The color to convert to grayscale
return
Color
The grayscale color

Example

import { fromRgb, grayscale } from "@temelj/color";

const red = fromRgb(255, 0, 0);
const gray = grayscale(red);

console.log(gray);
// Color has no saturation, only lightness remains

// Useful for accessibility testing or print previews
const colors = [
  fromRgb(255, 0, 0),
  fromRgb(0, 255, 0),
  fromRgb(0, 0, 255),
];

const grayPalette = colors.map(grayscale);
console.log(grayPalette);

Build docs developers (and LLMs) love