(hex: string, opacity: number)
| 25 | // Calculate the HEX representation for a color as if |
| 26 | // it was rendered on a white background |
| 27 | export function reduceTranslucentColor(hex: string, opacity: number) { |
| 28 | const color = hexToRgb(hex); |
| 29 | const white = { r: 255, g: 255, b: 255 }; |
| 30 | |
| 31 | if (!color) { |
| 32 | return undefined; |
| 33 | } |
| 34 | |
| 35 | const reducedRgb = { |
| 36 | r: Math.round(opacity * color.r + (1 - opacity) * white.r), |
| 37 | g: Math.round(opacity * color.g + (1 - opacity) * white.g), |
| 38 | b: Math.round(opacity * color.b + (1 - opacity) * white.b), |
| 39 | }; |
| 40 | |
| 41 | return rgbToHex(reducedRgb); |
| 42 | } |
no test coverage detected