(hexColor: string)
| 45 | } |
| 46 | |
| 47 | function 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 | |
| 60 | function toLinear(value: number): number { |
| 61 | return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4 |
no test coverage detected