@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.
82 lines • 3.1 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Color } from "./Color";
var GrayscaleColor = /** @class */ (function (_super) {
__extends(GrayscaleColor, _super);
function GrayscaleColor(value) {
var _this = _super.call(this, value) || this;
_this.l = 0;
_this.a = 255;
if (value == null)
return _this;
try {
_this._init(value);
}
catch (e) {
console.warn("Incorrect GrayscaleColor format: " + JSON.stringify(value));
}
return _this;
}
Object.defineProperty(GrayscaleColor.prototype, "type", {
get: function () { return "GrayscaleColor"; },
enumerable: true,
configurable: true
});
Object.defineProperty(GrayscaleColor.prototype, "alpha", {
get: function () { return this.a; },
enumerable: true,
configurable: true
});
GrayscaleColor.prototype.clone = function () {
return new GrayscaleColor(this);
};
GrayscaleColor.prototype.equals = function (color) {
if (color instanceof GrayscaleColor) {
var baseEquals = _super.prototype.equals.call(this, color);
return baseEquals && color instanceof GrayscaleColor && this.l === color.l && this.a === color.a;
}
return false;
};
GrayscaleColor.prototype.toString = function () {
return this._getPreview();
};
GrayscaleColor.prototype.getData = function () {
var data = _super.prototype.getData.call(this);
data.l = this.l;
data.a = this.a;
return data;
};
GrayscaleColor.prototype._getPreview = function () {
if (this.a === 255) {
return "rgb(" + this.l + "," + this.l + "," + this.l + ")";
}
else {
var a = (this.a / 255).toFixed(7);
return "rgba(" + this.l + "," + this.l + "," + this.l + "," + a + ")";
}
};
GrayscaleColor.prototype._init = function (colorObject) {
_super.prototype._init.call(this, colorObject);
colorObject.a = colorObject.a != null ? colorObject.a : 255;
this._validateNumber(colorObject.l);
this._validateNumber(colorObject.a);
this.l = colorObject.l;
this.a = colorObject.a;
if (this.preview == null)
this.preview = this._getPreview();
};
return GrayscaleColor;
}(Color));
export { GrayscaleColor };
//# sourceMappingURL=GrayscaleColor.js.map