(hex: HexColor)
| 257 | export function contrastRatio(foreground: HexColor, background: HexColor) { |
| 258 | const linear = (c: number) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4) |
| 259 | const luminance = (hex: HexColor) => { |
| 260 | const { r, g, b } = hexToRgb(hex) |
| 261 | return 0.2126 * linear(r) + 0.587 * linear(g) + 0.0722 * linear(b) |
| 262 | } |
| 263 | const fg = luminance(foreground) |
| 264 | const bg = luminance(background) |
| 265 | const lighter = Math.max(fg, bg) |
no test coverage detected