(foregroundColor: string, backgroundColor = '#FFFFFF')
| 25 | const COLOR_LEVEL_ALPHA = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1]; |
| 26 | |
| 27 | const rgba2hex = (foregroundColor: string, backgroundColor = '#FFFFFF') => { |
| 28 | const getAdjustedChannel = (fValue: number, bValue: number, opacity: number) => opacity * fValue + (1 - opacity) * bValue; |
| 29 | const fc = Color(foregroundColor); |
| 30 | const bc = Color(backgroundColor); |
| 31 | const opacity = fc.alpha(); |
| 32 | const adjustedColor = Color([ |
| 33 | getAdjustedChannel(fc.red(), bc.red(), opacity), |
| 34 | getAdjustedChannel(fc.green(), bc.green(), opacity), |
| 35 | getAdjustedChannel(fc.blue(), bc.blue(), opacity), |
| 36 | ]); |
| 37 | return adjustedColor.hex(); |
| 38 | }; |
| 39 | |
| 40 | export const getColorValue = (color: string, alpha: number) => { |
| 41 | return rgba2hex(Color(color).alpha(alpha).string()); |
no test coverage detected