MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / getReadableSymbolColor

Function getReadableSymbolColor

apps/desktop/main/window-titlebar.ts:47–58  ·  view source on GitHub ↗
(hexColor: string)

Source from the content-addressed store, hash-verified

45}
46
47function getReadableSymbolColor(hexColor: string): string {
48 const match = /^#([0-9a-f]{6})$/i.exec(hexColor)
49 if (!match) return '#52525b'
50
51 const value = match[1]
52 const r = Number.parseInt(value.slice(0, 2), 16) / 255
53 const g = Number.parseInt(value.slice(2, 4), 16) / 255
54 const b = Number.parseInt(value.slice(4, 6), 16) / 255
55 const luminance = 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b)
56
57 return luminance < 0.45 ? '#e4e4e7' : '#3f3f46'
58}
59
60function toLinear(value: number): number {
61 return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4

Callers 1

Calls 2

toLinearFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected