(color: string, opacity: number)
| 176 | } |
| 177 | |
| 178 | function changeColorAlpha(color: string, opacity: number) { |
| 179 | //if it has an alpha, remove it |
| 180 | if (color.length > 7) color = color.substring(0, color.length - 2); |
| 181 | |
| 182 | // coerce values so ti is between 0 and 1. |
| 183 | const _opacity = Math.round(Math.min(Math.max(opacity, 0), 1) * 255); |
| 184 | let opacityHex = _opacity.toString(16).toUpperCase(); |
| 185 | |
| 186 | // opacities near 0 need a trailing 0 |
| 187 | if (opacityHex.length == 1) opacityHex = "0" + opacityHex; |
| 188 | |
| 189 | return color + opacityHex; |
| 190 | } |
no test coverage detected