@ngageoint/color-js
Version:
Color Javascript
363 lines • 12.6 kB
TypeScript
/**
* Color utilities with support for hex, RBG, arithmetic RBG, HSL, and integer
* colors
*
* @author osbornb
*/
export declare class ColorUtils {
/**
* Hex color pattern
*/
private static readonly hexColorPattern;
/**
* Hex single color pattern
*/
private static readonly hexSingleColorPattern;
/**
* Convert the hex color values to a hex color, shorthanded when possible
*
* @param red
* red hex color in format RR or R
* @param green
* green hex color in format GG or G
* @param blue
* blue hex color in format BB or B
*
* @return hex color in format #RGB or #RRGGBB
*/
static toColorShorthand(red: string, green: string, blue: string): string;
/**
* Convert the hex color values to a hex color including an opaque alpha
* value of FF or F, shorthanded when possible
*
* @param red
* red hex color in format RR or R
* @param green
* green hex color in format GG or G
* @param blue
* blue hex color in format BB or B
*
* @return hex color in format #ARGB or #AARRGGBB
*/
static toColorShorthandWithDefaultAlpha(red: string, green: string, blue: string): string;
/**
* Convert the hex color values to a hex color, shorthanded when possible
*
* @param red
* red hex color in format RR or R
* @param green
* green hex color in format GG or G
* @param blue
* blue hex color in format BB or B
* @param alpha
* alpha hex color in format AA or A, null to not include alpha
*
* @return hex color in format #ARGB, #RGB, #AARRGGBB, or #RRGGBB
*/
static toColorShorthandWithAlpha(red: string, green: string, blue: string, alpha: string): string;
/**
* Convert the RBG values to a color integer or hex color values to a hex color
*
* @param red
* red integer color inclusively between 0 and 255 or red hex color in format RR or R
* @param green
* green integer color inclusively between 0 and 255 or green hex color in format GG or G
* @param blue
* blue integer color inclusively between 0 and 255 or blue hex color in format BB or B
*
* @return integer color or hex color in format #RRGGBB
*/
static toColor(red: string | number, green: string | number, blue: string | number): string | number;
/**
* Convert the RBG values to a color integer including an opaque alpha value
* of 255 or Convert the hex color values to a hex color including an opaque alpha
* value of FF
*
* @param red
* red integer color inclusively between 0 and 255 or red hex color in format RR or R
* @param green
* green integer color inclusively between 0 and 255 or green hex color in format GG or G
* @param blue
* blue integer color inclusively between 0 and 255 or blue hex color in format BB or B
*
* @return integer color or hex color in format #AARRGGBB
*/
static toColorWithDefaultAlpha(red: string | number, green: string | number, blue: string | number): string | number;
/**
* Convert the RBGA values to a color integer or Convert the hex color values to a hex color
*
* @param red
* red integer color inclusively between 0 and 255 or red hex color in format RR or R
* @param green
* green integer color inclusively between 0 and 255 or green hex color in format GG or G
* @param blue
* blue integer color inclusively between 0 and 255 or blue hex color in format BB or B or alpha hex color in format AA or A, null to not include alpha
* @param alpha
* alpha integer color inclusively between 0 and 255, -1 to not
* include alpha
*
* @return integer color or hex color in format #AARRGGBB or #RRGGBB
*/
static toColorWithAlpha(red: string | number, green: string | number, blue: string | number, alpha: string | number | null): string | number;
/**
* Convert the RGB integer to a hex single color
*
* @param color
* integer color inclusively between 0 and 255 or float color inclusively between 0.0 and 1.0
* @return hex single color in format FF
*/
static toHex(color: number): string;
/**
* Convert red, green, and blue arithmetic values to HSL (hue, saturation,
* lightness) values
*
* @param red
* red color inclusively between 0.0 and 1.0 or between 0 and 255
* @param green
* green color inclusively between 0.0 and 1.0 or between 0 and 255
* @param blue
* blue color inclusively between 0.0 and 1.0 or between 0 and 255
* @return HSL array where: 0 = hue, 1 = saturation, 2 = lightness
*/
static toHSL(red: number, green: number, blue: number): number[];
/**
* Convert the RGB integer to an arithmetic RBG float or Convert the hex single color to an arithmetic RBG float
*
* @param color
* integer color inclusively between 0 and 255 or hex single color in format FF or F
* @return float color inclusively between 0.0 and 1.0
*/
static toArithmeticRGB(color: string | number): number;
/**
* Convert HSL (hue, saturation, and lightness) values to RGB arithmetic
* values
*
* @param hue
* hue value inclusively between 0.0 and 360.0
* @param saturation
* saturation inclusively between 0.0 and 1.0
* @param lightness
* lightness inclusively between 0.0 and 1.0
* @return arithmetic RGB array where: 0 = red, 1 = green, 2 = blue
*/
static toArithmeticRGBFromHSL(hue: number, saturation: number, lightness: number): number[];
/**
* Convert the arithmetic RGB float to a RBG integer or Convert the hex single color to a RBG integer
*
* @param color
* float color inclusively between 0.0 and 1.0 or hex single color in format FF or F
*
* @return integer color inclusively between 0 and 255
*/
static toRGB(color: string | number): number;
/**
* Convert HSL (hue, saturation, and lightness) values to RGB integer values
*
* @param hue
* hue value inclusively between 0.0 and 360.0
* @param saturation
* saturation inclusively between 0.0 and 1.0
* @param lightness
* lightness inclusively between 0.0 and 1.0
* @return RGB integer array where: 0 = red, 1 = green, 2 = blue
*/
static toRGBFromHSL(hue: number, saturation: number, lightness: number): number[];
/**
* HSL convert helper method
*
* @param t1
* t1
* @param t2
* t2
* @param hue
* hue
* @return arithmetic RBG value
*/
private static hslConvert;
/**
* Get the hex single color
*
* @param hex
* hex color
* @param colorIndex
* red=0, green=1, blue=2, alpha=-1
* @return hex single color in format FF or null
*/
private static getHexSingle;
/**
* Get the red color from color integer or Get the hex red color from the hex string
*
* @param color
* color integer or hex color
* @return red color or hex red color in format RR
*/
static getRed(color: string | number): string | number;
/**
* Get the green color from color integer or Get the hex green color from the hex string
*
* @param color
* color integer or hex color
* @return green color or hex green color in format GG
*/
static getGreen(color: string | number): string | number;
/**
* Get the blue color from color integer or Get the hex blue color from the hex string
*
* @param color
* color integer or hex color
* @return blue color or hex blue color in format BB
*/
static getBlue(color: string | number): string | number;
/**
* Get the alpha color from color integer or Get the hex alpha color from the hex string if it exists
*
* @param color
* color integer or hex color
* @return alpha color or hex alpha color in format AA or null
*/
static getAlpha(color: string | number): string | number;
/**
* Shorthand the hex color if possible
*
* @param color
* hex color
* @return shorthand hex color or original value
*/
static shorthandHex(color: string): string;
/**
* Expand the hex if it is in shorthand
*
* @param color
* hex color
* @return expanded hex color or original value
*/
static expandShorthandHex(color: string): string;
/**
* Shorthand the hex single color if possible
*
* @param color
* hex single color
* @return shorthand hex color or original value
*/
static shorthandHexSingle(color: string): string;
/**
* Expand the hex single if it is in shorthand
*
* @param color
* hex single color
* @return expanded hex color or original value
*/
static expandShorthandHexSingle(color: string): string;
/**
* Check if the hex color value is valid
*
* @param color
* hex color
* @return true if valid
*/
static isValidHex(color: string | null): boolean;
/**
* Validate the hex color value
*
* @param color
* hex color
*/
static validateHex(color: string): void;
/**
* Check if the hex single color value is valid
*
* @param color
* hex single color
* @return true if valid
*/
static isValidHexSingle(color: string | null): boolean;
/**
* Validate the hex single color value
*
* @param color
* hex single color
*/
static validateHexSingle(color: string): void;
/**
* Check if the RBG integer color is valid, inclusively between 0 and 255
*
* @param color
* decimal color
* @return true if valid
*/
static isValidRGB(color: number): boolean;
/**
* Validate the RBG integer color is inclusively between 0 and 255
*
* @param color
* decimal color
*/
static validateRGB(color: number): void;
/**
* Check if the arithmetic RGB float color is valid, inclusively between 0.0
* and 1.0
*
* @param color
* decimal color
* @return true if valid
*/
static isValidArithmeticRGB(color: number): boolean;
/**
* Validate the arithmetic RGB float color is inclusively between 0.0 and
* 1.0
*
* @param color
* decimal color
*/
static validateArithmeticRGB(color: number): void;
/**
* Check if the HSL hue float value is valid, inclusively between 0.0 and
* 360.0
*
* @param hue
* hue value
* @return true if valid
*/
static isValidHue(hue: number): boolean;
/**
* Validate the HSL hue float value is inclusively between 0.0 and 360.0
*
* @param hue
* hue value
*/
static validateHue(hue: number): void;
/**
* Check if the HSL saturation float value is valid, inclusively between 0.0
* and 1.0
*
* @param saturation
* saturation value
* @return true if valid
*/
static isValidSaturation(saturation: number): boolean;
/**
* Validate the HSL saturation float value is inclusively between 0.0 and
* 1.0
*
* @param saturation
* saturation value
*/
static validateSaturation(saturation: number): void;
/**
* Check if the HSL lightness float value is valid, inclusively between 0.0
* and 1.0
*
* @param lightness
* lightness value
* @return true if valid
*/
static isValidLightness(lightness: number): boolean;
/**
* Validate the HSL lightness float value is inclusively between 0.0 and 1.0
*
* @param lightness
* lightness value
*/
static validateLightness(lightness: number): void;
}
//# sourceMappingURL=ColorUtils.d.ts.map