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.

117 lines 5.49 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, EqualsOfFloatNumbers } from "@aurigma/design-atoms-model/Math"; import { Graphics } from "../Graphics"; var PlainTextItemHandler = /** @class */ (function (_super) { __extends(PlainTextItemHandler, _super); function PlainTextItemHandler(item, textWhizz, apiClient, colorPreviewService) { if (textWhizz === void 0) { textWhizz = null; } return _super.call(this, item, textWhizz, apiClient, colorPreviewService) || this; } Object.defineProperty(PlainTextItemHandler.prototype, "item", { get: function () { return this._getItem(); }, set: function (item) { _super.prototype._setItem.call(this, item); }, enumerable: true, configurable: true }); PlainTextItemHandler.prototype.drawItemHandler = function (itemHandlerCtx) { _super.prototype.drawItemHandler.call(this, itemHandlerCtx); if (window["__$abl$"] === true) { var p = this._getBaselineLocation(); var rect = new RotatedRectangleF(p.x, p.y, 6, 6, 0); Graphics.fillRectangle(itemHandlerCtx, rect, "red"); } }; PlainTextItemHandler.prototype.onResized = function () { if (this.canvas == null) return; var 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)); var canvas = this.canvas; var minFontSize = canvas.minFontSize; fontSize = typeof minFontSize == "number" ? Math.max(fontSize, minFontSize) : fontSize; var maxFontSize = canvas.maxFontSize; fontSize = typeof maxFontSize == "number" ? Math.min(fontSize, maxFontSize) : fontSize; if (leading !== 0) { var minLeading = canvas.minLeading; leading = typeof minLeading == "number" ? Math.max(leading, minLeading) : leading; var 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.prototype.onResized.call(this); }; PlainTextItemHandler.prototype._setDataItem = function (itemData, itemHandlerData) { _super.prototype._setDataItem.call(this, itemData, itemHandlerData); this.item.baselineLocation = itemData.baselineLocation; }; PlainTextItemHandler.prototype._onItemPropertyChanged = function (sender, propertyName) { var _this = this; switch (propertyName) { case "baselineLocation": case "isVertical": this.update(); break; case "alignment": var location_1 = this.rectangle.location; var history_1 = this.canvas.history; if (history_1 != null) history_1.pause(); this.update(null, function () { var newLocation = _this.rectangle.location; var dX = location_1.x - newLocation.x; var dY = location_1.y - newLocation.y; _this.item.transform.move(dX, dY); if (history_1 != null) history_1.resume(); }); break; default: } if (propertyName !== "alignment") _super.prototype._onItemPropertyChanged.call(this, sender, propertyName); }; PlainTextItemHandler.prototype._getDefaultPermissions = function () { var permissions = _super.prototype._getDefaultPermissions.call(this); permissions.manipulation.resizeGrips.setCornerArbitrary(false); permissions.manipulation.resizeGrips.edge = false; return permissions; }; PlainTextItemHandler.prototype._getBaselineLocation = function () { var center = this.getControlCenter(); var point = this.item.baselineLocation.clone(); point.transform(this.item.transform.clone(), center); return point; }; PlainTextItemHandler.typeName = "PlainTextItemHandler"; return PlainTextItemHandler; }(BaseTextItemHandler)); export { PlainTextItemHandler }; //# sourceMappingURL=PlainTextItemHandler.js.map