import Color from "color"; export class PlainColor { public readonly h: number; public readonly s: number; public readonly v: number; public readonly r: number; public readonly g: number; public readonly b: number; public readonly a: number; public readonly hex: string; public readonly hexa: string; public readonly rgb: string; public readonly rgba: string; public readonly value: string; constructor( param: string | Color | { r: number, g: number, b: number } | { r: number, g: number, b: number, alpha: number } | { h: number, s: number, v: number } | { h: number, s: number, v: number, alpha: number } ) { const color = Color(param); this.hex = color.hex(); this.hexa = color.hexa(); const { color: [h, s, v], valpha } = color.hsv() as any; const { color: [r, g, b] } = color.rgb() as any; this.h = h; this.s = s; this.v = v; this.r = Number(r.toFixed(0)); this.g = Number(g.toFixed(0)); this.b = Number(b.toFixed(0)); this.a = Number(valpha.toFixed(2)); this.rgb = `rgb(${this.r},${this.g},${this.b})`; this.rgba = `rgb(${this.r},${this.g},${this.b},${this.a})`; this.value = typeof param === "string" ? param : (this.a === 1 ? this.hex : this.rgba); } useHsva({ h, s, v, a }: { h?: number, s?: number, v?: number, a?: number }) { return new PlainColor({ h: Number(h == null ? this.h : h), s: Number(s == null ? this.s : s), v: Number(v == null ? this.v : v), alpha: Number(a == null ? this.a : a), }); } useRgba({ r, g, b, a }: { r?: number, g?: number, b?: number, a?: number }) { return new PlainColor({ r: Number(r == null ? this.r : r), g: Number(g == null ? this.g : g), b: Number(b == null ? this.b : b), alpha: Number(a == null ? this.a : a), }); } }