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.

403 lines 17.7 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 __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { ModelComponent } from "./ModelComponent"; import * as _ from "underscore"; import { Collection } from "../Collection"; import { RenderingType } from "./RenderingType"; import { ColorContainerVisualization, TextureContainerVisualization } from "./ContainerVisualization"; import { PrintingTechniqueConstraints } from "./Constraints/PrintingTechniqueConstraints"; var Container = /** @class */ (function (_super) { __extends(Container, _super); function Container(initialItems, name) { var _this = _super.call(this) || this; _this.type = Container.type; _this.parentComponent = null; _this._locked = false; _this._items = new Collection(); _this._visible = true; _this._region = null; _this._onItemAdded = function (_a) { var newItem = _a.item; newItem.parentContainer = _this; }; _this._onItemRemoved = function (_a) { var removedItem = _a.item; if (removedItem.parentContainer == _this) removedItem.parentContainer = null; }; _this._onRegionChanged = function (sender, propName) { if (propName !== "left" && propName !== "top" && propName !== "width" && propName !== "height") return; _this._propertyChanged.notify(_this, "region"); }; _this._items = new Collection(); _this._items.add_itemAdded(_this._onItemAdded); _this._items.add_itemRemoved(_this._onItemRemoved); if (initialItems != null) _this.items.setRange(initialItems); if (name != null) _this.name = name; return _this; } Object.defineProperty(Container.prototype, "renderingType", { get: function () { return RenderingType.Normal; }, enumerable: true, configurable: true }); Object.defineProperty(Container.prototype, "region", { get: function () { return this._region; }, set: function (value) { if (this._region === value) return; if (this._region != null) this._region.removePropertyChanged(this._onRegionChanged); this._region = value; this._propertyChanged.notify(this, "region"); if (this._region != null) this._region.addPropertyChanged(this._onRegionChanged); }, enumerable: true, configurable: true }); Object.defineProperty(Container.prototype, "items", { get: function () { return this._items; }, enumerable: true, configurable: true }); Object.defineProperty(Container.prototype, "visible", { get: function () { return this._visible; }, set: function (value) { if (this._visible === value) return; this._visible = value; this._propertyChanged.notify(this, "visible"); }, enumerable: true, configurable: true }); Object.defineProperty(Container.prototype, "locked", { get: function () { return this._locked; }, set: function (value) { if (this._locked === value) return; this._locked = value; this._propertyChanged.notify(this, "locked"); }, enumerable: true, configurable: true }); Container.prototype.getSimplifiedObject = function () { var simplified = _super.prototype.getSimplifiedObject.call(this, ["parentComponent", "version"]); simplified["version"] = this.version; return simplified; }; Container.prototype.generateNewIds = function () { this._generateNewId(); this._items.forEach(function (i) { return i.generateNewIds(); }); }; Container.prototype._copy = function (source, destination, generateNewIds) { _super.prototype._copy.call(this, source, destination, generateNewIds); destination.items.addRange(source.items.toArray().map(function (i) { return i.clone(generateNewIds); })); destination.locked = source.locked; destination.visible = source.visible; destination.translationKey = source.translationKey; destination.region = source.region != null ? source.region.clone() : null; }; Container.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new Container(); this._copy(this, container, generateNewIds); return container; }; Container.type = "Container"; return Container; }(ModelComponent)); export { Container }; var MockupContainer = /** @class */ (function (_super) { __extends(MockupContainer, _super); function MockupContainer(initialItems, name) { var _this = _super.call(this, initialItems, name) || this; _this.noPrint = false; _this.noShow = false; _this.size = null; _this._locked = true; return _this; } MockupContainer.prototype._copy = function (source, destination, generateNewIds) { _super.prototype._copy.call(this, source, destination, generateNewIds); destination.noPrint = source.noPrint; destination.noShow = source.noShow; destination.size = source.size != null ? source.size.clone() : null; }; MockupContainer.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new MockupContainer(); this._copy(this, container, generateNewIds); return container; }; return MockupContainer; }(Container)); export { MockupContainer }; var SurfaceContainer = /** @class */ (function (_super) { __extends(SurfaceContainer, _super); function SurfaceContainer(initialItems, name) { var _this = _super.call(this, initialItems, name) || this; _this.type = SurfaceContainer.type; _this._locked = false; _this.printingTechniqueConstraints = new PrintingTechniqueConstraints(); return _this; } SurfaceContainer.prototype._copy = function (source, destination, generateNewIds) { _super.prototype._copy.call(this, source, destination, generateNewIds); destination.printingTechniqueConstraints = source.printingTechniqueConstraints.clone(generateNewIds); }; SurfaceContainer.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new SurfaceContainer(); this._copy(this, container, generateNewIds); return container; }; SurfaceContainer.prototype.getSimplifiedObject = function () { var result = _super.prototype.getSimplifiedObject.call(this); return __assign(__assign({}, result), { printingTechniqueConstraints: this.printingTechniqueConstraints.toJSON() }); }; SurfaceContainer.type = "SurfaceContainer"; return SurfaceContainer; }(Container)); export { SurfaceContainer }; var ColorLessContainer = /** @class */ (function (_super) { __extends(ColorLessContainer, _super); function ColorLessContainer(initialItems, name) { var _this = _super.call(this, initialItems, name) || this; _this.type = ColorLessContainer.type; _this._locked = false; return _this; } Object.defineProperty(ColorLessContainer.prototype, "renderingType", { get: function () { if (this.visualization === null) return null; if (this.visualization instanceof TextureContainerVisualization) return RenderingType.Solid; if (this.visualization instanceof ColorContainerVisualization) return RenderingType.Grayscale; return null; }, enumerable: true, configurable: true }); ColorLessContainer.prototype._copy = function (source, destination, generateNewIds) { var _a, _b; _super.prototype._copy.call(this, source, destination, generateNewIds); destination.outputColor = (_a = source.outputColor) === null || _a === void 0 ? void 0 : _a.clone(); destination.opaque = source.opaque; destination.dpi = source.dpi; destination.visualization = (_b = source.visualization) === null || _b === void 0 ? void 0 : _b.clone(); }; ColorLessContainer.prototype.getSimplifiedObject = function () { var result = _super.prototype.getSimplifiedObject.call(this); return __assign(__assign({}, result), { outputColor: this.outputColor.getData(), opaque: this.opaque, dpi: this.dpi, visualization: this.visualization.toJSON() }); }; ColorLessContainer.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new ColorLessContainer(); this._copy(this, container, generateNewIds); return container; }; ColorLessContainer.type = "ColorLessContainer"; return ColorLessContainer; }(SurfaceContainer)); export { ColorLessContainer }; var LimitedColorContainer = /** @class */ (function (_super) { __extends(LimitedColorContainer, _super); function LimitedColorContainer(initialItems, name) { var _this = _super.call(this, initialItems, name) || this; _this.type = LimitedColorContainer.type; _this._locked = false; return _this; } Object.defineProperty(LimitedColorContainer.prototype, "renderingType", { get: function () { return RenderingType.Normal; }, enumerable: true, configurable: true }); LimitedColorContainer.prototype._copy = function (source, destination, generateNewIds) { _super.prototype._copy.call(this, source, destination, generateNewIds); destination.maxColorNumber = source.maxColorNumber; destination.paletteUId = source.paletteUId; }; LimitedColorContainer.prototype.getSimplifiedObject = function () { var result = _super.prototype.getSimplifiedObject.call(this); return __assign(__assign({}, result), { maxColorNumber: this.maxColorNumber, paletteUId: this.paletteUId }); }; LimitedColorContainer.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new LimitedColorContainer(); this._copy(this, container, generateNewIds); return container; }; LimitedColorContainer.type = "LimitedColorContainer"; return LimitedColorContainer; }(SurfaceContainer)); export { LimitedColorContainer }; var FullColorContainer = /** @class */ (function (_super) { __extends(FullColorContainer, _super); function FullColorContainer(initialItems, name) { var _this = _super.call(this, initialItems, name) || this; _this.type = FullColorContainer.type; _this._locked = false; return _this; } Object.defineProperty(FullColorContainer.prototype, "renderingType", { get: function () { return RenderingType.Normal; }, enumerable: true, configurable: true }); FullColorContainer.prototype._copy = function (source, destination, generateNewIds) { _super.prototype._copy.call(this, source, destination, generateNewIds); destination.colorSpace = source.colorSpace; destination.colorProfile = source.colorProfile; }; FullColorContainer.prototype.getSimplifiedObject = function () { var result = _super.prototype.getSimplifiedObject.call(this); return __assign(__assign({}, result), { colorSpace: this.colorSpace, colorProfile: this.colorProfile }); }; FullColorContainer.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new FullColorContainer(); this._copy(this, container, generateNewIds); return container; }; FullColorContainer.type = "FullColorContainer"; return FullColorContainer; }(SurfaceContainer)); export { FullColorContainer }; var SpotColorContainer = /** @class */ (function (_super) { __extends(SpotColorContainer, _super); function SpotColorContainer() { var _this = _super.call(this) || this; _this.type = SpotColorContainer.type; return _this; } Object.defineProperty(SpotColorContainer.prototype, "renderingType", { get: function () { return RenderingType.Grayscale; }, enumerable: true, configurable: true }); SpotColorContainer.prototype._copy = function (source, destination, generateNewIds) { var _a; _super.prototype._copy.call(this, source, destination, generateNewIds); destination.previewColor = source.previewColor; destination.outputColor = (_a = source.outputColor) === null || _a === void 0 ? void 0 : _a.clone(); }; SpotColorContainer.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new SpotColorContainer(); this._copy(this, container, generateNewIds); return container; }; SpotColorContainer.type = "SpotColorContainer"; return SpotColorContainer; }(SurfaceContainer)); export { SpotColorContainer }; var TextureContainer = /** @class */ (function (_super) { __extends(TextureContainer, _super); function TextureContainer() { var _this = _super.call(this) || this; _this.type = TextureContainer.type; return _this; } Object.defineProperty(TextureContainer.prototype, "renderingType", { get: function () { return RenderingType.Grayscale; }, enumerable: true, configurable: true }); Object.defineProperty(TextureContainer.prototype, "previewTextureSource", { get: function () { return this._previewTextureSource; }, set: function (previewTextureSource) { if (previewTextureSource !== this._previewTextureSource) { this._previewTextureSource = previewTextureSource; this._propertyChanged.notify(this, "previewTextureSource"); } }, enumerable: true, configurable: true }); TextureContainer.prototype._copy = function (source, destination, generateNewIds) { var _a; _super.prototype._copy.call(this, source, destination, generateNewIds); destination.previewTextureSource = source.previewTextureSource != null ? source.previewTextureSource.clone() : null; destination.previewTextureName = source.previewTextureName; destination.outputColor = (_a = source.outputColor) === null || _a === void 0 ? void 0 : _a.clone(); return destination; }; TextureContainer.prototype.clone = function (generateNewIds) { if (generateNewIds === void 0) { generateNewIds = false; } var container = new TextureContainer(); this._copy(this, container, generateNewIds); return container; }; TextureContainer.prototype.getSimplifiedObject = function (omitProperties) { if (!_.isArray(omitProperties) && !_.isString(omitProperties)) omitProperties = []; var simplified = _super.prototype.getSimplifiedObject.call(this); simplified["previewTextureSource"] = { "id": this.previewTextureSource.id, "width": this.previewTextureSource.width, "height": this.previewTextureSource.height, "isVector": this.previewTextureSource.isVector, "pageIndex": this.previewTextureSource.pageIndex, "url": this.previewTextureSource.url, "actualSize": this.previewTextureSource.actualSize, "saveAspectRatio": this.previewTextureSource.saveAspectRatio, "origin": this.previewTextureSource.origin, }; return simplified; }; TextureContainer.type = "TextureContainer"; return TextureContainer; }(SurfaceContainer)); export { TextureContainer }; //# sourceMappingURL=Container.js.map