@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
869 lines (868 loc) • 54.9 kB
JavaScript
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 { Product } from "@aurigma/design-atoms-model/Product/Product";
import { Surface } from "@aurigma/design-atoms-model/Product/Surface";
import { SurfaceMockup } from "@aurigma/design-atoms-model/Product/SurfaceMockup";
import * as _ from "underscore";
import { MockupContainer, Container, SurfaceContainer, SpotColorContainer, TextureContainer, ColorLessContainer, FullColorContainer, LimitedColorContainer } from "@aurigma/design-atoms-model/Product/Container";
import { ColorContainerVisualization, TextureContainerVisualization } from "@aurigma/design-atoms-model/Product/ContainerVisualization";
import { SizeF, RectangleF, PointF, Path, RotatedRectangleF } from "@aurigma/design-atoms-model/Math";
import { SafetyLine } from "@aurigma/design-atoms-model/Product/SafetyLine";
import { CropMark, CropMarkText } from "@aurigma/design-atoms-model/Product/CropMark";
import { PrintArea } from "@aurigma/design-atoms-model/Product/PrintArea";
import { ItemMask } from "@aurigma/design-atoms-model/Product/ItemMask";
import { RectangleItem, EllipseItem, ShapeItem, BaseTextItem, PlainTextItem, ImageItem, BoundedTextItem, CurvedTextItem, PathBoundedTextItem, BarcodeItem, PlaceholderItem, LineItem, DashedLineItem, AutoScaledTextItem, ThemeBinding, SmartItem, InStringPlaceholder, ImageMetaData, OverlayEffect, GroupItem, ArchedTextItem, EncodingOptions, LayoutItem } from "@aurigma/design-atoms-model/Product/Items";
import { NotImplementedException, Exception } from "@aurigma/design-atoms-model/Exception";
import { Transform } from "@aurigma/design-atoms-model/Math/Transform";
import { ManipulationPermissions, ContentPermissions, BarcodePermissions, TextPermissions, ImagePermissions, ItemPermissions, ItemToolbarPermissions, FrontendPermissions, ResizeGripsPermissions, ShapePermissions, PathBoundedTextPermissions, PlaceholderPermissions, VisualizationPermissions, LinePermissions } from "@aurigma/design-atoms-model/Product/Items";
import { ParagraphSettings } from "@aurigma/design-atoms-model/Product/Items/ParagraphSettings";
import { StrokeSettings, LineJoin } from "@aurigma/design-atoms-model/Product/Items/StrokeSettings";
import { ShadowSettings } from "@aurigma/design-atoms-model/Product/Items/ShadowSettings";
import { MODELVERSION } from "@aurigma/design-atoms-model/Version";
import { Collection } from "@aurigma/design-atoms-model/Collection";
import { WatermarkConfig, WatermarkTextConfig, WatermarkImageConfig, WatermarkVisibilityConfig } from "@aurigma/design-atoms-model/Configuration/WatermarkConfig";
import { InteractiveZone, Watermark } from "@aurigma/design-atoms-model/Product";
import { GroupItemPermissions } from "@aurigma/design-atoms-model/Product/Items/GroupItemPermissions";
import { ClipartItem, ColorGroup } from "@aurigma/design-atoms-model/Product/Items/ClipartItem";
import { Margin } from "@aurigma/design-atoms-model/Math/Margin";
import { DefaultLayoutSettings, AutoLayoutSettings } from "@aurigma/design-atoms-model/Product/Items/LayoutItem";
import { ViolationSettings } from "@aurigma/design-atoms-model/Product/Items/ViolationSettings";
import { ShapeViolationSettings } from "@aurigma/design-atoms-model/Product/Items/ShapeViolationSettings";
import { ImageViolationSettings } from "@aurigma/design-atoms-model/Product/Items/ImageViolationSettings";
import { TextViolationSettings } from "@aurigma/design-atoms-model/Product/Items/TextViolationSettings";
import { Palette } from "@aurigma/design-atoms-model/Colors/Palette";
import { Swatch } from "@aurigma/design-atoms-model/Colors/Swatch";
import { JsonColorParser } from "./JsonColorParser";
import { Version } from "./Version";
import { NDEffectType, NDEffects, RecolorEffectParameters } from "@aurigma/design-atoms-model/Product/Effects";
import { PrintingTechniqueConstraints } from "@aurigma/design-atoms-model/Product/Constraints/PrintingTechniqueConstraints";
var modelVersion = Version.fromString(MODELVERSION);
var ProductParser = /** @class */ (function () {
function ProductParser(additionalConverters) {
var _this = this;
this.parsePalette = function (rawPalette) {
var palette = new Palette();
_this.parseCollection(rawPalette, _this.parseSwatch, palette);
return palette;
};
this.parseSwatch = function (rawSwatch) {
var swatch = new Swatch();
_this._parseModelComponent(rawSwatch, swatch, [
new PropertyConverter("color", _this.parseColor),
]);
return swatch;
};
this.parseSurface = function (rawSurface) {
var surface = new Surface();
_this._parseModelComponent(rawSurface, surface, [
new PropertyConverter("mockup", _this.parseMockup.bind(_this)),
new PropertyConverter("printAreas", function (rawContainers) { return _this.parseCollection(rawContainers, _this.parsePrintArea, surface.printAreas); }, true),
new PropertyConverter("containers", function (rawContainers) { return _this.parseCollection(rawContainers, _this.parseSurfaceContainer, surface.containers); }, true),
new PropertyConverter("previewMockups", function (rawContainers) { return _this.parseCollection(rawContainers, _this.parseMockup.bind(_this), surface.previewMockups); }, true),
new PropertyConverter("interactiveZones", function (rawContainers) { return _this.parseCollection(rawContainers, _this.parseInteractiveZone.bind(_this), surface.interactiveZones); }, true),
new PropertyConverter("watermark", _this.parseWatermark.bind(_this)),
]);
return surface;
};
this.parseMockupContainer = function (rawContainer) {
var container = new MockupContainer();
_this.parseContainer(rawContainer, container);
return container;
};
//TODO next release
//parsePrintAreaContainer = (rawContainer: Object) => {
// var container = new PrintAreaContainer();
// this.parseContainer(rawContainer, container);
// return container;
//}
this.parseInteractiveZone = function (rawActivityZone) {
var activityZone = new InteractiveZone();
var converters = [
new PropertyConverter("path", _this.parsePath.bind(_this)),
];
delete rawActivityZone["version"];
_this._parseObject(rawActivityZone, activityZone, converters);
return activityZone;
};
this.parseSurfaceContainer = function (rawContainer) {
var constraintsConverter = new PropertyConverter("printingTechniqueConstraints", _this._parsePrintingTechniqueConstraints);
var type = rawContainer["type"];
delete rawContainer["type"];
delete rawContainer["renderingType"];
switch (type) {
case SpotColorContainer.type: {
var converters = [
constraintsConverter,
(new PropertyConverter("outputColor", _this.parseColor.bind(_this))),
(new PropertyConverter("previewColor", _this.parseRgbColor.bind(_this))),
// property renderingType is get-only property and cannot be set
(new PropertyConverter("renderingType", function () { }, true))
];
var container = new SpotColorContainer();
_this.parseContainer(rawContainer, container, converters);
delete rawContainer["previewColor"];
delete rawContainer["outputColor"];
delete rawContainer["version"];
delete rawContainer["items"];
delete rawContainer["region"];
delete rawContainer["printingTechniqueConstraints"];
Object.assign(container, rawContainer);
return container;
}
case TextureContainer.type: {
var container = new TextureContainer();
var converters = [
constraintsConverter,
new PropertyConverter("outputColor", _this.parseColor.bind(_this)),
// property renderingType is get-only property and cannot be set
new PropertyConverter("renderingType", function () { }, true)
];
_this.parseContainer(rawContainer, container, converters);
container.previewTextureSource = _this.parseImageSource(rawContainer["previewTextureSource"]);
delete rawContainer["previewTextureSource"];
delete rawContainer["outputColor"];
delete rawContainer["version"];
delete rawContainer["items"];
delete rawContainer["region"];
delete rawContainer["printingTechniqueConstraints"];
Object.assign(container, rawContainer);
return container;
}
case FullColorContainer.type: {
var container = new FullColorContainer();
container.colorSpace = rawContainer["colorSpace"];
container.colorProfile = rawContainer["colorProfile"];
_this.parseContainer(rawContainer, container, [constraintsConverter]);
return container;
}
case ColorLessContainer.type: {
var container = new ColorLessContainer();
container.opaque = rawContainer["opaque"];
container.dpi = rawContainer["dpi"];
container.format = rawContainer["format"];
container.dither = rawContainer["dither"];
container.amount = rawContainer["amount"];
_this.parseContainer(rawContainer, container, [
new PropertyConverter("outputColor", _this.parseColor.bind(_this)),
constraintsConverter,
new PropertyConverter("visualization", _this._parseVisualization)
]);
return container;
}
case LimitedColorContainer.type: {
var container = new LimitedColorContainer();
container.maxColorNumber = rawContainer["maxColorNumber"];
container.paletteUId = rawContainer["paletteUId"];
_this.parseContainer(rawContainer, container, [constraintsConverter]);
return container;
}
default: {
var container = new SurfaceContainer();
_this.parseContainer(rawContainer, container, [constraintsConverter]);
return container;
}
}
};
this._parseVisualization = function (rawObject) {
if (rawObject["type"] === TextureContainerVisualization.type) {
return _this._parseTextureContainerVisualization(rawObject);
}
else if (rawObject["type"] === ColorContainerVisualization.type) {
return _this._parseColorContainerVisualization(rawObject);
}
};
this._parseTextureContainerVisualization = function (rawObject) {
var textureVisualization = new TextureContainerVisualization();
textureVisualization.textureName = rawObject["textureName"];
textureVisualization.opacity = rawObject["opacity"];
textureVisualization.enableGlareEffect = rawObject["enableGlareEffect"];
textureVisualization.textureSource = _this.parseImageSource(rawObject["textureSource"]);
return textureVisualization;
};
this._parseColorContainerVisualization = function (rawObject) {
var colorVisualization = new ColorContainerVisualization();
colorVisualization.color = _this.parseColor(rawObject["color"]);
colorVisualization.opacity = rawObject["opacity"];
colorVisualization.enableGlareEffect = rawObject["enableGlareEffect"];
return colorVisualization;
};
this._parsePrintingTechniqueConstraints = function (rawObject) {
var constraints = new PrintingTechniqueConstraints();
constraints.allowRasterElements = rawObject["allowRasterElements"];
constraints.minWidth = rawObject["minWidth"];
constraints.minFontSize = rawObject["minFontSize"];
constraints.targetDpi = rawObject["targetDpi"];
return constraints;
};
this.parseContainer = function (rawContainer, emptyContainer, converters) {
if (emptyContainer === void 0) { emptyContainer = new Container(); }
if (converters === void 0) { converters = []; }
_this._parseModelComponent(rawContainer, emptyContainer, __spread([
new PropertyConverter("region", _this.parseRectangleF.bind(_this)),
new PropertyConverter("size", _this.parseSizeF.bind(_this)),
new PropertyConverter("items", function (rawItems) { return _this.parseCollection(rawItems, _this.parseItem, emptyContainer.items); }, true),
// property renderingType is get-only property and cannot be set
new PropertyConverter("renderingType", function () { }, true)
], converters));
return emptyContainer;
};
this.parseSafetyLine = function (rawSafetyLine) {
var safetyLine = new SafetyLine();
var converters = [
new PropertyConverter("color", _this.parseColor.bind(_this)),
new PropertyConverter("altColor", _this.parseColor.bind(_this)),
new PropertyConverter("margin", _this._parseMargin)
];
_this._parseObject(rawSafetyLine, safetyLine, converters);
return safetyLine;
};
this.parseCropMark = function (rawCropMark) {
var cropMark = new CropMark();
var converters = [
new PropertyConverter("color", _this.parseColor.bind(_this)),
new PropertyConverter("leftNotes", _this._setConvertedArray.bind(_this, _this.parseCropMarkText, function (obj) { cropMark.leftNotes = obj; }), true),
new PropertyConverter("rightNotes", _this._setConvertedArray.bind(_this, _this.parseCropMarkText, function (obj) { cropMark.rightNotes = obj; }), true),
new PropertyConverter("topNotes", _this._setConvertedArray.bind(_this, _this.parseCropMarkText, function (obj) { cropMark.topNotes = obj; }), true),
new PropertyConverter("bottomNotes", _this._setConvertedArray.bind(_this, _this.parseCropMarkText, function (obj) { cropMark.bottomNotes = obj; }), true),
];
_this._parseObject(rawCropMark, cropMark, converters);
return cropMark;
};
this.parseCropMarkText = function (rawCropMarkText) {
var cropMarkText = new CropMarkText();
_this._parseObject(rawCropMarkText, cropMarkText, []);
return cropMarkText;
};
this.parsePrintArea = function (rawPrintArea) {
var printArea = new PrintArea();
_this._parseModelComponent(rawPrintArea, printArea, [
new PropertyConverter("bounds", _this.parseRectangleF.bind(_this)),
new PropertyConverter("safetyLines", function (rawLines) { return _this.parseCollection(rawLines, _this.parseSafetyLine, printArea.safetyLines); }, true),
new PropertyConverter("cropMarks", function (rawMarks) { return new Collection(rawMarks.map(_this.parseCropMark)); }),
new PropertyConverter("slug", _this._parseMargin),
new PropertyConverter("bleed", _this._parseMargin),
]);
return printArea;
};
this._parseMargin = function (rawMargin) {
if (rawMargin == null)
return new Margin(0);
return new Margin({
left: rawMargin["left"], top: rawMargin["top"], right: rawMargin["right"], bottom: rawMargin["bottom"]
});
};
this.parseItem = function (rawItem) {
if (rawItem == null)
return null;
var type = rawItem["$type"];
delete rawItem["$type"];
var converters = [
new PropertyConverter("pathBoundedTextPermissions", _this.parsePathBoundedTextPermissions.bind(_this)),
new PropertyConverter("manipulationPermissions", _this.parseManipulationPermissions.bind(_this)),
new PropertyConverter("frontendPermissions", _this.parseFrontendPermissions.bind(_this)),
new PropertyConverter("visualizationPermissions", _this.parseVisualizationPermissions.bind(_this)),
new PropertyConverter("violationSettings", _this.parseViolationSettings),
new PropertyConverter("itemPermissions", _this.parseItemPermissions.bind(_this)),
new PropertyConverter("transform", _this.parseTransform.bind(_this)),
new PropertyConverter("color", _this.parseColor.bind(_this)),
new PropertyConverter("themeBinding", _this.parseThemeBinding.bind(_this)),
new PropertyConverter("mask", _this.parseMask.bind(_this))
];
var item = null;
var textConverters = converters.concat([
new PropertyConverter("textPermissions", _this.parseTextPermissions.bind(_this)),
new PropertyConverter("font", _this.parseFontSettings.bind(_this), true),
new PropertyConverter("stroke", _this.parseStrokeSettings.bind(_this)),
new PropertyConverter("shadow", _this.parseShadowSettings.bind(_this))
]);
if (type == null)
throw new Exception("Serialized data seems to be corrupted.");
switch (type) {
case SmartItem.type:
item = _this.parseSmartItem(rawItem);
break;
case RectangleItem.type:
item = _this.parseRectangleItem(rawItem, converters);
break;
case ShapeItem.type:
item = _this.parseShapeItem(rawItem, converters);
break;
case LineItem.type:
item = _this.parseLineItem(rawItem, converters);
break;
case DashedLineItem.type:
item = _this.parseDashedLineItem(rawItem, converters);
break;
case EllipseItem.type:
item = _this.parseEllipseItem(rawItem, converters);
break;
case ImageItem.type:
item = _this.parseImageItem(rawItem, converters);
break;
case BarcodeItem.type:
item = _this.parseBarcodeItem(rawItem, converters);
break;
case PlainTextItem.type:
item = _this.parsePlainTextItem(rawItem, textConverters);
break;
case BoundedTextItem.type:
item = _this.parseBoundedTextItem(rawItem, textConverters);
break;
case PathBoundedTextItem.type:
item = _this.parsePathBoundedTextItem(rawItem, textConverters);
break;
case CurvedTextItem.type:
item = _this.parseCurvedTextItem(rawItem, textConverters);
break;
case AutoScaledTextItem.type:
item = _this.parseAutoScaledTextItem(rawItem, textConverters);
break;
case ArchedTextItem.type:
item = _this.parseArchedTextItem(rawItem, textConverters);
break;
case PlaceholderItem.type:
item = _this.parsePlaceholderItem(rawItem, converters);
break;
case GroupItem.type:
item = _this.parseGroupItem(rawItem, converters);
break;
case ClipartItem.type:
item = _this.parseClipartItem(rawItem, converters);
break;
case LayoutItem.type:
item = _this.parseLayoutItem(rawItem, converters);
break;
default:
throw new NotImplementedException("Deserializing of item with type - " + type + " is not implemented");
}
return item;
};
this.parseNDEffects = function (rawNDEffects) {
var ndEffects = new NDEffects();
Object.keys(rawNDEffects).forEach(function (key) {
switch (key) {
case NDEffectType.None: {
ndEffects[key] = {};
break;
}
case NDEffectType.Recolor: {
var recolorEffectParameters = new RecolorEffectParameters();
var rawRecolorEffectsParams = rawNDEffects[key];
recolorEffectParameters.reducedColorImageSource = _this.parseImageSource(rawRecolorEffectsParams.reducedColorImageSource);
recolorEffectParameters.defaultColorReplacements = _this.parseColorEntries(rawRecolorEffectsParams.defaultColorReplacements);
recolorEffectParameters.currentColorReplacements = _this.parseColorEntries(rawRecolorEffectsParams.currentColorReplacements);
ndEffects[key] = recolorEffectParameters;
break;
}
default: {
console.warn("Unknown NDEffectType!");
}
}
});
return ndEffects;
};
this.parseEncodingOptions = function (raw) {
var result = new EncodingOptions();
_this._parseModelComponent(raw, result, []);
return result;
};
this.parseLineItem = function (rawLine, baseConverters) {
var line = new LineItem();
var converters = __spread(baseConverters, _this._getLineConverters());
_this._parseModelComponent(rawLine, line, converters);
return line;
};
this.parseRotatedRectangle = function (rawRectangle) {
return new RotatedRectangleF(rawRectangle["centerX"], rawRectangle["centerY"], rawRectangle["width"], rawRectangle["height"], rawRectangle["angle"]);
};
this.parseViolationSettings = function (rawPerms) {
delete rawPerms["version"];
switch (rawPerms["type"]) {
case ViolationSettings.type:
return Object.assign(new ViolationSettings(), rawPerms);
case ShapeViolationSettings.type:
return Object.assign(new ShapeViolationSettings(), rawPerms);
case ImageViolationSettings.type:
return Object.assign(new ImageViolationSettings(), rawPerms);
case TextViolationSettings.type:
return Object.assign(new TextViolationSettings(), rawPerms);
default:
throw new NotImplementedException("Deserializing of item with type - " + rawPerms["type"] + " is not implemented");
}
};
this.parsePlaceholderPermissions = function (rawPerms) {
return Object.assign(new PlaceholderPermissions(), rawPerms);
};
this.parseLayoutSettings = function (rawPerms) {
var layoutSettings;
switch (rawPerms["type"]) {
case AutoLayoutSettings.type:
layoutSettings = new AutoLayoutSettings();
break;
default:
layoutSettings = new DefaultLayoutSettings();
break;
}
return Object.assign(layoutSettings, rawPerms);
};
this.parseGroupItemPermissions = function (rawPerms) {
return Object.assign(new GroupItemPermissions(), rawPerms);
};
this.parseLinePermissions = function (rawPerms) {
return Object.assign(new LinePermissions(), rawPerms);
};
this.parseBarcodePermissions = function (rawPerms) {
return Object.assign(new BarcodePermissions(), rawPerms);
};
this._parseOverlayEffect = function (value) {
if (value != null)
return new OverlayEffect({
color: value["color"] != null ? _this.parseColor(value["color"]) : null,
opacity: value["opacity"] != null ? value["opacity"] : null,
blendMode: value["blendMode"] != null ? value["blendMode"] : null
});
};
this._parseImageItemValue = function (value) {
return new ImageItem.ImageItemValue(value["name"], new ImageItem.ImageMetaData(value["value"]), _this.parseRotatedRectangle(value["transformedRectangle"]));
};
this._parseTextItemValue = function (value) {
return new BaseTextItem.BaseTextValue(value["name"], value["text"]);
};
this._parseObject = function (rawObject, destObject, converters) {
for (var propertyName in rawObject) {
if (!rawObject.hasOwnProperty(propertyName)) {
continue;
}
var converter = converters.find(function (c) { return c.property === propertyName; });
var rawValue = rawObject[propertyName];
if (converter == null) {
if (_.isObject(rawValue)) {
var type = rawValue["$type"];
delete rawValue["$type"];
if (_.isString(type)) {
var typeConverter = _.find(_this._additionalConverters, function (converterBound) { return (converterBound.type === type); });
if (typeConverter != null) {
destObject[propertyName] = typeConverter.parseRawValue(rawValue);
continue;
}
else
console.warn("Unknown type " + type);
}
}
destObject[propertyName] = rawValue;
continue;
}
if (converter.setByConverter) {
try {
converter.convert(rawValue, destObject);
}
catch (ex) {
console.error("Error while parsing property " + propertyName + " with converter ", converter, ex);
throw ex;
}
}
else {
if (propertyName === "manipulationPermissions" && destObject instanceof GroupItem) {
destObject["groupManipulationPermissions"] = converter.convert(rawValue);
continue;
}
destObject[propertyName] = converter.convert(rawValue);
}
}
};
/*
TODO: it crushes an insertion of psd when downloadPsdAsImage=false
const defaultConverters = [
new Model.AdditionalConverter(
"CustomersCanvas.Core.Model.PrintAreaContainer, CustomersCanvas.Core",
this.parsePrintAreaContainer.bind(this),
PrintAreaContainer),
new Model.AdditionalConverter(
"CustomersCanvas.Core.Model.PrintArea, CustomersCanvas.Core",
this.parsePrintArea.bind(this),
PrintArea)
];
this._additionalConverters = additionalConverters != null ? additionalConverters.concat(defaultConverters) : defaultConverters;
*/
this._additionalConverters = additionalConverters != null ? additionalConverters : [];
}
//#region public methods
ProductParser.prototype.parseProduct = function (rawProduct) {
var _this = this;
var product = new Product();
var productConverters = [
new PropertyConverter("surfaces", function (rawSurfaces) { return _this.parseCollection(rawSurfaces, _this.parseSurface, product.surfaces); }, true),
new PropertyConverter("watermarkConfig", this.parseWatermarkConfig.bind(this)),
new PropertyConverter("defaultSafetyLines", function (rawLines) { return _this.parseCollection(rawLines, _this.parseSafetyLine, product.defaultSafetyLines); }, true),
new PropertyConverter("defaultCropMarks", function (rawMarks) { return _this.parseCollection(rawMarks, _this.parseCropMark, product.defaultCropMarks); }, true),
new PropertyConverter("defaultDesignLocation", this.parsePointF.bind(this)),
new PropertyConverter("palette", function (rawPalette) { return _this.parsePalette(rawPalette); })
];
this._parseModelComponent(rawProduct, product, productConverters);
return product;
};
ProductParser.prototype.parseColor = function (rawColor) {
return JsonColorParser.parse(rawColor);
};
ProductParser.prototype.parseRgbColor = function (rawColor) {
return JsonColorParser.parseRgbColor(rawColor);
};
ProductParser.prototype.parseWatermarkConfig = function (rawConfig) {
var _this = this;
if (rawConfig == null)
return null;
var config = new WatermarkConfig();
var parseFontSettings = new PropertyConverter("fontSettings", (function (rawFontSettings) {
if (rawFontSettings == null)
return null;
var fontSettings = new BaseTextItem.FontSettings(null);
_this._parseObject(rawFontSettings, fontSettings, []);
return fontSettings;
}));
var parseWatermarkTextConfig = new PropertyConverter("text", (function (rawText) {
if (rawText == null)
return null;
var text = new WatermarkTextConfig();
_this._parseObject(rawText, text, [parseFontSettings]);
return text;
}));
var parseWatermarkImageConfig = new PropertyConverter("image", (function (rawImage) {
if (rawImage == null)
return null;
var image = new WatermarkImageConfig();
_this._parseObject(rawImage, image, []);
return image;
}));
var parseWatermarkVisibilityConfig = new PropertyConverter("visibility", (function (rawVisibility) {
if (rawVisibility == null)
return null;
var visibility = new WatermarkVisibilityConfig();
_this._parseObject(rawVisibility, visibility, []);
return visibility;
}));
this._parseObject(rawConfig, config, [parseWatermarkTextConfig, parseWatermarkImageConfig, parseWatermarkVisibilityConfig]);
return config;
};
ProductParser.prototype.parseWatermark = function (rawWatermark) {
if (rawWatermark == null)
return null;
var watermark = new Watermark();
this._parseObject(rawWatermark, watermark, []);
return watermark;
};
ProductParser.prototype.parseMockup = function (rawMockup) {
var _this = this;
var mockup = new SurfaceMockup();
this._parseModelComponent(rawMockup, mockup, [
new PropertyConverter("underContainers", function (rawContainers) { return _this.parseCollection(rawContainers, _this.parseMockupContainer, mockup.underContainers); }, true),
new PropertyConverter("overContainers", function (rawContainers) { return _this.parseCollection(rawContainers, _this.parseMockupContainer, mockup.overContainers); }, true)
]);
return mockup;
};
ProductParser.prototype.parseCollection = function (rawCollection, parseCollectionItem, targetCollection) {
if (rawCollection != null)
targetCollection.setRange(rawCollection.map(function (rawColItem) { return parseCollectionItem(rawColItem); }));
};
ProductParser.prototype.parseRectangleF = function (rawRectangle) {
if (rawRectangle == null)
return null;
return new RectangleF(rawRectangle["left"], rawRectangle["top"], rawRectangle["width"], rawRectangle["height"]);
};
ProductParser.prototype.parsePointF = function (rawPoint) {
if (rawPoint == null)
return null;
var pointF = new PointF();
Object.assign(pointF, rawPoint);
return pointF;
};
ProductParser.prototype.parseSizeF = function (rawSize) {
if (rawSize == null)
return null;
//TODO: use server-side JsonConverter
if (_.isString(rawSize)) {
var values = rawSize.split(",");
return new SizeF(parseFloat(values[0].trim()), parseFloat(values[1].trim()));
}
else
return _.extend(new SizeF(), rawSize);
};
ProductParser.prototype.parsePath = function (rawPath) {
if (rawPath == null)
return null;
if (typeof rawPath === "string")
return new Path(rawPath);
return new Path(rawPath["path"]);
};
ProductParser.prototype.parsePaths = function (rawPaths) {
var _this = this;
if (rawPaths == null || !_.isArray(rawPaths))
return null;
var paths = [];
_.toArray(rawPaths).forEach(function (v) {
paths.push(_this.parsePath(v));
});
return paths;
};
ProductParser.prototype.parseSmartItem = function (rawSmartItem) {
var smartItem = new SmartItem();
this._parseModelComponent(rawSmartItem, smartItem, []);
return smartItem;
};
ProductParser.prototype.parsePlainTextItem = function (rawPlainText, baseConverters) {
var plainTextItem = new PlainTextItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getBaseTextItemConverters(plainTextItem), [new PropertyConverter("baselineLocation", this.parsePointF.bind(this))]);
this._parseModelComponent(rawPlainText, plainTextItem, converters);
return plainTextItem;
};
ProductParser.prototype.parseArchedTextItem = function (rawArchedText, baseConverters) {
var archedTextItem = new ArchedTextItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getBaseTextItemConverters(archedTextItem), [new PropertyConverter("center", this.parsePointF.bind(this))]);
this._parseModelComponent(rawArchedText, archedTextItem, converters);
return archedTextItem;
};
ProductParser.prototype.parseAutoScaledTextItem = function (rawAutoScaledText, baseConverters) {
var autoScaledTextItem = new AutoScaledTextItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getBaseTextItemConverters(autoScaledTextItem), [new PropertyConverter("textRectangle", this.parseRectangleF.bind(this))]);
this._parseModelComponent(rawAutoScaledText, autoScaledTextItem, converters);
return autoScaledTextItem;
};
ProductParser.prototype.parseBoundedTextItem = function (rawBoundedText, baseConverters) {
var boundedTextItem = new BoundedTextItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getBaseTextItemConverters(boundedTextItem), [
new PropertyConverter("paragraphSettings", this.parseParagraphSettings.bind(this)),
new PropertyConverter("textRectangle", this.parseRectangleF.bind(this)),
new PropertyConverter("wrappingPath", this.parsePath.bind(this))
]);
this._parseModelComponent(rawBoundedText, boundedTextItem, converters);
return boundedTextItem;
};
ProductParser.prototype.parsePathBoundedTextItem = function (rawBoundedText, baseConverters) {
var pathBoundedTextItem = new PathBoundedTextItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getBaseTextItemConverters(pathBoundedTextItem), [
new PropertyConverter("pathBoundedTextPermissions", this.parsePathBoundedTextPermissions.bind(this)),
new PropertyConverter("boundingPaths", this.parsePaths.bind(this)),
new PropertyConverter("paragraphSettings", this.parseParagraphSettings.bind(this)),
new PropertyConverter("wrappingPath", this.parsePath.bind(this))
]);
this._parseModelComponent(rawBoundedText, pathBoundedTextItem, converters);
return pathBoundedTextItem;
};
ProductParser.prototype.parseCurvedTextItem = function (rawCurvedText, baseConverters) {
var curvedTextItem = new CurvedTextItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getBaseTextItemConverters(curvedTextItem), [new PropertyConverter("textPath", this.parsePath.bind(this))]);
this._parseModelComponent(rawCurvedText, curvedTextItem, converters);
return curvedTextItem;
};
ProductParser.prototype._getBaseTextItemConverters = function (item) {
var _this = this;
return [
new PropertyConverter("values", this._setConvertedArray.bind(this, this._parseTextItemValue, function (obj) { item.values = obj; }), true),
new PropertyConverter("placeholders", function (rawPlaceholders) { return _this.parseCollection(rawPlaceholders, _this.parseInStringPlaceholder, item.placeholders); }, true),
new PropertyConverter("colorPalette", function (rawPalette) { return _this.parseCollection(rawPalette, _this.parseColor, item.colorPalette); }, true)
];
};
ProductParser.prototype.parseImageItem = function (rawImage, baseConverters) {
var image = new ImageItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getImageConverters(image));
this._parseModelComponent(rawImage, image, converters);
return image;
};
ProductParser.prototype.parseColorEntries = function (rawColorEntries) {
var _this = this;
var colorMap = new Map();
if (!rawColorEntries)
return colorMap;
rawColorEntries
.forEach(function (entry) {
var keyColor = _this.parseColor(entry.keyColor);
var valueColor = _this.parseColor(entry.valueColor);
colorMap.set(keyColor, valueColor);
});
return colorMap;
};
ProductParser.prototype.parseBarcodeItem = function (rawBarcode, baseConverters) {
var barcode = new BarcodeItem();
var converters = baseConverters.concat(this._getShapeConverters(), this._getImageConverters(barcode), [
new PropertyConverter("barcodePermissions", this.parseBarcodePermissions.bind(this)),
new PropertyConverter("color", this.parseColor.bind(this)),
new PropertyConverter("barcodeOptions", this.parseEncodingOptions)
]);
this._parseModelComponent(rawBarcode, barcode, converters);
return barcode;
};
ProductParser.prototype.parsePlaceholderItem = function (rawPlaceholder, baseConverters) {
var self = this;
var placeholder = new PlaceholderItem();
var converters = __spread(baseConverters, this._getShapeConverters(), [
new PropertyConverter("placeholderPermissions", this.parsePlaceholderPermissions),
new PropertyConverter("contentPermissions", this.parseContentPermissions.bind(this)),
new PropertyConverter("content", this.parseItem),
new PropertyConverter("topFrames", parseRawFrames),
new PropertyConverter("bottomFrames", parseRawFrames),
new PropertyConverter("stubStorageMeta", function (rawObject) { return new ImageMetaData(rawObject); }),
new PropertyConverter("contentFillColor", this.parseColor.bind(this)),
new PropertyConverter("contentOverlayEffect", this._parseOverlayEffect.bind(this))
]);
this._parseModelComponent(rawPlaceholder, placeholder, converters);
return placeholder;
function parseRawFrames(rawFrames) {
return rawFrames.map(self.parseItem);
}
};
ProductParser.prototype.parseGroupItem = function (rawGroupItem, baseConverters) {
var groupItem = new GroupItem();
var converters = __spread(baseConverters, this._getShapeConverters(), this._getGroupConverters(groupItem));
this._parseModelComponent(rawGroupItem, groupItem, converters);
return groupItem;
};
ProductParser.prototype.parseClipartItem = function (rawClipartItem, baseConverters) {
var clipartItem = new ClipartItem();
var converters = __spread(baseConverters, this._getShapeConverters(), this._getGroupConverters(clipartItem), [
new PropertyConverter("colorGroups", this._setConvertedArray.bind(this, this.parseColorGroup.bind(this), function (colorGroups) { return clipartItem.colorGroups = colorGroups; }), true),
]);
this._parseModelComponent(rawClipartItem, clipartItem, converters);
return clipartItem;
};
ProductParser.prototype.parseLayoutItem = function (rawLayoutItem, baseConverters) {
var layoutItem = new LayoutItem();
var converters = __spread(baseConverters, this._getShapeConverters(), this._getGroupConverters(layoutItem), [
new PropertyConverter("layoutSettings", this.parseLayoutSettings),
new PropertyConverter("sourceRectangle", this.parseRotatedRectangle)
]);
this._parseModelComponent(rawLayoutItem, layoutItem, converters);
return layoutItem;
};
ProductParser.prototype.parseContentPermissions = function (rawContentPermissions, baseConverters) {
var contentPermissions = new ContentPermissions();
contentPermissions.barcodePermissions = this.parseBarcodePermissions(rawContentPermissions["barcodePermissions"]);
contentPermissions.imagePermissions = this.parseImagePermissions(rawContentPermissions["imagePermissions"]);
return contentPermissions;
};
ProductParser.prototype.parseEllipseItem = function (rawEllipse, baseConverters) {
var ellipse = new EllipseItem();
var converters = baseConverters.concat(this._getShapeConverters());
this._parseModelComponent(rawEllipse, ellipse, converters);
return ellipse;
};
ProductParser.prototype.parseRectangleItem = function (rawRectangle, baseConverters) {
var rectangle = new RectangleItem();
var converters = baseConverters.concat(this._getShapeConverters());
this._parseModelComponent(rawRectangle, rectangle, converters);
return rectangle;
};
ProductParser.prototype.parseShapeItem = function (rawShape, baseConverters) {
var shape = new ShapeItem();
var converters = baseConverters.concat(this._getShapeConverters());
this._parseModelComponent(rawShape, shape, converters);
return shape;
};
ProductParser.prototype.parseDashedLineItem = function (rawLine, baseConverters) {
var line = new DashedLineItem();
var converters = __spread(baseConverters, this._getLineConverters(), this._getDashedLineConverters());
this._parseModelComponent(rawLine, line, converters);
return line;
};
ProductParser.prototype.parseThemeBinding = function (rawThemeBinding) {
return rawThemeBinding != null ? ThemeBinding.fromRaw(rawThemeBinding) : null;
};
ProductParser.prototype.parseMask = function (rawMask) {
if (rawMask == null)
return null;
var mask = new ItemMask();
if (rawMask.vectorMask != null)
mask.vectorMask = this.parsePath(rawMask.vectorMask);
return mask;
};
ProductParser.prototype.parseTransform = function (rawTransform) {
return new Transform(rawTransform["scaleX"], rawTransform["scaleY"], rawTransform["translateX"], rawTransform["translateY"], rawTransform["angle"]);
};
ProductParser.prototype.parseFontSettings = function (rawSettings, destTextItem) {
var font = new BaseTextItem.FontSettings(null);
Object.assign(font, rawSettings);
destTextItem.font = font;
return destTextItem.font;
};
ProductParser.prototype.parseManipulationPermissions = function (rawPerms) {
var result = Object.assign(new ManipulationPermissions(), rawPerms);
result.resizeGrips = Object.assign(new ResizeGripsPermissions(false, false), rawPerms["resizeGrips"]);
return result;
};
ProductParser.prototype.parseFrontendPermissions = function (rawPerms) {
return Object.assign(new FrontendPermissions(), rawPerms);
};
ProductParser.prototype.parseVisualizationPermissions = function (rawPerms) {
return Object.assign(new VisualizationPermissions(), rawPerms);
};
ProductParser.prototype.parseColorGroup = function (rawPerms) {
return new ColorGroup(this.parseColor(rawPerms["color"]), rawPerms["targets"]);
};
ProductParser.prototype.parseItemPermissions = function (rawPerms) {
var result = Object.assign(new ItemPermissions(), rawPerms);
result.itemToolbarPermissions = Object.assign(new ItemToolbarPermissions(false), rawPerms["itemToolbarPermissions"]);
return result;
};
ProductParser.prototype.parseTextPermissions = function (rawPerms) {
return Object.assign(new TextPermissions(), rawPerms);
};
ProductParser.prototype.parsePathBoundedTextPermissions = function (rawPerms) {
return Object.assign(new PathBoundedTextPermissions(), rawPerms);
};
ProductParser.prototype.parseShapePermissions = function (rawPerms) {
return Object.assign(new ShapePermissions(), rawPerms);
};
ProductParser.prototype.parseImagePermissions = function (rawPerms) {
return Object.assign(new ImagePermissions(), rawPerms);
};
ProductParser.prototype.parseImageSource = function (rawImageSource) {
if (rawImageSource == null)
return null;
// TODO: Remove after implementing Issue #29923: Add Public/User ImageSource support
var unsupportedTypes = [
ImageItem.ImageSourceType.PublicImage,
ImageItem.ImageSourceType.UserImage,
ImageItem.ImageSourceType.File
];
var sourceType = rawImageSource["type"];
if (unsupportedTypes.includes(sourceType)) {
throw new Error("ImageSource type " + sourceType + " is not supported. " +
("Type " + sourceType + " corresponds to " + this.getTypeName(sourceType) + "."));
}
var origin = null;
if (rawImageSource["origin"] != null)
origin = new ImageItem.ImageSource.Origin(rawImageSource["origin"]);
if (rawImageSource["origin"] !== undefined)
delete rawImageSource["origin"];
return Object.assign(new ImageItem.ImageSource(rawImageSource["id"], rawImageSource["url"], 0, false, true, origin), rawImageSource);
};
ProductParser.prototype.parseParagraphSettings = function (rawSettings) {
return new ParagraphSettings(rawSettings);
};
ProductParser.prototype.parseStrokeSettings = function (rawSettings) {
if (rawSettings == null) {
return null;
}
return new StrokeSettings({
color: JsonColorParser.parse(rawSettings["color"]),
size: (typeof rawSettings["size"] == "number") ? rawSettings["size"] : 0,
lineJoin: (typeof rawSettings["lineJoin"] == "string") ? LineJoin[rawSettings["lineJoin"]] : LineJoin.Miter
});
};
ProductParser.prototype.parseShadowSettings = function (rawSettings) {