all files / core/elements/ text-element.js

96.72% Statements 59/61
83.33% Branches 25/30
94.44% Functions 17/18
96.55% Lines 56/58
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147                      23×       23×   23×   23×   23× 23×       23×             23× 23× 23×           112×           22× 22× 22× 22×                   23×           22×                 45×           22×                       22× 22× 22×         22×     15×   22× 22×           22× 22×   22× 22× 22× 22×        
/* istanbul ignore next */ 
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 __());
    };
})();
define(["require", "exports", "../../primitives/size", "./drawing-element", "./../../utility/dom-util"], function (require, exports, size_1, drawing_element_1, dom_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**
     * TextElement is used to display text/annotations
     */
    var TextElement = /** @class */ (function (_super) {
        __extends(TextElement, _super);
        /**
         * set the id for each element
         */
        function TextElement() {
            var _this = _super.call(this) || this;
            /**
             * sets or gets the image source
             */
            _this.textContent = '';
            /** @private */
            _this.canMeasure = true;
            /** @private */
            _this.canConsiderBounds = true;
            /** @private */
            _this.doWrap = true;
            _this.textNodes = [];
            /**
             * Defines the appearance of the text element
             */
            _this.style = {
                color: 'black', fill: 'transparent', strokeColor: 'black',
                strokeWidth: 1, fontFamily: 'Arial', fontSize: 12, whiteSpace: 'CollapseSpace',
                textWrapping: 'WrapWithOverflow', textAlign: 'Center', italic: false, bold: false,
                textDecoration: 'None', strokeDashArray: '', opacity: 1,
                textOverflow: 'Wrap'
            };
            _this.style.fill = 'transparent';
            _this.style.strokeColor = 'transparent';
            return _this;
        }
        Object.defineProperty(TextElement.prototype, "content", {
            /**
             * gets the content for the text element
             */
            get: function () {
                return this.textContent;
            },
            /**
             * sets the content for the text element
             */
            set: function (value) {
                Eif (this.textContent !== value) {
                    this.textContent = value;
                    this.isDirt = true;
                    this.doWrap = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(TextElement.prototype, "childNodes", {
            /**
             * sets the content for the text element
             */
            get: function () {
                return this.textNodes;
            },
            /**
             * gets the content for the text element
             */
            set: function (value) {
                this.textNodes = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(TextElement.prototype, "wrapBounds", {
            /**
             * gets the wrapBounds for the text
             */
            get: function () {
                return this.textWrapBounds;
            },
            /**
             * sets the wrapBounds for the text
             */
            set: function (value) {
                this.textWrapBounds = value;
            },
            enumerable: true,
            configurable: true
        });
        /** @private */
        TextElement.prototype.refreshTextElement = function () {
            this.isDirt = true;
        };
        /**
         * Measures the minimum size that is required for the text element
         * @param availableSize
         */
        TextElement.prototype.measure = function (availableSize) {
            var size;
            Eif (this.isDirt && this.canMeasure) {
                size = dom_util_1.measureText(this, this.style, this.content, this.width || availableSize.width);
            }
            else {
                size = this.desiredSize;
            }
            if (this.width === undefined || this.height === undefined) {
                this.desiredSize = new size_1.Size(size.width, size.height);
            }
            else {
                this.desiredSize = new size_1.Size(this.width, this.height);
            }
            this.desiredSize = this.validateDesiredSize(this.desiredSize, availableSize);
            return this.desiredSize;
        };
        /**
         * Arranges the text element
         * @param desiredSize
         */
        TextElement.prototype.arrange = function (desiredSize) {
            Eif (desiredSize.width !== this.actualSize.width || desiredSize.height !== this.actualSize.height || this.isDirt) {
                this.doWrap = true;
            }
            this.actualSize = desiredSize;
            this.updateBounds();
            this.isDirt = false;
            return this.actualSize;
        };
        return TextElement;
    }(drawing_element_1.DrawingElement));
    exports.TextElement = TextElement;
});