A comprehensive color library for JavaScript.
This release includes changes to how color strings are parsed, converted, and serialized, for better alignment to CSS specs:
[0, 1]
interval at parse-time.lab()
/ lch()
to [0, 100]
, in oklab()
/ oklch()
to [0, 1]
at parse-time.hsl()
and hwb()
syntaxes from [0, 1]
to [0, 100]
.0
in legacy syntaxes and as none
in modern syntaxes.0
for missing components in all color space conversions and gamut mapping functions.itp
;differenceItp()
.averageAngle()
always return in the [0, 360]
interval;luv
) conversion for l = 0
;const culori = require('culori')
(in addition to the previous culori/require
endpoint).clampChroma()
to change the destination RGB gamut (#212, #213)null
as the delta
color difference function (#212, #213)easingSmoothstepInverse()
function (re: #207)This release introduces new gamut-related functions:
inGamut(mode)
returns a function with which to check that a color is within the gamut of the mode
color space (#161); similar to displayable()
, but for any RGB-based color space.clampGamut(mode)
returns a function with which to clip a color to the gamut of the mode
color space; similar to clampRgb()
but for any RGB-based color space.toGamut(mode, ...)
returns a function to gamut-map a color to the mode
color space (#168); similar to clampChroma
but for any RGB-based color space.Fixes mapper()
function when mode = null
(See #194, thanks @bijela-gora!)
This new release includes revamped color parsing to align with the latest css-color-4
spec. Regular expression matching has been replaced with a parser that follows the css-syntax
spec more closely.
The new parser is more flexible with some aspects and stricter with others:
rgb(1-.2.3)
, are now properly handled (#187)<number>
, <percentage>
and 'none'
component valuescolor()
syntax no longer supports omitted component values that default to 0
; it now requires exactly three component values. (#186)Interpretation of component values has been aligned to the spec:
lch.c
(Chroma in the CIELCh color space) is [0, 150]
, with 100%
corresponding to 150
.Serialization has also been aligned to the spec:
lab
and lch
serialize the L
component as <number>
, not <percentage>
oklab
, oklch
and lrgb
are serialized to oklab()
, oklch()
, and color(srgb-linear)
respectively.Please consult the migration guide for assistance in upgrading from 2.x to 3.0.
parseRgb
and parseHsl
now perform parsing of the modern syntax for rgb()
and hsl()
respectively;parseRgbLegacy
and parseHslLegacy
have been added to parse the legacy syntaxes for rgb()
/ rgba()
/ hsl()
/ hsla()
parseOklab
and parseOklch
have been added to parse oklab()
and oklch()
.