UNPKG

medsurf-draw

Version:

Draw annotations on jpg/zoomify images, based on PIXI.js

184 lines 8.11 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as PIXI from "pixi.js-legacy"; import * as MedsurfDraw from "../../public-api"; import { BaseText, BaseTextImageModel } from "../../bases/elements/BaseText"; import { Design } from "../../config/design"; var EditableTextModel = (function (_super) { __extends(EditableTextModel, _super); function EditableTextModel() { return _super !== null && _super.apply(this, arguments) || this; } return EditableTextModel; }(BaseTextImageModel)); export { EditableTextModel }; var EditableText = (function (_super) { __extends(EditableText, _super); function EditableText(model) { var _this = _super.call(this, model) || this; _this.startTextIndex = _this.data.text.length; _this.endTextIndex = _this.data.text.length; _this.textSelection = false; _this.modeInteraction.on('select_item', _this._modeSelectItem, _this); _this.modeInteraction.on("remove-select_item", _this._removeModeSelectItem, _this); _this.writeInteraction = new MedsurfDraw.WriteInteraction(_this); _this.writeInteraction.on("onText", _this.onText, _this); _this.writeInteraction.on("endText", _this.endText, _this); return _this; } EditableText.prototype.init = function () { this._copyMethod = this.writeInteraction.onCopy.bind(this.writeInteraction); this._cutMethod = this.writeInteraction.onCut.bind(this.writeInteraction); this._pasteMethod = this.writeInteraction.onPaste.bind(this.writeInteraction); this.sortChildren(); this.onImageZoom(this.imageScale.x, this.imageScale.y); }; EditableText.prototype.destroy = function (options) { if (this.modeInteraction) { this.modeInteraction.off('select_item', this._modeSelectItem, this); this.modeInteraction.off("remove-select_item", this._removeModeSelectItem, this); } if (this.writeInteraction) { this.writeInteraction.off("onText", this.onText, this); this.writeInteraction.off("endText", this.endText, this); } _super.prototype.destroy.call(this, options); }; EditableText.prototype._modeSelectItem = function () { this.interactive = true; MedsurfDraw.Keyboard.events.on("down", "onTextPrimitiveKeyDown", this.writeInteraction.onKeyDown.bind(this.writeInteraction)); MedsurfDraw.Keyboard.events.on("pressed", "onTextPrimitiveKeyPress", this.writeInteraction.onKeyPressed.bind(this.writeInteraction)); MedsurfDraw.Keyboard.events.on("released", "onTextPrimitiveKeyUp", this.writeInteraction.onKeyReleased.bind(this.writeInteraction)); document.addEventListener("copy", this._copyMethod); document.addEventListener("cut", this._cutMethod); document.addEventListener("paste", this._pasteMethod); this.image.controlUpdateElements(); this.showItem(); this.emit("pointerover", new PIXI.InteractionEvent()); }; EditableText.prototype._removeModeSelectItem = function (parent, mode) { this.interactive = false; MedsurfDraw.Keyboard.events.remove("down", "onTextPrimitiveKeyDown"); MedsurfDraw.Keyboard.events.remove("pressed", "onTextPrimitiveKeyPress"); MedsurfDraw.Keyboard.events.remove("released", "onTextPrimitiveKeyUp"); document.removeEventListener("copy", this._copyMethod); document.removeEventListener("cut", this._cutMethod); document.removeEventListener("paste", this._pasteMethod); if (mode !== 'select_child' && !mode.startsWith('select_item') && mode !== 'delete') { if (this.parent instanceof MedsurfDraw.TextPrimitive || this.parent instanceof MedsurfDraw.LegendRow) { parent.emit("debounceControlSelectItem"); } } }; EditableText.prototype.controlSelectItem = function () { var _this = this; this.image.getImageObjects() .filter(function (imageObject) { return imageObject !== _this.parent.parent; }) .forEach(function (imageObject) { imageObject.modeInteraction.setMode('blocked_item'); }); if (this.parent instanceof MedsurfDraw.TextPrimitive) { this.parent.modeInteraction.setModeItem('select_child'); } if (this.parent instanceof MedsurfDraw.LegendRow) { this.parent.modeInteraction.setModeItem('select_child'); } this.modeInteraction.setModeChildren('select_parent'); this.modeInteraction.setModeItem('select_item'); }; EditableText.prototype.selectEndText = function () { this.writeInteraction.selectEndText(); }; EditableText.prototype.selectAllText = function () { this.writeInteraction.selectAllText(); }; EditableText.prototype.onText = function (text) { this.emit("onText", text); }; EditableText.prototype.endText = function () { this.emit("endText"); }; EditableText.prototype.onImageZoom = function (scaleX, scaleY) { var resolution = Math.round(scaleX); if (resolution < Design.text.minResolution) { resolution = Design.text.minResolution; } if (resolution > Design.text.maxResolution) { resolution = Design.text.maxResolution; } this.resolution = resolution; }; EditableText.prototype.getRectangle = function () { try { if (this.parent instanceof MedsurfDraw.TextPrimitive || this.parent instanceof MedsurfDraw.LegendRow) { return this.parent.getRectangle(); } return _super.prototype.getRectangle.call(this); } catch (e) { return new PIXI.Rectangle(this.position.x, this.position.y, 1, 1); } }; EditableText.prototype.getRotation = function () { if (this.parent instanceof MedsurfDraw.TextPrimitive || this.parent instanceof MedsurfDraw.LegendRow) { return this.parent.rotation; } return this.rotation; }; Object.defineProperty(EditableText.prototype, "startTextIndex", { get: function () { return this._startTextIndex; }, set: function (value) { this._startTextIndex = value; }, enumerable: false, configurable: true }); Object.defineProperty(EditableText.prototype, "endTextIndex", { get: function () { return this._endTextIndex; }, set: function (value) { this._endTextIndex = value; }, enumerable: false, configurable: true }); Object.defineProperty(EditableText.prototype, "textSelection", { get: function () { return this._textSelection; }, set: function (value) { this._textSelection = value; }, enumerable: false, configurable: true }); Object.defineProperty(EditableText.prototype, "writeInteraction", { get: function () { return this._writeInteraction; }, set: function (value) { this._writeInteraction = value; }, enumerable: false, configurable: true }); return EditableText; }(BaseText)); export { EditableText }; //# sourceMappingURL=EditableText.js.map