asamuzaK / cssColor

Resolve, parse, convert CSS color.
MIT License
1 stars 0 forks source link

CSS color

build CodeQL npm (scoped)

Resolve and convert CSS colors.

Install

npm i @asamuzakjp/css-color

Usage

import { convert, resolve } from '@asamuzakjp/css-color';

const resolvedValue =
  resolve('color-mix(in oklab, rgb(255 0 0), color(srgb 0 0.5 0 / 0.5))');
// 'oklab(0.5914 0.103273 0.119688 / 0.75)'

const convertedValue = covert.colorToHex('lab(46.2775% -47.5621 48.5837)');
// '#008000'

resolve(color, opt)

resolves CSS color

Parameters

Returns (string? | Array) returns one of rgba?(), color(space r g b / a), color(space x y z / a), lab(l a b / A), lch(l c h / a), oklab(l a b / A), oklch(l c h / a), \#rrggbb(aa)?, color-name?, null, and, if key is specified, [key, rgba?()] etc.

convert

Contains various color conversion functions.

convert.numberToHex(value)

convert number to hex string

Parameters

Returns string hex string: 00..ff

convert.colorToHex(value, opt)

convert color to hex

Parameters

Returns string #rrggbb|#rrggbbaa

convert.colorToHsl(value)

convert color to hsl

Parameters

Returns Array<number> [h, s, l, a]

convert.colorToHwb(value)

convert color to hwb

Parameters

Returns Array<number> [h, w, b, a]

convert.colorToLab(value)

convert color to lab

Parameters

Returns Array<number> [l, a, b, aa]

convert.colorToLch(value)

convert color to lch

Parameters

Returns Array<number> [l, c, h, aa]

convert.colorToOklab(value)

convert color to oklab

Parameters

Returns Array<number> [l, a, b, aa]

convert.colorToOklch(value)

convert color to oklch

Parameters

Returns Array<number> [l, c, h, aa]

convert.colorToRgb(value)

convert color to rgb

Parameters

Returns Array<number> [r, g, b, a]

convert.colorToXyz(value, opt)

convert color to xyz

Parameters

Returns Array<number> [x, y, z, a]

convert.colorToXyzD50(value)

convert color to xyz-d50

Parameters

Returns Array<number> [x, y, z, a]


Copyright (c) 2024 asamuzaK (Kazz)