@aurigma/design-atoms-model
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
46 lines • 1.35 kB
JavaScript
import { ColorSpace } from "./ColorSpace";
import { ProcessColor } from "./ProcessColor";
import { validateComponent } from "./ValidationUtils";
export class RgbColor extends ProcessColor {
constructor(r, g, b, alpha, profile = null) {
super(alpha, profile);
this._colorSpace = ColorSpace.Rgb;
this._r = validateComponent(r);
this._g = validateComponent(g);
this._b = validateComponent(b);
}
get r() {
return this._r;
}
get g() {
return this._g;
}
get b() {
return this._b;
}
equals(other) {
const rgbOther = other;
return super.equals(other)
&& this.r === rgbOther.r
&& this.g === rgbOther.g
&& this.b === rgbOther.b;
}
clone() {
return new RgbColor(this.r, this.g, this.b, this.alpha, this.profile);
}
getData() {
const data = super.getData();
data.r = this.r;
data.g = this.g;
data.b = this.b;
return data;
}
toString() {
if (this.alpha === 255) {
return `rgb(${this.r},${this.g},${this.b})`;
}
const a = (this.alpha / 255).toFixed(7);
return `rgba(${this.r},${this.g},${this.b},${a})`;
}
}
//# sourceMappingURL=RgbColor.js.map