UNPKG

advanced-color-utils

Version:

Unleash the full potential of color manipulation with the ColorUtils library! Designed for developers who need precise control over color processing.

138 lines (137 loc) 6.18 kB
import chroma from "chroma-js"; import { LabColor, RGBColor } from "color-diff"; import { HSLColor } from "./types"; export declare class ColorUtils { /** * Generate a complementary color for a given hex color. * @param {string} hex - The hex color string (e.g., '#ff0000'). * @returns {string} The complementary hex color string. */ static getComplementaryColor(hex: string): string; /** * Generate a color palette based on a given hex color and the desired number of colors. * @param {string} hex - The hex color string (e.g., '#ff0000'). * @param {number} numColors - The number of colors in the palette. * @returns {string[]} The array of hex color strings in the palette. */ static generateComplementaryPalette(hex: string, numColors: number): string[]; /** * Convert an RGB color to a hex color string. * @param {RGBColor} rgb - The RGB color object. * @returns {string} The hex color string. */ static rgbToHex(rgb: RGBColor): string; /** * Convert a hex color to an RGB object. * @param {string} hex - The hex color string (e.g., "#ff0000"). * @returns {RGBColor} The RGB color object. */ static hexToRgb(hex: string): RGBColor; /** * Convert a LAB color to a hex color string. * @param {LabColor} lab - The LAB color object. * @returns {string} The hex color string. */ static labToHex(lab: LabColor): string; /** * Convert a hex color to a LAB object. * @param {string} hex - The hex color string (e.g., "#ff0000"). * @returns {LabColor} The LAB color object. */ private static hexToLab; /** * Convert an RGB color to an HSL color object. * @param {RGBColor} rgb - The RGB color object. * @returns {HSLColor} The HSL color object. */ static rgbToHsl(rgb: RGBColor): HSLColor; /** * Convert an HSL color to an RGB color this is an approximation to the nearest RGB color. * @param {HSLColor} hsl - The HSL color object. * @returns {RGBColor} The RGB color object. */ static hslToRgb(hsl: HSLColor): RGBColor; /** * Generate a complementary color for a given hex color. * @param {string} hex - The hex color string (e.g., '#ff0000'). * @returns {string} The hex color string of the complementary color. */ static generateComplementaryColor(hex: string): string; /** * Generate triadic colors based on a base color. * @param {string} baseColor - The base HEX color string. * @returns {string[]} An array of triadic HEX color strings. */ static generateTriadicColors(baseColor: string): string[]; /** * Generate a monochromatic color scheme based on a given hex color. * Function not working at the moment some cases are returning NaN values * @param {string} hex - The hex color string. * @param {number} numColors - The number of monochromatic colors to generate. * @returns {string[]} An array of hex color strings representing the monochromatic color scheme. */ static generateMonochromaticColors(hex: string, numColors: number): string[]; /** * Get a specified number of distinct colors from a list based on a similarity threshold. * @param {string[]} hexColors - The list of hex color strings. * @param {number} numColors - The number of distinct colors to retrieve. * @param {number} threshold - The threshold for color similarity (lower values mean more similar). * @returns {string[]} The list of distinct hex color strings. */ static getDistinctColors(hexColors: string[], numColors: number, threshold: number): string[]; /** * Generate shades of a given hex color. * @param {string} hex - The hex color string. * @param {number} numShades - The number of shades to generate. * @returns {string[]} The array of hex color strings representing the shades. */ static generateShades(hex: string, numShades: number): string[]; /** * Generate tints of a given hex color. * @param {string} hex - The hex color string. * @param {number} numTints - The number of tints to generate. * @returns {string[]} The array of hex color strings representing the tints. */ static generateTints(hex: string, numTints: number): string[]; /** * Blend two hex colors together. * @param {string} color1 - The first hex color string. * @param {string} color2 - The second hex color string. * @param {number} ratio - The ratio of blending (0 to 1). 0 means full color1, 1 means full color2. * @param {chroma.InterpolationMode} [colorSpace='lab'] - The color space to use for blending (default is 'lab'). * @returns {string} The blended hex color string. */ static blendColors(color1: string, color2: string, ratio: number, colorSpace?: chroma.InterpolationMode): string; /** * Convert a hex color to an HSL color object. * @param {string} hex - The hex color string. * @returns {HSLColor} The HSL color object. */ static hexToHsl(hex: string): HSLColor; /** * Convert an HSL color to a hex color string. * @param {HSLColor} hsl - The HSL color object. * @returns {string} The hex color string. */ static hslToHex(hsl: HSLColor): string; /** * Calculate the contrast ratio between two colors. * @param {string} color1 - The first hex color string. * @param {string} color2 - The second hex color string. * @returns {number} The contrast ratio. */ static getContrastRatio(color1: string, color2: string): number; /** * Generate a random hex color string. * @returns {string} The random hex color string. */ static generateRandomColor(): string; /** * Generate analogous colors for a given hex color. * @param {string} hex - The hex color string. * @param {number} numColors - The number of analogous colors to generate. * @returns {string[]} The array of hex color strings representing the analogous colors. */ static generateAnalogousColors(hex: string, numColors: number): string[]; } export default ColorUtils;