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.

141 lines 6.25 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { BaseTextItemHandler } from "./BaseTextItemHandler"; import { RotatedRectangleF, Path } from "@aurigma/design-atoms-model/Math"; import { Graphics } from "../Graphics"; import { ShrinkMode, OverflowStrategy, WrappingMode } from "@aurigma/design-atoms-model/Product/Items"; var BoundedTextItemHandler = /** @class */ (function (_super) { __extends(BoundedTextItemHandler, _super); function BoundedTextItemHandler(item, textWhizz, apiClient, colorPreviewService) { if (textWhizz === void 0) { textWhizz = null; } if (apiClient === void 0) { apiClient = null; } var _this = _super.call(this, item, textWhizz, apiClient, colorPreviewService) || this; _this._lastRectangle = null; _this._textAutoFitted = null; _this._updateEmptyTextControlPoints(); return _this; } Object.defineProperty(BoundedTextItemHandler.prototype, "item", { get: function () { return this._getItem(); }, set: function (item) { _super.prototype._setItem.call(this, item); }, enumerable: true, configurable: true }); Object.defineProperty(BoundedTextItemHandler.prototype, "drawingRectangle", { get: function () { var isResizing = this.canvas.isItemHandlerSelected(this) && this.canvas.isSelectionResizing; return isResizing && this.startRectangle != null ? this.startRectangle : this.rectangle; }, enumerable: true, configurable: true }); Object.defineProperty(BoundedTextItemHandler.prototype, "lastRectangle", { get: function () { return this._lastRectangle; }, set: function (v) { this._lastRectangle = v; }, enumerable: true, configurable: true }); Object.defineProperty(BoundedTextItemHandler.prototype, "textAutoFitted", { get: function () { var _this = this; var checkAutofit = function () { var 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; }, enumerable: true, configurable: true }); BoundedTextItemHandler.prototype.getTextWrappingPath = function () { return this.item.textWrappingMode !== WrappingMode.None ? Path.rotatedRectangle(this.getTextRectangle()) : null; }; BoundedTextItemHandler.prototype.drawItemHandler = function (itemHandlerCtx) { _super.prototype.drawItemHandler.call(this, itemHandlerCtx); if (window["__$abl$"] === true) { Graphics.drawRectangle(itemHandlerCtx, this.getTextRectangle(), 1, "red", 1); } }; BoundedTextItemHandler.prototype.getTextRectangle = function () { var center = this.getControlCenter(); var rectangle = RotatedRectangleF.fromRectangleF(this.item.textRectangle); rectangle.transform(this.item.transform.clone(), center); return rectangle; }; BoundedTextItemHandler.prototype._setDataItem = function (item, itemHandlerData) { _super.prototype._setDataItem.call(this, item, itemHandlerData); this._textAutoFitted = null; this.item.scheduledFitMode = null; this.item.textRectangle = item.textRectangle; this.item.firstBaselineOffset = item.firstBaselineOffset; this.item.firstBaselineMinOffset = item.firstBaselineMinOffset; }; BoundedTextItemHandler.prototype._onItemPropertyChanged = function (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.prototype._onItemPropertyChanged.call(this, sender, propertyName); }; BoundedTextItemHandler.prototype._updateEmptyTextControlPoints = function () { var 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; var canvas = this.canvas; if (canvas != null) { canvas.redraw(); } this.onSuccessResponse(); this._setIsImageLoaded(true); }; BoundedTextItemHandler.prototype._setDefaultTextControlPoints = function () { }; BoundedTextItemHandler.typeName = "BoundedTextItemHandler"; return BoundedTextItemHandler; }(BaseTextItemHandler)); export { BoundedTextItemHandler }; //# sourceMappingURL=BoundedTextItemHandler.js.map