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

97.78% Statements 44/45
91.3% Branches 21/23
100% Functions 13/13
97.62% Lines 41/42
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                                                                                                                     
/* 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 });
    /**
     * ImageElement defines a basic image elements
     */
    var ImageElement = /** @class */ (function (_super) {
        __extends(ImageElement, _super);
        /**
         * set the id for each element
         */
        function ImageElement() {
            var _this = _super.call(this) || this;
            /**
             * sets or gets the image source
             */
            _this.imageSource = '';
            /**
             * sets or gets the print id
             * @private
             */
            _this.printID = '';
            /**
             * sets scaling factor of the image
             */
            _this.imageScale = 'None';
            /**
             * sets the alignment of the image
             */
            _this.imageAlign = 'None';
            /**
             * Sets how to stretch the image
             */
            _this.stretch = 'Stretch';
            return _this;
        }
        Object.defineProperty(ImageElement.prototype, "source", {
            /**
             * Gets the source for the image element
             */
            get: function () {
                return this.imageSource;
            },
            /**
             * Sets the source for the image element
             */
            set: function (value) {
                this.imageSource = value;
                this.isDirt = true;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * Measures minimum space that is required to render the image
         * @param availableSize
         */
        ImageElement.prototype.measure = function (availableSize) {
            if (this.isDirt && (this.stretch !== 'Stretch' || this.width === undefined && this.height === undefined)) {
                this.contentSize = dom_util_1.measureImage(this.source, this.contentSize);
                this.isDirt = false;
            }
            Eif (this.width !== undefined && this.height !== undefined) {
                this.desiredSize = new size_1.Size(this.width, this.height);
                this.contentSize = this.desiredSize;
            }
            else {
                this.desiredSize = this.contentSize;
            }
            this.desiredSize = this.validateDesiredSize(this.desiredSize, availableSize);
            return this.desiredSize;
        };
        /**
         * Arranges the image
         * @param desiredSize
         */
        ImageElement.prototype.arrange = function (desiredSize) {
            this.actualSize = new size_1.Size(this.desiredSize.width, this.desiredSize.height);
            this.updateBounds();
            return this.actualSize;
        };
        return ImageElement;
    }(drawing_element_1.DrawingElement));
    exports.ImageElement = ImageElement;
});