UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

106 lines 4.49 kB
import { Collection } from "@aurigma/design-atoms-model/Collection"; import { EventWithSenderArg } from "@aurigma/design-atoms-model/EventObject"; import { ProductParser } from "../Serialization/ProductParser"; var WatermarkHandler = /** @class */ (function () { function WatermarkHandler(watermarkConfig, service) { var _this = this; this._productParser = new ProductParser(); this._watermarkCollectionChangedEvent = new EventWithSenderArg(); this._watermarkContainers = new Collection(); this._onSurfacePropertyChanged = function (sender, propertyName) { switch (propertyName) { case "width": case "height": _this._updateWatermark(); break; } }; this._watermarkConfig = watermarkConfig; this._service = service; this._clearWatermarkContainer(); } Object.defineProperty(WatermarkHandler.prototype, "surface", { get: function () { return this._surface; }, set: function (value) { if (this._surface === value) return; if (this._surface != null) this.surface.removePropertyChanged(this._onSurfacePropertyChanged); this._surface = value; this._watermarkConfig = (this._surface != null && this._surface.parentProduct != null) ? this._surface.parentProduct.watermarkConfig : null; if (this._surface != null) this.surface.addPropertyChanged(this._onSurfacePropertyChanged); this._updateWatermark(); }, enumerable: true, configurable: true }); Object.defineProperty(WatermarkHandler.prototype, "watermarkConfig", { get: function () { return this._watermarkConfig; }, set: function (value) { if (this._watermarkConfig === value) return; this._watermarkConfig = value; this._updateWatermark(); }, enumerable: true, configurable: true }); Object.defineProperty(WatermarkHandler.prototype, "watermarkContainers", { get: function () { if (this._watermarkContainers == null) this._watermarkContainers = new Collection(); return this._watermarkContainers; }, enumerable: true, configurable: true }); WatermarkHandler.prototype._setWatermarkContainers = function (value) { this._watermarkContainers = value; this._watermarkCollectionChangedEvent.notify(this); }; WatermarkHandler.prototype.add_watermarkCollectionChanged = function (h) { this._watermarkCollectionChangedEvent.add(h); }; WatermarkHandler.prototype.remove_watermarkCollectionChanged = function (h) { this._watermarkCollectionChangedEvent.remove(h); }; WatermarkHandler.prototype._clearWatermarkContainer = function () { this._watermarkContainers = null; }; WatermarkHandler.prototype._updateWatermark = function () { this._clearWatermarkContainer(); if (this.surface == null || this.surface.width === 0 || this.surface.height === 0) return; if (this.watermarkConfig == null || this.watermarkConfig.visibility == null || this.watermarkConfig.visibility.canvas === false) return; this._requestWatermarkItems(); }; WatermarkHandler.prototype._requestWatermarkItems = function () { var _this = this; var id = Math.random(); this._requestWatermarkItemsId = id; this._service.getWatermarkItemsAsync(this.surface.width, this.surface.height, this._watermarkConfig) .then(function (container) { try { if (id !== _this._requestWatermarkItemsId) return; var containers = new Collection([_this._productParser.parseContainer(container)]); _this._setWatermarkContainers(containers); } catch (e) { throw e; } }) .catch(function (error) { console.error("Error while updating watermark items.", error); }); }; return WatermarkHandler; }()); export { WatermarkHandler }; //# sourceMappingURL=WatermarkHandler.js.map