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.

656 lines 29.2 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 __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); }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import { ContentItem } from "./ContentItem"; import { ImagePermissions } from "./ImagePermissions"; import { ResizeGripsPermissions } from "./ResizeGripsPermissions"; import { RectangleF } from "../../Math/RectangleF"; import { ArgumentException, NotImplementedException, Exception } from "../../Exception"; import { EventWithSenderArg } from "../../EventObject"; import * as _ from "underscore"; import { ImageEffect } from "./ImageEffect"; import { pixelsToPoints } from "../../Utils/Convert"; import { OverlayEffect } from "./OverlayEffect"; import { equals, arrayEquals } from "../../Utils/Utils"; import { Size } from "./Size"; import { Property } from "../Decorators/Property"; import { BlendMode } from "./BlendMode"; import { CmykColor } from "../../Colors"; import { ImageViolationSettings } from "./ImageViolationSettings"; import { CollectionPropertyFactory, ObjectPropertyFactory, SimplePropertyFactory } from "../Decorators/Factory"; import { NDEffects } from "../Effects/NDEffects"; var ImageItem = /** @class */ (function (_super) { __extends(ImageItem, _super); function ImageItem(sourceStorageId, location, width, height, ratioWidthToHeight) { var _this = _super.call(this) || this; _this.ndEffects = new NDEffects(); _this._effect = ImageEffect.None; _this._overlayEffect = null; _this.type = ImageItem.type; _this.mviKeepTemplateTransform = false; _this.values = []; _this.allowedSubfolder = null; _this.allowedTabs = null; _this.ratioWidthToHeight = null; _this.isUserImage = false; _this.unconvertedSource = null; _this._onSourcePropertyChanged = function (sender, property) { switch (property) { case "url": case "id": case "pageIndex": _this._propertyChanged.notify(_this, "source"); break; case "isVector": _this.applyPermissionsConstrain(); _this._propertyChanged.notify(_this, "source"); break; default: } }; _this._onOverlayEffectPropertyChanged = function (s, p) { _this._propertyChanged.notify(_this, "overlayEffect"); }; _this.imagePermissions = new ImagePermissions(); _this._setViolationSettings(new ImageViolationSettings(), true); _this.manipulationPermissions.resizeGrips = new ResizeGripsPermissions(true, false); _this.shapePermissions.allowChangeFillColor = false; _this.imagePermissions.allowKeepOverlayColor = false; _this.itemPermissions.itemToolbarPermissions.showSelectButton = true; if (sourceStorageId != null) { _this.source = new ImageItem.ImageSource(sourceStorageId); } else { _this.source = new ImageItem.ImageSource(); } if (ratioWidthToHeight != null) _this.ratioWidthToHeight = ratioWidthToHeight; if (width != null && height != null) { _this.sourceRectangle = new RectangleF(0, 0, width, height); } else { if (width != null) _this.SetWidth(width); if (height != null) _this.SetHeight(height); } if (location != null) { _this.sourceRectangle.left = location.x; _this.sourceRectangle.top = location.y; } return _this; } ImageItem.prototype._copy = function (source, destination, generateNewIds, appropriateParentContainer) { var e_1, _a; var _b; _super.prototype._copy.call(this, source, destination, generateNewIds, appropriateParentContainer); destination.imagePermissions = source._imagePermissions != null ? source._imagePermissions.clone() : null; destination.effect = source._effect; destination.overlayEffect = source.overlayEffect != null ? source.overlayEffect.clone() : null; destination.source = source._source.clone(); destination.unconvertedSource = source.unconvertedSource != null ? source.unconvertedSource.clone() : null; destination.mviKeepTemplateTransform = source.mviKeepTemplateTransform; if (source.values != null) { destination.values = []; try { for (var _c = __values(source.values), _d = _c.next(); !_d.done; _d = _c.next()) { var i = _d.value; destination.values.push(i.clone()); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_d && !_d.done && (_a = _c.return)) _a.call(_c); } finally { if (e_1) throw e_1.error; } } } destination.originalImageSource = (_b = source.originalImageSource) === null || _b === void 0 ? void 0 : _b.clone(); destination.ndEffects = source.ndEffects.clone(); destination.allowedSubfolder = source.allowedSubfolder; destination.allowedTabs = _.clone(source.allowedTabs); destination.ratioWidthToHeight = source.ratioWidthToHeight; destination.isUserImage = source.isUserImage; }; ImageItem.prototype.equals = function (other) { return _super.prototype.equals.call(this, other) && equals(this._imagePermissions, other._imagePermissions) && equals(this._effect, other._effect) && equals(this.unconvertedSource, other.unconvertedSource) && equals(this._source, other._source) && equals(this.mviKeepTemplateTransform, other.mviKeepTemplateTransform) && equals(this.overlayEffect, other.overlayEffect) && arrayEquals(this.values, other.values) && equals(this.allowedSubfolder, other.allowedSubfolder) && arrayEquals(this.allowedTabs, other.allowedTabs) && equals(this.ratioWidthToHeight, other.ratioWidthToHeight) && equals(this.isUserImage, other.isUserImage) && equals(this.originalImageSource, other.originalImageSource) && equals(this.ndEffects, other.ndEffects); }; ImageItem.prototype.clone = function (generateNewIds, appropriateParentContainer) { if (generateNewIds === void 0) { generateNewIds = false; } if (appropriateParentContainer === void 0) { appropriateParentContainer = false; } var item = new ImageItem(); this._copy(this, item, generateNewIds, appropriateParentContainer); return item; }; Object.defineProperty(ImageItem.prototype, "imagePermissions", { get: function () { return this._imagePermissions; }, set: function (value) { if (value == null) throw new ArgumentException("imagePermissions cannot be null"); if (equals(this._imagePermissions, value)) return; if (this._imagePermissions != null) this._imagePermissions.propertyChanged.remove(this._onPermissionsChanged); this._imagePermissions = value; this.applyPermissionsConstrain(); this._imagePermissions.propertyChanged.add(this._onPermissionsChanged); this._propertyChanged.notify(this, "imagePermissions"); }, enumerable: true, configurable: true }); Object.defineProperty(ImageItem.prototype, "violationSettings", { get: function () { return this._violationSettings; }, set: function (value) { this._setViolationSettings(value); }, enumerable: true, configurable: true }); ImageItem.prototype._setViolationSettings = function (value, skipTypeCheck) { if (skipTypeCheck === void 0) { skipTypeCheck = false; } if (!skipTypeCheck && !(value instanceof ImageViolationSettings)) throw new ArgumentException("Shape ViolationSettings property must has ImageViolationSettings type!"); _super.prototype._setViolationSettings.call(this, value, skipTypeCheck); }; ImageItem.prototype.applyPermissionsConstrain = function () { _super.prototype.applyPermissionsConstrain.call(this); if (this.imagePermissions != null && !this.imagePermissions.allowEditImage) this.itemPermissions.itemToolbarPermissions.showEditButtonConstraint = false; else if (this.source != null && this.source.isVector) this.itemPermissions.itemToolbarPermissions.showEditButtonConstraint = false; else this.itemPermissions.itemToolbarPermissions.showEditButtonConstraint = null; if (this.imagePermissions != null && !this.imagePermissions.allowChangeImage) this.itemPermissions.itemToolbarPermissions.showSelectButtonConstraint = false; else this.itemPermissions.itemToolbarPermissions.showSelectButtonConstraint = null; }; Object.defineProperty(ImageItem.prototype, "displayName", { get: function () { var _this = this; if (this._displayName == null && this.values != null && this.values.length > 0) { var selectedValue = this.values.find(function (imageItemValue) { return imageItemValue.value.id === _this.source.id; }); if (selectedValue != null) this.displayName = selectedValue.name; } return this._displayName; }, set: function (value) { if (value != this._displayName) this._displayName = value; }, enumerable: true, configurable: true }); Object.defineProperty(ImageItem.prototype, "source", { get: function () { return this._source; }, set: function (value) { if (this._source === value || this._source != null && this._source.equals(value)) return; if (this._source != null) this._source.removePropertyChanged(this._onSourcePropertyChanged); this._source = value; if (this._source != null) this._source.addPropertyChanged(this._onSourcePropertyChanged); this._propertyChanged.notify(this, "source"); }, enumerable: true, configurable: true }); Object.defineProperty(ImageItem.prototype, "effect", { get: function () { return this._effect; }, set: function (value) { if (this._effect !== value) { this._effect = value; this._propertyChanged.notify(this, "effect"); } }, enumerable: true, configurable: true }); Object.defineProperty(ImageItem.prototype, "overlayEffect", { get: function () { return this._overlayEffect; }, set: function (value) { if (OverlayEffect.equals(this.overlayEffect, value)) return; this._unsubscribeOverlayEffectPropertyChanged(); this._overlayEffect = value; this._subscribeOverlayEffectPropertyChanged(); this._propertyChanged.notify(this, "overlayEffect"); }, enumerable: true, configurable: true }); ImageItem.prototype._subscribeOverlayEffectPropertyChanged = function () { if (this.overlayEffect != null) this.overlayEffect.addPropertyChanged(this._onOverlayEffectPropertyChanged); }; ImageItem.prototype._unsubscribeOverlayEffectPropertyChanged = function () { if (this.overlayEffect != null) this.overlayEffect.removePropertyChanged(this._onOverlayEffectPropertyChanged); }; ImageItem.prototype.SetWidth = function (value, calculateHeight) { this.sourceRectangle.width = value; if (calculateHeight != null) calculateHeight = true; if (this.source.id != null && calculateHeight) this.sourceRectangle.height = this._calculateHeight(value); }; ImageItem.prototype.SetHeight = function (value, calculateWidth) { this.sourceRectangle.height = value; if (calculateWidth != null) calculateWidth = true; if (this.source.id != null && calculateWidth) this.sourceRectangle.width = this._calculateWidth(value); }; ImageItem.prototype.getSource = function () { throw new NotImplementedException(); }; ImageItem.prototype._calculateHeight = function (width) { if (this.ratioWidthToHeight == null) throw new Exception("Field ratioWidthToHeight is not set!"); return width / this.ratioWidthToHeight; }; ImageItem.prototype._calculateWidth = function (height) { if (this.ratioWidthToHeight == null) throw new Exception("Field ratioWidthToHeight is not set!"); return height * this.ratioWidthToHeight; }; ImageItem.prototype.getSimplifiedObject = function (omitProperties) { var _a, _b; if (!_.isArray(omitProperties) && !_.isString(omitProperties)) omitProperties = []; var simplified = _super.prototype.getSimplifiedObject.call(this, ["imagePermissions"].concat(omitProperties)); simplified["source"] = this.source.toJSON(); simplified["originalImageSource"] = (_a = this.originalImageSource) === null || _a === void 0 ? void 0 : _a.toJSON(); simplified["unconvertedSource"] = (_b = this.unconvertedSource) === null || _b === void 0 ? void 0 : _b.toJSON(); simplified["ndEffects"] = this.ndEffects.toJSON(); simplified["imagePermissions"] = this.imagePermissions.getSimplifiedObject(); return simplified; }; ImageItem.prototype.getOriginalImageSize = function () { return { width: pixelsToPoints(this.source.width, this.source.dpiX || 72), height: pixelsToPoints(this.source.height, this.source.dpiY || 72) }; }; ImageItem.type = "ImageItem"; __decorate([ Property({ factory: new SimplePropertyFactory("subfolder"), displayName: "Allowed subfolder" }), __metadata("design:type", String) ], ImageItem.prototype, "allowedSubfolder", void 0); __decorate([ Property({ factory: new CollectionPropertyFactory(Array), displayName: "Allowed tabs", }), __metadata("design:type", Array) ], ImageItem.prototype, "allowedTabs", void 0); __decorate([ Property({ factory: new SimplePropertyFactory("Image"), displayName: "Display name" }), __metadata("design:type", Object), __metadata("design:paramtypes", [Object]) ], ImageItem.prototype, "displayName", null); __decorate([ Property({ ignore: true }), __metadata("design:type", ImageItem.ImageSource) ], ImageItem.prototype, "unconvertedSource", void 0); __decorate([ Property({ enumObject: ImageEffect }), __metadata("design:type", Number), __metadata("design:paramtypes", [Number]) ], ImageItem.prototype, "effect", null); __decorate([ Property({ factory: new ObjectPropertyFactory(OverlayEffect, { color: new CmykColor(0, 0, 0, 0, 255), opacity: 1, blendMode: BlendMode.Normal }), displayName: "Overlay effect" }), __metadata("design:type", OverlayEffect), __metadata("design:paramtypes", [OverlayEffect]) ], ImageItem.prototype, "overlayEffect", null); return ImageItem; }(ContentItem)); export { ImageItem }; (function (ImageItem) { var ImageMetaData = /** @class */ (function () { function ImageMetaData(rawData) { _.extend(this, rawData); } ImageMetaData.prototype.clone = function () { return new ImageMetaData(this); }; ImageMetaData.prototype.equals = function (other) { return other != null && equals(this.id, other.id) && equals(this.width, other.width) && equals(this.height, other.height) && equals(this.isVector, other.isVector); }; return ImageMetaData; }()); ImageItem.ImageMetaData = ImageMetaData; var ImageItemValue = /** @class */ (function () { function ImageItemValue(name, value, transformedRectangle) { this.name = name; this.value = value; this.transformedRectangle = transformedRectangle; } ImageItemValue.prototype.clone = function () { return new ImageItemValue(this.name, this.value.clone(), this.transformedRectangle.clone()); }; ImageItemValue.prototype.equals = function (other) { return other != null && equals(this.name, other.name) && equals(this.value, other.value) && equals(this.transformedRectangle, other.transformedRectangle); }; return ImageItemValue; }()); ImageItem.ImageItemValue = ImageItemValue; var ImageSourceType; (function (ImageSourceType) { ImageSourceType[ImageSourceType["None"] = 0] = "None"; ImageSourceType[ImageSourceType["StorageId"] = 3] = "StorageId"; ImageSourceType[ImageSourceType["Url"] = 4] = "Url"; })(ImageSourceType = ImageItem.ImageSourceType || (ImageItem.ImageSourceType = {})); var ImageSource = /** @class */ (function () { function ImageSource(storageId, url, sourcePageIndex, actualSize, saveAspectRatio, origin) { if (sourcePageIndex === void 0) { sourcePageIndex = 0; } if (actualSize === void 0) { actualSize = false; } if (saveAspectRatio === void 0) { saveAspectRatio = true; } this._storageId = null; this._url = null; this._type = ImageSourceType.None; this._isVector = false; this._pageIndex = 0; this._origin = null; this._actualSize = false; this._saveAspectRatio = true; this._dpiX = 72; this._dpiY = 72; this._propertyChanged = new EventWithSenderArg(); this._storageId = storageId; if (storageId != null) { this._type = ImageSourceType.StorageId; this._origin = origin; } this._url = url; if (url != null) { this._type = ImageSourceType.Url; this._actualSize = actualSize; this._saveAspectRatio = saveAspectRatio; } } ImageSource.prototype.clone = function () { var clonedItem = new ImageSource(); clonedItem.id = this.id; clonedItem.url = this.url; clonedItem._type = this._type; clonedItem._width = this._width; clonedItem._height = this._height; clonedItem._isVector = this._isVector; clonedItem._pageIndex = this._pageIndex; clonedItem._origin = this._origin != null ? this._origin.clone() : null; clonedItem._actualSize = this._actualSize; clonedItem._saveAspectRatio = this._saveAspectRatio; clonedItem._dpiX = this._dpiX; clonedItem._dpiY = this._dpiY; return clonedItem; }; ImageSource.prototype.equals = function (other) { return equals(this.id, other.id) && equals(this.url, other.url) && equals(this._type, other._type) && equals(this._width, other._width) && equals(this._height, other._height) && equals(this._origin, other._origin) && equals(this._saveAspectRatio, other._saveAspectRatio) && other._pageIndex === this._pageIndex && JSON.stringify(other._origin) === JSON.stringify(this._origin) && other._actualSize === this._actualSize && other._saveAspectRatio === this._saveAspectRatio; }; Object.defineProperty(ImageSource.prototype, "id", { get: function () { return this._storageId; }, set: function (value) { if (this._storageId === value) return; this._storageId = value; this._propertyChanged.notify(this, "id"); }, enumerable: true, configurable: true }); ImageSource.prototype.setIdWithOrigin = function (id, origin) { this.id = id; this._setOrigin(origin); }; Object.defineProperty(ImageSource.prototype, "url", { get: function () { return this._url; }, set: function (value) { if (this._url === value) return; this._url = value; this._propertyChanged.notify(this, "url"); }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "width", { get: function () { return this._width; }, set: function (value) { if (this._width === value) return; this._width = value; this._propertyChanged.notify(this, "width"); }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "height", { get: function () { return this._height; }, set: function (value) { if (this._height === value) return; this._height = value; this._propertyChanged.notify(this, "height"); }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "isVector", { get: function () { return this._isVector; }, set: function (value) { if (this._isVector === value) return; this._isVector = value; this._propertyChanged.notify(this, "isVector"); }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "pageIndex", { get: function () { return this._pageIndex; }, set: function (value) { if (value === this._pageIndex) return; this._pageIndex = value; this._propertyChanged.notify(this, "pageIndex"); }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "origin", { get: function () { return this._origin; }, enumerable: true, configurable: true }); ImageSource.prototype._setOrigin = function (value) { if (value === this._origin) return; this._origin = value; this._propertyChanged.notify(this, "origin"); }; Object.defineProperty(ImageSource.prototype, "type", { get: function () { return this._type; }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "actualSize", { get: function () { return this._actualSize; }, set: function (value) { this._actualSize = value; }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "saveAspectRatio", { get: function () { return this._saveAspectRatio; }, set: function (value) { this._saveAspectRatio = value; }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "dpiX", { get: function () { return this._dpiX; }, set: function (dpi) { if (dpi > 0) this._dpiX = dpi; }, enumerable: true, configurable: true }); Object.defineProperty(ImageSource.prototype, "dpiY", { get: function () { return this._dpiY; }, set: function (dpi) { if (dpi > 0) this._dpiY = dpi; }, enumerable: true, configurable: true }); ImageSource.prototype.addPropertyChanged = function (listener) { this._propertyChanged.add(listener); }; ImageSource.prototype.removePropertyChanged = function (listener) { this._propertyChanged.remove(listener); }; ImageSource.prototype.toJSON = function () { return { "id": this.id, "width": this.width, "height": this.height, "isVector": this.isVector, "pageIndex": this.pageIndex, "url": this.url, "actualSize": this.actualSize, "saveAspectRatio": this.saveAspectRatio, "origin": this.origin }; }; return ImageSource; }()); ImageItem.ImageSource = ImageSource; (function (ImageSource) { var Origin = /** @class */ (function () { function Origin(rawData) { _.extend(this, rawData || {}); if (rawData != null && rawData["originalSize"] != null) this.originalSize = new Size(rawData["originalSize"]["width"], rawData["originalSize"]["height"]); } Origin.prototype.equals = function (other) { return other == null && equals(this.type, other.type) && equals(this.data, other.data) && equals(this.originalSize, other.originalSize); }; Origin.prototype.clone = function () { return new Origin(this); }; return Origin; }()); ImageSource.Origin = Origin; })(ImageSource = ImageItem.ImageSource || (ImageItem.ImageSource = {})); })(ImageItem || (ImageItem = {})); //# sourceMappingURL=ImageItem.js.map