@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
784 lines • 68.9 kB
JavaScript
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 { 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";
export class ItemsDataApplier {
constructor(_productHandler, _canvas, _productThemeManager) {
this._productHandler = _productHandler;
this._canvas = _canvas;
this._productThemeManager = _productThemeManager;
this._applyImagePermissions = (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 = (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 = async (item) => {
await this._productThemeManager.applyToItem(item, this._productThemeManager.currentProductTheme);
};
this._colorParser = this._canvas.viewer.colorParser;
this._listStyleSheetManagerFactory = new ListStyleSheetManagerFactory(CommonUtils.getListSettingFromConfig(_canvas.viewerConfiguration.listSettings));
}
async applyToItem(item, data, params = null) {
if (data == null)
return;
const normalizedParams = Object.assign({
ignorePermissions: true,
changePosition: false,
relativeToPrintArea: true
}, params || {});
let isItemUpdated = false;
const onPropertyChanged = () => isItemUpdated = true;
item.addPropertyChanged(onPropertyChanged);
if (item instanceof PlaceholderItem)
await this._applyToPlaceholderItem(item, data, normalizedParams);
else if (item instanceof ImageItem)
await this._applyToImage(item, data, normalizedParams);
else if (item instanceof BaseTextItem)
await this._applyToText(item, data, normalizedParams);
else if (item instanceof BarcodeItem)
await this._applyToBarcode(item, data, normalizedParams);
else if (item instanceof EllipseItem)
await this._applyToEllipse(item, data, normalizedParams);
else if (item instanceof RectangleItem)
await this._applyToRectangle(item, data, normalizedParams);
else if (item instanceof ShapeItem)
await this._applyToShapeItem(item, data, normalizedParams);
else if (item instanceof LineItem)
await this._applyToLineItem(item, data, normalizedParams);
else if (item instanceof ClipartItem)
await this._applyToClipartItem(item, data, normalizedParams);
else if (item instanceof GroupItem)
await this._applyToGroupItem(item, data, normalizedParams);
item.removePropertyChanged(onPropertyChanged);
if (isItemUpdated && this._productHandler.product != null && this._productHandler.product.getAllItems().includes(item)) {
await this._productHandler.getHandler(item).updateAsync();
this._canvas.redraw();
this._canvas.updateSelection();
}
return isItemUpdated;
}
async _applyToText(item, itemData, params) {
var _a;
if (itemData != null) {
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) {
item.wrappingMargin = Utils.applyNullableValue(item.wrappingMargin, itemData.wrappingMargin);
item.characterLimit = Utils.applyNullableValue(item.characterLimit, itemData.characterLimit);
if (itemData.paragraphSettings != null) {
const 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) {
await this._removeParagraphStyleFromText(item, itemData);
}
}
}
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);
}
}
await this._applyToBaseTextItem(item, itemData, params);
if (item instanceof BoundedTextItem)
item.overflowStrategy = Utils.applyNullableValue(item.overflowStrategy, this._convertOverflowStrategy(itemData === null || itemData === void 0 ? void 0 : itemData.overflowStrategy));
}
_convertShrinkMode(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.");
}
}
_convertOverflowStrategy(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;
case "fill":
return OverflowStrategy.Fill;
default:
throw new ArgumentException("Invalid overflow strategy.");
}
}
async _applyToLineItem(item, itemData, params) {
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);
}
var targetContainer = this._productHandler.userEditContainer;
var targetPrintArea = this._productHandler.userEditPrintArea;
var center = targetPrintArea != null ? targetPrintArea.bounds.center : new PointF(50, 50);
var rectangleWidth = targetContainer != null ? this._productHandler.getPrintAreaVisualSize(targetContainer).width * 0.4 : 10;
if (params.ignorePermissions || item.linePermissions.allowChangeLineWidth) {
const value = Utils.applyNullableValue(item.width, itemData.width);
if (targetContainer == null || targetContainer.region == null || !this._productHandler.suppressOutOfRegionManipulation) {
item.width = value;
}
else {
const 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)) {
const color = this._colorParser.parse(itemData.color);
item.color = Utils.applyNullableValue(item.color, color);
}
if (itemData.overprintStroke != null)
item.overprintStroke = itemData.overprintStroke;
const angle = this._productHandler.contentAngle;
if (angle > 0) {
item.transform.rotate(-angle);
}
const margin = item.width + 0.01;
let targetRec = targetContainer != null ? this._getRotatedRegion(targetContainer) : null;
if (targetRec != null) {
targetRec.width -= margin;
targetRec.height -= margin;
let scale = 1;
const itemHandler = this._productHandler.getHandler(item);
const rect = item instanceof PlaceholderItem ? itemHandler.getBoundsIncludingFrames() : itemHandler.bounds;
if (rect.width > targetRec.width || rect.height > targetRec.height) {
const newRectSize = fitSizeToSize(ISize.from(rect), ISize.from(targetRec));
newRectSize.width *= 0.9;
newRectSize.height *= 0.9;
scale = newRectSize.width / rect.width;
}
const itemRectCenter = new PointF(rect.left + (rect.width / 2), rect.top + (rect.height / 2));
const diffX = itemRectCenter.x - targetRec.left - (targetRec.width / 2);
const 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)));
}
await this._applyToItem(item, itemData, params);
}
async _applyToRectangle(item, itemData, params) {
await this._applyToShapeItem(item, itemData, params);
}
async _applyToGroupItem(item, itemData, params) {
await this._applyToItem(item, itemData, params);
}
async _applyToEllipse(item, itemData, params) {
await this._applyToShapeItem(item, itemData, params);
}
async _applyToClipartItem(item, itemData, params) {
await this._applyToItem(item, itemData, params);
}
async _applyToBarcode(item, itemData, params) {
this._applyBarcodePermissions(itemData.barcodePermissions, item.barcodePermissions);
this._applyBarcodeOptions(item.barcodeOptions, itemData.barcodeOptions);
if (itemData.barcodeContent != null && (item.barcodePermissions.allowChangeBarcodeContent || !params.ignorePermissions) && item.barcodeData.isEmpty) {
const 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 await this._applyToContentItem(item, itemData, params);
}
;
_applyBarcodeOptions(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 = Object.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;
}
async _applyToPlaceholderItem(item, itemData, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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);
}
}
}
const cntPerms = itemData.contentPermissions;
if (cntPerms != null) {
const barcodePerms = cntPerms.barcodePermissions;
if (barcodePerms != null) {
const 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;
}
const imagePerms = cntPerms.imagePermissions;
if (imagePerms != null) {
const 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);
const 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) {
let contentItem;
if (itemData.contentImageUrl != null) {
contentItem = new ImageItem();
}
else if (item.isBarcodePlaceholder) {
const 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) {
const contentParams = structuredClone(params);
contentParams.changePosition = false;
if (itemData.contentOverlayEffect != null) {
ItemUtils.applyOverlayEffect(item, itemData.contentOverlayEffect);
}
if (item.content instanceof ImageItem) {
const data = {
imageUrl: itemData.contentImageUrl,
imagePermissions: item.contentPermissions.imagePermissions,
overlayEffect: itemData.contentOverlayEffect
};
await this._applyToImage(item.content, data, contentParams);
}
else if (item.content instanceof BarcodeItem) {
await this._applyToBarcode(item.content, {
barcodeContent: itemData.barcodeContent || { barcodeFormat: item.barcodeFormat, barcodeValue: "" },
barcodePermissions: item.contentPermissions.barcodePermissions,
barcodeOptions: itemData.contentBarcodeOptions,
color: itemData.contentBarcodeColor
}, contentParams);
item.barcodeFormat = item.content.barcodeFormat;
item.shapePermissions.allowChangeFillColor = true;
}
if (item.barcodeFormat == null) {
item.imageContent.allowedSubfolder = item.allowedSubfolder;
item.imageContent.allowedTabs = item.allowedTabs;
}
}
await this._applyToShapeItem(item, itemData, params);
if (itemData.contentImageUrl == null && item.barcodeFormat == null)
return;
var contentItemHandler = this._productHandler.getHandler(item.content);
await contentItemHandler.waitUpdate();
var placeholderItemHandler = this._productHandler.getHandler(item);
contentItemHandler.updateRectangle(false, item.contentResizeMode, placeholderItemHandler);
}
async _applyToImage(item, config, params) {
var _a, _b;
if (config != null) {
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)) {
const imageItemHandler = this._productHandler.getHandler(item);
imageItemHandler.canvas = this._canvas;
await imageItemHandler.loadImage(config.imageUrl, {
downloadToServerCache: true,
actualSize: false,
saveAspectRatio: true
});
}
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);
}
}
}
return await this._applyToContentItem(item, config, params);
}
;
async _applyToContentItem(item, config, params) {
if (config != null) {
item.isVariable = Utils.applyNullableValue(item.isVariable, config.isVariable);
item.maskOpacity = Utils.applyNullableValue(item.maskOpacity, config.maskOpacity);
}
return await this._applyToShapeItem(item, config, params);
}
async _applyToShapeItem(item, itemConfig = null, params) {
var _a, _b;
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) {
const targetContainer = item.parentContainer != null ? item.parentContainer : this._productHandler.userEditContainer;
const value = Utils.applyNullableValue(item.borderWidth, itemConfig.borderWidth);
if (targetContainer == null || targetContainer.region == null || !this._productHandler.suppressOutOfRegionManipulation) {
item.borderWidth = value;
}
else {
const 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)) {
const color = this._colorParser.parse(itemConfig.fillColor);
if (item instanceof PlaceholderItem && item.isBarcodePlaceholder) {
item.content.fillColor = color;
}
else {
item.fillColor = color;
}
}
if (itemConfig.overprintFill != null)
item.overprintFill = itemConfig.overprintFill;
if (itemConfig.overprintStroke != null)
item.overprintStroke = itemConfig.overprintStroke;
}
await this._applyToItem(item, itemConfig, params);
}
async _applyToBaseTextItem(textItem, itemData, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
if (itemData != null) {
if (params.ignorePermissions || textItem.textPermissions.allowChangeText)
textItem.text = Utils.applyNullableValue(textItem.text, itemData.text);
if (params.ignorePermissions || textItem.textPermissions.allowChangeTextBIU) {
textItem.underline = Utils.applyNullableValue(textItem.underline, itemData.underline);
}
textItem.violationSettings.allowTextCrop = (_b = (_a = itemData.violationSettings) === null || _a === void 0 ? void 0 : _a.allowTextCrop) !== null && _b !== void 0 ? _b : textItem.violationSettings.allowTextCrop;
textItem.violationSettings.allowInPlaceText = (_d = (_c = itemData.violationSettings) === null || _c === void 0 ? void 0 : _c.allowInPlaceText) !== null && _d !== void 0 ? _d : textItem.violationSettings.allowInPlaceText;
textItem.tracking = Utils.applyNullableValue(textItem.tracking, itemData.tracking);
if (itemData.previewLeading != null) {
textItem.previewLeading = Utils.applyNullableValue(textItem.previewLeading, itemData.previewLeading);
}
else {
textItem.leading = Utils.applyNullableValue(textItem.leading, itemData.leading);
}
if (params.ignorePermissions || textItem.textPermissions.allowChangeTextAlignment) {
textItem.alignment = Utils.applyNullableValue(textItem.alignment, itemData.alignment);
}
textItem.horizontalScale = Utils.applyNullableValue(textItem.horizontalScale, itemData.horizontalScale);
textItem.verticalScale = Utils.applyNullableValue(textItem.verticalScale, itemData.verticalScale);
textItem.previewScale = Utils.applyNullableValue(textItem.previewScale, itemData.previewScale);
textItem.overlapLinesEnabled = Utils.applyNullableValue(textItem.overlapLinesEnabled, itemData.overlapLinesEnabled);
textItem.checkTextCrop = Utils.applyNullableValue(textItem.checkTextCrop, itemData.checkTextCrop);
textItem.isVariable = (_e = itemData.isVariable) !== null && _e !== void 0 ? _e : textItem.isVariable;
if (itemData.color != null && (params.ignorePermissions || textItem.textPermissions.allowChangeFontColor)) {
const color = this._colorParser.parse(itemData.color);
textItem.color = Utils.applyNullableValue(textItem.color, color);
}
if (itemData.font != null) {
if (params.ignorePermissions || textItem.textPermissions.allowChangeTextBIU) {
textItem.font.fauxBold = Utils.applyNullableValue(textItem.font.fauxBold, itemData.font.fauxBold);
textItem.font.fauxItalic = Utils.applyNullableValue(textItem.font.fauxItalic, itemData.font.fauxItalic);
}
if (params.ignorePermissions || textItem.textPermissions.allowChangeFont)
textItem.font.postScriptName = Utils.applyNullableValue(textItem.font.postScriptName, itemData.font.postScriptName);
if (params.ignorePermissions || textItem.textPermissions.allowChangeFontSize) {
if (itemData.font.previewSize != null) {
const previewSizeValue = ItemsDataApplier.parseItemsDataValueRelativeToHeight(itemData.font.previewSize, this._productHandler, params.relativeToPrintArea);
const value = Utils.applyNullableValue(textItem.previewFontSize, previewSizeValue);
const oldFontSize = textItem.previewFontSize;
textItem.previewFontSize = value;
if (textItem instanceof CurvedTextItem) {
const textItemHandler = this._productHandler.getHandler(textItem);
const centerPoint = textItemHandler.getTransformedRectangle().location;
const scale = value / oldFontSize;
const transform = new Transform(scale, scale, 0, 0, 0);
textItem.textPath.transform(transform, centerPoint);
}
}
else if (((_f = itemData.font) === null || _f === void 0 ? void 0 : _f.size) != null) {
const fontSizevalue = ItemsDataApplier.parseItemsDataValueRelativeToHeight(itemData.font.size, this._productHandler, params.relativeToPrintArea);
textItem.font.size = Utils.applyNullableValue(textItem.font.size, fontSizevalue);
}
}
textItem.font.allCaps = Utils.applyNullableValue(textItem.font.allCaps, itemData.font.allCaps);
if (((_g = itemData.font) === null || _g === void 0 ? void 0 : _g.smallCaps) !== undefined) {
await this._editText(textItem, textModel => {
for (const block of textModel.blocks) {
if (!(block instanceof Paragraph))
continue;
block.inlineElements = block.inlineElements.map(el => { var _a; return this._applySmallCaps(el, !!((_a = itemData.font) === null || _a === void 0 ? void 0 : _a.smallCaps)); });
}
});
}
}
if (itemData.stroke !== undefined && (params.ignorePermissions || textItem.textPermissions.allowChangeStroke)) {
if (itemData.stroke == null) {
textItem.stroke = null;
}
else {
if (textItem.stroke == null)
textItem.stroke = new StrokeSettings();
textItem.stroke.size = (_h = itemData.stroke.size) !== null && _h !== void 0 ? _h : textItem.stroke.size;
if (params.ignorePermissions || textItem.textPermissions.allowChangeStrokeColor) {
const color = (_j = this._parseColor(itemData.stroke.color)) !== null && _j !== void 0 ? _j : RgbColors.cyan;
textItem.stroke.color = color;
}
}
}
if (itemData.shadow !== undefined && (params.ignorePermissions || textItem.textPermissions.allowChangeShadow)) {
if (itemData.shadow == null) {
textItem.shadow = null;
}
else {
const color = (_k = this._parseColor(itemData.shadow.color)) !== null && _k !== void 0 ? _k : RgbColors.cyan;
textItem.shadow = new ShadowSettings({
size: itemData.shadow.size,
distance: itemData.shadow.distance,
angle: itemData.shadow.angle,
color: color
});
}
}
if (itemData.overprintText != null)
textItem.overprintText = itemData.overprintText;
if (params.applyPropertiesDeep) {
this._removeInlineStyleFromText(textItem, itemData, params);
}
}
await this._applyToShapeItem(textItem, itemData, params);
}
_applySmallCaps(element, enabled) {
if (element instanceof Span) {
if (!element.style) {
element.style = new SpanStyle();
}
element.style.smallCaps = enabled;
return element;
}
if (enabled) {
const span = new Span();
span.content.push(element);
span.style = new SpanStyle();
span.style.smallCaps = true;
return span;
}
return element;
}
async _removeInlineStyleFromText(item, data, params) {
await this._editText(item, textModel => {
if (data.color != null && (params.ignorePermissions || item.textPermissions.allowChangeFontColor)) {
this._removeColorFromText(textModel);
}
if (data.font != null) {
if (data.font.postScriptName != null && (params.ignorePermissions || item.textPermissions.allowChangeFont)) {
this._removeFontNameFromText(textModel);
}
if (params.ignorePermissions || item.textPermissions.allowChangeFontSize) {
this._removeFontSizeFromText(textModel);
}
if (params.ignorePermissions || item.textPermissions.allowChangeTextBIU) {
if (data.font.fauxBold != null) {
this._removeBoldFromText(textModel);
}
if (data.font.fauxItalic != null) {
this._removeItalicFromText(textModel);
}
if (data.underline != null) {
this._removeUnderlineFromText(textModel);
}
}
}
if (data.stroke != null && (params.ignorePermissions || item.textPermissions.allowChangeStroke)) {
if (data.stroke.size != null) {
this._removePenWidthFromText(textModel);
}
if (data.stroke.color != null && (params.ignorePermissions || item.textPermissions.allowChangeStrokeColor)) {
this._removePenColorFromText(textModel);
}
}
if (data.previewLeading != null && (params.ignorePermissions || item.textPermissions.allowChangeLeading)) {
this._removeLeadingFromText(textModel);
}
if (data.tracking != null) {
this._removeTrackingFromText(textModel);
}
if (data.alignment != null && (params.ignorePermissions || item.textPermissions.allowChangeTextAlignment)) {
this._removeAlignmentFromText(textModel);
}
});
}
async _removeParagraphStyleFromText(item, data) {
await this._editText(item, textModel => {
if (data.paragraphSettings != null) {
if (data.paragraphSettings.firstLineIndent != null) {
this._removeFirstLineIndentFromText(textModel);
}
if (data.paragraphSettings.leftIndent != null) {
this._removeLeftIndentFromText(textModel);
}
if (data.paragraphSettings.rightIndent != null) {
this._removeRightIndentFromText(textModel);
}
if (data.paragraphSettings.spaceAfter != null) {
this._removeSpaceAfterFromText(textModel);
}
if (data.paragraphSettings.spaceBefore != null) {
this._removeSpaceBeforeFromText(textModel);
}
}
});
}
async _editText(item, editText) {
const textParser = new GmXmlParser(this._colorParser);
const textSerializer = new GmXmlSerializer(this._colorParser);
const colorPalette = new ColorPalette(await ItemUtils.getColorPalette(item, this._canvas.viewer.colorPreviewService));
const listStyleSheetManager = this._listStyleSheetManagerFactory.create();
const textModel = textParser.parse(item.text, colorPalette, item.font.size, listStyleSheetManager);
editText(textModel);
const updatedText = textSerializer.serialize(textModel, colorPalette);
item.text = updatedText;
}
_removeColorFromText(textModel) {
this._editSpanStyles(textModel, style => style.color = null);
}
_removeFontNameFromText(textModel) {
this._editSpanStyles(textModel, style => style.fontName = null);
}
_removeFontSizeFromText(textModel) {
this._editSpanStyles(textModel, style => style.fontSize = null);
}
_removeBoldFromText(textModel) {
this._editSpanStyles(textModel, style => style.bold = null);
}
_removeItalicFromText(textModel) {
this._editSpanStyles(textModel, style => style.italic = null);
}
_removeUnderlineFromText(textModel) {
this._editSpanStyles(textModel, style => style.underline = null);
}
_removeLeadingFromText(textModel) {
this._editSpanStyles(textModel, style => style.leading = null);
}
_removeTrackingFromText(textModel) {
this._editSpanStyles(textModel, style => style.tracking = null);
}
_removePenColorFromText(textModel) {
this._editSpanStyles(textModel, style => style.penColor = null);
}
_removePenWidthFromText(textModel) {
this._editSpanStyles(textModel, style => style.penWidth = null);
}
_removeAlignmentFromText(textModel) {
this._editParagraphStyles(textModel, style => style.alignment = null);
}
_removeFirstLineIndentFromText(textModel) {
this._editParagraphStyles(textModel, style => style.firstLineIndent = null);
}
_removeLeftIndentFromText(textModel) {
this._editParagraphStyles(textModel, style => style.leftIndent = null);
}
_removeRightIndentFromText(textModel) {
this._editParagraphStyles(textModel, style => style.rightIndent = null);
}
_removeSpaceAfterFromText(textModel) {
this._editParagraphStyles(textModel, style => style.spaceAfter = null);
}
_removeSpaceBeforeFromText(textModel) {
this._editParagraphStyles(textModel, style => style.spaceBefore = null);
}
_editSpanStyles(textModel, editStyle) {
for (const block of textModel.blocks) {
if (block instanceof Paragraph) {
for (const inlineElement of block.inlineElements) {
if (inlineElement instanceof Span && inlineElement.style != null) {
editStyle(inlineElement.style);
}
}
}
}
}
_editParagraphStyles(textModel, editStyle) {
for (const block of textModel.blocks) {
if (block instanceof Paragraph && block.style != null) {
editStyle(block.style);
}
}
}
async _applyToItem(item, itemData, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
if (itemData != null) {
if (itemData.manipulationPermissions != null) {
const perms = itemData.manipulationPermissions;
const itemPerms = item.manipulationPermissions;
itemPerms.resizeGrips.corner = Utils.applyNullableValue(itemPerms.resizeGrips.corner, (_a = perms.resizeGrips) === null || _a === void 0 ? void 0 : _a.corner);
itemPerms.resizeGrips.edge = Utils.applyNullableValue(itemPerms.resizeGrips.edge, (_b = perms.resizeGrips) === null || _b === void 0 ? void 0 : _b.edge);
itemPerms.allowDelete = Utils.applyNullableValue(itemPerms.allowDelete, perms.allowDelete);
itemPerms.allowMoveHorizontal = Utils.applyNullableValue(itemPerms.allowMoveHorizontal, perms.allowMoveHorizontal);
itemPerms.allowMoveVertical = Utils.applyNullableValue(itemPerms.allowMoveVertical, perms.allowMoveVertical);
itemPerms.allowRotate = Utils.applyNullableValue(itemPerms.allowRotate, perms.allowRotate);
itemPerms.allowDragAndDrop = Utils.applyNullableValue(itemPerms.allowDragAndDrop, perms.allowDragAndDrop);
}
if (itemData.visualizationPermissions != null) {
item.visualizationPermissions.noPrint = Utils.applyNullableValue(item.visualizationPermissions.noPrint, itemData.visualizationPermissions.noPrint);
item.visualizationPermissions.noShow = Utils.applyNullableValue(item.visualizationPermissions.noShow, itemData.visualizationPermissions.noShow);
}
const itemPermsConf = itemData.itemPermissions;
if (itemPermsConf != null) {
item.itemPermissions.allowOpacityChange = Utils.applyNullableValue(item.itemPermissions.allowOpacityChange, itemPermsConf.allowOpacityChange);
item.itemPermissions.allowZOrderChange = Utils.applyNullableValue(item.itemPermissions.allowZOrderChange, itemPermsConf.a