/** * Colour maths for palette-legal editing. * * Pixel art lives or dies by palette discipline, and "nearest colour" in RGB * space is not the colour a human would pick — RGB distance weights green far * too heavily and ignores lightness. Everything here works in CIELAB with * CIE76 ΔE, which is close enough to perceptual for a ≤64-colour palette and * cheap enough to run per-pixel. */ export interface Rgb { r: number; g: number; b: number; a: number; } export interface Lab { l: number; a: number; b: number; } export declare function parseHex(hex: string): Rgb; export declare function toHex({ r, g, b, a }: Rgb, includeAlpha?: boolean): string; export declare function rgbToLab({ r, g, b }: Rgb): Lab; /** CIE76 ΔE. Values below ~2.3 are indistinguishable to most viewers. */ export declare function deltaE(a: Lab, b: Lab): number; export interface SnapResult { index: number; hex: string; distance: number; } /** * Nearest palette entry to `colour`, by ΔE. * * A fully transparent input snaps to itself: a palette has no entry for * "nothing", and picking the nearest opaque colour for it would paint over * holes the artist left on purpose. */ export declare function snapToPalette(colour: Rgb, palette: readonly string[]): SnapResult; export interface HueShiftOptions { /** Positive lightens, negative darkens. Roughly one ramp step per 0.15. */ amount: number; /** Degrees of hue rotation applied at full amount. */ hueShiftDegrees?: number; } /** Rotate `h` toward `target` along the shorter arc, by at most `degrees`. */ export declare function rotateHueToward(h: number, target: number, degrees: number): number; /** * Shade a colour the way a pixel artist does, not the way a brightness slider * does: shadows rotate toward blue and desaturate slightly, highlights rotate * toward yellow and saturate. Flat luminance ramps are the single most common * tell of machine-made pixel art. * * The rotation goes toward a target hue, not a fixed direction round the * wheel: a fixed "+N° for shadows" sends red shadows toward orange and yellow, * which is the opposite of what a red ramp needs. */ export declare function hueShiftShade(colour: Rgb, opts: HueShiftOptions): Rgb; export interface Hsl { h: number; s: number; l: number; } export declare function rgbToHsl({ r, g, b }: Rgb): Hsl; export declare function hslToRgb({ h, s, l }: Hsl): Omit; /** * Build a hue-shifted ramp of `steps` colours around a base colour. * The base sits at the ramp's midpoint so callers get equal shadow and light. */ export declare function buildRamp(base: Rgb, steps: number, spread?: number): string[]; /** Perceptual luminance, used by contrast and readability checks. */ export declare function luminance({ r, g, b }: Rgb): number; export declare function contrastRatio(a: Rgb, b: Rgb): number;