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.

240 lines 11 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Item } from "./Item"; import { Path } from "../../Math/Path"; import { RectangleF } from "../../Math/RectangleF"; import { ShapePermissions } from "./ShapePermissions"; import { ResizeGripsPermissions } from "./ResizeGripsPermissions"; import { Color, RgbColor, RgbColors } from "../../Colors"; import { EventObject } from "../../EventObject"; import { ArgumentException } from "../../Exception"; import { equals } from "../../Utils/Utils"; import { Property } from "../Decorators/Property"; import { ShapeViolationSettings } from "./ShapeViolationSettings"; import { ColorPropertyFactory } from "../Decorators/Factory"; import { arraysIsEqual } from "@aurigma/utils-js/algorithms/array"; export class ShapeItem extends Item { constructor(sourcePath) { super(); this._borderWidth = 1; this._fillColor = new RgbColor(112, 112, 112, 255); this._borderColor = RgbColors.black; this._altBorderColor = null; this._dash = []; this._fixedBorderWidth = false; this._overprintStroke = false; this._overprintFill = false; this.sourcePathId = null; this.sourcePathLoaded = false; this._stubPath = null; this._pathLoadedEvent = new EventObject(); this.type = ShapeItem.type; this.sourcePath = sourcePath != null ? sourcePath : new Path(""); this.sourceRectangle = new RectangleF(0, 0, 10, 10); this.shapePermissions = new ShapePermissions(); this._setViolationSettings(new ShapeViolationSettings(), true); this._ignorePermissionsChange = true; this.manipulationPermissions.resizeGrips = new ResizeGripsPermissions(true, true); this.itemPermissions.itemToolbarPermissions.showEditButton = false; this.itemPermissions.itemToolbarPermissions.showSelectButton = false; this._ignorePermissionsChange = false; } get fixedBorderWidth() { return this._fixedBorderWidth; } set fixedBorderWidth(value) { if (this._fixedBorderWidth !== value) { this._fixedBorderWidth = value; this._propertyChanged.notify(this, "fixedBorderWidth"); } } get borderWidth() { return this._borderWidth; } set borderWidth(value) { if (this._borderWidth !== value) { this._borderWidth = value; this._propertyChanged.notify(this, "borderWidth"); } } get sourcePath() { return this._sourcePath; } set sourcePath(value) { if (equals(this._sourcePath, value)) return; this._sourcePath = value; if (this.sourcePathLoaded !== true) this._propertyChanged.notify(this, "sourcePath"); } get sourceRectangle() { return this._sourceRectangle; } set sourceRectangle(value) { if (RectangleF.isEqual(this._sourceRectangle, value)) return; this._sourceRectangle = value; this._propertyChanged.notify(this, "sourceRectangle"); } get borderColor() { return this._borderColor; } set borderColor(value) { if (!Color.equals(this._borderColor, value)) { this._borderColor = value; this._propertyChanged.notify(this, "borderColor"); } } get overprintStroke() { return this._overprintStroke; } set overprintStroke(value) { if (this._overprintStroke === value) return; this._overprintStroke = value; this._propertyChanged.notify(this, "overprintStroke"); } get fillColor() { return this._fillColor; } set fillColor(value) { if (!Color.equals(this._fillColor, value)) { this._fillColor = value; this._propertyChanged.notify(this, "fillColor"); } } get overprintFill() { return this._overprintFill; } set overprintFill(value) { if (this._overprintFill === value) return; this._overprintFill = value; this._propertyChanged.notify(this, "overprintFill"); } get altBorderColor() { return this._altBorderColor; } set altBorderColor(value) { if (!Color.equals(this._altBorderColor, value)) { this._altBorderColor = value; this._propertyChanged.notify(this, "altBorderColor"); } } get dash() { return this._dash; } set dash(value) { if (!arraysIsEqual(this._dash, value)) { this._dash = value; this._propertyChanged.notify(this, "dash"); } } applyPermissionsConstrain() { super.applyPermissionsConstrain(); this.itemPermissions.itemToolbarPermissions.showEditButtonConstraint = false; this.itemPermissions.itemToolbarPermissions.showSelectButtonConstraint = false; if (this.isRenderTypeIsNormal) return; this.shapePermissions.allowChangeBorderColor = false; this.shapePermissions.allowChangeFillColor = false; } get shapePermissions() { return this._shapePermissions; } set shapePermissions(value) { if (value == null) throw new ArgumentException("shapePermissions cannot be null"); if (equals(this._shapePermissions, value)) return; if (this._shapePermissions != null) this._shapePermissions.propertyChanged.remove(this._onPermissionsChanged); this._shapePermissions = value; this.applyPermissionsConstrain(); this._shapePermissions.propertyChanged.add(this._onPermissionsChanged); this._propertyChanged.notify(this, "shapePermissions"); } get violationSettings() { return this._violationSettings; } set violationSettings(value) { this._setViolationSettings(value); } _setViolationSettings(value, skipTypeCheck = false) { if (!skipTypeCheck && !(value instanceof ShapeViolationSettings)) throw new ArgumentException("Shape ViolationSettings property must has ShapeViolationSettings type!"); super._setViolationSettings(value, skipTypeCheck); } _copy(source, destination, generateNewIds, appropriateParentContainer) { super._copy(source, destination, generateNewIds, appropriateParentContainer); destination.shapePermissions = source._shapePermissions != null ? source._shapePermissions.clone() : null; destination._stubPath = source._stubPath != null ? source._stubPath.clone() : null; destination.dash = structuredClone(source._dash); destination.altBorderColor = source._altBorderColor != null ? source._altBorderColor.clone() : null; destination.fillColor = source._fillColor != null ? source._fillColor.clone() : null; destination.borderColor = source._borderColor != null ? source._borderColor.clone() : null; destination.sourceRectangle = source._sourceRectangle != null ? source._sourceRectangle.clone() : null; if (source.sourcePathId != null) { destination.sourcePathId = source.sourcePathId; } else { destination.sourcePath = source._sourcePath != null ? source._sourcePath.clone() : null; } destination.borderWidth = source._borderWidth; destination.fixedBorderWidth = source.fixedBorderWidth; destination.overprintStroke = source.overprintStroke; destination.overprintFill = source.overprintFill; } equals(other) { const superEquals = super.equals(other); const shapePermissionsEq = equals(this._shapePermissions, other._shapePermissions); const stubPathEq = equals(this._stubPath, other._stubPath); const dashEq = equals(this._dash, other._dash); const altBorderColorEq = equals(this._altBorderColor, other._altBorderColor); const fillColorEq = equals(this._fillColor, other._fillColor); const borderColorEq = equals(this._borderColor, other._borderColor); const sourceRectEq = equals(this._sourceRectangle, other._sourceRectangle); const sourcePathIdEq = equals(this.sourcePathId, other.sourcePathId); const sourcePathEq = equals(this._sourcePath, other._sourcePath); const borderWidthEq = equals(this._borderWidth, other._borderWidth); const fixedBorderWidthEq = equals(this._fixedBorderWidth, other._fixedBorderWidth); const overprintStrokeEq = equals(this._overprintStroke, other._overprintStroke); const overprintFillEq = equals(this._overprintFill, other._overprintFill); return superEquals && shapePermissionsEq && stubPathEq && dashEq && altBorderColorEq && fillColorEq && borderColorEq && sourceRectEq && sourcePathIdEq && sourcePathEq && borderWidthEq && fixedBorderWidthEq && overprintStrokeEq && overprintFillEq; } clone(generateNewIds = false, appropriateParentContainer = false) { const item = new ShapeItem(); this._copy(this, item, generateNewIds, appropriateParentContainer); return item; } getSimplifiedObject(omitProperties) { const simplified = super.getSimplifiedObject(["shapePermissions"].concat(omitProperties)); simplified["shapePermissions"] = this.shapePermissions.getSimplifiedObject(); if (this.sourcePathId == null) simplified["sourcePath"] = this.sourcePath != null ? this.sourcePath.toString() : null; else simplified["sourcePath"] = null; return simplified; } _onPathLoaded() { this._pathLoadedEvent.notify(this); } getPathLoadedEvent() { return this._pathLoadedEvent; } } ShapeItem.type = "ShapeItem"; __decorate([ Property({ factory: new ColorPropertyFactory(), displayName: "Alternative border color" }), __metadata("design:type", Color), __metadata("design:paramtypes", [Color]) ], ShapeItem.prototype, "altBorderColor", null); //# sourceMappingURL=ShapeItem.js.map