Tanguv0.35.0
CLI, terminal & markup25 exports
Raw Markdown

/color

Color space conversions (hex, RGB, HSL, OKLCH), WCAG contrast ratios, and tonal palette operations.

(use /color)

Structs#

HSL#

struct

Cylindrical HSL color space: - h: hue angle in degrees (0.0..360.0) - s: saturation (0.0..1.0) - l: lightness (0.0..1.0) - a: alpha (0.0..1.0, default 1.0)

FieldTypeDefaultConstraints / Notes
hFloat——
sFloat——
lFloat——
aFloat——

Oklch#

struct

Perceptual Oklch color space: - l: perceived lightness (0.0..1.0) - c: chroma (0.0..~0.4) - h: hue angle in degrees (0.0..360.0) - a: alpha (0.0..1.0, default 1.0)

FieldTypeDefaultConstraints / Notes
lFloat——
cFloat——
hFloat——
aFloat——

RGB#

struct

3-channel linear or sRGB color (0.0..1.0). Derives `Eq` and `Vec` for full Euclidean vector arithmetic (`+`, `-`, `*`, `/`, `cmul`, `lerp`, `dot`).

FieldTypeDefaultConstraints / Notes
rFloat——
gFloat——
bFloat——

RGBA#

struct

4-channel sRGB color with alpha (0.0..1.0, default alpha 1.0).

FieldTypeDefaultConstraints / Notes
rFloat——
gFloat——
bFloat——
aFloat——

Functions & symbols#

contrast-ratio#

function
(contrast-ratio fg bg) -> Float

Computes the WCAG 2.1 contrast ratio (`1.0` to `21.0`) between two colors.

ParameterTypeOptionalDescription
fgAnyrequiredForeground color
bgAnyrequiredBackground color
Returns:Any
(color/contrast-ratio "#000000" "#ffffff") ; -> 21.0

darken#

function
(darken color amount) -> Oklch

Decreases perceptual Oklch lightness `l` by `amount`.

ParameterTypeOptionalDescription
colorAnyrequiredBase color
amountFloatrequiredLightness delta in Oklch (0.0..1.0)
Returns:Any
(color/darken "#3b82f6" 0.12)

desaturate#

function
(desaturate color amount) -> Oklch

Decreases Oklch chroma `c` toward neutral gray.

ParameterTypeOptionalDescription
colorAnyrequiredBase color
amountFloatrequiredChroma decrease
Returns:Any
(color/desaturate "#3b82f6" 0.05)

invert#

function
(invert color) -> RGBA

Inverts the RGB channels (`1.0 - c`) while keeping alpha unchanged.

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/invert "#000000")

lighten#

function
(lighten color amount) -> Oklch

Increases perceptual Oklch lightness `l` by `amount`.

ParameterTypeOptionalDescription
colorAnyrequiredBase color
amountFloatrequiredLightness delta in Oklch (0.0..1.0)
Returns:Any
(color/lighten "#3b82f6" 0.12)

linear-to-srgb#

function
(linear-to-srgb c) -> Float | RGB

Encodes linear-light channel(s) into sRGB gamma.

ParameterTypeOptionalDescription
valueFloat | RGB | RGBArequiredLinear-light channel or color
Returns:Any
(color/linear-to-srgb 0.214)

luminance#

function
(luminance color) -> Float

Computes WCAG relative luminance (`0.0` black to `1.0` white).

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/luminance "#ffffff") ; -> 1.0

mix#

function
(mix c1 c2 [t]) -> Oklch

Perceptually interpolates between `c1` and `c2` in Oklch space.

ParameterTypeOptionalDescription
c1AnyrequiredFirst color
c2AnyrequiredSecond color
tFloatoptionalInterpolation factor 0.0..1.0 (default 0.5)
Returns:Any
(color/mix "#3b82f6" "#ec4899" 0.5)

parse#

function
(parse input) -> RGBA

Parses any CSS color string, integer, or color struct into normalized `RGBA` (`0.0..1.0`).

ParameterTypeOptionalDescription
inputString | Int | RGB | RGBA | Oklch | HSLrequiredCSS hex/rgb()/oklch() string, packed int, or color struct
Returns:Any
(color/parse "#3b82f6")

rotate-hue#

function
(rotate-hue color degrees) -> Oklch

Shifts the Oklch hue angle by `degrees` (modulo 360).

ParameterTypeOptionalDescription
colorAnyrequiredBase color
degreesFloatrequiredHue rotation in degrees
Returns:Any
(color/rotate-hue "#3b82f6" 180.0)

saturate#

function
(saturate color amount) -> Oklch

Increases Oklch chroma `c` for a more vivid color.

ParameterTypeOptionalDescription
colorAnyrequiredBase color
amountFloatrequiredChroma increase
Returns:Any
(color/saturate "#3b82f6" 0.05)

srgb-to-linear#

function
(srgb-to-linear c) -> Float | RGB

Decodes gamma-encoded sRGB channel(s) into linear light.

ParameterTypeOptionalDescription
valueFloat | RGB | RGBArequiredsRGB channel or color
Returns:Any
(color/srgb-to-linear 0.5)

to-css#

function
(to-css color [format]) -> String

Serializes a color into a standard CSS color function or hex string.

ParameterTypeOptionalDescription
colorAnyrequiredColor value
formatKeySymboloptionalOptional output syntax (:rgb, :hsl, :oklch, :hex)
Returns:Any
(color/to-css (color/Oklch 0.7 0.15 240.0) :oklch)

to-hex#

function
(to-hex color [include-alpha]) -> String

Formats a color as a CSS hex string (`#rrggbb` or `#rrggbbaa`).

ParameterTypeOptionalDescription
colorAnyrequiredColor value
include_alphaBooloptionalInclude alpha channel as #RRGGBBAA
Returns:Any
(color/to-hex (color/RGB 1.0 0.0 0.0)) ; -> "#ff0000"

to-hsl#

function
(to-hsl color) -> HSL

Converts any color value into cylindrical `HSL` (`h`, `s`, `l`, `a`).

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/to-hsl "#10b981")

to-int#

function
(to-int color) -> Int

Packs an RGB(A) color into a 32-bit `0xRRGGBBAA` or `0xAARRGGBB` integer.

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/to-int "#ffffff")

to-oklch#

function
(to-oklch color) -> Oklch

Converts any color value into perceptual Oklch (`l`, `c`, `h`, `a`).

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/to-oklch (color/RGB 0.2 0.4 0.9))

to-rgb#

function
(to-rgb color) -> RGB

Converts any color value to 3-channel `RGB`.

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/to-rgb "#ff0000")

to-rgba#

function
(to-rgba color) -> RGBA

Converts any color value to 4-channel `RGBA`.

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/to-rgba "#ff000080")

to-u8#

function
(to-u8 color) -> Array

Converts `RGBA` floating channels (`0.0..1.0`) into `[r g b a]` bytes (`0..255`).

ParameterTypeOptionalDescription
colorRGB | RGBA | Oklch | HSL | String | IntrequiredInput color struct, CSS color string, or 0xRRGGBB integer
Returns:Any
(color/to-u8 (color/RGBA 1.0 0.5 0.0 1.0))

with-alpha#

function
(with-alpha color alpha) -> RGBA

Returns a copy of `color` with its alpha channel set to `alpha`.

ParameterTypeOptionalDescription
colorAnyrequiredBase color
alphaFloatrequiredAlpha channel 0.0..1.0
Returns:Any
(color/with-alpha "#000000" 0.4)