(c: number): number import {linear_component_to_srgb} from '@fuzdev/fuz_css/oklch.js'; Converts a linear-light sRGB component to gamma-encoded in [0, 1].
c
numberreturns
number OKLCH/OKLab ↔ sRGB conversions and gamut math.
Design-time and test use only — nothing here ships to browsers. The CSS
output of fuz_css stays pure oklch()/calc(); this module exists so
derivation scripts can fit curve knobs against real colors and so tests can
assert that every default stop is inside the sRGB gamut and meets the
contrast gates (see wcag.ts).
Matrices and constants follow css-color-4 and Björn Ottosson's reference implementation.
14 declarations
(c: number): number import {linear_component_to_srgb} from '@fuzdev/fuz_css/oklch.js'; Converts a linear-light sRGB component to gamma-encoded in [0, 1].
cnumbernumber Oklab import type {Oklab} from '@fuzdev/fuz_css/oklch.js'; A color in OKLab: lightness in [0, 1], a/b roughly in [-0.4, 0.4].
([lightness, a, b]: Oklab): Oklch import {oklab_to_oklch} from '@fuzdev/fuz_css/oklch.js'; Converts OKLab to OKLCH. Hue is normalized to [0, 360); an achromatic color gets hue 0.
__0Oklch ([lightness, a, b]: Oklab): RgbUnit import {oklab_to_srgb} from '@fuzdev/fuz_css/oklch.js'; Converts OKLab to gamma-encoded sRGB.
__0RgbUnit components that may fall outside [0, 1] when the color is out of gamut
Oklch import type {Oklch} from '@fuzdev/fuz_css/oklch.js'; A color in OKLCH: lightness in [0, 1], chroma ≥ 0 (unbounded), hue in degrees.
(a: Oklch, b: Oklch): number import {oklch_delta_e} from '@fuzdev/fuz_css/oklch.js'; Computes ΔEOK between two OKLCH colors — the Euclidean distance in OKLab. Just-noticeable differences sit around 0.02; css-color-4's gamut mapping uses 0.02 as its "local MINDE" threshold.
abnumber (lch: Oklch, epsilon?: number): boolean import {oklch_in_srgb_gamut} from '@fuzdev/fuz_css/oklch.js'; Checks whether an OKLCH color converts to sRGB with all components inside [0, 1].
lchepsilontolerance for float noise at the gamut boundary
number1e-6boolean (lightness: number, hue: number, precision?: number): number import {oklch_max_srgb_chroma} from '@fuzdev/fuz_css/oklch.js'; Finds the largest chroma at a given OKLCH lightness and hue such that every chroma below it is also inside the sRGB gamut. Returns 0 when the lightness itself is out of range.
This is deliberately the *safe* maximum for ramps, not the outermost gamut
intersection: the sRGB gamut is non-convex in OKLab (most visibly near the
blue primary), so the constant-(L, H) chroma ray can exit and re-enter the
gamut. A ramp needs the whole [0, C] segment representable, so the scan
stops at the first exit.
lightnessnumberhuenumberprecisionterminate when the refinement interval is smaller than this
number1e-5number ([lightness, chroma, hue]: Oklch): Oklab import {oklch_to_oklab} from '@fuzdev/fuz_css/oklch.js'; Converts OKLCH to OKLab.
__0Oklab (lch: Oklch): RgbUnit import {oklch_to_srgb} from '@fuzdev/fuz_css/oklch.js'; Converts OKLCH to gamma-encoded sRGB.
lchRgbUnit components that may fall outside [0, 1] when the color is out of gamut
RgbUnit import type {RgbUnit} from '@fuzdev/fuz_css/oklch.js'; An RGB color with components in the unit interval [0, 1]. Values are gamma-encoded sRGB unless a function documents linear-light. Out-of-gamut results are not clamped, so components may fall outside [0, 1].
(c: number): number import {srgb_component_to_linear} from '@fuzdev/fuz_css/oklch.js'; Converts a gamma-encoded sRGB component in [0, 1] to linear-light.
cnumbernumber ([r, g, b]: RgbUnit): Oklab import {srgb_to_oklab} from '@fuzdev/fuz_css/oklch.js'; Converts gamma-encoded sRGB to OKLab.
__0Oklab (rgb: RgbUnit): Oklch import {srgb_to_oklch} from '@fuzdev/fuz_css/oklch.js'; Converts gamma-encoded sRGB to OKLCH.
rgbOklch