MCPcopy Create free account
hub / github.com/anomalyco/opencode / luminance

Function luminance

packages/ui/src/theme/color.ts:259–262  ·  view source on GitHub ↗
(hex: HexColor)

Source from the content-addressed store, hash-verified

257export 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)

Callers 1

contrastRatioFunction · 0.70

Calls 2

linearFunction · 0.85
hexToRgbFunction · 0.70

Tested by

no test coverage detected