color-delta-e
Version:
   • 3.06 kB
TypeScript
/**
* RGB representation of a color
**/
declare type ColorTuple = [number, number, number];
declare type RGBColorTuple = [number, number, number];
declare type LABColorTuple = [number, number, number];
declare type deltaValueType = 'rgb' | 'hex' | 'hsl' | 'lab';
declare type InputTupleTypes = 'rgb' | 'hsl' | 'lab';
declare function contrastText(color: ColorTuple, type: InputTupleTypes): ColorTuple;
declare function contrastText(color: string, type?: undefined): string;
/**
* manually clear the internal cache.
*/
declare function clearCache(): void;
/**
* takes two colors and measure of change in visual perception of the two given colors, returns delta-e value 0 - 100+
*
* more on delta-e: http://zschuessler.github.io/DeltaE/learn/
*/
declare function deltaE(color1: ColorTuple, color2: string, type: Exclude<deltaValueType, 'hex'>, nocache?: boolean): number;
declare function deltaE(color1: string, color2: ColorTuple, type: Exclude<deltaValueType, 'hex'>, nocache?: boolean): number;
declare function deltaE(color1: ColorTuple, color2: ColorTuple, type: Exclude<deltaValueType, 'hex'>, nocache?: boolean): number;
declare function deltaE(color1: string, color2: string, type?: Exclude<deltaValueType, 'hex'>, nocache?: boolean): number;
/**
* checks if `first` would be noticebly different to the naked eye to `second`
* returns true if they contrast enough,
* threshold can be modified by `0 - 100` `(default = 5)`, to change how much difference the colors need to be
* nocache can be used to disable caching for color calculations
*/
interface IsPerceivableOptions {
threshold?: number;
type?: InputTupleTypes;
nocache?: boolean;
}
declare function isPerceivable(first: ColorTuple, second: ColorTuple, options?: IsPerceivableOptions): boolean;
declare function isPerceivable(first: string, second: string, options?: IsPerceivableOptions): boolean;
/**
* gets the average color within an image, does not support crossOrigin images set img element crossOrigin to `crossOrigin=""`
*/
declare function sampleImage(imgEl: HTMLImageElement): [number, number, number];
interface SelectorOptions {
compare: ColorTuple | string;
type?: InputTupleTypes;
threshold?: number;
}
/**
* provide a base color to compare and a contrast threshold, selector will go through each
* fallback contrast color and will pick the first fallback thats contrast meets the threshold
* if none meet contrast ratio selector will return the last fallback supplied
*/
declare function selector(options: SelectorOptions, ...fallbacks: Array<ColorTuple | string>): ColorTuple | string;
/**
* converts a RGBColorTuple to rgb string e.g `rgb(0,0,0)`
*/
declare function toRBGString([r, g, b]: RGBColorTuple): string;
/**
* converts a RGBColorTuple to hsl string e.g `hsl(0,0,0)`
*/
declare function toHSLString([h, s, l]: RGBColorTuple): string;
export { ColorTuple, InputTupleTypes, LABColorTuple, RGBColorTuple, clearCache, contrastText, deltaE, deltaValueType, isPerceivable, sampleImage, selector, toHSLString, toRBGString };