Skip to main content

parseColour

Parses a hex, rgb()/rgba() or oklch() colour to gamma-encoded sRGB. Numbers and percentages are read strictly: each component must be a finite number or percentage, the argument count must be right, and an oklch() hue may be plain or in degrees (other angle units are refused). Components outside their range are clamped as CSS does. OKLCH colours that fall outside the gamut are clipped per channel; use isInSrgbGamut to keep tokens from relying on that.

This is a function exported by @mapcairn/theme, checked against version 0.2.0.

Signature​

import { parseColour } from "@mapcairn/theme";

function parseColour(colour: string): Rgba;

Parameters​

  • colour (string)

Returns​

Rgba

Throws​

  • When the string is not in a supported syntax.

See also​

Source: packages/theme/src/contrast.ts:253