tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
396 lines • 11.6 kB
text/typescript
export default TinyColorConverter;
/**
* Represents a color in RGBA format.
* Each element must be a number between 0 and 255.
* The fourth value represents the alpha (transparency) channel.
*/
export type RgbaColor = number[];
/**
* Represents a color in RGB format.
* Each element must be a number between 0 and 255.
*/
export type RgbColor = number[];
/**
* Represents a color in HSLA format.
* The fourth value represents the alpha (transparency) channel.
*/
export type HslaColor = number[];
/**
* Represents a color in HSL format.
*/
export type HslColor = number[];
/**
* Represents a hex color.
*/
export type HexColor = string;
/**
* A union type representing various accepted color formats.
* Can be a hex color string, a numeric value, or an array-based RGB/RGBA representation.
*/
export type ColorTypes = HexColor | number | RgbColor | RgbaColor;
export type RgbaResult = {
/**
* - Red component (0–255)
*/
r: number;
/**
* - Green component (0–255)
*/
g: number;
/**
* - Blue component (0–255)
*/
b: number;
/**
* - Alpha component (0–255)
*/
a: number;
};
export type RgbResult = {
/**
* - Red component (0–255)
*/
r: number;
/**
* - Green component (0–255)
*/
g: number;
/**
* - Blue component (0–255)
*/
b: number;
};
export type HexResult = {
/**
* - Hex color
*/
hex: string;
};
export type HslResult = {
/**
* - Hue (0–360)
*/
h: number;
/**
* - Saturation (0–100)
*/
s: number;
/**
* - Lightness (0–100)
*/
l: number;
};
/**
* Represents a color in RGBA format.
* Each element must be a number between 0 and 255.
* The fourth value represents the alpha (transparency) channel.
*
* @typedef {number[]} RgbaColor
* @property {number} 0 - Red component (0–255)
* @property {number} 1 - Green component (0–255)
* @property {number} 2 - Blue component (0–255)
* @property {number} 3 - Alpha component (0–255)
*/
/**
* Represents a color in RGB format.
* Each element must be a number between 0 and 255.
*
* @typedef {number[]} RgbColor
* @property {number} 0 - Red component (0–255)
* @property {number} 1 - Green component (0–255)
* @property {number} 2 - Blue component (0–255)
*/
/**
* Represents a color in HSLA format.
* The fourth value represents the alpha (transparency) channel.
*
* @typedef {number[]} HslaColor
* @property {number} 0 - Hue (0–360)
* @property {number} 1 - Saturation (0–100)
* @property {number} 2 - Lightness (0–100)
* @property {number} 3 - Alpha component (0–255)
*/
/**
* Represents a color in HSL format.
*
* @typedef {number[]} HslColor
* @property {number} 0 - Hue (0–360)
* @property {number} 1 - Saturation (0–100)
* @property {number} 2 - Lightness (0–100)
*/
/**
* Represents a hex color.
*
* @typedef {string} HexColor
*/
/**
* A union type representing various accepted color formats.
* Can be a hex color string, a numeric value, or an array-based RGB/RGBA representation.
*
* @typedef {HexColor | number | RgbColor | RgbaColor} ColorTypes
*/
/**
* @typedef {Object} RgbaResult
* @property {number} r - Red component (0–255)
* @property {number} g - Green component (0–255)
* @property {number} b - Blue component (0–255)
* @property {number} a - Alpha component (0–255)
*/
/**
* @typedef {Object} RgbResult
* @property {number} r - Red component (0–255)
* @property {number} g - Green component (0–255)
* @property {number} b - Blue component (0–255)
*/
/**
* @typedef {Object} HexResult
* @property {string} hex - Hex color
*/
/**
* @typedef {Object} HslResult
* @property {number} h - Hue (0–360)
* @property {number} s - Saturation (0–100)
* @property {number} l - Lightness (0–100)
*/
/**
* A class that allows converting colors between all common formats.
*/
declare class TinyColorConverter {
/**
* Generates a smooth gradient of colors based on sine wave patterns.
*
* @see {@link https://www.npmjs.com/package/rainbow-colors-array} Code Reference
* @param {number} [len=24] - The number of colors to generate.
* @param {'rgb'|'hex'|'hsl'} [type='rgb'] - The format of the colors returned: `'rgb'`, `'hex'`, or `'hsl'`.
* @param {boolean} [pastel=false] - If true, generates pastel tones by adjusting the intensity and offset.
* @returns {Array<RgbResult|HexResult|HslResult>} An array of color values in the selected format:
*/
static _rca(len?: number, type?: "rgb" | "hex" | "hsl", pastel?: boolean): Array<RgbResult | HexResult | HslResult>;
/**
* Generates a smooth gradient of colors based on sine wave patterns.
*
* @param {number} [len=24] - The number of colors to generate.
* @param {boolean} [pastel=false] - If true, generates pastel tones by adjusting the intensity and offset.
* @returns {RgbResult[]} An array of rgb color values.
*/
static rcaRgb(len?: number, pastel?: boolean): RgbResult[];
/**
* Generates a smooth gradient of colors based on sine wave patterns.
*
* @param {number} [len=24] - The number of colors to generate.
* @param {boolean} [pastel=false] - If true, generates pastel tones by adjusting the intensity and offset.
* @returns {HslResult[]} An array of hsl color values.
*/
static rcaHsl(len?: number, pastel?: boolean): HslResult[];
/**
* Generates a smooth gradient of colors based on sine wave patterns.
*
* @param {number} [len=24] - The number of colors to generate.
* @param {boolean} [pastel=false] - If true, generates pastel tones by adjusting the intensity and offset.
* @returns {HexResult[]} An array of hex color values.
*/
static rcaHex(len?: number, pastel?: boolean): HexResult[];
/**
* Generates a random color in hexadecimal format.
*
* @returns {HexColor} A hex color string (e.g. `#a3e5f2`).
*/
static randomColor(): HexColor;
/**
* Parses input into RGBA array.
* @param {ColorTypes} input
* @param {boolean} isHsl
* @returns {RgbaColor}
*/
static parseInput(input: ColorTypes, isHsl: boolean): RgbaColor;
/**
* Converts hsl to integer.
* @param {number} h - Hue (0–360)
* @param {number} s - Saturation (0–100)
* @param {number} l - Lightness (0–100)
* @returns {number}
*/
static hslToInt(h: number, s: number, l: number): number;
/**
* Converts hsl to hex.
* @param {number} h - Hue (0–360)
* @param {number} s - Saturation (0–100)
* @param {number} l - Lightness (0–100)
* @returns {HexColor}
*/
static hslToHex(h: number, s: number, l: number): HexColor;
/**
* Converts hsl(a) string to RGBA array.
* @param {string} hsl
* @returns {RgbaColor}
*/
static hslStringToRgbaArray(hsl: string): RgbaColor;
/**
* Converts HSL or HSLA to RGBA.
* @param {number} h - Hue (0–360)
* @param {number} s - Saturation (0–100)
* @param {number} l - Lightness (0–100)
* @param {number} [a=1] - Alpha (0–1)
* @returns {RgbaColor}
*/
static hslToRgba(h: number, s: number, l: number, a?: number): RgbaColor;
/**
* Converts HSL or HSLA to RGB.
* @param {number} h - Hue (0–360)
* @param {number} s - Saturation (0–100)
* @param {number} l - Lightness (0–100)
* @param {number} [a=1] - Alpha (0–1)
* @returns {RgbColor}
*/
static hslToRgb(h: number, s: number, l: number, a?: number): RgbColor;
/**
* Converts hex to integer.
* @param {HexColor} hex
* @returns {number}
*/
static hexToInt(hex: HexColor): number;
/**
* Converts hex string to HSL array.
* @param {HexColor} hex
* @returns {HslColor}
*/
static hexToHsl(hex: HexColor): HslColor;
/**
* Converts hex string to HSL array.
* @param {HexColor} hex
* @returns {HslaColor}
*/
static hexToHsla(hex: HexColor): HslaColor;
/**
* Converts hex string to RGBA array.
* @param {HexColor} hex
* @returns {RgbaColor}
*/
static hexToRgba(hex: HexColor): RgbaColor;
/**
* Converts HEX to RGB.
* @param {HexColor} hex
* @returns {RgbColor}
*/
static hexToRgb(hex: HexColor): RgbColor;
/**
* Converts RGB to HEX.
* @param {number} r
* @param {number} g
* @param {number} b
* @returns {HexColor}
*/
static rgbToHex(r: number, g: number, b: number): HexColor;
/**
* Converts RGB to integer.
* @param {number} r
* @param {number} g
* @param {number} b
* @returns {number}
*/
static rgbToInt(r: number, g: number, b: number): number;
/**
* Converts RGBA to HSLA.
* @param {number} r
* @param {number} g
* @param {number} b
* @param {number} [a=1]
* @returns {HslaColor}
*/
static rgbaToHsla(r: number, g: number, b: number, a?: number): HslaColor;
/**
* Converts RGBA to HSL.
* @param {number} r
* @param {number} g
* @param {number} b
* @param {number} [a=1]
* @returns {HslColor}
*/
static rgbaToHsl(r: number, g: number, b: number, a?: number): HslColor;
/**
* Converts rgb(a) string to RGBA array.
* @param {string} rgb
* @returns {RgbaColor}
*/
static rgbStringToRgbaArray(rgb: string): RgbaColor;
/**
* Converts integer color to HSL.
* @param {number} int
* @returns {HslColor}
*/
static intToHsl(int: number): HslColor;
/**
* Converts integer color to HSL.
* @param {number} int
* @returns {HslaColor}
*/
static intToHsla(int: number): HslaColor;
/**
* Converts integer color to hex.
* @param {number} int
* @returns {HexColor}
*/
static intToHex(int: number): HexColor;
/**
* Converts an integer (0xRRGGBB) to RGBA.
* @param {number} value
* @returns {RgbaColor}
*/
static intToRgba(value: number): RgbaColor;
/**
* @param {ColorTypes|null} [input=null] - Any valid color (hex, rgb string, rgba string, hsl(a), css name, array or int).
* @param {boolean} [checkIsHsl=false]
*/
constructor(input?: ColorTypes | null, checkIsHsl?: boolean);
/**
* @param {ColorTypes} input - Any valid color (hex, rgb string, rgba string, hsl(a), css name, array or int).
*/
setColor(input: ColorTypes): void;
/**
* Returns HSLA array.
* @returns {HslaColor}
*/
toHslaArray(): HslaColor;
/**
* Returns RGB string.
* @returns {string}
*/
toHslString(): string;
/**
* Returns RGBA string.
* @returns {string}
*/
toHslaString(): string;
/**
* Returns RGBA array.
* @returns {RgbaColor}
*/
toRgbaArray(): RgbaColor;
/**
* Returns RGB string.
* @returns {string}
*/
toRgbString(): string;
/**
* Returns RGBA string.
* @returns {string}
*/
toRgbaString(): string;
/**
* Returns hex color.
* @returns {HexColor}
*/
toHex(): HexColor;
/**
* Returns color as integer.
* @returns {number}
*/
toInt(): number;
/**
* Returns the original input.
* @returns {ColorTypes}
*/
getOriginal(): ColorTypes;
#private;
}
//# sourceMappingURL=TinyColorConverter.d.mts.map