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

Function contrastRatio

packages/ui/src/theme/color.ts:257–268  ·  view source on GitHub ↗
(foreground: HexColor, background: HexColor)

Source from the content-addressed store, hash-verified

255}
256
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)
266 const darker = Math.min(fg, bg)
267 return (lighter + 0.05) / (darker + 0.05)
268}
269
270export function blend(color: HexColor, background: HexColor, alpha: number): HexColor {
271 const fg = hexToRgb(color)

Callers 1

pickGreyFunction · 0.90

Calls 1

luminanceFunction · 0.70

Tested by

no test coverage detected