UNPKG

qw-utils-vanguard

Version:

qw Utils package

78 lines (77 loc) 2.81 kB
/** * 颜色工具类 */ export declare class colorUtils { constructor(); /** * 判断是否 十六进制颜色值. * 输入形式可为 #fff000 #f00 * * @param String color 十六进制颜色值 * @return Boolean */ isHexColor: (color: string) => boolean; /** * RGB 颜色值转换为 十六进制颜色值. * r, g, 和 b 需要在 [0, 255] 范围内 * * @return String 类似#ff00ff * @param r * @param g * @param b */ rgbToHex: (r: number, g: number, b: number) => string; /** * Transform a HEX color to its RGB representation * @param {string} hex The color to transform * @returns The RGB representation of the passed color */ hexToRGB: (hex: string, opacity?: number) => string; colorIsDark: (color: string) => boolean | undefined; /** * Darkens a HEX color given the passed percentage * @param {string} color The color to process * @param {number} amount The amount to change the color by * @returns {string} The HEX representation of the processed color */ darken: (color: string, amount: number) => string; /** * Lightens a 6 char HEX color according to the passed percentage * @param {string} color The color to change * @param {number} amount The amount to change the color by * @returns {string} The processed color represented as HEX */ lighten: (color: string, amount: number) => string; /** * Sums the passed percentage to the R, G or B of a HEX color * @param {string} color The color to change * @param {number} amount The amount to change the color by * @returns {string} The processed part of the color */ addLight: (color: string, amount: number) => string; /** * Calculates luminance of an rgb color * @param {number} r red * @param {number} g green * @param {number} b blue */ luminanace: (r: number, g: number, b: number) => number; /** * Calculates contrast between two rgb colors * @param {string} rgb1 rgb color 1 * @param {string} rgb2 rgb color 2 */ contrast: (rgb1: string[], rgb2: number[]) => number; /** * Determines what the best text color is (black or white) based con the contrast with the background * @param hexColor - Last selected color by the user */ calculateBestTextColor: (hexColor: string) => "#000000" | "#FFFFFF"; /** * Subtracts the indicated percentage to the R, G or B of a HEX color * @param {string} color The color to change * @param {number} amount The amount to change the color by * @returns {string} The processed part of the color */ subtractLight: (color: string, amount: number) => string; }