Files
2026-07-13 13:12:33 +08:00

11 lines
547 B
TypeScript

// Shared e2e helpers. One relative-luminance implementation for every spec
// that asserts on computed colors — fix parsing quirks here, once.
/** Approximate relative luminance (0..1) of a computed `rgb()`/`rgba()` color. */
export function relativeLuminance(color: string): number {
const m = color.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/)
if (!m) throw new Error(`Unexpected computed color: ${color}`)
const [r, g, b] = [Number(m[1]), Number(m[2]), Number(m[3])]
return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255
}