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.

86 lines 3.68 kB
import { BaseTextItemHandler } from "./BaseTextItemHandler"; import { EqualsOfFloatNumbers } from "@aurigma/design-atoms-model/Math"; export class PlainTextItemHandler extends BaseTextItemHandler { constructor(item, textWhizz = null, apiClient, colorPreviewService) { super(item, textWhizz, apiClient, colorPreviewService); } get item() { return this._getItem(); } set item(item) { super._setItem(item); } onResized() { if (this.canvas == null) return; const ratio = this.rectangle.height / this._height; var fontSize = parseFloat((this.item.font.size * ratio).toFixed(1)); var leading = parseFloat((this.item.leading * ratio).toFixed(1)); const canvas = this.canvas; const minFontSize = canvas.minFontSize; fontSize = typeof minFontSize == "number" ? Math.max(fontSize, minFontSize) : fontSize; const maxFontSize = canvas.maxFontSize; fontSize = typeof maxFontSize == "number" ? Math.min(fontSize, maxFontSize) : fontSize; if (leading !== 0) { const minLeading = canvas.minLeading; leading = typeof minLeading == "number" ? Math.max(leading, minLeading) : leading; const maxLeading = canvas.maxLeading; leading = typeof maxLeading == "number" ? Math.min(leading, maxLeading) : leading; } if (EqualsOfFloatNumbers(fontSize, this.item.font.size, 0.01) && EqualsOfFloatNumbers(leading, this.item.leading, 0.01)) { if (this._startRectangle != null) { this.setRectangle(this._startRectangle); canvas.updateSelection(); delete this._startRectangle; } else this.update(null, null); return false; } return super.onResized(); } _setDataItem(itemData, itemHandlerData) { super._setDataItem(itemData, itemHandlerData); this.item.baselineLocation = itemData.baselineLocation; } _onItemPropertyChanged(sender, propertyName) { switch (propertyName) { case "baselineLocation": case "isVertical": this.update(); break; case "alignment": const location = this.rectangle.location; const history = this.canvas.history; if (history != null) history.pause(); this.update(null, () => { const newLocation = this.rectangle.location; const dX = location.x - newLocation.x; const dY = location.y - newLocation.y; this.item.transform.move(dX, dY); if (history != null) history.resume(); }); break; default: } if (propertyName !== "alignment") super._onItemPropertyChanged(sender, propertyName); } _getDefaultPermissions() { const permissions = super._getDefaultPermissions(); permissions.manipulation.resizeGrips.setCornerArbitrary(false); permissions.manipulation.resizeGrips.edge = false; return permissions; } _getBaselineLocation() { const center = this.getControlCenter(); const point = this.item.baselineLocation.clone(); point.transform(this.item.transform.clone(), center); return point; } } PlainTextItemHandler.typeName = "PlainTextItemHandler"; //# sourceMappingURL=PlainTextItemHandler.js.map