(hex: string | undefined)
| 74 | } |
| 75 | |
| 76 | function hexToRgb(hex: string | undefined) { |
| 77 | const match = hex ? hexColorPattern.exec(hex.trim()) : null |
| 78 | if (!match) return null |
| 79 | return { |
| 80 | r: Number.parseInt(match[1] ?? '0', 16), |
| 81 | g: Number.parseInt(match[2] ?? '0', 16), |
| 82 | b: Number.parseInt(match[3] ?? '0', 16), |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | function luminance(hex: string | undefined) { |
| 87 | const rgb = hexToRgb(hex) |