allc
Version:
A small typescript package for color conversion.
45 lines (44 loc) • 1.99 kB
JavaScript
/**
* Calculates the CSS representation of the given Oklab color.
*
* @param l The luminance component of Oklab, range [0, 1].
* @param a The a component of Oklab, unbounded.
* @param b The b component of Oklab, unbounded.
* @param withAlpha The alpha component of the color, range [0, 1], defaults to 1.
*
* @returns The CSS representation of the color.
*/
export const toCSSFromOklab = (l, a, b, withAlpha) => `oklab(${l} ${a} ${b}${withAlpha !== undefined ? `/${withAlpha}` : ""})`;
/**
* Calculates the CSS representation of the given CIELAB color.
*
* @param l The luminance component of CIELAB, range [0, 1].
* @param a The a component of CIELAB, unbounded.
* @param b The b component of CIELAB, unbounded.
* @param withAlpha The alpha component of the color, range [0, 1], defaults to 1.
*
* @returns The CSS representation of the color.
*/
export const toCSSFromCIELAB = (l, a, b, withAlpha) => `lab(${l} ${a} ${b}${withAlpha !== undefined ? `/${withAlpha}` : ""})`;
/**
* Calculates the CSS representation of the given Oklch color.
*
* @param l The luminance component of Oklch, range [0, 1].
* @param c The a component of Oklch, unbounded.
* @param h The b component of Oklch, unbounded.
* @param withAlpha The alpha component of the color, range [0, 1], defaults to 1.
*
* @returns The CSS representation of the color.
*/
export const toCSSFromOklch = (l, c, h, withAlpha) => `oklch(${l} ${c} ${h}${withAlpha !== undefined ? `/${withAlpha}` : ""})`;
/**
* Calculates the CSS representation of the given CIELCH color.
*
* @param l The luminance component of CIELCH, range [0, 1].
* @param c The a component of CIELCH, unbounded.
* @param h The b component of CIELCH, unbounded.
* @param withAlpha The alpha component of the color, range [0, 1], defaults to 1.
*
* @returns The CSS representation of the color.
*/
export const toCSSFromCIELCH = (l, c, h, withAlpha) => `lch(${l} ${c} ${h}${withAlpha !== undefined ? `/${withAlpha}` : ""})`;