@thi.ng/color
Version:
Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets
65 lines • 2.19 kB
TypeScript
import type { IDeref } from "@thi.ng/api";
import { type IParsedColor } from "../api.js";
/**
* Attempts to parse given CSS color into an interim {@link ParsedColor} type
* with {@link srgb}, {@link hsl}, {@link labD50} or {@link lch} color modes.
* Throws an error if any of the validations during parsing failed.
*
* @remarks
* The following syntax versions are supported:
*
* - CSS named colors
* - CSS system colors, see {@link CSS_SYSTEM_COLORS}
* - hex3/4/6/8
* - `rgb(r% g% b% / a%?)`
* - `rgb(r g b / a?)`
* - `rgb(r,g,b)`
* - `rgba(r,g,b,a)`
* - `hsl(h s% l% / a%?)`
* - `hsl(h,s%,l%)`
* - `hsla(h,s%,l%,a)`
* - `lab(l a b / alpha?)`
* - `lab(l% a% b% / alpha?)`
* - `lch(l c h / alpha?)`
* - `lch(l% c% h / alpha?)`
* - `oklab(l a b / alpha?)`
* - `oklab(l% a% b% / alpha?)`
* - `oklch(l c h / alpha?)`
* - `oklch(l% c% h / alpha?)`
*
* Hue values can be given according to CSS Color L4 spec (raw, deg, rad, grad,
* turn): https://www.w3.org/TR/css-color-4/#typedef-hue
*
* For (ok)lab/(ok)lch color channel values given as percentages, the scale
* ranges defined in the spec are used:
* https://www.w3.org/TR/css-color-4/#specifying-lab-lch
*
* If no alpha channel is given, it will default to 1.0 (fully opaque).
*
* Note that any named or system CSS colors, hex colors and any RGB colors will
* be returned as sRGB instance. In former versions of this library (pre 3.0.0),
* there was only a single RGB type with undefined behaviour re: linear or
* gamma-encoded versions. Since v3.0.0, {@link rgb} is only used for _linear_
* and {@link srgb} for non-linear (gamma encoded) RGB colors (CSS uses sRGB by
* default).
*
* @param src -
*/
export declare const parseCss: (src: string | IDeref<string>) => IParsedColor;
/**
* Parses a CSS hex color string into an uint32. Throws an error if given string
* doesn't conform to any of the supported formats.
*
* @remarks
* Supports the following input formats (`#` always optional and each letter a
* hex digit):
*
* - `#rgb`
* - `#rgba`
* - `#rrggbb`
* - `#rrggbbaa`
*
* @param src
*/
export declare const parseHex: (src: string) => number;
//# sourceMappingURL=parse-css.d.ts.map