Color - Play with Colors Convert, blend, manipulate and do more
Color
The Color
class provides a robust way to work with colors in various formats (i.e. Hex, Hex8, RGB, HSL, RGBA, HSLA) and includes methods for color manipulation, blending, and accessibility checks.
Table of Contents
- Color Manipulation Methods
- Color Scheme Generation
- Accessibility & Contrast Methods
- Static Validation Methods
Type Definitions
Hex
type Hex = `#${string}`; // Format: #3C6945
Hex6
type Hex6 = Branded<`#${string}`, 'Hex6'>; // Format: #3C6945
Hex8
type Hex8 = Branded<`#${string}`, 'Hex8'>; // Format: #3C6945FF (with alpha)
RGB
type RGB = `rgb(${number}, ${number}, ${number})` | `rgb(${number},${number},${number})`; // Format: rgb(R, G, B)
RGBA
type RGBA = `rgba(${number}, ${number}, ${number}, ${number})` | `rgba(${number},${number},${number},${number})`; // With alpha
HSL
type HSL = `hsl(${number}, ${number}%, ${number}%)` | `hsl(${number},${number}%,${number}%)`; // Format: hsl(H, S%, L%)
HSLA
type HSLA = `hsla(${number}, ${number}%, ${number}%, ${number})` | `hsla(${number},${number}%,${number}%,${number})`; // With alpha
ColorType
// Union of Alpha & Solid `Hex`, `RGB` and `HSL`
type ColorType = Hex | Hex6 | RGB | HSL | Hex8 | RGBA | HSLA;
CSSColor
type CSSColor = "black" | "silver" | "gray" | "white" | "maroon" | "red" | "purple" | "fuchsia" | "green" | "lime" | "olive" | "yellow" | "navy" | "blue" | "teal" | "aqua" | "aliceblue" | "antiquewhite" | "aquamarine" | "azure" | "beige" | "bisque" | "blanchedalmond" | "blueviolet" | "brown" | "burlywood" | "cadetblue" | "chartreuse" | "chocolate" | "coral" | "cornflowerblue" | "cornsilk" | "crimson" | "cyan" | "darkblue" | "darkcyan" | "darkgoldenrod" | "darkgray" | "darkgreen" | "darkgrey" | "darkkhaki" | "darkmagenta" | "darkolivegreen" | "darkorange" | ... 112 more ... | "error"; // All valid (150+) CSS color names
Percent
type Percent = 0 | 1 | 2 | ... | 100; // 0-100