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.

323 lines 15.5 kB
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 }; } }; import { Collection } from "@aurigma/design-atoms-model/Collection"; import { RgbColors } from "@aurigma/design-atoms-model/Colors"; import { BoundedTextItem, CurvedTextItem, PathBoundedTextItem, PlainTextItem } from "@aurigma/design-atoms-model/Product/Items"; import { OpenTypeFeature } from "@aurigma/design-atoms-text/Model"; import { NewBoundedTextItemHandler, NewCurvedTextItemHandler, NewPlainTextItemHandler } from "../ItemHandlers"; import { ItemUtils } from "../Utils/ItemUtils"; /** * Data required to initialize the text engine wrapper. * @remarks The TextWhizz is used as a text engine. */ var TextWhizzInitData = /** @class */ (function () { function TextWhizzInitData(itemHandler, colorPreviewService) { this._itemHandler = itemHandler; this._colorPreviewService = colorPreviewService; } Object.defineProperty(TextWhizzInitData.prototype, "text", { get: function () { return this._text; }, set: function (value) { this._text = value; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "rectangle", { get: function () { return this._rectangle; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "previewScale", { get: function () { return this._previewScale; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "frames", { get: function () { return this._frames; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "wrappingPath", { get: function () { return this._wrappingPath; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "colorPalette", { get: function () { return this._colorPalette; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "defaultCharStyle", { get: function () { return this._defaultCharStyle; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "defaultParagraphStyle", { get: function () { return this._defaultParagraphStyle; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "isTextVertical", { get: function () { return this._isTextVertical; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "isTextBounded", { get: function () { return this._isTextBounded; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "verticalAlignment", { get: function () { return this._verticalAlignment; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "overflowStrategy", { get: function () { return this._overflowStrategy; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "firstBaselineOffset", { get: function () { return this._firstBaselineOffset; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "firstBaselineMinOffset", { get: function () { return this._firstBaselineMinOffset; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "isFitToPath", { get: function () { return this._isFitToPath; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "start", { get: function () { return this._start; }, enumerable: true, configurable: true }); Object.defineProperty(TextWhizzInitData.prototype, "end", { get: function () { return this._end; }, enumerable: true, configurable: true }); TextWhizzInitData.prototype.getActualFrames = function () { return this._itemHandler.getFramesData(); }; TextWhizzInitData.prototype.update = function (customText) { if (customText === void 0) { customText = null; } return __awaiter(this, void 0, void 0, function () { var item, itemHandler, isTextBounded, isTextCurved, isTextPlain, _a, _b, _c, isTextVertical, overflowStrategy, verticalAlignment, firstBaselineOffset, firstBaselineMinOffset, isFitToPath, start, end, boundedTextItem, curvedTextItem, plainTextItem; return __generator(this, function (_d) { switch (_d.label) { case 0: item = this._itemHandler.item; itemHandler = this._itemHandler; isTextBounded = itemHandler instanceof NewBoundedTextItemHandler && item instanceof BoundedTextItem; isTextCurved = itemHandler instanceof NewCurvedTextItemHandler && item instanceof CurvedTextItem; isTextPlain = itemHandler instanceof NewPlainTextItemHandler && item instanceof PlainTextItem; this._text = customText != null ? customText : itemHandler.getTextForRendering(); this._rectangle = itemHandler.rectangle.toRectangleF(); this._previewScale = item.previewScale; this._frames = itemHandler.getFramesData(); this._wrappingPath = itemHandler.getWrappingPathData(); _a = this; _b = Collection.bind; return [4 /*yield*/, ItemUtils.getColorPalette(item, this._colorPreviewService)]; case 1: _a._colorPalette = new (_b.apply(Collection, [void 0, _d.sent()]))(); this._colorPalette.add_itemAdded(function (data) { return itemHandler.item.colorPalette.add(data.item.color); }); _c = this; return [4 /*yield*/, TextWhizzInitData.getDefaultInlineStyle(item, this._colorPreviewService)]; case 2: _c._defaultCharStyle = _d.sent(); this._defaultParagraphStyle = TextWhizzInitData.getDefaultParagraphStyle(item); this._isTextBounded = isTextBounded; isTextVertical = false; overflowStrategy = null; verticalAlignment = null; firstBaselineOffset = null; firstBaselineMinOffset = null; isFitToPath = null; start = null; end = null; if (isTextBounded) { boundedTextItem = item; overflowStrategy = boundedTextItem.overflowStrategy; verticalAlignment = boundedTextItem.verticalAlignment; firstBaselineOffset = boundedTextItem.firstBaselineOffset; firstBaselineMinOffset = boundedTextItem.firstBaselineMinOffset; isTextVertical = boundedTextItem.isVertical; } if (isTextCurved) { curvedTextItem = item; isFitToPath = curvedTextItem.fitToPath; start = curvedTextItem.start; end = curvedTextItem.end; } if (isTextPlain) { plainTextItem = item; isTextVertical = plainTextItem.isVertical; } this._isTextVertical = isTextVertical; this._verticalAlignment = verticalAlignment; this._overflowStrategy = overflowStrategy; this._firstBaselineOffset = firstBaselineOffset; this._firstBaselineMinOffset = firstBaselineMinOffset; this._isFitToPath = isFitToPath; this._start = start; this._end = end; return [2 /*return*/]; } }); }); }; TextWhizzInitData.getDefaultInlineStyle = function (item, colorPreviewService) { return __awaiter(this, void 0, void 0, function () { var style, _a, _b, stroke, _c, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: _a = { font: { postScriptName: item.font.postScriptName, size: item.font.size, fauxBold: item.font.fauxBold, fauxItalic: item.font.fauxItalic, allCaps: item.font.allCaps }, underline: item.underline, leading: item.leading, tracking: item.tracking }; _b = { color: item.color.clone() }; return [4 /*yield*/, colorPreviewService.getPreviewAsync(item.color)]; case 1: style = (_a.color = (_b.preview = _e.sent(), _b), _a); style.baselineShift = item.baselineShift; style.horizontalScale = item.horizontalScale; style.verticalScale = item.verticalScale; stroke = {}; if (!(item.stroke != null)) return [3 /*break*/, 3]; _c = stroke; _d = { color: item.stroke.color.clone() }; return [4 /*yield*/, colorPreviewService.getPreviewAsync(item.stroke.color)]; case 2: _c.color = (_d.preview = _e.sent(), _d); stroke.size = item.stroke.size; stroke.enabled = stroke.size > 0 && !stroke.color.color.isTransparent; return [3 /*break*/, 4]; case 3: stroke.color = { color: RgbColors.transparent, preview: RgbColors.transparent }; stroke.size = 0; stroke.enabled = false; _e.label = 4; case 4: style.stroke = stroke; if (item.font.openTypeFeatures.length > 0) style.openType = item.font.openTypeFeatures.map(function (_a) { var tag = _a.tag, value = _a.value; return new OpenTypeFeature(tag, value); }); return [2 /*return*/, style]; } }); }); }; TextWhizzInitData.getDefaultParagraphStyle = function (item) { var style = { alignment: item.alignment }; if (item instanceof BoundedTextItem || item instanceof PathBoundedTextItem) { style.firstLineIndent = item.paragraphSettings.FirstLineIndent; style.spaceAfter = item.paragraphSettings.SpaceAfter; style.spaceBefore = item.paragraphSettings.SpaceBefore; style.leftIndent = item.paragraphSettings.LeftIndent; style.rightIndent = item.paragraphSettings.RightIndent; } return style; }; return TextWhizzInitData; }()); export { TextWhizzInitData }; //# sourceMappingURL=TextWhizzInitData.js.map