UNPKG

toosoon-utils

Version:
237 lines (236 loc) 6.79 kB
import type { ColorHex, ColorRgb, ColorHsl, ColorHsb, ColorHcl, ColorLab, ColorRepresentation } from './types'; /** * Normalize a color representation into RGB * * @param {ColorRepresentation} color Color representation * @returns {ColorRgb} Normalized RGB color */ export declare function normalizeColor(color: ColorRepresentation): ColorRgb; /** * Normalize an hexadecimal string * * @param {string} hex Hexadecimal string * @returns {string} Normalized hexadecimal string */ export declare function normalizeHexString(hex: string): string; /** * Convert RGB to hexadecimal * * Note: * - RGB values are contained in the interval [0, 1] * * @param {ColorRgb} rgb RGB color * @returns {ColorHex} Hexadecimal color */ export declare function rgbToHex([r, g, b]: ColorRgb): ColorHex; /** * Convert RGB to hexadecimal string * * Note: * - RGB values are contained in the interval [0, 1] * * @param {ColorRgb} rgb RGB color * @returns {string} Hexadecimal string */ export declare function rgbToHexString([r, g, b]: ColorRgb): string; /** * Convert hexadecimal to RGB * * Note: * - RGB values are contained in the interval [0, 1] * * @param {ColorHex|string} hex Hexadecimal color * @returns {ColorRgb} RGB color */ export declare function hexToRgb(hex: ColorHex | string): ColorRgb; /** * Lighten a color * * @param {string} hex Hexadecimal string * @param {number} [amount=0] Amount of the color offset * @returns {string} Computed hexadecimal */ export declare function lighten(hex: string, amount?: number): string; /** * Darken a color * * @param {string} hex Hexadecimal string * @param {number} [amount=0] Amount of the color offset * @returns {string} Computed hexadecimal */ export declare function darken(hex: string, amount?: number): string; /** * Normalize an HSL string * * Note: * - HSL values are contained in the intervals: * - Hue: [0, 360] * - Saturation: [0, 1] * - Lightness: [0, 1] * * @param {string} hsl HSL string (format: 'hsl(360, 100%, 100%)') * @returns {ColorHsl} Normalized HSL color */ export declare function normalizeHslString(hsl: string): ColorHsl; /** * Convert RGB to HSL * * Notes: * - RGB values are contained in the interval [0, 1] * - HSL values are contained in the intervals: * - Hue: [0, 360] * - Saturation: [0, 1] * - Lightness: [0, 1] * * @param {ColorHgb} rgb RGB color * @returns {ColorHsl} HSL color */ export declare function rgbToHsl([r, g, b]: ColorRgb): ColorHsl; /** * Convert HSL to RGB * * Notes: * - RGB values are contained in the interval [0, 1] * - HSL values are contained in the intervals: * - Hue: [0, 360] * - Saturation: [0, 1] * - Lightness: [0, 1] * * @param {ColorHsl} hsl HSL color * @returns {ColorRgb} RGB color */ export declare function hslToRgb([h, s, l]: ColorHsl): ColorRgb; /** * Convert RGB to HSB * * Notes: * - RGB values are contained in the interval [0, 1] * - HSB values are contained in the intervals: * - Hue: [0, 360] * - Saturation: [0, 1] * - Brightness: [0, 1] * * @param {ColorRgb} rgb RGB color * @returns {ColorHsb} HSB color */ export declare function rgbToHsb([r, g, b]: ColorRgb): ColorHsb; /** * Convert HSB to RGB * * Notes: * - RGB values are contained in the interval [0, 1] * - HSB values are contained in the intervals: * - Hue: [0, 360] * - Saturation: [0, 1] * - Brightness: [0, 1] * * @param {ColorHsb} hsb HSB color * @returns {ColorRgb} RGB color */ export declare function hsbToRgb([h, s, b]: ColorHsb): ColorRgb; /** * Convert L*a*b* to HCL * -> http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html * * Notes: * - L*a*b* values are contained in the intervals: * - Lightness: [0 à 100] * - a (green, red): [~-128, ~+128] * - b (blue, yellow): [~-128, ~+128] * - HCL values are contained in the intervals: * - Hue: [0, 360] * - Chroma: [0, ~150] * - Lightness: [0, 100] * * @param {ColorLab} lab LAB color * @returns {ColorHcl} HCL color */ export declare function labToHcl([l, a, b]: ColorLab): ColorHcl; /** * Convert HCL to L*a*b* * -> http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html * * Notes: * - HCL values are contained in the intervals: * - Hue: [0, 360] * - Chroma: [0, ~150] * - Lightness: [0, 100] * - L*a*b* values are contained in the intervals: * - Lightness: [0 à 100] * - a (green, red): [~-128, ~+128] * - b (blue, yellow): [~-128, ~+128] * * @param {ColorHcl} hcl HCL color * @returns {ColorLab} LAB color */ export declare function hclToLab([h, c, l]: ColorHcl): ColorLab; /** * Convert L*a*b* to RGB * * Notes: * - RGB values are contained in the interval [0, 1] * - L*a*b* values are contained in the intervals: * - Lightness: [0 à 100] * - a (green, red): [~-128, ~+128] * - b (blue, yellow): [~-128, ~+128] * * @param {ColorLab} lab L*a*b* color * @returns {ColorRgb} RGB color */ export declare function labToRgb([l, a, b]: ColorLab): ColorRgb; /** * Convert RGB to L*a*b* * * Notes: * - RGB values are contained in the interval [0, 1] * - L*a*b* values are contained in the intervals: * - Lightness: [0 à 100] * - a (green, red): [~-128, ~+128] * - b (blue, yellow): [~-128, ~+128] * * @param {ColorRgb} rgb RGB color * @returns {ColorLab} L*a*b* color */ export declare function rgbToLab([r, g, b]: ColorRgb): ColorLab; /** * Get the delta from two L*a*b* colors * * Note: * - L*a*b* values are contained in the intervals: * - Lightness: [0 à 100] * - a (green, red): [~-128, ~+128] * - b (blue, yellow): [~-128, ~+128] * * @param {ColorLab} lab1 First L*a*b* color * @param {ColorLab} lab2 Second L*a*b* color * @returns {number} */ export declare function deltaE(lab1: ColorLab, lab2: ColorLab): number; /** * Convert RGB to HCL * * Notes: * - RGB values are contained in the interval [0, 1] * - HCL values are contained in the intervals: * - Hue: [0, 360] * - Chroma: [0, ~150] * - Luminance: [0, 100] * * @param {ColorRgb} rgb RGB color * @returns {ColorHcl} HCL color */ export declare function rgbToHcl([r, g, b]: ColorRgb): ColorHcl; /** * Converts HCL to RGB * * Notes: * - RGB values are contained in the interval [0, 1] * - HCL values are contained in the intervals: * - Hue: [0, 360] * - Chroma: [0, ~150] * - Luminance: [0, 100] * * @param {ColorHcl} hcl RGB color * @returns {ColorRgb} RGB color */ export declare function hclToRgb([h, c, l]: ColorHcl): ColorRgb;