all files / pdfviewer/drawing/ drawing-util.js

17.05% Statements 22/129
0% Branches 0/94
9.09% Functions 1/11
17.05% Lines 22/129
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207                                                                                                                                                                                                                                                                                                                                                                                  
define(["require", "exports", "@syncfusion/ej2-drawings", "@syncfusion/ej2-base"], function (require, exports, ej2_drawings_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function isLineShapes(obj) {
        if (obj.shapeAnnotationType === 'Line' || obj.shapeAnnotationType === 'LineWidthArrowHead'
            || obj.shapeAnnotationType === 'Distance' || obj.shapeAnnotationType === 'Polygon') {
            return true;
        }
        return false;
    }
    exports.isLineShapes = isLineShapes;
    function setElementStype(obj, element) {
        if (obj && element) {
            if (obj.formFieldAnnotationType) {
                if (obj.id.indexOf('diagram_helper') !== -1) {
                    element.style.fill = 'transparent';
                    element.style.strokeWidth = 1;
                    element.style.strokeDashArray = obj.borderDashArray;
                }
                else {
                    element.style.fill = 'transparent';
                    element.style.strokeWidth = 0;
                }
            }
            else {
                var fillColor = (obj.fillColor === '#ffffff00' ? 'transparent' : obj.fillColor);
                element.style.fill = fillColor ? fillColor : 'white';
                element.style.strokeColor = obj.strokeColor ?
                    obj.strokeColor : obj.borderColor;
                element.style.color = obj.strokeColor ?
                    obj.strokeColor : obj.borderColor;
                element.style.strokeWidth = obj.thickness;
                if (obj.shapeAnnotationType === 'Image' || obj.shapeAnnotationType === 'SignatureText' || obj.shapeAnnotationType === 'SignatureImage') {
                    element.style.strokeWidth = 0;
                }
                element.style.strokeDashArray = obj.borderDashArray;
                element.style.opacity = obj.opacity;
            }
        }
    }
    exports.setElementStype = setElementStype;
    function findPointsLength(points) {
        var length = 0;
        for (var i = 0; i < points.length - 1; i++) {
            length += ej2_drawings_1.Point.findLength(points[parseInt(i.toString(), 10)], points[i + 1]);
        }
        return length;
    }
    exports.findPointsLength = findPointsLength;
    function findPerimeterLength(points) {
        var length = ej2_drawings_1.Point.getLengthFromListOfPoints(points);
        return length;
    }
    exports.findPerimeterLength = findPerimeterLength;
    function getBaseShapeAttributes(element, transform) {
        var baseShapeAttributes = {
            width: element.actualSize.width, height: element.actualSize.height,
            x: element.offsetX - element.actualSize.width * element.pivot.x + 0.5,
            y: element.offsetY - element.actualSize.height * element.pivot.y + 0.5,
            angle: element.rotateAngle + element.parentTransform, fill: element.style.fill, stroke: element.style.strokeColor,
            pivotX: element.pivot.x, pivotY: element.pivot.y, strokeWidth: 1,
            opacity: element.style.opacity, dashArray: element.style.strokeDashArray || '',
            visible: element.visible, id: element.id
        };
        if (transform) {
            baseShapeAttributes.x += transform.tx;
            baseShapeAttributes.y += transform.ty;
        }
        return baseShapeAttributes;
    }
    exports.getBaseShapeAttributes = getBaseShapeAttributes;
    function getFunction(value) {
        if (value !== undefined) {
            if (typeof value === 'string') {
                value = ej2_base_1.getValue(value, window);
            }
        }
        return value;
    }
    exports.getFunction = getFunction;
    function cloneObject(obj, additionalProp, key) {
        var newObject = {};
        var keys = 'properties';
        var prop = 'propName';
        if (obj) {
            key = obj["" + prop];
            var sourceObject = obj["" + keys] || obj;
            var properties = [];
            properties = properties.concat(Object.keys(sourceObject));
            var customProperties = [];
            properties.push('version');
            if (key) {
                var propAdditional = getFunction(additionalProp);
                if (propAdditional) {
                    customProperties = propAdditional(key);
                }
                else {
                    customProperties = [];
                }
                properties = properties.concat(customProperties);
            }
            var internalProp = getInternalProperties(key);
            properties = properties.concat(internalProp);
            for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
                var property = properties_1[_i];
                if (property !== 'historyManager') {
                    if (property !== 'wrapper') {
                        var isEventEmmitter = obj["" + property] && Object.prototype.hasOwnProperty.call(obj, 'observers') ? true : false;
                        if (!isEventEmmitter) {
                            if (obj["" + property] instanceof Array) {
                                newObject["" + property] = cloneArray((internalProp.indexOf(property) === -1 && obj["" + key]) ? obj["" + key]["" + property] : obj["" + property], additionalProp, property);
                            }
                            else if (obj["" + property] instanceof Array === false && obj["" + property] instanceof HTMLElement) {
                                newObject["" + property] = obj["" + property].cloneNode(true).innerHtml;
                            }
                            else if (obj["" + property] instanceof Array === false && obj["" + property] instanceof Object && property !== 'template') {
                                newObject["" + property] = cloneObject((internalProp.indexOf(property) === -1 && obj["" + key]) ? obj["" + key]["" + property] : obj["" + property]);
                            }
                            else {
                                newObject["" + property] = obj["" + property];
                            }
                        }
                    }
                    else {
                        if (obj["" + property]) {
                            newObject["" + property] = {
                                actualSize: {
                                    width: obj["" + property].actualSize.width, height: obj["" + property].actualSize.height
                                }, offsetX: obj["" + property].offsetX, offsetY: obj["" + property].offsetY
                            };
                        }
                    }
                }
            }
        }
        return newObject;
    }
    exports.cloneObject = cloneObject;
    function cloneArray(sourceArray, additionalProp, key) {
        var clonedArray;
        if (sourceArray) {
            clonedArray = [];
            for (var i = 0; i < sourceArray.length; i++) {
                if (sourceArray[parseInt(i.toString(), 10)] instanceof Array) {
                    clonedArray.push(sourceArray[parseInt(i.toString(), 10)]);
                }
                else if (sourceArray[parseInt(i.toString(), 10)] instanceof Object) {
                    clonedArray.push(cloneObject(sourceArray[parseInt(i.toString(), 10)], additionalProp, key));
                }
                else {
                    clonedArray.push(sourceArray[parseInt(i.toString(), 10)]);
                }
            }
        }
        return clonedArray;
    }
    exports.cloneArray = cloneArray;
    function getInternalProperties(propName) {
        switch (propName) {
            case 'nodes':
            case 'children':
                return ['inEdges', 'outEdges', 'parentId', 'processId', 'nodeId', 'umlIndex', 'isPhase', 'isLane'];
            case 'connectors':
                return ['parentId'];
            case 'annotation':
                return ['nodeId'];
            case 'annotations':
                return ['nodeId'];
            case 'shape':
                return ['hasHeader'];
        }
        return [];
    }
    exports.getInternalProperties = getInternalProperties;
    function isLeader(obj, position) {
        var rotatedPoint;
        if (obj.shapeAnnotationType === 'Distance') {
            var leaderCount = 0;
            var newPoint1 = void 0;
            for (var i = 0; i < obj.wrapper.children.length; i++) {
                var angle = ej2_drawings_1.Point.findAngle(obj.sourcePoint, obj.targetPoint);
                var segment = obj.wrapper.children[parseInt(i.toString(), 10)];
                if (segment.id.indexOf('leader') > -1) {
                    var center = obj.wrapper.children[0].bounds.center;
                    if (leaderCount === 0) {
                        newPoint1 = { x: obj.sourcePoint.x, y: obj.sourcePoint.y - obj.leaderHeight };
                        center = obj.sourcePoint;
                    }
                    else {
                        newPoint1 = { x: obj.targetPoint.x, y: obj.targetPoint.y - obj.leaderHeight };
                        center = obj.targetPoint;
                    }
                    var matrix = ej2_drawings_1.identityMatrix();
                    ej2_drawings_1.rotateMatrix(matrix, angle, center.x, center.y);
                    rotatedPoint = ej2_drawings_1.transformPointByMatrix(matrix, { x: newPoint1.x, y: newPoint1.y });
                    if (position === 'Leader' + leaderCount) {
                        return { leader: 'leader' + leaderCount, point: rotatedPoint };
                    }
                    leaderCount++;
                }
            }
        }
        return { leader: '', point: rotatedPoint };
    }
    exports.isLeader = isLeader;
});