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.

738 lines 100 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; 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."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; import { PlainTextItem, BoundedTextItem, PathBoundedTextItem, TextVerticalAlignment, OverflowStrategy, ShrinkMode, LineItem, ImageItem, ShapeItem, RectangleItem, EllipseItem, BarcodeItem, BarcodeData, BarcodeFormat, BarcodeSubType, PlaceholderItem, ResizeMode, BaseTextItem, ContentItem, FitMode, CurvedTextItem, GroupItem, ClipartItem, ImageEffect, StrokeSettings, ShadowSettings, WrappingMode, ParagraphSettings, Size, ArchedTextItem, BlendMode } from "@aurigma/design-atoms-model/Product/Items"; import * as Utils from "@aurigma/design-atoms-model/Utils/Utils"; import { ArgumentException } from "@aurigma/design-atoms-model/Exception"; import * as _ from "underscore"; import { ShapeItemHandler } from "../ItemHandlers"; import { fitSizeToSize, ISize, rectangleEquals } from "../Utils/Math"; import { Path, PointF, RectangleF, RotatedRectangleF } from "@aurigma/design-atoms-model/Math"; import { Transform } from "@aurigma/design-atoms-model/Math/Transform"; import { ItemUtils } from "../Utils/ItemUtils"; import { JsonColorParser } from "../Serialization/JsonColorParser"; import { RgbColors } from "@aurigma/design-atoms-model"; import { ListStyleSheetManagerFactory } from "@aurigma/design-atoms-text/TextEditor/Services"; import { Utils as CommonUtils } from "../Utils/Common"; import { GmXmlParser, GmXmlSerializer } from "@aurigma/design-atoms-text/Serialization"; import { ColorPalette } from "@aurigma/design-atoms-text/Serialization/Model/ColorPalette"; import { Paragraph, Span, SpanStyle } from "@aurigma/design-atoms-text/Model"; import { OriginPointType } from "@aurigma/design-atoms-interfaces"; var ItemsDataApplier = /** @class */ (function () { function ItemsDataApplier(_productHandler, _canvas, _productThemeManager) { var _this = this; this._productHandler = _productHandler; this._canvas = _canvas; this._productThemeManager = _productThemeManager; this._applyImagePermissions = function (imagePermissionsConf, imagePermissions) { if (imagePermissionsConf == null) return; imagePermissions.allowChangeImage = Utils.applyNullableValue(imagePermissions.allowChangeImage, imagePermissionsConf.allowChangeImage); imagePermissions.allowEditImage = Utils.applyNullableValue(imagePermissions.allowEditImage, imagePermissionsConf.allowEditImage); imagePermissions.allowKeepOverlayColor = Utils.applyNullableValue(imagePermissions.allowKeepOverlayColor, imagePermissionsConf.allowKeepOverlayColor); }; this._applyBarcodePermissions = function (barcodePermissionsConf, barcodePermissions) { if (barcodePermissionsConf == null) return; barcodePermissions.allowChangeBarcodeType = Utils.applyNullableValue(barcodePermissions.allowChangeBarcodeType, barcodePermissionsConf.allowChangeBarcodeType); barcodePermissions.allowChangeBarcodeContent = Utils.applyNullableValue(barcodePermissions.allowChangeBarcodeContent, barcodePermissionsConf.allowChangeBarcodeContent); barcodePermissions.allowChangeBarcodeColor = Utils.applyNullableValue(barcodePermissions.allowChangeBarcodeColor, barcodePermissionsConf.allowChangeBarcodeColor); }; this._updateThemeForItem = function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._productThemeManager.applyToItem(item, this._productThemeManager.currentProductTheme)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; this._colorParser = this._canvas.viewer.colorParser; this._listStyleSheetManagerFactory = new ListStyleSheetManagerFactory(CommonUtils.getListSettingFromConfig(_canvas.viewerConfiguration.listSettings)); } ItemsDataApplier.prototype.applyToItem = function (item, data, params) { if (params === void 0) { params = null; } return __awaiter(this, void 0, void 0, function () { var normalizedParams, isItemUpdated, onPropertyChanged; return __generator(this, function (_a) { switch (_a.label) { case 0: if (data == null) return [2 /*return*/]; normalizedParams = Object.assign({ ignorePermissions: true, changePosition: false, relativeToPrintArea: true }, params || {}); isItemUpdated = false; onPropertyChanged = function () { return isItemUpdated = true; }; item.addPropertyChanged(onPropertyChanged); if (!(item instanceof PlaceholderItem)) return [3 /*break*/, 2]; return [4 /*yield*/, this._applyToPlaceholderItem(item, data, normalizedParams)]; case 1: _a.sent(); return [3 /*break*/, 20]; case 2: if (!(item instanceof ImageItem)) return [3 /*break*/, 4]; return [4 /*yield*/, this._applyToImage(item, data, normalizedParams)]; case 3: _a.sent(); return [3 /*break*/, 20]; case 4: if (!(item instanceof BaseTextItem)) return [3 /*break*/, 6]; return [4 /*yield*/, this._applyToText(item, data, normalizedParams)]; case 5: _a.sent(); return [3 /*break*/, 20]; case 6: if (!(item instanceof BarcodeItem)) return [3 /*break*/, 8]; return [4 /*yield*/, this._applyToBarcode(item, data, normalizedParams)]; case 7: _a.sent(); return [3 /*break*/, 20]; case 8: if (!(item instanceof EllipseItem)) return [3 /*break*/, 10]; return [4 /*yield*/, this._applyToEllipse(item, data, normalizedParams)]; case 9: _a.sent(); return [3 /*break*/, 20]; case 10: if (!(item instanceof RectangleItem)) return [3 /*break*/, 12]; return [4 /*yield*/, this._applyToRectangle(item, data, normalizedParams)]; case 11: _a.sent(); return [3 /*break*/, 20]; case 12: if (!(item instanceof ShapeItem)) return [3 /*break*/, 14]; return [4 /*yield*/, this._applyToShapeItem(item, data, normalizedParams)]; case 13: _a.sent(); return [3 /*break*/, 20]; case 14: if (!(item instanceof LineItem)) return [3 /*break*/, 16]; return [4 /*yield*/, this._applyToLineItem(item, data, normalizedParams)]; case 15: _a.sent(); return [3 /*break*/, 20]; case 16: if (!(item instanceof ClipartItem)) return [3 /*break*/, 18]; return [4 /*yield*/, this._applyToClipartItem(item, data, normalizedParams)]; case 17: _a.sent(); return [3 /*break*/, 20]; case 18: if (!(item instanceof GroupItem)) return [3 /*break*/, 20]; return [4 /*yield*/, this._applyToGroupItem(item, data, normalizedParams)]; case 19: _a.sent(); _a.label = 20; case 20: item.removePropertyChanged(onPropertyChanged); if (!(isItemUpdated && this._productHandler.product != null && this._productHandler.product.getAllItems().includes(item))) return [3 /*break*/, 22]; return [4 /*yield*/, this._productHandler.getHandler(item).updateAsync()]; case 21: _a.sent(); this._canvas.redraw(); this._canvas.updateSelection(); _a.label = 22; case 22: return [2 /*return*/, isItemUpdated]; } }); }); }; ItemsDataApplier.prototype._applyToText = function (item, itemData, params) { var _a; return __awaiter(this, void 0, void 0, function () { var settings; return __generator(this, function (_b) { switch (_b.label) { case 0: if (!(itemData != null)) return [3 /*break*/, 3]; if (itemData.textPermissions != null) { item.textPermissions.allowChangeText = Utils.applyNullableValue(item.textPermissions.allowChangeText, itemData.textPermissions.allowChangeText); item.textPermissions.allowChangeFont = Utils.applyNullableValue(item.textPermissions.allowChangeFont, itemData.textPermissions.allowChangeFont); item.textPermissions.allowChangeFontSize = Utils.applyNullableValue(item.textPermissions.allowChangeFontSize, itemData.textPermissions.allowChangeFontSize); item.textPermissions.allowChangeFontColor = Utils.applyNullableValue(item.textPermissions.allowChangeFontColor, itemData.textPermissions.allowChangeFontColor); item.textPermissions.allowChangeTextAlignment = Utils.applyNullableValue(item.textPermissions.allowChangeTextAlignment, itemData.textPermissions.allowChangeTextAlignment); item.textPermissions.allowChangeTextBIU = Utils.applyNullableValue(item.textPermissions.allowChangeTextBIU, itemData.textPermissions.allowChangeTextBIU); item.textPermissions.allowChangeShadow = Utils.applyNullableValue(item.textPermissions.allowChangeShadow, itemData.textPermissions.allowChangeShadow); item.textPermissions.allowChangeStroke = Utils.applyNullableValue(item.textPermissions.allowChangeStroke, itemData.textPermissions.allowChangeStroke); item.textPermissions.allowTextFormatting = Utils.applyNullableValue(item.textPermissions.allowTextFormatting, itemData.textPermissions.allowTextFormatting); item.textPermissions.allowChangeStrokeColor = (_a = itemData.textPermissions.allowChangeStrokeColor) !== null && _a !== void 0 ? _a : item.textPermissions.allowChangeStrokeColor; } if (item instanceof PlainTextItem || item instanceof BoundedTextItem || item instanceof PathBoundedTextItem) item.isVertical = Utils.applyNullableValue(item.isVertical, itemData.isVertical); if (!(item instanceof CurvedTextItem) && !(item instanceof ArchedTextItem)) item.maxLineCount = Utils.applyNullableValue(item.maxLineCount, itemData.maxLineCount); item.maxLineLength = Utils.applyNullableValue(item.maxLineLength, itemData.maxLineLength); if (!(item instanceof BoundedTextItem || item instanceof PathBoundedTextItem)) return [3 /*break*/, 2]; item.wrappingMargin = Utils.applyNullableValue(item.wrappingMargin, itemData.wrappingMargin); item.characterLimit = Utils.applyNullableValue(item.characterLimit, itemData.characterLimit); if (!(itemData.paragraphSettings != null)) return [3 /*break*/, 2]; settings = new ParagraphSettings(item.paragraphSettings); settings.FirstLineIndent = Utils.applyNullableValue(settings.FirstLineIndent, itemData.paragraphSettings.firstLineIndent); settings.SpaceBefore = Utils.applyNullableValue(settings.SpaceBefore, itemData.paragraphSettings.spaceBefore); settings.SpaceAfter = Utils.applyNullableValue(settings.SpaceAfter, itemData.paragraphSettings.spaceAfter); settings.LeftIndent = Utils.applyNullableValue(settings.LeftIndent, itemData.paragraphSettings.leftIndent); settings.RightIndent = Utils.applyNullableValue(settings.RightIndent, itemData.paragraphSettings.rightIndent); item.paragraphSettings = settings; if (!params.applyPropertiesDeep) return [3 /*break*/, 2]; return [4 /*yield*/, this._removeParagraphStyleFromText(item, itemData)]; case 1: _b.sent(); _b.label = 2; case 2: if (item instanceof BoundedTextItem) { if (itemData.verticalAlignment != null) { if (typeof itemData.verticalAlignment === "string") { switch (itemData.verticalAlignment.toLowerCase()) { case "top": item.verticalAlignment = TextVerticalAlignment.Top; break; case "center": item.verticalAlignment = TextVerticalAlignment.Center; break; case "bottom": item.verticalAlignment = TextVerticalAlignment.Bottom; break; } } else { item.verticalAlignment = itemData.verticalAlignment; } } item.shrinkMode = Utils.applyNullableValue(item.shrinkMode, this._convertShrinkMode(itemData.textShrinkMode)); } if (item instanceof ArchedTextItem) { item.bend = Utils.applyNullableValue(item.bend, itemData.bend); item.warp = Utils.applyNullableValue(item.warp, itemData.warp); } _b.label = 3; case 3: return [4 /*yield*/, this._applyToBaseTextItem(item, itemData, params)]; case 4: _b.sent(); if (item instanceof BoundedTextItem) item.overflowStrategy = Utils.applyNullableValue(item.overflowStrategy, this._convertOverflowStrategy(itemData === null || itemData === void 0 ? void 0 : itemData.overflowStrategy)); return [2 /*return*/]; } }); }); }; ItemsDataApplier.prototype._convertShrinkMode = function (shrinkModeString) { if (shrinkModeString == null) return null; if (typeof (shrinkModeString) === "number") return shrinkModeString; switch (shrinkModeString) { case "scale": return ShrinkMode.Scale; case "size": return ShrinkMode.Size; default: throw new ArgumentException("Invalid shrink mode."); } }; ItemsDataApplier.prototype._convertOverflowStrategy = function (overflowStrategyString) { if (overflowStrategyString == null) return null; if (typeof (overflowStrategyString) === "number") return overflowStrategyString; switch (overflowStrategyString) { case "clip": return OverflowStrategy.Clip; case "fitToWidth": return OverflowStrategy.FitToWidth; case "fitToBox": return OverflowStrategy.FitToBox; case "expandBox": return OverflowStrategy.ExpandBox; default: throw new ArgumentException("Invalid overflow strategy."); } }; ItemsDataApplier.prototype._applyToLineItem = function (item, itemData, params) { return __awaiter(this, void 0, void 0, function () { var targetContainer, targetPrintArea, center, rectangleWidth, value, newSelectionBounds, color, angle, margin, targetRec, scale, itemHandler, rect, newRectSize, itemRectCenter, diffX, diffY; return __generator(this, function (_a) { switch (_a.label) { case 0: if (itemData.linePermissions != null) { item.linePermissions.allowChangeLineColor = Utils.applyNullableValue(item.linePermissions.allowChangeLineColor, itemData.linePermissions.allowChangeLineColor); item.linePermissions.allowChangeLineWidth = Utils.applyNullableValue(item.linePermissions.allowChangeLineWidth, itemData.linePermissions.allowChangeLineWidth); } targetContainer = this._productHandler.userEditContainer; targetPrintArea = this._productHandler.userEditPrintArea; center = targetPrintArea != null ? targetPrintArea.bounds.center : new PointF(50, 50); rectangleWidth = targetContainer != null ? this._productHandler.getPrintAreaVisualSize(targetContainer).width * 0.4 : 10; if (params.ignorePermissions || item.linePermissions.allowChangeLineWidth) { value = Utils.applyNullableValue(item.width, itemData.width); if (targetContainer == null || targetContainer.region == null || !this._productHandler.suppressOutOfRegionManipulation) { item.width = value; } else { newSelectionBounds = this._calcNewGroupBounds(this._productHandler.selectedItems, value); if (rectangleEquals(RectangleF.intersect(targetContainer.region, newSelectionBounds), newSelectionBounds)) item.width = value; } item.fixedWidth = Utils.applyNullableValue(item.fixedWidth, itemData.fixedWidth); } if (params.changePosition) { if (itemData.point0 != null) { item.sourcePoint0.x = Utils.applyNullableValue(item.sourcePoint0.x, itemData.point0.x); item.sourcePoint0.y = Utils.applyNullableValue(item.sourcePoint0.y, itemData.point0.y); } else { item.sourcePoint0 = new PointF(center.x - rectangleWidth / 2, center.y); } if (itemData.point1 != null) { item.sourcePoint1.x = Utils.applyNullableValue(item.sourcePoint1.x, itemData.point1.x); item.sourcePoint1.y = Utils.applyNullableValue(item.sourcePoint1.y, itemData.point1.y); } else { item.sourcePoint1 = new PointF(center.x + rectangleWidth / 2, center.y); } } if (itemData.color != null && (params.ignorePermissions || item.linePermissions.allowChangeLineColor)) { color = this._colorParser.parse(itemData.color); item.color = Utils.applyNullableValue(item.color, color); } if (itemData.overprintStroke != null) item.overprintStroke = itemData.overprintStroke; angle = this._productHandler.contentAngle; if (angle > 0) { item.transform.rotate(-angle); } margin = item.width + 0.01; targetRec = targetContainer != null ? this._getRotatedRegion(targetContainer) : null; if (targetRec != null) { targetRec.width -= margin; targetRec.height -= margin; scale = 1; itemHandler = this._productHandler.getHandler(item); rect = item instanceof PlaceholderItem ? itemHandler.getBoundsIncludingFrames() : itemHandler.bounds; if (rect.width > targetRec.width || rect.height > targetRec.height) { newRectSize = fitSizeToSize(ISize.from(rect), ISize.from(targetRec)); newRectSize.width *= 0.9; newRectSize.height *= 0.9; scale = newRectSize.width / rect.width; } itemRectCenter = new PointF(rect.left + (rect.width / 2), rect.top + (rect.height / 2)); diffX = itemRectCenter.x - targetRec.left - (targetRec.width / 2); diffY = itemRectCenter.y - targetRec.top - (targetRec.height / 2); item.transform.setScaleX(scale * item.transform.scaleX); item.transform.setScaleY(scale * item.transform.scaleY); item.transform.setTranslateX(item.transform.translateX - diffX - ((itemHandler.getTransformedRectangle().centerX - itemRectCenter.x) * (1 - scale))); item.transform.setTranslateY(item.transform.translateY - diffY - ((itemHandler.getTransformedRectangle().centerY - itemRectCenter.y) * (1 - scale))); } return [4 /*yield*/, this._applyToItem(item, itemData, params)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; ItemsDataApplier.prototype._applyToRectangle = function (item, itemData, params) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._applyToShapeItem(item, itemData, params)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; ItemsDataApplier.prototype._applyToGroupItem = function (item, itemData, params) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._applyToItem(item, itemData, params)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; ItemsDataApplier.prototype._applyToEllipse = function (item, itemData, params) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._applyToShapeItem(item, itemData, params)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; ItemsDataApplier.prototype._applyToClipartItem = function (item, itemData, params) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._applyToItem(item, itemData, params)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; ItemsDataApplier.prototype._applyToBarcode = function (item, itemData, params) { return __awaiter(this, void 0, void 0, function () { var barcodeData; return __generator(this, function (_a) { switch (_a.label) { case 0: this._applyBarcodePermissions(itemData.barcodePermissions, item.barcodePermissions); this._applyBarcodeOptions(item.barcodeOptions, itemData.barcodeOptions); if (itemData.barcodeContent != null && (item.barcodePermissions.allowChangeBarcodeContent || !params.ignorePermissions) && item.barcodeData.isEmpty) { barcodeData = new BarcodeData(itemData.barcodeContent); if (item.barcodePermissions.allowChangeBarcodeType && !params.ignorePermissions) barcodeData.barcodeFormat = item.barcodeFormat; if (barcodeData.barcodeFormat === BarcodeFormat.QR_CODE && barcodeData.barcodeSubType === BarcodeSubType.None) { barcodeData.barcodeSubType = BarcodeSubType.Url; } item.applyBarcodeData(barcodeData); } if (itemData.color != null && (params.ignorePermissions || item.barcodePermissions.allowChangeBarcodeColor)) { item.color = this._colorParser.parse(itemData.color); } return [4 /*yield*/, this._applyToContentItem(item, itemData, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; ; ItemsDataApplier.prototype._applyBarcodeOptions = function (barcodeOptions, barcodeOptionsData) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; if (barcodeOptionsData == null) return; barcodeOptions.margin = (_a = barcodeOptionsData.margin) !== null && _a !== void 0 ? _a : barcodeOptions.margin; barcodeOptions.pureBarcode = (_b = barcodeOptionsData.pureBarcode) !== null && _b !== void 0 ? _b : barcodeOptions.pureBarcode; barcodeOptions.errorCorrection = (_c = barcodeOptionsData.errorCorrection) !== null && _c !== void 0 ? _c : barcodeOptions.errorCorrection; barcodeOptions.characterSet = (_d = barcodeOptionsData.characterSet) !== null && _d !== void 0 ? _d : barcodeOptions.characterSet; barcodeOptions.pdf417Compact = (_e = barcodeOptionsData.pdf417Compact) !== null && _e !== void 0 ? _e : barcodeOptions.pdf417Compact; barcodeOptions.pdf417Compaction = (_f = barcodeOptionsData.pdf417Compaction) !== null && _f !== void 0 ? _f : barcodeOptions.pdf417Compaction; if (barcodeOptionsData.pdf417Dimensions != null) barcodeOptions.pdf417Dimensions = __assign({}, barcodeOptionsData.pdf417Dimensions); barcodeOptions.disableEci = (_g = barcodeOptionsData.disableEci) !== null && _g !== void 0 ? _g : barcodeOptions.disableEci; barcodeOptions.code128ForceCodesetB = (_h = barcodeOptionsData.code128ForceCodesetB) !== null && _h !== void 0 ? _h : barcodeOptions.code128ForceCodesetB; barcodeOptions.aztecLayers = (_j = barcodeOptionsData.aztecLayers) !== null && _j !== void 0 ? _j : barcodeOptions.aztecLayers; barcodeOptions.qrVersion = (_k = barcodeOptionsData.qrVersion) !== null && _k !== void 0 ? _k : barcodeOptions.qrVersion; barcodeOptions.xDimension = (_l = barcodeOptionsData.xDimension) !== null && _l !== void 0 ? _l : barcodeOptions.xDimension; barcodeOptions.databarExpandedSegments = (_m = barcodeOptionsData.databarExpandedSegments) !== null && _m !== void 0 ? _m : barcodeOptions.databarExpandedSegments; }; ItemsDataApplier.prototype._applyToPlaceholderItem = function (item, itemData, params) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; return __awaiter(this, void 0, void 0, function () { var cntPerms, barcodePerms, itemBarcodePerms, imagePerms, itemImagePerms, barcodeFormatFromConfig, contentItem, size, contentParams, data, contentItemHandler, placeholderItemHandler; return __generator(this, function (_l) { switch (_l.label) { case 0: if (itemData.placeholderPermissions != null) { item.placeholderPermissions.allowEditContent = Utils.applyNullableValue(item.placeholderPermissions.allowEditContent, itemData.placeholderPermissions.allowEditContent); item.placeholderPermissions.showSelectButton = Utils.applyNullableValue(item.placeholderPermissions.showSelectButton, itemData.placeholderPermissions.showSelectButton); item.placeholderPermissions.showHandleButton = Utils.applyNullableValue(item.placeholderPermissions.showHandleButton, itemData.placeholderPermissions.showHandleButton); } if (itemData.contentFillColor) { item.contentFillColor = this._colorParser.parse(itemData.contentFillColor); if (item.content && item.content.type == ImageItem.type) { if (item.content.effect === ImageEffect.Colorize) { item.content.fillColor = this._colorParser.parse(itemData.contentFillColor); } } } cntPerms = itemData.contentPermissions; if (cntPerms != null) { barcodePerms = cntPerms.barcodePermissions; if (barcodePerms != null) { itemBarcodePerms = item.contentPermissions.barcodePermissions; itemBarcodePerms.allowChangeBarcodeColor = (_a = barcodePerms.allowChangeBarcodeColor) !== null && _a !== void 0 ? _a : itemBarcodePerms.allowChangeBarcodeColor; itemBarcodePerms.allowChangeBarcodeContent = (_b = barcodePerms.allowChangeBarcodeContent) !== null && _b !== void 0 ? _b : itemBarcodePerms.allowChangeBarcodeContent; itemBarcodePerms.allowChangeBarcodeType = (_c = barcodePerms.allowChangeBarcodeType) !== null && _c !== void 0 ? _c : itemBarcodePerms.allowChangeBarcodeType; } imagePerms = cntPerms.imagePermissions; if (imagePerms != null) { itemImagePerms = item.contentPermissions.imagePermissions; itemImagePerms.allowChangeImage = (_d = imagePerms.allowChangeImage) !== null && _d !== void 0 ? _d : itemImagePerms.allowChangeImage; itemImagePerms.allowEditImage = (_e = imagePerms.allowEditImage) !== null && _e !== void 0 ? _e : itemImagePerms.allowEditImage; itemImagePerms.allowKeepOverlayColor = (_f = imagePerms.allowKeepOverlayColor) !== null && _f !== void 0 ? _f : itemImagePerms.allowKeepOverlayColor; } } item.violationSettings.allowImageQuality = (_h = (_g = itemData.violationSettings) === null || _g === void 0 ? void 0 : _g.allowImageQuality) !== null && _h !== void 0 ? _h : item.violationSettings.allowImageQuality; if (itemData.contentResizeMode != null) { switch (itemData.contentResizeMode.toLowerCase()) { case "original": item.contentResizeMode = ResizeMode.Original; break; case "fill": item.contentResizeMode = ResizeMode.Fill; break; case "fit": item.contentResizeMode = ResizeMode.Fit; break; } } item.isStubContent = Utils.applyNullableValue(item.isStubContent, itemData.isStubContent); item.allowedSubfolder = Utils.applyNullableValue(item.allowedSubfolder, itemData.allowedSubfolder); item.allowedTabs = Utils.applyNullableValue(item.allowedTabs, itemData.allowedTabs); item.isVariable = Utils.applyNullableValue(item.isVariable, itemData.isVariable); item.isCoverMode = Utils.applyNullableValue(item.isCoverMode, itemData.isCoverMode); item.fixedStubContentSize = Utils.applyNullableValue(item.fixedStubContentSize, itemData.fixedStubContentSize); barcodeFormatFromConfig = (_j = itemData.barcodeFormat) !== null && _j !== void 0 ? _j : (_k = itemData.barcodeContent) === null || _k === void 0 ? void 0 : _k.barcodeFormat; item.barcodeFormat = Utils.applyNullableValue(item.barcodeFormat, barcodeFormatFromConfig); if (item.content == null) { contentItem = void 0; if (itemData.contentImageUrl != null) { contentItem = new ImageItem(); } else if (item.isBarcodePlaceholder) { size = ItemsDataApplier.getBarcodeRatio(item.barcodeFormat); contentItem = new BarcodeItem(null, null, null, new RectangleF(0, 0, size.width, size.height)); } item.content = contentItem; } if (!(item.content != null)) return [3 /*break*/, 5]; contentParams = _.clone(params); contentParams.changePosition = false; if (itemData.contentOverlayEffect != null) { ItemUtils.applyOverlayEffect(item, itemData.contentOverlayEffect); } if (!(item.content instanceof ImageItem)) return [3 /*break*/, 2]; data = { imageUrl: itemData.contentImageUrl, imagePermissions: item.contentPermissions.imagePermissions, overlayEffect: itemData.contentOverlayEffect }; return [4 /*yield*/, this._applyToImage(item.content, data, contentParams)]; case 1: _l.sent(); return [3 /*break*/, 4]; case 2: if (!(item.content instanceof BarcodeItem)) return [3 /*break*/, 4]; return [4 /*yield*/, this._applyToBarcode(item.content, { barcodeContent: itemData.barcodeContent || { barcodeFormat: item.barcodeFormat, barcodeValue: "" }, barcodePermissions: item.contentPermissions.barcodePermissions, barcodeOptions: itemData.contentBarcodeOptions, color: itemData.contentBarcodeColor }, contentParams)]; case 3: _l.sent(); item.barcodeFormat = item.content.barcodeFormat; item.shapePermissions.allowChangeFillColor = true; _l.label = 4; case 4: if (item.barcodeFormat == null) { item.imageContent.allowedSubfolder = item.allowedSubfolder; item.imageContent.allowedTabs = item.allowedTabs; } _l.label = 5; case 5: return [4 /*yield*/, this._applyToShapeItem(item, itemData, params)]; case 6: _l.sent(); if (itemData.contentImageUrl == null && item.barcodeFormat == null) return [2 /*return*/]; contentItemHandler = this._productHandler.getHandler(item.content); return [4 /*yield*/, contentItemHandler.waitUpdate()]; case 7: _l.sent(); placeholderItemHandler = this._productHandler.getHandler(item); contentItemHandler.updateRectangle(false, item.contentResizeMode, placeholderItemHandler); return [2 /*return*/]; } }); }); }; ItemsDataApplier.prototype._applyToImage = function (item, config, params) { var _a, _b; return __awaiter(this, void 0, void 0, function () { var imageItemHandler; return __generator(this, function (_c) { switch (_c.label) { case 0: if (!(config != null)) return [3 /*break*/, 3]; this._applyImagePermissions(config.imagePermissions, item.imagePermissions); item.violationSettings.allowImageQuality = (_b = (_a = config.violationSettings) === null || _a === void 0 ? void 0 : _a.allowImageQuality) !== null && _b !== void 0 ? _b : item.violationSettings.allowImageQuality; if (!(config.imageUrl != null && (params.ignorePermissions || item.imagePermissions.allowChangeImage))) return [3 /*break*/, 2]; imageItemHandler = this._productHandler.getHandler(item); imageItemHandler.canvas = this._canvas; return [4 /*yield*/, imageItemHandler.loadImage(config.imageUrl, { downloadToServerCache: true, actualSize: false, saveAspectRatio: true })]; case 1: _c.sent(); _c.label = 2; case 2: if (config.overlayEffect != undefined) { ItemUtils.applyOverlayEffect(item, config.overlayEffect); } if (config.overlayColor != null) { ItemUtils.setOverlayEffectColor(item, this._colorParser.parse(config.overlayColor)); console.warn("IImageItemData.overlayColor is deprecated. Use IImageItemData.overlayEffect instead."); } if (config.effect != null) { switch (config.effect.toLowerCase()) { case "none": item.effect = ImageEffect.None; break; case "blackandwhite": item.effect = ImageEffect.BlackAndWhite; break; case "grayscale": item.effect = ImageEffect.Grayscale; break; case "flipvertical": item.effect = ImageEffect.FlipVertical; break; case "fliphorizontal": item.effect = ImageEffect.FlipHorizontal; break; case "colorize": item.effect = ImageEffect.Colorize; break; case "blackandtransparent": item.effect = ImageEffect.BlackAndTransparent; break; default: console.error("Unknown image effect:", config.effect); } } _c.label = 3; case 3: return [4 /*yield*/, this._applyToContentItem(item, config, params)]; case 4: return [2 /*return*/, _c.sent()]; } }); }); }; ; ItemsDataApplier.prototype._applyToContentItem = function (item, config, params) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (config != null) { item.isVariable = Utils.applyNullableValue(item.isVariable, config.isVariable); item.maskOpacity = Utils.applyNullableValue(item.maskOpacity, config.maskOpacity); } return [4 /*yield*/, this._applyToShapeItem(item, config, params)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; ItemsDataApplier.prototype._applyToShapeItem = function (item, itemConfig, params) { if (itemConfig === void 0) { itemConfig = null; } var _a, _b; return __awaiter(this, void 0, void 0, function () { var targetContainer, value, newSelectionBounds, color; return __generator(this, function (_c) { switch (_c.label) { case 0: if (itemConfig != null) { if (itemConfig.shapePermissions != null) { item.shapePermissions.allowChangeBorderColor = Utils.applyNullableValue(item.shapePermissions.allowChangeBorderColor, itemConfig.shapePermissions.allowChangeBorderColor); item.shapePermissions.allowChangeBorderWidth = Utils.applyNullableValue(item.shapePermissions.allowChangeBorderWidth, itemConfig.shapePermissions.allowChangeBorderWidth); item.shapePermissions.allowChangeFillColor = Utils.applyNullableValue(item.shapePermissions.allowChangeFillColor, itemConfig.shapePermissions.allowChangeFillColor); } item.violationSettings.allowShape = (_b = (_a = itemConfig.violationSettings) === null || _a === void 0 ? void 0 : _a.allowShape) !== null && _b !== void 0 ? _b : item.violationSettings.allowShape; if (params.ignorePermissions || item.shapePermissions.allowChangeBorderWidth) { targetContainer = item.parentContainer != null ? item.parentContainer : this._productHandler.userEditContainer; value = Utils.applyNullableValue(item.borderWidth, itemConfig.borderWidth); if (targetContainer == null || targetContainer.region == null || !this._productHandler.suppressOutOfRegionManipulation) { item.borderWidth = value; } else { newSelectionBounds = this._calcNewGroupBounds(this._productHandler.selectedItems, value); if (rectangleEquals(RectangleF.intersect(targetContainer.region, newSelectionBounds), newSelectionBounds)) item.borderWidth = value; } } if (itemConfig.borderColor != null && (params.ignorePermissions || item.shapePermissions.allowChangeBorderColor)) { item.borderColor = this._colorParser.parse(itemConfig.borderColor); } if (itemConfig.fillColor != null && (params.ignorePermissions || item.shapePermissions.allowChangeFillColor)) { color = this._colorParser.parse(itemConfig.fillColor); if (item instanceof PlaceholderItem &