@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
879 lines • 44.4 kB
JavaScript
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 __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { RectangleF, PointF, Path, RotatedRectangleF, Transform } from "@aurigma/design-atoms-model/Math";
import { StrokeSettings } from "@aurigma/design-atoms-model/Product/Items";
import * as Utils from "@aurigma/design-atoms-model/Utils/Utils";
import { MobileTextEditor } from "@aurigma/design-atoms-text/TextEditor/MobileTextEditor";
import { Graphics } from "../Graphics";
import { TextRenderer } from "../InPlace/TextRenderer";
import { Deferred } from "../Utils/Deferred";
import { ImageContainer } from "./ImageContainer";
import { ShapeItemHandler } from "./ShapeItemHandler";
import { NotImplementedException, Exception } from "@aurigma/design-atoms-model/Exception";
import { EventWithSenderArg } from "@aurigma/design-atoms-model/EventObject";
import { applyIfDefined } from "../Utils/Functions";
import { toTextWhizzPath } from "@aurigma/design-atoms-text/Utils/PathUtils";
import { InputState } from "./../Input/InputManager/IInputManager";
import { AsyncHelper } from "../Utils/AsyncHelper";
import { ItemHandlerState } from "./ItemHandlerState";
import { TextUtils } from "@aurigma/design-atoms-text/Utils";
var NewBaseTextItemHandler = /** @class */ (function (_super) {
__extends(NewBaseTextItemHandler, _super);
function NewBaseTextItemHandler(fontRegistry, textEditorControllerFactory, item, textWhizz, apiClient, colorPreviewService, colorParser) {
if (textWhizz === void 0) { textWhizz = null; }
var _this = _super.call(this, null, item, textWhizz, apiClient, colorPreviewService) || this;
_this._fontRegistryUpdated = null;
_this._waitLoadFontsDef = null;
_this._waitLoadFontsLastInnerUpdate = null;
_this._frontEndUpdateExecutionToken = AsyncHelper.getExecutionToken();
_this._initFrontEndRenderingDef = null;
_this._staticTextRect = null;
_this._exitedEditModeEvent = new EventWithSenderArg();
_this._enteredEditModeEvent = new EventWithSenderArg();
_this._onStaticTextImageChanged = function (data) {
var _a;
if (data.canvas == null) {
_this._imageContainer.clear();
(_a = _this.canvas) === null || _a === void 0 ? void 0 : _a.redraw();
}
else {
_this._staticTextRect = data.rect;
_this._imageContainer.updateCanvas(data.canvas);
}
};
_this._fontRegistry = fontRegistry;
_this._textEditorControllerFactory = textEditorControllerFactory;
_this._colorParser = colorParser;
var rectangle = _this.item != null ? _this.item.sourceRectangle : null;
if (rectangle == null || rectangle.isEmpty())
rectangle = new RectangleF(0, 0, 10, 10);
_this.originalPath = Path.rectangle(rectangle.left, rectangle.top, rectangle.width, rectangle.height);
_this.controlPoints = [new PointF(rectangle.left, rectangle.top), new PointF(rectangle.right, rectangle.bottom)];
_this._imageContainer = new ImageContainer(function () { return __awaiter(_this, void 0, void 0, function () {
var ex_1;
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_c.trys.push([0, 2, , 3]);
if (this.canvas == null)
return [2 /*return*/];
(_a = this.canvas) === null || _a === void 0 ? void 0 : _a.redraw();
return [4 /*yield*/, this.waitUpdate()];
case 1:
_c.sent();
(_b = this.canvas) === null || _b === void 0 ? void 0 : _b.redraw();
return [3 /*break*/, 3];
case 2:
ex_1 = _c.sent();
console.warn("Error in [NewBaseTextItemHandler].ctor ImageContainer loaded", ex_1);
throw ex_1;
case 3: return [2 /*return*/];
}
});
}); });
_this._allowNegativeResize = false;
return _this;
}
NewBaseTextItemHandler.prototype.isHighlightNeeded = function () {
return this.editing;
};
Object.defineProperty(NewBaseTextItemHandler.prototype, "textEditorController", {
get: function () {
return this._textEditorController;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "item", {
get: function () {
return this._getItem();
},
set: function (item) {
_super.prototype._setItem.call(this, item);
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "isInEdit", {
get: function () {
var _a;
return (_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.isInEdit;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "textEditor", {
get: function () {
var _a;
return (_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.activeTextEditor;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "editing", {
get: function () {
return this.textEditor != null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "textCropped", {
get: function () {
if (!this.item.checkTextCrop)
return null;
if (this.ready && this.frontEndRenderingReady)
return this._textEditorController.isCropped;
else
return false;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "frontEndRenderingReady", {
get: function () {
var textWhizzReady = this._textWhizz != null;
var textManagerReady = this._textEditorController != null && !this._textEditorController.failed;
var fontsReady = this._fontRegistry != null && this._fontRegistry.ready && this._fontRegistry.containsFonts(this.getFonts());
return textWhizzReady && textManagerReady && fontsReady;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "inPlaceEditingEnabled", {
get: function () {
return this.frontEndRenderingReady && this.item.placeholders.length == 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "exitedEditModeEvent", {
get: function () {
return this._exitedEditModeEvent;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "enteredEditModeEvent", {
get: function () {
return this._enteredEditModeEvent;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NewBaseTextItemHandler.prototype, "colorPreviewService", {
get: function () {
return this._colorPreviewService;
},
enumerable: true,
configurable: true
});
NewBaseTextItemHandler.prototype.updateText = function (text) {
this._modifyItem(function (i) { i.text = text; });
};
NewBaseTextItemHandler.prototype.applyInlineStyle = function (style) {
var _this = this;
if (!style)
return;
applyIfDefined(style.color, function (value) { return _this.item.color = value; });
applyIfDefined(style.font, function (value) {
applyIfDefined(value.postScriptName, function (v) { return _this.item.font.postScriptName = v; });
applyIfDefined(value.allCaps, function (v) { return _this.item.font.allCaps = v; });
applyIfDefined(value.fauxBold, function (v) { return _this.item.font.fauxBold = v; });
applyIfDefined(value.fauxItalic, function (v) { return _this.item.font.fauxItalic = v; });
applyIfDefined(value.size, function (v) { return _this.item.font.size = v; });
});
applyIfDefined(style.leading, function (value) { return _this.item.leading = value; });
applyIfDefined(style.openType, function (value) { return _this.item.font.openTypeFeatures = value; });
applyIfDefined(style.stroke, function (value) {
if (_this.item.stroke == null)
_this.item.stroke = new StrokeSettings();
applyIfDefined(value.color, function (value) { return _this.item.stroke.color = value; });
applyIfDefined(value.size, function (value) { return _this.item.stroke.size = value; });
});
applyIfDefined(style.tracking, function (value) { return _this.item.tracking = value; });
applyIfDefined(style.underline, function (value) { return _this.item.underline = value; });
};
NewBaseTextItemHandler.prototype.applyParagraphStyle = function (paragraphStyle) {
var _this = this;
applyIfDefined(paragraphStyle.alignment, function (v) { return _this.item.alignment = v; });
};
NewBaseTextItemHandler.prototype.isEmpty = function () {
var _a;
return this.item.isEmpty() && !((_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.isInEdit);
};
NewBaseTextItemHandler.prototype.isEmptyTextPlaceholder = function () {
return this.item.isTextPlaceholder && TextUtils.isTextEmpty(this.item.text);
};
NewBaseTextItemHandler.prototype.setTextWhizzModule = function (textWhizz, fontRegistry) {
this._textWhizz = textWhizz;
this._fontRegistry = fontRegistry;
if (this._fontRegistryUpdated != null)
this._fontRegistryUpdated.resolve();
};
NewBaseTextItemHandler.prototype.onTextWhizzInit = function () {
_super.prototype.onTextWhizzInit.call(this);
this.update();
};
NewBaseTextItemHandler.prototype.waitUpdate = function () {
return __awaiter(this, void 0, void 0, function () {
var promisesToWait;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this._isDisposed)
return [2 /*return*/];
promisesToWait = [];
if (!this.frontEndRenderingReady) {
promisesToWait.push(this.waitInitFrontEndRendering());
this.update();
}
if (this.textEditorController)
promisesToWait.push(this.textEditorController.waitUpdate());
promisesToWait.push(_super.prototype.waitUpdate.call(this));
return [4 /*yield*/, Promise.all(promisesToWait)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
NewBaseTextItemHandler.prototype.frontEndUpdate = function (beforeUpdate, afterUpdate, trigger) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this._isDisposed)
return [2 /*return*/];
if (this._fontRegistry == null && this.canvas == null)
return [2 /*return*/];
if (this._handlerUpdated == null)
this._handlerUpdated = new Deferred();
if (!!this._isFrontEndRenderingInitialized()) return [3 /*break*/, 2];
return [4 /*yield*/, AsyncHelper.executeSingle(this._frontEndUpdateExecutionToken, function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.waitInitFrontEndRendering()];
case 1:
_a.sent();
return [2 /*return*/];
}
}); }); }, function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._doFrontEndUpdate(beforeUpdate, afterUpdate, trigger)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); })];
case 1:
_a.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, this._doFrontEndUpdate(beforeUpdate, afterUpdate, trigger)];
case 3:
_a.sent();
_a.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
NewBaseTextItemHandler.prototype.update = function (beforeUpdate, afterUpdate, trigger) {
this._updateImpl(beforeUpdate, afterUpdate, trigger);
};
NewBaseTextItemHandler.prototype.updateAsync = function (beforeUpdate, afterUpdate, trigger) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._updateImpl(beforeUpdate, afterUpdate, trigger)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
NewBaseTextItemHandler.prototype.quickUpdate = function () {
if (this.isVisible() && this.canvas && !this.frontEndRenderingReady) {
this.update();
}
};
NewBaseTextItemHandler.prototype.setRectangle = function (rectangle, supressOnChanged) {
var _a;
var controlBounds = RotatedRectangleF.fromRectangleF(this.getControlBounds());
var transform = rectangle.getTransform(controlBounds);
if (!transform.equals(this.item.transform)) {
this.item.setTransform(transform, supressOnChanged);
if ((_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.isActive) {
this._transformText(transform);
}
}
};
NewBaseTextItemHandler.prototype.updateRectangle = function (rectangle, updateFromTextEdit) {
var changed = false;
this._modifyItem(function (i) {
changed = !RectangleF.isEqual(i.sourceRectangle, rectangle);
if (changed) {
i.sourceRectangle = rectangle;
i.sourcePath = Path.rectangle(rectangle.left, rectangle.top, rectangle.width, rectangle.height);
}
});
if (this.controlPoints == null || this.controlPoints.length == 0) {
changed = true;
}
else {
var cp0 = this.controlPoints[0];
var cp1 = this.controlPoints[1];
var oldRect = RectangleF.FromLTRB(cp0.x, cp0.y, cp1.x, cp1.y);
if (!oldRect.equals(rectangle)) {
changed = true;
}
}
if (changed) {
this.controlPoints = [new PointF(rectangle.left, rectangle.top), new PointF(rectangle.right, rectangle.bottom)];
this.item.getItemChangedEvent().fire();
}
};
NewBaseTextItemHandler.prototype.redrawActiveText = function () {
if (this.canvas == null || this._textEditorController == null)
return;
this._textEditorController.redrawActiveText();
};
NewBaseTextItemHandler.prototype.drawItemHandler = function (itemHandlerCtx) {
var _a, _b;
if (itemHandlerCtx == null || this.canvas == null || this._textWhizz == null)
return;
if (!this._isReadyToDraw) {
this.canvas.drawWaitClock(itemHandlerCtx, this.rectangle.center);
return;
}
var renderForEyeDropper = this.ready && !((_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.isStatic) && this.canvas.isSelectionLocked;
if (this._hasVectorMask() && !renderForEyeDropper) {
itemHandlerCtx.save();
this._clip(itemHandlerCtx);
}
if (!this._isMobileTextEditorActive || renderForEyeDropper) {
var opacityMultiplier = this.isEmptyTextPlaceholder() ? 0.5 : 1;
this.renderFill(itemHandlerCtx, opacityMultiplier);
if (!this.ready || ((_b = this._textEditorController) === null || _b === void 0 ? void 0 : _b.isStatic) || renderForEyeDropper) {
try {
TextRenderer.renderTextImage(this, this._imageContainer, null, itemHandlerCtx, opacityMultiplier, TextRenderer.staticCanvasMargin);
}
catch (e) {
console.error(e);
}
}
this.renderStroke(itemHandlerCtx, opacityMultiplier);
}
if (this._hasVectorMask() && !renderForEyeDropper)
itemHandlerCtx.restore();
this._drawHandlerEffects(itemHandlerCtx);
};
NewBaseTextItemHandler.prototype.clearImageContainer = function () {
this._imageContainer.clear();
};
NewBaseTextItemHandler.prototype._endTransform = function (changed, resized) {
_super.prototype._endTransform.call(this, changed, resized);
if (!changed || !resized || !this.frontEndRenderingReady)
return;
this.update(null, null, this._getEndTransformTrigger(resized));
};
NewBaseTextItemHandler.prototype.processInPlaceEditingMouseEvent = function (e, mouseOverCurrent) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.inPlaceEditingEnabled)
throw new Exception("Inplace is not enabled for this item!");
return [4 /*yield*/, this._textEditorController.processMouseEvent(e, mouseOverCurrent)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
NewBaseTextItemHandler.prototype.processInPlaceEditingKeyEvent = function (e) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.inPlaceEditingEnabled)
throw new Exception("Inplace is not enabled for this item!");
e.preventDefault();
if (!(e.state !== InputState.Finished)) return [3 /*break*/, 2];
return [4 /*yield*/, this._textEditorController.processKeyEvent(e)];
case 1: return [2 /*return*/, _a.sent()];
case 2: return [2 /*return*/, true];
}
});
});
};
NewBaseTextItemHandler.prototype.enterEditMode = function () {
if (!this.inPlaceEditingEnabled)
throw new Exception("Inplace is not enabled for this item!");
return this._textEditorController.enterEditMode(0, 0);
};
NewBaseTextItemHandler.prototype.exitEditMode = function (stayActive) {
if (stayActive === void 0) { stayActive = false; }
if (!this.inPlaceEditingEnabled)
throw new Exception("Inplace is not enabled for this item!");
return this._textEditorController.exitEditMode(stayActive);
};
NewBaseTextItemHandler.prototype.getTextForRendering = function () {
return this.isEmptyTextPlaceholder() ? this.item.originalText : this.item.text;
};
NewBaseTextItemHandler.prototype.dispose = function () {
var _a, _b, _c;
(_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.exitedEditModeEvent.remove(this._onTextManagerExitedEditMode);
(_b = this._textEditorController) === null || _b === void 0 ? void 0 : _b.enteredEditModeEvent.remove(this._onTextManagerEnteredEditMode);
(_c = this._textEditorController) === null || _c === void 0 ? void 0 : _c.dispose();
this._textEditorController = null;
this._imageContainer.dispose();
_super.prototype.dispose.call(this);
};
NewBaseTextItemHandler.prototype.getFonts = function () {
return __spread([
this.item.font.postScriptName
], Utils.getFontNames(this.item.text), Utils.getFontNames(this.item.originalText));
};
NewBaseTextItemHandler.prototype._isReady = function () {
var _a;
return _super.prototype._isReady.call(this) && ((_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.ready);
};
NewBaseTextItemHandler.prototype._drawHandlerEffects = function (ctx) { };
NewBaseTextItemHandler.prototype._getColors = function () {
var _a;
return __spread([this.item.color], (_a = this.item.colorPalette) === null || _a === void 0 ? void 0 : _a.toArray(), _super.prototype._getColors.call(this));
};
NewBaseTextItemHandler.prototype._updateImpl = function (beforeUpdate, afterUpdate, trigger) {
return __awaiter(this, void 0, void 0, function () {
var postUpdate;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this.isVisible() || trigger == "text")) return [3 /*break*/, 2];
postUpdate = function () {
var _a, _b;
if (typeof afterUpdate == "function")
afterUpdate();
(_a = _this.canvas) === null || _a === void 0 ? void 0 : _a.updateSelection(true);
(_b = _this.canvas) === null || _b === void 0 ? void 0 : _b.redrawDesign();
};
return [4 /*yield*/, this.frontEndUpdate(beforeUpdate, postUpdate, trigger)];
case 1:
_a.sent();
return [3 /*break*/, 3];
case 2:
if (typeof beforeUpdate == "function") {
beforeUpdate();
}
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
};
NewBaseTextItemHandler.prototype._onItemPropertyChanged = function (sender, propertyName) {
var _a;
switch (propertyName) {
case "text":
(_a = this.textEditorController) === null || _a === void 0 ? void 0 : _a.initialize();
this.update(null, null, "text");
break;
case "font":
case "underline":
case "color":
case "alignment":
case "leading":
case "tracking":
case "verticalScale":
case "horizontalScale":
case "previewScale":
case "stroke":
case "shadow":
case "baselineShift":
case "overlapLinesEnabled":
case "maxLineCount":
case "maxLineLength":
this.update();
break;
case "checkTextCrop":
if (!this.frontEndRenderingReady && sender.checkTextCrop)
this.update();
break;
default:
}
if (propertyName !== "checkTextCrop")
_super.prototype._onItemPropertyChanged.call(this, sender, propertyName);
};
NewBaseTextItemHandler.prototype._onItemVisibilityChanged = function () {
var _a, _b, _c;
_super.prototype._onItemVisibilityChanged.call(this);
if ((_a = this.canvas) === null || _a === void 0 ? void 0 : _a.isItemHandlerSelected(this)) {
if (this.isVisible())
(_b = this._textEditorController) === null || _b === void 0 ? void 0 : _b.updateItemHandler();
else
(_c = this._textEditorController) === null || _c === void 0 ? void 0 : _c.clearText();
}
};
NewBaseTextItemHandler.prototype._setDataItem = function (itemData, itemHandlerData) {
throw new NotImplementedException("NewBaseTextItemHandler._setDataItem");
};
NewBaseTextItemHandler.prototype._createDataInstance = function (itemHandler) {
throw new NotImplementedException("NewBaseTextItemHandler._createDataInstance");
};
NewBaseTextItemHandler.prototype._onAddedOnCanvas = function (canvas) {
var _a;
this._textWhizz = canvas.textWhizz;
_super.prototype._onAddedOnCanvas.call(this, canvas);
(_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.bindToCanvas(canvas);
};
NewBaseTextItemHandler.prototype._onRemovedFromCanvas = function (canvas) {
var _a;
_super.prototype._onRemovedFromCanvas.call(this, canvas);
(_a = this._textEditorController) === null || _a === void 0 ? void 0 : _a.unbindFromCanvas();
};
NewBaseTextItemHandler.prototype._transformText = function (transform) {
this._textEditorController.transformText(transform);
};
NewBaseTextItemHandler.prototype._getBoundsMargin = function () {
return this._getActualBorderWidth() * 2;
};
NewBaseTextItemHandler.prototype.renderFill = function (itemHandlerCtx, opacityMultiplier) {
var item = this.item;
var rectangle = this.rectangle;
var fillColorPreview = this._getItemColorPreviews().fillColorPreview;
Graphics.fillRectangle(itemHandlerCtx, rectangle, fillColorPreview === null || fillColorPreview === void 0 ? void 0 : fillColorPreview.toString(), item.opacity * opacityMultiplier);
};
NewBaseTextItemHandler.prototype.renderStroke = function (itemHandlerCtx, opacityMultiplier) {
var borderWidth = this._getActualBorderWidth();
if (borderWidth <= 0)
return;
var item = this.item;
var rectangle = this.rectangle;
rectangle.width += borderWidth;
rectangle.height += borderWidth;
var path = Path.rotatedRectangle(rectangle);
var _a = this._getItemColorPreviews(), borderColorPreview = _a.borderColorPreview, altBorderColorPreview = _a.altBorderColorPreview;
Graphics.drawStroke(itemHandlerCtx, path, rectangle.center, new Transform(), borderWidth, borderColorPreview.toString(), altBorderColorPreview === null || altBorderColorPreview === void 0 ? void 0 : altBorderColorPreview.toString(), item.opacity * opacityMultiplier, item.dash);
};
NewBaseTextItemHandler.prototype._getEndTransformTrigger = function (resized) {
return "frame";
};
NewBaseTextItemHandler.prototype._onFrontEndRenderingInitialized = function () {
};
NewBaseTextItemHandler.prototype._initFrontEndRendering = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this._textEditorController = this._textEditorControllerFactory.create(this, this._textWhizz);
return [4 /*yield*/, this._textEditorController.initialize()];
case 1:
_a.sent();
this._textEditorController.add_staticTextImageChanged(this._onStaticTextImageChanged);
this._textEditorController.exitedEditModeEvent.add(this._onTextManagerExitedEditMode.bind(this));
this._textEditorController.enteredEditModeEvent.add(this._onTextManagerEnteredEditMode.bind(this));
this._textEditorController.bindToCanvas(this.canvas);
this._onFrontEndRenderingInitialized();
return [2 /*return*/];
}
});
});
};
NewBaseTextItemHandler.prototype._onTextManagerEnteredEditMode = function () {
this._enteredEditModeEvent.notify(this);
this.canvas.redrawActiveTexts();
};
NewBaseTextItemHandler.prototype._onTextManagerExitedEditMode = function () {
this._exitedEditModeEvent.notify(this);
};
NewBaseTextItemHandler.prototype._getPreviewScaleLimits = function () {
var maxPreviewScale = null;
var minPreviewScale = null;
if (this.canvas != null && this.canvas.maxFontSize != null && !isNaN(this.canvas.maxFontSize))
maxPreviewScale = this.canvas.maxFontSize / this.item.font.size;
if (this.canvas != null && this.canvas.minFontSize != null && !isNaN(this.canvas.minFontSize))
minPreviewScale = this.canvas.minFontSize / this.item.font.size;
return { min: minPreviewScale, max: maxPreviewScale };
};
NewBaseTextItemHandler.prototype.waitInitFrontEndRendering = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, font, e_1_1;
var e_1, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (this._fontRegistry != null && this._textEditorController != null)
return [2 /*return*/];
if (this._initFrontEndRenderingDef != null)
return [2 /*return*/, this._initFrontEndRenderingDef.promise];
this._initFrontEndRenderingDef = new Deferred();
return [4 /*yield*/, this._waitFontRegistryInitialized()];
case 1:
_d.sent();
_d.label = 2;
case 2:
_d.trys.push([2, 7, 8, 9]);
_a = __values(this.getFonts()), _b = _a.next();
_d.label = 3;
case 3:
if (!!_b.done) return [3 /*break*/, 6];
font = _b.value;
if (!!this._fontRegistry.containsFonts([font])) return [3 /*break*/, 5];
return [4 /*yield*/, this._fontRegistry.loadFonts([font])];
case 4:
_d.sent();
_d.label = 5;
case 5:
_b = _a.next();
return [3 /*break*/, 3];
case 6: return [3 /*break*/, 9];
case 7:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 9];
case 8:
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 9: return [4 /*yield*/, this._initFrontEndRendering()];
case 10:
_d.sent();
this._initFrontEndRenderingDef.resolve();
this._initFrontEndRenderingDef = null;
return [2 /*return*/];
}
});
});
};
NewBaseTextItemHandler.prototype._waitFontRegistryInitialized = function () {
if (this._fontRegistry != null)
return Promise.resolve();
if (this._fontRegistryUpdated == null)
this._fontRegistryUpdated = new Deferred();
return this._fontRegistryUpdated.promise;
};
NewBaseTextItemHandler.prototype._pathToTextWhizzPath = function (path) {
return toTextWhizzPath(this._textWhizz, path);
};
Object.defineProperty(NewBaseTextItemHandler.prototype, "_isMobileTextEditorActive", {
get: function () {
return this.textEditor instanceof MobileTextEditor;
},
enumerable: true,
configurable: true
});
NewBaseTextItemHandler.prototype._beforeFrontEndUpdate = function () {
var _this = this;
if (this.item.transform.isEmpty)
return;
var center = this.getControlCenter();
var transform = this.item.transform.clone();
transform.setAngle(0);
this._modifyItem(function (i) {
var _a;
_this._applyTransform(i, transform, center);
if (((_a = i.mask) === null || _a === void 0 ? void 0 : _a.vectorMask) != null)
i.mask.vectorMask = _this._getTransformedClippingPath(transform);
i.transform.clear({ keepAngle: true, supressOnChanged: true });
});
};
NewBaseTextItemHandler.prototype._isFrontEndRenderingInitialized = function () {
return this._textEditorController != null && this._fontRegistry != null;
};
NewBaseTextItemHandler.prototype._doFrontEndUpdate = function (beforeUpdate, afterUpdate, trigger) {
return __awaiter(this, void 0, void 0, function () {
var innerUpdate;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this._isDisposed || this.canvas == null) {
if (this._handlerUpdated != null) {
this._handlerUpdated.resolve();
this._handlerUpdated = null;
}
return [2 /*return*/];
}
innerUpdate = function () { return __awaiter(_this, void 0, void 0, function () {
var e_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (typeof beforeUpdate == "function")
beforeUpdate();
this._beforeFrontEndUpdate();
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this._textEditorController.updateText(trigger)];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
e_2 = _a.sent();
console.log(this._textWhizz.getExceptionMessage(e_2));
console.log(this._textWhizz.getExceptionName(e_2));
throw e_2;
case 4:
if (typeof afterUpdate == "function")
afterUpdate();
if (this._handlerUpdated != null) {
this._handlerUpdated.resolve();
this._handlerUpdated = null;
}
return [2 /*return*/];
}
});
}); };
if (!this.frontEndRenderingReady) return [3 /*break*/, 2];
return [4 /*yield*/, innerUpdate()];
case 1:
_a.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, this._waitLoadFonts(innerUpdate)];
case 3:
_a.sent();
_a.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
NewBaseTextItemHandler.prototype._waitLoadFonts = function (innerUpdate) {
var _this = this;
this._waitLoadFontsLastInnerUpdate = innerUpdate;
if (this._waitLoadFontsDef != null)
return this._waitLoadFontsDef.promise;
this._waitLoadFontsDef = new Deferred();
var promises = new Array();
promises.push(this._fontRegistry.loadFonts(this.getFonts()));
Promise.all(promises)
.then(function () {
if (_this._waitLoadFontsLastInnerUpdate)
_this._waitLoadFontsLastInnerUpdate();
_this._waitLoadFontsDef.resolve();
_this._waitLoadFontsDef = null;
})
.catch(function (e) {
_this._waitLoadFontsDef.reject(e);
_this._waitLoadFontsDef = null;
});
return this._waitLoadFontsDef.promise;
};
NewBaseTextItemHandler.prototype._needToDrawBaseline = function () {
if (this.isInEdit && this.textEditor.disableDrawBaseline)
return false;
var states = this._getBaselineDrawStates();
var currentState = this._getCurrentState();
if (states.includes(currentState))
return true;
};
NewBaseTextItemHandler.prototype._getBaselineDrawStates = function () {
return [];
};
NewBaseTextItemHandler.prototype._getCurrentState = function () {
if (this.isInEdit)
return ItemHandlerState.edit;
if (this.canvas.isItemHandlerSelected(this)) {
if (this.canvas.isSelectionResizing)
return ItemHandlerState.resize;
if (this.canvas.isSelectionDragging)
return ItemHandlerState.move;
if (this.canvas.isSelectionRotating)
return ItemHandlerState.rotate;
return ItemHandlerState.select;
}
if (this.canvas.hoverHandler.currentHandler == this)
return ItemHandlerState.hover;
return ItemHandlerState.idle;
};
NewBaseTextItemHandler.typeName = "NewBaseTextItemHandler";
return NewBaseTextItemHandler;
}(ShapeItemHandler));
export { NewBaseTextItemHandler };
//# sourceMappingURL=NewBaseTextItemHandler.js.map