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.

112 lines 4.87 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"; import { ColorFactory } from "./ColorFactory"; var SpotColor = /** @class */ (function (_super) { __extends(SpotColor, _super); function SpotColor(value) { var _this = _super.call(this, value) || this; if (value == null) return _this; var incorrectSpotColorMessage = "Incorrect SpotColor format: " + JSON.stringify(value); if (typeof value == "string") { if (!_this._tryInitFromString(value)) console.warn(incorrectSpotColorMessage); else _this._previewFromServer = Utils.isValidRgbColor(_this.preview); } else { try { _this._init(value); } catch (e) { console.warn(incorrectSpotColorMessage); } } return _this; } Object.defineProperty(SpotColor.prototype, "type", { get: function () { return "SpotColor"; }, enumerable: true, configurable: true }); SpotColor.prototype._tryInitFromString = function (value) { SpotColor._spot.lastIndex = 0; var match = SpotColor._spot.exec(value); if (match != null && match.length === 10) { this._init({ inkName: match[1].replace(/'/g, "").replace(/\"/g, ""), inkColor: ColorFactory.createColor(match[2]), inkSolidity: match[4] != null ? +match[4] : 1, tint: match[7] != null ? Utils.convertPercentToByte(match[7]) : 255, preview: match[9] != null ? match[9] : null }); return true; } return false; }; SpotColor.prototype.toString = function () { var inkColorWithoutPreview = this.inkColor.clone(); inkColorWithoutPreview.preview = null; return "spot('" + this.inkName + "'," + inkColorWithoutPreview.toString() + "," + this.inkSolidity + "," + Utils.convertByteToPercent(this.tint) + "," + this.preview + ")"; }; SpotColor.prototype.clone = function () { return new SpotColor(this); }; SpotColor.prototype.equals = function (color) { if (color instanceof SpotColor) { var baseEquals = _super.prototype.equals.call(this, color); return baseEquals && color instanceof SpotColor && this.inkName === color.inkName && this.inkColor.equals(color.inkColor) && this.inkSolidity === color.inkSolidity && this.alpha === color.alpha && this.tint === color.tint; } return false; }; SpotColor.prototype.getData = function () { var data = _super.prototype.getData.call(this); data.inkName = this.inkName; data.inkColor = this.inkColor.getData(); data.inkSolidity = this.inkSolidity; data.alpha = this.alpha; data.tint = this.tint; return data; }; SpotColor.prototype._getPreview = function () { return this.preview; }; SpotColor.prototype._init = function (colorObject) { _super.prototype._init.call(this, colorObject); colorObject.alpha = colorObject.alpha != null ? colorObject.alpha : 255; colorObject.tint = colorObject.tint != null ? colorObject.tint : 255; var inkColor = ColorFactory.createColor(colorObject.inkColor, true); this._validateString(colorObject.inkName); this._validateNumber(colorObject.inkSolidity, 0, 1); this._validateNumber(colorObject.alpha); this._validateNumber(colorObject.tint); this.inkName = colorObject.inkName; this.inkColor = inkColor; this.inkSolidity = colorObject.inkSolidity; this.alpha = colorObject.alpha; this.tint = colorObject.tint; }; SpotColor._spot = /^\s*spot\(\s*([^()]*)\s*,\s*(.{3,4}\([^()]*\))\s*(,\s*(\d{1}(\.\d{1,})?))?\s*(,\s*(\d{1,3})%)?\s*(,\s*(.*)\s*)?\)\s*;{0,1}\s*$/g; return SpotColor; }(Color)); export { SpotColor }; ColorFactory.registerColor("SpotColor", "spot", SpotColor); //# sourceMappingURL=SpotColor.js.map