add a helper to make color opaque

This commit is contained in:
ivanwonder
2019-11-12 10:06:51 +08:00
parent 5bc80fdf67
commit fd868044fd
4 changed files with 37 additions and 13 deletions
+9
View File
@@ -51,3 +51,12 @@ export function toRgba(r: number, g: number, b: number, a: number = 0xFF): numbe
export function fromRgba(value: number): [number, number, number, number] {
return [(value >> 24) & 0xFF, (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF];
}
export function opaque(color: IColor): IColor {
const rgba = (color.rgba | 0xFF) >>> 0;
const [r, g, b] = fromRgba(rgba);
return {
css: toCss(r, g, b),
rgba
};
}