UNPKG

medsurf-draw

Version:

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

115 lines 4.91 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 { BaseContainer, BaseContainerImageModel } from "../../bases/elements/BaseContainer"; import { BaseGraphics } from "../../bases/elements/BaseGraphics"; import { Design } from "../../config/design"; var SelectionElementModel = (function (_super) { __extends(SelectionElementModel, _super); function SelectionElementModel() { return _super !== null && _super.apply(this, arguments) || this; } return SelectionElementModel; }(BaseContainerImageModel)); export { SelectionElementModel }; var SelectionElement = (function (_super) { __extends(SelectionElement, _super); function SelectionElement(model) { var _this = _super.call(this, model) || this; _this.zIndex = Design.selectionElement.zIndex; _this.hideItem(); return _this; } SelectionElement.prototype.init = function () { this._selectionElement = new BaseGraphics({ image: this.image }); this.addChild(this._selectionElement); this.sortChildren(); this.emit("debounceDraw"); }; SelectionElement.prototype.draw = function () { this._selectionElement.cacheAsBitmap = false; this._selectionElement.clear(); if (!this.textElement || !this.textElement.textSelection || !this.textElement.style) { return; } var localHeight = this.textElement.style.fontSize + this.textElement.style.strokeThickness + this.textElement.style.lineHeight + 6; var selectionStart; var selectionEnd; if (this.textElement.startTextIndex > this.textElement.endTextIndex) { selectionStart = this.textElement.endTextIndex; selectionEnd = this.textElement.startTextIndex; } else { selectionStart = this.textElement.startTextIndex; selectionEnd = this.textElement.endTextIndex; } var previousText = this.textElement.text.substring(0, selectionStart); var heightFactor = 0; var index = previousText.indexOf("\n"); while (index > -1) { previousText = previousText.substring(index + 1); heightFactor++; index = previousText.indexOf("\n"); } var offset = this.textElement.context.measureText(previousText).width; var text = this.textElement.text.substring(selectionStart, selectionEnd); do { index = text.indexOf("\n"); var displayText = void 0; if (index > -1) { displayText = text.substring(0, index); } else { displayText = text; } var selectedWidth = this.textElement.context.measureText(displayText).width; this._selectionElement.beginFill(Design.selectionElement.fillColor, Design.selectionElement.fillAlpha); this._selectionElement.drawRect(offset, localHeight * heightFactor, selectedWidth, localHeight); this._selectionElement.endFill(); text = text.substring(index + 1); heightFactor++; offset = 0; } while (index > -1); this._selectionElement.cacheAsBitmap = true; }; SelectionElement.prototype.destroy = function (options) { if (this._selectionElement) { this._selectionElement.destroy(options); } _super.prototype.destroy.call(this, options); }; SelectionElement.prototype.onSelection = function () { if (this.textElement && this.textElement.textSelection && this.textElement.startTextIndex !== this.textElement.endTextIndex) { this.showItem(); this.emit("debounceDraw"); } else { this.hideItem(); } }; Object.defineProperty(SelectionElement.prototype, "textElement", { get: function () { return this.data.textElement; }, set: function (value) { this.data.textElement = value; }, enumerable: false, configurable: true }); return SelectionElement; }(BaseContainer)); export { SelectionElement }; //# sourceMappingURL=SelectionElement.js.map