@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
98 lines • 3.91 kB
JavaScript
import { BaseTextItemHandler } from "./BaseTextItemHandler";
import { RotatedRectangleF, Path } from "@aurigma/design-atoms-model/Math";
import { ShrinkMode, OverflowStrategy, WrappingMode } from "@aurigma/design-atoms-model/Product/Items";
export class BoundedTextItemHandler extends BaseTextItemHandler {
constructor(item, textWhizz = null, apiClient = null, colorPreviewService) {
super(item, textWhizz, apiClient, colorPreviewService);
this._lastRectangle = null;
this._textAutoFitted = null;
this._updateEmptyTextControlPoints();
}
get item() {
return this._getItem();
}
set item(item) {
super._setItem(item);
}
get drawingRectangle() {
const isResizing = this.canvas.isItemHandlerSelected(this) && this.canvas.isSelectionResizing;
return isResizing && this.startRectangle != null ? this.startRectangle : this.rectangle;
}
get lastRectangle() {
return this._lastRectangle;
}
set lastRectangle(v) {
this._lastRectangle = v;
}
get textAutoFitted() {
const checkAutofit = () => {
const item = this.item;
if (item.overflowStrategy === OverflowStrategy.Clip) {
return false;
}
if (item.shrinkMode === ShrinkMode.Scale || item.shrinkMode === ShrinkMode.Size) {
return item.originalVerticalScale < item.verticalScale ||
item.originalHorizontalScale < item.horizontalScale;
}
return false;
};
if (this._textAutoFitted == null) {
this._textAutoFitted = checkAutofit();
}
return this._textAutoFitted;
}
getTextWrappingPath() {
return this.item.textWrappingMode !== WrappingMode.None ? Path.rotatedRectangle(this.getTextRectangle()) : null;
}
getTextRectangle() {
const center = this.getControlCenter();
const rectangle = RotatedRectangleF.fromRectangleF(this.item.textRectangle);
rectangle.transform(this.item.transform.clone(), center);
return rectangle;
}
_setDataItem(item, itemHandlerData) {
super._setDataItem(item, itemHandlerData);
this._textAutoFitted = null;
this.item.scheduledFitMode = null;
this.item.textRectangle = item.textRectangle;
this.item.firstBaselineOffset = item.firstBaselineOffset;
this.item.firstBaselineMinOffset = item.firstBaselineMinOffset;
}
_onItemPropertyChanged(sender, propertyName) {
switch (propertyName) {
case "textRectangle":
case "verticalAlignment":
case "isVertical":
case "paragraphSettings":
case "wrappingMargin":
case "scheduledFitMode":
case "shrinkMode":
case "overflowStrategy":
case "wrappingPath":
case "firstBaselineOffset":
case "firstBaselineMinOffset":
case "characterLimit":
this.update();
break;
default:
}
super._onItemPropertyChanged(sender, propertyName);
}
_updateEmptyTextControlPoints() {
const textRectangle = this.item.textRectangle;
this._controlPoints[0].x = textRectangle.left;
this._controlPoints[0].y = textRectangle.top;
this._controlPoints[1].x = textRectangle.right;
this._controlPoints[1].y = textRectangle.bottom;
const canvas = this.canvas;
if (canvas != null) {
canvas.redraw();
}
this.onSuccessResponse();
this._setIsImageLoaded(true);
}
_setDefaultTextControlPoints() {
}
}
BoundedTextItemHandler.typeName = "BoundedTextItemHandler";
//# sourceMappingURL=BoundedTextItemHandler.js.map