Skip to content

rec2020 ​

Rec. 2020 wide gamut color space support. Rec. 2020 is a color space standard defined for UHD/4K/8K television and HDR content.

Inputs are converted to sRGB and clipped to its gamut. Values outside sRGB lose information during a round trip.

Install ​

ts
import xcolor from '@xpyjs/color'
import rec2020Plugin from '@xpyjs/color/plugins/rec2020'

xcolor.use(rec2020Plugin)

Methods ​

toRec2020() ​

Returns a Rec. 2020 object. Each channel value ranges from 0–1.

ts
xcolor('#ff0000').toRec2020()
// { r: 0.792, g: 0.231, b: 0.0738 }

toRec2020String() ​

Returns a color(rec2020 ...) format string.

ts
xcolor('#ff0000').toRec2020String()
// 'color(rec2020 0.792 0.231 0.0738)'

Input Parsing ​

ts
xcolor('color(rec2020 0.79 0.23 0.07)').toHex()

Formatting ​

ts
xcolor('#ff0000').toString('rec2020')  // 'color(rec2020 0.792 0.231 0.0738)'

Preserve the original coordinates ​

Use the plugin's named exports for a wide-gamut value that stays in its original space. parseWideColor(input) returns { space, coordinates, alpha } or null. formatWideColor(record) serializes those coordinates, and toSrgb(record) explicitly converts and clips them. Calling these functions needs no plugin registration.

Released under the MIT License.