UNPKG

medsurf-draw

Version:

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

120 lines 5.32 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 { Design } from "../../config/design"; import { BaseContainer, BaseContainerImageModel } from "../../bases/elements/BaseContainer"; var CaretElementModel = (function (_super) { __extends(CaretElementModel, _super); function CaretElementModel() { return _super !== null && _super.apply(this, arguments) || this; } return CaretElementModel; }(BaseContainerImageModel)); export { CaretElementModel }; var CaretElement = (function (_super) { __extends(CaretElement, _super); function CaretElement(model) { var _this = _super.call(this, model) || this; _this.zIndex = Design.caretElement.zIndex; _this.hideItem(); return _this; } CaretElement.prototype.init = function () { this._caretElement = new MedsurfDraw.Rectangle({ rectangle: new PIXI.Rectangle(0, 0, Design.caretElement.lineWidth, 0), options: { hasLine: false, hasFill: true, fillColor: Design.caretElement.fillColor, fillAlpha: Design.caretElement.fillAlpha }, lineWidth: Design.caretElement.lineWidth }); this.addChild(this._caretElement); this.sortChildren(); this.emit("debounceDraw"); }; CaretElement.prototype.draw = function () { this._caretElement.draw(); }; CaretElement.prototype.destroy = function (options) { if (this._caretElement) { this._caretElement.destroy(options); } _super.prototype.destroy.call(this, options); }; CaretElement.prototype.onCaret = function () { if (!this.textElement) { return; } var text = this.textElement.text.substring(0, this.textElement.startTextIndex); var heightFactor = 0; var index = text.indexOf("\n"); while (index > -1) { text = text.substring(index + 1); heightFactor++; index = text.indexOf("\n"); } if (this.textElement.style.wordWrap) { var startIndex = 0; var wordWrapRows = 0; for (var i = 1; i <= text.length; i++) { var tmpText = text.substring(startIndex, i); var tmpWidth = this.textElement.context.measureText(tmpText).width; if (tmpWidth > this.textElement.style ? this.textElement.style.wordWrapWidth || 0 : 0) { wordWrapRows++; startIndex = (i - 1); } } this._caretElement.position.x = this.textElement.context.measureText(text.substr(startIndex)).width; var localHeight = this.textElement.style.fontSize + this.textElement.style.strokeThickness + this.textElement.style.lineHeight + 6; this._caretElement.position.y = wordWrapRows * localHeight + localHeight * heightFactor; } else { this._caretElement.position.x = this.textElement.context.measureText(text).width; var localHeight = this.textElement.style.fontSize + this.textElement.style.strokeThickness + this.textElement.style.lineHeight + 6; this._caretElement.position.y = localHeight * heightFactor; } }; CaretElement.prototype.showItem = function () { if (this._caretFlashIntervalTimeout) { clearInterval(this._caretFlashIntervalTimeout); this._caretFlashIntervalTimeout = null; } this.emit("debounceDraw"); this._caretFlashIntervalTimeout = setInterval(this.toggleItem.bind(this), 500); _super.prototype.showItem.call(this); }; CaretElement.prototype.hideItem = function () { if (this._caretFlashIntervalTimeout) { clearInterval(this._caretFlashIntervalTimeout); this._caretFlashIntervalTimeout = null; } _super.prototype.hideItem.call(this); }; Object.defineProperty(CaretElement.prototype, "textElement", { get: function () { return this.data.textElement; }, set: function (value) { this.data.textElement = value; if (this.textElement) { this._caretElement.rectangle.height = this.textElement.style.fontSize + this.textElement.style.strokeThickness + this.textElement.style.lineHeight + 2; } }, enumerable: false, configurable: true }); return CaretElement; }(BaseContainer)); export { CaretElement }; //# sourceMappingURL=CaretElement.js.map