all files / barcode/utility/ dom-util.js

94.2% Statements 65/69
77.78% Branches 14/18
100% Functions 9/9
94.2% Lines 65/69
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   263× 263× 263×   263×   2280× 2280× 2280×                 2280×   2280×   2280× 2280× 2280× 2280× 2280× 2280× 2280× 2280× 2280× 2280× 2280× 2280× 2280×   980× 980× 2700× 7860× 7860× 480× 480× 2040× 2040× 1680×         7380×         717× 717× 717×   724× 724× 120×       120× 120× 120× 120× 120× 120× 120× 120× 120× 120× 120×     604×        
define(["require", "exports", "@syncfusion/ej2-base", "../primitives/size"], function (require, exports, ej2_base_1, size_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function createHtmlElement(elementType, attribute) {
        var element = ej2_base_1.createElement(elementType);
        Eif (attribute) {
            setAttribute(element, attribute);
        }
        return element;
    }
    exports.createHtmlElement = createHtmlElement;
    function getChildNode(node) {
        var child;
        var collection = [];
        Iif (ej2_base_1.Browser.info.name === 'msie' || ej2_base_1.Browser.info.name === 'edge') {
            for (var i = 0; i < node.childNodes.length; i++) {
                child = node.childNodes[parseInt(i.toString(), 10)];
                if (child.nodeType === 1) {
                    collection.push(child);
                }
            }
        }
        else {
            collection = node.children;
        }
        return collection;
    }
    exports.getChildNode = getChildNode;
    function measureText(textContent) {
        var measureElement = 'barcodeMeasureElement';
        window["" + measureElement].style.visibility = 'visible';
        var svg = window["" + measureElement].children[1];
        var text = getChildNode(svg)[0];
        text.textContent = textContent.string;
        text.style.fontSize = textContent.stringSize + 'px';
        text.style.fontFamily = textContent.fontStyle;
        text.style.fontWeight = '';
        var bBox = new size_1.Size(0, 0);
        bBox.width = text.getBBox().width;
        bBox.height = text.getBBox().height;
        window["" + measureElement].style.visibility = 'hidden';
        return bBox;
    }
    exports.measureText = measureText;
    function setAttribute(element, attributes) {
        var keys = Object.keys(attributes);
        for (var i = 0; i < keys.length; i++) {
            keys.forEach(function (key) {
                var value = attributes[key];
                if (key === 'style' && typeof value === 'string') {
                    var styleProperties = value.split(';');
                    styleProperties.forEach(function (property) {
                        var _a = property.split(':'), propName = _a[0], propValue = _a[1];
                        if (propName && propValue) {
                            element.style.setProperty(propName.trim(), propValue.trim());
                        }
                    });
                }
                else {
                    element.setAttribute(key, value);
                }
            });
        }
    }
    exports.setAttribute = setAttribute;
    function createSvgElement(elementType, attribute) {
        var element = document.createElementNS('http://www.w3.org/2000/svg', elementType);
        setAttribute(element, attribute);
        return element;
    }
    exports.createSvgElement = createSvgElement;
    function createMeasureElements() {
        var measureElement = 'barcodeMeasureElement';
        if (!window["" + measureElement]) {
            var divElement = createHtmlElement('div', {
                id: 'barcodeMeasureElement', class: 'barcodeMeasureElement',
                style: 'visibility:hidden ; height: 0px ; width: 0px; overflow: hidden;'
            });
            var text = createHtmlElement('span', { 'style': 'display:inline-block ; line-height: normal' });
            divElement.appendChild(text);
            var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
            svg.setAttribute('xlink', 'http://www.w3.org/1999/xlink');
            divElement.appendChild(svg);
            var tSpan = document.createElementNS('http://www.w3.org/2000/svg', 'text');
            tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
            svg.appendChild(tSpan);
            window["" + measureElement] = divElement;
            window["" + measureElement].usageCount = 1;
            document.body.appendChild(divElement);
        }
        else {
            window["" + measureElement].usageCount += 1;
        }
    }
    exports.createMeasureElements = createMeasureElements;
});