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.

100 lines 3.85 kB
import { RotatedRectangleF, RectangleF } from "@aurigma/design-atoms-model/Math"; import { ParagraphSettings } from "@aurigma/design-atoms-model/Product/Items"; import { BaseTextItemHandler } from "./BaseTextItemHandler"; import { PathHandler } from "./PathHandler"; export class PathBoundedTextItemHandler extends BaseTextItemHandler { constructor(item, textWhizz = null, apiClient, colorPreviewServce) { super(item, textWhizz, apiClient, colorPreviewServce); this._lastRectangle = null; this._lastRectangle = null; } get item() { return this._getItem(); } set item(item) { super._setItem(item); } get boundingPaths() { const paths = []; const center = this.getControlCenter(); const transform = this.item.transform.clone(); this.originalBoundingPaths.forEach(p => { var path = p.clone(); path.transform(transform, center); paths.push(path); }); return paths; } get originalBoundingPaths() { return this.item.boundingPaths; } set originalBoundingPaths(value) { this.item.boundingPaths = value; } get lastRectangle() { return this._lastRectangle; } set lastRectangle(value) { this._lastRectangle = value; } get wrappingMargin() { return this.item.wrappingMargin; } set wrappingMargin(value) { this.item.wrappingMargin = value; } get paragraphSettings() { return this.item.paragraphSettings; } set paragraphSettings(value) { if (!(value instanceof ParagraphSettings)) value = new ParagraphSettings(value); this.item.paragraphSettings = value; } get isVertical() { return this.item.isVertical; } set isVertical(value) { this.item.isVertical = value; } get drawingRectangle() { const isResizing = this.canvas.isItemHandlerSelected(this) && this.canvas.isSelectionResizing; return isResizing && this.startRectangle != null ? this.startRectangle : this.rectangle; } async getBoundingPathsBounds() { const paths = this.item.boundingPaths; const bounds = await Promise.all(paths.map(p => PathHandler.getBounds(p))); const rectangleF = RectangleF.getOverallBounds(bounds); const rectangle = RotatedRectangleF.fromRectangleF(rectangleF); rectangle.transform(this.item.transform.clone(), this.getControlCenter()); return rectangle.toRectangleF(); } _setDataItem(itemData, itemHandlerData) { super._setDataItem(itemData, itemHandlerData); this.item.boundingPaths = itemData.boundingPaths; this.item.wrappingMargin = itemData.wrappingMargin; this.item.characterLimit = itemData.characterLimit; this.item.paragraphSettings = itemData.paragraphSettings; this.item.isVertical = itemData.isVertical; this.item.firstBaselineOffset = itemData.firstBaselineOffset; this.item.firstBaselineMinOffset = itemData.firstBaselineMinOffset; } _onItemPropertyChanged(sender, propertyName) { switch (propertyName) { case "boundingPaths": case "wrappingPath": case "wrappingMargin": case "paragraphSettings": case "isVertical": case "firstBaselineOffset": case "firstBaselineMinOffset": case "characterLimit": this.update(); } super._onItemPropertyChanged(sender, propertyName); } _setDefaultTextControlPoints() { } } PathBoundedTextItemHandler.typeName = "PathBoundedTextItemHandler"; //# sourceMappingURL=PathBoundedTextItemHandler.js.map