all files / pdfviewer/organize-pdf/organize-core/ organize-math-utils.js

16.55% Statements 24/145
0% Branches 0/86
5.26% Functions 1/19
16.9% Lines 24/142
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222                                                                                                                                                                                                                                                                                                                                                                                                            
define(["require", "exports", "../organize-pdf", "@syncfusion/ej2-base"], function (require, exports, organize_pdf_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function getRotatedAngle(rotate) {
        switch (rotate.trim()) {
            case '0':
                return 0;
            case '90':
            case '1':
                return 90;
            case '180':
            case '2':
                return 180;
            case '270':
            case '3':
                return 270;
            case '360':
            case '4':
                return 0;
            default:
                return 0;
        }
    }
    exports.getRotatedAngle = getRotatedAngle;
    function getRotation(rotateAngle) {
        switch (rotateAngle.trim()) {
            case '0':
                return 0;
            case '90':
                return 1;
            case '180':
                return 2;
            case '270':
                return 3;
            case '360':
                return 0;
            default:
                return 0;
        }
    }
    exports.getRotation = getRotation;
    function updatePageSize(pageIndex, pageWidth, pageHeight) {
        if (this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)]) {
            this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)].width = pageWidth;
            this.pdfViewerBase.pageSize[parseInt(pageIndex.toString(), 10)].height = pageHeight;
            if (this.pdfViewerBase.highestWidth < pageWidth) {
                this.pdfViewerBase.highestWidth = pageWidth;
            }
            this.pdfViewerBase.isMixedSizeDocument = true;
        }
        for (var i = pageIndex; i < this.pdfViewerBase.pageSize.length; i++) {
            if (!this.pdfViewerBase.pageSize[parseInt((i - 1).toString(), 10)] && i - 1 < 0) {
                this.pdfViewerBase.pageSize[parseInt(i.toString(), 10)].top = this.pdfViewerBase.pageGap;
            }
            else {
                this.pdfViewerBase.pageSize[parseInt(i.toString(), 10)].top =
                    this.pdfViewerBase.pageSize[parseInt((i - 1).toString(), 10)].top +
                        this.pdfViewerBase.pageSize[parseInt((i - 1).toString(), 10)].height + this.pdfViewerBase.pageGap;
            }
        }
    }
    exports.updatePageSize = updatePageSize;
    function getNextSubIndex(parentElement, parentPageIndex) {
        var elementsWithAnchorId = parentElement.querySelectorAll("[id^='anchor_page_" + parentPageIndex + "']");
        var maxSubIndex = -1;
        elementsWithAnchorId.forEach(function (element) {
            var _a = element.id.split('_').slice(2), pageIndex = _a[0], subIndex = _a[1];
            if (Number(subIndex) > maxSubIndex) {
                maxSubIndex = Number(subIndex);
            }
        });
        return maxSubIndex + 1;
    }
    exports.getNextSubIndex = getNextSubIndex;
    function rotateClockwise(pageNumbers) {
        if (this.pdfViewer.pageOrganizerSettings.canRotate) {
            var _loop_1 = function (pageIndex) {
                var index = this_1.organizePagesCollection.findIndex(function (item) { return item.pageIndex === pageIndex; });
                if (index !== -1) {
                    this_1.organizePagesCollection[parseInt(index.toString(), 10)].rotateAngle =
                        (this_1.organizePagesCollection[parseInt(index.toString(), 10)].rotateAngle + 90 + 360) % 360;
                }
            };
            var this_1 = this;
            for (var _i = 0, pageNumbers_1 = pageNumbers; _i < pageNumbers_1.length; _i++) {
                var pageIndex = pageNumbers_1[_i];
                _loop_1(pageIndex);
            }
        }
    }
    exports.rotateClockwise = rotateClockwise;
    function rotateCounterclockwise(pageNumbers) {
        if (this.pdfViewer.pageOrganizerSettings.canRotate) {
            var _loop_2 = function (pageIndex) {
                var index = this_2.organizePagesCollection.findIndex(function (item) { return item.pageIndex === pageIndex; });
                if (index !== -1) {
                    this_2.organizePagesCollection[parseInt(index.toString(), 10)].rotateAngle =
                        (this_2.organizePagesCollection[parseInt(index.toString(), 10)].rotateAngle - 90 + 360) % 360;
                }
            };
            var this_2 = this;
            for (var _i = 0, pageNumbers_2 = pageNumbers; _i < pageNumbers_2.length; _i++) {
                var pageIndex = pageNumbers_2[_i];
                _loop_2(pageIndex);
            }
        }
    }
    exports.rotateCounterclockwise = rotateCounterclockwise;
    function getImageZoomFactor(imageContainer) {
        var minValue = this.getImageZoomMin();
        if (!this.pdfViewer.enablePageOrganizer || ej2_base_1.isNullOrUndefined(this.pdfViewer.pageOrganizerSettings)) {
            return minValue;
        }
        var size = this.getImageZoomValue();
        if (ej2_base_1.isNullOrUndefined(size)) {
            return minValue;
        }
        var maxValue = this.getImageZoomMax();
        if (!ej2_base_1.Browser.isDevice || this.pdfViewer.enableDesktopMode) {
            return this.getImageZoomValue();
        }
        else {
            var viewportWidth = this.pdfViewer.element.clientWidth;
            var imageContainerWidth = 140;
            imageContainer.style.position = 'absolute';
            document.body.appendChild(imageContainer);
            var computedStyle = window.getComputedStyle(imageContainer);
            var margin = parseFloat(computedStyle.marginLeft) + parseFloat(computedStyle.marginRight);
            document.body.removeChild(imageContainer);
            if ((imageContainerWidth * maxValue) <= (viewportWidth - margin)) {
                return this.getImageZoomValue();
            }
            else {
                var maxFactor = (viewportWidth - margin) / imageContainerWidth;
                var factor = (maxFactor - minValue) / (maxValue - minValue);
                if (size < minValue) {
                    return minValue;
                }
                if (size > maxValue) {
                    return (minValue + ((maxValue - minValue) * factor));
                }
                return (minValue + ((size - minValue) * factor));
            }
        }
    }
    exports.getImageZoomFactor = getImageZoomFactor;
    function getImageZoomValue(isImageRequest, size) {
        var minValue = this.getImageZoomMin();
        if (!this.pdfViewer.enablePageOrganizer || ej2_base_1.isNullOrUndefined(this.pdfViewer.pageOrganizerSettings)) {
            return minValue;
        }
        if (ej2_base_1.isNullOrUndefined(size)) {
            size = this.pdfViewer.pageOrganizerSettings.imageZoom;
            if (ej2_base_1.isNullOrUndefined(size)) {
                return minValue;
            }
        }
        var maxValue = this.getImageZoomMax();
        if (size < minValue) {
            return minValue;
        }
        if (size > maxValue) {
            return maxValue;
        }
        if (isImageRequest) {
            return Math.round(size);
        }
        return size;
    }
    exports.getImageZoomValue = getImageZoomValue;
    function processRotation(pageIndexes, pageRotateAngle) {
        if (this.pdfViewer.pageOrganizerSettings.canRotate) {
            var _loop_3 = function (pageIndex) {
                var rotateAngle = pdfRotateAngle(pageRotateAngle);
                var index = this_3.organizePagesCollection.findIndex(function (item) { return item.pageIndex === pageIndex; });
                if (index !== -1) {
                    this_3.organizePagesCollection[parseInt(index.toString(), 10)].rotateAngle =
                        (this_3.organizePagesCollection[parseInt(index.toString(), 10)].rotateAngle + rotateAngle + 360) % 360;
                }
            };
            var this_3 = this;
            for (var _i = 0, pageIndexes_1 = pageIndexes; _i < pageIndexes_1.length; _i++) {
                var pageIndex = pageIndexes_1[_i];
                _loop_3(pageIndex);
            }
        }
    }
    exports.processRotation = processRotation;
    function pdfRotateAngle(rotateAngle) {
        var angle = 0;
        if (rotateAngle === organize_pdf_1.PdfPageRotateAngle.RotateAngle0) {
            angle = 0;
        }
        else if (rotateAngle === organize_pdf_1.PdfPageRotateAngle.RotateAngle90) {
            angle = 90;
        }
        else if (rotateAngle === organize_pdf_1.PdfPageRotateAngle.RotateAngle180) {
            angle = 180;
        }
        else if (rotateAngle === organize_pdf_1.PdfPageRotateAngle.RotateAngle270) {
            angle = 270;
        }
        else if (rotateAngle === organize_pdf_1.PdfPageRotateAngle.RotateAngle360) {
            angle = 0;
        }
        return angle;
    }
    exports.pdfRotateAngle = pdfRotateAngle;
    function sorting(a, b) {
        a = !ej2_base_1.isNullOrUndefined(a) ? parseInt(a.toString(), 10) : -1;
        b = !ej2_base_1.isNullOrUndefined(b) ? parseInt(b.toString(), 10) : -1;
        if (a > b) {
            return 1;
        }
        if (a < b) {
            return -1;
        }
        return 0;
    }
    exports.sorting = sorting;
});