UNPKG

@nvl/egal

Version:

Reparametrization of OkLCh/HCT to simplify uniformity in color saturation.

185 lines (184 loc) 6.67 kB
import type { FindChromaOptions, EgalOptions, OutputColor, OutputFormat, ColorSpace } from './types.js'; export declare const ColorSpaceConstants: { /** * Globals set by HCT; do not modify unless changes to the HCT color system * are made. */ readonly hct: { readonly hue: { readonly min: 0; readonly max: 360; }; readonly chroma: { readonly min: 0; readonly max: 200; }; readonly lightness: { readonly min: 0; readonly max: 100; }; readonly bgLstar: { readonly min: 0; readonly max: 100; }; readonly props: { readonly hueProp: "h"; readonly chromaProp: "c"; readonly lightnessProp: "t"; }; }; /** * Globals set by OkLCh; do not modify unless changes to the OkLCh color * system are made. */ readonly oklch: { readonly hue: { readonly min: 0; readonly max: 360; }; readonly chroma: { readonly min: 0; readonly max: 1; }; readonly lightness: { readonly min: 0; readonly max: 1; }; readonly props: { readonly hueProp: "h"; readonly chromaProp: "c"; readonly lightnessProp: "l"; }; }; }; export declare const defaults: { readonly hueStep: 1; readonly gamut: "srgb"; readonly space: "oklch"; readonly precision: { readonly oklch: 0.00001; readonly hct: 0.01; }; }; /** * Given a specific hue and lightness, returns the maximum chroma that a color * with those hue and lightness values can have while still remaining * displayable in the specified color gamut (by default, `'srgb'`). * * @param hue - The hue of the color, in degrees. Must be between 0 and 360. * @param lightness - The lightness of the color. Must be between 0 and 100. * @param opts - Options for calculating the maximum chroma. * @returns The maximum chroma that a color with the specified hue and lightness * can have in the specified viewing conditions. */ export declare function findMaxChroma(hue: number, lightness: number, opts: Required<FindChromaOptions>): number; /** * Given a specific lightness, returns the maximum chroma that *all* colors with * that lightness can have across the specified hues. * * @param lightness - The lightness for which to find the "chroma floor". Must * be between 0 and 100, both inclusive. * @param opts - Options for the calculation the chroma floor. * @returns The chroma floor, i.e., the minimum of the maximum chromas for each * hue-lightness pair. */ export declare function findChromaFloorForLightness(lightness: number, opts: Required<FindChromaOptions & Pick<EgalOptions<OutputFormat>, 'hues'>>): number; export declare const defaultOptions: { readonly hues: 1; readonly output: "oklch"; readonly opacity: 1; readonly guardrails: true; readonly toeFunction: undefined; }; /** * * @param lightness - The lightness of the color. Must be between 0 and 100. A * lightness of 0 will always result in black (`rgb(0%, 0%, 0%)` or equivalent), * and a lightness of 100 will always result in white (`rgb(100%, 100%, 100%)` * or equivalent). * @param chroma - The chroma of the color. Must be a nonnegative number. Values * are interpreted as percentages of the maximal chroma _such that the chroma * can be maintained across the specified hues_. A chroma of 0 will result in a * grayscale color. * @param hue - The hue of the color, in degrees. Must be between 0 and 360. * @param options - Options for the calculation. * @returns A string representing the color in the specified output format, such * that the color obeys CSS syntax and remains within the specified color gamut. */ export declare function egal<OF extends OutputFormat = OutputFormat>(lightness: number, chroma: number, hue: number, options?: EgalOptions<OF>): OutputColor<OF>; /** * - **PRE:** `h ∈ ℝ ∪ {-∞, ∞, NaN}` * - **POST:** If `h` is finite, then `output ∈ [0, 360)` and * `output ≡ h mod 360`. If `h` is not finite, then `output = 0`. */ export declare function sanitizeHue(h: number): number; /** * - **PRE:** `value, min, max ∈ ℝ ∪ {-∞, ∞}` and `min ≤ max` * - **POST:** `output ∈ [min, max]`, with `output` being the closest value to * `value` within the range `[min, max]`. */ export declare function ensureInRange(value: number, min: number, max: number): number; /** * Thresholds for options and input values to use in the sanitization processes. */ export declare const Thresholds: { readonly precision: { readonly oklch: { readonly min: 0.00001; readonly max: 0.05; }; readonly hct: { readonly min: 0.001; readonly max: 5; }; }; readonly hues: { readonly min: 1; }; readonly chroma: { readonly max: 1000000; }; readonly lightness: { readonly max: 100; }; }; /** * - **PRE:** `p ∈ ℝ ∪ {-∞, ∞, NaN}`, `space ∈ {'oklch', 'hct'}` * - **POST:** `output ∈ [Thresholds.precision[space].min, Thresholds.precision[space].max]` * * @param p - The precision to sanitize. * @returns The sanitized precision. */ export declare function sanitizePrecision(p: number, space: ColorSpace): number; /** * - **PRE:** `h ∈ [0, 360)` * - **POST:** `output ∈ [Thresholds.hues.min, 360)` * * @param h - The hue step value to sanitize. * @returns The sanitized hue step value. */ export declare function sanitizeHues(h: number): number; /** * - **PRE:** `c ∈ ℝ ∪ {-∞, ∞, NaN}` * - **POST:** `output ∈ [0, Thresholds.chroma.max]` * * @param c - The chroma to sanitize. * @returns The sanitized chroma. */ export declare function sanitizeChroma(c: number): number; /** * - **PRE:** `l ∈ ℝ ∪ {-∞, ∞, NaN}` * - **POST:** `output ∈ [0, Thresholds.lightness.max]` * * @param l - The lightness to sanitize. * @param toeFn - Whether a toe function was applied to get `l`. * @param lBeforeToeFn - If `toeFn` is `true`, this is the lightness before the * toe function was applied. If `toeFn` is `false`, this is just `l`. * @returns The sanitized lightness. * * @remarks * The `toeFn` and `lBeforeToeFn` parameters are used to provide more * informative warning messages, but they are not otherwise used in the * sanitization process. */ export declare function sanitizeLightness(l: number, toeFn: boolean, lBeforeToeFn: number): number;