UNPKG

@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.

111 lines 4.24 kB
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"; import { Utils } from "./Utils"; var LabColor = /** @class */ (function (_super) { __extends(LabColor, _super); function LabColor(value) { var _this = _super.call(this, value) || this; _this.l = 0; _this.a = -128; _this.b = -128; _this.alpha = 0; if (value == null) return _this; var incorrectLabColorMessage = "Incorrect LabColor format: " + JSON.stringify(value); if (typeof value == "string") { if (!_this._tryInitFromString(value)) console.warn(incorrectLabColorMessage); else _this._previewFromServer = Utils.isValidRgbColor(_this.preview); } else { try { _this._init(value); } catch (e) { console.warn(incorrectLabColorMessage); } } return _this; } Object.defineProperty(LabColor.prototype, "type", { get: function () { return "LabColor"; }, enumerable: true, configurable: true }); LabColor.prototype._tryInitFromString = function (value) { LabColor._lab.lastIndex = 0; var match = LabColor._lab.exec(value); if (match != null && match.length === 8) { this._init({ l: +match[1], a: +match[2], b: +match[3], alpha: match[5] != null ? Utils.convertPercentToByte(match[5]) : 255, preview: match[7] != null ? match[7] : null }); return true; } return false; }; LabColor.prototype.clone = function () { return new LabColor(this); }; LabColor.prototype.equals = function (color) { if (color instanceof LabColor) { var baseEquals = _super.prototype.equals.call(this, color); return baseEquals && color instanceof LabColor && this.l === color.l && this.a === color.a && this.b === color.b && this.alpha === color.alpha; } return false; }; LabColor.prototype.toString = function () { var result = "lab(" + this.l + "," + this.a + "," + this.b + "," + Utils.convertByteToPercent(this.alpha); if (this.preview != null) result += "," + this.preview; result += ")"; return result; }; LabColor.prototype.getData = function () { var data = _super.prototype.getData.call(this); data.l = this.l; data.a = this.a; data.b = this.b; data.alpha = this.alpha; return data; }; LabColor.prototype._getPreview = function () { return this.preview; }; LabColor.prototype._init = function (colorObject) { _super.prototype._init.call(this, colorObject); colorObject.alpha = colorObject.alpha != null ? colorObject.alpha : 255; this._validateNumber(colorObject.l); this._validateNumber(colorObject.a, -128, 127); this._validateNumber(colorObject.b, -128, 127); this._validateNumber(colorObject.alpha); this.l = colorObject.l; this.a = colorObject.a; this.b = colorObject.b; this.alpha = colorObject.alpha; }; LabColor._lab = /^\s*lab\(\s*(\d{1,3})\s*,\s*(-*\d{1,3})\s*,\s*(-*\d{1,3})\s*(,\s*(\d{1,3})%)?\s*(\,\s*(.*)\s*)?\)\s*;{0,1}\s*$/g; return LabColor; }(Color)); export { LabColor }; //# sourceMappingURL=LabColor.js.map