UNPKG

colortranslator

Version:

A JavaScript library, written in TypeScript, to convert among different color models

320 lines (316 loc) 12.3 kB
declare enum Harmony { ANALOGOUS = "ANALOGOUS", COMPLEMENTARY = "COMPLEMENTARY", SPLIT_COMPLEMENTARY = "SPLIT_COMPLEMENTARY", TRIADIC = "TRIADIC", TETRADIC = "TETRADIC", SQUARE = "SQUARE" } declare enum Mix { ADDITIVE = "ADDITIVE", SUBTRACTIVE = "SUBTRACTIVE" } declare enum AnglesUnitEnum { NONE = "none", DEGREES = "deg", GRADIANS = "grad", RADIANS = "rad", TURNS = "turn" } declare enum ColorUnitEnum { NONE = "none", PERCENT = "percent" } declare enum CMYKFunctionEnum { DEVICE_CMYK = "device-cmyk", CMYK = "cmyk" } type NumberOrString = number | string; type AnglesUnitEnumString = `${AnglesUnitEnum}`; type ColorUnitEnumString = `${ColorUnitEnum}`; type CMYKFunctionEnumString = `${CMYKFunctionEnum}`; type MixString = `${Mix}`; interface HEXObject { R: string; G: string; B: string; A?: string; } interface RGBObject { R: number; G: number; B: number; A?: number; } interface RGBObjectGeneric { R: NumberOrString; G: NumberOrString; B: NumberOrString; A?: NumberOrString; } interface HSLObject { H: number; S: number; L: number; A?: number; } interface HSLObjectGeneric { H: number; S: NumberOrString; L: NumberOrString; A?: NumberOrString; } interface HWBObject { H: number; W: number; B: number; A?: number; } interface HWBObjectGeneric { H: number; W: NumberOrString; B: NumberOrString; A?: NumberOrString; } interface CIELabObject { L: number; a: number; b: number; A?: number; } interface CIELabObjectGeneric { L: NumberOrString; a: NumberOrString; b: NumberOrString; A?: NumberOrString; } interface LCHObject { L: number; C: number; H: number; A?: number; } interface LCHObjectGeneric { L: NumberOrString; C: NumberOrString; H: NumberOrString; A?: NumberOrString; } interface CMYKObject { C: number; M: number; Y: number; K: number; A?: number; } interface CMYKObjectGeneric { C: NumberOrString; M: NumberOrString; Y: NumberOrString; K: NumberOrString; A?: NumberOrString; } type Color = RGBObjectGeneric | HSLObjectGeneric | HWBObjectGeneric | CMYKObjectGeneric | CIELabObjectGeneric | LCHObjectGeneric; type ColorWithoutCMYK = RGBObjectGeneric | HSLObjectGeneric | HWBObjectGeneric | CIELabObjectGeneric | LCHObjectGeneric; type ColorInput = string | Color; type ColorInputWithoutCMYK = string | ColorWithoutCMYK; interface Options { decimals: number; legacyCSS: boolean; spacesAfterCommas: boolean; anglesUnit: AnglesUnitEnumString; rgbUnit: ColorUnitEnumString; labUnit: ColorUnitEnumString; lchUnit: ColorUnitEnumString; cmykUnit: ColorUnitEnumString; alphaUnit: ColorUnitEnumString; cmykFunction: CMYKFunctionEnumString; } type InputOptions = Partial<Options>; type StaticFunctionColorOutput<C> = C extends HEXObject ? HEXObject : C extends RGBObject ? RGBObject : C extends HSLObjectGeneric ? HSLObject : C extends HWBObjectGeneric ? HWBObject : C extends CIELabObjectGeneric ? CIELabObject : C extends LCHObjectGeneric ? LCHObject : string; type StaticFunctionReturn<C extends ColorInputWithoutCMYK> = StaticFunctionColorOutput<C>[]; type GetBlendOverload<C> = { (from: ColorInput, to: ColorInput, options?: InputOptions): C[]; (from: ColorInput, to: ColorInput, steps?: number, options?: InputOptions): C[]; }; type GetMixOverload<C> = { (color: ColorInput[], options?: InputOptions): C; (color: ColorInput[], mode?: MixString, options?: InputOptions): C; }; declare class ColorTranslator { constructor(color: ColorInput, options?: InputOptions); private _options; private rgb; private hsl; private hwb; private lab; private lch; private cmyk; private update; private updateRGB; private updateHSL; private updateHWB; private updateLAB; private updateLCH; private updateCMYK; private updateRGBFromHWB; private updateRGBFromLCH; private updateRGBFromCMYK; private updateRGBFromLAB; private updateLCHFromLAB; private updateLABromLCH; setOptions(options?: InputOptions): ColorTranslator; setR(R: number): ColorTranslator; setG(G: number): ColorTranslator; setB(B: number): ColorTranslator; setH(H: number): ColorTranslator; setS(S: number): ColorTranslator; setL(L: number): ColorTranslator; setWhiteness(W: number): ColorTranslator; setBlackness(B: number): ColorTranslator; setCIEL(L: number): ColorTranslator; setCIEa(a: number): ColorTranslator; setCIEb(b: number): ColorTranslator; setLCHL(l: number): ColorTranslator; setLCHC(c: number): ColorTranslator; setLCHH(h: number): ColorTranslator; setA(A: number): ColorTranslator; setC(C: number): ColorTranslator; setM(M: number): ColorTranslator; setY(Y: number): ColorTranslator; setK(K: number): ColorTranslator; get options(): Options; get R(): number; get G(): number; get B(): number; get H(): number; get S(): number; get L(): number; get Whiteness(): number; get Blackness(): number; get CIEL(): number; get CIEa(): number; get CIEb(): number; get LCHL(): number; get LCHC(): number; get LCHH(): number; get A(): number; get C(): number; get M(): number; get Y(): number; get K(): number; get HEXObject(): HEXObject; get HEXAObject(): HEXObject; get RGBObject(): RGBObject; get RGBAObject(): RGBObject; get HSLObject(): HSLObject; get HSLAObject(): HSLObject; get HWBObject(): HWBObject; get HWBAObject(): HWBObject; get CIELabObject(): CIELabObject; get CIELabAObject(): CIELabObject; get LCHObject(): LCHObject; get LCHAObject(): LCHObject; get CMYKObject(): CMYKObject; get CMYKAObject(): CMYKObject; get HEX(): string; get HEXA(): string; get RGB(): string; get RGBA(): string; get HSL(): string; get HSLA(): string; get HWB(): string; get HWBA(): string; get CIELab(): string; get CIELabA(): string; get LCH(): string; get LCHA(): string; get CMYK(): string; get CMYKA(): string; static toHEXObject(color: ColorInput): HEXObject; static toHEX(color: ColorInput): string; static toHEXAObject(color: ColorInput): HEXObject; static toHEXA(color: ColorInput): string; static toRGBObject(color: ColorInput, options?: InputOptions): RGBObject; static toRGB(color: ColorInput, options?: InputOptions): string; static toRGBAObject(color: ColorInput, options?: InputOptions): RGBObject; static toRGBA(color: ColorInput, options?: InputOptions): string; static toHSLObject(color: ColorInput, options?: InputOptions): HSLObject; static toHSL(color: ColorInput, options?: InputOptions): string; static toHSLAObject(color: ColorInput, options?: InputOptions): HSLObject; static toHSLA(color: ColorInput, options?: InputOptions): string; static toHWBObject(color: ColorInput, options?: InputOptions): HWBObject; static toHWB(color: ColorInput, options?: InputOptions): string; static toHWBAObject(color: ColorInput, options?: InputOptions): HWBObject; static toHWBA(color: ColorInput, options?: InputOptions): string; static toCIELabObject(color: ColorInput, options?: InputOptions): CIELabObject; static toCIELab(color: ColorInput, options?: InputOptions): string; static toCIELabAObject(color: ColorInput, options?: InputOptions): CIELabObject; static toCIELabA(color: ColorInput, options?: InputOptions): string; static toLCHObject(color: ColorInput, options?: InputOptions): LCHObject; static toLCH(color: ColorInput, options?: InputOptions): string; static toLCHAObject(color: ColorInput, options?: InputOptions): LCHObject; static toLCHA(color: ColorInput, options?: InputOptions): string; static toCMYKObject(color: ColorInput, options?: InputOptions): CMYKObject; static toCMYK(color: ColorInput, options?: InputOptions): string; static toCMYKAObject(color: ColorInput, options?: InputOptions): CMYKObject; static toCMYKA(color: ColorInput, options?: InputOptions): string; static getBlendHEXObject(from: ColorInput, to: ColorInput, steps?: number): RGBObject[]; static getBlendHEX(from: ColorInput, to: ColorInput, steps?: number): string[]; static getBlendHEXAObject(from: ColorInput, to: ColorInput, steps?: number): RGBObject[]; static getBlendHEXA(from: ColorInput, to: ColorInput, steps?: number): string[]; static getBlendRGBObject: GetBlendOverload<RGBObject>; static getBlendRGB: GetBlendOverload<string>; static getBlendRGBAObject: GetBlendOverload<RGBObject>; static getBlendRGBA: GetBlendOverload<string>; static getBlendHSLObject: GetBlendOverload<HSLObject>; static getBlendHSL: GetBlendOverload<string>; static getBlendHSLAObject: GetBlendOverload<HSLObject>; static getBlendHSLA: GetBlendOverload<string>; static getBlendHWBObject: GetBlendOverload<HWBObject>; static getBlendHWB: GetBlendOverload<string>; static getBlendHWBAObject: GetBlendOverload<HWBObject>; static getBlendHWBA: GetBlendOverload<string>; static getBlendCIELabObject: GetBlendOverload<CIELabObject>; static getBlendCIELab: GetBlendOverload<string>; static getBlendCIELabAObject: GetBlendOverload<CIELabObject>; static getBlendCIELabA: GetBlendOverload<string>; static getBlendLCHObject: GetBlendOverload<LCHObject>; static getBlendLCH: GetBlendOverload<string>; static getBlendLCHAObject: GetBlendOverload<LCHObject>; static getBlendLCHA: GetBlendOverload<string>; static getMixHEXObject: (colors: ColorInput[], mode?: MixString) => HEXObject; static getMixHEX: (colors: ColorInput[], mode?: MixString) => string; static getMixHEXAObject: (colors: ColorInput[], mode?: MixString) => HEXObject; static getMixHEXA: (colors: ColorInput[], mode?: MixString) => string; static getMixRGBObject: GetMixOverload<RGBObject>; static getMixRGB: GetMixOverload<string>; static getMixRGBAObject: GetMixOverload<RGBObject>; static getMixRGBA: GetMixOverload<string>; static getMixHSLObject: GetMixOverload<HSLObject>; static getMixHSL: GetMixOverload<string>; static getMixHSLAObject: GetMixOverload<HSLObject>; static getMixHSLA: GetMixOverload<string>; static getMixHWBObject: GetMixOverload<HWBObject>; static getMixHWB: GetMixOverload<string>; static getMixHWBAObject: GetMixOverload<HWBObject>; static getMixHWBA: GetMixOverload<string>; static getMixCIELabObject: GetMixOverload<CIELabObject>; static getMixCIELab: GetMixOverload<string>; static getMixCIELabAObject: GetMixOverload<CIELabObject>; static getMixCIELabA: GetMixOverload<string>; static getMixLCHObject: GetMixOverload<LCHObject>; static getMixLCH: GetMixOverload<string>; static getMixLCHAObject: GetMixOverload<LCHObject>; static getMixLCHA: GetMixOverload<string>; static getShades<C extends ColorInputWithoutCMYK>(color: C, options?: InputOptions): StaticFunctionReturn<C>; static getShades<C extends ColorInputWithoutCMYK>(color: C, shades?: number, options?: InputOptions): StaticFunctionReturn<C>; static getTints<C extends ColorInputWithoutCMYK>(color: C, options?: InputOptions): StaticFunctionReturn<C>; static getTints<C extends ColorInputWithoutCMYK>(color: C, tints?: number, options?: InputOptions): StaticFunctionReturn<C>; static getHarmony<C extends ColorInputWithoutCMYK>(color: C, options?: InputOptions): StaticFunctionReturn<C>; static getHarmony<C extends ColorInputWithoutCMYK>(color: C, mode?: MixString, options?: InputOptions): StaticFunctionReturn<C>; static getHarmony<C extends ColorInputWithoutCMYK>(color: C, harmony?: Harmony, options?: InputOptions): StaticFunctionReturn<C>; static getHarmony<C extends ColorInputWithoutCMYK>(color: C, harmony?: Harmony, mode?: MixString, options?: InputOptions): StaticFunctionReturn<C>; } export { ColorTranslator, Harmony, Mix }; export type { CIELabObject, CMYKObject, HSLObject, HWBObject, InputOptions, LCHObject, RGBObject };