@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.
128 lines • 5.5 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 { ModelComponent } from "./ModelComponent";
import { Surface } from "./Surface";
import * as _ from "underscore";
import { Collection } from "../Collection";
import { PointF } from "../Math/index";
import { Palette } from "../Colors/Palette";
var Product = /** @class */ (function (_super) {
__extends(Product, _super);
function Product(surfaces) {
if (surfaces === void 0) { surfaces = []; }
var _this = _super.call(this) || this;
_this.defaultDesignLocation = new PointF();
_this._defaultSafetyLines = new Collection();
_this._defaultCropMarks = new Collection();
_this._surfaces = new Collection();
_this._preferredFonts = [];
_this._onSurfacesAdd = function (_a) {
var surface = _a.item;
surface.parentProduct = _this;
};
_this.surfaces.add_collectionChanged(_this._onSurfacesAdd);
_this.surfaces.setRange(surfaces);
_this.palette = new Palette();
return _this;
}
Object.defineProperty(Product.prototype, "surfaces", {
get: function () {
return this._surfaces;
},
set: function (value) {
this.surfaces.setRange(value);
},
enumerable: true,
configurable: true
});
Product.prototype.serialize = function (serializer, forServer) {
return serializer.serialize(this, forServer);
};
Object.defineProperty(Product.prototype, "defaultSafetyLines", {
get: function () {
return this._defaultSafetyLines;
},
set: function (value) {
if (this._defaultSafetyLines === value)
return;
this._defaultSafetyLines = value;
this._propertyChanged.notify(this, "defaultSafetyLines");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Product.prototype, "defaultCropMarks", {
get: function () {
return this._defaultCropMarks;
},
set: function (value) {
if (this._defaultCropMarks === value)
return;
this._defaultCropMarks = value;
this._propertyChanged.notify(this, "defaultCropMarks");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Product.prototype, "preferredFonts", {
get: function () {
return this._preferredFonts;
},
set: function (value) {
this._preferredFonts = value;
this._propertyChanged.notify(this, "preferredFonts");
},
enumerable: true,
configurable: true
});
Product.prototype._copy = function (source, destination, generateNewIds) {
var _a;
_super.prototype._copy.call(this, source, destination, generateNewIds);
destination.surfaces.addRange(source.surfaces.toArray().map(function (s) { return s.clone(generateNewIds); }));
destination.watermarkConfig = source.watermarkConfig != null ? source.watermarkConfig.clone() : null;
destination.defaultCropMarks.addRange(source.defaultCropMarks.toArray().map(function (s) { return s.clone(); }));
destination.defaultSafetyLines.addRange(source.defaultSafetyLines.toArray().map(function (s) { return s.clone(); }));
destination.defaultDesignLocation = source.defaultDesignLocation.clone();
destination.palette.addRange(source.palette.select(function (x) { return x.clone(generateNewIds); }));
destination.preferredFonts = (_a = source.preferredFonts) === null || _a === void 0 ? void 0 : _a.slice();
};
Product.prototype.clone = function (generateNewIds) {
if (generateNewIds === void 0) { generateNewIds = false; }
var product = new Product();
this._copy(this, product, generateNewIds);
return product;
};
Product.prototype.getAllItems = function (options) {
if (options === void 0) { options = { ignoreMockups: false }; }
return Surface.getItems(this.surfaces, options);
};
Product.prototype.generateNewIds = function () {
this._generateNewId();
this._surfaces.forEach(function (i) { return i.generateNewIds(); });
};
/**
* Get surface by name or index.
* @param key - Surface name or index.
*/
Product.prototype.getSurface = function (key) {
var surfaces = this.surfaces.toArray();
var surfaceIndex = parseInt(key);
if (!Number.isNaN(surfaceIndex) && surfaceIndex >= 0 && surfaces.length > surfaceIndex)
return surfaces[surfaceIndex];
return _.find(surfaces, function (s) { return s.name === key; });
};
return Product;
}(ModelComponent));
export { Product };
//# sourceMappingURL=Product.js.map