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.

90 lines 3.58 kB
import { ModelComponent } from "./ModelComponent"; import { Surface } from "./Surface"; import { Collection } from "../Collection"; import { PointF } from "../Math/index"; import { Palette } from "../Colors/Palette"; export class Product extends ModelComponent { constructor(surfaces = []) { super(); this.defaultDesignLocation = new PointF(); this._defaultSafetyLines = new Collection(); this._defaultCropMarks = new Collection(); this._surfaces = new Collection(); this._preferredFonts = []; this._onSurfacesAdd = ({ item: surface }) => { surface.parentProduct = this; }; this.surfaces.add_collectionChanged(this._onSurfacesAdd); this.surfaces.setRange(surfaces); this.palette = new Palette(); } get surfaces() { return this._surfaces; } set surfaces(value) { this.surfaces.setRange(value); } serialize(serializer, forServer) { return serializer.serialize(this, forServer); } get defaultSafetyLines() { return this._defaultSafetyLines; } set defaultSafetyLines(value) { if (this._defaultSafetyLines === value) return; this._defaultSafetyLines = value; this._propertyChanged.notify(this, "defaultSafetyLines"); } get defaultCropMarks() { return this._defaultCropMarks; } set defaultCropMarks(value) { if (this._defaultCropMarks === value) return; this._defaultCropMarks = value; this._propertyChanged.notify(this, "defaultCropMarks"); } get preferredFonts() { return this._preferredFonts; } set preferredFonts(value) { this._preferredFonts = value; this._propertyChanged.notify(this, "preferredFonts"); } _copy(source, destination, generateNewIds) { var _a; super._copy(source, destination, generateNewIds); destination.surfaces.addRange(source.surfaces.toArray().map(s => s.clone(generateNewIds))); destination.watermarkConfig = source.watermarkConfig != null ? source.watermarkConfig.clone() : null; destination.defaultCropMarks.addRange(source.defaultCropMarks.toArray().map(s => s.clone())); destination.defaultSafetyLines.addRange(source.defaultSafetyLines.toArray().map(s => s.clone())); destination.defaultDesignLocation = source.defaultDesignLocation.clone(); destination.palette.addRange(source.palette.select(x => x.clone(generateNewIds))); destination.preferredFonts = (_a = source.preferredFonts) === null || _a === void 0 ? void 0 : _a.slice(); } clone(generateNewIds = false) { const product = new Product(); this._copy(this, product, generateNewIds); return product; } getAllItems(options = { ignoreMockups: false }) { return Surface.getItems(this.surfaces, options); } generateNewIds() { this._generateNewId(); this._surfaces.forEach(i => i.generateNewIds()); } /** * Get surface by name or index. * @param key - Surface name or index. */ getSurface(key) { const surfaces = this.surfaces.toArray(); const surfaceIndex = parseInt(key); if (!Number.isNaN(surfaceIndex) && surfaceIndex >= 0 && surfaces.length > surfaceIndex) return surfaces[surfaceIndex]; return surfaces.find((s) => s.name === key); } } //# sourceMappingURL=Product.js.map